1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-05 01:28:39 +00:00

Fix issue in char displacement calculation.

This commit is contained in:
Duan Yao 2014-06-18 21:15:58 +08:00
parent f705a98581
commit b9899d8d4a
2 changed files with 17 additions and 9 deletions

View File

@ -232,6 +232,7 @@ void DrawingTracer::draw_char_bbox(GfxState * state, double * bbox)
if (pt_in == 0)
{
transform_bbox_by_ctm(bbox);
if(on_char_clipped)
on_char_clipped(bbox, false);
}
@ -255,6 +256,7 @@ void DrawingTracer::draw_char_bbox(GfxState * state, double * bbox)
on_char_drawn(bbox);
}
}
DT_DEBUG(printf("DrawingTracer::draw_char_bbox:[%f,%f,%f,%f]\n",bbox[0],bbox[1],bbox[2],bbox[3]));
}
void DrawingTracer::draw_image(GfxState *state)

View File

@ -51,9 +51,14 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
char *p = s->getCString();
int len = s->getLength();
//accumulated displacement of chars in this string, in text object space
double dx = 0;
double dy = 0;
double dx1,dy1;
//displacement of current char, in text object space
double ddx, ddy;
//advance of current char, in glyph space
double ax, ay;
//origin of current char, in glyph space
double ox, oy;
int nChars = 0;
@ -65,14 +70,15 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
while (len > 0)
{
auto n = font->getNextChar(p, len, &code, &u, &uLen, &dx1, &dy1, &ox, &oy);
auto n = font->getNextChar(p, len, &code, &u, &uLen, &ax, &ay, &ox, &oy);
if(!(equal(ox, 0) && equal(oy, 0)))
{
cerr << "TODO: non-zero origins" << endl;
}
tracer.draw_char(state, dx, dy, dx1, dy1); //TODO dx dy seems not correct?
ddx = (ax * cur_font_size + cur_letter_space) * cur_horiz_scaling;
ddy = ay * cur_font_size;
tracer.draw_char(state, dx, dy, ax, ay);
bool is_space = false;
if (n == 1 && *p == ' ')
@ -93,13 +99,13 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
if(is_space && (param.space_as_offset))
{
// ignore horiz_scaling, as it has been merged into CTM
html_text_page.get_cur_line()->append_offset((dx1 * cur_font_size + cur_letter_space + cur_word_space) * draw_text_scale);
html_text_page.get_cur_line()->append_offset((ax * cur_font_size + cur_letter_space + cur_word_space) * draw_text_scale);
}
else
{
if((param.decompose_ligature) && (uLen > 1) && all_of(u, u+uLen, isLegalUnicode))
{
html_text_page.get_cur_line()->append_unicodes(u, uLen, (dx1 * cur_font_size + cur_letter_space));
html_text_page.get_cur_line()->append_unicodes(u, uLen, ddx);
}
else
{
@ -112,7 +118,7 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
{
uu = unicode_from_font(code, font);
}
html_text_page.get_cur_line()->append_unicodes(&uu, 1, (dx1 * cur_font_size + cur_letter_space));
html_text_page.get_cur_line()->append_unicodes(&uu, 1, ddx);
/*
* In PDF, word_space is appended if (n == 1 and *p = ' ')
* but in HTML, word_space is appended if (uu == ' ')
@ -125,8 +131,8 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
}
}
dx += dx1;
dy += dy1;
dx += ddx;
dy += ddy;
++nChars;
p += n;