diff options
| author | Eugen Wissner <belka@caraus.de> | 2023-03-14 09:52:02 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2023-03-14 09:52:02 +0100 |
| commit | 929ab04c2cdaa2c2296a2bf64582981fed52eb8e (patch) | |
| tree | eab7008d128ea82816ce6d2c83797376bd3f2349 /app | |
| parent | dd5d0701126ccfa178e0257d01806cc78cf18a33 (diff) | |
| download | fountainhead-929ab04c2cdaa2c2296a2bf64582981fed52eb8e.tar.gz | |
Add a test program
Diffstat (limited to 'app')
| -rw-r--r-- | app/Main.hs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..24e7a32 --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,46 @@ +module Main + ( main + ) where + +import qualified Data.ByteString as ByteString +import Data.ByteString (ByteString) +import qualified Text.Megaparsec as Megaparsec +import Data.Foldable (find) +-- TODO: kern table since format 1. +-- For details on subtable format see examples in TrueType reference. +import Graphics.Fountainhead.Parser + ( fontDirectoryP + , os2TableP + , parseTable + , shortLocaTableP + ) +import Graphics.Fountainhead.TrueType (FontDirectory(..), TableDirectory(..)) +import System.Environment (getArgs) + +fontMain :: IO () +fontMain = do + fontFile <- head <$> getArgs + ttfContents <- ByteString.readFile fontFile + + let initialState = Megaparsec.State + { stateInput = ttfContents + , stateOffset = 0 + , statePosState = Megaparsec.PosState + { pstateInput = ttfContents + , pstateOffset = 0 + , pstateSourcePos = Megaparsec.initialPos fontFile + , pstateTabWidth = Megaparsec.defaultTabWidth + , pstateLinePrefix = "" + } + , stateParseErrors = [] + } + (processedState, Right directory) = Megaparsec.runParser' fontDirectoryP initialState + print directory + 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 + +main :: IO () +main = fontMain |
