Git Product home page Git Product logo

em.js's Introduction

em.js

Javascript shim that fills in as-yet unimplemented text measurement functionality in HTML5 canvas.

What's this about

Stop me if you've heard this one. There is actually no way to determine the height of rendered text in the HTML5 canvas API. The proposed behavior of the TextMetrics API looks promising, but at the time of this writing is almost completely unsupported in almost every browser.

How to use

em.js is just a shim that replaces the measureText method on the HTML5 canvas 2D drawing context with one that actually implements some of the proposed metrics. To use it, simply include em.js in your web project before you make any calls to measureText. You can then use measureText as you would normally but get more of the promised metrics from the standard. As always, your mileage may vary.

References

This was mainly inspired by this answer on stack overflow, which details a method of essentially setting up tht text and rendering it, and using CSS to determine the various text metrics.

Footnote

This is by a wide margin, the most boring thing I've ever written. It hurts me even to document it, but this is one of those rare instances when I did a quick search for this function, and didn't find any canned solution for it, so I feel some obligation to post it online. I hope that you find it useful.

em.js's People

Contributors

ryansturmer avatar maximilianbuegler avatar

Stargazers

曾某某 avatar John Trump avatar Piotr Kapera avatar Xiaowei Chu avatar  avatar Jimmy Moon avatar  avatar  avatar Daniel Dara avatar Derek Seymour avatar Laurence Dougal Myers avatar

Watchers

 avatar Pelican George avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.