Dump maxp table

This commit is contained in:
Eugen Wissner 2023-11-20 09:33:04 +01:00
parent cda2a2a446
commit af16ee7b8e

View File

@ -16,6 +16,7 @@ module Graphics.Fountainhead.Dumper
, dumpHmtx
, dumpHhea
, dumpLoca
, dumpMaxp
, dumpTrueType
, dumpOffsetTable
) where
@ -49,6 +50,9 @@ import Graphics.Fountainhead.TrueType
, LongHorMetric(..)
, LocaTable(..)
, IndexToLocFormat(..)
, OpenMaxpTable(..)
, MaxpTable(..)
, TrueMaxpTable(..)
)
import qualified Text.Megaparsec as Megaparsec
import Graphics.Fountainhead.Parser
@ -59,6 +63,7 @@ import Graphics.Fountainhead.Parser
, hheaTableP
, hmtxTableP
, locaTableP
, maxpTableP
)
import Graphics.Fountainhead.Type (Fixed32(..), ttfEpoch)
import Data.Foldable (Foldable(..), find)
@ -330,13 +335,36 @@ dumpLoca table =
case Vector.unsnoc elements of
Just (init', last')
-> foldMap dumpLocaLine (Vector.indexed init')
<> " Ended at " <> paddedHexadecimal last'
<> " Ended at " <> paddedHexadecimal last' <> newlineBuilder
Nothing -> mempty
dumpLocaLine :: Integral a => (Int, a) -> Text.Builder.Builder
dumpLocaLine (index, element)
= " Idx " <> justifyNumber 6 index
<> " -> GlyphOffset " <> paddedHexadecimal element <> newlineBuilder
dumpMaxp :: MaxpTable -> Text.Builder.Builder
dumpMaxp (TrueMaxp TrueMaxpTable{..})
= dumpCaption "'maxp' Table - Maximum Profile"
<> " 'maxp' version: " <> dumpFixed32 version <> newlineBuilder
<> " numGlyphs: " <> Text.Builder.decimal numGlyphs <> newlineBuilder
<> " maxPoints: " <> Text.Builder.decimal maxPoints <> newlineBuilder
<> " maxContours: " <> Text.Builder.decimal maxContours <> newlineBuilder
<> " maxCompositePoints: " <> Text.Builder.decimal maxComponentPoints <> newlineBuilder
<> " maxCompositeContours: " <> Text.Builder.decimal maxComponentContours <> newlineBuilder
<> " maxZones: " <> Text.Builder.decimal maxZones <> newlineBuilder
<> " maxTwilightPoints: " <> Text.Builder.decimal maxTwilightPoints <> newlineBuilder
<> " maxStorage: " <> Text.Builder.decimal maxStorage <> newlineBuilder
<> " maxFunctionDefs: " <> Text.Builder.decimal maxFunctionDefs <> newlineBuilder
<> " maxInstructionDefs: " <> Text.Builder.decimal maxInstructionDefs <> newlineBuilder
<> " maxStackElements: " <> Text.Builder.decimal maxStackElements <> newlineBuilder
<> " maxSizeOfInstructions: " <> Text.Builder.decimal maxSizeOfInstructions <> newlineBuilder
<> " maxComponentElements: " <> Text.Builder.decimal maxComponentElements <> newlineBuilder
<> " maxCompoenetDepth: " <> Text.Builder.decimal maxComponentDepth <> newlineBuilder
dumpMaxp (OpenMaxp OpenMaxpTable{..})
= dumpCaption "'maxp' Table - Maximum Profile"
<> " 'maxp' version: " <> dumpFixed32 version <> newlineBuilder <> newlineBuilder
<> " numGlyphs: " <> Text.Builder.decimal numGlyphs <> newlineBuilder
dumpTables
:: Megaparsec.State ByteString Void
-> FontDirectory
@ -370,6 +398,7 @@ dumpTables processedState directory@FontDirectory{..}
<$> parseTable tableEntry (hmtxTableP $ getField @"numOfLongHorMetrics" hheaTable) processedState
"loca" -> Just $ dumpLoca
<$> parseTable tableEntry (locaTableP $ getField @"indexToLocFormat" headTable) processedState
"maxp" -> Just $ dumpMaxp <$> parseTable tableEntry maxpTableP processedState
_ -> Nothing
dumpTrueType :: ByteString -> FilePath -> Either DumpError Text.Builder.Builder