use of org.ebookdroid.core.codec.OutlineLink in project LibreraReader by foobnix.
the class MuPdfOutline method ttOutline.
private void ttOutline(final List<OutlineLink> ls, long outline, final int level) {
while (outline != -1) {
final String title = getTitle(outline);
final String link = getLink(outline, docHandle);
String linkUri = getLinkUri(outline, docHandle);
LOG.d("linkUri", linkUri);
if (title != null) {
final OutlineLink outlineLink = new OutlineLink(title, link, level, docHandle, linkUri);
boolean toAdd = true;
if (AppState.get().outlineMode == AppState.OUTLINE_ONLY_HEADERS) {
if (outlineLink.getTitle().contains("[subtitle]")) {
toAdd = false;
}
}
outlineLink.setTitle(outlineLink.getTitle().replace("[title]", "").replace("[subtitle]", ""));
if (outlineLink.getTitle().contains(Fb2Extractor.DIVIDER)) {
try {
String[] split = outlineLink.getTitle().split(Fb2Extractor.DIVIDER);
int level2 = Integer.parseInt(split[0]);
outlineLink.setLevel(level2);
outlineLink.setTitle(split[1]);
} catch (Exception e) {
LOG.e(e);
}
}
if (toAdd) {
ls.add(outlineLink);
}
}
final long child = getChild(outline);
ttOutline(ls, child, level + 1);
outline = getNext(outline);
}
}
use of org.ebookdroid.core.codec.OutlineLink in project LibreraReader by foobnix.
the class ExtUtils method openPDFInTextReflowAsync.
public static File openPDFInTextReflowAsync(Activity a, final File file, Handler dialog) {
try {
File bookTempRoot = new File(AppState.get().downlodsPath, file.getName());
if (!bookTempRoot.exists()) {
bookTempRoot.mkdirs();
} else {
CacheZipUtils.removeFiles(bookTempRoot.listFiles());
}
String pwd = "";
try {
pwd = a.getIntent().getStringExtra(HorizontalModeController.EXTRA_PASSWORD);
if (pwd == null) {
pwd = "";
}
} catch (Exception e) {
LOG.e(e);
}
CodecDocument doc = BookType.getCodecContextByPath(file.getPath()).openDocument(file.getPath(), pwd);
List<OutlineLink> outline = doc.getOutline();
final File fileReflowHtml = new File(bookTempRoot, "temp" + REFLOW_HTML);
try {
FileWriter fout = new FileWriter(fileReflowHtml);
BufferedWriter out = new BufferedWriter(fout);
out.write("<html>");
out.write("<head><meta charset=\"utf-8\"/></head>");
out.write("<body>");
int pages = doc.getPageCount();
int imgCount = 0;
for (int i = 0; i < pages; i++) {
LOG.d("Extract page", i);
CodecPage pageCodec = doc.getPage(i);
String html = pageCodec.getPageHTMLWithImages();
out.write("<a id=\"" + i + "\"></a>");
html = TxtUtils.replaceEndLine(html);
int startImage = html.indexOf(IMAGE_BEGIN);
while (startImage >= 0) {
if (!TempHolder.get().isConverting) {
CacheZipUtils.removeFiles(bookTempRoot.listFiles());
bookTempRoot.delete();
break;
}
imgCount++;
LOG.d("Extract image", imgCount);
int endImage = html.indexOf(IMAGE_END, startImage);
String mime = html.substring(startImage + IMAGE_BEGIN.length(), endImage);
String format;
if (mime.startsWith(IMAGE_JPEG_BASE64)) {
format = ".jpg";
mime = mime.replace(IMAGE_JPEG_BASE64, "");
} else if (mime.startsWith(IMAGE_PNG_BASE64)) {
format = ".png";
mime = mime.replace(IMAGE_PNG_BASE64, "");
} else {
format = ".none";
}
// FileOutputStream mimeOut = new FileOutputStream(new File(bookTempRoot, "mime"
// + imgCount + ".mime"));
// mimeOut.write(mime.getBytes());
// mimeOut.close();
byte[] decode = Base64.decode(mime, Base64.DEFAULT);
String imageName = imgCount + format;
LOG.d("Extract-mime", mime.substring(mime.length() - 10, mime.length()));
FileOutputStream imgStream = new FileOutputStream(new File(bookTempRoot, imageName));
imgStream.write(decode);
imgStream.close();
html = html.substring(0, startImage) + "<img src=\"" + imageName + "\"/>" + html.substring(endImage + IMAGE_END.length());
startImage = html.indexOf(IMAGE_BEGIN);
LOG.d("startImage", startImage);
}
// out.write(TextUtils.htmlEncode(html));
// html = html.replace("< ", "< ");
// html = html.replace("> ", "> ");
// html = html.replace("&", "&");
out.write(html);
pageCodec.recycle();
LOG.d("Extract page end1", i);
dialog.sendEmptyMessage(((i + 1) * 100) / pages);
if (!TempHolder.get().isConverting) {
CacheZipUtils.removeFiles(bookTempRoot.listFiles());
bookTempRoot.delete();
break;
}
}
doc.recycle();
out.write("</body></html>");
out.flush();
out.close();
fout.close();
} catch (Exception e) {
LOG.e(e);
return null;
}
File epubOutpub = new File(AppState.get().downlodsPath, file.getName() + REFLOW_EPUB);
if (epubOutpub.isFile()) {
epubOutpub.delete();
}
FileMeta meta = AppDB.get().getOrCreate(file.getPath());
Fb2Extractor.convertFolderToEpub(bookTempRoot, epubOutpub, meta.getAuthor(), meta.getTitle(), outline);
CacheZipUtils.removeFiles(bookTempRoot.listFiles());
bookTempRoot.delete();
if (!TempHolder.get().isConverting) {
epubOutpub.delete();
LOG.d("Delete temp file", fileReflowHtml.getPath());
}
LOG.d("openPDFInTextReflow", fileReflowHtml.getPath());
return epubOutpub;
} catch (RuntimeException e) {
LOG.e(e);
return null;
}
}
Aggregations