summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bf947f0)
raw | patch | inline | side by side (parent: bf947f0)
author | scislac <scislac@users.sourceforge.net> | |
Mon, 9 Nov 2009 21:52:06 +0000 (21:52 +0000) | ||
committer | scislac <scislac@users.sourceforge.net> | |
Mon, 9 Nov 2009 21:52:06 +0000 (21:52 +0000) |
src/extension/internal/cairo-render-context.cpp | patch | blob | history | |
src/extension/internal/cairo-render-context.h | patch | blob | history |
diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp
index 023a9b837a266d9d450ba0243adaf4bb218be0e1..c33beab8a14870c53424c92be46d76a66568a08f 100644 (file)
_renderer(parent),
_render_mode(RENDER_MODE_NORMAL),
_clip_mode(CLIP_MODE_MASK)
-{}
+{
+ font_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, font_data_free);
+}
CairoRenderContext::~CairoRenderContext(void)
{
+ if(font_table != NULL) {
+ g_hash_table_remove_all(font_table);
+ }
+
if (_cr) cairo_destroy(_cr);
if (_surface) cairo_surface_destroy(_surface);
if (_layout) g_object_unref(_layout);
}
+void CairoRenderContext::font_data_free(gpointer data)
+{
+ cairo_font_face_t *font_face = (cairo_font_face_t *)data;
+ if (font_face) {
+ cairo_font_face_destroy(font_face);
+ }
+}
CairoRenderer*
CairoRenderContext::getRenderer(void) const
// copy over the correct CTM
// It must be stored in item_transform of current state after pushState.
- Geom::Matrix item_transform;
+ Geom::Matrix item_transform;
if (_state->parent_has_userspace)
item_transform = getParentState()->transform * _state->item_transform;
else
@@ -1015,7 +1028,7 @@ CairoRenderContext::_createPatternPainter(SPPaintServer const *const paintserver
}
- // Calculate the size of the surface which has to be created
+ // Calculate the size of the surface which has to be created
#define SUBPIX_SCALE 100
// Cairo requires an integer pattern surface width/height.
// Subtract 0.5 to prevent small rounding errors from increasing pattern size by one pixel.
@@ -1323,7 +1336,7 @@ CairoRenderContext::renderPathVector(Geom::PathVector const & pathv, SPStyle con
}
bool no_fill = style->fill.isNone() || style->fill_opacity.value == 0;
- bool no_stroke = style->stroke.isNone() || style->stroke_width.computed < 1e-9 ||
+ bool no_stroke = style->stroke.isNone() || style->stroke_width.computed < 1e-9 ||
style->stroke_opacity.value == 0;
if (no_fill && no_stroke)
@@ -1492,10 +1505,11 @@ CairoRenderContext::renderGlyphtext(PangoFont *font, Geom::Matrix const *font_ma
{
// create a cairo_font_face from PangoFont
double size = style->font_size.computed;
- cairo_font_face_t *font_face = NULL;
+ gpointer fonthash = (gpointer)font;
+ cairo_font_face_t *font_face = (cairo_font_face_t *)g_hash_table_lookup(font_table, fonthash);
FcPattern *fc_pattern = NULL;
-
+
#ifdef USE_PANGO_WIN32
# ifdef CAIRO_HAS_WIN32_FONT
LOGFONTA *lfa = pango_win32_font_logfont(font);
@@ -1504,17 +1518,23 @@ CairoRenderContext::renderGlyphtext(PangoFont *font, Geom::Matrix const *font_ma
ZeroMemory(&lfw, sizeof(LOGFONTW));
memcpy(&lfw, lfa, sizeof(LOGFONTA));
MultiByteToWideChar(CP_OEMCP, MB_PRECOMPOSED, lfa->lfFaceName, LF_FACESIZE, lfw.lfFaceName, LF_FACESIZE);
-
- font_face = cairo_win32_font_face_create_for_logfontw(&lfw);
+
+ if(font_face == NULL) {
+ font_face = cairo_win32_font_face_create_for_logfontw(&lfw);
+ g_hash_table_insert(font_table, fonthash, font_face);
+ }
# endif
#else
# ifdef CAIRO_HAS_FT_FONT
PangoFcFont *fc_font = PANGO_FC_FONT(font);
fc_pattern = fc_font->font_pattern;
- font_face = cairo_ft_font_face_create_for_pattern(fc_pattern);
+ if(font_face == NULL) {
+ font_face = cairo_ft_font_face_create_for_pattern(fc_pattern);
+ g_hash_table_insert(font_table, fonthash, font_face);
+ }
# endif
#endif
-
+
cairo_save(_cr);
cairo_set_font_face(_cr, font_face);
@@ -1567,8 +1587,8 @@ CairoRenderContext::renderGlyphtext(PangoFont *font, Geom::Matrix const *font_ma
cairo_restore(_cr);
- if (font_face)
- cairo_font_face_destroy(font_face);
+// if (font_face)
+// cairo_font_face_destroy(font_face);
return true;
}
diff --git a/src/extension/internal/cairo-render-context.h b/src/extension/internal/cairo-render-context.h
index 930668e03b348b1749c08f1d302ee7f4b17dae22..e6f2d698ed433673e0a1555c9296a8448d7a841f 100644 (file)
void _concatTransform(cairo_t *cr, double xx, double yx, double xy, double yy, double x0, double y0);
void _concatTransform(cairo_t *cr, Geom::Matrix const *transform);
+ GHashTable *font_table;
+ static void font_data_free(gpointer data);
+
CairoRenderState *_createState(void);
};