How to know the baseline and x value for font.getPath() ?
See original GitHub issueHello, this question have already been asked but the answer given didn’t work :
var baseline = (font.ascender / font.unitsPerEm * fontSize);
So since it’s been a while maybe now there is a solution for it.
Expected Behavior
When I use font.getPath(‘text’, 0,0,40) => the text will be cut on the top or the bottom, or the right… And I would like to know the value of x and y relatively to the font and text. Or to make it simple, i would like the text to not be cut.
Steps to Reproduce (for bugs)
I made a small repo to visualize the text generated
- git clone https://github.com/microSoftware/display-font.git
- npm install
- node opentype.js (or nodemon opentype.js if you want to watch for modif)
- modify the words to see which one work and don’t work
- Go on http://localhost:8900 to see the result
Thank you
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (10 by maintainers)
Top Results From Across the Web
opentype.js - npm
This value determines the size of the grid. Common values are 2048 and 4096. Font.getPath(text, x, y, fontSize, options).
Read more >OpenType JS and FabricJS text convert to path - Stack Overflow
Calling font.getPath(string, x, y, fontSize) will "draw" a path from bottom to top: Example: draw text element at x=500, y=250
Read more >nodebox/opentype.js - Gitter
does anyone know how to implement a fallback font for opentype.parse(arraybuffer)?. or the appropriate way to handle missing glyphs? like ✩.
Read more >SkFont Class Reference - Skia
getPath() Modifies path to be the outline of the glyph. If the glyph has an outline, modifies path to be the glyph's outline...
Read more >opentype.js.Font JavaScript and Node.js code examples
let font = opts.fontFile ? opentype.loadSync(opts.fontFile) : defaultFont let svgString = font.getPath(str, x, y, opts.fontSize).toSVG()
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
font.getPath
draws the text with0,0
being the baseline.So, given a function
hline
that looks like this:You can see the relationship between baseline, ascender and descender here: this code:
Will draw the text like this, with ascender/descender in blue:
Working example in JSFiddle
Use path.getBoundingBox()
Then y1 of that is what you seek.
But note that ‘X’ is for example in most fonts taller than ‘o’, so both letters would be positioned to the top if you use it like that.