for (i = 0; i < glyphCount; i++) { (*glyphs)[i].index = layoutRecords[i].glyphID; (*glyphs)[i].x = FixedToFloat(layoutRecords[i].realPos); (*glyphs)[i].y = 0; }   free(theText);  ATSUDirectReleaseLayoutDataArrayPtr(	NULL, kATSUDirectDataLayoutRecordATSLayoutRecordCurrent, (void *)&layoutRecords);  ATSUDisposeTextLayout(textLayout);  ATSUDisposeStyle(style);   return CAIRO_STATUS_SUCCESS;
err = ATSUCreateTextLayout(&textLayout);  #if 1 charCount = strlen(utf8);   theText = (UniChar *) malloc(charCount * sizeof(UniChar));  for (i = 0; i < charCount; i++) { theText[i] = utf8[i]; } #endif  #if 0  charCount = strlen(utf8); theText = (UniChar *) malloc(charCount * sizeof(UniChar));  size_t inBytes = charCount, outBytes = charCount; iconv_t converter = iconv_open("UTF-8", "UTF-16"); charCount = iconv(converter, utf8, &inBytes, theText, &outBytes); #endif  err = ATSUSetTextPointerLocation(textLayout, theText, 0, charCount, charCount);    err = ATSUSetRunStyle(textLayout, font->unscaled_style, kATSUFromTextBeginning, kATSUToTextEnd);   err = ATSUDirectGetLayoutDataArrayPtrFromTextLayout(textLayout, 0, kATSUDirectDataLayoutRecordATSLayoutRecordCurrent, (void *) &layoutRecords, &glyphCount);  *nglyphs = glyphCount - 1;   *glyphs = (cairo_glyph_t *) malloc(*nglyphs * (sizeof(cairo_glyph_t))); if (*glyphs == NULL) { return CAIRO_STATUS_NO_MEMORY; }  for (i = 0; i < *nglyphs; i++) { (*glyphs)[i].index = layoutRecords[i].glyphID; (*glyphs)[i].x = FixedToFloat(layoutRecords[i].realPos); (*glyphs)[i].y = 0; }   free(theText);  ATSUDirectReleaseLayoutDataArrayPtr(NULL, kATSUDirectDataLayoutRecordATSLayoutRecordCurrent, (void *) &layoutRecords);  ATSUDisposeTextLayout(textLayout);  ATSUDisposeStyle(style);   return CAIRO_STATUS_SUCCESS;
_cairo_atsui_font_text_to_glyphs(	void				*abstract_font,									cairo_font_scale_t	*sc,									const unsigned char	*utf8,									cairo_glyph_t		**glyphs, 									int					*nglyphs){	cairo_atsui_font_t	*font = abstract_font;	size_t				i;	OSStatus			err;	ATSUTextLayout		textLayout;	ATSLayoutRecord		*layoutRecords;	ItemCount			glyphCount, charCount;	UniChar				*theText;	ATSUStyle			style;			charCount = strlen(utf8);			err = ATSUCreateTextLayout(&textLayout);			// Set the text in the text layout object, so we can measure it	theText = (UniChar *)malloc(charCount * sizeof(UniChar));		for (i = 0; i < charCount; i++)	{		theText[i] = utf8[i];	}		err = ATSUSetTextPointerLocation(   textLayout, 										theText, 										0, 										charCount, 										charCount);			style = CreateSizedCopyOfStyle(font->style, sc);			// Set the style for all of the text	err = ATSUSetRunStyle(	textLayout, 							style, 							kATSUFromTextBeginning, 							kATSUToTextEnd);				// Get the glyphs from the text layout object	err = ATSUDirectGetLayoutDataArrayPtrFromTextLayout(	textLayout,															0,															kATSUDirectDataLayoutRecordATSLayoutRecordCurrent, 															(void *)&layoutRecords,  															&glyphCount); 		*nglyphs = glyphCount;			*glyphs = (cairo_glyph_t *)malloc(glyphCount * (sizeof(cairo_glyph_t)));	if (*glyphs == NULL)	{	    return CAIRO_STATUS_NO_MEMORY;	}	for (i = 0; i < glyphCount; i++)	{		(*glyphs)[i].index = layoutRecords[i].glyphID;		(*glyphs)[i].x = FixedToFloat(layoutRecords[i].realPos);		(*glyphs)[i].y = 0;	}			free(theText);		ATSUDirectReleaseLayoutDataArrayPtr(	NULL, 											kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,											(void *)&layoutRecords); 		ATSUDisposeTextLayout(textLayout);		ATSUDisposeStyle(style);			return CAIRO_STATUS_SUCCESS;}