summaryrefslogtreecommitdiff
path: root/src/cairo-atsui-font.c
blob: cb4b1c5d778ec3f78bd3bc6ccff14168532b6d6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
/* cairo - a vector graphics library with display and print output
 *
 * Copyright © 2004 Calum Robinson
 *
 * This library is free software; you can redistribute it and/or
 * modify it either under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation
 * (the "LGPL") or, at your option, under the terms of the Mozilla
 * Public License Version 1.1 (the "MPL"). If you do not alter this
 * notice, a recipient may use your version of this file under either
 * the MPL or the LGPL.
 *
 * You should have received a copy of the LGPL along with this library
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * You should have received a copy of the MPL along with this library
 * in the file COPYING-MPL-1.1
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
 * the specific language governing rights and limitations.
 *
 * The Original Code is the cairo graphics library.
 *
 * The Initial Developer of the Original Code is Calum Robinson
 *
 * Contributor(s):
 *	Calum Robinson <calumr@mac.com>
 */

#include <stdlib.h>
#include <math.h>

#include "cairo-atsui.h"
#include "cairoint.h"





#pragma mark Types





typedef struct {
	cairo_unscaled_font_t	base;
	
	ATSUStyle				style;
	ATSUFontID				fontID;
} cairo_atsui_font_t;


typedef struct cairo_ATSUI_glyph_path_callback_info_t {
	cairo_path_t		*path;
	cairo_matrix_t		scale;
} cairo_ATSUI_glyph_path_callback_info_t;





#pragma mark Private Functions





static CGAffineTransform CGAffineTransformMakeWithCairoFontScale(cairo_font_scale_t scale)
{
	return CGAffineTransformMake(	scale.matrix[0][0],	scale.matrix[0][1],
									scale.matrix[1][0],	scale.matrix[1][1],
									0, 0);
}


static ATSUStyle CreateSizedCopyOfStyle(ATSUStyle inStyle, cairo_font_scale_t	*scale)
{
	ATSUStyle				style;
	OSStatus				err;
	
	
	// Set the style's size
	CGAffineTransform		theTransform = CGAffineTransformMakeWithCairoFontScale(*scale);
	Fixed					theSize = FloatToFixed(CGSizeApplyAffineTransform(CGSizeMake(1.0, 1.0), theTransform).height);
	const ATSUAttributeTag  theFontStyleTags[] = { kATSUSizeTag };
	const ByteCount         theFontStyleSizes[] = { sizeof(Fixed) };
	ATSUAttributeValuePtr   theFontStyleValues[] = { &theSize };

	err = ATSUCreateAndCopyStyle(inStyle, &style);
	
	err = ATSUSetAttributes(	style,
								sizeof(theFontStyleTags) / sizeof(ATSUAttributeTag),
								theFontStyleTags, theFontStyleSizes, theFontStyleValues);
	
	
	return style;
}





#pragma mark Public Functions





static cairo_unscaled_font_t *
_cairo_atsui_font_create(	const char   	*family, 
							cairo_font_slant_t   slant, 
							cairo_font_weight_t  weight)
{
	cairo_atsui_font_t  *font = NULL;
	ATSUStyle			style;
	ATSUFontID			fontID;
	OSStatus			err;
	Boolean				isItalic, isBold;
	
	
	err = ATSUCreateStyle(&style);
	
	
	switch (weight)
	{
		case CAIRO_FONT_WEIGHT_BOLD:
			isBold = true;
			break;
		case CAIRO_FONT_WEIGHT_NORMAL:
		default:
			isBold = false;
			break;
	}

	switch (slant)
	{
		case CAIRO_FONT_SLANT_ITALIC:
			isItalic = true;
			break;
		case CAIRO_FONT_SLANT_OBLIQUE:
			isItalic = false;
			break;
		case CAIRO_FONT_SLANT_NORMAL:
		default:
			isItalic = false;
			break;
	}
	
	err = ATSUFindFontFromName( family, strlen(family),
								kFontFamilyName,
								kFontNoPlatformCode,
								kFontRomanScript,
								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));
	
	if (_cairo_unscaled_font_init(&font->base, &cairo_atsui_font_backend) == CAIRO_STATUS_SUCCESS)
	{
		font->style		= style;
		font->fontID	= fontID;
		
		
		return &font->base;
	}
	
	
	free(font);
	
	return NULL;
}


static void 
_cairo_atsui_font_destroy(void *abstract_font)
{
	cairo_atsui_font_t *font = abstract_font;
	
	
	if (font == NULL)
	    return;
	
	if (font->style)
		ATSUDisposeStyle(font->style);
	
	free(font);
}


static cairo_status_t 
_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;
}


static cairo_status_t 
_cairo_atsui_font_font_extents(	void					*abstract_font,
								cairo_font_scale_t   	*sc,
								cairo_font_extents_t	*extents)
{
	cairo_atsui_font_t	*font = abstract_font;
	ATSFontRef			atsFont;
	ATSFontMetrics		metrics;
	OSStatus			err;
	
	
	// 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;
			

			return CAIRO_STATUS_SUCCESS;
		}
	}
	
	
	return CAIRO_STATUS_NULL_POINTER;
}


static cairo_status_t 
_cairo_atsui_font_glyph_extents(	void					*abstract_font,
									cairo_font_scale_t		*sc,
									cairo_glyph_t			*glyphs, 
									int						num_glyphs,
									cairo_text_extents_t	*extents)
{
	cairo_atsui_font_t		*font = abstract_font;
	cairo_point_double_t	origin;
	cairo_point_double_t	glyph_min, glyph_max;
	cairo_point_double_t	total_min, total_max;
	OSStatus				err;
	ATSUStyle				style;
	int						i;
	

	if (num_glyphs == 0)
	{
		extents->x_bearing = 0.0;
		extents->y_bearing = 0.0;
		extents->width  = 0.0;
		extents->height = 0.0;
		extents->x_advance = 0.0;
		extents->y_advance = 0.0;

		return CAIRO_STATUS_SUCCESS;
	}

	origin.x = glyphs[0].x;
	origin.y = glyphs[0].y;
	
	
	style = CreateSizedCopyOfStyle(font->style, sc);
	

	for (i = 0; i < num_glyphs; i++)
	{
		GlyphID					theGlyph = glyphs[i].index;
		double					minX, maxX, ascent, descent;
		ATSGlyphIdealMetrics	metricsH, metricsV;
		
		
		err = ATSUGlyphGetIdealMetrics(	style,
										1,
										&theGlyph,
										0,
										&metricsH);
		
		
		ATSUVerticalCharacterType	verticalType = kATSUStronglyVertical;
		ATSUAttributeTag			theTag = kATSUVerticalCharacterTag;
		ByteCount					theSize = sizeof(ATSUVerticalCharacterType);
		
		err = ATSUSetAttributes(style, 1, &theTag, &theSize, (ATSUAttributeValuePtr)&verticalType);
		
		err = ATSUGlyphGetIdealMetrics(	style,
										1,
										&theGlyph,
										0,
										&metricsV);
		
		minX = metricsH.otherSideBearing.x;
		maxX = metricsH.advance.x;
		
		ascent = metricsV.advance.x;
		descent = metricsV.otherSideBearing.x;
		
		glyph_min.x = glyphs[i].x + minX;
		glyph_min.y = glyphs[i].y + descent;
		glyph_max.x = glyphs[i].x + maxX;
		glyph_max.y = glyphs[i].y + ascent;
		
		if (i==0)
		{
			total_min = glyph_min;
			total_max = glyph_max;
		}
		else
		{
			if (glyph_min.x < total_min.x)
				total_min.x = glyph_min.x;
			if (glyph_min.y < total_min.y)
				total_min.y = glyph_min.y;

			if (glyph_max.x > total_max.x)
				total_max.x = glyph_max.x;
			if (glyph_max.y > total_max.y)
				total_max.y = glyph_max.y;
		}
	}
	

	extents->x_bearing = total_min.x - origin.x;
	extents->y_bearing = total_min.y - origin.y;
	extents->width 	= total_max.x - total_min.x;
	extents->height	= total_max.y - total_min.y;
	extents->x_advance = glyphs[i-1].x - origin.x;
	extents->y_advance = glyphs[i-1].y - origin.y;
	
	
	return CAIRO_STATUS_SUCCESS;
}


static cairo_status_t 
_cairo_atsui_font_glyph_bbox(	void				*abstract_font,
								cairo_font_scale_t 	*sc,
								const cairo_glyph_t	*glyphs,
								int					num_glyphs,
								cairo_box_t 		*bbox)
{
	cairo_atsui_font_t	*font = abstract_font;
	cairo_fixed_t		x1, y1, x2, y2;
	int					i;
	OSStatus			err;
	ATSUStyle			style;
	

	bbox->p1.x = bbox->p1.y = CAIRO_MAXSHORT << 16;
	bbox->p2.x = bbox->p2.y = CAIRO_MINSHORT << 16;
	
	
	style = CreateSizedCopyOfStyle(font->style, sc);
	
	
	for (i = 0; i < num_glyphs; i++)
	{
		GlyphID					theGlyph = glyphs[i].index;
		ATSGlyphIdealMetrics	metrics;
		
		
		err = ATSUGlyphGetIdealMetrics(	style,
										1,
										&theGlyph,
										0,
										&metrics);
		
		x1 = _cairo_fixed_from_double(glyphs[i].x);
		y1 = _cairo_fixed_from_double(glyphs[i].y);
		x2 = x1 + _cairo_fixed_from_double(metrics.advance.x);
		y2 = y1 + _cairo_fixed_from_double(metrics.advance.y);
		
		if (x1 < bbox->p1.x)
			bbox->p1.x = x1;
		
		if (y1 < bbox->p1.y)
			bbox->p1.y = y1;
		
		if (x2 > bbox->p2.x)
			bbox->p2.x = x2;
		
		if (y2 > bbox->p2.y)
			bbox->p2.y = y2;
	}
	
	
	ATSUDisposeStyle(style);
	

	return CAIRO_STATUS_SUCCESS;
}


static cairo_status_t 
_cairo_atsui_font_show_glyphs(	void				*abstract_font,
								cairo_font_scale_t 	*sc,
								cairo_operator_t	operator,
								cairo_surface_t 	*source,
								cairo_surface_t 	*surface,
								int					source_x,
								int					source_y,
								const cairo_glyph_t	*glyphs,
								int					num_glyphs)
{
	cairo_atsui_font_t		*font = abstract_font;
	CGContextRef			myBitmapContext;
    CGColorSpaceRef			colorSpace;
	cairo_image_surface_t	*destImageSurface;
	int						i;
	
	
	destImageSurface = _cairo_surface_get_image(surface);
    
	
	// Create a CGBitmapContext for the dest surface for drawing into
    colorSpace = CGColorSpaceCreateDeviceRGB();
	
	myBitmapContext = CGBitmapContextCreate(	destImageSurface->data,
												destImageSurface->width,
												destImageSurface->height,
												destImageSurface->depth / 4,
												destImageSurface->stride,
												colorSpace,
												kCGImageAlphaPremultipliedFirst);
	
	
	ATSFontRef	atsFont	= FMGetATSFontRefFromFont(font->fontID);
	CGFontRef	cgFont	= CGFontCreateWithPlatformFont(&atsFont);
	
	CGContextSetFont(myBitmapContext, cgFont);
	
	
	CGAffineTransform	textTransform = CGAffineTransformMakeWithCairoFontScale(*sc);
    CGSize				textSize = CGSizeMake(1.0, 1.0);
	
	textSize = CGSizeApplyAffineTransform(textSize, textTransform);
	
	CGContextSetFontSize(myBitmapContext, textSize.width);
	
	
	// 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;
		
		CGContextShowGlyphsAtPoint(myBitmapContext, source_x + glyphs[i].x, destImageSurface->height - (source_y + glyphs[i].y), &theGlyph, 1);
	}
	
	
	CGColorSpaceRelease(colorSpace);
	CGContextRelease(myBitmapContext);
	
	
	return CAIRO_STATUS_SUCCESS;
}


#pragma mark -


static OSStatus MyATSCubicMoveToCallback(const Float32Point *pt, void *callBackDataPtr)
{
    cairo_ATSUI_glyph_path_callback_info_t	*info = callBackDataPtr;
    double									scaledPt[2];
	cairo_point_t							point;
	
	
	scaledPt[0] = pt->x;
	scaledPt[1] = pt->y;
	
	cairo_matrix_transform_point(&info->scale, &scaledPt[0], &scaledPt[1]);

    point.x = _cairo_fixed_from_double(scaledPt[0]);
    point.y = _cairo_fixed_from_double(scaledPt[1]);

    _cairo_path_move_to(info->path, &point);
    
	
    return noErr;
}


static OSStatus MyATSCubicLineToCallback(const Float32Point *pt, void *callBackDataPtr)
{
    cairo_ATSUI_glyph_path_callback_info_t	*info = callBackDataPtr;
    cairo_point_t							point;
    double									scaledPt[2];
	
	
	scaledPt[0] = pt->x;
	scaledPt[1] = pt->y;
	
	cairo_matrix_transform_point(&info->scale, &scaledPt[0], &scaledPt[1]);
	
    point.x = _cairo_fixed_from_double(scaledPt[0]);
    point.y = _cairo_fixed_from_double(scaledPt[1]);

    _cairo_path_line_to(info->path, &point);
	
	
    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;
    cairo_point_t p0, p1, p2;
	double	scaledPt[2];
	
	
	scaledPt[0] = pt1->x;
	scaledPt[1] = pt1->y;
	
	cairo_matrix_transform_point(&info->scale, &scaledPt[0], &scaledPt[1]);

    p0.x = _cairo_fixed_from_double(scaledPt[0]);
    p0.y = _cairo_fixed_from_double(scaledPt[1]);
	

    scaledPt[0] = pt2->x;
	scaledPt[1] = pt2->y;
	
	cairo_matrix_transform_point(&info->scale, &scaledPt[0], &scaledPt[1]);

    p1.x = _cairo_fixed_from_double(scaledPt[0]);
    p1.y = _cairo_fixed_from_double(scaledPt[1]);
	

    scaledPt[0] = pt3->x;
	scaledPt[1] = pt3->y;
	
	cairo_matrix_transform_point(&info->scale, &scaledPt[0], &scaledPt[1]);

    p2.x = _cairo_fixed_from_double(scaledPt[0]);
    p2.y = _cairo_fixed_from_double(scaledPt[1]);
	

    _cairo_path_curve_to(info->path, &p0, &p1, &p2);
    
	
    return noErr; 
}


static OSStatus MyCubicClosePathProc(void * callBackDataPtr) 
{
    cairo_ATSUI_glyph_path_callback_info_t	*info = callBackDataPtr;
    
	
    _cairo_path_close_path(info->path);
    
	
    return noErr; 
}


static cairo_status_t 
_cairo_atsui_font_glyph_path(	void				*abstract_font,
								cairo_font_scale_t 	*sc,
								cairo_glyph_t		*glyphs, 
								int					num_glyphs,
								cairo_path_t		*path)
{
	int										i;
	cairo_atsui_font_t						*font = abstract_font;
	OSStatus								err;
	cairo_ATSUI_glyph_path_callback_info_t	info;
	ATSUStyle								style;
	
	
	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;
	
	
	style = CreateSizedCopyOfStyle(font->style, sc);
		

	for (i = 0; i < num_glyphs; i++)
	{
		GlyphID theGlyph = glyphs[i].index;
		
		
		cairo_matrix_set_affine(	&info.scale,
									1.0, 0.0,
									0.0, 1.0,
									glyphs[i].x, glyphs[i].y);
		
		
		err = ATSUGlyphGetCubicPaths(   style, 
										theGlyph, 
										moveProc,
										lineProc,
										curveProc,
										closePathProc,
										(void *)&info, 
										&err);
	}
	
	
	err = ATSUDisposeStyle(style);
	
	
	return CAIRO_STATUS_SUCCESS;
}


#pragma mark -


static cairo_status_t 
_cairo_atsui_font_create_glyph(cairo_image_glyph_cache_entry_t 	*val)	
{
	// TODO
	printf("_cairo_atsui_font_create_glyph is unimplemented\n");
	
	// I'm not sure if we need this, given that the ATSUI backend does no caching(?)
	
	
	return CAIRO_STATUS_SUCCESS;
}


cairo_font_t *
cairo_atsui_font_create(ATSUStyle style)
{	
	cairo_font_scale_t scale;
	cairo_font_t *scaled;
	cairo_atsui_font_t *f = NULL;
	
	
	scaled = malloc(sizeof(cairo_font_t));
	if (scaled == NULL)
		return NULL;
	
	
	f = malloc(sizeof(cairo_atsui_font_t));
	if (f)
	{
		if (_cairo_unscaled_font_init(&f->base, &cairo_atsui_font_backend) == CAIRO_STATUS_SUCCESS)
		{
			f->style = style;

			_cairo_font_init(scaled, &scale, &f->base);

			return scaled;
		}
	}
	
	
	free(scaled);
	
	
	return NULL;
}





#pragma mark Backend





const cairo_font_backend_t cairo_atsui_font_backend = {
	_cairo_atsui_font_create,
	_cairo_atsui_font_destroy,
	_cairo_atsui_font_font_extents,
	_cairo_atsui_font_text_to_glyphs,
	_cairo_atsui_font_glyph_extents,
	_cairo_atsui_font_glyph_bbox,
	_cairo_atsui_font_show_glyphs,
	_cairo_atsui_font_glyph_path,
	_cairo_atsui_font_create_glyph
};