coloration 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f20ffabab2c5147efa6b0c06421827a1b05fb615
4
+ data.tar.gz: 6323701b78561cd8382e2d0337138038b98784f3
5
+ SHA512:
6
+ metadata.gz: 2d26dc40b8625dd46bcba5baa2f85f90b870152d340de97a5cd98fe7df5ea91720da1567d492e5d7d69ae5a5cc0cc56d86c71d835f7f7a3093487326764e5f72
7
+ data.tar.gz: 006055f21fd76e4a136912e4efec624620170d2270d16e46d5bddc2c1dd0017e8488f23f784b766287abe36ed549b0cef9d9cb61160aaca4ad9290046a0e1616
data/README.md CHANGED
@@ -2,26 +2,36 @@
2
2
 
3
3
  ## About
4
4
 
5
- __Coloration__ is editor/IDE color scheme converter. Right now it allows you to convert your favourite Textmate color
6
- scheme (in XML plist format) to Vim, JEdit and KDevelop/Kate/Kwrite color scheme. It tries to do its best to generate the most accurate
7
- result for given target.
5
+ __Coloration__ is editor/IDE color scheme converter. Right now it allows you to
6
+ convert your favourite Textmate color scheme (in XML plist format) to Vim,
7
+ JEdit and KDevelop/Kate/Kwrite color scheme. It tries to do its best to
8
+ generate the most accurate result for given target.
9
+
10
+ ## Requirements
11
+
12
+ If you are running Coloration from the command line locally, a modern version
13
+ (> 2.0) of Ruby is required. Note: You may have trouble running Coloration with
14
+ Windows installations. (Pull requests welcome!)
8
15
 
9
16
  ## Installation && Usage
10
17
 
11
- You can use Coloration in two ways: online or on your local machine. Online version is available
12
- at [coloration.sickill.net](http://coloration.sickill.net/). If you like to install coloration on your own machine to
13
- do some batch conversion or for some other reason just run:
18
+ You can use Coloration in two ways: online or on your local machine. The online
19
+ version is available at [coloration.ku1ik.com](http://coloration.ku1ik.com/).
20
+ If you like to install coloration on your own machine to do some batch
21
+ conversion or for some other reason just run:
14
22
 
15
23
  gem install coloration
16
24
 
17
- It gives you _tm2vim_, _tm2jedit_ and _tm2katepart_ binaries to do the conversion on command line.
25
+ It gives you _tm2vim_, _tm2jedit_ and _tm2katepart_ binaries to do the
26
+ conversion on command line.
18
27
 
19
28
  ## Contact
20
29
 
21
- If you found a bug or want to look at the source code you should go to [githubs](http://github.com/sickill/coloration).
22
- Also if you tried to convert a theme and coloration failed or result is not quite good, please report an issue
23
- at [issue tracker](http://github.com/sickill/coloration/issues).
30
+ If you found a bug or want to look at the source code you should go to
31
+ [github](http://github.com/sickill/coloration). Also if you tried to convert a
32
+ theme and coloration failed or result is not quite good, please report an issue
33
+ at [issue tracker](http://github.com/sickill/coloration/issues).
24
34
 
25
35
  ## Author
26
36
 
27
- Coloration was created by Marcin Kulik ([sickill.net](http://sickill.net/))
37
+ Coloration was created by Marcin Kulik ([ku1ik.com](http://ku1ik.com/))
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ lib_dir = File.dirname(__FILE__) + '/../lib'
4
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
5
+
3
6
  require "coloration"
4
7
 
5
8
  Coloration::Converters::Textmate2JEditConverter.process_cmd_line
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ lib_dir = File.dirname(__FILE__) + '/../lib'
4
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
5
+
3
6
  require "coloration"
4
7
 
5
8
  Coloration::Converters::Textmate2KatePartConverter.process_cmd_line
data/bin/tm2vim CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ lib_dir = File.dirname(__FILE__) + '/../lib'
4
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
5
+
3
6
  require "coloration"
4
7
 
5
8
  Coloration::Converters::Textmate2VimConverter.process_cmd_line
@@ -1,13 +1,15 @@
1
- require 'color'
1
+ require 'coloration/color/color'
2
2
 
3
3
  require "coloration/version.rb"
4
4
  require "coloration/extensions.rb"
5
5
  require "coloration/style.rb"
6
- require "coloration/abstract_converter.rb"
6
+ require "coloration/converters/abstract_converter.rb"
7
7
  require "coloration/color_rgba.rb"
8
8
 
9
+ require "coloration/support/items_lookup.rb"
9
10
  require "coloration/readers/textmate_theme_reader.rb"
10
11
 
12
+ require "coloration/writers/abstract_writer.rb"
11
13
  require "coloration/writers/jedit_theme_writer.rb"
12
14
  require "coloration/writers/katepart_theme_writer.rb"
13
15
  require "coloration/writers/vim_theme_writer.rb"
@@ -0,0 +1,182 @@
1
+ #--
2
+ # Colour management with Ruby.
3
+ #
4
+ # Copyright 2005 Austin Ziegler
5
+ # http://rubyforge.org/ruby-pdf/
6
+ #
7
+ # Licensed under a MIT-style licence.
8
+ #
9
+ # $Id: cmyk.rb,v 1.5 2005/08/08 02:44:17 austin Exp $
10
+ #++
11
+
12
+ # An CMYK colour object. CMYK (cyan, magenta, yellow, and black) colours
13
+ # are based on additive percentages of ink. A CMYK colour of (0.3, 0, 0.8,
14
+ # 0.3) would be mixed from 30% cyan, 0% magenta, 80% yellow, and 30%
15
+ # black.
16
+ class Color::CMYK
17
+ # The format of a DeviceCMYK colour for PDF. In color-tools 2.0 this
18
+ # will be removed from this package and added back as a modification by
19
+ # the PDF::Writer package.
20
+ PDF_FORMAT_STR = "%.3f %.3f %.3f %.3f %s"
21
+
22
+ # Compares the other colour to this one. The other colour will be
23
+ # converted to CMYK before comparison, so the comparison between a CMYK
24
+ # colour and a non-CMYK colour will be approximate and based on the
25
+ # other colour's #to_cmyk conversion. If there is no #to_cmyk
26
+ # conversion, this will raise an exception. This will report that two
27
+ # CMYK colours are equivalent if all component values are within 1e-4
28
+ # (0.0001) of each other.
29
+ def ==(other)
30
+ other = other.to_cmyk
31
+ other.kind_of?(Color::CMYK) and
32
+ ((@c - other.c).abs <= 1e-4) and
33
+ ((@m - other.m).abs <= 1e-4) and
34
+ ((@y - other.y).abs <= 1e-4) and
35
+ ((@k - other.k).abs <= 1e-4)
36
+ end
37
+
38
+ # Creates a CMYK colour object from fractional values 0..1.
39
+ #
40
+ # Color::CMYK.from_fraction(0.3, 0, 0.8, 0.3)
41
+ def self.from_fraction(c = 0, m = 0, y = 0, k = 0)
42
+ colour = Color::CMYK.new
43
+ colour.c = c
44
+ colour.m = m
45
+ colour.y = y
46
+ colour.k = k
47
+ colour
48
+ end
49
+
50
+ # Creates a CMYK colour object from percentages. Internally, the colour
51
+ # is managed as fractional values 0..1.
52
+ #
53
+ # Color::CMYK.from_fraction(30, 0, 80, 30)
54
+ def initialize(c = 0, m = 0, y = 0, k = 0)
55
+ @c = c / 100.0
56
+ @m = m / 100.0
57
+ @y = y / 100.0
58
+ @k = k / 100.0
59
+ end
60
+
61
+ # Present the colour as a DeviceCMYK fill colour string for PDF. This
62
+ # will be removed from the default package in color-tools 2.0.
63
+ def pdf_fill
64
+ PDF_FORMAT_STR % [ @c, @m, @y, @k, "k" ]
65
+ end
66
+
67
+ # Present the colour as a DeviceCMYK stroke colour string for PDF. This
68
+ # will be removed from the default package in color-tools 2.0.
69
+ def pdf_stroke
70
+ PDF_FORMAT_STR % [ @c, @m, @y, @k, "K" ]
71
+ end
72
+
73
+ # Present the colour as an RGB HTML/CSS colour string. Note that this
74
+ # will perform a #to_rgb operation using the default conversion formula.
75
+ def html
76
+ to_rgb.html
77
+ end
78
+
79
+ # Converts the CMYK colour to RGB. Most colour experts strongly suggest
80
+ # that this is not a good idea (some even suggesting that it's a very
81
+ # bad idea). CMYK represents additive percentages of inks on white
82
+ # paper, whereas RGB represents mixed colour intensities on a black
83
+ # screen.
84
+ #
85
+ # However, the colour conversion can be done, and there are two
86
+ # different methods for the conversion that provide slightly different
87
+ # results. Adobe PDF conversions are done with the first form.
88
+ #
89
+ # # Adobe PDF Display Formula
90
+ # r = 1.0 - min(1.0, c + k)
91
+ # g = 1.0 - min(1.0, m + k)
92
+ # b = 1.0 - min(1.0, y + k)
93
+ #
94
+ # # Other
95
+ # r = 1.0 - (c * (1.0 - k) + k)
96
+ # g = 1.0 - (m * (1.0 - k) + k)
97
+ # b = 1.0 - (y * (1.0 - k) + k)
98
+ #
99
+ # If we have a CMYK colour of [33% 66% 83% 25%], the first method will
100
+ # give an approximate RGB colour of (107, 23, 0) or #6b1700. The second
101
+ # method will give an approximate RGB colour of (128, 65, 33) or
102
+ # #804121. Which is correct? Although the colours may seem to be
103
+ # drastically different in the RGB colour space, they are very similar
104
+ # colours, differing mostly in intensity. The first is a darker,
105
+ # slightly redder brown; the second is a lighter brown.
106
+ #
107
+ # Because of this subtlety, both methods are now offered for conversion
108
+ # in color-tools 1.2 or later. The Adobe method is not used by default;
109
+ # to enable it, pass +true+ to #to_rgb.
110
+ #
111
+ # Future versions of color-tools may offer other conversion mechanisms
112
+ # that offer greater colour fidelity.
113
+ def to_rgb(use_adobe_method = false)
114
+ if use_adobe_method
115
+ r = 1.0 - [1.0, @c + @k].min
116
+ g = 1.0 - [1.0, @m + @k].min
117
+ b = 1.0 - [1.0, @y + @k].min
118
+ else
119
+ r = 1.0 - (@c.to_f * (1.0 - @k.to_f) + @k.to_f)
120
+ g = 1.0 - (@m.to_f * (1.0 - @k.to_f) + @k.to_f)
121
+ b = 1.0 - (@y.to_f * (1.0 - @k.to_f) + @k.to_f)
122
+ end
123
+ Color::RGB.from_fraction(r, g, b)
124
+ end
125
+
126
+ # Converts the CMYK colour to a single greyscale value. There are
127
+ # undoubtedly multiple methods for this conversion, but only a minor
128
+ # variant of the Adobe conversion method will be used:
129
+ #
130
+ # g = 1.0 - min(1.0, 0.299 * c + 0.587 * m + 0.114 * y + k)
131
+ #
132
+ # This treats the CMY values similarly to YIQ (NTSC) values and then
133
+ # adds the level of black. This is a variant of the Adobe version
134
+ # because it uses the more precise YIQ (NTSC) conversion values for Y
135
+ # (intensity) rather than the approximates provided by Adobe (0.3, 0.59,
136
+ # and 0.11).
137
+ def to_grayscale
138
+ c = 0.299 * @c.to_f
139
+ m = 0.587 * @m.to_f
140
+ y = 0.114 * @y.to_f
141
+ g = 1.0 - [1.0, c + m + y + @k].min
142
+ Color::GrayScale.from_fraction(g)
143
+ end
144
+ alias to_greyscale to_grayscale
145
+
146
+ def to_cmyk
147
+ self
148
+ end
149
+
150
+ # Converts to RGB then YIQ.
151
+ def to_yiq
152
+ to_rgb.to_yiq
153
+ end
154
+
155
+ # Converts to RGB then HSL.
156
+ def to_hsl
157
+ to_rgb.to_hsl
158
+ end
159
+
160
+ attr_accessor :c, :m, :y, :k
161
+ remove_method :c=, :m=, :y=, :k= ;
162
+ def c=(cc) #:nodoc:
163
+ cc = 1.0 if cc > 1
164
+ cc = 0.0 if cc < 0
165
+ @c = cc
166
+ end
167
+ def m=(mm) #:nodoc:
168
+ mm = 1.0 if mm > 1
169
+ mm = 0.0 if mm < 0
170
+ @m = mm
171
+ end
172
+ def y=(yy) #:nodoc:
173
+ yy = 1.0 if yy > 1
174
+ yy = 0.0 if yy < 0
175
+ @y = yy
176
+ end
177
+ def k=(kk) #:nodoc:
178
+ kk = 1.0 if kk > 1
179
+ kk = 0.0 if kk < 0
180
+ @k = kk
181
+ end
182
+ end
@@ -0,0 +1,87 @@
1
+ #--
2
+ # Colour management with Ruby.
3
+ #
4
+ # Copyright 2005 Austin Ziegler
5
+ # http://rubyforge.org/ruby-pdf/
6
+ #
7
+ # Licensed under a MIT-style licence.
8
+ #
9
+ # $Id: color.rb,v 1.8 2005/08/08 02:44:17 austin Exp $
10
+ #++
11
+
12
+ # = Colour Management with Ruby
13
+ #
14
+ # == Copyright
15
+ # Copyright 2005 by Austin Ziegler
16
+ #
17
+ # Color::RGB and Color::CMYK were originally developed for the Ruby PDF
18
+ # project and PDF::Writer and represent wholly unique code.
19
+ #
20
+ # Color::Palette was developed based on techniques described by Andy
21
+ # "Malarkey"[http://www.stuffandnonsense.co.uk/archives/creating_colour_palettes.html]
22
+ # Clarke, implemented in JavaScript by Steve G. Chipman at
23
+ # SlayerOffice[http://slayeroffice.com/tools/color_palette/] and by Patrick
24
+ # Fitzgerald of BarelyFitz[http://www.barelyfitz.com/projects/csscolor/] in
25
+ # PHP.
26
+ #
27
+ # == LICENCE
28
+ # Permission is hereby granted, free of charge, to any person obtaining a
29
+ # copy of this software and associated documentation files (the "Software"),
30
+ # to deal in the Software without restriction, including without limitation
31
+ # the rights to use, copy, modify, merge, publish, distribute, sublicense,
32
+ # and/or sell copies of the Software, and to permit persons to whom the
33
+ # Software is furnished to do so, subject to the following conditions:
34
+ #
35
+ # * The names of its contributors may not be used to endorse or promote
36
+ # products derived from this software without specific prior written
37
+ # permission.
38
+ #
39
+ # The above copyright notice and this permission notice shall be included in
40
+ # all copies or substantial portions of the Software.
41
+ #
42
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
45
+ # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
47
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
48
+ # DEALINGS IN THE SOFTWARE.
49
+ module Color
50
+ COLOR_TOOLS_VERSION = '1.3.0'
51
+
52
+ class RGB; end
53
+ class CMYK; end
54
+ class GrayScale; end
55
+ class YIQ; end
56
+ end
57
+
58
+ require 'coloration/color/rgb'
59
+ require 'coloration/color/cmyk'
60
+ require 'coloration/color/grayscale'
61
+ require 'coloration/color/hsl'
62
+ require 'coloration/color/yiq'
63
+ require 'coloration/color/rgb/metallic'
64
+
65
+ # We load EVERYTHING if we're being run under ZenTest.
66
+ if defined? $ZENTEST and $ZENTEST
67
+ require 'coloration/color/css'
68
+ require 'coloration/color/palette/gimp'
69
+ require 'coloration/color/palette/monocontrast'
70
+ end
71
+
72
+ module Color
73
+ def self.const_missing(name) #:nodoc:
74
+ if Color::RGB.const_defined?(name)
75
+ warn "These colour constants have been deprecated. Use Color::RGB::#{name} instead."
76
+ Color::RGB::constants.each do |const|
77
+ next if const == "PDF_FORMAT_STR"
78
+ next if const == "Metallic"
79
+ const_set(const, Color::RGB.const_get(const))
80
+ end
81
+ class << Color; remove_method :const_missing; end
82
+ Color.const_get(name)
83
+ else
84
+ super
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,27 @@
1
+ #--
2
+ # Colour management with Ruby.
3
+ #
4
+ # Copyright 2005 Austin Ziegler
5
+ # http://rubyforge.org/ruby-pdf/
6
+ #
7
+ # Licensed under a MIT-style licence.
8
+ #
9
+ # $Id: css.rb,v 1.1 2005/08/05 23:07:20 austin Exp $
10
+ #++
11
+
12
+ require 'coloration/color'
13
+
14
+ # This namespace contains some CSS colour names.
15
+ module Color::CSS
16
+ # Returns the RGB colour for name or +nil+ if the name is not valid.
17
+ def self.[](name)
18
+ @colors[name.to_s.downcase.to_sym]
19
+ end
20
+
21
+ @colors = {}
22
+ Color::RGB.constants.each do |const|
23
+ next if const == "PDF_FORMAT_STR"
24
+ next if const == "Metallic"
25
+ @colors[const.downcase.to_sym] ||= Color::RGB.const_get(const)
26
+ end
27
+ end
@@ -0,0 +1,135 @@
1
+ #--
2
+ # Colour management with Ruby.
3
+ #
4
+ # Copyright 2005 Austin Ziegler
5
+ # http://rubyforge.org/ruby-pdf/
6
+ #
7
+ # Licensed under a MIT-style licence.
8
+ #
9
+ # $Id: grayscale.rb,v 1.3 2005/08/08 02:44:17 austin Exp $
10
+ #++
11
+
12
+ # A colour object representing shades of grey. Used primarily in PDF
13
+ # document creation.
14
+ class Color::GrayScale
15
+ # The format of a DeviceGrey colour for PDF. In color-tools 2.0 this
16
+ # will be removed from this package and added back as a modification by
17
+ # the PDF::Writer package.
18
+ PDF_FORMAT_STR = "%.3f %s"
19
+
20
+ # Creates a greyscale colour object from fractional values 0..1.
21
+ #
22
+ # Color::GreyScale.from_fraction(0.5)
23
+ def self.from_fraction(g = 0)
24
+ color = Color::GrayScale.new
25
+ color.g = g
26
+ color
27
+ end
28
+
29
+ # Creates a greyscale colour object from percentages 0..100.
30
+ #
31
+ # Color::GrayScale.new(50)
32
+ def initialize(g = 0)
33
+ @g = g / 100.0
34
+ end
35
+
36
+ # Compares the other colour to this one. The other colour will be
37
+ # converted to GreyScale before comparison, so the comparison between a
38
+ # GreyScale colour and a non-GreyScale colour will be approximate and
39
+ # based on the other colour's #to_greyscale conversion. If there is no
40
+ # #to_greyscale conversion, this will raise an exception. This will
41
+ # report that two GreyScale values are equivalent if they are within
42
+ # 1e-4 (0.0001) of each other.
43
+ def ==(other)
44
+ other = other.to_grayscale
45
+ other.kind_of?(Color::GrayScale) and
46
+ ((@g - other.g).abs <= 1e-4)
47
+ end
48
+
49
+ # Present the colour as a DeviceGrey fill colour string for PDF. This
50
+ # will be removed from the default package in color-tools 2.0.
51
+ def pdf_fill
52
+ PDF_FORMAT_STR % [ @g, "g" ]
53
+ end
54
+
55
+ # Present the colour as a DeviceGrey stroke colour string for PDF. This
56
+ # will be removed from the default package in color-tools 2.0.
57
+ def pdf_stroke
58
+ PDF_FORMAT_STR % [ @g, "G" ]
59
+ end
60
+
61
+ def to_255
62
+ [(@g * 255).round, 255].min
63
+ end
64
+ private :to_255
65
+
66
+ # Present the colour as an HTML/CSS colour string.
67
+ def html
68
+ gs = "%02x" % to_255
69
+ "##{gs * 3}"
70
+ end
71
+
72
+ # Convert the greyscale colour to CMYK.
73
+ def to_cmyk
74
+ k = 1.0 - @g.to_f
75
+ Color::CMYK.from_fraction(0, 0, 0, k)
76
+ end
77
+
78
+ # Convert the greyscale colour to RGB.
79
+ def to_rgb(ignored = true)
80
+ g = to_255
81
+ Color::RGB.new(g, g, g)
82
+ end
83
+
84
+ def to_grayscale
85
+ self
86
+ end
87
+ alias to_greyscale to_grayscale
88
+
89
+ # Lightens the greyscale colour by the stated percent.
90
+ def lighten_by(percent)
91
+ g = [@g + (@g * (percent / 100.0)), 1.0].min
92
+ Color::GrayScale.from_fraction(g)
93
+ end
94
+
95
+ # Darken the RGB hue by the stated percent.
96
+ def darken_by(percent)
97
+ g = [@g - (@g * (percent / 100.0)), 0.0].max
98
+ Color::GrayScale.from_fraction(g)
99
+ end
100
+
101
+ # Returns the YIQ (NTSC) colour encoding of the greyscale value. This
102
+ # is an approximation, as the values for I and Q are calculated by
103
+ # treating the greyscale value as an RGB value. The Y (intensity or
104
+ # brightness) value is the same as the greyscale value.
105
+ def to_yiq
106
+ y = @g
107
+ i = (@g * 0.596) + (@g * -0.275) + (@g * -0.321)
108
+ q = (@g * 0.212) + (@g * -0.523) + (@g * 0.311)
109
+ Color::YIQ.from_fraction(y, i, q)
110
+ end
111
+
112
+ # Returns the HSL colour encoding of the greyscale value.
113
+ def to_hsl
114
+ Color::HSL.from_fraction(0, 0, @g)
115
+ end
116
+
117
+ # Returns the brightness value for this greyscale value; this is the
118
+ # greyscale value.
119
+ def brightness
120
+ @g
121
+ end
122
+
123
+ attr_accessor :g
124
+ remove_method :g= ;
125
+ def g=(gg) #:nodoc:
126
+ gg = 1.0 if gg > 1
127
+ gg = 0.0 if gg < 0
128
+ @g = gg
129
+ end
130
+ end
131
+
132
+ module Color
133
+ # A synonym for Color::GrayScale.
134
+ GreyScale = GrayScale
135
+ end