rubyquartz 0.1.2
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.
- data/COPYRIGHT +24 -0
- data/History.txt +9 -0
- data/Manifest.txt +95 -0
- data/README.txt +71 -0
- data/Rakefile +51 -0
- data/ext/ExportedSymbols.txt +1 -0
- data/ext/bitmap.c +129 -0
- data/ext/bitmap.h +38 -0
- data/ext/bitmap_context.c +67 -0
- data/ext/bitmap_context.h +31 -0
- data/ext/color.c +145 -0
- data/ext/color.h +34 -0
- data/ext/colorspace.c +94 -0
- data/ext/colorspace.h +33 -0
- data/ext/context.c +393 -0
- data/ext/context.h +33 -0
- data/ext/extconf.rb +48 -0
- data/ext/font.c +148 -0
- data/ext/font.h +32 -0
- data/ext/function.c +124 -0
- data/ext/function.h +32 -0
- data/ext/image.c +140 -0
- data/ext/image.h +31 -0
- data/ext/image_source.c +143 -0
- data/ext/image_source.h +31 -0
- data/ext/pdf_document.c +91 -0
- data/ext/pdf_document.h +31 -0
- data/ext/pdf_page.c +79 -0
- data/ext/pdf_page.h +31 -0
- data/ext/point.c +42 -0
- data/ext/point.h +32 -0
- data/ext/rect.c +45 -0
- data/ext/rect.h +32 -0
- data/ext/rubyquartz.c +80 -0
- data/ext/rubyquartz.h +29 -0
- data/ext/rubyquartz_prefix.h +45 -0
- data/ext/shading.c +68 -0
- data/ext/shading.h +32 -0
- data/ext/size.c +42 -0
- data/ext/size.h +32 -0
- data/ext/text.c +258 -0
- data/ext/text.h +39 -0
- data/ext/utilities.c +181 -0
- data/ext/utilities.h +43 -0
- data/lib/rubyquartz.rb +59 -0
- data/lib/rubyquartz/bitmap.rb +62 -0
- data/lib/rubyquartz/bitmap_context.rb +50 -0
- data/lib/rubyquartz/color.rb +68 -0
- data/lib/rubyquartz/colorspace.rb +42 -0
- data/lib/rubyquartz/context.rb +116 -0
- data/lib/rubyquartz/font.rb +48 -0
- data/lib/rubyquartz/function.rb +57 -0
- data/lib/rubyquartz/image.rb +48 -0
- data/lib/rubyquartz/image_source.rb +50 -0
- data/lib/rubyquartz/pdf_document.rb +47 -0
- data/lib/rubyquartz/pdf_page.rb +54 -0
- data/lib/rubyquartz/point.rb +63 -0
- data/lib/rubyquartz/rect.rb +127 -0
- data/lib/rubyquartz/shading.rb +48 -0
- data/lib/rubyquartz/size.rb +39 -0
- data/lib/rubyquartz/text.rb +50 -0
- data/test/images/TestContext.test_begin_path.png +0 -0
- data/test/images/TestContext.test_draw_image.png +0 -0
- data/test/images/TestContext.test_draw_path.png +0 -0
- data/test/images/TestContext.test_draw_pdf.png +0 -0
- data/test/images/TestContext.test_draw_shading_axial.png +0 -0
- data/test/images/TestContext.test_draw_text.png +0 -0
- data/test/images/TestContext.test_draw_text_baseline_aligned.png +0 -0
- data/test/images/TestContext.test_draw_text_flipped.png +0 -0
- data/test/images/TestContext.test_draw_text_flipped_non_zero_point.png +0 -0
- data/test/images/TestContext.test_draw_text_non_zero_point.png +0 -0
- data/test/images/TestContext.test_fill.png +0 -0
- data/test/images/TestContext.test_gsave.png +0 -0
- data/test/images/TestContext.test_gsave_block.png +0 -0
- data/test/images/TestContext.test_line_width.png +0 -0
- data/test/images/TestContext.test_lineto.png +0 -0
- data/test/images/TestContext.test_rotate.png +0 -0
- data/test/images/TestContext.test_rounded_rect.png +0 -0
- data/test/images/TestContext.test_scale.png +0 -0
- data/test/images/TestContext.test_set_line_dash.png +0 -0
- data/test/images/TestContext.test_shadow.png +0 -0
- data/test/images/TestContext.test_stroke_rect.png +0 -0
- data/test/images/TestContext.test_text_bounds.png +0 -0
- data/test/images/TestContext.test_translate.png +0 -0
- data/test/inputs/circle.pdf +0 -0
- data/test/inputs/wash.png +0 -0
- data/test/rubyquartz_test.rb +51 -0
- data/test/tc_bitmap_context.rb +43 -0
- data/test/tc_color.rb +43 -0
- data/test/tc_context.rb +315 -0
- data/test/tc_font.rb +54 -0
- data/test/tc_image_source.rb +69 -0
- data/test/tc_pdf_document.rb +63 -0
- data/test/tc_pdf_page.rb +53 -0
- data/test/tc_text.rb +39 -0
- metadata +156 -0
data/ext/utilities.h
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
|
|
3
|
+
|
|
4
|
+
OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
|
|
5
|
+
|
|
6
|
+
Omni Source Code software is available from The Omni Group on their web
|
|
7
|
+
site at www.omnigroup.com.
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
10
|
+
copy of this software and associated documentation files (the "Software"),
|
|
11
|
+
to deal in the Software without restriction, including without limitation
|
|
12
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
13
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
|
14
|
+
Software is furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
Any original copyright notices and this permission notice shall be included
|
|
17
|
+
in all copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
24
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
25
|
+
DEALINGS IN THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
#include "ruby.h"
|
|
30
|
+
|
|
31
|
+
extern VALUE _symbol_for_string(CFStringRef str);
|
|
32
|
+
extern CFStringRef _copy_string_for_str(VALUE str);
|
|
33
|
+
extern VALUE _value_for_string(CFStringRef str);
|
|
34
|
+
extern CFURLRef _create_url_for_path(VALUE path);
|
|
35
|
+
|
|
36
|
+
extern CFDataRef _create_data_from_string(VALUE value, Boolean copy);
|
|
37
|
+
|
|
38
|
+
extern VALUE _cftype_alloc(VALUE klass);
|
|
39
|
+
extern CFTypeRef _cftype_get(VALUE self, CFTypeID typeID, const char *typeName);
|
|
40
|
+
extern void _cftype_set(VALUE self, CFTypeID typeID, const char *typeName, CFTypeRef value);
|
|
41
|
+
|
|
42
|
+
extern id _objc_type_get(VALUE self, Class cls);
|
|
43
|
+
extern void _objc_type_set(VALUE self, Class cls, id value);
|
data/lib/rubyquartz.rb
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
|
|
4
|
+
#
|
|
5
|
+
# Omni Source Code software is available from The Omni Group on their web
|
|
6
|
+
# site at www.omnigroup.com.
|
|
7
|
+
#
|
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
9
|
+
# copy of this software and associated documentation files (the "Software"),
|
|
10
|
+
# to deal in the Software without restriction, including without limitation
|
|
11
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
|
13
|
+
# Software is furnished to do so, subject to the following conditions:
|
|
14
|
+
#
|
|
15
|
+
# Any original copyright notices and this permission notice shall be included
|
|
16
|
+
# in all copies or substantial portions of the Software.
|
|
17
|
+
#
|
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
24
|
+
# DEALINGS IN THE SOFTWARE.
|
|
25
|
+
|
|
26
|
+
module Quartz
|
|
27
|
+
VERSION = '0.1.2'
|
|
28
|
+
|
|
29
|
+
public
|
|
30
|
+
def self.check_memory
|
|
31
|
+
_check_memory
|
|
32
|
+
GC.start
|
|
33
|
+
_check_memory
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Try to load this, but don't fail if it is missing (otherwise our rake commands can't run while we are in a clean state)
|
|
39
|
+
begin
|
|
40
|
+
require 'rubyquartz_api'
|
|
41
|
+
rescue LoadError
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
require 'rubyquartz/colorspace'
|
|
45
|
+
require 'rubyquartz/color'
|
|
46
|
+
require 'rubyquartz/bitmap'
|
|
47
|
+
require 'rubyquartz/image'
|
|
48
|
+
require 'rubyquartz/context'
|
|
49
|
+
require 'rubyquartz/bitmap_context'
|
|
50
|
+
require 'rubyquartz/font'
|
|
51
|
+
require 'rubyquartz/text'
|
|
52
|
+
require 'rubyquartz/point'
|
|
53
|
+
require 'rubyquartz/rect'
|
|
54
|
+
require 'rubyquartz/size'
|
|
55
|
+
require 'rubyquartz/function'
|
|
56
|
+
require 'rubyquartz/shading'
|
|
57
|
+
require 'rubyquartz/image_source'
|
|
58
|
+
require 'rubyquartz/pdf_document'
|
|
59
|
+
require 'rubyquartz/pdf_page'
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
|
|
4
|
+
#
|
|
5
|
+
# Omni Source Code software is available from The Omni Group on their web
|
|
6
|
+
# site at www.omnigroup.com.
|
|
7
|
+
#
|
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
9
|
+
# copy of this software and associated documentation files (the "Software"),
|
|
10
|
+
# to deal in the Software without restriction, including without limitation
|
|
11
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
|
13
|
+
# Software is furnished to do so, subject to the following conditions:
|
|
14
|
+
#
|
|
15
|
+
# Any original copyright notices and this permission notice shall be included
|
|
16
|
+
# in all copies or substantial portions of the Software.
|
|
17
|
+
#
|
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
24
|
+
# DEALINGS IN THE SOFTWARE.
|
|
25
|
+
|
|
26
|
+
module Quartz
|
|
27
|
+
class Bitmap
|
|
28
|
+
def initialize(width, height, colorspace, options={})
|
|
29
|
+
raise "Width must be an integer" if width.to_i != width
|
|
30
|
+
raise "Height must be an integer" if height.to_i != height
|
|
31
|
+
|
|
32
|
+
super()
|
|
33
|
+
|
|
34
|
+
bits_per_channel = options[:bits_per_channel] || 8
|
|
35
|
+
alpha = options[:alpha] || Bitmap::ALPHA_PREMULTIPLIED_FIRST
|
|
36
|
+
float_pixels = options[:float_pixels] || false
|
|
37
|
+
byte_order = options[:byte_order] || Bitmap::BYTE_ORDER_DEFAULT
|
|
38
|
+
|
|
39
|
+
bytes_per_row = options[:bytes_per_row]
|
|
40
|
+
if bytes_per_row.nil?
|
|
41
|
+
case alpha
|
|
42
|
+
when Bitmap::ALPHA_NONE
|
|
43
|
+
component_count = colorspace.component_count
|
|
44
|
+
when Bitmap::ALPHA_ONLY
|
|
45
|
+
component_count = 1
|
|
46
|
+
else
|
|
47
|
+
component_count = colorspace.component_count + 1
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
if float_pixels
|
|
51
|
+
bytes_per_component = 4
|
|
52
|
+
else
|
|
53
|
+
bytes_per_component = 1
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
bytes_per_row = width * component_count * bytes_per_component
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
_initialize(width, height, bits_per_channel, bytes_per_row, alpha, float_pixels, byte_order)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
|
|
4
|
+
#
|
|
5
|
+
# Omni Source Code software is available from The Omni Group on their web
|
|
6
|
+
# site at www.omnigroup.com.
|
|
7
|
+
#
|
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
9
|
+
# copy of this software and associated documentation files (the "Software"),
|
|
10
|
+
# to deal in the Software without restriction, including without limitation
|
|
11
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
|
13
|
+
# Software is furnished to do so, subject to the following conditions:
|
|
14
|
+
#
|
|
15
|
+
# Any original copyright notices and this permission notice shall be included
|
|
16
|
+
# in all copies or substantial portions of the Software.
|
|
17
|
+
#
|
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
24
|
+
# DEALINGS IN THE SOFTWARE.
|
|
25
|
+
|
|
26
|
+
module Quartz
|
|
27
|
+
class BitmapContext
|
|
28
|
+
attr_reader :bitmap
|
|
29
|
+
|
|
30
|
+
def initialize(width, height, options={})
|
|
31
|
+
raise "Width must be an integer" if width.to_i != width
|
|
32
|
+
raise "Height must be an integer" if height.to_i != height
|
|
33
|
+
|
|
34
|
+
super()
|
|
35
|
+
|
|
36
|
+
colorspace = options[:colorspace] || ColorSpace.new(:name => ColorSpace::GENERIC_RGB)
|
|
37
|
+
|
|
38
|
+
# Record the bitmap as an ivar so it is retained. _initialize grabs a pointer, so losing this ivar can cause crashes.
|
|
39
|
+
@bitmap = Quartz::Bitmap.new(width, height, colorspace, options)
|
|
40
|
+
_initialize(@bitmap, colorspace)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
public
|
|
44
|
+
|
|
45
|
+
def copy_image
|
|
46
|
+
Image.new(:bitmap_context => self)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
|
|
4
|
+
#
|
|
5
|
+
# Omni Source Code software is available from The Omni Group on their web
|
|
6
|
+
# site at www.omnigroup.com.
|
|
7
|
+
#
|
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
9
|
+
# copy of this software and associated documentation files (the "Software"),
|
|
10
|
+
# to deal in the Software without restriction, including without limitation
|
|
11
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
|
13
|
+
# Software is furnished to do so, subject to the following conditions:
|
|
14
|
+
#
|
|
15
|
+
# Any original copyright notices and this permission notice shall be included
|
|
16
|
+
# in all copies or substantial portions of the Software.
|
|
17
|
+
#
|
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
24
|
+
# DEALINGS IN THE SOFTWARE.
|
|
25
|
+
|
|
26
|
+
module Quartz
|
|
27
|
+
class Color
|
|
28
|
+
|
|
29
|
+
@@Gray = nil
|
|
30
|
+
@@RGB = nil
|
|
31
|
+
@@CMYK = nil
|
|
32
|
+
|
|
33
|
+
attr_reader :colorspace
|
|
34
|
+
|
|
35
|
+
def initialize(colorspace, *components)
|
|
36
|
+
@colorspace = colorspace
|
|
37
|
+
@components = components
|
|
38
|
+
_initialize_with_components(colorspace, components)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
public
|
|
42
|
+
|
|
43
|
+
def self.gray(g, a = 1.0)
|
|
44
|
+
@@Gray = ColorSpace.new(:name => ColorSpace::GENERIC_GRAY) if @@Gray.nil?
|
|
45
|
+
new(@@Gray, g, a)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.rgb(r, g, b, a = 1.0)
|
|
49
|
+
@@RGB = ColorSpace.new(:name => ColorSpace::GENERIC_RGB) if @@RGB.nil?
|
|
50
|
+
new(@@RGB, r, g, b, a)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.cmyk(c, m, y, k, a = 1.0)
|
|
54
|
+
@@CMYK = ColorSpace.new(:name => ColorSpace::GENERIC_CMYK) if @@CMYK.nil?
|
|
55
|
+
new(@@CMYK, c, m, y, k, a)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.hsv(h, s, v, a = 1.0)
|
|
59
|
+
components = [h, s, v]
|
|
60
|
+
convert_hsv_to_rgb(components)
|
|
61
|
+
rgb(components[0], components[1], components[2], a)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def to_s
|
|
65
|
+
"<Color: #{@colorspace.name} #{@components.join(" ")}"
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
|
|
4
|
+
#
|
|
5
|
+
# Omni Source Code software is available from The Omni Group on their web
|
|
6
|
+
# site at www.omnigroup.com.
|
|
7
|
+
#
|
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
9
|
+
# copy of this software and associated documentation files (the "Software"),
|
|
10
|
+
# to deal in the Software without restriction, including without limitation
|
|
11
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
|
13
|
+
# Software is furnished to do so, subject to the following conditions:
|
|
14
|
+
#
|
|
15
|
+
# Any original copyright notices and this permission notice shall be included
|
|
16
|
+
# in all copies or substantial portions of the Software.
|
|
17
|
+
#
|
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
24
|
+
# DEALINGS IN THE SOFTWARE.
|
|
25
|
+
|
|
26
|
+
module Quartz
|
|
27
|
+
class ColorSpace
|
|
28
|
+
|
|
29
|
+
attr_reader :name
|
|
30
|
+
|
|
31
|
+
def initialize(options)
|
|
32
|
+
@name = options[:name]
|
|
33
|
+
if @name
|
|
34
|
+
_init_with_name(@name)
|
|
35
|
+
else
|
|
36
|
+
# TODO: Add various other creation types
|
|
37
|
+
raise "Cannot determine how to create colorspace from given options"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
|
|
4
|
+
#
|
|
5
|
+
# Omni Source Code software is available from The Omni Group on their web
|
|
6
|
+
# site at www.omnigroup.com.
|
|
7
|
+
#
|
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
9
|
+
# copy of this software and associated documentation files (the "Software"),
|
|
10
|
+
# to deal in the Software without restriction, including without limitation
|
|
11
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
|
13
|
+
# Software is furnished to do so, subject to the following conditions:
|
|
14
|
+
#
|
|
15
|
+
# Any original copyright notices and this permission notice shall be included
|
|
16
|
+
# in all copies or substantial portions of the Software.
|
|
17
|
+
#
|
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
24
|
+
# DEALINGS IN THE SOFTWARE.
|
|
25
|
+
|
|
26
|
+
module Quartz
|
|
27
|
+
class Context
|
|
28
|
+
|
|
29
|
+
@@ModeNameToNumber = {
|
|
30
|
+
:fill => 0,
|
|
31
|
+
:eo_fill => 1,
|
|
32
|
+
:stoke => 2,
|
|
33
|
+
:fill_stroke => 3,
|
|
34
|
+
:eo_fill_stroke => 4,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public
|
|
38
|
+
|
|
39
|
+
def gsave
|
|
40
|
+
_gsave
|
|
41
|
+
success = true
|
|
42
|
+
if block_given?
|
|
43
|
+
begin
|
|
44
|
+
yield self
|
|
45
|
+
ensure
|
|
46
|
+
grestore
|
|
47
|
+
success = false
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
success
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def draw_path(mode)
|
|
54
|
+
_draw_path(@@ModeNameToNumber[mode])
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def fill_rect(*components)
|
|
58
|
+
_fill_rect(components[0], components[1], components[2], components[3])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def stroke_rect(*components)
|
|
62
|
+
_stroke_rect(components[0], components[1], components[2], components[3])
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def draw(drawable)
|
|
66
|
+
case drawable
|
|
67
|
+
when PDFPage
|
|
68
|
+
draw_pdf_page(drawable)
|
|
69
|
+
when Image
|
|
70
|
+
size = drawable.size
|
|
71
|
+
draw_image(0, 0, size.width, size.height, drawable)
|
|
72
|
+
else
|
|
73
|
+
raise "Don't know how to draw #{drawable}"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def draw_text(text, options={})
|
|
78
|
+
x = options[:x] || 0
|
|
79
|
+
y = options[:y] || 0
|
|
80
|
+
background = options[:background] || false
|
|
81
|
+
if options[:flip]
|
|
82
|
+
height = text.height_used
|
|
83
|
+
gsave {
|
|
84
|
+
translate(x, y)
|
|
85
|
+
scale(1, -1)
|
|
86
|
+
translate(0, -height)
|
|
87
|
+
_draw_text(text, 0, 0, background)
|
|
88
|
+
}
|
|
89
|
+
else
|
|
90
|
+
_draw_text(text, x, y, background)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def add_rounded_rect(rect, radius)
|
|
96
|
+
top_mid_x = rect.mid_x
|
|
97
|
+
top_mid_y = rect.max_y
|
|
98
|
+
|
|
99
|
+
top_left_x = rect.min_x
|
|
100
|
+
top_left_y = rect.max_y
|
|
101
|
+
|
|
102
|
+
top_right_x = rect.max_x
|
|
103
|
+
top_right_y = rect.max_y
|
|
104
|
+
|
|
105
|
+
bottom_right_x = rect.max_x
|
|
106
|
+
bottom_right_y = rect.min_y
|
|
107
|
+
|
|
108
|
+
moveto(top_mid_x, top_mid_y)
|
|
109
|
+
arc_to_point(top_left_x, top_left_y, rect.origin.x, rect.origin.y, radius)
|
|
110
|
+
arc_to_point(rect.origin.x, rect.origin.y, bottom_right_x, bottom_right_y, radius)
|
|
111
|
+
arc_to_point(bottom_right_x, bottom_right_y, top_right_x, top_right_y, radius)
|
|
112
|
+
arc_to_point(top_right_x, top_right_y, top_left_x, top_left_y, radius)
|
|
113
|
+
close_path
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|