Skip to content

Commit

Permalink
package
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanoHao committed Apr 23, 2022
1 parent 0e3de3e commit cc99ac7
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/
*.otf
*.ttf
*.ttx
src/*.otf
build/
dist/
Makefile
77 changes: 67 additions & 10 deletions configure.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"use strict";

const { dirname } = require('path');

const config = {
memory: 14, // per job, in GiB
name: {
normal: 'Resource Han Rounded',
postscript: 'ResourceHanRounded',
},
version: {
sfnt: 1.901,
name: "1.901",
head: 1.910,
name: "1.910",
},
vendor: {
id: 'Cyan',
Expand Down Expand Up @@ -80,7 +82,7 @@ const config = {
},
roundness: {
avar: [
// linear fit to ‘missing area’w
// linear fit to ‘missing area’
...new Array(100).fill(0).map((_, i) => [i * i / 10000 - 1, i / 100 - 1]),
[0, 0],
[1, 1],
Expand All @@ -105,49 +107,104 @@ module.exports = {

function main() {
const node = `node --max-old-space-size=${config.memory * 1024}`;
const ttcize = `node node_modules/otb-ttc-bundle/bin/otb-ttc-bundle`;
const sevenZip = `7z a -t7z -m0=LZMA:d=512m:fb=273 -ms`;
const quick7z = `cp $^ $(shell dirname $@) ; cd $(shell dirname $@) ; ${sevenZip} $(shell basename $@) $(shell basename -a $^) ; rm $(shell basename -a $^)`;

const makeRule = {
'.PHONY': {
dependency: ['all', 'clean', 'cleanall', 'cff2-vf', 'cff1-instance'],
rule: [],
},
'all': {
dependency: ['cff2-vf', ],
dependency: ['cff2-vf', 'cff2-otc', 'dist-cff2-otc', 'dist-cff2-otf', 'dist-cff2-subsetotf'],
rule: [],
},
'clean': {
dependency: [],
rule: [ '-rm -r build/' ],
rule: ['-rm -r build/'],
},
'cleanall': {
dependency: ['clean'],
rule: [ '-rm -r dist/' ],
rule: ['-rm -r dist/'],
},
'cff2-vf': {
dependency: [],
rule: [],
},
'dist-cff2-subsetotf': {
dependency: [],
rule: [],
},
'cff1-instance': {
dependency: [],
rule: [],
},
};

// cff2-vf targets
for (const subfamily of config.orthography.subfamily) {
const cff2Filename = `build/cff2/ResourceHanRounded${subfamily}-VF.otf`;
const shsFilename = `src/${config.orthography.shsMap[subfamily]}-VF.otf`;
makeRule['cff2-vf'].dependency.push(cff2Filename);
makeRule[cff2Filename] = {
dependency: [shsFilename],
rule: [
'mkdir -p build/cff2/',
`${node} script/main.js '${JSON.stringify({ subfamily })}'`,
],
rule: [`${node} script/main.js '${JSON.stringify({ subfamily })}'`],
}
}

// dist-cff2-subsetotf targets
for (const subfamily of config.orthography.subfamily.filter(
e => config.orthography.ttc.indexOf(e) == -1
)) {
const packFilename = `dist/cff2-subsetotf/RHR-CFF2-${subfamily}-${config.version.name}.7z`;
const cff2Filename = `build/cff2/ResourceHanRounded${subfamily}-VF.otf`;
makeRule['dist-cff2-subsetotf'].dependency.push(packFilename);
makeRule[packFilename] = {
dependency: [cff2Filename],
rule: [quick7z],
}
}

function makeFriendlyRule(friendlyName, filename, dependency, rule) {
makeRule[friendlyName] = {
dependency: [filename],
rule: [],
};
makeRule[filename] = {
dependency: dependency,
rule: rule,
};
}

makeFriendlyRule(
'cff2-otc',
'build/cff2-otc/ResourceHanRounded-VF.ttc',
config.orthography.ttc.map(o => `build/cff2/ResourceHanRounded${o}-VF.otf`),
[`${ttcize} -o $@ $^`],
);

makeFriendlyRule(
'dist-cff2-otc',
`dist/cff2-otc/RHR-CFF2-OTC-${config.version.name}.7z`,
['build/cff2-otc/ResourceHanRounded-VF.ttc'],
[quick7z],
);

makeFriendlyRule(
'dist-cff2-otf',
`dist/cff2-otf/RHR-CFF2-OTF-${config.version.name}.7z`,
config.orthography.ttc.map(o => `build/cff2/ResourceHanRounded${o}-VF.otf`),
[quick7z],
);

// dump Makefile
for (const key in makeRule) {
const value = makeRule[key];
console.log(key, ':', ...value.dependency);
const targetDir = dirname(key);
if (targetDir != '.')
console.log(`\tmkdir -p ${targetDir}`);
for (const rule of value.rule)
console.log(`\t${rule}`);
}
Expand Down
1 change: 1 addition & 0 deletions module/build-meta-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function makeVFBaseNameTable(subfamily) {
function buildVFMetaData(font, param) {
const { subfamily } = param;

font.head.fontRevision = config.version.head;
font.os2.achVendID = config.vendor.id;
font.os2.usWeightClass = 200;

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"ot-builder": "~1.5.1"
"ot-builder": "~1.5.1",
"otb-ttc-bundle": "~1.5.1"
}
}
2 changes: 1 addition & 1 deletion preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<style>
@font-face {
font-family: "RHR CN VF";
src: url("./build/cff2/ResourceHanRoundedJP-VF.otf") format("opentype");
src: url("./build/cff2/ResourceHanRoundedCN-VF.otf") format("opentype");
}

body {
Expand Down

0 comments on commit cc99ac7

Please sign in to comment.