int main( void) { GLYPH *glyph; int i; char * my_config = malloc(25); sprintf(my_config, "T1LIB_CONFIG=%s",LOCAL_CONFIG); /* Set our environment to an existent config file directory */ putenv( my_config); /* Pad bitmaps to 16 bits, the default being 8 bits */ T1_SetBitmapPad( 16); /* Initialize t1lib and return if error occurs. No logfile will be generated */ if ((T1_InitLib(NO_LOGFILE)==NULL)){ fprintf(stderr, "Initialization of t1lib failed\n"); return(-1); } /* For every font in the database, generate a glyph for the string "Test" at 25 bp. Use Kerning. Then dump an ASCII representation of the glyph to stdout */ for( i=0; i<T1_GetNoFonts(); i++){ printf("FontID=%d, Font=%s\n", i, T1_GetFontFilePath(i)); printf("FontID=%d, Metrics=%s\n", i, T1_GetAfmFilePath(i)); glyph=T1_SetString( i, "Test", 0, 0, T1_KERNING, 25.0, NULL); T1_DumpGlyph( glyph); } /* Close library and free all data */ T1_CloseLib(); return( 0); }
SWFFONT* swf_LoadT1Font(const char*filename) { SWFFONT * font; int nr; float angle,underline; char*fontname,*fullname,*familyname; BBox bbox; int s,num; char**charnames; char**charname; char*encoding[256]; int c; int t; if(!t1lib_initialized) { T1_SetBitmapPad(16); if ((T1_InitLib(NO_LOGFILE)==NULL)){ fprintf(stderr, "Initialization of t1lib failed\n"); return 0; } t1lib_initialized = 1; } nr = T1_AddFont(filename); T1_LoadFont(nr); charnames = T1_GetAllCharNames(nr); if(!charnames) { fprintf(stderr, "No Charnames record- not a Type1 Font?\n"); return 0; } angle = T1_GetItalicAngle(nr); fontname = T1_GetFontName(nr); fullname = T1_GetFullName(nr); familyname = T1_GetFamilyName(nr); underline = T1_GetUnderlinePosition(nr); bbox = T1_GetFontBBox(nr); font = (SWFFONT*)rfx_calloc(sizeof(SWFFONT)); font->version = 2; if(fontname) font->name = (U8*)strdup(fontname); else font->name = 0; font->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT)); num = 0; charname = charnames; while(*charname) { charname++; if(num<256) { if(*charname) encoding[num] = strdup(*charname); else encoding[num] = strdup(".notdef"); } num++; } for(t=num;t<256;t++) encoding[t] = strdup(".notdef"); //T1_ReencodeFont(nr, encoding); font->maxascii = num; font->numchars = num; font->style = (/*bold*/0?FONT_STYLE_BOLD:0) + (angle>0.05?FONT_STYLE_ITALIC:0); font->glyph = (SWFGLYPH*)rfx_calloc(num*sizeof(SWFGLYPH)); font->glyph2ascii = (U16*)rfx_calloc(num*sizeof(U16)); font->ascii2glyph = (int*)rfx_calloc(font->maxascii*sizeof(int)); font->layout->ascent = (U16)(underline - bbox.lly); font->layout->descent = (U16)(bbox.ury - underline); font->layout->leading = (U16)(font->layout->ascent - font->layout->descent - (bbox.lly - bbox.ury)); font->layout->bounds = (SRECT*)rfx_calloc(sizeof(SRECT)*num); font->layout->kerningcount = 0; font->layout->kerning = 0; font->glyphnames = rfx_calloc(num*sizeof(char*)); num = 0; charname = charnames; for(c=0;c<font->numchars;c++) { drawer_t draw; SRECT bbox; T1_OUTLINE * outline; FPOINT pos,last; int firstx; outline = T1_GetCharOutline(nr, c, 100.0, 0); firstx = outline->dest.x/0xffff; pos.x = 0; pos.y = 0; last = pos; font->glyphnames[c] = strdup(*charname); if(c<font->maxascii) font->ascii2glyph[c] = c; font->glyph2ascii[c] = c; swf_Shape01DrawerInit(&draw, 0); while(outline) { pos.x += (outline->dest.x/(float)0xffff); pos.y += (outline->dest.y/(float)0xffff); if(outline->type == T1_PATHTYPE_MOVE) { draw.moveTo(&draw,&pos); } else if(outline->type == T1_PATHTYPE_LINE) { draw.lineTo(&draw,&pos); } else if(outline->type == T1_PATHTYPE_BEZIER) { T1_BEZIERSEGMENT*o2 = (T1_BEZIERSEGMENT*)outline; FPOINT b,c; b.x = o2->B.x/(float)0xffff+last.x; b.y = o2->B.y/(float)0xffff+last.y; c.x = o2->C.x/(float)0xffff+last.x; c.y = o2->C.y/(float)0xffff+last.y; draw_cubicTo(&draw,&b,&c,&pos); } else { fprintf(stderr, "loadT1Font: unknown outline type:%d\n", outline->type); } last = pos; outline = outline->link; } draw.finish(&draw); font->glyph[c].shape = swf_ShapeDrawerToShape(&draw); bbox = swf_ShapeDrawerGetBBox(&draw); draw.dealloc(&draw); font->layout->bounds[c] = bbox; font->glyph[c].advance = bbox.xmax; if(!font->glyph[c].advance) { font->glyph[c].advance = firstx; } charname++; } T1_DeleteFont(nr); for(t=0;t<256;t++) rfx_free(encoding[t]); return font; }