From 3160ceab080fca8fef0cf2cf196b46284d15c19f Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 4 Feb 2024 11:07:15 +0100 Subject: Create a Metrics module --- src/Main.hs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/Main.hs (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs new file mode 100644 index 0000000..a87bf85 --- /dev/null +++ b/src/Main.hs @@ -0,0 +1,53 @@ +module Main + ( main + ) where + +import qualified Data.Text.Lazy.Builder as Text.Builder +import qualified Data.Text.Lazy.IO as Text.Lazy +import Graphics.Fountainhead (dumpFontFile) +import System.Exit (exitWith) +import GHC.IO.Exception (ExitCode(..)) +import Options.Applicative + ( Parser + , ParserInfo(..) + , (<**>) + , argument + , command + , execParser + , helper + , info + , fullDesc + , metavar + , progDesc + , str + , subparser + ) + +data Operation + = Dump + | Afm + deriving (Eq, Show) + +data Options = Options Operation FilePath + deriving (Eq, Show) + +operationOptions :: ParserInfo Options +operationOptions = info (options <**> helper) fullDesc + where + options = Options + <$> commands + <*> argument str (metavar "FONTFILE") + commands = subparser + $ command "dump" (info (pure Dump) (progDesc "Dumping the contents of a TrueType Font file.")) + <> command "afm" (info (pure Afm) (progDesc "Generating Adobe Font Metrics files for TrueType fonts.")) + +main :: IO () +main = execParser operationOptions >>= handleArguments + where + handleArguments (Options Dump fontFile) + = putStrLn ("Dumping File:" <> fontFile <> "\n\n") + >> dumpFontFile fontFile + >>= either print (Text.Lazy.putStrLn . Text.Builder.toLazyText) + handleArguments (Options Afm _) + = putStrLn "The program expects exactly one argument, the font file path." + >> exitWith (ExitFailure 2) -- cgit v1.2.3