From 7eac8747fb14dec69a0d7bb8be103bd9ef6f5f42 Mon Sep 17 00:00:00 2001 From: Igor Slepchin Date: Thu, 2 Feb 2012 18:08:50 -0500 Subject: [PATCH] Proper unicode support when dumping PDF outline. --- utils/HtmlOutputDev.cc | 195 ++++++++++++++++++++++++++---------------------- utils/HtmlOutputDev.h | 5 +- utils/pdftohtml.cc | 2 +- 3 files changed, 109 insertions(+), 93 deletions(-) diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc index c1447ad..c571e8e 100644 --- a/utils/HtmlOutputDev.cc +++ b/utils/HtmlOutputDev.cc @@ -62,6 +62,8 @@ #include "HtmlOutputDev.h" #include "HtmlFonts.h" #include "HtmlUtils.h" +#include "Outline.h" +#include "PDFDoc.h" #define DEBUG __FILE__ << ": " << __LINE__ << ": DEBUG: " @@ -1583,17 +1585,25 @@ void HtmlOutputDev::dumpMetaVars(FILE *file) } } -GBool HtmlOutputDev::dumpDocOutline(Catalog* catalog) +GBool HtmlOutputDev::dumpDocOutline(PDFDoc* doc) { +#ifdef DISABLE_OUTLINE + return gFalse; +#else FILE * output = NULL; GBool bClose = gFalse; + Catalog *catalog = doc->getCatalog(); if (!ok || xml) - return gFalse; + return gFalse; - Object *outlines = catalog->getOutline(); - if (!outlines->isDict()) - return gFalse; + Outline *outline = doc->getOutline(); + if (!outline) + return gFalse; + + GooList *outlines = outline->getItems(); + if (!outlines) + return gFalse; if (!complexMode && !xml) { @@ -1615,7 +1625,17 @@ GBool HtmlOutputDev::dumpDocOutline(Catalog* catalog) return gFalse; delete str; bClose = gTrue; - fputs("\n\nDocument Outline\n\n\n", output); + + char *htmlEncoding = + HtmlOutputDev::mapEncodingToHtml(globalParams->getTextEncodingName()); + + fprintf(output, "\n" \ + "\n" \ + "Document Outline\n" \ + "\n" \ + "\n\n", htmlEncoding); } } @@ -1629,97 +1649,92 @@ GBool HtmlOutputDev::dumpDocOutline(Catalog* catalog) fclose(output); } return done; +#endif } -GBool HtmlOutputDev::newOutlineLevel(FILE *output, Object *node, Catalog* catalog, int level) +GBool HtmlOutputDev::newOutlineLevel(FILE *output, GooList *outlines, Catalog* catalog, int level) { - Object curr, next; - GBool atLeastOne = gFalse; - - if (node->dictLookup("First", &curr)->isDict()) { - if (level == 1) + GBool atLeastOne = gFalse; + + if (level == 1) { fputs("", output); fputs("

Document Outline

\n", output); } - fputs("",output); - return atLeastOne; + return atLeastOne; } diff --git a/utils/HtmlOutputDev.h b/utils/HtmlOutputDev.h index 474e3af..d018899 100644 --- a/utils/HtmlOutputDev.h +++ b/utils/HtmlOutputDev.h @@ -58,6 +58,7 @@ class GfxState; class GooString; +class PDFDoc; //------------------------------------------------------------------------ // HtmlString //------------------------------------------------------------------------ @@ -298,7 +299,7 @@ public: int getPageWidth() { return maxPageWidth; } int getPageHeight() { return maxPageHeight; } - GBool dumpDocOutline(Catalog* catalog); + GBool dumpDocOutline(PDFDoc* catalog); private: // convert encoding into a HTML standard, or encoding->getCString if not @@ -308,7 +309,7 @@ private: GooString* getLinkDest(AnnotLink *link,Catalog *catalog); void dumpMetaVars(FILE *); void doFrame(int firstPage); - GBool newOutlineLevel(FILE *output, Object *node, Catalog* catalog, int level = 1); + GBool newOutlineLevel(FILE *output, GooList *outlines, Catalog* catalog, int level = 1); FILE *fContentsFrame; FILE *page; // html file diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc index fa00ae1..94ad1f3 100644 --- a/utils/pdftohtml.cc +++ b/utils/pdftohtml.cc @@ -404,7 +404,7 @@ int main(int argc, char *argv[]) { gTrue, gFalse, gFalse); if (!xml) { - htmlOut->dumpDocOutline(doc->getCatalog()); + htmlOut->dumpDocOutline(doc); } } -- 1.7.7.6