Skip to content

Commit

Permalink
Make a custom version of renderSVG that includes the xml:space=preser…
Browse files Browse the repository at this point in the history
…ve attribute. This preveres whitespace in svg text.
  • Loading branch information
rgleichman committed Jan 4, 2017
1 parent 7468166 commit 69589f7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
13 changes: 12 additions & 1 deletion app/Util.hs
Expand Up @@ -18,13 +18,18 @@ module Util (
maybeBoolToBool,
mapNodeInNamedNode,
sgNamedNodeToSyntaxNode,
nodeNameToInt
nodeNameToInt,
customRenderSVG
)where

import Diagrams.Backend.SVG(renderSVG', Options(..))
import Graphics.Svg.Attributes(bindAttr, AttrTag(..))

import Control.Arrow(first)
-- import Diagrams.Prelude(IsName, toName, Name)
import Data.Maybe(fromMaybe)
import qualified Debug.Trace
import Data.Text(pack)

import Types(EdgeEnd(..), Edge(..), NameAndPort(..), Connection, NodeName(..), Port,
SyntaxNode, SgNamedNode(..))
Expand Down Expand Up @@ -90,3 +95,9 @@ sgNamedNodeToSyntaxNode (SgNamedNode _ n) = n

nodeNameToInt :: NodeName -> Int
nodeNameToInt (NodeName x) = x

customRenderSVG outputFilename size = renderSVG' outputFilename svgOptions where
-- This xml:space attribute preserves the whitespace in the svg text.
attributes = [bindAttr XmlSpace_ (pack "preserve")]
-- TODO Look at the source of renderSVG to see what the 3rd argument to SVGOptions should be
svgOptions = SVGOptions size Nothing (pack "") attributes True
4 changes: 4 additions & 0 deletions glance.cabal
Expand Up @@ -37,6 +37,8 @@ executable glance-exe
, mtl
, semigroups
, diagrams-rasterific
, text
, svg-builder
default-language: Haskell2010
Other-modules: Icons, Rendering, Types, Util, Translate, TranslateCore, DrawingColors, GraphAlgorithms

Expand All @@ -58,6 +60,8 @@ test-suite glance-test
, haskell-src-exts
, mtl
, semigroups
, text
, svg-builder
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
Other-modules: Icons
Expand Down
3 changes: 2 additions & 1 deletion test/AllTests.hs
Expand Up @@ -7,6 +7,7 @@ import Diagrams.Prelude hiding ((#), (&))
import Test.HUnit

import Icons(colorScheme, ColorStyle(..))
import Util(customRenderSVG)

import UnitTests(allUnitTests)
import VisualGraphAlgorithmTests(visualCollapseTests)
Expand All @@ -26,7 +27,7 @@ renderDrawings = mapM_ saveDrawing where
saveDrawing (name, drawingMaker) = do
dia <- drawingMaker
-- TODO Replace string concatenation with proper path manipulation functions.
renderSVG ("test/test-output/" ++ name ++ ".svg") (mkWidth 700) (bgFrame 1 (backgroundC colorScheme) dia)
customRenderSVG ("test/test-output/" ++ name ++ ".svg") (mkWidth 700) (bgFrame 1 (backgroundC colorScheme) dia)

main :: IO ()
--main = print "Hello world"
Expand Down
4 changes: 3 additions & 1 deletion test/VisualTranslateTests.hs
Expand Up @@ -231,7 +231,9 @@ otherTests = [
"y = f (g x1 x2) x3",
"y = (f x1 x2) (g x1 x2)",
"y = Foo.bar",
"y x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 = f x1 x2 x3 x4 x5 x6 x7 x8 x9 x10"
"y x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 = f x1 x2 x3 x4 x5 x6 x7 x8 x9 x10",
-- test that whitespace is preserved
"y = \" foo bar baz \""
]

testDecls :: [String]
Expand Down
2 changes: 1 addition & 1 deletion todo.md
@@ -1,7 +1,7 @@
# Todo

## Todo Now
* Fix whitspace being stripped in comments.
* Use customRenderSVG in app/Main.hs.

* Add wiki pages discussing: Why a visual language?, Glance design goals, History of Glance, FAQ's, How to contribute, Code guide [code style, ...], Related projects, examples demonstrating the utility of Glance etc..

Expand Down

0 comments on commit 69589f7

Please sign in to comment.