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 module pango.PgFont; 26 27 private import gobject.ObjectG; 28 private import harfbuzz.feature_t; 29 private import pango.PgCoverage; 30 private import pango.PgFontDescription; 31 private import pango.PgFontFace; 32 private import pango.PgFontMap; 33 private import pango.PgFontMetrics; 34 private import pango.PgLanguage; 35 private import pango.c.functions; 36 public import pango.c.types; 37 38 39 /** 40 * A `PangoFont` is used to represent a font in a 41 * rendering-system-independent manner. 42 */ 43 public class PgFont : ObjectG 44 { 45 /** the main Gtk struct */ 46 protected PangoFont* pangoFont; 47 48 /** Get the main Gtk struct */ 49 public PangoFont* getPgFontStruct(bool transferOwnership = false) 50 { 51 if (transferOwnership) 52 ownedRef = false; 53 return pangoFont; 54 } 55 56 /** the main Gtk struct as a void* */ 57 protected override void* getStruct() 58 { 59 return cast(void*)pangoFont; 60 } 61 62 /** 63 * Sets our main struct and passes it to the parent class. 64 */ 65 public this (PangoFont* pangoFont, bool ownedRef = false) 66 { 67 this.pangoFont = pangoFont; 68 super(cast(GObject*)pangoFont, ownedRef); 69 } 70 71 72 /** */ 73 public static GType getType() 74 { 75 return pango_font_get_type(); 76 } 77 78 /** 79 * Frees an array of font descriptions. 80 * 81 * Params: 82 * descs = a pointer 83 * to an array of `PangoFontDescription`, may be %NULL 84 */ 85 public static void descriptionsFree(PgFontDescription[] descs) 86 { 87 PangoFontDescription*[] descsArray = new PangoFontDescription*[descs.length]; 88 for ( int i = 0; i < descs.length; i++ ) 89 { 90 descsArray[i] = descs[i].getPgFontDescriptionStruct(); 91 } 92 93 pango_font_descriptions_free(descsArray.ptr, cast(int)descs.length); 94 } 95 96 /** 97 * Returns a description of the font, with font size set in points. 98 * 99 * Use [method@Pango.Font.describe_with_absolute_size] if you want 100 * the font size in device units. 101 * 102 * Returns: a newly-allocated `PangoFontDescription` object. 103 */ 104 public PgFontDescription describe() 105 { 106 auto __p = pango_font_describe(pangoFont); 107 108 if(__p is null) 109 { 110 return null; 111 } 112 113 return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) __p, true); 114 } 115 116 /** 117 * Returns a description of the font, with absolute font size set 118 * in device units. 119 * 120 * Use [method@Pango.Font.describe] if you want the font size in points. 121 * 122 * Returns: a newly-allocated `PangoFontDescription` object. 123 * 124 * Since: 1.14 125 */ 126 public PgFontDescription describeWithAbsoluteSize() 127 { 128 auto __p = pango_font_describe_with_absolute_size(pangoFont); 129 130 if(__p is null) 131 { 132 return null; 133 } 134 135 return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) __p, true); 136 } 137 138 /** 139 * Computes the coverage map for a given font and language tag. 140 * 141 * Params: 142 * language = the language tag 143 * 144 * Returns: a newly-allocated `PangoCoverage` 145 * object. 146 */ 147 public PgCoverage getCoverage(PgLanguage language) 148 { 149 auto __p = pango_font_get_coverage(pangoFont, (language is null) ? null : language.getPgLanguageStruct()); 150 151 if(__p is null) 152 { 153 return null; 154 } 155 156 return ObjectG.getDObject!(PgCoverage)(cast(PangoCoverage*) __p, true); 157 } 158 159 /** 160 * Gets the `PangoFontFace` to which @font belongs. 161 * 162 * Returns: the `PangoFontFace` 163 * 164 * Since: 1.46 165 */ 166 public PgFontFace getFace() 167 { 168 auto __p = pango_font_get_face(pangoFont); 169 170 if(__p is null) 171 { 172 return null; 173 } 174 175 return ObjectG.getDObject!(PgFontFace)(cast(PangoFontFace*) __p); 176 } 177 178 /** 179 * Obtain the OpenType features that are provided by the font. 180 * 181 * These are passed to the rendering system, together with features 182 * that have been explicitly set via attributes. 183 * 184 * Note that this does not include OpenType features which the 185 * rendering system enables by default. 186 * 187 * Params: 188 * features = Array to features in 189 * numFeatures = the number of used items in @features 190 * 191 * Since: 1.44 192 */ 193 public void getFeatures(out feature_t[] features, ref uint numFeatures) 194 { 195 hb_feature_t* outfeatures = null; 196 197 pango_font_get_features(pangoFont, outfeatures, cast(uint)features.length, &numFeatures); 198 199 features = new feature_t[cast(uint)features.length]; 200 for(size_t i = 0; i < cast(uint)features.length; i++) 201 { 202 features[i] = ObjectG.getDObject!(feature_t)(cast(hb_feature_t*) &outfeatures[i]); 203 } 204 } 205 206 /** 207 * Gets the font map for which the font was created. 208 * 209 * Note that the font maintains a *weak* reference to the font map, so if 210 * all references to font map are dropped, the font map will be finalized 211 * even if there are fonts created with the font map that are still alive. 212 * In that case this function will return %NULL. 213 * 214 * It is the responsibility of the user to ensure that the font map is kept 215 * alive. In most uses this is not an issue as a #PangoContext holds 216 * a reference to the font map. 217 * 218 * Returns: the `PangoFontMap` for the 219 * font, or %NULL if @font is %NULL. 220 * 221 * Since: 1.10 222 */ 223 public PgFontMap getFontMap() 224 { 225 auto __p = pango_font_get_font_map(pangoFont); 226 227 if(__p is null) 228 { 229 return null; 230 } 231 232 return ObjectG.getDObject!(PgFontMap)(cast(PangoFontMap*) __p); 233 } 234 235 /** 236 * Gets the logical and ink extents of a glyph within a font. 237 * 238 * The coordinate system for each rectangle has its origin at the 239 * base line and horizontal origin of the character with increasing 240 * coordinates extending to the right and down. The macros PANGO_ASCENT(), 241 * PANGO_DESCENT(), PANGO_LBEARING(), and PANGO_RBEARING() can be used to convert 242 * from the extents rectangle to more traditional font metrics. The units 243 * of the rectangles are in 1/PANGO_SCALE of a device unit. 244 * 245 * If @font is %NULL, this function gracefully sets some sane values in the 246 * output variables and returns. 247 * 248 * Params: 249 * glyph = the glyph index 250 * inkRect = rectangle used to store the extents of the glyph 251 * as drawn or %NULL to indicate that the result is not needed. 252 * logicalRect = rectangle used to store the logical extents of 253 * the glyph or %NULL to indicate that the result is not needed. 254 */ 255 public void getGlyphExtents(PangoGlyph glyph, out PangoRectangle inkRect, out PangoRectangle logicalRect) 256 { 257 pango_font_get_glyph_extents(pangoFont, glyph, &inkRect, &logicalRect); 258 } 259 260 /** 261 * Get a `hb_font_t` object backing this font. 262 * 263 * Note that the objects returned by this function are cached and immutable. 264 * If you need to make changes to the `hb_font_t`, use hb_font_create_sub_font(). 265 * 266 * Returns: the `hb_font_t` object backing the 267 * font, or %NULL if the font does not have one 268 * 269 * Since: 1.44 270 */ 271 public hb_font_t* getHbFont() 272 { 273 return pango_font_get_hb_font(pangoFont); 274 } 275 276 /** 277 * Gets overall metric information for a font. 278 * 279 * Since the metrics may be substantially different for different scripts, 280 * a language tag can be provided to indicate that the metrics should be 281 * retrieved that correspond to the script(s) used by that language. 282 * 283 * If @font is %NULL, this function gracefully sets some sane values in the 284 * output variables and returns. 285 * 286 * Params: 287 * language = language tag used to determine which script 288 * to get the metrics for, or %NULL to indicate to get the metrics for 289 * the entire font. 290 * 291 * Returns: a `PangoFontMetrics` object. The caller must call 292 * [method@Pango.FontMetrics.unref] when finished using the object. 293 */ 294 public PgFontMetrics getMetrics(PgLanguage language) 295 { 296 auto __p = pango_font_get_metrics(pangoFont, (language is null) ? null : language.getPgLanguageStruct()); 297 298 if(__p is null) 299 { 300 return null; 301 } 302 303 return ObjectG.getDObject!(PgFontMetrics)(cast(PangoFontMetrics*) __p, true); 304 } 305 306 /** 307 * Returns whether the font provides a glyph for this character. 308 * 309 * Returns %TRUE if @font can render @wc 310 * 311 * Params: 312 * wc = a Unicode character 313 * 314 * Since: 1.44 315 */ 316 public bool hasChar(dchar wc) 317 { 318 return pango_font_has_char(pangoFont, wc) != 0; 319 } 320 }