diff --git a/bddy.js b/bddy.js index c0e5920f0..8d3bca31f 100644 --- a/bddy.js +++ b/bddy.js @@ -1,8 +1,10 @@ "use strict"; const fs = require("fs-extra"); +const os = require("os"); const CVT_PADDING = 300; +const PREFIX = "sarasa"; function objToArgs(o) { let a = []; @@ -39,13 +41,13 @@ const STYLE_FILENAME_OF = { italic: "italic", bolditalic: "bolditalic" }; - const STYLE_OF = { regular: "Regular", bold: "Bold", italic: "Italic", - bolditalic: "BoldItalic" + bolditalic: "Bold Italic" }; +const STYLES = Object.keys(STYLE_FILENAME_OF); const FAMILY_OF = { cl: "cl", @@ -53,6 +55,8 @@ const FAMILY_OF = { tc: "tc", j: "j" }; +const SUBFAMILIES = Object.keys(FAMILY_OF); + function styleOf(set) { return (set + "") .split("-") @@ -84,10 +88,11 @@ module.exports = function(ctx, forany, argv, bddy) { forany.file(`build/pass0`).def(ctx.ensureDir); forany.file(`build/pass1`).def(ctx.ensureDir); forany.file(`build/out`).def(ctx.ensureDir); + forany.file(`build/ttc`).def(ctx.ensureDir); forany.file(`build/out/*.ttf`).def(async function(target) { await this.check(`${target.dir}`); - const rawName = target.name.replace(/^sarasa-/g, ""); + const rawName = target.name.replace(new RegExp("^" + PREFIX + "-", "g"), ""); const [$1, $2] = await this.need( `build/pass1/${rawName}.ttf`, `hint/out/${deItalizedNameOf(rawName)}.ttf` @@ -182,14 +187,26 @@ module.exports = function(ctx, forany, argv, bddy) { await this.rm(tmpOTD); }); - forany.virt("all").def(async function(target) { + forany.virt("ttf").def(async function(target) { let targets = []; - - for (let sf in FAMILY_OF) - for (let st in STYLE_FILENAME_OF) { + for (let sf of SUBFAMILIES) + for (let st of STYLES) { targets.push(`build/out/sarasa-${sf}-${st}.ttf`); } await this.need(...targets); }); + + forany.file(`build/ttc/*.ttc`).def(async function(target) { + await this.check(`${target.dir}`); + const rawName = target.name.replace(new RegExp("^" + PREFIX + "-", "g"), ""); + const $$ = await this.need( + ...SUBFAMILIES.map(sf => `build/out/${PREFIX}-${sf}-${rawName}.ttf`) + ); + const ttcize = "node_modules/.bin/otfcc-ttcize" + (os.platform() === "win32" ? ".cmd" : ""); + await this.run(ttcize, "-o", target, ...$$, "-k", "-h"); + }); + forany.virt("ttc").def(async function(target) { + await this.need(...STYLES.map(st => `build/ttc/${PREFIX}-${st}.ttc`)); + }); }; diff --git a/build-pass2/build.js b/build-pass2/build.js index 39a788aee..6ebd23989 100644 --- a/build-pass2/build.js +++ b/build-pass2/build.js @@ -1,10 +1,44 @@ "use strict"; -const { quadify, introduce, build, gc, merge: { below: merge } } = require("megaminx"); +const { + quadify, + introduce, + build, + gc, + setEncodings, + merge: { below: merge } +} = require("megaminx"); const { isKanji } = require("caryll-iddb"); const italize = require("../common/italize"); const { nameFont } = require("./metadata.js"); +const ENCODINGS = { + J: { + gbk: false, + big5: false, + jis: true, + korean: false + }, + SC: { + gbk: true, + big5: false, + jis: false, + korean: false + }, + TC: { + gbk: false, + big5: true, + jis: false, + korean: false + }, + CL: { + gbk: false, + big5: true, + jis: false, + korean: false + } +}; + async function pass(ctx, config, argv) { const a = await ctx.run(introduce, "a", { from: argv.main, @@ -29,8 +63,21 @@ async function pass(ctx, config, argv) { version: "0.1.0", family: "Sarasa Gothic " + argv.subfamily, style: argv.style + }, + zh_CN: { + family: "更纱黑体 " + argv.subfamily, + style: argv.style + }, + zh_TW: { + family: "更紗黑體 " + argv.subfamily, + style: argv.style + }, + ja_JP: { + family: "更紗ゴシック " + argv.subfamily, + style: argv.style } }); + await ctx.run(setEncodings, "a", ENCODINGS[argv.subfamily]); await ctx.run(build, "a", { to: config.o, optimize: true }); } diff --git a/build-pass2/metadata.js b/build-pass2/metadata.js index b34dcfe5e..cb52c5b07 100644 --- a/build-pass2/metadata.js +++ b/build-pass2/metadata.js @@ -28,7 +28,7 @@ function convPostscript(name) { } function compatibilityName(family, style) { - if (style === "Regular" || style === "Bold" || style === "Italic" || style === "BoldItalic") { + if (style === "Regular" || style === "Bold" || style === "Italic" || style === "Bold Italic") { return { family, style, standardFour: true }; } else { return { family: family + " " + style, style: "Regular", standardFour: false }; diff --git a/package.json b/package.json index 0e0917531..1ee3896d9 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "inquirer": "^3.2.3", "inquirer-file-path": "^1.0.0", "megaminx": "^0.4.3", + "otfcc-ttcize": "^0.5.0", "scc-config": "^0.8.1", "which": "^1.2.14", "yargs": "^8.0.2"