Files
Iosevka/meta/naming.ptl
T
2019-09-28 20:29:39 -07:00

173 lines
5.6 KiB
Plaintext

define COPYRIGHT 0
define FAMILY 1
define STYLE 2
define UNIQUE_NAME 3
define FULL_NAME 4
define VERSION 5
define POSTSCRIPT 6
define TRADEMARK 7
define MANUFACTURER 8
define DESIGNER 9
define DESCRIPTION 10
define LICENCE 13
define PREFERRED_FAMILY 16
define PREFERRED_STYLE 17
define WWS_PREFERRED_FAMILY 21
define WWS_PREFERRED_STYLE 22
define [nameFont font nameid str] : begin
font.name.push : object # Mac Roman
platformID 1
encodingID 0
languageID 0
nameID nameid
nameString str
font.name.push : object # Windows Unicode English
platformID 3
encodingID 1
languageID 1033
nameID nameid
nameString str
define weightToMenuStyleMap : object
100 "Thin"
200 "Extralight"
300 "Light"
400 ""
500 "Medium"
600 "Semibold"
700 "Bold"
800 "Extrabold"
900 "Heavy"
define widthToMenuStyleMap : object
1 "Ultra-condensed"
2 "Extra-condensed"
3 "Condensed"
4 "Semi-condensed"
5 ""
6 "Semi-extended"
7 "Extended"
8 "Extra-extended"
9 "Ultra-extended"
define slantToMenuStyleMap : object
normal ""
italic "Italic"
oblique "Oblique"
define weightToMenuStyleMapShort : object
100 "Th"
200 "XLt"
300 "Lt"
400 ""
500 "Md"
600 "SmBd"
700 "Bd"
800 "XBd"
900 "Xv"
define widthToMenuStyleMapShort : object
1 "UltCn"
2 "XCn"
3 "Cn"
4 "SmCn"
5 ""
6 "SmEx"
7 "Ex"
8 "XEx"
9 "UltEx"
define slantToMenuStyleMapShort : object
normal ""
italic "It"
oblique "Obl"
define [getStyle weight width slant] : [[(weightToMenuStyleMap.(weight) + " " + widthToMenuStyleMap.(width) + " " + slantToMenuStyleMap.(slant)).replace [regex ' +' 'g'] ' '].trim] || "Regular"
define [getShortStyle weight width slant] : [(weightToMenuStyleMapShort.(weight) + " " + widthToMenuStyleMapShort.(width) + " " + slantToMenuStyleMapShort.(slant)).replace [regex ' ' 'g'] ''] || "Regular"
define [isRBIBI style] : style == 'Regular' || style == 'Bold' || style == 'Italic' || style == "Bold Italic"
export : define [assignFontNames para metrics font] : begin
set font.name {}
define family : para.naming.family.trim
define style : getStyle para.naming.weight para.menuWidth para.naming.slant
define version para.naming.version
define isItalic : para.naming.slant == "italic"
define isOblique : para.naming.slant == "oblique"
define isBold : para.naming.weight > 650
nameFont font PREFERRED_FAMILY family # Preferred Family
nameFont font PREFERRED_STYLE style # Preferred Style
nameFont font WWS_PREFERRED_FAMILY family # WWS Preferred Family
nameFont font WWS_PREFERRED_STYLE style # WWS Preferred Style
set font.name.preferredFamily family
set font.name.preferredSubFamily style
local compatFamily family
local compatStyle style
if [not : isRBIBI style] : begin
if isItalic : begin
set compatStyle slantToMenuStyleMap.italic
set compatFamily : family + ' ' + [getStyle para.naming.weight para.menuWidth 'normal']
: else : begin
set compatStyle 'Regular'
set compatFamily : family + ' ' + style
# Sometimes compatibility family will grow too large.
if (compatFamily.length >= 31) : begin
if isItalic : begin
set compatStyle slantToMenuStyleMap.italic
set compatFamily : family + ' ' + [getShortStyle para.naming.weight para.menuWidth 'normal']
: else : begin
local shortStyle : getShortStyle para.naming.weight para.menuWidth para.naming.slant
set compatStyle 'Regular'
set compatFamily : family + ' ' + shortStyle
nameFont font FAMILY compatFamily # Family
nameFont font STYLE compatStyle # Style
nameFont font UNIQUE_NAME "\(family) \(style) \(version)" # Unique Name
local fontfullName : if (style != 'Regular') (family + ' ' + style) family
nameFont font FULL_NAME fontfullName # Full Name
nameFont font POSTSCRIPT : fontfullName.replace [regex ' ' 'g'] '-' # Postscript
nameFont font VERSION version # Version
nameFont font COPYRIGHT para.copyright # Copyright
nameFont font MANUFACTURER para.manufacturer # Manufacturer
nameFont font DESIGNER para.designer # Designer
nameFont font DESCRIPTION para.description # Description
nameFont font LICENCE para.licence # Licence
set font.name : font.name.sort : lambda [a b] : begin
if (a.platformID != b.platformID) : return : a.platformID - b.platformID
if (a.encodingID != b.encodingID) : return : a.encodingID - b.encodingID
if (a.languageID != b.languageID) : return : a.languageID - b.languageID
return : a.nameID - b.nameID
# Weight, width and slantness
set font.OS_2.usWeightClass para.naming.weight
set font.OS_2.usWidthClass para.menuWidth
set font.OS_2.panose.2 : 1 + para.naming.weight / 100
set font.OS_2.fsSelection : object
oblique : not : not isOblique
bold : not : not isBold
italic : not : not (isItalic || isOblique)
regular : not : not ([not isBold] && [not isItalic] && [not isOblique])
useTypoMetrics true
set font.OS_2.sFamilyClass : 8 * 0x100 + 9
set font.OS_2.xAvgCharWidth para.width
set font.head.macStyle : object
bold : not : not isBold
italic : not : not (isItalic || isOblique)
if (para.diversityM == 1 && para.diversityF == 1 && para.diversityI == 1 && para.diversityII == 1) : begin
set font.OS_2.panose.3 9 # Monospaced
set font.post.isFixedPitch true
: else : begin
set font.OS_2.panose.3 0
set font.post.isFixedPitch false