File VFlib3-freetype2.patch of Package VFlib3
#! /bin/sh /usr/share/dpatch/dpatch-run
## 07_build_with_freetype2.dpatch by OHURA Makoto <ohura@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.
@DPATCH@
diff -urNad vflib3-3.6.14.dfsg~/configure.in vflib3-3.6.14.dfsg/configure.in
--- vflib3-3.6.14.dfsg~/configure.in 2008-06-07 15:15:49.000000000 +0900
+++ vflib3-3.6.14.dfsg/configure.in 2008-06-07 15:17:57.000000000 +0900
@@ -162,6 +162,50 @@
freetype_includedir=""; freetype_libdir="";
fi
+dnl For FreeType 2
+AC_SUBST(freetype2_includedir)
+AC_SUBST(freetype2_libdir)
+AC_SUBST(freetype2_lib)
+AC_SUBST(freetype2_objs)
+AC_ARG_WITH(
+ freetype2,
+ [ --with-freetype2[=LIB] Link FreeType 2 library LIB [LIB=freetype]],
+ if test "${withval}" = yes; then withval="freetype"; fi;
+ if test "${withval}" = no; then withval=""; fi;
+ if test "${withval}" = ""; then withval="freetype"; fi;
+ if test "${withval}" != ""; then
+ freetype2_lib=-l$withval; freetype2_objs="drv_ttf.lo";
+ AC_DEFINE(WITH_FREETYPE2)
+ fi)
+AC_ARG_WITH(
+ freetype2-includedir,
+ [ --with-freetype2-includedir=DIR FreeType 2 include files are in DIR],
+ if test "${withval}" = yes; then withval=""; fi;
+ if test "${withval}" = "";
+ then freetype2_includedir=""
+ else freetype2_includedir=-I${withval}; fi)
+AC_ARG_WITH(
+ freetype2-libdir,
+ [ --with-freetype2-libdir=DIR FreeType 2 library files are in DIR],
+ if test "${withval}" = yes; then withval=""; fi;
+ if test "${withval}" = "";
+ then freetype2_libdir=""
+ else freetype2_libdir=-L${withval}; fi)
+if test -n "$freetype2_lib" ; then
+ echo "Enabled the FreeType 2 font driver";
+ OLD_CPPFLAGS=${CPPFLAGS}; OLD_LIBS=${LIBS}
+ CPPFLAGS="${freetype2_includedir} ${CPPFLAGS}"
+ LIBS="${freetype2_libdir} ${freetype2_lib} ${LIBS}";
+ AC_TRY_CPP([#include <ft2build.h>], ,
+ AC_MSG_ERROR(Header file is not found: ${freetype2_includedir}))
+ dnl AC_TRY_LINK([#include <freetype.h>],
+ dnl [TT_Engine fte; TT_Init_FreeType(&fte)], ,
+ dnl AC_MSG_ERROR(Library file is not found: ${freetype_lib}))
+ CPPFLAGS=${OLD_CPPFLAGS}; LIBS=${OLD_LIBS}
+else echo "Disabled the FreeType 2 font driver";
+ freetype2_includedir=""; freetype2_libdir="";
+fi
+
AC_SUBST(t1lib_includedir)
AC_SUBST(t1lib_libdir)
AC_SUBST(t1lib_lib)
@@ -496,6 +540,11 @@
else
echo "** Configured to use TrueType."
fi
+if test "x-${freetype2_lib}" = "x-"; then
+ echo "** Configured NOT to use FreeType 2."
+else
+ echo "** Configured to use FreeType 2."
+fi
if test "x-${t1lib_lib}" = "x-"; then
echo "** Configured NOT to use Type 1."
else
diff -urNad vflib3-3.6.14.dfsg~/make-sub.in vflib3-3.6.14.dfsg/make-sub.in
--- vflib3-3.6.14.dfsg~/make-sub.in 2008-02-05 20:26:15.000000000 +0900
+++ vflib3-3.6.14.dfsg/make-sub.in 2008-06-07 15:17:57.000000000 +0900
@@ -4,6 +4,7 @@
VFCFLAGS=${CFLAGS} @XX_CFLAGS@ -DVFLIB_VERSION=\"@vflib_version@\"
LDFLAGS=@LDFLAGS@
EXT_LIBRARY= @freetype_libdir@ @freetype_lib@ \
+ @freetype2_libdir@ @freetype2_lib@ \
@t1lib_libdir@ @t1lib_lib@ \
@kpathsea_libdir@ @kpathsea_lib@ \
@gettext_lib@ \
diff -urNad vflib3-3.6.14.dfsg~/src/Makefile.in vflib3-3.6.14.dfsg/src/Makefile.in
--- vflib3-3.6.14.dfsg~/src/Makefile.in 2008-02-05 20:26:15.000000000 +0900
+++ vflib3-3.6.14.dfsg/src/Makefile.in 2008-06-07 15:17:57.000000000 +0900
@@ -35,7 +35,7 @@
drv_comic.c drv_try.c drv_mojikmap.c
DRV_OBJS = @bdf_objs@ @pcf_objs@ @hbf_objs@ \
@zeit_objs@ @jg_objs@ @ekan_objs@ \
- @ttf_objs@ @type1_objs@ \
+ @ttf_objs@ @freetype2_objs@ @type1_objs@ \
@texfonts_objs@ \
@gf_objs@ @pk_objs@ @tfm_objs@ @vf_objs@ @jtex_objs@ \
@comic_objs@ @try_objs@ @mojikmap_objs@
@@ -68,7 +68,7 @@
drv_ttf.lo: drv_ttf.c ttf.h
$(LIBTOOL) --mode=compile $(CC) $(VFCFLAGS) \
- @freetype_includedir@ -c drv_ttf.c
+ @freetype_includedir@ @freetype2_includedir@ -c drv_ttf.c
drv_t1.lo: drv_t1.c t1.h
$(LIBTOOL) --mode=compile $(CC) $(VFCFLAGS) \
@t1lib_includedir@ -c drv_t1.c
diff -urNad vflib3-3.6.14.dfsg~/src/drv_ini.c vflib3-3.6.14.dfsg/src/drv_ini.c
--- vflib3-3.6.14.dfsg~/src/drv_ini.c 2008-02-05 20:26:15.000000000 +0900
+++ vflib3-3.6.14.dfsg/src/drv_ini.c 2008-06-07 15:17:57.000000000 +0900
@@ -64,6 +64,9 @@
#ifdef WITH_TRUETYPE
{ VF_Init_Driver_TrueType, "TrueType" },
#endif
+#ifdef WITH_FREETYPE2
+ { VF_Init_Driver_TrueType, "TrueType" },
+#endif
#ifdef WITH_TYPE1
{ VF_Init_Driver_Type1, "Type1" },
#endif
diff -urNad vflib3-3.6.14.dfsg~/src/drv_ttf.c vflib3-3.6.14.dfsg/src/drv_ttf.c
--- vflib3-3.6.14.dfsg~/src/drv_ttf.c 2008-02-05 20:26:15.000000000 +0900
+++ vflib3-3.6.14.dfsg/src/drv_ttf.c 2008-06-07 15:17:57.000000000 +0900
@@ -47,6 +47,7 @@
*/
#include "config.h"
+#include "with.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
@@ -66,7 +67,17 @@
#include "ccv.h"
+#ifdef WITH_FREETYPE2
+# include <ft2build.h>
+# include FT_FREETYPE_H
+# include FT_GLYPH_H
+# include FT_TRIGONOMETRY_H
+typedef FT_Face TT_Face;
+typedef FT_UShort TT_UShort;
+typedef FT_Error TT_Error;
+#else
#include "freetype.h"
+#endif
#include "ttf.h"
#define DIRECTION_HORIZONTAL 0
@@ -101,10 +112,12 @@
int release_on_close;
int ttf_opened;
TT_Face tt_face;
+#ifndef WITH_FREETYPE2
TT_Instance tt_instance;
TT_CharMap tt_charmap;
TT_Glyph tt_glyph;
TT_Face_Properties tt_fprops;
+#endif
TT_UShort tt_upem;
char *font_name;
char *file_path;
@@ -177,11 +190,17 @@
Private VF_OUTLINE ttf_get_outline1(VF_FONT,long,double,double);
Private char *ttf_get_font_prop(VF_FONT,char*);
+#ifdef WITH_FREETYPE2
+Private VF_OUTLINE
+ get_outline_ttf_to_vflib(FONT_TTF, double ps, double mag_x, double mag_y,
+ double dpix, double dpiy, double asp);
+#else
Private VF_OUTLINE
get_outline_ttf_to_vflib(FONT_TTF,TT_Outline*,
TT_Glyph_Metrics*, TT_Instance_Metrics*,
double ps, double mag_x, double mag_y,
double dpix, double dpiy, double asp);
+#endif
Private long fix_jisx0212_row47_empty_sjis(long code_point);
Private int find_encoding_mapping(FONT_TTF);
Private int get_id_from_platform_name(char*);
@@ -195,7 +214,11 @@
+#ifdef WITH_FREETYPE2
+static FT_Library library;
+#else
static TT_Engine FreeType_Engine;
+#endif
static int Initialized_FreeType = 0;
@@ -259,7 +282,11 @@
return -1;
if (Initialized_FreeType == 0){
+#ifdef WITH_FREETYPE2
+ error = FT_Init_FreeType(&library);
+#else
error = TT_Init_FreeType(&FreeType_Engine);
+#endif
if (error){
vf_error = VF_ERR_FREETYPE_INIT;
return -1;
@@ -615,7 +642,24 @@
if (font_ttf == NULL)
return NULL;
+#ifdef WITH_FREETYPE2
+ if (font_ttf->ttf_opened == 0){
+ if (ttf_debug('f'))
+ printf("VFlib TrueType: FT_New_Face %s\n", font_ttf->font_name);
+ if ((error = FT_New_Face(library, font_path, (fontnum < 0) ? 0 : fontnum, &font_ttf->tt_face)))
+ return NULL;
+ else
+ font_ttf->ttf_opened = 1;
+ /* needed here? */
+ font_ttf->tt_upem = font_ttf->tt_face->units_per_EM;
+
+ if (ttf_debug('n'))
+ printf("VFlib TrueType: the number of embedded faces: %ld\n", (long)font_ttf->tt_face->num_faces);
+ if (error)
+ return NULL;
+ }
+#else
if (font_ttf->ttf_opened == 0){
if (fontnum < 0){
if (ttf_debug('f'))
@@ -648,6 +692,7 @@
if (error)
return NULL;
}
+#endif
return &font_ttf->tt_face;
}
@@ -661,14 +706,25 @@
the number of simultaneously opened files */
if (ttf_debug('f'))
printf("VFlib TrueType: TT_Flush_Face %s\n", font_ttf->font_name);
+#ifdef WITH_FREETYPE2
+ /* no supported call here... */
+#else
TT_Flush_Face(font_ttf->tt_face);
+#endif
} else {
/* after a font is closed */
if (ttf_debug('f'))
printf("VFlib TrueType: TT_Close_Face %s\n", font_ttf->font_name);
+#ifdef WITH_FREETYPE2
+ FT_Glyph glyph;
+ FT_Get_Glyph(font_ttf->tt_face->glyph, &glyph);
+ FT_Done_Glyph(glyph);
+ FT_Done_Face(font_ttf->tt_face);
+#else
TT_Done_Glyph(font_ttf->tt_glyph);
TT_Done_Instance(font_ttf->tt_instance);
TT_Close_Face(font_ttf->tt_face);
+#endif
vf_free(font_ttf->font_name);
vf_free(font_ttf->file_path);
vf_free(font_ttf);
@@ -772,6 +828,12 @@
double ps = 0.0, mx, my, asp, aspd;
double dpix = 0.0, dpiy = 0.0;
long cp;
+#ifdef WITH_FREETYPE2
+ FT_UInt chindex;
+ FT_Int32 load_flag;
+ FT_GlyphSlot slot;
+ FT_Long pointSize;
+#else
int chindex;
int load_flag;
TT_Raster_Map tt_bitmap;
@@ -779,6 +841,7 @@
TT_Instance_Metrics tt_imetrics;
TT_Outline tt_outline;
TT_Short xoff, yoff;
+#endif
TT_Error error;
error = 0;
@@ -792,6 +855,10 @@
my = mag_y * font_ttf->mag * font->mag_y;
asp = v_default_aspect * font_ttf->aspect * (mx / my);
+#ifdef WITH_FREETYPE2
+ ps = (my * ((font->point_size < 0) ? font_ttf->point_size : font->point_size));
+ pointSize = (FT_Long)(ps * 64.0);
+#endif
if ( (mode == MODE_METRIC1)
|| (mode == MODE_FONTBBX1)
|| (mode == MODE_BITMAP1)
@@ -800,9 +867,11 @@
dpix = font_ttf->dpi_x;
dpiy = font_ttf->dpi_y;
}
+#ifndef WITH_FREETYPE2
if ((ps = font->point_size) < 0)
ps = font_ttf->point_size;
ps = ps * my;
+#endif
} else if ( (mode == MODE_METRIC2)
|| (mode == MODE_FONTBBX2)
|| (mode == MODE_BITMAP2) ){
@@ -818,6 +887,13 @@
(FM_OPEN_METHOD)ttf_open_method,
(FM_CLOSE_METHOD)ttf_close_method, "FreeType");
+#ifdef WITH_FREETYPE2
+ if (mode != MODE_OUTLINE){
+ error = FT_Set_Char_Size(font_ttf->tt_face, 0, (FT_F26Dot6)(ps * 64), (int)dpix, (int)dpiy);
+ } else {
+ error = FT_Set_Char_Size(font_ttf->tt_face, 0, (FT_F26Dot6)12*64, 96*4, 96*4);
+ }
+#else
if (mode != MODE_OUTLINE){
TT_Set_Instance_Resolutions(font_ttf->tt_instance, dpix, dpiy);
error = TT_Set_Instance_PointSize(font_ttf->tt_instance, ps);
@@ -826,6 +902,7 @@
96*4, 96*4); /*XXX THESE ARE AD-HOC VALUES!!*/
error = TT_Set_Instance_PointSize(font_ttf->tt_instance, 12);
}
+#endif
if (error){
vf_error = VF_ERR_NO_GLYPH;
return NULL;
@@ -850,7 +927,22 @@
if (font_ttf->jisx0212_r47e_sjis == TRUE){
cp = fix_jisx0212_row47_empty_sjis(cp);
}
-
+#ifdef WITH_FREETYPE2
+ if (mode == MODE_METRIC1)
+ /* should this apply to MODE_METRIC2 as well? */
+ load_flag = FT_LOAD_NO_BITMAP | FT_LOAD_NO_SCALE;
+ else if (font_ttf->hinting == TRUE)
+ load_flag = FT_LOAD_NO_BITMAP;
+ else
+ load_flag = FT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING;
+ error = FT_Load_Char(font_ttf->tt_face, cp, load_flag);
+ if (error) {
+ vf_error = VF_ERR_NO_GLYPH;
+ return NULL;
+ }
+ slot = font_ttf->tt_face->glyph;
+ }
+#else
chindex = TT_Char_Index(font_ttf->tt_charmap, (int)cp);
if (chindex <= 0){
vf_error = VF_ERR_ILL_CODE_POINT;
@@ -874,9 +966,28 @@
}
(void) TT_Get_Instance_Metrics(font_ttf->tt_instance, &tt_imetrics);
+#endif
if (ttf_debug('m')){
printf("VFlib TrueType: Metrics\n");
+#ifdef WITH_FREETYPE2
+ printf(" in Header upem: %d, xMin: %d, yMin:%d, xMax:%d, yMax:%d\n",
+ font_ttf->tt_face->units_per_EM,
+ font_ttf->tt_face->bbox.xMin,
+ font_ttf->tt_face->bbox.yMin,
+ font_ttf->tt_face->bbox.xMax,
+ font_ttf->tt_face->bbox.yMax);
+
+ printf(" tt_metrics.bbx xMin:%ld, yMin:%ld, xMax:%ld, yMax:%ld\n",
+ slot->metrics.horiBearingX,
+ slot->metrics.horiBearingY - slot->metrics.height,
+ slot->metrics.width + slot->metrics.horiBearingX,
+ slot->metrics.horiBearingY);
+
+ printf(" tt_imetrics x_ppem:%d, y_ppem:%d, pointSize:%.4f, upem:%d\n",
+ font_ttf->tt_face->size->metrics.x_ppem, font_ttf->tt_face->size->metrics.y_ppem,
+ (double)(pointSize/64.0), font_ttf->tt_upem);
+#else
printf(" in Header upem: %d, xMin: %d, yMin:%d, xMax:%d, yMax:%d\n",
font_ttf->tt_fprops.header->Units_Per_EM,
font_ttf->tt_fprops.header->xMin,
@@ -889,9 +1000,50 @@
printf(" tt_imetrics x_ppem:%d, y_ppem:%d, pointSize:%.4f, upem:%d\n",
tt_imetrics.x_ppem, tt_imetrics.y_ppem,
(double)tt_imetrics.pointSize/64.0, font_ttf->tt_upem);
+#endif
}
val = NULL;
+#ifdef WITH_FREETYPE2
+ if ((mode == MODE_BITMAP1) || (mode == MODE_BITMAP2)) {
+ FT_Vector vector;
+ FT_Matrix matrix;
+ matrix.xx = (1<<16);
+ matrix.xy = 0;
+ matrix.yx = 0;
+ matrix.yy = (1<<16);
+ aspd = 1.0 - asp;
+ if (aspd < 0) {
+ aspd = 0.0 - aspd;
+ }
+ if (aspd < 1.0e-6) {
+ vector.x = -slot->metrics.horiBearingX;
+ vector.y = slot->metrics.height - slot->metrics.horiBearingY;
+ } else {
+ vector.x = -asp * slot->metrics.horiBearingX;;
+ vector.y = slot->metrics.height - slot->metrics.horiBearingY;
+ matrix.xx *= asp;
+ }
+ FT_Set_Transform(font_ttf->tt_face, &matrix, &vector);
+ error = FT_Render_Glyph(slot, FT_RENDER_MODE_MONO);
+ if (!error) {
+ ALLOC_IF_ERR(bm, struct vf_s_bitmap) {
+ vf_error = VF_ERR_NO_MEMORY;
+ return NULL;
+ }
+ bm->bbx_width = slot->bitmap.width;
+ bm->bbx_height = slot->bitmap.rows;
+ bm->raster = slot->bitmap.pitch;
+ bm->bitmap = malloc(bm->bbx_height * bm->raster);
+ memcpy(bm->bitmap, slot->bitmap.buffer, bm->bbx_height * bm->raster);
+ bm->off_x = toint(slot->metrics.horiBearingX * asp / 64.0);
+ bm->off_y = toint(slot->metrics.horiBearingY / 64.0);
+ bm->mv_x = toint(slot->metrics.horiAdvance * asp / 64.0);
+ bm->mv_y = 0;
+ val = (void*) bm;
+ }
+
+#else
if ((mode == MODE_BITMAP1) || (mode == MODE_BITMAP2)){
tt_bitmap.width = (tt_metrics.bbox.xMax-tt_metrics.bbox.xMin)*asp/64 + 1;
tt_bitmap.rows = (tt_metrics.bbox.yMax-tt_metrics.bbox.yMin)/64 + 1;
@@ -934,12 +1086,24 @@
bm->mv_y = 0;
val = (void*) bm;
+#endif
} else if (mode == MODE_METRIC1){
+ if (metric1 != NULL){
+#ifdef WITH_FREETYPE2
+ double pt = (double)pointSize / 64.0;
+ double ptx = (double)pointSize * asp / 64.0;
+ int upem = font_ttf->tt_upem;
+ metric1->bbx_width = ((double)slot->metrics.width / upem) * ptx;
+ metric1->bbx_height = ((double)slot->metrics.height / upem) * pt;
+ metric1->off_x = ((double)slot->metrics.horiBearingX / upem) * ptx;
+ metric1->off_y = ((double)slot->metrics.horiBearingY / upem) * pt;
+ metric1->mv_x = ((double)slot->advance.x / upem) * ptx; /*XXX*/
+ metric1->mv_y = ((double)slot->advance.y / upem) * pt; /*XXX*/
+#else
double xppem = 64.0 * (double)tt_imetrics.x_ppem;
double yppem = 64.0 * (double)tt_imetrics.y_ppem;
double pt = (double)tt_imetrics.pointSize / 64.0;
double ptx = (double)tt_imetrics.pointSize * asp / 64.0;
- if (metric1 != NULL){
metric1->bbx_width
= (double)((tt_metrics.bbox.xMax - tt_metrics.bbox.xMin) / xppem)*ptx;
metric1->bbx_height
@@ -948,10 +1112,22 @@
metric1->off_y = (double)(tt_metrics.bbox.yMax / yppem) * pt;
metric1->mv_x = (double)(tt_metrics.advance / xppem) * ptx; /*XXX*/
metric1->mv_y = 0.0 * pt; /*XXX*/
+#endif
}
val = (void*) metric1;
} else if (mode == MODE_METRIC2){
+#ifdef WITH_FREETYPE2
+ if (metric2 != NULL) {
+ metric2->bbx_width = toint((slot->metrics.width * asp) / 64.0);
+ metric2->bbx_height = toint(slot->metrics.height / 64.0);
+ metric2->off_x = toint((slot->metrics.horiBearingX * asp) / 64.0);
+ metric2->off_y = toint(slot->metrics.horiBearingY / 64.0);
+ metric2->mv_x = toint((slot->advance.x * asp) / 64.0);
+ metric2->mv_y = toint(slot->advance.y / 64.0);
+ }
+ val = (void*) metric2;
+#else
if (metric2 != NULL){
metric2->bbx_width
= toint((double)(tt_metrics.bbox.xMax-tt_metrics.bbox.xMin)*asp /64.0);
@@ -965,6 +1141,11 @@
val = (void*) metric2;
} else if (mode == MODE_OUTLINE){
+#endif
+#ifdef WITH_FREETYPE2
+ ol = get_outline_ttf_to_vflib(font_ttf, ps, mag_x, mag_y, dpix, dpiy, asp);
+ val = (void*) ol;
+#else
error = TT_Get_Glyph_Outline(font_ttf->tt_glyph, &tt_outline);
if (error)
return NULL;
@@ -975,10 +1156,18 @@
val = (void*) ol;
} else if (mode == MODE_FONTBBX1){
+#endif
+#ifdef WITH_FREETYPE2
+ long xmax = font_ttf->tt_face->bbox.xMax;
+ long xmin = font_ttf->tt_face->bbox.xMin;
+ long ymax = font_ttf->tt_face->bbox.yMax;
+ long ymin = font_ttf->tt_face->bbox.yMin;
+#else
long xmax = font_ttf->tt_fprops.header->xMax;
long xmin = font_ttf->tt_fprops.header->xMin;
long ymax = font_ttf->tt_fprops.header->yMax;
long ymin = font_ttf->tt_fprops.header->yMin;
+#endif
if (fontbbx1 != NULL){
fontbbx1->w = (double)(xmax - xmin) * ps * asp / font_ttf->tt_upem;
fontbbx1->h = (double)(ymax - ymin) * ps / font_ttf->tt_upem;
@@ -988,10 +1177,17 @@
val = (void*) fontbbx1;
} else if (mode == MODE_FONTBBX2){
+#ifdef WITH_FREETYPE2
+ long xmax = font_ttf->tt_face->bbox.xMax;
+ long xmin = font_ttf->tt_face->bbox.xMin;
+ long ymax = font_ttf->tt_face->bbox.yMax;
+ long ymin = font_ttf->tt_face->bbox.yMin;
+#else
long xmax = font_ttf->tt_fprops.header->xMax;
long xmin = font_ttf->tt_fprops.header->xMin;
long ymax = font_ttf->tt_fprops.header->yMax;
long ymin = font_ttf->tt_fprops.header->yMin;
+#endif
if (fontbbx2 != NULL){
fontbbx2->w = (double)(xmax - xmin) * ps * asp / font_ttf->tt_upem;
fontbbx2->h = (double)(ymax - ymin) * ps / font_ttf->tt_upem;
@@ -1050,6 +1246,11 @@
* in VFlib 2.23 by Mr Matsuda.
* --- H.Kakugawa
*/
+#ifdef WITH_FREETYPE2
+Private VF_OUTLINE
+get_outline_ttf_to_vflib(FONT_TTF font_ttf, double ps, double mag_x, double mag_y,
+ double dpix, double dpiy, double asp)
+#else
Private VF_OUTLINE
get_outline_ttf_to_vflib(FONT_TTF font_ttf,
TT_Outline *tt_outline,
@@ -1057,19 +1258,27 @@
TT_Instance_Metrics *tt_imetrics,
double ps, double mag_x, double mag_y,
double dpix, double dpiy, double asp)
+#endif
{
int vfsize, ct, pt, sp, ep, p1, p2, p3;
int maxw, maxh, bbx;
double x1, y1, x2, y2, x3, y3, f, fupem, mmm;
VF_OUTLINE_ELEM token, *vfdata, *vfp;
- mmm = 4*4; /*ad-hoc*/
-
+#ifdef WITH_FREETYPE2
+ FT_GlyphSlot slot = font_ttf->tt_face->glyph;
+ FT_Outline *tt_outline = &slot->outline;
+ maxw = slot->metrics.width + 1;
+ maxh = slot->metrics.height + 1;
+#else
maxw = (tt_metrics->bbox.xMax - tt_metrics->bbox.xMin + 1);
maxh = (tt_metrics->bbox.yMax - tt_metrics->bbox.yMin + 1);
+#endif
if ((bbx = maxw) < maxh)
bbx = maxh;
+ mmm = 4*4; /*ad-hoc*/
+
#if 0
printf("*** %d %d %d %d %d %d %d %d\n",
maxw, maxh, bbx, font_ttf->tt_upem,
@@ -1105,7 +1314,11 @@
/*XXX xCoord => points.x XXX*/
/*XXX yCoord => points.y XXX*/
/*XXX flag[] => flags XXX*/
+#ifdef WITH_FREETYPE2
+ if (tt_outline->tags[p1] & tt_outline->tags[p2] & TTF_OL_ONCURVE){
+#else
if (tt_outline->flags[p1] & tt_outline->flags[p2] & TTF_OL_ONCURVE){
+#endif
/* Line */
if (token != VF_OL_INSTR_LINE){
token = VF_OL_INSTR_LINE;
@@ -1113,7 +1326,11 @@
}
vfsize += 1;
} else {
+#ifdef WITH_FREETYPE2
+ if (tt_outline->tags[p2] & TTF_OL_ONCURVE)
+#else
if (tt_outline->flags[p2] & TTF_OL_ONCURVE)
+#endif
continue;
/* spline */
if (token != VF_OL_INSTR_BEZ){
@@ -1137,6 +1354,18 @@
vfdata[VF_OL_HEADER_INDEX_DPI_Y] = VF_OL_HEADER_ENCODE(dpiy);
vfdata[VF_OL_HEADER_INDEX_POINT_SIZE] = VF_OL_HEADER_ENCODE(ps);
vfdata[VF_OL_HEADER_INDEX_EM] = ceil(fupem * font_ttf->tt_upem);
+#ifdef WITH_FREETYPE2
+ vfdata[VF_OL_HEADER_INDEX_MAX_X] = toint(f * slot->metrics.width) + 1;
+ vfdata[VF_OL_HEADER_INDEX_MAX_Y] = toint(f * slot->metrics.height) + 1;
+ /* ... horizintal direction only. B-( */
+ vfdata[VF_OL_HEADER_INDEX_REF_X] = toint(f * slot->metrics.horiBearingX);
+ vfdata[VF_OL_HEADER_INDEX_REF_Y] = toint(f * slot->metrics.horiBearingY);
+ vfdata[VF_OL_HEADER_INDEX_MV_X] = toint(f * slot->metrics.horiAdvance);
+ vfdata[VF_OL_HEADER_INDEX_MV_Y] = toint(f * 0);
+
+#define ConvX(x) (long)(VF_OL_COORD_OFFSET + f * ((x)-slot->metrics.horiBearingX))
+#define ConvY(y) (long)(VF_OL_COORD_OFFSET + f * (slot->metrics.horiBearingY-(y)))
+#else
vfdata[VF_OL_HEADER_INDEX_MAX_X]
= toint(f * (tt_metrics->bbox.xMax - tt_metrics->bbox.xMin)) + 1;
vfdata[VF_OL_HEADER_INDEX_MAX_Y]
@@ -1149,7 +1378,7 @@
#define ConvX(x) (long)(VF_OL_COORD_OFFSET + f * ((x)-tt_metrics->bbox.xMin))
#define ConvY(y) (long)(VF_OL_COORD_OFFSET + f * (tt_metrics->bbox.yMax-(y)))
-
+#endif
vfp = &vfdata[VF_OL_OUTLINE_HEADER_SIZE_TYPE0];
for (ct = pt = 0; ct < tt_outline->n_contours; ct++){
token = (VF_OL_INSTR_TOKEN | VF_OL_INSTR_CWCURV);
@@ -1159,7 +1388,11 @@
p1 = pt;
p2 = (p1 < ep) ? (p1 + 1) : sp;
p3 = (p2 < ep) ? (p2 + 1) : sp;
+#ifdef WITH_FREETYPE2
+ if (tt_outline->tags[p1] & tt_outline->tags[p2] & TTF_OL_ONCURVE){
+#else
if (tt_outline->flags[p1] & tt_outline->flags[p2] & TTF_OL_ONCURVE){
+#endif
/* Line */
if (token != (VF_OL_INSTR_TOKEN | VF_OL_INSTR_LINE)) {
if (token == (VF_OL_INSTR_TOKEN | VF_OL_INSTR_CWCURV)){
@@ -1173,7 +1406,11 @@
y1 = tt_outline->points[p1].y;
*(vfp++) = VF_OL_MAKE_XY(ConvX(x1), ConvY(y1));
} else {
+#ifdef WITH_FREETYPE2
+ if (tt_outline->tags[p2] & TTF_OL_ONCURVE)
+#else
if (tt_outline->flags[p2] & TTF_OL_ONCURVE)
+#endif
continue;
/* spline */
if (token != (VF_OL_INSTR_TOKEN | VF_OL_INSTR_BEZ)){
@@ -1184,7 +1421,11 @@
}
token = VF_OL_INSTR_TOKEN | VF_OL_INSTR_BEZ;
}
+#ifdef WITH_FREETYPE2
+ if (tt_outline->tags[p1] & TTF_OL_ONCURVE){
+#else
if (tt_outline->flags[p1] & TTF_OL_ONCURVE){
+#endif
x1 = tt_outline->points[p1].x;
y1 = tt_outline->points[p1].y;
} else {
@@ -1193,7 +1434,11 @@
}
x2 = tt_outline->points[p2].x;
y2 = tt_outline->points[p2].y;
+#ifdef WITH_FREETYPE2
+ if (tt_outline->tags[p3] & TTF_OL_ONCURVE){
+#else
if (tt_outline->flags[p3] & TTF_OL_ONCURVE){
+#endif
x3 = tt_outline->points[p3].x;
y3 = tt_outline->points[p3].y;
} else {
@@ -1312,7 +1557,11 @@
/* Find mapping table number to be used in TrueType font file. */
map = font_ttf->mapping_id;
+#ifdef WITH_FREETYPE2
+ ntables = font_ttf->tt_face->num_charmaps;
+#else
ntables = TT_Get_CharMap_Count(font_ttf->tt_face);
+#endif
if (map != TT_MAP_ID_SEARCH){
if (ntables == 0){
fprintf(stderr, "VFlib TrueType warning: No mapping tables: %s\n",
@@ -1327,18 +1576,28 @@
fprintf(stderr, "VFlib TrueType warning: Illegal mapping table ID.");
fprintf(stderr, "Use mapping table #0.\n");
}
+#ifdef WITH_FREETYPE2
+ platform_id = font_ttf->tt_face->charmaps[map]->platform_id;
+ encoding_id = font_ttf->tt_face->charmaps[map]->encoding_id;
+#else
error = TT_Get_CharMap_ID(font_ttf->tt_face, map,
&platform_id, &encoding_id);
if (error)
return -1;
+#endif
if (ttf_debug('p'))
printf("VFlib TrueType: Platform,Encoding=(%s,%s)\n",
platform_id2name(platform_id),
encoding_id2name(platform_id, encoding_id));
} else {
for (map = 0; map < ntables; map++){
+#ifdef WITH_FREETYPE2
+ platform_id = font_ttf->tt_face->charmaps[map]->platform_id;
+ encoding_id = font_ttf->tt_face->charmaps[map]->encoding_id;
+#else
error = TT_Get_CharMap_ID(font_ttf->tt_face, map,
&platform_id, &encoding_id);
+#endif
if (ttf_debug('p'))
printf("VFlib TrueType: mapping #%d: Platform: %s, Encoding:%s\n",
map,
@@ -1364,8 +1623,12 @@
printf("VFlib TrueType: Use mapping table #%d (encoding#%d)\n",
font_ttf->mapping_id, encoding_id);
+#ifdef WITH_FREETYPE2
+ error = FT_Set_Charmap(font_ttf->tt_face, font_ttf->tt_face->charmaps[map]);
+#else
error = TT_Get_CharMap(font_ttf->tt_face, font_ttf->mapping_id,
&font_ttf->tt_charmap);
+#endif
if (error)
return -1;
diff -urNad vflib3-3.6.14.dfsg~/src/with.h.in vflib3-3.6.14.dfsg/src/with.h.in
--- vflib3-3.6.14.dfsg~/src/with.h.in 2008-02-05 20:26:15.000000000 +0900
+++ vflib3-3.6.14.dfsg/src/with.h.in 2008-06-07 15:17:57.000000000 +0900
@@ -22,6 +22,9 @@
/* Define if you compile VFlib with TrueType font driver */
#undef WITH_TRUETYPE
+/* Define if you compile VFlib with FreeType 2 font driver */
+#undef WITH_FREETYPE2
+
/* Define if you compile VFlib with Type1 font driver */
#undef WITH_TYPE1