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 * cairo_scaled_font_t represents a realization of a font face at a particular 78 * size and transformation and a certain set of font options. 79 */ 80 public class ScaledFont 81 { 82 83 /** the main Gtk struct */ 84 protected cairo_scaled_font_t* cairo_scaled_font; 85 86 87 public cairo_scaled_font_t* getScaledFontStruct() 88 { 89 return cairo_scaled_font; 90 } 91 92 93 /** the main Gtk struct as a void* */ 94 protected void* getStruct() 95 { 96 return cast(void*)cairo_scaled_font; 97 } 98 99 /** 100 * Sets our main struct and passes it to the parent class 101 */ 102 public this (cairo_scaled_font_t* cairo_scaled_font) 103 { 104 this.cairo_scaled_font = cairo_scaled_font; 105 } 106 107 /** 108 */ 109 110 /** 111 * Creates a cairo_scaled_font_t object from a font face and matrices that 112 * describe the size of the font and the environment in which it will 113 * be used. 114 * Since 1.0 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 * Since 1.0 148 * Returns: the referenced cairo_scaled_font_t 149 */ 150 public ScaledFont reference() 151 { 152 // cairo_scaled_font_t * cairo_scaled_font_reference (cairo_scaled_font_t *scaled_font); 153 auto p = cairo_scaled_font_reference(cairo_scaled_font); 154 155 if(p is null) 156 { 157 return null; 158 } 159 160 return new ScaledFont(cast(cairo_scaled_font_t*) p); 161 } 162 163 /** 164 * Decreases the reference count on font by one. If the result 165 * is zero, then font and all associated resources are freed. 166 * See cairo_scaled_font_reference(). 167 * Since 1.0 168 */ 169 public void destroy() 170 { 171 // void cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font); 172 cairo_scaled_font_destroy(cairo_scaled_font); 173 } 174 175 /** 176 * Checks whether an error has previously occurred for this 177 * scaled_font. 178 * Since 1.0 179 * Returns: CAIRO_STATUS_SUCCESS or another error such as CAIRO_STATUS_NO_MEMORY. 180 */ 181 public cairo_status_t status() 182 { 183 // cairo_status_t cairo_scaled_font_status (cairo_scaled_font_t *scaled_font); 184 return cairo_scaled_font_status(cairo_scaled_font); 185 } 186 187 /** 188 * Gets the metrics for a cairo_scaled_font_t. 189 * Since 1.0 190 * Params: 191 * extents = a cairo_font_extents_t which to store the retrieved extents. 192 */ 193 public void extents(cairo_font_extents_t* extents) 194 { 195 // void cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font, cairo_font_extents_t *extents); 196 cairo_scaled_font_extents(cairo_scaled_font, extents); 197 } 198 199 /** 200 * Gets the extents for a string of text. The extents describe a 201 * user-space rectangle that encloses the "inked" portion of the text 202 * drawn at the origin (0,0) (as it would be drawn by cairo_show_text() 203 * if the cairo graphics state were set to the same font_face, 204 * font_matrix, ctm, and font_options as scaled_font). Additionally, 205 * the x_advance and y_advance values indicate the amount by which the 206 * current point would be advanced by cairo_show_text(). 207 * Note that whitespace characters do not directly contribute to the 208 * size of the rectangle (extents.width and extents.height). They do 209 * contribute indirectly by changing the position of non-whitespace 210 * characters. In particular, trailing whitespace characters are 211 * likely to not affect the size of the rectangle, though they will 212 * affect the x_advance and y_advance values. 213 * Since 1.2 214 * Params: 215 * utf8 = a NUL-terminated string of text, encoded in UTF-8 216 * extents = a cairo_text_extents_t which to store the retrieved extents. 217 */ 218 public void textExtents(string utf8, cairo_text_extents_t* extents) 219 { 220 // void cairo_scaled_font_text_extents (cairo_scaled_font_t *scaled_font, const char *utf8, cairo_text_extents_t *extents); 221 cairo_scaled_font_text_extents(cairo_scaled_font, Str.toStringz(utf8), extents); 222 } 223 224 /** 225 * Gets the extents for an array of glyphs. The extents describe a 226 * user-space rectangle that encloses the "inked" portion of the 227 * glyphs, (as they would be drawn by cairo_show_glyphs() if the cairo 228 * graphics state were set to the same font_face, font_matrix, ctm, 229 * and font_options as scaled_font). Additionally, the x_advance and 230 * y_advance values indicate the amount by which the current point 231 * would be advanced by cairo_show_glyphs(). 232 * Note that whitespace glyphs do not contribute to the size of the 233 * rectangle (extents.width and extents.height). 234 * Since 1.0 235 * Params: 236 * glyphs = an array of glyph IDs with X and Y offsets. 237 * numGlyphs = the number of glyphs in the glyphs array 238 * extents = a cairo_text_extents_t which to store the retrieved extents. 239 */ 240 public void glyphExtents(cairo_glyph_t* glyphs, int numGlyphs, cairo_text_extents_t* extents) 241 { 242 // 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); 243 cairo_scaled_font_glyph_extents(cairo_scaled_font, glyphs, numGlyphs, extents); 244 } 245 246 /** 247 * Converts UTF-8 text to an array of glyphs, optionally with cluster 248 * mapping, that can be used to render later using scaled_font. 249 * If glyphs initially points to a non-NULL value, that array is used 250 * as a glyph buffer, and num_glyphs should point to the number of glyph 251 * entries available there. If the provided glyph array is too short for 252 * the conversion, a new glyph array is allocated using cairo_glyph_allocate() 253 * and placed in glyphs. Upon return, num_glyphs always contains the 254 * number of generated glyphs. If the value glyphs points to has changed 255 * after the call, the user is responsible for freeing the allocated glyph 256 * array using cairo_glyph_free(). This may happen even if the provided 257 * array was large enough. 258 * If clusters is not NULL, num_clusters and cluster_flags should not be NULL, 259 * and cluster mapping will be computed. 260 * The semantics of how cluster array allocation works is similar to the glyph 261 * array. That is, 262 * if clusters initially points to a non-NULL value, that array is used 263 * as a cluster buffer, and num_clusters should point to the number of cluster 264 * entries available there. If the provided cluster array is too short for 265 * the conversion, a new cluster array is allocated using cairo_text_cluster_allocate() 266 * and placed in clusters. Upon return, num_clusters always contains the 267 * number of generated clusters. If the value clusters points at has changed 268 * after the call, the user is responsible for freeing the allocated cluster 269 * array using cairo_text_cluster_free(). This may happen even if the provided 270 * array was large enough. 271 * In the simplest case, glyphs and clusters can point to NULL initially 272 * Since 1.8 273 * Params: 274 * x = X position to place first glyph 275 * y = Y position to place first glyph 276 * utf8 = a string of text encoded in UTF-8 277 * utf8_Len = length of utf8 in bytes, or -1 if it is NUL-terminated 278 * glyphs = pointer to array of glyphs to fill 279 * clusters = pointer to array of cluster mapping information to fill, or NULL 280 * clusterFlags = pointer to location to store cluster flags corresponding to the 281 * output clusters, or NULL 282 * 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. 283 */ 284 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) 285 { 286 // 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); 287 cairo_glyph_t* outglyphs = null; 288 int numGlyphs; 289 cairo_text_cluster_t* outclusters = null; 290 int numClusters; 291 292 auto p = cairo_scaled_font_text_to_glyphs(cairo_scaled_font, x, y, Str.toStringz(utf8), utf8_Len, &outglyphs, &numGlyphs, &outclusters, &numClusters, &clusterFlags); 293 294 glyphs = outglyphs[0 .. numGlyphs]; 295 clusters = outclusters[0 .. numClusters]; 296 return p; 297 } 298 299 /** 300 * Gets the font face that this scaled font uses. This might be the 301 * font face passed to cairo_scaled_font_create(), but this does not 302 * hold true for all possible cases. 303 * Since 1.2 304 * Returns: The cairo_font_face_t with which scaled_font was created. 305 */ 306 public FontFace getFontFace() 307 { 308 // cairo_font_face_t * cairo_scaled_font_get_font_face (cairo_scaled_font_t *scaled_font); 309 auto p = cairo_scaled_font_get_font_face(cairo_scaled_font); 310 311 if(p is null) 312 { 313 return null; 314 } 315 316 return new FontFace(cast(cairo_font_face_t*) p); 317 } 318 319 /** 320 * Stores the font options with which scaled_font was created into 321 * options. 322 * Since 1.2 323 * Params: 324 * options = return value for the font options 325 */ 326 public void getFontOptions(FontOption options) 327 { 328 // void cairo_scaled_font_get_font_options (cairo_scaled_font_t *scaled_font, cairo_font_options_t *options); 329 cairo_scaled_font_get_font_options(cairo_scaled_font, (options is null) ? null : options.getFontOptionStruct()); 330 } 331 332 /** 333 * Stores the font matrix with which scaled_font was created into 334 * matrix. 335 * Since 1.2 336 * Params: 337 * fontMatrix = return value for the matrix 338 */ 339 public void getFontMatrix(Matrix fontMatrix) 340 { 341 // void cairo_scaled_font_get_font_matrix (cairo_scaled_font_t *scaled_font, cairo_matrix_t *font_matrix); 342 cairo_scaled_font_get_font_matrix(cairo_scaled_font, (fontMatrix is null) ? null : fontMatrix.getMatrixStruct()); 343 } 344 345 /** 346 * Stores the CTM with which scaled_font was created into ctm. 347 * Note that the translation offsets (x0, y0) of the CTM are ignored 348 * by cairo_scaled_font_create(). So, the matrix this 349 * function returns always has 0,0 as x0,y0. 350 * Since 1.2 351 * Params: 352 * ctm = return value for the CTM 353 */ 354 public void getCtm(Matrix ctm) 355 { 356 // void cairo_scaled_font_get_ctm (cairo_scaled_font_t *scaled_font, cairo_matrix_t *ctm); 357 cairo_scaled_font_get_ctm(cairo_scaled_font, (ctm is null) ? null : ctm.getMatrixStruct()); 358 } 359 360 /** 361 * Stores the scale matrix of scaled_font into matrix. 362 * The scale matrix is product of the font matrix and the ctm 363 * associated with the scaled font, and hence is the matrix mapping from 364 * font space to device space. 365 * Since 1.8 366 * Params: 367 * scaleMatrix = return value for the matrix 368 */ 369 public void getScaleMatrix(Matrix scaleMatrix) 370 { 371 // void cairo_scaled_font_get_scale_matrix (cairo_scaled_font_t *scaled_font, cairo_matrix_t *scale_matrix); 372 cairo_scaled_font_get_scale_matrix(cairo_scaled_font, (scaleMatrix is null) ? null : scaleMatrix.getMatrixStruct()); 373 } 374 375 /** 376 * This function returns the type of the backend used to create 377 * a scaled font. See cairo_font_type_t for available types. 378 * However, this function never returns CAIRO_FONT_TYPE_TOY. 379 * Since 1.2 380 * Returns: The type of scaled_font. 381 */ 382 public cairo_font_type_t getType() 383 { 384 // cairo_font_type_t cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font); 385 return cairo_scaled_font_get_type(cairo_scaled_font); 386 } 387 388 /** 389 * Returns the current reference count of scaled_font. 390 * Since 1.4 391 * Returns: the current reference count of scaled_font. If the object is a nil object, 0 will be returned. 392 */ 393 public uint getReferenceCount() 394 { 395 // unsigned int cairo_scaled_font_get_reference_count (cairo_scaled_font_t *scaled_font); 396 return cairo_scaled_font_get_reference_count(cairo_scaled_font); 397 } 398 399 /** 400 * Attach user data to scaled_font. To remove user data from a surface, 401 * call this function with the key that was used to set it and NULL 402 * for data. 403 * Since 1.4 404 * Params: 405 * key = the address of a cairo_user_data_key_t to attach the user data to 406 * userData = the user data to attach to the cairo_scaled_font_t 407 * destroy = a cairo_destroy_func_t which will be called when the 408 * cairo_t is destroyed or when new user data is attached using the 409 * same key. 410 * Returns: CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY if a slot could not be allocated for the user data. 411 */ 412 public cairo_status_t setUserData(cairo_user_data_key_t* key, void* userData, cairo_destroy_func_t destroy) 413 { 414 // 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); 415 return cairo_scaled_font_set_user_data(cairo_scaled_font, key, userData, destroy); 416 } 417 418 /** 419 * Return user data previously attached to scaled_font using the 420 * specified key. If no user data has been attached with the given 421 * key this function returns NULL. 422 * Since 1.4 423 * Params: 424 * key = the address of the cairo_user_data_key_t the user data was 425 * attached to 426 * Returns: the user data previously attached or NULL. 427 */ 428 public void* getUserData(cairo_user_data_key_t* key) 429 { 430 // void * cairo_scaled_font_get_user_data (cairo_scaled_font_t *scaled_font, const cairo_user_data_key_t *key); 431 return cairo_scaled_font_get_user_data(cairo_scaled_font, key); 432 } 433 }