Class Renderer

All Implemented Interfaces:
Proxy
Direct Known Subclasses:
Renderer.Renderer$Impl

@Generated("org.javagi.JavaGI") public abstract class Renderer extends GObject

PangoRenderer is a base class for objects that can render text provided as PangoGlyphString or PangoLayout.

By subclassing PangoRenderer and overriding operations such as drawGlyphs and drawRectangle, renderers for particular font backends and destinations can be created.

Since:
1.8
  • Constructor Details

    • Renderer

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

      public Renderer()
      Create a new Renderer.
  • Method Details

    • getType

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

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

      protected Renderer asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • activate

      public void activate()

      Does initial setup before rendering operations on renderer.

      deactivate() should be called when done drawing. Calls such as drawLayout(Layout, int, int) automatically activate the layout before drawing on it.

      Calls to activate() and deactivate() can be nested and the renderer will only be initialized and deinitialized once.

      Since:
      1.8
    • deactivate

      public void deactivate()

      Cleans up after rendering operations on renderer.

      See docs for activate().

      Since:
      1.8
    • drawErrorUnderline

      public void drawErrorUnderline(int x, int y, int width, int height)

      Draw a squiggly line that approximately covers the given rectangle in the style of an underline used to indicate a spelling error.

      The width of the underline is rounded to an integer number of up/down segments and the resulting rectangle is centered in the original rectangle.

      This should be called while this Renderer is already active. Use activate() to activate a renderer.

      Parameters:
      x - X coordinate of underline, in Pango units in user coordinate system
      y - Y coordinate of underline, in Pango units in user coordinate system
      width - width of underline, in Pango units in user coordinate system
      height - height of underline, in Pango units in user coordinate system
      Since:
      1.8
    • drawGlyph

      public void drawGlyph(Font font, Glyph glyph, double x, double y)
      Draws a single glyph with coordinates in device space.
      Parameters:
      font - a PangoFont
      glyph - the glyph index of a single glyph
      x - X coordinate of left edge of baseline of glyph
      y - Y coordinate of left edge of baseline of glyph
      Since:
      1.8
    • drawGlyphItem

      public void drawGlyphItem(@Nullable String text, GlyphItem glyphItem, int x, int y)

      Draws the glyphs in glyphItem with the specified PangoRenderer, embedding the text associated with the glyphs in the output if the output format supports it.

      This is useful for rendering text in PDF.

      Note that this method does not handle attributes in glyphItem. If you want colors, shapes and lines handled automatically according to those attributes, you need to use pango_renderer_draw_layout_line() or pango_renderer_draw_layout().

      Note that text is the start of the text for layout, which is then indexed by glyph_item->item->offset.

      If text is null, this simply calls drawGlyphs(Font, GlyphString, int, int).

      The default implementation of this method simply falls back to drawGlyphs(Font, GlyphString, int, int).

      Parameters:
      text - the UTF-8 text that glyphItem refers to
      glyphItem - a PangoGlyphItem
      x - X position of left edge of baseline, in user space coordinates in Pango units
      y - Y position of left edge of baseline, in user space coordinates in Pango units
      Since:
      1.22
    • drawGlyphs

      public void drawGlyphs(Font font, GlyphString glyphs, int x, int y)
      Draws the glyphs in glyphs with the specified PangoRenderer.
      Parameters:
      font - a PangoFont
      glyphs - a PangoGlyphString
      x - X position of left edge of baseline, in user space coordinates in Pango units.
      y - Y position of left edge of baseline, in user space coordinates in Pango units.
      Since:
      1.8
    • drawLayout

      public void drawLayout(Layout layout, int x, int y)

      Draws layout with the specified PangoRenderer.

      This is equivalent to drawing the lines of the layout, at their respective positions relative to x, y.

      Parameters:
      layout - a PangoLayout
      x - X position of left edge of baseline, in user space coordinates in Pango units.
      y - Y position of left edge of baseline, in user space coordinates in Pango units.
      Since:
      1.8
    • drawLayoutLine

      public void drawLayoutLine(LayoutLine line, int x, int y)

      Draws line with the specified PangoRenderer.

      This draws the glyph items that make up the line, as well as shapes, backgrounds and lines that are specified by the attributes of those items.

      Parameters:
      line - a PangoLayoutLine
      x - X position of left edge of baseline, in user space coordinates in Pango units.
      y - Y position of left edge of baseline, in user space coordinates in Pango units.
      Since:
      1.8
    • drawRectangle

      public void drawRectangle(RenderPart part, int x, int y, int width, int height)

      Draws an axis-aligned rectangle in user space coordinates with the specified PangoRenderer.

      This should be called while this Renderer is already active. Use activate() to activate a renderer.

      Parameters:
      part - type of object this rectangle is part of
      x - X position at which to draw rectangle, in user space coordinates in Pango units
      y - Y position at which to draw rectangle, in user space coordinates in Pango units
      width - width of rectangle in Pango units
      height - height of rectangle in Pango units
      Since:
      1.8
    • drawTrapezoid

      public void drawTrapezoid(RenderPart part, double y1, double x11, double x21, double y2, double x12, double x22)
      Draws a trapezoid with the parallel sides aligned with the X axis using the given PangoRenderer; coordinates are in device space.
      Parameters:
      part - type of object this trapezoid is part of
      y1 - Y coordinate of top of trapezoid
      x11 - X coordinate of left end of top of trapezoid
      x21 - X coordinate of right end of top of trapezoid
      y2 - Y coordinate of bottom of trapezoid
      x12 - X coordinate of left end of bottom of trapezoid
      x22 - X coordinate of right end of bottom of trapezoid
      Since:
      1.8
    • getAlpha

      public short getAlpha(RenderPart part)
      Gets the current alpha for the specified part.
      Parameters:
      part - the part to get the alpha for
      Returns:
      the alpha for the specified part, or 0 if it hasn't been set and should be inherited from the environment.
      Since:
      1.38
    • getColor

      public @Nullable Color getColor(RenderPart part)
      Gets the current rendering color for the specified part.
      Parameters:
      part - the part to get the color for
      Returns:
      the color for the specified part, or null if it hasn't been set and should be inherited from the environment.
      Since:
      1.8
    • getLayout

      public @Nullable Layout getLayout()

      Gets the layout currently being rendered using renderer.

      Calling this function only makes sense from inside a subclass's methods, like in its draw_shape vfunc, for example.

      The returned layout should not be modified while still being rendered.

      Returns:
      the layout, or null if no layout is being rendered using this Renderer at this time.
      Since:
      1.20
    • getLayoutLine

      public @Nullable LayoutLine getLayoutLine()

      Gets the layout line currently being rendered using renderer.

      Calling this function only makes sense from inside a subclass's methods, like in its draw_shape vfunc, for example.

      The returned layout line should not be modified while still being rendered.

      Returns:
      the layout line, or null if no layout line is being rendered using this Renderer at this time.
      Since:
      1.20
    • getMatrix

      public @Nullable Matrix getMatrix()

      Gets the transformation matrix that will be applied when rendering.

      See setMatrix(Matrix).

      Returns:
      the matrix, or null if no matrix has been set (which is the same as the identity matrix). The returned matrix is owned by Pango and must not be modified or freed.
      Since:
      1.8
    • partChanged

      public void partChanged(RenderPart part)

      Informs Pango that the way that the rendering is done for part has changed.

      This should be called if the rendering changes in a way that would prevent multiple pieces being joined together into one drawing call. For instance, if a subclass of PangoRenderer was to add a stipple option for drawing underlines, it needs to call

      pango_renderer_part_changed (render, PANGO_RENDER_PART_UNDERLINE);
      

      When the stipple changes or underlines with different stipples might be joined together. Pango automatically calls this for changes to colors. (See setColor(RenderPart, Color))

      Parameters:
      part - the part for which rendering has changed.
      Since:
      1.8
    • setAlpha

      public void setAlpha(RenderPart part, short alpha)

      Sets the alpha for part of the rendering.

      Note that the alpha may only be used if a color is specified for part as well.

      Parameters:
      part - the part to set the alpha for
      alpha - an alpha value between 1 and 65536, or 0 to unset the alpha
      Since:
      1.38
    • setColor

      public void setColor(RenderPart part, @Nullable Color color)

      Sets the color for part of the rendering.

      Also see setAlpha(RenderPart, short).

      Parameters:
      part - the part to change the color of
      color - the new color or null to unset the current color
      Since:
      1.8
    • setMatrix

      public void setMatrix(@Nullable Matrix matrix)
      Sets the transformation matrix that will be applied when rendering.
      Parameters:
      matrix - a PangoMatrix, or null to unset any existing matrix (No matrix set is the same as setting the identity matrix.)
      Since:
      1.8
    • begin

      protected void begin()
      Do renderer-specific initialization before drawing
    • drawShape

      protected void drawShape(AttrShape attr, int x, int y)
      draw content for a glyph shaped with PangoAttrShape x, y are the coordinates of the left edge of the baseline, in user coordinates.
    • end

      protected void end()
      Do renderer-specific cleanup after drawing
    • prepareRun

      protected void prepareRun(LayoutRun run)
      updates the renderer for a new run