Giter VIP home page Giter VIP logo

Comments (6)

dpvc avatar dpvc commented on June 20, 2024 1

OK, an experiment does seem to show that they are the actual font metrics on a character-by-character basis, and that they use decimal parts of a pixel rather than full pixels. So that does seem useful, and worth looking into.

from mathjax-src.

dpvc avatar dpvc commented on June 20, 2024

Currently, there is no API for javascript to get the glyph metrics for a browser font (though there are some proposals for that). So MathJax has the needed data for the characters in its fonts stored in data files that it loads as part of the font data. That is one reason that MathJax only handles specific fonts (one right now, but more on the way later this summer). See the common/fonts files for the base information. The CHTML and SVG output jax add more information that is specific to that output format. The SVG output doesn't actually use fonts, but rather paths generated from the fonts, so svg/fonts adds all the path information into the font data.

from mathjax-src.

 avatar commented on June 20, 2024

Thanks, that’s exactly what I was looking for.

from mathjax-src.

paeifbnaeufbpae avatar paeifbnaeufbpae commented on June 20, 2024

As a follow-up on that: what about the TextMetrics object the Canvas API provides with measureText()? It seems like it's widely supported and provides actualBoundingBoxAscent and actualBoundingBoxDescent.

from mathjax-src.

dpvc avatar dpvc commented on June 20, 2024

@paeifbnaeufbpae, that is a nice idea, but the values seem to be in CSS pixels, while MathJax needs sub-pixel accuracy in order to do the layout properly. Also, I suspect that actualBoundingBoxAscent and actualBoundingBoxDescent` are the ascent and decent values of the font being used, which is the same for all characters in the font, but MathJax needs the character-by-character height and depth information for each glyph, not the font-wide ascent and descent. I haven't checked this, but that is what the documentation and the names of these value seem to imply (it is not entirely clear).

from mathjax-src.

paeifbnaeufbpae avatar paeifbnaeufbpae commented on June 20, 2024

@paeifbnaeufbpae, that is a nice idea, but the values seem to be in CSS pixels, while MathJax needs sub-pixel accuracy in order to do the layout properly. Also, I suspect that actualBoundingBoxAscent and actualBoundingBoxDescent` are the ascent and decent values of the font being used, which is the same for all characters in the font, but MathJax needs the character-by-character height and depth information for each glyph, not the font-wide ascent and descent. I haven't checked this, but that is what the documentation and the names of these value seem to imply (it is not entirely clear).

Hm... I suspect that you could just artificially scale the text up by 1 / precision (with precision being 1e-3 or something) to get the equivalent of sub-pixel accuracy?

And given that you first need to call the measureText function and pass in a specific string to measure to even get a FontMetrics object, I'd think it does indeed return the text-specific ascent/descent values. (Of course, one would have to measure single characters then and not larger runs of text.)

I guess a quick experiment would answer this question.

from mathjax-src.

Related Issues (20)

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.