1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-10-06 12:01:39 +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, double originX, double originY,
CharCode code, int nBytes, Unicode *u, int uLen) 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 "HTMLRenderer.h"
#include "namespace.h" #include "namespace.h"
using std::all_of;
long long HTMLRenderer::install_font(GfxFont * font) long long HTMLRenderer::install_font(GfxFont * font)
{ {
assert(sizeof(long long) == 2*sizeof(int)); 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(); auto ctu = font->getToUnicode();
int * code2GID = nullptr; int * code2GID = nullptr;
int code2GID_len = 0; 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) 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()) if(!font->isCIDFont())
{ {
maxcode = 0xff; maxcode = 0xff;
if(suffix == ".ttf") if(suffix == ".ttf")
{ {
script_fout << "Reencode(\"original\")" << endl;
int buflen; int buflen;
char * buf = nullptr; char * buf = nullptr;
if((buf = font->readEmbFontFile(xref, &buflen))) 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) for(int i = 0; i <= maxcode; ++i)
{ {
Unicode * u; Unicode * u;
auto n = ctu->mapToUnicode(i, &u); int n = map_to_unicode(i, &u);
// not sure what to do when n > 1 // not sure what to do when n > 1
if(n > 0)
{
++cnt; ++cnt;
map_fout << format("0x%|1$X|") % ((code2GID && (i < code2GID_len))? code2GID[i] : i); map_fout << format("0x%|1$X|") % ((code2GID && (i < code2GID_len))? code2GID[i] : i);
for(int j = 0; j < n; ++j) for(int j = 0; j < n; ++j)
map_fout << format(" 0x%|1$X|") % u[j]; map_fout << format(" 0x%|1$X|") % u[j];
map_fout << format(" # 0x%|1$X|") % i << endl; map_fout << format(" # 0x%|1$X|") % i << endl;
} }
}
if(cnt > 0) if(cnt > 0)
{ {
@ -205,8 +221,8 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix,
} }
} }
if(ctu)
ctu->decRefCnt(); ctu->decRefCnt();
}
script_fout << format("Generate(%1%)") % ((param->single_html ? tmp_dir : dest_dir) / (fn+".ttf")) << endl; script_fout << format("Generate(%1%)") % ((param->single_html ? tmp_dir : dest_dir) / (fn+".ttf")) << endl;
if(param->single_html) if(param->single_html)

View File

@ -204,17 +204,8 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
} }
else else
{ {
// should not consider hozi scaling here Unicode u = 0xE000 + code;
// will be handled by draw_ctm outputUnicodes(html_fout, &u, 1);
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;
} }
dx += dx1; dx += dx1;