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.PgLayoutLine; 26 27 private import gobject.ObjectG; 28 private import gtkc.pango; 29 public import gtkc.pangotypes; 30 private import gtkd.Loader; 31 32 33 /** 34 * The #PangoLayoutLine structure represents one of the lines resulting 35 * from laying out a paragraph via #PangoLayout. #PangoLayoutLine 36 * structures are obtained by calling pango_layout_get_line() and 37 * are only valid until the text, attributes, or settings of the 38 * parent #PangoLayout are modified. 39 * 40 * Routines for rendering PangoLayout objects are provided in 41 * code specific to each rendering system. 42 */ 43 public class PgLayoutLine 44 { 45 /** the main Gtk struct */ 46 protected PangoLayoutLine* pangoLayoutLine; 47 protected bool ownedRef; 48 49 /** Get the main Gtk struct */ 50 public PangoLayoutLine* getPgLayoutLineStruct(bool transferOwnership = false) 51 { 52 if (transferOwnership) 53 ownedRef = false; 54 return pangoLayoutLine; 55 } 56 57 /** the main Gtk struct as a void* */ 58 protected void* getStruct() 59 { 60 return cast(void*)pangoLayoutLine; 61 } 62 63 /** 64 * Sets our main struct and passes it to the parent class. 65 */ 66 public this (PangoLayoutLine* pangoLayoutLine, bool ownedRef = false) 67 { 68 this.pangoLayoutLine = pangoLayoutLine; 69 this.ownedRef = ownedRef; 70 } 71 72 ~this () 73 { 74 if ( Linker.isLoaded(LIBRARY_PANGO) && ownedRef ) 75 pango_layout_line_unref(pangoLayoutLine); 76 } 77 78 79 /** */ 80 public static GType getType() 81 { 82 return pango_layout_line_get_type(); 83 } 84 85 /** 86 * Computes the logical and ink extents of a layout line. See 87 * pango_font_get_glyph_extents() for details about the interpretation 88 * of the rectangles. 89 * 90 * Params: 91 * inkRect = rectangle used to store the extents of 92 * the glyph string as drawn, or %NULL 93 * logicalRect = rectangle used to store the logical 94 * extents of the glyph string, or %NULL 95 */ 96 public void getExtents(out PangoRectangle inkRect, out PangoRectangle logicalRect) 97 { 98 pango_layout_line_get_extents(pangoLayoutLine, &inkRect, &logicalRect); 99 } 100 101 /** 102 * Computes the logical and ink extents of @layout_line in device units. 103 * This function just calls pango_layout_line_get_extents() followed by 104 * two pango_extents_to_pixels() calls, rounding @ink_rect and @logical_rect 105 * such that the rounded rectangles fully contain the unrounded one (that is, 106 * passes them as first argument to pango_extents_to_pixels()). 107 * 108 * Params: 109 * inkRect = rectangle used to store the extents of 110 * the glyph string as drawn, or %NULL 111 * logicalRect = rectangle used to store the logical 112 * extents of the glyph string, or %NULL 113 */ 114 public void getPixelExtents(out PangoRectangle inkRect, out PangoRectangle logicalRect) 115 { 116 pango_layout_line_get_pixel_extents(pangoLayoutLine, &inkRect, &logicalRect); 117 } 118 119 /** 120 * Gets a list of visual ranges corresponding to a given logical range. 121 * This list is not necessarily minimal - there may be consecutive 122 * ranges which are adjacent. The ranges will be sorted from left to 123 * right. The ranges are with respect to the left edge of the entire 124 * layout, not with respect to the line. 125 * 126 * Params: 127 * startIndex = Start byte index of the logical range. If this value 128 * is less than the start index for the line, then 129 * the first range will extend all the way to the leading 130 * edge of the layout. Otherwise it will start at the 131 * leading edge of the first character. 132 * endIndex = Ending byte index of the logical range. If this value 133 * is greater than the end index for the line, then 134 * the last range will extend all the way to the trailing 135 * edge of the layout. Otherwise, it will end at the 136 * trailing edge of the last character. 137 * ranges = location to store a pointer to an array of ranges. 138 * The array will be of length <literal>2*n_ranges</literal>, 139 * with each range starting at <literal>(*ranges)[2*n]</literal> 140 * and of width <literal>(*ranges)[2*n + 1] - (*ranges)[2*n]</literal>. 141 * This array must be freed with g_free(). The coordinates are relative 142 * to the layout and are in Pango units. 143 * nRanges = The number of ranges stored in @ranges. 144 */ 145 public void getXRanges(int startIndex, int endIndex, out int[] ranges) 146 { 147 int* outranges = null; 148 int nRanges; 149 150 pango_layout_line_get_x_ranges(pangoLayoutLine, startIndex, endIndex, &outranges, &nRanges); 151 152 ranges = outranges[0 .. nRanges]; 153 } 154 155 /** 156 * Converts an index within a line to a X position. 157 * 158 * Params: 159 * index = byte offset of a grapheme within the layout 160 * trailing = an integer indicating the edge of the grapheme to retrieve 161 * the position of. If > 0, the trailing edge of the grapheme, 162 * if 0, the leading of the grapheme. 163 * xPos = location to store the x_offset (in Pango unit) 164 */ 165 public void indexToX(int index, bool trailing, out int xPos) 166 { 167 pango_layout_line_index_to_x(pangoLayoutLine, index, trailing, &xPos); 168 } 169 170 /** 171 * Increase the reference count of a #PangoLayoutLine by one. 172 * 173 * Returns: the line passed in. 174 * 175 * Since: 1.10 176 */ 177 public PgLayoutLine doref() 178 { 179 auto p = pango_layout_line_ref(pangoLayoutLine); 180 181 if(p is null) 182 { 183 return null; 184 } 185 186 return ObjectG.getDObject!(PgLayoutLine)(cast(PangoLayoutLine*) p, true); 187 } 188 189 /** 190 * Decrease the reference count of a #PangoLayoutLine by one. 191 * If the result is zero, the line and all associated memory 192 * will be freed. 193 */ 194 public void unref() 195 { 196 pango_layout_line_unref(pangoLayoutLine); 197 } 198 199 /** 200 * Converts from x offset to the byte index of the corresponding 201 * character within the text of the layout. If @x_pos is outside the line, 202 * @index_ and @trailing will point to the very first or very last position 203 * in the line. This determination is based on the resolved direction 204 * of the paragraph; for example, if the resolved direction is 205 * right-to-left, then an X position to the right of the line (after it) 206 * results in 0 being stored in @index_ and @trailing. An X position to the 207 * left of the line results in @index_ pointing to the (logical) last 208 * grapheme in the line and @trailing being set to the number of characters 209 * in that grapheme. The reverse is true for a left-to-right line. 210 * 211 * Params: 212 * xPos = the X offset (in Pango units) 213 * from the left edge of the line. 214 * index = location to store calculated byte index for 215 * the grapheme in which the user clicked. 216 * trailing = location to store an integer indicating where 217 * in the grapheme the user clicked. It will either 218 * be zero, or the number of characters in the 219 * grapheme. 0 represents the leading edge of the grapheme. 220 * 221 * Returns: %FALSE if @x_pos was outside the line, %TRUE if inside 222 */ 223 public bool xToIndex(int xPos, out int index, out int trailing) 224 { 225 return pango_layout_line_x_to_index(pangoLayoutLine, xPos, &index, &trailing) != 0; 226 } 227 }