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

📄 pango-markup.c

📁 linux
💻 C
📖 第 1 页 / 共 3 页
字号:
  const char *gravity_hint = NULL;  g_markup_parse_context_get_position (context,				       &line_number, &char_number);#define CHECK_DUPLICATE(var) G_STMT_START{                              \	  if ((var) != NULL) {                                          \	    g_set_error (error, G_MARKUP_ERROR,                         \			 G_MARKUP_ERROR_INVALID_CONTENT,                \			 _("Attribute '%s' occurs twice on <span> tag " \			   "on line %d char %d, may only occur once"),  \			 names[i], line_number, char_number);           \	    return FALSE;                                               \	  }}G_STMT_END#define CHECK_ATTRIBUTE2(var, name) \	if (attr_strcmp (names[i], (name)) == 0) { \	  CHECK_DUPLICATE (var); \	  (var) = values[i]; \	  found = TRUE; \	  break; \	}#define CHECK_ATTRIBUTE(var) CHECK_ATTRIBUTE2 (var, G_STRINGIFY (var))  i = 0;  while (names[i])    {      gboolean found = FALSE;      switch (names[i][0]) {      case 'f':	CHECK_ATTRIBUTE2(family, "face");	CHECK_ATTRIBUTE (fallback);	CHECK_ATTRIBUTE2(desc, "font_desc");	CHECK_ATTRIBUTE2(family, "font_family");	CHECK_ATTRIBUTE (foreground);	break;      case 's':	CHECK_ATTRIBUTE (size);	CHECK_ATTRIBUTE (stretch);	CHECK_ATTRIBUTE (strikethrough);	CHECK_ATTRIBUTE (strikethrough_color);	CHECK_ATTRIBUTE (style);	break;      case 'g':	CHECK_ATTRIBUTE (gravity);	CHECK_ATTRIBUTE (gravity_hint);	break;      case 'l':	CHECK_ATTRIBUTE (lang);	CHECK_ATTRIBUTE (letter_spacing);	break;      case 'u':	CHECK_ATTRIBUTE (underline);	CHECK_ATTRIBUTE (underline_color);	break;      default:	CHECK_ATTRIBUTE (background);	CHECK_ATTRIBUTE2(foreground, "color");	CHECK_ATTRIBUTE (rise);	CHECK_ATTRIBUTE (variant);	CHECK_ATTRIBUTE (weight);	break;      }      if (!found)	{	  g_set_error (error, G_MARKUP_ERROR,		       G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,		       _("Attribute '%s' is not allowed on the <span> tag "			 "on line %d char %d"),		       names[i], line_number, char_number);	  return FALSE;	}      ++i;    }  /* Parse desc first, then modify it with other font-related attributes. */  if (G_UNLIKELY (desc))    {      PangoFontDescription *parsed;      parsed = pango_font_description_from_string (desc);      if (parsed)	{	  add_attribute (tag, pango_attr_font_desc_new (parsed));	  if (tag)	    open_tag_set_absolute_font_size (tag, pango_font_description_get_size (parsed));	  pango_font_description_free (parsed);	}    }  if (G_UNLIKELY (family))    {      add_attribute (tag, pango_attr_family_new (family));    }  if (G_UNLIKELY (size))    {      if (g_ascii_isdigit (*size))	{	  char *end = NULL;	  gulong n;	  n = strtoul (size, &end, 10);	  if (*end != '\0' || n < 0 || n > 1000000)	    {	      g_set_error (error,			   G_MARKUP_ERROR,			   G_MARKUP_ERROR_INVALID_CONTENT,			   _("Value of 'size' attribute on <span> tag on line %d"			     "could not be parsed; should be an integer, or a "			     "string such as 'small', not '%s'"),			   line_number, size);	      goto error;	    }	  add_attribute (tag, pango_attr_size_new (n));	  if (tag)	    open_tag_set_absolute_font_size (tag, n);	}      else if (strcmp (size, "smaller") == 0)	{	  if (tag)	    {	      tag->scale_level_delta -= 1;	      tag->scale_level -= 1;	    }	}      else if (strcmp (size, "larger") == 0)	{	  if (tag)	    {	      tag->scale_level_delta += 1;	      tag->scale_level += 1;	    }	}      else if (parse_absolute_size (tag, size))	; /* nothing */      else	{	  g_set_error (error,		       G_MARKUP_ERROR,		       G_MARKUP_ERROR_INVALID_CONTENT,		       _("Value of 'size' attribute on <span> tag on line %d"			 "could not be parsed; should be an integer, or a "			 "string such as 'small', not '%s'"),		       line_number, size);	  goto error;	}    }  if (G_UNLIKELY (style))    {      PangoStyle pango_style;      if (pango_parse_style (style, &pango_style, FALSE))	add_attribute (tag, pango_attr_style_new (pango_style));      else	{	  g_set_error (error,		       G_MARKUP_ERROR,		       G_MARKUP_ERROR_INVALID_CONTENT,		       _("'%s' is not a valid value for the 'style' attribute "			 "on <span> tag, line %d; valid values are "			 "'normal', 'oblique', 'italic'"),		       style, line_number);	  goto error;	}    }  if (G_UNLIKELY (weight))    {      PangoWeight pango_weight;      if (pango_parse_weight (weight, &pango_weight, FALSE))	add_attribute (tag,		       pango_attr_weight_new (pango_weight));      else	{	  g_set_error (error,		       G_MARKUP_ERROR,		       G_MARKUP_ERROR_INVALID_CONTENT,		       _("'%s' is not a valid value for the 'weight' "			 "attribute on <span> tag, line %d; valid "			 "values are for example 'light', 'ultrabold' or a number"),		       weight, line_number);	  goto error;	}    }  if (G_UNLIKELY (variant))    {      PangoVariant pango_variant;      if (pango_parse_variant (variant, &pango_variant, FALSE))	add_attribute (tag, pango_attr_variant_new (pango_variant));      else	{	  g_set_error (error,		       G_MARKUP_ERROR,		       G_MARKUP_ERROR_INVALID_CONTENT,		       _("'%s' is not a valid value for the 'variant' "			 "attribute on <span> tag, line %d; valid values are "			 "'normal', 'smallcaps'"),		       variant, line_number);	  goto error;	}    }  if (G_UNLIKELY (stretch))    {      PangoStretch pango_stretch;      if (pango_parse_stretch (stretch, &pango_stretch, FALSE))	add_attribute (tag, pango_attr_stretch_new (pango_stretch));      else	{	  g_set_error (error,		       G_MARKUP_ERROR,		       G_MARKUP_ERROR_INVALID_CONTENT,		       _("'%s' is not a valid value for the 'stretch' "			 "attribute on <span> tag, line %d; valid "			 "values are for example 'condensed', "			 "'ultraexpanded', 'normal'"),		       stretch, line_number);	  goto error;	}    }  if (G_UNLIKELY (foreground))    {      PangoColor color;      if (!span_parse_color ("foreground", foreground, &color, line_number, error))	goto error;      add_attribute (tag, pango_attr_foreground_new (color.red, color.green, color.blue));    }  if (G_UNLIKELY (background))    {      PangoColor color;      if (!span_parse_color ("background", background, &color, line_number, error))	goto error;      add_attribute (tag, pango_attr_background_new (color.red, color.green, color.blue));    }  if (G_UNLIKELY (underline))    {      PangoUnderline ul = PANGO_UNDERLINE_NONE;      if (!span_parse_enum ("underline", underline, PANGO_TYPE_UNDERLINE, &ul, line_number, error))	goto error;      add_attribute (tag, pango_attr_underline_new (ul));    }  if (G_UNLIKELY (underline_color))    {      PangoColor color;      if (!span_parse_color ("underline_color", underline_color, &color, line_number, error))	goto error;      add_attribute (tag, pango_attr_underline_color_new (color.red, color.green, color.blue));    }  if (G_UNLIKELY (gravity))    {      PangoGravity gr = PANGO_GRAVITY_SOUTH;      if (!span_parse_enum ("gravity", gravity, PANGO_TYPE_GRAVITY, &gr, line_number, error))	goto error;      add_attribute (tag, pango_attr_gravity_new (gr));    }  if (G_UNLIKELY (gravity_hint))    {      PangoGravityHint hint = PANGO_GRAVITY_HINT_NATURAL;      if (!span_parse_enum ("gravity_hint", gravity_hint, PANGO_TYPE_GRAVITY_HINT, &hint, line_number, error))	goto error;      add_attribute (tag, pango_attr_gravity_hint_new (hint));    }  if (G_UNLIKELY (strikethrough))    {      gboolean b = FALSE;      if (!span_parse_boolean ("strikethrough", strikethrough, &b, line_number, error))	goto error;      add_attribute (tag, pango_attr_strikethrough_new (b));    }  if (G_UNLIKELY (strikethrough_color))    {      PangoColor color;      if (!span_parse_color ("strikethrough_color", strikethrough_color, &color, line_number, error))	goto error;      add_attribute (tag, pango_attr_strikethrough_color_new (color.red, color.green, color.blue));    }  if (G_UNLIKELY (fallback))    {      gboolean b = FALSE;      if (!span_parse_boolean ("fallback", fallback, &b, line_number, error))	goto error;      add_attribute (tag, pango_attr_fallback_new (b));    }  if (G_UNLIKELY (rise))    {      gint n = 0;      if (!span_parse_int ("rise", rise, &n, line_number, error))	goto error;      add_attribute (tag, pango_attr_rise_new (n));    }  if (G_UNLIKELY (letter_spacing))    {      gint n = 0;      if (!span_parse_int ("letter_spacing", letter_spacing, &n, line_number, error))	goto error;      add_attribute (tag, pango_attr_letter_spacing_new (n));    }  if (G_UNLIKELY (lang))    {      add_attribute (tag,		     pango_attr_language_new (pango_language_from_string (lang)));    }  return TRUE; error:  return FALSE;}static gbooleani_parse_func        (MarkupData            *md,		     OpenTag               *tag,		     const gchar          **names,		     const gchar          **values,		     GMarkupParseContext   *context,		     GError               **error){  CHECK_NO_ATTRS("i");  add_attribute (tag, pango_attr_style_new (PANGO_STYLE_ITALIC));  return TRUE;}static gbooleanmarkup_parse_func (MarkupData            *md,		   OpenTag               *tag,		   const gchar          **names,		   const gchar          **values,		   GMarkupParseContext   *context,		   GError               **error){  /* We don't do anything with this tag at the moment. */  return TRUE;}static gbooleans_parse_func        (MarkupData            *md,		     OpenTag               *tag,		     const gchar          **names,		     const gchar          **values,		     GMarkupParseContext   *context,		     GError               **error){  CHECK_NO_ATTRS("s");  add_attribute (tag, pango_attr_strikethrough_new (TRUE));  return TRUE;}#define SUPERSUB_RISE 5000static gbooleansub_parse_func      (MarkupData            *md,		     OpenTag               *tag,		     const gchar          **names,		     const gchar          **values,		     GMarkupParseContext   *context,		     GError               **error){  CHECK_NO_ATTRS("sub");  /* Shrink font, and set a negative rise */  if (tag)    {      tag->scale_level_delta -= 1;      tag->scale_level -= 1;    }  add_attribute (tag, pango_attr_rise_new (-SUPERSUB_RISE));  return TRUE;}static gbooleansup_parse_func      (MarkupData            *md,		     OpenTag               *tag,		     const gchar          **names,		     const gchar          **values,		     GMarkupParseContext   *context,		     GError               **error){  CHECK_NO_ATTRS("sup");  /* Shrink font, and set a positive rise */  if (tag)    {      tag->scale_level_delta -= 1;      tag->scale_level -= 1;    }  add_attribute (tag, pango_attr_rise_new (SUPERSUB_RISE));  return TRUE;}static gbooleansmall_parse_func    (MarkupData            *md,		     OpenTag               *tag,		     const gchar          **names,		     const gchar          **values,		     GMarkupParseContext   *context,		     GError               **error){  CHECK_NO_ATTRS("small");  /* Shrink text one level */  if (tag)    {      tag->scale_level_delta -= 1;      tag->scale_level -= 1;    }  return TRUE;}static gbooleantt_parse_func       (MarkupData            *md,		     OpenTag               *tag,		     const gchar          **names,		     const gchar          **values,		     GMarkupParseContext   *context,		     GError               **error){  CHECK_NO_ATTRS("tt");  add_attribute (tag, pango_attr_family_new ("Monospace"));  return TRUE;}static gbooleanu_parse_func        (MarkupData            *md,		     OpenTag               *tag,		     const gchar          **names,		     const gchar          **values,		     GMarkupParseContext   *context,		     GError               **error){  CHECK_NO_ATTRS("u");  add_attribute (tag, pango_attr_underline_new (PANGO_UNDERLINE_SINGLE));  return TRUE;}

⌨️ 快捷键说明

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