1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-03 08:38:39 +00:00

create a glyph for ' ' when there is not one

This commit is contained in:
Lu Wang 2012-10-08 16:26:19 +08:00
parent 9a34d44809
commit 12676ccc4a
7 changed files with 63 additions and 37 deletions

2
TODO
View File

@ -6,8 +6,6 @@ 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==

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