You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I'm trying to render a text at certain point and a rectangle around it. This example is doing exactly what I need. In python implementation font.measureText returns only advance of text. As per the doc only "TextBlob" class is having "bounds" method and to calculate it first you need to create an instance of it:
I think it's an unnecessary step to calculate bounds. We already have our font instance available to calculate bounds. The doc also suggests about paint.getTextBounds(...) method but it's not implemented yet.
To Reproduce
Steps to reproduce the behavior:
As shown in the above example at link:
Ok,
I have created this little function for text alignment and hope other users would find it useful.
# Horizontal alignALIGN_LEFT=1<<0# Default, align text horizontally to left.ALIGN_CENTER=1<<1# Align text horizontally to center.ALIGN_RIGHT=1<<2# Align text horizontally to right.# Vertical alignALIGN_TOP=1<<3# Align text vertically to top.ALIGN_MIDDLE=1<<4# Align text vertically to middle.ALIGN_BOTTOM=1<<5# Align text vertically to bottom.ALIGN_BASELINE=1<<6# Default, align text vertically to baseline.defdraw_text(canvas, txt, x, y, font, paint, flags):
# Get bounds of txtrect=skia.Rect.MakeXYWH(0, 0, 0, 0)
font.measureText(txt, bounds=rect)
px=0.0py=0.0ifALIGN_LEFT&flags:
px=rect.x()
elifALIGN_CENTER&flags:
px=rect.width()/2.0elifALIGN_RIGHT&flags:
px=rect.width()
ifALIGN_TOP&flags:
py=rect.y()
elifALIGN_MIDDLE&flags:
py=-rect.height()/2.0elifALIGN_BOTTOM&flags:
py=0.0elifALIGN_BASELINE&flags:
passcanvas.drawString('Hello World', x-px, y-py, font, paint)
#Exampledraw_text(canvas, "Hello World", 100, 100, font, paint, ALIGN_CENTER|ALIGN_MIDDLE)
Describe the bug
I'm trying to render a text at certain point and a rectangle around it. This example is doing exactly what I need. In python implementation font.measureText returns only advance of text. As per the doc only "TextBlob" class is having "bounds" method and to calculate it first you need to create an instance of it:
I think it's an unnecessary step to calculate bounds. We already have our font instance available to calculate bounds. The doc also suggests about paint.getTextBounds(...) method but it's not implemented yet.
To Reproduce
Steps to reproduce the behavior:
As shown in the above example at link:
Neither rect is having correct size nor it's drawn properly around the text.
Expected behavior
Get correct text bounds.
Desktop (please complete the following information):
Additional context
A simple example that shows getting the correct text bounds.
Regards.
The text was updated successfully, but these errors were encountered: