Details
-
Suggestion
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.14.2
-
None
Description
Canvas' context.measureText only returns an object only with a width property, it should also return:
actualBoundingBoxAscent
The distance from the horizontal line indicated by the textBaseline attribute to the top of the bounding rectangle of the given text, in CSS pixels; positive numbers indicating a distance going up from the given baseline.
actualBoundingBoxDescent
The distance from the horizontal line indicated by the textBaseline attribute to the bottom of the bounding rectangle of the given text, in CSS pixels; positive numbers indicating a distance going down from the given baseline.
actualBoundingBoxLeft
The distance parallel to the baseline from the alignment point given by the textAlign attribute to the left side of the bounding rectangle of the given text, in CSS pixels; positive numbers indicating a distance going left from the given alignment point.
actualBoundingBoxRight
The distance parallel to the baseline from the alignment point given by the textAlign attribute to the right side of the bounding rectangle of the given text, in CSS pixels; positive numbers indicating a distance going right from the given alignment point.
alphabeticBaseline
The distance from the horizontal line indicated by the textBaseline attribute to the alphabetic baseline of the line box, in CSS pixels; positive numbers indicating that the given baseline is below the alphabetic baseline. (Zero if the given baseline is the alphabetic baseline.)
emHeightAscent
The distance from the horizontal line indicated by the textBaseline attribute to the top of the em square in the line box, in CSS pixels; positive numbers indicating that the given baseline is below the top of the em square (so this value will usually be positive). Zero if the given baseline is the top of the em square; half the font size if the given baseline is the middle of the em square.
emHeightDescent
The distance from the horizontal line indicated by the textBaseline attribute to the bottom of the em square in the line box, in CSS pixels; positive numbers indicating that the given baseline is below the bottom of the em square (so this value will usually be negative). (Zero if the given baseline is the top of the em square.)
fontBoundingBoxAscent
The distance from the horizontal line indicated by the textBaseline attribute to the top of the highest bounding rectangle of all the fonts used to render the text, in CSS pixels; positive numbers indicating a distance going up from the given baseline.
fontBoundingBoxDescent
The distance from the horizontal line indicated by the textBaseline attribute to the bottom of the lowest bounding rectangle of all the fonts used to render the text, in CSS pixels; positive numbers indicating a distance going down from the given baseline.
hangingBaseline
The distance from the horizontal line indicated by the textBaseline attribute to the hanging baseline of the line box, in CSS pixels; positive numbers indicating that the given baseline is below the hanging baseline. (Zero if the given baseline is the hanging baseline.)
ideographicBaseline
The distance from the horizontal line indicated by the textBaseline attribute to the ideographic baseline of the line box, in CSS pixels; positive numbers indicating that the given baseline is below the ideographic baseline. (Zero if the given baseline is the ideographic baseline.)
Source: https://webplatform.github.io/docs/apis/canvas/TextMetrics/
How we would have used it:
let metrics = ctx.measureText(key); let actualKeyHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;
Right now, we have to use c++ and use QFontMetrics (::boundingRect) ourselves, the same API that measureText uses.
as the docs mention:
object measureText(text)
Returns an object with a width property, whose value is equivalent to calling QFontMetrics::width() with the given text in the current font.
QFont font(font_family, size);
QFontMetrics fm(font);
int actual_key_height = fm.boundingRect(key).height();