Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Fix width metric extraction #42

Merged
merged 3 commits into from
Apr 13, 2018
Merged

Fix width metric extraction #42

merged 3 commits into from
Apr 13, 2018

Conversation

edemaine
Copy link
Member

@edemaine edemaine commented Apr 8, 2018

Fix @ylemkimon's issues reported in #41 (comment)
In particular, fix width of space characters.

I'm not an expert in fonttools but it seemed that I needed to use both the existing 'glyf' structure for xMin/xMax and the getGlyphSet structure for width. Let me know if you know a cleaner way.

This will require rerunning the script if #41 gets merged first.

width = glyph.xMax - glyph.xMin
height = glyph.yMax / unitsPerEm
depth = -glyph.yMin / unitsPerEm
width = widths[name].width / unitsPerEm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get width by glyph.width.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I tried that, and it wasn't defined. Unless I somehow have the wrong version installed? I did it pretty recently.

Copy link
Member

@ylemkimon ylemkimon Apr 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edemaine Ah, sorry, I was looking at the fontforge Python API.

depth = -glyph.yMin
width = glyph.xMax - glyph.xMin
height = glyph.yMax / unitsPerEm
depth = -glyph.yMin / unitsPerEm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During refactoring the generation scripts of fonts and their metrics, I discovered that yMax and yMin from generated TTF does not match height and depth from tfm(TeX font metrics).

Are their definitions different? Or, do they change during conversion process? If so, which metrics should KaTeX use?

CC @kevinbarabash

Copy link
Member Author

@edemaine edemaine Apr 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did some spot checking of Typewriter-Regular (as that's what I was working on recently) and the letters I checked seemed close, but there's definitely some error. For example, y has a yMin of -228 and yMax of 431, and the metrics file says [0.22222, 0.43056, ...]. That's more than floating-point rounding should account for... I'll turn this into an issue (#43).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ylemkimon the height and depth calculations look reasonable.

@edemaine the difference may be due to when we're getting the measurements. One of the steps in the pipeline is the darken the fonts by making them a bit thicker.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like only the entries that had issues in fontMetricsData.js were updated. Based on what I'm seeing in this diff things look fine. If there's differences between the TTF and tfm file it's probably because of the darkening we do the font.

Copy link
Member

@kevinbarabash kevinbarabash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevinbarabash kevinbarabash merged commit f541ce8 into KaTeX:master Apr 13, 2018
@kevinbarabash
Copy link
Member

I'm not an expert in fonttools

Me neither.

edemaine added a commit to edemaine/KaTeX that referenced this pull request Apr 14, 2018
kevinbarabash pushed a commit to KaTeX/KaTeX that referenced this pull request Apr 21, 2018
* Fix space width in \texttt

Fix #1255 via KaTeX/katex-fonts#41.
Also fix width metrics via KaTeX/katex-fonts#42.

* Improve test

* Update screenshots
HosseinAgha pushed a commit to HosseinAgha/KaTeX that referenced this pull request Apr 23, 2018
* Fix space width in \texttt

Fix KaTeX#1255 via KaTeX/katex-fonts#41.
Also fix width metrics via KaTeX/katex-fonts#42.

* Improve test

* Update screenshots
kevinbarabash pushed a commit to KaTeX/KaTeX that referenced this pull request Apr 28, 2018
* Expose defineSymbol in the main KaTeX object

* More Unicode letters (#1260)

This PR serves as a complement to PR #1232 by supporting some letters that are omitted from the Unicode range 1D400–1D7FF.

* Include Bold-Italic fonts for \boldsymbol (#1257)

* Include Bold-Italic fonts for \boldsymbol

Fix #1228

* Update screenshots

* README: Add size badge (#1253)

* README: Add size badge

Add a size badge showing size of gzipped katex.min.js

* update-sri: Add code to replace size badge in readme

* Change to use badge from shields.io instead

My bad for assuming that badgesize.io supports https. Change to use the
badge from shields.io which supports https.

* More Unicode letters (#1260)

This PR serves as a complement to PR #1232 by supporting some letters that are omitted from the Unicode range 1D400–1D7FF.

* Include Bold-Italic fonts for \boldsymbol (#1257)

* Include Bold-Italic fonts for \boldsymbol

Fix #1228

* Update screenshots

* README: Add size badge

Add a size badge showing size of gzipped katex.min.js

* update-sri: Add code to replace size badge in readme

* Change to use badge from shields.io instead

My bad for assuming that badgesize.io supports https. Change to use the
badge from shields.io which supports https.

* Use badgesize.io with https

* Fix space width in \texttt (#1261)

* Fix space width in \texttt

Fix #1255 via KaTeX/katex-fonts#41.
Also fix width metrics via KaTeX/katex-fonts#42.

* Improve test

* Update screenshots
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants