Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-83602

complete Canvas2D TextMetrics implementation per updated/newly adopted specs

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.14.2
    • Other
    • None
    • All

    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:

      window.qml
      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.

      Bar.cpp
      QFont font(font_family, size);
      QFontMetrics fm(font);
      int actual_key_height = fm.boundingRect(key).height();
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            pakerane Pasi Keränen
            wis wis s
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes