1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 04:50:09 +00:00

add a class for rise

This commit is contained in:
Lu Wang 2012-08-24 19:40:43 +02:00
parent beb1f7fbb7
commit cde35df1a1
6 changed files with 49 additions and 22 deletions

View File

@ -28,8 +28,9 @@
-o-transform-origin:0% 100%;
}
#pdf-main span {
vertical-align: baseline;
position:relative;
line-height:0;
vertical-align: baseline;
}
#pdf-main ._ {
color:transparent;

View File

@ -49,6 +49,7 @@
* w<hex> - Word spacing
* c<hex> - Color
* _<hex> - white space
* r<hex> - Rise
*
*/
@ -139,6 +140,7 @@ class HTMLRenderer : public OutputDev
long long install_word_space(double word_space);
long long install_color(const GfxRGB * rgb);
long long install_whitespace(double ws_width, double & actual_width);
long long install_rise(double rise);
////////////////////////////////////////////////////
// export css styles
@ -156,6 +158,7 @@ class HTMLRenderer : public OutputDev
void export_word_space(long long ws_id, double word_space);
void export_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);
////////////////////////////////////////////////////
// state tracking
@ -199,9 +202,6 @@ class HTMLRenderer : public OutputDev
// The order is according to the appearance in check_state_change
// any state changed
bool all_changed;
// rise
double cur_rise;
bool rise_changed;
// current position
double cur_tx, cur_ty; // real text position, in text coords
bool text_pos_changed;
@ -239,6 +239,11 @@ class HTMLRenderer : public OutputDev
GfxRGB cur_color;
bool color_changed;
// rise
long long cur_rise_id;
double cur_rise;
bool rise_changed;
// optimize for web
// we try to render the final font size directly
// to reduce the effect of ctm as much as possible
@ -267,6 +272,7 @@ class HTMLRenderer : public OutputDev
std::map<GfxRGB, long long> color_map;
std::map<double, long long> whitespace_map;
std::map<double, long long> rise_map;
int image_count;

View File

@ -125,3 +125,8 @@ void HTMLRenderer::export_whitespace (long long ws_id, double ws_width)
allcss_fout << format("._%|1$x|{display:inline;margin-left:%2%px;}") % ws_id % ws_width << endl;
}
void HTMLRenderer::export_rise (long long rise_id, double rise)
{
allcss_fout << format(".r%|1$x|{top:%2%px;}") % rise_id % (-rise) << endl;
}

View File

@ -153,8 +153,6 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state)
html_fout << format(");background-position:0 0;background-size:%1%px %2%px;background-repeat:no-repeat;\">") % pageWidth % pageHeight;
cur_rise = 0;
draw_scale = 1.0;
cur_fn_id = install_font(nullptr);
@ -172,6 +170,9 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state)
cur_color.r = cur_color.g = cur_color.b = 0;
cur_color_id = install_color(&cur_color);
cur_rise = 0;
cur_rise_id = install_rise(cur_rise);
cur_tx = cur_ty = 0;
draw_tx = draw_ty = 0;

View File

@ -331,3 +331,16 @@ 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;
}

View File

@ -9,7 +9,7 @@
/*
* TODO
* use relative positioning for rise
* optimize lines using nested <span> (reuse classes)
*/
#include <algorithm>
@ -82,17 +82,6 @@ void HTMLRenderer::check_state_change(GfxState * state)
bool need_recheck_position = false;
bool need_rescale_font = false;
// rise
if(all_changed || rise_changed)
{
double new_rise = state->getRise();
if(!_equal(cur_rise, new_rise))
{
need_recheck_position = true;
cur_rise = new_rise;
}
}
// text position
// we've been tracking the text position positively in the update*** functions
if(all_changed || text_pos_changed)
@ -200,7 +189,7 @@ void HTMLRenderer::check_state_change(GfxState * state)
* TODO, writing mode, set dx and solve dy
*/
double dy = cur_ty + cur_rise - draw_ty;
double dy = cur_ty - draw_ty;
double tdx = old_ctm[4] - cur_ctm[4] - cur_ctm[2] * dy;
double tdy = old_ctm[5] - cur_ctm[5] - cur_ctm[3] * dy;
@ -277,6 +266,18 @@ void HTMLRenderer::check_state_change(GfxState * state)
}
}
// rise
if(all_changed || rise_changed)
{
double new_rise = state->getRise();
if(!_equal(cur_rise, new_rise))
{
new_line_status = max(new_line_status, LineStatus::SPAN);
cur_rise = new_rise;
cur_rise_id = install_rise(new_rise * draw_scale);
}
}
reset_state_change();
}
@ -355,7 +356,7 @@ void HTMLRenderer::prepare_line(GfxState * state)
% y % x % cur_tm_id;
//resync position
draw_ty = cur_ty + cur_rise;
draw_ty = cur_ty;
draw_tx = cur_tx;
}
@ -368,8 +369,8 @@ void HTMLRenderer::prepare_line(GfxState * state)
assert(false && "Bad value of new_line_status");
}
html_fout << format("<span class=\"f%|1$x| s%|2$x| c%|3$x| l%|4$x| w%|5$x|\">")
% cur_fn_id % cur_fs_id % cur_color_id % cur_ls_id % cur_ws_id;
html_fout << format("<span class=\"f%|1$x| s%|2$x| c%|3$x| l%|4$x| w%|5$x| r%|6$x|\">")
% cur_fn_id % cur_fs_id % cur_color_id % cur_ls_id % cur_ws_id % cur_rise_id;
line_status = LineStatus::SPAN;
}