1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = cairo-cairo-scaled-font-t.html
27  * outPack = cairo
28  * outFile = ScaledFont
29  * strct   = cairo_scaled_font_t
30  * realStrct=
31  * ctorStrct=
32  * clss    = ScaledFont
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- cairo_scaled_font_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- cairo.FontFace
47  * 	- cairo.FontOption
48  * 	- cairo.Matrix
49  * 	- glib.Str
50  * structWrap:
51  * 	- cairo_font_face_t* -> FontFace
52  * 	- cairo_font_options_t* -> FontOption
53  * 	- cairo_matrix_t* -> Matrix
54  * 	- cairo_scaled_font_t* -> ScaledFont
55  * module aliases:
56  * local aliases:
57  * overrides:
58  */
59 
60 module cairo.ScaledFont;
61 
62 public  import gtkc.cairotypes;
63 
64 private import gtkc.cairo;
65 private import glib.ConstructionException;
66 
67 
68 private import cairo.FontFace;
69 private import cairo.FontOption;
70 private import cairo.Matrix;
71 private import glib.Str;
72 
73 
74 
75 
76 /**
77  * Description
78  * cairo_scaled_font_t represents a realization of a font face at a particular
79  * size and transformation and a certain set of font options.
80  */
81 public class ScaledFont
82 {
83 	
84 	/** the main Gtk struct */
85 	protected cairo_scaled_font_t* cairo_scaled_font;
86 	
87 	
88 	public cairo_scaled_font_t* getScaledFontStruct()
89 	{
90 		return cairo_scaled_font;
91 	}
92 	
93 	
94 	/** the main Gtk struct as a void* */
95 	protected void* getStruct()
96 	{
97 		return cast(void*)cairo_scaled_font;
98 	}
99 	
100 	/**
101 	 * Sets our main struct and passes it to the parent class
102 	 */
103 	public this (cairo_scaled_font_t* cairo_scaled_font)
104 	{
105 		this.cairo_scaled_font = cairo_scaled_font;
106 	}
107 	
108 	/**
109 	 */
110 	
111 	/**
112 	 * Creates a cairo_scaled_font_t object from a font face and matrices that
113 	 * describe the size of the font and the environment in which it will
114 	 * be used.
115 	 * Params:
116 	 * fontFace = a cairo_font_face_t
117 	 * fontMatrix = font space to user space transformation matrix for the
118 	 *  font. In the simplest case of a N point font, this matrix is
119 	 *  just a scale by N, but it can also be used to shear the font
120 	 *  or stretch it unequally along the two axes. See
121 	 *  cairo_set_font_matrix().
122 	 * ctm = user to device transformation matrix with which the font will
123 	 *  be used.
124 	 * options = options to use when getting metrics for the font and
125 	 *  rendering with it.
126 	 * Returns: a newly created cairo_scaled_font_t. Destroy with cairo_scaled_font_destroy()
127 	 */
128 	public static ScaledFont create(FontFace fontFace, Matrix fontMatrix, Matrix ctm, FontOption options)
129 	{
130 		// cairo_scaled_font_t * cairo_scaled_font_create (cairo_font_face_t *font_face,  const cairo_matrix_t *font_matrix,  const cairo_matrix_t *ctm,  const cairo_font_options_t *options);
131 		auto p = cairo_scaled_font_create((fontFace is null) ? null : fontFace.getFontFaceStruct(), (fontMatrix is null) ? null : fontMatrix.getMatrixStruct(), (ctm is null) ? null : ctm.getMatrixStruct(), (options is null) ? null : options.getFontOptionStruct());
132 		
133 		if(p is null)
134 		{
135 			return null;
136 		}
137 		
138 		return new ScaledFont(cast(cairo_scaled_font_t*) p);
139 	}
140 	
141 	/**
142 	 * Increases the reference count on scaled_font by one. This prevents
143 	 * scaled_font from being destroyed until a matching call to
144 	 * cairo_scaled_font_destroy() is made.
145 	 * The number of references to a cairo_scaled_font_t can be get using
146 	 * cairo_scaled_font_get_reference_count().
147 	 * Returns: the referenced cairo_scaled_font_t
148 	 */
149 	public ScaledFont reference()
150 	{
151 		// cairo_scaled_font_t * cairo_scaled_font_reference (cairo_scaled_font_t *scaled_font);
152 		auto p = cairo_scaled_font_reference(cairo_scaled_font);
153 		
154 		if(p is null)
155 		{
156 			return null;
157 		}
158 		
159 		return new ScaledFont(cast(cairo_scaled_font_t*) p);
160 	}
161 	
162 	/**
163 	 * Decreases the reference count on font by one. If the result
164 	 * is zero, then font and all associated resources are freed.
165 	 * See cairo_scaled_font_reference().
166 	 */
167 	public void destroy()
168 	{
169 		// void cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font);
170 		cairo_scaled_font_destroy(cairo_scaled_font);
171 	}
172 	
173 	/**
174 	 * Checks whether an error has previously occurred for this
175 	 * scaled_font.
176 	 * Returns: CAIRO_STATUS_SUCCESS or another error such as CAIRO_STATUS_NO_MEMORY.
177 	 */
178 	public cairo_status_t status()
179 	{
180 		// cairo_status_t cairo_scaled_font_status (cairo_scaled_font_t *scaled_font);
181 		return cairo_scaled_font_status(cairo_scaled_font);
182 	}
183 	
184 	/**
185 	 * Gets the metrics for a cairo_scaled_font_t.
186 	 * Params:
187 	 * extents = a cairo_font_extents_t which to store the retrieved extents.
188 	 */
189 	public void extents(cairo_font_extents_t* extents)
190 	{
191 		// void cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font,  cairo_font_extents_t *extents);
192 		cairo_scaled_font_extents(cairo_scaled_font, extents);
193 	}
194 	
195 	/**
196 	 * Gets the extents for a string of text. The extents describe a
197 	 * user-space rectangle that encloses the "inked" portion of the text
198 	 * drawn at the origin (0,0) (as it would be drawn by cairo_show_text()
199 	 * if the cairo graphics state were set to the same font_face,
200 	 * font_matrix, ctm, and font_options as scaled_font). Additionally,
201 	 * the x_advance and y_advance values indicate the amount by which the
202 	 * current point would be advanced by cairo_show_text().
203 	 * Note that whitespace characters do not directly contribute to the
204 	 * size of the rectangle (extents.width and extents.height). They do
205 	 * contribute indirectly by changing the position of non-whitespace
206 	 * characters. In particular, trailing whitespace characters are
207 	 * likely to not affect the size of the rectangle, though they will
208 	 * affect the x_advance and y_advance values.
209 	 * Since 1.2
210 	 * Params:
211 	 * utf8 = a NUL-terminated string of text, encoded in UTF-8
212 	 * extents = a cairo_text_extents_t which to store the retrieved extents.
213 	 */
214 	public void textExtents(string utf8, cairo_text_extents_t* extents)
215 	{
216 		// void cairo_scaled_font_text_extents (cairo_scaled_font_t *scaled_font,  const char *utf8,  cairo_text_extents_t *extents);
217 		cairo_scaled_font_text_extents(cairo_scaled_font, Str.toStringz(utf8), extents);
218 	}
219 	
220 	/**
221 	 * Gets the extents for an array of glyphs. The extents describe a
222 	 * user-space rectangle that encloses the "inked" portion of the
223 	 * glyphs, (as they would be drawn by cairo_show_glyphs() if the cairo
224 	 * graphics state were set to the same font_face, font_matrix, ctm,
225 	 * and font_options as scaled_font). Additionally, the x_advance and
226 	 * y_advance values indicate the amount by which the current point
227 	 * would be advanced by cairo_show_glyphs().
228 	 * Note that whitespace glyphs do not contribute to the size of the
229 	 * rectangle (extents.width and extents.height).
230 	 * Params:
231 	 * glyphs = an array of glyph IDs with X and Y offsets.
232 	 * numGlyphs = the number of glyphs in the glyphs array
233 	 * extents = a cairo_text_extents_t which to store the retrieved extents.
234 	 */
235 	public void glyphExtents(cairo_glyph_t* glyphs, int numGlyphs, cairo_text_extents_t* extents)
236 	{
237 		// void cairo_scaled_font_glyph_extents (cairo_scaled_font_t *scaled_font,  const cairo_glyph_t *glyphs,  int num_glyphs,  cairo_text_extents_t *extents);
238 		cairo_scaled_font_glyph_extents(cairo_scaled_font, glyphs, numGlyphs, extents);
239 	}
240 	
241 	/**
242 	 * Converts UTF-8 text to an array of glyphs, optionally with cluster
243 	 * mapping, that can be used to render later using scaled_font.
244 	 * If glyphs initially points to a non-NULL value, that array is used
245 	 * as a glyph buffer, and num_glyphs should point to the number of glyph
246 	 * entries available there. If the provided glyph array is too short for
247 	 * the conversion, a new glyph array is allocated using cairo_glyph_allocate()
248 	 * and placed in glyphs. Upon return, num_glyphs always contains the
249 	 * number of generated glyphs. If the value glyphs points to has changed
250 	 * after the call, the user is responsible for freeing the allocated glyph
251 	 * array using cairo_glyph_free(). This may happen even if the provided
252 	 * array was large enough.
253 	 * If clusters is not NULL, num_clusters and cluster_flags should not be NULL,
254 	 * and cluster mapping will be computed.
255 	 * The semantics of how cluster array allocation works is similar to the glyph
256 	 * array. That is,
257 	 * if clusters initially points to a non-NULL value, that array is used
258 	 * as a cluster buffer, and num_clusters should point to the number of cluster
259 	 * entries available there. If the provided cluster array is too short for
260 	 * the conversion, a new cluster array is allocated using cairo_text_cluster_allocate()
261 	 * and placed in clusters. Upon return, num_clusters always contains the
262 	 * number of generated clusters. If the value clusters points at has changed
263 	 * after the call, the user is responsible for freeing the allocated cluster
264 	 * array using cairo_text_cluster_free(). This may happen even if the provided
265 	 * array was large enough.
266 	 * In the simplest case, glyphs and clusters can point to NULL initially
267 	 * Since 1.8
268 	 * Params:
269 	 * x = X position to place first glyph
270 	 * y = Y position to place first glyph
271 	 * utf8 = a string of text encoded in UTF-8
272 	 * utf8_Len = length of utf8 in bytes, or -1 if it is NUL-terminated
273 	 * glyphs = pointer to array of glyphs to fill
274 	 * clusters = pointer to array of cluster mapping information to fill, or NULL
275 	 * clusterFlags = pointer to location to store cluster flags corresponding to the
276 	 *  output clusters, or NULL
277 	 * Returns: CAIRO_STATUS_SUCCESS upon success, or an error status if the input values are wrong or if conversion failed. If the input values are correct but the conversion failed, the error status is also set on scaled_font.
278 	 */
279 	public cairo_status_t textToGlyphs(double x, double y, string utf8, int utf8_Len, out cairo_glyph_t[] glyphs, out cairo_text_cluster_t[] clusters, out cairo_text_cluster_flags_t clusterFlags)
280 	{
281 		// cairo_status_t cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t *scaled_font,  double x,  double y,  const char *utf8,  int utf8_len,  cairo_glyph_t **glyphs,  int *num_glyphs,  cairo_text_cluster_t **clusters,  int *num_clusters,  cairo_text_cluster_flags_t *cluster_flags);
282 		cairo_glyph_t* outglyphs = null;
283 		int numGlyphs;
284 		cairo_text_cluster_t* outclusters = null;
285 		int numClusters;
286 		
287 		auto p = cairo_scaled_font_text_to_glyphs(cairo_scaled_font, x, y, Str.toStringz(utf8), utf8_Len, &outglyphs, &numGlyphs, &outclusters, &numClusters, &clusterFlags);
288 		
289 		glyphs = outglyphs[0 .. numGlyphs];
290 		clusters = outclusters[0 .. numClusters];
291 		return p;
292 	}
293 	
294 	/**
295 	 * Gets the font face that this scaled font uses. This is the
296 	 * font face passed to cairo_scaled_font_create().
297 	 * Since 1.2
298 	 * Returns: The cairo_font_face_t with which scaled_font was created.
299 	 */
300 	public FontFace getFontFace()
301 	{
302 		// cairo_font_face_t * cairo_scaled_font_get_font_face (cairo_scaled_font_t *scaled_font);
303 		auto p = cairo_scaled_font_get_font_face(cairo_scaled_font);
304 		
305 		if(p is null)
306 		{
307 			return null;
308 		}
309 		
310 		return new FontFace(cast(cairo_font_face_t*) p);
311 	}
312 	
313 	/**
314 	 * Stores the font options with which scaled_font was created into
315 	 * options.
316 	 * Since 1.2
317 	 * Params:
318 	 * options = return value for the font options
319 	 */
320 	public void getFontOptions(FontOption options)
321 	{
322 		// void cairo_scaled_font_get_font_options (cairo_scaled_font_t *scaled_font,  cairo_font_options_t *options);
323 		cairo_scaled_font_get_font_options(cairo_scaled_font, (options is null) ? null : options.getFontOptionStruct());
324 	}
325 	
326 	/**
327 	 * Stores the font matrix with which scaled_font was created into
328 	 * matrix.
329 	 * Since 1.2
330 	 * Params:
331 	 * fontMatrix = return value for the matrix
332 	 */
333 	public void getFontMatrix(Matrix fontMatrix)
334 	{
335 		// void cairo_scaled_font_get_font_matrix (cairo_scaled_font_t *scaled_font,  cairo_matrix_t *font_matrix);
336 		cairo_scaled_font_get_font_matrix(cairo_scaled_font, (fontMatrix is null) ? null : fontMatrix.getMatrixStruct());
337 	}
338 	
339 	/**
340 	 * Stores the CTM with which scaled_font was created into ctm.
341 	 * Note that the translation offsets (x0, y0) of the CTM are ignored
342 	 * by cairo_scaled_font_create(). So, the matrix this
343 	 * function returns always has 0,0 as x0,y0.
344 	 * Since 1.2
345 	 * Params:
346 	 * ctm = return value for the CTM
347 	 */
348 	public void getCtm(Matrix ctm)
349 	{
350 		// void cairo_scaled_font_get_ctm (cairo_scaled_font_t *scaled_font,  cairo_matrix_t *ctm);
351 		cairo_scaled_font_get_ctm(cairo_scaled_font, (ctm is null) ? null : ctm.getMatrixStruct());
352 	}
353 	
354 	/**
355 	 * Stores the scale matrix of scaled_font into matrix.
356 	 * The scale matrix is product of the font matrix and the ctm
357 	 * associated with the scaled font, and hence is the matrix mapping from
358 	 * font space to device space.
359 	 * Since 1.8
360 	 * Params:
361 	 * scaleMatrix = return value for the matrix
362 	 */
363 	public void getScaleMatrix(Matrix scaleMatrix)
364 	{
365 		// void cairo_scaled_font_get_scale_matrix (cairo_scaled_font_t *scaled_font,  cairo_matrix_t *scale_matrix);
366 		cairo_scaled_font_get_scale_matrix(cairo_scaled_font, (scaleMatrix is null) ? null : scaleMatrix.getMatrixStruct());
367 	}
368 	
369 	/**
370 	 * This function returns the type of the backend used to create
371 	 * a scaled font. See cairo_font_type_t for available types.
372 	 * However, this function never returns CAIRO_FONT_TYPE_TOY.
373 	 * Since 1.2
374 	 * Returns: The type of scaled_font.
375 	 */
376 	public cairo_font_type_t getType()
377 	{
378 		// cairo_font_type_t cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font);
379 		return cairo_scaled_font_get_type(cairo_scaled_font);
380 	}
381 	
382 	/**
383 	 * Returns the current reference count of scaled_font.
384 	 * Since 1.4
385 	 * Returns: the current reference count of scaled_font. If the object is a nil object, 0 will be returned.
386 	 */
387 	public uint getReferenceCount()
388 	{
389 		// unsigned int cairo_scaled_font_get_reference_count  (cairo_scaled_font_t *scaled_font);
390 		return cairo_scaled_font_get_reference_count(cairo_scaled_font);
391 	}
392 	
393 	/**
394 	 * Attach user data to scaled_font. To remove user data from a surface,
395 	 * call this function with the key that was used to set it and NULL
396 	 * for data.
397 	 * Since 1.4
398 	 * Params:
399 	 * key = the address of a cairo_user_data_key_t to attach the user data to
400 	 * userData = the user data to attach to the cairo_scaled_font_t
401 	 * destroy = a cairo_destroy_func_t which will be called when the
402 	 * cairo_t is destroyed or when new user data is attached using the
403 	 * same key.
404 	 * Returns: CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY if a slot could not be allocated for the user data.
405 	 */
406 	public cairo_status_t setUserData(cairo_user_data_key_t* key, void* userData, cairo_destroy_func_t destroy)
407 	{
408 		// cairo_status_t cairo_scaled_font_set_user_data (cairo_scaled_font_t *scaled_font,  const cairo_user_data_key_t *key,  void *user_data,  cairo_destroy_func_t destroy);
409 		return cairo_scaled_font_set_user_data(cairo_scaled_font, key, userData, destroy);
410 	}
411 	
412 	/**
413 	 * Return user data previously attached to scaled_font using the
414 	 * specified key. If no user data has been attached with the given
415 	 * key this function returns NULL.
416 	 * Since 1.4
417 	 * Params:
418 	 * key = the address of the cairo_user_data_key_t the user data was
419 	 * attached to
420 	 * Returns: the user data previously attached or NULL.
421 	 */
422 	public void* getUserData(cairo_user_data_key_t* key)
423 	{
424 		// void * cairo_scaled_font_get_user_data (cairo_scaled_font_t *scaled_font,  const cairo_user_data_key_t *key);
425 		return cairo_scaled_font_get_user_data(cairo_scaled_font, key);
426 	}
427 }