diff options
author | Owen Taylor <otaylor@redhat.com> | 2004-11-19 22:57:11 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2004-11-19 22:57:11 +0000 |
commit | 25eb23b0c27d6c447240fcf8505ad35a2a5a5d93 (patch) | |
tree | 52bcfb8069fb7bdfe31b0537da68f1f4338637ee /pango | |
parent | cb18309673f263d54eba9c312ab5802b4a6beb70 (diff) | |
download | pango-25eb23b0c27d6c447240fcf8505ad35a2a5a5d93.tar.gz |
Remove color_set() virtual function ... it's not absolutely necessary for
Fri Nov 19 17:44:33 2004 Owen Taylor <otaylor@redhat.com>
* pango/pango-renderer.[ch]: Remove color_set() virtual
function ... it's not absolutely necessary for chaining
renderers, and it's not clear that chaining renderers
is actually useful, anyways.
* pango/pango-renderer.[ch] (pango_renderer_set_color): Constify
color argument.
* pango/pango-render.c: Fix various bugs.
* pango/pango-attributes.[ch] (pango_attr_shape_new_with_data):
Add the ability to create a shape attribute with user data.
* pango/pango-renderer.[ch] (PangoRendererClass): Add a draw_shape
virtual function, to draw content for PangoAttrShape.
* pango/pangoxft-fontmap.c (pango_xft_shutdown_display):
Add note to docs that XCloseDisplay() will automatically take care
of releasing Pango's allocated resources for the display.
* docs/Makefile.am (SCAN_OPTIONS): Add the appropriate
--deprecated-guards option.
* docs/tmpl/xft-fonts.sgml: Add long description.
* docs/tmpl/x-fonts.sgml: Document as dead.
Diffstat (limited to 'pango')
-rw-r--r-- | pango/pango-attributes.c | 69 | ||||
-rw-r--r-- | pango/pango-attributes.h | 16 | ||||
-rw-r--r-- | pango/pango-renderer.c | 98 | ||||
-rw-r--r-- | pango/pango-renderer.h | 25 | ||||
-rw-r--r-- | pango/pango.def | 1 | ||||
-rw-r--r-- | pango/pangoxft-fontmap.c | 4 | ||||
-rw-r--r-- | pango/pangoxft-render.c | 3 | ||||
-rw-r--r-- | pango/pangoxft-render.h | 6 |
8 files changed, 155 insertions, 67 deletions
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index fd5be6fb..276f7acd 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -697,13 +697,25 @@ static PangoAttribute * pango_attr_shape_copy (const PangoAttribute *attr) { const PangoAttrShape *shape_attr = (PangoAttrShape *)attr; + gpointer data; + + if (shape_attr->copy_func) + data = shape_attr->copy_func (shape_attr->data); + else + data = shape_attr->data; - return pango_attr_shape_new (&shape_attr->ink_rect, &shape_attr->logical_rect); + return pango_attr_shape_new_with_data (&shape_attr->ink_rect, &shape_attr->logical_rect, + data, shape_attr->copy_func, shape_attr->destroy_func); } static void pango_attr_shape_destroy (PangoAttribute *attr) { + const PangoAttrShape *shape_attr = (PangoAttrShape *)attr; + + if (shape_attr->destroy_func) + shape_attr->destroy_func (shape_attr->data); + g_free (attr); } @@ -713,7 +725,7 @@ pango_attr_shape_equal (const PangoAttribute *attr1, { const PangoAttrShape *shape_attr1 = (const PangoAttrShape *)attr1; const PangoAttrShape *shape_attr2 = (const PangoAttrShape *)attr2; - + return (shape_attr1->logical_rect.x == shape_attr2->logical_rect.x && shape_attr1->logical_rect.y == shape_attr2->logical_rect.y && shape_attr1->logical_rect.width == shape_attr2->logical_rect.width && @@ -721,24 +733,35 @@ pango_attr_shape_equal (const PangoAttribute *attr1, shape_attr1->ink_rect.x == shape_attr2->ink_rect.x && shape_attr1->ink_rect.y == shape_attr2->ink_rect.y && shape_attr1->ink_rect.width == shape_attr2->ink_rect.width && - shape_attr1->ink_rect.height == shape_attr2->ink_rect.height); + shape_attr1->ink_rect.height == shape_attr2->ink_rect.height && + shape_attr1->data == shape_attr2->data); } /** - * pango_attr_shape_new: + * pango_attr_shape_new_with_data: * @ink_rect: ink rectangle to assign to each character * @logical_rect: logical rectangle assign to each character + * @data: user data pointer + * @copy_func: function to copy @data when the attribute + * is copied. If %NULL, @data is simply copied + * as a pointer. + * @destroy_func: function to free @data when the attribute + * is freed, or %NULL. * - * Create a new shape attribute. A shape is used to impose a - * particular ink and logical rect on the result of shaping a - * particular glyph. This might be used, for instance, for - * embedding a picture or a widget inside a PangoLayout. + * Like pango_attr_shape_new(), but a user data pointer is also + * provided; this pointer can be accessed when rendering later + * rendering the glyph. * * Return value: the newly created attribute + * + * Since: 1.8 **/ PangoAttribute * -pango_attr_shape_new (const PangoRectangle *ink_rect, - const PangoRectangle *logical_rect) +pango_attr_shape_new_with_data (const PangoRectangle *ink_rect, + const PangoRectangle *logical_rect, + gpointer data, + PangoAttrDataCopyFunc copy_func, + GDestroyNotify destroy_func) { static const PangoAttrClass klass = { PANGO_ATTR_SHAPE, @@ -756,10 +779,36 @@ pango_attr_shape_new (const PangoRectangle *ink_rect, result->attr.klass = &klass; result->ink_rect = *ink_rect; result->logical_rect = *logical_rect; + result->data = data; + result->copy_func = copy_func; + result->destroy_func = destroy_func; return (PangoAttribute *)result; } +/** + * pango_attr_shape_new: + * @ink_rect: ink rectangle to assign to each character + * @logical_rect: logical rectangle assign to each character + * + * Create a new shape attribute. A shape is used to impose a + * particular ink and logical rect on the result of shaping a + * particular glyph. This might be used, for instance, for + * embedding a picture or a widget inside a PangoLayout. + * + * Return value: the newly created attribute + **/ +PangoAttribute * +pango_attr_shape_new (const PangoRectangle *ink_rect, + const PangoRectangle *logical_rect) +{ + g_return_val_if_fail (ink_rect != NULL, NULL); + g_return_val_if_fail (logical_rect != NULL, NULL); + + return pango_attr_shape_new_with_data (ink_rect, logical_rect, + NULL, NULL, NULL); +} + GType pango_attr_list_get_type (void) { diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h index 04086c4e..643d15e8 100644 --- a/pango/pango-attributes.h +++ b/pango/pango-attributes.h @@ -103,6 +103,8 @@ struct _PangoAttribute typedef gboolean (*PangoAttrFilterFunc) (PangoAttribute *attribute, gpointer data); +typedef gpointer (*PangoAttrDataCopyFunc) (gconstpointer data); + struct _PangoAttrClass { /*< public >*/ @@ -147,6 +149,10 @@ struct _PangoAttrShape PangoAttribute attr; PangoRectangle ink_rect; PangoRectangle logical_rect; + + gpointer data; + PangoAttrDataCopyFunc copy_func; + GDestroyNotify destroy_func; }; struct _PangoAttrFontDesc @@ -179,12 +185,18 @@ PangoAttribute *pango_attr_font_desc_new (const PangoFontDescription *desc); PangoAttribute *pango_attr_underline_new (PangoUnderline underline); PangoAttribute *pango_attr_strikethrough_new (gboolean strikethrough); PangoAttribute *pango_attr_rise_new (int rise); -PangoAttribute *pango_attr_shape_new (const PangoRectangle *ink_rect, - const PangoRectangle *logical_rect); PangoAttribute *pango_attr_scale_new (double scale_factor); PangoAttribute *pango_attr_fallback_new (gboolean enable_fallback); PangoAttribute *pango_attr_letter_spacing_new (int letter_spacing); +PangoAttribute *pango_attr_shape_new (const PangoRectangle *ink_rect, + const PangoRectangle *logical_rect); +PangoAttribute *pango_attr_shape_new_with_data (const PangoRectangle *ink_rect, + const PangoRectangle *logical_rect, + gpointer data, + PangoAttrDataCopyFunc copy_func, + GDestroyNotify destroy_func); + GType pango_attr_list_get_type (void) G_GNUC_CONST; PangoAttrList * pango_attr_list_new (void); void pango_attr_list_ref (PangoAttrList *list); diff --git a/pango/pango-renderer.c b/pango/pango-renderer.c index 252a8d79..cbdadb46 100644 --- a/pango/pango-renderer.c +++ b/pango/pango-renderer.c @@ -196,8 +196,11 @@ draw_underline (PangoRenderer *renderer, LineState *state) { PangoRectangle *rect = &state->underline_rect; + PangoUnderline underline = state->underline; - switch (state->underline) + state->underline = PANGO_UNDERLINE_NONE; + + switch (underline) { case PANGO_UNDERLINE_NONE: break; @@ -226,8 +229,6 @@ draw_underline (PangoRenderer *renderer, 3 * rect->height); break; } - - state->underline = PANGO_UNDERLINE_NONE; } static void @@ -235,16 +236,17 @@ draw_strikethrough (PangoRenderer *renderer, LineState *state) { PangoRectangle *rect = &state->strikethrough_rect; + gboolean strikethrough = state->strikethrough; - if (state->strikethrough) + state->strikethrough = FALSE; + + if (strikethrough) pango_renderer_draw_rectangle (renderer, PANGO_RENDER_PART_STRIKETHROUGH, rect->x, rect->y, rect->width, rect->height); - - state->strikethrough = FALSE; } static void @@ -264,6 +266,7 @@ handle_line_state_change (PangoRenderer *renderer, draw_underline (renderer, state); state->underline = renderer->underline; rect->x = state->logical_rect_end; + rect->width = 0; } if (part == PANGO_RENDER_PART_STRIKETHROUGH && @@ -275,6 +278,7 @@ handle_line_state_change (PangoRenderer *renderer, draw_underline (renderer, state); state->underline = renderer->underline; rect->x = state->logical_rect_end; + rect->width = 0; } } @@ -381,19 +385,17 @@ add_strikethrough (PangoRenderer *renderer, } static void -get_item_properties (PangoItem *item, - gint *rise, - gboolean *shape_set, - PangoRectangle *ink_rect, - PangoRectangle *logical_rect) +get_item_properties (PangoItem *item, + gint *rise, + PangoAttrShape **shape_attr) { GSList *l; if (rise) *rise = 0; - if (shape_set) - *shape_set = FALSE; + if (shape_attr) + *shape_attr = NULL; for (l = item->analysis.extra_attrs; l; l = l->next) { @@ -402,12 +404,8 @@ get_item_properties (PangoItem *item, switch (attr->klass->type) { case PANGO_ATTR_SHAPE: - if (shape_set) - *shape_set = TRUE; - if (logical_rect) - *logical_rect = ((PangoAttrShape *)attr)->logical_rect; - if (ink_rect) - *ink_rect = ((PangoAttrShape *)attr)->ink_rect; + if (shape_attr) + *shape_attr = (PangoAttrShape *)attr; break; case PANGO_ATTR_RISE: @@ -421,6 +419,29 @@ get_item_properties (PangoItem *item, } } +static void +draw_shaped_glyphs (PangoRenderer *renderer, + PangoGlyphString *glyphs, + PangoAttrShape *attr, + int x, + int y) +{ + PangoRendererClass *class = PANGO_RENDERER_GET_CLASS (renderer); + int i; + + if (!class->draw_shape) + return; + + for (i = 0; i < glyphs->num_glyphs; i++) + { + PangoGlyphInfo *gi = &glyphs->glyphs[i]; + + class->draw_shape (renderer, attr, x, y); + + x += gi->geometry.width; + } +} + /** * pango_renderer_draw_layout_line: * @renderer: a #PangoRenderer @@ -470,17 +491,20 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer, PangoFontMetrics *metrics; gint rise; PangoLayoutRun *run = l->data; + PangoAttrShape *shape_attr; PangoRectangle logical_rect; PangoRectangle ink_rect; - gboolean shape_set; pango_renderer_prepare_run (renderer, run); - get_item_properties (run->item, - &rise, - &shape_set, &ink_rect, &logical_rect); + get_item_properties (run->item, &rise, &shape_attr); - if (!shape_set) + if (shape_attr) + { + ink_rect = shape_attr->ink_rect; + logical_rect = shape_attr->logical_rect; + } + else { if (renderer->underline != PANGO_UNDERLINE_NONE || renderer->strikethrough) @@ -491,7 +515,7 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer, NULL, &logical_rect); } - state.logical_rect_end = x_off + logical_rect.x + logical_rect.width; + state.logical_rect_end = x + x_off + logical_rect.x + logical_rect.width; if (renderer->priv->color_set[PANGO_RENDER_PART_BACKGROUND]) { @@ -509,19 +533,16 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer, overall_rect.height); } - if (!shape_set) + if (shape_attr) { - pango_renderer_draw_glyphs (renderer, - run->item->analysis.font, run->glyphs, - x + x_off, y - rise); + draw_shaped_glyphs (renderer, run->glyphs, shape_attr, x + x_off, y - rise); } -#if 0 else { - pango_renderer_draw_shaped (renderer, + pango_renderer_draw_glyphs (renderer, + run->item->analysis.font, run->glyphs, x + x_off, y - rise); } -#endif if (renderer->underline != PANGO_UNDERLINE_NONE || renderer->strikethrough) @@ -1015,15 +1036,13 @@ pango_renderer_deactivate (PangoRenderer *renderer) * Since: 1.8 **/ void -pango_renderer_set_color (PangoRenderer *renderer, - PangoRenderPart part, - PangoColor *color) +pango_renderer_set_color (PangoRenderer *renderer, + PangoRenderPart part, + const PangoColor *color) { g_return_if_fail (PANGO_IS_RENDERER (renderer)); g_return_if_fail (IS_VALID_PART (part)); - pango_renderer_part_changed (renderer, part); - if ((!color && !renderer->priv->color_set[part]) || (color && renderer->priv->color_set[part] && renderer->priv->color[part].red == color->red && @@ -1031,6 +1050,8 @@ pango_renderer_set_color (PangoRenderer *renderer, renderer->priv->color[part].blue == color->blue)) return; + pango_renderer_part_changed (renderer, part); + if (color) { renderer->priv->color_set[part] = TRUE; @@ -1040,9 +1061,6 @@ pango_renderer_set_color (PangoRenderer *renderer, { renderer->priv->color_set[part] = FALSE; } - - if (PANGO_RENDERER_GET_CLASS (renderer)->color_set) - PANGO_RENDERER_GET_CLASS (renderer)->color_set (renderer, part, color); } /** diff --git a/pango/pango-renderer.h b/pango/pango-renderer.h index 5c587f85..eace2967 100644 --- a/pango/pango-renderer.h +++ b/pango/pango-renderer.h @@ -91,12 +91,13 @@ struct _PangoRenderer * @draw_error_underline: draws a squiggly line that approximately * covers the given rectangle in the style of an underline used to * indicate a spelling error. + * @draw_shape: draw content for a glyph shaped with #PangoAttrShape. + * @x, @y are the coordinates of the left edge of the baseline, + * in user coordinates. * @draw_trapezoid: draws a trapezoidal filled area * @draw_glyph: draws a single glyph * @part_changed: do renderer specific processing when rendering * attributes change - * @color_set: updates the renderer when a color has changed. - * if @color is %NULL, means that the color has been unset * @begin: Do renderer-specific initialization before drawing * @end: Do renderer-specific cleanup after drawing * @prepare_run: updates the renderer for a new run @@ -133,6 +134,12 @@ struct _PangoRendererClass int width, int height); + /* Nothing is drawn for shaped glyphs unless this is implemented */ + void (*draw_shape) (PangoRenderer *renderer, + PangoAttrShape *attr, + int x, + int y); + /* These two must be implemented and take coordinates in * device space as doubles. */ @@ -154,9 +161,6 @@ struct _PangoRendererClass */ void (*part_changed) (PangoRenderer *renderer, PangoRenderPart part); - void (*color_set) (PangoRenderer *renderer, - PangoRenderPart part, - PangoColor *color); /* Paired around drawing operations */ @@ -222,11 +226,12 @@ void pango_renderer_deactivate (PangoRenderer *renderer); void pango_renderer_part_changed (PangoRenderer *renderer, PangoRenderPart part); -void pango_renderer_set_color (PangoRenderer *renderer, - PangoRenderPart part, - PangoColor *color); -PangoColor *pango_renderer_get_color (PangoRenderer *renderer, - PangoRenderPart part); + +void pango_renderer_set_color (PangoRenderer *renderer, + PangoRenderPart part, + const PangoColor *color); +PangoColor *pango_renderer_get_color (PangoRenderer *renderer, + PangoRenderPart part); void pango_renderer_set_matrix (PangoRenderer *renderer, const PangoMatrix *matrix); diff --git a/pango/pango.def b/pango/pango.def index 1c62ea5b..5b9f2e1a 100644 --- a/pango/pango.def +++ b/pango/pango.def @@ -28,6 +28,7 @@ EXPORTS pango_attr_rise_new pango_attr_scale_new pango_attr_shape_new + pango_attr_shape_new_with_data pango_attr_size_new pango_attr_stretch_new pango_attr_strikethrough_new diff --git a/pango/pangoxft-fontmap.c b/pango/pangoxft-fontmap.c index cc3f62b5..c7af76a1 100644 --- a/pango/pangoxft-fontmap.c +++ b/pango/pangoxft-fontmap.c @@ -213,7 +213,9 @@ pango_xft_get_font_map (Display *display, * @screen: the screen number of a screen within @display * * Release any resources that have been cached for the - * combination of @display and @screen. + * combination of @display and @screen. Note that when the + * X display is closed, resources are released automatically, + * without needing to call this function. * * Since: 1.2 **/ diff --git a/pango/pangoxft-render.c b/pango/pangoxft-render.c index 145b6f59..1c156405 100644 --- a/pango/pangoxft-render.c +++ b/pango/pangoxft-render.c @@ -777,7 +777,8 @@ pango_xft_picture_render (Display *display, * @screen: the index of the screen for @display to which rendering will be done * * Create a new #PangoXftRenderer to allow rendering Pango objects - * with the Xft library. + * with the Xft library. You must call pango_xft_renderer_set_draw() before + * using the renderer. * * Return value: the newly created #PangoXftRenderer object. Unref * with g_object_unref() when you are finished with it. diff --git a/pango/pangoxft-render.h b/pango/pangoxft-render.h index 00390928..2d12df05 100644 --- a/pango/pangoxft-render.h +++ b/pango/pangoxft-render.h @@ -73,10 +73,10 @@ struct _PangoXftRenderer * @composite_trapezoids: draw the specified trapezoids using * the current color and other attributes for @part * @composite_glyphs: draw the specified glyphs using - * the current color and other attributes for @part + * the current foreground color and other foreground + * attributes * - * #PangoXftRenderer is a subclass of #PangoRenderer used for rendering - * Renders a #PangoGlyphString onto an Xrender <type>Picture</type> object. + * The class structure for #PangoXftRenderer * * Since: 1.8 */ |