Documentation
¶
Overview ¶
Package glyph provides high-quality text shaping, layout, and rendering for GPU-accelerated applications. It uses a platform-appropriate shaper and rasterizer per operating system, exposed behind a backend-agnostic DrawBackend interface.
Platform matrix ¶
OS Shaper Rasterizer Linux/BSD Pango + HarfBuzz FreeType + FontConfig macOS * CoreText CoreText / CoreGraphics Windows GDI + DirectWrite GDI + DirectWrite Android FreeType FreeType WASM Canvas2D Canvas2D * macOS can also use the Pango/FreeType stack with the glyph_pango build tag.
Quick start ¶
backend := ebitengine.NewBackend() // or sdl2, gpu, web, etc.
ts, err := glyph.NewTextSystem(backend)
if err != nil {
log.Fatal(err)
}
defer ts.Free()
layout, err := ts.LayoutText("Hello, world!", glyph.TextConfig{
Style: glyph.TextStyle{FontName: "Sans 18"},
})
if err != nil {
log.Fatal(err)
}
ts.DrawLayout(layout, 10, 10)
Architecture ¶
Context owns platform-specific shaper and font state. Renderer draws shaped layouts through a DrawBackend. Six backends are provided:
- github.com/go-gui-org/go-glyph/backend/ebitengine: Ebitengine integration.
- github.com/go-gui-org/go-glyph/backend/gpu: raw OpenGL 3.3 / Metal.
- github.com/go-gui-org/go-glyph/backend/sdl2: SDL2 rendering.
- github.com/go-gui-org/go-glyph/backend/web: HTML Canvas (WASM).
- github.com/go-gui-org/go-glyph/backend/android: Android GPU.
- github.com/go-gui-org/go-glyph/backend/ios: iOS Metal.
Thread Safety ¶
Context, Renderer, TextSystem, and GlyphAtlas are not safe for concurrent use. In a typical application, call all glyph methods from the main/render goroutine.
Sub-packages ¶
- github.com/go-gui-org/go-glyph/accessibility: screen-reader tree management.
- github.com/go-gui-org/go-glyph/ime: IME bridge (macOS/Linux).
Index ¶
- Constants
- func FCConfigAppFontAddDir(dir string) bool
- func FCConfigAppFontAddFile(path string) bool
- func GetSelectedText(text string, cursor, anchor int) string
- func IsDeadKey(r rune) bool
- func PangoAttrBackgroundNew(r, g, b uint16) *C.PangoAttribute
- func PangoAttrFontDescNew(desc *C.PangoFontDescription) *C.PangoAttribute
- func PangoAttrFontFeaturesNew(features string) *C.PangoAttribute
- func PangoAttrForegroundNew(r, g, b uint16) *C.PangoAttribute
- func PangoAttrLetterSpacingNew(spacing int) *C.PangoAttribute
- func PangoAttrShapeNew(ink, logical *C.PangoRectangle) *C.PangoAttribute
- func PangoAttrStrikethroughNew(strikethrough bool) *C.PangoAttribute
- func PangoAttrUnderlineNew(style int) *C.PangoAttribute
- func PangoContextGetMetrics(ctx *C.PangoContext, desc *C.PangoFontDescription, lang *C.PangoLanguage) *C.PangoFontMetrics
- func PangoContextSetBaseGravity(ctx *C.PangoContext)
- func PangoFCFontLockFace(font *C.PangoFont) unsafe.Pointer
- func PangoFCFontMapConfigChanged(fontMap PangoFontMapW)
- func PangoFCFontUnlockFace(font *C.PangoFont)
- func PangoFT2FontGetFace(font *C.PangoFont) C.FT_Face
- func PangoFontDescGetFamily(desc *C.PangoFontDescription) string
- func PangoFontDescGetSize(desc *C.PangoFontDescription) int
- func PangoFontDescSetFamily(desc *C.PangoFontDescription, family string)
- func PangoFontMetricsGetAscent(m *C.PangoFontMetrics) int
- func PangoFontMetricsGetDescent(m *C.PangoFontMetrics) int
- func PangoFontMetricsGetStrikethroughPosition(m *C.PangoFontMetrics) int
- func PangoFontMetricsGetStrikethroughThickness(m *C.PangoFontMetrics) int
- func PangoFontMetricsGetUnderlinePosition(m *C.PangoFontMetrics) int
- func PangoFontMetricsGetUnderlineThickness(m *C.PangoFontMetrics) int
- func PangoGetDefaultLanguage() *C.PangoLanguage
- func PangoLayoutGetAttributes(layout *C.PangoLayout) *C.PangoAttrList
- func PangoLayoutGetContext(layout *C.PangoLayout) *C.PangoContext
- func PangoLayoutGetFontDescription(layout *C.PangoLayout) *C.PangoFontDescription
- func PangoLayoutGetLineCount(layout *C.PangoLayout) int
- func PangoLayoutGetLogAttrsReadonly(layout *C.PangoLayout) (*C.PangoLogAttr, int)
- func ScaleBitmapBicubic(src []byte, srcW, srcH, dstW, dstH int) []byte
- func SetDPIAwareWindows()
- func ValidateDimension(dim int, name, location string) error
- func ValidateFontPath(path string, location string) error
- func ValidateSize(size, minVal, maxVal float32, name, location string) error
- func ValidateTextInput(text string, maxLen int, location string) error
- type AffineTransform
- type Alignment
- type AtlasPage
- type Bitmap
- type BlockStyle
- type CachedGlyph
- type CharRect
- type Clause
- type ClauseRects
- type ClauseStyle
- type Color
- type CompositionPhase
- type CompositionState
- func (cs *CompositionState) ClearClauses()
- func (cs *CompositionState) Commit() string
- func (cs *CompositionState) CompositionBounds(layout Layout) (Rect, bool)
- func (cs *CompositionState) DocumentCursorPos() int
- func (cs *CompositionState) GetClauseRects(layout Layout) []ClauseRects
- func (cs *CompositionState) HandleClause(start, length, style int)
- func (cs *CompositionState) HandleInsertText(text string) string
- func (cs *CompositionState) HandleMarkedText(text string, cursorInPreedit, documentCursor int)
- func (cs *CompositionState) HandleUnmarkText()
- func (cs *CompositionState) IsComposing() bool
- func (cs *CompositionState) PreeditEnd() int
- func (cs *CompositionState) Reset()
- func (cs *CompositionState) SetClauses(clauses []Clause, selected int)
- func (cs *CompositionState) SetMarkedText(text string, cursorInPreedit int)
- func (cs *CompositionState) Start(cursorPos int)
- type Context
- func (ctx *Context) AddFontFile(path string) error
- func (ctx *Context) FontHeight(cfg TextConfig) (float32, error)
- func (ctx *Context) FontMetrics(cfg TextConfig) (TextMetrics, error)
- func (ctx *Context) Free()
- func (ctx *Context) LayoutRichText(rt RichText, cfg TextConfig) (Layout, error)
- func (ctx *Context) LayoutText(text string, cfg TextConfig) (Layout, error)
- func (ctx *Context) ResolveFontName(fontDescStr string) (string, error)
- func (ctx *Context) ScaleFactor() float32
- type CursorPosition
- type DeadKeyState
- type DrawBackend
- type FTFace
- type FTLibrary
- type FTStroker
- type FontAxis
- type FontFeature
- type FontFeatures
- type FontMetricsEntry
- type Glyph
- type GlyphAtlas
- type GlyphInfo
- type GlyphPlacement
- type GradientConfig
- type GradientDirection
- type GradientStop
- type InlineObject
- type Item
- type Layout
- func (l *Layout) GetCharRect(index int) (Rect, bool)
- func (l *Layout) GetClosestOffset(x, y float32) int
- func (l *Layout) GetCursorPos(byteIndex int) (CursorPosition, bool)
- func (l *Layout) GetFontNameAtIndex(index int) string
- func (l *Layout) GetParagraphAtIndex(byteIndex int, text string) (int, int)
- func (l *Layout) GetSelectionRects(start, end int) []Rect
- func (l *Layout) GetValidCursorPositions() []int
- func (l *Layout) GetWordAtIndex(byteIndex int) (int, int)
- func (l *Layout) GlyphPositions() []GlyphInfo
- func (l *Layout) HitTest(x, y float32) int
- func (l *Layout) HitTestRect(x, y float32) (Rect, bool)
- func (l *Layout) MoveCursorDown(byteIndex int, preferredX float32) int
- func (l *Layout) MoveCursorLeft(byteIndex int) int
- func (l *Layout) MoveCursorLineEnd(byteIndex int) int
- func (l *Layout) MoveCursorLineStart(byteIndex int) int
- func (l *Layout) MoveCursorRight(byteIndex int) int
- func (l *Layout) MoveCursorUp(byteIndex int, preferredX float32) int
- func (l *Layout) MoveCursorWordLeft(byteIndex int) int
- func (l *Layout) MoveCursorWordRight(byteIndex int) int
- type Line
- type LoadGlyphConfig
- type LoadGlyphResult
- type LogAttr
- type MutationResult
- func CutSelection(text string, cursor, anchor int) (string, MutationResult)
- func DeleteBackward(text string, layout Layout, cursor int) MutationResult
- func DeleteForward(text string, layout Layout, cursor int) MutationResult
- func DeleteSelection(text string, cursor, anchor int) MutationResult
- func DeleteToLineEnd(text string, layout Layout, cursor int) MutationResult
- func DeleteToLineStart(text string, layout Layout, cursor int) MutationResult
- func DeleteToWordBoundary(text string, layout Layout, cursor int) MutationResult
- func DeleteToWordEnd(text string, layout Layout, cursor int) MutationResult
- func InsertReplacingSelection(text string, cursor, anchor int, insert string) MutationResult
- func InsertText(text string, cursor int, insert string) MutationResult
- type OperationType
- type PangoAttrListW
- type PangoContextW
- type PangoFontDescW
- type PangoFontMapW
- type PangoFontMetricsW
- type PangoFontW
- type PangoLayoutIterW
- func (it *PangoLayoutIterW) Close()
- func (it PangoLayoutIterW) GetBaseline() int
- func (it PangoLayoutIterW) GetCharExtents() C.PangoRectangle
- func (it PangoLayoutIterW) GetIndex() int
- func (it PangoLayoutIterW) GetLineExtents() (ink, logical C.PangoRectangle)
- func (it PangoLayoutIterW) GetLineReadonly() *C.PangoLayoutLine
- func (it PangoLayoutIterW) GetRunExtents() (ink, logical C.PangoRectangle)
- func (it PangoLayoutIterW) GetRunReadonly() *C.PangoGlyphItem
- func (it PangoLayoutIterW) NextChar() bool
- func (it PangoLayoutIterW) NextLine() bool
- func (it PangoLayoutIterW) NextRun() bool
- type PangoLayoutW
- func (l *PangoLayoutW) Close()
- func (l PangoLayoutW) GetExtents() (ink, logical C.PangoRectangle)
- func (l PangoLayoutW) GetIter() PangoLayoutIterW
- func (l PangoLayoutW) Ptr() *C.PangoLayout
- func (l PangoLayoutW) SetAlignment(align Alignment)
- func (l PangoLayoutW) SetAttributes(attrs PangoAttrListW)
- func (l PangoLayoutW) SetFontDescription(desc PangoFontDescW)
- func (l PangoLayoutW) SetIndent(indent int)
- func (l PangoLayoutW) SetMarkup(text string)
- func (l PangoLayoutW) SetTabs(tabs PangoTabArrayW)
- func (l PangoLayoutW) SetText(text string)
- func (l PangoLayoutW) SetWidth(width int)
- func (l PangoLayoutW) SetWrap(mode WrapMode)
- type PangoTabArrayW
- type Rect
- type Renderer
- func (r *Renderer) Atlas() *GlyphAtlas
- func (r *Renderer) Commit()
- func (r *Renderer) DrawComposition(layout Layout, x, y float32, cs *CompositionState, cursorColor Color)
- func (r *Renderer) DrawLayout(layout Layout, x, y float32)
- func (r *Renderer) DrawLayoutPlaced(layout Layout, placements []GlyphPlacement)
- func (r *Renderer) DrawLayoutRotated(layout Layout, x, y, angle float32)
- func (r *Renderer) DrawLayoutTransformed(layout Layout, x, y float32, transform AffineTransform)
- func (r *Renderer) DrawLayoutTransformedWithGradient(layout Layout, x, y float32, transform AffineTransform, ...)
- func (r *Renderer) DrawLayoutWithComposition(layout Layout, x, y float32, cs *CompositionState)
- func (r *Renderer) DrawLayoutWithGradient(layout Layout, x, y float32, gradient *GradientConfig)
- func (r *Renderer) Free()
- type RendererConfig
- type RichText
- type Shelf
- type StyleRun
- type TextChange
- type TextConfig
- type TextMetrics
- type TextOrientation
- type TextStyle
- type TextSystem
- func (ts *TextSystem) AddFontFile(path string) error
- func (ts *TextSystem) Commit()
- func (ts *TextSystem) Context() *Context
- func (ts *TextSystem) DrawLayout(l Layout, x, y float32)
- func (ts *TextSystem) DrawLayoutPlaced(l Layout, placements []GlyphPlacement)
- func (ts *TextSystem) DrawLayoutRotated(l Layout, x, y, angle float32)
- func (ts *TextSystem) DrawLayoutTransformed(l Layout, x, y float32, transform AffineTransform)
- func (ts *TextSystem) DrawLayoutTransformedWithGradient(l Layout, x, y float32, transform AffineTransform, gradient *GradientConfig)
- func (ts *TextSystem) DrawLayoutWithGradient(l Layout, x, y float32, gradient *GradientConfig)
- func (ts *TextSystem) DrawText(x, y float32, text string, cfg TextConfig) error
- func (ts *TextSystem) FontHeight(cfg TextConfig) (float32, error)
- func (ts *TextSystem) FontMetrics(cfg TextConfig) (TextMetrics, error)
- func (ts *TextSystem) Free()
- func (ts *TextSystem) LayoutRichText(rt RichText, cfg TextConfig) (Layout, error)
- func (ts *TextSystem) LayoutText(text string, cfg TextConfig) (Layout, error)
- func (ts *TextSystem) LayoutTextCached(text string, cfg TextConfig) (Layout, error)
- func (ts *TextSystem) Renderer() *Renderer
- func (ts *TextSystem) ResolveFontName(name string) (string, error)
- func (ts *TextSystem) TextHeight(text string, cfg TextConfig) (float32, error)
- func (ts *TextSystem) TextWidth(text string, cfg TextConfig) (float32, error)
- type TextureID
- type Typeface
- type UndoManager
- func (um *UndoManager) BreakCoalescing()
- func (um *UndoManager) CanRedo() bool
- func (um *UndoManager) CanUndo() bool
- func (um *UndoManager) Clear()
- func (um *UndoManager) FlushPending()
- func (um *UndoManager) RecordMutation(result MutationResult, inserted string, cursorBefore, anchorBefore int)
- func (um *UndoManager) Redo(text string) *UndoResult
- func (um *UndoManager) Undo(text string) *UndoResult
- func (um *UndoManager) UndoDepth() int
- type UndoOperation
- type UndoResult
- type WrapMode
Constants ¶
const ( FTPixelModeNone = C.FT_PIXEL_MODE_NONE FTPixelModeMono = C.FT_PIXEL_MODE_MONO FTPixelModeGray = C.FT_PIXEL_MODE_GRAY FTPixelModeLCD = C.FT_PIXEL_MODE_LCD FTPixelModeBGRA = C.FT_PIXEL_MODE_BGRA FTPixelModeLCDV = C.FT_PIXEL_MODE_LCD_V )
FreeType pixel modes.
const ( FTLoadDefault = C.FT_LOAD_DEFAULT FTLoadNoScale = C.FT_LOAD_NO_SCALE FTLoadNoHinting = C.FT_LOAD_NO_HINTING FTLoadRender = C.FT_LOAD_RENDER FTLoadNoBitmap = C.FT_LOAD_NO_BITMAP FTLoadForceAutohint = C.FT_LOAD_FORCE_AUTOHINT FTLoadMonochrome = C.FT_LOAD_MONOCHROME FTLoadNoAutohint = C.FT_LOAD_NO_AUTOHINT FTLoadTargetNormal = C.FT_LOAD_TARGET_NORMAL FTLoadTargetLight = C.FT_LOAD_TARGET_LIGHT FTLoadTargetMono = C.FT_LOAD_TARGET_MONO FTLoadTargetLCD = C.FT_LOAD_TARGET_LCD )
FreeType load flags.
const ( FTRenderModeNormal = C.FT_RENDER_MODE_NORMAL FTRenderModeLight = C.FT_RENDER_MODE_LIGHT FTRenderModeMono = C.FT_RENDER_MODE_MONO FTRenderModeLCD = C.FT_RENDER_MODE_LCD )
FreeType render modes.
const ( FTStrokerLineCapRound = C.FT_STROKER_LINECAP_ROUND FTStrokerLineJoinRound = C.FT_STROKER_LINEJOIN_ROUND )
FreeType stroker constants.
const ( FTFixedPointShift = 6 FTFixedPointUnit = 64 // 1 pixel in 26.6 format. FTSubpixelUnit = 16 // 0.25 pixels in 26.6. )
FreeType 26.6 fixed-point constants.
const ( // MaxTextLength is the maximum text input length (10KB) for // DoS prevention. MaxTextLength = 10240 // MaxTextureDimension is the maximum texture size in pixels. MaxTextureDimension = 16384 // MinFontSize is the minimum font size in points. MinFontSize = float32(0.1) // MaxFontSize is the maximum font size in points. MaxFontSize = float32(500.0) )
const FTFaceFlagColor = C.FT_FACE_FLAG_COLOR
FTFaceFlagColor is the FreeType face flag for color glyphs.
const MaxGlyphSize = 256
MaxGlyphSize caps individual glyph bitmaps to 256x256 pixels. This prevents a single oversized color emoji (some CBDT fonts ship 128px strikes) from consuming a disproportionate fraction of the atlas page. 256 supports up to ~256pt at 1x DPI; at 2x Retina the effective limit is ~128pt, which covers all practical UI sizes.
const PangoGlyphUnknownFlag = 0x10000000
PangoGlyphUnknownFlag is the flag bit set on glyph indices that Pango could not map to the font.
const PangoScale = C.PANGO_SCALE
PangoScale is the Pango scale factor (1024 units per em).
const SubpixelBins = 4
SubpixelBins is the number of subpixel positioning bins.
Variables ¶
This section is empty.
Functions ¶
func FCConfigAppFontAddDir ¶
FCConfigAppFontAddDir registers a font directory with FontConfig.
func FCConfigAppFontAddFile ¶
FCConfigAppFontAddFile registers a font file with FontConfig.
func GetSelectedText ¶
GetSelectedText returns the text between cursor and anchor.
func PangoAttrBackgroundNew ¶
func PangoAttrBackgroundNew(r, g, b uint16) *C.PangoAttribute
PangoAttrBackgroundNew creates a background color attribute.
func PangoAttrFontDescNew ¶
func PangoAttrFontDescNew(desc *C.PangoFontDescription) *C.PangoAttribute
PangoAttrFontDescNew creates a font description attribute.
func PangoAttrFontFeaturesNew ¶
func PangoAttrFontFeaturesNew(features string) *C.PangoAttribute
PangoAttrFontFeaturesNew creates an OpenType font features attribute.
func PangoAttrForegroundNew ¶
func PangoAttrForegroundNew(r, g, b uint16) *C.PangoAttribute
PangoAttrForegroundNew creates a foreground color attribute. Colors are 16-bit (0–65535).
func PangoAttrLetterSpacingNew ¶
func PangoAttrLetterSpacingNew(spacing int) *C.PangoAttribute
PangoAttrLetterSpacingNew creates a letter-spacing attribute (Pango units).
func PangoAttrShapeNew ¶
func PangoAttrShapeNew(ink, logical *C.PangoRectangle) *C.PangoAttribute
PangoAttrShapeNew creates a shape attribute (for inline objects).
func PangoAttrStrikethroughNew ¶
func PangoAttrStrikethroughNew(strikethrough bool) *C.PangoAttribute
PangoAttrStrikethroughNew creates a strikethrough attribute.
func PangoAttrUnderlineNew ¶
func PangoAttrUnderlineNew(style int) *C.PangoAttribute
PangoAttrUnderlineNew creates an underline attribute.
func PangoContextGetMetrics ¶
func PangoContextGetMetrics(ctx *C.PangoContext, desc *C.PangoFontDescription, lang *C.PangoLanguage) *C.PangoFontMetrics
PangoContextGetMetrics returns metrics for a font description.
func PangoContextSetBaseGravity ¶
func PangoContextSetBaseGravity(ctx *C.PangoContext)
PangoContextSetBaseGravity sets the base gravity for the context.
func PangoFCFontLockFace ¶
PangoFCFontLockFace extracts the FT_Face from a PangoFont. Caller must call PangoFCFontUnlockFace when done.
func PangoFCFontMapConfigChanged ¶
func PangoFCFontMapConfigChanged(fontMap PangoFontMapW)
PangoFCFontMapConfigChanged notifies the font map that config changed.
func PangoFCFontUnlockFace ¶
PangoFCFontUnlockFace releases the FT_Face lock.
func PangoFT2FontGetFace ¶
PangoFT2FontGetFace returns the FT_Face from a PangoFont. Deprecated but needed for cache key generation.
func PangoFontDescGetFamily ¶
func PangoFontDescGetFamily(desc *C.PangoFontDescription) string
PangoFontDescGetFamily returns the font family name.
func PangoFontDescGetSize ¶
func PangoFontDescGetSize(desc *C.PangoFontDescription) int
PangoFontDescGetSize returns the size in Pango units.
func PangoFontDescSetFamily ¶
func PangoFontDescSetFamily(desc *C.PangoFontDescription, family string)
PangoFontDescSetFamily sets the font family.
func PangoFontMetricsGetAscent ¶
func PangoFontMetricsGetAscent(m *C.PangoFontMetrics) int
PangoFontMetricsGetAscent returns ascent in Pango units.
func PangoFontMetricsGetDescent ¶
func PangoFontMetricsGetDescent(m *C.PangoFontMetrics) int
PangoFontMetricsGetDescent returns descent in Pango units.
func PangoFontMetricsGetStrikethroughPosition ¶
func PangoFontMetricsGetStrikethroughPosition(m *C.PangoFontMetrics) int
PangoFontMetricsGetStrikethroughPosition returns position in Pango units.
func PangoFontMetricsGetStrikethroughThickness ¶
func PangoFontMetricsGetStrikethroughThickness(m *C.PangoFontMetrics) int
PangoFontMetricsGetStrikethroughThickness returns thickness in Pango units.
func PangoFontMetricsGetUnderlinePosition ¶
func PangoFontMetricsGetUnderlinePosition(m *C.PangoFontMetrics) int
PangoFontMetricsGetUnderlinePosition returns position in Pango units.
func PangoFontMetricsGetUnderlineThickness ¶
func PangoFontMetricsGetUnderlineThickness(m *C.PangoFontMetrics) int
PangoFontMetricsGetUnderlineThickness returns thickness in Pango units.
func PangoGetDefaultLanguage ¶
func PangoGetDefaultLanguage() *C.PangoLanguage
PangoGetDefaultLanguage returns the default language.
func PangoLayoutGetAttributes ¶
func PangoLayoutGetAttributes(layout *C.PangoLayout) *C.PangoAttrList
PangoLayoutGetAttributes returns the attribute list from a layout.
func PangoLayoutGetContext ¶
func PangoLayoutGetContext(layout *C.PangoLayout) *C.PangoContext
PangoLayoutGetContext returns the context from a layout.
func PangoLayoutGetFontDescription ¶
func PangoLayoutGetFontDescription(layout *C.PangoLayout) *C.PangoFontDescription
PangoLayoutGetFontDescription returns the font description of a layout.
func PangoLayoutGetLineCount ¶
func PangoLayoutGetLineCount(layout *C.PangoLayout) int
PangoLayoutGetLineCount returns the number of lines.
func PangoLayoutGetLogAttrsReadonly ¶
func PangoLayoutGetLogAttrsReadonly(layout *C.PangoLayout) (*C.PangoLogAttr, int)
PangoLayoutGetLogAttrsReadonly returns readonly log attrs and count.
func ScaleBitmapBicubic ¶
ScaleBitmapBicubic scales an RGBA bitmap using bicubic (Catmull-Rom) interpolation with premultiplied alpha.
func SetDPIAwareWindows ¶
func SetDPIAwareWindows()
SetDPIAwareWindows is a no-op on non-Windows platforms. On Windows it marks the process as per-monitor DPI aware v2 so windows render at native physical resolution. See dpi_windows.go.
func ValidateDimension ¶
ValidateDimension validates an integer dimension (width/height).
func ValidateFontPath ¶
ValidateFontPath validates a font file path for safety and existence.
func ValidateSize ¶
ValidateSize validates a numeric size against min/max bounds.
Types ¶
type AffineTransform ¶
AffineTransform encodes a 2D affine transform matrix:
[ XX XY X0 ] [ YX YY Y0 ] [ 0 0 1 ]
func AffineIdentity ¶
func AffineIdentity() AffineTransform
AffineIdentity returns an identity transform.
func AffineRotation ¶
func AffineRotation(angle float32) AffineTransform
AffineRotation returns a rotation transform in radians around origin.
func AffineSkew ¶
func AffineSkew(skewX, skewY float32) AffineTransform
AffineSkew returns a shear transform with direct skew factors.
func AffineTranslation ¶
func AffineTranslation(dx, dy float32) AffineTransform
AffineTranslation returns a translation transform.
func (AffineTransform) Apply ¶
func (a AffineTransform) Apply(x, y float32) (float32, float32)
Apply maps a point through the affine transform.
func (AffineTransform) Multiply ¶
func (a AffineTransform) Multiply(b AffineTransform) AffineTransform
Multiply returns the composition of two transforms: a then b. Result maps point p as: Multiply(a, b).Apply(p) == a.Apply(b.Apply(p)).
type Alignment ¶
type Alignment int
Alignment specifies horizontal text alignment within the layout box.
type AtlasPage ¶
type AtlasPage struct {
Shelves []Shelf
StagingFront []byte // GPU upload source.
StagingBack []byte // CPU rasterization target.
TextureID TextureID
Width int
Height int
Age uint64 // Frame counter when last used.
UsedPixels int64
Dirty bool
}
AtlasPage is a single texture page in a multi-page glyph atlas.
type Bitmap ¶
Bitmap holds RGBA pixel data for a rasterized glyph.
func FTBitmapToBitmap ¶
FTBitmapToBitmap converts a raw FreeType bitmap (GRAY, MONO, LCD, or BGRA) into a uniform 32-bit RGBA Bitmap.
Supported pixel modes:
- GRAY: RGB=255, A=gamma[gray]. For tinting via vertex color.
- MONO: 1-bit expanded to 0 or 255 alpha.
- LCD: 3x-width subpixel bitmap flattened to RGBA.
- BGRA: Color emoji bitmaps, BGRA→RGBA swizzle.
type BlockStyle ¶
type BlockStyle struct {
Tabs []int
Align Alignment
Wrap WrapMode
// Width is the wrapping width. -1 = no wrapping.
Width float32
// Indent determines first-line indentation. Negative = hanging indent.
Indent float32
// LineSpacing adds extra vertical space after each line except the last.
LineSpacing float32
}
BlockStyle defines paragraph-level layout properties.
func DefaultBlockStyle ¶
func DefaultBlockStyle() BlockStyle
DefaultBlockStyle returns a BlockStyle with standard defaults.
type CachedGlyph ¶
type CachedGlyph struct {
X int
Y int
Width int
Height int
Left int // Bitmap left bearing.
Top int // Bitmap top bearing.
Page int // Atlas page index.
}
CachedGlyph stores atlas coordinates and bearing info for a rasterized glyph.
type Clause ¶
type Clause struct {
Start int
Length int
Style ClauseStyle
}
Clause represents a segment in multi-clause CJK composition.
type ClauseRects ¶
type ClauseRects struct {
Rects []Rect
ClauseIdx int
Style ClauseStyle
}
ClauseRects holds clause index, rects, and style for rendering.
type ClauseStyle ¶
type ClauseStyle int
ClauseStyle identifies the visual style of an IME clause.
const ( ClauseRaw ClauseStyle = iota // Unconverted input. ClauseConverted // Converted but not selected. ClauseSelected // Currently selected clause. )
type Color ¶
type Color struct {
R, G, B, A uint8
}
Color is an RGBA color with 8-bit channels.
func GradientColorAt ¶
func GradientColorAt(stops []GradientStop, t float32) Color
GradientColorAt samples the gradient at normalized position t.
type CompositionPhase ¶
type CompositionPhase int
CompositionPhase tracks IME preedit state.
const ( CompositionNone CompositionPhase = iota CompositionStarted CompositionUpdating CompositionCommitted )
type CompositionState ¶
type CompositionState struct {
PreeditText string
Clauses []Clause
Phase CompositionPhase
PreeditStart int
CursorOffset int
SelectedClause int
}
CompositionState tracks IME composition for preedit display.
func NewCompositionState ¶
func NewCompositionState() CompositionState
NewCompositionState returns an initialized CompositionState.
func (*CompositionState) ClearClauses ¶
func (cs *CompositionState) ClearClauses()
ClearClauses resets clause array for fresh enumeration.
func (*CompositionState) Commit ¶
func (cs *CompositionState) Commit() string
Commit finalizes composition, returns text to insert.
func (*CompositionState) CompositionBounds ¶
func (cs *CompositionState) CompositionBounds(layout Layout) (Rect, bool)
CompositionBounds returns bounding rect covering entire preedit. Returns ok=false if not composing.
func (*CompositionState) DocumentCursorPos ¶
func (cs *CompositionState) DocumentCursorPos() int
DocumentCursorPos returns absolute cursor position in document.
func (*CompositionState) GetClauseRects ¶
func (cs *CompositionState) GetClauseRects(layout Layout) []ClauseRects
GetClauseRects returns selection rects for each clause.
func (*CompositionState) HandleClause ¶
func (cs *CompositionState) HandleClause(start, length, style int)
HandleClause processes clause info from IME overlay.
func (*CompositionState) HandleInsertText ¶
func (cs *CompositionState) HandleInsertText(text string) string
HandleInsertText processes insertText from IME overlay.
func (*CompositionState) HandleMarkedText ¶
func (cs *CompositionState) HandleMarkedText(text string, cursorInPreedit, documentCursor int)
HandleMarkedText processes setMarkedText from IME overlay.
func (*CompositionState) HandleUnmarkText ¶
func (cs *CompositionState) HandleUnmarkText()
HandleUnmarkText cancels composition without committing.
func (*CompositionState) IsComposing ¶
func (cs *CompositionState) IsComposing() bool
IsComposing returns true if composition is active.
func (*CompositionState) PreeditEnd ¶
func (cs *CompositionState) PreeditEnd() int
PreeditEnd returns byte offset where preedit ends in document.
func (*CompositionState) Reset ¶
func (cs *CompositionState) Reset()
Reset discards composition without inserting text.
func (*CompositionState) SetClauses ¶
func (cs *CompositionState) SetClauses(clauses []Clause, selected int)
SetClauses updates clause segmentation from IME attributes.
func (*CompositionState) SetMarkedText ¶
func (cs *CompositionState) SetMarkedText(text string, cursorInPreedit int)
SetMarkedText updates preedit from IME.
func (*CompositionState) Start ¶
func (cs *CompositionState) Start(cursorPos int)
Start begins composition at document cursor position.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context holds the Pango and FreeType state needed for text shaping. Keep alive for application duration.
Not safe for concurrent use.
func NewContext ¶
NewContext initializes FreeType, Pango font map, and Pango context. scaleFactor is the display DPI scale (1.0 = 72 DPI, 2.0 = Retina).
func (*Context) AddFontFile ¶
AddFontFile loads a font file via FontConfig.
func (*Context) FontHeight ¶
func (ctx *Context) FontHeight(cfg TextConfig) (float32, error)
FontHeight returns ascent + descent in logical pixels for the font described by cfg.
func (*Context) FontMetrics ¶
func (ctx *Context) FontMetrics(cfg TextConfig) (TextMetrics, error)
FontMetrics returns detailed metrics (ascender, descender, height, line gap) in logical pixels.
func (*Context) LayoutRichText ¶
func (ctx *Context) LayoutRichText(rt RichText, cfg TextConfig) (Layout, error)
LayoutRichText shapes multi-styled text (RichText).
func (*Context) LayoutText ¶
func (ctx *Context) LayoutText(text string, cfg TextConfig) (Layout, error)
LayoutText shapes, wraps, and arranges text using Pango. Returns a Layout with positioned glyph runs, hit-test rects, line boundaries, and cursor attributes.
func (*Context) ResolveFontName ¶
ResolveFontName returns the FreeType family name that Pango resolves for the given font description string.
func (*Context) ScaleFactor ¶
ScaleFactor returns the DPI scale factor.
type CursorPosition ¶
CursorPosition represents the geometry for rendering a text cursor.
type DeadKeyState ¶
DeadKeyState tracks pending dead key for accent composition.
func (*DeadKeyState) StartDeadKey ¶
func (dks *DeadKeyState) StartDeadKey(dead rune, pos int)
StartDeadKey records a dead key press.
func (*DeadKeyState) TryCombine ¶
func (dks *DeadKeyState) TryCombine(base rune) (string, bool)
TryCombine attempts to combine pending dead key with base char. Returns (result, wasCombined). If invalid: returns both chars.
type DrawBackend ¶
type DrawBackend interface {
// NewTexture allocates a new RGBA texture of the given size.
NewTexture(width, height int) TextureID
// UpdateTexture uploads RGBA pixel data to an existing texture.
// data must be width*height*4 bytes.
UpdateTexture(id TextureID, data []byte)
// DeleteTexture releases a texture.
DeleteTexture(id TextureID)
// DrawTexturedQuad draws a textured rectangle with color tinting.
DrawTexturedQuad(id TextureID, src, dst Rect, c Color)
// DrawFilledRect draws an untextured filled rectangle.
DrawFilledRect(dst Rect, c Color)
// DrawTexturedQuadTransformed draws a textured quad with an
// affine transform applied.
DrawTexturedQuadTransformed(id TextureID, src, dst Rect, c Color, t AffineTransform)
// DPIScale returns the display DPI scale factor.
DPIScale() float32
}
DrawBackend abstracts the GPU rendering backend. Implementations provide texture management and drawing primitives. The Renderer calls only these methods — never a specific backend directly.
type FTFace ¶
type FTFace struct {
// contains filtered or unexported fields
}
FTFace wraps FT_Face.
type FTLibrary ¶
type FTLibrary struct {
// contains filtered or unexported fields
}
FTLibrary wraps FT_Library with explicit Close.
func InitFreeType ¶
InitFreeType initializes a new FreeType library instance.
type FTStroker ¶
type FTStroker struct {
// contains filtered or unexported fields
}
FTStroker wraps FT_Stroker with explicit Close.
func NewFTStroker ¶
NewFTStroker creates a new FreeType stroker.
type FontFeature ¶
FontFeature represents an OpenType feature tag and value.
type FontFeatures ¶
type FontFeatures struct {
OpenTypeFeatures []FontFeature
VariationAxes []FontAxis
}
FontFeatures holds OpenType features and variable font axes.
type FontMetricsEntry ¶
type FontMetricsEntry struct {
Ascent int // Pango units.
Descent int // Pango units.
LineGap int // Pango units (0 if not available).
}
FontMetricsEntry stores cached font metrics in Pango units.
type Glyph ¶
type Glyph struct {
Index uint32
XOffset float64
YOffset float64
XAdvance float64
YAdvance float64
Codepoint uint32 // Cluster byte length (use with Index as byte offset).
GlyphID uint16 // Resolved CGGlyph/HB glyph ID (0 = unknown, use text).
}
Glyph holds a shaped glyph index and its positioning offsets.
type GlyphAtlas ¶
type GlyphAtlas struct {
Backend DrawBackend
Pages []AtlasPage
Garbage []TextureID // Textures pending deletion.
MaxPages int
CurrentPage int
FrameCounter uint64
MaxGlyphDimension int
LastFrame uint64
}
GlyphAtlas manages a multi-page texture atlas for glyph bitmaps.
Not safe for concurrent use. Accessed only through Renderer.
func NewGlyphAtlas ¶
func NewGlyphAtlas(backend DrawBackend, w, h int) (*GlyphAtlas, error)
NewGlyphAtlas creates a new glyph atlas with one initial page. Dimensions are rounded up to the next power of two to satisfy GPU texture alignment requirements (most drivers silently round up non-power-of-two textures, wasting VRAM). Dimensions below 64 are clamped to 64.
func (*GlyphAtlas) Cleanup ¶
func (atlas *GlyphAtlas) Cleanup(frame uint64)
Cleanup removes stale textures from previous frames.
func (*GlyphAtlas) InsertBitmap ¶
func (atlas *GlyphAtlas) InsertBitmap(bmp Bitmap, left, top int) (CachedGlyph, bool, int, error)
InsertBitmap places a bitmap into the atlas using shelf-based best-height-fit with multi-page support. Returns the CachedGlyph, whether a page reset occurred, and the index of the reset page.
func (*GlyphAtlas) SwapAndUpload ¶
func (atlas *GlyphAtlas) SwapAndUpload()
SwapAndUpload swaps staging buffers and uploads dirty pages to the GPU.
type GlyphInfo ¶
type GlyphInfo struct {
X float32
Y float32 // Baseline y.
Advance float32
Index int // Index into Layout.Glyphs.
}
GlyphInfo provides the absolute position and advance of a glyph within a Layout. Returned by GlyphPositions.
type GlyphPlacement ¶
type GlyphPlacement struct {
X float32 // Absolute screen x.
Y float32 // Absolute screen y (baseline).
Angle float32 // Rotation in radians, 0 = upright.
}
GlyphPlacement specifies absolute screen position and rotation for a single glyph. Used with DrawLayoutPlaced for text-on-curve.
type GradientConfig ¶
type GradientConfig struct {
Stops []GradientStop
Direction GradientDirection
}
GradientConfig defines an N-stop gradient for text rendering. Stops must be sorted by position in ascending order.
type GradientDirection ¶
type GradientDirection int
GradientDirection controls the axis of color interpolation.
const ( GradientHorizontal GradientDirection = iota // Left to right. GradientVertical // Top to bottom. GradientDiagonal // Top-left to bottom-right. )
type GradientStop ¶
GradientStop defines a color at a normalized position (0.0–1.0).
type InlineObject ¶
type InlineObject struct {
ID string
Width float32 // Points.
Height float32
Offset float32 // Baseline offset.
}
InlineObject represents an embedded non-text element in a layout.
type Item ¶
type Item struct {
Style TextStyle
FTFace unsafe.Pointer // *C.FT_FaceRec, set during layout.
RunText string
ObjectID string
CSSFont string // WASM only: CSS font string for glyph rasterization.
Width float64
X float64 // Run position relative to layout.
Y float64 // Baseline y relative to layout.
Ascent float64
Descent float64
GlyphStart int
GlyphCount int
StartIndex int
Length int
// Decoration metrics.
UnderlineOffset float64
UnderlineThickness float64
StrikethroughOffset float64
StrikethroughThickness float64
StrokeWidth float32
Color Color
BgColor Color
StrokeColor Color
HasUnderline bool
HasStrikethrough bool
HasBgColor bool
HasStroke bool
UseOriginalColor bool // True for emoji — skip tinting.
IsObject bool
}
Item is a run of glyphs sharing the same font and attributes.
type Layout ¶
type Layout struct {
CharRectByIndex map[int]int // byte index → CharRects index
LogAttrByIndex map[int]int // byte index → LogAttrs index
Text string
ClonedObjectIDs []string
Items []Item
Glyphs []Glyph
CharRects []CharRect
Lines []Line
LogAttrs []LogAttr
Width float32 // Logical width.
Height float32 // Logical height.
VisualWidth float32 // Ink width.
VisualHeight float32 // Ink height.
// contains filtered or unexported fields
}
Layout is the result of text shaping. It contains positioned glyph runs, hit-test rectangles, line boundaries, and cursor attributes.
func (*Layout) GetCharRect ¶
GetCharRect returns the bounding box for a character at byte index. Returns ok=false if index is not a valid character position.
func (*Layout) GetClosestOffset ¶
GetClosestOffset returns the byte index of the character closest to (x, y). Handles clicks outside bounds.
func (*Layout) GetCursorPos ¶
func (l *Layout) GetCursorPos(byteIndex int) (CursorPosition, bool)
GetCursorPos returns cursor geometry at byte_index. Returns ok=false if not a valid cursor position.
func (*Layout) GetFontNameAtIndex ¶
GetFontNameAtIndex returns the font family name at byte index.
func (*Layout) GetParagraphAtIndex ¶
GetParagraphAtIndex returns (start, end) byte indices for paragraph containing index. Paragraph = text between \n\n.
func (*Layout) GetSelectionRects ¶
GetSelectionRects returns rectangles covering [start, end).
func (*Layout) GetValidCursorPositions ¶
GetValidCursorPositions returns sorted byte indices that are valid cursor positions. Uses pre-built cache.
func (*Layout) GetWordAtIndex ¶
GetWordAtIndex returns (start, end) byte indices for word containing index. Returns (index, index) if not in a word.
func (*Layout) GlyphPositions ¶
GlyphPositions returns the absolute position, advance, and index of every glyph in the layout.
func (*Layout) HitTest ¶
HitTest returns the byte index of the character at (x, y) relative to origin. Returns -1 if no character is found.
func (*Layout) HitTestRect ¶
HitTestRect returns the bounding box of the character at (x, y) relative to the layout origin. Returns ok=false if no character is found.
func (*Layout) MoveCursorDown ¶
MoveCursorDown returns byte index on next line at similar x.
func (*Layout) MoveCursorLeft ¶
MoveCursorLeft returns the previous valid cursor position.
func (*Layout) MoveCursorLineEnd ¶
MoveCursorLineEnd returns the end of the current line. At a soft-wrap boundary the later line is preferred.
func (*Layout) MoveCursorLineStart ¶
MoveCursorLineStart returns the start of the current line. At a soft-wrap boundary the later line is preferred.
func (*Layout) MoveCursorRight ¶
MoveCursorRight returns the next valid cursor position.
func (*Layout) MoveCursorUp ¶
MoveCursorUp returns byte index on previous line at similar x. Pass preferredX < 0 to use cursor's current x.
func (*Layout) MoveCursorWordLeft ¶
MoveCursorWordLeft returns the previous word start.
func (*Layout) MoveCursorWordRight ¶
MoveCursorWordRight returns the next word start.
type Line ¶
type Line struct {
StartIndex int
Length int
Rect Rect // Logical bounding box relative to layout.
IsParagraphStart bool
}
Line describes one line of a laid-out paragraph.
type LoadGlyphConfig ¶
type LoadGlyphConfig struct {
Face C.FT_Face // Borrowed from Pango; do not free.
Index uint32
TargetHeight int
SubpixelBin int // 0..3 → 0, 0.25, 0.5, 0.75 px shift.
}
LoadGlyphConfig holds parameters for glyph rasterization.
type LoadGlyphResult ¶
type LoadGlyphResult struct {
Cached CachedGlyph
ResetOccurred bool
ResetPage int
}
LoadGlyphResult holds the output of a glyph load operation.
func LoadGlyph ¶
func LoadGlyph(atlas *GlyphAtlas, cfg LoadGlyphConfig, scaleFactor float32) (LoadGlyphResult, error)
LoadGlyph rasterizes a glyph via FreeType and inserts it into the atlas.
Hybrid hinting strategy:
- High DPI (>= 2.0): FT_LOAD_TARGET_LCD for subpixel.
- Low DPI (< 2.0): FT_LOAD_TARGET_LIGHT for auto-hinting.
Subpixel positioning: bins 0–3 shift the outline by 0/0.25/0.5/0.75 pixels before rendering.
func LoadStrokedGlyph ¶
func LoadStrokedGlyph(atlas *GlyphAtlas, stroker FTStroker, cfg LoadGlyphConfig, strokeRadius int64, scaleFactor float32) (LoadGlyphResult, error)
LoadStrokedGlyph rasterizes a stroked (outline-only) glyph via FT_Stroker and inserts it into the atlas.
type MutationResult ¶
type MutationResult struct {
NewText string
DeletedText string
CursorPos int
RangeStart int
RangeEnd int
}
MutationResult contains the result of applying a text mutation.
func CutSelection ¶
func CutSelection(text string, cursor, anchor int) (string, MutationResult)
CutSelection removes selected text and returns it for clipboard.
func DeleteBackward ¶
func DeleteBackward(text string, layout Layout, cursor int) MutationResult
DeleteBackward removes one grapheme cluster before cursor (Backspace). Uses layout.MoveCursorLeft for grapheme boundary.
func DeleteForward ¶
func DeleteForward(text string, layout Layout, cursor int) MutationResult
DeleteForward removes one grapheme cluster after cursor (Delete).
func DeleteSelection ¶
func DeleteSelection(text string, cursor, anchor int) MutationResult
DeleteSelection removes text between cursor and anchor.
func DeleteToLineEnd ¶
func DeleteToLineEnd(text string, layout Layout, cursor int) MutationResult
DeleteToLineEnd removes text from cursor to line end (Cmd+Delete).
func DeleteToLineStart ¶
func DeleteToLineStart(text string, layout Layout, cursor int) MutationResult
DeleteToLineStart removes text from cursor to line start (Cmd+Backspace).
func DeleteToWordBoundary ¶
func DeleteToWordBoundary(text string, layout Layout, cursor int) MutationResult
DeleteToWordBoundary removes text from cursor to previous word boundary (Option+Backspace).
func DeleteToWordEnd ¶
func DeleteToWordEnd(text string, layout Layout, cursor int) MutationResult
DeleteToWordEnd removes text from cursor to next word boundary (Option+Delete).
func InsertReplacingSelection ¶
func InsertReplacingSelection(text string, cursor, anchor int, insert string) MutationResult
InsertReplacingSelection inserts text, replacing any selection.
func InsertText ¶
func InsertText(text string, cursor int, insert string) MutationResult
InsertText inserts a string at cursor position.
func (MutationResult) ToChange ¶
func (m MutationResult) ToChange(inserted string) TextChange
ToChange converts a MutationResult to a TextChange.
type OperationType ¶
type OperationType int
OperationType identifies the kind of undo operation.
const ( OpInsert OperationType = iota OpDelete OpReplace )
type PangoAttrListW ¶
type PangoAttrListW struct {
// contains filtered or unexported fields
}
PangoAttrListW wraps *PangoAttrList.
func NewPangoAttrList ¶
func NewPangoAttrList() PangoAttrListW
NewPangoAttrList creates a new attribute list.
func PangoAttrListCopy ¶
func PangoAttrListCopy(list *C.PangoAttrList) PangoAttrListW
PangoAttrListCopy copies a PangoAttrList.
func (PangoAttrListW) Insert ¶
func (a PangoAttrListW) Insert(attr *C.PangoAttribute)
Insert adds an attribute to the list. The list takes ownership.
type PangoContextW ¶
type PangoContextW struct {
// contains filtered or unexported fields
}
PangoContextW wraps *PangoContext.
func (*PangoContextW) Ptr ¶
func (c *PangoContextW) Ptr() *C.PangoContext
Ptr returns the raw C pointer.
type PangoFontDescW ¶
type PangoFontDescW struct {
// contains filtered or unexported fields
}
PangoFontDescW wraps *PangoFontDescription.
func NewPangoFontDescFromString ¶
func NewPangoFontDescFromString(desc string) PangoFontDescW
NewPangoFontDescFromString parses a Pango font description string.
func PangoFontDescNew ¶
func PangoFontDescNew() PangoFontDescW
PangoFontDescNew creates a new empty font description.
func (PangoFontDescW) SetSize ¶
func (d PangoFontDescW) SetSize(size int)
SetSize sets the font size in Pango units.
func (PangoFontDescW) SetStyle ¶
func (d PangoFontDescW) SetStyle(style int)
SetStyle sets the font style (normal/italic/oblique).
func (PangoFontDescW) SetVariations ¶
func (d PangoFontDescW) SetVariations(variations string)
SetVariations sets font variation axes string.
func (PangoFontDescW) SetWeight ¶
func (d PangoFontDescW) SetWeight(weight int)
SetWeight sets the font weight.
type PangoFontMapW ¶
type PangoFontMapW struct {
// contains filtered or unexported fields
}
PangoFontMapW wraps *PangoFontMap (the W suffix avoids conflict with the C type).
func NewPangoFT2FontMap ¶
func NewPangoFT2FontMap() PangoFontMapW
NewPangoFT2FontMap creates a new Pango FT2 font map.
func (PangoFontMapW) CreateContext ¶
func (m PangoFontMapW) CreateContext() PangoContextW
CreateContext creates a PangoContext from this font map.
func (PangoFontMapW) SetResolution ¶
func (m PangoFontMapW) SetResolution(dpiX, dpiY float64)
SetResolution sets the DPI resolution on the font map.
type PangoFontMetricsW ¶
type PangoFontMetricsW struct {
// contains filtered or unexported fields
}
PangoFontMetricsW wraps *PangoFontMetrics.
func PangoFontGetMetrics ¶
func PangoFontGetMetrics(font *C.PangoFont, lang *C.PangoLanguage) PangoFontMetricsW
PangoFontGetMetrics returns metrics for the font and language.
type PangoFontW ¶
type PangoFontW struct {
// contains filtered or unexported fields
}
PangoFontW wraps *PangoFont.
func PangoContextLoadFont ¶
func PangoContextLoadFont(ctx *C.PangoContext, desc *C.PangoFontDescription) PangoFontW
PangoContextLoadFont loads a font matching the description.
type PangoLayoutIterW ¶
type PangoLayoutIterW struct {
// contains filtered or unexported fields
}
PangoLayoutIterW wraps *PangoLayoutIter.
func (PangoLayoutIterW) GetBaseline ¶
func (it PangoLayoutIterW) GetBaseline() int
GetBaseline returns the current baseline in Pango units.
func (PangoLayoutIterW) GetCharExtents ¶
func (it PangoLayoutIterW) GetCharExtents() C.PangoRectangle
GetCharExtents returns the logical extents of the current character.
func (PangoLayoutIterW) GetIndex ¶
func (it PangoLayoutIterW) GetIndex() int
GetIndex returns the byte index of the current iterator position.
func (PangoLayoutIterW) GetLineExtents ¶
func (it PangoLayoutIterW) GetLineExtents() (ink, logical C.PangoRectangle)
GetLineExtents returns ink and logical extents of the current line.
func (PangoLayoutIterW) GetLineReadonly ¶
func (it PangoLayoutIterW) GetLineReadonly() *C.PangoLayoutLine
GetLineReadonly returns the current layout line.
func (PangoLayoutIterW) GetRunExtents ¶
func (it PangoLayoutIterW) GetRunExtents() (ink, logical C.PangoRectangle)
GetRunExtents returns ink and logical extents of the current run.
func (PangoLayoutIterW) GetRunReadonly ¶
func (it PangoLayoutIterW) GetRunReadonly() *C.PangoGlyphItem
GetRunReadonly returns the current run (may be nil for empty runs).
func (PangoLayoutIterW) NextChar ¶
func (it PangoLayoutIterW) NextChar() bool
NextChar advances to the next character.
func (PangoLayoutIterW) NextLine ¶
func (it PangoLayoutIterW) NextLine() bool
NextLine advances to the next line.
func (PangoLayoutIterW) NextRun ¶
func (it PangoLayoutIterW) NextRun() bool
NextRun advances to the next run. Returns false at end.
type PangoLayoutW ¶
type PangoLayoutW struct {
// contains filtered or unexported fields
}
PangoLayoutW wraps *PangoLayout with RAII.
func NewPangoLayout ¶
func NewPangoLayout(ctx PangoContextW) PangoLayoutW
NewPangoLayout creates a new PangoLayout for the given context.
func (PangoLayoutW) GetExtents ¶
func (l PangoLayoutW) GetExtents() (ink, logical C.PangoRectangle)
GetExtents returns ink and logical extents.
func (PangoLayoutW) GetIter ¶
func (l PangoLayoutW) GetIter() PangoLayoutIterW
GetIter returns a layout iterator.
func (PangoLayoutW) SetAlignment ¶
func (l PangoLayoutW) SetAlignment(align Alignment)
SetAlignment sets horizontal alignment.
func (PangoLayoutW) SetAttributes ¶
func (l PangoLayoutW) SetAttributes(attrs PangoAttrListW)
SetAttributes sets the attribute list.
func (PangoLayoutW) SetFontDescription ¶
func (l PangoLayoutW) SetFontDescription(desc PangoFontDescW)
SetFontDescription sets the font for the layout.
func (PangoLayoutW) SetIndent ¶
func (l PangoLayoutW) SetIndent(indent int)
SetIndent sets the first-line indent in Pango units.
func (PangoLayoutW) SetMarkup ¶
func (l PangoLayoutW) SetMarkup(text string)
SetMarkup sets the layout text with Pango markup.
func (PangoLayoutW) SetTabs ¶
func (l PangoLayoutW) SetTabs(tabs PangoTabArrayW)
SetTabs sets custom tab stops.
func (PangoLayoutW) SetText ¶
func (l PangoLayoutW) SetText(text string)
SetText sets the layout text.
func (PangoLayoutW) SetWidth ¶
func (l PangoLayoutW) SetWidth(width int)
SetWidth sets the layout width in Pango units (-1 = no wrap).
func (PangoLayoutW) SetWrap ¶
func (l PangoLayoutW) SetWrap(mode WrapMode)
SetWrap sets the wrap mode.
type PangoTabArrayW ¶
type PangoTabArrayW struct {
// contains filtered or unexported fields
}
PangoTabArrayW wraps *PangoTabArray.
func NewPangoTabArray ¶
func NewPangoTabArray(size int) PangoTabArrayW
NewPangoTabArray creates a tab array with the given number of stops.
func (PangoTabArrayW) SetTab ¶
func (t PangoTabArrayW) SetTab(index, position int)
SetTab sets a tab stop position in pixels.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer rasterizes glyphs, manages the glyph cache and atlas, and emits draw calls through the DrawBackend interface.
Not safe for concurrent use. All methods must be called from a single goroutine (typically the render/GL thread).
func NewRenderer ¶
func NewRenderer(backend DrawBackend, scaleFactor float32) (*Renderer, error)
NewRenderer creates a Renderer with default 1024x1024 atlas.
func NewRendererWithConfig ¶
func NewRendererWithConfig(backend DrawBackend, scaleFactor float32, atlasW, atlasH int, cfg RendererConfig) (*Renderer, error)
NewRendererWithConfig creates a Renderer with custom atlas size and configuration.
func (*Renderer) Atlas ¶
func (r *Renderer) Atlas() *GlyphAtlas
Atlas returns the glyph atlas for external access (e.g. debug).
func (*Renderer) Commit ¶
func (r *Renderer) Commit()
Commit uploads dirty atlas pages to the GPU. Call once per frame.
func (*Renderer) DrawComposition ¶
func (r *Renderer) DrawComposition(layout Layout, x, y float32, cs *CompositionState, cursorColor Color)
DrawComposition renders IME preedit visual feedback: clause underlines and preedit cursor. Call after DrawLayout when composition is active.
func (*Renderer) DrawLayout ¶
DrawLayout renders a Layout at (x, y) using the identity transform.
func (*Renderer) DrawLayoutPlaced ¶
func (r *Renderer) DrawLayoutPlaced(layout Layout, placements []GlyphPlacement)
DrawLayoutPlaced renders each glyph at individual placements. Decorations are skipped. placements must match layout.Glyphs length.
func (*Renderer) DrawLayoutRotated ¶
DrawLayoutRotated renders rotated by angle (radians).
func (*Renderer) DrawLayoutTransformed ¶
func (r *Renderer) DrawLayoutTransformed(layout Layout, x, y float32, transform AffineTransform)
DrawLayoutTransformed renders with an affine transform.
func (*Renderer) DrawLayoutTransformedWithGradient ¶
func (r *Renderer) DrawLayoutTransformedWithGradient(layout Layout, x, y float32, transform AffineTransform, gradient *GradientConfig)
DrawLayoutTransformedWithGradient renders with both transform and gradient.
func (*Renderer) DrawLayoutWithComposition ¶
func (r *Renderer) DrawLayoutWithComposition(layout Layout, x, y float32, cs *CompositionState)
DrawLayoutWithComposition renders a layout with preedit text. Currently draws normally; opacity reduction deferred to future.
func (*Renderer) DrawLayoutWithGradient ¶
func (r *Renderer) DrawLayoutWithGradient(layout Layout, x, y float32, gradient *GradientConfig)
DrawLayoutWithGradient renders with gradient colors.
type RendererConfig ¶
type RendererConfig struct {
MaxGlyphCacheEntries int // Default 4096, minimum 256.
}
RendererConfig configures the Renderer.
type Shelf ¶
type Shelf struct {
Y int // Vertical position of shelf top.
Height int // Shelf height (fixed at creation).
CursorX int // Next free x position.
Width int // Shelf width (page width).
}
Shelf is a horizontal strip within an atlas page.
type TextChange ¶
TextChange captures mutation info for undo support and events.
type TextConfig ¶
type TextConfig struct {
Style TextStyle
Gradient *GradientConfig // nil = no gradient.
Block BlockStyle
Orientation TextOrientation
UseMarkup bool
NoHitTesting bool
}
TextConfig holds configuration for text layout and rendering.
type TextMetrics ¶
TextMetrics contains metrics for a specific font configuration. All values are in pixels.
type TextOrientation ¶
type TextOrientation int
TextOrientation defines the flow direction of text.
const ( OrientationHorizontal TextOrientation = iota OrientationVertical // Vertical flow, upright chars (CJK). )
type TextStyle ¶
type TextStyle struct {
Features *FontFeatures
Object *InlineObject
// FontName is a Pango font description string, e.g. "Sans Italic Light 15".
FontName string
// Typeface overrides weight/style in FontName when not TypefaceRegular.
Typeface Typeface
// Size overrides the size in FontName (points). 0 = use FontName.
Size float32
// LetterSpacing is extra spacing between characters (points).
LetterSpacing float32
// StrokeWidth is outline width in points (0 = no stroke).
StrokeWidth float32
Color Color
// BgColor is the background highlight color behind the text run.
BgColor Color
StrokeColor Color
Underline bool
Strikethrough bool
}
TextStyle represents the visual style of a run of text.
type TextSystem ¶
type TextSystem struct {
// contains filtered or unexported fields
}
TextSystem is the main entry point for text rendering. It owns the Context, Renderer, and a layout cache.
Not safe for concurrent use. Callers must serialize access externally if shared across goroutines.
func NewTextSystem ¶
func NewTextSystem(backend DrawBackend) (*TextSystem, error)
NewTextSystem creates a TextSystem with default atlas size (1024x1024).
func NewTextSystemAtlasSize ¶
func NewTextSystemAtlasSize(backend DrawBackend, atlasW, atlasH int) (*TextSystem, error)
NewTextSystemAtlasSize creates a TextSystem with custom atlas dimensions.
func (*TextSystem) AddFontFile ¶
func (ts *TextSystem) AddFontFile(path string) error
AddFontFile registers a font file (TTF/OTF). Clears the layout cache to prevent stale FT_Face pointers.
func (*TextSystem) Commit ¶
func (ts *TextSystem) Commit()
Commit uploads atlas textures and prunes the layout cache. Call once per frame after all draw calls.
func (*TextSystem) Context ¶
func (ts *TextSystem) Context() *Context
Context returns the underlying Context for advanced usage.
func (*TextSystem) DrawLayout ¶
func (ts *TextSystem) DrawLayout(l Layout, x, y float32)
DrawLayout renders a pre-computed Layout at (x, y).
func (*TextSystem) DrawLayoutPlaced ¶
func (ts *TextSystem) DrawLayoutPlaced(l Layout, placements []GlyphPlacement)
DrawLayoutPlaced renders glyphs at individual placements.
func (*TextSystem) DrawLayoutRotated ¶
func (ts *TextSystem) DrawLayoutRotated(l Layout, x, y, angle float32)
DrawLayoutRotated renders rotated by angle (radians).
func (*TextSystem) DrawLayoutTransformed ¶
func (ts *TextSystem) DrawLayoutTransformed(l Layout, x, y float32, transform AffineTransform)
DrawLayoutTransformed renders with an affine transform.
func (*TextSystem) DrawLayoutTransformedWithGradient ¶
func (ts *TextSystem) DrawLayoutTransformedWithGradient( l Layout, x, y float32, transform AffineTransform, gradient *GradientConfig, )
DrawLayoutTransformedWithGradient renders with both an affine transform and gradient colors.
func (*TextSystem) DrawLayoutWithGradient ¶
func (ts *TextSystem) DrawLayoutWithGradient(l Layout, x, y float32, gradient *GradientConfig)
DrawLayoutWithGradient renders with gradient colors.
func (*TextSystem) DrawText ¶
func (ts *TextSystem) DrawText(x, y float32, text string, cfg TextConfig) error
DrawText renders text at (x, y) using configuration. Uses layout cache for repeated calls.
func (*TextSystem) FontHeight ¶
func (ts *TextSystem) FontHeight(cfg TextConfig) (float32, error)
FontHeight returns the font height (ascent + descent) in pixels.
func (*TextSystem) FontMetrics ¶
func (ts *TextSystem) FontMetrics(cfg TextConfig) (TextMetrics, error)
FontMetrics returns detailed font metrics.
func (*TextSystem) LayoutRichText ¶
func (ts *TextSystem) LayoutRichText(rt RichText, cfg TextConfig) (Layout, error)
LayoutRichText computes a Layout for multi-styled text.
func (*TextSystem) LayoutText ¶
func (ts *TextSystem) LayoutText(text string, cfg TextConfig) (Layout, error)
LayoutText computes a new Layout (bypasses cache).
func (*TextSystem) LayoutTextCached ¶
func (ts *TextSystem) LayoutTextCached(text string, cfg TextConfig) (Layout, error)
LayoutTextCached retrieves a cached layout or creates a new one.
func (*TextSystem) Renderer ¶
func (ts *TextSystem) Renderer() *Renderer
Renderer returns the underlying Renderer for advanced usage.
func (*TextSystem) ResolveFontName ¶
func (ts *TextSystem) ResolveFontName(name string) (string, error)
ResolveFontName returns the actual font family name that Pango resolves for the given description string.
func (*TextSystem) TextHeight ¶
func (ts *TextSystem) TextHeight(text string, cfg TextConfig) (float32, error)
TextHeight returns the visual height (pixels) of text.
func (*TextSystem) TextWidth ¶
func (ts *TextSystem) TextWidth(text string, cfg TextConfig) (float32, error)
TextWidth returns the width (pixels) of text if rendered with cfg.
type TextureID ¶
type TextureID uint64
TextureID is an opaque handle to a GPU texture managed by a DrawBackend.
type UndoManager ¶
type UndoManager struct {
// contains filtered or unexported fields
}
UndoManager tracks undo/redo stacks with coalescing.
func NewUndoManager ¶
func NewUndoManager(maxHistory int) *UndoManager
NewUndoManager creates an UndoManager with specified history limit.
func (*UndoManager) BreakCoalescing ¶
func (um *UndoManager) BreakCoalescing()
BreakCoalescing flushes pending operation on cursor navigation.
func (*UndoManager) CanRedo ¶
func (um *UndoManager) CanRedo() bool
CanRedo returns true if redo is possible.
func (*UndoManager) CanUndo ¶
func (um *UndoManager) CanUndo() bool
CanUndo returns true if undo is possible.
func (*UndoManager) FlushPending ¶
func (um *UndoManager) FlushPending()
FlushPending pushes pending coalescable op to undo stack.
func (*UndoManager) RecordMutation ¶
func (um *UndoManager) RecordMutation(result MutationResult, inserted string, cursorBefore, anchorBefore int)
RecordMutation tracks a mutation for undo support.
func (*UndoManager) Redo ¶
func (um *UndoManager) Redo(text string) *UndoResult
Redo reapplies an undone operation. Returns nil if nothing to redo.
func (*UndoManager) Undo ¶
func (um *UndoManager) Undo(text string) *UndoResult
Undo reverses the last operation. Returns nil if nothing to undo.
func (*UndoManager) UndoDepth ¶
func (um *UndoManager) UndoDepth() int
UndoDepth returns count of operations available for undo.
type UndoOperation ¶
type UndoOperation struct {
DeletedText string
InsertedText string
OpType OperationType
CursorBefore int
AnchorBefore int
RangeStart int
RangeEnd int
CursorAfter int
AnchorAfter int
}
UndoOperation stores inverse operation data for undo/redo.
func MutationToUndoOp ¶
func MutationToUndoOp(result MutationResult, inserted string, cursorBefore, anchorBefore int) UndoOperation
MutationToUndoOp converts a MutationResult to an UndoOperation.
type UndoResult ¶
UndoResult holds the result of an undo/redo operation.
Source Files
¶
- affine.go
- atlas.go
- backend.go
- bitmap.go
- bitmap_common.go
- cache.go
- cache_pango.go
- color.go
- composition.go
- config.go
- context.go
- doc.go
- dpi_other.go
- draw.go
- draw_composition.go
- enums.go
- gamma.go
- generate.go
- glyph.go
- gradient.go
- layout.go
- layout_attrs.go
- layout_iter.go
- layout_mutation.go
- layout_query.go
- layout_types.go
- pango.go
- pango_cgo.go
- rect.go
- renderer.go
- renderer_load.go
- undo.go
- validation.go
- validation_common.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package accessibility provides screen reader support for the glyph text rendering library.
|
Package accessibility provides screen reader support for the glyph text rendering library. |
|
backend
|
|
|
ebitengine
Package ebitengine provides an Ebitengine DrawBackend for the glyph text rendering library.
|
Package ebitengine provides an Ebitengine DrawBackend for the glyph text rendering library. |
|
gpu
Package gpu provides a raw Metal DrawBackend for the glyph text rendering library.
|
Package gpu provides a raw Metal DrawBackend for the glyph text rendering library. |
|
sdl2
Package sdl2 provides an SDL2 DrawBackend for the glyph text rendering library.
|
Package sdl2 provides an SDL2 DrawBackend for the glyph text rendering library. |
|
web
Package web provides a Canvas2D DrawBackend for browser-based rendering of go-glyph text.
|
Package web provides a Canvas2D DrawBackend for browser-based rendering of go-glyph text. |
|
Package ime provides platform-specific IME (Input Method Editor) bridges.
|
Package ime provides platform-specific IME (Input Method Editor) bridges. |


