Class FontDescription
- All Implemented Interfaces:
Proxy
PangoFontDescription
describes a font in an implementation-independent
manner.
PangoFontDescription
structures are used both to list what fonts are
available on the system and also for specifying the characteristics of
a font to load.
-
Constructor Summary
ConstructorDescriptionCreates a new font description structure with all fields unset.FontDescription
(MemorySegment address) Create a FontDescription proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionboolean
betterMatch
(@Nullable FontDescription oldMatch, FontDescription newMatch) Determines if the style attributes ofnewMatch
are a closer match for this FontDescription than those ofoldMatch
are, or ifoldMatch
isnull
, determines ifnewMatch
is a match at all.copy()
Make a copy of aPangoFontDescription
.Make a copy of aPangoFontDescription
, but don't duplicate allocated fields.boolean
equal
(FontDescription desc2) Compares two font descriptions for equality.void
free()
Frees a font description.static FontDescription
fromString
(String str) Creates a new font description from a string representation.Gets the family name field of a font description.Gets the gravity field of a font description.Determines which fields in a font description have been set.int
getSize()
Gets the size field of a font description.boolean
Determines whether the size of the font is in points (not absolute) or device units (absolute).Gets the stretch field of a font description.getStyle()
Gets the style field of aPangoFontDescription
.static Type
getType()
Get the GType of the FontDescription classGets the variant field of aPangoFontDescription
.Gets the variations field of a font description.Gets the weight field of a font description.int
hash()
Computes a hash of aPangoFontDescription
structure.void
merge
(@Nullable FontDescription descToMerge, boolean replaceExisting) Merges the fields that are set indescToMerge
into the fields in this FontDescription.void
mergeStatic
(FontDescription descToMerge, boolean replaceExisting) Merges the fields that are set indescToMerge
into the fields in this FontDescription, without copying allocated fields.void
setAbsoluteSize
(double size) Sets the size field of a font description, in device units.void
Sets the family name field of a font description.void
setFamilyStatic
(String family) Sets the family name field of a font description, without copying the string.void
setGravity
(Gravity gravity) Sets the gravity field of a font description.void
setSize
(int size) Sets the size field of a font description in fractional points.void
setStretch
(Stretch stretch) Sets the stretch field of a font description.void
Sets the style field of aPangoFontDescription
.void
setVariant
(Variant variant) Sets the variant field of a font description.void
setVariations
(@Nullable String variations) Sets the variations field of a font description.void
setVariationsStatic
(String variations) Sets the variations field of a font description.void
Sets the weight field of a font description.Creates a filename representation of a font description.toString()
Creates a string representation of a font description.void
unsetFields
(Set<FontMask> toUnset) Unsets some of the fields in aPangoFontDescription
.void
unsetFields
(FontMask... toUnset) Unsets some of the fields in aPangoFontDescription
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
FontDescription
Create a FontDescription proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
FontDescription
public FontDescription()Creates a new font description structure with all fields unset.
-
-
Method Details
-
getType
-
fromString
Creates a new font description from a string representation.The string must have the form
"\\[FAMILY-LIST] \\[STYLE-OPTIONS] \\[SIZE] \\[VARIATIONS]",
where FAMILY-LIST is a comma-separated list of families optionally terminated by a comma, STYLE_OPTIONS is a whitespace-separated list of words where each word describes one of style, variant, weight, stretch, or gravity, and SIZE is a decimal number (size in points) or optionally followed by the unit modifier "px" for absolute size. VARIATIONS is a comma-separated list of font variation specifications of the form "\\
axis
=value" (the = sign is optional).The following words are understood as styles: "Normal", "Roman", "Oblique", "Italic".
The following words are understood as variants: "Small-Caps", "All-Small-Caps", "Petite-Caps", "All-Petite-Caps", "Unicase", "Title-Caps".
The following words are understood as weights: "Thin", "Ultra-Light", "Extra-Light", "Light", "Semi-Light", "Demi-Light", "Book", "Regular", "Medium", "Semi-Bold", "Demi-Bold", "Bold", "Ultra-Bold", "Extra-Bold", "Heavy", "Black", "Ultra-Black", "Extra-Black".
The following words are understood as stretch values: "Ultra-Condensed", "Extra-Condensed", "Condensed", "Semi-Condensed", "Semi-Expanded", "Expanded", "Extra-Expanded", "Ultra-Expanded".
The following words are understood as gravity values: "Not-Rotated", "South", "Upside-Down", "North", "Rotated-Left", "East", "Rotated-Right", "West".
Any one of the options may be absent. If FAMILY-LIST is absent, then the family_name field of the resulting font description will be initialized to
null
. If STYLE-OPTIONS is missing, then all style options will be set to the default values. If SIZE is missing, the size in the resulting font description will be set to 0.A typical example:
"Cantarell Italic Light 15 \\
wght
=200"- Parameters:
str
- string representation of a font description.- Returns:
- a new
PangoFontDescription
.
-
betterMatch
Determines if the style attributes ofnewMatch
are a closer match for this FontDescription than those ofoldMatch
are, or ifoldMatch
isnull
, determines ifnewMatch
is a match at all.Approximate matching is done for weight and style; other style attributes must match exactly. Style attributes are all attributes other than family and size-related attributes. Approximate matching for style considers
Style.OBLIQUE
andStyle.ITALIC
as matches, but not as good a match as when the styles are equal.Note that
oldMatch
must match this FontDescription.- Parameters:
oldMatch
- aPangoFontDescription
, ornull
newMatch
- aPangoFontDescription
- Returns:
true
ifnewMatch
is a better match
-
copy
Make a copy of aPangoFontDescription
.- Returns:
- the newly allocated
PangoFontDescription
, which should be freed withfree()
, ornull
if this FontDescription wasnull
.
-
copyStatic
Make a copy of aPangoFontDescription
, but don't duplicate allocated fields.This is like
copy()
, but only a shallow copy is made of the family name and other allocated fields. The result can only be used until this FontDescription is modified or freed. This is meant to be used when the copy is only needed temporarily.- Returns:
- the newly allocated
PangoFontDescription
, which should be freed withfree()
, ornull
if this FontDescription wasnull
.
-
equal
Compares two font descriptions for equality.Two font descriptions are considered equal if the fonts they describe are provably identical. This means that their masks do not have to match, as long as other fields are all the same. (Two font descriptions may result in identical fonts being loaded, but still compare
false
.)- Parameters:
desc2
- anotherPangoFontDescription
- Returns:
true
if the two font descriptions are identical,false
otherwise.
-
free
public void free()Frees a font description. -
getFamily
Gets the family name field of a font description.- Returns:
- the family name field for the
font description, or
null
if not previously set. This has the same life-time as the font description itself and should not be freed.
-
getGravity
Gets the gravity field of a font description.- Returns:
- the gravity field for the font description.
Use
getSetFields()
to find out if the field was explicitly set or not.
-
getSetFields
-
getSize
public int getSize()Gets the size field of a font description.See
setSize(int)
.- Returns:
- the size field for the font description in points
or device units. You must call
getSizeIsAbsolute()
to find out which is the case. Returns 0 if the size field has not previously been set or it has been set to 0 explicitly. UsegetSetFields()
to find out if the field was explicitly set or not.
-
getSizeIsAbsolute
public boolean getSizeIsAbsolute()Determines whether the size of the font is in points (not absolute) or device units (absolute).See
setSize(int)
andsetAbsoluteSize(double)
.- Returns:
- whether the size for the font description is in
points or device units. Use
getSetFields()
to find out if the size field of the font description was explicitly set or not.
-
getStretch
Gets the stretch field of a font description.- Returns:
- the stretch field for the font description.
Use
getSetFields()
to find out if the field was explicitly set or not.
-
getStyle
Gets the style field of aPangoFontDescription
.- Returns:
- the style field for the font description.
Use
getSetFields()
to find out if the field was explicitly set or not.
-
getVariant
Gets the variant field of aPangoFontDescription
.- Returns:
- the variant field for the font description.
Use
getSetFields()
to find out if the field was explicitly set or not.
-
getVariations
Gets the variations field of a font description.- Returns:
- the variations field for the font
description, or
null
if not previously set. This has the same life-time as the font description itself and should not be freed.
-
getWeight
Gets the weight field of a font description.- Returns:
- the weight field for the font description.
Use
getSetFields()
to find out if the field was explicitly set or not.
-
hash
public int hash()Computes a hash of aPangoFontDescription
structure.This is suitable to be used, for example, as an argument to g_hash_table_new(). The hash value is independent of this FontDescription->mask.
- Returns:
- the hash value.
-
merge
Merges the fields that are set indescToMerge
into the fields in this FontDescription.If
replaceExisting
isfalse
, only fields in this FontDescription that are not already set are affected. Iftrue
, then fields that are already set will be replaced as well.If
descToMerge
isnull
, this function performs nothing.- Parameters:
descToMerge
- thePangoFontDescription
to merge from, ornull
replaceExisting
- iftrue
, replace fields in this FontDescription with the corresponding values fromdescToMerge
, even if they are already exist.
-
mergeStatic
Merges the fields that are set indescToMerge
into the fields in this FontDescription, without copying allocated fields.This is like
merge(org.gnome.pango.FontDescription, boolean)
, but only a shallow copy is made of the family name and other allocated fields. this FontDescription can only be used untildescToMerge
is modified or freed. This is meant to be used when the merged font description is only needed temporarily.- Parameters:
descToMerge
- thePangoFontDescription
to merge fromreplaceExisting
- iftrue
, replace fields in this FontDescription with the corresponding values fromdescToMerge
, even if they are already exist.
-
setAbsoluteSize
public void setAbsoluteSize(double size) Sets the size field of a font description, in device units.This is mutually exclusive with
setSize(int)
which sets the font size in points.- Parameters:
size
- the new size, in Pango units. There arePANGO_SCALE
Pango units in one device unit. For an output backend where a device unit is a pixel, asize
value of 10 * PANGO_SCALE gives a 10 pixel font.
-
setFamily
Sets the family name field of a font description.The family name represents a family of related font styles, and will resolve to a particular
PangoFontFamily
. In some uses ofPangoFontDescription
, it is also possible to use a comma separated list of family names for this field.- Parameters:
family
- a string representing the family name.
-
setFamilyStatic
Sets the family name field of a font description, without copying the string.This is like
setFamily(java.lang.String)
, except that no copy offamily
is made. The caller must make sure that the string passed in stays around until this FontDescription has been freed or the name is set again. This function can be used iffamily
is a static string such as a C string literal, or if this FontDescription is only needed temporarily.- Parameters:
family
- a string representing the family name
-
setGravity
Sets the gravity field of a font description.The gravity field specifies how the glyphs should be rotated. If
gravity
isGravity.AUTO
, this actually unsets the gravity mask on the font description.This function is seldom useful to the user. Gravity should normally be set on a
PangoContext
.- Parameters:
gravity
- the gravity for the font description.
-
setSize
public void setSize(int size) Sets the size field of a font description in fractional points.This is mutually exclusive with
setAbsoluteSize(double)
.- Parameters:
size
- the size of the font in points, scaled byPANGO_SCALE
. (That is, asize
value of 10 * PANGO_SCALE is a 10 point font. The conversion factor between points and device units depends on system configuration and the output device. For screen display, a logical DPI of 96 is common, in which case a 10 point font corresponds to a 10 * (96 / 72) = 13.3 pixel font. UsesetAbsoluteSize(double)
if you need a particular size in device units.
-
setStretch
Sets the stretch field of a font description.The
Pango.Stretch
field specifies how narrow or wide the font should be.- Parameters:
stretch
- the stretch for the font description
-
setStyle
Sets the style field of aPangoFontDescription
.The
Pango.Style
enumeration describes whether the font is slanted and the manner in which it is slanted; it can be eitherStyle.NORMAL
,Style.ITALIC
, orStyle.OBLIQUE
.Most fonts will either have a italic style or an oblique style, but not both, and font matching in Pango will match italic specifications with oblique fonts and vice-versa if an exact match is not found.
- Parameters:
style
- the style for the font description
-
setVariant
Sets the variant field of a font description.The
Pango.Variant
can either beVariant.NORMAL
orVariant.SMALL_CAPS
.- Parameters:
variant
- the variant type for the font description.
-
setVariations
Sets the variations field of a font description.OpenType font variations allow to select a font instance by specifying values for a number of axes, such as width or weight.
The format of the variations string is
AXIS1=VALUE,AXIS2=VALUE...
with each AXIS a 4 character tag that identifies a font axis, and each VALUE a floating point number. Unknown axes are ignored, and values are clamped to their allowed range.
Pango does not currently have a way to find supported axes of a font. Both harfbuzz and freetype have API for this. See for example hb_ot_var_get_axis_infos.
- Parameters:
variations
- a string representing the variations
-
setVariationsStatic
Sets the variations field of a font description.This is like
setVariations(java.lang.String)
, except that no copy ofvariations
is made. The caller must make sure that the string passed in stays around until this FontDescription has been freed or the name is set again. This function can be used ifvariations
is a static string such as a C string literal, or if this FontDescription is only needed temporarily.- Parameters:
variations
- a string representing the variations
-
setWeight
Sets the weight field of a font description.The weight field specifies how bold or light the font should be. In addition to the values of the
Pango.Weight
enumeration, other intermediate numeric values are possible.- Parameters:
weight
- the weight for the font description.
-
toFilename
Creates a filename representation of a font description.The filename is identical to the result from calling
toString()
, but with underscores instead of characters that are untypical in filenames, and in lower case only.- Returns:
- a new string that must be freed with g_free().
-
toString
Creates a string representation of a font description.See
fromString(java.lang.String)
for a description of the format of the string representation. The family list in the string description will only have a terminating comma if the last word of the list is a valid style option. -
unsetFields
-
unsetFields
Unsets some of the fields in aPangoFontDescription
.The unset fields will get back to their default values.
- Parameters:
toUnset
- bitmask of fields in the this FontDescription to unset.
-