+ err = atsu_get_text_layout_with_text_ptr (&ch, 1, style, &text_layout);
+ if (err == noErr)
+ {
+ ATSTrapezoid glyph_bounds;
+
+ err = ATSUGetGlyphBounds (text_layout, 0, 0,
+ kATSUFromTextBeginning, kATSUToTextEnd,
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
+ kATSUseFractionalOrigins,
+#else
+ kATSUseDeviceOrigins,
+#endif
+ 1, &glyph_bounds, NULL);
+ if (err == noErr)
+ {
+ xassert (glyph_bounds.lowerRight.x - glyph_bounds.lowerLeft.x
+ == glyph_bounds.upperRight.x - glyph_bounds.upperLeft.x);
+
+ width = Fix2Long (glyph_bounds.upperRight.x
+ - glyph_bounds.upperLeft.x);
+ if (font_ascent_return)
+ *font_ascent_return = -Fix2Long (glyph_bounds.upperLeft.y);
+ if (font_descent_return)
+ *font_descent_return = Fix2Long (glyph_bounds.lowerLeft.y);
+ }
+ }
+ if (err == noErr && overall_return)
+ {
+ err = ATSUMeasureTextImage (text_layout,
+ kATSUFromTextBeginning, kATSUToTextEnd,
+ 0, 0, &char_bounds);
+ if (err == noErr)
+ STORE_XCHARSTRUCT (*overall_return, width, char_bounds);
+#if USE_CG_TEXT_DRAWING
+ if (err == noErr && cg_glyph)
+ {
+ OSErr err1;
+ ATSUGlyphInfoArray glyph_info_array;
+ ByteCount count = sizeof (ATSUGlyphInfoArray);
+
+ err1 = ATSUMatchFontsToText (text_layout, kATSUFromTextBeginning,
+ kATSUToTextEnd, NULL, NULL, NULL);
+ if (err1 == noErr)
+ err1 = ATSUGetGlyphInfo (text_layout, kATSUFromTextBeginning,
+ kATSUToTextEnd, &count,
+ &glyph_info_array);
+ if (err1 == noErr)
+ {
+ xassert (glyph_info_array.glyphs[0].glyphID);
+ *cg_glyph = glyph_info_array.glyphs[0].glyphID;
+ }
+ else
+ *cg_glyph = 0;
+ }
+#endif
+ }
+ }
+ else
+#endif
+ {
+ if (font_ascent_return || font_descent_return)
+ {
+ FontInfo font_info;
+
+ GetFontInfo (&font_info);
+ if (font_ascent_return)
+ *font_ascent_return = font_info.ascent;
+ if (font_descent_return)
+ *font_descent_return = font_info.descent;
+ }
+ if (overall_return)
+ {
+ char ch = c;
+
+ width = CharWidth (ch);
+ QDTextBounds (1, &ch, &char_bounds);
+ STORE_XCHARSTRUCT (*overall_return, width, char_bounds);
+ }
+ }
+
+ return err;
+}
+
+
+/* Mac replacement for XTextExtents16. Only sets horizontal metrics. */
+
+static int
+mac_text_extents_16 (font_struct, string, nchars, overall_return)
+ XFontStruct *font_struct;
+ XChar2b *string;
+ int nchars;
+ XCharStruct *overall_return;
+{
+ int i;
+ short width = 0, lbearing = 0, rbearing = 0;
+ XCharStruct *pcm;
+
+ for (i = 0; i < nchars; i++)
+ {
+ pcm = mac_per_char_metric (font_struct, string, 0);
+ if (pcm == NULL)
+ width += FONT_WIDTH (font_struct);
+ else
+ {
+ lbearing = min (lbearing, width + pcm->lbearing);
+ rbearing = max (rbearing, width + pcm->rbearing);
+ width += pcm->width;
+ }
+ string++;
+ }
+
+ overall_return->lbearing = lbearing;
+ overall_return->rbearing = rbearing;
+ overall_return->width = width;
+
+ /* What's the meaning of the return value of XTextExtents16? */
+}
+
+
+#if USE_CG_TEXT_DRAWING