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