17
17
# This module contains all the classes used by ctioga
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) $')
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
30
# @todo alignement and justification are poor names. halign
31
# and/or valign would be better.
29
32
class BaseTextStyle < BasicStyle
31
34
# The angle of the text
35
typed_attribute :angle, 'float'
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
39
# side rather than a precise position. In frame coordinates ?
40
typed_attribute :shift, 'float'
39
42
# The scale of the text
43
typed_attribute :scale, 'float'
42
45
# The vertical alignment
43
attr_accessor :alignement
46
typed_attribute :alignment, 'alignment'
45
48
# The horizontal alignment
46
attr_accessor :justification
49
typed_attribute :justification, 'justification'
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)
56
dict = prepare_show_text_dict(text, x_or_loc, y, measure)
83
88
# The style of a full text object.
84
89
class FullTextStyle < BaseTextStyle
85
90
# The color of the text
91
typed_attribute :color, 'color'
88
93
# The (horizontal) position with respect to a location. You'll
89
94
# seldom need that.
90
attr_accessor :position
96
# @todo Maybe this needs to fo in TextLabel rather than here ?
97
typed_attribute :position, 'float'
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
FullTextStyleOptions = FullTextStyle.options_hash()
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
typed_attribute :text, "text"
110
110
# The location of the label.
112
112
# @todo This will have to eventually use PlotLocation, as it
113
113
# makes much more sense.
114
typed_attribute :loc, "location"
116
def initialize(text = nil)
116
def initialize(text = nil, loc = nil)
120
122
# Draw the label, if #text is not _nil_ or _false_.
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')
165
FullTextLabelOptions = TextLabel.options_hash()
172
172
class MarkerStringStyle < BasicStyle
176
'stroke_color' => 'color',
177
'fill_color' => 'color',
179
'horizontal_scale' => 'float',
180
'vertical_scale' => 'float',
182
'justification' => 'justification',
183
'alignment' => 'alignment',
187
174
# The angle of the text
175
typed_attribute :angle, 'float'
190
177
# The scale of the text
178
typed_attribute :scale, "float"
193
180
# The horizontal scale of the text
194
attr_accessor :horizontal_scale
181
typed_attribute :horizontal_scale, "float"
196
183
# The vertical scale of the text
197
attr_accessor :vertical_scale
184
typed_attribute :vertical_scale, "float"
199
186
# The vertical alignment
200
attr_accessor :alignement
187
typed_attribute :alignment, "alignment"
202
189
# The horizontal alignment
203
attr_accessor :justification
190
typed_attribute :justification, "justification"
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'
210
198
# A number between 1 to 14 -- a PDF font
199
typed_attribute :font, "pdf-font"
213
201
# The rendering mode.
214
202
attr_accessor :mode
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')
253
234
# A LaTeX font. It should be applied to text using the function