]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/scl/Simantics/Diagram/Internal/DiagramOntologyEntryPoint.scl
Font property for DIA.TextElement
[simantics/platform.git] / bundles / org.simantics.diagram / scl / Simantics / Diagram / Internal / DiagramOntologyEntryPoint.scl
1 import "Simantics/Variables"
2
3 import "http://www.simantics.org/Diagram-2.2" as DIA
4 import "http://www.simantics.org/G2D-1.1" as G2D
5
6 textFontValueAccessor =
7   createValueAccessor
8     (\self -> decodeFont self)
9     (\self binding -> decodeFont self)
10     (\self value -> encodeFont self value)
11     (\self value binding -> encodeFont self value)
12     standardGetDatatype
13   
14 decodeFont :: Variable -> <ReadGraph> String
15 decodeFont self = do
16   element = represents $ parent $ parent self
17   match possibleObject element DIA.TextElement.font with
18     Nothing -> ""
19     Just font -> do
20       family = match possibleRelatedValue font G2D.HasFontFamily with
21         Nothing -> "Arial"
22         Just f -> f
23       size = match possibleRelatedValue font G2D.HasFontSize with
24         Nothing -> 12
25         Just s -> s
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"
31         Nothing -> "Normal"
32       family + "," + (show size) + "," + style
33
34 encodeFont :: Variable -> String -> <WriteGraph> ()
35 encodeFont self value = do
36   parts = split "," value
37   match length parts with
38     3 -> do
39       element = represents $ parent $ parent self
40       denyByPredicate element DIA.TextElement.font
41       font = newResource ()
42       family = parts!0
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
54   ()