pango

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: LGPL-2.1, LGPL-2.1 Imports: 19 Imported by: 2

Documentation

Overview

Package pango is a port of the C library, which provides international text layout.

Index

Constants

View Source
const (
	ScaleXxsmall = 0.5787037037037 //  The scale factor for three shrinking steps (1 / (1.2 * 1.2 * 1.2)).
	ScaleXsmall  = 0.6944444444444 //  The scale factor for two shrinking steps (1 / (1.2 * 1.2)).
	ScaleSmall   = 0.8333333333333 //  The scale factor for one shrinking step (1 / 1.2).
	ScaleMedium  = 1.0             //  The scale factor for normal size (1.0).
	ScaleLarge   = 1.2             //  The scale factor for one magnification step (1.2).
	ScaleXLarge  = 1.44            //  The scale factor for two magnification steps (1.2 * 1.2).
	ScaleXxLarge = 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.
	AFCenterdBaseline uint8 = 1 << iota
	// Used to mark runs that hold ellipsized text in an ellipsized layout
	AFIsEllipsis
	// Add an hyphen at the end of the run during shaping
	AFNeedHyphen
)
View Source
const MaxInt = math.MaxInt32

MaxInt is used as a sentinel value to represent unbounded ranges.

View Source
const Scale = 1024

Scale 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.) Scale 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.

Variables

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 */},
}

GravityMap exposes the string representation for the Graviy values.

View Source
var Identity = Matrix{1, 0, 0, 1, 0, 0}
View Source
var StretchMap = 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 */},
	{/* 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 */},
	{/* contains filtered or unexported fields */},
	{/* contains filtered or unexported fields */},
}

StretchMap provides string identifier for the Stretch enumeration.

View Source
var StyleMap = 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 */},
}

StyleMap provides string identifier for the Style enumeration.

Functions

func SampleString

func SampleString(lang Language) string

SampleString 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 DefaultLanguage() 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 SetJustify(), this only has effect for partial lines.

const (
	ALIGN_LEFT   Alignment = iota // Put all available space on the right
	ALIGN_CENTER                  // Center the line within the available space
	ALIGN_RIGHT                   // Put all available space on the left
)

type Analysis

type Analysis struct {
	Font Font // the font for this segment.

	Language   Language // the detected language for this segment.
	ExtraAttrs AttrList // extra attributes for this segment.
	Script     Script   // the detected script for this segment

	Level   fribidi.Level //  the bidirectional level for this segment.
	Gravity Gravity       //  the glyph orientation for this segment.
	Flags   uint8         //  boolean flags for this segment.
}

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

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 Fl

AttrFloat is a float

func (AttrFloat) String

func (a AttrFloat) String() string

type AttrInt

type AttrInt int

AttrInt is an int

func (AttrInt) String

func (a AttrInt) String() string

type AttrKind

type AttrKind uint8

AttrKind is an enum for the supported attributes (see the constants).

const (
	ATTR_INVALID              AttrKind = iota // does not happen
	ATTR_LANGUAGE                             // language (AttrString)
	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 `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 `Scale` (AttrInt)
	ATTR_GRAVITY                              // base text gravity (AttrInt)
	ATTR_GRAVITY_HINT                         // gravity hint (AttrInt)
	ATTR_FONT_FEATURES                        // OpenType font features (AttrString).
	ATTR_FOREGROUND_ALPHA                     // foreground alpha (AttrInt).
	ATTR_BACKGROUND_ALPHA                     // background alpha (AttrInt).
	ATTR_ALLOW_BREAKS                         // whether breaks are allowed (AttrInt).
	ATTR_SHOW                                 // how to render invisible characters (AttrInt).
	ATTR_INSERT_HYPHENS                       // whether to insert hyphens at intra-word line breaks (AttrInt).
	ATTR_OVERLINE                             // whether the text has an overline (AttrInt).
	ATTR_OVERLINE_COLOR                       // overline color (AttrColor).
	ATTR_LINE_HEIGHT                          // line height factor (AttrFloat)
	ATTR_ABSOLUTE_LINE_HEIGHT                 // line height (AttrInt)
	ATTR_TEXT_TRANSFORM                       // (AttrInt)
	ATTR_WORD                                 // override segmentation to classify the range of the attribute as a single word (AttrInt)
	ATTR_SENTENCE                             // override segmentation to classify the range of the attribute as a single sentence (AttrInt)
	ATTR_BASELINE_SHIFT                       // baseline displacement (AttrInt)
	ATTR_FONT_SCALE                           // font-relative size change (AttrInt)
)

func (AttrKind) String

func (t AttrKind) String() string

type AttrList

type AttrList []*Attribute

func (*AttrList) Change

func (list *AttrList) Change(attr *Attribute)

Change inserts the given attribute into the `AttrList`. It will replace any attributes of the same type on that segment and be merged with any adjoining attributes that are identical.

This function is slower than insert() for creating an attribute list in order (potentially much slower for large lists). However, insert() is not suitable for continually changing a set of attributes since it never removes or combines existing attributes.

func (*AttrList) Filter

func (list *AttrList) Filter(fn func(attr *Attribute) bool) AttrList

Given a AttrList and callback function, removes any elements of `list` for which `fn` returns `true` and inserts them into a new list (possibly empty if no attributes of the given types were found).

func (*AttrList) Insert

func (list *AttrList) Insert(attr *Attribute)

Insert the given attribute into the list. It will be inserted after all other attributes with a matching `StartIndex`.

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

AttrString is a string

func (AttrString) String

func (a AttrString) String() string

type Attribute

type Attribute struct {
	Data AttrData // the kind specific value
	Kind AttrKind
	// 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 NewAttrAbsoluteLineHeight

func NewAttrAbsoluteLineHeight(height int) *Attribute

NewAttrAbsoluteLineHeight overrides the height of logical line extents to be `height`, in `Scale`-ths of a point

This affects the values returned by LayoutLine.getExtents(), LayoutLine.getPixelExtents() and LayoutIter.getLineExtents() methods.

func NewAttrAbsoluteSize

func NewAttrAbsoluteSize(size int) *Attribute

NewAttrAbsoluteSize creates a new font-size attribute in device units.

func NewAttrAllowBreaks

func NewAttrAllowBreaks(allowBreaks bool) *Attribute

NewAttrAllowBreaks creates a new allow-breaks attribute.

If breaks are disabled, the range will be kept in a single run, as far as possible.

func NewAttrBackground

func NewAttrBackground(color AttrColor) *Attribute

NewAttrBackground creates a new background color attribute.

func NewAttrBackgroundAlpha

func NewAttrBackgroundAlpha(alpha uint16) *Attribute

NewAttrBackgroundAlpha creates a new background alpha attribute.

func NewAttrBaselineShift

func NewAttrBaselineShift(rise int) *Attribute

NewAttrBaselineShift creates a new baseline displacement attribute.

The effect of this attribute is to shift the baseline of a run, relative to the run of preceding run. `rise` is either a `BaselineShift` enumeration value or an absolute value (> 1024) in Pango units, relative to the baseline of the previous run. Positive values displace the text upwards.

func NewAttrFallback

func NewAttrFallback(enableFallback bool) *Attribute

NewAttrFallback creates a new font fallback attribute.

If fallback is disabled, 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.

func NewAttrFamily

func NewAttrFamily(family string) *Attribute

NewAttrFamily creates a new font family attribute: `family` is the family or comma separated list of families.

func NewAttrFontDescription

func NewAttrFontDescription(desc FontDescription) *Attribute

NewAttrFontDescription creates a new font description attribute. This attribute allows setting family, style, weight, variant, stretch, and size simultaneously.

func NewAttrFontFeatures

func NewAttrFontFeatures(features string) *Attribute

NewAttrFontFeatures creates a new font features tag attribute, from a string with OpenType font features, in CSS syntax

func NewAttrFontScale

func NewAttrFontScale(scale FontScale) *Attribute

NewAttrFontScale creates a new font scale attribute.

The effect of this attribute is to change the font size of a run, relative to the size of preceding run. `scale` indicates font size change relative to the size of the previous run.

func NewAttrForeground

func NewAttrForeground(color AttrColor) *Attribute

NewAttrForeground creates a new foreground color attribute.

func NewAttrForegroundAlpha

func NewAttrForegroundAlpha(alpha uint16) *Attribute

NewAttrForegroundAlpha creates a new foreground alpha attribute.

func NewAttrGravity

func NewAttrGravity(gravity Gravity) *Attribute

NewAttrGravity creates a new gravity attribute, which should not be `PANGO_GRAVITY_AUTO`.

func NewAttrGravityHint

func NewAttrGravityHint(gravityHint GravityHint) *Attribute

NewAttrGravityHint creates a new gravity_hint attribute.

func NewAttrInsertHyphens

func NewAttrInsertHyphens(insertHyphens bool) *Attribute

NewAttrInsertHyphens creates a new insert-hyphens attribute.

Pango will insert hyphens when breaking lines in the middle of a word. This attribute can be used to suppress the hyphen.

func NewAttrLanguage

func NewAttrLanguage(language Language) *Attribute

NewAttrLanguage creates a new language tag attribute

func NewAttrLetterSpacing

func NewAttrLetterSpacing(letterSpacing int32) *Attribute

NewAttrLetterSpacing creates a new letter-spacing attribute, the amount of extra space to add between graphemes of the text, in Pango units.

func NewAttrLineHeight

func NewAttrLineHeight(factor float32) *Attribute

NewAttrLineHeight modifies the height of logical line extents by a factor.

This affects the values returned by LayoutLine.getExtents(), LayoutLine.getPixelExtents() and LayoutIter.getLineExtents() methods.

func NewAttrOverline

func NewAttrOverline(overline Overline) *Attribute

NewAttrOverline creates a new overline-style attribute.

func NewAttrOverlineColor

func NewAttrOverlineColor(color AttrColor) *Attribute

NewAttrOverlineColor creates a new overline color attribute. This attribute modifies the color of overlines. If not set, overlines will use the foreground color.

func NewAttrRise

func NewAttrRise(rise int) *Attribute

NewAttrRise creates a new baseline displacement attribute: `rise` is the amount that the text should be displaced vertically, in Pango units. Positive values displace the text upwards.

func NewAttrScale

func NewAttrScale(scaleFactor Fl) *Attribute

NewAttrScale creates a new font size scale attribute. The base font for the affected text will have its size multiplied by `scaleFactor`.

func NewAttrSentence

func NewAttrSentence() *Attribute

NewAttrSentence marks the range of the attribute as a single sentence.

Note that this may require adjustments to word and sentence classification around the range.

func NewAttrShape

func NewAttrShape(ink, logical Rectangle) *Attribute

NewAttrShape creates a new shape attribute. A shape is used to impose a particular ink and logical rectangle on the result of shaping a particular glyph. This might be used, for instance, for embedding a picture or a widget inside a `Layout`.

func NewAttrShow

func NewAttrShow(flags ShowFlags) *Attribute

NewAttrShow creates a new attribute that influences how invisible characters are rendered.

func NewAttrSize

func NewAttrSize(size int) *Attribute

NewAttrSize creates a new font-size attribute in fractional points.

func NewAttrStretch

func NewAttrStretch(stretch Stretch) *Attribute

NewAttrStretch creates a new font stretch attribute.

func NewAttrStrikethrough

func NewAttrStrikethrough(strikethrough bool) *Attribute

NewAttrStrikethrough creates a new strikethrough-style attribute.

func NewAttrStrikethroughColor

func NewAttrStrikethroughColor(color AttrColor) *Attribute

NewAttrStrikethroughColor creates a new strikethrough color attribute. This attribute modifies the color of strikethrough lines. If not set, strikethrough lines will use the foreground color.

func NewAttrStyle

func NewAttrStyle(style Style) *Attribute

NewAttrStyle creates a new font slant style attribute.

func NewAttrTextTransform

func NewAttrTextTransform(textTransform TextTransform) *Attribute

NewAttrTextTransform marks the range of the attribute as a single sentence.

Note that this may require adjustments to word and sentence classification around the range.

func NewAttrUnderline

func NewAttrUnderline(underline Underline) *Attribute

NewAttrUnderline creates a new underline-style attribute.

func NewAttrUnderlineColor

func NewAttrUnderlineColor(color AttrColor) *Attribute

NewAttrUnderlineColor creates a new underline color attribute. This attribute modifies the color of underlines. If not set, underlines will use the foreground color.

func NewAttrVariant

func NewAttrVariant(variant Variant) *Attribute

NewAttrVariant creates a new font variant attribute (normal or small caps)

func NewAttrWeight

func NewAttrWeight(weight Weight) *Attribute

NewAttrWeight creates a new font weight attribute.

func NewAttrWord

func NewAttrWord() *Attribute

NewAttrWord marks the range of the attribute as a single word.

Note that this may require adjustments to word and sentence classification around the range.

func (Attribute) String

func (attr Attribute) String() string

type BaselineShift

type BaselineShift uint8

BaselineShift affects baseline shifts between runs.

const (
	// Leave the baseline unchanged
	BASELINE_SHIFT_NONE BaselineShift = iota
	// Shift the baseline to the superscript position, relative to the previous run
	BASELINE_SHIFT_SUPERSCRIPT
	// Shift the baseline to the subscript position, relative to the previous run
	BASELINE_SHIFT_SUBSCRIPT
)

type CharAttr

type CharAttr uint16

CharAttr is a flag storing information about the attributes of a single character. See the various IsXXX methods for more informations.

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

func ComputeCharacterAttributes

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

ComputeCharacterAttributes 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 bidirectionel 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) IsBreakInsertsHyphen

func (c CharAttr) IsBreakInsertsHyphen() bool

IsBreakInsertsHyphen determines if, when breaking lines before this char, insert a hyphen.

func (CharAttr) IsBreakRemovesPreceding

func (c CharAttr) IsBreakRemovesPreceding() bool

IsBreakRemovesPreceding determines if, when breaking lines before this char, remove the preceding char.

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 is an optional transformation matrix that will be applied when rendering with this context.
	Matrix *Matrix

	// Returns whether font rendering with this context should
	// round glyph positions and widths.
	// This is a read-only property, see SetRoundGlyphPositions.
	RoundGlyphPositions bool
	// contains filtered or unexported fields
}

Context stores global information used to control the itemization process. such as the fontmap used to look up fonts, and default values such as the default language, default gravity, or default font.

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) GetMetrics

func (context *Context) GetMetrics(desc *FontDescription, lang Language) FontMetrics

GetMetrics 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. Empty language 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 DefaultLanguage()) will be returned.

The `FontDescription` is interpreted in the same way as by pango_itemize(), and the family name may be a comma separated list of figures. 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. `nil` means that the font description from the context will be used.

func (*Context) Itemize

func (context *Context) Itemize(text []rune, startIndex int, length int,
	attrs AttrList,
) *ItemList

Itemize breaks a piece of text into segments with consistent directional level and shaping engine, applying `attrs`.

Each rune of `text` will be contained in exactly one of the items in the returned list; the generated list of items will be in logical order (the start offsets of the items are ascending). `startIndex` is the first rune index in `text` to process, and `length` the number of characters to process after `startIndex`.

func (*Context) SetBaseGravity

func (context *Context) SetBaseGravity(gravity Gravity)

SetBaseGravity sets the base gravity for the context.

The base gravity is used in laying vertical text out.

func (*Context) SetFontDescription

func (context *Context) SetFontDescription(desc FontDescription)

SetFontDescription sets the default font description for the context, which is used during itemization when no other font information is available.

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

func (*Context) SetRoundGlyphPositions

func (context *Context) SetRoundGlyphPositions(roundPositions bool)

SetRoundGlyphPositions 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.

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 CursorPos

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

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 characterDirection() and findBaseDirection() cannot be `DIRECTION_WEAK_LTR` or `DIRECTION_WEAK_RTL`, since every character is either neutral or has a strong direction; on the other hand `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 (
	DIRECTION_LTR Direction = iota // A strong left-to-right direction
	DIRECTION_RTL                  // A strong right-to-left direction

	DIRECTION_WEAK_LTR // A weak left-to-right direction
	DIRECTION_WEAK_RTL // A weak right-to-left direction
	DIRECTION_NEUTRAL  // No direction specified
)

func (Direction) String

func (d Direction) String() string

String returns a nickname for the direction

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 (
	ELLIPSIZE_NONE   EllipsizeMode = iota // No ellipsization
	ELLIPSIZE_START                       // Omit characters at the start of the text
	ELLIPSIZE_MIDDLE                      // Omit characters in the middle of the text
	ELLIPSIZE_END                         // Omit characters at the end of the text
)

type Fl

type Fl = float32

type Font

type Font interface {
	// FaceID returns the origin of the file.
	// It is not used directly by pango, but usefull for applications
	// which needs to go back to the font raw content.
	FaceID() fonts.FaceID

	// 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/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

	// GetFeatures obtains the OpenType features that are provided by the font.
	// These are passed to the rendering system, together with features
	// that have been explicitly set via attributes.
	//
	// Note that this does not include OpenType features which the
	// rendering system enables by default.
	GetFeatures() []harfbuzz.Feature

	// GetHarfbuzzFont returns a harfbuzz.Font object backing this font.
	// Implementations should create the font once and cache it.
	GetHarfbuzzFont() *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.

func LoadFont

func LoadFont(fontmap FontMap, context *Context, description *FontDescription) Font

LoadFont calls `LoadFontset` and select the first font, or nil if not found. `context` is optional, and is used to select a language if provided.

type FontDescription

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

	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 NewFontDescriptionFrom

func NewFontDescriptionFrom(str string) FontDescription

NewFontDescriptionFrom creates a new font description from a string representation in 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 nil. 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 default value is returned on invalid or empty input.

A typical example:

"Cantarell Italic Light 15 @wght=200"

func (FontDescription) AsHash

func (desc FontDescription) AsHash() FontDescription

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

func (*FontDescription) SetAbsoluteSize

func (desc *FontDescription) SetAbsoluteSize(size int32)

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

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

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 `GRAVITY_AUTO`, this actually unsets the gravity mask on the font description.

func (*FontDescription) SetSize

func (desc *FontDescription) SetSize(size int32)

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

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

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.

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 (
	FmFamily     FontMask = 1 << iota // the font family is specified.
	FmStyle                           // the font style is specified.
	FmVariant                         // the font variant is specified.
	FmWeight                          // the font weight is specified.
	FmStretch                         // the font stretch is specified.
	FmSize                            // the font size is specified.
	FmGravity                         // the font gravity is specified (Since: 1.16.)
	FmVariations                      // 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 Unit

	// 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 Unit

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

	// 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 Unit

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

	// 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 Unit

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

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

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 FontScale

type FontScale uint8
const (
	FONT_SCALE_NONE        FontScale = iota // Leave the font size unchanged
	FONT_SCALE_SUPERSCRIPT                  // Change the font to a size suitable for superscripts
	FONT_SCALE_SUBSCRIPT                    // Change the font to a size suitable for subscripts
	FONT_SCALE_SMALL_CAPS                   // Change the font to a size suitable for Small Caps.
)

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 (
	// `GLYPH_EMPTY` 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 isZeroWidth()).
	GLYPH_EMPTY Glyph = 0x0FFFFFFF

	// `GLYPH_INVALID_INPUT` 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 `GLYPH_UNKNOWN_FLAG` on.
	GLYPH_INVALID_INPUT Glyph = 0xFFFFFFFF

	// `GLYPH_UNKNOWN_FLAG` 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.
	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   Unit // the logical width to use for the the character.
	XOffset Unit // horizontal offset from nominal character position.
	YOffset Unit // vertical offset from nominal character position.
}

GlyphGeometry contains width and positioning information for a single glyph. Note that `width` is not guaranteed to be the same as the glyph extents. Kerning and other positioning applied during shaping will affect both the `Width` and the `XOffset` for the glyphs in the glyph string that results from shaping.

The information in this struct is intended for rendering the glyphs, as follows:

  1. Render the current glyph at (x + XOffset, y + YOffset), where (x, y) is the current point
  2. Advance the current point to (x + Width, y)
  3. Render the next glyph...

type GlyphInfo

type GlyphInfo struct {
	Glyph    Glyph         // the glyph itself.
	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 {
	Item   *Item
	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) GetLogicalWidths

func (glyphItem *GlyphItem) GetLogicalWidths(text []rune) []Unit

GetLogicalWidths determine the screen width corresponding to each character. When multiple characters compose a single cluster, the width of the entire cluster is divided equally among the characters. It returns an array whose length is the number of characters in glyphItem (equal to glyphItem.item.num_chars)

func (GlyphItem) LTR

func (g GlyphItem) LTR() bool

LTR returns true if the input text level was Left-To-Right.

type GlyphItemIter

type GlyphItemIter struct {

	// Index into text[glyphItem.Item.Offset:]
	StartChar, EndChar int

	StartIndex, EndIndex int // Index into text
	// 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 `StartIndex` and `StartChar` values. If the `glyphItem` is right-to-left (that is, if `glyphItem.Item.Analysis.Level` is odd), then `startGlyph` decreases as the iterator moves forward. Moreover, in right-to-left cases, `startGlyph` is greater than `endGlyph`.

An iterator should be initialized using either of `InitStart()` and `InitEnd()`, for forward and backward iteration respectively, and walked over using any desired mixture of `NextCluster()` and `PrevCluster()`.

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 `StartIndex` and `EndIndex` values can directly index into `text`. The `startGlyph`, `endGlyph`, `StartChar`, and `EndChar` 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.

func (*GlyphItemIter) InitEnd

func (iter *GlyphItemIter) InitEnd(glyphItem *GlyphItem, text []rune) bool

InitEnd initializes a `GlyphItemIter` structure to point to the last cluster in a glyph item, and returns `true` if it finds one.

func (*GlyphItemIter) InitStart

func (iter *GlyphItemIter) InitStart(glyphItem *GlyphItem, text []rune) bool

InitStart initializes a `GlyphItemIter` structure to point to the first cluster in a glyph item, and returns `true` if it finds one.

func (*GlyphItemIter) NextCluster

func (iter *GlyphItemIter) NextCluster() bool

NextCluster advances the iterator to the next cluster in the glyph item.

func (*GlyphItemIter) PrevCluster

func (iter *GlyphItemIter) PrevCluster() bool

PrevCluster moves the iterator to the preceding cluster in the glyph item.

type GlyphString

type GlyphString struct {
	// Array of glyph information for the glyph string
	Glyphs []GlyphInfo

	// logical cluster info, indexed by the rune index
	// within the text corresponding to the glyph string
	LogClusters []int
}

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

func (*GlyphString) Extents

func (glyphs *GlyphString) Extents(font Font, inkRect, logicalRect *Rectangle)

Extents compute the logical and ink extents of the glyph string. See the documentation for Font.GlyphExtents() for details about the interpretation of the rectangles.

func (*GlyphString) IndexToX

func (glyphs *GlyphString) IndexToX(text []rune, analysis *Analysis, index int,
	trailing bool) Unit

IndexToX converts from character position, given by `index` to x position. (X position is measured from the left edge of the run). Character positions are computed by dividing up each cluster into equal portions. If `trailing` is `false`, it computes the result for the beginning of the character.

func (*GlyphString) Shape

func (glyphs *GlyphString) Shape(text []rune, analysis *Analysis)

Shape is a convenience shortcut for ShapeRange(text, 0, len(text), analysis).

func (*GlyphString) ShapeRange

func (glyphs *GlyphString) ShapeRange(paragraphText []rune, itemOffset, itemLength int, analysis *Analysis)

ShapeRange convert the characters into glyphs, using a segment of text and the corresponding `Analysis` structure returned from the itemization. You may also pass in only a substring of the item from the itemization.

`paragraphText` is the full paragraph text, which will be used to perform certain cross-item shaping interactions. The actual text to shape is delimited by `itemOffset` and `itemLength`.

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 Matrix, and then glyph orientation is controlled using Gravity.

See also: GravityHint

const (
	GRAVITY_SOUTH Gravity = iota // Glyphs stand upright (default)
	GRAVITY_EAST                 // Glyphs are rotated 90 degrees clockwise
	GRAVITY_NORTH                // Glyphs are upside-down
	GRAVITY_WEST                 // Glyphs are rotated 90 degrees counter-clockwise
	GRAVITY_AUTO                 // Gravity is resolved from the context matrix
)

func (Gravity) IsImproper

func (g Gravity) IsImproper() bool

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

func (Gravity) IsVertical

func (g Gravity) IsVertical() bool

IsVertical returns whether `g` represents vertical writing directions.

func (Gravity) String

func (g Gravity) String() string

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 (
	GRAVITY_HINT_NATURAL GravityHint = iota // scripts will take their natural gravity based on the base gravity and the script
	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.
	GRAVITY_HINT_LINE
)

type Item

type Item struct {
	Analysis Analysis // Analysis results for the item.
	Offset   int      // Rune offset of the start of this item in text.
	Length   int      // Number of runes in the item.
}

Item stores information about a segment of text.

func (*Item) Shape

func (item *Item) Shape(paragraphText []rune, logAttrs []CharAttr, glyphs *GlyphString, flags shapeFlags)

Shape converts the characters in `item` into glyphs.

This is similar to [func@Pango.shape_with_flags], except it takes a `PangoItem` instead of separate `item_text` and @analysis arguments. It takes `logAttrs`, which may be used in implementing text transforms.

type ItemList

type ItemList struct {
	Data *Item
	Next *ItemList
}

ItemList is a single linked list of Item elements.

func (*ItemList) ApplyAttributes

func (items *ItemList) ApplyAttributes(attrs AttrList)

ApplyAttributes apply `attrs` to the list.

type Language

type Language = language.Language

func DefaultLanguage

func DefaultLanguage() Language

DefaultLanguage calls language.DefaultLanguage.

type Layout

type Layout struct {
	// Attributes is the attribute list for the layout.
	// This is a readonly property, see `SetAttributes` to modify it.
	Attributes AttrList

	// Readonly text of the layout, see `SetText` to modify it.
	Text []rune

	// Width (in Pango units) to which the lines of the Layout should wrap or ellipsize.
	// or -1 if not set.
	// This is a readonly property, see `SetWidth` to modify it.
	Width Unit

	// Ellipsize height, in device units if positive, number of lines if negative.
	// This is a readonly property, see `SetHeight` to modify it.
	Height Unit

	// Amount by which first line should be shorter.
	// This is a readonly property, see `SetIndent` to modify it.
	Indent Unit

	// Spacing between lines.
	// This is a readonly property, see `SetSpacing` to modify it.
	Spacing Unit

	// Factor to apply to line height.
	// This is a readonly property, see `SetLineSpacing` to modify it.
	LineSpacing float32

	// Whether each complete line should be stretched to fill the entire
	// width of the layout.
	// This is a readonly property, see `SetJustify` to modify it.
	Justify bool

	// Whether the last line should be stretched to fill the
	// entire width of the layout.
	// This is a readonly property, see `SetJustifyLastLine` to modify it.
	JustifyLastLine bool
	// contains filtered or unexported fields
}

Layout represents an entire paragraph of text. It is initialized with a `Context`, 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`. It is possible, as well, to ignore the 2-D setup, and simply treat the results of a `Layout` as a list of lines.

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) GetBaseline

func (layout *Layout) GetBaseline() Unit

GetBaseline gets the Y position of baseline of the first line in `layout`, from top of the layout.

func (*Layout) GetCharacterAttributes

func (layout *Layout) GetCharacterAttributes() []CharAttr

GetCharacterAttributes retrieves an array of logical attributes for each character in the `layout`, triggering a layout if needed.

The returned slice length will be one more than the total number of characters in the layout, since there need to be attributes corresponding to both the position before the first character and the position after the last character.

The returned slice is retained by the layout and must to be modified.

func (*Layout) GetCursorPos

func (layout *Layout) GetCursorPos(index int, strongPos, weakPos *Rectangle)

GetCursorPos determines, given an index within a layout, the positions that of the strong and weak cursors if the insertion point is at that index.

The position of each cursor is stored as a zero-width rectangle with the height of the run extents.

The strong cursor location is the location where characters of the directionality equal to the base direction of the layout are inserted. The weak cursor location is the location where characters of the directionality opposite to the base direction of the layout are inserted.

The strong cursor has a little arrow pointing to the right, the weak cursor to the left. Typing a 'c' in this situation will insert the character after the 'b', and typing another Hebrew character, like 'ג', will insert it at the end.

func (*Layout) GetDirectionAt

func (layout *Layout) GetDirectionAt(index int) Direction

GetDirectionAt gets the text direction at the given character position in `layout` text.

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` if you dont need one of the extents.

func (*Layout) GetIter

func (layout *Layout) GetIter() *LayoutIter

GetIter returns an iterator to iterate over the visual extents of the layout. The first item is already loaded, meaning that a typical use of the iterator would be:

		iter := GetIter()
		for do := true; do; do = iter.NextXXX() {
			item := iter.GetXXX()
     }

func (*Layout) GetLine

func (layout *Layout) GetLine(line int) *LayoutLine

GetLine retrieves a particular line from a `Layout`, or `nil` if the index is out of range. This layout line will become invalid if changes are made to the `Layout`.

The returned line should not be modified.

func (*Layout) GetLineCount

func (layout *Layout) GetLineCount() int

GetLineCount retrieves the count of lines for the layout, triggering a layout if needed.

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) GetSize

func (layout *Layout) GetSize() (Unit, Unit)

GetSize determines the logical width and height of a `Layout` in Pango units.

This is simply a convenience wrapper around `Layout.GetExtents`.

func (*Layout) IndexToPos

func (layout *Layout) IndexToPos(index int, pos *Rectangle)

IndexToPos converts from an index within a `Layout` to the onscreen position corresponding to the grapheme at that index.

The return value is represented as rectangle. Note that `pos.X` is always the leading edge of the grapheme and `pos.X + pos.Width` the trailing edge of the grapheme. If the directionality of the grapheme is right-to-left, then `pos.Width` will be negative.

func (*Layout) IsEllipsized

func (layout *Layout) IsEllipsized() bool

IsEllipsized queries whether the layout had to ellipsize any paragraphs, triggering a layout if needed.

This returns `true` if the ellipsization mode for `layout` is not ELLIPSIZE_NONE, a positive width is set on `layout`, and there are paragraphs exceeding that width that have to be ellipsized.

func (*Layout) IsWrapped

func (layout *Layout) IsWrapped() bool

IsWrapped queries whether the layout had to wrap any paragraphs, triggering a layout if needed.

This returns `true` if a positive width is set on `layout`, ellipsization mode of `layout` is set to ELLIPSIZE_NONE, and there are paragraphs exceeding the layout width that have to be wrapped.

func (*Layout) MoveCursorVisually

func (layout *Layout) MoveCursorVisually(strong bool,
	oldIndex, oldTrailing, direction int,
) (newIndex, newTrailing int)

MoveCursorVisually computes a new cursor position from an old position (`oldIndex`) and a direction.

`strong` indicates whether the moving cursor is the strong cursor or the

weak cursor. The strong cursor is the cursor corresponding
to text insertion in the base direction for the layout.

if `oldTrailing` is 0, the cursor was at the leading edge of the

grapheme indicated by `oldIndex`, if > 0, the cursor
was at the trailing edge.

If `direction` is positive, then the new position will cause the strong or weak cursor to be displayed one position to right of where it was with the old cursor position. If `direction` is negative, it will be moved to the left.

A value of -1 for `newIndex` indicates that the cursor has been moved off the beginning of the layout. A value of `MaxInt` indicates that the cursor has been moved off the end of the layout. `newTrailing` is the number of characters to move forward from the location returned for `newIndex` to get the position where the cursor should be displayed. This allows distinguishing the position at the beginning of one line from the position at the end of the preceding line. `newIndex` is always on the line where the cursor should be displayed.

In the presence of bidirectional text, the correspondence between logical and visual order will depend on the direction of the current run, and there may be jumps when the cursor is moved off of the end of a run.

Motion here is in cursor positions, not in characters, so a single call to this function may move the cursor over multiple characters when multiple characters combine to form a single grapheme.

func (*Layout) SetAlignment

func (layout *Layout) SetAlignment(alignment Alignment)

SetAlignment sets the alignment for the layout: how partial lines are positioned within the horizontal space available.

func (*Layout) SetAttributes

func (layout *Layout) SetAttributes(attrs AttrList)

Sets the text attributes for a layout object.

func (*Layout) SetAutoDir

func (layout *Layout) SetAutoDir(autoDir bool)

SetAutoDir sets whether to calculate the bidirectional base direction for the layout according to the contents of the layout; when this flag is on (the default), then paragraphs in `layout` that begin with strong right-to-left characters (Arabic and Hebrew principally), will have right-to-left layout, paragraphs with letters from other scripts will have left-to-right layout. Paragraphs with only neutral characters get their direction from the surrounding paragraphs.

When `false`, the choice between left-to-right and right-to-left layout is done according to the base direction of the layout's Context. (See pango_context_set_base_dir()).

When the auto-computed direction of a paragraph differs from the base direction of the context, the interpretation of `ALIGN_LEFT` and `ALIGN_RIGHT` are swapped.

func (*Layout) SetEllipsize

func (layout *Layout) SetEllipsize(ellipsize EllipsizeMode)

SetEllipsize sets the type of ellipsization being performed for layout. Depending on the ellipsization mode `ellipsize`, text is removed from the start, middle, or end of text so they fit within the width and height of layout set with SetWidth() and SetHeight().

If the layout contains characters such as newlines that force it to be layed out in multiple paragraphs, then whether each paragraph is ellipsized separately or the entire layout is ellipsized as a whole depends on the set height of the layout. See SetHeight() for details.

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) SetHeight

func (layout *Layout) SetHeight(height Unit)

SetHeight sets the height to which the `Layout` should be ellipsized at.

There are two different behaviors, based on whether `height` is positive or negative.

If `height` is positive, it will be the maximum height of the layout. Only lines would be shown that would fit, and if there is any text omitted, an ellipsis added. At least one line is included in each paragraph regardless of how small the height value is. A value of zero will render exactly one line for the entire layout.

If `height` is negative, it will be the (negative of the) maximum number of lines per paragraph. That is, the total number of lines shown may well be more than this value if the layout contains multiple paragraphs of text. The default value of -1 means that the first line of each paragraph is ellipsized. This behavior may be changed in the future to act per layout instead of per paragraph.

Height setting only has effect if a positive width is set on `layout` and ellipsization mode of `layout` is not `ELLIPSIZE_NONE`. The behavior is undefined if a height other than -1 is set and ellipsization mode is set to `ELLIPSIZE_NONE`, and may change in the future.

func (*Layout) SetIndent

func (layout *Layout) SetIndent(indent Unit)

SetIndent sets the width in Pango units to indent each paragraph. A negative value of `indent` will produce a hanging indentation. That is, the first line will have the full width, and subsequent lines will be indented by the absolute value of `indent`.

The indent setting is ignored if layout alignment is set to `ALIGN_CENTER`.

func (*Layout) SetJustify

func (layout *Layout) SetJustify(justify bool)

SetJustify sets whether each complete line should be stretched to fill the entire width of the layout. This stretching is typically done by adding whitespace, but for some scripts (such as Arabic), the justification may be done in more complex ways, like extending the characters. Note that tabs and justification conflict with each other: Justification will move content away from its tab-aligned positions.

func (*Layout) SetJustifyLastLine

func (layout *Layout) SetJustifyLastLine(justify bool)

SetJustifyLastLine sets whether the last line should be stretched to fill the entire width of the layout.

This only has an effect if SetJustify has been called as well.

func (*Layout) SetLineSpacing

func (layout *Layout) SetLineSpacing(factor float32)

SetLineSpacing sets a factor for line spacing. Typical values are: 0, 1, 1.5, 2. The default values is 0.

If `factor` is non-zero, lines are placed so that

baseline2 = baseline1 + factor * height2

where height2 is the line height of the second line (as determined by the font(s)). In this case, the spacing set with SetSpacing() is ignored.

If `factor` is zero, spacing is applied as before.

func (*Layout) SetMarkup

func (layout *Layout) SetMarkup(markup []byte) error

SetMarkup sets the layout text and attribute list from marked-up text (see `ParseMarkup()` for the markup format). It replaces the current text and attribute list. It returns an error if the markup is not correctly formatted.

func (*Layout) SetRunes

func (layout *Layout) SetRunes(text []rune)

SetRunes is the same as `SetText` but skips UTF-8 validation. `text` is copied and not retained by the layout.

func (*Layout) SetSingleParagraphMode

func (layout *Layout) SetSingleParagraphMode(setting bool)

SetSingleParagraphMode set the paragraph behavior.

If `setting` is `true`, do not treat newlines and similar characters as paragraph separators; instead, keep all text in a single paragraph, and display a glyph for paragraph separator characters. Used when you want to allow editing of newlines on a single text line.

func (*Layout) SetSpacing

func (layout *Layout) SetSpacing(spacing Unit)

SetSpacing sets the amount of spacing in Pango unit between the lines of the layout. When placing lines with spacing, Pango arranges things so that

line2.top = line1.bottom + spacing

Note: Pango defaults to using the line height (as determined by the font) for placing lines. The `spacing` set with this function is only taken into account when the line-height factor is set to zero with SetLineSpacing().

func (*Layout) SetTabs

func (layout *Layout) SetTabs(tabs *TabArray)

SetTabs sets the tabs to use for `layout`, overriding the default tabs (by default, tabs are every 8 spaces). If `tabs` is nil, the default tabs are reinstated. Note that tabs and justification conflict with each other: justification will move content away from its tab-aligned positions. The same is true for alignments other than `ALIGN_LEFT`.

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 SetMarkup() on `layout` before, you may want to call SetAttributes() to clear the attributes set on the layout from the markup as this function does not clear attributes.

func (*Layout) SetWidth

func (layout *Layout) SetWidth(width Unit)

SetWidth sets the width (in Pango units) to which the lines of the layout should wrap or ellipsize. Pass -1 to indicate that no wrapping or ellipsization should be performed. The default value is -1: no width set.

func (*Layout) SetWrap

func (layout *Layout) SetWrap(wrap WrapMode)

SetWrap sets the wrap mode; the wrap mode only has effect if a width is set on the layout with SetWidth(). To turn off wrapping, set the width to -1.

type LayoutIter

type LayoutIter struct {

	// Index is the current readonly rune index in the text.
	// Note that iterating forward by char moves in visual order, not logical order, so indexes may not be
	// sequential. Also, the index may be equal to the length of the text
	// in the layout, if on the `nil` run (see `GetRun()`).
	Index int
	// contains filtered or unexported fields
}

LayoutIter is a structure that can be used to iterate over the visual extents of a `Layout`.

func (*LayoutIter) GetBaseline

func (iter *LayoutIter) GetBaseline() Unit

GetBaseline gets the Y position of the current line's baseline, in layout coordinates (origin at top left of the entire layout).

func (*LayoutIter) GetCharExtents

func (iter *LayoutIter) GetCharExtents() Rectangle

GetCharExtents gets the extents of the current character, in layout coordinates (origin is the top left of the entire layout). Only logical extents can sensibly be obtained for characters; ink extents make sense only down to the level of clusters.

func (*LayoutIter) GetClusterExtents

func (iter *LayoutIter) GetClusterExtents(inkRect, logicalRect *Rectangle)

GetClusterExtents gets the extents of the current cluster, in layout coordinates (origin is the top left of the entire layout).

func (*LayoutIter) GetLine

func (iter *LayoutIter) GetLine() *LayoutLine

GetLine gets the current line.

Use the faster pango_layout_iter_get_line_readonly() if you do not plan to modify the contents of the line (glyphs, glyph widths, etc.).

func (*LayoutIter) GetLineExtents

func (iter *LayoutIter) GetLineExtents(inkRect, logicalRect *Rectangle)

GetLineExtents obtains the extents of the current line. `inkRect` or `logicalRect` can be `nil` if you aren't interested in them. Extents are in layout coordinates (origin is the top-left corner of the entire layout). Thus the extents returned by this function will be the same width/height but not at the same x/y as the extents returned from GetExtents().

func (*LayoutIter) GetRun

func (iter *LayoutIter) GetRun() *GlyphItem

GetRun gets the current run. When iterating by run, at the end of each line, there's a position with a `nil` run, so this function can return `nil`. The `nil` run at the end of each line ensures that all lines have at least one run, even lines consisting of only a newline.

Use the faster pango_layout_iter_get_run_readonly() if you do not plan to modify the contents of the run (glyphs, glyph widths, etc.).

func (*LayoutIter) GetRunExtents

func (iter *LayoutIter) GetRunExtents(inkRect, logicalRect *Rectangle)

GetRunExtents gets the extents of the current run in layout coordinates (origin is the top left of the entire layout).

func (*LayoutIter) IsAtLastLine

func (iter *LayoutIter) IsAtLastLine() bool

IsAtLastLine determines whether `iter` is on the last line of the layout.

func (*LayoutIter) NextChar

func (iter *LayoutIter) NextChar() bool

NextChar moves `iter` forward to the next character in visual order. If `iter` was already at the end of the layout, returns `false`.

func (*LayoutIter) NextCluster

func (iter *LayoutIter) NextCluster() bool

NextCluster moves `iter` forward to the next cluster in visual order. If `iter` was already at the end of the layout, returns `false`.

func (*LayoutIter) NextLine

func (iter *LayoutIter) NextLine() bool

NextLine moves `iter` forward to the start of the next line. If `iter` is already on the last line, returns `false`.

func (*LayoutIter) NextRun

func (iter *LayoutIter) NextRun() bool

NextRun moves `iter` forward to the next run in visual order. If `iter` was already at the end of the layout, returns `false`.

type LayoutLine

type LayoutLine struct {
	Runs             *RunList  // list of runs in the line, from left to right
	StartIndex       int       // start of line as rune index into layout.Text
	Length           int       // length of line in runes
	IsParagraphStart bool      // true if this is the first line of the paragraph
	ResolvedDir      Direction // Resolved Direction of line
	// 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.

func (*LayoutLine) GetExtents

func (line *LayoutLine) GetExtents(inkRect, logicalRect *Rectangle) (height Unit)

GetExtents computes the logical and ink extents of a layout line, as well as the height. `inkRect` and `logicalRect` are optional

func (*LayoutLine) GetXRanges

func (line *LayoutLine) GetXRanges(startIndex, endIndex int) []Unit

GetXRanges gets a list of visual ranges corresponding to a given logical range. `startIndex` is the start rune index of the logical range. If this value

is less than the start index for the line, then the first range
will extend all the way to the leading edge of the layout. Otherwise,
it will start at the leading edge of the first character.

`endIndex` is the ending rune index of the logical range. If this value is

  greater than the end index for the line, then the last range will
  extend all the way to the trailing edge of the layout. Otherwise,
  it will end at the trailing edge of the last character.

	The returned slice will be of length
  `2*nRanges`, with each range starting at `ranges[2*n]` and of
  width `ranges[2*n + 1] - ranges[2*n]`. The coordinates are relative to the layout and are in
  Pango units.

This list is not necessarily minimal - there may be consecutive ranges which are adjacent. The ranges will be sorted from left to right. The ranges are with respect to the left edge of the entire layout, not with respect to the line.

func (*LayoutLine) IndexToX

func (line *LayoutLine) IndexToX(index int, trailing bool) Unit

IndexToX converts an index within a line to a X position `trailing` indicates the edge of the grapheme to retrieve the position of : if true, the trailing edge of the grapheme, else the leading of the grapheme.

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 (
	OVERLINE_NONE   Overline = iota // no overline should be drawn
	OVERLINE_SINGLE                 // Draw a single line above the ink extents of the text being underlined.
)

type ParsedMarkup

type ParsedMarkup struct {
	Attr      AttrList // Attributes extracted from the markup
	Text      []rune   // Text with tags stripped
	AccelChar rune     // Accelerator char
}

ParsedMarkup exposes the result of parsing a 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 ParseMarkup().

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

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

See ParseMarkup for complete syntax.

func ParseMarkup

func ParseMarkup(markupText []byte, accelMarker rune) (ParsedMarkup, error)

ParseMarkup parses marked-up text to create a plain-text string and an attribute list.

If `accelMarker` is nonzero, the given character will mark the character following it as an accelerator. For example, `accelMarker` might be an ampersand or underscore. All characters marked as an accelerator will receive a `PANGO_UNDERLINE_LOW` attribute, and the first character so marked will be returned in `accelChar`. Two `accelMarker` characters following each other produce a single literal `accelMarker` character.

A marked-up document follows an XML format : the root tag is `<markup>`, but ParseMarkup() 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 NewFontDescriptionFromString() 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      Unit // X coordinate of the left side of the rectangle.
	Y      Unit // Y coordinate of the the top side of the rectangle.
	Width  Unit // width of the rectangle.
	Height Unit // 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, Font.GlyphExtents())

type RunList

type RunList struct {
	Data *GlyphItem
	Next *RunList
}

RunList is a linked list of `GlyphItem`

type Script

type Script = language.Script

type ShowFlags

type ShowFlags uint8

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

const (
	SHOW_SPACES      ShowFlags = 1 << iota //  Render spaces, tabs and newlines visibly
	SHOW_LINE_BREAKS                       //  Render line breaks visibly
	SHOW_IGNORABLES                        //  Render default-ignorable Unicode characters visibly
	SHOW_NONE        ShowFlags = 0         //  No special treatment for invisible characters
)

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 {
	// Offset in pixels of this tab stop from the left margin of the text.
	Location Unit
	// Where the tab stop appears relative to the text.
	Alignment TabAlign
	// Rune for the decimal point to use. Only relevant when TabAlign is TAB_DECIMAL
	// Default to .
	DecimalPoint rune
}

type TabAlign

type TabAlign uint8

A TabAlign specifies where the text appears relative to the tab stop position.

const (
	// the tab stop appears to the left of the text
	TAB_LEFT TabAlign = iota
	// the text appears to the left of the tab stop position  until the available space is filled
	TAB_RIGHT
	// the text is centered at the tab stop position  until the available space is filled
	TAB_CENTER
	// text before the first '.' appears to the left of the tab stop position
	// (until the available space is filled), the rest to the right
	TAB_DECIMAL
)

type TabArray

type TabArray struct {
	Tabs              []Tab
	PositionsInPixels bool
}

A `TabArray` struct contains an array of tab stops. Each tab stop has an alignment and a position.

func (*TabArray) Copy

func (tabs *TabArray) Copy() *TabArray

Copy returns a deep copy

type TextTransform

type TextTransform uint8

TextTransform affects how Pango treats characters during shaping.

const (
	// Leave text unchanged
	TEXT_TRANSFORM_NONE TextTransform = iota
	// Display letters and numbers as lowercase
	TEXT_TRANSFORM_LOWERCASE
	// Display letters and numbers as uppercase
	TEXT_TRANSFORM_UPPERCASE
	// Display the first character of a word
	TEXT_TRANSFORM_CAPITALIZE
)

type Underline

type Underline uint8

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

const (
	UNDERLINE_NONE   Underline = iota // no underline should be drawn
	UNDERLINE_SINGLE                  // a single underline should be drawn
	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.
	// UNDERLINE_SINGLE should be used for extended
	// portions of text.
	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.
	UNDERLINE_ERROR
	UNDERLINE_SINGLE_LINE // like UNDERLINE_SINGLE, but drawn continuously across multiple runs.
	UNDERLINE_DOUBLE_LINE // like UNDERLINE_DOUBLE, but drawn continuously across multiple runs.
	UNDERLINE_ERROR_LINE  // like UNDERLINE_ERROR, but drawn continuously across multiple runs.
)

type Unit

type Unit int32

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

func (Unit) Pixels

func (g Unit) Pixels() int32

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

func (Unit) PixelsCeil

func (g Unit) PixelsCeil() int32

PixelsCeil converts from glyph units into device units by ceiling

func (Unit) PixelsFloor

func (g Unit) PixelsFloor() int32

PixelsFloor converts from glyph units into device units by flooring.

func (Unit) Round

func (d Unit) Round() Unit

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

type Variant

type Variant uint8

Variant specifies capitalization variant of the font.

const (
	VARIANT_NORMAL          Variant = iota // A normal font.
	VARIANT_SMALL_CAPS                     // A font with the lower case characters replaced by smaller variants of the capital characters.
	VARIANT_ALL_SMALL_CAPS                 // A font with all characters replaced by smaller variants of the capital characters.
	VARIANT_PETITE_CAPS                    // A font with the lower case characters replaced by smaller variants of the capital characters. Petite Caps can be even smaller than Small Caps.
	VARIANT_ALL_PETITE_CAPS                // A font with all characters replaced by smaller variants of the capital characters. Petite Caps can be even smaller than Small Caps.
	VARIANT_UNICASE                        // A font with the upper case characters replaced by smaller variants of the capital letters.
	VARIANT_TITLE_CAPS                     // A font with capital letters that are more suitable for all-uppercase titles.
)

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 (
	WEIGHT_THIN       Weight = 100  // the thin weight (= 100; Since: 1.24)
	WEIGHT_ULTRALIGHT Weight = 200  // the ultralight weight (= 200)
	WEIGHT_LIGHT      Weight = 300  // the light weight (= 300)
	WEIGHT_SEMILIGHT  Weight = 350  // the semilight weight (= 350; Since: 1.36.7)
	WEIGHT_BOOK       Weight = 380  // the book weight (= 380; Since: 1.24)
	WEIGHT_NORMAL     Weight = 400  // the default weight (= 400)
	WEIGHT_MEDIUM     Weight = 500  // the normal weight (= 500; Since: 1.24)
	WEIGHT_SEMIBOLD   Weight = 600  // the semibold weight (= 600)
	WEIGHT_BOLD       Weight = 700  // the bold weight (= 700)
	WEIGHT_ULTRABOLD  Weight = 800  // the ultrabold weight (= 800)
	WEIGHT_HEAVY      Weight = 900  // the heavy weight (= 900)
	WEIGHT_ULTRAHEAVY Weight = 1000 // the ultraheavy weight (= 1000; Since: 1.24)
)

type WrapMode

type WrapMode uint8

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

const (
	WRAP_WORD      WrapMode = iota // wrap lines at word boundaries.
	WRAP_CHAR                      // wrap lines at character boundaries.
	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 color implements a tool to generate the values of common colors supported by pango.
Package color implements a tool to generate the values of common colors supported by pango.
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.

Jump to

Keyboard shortcuts

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