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 new Opentype STAT table #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/tables/STAT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import r from 'restructure';


Copy link
Member

Choose a reason for hiding this comment

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

Extra whitespace line

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in all places

let AxisRecord = new r.Struct({
axisTag: new r.String(4), // e.g. 'ital', 'wght'
axisNameID: r.uint16,
axisOrdering: r.uint16,
})
Copy link
Member

Choose a reason for hiding this comment

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

Missing semicolons

Copy link
Author

Choose a reason for hiding this comment

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

Oh frabjous day. Attempting to check for missing semicolons also in the test file, to copy styles seen in other test files, eslint just kinda mentioned that I wasn't actually using a couple of the binary data sample tables 02, 03, 04. Missing semicolons and missed tests verified. Other cleanups done.


let AxisValue = new r.VersionedStruct( r.uint16, {
header: {
axisIndex: r.uint16,
flags: r.uint16,
valueNameID: r.uint16,
},
1: {
value: r.fixed32be,
Copy link
Member

Choose a reason for hiding this comment

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

Everything is assumed to be big endian by default. r.fixed32 should work and is an alias for r.fixed32be

},
2: {
nominalValue: r.fixed32be,
rangeMinValue: r.fixed32be,
rangeMaxValue: r.fixed32be,
},
3: {
value: r.fixed32be,
linkedValue: r.fixed32be,
},
})

let AxisValueArray = new r.Struct( {
axisValues: new r.Array(new r.Pointer(r.uint16, AxisValue),
parent => parent.parent.axisValueCount),
})


export default new r.VersionedStruct( r.uint32, {
header: {
designAxisSize: r.uint16,
designAxisCount: r.uint16,
offsetToDesignAxes: new r.Pointer(r.uint32,
new r.Array(AxisRecord,
'designAxisCount')),
axisValueCount: r.uint16,
offsetToAxisValueOffsets: new r.Pointer(r.uint32, AxisValueArray),
},
// Obsoleted version 1.0 ?
0x00010000: {
},
Copy link
Member

Choose a reason for hiding this comment

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

Put this on the same line as the opening brace

// Apparently version 1.1 added 'ElidedFallbackNameID'
0x00010001: {
elidedFallbackNameID: r.uint16,
},
})

2 changes: 2 additions & 0 deletions src/tables/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import gasp from './gasp';
import hdmx from './hdmx';
import kern from './kern';
import LTSH from './LTSH';
import STAT from './STAT';
import PCLT from './PCLT';
import VDMX from './VDMX';
import vhea from './vhea';
Expand All @@ -91,6 +92,7 @@ tables.gasp = gasp;
tables.hdmx = hdmx;
tables.kern = kern;
tables.LTSH = LTSH;
tables.STAT = STAT;
tables.PCLT = PCLT;
tables.VDMX = VDMX;
tables.vhea = vhea;
Expand Down
60 changes: 60 additions & 0 deletions test/data/Selawik-variable/Selawik-README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Overview
This version of Selawik is a test case and demonstration of OpenType 1.8 Font Variations technology and tables. It also includes some handy debugging characters.

This version of Selawik is intended for testing only, and is not recommended for shipping in applications, etc. For that, it is better to use the main branch of [Selawik](https://github.com/Microsoft/Selawik).

# Features

* Full TrueType hinting with VTT source tables included. See [Hinting](#hinting) for details.
* All tables required for OpenType 1.8 are present (see [Table Status](#table-status), below). This includes cvar (varied CVTs), GPOS/GDEF (kerning varies), and avar (coordinate space warping to match Segoe UI).

Note: This version of Selawik does not include an MVAR because its vertical metrics do not change anywhere in the design space, thus there is no need for MVAR. A future release will contain an axis that varies vertical metrics as an excuse to have an MVAR.

* Numerous interesting debugging glyphs (requires liga to be enabled). For example, \axis1 will show the current normalized wght coordinate. See [Debugging Glyphs](#debugging-glyphs) for details.
* 1 axis: weight

## Table status
The following tables are currently supported:

- [x] fvar
- [x] gvar
- [x] cvar
- [x] avar (to match Segoe UI weights and metrics)
- [x] STAT
- [x] GPOS/GDEF - kerning
- [x] HVAR

Not yet complete:

- [ ] GSUB/GDEF - to change dollar signs in the bold
- [ ] MVAR (future release)

## To do
* Add a second axis that varies vertical metrics so we need an MVAR table. This axis will not be one of the standard axes listed in the [OpenType 1.8 specification] (https://www.microsoft.com/typography/otspec/fvar.htm), so that it becomes an example of out to do a foundry-defined axis.
* Add Feature Variations (GPOS/GDEF) to switch dollar sign glyphs across weights.


# Debugging glyphs
Thanks to Greg Hitchcock's TrueType coding wizardry, this font includes many glyphs that are helpful for debugging implementations of variable fonts. It has a number of substitutions implemented as liga features:

Feature | Description
-------- | ----------
\axis1 | Shows the normalized coordinate on the wght axis for the currently selected instance (e.g. 1.0 for bold, -1.0 for light, or something in between).
\axis2 | Shows 0 because this font doesn't yet have a second axis.
\axis1hex | Same as \axis1 but in hex.
\axis2hex | Same as \axis2 but in hex.
\pointsize | Shows the point size passed to the TrueType rasterizer. Note that depending on how the application calls the rasterizer, this may not be what you expect - e.g. on Safari on MacOS, this is always 1024.
\ppem | Shows the pixels per em passed to the TrueType rastersize. Note that depending on how the application calls the rasterizer, this may not be what you expect - e.g. on Safari on MacOS, this is always 1024.
\ttversion | Shows the version of the TrueType rasterizer.
\ttmode | Shows the current TrueType rasterizer mode flags.
\boldtest | A glyph to help you detect artificial emboldening. The glyph has a vertical bar and a circle. The vertical bar's weight varies with the weight of the rest of the font: it gets bolder at bolder weights, lighter at lighter weights. The circle changes weight (and size) in opposition to the rest of the font: lighter at bold weights and vice versa. Thus, if you use this character and see both the circle and bar look bold, you're not looking at a true bold instance, but an algorithmically emboldened one.
\family | Shows the family name of the font.
\version | Shows the version of this font




# Hinting
This version of Selawik is primarily hinted with the light Latin hinting style Microsoft recommends for variable Latin fonts. The VTT Light Latin autohinter was used to create the first round of hints, which were then reviewed and touched up.

This hinting style only uses CVTs for vertical metrics anchors (ascender, descender, cap height, x-height, and baseline). While this makes for an easy job hinting a Latin font, it makes for a poor test case because Selawik doesn't vary vertical metrics with weight, thus doesn't vary CVTs, thus doesn't need a cvar. So, to make it more interesting, we added CVT-based stem hints to the lowercase only. This provided the need to vary CVTs and thus require a cvar. Note that this was only done for testing purposes. For variable fonts, Microsoft recommends the light hinting style using the `ResYDist()` command instead of a CVT-based stem hint.
Copy link
Member

Choose a reason for hiding this comment

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

Is there a license available for this font that we can include?

Copy link
Author

Choose a reason for hiding this comment

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

Both the original selawk.ttf and this modified Selawik-variable.ttf have the same notices in the name table:

 0:      © 2015 Microsoft Corporation (www.microsoft.com), with Reserved Font Name Selawik.  Selawik is a trademark of Microsoft Corporation in the United States and/or other countries.
13:      This Font Software is licensed under the SIL Open Font License, Version 1.1.
14:      http://opensource.org/licenses/OFL-1.1

I had ginned up an OFL.txt that began with these lines:

Copyright (c) 2015 Microsoft Corporation (www.microsoft.com), with Reserved Font Name Selawik. Selawik is a trademark of Microsoft Corporation in the United States and/or other countries.

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
followed by the OFL 1.1 text.

While I can't find a copy of any license file in the (original 2015) Selawik_Release.zip, I kinda felt presumptuous generating the missing license file. I'll do so to match your other font file entries if you wish.

Binary file added test/data/Selawik-variable/Selawik-variable.ttf
Binary file not shown.