pomax / fontmetrics.js Goto Github PK
View Code? Open in Web Editor NEWA JavaScript library that extends the Canvas2D context.measureText(<String>) with additional typographical metrics
A JavaScript library that extends the Canvas2D context.measureText(<String>) with additional typographical metrics
This library updates the canvas2d ctx.measureText(<String>) function so that it returns not just a string's width, but also its height, ascent wrt the baseline, descent wrt the baseline, the leading distance (the number of pixels between the baselines of two consecutive lines of text, pronounced like the metal "lead", not like the management "leader"), as well as the string's bounding box. Simply include on a page as: <script type="text/javascript" src="fontmetrics.js"></script> and measureText will return a much more complete object, structured as follows: { fontsize: <number>, /* as set on the canvas/context */ width: <number>, /* typesetting width of the text */ height: <number>, /* typesetting height of the text */ ascent: <number>, /* height above the baseline for this text */ descent: <number>, /* depth below the baseline for this text */ leading: <number>, /* the 'lead' (metal) spacing between the baselines of two lines */ bounds: /* the bounding box for the rasterised text on a canvas */ { minx: <number>, /* can be negative */ miny: <number>, /* can be negative */ maxx: <number>, /* not necessarily the same as width */ maxy: <number> /* not necessarily the same as height */ } } Note: all numbers represent screen pixels (not typographical points) See http://pomax.github.com/fontmetrics.js/ for a demonstration. This library is covered by an MIT (Expat flavour) license.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.