Fix serifs in dingbat circled numbers (#1182).

This commit is contained in:
be5invis 2021-07-31 12:50:09 -07:00
parent 5144fcb770
commit 2297c8b566
3 changed files with 74 additions and 45 deletions

1
changes/9.0.1.md Normal file
View file

@ -0,0 +1 @@
* Fix serifs in dingbat circled numbers (#1182).

View file

@ -4,6 +4,7 @@ $$include '../../meta/macros.ptl'
import [mix linreg clamp fallback] from '../../support/utils' import [mix linreg clamp fallback] from '../../support/utils'
import [getGrMesh AnyCv CvDecompose Joining] from "../../support/gr" import [getGrMesh AnyCv CvDecompose Joining] from "../../support/gr"
import [hashGeometry] from "../../support/geometry/index" import [hashGeometry] from "../../support/geometry/index"
import [Transform] from "../../support/geometry/transform"
extern Map extern Map
extern Set extern Set
@ -120,29 +121,25 @@ glyph-block AutoBuild-Enclosure : begin
define [EnclosureStrokeScale dscale digits width] : dscale / [Math.pow [AdjustDigitCount digits width] 0.66] define [EnclosureStrokeScale dscale digits width] : dscale / [Math.pow [AdjustDigitCount digits width] 0.66]
define enclosureInnerPartActualWidth : new Map define enclosureInnerPartActualWidth : new Map
define [EnsureInnerSubGlyphImpl miniatureFont markClass dscale xCompress yCompress mp mpShift bal baly kExtraYShift] : lambda [gidPart] : begin define [EnsureInnerSubGlyphImpl gniPrefix markClass miniatureFont mp actualWidth accumulatedTfm] : function [gidPart] : begin
define subGlyph : miniatureFont.queryByNameEnsured gidPart define subGlyph : miniatureFont.queryByNameEnsured gidPart
define geomHash : hashGeometry subGlyph.geometry define geomHash : hashGeometry subGlyph.geometry
define shift : if mp mpShift : getGlyphDefaultShift bal baly subGlyph
define shiftPartName : if mp "mp\(shift)" "sp"
define gniPart : '.ci.' + geomHash + '@' + [{ dscale xCompress yCompress shiftPartName kExtraYShift [subGlyph.gizmo.toString] }.join '/'] define gniPart : '.ci.' + gniPrefix + '.' + geomHash + '@' + [{ mp actualWidth accumulatedTfm }.join '/']
if [not : query-glyph gniPart] : begin if [not : query-glyph gniPart] : begin
enclosureInnerPartActualWidth.set gniPart (subGlyph.advanceWidth * dscale * xCompress) enclosureInnerPartActualWidth.set gniPart (actualWidth)
create-glyph gniPart : glyph-proc create-glyph gniPart : glyph-proc
set-width 0 set-width 0
set-mark-anchor 'compositeInner' 0 0 set-mark-anchor 'compositeInner' 0 0
include subGlyph include subGlyph
include : subGlyph.gizmo.inverse include accumulatedTfm
include : Scale (dscale * xCompress) (dscale * yCompress)
include : Translate 0 (dscale * shift + SymbolMid + (kExtraYShift - 0.5) * CAP * dscale)
include subGlyph.gizmo
if mp if mp
: then : set-mark-anchor markClass 0 0 (subGlyph.advanceWidth * dscale * xCompress) 0 then : set-mark-anchor markClass 0 0 (actualWidth) 0
: else : set-mark-anchor markClass (subGlyph.advanceWidth * dscale * xCompress / 2) 0 else : set-mark-anchor markClass (actualWidth / 2) 0
return gniPart return gniPart
define [EnsureInnerSubGlyphSeq markClass miniatureFont job dimens yCompress kExtraYShift] : begin define [EnsureInnerSubGlyphSeq gniPrefix markClass miniatureFont job dimens yCompress kExtraYShift] : begin
define { gn unicode parts w bal baly } job define { gn unicode parts w bal baly } job
define [object width mockInnerWidth dscale] dimens define [object width mockInnerWidth dscale] dimens
@ -154,13 +151,20 @@ glyph-block AutoBuild-Enclosure : begin
set totalWidth : totalWidth + derivedGlyph.advanceWidth set totalWidth : totalWidth + derivedGlyph.advanceWidth
local xCompress [Math.min 1 (mockInnerWidth / totalWidth)] local xCompress [Math.min 1 (mockInnerWidth / totalWidth)]
set totalWidth : Math.min mockInnerWidth totalWidth set totalWidth : Math.min mockInnerWidth totalWidth
local mpShift : getGlyphDefaultShift bal baly firstDerivedGyph
local shift : getGlyphDefaultShift bal baly firstDerivedGyph
local accumulatedTfm : Transform.Combine
firstDerivedGyph.gizmo.inverse
Scale (dscale * xCompress) (dscale * yCompress)
Translate 0 (dscale * shift + SymbolMid + (kExtraYShift - 0.5) * CAP * dscale)
begin firstDerivedGyph.gizmo
local finalParts {} local finalParts {}
foreach partIndex [range 0 parts.length] : do foreach partIndex [range 0 parts.length] : do
define gidPart parts.(partIndex) define gidPart parts.(partIndex)
local actualWidth : [miniatureFont.queryByNameEnsured gidPart].advanceWidth * dscale * xCompress
finalParts.push : EnsureComponentGlyphT gidPart finalParts.push : EnsureComponentGlyphT gidPart
EnsureInnerSubGlyphImpl miniatureFont markClass dscale xCompress yCompress (parts.length > 1) mpShift bal baly kExtraYShift EnsureInnerSubGlyphImpl gniPrefix markClass miniatureFont (parts.length > 1) actualWidth accumulatedTfm
return finalParts return finalParts
@ -175,22 +179,22 @@ glyph-block AutoBuild-Enclosure : begin
include : WithTransform [Translate x 0] : refer-glyph gniPart include : WithTransform [Translate x 0] : refer-glyph gniPart
set x : x + ([enclosureInnerPartActualWidth.get gniPart] || 0) set x : x + ([enclosureInnerPartActualWidth.get gniPart] || 0)
define [EnclosureInner gnEnclosure miniatureFont job dimens] : begin define [EnclosureInner gniPrefix gnEnclosure miniatureFont job dimens] : begin
define { gn unicode parts w bal baly } job define { gn unicode parts w bal baly } job
define [object width mockInnerWidth dscale] dimens define [object width mockInnerWidth dscale] dimens
local finalParts : EnsureInnerSubGlyphSeq 'enclosureInner' miniatureFont job dimens 1 0 local finalParts : EnsureInnerSubGlyphSeq gniPrefix 'enclosureInner' miniatureFont job dimens 1 0
if gnEnclosure : return : glyph-proc if gnEnclosure : return : glyph-proc
include : EnclosureInnerImpl dimens finalParts include : EnclosureInnerImpl dimens finalParts
CvDecompose.set currentGlyph [{gnEnclosure}.concat finalParts] CvDecompose.set currentGlyph [{gnEnclosure}.concat finalParts]
: else : return : new-glyph : EnclosureInnerImpl dimens finalParts : else : return : new-glyph : EnclosureInnerImpl dimens finalParts
define [TwoRowEnclosureInner gnEnclosure miniatureFont job dimens] : begin define [TwoRowEnclosureInner gniPrefix gnEnclosure miniatureFont job dimens] : begin
define { gn unicode parts w bal baly } job define { gn unicode parts w bal baly } job
define [object width mockInnerWidth dscale] dimens define [object width mockInnerWidth dscale] dimens
local jobFirstHalf { gn unicode [parts.slice 0 (parts.length / 2)] w bal baly } local jobFirstHalf { gn unicode [parts.slice 0 (parts.length / 2)] w bal baly }
local jobSecondHalf { gn unicode [parts.slice (parts.length / 2) ] w bal baly } local jobSecondHalf { gn unicode [parts.slice (parts.length / 2) ] w bal baly }
local finalPartsFirstHalf : EnsureInnerSubGlyphSeq 'enclosureInnerFirstHalf' miniatureFont jobFirstHalf dimens 0.45 (+0.55) local finalPartsFirstHalf : EnsureInnerSubGlyphSeq gniPrefix 'enclosureInnerFirstHalf' miniatureFont jobFirstHalf dimens 0.45 (+0.55)
local finalPartsSecondHalf : EnsureInnerSubGlyphSeq 'enclosureInnerSecondHalf' miniatureFont jobSecondHalf dimens 0.45 (+0.00) local finalPartsSecondHalf : EnsureInnerSubGlyphSeq gniPrefix 'enclosureInnerSecondHalf' miniatureFont jobSecondHalf dimens 0.45 (+0.00)
if gnEnclosure : return : glyph-proc if gnEnclosure : return : glyph-proc
include : EnclosureInnerImpl dimens finalPartsFirstHalf include : EnclosureInnerImpl dimens finalPartsFirstHalf
include : EnclosureInnerImpl dimens finalPartsSecondHalf include : EnclosureInnerImpl dimens finalPartsSecondHalf
@ -229,64 +233,70 @@ glyph-block AutoBuild-Enclosure : begin
define smoothB : SmoothBOf (SmallSmooth * (right - left) / (RightSB - SB)) width define smoothB : SmoothBOf (SmallSmooth * (right - left) / (RightSB - SB)) width
return : object width mockInnerWidth dscale sw0 sw top bot left right mosaicTop mosaicBot mosaicLeft mosaicRight smoothA smoothB return : object width mockInnerWidth dscale sw0 sw top bot left right mosaicTop mosaicBot mosaicLeft mosaicRight smoothA smoothB
define [StandardSpacing pp digits rows width] : MiniatureParaT pp define StandardSpacing : object
crowd -- [CircCrowd (digits / rows) width] gniPrefix ''
scale -- [CircScale (digits / rows) width] getPara : function [pp digits rows width] : MiniatureParaT pp
sbscale -- 1 crowd -- [CircCrowd (digits / rows) width]
mono -- (digits > 1) scale -- [CircScale (digits / rows) width]
mono2 -- (digits > 1) sbscale -- 1
mono -- (digits > 1)
mono2 -- (digits > 1)
define [ItalicSpacing pp digits rows width] : begin define ItalicSpacing : object
define pp1 : pp.reinit : function [a] : begin gniPrefix 'i'
set a.shape.slope 'italic' getPara : function[pp digits rows width] : begin
set a.shape.slopeAngle : mix (para.slopeAngle || 0) 15 (95 / 150) define pp1 : pp.reinit : function [a] : begin
return : StandardSpacing pp1 digits rows width set a.shape.slope 'italic'
set a.shape.slopeAngle : mix (para.slopeAngle || 0) 15 (95 / 150)
return : StandardSpacing.getPara pp1 digits rows width
define [SansSerifSpacing pp digits rows width] : begin define SansSerifSpacing : object
define pp1 : pp.reinit : function [a] : begin gniPrefix 'ss'
set a.shape.serifs 'sans' getPara : function [pp digits rows width] : begin
return : StandardSpacing pp1 digits rows width define pp1 : pp.reinit : function [a] : begin
set a.shape.serifs 'sans'
return : StandardSpacing.getPara pp1 digits rows width
define [EnclosureT prefix builder spacing digits rows demands fnEnclosure] : begin define [EnclosureT prefix builder spacing digits rows demands fnEnclosure] : begin
foreach {suffix ww gap} [items-of circleWidthClasses] : do foreach {suffix ww gap} [items-of circleWidthClasses] : do
define allowProportional : if (digits > 1) MONOSPACE-ONLY ALLOW-PROPORTIONAL define allowProportional : if (digits > 1) MONOSPACE-ONLY ALLOW-PROPORTIONAL
define jobs : CollectJobs builder.decomposable CENTERED allowProportional (prefix + digits) suffix demands define jobs : CollectJobs builder.decomposable CENTERED allowProportional (prefix + digits) suffix demands
define forkedPara : spacing para digits rows ww define forkedPara : spacing.getPara para digits rows ww
define miniatureFont : CreateDerivedFontFromJobs jobs {} : function [gs] : Fork gs forkedPara define miniatureFont : CreateDerivedFontFromJobs jobs {} : function [gs] : Fork gs forkedPara
define gnEnclosure : CircName null (prefix + digits + '.enclosure') {} suffix define gnEnclosure : CircName null (prefix + digits + '.enclosure') {} suffix
if [not : query-glyph gnEnclosure] : create-glyph gnEnclosure : fnEnclosure digits ww gap if [not : query-glyph gnEnclosure] : create-glyph gnEnclosure : fnEnclosure digits ww gap
foreach job [items-of jobs.decomposableJobs] : begin foreach job [items-of jobs.decomposableJobs] : begin
builder.build (prefix + digits) digits ww gap job miniatureFont gnEnclosure true builder.build (prefix + digits) spacing.gniPrefix digits ww gap job miniatureFont gnEnclosure true
foreach job [items-of jobs.nonDecomposable] : begin foreach job [items-of jobs.nonDecomposable] : begin
builder.build (prefix + digits) digits ww gap job miniatureFont gnEnclosure false builder.build (prefix + digits) spacing.gniPrefix digits ww gap job miniatureFont gnEnclosure false
applyRelations jobs.relApplications applyRelations jobs.relApplications
# Builders and Enclosure Shapes # Builders and Enclosure Shapes
define CircledBuilder : object define CircledBuilder : object
decomposable true decomposable true
build : lambda [prefix digits ww gap job miniatureFont gnEnclosure decomposable] : begin build : lambda [prefix gniPrefix digits ww gap job miniatureFont gnEnclosure decomposable] : begin
define { gn unicode parts w bal baly } job define { gn unicode parts w bal baly } job
define dimens : circleDimens digits ww define dimens : circleDimens digits ww
define [object width mockInnerWidth dscale] dimens define [object width mockInnerWidth dscale] dimens
if [not : query-glyph gn] : create-glyph gn [if (w == ww) unicode null] : glyph-proc if [not : query-glyph gn] : create-glyph gn [if (w == ww) unicode null] : glyph-proc
set-width width set-width width
include : EnclosureInner [if decomposable gnEnclosure null] miniatureFont job dimens include : EnclosureInner gniPrefix [if decomposable gnEnclosure null] miniatureFont job dimens
include : refer-glyph gnEnclosure include : refer-glyph gnEnclosure
define TwoRowBoxedBuilder : object define TwoRowBoxedBuilder : object
decomposable true decomposable true
build : lambda [prefix digits ww gap job miniatureFont gnEnclosure decomposable] : begin build : lambda [prefix gniPrefix digits ww gap job miniatureFont gnEnclosure decomposable] : begin
define { gn unicode parts w bal baly } job define { gn unicode parts w bal baly } job
define dimens : circleDimens digits ww define dimens : circleDimens digits ww
define [object width mockInnerWidth dscale] dimens define [object width mockInnerWidth dscale] dimens
if [not : query-glyph gn] : create-glyph gn [if (w == ww) unicode null] : glyph-proc if [not : query-glyph gn] : create-glyph gn [if (w == ww) unicode null] : glyph-proc
set-width width set-width width
include : TwoRowEnclosureInner [if decomposable gnEnclosure null] miniatureFont job dimens include : TwoRowEnclosureInner gniPrefix [if decomposable gnEnclosure null] miniatureFont job dimens
include : refer-glyph gnEnclosure include : refer-glyph gnEnclosure
define InsetBuilder : object define InsetBuilder : object
decomposable false decomposable false
build : lambda [prefix digits ww gap job miniatureFont gnEnclosure decomposable] : begin build : lambda [prefix gniPrefix digits ww gap job miniatureFont gnEnclosure decomposable] : begin
define { gn unicode parts w bal baly } job define { gn unicode parts w bal baly } job
define dimens : circleDimens digits ww define dimens : circleDimens digits ww
define [object width mockInnerWidth dscale] dimens define [object width mockInnerWidth dscale] dimens
@ -294,7 +304,7 @@ glyph-block AutoBuild-Enclosure : begin
set-width width set-width width
include : difference include : difference
refer-glyph gnEnclosure refer-glyph gnEnclosure
EnclosureInner [if decomposable gnEnclosure null] miniatureFont job dimens EnclosureInner gniPrefix [if decomposable gnEnclosure null] miniatureFont job dimens
define [AddEnclosureMark digits dimens] : glyph-proc define [AddEnclosureMark digits dimens] : glyph-proc
define [object width dscale mockInnerWidth] dimens define [object width dscale mockInnerWidth] dimens
@ -460,7 +470,7 @@ glyph-block AutoBuild-Enclosure : begin
define dimens : bracedDottdeDimens digits ww define dimens : bracedDottdeDimens digits ww
define [object width mockInnerWidth dscale] dimens define [object width mockInnerWidth dscale] dimens
set-width width set-width width
include : EnclosureInner [if jobDecomposable gnb null] miniatureFont job dimens include : EnclosureInner '' [if jobDecomposable gnb null] miniatureFont job dimens
include : refer-glyph gnb include : refer-glyph gnb
foreach job [items-of jobs.decomposableJobs] : CreateGlyphImpl true job foreach job [items-of jobs.decomposableJobs] : CreateGlyphImpl true job

View file

@ -67,4 +67,22 @@ exports.Transform = class Transform {
static isIdentity(tfm) { static isIdentity(tfm) {
return this.isTranslate(tfm) && tfm.x === 0 && tfm.y === 0; return this.isTranslate(tfm) && tfm.x === 0 && tfm.y === 0;
} }
static Combine(...tfms) {
let z00 = { x: 0, y: 0 };
let z10 = { x: 1, y: 0 };
let z01 = { x: 0, y: 1 };
for (const tfm of tfms) {
z00 = tfm.apply(z00);
z10 = tfm.apply(z10);
z01 = tfm.apply(z01);
}
return new Transform(
z10.x - z00.x,
z01.x - z00.x,
z10.y - z00.y,
z01.y - z00.y,
z00.x,
z00.y
);
}
}; };