mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 04:50:09 +00:00
set correct width
This commit is contained in:
parent
8cac1e6aaf
commit
84b0966551
@ -241,9 +241,6 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info)
|
||||
cairo_surface_set_fallback_resolution(surface, param.h_dpi, param.v_dpi);
|
||||
cairo_t * cr = cairo_create(surface);
|
||||
|
||||
//debug
|
||||
std::cerr << "debug " << code << std::endl;
|
||||
std::cerr << "pdf width " << ((Gfx8BitFont*)font)->getWidth(code) << std::endl;
|
||||
/*
|
||||
cairo_set_font_size(cr, scale);
|
||||
cairo_set_font_face(cr, cur_font->getFontFace());
|
||||
@ -254,6 +251,7 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info)
|
||||
double ox, oy;
|
||||
ox = oy = 0.0;
|
||||
|
||||
auto glyph_width = ((Gfx8BitFont*)font)->getWidth(code);
|
||||
// manually draw the char to get the metrics
|
||||
// adapted from _render_type3_glyph of poppler
|
||||
{
|
||||
@ -285,6 +283,12 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info)
|
||||
// set ctm
|
||||
cairo_set_matrix(cr, &ctm);
|
||||
|
||||
// calculate the position of origin
|
||||
cairo_matrix_transform_point(&ctm, &ox, &oy);
|
||||
// calculate glyph width
|
||||
double dummy = 0;
|
||||
cairo_matrix_transform_point(&ctm, &glyph_width, &dummy);
|
||||
|
||||
// draw the glyph
|
||||
auto output_dev = new CairoOutputDev();
|
||||
output_dev->setCairo(cr);
|
||||
@ -306,23 +310,6 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info)
|
||||
auto glyph_index = cur_font->getGlyph(code, nullptr, 0);
|
||||
gfx->display(char_procs->getVal(glyph_index, &char_proc_obj));
|
||||
|
||||
double wx, wy;
|
||||
output_dev->getType3GlyphWidth(&wx, &wy);
|
||||
cairo_matrix_transform_distance(&m1, &wx, &wy);
|
||||
std::cerr << "wx " << wx << " wy " << wy << std::endl;
|
||||
|
||||
if(output_dev->hasType3GlyphBBox())
|
||||
{
|
||||
double *bbox = output_dev->getType3GlyphBBox();
|
||||
|
||||
cairo_matrix_transform_point (&m1, &bbox[0], &bbox[1]);
|
||||
cairo_matrix_transform_point (&m1, &bbox[2], &bbox[3]);
|
||||
std::cerr << "*bbox";
|
||||
for(int i = 0; i < 4; ++i)
|
||||
std::cerr << ' ' << bbox[i];
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
char_proc_obj.free();
|
||||
delete gfx;
|
||||
delete output_dev;
|
||||
@ -345,7 +332,7 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info)
|
||||
throw string("Error in cairo: ") + cairo_status_to_string(status);
|
||||
}
|
||||
|
||||
ffw_import_svg_glyph(code, glyph_filename.c_str(), ox / GLYPH_DUMP_EM_SIZE, oy / GLYPH_DUMP_EM_SIZE);
|
||||
ffw_import_svg_glyph(code, glyph_filename.c_str(), ox / GLYPH_DUMP_EM_SIZE, 1.0 - oy / GLYPH_DUMP_EM_SIZE, glyph_width / GLYPH_DUMP_EM_SIZE);
|
||||
}
|
||||
|
||||
string font_filename = (char*)str_fmt("%s/f%llx.ttf", param.tmp_dir.c_str(), fn_id);
|
||||
|
@ -425,7 +425,7 @@ void ffw_set_widths(int * width_list, int mapping_len,
|
||||
}
|
||||
}
|
||||
|
||||
void ffw_import_svg_glyph(int code, const char * filename, double ox, double oy)
|
||||
void ffw_import_svg_glyph(int code, const char * filename, double ox, double oy, double width)
|
||||
{
|
||||
int enc = SFFindSlot(cur_fv->sf, cur_fv->map, code, "");
|
||||
if(enc == -1)
|
||||
@ -439,7 +439,7 @@ void ffw_import_svg_glyph(int code, const char * filename, double ox, double oy)
|
||||
if(!ok)
|
||||
err("Import SVG glyph failed");
|
||||
|
||||
// correct the origin
|
||||
// correct origin and width
|
||||
{
|
||||
int a = cur_fv->sf->ascent;
|
||||
int d = cur_fv->sf->descent;
|
||||
@ -450,6 +450,8 @@ void ffw_import_svg_glyph(int code, const char * filename, double ox, double oy)
|
||||
transform[4] = -ox * (a+d);
|
||||
transform[5] = -oy * (a+d) + d;
|
||||
FVTrans(cur_fv, sc, transform, NULL, fvt_alllayers | fvt_dontmovewidth);
|
||||
|
||||
SCSynchronizeWidth(sc, floor(width * (a+d) + 0.5), sc->width, cur_fv);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,8 @@ void ffw_set_widths(int * width_list, int mapping_len,
|
||||
////////////////////////
|
||||
// others
|
||||
// (ox,oy) is the position of the true origin, fractions related to em_size
|
||||
void ffw_import_svg_glyph(int code, const char * filename, double ox, double oy);
|
||||
// also true for glyph_width
|
||||
void ffw_import_svg_glyph(int code, const char * filename, double ox, double oy, double glyph_width);
|
||||
void ffw_auto_hint(void);
|
||||
void ffw_override_fstype(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user