make laantas-script usable as a library

This commit is contained in:
Rhiannon Morris 2024-11-28 00:18:31 +01:00
parent fe209a8aca
commit 3911f5052b
6 changed files with 25 additions and 14 deletions

View file

@ -7,14 +7,7 @@ license: AGPL-3.0-or-later
author: Rhiannon Morris <rhi@rhiannon.website>
maintainer: Rhiannon Morris <rhi@rhiannon.website>
executable laantas-script
hs-source-dirs: .
main-is: Main.hs
other-modules:
Svg,
Glyphs,
GlyphsBase,
Split
common base
default-language: Haskell2010
default-extensions:
BlockArguments,
@ -37,5 +30,19 @@ executable laantas-script
optparse-applicative ^>= 0.16.0.0,
text ^>= 2.1,
megaparsec ^>= 9.6.1
ghc-options:
-Wall -threaded -rtsopts -with-rtsopts=-N
ghc-options: -Wall
library
import: base
hs-source-dirs: lib
exposed-modules:
Svg,
Glyphs,
GlyphsBase,
Split
executable laantas-script
import: base
hs-source-dirs: main
main-is: Main.hs
build-depends: laantas-script

View file

@ -1,7 +1,8 @@
{-# OPTIONS_GHC -Wno-missing-signatures -Wno-name-shadowing #-}
module Glyphs
(Glyph (..), Diacritic, simpleDia, Segs (..), EGlyph, Word, doGlyphs,
(Glyph (..), Diacritic, simpleDia, Segs (..), EGlyph, Word,
doGlyphs, doGlyphsNoDoctype,
withSize,
charHeight', lineHeight', spaceWidth', gap',
charHeight, lineHeight, spaceWidth, gap,

View file

@ -94,8 +94,8 @@ type Diacritic = Diacritic' Double
simpleDia :: Segs -> Diacritic
simpleDia ss (SI {width}) = (ss, width)
doGlyphs :: [Word] -> Env -> Element
doGlyphs gs e = wrap $ run act e where
doGlyphsNoDoctype :: [Word] -> Env -> Element
doGlyphsNoDoctype gs e = wrap $ run act e where
act = do
E {stroke, color} <- ask
let gattrs = [Stroke_ <<- color, Stroke_width_ <<- toPx stroke,
@ -104,7 +104,10 @@ doGlyphs gs e = wrap $ run act e where
g_ gattrs . mconcat <$> traverse placeWord gs <* newline
wrap (content, T {width, height}) =
let sattrs = [Height_ <<- toPx height, Width_ <<- toPx width] in
doctype <> svg11_ content `with` sattrs
svg11_ content `with` sattrs
doGlyphs :: [Word] -> Env -> Element
doGlyphs gs e = doctype <> doGlyphsNoDoctype gs e
liftDia :: Diacritic -> Diacritic' SizeInfo