text/filtered.go

Functions Structs

Functions

func Advance

Advance implements Face.Advance.

Only includes runes that are in the allowed ranges.

func (f *FilteredFace) Advance(text string) float64 {
	totalAdvance := 0.0

	for _, r := range text {
		if f.inRanges(r) {
			// Get glyph advance from the wrapped face
			glyphAdvance := 0.0
			for glyph := range f.face.Glyphs(string(r)) {
				glyphAdvance = glyph.Advance
				break	// Only one glyph for a single rune
			}
			totalAdvance += glyphAdvance
		}
	}

	return totalAdvance
}

func AppendGlyphs

AppendGlyphs implements Face.AppendGlyphs.

Only appends glyphs for runes in the allowed ranges.

func (f *FilteredFace) AppendGlyphs(dst []Glyph, text string) []Glyph {
	for glyph := range f.Glyphs(text) {
		dst = append(dst, glyph)
	}
	return dst
}

func Contains

Contains reports whether the rune is in the range.

func (ur UnicodeRange) Contains(r rune) bool {
	return r >= ur.Start && r <= ur.End
}

func Direction

Direction implements Face.Direction.

func (f *FilteredFace) Direction() Direction {
	return f.face.Direction()
}

func Glyphs

Glyphs implements Face.Glyphs.

Only yields glyphs for runes in the allowed ranges.

func (f *FilteredFace) Glyphs(text string) iter.Seq[Glyph] {
	return func(yield func(Glyph) bool) {
		for glyph := range f.face.Glyphs(text) {
			if f.inRanges(glyph.Rune) {
				if !yield(glyph) {
					return
				}
			}
		}
	}
}

func HasGlyph

HasGlyph implements Face.HasGlyph.

Returns true only if the rune is in the allowed ranges and the wrapped face has it.

func (f *FilteredFace) HasGlyph(r rune) bool {
	if !f.inRanges(r) {
		return false
	}
	return f.face.HasGlyph(r)
}

func Metrics

Metrics implements Face.Metrics.

func (f *FilteredFace) Metrics() Metrics {
	return f.face.Metrics()
}

func NewFilteredFace

NewFilteredFace creates a FilteredFace.

Only glyphs in the specified ranges are considered available.

If no ranges are specified, all glyphs are available (no filtering).

func NewFilteredFace(face Face, ranges ...UnicodeRange) *FilteredFace {
	return &FilteredFace{
		face:	face,
		ranges:	ranges,
	}
}

func Size

Size implements Face.Size.

func (f *FilteredFace) Size() float64 {
	return f.face.Size()
}

func Source

Source implements Face.Source.

func (f *FilteredFace) Source() *FontSource {
	return f.face.Source()
}

Structs

type UnicodeRange struct

UnicodeRange represents a contiguous range of code points.

type UnicodeRange struct {
	Start	rune
	End	rune
}

type FilteredFace struct

FilteredFace wraps a face and restricts it to specific Unicode ranges.

Only glyphs in the specified ranges are considered available.

FilteredFace is safe for concurrent use.

type FilteredFace struct {
	face	Face
	ranges	[]UnicodeRange
}