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.MemorySlice;
28 private import gobject.ObjectG;
29 private import gtkd.Loader;
30 private import pango.c.functions;
31 public  import pango.c.types;
32 
33 
34 /**
35  * A `PangoMatrix` specifies a transformation between user-space
36  * and device coordinates.
37  * 
38  * The transformation is given by
39  * 
40  * ```
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  * ```
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 [method@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`.
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 	 *
223 	 * That is, the scale factor in the direction perpendicular to the
224 	 * vector that the X coordinate is mapped to.  If the scale in the X
225 	 * coordinate is needed as well, use [method@Pango.Matrix.get_font_scale_factors].
226 	 *
227 	 * Returns: the scale factor of @matrix on the height of the font,
228 	 *     or 1.0 if @matrix is %NULL.
229 	 *
230 	 * Since: 1.12
231 	 */
232 	public double getFontScaleFactor()
233 	{
234 		return pango_matrix_get_font_scale_factor(pangoMatrix);
235 	}
236 
237 	/**
238 	 * Calculates the scale factor of a matrix on the width and height of the font.
239 	 *
240 	 * That is, @xscale is the scale factor in the direction of the X coordinate,
241 	 * and @yscale is the scale factor in the direction perpendicular to the
242 	 * vector that the X coordinate is mapped to.
243 	 *
244 	 * Note that output numbers will always be non-negative.
245 	 *
246 	 * Params:
247 	 *     xscale = output scale factor in the x direction, or %NULL
248 	 *     yscale = output scale factor perpendicular to the x direction, or %NULL
249 	 *
250 	 * Since: 1.38
251 	 */
252 	public void getFontScaleFactors(out double xscale, out double yscale)
253 	{
254 		pango_matrix_get_font_scale_factors(pangoMatrix, &xscale, &yscale);
255 	}
256 
257 	/**
258 	 * Changes the transformation represented by @matrix to be the
259 	 * transformation given by first rotating by @degrees degrees
260 	 * counter-clockwise then applying the original transformation.
261 	 *
262 	 * Params:
263 	 *     degrees = degrees to rotate counter-clockwise
264 	 *
265 	 * Since: 1.6
266 	 */
267 	public void rotate(double degrees)
268 	{
269 		pango_matrix_rotate(pangoMatrix, degrees);
270 	}
271 
272 	/**
273 	 * Changes the transformation represented by @matrix to be the
274 	 * transformation given by first scaling by @sx in the X direction
275 	 * and @sy in the Y direction then applying the original
276 	 * transformation.
277 	 *
278 	 * Params:
279 	 *     scaleX = amount to scale by in X direction
280 	 *     scaleY = amount to scale by in Y direction
281 	 *
282 	 * Since: 1.6
283 	 */
284 	public void scale(double scaleX, double scaleY)
285 	{
286 		pango_matrix_scale(pangoMatrix, scaleX, scaleY);
287 	}
288 
289 	/**
290 	 * Transforms the distance vector (@dx,@dy) by @matrix.
291 	 *
292 	 * This is similar to [method@Pango.Matrix.transform_point],
293 	 * except that the translation components of the transformation
294 	 * are ignored. The calculation of the returned vector is as follows:
295 	 *
296 	 * ```
297 	 * dx2 = dx1 * xx + dy1 * xy;
298 	 * dy2 = dx1 * yx + dy1 * yy;
299 	 * ```
300 	 *
301 	 * Affine transformations are position invariant, so the same vector
302 	 * always transforms to the same vector. If (@x1,@y1) transforms
303 	 * to (@x2,@y2) then (@x1+@dx1,@y1+@dy1) will transform to
304 	 * (@x1+@dx2,@y1+@dy2) for all values of @x1 and @x2.
305 	 *
306 	 * Params:
307 	 *     dx = in/out X component of a distance vector
308 	 *     dy = in/out Y component of a distance vector
309 	 *
310 	 * Since: 1.16
311 	 */
312 	public void transformDistance(ref double dx, ref double dy)
313 	{
314 		pango_matrix_transform_distance(pangoMatrix, &dx, &dy);
315 	}
316 
317 	/**
318 	 * First transforms the @rect using @matrix, then calculates the bounding box
319 	 * of the transformed rectangle.
320 	 *
321 	 * This function is useful for example when you want to draw a rotated
322 	 * @PangoLayout to an image buffer, and want to know how large the image
323 	 * should be and how much you should shift the layout when rendering.
324 	 *
325 	 * For better accuracy, you should use [method@Pango.Matrix.transform_rectangle]
326 	 * on original rectangle in Pango units and convert to pixels afterward
327 	 * using [func@extents_to_pixels]'s first argument.
328 	 *
329 	 * Params:
330 	 *     rect = in/out bounding box in device units, or %NULL
331 	 *
332 	 * Since: 1.16
333 	 */
334 	public void transformPixelRectangle(ref PangoRectangle rect)
335 	{
336 		pango_matrix_transform_pixel_rectangle(pangoMatrix, &rect);
337 	}
338 
339 	/**
340 	 * Transforms the point (@x, @y) by @matrix.
341 	 *
342 	 * Params:
343 	 *     x = in/out X position
344 	 *     y = in/out Y position
345 	 *
346 	 * Since: 1.16
347 	 */
348 	public void transformPoint(ref double x, ref double y)
349 	{
350 		pango_matrix_transform_point(pangoMatrix, &x, &y);
351 	}
352 
353 	/**
354 	 * First transforms @rect using @matrix, then calculates the bounding box
355 	 * of the transformed rectangle.
356 	 *
357 	 * This function is useful for example when you want to draw a rotated
358 	 * @PangoLayout to an image buffer, and want to know how large the image
359 	 * should be and how much you should shift the layout when rendering.
360 	 *
361 	 * If you have a rectangle in device units (pixels), use
362 	 * [method@Pango.Matrix.transform_pixel_rectangle].
363 	 *
364 	 * If you have the rectangle in Pango units and want to convert to
365 	 * transformed pixel bounding box, it is more accurate to transform it first
366 	 * (using this function) and pass the result to pango_extents_to_pixels(),
367 	 * first argument, for an inclusive rounded rectangle.
368 	 * However, there are valid reasons that you may want to convert
369 	 * to pixels first and then transform, for example when the transformed
370 	 * coordinates may overflow in Pango units (large matrix translation for
371 	 * example).
372 	 *
373 	 * Params:
374 	 *     rect = in/out bounding box in Pango units, or %NULL
375 	 *
376 	 * Since: 1.16
377 	 */
378 	public void transformRectangle(ref PangoRectangle rect)
379 	{
380 		pango_matrix_transform_rectangle(pangoMatrix, &rect);
381 	}
382 
383 	/**
384 	 * Changes the transformation represented by @matrix to be the
385 	 * transformation given by first translating by (@tx, @ty)
386 	 * then applying the original transformation.
387 	 *
388 	 * Params:
389 	 *     tx = amount to translate in the X direction
390 	 *     ty = amount to translate in the Y direction
391 	 *
392 	 * Since: 1.6
393 	 */
394 	public void translate(double tx, double ty)
395 	{
396 		pango_matrix_translate(pangoMatrix, tx, ty);
397 	}
398 
399 	/**
400 	 * Converts extents from Pango units to device units.
401 	 *
402 	 * The conversion is done by dividing by the %PANGO_SCALE factor and
403 	 * performing rounding.
404 	 *
405 	 * The @inclusive rectangle is converted by flooring the x/y coordinates
406 	 * and extending width/height, such that the final rectangle completely
407 	 * includes the original rectangle.
408 	 *
409 	 * The @nearest rectangle is converted by rounding the coordinates
410 	 * of the rectangle to the nearest device unit (pixel).
411 	 *
412 	 * The rule to which argument to use is: if you want the resulting device-space
413 	 * rectangle to completely contain the original rectangle, pass it in as
414 	 * @inclusive. If you want two touching-but-not-overlapping rectangles stay
415 	 * touching-but-not-overlapping after rounding to device units, pass them in
416 	 * as @nearest.
417 	 *
418 	 * Params:
419 	 *     inclusive = rectangle to round to pixels inclusively, or %NULL.
420 	 *     nearest = rectangle to round to nearest pixels, or %NULL.
421 	 *
422 	 * Since: 1.16
423 	 */
424 	public static void extentsToPixels(PangoRectangle* inclusive, PangoRectangle* nearest)
425 	{
426 		pango_extents_to_pixels(inclusive, nearest);
427 	}
428 
429 	/**
430 	 * Converts a floating-point number to Pango units.
431 	 *
432 	 * The conversion is done by multiplying @d by %PANGO_SCALE and
433 	 * rounding the result to nearest integer.
434 	 *
435 	 * Params:
436 	 *     d = double floating-point value
437 	 *
438 	 * Returns: the value in Pango units.
439 	 *
440 	 * Since: 1.16
441 	 */
442 	public static int unitsFromDouble(double d)
443 	{
444 		return pango_units_from_double(d);
445 	}
446 
447 	/**
448 	 * Converts a number in Pango units to floating-point.
449 	 *
450 	 * The conversion is done by dividing @i by %PANGO_SCALE.
451 	 *
452 	 * Params:
453 	 *     i = value in Pango units
454 	 *
455 	 * Returns: the double value.
456 	 *
457 	 * Since: 1.16
458 	 */
459 	public static double unitsToDouble(int i)
460 	{
461 		return pango_units_to_double(i);
462 	}
463 }