1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 04:50:09 +00:00

build ps encodnig directly without read/write fiels

This commit is contained in:
Lu Wang 2012-09-03 22:32:56 +08:00
parent ba305ae9fd
commit 8bfd45d4d1
5 changed files with 52 additions and 29 deletions

View File

@ -272,6 +272,7 @@ class HTMLRenderer : public OutputDev
// for font reencoding
int32_t * cur_mapping;
char ** cur_mapping2;
////////////////////////////////////////////////////
// styles & resources

View File

@ -36,12 +36,14 @@ HTMLRenderer::HTMLRenderer(const Param * param)
ff_init();
cur_mapping = new int32_t [0x10000];
cur_mapping2 = new char* [0x100];
}
HTMLRenderer::~HTMLRenderer()
{
clean_tmp_files();
delete [] cur_mapping;
delete [] cur_mapping2;
}
void HTMLRenderer::process(PDFDoc *doc)

View File

@ -209,26 +209,24 @@ void HTMLRenderer::embed_font(const path & filepath, GfxFont * font, FontInfo &
else
{
// move the slot such that it's consistent with the encoding seen in PDF
// TODO: build encoding directly
ofstream out(tmp_dir / (fn + "_.encoding"));
add_tmp_file(fn+"_.encoding");
unordered_set<string> nameset;
bool name_conflict_warned = false;
out << format("/%1% [") % fn << endl;
memset(cur_mapping2, 0, 256 * sizeof(char*));
for(int i = 0; i < 256; ++i)
{
auto cn = font_8bit->getCharName(i);
if(cn == nullptr)
{
out << "/.notdef" << endl;
continue;
}
else
{
if(nameset.insert(string(cn)).second)
{
out << "/" << cn << endl;
cur_mapping2[i] = cn;
}
else
{
@ -238,14 +236,11 @@ void HTMLRenderer::embed_font(const path & filepath, GfxFont * font, FontInfo &
//TODO: may be resolved using advanced font properties?
cerr << "Warning: encoding confliction detected in font: " << fn << endl;
}
out << "/.notdef" << endl;
}
}
}
out << "] def" << endl;
ff_load_encoding((tmp_dir / (fn+"_.encoding")).c_str(), nullptr);
ff_reencode(fn.c_str(), 0);
ff_reencode_raw2(cur_mapping2, 256, 0);
}
}
else

View File

@ -73,6 +73,7 @@ void ff_load_font(const char * filename)
FVAppend(_FontViewCreate(cur_font));
}
/*
void ff_load_encoding(const char * filename, const char * encname)
{
char * _filename = strcopy(filename);
@ -81,6 +82,23 @@ void ff_load_encoding(const char * filename, const char * encname)
free(_encname);
free(_filename);
}
*/
static void ff_do_reencode(Encoding * encoding, int force)
{
if(force)
{
SFForceEncoding(cur_font, cur_font->fv->map, encoding);
}
else
{
EncMapFree(cur_font->fv->map);
cur_font->fv->map= EncMapFromEncoding(cur_font, encoding);
}
SFReplaceEncodingBDFProps(cur_font, cur_font->fv->map);
}
void ff_reencode(const char * encname, int force)
{
@ -88,17 +106,7 @@ void ff_reencode(const char * encname, int force)
if(!enc)
err("Unknown encoding %s\n", encname);
if(force)
{
SFForceEncoding(cur_font, cur_font->fv->map, enc);
}
else
{
EncMapFree(cur_font->fv->map);
cur_font->fv->map= EncMapFromEncoding(cur_font, enc);
}
SFReplaceEncodingBDFProps(cur_font, cur_font->fv->map);
ff_do_reencode(enc, force);
}
void ff_reencode_raw(int32 * mapping, int mapping_len, int force)
@ -110,17 +118,31 @@ void ff_reencode_raw(int32 * mapping, int mapping_len, int force)
memcpy(enc->unicode, mapping, mapping_len * sizeof(int32_t));
enc->enc_name = strcopy("");
if(force)
ff_do_reencode(enc, force);
}
void ff_reencode_raw2(char ** mapping, int mapping_len, int force)
{
Encoding * enc = calloc(1, sizeof(Encoding));
enc->enc_name = strcopy("");
enc->char_cnt = mapping_len;
enc->unicode = (int32_t*)malloc(mapping_len * sizeof(int32_t));
enc->psnames = (char**)calloc(mapping_len, sizeof(char*));
int i;
for(i = 0; i < mapping_len; ++i)
{
SFForceEncoding(cur_font, cur_font->fv->map, enc);
}
else
{
EncMapFree(cur_font->fv->map);
cur_font->fv->map= EncMapFromEncoding(cur_font, enc);
if(mapping[i])
{
enc->unicode[i] = UniFromName(mapping[i], ui_none, &custom);
enc->psnames[i] = strcopy(mapping[i]);
}
else
{
enc->unicode[i] = -1;
}
}
SFReplaceEncodingBDFProps(cur_font, cur_font->fv->map);
ff_do_reencode(enc, force);
}
void ff_cidflatten(void)

View File

@ -20,9 +20,12 @@ extern "C" {
void ff_init(void);
void ff_load_font(const char * filename);
/*
void ff_load_encoding(const char * filename, const char * encname);
*/
void ff_reencode(const char * encname, int force);
void ff_reencode_raw(int32_t * mapping, int mapping_len, int force);
void ff_reencode_raw2(char ** mapping, int mapping_len, int force);
void ff_cidflatten(void);
void ff_save(const char * filename);
void ff_close(void);