pango

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2021 License: MIT, LGPL-2.1 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EMOJI emojiScannerCategory = iota
	EMOJI_TEXT_PRESENTATION
	EMOJI_EMOJI_PRESENTATION
	EMOJI_MODIFIER_BASE
	EMOJI_MODIFIER
	EMOJI_VS_BASE
	REGIONAL_INDICATOR
	KEYCAP_BASE
	COMBINING_ENCLOSING_KEYCAP
	COMBINING_ENCLOSING_CIRCLE_BACKSLASH
	ZWJ
	VS15
	VS16
	TAG_BASE
	TAG_SEQUENCE
	TAG_TERM
)
View Source
const (
	PangoScale_XX_SMALL = 0.5787037037037 //  The scale factor for three shrinking steps (1 / (1.2 * 1.2 * 1.2)).
	PangoScale_X_SMALL  = 0.6944444444444 //  The scale factor for two shrinking steps (1 / (1.2 * 1.2)).
	PangoScale_SMALL    = 0.8333333333333 //  The scale factor for one shrinking step (1 / 1.2).
	PangoScale_MEDIUM   = 1.0             //  The scale factor for normal size (1.0).
	PangoScale_LARGE    = 1.2             //  The scale factor for one magnification step (1.2).
	PangoScale_X_LARGE  = 1.44            //  The scale factor for two magnification steps (1.2 * 1.2).
	PangoScale_XX_LARGE = 1.728           //  The scale factor for three magnification steps (1.2 * 1.2 * 1.2).
)

CSS scale factors (1.2 factor between each size)

View Source
const (
	// Whether the segment should be shifted to center around the baseline.
	// Used in vertical writing directions mostly.
	PANGO_ANALYSIS_FLAG_CENTERED_BASELINE = 1 << iota
	// Used to mark runs that hold ellipsized text in an ellipsized layout
	PANGO_ANALYSIS_FLAG_IS_ELLIPSIS
	// Add an hyphen at the end of the run during shaping
	PANGO_ANALYSIS_FLAG_NEED_HYPHEN
)
View Source
const (
	NOT_CACHED uint8 = iota
	CACHED
	LEAKED
)
extents cache status:

* * LEAKED means that the user has access to this line structure or a * run included in this line, and so can change the glyphs/glyph-widths. * If this is true, extents caching will be disabled.

View Source
const (
	MEASURE = iota
	ADJUST
)
View Source
const LINE_SEPARATOR = 0x2028

Only one character has type G_UNICODE_LINE_SEPARATOR in Unicode 5.0: update this if that changes.

View Source
const PAREN_STACK_DEPTH = 128
View Source
const PangoScale = 1024

PangoScale represents the scale between dimensions used for Pango distances and device units. (The definition of device units is dependent on the output device; it will typically be pixels for a screen, and points for a printer.) PangoScale is currently 1024, but this may be changed in the future.

When setting font sizes, device units are always considered to be points (as in "12 point font"), rather than pixels.

View Source
const SUPERSUB_RISE = 5000

Variables

View Source
var (
	FontsetCaches     = map[Fontset]*FontCache{}
	FontsetCachesLock sync.Mutex
)
View Source
var GravityMap = enumMap{
	{/* contains filtered or unexported fields */},
	{/* contains filtered or unexported fields */},
	{/* contains filtered or unexported fields */},
	{/* contains filtered or unexported fields */},
	{/* contains filtered or unexported fields */},
	{/* contains filtered or unexported fields */},
	{/* contains filtered or unexported fields */},
	{/* contains filtered or unexported fields */},
}
View Source
var Identity = Matrix{1, 0, 0, 1, 0, 0}

Functions

func GetSampleString

func GetSampleString(lang Language) string

GetSampleString get a string that is representative of the characters needed to render a particular language.

The sample text may be a pangram, but is not necessarily. It is chosen to be demonstrative of normal text in the language, as well as exposing font feature requirements unique to the language. It is suitable for use as sample text in a font selection dialog.

If `language` is empty, the default language as found by pango_language_get_default() is used.

If Pango does not have a sample string for `language`, the classic "The quick brown fox..." is returned.

Types

type Alignment

type Alignment uint8

Alignment Describes how to align the lines of a `Layout` within the available space. If the `Layout` is set to justify using pango_layout_set_justify(), this only has effect for partial lines.

const (
	PANGO_ALIGN_LEFT   Alignment = iota // Put all available space on the right
	PANGO_ALIGN_CENTER                  // Center the line within the available space
	PANGO_ALIGN_RIGHT                   // Put all available space on the left
)

type Analysis

type Analysis struct {
	// contains filtered or unexported fields
}

Analysis stores information about the properties of a segment of text.

type ApplyAttrsState

type ApplyAttrsState struct {
	// contains filtered or unexported fields
}

type AttrColor

type AttrColor struct {
	Red, Green, Blue uint16
}

AttrColor is used to represent a color in an uncalibrated RGB color-space.

func (AttrColor) String

func (a AttrColor) String() string

String returns a textual specification of the color in the hexadecimal form '#rrrrggggbbbb', where r,g and b are hex digits representing the red, green, and blue components respectively.

type AttrData

type AttrData interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

AttrData stores the type specific value of an attribute.

type AttrFloat

type AttrFloat float64

func (AttrFloat) String

func (a AttrFloat) String() string

type AttrInt

type AttrInt int

func (AttrInt) String

func (a AttrInt) String() string

type AttrIterator

type AttrIterator struct {
	StartIndex, EndIndex int // index into the underlying text
	// contains filtered or unexported fields
}

AttrIterator is used to represent an iterator through an `AttrList`. A new iterator is created with pango_attr_list_get_iterator(). Once the iterator is created, it can be advanced through the style changes in the text using pango_attr_iterator_next(). At each style change, the range of the current style segment and the attributes currently in effect can be queried.

type AttrList

type AttrList []*Attribute

type AttrShape

type AttrShape struct {
	// contains filtered or unexported fields
}

AttrShape is used to represent attributes which impose shape restrictions.

func (AttrShape) String

func (a AttrShape) String() string

type AttrString

type AttrString string

func (AttrString) String

func (a AttrString) String() string

type AttrType

type AttrType uint8
const (
	ATTR_INVALID             AttrType = iota // does not happen
	ATTR_LANGUAGE                            // language (AttrLanguage)
	ATTR_FAMILY                              // font family name list (AttrString)
	ATTR_STYLE                               // font slant style (AttrInt)
	ATTR_WEIGHT                              // font weight (AttrInt)
	ATTR_VARIANT                             // font variant (normal or small caps) (AttrInt)
	ATTR_STRETCH                             // font stretch (AttrInt)
	ATTR_SIZE                                // font size in points scaled by %PANGO_SCALE (AttrInt)
	ATTR_FONT_DESC                           // font description (AttrFontDesc)
	ATTR_FOREGROUND                          // foreground color (AttrColor)
	ATTR_BACKGROUND                          // background color (AttrColor)
	ATTR_UNDERLINE                           // whether the text has an underline (AttrInt)
	ATTR_STRIKETHROUGH                       // whether the text is struck-through (AttrInt)
	ATTR_RISE                                // baseline displacement (AttrInt)
	ATTR_SHAPE                               // shape (AttrShape)
	ATTR_SCALE                               // font size scale factor (AttrFloat)
	ATTR_FALLBACK                            // whether fallback is enabled (AttrInt)
	ATTR_LETTER_SPACING                      // letter spacing (AttrInt)
	ATTR_UNDERLINE_COLOR                     // underline color (AttrColor)
	ATTR_STRIKETHROUGH_COLOR                 // strikethrough color (AttrColor)
	ATTR_ABSOLUTE_SIZE                       // font size in pixels scaled by %PANGO_SCALE (AttrInt)
	ATTR_GRAVITY                             // base text gravity (AttrInt)
	ATTR_GRAVITY_HINT                        // gravity hint (AttrInt)
	ATTR_FONT_FEATURES                       // OpenType font features (AttrString). Since 1.38
	ATTR_FOREGROUND_ALPHA                    // foreground alpha (AttrInt). Since 1.38
	ATTR_BACKGROUND_ALPHA                    // background alpha (AttrInt). Since 1.38
	ATTR_ALLOW_BREAKS                        // whether breaks are allowed (AttrInt). Since 1.44
	ATTR_SHOW                                // how to render invisible characters (AttrInt). Since 1.44
	ATTR_INSERT_HYPHENS                      // whether to insert hyphens at intra-word line breaks (AttrInt). Since 1.44
	ATTR_OVERLINE                            // whether the text has an overline (AttrInt). Since 1.46
	ATTR_OVERLINE_COLOR                      // overline color (AttrColor). Since 1.46
)

func (AttrType) String

func (t AttrType) String() string

type Attribute

type Attribute struct {
	Data AttrData
	Type AttrType
	// Indexes into the underlying rune slice (note that
	// we diverge here from the C library, which works on byte slices).
	// The character at `EndIndex` is not included in the range.
	StartIndex, EndIndex int
}

Attribute are used as the input to the itemization process and also when creating a `Layout`. The common portion of the attribute holds the range to which the value applies. By default an attribute will have an all-inclusive range of [0,maxInt].

func (Attribute) String

func (attr Attribute) String() string

type BreakResult

type BreakResult uint8
const (
	BREAK_NONE_FIT       BreakResult = iota // Couldn't fit anything.
	BREAK_SOME_FIT                          // The item was broken in the middle.
	BREAK_ALL_FIT                           // Everything fit.
	BREAK_EMPTY_FIT                         // Nothing fit, but that was ok, as we can break at the first char.
	BREAK_LINE_SEPARATOR                    // Item begins with a line separator.
)

type ChangedFlags

type ChangedFlags uint8
const (
	EMBEDDING_CHANGED ChangedFlags = 1 << iota
	SCRIPT_CHANGED
	LANG_CHANGED
	FONT_CHANGED
	DERIVED_LANG_CHANGED
	WIDTH_CHANGED
	EMOJI_CHANGED
)

type CharAttr

type CharAttr uint16

CharAttr stores information about the attributes of a single character.

const (
	LineBreak CharAttr = 1 << iota
	MandatoryBreak
	CharBreak
	White
	CursorPosition
	WordStart
	WordEnd
	SentenceBoundary
	SentenceStart
	SentenceEnd
	BackspaceDeletesCharacter
	ExpandableSpace
	WordBoundary
)

func GetLogAttrs

func GetLogAttrs(text []rune, level fribidi.Level) []CharAttr

GetLogAttrs computes a `CharAttr` for each character in `text`.

The returned array has one `CharAttr` for each position in `text`: if `text` contains N characters, it has N+1 positions, including the last position at the end of the text.

`text` should be an entire paragraph; logical attributes can't be computed without context (for example you need to see spaces on either side of a word to know the word is a word).

`level` is the embedding level; pass -1 if unknown

func (CharAttr) IsBackspaceDeletesCharacter

func (c CharAttr) IsBackspaceDeletesCharacter() bool

IsBackspaceDeletesCharacter returns true if backspace deletes one character rather than the entire grapheme cluster. This field is only meaningful on grapheme boundaries (where IsCursorPosition is set). In some languages, the full grapheme (e.g. letter + diacritics) is considered a unit, while in others, each decomposed character in the grapheme is a unit. In the default implementation of pangoDefaultBreak, this bit is set on all grapheme boundaries except those following Latin, Cyrillic or Greek base characters.

func (CharAttr) IsCharBreak

func (c CharAttr) IsCharBreak() bool

IsCharBreak returns true if one can break here when doing character wrapping

func (CharAttr) IsCursorPosition

func (c CharAttr) IsCursorPosition() bool

IsCursorPosition returns true if the cursor can appear in front of character. i.e. this is a grapheme boundary, or the first character in the text. This flag implements Unicode's http://www.unicode.org/reports/tr29/ Grapheme Cluster Boundaries semantics.

func (CharAttr) IsExpandableSpace

func (c CharAttr) IsExpandableSpace() bool

IsExpandableSpace checks if it is a whitespace character that can possibly be expanded for justification purposes.

func (CharAttr) IsLineBreak

func (c CharAttr) IsLineBreak() bool

IsLineBreak return true if one can break line in front of character

func (CharAttr) IsMandatoryBreak

func (c CharAttr) IsMandatoryBreak() bool

IsMandatoryBreak return true if one must break line in front of character

func (CharAttr) IsSentenceBoundary

func (c CharAttr) IsSentenceBoundary() bool

is a sentence boundary. There are two ways to divide sentences. The first assigns all inter-sentence whitespace/control/format chars to some sentence, so all chars are in some sentence; IsSentenceBoundary denotes the boundaries there. The second way doesn't assign between-sentence spaces, etc. to any sentence, so IsSentenceStart/IsSentenceEnd mark the boundaries of those sentences.

func (CharAttr) IsSentenceEnd

func (c CharAttr) IsSentenceEnd() bool

IsSentenceEnd checks if it is the first char after a sentence. Note that in degenerate cases, you could have both IsSentenceStart and IsSentenceEnd set for some character. (e.g. no space after a period, so the next sentence starts right away)

func (CharAttr) IsSentenceStart

func (c CharAttr) IsSentenceStart() bool

IsSentenceStart checks if it is the first character in a sentence

func (CharAttr) IsWhite

func (c CharAttr) IsWhite() bool

IsWhite checks if it is whitespace character

func (CharAttr) IsWordBoundary

func (c CharAttr) IsWordBoundary() bool

IsWordBoundary checks if it is a word boundary, as defined by UAX#29. More specifically, means that this is not a position in the middle of a word. For example, both sides of a punctuation mark are considered word boundaries. This flag is particularly useful when selecting text word-by-word. This flag implements Unicode's http://www.unicode.org/reports/tr29/ Word Boundaries semantics.

func (CharAttr) IsWordEnd

func (c CharAttr) IsWordEnd() bool

IsWordEnd checks if it is the first non-word char after a word

	Note that in degenerate cases, you could have both IsWordStart
 and IsWordEnd set for some character.

func (CharAttr) IsWordStart

func (c CharAttr) IsWordStart() bool

IsWordStart checks if it is the first character in a word

type Context

type Context struct {
	Matrix *Matrix
	// contains filtered or unexported fields
}

Context stores global information used to control the itemization process.

func NewContext

func NewContext(fontmap FontMap) *Context

NewContext creates a `Context` connected to `fontmap`, and initialized to default values.

func (*Context) GetLanguage

func (context *Context) GetLanguage() Language

GetLanguage retrieves the global language tag for the context.

func (*Context) SetLanguage

func (context *Context) SetLanguage(language Language)

SetLanguage sets the global language tag for the context. The default language for the locale of the running process can be found using pango_language_get_default().

type Coverage

type Coverage interface {
	// Get returns true if the rune is covered
	Get(index rune) bool
	Set(index rune, covered bool)
}

Coverage represents a set of Unicode characters. Conceptually, it is a map[rune]bool, but it can be implemented much more efficiently

type Direction

type Direction uint8

The Direction type represents a direction in the Unicode bidirectional algorithm.

Not every value in this enumeration makes sense for every usage of Direction; for example, the return value of pango_unichar_direction() and pango_find_baseDir() cannot be `PANGO_DIRECTION_WEAK_LTR` or `PANGO_DIRECTION_WEAK_RTL`, since every character is either neutral or has a strong direction; on the other hand `PANGO_DIRECTION_NEUTRAL` doesn't make sense to pass to pango_itemize_with_baseDir().

See `Gravity` for how vertical text is handled in Pango.

If you are interested in text direction, you should really use fribidi directly. Direction is only retained because it is used in some public apis.

const (
	PANGO_DIRECTION_LTR Direction = iota // A strong left-to-right direction
	PANGO_DIRECTION_RTL                  // A strong right-to-left direction

	PANGO_DIRECTION_WEAK_LTR // A weak left-to-right direction
	PANGO_DIRECTION_WEAK_RTL // A weak right-to-left direction
	PANGO_DIRECTION_NEUTRAL  // No direction specified
)

type EllipsizeMode

type EllipsizeMode uint8

EllipsizeMode Describes what sort of (if any) ellipsization should be applied to a line of text. In the ellipsization process characters are removed from the text in order to make it fit to a given width and replaced with an ellipsis.

const (
	PANGO_ELLIPSIZE_NONE   EllipsizeMode = iota // No ellipsization
	PANGO_ELLIPSIZE_START                       // Omit characters at the start of the text
	PANGO_ELLIPSIZE_MIDDLE                      // Omit characters in the middle of the text
	PANGO_ELLIPSIZE_END                         // Omit characters at the end of the text
)

type EllipsizeState

type EllipsizeState struct {
	// contains filtered or unexported fields
}

state of ellipsization process

type EmojiIter

type EmojiIter struct {
	// contains filtered or unexported fields
}

type Fl

type Fl = float64

type Font

type Font interface {
	// Describe returns a description of the font.
	// The font size set in points, unless `absolute` is true,
	// meaning the font size is in device units.
	Describe(absolute bool) FontDescription

	// GetCoverage computes the coverage map for a given font and language tag.
	GetCoverage(language Language) Coverage

	// GlyphExtents gets the logical and ink extents of a glyph within a font. The
	// coordinate system for each rectangle has its origin at the
	// base line and horizontal origin of the character with increasing
	// coordinates extending to the right and down. The units
	// of the rectangles are in 1/PANGO_SCALE of a device unit.
	GlyphExtents(glyph Glyph, inkRect, logicalRect *Rectangle)

	// GetMetrics gets overall metric information for a font. Since the metrics may be
	// substantially different for different scripts, a language tag can
	// be provided to indicate that the metrics should
	// correspond to the script(s) used by that language.
	GetMetrics(language Language) FontMetrics

	// Gets the font map for which the font was created.
	GetFontMap() FontMap

	// Note that this does not include OpenType features which the
	// rendering system enables by default.
	GetFeatures() []harfbuzz.Feature

	// GetHBFont returns a hb_font_t object backing this font.
	// Implementations should create the font once and cache it.
	GetHBFont() *harfbuzz.Font
}

Font is used to represent a font in a rendering-system-independent matter. The concretes types implementing this interface MUST be valid map keys.

type FontCache

type FontCache struct {
	// contains filtered or unexported fields
}

we could maybe use a sync.Map ?

func NewFontCache

func NewFontCache() *FontCache

NewFontCache initialize a new font cache.

type FontDescription

type FontDescription struct {
	FamilyName string
	Variations string
	Weight     Weight
	Size       int

	Variant        Variant
	Stretch        Stretch
	Gravity        Gravity
	Style          Style
	SizeIsAbsolute bool
	// contains filtered or unexported fields
}

FontDescription represents the description of an ideal font. These structures are used both to list what fonts are available on the system and also for specifying the characteristics of a font to load.

This struct track the modifications to its field via a bit mask. Thus, the SetXXX methods should be used to mutate it.

This struct does not hold any pointer types: it can be copied by value.

func NewFontDescription

func NewFontDescription() FontDescription

NewFontDescription creates a new font description structure with all fields unset, but with default values.

func (FontDescription) AsHash

func (desc FontDescription) AsHash() FontDescription

AsHash returns a FontDescription suitable to be used as map key. In particular, the family_name is lowered, and `mask` is ignored.

func (*FontDescription) SetAbsoluteSize

func (desc *FontDescription) SetAbsoluteSize(size int)

Sets the size field of a font description, in device units. `size` is the new size, in Pango units. There are `PangoScale` Pango units in one device unit. For an output backend where a device unit is a pixel, a `size` value of 10 * PangoScale gives a 10 pixel font.

This is mutually exclusive with SetSize() which sets the font size in points.

func (*FontDescription) SetSize

func (desc *FontDescription) SetSize(size int)

Sets the size field of a font description in fractional points. `size` is the size of the font in points, scaled by PangoScale. That is, a `size` value of 10 * PangoScale 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.

This is mutually exclusive with SetAbsoluteSize(), to use if you need a particular size in device units

func (*FontDescription) Setfamily

func (desc *FontDescription) Setfamily(family string)

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 `FontFamily`. In some uses of `FontDescription`, it is also possible to use a comma separated list of family names for this field.

func (*FontDescription) Setgravity

func (desc *FontDescription) Setgravity(gravity Gravity)

Setgravity sets the gravity field of a font description. The gravity field specifies how the glyphs should be rotated. If @gravity is %PANGO_GRAVITY_AUTO, this actually unsets the gravity mask on the font description.

func (*FontDescription) Setstretch

func (desc *FontDescription) Setstretch(stretch Stretch)

Sets the stretch field of a font description. The stretch field specifies how narrow or wide the font should be.

func (*FontDescription) Setstyle

func (desc *FontDescription) Setstyle(style Style)

Sets the style field of a FontDescription. The Style enumeration Describes whether the font is slanted and the manner in which it is slanted; it can be either `STYLE_NORMAL`, `STYLE_ITALIC`, or `STYLE_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.

func (*FontDescription) Setvariant

func (desc *FontDescription) Setvariant(variant Variant)

Sets the variant field of a font description. The variant can either be `VARIANT_NORMAL` or `VARIANT_SMALL_CAPS`.

func (*FontDescription) Setvariations

func (desc *FontDescription) Setvariations(variations string)

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 or freetype have API for this.

func (*FontDescription) Setweight

func (desc *FontDescription) Setweight(weight Weight)

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 Weight enumeration, other intermediate numeric values are possible.

func (FontDescription) String

func (desc FontDescription) String() string

Creates a string representation of a font description. 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.

func (*FontDescription) UnsetFields

func (desc *FontDescription) UnsetFields(toUnset FontMask)

Unsets some of the fields in a `FontDescription`. The unset fields will get back to their default values.

type FontMap

type FontMap interface {
	// Load a set of fonts in the fontmap that can be used to render a font matching `desc`.
	// Returns nil if no font matched.
	LoadFontset(context *Context, desc *FontDescription, language Language) Fontset

	// Returns the current serial number of the fontmap.  The serial number is
	// initialized to an small number larger than zero when a new fontmap
	// is created and is increased whenever the fontmap is changed. It may
	// wrap, but will never have the value 0. Since it can wrap, never compare
	// it with "less than", always use "not equals".
	//
	// The fontmap can only be changed using backend-specific API, like changing
	// fontmap resolution.
	GetSerial() uint
}

FontMap represents the set of fonts available for a particular rendering system. It is the top-level object of all font access. From a FontMap, a font set is loaded.

The concretes types implementing this interface MUST be valid map keys.

type FontMask

type FontMask uint16

FontMask bits correspond to fields in a `FontDescription` that have been set.

const (
	F_FAMILY     FontMask = 1 << iota // the font family is specified.
	F_STYLE                           // the font style is specified.
	F_VARIANT                         // the font variant is specified.
	F_WEIGHT                          // the font weight is specified.
	F_STRETCH                         // the font stretch is specified.
	F_SIZE                            // the font size is specified.
	F_GRAVITY                         // the font gravity is specified (Since: 1.16.)
	F_VARIATIONS                      // OpenType font variations are specified (Since: 1.42)
)

type FontMetrics

type FontMetrics struct {
	// Distance from the baseline to the logical top of a line of text.
	// (The logical top may be above or below the top of the
	// actual drawn ink. It is necessary to lay out the text to figure
	// where the ink will be.)
	Ascent int32

	// Distance from the baseline to the logical bottom of a line of text.
	// (The logical bottom may be above or below the bottom of the
	// actual drawn ink. It is necessary to lay out the text to figure
	// where the ink will be.)
	Descent int32

	// Distance between successive baselines in wrapped text.
	Height int32

	// Representative value useful for example for
	// determining the initial size for a window. Actual characters in
	// text will be wider and narrower than this.
	ApproximateCharWidth int

	// Same as `approximate_char_width` but for digits.
	// This value is generally somewhat more accurate than `approximate_char_width` for digits.
	ApproximateDigitWidth int

	// Distance above the baseline of the top of the underline.
	// Since most fonts have underline positions beneath the baseline, this value is typically negative.
	UnderlinePosition int32

	// Suggested thickness to draw for the underline.
	UnderlineThickness int32

	// Distance above the baseline of the top of the strikethrough.
	StrikethroughPosition int32
	// Suggested thickness to draw for the strikethrough.
	StrikethroughThickness int32
}

FontMetrics holds the overall metric information for a font (possibly restricted to a script). All values are expressed in Pango units.

func FontGetMetrics

func FontGetMetrics(font Font, language Language) FontMetrics

FontGetMetrics gets overall metric information for a font. 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.

If `font` is `nil`, this function gracefully returns some sane values.

type Fontset

type Fontset interface {
	// Returns the language of the Fontset
	GetLanguage() Language

	// Iterates through all the fonts in a Fontset, calling `fn` for each one.
	// If `fn` returns `true`, that stops the iteration.
	Foreach(fn FontsetForeachFunc)
}

Fontset represents a set of Font to use when rendering text. It is the result of resolving a FontDescription against a particular Context. The concretes types implementing this interface MUST be valid map keys.

type FontsetForeachFunc

type FontsetForeachFunc = func(font Font) bool

Returns `true` stops the iteration

type Glyph

type Glyph uint32

Glyph represents a single glyph in the output form of a str. The low bytes stores the glyph index.

const (
	// The `PANGO_GLYPH_EMPTY` macro represents a `Glyph` value that has a
	// special meaning, which is a zero-width empty glyph. This is useful for
	// example in shaper modules, to use as the glyph for various zero-width
	// Unicode characters (those passing pango_is_zero_width()).
	PANGO_GLYPH_EMPTY Glyph = 0x0FFFFFFF

	// The `PANGO_GLYPH_INVALID_INPUT` macro represents a `Glyph` value that has a
	// special meaning of invalid input. `Layout` produces one such glyph
	// per invalid input UTF-8 byte and such a glyph is rendered as a crossed
	// box.
	//
	// Note that this value is defined such that it has the `PANGO_GLYPH_UNKNOWN_FLAG` on.
	PANGO_GLYPH_INVALID_INPUT Glyph = 0xFFFFFFFF

	// The `PANGO_GLYPH_UNKNOWN_FLAG` macro is a flag value that can be added to
	// a rune value of a valid Unicode character, to produce a `Glyph`
	// value, representing an unknown-character glyph for the respective rune.
	PANGO_GLYPH_UNKNOWN_FLAG = 0x10000000
)

func AsUnknownGlyph

func AsUnknownGlyph(wc rune) Glyph

AsUnknownGlyph returns a `Glyph` value that means no glyph was found for `wc`.

The way this unknown glyphs are rendered is backend specific. For example, a box with the hexadecimal Unicode code-point of the character written in it is what is done in the most common backends.

func (Glyph) GID

func (g Glyph) GID() fonts.GID

type GlyphGeometry

type GlyphGeometry struct {
	Width GlyphUnit // the logical width to use for the the character.
	// contains filtered or unexported fields
}

GlyphGeometry contains width and positioning information for a single glyph.

type GlyphInfo

type GlyphInfo struct {
	Geometry GlyphGeometry // the positional information about the glyph.
	// contains filtered or unexported fields
}

GlyphInfo represents a single glyph together with positioning information and visual attributes.

type GlyphItem

type GlyphItem struct {
	Glyphs *GlyphString
	// contains filtered or unexported fields
}

GlyphItem is a pair of a Item and the glyphs resulting from shaping the text corresponding to an item. As an example of the usage of GlyphItem, the results of shaping text with Layout is a list of LayoutLine, each of which contains a list of GlyphItem.

func (GlyphItem) LTR

func (g GlyphItem) LTR() bool

type GlyphItemIter

type GlyphItemIter struct {
	// contains filtered or unexported fields
}

GlyphItemIter is an iterator over the clusters in a `GlyphItem`. The forward direction of the iterator is the logical direction of text. That is, with increasing `start_index` and `start_char` values. If `glyphItem` is right-to-left (that is, if `glyphItem.item.analysis.level` is odd), then `start_glyph` decreases as the iterator moves forward. Moreover, in right-to-left cases, `start_glyph` is greater than `end_glyph`.

An iterator should be initialized using either of `pango_glyph_item_iter_init_start()` and `pango_glyph_item_iter_init_end()`, for forward and backward iteration respectively, and walked over using any desired mixture of `pango_glyph_item_iter_next_cluster()` and `pango_glyph_item_iter_prev_cluster()`.

Note that `text` is the start of the text to layout, which is then indexed by `glyphItem.item.offset` to get to the text of `glyphItem`. The `start_index` and `end_index` values can directly index into `text`. The `start_glyph`, `end_glyph`, `start_char`, and `end_char` values however are zero-based for the `glyphItem`. For each cluster, the item pointed at by the start variables is included in the cluster while the one pointed at by end variables is not.

type GlyphString

type GlyphString struct {
	// array of glyph information for the glyph string
	// with size num_glyphs
	Glyphs []GlyphInfo
	// contains filtered or unexported fields
}

GlyphString structure is used to store strings of glyphs with geometry and visual attribute information - ready for drawing

type GlyphUnit

type GlyphUnit int32

GlyphUnit is used to store dimensions within Pango. Dimensions are stored in 1/PangoScale of a device unit. (A device unit might be a pixel for screen display, or a point on a printer.) PangoScale is currently 1024, and may change in the future (unlikely though), but you should not depend on its exact value. .

func (GlyphUnit) Pixels

func (g GlyphUnit) Pixels() int

Pixels converts from glyph units into device units with correct rounding.

func (GlyphUnit) Round

func (d GlyphUnit) Round() GlyphUnit

Round rounds a dimension to whole device units, but does not convert it to device units.

type GlyphVisAttr

type GlyphVisAttr struct {
	// contains filtered or unexported fields
}

GlyphVisAttr is used to communicate information between the shaping phase and the rendering phase. More attributes may be added in the future.

type Gravity

type Gravity uint8

Gravity represents the orientation of glyphs in a segment of text. This is useful when rendering vertical text layouts. In those situations, the layout is rotated using a non-identity PangoMatrix, and then glyph orientation is controlled using Gravity.

Not every value in this enumeration makes sense for every usage of Gravity; for example, `PANGO_GRAVITY_AUTO` only can be passed to pango_context_set_base_gravity() and can only be returned by pango_context_get_base_gravity().

See also: GravityHint

const (
	PANGO_GRAVITY_SOUTH Gravity = iota // Glyphs stand upright (default)
	PANGO_GRAVITY_EAST                 // Glyphs are rotated 90 degrees clockwise
	PANGO_GRAVITY_NORTH                // Glyphs are upside-down
	PANGO_GRAVITY_WEST                 // Glyphs are rotated 90 degrees counter-clockwise
	PANGO_GRAVITY_AUTO                 // Gravity is resolved from the context matrix
)

func (Gravity) IsImproper

func (gravity Gravity) IsImproper() bool

IsImproper returns whether a `Gravity` represents a gravity that results in reversal of text direction.

func (Gravity) IsVertical

func (g Gravity) IsVertical() bool

whether `g` represents vertical writing directions.

type GravityHint

type GravityHint uint8

GravityHint defines how horizontal scripts should behave in a vertical context. That is, English excerpt in a vertical paragraph for example.

const (
	PANGO_GRAVITY_HINT_NATURAL GravityHint = iota // scripts will take their natural gravity based on the base gravity and the script
	PANGO_GRAVITY_HINT_STRONG                     // always use the base gravity set, regardless of the script
	// For scripts not in their natural direction (eg.
	// Latin in East gravity), choose per-script gravity such that every script
	// respects the line progression.  This means, Latin and Arabic will take
	// opposite gravities and both flow top-to-bottom for example.
	PANGO_GRAVITY_HINT_LINE
)

type Item

type Item struct {
	// contains filtered or unexported fields
}

Item stores information about a segment of text.

type ItemProperties

type ItemProperties struct {
	// contains filtered or unexported fields
}

Note that rise, letter_spacing, shape are constant across items, since we pass them into itemization.

uline and strikethrough can vary across an item, so we collect all the values that we find.

type ItemizeState

type ItemizeState struct {
	// contains filtered or unexported fields
}

type Language

type Language = language.Language

type Layout

type Layout struct {
	// contains filtered or unexported fields
}

Layout represents an entire paragraph of text. It is initialized with a #PangoContext, UTF-8 string and set of attributes for that string. Once that is done, the set of formatted lines can be extracted from the object, the layout can be rendered, and conversion between logical character positions within the layout's text, and the physical position of the resulting glyphs can be made.

There are also a number of parameters to adjust the formatting of a #Layout, which are illustrated in <xref linkend="parameters"/>. It is possible, as well, to ignore the 2-D setup, and simply treat the results of a #Layout as a list of lines.

<figure id="parameters"> <title>Adjustable parameters (on the left) and font metrics (on the right) for a Layout</title> <graphic fileref="layout.png" format="PNG"></graphic> </figure>

func NewLayout

func NewLayout(context *Context) *Layout

NewLayout creates a new `Layout` object with attributes initialized to default values for a particular `Context`.

func (*Layout) GetExtents

func (layout *Layout) GetExtents(inkRect, logicalRect *Rectangle)

GetExtents computes the ink and logical extents of `layout`. Logical extents are usually what you want for positioning things. Note that both extents may have non-zero x and y. You may want to use those to offset where you render the layout. Not doing that is a very typical bug that shows up as right-to-left layouts not being correctly positioned in a layout with a set width.

The extents are given in layout coordinates and in Pango units; layout coordinates begin at the top left corner of the layout. Pass `nil` is you dont need one of the extents.

func (*Layout) GetLinesReadonly

func (layout *Layout) GetLinesReadonly() []*LayoutLine

GetLinesReadonly is a faster alternative to pango_layout_get_lines(), but the user must not modify the contents of the lines (glyphs, glyph widths, etc.).

The returned lines will become invalid on any change to the layout's text or properties.

func (*Layout) SetFontDescription

func (layout *Layout) SetFontDescription(desc *FontDescription)

SetFontDescription sets the default font description for the layout. If `nil`, the font description from the layout's context is used.

func (*Layout) SetText

func (layout *Layout) SetText(text string)

SetText sets the text of the layout, validating `text` and rendering invalid UTF-8 with a placeholder glyph.

Note that if you have used pango_layout_set_markup() or pango_layout_set_markup_with_accel() on @layout before, you may want to call pango_layout_set_attributes() to clear the attributes set on the layout from the markup as this function does not clear attributes.

type LayoutLine

type LayoutLine struct {
	// contains filtered or unexported fields
}

LayoutLine represents one of the lines resulting from laying out a paragraph via `Layout`. `LayoutLine` structures are only valid until the text, attributes, or settings of the parent `Layout` are modified.

type LineIter

type LineIter struct {
	// contains filtered or unexported fields
}

iterator to a position within the ellipsized line

type Matrix

type Matrix struct {
	Xx, Xy, Yx, Yy, X0, Y0 Fl
}

Matrix is a transformation between user-space coordinates and device coordinates. The transformation is given by

x_device = x_user * matrix.xx + y_user * matrix.xy + matrix.x0; y_device = x_user * matrix.yx + y_user * matrix.yy + matrix.y0;

func (Matrix) GetFontScaleFactors

func (matrix Matrix) GetFontScaleFactors() (xscale, yscale Fl)

GetFontScaleFactors calculates the scale factor of a matrix on the width and height of the font. That is, `xscale` is the scale factor in the direction of the X coordinate, and `yscale` is the scale factor in the direction perpendicular to the vector that the X coordinate is mapped to.

Note that output numbers will always be non-negative.

type Overline

type Overline uint8

Overline is used to specify whether text should be overlined, and if so, the type of line.

const (
	PANGO_OVERLINE_NONE   Overline = iota // no overline should be drawn
	PANGO_OVERLINE_SINGLE                 // Draw a single line above the ink extents of the text being underlined.
)

type ParaBreakState

type ParaBreakState struct {
	// contains filtered or unexported fields
}

type ParenStackEntry

type ParenStackEntry struct {
	// contains filtered or unexported fields
}

type ParsedMarkup

type ParsedMarkup struct {
	Attr      AttrList
	Text      []rune // Text with tags stripped
	AccelChar rune   // Accelerator char
}

Simple markup language for text with attributes

Frequently, you want to display some text to the user with attributes applied to part of the text (for example, you might want bold or italicized words). With the base Pango interfaces, you could create a `AttrList` and apply it to the text; the problem is that you'd need to apply attributes to some numeric range of characters, for example "characters 12-17." This is broken from an internationalization standpoint; once the text is translated, the word you wanted to italicize could be in a different position.

The solution is to include the text attributes in the string to be translated. Pango provides this feature with a small markup language. You can parse a marked-up string into the string text plus a `AttrList` using pango_parse_markup()

A simple example of a marked-up string might be:

<span foreground="blue" size="x-large">Blue text</span> is <i>cool</i>!

Pango uses #GMarkup to parse this language, which means that XML features such as numeric character entities such as `&#169;` for © can be used too.

The root tag of a marked-up document is `<markup>`, but pango_parse_markup() allows you to omit this tag, so you will most likely never need to use it. The most general markup tag is `<span>`, then there are some convenience tags.

## Span attributes

`<span>` has the following attributes:

  • `font_desc`: A font description string, such as "Sans Italic 12". See pango_font_description_from_string() for a description of the format of the string representation . Note that any other span attributes will override this description. So if you have "Sans Italic" and also a `style="normal"` attribute, you will get Sans normal, not italic.
  • `font_family`: A font family name
  • `font_size`, `size`: Font size in 1024ths of a point, or one of the absolute sizes `xx-small`, `x-small`, `small`, `medium`, `large`, `x-large`, `xx-large`, or one of the relative sizes `smaller` or `larger`. If you want to specify a absolute size, it's usually easier to take advantage of the ability to specify a partial font description using `font`; you can use `font='12.5'` rather than `size='12800'`.
  • `font_style`: One of `normal`, `oblique`, `italic`
  • `font_weight`: One of `ultralight`, `light`, `normal`, `bold`, `ultrabold`, `heavy`, or a numeric weight
  • `font_variant`: One of `normal` or `smallcaps`
  • `font_stretch`, `stretch`: One of `ultracondensed`, `extracondensed`, `condensed`, `semicondensed`, `normal`, `semiexpanded`, `expanded`, `extraexpanded`, `ultraexpanded`
  • `font_features`: A comma-separated list of OpenType font feature settings, in the same syntax as accepted by CSS. E.g: `font_features='dlig=1, -kern, afrc on'`
  • `foreground`, `fgcolor`: An RGB color specification such as `#00FF00` or a color name such as `red`. Since 1.38, an RGBA color specification such as `#00FF007F` will be interpreted as specifying both a foreground color and foreground alpha.
  • `background`, `bgcolor`: An RGB color specification such as `#00FF00` or a color name such as `red`. Since 1.38, an RGBA color specification such as `#00FF007F` will be interpreted as specifying both a background color and background alpha.
  • `alpha`, `fgalpha`: An alpha value for the foreground color, either a plain integer between 1 and 65536 or a percentage value like `50%`.
  • `background_alpha`, `bgalpha`: An alpha value for the background color, either a plain integer between 1 and 65536 or a percentage value like `50%`.
  • `underline`: One of `none`, `single`, `double`, `low`, `error`, `single-line`, `double-line` or `error-line`.
  • `underline_color`: The color of underlines; an RGB color specification such as `#00FF00` or a color name such as `red`
  • `overline`: One of `none` or `single`
  • `overline_color`: The color of overlines; an RGB color specification such as `#00FF00` or a color name such as `red`
  • `rise`: Vertical displacement, in Pango units. Can be negative for subscript, positive for superscript.
  • `strikethrough` `true` or `false` whether to strike through the text
  • `strikethrough_color`: The color of strikethrough lines; an RGB color specification such as `#00FF00` or a color name such as `red`
  • `fallback`: `true` or `false` whether to enable fallback. If disabled, then characters will only be used from the closest matching font on the system. No fallback will be done to other fonts on the system that might contain the characters in the text. Fallback is enabled by default. Most applications should not disable fallback.
  • `allow_breaks`: `true` or `false` whether to allow line breaks or not. If not allowed, the range will be kept in a single run as far as possible. Breaks are allowed by default.
  • `insert_hyphens`:` `true` or `false` whether to insert hyphens when breaking lines in the middle of a word. Hyphens are inserted by default.
  • `show`: A value determining how invisible characters are treated. Possible values are `spaces`, `line-breaks`, `ignorables` or combinations, such as `spaces|line-breaks`.
  • `lang`: A language code, indicating the text language
  • `letter_spacing`: Inter-letter spacing in 1024ths of a point.
  • `gravity`: One of `south`, `east`, `north`, `west`, `auto`.
  • `gravity_hint`: One of `natural`, `strong`, `line`.

## Convenience tags

The following convenience tags are provided:

  • `<b>`: Bold
  • `<big>`: Makes font relatively larger, equivalent to `<span size="larger">`
  • `<i>`: Italic
  • `<s>`: Strikethrough
  • `<sub>`: Subscript
  • `<sup>`: Superscript
  • `<small>`: Makes font relatively smaller, equivalent to `<span size="smaller">`
  • `<tt>`: Monospace
  • `<u>`: Underline

type Rectangle

type Rectangle struct {
	X      int32 // X coordinate of the left side of the rectangle.
	Y      int32 // Y coordinate of the the top side of the rectangle.
	Width  int32 // width of the rectangle.
	Height int32 // height of the rectangle.
}

Rectangle represents a rectangle. It is frequently used to represent the logical or ink extents of a single glyph or section of text. (See, for instance, pango_font_get_glyph_extents())

type RunInfo

type RunInfo struct {
	// contains filtered or unexported fields
}

keeps information about a single run

type RunList

type RunList struct {
	Data *GlyphItem
	Next *RunList
}

RunList is a linked list of `GlypmItem`

type Script

type Script = language.Script

type ScriptIter

type ScriptIter struct {
	// contains filtered or unexported fields
}

ScriptIter is used to break a string of Unicode text into runs by Unicode script.

The range to which the iterator currently points, is the set of indexes `i` where `script_start` <= i < `script_end`. That is, it doesn't include the character stored at `script_end`.

type ScriptProperties

type ScriptProperties struct {
	// contains filtered or unexported fields
}

type ShapeFlags

type ShapeFlags uint8

ShapeFlags influences the shaping process. These can be passed to pango_shape_with_flags().

const (
	PANGO_SHAPE_NONE ShapeFlags = 0 // Default value.
	// Round glyph positions and widths to whole device units. This option should
	// be set if the target renderer can't do subpixel positioning of glyphs.
	PANGO_SHAPE_ROUND_POSITIONS ShapeFlags = 1
)

type ShowFlags

type ShowFlags uint8

ShowFlags affects how Pango treats characters that are normally not visible in the output.

const (
	PANGO_SHOW_NONE        ShowFlags = 0         //  No special treatment for invisible characters
	PANGO_SHOW_SPACES      ShowFlags = 1 << iota //  Render spaces, tabs and newlines visibly
	PANGO_SHOW_LINE_BREAKS                       //  Render line breaks visibly
	PANGO_SHOW_IGNORABLES                        //  Render default-ignorable Unicode characters visibly
)

type Stretch

type Stretch uint8

Stretch specifies the width of the font relative to other designs within a family.

const (
	STRETCH_ULTRA_CONDENSED Stretch = iota // ultra condensed width
	STRETCH_EXTRA_CONDENSED                // extra condensed width
	STRETCH_CONDENSED                      // condensed width
	STRETCH_SEMI_CONDENSED                 // semi condensed width
	STRETCH_NORMAL                         // the normal width
	STRETCH_SEMI_EXPANDED                  // semi expanded width
	STRETCH_EXPANDED                       // expanded width
	STRETCH_EXTRA_EXPANDED                 // extra expanded width
	STRETCH_ULTRA_EXPANDED                 // ultra expanded width
)

type Style

type Style uint8

Style specifies the various slant styles possible for a font.

const (
	STYLE_NORMAL  Style = iota //  the font is upright.
	STYLE_OBLIQUE              //  the font is slanted, but in a roman style.
	STYLE_ITALIC               //  the font is slanted in an italic style.
)

type Tab

type Tab struct {
	// contains filtered or unexported fields
}

type TabAlign

type TabAlign uint8

A TabAlign specifies where a tab stop appears relative to the text

const (
	PANGO_TAB_LEFT TabAlign = iota // the tab stop appears to the left of the text

)

type TabArray

type TabArray struct {
	// contains filtered or unexported fields
}

*

  • TabArray: *
  • A #TabArray struct contains an array
  • of tab stops. Each tab stop has an alignment and a position.

type Underline

type Underline uint8

Underline enumeration is used to specify whether text should be underlined, and if so, the type of underlining.

const (
	PANGO_UNDERLINE_NONE   Underline = iota // no underline should be drawn
	PANGO_UNDERLINE_SINGLE                  // a single underline should be drawn
	PANGO_UNDERLINE_DOUBLE                  // a double underline should be drawn
	// a single underline should be drawn at a
	// position beneath the ink extents of the text being
	// underlined. This should be used only for underlining
	// single characters, such as for keyboard accelerators.
	// PANGO_UNDERLINE_SINGLE should be used for extended
	// portions of text.
	PANGO_UNDERLINE_LOW
	// a wavy underline should be drawn below.
	// This underline is typically used to indicate an error such
	// as a possible mispelling; in some cases a contrasting color
	// may automatically be used.
	PANGO_UNDERLINE_ERROR
	PANGO_UNDERLINE_SINGLE_LINE // like PANGO_UNDERLINE_SINGLE, but drawn continuously across multiple runs.
	PANGO_UNDERLINE_DOUBLE_LINE // like PANGO_UNDERLINE_DOUBLE, but drawn continuously across multiple runs.
	PANGO_UNDERLINE_ERROR_LINE  // like PANGO_UNDERLINE_ERROR, but drawn continuously across multiple runs.
)

type Variant

type Variant uint8

Variant specifies capitalization variant of the font.

const (
	PANGO_VARIANT_NORMAL     Variant = iota // A normal font.
	PANGO_VARIANT_SMALL_CAPS                // A font with the lower case characters replaced by smaller variants of the capital characters.
)

type Weight

type Weight int

Weight specifies the weight (boldness) of a font. This is a numerical value ranging from 100 to 1000, but there are some predefined values:

const (
	PANGO_WEIGHT_THIN       Weight = 100  // the thin weight (= 100; Since: 1.24)
	PANGO_WEIGHT_ULTRALIGHT Weight = 200  // the ultralight weight (= 200)
	PANGO_WEIGHT_LIGHT      Weight = 300  // the light weight (= 300)
	PANGO_WEIGHT_SEMILIGHT  Weight = 350  // the semilight weight (= 350; Since: 1.36.7)
	PANGO_WEIGHT_BOOK       Weight = 380  // the book weight (= 380; Since: 1.24)
	PANGO_WEIGHT_NORMAL     Weight = 400  // the default weight (= 400)
	PANGO_WEIGHT_MEDIUM     Weight = 500  // the normal weight (= 500; Since: 1.24)
	PANGO_WEIGHT_SEMIBOLD   Weight = 600  // the semibold weight (= 600)
	PANGO_WEIGHT_BOLD       Weight = 700  // the bold weight (= 700)
	PANGO_WEIGHT_ULTRABOLD  Weight = 800  // the ultrabold weight (= 800)
	PANGO_WEIGHT_HEAVY      Weight = 900  // the heavy weight (= 900)
	PANGO_WEIGHT_ULTRAHEAVY Weight = 1000 // the ultraheavy weight (= 1000; Since: 1.24)
)

type WidthIter

type WidthIter struct {
	// contains filtered or unexported fields
}

type WrapMode

type WrapMode uint8

WrapMode Describes how to wrap the lines of a `Layout` to the desired width.

const (
	PANGO_WRAP_WORD      WrapMode = iota // wrap lines at word boundaries.
	PANGO_WRAP_CHAR                      // wrap lines at character boundaries.
	PANGO_WRAP_WORD_CHAR                 // wrap lines at word boundaries, but fall back to character boundaries if there is not enough space for a full word.
)

Directories

Path Synopsis
Package fcfonts is an implementation of the font tooling required by Pango, using textlayout/fontconfig and textlayout/fonts.
Package fcfonts is an implementation of the font tooling required by Pango, using textlayout/fontconfig and textlayout/fonts.
gen command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL