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

working on font encoding

This commit is contained in:
Lu Wang 2012-08-26 23:56:38 +08:00
parent d920cbdc83
commit a907cda379
3 changed files with 86 additions and 88 deletions

View File

@ -18,14 +18,5 @@ void BackgroundRenderer::drawChar(GfxState *state, double x, double y,
double originX, double originY,
CharCode code, int nBytes, Unicode *u, int uLen)
{
auto font = state->getFont();
if((font->getType() == fontType3)
|| (font->getWMode())
|| (uLen == 0)
|| (!all_of(u, u+uLen, isLegalUnicode))
)
{
SplashOutputDev::drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
}
}

View File

@ -17,6 +17,8 @@
#include "HTMLRenderer.h"
#include "namespace.h"
using std::all_of;
long long HTMLRenderer::install_font(GfxFont * font)
{
assert(sizeof(long long) == 2*sizeof(int));
@ -129,16 +131,33 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix,
auto ctu = font->getToUnicode();
int * code2GID = nullptr;
int code2GID_len = 0;
int maxcode = 0;
// if we cannot map to unicode through ctu, map the char to private Unicode values
auto map_to_unicode = [&ctu, this](int c, Unicode ** u)->int
{
int n = 0;
if(ctu)
{
int maxcode = 0;
n = ctu->mapToUnicode(c, u);
}
if((n == 0) || (!all_of(*u, (*u)+n, isLegalUnicode)))
{
static Unicode _ = 0;
_ = c + 0xE000;
*u = &_;
n = 1;
}
return n;
};
if(!font->isCIDFont())
{
maxcode = 0xff;
if(suffix == ".ttf")
{
script_fout << "Reencode(\"original\")" << endl;
int buflen;
char * buf = nullptr;
if((buf = font->readEmbFontFile(xref, &buflen)))
@ -186,17 +205,14 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix,
for(int i = 0; i <= maxcode; ++i)
{
Unicode * u;
auto n = ctu->mapToUnicode(i, &u);
int n = map_to_unicode(i, &u);
// not sure what to do when n > 1
if(n > 0)
{
++cnt;
map_fout << format("0x%|1$X|") % ((code2GID && (i < code2GID_len))? code2GID[i] : i);
for(int j = 0; j < n; ++j)
map_fout << format(" 0x%|1$X|") % u[j];
map_fout << format(" # 0x%|1$X|") % i << endl;
}
}
if(cnt > 0)
{
@ -205,8 +221,8 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix,
}
}
if(ctu)
ctu->decRefCnt();
}
script_fout << format("Generate(%1%)") % ((param->single_html ? tmp_dir : dest_dir) / (fn+".ttf")) << endl;
if(param->single_html)

View File

@ -204,17 +204,8 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
}
else
{
// should not consider hozi scaling here
// will be handled by draw_ctm
double target = dx1 * fs + cs;
if(n == 1 && *p == ' ')
target += state->getWordSpace();
double w;
auto wid = install_whitespace(target * draw_scale, w);
html_fout << format("<span class=\"_ _%|1$x|\">%2%</span>") % wid % (target > 0 ? " " : "");
dxerr += w/draw_scale - target;
Unicode u = 0xE000 + code;
outputUnicodes(html_fout, &u, 1);
}
dx += dx1;