Re: label markup



Havoc Pennington <hp redhat com> writes:

> 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().

Sounds reasonable.

> 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">

How are you going to implement this? (See below - GtkLabel can
have multiple paragraphs, but they all need the same alignment,
currently)

>   <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"
                      ^ Definitily need the # here

>         strikethrough="true" rise="100">

It would actually be more "modern" to do

 <span lang="en" font_desc="Serif Italic 10">Some Text</span>

Also, I think <font foreground="blue"></font> is a little odd.
 
> 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

Hmm, if you are going to support these, I'd be tempted to actually
implement the real CSS way of doing this, allow size=[xx-small |
x-small | small | medium | large | x-large | xx-large | larger |
smaller] In the <font> description, and then make <big> and <small>
synonyms for <font size="smaller"> <font size="larger">.

>   <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?

I don't think making gdk-pixbuf depend on pango is any nicer
than making pango depend on gdk-pixbuf :-); and I'm sure
we don't want that big table in two places.

One possibility would be to pass in a color parse function into
pango_markup_parse(), then virtualize the operation in PangoContext
to avoid having to pass these functions around everywhere.
I don't know if that is overkill just to get foreground="red"
to work.

One possibility would be to instead, support the 16 HTML colors
instead of the full rgb.txt set; that avoids having to have
the huge table.
 
>  - 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".

GtkLabel allows multiple paragraphs. I'd suggest making the
root tag <markup> and allowing that to be omitted as well as
<p>.

(Having recently read a bunch of W3C specs, I'm tempted to suggest
that the root tag should be

<markup xmlns="http://www.pango.org/xml/pango-markup";>

But I can get over that temptation pretty quickly.)
 
>  - 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.

I think gtk_misc_set_alignment() is fine now:

 gtk_misc_set_alignment() - as always, except when widget flipped
 0.0 is right aligned instead of left aligned.

I think my plan for the other two was:

 GTK_JUSTIFY_PRIMARY   => (direction == GTK_TEXT_DIR_LTR ? PANGO_ALIGN_LEFT ? PANGO_ALIGN_RIGHT)
 GTK_JUSTIFY_SECONDARY => (direction == GTK_TEXT_DIR_LTR ? PANGO_ALIGN_RIGHT ? PANGO_ALIGN_LEFT)

And then make GTK_JUSTIFY_LEFT and GTK_JUSTIFY_RIGHT compatibility
aliases for GTK_JUSTIFY_PRIMARY and GTK_JUSTIFY_SECONDARY. 

The reason for this arrangement is that I don't want to have magic
flipping in Pango, but to go along with the rest of the magic
flipping in GTK+, we need GtkJustify to do it.
 
Though I don't seem to have implemented this yet. 

Regards,
                                        Owen




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