📄 pango-attributes.c
字号:
/* Pango * pango-attributes.c: Attributed text * * Copyright (C) 2000-2002 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 "pango-attributes.h"#include "pango-impl-utils.h"struct _PangoAttrList{ guint ref_count; GSList *attributes; GSList *attributes_tail;};struct _PangoAttrIterator{ GSList *next_attribute; GList *attribute_stack; guint start_index; guint end_index;};static PangoAttribute *pango_attr_color_new (const PangoAttrClass *klass, guint16 red, guint16 green, guint16 blue);static PangoAttribute *pango_attr_string_new (const PangoAttrClass *klass, const char *str);static PangoAttribute *pango_attr_int_new (const PangoAttrClass *klass, int value);static PangoAttribute *pango_attr_float_new (const PangoAttrClass *klass, double value);static PangoAttribute *pango_attr_size_new_internal (int size, gboolean absolute);/** * pango_attr_type_register: * @name: an identifier for the type (currently unused.) * * Allocate a new attribute type ID. * * Return value: the new type ID. **/PangoAttrTypepango_attr_type_register (const gchar *name){ static guint current_type = 0x1000000; return current_type++;}/** * pango_attribute_copy: * @attr: a #PangoAttribute * * Make a copy of an attribute. * * Return value: the newly allocated #PangoAttribute, which should be * freed with pango_attribute_destroy(). **/PangoAttribute *pango_attribute_copy (const PangoAttribute *attr){ PangoAttribute *result; g_return_val_if_fail (attr != NULL, NULL); result = attr->klass->copy (attr); result->start_index = attr->start_index; result->end_index = attr->end_index; return result;}/** * pango_attribute_destroy: * @attr: a #PangoAttribute. * * Destroy a #PangoAttribute and free all associated memory. **/voidpango_attribute_destroy (PangoAttribute *attr){ g_return_if_fail (attr != NULL); attr->klass->destroy (attr);}/** * pango_attribute_equal: * @attr1: a #PangoAttribute * @attr2: another #PangoAttribute * * Compare two attributes for equality. This compares only the * actual value of the two attributes and not the ranges that the * attributes apply to. * * Return value: %TRUE if the two attributes have the same value. **/gbooleanpango_attribute_equal (const PangoAttribute *attr1, const PangoAttribute *attr2){ g_return_val_if_fail (attr1 != NULL, FALSE); g_return_val_if_fail (attr2 != NULL, FALSE); if (attr1->klass->type != attr2->klass->type) return FALSE; return attr1->klass->equal (attr1, attr2);}static PangoAttribute *pango_attr_string_copy (const PangoAttribute *attr){ return pango_attr_string_new (attr->klass, ((PangoAttrString *)attr)->value);}static voidpango_attr_string_destroy (PangoAttribute *attr){ PangoAttrString *sattr = (PangoAttrString *)attr; g_free (sattr->value); g_slice_free (PangoAttrString, sattr);}static gbooleanpango_attr_string_equal (const PangoAttribute *attr1, const PangoAttribute *attr2){ return strcmp (((PangoAttrString *)attr1)->value, ((PangoAttrString *)attr2)->value) == 0;}static PangoAttribute *pango_attr_string_new (const PangoAttrClass *klass, const char *str){ PangoAttrString *result = g_slice_new (PangoAttrString); result->attr.klass = klass; result->value = g_strdup (str); return (PangoAttribute *)result;}/** * pango_attr_family_new: * @family: the family or comma separated list of families * * Create a new font family attribute. * * Return value: the newly allocated #PangoAttribute, which should be * freed with pango_attribute_destroy(). **/PangoAttribute *pango_attr_family_new (const char *family){ static const PangoAttrClass klass = { PANGO_ATTR_FAMILY, pango_attr_string_copy, pango_attr_string_destroy, pango_attr_string_equal }; g_return_val_if_fail (family != NULL, NULL); return pango_attr_string_new (&klass, family);}static PangoAttribute *pango_attr_language_copy (const PangoAttribute *attr){ return pango_attr_language_new (((PangoAttrLanguage *)attr)->value);}static voidpango_attr_language_destroy (PangoAttribute *attr){ PangoAttrLanguage *lattr = (PangoAttrLanguage *)attr; g_slice_free (PangoAttrLanguage, lattr);}static gbooleanpango_attr_language_equal (const PangoAttribute *attr1, const PangoAttribute *attr2){ return ((PangoAttrLanguage *)attr1)->value == ((PangoAttrLanguage *)attr2)->value;}/** * pango_attr_language_new: * @language: language tag * * Create a new language tag attribute. * * Return value: the newly allocated #PangoAttribute, which should be * freed with pango_attribute_destroy(). **/PangoAttribute *pango_attr_language_new (PangoLanguage *language){ PangoAttrLanguage *result; static const PangoAttrClass klass = { PANGO_ATTR_LANGUAGE, pango_attr_language_copy, pango_attr_language_destroy, pango_attr_language_equal }; g_return_val_if_fail (language != NULL, NULL); result = g_slice_new (PangoAttrLanguage); result->attr.klass = &klass; result->value = language; return (PangoAttribute *)result;}static PangoAttribute *pango_attr_color_copy (const PangoAttribute *attr){ const PangoAttrColor *color_attr = (PangoAttrColor *)attr; return pango_attr_color_new (attr->klass, color_attr->color.red, color_attr->color.green, color_attr->color.blue);}static voidpango_attr_color_destroy (PangoAttribute *attr){ PangoAttrColor *cattr = (PangoAttrColor *)attr; g_slice_free (PangoAttrColor, cattr);}static gbooleanpango_attr_color_equal (const PangoAttribute *attr1, const PangoAttribute *attr2){ const PangoAttrColor *color_attr1 = (const PangoAttrColor *)attr1; const PangoAttrColor *color_attr2 = (const PangoAttrColor *)attr2; return (color_attr1->color.red == color_attr2->color.red && color_attr1->color.blue == color_attr2->color.blue && color_attr1->color.green == color_attr2->color.green);}static PangoAttribute *pango_attr_color_new (const PangoAttrClass *klass, guint16 red, guint16 green, guint16 blue){ PangoAttrColor *result = g_slice_new (PangoAttrColor); result->attr.klass = klass; result->color.red = red; result->color.green = green; result->color.blue = blue; return (PangoAttribute *)result;}/** * pango_attr_foreground_new: * @red: the red value (ranging from 0 to 65535) * @green: the green value * @blue: the blue value * * Create a new foreground color attribute. * * Return value: the newly allocated #PangoAttribute, which should be * freed with pango_attribute_destroy(). **/PangoAttribute *pango_attr_foreground_new (guint16 red, guint16 green, guint16 blue){ static const PangoAttrClass klass = { PANGO_ATTR_FOREGROUND, pango_attr_color_copy, pango_attr_color_destroy, pango_attr_color_equal }; return pango_attr_color_new (&klass, red, green, blue);}/** * pango_attr_background_new: * @red: the red value (ranging from 0 to 65535) * @green: the green value * @blue: the blue value * * Create a new background color attribute. * * Return value: the newly allocated #PangoAttribute, which should be * freed with pango_attribute_destroy(). **/PangoAttribute *pango_attr_background_new (guint16 red, guint16 green, guint16 blue){ static const PangoAttrClass klass = { PANGO_ATTR_BACKGROUND, pango_attr_color_copy, pango_attr_color_destroy, pango_attr_color_equal }; return pango_attr_color_new (&klass, red, green, blue);}static PangoAttribute *pango_attr_int_copy (const PangoAttribute *attr){ const PangoAttrInt *int_attr = (PangoAttrInt *)attr; return pango_attr_int_new (attr->klass, int_attr->value);}static voidpango_attr_int_destroy (PangoAttribute *attr){ PangoAttrInt *iattr = (PangoAttrInt *)attr; g_slice_free (PangoAttrInt, iattr);}static gbooleanpango_attr_int_equal (const PangoAttribute *attr1, const PangoAttribute *attr2){ const PangoAttrInt *int_attr1 = (const PangoAttrInt *)attr1; const PangoAttrInt *int_attr2 = (const PangoAttrInt *)attr2; return (int_attr1->value == int_attr2->value);}static PangoAttribute *pango_attr_int_new (const PangoAttrClass *klass, int value){ PangoAttrInt *result = g_slice_new (PangoAttrInt); result->attr.klass = klass; result->value = value; return (PangoAttribute *)result;}static PangoAttribute *pango_attr_float_copy (const PangoAttribute *attr){ const PangoAttrFloat *float_attr = (PangoAttrFloat *)attr; return pango_attr_float_new (attr->klass, float_attr->value);}static voidpango_attr_float_destroy (PangoAttribute *attr){ PangoAttrFloat *fattr = (PangoAttrFloat *)attr; g_slice_free (PangoAttrFloat, fattr);}static gbooleanpango_attr_float_equal (const PangoAttribute *attr1, const PangoAttribute *attr2){ const PangoAttrFloat *float_attr1 = (const PangoAttrFloat *)attr1; const PangoAttrFloat *float_attr2 = (const PangoAttrFloat *)attr2; return (float_attr1->value == float_attr2->value);}static PangoAttribute*pango_attr_float_new (const PangoAttrClass *klass, double value){ PangoAttrFloat *result = g_slice_new (PangoAttrFloat); result->attr.klass = klass; result->value = value; return (PangoAttribute *)result;}static PangoAttribute *pango_attr_size_copy (const PangoAttribute *attr){ const PangoAttrSize *size_attr = (PangoAttrSize *)attr; if (attr->klass->type == PANGO_ATTR_ABSOLUTE_SIZE) return pango_attr_size_new_absolute (size_attr->size); else return pango_attr_size_new (size_attr->size);}static voidpango_attr_size_destroy (PangoAttribute *attr){ PangoAttrSize *sattr = (PangoAttrSize *)attr; g_slice_free (PangoAttrSize, sattr);}static gbooleanpango_attr_size_equal (const PangoAttribute *attr1, const PangoAttribute *attr2){ const PangoAttrSize *size_attr1 = (const PangoAttrSize *)attr1; const PangoAttrSize *size_attr2 = (const PangoAttrSize *)attr2; return size_attr1->size == size_attr2->size;}static PangoAttribute *pango_attr_size_new_internal (int size, gboolean absolute){ PangoAttrSize *result; static const PangoAttrClass klass = { PANGO_ATTR_SIZE, pango_attr_size_copy, pango_attr_size_destroy, pango_attr_size_equal }; static const PangoAttrClass absolute_klass = { PANGO_ATTR_ABSOLUTE_SIZE, pango_attr_size_copy, pango_attr_size_destroy, pango_attr_size_equal }; result = g_slice_new (PangoAttrSize); result->attr.klass = absolute ? &absolute_klass : &klass; result->size = size; result->absolute = absolute; return (PangoAttribute *)result;}/** * pango_attr_size_new: * @size: the font size, in %PANGO_SCALE<!-- -->ths of a point. * * Create a new font-size attribute in fractional points. * * Return value: the newly allocated #PangoAttribute, which should be * freed with pango_attribute_destroy(). **/PangoAttribute *pango_attr_size_new (int size){ return pango_attr_size_new_internal (size, FALSE);}/** * pango_attr_size_new_absolute: * @size: the font size, in %PANGO_SCALE<!-- -->ths of a device unit. * * Create a new font-size attribute in device units. * * Return value: the newly allocated #PangoAttribute, which should be * freed with pango_attribute_destroy(). * * Since: 1.8 **/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -