@@ -36,7 +36,8 @@ const (
3636 // glyphMaskOffsets is the number of different subpixel offsets to render, in each axis.
3737 // The memory usage goes as the square of this number, and 4 produces very good results,
3838 // while 2 is acceptable, and is significantly better than 1. 8 is overkill.
39- glyphMaskOffsets = 4
39+ glyphMaskOffsetsX = 4
40+ glyphMaskOffsetsY = 4
4041)
4142
4243func init () {
@@ -83,7 +84,7 @@ func (gc *glyphCache) Glyph(face *font.Face, g *shaping.Glyph, outline font.Glyp
8384 gc .Lock ()
8485 defer gc .Unlock ()
8586
86- fsize := image.Point {X : int (g .Width .Ceil ()), Y : - int (g .Height .Ceil ())}
87+ fsize := image.Point {X : int (g .Width .Round ()), Y : - int (g .Height .Round ())}
8788 size := fsize .Add (image.Point {2 * glyphMaskBorder , 2 * glyphMaskBorder })
8889 if size .X <= 0 || size .X > glyphMaxSize || size .Y <= 0 || size .Y > glyphMaxSize {
8990 return nil , image.Point {}
@@ -95,8 +96,9 @@ func (gc *glyphCache) Glyph(face *font.Face, g *shaping.Glyph, outline font.Glyp
9596 pi := pf .ToPoint ().Sub (image.Point {glyphMaskBorder , glyphMaskBorder })
9697 pi .X += g .XBearing .Round ()
9798 pi .Y -= g .YBearing .Round ()
99+
98100 off := pos .Sub (pf )
99- oi := off .MulScalar ( glyphMaskOffsets ). Floor ().ToPoint ()
101+ oi := off .Mul ( math32 . Vec2 ( glyphMaskOffsetsX , glyphMaskOffsetsY )). Round ().ToPoint ()
100102 // fmt.Println("pos:", pos, "oi:", oi, "pi:", pi)
101103
102104 key := glyphKey {gid : g .GlyphID , sx : uint8 (fsize .X ), sy : uint8 (fsize .Y ), ox : uint8 (oi .X ), oy : uint8 (oi .Y )}
@@ -123,9 +125,9 @@ func (gc *glyphCache) renderGlyph(face *font.Face, gid font.GID, g *shaping.Glyp
123125 // clear target:
124126 draw .Draw (gc .image , gc .image .Bounds (), colors .Uniform (color .Transparent ), image.Point {0 , 0 }, draw .Src )
125127
126- od := float32 ( 1 ) / glyphMaskOffsets
127- x := - float32 (g .XBearing .Round ()) + float32 (xo )* od + glyphMaskBorder
128- y := float32 (g .YBearing .Round ()) + float32 (yo )* od + glyphMaskBorder
128+ od := math32 . Vec2 ( 1 , 1 ). Div ( math32 . Vec2 ( glyphMaskOffsetsX , glyphMaskOffsetsY ))
129+ x := - float32 (g .XBearing .Round ()) + float32 (xo )* od . X + glyphMaskBorder
130+ y := float32 (g .YBearing .Round ()) + float32 (yo )* od . Y + glyphMaskBorder
129131 rs := gc .filler
130132 rs .Clear ()
131133 for _ , s := range outline .Segments {
0 commit comments