measureText()
See original GitHub issueI am trying to surround a Konva.Text
with a Konva.Rect
, which requires that I measure the text before drawing the rectangle. How would you recommend that I accomplish this?
Currently it requires two passes with React to first render the Text and then render the Rectangle, since I can’t access the underlying Konva.Text
element before it is rendered.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top Results From Across the Web
CanvasRenderingContext2D.measureText() - Web APIs | MDN
measureText() method returns a TextMetrics object that contains information about the measured text (such as its width, for example).
Read more >HTML canvas measureText() Method - W3Schools
The measureText() method returns an object that contains the width of the specified text, in pixels. Tip: Use this method if you need...
Read more >HTML | canvas measureText() Method - GeeksforGeeks
The measureText() method is used to return an object that represents the width of the specified text in terms of pixels.
Read more >HTML5 Canvas: Why does measuring text with measureText ...
I benchmarked offsetWidth() vs measureText and I am getting drastically different values. Shouldn't they be the same? Why are they different ...
Read more >TextRenderer.MeasureText Method (System.Windows.Forms)
Provides the size, in pixels, of the specified text when drawn with the specified font in the specified device context, using the specified...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@blueberryfan Something like this:
@SyntaxRules the result of
measureText
appears to be less than the width oftextRef.current.width()
for some reason. I seem to have to hack a work around by adding additional pixels. It appears this is because measureText omits any padding applied. Is this a bug? Some example working code for those that arrive here.