bool InitCREngine( const char * exename, lString16Collection & fontDirs) { CRLog::trace("InitCREngine(%s)", exename); InitFontManager(lString8()); // Load font definitions into font manager // fonts are in files font1.lbf, font2.lbf, ... font32.lbf // use fontconfig lString16 fontExt = L".ttf"; lString16Collection fonts; getDirectoryFonts( fontDirs, fontExt, fonts, true ); // load fonts from file CRLog::debug("%d font files found", fonts.length()); if (!fontMan->GetFontCount()) { for (int fi=0; fi<fonts.length(); fi++ ) { lString8 fn = UnicodeToLocal(fonts[fi]); CRLog::trace("loading font: %s", fn.c_str()); if ( !fontMan->RegisterFont(fn) ) CRLog::trace(" failed\n"); } } if (!fontMan->GetFontCount()) { printf("Fatal Error: Cannot open font file(s) .ttf \nCannot work without font\n" ); return false; } printf("%d fonts loaded.\n", fontMan->GetFontCount()); return true; }
void LameMP3::Close() { if(!m_hMp3Stream) return; DWORD outLen = 0; int err = deinitStream(m_hMp3Stream, &m_out_mp3data[0], &outLen); assert(err == 0); if(outLen) m_outfile.send((const char*)&m_out_mp3data[0], outLen); ACE_TString filename = GetFileName(); closeStream(m_hMp3Stream); m_outfile.close(); if(filename.length()) { #if defined(UNICODE) //LAME doesn't support Unicode, so we just convert to locale //and hope for the best ACE_CString ascii = UnicodeToLocal(filename.c_str()); err = writeInfoTag(m_hMp3Stream, ascii.c_str()); #else err = writeInfoTag(m_hMp3Stream, filename.c_str()); #endif } m_out_mp3data.resize(0); m_hMp3Stream = 0; }
static int getXPointer(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); ldomXPointer xp = doc->text_view->getBookmark(); lua_pushstring(L, UnicodeToLocal(xp.toString()).c_str()); return 1; }
static int getHyphDictList(lua_State *L) { lua_newtable(L); HyphDictionaryList *list = HyphMan::getDictList(); for(int i = 0; i < list->length(); i++) { lua_pushnumber(L, i+1); lua_pushstring(L, UnicodeToLocal(list->get(i)->getId()).c_str()); lua_settable(L, -3); } return 1; }
static int getLinkFromPosition(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); int x = luaL_checkint(L, 2); int y = luaL_checkint(L, 3); lvPoint pt(x, y); ldomXPointer p = doc->text_view->getNodeByPoint(pt); lString16 href = p.getHRef(); lua_pushstring(L, UnicodeToLocal(href).c_str()); return 1; }
/* * helper function for getTableOfContent() */ static int walkTableOfContent(lua_State *L, LVTocItem *toc, int *count) { LVTocItem *toc_tmp = NULL; int i = 0, nr_child = toc->getChildCount(); for (i = 0; i < nr_child; i++) { toc_tmp = toc->getChild(i); lua_pushnumber(L, (*count)++); /* set subtable, Toc entry */ lua_newtable(L); lua_pushstring(L, "page"); lua_pushnumber(L, toc_tmp->getPage()+1); lua_settable(L, -3); lua_pushstring(L, "xpointer"); lua_pushstring(L, UnicodeToLocal( toc_tmp->getXPointer().toString()).c_str() ); lua_settable(L, -3); lua_pushstring(L, "depth"); lua_pushnumber(L, toc_tmp->getLevel()); lua_settable(L, -3); lua_pushstring(L, "title"); lua_pushstring(L, UnicodeToLocal(toc_tmp->getName()).c_str()); lua_settable(L, -3); /* set Toc entry to Toc table */ lua_settable(L, -3); if (toc_tmp->getChildCount() > 0) { walkTableOfContent(L, toc_tmp, count); } } return 0; }
static int getDocumentProps(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); lua_newtable(L); lua_pushstring(L, "title"); lua_pushstring(L, UnicodeToLocal(doc->text_view->getTitle()).c_str()); lua_settable(L, -3); lua_pushstring(L, "authors"); lua_pushstring(L, UnicodeToLocal(doc->text_view->getAuthors()).c_str()); lua_settable(L, -3); lua_pushstring(L, "language"); lua_pushstring(L, UnicodeToLocal(doc->text_view->getLanguage()).c_str()); lua_settable(L, -3); lua_pushstring(L, "series"); lua_pushstring(L, UnicodeToLocal(doc->text_view->getSeries()).c_str()); lua_settable(L, -3); return 1; }
/* * Return a table like this: * { * "FreeMono", * "FreeSans", * "FreeSerif", * } * */ static int getFontFaces(lua_State *L) { int i = 0; lString16Collection face_list; fontMan->getFaceList(face_list); lua_newtable(L); for (i = 0; i < face_list.length(); i++) { lua_pushnumber(L, i+1); lua_pushstring(L, UnicodeToLocal(face_list[i]).c_str()); lua_settable(L, -3); } return 1; }
bool getDirectoryFonts( lString16Collection & pathList, lString16Collection & ext, lString16Collection & fonts, bool absPath ) { int foundCount = 0; lString16 path; for ( int di=0; di<pathList.length();di++ ) { path = pathList[di]; LVContainerRef dir = LVOpenDirectory(path.c_str()); if ( !dir.isNull() ) { CRLog::trace("Checking directory %s", UnicodeToUtf8(path).c_str() ); for ( int i=0; i < dir->GetObjectCount(); i++ ) { const LVContainerItemInfo * item = dir->GetObjectInfo(i); lString16 fileName = item->GetName(); lString8 fn = UnicodeToLocal(fileName); //printf(" test(%s) ", fn.c_str() ); if ( !item->IsContainer() ) { bool found = false; lString16 lc = fileName; lc.lowercase(); for ( int j=0; j<ext.length(); j++ ) { if ( lc.endsWith(ext[j]) ) { found = true; break; } } if ( !found ) continue; lString16 fn; if ( absPath ) { fn = path; if ( !fn.empty() && fn[fn.length()-1]!=PATH_SEPARATOR_CHAR) fn << PATH_SEPARATOR_CHAR; } fn << fileName; foundCount++; fonts.add( fn ); } } } } return foundCount > 0; }
bool V3DocViewWin::saveHistory( lString16 filename ) { crtrace log; if ( filename.empty() ) filename = _historyFileName; if ( filename.empty() ) { CRLog::info("Cannot write history file - no file name specified"); return false; } CRLog::debug("Exporting bookmarks to %s", UnicodeToUtf8(_bookmarkDir).c_str()); _docview->exportBookmarks(_bookmarkDir); //use default filename _historyFileName = filename; log << "V3DocViewWin::saveHistory(" << filename << ")"; LVStreamRef stream = LVOpenFileStream( filename.c_str(), LVOM_WRITE ); if ( !stream ) { lString16 path16 = LVExtractPath( filename ); lString8 path = UnicodeToLocal( path16 ); #ifdef _WIN32 if ( !CreateDirectoryW( path16.c_str(), NULL ) ) { CRLog::error("Cannot create directory %s", path.c_str() ); } else { stream = LVOpenFileStream( filename.c_str(), LVOM_WRITE ); } #else path.erase( path.length()-1, 1 ); CRLog::warn("Cannot create settings file, trying to create directory %s", path.c_str()); if ( mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) ) { CRLog::error("Cannot create directory %s", path.c_str() ); } else { stream = LVOpenFileStream( filename.c_str(), LVOM_WRITE ); } #endif } if ( stream.isNull() ) { CRLog::error("Error while creating history file %s - position will be lost", UnicodeToUtf8(filename).c_str() ); return false; } return saveHistory( stream ); }
static int getWordFromPosition(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); int x = luaL_checkint(L, 2); int y = luaL_checkint(L, 3); LVDocView *tv = doc->text_view; lvRect margin = tv->getPageMargins(); int x_offset = margin.left; int y_offset = tv->GetPos() - (tv->getPageHeaderHeight() + margin.top) * (tv->getViewMode()==DVM_PAGES); LVPageWordSelector sel(tv); sel.selectWord(x - x_offset, y + y_offset); ldomWordEx * word = sel.getSelectedWord(); lua_newtable(L); // new word box if (word) { lvRect rect; ldomXRange range = word->getRange(); if (range.getRectEx(rect)) { lua_pushstring(L, "word"); lua_pushstring(L, UnicodeToLocal(word->getText()).c_str()); lua_settable(L, -3); lua_pushstring(L, "x0"); lua_pushinteger(L, rect.left + x_offset); lua_settable(L, -3); lua_pushstring(L, "y0"); lua_pushinteger(L, rect.top - y_offset); lua_settable(L, -3); lua_pushstring(L, "x1"); lua_pushinteger(L, rect.right + x_offset); lua_settable(L, -3); lua_pushstring(L, "y1"); lua_pushinteger(L, rect.bottom - y_offset); lua_settable(L, -3); } } return 1; }
bool V3DocViewWin::saveSettings( lString16 filename ) { crtrace log; if ( filename.empty() ) filename = _settingsFileName; if ( filename.empty() ) return false; _settingsFileName = filename; log << "V3DocViewWin::saveSettings(" << filename << ")"; LVStreamRef stream = LVOpenFileStream( filename.c_str(), LVOM_WRITE ); if ( !stream ) { lString16 path16 = LVExtractPath( filename ); lString8 path = UnicodeToLocal( path16 ); #ifdef _WIN32 if ( !CreateDirectoryW( path16.c_str(), NULL ) ) { CRLog::error("Cannot create directory %s", path.c_str() ); } else { stream = LVOpenFileStream( filename.c_str(), LVOM_WRITE ); } #else path.erase( path.length()-1, 1 ); CRLog::warn("Cannot create settings file, trying to create directory %s", path.c_str()); if ( mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) ) { CRLog::error("Cannot create directory %s", path.c_str() ); } else { stream = LVOpenFileStream( filename.c_str(), LVOM_WRITE ); } #endif } if ( stream.isNull() ) { lString8 fn = UnicodeToUtf8( filename ); CRLog::error("Cannot open settings file %s for write", fn.c_str() ); return false; } return _props->saveToStream( stream.get() ); }
static int getSelectedHyphDict(lua_State *L) { lua_pushstring(L, UnicodeToLocal(HyphMan::getSelectedDictionary()->getId()).c_str()); return 1; }
bool InitCREngine( const char * exename, lString16Collection & fontDirs ) { CRLog::trace("InitCREngine(%s)", exename); #ifdef _WIN32 lString16 appname( exename ); int lastSlash=-1; lChar16 slashChar = '/'; for ( int p=0; p<(int)appname.length(); p++ ) { if ( appname[p]=='\\' ) { slashChar = '\\'; lastSlash = p; } else if ( appname[p]=='/' ) { slashChar = '/'; lastSlash=p; } } lString16 appPath; if ( lastSlash>=0 ) appPath = appname.substr( 0, lastSlash+1 ); InitCREngineLog(UnicodeToUtf8(appPath).c_str()); lString16 datadir = appPath; #else lString16 datadir = lString16(CR3_DATA_DIR); #endif lString16 fontDir = datadir + L"fonts"; lString8 fontDir8_ = UnicodeToUtf8(fontDir); fontDirs.add( fontDir ); LVAppendPathDelimiter( fontDir ); lString8 fontDir8 = UnicodeToLocal(fontDir); //const char * fontDir8s = fontDir8.c_str(); //InitFontManager( fontDir8 ); InitFontManager( lString8() ); #ifdef _WIN32 lChar16 sysdir[MAX_PATH+1]; GetWindowsDirectoryW(sysdir, MAX_PATH); lString16 fontdir( sysdir ); fontdir << L"\\Fonts\\"; lString8 fontdir8( UnicodeToUtf8(fontdir) ); const char * fontnames[] = { "arial.ttf", "ariali.ttf", "arialb.ttf", "arialbi.ttf", "arialn.ttf", "arialni.ttf", "arialnb.ttf", "arialnbi.ttf", "cour.ttf", "couri.ttf", "courbd.ttf", "courbi.ttf", "times.ttf", "timesi.ttf", "timesb.ttf", "timesbi.ttf", "comic.ttf", "comicbd.ttf", "verdana.ttf", "verdanai.ttf", "verdanab.ttf", "verdanaz.ttf", "bookos.ttf", "bookosi.ttf", "bookosb.ttf", "bookosbi.ttf", "calibri.ttf", "calibrii.ttf", "calibrib.ttf", "calibriz.ttf", "cambria.ttf", "cambriai.ttf", "cambriab.ttf", "cambriaz.ttf", "georgia.ttf", "georgiai.ttf", "georgiab.ttf", "georgiaz.ttf", NULL }; for ( int fi = 0; fontnames[fi]; fi++ ) { fontMan->RegisterFont( fontdir8 + fontnames[fi] ); } #endif // Load font definitions into font manager // fonts are in files font1.lbf, font2.lbf, ... font32.lbf // use fontconfig lString16Collection fontExt; fontExt.add(lString16(L".ttf")); fontExt.add(lString16(L".otf")); fontExt.add(lString16(L".pfa")); fontExt.add(lString16(L".pfb")); lString16Collection fonts; getDirectoryFonts( fontDirs, fontExt, fonts, true ); // load fonts from file CRLog::debug("%d font files found", fonts.length()); //if (!fontMan->GetFontCount()) { for ( unsigned fi=0; fi<fonts.length(); fi++ ) { lString8 fn = UnicodeToLocal(fonts[fi]); CRLog::trace("loading font: %s", fn.c_str()); if ( !fontMan->RegisterFont(fn) ) { CRLog::trace(" failed\n"); } } //} // init hyphenation manager //char hyphfn[1024]; //sprintf(hyphfn, "Russian_EnUS_hyphen_(Alan).pdb" ); //if ( !initHyph( (UnicodeToLocal(appPath) + hyphfn).c_str() ) ) { #ifdef _LINUX // initHyph( "/usr/share/crengine/hyph/Russian_EnUS_hyphen_(Alan).pdb" ); #endif //} if (!fontMan->GetFontCount()) { //error #if (USE_FREETYPE==1) printf("Fatal Error: Cannot open font file(s) .ttf \nCannot work without font\n" ); #else printf("Fatal Error: Cannot open font file(s) font#.lbf \nCannot work without font\nUse FontConv utility to generate .lbf fonts from TTF\n" ); #endif return false; } printf("%d fonts loaded.\n", fontMan->GetFontCount()); return true; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { CRLog::setFileLogger( "crengine.log" ); CRLog::setLogLevel( CRLog::LL_TRACE ); // TODO: Place code here. MSG msg; HACCEL hAccelTable; //make_dither_table(); //TestWol(); /* LVStreamRef zipfile = LVOpenFileStream( L"zip_test.zip", LVOM_READ ); if (!zipfile.isNull()) { LVContainerRef zip = LVOpenArchieve( zipfile ); if (!zip.isNull()) { LVStreamRef log = LVOpenFileStream("ziptest.log", LVOM_WRITE); for (int i=0; i<zip->GetObjectCount(); i++) { const LVContainerItemInfo * item = zip->GetObjectInfo(i); if (item) { // *log << UnicodeToLocal( item->GetName() ); *log << lString8::itoa( (int)item->GetSize() ); LVStreamRef unpstream = zip->OpenStream( item->GetName(), LVOM_READ ); if (!unpstream.isNull()) { *log << "\n arc stream opened ok \n"; LVStreamRef outstream = LVOpenFileStream( item->GetName(), LVOM_WRITE ); if ( !outstream.isNull() ) { int copiedBytes = (int)LVPumpStream( outstream, unpstream ); *log << " copied " << lString8::itoa(copiedBytes) << " bytes\n"; } else { *log << " error opening out stream\n"; } } } } } } */ lString8 exe_dir; char exe_fn[MAX_PATH+1]; GetModuleFileNameA( NULL, exe_fn, MAX_PATH ); int last_slash = -1; int i; for (i=0; exe_fn[i]; i++) if (exe_fn[i]=='\\' || exe_fn[i]=='/') last_slash = i; if (last_slash>0) exe_dir = lString8( exe_fn, last_slash ); // init hyphenation manager initHyph( (exe_dir + "\\russian_EnUS_hyphen_(Alan).pdb").c_str() ); lString8 fontDir = exe_dir; fontDir << "\\fonts"; // init bitmap font manager InitFontManager( fontDir ); // Load font definitions into font manager // fonts are in files font1.lbf, font2.lbf, ... font32.lbf #if (USE_FREETYPE==1) LVContainerRef dir = LVOpenDirectory( LocalToUnicode(fontDir).c_str() ); if ( !dir.isNull() ) for ( i=0; i<dir->GetObjectCount(); i++ ) { const LVContainerItemInfo * item = dir->GetObjectInfo(i); lString16 fileName = item->GetName(); if ( !item->IsContainer() && fileName.length()>4 && lString16(fileName, fileName.length()-4, 4)==L".ttf" ) { lString8 fn = UnicodeToLocal(fileName); printf("loading font: %s\n", fn.c_str()); if ( !fontMan->RegisterFont(fn) ) { printf(" failed\n"); } } } //fontMan->RegisterFont(lString8("arial.ttf")); #else #if (USE_WIN32_FONTS==0) #define MAX_FONT_FILE 32 for (i=0; i<MAX_FONT_FILE; i++) { char fn[32]; sprintf( fn, "font%d.lbf", i ); fontMan->RegisterFont( lString8(fn) ); } #endif #endif //LVCHECKPOINT("WinMain start"); text_view = new LVDocView; // stylesheet can be placed to file fb2.css // if not found, default stylesheet will be used lString8 css = readFileToString( (exe_dir + "\\fb2.css").c_str() ); if (css.length() > 0) text_view->setStyleSheet( css ); //LVCHECKPOINT("WinMain before loads"); if (!fontMan->GetFontCount()) { //error char str[1000]; #if (USE_FREETYPE==1) sprintf(str, "Cannot open font file(s) fonts/*.ttf \nCannot work without font\nPlace some TTF files to font\\ directory" ); #else sprintf(str, "Cannot open font file(s) font#.lbf \nCannot work without font\nUse FontConv utility to generate .lbf fonts from TTF" ); #endif MessageBoxA( NULL, str, "CR Engine :: Fb2Test -- fatal error!", MB_OK); return 1; } lString8 cmdline(lpCmdLine); cmdline.trim(); if ( cmdline == "test_format" ) { testFormatting(); return 1; } if (cmdline.empty()) { cmdline = OpenFileDialog( NULL ); //cmdline = "example2.fb2"; } if ( cmdline.empty() ) return 2; if ( !text_view->LoadDocument( cmdline.c_str() )) { //error char str[100]; sprintf(str, "Cannot open document file %s", cmdline.c_str()); MessageBoxA( NULL, str, "CR Engine :: Fb2Test -- fatal error!", MB_OK); return 1; } //LVCHECKPOINT("WinMain after loads"); // Initialize global strings MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_FONTTEST); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } delete text_view; ShutdownFontManager(); return msg.wParam; }
static int getTextFromPositions(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); int x0 = luaL_checkint(L, 2); int y0 = luaL_checkint(L, 3); int x1 = luaL_checkint(L, 4); int y1 = luaL_checkint(L, 5); LVDocView *tv = doc->text_view; lvRect margin = tv->getPageMargins(); lvPoint startpt(x0, y0); lvPoint endpt(x1, y1); ldomXPointer startp = tv->getNodeByPoint(startpt); ldomXPointer endp = tv->getNodeByPoint(endpt); if (!startp.isNull() && !endp.isNull()) { lua_newtable(L); // new text boxes ldomXRange r(startp, endp); if (r.getStart().isNull() || r.getEnd().isNull()) return 0; r.sort(); if (!r.getStart().isVisibleWordStart()) r.getStart().prevVisibleWordStart(); if (!r.getEnd().isVisibleWordEnd()) r.getEnd().nextVisibleWordEnd(); if (r.isNull()) return 0; if (r.getStart() == r.getEnd()) { // for single CJK character ldomNode * node = r.getStart().getNode(); lString16 text = node->getText(); int textLen = text.length(); int offset = r.getEnd().getOffset(); if (offset < textLen - 1) r.getEnd().setOffset(offset + 1); } r.setFlags(1); tv->selectRange(r); // we don't need native highlight of selection int page = tv->getBookmarkPage(startp); int pages = tv->getPageCount(); lString16 titleText; lString16 posText; tv->getBookmarkPosText(startp, titleText, posText); lString16 selText = r.getRangeText( '\n', 8192 ); lua_pushstring(L, "text"); lua_pushstring(L, UnicodeToLocal(selText).c_str()); lua_settable(L, -3); lua_pushstring(L, "pos0"); lua_pushstring(L, UnicodeToLocal(r.getStart().toString()).c_str()); lua_settable(L, -3); lua_pushstring(L, "pos1"); lua_pushstring(L, UnicodeToLocal(r.getEnd().toString()).c_str()); lua_settable(L, -3); lua_pushstring(L, "title"); lua_pushstring(L, UnicodeToLocal(titleText).c_str()); lua_settable(L, -3); lua_pushstring(L, "context"); lua_pushstring(L, UnicodeToLocal(posText).c_str()); lua_settable(L, -3); lua_pushstring(L, "percent"); lua_pushnumber(L, 1.0*page/(pages-1)); lua_settable(L, -3); return 1; } return 0; }
static int findText(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); const char *l_pattern = luaL_checkstring(L, 2); lString16 pattern = lString16(l_pattern); int origin = luaL_checkint(L, 3); bool reverse = luaL_checkint(L, 4); bool caseInsensitive = luaL_checkint(L, 5); if ( pattern.empty() ) return 0; LVArray<ldomWord> words; lvRect rc; doc->text_view->GetPos( rc ); int pageHeight = rc.height(); int start = -1; int end = -1; if ( reverse ) { // backward if ( origin == 0 ) { // from end of current page to first page end = rc.bottom; } else if ( origin == -1 ) { // from the last page to end of current page start = rc.bottom + 1; } else { // origin == 1 // from prev page to the first page end = rc.top - 1; } } else { // forward if ( origin == 0 ) { // from current page to the last page start = rc.top; } else if ( origin == -1 ) { // from the first page to current page end = rc.top + 1; } else { // origin == 1 // from next page to the last page start = rc.bottom + 1; } } CRLog::debug("CRViewDialog::findText: Current page: %d .. %d", rc.top, rc.bottom); CRLog::debug("CRViewDialog::findText: searching for text '%s' from %d to %d origin %d", LCSTR(pattern), start, end, origin ); if ( doc->text_view->getDocument()->findText( pattern, caseInsensitive, reverse, start, end, words, 200, pageHeight ) ) { CRLog::debug("CRViewDialog::findText: pattern found"); doc->text_view->clearSelection(); doc->text_view->selectWords( words ); ldomMarkedRangeList * ranges = doc->text_view->getMarkedRanges(); if ( ranges && ranges->length() > 0 ) { lua_newtable(L); // hold all words for (int i = 0; i < words.length(); i++) { ldomWord word = words[i]; lua_newtable(L); // new word lua_pushstring(L, "start"); lua_pushstring(L, UnicodeToLocal(word.getStartXPointer().toString()).c_str()); lua_settable(L, -3); lua_pushstring(L, "end"); lua_pushstring(L, UnicodeToLocal(word.getEndXPointer().toString()).c_str()); lua_settable(L, -3); lua_rawseti(L, -2, i + 1); } return 1; } } CRLog::debug("CRViewDialog::findText: pattern not found"); return 0; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { CRLog::setFileLogger( "crengine.log", true ); CRLog::setLogLevel( CRLog::LL_TRACE ); //InitCREngineLog("/root/abook/crengine/crlog.ini"); #if 0 MMapTest(); #endif lString8 exe_dir; char exe_fn[MAX_PATH+1]; GetModuleFileNameA( NULL, exe_fn, MAX_PATH ); lChar16 exe_fn16[MAX_PATH+1]; GetModuleFileNameW( NULL, exe_fn16, MAX_PATH ); lString16 exedir = LVExtractPath(lString16(exe_fn16)); lString8 exedir8 = UnicodeToUtf8( exedir ); CRLog::debug("exedir=%s", exedir8.c_str()); CRMoFileTranslator * translator = new CRMoFileTranslator(); translator->openMoFile(exedir + L"/po/ru.mo"); CRI18NTranslator::setTranslator( translator ); lChar16 sysdir[MAX_PATH+1]; GetWindowsDirectoryW(sysdir, MAX_PATH); lString16 fontdir( sysdir ); fontdir << L"\\Fonts\\"; lString8 fontdir8( UnicodeToUtf8(fontdir) ); lString8 fd = UnicodeToLocal(exedir); lString16Collection fontDirs; //fontDirs.add( fontdir ); fontDirs.add( exedir + L"fonts" ); InitCREngine( exe_fn, fontDirs ); const char * fontnames[] = { #if 1 "arial.ttf", "ariali.ttf", "arialb.ttf", "arialbi.ttf", #endif "arialn.ttf", "arialni.ttf", "arialnb.ttf", "arialnbi.ttf", "cour.ttf", "couri.ttf", "courbd.ttf", "courbi.ttf", "times.ttf", "timesi.ttf", "timesb.ttf", "timesbi.ttf", #if 0 "comic.ttf", "comicbd.ttf", "verdana.ttf", "verdanai.ttf", "verdanab.ttf", "verdanaz.ttf", "bookos.ttf", "bookosi.ttf", "bookosb.ttf", "bookosbi.ttf", #endif #if 0 "calibri.ttf", "calibrii.ttf", "calibrib.ttf", "calibriz.ttf", "cambria.ttf", "cambriai.ttf", "cambriab.ttf", "cambriaz.ttf", "georgia.ttf", "georgiai.ttf", "georgiab.ttf", "georgiaz.ttf", #endif NULL }; for ( int fi = 0; fontnames[fi]; fi++ ) { fontMan->RegisterFont( fontdir8 + fontnames[fi] ); } //LVCHECKPOINT("WinMain start"); if (!fontMan->GetFontCount()) { //error char str[1000]; #if (USE_FREETYPE==1) sprintf(str, "Cannot open font file(s) fonts/*.ttf \nCannot work without font\nPlace some TTF files to font\\ directory" ); #else sprintf(str, "Cannot open font file(s) font#.lbf \nCannot work without font\nUse FontConv utility to generate .lbf fonts from TTF" ); #endif MessageBoxA( NULL, str, "CR Engine :: Fb2Test -- fatal error!", MB_OK); return 1; } lString8 cmdline(lpCmdLine); if ( cmdline.empty() ) return 2; // need filename hInst = hInstance; MyRegisterClass(hInstance); { CRWin32WindowManager winman(500, 700); const char * keymap_locations [] = { exedir8.c_str(), NULL, }; loadKeymaps( winman, keymap_locations ); ldomDocCache::init( exedir + L"cache", 0x100000 * 96 ); /*96Mb*/ winman.loadSkin( LVExtractPath(LocalToUnicode(lString8(exe_fn))) + L"skin" ); V3DocViewWin * main_win = new V3DocViewWin( &winman, LVExtractPath(LocalToUnicode(lString8(exe_fn))) ); main_win->getDocView()->setBackgroundColor(0xFFFFFF); main_win->getDocView()->setTextColor(0x000000); main_win->getDocView()->setFontSize( 20 ); main_win->loadCSS( exedir + L"fb2.css" ); main_win->loadSettings( exedir + L"cr3.ini" ); main_win->saveSettings(lString16()); main_win->setHelpFile( exedir + L"cr3-manual-ru.fb2" ); HyphMan::initDictionaries( exedir + L"hyph\\" ); main_win->loadDefaultCover( exedir + L"cr3_def_cover.png" ); main_win->setBookmarkDir(lString16("c:\\cr3\\bookmarks\\")); lString8 exedir8 = UnicodeToUtf8( exedir ); const char * dirs[] = { exedir8.c_str(), NULL }; loadKeymaps( winman, dirs ); main_win->loadHistory( exedir + L"cr3hist.bmk" ); winman.activateWindow( main_win ); if ( !main_win->loadDocument( LocalToUnicode( cmdline )) ) { char str[100]; sprintf(str, "Cannot open document file %s", cmdline.c_str()); MessageBoxA( NULL, str, "CR Engine :: Fb2Test -- fatal error!", MB_OK); return 1; } else { winman.runEventLoop(); } } //ShutdownFontManager(); return 0; }
static int getPageLinks(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); lua_newtable(L); // all links ldomXRangeList links; ldomXRangeList & sel = doc->text_view->getDocument()->getSelections(); doc->text_view->getCurrentPageLinks( links ); int linkCount = links.length(); if ( linkCount ) { sel.clear(); lvRect margin = doc->text_view->getPageMargins(); int x_offset = margin.left; int y_offset = doc->text_view->GetPos() - doc->text_view->getPageHeaderHeight() - margin.top; for ( int i=0; i<linkCount; i++ ) { lString16 txt = links[i]->getRangeText(); lString8 txt8 = UnicodeToLocal( txt ); lString16 link = links[i]->getHRef(); lString8 link8 = UnicodeToLocal( link ); ldomXRange currSel; currSel = *links[i]; lvPoint start_pt ( currSel.getStart().toPoint() ); lvPoint end_pt ( currSel.getEnd().toPoint() ); CRLog::debug("# link %d start %d %d end %d %d '%s' %s\n", i, start_pt.x, start_pt.y, end_pt.x, end_pt.y, txt8.c_str(), link8.c_str() ); lua_newtable(L); // new link lua_pushstring(L, "start_x"); lua_pushinteger(L, start_pt.x + x_offset); lua_settable(L, -3); lua_pushstring(L, "start_y"); lua_pushinteger(L, start_pt.y - y_offset); lua_settable(L, -3); lua_pushstring(L, "end_x"); lua_pushinteger(L, end_pt.x + x_offset); lua_settable(L, -3); lua_pushstring(L, "end_y"); lua_pushinteger(L, end_pt.y - y_offset); lua_settable(L, -3); const char * link_to = link8.c_str(); if ( link_to[0] == '#' ) { lua_pushstring(L, "section"); lua_pushstring(L, link_to); lua_settable(L, -3); sel.add( new ldomXRange(*links[i]) ); // highlight } else { lua_pushstring(L, "uri"); lua_pushstring(L, link_to); lua_settable(L, -3); } lua_rawseti(L, -2, i + 1); } doc->text_view->updateSelections(); } return 1; }