diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2011-06-17 15:42:16 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2011-06-17 15:42:16 -0400 |
commit | 0b469b7eeb36ce8181b404f24eaaacaa9ec2c3fe (patch) | |
tree | b89838087398df711b6b88337d67eac7eb02e7b8 /pango | |
parent | 7f9f7184286d584398603e449271d8bbd0e2e101 (diff) | |
parent | 26092c20b0936ff669513fbd64537123b99d036e (diff) | |
download | pango-0b469b7eeb36ce8181b404f24eaaacaa9ec2c3fe.tar.gz |
Merge branch 'master' into harfbuzz-ng-external
Conflicts:
configure.in
pango/opentype/hb-common.h
pango/pango-ot-info.c
Diffstat (limited to 'pango')
50 files changed, 2353 insertions, 629 deletions
diff --git a/pango/Makefile.am b/pango/Makefile.am index de866d2c..98835348 100644 --- a/pango/Makefile.am +++ b/pango/Makefile.am @@ -378,6 +378,26 @@ libpangocairo_1_0_la_SOURCES += \ endif if HAVE_CAIRO_ATSUI +if HAVE_CORE_TEXT +libpangocairo_1_0_la_SOURCES += \ + modules.h \ + module-defs-coretext.c \ + pangocoretext.h \ + pangocoretext.c \ + pangocoretext-private.h \ + pangocoretext-fontmap.c \ + pangocairo-coretext.h \ + pangocairo-coretextfont.c \ + pangocairo-coretextfont.h \ + pangocairo-coretextfontmap.c +pangoinclude_HEADERS += pangocoretext.h + +libpangocairo_1_0_la_LDFLAGS += -framework CoreFoundation -framework ApplicationServices +libpangocairo_1_0_la_LIBADD += $(INCLUDED_CORE_TEXT_MODULES) +# We don't have an CoreText GIR right now, so this is just hypothetical +PANGOCAIRO_FONT_BACKEND_GI_MODULE = PangoCoreText-1.0 + +else libpangocairo_1_0_la_SOURCES += \ modules.h \ module-defs-atsui.c \ @@ -397,6 +417,7 @@ libpangocairo_1_0_la_LIBADD += $(INCLUDED_ATSUI_MODULES) # We don't have an ATSUI GIR right now, so this is just hypothetical PANGOCAIRO_FONT_BACKEND_GI_MODULE = PangoATSUI-1.0 endif +endif pangocairo_introspection_files = \ $(libpangocairo_1_0_la_SOURCES) \ @@ -598,7 +619,8 @@ MODULE_DEF_FILES = \ module-defs-x.c \ module-defs-fc.c \ module-defs-win32.c \ - module-defs-atsui.c + module-defs-atsui.c \ + module-defs-coretext.c $(MODULE_DEF_FILES): $(top_builddir)/config.status $(AM_V_GEN) cd $(top_builddir) && $(SHELL) ./config.status pango/$@ diff --git a/pango/fonts.c b/pango/fonts.c index 34cd67c3..6d35f83e 100644 --- a/pango/fonts.c +++ b/pango/fonts.c @@ -155,7 +155,7 @@ pango_font_description_set_family_static (PangoFontDescription *desc, * %NULL if not previously set. This has the same life-time * as the font description itself and should not be freed. **/ -G_CONST_RETURN char * +const char * pango_font_description_get_family (const PangoFontDescription *desc) { g_return_val_if_fail (desc != NULL, NULL); @@ -509,7 +509,7 @@ pango_font_description_unset_fields (PangoFontDescription *desc, /** * pango_font_description_merge: * @desc: a #PangoFontDescription - * @desc_to_merge: the #PangoFontDescription to merge from, or %NULL + * @desc_to_merge: (allow-none): the #PangoFontDescription to merge from, or %NULL * @replace_existing: if %TRUE, replace fields in @desc with the * corresponding values from @desc_to_merge, even if they * are already exist. @@ -615,7 +615,7 @@ compute_distance (const PangoFontDescription *a, /** * pango_font_description_better_match: * @desc: a #PangoFontDescription - * @old_match: a #PangoFontDescription, or %NULL + * @old_match: (allow-none): a #PangoFontDescription, or %NULL * @new_match: a #PangoFontDescription * * Determines if the style attributes of @new_match are a closer match @@ -815,7 +815,8 @@ pango_font_description_free (PangoFontDescription *desc) /** * pango_font_descriptions_free: - * @descs: a pointer to an array of #PangoFontDescription, may be %NULL + * @descs: (allow-none) (array length=n_descs) (transfer full): a pointer + * to an array of #PangoFontDescription, may be %NULL * @n_descs: number of font descriptions in @descs * * Frees an array of font descriptions. @@ -1545,10 +1546,10 @@ pango_font_find_shaper (PangoFont *font, * pango_font_get_glyph_extents: * @font: a #PangoFont * @glyph: the glyph index - * @ink_rect: rectangle used to store the extents of the glyph as drawn - * or %NULL to indicate that the result is not needed. - * @logical_rect: rectangle used to store the logical extents of the glyph - * or %NULL to indicate that the result is not needed. + * @ink_rect: (out) (allow-none): rectangle used to store the extents of the glyph + * as drawn or %NULL to indicate that the result is not needed. + * @logical_rect: (out) (allow-none): rectangle used to store the logical extents of + * the glyph or %NULL to indicate that the result is not needed. * * Gets the logical and ink extents of a glyph within a font. The * coordinate system for each rectangle has its origin at the @@ -1592,9 +1593,8 @@ pango_font_get_glyph_extents (PangoFont *font, /** * pango_font_get_metrics: * @font: a #PangoFont - * @language: language tag used to determine which script to get the metrics - * for, or %NULL to indicate to get the metrics for the entire - * font. + * @language: (allow-none): language tag used to determine which script to get the metrics + * for, or %NULL to indicate to get the metrics for the entire font. * * Gets overall metric information for a font. Since the metrics may be * substantially different for different scripts, a language tag can @@ -1644,7 +1644,8 @@ pango_font_get_metrics (PangoFont *font, * alive. In most uses this is not an issue as a #PangoContext holds * a reference to the font map. * - * Return value: the #PangoFontMap for the font, or %NULL if @font is %NULL. + * Return value: (transfer none): the #PangoFontMap for the font, or %NULL + * if @font is %NULL. * * Since: 1.10 **/ @@ -1907,7 +1908,7 @@ pango_font_family_init (PangoFontFamily *family G_GNUC_UNUSED) * Return value: the name of the family. This string is owned * by the family object and must not be modified or freed. **/ -G_CONST_RETURN char * +const char * pango_font_family_get_name (PangoFontFamily *family) { g_return_val_if_fail (PANGO_IS_FONT_FAMILY (family), NULL); @@ -1918,10 +1919,10 @@ pango_font_family_get_name (PangoFontFamily *family) /** * pango_font_family_list_faces: * @family: a #PangoFontFamily - * @faces: location to store an array of pointers to #PangoFontFace + * @faces: (out) (allow-none) (array length=n_faces): location to store an array of pointers to #PangoFontFace * objects, or %NULL. This array should be freed with g_free() * when it is no longer needed. - * @n_faces: location to store number of elements in @faces. + * @n_faces: (out): location to store number of elements in @faces. * * Lists the different font faces that make up @family. The faces * in a family share a common design, but differ in slant, weight, @@ -2040,7 +2041,7 @@ pango_font_face_is_synthesized (PangoFontFace *face) * Return value: the face name for the face. This string is * owned by the face object and must not be modified or freed. **/ -G_CONST_RETURN char * +const char * pango_font_face_get_face_name (PangoFontFace *face) { g_return_val_if_fail (PANGO_IS_FONT_FACE (face), NULL); diff --git a/pango/glyphstring.c b/pango/glyphstring.c index e407bd6a..58a30043 100644 --- a/pango/glyphstring.c +++ b/pango/glyphstring.c @@ -261,10 +261,10 @@ pango_glyph_string_extents_range (PangoGlyphString *glyphs, * pango_glyph_string_extents: * @glyphs: a #PangoGlyphString * @font: a #PangoFont - * @ink_rect: rectangle used to store the extents of the glyph string as drawn - * or %NULL to indicate that the result is not needed. - * @logical_rect: rectangle used to store the logical extents of the glyph string - * or %NULL to indicate that the result is not needed. + * @ink_rect: (out) (allow-none): rectangle used to store the extents of the glyph string + * as drawn or %NULL to indicate that the result is not needed. + * @logical_rect: (out) (allow-none): rectangle used to store the logical extents of the + * glyph string or %NULL to indicate that the result is not needed. * * Compute the logical and ink extents of a glyph string. See the documentation * for pango_font_get_glyph_extents() for details about the interpretation diff --git a/pango/modules.c b/pango/modules.c index dad8aae7..5ef2f315 100644 --- a/pango/modules.c +++ b/pango/modules.c @@ -93,8 +93,6 @@ static GSList *registered_engines = NULL; static GSList *dlloaded_engines = NULL; static GHashTable *dlloaded_modules; -static GObjectClass *parent_class; - static void build_map (PangoMapInfo *info); static void init_modules (void); @@ -178,6 +176,8 @@ pango_find_map (PangoLanguage *language, return map_info->map; } +G_DEFINE_TYPE (PangoModule, pango_module, G_TYPE_TYPE_MODULE); + static gboolean pango_module_load (GTypeModule *module) { @@ -258,7 +258,12 @@ pango_module_finalize (GObject *object) g_free (module->path); - parent_class->finalize (object); + G_OBJECT_CLASS (pango_module_parent_class)->finalize (object); +} + +static void +pango_module_init (PangoModule *self) +{ } static void @@ -267,17 +272,12 @@ pango_module_class_init (PangoModuleClass *class) GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class); GObjectClass *gobject_class = G_OBJECT_CLASS (class); - parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (class)); - module_class->load = pango_module_load; module_class->unload = pango_module_unload; gobject_class->finalize = pango_module_finalize; } -static PANGO_DEFINE_TYPE (PangoModule, pango_module, - pango_module_class_init, NULL, - G_TYPE_TYPE_MODULE) static PangoEngine * pango_engine_pair_get_engine (PangoEnginePair *pair) diff --git a/pango/modules.h b/pango/modules.h index ca22701b..7eac8fb6 100644 --- a/pango/modules.h +++ b/pango/modules.h @@ -30,5 +30,6 @@ extern PangoIncludedModule _pango_included_x_modules[]; extern PangoIncludedModule _pango_included_fc_modules[]; extern PangoIncludedModule _pango_included_win32_modules[]; extern PangoIncludedModule _pango_included_atsui_modules[]; +extern PangoIncludedModule _pango_included_core_text_modules[]; #endif /* __MODULES_H__ */ diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index a253a67c..4b9d5071 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -97,7 +97,7 @@ pango_attr_type_register (const gchar *name) * * Since: 1.22 **/ -G_CONST_RETURN char * +const char * pango_attr_type_get_name (PangoAttrType type) { const char *result = NULL; @@ -960,11 +960,11 @@ pango_attr_shape_equal (const PangoAttribute *attr1, * @ink_rect: ink rectangle to assign to each character * @logical_rect: logical rectangle to assign to each character * @data: user data pointer - * @copy_func: function to copy @data when the attribute - * is copied. If %NULL, @data is simply copied - * as a pointer. - * @destroy_func: function to free @data when the attribute - * is freed, or %NULL + * @copy_func: (allow-none): function to copy @data when the + * attribute is copied. If %NULL, @data is simply + * copied as a pointer. + * @destroy_func: (allow-none): function to free @data when the + * attribute is freed, or %NULL * * Like pango_attr_shape_new(), but a user data pointer is also * provided; this pointer can be accessed when later @@ -1782,9 +1782,9 @@ pango_attr_iterator_get (PangoAttrIterator *iterator, * an attribute in the #PangoAttrList associated with the iterator, * so if you plan to keep it around, you must call: * <literal>pango_font_description_set_family (desc, pango_font_description_get_family (desc))</literal>. - * @language: if non-%NULL, location to store language tag for item, or %NULL + * @language: (allow-none): if non-%NULL, location to store language tag for item, or %NULL * if none is found. - * @extra_attrs: (element type Pango.Attribute) (transfer full): if non-%NULL, + * @extra_attrs: (allow-none) (element-type Pango.Attribute) (transfer full): if non-%NULL, * location in which to store a list of non-font * attributes at the the current position; only the highest priority * value of each attribute will be added to this list. In order @@ -1931,15 +1931,15 @@ pango_attr_iterator_get_font (PangoAttrIterator *iterator, /** * pango_attr_list_filter: * @list: a #PangoAttrList - * @func: callback function; returns %TRUE if an attribute - * should be filtered out. - * @data: Data to be passed to @func + * @func: (scope call) (closure data): callback function; returns %TRUE + * if an attribute should be filtered out. + * @data: (closure): Data to be passed to @func * * Given a #PangoAttrList and callback function, removes any elements * of @list for which @func returns %TRUE and inserts them into * a new list. * - * Return value: the new #PangoAttrList or %NULL if + * Return value: (transfer full): the new #PangoAttrList or %NULL if * no attributes of the given types were found. * * Since: 1.2 diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h index 866e35dd..59f97a3a 100644 --- a/pango/pango-attributes.h +++ b/pango/pango-attributes.h @@ -180,7 +180,7 @@ struct _PangoAttrFontDesc }; PangoAttrType pango_attr_type_register (const gchar *name); -G_CONST_RETURN char * pango_attr_type_get_name (PangoAttrType type) G_GNUC_CONST; +const char * pango_attr_type_get_name (PangoAttrType type) G_GNUC_CONST; void pango_attribute_init (PangoAttribute *attr, const PangoAttrClass *klass); diff --git a/pango/pango-context.c b/pango/pango-context.c index 6ec0b56f..110a6f36 100644 --- a/pango/pango-context.c +++ b/pango/pango-context.c @@ -146,8 +146,8 @@ update_resolved_gravity (PangoContext *context) /** * pango_context_set_matrix: * @context: a #PangoContext - * @matrix: a #PangoMatrix, or %NULL to unset any existing matrix. - * (No matrix set is the same as setting the identity matrix.) + * @matrix: (allow-none): a #PangoMatrix, or %NULL to unset any existing + * matrix. (No matrix set is the same as setting the identity matrix.) * * Sets the transformation matrix that will be applied when rendering * with this context. Note that reported metrics are in the user space @@ -188,7 +188,7 @@ pango_context_set_matrix (PangoContext *context, * * Since: 1.6 **/ -G_CONST_RETURN PangoMatrix * +const PangoMatrix * pango_context_get_matrix (PangoContext *context) { g_return_val_if_fail (PANGO_IS_CONTEXT (context), NULL); @@ -227,8 +227,8 @@ pango_context_set_font_map (PangoContext *context, * * Gets the #PangoFontmap used to look up fonts for this context. * - * Return value: the font map for the #PangoContext. This value - * is owned by Pango and should not be unreferenced. + * Return value: (transfer none): the font map for the #PangoContext. + * This value is owned by Pango and should not be unreferenced. * * Since: 1.6 **/ @@ -243,9 +243,10 @@ pango_context_get_font_map (PangoContext *context) /** * pango_context_list_families: * @context: a #PangoContext - * @families: location to store a pointer to an array of #PangoFontFamily *. - * This array should be freed with g_free(). - * @n_families: location to store the number of elements in @descs + * @families: (out) (array length=n_families): location to store a pointer to + * an array of #PangoFontFamily *. This array should be freed + * with g_free(). + * @n_families: (out): location to store the number of elements in @descs * * List all families for a context. **/ @@ -280,7 +281,8 @@ pango_context_list_families (PangoContext *context, * Loads the font in one of the fontmaps in the context * that is the closest match for @desc. * - * Returns: the font loaded, or %NULL if no font matched. + * Returns: (transfer full): the newly allocated #PangoFont that + * was loaded, or %NULL if no font matched. **/ PangoFont * pango_context_load_font (PangoContext *context, @@ -300,7 +302,8 @@ pango_context_load_font (PangoContext *context, * Load a set of fonts in the context that can be used to render * a font matching @desc. * - * Returns: the fontset, or %NULL if no font matched. + * Returns: (transfer full): the newly allocated #PangoFontset loaded, + * or %NULL if no font matched. **/ PangoFontset * pango_context_load_fontset (PangoContext *context, @@ -1481,23 +1484,23 @@ itemize_state_finish (ItemizeState *state) /** * pango_itemize_with_base_dir: * @context: a structure holding information that affects - the itemization process. + * the itemization process. + * @base_dir: base direction to use for bidirectional processing * @text: the text to itemize. * @start_index: first byte in @text to process * @length: the number of bytes (not characters) to process - * after @start_index. - * This must be >= 0. - * @base_dir: base direction to use for bidirectional processing + * after @start_index. This must be >= 0. * @attrs: the set of attributes that apply to @text. - * @cached_iter: Cached attribute iterator, or %NULL + * @cached_iter: (allow-none): Cached attribute iterator, or %NULL * * Like pango_itemize(), but the base direction to use when * computing bidirectional levels (see pango_context_set_base_dir ()), * is specified explicitly rather than gotten from the #PangoContext. * - * Return value: a #GList of #PangoItem structures. The items should be - * freed using pango_item_free() probably in combination with g_list_foreach(), - * and the list itself using g_list_free(). + * Return value: (transfer full) (element-type Pango.Item): a #GList of + * #PangoItem structures. The items should be freed using + * pango_item_free() probably in combination with + * g_list_foreach(), and the list itself using g_list_free(). * * Since: 1.4 */ @@ -1566,7 +1569,7 @@ itemize_with_font (PangoContext *context, * after @start_index. * This must be >= 0. * @attrs: the set of attributes that apply to @text. - * @cached_iter: Cached attribute iterator, or %NULL + * @cached_iter: (allow-none): Cached attribute iterator, or %NULL * * Breaks a piece of text into segments with consistent * directional level and shaping engine. Each byte of @text will @@ -1579,7 +1582,10 @@ itemize_with_font (PangoContext *context, * the range covering the position just after @start_index + @length. * (i.e. if itemizing in a loop, just keep passing in the same @cached_iter). * - * Return value: a #GList of #PangoItem structures. + * Return value: (transfer full) (element-type Pango.Item): a #GList of #PangoItem + * structures. The items should be freed using pango_item_free() + * probably in combination with g_list_foreach(), and the list itself + * using g_list_free(). */ GList * pango_itemize (PangoContext *context, @@ -1674,13 +1680,13 @@ update_metrics_from_items (PangoFontMetrics *metrics, /** * pango_context_get_metrics: * @context: a #PangoContext - * @desc: a #PangoFontDescription structure. %NULL means that the font - * description from the context will be used. - * @language: language tag used to determine which script to get the metrics - * for. %NULL means that the language tag from the context will - * be used. If no language tag is set on the context, metrics - * for the default language (as determined by - * pango_language_get_default()) will be returned. + * @desc: (allow-none): a #PangoFontDescription structure. %NULL means that the + * font description from the context will be used. + * @language: (allow-none): language tag used to determine which script to get + * the metrics for. %NULL means that the language tag from the context + * will be used. If no language tag is set on the context, metrics + * for the default language (as determined by pango_language_get_default()) + * will be returned. * * Get overall metric information for a particular font * description. Since the metrics may be substantially different for diff --git a/pango/pango-context.h b/pango/pango-context.h index d8c3cb86..d85928a5 100644 --- a/pango/pango-context.h +++ b/pango/pango-context.h @@ -84,9 +84,9 @@ void pango_context_set_gravity_hint (PangoContext PangoGravityHint hint); PangoGravityHint pango_context_get_gravity_hint (PangoContext *context); -void pango_context_set_matrix (PangoContext *context, - const PangoMatrix *matrix); -G_CONST_RETURN PangoMatrix *pango_context_get_matrix (PangoContext *context); +void pango_context_set_matrix (PangoContext *context, + const PangoMatrix *matrix); +const PangoMatrix * pango_context_get_matrix (PangoContext *context); /* Break a string of Unicode characters into segments with * consistent shaping/language engine and bidrectional level. diff --git a/pango/pango-engine.c b/pango/pango-engine.c index 50ba7f40..1a49385b 100644 --- a/pango/pango-engine.c +++ b/pango/pango-engine.c @@ -25,13 +25,32 @@ #include "pango-engine-private.h" #include "pango-impl-utils.h" -PANGO_DEFINE_TYPE_ABSTRACT (PangoEngine, pango_engine, - NULL, NULL, - G_TYPE_OBJECT) -PANGO_DEFINE_TYPE_ABSTRACT (PangoEngineLang, pango_engine_lang, - NULL, NULL, - PANGO_TYPE_ENGINE) +G_DEFINE_ABSTRACT_TYPE (PangoEngine, pango_engine, G_TYPE_OBJECT); + +static void +pango_engine_init (PangoEngine *self) +{ +} + +static void +pango_engine_class_init (PangoEngineClass *klass) +{ +} + + +G_DEFINE_ABSTRACT_TYPE (PangoEngineLang, pango_engine_lang, PANGO_TYPE_ENGINE); + +static void +pango_engine_lang_init (PangoEngineLang *self) +{ +} + +static void +pango_engine_lang_class_init (PangoEngineLangClass *klass) +{ +} + static PangoCoverageLevel pango_engine_shape_real_covers (PangoEngineShape *engine G_GNUC_UNUSED, @@ -48,16 +67,20 @@ pango_engine_shape_real_covers (PangoEngineShape *engine G_GNUC_UNUSED, return result; } + +G_DEFINE_ABSTRACT_TYPE (PangoEngineShape, pango_engine_shape, PANGO_TYPE_ENGINE); + +static void +pango_engine_shape_init (PangoEngineShape *klass) +{ +} + static void pango_engine_shape_class_init (PangoEngineShapeClass *class) { class->covers = pango_engine_shape_real_covers; } -PANGO_DEFINE_TYPE_ABSTRACT (PangoEngineShape, pango_engine_shape, - pango_engine_shape_class_init, NULL, - PANGO_TYPE_ENGINE) - void _pango_engine_shape_shape (PangoEngineShape *engine, PangoFont *font, @@ -154,17 +177,23 @@ fallback_engine_covers (PangoEngineShape *engine G_GNUC_UNUSED, return PANGO_COVERAGE_NONE; } + +static GType pango_fallback_engine_get_type (void); + +G_DEFINE_ABSTRACT_TYPE (PangoFallbackEngine, pango_fallback_engine, PANGO_TYPE_ENGINE_SHAPE); + +static void +pango_fallback_engine_init (PangoFallbackEngine *self) +{ +} + static void -fallback_engine_class_init (PangoEngineShapeClass *class) +pango_fallback_engine_class_init (PangoFallbackEngineClass *class) { class->covers = fallback_engine_covers; class->script_shape = fallback_engine_shape; } -static PANGO_DEFINE_TYPE (PangoFallbackEngine, pango_fallback_engine, - fallback_engine_class_init, NULL, - PANGO_TYPE_ENGINE_SHAPE) - PangoEngineShape * _pango_get_fallback_shaper (void) { diff --git a/pango/pango-font.h b/pango/pango-font.h index b5b2cf14..eea27b4e 100644 --- a/pango/pango-font.h +++ b/pango/pango-font.h @@ -117,7 +117,7 @@ void pango_font_description_set_family (PangoFontDescript const char *family); void pango_font_description_set_family_static (PangoFontDescription *desc, const char *family); -G_CONST_RETURN char *pango_font_description_get_family (const PangoFontDescription *desc) G_GNUC_PURE; +const char *pango_font_description_get_family (const PangoFontDescription *desc) G_GNUC_PURE; void pango_font_description_set_style (PangoFontDescription *desc, PangoStyle style); PangoStyle pango_font_description_get_style (const PangoFontDescription *desc) G_GNUC_PURE; @@ -212,7 +212,7 @@ GType pango_font_family_get_type (void) G_GNUC_CONST; void pango_font_family_list_faces (PangoFontFamily *family, PangoFontFace ***faces, int *n_faces); -G_CONST_RETURN char *pango_font_family_get_name (PangoFontFamily *family) G_GNUC_PURE; +const char *pango_font_family_get_name (PangoFontFamily *family) G_GNUC_PURE; gboolean pango_font_family_is_monospace (PangoFontFamily *family) G_GNUC_PURE; #ifdef PANGO_ENABLE_BACKEND @@ -261,7 +261,7 @@ struct _PangoFontFamilyClass GType pango_font_face_get_type (void) G_GNUC_CONST; PangoFontDescription *pango_font_face_describe (PangoFontFace *face); -G_CONST_RETURN char *pango_font_face_get_face_name (PangoFontFace *face) G_GNUC_PURE; +const char *pango_font_face_get_face_name (PangoFontFace *face) G_GNUC_PURE; void pango_font_face_list_sizes (PangoFontFace *face, int **sizes, int *n_sizes); diff --git a/pango/pango-fontmap.c b/pango/pango-fontmap.c index 13f4263c..ea6bb574 100644 --- a/pango/pango-fontmap.c +++ b/pango/pango-fontmap.c @@ -56,8 +56,8 @@ pango_font_map_init (PangoFontMap *fontmap G_GNUC_UNUSED) * gdk_pango_context_get_for_screen(), and * gtk_widget_get_pango_context(). Use those instead. * - * Return value: the newly allocated #PangoContext, which should - * be freed with g_object_unref(). + * Return value: (transfer full): the newly allocated #PangoContext, + * which should be freed with g_object_unref(). * * Since: 1.22 **/ @@ -82,7 +82,8 @@ pango_font_map_create_context (PangoFontMap *fontmap) * * Load the font in the fontmap that is the closest match for @desc. * - * Returns: the font loaded, or %NULL if no font matched. + * Returns: (transfer full): the newly allocated #PangoFont loaded, + * or %NULL if no font matched. **/ PangoFont * pango_font_map_load_font (PangoFontMap *fontmap, @@ -97,9 +98,9 @@ pango_font_map_load_font (PangoFontMap *fontmap, /** * pango_font_map_list_families: * @fontmap: a #PangoFontMap - * @families: location to store a pointer to an array of #PangoFontFamily *. + * @families: (out) (array length=n_families): location to store a pointer to an array of #PangoFontFamily *. * This array should be freed with g_free(). - * @n_families: location to store the number of elements in @families + * @n_families: (out): location to store the number of elements in @families * * List all families for a fontmap. **/ @@ -123,7 +124,8 @@ pango_font_map_list_families (PangoFontMap *fontmap, * Load a set of fonts in the fontmap that can be used to render * a font matching @desc. * - * Returns: the fontset, or %NULL if no font matched. + * Returns: (transfer full): the newly allocated #PangoFontset + * loaded, or %NULL if no font matched. **/ PangoFontset * pango_font_map_load_fontset (PangoFontMap *fontmap, @@ -290,7 +292,7 @@ pango_font_map_real_load_fontset (PangoFontMap *fontmap, * * Since: 1.4 **/ -G_CONST_RETURN char * +const char * pango_font_map_get_shape_engine_type (PangoFontMap *fontmap) { g_return_val_if_fail (PANGO_IS_FONT_MAP (fontmap), NULL); diff --git a/pango/pango-fontset.c b/pango/pango-fontset.c index ce1eb33d..7c382b34 100644 --- a/pango/pango-fontset.c +++ b/pango/pango-fontset.c @@ -32,14 +32,20 @@ static PangoFontMetrics *pango_fontset_real_get_metrics (PangoFontset *fontset); + +G_DEFINE_ABSTRACT_TYPE (PangoFontset, pango_fontset, G_TYPE_OBJECT); + +static void +pango_fontset_init (PangoFontset *self) +{ +} + static void pango_fontset_class_init (PangoFontsetClass *class) { class->get_metrics = pango_fontset_real_get_metrics; } -PANGO_DEFINE_TYPE_ABSTRACT (PangoFontset, pango_fontset, - pango_fontset_class_init, NULL, G_TYPE_OBJECT) /** * pango_fontset_get_font: @@ -49,8 +55,8 @@ PANGO_DEFINE_TYPE_ABSTRACT (PangoFontset, pango_fontset, * Returns the font in the fontset that contains the best glyph for the * Unicode character @wc. * - * Return value: a #PangoFont. The caller must call g_object_unref when finished - * with the font. + * Return value: (transfer full): a #PangoFont. The caller must call + * g_object_unref when finished with the font. **/ PangoFont * pango_fontset_get_font (PangoFontset *fontset, @@ -82,8 +88,8 @@ pango_fontset_get_metrics (PangoFontset *fontset) /** * pango_fontset_foreach: * @fontset: a #PangoFontset - * @func: Callback function - * @data: data to pass to the callback function + * @func: (closure data) (scope call): Callback function + * @data: (closure): data to pass to the callback function * * Iterates through all the fonts in a fontset, calling @func for * each one. If @func returns %TRUE, that stops the iteration. @@ -202,7 +208,6 @@ pango_fontset_real_get_metrics (PangoFontset *fontset) #define PANGO_FONTSET_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_FONTSET_SIMPLE, PangoFontsetSimpleClass)) static void pango_fontset_simple_finalize (GObject *object); -static void pango_fontset_simple_init (PangoFontsetSimple *fontset); static PangoFontMetrics *pango_fontset_simple_get_metrics (PangoFontset *fontset); static PangoLanguage * pango_fontset_simple_get_language (PangoFontset *fontset); static PangoFont * pango_fontset_simple_get_font (PangoFontset *fontset, @@ -225,8 +230,6 @@ struct _PangoFontsetSimpleClass PangoFontsetClass parent_class; }; -static PangoFontsetClass *simple_parent_class; /* Parent class structure for PangoFontsetSimple */ - /** * pango_fontset_simple_new: * @language: a #PangoLanguage tag @@ -247,15 +250,17 @@ pango_fontset_simple_new (PangoLanguage *language) return fontset; } + +G_DEFINE_TYPE (PangoFontsetSimple, pango_fontset_simple, PANGO_TYPE_FONTSET); + static void pango_fontset_simple_class_init (PangoFontsetSimpleClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); PangoFontsetClass *fontset_class = PANGO_FONTSET_CLASS (class); - simple_parent_class = g_type_class_peek_parent (class); - object_class->finalize = pango_fontset_simple_finalize; + fontset_class->get_font = pango_fontset_simple_get_font; fontset_class->get_metrics = pango_fontset_simple_get_metrics; fontset_class->get_language = pango_fontset_simple_get_language; @@ -270,10 +275,6 @@ pango_fontset_simple_init (PangoFontsetSimple *fontset) fontset->language = NULL; } -PANGO_DEFINE_TYPE (PangoFontsetSimple, pango_fontset_simple, - pango_fontset_simple_class_init, pango_fontset_simple_init, - PANGO_TYPE_FONTSET) - static void pango_fontset_simple_finalize (GObject *object) { @@ -295,7 +296,7 @@ pango_fontset_simple_finalize (GObject *object) g_ptr_array_free (fontset->coverages, TRUE); - G_OBJECT_CLASS (simple_parent_class)->finalize (object); + G_OBJECT_CLASS (pango_fontset_simple_parent_class)->finalize (object); } /** @@ -344,7 +345,7 @@ pango_fontset_simple_get_metrics (PangoFontset *fontset) return pango_font_get_metrics (PANGO_FONT (g_ptr_array_index(simple->fonts, 0)), simple->language); - return PANGO_FONTSET_CLASS (simple_parent_class)->get_metrics (fontset); + return PANGO_FONTSET_CLASS (pango_fontset_simple_parent_class)->get_metrics (fontset); } static PangoFont * diff --git a/pango/pango-glyph-item.c b/pango/pango-glyph-item.c index 49d4b07d..26c3666f 100644 --- a/pango/pango-glyph-item.c +++ b/pango/pango-glyph-item.c @@ -564,9 +564,9 @@ split_before_cluster_start (ApplyAttrsState *state) * This function takes ownership of @glyph_item; it will be reused * as one of the elements in the list. * - * Return value: a list of glyph items resulting from splitting - * @glyph_item. Free the elements using pango_glyph_item_free(), - * the list using g_slist_free(). + * Return value: (transfer full): a list of glyph items resulting + * from splitting @glyph_item. Free the elements using + * pango_glyph_item_free(), the list using g_slist_free(). * * Since: 1.2 **/ diff --git a/pango/pango-impl-utils.h b/pango/pango-impl-utils.h index 6d6c8ff2..da3ef1cb 100644 --- a/pango/pango-impl-utils.h +++ b/pango/pango-impl-utils.h @@ -29,52 +29,6 @@ G_BEGIN_DECLS -#define PANGO_DEFINE_TYPE_FULL(name, prefix, \ - class_init, instance_init, \ - parent_type, abstract) \ -GType \ -prefix ## _get_type (void) \ -{ \ - static GType object_type = 0; \ - \ - if (!object_type) \ - { \ - static const GTypeInfo object_info = \ - { \ - sizeof (name ## Class), \ - (GBaseInitFunc) NULL, \ - (GBaseFinalizeFunc) NULL, \ - (GClassInitFunc) class_init, \ - (GClassFinalizeFunc) NULL, \ - NULL, /* class_data */ \ - sizeof (name), \ - 0, /* n_prelocs */ \ - (GInstanceInitFunc) instance_init, \ - NULL /* value_table */ \ - }; \ - \ - object_type = g_type_register_static (parent_type, \ - g_intern_static_string (# name), \ - &object_info, abstract); \ - } \ - \ - return object_type; \ -} - -#define PANGO_DEFINE_TYPE(name, prefix, \ - class_init, instance_init, \ - parent_type) \ - PANGO_DEFINE_TYPE_FULL (name, prefix, \ - class_init, instance_init, \ - parent_type, 0) - -#define PANGO_DEFINE_TYPE_ABSTRACT(name, prefix, \ - class_init, instance_init, \ - parent_type) \ - PANGO_DEFINE_TYPE_FULL (name, prefix, \ - class_init, instance_init, \ - parent_type, G_TYPE_FLAG_ABSTRACT) - /* String interning for static strings */ #define I_(string) g_intern_static_string (string) diff --git a/pango/pango-language.c b/pango/pango-language.c index a1675886..5b8583e9 100644 --- a/pango/pango-language.c +++ b/pango/pango-language.c @@ -245,7 +245,7 @@ pango_language_get_default (void) /** * pango_language_from_string: - * @language: a string representing a language tag, or %NULL + * @language: (allow-none): a string representing a language tag, or %NULL * * Take a RFC-3066 format language tag as a string and convert it to a * #PangoLanguage pointer that can be efficiently copied (copy the @@ -311,7 +311,7 @@ pango_language_from_string (const char *language) * Returns: a string representing the language tag. This is owned by * Pango and should not be freed. */ -G_CONST_RETURN char * +const char * (pango_language_to_string) (PangoLanguage *language) { return pango_language_to_string (language); @@ -523,7 +523,7 @@ static const LangInfo lang_texts[] = { * Return value: the sample string. This value is owned by Pango * and should not be freed. **/ -G_CONST_RETURN char * +const char * pango_language_get_sample_string (PangoLanguage *language) { const LangInfo *lang_info; @@ -553,8 +553,9 @@ pango_language_get_sample_string (PangoLanguage *language) /** * pango_language_get_scripts: - * @language: a #PangoLanguage, or %NULL - * @num_scripts: location to return number of scripts, or %NULL + * @language: (allow-none): a #PangoLanguage, or %NULL + * @num_scripts: (out caller-allocates) (allow-none): location to return number of scripts, + * or %NULL * * Determines the scripts used to to write @language. * If nothing is known about the language tag @language, @@ -584,7 +585,7 @@ pango_language_get_sample_string (PangoLanguage *language) * Since: 1.22 **/ -G_CONST_RETURN PangoScript * +const PangoScript * pango_language_get_scripts (PangoLanguage *language, int *num_scripts) { diff --git a/pango/pango-language.h b/pango/pango-language.h index 37cdc164..31660ca3 100644 --- a/pango/pango-language.h +++ b/pango/pango-language.h @@ -34,11 +34,11 @@ typedef struct _PangoLanguage PangoLanguage; GType pango_language_get_type (void) G_GNUC_CONST; PangoLanguage *pango_language_from_string (const char *language); -G_CONST_RETURN char *pango_language_to_string (PangoLanguage *language) G_GNUC_CONST; +const char *pango_language_to_string (PangoLanguage *language) G_GNUC_CONST; /* For back compat. Will have to keep indefinitely. */ #define pango_language_to_string(language) ((const char *)language) -G_CONST_RETURN char *pango_language_get_sample_string (PangoLanguage *language) G_GNUC_CONST; +const char *pango_language_get_sample_string (PangoLanguage *language) G_GNUC_CONST; PangoLanguage *pango_language_get_default (void) G_GNUC_CONST; gboolean pango_language_matches (PangoLanguage *language, @@ -48,7 +48,7 @@ gboolean pango_language_matches (PangoLanguage *language, gboolean pango_language_includes_script (PangoLanguage *language, PangoScript script) G_GNUC_PURE; -G_CONST_RETURN PangoScript *pango_language_get_scripts (PangoLanguage *language, +const PangoScript *pango_language_get_scripts (PangoLanguage *language, int *num_scripts); G_END_DECLS diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 02fdf193..40f92fae 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -282,9 +282,9 @@ pango_layout_new (PangoContext *context) * tab array, and text from the original layout are all copied by * value. * - * Return value: the newly allocated #PangoLayout, with a reference - * count of one, which should be freed with - * g_object_unref(). + * Return value: (transfer full): the newly allocated #PangoLayout, + * with a reference count of one, which should be freed + * with g_object_unref(). **/ PangoLayout* pango_layout_copy (PangoLayout *src) @@ -591,7 +591,7 @@ pango_layout_get_spacing (PangoLayout *layout) /** * pango_layout_set_attributes: * @layout: a #PangoLayout - * @attrs: a #PangoAttrList, can be %NULL + * @attrs: (allow-none) (transfer full): a #PangoAttrList, can be %NULL * * Sets the text attributes for a layout object. * References @attrs, so the caller can unref its reference. @@ -638,7 +638,7 @@ pango_layout_get_attributes (PangoLayout *layout) /** * pango_layout_set_font_description: * @layout: a #PangoLayout - * @desc: the new #PangoFontDescription, or %NULL to unset the + * @desc: (allow-none): the new #PangoFontDescription, or %NULL to unset the * current font description * * Sets the default font description for the layout. If no font @@ -677,7 +677,7 @@ pango_layout_set_font_description (PangoLayout *layout, * * Since: 1.8 **/ -G_CONST_RETURN PangoFontDescription * +const PangoFontDescription * pango_layout_get_font_description (PangoLayout *layout) { g_return_val_if_fail (PANGO_IS_LAYOUT (layout), NULL); @@ -832,7 +832,7 @@ pango_layout_get_alignment (PangoLayout *layout) /** * pango_layout_set_tabs: * @layout: a #PangoLayout - * @tabs: a #PangoTabArray, or %NULL + * @tabs: (allow-none): a #PangoTabArray, or %NULL * * Sets the tabs to use for @layout, overriding the default tabs * (by default, tabs are every 8 spaces). If @tabs is %NULL, the default @@ -1087,7 +1087,7 @@ pango_layout_set_text (PangoLayout *layout, * * Return value: the text in the @layout. **/ -G_CONST_RETURN char* +const char* pango_layout_get_text (PangoLayout *layout) { g_return_val_if_fail (PANGO_IS_LAYOUT (layout), NULL); @@ -1096,11 +1096,31 @@ pango_layout_get_text (PangoLayout *layout) } /** + * pango_layout_get_character_count: + * @layout: a #PangoLayout + * + * Returns the number of Unicode characters in the + * the text of @layout. + * + * Return value: the number of Unicode characters + * in the text of @layout + * + * Since: 1.30 + */ +gint +pango_layout_get_character_count (PangoLayout *layout) +{ + g_return_val_if_fail (PANGO_IS_LAYOUT (layout), 0); + + return layout->n_chars; +} + +/** * pango_layout_set_markup: * @layout: a #PangoLayout * @markup: marked-up text * @length: length of marked-up text in bytes, or -1 if @markup is - * nul-terminated + * null-terminated * * Same as pango_layout_set_markup_with_accel(), but * the markup text isn't scanned for accelerators. @@ -1120,9 +1140,10 @@ pango_layout_set_markup (PangoLayout *layout, * @markup: marked-up text * (see <link linkend="PangoMarkupFormat">markup format</link>) * @length: length of marked-up text in bytes, or -1 if @markup is - * nul-terminated + * null-terminated * @accel_marker: marker for accelerators in the text - * @accel_char: return location for first located accelerator, or %NULL + * @accel_char: (out caller-allocates) (allow-none): return location + * for first located accelerator, or %NULL * * Sets the layout text and attribute list from marked-up text (see * <link linkend="PangoMarkupFormat">markup format</link>). Replaces @@ -1276,6 +1297,43 @@ pango_layout_get_log_attrs (PangoLayout *layout, *n_attrs = layout->n_chars + 1; } +/** + * pango_layout_get_log_attrs_readonly: + * @layout: a #PangoLayout + * @n_attrs: location to store the number of the attributes in the array + * + * Retrieves an array of logical attributes for each character in + * the @layout. + * + * This is a faster alternative to pango_layout_get_log_attrs(). + * The returned array is part of @layout and must not be modified. + * Modifying the layout will invalidate the returned array. + * + * The number of attributes returned in @n_attrs will be one more + * than the total number of characters in the layout, since there + * need to be attributes corresponding to both the position before + * the first character and the position after the last character. + * + * Returns: an array of logical attributes + * + * Since: 1.30 + */ +const PangoLogAttr * +pango_layout_get_log_attrs_readonly (PangoLayout *layout, + gint *n_attrs) +{ + if (n_attrs) + *n_attrs = 0; + g_return_val_if_fail (layout != NULL, NULL); + + pango_layout_check_lines (layout); + + if (n_attrs) + *n_attrs = layout->n_chars + 1; + + return layout->log_attrs; +} + /** * pango_layout_get_line_count: @@ -1375,7 +1433,6 @@ pango_layout_get_line (PangoLayout *layout, { GSList *list_item; g_return_val_if_fail (layout != NULL, NULL); - g_return_val_if_fail (line >= 0, NULL); if (line < 0) return NULL; @@ -1421,7 +1478,6 @@ pango_layout_get_line_readonly (PangoLayout *layout, { GSList *list_item; g_return_val_if_fail (layout != NULL, NULL); - g_return_val_if_fail (line >= 0, NULL); if (line < 0) return NULL; @@ -1597,10 +1653,10 @@ pango_layout_index_to_line_and_extents (PangoLayout *layout, * @trailing: an integer indicating the edge of the grapheme to retrieve the * position of. If 0, the trailing edge of the grapheme, if > 0, * the leading of the grapheme. - * @line: (out): location to store resulting line index. (which will - * between 0 and pango_layout_get_line_count(layout) - 1) - * @x_pos (out): location to store resulting position within line - * (%PANGO_SCALE units per device unit) + * @line: (out) (allow-none): location to store resulting line index. (which will + * between 0 and pango_layout_get_line_count(layout) - 1), or %NULL + * @x_pos: (out) (allow-none): location to store resulting position within line + * (%PANGO_SCALE units per device unit), or %NULL * * Converts from byte @index_ within the @layout to line and X position. * (X position is measured from the left edge of the line) @@ -2166,9 +2222,9 @@ pango_layout_line_get_char_direction (PangoLayoutLine *layout_line, * pango_layout_get_cursor_pos: * @layout: a #PangoLayout * @index_: the byte index of the cursor - * @strong_pos: (out): location to store the strong cursor position + * @strong_pos: (out) (allow-none): location to store the strong cursor position * (may be %NULL) - * @weak_pos: (out): location to store the weak cursor position (may be %NULL) + * @weak_pos: (out) (allow-none): location to store the weak cursor position (may be %NULL) * * Given an index within a layout, determines the positions that of the * strong and weak cursors if the insertion point is at that @@ -2588,11 +2644,12 @@ pango_layout_get_extents_internal (PangoLayout *layout, /** * pango_layout_get_extents: * @layout: a #PangoLayout - * @ink_rect: (out): rectangle used to store the extents of the layout as drawn - * or %NULL to indicate that the result is not needed. - * @logical_rect: (out):rectangle used to store the logical extents of the - * layout or %NULL to indicate that the result is not - * needed. + * @ink_rect: (out) (allow-none): rectangle used to store the extents of the + * layout as drawn or %NULL to indicate that the result is + * not needed. + * @logical_rect: (out) (allow-none):rectangle used to store the logical + * extents of the layout or %NULL to indicate that the + * result is not needed. * * Computes the logical and ink extents of @layout. Logical extents * are usually what you want for positioning things. Note that both extents @@ -2617,11 +2674,12 @@ pango_layout_get_extents (PangoLayout *layout, /** * pango_layout_get_pixel_extents: * @layout: a #PangoLayout - * @ink_rect: (out): rectangle used to store the extents of the layout as drawn - * or %NULL to indicate that the result is not needed. - * @logical_rect: (out): rectangle used to store the logical extents of the - * layout or %NULL to indicate that the result is not - * needed. + * @ink_rect: (out) (allow-none): rectangle used to store the extents of the + * layout as drawn or %NULL to indicate that the result is + * not needed. + * @logical_rect: (out) (allow-none): rectangle used to store the logical + * extents of the layout or %NULL to indicate that the + * result is not needed. * * Computes the logical and ink extents of @layout in device units. * This function just calls pango_layout_get_extents() followed by @@ -2644,8 +2702,8 @@ pango_layout_get_pixel_extents (PangoLayout *layout, /** * pango_layout_get_size: * @layout: a #PangoLayout - * @width: (out): location to store the logical width, or %NULL - * @height: (out): location to store the logical height, or %NULL + * @width: (out caller-allocates) (allow-none): location to store the logical width, or %NULL + * @height: (out caller-allocates) (allow-none): location to store the logical height, or %NULL * * Determines the logical width and height of a #PangoLayout * in Pango units (device units scaled by %PANGO_SCALE). This @@ -2669,8 +2727,8 @@ pango_layout_get_size (PangoLayout *layout, /** * pango_layout_get_pixel_size: * @layout: a #PangoLayout - * @width: (out): location to store the logical width, or %NULL - * @height: (out): location to store the logical height, or %NULL + * @width: (out) (allow-none): location to store the logical width, or %NULL + * @height: (out) (allow-none): location to store the logical height, or %NULL * * Determines the logical width and height of a #PangoLayout * in device units. (pango_layout_get_size() returns the width @@ -4176,7 +4234,7 @@ pango_layout_line_get_width (PangoLayoutLine *line) * the last range will extend all the way to the trailing * edge of the layout. Otherwise, it will end at the * trailing edge of the last character. - * @ranges: (out) (array length=n_ranges) (transfer=full): + * @ranges: (out) (array length=n_ranges) (transfer full): * location to store a pointer to an array of ranges. * The array will be of length <literal>2*n_ranges</literal>, * with each range starting at <literal>(*ranges)[2*n]</literal> @@ -4528,10 +4586,10 @@ pango_layout_run_get_extents (PangoLayoutRun *run, /** * pango_layout_line_get_extents: * @line: a #PangoLayoutLine - * @ink_rect: (out): rectangle used to store the extents of the glyph string - * as drawn, or %NULL - * @logical_rect: (out):rectangle used to store the logical extents of the glyph - * string, or %NULL + * @ink_rect: (out) (allow-none): rectangle used to store the extents of + * the glyph string as drawn, or %NULL + * @logical_rect: (out) (allow-none):rectangle used to store the logical + * extents of the glyph string, or %NULL * * Computes the logical and ink extents of a layout line. See * pango_font_get_glyph_extents() for details about the interpretation @@ -4676,10 +4734,10 @@ pango_layout_line_new (PangoLayout *layout) /** * pango_layout_line_get_pixel_extents: * @layout_line: a #PangoLayoutLine - * @ink_rect: (out): rectangle used to store the extents of the glyph string - * as drawn, or %NULL - * @logical_rect: (out): rectangle used to store the logical extents of the - * glyph string, or %NULL + * @ink_rect: (out) (allow-none): rectangle used to store the extents of + * the glyph string as drawn, or %NULL + * @logical_rect: (out) (allow-none): rectangle used to store the logical + * extents of the glyph string, or %NULL * * Computes the logical and ink extents of @layout_line in device units. * This function just calls pango_layout_line_get_extents() followed by @@ -5567,7 +5625,7 @@ pango_layout_iter_get_index (PangoLayoutIter *iter) * Use the faster pango_layout_iter_get_run_readonly() if you do not plan * to modify the contents of the run (glyphs, glyph widths, etc.). * - * Return value: the current run. + * Return value: (transfer none): the current run. **/ PangoLayoutRun* pango_layout_iter_get_run (PangoLayoutIter *iter) @@ -5593,7 +5651,7 @@ pango_layout_iter_get_run (PangoLayoutIter *iter) * but the user is not expected * to modify the contents of the run (glyphs, glyph widths, etc.). * - * Return value: the current run, that should not be modified. + * Return value: (transfer none): the current run, that should not be modified. * * Since: 1.16 **/ @@ -5683,7 +5741,7 @@ pango_layout_iter_at_last_line (PangoLayoutIter *iter) * * Gets the layout associated with a #PangoLayoutIter. * - * Return value: the layout associated with @iter. + * Return value: (transfer none): the layout associated with @iter. * * Since: 1.20 **/ @@ -5995,8 +6053,8 @@ pango_layout_iter_get_char_extents (PangoLayoutIter *iter, /** * pango_layout_iter_get_cluster_extents: * @iter: a #PangoLayoutIter - * @ink_rect: rectangle to fill with ink extents, or %NULL - * @logical_rect: rectangle to fill with logical extents, or %NULL + * @ink_rect: (out) (allow-none): rectangle to fill with ink extents, or %NULL + * @logical_rect: (out) (allow-none): rectangle to fill with logical extents, or %NULL * * Gets the extents of the current cluster, in layout coordinates * (origin is the top left of the entire layout). @@ -6043,8 +6101,8 @@ pango_layout_iter_get_cluster_extents (PangoLayoutIter *iter, /** * pango_layout_iter_get_run_extents: * @iter: a #PangoLayoutIter - * @ink_rect: rectangle to fill with ink extents, or %NULL - * @logical_rect: rectangle to fill with logical extents, or %NULL + * @ink_rect: (out) (allow-none): rectangle to fill with ink extents, or %NULL + * @logical_rect: (out) (allow-none): rectangle to fill with logical extents, or %NULL * * Gets the extents of the current run in layout coordinates * (origin is the top left of the entire layout). @@ -6100,8 +6158,8 @@ pango_layout_iter_get_run_extents (PangoLayoutIter *iter, /** * pango_layout_iter_get_line_extents: * @iter: a #PangoLayoutIter - * @ink_rect: rectangle to fill with ink extents, or %NULL - * @logical_rect: rectangle to fill with logical extents, or %NULL + * @ink_rect: (out) (allow-none): rectangle to fill with ink extents, or %NULL + * @logical_rect: (out) (allow-none): rectangle to fill with logical extents, or %NULL * * Obtains the extents of the current line. @ink_rect or @logical_rect * can be %NULL if you aren't interested in them. Extents are in layout @@ -6140,8 +6198,8 @@ pango_layout_iter_get_line_extents (PangoLayoutIter *iter, /** * pango_layout_iter_get_line_yrange: * @iter: a #PangoLayoutIter - * @y0_: start of line - * @y1_: end of line + * @y0_: (out) (allow-none): start of line, or %NULL + * @y1_: (out) (allow-none): end of line, or %NULL * * Divides the vertical space in the #PangoLayout being iterated over * between the lines in the layout, and returns the space belonging to @@ -6216,8 +6274,10 @@ pango_layout_iter_get_baseline (PangoLayoutIter *iter) /** * pango_layout_iter_get_layout_extents: * @iter: a #PangoLayoutIter - * @ink_rect: rectangle to fill with ink extents, or %NULL - * @logical_rect: rectangle to fill with logical extents, or %NULL + * @ink_rect: (out) (allow-none): rectangle to fill with ink extents, + * or %NULL + * @logical_rect: (out) (allow-none): rectangle to fill with logical + * extents, or %NULL * * Obtains the extents of the #PangoLayout being iterated * over. @ink_rect or @logical_rect can be %NULL if you diff --git a/pango/pango-layout.h b/pango/pango-layout.h index 3b769ffa..bb0a0cf3 100644 --- a/pango/pango-layout.h +++ b/pango/pango-layout.h @@ -103,6 +103,8 @@ void pango_layout_set_text (PangoLayout *layout, int length); const char *pango_layout_get_text (PangoLayout *layout); +gint pango_layout_get_character_count (PangoLayout *layout); + void pango_layout_set_markup (PangoLayout *layout, const char *markup, int length); @@ -116,7 +118,7 @@ void pango_layout_set_markup_with_accel (PangoLayout *layout, void pango_layout_set_font_description (PangoLayout *layout, const PangoFontDescription *desc); -G_CONST_RETURN PangoFontDescription *pango_layout_get_font_description (PangoLayout *layout); +const PangoFontDescription *pango_layout_get_font_description (PangoLayout *layout); void pango_layout_set_width (PangoLayout *layout, int width); @@ -166,6 +168,9 @@ void pango_layout_get_log_attrs (PangoLayout *layout, PangoLogAttr **attrs, gint *n_attrs); +const PangoLogAttr *pango_layout_get_log_attrs_readonly (PangoLayout *layout, + gint *n_attrs); + void pango_layout_index_to_pos (PangoLayout *layout, int index_, PangoRectangle *pos); diff --git a/pango/pango-matrix.c b/pango/pango-matrix.c index f3a47e4b..50a4c800 100644 --- a/pango/pango-matrix.c +++ b/pango/pango-matrix.c @@ -188,7 +188,7 @@ pango_matrix_concat (PangoMatrix *matrix, /** * pango_matrix_get_font_scale_factor: - * @matrix: a #PangoMatrix, may be %NULL + * @matrix: (allow-none): a #PangoMatrix, may be %NULL * * Returns the scale factor of a matrix on the height of the font. * That is, the scale factor in the direction perpendicular to the @@ -244,8 +244,8 @@ pango_matrix_get_font_scale_factor (const PangoMatrix *matrix) /** * pango_matrix_transform_distance: * @matrix: a #PangoMatrix, or %NULL - * @dx: in/out X component of a distance vector - * @dy: yn/out Y component of a distance vector + * @dx: (inout): in/out X component of a distance vector + * @dy: (inout): in/out Y component of a distance vector * * Transforms the distance vector (@dx,@dy) by @matrix. This is * similar to pango_matrix_transform_point() except that the translation @@ -284,8 +284,8 @@ pango_matrix_transform_distance (const PangoMatrix *matrix, /** * pango_matrix_transform_point: * @matrix: a #PangoMatrix, or %NULL - * @x: in/out X position - * @y: in/out Y position + * @x: (inout): in/out X position + * @y: (inout): in/out Y position * * Transforms the point (@x, @y) by @matrix. * @@ -308,7 +308,7 @@ pango_matrix_transform_point (const PangoMatrix *matrix, /** * pango_matrix_transform_rectangle: * @matrix: a #PangoMatrix, or %NULL - * @rect: in/out bounding box in Pango units, or %NULL + * @rect: (inout) (allow-none): in/out bounding box in Pango units, or %NULL * * First transforms @rect using @matrix, then calculates the bounding box * of the transformed rectangle. The rectangle should be in Pango units. @@ -388,7 +388,7 @@ pango_matrix_transform_rectangle (const PangoMatrix *matrix, /** * pango_matrix_transform_pixel_rectangle: * @matrix: a #PangoMatrix, or %NULL - * @rect: in/out bounding box in device units, or %NULL + * @rect: (inout) (allow-none): in/out bounding box in device units, or %NULL * * First transforms the @rect using @matrix, then calculates the bounding box * of the transformed rectangle. The rectangle should be in device units diff --git a/pango/pango-ot-info.c b/pango/pango-ot-info.c index b03fa64b..56d28bfe 100644 --- a/pango/pango-ot-info.c +++ b/pango/pango-ot-info.c @@ -25,44 +25,19 @@ #include "pango-impl-utils.h" #include FT_TRUETYPE_TABLES_H -static void pango_ot_info_class_init (GObjectClass *object_class); static void pango_ot_info_finalize (GObject *object); -static GObjectClass *parent_class; +G_DEFINE_TYPE (PangoOTInfo, pango_ot_info, G_TYPE_OBJECT); -GType -pango_ot_info_get_type (void) +static void +pango_ot_info_init (PangoOTInfo *self) { - static GType object_type = 0; - - if (G_UNLIKELY (!object_type)) - { - const GTypeInfo object_info = - { - sizeof (PangoOTInfoClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc)pango_ot_info_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (PangoOTInfo), - 0, /* n_preallocs */ - NULL, /* init */ - NULL, /* value_table */ - }; - - object_type = g_type_register_static (G_TYPE_OBJECT, - I_("PangoOTInfo"), - &object_info, 0); - } - - return object_type; } static void -pango_ot_info_class_init (GObjectClass *object_class) +pango_ot_info_class_init (PangoOTInfoClass *klass) { - parent_class = g_type_class_peek_parent (object_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = pango_ot_info_finalize; } @@ -75,7 +50,7 @@ pango_ot_info_finalize (GObject *object) if (info->hb_face) hb_face_destroy (info->hb_face); - parent_class->finalize (object); + G_OBJECT_CLASS (pango_ot_info_parent_class)->finalize (object); } static void diff --git a/pango/pango-ot-ruleset.c b/pango/pango-ot-ruleset.c index b5e27959..82f82108 100644 --- a/pango/pango-ot-ruleset.c +++ b/pango/pango-ot-ruleset.c @@ -24,45 +24,14 @@ #include "pango-ot-private.h" #include "pango-impl-utils.h" -static void pango_ot_ruleset_class_init (GObjectClass *object_class); -static void pango_ot_ruleset_init (PangoOTRuleset *ruleset); static void pango_ot_ruleset_finalize (GObject *object); -static GObjectClass *parent_class; - -GType -pango_ot_ruleset_get_type (void) -{ - static GType object_type = 0; - - if (G_UNLIKELY (!object_type)) - { - const GTypeInfo object_info = - { - sizeof (PangoOTRulesetClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc)pango_ot_ruleset_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (PangoOTRuleset), - 0, /* n_preallocs */ - (GInstanceInitFunc)pango_ot_ruleset_init, - NULL /* value_table */ - }; - - object_type = g_type_register_static (G_TYPE_OBJECT, - I_("PangoOTRuleset"), - &object_info, 0); - } - - return object_type; -} +G_DEFINE_TYPE (PangoOTRuleset, pango_ot_ruleset, G_TYPE_OBJECT); static void -pango_ot_ruleset_class_init (GObjectClass *object_class) +pango_ot_ruleset_class_init (PangoOTRulesetClass *klass) { - parent_class = g_type_class_peek_parent (object_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = pango_ot_ruleset_finalize; } @@ -86,7 +55,7 @@ pango_ot_ruleset_finalize (GObject *object) if (ruleset->info) g_object_remove_weak_pointer (G_OBJECT (ruleset->info), (gpointer *)(void *)&ruleset->info); - parent_class->finalize (object); + G_OBJECT_CLASS (pango_ot_ruleset_parent_class)->finalize (object); } /** @@ -107,7 +76,7 @@ pango_ot_ruleset_finalize (GObject *object) * * Since: 1.18 **/ -G_CONST_RETURN PangoOTRuleset * +const PangoOTRuleset * pango_ot_ruleset_get_for_description (PangoOTInfo *info, const PangoOTRulesetDescription *desc) { diff --git a/pango/pango-renderer.c b/pango/pango-renderer.c index db75446f..1565e640 100644 --- a/pango/pango-renderer.c +++ b/pango/pango-renderer.c @@ -106,15 +106,11 @@ to_device (PangoMatrix *matrix, G_DEFINE_ABSTRACT_TYPE (PangoRenderer, pango_renderer, G_TYPE_OBJECT) -static GObjectClass *parent_class; - static void pango_renderer_class_init (PangoRendererClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass)); - klass->draw_glyphs = pango_renderer_default_draw_glyphs; klass->draw_glyph_item = pango_renderer_default_draw_glyph_item; klass->draw_rectangle = pango_renderer_default_draw_rectangle; @@ -143,7 +139,7 @@ pango_renderer_finalize (GObject *gobject) if (renderer->matrix) pango_matrix_free (renderer->matrix); - parent_class->finalize (gobject); + G_OBJECT_CLASS (pango_renderer_parent_class)->finalize (gobject); } /** @@ -676,7 +672,7 @@ pango_renderer_default_draw_glyphs (PangoRenderer *renderer, /** * pango_renderer_draw_glyph_item: * @renderer: a #PangoRenderer - * @text: the UTF-8 text that @glyph_item refers to, or %NULL + * @text: (allow-none): the UTF-8 text that @glyph_item refers to, or %NULL * @glyph_item: a #PangoGlyphItem * @x: X position of left edge of baseline, in user space coordinates * in Pango units. @@ -1145,7 +1141,7 @@ pango_renderer_deactivate (PangoRenderer *renderer) * pango_renderer_set_color: * @renderer: a #PangoRenderer * @part: the part to change the color of - * @color: the new color or %NULL to unset the current color + * @color: (allow-none): the new color or %NULL to unset the current color * * Sets the color for part of the rendering. * @@ -1321,7 +1317,7 @@ pango_renderer_default_prepare_run (PangoRenderer *renderer, /** * pango_renderer_set_matrix: * @renderer: a #PangoRenderer - * @matrix: a #PangoMatrix, or %NULL to unset any existing matrix. + * @matrix: (allow-none): a #PangoMatrix, or %NULL to unset any existing matrix. * (No matrix set is the same as setting the identity matrix.) * * Sets the transformation matrix that will be applied when rendering. @@ -1352,7 +1348,7 @@ pango_renderer_set_matrix (PangoRenderer *renderer, * * Since: 1.8 **/ -G_CONST_RETURN PangoMatrix * +const PangoMatrix * pango_renderer_get_matrix (PangoRenderer *renderer) { g_return_val_if_fail (PANGO_IS_RENDERER (renderer), NULL); @@ -1371,7 +1367,7 @@ pango_renderer_get_matrix (PangoRenderer *renderer) * The returned layout should not be modified while still being * rendered. * - * Return value: the layout, or %NULL if no layout is being + * Return value: (transfer none): the layout, or %NULL if no layout is being * rendered using @renderer at this time. * * Since: 1.20 diff --git a/pango/pango-renderer.h b/pango/pango-renderer.h index 354127b7..5410a9fe 100644 --- a/pango/pango-renderer.h +++ b/pango/pango-renderer.h @@ -249,7 +249,7 @@ PangoColor *pango_renderer_get_color (PangoRenderer *renderer, void pango_renderer_set_matrix (PangoRenderer *renderer, const PangoMatrix *matrix); -G_CONST_RETURN PangoMatrix *pango_renderer_get_matrix (PangoRenderer *renderer); +const PangoMatrix *pango_renderer_get_matrix (PangoRenderer *renderer); PangoLayout *pango_renderer_get_layout (PangoRenderer *renderer); PangoLayoutLine *pango_renderer_get_layout_line (PangoRenderer *renderer); diff --git a/pango/pango-script.c b/pango/pango-script.c index 605e46e2..92f2ef11 100644 --- a/pango/pango-script.c +++ b/pango/pango-script.c @@ -153,9 +153,9 @@ pango_script_iter_free (PangoScriptIter *iter) /** * pango_script_iter_get_range: * @iter: a #PangoScriptIter - * @start: location to store start position of the range, or %NULL - * @end: location to store end position of the range, or %NULL - * @script: location to store script for range, or %NULL + * @start: (out) (allow-none): location to store start position of the range, or %NULL + * @end: (out) (allow-none): location to store end position of the range, or %NULL + * @script: (out) (allow-none): location to store script for range, or %NULL * * Gets information about the range to which @iter currently points. * The range is the set of locations p where *start <= p < *end. @@ -164,10 +164,10 @@ pango_script_iter_free (PangoScriptIter *iter) * Since: 1.4 **/ void -pango_script_iter_get_range (PangoScriptIter *iter, - G_CONST_RETURN char **start, - G_CONST_RETURN char **end, - PangoScript *script) +pango_script_iter_get_range (PangoScriptIter *iter, + const char **start, + const char **end, + PangoScript *script) { if (start) *start = iter->script_start; diff --git a/pango/pango-script.h b/pango/pango-script.h index 32ef7372..ef5f698b 100644 --- a/pango/pango-script.h +++ b/pango/pango-script.h @@ -128,12 +128,12 @@ PangoScript pango_script_for_unichar (gunichar ch) G_GNUC_CO PangoScriptIter *pango_script_iter_new (const char *text, int length); -void pango_script_iter_get_range (PangoScriptIter *iter, - G_CONST_RETURN char **start, - G_CONST_RETURN char **end, - PangoScript *script); -gboolean pango_script_iter_next (PangoScriptIter *iter); -void pango_script_iter_free (PangoScriptIter *iter); +void pango_script_iter_get_range (PangoScriptIter *iter, + const char **start, + const char **end, + PangoScript *script); +gboolean pango_script_iter_next (PangoScriptIter *iter); +void pango_script_iter_free (PangoScriptIter *iter); #include <pango/pango-language.h> diff --git a/pango/pango-tabs.c b/pango/pango-tabs.c index aec86129..ce488173 100644 --- a/pango/pango-tabs.c +++ b/pango/pango-tabs.c @@ -283,8 +283,8 @@ pango_tab_array_set_tab (PangoTabArray *tab_array, * pango_tab_array_get_tab: * @tab_array: a #PangoTabArray * @tab_index: tab stop index - * @alignment: location to store alignment, or %NULL - * @location: location to store tab position, or %NULL + * @alignment: (out) (allow-none): location to store alignment, or %NULL + * @location: (out) (allow-none): location to store tab position, or %NULL * * Gets the alignment and position of a tab stop. * @@ -309,8 +309,10 @@ pango_tab_array_get_tab (PangoTabArray *tab_array, /** * pango_tab_array_get_tabs: * @tab_array: a #PangoTabArray - * @alignments: location to store an array of tab stop alignments, or %NULL - * @locations: location to store an array of tab positions, or %NULL + * @alignments: (out) (allow-none): location to store an array of tab stop + * alignments, or %NULL + * @locations: (out) (allow-none): location to store an array of tab positions, + * or %NULL * * If non-%NULL, @alignments and @locations are filled with allocated * arrays of length pango_tab_array_get_size(). You must free the diff --git a/pango/pango-utils.c b/pango/pango-utils.c index 1e10448c..44ec353d 100644 --- a/pango/pango-utils.c +++ b/pango/pango-utils.c @@ -176,7 +176,8 @@ pango_trim_string (const char *str) * Splits a %G_SEARCHPATH_SEPARATOR-separated list of files, stripping * white space and substituting ~/ with $HOME/. * - * Return value: a list of strings to be freed with g_strfreev() + * Return value: (transfer full) (array zero-terminated=1): a list of + * strings to be freed with g_strfreev() **/ char ** pango_split_file_list (const char *str) @@ -235,7 +236,7 @@ pango_split_file_list (const char *str) /** * pango_read_line: * @stream: a stdio stream - * @str: #GString buffer into which to write the result + * @str: (out): #GString buffer into which to write the result * * Reads an entire line from a file into a buffer. Lines may * be delimited with '\n', '\r', '\n\r', or '\r\n'. The delimiter @@ -343,7 +344,7 @@ pango_read_line (FILE *stream, GString *str) /** * pango_skip_space: - * @pos: in/out string position + * @pos: (inout): in/out string position * * Skips 0 or more characters of white space. * @@ -365,8 +366,8 @@ pango_skip_space (const char **pos) /** * pango_scan_word: - * @pos: in/out string position - * @out: a #GString into which to write the result + * @pos: (inout): in/out string position + * @out: (out): a #GString into which to write the result * * Scans a word into a #GString buffer. A word consists * of [A-Za-z_] followed by zero or more [A-Za-z_0-9] @@ -407,8 +408,8 @@ pango_scan_word (const char **pos, GString *out) /** * pango_scan_string: - * @pos: in/out string position - * @out: a #GString into which to write the result + * @pos: (inout): in/out string position + * @out: (out): a #GString into which to write the result * * Scans a string into a #GString buffer. The string may either * be a sequence of non-white-space characters, or a quoted @@ -497,8 +498,8 @@ pango_scan_string (const char **pos, GString *out) /** * pango_scan_int: - * @pos: in/out string position - * @out: an int into which to write the result + * @pos: (inout): in/out string position + * @out: (out): an int into which to write the result * * Scans an integer. * Leading white space is skipped. @@ -689,7 +690,7 @@ DllMain (HINSTANCE hinstDLL, * Return value: the Pango sysconf directory. The returned string should * not be freed. */ -G_CONST_RETURN char * +const char * pango_get_sysconf_subdirectory (void) { static const gchar *result = NULL; @@ -722,10 +723,10 @@ pango_get_sysconf_subdirectory (void) * Return value: the Pango lib directory. The returned string should * not be freed. */ -G_CONST_RETURN char * +const char * pango_get_lib_subdirectory (void) { - static gchar *result = NULL; + static const gchar *result = NULL; if (result == NULL) { @@ -773,10 +774,10 @@ parse_int (const char *word, /** * pango_parse_enum: * @type: enum type to parse, eg. %PANGO_TYPE_ELLIPSIZE_MODE. - * @str: string to parse. May be %NULL. - * @value: integer to store the result in, or %NULL. + * @str: (allow-none): string to parse. May be %NULL. + * @value: (out) (allow-none): integer to store the result in, or %NULL. * @warn: if %TRUE, issue a g_warning() on bad input. - * @possible_values: place to store list of possible values on failure, or %NULL. + * @possible_values: (out) (allow-none): place to store list of possible values on failure, or %NULL. * * Parses an enum type and stores the result in @value. * @@ -977,7 +978,7 @@ handle_alias_line (GString *line_buffer, #ifdef HAVE_CAIRO_WIN32 -static const char *builtin_aliases[] = { +static const char * const builtin_aliases[] = { "courier = \"courier new\"", "\"segoe ui\" = \"segoe ui,meiryo,malgun gothic,microsoft jhenghei,microsoft yahei,gisha,leelawadee,arial unicode ms,browallia new,mingliu,simhei,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"", "tahoma = \"tahoma,arial unicode ms,lucida sans unicode,browallia new,mingliu,simhei,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"", @@ -1094,9 +1095,9 @@ pango_load_aliases (void) /** * pango_lookup_aliases: * @fontname: an ascii string - * @families: will be set to an array of font family names. + * @families: (out) (array length=n_families): will be set to an array of font family names. * this array is owned by pango and should not be freed. - * @n_families: will be set to the length of the @families array. + * @n_families: (out): will be set to the length of the @families array. * * Look up all user defined aliases for the alias @fontname. * The resulting font family names will be stored in @families, @@ -1222,8 +1223,8 @@ pango_is_zero_width (gunichar ch) /** * pango_quantize_line_geometry: - * @thickness: pointer to the thickness of a line, in Pango units - * @position: corresponding position + * @thickness: (inout): pointer to the thickness of a line, in Pango units + * @position: (inout): corresponding position * * Quantizes the thickness and position of a line, typically an * underline or strikethrough, to whole device pixels, that is integer @@ -1294,8 +1295,8 @@ pango_units_to_double (int i) /** * pango_extents_to_pixels: - * @inclusive: rectangle to round to pixels inclusively, or %NULL. - * @nearest: rectangle to round to nearest pixels, or %NULL. + * @inclusive: (allow-none): rectangle to round to pixels inclusively, or %NULL. + * @nearest: (allow-none): rectangle to round to nearest pixels, or %NULL. * * Converts extents from Pango units to device units, dividing by the * %PANGO_SCALE factor and performing rounding. diff --git a/pango/pango-utils.h b/pango/pango-utils.h index 41a8bbb0..f86c6620 100644 --- a/pango/pango-utils.h +++ b/pango/pango-utils.h @@ -82,13 +82,13 @@ gboolean pango_parse_stretch (const char *str, * stored in the registry). The returned string should not be * g_free'd. */ -G_CONST_RETURN char * pango_get_sysconf_subdirectory (void) G_GNUC_PURE; +const char * pango_get_sysconf_subdirectory (void) G_GNUC_PURE; /* Ditto for LIBDIR/pango. On Win32, use the same Pango * installation directory. This returned string should not be * g_free'd either. */ -G_CONST_RETURN char * pango_get_lib_subdirectory (void) G_GNUC_PURE; +const char * pango_get_lib_subdirectory (void) G_GNUC_PURE; #endif /* PANGO_ENABLE_BACKEND */ @@ -131,12 +131,12 @@ gboolean pango_is_zero_width (gunichar ch) G_GNUC_CONST; int pango_version (void) G_GNUC_CONST; /* Return run-time Pango version as an string */ -G_CONST_RETURN char * pango_version_string (void) G_GNUC_CONST; +const char * pango_version_string (void) G_GNUC_CONST; /* Check that run-time Pango is as new as required */ -G_CONST_RETURN char * pango_version_check (int required_major, - int required_minor, - int required_micro) G_GNUC_CONST; +const char * pango_version_check (int required_major, + int required_minor, + int required_micro) G_GNUC_CONST; G_END_DECLS diff --git a/pango/pango.def b/pango/pango.def index 3b1bc766..1b0306d6 100644 --- a/pango/pango.def +++ b/pango/pango.def @@ -232,6 +232,7 @@ EXPORTS pango_layout_get_attributes pango_layout_get_auto_dir pango_layout_get_baseline + pango_layout_get_character_count pango_layout_get_context pango_layout_get_cursor_pos pango_layout_get_ellipsize @@ -247,6 +248,7 @@ EXPORTS pango_layout_get_lines pango_layout_get_lines_readonly pango_layout_get_log_attrs + pango_layout_get_log_attrs_readonly pango_layout_get_pixel_extents pango_layout_get_pixel_size pango_layout_get_single_paragraph_mode diff --git a/pango/pangoatsui-fontmap.c b/pango/pangoatsui-fontmap.c index 12b86bba..8eb123ae 100644 --- a/pango/pangoatsui-fontmap.c +++ b/pango/pangoatsui-fontmap.c @@ -70,9 +70,6 @@ struct _PangoATSUIFace 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) { @@ -222,14 +219,14 @@ pango_atsui_family_finalize (GObject *object) G_OBJECT_CLASS (pango_atsui_family_parent_class)->finalize (object); } +G_DEFINE_TYPE (PangoATSUIFamilyClass, pango_atsui_family, PANGO_TYPE_FONT_FAMILY); + static void -pango_atsui_family_class_init (PangoFontFamilyClass *class) +pango_atsui_family_class_init (PangoATSUIFamilyClass *class) { GObjectClass *object_class = (GObjectClass *)class; int i; - 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; @@ -246,34 +243,6 @@ pango_atsui_family_init (PangoATSUIFamily *family) family->n_faces = -1; } -static GType -pango_atsui_family_get_type (void) -{ - static GType object_type = 0; - - if (G_UNLIKELY (!object_type)) - { - 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, - I_("PangoATSUIFamily"), - &object_info, 0); - } - - return object_type; -} - static PangoFontDescription * pango_atsui_face_describe (PangoFontFace *face) { @@ -368,8 +337,6 @@ 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; diff --git a/pango/pangocairo-context.c b/pango/pangocairo-context.c index 69432f04..df1b889a 100644 --- a/pango/pangocairo-context.c +++ b/pango/pangocairo-context.c @@ -260,7 +260,7 @@ pango_cairo_context_set_font_options (PangoContext *context, * * Since: 1.10 **/ -G_CONST_RETURN cairo_font_options_t * +const cairo_font_options_t * pango_cairo_context_get_font_options (PangoContext *context) { PangoCairoContextInfo *info; @@ -286,7 +286,7 @@ pango_cairo_context_get_font_options (PangoContext *context) * Return value: the combined set of font options. This value is owned * by the context and must not be modified or freed. **/ -G_CONST_RETURN cairo_font_options_t * +const cairo_font_options_t * _pango_cairo_context_get_merged_font_options (PangoContext *context) { PangoCairoContextInfo *info = get_context_info (context, TRUE); @@ -340,7 +340,7 @@ pango_cairo_context_set_shape_renderer (PangoContext *context, } /** - * pango_cairo_context_get_shape_renderer: + * pango_cairo_context_get_shape_renderer: (skip) * @context: a #PangoContext, from a pangocairo font map * @data: Pointer to #gpointer to return user data * @@ -394,7 +394,7 @@ pango_cairo_context_get_shape_renderer (PangoContext *context, * create a layout for use with @cr and do not need to access #PangoContext * directly, you can use pango_cairo_create_layout() instead. * - * Return value: the newly created #PangoContext. Free with + * Return value: (transfer full): the newly created #PangoContext. Free with * g_object_unref(). * * Since: 1.22 @@ -430,7 +430,7 @@ pango_cairo_create_context (cairo_t *cr) * #PangoContext object for each layout. This might matter in an * application that was laying out large amounts of text. * - * Return value: the newly created #PangoLayout. Free with + * Return value: (transfer full): the newly created #PangoLayout. Free with * g_object_unref(). * * Since: 1.10 diff --git a/pango/pangocairo-coretext.h b/pango/pangocairo-coretext.h new file mode 100644 index 00000000..420e1c9e --- /dev/null +++ b/pango/pangocairo-coretext.h @@ -0,0 +1,55 @@ +/* Pango + * pangocairo-coretext.h: + * + * Copyright (C) 2005 Imendio AB + * Copyright (C) 2010 Kristian Rietveld <kris@gtk.org> + * + * 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_CORETEXT_H__ +#define __PANGOCAIRO_CORETEXT_H__ + +#include "pangocoretext-private.h" +#include <pango/pangocairo.h> +#include <cairo-quartz.h> + +G_BEGIN_DECLS + +#define PANGO_TYPE_CAIRO_CORE_TEXT_FONT_MAP (pango_cairo_core_text_font_map_get_type ()) +#define PANGO_CAIRO_CORE_TEXT_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_CAIRO_CORE_TEXT_FONT_MAP, PangoCairoCoreTextFontMap)) +#define PANGO_IS_CAIRO_CORE_TEXT_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_CAIRO_CORE_TEXT_FONT_MAP)) + +typedef struct _PangoCairoCoreTextFontMap PangoCairoCoreTextFontMap; + +struct _PangoCairoCoreTextFontMap +{ + PangoCoreTextFontMap parent_instance; + + gdouble dpi; +}; + +GType pango_cairo_core_text_font_map_get_type (void) G_GNUC_CONST; + +PangoCoreTextFont * +_pango_cairo_core_text_font_new (PangoCairoCoreTextFontMap *cafontmap, + PangoContext *context, + PangoCoreTextFace *face, + const PangoFontDescription *desc); + +G_END_DECLS + +#endif /* __PANGOCAIRO_CORETEXT_H__ */ diff --git a/pango/pangocairo-coretextfont.c b/pango/pangocairo-coretextfont.c new file mode 100644 index 00000000..7b58148c --- /dev/null +++ b/pango/pangocairo-coretextfont.c @@ -0,0 +1,284 @@ +/* Pango + * pangocairo-coretextfont.c + * + * Copyright (C) 2000-2005 Red Hat Software + * Copyright (C) 2005-2007 Imendio AB + * Copyright (C) 2010 Kristian Rietveld <kris@gtk.org> + * + * 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 "config.h" + +#include <Carbon/Carbon.h> + +#include "pango-impl-utils.h" +#include "pangocoretext-private.h" +#include "pangocairo.h" +#include "pangocairo-private.h" +#include "pangocairo-coretext.h" +#include "pangocairo-coretextfont.h" + +struct _PangoCairoCoreTextFont +{ + PangoCoreTextFont font; + PangoCairoFontPrivate cf_priv; + + int abs_size; +}; + +struct _PangoCairoCoreTextFontClass +{ + PangoCoreTextFontClass parent_class; +}; + + + +static cairo_font_face_t *pango_cairo_core_text_font_create_font_face (PangoCairoFont *font); +static PangoFontMetrics *pango_cairo_core_text_font_create_base_metrics_for_context (PangoCairoFont *font, + PangoContext *context); + +static void +cairo_font_iface_init (PangoCairoFontIface *iface) +{ + iface->create_font_face = pango_cairo_core_text_font_create_font_face; + iface->create_base_metrics_for_context = pango_cairo_core_text_font_create_base_metrics_for_context; + iface->cf_priv_offset = G_STRUCT_OFFSET (PangoCairoCoreTextFont, cf_priv); +} + +G_DEFINE_TYPE_WITH_CODE (PangoCairoCoreTextFont, pango_cairo_core_text_font, PANGO_TYPE_CORE_TEXT_FONT, + { G_IMPLEMENT_INTERFACE (PANGO_TYPE_CAIRO_FONT, cairo_font_iface_init) }); + +/* we want get_glyph_extents extremely fast, so we use a small wrapper here + * to avoid having to lookup the interface data like we do for get_metrics + * in _pango_cairo_font_get_metrics(). */ +static void +pango_cairo_core_text_font_get_glyph_extents (PangoFont *font, + PangoGlyph glyph, + PangoRectangle *ink_rect, + PangoRectangle *logical_rect) +{ + PangoCairoCoreTextFont *cafont = (PangoCairoCoreTextFont *) (font); + + _pango_cairo_font_private_get_glyph_extents (&cafont->cf_priv, + glyph, + ink_rect, + logical_rect); +} + +static cairo_font_face_t * +pango_cairo_core_text_font_create_font_face (PangoCairoFont *font) +{ + PangoCoreTextFont *ctfont = (PangoCoreTextFont *) (font); + CTFontRef font_id; + CGFontRef cgfont; + cairo_font_face_t *cairo_face; + + font_id = pango_core_text_font_get_ctfont (ctfont); + cgfont = CTFontCopyGraphicsFont (font_id, NULL); + + cairo_face = cairo_quartz_font_face_create_for_cgfont (cgfont); + + CFRelease (cgfont); + + return cairo_face; +} + +static int +max_glyph_width (PangoLayout *layout) +{ + int max_width = 0; + GSList *l, *r; + + for (l = pango_layout_get_lines_readonly (layout); l; l = l->next) + { + PangoLayoutLine *line = l->data; + + for (r = line->runs; r; r = r->next) + { + PangoGlyphString *glyphs = ((PangoGlyphItem *)r->data)->glyphs; + int i; + + for (i = 0; i < glyphs->num_glyphs; i++) + if (glyphs->glyphs[i].geometry.width > max_width) + max_width = glyphs->glyphs[i].geometry.width; + } + } + + return max_width; +} + +static PangoFontMetrics * +pango_cairo_core_text_font_create_base_metrics_for_context (PangoCairoFont *font, + PangoContext *context) +{ + PangoCoreTextFont *cfont = (PangoCoreTextFont *) font; + PangoFontMetrics *metrics; + PangoFontDescription *font_desc; + PangoLayout *layout; + PangoRectangle extents; + PangoLanguage *language = pango_context_get_language (context); + const char *sample_str = pango_language_get_sample_string (language); + CTFontRef ctfont; + + metrics = pango_font_metrics_new (); + + ctfont = pango_core_text_font_get_ctfont (cfont); + + metrics->ascent = CTFontGetAscent (ctfont) * PANGO_SCALE; + metrics->descent = CTFontGetDescent (ctfont) * PANGO_SCALE; + + metrics->underline_position = CTFontGetUnderlinePosition (ctfont) * PANGO_SCALE; + metrics->underline_thickness = CTFontGetUnderlineThickness (ctfont) * PANGO_SCALE; + + metrics->strikethrough_position = metrics->ascent / 3; + metrics->strikethrough_thickness = CTFontGetUnderlineThickness (ctfont) * PANGO_SCALE; + + layout = pango_layout_new (context); + font_desc = pango_font_describe_with_absolute_size ((PangoFont *) font); + pango_layout_set_font_description (layout, font_desc); + pango_layout_set_text (layout, sample_str, -1); + pango_layout_get_extents (layout, NULL, &extents); + + metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str); + + pango_layout_set_text (layout, "0123456789", -1); + metrics->approximate_digit_width = max_glyph_width (layout); + + pango_font_description_free (font_desc); + g_object_unref (layout); + + return metrics; +} + +static PangoFontDescription * +pango_cairo_core_text_font_describe_absolute (PangoFont *font) +{ + PangoFontDescription *desc; + PangoCairoCoreTextFont *cafont = (PangoCairoCoreTextFont *) font; + + desc = pango_font_describe (font); + pango_font_description_set_absolute_size (desc, cafont->abs_size); + + return desc; +} + +static void +pango_cairo_core_text_font_finalize (GObject *object) +{ + PangoCairoCoreTextFont *cafont = (PangoCairoCoreTextFont *) object; + + _pango_cairo_font_private_finalize (&cafont->cf_priv); + + G_OBJECT_CLASS (pango_cairo_core_text_font_parent_class)->finalize (object); +} + +static void +pango_cairo_core_text_font_class_init (PangoCairoCoreTextFontClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + PangoFontClass *font_class = PANGO_FONT_CLASS (class); + + object_class->finalize = pango_cairo_core_text_font_finalize; + + font_class->get_glyph_extents = pango_cairo_core_text_font_get_glyph_extents; + font_class->get_metrics = _pango_cairo_font_get_metrics; + font_class->describe_absolute = pango_cairo_core_text_font_describe_absolute; +} + +static void +pango_cairo_core_text_font_init (PangoCairoCoreTextFont *cafont G_GNUC_UNUSED) +{ +} + +PangoCoreTextFont * +_pango_cairo_core_text_font_new (PangoCairoCoreTextFontMap *cafontmap, + PangoContext *context, + PangoCoreTextFace *face, + const PangoFontDescription *desc) +{ + const char *postscript_name; + gboolean synthesize_italic = FALSE; + PangoCairoCoreTextFont *cafont; + PangoCoreTextFont *cfont; + CFStringRef cfstr; + CTFontRef font_ref; + CGFontRef font_id; + double size, abs_size; + double dpi; + cairo_matrix_t font_matrix; + + postscript_name = _pango_core_text_face_get_postscript_name (face); + + abs_size = size = pango_units_to_double (pango_font_description_get_size (desc)); + + if (context) + { + dpi = pango_cairo_context_get_resolution (context); + + if (dpi <= 0) + dpi = cafontmap->dpi; + } + else + dpi = cafontmap->dpi; + + if (pango_font_description_get_size_is_absolute (desc)) + size *= 72. / dpi; + else + abs_size *= dpi / 72.; + + cfstr = CFStringCreateWithCString (NULL, postscript_name, + kCFStringEncodingUTF8); + font_ref = CTFontCreateWithName (cfstr, size, NULL); + CFRelease (cfstr); + + if (_pango_core_text_face_get_synthetic_italic (face)) + synthesize_italic = TRUE; + + font_id = CTFontCopyGraphicsFont (font_ref, NULL); + if (!font_id) + return NULL; + + cafont = g_object_new (PANGO_TYPE_CAIRO_CORE_TEXT_FONT, NULL); + cfont = PANGO_CORE_TEXT_FONT (cafont); + + _pango_core_text_font_set_font_description (cfont, desc); + _pango_core_text_font_set_face (cfont, face); + + cafont->abs_size = abs_size * PANGO_SCALE; + + _pango_core_text_font_set_ctfont (cfont, font_ref); + + if (synthesize_italic) + cairo_matrix_init (&font_matrix, + 1, 0, + -0.25, 1, + 0, 0); + else + cairo_matrix_init_identity (&font_matrix); + + /* Scale using absolute size */ + cairo_matrix_scale (&font_matrix, abs_size, abs_size); + + _pango_cairo_font_private_initialize (&cafont->cf_priv, + (PangoCairoFont *) cafont, + pango_font_description_get_gravity (desc), + _pango_cairo_context_get_merged_font_options (context), + pango_context_get_matrix (context), + &font_matrix); + + return cfont; +} diff --git a/pango/pangocairo-coretextfont.h b/pango/pangocairo-coretextfont.h new file mode 100644 index 00000000..752dfdd7 --- /dev/null +++ b/pango/pangocairo-coretextfont.h @@ -0,0 +1,37 @@ +/* Pango + * pangocairo-coretextfont.c + * + * Copyright (C) 2005 Imendio AB + * Copyright (C) 2010 Kristian Rietveld <kris@gtk.org> + * + * 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_CORETEXTFONT_H__ +#define __PANGOCAIRO_CORETEXTFONT_H__ + +#define PANGO_TYPE_CAIRO_CORE_TEXT_FONT (pango_cairo_core_text_font_get_type ()) +#define PANGO_CAIRO_CORE_TEXT_FONT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_CAIRO_CORE_TEXT_FONT, PangoCairoCoreTextFont)) +#define PANGO_CAIRO_CORE_TEXT_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_CAIRO_CORE_TEXT_FONT, PangoCairoCoreTextFontClass)) +#define PANGO_IS_CAIRO_CORE_TEXT_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_CAIRO_CORE_TEXT_FONT)) +#define PANGO_CAIRO_CORE_TEXT_FONT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_CAIRO_CORE_TEXT_FONT, PangoCairoCoreTextFontClass)) + +typedef struct _PangoCairoCoreTextFont PangoCairoCoreTextFont; +typedef struct _PangoCairoCoreTextFontClass PangoCairoCoreTextFontClass; + +GType pango_cairo_core_text_font_get_type (void) G_GNUC_CONST; + +#endif /* __PANGOCAIRO_CORETEXTFONT_H__ */ diff --git a/pango/pangocairo-coretextfontmap.c b/pango/pangocairo-coretextfontmap.c new file mode 100644 index 00000000..e05a1d40 --- /dev/null +++ b/pango/pangocairo-coretextfontmap.c @@ -0,0 +1,107 @@ +/* Pango + * pangocairo-coretextfontmap.c + * + * Copyright (C) 2005 Imendio AB + * Copyright (C) 2010 Kristian Rietveld <kris@gtk.org> + * + * 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 "config.h" + +#include "pangocoretext-private.h" +#include "pangocairo.h" +#include "pangocairo-private.h" +#include "pangocairo-coretext.h" + +typedef struct _PangoCairoCoreTextFontMapClass PangoCairoCoreTextFontMapClass; + +struct _PangoCairoCoreTextFontMapClass +{ + PangoCoreTextFontMapClass parent_class; +}; + +static void +pango_cairo_core_text_font_map_set_resolution (PangoCairoFontMap *cfontmap, + double dpi) +{ + PangoCairoCoreTextFontMap *cafontmap = PANGO_CAIRO_CORE_TEXT_FONT_MAP (cfontmap); + + cafontmap->dpi = dpi; +} + +static double +pango_cairo_core_text_font_map_get_resolution (PangoCairoFontMap *cfontmap) +{ + PangoCairoCoreTextFontMap *cafontmap = PANGO_CAIRO_CORE_TEXT_FONT_MAP (cfontmap); + + return cafontmap->dpi; +} + +static cairo_font_type_t +pango_cairo_core_text_font_map_get_font_type (PangoCairoFontMap *cfontmap) +{ + /* This is a bit misleading, but Cairo takes a CoreGraphics font + * for rendering and does not use ATSUI. + */ + return CAIRO_FONT_TYPE_ATSUI; +} + +static void +cairo_font_map_iface_init (PangoCairoFontMapIface *iface) +{ + iface->set_resolution = pango_cairo_core_text_font_map_set_resolution; + iface->get_resolution = pango_cairo_core_text_font_map_get_resolution; + iface->get_font_type = pango_cairo_core_text_font_map_get_font_type; +} + +G_DEFINE_TYPE_WITH_CODE (PangoCairoCoreTextFontMap, pango_cairo_core_text_font_map, PANGO_TYPE_CORE_TEXT_FONT_MAP, + { G_IMPLEMENT_INTERFACE (PANGO_TYPE_CAIRO_FONT_MAP, cairo_font_map_iface_init) }); + + +static PangoCoreTextFont * +pango_cairo_core_text_font_map_create_font (PangoCoreTextFontMap *fontmap, + PangoContext *context, + PangoCoreTextFace *face, + const PangoFontDescription *desc) + +{ + return _pango_cairo_core_text_font_new (PANGO_CAIRO_CORE_TEXT_FONT_MAP (fontmap), + context, face, desc); +} + +static void +pango_cairo_core_text_font_map_finalize (GObject *object) +{ + G_OBJECT_CLASS (pango_cairo_core_text_font_map_parent_class)->finalize (object); +} + +static void +pango_cairo_core_text_font_map_class_init (PangoCairoCoreTextFontMapClass *class) +{ + PangoCoreTextFontMapClass *ctfontmapclass = (PangoCoreTextFontMapClass *)class; + GObjectClass *object_class = (GObjectClass *)class; + + object_class->finalize = pango_cairo_core_text_font_map_finalize; + + ctfontmapclass->create_font = pango_cairo_core_text_font_map_create_font; +} + +static void +pango_cairo_core_text_font_map_init (PangoCairoCoreTextFontMap *cafontmap) +{ + cafontmap->dpi = 72.; +} diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c index df0a7777..8dc8df04 100644 --- a/pango/pangocairo-font.c +++ b/pango/pangocairo-font.c @@ -34,37 +34,15 @@ G_STRUCT_MEMBER_P (font, \ PANGO_CAIRO_FONT_GET_IFACE(PANGO_CAIRO_FONT(font))->cf_priv_offset))) -GType -pango_cairo_font_get_type (void) -{ - static GType cairo_font_type = 0; - - if (! cairo_font_type) - { - const GTypeInfo cairo_font_info = - { - sizeof (PangoCairoFontIface), /* class_size */ - NULL, /* base_init */ - NULL, /* base_finalize */ - NULL, - NULL, /* class_finalize */ - NULL, /* class_data */ - 0, - 0, - NULL, - NULL - }; - - cairo_font_type = - g_type_register_static (G_TYPE_INTERFACE, I_("PangoCairoFont"), - &cairo_font_info, 0); - - g_type_interface_add_prerequisite (cairo_font_type, PANGO_TYPE_FONT); - } +typedef PangoCairoFontIface PangoCairoFontInterface; +G_DEFINE_INTERFACE (PangoCairoFont, pango_cairo_font, PANGO_TYPE_FONT) - return cairo_font_type; +static void +pango_cairo_font_default_init (PangoCairoFontIface *iface) +{ } + static PangoCairoFontPrivateScaledFontData * _pango_cairo_font_private_scaled_font_data_create (void) { diff --git a/pango/pangocairo-fontmap.c b/pango/pangocairo-fontmap.c index ae917d06..d5bff788 100644 --- a/pango/pangocairo-fontmap.c +++ b/pango/pangocairo-fontmap.c @@ -26,7 +26,11 @@ #include "pango-impl-utils.h" #if defined (HAVE_CAIRO_ATSUI) -# include "pangocairo-atsui.h" +# if defined (HAVE_CORE_TEXT) +# include "pangocairo-coretext.h" +# else +# include "pangocairo-atsui.h" +# endif #endif #if defined (HAVE_CAIRO_WIN32) # include "pangocairo-win32.h" @@ -35,35 +39,13 @@ # include "pangocairo-fc.h" #endif -GType -pango_cairo_font_map_get_type (void) -{ - static GType cairo_font_map_type = 0; - - if (! cairo_font_map_type) - { - const GTypeInfo cairo_font_map_info = - { - sizeof (PangoCairoFontMapIface), /* class_size */ - NULL, /* base_init */ - NULL, /* base_finalize */ - NULL, - NULL, /* class_finalize */ - NULL, /* class_data */ - 0, - 0, - NULL, - NULL - }; - cairo_font_map_type = - g_type_register_static (G_TYPE_INTERFACE, I_("PangoCairoFontMap"), - &cairo_font_map_info, 0); +typedef PangoCairoFontMapIface PangoCairoFontMapInterface; +G_DEFINE_INTERFACE (PangoCairoFontMap, pango_cairo_font_map, PANGO_TYPE_FONT_MAP) - g_type_interface_add_prerequisite (cairo_font_map_type, PANGO_TYPE_FONT_MAP); - } - - return cairo_font_map_type; +static void +pango_cairo_font_map_default_init (PangoCairoFontMapIface *iface) +{ } /** @@ -80,8 +62,8 @@ pango_cairo_font_map_get_type (void) * You generally should only use the #PangoFontMap and * #PangoCairoFontMap interfaces on the returned object. * - * Return value: the newly allocated #PangoFontMap, which should - * be freed with g_object_unref(). + * Return value: (transfer full): the newly allocated #PangoFontMap, + * which should be freed with g_object_unref(). * * Since: 1.10 **/ @@ -92,7 +74,11 @@ pango_cairo_font_map_new (void) g_type_init (); #if defined(HAVE_CAIRO_ATSUI) +#if defined(HAVE_CORE_TEXT) + return g_object_new (PANGO_TYPE_CAIRO_CORE_TEXT_FONT_MAP, NULL); +#else return g_object_new (PANGO_TYPE_CAIRO_ATSUI_FONT_MAP, NULL); +#endif #elif defined(HAVE_CAIRO_WIN32) return g_object_new (PANGO_TYPE_CAIRO_WIN32_FONT_MAP, NULL); #elif defined(HAVE_CAIRO_FREETYPE) @@ -114,10 +100,10 @@ pango_cairo_font_map_new (void) * or in fact in most of those cases, just use * @pango_cairo_font_map_get_default(). * - * Return value: the newly allocated #PangoFontMap of suitable type - * which should be freed with g_object_unref(), - * or %NULL if the requested cairo font backend is - * not supported / compiled in. + * Return value: (transfer full) : the newly allocated #PangoFontMap + * of suitable type which should be freed with + * g_object_unref(), or %NULL if the requested cairo + * font backend is not supported / compiled in. * * Since: 1.18 **/ @@ -131,8 +117,12 @@ pango_cairo_font_map_new_for_font_type (cairo_font_type_t fonttype) { #if defined(HAVE_CAIRO_ATSUI) case CAIRO_FONT_TYPE_QUARTZ: +#if defined(HAVE_CORE_TEXT) + return g_object_new (PANGO_TYPE_CAIRO_CORE_TEXT_FONT_MAP, NULL); +#else return g_object_new (PANGO_TYPE_CAIRO_ATSUI_FONT_MAP, NULL); #endif +#endif #if defined(HAVE_CAIRO_WIN32) case CAIRO_FONT_TYPE_WIN32: return g_object_new (PANGO_TYPE_CAIRO_WIN32_FONT_MAP, NULL); @@ -163,8 +153,8 @@ static PangoFontMap *default_font_map = NULL; * change the Cairo font backend that the default fontmap * uses for example. * - * Return value: the default Cairo fontmap for Pango. This - * object is owned by Pango and must not be freed. + * Return value: (transfer none): the default Cairo fontmap + * for Pango. This object is owned by Pango and must not be freed. * * Since: 1.10 **/ @@ -250,7 +240,7 @@ pango_cairo_font_map_get_resolution (PangoCairoFontMap *fontmap) } /** - * pango_cairo_font_map_create_context: + * pango_cairo_font_map_create_context: (skip) * @fontmap: a #PangoCairoFontMap * * Create a #PangoContext for the given fontmap. diff --git a/pango/pangocoretext-fontmap.c b/pango/pangocoretext-fontmap.c new file mode 100644 index 00000000..542665e0 --- /dev/null +++ b/pango/pangocoretext-fontmap.c @@ -0,0 +1,1000 @@ +/* Pango + * pangocoretext-fontmap.c + * + * Copyright (C) 2000-2003 Red Hat, Inc. + * Copyright (C) 2005-2007 Imendio AB + * Copyright (C) 2010 Kristian Rietveld <kris@gtk.org> + * + * 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 "config.h" + +#include "pango-fontmap.h" +#include "pangocoretext-private.h" +#include "pango-impl-utils.h" +#include "modules.h" + +#include <Carbon/Carbon.h> + +typedef struct _FontHashKey FontHashKey; + + +#define PANGO_TYPE_CORE_TEXT_FAMILY (pango_core_text_family_get_type ()) +#define PANGO_CORE_TEXT_FAMILY(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_CORE_TEXT_FAMILY, PangoCoreTextFamily)) +#define PANGO_IS_CORE_TEXT_FAMILY(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_CORE_TEXT_FAMILY)) +#define PANGO_CORE_TEXT_FAMILY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_CORE_TEXT_FAMILY, PangoCoreTextFamilyClass)) +#define PANGO_IS_CORE_TEXT_FAMILY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_CORE_TEXT_FAMILY)) +#define PANGO_CORE_TEXT_FAMILY_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), PANGO_CORE_TEXT_FAMILY, PangoCoreTextFamilyClass)) + +struct _PangoCoreTextFamily +{ + PangoFontFamily parent_instance; + + char *family_name; + + guint is_monospace : 1; + + PangoFontFace **faces; + gint n_faces; +}; + +struct _PangoCoreTextFamilyClass +{ + PangoFontFamilyClass parent_class; +}; + +typedef struct _PangoCoreTextFamilyClass PangoCoreTextFamilyClass; + +#define PANGO_TYPE_CORE_TEXT_FACE (pango_core_text_face_get_type ()) +#define PANGO_CORE_TEXT_FACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_CORE_TEXT_FACE, PangoCoreTextFace)) +#define PANGO_IS_CORE_TEXT_FACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_CORE_TEXT_FACE)) +#define PANGO_CORE_TEXT_FACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_CORE_TEXT_FACE, PangoCoreTextFaceClass)) +#define PANGO_IS_CORE_TEXT_FACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_CORE_TEXT_FACE)) +#define PANGO_CORE_TEXT_FACE_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), PANGO_CORE_TEXT_FACE, PangoCoreTextFaceClass)) + +struct _PangoCoreTextFace +{ + PangoFontFace parent_instance; + + PangoCoreTextFamily *family; + + PangoCoverage *coverage; + + char *postscript_name; + char *style_name; + + PangoWeight weight; + int traits; + guint synthetic_italic : 1; +}; + +struct _PangoCoreTextFaceClass +{ + PangoFontFaceClass parent_class; +}; + +typedef struct _PangoCoreTextFaceClass PangoCoreTextFaceClass; + +static GType pango_core_text_family_get_type (void); +static GType pango_core_text_face_get_type (void); + +typedef struct +{ + float bound; + PangoWeight weight; +} PangoCTWeight; + +static const float ct_weight_min = -1.00f; +static const float ct_weight_max = 1.00f; + +static const PangoCTWeight ct_weight_limits[] = { + { -0.70, PANGO_WEIGHT_THIN}, + { -0.50, PANGO_WEIGHT_ULTRALIGHT }, + { -0.35, PANGO_WEIGHT_LIGHT }, + { -0.10, PANGO_WEIGHT_BOOK }, + { 0.10, PANGO_WEIGHT_NORMAL }, + { 0.24, PANGO_WEIGHT_MEDIUM }, + { 0.36, PANGO_WEIGHT_SEMIBOLD }, + { 0.50, PANGO_WEIGHT_BOLD }, + { 0.75, PANGO_WEIGHT_ULTRABOLD }, + { 1.00, PANGO_WEIGHT_HEAVY } +}; + +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 gchar * +gchar_from_cf_string (CFStringRef str) +{ + CFIndex len; + gchar *buffer; + + /* GetLength returns the number of UTF-16 pairs, so this number + * times 2 should definitely gives us enough space for UTF8. + * We add one for the terminating zero. + */ + len = CFStringGetLength (str) * 2 + 1; + buffer = g_new0 (char, len); + CFStringGetCString (str, buffer, len, kCFStringEncodingUTF8); + + return buffer; +} + +static PangoCoverage * +pango_coverage_from_cf_charset (CFCharacterSetRef charset) +{ + CFIndex i, length; + CFDataRef bitmap; + const UInt8 *ptr; + PangoCoverage *coverage; + + coverage = pango_coverage_new (); + + bitmap = CFCharacterSetCreateBitmapRepresentation (kCFAllocatorDefault, + charset); + + /* We only handle the BMP plane */ + length = MIN (CFDataGetLength (bitmap), 8192); + ptr = CFDataGetBytePtr (bitmap); + + /* FIXME: can and should this be done more efficiently? */ + for (i = 0; i < length; i++) + { + int j; + + for (j = 0; j < 8; j++) + pango_coverage_set (coverage, i * 8 + j, + ((ptr[i] & (1 << j)) == (1 << j)) ? + PANGO_COVERAGE_EXACT : PANGO_COVERAGE_NONE); + } + + CFRelease (bitmap); + + return coverage; +} + +static inline gboolean +pango_core_text_face_is_oblique (PangoCoreTextFace *face) +{ + return g_strrstr (face->style_name, "Oblique") != NULL; +} + +static inline PangoCoreTextFace * +pango_core_text_face_from_ct_font_descriptor (CTFontDescriptorRef desc) +{ + int font_traits; + char *buffer; + CFStringRef str; + CFNumberRef number; + CGFloat value; + CFDictionaryRef dict; + CFCharacterSetRef charset; + PangoCoreTextFace *face = g_object_new (PANGO_TYPE_CORE_TEXT_FACE, + NULL); + + face->synthetic_italic = FALSE; + + /* Get font name */ + str = CTFontDescriptorCopyAttribute (desc, kCTFontNameAttribute); + buffer = gchar_from_cf_string (str); + + /* We strdup again to save space. */ + face->postscript_name = g_strdup (buffer); + + CFRelease (str); + g_free (buffer); + + /* Get style name */ + str = CTFontDescriptorCopyAttribute (desc, kCTFontStyleNameAttribute); + buffer = gchar_from_cf_string (str); + + face->style_name = g_strdup (buffer); + + CFRelease (str); + g_free (buffer); + + /* Get font traits, symbolic traits */ + dict = CTFontDescriptorCopyAttribute (desc, kCTFontTraitsAttribute); + number = (CFNumberRef)CFDictionaryGetValue (dict, + kCTFontWeightTrait); + if (CFNumberGetValue (number, kCFNumberCGFloatType, &value)) + { + if (value < ct_weight_min || value > ct_weight_max) + { + face->weight = PANGO_WEIGHT_NORMAL; /* This is really an error */ + } + else + { + guint i; + for (i = 0; i < G_N_ELEMENTS(ct_weight_limits); i++) + if (value < ct_weight_limits[i].bound) + { + face->weight = ct_weight_limits[i].weight; + break; + } + } + } + else + face->weight = PANGO_WEIGHT_NORMAL; + + number = (CFNumberRef)CFDictionaryGetValue (dict, kCTFontSymbolicTrait); + if (CFNumberGetValue (number, kCFNumberIntType, &font_traits)) + { + face->traits = font_traits; + } + CFRelease (dict); + + /* Get font coverage */ + charset = CTFontDescriptorCopyAttribute (desc, + kCTFontCharacterSetAttribute); + face->coverage = pango_coverage_from_cf_charset (charset); + CFRelease (charset); + + return face; +} + +static void +pango_core_text_family_list_faces (PangoFontFamily *family, + PangoFontFace ***faces, + int *n_faces) +{ + PangoCoreTextFamily *ctfamily = PANGO_CORE_TEXT_FAMILY (family); + + if (ctfamily->n_faces < 0) + { + GList *l; + GList *faces = NULL; + GList *synthetic_faces = NULL; + GHashTable *italic_faces; + const char *real_family = get_real_family (ctfamily->family_name); + CTFontCollectionRef collection; + CFArrayRef ctfaces; + CFArrayRef font_descriptors; + CFDictionaryRef attributes; + CFIndex i, count; + + CFTypeRef keys[] = { + (CFTypeRef) kCTFontFamilyNameAttribute + }; + + CFStringRef values[] = { + CFStringCreateWithCString (kCFAllocatorDefault, + real_family, + kCFStringEncodingUTF8) + }; + + CTFontDescriptorRef descriptors[1]; + + attributes = CFDictionaryCreate (kCFAllocatorDefault, + (const void **)keys, + (const void **)values, + 1, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + descriptors[0] = CTFontDescriptorCreateWithAttributes (attributes); + font_descriptors = CFArrayCreate (kCFAllocatorDefault, + (const void **)descriptors, + 1, + &kCFTypeArrayCallBacks); + collection = CTFontCollectionCreateWithFontDescriptors (font_descriptors, + NULL); + + ctfaces = CTFontCollectionCreateMatchingFontDescriptors (collection); + + italic_faces = g_hash_table_new (g_direct_hash, g_direct_equal); + + count = CFArrayGetCount (ctfaces); + for (i = 0; i < count; i++) + { + PangoCoreTextFace *face; + CTFontDescriptorRef desc = CFArrayGetValueAtIndex (ctfaces, i); + + face = pango_core_text_face_from_ct_font_descriptor (desc); + face->family = ctfamily; + + faces = g_list_prepend (faces, face); + + if (face->traits & kCTFontItalicTrait + || pango_core_text_face_is_oblique (face)) + g_hash_table_insert (italic_faces, + GINT_TO_POINTER ((gint)face->weight), + face); + } + + CFRelease (font_descriptors); + CFRelease (attributes); + CFRelease (ctfaces); + + /* For all fonts for which a non-synthetic italic variant does + * not exist on the system, we create synthesized versions here. + */ + for (l = faces; l; l = l->next) + { + PangoCoreTextFace *face = l->data; + + if (!g_hash_table_lookup (italic_faces, + GINT_TO_POINTER ((gint)face->weight))) + { + PangoCoreTextFace *italic_face; + + italic_face = g_object_new (PANGO_TYPE_CORE_TEXT_FACE, NULL); + + italic_face->family = ctfamily; + italic_face->postscript_name = g_strdup (face->postscript_name); + italic_face->weight = face->weight; + italic_face->traits = face->traits | kCTFontItalicTrait; + italic_face->synthetic_italic = TRUE; + italic_face->coverage = pango_coverage_ref (face->coverage); + + /* Try to create a sensible face name. */ + if (strcasecmp (face->style_name, "regular") == 0) + italic_face->style_name = g_strdup ("Oblique"); + else + italic_face->style_name = g_strdup_printf ("%s Oblique", + face->style_name); + + synthetic_faces = g_list_prepend (synthetic_faces, italic_face); + } + } + + faces = g_list_concat (faces, synthetic_faces); + + ctfamily->n_faces = g_list_length (faces); + ctfamily->faces = g_new (PangoFontFace *, ctfamily->n_faces); + + for (l = faces, i = 0; l; l = l->next, i++) + ctfamily->faces[i] = l->data; + + g_list_free (faces); + g_hash_table_destroy (italic_faces); + } + + if (n_faces) + *n_faces = ctfamily->n_faces; + + if (faces) + *faces = g_memdup (ctfamily->faces, ctfamily->n_faces * sizeof (PangoFontFace *)); +} + +static const char * +pango_core_text_family_get_name (PangoFontFamily *family) +{ + PangoCoreTextFamily *ctfamily = PANGO_CORE_TEXT_FAMILY (family); + + return ctfamily->family_name; +} + +static gboolean +pango_core_text_family_is_monospace (PangoFontFamily *family) +{ + PangoCoreTextFamily *ctfamily = PANGO_CORE_TEXT_FAMILY (family); + + return ctfamily->is_monospace; +} + +G_DEFINE_TYPE (PangoCoreTextFamily, pango_core_text_family, PANGO_TYPE_FONT_FAMILY); + +static void +pango_core_text_family_finalize (GObject *object) +{ + PangoCoreTextFamily *family = PANGO_CORE_TEXT_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_core_text_family_parent_class)->finalize (object); +} + + +static void +pango_core_text_family_class_init (PangoCoreTextFamilyClass *klass) +{ + GObjectClass *object_class = (GObjectClass *)klass; + int i; + PangoFontFamilyClass *pfclass = PANGO_FONT_FAMILY_CLASS(klass); + + object_class->finalize = pango_core_text_family_finalize; + + pfclass->list_faces = pango_core_text_family_list_faces; + pfclass->get_name = pango_core_text_family_get_name; + pfclass->is_monospace = pango_core_text_family_is_monospace; + + for (i = 0; _pango_included_core_text_modules[i].list; i++) + pango_module_register (&_pango_included_core_text_modules[i]); +} + +static void +pango_core_text_family_init (PangoCoreTextFamily *family) +{ + family->n_faces = -1; +} + +static PangoFontDescription * +pango_core_text_face_describe (PangoFontFace *face) +{ + PangoCoreTextFace *ctface = PANGO_CORE_TEXT_FACE (face); + PangoFontDescription *description; + PangoStyle pango_style; + PangoVariant pango_variant; + + description = pango_font_description_new (); + + pango_font_description_set_family (description, ctface->family->family_name); + + + if (ctface->traits & kCTFontItalicTrait) + pango_style = PANGO_STYLE_ITALIC; + else if (pango_core_text_face_is_oblique (ctface)) + pango_style = PANGO_STYLE_OBLIQUE; + else + pango_style = PANGO_STYLE_NORMAL; + + /* FIXME: How can this be figured using CoreText? */ +#if 0 + if (ctface->traits & NSSmallCapsFontMask) + pango_variant = PANGO_VARIANT_SMALL_CAPS; + else +#endif + pango_variant = PANGO_VARIANT_NORMAL; + + pango_font_description_set_weight (description, ctface->weight); + pango_font_description_set_style (description, pango_style); + pango_font_description_set_variant (description, pango_variant); + + return description; +} + +static const char * +pango_core_text_face_get_face_name (PangoFontFace *face) +{ + PangoCoreTextFace *ctface = PANGO_CORE_TEXT_FACE (face); + + return ctface->style_name; +} + +static void +pango_core_text_face_list_sizes (PangoFontFace *face, + int **sizes, + int *n_sizes) +{ + *n_sizes = 0; + *sizes = NULL; +} + +G_DEFINE_TYPE (PangoCoreTextFace, pango_core_text_face, PANGO_TYPE_FONT_FACE); + +static void +pango_core_text_face_init (PangoCoreTextFace *face) +{ + face->family = NULL; + face->coverage = NULL; +} + + + +static void +pango_core_text_face_finalize (GObject *object) +{ + PangoCoreTextFace *ctface = PANGO_CORE_TEXT_FACE (object); + + if (ctface->coverage) + pango_coverage_unref (ctface->coverage); + + g_free (ctface->postscript_name); + g_free (ctface->style_name); + + G_OBJECT_CLASS (pango_core_text_face_parent_class)->finalize (object); +} + +static gboolean +pango_core_text_face_is_synthesized (PangoFontFace *face) +{ + PangoCoreTextFace *cface = PANGO_CORE_TEXT_FACE (face); + + return cface->synthetic_italic; +} + +static void +pango_core_text_face_class_init (PangoCoreTextFaceClass *klass) +{ + GObjectClass *object_class = (GObjectClass *)klass; + PangoFontFaceClass *pfclass = PANGO_FONT_FACE_CLASS(klass); + + object_class->finalize = pango_core_text_face_finalize; + + pfclass->describe = pango_core_text_face_describe; + pfclass->get_face_name = pango_core_text_face_get_face_name; + pfclass->list_sizes = pango_core_text_face_list_sizes; + pfclass->is_synthesized = pango_core_text_face_is_synthesized; +} + +const char * +_pango_core_text_face_get_postscript_name (PangoCoreTextFace *face) +{ + return face->postscript_name; +} + +gboolean +_pango_core_text_face_get_synthetic_italic (PangoCoreTextFace *face) +{ + return face->synthetic_italic; +} + +PangoCoverage * +_pango_core_text_face_get_coverage (PangoCoreTextFace *face, + PangoLanguage *language) +{ + return face->coverage; +} + +static void pango_core_text_font_map_class_init (PangoCoreTextFontMapClass *class); +static void pango_core_text_font_map_init (PangoCoreTextFontMap *ctfontmap); + +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 (PangoCoreTextFontMap, pango_core_text_font_map, PANGO_TYPE_FONT_MAP); + +static void +pango_core_text_font_map_finalize (GObject *object) +{ + PangoCoreTextFontMap *fontmap = PANGO_CORE_TEXT_FONT_MAP (object); + + g_hash_table_destroy (fontmap->font_hash); + g_hash_table_destroy (fontmap->families); + + G_OBJECT_CLASS (pango_core_text_font_map_parent_class)->finalize (object); +} + +struct _FontHashKey { + PangoCoreTextFontMap *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_CORE_TEXT_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_CORE_TEXT_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_CORE_TEXT_FONT_MAP_GET_CLASS (key->fontmap)->context_key_free (key->fontmap, + key->context_key); + + g_slice_free (FontHashKey, key); +} + +static FontHashKey * +font_hash_key_copy (FontHashKey *old) +{ + FontHashKey *key = g_slice_new (FontHashKey); + + 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_CORE_TEXT_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 (PangoCoreTextFontMap *fcfontmap, + PangoContext *context, + FontHashKey *key) +{ + key->fontmap = fcfontmap; + get_context_matrix (context, &key->matrix); + + if (PANGO_CORE_TEXT_FONT_MAP_GET_CLASS (fcfontmap)->context_key_get) + key->context_key = (gpointer)PANGO_CORE_TEXT_FONT_MAP_GET_CLASS (fcfontmap)->context_key_get (fcfontmap, context); + else + key->context_key = NULL; +} + +static void +pango_core_text_font_map_add (PangoCoreTextFontMap *ctfontmap, + PangoContext *context, + PangoCoreTextFont *ctfont) +{ + FontHashKey key; + FontHashKey *key_copy; + PangoCoreTextFace *face; + + _pango_core_text_font_set_font_map (ctfont, ctfontmap); + + font_hash_key_for_context (ctfontmap, context, &key); + face = _pango_core_text_font_get_face (ctfont); + key.postscript_name = (char *)_pango_core_text_face_get_postscript_name (face); + key.desc = _pango_core_text_font_get_font_description (ctfont); + + key_copy = font_hash_key_copy (&key); + _pango_core_text_font_set_context_key (ctfont, key_copy->context_key); + g_hash_table_insert (ctfontmap->font_hash, key_copy, g_object_ref (ctfont)); +} + +static PangoCoreTextFont * +pango_core_text_font_map_lookup (PangoCoreTextFontMap *ctfontmap, + PangoContext *context, + PangoFontDescription *desc, + PangoCoreTextFace *face) +{ + FontHashKey key; + + font_hash_key_for_context (ctfontmap, context, &key); + key.postscript_name = (char *)_pango_core_text_face_get_postscript_name (face); + key.desc = desc; + + return g_hash_table_lookup (ctfontmap->font_hash, &key); +} + +static gboolean +find_best_match (PangoCoreTextFamily *font_family, + const PangoFontDescription *description, + PangoFontDescription **best_description, + PangoCoreTextFace **best_face) +{ + PangoFontDescription *new_desc; + int i; + + *best_description = NULL; + *best_face = 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_description, new_desc)) + { + pango_font_description_free (*best_description); + *best_description = new_desc; + *best_face = (PangoCoreTextFace *)font_family->faces[i]; + } + else + pango_font_description_free (new_desc); + } + + if (*best_description) + return TRUE; + + return FALSE; +} + +static PangoFont * +pango_core_text_font_map_load_font (PangoFontMap *fontmap, + PangoContext *context, + const PangoFontDescription *description) +{ + PangoCoreTextFontMap *ctfontmap = (PangoCoreTextFontMap *)fontmap; + PangoCoreTextFamily *font_family; + const gchar *family; + gchar *name; + gint size; + gboolean is_absolute; + + size = pango_font_description_get_size (description); + if (size < 0) + return NULL; + + is_absolute = pango_font_description_get_size_is_absolute (description); + + family = pango_font_description_get_family (description); + family = family ? family : ""; + name = g_utf8_casefold (family, -1); + font_family = g_hash_table_lookup (ctfontmap->families, name); + g_free (name); + + if (font_family) + { + PangoFontDescription *best_description; + PangoCoreTextFace *best_face; + PangoCoreTextFont *best_font; + + /* Force a listing of the available faces */ + pango_font_family_list_faces ((PangoFontFamily *)font_family, NULL, NULL); + + if (!find_best_match (font_family, description, &best_description, &best_face)) + return NULL; + + if (is_absolute) + pango_font_description_set_absolute_size (best_description, size); + else + pango_font_description_set_size (best_description, size); + + best_font = pango_core_text_font_map_lookup (ctfontmap, + context, + best_description, + best_face); + + if (best_font) + g_object_ref (best_font); + else + { + PangoCoreTextFontMapClass *klass; + + klass = PANGO_CORE_TEXT_FONT_MAP_GET_CLASS (ctfontmap); + best_font = klass->create_font (ctfontmap, context, + best_face, best_description); + + if (best_font) + pango_core_text_font_map_add (ctfontmap, context, best_font); + /* FIXME: Handle the else case here. */ + } + + pango_font_description_free (best_description); + + return (PangoFont *)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_core_text_font_map_list_families (PangoFontMap *fontmap, + PangoFontFamily ***families, + int *n_families) +{ + GSList *family_list = NULL; + GSList *tmp_list; + PangoCoreTextFontMap *ctfontmap = (PangoCoreTextFontMap *)fontmap; + + if (!n_families) + return; + + g_hash_table_foreach (ctfontmap->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_core_text_font_map_init (PangoCoreTextFontMap *ctfontmap) +{ + PangoCoreTextFamily *family; + CTFontCollectionRef collection; + CFArrayRef ctfaces; + CFIndex i, count; + + ctfontmap->families = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, g_object_unref); + + + ctfontmap->font_hash = g_hash_table_new_full ((GHashFunc)font_hash_key_hash, + (GEqualFunc)font_hash_key_equal, + (GDestroyNotify)font_hash_key_free, + NULL); + + collection = CTFontCollectionCreateFromAvailableFonts (0); + ctfaces = CTFontCollectionCreateMatchingFontDescriptors (collection); + count = CFArrayGetCount (ctfaces); + + for (i = 0; i < count; i++) + { + int font_traits; + char *buffer; + char *family_name; + CFStringRef str; + CFNumberRef number; + CFDictionaryRef dict; + CTFontDescriptorRef desc = CFArrayGetValueAtIndex (ctfaces, i); + + str = CTFontDescriptorCopyAttribute (desc, kCTFontFamilyNameAttribute); + buffer = gchar_from_cf_string (str); + + family_name = g_utf8_casefold (buffer, -1); + + family = g_hash_table_lookup (ctfontmap->families, family_name); + if (!family) + { + family = g_object_new (PANGO_TYPE_CORE_TEXT_FAMILY, NULL); + g_hash_table_insert (ctfontmap->families, g_strdup (family_name), + family); + + family->family_name = g_strdup (buffer); + } + + CFRelease (str); + g_free (buffer); + + g_free (family_name); + + /* We assume that all faces in the family are monospaced or none. */ + dict = CTFontDescriptorCopyAttribute (desc, kCTFontTraitsAttribute); + number = (CFNumberRef)CFDictionaryGetValue (dict, + kCTFontSymbolicTrait); + + if (CFNumberGetValue (number, kCFNumberIntType, &font_traits)) + { + if (font_traits & kCTFontMonoSpaceTrait) + family->is_monospace = TRUE; + } + + CFRelease (dict); + } + + /* Insert aliases */ + family = g_object_new (PANGO_TYPE_CORE_TEXT_FAMILY, NULL); + family->family_name = g_strdup ("Sans"); + g_hash_table_insert (ctfontmap->families, + g_utf8_casefold (family->family_name, -1), family); + + family = g_object_new (PANGO_TYPE_CORE_TEXT_FAMILY, NULL); + family->family_name = g_strdup ("Serif"); + g_hash_table_insert (ctfontmap->families, + g_utf8_casefold (family->family_name, -1), family); + + family = g_object_new (PANGO_TYPE_CORE_TEXT_FAMILY, NULL); + family->family_name = g_strdup ("Monospace"); + family->is_monospace = TRUE; + g_hash_table_insert (ctfontmap->families, + g_utf8_casefold (family->family_name, -1), family); +} + +static void +pango_core_text_font_map_class_init (PangoCoreTextFontMapClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + PangoFontMapClass *fontmap_class = PANGO_FONT_MAP_CLASS (class); + + object_class->finalize = pango_core_text_font_map_finalize; + + fontmap_class->load_font = pango_core_text_font_map_load_font; + fontmap_class->list_families = pango_core_text_font_map_list_families; + fontmap_class->shape_engine_type = PANGO_RENDER_TYPE_CORE_TEXT; +} diff --git a/pango/pangocoretext-private.h b/pango/pangocoretext-private.h new file mode 100644 index 00000000..4ed0e8e5 --- /dev/null +++ b/pango/pangocoretext-private.h @@ -0,0 +1,102 @@ +/* Pango + * pangocoretext-private.h: + * + * Copyright (C) 2003 Red Hat Software + * Copyright (C) 2005-2007 Imendio AB + * Copyright (C) 2010 Kristian Rietveld <kris@gtk.org> + * + * 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 __PANGOCORETEXT_PRIVATE_H__ +#define __PANGOCORETEXT_PRIVATE_H__ + +#include <pango/pango-fontmap.h> +#include <pango/pango-context.h> +#include "pangocoretext.h" + +G_BEGIN_DECLS + +#define PANGO_TYPE_CORE_TEXT_FONT_MAP (pango_core_text_font_map_get_type ()) +#define PANGO_CORE_TEXT_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_CORE_TEXT_FONT_MAP, PangoCoreTextFontMap)) +#define PANGO_CORE_TEXT_IS_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_CORE_TEXT_FONT_MAP)) +#define PANGO_CORE_TEXT_FONT_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_CORE_TEXT_FONT_MAP, PangoCoreTextFontMapClass)) +#define PANGO_IS_CORE_TEXT_FONT_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_CORE_TEXT_FONT_MAP)) +#define PANGO_CORE_TEXT_FONT_MAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_CORE_TEXT_FONT_MAP, PangoCoreTextFontMapClass)) + + +typedef struct _PangoCoreTextFamily PangoCoreTextFamily; +typedef struct _PangoCoreTextFace PangoCoreTextFace; + +typedef struct _PangoCoreTextFontMap PangoCoreTextFontMap; +typedef struct _PangoCoreTextFontMapClass PangoCoreTextFontMapClass; + +struct _PangoCoreTextFontMap +{ + PangoFontMap parent_instance; + + GHashTable *font_hash; + + GHashTable *families; +}; + +struct _PangoCoreTextFontMapClass +{ + PangoFontMapClass parent_class; + + gconstpointer (*context_key_get) (PangoCoreTextFontMap *ctfontmap, + PangoContext *context); + gpointer (*context_key_copy) (PangoCoreTextFontMap *ctfontmap, + gconstpointer key); + void (*context_key_free) (PangoCoreTextFontMap *ctfontmap, + gpointer key); + guint32 (*context_key_hash) (PangoCoreTextFontMap *ctfontmap, + gconstpointer key); + gboolean (*context_key_equal) (PangoCoreTextFontMap *ctfontmap, + gconstpointer key_a, + gconstpointer key_b); + + PangoCoreTextFont * (* create_font) (PangoCoreTextFontMap *fontmap, + PangoContext *context, + PangoCoreTextFace *face, + const PangoFontDescription *desc); +}; + + +GType pango_core_text_font_map_get_type (void) G_GNUC_CONST; + +const char * _pango_core_text_face_get_postscript_name (PangoCoreTextFace *face); +gboolean _pango_core_text_face_get_synthetic_italic (PangoCoreTextFace *face); +PangoCoverage * _pango_core_text_face_get_coverage (PangoCoreTextFace *face, + PangoLanguage *language); + +void _pango_core_text_font_set_font_description (PangoCoreTextFont *afont, + const PangoFontDescription *desc); +PangoFontDescription *_pango_core_text_font_get_font_description (PangoCoreTextFont *afont); +void _pango_core_text_font_set_font_map (PangoCoreTextFont *afont, + PangoCoreTextFontMap *fontmap); +void _pango_core_text_font_set_face (PangoCoreTextFont *afont, + PangoCoreTextFace *aface); +PangoCoreTextFace * _pango_core_text_font_get_face (PangoCoreTextFont *font); +gpointer _pango_core_text_font_get_context_key (PangoCoreTextFont *afont); +void _pango_core_text_font_set_context_key (PangoCoreTextFont *afont, + gpointer context_key); +void _pango_core_text_font_set_ctfont (PangoCoreTextFont *font, + CTFontRef font_ref); + +G_END_DECLS + +#endif /* __PANGOCORETEXT_PRIVATE_H__ */ diff --git a/pango/pangocoretext.c b/pango/pangocoretext.c new file mode 100644 index 00000000..36e5a373 --- /dev/null +++ b/pango/pangocoretext.c @@ -0,0 +1,204 @@ +/* Pango + * pangocoretext.c + * + * Copyright (C) 2005-2007 Imendio AB + * Copyright (C) 2010 Kristian Rietveld <kris@gtk.org> + * + * 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 "config.h" + +#include "pangocoretext.h" +#include "pangocoretext-private.h" + +G_DEFINE_TYPE (PangoCoreTextFont, pango_core_text_font, PANGO_TYPE_FONT); + +struct _PangoCoreTextFontPrivate +{ + PangoCoreTextFace *face; + PangoFontDescription *desc; + gpointer context_key; + + CTFontRef font_ref; + + PangoFontMap *fontmap; +}; + +static void +pango_core_text_font_finalize (GObject *object) +{ + PangoCoreTextFont *ctfont = (PangoCoreTextFont *)object; + PangoCoreTextFontPrivate *priv = ctfont->priv; + + pango_font_description_free (priv->desc); + + g_assert (priv->fontmap != NULL); + g_object_remove_weak_pointer (G_OBJECT (priv->fontmap), (gpointer *) (gpointer) &priv->fontmap); + priv->fontmap = NULL; + + G_OBJECT_CLASS (pango_core_text_font_parent_class)->finalize (object); +} + +static PangoFontDescription * +pango_core_text_font_describe (PangoFont *font) +{ + PangoCoreTextFont *ctfont = (PangoCoreTextFont *)font; + PangoCoreTextFontPrivate *priv = ctfont->priv; + + return pango_font_description_copy (priv->desc); +} + +static PangoCoverage * +pango_core_text_font_get_coverage (PangoFont *font, + PangoLanguage *language) +{ + PangoCoreTextFont *ctfont = (PangoCoreTextFont *)font; + PangoCoreTextFontPrivate *priv = ctfont->priv; + + return pango_coverage_ref (_pango_core_text_face_get_coverage (priv->face, + language)); +} + +static PangoEngineShape * +pango_core_text_font_find_shaper (PangoFont *font, + PangoLanguage *language, + guint32 ch) +{ + /* FIXME: Implement */ + return NULL; +} + +static PangoFontMap * +pango_core_text_font_get_font_map (PangoFont *font) +{ + PangoCoreTextFont *ctfont = (PangoCoreTextFont *)font; + + return ctfont->priv->fontmap; +} + +static void +pango_core_text_font_init (PangoCoreTextFont *ctfont) +{ + ctfont->priv = G_TYPE_INSTANCE_GET_PRIVATE (ctfont, + PANGO_TYPE_CORE_TEXT_FONT, + PangoCoreTextFontPrivate); +} + +static void +pango_core_text_font_class_init (PangoCoreTextFontClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + PangoFontClass *font_class = PANGO_FONT_CLASS (class); + + object_class->finalize = pango_core_text_font_finalize; + + font_class->describe = pango_core_text_font_describe; + font_class->get_coverage = pango_core_text_font_get_coverage; + font_class->find_shaper = pango_core_text_font_find_shaper; + font_class->get_font_map = pango_core_text_font_get_font_map; + + g_type_class_add_private (object_class, sizeof (PangoCoreTextFontPrivate)); +} + +void +_pango_core_text_font_set_font_description (PangoCoreTextFont *font, + const PangoFontDescription *desc) +{ + PangoCoreTextFontPrivate *priv = font->priv; + + priv->desc = pango_font_description_copy (desc); +} + +PangoFontDescription * +_pango_core_text_font_get_font_description (PangoCoreTextFont *font) +{ + PangoCoreTextFontPrivate *priv = font->priv; + + return priv->desc; +} + +void +_pango_core_text_font_set_font_map (PangoCoreTextFont *font, + PangoCoreTextFontMap *fontmap) +{ + PangoCoreTextFontPrivate *priv = font->priv; + + g_assert (priv->fontmap == NULL); + priv->fontmap = (PangoFontMap *) fontmap; + g_object_add_weak_pointer (G_OBJECT (priv->fontmap), (gpointer *) (gpointer) &priv->fontmap); +} + +void +_pango_core_text_font_set_face (PangoCoreTextFont *ctfont, + PangoCoreTextFace *ctface) +{ + PangoCoreTextFontPrivate *priv = ctfont->priv; + + priv->face = ctface; +} + +PangoCoreTextFace * +_pango_core_text_font_get_face (PangoCoreTextFont *font) +{ + PangoCoreTextFontPrivate *priv = font->priv; + + return priv->face; +} + +gpointer +_pango_core_text_font_get_context_key (PangoCoreTextFont *font) +{ + PangoCoreTextFontPrivate *priv = font->priv; + + return priv->context_key; +} + +void +_pango_core_text_font_set_context_key (PangoCoreTextFont *font, + gpointer context_key) +{ + PangoCoreTextFontPrivate *priv = font->priv; + + priv->context_key = context_key; +} + +void +_pango_core_text_font_set_ctfont (PangoCoreTextFont *font, + CTFontRef font_ref) +{ + PangoCoreTextFontPrivate *priv = font->priv; + + priv->font_ref = font_ref; +} + +/** + * pango_core_text_font_get_ctfont: + * @font: A #PangoCoreTextFont + * + * Returns the CTFontRef of a font. + * + * Return value: the CTFontRef associated to @font. + * + * Since: 1.24 + */ +CTFontRef +pango_core_text_font_get_ctfont (PangoCoreTextFont *font) +{ + PangoCoreTextFontPrivate *priv = font->priv; + + return priv->font_ref; +} diff --git a/pango/pangocoretext.h b/pango/pangocoretext.h new file mode 100644 index 00000000..22dd9cb0 --- /dev/null +++ b/pango/pangocoretext.h @@ -0,0 +1,80 @@ +/* Pango + * pangocoretext.h: + * + * Copyright (C) 2005 Imendio AB + * Copyright (C) 2010 Kristian Rietveld <kris@gtk.org> + * + * 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 __PANGOCORETEXT_H__ +#define __PANGOCORETEXT_H__ + +#include <pango/pango-context.h> +#include <pango/pango-font.h> +#include <Carbon/Carbon.h> + +G_BEGIN_DECLS + +#define PANGO_TYPE_CORE_TEXT_FONT (pango_core_text_font_get_type ()) +#define PANGO_CORE_TEXT_FONT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_CORE_TEXT_FONT, PangoCoreTextFont)) +#define PANGO_IS_CORE_TEXT_FONT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_CORE_TEXT_FONT)) + +typedef struct _PangoCoreTextFont PangoCoreTextFont; +typedef struct _PangoCoreTextFontClass PangoCoreTextFontClass; + +#if defined(PANGO_ENABLE_ENGINE) || defined(PANGO_ENABLE_BACKEND) + +#define PANGO_RENDER_TYPE_CORE_TEXT "PangoRenderCoreText" + +#ifdef PANGO_ENABLE_BACKEND + +#define PANGO_CORE_TEXT_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_CORE_TEXT_FONT, PangoCoreTextFontClass)) +#define PANGO_IS_CORE_TEXT_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_CORE_TEXT_FONT)) +#define PANGO_CORE_TEXT_FONT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_CORE_TEXT_FONT, PangoCoreTextFontClass)) + +typedef struct _PangoCoreTextFontPrivate PangoCoreTextFontPrivate; + +struct _PangoCoreTextFont +{ + PangoFont parent_instance; + PangoCoreTextFontPrivate *priv; +}; + +struct _PangoCoreTextFontClass +{ + PangoFontClass parent_class; + + /*< private >*/ + + /* Padding for future expansion */ + void (*_pango_reserved1) (void); + void (*_pango_reserved2) (void); + void (*_pango_reserved3) (void); + void (*_pango_reserved4) (void); +}; + +#endif /* PANGO_ENABLE_BACKEND */ + +CTFontRef pango_core_text_font_get_ctfont (PangoCoreTextFont *font); + +#endif /* PANGO_ENABLE_ENGINE || PANGO_ENABLE_BACKEND */ + +GType pango_core_text_font_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* __PANGOCORETEXT_H__ */ diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index 5211361a..23489684 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -790,7 +790,6 @@ pango_fc_patterns_get_font_pattern (PangoFcPatterns *pats, int i) */ static void pango_fc_fontset_finalize (GObject *object); -static void pango_fc_fontset_init (PangoFcFontset *fontset); static PangoLanguage * pango_fc_fontset_get_language (PangoFontset *fontset); static PangoFont * pango_fc_fontset_get_font (PangoFontset *fontset, guint wc); @@ -814,8 +813,7 @@ struct _PangoFcFontset }; typedef PangoFontsetClass PangoFcFontsetClass; - -static PangoFontsetClass *fc_fontset_parent_class; /* Parent class structure for PangoFcFontset */ +G_DEFINE_TYPE (PangoFcFontset, pango_fc_fontset, PANGO_TYPE_FONTSET); static PangoFcFontset * pango_fc_fontset_new (PangoFcFontsetKey *key, @@ -892,9 +890,8 @@ pango_fc_fontset_class_init (PangoFcFontsetClass *class) GObjectClass *object_class = G_OBJECT_CLASS (class); PangoFontsetClass *fontset_class = PANGO_FONTSET_CLASS (class); - fc_fontset_parent_class = g_type_class_peek_parent (class); - object_class->finalize = pango_fc_fontset_finalize; + fontset_class->get_font = pango_fc_fontset_get_font; fontset_class->get_language = pango_fc_fontset_get_language; fontset_class->foreach = pango_fc_fontset_foreach; @@ -935,7 +932,7 @@ pango_fc_fontset_finalize (GObject *object) if (fontset->patterns) pango_fc_patterns_unref (fontset->patterns); - G_OBJECT_CLASS (fc_fontset_parent_class)->finalize (object); + G_OBJECT_CLASS (pango_fc_fontset_parent_class)->finalize (object); } static PangoLanguage * @@ -1008,9 +1005,6 @@ pango_fc_fontset_foreach (PangoFontset *fontset, } } -static PANGO_DEFINE_TYPE (PangoFcFontset, pango_fc_fontset, - pango_fc_fontset_class_init, pango_fc_fontset_init, - PANGO_TYPE_FONTSET) /* * PangoFcFontMap @@ -2180,7 +2174,8 @@ pango_fc_font_description_from_pattern (FcPattern *pattern, gboolean include_siz * PangoFcFace */ -static GObjectClass *pango_fc_face_parent_class = NULL; +typedef PangoFontFaceClass PangoFcFaceClass; +G_DEFINE_TYPE (PangoFcFace, pango_fc_face, PANGO_TYPE_FONT_FACE); static PangoFontDescription * make_alias_description (PangoFcFamily *fcfamily, @@ -2359,17 +2354,19 @@ pango_fc_face_finalize (GObject *object) g_free (fcface->style); - pango_fc_face_parent_class->finalize (object); + G_OBJECT_CLASS (pango_fc_face_parent_class)->finalize (object); } -typedef PangoFontFaceClass PangoFcFaceClass; +static void +pango_fc_face_init (PangoFcFace *self) +{ +} static void pango_fc_face_class_init (PangoFcFaceClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); - pango_fc_face_parent_class = g_type_class_peek_parent (class); object_class->finalize = pango_fc_face_finalize; class->describe = pango_fc_face_describe; @@ -2378,15 +2375,13 @@ pango_fc_face_class_init (PangoFcFaceClass *class) class->is_synthesized = pango_fc_face_is_synthesized; } -static PANGO_DEFINE_TYPE (PangoFcFace, pango_fc_face, - pango_fc_face_class_init, NULL, - PANGO_TYPE_FONT_FACE) /* * PangoFcFamily */ -static GObjectClass *pango_fc_family_parent_class = NULL; +typedef PangoFontFamilyClass PangoFcFamilyClass; +G_DEFINE_TYPE (PangoFcFamily, pango_fc_family, PANGO_TYPE_FONT_FAMILY); static PangoFcFace * create_face (PangoFcFamily *fcfamily, @@ -2567,17 +2562,14 @@ pango_fc_family_finalize (GObject *object) } g_free (fcfamily->faces); - pango_fc_family_parent_class->finalize (object); + G_OBJECT_CLASS (pango_fc_family_parent_class)->finalize (object); } -typedef PangoFontFamilyClass PangoFcFamilyClass; - static void pango_fc_family_class_init (PangoFcFamilyClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); - pango_fc_family_parent_class = g_type_class_peek_parent (class); object_class->finalize = pango_fc_family_finalize; class->list_faces = pango_fc_family_list_faces; @@ -2590,7 +2582,3 @@ pango_fc_family_init (PangoFcFamily *fcfamily) { fcfamily->n_faces = -1; } - -static PANGO_DEFINE_TYPE (PangoFcFamily, pango_fc_family, - pango_fc_family_class_init, pango_fc_family_init, - PANGO_TYPE_FONT_FAMILY) diff --git a/pango/pangoft2.c b/pango/pangoft2.c index f4a3864b..b41c468a 100644 --- a/pango/pangoft2.c +++ b/pango/pangoft2.c @@ -520,7 +520,7 @@ ft_error_compare (const void *pkey, return ((ft_error_description *) pkey)->code - ((ft_error_description *) pbase)->code; } -G_CONST_RETURN char * +const char * _pango_ft2_ft_strerror (FT_Error error) { #undef __FTERRORS_H__ diff --git a/pango/pangox-fontmap.c b/pango/pangox-fontmap.c index 6d5e547e..30946452 100644 --- a/pango/pangox-fontmap.c +++ b/pango/pangox-fontmap.c @@ -41,6 +41,7 @@ #include "pangox-private.h" typedef struct _PangoXFamily PangoXFamily; +typedef struct _PangoXFamilyClass PangoXFamilyClass; typedef struct _PangoXSizeInfo PangoXSizeInfo; /* Number of freed fonts */ @@ -79,6 +80,11 @@ struct _PangoXFamily GSList *font_entries; }; +struct _PangoXFamilyClass +{ + PangoFontFamilyClass parent_class; +}; + struct _PangoXFace { PangoFontFace parent_instance; @@ -133,9 +139,6 @@ static const struct { { "condensed", PANGO_STRETCH_CONDENSED }, }; -static void pango_x_font_map_init (PangoXFontMap *fontmap); -static void pango_x_font_map_class_init (PangoFontMapClass *class); - static void pango_x_font_map_finalize (GObject *object); static PangoFont *pango_x_font_map_load_font (PangoFontMap *fontmap, PangoContext *context, @@ -171,37 +174,7 @@ GType pango_x_family_get_type (void); GType pango_x_face_get_type (void); - -static PangoFontClass *font_map_parent_class; /* Parent class structure for PangoXFontMap */ - -GType -pango_x_font_map_get_type (void) -{ - static GType object_type = 0; - - if (G_UNLIKELY (!object_type)) - { - const GTypeInfo object_info = - { - sizeof (PangoFontMapClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) pango_x_font_map_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (PangoXFontMap), - 0, /* n_preallocs */ - (GInstanceInitFunc) pango_x_font_map_init, - NULL /* value_table */ - }; - - object_type = g_type_register_static (PANGO_TYPE_FONT_MAP, - I_("PangoXFontMap"), - &object_info, 0); - } - - return object_type; -} +G_DEFINE_TYPE (PangoXFontMap, pango_x_font_map, PANGO_TYPE_FONT_MAP); static void pango_x_font_map_init (PangoXFontMap *xfontmap) @@ -214,16 +187,16 @@ pango_x_font_map_init (PangoXFontMap *xfontmap) } static void -pango_x_font_map_class_init (PangoFontMapClass *class) +pango_x_font_map_class_init (PangoXFontMapClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); - - font_map_parent_class = g_type_class_peek_parent (class); + PangoFontMapClass *font_map_class = PANGO_FONT_MAP_CLASS (class); object_class->finalize = pango_x_font_map_finalize; - class->load_font = pango_x_font_map_load_font; - class->list_families = pango_x_font_map_list_families; - class->shape_engine_type = PANGO_RENDER_TYPE_X; + + font_map_class->load_font = pango_x_font_map_load_font; + font_map_class->list_families = pango_x_font_map_list_families; + font_map_class->shape_engine_type = PANGO_RENDER_TYPE_X; } /* @@ -393,7 +366,7 @@ pango_x_font_map_finalize (GObject *object) fontmaps = g_list_remove (fontmaps, xfontmap); - G_OBJECT_CLASS (font_map_parent_class)->finalize (object); + G_OBJECT_CLASS (pango_x_font_map_parent_class)->finalize (object); } static void @@ -1441,7 +1414,7 @@ pango_x_fontmap_atom_from_name (PangoFontMap *fontmap, } -G_CONST_RETURN char * +const char * pango_x_fontmap_name_from_atom (PangoFontMap *fontmap, Atom atom) { @@ -1494,40 +1467,19 @@ pango_x_face_get_face_name (PangoFontFace *face) return xface->face_name; } +typedef PangoFontFaceClass PangoXFaceClass; +G_DEFINE_TYPE (PangoXFace, pango_x_face, PANGO_TYPE_FONT_FACE); + static void -pango_x_face_class_init (PangoFontFaceClass *class) +pango_x_face_class_init (PangoXFaceClass *class) { class->describe = pango_x_face_describe; class->get_face_name = pango_x_face_get_face_name; } -GType -pango_x_face_get_type (void) +static void +pango_x_face_init (PangoXFace *self) { - static GType object_type = 0; - - if (G_UNLIKELY (!object_type)) - { - const GTypeInfo object_info = - { - sizeof (PangoFontFaceClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) pango_x_face_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (PangoXFace), - 0, /* n_preallocs */ - (GInstanceInitFunc) NULL, - NULL /* value_table */ - }; - - object_type = g_type_register_static (PANGO_TYPE_FONT_FACE, - I_("PangoXFace"), - &object_info, 0); - } - - return object_type; } /* Cut and paste here to avoid an inter-module dependency */ @@ -1645,7 +1597,7 @@ pango_x_family_list_faces (PangoFontFamily *family, } } -static G_CONST_RETURN char * +static const char * pango_x_family_get_name (PangoFontFamily *family) { PangoXFamily *xfamily = PANGO_X_FAMILY (family); @@ -1653,39 +1605,18 @@ pango_x_family_get_name (PangoFontFamily *family) return xfamily->family_name; } +G_DEFINE_TYPE (PangoXFamily, pango_x_family, PANGO_TYPE_FONT_FAMILY); + static void -pango_x_family_class_init (PangoFontFamilyClass *class) +pango_x_family_class_init (PangoXFamilyClass *klass) { - class->list_faces = pango_x_family_list_faces; - class->get_name = pango_x_family_get_name; + PangoFontFamilyClass *font_family_class = PANGO_FONT_FAMILY_CLASS (klass); + + font_family_class->list_faces = pango_x_family_list_faces; + font_family_class->get_name = pango_x_family_get_name; } -GType -pango_x_family_get_type (void) +static void +pango_x_family_init (PangoXFamily *self) { - static GType object_type = 0; - - if (G_UNLIKELY (!object_type)) - { - const GTypeInfo object_info = - { - sizeof (PangoFontFamilyClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) pango_x_family_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (PangoXFamily), - 0, /* n_preallocs */ - (GInstanceInitFunc) NULL, - NULL /* value_table */ - }; - - object_type = g_type_register_static (PANGO_TYPE_FONT_FAMILY, - I_("PangoXFamily"), - &object_info, 0); - } - - return object_type; } - diff --git a/pango/pangox-private.h b/pango/pangox-private.h index b3a9c8f3..e28ab8b7 100644 --- a/pango/pangox-private.h +++ b/pango/pangox-private.h @@ -92,6 +92,11 @@ struct _PangoXFontMap Window coverage_win; }; +struct _PangoXFontMapClass +{ + PangoFontMapClass parent_class; +}; + GType pango_x_font_map_get_type (void) G_GNUC_CONST; PangoXFont * pango_x_font_new (PangoFontMap *fontmap, diff --git a/pango/pangox.c b/pango/pangox.c index c49024f0..24bca5ea 100644 --- a/pango/pangox.c +++ b/pango/pangox.c @@ -69,10 +69,6 @@ struct _PangoXFontClass PangoFontClass parent_class; }; -static PangoFontClass *parent_class; /* Parent class structure for PangoXFont */ - -static void pango_x_font_class_init (PangoXFontClass *class); -static void pango_x_font_init (PangoXFont *xfont); static void pango_x_font_dispose (GObject *object); static void pango_x_font_finalize (GObject *object); @@ -224,34 +220,7 @@ pango_x_context_set_funcs (PangoContext *context, info->free_gc_func = free_gc_func; } -static GType -pango_x_font_get_type (void) -{ - static GType object_type = 0; - - if (G_UNLIKELY (!object_type)) - { - const GTypeInfo object_info = - { - sizeof (PangoXFontClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) pango_x_font_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (PangoXFont), - 0, /* n_preallocs */ - (GInstanceInitFunc) pango_x_font_init, - NULL /* value_table */ - }; - - object_type = g_type_register_static (PANGO_TYPE_FONT, - I_("PangoXFont"), - &object_info, 0); - } - - return object_type; -} +G_DEFINE_TYPE (PangoXFont, pango_x_font, PANGO_TYPE_FONT); static void pango_x_font_init (PangoXFont *xfont) @@ -275,8 +244,6 @@ pango_x_font_class_init (PangoXFontClass *class) GObjectClass *object_class = G_OBJECT_CLASS (class); PangoFontClass *font_class = PANGO_FONT_CLASS (class); - parent_class = g_type_class_peek_parent (class); - object_class->finalize = pango_x_font_finalize; object_class->dispose = pango_x_font_dispose; @@ -1271,7 +1238,7 @@ pango_x_font_dispose (GObject *object) if (!xfont->in_cache && xfont->fontmap) pango_x_fontmap_cache_add (xfont->fontmap, xfont); - G_OBJECT_CLASS (parent_class)->dispose (object); + G_OBJECT_CLASS (pango_x_font_parent_class)->dispose (object); } @@ -1326,7 +1293,7 @@ pango_x_font_finalize (GObject *object) g_strfreev (xfont->fonts); - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS (pango_x_font_parent_class)->finalize (object); } static PangoFontDescription * diff --git a/pango/pangox.def b/pango/pangox.def index e70ca70c..36d7e3f4 100644 --- a/pango/pangox.def +++ b/pango/pangox.def @@ -11,6 +11,7 @@ pango_x_font_cache_free pango_x_font_cache_load pango_x_font_cache_new pango_x_font_cache_unload +pango_x_font_get_type pango_x_font_get_unknown_glyph pango_x_font_map_for_display pango_x_font_map_get_font_cache diff --git a/pango/pangoxft-fontmap.c b/pango/pangoxft-fontmap.c index 2feb4982..3e6034e9 100644 --- a/pango/pangoxft-fontmap.c +++ b/pango/pangoxft-fontmap.c @@ -176,7 +176,7 @@ register_display (Display *display) * The fontmap is owned by Pango and will be valid until * the display is closed. * - * Return value: a #PangoFontMap object, owned by Pango. + * Return value: (transfer none): a #PangoFontMap object, owned by Pango. * * Since: 1.2 **/ @@ -310,7 +310,7 @@ _pango_xft_font_map_get_info (PangoFontMap *fontmap, } /** - * pango_xft_get_context: + * pango_xft_get_context: (skip) * @display: an X display. * @screen: an X screen. * diff --git a/pango/reorder-items.c b/pango/reorder-items.c index 25433509..73342248 100644 --- a/pango/reorder-items.c +++ b/pango/reorder-items.c @@ -37,7 +37,8 @@ static GList *reorder_items_recurse (GList *items, int n_items); * directional levels, produce a list in visual order. * The original list is unmodified. * - * Returns: a #GList of #PangoItem structures in visual order. + * Returns: (transfer full) (element-type Pango.Item): a #GList + * of #PangoItem structures in visual order. * * (Please open a bug if you use this function. * It is not a particularly convenient interface, and the code |