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.PgGlyphItem;
26 
27 private import glib.ListSG;
28 private import glib.MemorySlice;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 public  import gtkc.pangotypes;
32 private import gtkd.Loader;
33 private import pango.PgAttributeList;
34 private import pango.PgGlyphString;
35 private import pango.PgItem;
36 private import pango.c.functions;
37 public  import pango.c.types;
38 
39 
40 /**
41  * A #PangoGlyphItem is a pair of a #PangoItem and the glyphs
42  * resulting from shaping the text corresponding to an item.
43  * As an example of the usage of #PangoGlyphItem, the results
44  * of shaping text with #PangoLayout is a list of #PangoLayoutLine,
45  * each of which contains a list of #PangoGlyphItem.
46  */
47 public final class PgGlyphItem
48 {
49 	/** the main Gtk struct */
50 	protected PangoGlyphItem* pangoGlyphItem;
51 	protected bool ownedRef;
52 
53 	/** Get the main Gtk struct */
54 	public PangoGlyphItem* getPgGlyphItemStruct(bool transferOwnership = false)
55 	{
56 		if (transferOwnership)
57 			ownedRef = false;
58 		return pangoGlyphItem;
59 	}
60 
61 	/** the main Gtk struct as a void* */
62 	protected void* getStruct()
63 	{
64 		return cast(void*)pangoGlyphItem;
65 	}
66 
67 	/**
68 	 * Sets our main struct and passes it to the parent class.
69 	 */
70 	public this (PangoGlyphItem* pangoGlyphItem, bool ownedRef = false)
71 	{
72 		this.pangoGlyphItem = pangoGlyphItem;
73 		this.ownedRef = ownedRef;
74 	}
75 
76 	~this ()
77 	{
78 		if ( Linker.isLoaded(LIBRARY_PANGO) && ownedRef )
79 			pango_glyph_item_free(pangoGlyphItem);
80 	}
81 
82 
83 	/**
84 	 * corresponding #PangoItem.
85 	 */
86 	public @property PgItem item()
87 	{
88 		return ObjectG.getDObject!(PgItem)(pangoGlyphItem.item, false);
89 	}
90 
91 	/** Ditto */
92 	public @property void item(PgItem value)
93 	{
94 		pangoGlyphItem.item = value.getPgItemStruct();
95 	}
96 
97 	/**
98 	 * corresponding #PangoGlyphString.
99 	 */
100 	public @property PgGlyphString glyphs()
101 	{
102 		return ObjectG.getDObject!(PgGlyphString)(pangoGlyphItem.glyphs, false);
103 	}
104 
105 	/** Ditto */
106 	public @property void glyphs(PgGlyphString value)
107 	{
108 		pangoGlyphItem.glyphs = value.getPgGlyphStringStruct();
109 	}
110 
111 	/** */
112 	public static GType getType()
113 	{
114 		return pango_glyph_item_get_type();
115 	}
116 
117 	/**
118 	 * Splits a shaped item (PangoGlyphItem) into multiple items based
119 	 * on an attribute list. The idea is that if you have attributes
120 	 * that don't affect shaping, such as color or underline, to avoid
121 	 * affecting shaping, you filter them out (pango_attr_list_filter()),
122 	 * apply the shaping process and then reapply them to the result using
123 	 * this function.
124 	 *
125 	 * All attributes that start or end inside a cluster are applied
126 	 * to that cluster; for instance, if half of a cluster is underlined
127 	 * and the other-half strikethrough, then the cluster will end
128 	 * up with both underline and strikethrough attributes. In these
129 	 * cases, it may happen that item->extra_attrs for some of the
130 	 * result items can have multiple attributes of the same type.
131 	 *
132 	 * This function takes ownership of @glyph_item; it will be reused
133 	 * as one of the elements in the list.
134 	 *
135 	 * Params:
136 	 *     text = text that @list applies to
137 	 *     list = a #PangoAttrList
138 	 *
139 	 * Returns: a
140 	 *     list of glyph items resulting from splitting @glyph_item. Free
141 	 *     the elements using pango_glyph_item_free(), the list using
142 	 *     g_slist_free().
143 	 *
144 	 * Since: 1.2
145 	 */
146 	public ListSG applyAttrs(string text, PgAttributeList list)
147 	{
148 		auto p = pango_glyph_item_apply_attrs(pangoGlyphItem, Str.toStringz(text), (list is null) ? null : list.getPgAttributeListStruct());
149 
150 		if(p is null)
151 		{
152 			return null;
153 		}
154 
155 		return new ListSG(cast(GSList*) p, true);
156 	}
157 
158 	/**
159 	 * Make a deep copy of an existing #PangoGlyphItem structure.
160 	 *
161 	 * Returns: the newly allocated #PangoGlyphItem, which should
162 	 *     be freed with pango_glyph_item_free(), or %NULL
163 	 *     if @orig was %NULL.
164 	 *
165 	 * Since: 1.20
166 	 */
167 	public PgGlyphItem copy()
168 	{
169 		auto p = pango_glyph_item_copy(pangoGlyphItem);
170 
171 		if(p is null)
172 		{
173 			return null;
174 		}
175 
176 		return ObjectG.getDObject!(PgGlyphItem)(cast(PangoGlyphItem*) p, true);
177 	}
178 
179 	/**
180 	 * Frees a #PangoGlyphItem and resources to which it points.
181 	 *
182 	 * Since: 1.6
183 	 */
184 	public void free()
185 	{
186 		pango_glyph_item_free(pangoGlyphItem);
187 		ownedRef = false;
188 	}
189 
190 	/**
191 	 * Given a #PangoGlyphItem and the corresponding
192 	 * text, determine the screen width corresponding to each character. When
193 	 * multiple characters compose a single cluster, the width of the entire
194 	 * cluster is divided equally among the characters.
195 	 *
196 	 * See also pango_glyph_string_get_logical_widths().
197 	 *
198 	 * Params:
199 	 *     text = text that @glyph_item corresponds to
200 	 *         (glyph_item->item->offset is an offset from the
201 	 *         start of @text)
202 	 *     logicalWidths = an array whose length is the number of
203 	 *         characters in glyph_item (equal to
204 	 *         glyph_item->item->num_chars) to be filled in with
205 	 *         the resulting character widths.
206 	 *
207 	 * Since: 1.26
208 	 */
209 	public void getLogicalWidths(string text, int[] logicalWidths)
210 	{
211 		pango_glyph_item_get_logical_widths(pangoGlyphItem, Str.toStringz(text), logicalWidths.ptr);
212 	}
213 
214 	/**
215 	 * Adds spacing between the graphemes of @glyph_item to
216 	 * give the effect of typographic letter spacing.
217 	 *
218 	 * Params:
219 	 *     text = text that @glyph_item corresponds to
220 	 *         (glyph_item->item->offset is an offset from the
221 	 *         start of @text)
222 	 *     logAttrs = logical attributes for the item
223 	 *         (the first logical attribute refers to the position
224 	 *         before the first character in the item)
225 	 *     letterSpacing = amount of letter spacing to add
226 	 *         in Pango units. May be negative, though too large
227 	 *         negative values will give ugly results.
228 	 *
229 	 * Since: 1.6
230 	 */
231 	public void letterSpace(string text, PangoLogAttr[] logAttrs, int letterSpacing)
232 	{
233 		pango_glyph_item_letter_space(pangoGlyphItem, Str.toStringz(text), logAttrs.ptr, letterSpacing);
234 	}
235 
236 	/**
237 	 * Modifies @orig to cover only the text after @split_index, and
238 	 * returns a new item that covers the text before @split_index that
239 	 * used to be in @orig. You can think of @split_index as the length of
240 	 * the returned item. @split_index may not be 0, and it may not be
241 	 * greater than or equal to the length of @orig (that is, there must
242 	 * be at least one byte assigned to each item, you can't create a
243 	 * zero-length item).
244 	 *
245 	 * This function is similar in function to pango_item_split() (and uses
246 	 * it internally.)
247 	 *
248 	 * Params:
249 	 *     text = text to which positions in @orig apply
250 	 *     splitIndex = byte index of position to split item, relative to the start of the item
251 	 *
252 	 * Returns: the newly allocated item representing text before
253 	 *     @split_index, which should be freed
254 	 *     with pango_glyph_item_free().
255 	 *
256 	 * Since: 1.2
257 	 */
258 	public PgGlyphItem split(string text, int splitIndex)
259 	{
260 		auto p = pango_glyph_item_split(pangoGlyphItem, Str.toStringz(text), splitIndex);
261 
262 		if(p is null)
263 		{
264 			return null;
265 		}
266 
267 		return ObjectG.getDObject!(PgGlyphItem)(cast(PangoGlyphItem*) p, true);
268 	}
269 }