summaryrefslogtreecommitdiff
path: root/pango/pango-layout.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@pobox.com>2000-11-01 06:46:29 +0000
committerHavoc Pennington <hp@src.gnome.org>2000-11-01 06:46:29 +0000
commitb00a32cc4f7b8783d673f31502b4ef3555486995 (patch)
tree2a035c680e76bdfa121585577de26a4796e46345 /pango/pango-layout.c
parent717a0b958c4616753798250985558cab328a6837 (diff)
downloadpango-b00a32cc4f7b8783d673f31502b4ef3555486995.tar.gz
Add a new attribute for scaling a font; also required adding
2000-11-01 Havoc Pennington <hp@pobox.com> * pango/pango-attributes.c (pango_attr_scale_new): Add a new attribute for scaling a font; also required adding PangoAttrFloat. (pango_attr_iterator_get_font): Add PANGO_ATTR_SCALE handling. * pango/pango-utils.c (pango_parse_stretch): Take a plain string not a GString (pango_parse_weight): ditto (pango_parse_variant): ditto (pango_parse_style): ditto * pango/pangox-fontmap.c (pango_x_font_map_read_alias_file): pass GString::str instead of the GString itself to pango_parse_* * pango/pangoft2-fontmap.c (pango_ft2_insert_face): ditto * pango/pangowin32-fontmap.c (pango_win32_font_map_read_alias_file): ditto * pango/pango-layout.c (get_tab_pos): adapt to new pango_itemize() signature (pango_layout_check_lines): Raise attr list copy/creation out of the loop over paragraphs. Adapt to pango_itemize() changes. * pango/pango-context.c (pango_itemize): pass in a starting index and a cached iterator (add_engines): Easy optimization, pass in n_chars instead of recomputing it. Also, pass on the start index and cached iterator. * docs/pango-sections.txt: Add new stuff docs/pango_markup.sgml: Docs on markup format * pango/pango-layout.c (pango_layout_get_attributes): New function to retrieve the AttrList from a layout (pango_layout_set_markup): Set layout from markup (pango_layout_set_markup_with_accel): Set layout from markup including accelerator parsing. * pango/pango-attributes.h (pango_parse_markup): New function to convert a tag string to an attribute list * pango/pango-markup.c (pango_parse_markup): implement * docs/Makefile.am, docs/pango-docs.sgml, docs/pango-sections.txt, docs/pango_markup.sgml: oooooh, documentation for the above patch! * docs/tmpl/pango-unused.sgml: Remove from CVS; just causes problems, and was full of checked-in conflict markers.
Diffstat (limited to 'pango/pango-layout.c')
-rw-r--r--pango/pango-layout.c147
1 files changed, 115 insertions, 32 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 4db0a3e4..2736a7e8 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -352,6 +352,22 @@ pango_layout_set_attributes (PangoLayout *layout,
}
/**
+ * pango_layout_get_attributes:
+ * @layout: a #PangoLayout
+ *
+ * Returns the attribute list for the layout, if any
+ *
+ * Return value: a #PangoAttrList
+ **/
+PangoAttrList*
+pango_layout_get_attributes (PangoLayout *layout)
+{
+ g_return_val_if_fail (PANGO_IS_LAYOUT (layout), NULL);
+
+ return layout->attrs;
+}
+
+/**
* pango_layout_set_font_description:
* @layout: a #PangoLayout
* @desc: the new pango font description, or %NULL to unset the
@@ -557,6 +573,65 @@ pango_layout_set_text (PangoLayout *layout,
pango_layout_clear_lines (layout);
}
+void
+pango_layout_set_markup (PangoLayout *layout,
+ const char *markup,
+ int length)
+{
+ pango_layout_set_markup_with_accel (layout, markup, length, 0, NULL);
+}
+
+/**
+ * pango_layout_set_markup_with_accel:
+ * @layout: a #PangoLayout
+ * @markup: some marked-up text (see <link linkend="PangoMarkupFormat">markup format</link>)
+ * @length: length of @markup in bytes
+ * @accel_marker: marker for accelerators in the text
+ * @accel_char: return location for any located accelerators
+ *
+ * Sets the layout text and attribute list from marked-up text (see
+ * <link linkend="PangoMarkupFormat">markup format</link>). Replaces
+ * the current text and attribute list.
+ *
+ * If @accel_marker is nonzero, the given character will mark the
+ * character following it as an accelerator. For example, the accel
+ * marker might be an ampersand or underscore. All characters marked
+ * as an accelerator will receive a %PANGO_UNDERLINE_LOW attribute,
+ * and the first character so marked will be returned in @accel_char.
+ * Two @accel_marker characters following each other produce a single
+ * literal @accel_marker character.
+ **/
+void
+pango_layout_set_markup_with_accel (PangoLayout *layout,
+ const char *markup,
+ int length,
+ gunichar accel_marker,
+ gunichar *accel_char)
+{
+ PangoAttrList *list = NULL;
+ char *text = NULL;
+ GError *error;
+
+ g_return_if_fail (PANGO_IS_LAYOUT (layout));
+ g_return_if_fail (markup != NULL);
+
+ error = NULL;
+ if (!pango_parse_markup (markup, length,
+ accel_marker,
+ &list, &text,
+ accel_char,
+ &error))
+ {
+ g_warning ("%s: %s", G_STRLOC, error->message);
+ g_error_free (error);
+ return;
+ }
+
+ pango_layout_set_text (layout, text, -1);
+ pango_layout_set_attributes (layout, list);
+ pango_attr_list_unref (list);
+}
+
/**
* pango_layout_context_changed:
* @layout: a #PangoLayout
@@ -1807,7 +1882,7 @@ get_tab_pos (PangoLayout *layout, int index)
pango_attr_list_insert_before (attrs, attr);
}
- items = pango_itemize (layout->context, " ", 1, attrs);
+ items = pango_itemize (layout->context, " ", 0, 1, attrs, NULL);
pango_attr_list_unref (attrs);
item = items->data;
@@ -2028,7 +2103,9 @@ pango_layout_check_lines (PangoLayout *layout)
const char *start;
gboolean done = FALSE;
int start_offset;
-
+ PangoAttrList *attrs;
+ PangoAttrIterator *iter;
+
if (layout->lines)
return;
@@ -2039,6 +2116,31 @@ pango_layout_check_lines (PangoLayout *layout)
*/
if (!layout->text)
pango_layout_set_text (layout, NULL, 0);
+
+ if (layout->attrs)
+ {
+ /* If we were being clever, we'd try to catch the case here
+ * where the set font desc doesn't change the font for any
+ * characters.
+ */
+ if (layout->font_desc)
+ attrs = pango_attr_list_copy (layout->attrs);
+ else
+ attrs = layout->attrs;
+ }
+ else
+ attrs = pango_attr_list_new ();
+
+ if (layout->font_desc)
+ {
+ PangoAttribute *attr = pango_attr_font_desc_new (layout->font_desc);
+ attr->start_index = 0;
+ attr->end_index = layout->length;
+
+ pango_attr_list_insert_before (attrs, attr);
+ }
+
+ iter = pango_attr_list_get_iterator (attrs);
layout->log_attrs = g_new (PangoLogAttr, layout->n_chars);
@@ -2046,9 +2148,7 @@ pango_layout_check_lines (PangoLayout *layout)
start = layout->text;
do
{
- PangoLayoutLine *line;
- PangoAttrList *attrs;
-
+ PangoLayoutLine *line;
GList *items, *tmp_list;
gboolean last_cant_end = FALSE;
gboolean current_cant_end = FALSE;
@@ -2067,33 +2167,13 @@ pango_layout_check_lines (PangoLayout *layout)
if (end == layout->text + layout->length)
done = TRUE;
- if (layout->attrs)
- {
- /* If we were being clever, we'd try to catch the case here
- * where the set font desc doesn't change the font for any
- * characters.
- */
- if (layout->font_desc)
- attrs = pango_attr_list_copy (layout->attrs);
- else
- attrs = layout->attrs;
- }
- else
- attrs = pango_attr_list_new ();
- if (layout->font_desc)
- {
- PangoAttribute *attr = pango_attr_font_desc_new (layout->font_desc);
- attr->start_index = 0;
- attr->end_index = layout->length;
-
- pango_attr_list_insert_before (attrs, attr);
- }
-
- items = pango_itemize (layout->context, start, end - start, attrs);
-
- if (attrs != layout->attrs)
- pango_attr_list_unref (attrs);
+ items = pango_itemize (layout->context,
+ layout->text,
+ start - layout->text,
+ end - start,
+ attrs,
+ iter);
get_para_log_attrs (start, items, layout->log_attrs + start_offset);
@@ -2107,7 +2187,7 @@ pango_layout_check_lines (PangoLayout *layout)
BreakResult result;
int old_num_chars = item->num_chars;
- result = process_item (line, item, start,
+ result = process_item (line, item, layout->text,
layout->log_attrs + start_offset,
(line->runs == NULL) || last_cant_end,
current_cant_end,
@@ -2201,6 +2281,9 @@ pango_layout_check_lines (PangoLayout *layout)
}
}
while (!done);
+
+ if (attrs != layout->attrs)
+ pango_attr_list_unref (attrs);
layout->lines = g_slist_reverse (layout->lines);
}