Skip to content

Commit

Permalink
Turn path offsetting (faux bolding) into a parameter, disable it by d…
Browse files Browse the repository at this point in the history
  • Loading branch information
Transfusion committed Mar 25, 2021
1 parent 150d330 commit b87a3b9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/generate-svgs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 21 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const workerProcess = () => {
msg: {
index,
is_mincho,
offset,
output,
names,
dump_file_name,
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -175,6 +182,7 @@ const run = (
msg: {
index: i,
is_mincho,
offset,
output,
dump_file_name,
dump_all_file_name,
Expand All @@ -200,16 +208,24 @@ const run = (
if (cluster.isMaster)
program
.arguments(
"<numThreads> <gothic> <dump_newest_only.txt> <dump_all_versions.txt> <output.json>"
"<numThreads> <mincho/gothic> <offset> <dump_newest_only.txt> <dump_all_versions.txt> <output.json>"
)
.description(
"glyphwiki-gensvg <numThreads> <1 for mincho, 0 for gothic> <path to dump_newest_only.txt> <path to dump_all_versions.txt> <output.json>"
"glyphwiki-gensvg <numThreads> <1 for mincho, 0 for gothic> <1 to faux bold if mincho is enabled, 0 otherwise> <path to dump_newest_only.txt> <path to dump_all_versions.txt> <output.json>"
)
.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)
Expand Down
2 changes: 1 addition & 1 deletion test-single-svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 = [];
Expand Down

0 comments on commit b87a3b9

Please sign in to comment.