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
Currently there is no word-wrap functionality baked into the SVG rendering step, which is just shameful ☹️. This issue is mostly a place for me to store some thoughts, notes, and log my results throughout the process of implementing a "smart" wrapper function for migo.
Can we get away with using SVGTextElement.getComputedTextLength()? Does it produce accurate and dependable results...? On that note, what about SVGTextElement.getBoundingClientRect? Or SVGTextElement.getBBox? It sure would save me a lot of time to just be able to use a built-in interface for 90% of the logic in this scenario.
If not, heres a basic outline of the steps involved:
calculate glyph width from font size + weight
(like @nicktaras/getFontCharWidth, or digging into the SVG font interfaces)
estimate required width for a given string in the desired font/size/weight
subtract a small percentage of the window width to determine a "safe-zone"; ensuring
any breakable-words will be wrapped before it reaches the edge of the canvas or screen.
e.g. width - (width * 0.05) ~> 950px / 1000px total (25px margin)
diff the required text width with the image safe-zone width.
letd=Math.ceil(requiredWidthFromStep2-safeWidthFromStep3);if(d>0){wrapLine();// if a line is reeeeeally long and requires 2+ screen breaks to fit// this re-wrap the text until all lines fit within the canvas.repeatStartingFromStep2ForEveryLine();}
if all lines don't fit within the canvas size, attempt to scale the font size
down until they do. Truncating the text should only be used as THE last resort.
The text was updated successfully, but these errors were encountered:
Currently there is no word-wrap functionality baked into the SVG rendering step, which is just shameful☹️ . This issue is mostly a place for me to store some thoughts, notes, and log my results throughout the process of implementing a "smart" wrapper function for migo.
Can we get away with using
SVGTextElement.getComputedTextLength()
? Does it produce accurate and dependable results...? On that note, what aboutSVGTextElement.getBoundingClientRect
? OrSVGTextElement.getBBox
? It sure would save me a lot of time to just be able to use a built-in interface for 90% of the logic in this scenario.If not, heres a basic outline of the steps involved:
textLength * (glyphWidthFromStep1 + letterSpacing)
)any breakable-words will be wrapped before it reaches the edge of the canvas or screen.
width - (width * 0.05) ~> 950px / 1000px total (25px margin)
down until they do. Truncating the text should only be used as THE last resort.
The text was updated successfully, but these errors were encountered: