mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-07-05 09:38:40 +00:00
fixing working with fontforge
This commit is contained in:
parent
4543fc9dbc
commit
069a072642
|
@ -12,6 +12,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <boost/filesystem/fstream.hpp>
|
#include <boost/filesystem/fstream.hpp>
|
||||||
|
@ -269,6 +270,9 @@ class HTMLRenderer : public OutputDev
|
||||||
double line_ascent, line_height;
|
double line_ascent, line_height;
|
||||||
std::stringstream line_buf;
|
std::stringstream line_buf;
|
||||||
|
|
||||||
|
// for font reencoding
|
||||||
|
int32_t * cur_mapping;
|
||||||
|
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
// styles & resources
|
// styles & resources
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
|
|
|
@ -28,11 +28,13 @@ HTMLRenderer::HTMLRenderer(const Param * param)
|
||||||
,tmp_dir(param->tmp_dir)
|
,tmp_dir(param->tmp_dir)
|
||||||
{
|
{
|
||||||
ff_init();
|
ff_init();
|
||||||
|
cur_mapping = new int32_t [0x10000];
|
||||||
}
|
}
|
||||||
|
|
||||||
HTMLRenderer::~HTMLRenderer()
|
HTMLRenderer::~HTMLRenderer()
|
||||||
{
|
{
|
||||||
clean_tmp_files();
|
clean_tmp_files();
|
||||||
|
delete [] cur_mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLRenderer::process(PDFDoc *doc)
|
void HTMLRenderer::process(PDFDoc *doc)
|
||||||
|
|
|
@ -209,6 +209,7 @@ void HTMLRenderer::embed_font(const path & filepath, GfxFont * font, FontInfo &
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// move the slot such that it's consistent with the encoding seen in PDF
|
// move the slot such that it's consistent with the encoding seen in PDF
|
||||||
|
// TODO: build encoding directly
|
||||||
ofstream out(tmp_dir / (fn + "_.encoding"));
|
ofstream out(tmp_dir / (fn + "_.encoding"));
|
||||||
add_tmp_file(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:
|
* - For 8bit nonTruetype fonts:
|
||||||
* Try to calculate the correct Unicode value from the glyph names, unless param->always_apply_tounicode is set
|
* 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"));
|
auto ctu = font->getToUnicode();
|
||||||
add_tmp_file(fn+".encoding");
|
memset(cur_mapping, 0, maxcode * sizeof(int32_t));
|
||||||
|
|
||||||
for(int i = 0; i <= maxcode; ++i)
|
for(int i = 0; i <= maxcode; ++i)
|
||||||
{
|
{
|
||||||
if((suffix != ".ttf") && (font_8bit != nullptr) && (font_8bit->getCharName(i) == nullptr))
|
if((suffix != ".ttf") && (font_8bit != nullptr) && (font_8bit->getCharName(i) == nullptr))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
++ cnt;
|
|
||||||
map_fout << format("0x%|1$X|") % ((code2GID && (i < code2GID_len))? code2GID[i] : i);
|
|
||||||
|
|
||||||
Unicode u, *pu=&u;
|
Unicode u, *pu=&u;
|
||||||
|
|
||||||
if(info.use_tounicode)
|
if(info.use_tounicode)
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n = ctu ? (ctu->mapToUnicode(i, &pu)) : 0;
|
||||||
if(ctu)
|
|
||||||
n = ctu->mapToUnicode(i, &pu);
|
|
||||||
u = check_unicode(pu, n, i, font);
|
u = check_unicode(pu, n, i, font);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -309,21 +303,14 @@ void HTMLRenderer::embed_font(const path & filepath, GfxFont * font, FontInfo &
|
||||||
u = unicode_from_font(i, font);
|
u = unicode_from_font(i, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
map_fout << format(" 0x%|1$X|") % u;
|
cur_mapping[((code2GID && (i < code2GID_len))? code2GID[i] : i)] = u;
|
||||||
map_fout << format(" # 0x%|1$X|") % i;
|
|
||||||
|
|
||||||
map_fout << endl;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(cnt > 0)
|
ff_reencode_raw(cur_mapping, maxcode, 1);
|
||||||
{
|
|
||||||
ff_load_encoding((tmp_dir / (fn+".encoding")).c_str(), fn.c_str());
|
|
||||||
ff_reencode(fn.c_str(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ctu)
|
if(ctu)
|
||||||
ctu->decRefCnt();
|
ctu->decRefCnt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto dest = ((param->single_html ? tmp_dir : dest_dir) / (fn+(param->font_suffix)));
|
auto dest = ((param->single_html ? tmp_dir : dest_dir) / (fn+(param->font_suffix)));
|
||||||
|
|
32
src/ff/ff.c
32
src/ff/ff.c
|
@ -42,6 +42,13 @@ static int max(int a, int b)
|
||||||
return (a>b) ? a : 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)
|
void ff_init(void)
|
||||||
{
|
{
|
||||||
InitSimpleStuff();
|
InitSimpleStuff();
|
||||||
|
@ -49,6 +56,9 @@ void ff_init(void)
|
||||||
default_encoding=FindOrMakeEncoding("ISO8859-1");
|
default_encoding=FindOrMakeEncoding("ISO8859-1");
|
||||||
if ( default_encoding==NULL )
|
if ( default_encoding==NULL )
|
||||||
default_encoding=&custom; /* In case iconv is broken */
|
default_encoding=&custom; /* In case iconv is broken */
|
||||||
|
|
||||||
|
//disable error output of Fontforge
|
||||||
|
ui_interface->logwarning = &dummy;
|
||||||
}
|
}
|
||||||
void ff_load_font(const char * filename)
|
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);
|
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)
|
void ff_cidflatten(void)
|
||||||
{
|
{
|
||||||
printf("cid flatten\n");
|
printf("cid flatten\n");
|
||||||
|
|
|
@ -10,14 +10,19 @@
|
||||||
* 2012.09.03
|
* 2012.09.03
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
#include <cstdint>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
#else
|
||||||
|
#include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void ff_init(void);
|
void ff_init(void);
|
||||||
void ff_load_font(const char * filename);
|
void ff_load_font(const char * filename);
|
||||||
void ff_load_encoding(const char * filename, const char * encname);
|
void ff_load_encoding(const char * filename, const char * encname);
|
||||||
void ff_reencode(const char * encname, int force);
|
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_cidflatten(void);
|
||||||
void ff_save(const char * filename);
|
void ff_save(const char * filename);
|
||||||
void ff_close(void);
|
void ff_close(void);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user