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 should
96 	 *     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.
127 	 *
128 	 * Return: the scale factor of @matrix on the height of the font,
129 	 *     or 1.0 if @matrix is %NULL.
130 	 *
131 	 * Since: 1.12
132 	 */
133 	public double getFontScaleFactor()
134 	{
135 		return pango_matrix_get_font_scale_factor(pangoMatrix);
136 	}
137 
138 	/**
139 	 * Changes the transformation represented by @matrix to be the
140 	 * transformation given by first rotating by @degrees degrees
141 	 * counter-clockwise then applying the original transformation.
142 	 *
143 	 * Params:
144 	 *     degrees = degrees to rotate counter-clockwise
145 	 *
146 	 * Since: 1.6
147 	 */
148 	public void rotate(double degrees)
149 	{
150 		pango_matrix_rotate(pangoMatrix, degrees);
151 	}
152 
153 	/**
154 	 * Changes the transformation represented by @matrix to be the
155 	 * transformation given by first scaling by @sx in the X direction
156 	 * and @sy in the Y direction then applying the original
157 	 * transformation.
158 	 *
159 	 * Params:
160 	 *     scaleX = amount to scale by in X direction
161 	 *     scaleY = amount to scale by in Y direction
162 	 *
163 	 * Since: 1.6
164 	 */
165 	public void scale(double scaleX, double scaleY)
166 	{
167 		pango_matrix_scale(pangoMatrix, scaleX, scaleY);
168 	}
169 
170 	/**
171 	 * Transforms the distance vector (@dx,@dy) by @matrix. This is
172 	 * similar to pango_matrix_transform_point() except that the translation
173 	 * components of the transformation are ignored. The calculation of
174 	 * the returned vector is as follows:
175 	 *
176 	 * <programlisting>
177 	 * dx2 = dx1 * xx + dy1 * xy;
178 	 * dy2 = dx1 * yx + dy1 * yy;
179 	 * </programlisting>
180 	 *
181 	 * Affine transformations are position invariant, so the same vector
182 	 * always transforms to the same vector. If (@x1,@y1) transforms
183 	 * to (@x2,@y2) then (@x1+@dx1,@y1+@dy1) will transform to
184 	 * (@x1+@dx2,@y1+@dy2) for all values of @x1 and @x2.
185 	 *
186 	 * Params:
187 	 *     dx = in/out X component of a distance vector
188 	 *     dy = in/out Y component of a distance vector
189 	 *
190 	 * Since: 1.16
191 	 */
192 	public void transformDistance(ref double dx, ref double dy)
193 	{
194 		pango_matrix_transform_distance(pangoMatrix, &dx, &dy);
195 	}
196 
197 	/**
198 	 * First transforms the @rect using @matrix, then calculates the bounding box
199 	 * of the transformed rectangle.  The rectangle should be in device units
200 	 * (pixels).
201 	 *
202 	 * This function is useful for example when you want to draw a rotated
203 	 * @PangoLayout to an image buffer, and want to know how large the image
204 	 * should be and how much you should shift the layout when rendering.
205 	 *
206 	 * For better accuracy, you should use pango_matrix_transform_rectangle() on
207 	 * original rectangle in Pango units and convert to pixels afterward
208 	 * using pango_extents_to_pixels()'s first argument.
209 	 *
210 	 * Params:
211 	 *     rect = in/out bounding box in device units, or %NULL
212 	 *
213 	 * Since: 1.16
214 	 */
215 	public void transformPixelRectangle(ref PangoRectangle rect)
216 	{
217 		pango_matrix_transform_pixel_rectangle(pangoMatrix, &rect);
218 	}
219 
220 	/**
221 	 * Transforms the point (@x, @y) by @matrix.
222 	 *
223 	 * Params:
224 	 *     x = in/out X position
225 	 *     y = in/out Y position
226 	 *
227 	 * Since: 1.16
228 	 */
229 	public void transformPoint(ref double x, ref double y)
230 	{
231 		pango_matrix_transform_point(pangoMatrix, &x, &y);
232 	}
233 
234 	/**
235 	 * First transforms @rect using @matrix, then calculates the bounding box
236 	 * of the transformed rectangle.  The rectangle should be in Pango units.
237 	 *
238 	 * This function is useful for example when you want to draw a rotated
239 	 * @PangoLayout to an image buffer, and want to know how large the image
240 	 * should be and how much you should shift the layout when rendering.
241 	 *
242 	 * If you have a rectangle in device units (pixels), use
243 	 * pango_matrix_transform_pixel_rectangle().
244 	 *
245 	 * If you have the rectangle in Pango units and want to convert to
246 	 * transformed pixel bounding box, it is more accurate to transform it first
247 	 * (using this function) and pass the result to pango_extents_to_pixels(),
248 	 * first argument, for an inclusive rounded rectangle.
249 	 * However, there are valid reasons that you may want to convert
250 	 * to pixels first and then transform, for example when the transformed
251 	 * coordinates may overflow in Pango units (large matrix translation for
252 	 * example).
253 	 *
254 	 * Params:
255 	 *     rect = in/out bounding box in Pango units, or %NULL
256 	 *
257 	 * Since: 1.16
258 	 */
259 	public void transformRectangle(ref PangoRectangle rect)
260 	{
261 		pango_matrix_transform_rectangle(pangoMatrix, &rect);
262 	}
263 
264 	/**
265 	 * Changes the transformation represented by @matrix to be the
266 	 * transformation given by first translating by (@tx, @ty)
267 	 * then applying the original transformation.
268 	 *
269 	 * Params:
270 	 *     tx = amount to translate in the X direction
271 	 *     ty = amount to translate in the Y direction
272 	 *
273 	 * Since: 1.6
274 	 */
275 	public void translate(double tx, double ty)
276 	{
277 		pango_matrix_translate(pangoMatrix, tx, ty);
278 	}
279 
280 	/**
281 	 * Converts extents from Pango units to device units, dividing by the
282 	 * %PANGO_SCALE factor and performing rounding.
283 	 *
284 	 * The @inclusive rectangle is converted by flooring the x/y coordinates and extending
285 	 * width/height, such that the final rectangle completely includes the original
286 	 * rectangle.
287 	 *
288 	 * The @nearest rectangle is converted by rounding the coordinates
289 	 * of the rectangle to the nearest device unit (pixel).
290 	 *
291 	 * The rule to which argument to use is: if you want the resulting device-space
292 	 * rectangle to completely contain the original rectangle, pass it in as @inclusive.
293 	 * If you want two touching-but-not-overlapping rectangles stay
294 	 * touching-but-not-overlapping after rounding to device units, pass them in
295 	 * as @nearest.
296 	 *
297 	 * Params:
298 	 *     inclusive = rectangle to round to pixels inclusively, or %NULL.
299 	 *     nearest = rectangle to round to nearest pixels, or %NULL.
300 	 *
301 	 * Since: 1.16
302 	 */
303 	public static void extentsToPixels(PangoRectangle* inclusive, PangoRectangle* nearest)
304 	{
305 		pango_extents_to_pixels(inclusive, nearest);
306 	}
307 
308 	/**
309 	 * Converts a floating-point number to Pango units: multiplies
310 	 * it by %PANGO_SCALE and rounds to nearest integer.
311 	 *
312 	 * Params:
313 	 *     d = double floating-point value
314 	 *
315 	 * Return: the value in Pango units.
316 	 *
317 	 * Since: 1.16
318 	 */
319 	public static int unitsFromDouble(double d)
320 	{
321 		return pango_units_from_double(d);
322 	}
323 
324 	/**
325 	 * Converts a number in Pango units to floating-point: divides
326 	 * it by %PANGO_SCALE.
327 	 *
328 	 * Params:
329 	 *     i = value in Pango units
330 	 *
331 	 * Return: the double value.
332 	 *
333 	 * Since: 1.16
334 	 */
335 	public static double unitsToDouble(int i)
336 	{
337 		return pango_units_to_double(i);
338 	}
339 }