Add a test program

This commit is contained in:
Eugen Wissner 2023-03-14 09:52:02 +01:00
parent dd5d070112
commit 929ab04c2c
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
3 changed files with 76 additions and 1 deletions

View File

@ -1 +1,6 @@
TrueType font parser. # TrueType font parser.
An experiment to create a TrueType and OpenType font parser and encoder
that can be used to embed fonts in PDF.
This project is currently only a draft.

46
app/Main.hs Normal file
View File

@ -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

View File

@ -35,3 +35,27 @@ library
megaparsec ^>= 9.3, megaparsec ^>= 9.3,
time ^>= 1.12, time ^>= 1.12,
vector ^>= 0.13.0 vector ^>= 0.13.0
executable fountainhead
main-is: Main.hs
default-extensions:
OverloadedStrings
NamedFieldPuns
DataKinds
DuplicateRecordFields
ExplicitForAll
TypeApplications
build-depends:
base,
bytestring,
containers,
parser-combinators,
vector,
transformers,
text,
time,
megaparsec,
fountainhead
hs-source-dirs: app
default-language: Haskell2010