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