use of org.ebookdroid.core.codec.CodecContext in project LibreraReader by foobnix.
the class MultyDocSearchDialog method searchInThePDF.
public static int searchInThePDF(String path, String text, final Handler update1) {
try {
text = text.toLowerCase(Locale.US);
CodecContext ctx = BookType.getCodecContextByPath(path);
CodecDocument openDocument = null;
CacheZipUtils.cacheLock.lock();
try {
String zipPath = CacheZipUtils.extracIfNeed(path, CacheDir.ZipApp).unZipPath;
openDocument = ctx.openDocument(zipPath, "");
LOG.d("searchInThePDF", openDocument, zipPath);
} finally {
CacheZipUtils.cacheLock.unlock();
}
if (!Model.get().isSearcingRun) {
openDocument.recycle();
ctx.recycle();
return -1;
}
int pageCount = openDocument.getPageCount();
Model.get().currentPagesCount = pageCount;
Model.get().currentDoc = new File(path).getName();
LOG.d("searchInThePDF", "pageCount", Model.get().currentPagesCount, Model.get().currentDoc);
int emptyCount = 0;
for (int i = 0; i < pageCount; i++) {
if (!Model.get().isSearcingRun) {
openDocument.recycle();
ctx.recycle();
return -1;
}
CodecPage page = openDocument.getPage(i);
TextWord[][] textPage = page.getText();
LOG.d("searchInThePDF", "getText", textPage != null ? textPage.length : "null");
if (textPage == null || textPage.length <= 1) {
emptyCount++;
if (emptyCount >= 5) {
LOG.d("searchInThePDF", "Page is empty", emptyCount);
break;
}
}
List<TextWord> findText = Page.findText(text, textPage);
page.recycle();
page = null;
Model.get().currentPage = i;
update1.sendEmptyMessage(0);
if (!findText.isEmpty()) {
openDocument.recycle();
ctx.recycle();
findText = null;
openDocument = null;
ctx = null;
return i;
}
findText = null;
}
openDocument.recycle();
ctx.recycle();
openDocument = null;
ctx = null;
System.gc();
} catch (Exception e) {
LOG.e(e);
}
return -1;
}
use of org.ebookdroid.core.codec.CodecContext in project LibreraReader by foobnix.
the class ImageExtractor method singleCodecContext.
public static synchronized CodecDocument singleCodecContext(final String path, String passw, int w, int h) {
try {
CodecContext codecContex = BookType.getCodecContextByPath(path);
LOG.d("CodecContext", codecContex);
if (codecContex == null) {
return null;
}
TempHolder.get().loadingCancelled = false;
return codecContex.openDocument(path, passw);
} catch (RuntimeException e) {
LOG.e(e);
return null;
}
}
use of org.ebookdroid.core.codec.CodecContext in project LibreraReader by foobnix.
the class ZipContext method openDocumentInner.
@Override
public CodecDocument openDocumentInner(String fileName, String password) {
LOG.d("ZipContext begin", fileName);
Pair<Boolean, String> pack = CacheZipUtils.isSingleAndSupportEntryFile(new File(fileName));
if (pack.first) {
LOG.d("ZipContext", "Singe archive entry");
Fb2Context fb2Context = new Fb2Context();
String etryPath = pack.second;
File cacheFileName = fb2Context.getCacheFileName(new File(CacheDir.ZipApp.getDir(), etryPath).getPath());
LOG.d("ZipContext", etryPath, cacheFileName.getName());
if (cacheFileName.exists()) {
LOG.d("ZipContext", "FB2 cache exists");
return fb2Context.openDocumentInner(etryPath, password);
}
}
String path = CacheZipUtils.extracIfNeed(fileName, CacheDir.ZipApp).unZipPath;
if (path.endsWith("zip")) {
return null;
}
CodecContext ctx = BookType.getCodecContextByPath(path);
LOG.d("ZipContext", "open", path);
return ctx.openDocument(path, password);
}
Aggregations