RXAAL 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. data/COPYING +674 -0
  2. data/README +0 -0
  3. data/RXAAL.gemspec +15 -0
  4. data/Rakefile +60 -0
  5. data/lib/angle.rb +9 -0
  6. data/lib/arc.rb +13 -0
  7. data/lib/arrow.rb +23 -0
  8. data/lib/attribute.rb +13 -0
  9. data/lib/bound_array.rb +56 -0
  10. data/lib/center.rb +7 -0
  11. data/lib/circle.rb +11 -0
  12. data/lib/circle_segment.rb +9 -0
  13. data/lib/contents.rb +7 -0
  14. data/lib/coordinate.rb +20 -0
  15. data/lib/core_ext/class.rb +17 -0
  16. data/lib/core_ext/module.rb +23 -0
  17. data/lib/core_ext/object.rb +7 -0
  18. data/lib/core_ext/string.rb +11 -0
  19. data/lib/ellipse.rb +8 -0
  20. data/lib/enum.rb +8 -0
  21. data/lib/enum/anchor.rb +16 -0
  22. data/lib/enum/color_name.rb +24 -0
  23. data/lib/enum/offset_mode.rb +9 -0
  24. data/lib/enum/stroke_type.rb +9 -0
  25. data/lib/enum/text_alignment.rb +9 -0
  26. data/lib/font.rb +25 -0
  27. data/lib/generic_color.rb +7 -0
  28. data/lib/graphic_prim.rb +25 -0
  29. data/lib/line.rb +9 -0
  30. data/lib/metadata.rb +78 -0
  31. data/lib/metadata_mod.rb +34 -0
  32. data/lib/named_color.rb +16 -0
  33. data/lib/node_prim.rb +15 -0
  34. data/lib/ns_container.rb +30 -0
  35. data/lib/offset.rb +63 -0
  36. data/lib/operation.rb +5 -0
  37. data/lib/par.rb +25 -0
  38. data/lib/par_container.rb +2 -0
  39. data/lib/point.rb +8 -0
  40. data/lib/polygon.rb +22 -0
  41. data/lib/polyline.rb +29 -0
  42. data/lib/privtest.rb +24 -0
  43. data/lib/r_xaal_error.rb +2 -0
  44. data/lib/r_xaal_object.rb +5 -0
  45. data/lib/radius.rb +5 -0
  46. data/lib/rectangle.rb +10 -0
  47. data/lib/rgb_color.rb +20 -0
  48. data/lib/rxaal.rb +28 -0
  49. data/lib/seq.rb +31 -0
  50. data/lib/serializable.rb +11 -0
  51. data/lib/shape.rb +5 -0
  52. data/lib/show_hide.rb +27 -0
  53. data/lib/square.rb +35 -0
  54. data/lib/stroke.rb +27 -0
  55. data/lib/style.rb +91 -0
  56. data/lib/style_container.rb +5 -0
  57. data/lib/style_mod.rb +63 -0
  58. data/lib/text.rb +34 -0
  59. data/lib/top_level_elem.rb +12 -0
  60. data/lib/triangle.rb +9 -0
  61. data/lib/xaal_doc.rb +93 -0
  62. data/lib/xaal_element.rb +77 -0
  63. data/lib/xaalns.rb +14 -0
  64. data/test/arrow_test.rb +43 -0
  65. data/test/attribute_test.rb +10 -0
  66. data/test/bound_array_test.rb +54 -0
  67. data/test/metadata_test.rb +35 -0
  68. data/test/module_test.rb +36 -0
  69. data/test/ns_container_test.rb +18 -0
  70. data/test/serializable_test.rb +19 -0
  71. data/test/style_test.rb +64 -0
  72. data/test/test_base.rb +19 -0
  73. data/test/xaal_element_test.rb +47 -0
  74. metadata +145 -0
@@ -0,0 +1,20 @@
1
+ require "generic_color"
2
+ module RXaal
3
+ class RGBColor < GenericColor
4
+ attr_accessor_of_class Integer, :r, :g, :b
5
+ def initialize(_r, _g, _b)
6
+ super
7
+ @r = _r
8
+ @g = _g
9
+ @b = _b
10
+ end
11
+
12
+ def xaal_serialize(parent)
13
+ elem = Element.new "color"
14
+ elem.attributes['r'] = r
15
+ elem.attributes['g'] = g
16
+ elem.attributes["b"] = b
17
+ parent.elements << elem
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ module RXaal
2
+ require "core_ext/module"
3
+ require "core_ext/string"
4
+ require "core_ext/object"
5
+ require "core_ext/class"
6
+ autoload :XaalNS, "xaalns"
7
+ autoload :Anchor, "enum/anchor"
8
+ autoload :ColorName, "enum/color_name"
9
+ autoload :OffsetMode, "enum/offset_mode"
10
+ autoload :StrokeType, "enum/stroke_type"
11
+ autoload :TextAlignment, "enum/text_alignment"
12
+ smrt_autoload :Angle, :Arc, :Arrow, :Attribute
13
+ smrt_autoload :BoundArray
14
+ smrt_autoload :Center, :CircleSegment, :Circle, :Coordinate
15
+ smrt_autoload :Ellipse, :Enum
16
+ smrt_autoload :Font
17
+ smrt_autoload :GenericColor, :GraphicPrim
18
+ smrt_autoload :Line
19
+ smrt_autoload :Metadata, :MetadataMod
20
+ smrt_autoload :NamedColor, :NodePrim, :NSContainer
21
+ smrt_autoload :Offset, :Operation
22
+ smrt_autoload :Par, :Point, :Polygon, :Polyline
23
+ smrt_autoload :RXaalError, :RXaalObject, :Radius, :Rectangle, :RGBColor
24
+ smrt_autoload :Seq, :Serializable, :Shape, :ShowHide, :Square, :Stroke, :StyleContainer,
25
+ :StyleMod, :Style
26
+ smrt_autoload :Text, :TopLevelElem, :Triangle
27
+ smrt_autoload :XaalDoc, :XaalElement
28
+ end
@@ -0,0 +1,31 @@
1
+ module RXaal
2
+ class Seq < TopLevelElem
3
+ attr_reader :pars
4
+ #narrative does not do type checking currently
5
+ attr_accessor :narrative
6
+
7
+ def initialize(doc)
8
+ super(doc)
9
+ @pars = BoundArray.new(Par)
10
+ end
11
+
12
+
13
+
14
+ def xaal_serialize(parent)
15
+ e = Element.new "seq"
16
+ parent.elements << e
17
+
18
+ if @narrative != nil
19
+ n = Element.new "narrative"
20
+ n.text=(@narrative)
21
+ e.elements << n
22
+ end
23
+
24
+ pars.each { |p|
25
+ p.xaal_serialize(e)
26
+ }
27
+
28
+ superclass_serialize(e)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ require "rexml/element"
2
+ module RXaal
3
+ module Serializable
4
+ include REXML
5
+ # serializes the current element in the REXML tree with parent as its
6
+ # parent element
7
+ def xaal_serialize(parent)
8
+ raise NotImplementedError, "must be overrriden"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module RXaal
2
+ class Shape < XaalElement
3
+
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+
2
+ module RXaal
3
+ class ShowHide < BoundArray
4
+ include Serializable
5
+
6
+
7
+ attr_reader :show
8
+ attr_accessor_of_class String, :type
9
+
10
+ def initialize(show)
11
+ super(XaalElement)
12
+ @show = show
13
+ end
14
+
15
+ def xaal_serialize(parent)
16
+ e_name = @show ? "show" : "hide"
17
+ e = Element.new e_name
18
+ parent.elements << e
19
+ e.attributes["type"] = @type
20
+ each { |obj|
21
+ t_obj = Element.new "object_ref"
22
+ t_obj.attributes["id"] = obj.id
23
+ e.elements << t_obj
24
+ }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ require 'rectangle'
2
+ module RXaal
3
+ class Square < Rectangle
4
+
5
+ def initialize
6
+ super
7
+ end
8
+
9
+ def coordinate
10
+ return self.coor1
11
+ end
12
+
13
+ def coordinate=(new_value)
14
+ self.coor1=(new_value)
15
+ end
16
+
17
+ private
18
+
19
+ def coor1
20
+ return super
21
+ end
22
+
23
+ def coor1=(n)
24
+ return super(n)
25
+ end
26
+
27
+ def coor2
28
+ return nil
29
+ end
30
+
31
+ def coor2=(n)
32
+ return nil
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ module RXaal
2
+ class Stroke < XaalElement
3
+ include Serializable
4
+
5
+ attr_accessor_of_class String, :type
6
+ attr_accessor_of_class Integer, :width
7
+
8
+ def initialize(doc, id = nil, elem_ns=nil)
9
+ super(doc, id, elem_ns)
10
+ end
11
+
12
+ def xaal_serialize(parent)
13
+ if (@type != nil || @width != nil)
14
+ e = REXML::Element.new "stroke"
15
+ parent.elements << e
16
+
17
+ if @type != nil
18
+ e.attributes["type"] = @type
19
+ end
20
+ if @width != nil
21
+ e.attributes["width"] = @width
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,91 @@
1
+ module RXaal
2
+ class Style < XaalElement
3
+ include StyleMod, Serializable
4
+ attr_accessor_of_class Style, :uses
5
+ style_attr_accessor_of_bool :forward_arrow, :backwards_arrow
6
+ attr_accessor :color, :fill_color
7
+ style_attr_accessor_of_class Font, :font
8
+ style_attr_accessor_of_class Stroke, :stroke
9
+
10
+ def initialize (doc, id = nil, uses_style = nil)
11
+ super(doc, id)
12
+ @uses = uses_style
13
+ end
14
+
15
+ def font_size
16
+ if font != nil
17
+ return font.size
18
+ end
19
+ return nil
20
+ end
21
+
22
+ def font_size=(_size)
23
+ if @font == nil
24
+ @font.new(@doc)
25
+ end
26
+
27
+ @font.size = _size
28
+ end
29
+
30
+ def font_family
31
+ if font != nil
32
+ return font.family
33
+ end
34
+ return nil
35
+ end
36
+
37
+ def font_family=(_fam)
38
+ if @font == nil
39
+ @font.new(@doc)
40
+ end
41
+
42
+ @font.family = _fam
43
+ end
44
+
45
+ def stroke_type
46
+ if stroke != nil
47
+ return stroke.type
48
+ end
49
+ return nil
50
+ end
51
+
52
+ def stroke_type=(_type)
53
+ if @stroke == nil
54
+ @stroke.new(@doc)
55
+ end
56
+
57
+ @stroke.type = _type
58
+ end
59
+
60
+ def stroke_width
61
+ if stroke != nil
62
+ return stroke.width
63
+ end
64
+ return nil
65
+ end
66
+
67
+ def stroke_width=(_width)
68
+ if @stroke == nil
69
+ @stroke.new(@doc)
70
+ end
71
+
72
+ @stroke.width = _width
73
+ end
74
+
75
+ # TODO: this doesn't really do anything with uses yet
76
+ def xaal_serialize(parent)
77
+ style = REXML::Element.new "style"
78
+ parent.elements << style
79
+
80
+ [:color, :fill_color, :font, :stroke].each { |c|
81
+ t = self.send(c)
82
+ if t != nil
83
+ t.xaal_serialize(style)
84
+ end
85
+
86
+ }
87
+
88
+ superclass_serialize(style)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,5 @@
1
+ class StyleContainer < Array
2
+
3
+
4
+
5
+ end
@@ -0,0 +1,63 @@
1
+ module RXaal
2
+ module StyleMod
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def style_attr_accessor(*symbols)
9
+ symbols.each { |s|
10
+
11
+ style_get(s)
12
+
13
+ define_method("#{s}=") do |val|
14
+ instance_variable_set("@#{s}", val)
15
+ end
16
+ }
17
+ end
18
+
19
+ def style_attr_accessor_of_class(klass, *symbols)
20
+ symbols.each { |s|
21
+ style_get(s)
22
+
23
+ define_method("#{s}=") do |val|
24
+ if val.class == klass
25
+ instance_variable_set("@#{s}", val)
26
+ end
27
+ end
28
+ }
29
+
30
+
31
+ end
32
+ def style_attr_accessor_of_bool( *symbols)
33
+ symbols.each { |s|
34
+ style_get(s)
35
+
36
+ define_method("#{s}=") do |val|
37
+ if val.class == TrueClass || val.class == FalseClass
38
+ instance_variable_set("@#{s}", val)
39
+ end
40
+ end
41
+ }
42
+
43
+
44
+ end
45
+
46
+ def style_get(s)
47
+ define_method(s) do
48
+ symb = instance_variable_get("@#{s}")
49
+ if symb != nil
50
+ symb
51
+ else
52
+ if self.uses != nil
53
+ self.uses.send(s)
54
+ else
55
+ nil
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,34 @@
1
+ module RXaal
2
+ class Text < NodePrim
3
+ attr_accessor_of_class Contents, :contents
4
+ attr_accessor_of_class String, :alignment
5
+ attr_accessor_of_class Integer
6
+ attr_accessor_of_boolean :boxed
7
+
8
+ def initialize
9
+ super
10
+ end
11
+
12
+
13
+ def xaal_serialize(parent)
14
+ text = Element.new "text"
15
+ parent.elements << text
16
+
17
+ if @alignment != nil
18
+ e_align = Element.new "alignment"
19
+ e_align.text = alignment
20
+ text << e_align
21
+ end
22
+
23
+ if @boxed != nil
24
+ e_boxed = Element.new "boxed"
25
+ e_boxed.text = boxed.to_s
26
+ end
27
+
28
+ contents.xaal_serialize(text)
29
+
30
+ superclass_serialize(text)
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,12 @@
1
+ module RXaal
2
+ class TopLevelElem < XaalElement
3
+
4
+ def initialize(doc, id = nil, elem_ns = nil)
5
+ super(doc, id, elem_ns)
6
+ end
7
+
8
+ def superclass_serialize(e)
9
+ super(e)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ require 'node_prim'
2
+ module RXaal
3
+ class Triangle < NodePrim
4
+
5
+ def initialize
6
+ super
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,93 @@
1
+ #This file is part of Foobar.
2
+ #
3
+ #Foobar is free software: you can redistribute it and/or modify
4
+ #it under the terms of the GNU General Public License as published by
5
+ #the Free Software Foundation, either version 3 of the License, or
6
+ #(at your option) any later version.
7
+ #
8
+ # Foobar is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with Foobar. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+
17
+
18
+ require 'rexml/document'
19
+ require 'rexml/xmldecl'
20
+
21
+ module RXaal
22
+ class XaalDoc
23
+ include Serializable
24
+ XAAL_NS_URI = "http://www.cs.hut.fi/Research/SVG/XAAL"
25
+ XSI_URI = "http://www.w3.org/2001/XMLSchema-instance"
26
+ XAAL_VERSION = "0.1"
27
+ attr_reader :xaal_version
28
+ attr_reader :namespaces
29
+ attr_reader :defs, :global_styles, :metadata
30
+ attr_reader :general_options
31
+ attr_reader :initials, :seqs
32
+
33
+ attr_reader :custom_top_level_elems
34
+
35
+
36
+ def initialize
37
+ @namespaces = NSContainer.new
38
+ @namespaces.add_ns(XAAL_NS_URI)
39
+ @namespaces.add_ns(XSI_URI, "xsi")
40
+ @top_level_elems = Array.new
41
+ @metadata = Metadata.new(self)
42
+ #self.styles = StyleContainer.new
43
+ @initials = Array.new
44
+ @seqs = Array.new
45
+ @custom_top_level_elems = BoundArray.new(TopLevelElem)
46
+ end
47
+
48
+ def add_option (name, value)
49
+ self.general_options[name] = value
50
+ end
51
+
52
+
53
+
54
+ def xaal_serialize(parent=nil)
55
+
56
+ doc = REXML::Document.new
57
+ doc << REXML::XMLDecl.default
58
+ root = REXML::Element.new "xaal"
59
+ doc.add(root)
60
+
61
+ self.namespaces.each { |ns|
62
+ pref = ns.prefix
63
+ url = ns.url
64
+ if (pref == "")
65
+ #its the default
66
+ root.add_namespace(url)
67
+ else
68
+ #its not
69
+ root.add_namespace(pref, url)
70
+ end
71
+ }
72
+ root.add_attribute('version', XAAL_VERSION)
73
+ root.add_attribute(@namespaces.uri_to_ns[XSI_URI].prefix << ":schemaLocation", "http://www.cs.hut.fi/Research/SVG/XAAL xaal.xsd")
74
+
75
+ self.metadata.xaal_serialize(root)
76
+ init = REXML::Element.new "initial"
77
+ root.elements << init
78
+
79
+ initials.each { |i|
80
+ i.xaal_serialize(init)
81
+ }
82
+ anim = REXML::Element.new "animation"
83
+ root.elements << anim
84
+ seqs.each { |s|
85
+ s.xaal_serialize(anim)
86
+ }
87
+ output_str = String.new
88
+ doc.write(output_str, 3)
89
+
90
+ return output_str
91
+ end
92
+ end
93
+ end