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:
parent
4d94c1d072
commit
014ef7ecc2
@ -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
|
||||
|
@ -69,6 +69,7 @@ HTMLRenderer::~HTMLRenderer()
|
||||
void HTMLRenderer::process(PDFDoc *doc)
|
||||
{
|
||||
cur_doc = doc;
|
||||
cur_catalog = doc->getCatalog();
|
||||
xref = doc->getXRef();
|
||||
|
||||
pre_process(doc);
|
||||
|
@ -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<LinkGoTo*>(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 << "<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 << ">";
|
||||
|
Loading…
Reference in New Issue
Block a user