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