bool getDirectoryFonts( lString16Collection & pathList, lString16 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(); if ( !item->IsContainer() && fileName.length()>4 && lString16(fileName, fileName.length()-4, 4)==ext ) { 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; }
void qt2cr( lString16Collection & dst, const QStringList & src ) { dst.clear(); for ( int i=0; i<src.length(); i++ ) { dst.add( qt2cr( src[i] ) ); } }
void CRJNIEnv::fromJavaStringArray( jobjectArray array, lString16Collection & dst ) { dst.clear(); int len = env->GetArrayLength(array); for ( int i=0; i<len; i++ ) { jstring str = (jstring)env->GetObjectArrayElement(array, i); dst.add(fromJavaString(str)); env->DeleteLocalRef(str); } }
static void findImagesFromDirectory( lString16 dir, lString16Collection & files ) { LVAppendPathDelimiter(dir); if ( !LVDirectoryExists(dir) ) return; LVContainerRef cont = LVOpenDirectory(dir.c_str()); if ( !cont.isNull() ) { for ( int i=0; i<cont->GetObjectCount(); i++ ) { const LVContainerItemInfo * item = cont->GetObjectInfo(i); if ( !item->IsContainer() ) { lString16 name = item->GetName(); name.lowercase(); if ( name.endsWith(".png") || name.endsWith(".jpg") || name.endsWith(".gif") || name.endsWith(".jpeg") ) { files.add(dir + item->GetName()); } } } } }
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 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; }