diff options
Diffstat (limited to 'lib/Graphics/Fountainhead/Parser.hs')
| -rw-r--r-- | lib/Graphics/Fountainhead/Parser.hs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/Graphics/Fountainhead/Parser.hs b/lib/Graphics/Fountainhead/Parser.hs index 672f9fc..5c437d6 100644 --- a/lib/Graphics/Fountainhead/Parser.hs +++ b/lib/Graphics/Fountainhead/Parser.hs @@ -33,6 +33,7 @@ module Graphics.Fountainhead.Parser , nameTableP , os2TableP , panoseP + , parseFontDirectory , parseTable , pascalStringP , postTableP @@ -157,6 +158,29 @@ type Parser = Megaparsec.Parsec Void ByteString type ParseErrorBundle = Megaparsec.ParseErrorBundle ByteString Void type ParseState = Megaparsec.State ByteString Void +-- | Does initial parsing and returns the font directory and parsing state +-- that can be used to parse other tables in the font. +-- +-- Font file name can be empty. +parseFontDirectory + :: FilePath + -> ByteString + -> (ParseState, Either ParseErrorBundle FontDirectory) +parseFontDirectory fontFile ttfContents = + let initialState = Megaparsec.State + { stateInput = ttfContents + , stateOffset = 0 + , statePosState = Megaparsec.PosState + { pstateInput = ttfContents + , pstateOffset = 0 + , pstateSourcePos = Megaparsec.initialPos fontFile + , pstateTabWidth = Megaparsec.defaultTabWidth + , pstateLinePrefix = "" + } + , stateParseErrors = [] + } + in Megaparsec.runParser' fontDirectoryP initialState + -- * Font directory offsetSubtableP :: Parser OffsetSubtable |
