Class GlyphString
- All Implemented Interfaces:
Proxy
PangoGlyphString
is used to store strings of glyphs with geometry
and visual attribute information.
The storage for the glyph information is owned by the structure which simplifies memory management.
-
Constructor Summary
ConstructorDescriptionCreate a newPangoGlyphString
.GlyphString
(MemorySegment address) Create a GlyphString proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Copy a glyph string and associated storage.void
Compute the logical and ink extents of a glyph string.void
extentsRange
(int start, int end, Font font, @Nullable Rectangle inkRect, @Nullable Rectangle logicalRect) Computes the extents of a sub-portion of a glyph string.void
free()
Free a glyph string and associated storage.void
getLogicalWidths
(String text, int length, int embeddingLevel, int[] logicalWidths) Given aPangoGlyphString
and corresponding text, determine the width corresponding to each character.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the GlyphString classint
getWidth()
Computes the logical width of the glyph string.void
indexToX
(String text, int length, Analysis analysis, int index, boolean trailing, Out<Integer> xPos) Converts from character position to x position.void
indexToXFull
(String text, int length, Analysis analysis, @Nullable LogAttr attrs, int index, boolean trailing, Out<Integer> xPos) Converts from character position to x position.Read the value of the fieldglyphs
.Read the value of the fieldlog_clusters
.int
Read the value of the fieldnum_glyphs
.int
Read the value of the fieldspace
.void
setSize
(int newLen) Resize a glyph string to the given length.void
writeGlyphs
(GlyphInfo[] glyphs, Arena _arena) Write a value in the fieldglyphs
.void
writeLogClusters
(MemorySegment logClusters) Write a value in the fieldlog_clusters
.void
writeNumGlyphs
(int numGlyphs) Write a value in the fieldnum_glyphs
.void
writeSpace
(int space) Write a value in the fieldspace
.void
xToIndex
(String text, int length, Analysis analysis, int xPos, Out<Integer> index, Out<Integer> trailing) Convert from x offset to character position.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
GlyphString
Create a GlyphString proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
GlyphString
public GlyphString()Create a newPangoGlyphString
.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readNumGlyphs
public int readNumGlyphs()Read the value of the fieldnum_glyphs
.- Returns:
- The value of the field
num_glyphs
-
writeNumGlyphs
public void writeNumGlyphs(int numGlyphs) Write a value in the fieldnum_glyphs
.- Parameters:
numGlyphs
- The new value for the fieldnum_glyphs
-
readGlyphs
Read the value of the fieldglyphs
.- Returns:
- The value of the field
glyphs
-
writeGlyphs
-
readLogClusters
Read the value of the fieldlog_clusters
.- Returns:
- The value of the field
log_clusters
-
writeLogClusters
Write a value in the fieldlog_clusters
.- Parameters:
logClusters
- The new value for the fieldlog_clusters
-
readSpace
public int readSpace()Read the value of the fieldspace
.- Returns:
- The value of the field
space
-
writeSpace
public void writeSpace(int space) Write a value in the fieldspace
.- Parameters:
space
- The new value for the fieldspace
-
copy
Copy a glyph string and associated storage.- Returns:
- the newly allocated
PangoGlyphString
-
extents
public void extents(Font font, @Nullable @Nullable Rectangle inkRect, @Nullable @Nullable Rectangle logicalRect) Compute the logical and ink extents of a glyph string.See the documentation for
Font.getGlyphExtents(org.gnome.pango.Glyph, org.gnome.pango.Rectangle, org.gnome.pango.Rectangle)
for details about the interpretation of the rectangles.Examples of logical (red) and ink (green) rects:
- Parameters:
font
- aPangoFont
inkRect
- rectangle used to store the extents of the glyph string as drawnlogicalRect
- rectangle used to store the logical extents of the glyph string
-
extentsRange
public void extentsRange(int start, int end, Font font, @Nullable @Nullable Rectangle inkRect, @Nullable @Nullable Rectangle logicalRect) Computes the extents of a sub-portion of a glyph string.The extents are relative to the start of the glyph string range (the origin of their coordinate system is at the start of the range, not at the start of the entire glyph string).
- Parameters:
start
- start indexend
- end index (the range is the set of bytes with indices such that start <= index < end)font
- aPangoFont
inkRect
- rectangle used to store the extents of the glyph string range as drawnlogicalRect
- rectangle used to store the logical extents of the glyph string range
-
free
public void free()Free a glyph string and associated storage. -
getLogicalWidths
Given aPangoGlyphString
and corresponding text, determine the width corresponding to each character.When multiple characters compose a single cluster, the width of the entire cluster is divided equally among the characters.
See also
GlyphItem.getLogicalWidths(java.lang.String, int[])
.- Parameters:
text
- the text corresponding to the glyphslength
- the length oftext
, in bytesembeddingLevel
- the embedding level of the stringlogicalWidths
- an array whose length is the number of characters in text (equal tog_utf8_strlen (text, length)
unless text hasNUL
bytes) to be filled in with the resulting character widths.
-
getWidth
public int getWidth()Computes the logical width of the glyph string.This can also be computed using
extents(org.gnome.pango.Font, org.gnome.pango.Rectangle, org.gnome.pango.Rectangle)
. However, since this only computes the width, it's much faster. This is in fact only a convenience function that computes the sum ofgeometry
.width for each glyph in the this GlyphString.- Returns:
- the logical width of the glyph string.
-
indexToX
public void indexToX(String text, int length, Analysis analysis, int index, boolean trailing, Out<Integer> xPos) Converts from character position to x position.The X position is measured from the left edge of the run. Character positions are obtained using font metrics for ligatures where available, and computed by dividing up each cluster into equal portions, otherwise.
<picture> <source srcset="glyphstring-positions-dark.png" media="(prefers-color-scheme: dark)"> <img alt="Glyph positions" src="glyphstring-positions-light.png"> </picture>
- Parameters:
text
- the text for the runlength
- the number of bytes (not characters) intext
.analysis
- the analysis information return fromPango.itemize(org.gnome.pango.Context, java.lang.String, int, int, org.gnome.pango.AttrList, org.gnome.pango.AttrIterator)
index
- the byte index withintext
trailing
- whether we should compute the result for the beginning (false
) or end (true
) of the character.xPos
- location to store result
-
indexToXFull
public void indexToXFull(String text, int length, Analysis analysis, @Nullable @Nullable LogAttr attrs, int index, boolean trailing, Out<Integer> xPos) Converts from character position to x position.This variant of
indexToX(java.lang.String, int, org.gnome.pango.Analysis, int, boolean, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
additionally accepts aPangoLogAttr
array. The grapheme boundary information in it can be used to disambiguate positioning inside some complex clusters.- Parameters:
text
- the text for the runlength
- the number of bytes (not characters) intext
.analysis
- the analysis information return fromPango.itemize(org.gnome.pango.Context, java.lang.String, int, int, org.gnome.pango.AttrList, org.gnome.pango.AttrIterator)
attrs
-PangoLogAttr
array fortext
index
- the byte index withintext
trailing
- whether we should compute the result for the beginning (false
) or end (true
) of the character.xPos
- location to store result
-
setSize
public void setSize(int newLen) Resize a glyph string to the given length.- Parameters:
newLen
- the new length of the string
-
xToIndex
public void xToIndex(String text, int length, Analysis analysis, int xPos, Out<Integer> index, Out<Integer> trailing) Convert from x offset to character position.Character positions are computed by dividing up each cluster into equal portions. In scripts where positioning within a cluster is not allowed (such as Thai), the returned value may not be a valid cursor position; the caller must combine the result with the logical attributes for the text to compute the valid cursor position.
- Parameters:
text
- the text for the runlength
- the number of bytes (not characters) in text.analysis
- the analysis information return fromPango.itemize(org.gnome.pango.Context, java.lang.String, int, int, org.gnome.pango.AttrList, org.gnome.pango.AttrIterator)
xPos
- the x offset (in Pango units)index
- location to store calculated byte index withintext
trailing
- location to store a boolean indicating whether the user clicked on the leading or trailing edge of the character
-