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