import "Simantics/Variables" include "Simantics/Diagram/SVGNode" import "http://www.simantics.org/Diagram-2.2" as DIA import "http://www.simantics.org/G2D-1.1" as G2D textFontValueAccessor = createValueAccessor (\self -> decodeFont self) (\self binding -> decodeFont self) (\self value -> encodeFont self value) (\self value binding -> encodeFont self value) standardGetDatatype decodeFont :: Variable -> String decodeFont self = do element = represents $ parent $ parent self match possibleObject element DIA.TextElement.font with Nothing -> "" Just font -> do family = match possibleRelatedValue font G2D.HasFontFamily with Nothing -> "Arial" Just f -> f size = match possibleRelatedValue font G2D.HasFontSize with Nothing -> 12 Just s -> s style = match possibleObject font G2D.HasFontStyle with Just G2D.FontStyle.normal_font_style -> "Normal" Just G2D.FontStyle.bold_font_style -> "Bold" Just G2D.FontStyle.italic_font_style -> "Italic" Just G2D.FontStyle.bold_italic_style -> "BoldItalic" Nothing -> "Normal" family + "," + (show size) + "," + style encodeFont :: Variable -> String -> () encodeFont self value = do parts = split "," value match length parts with 3 -> do element = represents $ parent $ parent self denyByPredicate element DIA.TextElement.font font = newResource () family = parts!0 size = read (parts!1) :: Integer style = match parts!2 with "Normal" -> G2D.FontStyle.normal_font_style "Bold" -> G2D.FontStyle.bold_font_style "Italic" -> G2D.FontStyle.italic_font_style "BoldItalic" -> G2D.FontStyle.bold_italic_style claim font L0.InstanceOf G2D.Font claimRelatedValue font G2D.HasFontFamily (parts!0) claimRelatedValue font G2D.HasFontSize size claim font G2D.HasFontStyle style claim element DIA.TextElement.font font ()