summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2000-07-02 22:04:51 +0000
committerOwen Taylor <otaylor@src.gnome.org>2000-07-02 22:04:51 +0000
commit8e49176b74e6b7730f298dcfb61baa1aadd36065 (patch)
tree7cfddc9baa08e23d56a90645e597336ab9ac65be /pango
parent6870ed61201c6c8545c59861a148647e39a3b7ed (diff)
downloadpango-8e49176b74e6b7730f298dcfb61baa1aadd36065.tar.gz
New function that inserts before other attributes with matching start
Sun Jul 2 17:59:56 2000 Owen Taylor <otaylor@redhat.com> * pango/pango-attributes.[ch] (pango_attr_list_insert_before): New function that inserts before other attributes with matching start index. * pango/pango-layout.[ch] (pango_layout_set_font_description): Add the ability to set a default font description on the layout, overriding the font description from the context.
Diffstat (limited to 'pango')
-rw-r--r--pango/pango-attributes.c65
-rw-r--r--pango/pango-attributes.h16
-rw-r--r--pango/pango-layout.c75
-rw-r--r--pango/pango-layout.h32
4 files changed, 142 insertions, 46 deletions
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 695fa0f8..a688cab6 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -649,31 +649,21 @@ pango_attr_list_copy (PangoAttrList *list)
return new;
}
-/**
- * pango_attr_list_insert:
- * @list: a #PangoAttrList
- * @attr: the attribute to insert. Ownership of this value is
- * assumed by the list.
- *
- * Insert the given attribute into the #PangoAttrList. It will
- * be inserted after all other attributes with a matching
- * @start_index.
- **/
-void
-pango_attr_list_insert (PangoAttrList *list,
- PangoAttribute *attr)
+static void
+pango_attr_list_insert_internal (PangoAttrList *list,
+ PangoAttribute *attr,
+ gboolean before)
{
GSList *tmp_list, *prev, *link;
gint start_index = attr->start_index;
- g_return_if_fail (list != NULL);
-
if (!list->attributes)
{
list->attributes = g_slist_prepend (NULL, attr);
list->attributes_tail = list->attributes;
}
- else if (((PangoAttribute *)list->attributes_tail->data)->start_index <= start_index)
+ else if (((PangoAttribute *)list->attributes_tail->data)->start_index < start_index ||
+ (!before && ((PangoAttribute *)list->attributes_tail->data)->start_index == start_index))
{
g_slist_append (list->attributes_tail, attr);
}
@@ -685,7 +675,8 @@ pango_attr_list_insert (PangoAttrList *list,
{
PangoAttribute *tmp_attr = tmp_list->data;
- if (tmp_attr->start_index > start_index)
+ if (tmp_attr->start_index > start_index ||
+ (before && tmp_attr->start_index == start_index))
{
link = g_slist_alloc ();
link->next = tmp_list;
@@ -707,6 +698,46 @@ pango_attr_list_insert (PangoAttrList *list,
}
/**
+ * pango_attr_list_insert:
+ * @list: a #PangoAttrList
+ * @attr: the attribute to insert. Ownership of this value is
+ * assumed by the list.
+ *
+ * Insert the given attribute into the #PangoAttrList. It will
+ * be inserted after all other attributes with a matching
+ * @start_index.
+ **/
+void
+pango_attr_list_insert (PangoAttrList *list,
+ PangoAttribute *attr)
+{
+ g_return_if_fail (list != NULL);
+ g_return_if_fail (attr != NULL);
+
+ pango_attr_list_insert_internal (list, attr, FALSE);
+}
+
+/**
+ * pango_attr_list_insert_before:
+ * @list: a #PangoAttrList
+ * @attr: the attribute to insert. Ownership of this value is
+ * assumed by the list.
+ *
+ * Insert the given attribute into the #PangoAttrList. It will
+ * be inserted before all other attributes with a matching
+ * @start_index.
+ **/
+void
+pango_attr_list_insert_before (PangoAttrList *list,
+ PangoAttribute *attr)
+{
+ g_return_if_fail (list != NULL);
+ g_return_if_fail (attr != NULL);
+
+ pango_attr_list_insert_internal (list, attr, TRUE);
+}
+
+/**
* pango_attr_list_change:
* @list: a #PangoAttrList
* @attr: the attribute to insert. Ownership of this value is
diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h
index 3e34d011..3670163e 100644
--- a/pango/pango-attributes.h
+++ b/pango/pango-attributes.h
@@ -128,15 +128,17 @@ PangoAttribute *pango_attr_underline_new (PangoUnderline underl
PangoAttribute *pango_attr_strikethrough_new (gboolean strikethrough);
PangoAttribute *pango_attr_rise_new (int rise);
-PangoAttrList * pango_attr_list_new (void);
-void pango_attr_list_ref (PangoAttrList *list);
-void pango_attr_list_unref (PangoAttrList *list);
-PangoAttrList * pango_attr_list_copy (PangoAttrList *list);
-void pango_attr_list_insert (PangoAttrList *list,
+PangoAttrList * pango_attr_list_new (void);
+void pango_attr_list_ref (PangoAttrList *list);
+void pango_attr_list_unref (PangoAttrList *list);
+PangoAttrList * pango_attr_list_copy (PangoAttrList *list);
+void pango_attr_list_insert (PangoAttrList *list,
PangoAttribute *attr);
-void pango_attr_list_change (PangoAttrList *list,
+void pango_attr_list_insert_before (PangoAttrList *list,
PangoAttribute *attr);
-PangoAttrIterator * pango_attr_list_get_iterator (PangoAttrList *list);
+void pango_attr_list_change (PangoAttrList *list,
+ PangoAttribute *attr);
+PangoAttrIterator *pango_attr_list_get_iterator (PangoAttrList *list);
void pango_attr_iterator_range (PangoAttrIterator *iterator,
gint *start,
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index abcc7f5b..f8afe07a 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -39,6 +39,8 @@ struct _PangoLayout
PangoContext *context;
PangoAttrList *attrs;
+ PangoFontDescription *font_desc;
+
gchar *text;
int length; /* length of text in bytes */
int width; /* wrap width, in device units */
@@ -115,6 +117,7 @@ static void
pango_layout_init (PangoLayout *layout)
{
layout->attrs = NULL;
+ layout->font_desc = NULL;
layout->text = NULL;
layout->length = 0;
layout->width = -1;
@@ -335,6 +338,34 @@ pango_layout_set_attributes (PangoLayout *layout,
}
/**
+ * pango_layout_set_font_description:
+ * @layout: a #PangoLayout
+ * @desc: the new pango font description, or %NULL to unset the
+ * current font description.
+ *
+ * Set the default font description for the layout. If no font
+ * description is set on the layout, the font description from
+ * the layout's context is used.
+ **/
+void
+pango_layout_set_font_description (PangoLayout *layout,
+ const PangoFontDescription *desc)
+{
+ g_return_if_fail (layout != NULL);
+ g_return_if_fail (desc != NULL);
+
+ if (layout->font_desc)
+ pango_font_description_free (layout->font_desc);
+
+ if (desc)
+ layout->font_desc = pango_font_description_copy (desc);
+ else
+ layout->font_desc = NULL;
+
+ pango_layout_clear_lines (layout);
+}
+
+/**
* pango_layout_set_justify:
* @layout: a #PangoLayout
* @justify: whether the lines in the layout should be justified.
@@ -1758,6 +1789,8 @@ pango_layout_check_lines (PangoLayout *layout)
do
{
PangoLayoutLine *line;
+ PangoAttrList *attrs;
+
GList *items, *tmp_list;
gboolean last_cant_end = FALSE;
gboolean current_cant_end = FALSE;
@@ -1776,16 +1809,34 @@ pango_layout_check_lines (PangoLayout *layout)
if (end == layout->text + layout->length)
done = TRUE;
- /* FIXME, should we force people to set the attrs? */
if (layout->attrs)
- items = pango_itemize (layout->context, start, end - start, 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)
{
- PangoAttrList *attrs = pango_attr_list_new ();
- items = pango_itemize (layout->context, start, end - start, attrs);
- pango_attr_list_unref (attrs);
+ 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);
+
get_para_log_attrs (start, items, layout->log_attrs + start_offset);
line = pango_layout_line_new (layout);
@@ -2260,8 +2311,15 @@ pango_layout_line_get_empty_extents (PangoLayoutLine *line,
if (start <= index && index < end)
{
+ PangoFontDescription *base_font_desc;
+
+ if (layout->font_desc)
+ base_font_desc = layout->font_desc;
+ else
+ base_font_desc = pango_context_get_font_description (layout->context);
+
pango_attr_iterator_get_font (iter,
- pango_context_get_font_description (layout->context),
+ base_font_desc,
&font_desc,
NULL);
break;
@@ -2274,7 +2332,10 @@ pango_layout_line_get_empty_extents (PangoLayoutLine *line,
}
else
{
- font_desc = *pango_context_get_font_description (layout->context);
+ if (layout->font_desc)
+ font_desc = *layout->font_desc;
+ else
+ font_desc = *pango_context_get_font_description (layout->context);
}
font = pango_context_load_font (layout->context, &font_desc);
diff --git a/pango/pango-layout.h b/pango/pango-layout.h
index 516b867a..91e22605 100644
--- a/pango/pango-layout.h
+++ b/pango/pango-layout.h
@@ -77,21 +77,23 @@ void pango_layout_set_text (PangoLayout *layout,
const char *text,
int length);
-void pango_layout_set_width (PangoLayout *layout,
- int width);
-int pango_layout_get_width (PangoLayout *layout);
-void pango_layout_set_indent (PangoLayout *layout,
- int indent);
-int pango_layout_get_indent (PangoLayout *layout);
-void pango_layout_set_spacing (PangoLayout *layout,
- int spacing);
-int pango_layout_get_spacing (PangoLayout *layout);
-void pango_layout_set_justify (PangoLayout *layout,
- gboolean justify);
-gboolean pango_layout_get_justify (PangoLayout *layout);
-void pango_layout_set_alignment (PangoLayout *layout,
- PangoAlignment alignment);
-PangoAlignment pango_layout_get_alignment (PangoLayout *layout);
+void pango_layout_set_font_description (PangoLayout *layout,
+ const PangoFontDescription *desc);
+void pango_layout_set_width (PangoLayout *layout,
+ int width);
+int pango_layout_get_width (PangoLayout *layout);
+void pango_layout_set_indent (PangoLayout *layout,
+ int indent);
+int pango_layout_get_indent (PangoLayout *layout);
+void pango_layout_set_spacing (PangoLayout *layout,
+ int spacing);
+int pango_layout_get_spacing (PangoLayout *layout);
+void pango_layout_set_justify (PangoLayout *layout,
+ gboolean justify);
+gboolean pango_layout_get_justify (PangoLayout *layout);
+void pango_layout_set_alignment (PangoLayout *layout,
+ PangoAlignment alignment);
+PangoAlignment pango_layout_get_alignment (PangoLayout *layout);
void pango_layout_context_changed (PangoLayout *layout);