diff options
| author | Eugen Wissner <belka@caraus.de> | 2023-11-11 10:57:43 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2023-11-11 10:57:43 +0100 |
| commit | 1d4efb44bba9dc3dec416399554c3965f3dd628f (patch) | |
| tree | 1f0cc1012d666a1ca5305ab6309219dc4d2224e8 /app | |
| parent | 16f9dc70d181ba419ca1b9c02e8c367cafac3268 (diff) | |
| download | fountainhead-1d4efb44bba9dc3dec416399554c3965f3dd628f.tar.gz | |
Move ttf dumper to a module
Diffstat (limited to 'app')
| -rw-r--r-- | app/Main.hs | 45 |
1 files changed, 7 insertions, 38 deletions
diff --git a/app/Main.hs b/app/Main.hs index aee0fd4..89a8dcd 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -15,6 +15,7 @@ import qualified Data.Text.Lazy as Text.Lazy import qualified Data.Text.Lazy.IO as Text.Lazy import qualified Data.Text.Encoding as Text import GHC.Records (HasField(..)) +import Graphics.Fountainhead.Dumper (dumpTrueType) -- TODO: kern table since format 1. -- For details on subtable format see examples in TrueType reference. import Graphics.Fountainhead.Parser @@ -50,49 +51,17 @@ fontMain fontFile = do } , stateParseErrors = [] } - (processedState, Right directory) = Megaparsec.runParser' fontDirectoryP initialState - - Text.Lazy.putStrLn $ Text.Builder.toLazyText $ dumpOffsetTable directory - {- print directory + (processedState, initialResult) = Megaparsec.runParser' fontDirectoryP initialState + + case initialResult >>= dumpTrueType processedState of + (Right fontDump) -> Text.Lazy.putStrLn $ Text.Builder.toLazyText fontDump + Left e -> putStr (Megaparsec.errorBundlePretty e) + {- let Just tableDirectory' = find (("OS/2" ==) . tag) $ tableDirectory directory tableResult = parseTable tableDirectory' os2TableP processedState case tableResult of - Left e -> putStr (Megaparsec.errorBundlePretty e) Right x -> print x -} -paddedHexadecimal :: Integral a => a -> Text.Builder.Builder -paddedHexadecimal = ("0x" <>) - . Text.Builder.fromLazyText - . Text.Lazy.justifyRight 8 '0' - . Text.Builder.toLazyText - . Text.Builder.hexadecimal - -justifyNumber :: Integral a => Int64 -> a -> Text.Builder.Builder -justifyNumber count = Text.Builder.fromLazyText - . Text.Lazy.justifyRight count ' ' - . Text.Builder.toLazyText - . Text.Builder.decimal - -dumpOffsetTable :: FontDirectory -> Text.Builder.Builder -dumpOffsetTable directory - = "Offset Table\n------------\n" - <> " sfnt version: 1.0\n number of tables: " - <> Text.Builder.decimal (numTables $ offsetSubtable directory) - <> Text.Builder.singleton '\n' - <> dumpOffsetSummary (tableDirectory directory) - where - dumpOffsetSummary = mconcat . fmap dumpOffsetRow . zip [0..] - dumpOffsetRow (index, table) = justifyNumber 4 index - <> ". '" - <> Text.Builder.fromText (Text.decodeASCII $ tag table) - <> "' - checksum = " - <> paddedHexadecimal (getField @"checkSum" table) - <> ", offset = " - <> paddedHexadecimal (getField @"offset" table) - <> ", len = " - <> justifyNumber 9 (getField @"length" table) - <> Text.Builder.singleton '\n' - main :: IO () main = do programArguments <- getArgs |
