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
|
@@ -0,0 +1,48 @@
|
|
|
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 Font
|
|
28
|
+
|
|
29
|
+
@@Families = nil
|
|
30
|
+
def self.families
|
|
31
|
+
if @@Families.nil?
|
|
32
|
+
@@Families = _families.sort
|
|
33
|
+
end
|
|
34
|
+
@@Families
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# TODO: Is sorting really worth it?
|
|
38
|
+
def self.fonts_in_family(family)
|
|
39
|
+
_fonts_in_family(family).sort
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def initialize(options={})
|
|
43
|
+
name = options[:name]
|
|
44
|
+
size = options[:size]
|
|
45
|
+
_initialize_with_name_and_size(name, size)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
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 Function
|
|
28
|
+
|
|
29
|
+
# domain/range are each an array of Ranges
|
|
30
|
+
# when creating the CGFunctionRef:
|
|
31
|
+
# info = self
|
|
32
|
+
# domainDimention = domain.length
|
|
33
|
+
# domain = C array built from 'domain'
|
|
34
|
+
# as above for rangeDimention and range
|
|
35
|
+
# callbacks:
|
|
36
|
+
# evaluate -> #evaluate on the instance
|
|
37
|
+
# releaseInfo -> nothing since the info should only get released if we get GC'd?
|
|
38
|
+
def initialize(domain, range)
|
|
39
|
+
# Flatten the domain and range arrays of ranges to interleaved start/end pairs.
|
|
40
|
+
# The length values should be the count of ranges, not the count of flattended values
|
|
41
|
+
flattened_domain = []
|
|
42
|
+
domain.each {|r| flattened_domain << r.begin << r.end}
|
|
43
|
+
|
|
44
|
+
flattened_range = []
|
|
45
|
+
range.each {|r| flattened_range << r.begin << r.end}
|
|
46
|
+
|
|
47
|
+
_initialize(domain.length, flattened_domain, range.length, flattened_range)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# input is a domain-lengthed array of Numerics
|
|
51
|
+
# output is a domain-lenghted array of Numerics
|
|
52
|
+
# OPTIMIZATION: Keep these arrays around in C-land to avoid reallocating them on each call?
|
|
53
|
+
def evaluate(input, output)
|
|
54
|
+
raise "Subclasses must implement evaluate"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
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 Image
|
|
28
|
+
|
|
29
|
+
def initialize(options)
|
|
30
|
+
bitmap_context = options[:bitmap_context]
|
|
31
|
+
if bitmap_context
|
|
32
|
+
_initialize_with_bitmap_context(bitmap_context)
|
|
33
|
+
return
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
image_source = options[:image_source]
|
|
37
|
+
index = options[:index]
|
|
38
|
+
if image_source && index
|
|
39
|
+
_initialize_with_image_source_at_index(image_source, index)
|
|
40
|
+
return
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# TODO: Add various other creation types
|
|
44
|
+
raise "Cannot determine how to create image from given options"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
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 ImageSource
|
|
28
|
+
|
|
29
|
+
def initialize(options)
|
|
30
|
+
path = options[:path]
|
|
31
|
+
if path
|
|
32
|
+
_initialize_with_path(path)
|
|
33
|
+
return
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if data = options[:data]
|
|
38
|
+
_initialize_with_data(data)
|
|
39
|
+
return
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# TODO: Add various other creation types
|
|
43
|
+
raise "Cannot determine how to create image from given options"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def[](index)
|
|
47
|
+
Image.new(:image_source => self, :index => index)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
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 PDFDocument
|
|
28
|
+
|
|
29
|
+
def initialize(options)
|
|
30
|
+
if data = options[:data]
|
|
31
|
+
_initialize_with_data(data)
|
|
32
|
+
return
|
|
33
|
+
end
|
|
34
|
+
if path = options[:path]
|
|
35
|
+
_initialize_with_path(path)
|
|
36
|
+
return
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# TODO: Add various other creation types
|
|
40
|
+
raise "Cannot determine how to create PDF document from given options"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def[](index)
|
|
44
|
+
PDFPage.new(:document => self, :index => index)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
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 PDFPage
|
|
28
|
+
attr_reader :document
|
|
29
|
+
|
|
30
|
+
@@BoxTypeToNumber = {
|
|
31
|
+
:media => 0,
|
|
32
|
+
:crop => 1,
|
|
33
|
+
:bleed => 2,
|
|
34
|
+
:trim => 3,
|
|
35
|
+
:art => 4,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
def initialize(options)
|
|
39
|
+
@document = options[:document] # Keep a reference to this since the CGPDFPageRef refers to its CGPDFDocumentRef but doesn't retain it.
|
|
40
|
+
index = options[:index]
|
|
41
|
+
if @document && index
|
|
42
|
+
_initialize_with_document_at_index(@document, index)
|
|
43
|
+
return
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
raise "Cannot determine how to create PDF page from given options"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def page_box(type)
|
|
50
|
+
_page_box(@@BoxTypeToNumber[type])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
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 Point
|
|
28
|
+
attr_accessor :x, :y
|
|
29
|
+
|
|
30
|
+
def initialize(x,y)
|
|
31
|
+
@x = x
|
|
32
|
+
@y = y
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def +(p)
|
|
36
|
+
Point.new(@x+p.x, @y+p.y)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def -(p)
|
|
40
|
+
Point.new(@x-p.x, @y-p.y)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def *(scalar)
|
|
44
|
+
Point.new(@x*scalar, @y*scalar)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def dot(p)
|
|
48
|
+
(@x*p.x) + (@y*p.y)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def perp
|
|
52
|
+
Point.new(-@y, @x)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def abs
|
|
56
|
+
Point.new(@x.abs, @y.abs)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def to_s
|
|
60
|
+
"(#{@x}, #{@y})"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
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 Rect
|
|
28
|
+
attr_accessor :origin, :size
|
|
29
|
+
|
|
30
|
+
def initialize(origin, size)
|
|
31
|
+
@origin = origin.dup
|
|
32
|
+
@size = size.dup
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def inset(dx, dy)
|
|
36
|
+
o = Point.new(@origin.x + dx, @origin.y + dy)
|
|
37
|
+
s = Size.new(@size.width - 2*dx, @size.height - 2*dy)
|
|
38
|
+
if s.width < 0 or s.height < 0
|
|
39
|
+
s.width = 0
|
|
40
|
+
s.height = 0
|
|
41
|
+
end
|
|
42
|
+
Rect.new(o, s)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def min_x
|
|
46
|
+
@origin.x
|
|
47
|
+
end
|
|
48
|
+
def max_x
|
|
49
|
+
@origin.x + @size.width
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def min_y
|
|
53
|
+
@origin.y
|
|
54
|
+
end
|
|
55
|
+
def max_y
|
|
56
|
+
@origin.y + @size.height
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def mid_x
|
|
60
|
+
@origin.x + @size.width / 2.0
|
|
61
|
+
end
|
|
62
|
+
def mid_y
|
|
63
|
+
@origin.y + @size.height / 2.0
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def cut(edge, amount)
|
|
67
|
+
origin = @origin.dup
|
|
68
|
+
size = @size.dup
|
|
69
|
+
case edge
|
|
70
|
+
when :min_x
|
|
71
|
+
origin.x += amount
|
|
72
|
+
size.width -= amount
|
|
73
|
+
when :min_y
|
|
74
|
+
origin.y += amount
|
|
75
|
+
size.height -= amount
|
|
76
|
+
when :max_x
|
|
77
|
+
size.width -= amount
|
|
78
|
+
when :max_y
|
|
79
|
+
size.height -= amount
|
|
80
|
+
else
|
|
81
|
+
raise "Unknown edge #{edge}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
if size.width < 0 or size.height < 0
|
|
85
|
+
size.width = 0
|
|
86
|
+
size.height = 0
|
|
87
|
+
end
|
|
88
|
+
Rect.new(origin, size)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def union!(r)
|
|
92
|
+
_min_x = min_x
|
|
93
|
+
_min_y = min_y
|
|
94
|
+
_max_x = max_x
|
|
95
|
+
_max_y = max_y
|
|
96
|
+
|
|
97
|
+
other_min_x = r.min_x
|
|
98
|
+
other_min_y = r.min_y
|
|
99
|
+
other_max_x = r.max_x
|
|
100
|
+
other_max_y = r.max_y
|
|
101
|
+
|
|
102
|
+
_min_x = other_min_x if other_min_x < _min_x
|
|
103
|
+
_min_y = other_min_y if other_min_y < _min_y
|
|
104
|
+
|
|
105
|
+
_max_x = other_max_x if other_max_x > _max_x
|
|
106
|
+
_max_y = other_max_y if other_max_y > _max_y
|
|
107
|
+
|
|
108
|
+
@origin.x = _min_x
|
|
109
|
+
@origin.y = _min_y
|
|
110
|
+
@size.width = _max_x - _min_x
|
|
111
|
+
@size.height = _max_y - _min_y
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Returns a rect with integral coordinates that encloses the receiver
|
|
115
|
+
def integral
|
|
116
|
+
x0 = min_x.floor
|
|
117
|
+
y0 = min_y.floor
|
|
118
|
+
x1 = max_x.ceil
|
|
119
|
+
y1 = max_y.ceil
|
|
120
|
+
Rect.new(Point.new(x0,y0), Size.new(x1-x0,y1-y0))
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def to_s
|
|
124
|
+
"(#{@origin}, #{@size})"
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|