jpbruyere / vkvg

Vulkan 2D graphics library
https://jpbruyere.github.io/vkvg/
MIT License
773 stars 33 forks source link

Issue with getting glyphs info #118

Closed Rubo3 closed 2 years ago

Rubo3 commented 2 years ago

When I call vkvg_text_run_get_glyph_position with HarfBuzz with a pointer to enough memory, no matter what the index is or the number of glyphs is, I always get x_advance = 1024, and y_advance, x_offset and y_offset = 0. The text is correctly displayed though.

jpbruyere commented 2 years ago

and? hb return x_advance, that looks normal for me. metrics looks different between with/without harfbuzz.

Rubo3 commented 2 years ago

But if that's normal, what should you do with this info? I mean, it's the same for all glyphs.

Rubo3 commented 2 years ago

Wait do you mean it returns x_advance only?

Rubo3 commented 2 years ago

Oh ok, but isn't 1024 too much? The glyphs are clearly not distant 1024 pixels from each other.

jpbruyere commented 2 years ago

Font metrics has some subtilities, we have to define clearly what unit we use for both harfbuzz and stb for returned values.

Rubo3 commented 2 years ago

Yes, it would be a good idea to return the same values from vkvg_get_glyph_position regardless of the backend vkvg uses.

Rubo3 commented 2 years ago

I noticed that with or without HarfBuzz I always get 1024, 0, 0, 0.

jpbruyere commented 2 years ago

I made a quick test this afternoon, and I got different results, I have to double check this.

Rubo3 commented 2 years ago

@billzez do you have the same issue?

billzez commented 2 years ago

I believe these values are fixed point, so you have to convert to float. (float)x_advance / 16.0 for subpixel position or just x_advance >> 6.

Rubo3 commented 2 years ago

Thanks, but why divide by 16? Also, comparing the result of vkvg_text_run_get_glyph_position with the one from vkvg_text_run_get_extents, with a text run of only one character, on the former I get sane values, like width = 16, height = 36, x_advance = 16, y_advance = 0, while on the latter I still get 1024, 0, 0, 0, 0. Even if I divide 2014 by 16, I get 64, which is four times greater than the text run x_advance.

jpbruyere commented 2 years ago

give me a complete run-able sample so that I could check everything.

Rubo3 commented 2 years ago

Here you go: https://gitlab.com/Rubo/shitty. The relevant function is here: https://gitlab.com/Rubo/shitty/-/blob/master/editor/main.c#L42

jpbruyere commented 2 years ago

I run 'make', and nothing happens. I was talking about a simple unit test, you may just add a method or two in the tests/text.c sample, this would be simpler for me.

Rubo3 commented 2 years ago

Oh right, that was so easy I didn't think about it...

Rubo3 commented 2 years ago

I think this would suffice: hello.txt (I changed its extension to .txt so that GitHub would not complain).

As a result, with HarfBuzz I get:

Text x_advance = 184.000000

Glyphs x_advance:
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000

Total x_advance = 12083.000000
jpbruyere commented 2 years ago

my result with harfbuzz & freetype:

Text x_advance = 196.000000

Glyphs x_advance:
196.000000
196.000000
196.000000
196.000000
196.000000
196.000000
196.000000
196.000000
196.000000
196.000000
196.000000
196.000000
196.000000

Total x_advance = 12953.000000
jpbruyere commented 2 years ago

and without harfbuzz, small metrics diff:

Text x_advance = 203.000000

Glyphs x_advance:
203.000000
203.000000
203.000000
203.000000
203.000000
203.000000
203.000000
203.000000
203.000000
203.000000
203.000000
203.000000
203.000000

Total x_advance = 12992.000000
jpbruyere commented 2 years ago

change

printf("%f\n", info.x_advance);

with

printf("%d\n", info.x_advance);

It's an integer, that you try to print out as a float....

Rubo3 commented 2 years ago

Right, thank you, I also changed the x_advance type at line 29 to int32_t. Now I get:

Text x_advance = 184.000000
...
Total x_advance = 12083

which still are not the same.

jpbruyere commented 2 years ago

How old are you Rubo?

Rubo3 commented 2 years ago

Does it matter?

jpbruyere commented 2 years ago

Sometimes I feel you are very young (12-14yo), but maybe I'm wrong. I appreciate your involvement but you have to solve such simple issue by yourself. Creating opensource software is such demanding, you must be a little harder with yourself. Other pr are really complicated, there I'm pleased to help you, but here, you should be able to go forward by yourself. Tanks again for your help.

Rubo3 commented 2 years ago

Sometimes I feel you are very young (12-14yo)

Well this one did hurt... Anyway, I solved by creating a text run for each glyph, then vkvg_text_extents_t.width and vkvg_text_extents_t.height did the trick. Sorry to have bothered you with such simple issues.

jpbruyere commented 2 years ago

I didn't mean to hurt you, sorry.

Rubo3 commented 2 years ago

Don't worry! I was just exaggerating.