[cairo-commit] src/cairo-atsui-font.c src/cairo-quartz-private.h src/cairo-quartz-surface.c
Vladimir Vukicevic
vladimir at kemper.freedesktop.org
Tue Jan 15 16:11:31 PST 2008
src/cairo-atsui-font.c | 18 ++++++++++++++++++
src/cairo-quartz-private.h | 3 +++
src/cairo-quartz-surface.c | 10 ++--------
3 files changed, 23 insertions(+), 8 deletions(-)
New commits:
commit 57c2b75c229ac7811c573548ae50e6b0e4ecf862
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date: Tue Jan 15 14:27:14 2008 -0800
[quartz] Store the CGFontRef and reuse it for rendering
Previously the CGFontRef was recreated each time in show_glyphs; this
caused the font to get re-embedded in any PDF files that were being
generated through Quartz.
diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c
index af4c00f..d4c1f64 100644
--- a/src/cairo-atsui-font.c
+++ b/src/cairo-atsui-font.c
@@ -87,6 +87,7 @@ struct _cairo_atsui_font {
Fixed size;
CGAffineTransform font_matrix;
+ CGFontRef cgfref;
};
struct _cairo_atsui_font_face {
@@ -299,6 +300,7 @@ _cairo_atsui_font_create_scaled (cairo_font_face_t *font_face,
status = _cairo_atsui_font_set_metrics (font);
+ font->cgfref = 0;
FAIL:
if (status) {
if (font) {
@@ -447,6 +449,9 @@ _cairo_atsui_font_fini(void *abstract_font)
ATSUDisposeStyle(font->style);
if (font->unscaled_style)
ATSUDisposeStyle(font->unscaled_style);
+ if (font->cgfref)
+ CGFontRelease(font->cgfref);
+
}
static GlyphID
@@ -942,6 +947,19 @@ _cairo_atsui_scaled_font_get_atsu_font_id (cairo_scaled_font_t *sfont)
return afont->fontID;
}
+CGFontRef
+_cairo_atsui_scaled_font_get_cg_font_ref (cairo_scaled_font_t *sfont)
+{
+ cairo_atsui_font_t *afont = (cairo_atsui_font_t *) sfont;
+
+ if (!afont->cgfref) {
+ ATSFontRef atsfref = FMGetATSFontRefFromFont (afont->fontID);
+ afont->cgfref = CGFontCreateWithPlatformFont (&atsfref);
+ }
+ return afont->cgfref;
+}
+
+
static cairo_int_status_t
_cairo_atsui_load_truetype_table (void *abstract_font,
unsigned long tag,
diff --git a/src/cairo-quartz-private.h b/src/cairo-quartz-private.h
index 5e46e8d..52a3d7f 100644
--- a/src/cairo-quartz-private.h
+++ b/src/cairo-quartz-private.h
@@ -72,6 +72,9 @@ _cairo_atsui_scaled_font_get_atsu_style (cairo_scaled_font_t *sfont);
ATSUFontID
_cairo_atsui_scaled_font_get_atsu_font_id (cairo_scaled_font_t *sfont);
+
+CGFontRef
+_cairo_atsui_scaled_font_get_cg_font_ref (cairo_scaled_font_t *sfont);
#endif /* CAIRO_HAS_ATSUI_FONT */
#endif /* CAIRO_QUARTZ_PRIVATE_H */
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index d254332..1990062 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -1524,9 +1524,6 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface,
int num_glyphs,
cairo_scaled_font_t *scaled_font)
{
- ATSUFontID fid;
- ATSFontRef atsfref;
- CGFontRef cgfref;
CGAffineTransform cairoTextTransform, textTransform, ctm;
// XXXtodo/perf: stack storage for glyphs/sizes
#define STATIC_BUF_SIZE 64
@@ -1568,12 +1565,9 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface,
CGContextSetCompositeOperation (surface->cgContext, _cairo_quartz_cairo_operator_to_quartz (op));
- fid = _cairo_atsui_scaled_font_get_atsu_font_id (scaled_font);
- atsfref = FMGetATSFontRefFromFont (fid);
- cgfref = CGFontCreateWithPlatformFont (&atsfref);
-
+ /* this doesn't addref */
+ CGFontRef cgfref = _cairo_atsui_scaled_font_get_cg_font_ref (scaled_font);
CGContextSetFont (surface->cgContext, cgfref);
- CGFontRelease (cgfref);
/* So this should include the size; I don't know if I need to extract the
* size from this and call CGContextSetFontSize.. will I get crappy hinting
More information about the cairo-commit
mailing list