mirror of
https://github.com/rgleichman/glance.git
synced 2024-08-16 18:30:36 +03:00
Make a custom version of renderSVG that includes the xml:space=preserve attribute. This preveres whitespace in svg text.
This commit is contained in:
parent
7468166f14
commit
69589f7d24
13
app/Util.hs
13
app/Util.hs
@ -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(..))
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
||||
@ -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
|
||||
|
@ -7,6 +7,7 @@ import Diagrams.Prelude hiding ((#), (&))
|
||||
import Test.HUnit
|
||||
|
||||
import Icons(colorScheme, ColorStyle(..))
|
||||
import Util(customRenderSVG)
|
||||
|
||||
import UnitTests(allUnitTests)
|
||||
import VisualGraphAlgorithmTests(visualCollapseTests)
|
||||
@ -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"
|
||||
|
@ -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]
|
||||
|
2
todo.md
2
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..
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user