1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-21 20:50:07 +00:00

more state managers

This commit is contained in:
Lu Wang 2013-02-06 20:09:40 +08:00
parent b98ab8781e
commit a2ed253454
7 changed files with 44 additions and 24 deletions

2
TODO
View File

@ -1,5 +1,5 @@
optimize font_size & transform matrix tracking
c++ classes for different states
print css for draw/link/image...
== Future: ==

View File

@ -225,11 +225,6 @@ protected:
double default_ctm[6];
// page info
int pageNum;
double pageWidth ;
double pageHeight ;
/*
* The content of each page is first scaled with factor1 (>=1), then scale back with factor2(<=1)
*
@ -292,7 +287,9 @@ protected:
WordSpaceManager word_space_manager;
FillColorManager fill_color_manager;
FontSizeManager font_size_manager;
BottomManager bottom_manager;
HeightManager height_manager;
WidthManager width_manager;
RiseManager rise_manager;
LeftManager left_manager;
////////////////////////////////////////////////

View File

@ -85,15 +85,14 @@ void HTMLRenderer::TextLineBuffer::flush(void)
ostream & out = renderer->f_pages.fs;
renderer->height_manager.install(max_ascent);
renderer->left_manager.install(x);
renderer->left_manager .install(x);
renderer->bottom_manager.install(y);
out << "<div style=\""
<< "bottom:" << round(y) << "px;"
<< "\""
<< " class=\"" << CSS::LINE_CN
<< " " << CSS::TRANSFORM_MATRIX_CN << tm_id
<< " " << CSS::LEFT_CN << renderer->left_manager.get_id()
<< " " << CSS::HEIGHT_CN << renderer->height_manager.get_id()
out << "<div class=\"" << CSS::LINE_CN
<< " " << CSS::TRANSFORM_MATRIX_CN << tm_id
<< " " << CSS::LEFT_CN << renderer->left_manager .get_id()
<< " " << CSS::HEIGHT_CN << renderer->height_manager.get_id()
<< " " << CSS::BOTTOM_CN << renderer->bottom_manager.get_id()
<< "\">";
auto cur_state_iter = states.begin();

View File

@ -61,8 +61,10 @@ HTMLRenderer::HTMLRenderer(const Param * param)
word_space_manager .set_eps(EPS);
rise_manager .set_eps(param->v_eps);
whitespace_manager .set_eps(param->h_eps);
height_manager .set_eps(EPS);
left_manager .set_eps(param->h_eps);
height_manager .set_eps(EPS);
width_manager .set_eps(EPS);
bottom_manager .set_eps(EPS);
}
HTMLRenderer::~HTMLRenderer()
@ -156,18 +158,17 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state)
void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
{
this->pageNum = pageNum;
this->pageWidth = state->getPageWidth();
this->pageHeight = state->getPageHeight();
assert((!line_opened) && "Open line in startPage detected!");
height_manager.install(state->getPageWidth());
width_maanger.install(state->getPageHeight());
f_pages.fs
<< "<div class=\"" << CSS::PAGE_DECORATION_CN
<< "\" style=\"width:"
<< (pageWidth) << "px;height:"
<< (pageHeight) << "px;\">"
<< "<div id=\"" << CSS::PAGE_FRAME_CN << pageNum << "\" data-page-no=\"" << pageNum << "\" class=\"p\">"
<< " " << CSS::WIDTH_CN << width_manager.get_id()
<< " " << CSS::HEIGHT_CN << height_manager.get_id()
<< "\">"
<< "<div id=\"" << CSS::PAGE_FRAME_CN << pageNum
<< "\" data-page-no=\"" << pageNum << "\" class=\"p\">"
<< "<div class=\"" << CSS::PAGE_CONTENT_BOX_CN << "\" style=\"";
if(param->process_nontext)
@ -189,6 +190,7 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
}
}
// TODO print css
f_pages.fs << ");background-position:0 0;background-size:" << pageWidth << "px " << pageHeight << "px;background-repeat:no-repeat;";
}
@ -348,7 +350,9 @@ void HTMLRenderer::post_process()
whitespace_manager .dump_css(f_css.fs);
fill_color_manager .dump_css(f_css.fs);
font_size_manager .dump_css(f_css.fs);
bottom_manager .dump_css(f_css.fs);
height_manager .dump_css(f_css.fs);
width_manager .dump_css(f_css.fs);
rise_manager .dump_css(f_css.fs);
left_manager .dump_css(f_css.fs);

View File

@ -109,7 +109,9 @@ void HTMLRenderer::reset_state()
whitespace_manager .reset();
fill_color_manager .reset();
font_size_manager .reset();
bottom_manager .reset();
height_manager .reset();
width_manager .reset();
rise_manager .reset();
left_manager .reset();

View File

@ -46,8 +46,10 @@ const char * const LETTER_SPACE_CN = "l";
const char * const WORD_SPACE_CN = "w";
const char * const RISE_CN = "r";
const char * const WHITESPACE_CN = "_";
const char * const HEIGHT_CN = "h";
const char * const LEFT_CN = "L";
const char * const HEIGHT_CN = "h";
const char * const WIDTH_CN = "W";
const char * const BOTTOM_CN = "B";
const char * const CSS_DRAW_CN = "Cd";
const char * const LINK_CN = "a";

View File

@ -314,6 +314,22 @@ public:
}
};
class WidthManager : public StateManager<double, WidthManager>
{
public:
static const char * get_css_class_name (void) { return CSS::WIDTH_CN; }
double default_value(void) { return 0; }
void dump_value(std::ostream & out, double value) { out << "width:" << round(value) << "px;"; }
};
class BottomManager : public StateManager<double, BottomManager>
{
public:
static const char * get_css_class_name (void) { return CSS::BOTTOM_CN; }
double default_value(void) { return 0; }
void dump_value(std::ostream & out, double value) { out << "bottom:" << round(value) << "px;"; }
};
class HeightManager : public StateManager<double, HeightManager>
{
public: