diff --git a/src/HTMLRenderer/HTMLRenderer.h b/src/HTMLRenderer/HTMLRenderer.h
index 04b190a..59f17b3 100644
--- a/src/HTMLRenderer/HTMLRenderer.h
+++ b/src/HTMLRenderer/HTMLRenderer.h
@@ -210,12 +210,14 @@ class HTMLRenderer : public OutputDev
void pre_process(PDFDoc * doc);
void post_process();
- // set flags
void set_stream_flags (std::ostream & out);
std::string dump_embedded_font (GfxFont * font, long long fn_id);
void embed_font(const std::string & filepath, GfxFont * font, FontInfo & info, bool get_metric_only = false);
+ // convert a LinkDest to a string that our Javascript code can understand
+ std::string get_linkdest_str(int & pageno, LinkDest * dest);
+
////////////////////////////////////////////////////
// manage styles
////////////////////////////////////////////////////
@@ -300,6 +302,8 @@ class HTMLRenderer : public OutputDev
XRef * xref;
PDFDoc * cur_doc;
+ Catalog * cur_catalog;
+
double default_ctm[6];
// page info
diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc
index 7d35f6c..f588f1b 100644
--- a/src/HTMLRenderer/general.cc
+++ b/src/HTMLRenderer/general.cc
@@ -69,6 +69,7 @@ HTMLRenderer::~HTMLRenderer()
void HTMLRenderer::process(PDFDoc *doc)
{
cur_doc = doc;
+ cur_catalog = doc->getCatalog();
xref = doc->getXRef();
pre_process(doc);
diff --git a/src/HTMLRenderer/link.cc b/src/HTMLRenderer/link.cc
index fa78b9e..d64d513 100644
--- a/src/HTMLRenderer/link.cc
+++ b/src/HTMLRenderer/link.cc
@@ -30,8 +30,24 @@ using std::endl;
* The detailed rectangle area of the link destination
* Will be parsed and performed by Javascript
*/
-static string get_dest_detail_str(int pageno, LinkDest * dest)
+string HTMLRenderer::get_linkdest_str(int & pageno, LinkDest * dest)
{
+ pageno = 0;
+ if(dest->isPageRef())
+ {
+ auto pageref = dest->getPageRef();
+ pageno = cur_catalog->findPage(pageref.num, pageref.gen);
+ }
+ else
+ {
+ pageno = dest->getPageNum();
+ }
+
+ if(pageno <= 0)
+ {
+ return "";
+ }
+
ostringstream sout;
// dec
sout << "[" << pageno;
@@ -125,34 +141,21 @@ void HTMLRenderer::processLink(AnnotLink * al)
{
case actionGoTo:
{
- auto catalog = cur_doc->getCatalog();
auto * real_action = dynamic_cast(action);
LinkDest * dest = nullptr;
if(auto _ = real_action->getDest())
dest = _->copy();
else if (auto _ = real_action->getNamedDest())
- dest = catalog->findDest(_);
+ dest = cur_catalog->findDest(_);
if(dest)
{
int pageno = 0;
- if(dest->isPageRef())
- {
- auto pageref = dest->getPageRef();
- pageno = catalog->findPage(pageref.num, pageref.gen);
- }
- else
- {
- pageno = dest->getPageNum();
- }
-
+ dest_detail_str = get_linkdest_str(pageno, dest);
if(pageno > 0)
{
dest_str = (char*)str_fmt("#p%x", pageno);
- dest_detail_str = get_dest_detail_str(pageno, dest);
}
-
delete dest;
-
}
}
break;
@@ -178,11 +181,11 @@ void HTMLRenderer::processLink(AnnotLink * al)
}
}
- if(dest_str != "")
+ if(!dest_str.empty())
{
html_fout << "";