glyphs

package
v0.0.0-...-c384780 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGlyphsPerBatch = 4 * 1024
)
View Source
const UnicodeVersion = "13.0.0"

Variables

View Source
var PrintPositions bool

@Debug

View Source
var (
	RuneInfos map[rune]RuneInfo
)

Functions

func DrawHorizontalLine

func DrawHorizontalLine(img *image.RGBA, posY int, color color.NRGBA)

func DrawRect

func DrawRect(img *image.RGBA, rect image.Rectangle, color color.NRGBA)

func DrawVerticalLine

func DrawVerticalLine(img *image.RGBA, posX int, color color.NRGBA)

func I26_6ToF32

func I26_6ToF32(x fixed.Int26_6) float32

func ParseArabicShaping

func ParseArabicShaping(arabicShapingFile string) (map[rune]ArabicShapingInfo, error)

func ParseUnicodeData

func ParseUnicodeData(unicodeDataFile, arabicShapingFile string, rangesToLoad ...*unicode.RangeTable) (map[rune]RuneInfo, error)

ParseUnicodeData decodes a 'UnicodeData' file according to http://www.unicode.org/Public/3.0-Update/UnicodeData-3.0.0.html and returns a map containing information on all runes within the passed ranges. If no ranges are passed then the full unicode data file will be decoded.

Any runes that don't fall in a script range are ignored (usually only a handful).

The latest file can be found at https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt

func PropertyTableFromRune

func PropertyTableFromRune(r rune) *unicode.RangeTable

func SaveImgToPNG

func SaveImgToPNG(img image.Image, file string) error

func ScriptTableFromRune

func ScriptTableFromRune(r rune) *unicode.RangeTable

Types

type ArabicShapingInfo

type ArabicShapingInfo struct {
	JoinType JoiningType
}

type BidiCategory

type BidiCategory uint8
const (
	BidiCategory_L   BidiCategory = iota // Left-to-Right
	BidiCategory_LRE                     // Left-to-Right Embedding
	BidiCategory_LRO                     // Left-to-Right Override
	BidiCategory_LRI                     // Left‑to‑Right Isolate
	BidiCategory_R                       // Right-to-Left
	BidiCategory_AL                      // Right-to-Left Arabic
	BidiCategory_RLE                     // Right-to-Left Embedding
	BidiCategory_RLO                     // Right-to-Left Override
	BidiCategory_RLI                     // Right-to-Left Isolate
	BidiCategory_PDF                     // Pop Directional Format
	BidiCategory_PDI                     // Pop Directional Isolate
	BidiCategory_FSI                     // First Strong Isolate
	BidiCategory_EN                      // European Number
	BidiCategory_ES                      // European Number Separator
	BidiCategory_ET                      // European Number Terminator
	BidiCategory_AN                      // Arabic Number
	BidiCategory_CS                      // Common Number Separator
	BidiCategory_LRM                     // Left-to-Right Mark
	BidiCategory_RLM                     // Right-to-Left Mark
	BidiCategory_ALM                     // Arabic Letter Mark

	BidiCategory_NSM // Non-Spacing Mark
	BidiCategory_BN  // Boundary Neutral
	BidiCategory_B   // Paragraph Separator
	BidiCategory_S   // Segment Separator
	BidiCategory_WS  // Whitespace
	BidiCategory_ON  // Other Neutrals
)

type Category

type Category uint8
const (
	//Normative categories
	Category_Lu Category = iota // Letter, Uppercase
	Category_Ll                 // Letter, Lowercase
	Category_Lt                 // Letter, Titlecase
	Category_Mn                 // Mark, Non-Spacing
	Category_Mc                 // Mark, Spacing Combining
	Category_Me                 // Mark, Enclosing
	Category_Nd                 // Number, Decimal Digit
	Category_Nl                 // Number, Letter
	Category_No                 // Number, Other
	Category_Zs                 // Separator, Space
	Category_Zl                 // Separator, Line
	Category_Zp                 // Separator, Paragraph
	Category_Cc                 // Other, Control
	Category_Cf                 // Other, Format
	Category_Cs                 // Other, Surrogate
	Category_Co                 // Other, Private Use
	Category_Cn                 // Other, Not Assigned (no characters in the file have this property)

	//Informative categories
	Category_Lm // Letter, Modifier
	Category_Lo // Letter, Other
	Category_Pc // Punctuation, Connector
	Category_Pd // Punctuation, Dash
	Category_Ps // Punctuation, Open
	Category_Pe // Punctuation, Close
	Category_Pi // Punctuation, Initial quote (may behave like Ps or Pe depending on usage)
	Category_Pf // Punctuation, Final quote (may behave like Ps or Pe depending on usage)
	Category_Po // Punctuation, Other
	Category_Sm // Symbol, Math
	Category_Sc // Symbol, Currency
	Category_Sk // Symbol, Modifier
	Category_So // Symbol, Other
)

type DecompTag

type DecompTag uint8
const (
	DecompTag_font     DecompTag = iota // A font variant (e.g. a blackletter form).
	DecompTag_noBreak                   // A no-break version of a space or hyphen.
	DecompTag_initial                   // An initial presentation form (Arabic).
	DecompTag_medial                    // A medial presentation form (Arabic).
	DecompTag_final                     // A final presentation form (Arabic).
	DecompTag_isolated                  // An isolated presentation form (Arabic).
	DecompTag_circle                    // An encircled form.
	DecompTag_super                     // A superscript form.
	DecompTag_sub                       // A subscript form.
	DecompTag_vertical                  // A vertical layout presentation form.
	DecompTag_wide                      // A wide (or zenkaku) compatibility character.
	DecompTag_narrow                    // A narrow (or hankaku) compatibility character.
	DecompTag_small                     // A small variant form (CNS compatibility).
	DecompTag_square                    // A CJK squared font variant.
	DecompTag_fraction                  // A vulgar fraction form.
	DecompTag_compat                    // Otherwise unspecified compatibility character.
	DecompTag_NONE                      // Not decomposition mapping tag, which indicates canonical form.
)

func (DecompTag) String

func (cd DecompTag) String() string

type FontAtlas

type FontAtlas struct {
	Font *truetype.Font
	Face font.Face
	Img  *image.RGBA
	// A map version of nset (https://github.com/bloeys/nset) would be amazing here
	Glyphs map[rune]FontAtlasGlyph

	//SpaceAdvance is the advance of a space char
	SpaceAdvance float32
	//LineHeight is the height of metrics.Height
	LineHeight float32
}

func NewFontAtlasFromFile

func NewFontAtlasFromFile(fontFile string, fontOptions *truetype.Options) (*FontAtlas, error)

NewFontAtlasFromFile reads a TTF or TTC file and produces a font texture atlas containing all its characters using the specified options. The atlas uses equally sized tiles such that all characters use an equal horizontal/vertical on the atlas. If the character is smaller than the tile then the rest of the tile is empty.

Only monospaced fonts are supported

func NewFontAtlasFromFont

func NewFontAtlasFromFont(f *truetype.Font, face font.Face, pointSize uint) (*FontAtlas, error)

NewFontAtlasFromFont uses the passed font to produce a font texture atlas containing all its characters using the specified options. The atlas uses equally sized tiles such that all characters use an equal horizontal/vertical on the atlas. If the character is smaller than the tile then the rest of the tile is empty.

Only monospaced fonts are supported.

type FontAtlasGlyph

type FontAtlasGlyph struct {
	Rune  rune
	U     float32
	V     float32
	SizeU float32
	SizeV float32

	Ascent   float32
	Descent  float32
	BearingX float32
	Advance  float32
}

func GlyphFromRunes

func GlyphFromRunes(glyphTable map[rune]FontAtlasGlyph, curr, prev, next rune) FontAtlasGlyph

GlyphFromRunes does shaping where it selects the proper rune based (e.g. end Alef) on the surrounding runes

type GlyphRend

type GlyphRend struct {
	Atlas    *FontAtlas
	AtlasTex *assets.Texture

	GlyphMesh           *meshes.Mesh
	GlyphFgInstancedBuf buffers.Buffer
	GlyphBgInstancedBuf buffers.Buffer
	GlyphMat            *materials.Material
	TextRunsBuf         []TextRun

	//Luckily slices still work with go-opengl, so for now we will use our slice as an array (no appending)
	GlyphFgCount uint32
	GlyphFgVBO   []float32

	GlyphBgCount uint32
	GlyphBgVBO   []float32

	ScreenWidth  int32
	ScreenHeight int32

	SpacesPerTab uint

	Opts      GlyphRendOpt
	OptValues GlyphRendOptValues
}

func NewGlyphRend

func NewGlyphRend(fontFile string, fontOptions *truetype.Options, screenWidth, screenHeight int32) (*GlyphRend, error)

func (*GlyphRend) Draw

func (gr *GlyphRend) Draw()

func (*GlyphRend) DrawTextOpenGL01

func (gr *GlyphRend) DrawTextOpenGL01(text []rune, screenPos *gglm.Vec3, color *gglm.Vec4) gglm.Vec3

func (*GlyphRend) DrawTextOpenGL01String

func (gr *GlyphRend) DrawTextOpenGL01String(text string, screenPos *gglm.Vec3, color *gglm.Vec4) gglm.Vec3

DrawTextOpenGLAbs prepares text that will be drawn on the next GlyphRend.Draw call. screenPos is in the range [0,1], where (0,0) is the bottom left. Color is RGBA in the range [0,1].

func (*GlyphRend) DrawTextOpenGLAbs

func (gr *GlyphRend) DrawTextOpenGLAbs(text []rune, startPos *gglm.Vec3, color *gglm.Vec4) gglm.Vec3

DrawTextOpenGLAbsString prepares text that will be drawn on the next GlyphRend.Draw call. screenPos is in the range ([0,ScreenWidth],[0,ScreenHeight]) where (0,0) is bottom left. Color is RGBA in the range [0,1].

func (*GlyphRend) DrawTextOpenGLAbsRect

func (gr *GlyphRend) DrawTextOpenGLAbsRect(text []rune, rectTopLeft *gglm.Vec3, rectBotRight *gglm.Vec2, color *gglm.Vec4) gglm.Vec3

func (*GlyphRend) DrawTextOpenGLAbsRectWithStartPos

func (gr *GlyphRend) DrawTextOpenGLAbsRectWithStartPos(text []rune, startPos, rectTopLeft *gglm.Vec3, rectBotRight *gglm.Vec2, color *gglm.Vec4) gglm.Vec3

func (*GlyphRend) DrawTextOpenGLAbsString

func (gr *GlyphRend) DrawTextOpenGLAbsString(text string, screenPos *gglm.Vec3, color *gglm.Vec4) gglm.Vec3

DrawTextOpenGLAbsString prepares text that will be drawn on the next GlyphRend.Draw call. screenPos is in the range ([0,ScreenWidth],[0,ScreenHeight]) where (0,0) is bottom left. Color is RGBA in the range [0,1].

func (*GlyphRend) GetTextRuns

func (gr *GlyphRend) GetTextRuns(rs []rune, textRunsBuf *[]TextRun)

func (*GlyphRend) GridSize

func (gr *GlyphRend) GridSize() (w, h int64)

func (*GlyphRend) HasOpt

func (gr *GlyphRend) HasOpt(opt GlyphRendOpt) bool

func (*GlyphRend) ScreenPosToGridPos

func (gr *GlyphRend) ScreenPosToGridPos(x, y float32) (gridX, gridY float32)

func (*GlyphRend) SetFace

func (gr *GlyphRend) SetFace(fontOptions *truetype.Options) error

SetFace updates the underlying font atlas used by the glyph renderer. The current atlas is unchanged if there is an error

func (*GlyphRend) SetFontFromFile

func (gr *GlyphRend) SetFontFromFile(fontFile string, fontOptions *truetype.Options) error

func (*GlyphRend) SetOpts

func (gr *GlyphRend) SetOpts(opts ...GlyphRendOpt)

func (*GlyphRend) SetScreenSize

func (gr *GlyphRend) SetScreenSize(screenWidth, screenHeight int32)

type GlyphRendOpt

type GlyphRendOpt uint64
const (
	GlyphRendOpt_None    GlyphRendOpt = 0
	GlyphRendOpt_BgColor GlyphRendOpt = 1 << (iota - 1)
	GlyphRendOpt_Underline
	GlyphRendOpt_COUNT GlyphRendOpt = iota
)

type GlyphRendOptValues

type GlyphRendOptValues struct {
	BgColor *gglm.Vec4
}

type JoiningType

type JoiningType uint8
const (
	JoiningType_Right JoiningType = iota
	JoiningType_Left
	JoiningType_Dual
	JoiningType_Causing
	JoiningType_None
	JoiningType_Transparent
)

type RuneInfo

type RuneInfo struct {
	Name       string
	Cat        Category
	BidiCat    BidiCategory
	DecompTag  DecompTag
	JoinType   JoiningType
	IsLigature bool

	//Decomp is the ordered set of runes this rune decomposes into
	//as defined by unicodeData.txt
	Decomp []rune

	//EquivalentRunes are runes that are canonically or compatiability equivalent to this rune
	EquivalentRunes []rune

	//ScriptTable is one of the script tables in the unicode package such as unicode.Arabic
	//and is guaranteed to not be nil.
	ScriptTable *unicode.RangeTable
}

type TextRun

type TextRun struct {
	Runes []rune
	IsLtr bool
}

Jump to

Keyboard shortcuts

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