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.PgGlyphString; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gtkc.pango; 31 public import gtkc.pangotypes; 32 private import pango.PgFont; 33 34 35 /** 36 * The #PangoGlyphString structure is used to store strings 37 * of glyphs with geometry and visual attribute information. 38 * The storage for the glyph information is owned 39 * by the structure which simplifies memory management. 40 */ 41 public class PgGlyphString 42 { 43 /** the main Gtk struct */ 44 protected PangoGlyphString* pangoGlyphString; 45 46 /** Get the main Gtk struct */ 47 public PangoGlyphString* getPgGlyphStringStruct() 48 { 49 return pangoGlyphString; 50 } 51 52 /** the main Gtk struct as a void* */ 53 protected void* getStruct() 54 { 55 return cast(void*)pangoGlyphString; 56 } 57 58 /** 59 * Sets our main struct and passes it to the parent class. 60 */ 61 public this (PangoGlyphString* pangoGlyphString) 62 { 63 this.pangoGlyphString = pangoGlyphString; 64 } 65 66 /** 67 */ 68 69 public static GType getType() 70 { 71 return pango_glyph_string_get_type(); 72 } 73 74 /** 75 * Create a new #PangoGlyphString. 76 * 77 * Return: the newly allocated #PangoGlyphString, which 78 * should be freed with pango_glyph_string_free(). 79 * 80 * Throws: ConstructionException GTK+ fails to create the object. 81 */ 82 public this() 83 { 84 auto p = pango_glyph_string_new(); 85 86 if(p is null) 87 { 88 throw new ConstructionException("null returned by new"); 89 } 90 91 this(cast(PangoGlyphString*) p); 92 } 93 94 /** 95 * Copy a glyph string and associated storage. 96 * 97 * Return: the newly allocated #PangoGlyphString, which 98 * should be freed with pango_glyph_string_free(), 99 * or %NULL if @string was %NULL. 100 */ 101 public PgGlyphString copy() 102 { 103 auto p = pango_glyph_string_copy(pangoGlyphString); 104 105 if(p is null) 106 { 107 return null; 108 } 109 110 return ObjectG.getDObject!(PgGlyphString)(cast(PangoGlyphString*) p); 111 } 112 113 /** 114 * Compute the logical and ink extents of a glyph string. See the documentation 115 * for pango_font_get_glyph_extents() for details about the interpretation 116 * of the rectangles. 117 * 118 * Params: 119 * font = a #PangoFont 120 * inkRect = rectangle used to store the extents of the glyph string 121 * as drawn or %NULL to indicate that the result is not needed. 122 * logicalRect = rectangle used to store the logical extents of the 123 * glyph string or %NULL to indicate that the result is not needed. 124 */ 125 public void extents(PgFont font, out PangoRectangle inkRect, out PangoRectangle logicalRect) 126 { 127 pango_glyph_string_extents(pangoGlyphString, (font is null) ? null : font.getPgFontStruct(), &inkRect, &logicalRect); 128 } 129 130 /** 131 * Computes the extents of a sub-portion of a glyph string. The extents are 132 * relative to the start of the glyph string range (the origin of their 133 * coordinate system is at the start of the range, not at the start of the entire 134 * glyph string). 135 * 136 * Params: 137 * start = start index 138 * end = end index (the range is the set of bytes with 139 * indices such that start <= index < end) 140 * font = a #PangoFont 141 * inkRect = rectangle used to store the 142 * extents of the glyph string range as drawn or %NULL to 143 * indicate that the result is not needed. 144 * logicalRect = rectangle used to store the 145 * logical extents of the glyph string range or %NULL to 146 * indicate that the result is not needed. 147 */ 148 public void extentsRange(int start, int end, PgFont font, out PangoRectangle inkRect, out PangoRectangle logicalRect) 149 { 150 pango_glyph_string_extents_range(pangoGlyphString, start, end, (font is null) ? null : font.getPgFontStruct(), &inkRect, &logicalRect); 151 } 152 153 /** 154 * Free a glyph string and associated storage. 155 */ 156 public void free() 157 { 158 pango_glyph_string_free(pangoGlyphString); 159 } 160 161 /** 162 * Given a #PangoGlyphString resulting from pango_shape() and the corresponding 163 * text, determine the screen width corresponding to each character. When 164 * multiple characters compose a single cluster, the width of the entire 165 * cluster is divided equally among the characters. 166 * 167 * See also pango_glyph_item_get_logical_widths(). 168 * 169 * Params: 170 * text = the text corresponding to the glyphs 171 * length = the length of @text, in bytes 172 * embeddingLevel = the embedding level of the string 173 * logicalWidths = an array whose length is the number of 174 * characters in text (equal to g_utf8_strlen (text, 175 * length) unless text has NUL bytes) to be filled in 176 * with the resulting character widths. 177 */ 178 public void getLogicalWidths(string text, int length, int embeddingLevel, int[] logicalWidths) 179 { 180 pango_glyph_string_get_logical_widths(pangoGlyphString, Str.toStringz(text), length, embeddingLevel, logicalWidths.ptr); 181 } 182 183 /** 184 * Computes the logical width of the glyph string as can also be computed 185 * using pango_glyph_string_extents(). However, since this only computes the 186 * width, it's much faster. This is in fact only a convenience function that 187 * computes the sum of geometry.width for each glyph in the @glyphs. 188 * 189 * Return: the logical width of the glyph string. 190 * 191 * Since: 1.14 192 */ 193 public int getWidth() 194 { 195 return pango_glyph_string_get_width(pangoGlyphString); 196 } 197 198 /** 199 * Converts from character position to x position. (X position 200 * is measured from the left edge of the run). Character positions 201 * are computed by dividing up each cluster into equal portions. 202 * 203 * Params: 204 * text = the text for the run 205 * length = the number of bytes (not characters) in @text. 206 * analysis = the analysis information return from pango_itemize() 207 * index = the byte index within @text 208 * trailing = whether we should compute the result for the beginning (%FALSE) 209 * or end (%TRUE) of the character. 210 * xPos = location to store result 211 */ 212 public void indexToX(string text, int length, PangoAnalysis* analysis, int index, bool trailing, out int xPos) 213 { 214 pango_glyph_string_index_to_x(pangoGlyphString, Str.toStringz(text), length, analysis, index, trailing, &xPos); 215 } 216 217 /** 218 * Resize a glyph string to the given length. 219 * 220 * Params: 221 * newLen = the new length of the string. 222 */ 223 public void setSize(int newLen) 224 { 225 pango_glyph_string_set_size(pangoGlyphString, newLen); 226 } 227 228 /** 229 * Convert from x offset to character position. Character positions 230 * are computed by dividing up each cluster into equal portions. 231 * In scripts where positioning within a cluster is not allowed 232 * (such as Thai), the returned value may not be a valid cursor 233 * position; the caller must combine the result with the logical 234 * attributes for the text to compute the valid cursor position. 235 * 236 * Params: 237 * text = the text for the run 238 * length = the number of bytes (not characters) in text. 239 * analysis = the analysis information return from pango_itemize() 240 * xPos = the x offset (in Pango units) 241 * index = location to store calculated byte index within @text 242 * trailing = location to store a boolean indicating 243 * whether the user clicked on the leading or trailing 244 * edge of the character. 245 */ 246 public void xToIndex(string text, int length, PangoAnalysis* analysis, int xPos, out int index, out int trailing) 247 { 248 pango_glyph_string_x_to_index(pangoGlyphString, Str.toStringz(text), length, analysis, xPos, &index, &trailing); 249 } 250 }