Add hwid/fwid for circled/boxed/braced characters

This commit is contained in:
Belleve Invis 2019-10-03 18:53:52 -07:00
parent 7e114dbfb8
commit a84743e77a

View file

@ -247,6 +247,9 @@ export : define [apply] : begin
# Build miniature clyphs : circled, superscripts, subscripts... # Build miniature clyphs : circled, superscripts, subscripts...
# Circled # Circled
define circleWidthClasses {{'hwid' WIDTH} {'fwid' FULLWIDTH0}}
define [circleInner dscale miniatureFont unicode parts width bal baly] : begin define [circleInner dscale miniatureFont unicode parts width bal baly] : begin
define gni : '.ci.' + [parts.join '_'] + '.' + [{dscale width bal baly}.join '.'] define gni : '.ci.' + [parts.join '_'] + '.' + [{dscale width bal baly}.join '.']
if (glyphs.(gni)) : return glyphs.(gni) if (glyphs.(gni)) : return glyphs.(gni)
@ -274,11 +277,14 @@ export : define [apply] : begin
set-width 0 set-width 0
return lg return lg
define CircCrowd 5
define CircScale 0.65
define [circleDimens dscale w m] : begin define [circleDimens dscale w m] : begin
define width : fallback w WIDTH define width : fallback w WIDTH
define dscale : linreg WIDTH 0.55 UPM 0.6 width define dscale : linreg WIDTH 0.55 UPM 0.6 width
define spatt : linreg WIDTH 0.175 UPM 0.27 width define spatt : linreg WIDTH 0.175 UPM 0.27 width
define sw0 : adviceBlackness 5 define sw0 : dscale * [adviceBlackness CircCrowd] / CircScale
define sw : Math.max sw0 [fallback m 0] define sw : Math.max sw0 [fallback m 0]
define top : CAP * dscale + [Math.max (CAP * spatt) (sw * 3)] define top : CAP * dscale + [Math.max (CAP * spatt) (sw * 3)]
define bot : 0 - [Math.max (CAP * spatt) (sw * 3)] define bot : 0 - [Math.max (CAP * spatt) (sw * 3)]
@ -298,105 +304,117 @@ export : define [apply] : begin
local pendingGlyphs : records.map : [record] => record.1 local pendingGlyphs : records.map : [record] => record.1
return : Miniature return : Miniature
glyphs -- [pendingGlyphs.reduce : [a b] => [a.concat b]] glyphs -- [pendingGlyphs.reduce : [a b] => [a.concat b]]
crowd -- 5 crowd -- CircCrowd
scale -- 0.65 scale -- CircScale
unfair -- true unfair -- true
define [CircName prefix parts suffix] : suggestName : prefix + '-' + [parts.join '_'] + '.' + suffix
define [createCircledGlyphs records] : if [not recursive] : begin define [createCircledGlyphs records] : if [not recursive] : begin
local miniatureFont : circledMiniatureFont records local miniatureFont : circledMiniatureFont records
foreach {unicode parts w bal baly} [items-of records] : do foreach {unicode parts w bal baly} [items-of records] : do
define [object width dscale sw top bot left right] : circleDimens dscale w foreach {suffix ww} [items-of circleWidthClasses] : do
create-glyph [suggestName : 'circle-' + [parts.join '_']] : glyph-construction define [object width dscale sw top bot left right] : circleDimens dscale ww
set-width width create-glyph [CircName 'circle' parts suffix] : glyph-construction
if unicode : assign-unicode unicode set-width width
include : circleInner dscale miniatureFont unicode parts width bal baly if (w == ww && unicode) : assign-unicode unicode
include : OShape top bot left right sw (SMALLSMOOTHA * width / WIDTH) (SMALLSMOOTHB * width / WIDTH) include : circleInner dscale miniatureFont unicode parts width bal baly
include : OShape top bot left right sw (SMALLSMOOTHA * width / WIDTH) (SMALLSMOOTHB * width / WIDTH)
apply-transform : Upright apply-transform : Upright
apply-transform : Translate 0 (symbolMid - CAP * dscale / 2) apply-transform : Translate 0 (symbolMid - CAP * dscale / 2)
apply-transform : Italify apply-transform : Italify
define [createBoxedGlyphs records] : if [not recursive] : begin define [createBoxedGlyphs records] : if [not recursive] : begin
local miniatureFont : circledMiniatureFont records local miniatureFont : circledMiniatureFont records
foreach {unicode parts w bal baly} [items-of records] : do foreach {unicode parts w bal baly} [items-of records] : do
define [object width dscale sw top bot left right] : circleDimens dscale w foreach {suffix ww} [items-of circleWidthClasses] : do
create-glyph [suggestName : 'boxed-' + [parts.join '_']] : glyph-construction define [object width dscale sw top bot left right] : circleDimens dscale ww
set-width width create-glyph [CircName 'boxed' parts suffix] : glyph-construction
if unicode : assign-unicode unicode set-width width
include : circleInner dscale miniatureFont unicode parts width bal baly if (w == ww && unicode) : assign-unicode unicode
include : union include : circleInner dscale miniatureFont unicode parts width bal baly
HBarTop left right top sw include : union
HBarBottom left right bot sw HBarTop left right top sw
VBarLeft left bot top sw HBarBottom left right bot sw
VBarRight right bot top sw VBarLeft left bot top sw
VBarRight right bot top sw
apply-transform : Upright apply-transform : Upright
apply-transform : Translate 0 (symbolMid - CAP * dscale / 2) apply-transform : Translate 0 (symbolMid - CAP * dscale / 2)
apply-transform : Italify apply-transform : Italify
define [createInsetCircledGlyphs records] : if [not recursive] : begin define [createInsetCircledGlyphs records] : if [not recursive] : begin
local miniatureFont : circledMiniatureFont records local miniatureFont : circledMiniatureFont records
foreach {unicode parts w bal baly} [items-of records] : do foreach {unicode parts w bal baly} [items-of records] : do
define [object width dscale sw top bot left right] : circleDimens dscale w foreach {suffix ww} [items-of circleWidthClasses] : do
create-glyph [suggestName : 'inset-circle-' + [parts.join '_']] : glyph-construction define [object width dscale sw top bot left right] : circleDimens dscale ww
set-width width create-glyph [CircName 'inset-circle' parts suffix] : glyph-construction
if unicode : assign-unicode unicode set-width width
include : difference if (w == ww && unicode) : assign-unicode unicode
OShapeOutline top bot left right sw (SMALLSMOOTHA * width / WIDTH) (SMALLSMOOTHB * width / WIDTH) include : difference
circleInner dscale miniatureFont unicode parts width bal baly OShapeOutline top bot left right sw (SMALLSMOOTHA * width / WIDTH) (SMALLSMOOTHB * width / WIDTH)
circleInner dscale miniatureFont unicode parts width bal baly
apply-transform : Upright apply-transform : Upright
apply-transform : Translate 0 (symbolMid - CAP * dscale / 2) apply-transform : Translate 0 (symbolMid - CAP * dscale / 2)
apply-transform : Italify apply-transform : Italify
define [createInsetBoxedGlyphs records] : if [not recursive] : begin define [createInsetBoxedGlyphs records] : if [not recursive] : begin
local miniatureFont : circledMiniatureFont records local miniatureFont : circledMiniatureFont records
foreach {unicode parts w bal baly} [items-of records] : do foreach {unicode parts w bal baly} [items-of records] : do
define [object width dscale sw top bot left right] : circleDimens dscale w foreach {suffix ww} [items-of circleWidthClasses] : do
create-glyph [suggestName : 'inset-boxed-' + [parts.join '_']] : glyph-construction define [object width dscale sw top bot left right] : circleDimens dscale ww
set-width width create-glyph [CircName 'inset-boxed' parts suffix] : glyph-construction
if unicode : assign-unicode unicode set-width width
include : difference if (w == ww && unicode) : assign-unicode unicode
spiro-outline include : difference
corner left top spiro-outline
corner left bot corner left top
corner right bot corner left bot
corner right top corner right bot
close corner right top
circleInner dscale miniatureFont unicode parts width bal baly close
circleInner dscale miniatureFont unicode parts width bal baly
apply-transform : Upright apply-transform : Upright
apply-transform : Translate 0 (symbolMid - CAP * dscale / 2) apply-transform : Translate 0 (symbolMid - CAP * dscale / 2)
apply-transform : Italify apply-transform : Italify
define [createDoubleCircledGlyphs records] : if [not recursive] : begin define [createDoubleCircledGlyphs records] : if [not recursive] : begin
local miniatureFont : circledMiniatureFont records local miniatureFont : circledMiniatureFont records
foreach {unicode parts w bal baly} [items-of records] : do foreach {unicode parts w bal baly} [items-of records] : do
define [object width dscale sw0 sw top bot left right] : circleDimens dscale w (w * 0.08) foreach {suffix ww} [items-of circleWidthClasses] : do
define sw1 : Math.min sw0 (sw / 3) define [object width dscale sw0 sw top bot left right] : circleDimens dscale ww (ww * 0.08)
create-glyph [suggestName : 'double-circle-' + [parts.join '_']] : glyph-construction define sw1 : Math.min sw0 (sw / 3)
set-width width create-glyph [CircName 'double-circle' parts suffix] : glyph-construction
if unicode : assign-unicode unicode set-width width
include : circleInner dscale miniatureFont unicode parts width bal baly if (w == ww && unicode) : assign-unicode unicode
include : OShape top bot left right sw1 (SMALLSMOOTHA * width / WIDTH) (SMALLSMOOTHB * width / WIDTH) include : circleInner dscale miniatureFont unicode parts width bal baly
include : OShape include : OShape top bot left right sw1 (SMALLSMOOTHA * width / WIDTH) (SMALLSMOOTHB * width / WIDTH)
top - sw + sw1 include : OShape
bot + sw - sw1 top - sw + sw1
left + sw * HVCONTRAST - sw1 * HVCONTRAST bot + sw - sw1
right - sw * HVCONTRAST + sw1 * HVCONTRAST left + sw * HVCONTRAST - sw1 * HVCONTRAST
begin sw1 right - sw * HVCONTRAST + sw1 * HVCONTRAST
SMALLSMOOTHA * width / WIDTH begin sw1
SMALLSMOOTHB * width / WIDTH SMALLSMOOTHA * width / WIDTH
SMALLSMOOTHB * width / WIDTH
apply-transform : Upright apply-transform : Upright
apply-transform : Translate 0 (symbolMid - CAP * dscale / 2) apply-transform : Translate 0 (symbolMid - CAP * dscale / 2)
apply-transform : Italify apply-transform : Italify
define BraceCrowd [fallback para.smallCrowd 3.75]
define BraceScale 0.65
define [bracedDottdeDimens width] : begin define [bracedDottdeDimens width] : begin
define sw0 : Math.max (WIDTH * 0.075) [adviceBlackness 5]
define sw : Math.min STROKE sw0
define dscale : linreg WIDTH 0.55 UPM 0.65 width define dscale : linreg WIDTH 0.55 UPM 0.65 width
define pscale : linreg WIDTH 0.6 UPM 0.75 width define pscale : linreg WIDTH 0.6 UPM 0.75 width
define sw0 : Math.max
WIDTH * 0.075
dscale * [adviceBlackness BraceCrowd] / BraceScale
define sw : Math.min STROKE sw0
define l : [Math.max (SB + O * 3) (width / 2 - CAP / 2 * dscale - sw0 * 2.5)] + OX define l : [Math.max (SB + O * 3) (width / 2 - CAP / 2 * dscale - sw0 * 2.5)] + OX
define r : width - l define r : width - l
return : object width sw dscale pscale l r return : object width sw dscale pscale l r
@ -405,68 +423,70 @@ export : define [apply] : begin
local pendingGlyphs : records.map : [record] => record.1 local pendingGlyphs : records.map : [record] => record.1
local miniatureFont : Miniature local miniatureFont : Miniature
glyphs -- [pendingGlyphs.reduce : [a b] => [a.concat b]] glyphs -- [pendingGlyphs.reduce : [a b] => [a.concat b]]
crowd -- [fallback para.smallCrowd 3.75] crowd -- BraceCrowd
scale -- 0.65 scale -- BraceScale
sbscale -- 1 sbscale -- 1
unfair -- true unfair -- true
foreach {unicode parts w bal baly} [items-of records] : do foreach {unicode parts w bal baly} [items-of records] : do
define [object width dscale pscale sw l r] : bracedDottdeDimens w foreach {suffix ww} [items-of circleWidthClasses] : do
local gn : suggestName : 'braced-' + [parts.join '_'] define [object width dscale pscale sw l r] : bracedDottdeDimens ww
local gni : suggestName : 'braced-inner-' + [parts.join '_'] + '.' + dscale local gn : CircName 'braced' parts suffix
local gni : CircName 'braced-inner' parts suffix
local lg : create-glyph gni : glyph-construction
local tw 0
local lastg null
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
set lastg g
apply-transform : Translate tw 0
apply-transform : Upright
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
local shift 0
if (lastg.anchors.above && lastg.anchors.below) : begin
local gMiddleY [mix lastg.anchors.above.y lastg.anchors.below.y 0.5]
if bal : set shift : CAP / 2 - [mix baly gMiddleY bal]
: else : set shift : CAP / 2 - gMiddleY
apply-transform : Translate (width / 2) (symbolMid * pscale - (CAP / 2 - shift) * dscale)
apply-transform : Italify
set currentGlyph.cmpPriority 11
refair this
set-width 0
sketch
local s : TANSLANT * symbolMid
set-width width
include lg
include : dispiro
widths.lhs sw
g4 ([mix l r 0.15] - s) (parenTop * pscale)
g4.down.mid (l - s + O) (symbolMid * pscale)
g4 ([mix l r 0.15] - s) (parenBot * pscale)
include : dispiro local lg : create-glyph gni : glyph-construction
widths.rhs sw local tw 0
g4 ([mix r l 0.15] + s) (parenTop * pscale) local lastg null
g4.down.mid (r + s - O) (symbolMid * pscale) foreach [glyphid : items-of parts] : begin
g4 ([mix r l 0.15] + s) (parenBot * pscale) 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
set lastg g
apply-transform : Translate tw 0
apply-transform : Upright
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
local shift 0
if (lastg.anchors.above && lastg.anchors.below) : begin
local gMiddleY [mix lastg.anchors.above.y lastg.anchors.below.y 0.5]
if bal : set shift : CAP / 2 - [mix baly gMiddleY bal]
: else : set shift : CAP / 2 - gMiddleY
apply-transform : Translate (width / 2) (symbolMid * pscale - (CAP / 2 - shift) * dscale)
apply-transform : Italify
set currentGlyph.cmpPriority 11
refair this
set-width 0
sketch
local s : TANSLANT * symbolMid
set-width width
include lg
include : dispiro
widths.lhs sw
g4 ([mix l r 0.15] - s) (parenTop * pscale)
g4.down.mid (l - s + O) (symbolMid * pscale)
g4 ([mix l r 0.15] - s) (parenBot * pscale)
include : Upright include : dispiro
include : Translate 0 (symbolMid - symbolMid * pscale) widths.rhs sw
include : Italify g4 ([mix r l 0.15] + s) (parenTop * pscale)
g4.down.mid (r + s - O) (symbolMid * pscale)
save gn unicode g4 ([mix r l 0.15] + s) (parenBot * pscale)
include : Upright
include : Translate 0 (symbolMid - symbolMid * pscale)
include : Italify
if (w == ww) : save gn unicode
: else : save gn
define [createDottedGlyphs shrink records] : if [not recursive] : begin define [createDottedGlyphs shrink records] : if [not recursive] : begin
local pendingGlyphs : records.map : [record] => record.1 local pendingGlyphs : records.map : [record] => record.1
@ -475,29 +495,33 @@ export : define [apply] : begin
if (para.spacing > 1) 1 shrink if (para.spacing > 1) 1 shrink
foreach {unicode parts w} [items-of records] : do foreach {unicode parts w} [items-of records] : do
local gn : suggestName : 'dotted-' + [parts.join '_'] foreach {suffix ww} [items-of circleWidthClasses] : do
define [object width dscale pscale sw l r] : bracedDottdeDimens w
sketch local gn : CircName 'dotted' parts suffix
set-width width define [object width dscale pscale sw l r] : bracedDottdeDimens ww
local tw 0
foreach [glyphid : items-of : parts.concat {'period'}] : begin sketch
local g miniatureFont.(glyphid) set-width width
if tw : begin # Add a little kern local tw 0
set tw : tw - SB foreach [glyphid : items-of : parts.concat {'period'}] : begin
apply-transform : Translate SB 0 local g miniatureFont.(glyphid)
include g if tw : begin # Add a little kern
apply-transform : Translate (-g.advanceWidth) 0 set tw : tw - SB
set tw : tw + g.advanceWidth apply-transform : Translate SB 0
apply-transform : Translate tw 0 include g
set tw : tw - SB apply-transform : Translate (-g.advanceWidth) 0
apply-transform : Upright set tw : tw + g.advanceWidth
if (tw > width) apply-transform : Translate tw 0
: then : apply-transform : Scale [Math.min 1 (width / tw)] 1 set tw : tw - SB
: else : apply-transform : Translate (width / 2 - tw / 2) 0 apply-transform : Upright
apply-transform : Italify if (tw > width)
set currentGlyph.cmpPriority 11 : then : apply-transform : Scale [Math.min 1 (width / tw)] 1
save gn unicode : else : apply-transform : Translate (width / 2 - tw / 2) 0
apply-transform : Italify
set currentGlyph.cmpPriority 11
if (w == ww) : save gn unicode
: else : save gn
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
@ -987,10 +1011,11 @@ export : define [apply] : begin
# Circled & Braced # Circled & Braced
if [not recursive] : let : begin if [not recursive] : let : begin
local compositions : list local compositions : list
list 0xA9 {'C'} FULLWIDTH2 list 0xA9 {'C'} FULLWIDTH2
list 0xAE {'R'} FULLWIDTH2 list 0x1F12F {'turnC'} FULLWIDTH2
list 0x2117 {'P'} FULLWIDTH2 list 0xAE {'R'} FULLWIDTH2
list 0x24EA {'zero'} FULLWIDTH1 list 0x2117 {'P'} FULLWIDTH2
list 0x24EA {'zero'} FULLWIDTH1
compositions.push { null {'space'} FULLWIDTH1 } compositions.push { null {'space'} FULLWIDTH1 }
foreach [j : range 1 till 20] : compositions.push : list foreach [j : range 1 till 20] : compositions.push : list
0x2460 + j - 1 0x2460 + j - 1