label markup



Hi,

As a Pango feature, I propose adding something like:

gboolean
pango_parse_markup (const char     *markup_text,
                    PangoAttrList **attributes,            
                    char          **text,
                    GError        **error);

which would parse some markup such as:
 
  "This is some <b>markup</b>"

into an attribute list with a bold attribute, and some the text
with tags stripped out. The attribute list and text are meant to be
used with a PangoLayout of course.

For convenience we'd provide:
 
PangoLayout* pango_layout_new_from_markup (const char *markup_text,
                                           GError    **error);

and in GTK+, this one which does a g_warning() on invalid markup:
 
GtkWidget* gtk_label_new_from_markup (const char *markup_text);

we might add with_markup() in other places which take label text as
well, such as gtk_frame_new_with_markup().

The purpose of this feature is to make it easy to do labels with
special formatting. Otherwise it will require some fairly involved
futzing around with PangoLayout and PangoAttrList and a lot of
new_with_layout() functions.

Here is an initial proposal for the supported tags:

Base tags:
  <p align="center">
  <language name="isocountrycode">
  <font family="Sans" size="10" style="italic" weight="bold" 
        variant="smallcaps" stretch="condensed" desc="Serif Italic 10"
        foreground="FFFFFF" background="FFFFFF" underline="double"
        strikethrough="true" rise="100">

Syntactic sugar that can be done with the base tags:
  <i>     italic
  <b>     bold
  <u>     underline
  <s>     strikethrough
  <sup>   superscript
  <sub>   subscript
  <big>   somewhat larger
  <small> somewhat smaller
  <tt>    monospace

  On the <font> tag, attributes have synonyms for HTML familiarity;
   for "family" you can also use "face", and for "foreground" you 
   can also use "color"

Issues:

 - would be nice to use gdk_color_parse for color, but it isn't 
   in pango; maybe move the non-X version to pango?

 - the <p> tag is the root tag; this markup language is for single 
   paragraphs. For GtkLabel, it's kind of annoying to have
   to do <p>My Label</p> though, so we should automatically bracket
   the markup text in <p></p> if the first two chars aren't "<p".

 - I'm sort of confused by PangoAlign, GtkJustification,
   gtk_misc_set_alignment(), and their usage in GtkTextTag and 
   GtkLabel; we should make sure these make sense.

Havoc






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]