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> author: Rhiannon Morris <rhi@rhiannon.website>
maintainer: Rhiannon Morris <rhi@rhiannon.website> maintainer: Rhiannon Morris <rhi@rhiannon.website>
executable laantas-script common base
hs-source-dirs: .
main-is: Main.hs
other-modules:
Svg,
Glyphs,
GlyphsBase,
Split
default-language: Haskell2010 default-language: Haskell2010
default-extensions: default-extensions:
BlockArguments, BlockArguments,
@ -37,5 +30,19 @@ executable laantas-script
optparse-applicative ^>= 0.16.0.0, optparse-applicative ^>= 0.16.0.0,
text ^>= 2.1, text ^>= 2.1,
megaparsec ^>= 9.6.1 megaparsec ^>= 9.6.1
ghc-options: ghc-options: -Wall
-Wall -threaded -rtsopts -with-rtsopts=-N
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 #-} {-# OPTIONS_GHC -Wno-missing-signatures -Wno-name-shadowing #-}
module Glyphs module Glyphs
(Glyph (..), Diacritic, simpleDia, Segs (..), EGlyph, Word, doGlyphs, (Glyph (..), Diacritic, simpleDia, Segs (..), EGlyph, Word,
doGlyphs, doGlyphsNoDoctype,
withSize, withSize,
charHeight', lineHeight', spaceWidth', gap', charHeight', lineHeight', spaceWidth', gap',
charHeight, lineHeight, spaceWidth, gap, charHeight, lineHeight, spaceWidth, gap,

View file

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