github.com/kintar/etxt@v0.0.9/esizer/impl_fixed.go (about) 1 package esizer 2 3 import "golang.org/x/image/font" 4 import "golang.org/x/image/font/sfnt" 5 import "golang.org/x/image/math/fixed" 6 7 import "github.com/kintar/etxt/efixed" 8 9 // A [Sizer] with a fixed advance between glyphs. 10 type FixedSizer struct { 11 advance fixed.Int26_6 12 buffer sfnt.Buffer 13 } 14 15 // Sets the fixed advance between characters. 16 func (self *FixedSizer) SetAdvance(advance int) { 17 self.SetAdvanceFract(fixed.Int26_6(advance << 6)) 18 } 19 20 // Like [FixedSizer.SetAdvance], but expecting a float64 instead of an int. 21 func (self *FixedSizer) SetAdvanceFloat(advance float64) { 22 self.advance = efixed.FromFloat64RoundToZero(advance) 23 } 24 25 // Like [FixedSizer.SetAdvance], but expcting a fixed.Int26_6 instead of an int. 26 func (self *FixedSizer) SetAdvanceFract(advance fixed.Int26_6) { 27 self.advance = advance 28 } 29 30 // Satisfies the [Sizer] interface. 31 func (self *FixedSizer) Metrics(font *Font, size fixed.Int26_6) font.Metrics { 32 return DefaultMetricsFunc(font, size, &self.buffer) 33 } 34 35 // Satisfies the [Sizer] interface. 36 func (self *FixedSizer) Advance(*Font, GlyphIndex, fixed.Int26_6) fixed.Int26_6 { 37 return self.advance 38 } 39 40 // Satisfies the [Sizer] interface. 41 func (self *FixedSizer) Kern(*Font, GlyphIndex, GlyphIndex, fixed.Int26_6) fixed.Int26_6 { 42 return 0 43 }