#include <stdio.h>
#include <stdlib.h>
+#ifdef HAVE_LIBT1
+#include <t1lib.h>
+#endif
+
+
/*
=head1 NAME
static void t1_push_error(void);
+static int t1_active_fonts = 0;
+static int t1_initialized = 0;
+
/*
=item i_init_t1(t1log)
i_init_t1(int t1log) {
int init_flags = IGNORE_CONFIGFILE|IGNORE_FONTDATABASE;
mm_log((1,"init_t1()\n"));
+
+ if (t1_active_fonts) {
+ mm_log((1, "Cannot re-initialize T1 - active fonts\n"));
+ return 1;
+ }
+
+ if (t1_initialized) {
+ T1_CloseLib();
+ }
if (t1log)
init_flags |= LOGFILE;
}
T1_SetLogLevel(T1LOG_DEBUG);
i_t1_set_aa(1); /* Default Antialias value */
+
+ ++t1_initialized;
+
return(0);
}
void
i_close_t1(void) {
T1_CloseLib();
+ t1_initialized = 0;
}
if (T1_SetAfmFileName(font_id,afm)<0) mm_log((1,"i_t1_new: afm loading of '%s' failed.\n",afm));
}
+ ++t1_active_fonts;
+
return font_id;
}
int
i_t1_destroy(int font_id) {
mm_log((1,"i_t1_destroy(font_id %d)\n",font_id));
+
+ --t1_active_fonts;
+
return T1_DeleteFont(font_id);
}
/* Truetype font support */
#ifdef HAVE_LIBTT
-/* This is enabled by default when configuring Freetype 1.x
+/* These are enabled by default when configuring Freetype 1.x
I haven't a clue how to reliably detect it at compile time.
We need a compilation probe in Makefile.PL
*/
#define FTXPOST 1
+#define FTXERR18 1
#include <freetype.h>
#define TT_CHC 5
#include <ftxpost.h>
#endif
+#ifdef FTXERR18
+#include <ftxerr18.h>
+#endif
+
/* some versions of FT1.x don't seem to define this - it's font defined
so it won't change */
#ifndef TT_MS_LANGID_ENGLISH_GENERAL
#define USTRCT(x) ((x).z)
#define TT_VALID( handle ) ( ( handle ).z != NULL )
+static void i_tt_push_error(TT_Error rc);
/* Prototypes */
TT_Fonthandle *handle;
unsigned short i,n;
unsigned short platform,encoding;
+
+ i_clear_error();
mm_log((1,"i_tt_new(fontname '%s')\n",fontname));
mm_log((1, "Error while opening %s, error code = 0x%x.\n",fontname,
error ));
}
+ i_tt_push_error(error);
return NULL;
}
return 0;
}
- /* ascent = ( handle->properties.horizontal->Ascender * handle->instanceh[inst].imetrics.y_ppem ) / handle->properties.header->Units_Per_EM; */
-
if ( smooth ) i_tt_done_raster_map( &small_bit );
return 1;
}
*/
undef_int
-i_tt_cp( TT_Fonthandle *handle, i_img *im, int xb, int yb, int channel, float points, char const* txt, int len, int smooth, int utf8 ) {
+i_tt_cp( TT_Fonthandle *handle, i_img *im, int xb, int yb, int channel, float points, char const* txt, int len, int smooth, int utf8, int align ) {
int cords[BOUNDING_BOX_COUNT];
- int ascent, st_offset;
+ int ascent, st_offset, y;
TT_Raster_Map bit;
i_clear_error();
if (! i_tt_rasterize( handle, &bit, cords, points, txt, len, smooth, utf8 ) ) return 0;
- ascent=cords[5];
- st_offset=cords[0];
+ ascent=cords[BBOX_ASCENT];
+ st_offset=cords[BBOX_NEG_WIDTH];
+ y = align ? yb-ascent : yb;
- i_tt_dump_raster_map_channel( im, &bit, xb-st_offset , yb-ascent, channel, smooth );
+ i_tt_dump_raster_map_channel( im, &bit, xb-st_offset , y, channel, smooth );
i_tt_done_raster_map( &bit );
return 1;
*/
undef_int
-i_tt_text( TT_Fonthandle *handle, i_img *im, int xb, int yb, i_color *cl, float points, char const* txt, int len, int smooth, int utf8) {
+i_tt_text( TT_Fonthandle *handle, i_img *im, int xb, int yb, i_color *cl, float points, char const* txt, int len, int smooth, int utf8, int align) {
int cords[BOUNDING_BOX_COUNT];
- int ascent, st_offset;
+ int ascent, st_offset, y;
TT_Raster_Map bit;
i_clear_error();
if (! i_tt_rasterize( handle, &bit, cords, points, txt, len, smooth, utf8 ) ) return 0;
- ascent=cords[5];
- st_offset=cords[0];
+ ascent=cords[BBOX_ASCENT];
+ st_offset=cords[BBOX_NEG_WIDTH];
+ y = align ? yb-ascent : yb;
- i_tt_dump_raster_map2( im, &bit, xb+st_offset, yb-ascent, cl, smooth );
+ i_tt_dump_raster_map2( im, &bit, xb+st_offset, y, cl, smooth );
i_tt_done_raster_map( &bit );
return 1;
#endif
}
+/*
+=item i_tt_push_error(code)
+
+Push an error message and code onto the Imager error stack.
+
+=cut
+*/
+static void
+i_tt_push_error(TT_Error rc) {
+#ifdef FTXERR18
+ TT_String const *msg = TT_ErrToString18(rc);
+
+ i_push_error(rc, msg);
+#else
+ i_push_errorf(rc, "Error code 0x%04x", (unsigned)rc);
+#endif
+}
+
#endif /* HAVE_LIBTT */