bool V3DocViewWin::loadSettings( lString16 filename ) { _settingsFileName = filename; LVStreamRef stream = LVOpenFileStream( filename.c_str(), LVOM_READ ); if ( stream.isNull() ) { _docview->propsUpdateDefaults( _props ); _docview->propsApply( _props ); _wm->getScreen()->setFullUpdateInterval(_props->getIntDef(PROP_DISPLAY_FULL_UPDATE_INTERVAL, 1)); _wm->getScreen()->setTurboUpdateEnabled(_props->getIntDef(PROP_DISPLAY_TURBO_UPDATE_MODE, 0)); //setAccelerators( _wm->getAccTables().get(lString16("main"), _props) ); return false; } if ( _props->loadFromStream( stream.get() ) ) { _props->setIntDef(PROP_FILE_PROPS_FONT_SIZE, 26); _docview->propsUpdateDefaults( _props ); _docview->propsApply( _props ); _wm->getScreen()->setFullUpdateInterval(_props->getIntDef(PROP_DISPLAY_FULL_UPDATE_INTERVAL, 1)); _wm->getScreen()->setTurboUpdateEnabled(_props->getIntDef(PROP_DISPLAY_TURBO_UPDATE_MODE, 0)); setAccelerators( _wm->getAccTables().get(lString16("main"), _props) ); return true; } _docview->propsUpdateDefaults( _props ); _docview->propsApply( _props ); _wm->getScreen()->setFullUpdateInterval(_props->getIntDef(PROP_DISPLAY_FULL_UPDATE_INTERVAL, 1)); _wm->getScreen()->setTurboUpdateEnabled(_props->getIntDef(PROP_DISPLAY_TURBO_UPDATE_MODE, 0)); //setAccelerators( _wm->getAccTables().get(lString16("main"), _props) ); return false; }
bool DetectEpubFormat( LVStreamRef stream ) { LVContainerRef m_arc = LVOpenArchieve( stream ); if ( m_arc.isNull() ) return false; // not a ZIP archive //dumpZip( m_arc ); // read "mimetype" file contents from root of archive lString16 mimeType; { LVStreamRef mtStream = m_arc->OpenStream(L"mimetype", LVOM_READ ); if ( !mtStream.isNull() ) { int size = mtStream->GetSize(); if ( size>4 && size<100 ) { LVArray<char> buf( size+1, '\0' ); if ( mtStream->Read( buf.get(), size, NULL )==LVERR_OK ) { for ( int i=0; i<size; i++ ) if ( buf[i]<32 || ((unsigned char)buf[i])>127 ) buf[i] = 0; buf[size] = 0; if ( buf[0] ) mimeType = Utf8ToUnicode( lString8( buf.get() ) ); } } } } if ( mimeType != L"application/epub+zip" ) return false; return true; }
jbyteArray scanBookCoverInternal (JNIEnv * _env, jclass _class, jstring _path) { CRJNIEnv env(_env); lString16 path = env.fromJavaString(_path); CRLog::debug("scanBookCoverInternal(%s) called", LCSTR(path)); lString16 arcname, item; LVStreamRef res; jbyteArray array = NULL; LVContainerRef arc; if (!LVSplitArcName(path, arcname, item)) { // not in archive LVStreamRef stream = LVOpenFileStream(path.c_str(), LVOM_READ); if (!stream.isNull()) { arc = LVOpenArchieve(stream); if (!arc.isNull()) { // ZIP-based format if (DetectEpubFormat(stream)) { // EPUB // extract coverpage from epub res = GetEpubCoverpage(arc); } } else { res = GetFB2Coverpage(stream); if (res.isNull()) { doc_format_t fmt; if (DetectPDBFormat(stream, fmt)) { res = GetPDBCoverpage(stream); } } } } } else { CRLog::debug("scanBookCoverInternal() : is archive, item=%s, arc=%s", LCSTR(item), LCSTR(arcname)); LVStreamRef arcstream = LVOpenFileStream(arcname.c_str(), LVOM_READ); if (!arcstream.isNull()) { arc = LVOpenArchieve(arcstream); if (!arc.isNull()) { LVStreamRef stream = arc->OpenStream(item.c_str(), LVOM_READ); if (!stream.isNull()) { CRLog::debug("scanBookCoverInternal() : archive stream opened ok, parsing"); res = GetFB2Coverpage(stream); if (res.isNull()) { doc_format_t fmt; if (DetectPDBFormat(stream, fmt)) { res = GetPDBCoverpage(stream); } } } } } } if (!res.isNull()) array = env.streamToJByteArray(res); if (array != NULL) CRLog::debug("scanBookCoverInternal() : returned cover page array"); else CRLog::debug("scanBookCoverInternal() : cover page data not found"); return array; }
bool CRFileHist::saveToStream( LVStream * targetStream ) { LVStreamRef streamref = LVCreateMemoryStream(NULL, 0, false, LVOM_WRITE); LVStream * stream = streamref.get(); const char * xml_hdr = "\xef\xbb\xbf<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<FictionBookMarks>\r\n"; const char * xml_ftr = "</FictionBookMarks>\r\n"; //const char * crlf = "\r\n"; *stream << xml_hdr; for ( int i=0; i<_records.length(); i++ ) { CRFileHistRecord * rec = _records[i]; putTag( stream, 1, "file" ); putTag( stream, 2, "file-info" ); putTagValue( stream, 3, "doc-title", rec->getTitle() ); putTagValue( stream, 3, "doc-author", rec->getAuthor() ); putTagValue( stream, 3, "doc-series", rec->getSeries() ); putTagValue( stream, 3, "doc-filename", rec->getFileName() ); putTagValue( stream, 3, "doc-filepath", rec->getFilePath() ); putTagValue( stream, 3, "doc-filesize", lString16::itoa( (unsigned int)rec->getFileSize() ) ); putTag( stream, 2, "/file-info" ); putTag( stream, 2, "bookmark-list" ); putBookmark( stream, rec->getLastPos() ); for ( int j=0; j<rec->getBookmarks().length(); j++) { CRBookmark * bmk = rec->getBookmarks()[j]; putBookmark( stream, bmk ); } putTag( stream, 2, "/bookmark-list" ); putTag( stream, 1, "/file" ); } *stream << xml_ftr; LVPumpStream( targetStream, stream ); return true; }
/* * Class: org_coolreader_crengine_Engine * Method: drawBookCoverInternal * Signature: (Landroid/graphics/Bitmap;[BLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;II)V */ JNIEXPORT void JNICALL Java_org_coolreader_crengine_Engine_drawBookCoverInternal (JNIEnv * _env, jobject _engine, jobject bitmap, jbyteArray _data, jstring _fontFace, jstring _title, jstring _authors, jstring _seriesName, jint seriesNumber, jint bpp) { CRJNIEnv env(_env); //CRLog::debug("drawBookCoverInternal called"); lString8 fontFace = UnicodeToUtf8(env.fromJavaString(_fontFace)); lString16 title = env.fromJavaString(_title); lString16 authors = env.fromJavaString(_authors); lString16 seriesName = env.fromJavaString(_seriesName); LVStreamRef stream; LVImageSourceRef image; if (_data != NULL && _env->GetArrayLength(_data) > 0) { stream = env.jbyteArrayToStream(_data); if (!stream.isNull()) image = LVCreateStreamImageSource(stream); } LVDrawBuf * drawbuf = BitmapAccessorInterface::getInstance()->lock(_env, bitmap); if (drawbuf != NULL) { int factor = 1; int dx = drawbuf->GetWidth(); int dy = drawbuf->GetHeight(); int MIN_WIDTH = 300; int MIN_HEIGHT = 400; if (dx < MIN_WIDTH || dy < MIN_HEIGHT) { if (dx * 2 < MIN_WIDTH || dy * 2 < MIN_HEIGHT) { dx *= 3; dy *= 3; factor = 3; } else { dx *= 2; dy *= 2; factor = 2; } } LVDrawBuf * drawbuf2 = drawbuf; if (factor > 1) drawbuf2 = new LVColorDrawBuf(dx, dy, drawbuf->GetBitsPerPixel()); if (bpp >= 16) { // native color resolution LVDrawBookCover(*drawbuf2, image, fontFace, title, authors, seriesName, seriesNumber); } else { LVGrayDrawBuf grayBuf(drawbuf2->GetWidth(), drawbuf2->GetHeight(), bpp); LVDrawBookCover(grayBuf, image, fontFace, title, authors, seriesName, seriesNumber); grayBuf.DrawTo(drawbuf2, 0, 0, 0, NULL); } if (factor > 1) { drawbuf->DrawRescaled(drawbuf2, 0, 0, drawbuf->GetWidth(), drawbuf->GetHeight(), 0); delete drawbuf2; } //CRLog::trace("getPageImageInternal calling bitmap->unlock"); BitmapAccessorInterface::getInstance()->unlock(_env, bitmap, drawbuf); } else { CRLog::error("bitmap accessor is invalid"); } //CRLog::debug("drawBookCoverInternal finished"); }
bool TexHyph::load( lString16 fileName ) { LVStreamRef stream = LVOpenFileStream( fileName.c_str(), LVOM_READ ); if ( stream.isNull() ) return false; return load( stream ); }
void initHyph(const char * fname) { HyphMan hyphman; LVStreamRef stream = LVOpenFileStream( fname, LVOM_READ); if (!stream) return; HyphMan::Open( stream.get() ); }
virtual LVStreamRef OpenStream( const lChar16 * fname, lvopen_mode_t mode ) { LVStreamRef res = _container->OpenStream(fname, mode); if (res.isNull()) return res; if (isEncryptedItem(fname)) return LVStreamRef(new FontDemanglingStream(res, _fontManglingKey)); return res; }
bool V3DocViewWin::saveHistory( LVStreamRef stream ) { if ( stream.isNull() ) { CRLog::error("Cannot open history file for write" ); return false; } _docview->getHistory()->limit( 32 ); return _docview->getHistory()->saveToStream( stream.get() ); }
bool V3DocViewWin::loadDictConfig( lString16 filename ) { LVStreamRef stream = LVOpenFileStream( filename.c_str(), LVOM_READ ); if ( !stream.isNull() ) { _dictConfig = filename; return true; } return false; }
bool HyphDictionaryList::open(lString16 hyphDirectory, bool clear) { CRLog::info("HyphDictionaryList::open(%s)", LCSTR(hyphDirectory) ); if (clear) { _list.clear(); addDefault(); } if ( hyphDirectory.empty() ) return true; //LVAppendPathDelimiter( hyphDirectory ); LVContainerRef container; LVStreamRef stream; if ( (hyphDirectory.endsWith("/") || hyphDirectory.endsWith("\\")) && LVDirectoryExists(hyphDirectory) ) { container = LVOpenDirectory( hyphDirectory.c_str(), L"*.*" ); } else if ( LVFileExists(hyphDirectory) ) { stream = LVOpenFileStream( hyphDirectory.c_str(), LVOM_READ ); if ( !stream.isNull() ) container = LVOpenArchieve( stream ); } if ( !container.isNull() ) { int len = container->GetObjectCount(); int count = 0; CRLog::info("%d items found in hyph directory", len); for ( int i=0; i<len; i++ ) { const LVContainerItemInfo * item = container->GetObjectInfo( i ); lString16 name = item->GetName(); lString16 suffix; HyphDictType t = HDT_NONE; if ( name.endsWith(".pdb") ) { suffix = "_hyphen_(Alan).pdb"; t = HDT_DICT_ALAN; } else if ( name.endsWith(".pattern") ) { suffix = ".pattern"; t = HDT_DICT_TEX; } else continue; lString16 filename = hyphDirectory + name; lString16 id = name; lString16 title = name; if ( title.endsWith( suffix ) ) title.erase( title.length() - suffix.length(), suffix.length() ); _list.add( new HyphDictionary( t, title, id, filename ) ); count++; } CRLog::info("%d dictionaries added to list", _list.length()); return true; } else { CRLog::info("no hyphenation dictionary items found in hyph directory %s", LCSTR(hyphDirectory)); } return false; }
bool open() { LVStreamRef stream = _container->OpenStream(L"META-INF/encryption.xml", LVOM_READ); if (stream.isNull()) return false; EncCallback enccallback(this); LVXMLParser parser(stream, &enccallback, false, false); if (!parser.Parse()) return false; if (_list.length()) return true; return false; }
void InitCREngineLog( const char * cfgfile ) { if ( !cfgfile ) { CRLog::setStdoutLogger(); CRLog::setLogLevel( CRLog::LL_TRACE ); return; } lString16 logfname; lString16 loglevelstr = #ifdef _DEBUG L"TRACE"; #else L"INFO"; #endif bool autoFlush = false; CRPropRef logprops = LVCreatePropsContainer(); { LVStreamRef cfg = LVOpenFileStream( cfgfile, LVOM_READ ); if ( !cfg.isNull() ) { logprops->loadFromStream( cfg.get() ); logfname = logprops->getStringDef( PROP_LOG_FILENAME, "stdout" ); loglevelstr = logprops->getStringDef( PROP_LOG_LEVEL, "TRACE" ); autoFlush = logprops->getBoolDef( PROP_LOG_AUTOFLUSH, false ); } } CRLog::log_level level = CRLog::LL_INFO; if ( loglevelstr==L"OFF" ) { level = CRLog::LL_FATAL; logfname.clear(); } else if ( loglevelstr==L"FATAL" ) { level = CRLog::LL_FATAL; } else if ( loglevelstr==L"ERROR" ) { level = CRLog::LL_ERROR; } else if ( loglevelstr==L"WARN" ) { level = CRLog::LL_WARN; } else if ( loglevelstr==L"INFO" ) { level = CRLog::LL_INFO; } else if ( loglevelstr==L"DEBUG" ) { level = CRLog::LL_DEBUG; } else if ( loglevelstr==L"TRACE" ) { level = CRLog::LL_TRACE; } if ( !logfname.empty() ) { if ( logfname==L"stdout" ) CRLog::setStdoutLogger(); else if ( logfname==L"stderr" ) CRLog::setStderrLogger(); else CRLog::setFileLogger( UnicodeToUtf8( logfname ).c_str(), autoFlush ); } CRLog::setLogLevel( level ); CRLog::trace("Log initialization done."); }
lString8 readFileToString( const char * fname ) { lString8 buf; LVStreamRef stream = LVOpenFileStream(fname, LVOM_READ); if (!stream) return buf; int sz = stream->GetSize(); if (sz>0) { buf.insert( 0, sz, ' ' ); stream->Read( buf.modify(), sz, NULL ); } return buf; }
/* * Class: org_coolreader_crengine_ReaderView * Method: setPageBackgroundTextureInternal * Signature: ([BI)V */ JNIEXPORT void JNICALL Java_org_coolreader_crengine_ReaderView_setPageBackgroundTextureInternal (JNIEnv * _env, jobject _this, jbyteArray jdata, jint tileFlags ) { CRJNIEnv env(_env); ReaderViewNative * p = getNative(_env, _this); LVImageSourceRef img; if ( jdata!=NULL ) { LVStreamRef stream = env.jbyteArrayToStream( jdata ); if ( !stream.isNull() ) { img = LVCreateStreamImageSource(stream); } } p->_docview->setBackgroundImage(img, tileFlags!=0); }
bool read( LVStreamRef stream ) { // TODO: byte order support lvsize_t bytesRead = 0; if ( stream->Read(this, sizeof(PDBHdr), &bytesRead )!=LVERR_OK ) return false; if ( bytesRead!=sizeof(PDBHdr) ) return false; lvByteOrderConv cnv; if ( cnv.lsf() ) { cnv.rev(&attributes); cnv.rev(&version); cnv.rev(&creationDate); cnv.rev(&modificationDate); cnv.rev(&lastBackupDate); cnv.rev(&modificationNumber); cnv.rev(&appInfoID); cnv.rev(&sortInfoID); cnv.rev(&uniqueIDSeed); cnv.rev(&nextRecordList); cnv.rev(&recordCount); cnv.rev(&firstEntry); } return true; }
jbyteArray CRJNIEnv::streamToJByteArray( LVStreamRef stream ) { if ( stream.isNull() ) return NULL; unsigned sz = stream->GetSize(); if ( sz<10 || sz>2000000 ) return NULL; jbyteArray array = env->NewByteArray(sz); lUInt8 * array_data = (lUInt8 *)env->GetByteArrayElements(array, 0); lvsize_t bytesRead = 0; stream->Read(array_data, sz, &bytesRead); env->ReleaseByteArrayElements(array, (jbyte*)array_data, 0); if (bytesRead != sz) return NULL; return array; }
bool HyphMan::activateDictionaryFromStream( LVStreamRef stream ) { if ( stream.isNull() ) return false; CRLog::trace("remove old hyphenation method"); if ( HyphMan::_method != &NO_HYPH && HyphMan::_method != &ALGO_HYPH && HyphMan::_method ) { delete HyphMan::_method; HyphMan::_method = &NO_HYPH; } CRLog::trace("creating new TexHyph method"); TexHyph * method = new TexHyph(); CRLog::trace("loading from file"); if ( !method->load( stream ) ) { CRLog::error("HyphMan::activateDictionaryFromStream: Cannot open hyphenation dictionary from stream" ); delete method; return false; } CRLog::debug("Dictionary is loaded successfully. Activating."); HyphMan::_method = method; if ( HyphMan::_dictList->find(lString16(HYPH_DICT_ID_DICTIONARY))==NULL ) { HyphDictionary * dict = new HyphDictionary( HDT_DICT_ALAN, cs16("Dictionary"), lString16(HYPH_DICT_ID_DICTIONARY), lString16::empty_str ); HyphMan::_dictList->add(dict); HyphMan::_selectedDictionary = dict; } CRLog::trace("Activation is done"); return true; }
bool V3DocViewWin::loadHistory( LVStreamRef stream ) { if ( stream.isNull() ) { return false; } if ( !_docview->getHistory()->loadFromStream( stream ) ) return false; return true; }
void MainWindow::onPropsChange( PropsRef props ) { for ( int i=0; i<props->count(); i++ ) { QString name = props->name( i ); QString value = props->value( i ); int v = (value != "0"); CRLog::debug("MainWindow::onPropsChange [%d] '%s'=%s ", i, props->name(i), props->value(i).toUtf8().data() ); if ( name == PROP_WINDOW_FULLSCREEN ) { bool state = windowState().testFlag(Qt::WindowFullScreen); bool vv = v ? true : false; if ( state != vv ) setWindowState( windowState() ^ Qt::WindowFullScreen ); } if ( name == PROP_WINDOW_SHOW_MENU ) { ui->menuBar->setVisible( v ); } if ( name == PROP_WINDOW_SHOW_SCROLLBAR ) { ui->scroll->setVisible( v ); } if ( name == PROP_BACKGROUND_IMAGE ) { lString16 fn = qt2cr(value); LVImageSourceRef img; if ( !fn.empty() && fn[0]!='[' ) { CRLog::debug("Background image file: %s", LCSTR(fn)); LVStreamRef stream = LVOpenFileStream(fn.c_str(), LVOM_READ); if ( !stream.isNull() ) { img = LVCreateStreamImageSource(stream); } } fn.lowercase(); bool tiled = ( fn.pos(lString16("\\textures\\"))>=0 || fn.pos(lString16("/textures/"))>=0); ui->view->getDocView()->setBackgroundImage(img, tiled); } if ( name == PROP_WINDOW_TOOLBAR_SIZE ) { ui->mainToolBar->setVisible( v ); } if ( name == PROP_WINDOW_SHOW_STATUSBAR ) { ui->statusBar->setVisible( v ); } if ( name == PROP_WINDOW_STYLE ) { QApplication::setStyle( value ); } } }
static bool GetEPUBBookProperties(const char *name, LVStreamRef stream, BookProperties * pBookProps) { LVContainerRef m_arc = LVOpenArchieve( stream ); if ( m_arc.isNull() ) return false; // not a ZIP archive // check root media type lString16 rootfilePath = EpubGetRootFilePath(m_arc); if ( rootfilePath.empty() ) return false; lString16 codeBase; codeBase=LVExtractPath(rootfilePath, false); LVStreamRef content_stream = m_arc->OpenStream(rootfilePath.c_str(), LVOM_READ); if ( content_stream.isNull() ) return false; ldomDocument * doc = LVParseXMLStream( content_stream ); if ( !doc ) return false; time_t t = (time_t)time(0); struct stat fs; if ( !stat( name, &fs ) ) { t = fs.st_mtime; } lString16 author = doc->textFromXPath( lString16("package/metadata/creator")).trim(); lString16 title = doc->textFromXPath( lString16("package/metadata/title")).trim(); lString16 language = doc->textFromXPath( lString16("package/metadata/language")).trim(); pBookProps->author = author; pBookProps->title = title; pBookProps->language = language; for ( int i=1; i<20; i++ ) { ldomNode * item = doc->nodeFromXPath( lString16("package/metadata/meta[") << fmt::decimal(i) << "]" ); if ( !item ) break; lString16 name = item->getAttributeValue("name"); lString16 content = item->getAttributeValue("content"); if (name == "calibre:series") pBookProps->series = content.trim(); else if (name == "calibre:series_index") pBookProps->seriesNumber = content.trim().atoi(); } pBookProps->filesize = (long)stream->GetSize(); pBookProps->filename = lString16(name); pBookProps->filedate = getDateTimeString( t ); delete doc; return true; }
static int getCoverPageImageData(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); LVStreamRef stream = doc->text_view->getCoverPageImageStream(); if (!stream.isNull()) { unsigned size = stream->GetSize(); lvsize_t read_size = 0; void *buffer = (void *)malloc(size); if (buffer != NULL) { stream->Read(buffer, size, &read_size); if (read_size == size) { lua_pushlightuserdata(L, buffer); lua_pushinteger(L, size); return 2; } } } return 0; }
virtual ~LVRtfPictDestination() { if (!_fmt || _buf.empty()) return; // add Image BLOB lString16 name(BLOB_NAME_PREFIX); // L"@blob#" name << L"image"; name << lString16::itoa(m_parser.nextImageIndex()); name << (_fmt==rtf_img_jpeg ? L".jpg" : L".png"); m_callback->OnBlob(name, _buf.get(), _buf.length()); #if 0 { LVStreamRef stream = LVOpenFileStream((lString16(L"/tmp/") + name).c_str(), LVOM_WRITE); stream->Write(_buf.get(), _buf.length(), NULL); } #endif m_callback->OnTagOpen(LXML_NS_NONE, L"img"); m_callback->OnAttribute(LXML_NS_NONE, L"src", name.c_str()); m_callback->OnTagClose(LXML_NS_NONE, L"img"); }
static int newDocView(lua_State *L) { int width = luaL_checkint(L, 1); int height = luaL_checkint(L, 2); LVDocViewMode view_mode = (LVDocViewMode)luaL_checkint(L, 3); CreDocument *doc = (CreDocument*) lua_newuserdata(L, sizeof(CreDocument)); luaL_getmetatable(L, "credocument"); lua_setmetatable(L, -2); doc->text_view = new LVDocView(); //doc->text_view->setBackgroundColor(0xFFFFFF); //doc->text_view->setTextColor(0x000000); //doc->text_view->doCommand(DCMD_SET_DOC_FONTS, 1); //doc->text_view->doCommand(DCMD_SET_INTERNAL_STYLES, 1); doc->text_view->setViewMode(view_mode, -1); doc->text_view->Resize(width, height); doc->text_view->setPageHeaderInfo(PGHDR_AUTHOR|PGHDR_TITLE|PGHDR_PAGE_NUMBER|PGHDR_PAGE_COUNT|PGHDR_CHAPTER_MARKS|PGHDR_CLOCK); // it will overwrite all settings by values found in ./data/cr3.ini CRPropRef props = doc->text_view->propsGetCurrent(); LVStreamRef stream = LVOpenFileStream("data/cr3.ini", LVOM_READ); if ( !stream.isNull() && props->loadFromStream(stream.get()) ) { doc->text_view->propsApply(props); } else { // Tweak the default settings to be slightly less random props->setString(PROP_FALLBACK_FONT_FACE, "Noto Sans CJK SC"); props->setString(PROP_HYPHENATION_DICT, "English_US_hyphen_(Alan).pdb"); props->setString(PROP_STATUS_FONT_FACE, "Noto Sans"); props->setString(PROP_FONT_FACE, "Noto Serif"); props->setInt(PROP_FONT_HINTING, 2); // autohint, to be conservative (some ttf fonts' bytecode is truly crappy) props->setInt(PROP_FONT_KERNING_ENABLED, 1); props->setString("styles.pre.font-face", "font-family: \"Droid Sans Mono\""); stream = LVOpenFileStream("data/cr3.ini", LVOM_WRITE); props->saveToStream(stream.get()); } doc->text_view->setBatteryIcons(getBatteryIcons(0x000000)); return 1; }
bool ReaderViewNative::saveHistory( lString16 filename ) { if ( !filename.empty() ) historyFileName = filename; if ( historyFileName.empty() ) return false; if ( _docview->isDocumentOpened() ) { CRLog::debug("ReaderViewNative::saveHistory() : saving position"); _docview->savePosition(); } CRLog::info("Trying to save history to file %s", LCSTR(historyFileName)); CRFileHist * hist = _docview->getHistory(); LVStreamRef stream = LVOpenFileStream(historyFileName.c_str(), LVOM_WRITE); if ( stream.isNull() ) { CRLog::error("Cannot create file %s for writing", LCSTR(historyFileName)); return false; } if ( _docview->isDocumentOpened() ) _docview->savePosition(); return hist->saveToStream( stream.get() ); }
void MainWindow::on_actionOpen_triggered() { QString lastPath; LVPtrVector<CRFileHistRecord> & files = ui->view->getDocView()->getHistory()->getRecords(); if ( files.length()>0 ) { lastPath = cr2qt( files[0]->getFilePath() ); } QString fileName = QFileDialog::getOpenFileName(this, tr("Open book file"), lastPath, tr("All supported formats (*.fb2 *.txt *.tcr *.rtf *.doc *.epub *.html *.htm *.chm *.zip *.pdb *.pml *.prc *.pml *.mobi);;FB2 books (*.fb2 *.fb2.zip);;Text files (*.txt);;Rich text (*.rtf);;MS Word document (*.doc);;HTML files (*.htm *.html);;EPUB files (*.epub);;CHM files (*.chm);;MOBI files (*.mobi *.prc *.azw);;PalmDOC files (*.pdb *.pml);;ZIP archives (*.zip)")); if ( fileName.length()==0 ) return; if ( !ui->view->loadDocument( fileName ) ) { // error } else { #ifdef _DEBUG LVStreamRef in = ui->view->getDocView()->getCoverPageImageStream(); if ( !in.isNull() ) { LVStreamRef out = LVOpenFileStream("/tmp/cover.png", LVOM_WRITE); if ( !out.isNull() ) { LVPumpStream( out.get(), in.get() ); } } #endif update(); } }
bool HyphDictionary::activate() { if (HyphMan::_selectedDictionary == this) return true; // already active if ( getType() == HDT_ALGORITHM ) { CRLog::info("Turn on algorythmic hyphenation" ); if ( HyphMan::_method != &ALGO_HYPH ) { if ( HyphMan::_method != &NO_HYPH ) delete HyphMan::_method; HyphMan::_method = &ALGO_HYPH; } } else if ( getType() == HDT_NONE ) { CRLog::info("Disabling hyphenation" ); if ( HyphMan::_method != &NO_HYPH ) { if ( HyphMan::_method != &ALGO_HYPH ) delete HyphMan::_method; HyphMan::_method = &NO_HYPH; } } else if ( getType() == HDT_DICT_ALAN || getType() == HDT_DICT_TEX ) { if ( HyphMan::_method != &NO_HYPH && HyphMan::_method != &ALGO_HYPH ) { delete HyphMan::_method; HyphMan::_method = &NO_HYPH; } CRLog::info("Selecting hyphenation dictionary %s", UnicodeToUtf8(_filename).c_str() ); LVStreamRef stream = LVOpenFileStream( getFilename().c_str(), LVOM_READ ); if ( stream.isNull() ) { CRLog::error("Cannot open hyphenation dictionary %s", UnicodeToUtf8(_filename).c_str() ); return false; } TexHyph * method = new TexHyph(); if ( !method->load( stream ) ) { CRLog::error("Cannot open hyphenation dictionary %s", UnicodeToUtf8(_filename).c_str() ); delete method; return false; } HyphMan::_method = method; } HyphMan::_selectedDictionary = this; return true; }
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 ); }
void V3DocViewWin::showHelpDialog() { LVStreamRef stream = LVOpenFileStream( _helpFile.c_str(), LVOM_READ ); lString8 help; if ( stream.isNull() ) { // show warning lString8 body; body << "<title><p>" << _("No manual currently available for this language, sorry!") << "</p></title>"; help = CRViewDialog::makeFb2Xml( body ); } else { int len = stream->GetSize(); if ( len>100 && len <1000000 ) { help.append( len, ' ' ); stream->Read( help.modify(), len, NULL ); } } //lString8 help = UnicodeToUtf8( LVReadTextFile( _helpFile ) ); if ( !help.empty() ) { CRViewDialog * dlg = new CRViewDialog( _wm, lString16(_("Help")), help, lvRect(), true, true ); _wm->activateWindow( dlg ); } }
/* * Class: org_coolreader_crengine_Engine * Method: setHyphenationMethod * Signature: (I[B)Z */ JNIEXPORT jboolean JNICALL Java_org_coolreader_crengine_Engine_setHyphenationMethod (JNIEnv * _env, jobject _engine, jint method, jbyteArray data) { CRJNIEnv env(_env); if ( method==0 ) { CRLog::info("Selecting hyphenation method: Disabled"); return HyphMan::activateDictionary(lString16(HYPH_DICT_ID_NONE)); } else if ( method==1 ) { CRLog::info("Selecting hyphenation method: Algoryphmic"); return HyphMan::activateDictionary(lString16(HYPH_DICT_ID_ALGORITHM)); } else { CRLog::info("Selecting hyphenation method: Dictionary"); LVStreamRef stream = env.jbyteArrayToStream( data ); CRLog::debug("Stream is created from byte array, length=%d", (int)(stream.isNull()?0:stream->GetSize())); bool res = HyphMan::activateDictionaryFromStream(stream); if ( !res ) { CRLog::error("Dictionary activation is failed: disabling hyphenation"); HyphMan::activateDictionary(lString16(HYPH_DICT_ID_NONE)); return false; } return true; } }