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