]> git.imager.perl.org - imager.git/blobdiff - font.c
0.73 release
[imager.git] / font.c
diff --git a/font.c b/font.c
index cd6aaef4d01c642f4cdb2faa2f6331a97c2c7f96..706f06d6ee110d0477a6b05a714c47cdda3e0d35 100644 (file)
--- a/font.c
+++ b/font.c
@@ -63,18 +63,10 @@ i_init_fonts(int t1log) {
   mm_log((1,"Initializing fonts\n"));
 
 #ifdef HAVE_LIBT1
-  i_init_t1(t1log);
-#endif
-  
-#ifdef HAVE_LIBTT
-  i_init_tt();
-#endif
-
-#ifdef HAVE_FT2
-  if (!i_ft2_init())
+  if (i_init_t1(t1log))
     return 0;
 #endif
-
+  
   return(1); /* FIXME: Always true - check the return values of the init_t1 and init_tt functions */
 }
 
@@ -104,8 +96,11 @@ i_init_t1(int t1log) {
   int init_flags = IGNORE_CONFIGFILE|IGNORE_FONTDATABASE;
   mm_log((1,"init_t1()\n"));
 
+  i_clear_error();
+
   if (t1_active_fonts) {
     mm_log((1, "Cannot re-initialize T1 - active fonts\n"));
+    i_push_error(0, "Cannot re-initialize T1 - active fonts");
     return 1;
   }
 
@@ -117,6 +112,7 @@ i_init_t1(int t1log) {
     init_flags |= LOGFILE;
   if ((T1_InitLib(init_flags) == NULL)){
     mm_log((1,"Initialization of t1lib failed\n"));
+    i_push_error(0, "T1_InitLib failed");
     return(1);
   }
   T1_SetLogLevel(T1LOG_DEBUG);
@@ -160,6 +156,11 @@ int
 i_t1_new(char *pfb,char *afm) {
   int font_id;
 
+  i_clear_error();
+
+  if (!t1_initialized && i_init_t1(0))
+    return -1;
+
   mm_log((1,"i_t1_new(pfb %s,afm %s)\n",pfb,(afm?afm:"NULL")));
   font_id = T1_AddFont(pfb);
   if (font_id<0) {
@@ -407,10 +408,9 @@ Interface to text rendering in a single color onto an image
 undef_int
 i_t1_text(i_img *im,int xb,int yb,const i_color *cl,int fontnum,float points,const char* str,int len,int align, int utf8, char const *flags) {
   GLYPH *glyph;
-  int xsize,ysize,x,y,ch;
-  i_color val;
-  unsigned char c,i;
+  int xsize,ysize,y;
   int mod_flags = t1_get_flags(flags);
+  i_render r;
 
   if (im == NULL) { mm_log((1,"i_t1_cp: Null image in input\n")); return(0); }
 
@@ -438,14 +438,13 @@ i_t1_text(i_img *im,int xb,int yb,const i_color *cl,int fontnum,float points,con
   mm_log((1,"width: %d height: %d\n",xsize,ysize));
 
   if (align==1) { xb+=glyph->metrics.leftSideBearing; yb-=glyph->metrics.ascent; }
-  
-  for(y=0;y<ysize;y++) for(x=0;x<xsize;x++) {
-    c=glyph->bits[y*xsize+x];
-    i=255-c;
-    i_gpix(im,x+xb,y+yb,&val);
-    for(ch=0;ch<im->channels;ch++) val.channel[ch]=(c*cl->channel[ch]+i*val.channel[ch])/255;
-    i_ppix(im,x+xb,y+yb,&val);
+
+  i_render_init(&r, im, xsize);
+  for(y=0;y<ysize;y++) {
+    i_render_color(&r, xb, yb+y, xsize, (unsigned char *)glyph->bits+y*xsize, cl);
   }
+  i_render_done(&r);
+    
   return 1;
 }
 
@@ -853,6 +852,7 @@ static undef_int i_tt_bbox_inst( TT_Fonthandle *handle, int inst ,const char *tx
 
 /* static globals needed */
 
+static int TT_initialized = 0;
 static TT_Engine    engine;
 static int  LTT_dpi    = 72; /* FIXME: this ought to be a part of the call interface */
 static int  LTT_hinted = 1;  /* FIXME: this too */
@@ -872,14 +872,18 @@ Initializes the freetype font rendering engine
 */
 
 undef_int
-i_init_tt() {
+i_init_tt(void) {
   TT_Error  error;
   TT_Byte palette[] = { 0, 64, 127, 191, 255 };
 
+  i_clear_error();
+
   mm_log((1,"init_tt()\n"));
   error = TT_Init_FreeType( &engine );
   if ( error ){
     mm_log((1,"Initialization of freetype failed, code = 0x%x\n",error));
+    i_tt_push_error(error);
+    i_push_error(0, "Could not initialize freetype 1.x");
     return(1);
   }
 
@@ -887,6 +891,9 @@ i_init_tt() {
   error = TT_Init_Post_Extension( engine );
   if (error) {
     mm_log((1, "Initialization of Post extension failed = 0x%x\n", error));
+    
+    i_tt_push_error(error);
+    i_push_error(0, "Could not initialize FT 1.x POST extension");
     return 1;
   }
 #endif
@@ -894,9 +901,13 @@ i_init_tt() {
   error = TT_Set_Raster_Gray_Palette(engine, palette);
   if (error) {
     mm_log((1, "Initialization of gray levels failed = 0x%x\n", error));
+    i_tt_push_error(error);
+    i_push_error(0, "Could not initialize FT 1.x POST extension");
     return 1;
   }
 
+  TT_initialized = 1;
+
   return(0);
 }
 
@@ -1021,6 +1032,11 @@ i_tt_new(const char *fontname) {
   unsigned short i,n;
   unsigned short platform,encoding;
 
+  if (!TT_initialized && i_init_tt()) {
+    i_push_error(0, "Could not initialize FT1 engine");
+    return NULL;
+  }
+
   i_clear_error();
   
   mm_log((1,"i_tt_new(fontname '%s')\n",fontname));
@@ -1515,8 +1531,7 @@ static
 void
 i_tt_dump_raster_map2( i_img* im, TT_Raster_Map* bit, int xb, int yb, const i_color *cl, int smooth ) {
   unsigned char *bmap;
-  i_color val;
-  int c, i, ch, x, y;
+  int x, y;
   mm_log((1,"i_tt_dump_raster_map2(im 0x%x, bit 0x%X, xb %d, yb %d, cl 0x%X)\n",im,bit,xb,yb,cl));
   
   bmap = bit->bitmap;
@@ -1578,7 +1593,7 @@ Function to dump a raster onto a single channel image in color (internal)
 static
 void
 i_tt_dump_raster_map_channel( i_img* im, TT_Raster_Map*  bit, int xb, int yb, int channel, int smooth ) {
-  char *bmap;
+  unsigned char *bmap;
   i_color val;
   int c,x,y;
   int old_mask = im->ch_mask;
@@ -1586,7 +1601,7 @@ i_tt_dump_raster_map_channel( i_img* im, TT_Raster_Map*  bit, int xb, int yb, in
 
   mm_log((1,"i_tt_dump_raster_channel(im 0x%x, bit 0x%X, xb %d, yb %d, channel %d)\n",im,bit,xb,yb,channel));
   
-  bmap = (char *)bit->bitmap;
+  bmap = bit->bitmap;
   
   if ( smooth ) {
     for(y=0;y<bit->rows;y++) for(x=0;x<bit->width;x++) {