🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: adobe.typography
1 messages
1 total messages Started by Robin Hoo Tue, 31 Jul 2007 00:08
How can I get the right glyph
#762
Author: Robin Hoo
Date: Tue, 31 Jul 2007 00:08
137 lines
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;
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads