mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
process outline
This commit is contained in:
parent
e0c859188e
commit
a9bc242c1c
@ -154,6 +154,7 @@ add_executable(pdf2htmlEX
|
||||
src/HTMLRenderer/TextLineBuffer.h
|
||||
src/HTMLRenderer/TextLineBuffer.cc
|
||||
src/HTMLRenderer/link.cc
|
||||
src/HTMLRenderer/outline.cc
|
||||
src/HTMLRenderer/state.cc
|
||||
src/HTMLRenderer/text.cc
|
||||
src/BackgroundRenderer/BackgroundRenderer.h
|
||||
|
@ -1,10 +1,18 @@
|
||||
/* Base CSS */
|
||||
/* Copyright 2012 Lu Wang <coolwanglu@gmail.com> */
|
||||
#pdf-main { /* PDF container */
|
||||
#pdf-outline { /* PDF Outline */
|
||||
position:absolute;
|
||||
top:0;
|
||||
left:0;
|
||||
bottom:0;
|
||||
width:200px;
|
||||
overflow:auto;
|
||||
}
|
||||
#pdf-main { /* PDF container */
|
||||
position:absolute;
|
||||
top:0;
|
||||
left:200px;
|
||||
bottom:0;
|
||||
right:0;
|
||||
overflow:auto;
|
||||
background-color:grey;
|
||||
|
@ -129,7 +129,8 @@ var pdf2htmlEX = (function(){
|
||||
|
||||
//this.zoom_fixer();
|
||||
|
||||
this.container.on('click', '.a', this, this.annot_link_handler);
|
||||
// used by outline/annot_link etc
|
||||
this.container.on('click', '.a', this, this.link_handler);
|
||||
|
||||
this.render();
|
||||
},
|
||||
@ -231,7 +232,7 @@ var pdf2htmlEX = (function(){
|
||||
return this.pages[(new Page(obj.closest('.p')[0])).n];
|
||||
},
|
||||
|
||||
annot_link_handler : function (e) {
|
||||
link_handler : function (e) {
|
||||
var _ = e.data;
|
||||
var t = $(e.currentTarget);
|
||||
var cur_page = _.get_containing_page(t);
|
||||
|
@ -212,13 +212,16 @@ class HTMLRenderer : public OutputDev
|
||||
void pre_process(PDFDoc * doc);
|
||||
void post_process();
|
||||
|
||||
void process_outline();
|
||||
void process_outline_items(GooList * items);
|
||||
|
||||
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);
|
||||
// convert a LinkAction to a string that our Javascript code can understand
|
||||
std::string get_linkaction_str(LinkAction *, std::string & detail);
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// manage styles
|
||||
|
@ -74,6 +74,9 @@ void HTMLRenderer::process(PDFDoc *doc)
|
||||
|
||||
pre_process(doc);
|
||||
|
||||
///////////////////
|
||||
// Process pages
|
||||
|
||||
BackgroundRenderer * bg_renderer = nullptr;
|
||||
if(param->process_nontext)
|
||||
{
|
||||
@ -120,6 +123,10 @@ void HTMLRenderer::process(PDFDoc *doc)
|
||||
cerr << "Working: " << page_count << "/" << page_count;
|
||||
cerr << endl;
|
||||
|
||||
////////////////////////
|
||||
// Process Outline
|
||||
process_outline();
|
||||
|
||||
post_process();
|
||||
|
||||
if(bg_renderer)
|
||||
|
@ -29,14 +29,16 @@ using std::endl;
|
||||
/*
|
||||
* The detailed rectangle area of the link destination
|
||||
* Will be parsed and performed by Javascript
|
||||
* The string will be put into a HTML attribute, surrounded by single quotes
|
||||
* So pay attention to the characters used here
|
||||
*/
|
||||
string HTMLRenderer::get_linkdest_str(int & pageno, LinkDest * dest)
|
||||
static string get_linkdest_detail_str(LinkDest * dest, Catalog * catalog, int & pageno)
|
||||
{
|
||||
pageno = 0;
|
||||
if(dest->isPageRef())
|
||||
{
|
||||
auto pageref = dest->getPageRef();
|
||||
pageno = cur_catalog->findPage(pageref.num, pageref.gen);
|
||||
pageno = catalog->findPage(pageref.num, pageref.gen);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -125,15 +127,10 @@ string HTMLRenderer::get_linkdest_str(int & pageno, LinkDest * dest)
|
||||
return sout.str();
|
||||
}
|
||||
|
||||
/*
|
||||
* Based on pdftohtml from poppler
|
||||
* TODO: CSS for link rectangles
|
||||
* TODO: share rectangle draw with css-draw
|
||||
*/
|
||||
void HTMLRenderer::processLink(AnnotLink * al)
|
||||
string HTMLRenderer::get_linkaction_str(LinkAction * action, string & detail)
|
||||
{
|
||||
std::string dest_str, dest_detail_str;
|
||||
auto action = al->getAction();
|
||||
string dest_str;
|
||||
detail = "";
|
||||
if(action)
|
||||
{
|
||||
auto kind = action->getKind();
|
||||
@ -150,7 +147,7 @@ void HTMLRenderer::processLink(AnnotLink * al)
|
||||
if(dest)
|
||||
{
|
||||
int pageno = 0;
|
||||
dest_detail_str = get_linkdest_str(pageno, dest);
|
||||
detail = get_linkdest_detail_str(dest, cur_catalog, pageno);
|
||||
if(pageno > 0)
|
||||
{
|
||||
dest_str = (char*)str_fmt("#p%x", pageno);
|
||||
@ -181,6 +178,19 @@ void HTMLRenderer::processLink(AnnotLink * al)
|
||||
}
|
||||
}
|
||||
|
||||
return dest_str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Based on pdftohtml from poppler
|
||||
* TODO: CSS for link rectangles
|
||||
* TODO: share rectangle draw with css-draw
|
||||
*/
|
||||
void HTMLRenderer::processLink(AnnotLink * al)
|
||||
{
|
||||
string dest_detail_str;
|
||||
string dest_str = get_linkaction_str(al->getAction(), dest_detail_str);
|
||||
|
||||
if(!dest_str.empty())
|
||||
{
|
||||
f_pages.fs << "<a class=\"a\" href=\"" << dest_str << "\"";
|
||||
|
72
src/HTMLRenderer/outline.cc
Normal file
72
src/HTMLRenderer/outline.cc
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* outline.cc
|
||||
*
|
||||
* Handling Outline items
|
||||
*
|
||||
* by WangLu
|
||||
* 2013.01.28
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <Outline.h>
|
||||
#include <goo/GooList.h>
|
||||
|
||||
#include "HTMLRenderer.h"
|
||||
#include "util/namespace.h"
|
||||
#include "util/unicode.h"
|
||||
|
||||
namespace pdf2htmlEX {
|
||||
|
||||
using std::ostream;
|
||||
|
||||
void HTMLRenderer::process_outline_items(GooList * items)
|
||||
{
|
||||
if((!items) || (items->getLength() == 0))
|
||||
return;
|
||||
|
||||
f_outline.fs << "<ul>";
|
||||
|
||||
for(int i = 0; i < items->getLength(); ++i)
|
||||
{
|
||||
OutlineItem * item = (OutlineItem*)(items->get(i));
|
||||
|
||||
string detail;
|
||||
string dest = get_linkaction_str(item->getAction(), detail);
|
||||
|
||||
// we don't care dest is empty or not.
|
||||
f_outline.fs << "<li>"
|
||||
<< "<a href=\"" << dest << "\"";
|
||||
|
||||
if(!detail.empty())
|
||||
f_outline.fs << " data-dest-detail='" << detail << "'";
|
||||
|
||||
f_outline.fs << ">";
|
||||
|
||||
outputUnicodes(f_outline.fs, item->getTitle(), item->getTitleLength());
|
||||
|
||||
f_outline.fs << "</a>";
|
||||
|
||||
// check kids
|
||||
item->open();
|
||||
if(item->hasKids())
|
||||
{
|
||||
process_outline_items(item->getKids());
|
||||
}
|
||||
item->close();
|
||||
f_outline.fs << "</li>";
|
||||
}
|
||||
|
||||
f_outline.fs << "</ul>";
|
||||
}
|
||||
|
||||
void HTMLRenderer::process_outline()
|
||||
{
|
||||
Outline * outline = cur_doc->getOutline();
|
||||
if(!outline)
|
||||
return;
|
||||
|
||||
process_outline_items(outline->getItems());
|
||||
}
|
||||
|
||||
}// namespace pdf2htmlEX
|
@ -33,6 +33,9 @@ Unicode unicode_from_font (CharCode code, GfxFont * font);
|
||||
*/
|
||||
Unicode check_unicode(Unicode * u, int len, CharCode code, GfxFont * font);
|
||||
|
||||
/*
|
||||
* Escape necessary characters, and map Unicode to UTF-8
|
||||
*/
|
||||
void outputUnicodes(std::ostream & out, const Unicode * u, int uLen);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user