1 import "Simantics/Variables"
3 import "http://www.simantics.org/Diagram-2.2" as DIA
4 import "http://www.simantics.org/G2D-1.1" as G2D
6 textFontValueAccessor =
8 (\self -> decodeFont self)
9 (\self binding -> decodeFont self)
10 (\self value -> encodeFont self value)
11 (\self value binding -> encodeFont self value)
14 decodeFont :: Variable -> <ReadGraph> String
16 element = represents $ parent $ parent self
17 match possibleObject element DIA.TextElement.font with
20 family = match possibleRelatedValue font G2D.HasFontFamily with
23 size = match possibleRelatedValue font G2D.HasFontSize with
26 style = match possibleObject font G2D.HasFontStyle with
27 Just G2D.FontStyle.normal_font_style -> "Normal"
28 Just G2D.FontStyle.bold_font_style -> "Bold"
29 Just G2D.FontStyle.italic_font_style -> "Italic"
30 Just G2D.FontStyle.bold_italic_style -> "BoldItalic"
32 family + "," + (show size) + "," + style
34 encodeFont :: Variable -> String -> <WriteGraph> ()
35 encodeFont self value = do
36 parts = split "," value
37 match length parts with
39 element = represents $ parent $ parent self
40 denyByPredicate element DIA.TextElement.font
43 size = read (parts!1) :: Integer
44 style = match parts!2 with
45 "Normal" -> G2D.FontStyle.normal_font_style
46 "Bold" -> G2D.FontStyle.bold_font_style
47 "Italic" -> G2D.FontStyle.italic_font_style
48 "BoldItalic" -> G2D.FontStyle.bold_italic_style
49 claim font L0.InstanceOf G2D.Font
50 claimRelatedValue font G2D.HasFontFamily (parts!0)
51 claimRelatedValue font G2D.HasFontSize size
52 claim font G2D.HasFontStyle style
53 claim element DIA.TextElement.font font