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