Class Renderer
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
Renderer.RendererImpl
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Renderer.Builder<B extends Renderer.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Class structure forPangoRenderer
.static class
The RendererImpl type represents a native instance of the abstract Renderer class.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionRenderer
(MemorySegment address) Create a Renderer proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
Does initial setup before rendering operations on this Renderer.protected Renderer
asParent()
Returns this instance as if it were its parent type.protected void
begin()
Do renderer-specific initialization before drawingstatic Renderer.Builder
<? extends Renderer.Builder> builder()
ARenderer.Builder
object constructs aRenderer
with the specified properties.void
Cleans up after rendering operations on this Renderer.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.void
Draws a single glyph with coordinates in device space.void
drawGlyphItem
(@Nullable String text, GlyphItem glyphItem, int x, int y) Draws the glyphs inglyphItem
with the specifiedPangoRenderer
, embedding the text associated with the glyphs in the output if the output format supports it.void
drawGlyphs
(Font font, GlyphString glyphs, int x, int y) Draws the glyphs inglyphs
with the specifiedPangoRenderer
.void
drawLayout
(Layout layout, int x, int y) Drawslayout
with the specifiedPangoRenderer
.void
drawLayoutLine
(LayoutLine line, int x, int y) Drawsline
with the specifiedPangoRenderer
.void
drawRectangle
(RenderPart part, int x, int y, int width, int height) Draws an axis-aligned rectangle in user space coordinates with the specifiedPangoRenderer
.protected void
draw content for a glyph shaped withPangoAttrShape
x
,y
are the coordinates of the left edge of the baseline, in user coordinates.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 givenPangoRenderer
; coordinates are in device space.protected void
end()
Do renderer-specific cleanup after drawingshort
getAlpha
(RenderPart part) Gets the current alpha for the specified part.getColor
(RenderPart part) Gets the current rendering color for the specified part.Gets the layout currently being rendered using this Renderer.Gets the layout line currently being rendered using this Renderer.Gets the transformation matrix that will be applied when rendering.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the Renderer classvoid
partChanged
(RenderPart part) Informs Pango that the way that the rendering is done forpart
has changed.protected void
prepareRun
(LayoutRun run) updates the renderer for a new runvoid
setAlpha
(RenderPart part, short alpha) Sets the alpha for part of the rendering.void
setColor
(RenderPart part, @Nullable Color color) Sets the color for part of the rendering.void
Sets the transformation matrix that will be applied when rendering.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Renderer
Create a Renderer proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
activate
public void activate()Does initial setup before rendering operations on this Renderer.deactivate()
should be called when done drawing. Calls such asdrawLayout(org.gnome.pango.Layout, int, int)
automatically activate the layout before drawing on it.Calls to
activate()
anddeactivate()
can be nested and the renderer will only be initialized and deinitialized once. -
deactivate
public void deactivate()Cleans up after rendering operations on this Renderer.See docs for
activate()
. -
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 systemy
- Y coordinate of underline, in Pango units in user coordinate systemwidth
- width of underline, in Pango units in user coordinate systemheight
- height of underline, in Pango units in user coordinate system
-
drawGlyph
-
drawGlyphItem
Draws the glyphs inglyphItem
with the specifiedPangoRenderer
, 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 byglyph_item->item->offset
.If
text
isnull
, this simply callsdrawGlyphs(org.gnome.pango.Font, org.gnome.pango.GlyphString, int, int)
.The default implementation of this method simply falls back to
drawGlyphs(org.gnome.pango.Font, org.gnome.pango.GlyphString, int, int)
.- Parameters:
text
- the UTF-8 text thatglyphItem
refers toglyphItem
- aPangoGlyphItem
x
- X position of left edge of baseline, in user space coordinates in Pango unitsy
- Y position of left edge of baseline, in user space coordinates in Pango units
-
drawGlyphs
Draws the glyphs inglyphs
with the specifiedPangoRenderer
.- Parameters:
font
- aPangoFont
glyphs
- aPangoGlyphString
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.
-
drawLayout
Drawslayout
with the specifiedPangoRenderer
.This is equivalent to drawing the lines of the layout, at their respective positions relative to
x
,y
.- Parameters:
layout
- aPangoLayout
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.
-
drawLayoutLine
Drawsline
with the specifiedPangoRenderer
.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
- aPangoLayoutLine
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.
-
drawRectangle
Draws an axis-aligned rectangle in user space coordinates with the specifiedPangoRenderer
.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 ofx
- X position at which to draw rectangle, in user space coordinates in Pango unitsy
- Y position at which to draw rectangle, in user space coordinates in Pango unitswidth
- width of rectangle in Pango unitsheight
- height of rectangle in Pango units
-
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 givenPangoRenderer
; coordinates are in device space.- Parameters:
part
- type of object this trapezoid is part ofy1
- Y coordinate of top of trapezoidx11
- X coordinate of left end of top of trapezoidx21
- X coordinate of right end of top of trapezoidy2
- Y coordinate of bottom of trapezoidx12
- X coordinate of left end of bottom of trapezoidx22
- X coordinate of right end of bottom of trapezoid
-
getAlpha
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.
-
getColor
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.
-
getLayout
Gets the layout currently being rendered using this 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.
-
getLayoutLine
Gets the layout line currently being rendered using this 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.
-
getMatrix
Gets the transformation matrix that will be applied when rendering.- 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.
-
partChanged
Informs Pango that the way that the rendering is done forpart
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 callpango_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(org.gnome.pango.RenderPart, org.gnome.pango.Color)
)- Parameters:
part
- the part for which rendering has changed.
-
setAlpha
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 foralpha
- an alpha value between 1 and 65536, or 0 to unset the alpha
-
setColor
Sets the color for part of the rendering.- Parameters:
part
- the part to change the color ofcolor
- the new color ornull
to unset the current color
-
setMatrix
Sets the transformation matrix that will be applied when rendering.- Parameters:
matrix
- aPangoMatrix
, ornull
to unset any existing matrix (No matrix set is the same as setting the identity matrix.)
-
begin
protected void begin()Do renderer-specific initialization before drawing -
drawShape
draw content for a glyph shaped withPangoAttrShape
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
updates the renderer for a new run -
builder
ARenderer.Builder
object constructs aRenderer
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withRenderer.Builder.build()
.
-