Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move origin to top-left text draw failed #139

Closed
Modificator opened this issue Dec 30, 2021 · 3 comments
Closed

move origin to top-left text draw failed #139

Modificator opened this issue Dec 30, 2021 · 3 comments

Comments

@Modificator
Copy link

Modificator commented Dec 30, 2021

When I use SetView(canvas.Identity.ReflectYAbout) text draw result

image

useSetCoordView can draw right, but other draw can't draw right, ↓ background draw out of canvas

image

var fontLoadSlice = []string{
	".SF Regular",
	"Arial",
	"Droid Sans",
}
var fontFamily *canvas.FontFamily
	fontFamily = canvas.NewFontFamily("times")
	for _, fontName := range fontLoadSlice {
		err := fontFamily.LoadLocalFont(fontName, canvas.FontRegular)
		fmt.Println(err)
		if err == nil {
			break
		}
	}
	headerFont := fontFamily.Face(28.0, canvas.Black, canvas.FontRegular, canvas.FontNormal)
	c := canvas.New(500, 200)
	ctx := canvas.NewContext(c)
	ctx.SetView(canvas.Identity.ReflectYAbout(100))
        //ctx.SetCoordView(canvas.Identity.ReflectYAbout(100))
	ctx.SetFillColor(canvas.White)
	ctx.DrawPath(0, 0, canvas.Rectangle(c.Size()))
	//ctx.SetStrokeColor(canvas.Black)
	//ctx.DrawPath(10, 10, canvas.Rectangle(480, 180))
	headerText := canvas.NewTextBox(headerFont, "test", 0, 0, canvas.Justify, canvas.Justify, 0, 0)
	ctx.DrawText(30, 30, headerText)
@tdewolff
Copy link
Owner

tdewolff commented Jan 3, 2022

Yes, this may not be the easiest for people who'd like to work with top-left as the origin, but SetCoordView or SetCoordSystem should be used to change the coordinate transformation to position elements (but not transform the elements themselves) while SetView transforms the complete view. The former allows you to position the elements with top-left as the origin, but the elements themselves (a path for example) will always have bottom-left (the mathematical standard) as its origin. That is, you define the path with a bottom-left origin, and then you can position it using with top-left as the origin.

I'm thinking of changing this system, by introducing a CartesianIVContext for example that draws everything Y-flipped except for text. Additonally, it would be possible to add a PolarContext for polar coordinates etc.

@marco-m
Copy link

marco-m commented May 23, 2022

Is this a duplicate of #72 ?

@tdewolff
Copy link
Owner

Yes it is! I will close this one. As mentioned in the other issue:

I've added a change that adds better support for CartesianIV (i.e. origin is top-left). It differs from CartesianI (i.e. origin is bottom-left) in that it anchors differently to images (anchors top-left vs bottom-left) and that text has always been anchored to the baseline (TextLine) or to top-left (TextBox) and remains so. This means that switching to CartesianIV may change the position of text and images.

You can change to CartesianIV using:

ctx.SetCoordSystem(canvas.CartesianIV)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants