Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lineGap configuration option to the Font object #681

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sammyfeng0530
Copy link

Add a 'lineGap' configuration option to the Font object.

Description

Add a 'lineGap' configuration option to the Font object, so that the generated font file when calling toArrayBuffer includes the 'lineGap' property.

Motivation and Context

I need the 'lineGap' property to calculate the automatic height of text. Currently, the generated font file does not include this property, which causes inaccuracies in my text's automatic height calculation.

How Has This Been Tested?

const font = new Font({
    familyName: 'MyFont',
    styleName: 'Medium',
    unitsPerEm: 1000,
    ascender: 800,
    descender: 0,
    fsSelection: 42,
    lineGap: 500,
    tables: {os2: {achVendID: 'TEST'}},
    glyphs: glyphs
});
// It will be 500
console.log('font.lineGap :>> ', font.lineGap)

const buffer = font.toArrayBuffer()
const f = opentype.parse(buffer)
// It will be 500
console.log('f.lineGap :>> ', f.lineGap)
// It will be 500
console.log('f.tables.hhea.lineGap :>> ', f.tables.hhea.lineGap)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I did npm run test and all tests passed green (including code styling checks).
  • I have added tests to cover my changes.
  • My change requires a change to the documentation.
  • I have updated the README accordingly.
  • I have read the CONTRIBUTING document.

@Finii
Copy link

Finii commented Sep 10, 2024

Hmm, HHEA gap and OS2 gap can be different in fonts and there are a lot fonts out there where that is the case.

I must admit I do not understand the issue, but this code enforces that both gap values are always the same:

image

Here an example of a commercial font with different gap values.
The gap values differ because the ascenders and descenders also differ and they want to have the same baseline to baseline metric, probably.

image

This is what font-line reports for that font, note 2 different metrices for 3 metric systems ;)

Version 0.83
SHA1: ef32ba2c56fcb8c6e5a8e7f57985a8be01484524

::::::::::::::::::::::::::::::::::::::::::::::::::
  Metrics
::::::::::::::::::::::::::::::::::::::::::::::::::
[head] Units per Em:   1000
[head] yMax:           962
[head] yMin:          -189
[OS/2] CapHeight:      693
[OS/2] xHeight:        520
[OS/2] TypoAscender:   776
[OS/2] TypoDescender: -185
[OS/2] WinAscent:      932
[OS/2] WinDescent:     189
[hhea] Ascent:         932
[hhea] Descent:       -189

[hhea] LineGap:        28
[OS/2] TypoLineGap:    56

::::::::::::::::::::::::::::::::::::::::::::::::::
  Ascent to Descent Calculations
::::::::::::::::::::::::::::::::::::::::::::::::::
[hhea] Ascent to Descent:              1121
[OS/2] TypoAscender to TypoDescender:  961
[OS/2] WinAscent to WinDescent:        1121

::::::::::::::::::::::::::::::::::::::::::::::::::
  Delta Values
::::::::::::::::::::::::::::::::::::::::::::::::::
[hhea] Ascent to [OS/2] TypoAscender:       156
[hhea] Descent to [OS/2] TypoDescender:     4
[OS/2] WinAscent to [OS/2] TypoAscender:    156
[OS/2] WinDescent to [OS/2] TypoDescender:  4

::::::::::::::::::::::::::::::::::::::::::::::::::
  Baseline to Baseline Distances
::::::::::::::::::::::::::::::::::::::::::::::::::
hhea metrics: 1149
typo metrics: 1017
win metrics:  1149

[OS/2] fsSelection USE_TYPO_METRICS bit set: False

::::::::::::::::::::::::::::::::::::::::::::::::::
  Ratios
::::::::::::::::::::::::::::::::::::::::::::::::::
hhea metrics / UPM:  1.15
typo metrics / UPM:  1.02
win metrics  / UPM:  1.15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants