1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00

expose get_linkdest_str

This commit is contained in:
Lu Wang 2013-01-28 18:31:02 +08:00
parent 4d94c1d072
commit 014ef7ecc2
3 changed files with 27 additions and 19 deletions

View File

@ -210,12 +210,14 @@ class HTMLRenderer : public OutputDev
void pre_process(PDFDoc * doc); void pre_process(PDFDoc * doc);
void post_process(); void post_process();
// set flags
void set_stream_flags (std::ostream & out); void set_stream_flags (std::ostream & out);
std::string dump_embedded_font (GfxFont * font, long long fn_id); 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); 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 // manage styles
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
@ -300,6 +302,8 @@ class HTMLRenderer : public OutputDev
XRef * xref; XRef * xref;
PDFDoc * cur_doc; PDFDoc * cur_doc;
Catalog * cur_catalog;
double default_ctm[6]; double default_ctm[6];
// page info // page info

View File

@ -69,6 +69,7 @@ HTMLRenderer::~HTMLRenderer()
void HTMLRenderer::process(PDFDoc *doc) void HTMLRenderer::process(PDFDoc *doc)
{ {
cur_doc = doc; cur_doc = doc;
cur_catalog = doc->getCatalog();
xref = doc->getXRef(); xref = doc->getXRef();
pre_process(doc); pre_process(doc);

View File

@ -30,8 +30,24 @@ using std::endl;
* The detailed rectangle area of the link destination * The detailed rectangle area of the link destination
* Will be parsed and performed by Javascript * 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; ostringstream sout;
// dec // dec
sout << "[" << pageno; sout << "[" << pageno;
@ -125,34 +141,21 @@ void HTMLRenderer::processLink(AnnotLink * al)
{ {
case actionGoTo: case actionGoTo:
{ {
auto catalog = cur_doc->getCatalog();
auto * real_action = dynamic_cast<LinkGoTo*>(action); auto * real_action = dynamic_cast<LinkGoTo*>(action);
LinkDest * dest = nullptr; LinkDest * dest = nullptr;
if(auto _ = real_action->getDest()) if(auto _ = real_action->getDest())
dest = _->copy(); dest = _->copy();
else if (auto _ = real_action->getNamedDest()) else if (auto _ = real_action->getNamedDest())
dest = catalog->findDest(_); dest = cur_catalog->findDest(_);
if(dest) if(dest)
{ {
int pageno = 0; int pageno = 0;
if(dest->isPageRef()) dest_detail_str = get_linkdest_str(pageno, dest);
{
auto pageref = dest->getPageRef();
pageno = catalog->findPage(pageref.num, pageref.gen);
}
else
{
pageno = dest->getPageNum();
}
if(pageno > 0) if(pageno > 0)
{ {
dest_str = (char*)str_fmt("#p%x", pageno); dest_str = (char*)str_fmt("#p%x", pageno);
dest_detail_str = get_dest_detail_str(pageno, dest);
} }
delete dest; delete dest;
} }
} }
break; break;
@ -178,11 +181,11 @@ void HTMLRenderer::processLink(AnnotLink * al)
} }
} }
if(dest_str != "") if(!dest_str.empty())
{ {
html_fout << "<a class=\"a\" href=\"" << dest_str << "\""; html_fout << "<a class=\"a\" href=\"" << dest_str << "\"";
if(dest_detail_str != "") if(!dest_detail_str.empty())
html_fout << " data-dest-detail='" << dest_detail_str << "'"; html_fout << " data-dest-detail='" << dest_detail_str << "'";
html_fout << ">"; html_fout << ">";