⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fonts.c

📁 GTK+-2.0源码之pango-1.15.6.tar.gz
💻 C
📖 第 1 页 / 共 4 页
字号:
  FIELD (style,   PANGO_FONT_MASK_STYLE);  FIELD (variant, PANGO_FONT_MASK_VARIANT);  FIELD (weight,  PANGO_FONT_MASK_WEIGHT);  FIELD (stretch, PANGO_FONT_MASK_STRETCH);  FIELD (gravity, PANGO_FONT_MASK_GRAVITY);#undef FIELD  return found;}static const char *getword (const char *str, const char *last, size_t *wordlen){  const char *result;  while (last > str && g_ascii_isspace (*(last - 1)))    last--;  result = last;  while (result > str && !g_ascii_isspace (*(result - 1)))    result--;  *wordlen = last - result;  return result;}static gbooleanparse_size (const char *word,	    size_t      wordlen,	    int        *pango_size,	    gboolean   *size_is_absolute){  char *end;  double size = g_ascii_strtod (word, &end);  if (end != word &&      (end == word + wordlen ||       (end + 2 == word + wordlen && !strncmp (end, "px", 2))      ) && size >= 0 && size <= 1000000) /* word is a valid float */    {      if (pango_size)	*pango_size = (int)(size * PANGO_SCALE + 0.5);      if (size_is_absolute)	*size_is_absolute = end < word + wordlen;      return TRUE;    }  return FALSE;}/** * pango_font_description_from_string: * @str: string representation of a font description. * * Creates a new font description from a string representation in the * form "[FAMILY-LIST] [STYLE-OPTIONS] [SIZE]", where FAMILY-LIST is a * comma separated list of families optionally terminated by a comma, * STYLE_OPTIONS is a whitespace separated list of words where each WORD * describes one of style, variant, weight, stretch, or gravity, and SIZE * is a decimal number (size in points) or optionally followed by the * unit modifier "px" for absolute size. Any one of the options may * be absent.  If FAMILY-LIST is absent, then the family_name field of * the resulting font description will be initialized to %NULL.  If * STYLE-OPTIONS is missing, then all style options will be set to the * default values. If SIZE is missing, the size in the resulting font * description will be set to 0. * * Return value: a new #PangoFontDescription. **/PangoFontDescription *pango_font_description_from_string (const char *str){  PangoFontDescription *desc;  const char *p, *last;  size_t len, wordlen;  g_return_val_if_fail (str != NULL, NULL);  desc = pango_font_description_new ();  desc->mask = PANGO_FONT_MASK_STYLE |	       PANGO_FONT_MASK_WEIGHT |	       PANGO_FONT_MASK_VARIANT |	       PANGO_FONT_MASK_STRETCH;  len = strlen (str);  last = str + len;  p = getword (str, last, &wordlen);  /* Look for a size at the end of the string   */  if (wordlen != 0)    {      gboolean size_is_absolute;      if (parse_size (p, wordlen, &desc->size, &size_is_absolute))	{	  desc->size_is_absolute = size_is_absolute;	  desc->mask |= PANGO_FONT_MASK_SIZE;	  last = p;	}    }  /* Now parse style words   */  p = getword (str, last, &wordlen);  while (wordlen != 0)    {      if (!find_field_any (p, wordlen, desc))	break;      else	{	  last = p;	  p = getword (str, last, &wordlen);	}    }  /* Remainder (str => p) is family list. Trim off trailing commas and leading and trailing white space   */  while (last > str && g_ascii_isspace (*(last - 1)))    last--;  if (last > str && *(last - 1) == ',')    last--;  while (last > str && g_ascii_isspace (*(last - 1)))    last--;  while (last > str && g_ascii_isspace (*str))    str++;  if (str != last)    {      desc->family_name = g_strndup (str, last - str);      desc->mask |= PANGO_FONT_MASK_FAMILY;    }  return desc;}static voidappend_field (GString *str, const FieldMap *map, int n_elements, int val){  int i;  for (i=0; i<n_elements; i++)    {      if (map[i].value == val)	{	  if (map[i].str && map[i].str[0])	    {	      if (str->len > 0 && str->str[str->len -1] != ' ')		g_string_append_c (str, ' ');	      g_string_append (str, map[i].str);	    }	  return;	}    }  if (str->len > 0 || str->str[str->len -1] != ' ')    g_string_append_c (str, ' ');  g_string_append_printf (str, "%d", val);}/** * pango_font_description_to_string: * @desc: a #PangoFontDescription * * Creates a string representation of a font description. See * pango_font_description_from_string() for a description of the * format of the string representation. The family list in the * string description will only have a terminating comma if the * last word of the list is a valid style option. * * Return value: a new string that must be freed with g_free(). **/char *pango_font_description_to_string (const PangoFontDescription  *desc){  GString *result = g_string_new (NULL);  if (desc->family_name && desc->mask & PANGO_FONT_MASK_FAMILY)    {      const char *p;      size_t wordlen;      g_string_append (result, desc->family_name);      /* We need to add a trailing comma if the family name ends       * in a keyword like "Bold", or if the family name ends in       * a number and no keywords will be added.       */      p = getword (desc->family_name, desc->family_name + strlen(desc->family_name), &wordlen);      if (wordlen != 0 &&	  (find_field_any (p, wordlen, NULL) ||	   (parse_size (p, wordlen, NULL, NULL) &&	    desc->weight == PANGO_WEIGHT_NORMAL &&	    desc->style == PANGO_STYLE_NORMAL &&	    desc->stretch == PANGO_STRETCH_NORMAL &&	    desc->variant == PANGO_VARIANT_NORMAL &&	    (desc->mask & (PANGO_FONT_MASK_GRAVITY | PANGO_FONT_MASK_SIZE)) == 0)))	g_string_append_c (result, ',');    }  append_field (result, weight_map, G_N_ELEMENTS (weight_map), desc->weight);  append_field (result, style_map, G_N_ELEMENTS (style_map), desc->style);  append_field (result, stretch_map, G_N_ELEMENTS (stretch_map), desc->stretch);  append_field (result, variant_map, G_N_ELEMENTS (variant_map), desc->variant);  if (desc->mask & PANGO_FONT_MASK_GRAVITY)    append_field (result, gravity_map, G_N_ELEMENTS (gravity_map), desc->gravity);  if (result->len == 0)    g_string_append (result, "Normal");  if (desc->mask & PANGO_FONT_MASK_SIZE)    {      char buf[G_ASCII_DTOSTR_BUF_SIZE];      if (result->len > 0 || result->str[result->len -1] != ' ')	g_string_append_c (result, ' ');      g_ascii_dtostr (buf, sizeof (buf), (double)desc->size / PANGO_SCALE);      g_string_append (result, buf);      if (desc->size_is_absolute)	g_string_append (result, "px");    }  return g_string_free (result, FALSE);}/** * pango_font_description_to_filename: * @desc: a #PangoFontDescription * * Creates a filename representation of a font description. The * filename is identical to the result from calling * pango_font_description_to_string(), but with underscores instead of * characters that are untypical in filenames, and in lower case only. * * Return value: a new string that must be freed with g_free(). **/char *pango_font_description_to_filename (const PangoFontDescription  *desc){  char *result = pango_font_description_to_string (desc);  char *p;  p = result;  while (*p)    {      if (strchr ("-+_.", *p) == NULL && !g_ascii_isalnum (*p))	*p = '_';      else	*p = g_ascii_tolower (*p);      p++;    }  return result;}G_DEFINE_TYPE (PangoFont, pango_font, G_TYPE_OBJECT)static voidpango_font_class_init (PangoFontClass *class){}static voidpango_font_init (PangoFont *font){}/** * pango_font_describe: * @font: a #PangoFont * * Returns a description of the font, with font size set in points. * Use pango_font_describe_with_absolute_size() if you want the font * size in device units. * * Return value: a newly-allocated #PangoFontDescription object. **/PangoFontDescription *pango_font_describe (PangoFont      *font){  g_return_val_if_fail (font != NULL, NULL);  return PANGO_FONT_GET_CLASS (font)->describe (font);}/** * pango_font_describe_with_absolute_size: * @font: a #PangoFont * * Returns a description of the font, with absolute font size set * (in device units). Use pango_font_describe() if you want the font * size in points. * * Return value: a newly-allocated #PangoFontDescription object. * * Since: 1.14 **/PangoFontDescription *pango_font_describe_with_absolute_size (PangoFont      *font){  g_return_val_if_fail (font != NULL, NULL);  if (G_UNLIKELY (!PANGO_FONT_GET_CLASS (font)->describe_absolute))    {      g_warning ("describe_absolute not implemented for this font class, report this as a bug");      return pango_font_describe (font);    }  return PANGO_FONT_GET_CLASS (font)->describe_absolute (font);}/** * pango_font_get_coverage: * @font: a #PangoFont * @language: the language tag * * Computes the coverage map for a given font and language tag. * * Return value: a newly-allocated #PangoCoverage object. **/PangoCoverage *pango_font_get_coverage (PangoFont     *font,			 PangoLanguage *language){  g_return_val_if_fail (font != NULL, NULL);  return PANGO_FONT_GET_CLASS (font)->get_coverage (font, language);}/** * pango_font_find_shaper: * @font: a #PangoFont * @language: the language tag * @ch: a Unicode character. * * Finds the best matching shaper for a font for a particular * language tag and character point. * * Return value: the best matching shaper. **/PangoEngineShape *pango_font_find_shaper (PangoFont     *font,			PangoLanguage *language,			guint32        ch){  PangoEngineShape* shaper;  g_return_val_if_fail (font != NULL, NULL);  shaper = PANGO_FONT_GET_CLASS (font)->find_shaper (font, language, ch);  return shaper;}/** * 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. * * Gets the logical and ink extents of a glyph within a font. The * coordinate system for each rectangle has its origin at the * base line and horizontal origin of the character with increasing * coordinates extending to the right and down. The macros PANGO_ASCENT(), * PANGO_DESCENT(), PANGO_LBEARING(), and PANGO_RBEARING() can be used to convert * from the extents rectangle to more traditional font metrics. The units * of the rectangles are in 1/PANGO_SCALE of a device unit. **/voidpango_font_get_glyph_extents  (PangoFont      *font,			       PangoGlyph      glyph,			       PangoRectangle *ink_rect,			       PangoRectangle *logical_rect){  if (G_UNLIKELY (!font))    {      if (!_pango_warning_history.get_glyph_extents)	{	  _pango_warning_history.get_glyph_extents = TRUE;	  g_warning (bad_font_warning, "pango_font_get_glyph_extents");	}      if (ink_rect)	{	  ink_rect->x = PANGO_SCALE;	  ink_rect->y = - (PANGO_UNKNOWN_GLYPH_HEIGHT - 1) * PANGO_SCALE;	  ink_rect->height = (PANGO_UNKNOWN_GLYPH_HEIGHT - 2) * PANGO_SCALE;	  ink_rect->width = (PANGO_UNKNOWN_GLYPH_WIDTH - 2) * PANGO_SCALE;	}      if (logical_rect)	{	  logical_rect->x = logical_rect->y = 0;	  logical_rect->y = - PANGO_UNKNOWN_GLYPH_HEIGHT * PANGO_SCALE;	  logical_rect->height = PANGO_UNKNOWN_GLYPH_HEIGHT * PANGO_SCALE;	  logical_rect->width = PANGO_UNKNOWN_GLYPH_WIDTH * PANGO_SCALE;	}      return;    }  PANGO_FONT_GET_CLASS (font)->get_glyph_extents (font, glyph, ink_rect, logical_rect);}/** * 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. * * Gets overall metric information for a font. Since the metrics may be * substantially different for different scripts, a language tag can * be provided to indicate that the metrics should be retrieved that * correspond to the script(s) used by that language. * * Return value: a #PangoFontMetrics object. The caller must call pango_font_metrics_unref() *   when finished using the object. **/PangoFontMetrics *pango_font_get_metrics (PangoFont        *font,			PangoLanguage    *language){  if (G_UNLIKELY (!font))    {      PangoFontMetrics *metrics;      if (!_pango_warning_history.get_metrics)	{	  _pango_warning_history.get_metrics = TRUE;	  g_warning (bad_font_warning, "pango_font_get_metrics");	}      metrics = pango_font_metrics_new ();      metrics->ascent = PANGO_SCALE * PANGO_UNKNOWN_GLYPH_HEIGHT;      metrics->descent = 0;      metrics->approximate_char_width = PANGO_SCALE * PANGO_UNKNOWN_GLYPH_WIDTH;      metrics->approximate_digit_width = PANGO_SCALE * PANGO_UNKNOWN_GLYPH_WIDTH;      metrics->underline_position = -PANGO_SCALE;      metrics->underline_thickness = PANGO_SCALE;      metrics->strikethrough_position = PANGO_SCALE * PANGO_UNKNOWN_GLYPH_HEIGHT / 2;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -