1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00
This commit is contained in:
Lu Wang 2013-02-06 20:29:48 +08:00
parent a2ed253454
commit bc80a79ac0
5 changed files with 77 additions and 20 deletions

View File

@ -58,6 +58,7 @@
}
@media print {
@page { margin:0; }
html { margin:0; }
body {
margin:0;
/* enable printing background images for WebKit */

View File

@ -139,13 +139,15 @@ protected:
// misc
////////////////////////////////////////////////////
void pre_process(PDFDoc * doc);
void post_process();
void post_process(void);
void process_outline();
void process_outline(void);
void process_outline_items(GooList * items);
void set_stream_flags (std::ostream & out);
void dump_css(void);
// convert a LinkAction to a string that our Javascript code can understand
std::string get_linkaction_str(LinkAction *, std::string & detail);
@ -222,6 +224,7 @@ protected:
XRef * xref;
PDFDoc * cur_doc;
Catalog * cur_catalog;
int pageNum;
double default_ctm[6];

View File

@ -160,8 +160,10 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
{
assert((!line_opened) && "Open line in startPage detected!");
height_manager.install(state->getPageWidth());
width_maanger.install(state->getPageHeight());
this->pageNum = pageNum;
width_manager.install(state->getPageWidth());
height_manager.install(state->getPageHeight());
f_pages.fs
<< "<div class=\"" << CSS::PAGE_DECORATION_CN
<< " " << CSS::WIDTH_CN << width_manager.get_id()
@ -191,7 +193,9 @@ 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;";
f_pages.fs << ");background-position:0 0;background-size:"
<< state->getPageWidth() << "px "
<< state->getPageHeight() << "px;background-repeat:no-repeat;";
}
f_pages.fs << "\">";
@ -340,22 +344,9 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
}
}
void HTMLRenderer::post_process()
void HTMLRenderer::post_process(void)
{
// dump css
transform_matrix_manager.dump_css(f_css.fs);
letter_space_manager .dump_css(f_css.fs);
stroke_color_manager .dump_css(f_css.fs);
word_space_manager .dump_css(f_css.fs);
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);
dump_css();
// close files
f_outline.fs.close();
f_pages.fs.close();
@ -447,6 +438,39 @@ void HTMLRenderer::set_stream_flags(std::ostream & out)
out << hex << fixed;
}
void HTMLRenderer::dump_css (void)
{
transform_matrix_manager.dump_css(f_css.fs);
letter_space_manager .dump_css(f_css.fs);
stroke_color_manager .dump_css(f_css.fs);
word_space_manager .dump_css(f_css.fs);
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);
// print css
double print_scale = 96.0 / DEFAULT_DPI / text_zoom_factor();
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);
f_css.fs << "}" << endl;
}
void HTMLRenderer::embed_file(ostream & out, const string & path, const string & type, bool copy)
{
string fn = get_filename(path);

View File

@ -23,6 +23,7 @@ const char * const INVALID_ID = "_";
// work around strings
// TODOsince we have this string, should this file be named as general "css.h" ?
const char * const WEBKIT_ONLY = "@media screen and (-webkit-min-device-pixel-ratio:0)";
const char * const PRINT_ONLY = "@media print";
// TODO: better names, remove collission (i.e LINE_CN vs LETTER_SPACE_CN)

View File

@ -65,6 +65,15 @@ public:
}
}
void dump_print_css(std::ostream & out, double scale) {
for(auto iter = value_map.begin(); iter != value_map.end(); ++iter)
{
out << "." << imp->get_css_class_name() << iter->second << "{";
imp->dump_print_value(out, iter->first, scale);
out << "}" << std::endl;
}
}
protected:
// this version of install does not check if value has been updated
// return if a new entry has been created
@ -128,6 +137,8 @@ public:
}
}
void dump_print_css(std::ostream & out, double scale) {}
protected:
// return if a new entry has been created
bool _install(const double * new_value) {
@ -214,6 +225,8 @@ public:
}
}
void dump_print_css(std::ostream & out, double scale) {}
protected:
bool _install(const GfxRGB & new_value) {
is_transparent = false;
@ -276,6 +289,7 @@ public:
static const char * get_css_class_name (void) { return CSS::FONT_SIZE_CN; }
double default_value(void) { return 0; }
void dump_value(std::ostream & out, double value) { out << "font-size:" << round(value) << "px;"; }
void dump_print_value(std::ostream & out, double value, double scale) { out << "font-size:" << round(value*scale) << "pt;"; }
};
class LetterSpaceManager : public StateManager<double, LetterSpaceManager>
@ -284,6 +298,7 @@ public:
static const char * get_css_class_name (void) { return CSS::LETTER_SPACE_CN; }
double default_value(void) { return 0; }
void dump_value(std::ostream & out, double value) { out << "letter-spacing:" << round(value) << "px;"; }
void dump_print_value(std::ostream & out, double value, double scale) { out << "letter-spacing:" << round(value*scale) << "pt;"; }
};
class WordSpaceManager : public StateManager<double, WordSpaceManager>
@ -292,6 +307,7 @@ public:
static const char * get_css_class_name (void) { return CSS::WORD_SPACE_CN;}
double default_value(void) { return 0; }
void dump_value(std::ostream & out, double value) { out << "word-spacing:" << round(value) << "px;"; }
void dump_print_value(std::ostream & out, double value, double scale) { out << "word-spacing:" << round(value*scale) << "pt;"; }
};
class RiseManager : public StateManager<double, RiseManager>
@ -300,6 +316,7 @@ public:
static const char * get_css_class_name (void) { return CSS::RISE_CN; }
double default_value(void) { return 0; }
void dump_value(std::ostream & out, double value) { out << "top:" << round(-value) << "px;"; }
void dump_print_value(std::ostream & out, double value, double scale) { out << "top:" << round(-value*scale) << "pt;"; }
};
class WhitespaceManager : public StateManager<double, WhitespaceManager>
@ -312,6 +329,13 @@ public:
: "display:inline;margin-left:")
<< round(value) << "px;";
}
void dump_print_value(std::ostream & out, double value, double scale)
{
value *= scale;
out << ((value > 0) ? "display:inline-block;width:"
: "display:inline;margin-left:")
<< round(value) << "pt;";
}
};
class WidthManager : public StateManager<double, WidthManager>
@ -320,6 +344,7 @@ 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;"; }
void dump_print_value(std::ostream & out, double value, double scale) { out << "width:" << round(value*scale) << "pt;"; }
};
class BottomManager : public StateManager<double, BottomManager>
@ -328,6 +353,7 @@ 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;"; }
void dump_print_value(std::ostream & out, double value, double scale) { out << "bottom:" << round(value*scale) << "pt;"; }
};
class HeightManager : public StateManager<double, HeightManager>
@ -336,6 +362,7 @@ public:
static const char * get_css_class_name (void) { return CSS::HEIGHT_CN; }
double default_value(void) { return 0; }
void dump_value(std::ostream & out, double value) { out << "height:" << round(value) << "px;"; }
void dump_print_value(std::ostream & out, double value, double scale) { out << "height:" << round(value*scale) << "pt;"; }
};
class LeftManager : public StateManager<double, LeftManager>
@ -344,6 +371,7 @@ public:
static const char * get_css_class_name (void) { return CSS::LEFT_CN; }
double default_value(void) { return 0; }
void dump_value(std::ostream & out, double value) { out << "left:" << round(value) << "px;"; }
void dump_print_value(std::ostream & out, double value, double scale) { out << "left:" << round(value*scale) << "pt;"; }
};
class TransformMatrixManager : public StateManager<Matrix, TransformMatrixManager>