~ubuntu-branches/ubuntu/wily/ctioga2/wily

« back to all changes in this revision

Viewing changes to lib/ctioga2/graphics/styles/texts.rb

  • Committer: Package Import Robot
  • Author(s): Vincent Fourmond
  • Date: 2013-07-08 20:58:17 UTC
  • mfrom: (6.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130708205817-cephnc6etndyxrrp
Tags: 0.4-2
* Upload to unstable
* Already conforms to newer standards

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# This module contains all the classes used by ctioga
18
18
module CTioga2
19
19
 
20
 
  Version::register_svn_info('$Revision: 197 $', '$Date: 2010-11-29 14:26:12 +0100 (Mon, 29 Nov 2010) $')
 
20
  Version::register_svn_info('$Revision: 370 $', '$Date: 2012-12-28 17:40:18 +0100 (Fri, 28 Dec 2012) $')
21
21
 
22
22
  module Graphics
23
23
 
26
26
      # The style of a text object. This class is suitable for
27
27
      # inclusion as a Hash to FigureMaker#show_axis, for the tick
28
28
      # labels.
 
29
      #
 
30
      # @todo alignement and justification are poor names. halign
 
31
      # and/or valign would be better.
29
32
      class BaseTextStyle < BasicStyle
30
33
        
31
34
        # The angle of the text
32
 
        attr_accessor :angle
 
35
        typed_attribute :angle, 'float'
33
36
 
34
37
        # The 'shift' of the text. Only meaningful for axes and tick
35
38
        # labels, where the position of the text is specified using a
36
 
        # side rather than a precise position
37
 
        attr_accessor :shift
 
39
        # side rather than a precise position. In frame coordinates ?
 
40
        typed_attribute :shift, 'float'
38
41
 
39
42
        # The scale of the text
40
 
        attr_accessor :scale
 
43
        typed_attribute :scale, 'float'
41
44
 
42
45
        # The vertical alignment 
43
 
        attr_accessor :alignement
 
46
        typed_attribute :alignment, 'alignment'
44
47
 
45
48
        # The horizontal alignment
46
 
        attr_accessor :justification
 
49
        typed_attribute :justification, 'justification'
47
50
 
48
51
        # Draw the _text_ at the given location with the given style.
49
52
        # If _y_ is _nil_, then _x_or_loc_ is taken to be a location
50
53
        # (see FigureMaker#show_text).
51
54
        def draw_text(t, text, x_or_loc, y = nil, measure = nil)
52
 
          dict = prepare_show_text_dict(text, x_or_loc, y, measure)
53
 
          t.show_text(dict)
 
55
          t.context do
 
56
            dict = prepare_show_text_dict(text, x_or_loc, y, measure)
 
57
            t.show_text(dict)
 
58
          end
54
59
        end
55
60
 
56
61
        protected
83
88
      # The style of a full text object.
84
89
      class FullTextStyle < BaseTextStyle
85
90
        # The color of the text
86
 
        attr_accessor :color
 
91
        typed_attribute :color, 'color'
87
92
 
88
93
        # The (horizontal) position with respect to a location. You'll
89
94
        # seldom need that.
90
 
        attr_accessor :position
 
95
        #
 
96
        # @todo Maybe this needs to fo in TextLabel rather than here ?
 
97
        typed_attribute :position, 'float'
91
98
      end
92
99
 
93
100
      # A hash that can be used as a base for optional arguments to
94
101
      # things that take texts.
95
 
      FullTextStyleOptions = {
96
 
        'angle' => CmdArg.new('float'),
97
 
        'shift' => CmdArg.new('float'),
98
 
        'scale' => CmdArg.new('float'),
99
 
        'justification' => CmdArg.new('justification'),
100
 
        'color' => CmdArg.new('color'),
101
 
        'align' => CmdArg.new('alignment'),
102
 
      }
 
102
      FullTextStyleOptions = FullTextStyle.options_hash()
103
103
 
104
104
      # A label.
105
105
      class TextLabel < FullTextStyle
106
106
        # The text of the label. _nil_ or _false_ means there will be
107
107
        # no text displayed
108
 
        attr_accessor :text
 
108
        typed_attribute :text, "text"
109
109
        
110
110
        # The location of the label.
111
111
        #
112
112
        # @todo This will have to eventually use PlotLocation, as it
113
113
        # makes much more sense.
114
 
        attr_accessor :loc
 
114
        typed_attribute :loc, "location"
115
115
 
116
 
        def initialize(text = nil)
 
116
        def initialize(text = nil, loc = nil)
 
117
          super()
117
118
          @text = text
 
119
          @loc = loc
118
120
        end
119
121
        
120
122
        # Draw the label, if #text is not _nil_ or _false_.
159
161
 
160
162
      end
161
163
 
162
 
      # Same thing as FullTextStyleOptions, but also permits to
163
 
      # override the #text part of the whole stuff..
164
 
      FullTextLabelOptions = FullTextStyleOptions.dup
165
 
      FullTextLabelOptions['text'] = CmdArg.new('text')
 
164
 
 
165
      FullTextLabelOptions = TextLabel.options_hash()
166
166
 
167
167
 
168
168
 
171
171
      # like that.
172
172
      class MarkerStringStyle < BasicStyle
173
173
        
174
 
        MarkerOptions = {
175
 
          'color' => 'color',
176
 
          'stroke_color' => 'color',
177
 
          'fill_color' => 'color',
178
 
          'scale' => 'float',
179
 
          'horizontal_scale' => 'float',
180
 
          'vertical_scale' => 'float',
181
 
          'angle' => 'float',
182
 
          'justification' => 'justification',
183
 
          'alignment' => 'alignment',
184
 
        }
185
 
 
186
 
 
187
174
        # The angle of the text
188
 
        attr_accessor :angle
 
175
        typed_attribute :angle, 'float'
189
176
 
190
177
        # The scale of the text
191
 
        attr_accessor :scale
 
178
        typed_attribute :scale, "float"
192
179
 
193
180
        # The horizontal scale of the text
194
 
        attr_accessor :horizontal_scale
 
181
        typed_attribute :horizontal_scale, "float"
195
182
 
196
183
        # The vertical scale of the text
197
 
        attr_accessor :vertical_scale
 
184
        typed_attribute :vertical_scale, "float"
198
185
 
199
186
        # The vertical alignment 
200
 
        attr_accessor :alignement
 
187
        typed_attribute :alignment, "alignment"
201
188
 
202
189
        # The horizontal alignment
203
 
        attr_accessor :justification
 
190
        typed_attribute :justification, "justification"
204
191
 
205
192
        # Colors
206
 
        attr_accessor :color
207
 
        attr_accessor :stroke_color
208
 
        attr_accessor :fill_color
 
193
        typed_attribute :color, 'color-or-false'
 
194
        typed_attribute :stroke_color, 'color-or-false'
 
195
        typed_attribute :fill_color, 'color-or-false'
 
196
 
209
197
 
210
198
        # A number between 1 to 14 -- a PDF font
211
 
        attr_accessor :font
 
199
        typed_attribute :font, "pdf-font"
212
200
 
213
201
        # The rendering mode.
214
202
        attr_accessor :mode
226
214
          dict = self.to_hash
227
215
          dict['text'] = text
228
216
          dict['at'] = [x, y]
229
 
          # TODO !
230
 
          dict['mode'] = 
 
217
          t.show_marker(dict)
 
218
        end
 
219
 
 
220
        # Draws the string marker at the given location
 
221
        def draw_marker(t, marker, x, y)
 
222
          dict = self.to_hash
 
223
          dict['marker'] = marker
 
224
          dict['at'] = [x, y]
231
225
          t.show_marker(dict)
232
226
        end
233
227
 
237
231
        end
238
232
      end
239
233
      
240
 
      StringMarkerOptions = {
241
 
        'color' => CmdArg.new('color'),
242
 
        'stroke_color' => CmdArg.new('color'),
243
 
        'fill_color' => CmdArg.new('color'),
244
 
        'scale' => CmdArg.new('float'),
245
 
        'horizontal_scale' => CmdArg.new('float'),
246
 
        'vertical_scale' => CmdArg.new('float'),
247
 
        'angle' => CmdArg.new('float'),
248
 
        'justification' => CmdArg.new('justification'),
249
 
        'alignment' => CmdArg.new('alignment'),
250
 
        'font' => CmdArg.new('pdf-font')
251
 
      }
252
 
 
253
234
      # A LaTeX font. It should be applied to text using the function
254
235
      # #fontify.
255
236
      #