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

background image css for print

This commit is contained in:
Lu Wang 2013-02-28 22:37:15 +08:00
parent c32cb95c45
commit f982a6964c
4 changed files with 63 additions and 20 deletions

View File

@ -109,6 +109,8 @@
-moz-transform-origin:0% 0%;
-webkit-transform-origin:0% 0%;
-o-transform-origin:0% 0%;
background-position:0 0;
background-repeat:no-repeat;
}
.@CSS_PAGE_CONTENT_BOX_CN@.opened { /* used by pdf2htmlEX.js, to show/hide pages */
display:block;

View File

@ -241,6 +241,9 @@ protected:
double text_scale_factor1;
double text_scale_factor2;
// 1px on screen should be printed as print_scale()pt
double print_scale (void) const { return 96.0 / DEFAULT_DPI / text_zoom_factor(); }
////////////////////////////////////////////////////
// states
@ -294,6 +297,7 @@ protected:
RiseManager rise_manager;
LeftManager left_manager;
////////////////////////////////////////////////
BGImageSizeManager bgimage_size_manager;
// optimize for web
// we try to render the final font size directly

View File

@ -172,12 +172,13 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
<< "<div id=\"" << CSS::PAGE_FRAME_CN << pageNum
<< "\" class=\"" << CSS::PAGE_FRAME_CN
<< "\" data-page-no=\"" << pageNum << "\">"
<< "<div class=\"" << CSS::PAGE_CONTENT_BOX_CN << "\" style=\"";
<< "<div class=\"" << CSS::PAGE_CONTENT_BOX_CN
<< " " << CSS::PAGE_CONTENT_BOX_CN << pageNum
<< "\" style=\"";
if(param->process_nontext)
{
f_pages.fs << "background-image:url(";
{
if(param->single_html)
{
@ -192,11 +193,8 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
f_pages.fs << str_fmt("p%x.png", pageNum);
}
}
// TODO print css
f_pages.fs << ");background-position:0 0;background-size:"
<< state->getPageWidth() << "px "
<< state->getPageHeight() << "px;background-repeat:no-repeat;";
f_pages.fs << ");";
bgimage_size_manager.install(pageNum, state->getPageWidth(), state->getPageHeight());
}
f_pages.fs << "\">";
@ -461,22 +459,24 @@ void HTMLRenderer::dump_css (void)
width_manager .dump_css(f_css.fs);
rise_manager .dump_css(f_css.fs);
left_manager .dump_css(f_css.fs);
bgimage_size_manager.dump_css(f_css.fs);
// print css
double print_scale = 96.0 / DEFAULT_DPI / text_zoom_factor();
double ps = print_scale();
f_css.fs << CSS::PRINT_ONLY << "{" << endl;
transform_matrix_manager.dump_print_css(f_css.fs, print_scale);
letter_space_manager .dump_print_css(f_css.fs, print_scale);
stroke_color_manager .dump_print_css(f_css.fs, print_scale);
word_space_manager .dump_print_css(f_css.fs, print_scale);
whitespace_manager .dump_print_css(f_css.fs, print_scale);
fill_color_manager .dump_print_css(f_css.fs, print_scale);
font_size_manager .dump_print_css(f_css.fs, print_scale);
bottom_manager .dump_print_css(f_css.fs, print_scale);
height_manager .dump_print_css(f_css.fs, print_scale);
width_manager .dump_print_css(f_css.fs, print_scale);
rise_manager .dump_print_css(f_css.fs, print_scale);
left_manager .dump_print_css(f_css.fs, print_scale);
transform_matrix_manager.dump_print_css(f_css.fs, ps);
letter_space_manager .dump_print_css(f_css.fs, ps);
stroke_color_manager .dump_print_css(f_css.fs, ps);
word_space_manager .dump_print_css(f_css.fs, ps);
whitespace_manager .dump_print_css(f_css.fs, ps);
fill_color_manager .dump_print_css(f_css.fs, ps);
font_size_manager .dump_print_css(f_css.fs, ps);
bottom_manager .dump_print_css(f_css.fs, ps);
height_manager .dump_print_css(f_css.fs, ps);
width_manager .dump_print_css(f_css.fs, ps);
rise_manager .dump_print_css(f_css.fs, ps);
left_manager .dump_print_css(f_css.fs, ps);
bgimage_size_manager.dump_print_css(f_css.fs, ps);
f_css.fs << "}" << endl;
}

View File

@ -453,6 +453,43 @@ public:
}
};
/////////////////////////////////////
/*
* Manage the background image sizes
* Kind of similar with StateManager, but not exactly the same
* anyway temporarly leave it here
*/
class BGImageSizeManager
{
public:
void install(int page_no, double width, double height){
value_map.insert(std::make_pair(page_no, std::make_pair(width, height)));
}
void dump_css(std::ostream & out) {
for(auto iter = value_map.begin(); iter != value_map.end(); ++iter)
{
const auto & s = iter->second;
out << "." << CSS::PAGE_CONTENT_BOX_CN << iter->first << "{";
out << "background-size:" << round(s.first) << "px " << round(s.second) << "px;";
out << "}" << std::endl;
}
}
void dump_print_css(std::ostream & out, double scale) {
for(auto iter = value_map.begin(); iter != value_map.end(); ++iter)
{
const auto & s = iter->second;
out << "." << CSS::PAGE_CONTENT_BOX_CN << iter->first << "{";
out << "background-size:" << round(s.first * scale) << "pt " << round(s.second * scale) << "pt;";
out << "}" << std::endl;
}
}
private:
std::unordered_map<int, std::pair<double,double>> value_map;
};
} // namespace pdf2htmlEX
#endif //STATEMANAGER_H__