@capsizecss/unpack
Advanced tools
Comparing version 0.0.0-x-avg-char-width-20221011221538 to 0.0.0-x-avg-char-width-20221019035511
# @capsizecss/unpack | ||
## 0.0.0-x-avg-char-width-20221011221538 | ||
## 0.0.0-x-avg-char-width-20221019035511 | ||
@@ -5,0 +5,0 @@ ### Minor Changes |
@@ -14,4 +14,64 @@ 'use strict'; | ||
const sampleString = 'abcdefghijklmnopqrstuvwxyz'; | ||
// Table 2: Weight Factors | ||
const weightings = { | ||
a: 64, | ||
b: 14, | ||
c: 27, | ||
d: 35, | ||
e: 100, | ||
f: 2, | ||
g: 14, | ||
h: 42, | ||
i: 63, | ||
j: 3, | ||
k: 6, | ||
l: 35, | ||
m: 2, | ||
n: 56, | ||
o: 56, | ||
p: 17, | ||
q: 4, | ||
r: 49, | ||
s: 56, | ||
t: 71, | ||
u: 31, | ||
v: 1, | ||
w: 18, | ||
x: 3, | ||
y: 18, | ||
z: 2 // ' ': 166, | ||
}; // Ref: https://en.wikipedia.org/wiki/Letter_frequency#Relative_frequencies_of_letters_in_other_languages | ||
const wikipediaWeightings = { | ||
a: 8.167, | ||
b: 1.492, | ||
c: 2.782, | ||
d: 4.253, | ||
e: 12.702, | ||
f: 2.228, | ||
g: 2.015, | ||
h: 6.094, | ||
i: 6.966, | ||
j: 0.153, | ||
k: 0.772, | ||
l: 4.025, | ||
m: 2.406, | ||
n: 6.749, | ||
o: 7.507, | ||
p: 1.929, | ||
q: 0.095, | ||
r: 5.987, | ||
s: 6.327, | ||
t: 9.056, | ||
u: 2.758, | ||
v: 0.978, | ||
w: 2.36, | ||
x: 0.15, | ||
y: 1.974, | ||
z: 0.074 | ||
}; | ||
const sampleString = Object.keys(weightings).join(''); | ||
const unpackMetricsFromFont = font => { | ||
@@ -27,9 +87,17 @@ const { | ||
} = font; | ||
const sampleGlyphs = font.glyphsForString(sampleString); // sampleGlyphs.forEach((glyph, index) => { | ||
// console.log(sampleString.charAt(index), glyph.advanceWidth); | ||
// }); | ||
const sampleGlyphs = font.glyphsForString(sampleString); // xAvgLowercase | ||
const total = sampleGlyphs.reduce((sum, glyph) => sum + glyph.advanceWidth, 0); | ||
const xAvgLowercase = Math.round(total / sampleGlyphs.length); // @ts-expect-error | ||
const xAvgLowercase = Math.round(total / sampleGlyphs.length); // xAvgWeightedOs2 | ||
const weightedOs2Total = sampleGlyphs.reduce((sum, glyph, index) => { | ||
return sum + glyph.advanceWidth * weightings[sampleString.charAt(index)]; | ||
}, 0); | ||
const xAvgWeightedOs2 = Math.round(weightedOs2Total / 1000); // xAvgWeightedWiki | ||
const weightedWikiTotal = sampleGlyphs.reduce((sum, glyph, index) => { | ||
return sum + glyph.advanceWidth * (wikipediaWeightings[sampleString.charAt(index)] / 100); | ||
}, 0); | ||
const xAvgWeightedWiki = Math.round(weightedWikiTotal); // @ts-expect-error | ||
const xAvgCharWidth = font['OS/2'].xAvgCharWidth; | ||
@@ -45,3 +113,5 @@ return { | ||
xAvgCharWidth, | ||
xAvgLowercase | ||
xAvgLowercase, | ||
xAvgWeightedOs2, | ||
xAvgWeightedWiki | ||
}; | ||
@@ -48,0 +118,0 @@ }; |
@@ -5,4 +5,64 @@ import 'cross-fetch/polyfill'; | ||
const sampleString = 'abcdefghijklmnopqrstuvwxyz'; | ||
// Table 2: Weight Factors | ||
const weightings = { | ||
a: 64, | ||
b: 14, | ||
c: 27, | ||
d: 35, | ||
e: 100, | ||
f: 2, | ||
g: 14, | ||
h: 42, | ||
i: 63, | ||
j: 3, | ||
k: 6, | ||
l: 35, | ||
m: 2, | ||
n: 56, | ||
o: 56, | ||
p: 17, | ||
q: 4, | ||
r: 49, | ||
s: 56, | ||
t: 71, | ||
u: 31, | ||
v: 1, | ||
w: 18, | ||
x: 3, | ||
y: 18, | ||
z: 2 // ' ': 166, | ||
}; // Ref: https://en.wikipedia.org/wiki/Letter_frequency#Relative_frequencies_of_letters_in_other_languages | ||
const wikipediaWeightings = { | ||
a: 8.167, | ||
b: 1.492, | ||
c: 2.782, | ||
d: 4.253, | ||
e: 12.702, | ||
f: 2.228, | ||
g: 2.015, | ||
h: 6.094, | ||
i: 6.966, | ||
j: 0.153, | ||
k: 0.772, | ||
l: 4.025, | ||
m: 2.406, | ||
n: 6.749, | ||
o: 7.507, | ||
p: 1.929, | ||
q: 0.095, | ||
r: 5.987, | ||
s: 6.327, | ||
t: 9.056, | ||
u: 2.758, | ||
v: 0.978, | ||
w: 2.36, | ||
x: 0.15, | ||
y: 1.974, | ||
z: 0.074 | ||
}; | ||
const sampleString = Object.keys(weightings).join(''); | ||
const unpackMetricsFromFont = font => { | ||
@@ -18,9 +78,17 @@ const { | ||
} = font; | ||
const sampleGlyphs = font.glyphsForString(sampleString); // sampleGlyphs.forEach((glyph, index) => { | ||
// console.log(sampleString.charAt(index), glyph.advanceWidth); | ||
// }); | ||
const sampleGlyphs = font.glyphsForString(sampleString); // xAvgLowercase | ||
const total = sampleGlyphs.reduce((sum, glyph) => sum + glyph.advanceWidth, 0); | ||
const xAvgLowercase = Math.round(total / sampleGlyphs.length); // @ts-expect-error | ||
const xAvgLowercase = Math.round(total / sampleGlyphs.length); // xAvgWeightedOs2 | ||
const weightedOs2Total = sampleGlyphs.reduce((sum, glyph, index) => { | ||
return sum + glyph.advanceWidth * weightings[sampleString.charAt(index)]; | ||
}, 0); | ||
const xAvgWeightedOs2 = Math.round(weightedOs2Total / 1000); // xAvgWeightedWiki | ||
const weightedWikiTotal = sampleGlyphs.reduce((sum, glyph, index) => { | ||
return sum + glyph.advanceWidth * (wikipediaWeightings[sampleString.charAt(index)] / 100); | ||
}, 0); | ||
const xAvgWeightedWiki = Math.round(weightedWikiTotal); // @ts-expect-error | ||
const xAvgCharWidth = font['OS/2'].xAvgCharWidth; | ||
@@ -36,3 +104,5 @@ return { | ||
xAvgCharWidth, | ||
xAvgLowercase | ||
xAvgLowercase, | ||
xAvgWeightedOs2, | ||
xAvgWeightedWiki | ||
}; | ||
@@ -39,0 +109,0 @@ }; |
@@ -14,4 +14,64 @@ 'use strict'; | ||
const sampleString = 'abcdefghijklmnopqrstuvwxyz'; | ||
// Table 2: Weight Factors | ||
const weightings = { | ||
a: 64, | ||
b: 14, | ||
c: 27, | ||
d: 35, | ||
e: 100, | ||
f: 2, | ||
g: 14, | ||
h: 42, | ||
i: 63, | ||
j: 3, | ||
k: 6, | ||
l: 35, | ||
m: 2, | ||
n: 56, | ||
o: 56, | ||
p: 17, | ||
q: 4, | ||
r: 49, | ||
s: 56, | ||
t: 71, | ||
u: 31, | ||
v: 1, | ||
w: 18, | ||
x: 3, | ||
y: 18, | ||
z: 2 // ' ': 166, | ||
}; // Ref: https://en.wikipedia.org/wiki/Letter_frequency#Relative_frequencies_of_letters_in_other_languages | ||
const wikipediaWeightings = { | ||
a: 8.167, | ||
b: 1.492, | ||
c: 2.782, | ||
d: 4.253, | ||
e: 12.702, | ||
f: 2.228, | ||
g: 2.015, | ||
h: 6.094, | ||
i: 6.966, | ||
j: 0.153, | ||
k: 0.772, | ||
l: 4.025, | ||
m: 2.406, | ||
n: 6.749, | ||
o: 7.507, | ||
p: 1.929, | ||
q: 0.095, | ||
r: 5.987, | ||
s: 6.327, | ||
t: 9.056, | ||
u: 2.758, | ||
v: 0.978, | ||
w: 2.36, | ||
x: 0.15, | ||
y: 1.974, | ||
z: 0.074 | ||
}; | ||
const sampleString = Object.keys(weightings).join(''); | ||
const unpackMetricsFromFont = font => { | ||
@@ -27,9 +87,17 @@ const { | ||
} = font; | ||
const sampleGlyphs = font.glyphsForString(sampleString); // sampleGlyphs.forEach((glyph, index) => { | ||
// console.log(sampleString.charAt(index), glyph.advanceWidth); | ||
// }); | ||
const sampleGlyphs = font.glyphsForString(sampleString); // xAvgLowercase | ||
const total = sampleGlyphs.reduce((sum, glyph) => sum + glyph.advanceWidth, 0); | ||
const xAvgLowercase = Math.round(total / sampleGlyphs.length); // @ts-expect-error | ||
const xAvgLowercase = Math.round(total / sampleGlyphs.length); // xAvgWeightedOs2 | ||
const weightedOs2Total = sampleGlyphs.reduce((sum, glyph, index) => { | ||
return sum + glyph.advanceWidth * weightings[sampleString.charAt(index)]; | ||
}, 0); | ||
const xAvgWeightedOs2 = Math.round(weightedOs2Total / 1000); // xAvgWeightedWiki | ||
const weightedWikiTotal = sampleGlyphs.reduce((sum, glyph, index) => { | ||
return sum + glyph.advanceWidth * (wikipediaWeightings[sampleString.charAt(index)] / 100); | ||
}, 0); | ||
const xAvgWeightedWiki = Math.round(weightedWikiTotal); // @ts-expect-error | ||
const xAvgCharWidth = font['OS/2'].xAvgCharWidth; | ||
@@ -45,3 +113,5 @@ return { | ||
xAvgCharWidth, | ||
xAvgLowercase | ||
xAvgLowercase, | ||
xAvgWeightedOs2, | ||
xAvgWeightedWiki | ||
}; | ||
@@ -48,0 +118,0 @@ }; |
@@ -14,4 +14,64 @@ 'use strict'; | ||
const sampleString = 'abcdefghijklmnopqrstuvwxyz'; | ||
// Table 2: Weight Factors | ||
const weightings = { | ||
a: 64, | ||
b: 14, | ||
c: 27, | ||
d: 35, | ||
e: 100, | ||
f: 2, | ||
g: 14, | ||
h: 42, | ||
i: 63, | ||
j: 3, | ||
k: 6, | ||
l: 35, | ||
m: 2, | ||
n: 56, | ||
o: 56, | ||
p: 17, | ||
q: 4, | ||
r: 49, | ||
s: 56, | ||
t: 71, | ||
u: 31, | ||
v: 1, | ||
w: 18, | ||
x: 3, | ||
y: 18, | ||
z: 2 // ' ': 166, | ||
}; // Ref: https://en.wikipedia.org/wiki/Letter_frequency#Relative_frequencies_of_letters_in_other_languages | ||
const wikipediaWeightings = { | ||
a: 8.167, | ||
b: 1.492, | ||
c: 2.782, | ||
d: 4.253, | ||
e: 12.702, | ||
f: 2.228, | ||
g: 2.015, | ||
h: 6.094, | ||
i: 6.966, | ||
j: 0.153, | ||
k: 0.772, | ||
l: 4.025, | ||
m: 2.406, | ||
n: 6.749, | ||
o: 7.507, | ||
p: 1.929, | ||
q: 0.095, | ||
r: 5.987, | ||
s: 6.327, | ||
t: 9.056, | ||
u: 2.758, | ||
v: 0.978, | ||
w: 2.36, | ||
x: 0.15, | ||
y: 1.974, | ||
z: 0.074 | ||
}; | ||
const sampleString = Object.keys(weightings).join(''); | ||
const unpackMetricsFromFont = font => { | ||
@@ -27,9 +87,17 @@ const { | ||
} = font; | ||
const sampleGlyphs = font.glyphsForString(sampleString); // sampleGlyphs.forEach((glyph, index) => { | ||
// console.log(sampleString.charAt(index), glyph.advanceWidth); | ||
// }); | ||
const sampleGlyphs = font.glyphsForString(sampleString); // xAvgLowercase | ||
const total = sampleGlyphs.reduce((sum, glyph) => sum + glyph.advanceWidth, 0); | ||
const xAvgLowercase = Math.round(total / sampleGlyphs.length); // @ts-expect-error | ||
const xAvgLowercase = Math.round(total / sampleGlyphs.length); // xAvgWeightedOs2 | ||
const weightedOs2Total = sampleGlyphs.reduce((sum, glyph, index) => { | ||
return sum + glyph.advanceWidth * weightings[sampleString.charAt(index)]; | ||
}, 0); | ||
const xAvgWeightedOs2 = Math.round(weightedOs2Total / 1000); // xAvgWeightedWiki | ||
const weightedWikiTotal = sampleGlyphs.reduce((sum, glyph, index) => { | ||
return sum + glyph.advanceWidth * (wikipediaWeightings[sampleString.charAt(index)] / 100); | ||
}, 0); | ||
const xAvgWeightedWiki = Math.round(weightedWikiTotal); // @ts-expect-error | ||
const xAvgCharWidth = font['OS/2'].xAvgCharWidth; | ||
@@ -45,3 +113,5 @@ return { | ||
xAvgCharWidth, | ||
xAvgLowercase | ||
xAvgLowercase, | ||
xAvgWeightedOs2, | ||
xAvgWeightedWiki | ||
}; | ||
@@ -48,0 +118,0 @@ }; |
@@ -5,4 +5,64 @@ import 'cross-fetch/polyfill'; | ||
const sampleString = 'abcdefghijklmnopqrstuvwxyz'; | ||
// Table 2: Weight Factors | ||
const weightings = { | ||
a: 64, | ||
b: 14, | ||
c: 27, | ||
d: 35, | ||
e: 100, | ||
f: 2, | ||
g: 14, | ||
h: 42, | ||
i: 63, | ||
j: 3, | ||
k: 6, | ||
l: 35, | ||
m: 2, | ||
n: 56, | ||
o: 56, | ||
p: 17, | ||
q: 4, | ||
r: 49, | ||
s: 56, | ||
t: 71, | ||
u: 31, | ||
v: 1, | ||
w: 18, | ||
x: 3, | ||
y: 18, | ||
z: 2 // ' ': 166, | ||
}; // Ref: https://en.wikipedia.org/wiki/Letter_frequency#Relative_frequencies_of_letters_in_other_languages | ||
const wikipediaWeightings = { | ||
a: 8.167, | ||
b: 1.492, | ||
c: 2.782, | ||
d: 4.253, | ||
e: 12.702, | ||
f: 2.228, | ||
g: 2.015, | ||
h: 6.094, | ||
i: 6.966, | ||
j: 0.153, | ||
k: 0.772, | ||
l: 4.025, | ||
m: 2.406, | ||
n: 6.749, | ||
o: 7.507, | ||
p: 1.929, | ||
q: 0.095, | ||
r: 5.987, | ||
s: 6.327, | ||
t: 9.056, | ||
u: 2.758, | ||
v: 0.978, | ||
w: 2.36, | ||
x: 0.15, | ||
y: 1.974, | ||
z: 0.074 | ||
}; | ||
const sampleString = Object.keys(weightings).join(''); | ||
const unpackMetricsFromFont = font => { | ||
@@ -18,9 +78,17 @@ const { | ||
} = font; | ||
const sampleGlyphs = font.glyphsForString(sampleString); // sampleGlyphs.forEach((glyph, index) => { | ||
// console.log(sampleString.charAt(index), glyph.advanceWidth); | ||
// }); | ||
const sampleGlyphs = font.glyphsForString(sampleString); // xAvgLowercase | ||
const total = sampleGlyphs.reduce((sum, glyph) => sum + glyph.advanceWidth, 0); | ||
const xAvgLowercase = Math.round(total / sampleGlyphs.length); // @ts-expect-error | ||
const xAvgLowercase = Math.round(total / sampleGlyphs.length); // xAvgWeightedOs2 | ||
const weightedOs2Total = sampleGlyphs.reduce((sum, glyph, index) => { | ||
return sum + glyph.advanceWidth * weightings[sampleString.charAt(index)]; | ||
}, 0); | ||
const xAvgWeightedOs2 = Math.round(weightedOs2Total / 1000); // xAvgWeightedWiki | ||
const weightedWikiTotal = sampleGlyphs.reduce((sum, glyph, index) => { | ||
return sum + glyph.advanceWidth * (wikipediaWeightings[sampleString.charAt(index)] / 100); | ||
}, 0); | ||
const xAvgWeightedWiki = Math.round(weightedWikiTotal); // @ts-expect-error | ||
const xAvgCharWidth = font['OS/2'].xAvgCharWidth; | ||
@@ -36,3 +104,5 @@ return { | ||
xAvgCharWidth, | ||
xAvgLowercase | ||
xAvgLowercase, | ||
xAvgWeightedOs2, | ||
xAvgWeightedWiki | ||
}; | ||
@@ -39,0 +109,0 @@ }; |
@@ -13,2 +13,4 @@ import 'cross-fetch/polyfill'; | ||
xAvgLowercase: number; | ||
xAvgWeightedOs2: number; | ||
xAvgWeightedWiki: number; | ||
}; | ||
@@ -15,0 +17,0 @@ export declare type Font = ReturnType<typeof unpackMetricsFromFont>; |
{ | ||
"name": "@capsizecss/unpack", | ||
"version": "0.0.0-x-avg-char-width-20221011221538", | ||
"version": "0.0.0-x-avg-char-width-20221019035511", | ||
"description": "Unpack capsize font metrics from fonts", | ||
@@ -5,0 +5,0 @@ "main": "dist/capsizecss-unpack.cjs.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20812
665