1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-03 08:38:39 +00:00
This commit is contained in:
Lu Wang 2012-10-09 23:10:06 +08:00
commit 792c2ff728
9 changed files with 67 additions and 38 deletions

5
TODO
View File

@ -1,3 +1,5 @@
word space/offset before the first letter (calendar pdf)
don't dump image when there is nothing
Integrate splash/cairo
@ -6,12 +8,9 @@ native support for draw
draw non-orthogonal lines with CSS
create a glyph for ' ', if there is not in a font
position history stack (popstate)
==Wait until someone asks==
try harder finding glyph names (using fontforge) for CID Type 0
rename single-html -> embed-font/image/css ...
merge sub/sup into one line

View File

@ -66,6 +66,7 @@ span {
}
._ {
color:transparent;
z-index:-1;
}
::selection{
background: rgba(127,255,255,1);

View File

@ -101,6 +101,7 @@ static void get_shading_bbox(GfxState * state, GfxShading * shading,
/*
* Note that the coordinate system in HTML and PDF are different
* This functions returns the angle of vector (dx,dy) in the PDF coordinate system, in rad
*/
static double get_angle(double dx, double dy)
{

View File

@ -41,12 +41,6 @@ void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suff
<< ";line-height:" << _round(info.ascent - info.descent)
<< ";font-style:normal;font-weight:normal;}";
// when ' ' is not vaild in the font, when we use ' ' in padding
// the browser will use the fallback font, whose metrics could be (very) different, then the layout will be affected
// so set the font-zie to avoid being affected
if(!(info.has_space))
css_fout << ".f" << info.id << ">._{font-size:1px;}";
css_fout << endl;
}

View File

@ -55,7 +55,7 @@ HTMLRenderer::HTMLRenderer(const Param * param)
HTMLRenderer::~HTMLRenderer()
{
ffw_fin();
ffw_finalize();
clean_tmp_files();
delete [] cur_mapping;
delete [] cur_mapping2;

View File

@ -190,7 +190,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
* if parm->tounicode is 0, try the provided tounicode map first
*/
info.use_tounicode = (is_truetype_suffix(suffix) || (param->tounicode >= 0));
info.has_space = false;
bool has_space = false;
const char * used_map = nullptr;
@ -360,7 +360,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
}
if(u == ' ')
info.has_space = true;
has_space = true;
if(codeset.insert(u).second)
{
@ -410,6 +410,22 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
ffw_reencode_raw(cur_mapping, max_key + 1, 1);
// we need the space chracter for offsets
if(!has_space)
{
int space_width;
if(font_8bit)
{
space_width = (int)floor(font_8bit->getWidth(' ') * info.em_size + 0.5);
}
else
{
char buf[2] = {0, ' '};
space_width = (int)floor(font_cid->getWidth(buf, 2) * info.em_size + 0.5);
}
ffw_make_char((int)' ', space_width);
}
if(ctu)
ctu->decRefCnt();
}

View File

@ -77,7 +77,7 @@ void ffw_init(int debug)
}
}
void ffw_fin(void)
void ffw_finalize(void)
{
while(enc_head)
{
@ -147,6 +147,26 @@ void ffw_prepare_font(void)
}
}
void ffw_save(const char * filename)
{
char * _filename = strcopy(filename);
char * _ = strcopy("");
int r = GenerateScript(cur_fv->sf, _filename
, _, -1, -1, NULL, NULL, cur_fv->map, NULL, ly_fore);
free(_);
free(_filename);
if(!r)
err("Cannot save font to %s\n", filename);
}
void ffw_close(void)
{
FontViewClose(cur_fv);
cur_fv = NULL;
}
static void ffw_do_reencode(Encoding * encoding, int force)
{
assert(encoding);
@ -235,25 +255,9 @@ void ffw_cidflatten(void)
SFFlatten(cur_fv->sf->cidmaster);
}
void ffw_save(const char * filename)
void ffw_make_char(int enc, int width)
{
char * _filename = strcopy(filename);
char * _ = strcopy("");
int r = GenerateScript(cur_fv->sf, _filename
, _, -1, -1, NULL, NULL, cur_fv->map, NULL, ly_fore);
free(_);
free(_filename);
if(!r)
err("Cannot save font to %s\n", filename);
}
void ffw_close(void)
{
FontViewClose(cur_fv);
cur_fv = NULL;
SFMakeChar(cur_fv->sf, cur_fv->map, enc)->width = width;
}
int ffw_get_em_size(void)

View File

@ -19,18 +19,31 @@ extern "C" {
#include <stdint.h>
#endif
////////////////////////
// global
void ffw_init(int debug);
void ffw_fin(void);
void ffw_finalize(void);
////////////////////////
// load & save
void ffw_load_font(const char * filename);
void ffw_prepare_font(void);
void ffw_reencode_glyph_order(void);
void ffw_reencode_raw(int32_t * mapping, int mapping_len, int force);
void ffw_reencode_raw2(char ** mapping, int mapping_len, int force);
void ffw_cidflatten(void);
void ffw_save(const char * filename);
void ffw_close(void);
////////////////////////
// encoding
void ffw_reencode_glyph_order(void);
void ffw_reencode_raw(int32_t * mapping, int mapping_len, int force);
void ffw_reencode_raw2(char ** mapping, int mapping_len, int force);
void ffw_cidflatten(void);
// get or create the char, and set the width
void ffw_make_char(int enc, int width);
////////////////////////
// metrics
int ffw_get_em_size(void);
// fix metrics and get them
void ffw_metric(double * ascent, double * descent);
@ -39,6 +52,8 @@ void ffw_set_widths(int * width_list, int mapping_len,
int stretch_narrow, int squeeze_wide,
int remove_unused);
////////////////////////
// others
void ffw_auto_hint(void);
#ifdef __cplusplus

View File

@ -103,7 +103,6 @@ public:
bool use_tounicode;
int em_size;
double ascent, descent;
bool has_space; // whether space is included in the font
};
class Matrix_less