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