Extract some convenience parsing functions
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user