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.PgMatrix;
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  * A structure specifying a transformation between user-space
35  * coordinates and device coordinates. The transformation
36  * is given by
37  * 
38  * <programlisting>
39  * x_device = x_user * matrix->xx + y_user * matrix->xy + matrix->x0;
40  * y_device = x_user * matrix->yx + y_user * matrix->yy + matrix->y0;
41  * </programlisting>
42  *
43  * Since: 1.6
44  */
45 public class PgMatrix
46 {
47 	/** the main Gtk struct */
48 	protected PangoMatrix* pangoMatrix;
49 	protected bool ownedRef;
50 
51 	/** Get the main Gtk struct */
52 	public PangoMatrix* getPgMatrixStruct(bool transferOwnership = false)
53 	{
54 		if (transferOwnership)
55 			ownedRef = false;
56 		return pangoMatrix;
57 	}
58 
59 	/** the main Gtk struct as a void* */
60 	protected void* getStruct()
61 	{
62 		return cast(void*)pangoMatrix;
63 	}
64 
65 	/**
66 	 * Sets our main struct and passes it to the parent class.
67 	 */
68 	public this (PangoMatrix* pangoMatrix, bool ownedRef = false)
69 	{
70 		this.pangoMatrix = pangoMatrix;
71 		this.ownedRef = ownedRef;
72 	}
73 
74 	~this ()
75 	{
76 		if (  Linker.isLoaded(LIBRARY_PANGO) && ownedRef )
77 			pango_matrix_free(pangoMatrix);
78 	}
79 
80 
81 	/** */
82 	public static GType getType()
83 	{
84 		return pango_matrix_get_type();
85 	}
86 
87 	/**
88 	 * Changes the transformation represented by @matrix to be the
89 	 * transformation given by first applying transformation
90 	 * given by @new_matrix then applying the original transformation.
91 	 *
92 	 * Params:
93 	 *     newMatrix = a #PangoMatrix
94 	 *
95 	 * Since: 1.6
96 	 */
97 	public void concat(PgMatrix newMatrix)
98 	{
99 		pango_matrix_concat(pangoMatrix, (newMatrix is null) ? null : newMatrix.getPgMatrixStruct());
100 	}
101 
102 	/**
103 	 * Copies a #PangoMatrix.
104 	 *
105 	 * Returns: the newly allocated #PangoMatrix, which
106 	 *     should be freed with pango_matrix_free(), or %NULL if
107 	 *     @matrix was %NULL.
108 	 *
109 	 * Since: 1.6
110 	 */
111 	public PgMatrix copy()
112 	{
113 		auto p = pango_matrix_copy(pangoMatrix);
114 		
115 		if(p is null)
116 		{
117 			return null;
118 		}
119 		
120 		return ObjectG.getDObject!(PgMatrix)(cast(PangoMatrix*) p, true);
121 	}
122 
123 	/**
124 	 * Free a #PangoMatrix created with pango_matrix_copy().
125 	 *
126 	 * Since: 1.6
127 	 */
128 	public void free()
129 	{
130 		pango_matrix_free(pangoMatrix);
131 		ownedRef = false;
132 	}
133 
134 	/**
135 	 * Returns the scale factor of a matrix on the height of the font.
136 	 * That is, the scale factor in the direction perpendicular to the
137 	 * vector that the X coordinate is mapped to.  If the scale in the X
138 	 * coordinate is needed as well, use pango_matrix_get_font_scale_factors().
139 	 *
140 	 * Returns: the scale factor of @matrix on the height of the font,
141 	 *     or 1.0 if @matrix is %NULL.
142 	 *
143 	 * Since: 1.12
144 	 */
145 	public double getFontScaleFactor()
146 	{
147 		return pango_matrix_get_font_scale_factor(pangoMatrix);
148 	}
149 
150 	/**
151 	 * Calculates the scale factor of a matrix on the width and height of the font.
152 	 * That is, @xscale is the scale factor in the direction of the X coordinate,
153 	 * and @yscale is the scale factor in the direction perpendicular to the
154 	 * vector that the X coordinate is mapped to.
155 	 *
156 	 * Note that output numbers will always be non-negative.
157 	 *
158 	 * Params:
159 	 *     xscale = output scale factor in the x direction, or %NULL
160 	 *     yscale = output scale factor perpendicular to the x direction, or %NULL
161 	 *
162 	 * Since: 1.38
163 	 */
164 	public void getFontScaleFactors(out double xscale, out double yscale)
165 	{
166 		pango_matrix_get_font_scale_factors(pangoMatrix, &xscale, &yscale);
167 	}
168 
169 	/**
170 	 * Changes the transformation represented by @matrix to be the
171 	 * transformation given by first rotating by @degrees degrees
172 	 * counter-clockwise then applying the original transformation.
173 	 *
174 	 * Params:
175 	 *     degrees = degrees to rotate counter-clockwise
176 	 *
177 	 * Since: 1.6
178 	 */
179 	public void rotate(double degrees)
180 	{
181 		pango_matrix_rotate(pangoMatrix, degrees);
182 	}
183 
184 	/**
185 	 * Changes the transformation represented by @matrix to be the
186 	 * transformation given by first scaling by @sx in the X direction
187 	 * and @sy in the Y direction then applying the original
188 	 * transformation.
189 	 *
190 	 * Params:
191 	 *     scaleX = amount to scale by in X direction
192 	 *     scaleY = amount to scale by in Y direction
193 	 *
194 	 * Since: 1.6
195 	 */
196 	public void scale(double scaleX, double scaleY)
197 	{
198 		pango_matrix_scale(pangoMatrix, scaleX, scaleY);
199 	}
200 
201 	/**
202 	 * Transforms the distance vector (@dx,@dy) by @matrix. This is
203 	 * similar to pango_matrix_transform_point() except that the translation
204 	 * components of the transformation are ignored. The calculation of
205 	 * the returned vector is as follows:
206 	 *
207 	 * <programlisting>
208 	 * dx2 = dx1 * xx + dy1 * xy;
209 	 * dy2 = dx1 * yx + dy1 * yy;
210 	 * </programlisting>
211 	 *
212 	 * Affine transformations are position invariant, so the same vector
213 	 * always transforms to the same vector. If (@x1,@y1) transforms
214 	 * to (@x2,@y2) then (@x1+@dx1,@y1+@dy1) will transform to
215 	 * (@x1+@dx2,@y1+@dy2) for all values of @x1 and @x2.
216 	 *
217 	 * Params:
218 	 *     dx = in/out X component of a distance vector
219 	 *     dy = in/out Y component of a distance vector
220 	 *
221 	 * Since: 1.16
222 	 */
223 	public void transformDistance(ref double dx, ref double dy)
224 	{
225 		pango_matrix_transform_distance(pangoMatrix, &dx, &dy);
226 	}
227 
228 	/**
229 	 * First transforms the @rect using @matrix, then calculates the bounding box
230 	 * of the transformed rectangle.  The rectangle should be in device units
231 	 * (pixels).
232 	 *
233 	 * This function is useful for example when you want to draw a rotated
234 	 * @PangoLayout to an image buffer, and want to know how large the image
235 	 * should be and how much you should shift the layout when rendering.
236 	 *
237 	 * For better accuracy, you should use pango_matrix_transform_rectangle() on
238 	 * original rectangle in Pango units and convert to pixels afterward
239 	 * using pango_extents_to_pixels()'s first argument.
240 	 *
241 	 * Params:
242 	 *     rect = in/out bounding box in device units, or %NULL
243 	 *
244 	 * Since: 1.16
245 	 */
246 	public void transformPixelRectangle(ref PangoRectangle rect)
247 	{
248 		pango_matrix_transform_pixel_rectangle(pangoMatrix, &rect);
249 	}
250 
251 	/**
252 	 * Transforms the point (@x, @y) by @matrix.
253 	 *
254 	 * Params:
255 	 *     x = in/out X position
256 	 *     y = in/out Y position
257 	 *
258 	 * Since: 1.16
259 	 */
260 	public void transformPoint(ref double x, ref double y)
261 	{
262 		pango_matrix_transform_point(pangoMatrix, &x, &y);
263 	}
264 
265 	/**
266 	 * First transforms @rect using @matrix, then calculates the bounding box
267 	 * of the transformed rectangle.  The rectangle should be in Pango units.
268 	 *
269 	 * This function is useful for example when you want to draw a rotated
270 	 * @PangoLayout to an image buffer, and want to know how large the image
271 	 * should be and how much you should shift the layout when rendering.
272 	 *
273 	 * If you have a rectangle in device units (pixels), use
274 	 * pango_matrix_transform_pixel_rectangle().
275 	 *
276 	 * If you have the rectangle in Pango units and want to convert to
277 	 * transformed pixel bounding box, it is more accurate to transform it first
278 	 * (using this function) and pass the result to pango_extents_to_pixels(),
279 	 * first argument, for an inclusive rounded rectangle.
280 	 * However, there are valid reasons that you may want to convert
281 	 * to pixels first and then transform, for example when the transformed
282 	 * coordinates may overflow in Pango units (large matrix translation for
283 	 * example).
284 	 *
285 	 * Params:
286 	 *     rect = in/out bounding box in Pango units, or %NULL
287 	 *
288 	 * Since: 1.16
289 	 */
290 	public void transformRectangle(ref PangoRectangle rect)
291 	{
292 		pango_matrix_transform_rectangle(pangoMatrix, &rect);
293 	}
294 
295 	/**
296 	 * Changes the transformation represented by @matrix to be the
297 	 * transformation given by first translating by (@tx, @ty)
298 	 * then applying the original transformation.
299 	 *
300 	 * Params:
301 	 *     tx = amount to translate in the X direction
302 	 *     ty = amount to translate in the Y direction
303 	 *
304 	 * Since: 1.6
305 	 */
306 	public void translate(double tx, double ty)
307 	{
308 		pango_matrix_translate(pangoMatrix, tx, ty);
309 	}
310 
311 	/**
312 	 * Converts extents from Pango units to device units, dividing by the
313 	 * %PANGO_SCALE factor and performing rounding.
314 	 *
315 	 * The @inclusive rectangle is converted by flooring the x/y coordinates and extending
316 	 * width/height, such that the final rectangle completely includes the original
317 	 * rectangle.
318 	 *
319 	 * The @nearest rectangle is converted by rounding the coordinates
320 	 * of the rectangle to the nearest device unit (pixel).
321 	 *
322 	 * The rule to which argument to use is: if you want the resulting device-space
323 	 * rectangle to completely contain the original rectangle, pass it in as @inclusive.
324 	 * If you want two touching-but-not-overlapping rectangles stay
325 	 * touching-but-not-overlapping after rounding to device units, pass them in
326 	 * as @nearest.
327 	 *
328 	 * Params:
329 	 *     inclusive = rectangle to round to pixels inclusively, or %NULL.
330 	 *     nearest = rectangle to round to nearest pixels, or %NULL.
331 	 *
332 	 * Since: 1.16
333 	 */
334 	public static void extentsToPixels(PangoRectangle* inclusive, PangoRectangle* nearest)
335 	{
336 		pango_extents_to_pixels(inclusive, nearest);
337 	}
338 
339 	/**
340 	 * Converts a floating-point number to Pango units: multiplies
341 	 * it by %PANGO_SCALE and rounds to nearest integer.
342 	 *
343 	 * Params:
344 	 *     d = double floating-point value
345 	 *
346 	 * Returns: the value in Pango units.
347 	 *
348 	 * Since: 1.16
349 	 */
350 	public static int unitsFromDouble(double d)
351 	{
352 		return pango_units_from_double(d);
353 	}
354 
355 	/**
356 	 * Converts a number in Pango units to floating-point: divides
357 	 * it by %PANGO_SCALE.
358 	 *
359 	 * Params:
360 	 *     i = value in Pango units
361 	 *
362 	 * Returns: the double value.
363 	 *
364 	 * Since: 1.16
365 	 */
366 	public static double unitsToDouble(int i)
367 	{
368 		return pango_units_to_double(i);
369 	}
370 }