Class Context
- All Implemented Interfaces:
Proxy
PangoContext
stores global information used to control the
itemization process.
The information stored by PangoContext
includes the fontmap used
to look up fonts, and default values such as the default language,
default gravity, or default font.
To obtain a PangoContext
, use FontMap.createContext()
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Context.Builder<B extends Context.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionContext()
Creates a newPangoContext
initialized to default values.Context
(MemorySegment address) Create a Context proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected Context
asParent()
Returns this instance as if it were its parent type.static Context.Builder
<? extends Context.Builder> builder()
AContext.Builder
object constructs aContext
with the specified properties.void
changed()
Forces a change in the context, which will cause anyPangoLayout
using this context to re-layout.Retrieves the base direction for the context.Retrieves the base gravity for the context.Retrieve the default font description for the context.Gets thePangoFontMap
used to look up fonts for this context.Retrieves the gravity for the context.Retrieves the gravity hint for the context.Retrieves the global language tag for the context.Gets the transformation matrix that will be applied when rendering with this context.getMetrics
(@Nullable FontDescription desc, @Nullable Language language) Get overall metric information for a particular font description.boolean
Returns whether font rendering with this context should round glyph positions and widths.int
Returns the current serial number of this Context.static Type
getType()
Get the GType of the Context classvoid
listFamilies
(Out<FontFamily[]> families) List all families for a context.loadFont
(FontDescription desc) Loads the font in one of the fontmaps in the context that is the closest match fordesc
.loadFontset
(FontDescription desc, Language language) Load a set of fonts in the context that can be used to render a font matchingdesc
.void
setBaseDir
(Direction direction) Sets the base direction for the context.void
setBaseGravity
(Gravity gravity) Sets the base gravity for the context.void
setFontDescription
(@Nullable FontDescription desc) Set the default font description for the contextvoid
setFontMap
(@Nullable FontMap fontMap) Sets the font map to be searched when fonts are looked-up in this context.void
setGravityHint
(GravityHint hint) Sets the gravity hint for the context.void
setLanguage
(@Nullable Language language) Sets the global language tag for the context.void
Sets the transformation matrix that will be applied when rendering with this context.void
setRoundGlyphPositions
(boolean roundPositions) Sets whether font rendering with this context should round glyph positions and widths to integral positions, in device units.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, getMemoryLayout, 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
-
Context
Create a Context proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Context
public Context()Creates a newPangoContext
initialized to default values.This function is not particularly useful as it should always be followed by a
setFontMap(org.gnome.pango.FontMap)
call, and the functionFontMap.createContext()
does these two steps together and hence users are recommended to use that.If you are using Pango as part of a higher-level system, that system may have it's own way of create a
PangoContext
. For instance, the GTK toolkit has, among others,gtk_widget_get_pango_context()
. Use those instead.
-
-
Method Details
-
getType
-
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. -
changed
public void changed()Forces a change in the context, which will cause anyPangoLayout
using this context to re-layout.This function is only useful when implementing a new backend for Pango, something applications won't do. Backends should call this function if they have attached extra data to the context and such data is changed.
-
getBaseDir
Retrieves the base direction for the context.- Returns:
- the base direction for the context.
-
getBaseGravity
Retrieves the base gravity for the context.- Returns:
- the base gravity for the context.
-
getFontDescription
Retrieve the default font description for the context.- Returns:
- a pointer to the context's default font description. This value must not be modified or freed.
-
getFontMap
Gets thePangoFontMap
used to look up fonts for this context.- Returns:
- the font map for the.
PangoContext
This value is owned by Pango and should not be unreferenced.
-
getGravity
Retrieves the gravity for the context.This is similar to
getBaseGravity()
, except for when the base gravity isGravity.AUTO
for whichGravity.getForMatrix(org.gnome.pango.Matrix)
is used to return the gravity from the current context matrix.- Returns:
- the resolved gravity for the context.
-
getGravityHint
Retrieves the gravity hint for the context.See
setGravityHint(org.gnome.pango.GravityHint)
for details.- Returns:
- the gravity hint for the context.
-
getLanguage
Retrieves the global language tag for the context.- Returns:
- the global language tag.
-
getMatrix
Gets the transformation matrix that will be applied when rendering with this context.- 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.
-
getMetrics
public FontMetrics getMetrics(@Nullable @Nullable FontDescription desc, @Nullable @Nullable Language language) Get overall metric information for a particular font description.Since the metrics may be substantially different for different scripts, a language tag can be provided to indicate that the metrics should be retrieved that correspond to the script(s) used by that language.
The
PangoFontDescription
is interpreted in the same way as byPango.itemize(org.gnome.pango.Context, java.lang.String, int, int, org.gnome.pango.AttrList, org.gnome.pango.AttrIterator)
, and the family name may be a comma separated list of names. If characters from multiple of these families would be used to render the string, then the returned fonts would be a composite of the metrics for the fonts loaded for the individual families.- Parameters:
desc
- aPangoFontDescription
structure.null
means that the font description from the context will be used.language
- language tag used to determine which script to get the metrics for.null
means that the language tag from the context will be used. If no language tag is set on the context, metrics for the default language (as determined byLanguage.getDefault()
will be returned.- Returns:
- a
PangoFontMetrics
object. The caller must callFontMetrics.unref()
when finished using the object.
-
getRoundGlyphPositions
public boolean getRoundGlyphPositions()Returns whether font rendering with this context should round glyph positions and widths. -
getSerial
public int getSerial()Returns the current serial number of this Context.The serial number is initialized to an small number larger than zero when a new context is created and is increased whenever the context is changed using any of the setter functions, or the
PangoFontMap
it uses to find fonts has changed. The serial may wrap, but will never have the value 0. Since it can wrap, never compare it with "less than", always use "not equals".This can be used to automatically detect changes to a
PangoContext
, and is only useful when implementing objects that need update when theirPangoContext
changes, likePangoLayout
.- Returns:
- The current serial number of this Context.
-
listFamilies
List all families for a context.- Parameters:
families
- location to store a pointer to an array ofPangoFontFamily
. This array should be freed with g_free().
-
loadFont
Loads the font in one of the fontmaps in the context that is the closest match fordesc
.- Parameters:
desc
- aPangoFontDescription
describing the font to load- Returns:
- the newly allocated
PangoFont
that was loaded, ornull
if no font matched.
-
loadFontset
Load a set of fonts in the context that can be used to render a font matchingdesc
.- Parameters:
desc
- aPangoFontDescription
describing the fonts to loadlanguage
- aPangoLanguage
the fonts will be used for- Returns:
- the newly allocated
PangoFontset
loaded, ornull
if no font matched.
-
setBaseDir
Sets the base direction for the context.The base direction is used in applying the Unicode bidirectional algorithm; if the
direction
isDirection.LTR
orDirection.RTL
, then the value will be used as the paragraph direction in the Unicode bidirectional algorithm. A value ofDirection.WEAK_LTR
orDirection.WEAK_RTL
is used only for paragraphs that do not contain any strong characters themselves.- Parameters:
direction
- the new base direction
-
setBaseGravity
Sets the base gravity for the context.The base gravity is used in laying vertical text out.
- Parameters:
gravity
- the new base gravity
-
setFontDescription
Set the default font description for the context- Parameters:
desc
- the new pango font description
-
setFontMap
Sets the font map to be searched when fonts are looked-up in this context.This is only for internal use by Pango backends, a
PangoContext
obtained via one of the recommended methods should already have a suitable font map.- Parameters:
fontMap
- thePangoFontMap
to set.
-
setGravityHint
Sets the gravity hint for the context.The gravity hint is used in laying vertical text out, and is only relevant if gravity of the context as returned by
getGravity()
is set toGravity.EAST
orGravity.WEST
.- Parameters:
hint
- the new gravity hint
-
setLanguage
Sets the global language tag for the context.The default language for the locale of the running process can be found using
Language.getDefault()
.- Parameters:
language
- the new language tag.
-
setMatrix
Sets the transformation matrix that will be applied when rendering with this context.Note that reported metrics are in the user space coordinates before the application of the matrix, not device-space coordinates after the application of the matrix. So, they don't scale with the matrix, though they may change slightly for different matrices, depending on how the text is fit to the pixel grid.
- Parameters:
matrix
- aPangoMatrix
, ornull
to unset any existing matrix. (No matrix set is the same as setting the identity matrix.)
-
setRoundGlyphPositions
public void setRoundGlyphPositions(boolean roundPositions) Sets whether font rendering with this context should round glyph positions and widths to integral positions, in device units.This is useful when the renderer can't handle subpixel positioning of glyphs.
The default value is to round glyph positions, to remain compatible with previous Pango behavior.
- Parameters:
roundPositions
- whether to round glyph positions
-
builder
AContext.Builder
object constructs aContext
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withContext.Builder.build()
.
-