FontVariation

package
v0.0.0-...-357ca8a Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Provides OpenType variations, simulated bold / slant, and additional font settings like OpenType features and extra spacing.

To use simulated bold font variant:

package main

import (
	"graphics.gd/classdb/Font"
	"graphics.gd/classdb/FontVariation"
	"graphics.gd/classdb/Resource"
	"graphics.gd/classdb/TextServer"
	"graphics.gd/classdb/TextServerManager"
	"graphics.gd/variant/String"
)

func ExampleFontVariation() {
	var fv = FontVariation.New()
	var ts = TextServer.Advanced(TextServerManager.GetPrimaryInterface())
	fv.SetBaseFont(Resource.Load[Font.Instance]("res://BarlowCondensed-Regular.ttf"))
	fv.SetVariationOpentype(map[any]any{
		ts.NameToTag(String.New("wght")):        900,
		ts.NameToTag(String.New("custom_hght")): 900,
	})
}

To set the coordinate of multiple variation axes:

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsFontVariation() Instance
}

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsFont

func (self *Extension[T]) AsFont() Font.Instance

func (*Extension[T]) AsFontVariation

func (self *Extension[T]) AsFontVariation() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

func (*Extension[T]) AsResource

func (self *Extension[T]) AsResource() Resource.Instance

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.FontVariation

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsFont

func (self Instance) AsFont() Font.Instance

func (Instance) AsFontVariation

func (self Instance) AsFontVariation() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResource

func (self Instance) AsResource() Resource.Instance

func (Instance) BaseFont

func (self Instance) BaseFont() Font.Instance

Base font used to create a variation. If not set, default Theme font is used.

func (Instance) BaselineOffset

func (self Instance) BaselineOffset() Float.X

Extra baseline offset (as a fraction of font height).

func (Instance) ID

func (self Instance) ID() ID

func (Instance) SetBaseFont

func (self Instance) SetBaseFont(value Font.Instance)

SetBaseFont sets the property returned by [GetBaseFont].

func (Instance) SetBaselineOffset

func (self Instance) SetBaselineOffset(value Float.X)

SetBaselineOffset sets the property returned by [GetBaselineOffset].

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetOpentypeFeatures

func (self Instance) SetOpentypeFeatures(value map[any]any)

A set of OpenType feature tags. More info: OpenType feature tags.

func (Instance) SetSpacingBottom

func (self Instance) SetSpacingBottom(value int)

Extra spacing at the bottom of the line in pixels.

func (Instance) SetSpacingGlyph

func (self Instance) SetSpacingGlyph(value int)

Extra spacing between graphical glyphs.

func (Instance) SetSpacingSpace

func (self Instance) SetSpacingSpace(value int)

Extra width of the space glyphs.

func (Instance) SetSpacingTop

func (self Instance) SetSpacingTop(value int)

Extra spacing at the top of the line in pixels.

func (Instance) SetVariationEmbolden

func (self Instance) SetVariationEmbolden(value Float.X)

SetVariationEmbolden sets the property returned by [GetVariationEmbolden].

func (Instance) SetVariationFaceIndex

func (self Instance) SetVariationFaceIndex(value int)

SetVariationFaceIndex sets the property returned by [GetVariationFaceIndex].

func (Instance) SetVariationOpentype

func (self Instance) SetVariationOpentype(value map[any]any)

SetVariationOpentype sets the property returned by [GetVariationOpentype].

func (Instance) SetVariationTransform

func (self Instance) SetVariationTransform(value Transform2D.OriginXY)

SetVariationTransform sets the property returned by [GetVariationTransform].

func (Instance) VariationEmbolden

func (self Instance) VariationEmbolden() Float.X

If is not equal to zero, emboldens the font outlines. Negative values reduce the outline thickness.

Note: Emboldened fonts might have self-intersecting outlines, which will prevent MSDF fonts and TextMesh from working correctly.

func (Instance) VariationFaceIndex

func (self Instance) VariationFaceIndex() int

Active face index in the TrueType / OpenType collection file.

func (Instance) VariationOpentype

func (self Instance) VariationOpentype() map[any]any

Font OpenType variation coordinates. More info: OpenType variation tags.

Note: This data structure uses OpenType tags as keys. Variation axes can be identified both by tags (int, e.g. 0x77678674) and names (string, e.g. wght). Some axes might be accessible by multiple names. For example, wght refers to the same axis as weight. Tags on the other hand are unique. To convert between names and tags, use TextServer.NameToTag and TextServer.TagToName.

Note: To get available variation axes of a font, use Font.GetSupportedVariationList.

func (Instance) VariationTransform

func (self Instance) VariationTransform() Transform2D.OriginXY

2D transform, applied to the font outlines, can be used for slanting, flipping and rotating glyphs.

For example, to simulate italic typeface by slanting, apply the following transform Transform2D(1.0, slant, 0.0, 1.0, 0.0, 0.0).

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

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