Class Context

All Implemented Interfaces:
Proxy

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

A 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().

  • Constructor Details

    • Context

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

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

    • getType

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

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

      protected Context 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
    • changed

      public void changed()

      Forces a change in the context, which will cause any PangoLayout 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.

      Since:
      1.32.4
    • getBaseDir

      public Direction getBaseDir()

      Retrieves the base direction for the context.

      See setBaseDir(Direction).

      Returns:
      the base direction for the context.
    • getBaseGravity

      public Gravity getBaseGravity()

      Retrieves the base gravity for the context.

      See setBaseGravity(Gravity).

      Returns:
      the base gravity for the context.
      Since:
      1.16
    • getFontDescription

      public @Nullable FontDescription 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

      public @Nullable FontMap getFontMap()
      Gets the PangoFontMap 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.
      Since:
      1.6
    • getGravity

      public Gravity getGravity()

      Retrieves the gravity for the context.

      This is similar to getBaseGravity(), except for when the base gravity is Gravity.AUTO for which Gravity.getForMatrix(Matrix) is used to return the gravity from the current context matrix.

      Returns:
      the resolved gravity for the context.
      Since:
      1.16
    • getGravityHint

      public GravityHint getGravityHint()

      Retrieves the gravity hint for the context.

      See setGravityHint(GravityHint) for details.

      Returns:
      the gravity hint for the context.
      Since:
      1.16
    • getLanguage

      public Language getLanguage()
      Retrieves the global language tag for the context.
      Returns:
      the global language tag.
    • getMatrix

      public @Nullable Matrix getMatrix()

      Gets the transformation matrix that will be applied when rendering with this context.

      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.6
    • getMetrics

      public FontMetrics getMetrics(@Nullable FontDescription desc, @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 by Pango.itemize(Context, String, int, int, AttrList, 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 - a PangoFontDescription 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 by Language.getDefault() will be returned.
      Returns:
      a PangoFontMetrics object. The caller must call FontMetrics.unref() when finished using the object.
    • getRoundGlyphPositions

      public boolean getRoundGlyphPositions()
      Returns whether font rendering with this context should round glyph positions and widths.
      Since:
      1.44
    • getSerial

      public int getSerial()

      Returns the current serial number of 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 their PangoContext changes, like PangoLayout.

      Returns:
      The current serial number of context.
      Since:
      1.32.4
    • listFamilies

      public void listFamilies(@Nullable Out<FontFamily[]> families)
      List all families for a context.
      Parameters:
      families - location to store a pointer to an array of PangoFontFamily. This array should be freed with g_free().
    • loadFont

      public @Nullable Font loadFont(FontDescription desc)
      Loads the font in one of the fontmaps in the context that is the closest match for desc.
      Parameters:
      desc - a PangoFontDescription describing the font to load
      Returns:
      the newly allocated PangoFont that was loaded, or null if no font matched.
    • loadFontset

      public @Nullable Fontset loadFontset(FontDescription desc, Language language)
      Load a set of fonts in the context that can be used to render a font matching desc.
      Parameters:
      desc - a PangoFontDescription describing the fonts to load
      language - a PangoLanguage the fonts will be used for
      Returns:
      the newly allocated PangoFontset loaded, or null if no font matched.
    • setBaseDir

      public void setBaseDir(Direction direction)

      Sets the base direction for the context.

      The base direction is used in applying the Unicode bidirectional algorithm; if the direction is Direction.LTR or Direction.RTL, then the value will be used as the paragraph direction in the Unicode bidirectional algorithm. A value of Direction.WEAK_LTR or Direction.WEAK_RTL is used only for paragraphs that do not contain any strong characters themselves.

      Parameters:
      direction - the new base direction
    • setBaseGravity

      public void setBaseGravity(Gravity gravity)

      Sets the base gravity for the context.

      The base gravity is used in laying vertical text out.

      Parameters:
      gravity - the new base gravity
      Since:
      1.16
    • setFontDescription

      public void setFontDescription(FontDescription desc)
      Set the default font description for the context
      Parameters:
      desc - the new pango font description
    • setFontMap

      public void setFontMap(@Nullable FontMap fontMap)

      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 - the PangoFontMap to set.
    • setGravityHint

      public void setGravityHint(GravityHint hint)

      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 to Gravity.EAST or Gravity.WEST.

      Parameters:
      hint - the new gravity hint
      Since:
      1.16
    • setLanguage

      public void setLanguage(@Nullable Language language)

      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

      public void setMatrix(@Nullable Matrix matrix)

      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 - a PangoMatrix, or null to unset any existing matrix. (No matrix set is the same as setting the identity matrix.)
      Since:
      1.6
    • 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
      Since:
      1.44
    • builder

      public static Context.Builder<? extends Context.Builder> builder()
      A Context.Builder object constructs a Context with the specified properties. Use the various set...() methods to set properties, and finish construction with Context.Builder.build().
      Returns:
      the builder object