📄 pango-context.c
字号:
/* Pango * pango-context.c: Contexts for itemization and shaping * * Copyright (C) 2000, 2006 Red Hat Software * * 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 <string.h>#include <stdlib.h>#include "pango-context.h"#include "pango-impl-utils.h"#include "pango-engine.h"#include "pango-engine-private.h"#include "pango-modules.h"struct _PangoContext{ GObject parent_instance; PangoLanguage *language; PangoDirection base_dir; PangoGravity base_gravity; PangoGravity resolved_gravity; PangoGravityHint gravity_hint; PangoFontDescription *font_desc; PangoMatrix *matrix; PangoFontMap *font_map;};struct _PangoContextClass{ GObjectClass parent_class;};static void pango_context_finalize (GObject *object);G_DEFINE_TYPE (PangoContext, pango_context, G_TYPE_OBJECT)static voidpango_context_init (PangoContext *context){ context->base_dir = PANGO_DIRECTION_WEAK_LTR; context->resolved_gravity = context->base_gravity = PANGO_GRAVITY_SOUTH; context->gravity_hint = PANGO_GRAVITY_HINT_NATURAL; context->language = NULL; context->font_map = NULL; context->font_desc = pango_font_description_new (); pango_font_description_set_family_static (context->font_desc, "serif"); pango_font_description_set_style (context->font_desc, PANGO_STYLE_NORMAL); pango_font_description_set_variant (context->font_desc, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (context->font_desc, PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (context->font_desc, PANGO_STRETCH_NORMAL); pango_font_description_set_size (context->font_desc, 12 * PANGO_SCALE);}static voidpango_context_class_init (PangoContextClass *klass){ GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = pango_context_finalize;}static voidpango_context_finalize (GObject *object){ PangoContext *context; context = PANGO_CONTEXT (object); if (context->font_map) g_object_unref (context->font_map); pango_font_description_free (context->font_desc); if (context->matrix) pango_matrix_free (context->matrix); G_OBJECT_CLASS (pango_context_parent_class)->finalize (object);}/** * pango_context_new: * * Creates a new #PangoContext initialized to default value. * * This function is only useful when implementing a new backend * for Pango, something applications won't do. You should use * the context creation function for the backend you are using, * for example, pango_cairo_font_map_create_context(), pango_xft_get_context(), * pango_win32_get_context() or, pango_ft2_font_map_create_context(). * * If you are using Pango as part of a higher-level system, * that system may have it's own ways of create a #PangoContext. * For instance, the GTK+ toolkit has, among others, * gdk_pango_context_get_for_screen(), and * gtk_widget_get_pango_context(). * * Return value: the newly allocated #PangoContext, which should * be freed with g_object_unref(). **/PangoContext *pango_context_new (void){ PangoContext *context; context = g_object_new (PANGO_TYPE_CONTEXT, NULL); return context;}static voidupdate_resolved_gravity (PangoContext *context){ if (context->base_gravity == PANGO_GRAVITY_AUTO) context->resolved_gravity = pango_gravity_get_for_matrix (context->matrix); else context->resolved_gravity = context->base_gravity;}/** * 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.) * * Sets the transformation matrix that will be applied when rendering * with this context. Note that reported metrics are in the user space * coordinates before the application of the matrix, not device-space * coordinates after the application of the matrix. So, they don't scale * with the matrix, though they may change slightly for different * matrices, depending on how the text is fit to the pixel grid. * * Since: 1.6 **/voidpango_context_set_matrix (PangoContext *context, const PangoMatrix *matrix){ g_return_if_fail (PANGO_IS_CONTEXT (context)); if (context->matrix) pango_matrix_free (context->matrix); if (matrix) context->matrix = pango_matrix_copy (matrix); else context->matrix = NULL; update_resolved_gravity (context);}/** * pango_context_get_matrix: * @context: a #PangoContext * * Gets the transformation matrix that will be applied when * rendering with this context. See pango_context_set_matrix(). * * Return value: the matrix, or %NULL if no matrix has been set * (which is the same as the identity matrix). The returned * matrix is owned by Pango and must not be modified or * freed. * * Since: 1.6 **/G_CONST_RETURN PangoMatrix *pango_context_get_matrix (PangoContext *context){ g_return_val_if_fail (PANGO_IS_CONTEXT (context), NULL); return context->matrix;}/** * pango_context_set_font_map: * @context: a #PangoContext * @font_map: the #PangoFontMap to set. * * Sets the font map to be searched when fonts are looked-up in this context. * This is only for internal use by Pango backends, a #PangoContext obtained * via one of the recommended methods should already have a suitable font map. **/voidpango_context_set_font_map (PangoContext *context, PangoFontMap *font_map){ g_return_if_fail (PANGO_IS_CONTEXT (context)); g_return_if_fail (!font_map || PANGO_IS_FONT_MAP (font_map)); if (font_map) g_object_ref (font_map); if (context->font_map) g_object_unref (context->font_map); context->font_map = font_map;}/** * pango_context_get_font_map: * @context: a #PangoContext * * 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. * * Since: 1.6 **/PangoFontMap *pango_context_get_font_map (PangoContext *context){ g_return_val_if_fail (PANGO_IS_CONTEXT (context), NULL); return context->font_map;}/** * 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 * * List all families for a context. **/voidpango_context_list_families (PangoContext *context, PangoFontFamily ***families, int *n_families){ g_return_if_fail (context != NULL); g_return_if_fail (families == NULL || n_families != NULL); if (n_families == NULL) return; if (context->font_map == NULL) { *n_families = 0; if (families) *families = NULL; return; } else pango_font_map_list_families (context->font_map, families, n_families);}/** * pango_context_load_font: * @context: a #PangoContext * @desc: a #PangoFontDescription describing the font to load * * 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. **/PangoFont *pango_context_load_font (PangoContext *context, const PangoFontDescription *desc){ g_return_val_if_fail (context != NULL, NULL); g_return_val_if_fail (pango_font_description_get_family (desc) != NULL, NULL); return pango_font_map_load_font (context->font_map, context, desc);}/** * pango_context_load_fontset: * @context: a #PangoContext * @desc: a #PangoFontDescription describing the fonts to load * @language: a #PangoLanguage the fonts will be used for * * 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. **/PangoFontset *pango_context_load_fontset (PangoContext *context, const PangoFontDescription *desc, PangoLanguage *language){ g_return_val_if_fail (context != NULL, NULL); g_return_val_if_fail (pango_font_description_get_family (desc) != NULL, NULL); g_return_val_if_fail (pango_font_description_get_size (desc) != 0, NULL); return pango_font_map_load_fontset (context->font_map, context, desc, language);}/** * pango_context_set_font_description: * @context: a #PangoContext * @desc: the new pango font description * * Set the default font description for the context **/voidpango_context_set_font_description (PangoContext *context, const PangoFontDescription *desc){ g_return_if_fail (context != NULL); g_return_if_fail (desc != NULL); pango_font_description_free (context->font_desc); context->font_desc = pango_font_description_copy (desc);}/** * pango_context_get_font_description: * @context: a #PangoContext * * Retrieve the default font description for the context. * * Return value: a pointer to the context's default font description. * This value must not be modified or freed. **/PangoFontDescription *pango_context_get_font_description (PangoContext *context){ g_return_val_if_fail (context != NULL, NULL); return context->font_desc;}/** * pango_context_set_language: * @context: a #PangoContext * @language: the new language tag. * * Sets the global language tag for the context. The default language * for the locale of the running process can be found using * pango_language_get_default(). **/voidpango_context_set_language (PangoContext *context, PangoLanguage *language){ g_return_if_fail (context != NULL); context->language = language;}/** * pango_context_get_language: * @context: a #PangoContext * * Retrieves the global language tag for the context. * * Return value: the global language tag. **/PangoLanguage *pango_context_get_language (PangoContext *context){ g_return_val_if_fail (context != NULL, NULL); return context->language;}/** * pango_context_set_base_dir: * @context: a #PangoContext * @direction: the new base direction * * Sets the base direction for the context. * * The base direction is used in applying the Unicode bidirectional * algorithm; if the @direction is %PANGO_DIRECTION_LTR or * %PANGO_DIRECTION_RTL, then the value will be used as the paragraph * direction in the Unicode bidirectional algorithm. A value of * %PANGO_DIRECTION_WEAK_LTR or %PANGO_DIRECTION_WEAK_RTL is used only * for paragraphs that do not contain any strong characters themselves. **/voidpango_context_set_base_dir (PangoContext *context, PangoDirection direction){ g_return_if_fail (context != NULL); context->base_dir = direction;}/** * pango_context_get_base_dir: * @context: a #PangoContext *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -