How to position glyphs #2599
Replies: 1 comment 2 replies
-
Ascent and Descent are just the standard glyph properties as show here for example: https://stackoverflow.com/questions/5995293/get-single-glyph-metrics-net Obviously they are in pixel. If the glyph extends below the baseline (like 'g') then the descent is negative. A glyph, which is placed on the base line (like 'a') has a descent value of 0. See also here: https://github.com/olikraus/u8g2/wiki/u8g2reference#getdescent Nevertheless we need to distinguish between the functions getDescent and getAscent in u8g2. Ascent and descent are glyph properties. They can't be changed are defined by the font designer. The x and y offset are part of the compression algorithm. They define how the bitmap is shifted away from the origin. The getDescent and getAscent function in u8g2 return something like the overall font values for ascent and descent. vref only is used to convert the y position in different modes. vref is 0 for the base line mode (which I suggest should be the default)
Correct. Technically the gylph bitmap starts at the uppler left corner and the y values grow towards the bottom. Lines 636 to 637 in 5f96958
You can say, that the origin is shifted above the glyph. The shift is the same for all glyph (so it is a font property).
y-offset, ascent and descent are gylph properties, the mode (vref) is a font property. It will be like this:
It is just used by the mode. In baseline mode, vref will be always 0. In top mode, vref is the size of the tallest glyph (well... depends, see next answer)
Like noted above, the question is: What is the tallest glphy? The idea of the SetFontRefHeight is to define, the height of the font for the top mode. So for example with "setFontRefHeightAll" u8g2 will use the height of the tallest glyph found in the font: https://github.com/olikraus/u8g2/wiki/u8g2reference#setfontrefheightall |
Beta Was this translation helpful? Give feedback.
-
Hello,
I am having trouble getting my glyph placement correct. I have tried a few iterations of using x-offset and y-offset, vref, ascent, descent, etc. I guess I don't understand how they all relate, and how they relate to the font positions Baseline, Top, Center and Bottom. I found the code that calculated vref, but using the result has not worked for me. I need to position glyphs correctly in a single line in Baseline and Top modes at a minimum.
As I understand it, the (0,0) position for a glyph defaults to the lower left corner. In Baseline mode, all the glyphs in a string share the same y position (assuming a single line) with a possible downward shift for y-offset. Does Top mode mean that all glyphs in a string have their tops positioned along the same y position? And how do y-offset, ascent and descent factor into these? Finally, how is vref value meant to be used? And what about SetFontRefHeight?
Thanks a lot,
Gentle
Beta Was this translation helpful? Give feedback.
All reactions