github.com/kintar/etxt@v0.0.9/esizer/impl_advance.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 import "github.com/kintar/etxt/efixed" 7 8 // Like [HorzPaddingSizer], but adds the extra padding in the advance 9 // instead of the kern. 10 // 11 // If you aren't modifying the glyphs, only padding them horizontally, 12 // use [HorzPaddingSizer] instead. This sizer is intended to deal with 13 // modified glyphs that have actually become wider. 14 type AdvancePadSizer struct { 15 buffer sfnt.Buffer 16 padding fixed.Int26_6 17 } 18 19 // Sets the configurable horizontal padding value, in pixels. 20 func (self *AdvancePadSizer) SetPadding(value int) { 21 self.padding = fixed.Int26_6(value << 6) 22 } 23 24 // Like [AdvancePadSizer.SetPadding], but expecting a fixed.Int26_6 instead 25 // of an int. 26 func (self *AdvancePadSizer) SetPaddingFract(value fixed.Int26_6) { 27 self.padding = value 28 } 29 30 // Like [AdvancePadSizer.SetPadding], but expecting a float64 instead of 31 // an int. 32 func (self *AdvancePadSizer) SetPaddingFloat(value float64) { 33 self.padding = efixed.FromFloat64RoundToZero(value) 34 } 35 36 // Satisfies the [Sizer] interface. 37 func (self *AdvancePadSizer) Metrics(f *Font, size fixed.Int26_6) font.Metrics { 38 return DefaultMetricsFunc(f, size, &self.buffer) 39 } 40 41 // Satisfies the [Sizer] interface. 42 func (self *AdvancePadSizer) Advance(f *Font, glyphIndex GlyphIndex, size fixed.Int26_6) fixed.Int26_6 { 43 return DefaultAdvanceFunc(f, glyphIndex, size, &self.buffer) + self.padding 44 } 45 46 // Satisfies the [Sizer] interface. 47 func (self *AdvancePadSizer) Kern(f *Font, prevGlyphIndex GlyphIndex, currGlyphIndex GlyphIndex, size fixed.Int26_6) fixed.Int26_6 { 48 return DefaultKernFunc(f, prevGlyphIndex, currGlyphIndex, size, &self.buffer) 49 }