[cairo-commit] 5 commits - src/cairo-atsui-font.c src/cairo-quartz-surface.c

Brian Ewins brianewins at kemper.freedesktop.org
Mon Mar 19 11:28:54 PDT 2007


 src/cairo-atsui-font.c     |  232 +++++++++------------------------------------
 src/cairo-quartz-surface.c |    9 +
 2 files changed, 58 insertions(+), 183 deletions(-)

New commits:
diff-tree 12feb1f98627637bf83ba70f739bb5b2699085aa (from 986b0ff83813b68a19490fe8629bfdaeed68cbe2)
Author: Brian Ewins <Brian.Ewins at gmail.com>
Date:   Mon Mar 19 18:22:44 2007 +0000

    [quartz] apply ctm to text (#9568)
    
    Applies the ctm to text output on the quartz surface. This corrects
    the text-pattern test, and also corrects the size of text when the
    ctm includes a scale.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 1ac4c7b..33f3a10 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -1285,13 +1285,20 @@ _cairo_quartz_surface_show_glyphs (void 
      * text matrix?
      */
     //ND((stderr, "show_glyphs: glyph 0 at: %f, %f\n", glyphs[0].x, glyphs[0].y));
-    CGAffineTransform cairoTextTransform, textTransform;
+    CGAffineTransform cairoTextTransform, textTransform, ctm;
     _cairo_quartz_cairo_matrix_to_quartz (&scaled_font->font_matrix, &cairoTextTransform);
 
     textTransform = CGAffineTransformMakeTranslation (glyphs[0].x, glyphs[0].y);
     textTransform = CGAffineTransformScale (textTransform, 1.0, -1.0);
     textTransform = CGAffineTransformConcat (cairoTextTransform, textTransform);
 
+    ctm = CGAffineTransformMake (scaled_font->ctm.xx,
+				 -scaled_font->ctm.yx,
+				 -scaled_font->ctm.xy,
+				 scaled_font->ctm.yy,
+				 0., 0.);
+    textTransform = CGAffineTransformConcat (ctm, textTransform);
+
     CGContextSetTextMatrix (surface->cgContext, textTransform);
     CGContextSetFontSize (surface->cgContext, 1.0);
 
diff-tree 986b0ff83813b68a19490fe8629bfdaeed68cbe2 (from 06a44839270354c7f74aa66352fb4234095dee4e)
Author: Brian Ewins <Brian.Ewins at gmail.com>
Date:   Mon Mar 19 18:21:27 2007 +0000

    [atsui] make text_to_glyphs return positions in user units. (#9568)
    
    text_to_glyphs was returning positions in device units; correct this
    to use user units.

diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c
index 030db16..a26e76f 100644
--- a/src/cairo-atsui-font.c
+++ b/src/cairo-atsui-font.c
@@ -844,6 +844,9 @@ _cairo_atsui_font_text_to_glyphs (void		
     cairo_atsui_font_t *font = abstract_font;
     ItemCount glyphCount;
     int i;
+    CGPoint point;
+    double xscale, yscale;
+    CGAffineTransform device_to_user_scale;
 
     status = _cairo_utf8_to_utf16 ((unsigned char *)utf8, -1, &utf16, &n16);
     if (status)
@@ -870,9 +873,18 @@ _cairo_atsui_font_text_to_glyphs (void		
 	return CAIRO_STATUS_NO_MEMORY;
     }
 
+    _cairo_matrix_compute_scale_factors (&font->base.ctm, &xscale, &yscale, 1);
+    device_to_user_scale = 
+	CGAffineTransformInvert (CGAffineTransformMake (xscale, 0,
+							0, yscale,
+							0, 0));
     for (i = 0; i < *num_glyphs; i++) {
 	(*glyphs)[i].index = layoutRecords[i].glyphID;
-	(*glyphs)[i].x = x + FixedToFloat(layoutRecords[i].realPos);
+	/* ATSLayoutRecord.realPos is in device units, convert to user units */
+	point = CGPointMake (FixedToFloat (layoutRecords[i].realPos), 0);
+	point = CGPointApplyAffineTransform (point, device_to_user_scale);
+
+	(*glyphs)[i].x = x + point.x;
 	(*glyphs)[i].y = y;
     }
 
diff-tree 06a44839270354c7f74aa66352fb4234095dee4e (from 240479d10d3263719b0c8a4426fda088899551a2)
Author: Brian Ewins <Brian.Ewins at gmail.com>
Date:   Sun Mar 18 20:20:11 2007 +0000

    [atsui] store sizes in the atsui font
    
    The ATSUStyle that we store in the font contains references to
    the size and font matrix; we need to store them in the font so that
    they are not released before the style.

diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c
index 36b56d7..030db16 100644
--- a/src/cairo-atsui-font.c
+++ b/src/cairo-atsui-font.c
@@ -82,6 +82,9 @@ struct _cairo_atsui_font {
     ATSUStyle style;
     ATSUStyle unscaled_style;
     ATSUFontID fontID;
+
+    Fixed size;
+    CGAffineTransform font_matrix;
 };
 
 struct _cairo_atsui_font_face {
@@ -224,8 +227,6 @@ _cairo_atsui_font_create_scaled (cairo_f
     cairo_status_t status;
     double xscale = 1.0;
     double yscale = 1.0;
-    CGAffineTransform theTransform;
-    Fixed theSize;
 
     font = malloc(sizeof(cairo_atsui_font_t));
     if (font == NULL)
@@ -236,11 +237,12 @@ _cairo_atsui_font_create_scaled (cairo_f
 
     _cairo_matrix_compute_scale_factors (&font->base.scale, 
 					 &xscale, &yscale, 1);
-    theTransform = CGAffineTransformMake (1.0, 0,
-					  0, yscale/xscale,
-					  0, 0);
-    theSize = FloatToFixed (xscale); 
-    font->style = CreateSizedCopyOfStyle (style, &theSize, &theTransform);
+    font->font_matrix = CGAffineTransformMake (1., 0.,
+					       0., yscale/xscale,
+					       0., 0.);
+    font->size = FloatToFixed (xscale);
+
+    font->style = CreateSizedCopyOfStyle (style, &font->size, &font->font_matrix);
 
     {
 	Fixed theSize = FloatToFixed(1.0);
diff-tree 240479d10d3263719b0c8a4426fda088899551a2 (from 43577e26b4c2285499ebfddba6cfa62cbbb15feb)
Author: Brian Ewins <Brian.Ewins at gmail.com>
Date:   Sun Mar 18 20:20:10 2007 +0000

    [atsui] refactor CreateSizedCopyOfStyle
    
    This is just to make it easier to use with passed-in matrices,
    which I'll make use of in a subsequent patch.

diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c
index 3b0d031..36b56d7 100644
--- a/src/cairo-atsui-font.c
+++ b/src/cairo-atsui-font.c
@@ -155,24 +155,18 @@ CGAffineTransformMakeWithCairoFontScale(
 }
 
 static ATSUStyle
-CreateSizedCopyOfStyle(ATSUStyle inStyle, const cairo_matrix_t *scale)
+CreateSizedCopyOfStyle(ATSUStyle inStyle, 
+		       const Fixed *theSize, 
+		       const CGAffineTransform *theTransform)
 {
     ATSUStyle style;
     OSStatus err;
-    double xscale = 1.0;
-    double yscale = 1.0;
-    CGAffineTransform theTransform;
-    Fixed theSize;
-    const ATSUAttributeTag theFontStyleTags[] = { kATSUSizeTag, kATSUFontMatrixTag };
-    const ByteCount theFontStyleSizes[] = { sizeof(Fixed), sizeof(CGAffineTransform) };
-    ATSUAttributeValuePtr theFontStyleValues[] = { &theSize, &theTransform };
-
-    /* Set the style's size */
-    _cairo_matrix_compute_scale_factors(scale, &xscale, &yscale, 1);
-    theTransform = CGAffineTransformMake(1.0, 0,
-					 0, yscale/xscale,
-					 0, 0);
-    theSize = FloatToFixed(xscale);    
+    const ATSUAttributeTag theFontStyleTags[] = { kATSUSizeTag, 
+						  kATSUFontMatrixTag };
+    const ByteCount theFontStyleSizes[] = { sizeof(Fixed), 
+					    sizeof(CGAffineTransform) };
+    ATSUAttributeValuePtr theFontStyleValues[] = { (Fixed *)theSize, 
+						   (CGAffineTransform *)theTransform };
 
     err = ATSUCreateAndCopyStyle(inStyle, &style);
 
@@ -228,6 +222,10 @@ _cairo_atsui_font_create_scaled (cairo_f
     cairo_atsui_font_t *font = NULL;
     OSStatus err;
     cairo_status_t status;
+    double xscale = 1.0;
+    double yscale = 1.0;
+    CGAffineTransform theTransform;
+    Fixed theSize;
 
     font = malloc(sizeof(cairo_atsui_font_t));
     if (font == NULL)
@@ -236,7 +234,13 @@ _cairo_atsui_font_create_scaled (cairo_f
     _cairo_scaled_font_init(&font->base, font_face, font_matrix, ctm, options,
 			    &cairo_atsui_scaled_font_backend);
 
-    font->style = CreateSizedCopyOfStyle(style, &font->base.scale);
+    _cairo_matrix_compute_scale_factors (&font->base.scale, 
+					 &xscale, &yscale, 1);
+    theTransform = CGAffineTransformMake (1.0, 0,
+					  0, yscale/xscale,
+					  0, 0);
+    theSize = FloatToFixed (xscale); 
+    font->style = CreateSizedCopyOfStyle (style, &theSize, &theTransform);
 
     {
 	Fixed theSize = FloatToFixed(1.0);
diff-tree 43577e26b4c2285499ebfddba6cfa62cbbb15feb (from 5aaf584bf44d762af5e486f21a037eb0cc6e1197)
Author: Brian Ewins <Brian.Ewins at gmail.com>
Date:   Sun Mar 18 20:20:10 2007 +0000

    [atsui] remove the unused old_show_glyphs function.
    
    _cairo_atsui_old_show_glyphs was a relic of the old quartz 
    surface and is no longer required.

diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c
index d9fbde3..3b0d031 100644
--- a/src/cairo-atsui-font.c
+++ b/src/cairo-atsui-font.c
@@ -146,47 +146,6 @@ cairo_atsui_font_face_create_for_atsu_fo
     return &font_face->base;
 }
 
-static CGContextRef
-CGBitmapContextCreateWithCairoImageSurface (const cairo_image_surface_t * surface)
-{
-    CGContextRef contextRef;
-    CGColorSpaceRef colorSpace;
-    int bits_per_comp, alpha;
-
-    /* Create a CGBitmapContext for the dest surface for drawing into */
-    if (surface->depth == 1) {
-	colorSpace = CGColorSpaceCreateDeviceGray ();
-	bits_per_comp = 1;
-	alpha = kCGImageAlphaNone;
-    } else if (surface->depth == 8) {
-	colorSpace = CGColorSpaceCreateDeviceGray ();
-	bits_per_comp = 8;
-	alpha = kCGImageAlphaNone;
-    } else if (surface->depth == 24) {
-	colorSpace = CGColorSpaceCreateDeviceRGB ();
-	bits_per_comp = 8;
-	alpha = kCGImageAlphaNoneSkipFirst | CG_BITMAP_BYTE_ORDER_FLAG;
-    } else if (surface->depth == 32) {
-	colorSpace = CGColorSpaceCreateDeviceRGB ();
-	bits_per_comp = 8;
-	alpha = kCGImageAlphaPremultipliedFirst | CG_BITMAP_BYTE_ORDER_FLAG;
-    } else {
-	/* not reached */
-	return NULL;
-    }
-    
-    contextRef = CGBitmapContextCreate (surface->data,
-					surface->width,
-					surface->height,
-					bits_per_comp,
-					surface->stride,
-					colorSpace,
-					alpha);
-    CGColorSpaceRelease (colorSpace);
-
-    return contextRef;
-}
-
 static CGAffineTransform
 CGAffineTransformMakeWithCairoFontScale(const cairo_matrix_t *scale)
 {
@@ -781,7 +740,20 @@ _cairo_atsui_scaled_font_init_glyph_surf
     if (!surface)
 	return CAIRO_STATUS_NO_MEMORY;
 
-    drawingContext = CGBitmapContextCreateWithCairoImageSurface (surface);
+    /* Create a CGBitmapContext for the dest surface for drawing into */
+    {
+	CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray ();
+    
+	drawingContext = CGBitmapContextCreate (surface->data,
+						surface->width,
+						surface->height,
+						8,
+						surface->stride,
+						colorSpace,
+						kCGImageAlphaNone);
+	CGColorSpaceRelease (colorSpace);
+    }
+
     if (!drawingContext) {
 	cairo_surface_destroy ((cairo_surface_t *)surface);
 	return CAIRO_STATUS_NO_MEMORY;
@@ -908,124 +880,6 @@ _cairo_atsui_font_text_to_glyphs (void		
     return CAIRO_STATUS_SUCCESS;
 }
 
-#if CAIRO_HAS_QUARTZ_SURFACE
-static cairo_int_status_t
-_cairo_atsui_font_old_show_glyphs (void		       *abstract_font,
-				   cairo_operator_t    	op,
-				   cairo_pattern_t     *pattern,
-				   cairo_surface_t     *generic_surface,
-				   int                 	source_x,
-				   int                 	source_y,
-				   int			dest_x,
-				   int			dest_y,
-				   unsigned int		width,
-				   unsigned int		height,
-				   cairo_glyph_t       *glyphs,
-				   int                 	num_glyphs)
-{
-    cairo_atsui_font_t *font = abstract_font;
-    CGContextRef drawingContext;
-    cairo_image_surface_t *destImageSurface;
-    int i;
-    void *extra = NULL;
-    cairo_bool_t can_draw_directly;
-    cairo_rectangle_int16_t rect;
-
-    ATSFontRef atsFont;
-    CGFontRef cgFont;
-    CGAffineTransform textTransform;
-
-    if (cairo_surface_get_type (generic_surface) != CAIRO_SURFACE_TYPE_QUARTZ)
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    /* Check if we can draw directly to the destination surface */
-    can_draw_directly = _cairo_pattern_is_opaque_solid (pattern) &&
-	op == CAIRO_OPERATOR_OVER;
-
-    if (!can_draw_directly) {
-	rect.x = dest_x;
-	rect.y = dest_y;
-	rect.width = width;
-	rect.height = height;
-
-	_cairo_surface_acquire_dest_image(generic_surface,
-					  &rect,
-					  &destImageSurface,
-					  &rect,
-					  &extra);
-
-	drawingContext = CGBitmapContextCreateWithCairoImageSurface (destImageSurface);
-	if (!drawingContext) 
-	    return CAIRO_INT_STATUS_UNSUPPORTED;
-
-	CGContextTranslateCTM(drawingContext, 0, destImageSurface->height);
-	CGContextScaleCTM(drawingContext, 1.0f, -1.0f);
-    } else {
-	drawingContext = ((cairo_quartz_surface_t *)generic_surface)->cgContext;
-	CGContextSaveGState (drawingContext);
-    }
-
-    atsFont = FMGetATSFontRefFromFont(font->fontID);
-    cgFont = CGFontCreateWithPlatformFont(&atsFont);
-
-    CGContextSetFont(drawingContext, cgFont);
-
-    if (font->base.options.antialias ==  CAIRO_ANTIALIAS_NONE) {
-	CGContextSetShouldAntialias (drawingContext, false);
-    }
-
-    textTransform = CGAffineTransformMakeWithCairoFontScale(&font->base.scale);
-    textTransform = CGAffineTransformScale(textTransform, 1.0f, -1.0f);
-
-    CGContextSetFontSize(drawingContext, 1.0);
-    CGContextSetTextMatrix(drawingContext, textTransform);
-
-    if (pattern->type == CAIRO_PATTERN_TYPE_SOLID &&
-	_cairo_pattern_is_opaque_solid(pattern))
-    {
-	cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *)pattern;
-	CGContextSetRGBFillColor(drawingContext,
-				 solid->color.red,
-				 solid->color.green,
-				 solid->color.blue, 1.0f);
-    } else {
-	CGContextSetRGBFillColor(drawingContext, 0.0f, 0.0f, 0.0f, 0.0f);
-    }
-
-    /* TODO - bold and italic text
-     *
-     * We could draw the text using ATSUI and get bold, italics
-     * etc. for free, but ATSUI does a lot of text layout work
-     * that we don't really need...
-     */
-
-    for (i = 0; i < num_glyphs; i++) {
-        CGGlyph theGlyph = glyphs[i].index;
-
-	/* round glyph locations to the nearest pixel */
-	/* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */
-        CGContextShowGlyphsAtPoint(drawingContext,
-				   _cairo_lround (glyphs[i].x),
-				   _cairo_lround (glyphs[i].y),
-                                   &theGlyph, 1);
-    }
-
-    if (!can_draw_directly) {
-	CGContextRelease(drawingContext);
-
-	_cairo_surface_release_dest_image(generic_surface,
-					  &rect,
-					  destImageSurface,
-					  &rect,
-					  extra);
-    } else {
-      CGContextRestoreGState (drawingContext);
-    }
-
-    return CAIRO_STATUS_SUCCESS;
-}
-#endif /* CAIRO_HAS_QUARTZ_SURFACE */
-
 ATSUStyle
 _cairo_atsui_scaled_font_get_atsu_style (cairo_scaled_font_t *sfont)
 {
@@ -1073,11 +927,7 @@ const cairo_scaled_font_backend_t cairo_
     _cairo_atsui_font_scaled_glyph_init,
     _cairo_atsui_font_text_to_glyphs,
     NULL, /* ucs4_to_index */
-#if CAIRO_HAS_QUARTZ_SURFACE
-    _cairo_atsui_font_old_show_glyphs,
-#else
-    NULL,
-#endif /* CAIRO_HAS_QUARTZ_SURFACE */
+    NULL, /* show_glyphs */
     _cairo_atsui_load_truetype_table,
     NULL, /* map_glyphs_to_unicode */
 };


More information about the cairo-commit mailing list