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
To generate figures in headless mode, we still need to know the dimensions of the labels at runtime, since we delegate label rendering to MathJax. The current approach gets SVG DOM elements of labels, call getBbox() on a ghost <g> element that wraps each of them, and return the width and height of the SVGRect returned. @maxkrieger and I did some experiments on the label generation & dimensions of the labels. Here's what we know so far:
The MathJax SVG labels has path strings that is in some random model space, not the screen space, where the y-axis is facing "up". See an example below:
To get the labels into the screen space, MathJax does some mysterious computation to compute width and height of the labels in ex unit. Which matchs of ratio of the viewBox exactly. In the previous example: 2.041ex / 1.764ex = 1.1570294785 878.8 / 759.5 = 1.1570770244
The result of getBbox, however, seems to return a bbox with a different ratio. We did some light experiements by copying the <svg> with ex dimensions with the one with computed bbox dimonsions in the same parent <svg>. The ex version seems to be bigger:
Setting the fontSize of the <svg> returned by MathJax has an effect of the size of the glyph due to unknown reasons. We don't know how it's computed, nor can we reproduce it by changing fontSize in Chrome inspector.
Interestingly, the width and height attributes seem to take precedance over fontSize when they are different. For instance, the venn-3d.sty example renders each label with a computed, Penrose-unit width that's proportional to the radius of the circle containinig it. However, the system still applies a 12pt font size on all labels as well. The frontend, in face, applies both properties on the <svg> at runtime, but the width attirbute determines the actual size of the glyph, which made the example magically works.
There seems to be no generic server-side implementation of getBbox(). If so, computing the precise dimensions of the labels will have to be algorithmetic. However, the transformation from MathJax's label space to the canvas space in the brower (currently done by MathJax) is still unknown, preventing us from computing it by hand.
For now, we are assuming 12pt for all mass-generated diagrams and use a magic number to convert from ex to px. Due to the abovementioned bbox inaccuracy problem, this number is in face inaccurate (mostly to the precision of 0.1 ish). Things like https://github.com/kapetan/text-height might be useful, but we have not tried these options.
The text was updated successfully, but these errors were encountered:
Bumping this issue. For Equation, #1026 standardized dimensions for both node and browser.
However, we introduced Text in #829 and subsequently refined the measurements in #842. There are still discrepancies between node and browser. Some related issues in node-canvas:
Related: #299
To generate figures in headless mode, we still need to know the dimensions of the labels at runtime, since we delegate label rendering to MathJax. The current approach gets SVG DOM elements of labels, call
getBbox()
on a ghost<g>
element that wraps each of them, and return the width and height of theSVGRect
returned. @maxkrieger and I did some experiments on the label generation & dimensions of the labels. Here's what we know so far:ex
unit. Which matchs of ratio of theviewBox
exactly. In the previous example:2.041ex / 1.764ex = 1.1570294785
878.8 / 759.5 = 1.1570770244
<svg>
withex
dimensions with the one with computed bbox dimonsions in the same parent<svg>
. Theex
version seems to be bigger:22.2 / 23.44 = 0.94
fontSize
of the<svg>
returned by MathJax has an effect of the size of the glyph due to unknown reasons. We don't know how it's computed, nor can we reproduce it by changingfontSize
in Chrome inspector.width
andheight
attributes seem to take precedance overfontSize
when they are different. For instance, thevenn-3d.sty
example renders each label with a computed, Penrose-unit width that's proportional to the radius of the circle containinig it. However, the system still applies a12pt
font size on all labels as well. The frontend, in face, applies both properties on the<svg>
at runtime, but thewidth
attirbute determines the actual size of the glyph, which made the example magically works.getBbox()
. If so, computing the precise dimensions of the labels will have to be algorithmetic. However, the transformation from MathJax's label space to the canvas space in the brower (currently done by MathJax) is still unknown, preventing us from computing it by hand.12pt
for all mass-generated diagrams and use a magic number to convert fromex
topx
. Due to the abovementioned bbox inaccuracy problem, this number is in face inaccurate (mostly to the precision of0.1
ish). Things like https://github.com/kapetan/text-height might be useful, but we have not tried these options.The text was updated successfully, but these errors were encountered: