📄 fonts.c
字号:
/* Pango * fonts.c: * * Copyright (C) 1999 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 <stdlib.h>#include <math.h>#include <string.h>#include "pango-types.h"#include "pango-font.h"#include "pango-fontmap.h"#include "pango-impl-utils.h"static const char bad_font_warning[] = "%s called with null font argument, expect ugly output";struct _PangoFontDescription{ char *family_name; PangoStyle style; PangoVariant variant; PangoWeight weight; PangoStretch stretch; PangoGravity gravity; guint16 mask; guint static_family : 1; guint size_is_absolute : 1; int size;};GTypepango_font_description_get_type (void){ static GType our_type = 0; if (our_type == 0) our_type = g_boxed_type_register_static (I_("PangoFontDescription"), (GBoxedCopyFunc)pango_font_description_copy, (GBoxedFreeFunc)pango_font_description_free); return our_type;}static const PangoFontDescription pfd_defaults = { NULL, /* family_name */ PANGO_STYLE_NORMAL, /* style */ PANGO_VARIANT_NORMAL, /* variant */ PANGO_WEIGHT_NORMAL, /* weight */ PANGO_STRETCH_NORMAL, /* stretch */ PANGO_GRAVITY_SOUTH, /* gravity */ 0, /* mask */ 0, /* static_family */ FALSE, /* size_is_absolute */ 0, /* size */};/** * pango_font_description_new: * * Creates a new font description structure with all fields unset. * * Return value: the newly allocated #PangoFontDescription, which * should be freed using pango_font_description_free(). **/PangoFontDescription *pango_font_description_new (void){ PangoFontDescription *desc = g_slice_new (PangoFontDescription); *desc = pfd_defaults; return desc;}/** * pango_font_description_set_family: * @desc: a #PangoFontDescription. * @family: a string representing the family name. * * Sets the family name field of a font description. The family * name represents a family of related font styles, and will * resolve to a particular #PangoFontFamily. In some uses of * #PangoFontDescription, it is also possible to use a comma * separated list of family names for this field. **/voidpango_font_description_set_family (PangoFontDescription *desc, const char *family){ g_return_if_fail (desc != NULL); pango_font_description_set_family_static (desc, family ? g_strdup (family) : NULL); if (family) desc->static_family = FALSE;}/** * pango_font_description_set_family_static: * @desc: a #PangoFontDescription * @family: a string representing the family name. * * Like pango_font_description_set_family(), except that no * copy of @family is made. The caller must make sure that the * string passed in stays around until @desc has been freed * or the name is set again. This function can be used if * @family is a static string such as a C string literal, or * if @desc is only needed temporarily. **/voidpango_font_description_set_family_static (PangoFontDescription *desc, const char *family){ g_return_if_fail (desc != NULL); if (desc->family_name == family) return; if (desc->family_name && !desc->static_family) g_free (desc->family_name); if (family) { desc->family_name = (char *)family; desc->static_family = TRUE; desc->mask |= PANGO_FONT_MASK_FAMILY; } else { desc->family_name = pfd_defaults.family_name; desc->static_family = pfd_defaults.static_family; desc->mask &= ~PANGO_FONT_MASK_FAMILY; }}/** * pango_font_description_get_family: * @desc: a #PangoFontDescription. * * Gets the family name field of a font description. See * pango_font_description_set_family(). * * Return value: the family name field for the font description, or * %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 *pango_font_description_get_family (const PangoFontDescription *desc){ g_return_val_if_fail (desc != NULL, NULL); return desc->family_name;}/** * pango_font_description_set_style: * @desc: a #PangoFontDescription * @style: the style for the font description * * Sets the style field of a #PangoFontDescription. The * #PangoStyle enumeration describes whether the font is slanted and * the manner in which it is slanted; it can be either * #PANGO_STYLE_NORMAL, #PANGO_STYLE_ITALIC, or #PANGO_STYLE_OBLIQUE. * Most fonts will either have a italic style or an oblique * style, but not both, and font matching in Pango will * match italic specifications with oblique fonts and vice-versa * if an exact match is not found. **/voidpango_font_description_set_style (PangoFontDescription *desc, PangoStyle style){ g_return_if_fail (desc != NULL); desc->style = style; desc->mask |= PANGO_FONT_MASK_STYLE;}/** * pango_font_description_get_style: * @desc: a #PangoFontDescription * * Gets the style field of a #PangoFontDescription. See * pango_font_description_set_style(). * * Return value: the style field for the font description. * Use pango_font_description_get_set_fields() to find out if * the field was explicitly set or not. **/PangoStylepango_font_description_get_style (const PangoFontDescription *desc){ g_return_val_if_fail (desc != NULL, pfd_defaults.style); return desc->style;}/** * pango_font_description_set_variant: * @desc: a #PangoFontDescription * @variant: the variant type for the font description. * * Sets the variant field of a font description. The #PangoVariant * can either be %PANGO_VARIANT_NORMAL or %PANGO_VARIANT_SMALL_CAPS. **/voidpango_font_description_set_variant (PangoFontDescription *desc, PangoVariant variant){ g_return_if_fail (desc != NULL); desc->variant = variant; desc->mask |= PANGO_FONT_MASK_VARIANT;}/** * pango_font_description_get_variant: * @desc: a #PangoFontDescription. * * Gets the variant field of a #PangoFontDescription. See * pango_font_description_set_variant(). * * Return value: the variant field for the font description. Use * pango_font_description_get_set_fields() to find out if * the field was explicitly set or not. **/PangoVariantpango_font_description_get_variant (const PangoFontDescription *desc){ g_return_val_if_fail (desc != NULL, pfd_defaults.variant); return desc->variant;}/** * pango_font_description_set_weight: * @desc: a #PangoFontDescription * @weight: the weight for the font description. * * Sets the weight field of a font description. The weight field * specifies how bold or light the font should be. In addition * to the values of the #PangoWeight enumeration, other intermediate * numeric values are possible. **/voidpango_font_description_set_weight (PangoFontDescription *desc, PangoWeight weight){ g_return_if_fail (desc != NULL); desc->weight = weight; desc->mask |= PANGO_FONT_MASK_WEIGHT;}/** * pango_font_description_get_weight: * @desc: a #PangoFontDescription * * Gets the weight field of a font description. See * pango_font_description_set_weight(). * * Return value: the weight field for the font description. Use * pango_font_description_get_set_fields() to find out if * the field was explicitly set or not. **/PangoWeightpango_font_description_get_weight (const PangoFontDescription *desc){ g_return_val_if_fail (desc != NULL, pfd_defaults.weight); return desc->weight;}/** * pango_font_description_set_stretch: * @desc: a #PangoFontDescription * @stretch: the stretch for the font description * * Sets the stretch field of a font description. The stretch field * specifies how narrow or wide the font should be. **/voidpango_font_description_set_stretch (PangoFontDescription *desc, PangoStretch stretch){ g_return_if_fail (desc != NULL); desc->stretch = stretch; desc->mask |= PANGO_FONT_MASK_STRETCH;}/** * pango_font_description_get_stretch: * @desc: a #PangoFontDescription. * * Gets the stretch field of a font description. * See pango_font_description_set_stretch(). * * Return value: the stretch field for the font description. Use * pango_font_description_get_set_fields() to find out if * the field was explicitly set or not. **/PangoStretchpango_font_description_get_stretch (const PangoFontDescription *desc){ g_return_val_if_fail (desc != NULL, pfd_defaults.stretch); return desc->stretch;}/** * pango_font_description_set_size: * @desc: a #PangoFontDescription * @size: the size of the font in points, scaled by PANGO_SCALE. (That is, * a @size value of 10 * PANGO_SCALE is a 10 point font. The conversion * factor between points and device units depends on system configuration * and the output device. For screen display, a logical DPI of 96 is * common, in which case a 10 point font corresponds to a 10 * (96 / 72) = 13.3 * pixel font. Use pango_font_description_set_absolute_size() if you need * a particular size in device units. * * Sets the size field of a font description in fractional points. This is mutually * exclusive with pango_font_description_set_absolute_size(). **/voidpango_font_description_set_size (PangoFontDescription *desc, gint size){ g_return_if_fail (desc != NULL); g_return_if_fail (size >= 0); desc->size = size; desc->size_is_absolute = FALSE; desc->mask |= PANGO_FONT_MASK_SIZE;}/** * pango_font_description_get_size: * @desc: a #PangoFontDescription * * Gets the size field of a font description. * See pango_font_description_set_size(). * * Return value: the size field for the font description in points or device units. * You must call pango_font_description_get_size_is_absolute() * to find out which is the case. Returns 0 if the size field has not * previously been set or it has been set to 0 explicitly. * Use pango_font_description_get_set_fields() to * find out if the field was explicitly set or not. **/gintpango_font_description_get_size (const PangoFontDescription *desc){ g_return_val_if_fail (desc != NULL, pfd_defaults.size); return desc->size;}/** * pango_font_description_set_absolute_size: * @desc: a #PangoFontDescription * @size: the new size, in Pango units. There are %PANGO_SCALE Pango units in one * device unit. For an output backend where a device unit is a pixel, a @size * value of 10 * PANGO_SCALE gives a 10 pixel font. * * Sets the size field of a font description, in device units. This is mutually * exclusive with pango_font_description_set_size(). * * Since: 1.8 **/voidpango_font_description_set_absolute_size (PangoFontDescription *desc, double size){ g_return_if_fail (desc != NULL); g_return_if_fail (size >= 0); desc->size = size; desc->size_is_absolute = TRUE; desc->mask |= PANGO_FONT_MASK_SIZE;}/** * pango_font_description_get_size_is_absolute: * @desc: a #PangoFontDescription * * Determines whether the size of the font is in points or device units. * See pango_font_description_set_size() and pango_font_description_set_absolute_size(). * * Return value: whether the size for the font description is in * points or device units. Use pango_font_description_get_set_fields() to * find out if the size field of the font description was explicitly set or not. * * Since: 1.8 **/gbooleanpango_font_description_get_size_is_absolute (const PangoFontDescription *desc){ g_return_val_if_fail (desc != NULL, pfd_defaults.size_is_absolute); return desc->size_is_absolute;}/** * pango_font_description_set_gravity: * @desc: a #PangoFontDescription * @gravity: the gravity for the font description. * * Sets the gravity field of a font description. The gravity field * specifies how the glyphs should be rotated. If @gravity is * %PANGO_GRAVITY_AUTO, this actually unsets the gravity mask on * the font description. * * This function is seldom useful to the user. Gravity should normally * be set on a #PangoContext. * * Since: 1.16 **/voidpango_font_description_set_gravity (PangoFontDescription *desc, PangoGravity gravity){ g_return_if_fail (desc != NULL); if (gravity == PANGO_GRAVITY_AUTO) { pango_font_description_unset_fields (desc, PANGO_FONT_MASK_GRAVITY); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -