mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
add a class for rise
This commit is contained in:
parent
beb1f7fbb7
commit
cde35df1a1
@ -28,8 +28,9 @@
|
|||||||
-o-transform-origin:0% 100%;
|
-o-transform-origin:0% 100%;
|
||||||
}
|
}
|
||||||
#pdf-main span {
|
#pdf-main span {
|
||||||
vertical-align: baseline;
|
position:relative;
|
||||||
line-height:0;
|
line-height:0;
|
||||||
|
vertical-align: baseline;
|
||||||
}
|
}
|
||||||
#pdf-main ._ {
|
#pdf-main ._ {
|
||||||
color:transparent;
|
color:transparent;
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
* w<hex> - Word spacing
|
* w<hex> - Word spacing
|
||||||
* c<hex> - Color
|
* c<hex> - Color
|
||||||
* _<hex> - white space
|
* _<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_word_space(double word_space);
|
||||||
long long install_color(const GfxRGB * rgb);
|
long long install_color(const GfxRGB * rgb);
|
||||||
long long install_whitespace(double ws_width, double & actual_width);
|
long long install_whitespace(double ws_width, double & actual_width);
|
||||||
|
long long install_rise(double rise);
|
||||||
|
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
// export css styles
|
// export css styles
|
||||||
@ -156,6 +158,7 @@ class HTMLRenderer : public OutputDev
|
|||||||
void export_word_space(long long ws_id, double word_space);
|
void export_word_space(long long ws_id, double word_space);
|
||||||
void export_color(long long color_id, const GfxRGB * rgb);
|
void export_color(long long color_id, const GfxRGB * rgb);
|
||||||
void export_whitespace(long long ws_id, double ws_width);
|
void export_whitespace(long long ws_id, double ws_width);
|
||||||
|
void export_rise(long long rise_id, double rise);
|
||||||
|
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
// state tracking
|
// state tracking
|
||||||
@ -199,9 +202,6 @@ class HTMLRenderer : public OutputDev
|
|||||||
// The order is according to the appearance in check_state_change
|
// The order is according to the appearance in check_state_change
|
||||||
// any state changed
|
// any state changed
|
||||||
bool all_changed;
|
bool all_changed;
|
||||||
// rise
|
|
||||||
double cur_rise;
|
|
||||||
bool rise_changed;
|
|
||||||
// current position
|
// current position
|
||||||
double cur_tx, cur_ty; // real text position, in text coords
|
double cur_tx, cur_ty; // real text position, in text coords
|
||||||
bool text_pos_changed;
|
bool text_pos_changed;
|
||||||
@ -239,6 +239,11 @@ class HTMLRenderer : public OutputDev
|
|||||||
GfxRGB cur_color;
|
GfxRGB cur_color;
|
||||||
bool color_changed;
|
bool color_changed;
|
||||||
|
|
||||||
|
// rise
|
||||||
|
long long cur_rise_id;
|
||||||
|
double cur_rise;
|
||||||
|
bool rise_changed;
|
||||||
|
|
||||||
// optimize for web
|
// optimize for web
|
||||||
// we try to render the final font size directly
|
// we try to render the final font size directly
|
||||||
// to reduce the effect of ctm as much as possible
|
// 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<GfxRGB, long long> color_map;
|
||||||
|
|
||||||
std::map<double, long long> whitespace_map;
|
std::map<double, long long> whitespace_map;
|
||||||
|
std::map<double, long long> rise_map;
|
||||||
|
|
||||||
int image_count;
|
int image_count;
|
||||||
|
|
||||||
|
@ -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;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -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;
|
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;
|
draw_scale = 1.0;
|
||||||
|
|
||||||
cur_fn_id = install_font(nullptr);
|
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.r = cur_color.g = cur_color.b = 0;
|
||||||
cur_color_id = install_color(&cur_color);
|
cur_color_id = install_color(&cur_color);
|
||||||
|
|
||||||
|
cur_rise = 0;
|
||||||
|
cur_rise_id = install_rise(cur_rise);
|
||||||
|
|
||||||
cur_tx = cur_ty = 0;
|
cur_tx = cur_ty = 0;
|
||||||
draw_tx = draw_ty = 0;
|
draw_tx = draw_ty = 0;
|
||||||
|
|
||||||
|
@ -331,3 +331,16 @@ long long HTMLRenderer::install_whitespace(double ws_width, double & actual_widt
|
|||||||
return new_ws_id;
|
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;
|
||||||
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO
|
* TODO
|
||||||
* use relative positioning for rise
|
* optimize lines using nested <span> (reuse classes)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -82,17 +82,6 @@ void HTMLRenderer::check_state_change(GfxState * state)
|
|||||||
bool need_recheck_position = false;
|
bool need_recheck_position = false;
|
||||||
bool need_rescale_font = 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
|
// text position
|
||||||
// we've been tracking the text position positively in the update*** functions
|
// we've been tracking the text position positively in the update*** functions
|
||||||
if(all_changed || text_pos_changed)
|
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
|
* 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 tdx = old_ctm[4] - cur_ctm[4] - cur_ctm[2] * dy;
|
||||||
double tdy = old_ctm[5] - cur_ctm[5] - cur_ctm[3] * 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();
|
reset_state_change();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,7 +356,7 @@ void HTMLRenderer::prepare_line(GfxState * state)
|
|||||||
% y % x % cur_tm_id;
|
% y % x % cur_tm_id;
|
||||||
|
|
||||||
//resync position
|
//resync position
|
||||||
draw_ty = cur_ty + cur_rise;
|
draw_ty = cur_ty;
|
||||||
draw_tx = cur_tx;
|
draw_tx = cur_tx;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -368,8 +369,8 @@ void HTMLRenderer::prepare_line(GfxState * state)
|
|||||||
assert(false && "Bad value of new_line_status");
|
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|\">")
|
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_fn_id % cur_fs_id % cur_color_id % cur_ls_id % cur_ws_id % cur_rise_id;
|
||||||
|
|
||||||
line_status = LineStatus::SPAN;
|
line_status = LineStatus::SPAN;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user