Commit 6ab23d28 authored by Dom Lachowicz's avatar Dom Lachowicz

bug 126102

parent 23d11fe3
......@@ -62,6 +62,7 @@ rsvg_state_init (RsvgState *state)
state->font_weight = PANGO_WEIGHT_NORMAL;
state->font_stretch = PANGO_STRETCH_NORMAL;
state->text_dir = PANGO_DIRECTION_LTR;
state->text_anchor = TEXT_ANCHOR_START;
state->visible = TRUE;
}
......@@ -232,6 +233,20 @@ rsvg_parse_style_arg (RsvgHandle *ctx, RsvgState *state, const char *str)
else
state->text_dir = PANGO_DIRECTION_LTR;
}
else if (rsvg_css_param_match (str, "text-anchor"))
{
if (!strcmp (str + arg_off, "inherit"))
state->text_anchor = parent_state->text_anchor;
else
{
if (strstr (str + arg_off, "start"))
state->text_anchor = TEXT_ANCHOR_START;
else if (strstr (str + arg_off, "middle"))
state->text_anchor = TEXT_ANCHOR_MIDDLE;
else if (strstr (str + arg_off, "end") )
state->text_anchor = TEXT_ANCHOR_END;
}
}
else if (rsvg_css_param_match (str, "stop-color"))
{
state->stop_color = rsvg_css_parse_color (str + arg_off);
......@@ -327,6 +342,7 @@ rsvg_is_style_arg(const char *str)
g_hash_table_insert (styles, "stroke-miterlimit", GINT_TO_POINTER (TRUE));
g_hash_table_insert (styles, "stroke-opacity", GINT_TO_POINTER (TRUE));
g_hash_table_insert (styles, "stroke-width", GINT_TO_POINTER (TRUE));
g_hash_table_insert (styles, "text-anchor", GINT_TO_POINTER (TRUE));
g_hash_table_insert (styles, "text-decoration", GINT_TO_POINTER (TRUE));
g_hash_table_insert (styles, "visibility", GINT_TO_POINTER (TRUE));
g_hash_table_insert (styles, "writing-mode", GINT_TO_POINTER (TRUE));
......
......@@ -45,6 +45,12 @@ enum {
TEXT_STRIKE = 0x04
};
typedef enum {
TEXT_ANCHOR_START,
TEXT_ANCHOR_MIDDLE,
TEXT_ANCHOR_END
} TextAnchor;
typedef struct {
double affine[6];
......@@ -69,7 +75,8 @@ typedef struct {
PangoWeight font_weight;
PangoStretch font_stretch;
TextDecoration font_decor;
PangoDirection text_dir;
PangoDirection text_dir;
TextAnchor text_anchor;
guint text_offset;
......
......@@ -123,7 +123,7 @@ rsvg_text_handler_characters (RsvgSaxHandler *self, const xmlChar *ch, int len)
PangoLayout *layout;
PangoFontDescription *font;
PangoLayoutLine *line;
PangoRectangle ink_rect, line_ink_rect;
PangoRectangle ink_rect, line_ink_rect, logical_rect;
FT_Bitmap bitmap;
state = rsvg_state_current (ctx);
......@@ -219,8 +219,34 @@ rsvg_text_handler_characters (RsvgSaxHandler *self, const xmlChar *ch, int len)
bitmap.pixel_mode = ft_pixel_mode_grays;
pango_ft2_render_layout (&bitmap, layout, -ink_rect.x, -ink_rect.y);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
if ((state->text_dir == PANGO_DIRECTION_RTL) ||
(state->text_dir == PANGO_DIRECTION_LTR)) {
switch (state->text_anchor) {
case TEXT_ANCHOR_MIDDLE:
logical_rect.width /= 2;
break;
case TEXT_ANCHOR_END:
break;
default:
logical_rect.width = 0;
break;
}
logical_rect.height = 0;
} else {
switch (state->text_anchor) {
case TEXT_ANCHOR_MIDDLE:
logical_rect.height /= 2;
break;
case TEXT_ANCHOR_END:
break;
default:
logical_rect.height = 0;
break;
}
logical_rect.width = 0;
}
g_object_unref (layout);
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
render = art_render_new (0, 0,
gdk_pixbuf_get_width (pixbuf),
......@@ -239,10 +265,10 @@ rsvg_text_handler_characters (RsvgSaxHandler *self, const xmlChar *ch, int len)
art_render_mask_solid (render, opacity);
art_render_mask (render,
state->affine[4] + line_ink_rect.x + state->text_offset,
state->affine[5] + line_ink_rect.y,
state->affine[4] + line_ink_rect.x + bitmap.width + state->text_offset,
state->affine[5] + line_ink_rect.y + bitmap.rows,
state->affine[4] + line_ink_rect.x + state->text_offset - logical_rect.width,
state->affine[5] + line_ink_rect.y - logical_rect.height,
state->affine[4] + line_ink_rect.x + bitmap.width + state->text_offset - logical_rect.width,
state->affine[5] + line_ink_rect.y + bitmap.rows - logical_rect.height,
bitmap.buffer, bitmap.pitch);
art_render_invoke (render);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment