-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/image/font/opentype: Face isn't compliant with font.Face #58252
Comments
I don't see an owner listed on https://dev.golang.org/owners, but most of the code seems to have been written by @nigeltao. |
Hi! I proposed a small change here that should fix this issue. |
I'm tempted to close this as Working As Intended. Glyph index 0 is a valid index, and by convention it's the
Calling There is a separate question of "if I have a string, what runes in it are covered by this Face (excluding For example, Han Unification means that "does this Face have a non-zero glyph index for this rune" isn't sufficient to answer "is this the right font for this rune". At a minimum, this should probably involve some concept of the user's locale, but I don't think Go has a good cross-platform abstraction for this yet. For example, Android's minikin library's author said that:
Again, font selection and coverage calculation is a bigger problem needing separate API. |
Consider the opentype example_test.go file, changing the "e" in the "jelly" string to a Unicode U+2603 Snowman, and running diff --git a/font/opentype/example_test.go b/font/opentype/example_test.go
index 4d7ee85..c8d522a 100644
--- a/font/opentype/example_test.go
+++ b/font/opentype/example_test.go
@@ -46,7 +46,7 @@ func ExampleNewFace() {
Dot: fixed.P(startingDotX, startingDotY),
}
fmt.Printf("The dot is at %v\n", d.Dot)
- d.DrawString("jel")
+ d.DrawString("j\u2603l")
fmt.Printf("The dot is at %v\n", d.Dot)
d.Src = image.NewUniform(color.Gray{0x7F})
d.DrawString("ly")
I think (1) is the better output. |
Hello! Thank you for your response.
I agree! Glyph index 0 is a valid index, however, it implies that the glyph you are trying to draw isn't present. The fact that the .notdef is being returned should mean that ok == false, as stated in the font.Face documentation.
(Glyph, GlyphAdvance, GlyphBounds) To me, this sounds like it must return an ok == false, and the .notdef glyph bounds/advance/mask/etc. After all, what is the point of the ok variable if not to determine that it is using a fallback glyph? The only other thing I see is for error handling, and to me, in an ideal world errors would mean itd draw the .notdef glyph. The benefit of this patch is that libraries like multiface could work properly. It would make users be able to use fallback glyphs without the need for called Index() ourselves.
There could be a separate structure and API for this, but I'm not sure to what extent that is relevant to the issue at hand. I don't think this patch is significantly slower than before. It introduces 1-2 checks per function. The Regarding the |
This is an issue due to |
Hello, may I please get an update on this, @nigeltao? |
Change https://go.dev/cl/474376 mentions this issue: |
Change https://go.dev/cl/552616 mentions this issue: |
As the commit message of CL 474376 notes, the "TODO: is falling back on the U+FFFD glyph the responsibility of the Drawer or the Face?" was resolved. There's no need to panic anymore. Updates golang/go#58252. Change-Id: Ic4bcc3dfb8a463e7abcfccdbcf826644327f1aec Reviewed-on: https://go-review.googlesource.com/c/exp/+/552616 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com> Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I created a new face from opentype. Then, I called Glyph() on a non existing character.
What did you expect to see?
I expected it to return !ok, as stated in the
font.Face
documentation.What did you see instead?
It returns ok.
The text was updated successfully, but these errors were encountered: