From b87a3b9e62aede947f581975758fe117f3bdde63 Mon Sep 17 00:00:00 2001 From: Bryan Kok Date: Fri, 26 Mar 2021 01:49:01 +0800 Subject: [PATCH] Turn path offsetting (faux bolding) into a parameter, disable it by default https://github.com/Radically/HanaMinModLite/issues/4 --- .github/workflows/generate-svgs.yml | 4 ++-- index.ts | 26 +++++++++++++++++++++----- test-single-svg.ts | 2 +- utils.ts | 10 +++++++--- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/.github/workflows/generate-svgs.yml b/.github/workflows/generate-svgs.yml index f917850..1d82aa3 100644 --- a/.github/workflows/generate-svgs.yml +++ b/.github/workflows/generate-svgs.yml @@ -25,10 +25,10 @@ jobs: - run: sudo apt install wget - run: npm ci - run: sh fetch_dump.sh - - run: npm run start 2 1 glyphwiki_dump/dump_newest_only.txt glyphwiki_dump/dump_all_versions_noescape.txt glyphwiki_mincho.txt + - run: npm run start 2 1 0 glyphwiki_dump/dump_newest_only.txt glyphwiki_dump/dump_all_versions_noescape.txt glyphwiki_mincho.txt - run: cat glyphwiki_mincho.txt.* > glyphwiki_mincho.txt - run: gzip glyphwiki_mincho.txt - - run: npm run start 2 0 glyphwiki_dump/dump_newest_only.txt glyphwiki_dump/dump_all_versions_noescape.txt glyphwiki_gothic.txt + - run: npm run start 2 0 0 glyphwiki_dump/dump_newest_only.txt glyphwiki_dump/dump_all_versions_noescape.txt glyphwiki_gothic.txt - run: cat glyphwiki_gothic.txt.* > glyphwiki_gothic.txt - run: gzip glyphwiki_gothic.txt - name: Release diff --git a/index.ts b/index.ts index 98f8e4e..029b5a1 100644 --- a/index.ts +++ b/index.ts @@ -30,6 +30,7 @@ const workerProcess = () => { msg: { index, is_mincho, + offset, output, names, dump_file_name, @@ -39,6 +40,7 @@ const workerProcess = () => { msg: { index: number; is_mincho: number; + offset: number; output: string; dump_file_name: string; dump_all_file_name: string; @@ -88,8 +90,12 @@ const workerProcess = () => { // console.log(`W ${process.pid} ${i}/${names.length}`); const polygons = new Polygons(); kage.makeGlyph(polygons, name); - // @ts-ignore - res[name] = postProcessPolygon(polygons.generateSVG(), !!is_mincho); + res[name] = postProcessPolygon( + // @ts-ignore + polygons.generateSVG(), + !!is_mincho, + !!offset + ); } // write to disk @@ -110,6 +116,7 @@ const workerProcess = () => { const run = ( dump_file_name: string, is_mincho: number, + offset: number, dump_all_file_name: string, output: string, numCPUs: number @@ -175,6 +182,7 @@ const run = ( msg: { index: i, is_mincho, + offset, output, dump_file_name, dump_all_file_name, @@ -200,16 +208,24 @@ const run = ( if (cluster.isMaster) program .arguments( - " " + " " ) .description( - "glyphwiki-gensvg <1 for mincho, 0 for gothic> " + "glyphwiki-gensvg <1 for mincho, 0 for gothic> <1 to faux bold if mincho is enabled, 0 otherwise> " ) .action( - (numThreads, is_mincho, dump_file_name, dump_all_versions, output) => { + ( + numThreads, + is_mincho, + offset, + dump_file_name, + dump_all_versions, + output + ) => { run( dump_file_name, Number(is_mincho), + Number(offset), dump_all_versions, output, Number(numThreads) diff --git a/test-single-svg.ts b/test-single-svg.ts index 147dfdb..9e42f27 100644 --- a/test-single-svg.ts +++ b/test-single-svg.ts @@ -34,7 +34,7 @@ const run = ( const svg = polygons.generateSVG(false); console.log(svg); - console.log(postProcessPolygon(svg, false)); + console.log(postProcessPolygon(svg, false, false)); }; program diff --git a/utils.ts b/utils.ts index 2cb11fd..f7796c6 100644 --- a/utils.ts +++ b/utils.ts @@ -8,7 +8,11 @@ export function precisionRound(number: number, precision: number) { } export const SCALE_FACTOR = 5; -export const postProcessPolygon = (svg: string, is_mincho: boolean) => { +export const postProcessPolygon = ( + svg: string, + is_mincho: boolean, + offset: boolean +) => { const parsedSVG = parse(svg); const polygonsPoints = parsedSVG.children[0].children[0].children .filter(({ tagName }) => tagName === "polygon") @@ -76,14 +80,14 @@ export const postProcessPolygon = (svg: string, is_mincho: boolean) => { return res; }; - if (is_mincho) { + if (is_mincho && offset) { const co = new ClipperLib.ClipperOffset(2, 0.25); co.AddPaths( paths, ClipperLib.JoinType.jtRound, ClipperLib.EndType.etClosedPolygon ); - co.Execute(paths, 1.8); + co.Execute(paths, 1.3); } let res = [];