From c830201fcd8fb1d63c20fcefc70d36c24e54187d Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Tue, 22 Nov 2005 09:12:05 +0000 Subject: Add checks for ATSUI. 2005-11-21 Anders Carlsson * configure.in: Add checks for ATSUI. * examples/Makefile.am: Only build pango-cairoview if freetype is detected. * modules/basic/Makefile.am: Add basic ATSUI module. * pango/Makefile.am: Add ATSUI files for cairo backend. * pango/pangocairo-fontmap.c: (pango_cairo_font_map_new): Support creating ATSUI font maps here. * pango/pangoatsui-fontmap.c: * pango/pangoatsui-private.h: * pango/pangoatsui.c: * pango/pangoatsui.h: * pango/pangocairo-atsui.h: * pango/pangocairo-atsuifont.c: * pango/pangocairo-atsuifont.h: * pango/pangocairo-atsuifontmap.c: Add. --- ChangeLog | 28 ++ configure.in | 52 ++- examples/Makefile.am | 2 + modules/basic/Makefile.am | 15 + pango/Makefile.am | 13 + pango/pangoatsui-fontmap.c | 697 ++++++++++++++++++++++++++++++++++++++++ pango/pangoatsui-private.h | 105 ++++++ pango/pangoatsui.c | 103 ++++++ pango/pangoatsui.h | 33 ++ pango/pangocairo-atsui.h | 57 ++++ pango/pangocairo-atsuifont.c | 271 ++++++++++++++++ pango/pangocairo-atsuifont.h | 38 +++ pango/pangocairo-atsuifontmap.c | 110 +++++++ pango/pangocairo-fontmap.c | 8 +- 14 files changed, 1527 insertions(+), 5 deletions(-) create mode 100644 pango/pangoatsui-fontmap.c create mode 100644 pango/pangoatsui-private.h create mode 100644 pango/pangoatsui.c create mode 100644 pango/pangoatsui.h create mode 100644 pango/pangocairo-atsui.h create mode 100644 pango/pangocairo-atsuifont.c create mode 100644 pango/pangocairo-atsuifont.h create mode 100644 pango/pangocairo-atsuifontmap.c diff --git a/ChangeLog b/ChangeLog index 237b16b1..9ee313fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2005-11-21 Anders Carlsson + + * configure.in: + Add checks for ATSUI. + + * examples/Makefile.am: + Only build pango-cairoview if freetype is detected. + + * modules/basic/Makefile.am: + Add basic ATSUI module. + + * pango/Makefile.am: + Add ATSUI files for cairo backend. + + * pango/pangocairo-fontmap.c: + (pango_cairo_font_map_new): + Support creating ATSUI font maps here. + + * pango/pangoatsui-fontmap.c: + * pango/pangoatsui-private.h: + * pango/pangoatsui.c: + * pango/pangoatsui.h: + * pango/pangocairo-atsui.h: + * pango/pangocairo-atsuifont.c: + * pango/pangocairo-atsuifont.h: + * pango/pangocairo-atsuifontmap.c: + Add. + 2005-11-21 Behdad Esfahbod * pango/pango-script.c (pango_script_for_unichar_bsearch): Only update diff --git a/configure.in b/configure.in index a6418690..ced767e5 100644 --- a/configure.in +++ b/configure.in @@ -270,12 +270,18 @@ fi AC_SUBST(WIN32_LIBS) AM_CONDITIONAL(HAVE_WIN32, $have_win32) +# +# Checks for ATSUI +# +AC_CHECK_HEADER(Carbon/Carbon.h, [have_atsui=true], [have_atsui=true]) + # # Checks for Cairo # have_cairo=false have_cairo_freetype=false have_cairo_win32=false +have_cairo_atsui=false PKG_CHECK_MODULES(CAIRO, cairo >= 0.5.2-head, have_cairo=true, :) @@ -290,7 +296,12 @@ if $have_cairo ; then if $have_cairo_freetype && $have_freetype ; then AC_DEFINE(HAVE_CAIRO_FREETYPE, 1, [Whether Cairo uses FreeType for fonts]) else - have_cairo=false + AC_CHECK_LIB(cairo, cairo_atsui_font_face_create_for_atsu_font_id, have_cairo_atsui=true, :) + if $have_cairo_atsui && $have_atsui ; then + AC_DEFINE(HAVE_CAIRO_ATSUI, 1, [Whether Cairo uses ATSUI for fonts]) + else + have_cairo=false + fi fi fi LDFLAGS=$pango_save_ldflags @@ -299,6 +310,7 @@ fi AM_CONDITIONAL(HAVE_CAIRO, $have_cairo) AM_CONDITIONAL(HAVE_CAIRO_WIN32, $have_cairo_win32 && $have_win32) AM_CONDITIONAL(HAVE_CAIRO_FREETYPE, $have_cairo_freetype && $have_freetype) +AM_CONDITIONAL(HAVE_CAIRO_ATSUI, $have_cairo_atsui && $have_atsui) # # We must have some backend defined, in order for the pango-querymodules @@ -306,8 +318,8 @@ AM_CONDITIONAL(HAVE_CAIRO_FREETYPE, $have_cairo_freetype && $have_freetype) # a new Pango backend outside of Pango, you are up to sending the necessary # patch to fix that rule. :-) # -if $have_freetype || $have_x || $have_xft || $have_win32 ; then : ; else - AC_MSG_ERROR([*** Didn't find any of FreeType, X11, or Win32. +if $have_freetype || $have_x || $have_xft || $have_win32 || $have_cairo_atsui ; then : ; else + AC_MSG_ERROR([*** Didn't find any of FreeType, X11, ATSUI or Win32. *** Must have at least one backend to build Pango.]) fi @@ -386,6 +398,7 @@ AM_CONDITIONAL(HAVE_INCLUDED_MODULES, test "x$included_modules" != x) INCLUDED_X_MODULES= INCLUDED_FC_MODULES= INCLUDED_WIN32_MODULES= +INCLUDED_ATSUI_MODULES= IFS="${IFS= }"; pango_save_ifs="$IFS"; IFS="," for module in $included_modules; do if echo $indic_modules | egrep "(^| )$module(\$| )" > /dev/null; then @@ -400,6 +413,8 @@ for module in $included_modules; do INCLUDED_X_MODULES="$INCLUDED_X_MODULES \$(top_builddir)/modules/$dir/libpango-$module.la" elif echo $module | egrep -- "-win32($|,)" > /dev/null; then INCLUDED_WIN32_MODULES="$INCLUDED_WIN32_MODULES \$(top_builddir)/modules/$dir/libpango-$module.la" + elif echo $module | egrep -- "-atsui($|,)" > /dev/null; then + INCLUDED_ATSUI_MODULES="$INCLUDED_ATSUI_MODULES \$(top_builddir)/modules/$dir/libpango-$module.la" else AC_MSG_ERROR([the specified module $module does not exist]) fi @@ -409,12 +424,14 @@ IFS="$pango_save_ifs" AC_SUBST(INCLUDED_X_MODULES) AC_SUBST(INCLUDED_FC_MODULES) AC_SUBST(INCLUDED_WIN32_MODULES) +AC_SUBST(INCLUDED_ATSUI_MODULES) AM_CONDITIONAL(INCLUDE_ARABIC_FC,echo $included_modules | egrep '(^|,)arabic-fc($|,)' > /dev/null) AM_CONDITIONAL(INCLUDE_BASIC_FC,echo $included_modules | egrep '(^|,)basic-fc($|,)' > /dev/null) AM_CONDITIONAL(INCLUDE_BASIC_WIN32,echo $included_modules | egrep '(^|,)basic-win32($|,)' > /dev/null) AM_CONDITIONAL(INCLUDE_BASIC_X,echo $included_modules | egrep '(^|,)basic-x($|,)' > /dev/null) +AM_CONDITIONAL(INCLUDE_BASIC_ATSUI,echo $included_modules | egrep '(^|,)basic-x($|,)' > /dev/null) AM_CONDITIONAL(INCLUDE_HANGUL_FC,echo $included_modules | egrep '(^|,)hangul-fc($|,)' > /dev/null) @@ -699,6 +716,35 @@ cat >> pango/module-defs-win32.c < pango/module-defs-atsui.c <@ = { +EOTEXT + +IFS="${IFS= }"; pango_save_ifs="$IFS"; IFS="," +for module in $included_modules; do + if echo $module | egrep -- "-atsui($|,)" > /dev/null; then + module_c=`echo $module | sed s/-/_/` + cat >> pango/module-defs-atsui.c <> pango/module-defs-atsui.c < + +typedef struct _PangoATSUIFamily PangoATSUIFamily; +typedef struct _PangoATSUIFace PangoATSUIFace; +typedef struct _FontHashKey FontHashKey; + +struct _PangoATSUIFamily +{ + PangoFontFamily parent_instance; + + char *family_name; + + PangoFontFace **faces; + gint n_faces; +}; + +#define PANGO_TYPE_ATSUI_FAMILY (pango_atsui_family_get_type ()) +#define PANGO_ATSUI_FAMILY(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_ATSUI_FAMILY, PangoATSUIFamily)) +#define PANGO_ATSUI_IS_FAMILY(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_ATSUI_FAMILY)) + +#define PANGO_TYPE_ATSUI_FACE (pango_atsui_face_get_type ()) +#define PANGO_ATSUI_FACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_ATSUI_FACE, PangoATSUIFace)) +#define PANGO_ATSUI_IS_FACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_ATSUI_FACE)) + +struct _PangoATSUIFace +{ + PangoFontFace parent_instance; + + PangoATSUIFamily *family; + + char *postscript_name; + char *style_name; + + int weight; + int traits; +}; + +static GType pango_atsui_family_get_type (void); +static GType pango_atsui_face_get_type (void); + +static gpointer pango_atsui_family_parent_class; +static gpointer pango_atsui_face_parent_class; + +static const char * +get_real_family (const char *family_name) +{ + switch (family_name[0]) + { + case 'm': + case 'M': + if (g_ascii_strcasecmp (family_name, "monospace") == 0) + return "Courier"; + break; + case 's': + case 'S': + if (g_ascii_strcasecmp (family_name, "sans") == 0) + return "Helvetica"; + else if (g_ascii_strcasecmp (family_name, "serif") == 0) + return "Times"; + break; + } + + return family_name; +} + +static void +pango_atsui_family_list_faces (PangoFontFamily *family, + PangoFontFace ***faces, + int *n_faces) +{ + PangoATSUIFamily *atsuifamily = PANGO_ATSUI_FAMILY (family); + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + if (atsuifamily->n_faces < 0) + { + const char *real_family = get_real_family (atsuifamily->family_name); + NSArray *members = [[NSFontManager sharedFontManager] availableMembersOfFontFamily:[NSString stringWithUTF8String:real_family]]; + int i; + + atsuifamily->n_faces = [members count]; + atsuifamily->faces = g_new (PangoFontFace *, atsuifamily->n_faces); + + for (i = 0; i < atsuifamily->n_faces; i++) + { + PangoATSUIFace *face = g_object_new (PANGO_TYPE_ATSUI_FACE, NULL); + NSArray *font_array = [members objectAtIndex:i]; + + face->family = atsuifamily; + face->postscript_name = g_strdup ([[font_array objectAtIndex:0] UTF8String]); + face->style_name = g_strdup ([[font_array objectAtIndex:1] UTF8String]); + face->weight = [[font_array objectAtIndex:2] intValue]; + face->traits = [[font_array objectAtIndex:3] intValue]; + + atsuifamily->faces[i] = (PangoFontFace *)face; + } + } + + if (n_faces) + *n_faces = atsuifamily->n_faces; + + if (faces) + *faces = g_memdup (atsuifamily->faces, atsuifamily->n_faces * sizeof (PangoFontFace *)); + + [pool release]; +} + +static const char * +pango_atsui_family_get_name (PangoFontFamily *family) +{ + PangoATSUIFamily *atsuifamily = PANGO_ATSUI_FAMILY (family); + + return atsuifamily->family_name; +} + +static gboolean +pango_atsui_family_is_monospace (PangoFontFamily *family) +{ + /* Fixme: Implement */ + return FALSE; +} + +static void +pango_atsui_family_finalize (GObject *object) +{ + PangoATSUIFamily *family = PANGO_ATSUI_FAMILY (object); + int i; + + g_free (family->family_name); + + if (family->n_faces != -1) + { + for (i = 0; i < family->n_faces; i++) + { + g_object_unref (family->faces[i]); + } + + g_free (family->faces); + } + + G_OBJECT_CLASS (pango_atsui_family_parent_class)->finalize (object); +} + +static void +pango_atsui_family_class_init (PangoFontFamilyClass *class) +{ + GObjectClass *object_class = (GObjectClass *)class; + + pango_atsui_family_parent_class = g_type_class_peek_parent (class); + + object_class->finalize = pango_atsui_family_finalize; + + class->list_faces = pango_atsui_family_list_faces; + class->get_name = pango_atsui_family_get_name; + class->is_monospace = pango_atsui_family_is_monospace; +} + +static void +pango_atsui_family_init (PangoATSUIFamily *family) +{ + family->n_faces = -1; +} + +static GType +pango_atsui_family_get_type (void) +{ + static GType object_type = 0; + + if (!object_type) + { + static const GTypeInfo object_info = + { + sizeof (PangoFontFamilyClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) pango_atsui_family_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (PangoATSUIFamily), + 0, /* n_preallocs */ + (GInstanceInitFunc) pango_atsui_family_init, + }; + + object_type = g_type_register_static (PANGO_TYPE_FONT_FAMILY, + "PangoATSUIFamily", + &object_info, 0); + } + + return object_type; +} + +static PangoFontDescription * +pango_atsui_face_describe (PangoFontFace *face) +{ + PangoATSUIFace *atsuiface = PANGO_ATSUI_FACE (face); + PangoFontDescription *description; + PangoWeight pango_weight; + PangoStyle pango_style; + PangoVariant pango_variant; + int weight; + + description = pango_font_description_new (); + + pango_font_description_set_family (description, atsuiface->family->family_name); + + weight = atsuiface->weight; + + if (weight == 1 || weight == 2) + pango_weight = PANGO_WEIGHT_ULTRALIGHT; + else if (weight == 3 || weight == 4) + pango_weight = PANGO_WEIGHT_LIGHT; + else if (weight == 5 || weight == 6) + pango_weight = PANGO_WEIGHT_NORMAL; + else if (weight == 7 || weight == 8) + pango_weight = PANGO_WEIGHT_SEMIBOLD; + else if (weight == 9 || weight == 10) + pango_weight = PANGO_WEIGHT_BOLD; + else if (weight == 11 || weight == 12) + pango_weight = PANGO_WEIGHT_ULTRABOLD; + else if (weight == 13 || weight == 14) + pango_weight = PANGO_WEIGHT_HEAVY; + else + g_assert_not_reached (); + + if (atsuiface->traits & NSItalicFontMask) + pango_style = PANGO_STYLE_ITALIC; + else + pango_style = PANGO_STYLE_NORMAL; + + if (atsuiface->traits & NSSmallCapsFontMask) + pango_variant = PANGO_VARIANT_SMALL_CAPS; + else + pango_variant = PANGO_VARIANT_NORMAL; + + pango_font_description_set_weight (description, pango_weight); + pango_font_description_set_style (description, pango_style); + + return description; +} + +static const char * +pango_atsui_face_get_face_name (PangoFontFace *face) +{ + PangoATSUIFace *atsuiface = PANGO_ATSUI_FACE (face); + + return atsuiface->style_name; +} + +static void +pango_atsui_face_list_sizes (PangoFontFace *face, + int **sizes, + int *n_sizes) +{ + *n_sizes = 0; + *sizes = NULL; +} + +static void +pango_atsui_face_finalize (GObject *object) +{ + PangoATSUIFace *atsuiface = PANGO_ATSUI_FACE (object); + + g_free (atsuiface->postscript_name); + g_free (atsuiface->style_name); + + G_OBJECT_CLASS (pango_atsui_face_parent_class)->finalize (object); +} + +static void +pango_atsui_face_class_init (PangoFontFaceClass *class) +{ + GObjectClass *object_class = (GObjectClass *)class; + + pango_atsui_face_parent_class = g_type_class_peek_parent (class); + + object_class->finalize = pango_atsui_face_finalize; + + class->describe = pango_atsui_face_describe; + class->get_face_name = pango_atsui_face_get_face_name; + class->list_sizes = pango_atsui_face_list_sizes; +} + +GType +pango_atsui_face_get_type (void) +{ + static GType object_type = 0; + + if (!object_type) + { + static const GTypeInfo object_info = + { + sizeof (PangoFontFaceClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) pango_atsui_face_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (PangoATSUIFace), + 0, /* n_preallocs */ + (GInstanceInitFunc) NULL, + }; + + object_type = g_type_register_static (PANGO_TYPE_FONT_FACE, + "PangoATSUIFace", + &object_info, 0); + } + + return object_type; +} + +static void pango_atsui_font_map_class_init (PangoATSUIFontMapClass *class); +static void pango_atsui_font_map_init (PangoATSUIFontMap *atsuifontmap); + +static guint font_hash_key_hash (const FontHashKey *key); +static gboolean font_hash_key_equal (const FontHashKey *key_a, + const FontHashKey *key_b); +static void font_hash_key_free (FontHashKey *key); + +G_DEFINE_TYPE (PangoATSUIFontMap, pango_atsui_font_map, PANGO_TYPE_FONT_MAP); + +static void +pango_atsui_font_map_finalize (GObject *object) +{ + PangoATSUIFontMap *fontmap = PANGO_ATSUI_FONT_MAP (object); + + g_hash_table_destroy (fontmap->font_hash); + g_hash_table_destroy (fontmap->families); + + G_OBJECT_CLASS (pango_atsui_font_map_parent_class)->finalize (object); +} + +struct _FontHashKey { + PangoATSUIFontMap *fontmap; + PangoMatrix matrix; + PangoFontDescription *desc; + char *postscript_name; + gpointer context_key; +}; + +/* Fowler / Noll / Vo (FNV) Hash (http://www.isthe.com/chongo/tech/comp/fnv/) + * + * Not necessarily better than a lot of other hashes, but should be OK, and + * well tested with binary data. + */ + +#define FNV_32_PRIME ((guint32)0x01000193) +#define FNV1_32_INIT ((guint32)0x811c9dc5) + +static guint32 +hash_bytes_fnv (unsigned char *buffer, + int len, + guint32 hval) +{ + while (len--) + { + hval *= FNV_32_PRIME; + hval ^= *buffer++; + } + + return hval; +} + +static gboolean +font_hash_key_equal (const FontHashKey *key_a, + const FontHashKey *key_b) +{ + if (key_a->matrix.xx == key_b->matrix.xx && + key_a->matrix.xy == key_b->matrix.xy && + key_a->matrix.yx == key_b->matrix.yx && + key_a->matrix.yy == key_b->matrix.yy && + pango_font_description_equal (key_a->desc, key_b->desc) && + strcmp (key_a->postscript_name, key_b->postscript_name) == 0) + { + if (key_a->context_key) + return PANGO_ATSUI_FONT_MAP_GET_CLASS (key_a->fontmap)->context_key_equal (key_a->fontmap, + key_a->context_key, + key_b->context_key); + else + return TRUE; + } + else + return FALSE; +} + +static guint +font_hash_key_hash (const FontHashKey *key) +{ + guint32 hash = FNV1_32_INIT; + + /* We do a bytewise hash on the context matrix */ + hash = hash_bytes_fnv ((unsigned char *)(&key->matrix), + sizeof(double) * 4, + hash); + + if (key->context_key) + hash ^= PANGO_ATSUI_FONT_MAP_GET_CLASS (key->fontmap)->context_key_hash (key->fontmap, + key->context_key); + + hash ^= g_str_hash (key->postscript_name); + + return (hash ^ pango_font_description_hash (key->desc)); +} + +static void +font_hash_key_free (FontHashKey *key) +{ + if (key->context_key) + PANGO_ATSUI_FONT_MAP_GET_CLASS (key->fontmap)->context_key_free (key->fontmap, + key->context_key); + + g_free (key); +} + +static FontHashKey * +font_hash_key_copy (FontHashKey *old) +{ + FontHashKey *key = g_new (FontHashKey, 1); + + key->fontmap = old->fontmap; + key->matrix = old->matrix; + key->desc = pango_font_description_copy (old->desc); + key->postscript_name = g_strdup (old->postscript_name); + if (old->context_key) + key->context_key = PANGO_ATSUI_FONT_MAP_GET_CLASS (key->fontmap)->context_key_copy (key->fontmap, + old->context_key); + else + key->context_key = NULL; + + return key; +} + + +static void +get_context_matrix (PangoContext *context, + PangoMatrix *matrix) +{ + const PangoMatrix *set_matrix; + static const PangoMatrix identity = PANGO_MATRIX_INIT; + + if (context) + set_matrix = pango_context_get_matrix (context); + else + set_matrix = NULL; + + if (set_matrix) + *matrix = *set_matrix; + else + *matrix = identity; +} + +static void +font_hash_key_for_context (PangoATSUIFontMap *fcfontmap, + PangoContext *context, + FontHashKey *key) +{ + key->fontmap = fcfontmap; + get_context_matrix (context, &key->matrix); + + if (PANGO_ATSUI_FONT_MAP_GET_CLASS (fcfontmap)->context_key_get) + key->context_key = (gpointer)PANGO_ATSUI_FONT_MAP_GET_CLASS (fcfontmap)->context_key_get (fcfontmap, context); + else + key->context_key = NULL; +} + +static void +pango_atsui_font_map_add (PangoATSUIFontMap *atsuifontmap, + PangoContext *context, + PangoATSUIFont *atsuifont) +{ + FontHashKey key; + FontHashKey *key_copy; + + g_assert (atsuifont->fontmap == NULL); + + atsuifont->fontmap = g_object_ref (atsuifontmap); + + font_hash_key_for_context (atsuifontmap, context, &key); + key.postscript_name = atsuifont->postscript_name; + key.desc = atsuifont->desc; + + key_copy = font_hash_key_copy (&key); + atsuifont->context_key = key_copy->context_key; + atsuifont->matrix = key.matrix; + g_hash_table_insert (atsuifontmap->font_hash, key_copy, g_object_ref (atsuifont)); +} + +static PangoATSUIFont * +pango_atsui_font_map_lookup (PangoATSUIFontMap *atsuifontmap, + PangoContext *context, + PangoFontDescription *desc, + const char *postscript_name) +{ + FontHashKey key; + + font_hash_key_for_context (atsuifontmap, context, &key); + key.postscript_name = (char *)postscript_name; + key.desc = desc; + + return g_hash_table_lookup (atsuifontmap->font_hash, &key); +} + +static PangoFont * +pango_atsui_font_map_load_font (PangoFontMap *fontmap, + PangoContext *context, + const PangoFontDescription *description) +{ + PangoATSUIFontMap *atsuifontmap = (PangoATSUIFontMap *)fontmap; + PangoATSUIFamily *font_family; + gchar *name; + gint size; + + g_return_val_if_fail (description != NULL, NULL); + + size = pango_font_description_get_size (description); + + if (size <= 0) + return NULL; + + name = g_utf8_casefold (pango_font_description_get_family (description), -1); + + font_family = g_hash_table_lookup (atsuifontmap->families, name); + g_free (name); + if (font_family) + { + PangoFontDescription *best_desc = NULL, *new_desc; + PangoATSUIFace *best_face = NULL; + PangoATSUIFont *best_font; + int i; + + /* Force a listing of the available faces */ + pango_font_family_list_faces ((PangoFontFamily *)font_family, NULL, NULL); + + for (i = 0; i < font_family->n_faces; i++) + { + new_desc = pango_font_face_describe (font_family->faces[i]); + + if (pango_font_description_better_match (description, best_desc, new_desc)) + { + pango_font_description_free (best_desc); + best_desc = new_desc; + best_face = (PangoATSUIFace *)font_family->faces[i]; + } + else + { + pango_font_description_free (new_desc); + } + } + + pango_font_description_set_size (best_desc, size); + + best_font = pango_atsui_font_map_lookup (atsuifontmap, context, best_desc, best_face->postscript_name); + + if (best_font) + g_object_ref (best_font); + else + { + best_font = (* PANGO_ATSUI_FONT_MAP_GET_CLASS (atsuifontmap)->create_font) (atsuifontmap, context, + best_face->postscript_name, best_desc); + + if (best_font) + pango_atsui_font_map_add (atsuifontmap, context, best_font); + } + + pango_font_description_free (best_desc); + return PANGO_FONT (best_font); + } + return NULL; +} + +static void +list_families_foreach (gpointer key, + gpointer value, + gpointer user_data) +{ + GSList **list = user_data; + + *list = g_slist_prepend (*list, value); +} + +static void +pango_atsui_font_map_list_families (PangoFontMap *fontmap, + PangoFontFamily ***families, + int *n_families) +{ + GSList *family_list = NULL; + GSList *tmp_list; + PangoATSUIFontMap *atsuifontmap = (PangoATSUIFontMap *)fontmap; + + if (!n_families) + return; + + g_hash_table_foreach (atsuifontmap->families, list_families_foreach, &family_list); + + *n_families = g_slist_length (family_list); + + if (families) + { + int i = 0; + + *families = g_new (PangoFontFamily *, *n_families); + + tmp_list = family_list; + while (tmp_list) + { + (*families)[i] = tmp_list->data; + i++; + tmp_list = tmp_list->next; + } + } + + g_slist_free (family_list); +} + +static void +pango_atsui_font_map_init (PangoATSUIFontMap *atsuifontmap) +{ + NSArray *family_array; + NSAutoreleasePool *pool; + PangoATSUIFamily *family; + + int size, i; + + atsuifontmap->families = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, g_object_unref); + + + atsuifontmap->font_hash = g_hash_table_new_full ((GHashFunc)font_hash_key_hash, + (GEqualFunc)font_hash_key_equal, + (GDestroyNotify)font_hash_key_free, + NULL); + + pool = [[NSAutoreleasePool alloc] init]; + family_array = [[NSFontManager sharedFontManager] availableFontFamilies]; + size = [family_array count]; + + for (i = 0; i < size; i++) { + NSString *family_name = [family_array objectAtIndex:i]; + + family = g_object_new (PANGO_TYPE_ATSUI_FAMILY, NULL); + family->family_name = g_strdup ([family_name UTF8String]); + + g_hash_table_insert (atsuifontmap->families, g_utf8_casefold (family->family_name, -1), family); + } + + /* Insert aliases */ + family = g_object_new (PANGO_TYPE_ATSUI_FAMILY, NULL); + family->family_name = g_strdup ("Sans"); + g_hash_table_insert (atsuifontmap->families, g_utf8_casefold (family->family_name, -1), family); + + family = g_object_new (PANGO_TYPE_ATSUI_FAMILY, NULL); + family->family_name = g_strdup ("Serif"); + g_hash_table_insert (atsuifontmap->families, g_utf8_casefold (family->family_name, -1), family); + + family = g_object_new (PANGO_TYPE_ATSUI_FAMILY, NULL); + family->family_name = g_strdup ("Monospace"); + g_hash_table_insert (atsuifontmap->families, g_utf8_casefold (family->family_name, -1), family); + + [pool release]; +} + +static void +pango_atsui_font_map_class_init (PangoATSUIFontMapClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + PangoFontMapClass *fontmap_class = PANGO_FONT_MAP_CLASS (class); + + object_class->finalize = pango_atsui_font_map_finalize; + + fontmap_class->load_font = pango_atsui_font_map_load_font; + fontmap_class->list_families = pango_atsui_font_map_list_families; + fontmap_class->shape_engine_type = PANGO_RENDER_TYPE_ATSUI; +} + + diff --git a/pango/pangoatsui-private.h b/pango/pangoatsui-private.h new file mode 100644 index 00000000..f0603c24 --- /dev/null +++ b/pango/pangoatsui-private.h @@ -0,0 +1,105 @@ +/* Pango + * pangoatsui-private.h: + * + * Copyright (C) 2003 Red Hat Software + * Copyright (C) 2005 Imendio AB + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __PANGOATSUI_PRIVATE_H__ +#define __PANGOATSUI_PRIVATE_H__ + +#include +#include + +G_BEGIN_DECLS + +#define PANGO_TYPE_ATSUI_FONT_MAP (pango_atsui_font_map_get_type ()) +#define PANGO_ATSUI_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_ATSUI_FONT_MAP, PangoATSUIFontMap)) +#define PANGO_ATSUI_IS_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_ATSUI_FONT_MAP)) +#define PANGO_ATSUI_FONT_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_ATSUI_FONT_MAP, PangoATSUIFontMapClass)) +#define PANGO_IS_ATSUI_FONT_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_ATSUI_FONT_MAP)) +#define PANGO_ATSUI_FONT_MAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_ATSUI_FONT_MAP, PangoATSUIFontMapClass)) + +#define PANGO_TYPE_ATSUI_FONT (pango_atsui_font_get_type ()) +#define PANGO_ATSUI_FONT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_ATSUI_FONT, PangoATSUIFont)) +#define PANGO_ATSUI_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_ATSUI_FONT, PangoATSUIFontClass)) +#define PANGO_ATSUI_IS_FONT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_ATSUI_FONT)) +#define PANGO_ATSUI_IS_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_ATSUI_FONT)) +#define PANGO_ATSUI_FONT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_ATSUI_FONT, PangoATSUIFontClass)) + +#define PANGO_RENDER_TYPE_ATSUI "PangoRenderATSUI" + +typedef struct _PangoATSUIFontMap PangoATSUIFontMap; +typedef struct _PangoATSUIFontMapClass PangoATSUIFontMapClass; +typedef struct _PangoATSUIFont PangoATSUIFont; +typedef struct _PangoATSUIFontClass PangoATSUIFontClass; + +struct _PangoATSUIFontMap +{ + PangoFontMap parent_instance; + + GHashTable *font_hash; + + GHashTable *families; +}; + +struct _PangoATSUIFontMapClass +{ + PangoFontMapClass parent_class; + + gconstpointer (*context_key_get) (PangoATSUIFontMap *atsuifontmap, + PangoContext *context); + gpointer (*context_key_copy) (PangoATSUIFontMap *atsuifontmap, + gconstpointer key); + void (*context_key_free) (PangoATSUIFontMap *atsuifontmap, + gpointer key); + guint32 (*context_key_hash) (PangoATSUIFontMap *atsuifontmap, + gconstpointer key); + gboolean (*context_key_equal) (PangoATSUIFontMap *atsuifontmap, + gconstpointer key_a, + gconstpointer key_b); + + PangoATSUIFont * (* create_font) (PangoATSUIFontMap *fontmap, + PangoContext *context, + const char *postscript_name, + const PangoFontDescription *desc); +}; + +struct _PangoATSUIFont +{ + PangoFont parent_instance; + + char *postscript_name; + PangoFontDescription *desc; + PangoMatrix matrix; + gpointer context_key; + + PangoFontMap *fontmap; +}; + +struct _PangoATSUIFontClass +{ + PangoFontClass parent_class; +}; + +GType pango_atsui_font_map_get_type (void); +GType pango_atsui_font_get_type (void); + +G_END_DECLS + +#endif /* __PANGOATSUI_H__ */ diff --git a/pango/pangoatsui.c b/pango/pangoatsui.c new file mode 100644 index 00000000..d58a7ac4 --- /dev/null +++ b/pango/pangoatsui.c @@ -0,0 +1,103 @@ +/* Pango + * pangatsui.c + * + * Copyright (C) 2005 Imendio AB + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "pangoatsui-private.h" + +G_DEFINE_TYPE (PangoATSUIFont, pango_atsui_font, PANGO_TYPE_FONT); + +static void +pango_atsui_font_finalize (GObject *object) +{ + PangoATSUIFont *font = (PangoATSUIFont *)object; + + g_free (font->postscript_name); + pango_font_description_free (font->desc); + + g_object_unref (font->fontmap); + + G_OBJECT_CLASS (pango_atsui_font_parent_class)->finalize (object); +} + +static PangoFontDescription * +pango_atsui_font_describe (PangoFont *font) +{ + PangoATSUIFont *atsuifont = PANGO_ATSUI_FONT (font); + + return pango_font_description_copy (atsuifont->desc); +} + +static PangoCoverage * +pango_atsui_font_get_coverage (PangoFont *font, + PangoLanguage *language) +{ + PangoCoverage *coverage; + int i; + + /* FIXME: Currently we say that all fonts have the + * 255 first glyphs. This is not true. + */ + coverage = pango_coverage_new (); + + for (i = 0; i < 256; i++) + pango_coverage_set (coverage, i, PANGO_COVERAGE_EXACT); + + return coverage; +} + +static PangoEngineShape * +pango_atsui_font_find_shaper (PangoFont *font, + PangoLanguage *language, + guint32 ch) +{ + /* FIXME: Implement */ + return NULL; +} + +static PangoFontMap * +pango_atsui_font_get_font_map (PangoFont *font) +{ + PangoATSUIFont *atsuifont = (PangoATSUIFont *)font; + + return atsuifont->fontmap; +} + +static void +pango_atsui_font_init (PangoATSUIFont *font) +{ +} + +static void +pango_atsui_font_class_init (PangoATSUIFontClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + PangoFontClass *font_class = PANGO_FONT_CLASS (class); + + object_class->finalize = pango_atsui_font_finalize; + + font_class->describe = pango_atsui_font_describe; + font_class->get_coverage = pango_atsui_font_get_coverage; + font_class->find_shaper = pango_atsui_font_find_shaper; + font_class->get_font_map = pango_atsui_font_get_font_map; +} + + + + diff --git a/pango/pangoatsui.h b/pango/pangoatsui.h new file mode 100644 index 00000000..801d9e41 --- /dev/null +++ b/pango/pangoatsui.h @@ -0,0 +1,33 @@ +/* Pango + * pangoatsui.h: + * + * Copyright (C) 2005 Imendio AB + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __PANGOATSUI_H__ +#define __PANGOATSUI_H__ + +#include + +G_BEGIN_DECLS + +#define PANGO_RENDER_TYPE_ATSUI "PangoRenderATSUI" + +G_END_DECLS + +#endif /* __PANGOATSUI_H__ */ diff --git a/pango/pangocairo-atsui.h b/pango/pangocairo-atsui.h new file mode 100644 index 00000000..4b030cf8 --- /dev/null +++ b/pango/pangocairo-atsui.h @@ -0,0 +1,57 @@ +/* Pango + * pangoatsui.h: + * + * Copyright (C) 2005 Imendio AB + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __PANGOCAIRO_ATSUI_H__ +#define __PANGOCAIRO_ATSUI_H__ + +#include "pangoatsui-private.h" +#include "pangocairo.h" +#include + +G_BEGIN_DECLS + +#define PANGO_TYPE_CAIRO_ATSUI_FONT_MAP (pango_cairo_atsui_font_map_get_type ()) +#define PANGO_CAIRO_ATSUI_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_CAIRO_ATSUI_FONT_MAP, PangoCairoATSUIFontMap)) +#define PANGO_IS_CAIRO_ATSUI_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_CAIRO_ATSUI_FONT_MAP)) + +typedef struct _PangoCairoATSUIFontMap PangoCairoATSUIFontMap; + +struct _PangoCairoATSUIFontMap +{ + PangoATSUIFontMap parent_instance; + + PangoRenderer *renderer; + + gdouble dpi; +}; + +GType pango_cairo_atsui_font_map_get_type (void); + +PangoATSUIFont * +_pango_cairo_atsui_font_new (PangoCairoATSUIFontMap *cafontmap, + PangoContext *context, + const char *postscript_name, + const PangoFontDescription *desc); + +G_END_DECLS + +#endif /* __PANGOCAIRO_ATSUI_H__ */ + diff --git a/pango/pangocairo-atsuifont.c b/pango/pangocairo-atsuifont.c new file mode 100644 index 00000000..02b0d88b --- /dev/null +++ b/pango/pangocairo-atsuifont.c @@ -0,0 +1,271 @@ +/* Pango + * pangocairo-atsuifont.c + * + * Copyright (C) 2000-2005 Red Hat Software + * Copyright (C) 2005 Imendio AB + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "pangoatsui-private.h" +#include "pangocairo.h" +#include "pangocairo-private.h" +#include "pangocairo-atsui.h" +#include "pangocairo-atsuifont.h" + +struct _PangoCairoATSUIFont +{ + PangoATSUIFont font; + + ATSUFontID font_id; + cairo_font_face_t *font_face; + cairo_scaled_font_t *scaled_font; + cairo_matrix_t font_matrix; + cairo_matrix_t ctm; + cairo_font_options_t *options; + + double size; +}; + +struct _PangoCairoATSUIFontClass +{ + PangoATSUIFontClass parent_class; +}; + + + +static cairo_font_face_t *pango_cairo_atsui_font_get_font_face (PangoCairoFont *font); + +ATSUFontID +pango_cairo_atsui_font_get_atsu_font_id (PangoCairoATSUIFont *cafont) +{ + return cafont->font_id; +} + +static void +pango_cairo_atsui_font_install (PangoCairoFont *font, + cairo_t *cr) +{ + PangoCairoATSUIFont *cwfont = PANGO_CAIRO_ATSUI_FONT (font); + + cairo_set_font_face (cr, + pango_cairo_atsui_font_get_font_face (font)); + + cairo_set_font_matrix (cr, &cwfont->font_matrix); + cairo_set_font_options (cr, cwfont->options); +} + +static void +cairo_font_iface_init (PangoCairoFontIface *iface) +{ + iface->install = pango_cairo_atsui_font_install; +} + +G_DEFINE_TYPE_WITH_CODE (PangoCairoATSUIFont, pango_cairo_atsui_font, PANGO_TYPE_ATSUI_FONT, + { G_IMPLEMENT_INTERFACE (PANGO_TYPE_CAIRO_FONT, cairo_font_iface_init) }); + +static cairo_font_face_t * +pango_cairo_atsui_font_get_font_face (PangoCairoFont *font) +{ + PangoCairoATSUIFont *cafont = PANGO_CAIRO_ATSUI_FONT (font); + + if (!cafont->font_face) + { + cafont->font_face = cairo_atsui_font_face_create_for_atsu_font_id (cafont->font_id); + } + + return cafont->font_face; +} + +static cairo_scaled_font_t * +pango_cairo_atsui_font_get_scaled_font (PangoCairoFont *font) +{ + PangoCairoATSUIFont *cafont = PANGO_CAIRO_ATSUI_FONT (font); + + if (!cafont->scaled_font) + { + cairo_font_face_t *font_face; + + font_face = pango_cairo_atsui_font_get_font_face (font); + cafont->scaled_font = cairo_scaled_font_create (font_face, + &cafont->font_matrix, + &cafont->ctm, + cafont->options); + + /* Failure of the above should only occur for out of memory, + * we can't proceed at that point + */ + if (!cafont->scaled_font) + g_error ("Unable create Cairo font"); + } + + return cafont->scaled_font; +} + +static void +pango_cairo_atsui_font_get_glyph_extents (PangoFont *font, + PangoGlyph glyph, + PangoRectangle *ink_rect, + PangoRectangle *logical_rect) +{ + cairo_scaled_font_t *scaled_font; + cairo_text_extents_t extents; + cairo_glyph_t cairo_glyph; + + scaled_font = pango_cairo_atsui_font_get_scaled_font (PANGO_CAIRO_FONT (font)); + + cairo_glyph.index = glyph; + cairo_glyph.x = 0; + cairo_glyph.y = 0; + + cairo_scaled_font_glyph_extents (scaled_font, + &cairo_glyph, 1, &extents); + + if (ink_rect) + { + ink_rect->x = extents.x_bearing * PANGO_SCALE; + ink_rect->y = extents.y_bearing * PANGO_SCALE; + ink_rect->width = extents.width * PANGO_SCALE; + ink_rect->height = extents.height * PANGO_SCALE; + } + + if (logical_rect) + { + cairo_font_extents_t font_extents; + + cairo_scaled_font_extents (scaled_font, &font_extents); + + logical_rect->x = 0; + logical_rect->y = - font_extents.ascent * PANGO_SCALE; + logical_rect->width = extents.x_advance * PANGO_SCALE; + logical_rect->height = (font_extents.ascent + font_extents.descent) * PANGO_SCALE; + } +} + + +static PangoFontMetrics * +pango_cairo_atsui_font_get_metrics (PangoFont *font, + PangoLanguage *language) +{ + PangoCairoATSUIFont *cafont = PANGO_CAIRO_ATSUI_FONT (font); + ATSFontRef ats_font; + ATSFontMetrics ats_metrics; + PangoFontMetrics *metrics; + + ats_font = FMGetATSFontRefFromFont(cafont->font_id); + + ATSFontGetHorizontalMetrics (ats_font, kATSOptionFlagsDefault, &ats_metrics); + + metrics = pango_font_metrics_new (); + + metrics->ascent = ats_metrics.ascent * cafont->size * PANGO_SCALE; + metrics->descent = -ats_metrics.descent * cafont->size * PANGO_SCALE; + + metrics->approximate_char_width = ats_metrics.avgAdvanceWidth * cafont->size * PANGO_SCALE; + metrics->approximate_digit_width = ats_metrics.avgAdvanceWidth * cafont->size * PANGO_SCALE; + + metrics->underline_position = ats_metrics.underlinePosition * cafont->size * PANGO_SCALE; + metrics->underline_thickness = ats_metrics.underlineThickness * cafont->size * PANGO_SCALE; + + metrics->strikethrough_position = metrics->ascent / 3; + metrics->strikethrough_thickness = ats_metrics.underlineThickness * cafont->size * PANGO_SCALE; + + return metrics; +} + +static void +pango_cairo_atsui_font_finalize (GObject *object) +{ + PangoCairoATSUIFont *cafont = PANGO_CAIRO_ATSUI_FONT (object); + + cairo_font_face_destroy (cafont->font_face); + cairo_scaled_font_destroy (cafont->scaled_font); + cairo_font_options_destroy (cafont->options); + + G_OBJECT_CLASS (pango_cairo_atsui_font_parent_class)->finalize (object); +} + +static void +pango_cairo_atsui_font_class_init (PangoCairoATSUIFontClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + PangoFontClass *font_class = PANGO_FONT_CLASS (class); + + object_class->finalize = pango_cairo_atsui_font_finalize; + + font_class->get_metrics = pango_cairo_atsui_font_get_metrics; + font_class->get_glyph_extents = pango_cairo_atsui_font_get_glyph_extents; +} + +static void +pango_cairo_atsui_font_init (PangoCairoATSUIFont *cafont) +{ +} + +PangoATSUIFont * +_pango_cairo_atsui_font_new (PangoCairoATSUIFontMap *cafontmap, + PangoContext *context, + const char *postscript_name, + const PangoFontDescription *desc) +{ + PangoCairoATSUIFont *cafont; + PangoATSUIFont *afont; + CFStringRef cfstr; + ATSFontRef font_ref; + const PangoMatrix *pango_ctm; + ATSUFontID font_id; + + cfstr = CFStringCreateWithCString (NULL, postscript_name, + kCFStringEncodingUTF8); + + font_ref = ATSFontFindFromPostScriptName (cfstr, kATSOptionFlagsDefault); + font_id = FMGetFontFromATSFontRef (font_ref); + + CFRelease (cfstr); + + if (!font_id) + return NULL; + + cafont = g_object_new (PANGO_TYPE_CAIRO_ATSUI_FONT, NULL); + afont = PANGO_ATSUI_FONT (cafont); + + afont->desc = pango_font_description_copy (desc); + afont->postscript_name = g_strdup (postscript_name); + + cafont->size = (double) pango_font_description_get_size (desc) / PANGO_SCALE; + cafont->font_id = font_id; + + if (!pango_font_description_get_size_is_absolute (desc)) + { + /* FIXME: Need to handle dpi here. See other font implementations for more info. */ + } + + cairo_matrix_init_scale (&cafont->font_matrix, cafont->size, cafont->size); + pango_ctm = pango_context_get_matrix (context); + if (pango_ctm) + cairo_matrix_init (&cafont->ctm, + pango_ctm->xx, + pango_ctm->yx, + pango_ctm->xy, + pango_ctm->yy, + 0., 0.); + else + cairo_matrix_init_identity (&cafont->ctm); + + cafont->options = cairo_font_options_copy (_pango_cairo_context_get_merged_font_options (context)); + + return afont; +} diff --git a/pango/pangocairo-atsuifont.h b/pango/pangocairo-atsuifont.h new file mode 100644 index 00000000..94bf92ab --- /dev/null +++ b/pango/pangocairo-atsuifont.h @@ -0,0 +1,38 @@ +/* Pango + * pangocairo-atsuifont.c + * + * Copyright (C) 2005 Imendio AB + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __PANGOCAIRO_ATSUIFONT_H__ +#define __PANGOCAIRO_ATSUIFONT_H__ + +#define PANGO_TYPE_CAIRO_ATSUI_FONT (pango_cairo_atsui_font_get_type ()) +#define PANGO_CAIRO_ATSUI_FONT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_CAIRO_ATSUI_FONT, PangoCairoATSUIFont)) +#define PANGO_CAIRO_ATSUI_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_CAIRO_ATSUI_FONT, PangoCairoATSUIFontClass)) +#define PANGO_CAIRO_IS_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_CAIRO_ATSUI_FONT)) +#define PANGO_CAIRO_ATSUI_FONT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_CAIRO_ATSUI_FONT, PangoCairoATSUIFontClass)) + +typedef struct _PangoCairoATSUIFont PangoCairoATSUIFont; +typedef struct _PangoCairoATSUIFontClass PangoCairoATSUIFontClass; + +GType pango_cairo_atsui_font_get_type (void); + +ATSUFontID pango_cairo_atsui_font_get_atsu_font_id (PangoCairoATSUIFont *cafont); + +#endif /* __PANGOCAIRO_ATSUIFONT_H__ */ diff --git a/pango/pangocairo-atsuifontmap.c b/pango/pangocairo-atsuifontmap.c new file mode 100644 index 00000000..80cacbbc --- /dev/null +++ b/pango/pangocairo-atsuifontmap.c @@ -0,0 +1,110 @@ +/* Pango + * pangocairo-atsuifontmap.c + * + * Copyright (C) 2005 Imendio AB + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "pangoatsui-private.h" +#include "pangocairo.h" +#include "pangocairo-private.h" +#include "pangocairo-atsui.h" + +typedef struct _PangoCairoATSUIFontMapClass PangoCairoATSUIFontMapClass; + +struct _PangoCairoATSUIFontMapClass +{ + PangoATSUIFontMapClass parent_class; +}; + +static PangoRenderer * +pango_cairo_atsui_font_map_get_renderer (PangoCairoFontMap *cfontmap) +{ + PangoCairoATSUIFontMap *cwfontmap = PANGO_CAIRO_ATSUI_FONT_MAP (cfontmap); + + if (!cwfontmap->renderer) + cwfontmap->renderer = g_object_new (PANGO_TYPE_CAIRO_RENDERER, NULL); + + return cwfontmap->renderer; +} + +static void +pango_cairo_atsui_font_map_set_resolution (PangoCairoFontMap *cfontmap, + double dpi) +{ + PangoCairoATSUIFontMap *cafontmap = PANGO_CAIRO_ATSUI_FONT_MAP (cfontmap); + + cafontmap->dpi = dpi; +} + +static double +pango_cairo_atsui_font_map_get_resolution (PangoCairoFontMap *cfontmap) +{ + PangoCairoATSUIFontMap *cafontmap = PANGO_CAIRO_ATSUI_FONT_MAP (cfontmap); + + return cafontmap->dpi; +} + +static void +cairo_font_map_iface_init (PangoCairoFontMapIface *iface) +{ + iface->set_resolution = pango_cairo_atsui_font_map_set_resolution; + iface->get_resolution = pango_cairo_atsui_font_map_get_resolution; + iface->get_renderer = pango_cairo_atsui_font_map_get_renderer; +} + +G_DEFINE_TYPE_WITH_CODE (PangoCairoATSUIFontMap, pango_cairo_atsui_font_map, PANGO_TYPE_ATSUI_FONT_MAP, + { G_IMPLEMENT_INTERFACE (PANGO_TYPE_CAIRO_FONT_MAP, cairo_font_map_iface_init) }); + + +static PangoATSUIFont * +pango_cairo_atsui_font_map_create_font (PangoATSUIFontMap *fontmap, + PangoContext *context, + const char *postscript_name, + const PangoFontDescription *desc) + +{ + return _pango_cairo_atsui_font_new (PANGO_CAIRO_ATSUI_FONT_MAP (fontmap), context, + postscript_name, desc); +} + +static void +pango_cairo_atsui_font_map_finalize (GObject *object) +{ + PangoCairoATSUIFontMap *cafontmap = PANGO_CAIRO_ATSUI_FONT_MAP (object); + + if (cafontmap->renderer) + g_object_unref (cafontmap->renderer); + + G_OBJECT_CLASS (pango_cairo_atsui_font_map_parent_class)->finalize (object); +} + +static void +pango_cairo_atsui_font_map_class_init (PangoCairoATSUIFontMapClass *class) +{ + PangoATSUIFontMapClass *atsuifontmapclass = (PangoATSUIFontMapClass *)class; + GObjectClass *object_class = (GObjectClass *)class; + + object_class->finalize = pango_cairo_atsui_font_map_finalize; + + atsuifontmapclass->create_font = pango_cairo_atsui_font_map_create_font; +} + +static void +pango_cairo_atsui_font_map_init (PangoCairoATSUIFontMap *cafontmap) +{ +} diff --git a/pango/pangocairo-fontmap.c b/pango/pangocairo-fontmap.c index 80a72b2f..501592d5 100644 --- a/pango/pangocairo-fontmap.c +++ b/pango/pangocairo-fontmap.c @@ -24,7 +24,9 @@ #include "pangocairo.h" #include "pangocairo-private.h" -#if defined (HAVE_CAIRO_FREETYPE) +#if defined (HAVE_CAIRO_ATSUI) +# include "pangocairo-atsui.h" +#elif defined (HAVE_CAIRO_FREETYPE) # include "pangocairo-fc.h" #elif defined (HAVE_CAIRO_WIN32) # include "pangocairo-win32.h" @@ -86,7 +88,9 @@ pango_cairo_font_map_new (void) /* Make sure that the type system is initialized */ g_type_init (); -#if defined(HAVE_CAIRO_WIN32) +#if defined(HAVE_CAIRO_ATSUI) + return g_object_new (PANGO_TYPE_CAIRO_ATSUI_FONT_MAP, NULL); +#elif defined(HAVE_CAIRO_WIN32) return g_object_new (PANGO_TYPE_CAIRO_WIN32_FONT_MAP, NULL); #elif defined(HAVE_CAIRO_FREETYPE) return g_object_new (PANGO_TYPE_CAIRO_FC_FONT_MAP, NULL); -- cgit v1.2.1