Class Matrix

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Matrix extends ProxyInstance

A 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;
Since:
1.6
  • Constructor Summary

    Constructors
    Constructor
    Description
    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.
    Matrix(double xx, double xy, double yx, double yy, double x0, double y0, Arena arena)
    Allocate a new Matrix with the fields set to the provided values.
    Matrix(Arena arena)
    Allocate a new Matrix.
    Create a Matrix proxy instance for the provided memory address.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    concat(Matrix newMatrix)
    Changes the transformation represented by this Matrix to be the transformation given by first applying transformation given by newMatrix then applying the original transformation.
    @Nullable Matrix
    Copies a PangoMatrix.
    void
    Free a PangoMatrix.
    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.
    The memory layout of the native struct.
    double
    Gets the slant ratio of a matrix.
    static @Nullable Type
    Get the GType of the Matrix class.
    double
    Read the value of the field x0.
    double
    Read the value of the field xx.
    double
    Read the value of the field xy.
    double
    Read the value of the field y0.
    double
    Read the value of the field yx.
    double
    Read the value of the field yy.
    void
    rotate(double degrees)
    Changes the transformation represented by this Matrix to be the transformation given by first rotating by degrees 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 by sx in the X direction and sy in the Y direction then applying the original transformation.
    void
    Transforms the distance vector (dy) by matrix.
    void
    First transforms the rect using matrix, then calculates the bounding box of the transformed rectangle.
    void
    Transforms the point (x, y) by matrix.
    void
    transformRectangle(@Nullable Rectangle rect)
    First transforms rect using 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 field x0.
    void
    writeXx(double xx)
    Write a value in the field xx.
    void
    writeXy(double xy)
    Write a value in the field xy.
    void
    writeY0(double y0)
    Write a value in the field y0.
    void
    writeYx(double yx)
    Write a value in the field yx.
    void
    writeYy(double yy)
    Write a value in the field yy.

    Methods inherited from class ProxyInstance

    equals, handle, hashCode

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Matrix

      public Matrix(MemorySegment address)
      Create a Matrix proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Matrix

      public Matrix(Arena arena)
      Allocate a new Matrix.
      Parameters:
      arena - to control the memory allocation scope
    • Matrix

      public Matrix()
      Allocate a new Matrix. The memory is allocated with Arena.ofAuto().
    • Matrix

      public Matrix(double xx, double xy, double yx, double yy, double x0, double y0, Arena arena)
      Allocate a new Matrix with the fields set to the provided values.
      Parameters:
      xx - value for the field xx
      xy - value for the field xy
      yx - value for the field yx
      yy - value for the field yy
      x0 - value for the field x0
      y0 - value for the field y0
      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 with Arena.ofAuto().
      Parameters:
      xx - value for the field xx
      xy - value for the field xy
      yx - value for the field yx
      yy - value for the field yy
      x0 - value for the field x0
      y0 - value for the field y0
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Matrix class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • readXx

      public double readXx()
      Read the value of the field xx.
      Returns:
      The value of the field xx
    • writeXx

      public void writeXx(double xx)
      Write a value in the field xx.
      Parameters:
      xx - The new value for the field xx
    • readXy

      public double readXy()
      Read the value of the field xy.
      Returns:
      The value of the field xy
    • writeXy

      public void writeXy(double xy)
      Write a value in the field xy.
      Parameters:
      xy - The new value for the field xy
    • readYx

      public double readYx()
      Read the value of the field yx.
      Returns:
      The value of the field yx
    • writeYx

      public void writeYx(double yx)
      Write a value in the field yx.
      Parameters:
      yx - The new value for the field yx
    • readYy

      public double readYy()
      Read the value of the field yy.
      Returns:
      The value of the field yy
    • writeYy

      public void writeYy(double yy)
      Write a value in the field yy.
      Parameters:
      yy - The new value for the field yy
    • readX0

      public double readX0()
      Read the value of the field x0.
      Returns:
      The value of the field x0
    • writeX0

      public void writeX0(double x0)
      Write a value in the field x0.
      Parameters:
      x0 - The new value for the field x0
    • readY0

      public double readY0()
      Read the value of the field y0.
      Returns:
      The value of the field y0
    • writeY0

      public void writeY0(double y0)
      Write a value in the field y0.
      Parameters:
      y0 - The new value for the field y0
    • concat

      public void concat(Matrix newMatrix)
      Changes the transformation represented by this Matrix to be the transformation given by first applying transformation given by newMatrix then applying the original transformation.
      Parameters:
      newMatrix - a PangoMatrix
      Since:
      1.6
    • copy

      public @Nullable Matrix copy()
      Copies a PangoMatrix.
      Returns:
      the newly allocated PangoMatrix
      Since:
      1.6
    • free

      public void free()
      Free a PangoMatrix.
      Since:
      1.6
    • 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(Out, Out).

      Returns:
      the scale factor of this Matrix on the height of the font, or 1.0 if this Matrix is null.
      Since:
      1.12
    • getFontScaleFactors

      public 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.

      That is, xscale is the scale factor in the direction of the X coordinate, and yscale 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 direction
      yscale - output scale factor perpendicular to the x direction
      Since:
      1.38
    • 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
      Since:
      1.50
    • rotate

      public void rotate(double degrees)
      Changes the transformation represented by this Matrix to be the transformation given by first rotating by degrees degrees counter-clockwise then applying the original transformation.
      Parameters:
      degrees - degrees to rotate counter-clockwise
      Since:
      1.6
    • scale

      public void scale(double scaleX, double scaleY)
      Changes the transformation represented by this Matrix to be the transformation given by first scaling by sx in the X direction and sy in the Y direction then applying the original transformation.
      Parameters:
      scaleX - amount to scale by in X direction
      scaleY - amount to scale by in Y direction
      Since:
      1.6
    • transformDistance

      public void transformDistance(Out<Double> dx, Out<Double> dy)

      Transforms the distance vector (dy) by matrix.

      This is similar to transformPoint(Out, Out), 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 (y1) transforms to (y2) then (dy1) will transform to (dy2) for all values of x1 and x2.

      Parameters:
      dx - in/out X component of a distance vector
      dy - in/out Y component of a distance vector
      Since:
      1.16
    • transformPixelRectangle

      public void transformPixelRectangle(@Nullable Rectangle rect)

      First transforms the rect using 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(Rectangle) on original rectangle in Pango units and convert to pixels afterward using Pango.extentsToPixels(Rectangle, Rectangle)'s first argument.

      Parameters:
      rect - in/out bounding box in device units
      Since:
      1.16
    • transformPoint

      public void transformPoint(Out<Double> x, Out<Double> y)
      Transforms the point (x, y) by matrix.
      Parameters:
      x - in/out X position
      y - in/out Y position
      Since:
      1.16
    • transformRectangle

      public void transformRectangle(@Nullable Rectangle rect)

      First transforms rect using 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(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
      Since:
      1.16
    • 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 direction
      ty - amount to translate in the Y direction
      Since:
      1.6