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

rename ff to ffw

This commit is contained in:
Lu Wang 2012-09-17 20:40:10 +08:00
parent d2fb40fc00
commit ac6b04ab32
6 changed files with 104 additions and 96 deletions

View File

@ -122,8 +122,8 @@ add_executable(pdf2htmlEX
src/HTMLRenderer/image.cc
src/include/namespace.h
src/HTMLRenderer/LineBuffer.cc
src/include/ff.h
src/ff.c
src/include/ffw.h
src/ffw.c
src/include/BackgroundRenderer.h
src/BackgroundRenderer.cc
src/include/FontPreprocessor.h

View File

@ -16,7 +16,7 @@
#include "HTMLRenderer.h"
#include "BackgroundRenderer.h"
#include "namespace.h"
#include "ff.h"
#include "ffw.h"
#include "pdf2htmlEX-config.h"
namespace pdf2htmlEX {
@ -36,17 +36,20 @@ HTMLRenderer::HTMLRenderer(const Param * param)
,image_count(0)
,param(param)
{
//disable error function of poppler
setErrorCallback(&dummy, nullptr);
if(!(param->debug))
{
//disable error function of poppler
setErrorCallback(&dummy, nullptr);
}
ff_init();
ffw_init(param->debug);
cur_mapping = new int32_t [0x10000];
cur_mapping2 = new char* [0x100];
}
HTMLRenderer::~HTMLRenderer()
{
ff_fin();
ffw_fin();
clean_tmp_files();
delete [] cur_mapping;
delete [] cur_mapping2;

View File

@ -15,7 +15,7 @@
#include <CharCodeToUnicode.h>
#include <fofi/FoFiTrueType.h>
#include "ff.h"
#include "ffw.h"
#include "HTMLRenderer.h"
#include "namespace.h"
@ -158,7 +158,7 @@ string HTMLRenderer::dump_embedded_font (GfxFont * font, long long fn_id)
void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo & info, bool get_metric_only)
{
ff_load_font(filepath.c_str());
ffw_load_font(filepath.c_str());
int * code2GID = nullptr;
int code2GID_len = 0;
@ -198,7 +198,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
maxcode = 0xff;
if(is_truetype_suffix(suffix))
{
ff_reencode_glyph_order();
ffw_reencode_glyph_order();
FoFiTrueType *fftt = nullptr;
if((fftt = FoFiTrueType::load((char*)filepath.c_str())) != nullptr)
{
@ -242,7 +242,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
}
}
ff_reencode_raw2(cur_mapping2, 256, 0);
ffw_reencode_raw2(cur_mapping2, 256, 0);
}
}
else
@ -251,7 +251,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
if(is_truetype_suffix(suffix))
{
ff_reencode_glyph_order();
ffw_reencode_glyph_order();
GfxCIDFont * _font = dynamic_cast<GfxCIDFont*>(font);
@ -261,7 +261,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
}
else
{
ff_cidflatten();
ffw_cidflatten();
}
}
@ -334,7 +334,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
}
}
ff_reencode_raw(cur_mapping, max_key + 1, 1);
ffw_reencode_raw(cur_mapping, max_key + 1, 1);
if(ctu)
ctu->decRefCnt();
@ -354,16 +354,16 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
auto fn = str_fmt("%s/f%llx_.ttf", param->tmp_dir.c_str(), info.id);
add_tmp_file((char*)fn);
ff_save((char*)fn);
ff_close();
ff_load_font((char*)fn);
ffw_save((char*)fn);
ffw_close();
ffw_load_font((char*)fn);
}
{
// read metrics
// int em = ff_get_em_size();
// int em = ffw_get_em_size();
int ascent,descent;
ff_metric(&ascent, &descent);
ffw_metric(&ascent, &descent);
int em = ascent + descent;
if(em != 0)
@ -381,8 +381,8 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
cerr << "Ascent: " << info.ascent << " Descent: " << info.descent << endl;
}
ff_set_ascent(ascent);
ff_set_descent(descent);
ffw_set_ascent(ascent);
ffw_set_descent(descent);
}
{
@ -393,8 +393,8 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
if(param->single_html)
add_tmp_file((char*)fn);
ff_save((char*)fn);
ff_close();
ffw_save((char*)fn);
ffw_close();
}
}

View File

@ -1,5 +1,5 @@
/*
* ff.c
* ffw.c: Fontforge wrapper
*
* Processing fonts using Fontforge
*
@ -16,7 +16,7 @@
#include <fontforge.h>
#include <baseviews.h>
#include "ff.h"
#include "ffw.h"
static FontViewBase * cur_fv = NULL;
static Encoding * original_enc = NULL;
@ -45,14 +45,15 @@ static int max(int a, int b)
return (a>b) ? a : b;
}
static void dummy(const char * format, ...)
static void dumb_logwarning(const char * format, ...)
{
va_list al;
va_start(al, format);
va_end(al);
}
void ff_init(void)
static void dumb_post_error(const char * title, const char * error, ...)
{
}
void ffw_init(int debug)
{
InitSimpleStuff();
if ( default_encoding==NULL )
@ -60,13 +61,17 @@ void ff_init(void)
if ( default_encoding==NULL )
default_encoding=&custom; /* In case iconv is broken */
//disable error output of Fontforge
ui_interface->logwarning = &dummy;
if(!debug)
{
//disable error output of Fontforge
ui_interface->logwarning = &dumb_logwarning;
ui_interface->post_error = &dumb_post_error;
}
original_enc = FindOrMakeEncoding("original");
}
void ff_fin(void)
void ffw_fin(void)
{
while(enc_head)
{
@ -85,7 +90,7 @@ void ff_fin(void)
}
}
void ff_load_font(const char * filename)
void ffw_load_font(const char * filename)
{
char * _filename = strcopy(filename);
SplineFont * font = LoadSplineFont(_filename, 1);
@ -101,7 +106,7 @@ void ff_load_font(const char * filename)
cur_fv = font->fv;
}
static void ff_do_reencode(Encoding * encoding, int force)
static void ffw_do_reencode(Encoding * encoding, int force)
{
assert(encoding);
@ -123,21 +128,21 @@ static void ff_do_reencode(Encoding * encoding, int force)
SFReplaceEncodingBDFProps(cur_fv->sf, cur_fv->map);
}
void ff_reencode_glyph_order(void)
void ffw_reencode_glyph_order(void)
{
ff_do_reencode(original_enc, 0);
ffw_do_reencode(original_enc, 0);
}
void ff_reencode(const char * encname, int force)
void ffw_reencode(const char * encname, int force)
{
Encoding * enc = FindOrMakeEncoding(encname);
if(!enc)
err("Unknown encoding %s\n", encname);
ff_do_reencode(enc, force);
ffw_do_reencode(enc, force);
}
void ff_reencode_raw(int32 * mapping, int mapping_len, int force)
void ffw_reencode_raw(int32 * mapping, int mapping_len, int force)
{
Encoding * enc = calloc(1, sizeof(Encoding));
enc->only_1byte = enc->has_1byte = true;
@ -149,10 +154,10 @@ void ff_reencode_raw(int32 * mapping, int mapping_len, int force)
enc->next = enc_head;
enc_head = enc;
ff_do_reencode(enc, force);
ffw_do_reencode(enc, force);
}
void ff_reencode_raw2(char ** mapping, int mapping_len, int force)
void ffw_reencode_raw2(char ** mapping, int mapping_len, int force)
{
Encoding * enc = calloc(1, sizeof(Encoding));
enc->enc_name = strcopy("");
@ -176,17 +181,17 @@ void ff_reencode_raw2(char ** mapping, int mapping_len, int force)
enc->next = enc_head;
enc_head = enc;
ff_do_reencode(enc, force);
ffw_do_reencode(enc, force);
}
void ff_cidflatten(void)
void ffw_cidflatten(void)
{
if(!cur_fv->sf->cidmaster)
err("Cannot flatten a non-CID font");
SFFlatten(cur_fv->sf->cidmaster);
}
void ff_save(const char * filename)
void ffw_save(const char * filename)
{
char * _filename = strcopy(filename);
char * _ = strcopy("");
@ -201,13 +206,13 @@ void ff_save(const char * filename)
err("Cannot save font to %s\n", filename);
}
void ff_close(void)
void ffw_close(void)
{
FontViewClose(cur_fv);
cur_fv = NULL;
}
void ff_metric(int * ascent, int * descent)
void ffw_metric(int * ascent, int * descent)
{
*ascent = cur_fv->sf->ascent;
*descent = cur_fv->sf->descent;
@ -227,33 +232,33 @@ void ff_metric(int * ascent, int * descent)
cur_fv->sf->pfminfo.hheaddescent_add = 0;
}
int ff_get_em_size(void)
int ffw_get_em_size(void)
{
return (cur_fv->sf->pfminfo.os2_typoascent - cur_fv->sf->pfminfo.os2_typodescent);
}
int ff_get_max_ascent(void)
int ffw_get_max_ascent(void)
{
return max(cur_fv->sf->pfminfo.os2_winascent,
max(cur_fv->sf->pfminfo.os2_typoascent,
cur_fv->sf->pfminfo.hhead_ascent));
}
int ff_get_max_descent(void)
int ffw_get_max_descent(void)
{
return max(cur_fv->sf->pfminfo.os2_windescent,
max(-cur_fv->sf->pfminfo.os2_typodescent,
-cur_fv->sf->pfminfo.hhead_descent));
}
void ff_set_ascent(int a)
void ffw_set_ascent(int a)
{
cur_fv->sf->pfminfo.os2_winascent = a;
cur_fv->sf->pfminfo.os2_typoascent = a;
cur_fv->sf->pfminfo.hhead_ascent = a;
}
void ff_set_descent(int d)
void ffw_set_descent(int d)
{
cur_fv->sf->pfminfo.os2_windescent = d;
cur_fv->sf->pfminfo.os2_typodescent = -d;

View File

@ -1,44 +0,0 @@
/*
* ff.h
*
* Processing fonts using Fontforge
*
* fontforge.h cannot be included in C++
* So this wrapper in C publishes several functions we need
*
* by WangLu
* 2012.09.03
*/
#ifdef __cplusplus
#include <cstdint>
namespace pdf2htmlEX {
extern "C" {
#else
#include <stdint.h>
#endif
void ff_init(void);
void ff_fin(void);
void ff_load_font(const char * filename);
void ff_reencode_glyph_order(void);
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);
// fix metrics and get them
void ff_metric(int * ascent, int * descent);
int ff_get_em_size(void);
int ff_get_max_ascent(void);
int ff_get_max_descent(void);
void ff_set_ascent(int a);
void ff_set_descent(int d);
#ifdef __cplusplus
}
}
#endif

44
src/include/ffw.h Normal file
View File

@ -0,0 +1,44 @@
/*
* ffw.h : Fontforge Wrapper
*
* Processing fonts using Fontforge
*
* fontforge.h cannot be included in C++
* So this wrapper in C publishes several functions we need
*
* by WangLu
* 2012.09.03
*/
#ifdef __cplusplus
#include <cstdint>
namespace pdf2htmlEX {
extern "C" {
#else
#include <stdint.h>
#endif
void ffw_init(int debug);
void ffw_fin(void);
void ffw_load_font(const char * filename);
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);
// fix metrics and get them
void ffw_metric(int * ascent, int * descent);
int ffw_get_em_size(void);
int ffw_get_max_ascent(void);
int ffw_get_max_descent(void);
void ffw_set_ascent(int a);
void ffw_set_descent(int d);
#ifdef __cplusplus
}
}
#endif