From 7057ada9aa55ee927434f9c67edd8b626be234f6 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 2 Dec 2023 15:14:58 +0100 Subject: [PATCH] Dump OS/2 panose fields --- src/Graphics/Fountainhead/Dumper.hs | 44 ++++++-- src/Graphics/Fountainhead/TrueType.hs | 141 +++++++++++++++++++++++++- 2 files changed, 171 insertions(+), 14 deletions(-) diff --git a/src/Graphics/Fountainhead/Dumper.hs b/src/Graphics/Fountainhead/Dumper.hs index 1a7da2b..8c99fc7 100644 --- a/src/Graphics/Fountainhead/Dumper.hs +++ b/src/Graphics/Fountainhead/Dumper.hs @@ -272,19 +272,41 @@ dumpOs2 = (dumpCaption "'OS/2' Table - OS/2 and Windows Metrics" <>) . go <> " ySuperscriptYOffset: " <> Text.Builder.decimal ySuperscriptYOffset <> newlineBuilder <> " yStrikeoutSize: " <> Text.Builder.decimal yStrikeoutSize <> newlineBuilder <> " yStrikeoutPosition: " <> Text.Builder.decimal yStrikeoutPosition <> newlineBuilder - <> " sFamilyClass:" <> familyClass sFamilyClass + <> " sFamilyClass:" <> familyClass sFamilyClass <> newlineBuilder <> " PANOSE:" <> newlineBuilder <> dumpPanose panose + <> fold (Vector.imap dumpUnicodeRange ulUnicodeRange) + <> " achVendID: '" <> achVendID' achVendID <> "'\n" + achVendID' = Text.Builder.fromText . Text.decodeLatin1 . ByteString.pack . fmap fromIntegral . toList + dumpUnicodeRange index value = + let bits = index * 32 + parens = "( Bits " <> Text.Builder.decimal bits <> " - " + <> Text.Builder.decimal (bits + 31) <> " ):" + in " Unicode Range: " <> Text.Builder.decimal (index + 1) + <> Text.Builder.fromLazyText (Text.Lazy.justifyLeft 25 ' ' (Text.Builder.toLazyText parens)) + <> paddedHexadecimal value + <> newlineBuilder dumpPanose Panose{..} - = " Family Kind: 0 'Any'" - <> " Serif Style: 0 'Any'" - <> " Weight: 0 'Any'" - <> " Proportion: 0 'Any'" - <> " Contrast: 0 'Any'" - <> " Stroke: 0 'Any'" - <> " Arm Style: 0 'Any'" - <> " Lettreform: 0 'Any'" - <> " Midline: 0 'Any'" - <> " X-height: 0 'Any'" + = " Family Kind: " <> dumpPanoseField bFamilyType + <> " Serif Style: " <> dumpPanoseField bSerifStyle + <> " Weight: " <> dumpPanoseField bWeight + <> " Proportion: " <> dumpPanoseField bProportion + <> " Contrast: " <> dumpPanoseField bContrast + <> " Stroke: " <> dumpPanoseField bStrokeVariation + <> " Arm Style: " <> dumpPanoseField bArmStyle + <> " Lettreform: " <> dumpPanoseField bLetterform + <> " Midline: " <> dumpPanoseField bMidline + <> " X-height: " <> dumpPanoseField bXHeight + dumpPanoseField field' = + let numericField = Text.Builder.fromLazyText + $ Text.Lazy.justifyLeft 8 ' ' + $ Text.Builder.toLazyText + $ Text.Builder.decimal + $ fromEnum field' + in numericField + <> Text.Builder.singleton '\'' + <> Text.Builder.fromString (show field') + <> Text.Builder.singleton '\'' + <> newlineBuilder familyClass value = " " <> Text.Builder.decimal (value .>>. 8) <> " subclass = " <> Text.Builder.decimal (value .&. 0x00ff) weightClass classValue diff --git a/src/Graphics/Fountainhead/TrueType.hs b/src/Graphics/Fountainhead/TrueType.hs index 86aeb5f..2fff036 100644 --- a/src/Graphics/Fountainhead/TrueType.hs +++ b/src/Graphics/Fountainhead/TrueType.hs @@ -1007,7 +1007,62 @@ data BLetterform | ObliqueRoundedLetterform | ObliqueOffCenterLetterform | ObliqueSquareLetterform - deriving (Eq, Show) + deriving Eq + +instance Show BLetterform + where + show AnyLetterform = "Any" + show NoFitLetterform = "No Fit" + show NormalContactLetterform = "Normal/Contact" + show NormalWeightedLetterform = "Normal/Weighted" + show NormalBoxedLetterform = "Normal/Boxed" + show NormalFlattenedLetterform = "Normal/Flattened" + show NormalRoundedLetterform = "Normal/Rounded" + show NormalOffCenterLetterform = "Normal/Off Center" + show NormalSquareLetterform = "Normal/Square" + show ObliqueContactLetterform = "Oblique/Contact" + show ObliqueWeightedLetterform = "Oblique/Weighted" + show ObliqueBoxedLetterform = "Oblique/Boxed" + show ObliqueFlattenedLetterform = "Oblique/Flattened" + show ObliqueRoundedLetterform = "Oblique/Rounded" + show ObliqueOffCenterLetterform = "Oblique/Off Center" + show ObliqueSquareLetterform = "Oblique/Square" + +instance Enum BLetterform + where + fromEnum AnyLetterform = 0 + fromEnum NoFitLetterform = 1 + fromEnum NormalContactLetterform = 2 + fromEnum NormalWeightedLetterform = 3 + fromEnum NormalBoxedLetterform = 4 + fromEnum NormalFlattenedLetterform = 5 + fromEnum NormalRoundedLetterform = 6 + fromEnum NormalOffCenterLetterform = 7 + fromEnum NormalSquareLetterform = 8 + fromEnum ObliqueContactLetterform = 9 + fromEnum ObliqueWeightedLetterform = 10 + fromEnum ObliqueBoxedLetterform = 11 + fromEnum ObliqueFlattenedLetterform = 12 + fromEnum ObliqueRoundedLetterform = 13 + fromEnum ObliqueOffCenterLetterform = 14 + fromEnum ObliqueSquareLetterform = 15 + toEnum 0 = AnyLetterform + toEnum 1 = NoFitLetterform + toEnum 2 = NormalContactLetterform + toEnum 3 = NormalWeightedLetterform + toEnum 4 = NormalBoxedLetterform + toEnum 5 = NormalFlattenedLetterform + toEnum 6 = NormalRoundedLetterform + toEnum 7 = NormalOffCenterLetterform + toEnum 8 = NormalSquareLetterform + toEnum 9 = ObliqueContactLetterform + toEnum 10 = ObliqueWeightedLetterform + toEnum 11 = ObliqueBoxedLetterform + toEnum 12 = ObliqueFlattenedLetterform + toEnum 13 = ObliqueRoundedLetterform + toEnum 14 = ObliqueOffCenterLetterform + toEnum 15 = ObliqueSquareLetterform + toEnum _ = error "Unknown letterform" data BMidline = AnyMidline @@ -1024,7 +1079,56 @@ data BMidline | LowTrimmedMidline | LowPointedMidline | LowSerifedMidline - deriving (Eq, Show) + deriving Eq + +instance Show BMidline + where + show AnyMidline = "Any" + show NoFitMidline = "No Fit" + show StandardTrimmedMidline = "Standard/Trimmed" + show StandardPointedMidline = "Standard/Pointed" + show StandardSerifedMidline = "Standard/Serifed" + show HighTrimmedMidline = "High/Trimmed" + show HighPointedMidline = "High/Pointed" + show HighSerifedMidline = "High/Serifed" + show ConstantTrimmedMidline = "Constant/Trimmed" + show ConstantPointedMidline = "Constant/Pointed" + show ConstantSerifedMidline = "Constant/Serifed" + show LowTrimmedMidline = "Low/Trimmed" + show LowPointedMidline = "Low/Pointed" + show LowSerifedMidline = "Low/Serifed" + +instance Enum BMidline + where + fromEnum AnyMidline = 0 + fromEnum NoFitMidline = 1 + fromEnum StandardTrimmedMidline = 2 + fromEnum StandardPointedMidline = 3 + fromEnum StandardSerifedMidline = 4 + fromEnum HighTrimmedMidline = 5 + fromEnum HighPointedMidline = 6 + fromEnum HighSerifedMidline = 7 + fromEnum ConstantTrimmedMidline = 8 + fromEnum ConstantPointedMidline = 9 + fromEnum ConstantSerifedMidline = 10 + fromEnum LowTrimmedMidline = 11 + fromEnum LowPointedMidline = 12 + fromEnum LowSerifedMidline = 13 + toEnum 0 = AnyMidline + toEnum 1 = NoFitMidline + toEnum 2 = StandardTrimmedMidline + toEnum 3 = StandardPointedMidline + toEnum 4 = StandardSerifedMidline + toEnum 5 = HighTrimmedMidline + toEnum 6 = HighPointedMidline + toEnum 7 = HighSerifedMidline + toEnum 8 = ConstantTrimmedMidline + toEnum 9 = ConstantPointedMidline + toEnum 10 = ConstantSerifedMidline + toEnum 11 = LowTrimmedMidline + toEnum 12 = LowPointedMidline + toEnum 13 = LowSerifedMidline + toEnum _ = error "Unknown midline" data BXHeight = AnyXHeight @@ -1035,7 +1139,38 @@ data BXHeight | DuckingSmallXHeight | DuckingStandardXHeight | DuckingLargeXHeight - deriving (Eq, Show) + deriving Eq + +instance Show BXHeight + where + show AnyXHeight = "Any" + show NoFitXHeight = "No Fit" + show ConstantSmallXHeight = "Constant/Small" + show ConstantStandardXHeight = "Constant/Standard" + show ConstantLargeXHeight = "Constant/Large" + show DuckingSmallXHeight = "Ducking/Small" + show DuckingStandardXHeight = "Ducking/Standard" + show DuckingLargeXHeight = "Ducking/Large" + +instance Enum BXHeight + where + fromEnum AnyXHeight = 0 + fromEnum NoFitXHeight = 1 + fromEnum ConstantSmallXHeight = 2 + fromEnum ConstantStandardXHeight = 3 + fromEnum ConstantLargeXHeight = 4 + fromEnum DuckingSmallXHeight = 5 + fromEnum DuckingStandardXHeight = 6 + fromEnum DuckingLargeXHeight = 7 + toEnum 0 = AnyXHeight + toEnum 1 = NoFitXHeight + toEnum 2 = ConstantSmallXHeight + toEnum 3 = ConstantStandardXHeight + toEnum 4 = ConstantLargeXHeight + toEnum 5 = DuckingSmallXHeight + toEnum 6 = DuckingStandardXHeight + toEnum 7 = DuckingLargeXHeight + toEnum _ = error "Unknown X height" -- * Kern table