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-05 14:45:40 +08:00
parent 9dca488d96
commit 82c0e28853
7 changed files with 18 additions and 39 deletions

View File

@ -168,7 +168,6 @@ class HTMLRenderer : public OutputDev
long long install_fill_color(const GfxRGB * rgb);
long long install_stroke_color(const GfxRGB * rgb);
long long install_whitespace(double ws_width, double & actual_width);
long long install_rise(double rise);
long long install_height(double height);
long long install_left(double left);
@ -187,7 +186,6 @@ class HTMLRenderer : public OutputDev
void export_fill_color(long long color_id, const GfxRGB * rgb);
void export_stroke_color(long long color_id, const GfxRGB * rgb);
void export_whitespace(long long ws_id, double ws_width);
void export_rise(long long rise_id, double rise);
void export_height(long long height_id, double height);
void export_left(long long left_id, double left);
@ -319,9 +317,8 @@ class HTMLRenderer : public OutputDev
bool stroke_color_changed;
// rise
long long cur_rise_id;
double cur_rise;
bool rise_changed;
RiseManager rise_manager;
// optimize for web
// we try to render the final font size directly
@ -359,11 +356,9 @@ class HTMLRenderer : public OutputDev
////////////////////////////////////////////////////
std::unordered_map<long long, FontInfo> font_name_map;
std::map<double, long long> font_size_map;
std::map<Matrix, long long, Matrix_less> transform_matrix_map;
std::unordered_map<GfxRGB, long long, GfxRGB_hash, GfxRGB_equal> fill_color_map, stroke_color_map;
std::map<double, long long> whitespace_map;
std::map<double, long long> rise_map;
std::map<double, long long> height_map;
std::map<double, long long> left_map;

View File

@ -190,7 +190,7 @@ void HTMLRenderer::TextLineBuffer::set_state (State & state)
state.ids[State::STROKE_COLOR_ID] = renderer->cur_stroke_color_id;
state.ids[State::LETTER_SPACE_ID] = renderer->letter_space_manager.get_id();
state.ids[State::WORD_SPACE_ID] = renderer->word_space_manager.get_id();
state.ids[State::RISE_ID] = renderer->cur_rise_id;
state.ids[State::RISE_ID] = renderer->rise_manager.get_id();
const FontInfo * info = renderer->cur_font_info;
state.ascent = info->ascent;

View File

@ -196,11 +196,6 @@ void HTMLRenderer::export_whitespace (long long ws_id, double ws_width)
f_css.fs << "._" << ws_id << "{display:inline;margin-left:" << round(ws_width) << "px;}" << endl;
}
void HTMLRenderer::export_rise (long long rise_id, double rise)
{
f_css.fs << ".r" << rise_id << "{top:" << round(-rise) << "px;}" << endl;
}
void HTMLRenderer::export_height (long long height_id, double height)
{
f_css.fs << ".h" << height_id << "{height:" << round(height) << "px;}" << endl;

View File

@ -56,9 +56,10 @@ HTMLRenderer::HTMLRenderer(const Param * param)
cur_mapping2 = new char* [0x100];
width_list = new int [0x10000];
font_size_manager .set_param(CSS::FONT_SIZE_CN , EPS);
letter_space_manager.set_param(CSS::LETTER_SPACE_CN, EPS);
word_space_manager .set_param(CSS::WORD_SPACE_CN , EPS);
font_size_manager .set_param(CSS::FONT_SIZE_CN , EPS );
letter_space_manager.set_param(CSS::LETTER_SPACE_CN, EPS );
word_space_manager .set_param(CSS::WORD_SPACE_CN , EPS );
rise_manager .set_param(CSS::RISE_CN , param->v_eps);
}
HTMLRenderer::~HTMLRenderer()
@ -339,6 +340,7 @@ void HTMLRenderer::post_process()
font_size_manager .dump_css(f_css.fs);
letter_space_manager.dump_css(f_css.fs);
word_space_manager .dump_css(f_css.fs);
rise_manager .dump_css(f_css.fs);
// close files
f_outline.fs.close();

View File

@ -280,20 +280,6 @@ long long HTMLRenderer::install_whitespace(double ws_width, double & actual_widt
return new_ws_id;
}
long long HTMLRenderer::install_rise(double rise)
{
auto iter = rise_map.lower_bound(rise - param->v_eps);
if((iter != rise_map.end()) && (abs(iter->first - rise) <= param->v_eps))
{
return iter->second;
}
long long new_rise_id = rise_map.size();
rise_map.insert(make_pair(rise, new_rise_id));
export_rise(new_rise_id, rise);
return new_rise_id;
}
long long HTMLRenderer::install_height(double height)
{
auto iter = height_map.lower_bound(height - EPS);

View File

@ -116,8 +116,7 @@ void HTMLRenderer::reset_state()
cur_stroke_color_id = install_stroke_color(&cur_stroke_color);
cur_has_stroke = false;
cur_rise = 0;
cur_rise_id = install_rise(cur_rise);
rise_manager.reset();
cur_tx = cur_ty = 0;
draw_tx = draw_ty = 0;
@ -408,15 +407,10 @@ void HTMLRenderer::check_state_change(GfxState * state)
// rise
// depends draw_text_scale
if(all_changed || rise_changed || draw_text_scale_changed)
if((all_changed || rise_changed || draw_text_scale_changed)
&& (rise_manager.install(state->getRise() * draw_text_scale)))
{
double new_rise = state->getRise();
if(!equal(cur_rise, new_rise))
{
new_line_state = max<NewLineState>(new_line_state, NLS_SPAN);
cur_rise = new_rise;
cur_rise_id = install_rise(new_rise * draw_text_scale);
}
new_line_state = max<NewLineState>(new_line_state, NLS_SPAN);
}
reset_state_change();

View File

@ -114,6 +114,13 @@ public:
void dump_value(std::ostream & out, double value) { out << "word-spacing:" << round(value) << "px;"; }
};
class RiseManager : public StateManager<double, RiseManager>
{
public:
double default_value(void) { return 0; }
void dump_value(std::ostream & out, double value) { out << "top:" << round(-value) << "px;"; }
};
} // namespace pdf2htmlEX
#endif //STATEMANAGER_H__