golang/freetype

RoundCapper seems to be "working in reverse", shape is spiky not round

tv42 opened this issue · 7 comments

tv42 commented

out

package main

import (
    "image"
    "image/png"
    "log"
    "os"

    "github.com/golang/freetype/raster"
    "golang.org/x/image/math/fixed"
)

func main() {
    const (
        w = 400
        h = 400
    )
    var p raster.Path
    p.Start(fixed.P(150, 150))
    p.Add1(fixed.P(200, 250))
    p.Add1(fixed.P(300, 250))

    r := raster.NewRasterizer(w, h)
    r.UseNonZeroWinding = true
    r.AddStroke(p, fixed.I(80), raster.RoundCapper, raster.RoundJoiner)

    rgba := image.NewRGBA(image.Rect(0, 0, w, h))
    painter := raster.NewRGBAPainter(rgba)
    painter.SetColor(image.Black)
    r.Rasterize(painter)

    f, err := os.Create("out.png")
    if err != nil {
        log.Fatalf("cannot create file: %v", err)
    }
    defer f.Close()
    if err := png.Encode(f, rgba); err != nil {
        log.Fatalf("writing png: %v", err)
    }
    if err := f.Close(); err != nil {
        log.Fatalf("closing file: %v", err)
    }
}

@tv42 Have you figured this out? I'm running into the same issue.

tv42 commented

@fogleman No clue about the internals. I skimmed the repo just enough to think that the bug was probably introduced at the same time as the math/fixed change, but the commit in question was a bit too verbose to find anything relevant in.

Any insight into this, @nigeltao ? I can try to fix it if you can point me in the right direction.

It's probably a bug introduced by 856a70c or d91c1d6

Sorry to not be more helpful. I've got a lot on my plate right now.

I can confirm that the bug was introduced in 856a70c - worked properly before that.

@tv42 @nigeltao I have submitted a pull request that fixes this. It's pretty simple: #29

Fixed by PR #29, which has been merged.

Sorry for the late response to the original issue.