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
glyphs/*.js
testdrive/assets
package-lock.json

View file

@ -249,37 +249,46 @@ export : define [apply] : begin
local dscale 0.55
local pendingGlyphs : records.map : [record] => record.1
local miniatureFont : Miniature
glyphs -- pendingGlyphs
glyphs -- [pendingGlyphs.reduce : [a b] => [a.concat b]]
crowd -- [fallback para.smallCrowd 3.75]
scale -- 0.65
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
set-width width
local sw [adviceBlackness 5]
if unicode : assign-unicode unicode
include : create-glyph [suggestName : 'circleinner' + glyphid] : glyph-construction
local top (CAP * dscale + [Math.max (CAP * 0.175) (sw * 3)])
local bot (-[Math.max (CAP * 0.175) (sw * 3)])
local left : Math.max (SB + O * 3) : Math.min (width / 2 - (top - bot) / 2) (width / 2 - CAP / 2 * dscale - sw * 2.5)
local right : Math.min (width - SB - O * 3) : Math.max (width / 2 + (top - bot) / 2) (width / 2 + CAP / 2 * dscale + sw * 2.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 : 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 : Upright
apply-transform : Translate (-WIDTH / 2) (-CAP / 2 + shift)
apply-transform : Translate (-tw / 2) (-CAP / 2 + shift)
apply-transform : Scale dscale
apply-transform : Translate (width / 2) (CAP / 2 * dscale)
apply-transform : Italify
set currentGlyph.cmpPriority 12
refair this
include : OShape
* (CAP * dscale + [Math.max (CAP * 0.175) (sw * 3)])
* (-[Math.max (CAP * 0.175) (sw * 3)])
* [Math.max (SB + O * 3) (width / 2 - CAP / 2 * dscale - sw * 2.5)]
* [Math.min (width - SB - O * 3) (width / 2 + CAP / 2 * dscale + sw * 2.5)]
* sw
* (SMALLSMOOTHA * width / WIDTH)
* (SMALLSMOOTHB * width / WIDTH)
create-glyph gn : glyph-construction
set-width width
if unicode : assign-unicode unicode
include lg
include : OShape top bot left right sw (SMALLSMOOTHA * width / WIDTH) (SMALLSMOOTHB * width / WIDTH)
apply-transform : Upright
apply-transform : Translate 0 (parenMid - CAP * dscale / 2)
apply-transform : Italify
@ -289,29 +298,43 @@ export : define [apply] : begin
local pscale 0.6
local pendingGlyphs : records.map : [record] => record.1
local miniatureFont : Miniature
glyphs -- pendingGlyphs
glyphs -- [pendingGlyphs.reduce : [a b] => [a.concat b]]
crowd -- [fallback para.smallCrowd 3.75]
scale -- 0.65
sbscale -- 1
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
set-width 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
include : create-glyph [suggestName : 'braceinner' + glyphid] : glyph-construction
include miniatureFont.(glyphid)
local lg : create-glyph gni : glyph-construction
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 : 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 : Translate (width / 2) 0
apply-transform : Italify
set currentGlyph.cmpPriority 11
refair this
sketch
set-width width
include lg
include : dispiro
widths.lhs sw
g4 [mix l r 0.15] (parenTop * pscale)
@ -328,7 +351,43 @@ export : define [apply] : begin
include : Translate 0 (parenMid - parenMid * pscale)
include : Italify
save [suggestName : 'braced' + glyphid] unicode
save gn 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
local pendingGlyphs : records.map : [record] => record.1
@ -434,25 +493,6 @@ export : define [apply] : begin
apply-transform : Italify
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
list 0x1D00 'A'
list 0x1D01 'AE'
@ -747,8 +787,6 @@ export : define [apply] : begin
list 0x1DF4 'udieresis'
# Unicode Ligatures
let : begin
define stdShrink : clamp 0.75 0.9 : linreg 72 0.75 108 0.9 STROKE
define [createLigatures shrink1 shrink2 wadj1 wadj2 records] : if [not recursive] : begin
local pendingGlyphs1 : records.map : [record] => record.1
local pendingGlyphs2 : records.map : [record] => record.2
@ -785,6 +823,7 @@ export : define [apply] : begin
if mark : include mark
save glyphName unicode
define stdShrink : clamp 0.75 0.9 : linreg 72 0.75 108 0.9 STROKE
createLigatures stdShrink stdShrink 1 1 : list
list 0x1C4 'D' 'Zcaron'
list 0x1C5 'D' 'zcaron'
@ -815,6 +854,40 @@ export : define [apply] : begin
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
let : begin
define [doubleSuperscript a b] : glyph-construction

View file

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

View file

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

View file

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