1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00

fixing working with fontforge

This commit is contained in:
Lu Wang 2012-09-03 21:54:48 +08:00
parent 4543fc9dbc
commit 069a072642
5 changed files with 54 additions and 24 deletions

View File

@ -12,6 +12,7 @@
#include <vector>
#include <set>
#include <sstream>
#include <cstdint>
#include <boost/format.hpp>
#include <boost/filesystem/fstream.hpp>
@ -269,6 +270,9 @@ class HTMLRenderer : public OutputDev
double line_ascent, line_height;
std::stringstream line_buf;
// for font reencoding
int32_t * cur_mapping;
////////////////////////////////////////////////////
// styles & resources
////////////////////////////////////////////////////

View File

@ -28,11 +28,13 @@ HTMLRenderer::HTMLRenderer(const Param * param)
,tmp_dir(param->tmp_dir)
{
ff_init();
cur_mapping = new int32_t [0x10000];
}
HTMLRenderer::~HTMLRenderer()
{
clean_tmp_files();
delete [] cur_mapping;
}
void HTMLRenderer::process(PDFDoc *doc)

View File

@ -209,6 +209,7 @@ 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");
@ -277,31 +278,24 @@ void HTMLRenderer::embed_font(const path & filepath, GfxFont * font, FontInfo &
* - For 8bit nonTruetype fonts:
* Try to calculate the correct Unicode value from the glyph names, unless param->always_apply_tounicode is set
*
* TODO: build Encoding directly, without read/write files
*/
auto ctu = font->getToUnicode();
int cnt = 0;
{
ofstream map_fout(tmp_dir / (fn + ".encoding"));
add_tmp_file(fn+".encoding");
auto ctu = font->getToUnicode();
memset(cur_mapping, 0, maxcode * sizeof(int32_t));
for(int i = 0; i <= maxcode; ++i)
{
if((suffix != ".ttf") && (font_8bit != nullptr) && (font_8bit->getCharName(i) == nullptr))
{
continue;
++ cnt;
map_fout << format("0x%|1$X|") % ((code2GID && (i < code2GID_len))? code2GID[i] : i);
}
Unicode u, *pu=&u;
if(info.use_tounicode)
{
int n = 0;
if(ctu)
n = ctu->mapToUnicode(i, &pu);
int n = ctu ? (ctu->mapToUnicode(i, &pu)) : 0;
u = check_unicode(pu, n, i, font);
}
else
@ -309,21 +303,14 @@ void HTMLRenderer::embed_font(const path & filepath, GfxFont * font, FontInfo &
u = unicode_from_font(i, font);
}
map_fout << format(" 0x%|1$X|") % u;
map_fout << format(" # 0x%|1$X|") % i;
map_fout << endl;
cur_mapping[((code2GID && (i < code2GID_len))? code2GID[i] : i)] = u;
}
}
if(cnt > 0)
{
ff_load_encoding((tmp_dir / (fn+".encoding")).c_str(), fn.c_str());
ff_reencode(fn.c_str(), 1);
}
ff_reencode_raw(cur_mapping, maxcode, 1);
if(ctu)
ctu->decRefCnt();
if(ctu)
ctu->decRefCnt();
}
}
auto dest = ((param->single_html ? tmp_dir : dest_dir) / (fn+(param->font_suffix)));

View File

@ -42,6 +42,13 @@ static int max(int a, int b)
return (a>b) ? a : b;
}
static void dummy(const char * format, ...)
{
va_list al;
va_start(al, format);
va_end(al);
}
void ff_init(void)
{
InitSimpleStuff();
@ -49,6 +56,9 @@ void ff_init(void)
default_encoding=FindOrMakeEncoding("ISO8859-1");
if ( default_encoding==NULL )
default_encoding=&custom; /* In case iconv is broken */
//disable error output of Fontforge
ui_interface->logwarning = &dummy;
}
void ff_load_font(const char * filename)
{
@ -91,6 +101,28 @@ void ff_reencode(const char * encname, int force)
SFReplaceEncodingBDFProps(cur_font, cur_font->fv->map);
}
void ff_reencode_raw(int32 * mapping, int mapping_len, int force)
{
Encoding * enc = calloc(1, sizeof(Encoding));
enc->only_1byte = enc->has_1byte = true;
enc->char_cnt = mapping_len;
enc->unicode = (int32_t*)malloc(mapping_len * sizeof(int32_t));
memcpy(enc->unicode, mapping, mapping_len * sizeof(int32_t));
enc->enc_name = strcopy("");
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);
}
void ff_cidflatten(void)
{
printf("cid flatten\n");

View File

@ -10,14 +10,19 @@
* 2012.09.03
*/
#ifdef __cplusplus
#include <cstdint>
extern "C" {
#else
#include <stdint.h>
#endif
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_cidflatten(void);
void ff_save(const char * filename);
void ff_close(void);