Article View: adobe.typography
Article #762How can I get the right glyph
From: Robin Hoo
Date: Tue, 31 Jul 2007 00:08
Date: Tue, 31 Jul 2007 00:08
137 lines
6490 bytes
6490 bytes
Hi, All
I'm working on the coding about extract the ttf glyph as a piece of
postscript code. I got stuck in how to get the right glyph on some
open type font. The problem is my code works perfect to the Japanese
and simplify Chinese but not works to the traditional Chinese and
Korean fonts. It seems there some new offset or glyph array should be
taken care of. And I found the GSUB table invovled, but I don't know
how to use it to detect the right glyph array or glyph offset. I'll
post my code. Anyone got any idea, pls show me some lights on it.
Thanks in advance.
char * ttf2PSproc(char *codepage, unsigned short unicode)
/*
* from TTF file, generate the PS procedure for individual char
* now handle composite glyph
*/
{
static char PostScript[40960];
unsigned short cidx = fontIndex(codepage,unicode/256,unicode
%256);
unsigned short flag, glyphindex;
short arg1, arg2;
float matrix[4];
long lcoff;
int k;
long m;
char FileName[256];
FILE *FontFile;
if (getFontFileName(codepage)==NULL) errorHandler(vstrcat("Can
not
open the font file name of %s!\n",codepage),"ttf2PSproc()",__LINE__,
0) ;
strcpy(FileName,getFontFileName(codepage));
FontFile=fopen(FileName,"rb");
if (FontFile==NULL) errorHandler(vstrcat("Can not open the font
file
%s!\n",FileName),"ttf2PSproc()",__LINE__,0) ;
PostScript[0]='\0';
pidx = oidx = 0; /* idx must reset after each glyf */
lcoff = TTFFont.glyf.offset + localOffset(FontFile,
codepage,cidx);
fseek(FontFile, lcoff, 0);
TTFFont.glyf_nctours = (short) get2Byte(FontFile);
if (TTFFont.glyf_nctours >= 0)
{
TTFFont.g_xoff = TTFFont.g_yoff = 0;
TTFFont.g_xx = TTFFont.g_yy = 1.0;
TTFFont.g_xy = TTFFont.g_yx = 0.0;
getGlyf(FontFile, cidx);
buildGlyph();
strcat(PostScript,uappendFill85());
clearData();
}
else if (TTFFont.glyf_nctours < 0)
{ /* composite glyph */
get2Byte(FontFile); get2Byte(FontFile);
get2Byte(FontFile); get2Byte(FontFile); /* skip glyf
boundingbox */
lcoff += 10L;
k=0;
do
{
TTFFont.g_xoff = TTFFont.g_yoff = 0;
TTFFont.g_xx = TTFFont.g_yy = 1.0;
TTFFont.g_xy = TTFFont.g_yx = 0.0;
if (k++ > 0)
{
strcat(PostScript, "U\n");
pidx = oidx = 0;
}
fseek(FontFile, lcoff, 0);
flag = get2Byte(FontFile);
glyphindex = get2Byte(FontFile);
lcoff += 4L;
if (flag & ARG_1_AND_2_ARE_WORDS)
{
arg1 = (short) get2Byte(FontFile);
arg2 = (short) get2Byte(FontFile);
lcoff += 4L;
}
else
{
m = get2Byte(FontFile);
lcoff += 2L;
arg1 = (char) (m >> 8);
arg2 = (char) (m & 0xFF);
}
matrix[1] = matrix[2] = 0.0;
if (flag & HAVE_A_SCALE)
{
matrix[0] = matrix[3] = f2Dot14((short)
get2Byte(FontFile));
lcoff += 2L;
}
else if (flag & HAVE_XY_SCALES)
{
matrix[0] = f2Dot14((short)
get2Byte(FontFile));
matrix[3] = f2Dot14((short)
get2Byte(FontFile));
lcoff += 4L;
}
else if (flag & HAVE_A_TWO_BY_TWO)
{
matrix[0] = f2Dot14((short)
get2Byte(FontFile));
matrix[1] = f2Dot14((short)
get2Byte(FontFile));
matrix[2] = f2Dot14((short)
get2Byte(FontFile));
matrix[3] = f2Dot14((short)
get2Byte(FontFile));
lcoff += 8L;
}
else
{
matrix[0] = matrix[3] = 1.0;
}
TTFFont.g_xoff = arg1;
TTFFont.g_yoff = arg2;
TTFFont.g_xx = matrix[0];
TTFFont.g_xy = matrix[1];
TTFFont.g_yx = matrix[2];
TTFFont.g_yy = matrix[3];
getGlyf(FontFile,glyphindex);
buildGlyph();
strcat(PostScript,uappendFill85());
clearData();
} while (flag & MORE_COMPONENTS);
}
fclose(FontFile);
return PostScript;
}
Technical Details
Message-ID:
<1185840517.774955.168910@q75g2000hsh.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!q75g2000hsh.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1042b6,f7f2410abeb060b6,start X-Google-Attributes: gid1042b6,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!q75g2000hsh.googlegroups.com!not-for-mail From: Robin Hoo <robin.hoo.cn@gmail.com> Newsgroups: adobe.typography Subject: How can I get the right glyph Date: Tue, 31 Jul 2007 00:08:37 -0000 Organization: http://groups.google.com Lines: 138 Message-ID: <1185840517.774955.168910@q75g2000hsh.googlegroups.com> NNTP-Posting-Host: 210.13.107.131 Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312" X-Trace: posting.google.com 1185840517 11265 127.0.0.1 (31 Jul 2007 00:08:37 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 31 Jul 2007 00:08:37 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: q75g2000hsh.googlegroups.com; posting-host=210.13.107.131; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0