Simplify code around metadata

This commit is contained in:
be5invis 2021-04-27 00:45:40 -07:00
parent 5025aa1d7b
commit ca49579e17
15 changed files with 169 additions and 340 deletions

View file

@ -11,16 +11,13 @@ const { assignFontNames } = require("../meta/naming");
const { copyFontMetrics } = require("../meta/aesthetics");
module.exports = async function (argv, para) {
const otd = EmptyFont();
const gs = buildGlyphs(para);
assignFontNames(para, otd);
copyFontMetrics(gs.fontMetrics, otd);
const baseFont = EmptyFont();
assignFontNames(para, baseFont);
copyFontMetrics(gs.fontMetrics, baseFont);
const otl = buildOtl(para, gs.glyphStore);
otd.GSUB = otl.GSUB;
otd.GPOS = otl.GPOS;
otd.GDEF = otl.GDEF;
// Regulate
const excludeChars = new Set();
@ -31,9 +28,9 @@ module.exports = async function (argv, para) {
}
const cache = await Caching.load(argv);
const finalGs = finalizeFont(cache, para, gs.glyphStore, excludeChars, otd);
const finalGs = finalizeFont(cache, para, gs.glyphStore, excludeChars, otl);
await Caching.save(argv, cache);
const font = convertOtd(otd, finalGs);
const font = convertOtd(baseFont, otl, finalGs);
return { font, glyphStore: finalGs };
};

View file

@ -1,122 +1,14 @@
"use strict";
const { Ot } = require("ot-builder");
module.exports = function () {
return {
head: {
checkSumAdjustment: 369537602,
flags: 11,
fontDirectionHint: 2,
fontRevision: 1,
glyphDataFormat: 0,
indexToLocFormat: 0,
lowestRecPPEM: 8,
macStyle: 0,
magickNumber: 1594834165,
created: 3562553439,
modified: 3562553439,
unitsPerEm: 1000,
version: 1,
xMax: 306,
xMin: 34,
yMax: 682,
yMin: 0
},
hhea: {
advanceWidthMax: 374,
ascender: 812,
caretOffset: 0,
caretSlopeRise: 1,
caretSlopeRun: 0,
descender: -212,
lineGap: 92,
metricDataFormat: 0,
minLeftSideBearing: 34,
minRightSideBearing: 68,
numOfLongHorMetrics: 1,
reserved0: 0,
reserved1: 0,
reserved2: 0,
reserved3: 0,
version: 1,
xMaxExtent: 306
},
OS_2: {
achVendID: "BE5N",
panose: {
bFamilyType: 2,
bSerifStyle: 0,
bWeight: 5,
bProportion: 9,
bContrast: 3,
bStrokeVariation: 0,
bArmStyle: 0,
bLetterform: 0,
bMidline: 0,
bXHeight: 4
},
fsSelection: 192,
fsType: 0,
sCapHeight: 0,
sFamilyClass: 0,
sTypoAscender: 812,
sTypoDescender: -212,
sTypoLineGap: 92,
sxHeight: 792,
ulUnicodeRange1: 1,
ulUnicodeRange2: 268435456,
ulUnicodeRange3: 0,
ulUnicodeRange4: 0,
usBreakChar: 32,
usDefaultChar: 0,
usFirstCharIndex: 0,
usLastCharIndex: 0,
usMaxContext: 1,
usWeightClass: 400,
usWidthClass: 5,
usWinAscent: 812,
usWinDescent: 212,
version: 4,
xAvgCharWidth: 500,
yStrikeoutPosition: 265,
yStrikeoutSize: 51,
ySubscriptXOffset: 0,
ySubscriptXSize: 665,
ySubscriptYOffset: 143,
ySubscriptYSize: 716,
ySuperscriptXOffset: 0,
ySuperscriptXSize: 665,
ySuperscriptYOffset: 491,
ySuperscriptYSize: 716,
ulCodePageRange1: 0x2000011f,
ulCodePageRange2: 0xc4000000
},
post: {
version: 2,
isFixedPitch: false,
italicAngle: 0,
underlinePosition: -50,
underlineThickness: 50,
minMemType42: 0,
maxMemType42: 0,
minMemType1: 0,
maxMemType1: 0
},
maxp: {
version: 1.0,
numGlyphs: 0,
maxPoints: 0,
maxContours: 0,
maxCompositePoints: 0,
maxCompositeContours: 0,
maxZones: 2,
maxTwilightPoints: 0,
maxStorage: 0,
maxFunctionDefs: 0,
maxInstructionDefs: 0,
maxStackElements: 0,
maxSizeOfInstructions: 0,
maxComponentElements: 0,
maxComponentDepth: 0
}
head: new Ot.Head.Table(),
hhea: new Ot.MetricHead.Hhea(),
os2: new Ot.Os2.Table(4),
post: new Ot.Post.Table(3, 0),
maxp: Ot.Maxp.Table.TrueType(),
name: new Ot.Name.Table()
};
};

View file

@ -2,10 +2,10 @@
const { Radical } = require("../../support/gr");
module.exports = function gcFont(glyphStore, excludedChars, restFont, cfg) {
markSweepOtlLookups(restFont.GSUB);
markSweepOtlLookups(restFont.GPOS);
const sink = markGlyphs(glyphStore, excludedChars, restFont, cfg);
module.exports = function gcFont(glyphStore, excludedChars, otl, cfg) {
markSweepOtlLookups(otl.GSUB);
markSweepOtlLookups(otl.GPOS);
const sink = markGlyphs(glyphStore, excludedChars, otl, cfg);
return sweep(glyphStore, sink);
};
@ -66,9 +66,9 @@ function sweepFeatures(table, accessibleLookupsIds) {
table.features = features1;
}
function markGlyphs(glyphStore, excludedChars, restFont, cfg) {
function markGlyphs(glyphStore, excludedChars, otl, cfg) {
const sink = markGlyphsInitial(glyphStore, excludedChars);
while (markGlyphsStep(glyphStore, sink, restFont, cfg));
while (markGlyphsStep(glyphStore, sink, otl, cfg));
return sink;
}
function markGlyphsInitial(glyphStore, excludedChars) {
@ -86,11 +86,11 @@ function markGlyphsInitial(glyphStore, excludedChars) {
}
return sink;
}
function markGlyphsStep(glyphStore, sink, restFont, cfg) {
function markGlyphsStep(glyphStore, sink, otl, cfg) {
const glyphCount = sink.size;
if (restFont.GSUB) {
for (const l in restFont.GSUB.lookups) {
const lookup = restFont.GSUB.lookups[l];
if (otl.GSUB) {
for (const l in otl.GSUB.lookups) {
const lookup = otl.GSUB.lookups[l];
if (!lookup) continue;
markGlyphsLookupImpl(sink, lookup, cfg);
}

View file

@ -1,22 +1,12 @@
const Metadata = require("./metadata");
const convertGlyphs = require("./glyphs");
const convertName = require("./name");
const { convertGsub, convertGpos, convertGdef } = require("./layout");
module.exports = function (otdRestFont, gs) {
const head = Metadata.convertHead(otdRestFont.head);
const hhea = Metadata.convertHhea(otdRestFont.hhea);
const post = Metadata.convertPost(otdRestFont.post);
const maxp = Metadata.convertMaxp(otdRestFont.maxp);
const os2 = Metadata.convertOs2(otdRestFont.OS_2);
const name = convertName(otdRestFont.name);
module.exports = function (baseFont, otl, gs) {
const { glyphs, cmap } = convertGlyphs(gs);
const gsub = convertGsub(otdRestFont.GSUB, glyphs);
const gpos = convertGpos(otdRestFont.GPOS, glyphs);
const gdef = convertGdef(otdRestFont.GDEF, glyphs);
const gsub = convertGsub(otl.GSUB, glyphs);
const gpos = convertGpos(otl.GPOS, glyphs);
const gdef = convertGdef(otl.GDEF, glyphs);
return { glyphs, head, hhea, post, maxp, os2, name, cmap, gsub, gpos, gdef };
return { ...baseFont, glyphs, cmap, gsub, gpos, gdef };
};

View file

@ -1,98 +0,0 @@
const { Ot } = require("ot-builder");
exports.convertHead = convertHead;
function convertHead(otdHead) {
const head = new Ot.Head.Table();
head.fontRevision = otdHead.fontRevision;
head.flags = otdHead.flags;
head.fontDirectionHint = otdHead.fontDirectionHint;
head.unitsPerEm = otdHead.unitsPerEm;
head.macStyle = macStyleObjToEnum(otdHead.macStyle);
head.lowestRecPPEM = otdHead.lowestRecPPEM;
head.glyphDataFormat = otdHead.glyphDataFormat;
return head;
}
exports.convertHhea = convertHhea;
function convertHhea(otdHhea) {
const hhea = new Ot.MetricHead.Hhea();
hhea.ascender = otdHhea.ascender;
hhea.descender = otdHhea.descender;
hhea.lineGap = otdHhea.lineGap;
hhea.caretSlopeRise = otdHhea.caretSlopeRise;
hhea.caretSlopeRun = otdHhea.caretSlopeRun;
hhea.caretOffset = otdHhea.caretOffset;
return hhea;
}
exports.convertPost = convertPost;
function convertPost(otdPost) {
const post = new Ot.Post.Table(3, 0);
post.italicAngle = otdPost.italicAngle;
post.underlinePosition = otdPost.underlinePosition;
post.underlineThickness = otdPost.underlineThickness;
post.isFixedPitch = otdPost.isFixedPitch;
return post;
}
exports.convertMaxp = convertMaxp;
function convertMaxp(otdMaxp) {
const maxp = Ot.Maxp.Table.TrueType();
return maxp;
}
exports.convertOs2 = convertOs2;
function convertOs2(otdOs2) {
const os2 = new Ot.Os2.Table(4);
os2.achVendID = otdOs2.achVendID;
os2.panose = otdOs2.panose;
os2.fsSelection = fsSelectionObjToEnum(otdOs2.fsSelection);
os2.fsType = otdOs2.fsType;
os2.sCapHeight = otdOs2.sCapHeight;
os2.sFamilyClass = otdOs2.sFamilyClass;
os2.sTypoAscender = otdOs2.sTypoAscender;
os2.sTypoDescender = otdOs2.sTypoDescender;
os2.sTypoLineGap = otdOs2.sTypoLineGap;
os2.sxHeight = otdOs2.sxHeight;
os2.usBreakChar = otdOs2.usBreakChar;
os2.usDefaultChar = otdOs2.usDefaultChar;
os2.usFirstCharIndex = otdOs2.usFirstCharIndex;
os2.usLastCharIndex = otdOs2.usLastCharIndex;
os2.usMaxContext = otdOs2.usMaxContext;
os2.usWeightClass = otdOs2.usWeightClass;
os2.usWidthClass = otdOs2.usWidthClass;
os2.usWinAscent = otdOs2.usWinAscent;
os2.usWinDescent = otdOs2.usWinDescent;
os2.xAvgCharWidth = otdOs2.xAvgCharWidth;
os2.yStrikeoutPosition = otdOs2.yStrikeoutPosition;
os2.yStrikeoutSize = otdOs2.yStrikeoutSize;
os2.ySubscriptXOffset = otdOs2.ySubscriptXOffset;
os2.ySubscriptXSize = otdOs2.ySubscriptXSize;
os2.ySubscriptYOffset = otdOs2.ySubscriptYOffset;
os2.ySubscriptYSize = otdOs2.ySubscriptYSize;
os2.ySuperscriptXOffset = otdOs2.ySuperscriptXOffset;
os2.ySuperscriptXSize = otdOs2.ySuperscriptXSize;
os2.ySuperscriptYOffset = otdOs2.ySuperscriptYOffset;
os2.ySuperscriptYSize = otdOs2.ySuperscriptYSize;
os2.ulCodePageRange1 = otdOs2.ulCodePageRange1;
os2.ulCodePageRange2 = otdOs2.ulCodePageRange2;
return os2;
}
function macStyleObjToEnum(o) {
return (
(o.bold ? Ot.Head.MacStyle.Bold : 0) |
(o.italic ? Ot.Head.MacStyle.Italic : 0) |
(o.condensed ? Ot.Head.MacStyle.Condensed : 0) |
(o.extended ? Ot.Head.MacStyle.Extended : 0)
);
}
function fsSelectionObjToEnum(o) {
return (
(o.oblique ? Ot.Os2.FsSelection.OBLIQUE : 0) |
(o.bold ? Ot.Os2.FsSelection.BOLD : 0) |
(o.italic ? Ot.Os2.FsSelection.ITALIC : 0) |
(o.regular ? Ot.Os2.FsSelection.REGULAR : 0) |
(o.useTypoMetrics ? Ot.Os2.FsSelection.USE_TYPO_METRICS : 0)
);
}

View file

@ -1,20 +0,0 @@
const { Ot } = require("ot-builder");
module.exports = convertName;
function convertName(otdName) {
const name = new Ot.Name.Table();
for (const entry of otdName) {
name.records.push({
platformID: entry.platformID,
encodingID: entry.encodingID,
languageID: entry.languageID,
nameID: entry.nameID,
value:
entry.platformID === 3 && entry.encodingID === 1
? entry.nameString
: Buffer.from(entry.nameString, "utf-8")
});
}
return name;
}

View file

@ -192,8 +192,8 @@ glyph-block AutoBuild-Enclosure : begin
define bot : SymbolMid - CAP * dscale / 2 - (CAP * spatt)
define mosaicLeft 0
define mosaicRight width
define mosaicBot fontMetrics.OS_2.sTypoDescender
define mosaicTop fontMetrics.OS_2.sTypoAscender
define mosaicBot fontMetrics.os2.sTypoDescender
define mosaicTop fontMetrics.os2.sTypoAscender
define left : Math.max
SB + O * 3
Math.min

View file

@ -27,7 +27,7 @@ export all : define [buildGlyphs para recursive recursiveCodes] : begin
define metrics : calculateMetrics para
define [object GlobalTransform UPM Middle CAP XH SB RightSB Contrast Stroke Width TanSlope OverlayPos Descender SymbolMid ParenTop ParenBot OperTop OperBot PlusTop PlusBot TackTop TackBot AdviceStroke MVertStrokeD] metrics
define fontMetrics {.head {.} .hhea {.} .OS_2 {.} .post {.}}
define fontMetrics { .head {.} .hhea {.} .os2 {.} .post {.} }
setFontMetrics para metrics fontMetrics
# Anchor parameters

View file

@ -11,8 +11,8 @@ glyph-block Symbol-Math-Integrals : begin
glyph-block-import Common-Derivatives
glyph-block-import Letter-Latin-Lower-F : LongSShape
define MosaicTop fontMetrics.OS_2.sTypoAscender
define MosaicBottom fontMetrics.OS_2.sTypoDescender
define MosaicTop fontMetrics.os2.sTypoAscender
define MosaicBottom fontMetrics.os2.sTypoDescender
define MosaicHeight : MosaicTop - MosaicBottom
define IntHookY : Hook * 0.75

View file

@ -11,8 +11,8 @@ glyph-block Symbol-Mosaic : begin
glyph-block-import CommonShapes
glyph-block-import Common-Derivatives
define MosaicTop fontMetrics.OS_2.sTypoAscender
define MosaicBottom fontMetrics.OS_2.sTypoDescender
define MosaicTop fontMetrics.os2.sTypoAscender
define MosaicBottom fontMetrics.os2.sTypoDescender
for-width-kinds WideWidth4
@ -728,8 +728,8 @@ glyph-block Symbol-Mosaic-Powerline : begin
glyph-block-import CommonShapes : ForceUpright FlipAround HBarBottom HBarTop
glyph-block-import Common-Derivatives : refer-glyph
define MosaicTop fontMetrics.OS_2.sTypoAscender
define MosaicBottom fontMetrics.OS_2.sTypoDescender
define MosaicTop fontMetrics.os2.sTypoAscender
define MosaicBottom fontMetrics.os2.sTypoDescender
for-width-kinds WideWidth4
local pwlMidOrig : (MosaicTop + MosaicBottom) / 2

View file

@ -12,7 +12,7 @@ glyph-block Symbol-Pictograph-Metric-Marks : begin
glyph-block-import Common-Derivatives
create-glyph 'metmark' 0xE00F : glyph-proc
include : VBar Middle (-fontMetrics.OS_2.usWinDescent) (fontMetrics.OS_2.usWinAscent) ShoulderFine
include : VBar Middle (-fontMetrics.os2.usWinDescent) (fontMetrics.os2.usWinAscent) ShoulderFine
include : HBar Middle Width 0 ShoulderFine
include : HBar Middle Width CAP ShoulderFine
include : HBar Middle Width XH ShoulderFine
@ -21,8 +21,8 @@ glyph-block Symbol-Pictograph-Metric-Marks : begin
include : HBar 0 Middle ParenTop ShoulderFine
include : HBar 0 Middle ParenBot ShoulderFine
define MosaicTop fontMetrics.OS_2.sTypoAscender
define MosaicBottom fontMetrics.OS_2.sTypoDescender
define MosaicTop fontMetrics.os2.sTypoAscender
define MosaicBottom fontMetrics.os2.sTypoDescender
define MarkerSize (UPM / 12)
define MarkerBarWidth (UPM / 50)

View file

@ -10,8 +10,8 @@ glyph-block Symbol-Punctuation-Brackets : begin
glyph-block-import CommonShapes
glyph-block-import Common-Derivatives
define MosaicTop fontMetrics.OS_2.sTypoAscender
define MosaicBottom fontMetrics.OS_2.sTypoDescender
define MosaicTop fontMetrics.os2.sTypoAscender
define MosaicBottom fontMetrics.os2.sTypoDescender
define MosaicHeight : MosaicTop - MosaicBottom
define [ParenDim] : params [[delta 0] [dp DesignParameters]] : object

View file

@ -219,41 +219,69 @@ export : define [setFontMetrics para metrics fm] : begin
define winMetricAscenderPad : Math.round : fallback para.winMetricAscenderPad 0
define winMetricDescenderPad : Math.round : fallback para.winMetricDescenderPad 0
set fm.OS_2.xAvgCharWidth Width
set fm.os2.xAvgCharWidth Width
set fm.head.unitsPerEm 1000
set fm.hhea.ascender asc
set fm.OS_2.usWinAscent (asc + winMetricAscenderPad)
set fm.OS_2.sTypoAscender asc
set fm.os2.usWinAscent (asc + winMetricAscenderPad)
set fm.os2.sTypoAscender asc
set fm.hhea.descender (Descender - descenderPad)
set fm.OS_2.usWinDescent ([Math.abs desc] + descenderPad + winMetricDescenderPad)
set fm.OS_2.sTypoDescender (desc - descenderPad)
set fm.os2.usWinDescent ([Math.abs desc] + descenderPad + winMetricDescenderPad)
set fm.os2.sTypoDescender (desc - descenderPad)
set fm.hhea.lineGap (leading - asc + Descender)
set fm.OS_2.sTypoLineGap (leading - asc + desc)
set fm.os2.sTypoLineGap (leading - asc + desc)
set fm.OS_2.sxHeight XH
set fm.OS_2.sCapHeight CAP
set fm.os2.sxHeight XH
set fm.os2.sCapHeight CAP
set fm.post.italicAngle [Math.round (0 - para.slopeAngle)]
# Fixed metrics
set fm.os2.yStrikeoutPosition para."os2.yStrikeoutPosition"
set fm.os2.yStrikeoutSize para."os2.yStrikeoutSize"
set fm.os2.ySubscriptXOffset para."os2.ySubscriptXOffset"
set fm.os2.ySubscriptXSize para."os2.ySubscriptXSize"
set fm.os2.ySubscriptYOffset para."os2.ySubscriptYOffset"
set fm.os2.ySubscriptYSize para."os2.ySubscriptYSize"
set fm.os2.ySuperscriptXOffset para."os2.ySuperscriptXOffset"
set fm.os2.ySuperscriptXSize para."os2.ySuperscriptXSize"
set fm.os2.ySuperscriptYOffset para."os2.ySuperscriptYOffset"
set fm.os2.ySuperscriptYSize para."os2.ySuperscriptYSize"
set fm.post.underlinePosition para."post.underlinePosition"
set fm.post.underlineThickness para."post.underlineThickness"
export : define [copyFontMetrics fm1 fm2] : begin
set fm2.OS_2.xAvgCharWidth fm1.OS_2.xAvgCharWidth
set fm2.os2.xAvgCharWidth fm1.os2.xAvgCharWidth
set fm2.head.unitsPerEm fm1.head.unitsPerEm
set fm2.hhea.ascender fm1.hhea.ascender
set fm2.OS_2.usWinAscent fm1.OS_2.usWinAscent
set fm2.OS_2.sTypoAscender fm1.OS_2.sTypoAscender
set fm2.os2.usWinAscent fm1.os2.usWinAscent
set fm2.os2.sTypoAscender fm1.os2.sTypoAscender
set fm2.hhea.descender fm1.hhea.descender
set fm2.OS_2.usWinDescent fm1.OS_2.usWinDescent
set fm2.OS_2.sTypoDescender fm1.OS_2.sTypoDescender
set fm2.os2.usWinDescent fm1.os2.usWinDescent
set fm2.os2.sTypoDescender fm1.os2.sTypoDescender
set fm2.hhea.lineGap fm1.hhea.lineGap
set fm2.OS_2.sTypoLineGap fm1.OS_2.sTypoLineGap
set fm2.os2.sTypoLineGap fm1.os2.sTypoLineGap
set fm2.OS_2.sxHeight fm1.OS_2.sxHeight
set fm2.OS_2.sCapHeight fm1.OS_2.sCapHeight
set fm2.os2.sxHeight fm1.os2.sxHeight
set fm2.os2.sCapHeight fm1.os2.sCapHeight
set fm2.post.italicAngle fm1.post.italicAngle
set fm2.os2.yStrikeoutPosition fm1.os2.yStrikeoutPosition
set fm2.os2.yStrikeoutSize fm1.os2.yStrikeoutSize
set fm2.os2.ySubscriptXOffset fm1.os2.ySubscriptXOffset
set fm2.os2.ySubscriptXSize fm1.os2.ySubscriptXSize
set fm2.os2.ySubscriptYOffset fm1.os2.ySubscriptYOffset
set fm2.os2.ySubscriptYSize fm1.os2.ySubscriptYSize
set fm2.os2.ySuperscriptXOffset fm1.os2.ySuperscriptXOffset
set fm2.os2.ySuperscriptXSize fm1.os2.ySuperscriptXSize
set fm2.os2.ySuperscriptYOffset fm1.os2.ySuperscriptYOffset
set fm2.os2.ySuperscriptYSize fm1.os2.ySuperscriptYSize
set fm2.post.underlinePosition fm1.post.underlinePosition
set fm2.post.underlineThickness fm1.post.underlineThickness
export : define [compositeBaseAnchors] : begin
local h {.}
foreach a [items-of arguments] : foreach k [items-of [Object.keys a.baseAnchors]] : begin

View file

@ -1,5 +1,8 @@
import [fallback] from '../support/utils'
import 'semver' as semver
import [Ot] from "ot-builder"
extern Buffer
import [fallback] from '../support/utils'
define COPYRIGHT 0
define FAMILY 1
@ -19,18 +22,18 @@ define WWS_PREFERRED_FAMILY 21
define WWS_PREFERRED_STYLE 22
define [nameFont font nameid str] : begin
font.name.push : object # Mac Roman
platformID 1
encodingID 0
languageID 0
nameID nameid
nameString str
font.name.push : object # Windows Unicode English
platformID 3
encodingID 1
languageID 1033
nameID nameid
nameString str
font.name.records.push : object # Mac Roman
platformID 1
encodingID 0
languageID 0
nameID nameid
value : Buffer.from str 'utf-8'
font.name.records.push : object # Windows Unicode English
platformID 3
encodingID 1
languageID 1033
nameID nameid
value str
define weightToMenuStyleMap : object
100 "Thin"
@ -122,11 +125,14 @@ define [getStyleLinkedStyles weight width slope] : begin
getStyle nameSuffixWeight nameSuffixWidth nameSuffixSlope
getShortStyle nameSuffixWeight nameSuffixWidth nameSuffixSlope
define [accumulate entries] : begin
local s 0
foreach { ev cond } [items-of entries] : begin
if cond : set s : s + ev
return s
export : define [assignFontNames para font] : begin
set font.name {}
# Preferred names
define family : para.naming.family.trim
define style : getStyle para.naming.weight para.naming.width para.naming.slope
define version : "Version " + para.naming.version
@ -140,6 +146,7 @@ export : define [assignFontNames para font] : begin
nameFont font WWS_PREFERRED_FAMILY family # WWS Preferred Family
nameFont font WWS_PREFERRED_STYLE style # WWS Preferred Style
# Compat names
local {compatStyle compatFamilySuffix shortCompatFamilySuffix} : getStyleLinkedStyles para.naming.weight para.naming.width para.naming.slope
local compatFamily family
if (compatFamilySuffix != "Regular") : set compatFamily : family + ' ' + compatFamilySuffix
@ -154,47 +161,65 @@ export : define [assignFontNames para font] : begin
nameFont font FULL_NAME fontfullName # Full Name
nameFont font POSTSCRIPT : fontfullName.replace [regex ' ' 'g'] '-' # Postscript
nameFont font VERSION version # Version
# Misc names
nameFont font COPYRIGHT para.naming.copyright # Copyright
nameFont font MANUFACTURER para.naming.manufacturer # Manufacturer
nameFont font DESIGNER para.naming.designer # Designer
nameFont font DESCRIPTION para.naming.description # Description
nameFont font LICENCE para.naming.licence # Licence
set font.name : font.name.sort : lambda [a b] : begin
if (a.platformID != b.platformID) : return : a.platformID - b.platformID
if (a.encodingID != b.encodingID) : return : a.encodingID - b.encodingID
if (a.languageID != b.languageID) : return : a.languageID - b.languageID
return : a.nameID - b.nameID
# Weight, width and slope numbers
set font.os2.usWeightClass para.naming.weight
set font.os2.usWidthClass para.naming.width
set font.os2.panose.bWeight : 1 + para.naming.weight / 100
set font.os2.sFamilyClass : 8 * 0x100 + 9
set font.os2.xAvgCharWidth : Math.round para.width
# Weight, width and slope
set font.OS_2.usWeightClass para.naming.weight
set font.OS_2.usWidthClass para.naming.width
set font.OS_2.panose.bWeight : 1 + para.naming.weight / 100
set font.OS_2.fsSelection : object
oblique : not : not isOblique
bold : not : not isBold
italic : not : not (isItalic || isOblique)
regular : not : not ([not isBold] && [not isItalic] && [not isOblique])
useTypoMetrics true
set font.OS_2.sFamilyClass : 8 * 0x100 + 9
set font.OS_2.xAvgCharWidth : Math.round para.width
set font.head.macStyle : object
bold : not : not isBold
italic : not : not (isItalic || isOblique)
condensed : not : not (para.naming.width < 5)
extended : not : not (para.naming.width > 5)
set font.os2.fsSelection : accumulate : list
list Ot.Os2.FsSelection.OBLIQUE isOblique
list Ot.Os2.FsSelection.BOLD isBold
list Ot.Os2.FsSelection.ITALIC (isItalic || isOblique)
list Ot.Os2.FsSelection.REGULAR (!isBold && !isItalic && !isOblique)
list Ot.Os2.FsSelection.USE_TYPO_METRICS true
set font.head.macStyle : accumulate : list
list Ot.Head.MacStyle.Bold isBold
list Ot.Head.MacStyle.Italic (isItalic || isOblique)
list Ot.Head.MacStyle.Condensed (para.naming.width < 5)
list Ot.Head.MacStyle.Extended (para.naming.width > 5)
# Version
nameFont font VERSION version # Version
define majorVersion : semver.major para.naming.version
define minorVersion : semver.minor para.naming.version
define patchVersion : semver.patch para.naming.version
if (minorVersion > 99 || patchVersion > 9) : throw : new Error "Version number overflow"
set font.head.fontRevision : majorVersion + (minorVersion * 10 + patchVersion) / 1000
if [not para.isQuasiProportional] : begin
set font.OS_2.panose.bProportion 9 # Monospaced
# Panose
set font.os2.panose.bFamilyType 2
set font.os2.panose.bContrast 3
set font.os2.panose.bXHeight 4
# Pitch
if [not para.isQuasiProportional]
: then : begin
set font.os2.panose.bProportion 9 # Monospaced
set font.post.isFixedPitch true
: else : begin
set font.OS_2.panose.bProportion 0
set font.os2.panose.bProportion 0
set font.post.isFixedPitch false
# Misc
set font.head.flags : accumulate : list
list Ot.Head.Flags.BaseLineYAt0 true
list Ot.Head.Flags.LeftSidebearingAtX0 true
list Ot.Head.Flags.InstructionsMayDependOnPointSize true
list Ot.Head.Flags.ForcePpemToBeInteger true
list Ot.Head.Flags.InstructionMayAlterAdvanceWidth true
# Enforce the order of NAME table entries
font.name.records.sort : lambda [a b] : begin
if (a.platformID != b.platformID) : return : a.platformID - b.platformID
if (a.encodingID != b.encodingID) : return : a.encodingID - b.encodingID
if (a.languageID != b.languageID) : return : a.languageID - b.languageID
return : a.nameID - b.nameID

View file

@ -75,6 +75,21 @@ diversityF = 1
diversityI = 1
diversityII = 1
# OS/2 and POST fixed metrics
"os2.yStrikeoutPosition" = 265
"os2.yStrikeoutSize" = 51
"os2.ySubscriptXOffset" = 0
"os2.ySubscriptXSize" = 665
"os2.ySubscriptYOffset" = 143
"os2.ySubscriptYSize" = 716
"os2.ySuperscriptXOffset" = 0
"os2.ySuperscriptXSize" = 665
"os2.ySuperscriptYOffset" = 491
"os2.ySuperscriptYSize" = 716
"post.underlinePosition" = -50
"post.underlineThickness" = 50
[verbose]
verbose = true