3 docCopyright("Daniel Rosengren", 2007)
4 docLicense("BSD revised")
5 docCategory("Graphics")
8 #include "IoCairoScaledFont.h"
9 #include "IoCairoFontFace.h"
10 #include "IoCairoFontExtents.h"
11 #include "IoCairoTextExtents.h"
12 #include "IoCairoFontOptions.h"
13 #include "IoCairoGlyph.h"
14 #include "IoCairoMatrix.h"
20 #define FONT(self) ((cairo_scaled_font_t *)IoObject_dataPointer(self))
21 #define CHECK_STATUS(self) checkStatus_(IOSTATE, m, cairo_scaled_font_status(FONT(self)))
24 void *IoMessage_locals_cairoScaledFontArgAt_(IoMessage
*self
, void *locals
, int n
)
26 IoObject
*arg
= IoMessage_locals_valueArgAt_(self
, locals
, n
);
27 if (!ISCAIROSCALEDFONT(arg
))
28 IoMessage_locals_numberArgAt_errorForType_(self
, locals
, n
, "CairoScaledFont");
33 static IoTag
*IoCairoScaledFont_newTag(void *state
)
35 IoTag
*tag
= IoTag_newWithName_("CairoScaledFont");
36 IoTag_state_(tag
, state
);
37 IoTag_freeFunc_(tag
, (IoTagFreeFunc
*)IoCairoScaledFont_free
);
38 IoTag_cloneFunc_(tag
, (IoTagCloneFunc
*)IoCairoScaledFont_rawClone
);
42 IoCairoScaledFont
*IoCairoScaledFont_proto(void *state
)
44 IoObject
*self
= IoObject_new(state
);
45 IoObject_tag_(self
, IoCairoScaledFont_newTag(state
));
47 IoState_registerProtoWithFunc_(state
, self
, IoCairoScaledFont_proto
);
50 IoMethodTable methodTable
[] = {
51 {"create", IoCairoScaledFont_create
},
53 {"extents", IoCairoScaledFont_extents
},
54 {"textExtents", IoCairoScaledFont_textExtents
},
55 {"glyphExtents", IoCairoScaledFont_glyphExtents
},
57 {"getFontFace", IoCairoScaledFont_getFontFace
},
58 {"getFontOptions", IoCairoScaledFont_getFontOptions
},
59 {"getFontMatrix", IoCairoScaledFont_getFontMatrix
},
60 {"getCTM", IoCairoScaledFont_getCTM
},
65 IoObject_addMethodTable_(self
, methodTable
);
71 IoCairoScaledFont
*IoCairoScaledFont_rawClone(IoCairoScaledFont
*proto
)
73 IoCairoScaledFont
*self
= IoObject_rawClonePrimitive(proto
);
75 IoObject_setDataPointer_(self
, cairo_scaled_font_reference(FONT(proto
)));
79 IoCairoScaledFont
*IoCairoScaledFont_newWithRawScaledFont_(void *state
, IoMessage
*m
, cairo_scaled_font_t
*font
)
81 IoCairoScaledFont
*self
= IOCLONE(IoState_protoWithInitFunction_(state
, IoCairoScaledFont_proto
));
82 IoObject_setDataPointer_(self
, font
);
87 void IoCairoScaledFont_free(IoCairoScaledFont
*self
)
90 cairo_scaled_font_destroy(FONT(self
));
93 cairo_scaled_font_t
*IoCairoScaledFont_rawScaledFont(IoCairoScaledFont
*self
)
99 /* ------------------------------------------------------------------------------------------------*/
101 IoObject
*IoCairoScaledFont_create(IoCairoScaledFont
*self
, IoObject
*locals
, IoMessage
*m
)
103 IoCairoFontFace
*face
= IoMessage_locals_cairoFontFaceArgAt_(m
, locals
, 0);
104 IoCairoMatrix
*matrix
= IoMessage_locals_cairoMatrixArgAt_(m
, locals
, 1);
105 IoCairoMatrix
*ctm
= IoMessage_locals_cairoMatrixArgAt_(m
, locals
, 2);
106 IoCairoFontOptions
*options
= IoMessage_locals_cairoFontOptionsArgAt_(m
, locals
, 3);
108 cairo_scaled_font_t
*font
= cairo_scaled_font_create(
109 IoCairoFontFace_rawFontFace(face
),
110 IoCairoMatrix_rawMatrix(matrix
),
111 IoCairoMatrix_rawMatrix(ctm
),
112 IoCairoFontOptions_rawFontOptions(options
)
114 return IoCairoScaledFont_newWithRawScaledFont_(IOSTATE
, m
, font
);
118 IoObject
*IoCairoScaledFont_extents(IoCairoScaledFont
*self
, IoObject
*locals
, IoMessage
*m
)
120 cairo_font_extents_t extents
;
121 cairo_scaled_font_extents(FONT(self
), &extents
);
123 return IoCairoFontExtents_newWithRawFontExtents(IOSTATE
, &extents
);
126 IoObject
*IoCairoScaledFont_textExtents(IoCairoScaledFont
*self
, IoObject
*locals
, IoMessage
*m
)
128 const char *text
= IoMessage_locals_UTF8ArgAt_(m
, locals
, 0);
129 cairo_text_extents_t extents
;
130 cairo_scaled_font_text_extents(FONT(self
), text
, &extents
);
132 return IoCairoTextExtents_newWithRawTextExtents(IOSTATE
, &extents
);
135 IoObject
*IoCairoScaledFont_glyphExtents(IoCairoScaledFont
*self
, IoObject
*locals
, IoMessage
*m
)
137 IoList
*glyphList
= IoMessage_locals_listArgAt_(m
, locals
, 0);
139 cairo_glyph_t
*glyphs
= rawGlyphsFromList_count_(glyphList
, &glyphCount
);
140 cairo_text_extents_t extents
;
145 cairo_scaled_font_glyph_extents(FONT(self
), glyphs
, glyphCount
, &extents
);
148 return IoCairoTextExtents_newWithRawTextExtents(IOSTATE
, &extents
);
152 IoObject
*IoCairoScaledFont_getFontFace(IoCairoScaledFont
*self
, IoObject
*locals
, IoMessage
*m
)
154 cairo_font_face_t
*face
= cairo_scaled_font_get_font_face(FONT(self
));
155 return IoCairoFontFace_newWithRawFontFace_(self
, cairo_font_face_reference(face
));
158 IoObject
*IoCairoScaledFont_getFontOptions(IoCairoScaledFont
*self
, IoObject
*locals
, IoMessage
*m
)
160 cairo_font_options_t
*options
= cairo_font_options_create();
161 cairo_scaled_font_get_font_options(FONT(self
), options
);
162 return IoCairoFontOptions_newWithRawFontOptions_(IOSTATE
, m
, options
);
165 IoObject
*IoCairoScaledFont_getFontMatrix(IoCairoScaledFont
*self
, IoObject
*locals
, IoMessage
*m
)
167 cairo_matrix_t matrix
;
168 cairo_scaled_font_get_font_matrix(FONT(self
), &matrix
);
169 return IoCairoMatrix_newWithRawMatrix_(IOSTATE
, &matrix
);
172 IoObject
*IoCairoScaledFont_getCTM(IoCairoScaledFont
*self
, IoObject
*locals
, IoMessage
*m
)
174 cairo_matrix_t matrix
;
175 cairo_scaled_font_get_ctm(FONT(self
), &matrix
);
176 return IoCairoMatrix_newWithRawMatrix_(IOSTATE
, &matrix
);