[cairo-commit] cairo/src cairo-atsui-font.c, 1.23, 1.24 cairo-atsui.h, 1.6, 1.7

Anders Carlsson commit at pdx.freedesktop.org
Fri Sep 30 08:31:38 PDT 2005


Committed by: andersca

Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv24928/src

Modified Files:
	cairo-atsui-font.c cairo-atsui.h 
Log Message:
2005-09-30  Anders Carlsson  <andersca at imendio.com>

        * src/cairo-atsui-font.c:
        (_cairo_atsui_font_face_destroy):
        (_cairo_atsui_font_face_scaled_font_create):
        (cairo_atsui_font_face_create_for_atsu_font_id):
        (CreateSizedCopyOfStyle):
        (_cairo_atsui_font_set_metrics):
        (_cairo_atsui_font_create_scaled):
        (_cairo_atsui_font_create_toy):
        (_cairo_atsui_font_init_glyph_metrics):
        (_move_to):
        (_line_to):
        (_curve_to):
        (_close_path):
        (_cairo_atsui_scaled_font_init_glyph_path):
        (_cairo_atsui_font_scaled_glyph_init):
        (_cairo_atsui_font_text_to_glyphs):
        (_cairo_atsui_font_show_glyphs):
        * src/cairo-atsui.h:
	Bring the ATSUI backend up to date wrt the new font backend
	changes. Also, add cairo_atsui_font_face_create_for_atsu_font_id
	which takes an ATSUFontID and returns a cairo_font_face_t.


Index: cairo-atsui-font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-atsui-font.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- cairo-atsui-font.c	28 Sep 2005 17:35:56 -0000	1.23
+++ cairo-atsui-font.c	30 Sep 2005 15:31:36 -0000	1.24
@@ -39,31 +39,84 @@
 #include "cairoint.h"
 #include "cairo.h"
 
-/*
- * FixedToFloat/FloatToFixed are 10.3+ SDK items - include definitions
- * here so we can use older SDKs.
- */
-#ifndef FixedToFloat
-#define fixed1              ((Fixed) 0x00010000L)
-#define FixedToFloat(a)     ((float)(a) / fixed1)
-#define FloatToFixed(a)     ((Fixed)((float)(a) * fixed1))
-#endif
+typedef struct _cairo_atsui_font_face cairo_atsui_font_face_t;
+typedef struct _cairo_atsui_font cairo_atsui_font_t;
 
-typedef struct {
+static cairo_status_t _cairo_atsui_font_create_scaled (cairo_font_face_t *font_face,
+						       ATSUFontID font_id,
+						       ATSUStyle style,
+						       const cairo_matrix_t *font_matrix,
+						       const cairo_matrix_t *ctm,
+						       const cairo_font_options_t *options,
+						       cairo_scaled_font_t **font_out);
+
+struct _cairo_atsui_font {
     cairo_scaled_font_t base;
 
     cairo_matrix_t scale;
     ATSUStyle style;
     ATSUStyle unscaled_style;
     ATSUFontID fontID;
-} cairo_atsui_font_t;
+};
+
+
+struct _cairo_atsui_font_face {
+  cairo_font_face_t base;
+  ATSUFontID font_id;
+};
+
+static void
+_cairo_atsui_font_face_destroy (void *abstract_face)
+{
+}
+
+static cairo_status_t
+_cairo_atsui_font_face_scaled_font_create (void	*abstract_face,
+					   const cairo_matrix_t	*font_matrix,
+					   const cairo_matrix_t	*ctm,
+					   const cairo_font_options_t *options,
+					   cairo_scaled_font_t **font)
+{
+    cairo_atsui_font_face_t *font_face = abstract_face;
+    OSStatus err;
+    ATSUAttributeTag styleTags[] = { kATSUFontTag };
+    ATSUAttributeValuePtr styleValues[] = { &font_face->font_id };
+    ByteCount styleSizes[] = {  sizeof(ATSUFontID) };
+    ATSUStyle style;
+
+    err = ATSUCreateStyle (&style);
+    err = ATSUSetAttributes(style,
+                            sizeof(styleTags) / sizeof(styleTags[0]),
+                            styleTags, styleSizes, styleValues);
+
+    return _cairo_atsui_font_create_scaled (&font_face->base, font_face->font_id, style,
+					    font_matrix, ctm, options, font);
+}
+
+static const cairo_font_face_backend_t _cairo_atsui_font_face_backend = {
+    _cairo_atsui_font_face_destroy,
+    _cairo_atsui_font_face_scaled_font_create
+};
+
+cairo_public cairo_font_face_t *
+cairo_atsui_font_face_create_for_atsu_font_id (ATSUFontID font_id)
+{
+  cairo_atsui_font_face_t *font_face;
+
+  font_face = malloc (sizeof (cairo_atsui_font_face_t));
+  if (!font_face) {
+    _cairo_error (CAIRO_STATUS_NO_MEMORY);
+    return (cairo_font_face_t *)&_cairo_font_face_nil;
+  }
+
+  font_face->font_id = font_id;
+
+    _cairo_font_face_init (&font_face->base, &_cairo_atsui_font_face_backend);
+
+    return &font_face->base;
+}
 
-typedef struct cairo_ATSUI_glyph_path_callback_info_t {
-    cairo_path_fixed_t *path;
-    cairo_matrix_t scale;
-} cairo_ATSUI_glyph_path_callback_info_t;
 
-const cairo_scaled_font_backend_t cairo_atsui_scaled_font_backend;
 
 static CGAffineTransform
 CGAffineTransformMakeWithCairoFontScale(cairo_matrix_t *scale)
@@ -79,7 +132,6 @@
     ATSUStyle style;
     OSStatus err;
 
-
     // Set the style's size
     CGAffineTransform theTransform =
         CGAffineTransformMakeWithCairoFontScale(scale);
@@ -100,6 +152,86 @@
     return style;
 }
 
+static cairo_status_t
+_cairo_atsui_font_set_metrics (cairo_atsui_font_t *font)
+{
+    ATSFontRef atsFont;
+    ATSFontMetrics metrics;
+    OSStatus err;
+
+    atsFont = FMGetATSFontRefFromFont(font->fontID);
+
+    if (atsFont) {
+        err =
+            ATSFontGetHorizontalMetrics(atsFont, kATSOptionFlagsDefault,
+                                        &metrics);
+
+        if (err == noErr) {
+	    cairo_font_extents_t extents;
+	    
+            extents.ascent = metrics.ascent;
+            extents.descent = metrics.descent;
+            extents.height = metrics.capHeight;
+            extents.max_x_advance = metrics.maxAdvanceWidth;
+
+            // The FT backend doesn't handle max_y_advance either, so we'll ignore it for now. 
+            extents.max_y_advance = 0.0;
+
+	    _cairo_scaled_font_set_metrics (&font->base, &extents);
+
+            return CAIRO_STATUS_SUCCESS;
+        }
+    }
+
+    return CAIRO_STATUS_NULL_POINTER;
+}
+
+static cairo_status_t
+_cairo_atsui_font_create_scaled (cairo_font_face_t *font_face,
+				 ATSUFontID font_id,
+				 ATSUStyle style,
+				 const cairo_matrix_t *font_matrix,
+				 const cairo_matrix_t *ctm,
+				 const cairo_font_options_t *options,
+				 cairo_scaled_font_t **font_out)
+{
+    cairo_atsui_font_t *font = NULL;
+    cairo_matrix_t scale;
+    OSStatus err;
+    cairo_status_t status;
+
+    font = malloc(sizeof(cairo_atsui_font_t));
+
+    _cairo_scaled_font_init(&font->base, font_face, font_matrix, ctm, options,
+			    &cairo_atsui_scaled_font_backend);
+
+    cairo_matrix_multiply(&scale, font_matrix, ctm);
+    font->style = CreateSizedCopyOfStyle(style, &scale);
+
+    Fixed theSize = FloatToFixed(1.0);
+    const ATSUAttributeTag theFontStyleTags[] = { kATSUSizeTag };
+    const ByteCount theFontStyleSizes[] = { sizeof(Fixed) };
+    ATSUAttributeValuePtr theFontStyleValues[] = { &theSize };
+    err = ATSUSetAttributes(style,
+                            sizeof(theFontStyleTags) /
+                            sizeof(ATSUAttributeTag), theFontStyleTags,
+                            theFontStyleSizes, theFontStyleValues);
+
+    font->unscaled_style = style;
+
+    font->fontID = font_id;
+    font->scale = scale;
+
+    *font_out = &font->base;
+
+    status = _cairo_atsui_font_set_metrics (font);
+    if (status) {
+	cairo_scaled_font_destroy (&font->base);
+	return status;
+    }
+
+    return CAIRO_STATUS_SUCCESS;
+}
 
 static cairo_status_t
 _cairo_atsui_font_create_toy(cairo_toy_font_face_t *toy_face,
@@ -108,12 +240,10 @@
 			     const cairo_font_options_t *options,
 			     cairo_scaled_font_t **font_out)
 {
-    cairo_atsui_font_t *font = NULL;
     ATSUStyle style;
     ATSUFontID fontID;
     OSStatus err;
     Boolean isItalic, isBold;
-    cairo_matrix_t scale;
     const char *family = toy_face->family;
 
     err = ATSUCreateStyle(&style);
@@ -170,43 +300,19 @@
 				   kFontNoLanguageCode, &fontID);
     }
 
-
     ATSUAttributeTag styleTags[] =
         { kATSUQDItalicTag, kATSUQDBoldfaceTag, kATSUFontTag };
     ATSUAttributeValuePtr styleValues[] = { &isItalic, &isBold, &fontID };
     ByteCount styleSizes[] =
         { sizeof(Boolean), sizeof(Boolean), sizeof(ATSUFontID) };
 
-
     err = ATSUSetAttributes(style,
                             sizeof(styleTags) / sizeof(styleTags[0]),
                             styleTags, styleSizes, styleValues);
 
-    font = malloc(sizeof(cairo_atsui_font_t));
-
-    _cairo_scaled_font_init(&font->base, toy_face, font_matrix, ctm, options,
-			    &cairo_atsui_scaled_font_backend);
-
-    cairo_matrix_multiply(&scale, font_matrix, ctm);
-    font->style = CreateSizedCopyOfStyle(style, &scale);
-
-    Fixed theSize = FloatToFixed(1.0);
-    const ATSUAttributeTag theFontStyleTags[] = { kATSUSizeTag };
-    const ByteCount theFontStyleSizes[] = { sizeof(Fixed) };
-    ATSUAttributeValuePtr theFontStyleValues[] = { &theSize };
-    err = ATSUSetAttributes(style,
-                            sizeof(theFontStyleTags) /
-                            sizeof(ATSUAttributeTag), theFontStyleTags,
-                            theFontStyleSizes, theFontStyleValues);
-
-    font->unscaled_style = style;
-
-    font->fontID = fontID;
-    font->scale = scale;
 
-    *font_out = &font->base;
-
-    return CAIRO_STATUS_SUCCESS;
+    return _cairo_atsui_font_create_scaled (&toy_face->base, fontID, style,
+					    font_matrix, ctm, options, font_out);
 }
 
 static void
@@ -223,226 +329,230 @@
         ATSUDisposeStyle(font->unscaled_style);
 }
 
-
-static void
-_cairo_atsui_font_get_glyph_cache_key(void *abstract_font,
-				      cairo_glyph_cache_key_t *key)
-{
-}
-
-
 static cairo_status_t
-_cairo_atsui_font_text_to_glyphs(void		*abstract_font,
-                                 const char     *utf8,
-                                 cairo_glyph_t **glyphs,
-				 int		*num_glyphs)
+_cairo_atsui_font_init_glyph_metrics (cairo_atsui_font_t *font,
+				      cairo_scaled_glyph_t *scaled_glyph)
 {
-    cairo_atsui_font_t *font = abstract_font;
-    size_t i;
-    OSStatus err;
-    ATSUTextLayout textLayout;
-    ATSLayoutRecord *layoutRecords;
-    ItemCount glyphCount;
-    int charCount;
-    UniChar *theText;
-    cairo_status_t status;
-
-    // liberal estimate of size
-    charCount = strlen(utf8);
+   cairo_text_extents_t extents;
+   OSStatus err;
+   GlyphID theGlyph = _cairo_scaled_glyph_index (scaled_glyph);
+   ATSGlyphIdealMetrics metricsH, metricsV;
+   ATSUStyle style;
+   ATSUVerticalCharacterType verticalType = kATSUStronglyVertical;
+   const ATSUAttributeTag theTag[] = { kATSUVerticalCharacterTag };
+   const ByteCount theSizes[] = { sizeof(verticalType) };
+   ATSUAttributeValuePtr theValues[] = { &verticalType };
 
-    if (charCount == 0) {
-       *glyphs = NULL;
-       *num_glyphs = 0;
-       return CAIRO_STATUS_SUCCESS;
-    }
+   ATSUCreateAndCopyStyle(font->unscaled_style, &style);
 
-    status = _cairo_utf8_to_utf16 (utf8, -1, &theText, &charCount);
-    if (status)
-	return status;
+   err = ATSUGlyphGetIdealMetrics(style,
+				  1, &theGlyph, 0, &metricsH);
+   err = ATSUSetAttributes(style, 1, theTag, theSizes, theValues);
+   err = ATSUGlyphGetIdealMetrics(style,
+				  1, &theGlyph, 0, &metricsV);
 
-    err = ATSUCreateTextLayout(&textLayout);
+   extents.x_bearing = metricsH.sideBearing.x;
+   extents.y_bearing = metricsV.advance.y;
+   extents.width = 
+      metricsH.advance.x - metricsH.sideBearing.x - metricsH.otherSideBearing.x;
+   extents.height = 
+     -metricsV.advance.y - metricsV.sideBearing.y - metricsV.otherSideBearing.y;
+   extents.x_advance = metricsH.advance.x;
+   extents.y_advance = 0;
 
-    err = ATSUSetTextPointerLocation(textLayout,
-                                     theText, 0, charCount, charCount);
+  _cairo_scaled_glyph_set_metrics (scaled_glyph,
+				   &font->base,
+				   &extents);
 
+  return CAIRO_STATUS_SUCCESS;
+}
 
-    // Set the style for all of the text
-    err = ATSUSetRunStyle(textLayout,
-                          font->unscaled_style, kATSUFromTextBeginning, kATSUToTextEnd);
+static OSStatus 
+_move_to (const Float32Point *point,
+	  void *callback_data)
+{
+    cairo_path_fixed_t *path = callback_data;
 
-    // Get the glyphs from the text layout object
-    err = ATSUDirectGetLayoutDataArrayPtrFromTextLayout(textLayout,
-                                                        0,
-                                                        kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,
-                                                        (void *)
-                                                        &layoutRecords,
-                                                        &glyphCount);
+    _cairo_path_fixed_close_path (path);
+    _cairo_path_fixed_move_to (path,
+			       _cairo_fixed_from_double(point->x),
+			       _cairo_fixed_from_double(point->y));
 
-    *num_glyphs = glyphCount - 1;
+    return noErr;
+}
 
+static OSStatus 
+_line_to (const Float32Point *point,
+	  void *callback_data)
+{
+    cairo_path_fixed_t *path = callback_data;
 
-    *glyphs =
-        (cairo_glyph_t *) malloc(*num_glyphs * (sizeof(cairo_glyph_t)));
-    if (*glyphs == NULL) {
-        return CAIRO_STATUS_NO_MEMORY;
-    }
+    _cairo_path_fixed_line_to (path,
+			       _cairo_fixed_from_double(point->x),
+			       _cairo_fixed_from_double(point->y));
+    
+    return noErr;
+}
 
-    for (i = 0; i < *num_glyphs; i++) {
-        (*glyphs)[i].index = layoutRecords[i].glyphID;
-        (*glyphs)[i].x = FixedToFloat(layoutRecords[i].realPos);
-        (*glyphs)[i].y = 0;
-    }
+static OSStatus
+_curve_to (const Float32Point *point1,
+	   const Float32Point *point2,
+	   const Float32Point *point3,
+	   void *callback_data)
+{
+    cairo_path_fixed_t *path = callback_data;
 
+    _cairo_path_fixed_curve_to (path,
+				_cairo_fixed_from_double(point1->x),
+				_cairo_fixed_from_double(point1->y),
+				_cairo_fixed_from_double(point2->x),
+				_cairo_fixed_from_double(point2->y),
+				_cairo_fixed_from_double(point3->x),
+				_cairo_fixed_from_double(point3->y));
+    
+    return noErr;
+}
 
-    free(theText);
+static OSStatus
+_close_path (void *callback_data)
 
-    ATSUDirectReleaseLayoutDataArrayPtr(NULL,
-                                        kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,
-                                        (void *) &layoutRecords);
+{
+    cairo_path_fixed_t *path = callback_data;
 
-    ATSUDisposeTextLayout(textLayout);
+    _cairo_path_fixed_close_path (path);
 
-    return CAIRO_STATUS_SUCCESS;
+    return noErr;
 }
 
-
-static cairo_status_t
-_cairo_atsui_font_font_extents(void *abstract_font,
-                               cairo_font_extents_t * extents)
+static cairo_status_t 
+_cairo_atsui_scaled_font_init_glyph_path (cairo_atsui_font_t *scaled_font,
+					  cairo_scaled_glyph_t *scaled_glyph)
 {
-    cairo_atsui_font_t *font = abstract_font;
-    ATSFontRef atsFont;
-    ATSFontMetrics metrics;
+    static ATSCubicMoveToUPP moveProc = NULL;
+    static ATSCubicLineToUPP lineProc = NULL;
+    static ATSCubicCurveToUPP curveProc = NULL;
+    static ATSCubicClosePathUPP closePathProc = NULL;
     OSStatus err;
+    cairo_path_fixed_t *path;
 
-    // TODO - test this
-
-    atsFont = FMGetATSFontRefFromFont(font->fontID);
-
-    if (atsFont) {
-        err =
-            ATSFontGetHorizontalMetrics(atsFont, kATSOptionFlagsDefault,
-                                        &metrics);
-
-        if (err == noErr) {
-            extents->ascent = metrics.ascent;
-            extents->descent = metrics.descent;
-            extents->height = metrics.capHeight;
-            extents->max_x_advance = metrics.maxAdvanceWidth;
-
-            // The FT backend doesn't handle max_y_advance either, so we'll ignore it for now. 
-            extents->max_y_advance = 0.0;
+    path = _cairo_path_fixed_create ();
+    if (!path)
+	return CAIRO_STATUS_NO_MEMORY;
 
-            return CAIRO_STATUS_SUCCESS;
-        }
+    if (moveProc == NULL) {
+        moveProc = NewATSCubicMoveToUPP(_move_to);
+        lineProc = NewATSCubicLineToUPP(_line_to);
+        curveProc = NewATSCubicCurveToUPP(_curve_to);
+        closePathProc = NewATSCubicClosePathUPP(_close_path);
     }
 
+    err = ATSUGlyphGetCubicPaths(scaled_font->style,
+				 _cairo_scaled_glyph_index (scaled_glyph),
+				 moveProc,
+				 lineProc,
+				 curveProc,
+				 closePathProc, (void *)path, &err);
+
+    _cairo_scaled_glyph_set_path (scaled_glyph, &scaled_font->base, path);
 
-    return CAIRO_STATUS_NULL_POINTER;
+    return CAIRO_STATUS_SUCCESS;
 }
 
-
 static cairo_status_t
-_cairo_atsui_font_glyph_extents(void *abstract_font,
-                                cairo_glyph_t * glyphs,
-                                int num_glyphs,
-                                cairo_text_extents_t * extents)
+_cairo_atsui_font_scaled_glyph_init (void			*abstract_font,
+				     cairo_scaled_glyph_t	*scaled_glyph,
+				     cairo_scaled_glyph_info_t	 info)
 {
-    cairo_atsui_font_t *font = abstract_font;
-    OSStatus err;
-
-    assert(num_glyphs == 1);
-
-    GlyphID theGlyph = glyphs[0].index;
-
-    ATSGlyphIdealMetrics metricsH, metricsV;
-    ATSUStyle style;
-
-    ATSUCreateAndCopyStyle(font->unscaled_style, &style);
-
-    err = ATSUGlyphGetIdealMetrics(style,
-				   1, &theGlyph, 0, &metricsH);
-
-    ATSUVerticalCharacterType verticalType = kATSUStronglyVertical;
-    const ATSUAttributeTag theTag[] = { kATSUVerticalCharacterTag };
-    const ByteCount theSizes[] = { sizeof(verticalType) };
-    ATSUAttributeValuePtr theValues[] = { &verticalType };
-    
-    err = ATSUSetAttributes(style, 1, theTag, theSizes, theValues);
-
-    err = ATSUGlyphGetIdealMetrics(style,
-				   1, &theGlyph, 0, &metricsV);
+    cairo_atsui_font_t *scaled_font = abstract_font;
+    cairo_status_t status;
 
-    extents->x_bearing = metricsH.sideBearing.x;
-    extents->y_bearing = metricsV.advance.y;
-    extents->width = 
-	metricsH.advance.x - metricsH.sideBearing.x - metricsH.otherSideBearing.x;
-    extents->height = 
-	-metricsV.advance.y - metricsV.sideBearing.y - metricsV.otherSideBearing.y;
-    extents->x_advance = metricsH.advance.x;
-    extents->y_advance = 0;
+    if ((info & CAIRO_SCALED_GLYPH_INFO_METRICS) != 0) {
+      status = _cairo_atsui_font_init_glyph_metrics (scaled_font, scaled_glyph);
+      if (status)
+	return status;
+    }
 
-    ATSUDisposeStyle(style);
+    if ((info & CAIRO_SCALED_GLYPH_INFO_PATH) != 0) {
+	status = _cairo_atsui_scaled_font_init_glyph_path (scaled_font, scaled_glyph);
+	if (status)
+	    return status;
+    }
 
     return CAIRO_STATUS_SUCCESS;
 }
 
-
-static cairo_status_t
-_cairo_atsui_font_glyph_bbox(void *abstract_font,
-                             const cairo_glyph_t *glyphs,
-                             int num_glyphs, cairo_box_t *bbox)
+static cairo_int_status_t 
+_cairo_atsui_font_text_to_glyphs (void		*abstract_font,
+				  double	 x,
+				  double	 y,
+				  const char	*utf8,
+				  cairo_glyph_t **glyphs, 
+				  int		*num_glyphs)
 {
+    cairo_status_t status = CAIRO_STATUS_SUCCESS;
+    uint16_t *utf16;
+    int n16;
+    OSStatus err;
+    ATSUTextLayout textLayout;
+    ATSLayoutRecord *layoutRecords;
     cairo_atsui_font_t *font = abstract_font;
-    cairo_fixed_t x1, y1, x2, y2;
+    ItemCount glyphCount;
     int i;
 
-    bbox->p1.x = bbox->p1.y = CAIRO_MAXSHORT << 16;
-    bbox->p2.x = bbox->p2.y = CAIRO_MINSHORT << 16;
-
-
-    for (i = 0; i < num_glyphs; i++) {
-        GlyphID theGlyph = glyphs[i].index;
+    status = _cairo_utf8_to_utf16 ((unsigned char *)utf8, -1, &utf16, &n16);
+    if (status)
+	return status;
 
-	ATSGlyphScreenMetrics metrics;
-	ATSUGlyphGetScreenMetrics(font->style, 
-				  1, &theGlyph, 0, true, true, &metrics);
+    err = ATSUCreateTextLayout(&textLayout);
 
-	x1 = _cairo_fixed_from_double(glyphs[i].x + metrics.topLeft.x);
-	y1 = _cairo_fixed_from_double(glyphs[i].y - metrics.topLeft.y);
-	x2 = x1 + _cairo_fixed_from_double(metrics.height);
-	y2 = y1 + _cairo_fixed_from_double(metrics.width);
+    err = ATSUSetTextPointerLocation(textLayout, utf16, 0, n16, n16);
 
-        if (x1 < bbox->p1.x)
-            bbox->p1.x = x1;
+    // Set the style for all of the text
+    err = ATSUSetRunStyle(textLayout,
+			  font->style, kATSUFromTextBeginning, kATSUToTextEnd);
 
-        if (y1 < bbox->p1.y)
-            bbox->p1.y = y1;
+    err = ATSUDirectGetLayoutDataArrayPtrFromTextLayout(textLayout,
+							0,
+							kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,
+							(void *)&layoutRecords,
+							&glyphCount);
 
-        if (x2 > bbox->p2.x)
-            bbox->p2.x = x2;
+    *num_glyphs = glyphCount - 1;
+    *glyphs = 
+	(cairo_glyph_t *) malloc(*num_glyphs * (sizeof (cairo_glyph_t)));
+    if (*glyphs == NULL) {
+	return CAIRO_STATUS_NO_MEMORY;
+    }
 
-        if (y2 > bbox->p2.y)
-            bbox->p2.y = y2;
+    for (i = 0; i < *num_glyphs; i++) {
+	(*glyphs)[i].index = layoutRecords[i].glyphID;
+	(*glyphs)[i].x = x + FixedToFloat(layoutRecords[i].realPos);
+	(*glyphs)[i].y = y;
     }
 
+    free (utf16);
+
+    ATSUDirectReleaseLayoutDataArrayPtr(NULL, 
+					kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,
+					(void *) &layoutRecords);
+    ATSUDisposeTextLayout(textLayout);
+    
     return CAIRO_STATUS_SUCCESS;
 }
 
-
-static cairo_status_t
-_cairo_atsui_font_show_glyphs(void *abstract_font,
-                              cairo_operator_t operator,
-                              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,
-                              const cairo_glyph_t *glyphs,
-			      int num_glyphs)
+static cairo_int_status_t 
+_cairo_atsui_font_show_glyphs (void		       *abstract_font,
+			       cairo_operator_t    	operator,
+			       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,
+			       const cairo_glyph_t      *glyphs,
+			       int                 	num_glyphs)
 {
     cairo_atsui_font_t *font = abstract_font;
     CGContextRef myBitmapContext;
@@ -505,7 +615,7 @@
 
     for (i = 0; i < num_glyphs; i++) {
         CGGlyph theGlyph = glyphs[i].index;
-
+		
         CGContextShowGlyphsAtPoint(myBitmapContext,
 				   glyphs[i].x,
                                    glyphs[i].y,
@@ -525,166 +635,12 @@
     return CAIRO_STATUS_SUCCESS;
 }
 
-
-static OSStatus MyATSCubicMoveToCallback(const Float32Point * pt,
-                                         void *callBackDataPtr)
-{
-    cairo_ATSUI_glyph_path_callback_info_t *info = callBackDataPtr;
-    double scaledPt[2];
-    cairo_fixed_t x, y;
-
-    scaledPt[0] = pt->x;
-    scaledPt[1] = pt->y;
-
-    cairo_matrix_transform_point(&info->scale, &scaledPt[0], &scaledPt[1]);
-
-    x = _cairo_fixed_from_double(scaledPt[0]);
-    y = _cairo_fixed_from_double(scaledPt[1]);
-
-    _cairo_path_fixed_close_path(info->path);
-    _cairo_path_fixed_move_to(info->path, x, y);
-
-    return noErr;
-}
-
-
-static OSStatus MyATSCubicLineToCallback(const Float32Point * pt,
-                                         void *callBackDataPtr)
-{
-    cairo_ATSUI_glyph_path_callback_info_t *info = callBackDataPtr;
-    double scaledPt[2];
-    cairo_fixed_t x, y;
-
-    scaledPt[0] = pt->x;
-    scaledPt[1] = pt->y;
-
-    cairo_matrix_transform_point(&info->scale, &scaledPt[0], &scaledPt[1]);
-
-    x = _cairo_fixed_from_double(scaledPt[0]);
-    y = _cairo_fixed_from_double(scaledPt[1]);
-
-    _cairo_path_fixed_line_to(info->path, x, y);
-
-
-    return noErr;
-}
-
-
-static OSStatus MyATSCubicCurveToCallback(const Float32Point * pt1,
-                                          const Float32Point * pt2,
-                                          const Float32Point * pt3,
-                                          void *callBackDataPtr)
-{
-    cairo_ATSUI_glyph_path_callback_info_t *info = callBackDataPtr;
-    double scaledPt[2];
-    cairo_fixed_t x0, y0;
-    cairo_fixed_t x1, y1;
-    cairo_fixed_t x2, y2;
-
-
-    scaledPt[0] = pt1->x;
-    scaledPt[1] = pt1->y;
-
-    cairo_matrix_transform_point(&info->scale, &scaledPt[0], &scaledPt[1]);
-
-    x0 = _cairo_fixed_from_double(scaledPt[0]);
-    y0 = _cairo_fixed_from_double(scaledPt[1]);
-
-
-    scaledPt[0] = pt2->x;
-    scaledPt[1] = pt2->y;
-
-    cairo_matrix_transform_point(&info->scale, &scaledPt[0], &scaledPt[1]);
-
-    x1 = _cairo_fixed_from_double(scaledPt[0]);
-    y1 = _cairo_fixed_from_double(scaledPt[1]);
-
-
-    scaledPt[0] = pt3->x;
-    scaledPt[1] = pt3->y;
-
-    cairo_matrix_transform_point(&info->scale, &scaledPt[0], &scaledPt[1]);
-
-    x2 = _cairo_fixed_from_double(scaledPt[0]);
-    y2 = _cairo_fixed_from_double(scaledPt[1]);
-
-
-    _cairo_path_fixed_curve_to(info->path, x0, y0, x1, y1, x2, y2);
-
-
-    return noErr;
-}
-
-
-static OSStatus MyCubicClosePathProc(void *callBackDataPtr)
-{
-    cairo_ATSUI_glyph_path_callback_info_t *info = callBackDataPtr;
-
-
-    _cairo_path_fixed_close_path(info->path);
-
-
-    return noErr;
-}
-
-
-static cairo_status_t
-_cairo_atsui_font_glyph_path(void *abstract_font,
-                             cairo_glyph_t *glyphs, int num_glyphs,
-			     cairo_path_fixed_t *path)
-{
-    int i;
-    cairo_atsui_font_t *font = abstract_font;
-    OSStatus err;
-    cairo_ATSUI_glyph_path_callback_info_t info;
-
-
-    static ATSCubicMoveToUPP moveProc = NULL;
-    static ATSCubicLineToUPP lineProc = NULL;
-    static ATSCubicCurveToUPP curveProc = NULL;
-    static ATSCubicClosePathUPP closePathProc = NULL;
-
-
-    if (moveProc == NULL) {
-        moveProc = NewATSCubicMoveToUPP(MyATSCubicMoveToCallback);
-        lineProc = NewATSCubicLineToUPP(MyATSCubicLineToCallback);
-        curveProc = NewATSCubicCurveToUPP(MyATSCubicCurveToCallback);
-        closePathProc = NewATSCubicClosePathUPP(MyCubicClosePathProc);
-    }
-
-
-    info.path = path;
-
-
-    for (i = 0; i < num_glyphs; i++) {
-        GlyphID theGlyph = glyphs[i].index;
-
-
-        cairo_matrix_init(&info.scale,
-			  1.0, 0.0,
-			  0.0, 1.0, glyphs[i].x, glyphs[i].y);
-
-
-        err = ATSUGlyphGetCubicPaths(font->style,
-                                     theGlyph,
-                                     moveProc,
-                                     lineProc,
-                                     curveProc,
-                                     closePathProc, (void *) &info, &err);
-    }
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
 const cairo_scaled_font_backend_t cairo_atsui_scaled_font_backend = {
     _cairo_atsui_font_create_toy,
     _cairo_atsui_font_fini,
-    _cairo_atsui_font_font_extents,
+    _cairo_atsui_font_scaled_glyph_init,
     _cairo_atsui_font_text_to_glyphs,
-    _cairo_atsui_font_glyph_extents,
-    _cairo_atsui_font_glyph_bbox,
+    NULL, /* ucs4_to_index */
     _cairo_atsui_font_show_glyphs,
-    _cairo_atsui_font_glyph_path,
-    _cairo_atsui_font_get_glyph_cache_key,
 };
 

Index: cairo-atsui.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-atsui.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- cairo-atsui.h	14 May 2005 17:03:56 -0000	1.6
+++ cairo-atsui.h	30 Sep 2005 15:31:36 -0000	1.7
@@ -46,6 +46,9 @@
 
 CAIRO_BEGIN_DECLS
 
+cairo_public cairo_font_face_t *
+cairo_atsui_font_face_create_for_atsu_font_id (ATSUFontID font_id);
+
 CAIRO_END_DECLS
 
 #else  /* CAIRO_HAS_ATSUI_FONT */



More information about the cairo-commit mailing list