1
# styles.rb : Different Types to deal with various style arguments.
2
# Copyright (C) 2006, 2009 Vincent Fourmond
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
require 'ctioga2/utils'
23
Version::register_svn_info('$Revision: 222 $', '$Date: 2011-01-11 00:52:31 +0100 (Tue, 11 Jan 2011) $')
28
# A color for use with Tioga, ie a [red, green, blue] array of
29
# values between 0 and 1.0. It accepts HTML-like colors, or
30
# three comma-separated values between 0 and 1.
31
class TiogaColorType < Type
33
type_name :tioga_color, 'color'
35
HLSRegexp = /(?:hls):/i
37
def string_to_type_internal(str)
40
str = str.gsub(HLSRegexp,'')
44
if str =~ /^\s*#([0-9a-fA-F]{6})\s*$/
45
value = $1.scan(/../).map {
48
elsif str =~ /^\s*#([0-9a-fA-F]{3})\s*$/
49
value = $1.scan(/./).map {
53
value = str.split(/\s*,\s*/).map do |s|
58
raise IncorrectInput, "You need exactly three values to make up a color"
62
value = Tioga::FigureMaker.hls_to_rgb(value)
68
# A line style for Tioga. It will be represented as:
72
# This creates a line style of:
76
# If the :e is omitted 0 is used.
77
class LineStyleType < Type
79
type_name :tioga_line_style, 'line_style'
81
def string_to_type_internal(str)
82
specs = str.split(/\s*,\s*/)
83
if specs.last =~ /:(.*)$/
85
specs.last.gsub!(/:.*$/,'')
89
return [ specs.map { |s| s.to_f }, phase]
93
# A marker Type for Tioga. Input as
97
class MarkerType < Type
99
type_name :tioga_marker, 'marker'
101
def string_to_type_internal(str)
102
specs = str.split(/\s*,\s*/)
104
return [specs[0].to_i, specs[1].to_i]
105
elsif specs.size == 3
106
return [specs[0].to_i, specs[1].to_i, specs[2].to_f]
108
raise IncorrectInput, "You need two or three values to make a marker"
113
# The type of edges/axis
114
class AxisType < Type
116
include Tioga::FigureConstants
119
/hidden|off/i => AXIS_HIDDEN,
120
/line/i => AXIS_LINE_ONLY,
121
/ticks/i => AXIS_WITH_TICKS_ONLY,
122
/major/i => AXIS_WITH_MAJOR_TICKS_ONLY,
123
/major-num/i => AXIS_WITH_MAJOR_TICKS_AND_NUMERIC_LABELS,
124
/full/i => AXIS_WITH_TICKS_AND_NUMERIC_LABELS
127
type_name :tioga_axis_type, 'axis_type'
129
def string_to_type_internal(str)
130
for k,v in ValidTypes
131
if str =~ /^\s*#{k}\s*/
135
raise IncorrectInput, "Not an axis type: #{str}"
140
class LaTeXFontBaseType < Type
141
type_name :latex_font, 'latex font'
143
def string_to_type_internal(str)
144
return Graphics::Styles::LaTeXFont.from_text(str)
149
class LaTeXFontBaseType < Type
150
type_name :colormap, 'color map'
152
def string_to_type_internal(str)
153
return Graphics::Styles::ColorMap.from_text(str)