add more circled glyphs and paren glyphs

This commit is contained in:
be5invis 2017-06-27 21:52:15 +08:00
parent 7e2b717980
commit d5c87914f5
5 changed files with 239 additions and 150 deletions

2
.gitignore vendored
View file

@ -58,3 +58,5 @@ meta/*.js
meta/feature/*.js meta/feature/*.js
glyphs/*.js glyphs/*.js
testdrive/assets testdrive/assets
package-lock.json

View file

@ -249,86 +249,145 @@ export : define [apply] : begin
local dscale 0.55 local dscale 0.55
local pendingGlyphs : records.map : [record] => record.1 local pendingGlyphs : records.map : [record] => record.1
local miniatureFont : Miniature local miniatureFont : Miniature
glyphs -- pendingGlyphs glyphs -- [pendingGlyphs.reduce : [a b] => [a.concat b]]
crowd -- [fallback para.smallCrowd 3.75] crowd -- [fallback para.smallCrowd 3.75]
scale -- 0.65 scale -- 0.65
unfair -- true unfair -- true
foreach {unicode glyphid w} [items-of records] : create-glyph [suggestName : 'circle' + glyphid] : glyph-construction foreach {unicode parts w} [items-of records] : do
local gn : suggestName : 'circle-' + [parts.join '_']
local gni : suggestName : 'circle-inner-' + [parts.join '_']
local width : fallback w WIDTH local width : fallback w WIDTH
set-width width
local sw [adviceBlackness 5] local sw [adviceBlackness 5]
if unicode : assign-unicode unicode local top (CAP * dscale + [Math.max (CAP * 0.175) (sw * 3)])
include : create-glyph [suggestName : 'circleinner' + glyphid] : glyph-construction local bot (-[Math.max (CAP * 0.175) (sw * 3)])
local g miniatureFont.(glyphid) local left : Math.max (SB + O * 3) : Math.min (width / 2 - (top - bot) / 2) (width / 2 - CAP / 2 * dscale - sw * 2.5)
include g local right : Math.min (width - SB - O * 3) : Math.max (width / 2 + (top - bot) / 2) (width / 2 + CAP / 2 * dscale + sw * 2.5)
local shift 0
if (g.anchors.above && g.anchors.below) : set shift : CAP / 2 - [mix g.anchors.above.y g.anchors.below.y 0.5] local lg : create-glyph gni : glyph-construction
local tw 0
foreach [glyphid : items-of parts] : begin
local g miniatureFont.(glyphid)
include g
apply-transform : Translate (-g.advanceWidth) 0
set tw : tw + g.advanceWidth
apply-transform : Translate tw 0
apply-transform : Upright apply-transform : Upright
apply-transform : Translate (-WIDTH / 2) (-CAP / 2 + shift) apply-transform : Scale [Math.min 1 (width / tw)] 1
set tw : Math.min width tw
local shift 0
if (g.anchors.above && g.anchors.below) : set shift : CAP / 2 - [mix g.anchors.above.y g.anchors.below.y 0.5]
apply-transform : Translate (-tw / 2) (-CAP / 2 + shift)
apply-transform : Scale dscale apply-transform : Scale dscale
apply-transform : Translate (width / 2) (CAP / 2 * dscale) apply-transform : Translate (width / 2) (CAP / 2 * dscale)
apply-transform : Italify apply-transform : Italify
set currentGlyph.cmpPriority 12 set currentGlyph.cmpPriority 12
refair this refair this
include : OShape create-glyph gn : glyph-construction
* (CAP * dscale + [Math.max (CAP * 0.175) (sw * 3)]) set-width width
* (-[Math.max (CAP * 0.175) (sw * 3)]) if unicode : assign-unicode unicode
* [Math.max (SB + O * 3) (width / 2 - CAP / 2 * dscale - sw * 2.5)] include lg
* [Math.min (width - SB - O * 3) (width / 2 + CAP / 2 * dscale + sw * 2.5)] include : OShape top bot left right sw (SMALLSMOOTHA * width / WIDTH) (SMALLSMOOTHB * width / WIDTH)
* sw apply-transform : Upright
* (SMALLSMOOTHA * width / WIDTH) apply-transform : Translate 0 (parenMid - CAP * dscale / 2)
* (SMALLSMOOTHB * width / WIDTH) apply-transform : Italify
apply-transform : Upright
apply-transform : Translate 0 (parenMid - CAP * dscale / 2)
apply-transform : Italify
define [createBracedGlyphs records] : if [not recursive] : begin define [createBracedGlyphs records] : if [not recursive] : begin
local dscale 0.55 local dscale 0.55
local pscale 0.6 local pscale 0.6
local pendingGlyphs : records.map : [record] => record.1 local pendingGlyphs : records.map : [record] => record.1
local miniatureFont : Miniature local miniatureFont : Miniature
glyphs -- pendingGlyphs glyphs -- [pendingGlyphs.reduce : [a b] => [a.concat b]]
crowd -- [fallback para.smallCrowd 3.75] crowd -- [fallback para.smallCrowd 3.75]
scale -- 0.65 scale -- 0.65
sbscale -- 1 sbscale -- 1
unfair -- true unfair -- true
foreach {unicode glyphid w} [items-of records] : sketch foreach {unicode parts w} [items-of records] : do
local gn : suggestName : 'braced-' + [parts.join '_']
local gni : suggestName : 'braced-inner-' + [parts.join '_']
local width : fallback w WIDTH local width : fallback w WIDTH
set-width width
local sw [adviceBlackness 5] local sw [adviceBlackness 5]
local l : [Math.max (SB + O * 3) (width / 2 - CAP / 2 * dscale - sw * 2.5)] + OX local l : [Math.max (SB + O * 3) (width / 2 - CAP / 2 * dscale - sw * 2.5)] + OX
local r : width - l local r : width - l
include : create-glyph [suggestName : 'braceinner' + glyphid] : glyph-construction local lg : create-glyph gni : glyph-construction
include miniatureFont.(glyphid) local tw 0
foreach [glyphid : items-of parts] : begin
local g miniatureFont.(glyphid)
if tw : begin # Add a little kern
set tw : tw - SB
apply-transform : Translate SB 0
include g
apply-transform : Translate (-g.advanceWidth) 0
set tw : tw + g.advanceWidth
apply-transform : Translate tw 0
apply-transform : Upright apply-transform : Upright
apply-transform : Translate (-WIDTH / 2) 0 apply-transform : Scale [Math.min 1 (width / tw)] 1
set tw : Math.min width tw
apply-transform : Translate (-tw / 2) 0
apply-transform : Scale dscale apply-transform : Scale dscale
apply-transform : Translate (width / 2) 0 apply-transform : Translate (width / 2) 0
apply-transform : Italify apply-transform : Italify
set currentGlyph.cmpPriority 11 set currentGlyph.cmpPriority 11
refair this refair this
sketch
set-width width
include lg
include : dispiro
widths.lhs sw
g4 [mix l r 0.15] (parenTop * pscale)
g4.down.mid l (parenMid * pscale)
g4 [mix l r 0.15] (parenBot * pscale)
include : dispiro include : dispiro
widths.lhs sw widths.rhs sw
g4 [mix l r 0.15] (parenTop * pscale) g4 [mix r l 0.15] (parenTop * pscale)
g4.down.mid l (parenMid * pscale) g4.down.mid r (parenMid * pscale)
g4 [mix l r 0.15] (parenBot * pscale) g4 [mix r l 0.15] (parenBot * pscale)
include : dispiro include : Upright
widths.rhs sw include : Translate 0 (parenMid - parenMid * pscale)
g4 [mix r l 0.15] (parenTop * pscale) include : Italify
g4.down.mid r (parenMid * pscale)
g4 [mix r l 0.15] (parenBot * pscale)
include : Upright save gn unicode
include : Translate 0 (parenMid - parenMid * pscale)
include : Italify
save [suggestName : 'braced' + glyphid] unicode define [createDottedGlyphs shrink records] : if [not recursive] : begin
local dscale 0.55
local pscale 0.6
local pendingGlyphs : records.map : [record] => record.1
local miniatureFont : Thinner
[pendingGlyphs.reduce : [a b] => [a.concat b]].concat {'period'}
if (para.spacing > 1) 1 shrink
foreach {unicode parts w} [items-of records] : do
local gn : suggestName : 'dotted-' + [parts.join '_']
local width : fallback w WIDTH
local sw [adviceBlackness 5]
local l : [Math.max (SB + O * 3) (width / 2 - CAP / 2 * dscale - sw * 2.5)] + OX
local r : width - l
sketch
set-width width
local tw 0
foreach [glyphid : items-of : parts.concat {'period'}] : begin
local g miniatureFont.(glyphid)
if tw : begin # Add a little kern
set tw : tw - SB
apply-transform : Translate SB 0
include g
apply-transform : Translate (-g.advanceWidth) 0
set tw : tw + g.advanceWidth
apply-transform : Translate tw 0
set tw : tw - SB
apply-transform : Upright
if (tw > width)
: then : apply-transform : Scale [Math.min 1 (width / tw)] 1
: else : apply-transform : Translate (width / 2 - tw / 2) 0
apply-transform : Italify
set currentGlyph.cmpPriority 11
save gn unicode
define [createSuperscripts records] : if [not recursive] : begin define [createSuperscripts records] : if [not recursive] : begin
local pendingGlyphs : records.map : [record] => record.1 local pendingGlyphs : records.map : [record] => record.1
@ -434,25 +493,6 @@ export : define [apply] : begin
apply-transform : Italify apply-transform : Italify
include : HBar SB RIGHTSB parenMid (fine * 0.75) include : HBar SB RIGHTSB parenMid (fine * 0.75)
if [not recursive] : let : begin
local compositions : list
list 0xA9 'C' FULLWIDTH2
list 0xAE 'R' FULLWIDTH2
list 0x2117 'P' FULLWIDTH2
list 0x24EA 'zero' FULLWIDTH1
list null 'space' FULLWIDTH1
foreach [j : range 1 till 9] : compositions.push {(0x2460 + j - 1) unicodeGlyphs.(['0'.charCodeAt 0] + j).name FULLWIDTH1}
foreach [j : range 0 26] : compositions.push {(0x24B6 + j) unicodeGlyphs.(['A'.charCodeAt 0] + j).name FULLWIDTH1}
foreach [j : range 0 26] : compositions.push {(0x24D0 + j) unicodeGlyphs.(['a'.charCodeAt 0] + j).name FULLWIDTH1}
createCircledGlyphs compositions
local compositions : list
list null 'space' FULLWIDTH1
foreach [j : range 1 till 9] : compositions.push {(0x2474 + j - 1) unicodeGlyphs.(['0'.charCodeAt 0] + j).name FULLWIDTH1}
foreach [j : range 0 26] : compositions.push {(0x249C + j) unicodeGlyphs.(['a'.charCodeAt 0] + j).name FULLWIDTH1}
createBracedGlyphs compositions
createSMCPs : list createSMCPs : list
list 0x1D00 'A' list 0x1D00 'A'
list 0x1D01 'AE' list 0x1D01 'AE'
@ -747,73 +787,106 @@ export : define [apply] : begin
list 0x1DF4 'udieresis' list 0x1DF4 'udieresis'
# Unicode Ligatures # Unicode Ligatures
let : begin define [createLigatures shrink1 shrink2 wadj1 wadj2 records] : if [not recursive] : begin
define stdShrink : clamp 0.75 0.9 : linreg 72 0.75 108 0.9 STROKE local pendingGlyphs1 : records.map : [record] => record.1
define [createLigatures shrink1 shrink2 wadj1 wadj2 records] : if [not recursive] : begin local pendingGlyphs2 : records.map : [record] => record.2
local pendingGlyphs1 : records.map : [record] => record.1 local df1 : Thinner pendingGlyphs1 [if (para.spacing > 1) 1 shrink1]
local pendingGlyphs2 : records.map : [record] => record.2 local df2 : Thinner pendingGlyphs2 [if (para.spacing > 1) 1 shrink2]
local df1 : Thinner pendingGlyphs1 [if (para.spacing > 1) 1 shrink1]
local df2 : Thinner pendingGlyphs2 [if (para.spacing > 1) 1 shrink2]
foreach [{unicode c1 c2 mark} : items-of records] : begin foreach [{unicode c1 c2 mark} : items-of records] : begin
local glyphName "\(c1)_\(c2)" local glyphName "\(c1)_\(c2)"
if glyphs.(glyphName) : begin if glyphs.(glyphName) : begin
local j 2 local j 2
while glyphs.(glyphName + j) : inc j while glyphs.(glyphName + j) : inc j
set glyphName (glyphName + j) set glyphName (glyphName + j)
if (para.spacing > 1) : begin if (para.spacing > 1) : begin
sketch sketch
include df2.(c2) include df2.(c2)
include : Translate WIDTH 0 include : Translate WIDTH 0
include df1.(c1) include df1.(c1)
set-width FULLWIDTH set-width FULLWIDTH
save glyphName unicode save glyphName unicode
: else : else
local kern : SB * 7/8 * (shrink1 + shrink2) local kern : SB * 7/8 * (shrink1 + shrink2)
local refw : WIDTH * (shrink1 * wadj1 + shrink2 * wadj2) - kern local refw : WIDTH * (shrink1 * wadj1 + shrink2 * wadj2) - kern
sketch sketch
include df2.(c2) include df2.(c2)
include : Translate (WIDTH * shrink1 * wadj1 - kern) 0 include : Translate (WIDTH * shrink1 * wadj1 - kern) 0
include df1.(c1) include df1.(c1)
include : Translate (-WIDTH * shrink1 * (1 - wadj1) / 2) 0 include : Translate (-WIDTH * shrink1 * (1 - wadj1) / 2) 0
include : Upright include : Upright
include : Translate (-refw / 2) 0 include : Translate (-refw / 2) 0
include : Scale ((WIDTH - SB * 1.25) / (WIDTH - SB * 2) * WIDTH / refw) 1 include : Scale ((WIDTH - SB * 1.25) / (WIDTH - SB * 2) * WIDTH / refw) 1
include : Translate (WIDTH / 2) 0 include : Translate (WIDTH / 2) 0
include : Italify include : Italify
if mark : include mark if mark : include mark
save glyphName unicode save glyphName unicode
createLigatures stdShrink stdShrink 1 1 : list define stdShrink : clamp 0.75 0.9 : linreg 72 0.75 108 0.9 STROKE
list 0x1C4 'D' 'Zcaron' createLigatures stdShrink stdShrink 1 1 : list
list 0x1C5 'D' 'zcaron' list 0x1C4 'D' 'Zcaron'
list 0x1C6 'd' 'zcaron' list 0x1C5 'D' 'zcaron'
list 0x1C7 'L' 'J' list 0x1C6 'd' 'zcaron'
list 0x1C8 'L' 'j' list 0x1C7 'L' 'J'
list 0x1C9 'l' 'j' list 0x1C8 'L' 'j'
list 0x1CA 'N' 'J' list 0x1C9 'l' 'j'
list 0x1CB 'N' 'j' list 0x1CA 'N' 'J'
list 0x1CC 'n' 'j' list 0x1CB 'N' 'j'
list 0x2A3 'd' 'z' list 0x1CC 'n' 'j'
list 0x1F1 'D' 'Z' list 0x2A3 'd' 'z'
list 0x1F2 'D' 'z' list 0x1F1 'D' 'Z'
list 0x1F3 'd' 'z' list 0x1F2 'D' 'z'
list 0x2A4 'd' 'ezh' list 0x1F3 'd' 'z'
list 0x2A5 'd' 'zcurlytail' list 0x2A4 'd' 'ezh'
list 0x2A6 't' 's' list 0x2A5 'd' 'zcurlytail'
list 0x2A7 't' 'esh' list 0x2A6 't' 's'
list 0x2A8 't' 'ccurlytail' list 0x2A7 't' 'esh'
list 0x2A9 'f' 'eng' list 0x2A8 't' 'ccurlytail'
list 0x2AA 'l' 's' list 0x2A9 'f' 'eng'
list 0x2AB 'l' 'z' list 0x2AA 'l' 's'
list 0x478 'O' 'y' markset.if list 0x2AB 'l' 'z'
list 0x479 'o' 'y' markset.p list 0x478 'O' 'y' markset.if
list 0x20A7 'P' 's' list 0x479 'o' 'y' markset.p
list 0x20A8 'R' 's' list 0x20A7 'P' 's'
createLigatures 0.7 0.8 0.75 0.9 : list list 0x20A8 'R' 's'
list 0x2103 'degree' 'C' createLigatures 0.7 0.8 0.75 0.9 : list
list 0x2109 'degree' 'F' list 0x2103 'degree' 'C'
list 0x2109 'degree' 'F'
# Circled & Braced
if [not recursive] : let : begin
local compositions : list
list 0xA9 {'C'} FULLWIDTH2
list 0xAE {'R'} FULLWIDTH2
list 0x2117 {'P'} FULLWIDTH2
list 0x24EA {'zero'} FULLWIDTH1
list null {'space'} FULLWIDTH1
foreach [j : range 1 till 20] : compositions.push : list
0x2460 + j - 1
[(j+'').split ''].map : c => unicodeGlyphs.(['0'.charCodeAt 0] + (c - 0)).name
begin FULLWIDTH1
foreach [j : range 0 26] : compositions.push {(0x24B6 + j) {unicodeGlyphs.(['A'.charCodeAt 0] + j).name} FULLWIDTH1}
foreach [j : range 0 26] : compositions.push {(0x24D0 + j) {unicodeGlyphs.(['a'.charCodeAt 0] + j).name} FULLWIDTH1}
createCircledGlyphs compositions
if [not recursive] : let : begin
local compositions : list
list null {'space'} FULLWIDTH1
foreach [j : range 1 till 20] : compositions.push : list
0x2474 + j - 1
[(j+'').split ''].map : c => unicodeGlyphs.(['0'.charCodeAt 0] + (c - 0)).name
begin FULLWIDTH1
foreach [j : range 0 26] : compositions.push {(0x249C + j) {unicodeGlyphs.(['a'.charCodeAt 0] + j).name} FULLWIDTH1}
createBracedGlyphs compositions
if [not recursive] : let : begin
local compositions {}
foreach [j : range 1 till [if (para.spacing > 0) 20 9]] : compositions.push : list
0x2488 + j - 1
[(j+'').split ''].map : c => unicodeGlyphs.(['0'.charCodeAt 0] + (c - 0)).name
begin FULLWIDTH1
createDottedGlyphs 0.9 compositions
# Composite superscripts and subscripts # Composite superscripts and subscripts
let : begin let : begin

View file

@ -27,6 +27,9 @@ test : $(BUILD)/targets.mk
fw : $(BUILD)/targets.mk fw : $(BUILD)/targets.mk
@$(MAKE) -f utility/standard.mk fw @$(MAKE) -f utility/standard.mk fw
scripts :
@$(MAKE) -f utility/scripts.mk scripts
sample-images : sample-images :
@$(MAKE) -f utility/standard.mk sample-images @$(MAKE) -f utility/standard.mk sample-images

View file

@ -3,17 +3,17 @@
"version": "1.9.2", "version": "1.9.2",
"main": "./generate.js", "main": "./generate.js",
"dependencies": { "dependencies": {
"bezier-js": "^2.0.0", "bezier-js": "^2.2.3",
"caryll-shapeops": "^0.2.0", "caryll-shapeops": "^0.2.1",
"cubic2quad": "^1.0.0", "cubic2quad": "^1.1.1",
"libspiro-js": ">=0.3.0", "libspiro-js": "^0.3.1",
"object-assign": "^4.1.1", "object-assign": "^4.1.1",
"otfcc-c2q": "^0.5.0", "otfcc-c2q": "^0.5.0",
"pad": "^1.1.0", "pad": "^1.1.0",
"patel": ">=0.32.0", "patel": "^0.32.1",
"toml": ">=2.3.0", "toml": "^2.3.2",
"topsort": "0.0.2", "topsort": "0.0.2",
"unorm": ">=1.4.1", "unorm": "^1.4.1",
"yargs": "*" "yargs": "^8.0.2"
} }
} }

View file

@ -10,8 +10,8 @@ function contourHash(c) {
var buf = ""; var buf = "";
for (var j = 1; j < c.length; j++) { for (var j = 1; j < c.length; j++) {
var z = c[j]; var z = c[j];
buf += `${z.on ? 'o' : 'f'}${z.cubic ? 'c' : 'q'}${delta(z.x, lx)},${delta(z.y, ly)};`; buf += `${z.on ? "o" : "f"}${z.cubic ? "c" : "q"}${delta(z.x, lx)},${delta(z.y, ly)};`;
lx = z.x, ly = z.y; (lx = z.x), (ly = z.y);
} }
return buf; return buf;
} }
@ -20,9 +20,14 @@ function match(g1, g2, _n) {
for (let j = 0; j + g1.contours.length <= g2.contours.length; j++) { for (let j = 0; j + g1.contours.length <= g2.contours.length; j++) {
var found = true; var found = true;
for (var k = j; k < g2.contours.length && k - j < g1.contours.length; k++) { for (var k = j; k < g2.contours.length && k - j < g1.contours.length; k++) {
if (g1.contours[k - j].hash !== g2.contours[k].hash if (
|| !(k <= j || delta(g1.contours[k - j][0].x, g1.contours[k - j - 1][0].x) === delta(g2.contours[k][0].x, g2.contours[k - 1][0].x) g1.contours[k - j].hash !== g2.contours[k].hash ||
&& delta(g1.contours[k - j][0].y, g1.contours[k - j - 1][0].y) === delta(g2.contours[k][0].y, g2.contours[k - 1][0].y))) { !(k <= j ||
(delta(g1.contours[k - j][0].x, g1.contours[k - j - 1][0].x) ===
delta(g2.contours[k][0].x, g2.contours[k - 1][0].x) &&
delta(g1.contours[k - j][0].y, g1.contours[k - j - 1][0].y) ===
delta(g2.contours[k][0].y, g2.contours[k - 1][0].y)))
) {
found = false; found = false;
break; break;
} }
@ -64,10 +69,9 @@ function autoref(glyf) {
} }
} }
// Refl-referencify, forward. // Refl-referencify, forward.
for (var j = 0; j < glyf.length; j++) { for (var j = 0; j < glyf.length; j++) {
if (!glyf[j].contours.length || glyf[j].references && glyf[j].references.length) continue; if (!glyf[j].contours.length || (glyf[j].references && glyf[j].references.length)) continue;
for (var k = j + 1; k < glyf.length; k++) { for (var k = j + 1; k < glyf.length; k++) {
if (glyf[j].contours.length === glyf[k].contours.length) { if (glyf[j].contours.length === glyf[k].contours.length) {
if (match(glyf[j], glyf[k], j)) { if (match(glyf[j], glyf[k], j)) {
@ -79,7 +83,12 @@ function autoref(glyf) {
// referencify, backward // referencify, backward
for (var j = 0; j < glyf.length; j++) { for (var j = 0; j < glyf.length; j++) {
if (glyf[j].cmpPriority < 0 || !glyf[j].contours.length || glyf[j].references && glyf[j].references.length) continue; if (
glyf[j].cmpPriority < 0 ||
!glyf[j].contours.length ||
(glyf[j].references && glyf[j].references.length)
)
continue;
for (var k = j - 1; k >= 0; k--) { for (var k = j - 1; k >= 0; k--) {
if (glyf[j].contours.length > glyf[k].contours.length) continue; if (glyf[j].contours.length > glyf[k].contours.length) continue;
while (match(glyf[j], glyf[k], j)) { while (match(glyf[j], glyf[k], j)) {
@ -90,8 +99,10 @@ function autoref(glyf) {
// unlink composite // unlink composite
for (var j = 0; j < glyf.length; j++) { for (var j = 0; j < glyf.length; j++) {
if (glyf[j].contours.length === 0 || !glyf[j].references || glyf[j].references.length === 0) continue; if (!glyf[j].references || glyf[j].references.length === 0) continue;
// console.log("Unlink", glyf[j].name); if (glyf[j].contours.length === 0 && !(glyf[j].unicode && glyf[j].unicode[0] < 0x80))
continue;
var cs = unlinkRef(glyf[j], 0, 0, glyf); var cs = unlinkRef(glyf[j], 0, 0, glyf);
glyf[j].contours = g.contours.concat(cs); glyf[j].contours = g.contours.concat(cs);
glyf[j].references = []; glyf[j].references = [];
@ -105,8 +116,8 @@ function supporessNaN(glyf) {
for (var k = 0; k < g.contours.length; k++) { for (var k = 0; k < g.contours.length; k++) {
var contour = g.contours[k]; var contour = g.contours[k];
for (let z of contour) { for (let z of contour) {
if (!isFinite(z.x)) z.x = 0 if (!isFinite(z.x)) z.x = 0;
if (!isFinite(z.y)) z.y = 0 if (!isFinite(z.y)) z.y = 0;
} }
} }
} }