Commit 2c51aa87 authored by Dom Lachowicz's avatar Dom Lachowicz Committed by Dom Lachowicz

Committed patch from Kouhei Sutou <kou@cozmixng.org> that makes librsvg

2006-08-22  Dom Lachowicz <cinamod@hotmail.com>

	* Bug 344116: Committed patch from Kouhei Sutou <kou@cozmixng.org>
	that makes librsvg use Pango-Cairo instead of PangoFT2+rendering
	text as a path. This patch is disabled for now, as it crashes on
	at least 5 known SVGs (see bug 344116)
parent 678517bb
2006-08-22 Dom Lachowicz <cinamod@hotmail.com>
* Bug 344116: Committed patch from Kouhei Sutou <kou@cozmixng.org>
that makes librsvg use Pango-Cairo instead of PangoFT2+rendering
text as a path. This patch is disabled for now, as it crashes on
at least 5 known SVGs (see bug 344116)
2006-08-22 Dom Lachowicz <cinamod@hotmail.com>
* rsvg-base.c (rsvg_handle_write_impl): Have libxml2 replace entities
......
......@@ -8,6 +8,7 @@ GLIB_REQUIRED=2.11.0
LIBXML_REQUIRED=2.4.7
CAIRO_REQUIRED=1.2.0
PANGOFT2_REQUIRED=1.2.0
PANGOCAIRO_REQUIRED=1.2.0
AC_SUBST(GDK_PIXBUF_REQUIRED)
AC_SUBST(GLIB_REQUIRED)
......@@ -86,10 +87,12 @@ PKG_CHECK_MODULES(LIBRSVG, \
glib-2.0 >= $GLIB_REQUIRED \
libxml-2.0 >= $LIBXML_REQUIRED \
pangoft2 >= $PANGOFT2_REQUIRED \
pangocairo >= $PANGOCAIRO_REQUIRED \
cairo >= $CAIRO_REQUIRED \
cairo-png >= $CAIRO_REQUIRED \
fontconfig >= $FONTCONFIG_REQUIRED
freetype2)
AC_SUBST(LIBRSVG_LIBS)
AC_SUBST(LIBRSVG_CFLAGS)
......
......@@ -39,6 +39,8 @@
#include <math.h>
#include <string.h>
#include <pango/pangocairo.h>
static void
rsvg_pixmap_destroy (gchar *pixels, gpointer data)
{
......@@ -396,6 +398,77 @@ _set_rsvg_affine (cairo_t *cr, const double affine[6])
cairo_transform (cr, &matrix);
}
PangoContext *
rsvg_cairo_create_pango_context (RsvgDrawingCtx *ctx)
{
PangoFontMap *fontmap;
PangoContext *context;
fontmap = pango_cairo_font_map_get_default ();
context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap));
pango_cairo_context_set_resolution (context, ctx->dpi_y);
return context;
}
void
rsvg_cairo_render_pango_layout (RsvgDrawingCtx *ctx,
PangoLayout *layout,
double x, double y)
{
RsvgCairoRender *render = (RsvgCairoRender *)ctx->render;
RsvgState *state = rsvg_state_current(ctx);
PangoRectangle logical;
RsvgBbox bbox;
cairo_save (render->cr);
_set_rsvg_affine (render->cr, state->affine);
cairo_set_line_width (render->cr,
_rsvg_css_normalize_length(&state->stroke_width,
ctx, 'h'));
pango_cairo_update_layout (render->cr, layout);
pango_layout_get_pixel_extents(layout, NULL, &logical);
rsvg_bbox_init(&bbox, state->affine);
bbox.x = x;
bbox.y = y;
bbox.w = logical.width;
bbox.h = logical.height;
bbox.virgin = 0;
cairo_translate (render->cr, x, y);
rsvg_bbox_insert(&render->bbox, &bbox);
if (state->fill)
{
_set_source_rsvg_paint_server (ctx,
state->current_color,
state->fill,
state->fill_opacity,
bbox,
rsvg_state_current(ctx)->current_color);
pango_cairo_show_layout (render->cr, layout);
}
if (state->stroke)
{
pango_cairo_layout_path (render->cr, layout);
_set_source_rsvg_paint_server (ctx,
state->current_color,
state->stroke,
state->stroke_opacity,
bbox,
rsvg_state_current(ctx)->current_color);
cairo_stroke (render->cr);
}
cairo_restore (render->cr);
}
void
rsvg_cairo_render_path (RsvgDrawingCtx *ctx, const RsvgBpathDef *bpath_def)
{
......
......@@ -31,6 +31,14 @@
G_BEGIN_DECLS
PangoContext *
rsvg_cairo_create_pango_context (RsvgDrawingCtx *ctx);
void
rsvg_cairo_render_pango_layout (RsvgDrawingCtx *ctx,
PangoLayout *layout,
double x, double y);
void
rsvg_cairo_render_path (RsvgDrawingCtx *ctx,
const RsvgBpathDef * path);
......
......@@ -53,6 +53,8 @@ rsvg_cairo_render_new(cairo_t * cr, double width, double height)
RsvgCairoRender * cairo_render = g_new0(RsvgCairoRender, 1);
cairo_render->super.free = rsvg_cairo_render_free;
cairo_render->super.create_pango_context = rsvg_cairo_create_pango_context;
cairo_render->super.render_pango_layout = rsvg_cairo_render_pango_layout;
cairo_render->super.render_image = rsvg_cairo_render_image;
cairo_render->super.render_path = rsvg_cairo_render_path;
cairo_render->super.pop_discrete_layer = rsvg_cairo_pop_discrete_layer;
......
......@@ -144,6 +144,10 @@ struct RsvgDrawingCtx {
struct RsvgRender {
void (* free) (RsvgRender * self);
PangoContext * (* create_pango_context) (RsvgDrawingCtx *ctx);
void (* render_pango_layout) (RsvgDrawingCtx *ctx,
PangoLayout *layout,
double x, double y);
void (* render_path) (RsvgDrawingCtx *ctx, const RsvgBpathDef * path);
void (* render_image) (RsvgDrawingCtx *ctx, const GdkPixbuf * pixbuf,
double x, double y, double w, double h);
......
......@@ -515,30 +515,24 @@ rsvg_text_layout_free(RsvgTextLayout * layout)
g_free(layout);
}
static RsvgTextLayout *
rsvg_text_layout_new (RsvgDrawingCtx *ctx,
RsvgState *state,
const char *text)
static PangoLayout *
rsvg_text_create_layout (RsvgDrawingCtx *ctx,
RsvgState *state,
const char *text,
PangoContext *context)
{
RsvgTextLayout * layout;
PangoFontDescription *font_desc;
PangoLayout *layout;
if (ctx->pango_context == NULL)
ctx->pango_context = rsvg_text_get_pango_context (ctx);
if (state->lang)
pango_context_set_language (ctx->pango_context,
pango_context_set_language (context,
pango_language_from_string (state->lang));
if (state->unicode_bidi == UNICODE_BIDI_OVERRIDE ||
state->unicode_bidi == UNICODE_BIDI_EMBED)
pango_context_set_base_dir (ctx->pango_context, state->text_dir);
pango_context_set_base_dir (context, state->text_dir);
layout = g_new0 (RsvgTextLayout, 1);
layout->layout = pango_layout_new (ctx->pango_context);
layout->ctx = ctx;
font_desc = pango_font_description_copy (pango_context_get_font_description (ctx->pango_context));
font_desc = pango_font_description_copy (pango_context_get_font_description (context));
if (state->font_family)
pango_font_description_set_family_static (font_desc, state->font_family);
......@@ -548,17 +542,39 @@ rsvg_text_layout_new (RsvgDrawingCtx *ctx,
pango_font_description_set_weight (font_desc, state->font_weight);
pango_font_description_set_stretch (font_desc, state->font_stretch);
pango_font_description_set_size (font_desc, _rsvg_css_normalize_length(&state->font_size, ctx, 'v') * PANGO_SCALE / ctx->dpi_y * 72);
pango_layout_set_font_description (layout->layout, font_desc);
layout = pango_layout_new (context);
pango_layout_set_font_description (layout, font_desc);
pango_font_description_free (font_desc);
if (text)
pango_layout_set_text (layout->layout, text, -1);
pango_layout_set_text (layout, text, -1);
else
pango_layout_set_text (layout->layout, NULL, 0);
pango_layout_set_alignment (layout->layout, (state->text_dir == PANGO_DIRECTION_LTR ||
state->text_dir == PANGO_DIRECTION_TTB_LTR) ?
pango_layout_set_text (layout, NULL, 0);
pango_layout_set_alignment (layout, (state->text_dir == PANGO_DIRECTION_LTR ||
state->text_dir == PANGO_DIRECTION_TTB_LTR) ?
PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT);
return layout;
}
static RsvgTextLayout *
rsvg_text_layout_new (RsvgDrawingCtx *ctx,
RsvgState *state,
const char *text)
{
RsvgTextLayout * layout;
if (ctx->pango_context == NULL)
ctx->pango_context = rsvg_text_get_pango_context (ctx);
layout = g_new0 (RsvgTextLayout, 1);
layout->layout = rsvg_text_create_layout (ctx, state, text,
ctx->pango_context);
layout->ctx = ctx;
layout->anchor = state->text_anchor;
......@@ -913,10 +929,31 @@ rsvg_text_render_text (RsvgDrawingCtx *ctx,
gdouble *x,
gdouble *y)
{
GString * render;
render = rsvg_text_render_text_as_string (ctx,text,x,y);
rsvg_render_path (ctx, render->str);
g_string_free(render, TRUE);
if (0 && ctx->render->create_pango_context && ctx->render->render_pango_layout)
{
PangoContext *context;
PangoLayout *layout;
PangoLayoutIter *iter;
RsvgState *state;
gint w, h, baseline;
state = rsvg_state_current(ctx);
context = ctx->render->create_pango_context (ctx);
layout = rsvg_text_create_layout (ctx, state, text, context);
pango_layout_get_pixel_size (layout, &w, &h);
iter = pango_layout_get_iter (layout);
baseline = pango_layout_iter_get_baseline (iter) / PANGO_SCALE;
pango_layout_iter_free (iter);
ctx->render->render_pango_layout (ctx, layout, *x, *y - baseline);
*x += w;
}
else
{
GString * render;
render = rsvg_text_render_text_as_string (ctx,text,x,y);
rsvg_render_path (ctx, render->str);
g_string_free(render, TRUE);
}
}
static gdouble
......
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