asciidiagram 1.1.1.1 → 1.2
raw patch · 5 files changed
+73/−23 lines, 5 filesdep ~rasterific-svgdep ~svg-tree
Dependency ranges changed: rasterific-svg, svg-tree
Files
- asciidiagram.cabal +4/−4
- changelog +6/−0
- exec-src/asciidiagram.hs +2/−2
- src/Text/AsciiDiagram.hs +36/−8
- src/Text/AsciiDiagram/SvgRender.hs +25/−9
asciidiagram.cabal view
@@ -1,7 +1,7 @@ -- Initial hitaa.cabal generated by cabal init. For further documentation, -- see http://haskell.org/cabal/users-guide/ name: asciidiagram-version: 1.1.1.1+version: 1.2 synopsis: Pretty rendering of Ascii diagram into svg or png. description: Asciidiagram Ascii art diagram like this:@@ -40,7 +40,7 @@ Source-Repository this Type: git Location: git://github.com/Twinside/asciidiagram.git- Tag: v1.1.1.1+ Tag: v1.2 library ghc-options: -O2 -Wall@@ -62,8 +62,8 @@ , containers >= 0.5 , mtl >= 2.1 && < 2.3 , lens >= 4.6 && < 5.0- , svg-tree >= 0.3 && < 0.4- , rasterific-svg >= 0.2.3 && < 0.3+ , svg-tree >= 0.4.1 && < 0.5+ , rasterific-svg >= 0.3 && < 0.4 , FontyFruity >= 0.5 && < 0.6 , JuicyPixels >= 3.2
changelog view
@@ -1,6 +1,12 @@ Change log ========== +v1.2 February 2016+------------------+ * Breaking change: DPI parameter on the rendering functions+ * Fix: exposing grid size+ * Fix: Bumped dependencies+ v1.1.1.1 May 2015 -----------------
exec-src/asciidiagram.hs view
@@ -112,13 +112,13 @@ savePdf diag = do cache <- getFontCache $ _verbose opt verbose . putStrLn $ "Writing PDF file " ++ _outputFile opt- pdf <- pdfOfDiagram cache 96 diag+ pdf <- pdfOfDiagram cache diag LB.writeFile (savingPath "pdf") pdf savePng diag = do cache <- getFontCache $ _verbose opt verbose . putStrLn $ "Writing PNG file " ++ _outputFile opt- img <- imageOfDiagram cache 96 diag+ img <- imageOfDiagram cache diag writePng (savingPath "png") img main :: IO ()
src/Text/AsciiDiagram.hs view
@@ -62,6 +62,15 @@ , imageOfDiagram , pdfOfDiagram + -- * Customized rendering+ , svgOfDiagramAtSize + , GridSize( .. )+ , defaultGridSize+ , saveAsciiDiagramAsSvgAtSize+ , imageOfDiagramAtSize+ , pdfOfDiagramAtSize++ -- * Document description , Diagram( .. ) , TextZone( .. )@@ -100,7 +109,7 @@ import Codec.Picture( Image, PixelRGBA8 ) import Graphics.Text.TrueType( FontCache )-import Graphics.Svg( Dpi, saveXmlFile )+import Graphics.Svg( saveXmlFile ) import Graphics.Rasterific.Svg( renderSvgDocument, pdfOfSvgDocument ) {-import Debug.Trace-}@@ -266,18 +275,37 @@ saveAsciiDiagramAsSvg fileName diagram = saveXmlFile fileName $ svgOfDiagram diagram --- | Render a Diagram as an image. a good value for the Dpi+-- | Helper function helping you save a diagram as+-- a SVG file on disk with a customized grid size.+saveAsciiDiagramAsSvgAtSize :: FilePath -> GridSize -> Diagram -> IO ()+saveAsciiDiagramAsSvgAtSize fileName gridSize =+ saveXmlFile fileName . svgOfDiagramAtSize gridSize++-- | Render a Diagram as an image. The Dpi -- is 96. The IO dependency is there to allow loading of the -- font files used in the document.-imageOfDiagram :: FontCache -> Dpi -> Diagram -> IO (Image PixelRGBA8)-imageOfDiagram cache dpi = - fmap fst . renderSvgDocument cache Nothing dpi . svgOfDiagram+imageOfDiagram :: FontCache -> Diagram -> IO (Image PixelRGBA8)+imageOfDiagram cache = + fmap fst . renderSvgDocument cache Nothing 96 . svgOfDiagram +-- | Render a Diagram as an image with a custom grid size. The Dpi+-- is 96. The IO dependency is there to allow loading of the+-- font files used in the document.+imageOfDiagramAtSize :: FontCache -> GridSize -> Diagram -> IO (Image PixelRGBA8)+imageOfDiagramAtSize cache gridSize =+ fmap fst . renderSvgDocument cache Nothing 96 . svgOfDiagramAtSize gridSize+ -- | Render a Diagram into a PDF file. IO dependency to allow -- loading of the font files used in the document.-pdfOfDiagram :: FontCache -> Dpi -> Diagram -> IO LB.ByteString-pdfOfDiagram cache dpi =- fmap fst . pdfOfSvgDocument cache Nothing dpi . svgOfDiagram+pdfOfDiagram :: FontCache -> Diagram -> IO LB.ByteString+pdfOfDiagram cache =+ fmap fst . pdfOfSvgDocument cache Nothing 96 . svgOfDiagram++-- | Render a Diagram into a PDF file with a custom grid size.+-- IO dependency to allow loading of the font files used in the document.+pdfOfDiagramAtSize :: FontCache -> GridSize -> Diagram -> IO LB.ByteString+pdfOfDiagramAtSize cache size =+ fmap fst . pdfOfSvgDocument cache Nothing 96 . svgOfDiagramAtSize size -- $linesdoc -- The basic syntax of asciidiagrams is made of lines made out\nof \'-\' and \'|\' characters. They can be connected with anchors\nlike \'+\' (direct connection) or \'\\\' and \'\/\' (smooth connections)\n
src/Text/AsciiDiagram/SvgRender.hs view
@@ -1,6 +1,10 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-}-module Text.AsciiDiagram.SvgRender( svgOfDiagram ) where+module Text.AsciiDiagram.SvgRender( GridSize( .. )+ , defaultGridSize+ , svgOfDiagram+ , svgOfDiagramAtSize+ ) where #if !MIN_VERSION_base(4,8,0) import Data.Monoid( mempty )@@ -38,13 +42,24 @@ {-import Debug.Trace-} {-import Text.Groom-} +-- | Simple type describing the grid size used during render. data GridSize = GridSize- { _gridCellWidth :: !Float- , _gridCellHeight :: !Float+ { _gridCellWidth :: !Float -- ^ Width of a cell (in pixel)+ , _gridCellHeight :: !Float -- ^ Height of a cell (in pixel)++ -- | Coefficient used to space adjacent shapes, set to 0+ -- if you want to remove space between them. , _gridShapeContraction :: !Float } deriving (Eq, Show) +-- | Default grid size used in the simple render functions+defaultGridSize :: GridSize+defaultGridSize = GridSize+ { _gridCellWidth = 10+ , _gridCellHeight = 14+ , _gridShapeContraction = 1.5+ } toSvg :: GridSize -> Point -> Svg.RPoint toSvg s (V2 x y) =@@ -457,7 +472,13 @@ -- | Transform an Ascii diagram to a SVG document which -- can be saved or converted to an image. svgOfDiagram :: Diagram -> Svg.Document-svgOfDiagram diagram = Document+svgOfDiagram = svgOfDiagramAtSize defaultGridSize where++-- | Transform an Ascii diagram to a SVG document which+-- can be saved or converted to an image, with a customizable+-- grid size.+svgOfDiagramAtSize :: GridSize -> Diagram -> Svg.Document+svgOfDiagramAtSize scale diagram = Document { _viewBox = Nothing , _width = toSvgSize _gridCellWidth $ _diagramCellWidth diagram + 1@@ -493,9 +514,4 @@ textSvg = textToTree scale <$> _diagramTexts diagram strokeScale = scale { _gridShapeContraction = 0 }- scale = GridSize- { _gridCellWidth = 10- , _gridCellHeight = 14- , _gridShapeContraction = 1.5- }