1 import "Simantics/Variables"
2 include "Simantics/Diagram/SVGNode"
4 import "http://www.simantics.org/Diagram-2.2" as DIA
5 import "http://www.simantics.org/G2D-1.1" as G2D
7 textFontValueAccessor =
9 (\self -> decodeFont self)
10 (\self binding -> decodeFont self)
11 (\self value -> encodeFont self value)
12 (\self value binding -> encodeFont self value)
15 decodeFont :: Variable -> <ReadGraph> String
17 element = represents $ parent $ parent self
18 match possibleObject element DIA.TextElement.font with
21 family = match possibleRelatedValue font G2D.HasFontFamily with
24 size = match possibleRelatedValue font G2D.HasFontSize with
27 style = match possibleObject font G2D.HasFontStyle with
28 Just G2D.FontStyle.normal_font_style -> "Normal"
29 Just G2D.FontStyle.bold_font_style -> "Bold"
30 Just G2D.FontStyle.italic_font_style -> "Italic"
31 Just G2D.FontStyle.bold_italic_style -> "BoldItalic"
33 family + "," + (show size) + "," + style
35 encodeFont :: Variable -> String -> <WriteGraph> ()
36 encodeFont self value = do
37 parts = split "," value
38 match length parts with
40 element = represents $ parent $ parent self
41 denyByPredicate element DIA.TextElement.font
44 size = read (parts!1) :: Integer
45 style = match parts!2 with
46 "Normal" -> G2D.FontStyle.normal_font_style
47 "Bold" -> G2D.FontStyle.bold_font_style
48 "Italic" -> G2D.FontStyle.italic_font_style
49 "BoldItalic" -> G2D.FontStyle.bold_italic_style
50 claim font L0.InstanceOf G2D.Font
51 claimRelatedValue font G2D.HasFontFamily (parts!0)
52 claimRelatedValue font G2D.HasFontSize size
53 claim font G2D.HasFontStyle style
54 claim element DIA.TextElement.font font