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 public  import gtkc.pangotypes;
29 private import pango.PgCoverage;
30 private import pango.PgEngineShape;
31 private import pango.PgFontDescription;
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  * The #PangoFont structure is used to represent
41  * a font in a rendering-system-independent matter.
42  * To create an implementation of a #PangoFont,
43  * the rendering-system specific code should allocate
44  * a larger structure that contains a nested
45  * #PangoFont, fill in the <structfield>klass</structfield> member of
46  * the nested #PangoFont with a pointer to
47  * a appropriate #PangoFontClass, then call
48  * pango_font_init() on the structure.
49  * 
50  * The #PangoFont structure contains one member
51  * which the implementation fills in.
52  */
53 public class PgFont : ObjectG
54 {
55 	/** the main Gtk struct */
56 	protected PangoFont* pangoFont;
57 
58 	/** Get the main Gtk struct */
59 	public PangoFont* getPgFontStruct(bool transferOwnership = false)
60 	{
61 		if (transferOwnership)
62 			ownedRef = false;
63 		return pangoFont;
64 	}
65 
66 	/** the main Gtk struct as a void* */
67 	protected override void* getStruct()
68 	{
69 		return cast(void*)pangoFont;
70 	}
71 
72 	protected override void setStruct(GObject* obj)
73 	{
74 		pangoFont = cast(PangoFont*)obj;
75 		super.setStruct(obj);
76 	}
77 
78 	/**
79 	 * Sets our main struct and passes it to the parent class.
80 	 */
81 	public this (PangoFont* pangoFont, bool ownedRef = false)
82 	{
83 		this.pangoFont = pangoFont;
84 		super(cast(GObject*)pangoFont, ownedRef);
85 	}
86 
87 
88 	/** */
89 	public static GType getType()
90 	{
91 		return pango_font_get_type();
92 	}
93 
94 	/**
95 	 * Frees an array of font descriptions.
96 	 *
97 	 * Params:
98 	 *     descs = a pointer
99 	 *         to an array of #PangoFontDescription, may be %NULL
100 	 */
101 	public static void descriptionsFree(PgFontDescription[] descs)
102 	{
103 		PangoFontDescription*[] descsArray = new PangoFontDescription*[descs.length];
104 		for ( int i = 0; i < descs.length; i++ )
105 		{
106 			descsArray[i] = descs[i].getPgFontDescriptionStruct();
107 		}
108 
109 		pango_font_descriptions_free(descsArray.ptr, cast(int)descs.length);
110 	}
111 
112 	/**
113 	 * Returns a description of the font, with font size set in points.
114 	 * Use pango_font_describe_with_absolute_size() if you want the font
115 	 * size in device units.
116 	 *
117 	 * Returns: a newly-allocated #PangoFontDescription object.
118 	 */
119 	public PgFontDescription describe()
120 	{
121 		auto p = pango_font_describe(pangoFont);
122 
123 		if(p is null)
124 		{
125 			return null;
126 		}
127 
128 		return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) p, true);
129 	}
130 
131 	/**
132 	 * Returns a description of the font, with absolute font size set
133 	 * (in device units). Use pango_font_describe() if you want the font
134 	 * size in points.
135 	 *
136 	 * Returns: a newly-allocated #PangoFontDescription object.
137 	 *
138 	 * Since: 1.14
139 	 */
140 	public PgFontDescription describeWithAbsoluteSize()
141 	{
142 		auto p = pango_font_describe_with_absolute_size(pangoFont);
143 
144 		if(p is null)
145 		{
146 			return null;
147 		}
148 
149 		return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) p, true);
150 	}
151 
152 	/**
153 	 * Finds the best matching shaper for a font for a particular
154 	 * language tag and character point.
155 	 *
156 	 * Params:
157 	 *     language = the language tag
158 	 *     ch = a Unicode character.
159 	 *
160 	 * Returns: the best matching shaper.
161 	 */
162 	public PgEngineShape findShaper(PgLanguage language, uint ch)
163 	{
164 		auto p = pango_font_find_shaper(pangoFont, (language is null) ? null : language.getPgLanguageStruct(), ch);
165 
166 		if(p is null)
167 		{
168 			return null;
169 		}
170 
171 		return ObjectG.getDObject!(PgEngineShape)(cast(PangoEngineShape*) p);
172 	}
173 
174 	/**
175 	 * Computes the coverage map for a given font and language tag.
176 	 *
177 	 * Params:
178 	 *     language = the language tag
179 	 *
180 	 * Returns: a newly-allocated #PangoCoverage
181 	 *     object.
182 	 */
183 	public PgCoverage getCoverage(PgLanguage language)
184 	{
185 		auto p = pango_font_get_coverage(pangoFont, (language is null) ? null : language.getPgLanguageStruct());
186 
187 		if(p is null)
188 		{
189 			return null;
190 		}
191 
192 		return ObjectG.getDObject!(PgCoverage)(cast(PangoCoverage*) p, true);
193 	}
194 
195 	/**
196 	 * Gets the font map for which the font was created.
197 	 *
198 	 * Note that the font maintains a <firstterm>weak</firstterm> reference
199 	 * to the font map, so if all references to font map are dropped, the font
200 	 * map will be finalized even if there are fonts created with the font
201 	 * map that are still alive.  In that case this function will return %NULL.
202 	 * It is the responsibility of the user to ensure that the font map is kept
203 	 * alive.  In most uses this is not an issue as a #PangoContext holds
204 	 * a reference to the font map.
205 	 *
206 	 * Returns: the #PangoFontMap for the
207 	 *     font, or %NULL if @font is %NULL.
208 	 *
209 	 * Since: 1.10
210 	 */
211 	public PgFontMap getFontMap()
212 	{
213 		auto p = pango_font_get_font_map(pangoFont);
214 
215 		if(p is null)
216 		{
217 			return null;
218 		}
219 
220 		return ObjectG.getDObject!(PgFontMap)(cast(PangoFontMap*) p);
221 	}
222 
223 	/**
224 	 * Gets the logical and ink extents of a glyph within a font. The
225 	 * coordinate system for each rectangle has its origin at the
226 	 * base line and horizontal origin of the character with increasing
227 	 * coordinates extending to the right and down. The macros PANGO_ASCENT(),
228 	 * PANGO_DESCENT(), PANGO_LBEARING(), and PANGO_RBEARING() can be used to convert
229 	 * from the extents rectangle to more traditional font metrics. The units
230 	 * of the rectangles are in 1/PANGO_SCALE of a device unit.
231 	 *
232 	 * If @font is %NULL, this function gracefully sets some sane values in the
233 	 * output variables and returns.
234 	 *
235 	 * Params:
236 	 *     glyph = the glyph index
237 	 *     inkRect = rectangle used to store the extents of the glyph
238 	 *         as drawn or %NULL to indicate that the result is not needed.
239 	 *     logicalRect = rectangle used to store the logical extents of
240 	 *         the glyph or %NULL to indicate that the result is not needed.
241 	 */
242 	public void getGlyphExtents(PangoGlyph glyph, out PangoRectangle inkRect, out PangoRectangle logicalRect)
243 	{
244 		pango_font_get_glyph_extents(pangoFont, glyph, &inkRect, &logicalRect);
245 	}
246 
247 	/**
248 	 * Gets overall metric information for a font. Since the metrics may be
249 	 * substantially different for different scripts, a language tag can
250 	 * be provided to indicate that the metrics should be retrieved that
251 	 * correspond to the script(s) used by that language.
252 	 *
253 	 * If @font is %NULL, this function gracefully sets some sane values in the
254 	 * output variables and returns.
255 	 *
256 	 * Params:
257 	 *     language = language tag used to determine which script to get the metrics
258 	 *         for, or %NULL to indicate to get the metrics for the entire font.
259 	 *
260 	 * Returns: a #PangoFontMetrics object. The caller must call pango_font_metrics_unref()
261 	 *     when finished using the object.
262 	 */
263 	public PgFontMetrics getMetrics(PgLanguage language)
264 	{
265 		auto p = pango_font_get_metrics(pangoFont, (language is null) ? null : language.getPgLanguageStruct());
266 
267 		if(p is null)
268 		{
269 			return null;
270 		}
271 
272 		return ObjectG.getDObject!(PgFontMetrics)(cast(PangoFontMetrics*) p, true);
273 	}
274 }