Class Matrix
- All Implemented Interfaces:
Proxy
PangoMatrix
specifies a transformation between user-space
and device coordinates.
The transformation is given by
x_device = x_user * matrix->xx + y_user * matrix->xy + matrix->x0;
y_device = x_user * matrix->yx + y_user * matrix->yy + matrix->y0;
-
Constructor Summary
ConstructorDescriptionMatrix()
Allocate a new Matrix.Matrix
(double xx, double xy, double yx, double yy, double x0, double y0) Allocate a new Matrix with the fields set to the provided values.Allocate a new Matrix with the fields set to the provided values.Allocate a new Matrix.Matrix
(MemorySegment address) Create a Matrix proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Changes the transformation represented by this Matrix to be the transformation given by first applying transformation given bynewMatrix
then applying the original transformation.copy()
Copies aPangoMatrix
.void
free()
Free aPangoMatrix
.double
Returns the scale factor of a matrix on the height of the font.void
getFontScaleFactors
(@Nullable Out<Double> xscale, @Nullable Out<Double> yscale) Calculates the scale factor of a matrix on the width and height of the font.static MemoryLayout
The memory layout of the native struct.double
Gets the slant ratio of a matrix.static Type
getType()
Get the GType of the Matrix classdouble
readX0()
Read the value of the fieldx0
.double
readXx()
Read the value of the fieldxx
.double
readXy()
Read the value of the fieldxy
.double
readY0()
Read the value of the fieldy0
.double
readYx()
Read the value of the fieldyx
.double
readYy()
Read the value of the fieldyy
.void
rotate
(double degrees) Changes the transformation represented by this Matrix to be the transformation given by first rotating bydegrees
degrees counter-clockwise then applying the original transformation.void
scale
(double scaleX, double scaleY) Changes the transformation represented by this Matrix to be the transformation given by first scaling bysx
in the X direction andsy
in the Y direction then applying the original transformation.void
transformDistance
(Out<Double> dx, Out<Double> dy) Transforms the distance vector (dx
,dy
) by this Matrix.void
transformPixelRectangle
(@Nullable Rectangle rect) First transforms therect
using this Matrix, then calculates the bounding box of the transformed rectangle.void
transformPoint
(Out<Double> x, Out<Double> y) Transforms the point (x
,y
) by this Matrix.void
transformRectangle
(@Nullable Rectangle rect) First transformsrect
using this Matrix, then calculates the bounding box of the transformed rectangle.void
translate
(double tx, double ty) Changes the transformation represented by this Matrix to be the transformation given by first translating by (tx
,ty
) then applying the original transformation.void
writeX0
(double x0) Write a value in the fieldx0
.void
writeXx
(double xx) Write a value in the fieldxx
.void
writeXy
(double xy) Write a value in the fieldxy
.void
writeY0
(double y0) Write a value in the fieldy0
.void
writeYx
(double yx) Write a value in the fieldyx
.void
writeYy
(double yy) Write a value in the fieldyy
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Matrix
Create a Matrix proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Matrix
Allocate a new Matrix.- Parameters:
arena
- to control the memory allocation scope
-
Matrix
public Matrix()Allocate a new Matrix. The memory is allocated withArena.ofAuto()
. -
Matrix
Allocate a new Matrix with the fields set to the provided values.- Parameters:
xx
- value for the fieldxx
xy
- value for the fieldxy
yx
- value for the fieldyx
yy
- value for the fieldyy
x0
- value for the fieldx0
y0
- value for the fieldy0
arena
- to control the memory allocation scope
-
Matrix
public Matrix(double xx, double xy, double yx, double yy, double x0, double y0) Allocate a new Matrix with the fields set to the provided values. The memory is allocated withArena.ofAuto()
.- Parameters:
xx
- value for the fieldxx
xy
- value for the fieldxy
yx
- value for the fieldyx
yy
- value for the fieldyy
x0
- value for the fieldx0
y0
- value for the fieldy0
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readXx
public double readXx()Read the value of the fieldxx
.- Returns:
- The value of the field
xx
-
writeXx
public void writeXx(double xx) Write a value in the fieldxx
.- Parameters:
xx
- The new value for the fieldxx
-
readXy
public double readXy()Read the value of the fieldxy
.- Returns:
- The value of the field
xy
-
writeXy
public void writeXy(double xy) Write a value in the fieldxy
.- Parameters:
xy
- The new value for the fieldxy
-
readYx
public double readYx()Read the value of the fieldyx
.- Returns:
- The value of the field
yx
-
writeYx
public void writeYx(double yx) Write a value in the fieldyx
.- Parameters:
yx
- The new value for the fieldyx
-
readYy
public double readYy()Read the value of the fieldyy
.- Returns:
- The value of the field
yy
-
writeYy
public void writeYy(double yy) Write a value in the fieldyy
.- Parameters:
yy
- The new value for the fieldyy
-
readX0
public double readX0()Read the value of the fieldx0
.- Returns:
- The value of the field
x0
-
writeX0
public void writeX0(double x0) Write a value in the fieldx0
.- Parameters:
x0
- The new value for the fieldx0
-
readY0
public double readY0()Read the value of the fieldy0
.- Returns:
- The value of the field
y0
-
writeY0
public void writeY0(double y0) Write a value in the fieldy0
.- Parameters:
y0
- The new value for the fieldy0
-
concat
Changes the transformation represented by this Matrix to be the transformation given by first applying transformation given bynewMatrix
then applying the original transformation.- Parameters:
newMatrix
- aPangoMatrix
-
copy
-
free
public void free()Free aPangoMatrix
. -
getFontScaleFactor
public double getFontScaleFactor()Returns the scale factor of a matrix on the height of the font.That is, the scale factor in the direction perpendicular to the vector that the X coordinate is mapped to. If the scale in the X coordinate is needed as well, use
getFontScaleFactors(io.github.jwharm.javagi.base.Out<java.lang.Double>, io.github.jwharm.javagi.base.Out<java.lang.Double>)
.- Returns:
- the scale factor of this Matrix on the height of the font,
or 1.0 if this Matrix is
null
.
-
getFontScaleFactors
public void getFontScaleFactors(@Nullable @Nullable Out<Double> xscale, @Nullable @Nullable Out<Double> yscale) Calculates the scale factor of a matrix on the width and height of the font.That is,
xscale
is the scale factor in the direction of the X coordinate, andyscale
is the scale factor in the direction perpendicular to the vector that the X coordinate is mapped to.Note that output numbers will always be non-negative.
- Parameters:
xscale
- output scale factor in the x directionyscale
- output scale factor perpendicular to the x direction
-
getSlantRatio
public double getSlantRatio()Gets the slant ratio of a matrix.For a simple shear matrix in the form:
1 λ 0 1
this is simply λ.
- Returns:
- the slant ratio of this Matrix
-
rotate
public void rotate(double degrees) Changes the transformation represented by this Matrix to be the transformation given by first rotating bydegrees
degrees counter-clockwise then applying the original transformation.- Parameters:
degrees
- degrees to rotate counter-clockwise
-
scale
public void scale(double scaleX, double scaleY) Changes the transformation represented by this Matrix to be the transformation given by first scaling bysx
in the X direction andsy
in the Y direction then applying the original transformation.- Parameters:
scaleX
- amount to scale by in X directionscaleY
- amount to scale by in Y direction
-
transformDistance
Transforms the distance vector (dx
,dy
) by this Matrix.This is similar to
transformPoint(io.github.jwharm.javagi.base.Out<java.lang.Double>, io.github.jwharm.javagi.base.Out<java.lang.Double>)
, except that the translation components of the transformation are ignored. The calculation of the returned vector is as follows:dx2 = dx1 * xx + dy1 * xy; dy2 = dx1 * yx + dy1 * yy;
Affine transformations are position invariant, so the same vector always transforms to the same vector. If (
x1
,y1
) transforms to (x2
,y2
) then (x1
+dx1
,y1
+dy1
) will transform to (x1
+dx2
,y1
+dy2
) for all values ofx1
andx2
.- Parameters:
dx
- in/out X component of a distance vectordy
- in/out Y component of a distance vector
-
transformPixelRectangle
First transforms therect
using this Matrix, then calculates the bounding box of the transformed rectangle.This function is useful for example when you want to draw a rotated
PangoLayout
to an image buffer, and want to know how large the image should be and how much you should shift the layout when rendering.For better accuracy, you should use
transformRectangle(org.gnome.pango.Rectangle)
on original rectangle in Pango units and convert to pixels afterward usingPango.extentsToPixels(org.gnome.pango.Rectangle, org.gnome.pango.Rectangle)
's first argument.- Parameters:
rect
- in/out bounding box in device units
-
transformPoint
-
transformRectangle
First transformsrect
using this Matrix, then calculates the bounding box of the transformed rectangle.This function is useful for example when you want to draw a rotated
PangoLayout
to an image buffer, and want to know how large the image should be and how much you should shift the layout when rendering.If you have a rectangle in device units (pixels), use
transformPixelRectangle(org.gnome.pango.Rectangle)
.If you have the rectangle in Pango units and want to convert to transformed pixel bounding box, it is more accurate to transform it first (using this function) and pass the result to pango_extents_to_pixels(), first argument, for an inclusive rounded rectangle. However, there are valid reasons that you may want to convert to pixels first and then transform, for example when the transformed coordinates may overflow in Pango units (large matrix translation for example).
- Parameters:
rect
- in/out bounding box in Pango units
-
translate
public void translate(double tx, double ty) Changes the transformation represented by this Matrix to be the transformation given by first translating by (tx
,ty
) then applying the original transformation.- Parameters:
tx
- amount to translate in the X directionty
- amount to translate in the Y direction
-