cairo-1.12.8/ 0000755 0000041 0000041 00000000000 12256106703 012732 5 ustar www-data www-data cairo-1.12.8/Rakefile 0000644 0000041 0000041 00000032625 12256106703 014407 0 ustar www-data www-data # -*- coding: utf-8; mode: ruby -*-
require 'English'
require 'find'
require 'fileutils'
require 'open-uri'
require 'rubygems'
require 'rubygems/package_task'
require 'yard'
require 'bundler/gem_helper'
require 'rake/extensiontask'
require 'packnga'
base_dir = File.join(File.dirname(__FILE__))
cairo_ext_dir = File.join(base_dir, 'ext', 'cairo')
cairo_lib_dir = File.join(base_dir, 'lib')
$LOAD_PATH.unshift(cairo_ext_dir)
$LOAD_PATH.unshift(cairo_lib_dir)
ENV["RUBYLIB"] = "#{cairo_lib_dir}:#{cairo_ext_dir}:#{ENV['RUBYLIB']}"
helper = Bundler::GemHelper.new(base_dir)
helper.install
spec = helper.gemspec
Gem::PackageTask.new(spec) do |pkg|
pkg.need_tar_gz = true
end
Packnga::DocumentTask.new(spec) do |task|
end
Packnga::ReleaseTask.new(spec) do |task|
end
binary_dir = File.join("vendor", "local")
Rake::ExtensionTask.new("cairo", spec) do |ext|
ext.cross_platform = ["x86-mingw32"]
ext.cross_compile = true
ext.cross_compiling do |_spec|
if /mingw|mswin/ =~ _spec.platform.to_s
binary_files = []
Find.find(binary_dir) do |name|
next unless File.file?(name)
next if /\.zip\z/i =~ name
binary_files << name
end
_spec.files += binary_files
stage_path = "#{ext.tmp_dir}/#{_spec.platform}/stage"
binary_files.each do |binary_file|
stage_binary_file = "#{stage_path}/#{binary_file}"
stage_binary_dir = File.dirname(stage_binary_file)
directory stage_binary_dir
file stage_binary_file => [stage_binary_dir, binary_file] do
cp(binary_file, stage_binary_file)
end
end
end
end
end
class Package < Struct.new(:name,
:label,
:version,
:compression_method,
:download_site,
:download_base_url,
:windows)
def initialize(parameters)
super()
parameters.each do |key, value|
__send__("#{key}=", value)
end
end
def label
super || name
end
def base_name
"#{name}-#{version}"
end
def compression_method
super || "xz"
end
def archive_path
"#{base_name}.tar.#{compression_method}"
end
def archive_url
"#{download_base_url}/#{archive_path}"
end
def download_base_url
super || download_site_base_url
end
def download_site_base_url
case download_site
when :cairo
base_url = "http://cairographics.org/releases"
when :gnome
base_url = "http://ftp.gnome.org/pub/gnome/sources"
release_series = version.gsub(/\A(\d+\.\d+).+\z/, '\1')
base_url << "/#{name}/#{release_series}"
else
base_url = nil
end
base_url
end
def windows
Windows.new(super || {})
end
class Windows < Struct.new(:builder,
:build_host,
:configure_args,
:built_file,
:patches,
:need_autoreconf)
def initialize(parameters)
super()
parameters.each do |key, value|
__send__("#{key}=", value)
end
end
def build_host
"i686-w64-mingw32"
end
def configure_args
super || []
end
def patches
super || []
end
def need_autoreconf?
need_autoreconf
end
end
end
class WindowsTask
include Rake::DSL
def initialize(spec, base_dir=".")
@spec = spec
@base_dir = Pathname.new(base_dir).expand_path
yield(self)
end
def define
define_download_task
end
def packages=(packages)
@packages = packages.collect do |parameters|
Package.new(parameters)
end
end
private
def define_download_task
define_gcc_task
define_source_download_task
define_build_task
end
def define_gcc_task
namespace :windows do
namespace :gcc do
namespace :dll do
desc "Bundle GCC related DLLs"
task :bundle do
dll_names = ["libgcc_s_sjlj-1.dll", "libwinpthread-1.dll"]
dll_names.each do |dll_name|
cp(absolete_gcc_dll_path(dll_name), install_dir + "bin")
end
end
end
end
end
end
def absolete_gcc_dll_path(dll_name)
build_host = @packages.first.windows.build_host
`#{build_host}-gcc -print-file-name=#{dll_name}`.strip
end
def define_source_download_task
namespace :source do
tasks = []
@packages.each do |package|
namespace package.name do
archive_path = downloaded_archive_path(package)
file archive_path.to_s do
mkdir_p(archive_path.dirname.to_s)
download(package, archive_path)
end
desc "Download #{package.name} source"
task :download => archive_path.to_s
tasks << join_task_name(Rake.application.current_scope, "download")
end
end
desc "Download sources"
task :download => tasks
end
end
def download(package, archive_path)
open(package.archive_url) do |downloaded_archive|
begin
archive_path.open("wb") do |archive_file|
buffer = ""
while downloaded_archive.read(4096, buffer)
archive_file.print(buffer)
end
end
rescue Exception
rm_rf(archive_path.to_s)
raise
end
end
end
def define_build_task
namespace :windows do
tasks = []
@packages.each do |package|
namespace package.name do
built_file = install_dir + package.windows.built_file
file built_file.to_s do
Rake::Task["source:#{package.name}:download"].invoke
build(package)
end
desc "Build #{package.label} package"
task :build => built_file.to_s
tasks << join_task_name(Rake.application.current_scope, "build")
end
end
desc "Build packages"
task :build => ["windows:gcc:dll:bundle"] + tasks
end
end
def join_task_name(current_scope, task_name)
if Rake.const_defined?(:Scope)
current_scope.path_with_task_name(task_name)
else
(current_scope + [task_name]).join(":")
end
end
def build(package)
ENV["PATH"] = ["#{install_dir}/bin", ENV["PATH"]].join(File::PATH_SEPARATOR)
ENV["PKG_CONFIG_LIBDIR"] = "#{install_dir}/lib/pkgconfig"
ENV["PKG_CONFIG_PATH"] = [
ruby_glib2_pkg_config_path,
].join(":")
package_build_dir = build_dir + package.name
rm_rf(package_build_dir.to_s)
mkdir_p(package_build_dir.to_s)
archive_path = downloaded_archive_path(package).expand_path
Dir.chdir(package_build_dir.to_s) do
sh("tar", "xf", archive_path.to_s)
Dir.chdir(package.base_name.to_s) do
package.windows.patches.each do |patch|
sh("patch", "-p1", "--input", (patches_dir + patch).to_s)
end
sh("autoreconf", "--install") if package.windows.need_autoreconf?
custom_builder = package.windows.builder
if custom_builder
custom_builder.build(package, install_dir)
else
build_with_gnu_build_system(package)
end
package_license_dir = license_dir + package.name
package_license_files = Dir.glob("{README*,AUTHORS,COPYING*}")
mkdir_p(package_license_dir.to_s)
cp(package_license_files, package_license_dir.to_s)
end
end
end
def build_with_gnu_build_system(package)
configure_args = [
"CPPFLAGS=#{cppflags(package)}",
"LDFLAGS=#{ldflags(package)}",
"--prefix=#{install_dir}",
"--host=#{package.windows.build_host}",
]
configure_args += package.windows.configure_args
sh("./configure", *configure_args)
ENV["GREP_OPTIONS"] = "--text"
sh("nice", "make", *build_make_args(package))
sh("nice", "make", "install", *install_make_args(package))
end
def cppflags(package)
include_paths = [
install_dir + "include",
]
flags = include_paths.collect do |path|
"-I#{path}"
end
flags.join(" ")
end
def ldflags(package)
library_paths = [
install_dir + "lib",
]
flags = library_paths.collect do |path|
"-L#{path}"
end
flags.join(" ")
end
def build_make_args(package)
args = []
make_n_jobs = ENV["MAKE_N_JOBS"]
args << "-j#{make_n_jobs}" if make_n_jobs
args
end
def install_make_args(package)
[]
end
def tmp_dir
@base_dir + "tmp"
end
def download_dir
tmp_dir + "download"
end
def build_dir
tmp_dir + "build"
end
def install_dir
@base_dir + "vendor" + "local"
end
def license_dir
install_dir + "share" + "license"
end
def downloaded_archive_path(package)
download_dir + package.archive_path
end
def patches_dir
@base_dir + "patches"
end
def ruby_gnome2_dir
@base_dir.parent + "ruby-gnome2.win32"
end
def ruby_glib2_pkg_config_path
ruby_gnome2_dir + "glib2/vendor/local/lib/pkgconfig"
end
end
class ZlibBuilder
include Rake::DSL
def build(package, install_dir)
sh("make",
"PREFIX=#{package.windows.build_host}-",
"-f",
"win32/Makefile.gcc")
include_path = install_dir + "include"
library_path = install_dir + "lib"
binary_path = install_dir + "bin"
sh("make",
"INCLUDE_PATH=#{include_path}",
"LIBRARY_PATH=#{library_path}",
"BINARY_PATH=#{binary_path}",
"SHARED_MODE=1",
"-f",
"win32/Makefile.gcc",
"install")
end
end
windows_task = WindowsTask.new(spec) do |task|
task.packages = [
{
:name => "zlib",
:version => "1.2.8",
:download_base_url => "http://sourceforge.net/projects/libpng/files/zlib/1.2.8",
:compression_method => "gz",
:windows => {
:builder => ZlibBuilder.new,
:built_file => "bin/zlib1.dll",
},
},
{
:name => "libpng",
:version => "1.6.8",
:download_base_url => "http://sourceforge.net/projects/libpng/files/libpng16/1.6.8",
:windows => {
:built_file => "bin/libpng16-16.dll",
},
},
{
:name => "freetype",
:version => "2.5.2",
:download_base_url => "http://sourceforge.net/projects/freetype/files/freetype2/2.5.2",
:compression_method => "bz2",
:windows => {
:built_file => "bin/libfreetype-6.dll",
},
},
{
:name => "libxml2",
:version => "2.9.1",
:download_base_url => "ftp://xmlsoft.org/libxml2",
:compression_method => "gz",
:windows => {
:built_file => "bin/libxml2-2.dll",
:configure_args => [
"--without-python",
],
},
},
{
:name => "fontconfig",
:version => "2.11.0",
:download_base_url => "http://www.freedesktop.org/software/fontconfig/release",
:compression_method => "bz2",
:windows => {
:built_file => "bin/libfontconfig-1.dll",
:configure_args => [
"--enable-libxml2",
"--disable-docs",
],
:patches => [
"fontconfig-2.11.0-disable-mktemp-s.diff",
"fontconfig-2.11.0-disable-test.diff",
],
:need_autoreconf => true,
},
},
{
:name => "pixman",
:version => "0.32.4",
:download_site => :cairo,
:compression_method => "gz",
:windows => {
:built_file => "bin/libpixman-1-0.dll",
},
},
{
:name => "cairo",
:version => "1.12.16",
:download_site => :cairo,
:windows => {
:built_file => "bin/libcairo-2.dll",
:configure_args => [
"--enable-gobject",
],
},
},
]
end
windows_task.define
# for releasing
task :dist do
sh "./dist.sh", spec.version.to_s
end
# for documentation
langs = [
["en", "English"],
["ja", "日本語"],
]
rcairo_doc_dir = File.expand_path(File.join(base_dir, "..", "rcairo-doc"))
rcairo_doc_css = File.join(rcairo_doc_dir, "doc.css")
rcairo_doc_title_image = File.join(rcairo_doc_dir, "rcairo-title.png")
doc_dir = "doc"
doc_index = File.join(doc_dir, "index.html")
doc_css = File.join(doc_dir, "doc.css")
doc_title_image = File.join(doc_dir, "rcairo-title.png")
task(doc_index).instance_variable_get("@actions").clear
file doc_dir do
mkdir_p doc_dir
end
file doc_title_image => [doc_dir, rcairo_doc_title_image] do
cp rcairo_doc_title_image, doc_title_image
end
file doc_css => [rcairo_doc_css, doc_title_image] do
cp rcairo_doc_css, doc_css
end
file doc_index => doc_css do
File.open(doc_index, "w") do |index|
index << <<-EOH
rcairo reference manual
rcairo reference manual
EOH
langs.each do |lang, native_lang|
index << <<-EOH
- #{native_lang}
EOH
end
index << <<-EOH
Up
EOH
end
end
langs.each do |lang,|
lang_doc_dir = File.join(doc_dir, lang)
directory lang_doc_dir
lang_doc_index = File.join(lang_doc_dir, "index.html")
file doc_index => lang_doc_index
file lang_doc_index => [lang_doc_dir] do
lang_doc_dir = File.join(doc_dir, lang)
lang_rcairo_doc_dir = File.join(rcairo_doc_dir, lang)
cp Dir[File.join(lang_rcairo_doc_dir, "*.rd")], lang_doc_dir
ruby File.join(rcairo_doc_dir, "update-html.rb"), lang_doc_dir
ruby File.join(rcairo_doc_dir, "update-html.rb"), lang_doc_dir
rm Dir[File.join(lang_doc_dir, "*.{rd,rdc,rbl}")]
end
end
cairo-1.12.8/Gemfile 0000644 0000041 0000041 00000000115 12256106703 014222 0 ustar www-data www-data # -*- mode: ruby; coding: utf-8 -*-
source "https://rubygems.org/"
gemspec
cairo-1.12.8/GPL 0000644 0000041 0000041 00000043131 12256106703 013301 0 ustar www-data www-data GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
cairo-1.12.8/NEWS 0000644 0000041 0000041 00000023073 12256106703 013436 0 ustar www-data www-data Release 1.12.8 (2013-12-23) Kouhei Sutou
===========================================================
Fixes
-----
* Bundled missing libwinpthread-1.dll into gem for Windows.
[Reported by Masafumi Yokoyama]
Thanks
------
* Masafumi Yokoyama
Release 1.12.7 (2013-12-23) Kouhei Sutou
===========================================================
Improvements
------------
* Added paper sizes of ISO B series and JIS B series.
[Patch by 5.5]
* Added Windows binary for Ruby 2.1.0.
* Updated bundled cairo to 1.12.16 from 1.12.14 for Windows.
Fixes
-----
* Fixed a bug that Cairo::ImageSurface.new(cloned_data, ...)
changes both the original data and the cloned data.
[Patch by Naoyuki Hirayama]
Thanks
------
* 5.5
* Naoyuki Hirayama
Release 1.12.6 (2013-05-24) Kouhei Sutou
===========================================================
Improvements
------------
* Supported Windows XP again.
[ruby-list:49392][Reported by 5.5]
[ruby-list:49401][Researched by myokoym]
Thanks
------
* 5.5
* myokoym
Release 1.12.5 (2013-05-18) Kouhei Sutou
===========================================================
Improvements
------------
* Updated bundled cairo binary for Windows to 1.12.14.
Release 1.12.4 (2013-03-11) Kouhei Sutou
===========================================================
Improvements
------------
* Added Windows binary for Ruby 2.0.0.
Release 1.12.3 (2012-12-04) Kouhei Sutou
===========================================================
Improvements
------------
* Supported Ruby 2.0.0.
[Reported by tmtms]
* Supported auto native package install by Homebrew and MacPorts.
Thanks
------
* tmtms
Release 1.12.2 (2012-06-03) Kouhei Sutou
===========================================================
Improvements
------------
* Added Cairo::Device.supported?.
[GitHub#11] [Reported by Cédric Boutillier]
* Added Cairo::Device.gl_texture_supported?.
* Added Cairo::Surface.supported?.
* Defined all surfaces even if a surface isn't available. Use
Cairo::Surface.XXX_supported? method to check surface
availability.
* Added Cairo::Pattern.xxx_supported?.
[GitHub#12] [Reported by Mamoru Tasaka]
* [experimental] Supported auto native package install.
Thanks
------
* Cédric Boutillier
* Mamoru Tasaka
Release 1.12.1 (2012-03-31) Kouhei Sutou
===========================================================
Improvements
------------
* Re-supported cairo < 1.10.0.
[ruby-gnome2-devel-en] Help me install my own program [Eric C.]
Fixes
-----
* Fixed a problem that an unresolved symbol is referenced.
Thanks
------
* Eric C.
Release 1.12.0 (2012-03-25) Kouhei Sutou
===========================================================
Improvements
------------
* Supported cairo 1.12.0.
* Cairo::Surface#supported_mime_type?
* Cairo::Surface#create_similar_image
* Cairo::Surface#map_to_image
* Cairo::Surface#unmap_to_image
* Cairo::RecordingSurface#extents
* Cairo::MeshPattern
* Cairo::RasterSourcePattern
* Cairo::MimeType::UNIQUE_ID
* Supported glesv2 surface.
Fixes
-----
* Fixed a bug that Cairo::HINT_METRICS_ON can't be specified. #8
[Vasily Fedoseyev]
Thanks
------
* Vasily Fedoseyev
Release 1.10.2 (2011-11-20) Kouhei Sutou
===========================================================
Fixes
-----
* Added missing pkg-config dependency. #8 [Will Bryant]
Thanks
------
* Will Bryant
Release 1.10.1 (2011-10-12) Kouhei Sutou
===========================================================
Features
--------
* Accepted Cairo::EXTEND_PAD as extend value.
* Suppressed a warning. [Stefan Salewski]
* Bound CAIRO_SURFACE_TYPE_XLIB and CAIRO_SURFACE_TYPE_XCB.
* Supported cairo 1.10.2.
* Fixed recording surface test. #4 [Mamoru Tasaka]
* AcceptedCairo::OPERATOR_HSL_LUMINDSITY as operator value.
#6 [Matt Bramlage]
* Suppressed warnings on Windows. [Nikolai Weibull]
* Added --without-vendor-override options to extconf.rb.
[Nikolai Weibull]
Thanks
------
* Stefan Salewski
* Mamoru Tasaka
* Matt Bramlage
* Nikolai Weibull
Release 1.10.0 (2010-09-12) Kouhei Sutou
===========================================================
Features
--------
* Support cairo 1.10.0.
Release 1.8.5 (2010-08-28) Kouhei Sutou
==========================================================
Fixes
-----
* Fix build system. (patch by kimura watasu and suggested by OBATA Akio)
* Fix Windows gem. (reported by Dominic Sisneros, supported by Masaya TARUI)
Thanks
------
* Dominic Sisneros
* kimura wataru
* OBATA Akio
* Masaya TARUI
Release 1.8.3 (2010-08-26) Kouhei Sutou
==========================================================
Features
--------
* Support cairo 1.8.10.
* Support Ruby 1.9.2. (reported by Tasuku SUENAGA and kimura wataru)
* Fix RGV -> HSV conversion. (patch by Yuta Taniguchi)
* Support Cairo::Color as Hash key.
Thanks
------
* Yuta Taniguchi
* Tasuku SUENAGA
* kimura wataru
Release 1.8.1 (2009-12-13) Kouhei Sutou
==========================================================
Features
--------
* Support cairo 1.8.8.
* Improve auto .pc detection.
Release 1.8.0 (2008-09-26) Kouhei Sutou
==========================================================
Features
--------
* Support cairo 1.8.0.
* Resupport cairo 1.2.x. (reported by Yusuke ENDOH)
Release 1.7.0 (2008-08-17) Kouhei Sutou
==========================================================
Features
--------
* Support cairo 1.7.4.
* Add new methods:
* Cairo::Context#destroy
* Cairo::Surface#destroy
* Cairo.satisfied_version?
* Resupport ruby 1.9. (suggested by Paul van Tilburg)
* Fix README. (suggested by Davide Rambaldi)
Release 1.6.3 (2008-07-19) Kouhei Sutou
==========================================================
Features
--------
* Fix build failure on Debian GNU/Linux. (reported by James Healy)
* Fix GC failure with Ruby 1.8.7. (reported by James Healy)
* Improve building on MacOS X. (suggested by Carsten Bormann)
* Fix install location of cairo.so. (suggested by OBATA Akio)
Release 1.6.2 (2008-06-14) Kouhei Sutou
==========================================================
Features
--------
* Fix build failure on MacOS X.
* Fix build failure on 64bit Linux.
* Fix build failure with old Ruby.
* Fix build failure with Ruby 1.9.
Release 1.6.1 (2008-04-24) Kouhei Sutou
==========================================================
Features
--------
* Fix Quartz related bugs. (thanks to kimura wataru)
* Support PKG_CONFIG_LIBDIR. (thanks to OBATA Akio)
* Support RubyGems for mswin32.
Release 1.6.0 (2008-04-11) Kouhei Sutou
==========================================================
Features
--------
* Support cairo 1.6.0.
* Improve Quartz surface support. (thanks to kimura wataru, OBATA Akio)
* Support Cairo::Win32PrintingSurface.
* Support Cairo::QuartzImageSurface.
* Support ruby 1.9.0.
* Add Cairo::Paper.
* Improve size specification of Cairo::PSSurface,
Cairo::PDFSurface, Cairo::SVGSurface.
Release 1.5.1 (2008-01-11) Kouhei Sutou
==========================================================
Features
--------
* Support Quartz surface.
* Fix a wrong type conversion bug. (Binzo)
* Fix a memory leak bug. (Binzo)
* Support ruby 1.9.0. (Paul van Tilburg)
* Fix typos. (NANKI Haruo)
* Rename Cairo::WIN32Surface to Cairo::Win32Surface
* Cairo::WIN32Surface is still available for backward compatibility but
don't use in newly written code.
Release 1.5.0 (2007-05-27) Kouhei Sutou
==========================================================
Many API improvement.
Features
--------
* Support Cairo::Surface.new with block.
* Support RubyGems.
* Add experimental API Cairo::Context#pseudo_blur. (API
may be changed.)
* Fix strange Cairo::Context#push_group and
Cairo::Context#pop_group behaviour.
* Fix Cairo::Context::Path#map_path_onto.
* Add high-level color interface. (Cairo::Color)
* Improve color related API. For example:
From:
context.set_source_rgb(1, 0, 0)
To:
context.set_source_color(:red)
* Support color type conversion between RGB, CMYK and HSV.
* Many default color definitions.
* Support path creation using Cairo::Path without
Cairo::Context.
* Improve constant value specify API. For example:
From:
Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, 100, 100)
To:
Cairo::ImageSurface.new(:argb32, 100, 100)
* Support win32 surface. (Yoshinao Muramatsu)
Release 1.4.1 (2007-03-10 Kouhei Sutou )
==========================================================
Features
--------
* Add missing pkg-config.rb.
Release 1.4.0 (2007-03-06 Kouhei Sutou )
==========================================================
Features
--------
* All cairo 1.4.0 API are implemented.
Release 1.2.0 (2006-07-01 Kouhei Sutou )
==========================================================
Features
--------
* All cairo 1.2.0 API are implemented.
* SVG surface is supported.
Release 1.0.0 (2005-10-16 Kouhei Sutou )
==========================================================
Features
--------
* All cairo 1.0.0 API are implemented.
* PS/PDF surfaces are supported.
cairo-1.12.8/README.rdoc 0000644 0000041 0000041 00000005603 12256106703 014544 0 ustar www-data www-data = README
== Name
rcairo
== Description
Ruby bindings for cairo // cairo extension for Ruby
http://cairographics.org/
== Dependencies
* ruby >= 1.9.3 (2.0.0 also supported!)
* cairo >= 1.2.0 (1.12.0 also supported!)
== Install
=== Package
This way is recommended.
# gem install cairo
=== Self build
For experimental users.
Download rcairo-X.Y.Z.tar.gz from http://cairographics.org/releases/
Extracting:
% tar xvzf rcairo-X.Y.Z.tar.gz
Compiling:
% cd rcairo-X.Y.Z
% ruby extconf.rb # to check for dependencies and create Makefiles
% make # to compile
# make install # to install the cairo extension.
# The samples in the samples folder should be able
# to run before installation except text-on-path.rb
# and text2.rb. They uses Ruby/Pango with rcairo
# support. So you need to install rcairo and build
# Ruby/Pango with it before you run them.
Options to extconf.rb:
* --without-vendor-override: Use system libraries instead of those found in
vendor/local for compiling
== Windows
cairo-X.Y.Z-x86-mingw32.gem includes cairo related binaries.
* cairo related binaries:
http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/
* cairo-X.Y.Z-a_win32.zip
* cairo-dev-X.Y.Z-a_win32.zip
* libpng-X.Y.Z-a_win32.zip
* zlib-X.Y.Z-a_win32.zip
* expat_X.Y.Z-a_win32.zip
* fontconfig_X.Y.Z-a_win32.zip
* freetype_X.Y.Z-a_win32.zip
== Documents
* Reference manual:
http://cairo.rubyforge.org/doc/
* Repository of the reference manual:
http://github.com/rcairo/doc
* An article for rcairo on Rubyst Magazine a.k.a. RubiMa (in Japanese):
http://jp.rubyist.net/magazine/?0019-cairo
== Source
There is the rcairo repository at GitHub:
http://github.com/rcairo/rcairo
== Mailing list
If you have trouble with cairo or rcairo, or you have some ideas for how
it could be improved, please feel free to send a message to the cairo
mailinglist at cairo@cairographics.org , which is archived at
http://cairographics.org/cgi-bin/mailman/listinfo/cairo
== Thanks
* Yoshinao Muramatsu: win32 surface support patch.
* NANKI Haruo: some bug fix patches.
* Paul van Tilburg:
* some patches that support ruby 1.9.
* some suggestions.
* Binzo: some bug reports and fixed that.
* kimura wataru:
* some advices for RubyCocoa.
* reports a bug.
* OBATA Akio:
* reports a bug.
* some suggestions.
* James Healy: reports bugs.
* Carsten Bormann: A suggestion.
* Davide Rambaldi: A suggestion.
* Yusuke ENDOH: reports a bug.
* Yuta Taniguchi: a bug fix patch.
* kimura wataru:
* reports a bug.
* some patches.
* Masayas TARUI:
* Windows support.
* Stefan Salewski: reports a bug.
* Mamoru Tasaka: reports bugs.
* Nikolai Weibull: reports problems.
* Will Bryant: reports a bug.
* Vasily Fedoseyev: fixes a bug.
* Eric C.: reports a bug.
* Cédric Boutillier: reports a bug.
* tmtms: reports a bug.
cairo-1.12.8/lib/ 0000755 0000041 0000041 00000000000 12256106703 013500 5 ustar www-data www-data cairo-1.12.8/lib/cairo/ 0000755 0000041 0000041 00000000000 12256106703 014575 5 ustar www-data www-data cairo-1.12.8/lib/cairo/device.rb 0000644 0000041 0000041 00000000472 12256106703 016364 0 ustar www-data www-data module Cairo
if const_defined?(:Device)
class Device
class << self
def supported?(type)
supported_predicate = "#{type.to_s.downcase}_supported?"
return false unless respond_to?(supported_predicate)
send(supported_predicate)
end
end
end
end
end
cairo-1.12.8/lib/cairo/context/ 0000755 0000041 0000041 00000000000 12256106703 016261 5 ustar www-data www-data cairo-1.12.8/lib/cairo/context/blur.rb 0000644 0000041 0000041 00000002077 12256106703 017560 0 ustar www-data www-data module Cairo
class Context
module Blur
def pseudo_blur(radius=3, &block)
raise ArgumentError, "should specify block" if block.nil?
pattern = push_group(Cairo::CONTENT_COLOR_ALPHA, false, &block)
save do
set_source(pattern)
paint(0.5)
end
1.step(radius, 1) do |i|
opacity = 0.075 - 0.005 * i
next if opacity <= 0
5.downto(1) do |ratio|
r = i / ratio.to_f
r_13 = r / 3.0
r_23 = 2 * r_13
[
[-r, 0],
[-r_23, r_23],
[-r_23, r_13],
[0, r],
[r_13, r_23],
[r_23, r_23],
[r, 0],
[r_23, -r_13],
[r_23, -r_23],
[0, -r],
[-r_13, -r_23],
[-r_23, -r_23],
].each do |x, y|
save do
translate(x, y)
set_source(pattern)
paint(opacity)
end
end
end
end
end
end
end
end
cairo-1.12.8/lib/cairo/context/path.rb 0000644 0000041 0000041 00000007727 12256106703 017557 0 ustar www-data www-data module Cairo
class Context
module Path
def transform_path(path, &block)
transformed_path = Cairo::Path.new
path.each do |type, points|
case type
when PATH_MOVE_TO
transformed_path.move_to(*points.collect(&block).flatten)
when PATH_LINE_TO
transformed_path.line_to(*points.collect(&block).flatten)
when PATH_CURVE_TO
transformed_path.curve_to(*points.collect(&block).flatten)
when PATH_CLOSE_PATH
transformed_path.close
end
end
transformed_path
end
def map_path_onto(path)
parameterized_path = parameterize_path(path)
transformed_path = transform_path(copy_path) do |x, y|
current_point = nil
d = x
i = -1
type = points = nil
path.each do |_type, _points|
type, points = _type, _points
i += 1
break if d < parameterized_path[i]
d -= parameterized_path[i]
case type
when PATH_MOVE_TO
current_point = points[0]
when PATH_LINE_TO
current_point = points[0]
when PATH_CURVE_TO
current_point = points[2]
when PATH_CLOSE_PATH
end
end
case type
when PATH_MOVE_TO
[x, y]
when PATH_LINE_TO
ratio = d / parameterized_path[i]
current_x, current_y = current_point
lx, ly = points[0]
new_x = current_x * (1 - ratio) + lx * ratio
new_y = current_y * (1 - ratio) + ly * ratio
dx = -(current_x - lx)
dy = -(current_y - ly)
ratio = y / parameterized_path[i]
[new_x + -dy * ratio, new_y + dx * ratio]
when PATH_CURVE_TO
ratio = d / parameterized_path[i]
current_x, current_y = current_point
cx0, cy0 = points[0]
cx1, cy1 = points[1]
cx2, cy2 = points[2]
new_x = current_x * (1 - ratio) * (1 - ratio) * (1 - ratio) +
3 * cx0 * (1 - ratio) * (1 - ratio) * ratio +
3 * cx1 * (1 - ratio) * ratio * ratio +
cx2 * ratio * ratio * ratio
new_y = current_y * (1 - ratio) * (1 - ratio) * (1 - ratio) +
3 * cy0 * (1 - ratio) * (1 - ratio) * ratio +
3 * cy1 * (1 - ratio) * ratio * ratio +
cy2 * ratio * ratio * ratio
dx = -3 * current_x * (1 - ratio) * (1 - ratio) +
3 * cx0 * (1 - 4 * ratio + 3 * ratio * ratio) +
3 * cx1 * ( 2 * ratio - 3 * ratio * ratio) +
3 * cx2 * ratio * ratio
dy = -3 * current_y * (1 - ratio) * (1 - ratio) +
3 * cy0 * (1 - 4 * ratio + 3 * ratio * ratio) +
3 * cy1 * ( 2 * ratio - 3 * ratio * ratio) +
3 * cy2 * ratio * ratio
ratio = y / Math.sqrt(dx ** 2 + dy ** 2)
[new_x + -dy * ratio, new_y + dx * ratio]
when PATH_CLOSE_PATH
[x, y]
end
end
new_path
append_path(transformed_path)
end
private
def parameterize_path(path)
current_point = nil
path.collect do |type, points|
result = 0
case type
when PATH_MOVE_TO
current_point = points[0]
when PATH_LINE_TO
result = current_point.distance(points[0])
current_point = points[0]
when PATH_CURVE_TO
result = current_point.distance(points[0])
result += points[0].distance(points[1])
result += points[1].distance(points[2])
current_point = points[2]
when PATH_CLOSE_PATH
end
result
end
end
end
end
end
cairo-1.12.8/lib/cairo/context/rectangle.rb 0000644 0000041 0000041 00000001544 12256106703 020556 0 ustar www-data www-data module Cairo
class Context
module Rectangle
def rounded_rectangle(x, y, width, height, x_radius, y_radius=nil)
x1 = x
x2 = x1 + width
y1 = y
y2 = y1 + height
y_radius ||= x_radius
x_radius = [x_radius, width / 2.0].min
y_radius = [y_radius, height / 2.0].min
xr1 = x_radius
xr2 = x_radius / 2.0
yr1 = y_radius
yr2 = y_radius / 2.0
move_to(x1 + xr1, y1)
line_to(x2 - xr1, y1)
curve_to(x2 - xr2, y1, x2, y1 + yr2, x2, y1 + yr1)
line_to(x2, y2 - yr1)
curve_to(x2, y2 - yr2, x2 - xr2, y2, x2 - xr1, y2)
line_to(x1 + xr1, y2)
curve_to(x1 + xr2, y2, x1, y2 - yr2, x1, y2 - yr1)
line_to(x1, y1 + yr1)
curve_to(x1, y1 + yr2, x1 + xr2, y1, x1 + xr1, y1)
close_path
end
end
end
end
cairo-1.12.8/lib/cairo/context/circle.rb 0000644 0000041 0000041 00000000261 12256106703 020046 0 ustar www-data www-data module Cairo
class Context
module Circle
def circle(center_x, center_y, radius)
arc(center_x, center_y, radius, 0, 2 * Math::PI)
end
end
end
end
cairo-1.12.8/lib/cairo/context/color.rb 0000644 0000041 0000041 00000000303 12256106703 017720 0 ustar www-data www-data require 'cairo/color'
module Cairo
class Context
module Color
def set_source_color(color)
set_source_rgba(*Cairo::Color.parse(color).to_rgb.to_a)
end
end
end
end
cairo-1.12.8/lib/cairo/context/triangle.rb 0000644 0000041 0000041 00000000323 12256106703 020411 0 ustar www-data www-data module Cairo
class Context
module Triangle
def triangle(x1, y1, x2, y2, x3, y3)
move_to(x1, y1)
line_to(x2, y2)
line_to(x3, y3)
close_path
end
end
end
end
cairo-1.12.8/lib/cairo/pattern.rb 0000644 0000041 0000041 00000000474 12256106703 016604 0 ustar www-data www-data module Cairo
class Pattern
class << self
def supported?(type)
type = type.to_s.gsub(/([a-z])([A-Z])/, '\\1_\\2').downcase
supported_predicate = "#{type}_supported?"
return false unless respond_to?(supported_predicate)
send(supported_predicate)
end
end
end
end
cairo-1.12.8/lib/cairo/context.rb 0000644 0000041 0000041 00000001030 12256106703 016600 0 ustar www-data www-data require 'cairo/context/rectangle'
require 'cairo/context/triangle'
require 'cairo/context/circle'
require 'cairo/context/path'
require 'cairo/context/blur'
require 'cairo/context/color'
module Cairo
class Context
include Rectangle
include Triangle
include Circle
include Path
include Blur
include Color
def stroke_preserve(&block)
stroke(true, &block)
end
def fill_preserve(&block)
fill(true, &block)
end
def clip_preserve(&block)
clip(true, &block)
end
end
end
cairo-1.12.8/lib/cairo/papers.rb 0000644 0000041 0000041 00000003036 12256106703 016416 0 ustar www-data www-data require 'cairo/paper'
module Cairo
class Paper
[
[841, 1189, "A0"],
[594, 841, "A1"],
[420, 594, "A2"],
[297, 420, "A3"],
[210, 297, "A4"],
[148, 210, "A5"],
[105, 148, "A6"],
[74, 105, "A7"],
[52, 74, "A8"],
[37, 52, "A9"],
[26, 37, "A10"],
[1000, 1414 , "ISO_B0"],
[707, 1000 , "ISO_B1"],
[500, 707 , "ISO_B2"],
[353, 500 , "ISO_B3"],
[250, 353 , "ISO_B4"],
[176, 250 , "ISO_B5"],
[125, 176 , "ISO_B6"],
[88, 125 , "ISO_B7"],
[62, 88 , "ISO_B8"],
[44, 62 , "ISO_B9"],
[31, 44 , "ISO_B10"],
[1030, 1456, "JIS_B0"],
[728, 1030, "JIS_B1"],
[515, 728, "JIS_B2"],
[364, 515, "JIS_B3"],
[257, 364, "JIS_B4"],
[182, 257, "JIS_B5"],
[128, 182, "JIS_B6"],
[91, 128, "JIS_B7"],
[64, 91, "JIS_B8"],
[45, 64, "JIS_B9"],
[32, 45, "JIS_B10"],
[1030, 1456, "B0"],
[728, 1030, "B1"],
[515, 728, "B2"],
[364, 515, "B3"],
[257, 364, "B4"],
[182, 257, "B5"],
[128, 182, "B6"],
[91, 128, "B7"],
[64, 91, "B8"],
[45, 64, "B9"],
[32, 45, "B10"],
[215.9, 279.4, "letter"],
[215.9, 355.6, "legal"],
[279.9, 431.8, "tabloid"],
[100, 148, "Japanese postcard"],
].each do |width, height, name|
constant_name = name.upcase.gsub(/ +/, '_')
const_set(constant_name, new(width, height, "mm", name))
const_set("#{constant_name}_LANDSCAPE",
new(height, width, "mm", "#{name} (landscape)"))
end
end
end
cairo-1.12.8/lib/cairo/path.rb 0000644 0000041 0000041 00000000546 12256106703 016063 0 ustar www-data www-data require 'forwardable'
module Cairo
class Path
extend Forwardable
methods = %w(new_path new_sub_path move_to line_to curve_to
arc arc_negative rel_move_to rel_line_to rel_curve_to
rectangle rounded_rectangle circle)
def_delegators :@context, *methods
def close
@context.close_path
end
end
end
cairo-1.12.8/lib/cairo/point.rb 0000644 0000041 0000041 00000000176 12256106703 016257 0 ustar www-data www-data module Cairo
class Point
def distance(other)
Math.sqrt((other.x - x) ** 2 + (other.y - y) ** 2)
end
end
end
cairo-1.12.8/lib/cairo/colors.rb 0000644 0000041 0000041 00000074657 12256106703 016446 0 ustar www-data www-data require 'cairo/color'
module Cairo
module Color
# Alice Blue: #F0F8FF
ALICE_BLUE = RGB.new(0.941176470588235, 0.972549019607843, 1.0)
# Alizarin Crimson: #E32636
ALIZARIN_CRIMSON = RGB.new(0.890196078431372, 0.149019607843137, 0.211764705882353)
# Amaranth: #E52B50
AMARANTH = RGB.new(0.898039215686275, 0.168627450980392, 0.313725490196078)
# Amber: #FFBF00
AMBER = RGB.new(1.0, 0.749019607843137, 0.0)
# Amethyst: #9966CC
AMETHYST = RGB.new(0.6, 0.4, 0.8)
# Apricot: #FBCEB1
APRICOT = RGB.new(0.984313725490196, 0.807843137254902, 0.694117647058824)
# Aqua: #00FFFF
AQUA = RGB.new(0.0, 1.0, 1.0)
# Aquamarine: #7FFFD4
AQUAMARINE = RGB.new(0.498039215686275, 1.0, 0.831372549019608)
# Asparagus: #7BA05B
ASPARAGUS = RGB.new(0.482352941176471, 0.627450980392157, 0.356862745098039)
# Azure: #007FFF
AZURE = RGB.new(0.0, 0.498039215686275, 1.0)
# Beige: #F5F5DC
BEIGE = RGB.new(0.96078431372549, 0.96078431372549, 0.862745098039216)
# Bistre: #3D2B1F
BISTRE = RGB.new(0.23921568627451, 0.168627450980392, 0.12156862745098)
# Black: #000000
BLACK = RGB.new(0.0, 0.0, 0.0)
# Blue: #0000FF
BLUE = RGB.new(0.0, 0.0, 1.0)
# Bondi Blue: #0095B6
BONDI_BLUE = RGB.new(0.0, 0.584313725490196, 0.713725490196078)
# Bright green: #66FF00
BRIGHT_GREEN = RGB.new(0.4, 1.0, 0.0)
# Bright turquoise: #08E8DE
BRIGHT_TURQUOISE = RGB.new(0.0313725490196078, 0.909803921568627, 0.870588235294118)
# Brown: #964B00
BROWN = RGB.new(0.588235294117647, 0.294117647058824, 0.0)
# Buff: #F0DC82
BUFF = RGB.new(0.941176470588235, 0.862745098039216, 0.509803921568627)
# Burgundy: #900020
BURGUNDY = RGB.new(0.501960784313725, 0.0, 0.125490196078431)
# Burnt Orange: #CC5500
BURNT_ORANGE = RGB.new(0.8, 0.333333333333333, 0.0)
# Burnt Sienna: #E97451
BURNT_SIENNA = RGB.new(0.913725490196078, 0.454901960784314, 0.317647058823529)
# Burnt umber: #8A3324
BURNT_UMBER = RGB.new(0.541176470588235, 0.2, 0.141176470588235)
# Camouflage green: #78866B
CAMOUFLAGE_GREEN = RGB.new(0.470588235294118, 0.525490196078431, 0.419607843137255)
# Cardinal: #C41E3A
CARDINAL = RGB.new(0.768627450980392, 0.117647058823529, 0.227450980392157)
# Carmine: #960018
CARMINE = RGB.new(0.588235294117647, 0.0, 0.0941176470588235)
# Carnation: #F95A61
CARNATION = RGB.new(0.976470588235294, 0.352941176470588, 0.380392156862745)
# Carrot orange: #ED9121
CARROT_ORANGE = RGB.new(0.929411764705882, 0.568627450980392, 0.129411764705882)
# Celadon: #ACE1AF
CELADON = RGB.new(0.674509803921569, 0.882352941176471, 0.686274509803922)
# Cerise: #DE3163
CERISE = RGB.new(0.870588235294118, 0.192156862745098, 0.388235294117647)
# Cerulean: #007BA7
CERULEAN = RGB.new(0.0, 0.482352941176471, 0.654901960784314)
# Cerulean blue: #2A52BE
CERULEAN_BLUE = RGB.new(0.164705882352941, 0.32156862745098, 0.745098039215686)
# Chartreuse: #7FFF00
CHARTREUSE = RGB.new(0.498039215686275, 1.0, 0.0)
# Chartreuse yellow: #DFFF00
CHARTREUSE_YELLOW = RGB.new(0.874509803921569, 1.0, 0.0)
# Chestnut: #CD5C5C
CHESTNUT = RGB.new(0.803921568627451, 0.36078431372549, 0.36078431372549)
# Chocolate: #D2691E
CHOCOLATE = RGB.new(0.823529411764706, 0.411764705882353, 0.117647058823529)
# Cinnamon: #7B3F00
CINNAMON = RGB.new(0.482352941176471, 0.247058823529412, 0.0)
# Cobalt: #0047AB
COBALT = RGB.new(0.0, 0.27843137254902, 0.670588235294118)
# Copper: #B87333
COPPER = RGB.new(0.72156862745098, 0.450980392156863, 0.2)
# Copper rose: #996666
COPPER_ROSE = RGB.new(0.6, 0.4, 0.4)
# Coral: #FF7F50
CORAL = RGB.new(1.0, 0.498039215686275, 0.313725490196078)
# Coral Red: #FF4040
CORAL_RED = RGB.new(1.0, 0.250980392156863, 0.250980392156863)
# Corn: #FBEC5D
CORN = RGB.new(0.984313725490196, 0.925490196078431, 0.364705882352941)
# Cornflower blue: #6495ED
CORNFLOWER_BLUE = RGB.new(0.392156862745098, 0.584313725490196, 0.929411764705882)
# Cream: #FFFDD0
CREAM = RGB.new(1.0, 0.992156862745098, 0.815686274509804)
# Crimson: #DC143C
CRIMSON = RGB.new(0.862745098039216, 0.0784313725490196, 0.235294117647059)
# Cyan: #00FFFF
CYAN = RGB.new(0.0, 1.0, 1.0)
# Dark blue: #0000C8
DARK_BLUE = RGB.new(0.0, 0.0, 0.545098039215686)
# Denim: #1560BD
DENIM = RGB.new(0.0823529411764706, 0.376470588235294, 0.741176470588235)
# Dodger blue: #1E90FF
DODGER_BLUE = RGB.new(0.117647058823529, 0.564705882352941, 1.0)
# Emerald: #50C878
EMERALD = RGB.new(0.313725490196078, 0.784313725490196, 0.470588235294118)
# Eggplant: #990066
EGGPLANT = RGB.new(0.6, 0.0, 0.4)
# Falu red: #801818
FALU_RED = RGB.new(0.501960784313725, 0.0941176470588235, 0.0941176470588235)
# Fern green: #4F7942
FERN_GREEN = RGB.new(0.309803921568627, 0.474509803921569, 0.258823529411765)
# Flax: #EEDC82
FLAX = RGB.new(0.933333333333333, 0.862745098039216, 0.509803921568627)
# Forest green: #228B22
FOREST_GREEN = RGB.new(0.133333333333333, 0.545098039215686, 0.133333333333333)
# French Rose: #F64A8A
FRENCH_ROSE = RGB.new(0.964705882352941, 0.290196078431373, 0.541176470588235)
# Fuchsia: #FF00FF
FUCHSIA = RGB.new(1.0, 0.0, 1.0)
# Gamboge: #E49B0F
GAMBOGE = RGB.new(0.894117647058824, 0.607843137254902, 0.0588235294117647)
# Gold: #FFD700
GOLD = RGB.new(1.0, 0.843137254901961, 0.0)
# Goldenrod: #DAA520
GOLDENROD = RGB.new(0.854901960784314, 0.647058823529412, 0.125490196078431)
# Gray: #808080
GRAY = RGB.new(0.501960784313725, 0.501960784313725, 0.501960784313725)
# Gray-asparagus: #465945
GRAY_ASPARAGUS = RGB.new(0.274509803921569, 0.349019607843137, 0.270588235294118)
# Green: #00FF00
GREEN = RGB.new(0.0, 1.0, 0.0)
# Green-yellow: #ADFF2F
GREEN_YELLOW = RGB.new(0.67843137254902, 1.0, 0.184313725490196)
# Harlequin: #3FFF00
HARLEQUIN = RGB.new(0.247058823529412, 1.0, 0.0)
# Heliotrope: #DF73FF
HELIOTROPE = RGB.new(0.874509803921569, 0.450980392156863, 1.0)
# Hollywood Cerise: #F400A1
HOLLYWOOD_CERISE = RGB.new(0.956862745098039, 0.0, 0.631372549019608)
# Hot Magenta: #FF00CC
HOT_MAGENTA = RGB.new(1.0, 0.0, 0.8)
# Hot Pink: #FF69B4
HOT_PINK = RGB.new(1.0, 0.411764705882353, 0.705882352941177)
# Indigo: #4B0082
INDIGO = RGB.new(0.294117647058824, 0.0, 0.509803921568627)
# International Klein Blue: #002FA7
INTERNATIONAL_KLEIN_BLUE = RGB.new(0.0, 0.184313725490196, 0.654901960784314)
# International orange: #FF4F00
INTERNATIONAL_ORANGE = RGB.new(1.0, 0.309803921568627, 0.0)
# Ivory: #FFFFF0
IVORY = RGB.new(1.0, 1.0, 0.941176470588235)
# Jade: #00A86B
JADE = RGB.new(0.0, 0.658823529411765, 0.419607843137255)
# Khaki: #C3B091
KHAKI = RGB.new(0.764705882352941, 0.690196078431373, 0.568627450980392)
# Khaki (X11): #F0E68C
KHAKI_X11 = RGB.new(0.941176470588235, 0.901960784313726, 0.549019607843137)
# Lavender: #B57EDC
LAVENDER = RGB.new(0.709803921568627, 0.494117647058824, 0.862745098039216)
# Lavender blue: #CCCCFF
LAVENDER_BLUE = RGB.new(0.8, 0.8, 1.0)
# Lavender blush: #FFF0F5
LAVENDER_BLUSH = RGB.new(1.0, 0.941176470588235, 0.96078431372549)
# Lavender gray: #BDBBD7
LAVENDER_GRAY = RGB.new(0.741176470588235, 0.733333333333333, 0.843137254901961)
# Lavender pink: #FBAED2
LAVENDER_PINK = RGB.new(0.984313725490196, 0.682352941176471, 0.823529411764706)
# Lavender rose: #FBA0E3
LAVENDER_ROSE = RGB.new(0.984313725490196, 0.627450980392157, 0.890196078431372)
# Lemon: #FDE910
LEMON = RGB.new(0.992156862745098, 0.913725490196078, 0.0627450980392157)
# Lemon chiffon: #FFFACD
LEMON_CHIFFON = RGB.new(1.0, 0.980392156862745, 0.803921568627451)
# Lilac: #C8A2C8
LILAC = RGB.new(0.784313725490196, 0.635294117647059, 0.784313725490196)
# Lime: #BFFF00
LIME = RGB.new(0.749019607843137, 1.0, 0.0)
# Linen: #FAF0E6
LINEN = RGB.new(0.980392156862745, 0.941176470588235, 0.901960784313726)
# Magenta: #FF00FF
MAGENTA = RGB.new(1.0, 0.0, 1.0)
# Malachite: #0BDA51
MALACHITE = RGB.new(0.0431372549019608, 0.854901960784314, 0.317647058823529)
# Maroon: #800000
MAROON = RGB.new(0.501960784313725, 0.0, 0.0)
# Mauve: #E0B0FF
MAUVE = RGB.new(0.87843137254902, 0.690196078431373, 1.0)
# Medium carmine: #AF4035
MEDIUM_CARMINE = RGB.new(0.686274509803922, 0.250980392156863, 0.207843137254902)
# Medium Lavender: #EE82EE
MEDIUM_LAVENDER = RGB.new(0.933333333333333, 0.509803921568627, 0.933333333333333)
# Medium Purple: #9370DB
MEDIUM_PURPLE = RGB.new(0.576470588235294, 0.43921568627451, 0.858823529411765)
# Midnight Blue: #003366
MIDNIGHT_BLUE = RGB.new(0.0, 0.2, 0.4)
# Mint Green: #98FF98
MINT_GREEN = RGB.new(0.596078431372549, 1.0, 0.596078431372549)
# Moss green: #ADDFAD
MOSS_GREEN = RGB.new(0.67843137254902, 0.874509803921569, 0.67843137254902)
# Mountbatten pink: #997A8D
MOUNTBATTEN_PINK = RGB.new(0.6, 0.47843137254902, 0.552941176470588)
# Mustard: #FFDB58
MUSTARD = RGB.new(1.0, 0.858823529411765, 0.345098039215686)
# Navajo white: #FFDEAD
NAVAJO_WHITE = RGB.new(1.0, 0.870588235294118, 0.67843137254902)
# Navy Blue: #000080
NAVY_BLUE = RGB.new(0.0, 0.0, 0.501960784313725)
# Ochre: #CC7722
OCHRE = RGB.new(0.8, 0.466666666666667, 0.133333333333333)
# Old Gold: #CFB53B
OLD_GOLD = RGB.new(0.811764705882353, 0.709803921568627, 0.231372549019608)
# Old Lace: #FDF5E6
OLD_LACE = RGB.new(0.992156862745098, 0.96078431372549, 0.901960784313726)
# Old Lavender: #796878
OLD_LAVENDER = RGB.new(0.474509803921569, 0.407843137254902, 0.470588235294118)
# Old Rose: #C08081
OLD_ROSE = RGB.new(0.752941176470588, 0.501960784313725, 0.505882352941176)
# Olive: #808000
OLIVE = RGB.new(0.501960784313725, 0.501960784313725, 0.0)
# Olive Drab: #6B8E23
OLIVE_DRAB = RGB.new(0.419607843137255, 0.556862745098039, 0.137254901960784)
# Orange (color wheel): #FF7500
ORANGE_COLOR_WHEEL = RGB.new(1.0, 0.498039215686275, 0.0)
ORANGE = ORANGE_COLOR_WHEEL
# Orange (web): #FFA500
ORANGE_WEB = RGB.new(1.0, 0.647058823529412, 0.0)
# Orange Peel: #FFA000
ORANGE_PEEL = RGB.new(1.0, 0.627450980392157, 0.0)
# Orchid: #DA70D6
ORCHID = RGB.new(0.854901960784314, 0.43921568627451, 0.83921568627451)
# Papaya whip: #FFEFD5
PAPAYA_WHIP = RGB.new(1.0, 0.937254901960784, 0.835294117647059)
# Pastel green: #77DD77
PASTEL_GREEN = RGB.new(0.466666666666667, 0.866666666666667, 0.466666666666667)
# Pastel pink: #FFD1DC
PASTEL_PINK = RGB.new(1.0, 0.819607843137255, 0.862745098039216)
# Peach: #FFE5B4
PEACH = RGB.new(1.0, 0.898039215686275, 0.705882352941177)
# Peach-orange: #FFCC99
PEACH_ORANGE = RGB.new(1.0, 0.8, 0.6)
# Peach-yellow: #FADFAD
PEACH_YELLOW = RGB.new(0.980392156862745, 0.874509803921569, 0.67843137254902)
# Pear: #D1E231
PEAR = RGB.new(0.819607843137255, 0.886274509803922, 0.192156862745098)
# Periwinkle: #CCCCFF
PERIWINKLE = RGB.new(0.8, 0.8, 1.0)
# Persian blue: #1C39BB
PERSIAN_BLUE = RGB.new(0.109803921568627, 0.223529411764706, 0.733333333333333)
# Persian green: #00A693
PERSIAN_GREEN = RGB.new(0.0, 0.650980392156863, 0.576470588235294)
# Persian indigo: #32127A
PERSIAN_INDIGO = RGB.new(0.196078431372549, 0.0705882352941176, 0.47843137254902)
# Persian pink: #F77FBE
PERSIAN_PINK = RGB.new(0.968627450980392, 0.498039215686275, 0.745098039215686)
# Persian red: #CC3333
PERSIAN_RED = RGB.new(0.8, 0.2, 0.2)
# Persian rose: #FF1CB1
PERSIAN_ROSE = RGB.new(1.0, 0.109803921568627, 0.694117647058824)
# Pine Green: #01796F
PINE_GREEN = RGB.new(0.00392156862745098, 0.474509803921569, 0.435294117647059)
# Pink: #FFC0CB
PINK = RGB.new(1.0, 0.752941176470588, 0.796078431372549)
# Pink-orange: #FF9966
PINK_ORANGE = RGB.new(1.0, 0.6, 0.4)
# Pomegranate: #F34723
POMEGRANATE = RGB.new(0.952941176470588, 0.27843137254902, 0.137254901960784)
# Powder blue (web): #B0E0E6
POWDER_BLUE_WEB = RGB.new(0.690196078431373, 0.87843137254902, 0.901960784313726)
# Puce: #CC8899
PUCE = RGB.new(0.8, 0.533333333333333, 0.6)
# Prussian blue: #003153
PRUSSIAN_BLUE = RGB.new(0.0, 0.192156862745098, 0.325490196078431)
# Pumpkin: #FF7518
PUMPKIN = RGB.new(1.0, 0.458823529411765, 0.0941176470588235)
# Purple: #660099
PURPLE = RGB.new(0.4, 0.0, 0.6)
# Raw umber: #734A12
RAW_UMBER = RGB.new(0.450980392156863, 0.290196078431373, 0.0705882352941176)
# Red: #FF0000
RED = RGB.new(1.0, 0.0, 0.0)
# Red-violet: #C71585
RED_VIOLET = RGB.new(0.780392156862745, 0.0823529411764706, 0.52156862745098)
# Robin egg blue: #00CCCC
ROBIN_EGG_BLUE = RGB.new(0.0, 0.8, 0.8)
# Rose: #FF007F
ROSE = RGB.new(1.0, 0.0, 0.498039215686275)
# Royal Blue: #4169E1
ROYAL_BLUE = RGB.new(0.254901960784314, 0.411764705882353, 0.882352941176471)
# Russet: #80461B
RUSSET = RGB.new(0.501960784313725, 0.274509803921569, 0.105882352941176)
# Rust: #B7410E
RUST = RGB.new(0.717647058823529, 0.254901960784314, 0.0549019607843137)
# Safety Orange (Blaze Orange): #FF6600
SAFETY_ORANGE = RGB.new(1.0, 0.4, 0.0)
BLAZE_ORANGE = SAFETY_ORANGE
# Saffron: #F4C430
SAFFRON = RGB.new(0.956862745098039, 0.768627450980392, 0.188235294117647)
# Sapphire: #082567
SAPPHIRE = RGB.new(0.0313725490196078, 0.145098039215686, 0.403921568627451)
# Salmon: #FF8C69
SALMON = RGB.new(1.0, 0.549019607843137, 0.411764705882353)
# Sandy brown: #F4A460
SANDY_BROWN = RGB.new(0.956862745098039, 0.643137254901961, 0.376470588235294)
# Sangria: #92000A
SANGRIA = RGB.new(0.572549019607843, 0.0, 0.0392156862745098)
# Scarlet: #FF2400
SCARLET = RGB.new(1.0, 0.141176470588235, 0.0)
# School bus yellow: #FFD800
SCHOOL_BUS_YELLOW = RGB.new(1.0, 0.847058823529412, 0.0)
# Sea Green: #2E8B57
SEA_GREEN = RGB.new(0.180392156862745, 0.545098039215686, 0.341176470588235)
# Seashell: #FFF5EE
SEASHELL = RGB.new(1.0, 0.96078431372549, 0.933333333333333)
# Selective yellow: #FFBA00
SELECTIVE_YELLOW = RGB.new(1.0, 0.729411764705882, 0.0)
# Sepia: #704214
SEPIA = RGB.new(0.43921568627451, 0.258823529411765, 0.0784313725490196)
# Shocking Pink: #FC0FC0
SHOCKING_PINK = RGB.new(0.988235294117647, 0.0588235294117647, 0.752941176470588)
# Silver: #C0C0C0
SILVER = RGB.new(0.752941176470588, 0.752941176470588, 0.752941176470588)
# Slate gray: #708090
SLATE_GRAY = RGB.new(0.43921568627451, 0.501960784313725, 0.564705882352941)
# Smalt (Dark powder blue): #003399
SMALT = RGB.new(0.0, 0.2, 0.6)
DARK_POWDER_BLUE = SMALT
# Spring Green: #00FF7F
SPRING_GREEN = RGB.new(0.0, 1.0, 0.498039215686275)
# Steel blue: #4682B4
STEEL_BLUE = RGB.new(0.274509803921569, 0.509803921568627, 0.705882352941177)
# Swamp green: #ACB78E
SWAMP_GREEN = RGB.new(0.674509803921569, 0.717647058823529, 0.556862745098039)
# Tan: #D2B48C
TAN = RGB.new(0.823529411764706, 0.705882352941177, 0.549019607843137)
# Tangerine: #FFCC00
TANGERINE = RGB.new(1.0, 0.8, 0.0)
# Taupe: #483C32
TAUPE = RGB.new(0.282352941176471, 0.235294117647059, 0.196078431372549)
# Tea Green: #D0F0C0
TEA_GREEN = RGB.new(0.815686274509804, 0.941176470588235, 0.752941176470588)
# Teal: #008080
TEAL = RGB.new(0.0, 0.501960784313725, 0.501960784313725)
# Tenné (Tawny): #CD5700
TENNE = RGB.new(0.803921568627451, 0.341176470588235, 0.0)
TAWNY = TENNE
# Terra cotta: #E2725B
TERRA_COTTA = RGB.new(0.886274509803922, 0.447058823529412, 0.356862745098039)
# Thistle: #D8BFD8
THISTLE = RGB.new(0.847058823529412, 0.749019607843137, 0.847058823529412)
# Turquoise: #30D5C8
TURQUOISE = RGB.new(0.188235294117647, 0.835294117647059, 0.784313725490196)
# Ultramarine: #120A8F
ULTRAMARINE = RGB.new(0.0705882352941176, 0.0392156862745098, 0.56078431372549)
# Vermilion: #FF4D00
VERMILION = RGB.new(1.0, 0.301960784313725, 0.0)
# Violet: #8B00FF
VIOLET = RGB.new(0.545098039215686, 0.0, 1.0)
# Violet-eggplant: #991199
VIOLET_EGGPLANT = RGB.new(0.6, 0.0666666666666667, 0.6)
# Viridian: #40826D
VIRIDIAN = RGB.new(0.250980392156863, 0.509803921568627, 0.427450980392157)
# Wheat: #F5DEB3
WHEAT = RGB.new(0.96078431372549, 0.870588235294118, 0.701960784313725)
# White: #FFFFFF
WHITE = RGB.new(1.0, 1.0, 1.0)
# Wisteria: #C9A0DC
WISTERIA = RGB.new(0.788235294117647, 0.627450980392157, 0.862745098039216)
# Yellow: #FFFF00
YELLOW = RGB.new(1.0, 1.0, 0.0)
# Zinnwaldite: #EBC2AF
ZINNWALDITE = RGB.new(0.92156862745098, 0.76078431372549, 0.686274509803922)
module X11
# Gray: #BEBEBE
GRAY = RGB.new(0.745098039215686, 0.745098039215686, 0.745098039215686)
# Green: #00FF00
GREEN = RGB.new(0.0, 1.0, 0.0)
# Maroon: #B03060
MAROON = RGB.new(0.690196078431373, 0.188235294117647, 0.376470588235294)
# Purple: #A020F0
PURPLE = RGB.new(0.627450980392157, 0.125490196078431, 0.941176470588235)
# Alice Blue: #F0F8FF
ALICE_BLUE = RGB.new(0.941176470588235, 0.972549019607843, 1.0)
# Antique White: #FAEBD7
ANTIQUE_WHITE = RGB.new(0.980392156862745, 0.92156862745098, 0.843137254901961)
# Aqua: #00FFFF
AQUA = RGB.new(0.0, 1.0, 1.0)
# Aquamarine: #7FFFD4
AQUAMARINE = RGB.new(0.498039215686275, 1.0, 0.831372549019608)
# Azure: #F0FFFF
AZURE = RGB.new(0.941176470588235, 1.0, 1.0)
# Beige: #F5F5DC
BEIGE = RGB.new(0.96078431372549, 0.96078431372549, 0.862745098039216)
# Bisque: #FFE4C4
BISQUE = RGB.new(1.0, 0.894117647058824, 0.768627450980392)
# Black: #000000
BLACK = RGB.new(0.0, 0.0, 0.0)
# Blanched Almond: #FFEBCD
BLANCHED_ALMOND = RGB.new(1.0, 0.92156862745098, 0.803921568627451)
# Blue: #0000FF
BLUE = RGB.new(0.0, 0.0, 1.0)
# Blue Violet: #8A2BE2
BLUE_VIOLET = RGB.new(0.541176470588235, 0.168627450980392, 0.886274509803922)
# Brown: #A52A2A
BROWN = RGB.new(0.647058823529412, 0.164705882352941, 0.164705882352941)
# Burly Wood: #DEB887
BURLY_WOOD = RGB.new(0.870588235294118, 0.72156862745098, 0.529411764705882)
# Cadet Blue: #5F9EA0
CADET_BLUE = RGB.new(0.372549019607843, 0.619607843137255, 0.627450980392157)
# Chartreuse: #7FFF00
CHARTREUSE = RGB.new(0.498039215686275, 1.0, 0.0)
# Chocolate: #D2691E
CHOCOLATE = RGB.new(0.823529411764706, 0.411764705882353, 0.117647058823529)
# Coral: #FF7F50
CORAL = RGB.new(1.0, 0.498039215686275, 0.313725490196078)
# Cornflower Blue: #6495ED
CORNFLOWER_BLUE = RGB.new(0.392156862745098, 0.584313725490196, 0.929411764705882)
# Cornsilk: #FFF8DC
CORNSILK = RGB.new(1.0, 0.972549019607843, 0.862745098039216)
# Crimson: #DC143C
CRIMSON = RGB.new(0.862745098039216, 0.0784313725490196, 0.235294117647059)
# Cyan: #00FFFF
CYAN = RGB.new(0.0, 1.0, 1.0)
# Dark Blue: #00008B
DARK_BLUE = RGB.new(0.0, 0.0, 0.545098039215686)
# Dark Cyan: #008B8B
DARK_CYAN = RGB.new(0.0, 0.545098039215686, 0.545098039215686)
# Dark Goldenrod: #B8860B
DARK_GOLDENROD = RGB.new(0.72156862745098, 0.525490196078431, 0.0431372549019608)
# Dark Gray: #A9A9A9
DARK_GRAY = RGB.new(0.662745098039216, 0.662745098039216, 0.662745098039216)
# Dark Green: #006400
DARK_GREEN = RGB.new(0.0, 0.392156862745098, 0.0)
# Dark Khaki: #BDB76B
DARK_KHAKI = RGB.new(0.741176470588235, 0.717647058823529, 0.419607843137255)
# Dark Magenta: #8B008B
DARK_MAGENTA = RGB.new(0.545098039215686, 0.0, 0.545098039215686)
# Dark Olive Green: #556B2F
DARK_OLIVE_GREEN = RGB.new(0.333333333333333, 0.419607843137255, 0.184313725490196)
# Dark Orange: #FF8C00
DARK_ORANGE = RGB.new(1.0, 0.549019607843137, 0.0)
# Dark Orchid: #9932CC
DARK_ORCHID = RGB.new(0.6, 0.196078431372549, 0.8)
# Dark Red: #8B0000
DARK_RED = RGB.new(0.545098039215686, 0.0, 0.0)
# Dark Salmon: #E9967A
DARK_SALMON = RGB.new(0.913725490196078, 0.588235294117647, 0.47843137254902)
# Dark Sea Green: #8FBC8F
DARK_SEA_GREEN = RGB.new(0.56078431372549, 0.737254901960784, 0.56078431372549)
# Dark Slate Blue: #483D8B
DARK_SLATE_BLUE = RGB.new(0.282352941176471, 0.23921568627451, 0.545098039215686)
# Dark Slate Gray: #2F4F4F
DARK_SLATE_GRAY = RGB.new(0.184313725490196, 0.309803921568627, 0.309803921568627)
# Dark Turquoise: #00CED1
DARK_TURQUOISE = RGB.new(0.0, 0.807843137254902, 0.819607843137255)
# Dark Violet: #9400D3
DARK_VIOLET = RGB.new(0.580392156862745, 0.0, 0.827450980392157)
# Deep Pink: #FF1493
DEEP_PINK = RGB.new(1.0, 0.0784313725490196, 0.576470588235294)
# Deep Sky Blue: #00BFFF
DEEP_SKY_BLUE = RGB.new(0.0, 0.749019607843137, 1.0)
# Dim Gray: #696969
DIM_GRAY = RGB.new(0.411764705882353, 0.411764705882353, 0.411764705882353)
# Dodger Blue: #1E90FF
DODGER_BLUE = RGB.new(0.117647058823529, 0.564705882352941, 1.0)
# Fire Brick: #B22222
FIRE_BRICK = RGB.new(0.698039215686274, 0.133333333333333, 0.133333333333333)
# Floral White: #FFFAF0
FLORAL_WHITE = RGB.new(1.0, 0.980392156862745, 0.941176470588235)
# Forest Green: #228B22
FOREST_GREEN = RGB.new(0.133333333333333, 0.545098039215686, 0.133333333333333)
# Fuchsia: #FF00FF
FUCHSIA = RGB.new(1.0, 0.0, 1.0)
# Gainsboro: #DCDCDC
GAINSBORO = RGB.new(0.862745098039216, 0.862745098039216, 0.862745098039216)
# Ghost White: #F8F8FF
GHOST_WHITE = RGB.new(0.972549019607843, 0.972549019607843, 1.0)
# Gold: #FFD700
GOLD = RGB.new(1.0, 0.843137254901961, 0.0)
# Goldenrod: #DAA520
GOLDENROD = RGB.new(0.854901960784314, 0.647058823529412, 0.125490196078431)
# Green Yellow: #ADFF2F
GREEN_YELLOW = RGB.new(0.67843137254902, 1.0, 0.184313725490196)
# Honeydew: #F0FFF0
HONEYDEW = RGB.new(0.941176470588235, 1.0, 0.941176470588235)
# Hot Pink: #FF69B4
HOT_PINK = RGB.new(1.0, 0.411764705882353, 0.705882352941177)
# Indian Red: #CD5C5C
INDIAN_RED = RGB.new(0.803921568627451, 0.36078431372549, 0.36078431372549)
# Indigo: #4B0082
INDIGO = RGB.new(0.294117647058824, 0.0, 0.509803921568627)
# Ivory: #FFFFF0
IVORY = RGB.new(1.0, 1.0, 0.941176470588235)
# Khaki: #F0E68C
KHAKI = RGB.new(0.941176470588235, 0.901960784313726, 0.549019607843137)
# Lavender: #E6E6FA
LAVENDER = RGB.new(0.901960784313726, 0.901960784313726, 0.980392156862745)
# Lavender Blush: #FFF0F5
LAVENDER_BLUSH = RGB.new(1.0, 0.941176470588235, 0.96078431372549)
# Lawn Green: #7CFC00
LAWN_GREEN = RGB.new(0.486274509803922, 0.988235294117647, 0.0)
# Lemon Chiffon: #FFFACD
LEMON_CHIFFON = RGB.new(1.0, 0.980392156862745, 0.803921568627451)
# Light Blue: #ADD8E6
LIGHT_BLUE = RGB.new(0.67843137254902, 0.847058823529412, 0.901960784313726)
# Light Coral: #F08080
LIGHT_CORAL = RGB.new(0.941176470588235, 0.501960784313725, 0.501960784313725)
# Light Cyan: #E0FFFF
LIGHT_CYAN = RGB.new(0.87843137254902, 1.0, 1.0)
# Light Goldenrod Yellow: #FAFAD2
LIGHT_GOLDENROD_YELLOW = RGB.new(0.980392156862745, 0.980392156862745, 0.823529411764706)
# Light Green: #90EE90
LIGHT_GREEN = RGB.new(0.564705882352941, 0.933333333333333, 0.564705882352941)
# Light Grey: #D3D3D3
LIGHT_GREY = RGB.new(0.827450980392157, 0.827450980392157, 0.827450980392157)
# Light Pink: #FFB6C1
LIGHT_PINK = RGB.new(1.0, 0.713725490196078, 0.756862745098039)
# Light Salmon: #FFA07A
LIGHT_SALMON = RGB.new(1.0, 0.627450980392157, 0.47843137254902)
# Light Sea Green: #20B2AA
LIGHT_SEA_GREEN = RGB.new(0.125490196078431, 0.698039215686274, 0.666666666666667)
# Light Sky Blue: #87CEFA
LIGHT_SKY_BLUE = RGB.new(0.529411764705882, 0.807843137254902, 0.980392156862745)
# Light Slate Gray: #778899
LIGHT_SLATE_GRAY = RGB.new(0.466666666666667, 0.533333333333333, 0.6)
# Light Steel Blue: #B0C4DE
LIGHT_STEEL_BLUE = RGB.new(0.690196078431373, 0.768627450980392, 0.870588235294118)
# Light Yellow: #FFFFE0
LIGHT_YELLOW = RGB.new(1.0, 1.0, 0.87843137254902)
# Lime: #00FF00
LIME = RGB.new(0.0, 1.0, 0.0)
# Lime Green: #32CD32
LIME_GREEN = RGB.new(0.196078431372549, 0.803921568627451, 0.196078431372549)
# Linen: #FAF0E6
LINEN = RGB.new(0.980392156862745, 0.941176470588235, 0.901960784313726)
# Magenta: #FF00FF
MAGENTA = RGB.new(1.0, 0.0, 1.0)
# Medium Aquamarine: #66CDAA
MEDIUM_AQUAMARINE = RGB.new(0.4, 0.803921568627451, 0.666666666666667)
# Medium Blue: #0000CD
MEDIUM_BLUE = RGB.new(0.0, 0.0, 0.803921568627451)
# Medium Orchid: #BA55D3
MEDIUM_ORCHID = RGB.new(0.729411764705882, 0.333333333333333, 0.827450980392157)
# Medium Purple: #9370DB
MEDIUM_PURPLE = RGB.new(0.576470588235294, 0.43921568627451, 0.858823529411765)
# Medium Sea Green: #3CB371
MEDIUM_SEA_GREEN = RGB.new(0.235294117647059, 0.701960784313725, 0.443137254901961)
# Medium Slate Blue: #7B68EE
MEDIUM_SLATE_BLUE = RGB.new(0.482352941176471, 0.407843137254902, 0.933333333333333)
# Medium Spring Green: #00FA9A
MEDIUM_SPRING_GREEN = RGB.new(0.0, 0.980392156862745, 0.603921568627451)
# Medium Turquoise: #48D1CC
MEDIUM_TURQUOISE = RGB.new(0.282352941176471, 0.819607843137255, 0.8)
# Medium Violet Red: #C71585
MEDIUM_VIOLET_RED = RGB.new(0.780392156862745, 0.0823529411764706, 0.52156862745098)
# Midnight Blue: #191970
MIDNIGHT_BLUE = RGB.new(0.0980392156862745, 0.0980392156862745, 0.43921568627451)
# Mint Cream: #F5FFFA
MINT_CREAM = RGB.new(0.96078431372549, 1.0, 0.980392156862745)
# Misty Rose: #FFE4E1
MISTY_ROSE = RGB.new(1.0, 0.894117647058824, 0.882352941176471)
# Moccasin: #FFE4B5
MOCCASIN = RGB.new(1.0, 0.894117647058824, 0.709803921568627)
# Navajo White: #FFDEAD
NAVAJO_WHITE = RGB.new(1.0, 0.870588235294118, 0.67843137254902)
# Old Lace: #FDF5E6
OLD_LACE = RGB.new(0.992156862745098, 0.96078431372549, 0.901960784313726)
# Olive: #808000
OLIVE = RGB.new(0.501960784313725, 0.501960784313725, 0.0)
# Olive Drab: #6B8E23
OLIVE_DRAB = RGB.new(0.419607843137255, 0.556862745098039, 0.137254901960784)
# Orange: #FFA500
ORANGE = RGB.new(1.0, 0.647058823529412, 0.0)
# Orange Red: #FF4500
ORANGE_RED = RGB.new(1.0, 0.270588235294118, 0.0)
# Orchid: #DA70D6
ORCHID = RGB.new(0.854901960784314, 0.43921568627451, 0.83921568627451)
# Pale Goldenrod: #EEE8AA
PALE_GOLDENROD = RGB.new(0.933333333333333, 0.909803921568627, 0.666666666666667)
# Pale Green: #98FB98
PALE_GREEN = RGB.new(0.596078431372549, 0.984313725490196, 0.596078431372549)
# Pale Turquoise: #AFEEEE
PALE_TURQUOISE = RGB.new(0.686274509803922, 0.933333333333333, 0.933333333333333)
# Pale Violet Red: #DB7093
PALE_VIOLET_RED = RGB.new(0.858823529411765, 0.43921568627451, 0.576470588235294)
# Papaya Whip: #FFEFD5
PAPAYA_WHIP = RGB.new(1.0, 0.937254901960784, 0.835294117647059)
# Peach Puff: #FFDAB9
PEACH_PUFF = RGB.new(1.0, 0.854901960784314, 0.725490196078431)
# Peru: #CD853F
PERU = RGB.new(0.803921568627451, 0.52156862745098, 0.247058823529412)
# Pink: #FFC0CB
PINK = RGB.new(1.0, 0.752941176470588, 0.796078431372549)
# Plum: #DDA0DD
PLUM = RGB.new(0.866666666666667, 0.627450980392157, 0.866666666666667)
# Powder Blue: #B0E0E6
POWDER_BLUE = RGB.new(0.690196078431373, 0.87843137254902, 0.901960784313726)
# Red: #FF0000
RED = RGB.new(1.0, 0.0, 0.0)
# Rosy Brown: #BC8F8F
ROSY_BROWN = RGB.new(0.737254901960784, 0.56078431372549, 0.56078431372549)
# Royal Blue: #4169E1
ROYAL_BLUE = RGB.new(0.254901960784314, 0.411764705882353, 0.882352941176471)
# Saddle Brown: #8B4513
SADDLE_BROWN = RGB.new(0.545098039215686, 0.270588235294118, 0.0745098039215686)
# Salmon: #FA8072
SALMON = RGB.new(0.980392156862745, 0.501960784313725, 0.447058823529412)
# Sandy Brown: #F4A460
SANDY_BROWN = RGB.new(0.956862745098039, 0.643137254901961, 0.376470588235294)
# Sea Green: #2E8B57
SEA_GREEN = RGB.new(0.180392156862745, 0.545098039215686, 0.341176470588235)
# Seashell: #FFF5EE
SEASHELL = RGB.new(1.0, 0.96078431372549, 0.933333333333333)
# Sienna: #A0522D
SIENNA = RGB.new(0.627450980392157, 0.32156862745098, 0.176470588235294)
# Silver: #C0C0C0
SILVER = RGB.new(0.752941176470588, 0.752941176470588, 0.752941176470588)
# Sky Blue: #87CEEB
SKY_BLUE = RGB.new(0.529411764705882, 0.807843137254902, 0.92156862745098)
# Slate Blue: #6A5ACD
SLATE_BLUE = RGB.new(0.415686274509804, 0.352941176470588, 0.803921568627451)
# Slate Gray: #708090
SLATE_GRAY = RGB.new(0.43921568627451, 0.501960784313725, 0.564705882352941)
# Snow: #FFFAFA
SNOW = RGB.new(1.0, 0.980392156862745, 0.980392156862745)
# Spring Green: #00FF7F
SPRING_GREEN = RGB.new(0.0, 1.0, 0.498039215686275)
# Steel Blue: #4682B4
STEEL_BLUE = RGB.new(0.274509803921569, 0.509803921568627, 0.705882352941177)
# Tan: #D2B48C
TAN = RGB.new(0.823529411764706, 0.705882352941177, 0.549019607843137)
# Teal: #008080
TEAL = RGB.new(0.0, 0.501960784313725, 0.501960784313725)
# Thistle: #D8BFD8
THISTLE = RGB.new(0.847058823529412, 0.749019607843137, 0.847058823529412)
# Tomato: #FF6347
TOMATO = RGB.new(1.0, 0.388235294117647, 0.27843137254902)
# Turquoise: #40E0D0
TURQUOISE = RGB.new(0.250980392156863, 0.87843137254902, 0.815686274509804)
# Violet: #EE82EE
VIOLET = RGB.new(0.933333333333333, 0.509803921568627, 0.933333333333333)
# Wheat: #F5DEB3
WHEAT = RGB.new(0.96078431372549, 0.870588235294118, 0.701960784313725)
# White: #FFFFFF
WHITE = RGB.new(1.0, 1.0, 1.0)
# White Smoke: #F5F5F5
WHITE_SMOKE = RGB.new(0.96078431372549, 0.96078431372549, 0.96078431372549)
# Yellow: #FFFF00
YELLOW = RGB.new(1.0, 1.0, 0.0)
# Yellow Green: #9ACD32
YELLOW_GREEN = RGB.new(0.603921568627451, 0.803921568627451, 0.196078431372549)
end
include X11
end
end
cairo-1.12.8/lib/cairo/color.rb 0000644 0000041 0000041 00000014406 12256106703 016245 0 ustar www-data www-data module Cairo
module Color
module_function
def parse(value, robust=false)
return value.dup if value.is_a?(Base)
case value
when Array
case value.first
when :cmyk, :cmyka
CMYK.new(*value[1..-1])
when :hsv, :hsva
HSV.new(*value[1..-1])
else
_, *value = value if [:rgb, :rgba].include?(value.first)
RGB.new(*value)
end
when /\A#/ #
parse_hex_color(value)
when String, Symbol
name = Cairo.normalize_const_name(value)
begin
const_get(name).dup
rescue NameError
raise ArgumentError, "unknown color name: #{value}"
end
else
if robust
raise ArgumentError, "can't parse as color name: #{value.inspect}"
end
value
end
end
HEX_RE = "(?i:[a-f\\d])"
def parse_hex_color(value)
case value
when /\A#((?:#{HEX_RE}){3,4})\z/ #
RGB.new(*$1.scan(/./).collect {|part| part.hex / 15.0})
when /\A#((?:#{HEX_RE}{2,2}){3,4})\z/ #
RGB.new(*$1.scan(/.{2,2}/).collect {|part| part.hex / 255.0})
when /\A#((?:#{HEX_RE}{4,4}){3,4})\z/ #
RGB.new(*$1.scan(/.{4,4}/).collect {|part| part.hex / 65535.0})
else
message = "invalid hex color format: #{value} should be "
message << "#RGB, #RGBA, #RRGGBB, #RRGGBBAA, #RRRRGGGGBBBB "
message << "or #RRRRGGGGBBBBAAAA"
raise ArgumentError, message
end
end
class Base
attr_accessor :alpha
alias_method :a, :alpha
alias_method :a=, :alpha=
def initialize(a)
assert_in_range(a, "alpha channel")
@alpha = a
end
private
def assert_in_range(value, description)
unless (0.0..1.0).include?(value)
raise ArgumentError,
"#{description} value should be in [0.0, 1.0]: #{value.inspect}"
end
end
end
class RGB < Base
attr_accessor :red, :green, :blue
alias_method :r, :red
alias_method :r=, :red=
alias_method :g, :green
alias_method :g=, :green=
alias_method :b, :blue
alias_method :b=, :blue=
def initialize(r, g, b, a=1.0)
super(a)
assert_in_range(r, "red")
assert_in_range(g, "green")
assert_in_range(b, "blue")
@red = r
@green = g
@blue = b
end
def hash
to_s.hash
end
def eql?(other)
self == other
end
def ==(other)
other.is_a?(self.class) and other.to_s == to_s
end
def to_a
[@red, @green, @blue, @alpha]
end
alias_method :to_ary, :to_a
def to_s
"#%02X%02X%02X%02X" % to_a.collect {|v| (v * 255).ceil}
end
def to_rgb
clone
end
def to_cmyk
cmy = [1.0 - @red, 1.0 - @green, 1.0 - @blue]
key_plate = cmy.min
if key_plate < 1.0
one_k = 1.0 - key_plate
cmyk = cmy.collect {|value| (value - key_plate) / one_k} + [key_plate]
else
cmyk = [0, 0, 0, key_plate]
end
cmyka = cmyk + [@alpha]
CMYK.new(*cmyka)
end
def to_hsv
max = [@red, @blue, @green].max
if max > 0
min = [@red, @blue, @green].min
max_min = max - min
case max
when @red
numerator = @green - @blue
angle = 0
when @green
numerator = @blue - @red
angle = 120
when @blue
numerator = @red - @green
angle = 240
end
h = max_min > 0 ? 60 * numerator / max_min + angle : 0.0
s = max_min / max
else
h = 0.0
s = 0.0
end
v = max
HSV.new(h, s, v, @alpha)
end
end
class CMYK < Base
attr_accessor :cyan, :magenta, :yellow, :key_plate
alias_method :c, :cyan
alias_method :c=, :cyan=
alias_method :m, :magenta
alias_method :m=, :magenta=
alias_method :y, :yellow
alias_method :y=, :yellow=
alias_method :k, :key_plate
alias_method :k=, :key_plate=
def initialize(c, m, y, k, a=1.0)
super(a)
assert_in_range(c, "cyan")
assert_in_range(m, "magenta")
assert_in_range(y, "yellow")
assert_in_range(k, "key plate")
@cyan = c
@magenta = m
@yellow = y
@key_plate = k
end
def to_a
[@cyan, @magenta, @yellow, @key_plate, @alpha]
end
alias_method :to_ary, :to_a
def to_rgb
one_k = 1.0 - @key_plate
rgba = [
(1.0 - @cyan) * one_k,
(1.0 - @magenta) * one_k,
(1.0 - @yellow) * one_k,
@alpha,
]
RGB.new(*rgba)
end
def to_cmyk
clone
end
def to_hsv
to_rgb.to_hsv
end
end
class HSV < Base
attr_accessor :hue, :saturation, :value
alias_method :h, :hue
alias_method :h=, :hue=
alias_method :s, :saturation
alias_method :s=, :saturation=
alias_method :v, :value
alias_method :v=, :value=
def initialize(h, s, v, a=1.0)
super(a)
assert_in_range(s, "saturation")
assert_in_range(v, "value")
@hue = h.modulo(360.0)
@saturation = s
@value = v
end
def to_a
[@hue, @saturation, @value, @alpha]
end
alias_method :to_ary, :to_a
def to_rgb
if s > 0
h_60 = @hue / 60.0
hi = h_60.floor.modulo(6)
f = h_60 - hi
p = @value * (1 - @saturation)
q = @value * (1 - f * @saturation)
t = @value * (1 - (1 - f) * @saturation)
case hi
when 0
rgb = [@value, t, p]
when 1
rgb = [q, @value, p]
when 2
rgb = [p, @value, t]
when 3
rgb = [p, q, @value]
when 4
rgb = [t, p, @value]
when 5
rgb = [@value, p, q]
end
rgba = rgb + [@alpha]
RGB.new(*rgba)
else
RGB.new(@value, @value, @value, @alpha)
end
end
def to_cmyk
to_rgb.to_cmyk
end
def to_hsv
clone
end
end
end
end
cairo-1.12.8/lib/cairo/constants.rb 0000644 0000041 0000041 00000001613 12256106703 017137 0 ustar www-data www-data module Cairo
define_constants = Proc.new do |const_module, prefix, target|
target ||= self
const_module.constants.each do |const_name|
target.const_set([prefix, const_name].compact.join("_"),
const_module.const_get(const_name))
end
end
%w(operator antialias fill_rule line_cap line_join font_slant
font_weight subpixel_order hint_style hint_metrics content
format extend filter).each do |name|
module_name = name.split(/_/).collect {|component| component.capitalize}.join
define_constants.call(const_get(module_name), name.upcase)
end
define_constants.call(PathDataType, "PATH")
define_constants.call(PathDataType, nil, Path)
define_constants.call(SVGVersion, nil, SVGSurface)
define_constants.call(SVGVersion, "SVG")
if const_defined?(:TextClusterFlag)
define_constants.call(TextClusterFlag, "TEXT_CLUSTER_FLAG")
end
end
cairo-1.12.8/lib/cairo/surface.rb 0000644 0000041 0000041 00000000406 12256106703 016552 0 ustar www-data www-data module Cairo
class Surface
class << self
def supported?(type)
supported_predicate = "#{type.to_s.downcase}_supported?"
return false unless respond_to?(supported_predicate)
send(supported_predicate)
end
end
end
end
cairo-1.12.8/lib/cairo/paper.rb 0000644 0000041 0000041 00000011775 12256106703 016244 0 ustar www-data www-data module Cairo
class Paper
class ParseError < ArgumentError
end
class UnknownPaperName < ParseError
attr_reader :name
def initialize(name)
@name = name
super("unknown paper name: #{name}")
end
end
class UnknownUnit < ParseError
attr_reader :unit
def initialize(unit)
@unit = unit
super("unknown unit: #{unit}")
end
end
class UnrecognizedPaperDescription < ParseError
attr_reader :description
def initialize(description)
@description = description
super("unrecognized paper description: #{description.inspect}")
end
end
class << self
def parse(paper_description, robust=false)
case paper_description
when Paper
return paper_description.dup
when Symbol
paper = resolve_constant(paper_description)
return paper.dup if paper
raise UnknownPaperName.new(paper_description)
when String
paper = resolve_constant(paper_description)
paper ||= parse_size(paper_description)
return paper.dup if paper
when Array
return new(*paper_description)
end
raise UnrecognizedPaperDescription.new(paper_description) if robust
nil
end
@@default_unit = nil
def default_unit
@@default_unit
end
def default_unit=(unit)
@@default_unit = unit
end
@@unit_resolvers = {}
def register_unit_resolver(from_units, to_units, &resolver)
from_units = [from_units] unless from_units.is_a?(Array)
to_units = [to_units] unless to_units.is_a?(Array)
from_units.each do |from_unit|
@@unit_resolvers[from_unit] ||= []
to_units.each do |unit|
@@unit_resolvers[from_unit] << [unit, resolver]
end
end
end
def resolve_unit(size, from_unit, to_unit)
from_unit ||= default_unit
return size if from_unit == to_unit
from_units = @@unit_resolvers[from_unit] || []
raise UnknownUnit.new(from_unit) if from_units.empty?
from_units.each do |unit, resolver|
return resolver.call(size) if to_unit == unit
end
raise UnknownUnit.new(to_unit)
end
private
def resolve_constant(name)
name = name.to_s.upcase.gsub(/\s+|-/, '_')
if /\A[A-Z]/ =~ name and const_defined?(name)
const_get(name)
else
nil
end
end
def parse_size(size)
size_re = /(\d+(\.\d*)?)/
unit_re = /([a-zA-Z]+?)/
if /\A#{size_re}#{unit_re}?x#{size_re}#{unit_re}?(?:#(.*))?\z/ !~ size
return nil
end
width = $1
width_fractional = $2
width_unit = $3
height = $4
height_fractional = $5
height_unit = $6
name = $7
width = width_fractional ? Float(width) : Integer(width)
height = height_fractional ? Float(height) : Integer(height)
new(resolve_unit(width, width_unit, "pt"),
resolve_unit(height, height_unit, "pt"),
nil, name)
end
end
self.default_unit = "pt"
register_unit_resolver("pt", ["in", "inch"]) {|size| size / 72.0}
register_unit_resolver(["in", "inch"], "pt") {|size| size * 72}
register_unit_resolver("pt", "mm") {|size| size * 25.4 / 72.0}
register_unit_resolver("mm", "pt") {|size| size / 25.4 * 72}
register_unit_resolver("pt", "cm") {|size| size * 2.54 / 72.0}
register_unit_resolver("cm", "pt") {|size| size / 2.54 * 72}
register_unit_resolver("pt", "m") {|size| size * 0.0254 / 72.0}
register_unit_resolver("m", "pt") {|size| size / 0.0254 * 72}
attr_reader :unit
attr_writer :width, :height
attr_accessor :name
def initialize(width, height, unit=nil, name=nil)
@width = width
@height = height
@unit = unit
@name = name
end
def unit=(unit)
if @unit != unit
@width = self.class.resolve_unit(width, @unit, unit)
@height = self.class.resolve_unit(height, @unit, unit)
end
@unit = unit
end
def width(unit=nil)
return @width if unit.nil?
self.class.resolve_unit(@width, @unit, unit)
end
def height(unit=nil)
return @height if unit.nil?
self.class.resolve_unit(@height, @unit, unit)
end
def size(unit=nil)
[width(unit), height(unit)]
end
def ==(other)
other.is_a?(self.class) and @name == other.name and
width_in_delta?(other.width(@unit)) and
height_in_delta?(other.height(@unit))
end
def to_s
string = "#{@width}#{@unit}x#{@height}#{@unit}"
string << "\##{@name}" if @name
string
end
private
def width_in_delta?(value, delta=nil)
in_delta?(@width, delta, value)
end
def height_in_delta?(value, delta=nil)
in_delta?(@height, delta, value)
end
def in_delta?(value, delta, other)
delta ||= 0.001
value - delta < other and other < value + delta
end
end
end
cairo-1.12.8/lib/cairo.rb 0000644 0000041 0000041 00000006274 12256106703 015133 0 ustar www-data www-data # vim: filetype=ruby:expandtab:shiftwidth=2:tabstop=8:softtabstop=2 :
if /mingw|mswin|mswin32/ =~ RUBY_PLATFORM
require 'pathname'
base_dir = Pathname(File.dirname(__FILE__))
base_dir = base_dir.parent + "vendor" + "local"
if base_dir.exist?
base_dir = base_dir.to_s.gsub(/\//, "\\")
ENV['PATH'] = %w(bin lib).collect do |dir|
"#{base_dir}\\#{dir};"
end.join('') + ENV['PATH']
else
require 'rbconfig'
ENV['PATH'] = %w(bin lib).collect do |dir|
"#{RbConfig::CONFIG["prefix"]}\\lib\\GTK\\#{dir};"
end.join('') + ENV['PATH']
end
end
module Cairo
class << self
def __add_one_arg_setter(klass)
names = klass.instance_methods(false)
names.each do |name|
if /^set_(.*)/ =~ name and
not names.include? "#{$1}=" and
klass.instance_method(name).arity == 1
klass.module_eval("def #{$1}=(val); set_#{$1}(val); val; end")
end
end
end
def normalize_const_name(name)
name.to_s.upcase.gsub(/[\s\-_.]+/, "_")
end
end
end
require 'cairo/color'
require 'cairo/paper'
begin
major, minor, _ = RUBY_VERSION.split(/\./)
require "#{major}.#{minor}/cairo.so"
rescue LoadError
require 'cairo.so'
end
require 'cairo/constants'
module Cairo
class << self
undef __add_one_arg_setter
def bindings_version
major, minor, micro, tag = BINDINGS_VERSION
version = [major, minor, micro].join('.')
version << "-#{tag}" if tag
version
end
def exit_application(exception, status)
puts("#{exception.class}: #{exception}")
puts(exception.backtrace)
exit(status)
end
end
class Surface
def dup
raise NotImplementedError
end
def clone
raise NotImplementedError
end
end
if const_defined?("PSLevel")
module PSLevel
class << self
def names
list.collect {|version| name(version)}
end
end
end
end
if const_defined?("SVGVersion")
module SVGVersion
class << self
def names
list.collect {|version| name(version)}
end
end
end
end
if const_defined?("SVGSurface")
class SVGSurface
class << self
def versions_as_string
SVGVersion.names
end
def versions
SVGVersion.list
end
def version_to_string(version)
SVGVersion.name(version)
end
end
end
end
class Matrix
def dup
Matrix.new(*to_a)
end
def clone
copy = dup
copy.freeze if self.frozen?
copy
end
def translate(tx, ty); dup.translate!(tx, ty); end
def scale(sx, sy); dup.scale!(sx, sy); end
def rotate(radians); dup.rotate!(radians); end
def invert; dup.invert!; end
def multiply(other); dup.multiply!(other); end
alias_method :*, :multiply
end
class FontOptions
def merge(other)
dup.merge!(other)
end
end
end
require 'cairo/point'
require 'cairo/colors'
require 'cairo/papers'
require 'cairo/context'
require 'cairo/device'
require 'cairo/surface'
require 'cairo/pattern'
require 'cairo/path'
module Cairo
if const_defined?(:Win32Surface)
WIN32Surface = Win32Surface # For backward compatibility
end
end
cairo-1.12.8/samples/ 0000755 0000041 0000041 00000000000 12256106703 014376 5 ustar www-data www-data cairo-1.12.8/samples/pac-tee.rb 0000644 0000041 0000041 00000010367 12256106703 016250 0 ustar www-data www-data =begin
pac-tee.rb - rcairo sample script with TeeSurface.
Original: pac.rb in http://www.artima.com/rubycs/articles/pdf_writer3.html
=end
top = File.expand_path(File.join(File.dirname(__FILE__), ".."))
$LOAD_PATH.unshift File.join(top, "ext", "cairo")
$LOAD_PATH.unshift File.join(top, "lib")
require "cairo"
def pac(surface, width, height)
cr = Cairo::Context.new(surface)
# NOTE: You may need to set line width when use Cairo::Context#scale
cr.set_line_width(cr.line_width / [width, height].max)
cr.scale(width, height)
cr.save do
cr.set_source_color(:black)
cr.rectangle(0, 0, 1, 1)
cr.fill
end
# Wall
wall_width = 0.89
wall_height = 0.03
wall_space = 0.5
wall_x = 0.02
wall1_y = 1 - 0.86
wall2_y = wall1_y + wall_space
wall_radius = 0.01
cr.set_source_color(:magenta)
cr.rounded_rectangle(wall_x, wall1_y, wall_width, wall_height, wall_radius)
cr.fill
cr.set_source_color(:cyan)
cr.rounded_rectangle(wall_x, wall1_y, wall_width, wall_height, wall_radius)
cr.stroke
cr.set_source_color(:magenta)
cr.rounded_rectangle(wall_x, wall2_y, wall_width, wall_height, wall_radius)
cr.fill
cr.set_source_color(:cyan)
cr.rounded_rectangle(wall_x, wall2_y, wall_width, wall_height, wall_radius)
cr.stroke
# Body
body_x = 0.17
body_y = 1 - 0.58
body_width = 0.23
body_height = 0.33
cr.save do
cr.translate(body_x, body_y)
cr.set_source_color(:yellow)
cr.scale(body_width, body_height)
cr.arc(0, 0, 0.5, 30 * (Math::PI / 180), 330 * (Math::PI / 180))
cr.line_to(0, 0)
cr.close_path
cr.fill
end
# Dot
dot_width = 0.02
dot_height = 0.03
small_dot_width = 0.01
small_dot_height = 0.015
dot_x = 0.29
dot_y = 1 - 0.58
dot_step = 0.05
cr.save do
cr.set_source_color(:yellow)
cr.save do
cr.translate(dot_x, dot_y)
cr.scale(dot_width, dot_height)
cr.circle(0, 0, 1).fill
end
4.times do |i|
cr.save do
cr.translate(dot_x + dot_step * (i + 1), dot_y)
cr.scale(small_dot_width, small_dot_height)
cr.circle(0, 0, 1).fill
end
end
end
# Ghost
ghost_x = 0.59
ghost_x_step = 0.03
ghost_y = 1 - 0.42
ghost_y_step = 0.04
ghost_width = 0.18
ghost_height = 0.29
ghost_radius= 0.08
cr.move_to(ghost_x, ghost_y)
cr.line_to(ghost_x, ghost_y - ghost_height)
cr.curve_to(ghost_x + ghost_width / 3.0,
ghost_y - ghost_height - ghost_radius,
ghost_x + ghost_width * (2.0 / 3.0),
ghost_y - ghost_height - ghost_radius,
ghost_x + ghost_width,
ghost_y - ghost_height)
cr.line_to(ghost_x + ghost_width, ghost_y)
i = 0
(ghost_x + ghost_width).step(ghost_x, -ghost_x_step) do |x|
cr.line_to(x, ghost_y + -ghost_y_step * (i % 2))
i += 1
end
cr.close_path
cr.set_source_color(:blue)
cr.fill_preserve
cr.set_source_color(:cyan)
cr.stroke
# Ghost Eyes
eye_x = 0.62
eye_y = 1 - 0.63
eye_space = 0.06
white_eye_width = 0.03
white_eye_height = 0.04
black_eye_width = 0.01
black_eye_height = 0.02
cr.set_source_color(:white)
cr.rectangle(eye_x, eye_y - white_eye_height,
white_eye_width, white_eye_height)
cr.fill
cr.rectangle(eye_x + eye_space, eye_y - white_eye_height,
white_eye_width, white_eye_height)
cr.fill
cr.set_source_color(:black)
cr.rectangle(eye_x, eye_y - black_eye_height,
black_eye_width, black_eye_height)
cr.fill
cr.rectangle(eye_x + eye_space, eye_y - black_eye_height,
black_eye_width, black_eye_height)
cr.fill
cr.show_page
end
paper = Cairo::Paper.parse(:a4_landscape)
size_in_points = paper.size("pt")
image_surface = Cairo::ImageSurface.new(*size_in_points)
tee_surface = Cairo::TeeSurface.new(image_surface)
add_scalable_surface = Proc.new do |surface_class_name, suffix|
if Cairo.const_defined?(surface_class_name)
surface_class = Cairo.const_get(surface_class_name)
tee_surface << surface_class.new("pac-tee.#{suffix}", paper)
else
puts("#{surface_class_name} isn't supported.")
end
end
add_scalable_surface.call("PSSurface", "ps")
add_scalable_surface.call("PDFSurface", "pdf")
add_scalable_surface.call("SVGSurface", "svg")
pac(tee_surface, *size_in_points)
image_surface.write_to_png("pac-tee.png")
cairo-1.12.8/samples/pac-nomralize.rb 0000644 0000041 0000041 00000010427 12256106703 017470 0 ustar www-data www-data =begin
pac-normalize.rb - rcairo sample script with #scale and #translate.
Original: pac.rb in http://www.artima.com/rubycs/articles/pdf_writer3.html
=end
top = File.expand_path(File.join(File.dirname(__FILE__), ".."))
$LOAD_PATH.unshift File.join(top, "ext", "cairo")
$LOAD_PATH.unshift File.join(top, "lib")
require "cairo"
def pac(surface, width, height)
cr = Cairo::Context.new(surface)
# NOTE: You may need to set line width when use Cairo::Context#scale
cr.set_line_width(cr.line_width / [width, height].max)
cr.scale(width, height)
cr.save do
cr.set_source_color(:black)
cr.rectangle(0, 0, 1, 1)
cr.fill
end
# Wall
wall_width = 0.89
wall_height = 0.03
wall_space = 0.5
wall_x = 0.02
wall1_y = 1 - 0.86
wall2_y = wall1_y + wall_space
wall_radius = 0.01
cr.set_source_color(:magenta)
cr.rounded_rectangle(wall_x, wall1_y, wall_width, wall_height, wall_radius)
cr.fill
cr.set_source_color(:cyan)
cr.rounded_rectangle(wall_x, wall1_y, wall_width, wall_height, wall_radius)
cr.stroke
cr.set_source_color(:magenta)
cr.rounded_rectangle(wall_x, wall2_y, wall_width, wall_height, wall_radius)
cr.fill
cr.set_source_color(:cyan)
cr.rounded_rectangle(wall_x, wall2_y, wall_width, wall_height, wall_radius)
cr.stroke
# Body
body_x = 0.17
body_y = 1 - 0.58
body_width = 0.23
body_height = 0.33
cr.save do
cr.translate(body_x, body_y)
cr.set_source_color(:yellow)
cr.scale(body_width, body_height)
cr.arc(0, 0, 0.5, 30 * (Math::PI / 180), 330 * (Math::PI / 180))
cr.line_to(0, 0)
cr.close_path
cr.fill
end
# Dot
dot_width = 0.02
dot_height = 0.03
small_dot_width = 0.01
small_dot_height = 0.015
dot_x = 0.29
dot_y = 1 - 0.58
dot_step = 0.05
cr.save do
cr.set_source_color(:yellow)
cr.save do
cr.translate(dot_x, dot_y)
cr.scale(dot_width, dot_height)
cr.circle(0, 0, 1).fill
end
4.times do |i|
cr.save do
cr.translate(dot_x + dot_step * (i + 1), dot_y)
cr.scale(small_dot_width, small_dot_height)
cr.circle(0, 0, 1).fill
end
end
end
# Ghost
ghost_x = 0.59
ghost_x_step = 0.03
ghost_y = 1 - 0.42
ghost_y_step = 0.04
ghost_width = 0.18
ghost_height = 0.29
ghost_radius= 0.08
cr.move_to(ghost_x, ghost_y)
cr.line_to(ghost_x, ghost_y - ghost_height)
cr.curve_to(ghost_x + ghost_width / 3.0,
ghost_y - ghost_height - ghost_radius,
ghost_x + ghost_width * (2.0 / 3.0),
ghost_y - ghost_height - ghost_radius,
ghost_x + ghost_width,
ghost_y - ghost_height)
cr.line_to(ghost_x + ghost_width, ghost_y)
i = 0
(ghost_x + ghost_width).step(ghost_x, -ghost_x_step) do |x|
cr.line_to(x, ghost_y + -ghost_y_step * (i % 2))
i += 1
end
cr.close_path
cr.set_source_color(:blue)
cr.fill_preserve
cr.set_source_color(:cyan)
cr.stroke
# Ghost Eyes
eye_x = 0.62
eye_y = 1 - 0.63
eye_space = 0.06
white_eye_width = 0.03
white_eye_height = 0.04
black_eye_width = 0.01
black_eye_height = 0.02
cr.set_source_color(:white)
cr.rectangle(eye_x, eye_y - white_eye_height,
white_eye_width, white_eye_height)
cr.fill
cr.rectangle(eye_x + eye_space, eye_y - white_eye_height,
white_eye_width, white_eye_height)
cr.fill
cr.set_source_color(:black)
cr.rectangle(eye_x, eye_y - black_eye_height,
black_eye_width, black_eye_height)
cr.fill
cr.rectangle(eye_x + eye_space, eye_y - black_eye_height,
black_eye_width, black_eye_height)
cr.fill
cr.show_page
end
paper = Cairo::Paper.parse(:a4_landscape)
size_in_points = paper.size("pt")
Cairo::ImageSurface.new(*size_in_points) do |surface|
cr = pac(surface, *size_in_points)
cr.target.write_to_png("pac-normalize.png")
end
scalable_surface_output = Proc.new do |surface_class_name, suffix|
if Cairo.const_defined?(surface_class_name)
surface_class = Cairo.const_get(surface_class_name)
surface_class.new("pac-normalize.#{suffix}", paper) do |surface|
pac(surface, *size_in_points)
end
else
puts("#{surface_class_name} isn't supported.")
end
end
scalable_surface_output.call("PSSurface", "ps")
scalable_surface_output.call("PDFSurface", "pdf")
scalable_surface_output.call("SVGSurface", "svg")
cairo-1.12.8/samples/blur.rb 0000755 0000041 0000041 00000002153 12256106703 015673 0 ustar www-data www-data #!/usr/bin/env ruby
top = File.expand_path(File.join(File.dirname(__FILE__), ".."))
$LOAD_PATH.unshift File.join(top, "ext", "cairo")
$LOAD_PATH.unshift File.join(top, "lib")
require 'cairo'
margin = 10
rectangle_width = 300
rectangle_height = 100
width = rectangle_width + 2 * margin
height = (rectangle_height + 2 * margin) * 3
surface = Cairo::ImageSurface.new(width, height)
context = Cairo::Context.new(surface)
context.set_source_color(:white)
context.paint
module Cairo
module Color
GRAY30 = Cairo::Color::RGB.new(0.3, 0.3, 0.3)
end
end
context.set_source_color(:gray30)
context.rectangle(margin, margin, rectangle_width, rectangle_height)
context.fill
context.pseudo_blur do
context.set_source_color(:gray30)
context.rectangle(margin, rectangle_height + 2 * margin + margin / 2,
rectangle_width, rectangle_height)
context.fill
end
context.pseudo_blur(5) do
context.set_source_color(:gray30)
context.rectangle(margin, (rectangle_height + 2 * margin) * 2 + margin / 2,
rectangle_width, rectangle_height)
context.fill
end
surface.write_to_png("blur.png")
cairo-1.12.8/samples/png.rb 0000755 0000041 0000041 00000001627 12256106703 015520 0 ustar www-data www-data #!/usr/bin/env ruby
top = File.expand_path(File.join(File.dirname(__FILE__), ".."))
$LOAD_PATH.unshift File.join(top, "ext", "cairo")
$LOAD_PATH.unshift File.join(top, "lib")
require 'cairo'
width = 200
height = 200
data = nil
stride = nil
Cairo::ImageSurface.new(width, height) do |surface|
cr = Cairo::Context.new(surface)
# fill background with white
cr.set_source_color("#fffc")
cr.paint
# create shape
cr.move_to(50, 50)
cr.curve_to(100, 25, 100, 75, 150, 50)
cr.line_to(150, 150)
cr.line_to(50, 150)
cr.close_path
cr.set_source_color(:black)
cr.fill_preserve
cr.set_source_color(:red)
cr.set_line_join(Cairo::LINE_JOIN_MITER)
cr.set_line_width(4)
cr.stroke
cr.target.write_to_png("test.png")
data = cr.target.data
stride = cr.target.stride
end
Cairo::ImageSurface.new(data, :argb32, width, height, stride) do |surface|
surface.write_to_png("test-renew.png")
end
cairo-1.12.8/samples/text2.rb 0000755 0000041 0000041 00000006627 12256106703 016007 0 ustar www-data www-data #!/usr/bin/env ruby
top = File.expand_path(File.join(File.dirname(__FILE__), ".."))
$LOAD_PATH.unshift File.join(top, "ext", "cairo")
$LOAD_PATH.unshift File.join(top, "lib")
require 'optparse'
require 'ostruct'
require 'cairo'
require 'pango'
def parse(args=ARGV)
options = OpenStruct.new
options.width = 595.275590551181.round
options.height = 841.889763779528.round
options.font_description = "Monospace 12"
options.fade_out = false
opts = OptionParser.new do |opts|
opts.on("--width=WIDTH", Integer, "paper width") do |width|
options.width = width
end
opts.on("--height=HEIGHT", Integer, "paper height") do |height|
options.height = height
end
opts.on("--font-description=DESCRIPTION",
"font description (e.g. 'Monospace 14')") do |desc|
options.font_description = desc
end
opts.on("--[no-]fade-out",
"fade-out one-third of page") do |fade_out|
options.fade_out = fade_out
end
end
opts.parse!(args)
options
end
def render_background(cr)
cr.set_source_color(:white)
cr.paint
end
def make_layout(cr, text, width, font_description)
layout = cr.create_pango_layout
layout.text = text
layout.width = width * Pango::SCALE
layout.font_description = Pango::FontDescription.new(font_description)
cr.update_pango_layout(layout)
layout
end
def setup_fade_out(cr, width)
fade_out = Cairo::LinearPattern.new(0, 0, width, 0)
fade_out.add_color_stop(0, "#000f")
fade_out.add_color_stop(0.66, "#000f")
fade_out.add_color_stop(1, "#0000")
cr.set_source(fade_out)
end
def render_layout(cr, layout, margin_left, margin_top, body_height)
x = margin_left
y = margin_top
limit_y = margin_top + body_height
iter = layout.iter
prev_baseline = iter.baseline / Pango::SCALE
begin
line = iter.line
ink_rect, logical_rect = iter.line_extents
y_begin, y_end = iter.line_yrange
if limit_y < (y + y_end / Pango::SCALE)
cr.show_page
y = margin_top - prev_baseline
end
baseline = iter.baseline / Pango::SCALE
cr.move_to(x + logical_rect.x / Pango::SCALE, y + baseline)
cr.show_pango_layout_line(line)
prev_baseline = baseline
end while iter.next_line!
end
def render(options, output, surface_class)
text = options.text
width = options.width
height = options.height
font_description = options.font_description
fade_out = options.fade_out
margin_left = (width * 0.05).ceil
margin_right = (width * 0.05).ceil
margin_top = (height * 0.05).ceil
margin_bottom = (height * 0.05).ceil
body_width = width - margin_left - margin_right
body_height = height - margin_top - margin_bottom
surface_class.new(output, width, height) do |surface|
cr = Cairo::Context.new(surface)
render_background(cr)
layout = make_layout(cr, text, body_width, font_description)
if fade_out
setup_fade_out(cr, body_width)
else
cr.set_source_color(:black)
end
render_layout(cr, layout, margin_left, margin_top, body_height)
cr.show_page
end
end
def output(options, surface_class_name, suffix)
if Cairo.const_defined?(surface_class_name)
surface_class = Cairo.const_get(surface_class_name)
render(options, "text2.#{suffix}", surface_class)
else
puts("#{surface_class_name} isn't supported.")
end
end
options = parse
options.text = ARGF.read
output(options, "PSSurface", "ps")
output(options, "PDFSurface", "pdf")
output(options, "SVGSurface", "svg")
cairo-1.12.8/samples/scalable.rb 0000755 0000041 0000041 00000002400 12256106703 016470 0 ustar www-data www-data #!/usr/bin/env ruby
top = File.expand_path(File.join(File.dirname(__FILE__), ".."))
$LOAD_PATH.unshift File.join(top, "ext", "cairo")
$LOAD_PATH.unshift File.join(top, "lib")
require 'cairo'
require 'stringio'
def render(output, surface_class)
surface_class.new(output, 200, 200) do |surface|
cr = Cairo::Context.new(surface)
# fill background with white
cr.set_source_color("#fffc")
cr.paint
# create shape
cr.move_to(50, 50)
cr.curve_to(100, 25, 100, 75, 150, 50)
cr.line_to(150, 150)
cr.line_to(50, 150)
cr.close_path
cr.set_source_color(:black)
cr.fill_preserve
cr.set_source_color(:red)
cr.set_line_join(Cairo::LINE_JOIN_MITER)
cr.set_line_width(4)
cr.stroke
cr.show_page
surface.finish
end
end
def output(surface_class_name, suffix)
if Cairo.const_defined?(surface_class_name)
surface_class = Cairo.const_get(surface_class_name)
render("test.#{suffix}", surface_class)
output = StringIO.new
render(output, surface_class)
output.rewind
File.open("test2.#{suffix}", "wb") do |f|
f.print(output.read)
end
else
puts("#{surface_class_name} isn't supported.")
end
end
output("PSSurface", "ps")
output("PDFSurface", "pdf")
output("SVGSurface", "svg")
cairo-1.12.8/samples/text-on-path.rb 0000755 0000041 0000041 00000002312 12256106703 017254 0 ustar www-data www-data #!/usr/bin/env ruby
top = File.expand_path(File.join(File.dirname(__FILE__), ".."))
$LOAD_PATH.unshift File.join(top, "ext", "cairo")
$LOAD_PATH.unshift File.join(top, "lib")
require 'cairo'
require 'pango'
def render_background(cr)
cr.set_source_color(:white)
cr.paint
end
def make_layout(cr, text)
layout = cr.create_pango_layout
layout.text = text
layout.font_description = Pango::FontDescription.new("Serif 36")
cr.update_pango_layout(layout)
layout
end
def render(surface)
text = "It was a dream... Oh Just a dream..."
cr = Cairo::Context.new(surface)
render_background(cr)
cr.set_source_color(:red)
cr.move_to(25, 350)
cr.line_to(150, 375)
cr.curve_to(275, 400, 450, 350, 450, 200)
cr.curve_to(450, 0, 300, 150, 50, 50)
cr.stroke_preserve
path = cr.copy_path_flat
cr.line_width = 1
cr.new_path
layout = make_layout(cr, text)
cr.pango_layout_line_path(layout.get_line(0))
cr.map_path_onto(path)
cr.set_source_rgba(0.3, 0.3, 1.0, 0.3)
cr.fill_preserve
cr.set_source_rgba(0.1, 0.1, 0.1)
cr.stroke
cr.show_page
end
def output
Cairo::ImageSurface.new(500, 500) do |surface|
render(surface)
surface.write_to_png("text-on-path.png")
end
end
output
cairo-1.12.8/samples/pac.rb 0000644 0000041 0000041 00000004430 12256106703 015467 0 ustar www-data www-data =begin
pac.rb - rcairo sample script.
Original: pac.rb in http://www.artima.com/rubycs/articles/pdf_writer3.html
=end
top = File.expand_path(File.join(File.dirname(__FILE__), ".."))
$LOAD_PATH.unshift File.join(top, "ext", "cairo")
$LOAD_PATH.unshift File.join(top, "lib")
require "cairo"
paper = Cairo::Paper::A4_LANDSCAPE
def pac(surface)
cr = Cairo::Context.new(surface)
cr.set_source_color(:black)
cr.paint
# Wall
cr.set_source_color(:magenta)
cr.rounded_rectangle(20, 80, 750, 20, 10)
cr.fill
cr.set_source_color(:cyan)
cr.rounded_rectangle(20, 80, 750, 20, 10)
cr.stroke
cr.set_source_color(:magenta)
cr.rounded_rectangle(20, 380, 750, 20, 10)
cr.fill
cr.set_source_color(:cyan)
cr.rounded_rectangle(20, 380, 750, 20, 10)
cr.stroke
# Body
cr.set_source_color(:yellow)
cr.fill do
cr.arc(150, 250, 100, 30 * (Math::PI / 180), 330 * (Math::PI / 180))
cr.line_to(150, 250)
end
# Dot
cr.set_source_color(:yellow)
cr.circle(250, 250, 20).fill
cr.circle(300, 250, 10).fill
cr.circle(350, 250, 10).fill
cr.circle(400, 250, 10).fill
cr.circle(450, 250, 10).fill
# Ghost
cr.move_to(500, 350)
cr.line_to(500, 175)
cr.curve_to(550, 125, 600, 125, 650, 175)
cr.line_to(650, 350)
cr.line_to(625, 325)
cr.line_to(600, 350)
cr.line_to(575, 325)
cr.line_to(550, 350)
cr.line_to(525, 325)
cr.line_to(500, 350)
cr.set_source_color(:blue)
cr.fill_preserve
cr.set_source_color(:cyan)
cr.stroke
# Ghost Eyes
cr.set_source_color(:white)
cr.rectangle(525, 200, 25, 25).fill
cr.rectangle(575, 200, 25, 25).fill
cr.set_source_color(:black)
cr.rectangle(525, 215, 10, 10).fill
cr.rectangle(575, 215, 10, 10).fill
cr.show_page
end
Cairo::ImageSurface.new(*paper.size("pt")) do |surface|
cr = pac(surface)
cr.target.write_to_png("pac.png")
end
def scalable_surface_output(surface_class_name, paper, suffix)
if Cairo.const_defined?(surface_class_name)
surface_class = Cairo.const_get(surface_class_name)
surface_class.new("pac.#{suffix}", paper) do |surface|
pac(surface)
end
else
puts("#{surface_class_name} isn't supported.")
end
end
scalable_surface_output("PSSurface", paper, "ps")
scalable_surface_output("PDFSurface", paper, "pdf")
scalable_surface_output("SVGSurface", paper, "svg")
cairo-1.12.8/samples/agg/ 0000755 0000041 0000041 00000000000 12256106703 015134 5 ustar www-data www-data cairo-1.12.8/samples/agg/aa_test.rb 0000755 0000041 0000041 00000020035 12256106703 017104 0 ustar www-data www-data #!/usr/bin/env ruby
# ported from examples/aa_test.cpp in AGG source tree.
top = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
src = File.join(top, "src")
$LOAD_PATH.unshift src
$LOAD_PATH.unshift File.join(src, "lib")
require 'gtk2'
window = Gtk::Window.new
window.set_default_size(480, 350)
area = Gtk::DrawingArea.new
def stroke_line(context, x1, y1, x2, y2, line_width, dash_length)
context.save do
yield if block_given?
context.move_to(x1, y1)
context.line_to(x2, y2)
context.set_dash(dash_length) if dash_length > 0
context.line_width = line_width
context.line_cap = :round
context.stroke
end
end
def fill_triangle(context, x1, y1, x2, y2, x3, y3)
context.save do
yield if block_given?
context.triangle(x1, y1, x2, y2, x3, y3)
context.fill
end
end
def set_gradient(context, x1, y1, x2, y2, color_stops)
pattern = Cairo::LinearPattern.new(x1, y1, x2, y2)
color_stops.each do |offset, color|
pattern.add_color_stop(offset, color)
end
context.set_source(pattern)
end
def stroke_gradient_line(context, x1, y1, x2, y2,
line_width, dash_length, color_stops)
stroke_line(context, x1, y1, x2, y2, line_width, dash_length) do
set_gradient(context, x1, y1, x2, y2, color_stops)
end
end
def fill_gradient_triangle(context, x1, y1, x2, y2, x3, y3, color_stops)
fill_triangle(context, x1, y1, x2, y2, x3, y3) do
set_gradient(context,
x1, y1,
x3 - (x3 - x2) / 2.0,
y3 - (y3 - y2) / 2.0,
color_stops)
end
end
def draw_background_circle(context, w, h)
context.set_source_color([1.0, 1.0, 1.0, 0.2])
cx = w / 2.0
cy = h / 2.0
radius = [cx, cy].min
1.upto(180) do |i|
n = 2 * Math::PI * i / 180.0
stroke_line(context,
cx + radius * Math.sin(n),
cy + radius * Math.cos(n),
cx, cy,
1.0, i < 90 ? i : 0)
end
end
def draw_upper_small_circles(context, i)
context.circle(18 + i * 4 + 0.5,
33 + 0.5,
i / 20.0)
context.fill
context.circle(18 + i * 4 + (i - 1) / 10.0 + 0.5,
27 + (i - 1) / 10.0 + 0.5,
0.5)
context.fill
end
def draw_upper_circles(context, i)
context.set_source_color(:white)
context.circle(20 + i * (i + 1) + 0.5,
20.5,
i / 2.0)
context.fill
draw_upper_small_circles(context, i)
end
def draw_upper_gradient_lines(context, i)
stroke_gradient_line(context,
20 + i * (i + 1),
40.5,
20 + i * (i + 1) + (i - 1) * 4,
100.5,
i,
0,
[[0, :white],
[1, [i % 2, (i % 3) * 0.5, (i % 5) * 0.25]]])
end
def draw_middle_small_circles(context, i)
stroke_gradient_line(context,
17.5 + i * 4,
107,
17.5 + i * 4 + i / 6.66666667,
107,
1,
0,
[[0, :red],
[1, :blue]])
stroke_gradient_line(context,
18 + i * 4,
112.5,
18 + i * 4,
112.5 + i / 6.66666667,
1,
0,
[[0, :red],
[1, :blue]])
end
def draw_middle_gradient_lines(context, i)
stroke_gradient_line(context,
21.5,
120 + (i - 1) * 3.1,
52.5,
120 + (i - 1) * 3.1,
1,
0,
[[0, :red],
[1, :white]])
stroke_gradient_line(context,
52.5,
118 + i * 3,
83.5,
118 + i * 3,
2 - (i - 1) / 10.0,
0,
[[0, :green],
[1, :white]])
stroke_gradient_line(context,
83.5,
119 + i * 3,
114.5,
119 + i * 3,
2 - (i - 1) / 10.0,
3.0,
[[0, :blue],
[1, :white]])
end
def draw_middle_white_lines(context, i)
context.set_source_color(:white)
stroke_line(context,
125.5, 119.5 + (i + 2) * (i / 2.0),
135.5, 119.5 + (i + 2) * (i / 2.0),
i, 0)
end
def draw_lower_short_lines(context, i)
context.set_source_color(:white)
stroke_line(context,
17.5 + i * 4, 192,
18.5 + i * 4, 192,
i / 10.0, 0)
stroke_line(context,
17.5 + i * 4 + (i - 1) / 10.0, 186,
18.5 + i * 4 + (i - 1) / 10.0, 186,
1.0, 0)
end
def draw_right_triangles(context, i, w, h)
x1 = w - 150
x2 = w - 20
y_upper = h - 20 - i * (i + 2)
y_middle = h - 20 - i * (i + 1.5)
y_lower = h - 20 - i * (i + 1)
context.save do
pattern = Cairo::LinearPattern.new(x1, y_middle, x2, y_middle)
pattern.add_color_stop(0, :white)
pattern.add_color_stop(1, [i % 2, (i % 3) * 0.5, (i % 5) * 0.25])
context.set_source(pattern)
context.move_to(x1, y_middle)
context.line_to(x2, y_lower)
context.line_to(x2, y_upper)
context.fill
end
end
def draw_sample_shapes(context, w, h)
context.set_source_color(:black)
context.paint
draw_background_circle(context, w, h)
1.upto(20) do |i|
draw_upper_circles(context, i)
draw_upper_gradient_lines(context, i)
draw_middle_small_circles(context, i)
draw_middle_gradient_lines(context, i)
draw_middle_white_lines(context, i) if i <= 10
draw_lower_short_lines(context, i)
end
1.upto(13) do |i|
draw_right_triangles(context, i, w, h)
end
end
def draw_random_shapes(context, w, h)
srand(123)
context.set_source_color(:black)
context.paint
n_circles = 20000
start = Time.now
n_circles.times do |i|
context.circle(rand(w), rand(h), rand(20.0) + 1.0)
context.set_source_color([rand, rand, rand, 0.5 + rand / 2])
context.fill
end
circle_draw_time = Time.now - start
n_lines = 2000
start = Time.now
n_lines.times do |i|
x1 = rand(w)
y1 = rand(h)
stroke_gradient_line(context,
x1, y1,
x1 + rand(w * 0.5) - w * 0.25,
y1 + rand(h * 0.5) - h * 0.25,
10.0, 0,
[[0, [rand, rand, rand, 0.5 + rand / 2]],
[1, [rand, rand, rand, rand]]])
end
line_draw_time = Time.now - start
n_triangles = 2000
start = Time.now
n_triangles.times do |i|
x1 = rand(w)
y1 = rand(h)
fill_gradient_triangle(context,
x1, y1,
x1 + rand(w * 0.4) - w * 0.2,
y1 + rand(h * 0.4) - h * 0.2,
x1 + rand(w * 0.4) - w * 0.2,
y1 + rand(h * 0.4) - h * 0.2,
[[0, [rand, rand, rand, 0.5 + rand / 2]],
[0.5, [rand, rand, rand, rand]],
[1, [rand, rand, rand, rand]]])
end
triangle_draw_time = Time.now - start
puts "Points=%.2fK/sec, Lines=%.2fK/sec, Triangles=%.2fK/sec" %
[n_circles.to_f / circle_draw_time,
n_lines.to_f / line_draw_time,
n_triangles.to_f / triangle_draw_time]
end
random_mode = false
area.add_events(Gdk::Event::BUTTON_PRESS_MASK)
area.signal_connect("button-press-event") do |widget, event|
random_mode = !random_mode
widget.queue_draw
false
end
area.signal_connect("expose-event") do |widget, event|
context = widget.window.create_cairo_context
x, y, w, h = widget.allocation.to_a
if random_mode
draw_random_shapes(context, w, h)
else
draw_sample_shapes(context, w, h)
end
true
end
window.add(area)
window.show_all
Gtk.main
cairo-1.12.8/metadata.yml 0000644 0000041 0000041 00000012541 12256106703 015240 0 ustar www-data www-data --- !ruby/object:Gem::Specification
name: cairo
version: !ruby/object:Gem::Version
version: 1.12.8
platform: ruby
authors:
- Kouhei Sutou
autorequire:
bindir: bin
cert_chain: []
date: 2013-12-23 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: pkg-config
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: bundler
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: test-unit-notify
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: rake-compiler
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: packnga
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
description: Ruby bindings for cairo
email:
- kou@cozmixng.org
executables: []
extensions:
- ext/cairo/extconf.rb
extra_rdoc_files:
- README.rdoc
files:
- AUTHORS
- COPYING
- GPL
- Gemfile
- NEWS
- README.rdoc
- ext/cairo/extconf.rb
- Rakefile
- lib/cairo/color.rb
- lib/cairo/pattern.rb
- lib/cairo/papers.rb
- lib/cairo/point.rb
- lib/cairo/context.rb
- lib/cairo/device.rb
- lib/cairo/colors.rb
- lib/cairo/context/circle.rb
- lib/cairo/context/rectangle.rb
- lib/cairo/context/color.rb
- lib/cairo/context/blur.rb
- lib/cairo/context/triangle.rb
- lib/cairo/context/path.rb
- lib/cairo/path.rb
- lib/cairo/surface.rb
- lib/cairo/constants.rb
- lib/cairo/paper.rb
- lib/cairo.rb
- samples/pac-tee.rb
- samples/agg/aa_test.rb
- samples/pac-nomralize.rb
- samples/text2.rb
- samples/scalable.rb
- samples/blur.rb
- samples/png.rb
- samples/pac.rb
- samples/text-on-path.rb
- ext/cairo/cairo.def
- ext/cairo/depend
- ext/cairo/rb_cairo_io.c
- ext/cairo/rb_cairo_constants.c
- ext/cairo/rb_cairo_pattern.c
- ext/cairo/rb_cairo_exception.c
- ext/cairo/rb_cairo_font_options.c
- ext/cairo/rb_cairo_text_cluster.c
- ext/cairo/rb_cairo_text_extents.c
- ext/cairo/rb_cairo_device.c
- ext/cairo/rb_cairo_font_face.c
- ext/cairo/rb_cairo_scaled_font.c
- ext/cairo/rb_cairo_context.c
- ext/cairo/rb_cairo_glyph.c
- ext/cairo/rb_cairo_surface.c
- ext/cairo/rb_cairo_font_extents.c
- ext/cairo/rb_cairo_path.c
- ext/cairo/rb_cairo_private.c
- ext/cairo/rb_cairo_matrix.c
- ext/cairo/rb_cairo_region.c
- ext/cairo/rb_cairo.c
- ext/cairo/rb_cairo_io.h
- ext/cairo/rb_cairo.h
- ext/cairo/rb_cairo_private.h
- test/test_surface.rb
- test/test_scaled_font.rb
- test/test_recording_surface.rb
- test/test_text_to_glyphs_data.rb
- test/test_font_extents.rb
- test/test_tee_surface.rb
- test/test_text_extents.rb
- test/test_paper.rb
- test/test_context.rb
- test/cairo-test-utils.rb
- test/test_xml_device.rb
- test/test_raster_source_pattern.rb
- test/run-test.rb
- test/test_script_surface.rb
- test/test_region.rb
- test/test_font_face.rb
- test/test_script_device.rb
- test/test_xml_surface.rb
- test/test_exception.rb
- test/test_text_cluster.rb
- test/test_image_surface.rb
- test/test_color.rb
- test/test_font_options.rb
- test/test_constants.rb
homepage: http://cairographics.org/rcairo
licenses:
- Ruby's
metadata: {}
post_install_message:
rdoc_options: []
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
requirements: []
rubyforge_project: cairo
rubygems_version: 2.0.14
signing_key:
specification_version: 4
summary: Ruby bindings for cairo
test_files:
- test/test_surface.rb
- test/test_scaled_font.rb
- test/test_recording_surface.rb
- test/test_text_to_glyphs_data.rb
- test/test_font_extents.rb
- test/test_tee_surface.rb
- test/test_text_extents.rb
- test/test_paper.rb
- test/test_context.rb
- test/cairo-test-utils.rb
- test/test_xml_device.rb
- test/test_raster_source_pattern.rb
- test/run-test.rb
- test/test_script_surface.rb
- test/test_region.rb
- test/test_font_face.rb
- test/test_script_device.rb
- test/test_xml_surface.rb
- test/test_exception.rb
- test/test_text_cluster.rb
- test/test_image_surface.rb
- test/test_color.rb
- test/test_font_options.rb
- test/test_constants.rb
cairo-1.12.8/test/ 0000755 0000041 0000041 00000000000 12256106703 013711 5 ustar www-data www-data cairo-1.12.8/test/test_script_device.rb 0000644 0000041 0000041 00000002105 12256106703 020116 0 ustar www-data www-data require 'cairo'
require 'stringio'
class ScriptDeviceTest < Test::Unit::TestCase
include CairoTestUtils
def setup
only_device("Script")
end
def test_new
output = StringIO.new
device = Cairo::ScriptDevice.new(output)
assert_equal("%!CairoScript\n", output.string)
device.finish
assert_equal("%!CairoScript\n", output.string)
end
def test_new_with_block
output = StringIO.new
string = nil
Cairo::ScriptDevice.new(output) do |device|
string = output.string
end
assert_equal("%!CairoScript\n", string)
end
def test_write_comment
output = StringIO.new
Cairo::ScriptDevice.new(output) do |device|
device.write_comment("Hello!")
end
assert_equal("%!CairoScript\n" +
"% Hello!\n",
output.string)
end
def test_mode
output = StringIO.new
Cairo::ScriptDevice.new(output) do |device|
assert_equal(Cairo::ScriptMode::ASCII, device.mode)
device.mode = Cairo::ScriptMode::BINARY
assert_equal(Cairo::ScriptMode::BINARY, device.mode)
end
end
end
cairo-1.12.8/test/test_text_to_glyphs_data.rb 0000644 0000041 0000041 00000003356 12256106703 021351 0 ustar www-data www-data require 'cairo'
class TextToGlyphsDataTest < Test::Unit::TestCase
include CairoTestUtils
def test_new
only_cairo_version(1, 7, 6)
data = Cairo::UserFontFace::TextToGlyphsData.new(false, false, false)
assert_equal([false, false, false],
[data.need_glyphs?, data.need_clusters?,
data.need_cluster_flags?])
data = Cairo::UserFontFace::TextToGlyphsData.new(true, false, false)
assert_equal([true, false, false],
[data.need_glyphs?, data.need_clusters?,
data.need_cluster_flags?])
data = Cairo::UserFontFace::TextToGlyphsData.new(false, true, false)
assert_equal([false, true, false],
[data.need_glyphs?, data.need_clusters?,
data.need_cluster_flags?])
data = Cairo::UserFontFace::TextToGlyphsData.new(false, false, true)
assert_equal([false, false, true],
[data.need_glyphs?, data.need_clusters?,
data.need_cluster_flags?])
end
def test_accessor
only_cairo_version(1, 7, 6)
data = Cairo::UserFontFace::TextToGlyphsData.new(true, true, true)
assert_equal([nil, nil, 0],
[data.glyphs, data.clusters, data.cluster_flags])
glyph = Cairo::Glyph.new(0, 5, 10)
data.glyphs = [glyph]
assert_equal([[glyph], nil, 0],
[data.glyphs, data.clusters, data.cluster_flags])
cluster = Cairo::TextCluster.new(0, 1)
data.clusters = [cluster]
assert_equal([[glyph], [cluster], 0],
[data.glyphs, data.clusters, data.cluster_flags])
data.cluster_flags = :backward
assert_equal([[glyph], [cluster], Cairo::TextClusterFlag::BACKWARD],
[data.glyphs, data.clusters, data.cluster_flags])
end
end
cairo-1.12.8/test/test_script_surface.rb 0000644 0000041 0000041 00000000473 12256106703 020315 0 ustar www-data www-data class ScriptSurfaceTest < Test::Unit::TestCase
include CairoTestUtils
def setup
only_surface("Script")
end
def test_device
device = Cairo::ScriptDevice.new(StringIO.new)
surface = Cairo::ScriptSurface.new(device, 100, 100)
assert_equal(Cairo::ScriptDevice, surface.device.class)
end
end
cairo-1.12.8/test/test_text_extents.rb 0000644 0000041 0000041 00000002255 12256106703 020037 0 ustar www-data www-data require 'cairo'
class TextExtentsTest < Test::Unit::TestCase
include CairoTestUtils
def test_new
extents = Cairo::TextExtents.new
assert_equal([0.0, -1.0, 0.0, 1.0, 1.0, 0.0],
[extents.x_bearing, extents.y_bearing,
extents.width, extents.height,
extents.x_advance, extents.y_advance])
end
def test_accessor
extents = Cairo::TextExtents.new
extents.x_bearing = 0.1
extents.y_bearing = 0.2
extents.width = 0.3
extents.height = 0.4
extents.x_advance = 0.5
extents.y_advance = 0.6
assert_equal([0.1, 0.2, 0.3, 0.4, 0.5, 0.6],
[extents.x_bearing, extents.y_bearing,
extents.width, extents.height,
extents.x_advance, extents.y_advance])
end
def test_to_s
extents = Cairo::TextExtents.new
extents.x_bearing = 0.1
extents.y_bearing = 0.2
extents.width = 0.3
extents.height = 0.4
extents.x_advance = 0.5
extents.y_advance = 0.6
assert_equal("#",
extents.to_s)
end
end
cairo-1.12.8/test/test_surface.rb 0000644 0000041 0000041 00000002514 12256106703 016727 0 ustar www-data www-data require 'cairo'
require 'stringio'
class SurfaceTest < Test::Unit::TestCase
include CairoTestUtils
def test_new
output = StringIO.new
surface = Cairo::PDFSurface.new(output, 10, 10)
assert_not_equal("%%EOF\n", output.string[-6..-1])
surface.finish
assert_equal("%%EOF\n", output.string[-6..-1])
end
def test_new_with_block
output = StringIO.new
Cairo::PDFSurface.new(output, 10, 10) do |surface|
assert_not_equal("%%EOF\n", output.string[-6..-1])
end
assert_equal("%%EOF\n", output.string[-6..-1])
end
def test_new_with_block_and_finish
assert_nothing_raised do
Cairo::PDFSurface.new(StringIO.new, 10, 10) do |surface|
surface.finish
end
end
end
def test_fallback_resolution
only_cairo_version(1, 7, 2)
surface = Cairo::ImageSurface.new(100, 100)
assert_equal([300.0, 300.0], surface.fallback_resolution)
surface.set_fallback_resolution(95, 95)
assert_equal([95.0, 95.0], surface.fallback_resolution)
end
def test_mime_data
only_cairo_version(1, 10, 0)
output = StringIO.new
surface = Cairo::PDFSurface.new(output, 100, 100)
surface.set_mime_data(Cairo::MimeType::URI, "http://cairo.rubyforge.org/")
assert_equal("http://cairo.rubyforge.org/",
surface.get_mime_data(Cairo::MimeType::URI))
end
end
cairo-1.12.8/test/test_text_cluster.rb 0000644 0000041 0000041 00000001512 12256106703 020021 0 ustar www-data www-data require 'cairo'
class TextClusterTest < Test::Unit::TestCase
include CairoTestUtils
def test_new
only_cairo_version(1, 7, 2)
cluster = Cairo::TextCluster.new(2, 3)
assert_equal([2, 3], [cluster.num_bytes, cluster.num_glyphs])
assert_equal("#",
cluster.to_s)
end
def test_accessor
only_cairo_version(1, 7, 2)
cluster = Cairo::TextCluster.new(5, 7)
assert_equal([5, 7], [cluster.num_bytes, cluster.num_glyphs])
cluster.num_bytes = 1
cluster.num_glyphs = 2
assert_equal([1, 2], [cluster.num_bytes, cluster.num_glyphs])
end
def test_to_s
only_cairo_version(1, 7, 2)
cluster = Cairo::TextCluster.new(9, 1)
assert_equal("#",
cluster.to_s)
end
end
cairo-1.12.8/test/test_region.rb 0000644 0000041 0000041 00000005677 12256106703 016577 0 ustar www-data www-data class RegionTest < Test::Unit::TestCase
include CairoTestUtils
def setup
only_cairo_version(1, 10, 0)
end
def test_new_empty
region = Cairo::Region.new
assert_predicate(region, :empty?)
end
def test_new_rectangle
region = Cairo::Region.new([0, 0, 10, 10])
assert_not_predicate(region, :empty?)
end
def test_num_rectangles
region = Cairo::Region.new
assert_equal(0, region.num_rectangles)
end
def test_get_rectangle
region = Cairo::Region.new([0, 0, 10, 10])
assert_equal([0, 0, 10, 10], region[0])
end
def test_dup
region = Cairo::Region.new([0, 0, 10, 10])
region.dup.subtract!([5, 5, 5, 5])
assert_equal([0, 0, 10, 10], region.extents)
end
def test_equal
assert_equal(Cairo::Region.new([0, 0, 10, 10]),
Cairo::Region.new([0, 0, 10, 10]))
assert_not_equal(Cairo::Region.new([0, 0, 10, 10]),
Cairo::Region.new([0, 0, 100, 100]))
end
def test_extents
region = Cairo::Region.new
assert_equal([0, 0, 0, 0], region.extents)
region.union!([0, 0, 10, 10])
assert_equal([0, 0, 10, 10], region.extents)
end
def test_contains_rectangle
region = Cairo::Region.new([0, 0, 10, 10])
assert_equal(Cairo::RegionOverlap::IN,
region.contains_rectangle([2, 2, 2, 2]))
assert_equal(Cairo::RegionOverlap::OUT,
region.contains_rectangle([10, 10, 1, 1]))
assert_equal(Cairo::RegionOverlap::PART,
region.contains_rectangle([2, 2, 10, 10]))
end
def test_contains_point
region = Cairo::Region.new([0, 0, 10, 10])
assert_equal(true, region.contains_point?(5, 5))
assert_equal(false, region.contains_point?(10, 10))
end
def test_translate
region = Cairo::Region.new([0, 0, 10, 10])
assert_equal(true, region.contains_point?(5, 5))
region.translate!(6, 6)
assert_equal(false, region.contains_point?(5, 5))
end
def test_subtract
region = Cairo::Region.new([0, 0, 10, 10])
assert_equal(true, region.contains_point?(5, 5))
region.subtract!([5, 5, 2, 2])
assert_equal(false, region.contains_point?(5, 5))
end
def test_intersect
region = Cairo::Region.new([0, 0, 10, 10])
assert_equal(true, region.contains_point?(5, 5))
assert_equal(true, region.contains_point?(7, 7))
region.intersect!([5, 5, 2, 2])
assert_equal(true, region.contains_point?(5, 5))
assert_equal(false, region.contains_point?(7, 7))
end
def test_union
region = Cairo::Region.new([0, 0, 4, 4])
assert_equal(false, region.contains_point?(5, 5))
region.union!([5, 5, 5, 5])
assert_equal(true, region.contains_point?(5, 5))
end
def test_xor
region = Cairo::Region.new([0, 0, 5, 5])
assert_equal(true, region.contains_point?(4, 4))
assert_equal(false, region.contains_point?(7, 7))
region.xor!([3, 3, 5, 5])
assert_equal(false, region.contains_point?(4, 4))
assert_equal(true, region.contains_point?(7, 7))
end
end
cairo-1.12.8/test/test_font_face.rb 0000644 0000041 0000041 00000021657 12256106703 017234 0 ustar www-data www-data require 'cairo'
class FontFaceTest < Test::Unit::TestCase
include CairoTestUtils
def test_toy_font_face_new
only_cairo_version(1, 7, 2)
face = Cairo::ToyFontFace.new
default_font_family = ""
# default_font_family = "Helvetica" if quartz?
default_font_family = "Arial" if win32?
assert_equal([default_font_family,
Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_NORMAL],
[face.family, face.slant, face.weight])
face = Cairo::ToyFontFace.new("serif")
assert_equal(["serif", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL],
[face.family, face.slant, face.weight])
face = Cairo::ToyFontFace.new(:serif)
assert_equal(["serif", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL],
[face.family, face.slant, face.weight])
face = Cairo::ToyFontFace.new("serif", :oblique)
assert_equal(["serif", Cairo::FONT_SLANT_OBLIQUE, Cairo::FONT_WEIGHT_NORMAL],
[face.family, face.slant, face.weight])
face = Cairo::ToyFontFace.new("serif", nil, :bold)
assert_equal(["serif", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD],
[face.family, face.slant, face.weight])
face = Cairo::ToyFontFace.new("serif", :italic, :bold)
assert_equal(["serif", Cairo::FONT_SLANT_ITALIC, Cairo::FONT_WEIGHT_BOLD],
[face.family, face.slant, face.weight])
end
def test_toy_font_face_new_with_invalid_family_name
only_cairo_version(1, 7, 2)
exception = assert_raise(ArgumentError) do
Cairo::ToyFontFace.new(999)
end
assert_equal("family name should be nil, String or Symbol: 999",
exception.message)
end
def test_user_font_face_empty
only_cairo_version(1, 7, 2)
face = Cairo::UserFontFace.new
scaled_font = Cairo::ScaledFont.new(face,
Cairo::Matrix.identity,
Cairo::Matrix.identity,
Cairo::FontOptions.new)
assert_equal([[], [], 0],
scaled_font.text_to_glyphs(0, 0, "text"))
end
def test_user_font_face_callback
only_cairo_version(1, 7, 2)
face = Cairo::UserFontFace.new
init_args = []
face.on_init do |*args|
init_args << args
end
render_glyph_args = []
face.on_render_glyph do |*args|
render_glyph_args << args
end
text_to_glyphs_args = []
face.on_text_to_glyphs do |*args|
text_to_glyphs_args << args
scaled_font, utf8, data = args
data.cluster_flags = :backward
end
unicode_to_glyph_args = []
face.on_unicode_to_glyph do |*args|
unicode_to_glyph_args << args
scaled_font, unicode = args
unicode
end
scaled_font = Cairo::ScaledFont.new(face,
Cairo::Matrix.identity,
Cairo::Matrix.identity,
Cairo::FontOptions.new)
result = scaled_font.text_to_glyphs(0, 0, "text")
assert_equal([[[Cairo::ScaledFont, Cairo::Context, Cairo::FontExtents]],
[[Cairo::ScaledFont, codepoint("t"),
Cairo::Context, Cairo::TextExtents],
[Cairo::ScaledFont, codepoint("e"),
Cairo::Context, Cairo::TextExtents],
[Cairo::ScaledFont, codepoint("x"),
Cairo::Context, Cairo::TextExtents]],
[[Cairo::ScaledFont, "text",
Cairo::UserFontFace::TextToGlyphsData]],
[[Cairo::ScaledFont, codepoint("t")],
[Cairo::ScaledFont, codepoint("e")],
[Cairo::ScaledFont, codepoint("x")],
[Cairo::ScaledFont, codepoint("t")]],
[[], [], Cairo::TextClusterFlag::BACKWARD]],
[classify_cairo_object(init_args),
classify_cairo_object(render_glyph_args),
classify_cairo_object(text_to_glyphs_args),
classify_cairo_object(unicode_to_glyph_args),
result])
end
if Cairo.satisfied_version?(1, 7, 2)
class CustomUserFontFace < Cairo::UserFontFace
attr_reader :init_args, :render_glyph_args
attr_reader :text_to_glyphs_args, :unicode_to_glyph_args
def initialize
super
@init_args = []
@render_glyph_args = []
@text_to_glyphs_args = []
@unicode_to_glyph_args = []
end
def init(*args)
@init_args << args
end
def render_glyph(*args)
@render_glyph_args << args
end
def text_to_glyphs(*args)
@text_to_glyphs_args << args
scaled_font, utf8, data = args
data.cluster_flags = :backward
end
def unicode_to_glyph(*args)
@unicode_to_glyph_args << args
scaled_font, unicode = args
unicode
end
end
end
def test_user_font_face_class
only_cairo_version(1, 7, 2)
face = CustomUserFontFace.new
scaled_font = Cairo::ScaledFont.new(face,
Cairo::Matrix.identity,
Cairo::Matrix.identity,
Cairo::FontOptions.new)
result = scaled_font.text_to_glyphs(0, 0, "text")
assert_equal([[[Cairo::ScaledFont, Cairo::Context, Cairo::FontExtents]],
[[Cairo::ScaledFont, codepoint("t"),
Cairo::Context, Cairo::TextExtents],
[Cairo::ScaledFont, codepoint("e"),
Cairo::Context, Cairo::TextExtents],
[Cairo::ScaledFont, codepoint("x"),
Cairo::Context, Cairo::TextExtents]],
[[Cairo::ScaledFont, "text",
Cairo::UserFontFace::TextToGlyphsData]],
[[Cairo::ScaledFont, codepoint("t")],
[Cairo::ScaledFont, codepoint("e")],
[Cairo::ScaledFont, codepoint("x")],
[Cairo::ScaledFont, codepoint("t")]],
[[], [], Cairo::TextClusterFlag::BACKWARD]],
[classify_cairo_object(face.init_args),
classify_cairo_object(face.render_glyph_args),
classify_cairo_object(face.text_to_glyphs_args),
classify_cairo_object(face.unicode_to_glyph_args),
result])
end
def test_user_font_face_class_and_callback
only_cairo_version(1, 7, 2)
face = CustomUserFontFace.new
init_args = []
face.on_init do |*args|
init_args << args
end
render_glyph_args = []
face.on_render_glyph do |*args|
render_glyph_args << args
end
text_to_glyphs_args = []
face.on_text_to_glyphs do |*args|
text_to_glyphs_args << args
scaled_font, utf8, data = args
data.cluster_flags = :backward
end
unicode_to_glyph_args = []
face.on_unicode_to_glyph do |*args|
unicode_to_glyph_args << args
scaled_font, unicode = args
unicode
end
scaled_font = Cairo::ScaledFont.new(face,
Cairo::Matrix.identity,
Cairo::Matrix.identity,
Cairo::FontOptions.new)
result = scaled_font.text_to_glyphs(0, 0, "text")
assert_equal([[[Cairo::ScaledFont, Cairo::Context, Cairo::FontExtents]],
[[Cairo::ScaledFont, codepoint("t"),
Cairo::Context, Cairo::TextExtents],
[Cairo::ScaledFont, codepoint("e"),
Cairo::Context, Cairo::TextExtents],
[Cairo::ScaledFont, codepoint("x"),
Cairo::Context, Cairo::TextExtents]],
[[Cairo::ScaledFont, "text",
Cairo::UserFontFace::TextToGlyphsData]],
[[Cairo::ScaledFont, codepoint("t")],
[Cairo::ScaledFont, codepoint("e")],
[Cairo::ScaledFont, codepoint("x")],
[Cairo::ScaledFont, codepoint("t")]],
[],
[],
[],
[],
[[], [], Cairo::TextClusterFlag::BACKWARD]],
[classify_cairo_object(init_args),
classify_cairo_object(render_glyph_args),
classify_cairo_object(text_to_glyphs_args),
classify_cairo_object(unicode_to_glyph_args),
classify_cairo_object(face.init_args),
classify_cairo_object(face.render_glyph_args),
classify_cairo_object(face.text_to_glyphs_args),
classify_cairo_object(face.unicode_to_glyph_args),
result])
end
def classify_cairo_object(object)
if object.is_a?(Array)
object.collect {|obj| classify_cairo_object(obj)}
elsif /\ACairo::/ =~ object.class.name
object.class
else
object
end
end
def codepoint(character)
character.unpack("U")[0]
end
end
cairo-1.12.8/test/test_raster_source_pattern.rb 0000644 0000041 0000041 00000011067 12256106703 021717 0 ustar www-data www-data require "cairo"
require "tempfile"
class RasterSourcePatternTest < Test::Unit::TestCase
include CairoTestUtils
def setup
only_pattern("RasterSource")
end
def test_acquire_and_release
Cairo::ImageSurface.new(100, 100) do |surface|
Cairo::Context.new(surface) do |context|
context.set_source(1, 1, 1)
context.paint
called = []
red_pattern = Cairo::RasterSourcePattern.new(100, 100)
red_pattern.acquire do |pattern, target, extents|
called << :acquire
red_image = target.create_similar_image(extents.width, extents.height)
red_image.set_device_offset(extents.x, extents.y)
Cairo::Context.new(red_image) do |red_image_context|
red_image_context.set_source(1, 0, 0)
red_image_context.paint
end
red_image
end
red_pattern.release do |pattern, surface|
called << :release
surface.finish
end
context.set_source(red_pattern)
context.rectangle(40, 40, 20, 20)
context.fill
assert_equal([:acquire, :release], called)
end
show_result(surface)
end
end
class SnapshotTest < self
def setup
super
only_surface("Recording")
end
def test_success
Cairo::RecordingSurface.new(0, 0, 100, 100) do |surface|
Cairo::Context.new(surface) do |context|
called = []
raster_source = Cairo::RasterSourcePattern.new(100, 100)
raster_source.snapshot do |pattern|
called << :snapshot
end
context.set_source(raster_source)
context.rectangle(40, 40, 20, 20)
context.fill
assert_equal([:snapshot], called)
end
show_result(surface)
end
end
def test_error
Cairo::RecordingSurface.new(0, 0, 100, 100) do |surface|
Cairo::Context.new(surface) do |context|
called = []
raster_source = Cairo::RasterSourcePattern.new(100, 100)
raster_source.snapshot do |pattern|
called << :snapshot
raise NoMemoryError
end
context.set_source(raster_source)
context.rectangle(40, 40, 20, 20)
assert_raise(NoMemoryError) do
context.fill
end
assert_equal([:snapshot], called)
end
show_result(surface)
end
end
end
class CopyTest < self
def setup
super
only_surface("Script")
end
def test_success
output = StringIO.new
device = Cairo::ScriptDevice.new(output)
Cairo::ScriptSurface.new(device, 100, 200) do |surface|
Cairo::Context.new(surface) do |context|
called = []
raster_source = Cairo::RasterSourcePattern.new(100, 100)
raster_source.acquire do |pattern, target, extents|
called << :acquire
red_image = target.create_similar_image(extents.width,
extents.height)
red_image.set_device_offset(extents.x, extents.y)
Cairo::Context.new(red_image) do |red_image_context|
red_image_context.set_source(1, 0, 0)
red_image_context.paint
end
red_image
end
raster_source.release do |pattern, surface|
called << :release
surface.finish
end
raster_source.copy do |pattern|
called << :copy
end
context.set_source(raster_source)
context.rectangle(40, 40, 20, 20)
context.fill
assert_equal([:copy, :acquire, :release], called)
end
show_result(surface)
end
end
def test_error
output = StringIO.new
device = Cairo::ScriptDevice.new(output)
Cairo::ScriptSurface.new(device, 100, 200) do |surface|
Cairo::Context.new(surface) do |context|
called = []
raster_source = Cairo::RasterSourcePattern.new(100, 100)
raster_source.copy do |pattern|
called << :copy
raise NoMemoryError
end
context.set_source(raster_source)
context.rectangle(40, 40, 20, 20)
assert_raise(NoMemoryError) do
context.fill
end
assert_equal([:copy], called)
end
show_result(surface)
end
end
end
private
def show_result(image_surface)
return if ENV["RCAIRO_TEST_SHOW_RESULT"] != "yes"
result = Tempfile.new("result")
image_surface.write_to_png(result.path)
system("display", result.path)
end
end
cairo-1.12.8/test/test_paper.rb 0000644 0000041 0000041 00000004404 12256106703 016406 0 ustar www-data www-data require 'cairo'
class PaperTest < Test::Unit::TestCase
def test_parse_paper
a4 = Cairo::Paper::A4
assert_parse(a4, a4)
end
def test_parse_name
assert_parse(:A4, "A4")
assert_parse(:A4_LANDSCAPE, "A4 landscape")
assert_parse(:A4, :A4)
assert_parse(:A4, :a4)
assert_parse(:JAPANESE_POSTCARD, :japanese_postcard)
assert_parse(:JAPANESE_POSTCARD, "japanese-postcard")
assert_parse(:JAPANESE_POSTCARD, "Japanese postcard")
exception = assert_raise(Cairo::Paper::UnknownPaperName) do
Cairo::Paper.parse(:nonexistence)
end
assert_equal(:nonexistence, exception.name)
end
def test_parse_size
assert_parse(paper(100, 200), "100x200")
assert_parse(paper(283.46456664, 566.929134), "100mmx200mm")
assert_parse(paper(284.88188952, 200.9), "100.5mmx200.9")
assert_parse(paper(72, 612.0), "1inx8.5inch")
assert_parse(paper(28.346456664, 24094.488168), "1cmx8.5m")
assert_parse(paper(100, 200), [100, 200])
exception = assert_raise(Cairo::Paper::UnknownUnit) do
Cairo::Paper.parse("100kmx100")
end
assert_equal("km", exception.unit)
end
def test_parse_size_with_name
assert_parse(paper(28.346456664, 24094.488168, nil, "Name"),
"1cmx8.5m#Name")
end
def test_unrecognized_input
assert_nothing_raised do
Cairo::Paper.parse({})
end
exception = assert_raise(Cairo::Paper::UnrecognizedPaperDescription) do
Cairo::Paper.parse({}, true)
end
assert_equal({}, exception.description)
end
def test_unit
paper = parse("1cmx8.5m")
assert_nil(paper.unit)
assert_in_delta(28.346456664, 0.01, paper.width)
assert_in_delta(24094.488168, 0.01, paper.height)
paper.unit = "inch"
assert_equal("inch", paper.unit)
assert_in_delta(0.393700787, 0.01, paper.width)
assert_in_delta(334.645669, 0.01, paper.height)
end
private
def paper(width, height, *rest)
Cairo::Paper.new(width, height, *rest)
end
def parse(paper_description)
Cairo::Paper.parse(paper_description)
end
def assert_parse(expected, paper_description, message=nil)
expected = Cairo::Paper.const_get(expected) if expected.is_a?(Symbol)
actual_paper = parse(paper_description)
assert_equal(expected, actual_paper, message)
end
end
cairo-1.12.8/test/test_font_options.rb 0000644 0000041 0000041 00000000300 12256106703 020007 0 ustar www-data www-data require 'cairo'
class FontOptionsTest < Test::Unit::TestCase
include CairoTestUtils
def setup
@options = Cairo::FontOptions.new
end
def test_something
# WRITE ME!
end
end
cairo-1.12.8/test/test_exception.rb 0000644 0000041 0000041 00000001241 12256106703 017271 0 ustar www-data www-data require 'cairo'
class ExceptionTest < Test::Unit::TestCase
def test_new_symbols_since_1_7_2
if Cairo.satisfied_version?(1, 7, 2)
assertion = :assert_defined
else
assertion = :assert_not_defined
end
send(assertion, "FontTypeMismatch")
send(assertion, "UserFontImmutable")
send(assertion, "UserFontError")
send(assertion, "NegativeCount")
send(assertion, "InvalidClusters")
send(assertion, "InvalidSlant")
send(assertion, "InvalidWeight")
end
private
def assert_defined(name)
assert_true(Cairo.const_defined?(name))
end
def assert_not_defined(name)
assert_false(Cairo.const_defined?(name))
end
end
cairo-1.12.8/test/test_xml_surface.rb 0000644 0000041 0000041 00000001463 12256106703 017611 0 ustar www-data www-data class XMLSurfaceTest < Test::Unit::TestCase
include CairoTestUtils
def setup
only_surface("XML")
end
def test_new
only_cairo_version(1, 12, 0)
output = StringIO.new
device = Cairo::XMLDevice.new(output)
surface = Cairo::XMLSurface.new(device, 100, 200)
Cairo::Context.new(surface) do |context|
context.move_to(15, 30)
context.line_to(80, 100)
context.stroke
end
assert_equal(<<-EOX, output.string)
OVER
2
10
LINE_CAP_BUTT
LINE_JOIN_MITER
0 0 0 1
15 30 m 80 100 l
0.1
DEFAULT
EOX
end
end
cairo-1.12.8/test/test_scaled_font.rb 0000644 0000041 0000041 00000002076 12256106703 017563 0 ustar www-data www-data require 'cairo'
require 'stringio'
class ScaledFontTest < Test::Unit::TestCase
include CairoTestUtils
def test_scale_matrix
only_cairo_version(1, 7, 2)
surface = Cairo::ImageSurface.new(100, 100)
context = Cairo::Context.new(surface)
scaled_font = context.scaled_font
assert_equal(Cairo::Matrix.new(10.0, 0.0, 0.0,
10.0, 0.0, 0.0),
scaled_font.scale_matrix)
end
def test_text_to_glyphs
only_cairo_version(1, 7, 6)
surface = Cairo::PDFSurface.new(StringIO.new, 10, 10)
context = Cairo::Context.new(surface)
scaled_font = Cairo::ScaledFont.new(context.font_face,
Cairo::Matrix.identity,
Cairo::Matrix.identity,
Cairo::FontOptions.new)
expected_glyphs = []
expected_clusters = []
expected_cluster_flags = 0
assert_equal([expected_glyphs, expected_clusters, expected_cluster_flags],
scaled_font.text_to_glyphs(0, 0, "text"))
end
end
cairo-1.12.8/test/test_recording_surface.rb 0000644 0000041 0000041 00000000766 12256106703 020772 0 ustar www-data www-data class RecordingSurfaceTest < Test::Unit::TestCase
include CairoTestUtils
def setup
only_surface("Recording")
end
def test_new
only_cairo_version(1, 12, 0)
surface = Cairo::RecordingSurface.new(10, 20, 300, 400)
assert_equal([0.0, 0.0, 0.0, 0.0], surface.ink_extents)
Cairo::Context.new(surface) do |context|
context.move_to(15, 30)
context.line_to(80, 100)
context.stroke
end
assert_equal([10.0, 20.0, 61.0, 61.0], surface.ink_extents)
end
end
cairo-1.12.8/test/test_constants.rb 0000644 0000041 0000041 00000000642 12256106703 017313 0 ustar www-data www-data require 'cairo'
class ConstantsTest < Test::Unit::TestCase
def test_text_cluster_flags
constant_name = "TextClusterFlag"
unless Cairo.satisfied_version?(1, 7, 6)
assert_false(Cairo.const_defined?(constant_name))
return
end
assert_true(Cairo.const_defined?(constant_name))
assert_equal((0..1).to_a,
[0,
Cairo::TextClusterFlag::BACKWARD])
end
end
cairo-1.12.8/test/test_tee_surface.rb 0000644 0000041 0000041 00000001510 12256106703 017557 0 ustar www-data www-data class TeeSurfaceTest < Test::Unit::TestCase
include CairoTestUtils
def setup
only_surface("Tee")
only_surface("Script")
end
def test_new
output1 = StringIO.new
device1 = Cairo::ScriptDevice.new(output1)
surface1 = Cairo::ScriptSurface.new(device1, 100, 200)
output2 = StringIO.new
device2 = Cairo::ScriptDevice.new(output2)
surface2 = Cairo::ScriptSurface.new(device2, 100, 200)
surface = Cairo::TeeSurface.new(surface1)
surface << surface2
Cairo::Context.new(surface) do |context|
context.move_to(15, 30)
context.line_to(80, 100)
context.stroke
end
assert_equal(<<-EOS, output1.string)
%!CairoScript
<< /content //COLOR_ALPHA /width 100 /height 200 >> surface context
n 15 30 m 80 100 l
stroke+
EOS
assert_equal(output1.string, output2.string)
end
end
cairo-1.12.8/test/test_context.rb 0000644 0000041 0000041 00000005755 12256106703 016775 0 ustar www-data www-data require 'cairo'
require 'stringio'
class ContextTest < Test::Unit::TestCase
include CairoTestUtils
def setup
@output = StringIO.new
@surface = Cairo::PDFSurface.new(@output, 10, 10)
end
def test_new_and_destroy
context = Cairo::Context.new(@surface)
@surface.destroy
assert_not_equal("%%EOF\n", @output.string[-6..-1])
context.destroy
assert_equal("%%EOF\n", @output.string[-6..-1])
end
def test_new_with_block
Cairo::Context.new(@surface) do |context|
@surface.destroy
assert_not_equal("%%EOF\n", @output.string[-6..-1])
end
assert_equal("%%EOF\n", @output.string[-6..-1])
end
def test_new_with_block_and_destroy
assert_nothing_raised do
Cairo::Context.new(@surface) do |context|
context.destroy
end
end
end
def test_font_face
only_cairo_version(1, 7, 2)
context = Cairo::Context.new(@surface)
assert_kind_of(Cairo::FontFace, context.font_face)
face = Cairo::ToyFontFace.new("serif")
context.font_face = face
assert_equal("serif", context.font_face.family)
face = Cairo::ToyFontFace.new("sans")
context.font_face = face
assert_equal("sans", context.font_face.family)
end
def test_text_to_glyphs
only_cairo_version(1, 7, 2)
surface = Cairo::PDFSurface.new(StringIO.new, 10, 10)
context = Cairo::Context.new(surface)
scaled_font = Cairo::ScaledFont.new(context.font_face,
Cairo::Matrix.identity,
Cairo::Matrix.identity,
Cairo::FontOptions.new)
utf8 = "text"
glyphs, clusters, backward = scaled_font.text_to_glyphs(0, 0, utf8)
assert_nothing_raised do
context.show_text_glyphs(utf8, glyphs, clusters, backward)
end
end
def test_select_font_face
only_cairo_version(1, 7, 2)
context = Cairo::Context.new(@surface)
face = context.font_face
default_font_family = ""
# default_font_family = "Helvetica" if quartz?
default_font_family = "Arial" if win32?
assert_equal([default_font_family,
Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_NORMAL],
[face.family, face.slant, face.weight])
context.select_font_face
face = context.font_face
assert_equal([default_font_family,
Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_NORMAL],
[face.family, face.slant, face.weight])
context.select_font_face(:serif, :italic, :bold)
face = context.font_face
assert_equal(["serif", Cairo::FONT_SLANT_ITALIC, Cairo::FONT_WEIGHT_BOLD],
[face.family, face.slant, face.weight])
end
def test_select_font_face_with_invalid_family_name
context = Cairo::Context.new(@surface)
exception = assert_raise(ArgumentError) do
context.select_font_face([999])
end
assert_equal("family name should be nil, String or Symbol: [999]",
exception.message)
end
end
cairo-1.12.8/test/run-test.rb 0000755 0000041 0000041 00000001216 12256106703 016022 0 ustar www-data www-data #!/usr/bin/env ruby
base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
ext_dir = File.join(base_dir, "ext", "cairo")
lib_dir = File.join(base_dir, "lib")
test_dir = File.join(base_dir, "test")
if system("which make >/dev/null 2>&1")
Dir.chdir(base_dir) do
system("make > /dev/null") or exit(1)
end
end
require 'rubygems'
require 'bundler/setup'
require 'test-unit'
$LOAD_PATH.unshift(base_dir)
$LOAD_PATH.unshift(ext_dir)
$LOAD_PATH.unshift(lib_dir)
$LOAD_PATH.unshift(test_dir)
require 'cairo-test-utils'
Dir.glob("test/**/test_*.rb") do |file|
require file.sub(/\.rb$/, '')
end
exit Test::Unit::AutoRunner.run(false)
cairo-1.12.8/test/test_font_extents.rb 0000644 0000041 0000041 00000002064 12256106703 020017 0 ustar www-data www-data require 'cairo'
class FontExtentsTest < Test::Unit::TestCase
include CairoTestUtils
def test_new
extents = Cairo::FontExtents.new
assert_equal([1.0, 0.0, 1.0, 1.0, 0.0],
[extents.ascent, extents.descent, extents.height,
extents.max_x_advance, extents.max_y_advance])
end
def test_accessor
extents = Cairo::FontExtents.new
extents.ascent = 0.1
extents.descent = 0.2
extents.height = 0.3
extents.max_x_advance = 0.4
extents.max_y_advance = 0.5
assert_equal([0.1, 0.2, 0.3, 0.4, 0.5],
[extents.ascent, extents.descent, extents.height,
extents.max_x_advance, extents.max_y_advance])
end
def test_to_s
extents = Cairo::FontExtents.new
extents.ascent = 0.1
extents.descent = 0.2
extents.height = 0.3
extents.max_x_advance = 0.4
extents.max_y_advance = 0.5
assert_equal("#",
extents.to_s)
end
end
cairo-1.12.8/test/test_image_surface.rb 0000644 0000041 0000041 00000001372 12256106703 020072 0 ustar www-data www-data require 'cairo'
class ImageSurfaceTest < Test::Unit::TestCase
include CairoTestUtils
def test_cloned_data
width = 10
height = 10
original_surface = Cairo::ImageSurface.new(:a1, width, height)
original_data = original_surface.data
cloned_data = original_data.clone
cloned_surface = Cairo::ImageSurface.new(cloned_data,
:a1, width, height,
original_surface.stride)
Cairo::Context.new(cloned_surface) do |context|
context.set_source_rgb(255, 255, 255)
context.scale(width, height)
context.move_to(0, 0)
context.line_to(1, 1)
context.stroke
end
assert_not_equal(original_data, cloned_data)
end
end
cairo-1.12.8/test/test_color.rb 0000644 0000041 0000041 00000000451 12256106703 016413 0 ustar www-data www-data require 'cairo'
class ColorTest < Test::Unit::TestCase
def test_rgb_to_hsv
color = rgb(0.3, 0.5, 0.75)
assert_equal(color, color.to_hsv.to_rgb)
end
private
def rgb(r, g, b)
Cairo::Color::RGB.new(r, g, b)
end
def hsv(h, s, v)
Cairo::Color::HSV.new(h, s, v)
end
end
cairo-1.12.8/test/cairo-test-utils.rb 0000644 0000041 0000041 00000001506 12256106703 017450 0 ustar www-data www-data require 'cairo'
require 'stringio'
module CairoTestUtils
private
def only_cairo_version(major, minor, micro=nil)
unless Cairo.satisfied_version?(major, minor, micro)
omit("Require cairo >= #{major}.#{minor}.#{micro}")
end
end
def only_win32
omit("Only for Win32 platform") unless win32
end
def win32?
/cygwin|mingw|mswin32|bccwin32/.match(RUBY_PLATFORM) ? true : false
end
def only_device(name)
only_cairo_version(1, 10)
unless Cairo::Device.supported?(name)
omit("Only for #{name} device available")
end
end
def only_surface(name)
unless Cairo::Surface.supported?(name)
omit("Only for #{name} device available")
end
end
def only_pattern(name)
unless Cairo::Pattern.supported?(name)
omit("Only for #{name} device available")
end
end
end
cairo-1.12.8/test/test_xml_device.rb 0000644 0000041 0000041 00000000653 12256106703 017420 0 ustar www-data www-data class XMLDeviceTest < Test::Unit::TestCase
include CairoTestUtils
def setup
only_device("XML")
end
def test_new
output = StringIO.new
device = Cairo::XMLDevice.new(output)
assert_equal("", output.string)
end
def test_new_with_block
output = StringIO.new
string = nil
Cairo::XMLDevice.new(output) do |device|
string = output.string
end
assert_equal("", string)
end
end
cairo-1.12.8/AUTHORS 0000644 0000041 0000041 00000000225 12256106703 014001 0 ustar www-data www-data Active:
Kouhei Sutou
Inactive:
Evan Marin
Øyvind Kolås
MenTaLguY
cairo-1.12.8/checksums.yaml.gz 0000444 0000041 0000041 00000000414 12256106703 016217 0 ustar www-data www-data =Re;R0D"cI9
cRBovr~}^-E`+TYtٓáy''gj( XzVӣWĥUlB0[h 's0B}
msHˀlL߀+tfo+T/9oS0s17HT}9P6yVu:
Ql`TqY2
N{g9jMJe
cairo-1.12.8/ext/ 0000755 0000041 0000041 00000000000 12256106703 013532 5 ustar www-data www-data cairo-1.12.8/ext/cairo/ 0000755 0000041 0000041 00000000000 12256106703 014627 5 ustar www-data www-data cairo-1.12.8/ext/cairo/rb_cairo_pattern.c 0000644 0000041 0000041 00000103765 12256106703 020324 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-06-12 10:59:54 $
*
* Copyright 2012 Kouhei Sutou
* Copyright 2005 Øyvind Kolås
* Copyright 2004-2005 MenTaLguY
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
VALUE rb_cCairo_Pattern;
VALUE rb_cCairo_SolidPattern;
VALUE rb_cCairo_SurfacePattern;
VALUE rb_cCairo_GradientPattern;
VALUE rb_cCairo_LinearPattern;
VALUE rb_cCairo_RadialPattern;
VALUE rb_cCairo_MeshPattern;
VALUE rb_cCairo_RasterSourcePattern;
static ID id_parse, id_to_rgb, id_to_a, id_inspect, id_new, id_call;
#define _SELF(self) (RVAL2CRPATTERN(self))
#if CAIRO_CHECK_VERSION(1, 11, 4)
# define RB_CAIRO_HAS_MESH_PATTERN
# define RB_CAIRO_HAS_RASTER_SOURCE_PATTERN
#endif
static VALUE
cr_color_parse (VALUE color)
{
return rb_funcall (rb_mCairo_Color, id_parse, 1, color);
}
static inline void
cr_pattern_check_status (cairo_pattern_t *pattern)
{
rb_cairo_check_status (cairo_pattern_status (pattern));
}
static VALUE
cr_pattern_get_klass (cairo_pattern_t *pattern)
{
VALUE klass;
cairo_pattern_type_t type;
type = cairo_pattern_get_type (pattern);
switch (type)
{
case CAIRO_PATTERN_TYPE_SOLID:
klass = rb_cCairo_SolidPattern;
break;
case CAIRO_PATTERN_TYPE_SURFACE:
klass = rb_cCairo_SurfacePattern;
break;
case CAIRO_PATTERN_TYPE_LINEAR:
klass = rb_cCairo_LinearPattern;
break;
case CAIRO_PATTERN_TYPE_RADIAL:
klass = rb_cCairo_RadialPattern;
break;
#if CAIRO_CHECK_VERSION(1, 11, 4)
case CAIRO_PATTERN_TYPE_MESH:
klass = rb_cCairo_MeshPattern;
break;
case CAIRO_PATTERN_TYPE_RASTER_SOURCE:
klass = rb_cCairo_RasterSourcePattern;
break;
#endif
default:
rb_raise (rb_eArgError, "unknown pattern type: %d", type);
break;
}
return klass;
}
static VALUE
cr_pattern_solid_supported_p (VALUE klass)
{
return Qtrue;
}
static VALUE
cr_pattern_surface_supported_p (VALUE klass)
{
return Qtrue;
}
static VALUE
cr_pattern_gradient_supported_p (VALUE klass)
{
return Qtrue;
}
static VALUE
cr_pattern_linear_supported_p (VALUE klass)
{
return Qtrue;
}
static VALUE
cr_pattern_radial_supported_p (VALUE klass)
{
return Qtrue;
}
static VALUE
cr_pattern_mesh_supported_p (VALUE klass)
{
#ifdef RB_CAIRO_HAS_MESH_PATTERN
return Qtrue;
#else
return Qfalse;
#endif
}
static VALUE
cr_pattern_raster_source_supported_p (VALUE klass)
{
#ifdef RB_CAIRO_HAS_RASTER_SOURCE_PATTERN
return Qtrue;
#else
return Qfalse;
#endif
}
cairo_pattern_t *
rb_cairo_pattern_from_ruby_object (VALUE obj)
{
cairo_pattern_t *pattern;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_Pattern))
{
rb_raise (rb_eTypeError, "not a cairo pattern");
}
Data_Get_Struct (obj, cairo_pattern_t, pattern);
return pattern;
}
static void
cr_pattern_free (void *ptr)
{
if (ptr)
{
cairo_pattern_destroy ((cairo_pattern_t *) ptr);
}
}
VALUE
rb_cairo_pattern_to_ruby_object (cairo_pattern_t *pattern)
{
if (pattern)
{
VALUE klass;
klass = cr_pattern_get_klass (pattern);
cairo_pattern_reference (pattern);
return Data_Wrap_Struct (klass, NULL, cr_pattern_free, pattern);
}
else
{
return Qnil;
}
}
static VALUE
cr_pattern_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, cr_pattern_free, NULL);
}
static VALUE
cr_pattern_initialize (int argc, VALUE *argv, VALUE self)
{
rb_raise(rb_eNotImpError,
"%s class instantiation isn't supported on this cairo installation",
rb_obj_classname(self));
return Qnil;
}
static VALUE
cr_solid_pattern_initialize (int argc, VALUE *argv, VALUE self)
{
VALUE red, green, blue, alpha;
int n;
cairo_pattern_t *pattern;
n = rb_scan_args (argc, argv, "13", &red, &green, &blue, &alpha);
if (n == 1)
{
VALUE color = red;
color = cr_color_parse (color);
if (rb_cairo__is_kind_of (color, rb_cCairo_Color_Base))
red = rb_funcall (rb_funcall (color, id_to_rgb, 0), id_to_a, 0);
}
if (n == 1 && rb_cairo__is_kind_of (red, rb_cArray) &&
(RARRAY_LEN (red) == 3 || RARRAY_LEN (red) == 4))
{
VALUE ary = red;
n = RARRAY_LEN (ary);
red = rb_ary_entry (ary, 0);
green = rb_ary_entry (ary, 1);
blue = rb_ary_entry (ary, 2);
alpha = rb_ary_entry (ary, 3);
}
if (n == 3)
{
pattern = cairo_pattern_create_rgb (NUM2DBL (red),
NUM2DBL (green),
NUM2DBL (blue));
}
else if (n == 4)
{
pattern = cairo_pattern_create_rgba (NUM2DBL (red),
NUM2DBL (green),
NUM2DBL (blue),
NUM2DBL (alpha));
}
else
{
VALUE inspected;
inspected = rb_funcall (argc == 1 ? red : rb_ary_new4 (argc, argv),
id_inspect, 0);
rb_raise (rb_eArgError,
"invalid argument: %s (expect "
"(color_name), "
"(color_hex_triplet), "
"(Cairo::Color::RGB), "
"(Cairo::Color::CMYK), "
"(Cairo::Color::HSV), "
"(red, green, blue), "
"([red, green, blue]), "
"(red, green, blue, alpha) or "
"([red, green, blue, alpha])"
")",
RVAL2CSTR (inspected));
}
cr_pattern_check_status (pattern);
DATA_PTR (self) = pattern;
return Qnil;
}
static VALUE
cr_surface_pattern_initialize (VALUE self, VALUE surface)
{
cairo_pattern_t *pattern;
pattern = cairo_pattern_create_for_surface (RVAL2CRSURFACE (surface));
cr_pattern_check_status (pattern);
DATA_PTR (self) = pattern;
return Qnil;
}
static VALUE
cr_linear_pattern_initialize (VALUE self, VALUE x0, VALUE y0,
VALUE x1, VALUE y1)
{
cairo_pattern_t *pattern;
pattern = cairo_pattern_create_linear (NUM2DBL (x0), NUM2DBL (y0),
NUM2DBL (x1), NUM2DBL (y1));
cr_pattern_check_status (pattern);
DATA_PTR (self) = pattern;
return Qnil;
}
static VALUE
cr_radial_pattern_initialize (VALUE self, VALUE cx0, VALUE cy0, VALUE radius0,
VALUE cx1, VALUE cy1, VALUE radius1)
{
cairo_pattern_t *pattern;
pattern = cairo_pattern_create_radial (NUM2DBL (cx0), NUM2DBL (cy0),
NUM2DBL (radius0),
NUM2DBL (cx1), NUM2DBL (cy1),
NUM2DBL (radius1));
cr_pattern_check_status (pattern);
DATA_PTR (self) = pattern;
return Qnil;
}
/* Cairo::GradientPattern */
static VALUE
cr_gradient_pattern_add_color_stop_generic (int argc, VALUE *argv, VALUE self)
{
VALUE offset, red, green, blue, alpha;
int n;
n = rb_scan_args (argc, argv, "23", &offset, &red, &green, &blue, &alpha);
if (n == 2)
{
VALUE color = red;
color = cr_color_parse (color);
if (rb_cairo__is_kind_of (color, rb_cCairo_Color_Base))
red = rb_funcall (rb_funcall (color, id_to_rgb, 0), id_to_a, 0);
}
if (n == 2 && rb_cairo__is_kind_of (red, rb_cArray))
{
VALUE ary = red;
n = RARRAY_LEN (ary) + 1;
red = rb_ary_entry (ary, 0);
green = rb_ary_entry (ary, 1);
blue = rb_ary_entry (ary, 2);
alpha = rb_ary_entry (ary, 3);
}
if (n == 4 || (n == 5 && NIL_P (alpha)))
{
cairo_pattern_add_color_stop_rgb (_SELF (self), NUM2DBL (offset),
NUM2DBL (red), NUM2DBL (green),
NUM2DBL (blue));
}
else if (n == 5)
{
cairo_pattern_add_color_stop_rgba (_SELF (self), NUM2DBL (offset),
NUM2DBL (red), NUM2DBL (green),
NUM2DBL (blue), NUM2DBL (alpha));
}
else
{
VALUE inspected;
inspected = rb_funcall (rb_ary_new4 (argc, argv), id_inspect, 0);
rb_raise (rb_eArgError,
"invalid argument: %s (expect "
"(offset, color_name), "
"(offset, color_hex_triplet), "
"(offset, Cairo::Color::RGB), "
"(offset, Cairo::Color::CMYK), "
"(offset, Cairo::Color::HSV), "
"(offset, red, green, blue), "
"(offset, [red, green, blue]), "
"(offset, red, green, blue, alpha) or "
"(offset, [red, green, blue, alpha])"
")",
RVAL2CSTR (inspected));
}
cr_pattern_check_status (_SELF (self));
return self;
}
/* Cairo::Pattern */
static VALUE
cr_pattern_set_matrix (VALUE self, VALUE matrix)
{
cairo_pattern_set_matrix (_SELF (self), RVAL2CRMATRIX (matrix));
cr_pattern_check_status (_SELF (self));
return self;
}
static VALUE
cr_pattern_get_matrix (VALUE self)
{
cairo_matrix_t matrix;
cairo_pattern_get_matrix (_SELF (self), &matrix);
cr_pattern_check_status (_SELF (self));
return CRMATRIX2RVAL (&matrix);
}
static VALUE
cr_pattern_set_extend (VALUE self, VALUE extend)
{
cairo_pattern_set_extend (_SELF (self), RVAL2CREXTEND (extend));
cr_pattern_check_status (_SELF (self));
return self;
}
static VALUE
cr_pattern_get_extend (VALUE self)
{
return INT2NUM (cairo_pattern_get_extend (_SELF (self)));
}
static VALUE
cr_pattern_set_filter (VALUE self, VALUE filter)
{
cairo_pattern_set_filter (_SELF (self), RVAL2CRFILTER (filter));
cr_pattern_check_status (_SELF (self));
return self;
}
static VALUE
cr_pattern_get_filter (VALUE self)
{
return INT2NUM (cairo_pattern_get_filter (_SELF (self)));
}
#if CAIRO_CHECK_VERSION(1, 3, 0)
static VALUE
cr_solid_pattern_get_rgba (VALUE self)
{
double red, green, blue, alpha;
rb_cairo_check_status (cairo_pattern_get_rgba (_SELF (self),
&red, &green, &blue, &alpha));
return rb_ary_new3 (4,
rb_float_new (red), rb_float_new (green),
rb_float_new (blue), rb_float_new (alpha));
}
static VALUE
cr_solid_pattern_get_color (VALUE self)
{
return cr_color_parse (cr_solid_pattern_get_rgba (self));
}
static VALUE
cr_surface_pattern_get_surface (VALUE self)
{
cairo_surface_t *surface;
rb_cairo_check_status (cairo_pattern_get_surface (_SELF (self), &surface));
return CRSURFACE2RVAL (surface);
}
static VALUE
cr_gradient_pattern_get_color_stop_rgba (VALUE self, VALUE index)
{
cairo_status_t status;
double offset, red, green, blue, alpha;
status = cairo_pattern_get_color_stop_rgba (_SELF (self), NUM2INT (index),
&offset, &red, &green, &blue,
&alpha);
rb_cairo_check_status (status);
return rb_ary_new3 (5, rb_float_new (offset),
rb_float_new (red), rb_float_new (green),
rb_float_new (blue), rb_float_new (alpha));
}
static VALUE
cr_gradient_pattern_get_color_stop_color (VALUE self, VALUE index)
{
VALUE result, offset, rgba;
result = cr_gradient_pattern_get_color_stop_rgba (self, index);
offset = rb_ary_shift (result);
rgba = result;
return rb_ary_new3 (2, offset, cr_color_parse (rgba));
}
static VALUE
cr_gradient_pattern_get_color_stop_count (VALUE self)
{
cairo_status_t status;
int count;
status = cairo_pattern_get_color_stop_count (_SELF (self), &count);
rb_cairo_check_status (status);
return INT2NUM (count);
}
static VALUE
cr_linear_pattern_get_linear_points (VALUE self)
{
cairo_status_t status;
double x0, y0, x1, y1;
status = cairo_pattern_get_linear_points (_SELF (self), &x0, &y0, &x1, &y1);
rb_cairo_check_status (status);
return rb_ary_new3 (4,
rb_float_new (x0), rb_float_new (y0),
rb_float_new (x1), rb_float_new (y1));
}
static VALUE
cr_radial_pattern_get_radial_circles (VALUE self)
{
cairo_status_t status;
double x0, y0, r0, x1, y1, r1;
status = cairo_pattern_get_radial_circles (_SELF (self),
&x0, &y0, &r0,
&x1, &y1, &r1);
rb_cairo_check_status (status);
return rb_ary_new3 (2,
rb_ary_new3 (3,
rb_float_new (x0),
rb_float_new (y0),
rb_float_new (r0)),
rb_ary_new3 (3,
rb_float_new (x1),
rb_float_new (y1),
rb_float_new (r1)));
}
#endif
/* Cairo::SurfacePattern */
/* none */
#ifdef RB_CAIRO_HAS_MESH_PATTERN
/* Cairo::MeshPattern */
static VALUE
cr_mesh_pattern_initialize (VALUE self)
{
cairo_pattern_t *pattern;
pattern = cairo_pattern_create_mesh ();
cr_pattern_check_status (pattern);
DATA_PTR (self) = pattern;
return Qnil;
}
static VALUE
cr_mesh_pattern_end_patch (VALUE self)
{
cairo_pattern_t *pattern;
pattern = _SELF (self);
cairo_mesh_pattern_end_patch (pattern);
cr_pattern_check_status (pattern);
return self;
}
static VALUE
cr_mesh_pattern_begin_patch (VALUE self)
{
cairo_pattern_t *pattern;
pattern = _SELF (self);
cairo_mesh_pattern_begin_patch (pattern);
cr_pattern_check_status (pattern);
if (rb_block_given_p ())
return rb_ensure (rb_yield, self, cr_mesh_pattern_end_patch, self);
else
return self;
}
static VALUE
cr_mesh_pattern_curve_to (VALUE self,
VALUE x1, VALUE y1,
VALUE x2, VALUE y2,
VALUE x3, VALUE y3)
{
cairo_pattern_t *pattern;
pattern = _SELF (self);
cairo_mesh_pattern_curve_to (pattern,
NUM2DBL (x1), NUM2DBL (y1),
NUM2DBL (x2), NUM2DBL (y2),
NUM2DBL (x3), NUM2DBL (y3));
cr_pattern_check_status (pattern);
return self;
}
static VALUE
cr_mesh_pattern_line_to (VALUE self, VALUE x, VALUE y)
{
cairo_pattern_t *pattern;
pattern = _SELF (self);
cairo_mesh_pattern_line_to (pattern, NUM2DBL (x), NUM2DBL (y));
cr_pattern_check_status (pattern);
return self;
}
static VALUE
cr_mesh_pattern_move_to (VALUE self, VALUE x, VALUE y)
{
cairo_pattern_t *pattern;
pattern = _SELF (self);
cairo_mesh_pattern_move_to (pattern, NUM2DBL (x), NUM2DBL (y));
cr_pattern_check_status (pattern);
return self;
}
static VALUE
cr_mesh_pattern_set_control_point (VALUE self, VALUE rb_nth_point,
VALUE rb_x, VALUE rb_y)
{
cairo_pattern_t *pattern;
unsigned int nth_point;
pattern = _SELF (self);
nth_point = NUM2UINT (rb_nth_point);
if (0 <= nth_point && nth_point <= 3)
{
cairo_mesh_pattern_set_control_point (pattern, nth_point,
NUM2DBL (rb_x), NUM2DBL (rb_y));
}
else
{
VALUE inspected;
inspected = rb_funcall (rb_ary_new3 (3, rb_nth_point, rb_x, rb_y),
id_inspect, 0);
rb_raise (rb_eArgError, "nth_point must be 0, 1, 2 or 3: <%u>: <%s>",
nth_point, RVAL2CSTR (inspected));
}
cr_pattern_check_status (pattern);
return self;
}
static VALUE
cr_mesh_pattern_set_corner_color_generic (int argc, VALUE *argv, VALUE self)
{
cairo_pattern_t *pattern;
VALUE rb_nth_corner, rb_red, rb_green, rb_blue, rb_alpha;
unsigned int nth_corner;
double red, green, blue, alpha;
rb_scan_args (argc, argv, "41",
&rb_nth_corner, &rb_red, &rb_green, &rb_blue, &rb_alpha);
nth_corner = NUM2UINT (rb_nth_corner);
if (!(0 <= nth_corner && nth_corner <= 3))
{
VALUE inspected;
inspected = rb_funcall (rb_ary_new4 (argc, argv), id_inspect, 0);
rb_raise (rb_eArgError, "nth_corner must be 0, 1, 2 or 3: <%u>: <%s>",
nth_corner, RVAL2CSTR (inspected));
}
pattern = _SELF (self);
red = NUM2DBL (rb_red);
green = NUM2DBL (rb_green);
blue = NUM2DBL (rb_blue);
if (NIL_P (rb_alpha))
{
cairo_mesh_pattern_set_corner_color_rgb (pattern, nth_corner,
red, green, blue);
}
else
{
alpha = NUM2DBL (rb_alpha);
cairo_mesh_pattern_set_corner_color_rgba (pattern, nth_corner,
red, green, blue, alpha);
}
cr_pattern_check_status (pattern);
return self;
}
static VALUE
cr_mesh_pattern_get_patch_count (VALUE self)
{
cairo_pattern_t *pattern;
unsigned int count;
cairo_status_t status;
pattern = _SELF (self);
status = cairo_mesh_pattern_get_patch_count (pattern, &count);
rb_cairo_check_status (status);
return UINT2NUM (count);
}
static VALUE
cr_mesh_pattern_get_path (VALUE self, VALUE nth_patch)
{
cairo_pattern_t *pattern;
cairo_path_t *path;
pattern = _SELF (self);
path = cairo_mesh_pattern_get_path (pattern, NUM2UINT (nth_patch));
rb_cairo_check_status (path->status);
return CRPATH2RVAL (path);
}
static VALUE
cr_mesh_pattern_get_corner_color (VALUE self,
VALUE rb_nth_patch, VALUE rb_nth_corner)
{
cairo_pattern_t *pattern;
unsigned int nth_patch, nth_corner;
double red, green, blue, alpha;
cairo_status_t status;
nth_patch = NUM2UINT (rb_nth_patch);
nth_corner = NUM2UINT (rb_nth_corner);
if (!(0 <= nth_corner && nth_corner <= 3))
{
VALUE inspected;
inspected = rb_funcall (rb_ary_new3 (2, rb_nth_patch, rb_nth_corner),
id_inspect, 0);
rb_raise (rb_eArgError, "nth_corner must be 0, 1, 2 or 3: <%u>: <%s>",
nth_corner, RVAL2CSTR (inspected));
}
pattern = _SELF (self);
status = cairo_mesh_pattern_get_corner_color_rgba (pattern,
nth_patch, nth_corner,
&red,
&green,
&blue,
&alpha);
rb_cairo_check_status (status);
return rb_ary_new3 (4,
rb_float_new (red), rb_float_new (green),
rb_float_new (blue), rb_float_new (alpha));
}
static VALUE
cr_mesh_pattern_get_control_point (VALUE self,
VALUE rb_nth_patch, VALUE rb_nth_point)
{
cairo_pattern_t *pattern;
unsigned int nth_patch, nth_point;
double x, y;
cairo_status_t status;
nth_patch = NUM2UINT (rb_nth_patch);
nth_point = NUM2UINT (rb_nth_point);
if (!(0 <= nth_point && nth_point <= 3))
{
VALUE inspected;
inspected = rb_funcall (rb_ary_new3 (2, rb_nth_patch, rb_nth_point),
id_inspect, 0);
rb_raise (rb_eArgError, "nth_point must be 0, 1, 2 or 3: <%u>: <%s>",
nth_point, RVAL2CSTR (inspected));
}
pattern = _SELF (self);
status = cairo_mesh_pattern_get_control_point (pattern,
nth_patch, nth_point,
&x, &y);
rb_cairo_check_status (status);
return rb_ary_new3 (2, rb_float_new (x), rb_float_new (y));
}
#endif
#ifdef RB_CAIRO_HAS_RASTER_SOURCE_PATTERN
/* Cairo::RasterSourcePattern */
static cairo_surface_t *
cr_raster_source_acquire_callback (cairo_pattern_t *pattern,
void *callback_data,
cairo_surface_t *target,
const cairo_rectangle_int_t *extents)
{
VALUE rb_pattern;
VALUE rb_acquire;
cairo_surface_t *acquired_surface = NULL;
rb_pattern = POINTER2RVAL (callback_data);
rb_acquire = rb_iv_get (rb_pattern, "@acquire");
if (!NIL_P (rb_acquire))
{
VALUE rb_acquired_surface;
VALUE rb_target;
VALUE rb_extents;
rb_target = CRSURFACE2RVAL (target);
rb_extents = rb_funcall (rb_cCairo_Rectangle, id_new, 4,
INT2NUM (extents->x),
INT2NUM (extents->y),
INT2NUM (extents->width),
INT2NUM (extents->height));
rb_acquired_surface = rb_funcall (rb_acquire, id_call, 3,
rb_pattern, rb_target, rb_extents);
if (!NIL_P (rb_acquired_surface))
acquired_surface = RVAL2CRSURFACE (rb_acquired_surface);
}
return acquired_surface;
}
static void
cr_raster_source_release_callback (cairo_pattern_t *pattern,
void *callback_data,
cairo_surface_t *surface)
{
VALUE rb_pattern;
VALUE rb_release;
VALUE rb_surface;
rb_pattern = POINTER2RVAL (callback_data);
rb_release = rb_iv_get (rb_pattern, "@release");
if (NIL_P (rb_release))
return;
rb_surface = CRSURFACE2RVAL (surface);
rb_funcall (rb_release, id_call, 2, rb_pattern, rb_surface);
}
typedef struct cr_raster_source_notify_callback_data
{
VALUE pattern;
VALUE callback;
cairo_status_t status;
} cr_raster_source_notify_callback_data_t;
static VALUE
cr_raster_source_notify_callback_body (VALUE data)
{
cr_raster_source_notify_callback_data_t* callback_data;
callback_data = RVAL2POINTER (data);
rb_funcall (callback_data->callback, id_call, 1, callback_data->pattern);
return Qnil;
}
static VALUE
cr_raster_source_notify_callback_rescue (VALUE data, VALUE exception)
{
cr_raster_source_notify_callback_data_t *callback_data;
callback_data = RVAL2POINTER (data);
callback_data->status = rb_cairo__exception_to_status (exception);
if (callback_data->status == (cairo_status_t)-1)
rb_exc_raise (exception);
return Qnil;
}
static cairo_status_t
cr_raster_source_snapshot_callback (cairo_pattern_t *pattern,
void *callback_data)
{
VALUE rb_pattern;
VALUE rb_snapshot;
cr_raster_source_notify_callback_data_t data;
rb_pattern = POINTER2RVAL (callback_data);
rb_snapshot = rb_iv_get (rb_pattern, "@snapshot");
if (NIL_P (rb_snapshot))
return CAIRO_STATUS_SUCCESS;
data.pattern = rb_pattern;
data.callback = rb_snapshot;
data.status = CAIRO_STATUS_SUCCESS;
rb_rescue2 (cr_raster_source_notify_callback_body,
POINTER2RVAL (&data),
cr_raster_source_notify_callback_rescue,
POINTER2RVAL (&data),
rb_eException);
return data.status;
}
static cairo_status_t
cr_raster_source_copy_callback (cairo_pattern_t *pattern,
void *callback_data,
const cairo_pattern_t *other)
{
VALUE rb_pattern;
VALUE rb_copy;
cr_raster_source_notify_callback_data_t data;
rb_pattern = POINTER2RVAL (callback_data);
rb_copy = rb_iv_get (rb_pattern, "@copy");
if (NIL_P (rb_copy))
return CAIRO_STATUS_SUCCESS;
data.pattern = rb_pattern;
data.callback = rb_copy;
data.status = CAIRO_STATUS_SUCCESS;
rb_rescue2 (cr_raster_source_notify_callback_body,
POINTER2RVAL (&data),
cr_raster_source_notify_callback_rescue,
POINTER2RVAL (&data),
rb_eException);
return data.status;
}
static void
cr_raster_source_finish_callback (cairo_pattern_t *pattern, void *callback_data)
{
VALUE rb_pattern;
VALUE rb_finish;
rb_pattern = POINTER2RVAL (callback_data);
rb_finish = rb_iv_get (rb_pattern, "@finish");
if (NIL_P (rb_finish))
return;
rb_funcall (rb_finish, id_call, 1, rb_pattern);
}
static VALUE
cr_raster_source_pattern_initialize (int argc, VALUE *argv, VALUE self)
{
cairo_pattern_t *pattern;
cairo_content_t content;
int width, height;
VALUE arg1, arg2, arg3;
rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3);
if (argc == 2)
{
content = CAIRO_CONTENT_COLOR_ALPHA;
width = NUM2INT (arg1);
height = NUM2INT (arg2);
}
else
{
content = RVAL2CRCONTENT (arg1);
width = NUM2INT (arg2);
height = NUM2INT (arg3);
}
pattern = cairo_pattern_create_raster_source (RVAL2POINTER (self),
content, width, height);
cr_pattern_check_status (pattern);
DATA_PTR (self) = pattern;
rb_iv_set (self, "@acquire", Qnil);
rb_iv_set (self, "@release", Qnil);
rb_iv_set (self, "@snapshot", Qnil);
rb_iv_set (self, "@copy", Qnil);
rb_iv_set (self, "@finish", Qnil);
cairo_raster_source_pattern_set_acquire (pattern,
cr_raster_source_acquire_callback,
cr_raster_source_release_callback);
cairo_raster_source_pattern_set_snapshot (pattern,
cr_raster_source_snapshot_callback);
cairo_raster_source_pattern_set_copy (pattern,
cr_raster_source_copy_callback);
cairo_raster_source_pattern_set_finish (pattern,
cr_raster_source_finish_callback);
return Qnil;
}
static VALUE
cr_raster_source_pattern_acquire (VALUE self)
{
if (!rb_block_given_p ())
{
VALUE inspected;
inspected = rb_funcall (self, id_inspect, 0);
rb_raise (rb_eArgError, "acquire block is missing: %s",
RVAL2CSTR (inspected));
}
rb_iv_set (self, "@acquire", rb_block_proc ());
return self;
}
static VALUE
cr_raster_source_pattern_release (VALUE self)
{
if (!rb_block_given_p ())
{
VALUE inspected;
inspected = rb_funcall (self, id_inspect, 0);
rb_raise (rb_eArgError, "release block is missing: %s",
RVAL2CSTR (inspected));
}
rb_iv_set (self, "@release", rb_block_proc ());
return self;
}
static VALUE
cr_raster_source_pattern_snapshot (VALUE self)
{
if (!rb_block_given_p ())
{
VALUE inspected;
inspected = rb_funcall (self, id_inspect, 0);
rb_raise (rb_eArgError, "snapshot block is missing: %s",
RVAL2CSTR (inspected));
}
rb_iv_set (self, "@snapshot", rb_block_proc ());
return self;
}
static VALUE
cr_raster_source_pattern_copy (VALUE self)
{
if (!rb_block_given_p ())
{
VALUE inspected;
inspected = rb_funcall (self, id_inspect, 0);
rb_raise (rb_eArgError, "copy block is missing: %s",
RVAL2CSTR (inspected));
}
rb_iv_set (self, "@copy", rb_block_proc ());
return self;
}
static VALUE
cr_raster_source_pattern_finish (VALUE self)
{
if (!rb_block_given_p ())
{
VALUE inspected;
inspected = rb_funcall (self, id_inspect, 0);
rb_raise (rb_eArgError, "finish block is missing: %s",
RVAL2CSTR (inspected));
}
rb_iv_set (self, "@finish", rb_block_proc ());
return self;
}
#endif
void
Init_cairo_pattern (void)
{
id_parse = rb_intern ("parse");
id_to_rgb = rb_intern ("to_rgb");
id_to_a = rb_intern ("to_a");
id_inspect = rb_intern ("inspect");
id_new = rb_intern ("new");
id_call = rb_intern ("call");
rb_cCairo_Pattern =
rb_define_class_under (rb_mCairo, "Pattern", rb_cObject);
rb_define_alloc_func (rb_cCairo_Pattern, cr_pattern_allocate);
rb_define_singleton_method (rb_cCairo_Pattern, "solid_supported?",
cr_pattern_solid_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Pattern, "surface_supported?",
cr_pattern_surface_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Pattern, "gradient_supported?",
cr_pattern_gradient_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Pattern, "linear_supported?",
cr_pattern_linear_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Pattern, "radial_supported?",
cr_pattern_radial_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Pattern, "mesh_supported?",
cr_pattern_mesh_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Pattern, "raster_source_supported?",
cr_pattern_raster_source_supported_p, 0);
rb_define_method (rb_cCairo_Pattern, "initialize", cr_pattern_initialize, -1);
rb_define_method (rb_cCairo_Pattern, "set_matrix", cr_pattern_set_matrix, 1);
rb_define_method (rb_cCairo_Pattern, "matrix", cr_pattern_get_matrix, 0);
rb_define_method (rb_cCairo_Pattern, "set_extend", cr_pattern_set_extend, 1);
rb_define_alias (rb_cCairo_Pattern, "__extend__", "extend");
rb_define_method (rb_cCairo_Pattern, "extend", cr_pattern_get_extend, 0);
rb_define_method (rb_cCairo_Pattern, "set_filter", cr_pattern_set_filter, 1);
rb_define_method (rb_cCairo_Pattern, "filter", cr_pattern_get_filter, 0);
RB_CAIRO_DEF_SETTERS (rb_cCairo_Pattern);
rb_cCairo_SolidPattern =
rb_define_class_under (rb_mCairo, "SolidPattern", rb_cCairo_Pattern);
rb_define_method (rb_cCairo_SolidPattern, "initialize",
cr_solid_pattern_initialize, -1);
#if CAIRO_CHECK_VERSION(1, 3, 0)
rb_define_method (rb_cCairo_SolidPattern, "rgba",
cr_solid_pattern_get_rgba, 0);
rb_define_method (rb_cCairo_SolidPattern, "color",
cr_solid_pattern_get_color, 0);
#endif
RB_CAIRO_DEF_SETTERS (rb_cCairo_SolidPattern);
rb_cCairo_SurfacePattern =
rb_define_class_under (rb_mCairo, "SurfacePattern", rb_cCairo_Pattern);
rb_define_method (rb_cCairo_SurfacePattern, "initialize",
cr_surface_pattern_initialize, 1);
#if CAIRO_CHECK_VERSION(1, 3, 0)
rb_define_method (rb_cCairo_SurfacePattern, "surface",
cr_surface_pattern_get_surface, 0);
#endif
RB_CAIRO_DEF_SETTERS (rb_cCairo_SurfacePattern);
rb_cCairo_GradientPattern =
rb_define_class_under (rb_mCairo, "GradientPattern", rb_cCairo_Pattern);
rb_define_method (rb_cCairo_GradientPattern, "add_color_stop",
cr_gradient_pattern_add_color_stop_generic, -1);
rb_define_alias (rb_cCairo_GradientPattern,
"add_color_stop_rgb", "add_color_stop");
rb_define_alias (rb_cCairo_GradientPattern,
"add_color_stop_rgba", "add_color_stop");
#if CAIRO_CHECK_VERSION(1, 3, 0)
rb_define_method (rb_cCairo_GradientPattern, "get_color_stop_rgba",
cr_gradient_pattern_get_color_stop_rgba, 1);
rb_define_method (rb_cCairo_GradientPattern, "get_color_stop_color",
cr_gradient_pattern_get_color_stop_color, 1);
rb_define_method (rb_cCairo_GradientPattern, "color_stop_count",
cr_gradient_pattern_get_color_stop_count, 0);
#endif
RB_CAIRO_DEF_SETTERS (rb_cCairo_GradientPattern);
rb_cCairo_LinearPattern =
rb_define_class_under (rb_mCairo, "LinearPattern",
rb_cCairo_GradientPattern);
rb_define_method (rb_cCairo_LinearPattern, "initialize",
cr_linear_pattern_initialize, 4);
#if CAIRO_CHECK_VERSION(1, 3, 0)
rb_define_method (rb_cCairo_LinearPattern, "points",
cr_linear_pattern_get_linear_points, 0);
#endif
RB_CAIRO_DEF_SETTERS (rb_cCairo_LinearPattern);
rb_cCairo_RadialPattern =
rb_define_class_under (rb_mCairo, "RadialPattern",
rb_cCairo_GradientPattern);
rb_define_method (rb_cCairo_RadialPattern, "initialize",
cr_radial_pattern_initialize, 6);
#if CAIRO_CHECK_VERSION(1, 3, 0)
rb_define_method (rb_cCairo_RadialPattern, "circles",
cr_radial_pattern_get_radial_circles, 0);
#endif
RB_CAIRO_DEF_SETTERS (rb_cCairo_RadialPattern);
rb_cCairo_MeshPattern =
rb_define_class_under (rb_mCairo, "MeshPattern",
rb_cCairo_Pattern);
#ifdef RB_CAIRO_HAS_MESH_PATTERN
rb_define_method (rb_cCairo_MeshPattern, "initialize",
cr_mesh_pattern_initialize, 0);
rb_define_method (rb_cCairo_MeshPattern, "begin_patch",
cr_mesh_pattern_begin_patch, 0);
rb_define_method (rb_cCairo_MeshPattern, "end_patch",
cr_mesh_pattern_end_patch, 0);
rb_define_method (rb_cCairo_MeshPattern, "curve_to",
cr_mesh_pattern_curve_to, 6);
rb_define_method (rb_cCairo_MeshPattern, "line_to",
cr_mesh_pattern_line_to, 2);
rb_define_method (rb_cCairo_MeshPattern, "move_to",
cr_mesh_pattern_move_to, 2);
rb_define_method (rb_cCairo_MeshPattern, "set_control_point",
cr_mesh_pattern_set_control_point, 3);
rb_define_method (rb_cCairo_MeshPattern, "set_corner_color",
cr_mesh_pattern_set_corner_color_generic, -1);
rb_define_alias (rb_cCairo_MeshPattern,
"set_corner_color_rgb", "set_corner_color");
rb_define_alias (rb_cCairo_MeshPattern,
"set_corner_color_rgba", "set_corner_color");
rb_define_method (rb_cCairo_MeshPattern, "patch_count",
cr_mesh_pattern_get_patch_count, 0);
rb_define_method (rb_cCairo_MeshPattern, "get_path",
cr_mesh_pattern_get_path, 1);
rb_define_method (rb_cCairo_MeshPattern, "get_corner_color",
cr_mesh_pattern_get_corner_color, 2);
rb_define_method (rb_cCairo_MeshPattern, "get_control_point",
cr_mesh_pattern_get_control_point, 2);
#endif
RB_CAIRO_DEF_SETTERS (rb_cCairo_MeshPattern);
rb_cCairo_RasterSourcePattern =
rb_define_class_under (rb_mCairo, "RasterSourcePattern",
rb_cCairo_Pattern);
#ifdef RB_CAIRO_HAS_RASTER_SOURCE_PATTERN
rb_define_method (rb_cCairo_RasterSourcePattern, "initialize",
cr_raster_source_pattern_initialize, -1);
rb_define_method (rb_cCairo_RasterSourcePattern, "acquire",
cr_raster_source_pattern_acquire, 0);
rb_define_method (rb_cCairo_RasterSourcePattern, "release",
cr_raster_source_pattern_release, 0);
rb_define_method (rb_cCairo_RasterSourcePattern, "snapshot",
cr_raster_source_pattern_snapshot, 0);
rb_define_method (rb_cCairo_RasterSourcePattern, "copy",
cr_raster_source_pattern_copy, 0);
rb_define_method (rb_cCairo_RasterSourcePattern, "finish",
cr_raster_source_pattern_finish, 0);
#endif
RB_CAIRO_DEF_SETTERS (rb_cCairo_RasterSourcePattern);
}
cairo-1.12.8/ext/cairo/rb_cairo.h 0000644 0000041 0000041 00000034104 12256106703 016562 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-09-19 12:56:27 $
*
* Copyright 2006-2008 Kouhei Sutou
* Copyright 2005 Øyvind Kolås
* Copyright 2004-2005 MenTaLguY
*
* This file is made available under the same terms as Ruby
*
*/
#ifndef RB_CAIRO_H
#define RB_CAIRO_H
#include
#ifdef CAIRO_HAS_PS_SURFACE
# include
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
# include
#endif
#ifdef CAIRO_HAS_SVG_SURFACE
# include
#endif
#ifdef CAIRO_HAS_SCRIPT_SURFACE
# include
#endif
#define CAIRO_CHECK_VERSION(major, minor, micro) \
(CAIRO_VERSION_MAJOR > (major) || \
(CAIRO_VERSION_MAJOR == (major) && CAIRO_VERSION_MINOR > (minor)) || \
(CAIRO_VERSION_MAJOR == (major) && CAIRO_VERSION_MINOR == (minor) && \
CAIRO_VERSION_MICRO >= (micro)))
#include "ruby.h"
#if defined(__cplusplus)
# define RB_CAIRO_BEGIN_DECLS extern "C" {
# define RB_CAIRO_END_DECLS }
#else
# define RB_CAIRO_BEGIN_DECLS
# define RB_CAIRO_END_DECLS
#endif
RB_CAIRO_BEGIN_DECLS
#if defined(RUBY_CAIRO_PLATFORM_WIN32) && !defined(RB_CAIRO_PLATFORM_WIN32)
# define RB_CAIRO_PLATFORM_WIN32 RUBY_CAIRO_PLATFORM_WIN32
#endif
#if defined(RUBY_CAIRO_STATIC_COMPILATION) && !defined(RB_CAIRO_STATIC_COMPILATION)
# define RB_CAIRO_STATIC_COMPILATION RUBY_CAIRO_STATIC_COMPILATION
#endif
#if defined(RB_CAIRO_PLATFORM_WIN32) && !defined(RB_CAIRO_STATIC_COMPILATION)
# ifdef RB_CAIRO_COMPILATION
# define RB_CAIRO_VAR __declspec(dllexport)
# else
# define RB_CAIRO_VAR extern __declspec(dllimport)
# endif
#else
# define RB_CAIRO_VAR extern
#endif
#define RB_CAIRO_VERSION_MAJOR 1
#define RB_CAIRO_VERSION_MINOR 12
#define RB_CAIRO_VERSION_MICRO 8
RB_CAIRO_VAR VALUE rb_mCairo;
RB_CAIRO_VAR VALUE rb_cCairo_Context;
RB_CAIRO_VAR VALUE rb_cCairo_Rectangle;
RB_CAIRO_VAR VALUE rb_cCairo_Point;
RB_CAIRO_VAR VALUE rb_cCairo_Path;
RB_CAIRO_VAR VALUE rb_cCairo_PathData;
RB_CAIRO_VAR VALUE rb_cCairo_PathMoveTo;
RB_CAIRO_VAR VALUE rb_cCairo_PathLineTo;
RB_CAIRO_VAR VALUE rb_cCairo_PathCurveTo;
RB_CAIRO_VAR VALUE rb_cCairo_PathClosePath;
RB_CAIRO_VAR VALUE rb_cCairo_Matrix;
RB_CAIRO_VAR VALUE rb_cCairo_Region;
RB_CAIRO_VAR VALUE rb_cCairo_Pattern;
RB_CAIRO_VAR VALUE rb_cCairo_SolidPattern;
RB_CAIRO_VAR VALUE rb_cCairo_SurfacePattern;
RB_CAIRO_VAR VALUE rb_cCairo_GradientPattern;
RB_CAIRO_VAR VALUE rb_cCairo_LinearPattern;
RB_CAIRO_VAR VALUE rb_cCairo_RadialPattern;
RB_CAIRO_VAR VALUE rb_cCairo_MeshPattern;
RB_CAIRO_VAR VALUE rb_cCairo_RasterSourcePattern;
RB_CAIRO_VAR VALUE rb_cCairo_FontFace;
RB_CAIRO_VAR VALUE rb_cCairo_ToyFontFace;
RB_CAIRO_VAR VALUE rb_cCairo_UserFontFace;
RB_CAIRO_VAR VALUE rb_cCairo_UserFontFace_TextToGlyphsData;
RB_CAIRO_VAR VALUE rb_cCairo_FontExtents;
RB_CAIRO_VAR VALUE rb_cCairo_FontOptions;
RB_CAIRO_VAR VALUE rb_cCairo_ScaledFont;
RB_CAIRO_VAR VALUE rb_cCairo_TextExtents;
RB_CAIRO_VAR VALUE rb_cCairo_Glyph;
RB_CAIRO_VAR VALUE rb_cCairo_Surface;
RB_CAIRO_VAR VALUE rb_cCairo_ImageSurface;
RB_CAIRO_VAR VALUE rb_cCairo_PDFSurface;
RB_CAIRO_VAR VALUE rb_cCairo_PSSurface;
RB_CAIRO_VAR VALUE rb_cCairo_SVGSurface;
RB_CAIRO_VAR VALUE rb_cCairo_Win32Surface;
RB_CAIRO_VAR VALUE rb_cCairo_Win32PrintingSurface;
/* For backward compatibility*/
#define rb_cCairo_WIN32Surface rb_cCairo_Win32Surface
RB_CAIRO_VAR VALUE rb_cCairo_QuartzSurface;
RB_CAIRO_VAR VALUE rb_cCairo_QuartzImageSurface;
RB_CAIRO_VAR VALUE rb_cCairo_ScriptSurface;
RB_CAIRO_VAR VALUE rb_cCairo_QtSurface;
RB_CAIRO_VAR VALUE rb_cCairo_RecordingSurface;
RB_CAIRO_VAR VALUE rb_cCairo_VGSurface;
RB_CAIRO_VAR VALUE rb_cCairo_GLSurface;
RB_CAIRO_VAR VALUE rb_cCairo_GLTextureSurface;
RB_CAIRO_VAR VALUE rb_cCairo_DRMSurface;
RB_CAIRO_VAR VALUE rb_cCairo_TeeSurface;
RB_CAIRO_VAR VALUE rb_cCairo_XMLSurface;
RB_CAIRO_VAR VALUE rb_cCairo_SkiaSurface;
RB_CAIRO_VAR VALUE rb_cCairo_SubSurface;
RB_CAIRO_VAR VALUE rb_cCairo_Device;
RB_CAIRO_VAR VALUE rb_cCairo_DRMDevice;
RB_CAIRO_VAR VALUE rb_cCairo_GLDevice;
RB_CAIRO_VAR VALUE rb_cCairo_ScriptDevice;
RB_CAIRO_VAR VALUE rb_cCairo_XCBDevice;
RB_CAIRO_VAR VALUE rb_cCairo_XlibtDevice;
RB_CAIRO_VAR VALUE rb_cCairo_XMLDevice;
RB_CAIRO_VAR VALUE rb_mCairo_Operator;
RB_CAIRO_VAR VALUE rb_mCairo_Antialias;
RB_CAIRO_VAR VALUE rb_mCairo_FillRule;
RB_CAIRO_VAR VALUE rb_mCairo_LineCap;
RB_CAIRO_VAR VALUE rb_mCairo_LineJoin;
RB_CAIRO_VAR VALUE rb_mCairo_FontSlant;
RB_CAIRO_VAR VALUE rb_mCairo_FontWeight;
RB_CAIRO_VAR VALUE rb_mCairo_SubpixelOrder;
RB_CAIRO_VAR VALUE rb_mCairo_HintStyle;
RB_CAIRO_VAR VALUE rb_mCairo_HintMetrics;
RB_CAIRO_VAR VALUE rb_mCairo_FontType;
RB_CAIRO_VAR VALUE rb_mCairo_PathDataType;
RB_CAIRO_VAR VALUE rb_mCairo_Content;
RB_CAIRO_VAR VALUE rb_mCairo_SurfaceType;
RB_CAIRO_VAR VALUE rb_mCairo_Format;
RB_CAIRO_VAR VALUE rb_mCairo_PatternType;
RB_CAIRO_VAR VALUE rb_mCairo_Extend;
RB_CAIRO_VAR VALUE rb_mCairo_Filter;
RB_CAIRO_VAR VALUE rb_mCairo_SVGVersion;
RB_CAIRO_VAR VALUE rb_mCairo_PSLevel;
RB_CAIRO_VAR VALUE rb_mCairo_PDFVersion;
RB_CAIRO_VAR VALUE rb_mCairo_SVGVersion;
RB_CAIRO_VAR VALUE rb_mCairo_TextClusterFlag;
RB_CAIRO_VAR VALUE rb_mCairo_ScriptMode;
RB_CAIRO_VAR VALUE rb_mCairo_MimeType;
RB_CAIRO_VAR VALUE rb_mCairo_RegionOverlap;
RB_CAIRO_VAR VALUE rb_mCairo_Color;
RB_CAIRO_VAR VALUE rb_cCairo_Color_Base;
RB_CAIRO_VAR VALUE rb_cCairo_Paper;
#define RVAL2POINTER(obj) ((void *)(obj))
#define POINTER2RVAL(pointer) ((VALUE)(pointer))
#define RVAL2CRCONTEXT(obj) (rb_cairo_context_from_ruby_object(obj))
#define CRCONTEXT2RVAL(cr) (rb_cairo_context_to_ruby_object(cr))
#define RVAL2CRPATH(obj) (rb_cairo_path_from_ruby_object(obj))
#define CRPATH2RVAL(path) (rb_cairo_path_to_ruby_object(path))
#define RVAL2CRMATRIX(obj) (rb_cairo_matrix_from_ruby_object(obj))
#define CRMATRIX2RVAL(matrix) (rb_cairo_matrix_to_ruby_object(matrix))
#define RVAL2CRREGION(obj) (rb_cairo_region_from_ruby_object(obj))
#define CRREGION2RVAL(region) (rb_cairo_region_to_ruby_object(region))
#define RVAL2CRPATTERN(obj) (rb_cairo_pattern_from_ruby_object(obj))
#define CRPATTERN2RVAL(pattern) (rb_cairo_pattern_to_ruby_object(pattern))
#define RVAL2CRFONTFACE(obj) (rb_cairo_font_face_from_ruby_object(obj))
#define CRFONTFACE2RVAL(face) (rb_cairo_font_face_to_ruby_object(face))
#define RVAL2CRFONTEXTENTS(obj) (rb_cairo_font_extents_from_ruby_object(obj))
#define CRFONTEXTENTS2RVAL(ext) (rb_cairo_font_extents_to_ruby_object(ext))
#define RVAL2CRFONTOPTIONS(obj) (rb_cairo_font_options_from_ruby_object(obj))
#define CRFONTOPTIONS2RVAL(opt) (rb_cairo_font_options_to_ruby_object(opt))
#define RVAL2CRSCALEDFONT(obj) (rb_cairo_scaled_font_from_ruby_object(obj))
#define CRSCALEDFONT2RVAL(font) (rb_cairo_scaled_font_to_ruby_object(font))
#define RVAL2CRTEXTEXTENTS(obj) (rb_cairo_text_extents_from_ruby_object(obj))
#define CRTEXTEXTENTS2RVAL(ext) (rb_cairo_text_extents_to_ruby_object(ext))
#define RVAL2CRGLYPH(obj) (rb_cairo_glyph_from_ruby_object(obj))
#define CRGLYPH2RVAL(glyph) (rb_cairo_glyph_to_ruby_object(glyph))
#define RVAL2CRTEXTCLUSTER(obj) (rb_cairo_text_cluster_from_ruby_object(obj))
#define CRTEXTCLUSTER2RVAL(cluster) (rb_cairo_text_cluster_to_ruby_object(cluster))
#define RVAL2CRSURFACE(obj) (rb_cairo_surface_from_ruby_object(obj))
#define CRSURFACE2RVAL(surface) (rb_cairo_surface_to_ruby_object(surface))
#define CRSURFACE2RVAL_WITH_DESTROY(surface) \
(rb_cairo_surface_to_ruby_object_with_destroy(surface))
#define RVAL2CRDEVICE(obj) (rb_cairo_device_from_ruby_object(obj))
#define CRDEVICE2RVAL(device) (rb_cairo_device_to_ruby_object(device))
cairo_t *rb_cairo_context_from_ruby_object (VALUE obj);
VALUE rb_cairo_context_to_ruby_object (cairo_t *cr);
cairo_path_t *rb_cairo_path_from_ruby_object (VALUE obj);
VALUE rb_cairo_path_to_ruby_object (cairo_path_t *path);
cairo_matrix_t *rb_cairo_matrix_from_ruby_object (VALUE obj);
VALUE rb_cairo_matrix_to_ruby_object (cairo_matrix_t *matrix);
#if CAIRO_CHECK_VERSION(1, 10, 0)
cairo_region_t *rb_cairo_region_from_ruby_object (VALUE obj);
VALUE rb_cairo_region_to_ruby_object (cairo_region_t *region);
#endif
cairo_pattern_t *rb_cairo_pattern_from_ruby_object (VALUE obj);
VALUE rb_cairo_pattern_to_ruby_object (cairo_pattern_t *pat);
cairo_font_face_t *rb_cairo_font_face_from_ruby_object (VALUE obj);
VALUE rb_cairo_font_face_to_ruby_object (cairo_font_face_t *face);
cairo_font_extents_t *rb_cairo_font_extents_from_ruby_object (VALUE obj);
VALUE rb_cairo_font_extents_to_ruby_object (cairo_font_extents_t *extents);
cairo_font_options_t *rb_cairo_font_options_from_ruby_object (VALUE obj);
VALUE rb_cairo_font_options_to_ruby_object (cairo_font_options_t *options);
cairo_scaled_font_t *rb_cairo_scaled_font_from_ruby_object (VALUE obj);
VALUE rb_cairo_scaled_font_to_ruby_object (cairo_scaled_font_t *options);
cairo_text_extents_t *rb_cairo_text_extents_from_ruby_object (VALUE obj);
VALUE rb_cairo_text_extents_to_ruby_object (cairo_text_extents_t *extents);
cairo_glyph_t *rb_cairo_glyph_from_ruby_object (VALUE obj);
VALUE rb_cairo_glyph_to_ruby_object (cairo_glyph_t *glyph);
#if CAIRO_CHECK_VERSION(1, 7, 2)
cairo_text_cluster_t *rb_cairo_text_cluster_from_ruby_object (VALUE obj);
VALUE rb_cairo_text_cluster_to_ruby_object (cairo_text_cluster_t *cluster);
#endif
cairo_surface_t *rb_cairo_surface_from_ruby_object (VALUE obj);
VALUE rb_cairo_surface_to_ruby_object (cairo_surface_t *surface);
VALUE rb_cairo_surface_to_ruby_object_with_destroy
(cairo_surface_t *surface);
#if CAIRO_CHECK_VERSION(1, 10, 0)
cairo_device_t *rb_cairo_device_from_ruby_object (VALUE obj);
VALUE rb_cairo_device_to_ruby_object (cairo_device_t *device);
#endif
#define RVAL2CROPERATOR(obj) (rb_cairo_operator_from_ruby_object(obj))
#define RVAL2CRANTIALIAS(obj) (rb_cairo_antialias_from_ruby_object(obj))
#define RVAL2CRFILLRULE(obj) (rb_cairo_fill_rule_from_ruby_object(obj))
#define RVAL2CRLINECAP(obj) (rb_cairo_line_cap_from_ruby_object(obj))
#define RVAL2CRLINEJOIN(obj) (rb_cairo_line_join_from_ruby_object(obj))
#define RVAL2CRFONTSLANT(obj) (rb_cairo_font_slant_from_ruby_object(obj))
#define RVAL2CRFONTWEIGHT(obj) (rb_cairo_font_weight_from_ruby_object(obj))
#define RVAL2CRSUBPIXELORDER(obj) (rb_cairo_subpixel_order_from_ruby_object(obj))
#define RVAL2CRHINTSTYLE(obj) (rb_cairo_hint_style_from_ruby_object(obj))
#define RVAL2CRHINTMETRICS(obj) (rb_cairo_hint_metrics_from_ruby_object(obj))
#define RVAL2CRPATHDATATYPE(obj) (rb_cairo_path_data_type_from_ruby_object(obj))
#define RVAL2CRCONTENT(obj) (rb_cairo_content_from_ruby_object(obj))
#define RVAL2CRFORMAT(obj) (rb_cairo_format_from_ruby_object(obj))
#define RVAL2CREXTEND(obj) (rb_cairo_extend_from_ruby_object(obj))
#define RVAL2CRFILTER(obj) (rb_cairo_filter_from_ruby_object(obj))
#ifdef CAIRO_HAS_SVG_SURFACE
#define RVAL2CRSVGVERSION(obj) (rb_cairo_svg_version_from_ruby_object(obj))
#endif
#ifdef CAIRO_HAS_PS_SURFACE
# if CAIRO_CHECK_VERSION(1, 5, 2)
#define RVAL2CRPSLEVEL(obj) (rb_cairo_ps_level_from_ruby_object(obj))
# endif
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
# if CAIRO_CHECK_VERSION(1, 10, 0)
#define RVAL2CRPDFVERSION(obj) (rb_cairo_pdf_version_from_ruby_object(obj))
# endif
#endif
#if CAIRO_CHECK_VERSION(1, 7, 6)
#define RVAL2CRTEXTCLUSTERFLAGS(obj) (rb_cairo_text_cluster_flags_from_ruby_object(obj))
#endif
#ifdef CAIRO_HAS_SCRIPT_SURFACE
#define RVAL2CRSCRIPTMODE(obj) (rb_cairo_script_mode_from_ruby_object(obj))
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
#define RVAL2CRREGIONOVERLAP(obj) (rb_cairo_region_overalap_from_ruby_object(obj))
#endif
cairo_operator_t rb_cairo_operator_from_ruby_object (VALUE obj);
cairo_antialias_t rb_cairo_antialias_from_ruby_object (VALUE obj);
cairo_fill_rule_t rb_cairo_fill_rule_from_ruby_object (VALUE obj);
cairo_line_cap_t rb_cairo_line_cap_from_ruby_object (VALUE obj);
cairo_line_join_t rb_cairo_line_join_from_ruby_object (VALUE obj);
cairo_font_slant_t rb_cairo_font_slant_from_ruby_object (VALUE obj);
cairo_font_weight_t rb_cairo_font_weight_from_ruby_object (VALUE obj);
cairo_subpixel_order_t rb_cairo_subpixel_order_from_ruby_object (VALUE obj);
cairo_hint_style_t rb_cairo_hint_style_from_ruby_object (VALUE obj);
cairo_hint_metrics_t rb_cairo_hint_metrics_from_ruby_object (VALUE obj);
cairo_path_data_type_t rb_cairo_path_data_type_from_ruby_object (VALUE obj);
cairo_content_t rb_cairo_content_from_ruby_object (VALUE obj);
cairo_format_t rb_cairo_format_from_ruby_object (VALUE obj);
cairo_extend_t rb_cairo_extend_from_ruby_object (VALUE obj);
cairo_filter_t rb_cairo_filter_from_ruby_object (VALUE obj);
#ifdef CAIRO_HAS_SVG_SURFACE
cairo_svg_version_t rb_cairo_svg_version_from_ruby_object (VALUE obj);
#endif
#ifdef CAIRO_HAS_PS_SURFACE
# if CAIRO_CHECK_VERSION(1, 5, 2)
cairo_ps_level_t rb_cairo_ps_level_from_ruby_object (VALUE obj);
# endif
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
# if CAIRO_CHECK_VERSION(1, 10, 0)
cairo_pdf_version_t rb_cairo_pdf_version_from_ruby_object (VALUE obj);
# endif
#endif
#if CAIRO_CHECK_VERSION(1, 7, 6)
cairo_text_cluster_flags_t rb_cairo_text_cluster_flags_from_ruby_object (VALUE obj);
#endif
#ifdef CAIRO_HAS_SCRIPT_SURFACE
cairo_script_mode_t rb_cairo_script_mode_from_ruby_object (VALUE obj);
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
cairo_region_overlap_t rb_cairo_region_overlap_from_ruby_object(VALUE obj);
#endif
void rb_cairo_check_status (cairo_status_t status);
#define RB_CAIRO_DEF_SETTERS(klass) rb_cairo_def_setters(klass);
void rb_cairo_def_setters (VALUE klass);
RB_CAIRO_END_DECLS
#endif
cairo-1.12.8/ext/cairo/rb_cairo_private.c 0000644 0000041 0000041 00000012452 12256106703 020311 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-08-17 07:21:42 $
*
* Copyright 2005-2008 Kouhei Sutou
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
static ID cr_id_normalize_const_name;
static ID cr_id_objects;
static ID cr_id_dup;
static ID cr_id_inspect;
static ID cr_id_exit_application;
VALUE
rb_cairo__float_array (double *values, unsigned count)
{
VALUE result;
unsigned i;
result = rb_ary_new2 (count);
for (i = 0; i < count; i++)
{
rb_ary_push (result, rb_float_new (values[i]));
}
return result;
}
void
rb_cairo__glyphs_to_array (VALUE rb_array, cairo_glyph_t *glyphs, int length)
{
int i;
for (i = 0; i < length; i++)
{
memcpy ((char *) &glyphs[i],
(char *) RVAL2CRGLYPH (rb_ary_entry (rb_array, i)),
sizeof (cairo_glyph_t));
}
}
VALUE
rb_cairo__const_get (VALUE name, const char *prefix)
{
VALUE rb_normalized_name;
char *const_name, *normalized_name;
size_t prefix_len, normalized_name_len;
rb_normalized_name = rb_funcall (rb_mCairo,
cr_id_normalize_const_name, 1, name);
normalized_name = RVAL2CSTR (rb_normalized_name);
prefix_len = strlen (prefix);
normalized_name_len = strlen (normalized_name);
const_name = ALLOCA_N (char, prefix_len + normalized_name_len + 1);
strncpy (const_name, prefix, prefix_len);
strncpy (const_name + prefix_len, normalized_name, normalized_name_len);
const_name[prefix_len + normalized_name_len] = '\0';
return rb_const_get (rb_mCairo, rb_intern (const_name));
}
cairo_bool_t
rb_cairo__is_kind_of (VALUE object, VALUE klass)
{
return RVAL2CBOOL (rb_obj_is_kind_of (object, klass));
}
rb_cairo__object_holder_t *
rb_cairo__object_holder_new (VALUE klass, VALUE object)
{
rb_cairo__object_holder_t *holder;
holder = ALLOC(rb_cairo__object_holder_t);
rb_cairo__gc_guard_add (klass, object);
holder->object = object;
return holder;
}
void
rb_cairo__object_holder_free (VALUE klass, void *ptr)
{
rb_cairo__object_holder_t *holder = ptr;
if (!NIL_P (holder->object))
rb_cairo__gc_guard_remove (klass, holder->object);
xfree (holder);
}
void
rb_cairo__initialize_gc_guard_holder_class (VALUE klass)
{
rb_ivar_set (klass, cr_id_objects, rb_hash_new ());
}
void
rb_cairo__gc_guard_add (VALUE klass, VALUE object)
{
rb_hash_aset (rb_ivar_get (klass, cr_id_objects), object, Qnil);
}
void
rb_cairo__gc_guard_remove (VALUE klass, VALUE object)
{
rb_hash_delete (rb_ivar_get (klass, cr_id_objects), object);
}
VALUE
rb_cairo__gc_guarded_objects (VALUE klass)
{
return rb_funcall (rb_ivar_get (klass, cr_id_objects), cr_id_dup, 0);
}
const char *
rb_cairo__inspect (VALUE object)
{
VALUE inspected;
inspected = rb_funcall (object, cr_id_inspect, 0);
return RSTRING_PTR (inspected);
}
#if CAIRO_CHECK_VERSION(1, 7, 2)
VALUE
rb_cairo__glyphs_to_ruby_object (cairo_glyph_t *glyphs, int num_glyphs)
{
int i;
VALUE rb_glyphs;
rb_glyphs = rb_ary_new2 (num_glyphs);
for (i = 0; i < num_glyphs; i++)
{
RARRAY_PTR (rb_glyphs)[i] = CRGLYPH2RVAL (glyphs + i);
}
return rb_glyphs;
}
void
rb_cairo__glyphs_from_ruby_object (VALUE rb_glyphs,
cairo_glyph_t **glyphs, int *num_glyphs)
{
int i, len;
if (NIL_P (rb_glyphs))
{
*num_glyphs = -1;
return;
}
len = RARRAY_LEN (rb_glyphs);
if (*num_glyphs < len)
*glyphs = cairo_glyph_allocate (len);
*num_glyphs = len;
for (i = 0; i < len; i++)
{
cairo_glyph_t *glyph;
glyph = *glyphs + i;
*glyph = *(RVAL2CRGLYPH (RARRAY_PTR (rb_glyphs)[i]));
}
}
VALUE
rb_cairo__text_clusters_to_ruby_object (cairo_text_cluster_t *clusters,
int num_clusters)
{
int i;
VALUE rb_clusters;
rb_clusters = rb_ary_new2 (num_clusters);
for (i = 0; i < num_clusters; i++)
{
RARRAY_PTR (rb_clusters)[i] = CRTEXTCLUSTER2RVAL (clusters + i);
}
return rb_clusters;
}
void
rb_cairo__text_clusters_from_ruby_object (VALUE rb_clusters,
cairo_text_cluster_t **clusters,
int *num_clusters)
{
int i, len;
if (NIL_P (rb_clusters))
{
*num_clusters = -1;
return;
}
len = RARRAY_LEN (rb_clusters);
if (*num_clusters < len)
*clusters = cairo_text_cluster_allocate (len);
*num_clusters = len;
for (i = 0; i < len; i++)
{
cairo_text_cluster_t *cluster;
cluster = *clusters + i;
*cluster = *(RVAL2CRTEXTCLUSTER (RARRAY_PTR (rb_clusters)[i]));
}
}
#endif
VALUE
rb_cairo__invoke_callback (cr_callback_func_t func, VALUE data)
{
int state = 0;
VALUE result, exception;
result = rb_protect (func, data, &state);
if (state)
{
exception = RB_ERRINFO;
if (exception)
rb_funcall (rb_mCairo, cr_id_exit_application, 2,
exception, INT2NUM (EXIT_FAILURE));
}
return result;
}
void
Init_cairo_private (void)
{
cr_id_normalize_const_name = rb_intern ("normalize_const_name");
cr_id_objects = rb_intern ("objects");
cr_id_dup = rb_intern ("dup");
cr_id_inspect = rb_intern ("inspect");
cr_id_exit_application = rb_intern ("exit_application");
}
cairo-1.12.8/ext/cairo/rb_cairo_font_extents.c 0000644 0000041 0000041 00000012044 12256106703 021354 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-08-17 05:12:37 $
*
* Copyright 2005 Øyvind Kolås
* Copyright 2004-2005 MenTaLguY
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
VALUE rb_cCairo_FontExtents;
#define _SELF(self) (RVAL2CRFONTEXTENTS(self))
cairo_font_extents_t *
rb_cairo_font_extents_from_ruby_object (VALUE obj)
{
cairo_font_extents_t *extents;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_FontExtents))
{
rb_raise (rb_eTypeError, "not a cairo font extents");
}
Data_Get_Struct (obj, cairo_font_extents_t, extents);
return extents;
}
VALUE
rb_cairo_font_extents_to_ruby_object (cairo_font_extents_t *extents)
{
if (extents)
{
cairo_font_extents_t *new_extents = ALLOC (cairo_font_extents_t);
*new_extents = *extents;
return Data_Wrap_Struct (rb_cCairo_FontExtents, NULL, -1, new_extents);
}
else
{
return Qnil;
}
}
static VALUE
cr_font_extents_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, -1, NULL);
}
static VALUE
cr_font_extents_initialize (VALUE self)
{
cairo_font_extents_t *extents;
extents = ALLOC (cairo_font_extents_t);
extents->ascent = 1.0;
extents->descent = 0.0;
extents->height = 1.0;
extents->max_x_advance = 1.0;
extents->max_y_advance = 0.0;
DATA_PTR (self) = extents;
return Qnil;
}
static VALUE
cr_font_extents_ascent (VALUE self)
{
return rb_float_new (_SELF(self)->ascent);
}
static VALUE
cr_font_extents_set_ascent (VALUE self, VALUE ascent)
{
_SELF(self)->ascent = NUM2DBL (ascent);
return self;
}
static VALUE
cr_font_extents_descent (VALUE self)
{
return rb_float_new (_SELF(self)->descent);
}
static VALUE
cr_font_extents_set_descent (VALUE self, VALUE descent)
{
_SELF(self)->descent = NUM2DBL (descent);
return self;
}
static VALUE
cr_font_extents_height (VALUE self)
{
return rb_float_new (_SELF(self)->height);
}
static VALUE
cr_font_extents_set_height (VALUE self, VALUE height)
{
_SELF(self)->height = NUM2DBL (height);
return self;
}
static VALUE
cr_font_extents_max_x_advance (VALUE self)
{
return rb_float_new (_SELF(self)->max_x_advance);
}
static VALUE
cr_font_extents_set_max_x_advance (VALUE self, VALUE max_x_advance)
{
_SELF(self)->max_x_advance = NUM2DBL (max_x_advance);
return self;
}
static VALUE
cr_font_extents_max_y_advance (VALUE self)
{
return rb_float_new (_SELF(self)->max_y_advance);
}
static VALUE
cr_font_extents_set_max_y_advance (VALUE self, VALUE max_y_advance)
{
_SELF(self)->max_y_advance = NUM2DBL (max_y_advance);
return self;
}
static VALUE
cr_font_extents_to_s (VALUE self)
{
VALUE ret;
ret = rb_str_new2 ("#<");
rb_str_cat2 (ret, rb_class2name (CLASS_OF (self)));
rb_str_cat2 (ret, ": ");
rb_str_cat2 (ret, "ascent=");
rb_str_concat (ret, rb_inspect (cr_font_extents_ascent (self)));
rb_str_cat2 (ret, ", ");
rb_str_cat2 (ret, "descent=");
rb_str_concat (ret, rb_inspect (cr_font_extents_descent (self)));
rb_str_cat2 (ret, ", ");
rb_str_cat2 (ret, "height=");
rb_str_concat (ret, rb_inspect (cr_font_extents_height (self)));
rb_str_cat2 (ret, ", ");
rb_str_cat2 (ret, "max_x_advance=");
rb_str_concat (ret, rb_inspect (cr_font_extents_max_x_advance (self)));
rb_str_cat2 (ret, ", ");
rb_str_cat2 (ret, "max_y_advance=");
rb_str_concat (ret, rb_inspect (cr_font_extents_max_y_advance (self)));
rb_str_cat2 (ret, ">");
return ret;
}
void
Init_cairo_font_extents (void)
{
rb_cCairo_FontExtents =
rb_define_class_under (rb_mCairo, "FontExtents", rb_cObject);
rb_define_alloc_func (rb_cCairo_FontExtents, cr_font_extents_allocate);
rb_define_method (rb_cCairo_FontExtents, "initialize",
cr_font_extents_initialize, 0);
rb_define_method (rb_cCairo_FontExtents, "ascent",
cr_font_extents_ascent, 0);
rb_define_method (rb_cCairo_FontExtents, "set_ascent",
cr_font_extents_set_ascent, 1);
rb_define_method (rb_cCairo_FontExtents, "descent",
cr_font_extents_descent, 0);
rb_define_method (rb_cCairo_FontExtents, "set_descent",
cr_font_extents_set_descent, 1);
rb_define_method (rb_cCairo_FontExtents, "height",
cr_font_extents_height, 0);
rb_define_method (rb_cCairo_FontExtents, "set_height",
cr_font_extents_set_height, 1);
rb_define_method (rb_cCairo_FontExtents, "max_x_advance",
cr_font_extents_max_x_advance, 0);
rb_define_method (rb_cCairo_FontExtents, "set_max_x_advance",
cr_font_extents_set_max_x_advance, 1);
rb_define_method (rb_cCairo_FontExtents, "max_y_advance",
cr_font_extents_max_y_advance, 0);
rb_define_method (rb_cCairo_FontExtents, "set_max_y_advance",
cr_font_extents_set_max_y_advance, 1);
rb_define_method (rb_cCairo_FontExtents, "to_s", cr_font_extents_to_s, 0);
RB_CAIRO_DEF_SETTERS (rb_cCairo_FontExtents);
}
cairo-1.12.8/ext/cairo/rb_cairo_region.c 0000644 0000041 0000041 00000030544 12256106703 020124 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* Copyright 2010 Kouhei Sutou
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
VALUE rb_cCairo_Region = Qnil;
#if CAIRO_CHECK_VERSION(1, 10, 0)
#define _SELF (RVAL2CRREGION(self))
static inline void
cr_region_check_status (cairo_region_t *region)
{
rb_cairo_check_status (cairo_region_status (region));
}
cairo_region_t *
rb_cairo_region_from_ruby_object (VALUE obj)
{
cairo_region_t *region;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_Region))
{
rb_raise (rb_eTypeError, "not a cairo region");
}
Data_Get_Struct (obj, cairo_region_t, region);
return region;
}
static void
cr_region_free (void *ptr)
{
if (ptr)
{
cairo_region_destroy ((cairo_region_t *) ptr);
}
}
VALUE
rb_cairo_region_to_ruby_object (cairo_region_t *region)
{
if (region)
{
cairo_region_reference (region);
return Data_Wrap_Struct (rb_cCairo_Region, NULL, cr_region_free, region);
}
else
{
return Qnil;
}
}
static VALUE
cr_region_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, cr_region_free, NULL);
}
static VALUE
cr_region_initialize (int argc, VALUE *argv, VALUE self)
{
cairo_region_t *region;
if (argc == 0)
{
region = cairo_region_create ();
}
else
{
int i;
cairo_rectangle_int_t *rectangles;
rectangles = ALLOCA_N (cairo_rectangle_int_t, argc);
for (i = 0; i < argc; i++)
{
VALUE rb_rectangle;
rb_rectangle = rb_check_array_type (argv[i]);
if (RARRAY_LEN (rb_rectangle) != 4)
rb_raise (rb_eArgError,
"invalid argument (expect "
"() or ([x, y, width, height], ...): %s",
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
rectangles[i].x = NUM2INT (RARRAY_PTR (rb_rectangle)[0]);
rectangles[i].y = NUM2INT (RARRAY_PTR (rb_rectangle)[1]);
rectangles[i].width = NUM2INT (RARRAY_PTR (rb_rectangle)[2]);
rectangles[i].height = NUM2INT (RARRAY_PTR (rb_rectangle)[3]);
}
region = cairo_region_create_rectangles (rectangles, argc);
}
cr_region_check_status (region);
DATA_PTR (self) = region;
return Qnil;
}
static VALUE
cr_region_dup (VALUE self)
{
cairo_region_t *copied_region;
VALUE rb_copied_region;
copied_region = cairo_region_copy (_SELF);
cr_region_check_status (copied_region);
rb_copied_region = CRREGION2RVAL (copied_region);
cairo_region_destroy (copied_region);
return rb_copied_region;
}
static VALUE
cr_region_equal (VALUE self, VALUE other)
{
cairo_region_t *region, *other_region;
if (!rb_cairo__is_kind_of (other, rb_cCairo_Region))
return Qfalse;
region = _SELF;
other_region = RVAL2CRREGION (other);
return CBOOL2RVAL (cairo_region_equal (region, other_region));
}
static VALUE
cr_region_get_extents (VALUE self)
{
cairo_region_t *region;
cairo_rectangle_int_t extents;
region = _SELF;
cairo_region_get_extents (region, &extents);
cr_region_check_status (region);
return rb_ary_new3 (4,
INT2NUM (extents.x), INT2NUM (extents.y),
INT2NUM (extents.width), INT2NUM (extents.height));
}
static VALUE
cr_region_num_rectangles (VALUE self)
{
cairo_region_t *region;
int num_rectangles;
region = _SELF;
num_rectangles = cairo_region_num_rectangles (region);
cr_region_check_status (region);
return INT2NUM (num_rectangles);
}
static VALUE
cr_region_get_rectangle (VALUE self, VALUE index)
{
cairo_region_t *region;
cairo_rectangle_int_t extents;
region = _SELF;
cairo_region_get_rectangle (region, NUM2INT (index), &extents);
cr_region_check_status (region);
return rb_ary_new3 (4,
INT2NUM (extents.x), INT2NUM (extents.y),
INT2NUM (extents.width), INT2NUM (extents.height));
}
static VALUE
cr_region_is_empty (VALUE self)
{
return CBOOL2RVAL (cairo_region_is_empty (_SELF));
}
static VALUE
cr_region_containts_rectangle (int argc, VALUE *argv, VALUE self)
{
cairo_region_t *region;
cairo_rectangle_int_t rectangle;
cairo_region_overlap_t overlap;
VALUE arg1, arg2, arg3, arg4;
const char *error_message =
"invalid argument (expect "
"(x, y, width, height) or ([x, y, width, height])): %s";
rb_scan_args (argc, argv, "13", &arg1, &arg2, &arg3, &arg4);
region = _SELF;
if (argc == 1)
{
VALUE rb_rectangle;
rb_rectangle = rb_check_array_type (arg1);
if (RARRAY_LEN (rb_rectangle) != 4)
rb_raise (rb_eArgError, error_message,
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
rectangle.x = NUM2INT (RARRAY_PTR (rb_rectangle)[0]);
rectangle.y = NUM2INT (RARRAY_PTR (rb_rectangle)[1]);
rectangle.width = NUM2INT (RARRAY_PTR (rb_rectangle)[2]);
rectangle.height = NUM2INT (RARRAY_PTR (rb_rectangle)[3]);
}
else if (argc == 4)
{
rectangle.x = NUM2INT (arg1);
rectangle.y = NUM2INT (arg2);
rectangle.width = NUM2INT (arg3);
rectangle.height = NUM2INT (arg4);
}
else
{
rb_raise (rb_eArgError, error_message,
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
}
overlap = cairo_region_contains_rectangle (region, &rectangle);
cr_region_check_status (region);
return INT2NUM (overlap);
}
static VALUE
cr_region_containts_point (int argc, VALUE *argv, VALUE self)
{
cairo_region_t *region;
int x, y;
VALUE arg1, arg2;
const char *error_message =
"invalid argument (expect "
"(x, y) or ([x, y])): %s";
rb_scan_args (argc, argv, "11", &arg1, &arg2);
region = _SELF;
if (argc == 1)
{
VALUE point;
point = rb_check_array_type (arg1);
if (RARRAY_LEN (point) != 4)
rb_raise (rb_eArgError, error_message,
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
x = NUM2INT (RARRAY_PTR (point)[0]);
y = NUM2INT (RARRAY_PTR (point)[1]);
}
else
{
x = NUM2INT (arg1);
y = NUM2INT (arg2);
}
return CBOOL2RVAL (cairo_region_contains_point (region, x, y));
}
static VALUE
cr_region_translate (int argc, VALUE *argv, VALUE self)
{
cairo_region_t *region;
int x, y;
VALUE arg1, arg2;
const char *error_message =
"invalid argument (expect "
"(x, y) or ([x, y])): %s";
rb_scan_args (argc, argv, "11", &arg1, &arg2);
region = _SELF;
if (argc == 1)
{
VALUE point;
point = rb_check_array_type (arg1);
if (RARRAY_LEN (point) != 4)
rb_raise (rb_eArgError, error_message,
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
x = NUM2INT (RARRAY_PTR (point)[0]);
y = NUM2INT (RARRAY_PTR (point)[1]);
}
else
{
x = NUM2INT (arg1);
y = NUM2INT (arg2);
}
cairo_region_translate (region, x, y);
cr_region_check_status (region);
return Qnil;
}
#define DEFINE_OPERATOR(type) \
static VALUE \
cr_region_ ## type (int argc, VALUE *argv, VALUE self) \
{ \
cairo_status_t status; \
cairo_region_t *region, *other = NULL; \
cairo_rectangle_int_t rectangle; \
VALUE arg1, arg2, arg3, arg4; \
const char *error_message = \
"invalid argument (expect " \
"(region), (x, y, width, height) or ([x, y, width, height])): %s"; \
\
rb_scan_args (argc, argv, "13", &arg1, &arg2, &arg3, &arg4); \
\
region = _SELF; \
if (argc == 1) \
{ \
if (rb_cairo__is_kind_of (arg1, rb_cCairo_Region)) \
{ \
other = RVAL2CRREGION (arg1); \
} \
else \
{ \
VALUE rb_rectangle; \
\
rb_rectangle = rb_check_array_type (arg1); \
if (RARRAY_LEN (rb_rectangle) != 4) \
rb_raise (rb_eArgError, error_message, \
rb_cairo__inspect (rb_ary_new4 (argc, argv))); \
rectangle.x = NUM2INT (RARRAY_PTR (rb_rectangle)[0]); \
rectangle.y = NUM2INT (RARRAY_PTR (rb_rectangle)[1]); \
rectangle.width = NUM2INT (RARRAY_PTR (rb_rectangle)[2]); \
rectangle.height = NUM2INT (RARRAY_PTR (rb_rectangle)[3]); \
} \
} \
else if (argc == 4) \
{ \
rectangle.x = NUM2INT (arg1); \
rectangle.y = NUM2INT (arg2); \
rectangle.width = NUM2INT (arg3); \
rectangle.height = NUM2INT (arg4); \
} \
else \
{ \
rb_raise (rb_eArgError, error_message, \
rb_cairo__inspect (rb_ary_new4 (argc, argv))); \
} \
\
if (other) \
status = cairo_region_ ## type (region, other); \
else \
status = cairo_region_ ## type ## _rectangle (region, &rectangle); \
rb_cairo_check_status (status); \
cr_region_check_status (region); \
return Qnil; \
}
DEFINE_OPERATOR(subtract)
DEFINE_OPERATOR(intersect)
DEFINE_OPERATOR(union)
DEFINE_OPERATOR(xor)
#endif
void
Init_cairo_region (void)
{
#if CAIRO_CHECK_VERSION(1, 10, 0)
rb_cCairo_Region =
rb_define_class_under (rb_mCairo, "Region", rb_cObject);
rb_define_alloc_func (rb_cCairo_Region, cr_region_allocate);
rb_define_method (rb_cCairo_Region, "initialize", cr_region_initialize, -1);
rb_define_method (rb_cCairo_Region, "dup", cr_region_dup, 0);
rb_define_method (rb_cCairo_Region, "==", cr_region_equal, 1);
rb_define_method (rb_cCairo_Region, "extents", cr_region_get_extents, 0);
rb_define_method (rb_cCairo_Region, "num_rectangles",
cr_region_num_rectangles, 0);
rb_define_method (rb_cCairo_Region, "[]",
cr_region_get_rectangle, 1);
rb_define_method (rb_cCairo_Region, "empty?", cr_region_is_empty, 0);
rb_define_method (rb_cCairo_Region, "contains_rectangle",
cr_region_containts_rectangle, -1);
rb_define_method (rb_cCairo_Region, "contains_point?",
cr_region_containts_point, -1);
rb_define_method (rb_cCairo_Region, "translate!", cr_region_translate, -1);
rb_define_method (rb_cCairo_Region, "subtract!", cr_region_subtract, -1);
rb_define_method (rb_cCairo_Region, "intersect!", cr_region_intersect, -1);
rb_define_method (rb_cCairo_Region, "union!", cr_region_union, -1);
rb_define_method (rb_cCairo_Region, "xor!", cr_region_xor, -1);
RB_CAIRO_DEF_SETTERS (rb_cCairo_Region);
#endif
}
cairo-1.12.8/ext/cairo/rb_cairo_surface.c 0000644 0000041 0000041 00000177672 12256106703 020307 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-11-01 14:23:14 $
*
* Copyright 2005-2012 Kouhei Sutou
* Copyright 2005 Øyvind Kolås
* Copyright 2004-2005 MenTaLguY
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
#include "rb_cairo_io.h"
#ifdef HAVE_RUBY_ST_H
# include
#else
# include
#endif
#if CAIRO_CHECK_VERSION(1, 5, 2)
# define RB_CAIRO_HAS_WIN32_PRINTING_SURFACE_TYPE
#endif
#if CAIRO_CHECK_VERSION(1, 5, 12)
# define RB_CAIRO_HAS_QUARTZ_IMAGE_SURFACE_TYPE
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
# define OpenFile OpenFile_win32
# include
# undef OpenFile
# ifdef RB_CAIRO_HAS_WIN32_PRINTING_SURFACE_TYPE
# define RB_CAIRO_HAS_WIN32_PRINTING_SURFACE
# endif
#endif
#ifdef HAVE_RUBY_IO_H
# include
#else
# include
#endif
#ifdef CAIRO_HAS_QUARTZ_SURFACE
# ifndef HAVE_TYPE_ENUM_RUBY_VALUE_TYPE
enum ruby_value_type {
RUBY_T_DATA = T_DATA
};
# endif
# undef T_DATA
# include
# define T_DATA RUBY_T_DATA
# ifdef HAVE_RUBY_COCOA
# define RB_CAIRO_HAS_QUARTZ_SURFACE
# ifdef RB_CAIRO_HAS_QUARTZ_IMAGE_SURFACE_TYPE
# define RB_CAIRO_HAS_QUARTZ_IMAGE_SURFACE
# endif
# endif
#endif
#ifdef CAIRO_HAS_XML_SURFACE
# include
#endif
#ifdef CAIRO_HAS_TEE_SURFACE
# include
#endif
#if defined(CAIRO_HAS_GL_SURFACE) || defined(CAIRO_HAS_GLESV2_SURFACE)
# define RB_CAIRO_HAS_GL_SURFACE
#endif
#ifdef RB_CAIRO_HAS_GL_SURFACE
# include
#endif
VALUE rb_cCairo_Surface;
VALUE rb_cCairo_ImageSurface;
VALUE rb_cCairo_PDFSurface = Qnil;
VALUE rb_cCairo_PSSurface = Qnil;
VALUE rb_cCairo_XLibSurface = Qnil;
VALUE rb_cCairo_XCBSurface = Qnil;
VALUE rb_cCairo_SVGSurface = Qnil;
VALUE rb_cCairo_Win32Surface = Qnil;
VALUE rb_cCairo_Win32PrintingSurface = Qnil;
VALUE rb_cCairo_QuartzSurface = Qnil;
VALUE rb_cCairo_QuartzImageSurface = Qnil;
VALUE rb_cCairo_ScriptSurface = Qnil;
VALUE rb_cCairo_QtSurface = Qnil;
VALUE rb_cCairo_RecordingSurface = Qnil;
VALUE rb_cCairo_VGSurface = Qnil;
VALUE rb_cCairo_GLSurface = Qnil;
VALUE rb_cCairo_GLTextureSurface = Qnil;
VALUE rb_cCairo_DRMSurface = Qnil;
VALUE rb_cCairo_TeeSurface = Qnil;
VALUE rb_cCairo_XMLSurface = Qnil;
VALUE rb_cCairo_SkiaSurface = Qnil;
VALUE rb_cCairo_SubSurface = Qnil;
VALUE rb_cCairo_CoglSurface = Qnil;
static ID cr_id_parse;
static ID cr_id_size;
static ID cr_id_set_unit;
static cairo_user_data_key_t cr_closure_key;
static cairo_user_data_key_t cr_object_holder_key;
static cairo_user_data_key_t cr_finished_key;
#define _SELF (RVAL2CRSURFACE(self))
static VALUE
cr_paper_parse (VALUE paper_description)
{
return rb_funcall (rb_cCairo_Paper, cr_id_parse, 2, paper_description, Qtrue);
}
static void
cr_paper_to_size_in_points (VALUE paper_description, VALUE *width, VALUE *height)
{
VALUE paper, size;
paper = cr_paper_parse (paper_description);
size = rb_funcall (paper, cr_id_size, 1, rb_str_new2 ("pt"));
*width = RARRAY_PTR (size)[0];
*height = RARRAY_PTR (size)[1];
}
static inline void
cr_surface_check_status (cairo_surface_t *surface)
{
rb_cairo_check_status (cairo_surface_status (surface));
}
static VALUE
cr_surface_get_klass (cairo_surface_t *surface)
{
VALUE klass;
cairo_surface_type_t type;
type = cairo_surface_get_type (surface);
switch (type)
{
case CAIRO_SURFACE_TYPE_IMAGE:
klass = rb_cCairo_ImageSurface;
break;
case CAIRO_SURFACE_TYPE_PDF:
klass = rb_cCairo_PDFSurface;
break;
case CAIRO_SURFACE_TYPE_PS:
klass = rb_cCairo_PSSurface;
break;
case CAIRO_SURFACE_TYPE_XLIB:
klass = rb_cCairo_XLibSurface;
break;
case CAIRO_SURFACE_TYPE_XCB:
klass = rb_cCairo_XCBSurface;
break;
case CAIRO_SURFACE_TYPE_QUARTZ:
klass = rb_cCairo_QuartzSurface;
break;
case CAIRO_SURFACE_TYPE_WIN32:
klass = rb_cCairo_Win32Surface;
break;
case CAIRO_SURFACE_TYPE_SVG:
klass = rb_cCairo_SVGSurface;
break;
#ifdef RB_CAIRO_HAS_WIN32_PRINTING_SURFACE_TYPE
case CAIRO_SURFACE_TYPE_WIN32_PRINTING:
klass = rb_cCairo_Win32PrintingSurface;
break;
#endif
#ifdef RB_CAIRO_HAS_QUARTZ_IMAGE_SURFACE_TYPE
case CAIRO_SURFACE_TYPE_QUARTZ_IMAGE:
klass = rb_cCairo_QuartzImageSurface;
break;
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
case CAIRO_SURFACE_TYPE_SCRIPT:
klass = rb_cCairo_ScriptSurface;
break;
case CAIRO_SURFACE_TYPE_QT:
klass = rb_cCairo_QtSurface;
break;
case CAIRO_SURFACE_TYPE_RECORDING:
klass = rb_cCairo_RecordingSurface;
break;
case CAIRO_SURFACE_TYPE_VG:
klass = rb_cCairo_VGSurface;
break;
case CAIRO_SURFACE_TYPE_GL:
klass = rb_cCairo_GLSurface;
break;
case CAIRO_SURFACE_TYPE_DRM:
klass = rb_cCairo_DRMSurface;
break;
case CAIRO_SURFACE_TYPE_TEE:
klass = rb_cCairo_TeeSurface;
break;
case CAIRO_SURFACE_TYPE_XML:
klass = rb_cCairo_XMLSurface;
break;
case CAIRO_SURFACE_TYPE_SKIA:
klass = rb_cCairo_SkiaSurface;
break;
case CAIRO_SURFACE_TYPE_SUBSURFACE:
klass = rb_cCairo_SubSurface;
break;
#endif
#if CAIRO_CHECK_VERSION(1, 11, 4)
case CAIRO_SURFACE_TYPE_COGL:
klass = rb_cCairo_CoglSurface;
break;
#endif
default:
klass = rb_cCairo_Surface;
break;
}
if (NIL_P (klass))
rb_raise (rb_eArgError, "unknown source type: %d", type);
return klass;
}
static VALUE
cr_surface_image_supported_p (VALUE klass)
{
return Qtrue;
}
static VALUE
cr_surface_pdf_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_PDF_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
static VALUE
cr_surface_ps_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_PS_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
static VALUE
cr_surface_quartz_supported_p (VALUE klass)
{
#ifdef RB_CAIRO_HAS_QUARTZ_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
static VALUE
cr_surface_win32_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_WIN32_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
static VALUE
cr_surface_svg_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_SVG_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
static VALUE
cr_surface_win32_printing_supported_p (VALUE klass)
{
#ifdef RB_CAIRO_HAS_WIN32_PRINTING_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
static VALUE
cr_surface_quartz_image_supported_p (VALUE klass)
{
#ifdef RB_CAIRO_HAS_QUARTZ_IMAGE_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
static VALUE
cr_surface_script_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_SCRIPT_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
static VALUE
cr_surface_recording_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_RECORDING_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
static VALUE
cr_surface_gl_supported_p (VALUE klass)
{
#ifdef RB_CAIRO_HAS_GL_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
static VALUE
cr_surface_gl_texture_supported_p (VALUE klass)
{
return cr_surface_gl_supported_p(klass);
}
static VALUE
cr_surface_tee_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_TEE_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
static VALUE
cr_surface_xml_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_XML_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
/* constructor/de-constructor */
cairo_surface_t *
rb_cairo_surface_from_ruby_object (VALUE obj)
{
cairo_surface_t *surface;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_Surface))
{
rb_raise (rb_eTypeError, "not a cairo surface");
}
Data_Get_Struct (obj, cairo_surface_t, surface);
if (!surface)
rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
return surface;
}
static rb_cairo__object_holder_t *
cr_object_holder_new (VALUE object)
{
return rb_cairo__object_holder_new (rb_cCairo_Surface, object);
}
static void
cr_object_holder_free (void *ptr)
{
rb_cairo__object_holder_free (rb_cCairo_Surface, ptr);
}
static void
cr_surface_free (void *ptr)
{
cairo_surface_t *surface = ptr;
if (surface)
cairo_surface_destroy (surface);
}
VALUE
rb_cairo_surface_to_ruby_object (cairo_surface_t *surface)
{
if (surface)
{
VALUE klass;
klass = cr_surface_get_klass (surface);
cairo_surface_reference (surface);
return Data_Wrap_Struct (klass, NULL, cr_surface_free, surface);
}
else
{
return Qnil;
}
}
VALUE
rb_cairo_surface_to_ruby_object_with_destroy (cairo_surface_t *surface)
{
VALUE rb_surface;
rb_surface = rb_cairo_surface_to_ruby_object (surface);
if (surface)
cairo_surface_destroy (surface);
return rb_surface;
}
static VALUE
cr_surface_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, cr_surface_free, NULL);
}
static VALUE
cr_surface_initialize (int argc, VALUE *argv, VALUE self)
{
rb_raise(rb_eNotImpError,
"%s class creation isn't supported on this cairo installation",
rb_obj_classname(self));
return Qnil;
}
/* Surface manipulation */
static VALUE
cr_surface_destroy (VALUE self)
{
cairo_surface_t *surface;
surface = _SELF;
cairo_surface_destroy (surface);
DATA_PTR (self) = NULL;
return self;
}
static VALUE
cr_surface_finish (VALUE self)
{
cairo_surface_t *surface;
rb_cairo__io_callback_closure_t *closure;
surface = _SELF;
closure = cairo_surface_get_user_data (surface, &cr_closure_key);
cairo_surface_finish (surface);
cairo_surface_set_user_data (surface, &cr_finished_key, (void *)CR_TRUE, NULL);
cairo_surface_set_user_data (surface, &cr_object_holder_key, NULL, NULL);
if (closure && !NIL_P (closure->error))
rb_exc_raise (closure->error);
cr_surface_check_status (surface);
return self;
}
static void
yield_and_finish (VALUE self)
{
cairo_surface_t *surface;
rb_yield (self);
surface = _SELF;
if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
return;
if (cairo_surface_get_user_data (surface, &cr_finished_key))
return;
cr_surface_finish (self);
}
static VALUE
cr_surface_create_similar (int argc, VALUE *argv, VALUE self)
{
cairo_surface_t *surface, *similar_surface;
cairo_content_t content;
int width, height;
VALUE arg1, arg2, arg3;
rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3);
surface = _SELF;
if (argc == 2)
{
content = cairo_surface_get_content (surface);
width = NUM2INT (arg1);
height = NUM2INT (arg2);
}
else
{
content = RVAL2CRCONTENT (arg1);
width = NUM2INT (arg2);
height = NUM2INT (arg3);
}
similar_surface = cairo_surface_create_similar (surface, content,
width, height);
cr_surface_check_status (similar_surface);
return CRSURFACE2RVAL_WITH_DESTROY (similar_surface);
}
#if CAIRO_CHECK_VERSION(1, 11, 4)
static VALUE
cr_surface_create_similar_image (int argc, VALUE *argv, VALUE self)
{
cairo_surface_t *surface, *similar_image;
cairo_format_t format;
int width, height;
VALUE arg1, arg2, arg3;
rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3);
surface = _SELF;
if (argc == 2)
{
if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE)
{
format = cairo_image_surface_get_format (surface);
}
else
{
format = CAIRO_FORMAT_ARGB32;
}
width = NUM2INT (arg1);
height = NUM2INT (arg2);
}
else
{
format = RVAL2CRFORMAT (arg1);
width = NUM2INT (arg2);
height = NUM2INT (arg3);
}
similar_image = cairo_surface_create_similar_image (surface, format,
width, height);
cr_surface_check_status (similar_image);
return CRSURFACE2RVAL_WITH_DESTROY (similar_image);
}
static VALUE
cr_surface_map_to_image (int argc, VALUE *argv, VALUE self)
{
cairo_surface_t *surface, *mapped_image;
cairo_rectangle_int_t extents_value;
cairo_rectangle_int_t *extents = NULL;
VALUE rb_extents;
rb_scan_args (argc, argv, "01", &rb_extents);
surface = _SELF;
if (!NIL_P (rb_extents))
{
extents = &extents_value;
if (rb_cairo__is_kind_of (rb_extents, rb_cCairo_Rectangle))
{
extents->x = NUM2INT (rb_iv_get (rb_extents, "@x"));
extents->y = NUM2INT (rb_iv_get (rb_extents, "@y"));
extents->width = NUM2INT (rb_iv_get (rb_extents, "@width"));
extents->height = NUM2INT (rb_iv_get (rb_extents, "@height"));
}
else
{
VALUE *values;
rb_extents = rb_convert_type (rb_extents, T_ARRAY, "Array", "to_ary");
values = RARRAY_PTR (rb_extents);
extents->x = NUM2INT (values[0]);
extents->y = NUM2INT (values[1]);
extents->height = NUM2INT (values[2]);
extents->width = NUM2INT (values[3]);
}
}
mapped_image = cairo_surface_map_to_image (surface, extents);
cr_surface_check_status (mapped_image);
return CRSURFACE2RVAL_WITH_DESTROY (mapped_image);
}
static VALUE
cr_surface_unmap_image (VALUE self, VALUE rb_mapped_image)
{
cairo_surface_t *surface, *mapped_image;
surface = _SELF;
mapped_image = RVAL2CRSURFACE (rb_mapped_image);
cairo_surface_unmap_image (surface, mapped_image);
return Qnil;
}
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
static VALUE
cr_surface_destroy_with_destroy_check (VALUE self)
{
if (DATA_PTR (self))
cr_surface_destroy (self);
return Qnil;
}
static VALUE
cr_surface_create_sub_rectangle_surface (VALUE self, VALUE x, VALUE y,
VALUE width, VALUE height)
{
VALUE rb_surface;
cairo_surface_t *surface;
surface = cairo_surface_create_for_rectangle (RVAL2CRSURFACE (self),
NUM2DBL (x),
NUM2DBL (y),
NUM2DBL (width),
NUM2INT (height));
cr_surface_check_status (surface);
rb_surface = CRSURFACE2RVAL_WITH_DESTROY (surface);
if (rb_block_given_p ())
return rb_ensure (rb_yield, rb_surface,
cr_surface_destroy_with_destroy_check, rb_surface);
else
return rb_surface;
}
static VALUE
cr_surface_get_device (VALUE self)
{
return CRDEVICE2RVAL (cairo_surface_get_device (_SELF));
}
#endif
static VALUE
cr_surface_get_content (VALUE self)
{
return INT2NUM (cairo_surface_get_content (_SELF));
}
#ifdef CAIRO_HAS_PNG_FUNCTIONS
static VALUE
cr_surface_write_to_png_stream (VALUE self, VALUE target)
{
cairo_status_t status;
rb_cairo__io_callback_closure_t closure;
closure.target = target;
closure.error = Qnil;
status = cairo_surface_write_to_png_stream (_SELF,
rb_cairo__io_write_func,
(void *)&closure);
if (!NIL_P (closure.error))
rb_exc_raise (closure.error);
rb_cairo_check_status (status);
return self;
}
static VALUE
cr_surface_write_to_png (VALUE self, VALUE filename)
{
cairo_status_t status;
status = cairo_surface_write_to_png (_SELF, StringValueCStr (filename));
rb_cairo_check_status (status);
return self;
}
static VALUE
cr_surface_write_to_png_generic (VALUE self, VALUE target)
{
if (rb_respond_to (target, rb_cairo__io_id_write))
return cr_surface_write_to_png_stream (self, target);
else
return cr_surface_write_to_png (self, target);
}
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
static VALUE
cr_surface_get_mime_data (VALUE self, VALUE mime_type)
{
cairo_surface_t *surface;
const unsigned char *data;
unsigned long length;
surface = _SELF;
cairo_surface_get_mime_data (surface, StringValueCStr (mime_type),
&data, &length);
if (data)
return rb_str_new ((const char *)data, length);
else
return Qnil;
}
static VALUE
cr_surface_set_mime_data (VALUE self, VALUE rb_mime_type, VALUE rb_data)
{
cairo_status_t status;
cairo_surface_t *surface;
const char *mime_type;
surface = _SELF;
mime_type = StringValueCStr (rb_mime_type);
if (NIL_P (rb_data))
{
status = cairo_surface_set_mime_data (surface, mime_type,
NULL, 0, NULL, NULL);
}
else
{
const char *raw_data;
unsigned char *data;
unsigned long length;
raw_data = StringValuePtr (rb_data);
length = RSTRING_LEN (rb_data);
data = xmalloc (length);
memcpy (data, raw_data, length);
status = cairo_surface_set_mime_data (surface, mime_type,
data, length,
xfree, data);
}
rb_cairo_check_status (status);
return Qnil;
}
#endif
#if CAIRO_CHECK_VERSION(1, 11, 4)
static VALUE
cr_surface_supported_mime_type_p (VALUE self, VALUE rb_mime_type)
{
cairo_surface_t *surface;
const char *mime_type;
cairo_bool_t supported_p;
surface = _SELF;
mime_type = StringValueCStr (rb_mime_type);
supported_p = cairo_surface_supports_mime_type (surface, mime_type);
return CBOOL2RVAL (supported_p);
}
#endif
static VALUE
cr_surface_get_font_options (VALUE self)
{
cairo_font_options_t *options = cairo_font_options_create();
cairo_surface_get_font_options (_SELF, options);
cr_surface_check_status (_SELF);
rb_cairo_check_status (cairo_font_options_status (options));
return CRFONTOPTIONS2RVAL (options);
}
static VALUE
cr_surface_flush (VALUE self)
{
cairo_surface_flush (_SELF);
cr_surface_check_status (_SELF);
return self;
}
static VALUE
cr_surface_mark_dirty (int argc, VALUE *argv, VALUE self)
{
VALUE x, y, width, height;
int n;
n = rb_scan_args (argc, argv, "04", &x, &y, &width, &height);
if (n == 0)
{
cairo_surface_mark_dirty (_SELF);
}
else if (n == 4)
{
cairo_surface_mark_dirty_rectangle (_SELF,
NUM2INT (x), NUM2INT (y),
NUM2INT (width), NUM2INT (height));
}
else
{
int i;
VALUE args;
args = rb_ary_new2 (n);
for (i = 0; i < n; i++)
{
rb_ary_push (args, argv[i]);
}
rb_raise (rb_eArgError,
"invalid argument (expect () or (x, y, width, height)): %s",
rb_cairo__inspect (args));
}
cr_surface_check_status (_SELF);
return self;
}
static VALUE
cr_surface_set_device_offset (VALUE self, VALUE x_offset, VALUE y_offset)
{
cairo_surface_set_device_offset (_SELF,
NUM2DBL (x_offset),
NUM2DBL (y_offset));
cr_surface_check_status (_SELF);
return self;
}
static VALUE
cr_surface_get_device_offset (VALUE self)
{
double x_offset, y_offset;
cairo_surface_get_device_offset (_SELF, &x_offset, &y_offset);
cr_surface_check_status (_SELF);
return rb_ary_new3 (2, rb_float_new (x_offset), rb_float_new (y_offset));
}
static VALUE
cr_surface_set_fallback_resolution (VALUE self,
VALUE x_pixels_per_inch,
VALUE y_pixels_per_inch)
{
cairo_surface_set_fallback_resolution (_SELF,
NUM2DBL (x_pixels_per_inch),
NUM2DBL (y_pixels_per_inch));
cr_surface_check_status (_SELF);
return self;
}
#if CAIRO_CHECK_VERSION(1, 7, 2)
static VALUE
cr_surface_get_fallback_resolution (VALUE self)
{
double x_pixels_per_inch, y_pixels_per_inch;
cairo_surface_get_fallback_resolution (_SELF,
&x_pixels_per_inch,
&y_pixels_per_inch);
cr_surface_check_status (_SELF);
return rb_ary_new3 (2,
rb_float_new (x_pixels_per_inch),
rb_float_new (y_pixels_per_inch));
}
#endif
#if CAIRO_CHECK_VERSION(1, 5, 2)
static VALUE
cr_surface_copy_page (VALUE self)
{
cairo_surface_copy_page (_SELF);
cr_surface_check_status (_SELF);
return self;
}
static VALUE
cr_surface_show_page (VALUE self)
{
cairo_surface_show_page (_SELF);
cr_surface_check_status (_SELF);
return self;
}
#endif
/* image surface functions */
#ifdef CAIRO_HAS_PNG_FUNCTIONS
static cairo_surface_t *
cr_image_surface_create_from_png_stream (VALUE target)
{
rb_cairo__io_callback_closure_t closure;
cairo_surface_t *surface;
closure.target = target;
closure.error = Qnil;
surface = cairo_image_surface_create_from_png_stream (rb_cairo__io_read_func,
(void *)&closure);
if (!NIL_P (closure.error))
rb_exc_raise (closure.error);
return surface;
}
static cairo_surface_t *
cr_image_surface_create_from_png (VALUE filename)
{
return cairo_image_surface_create_from_png (StringValueCStr (filename));
}
static VALUE
cr_image_surface_create_from_png_generic (VALUE klass, VALUE target)
{
VALUE rb_surface;
cairo_surface_t *surface;
if (rb_respond_to (target, rb_cairo__io_id_read))
surface = cr_image_surface_create_from_png_stream (target);
else
surface = cr_image_surface_create_from_png (target);
cr_surface_check_status (surface);
rb_surface = cr_surface_allocate (klass);
DATA_PTR (rb_surface) = surface;
return rb_surface;
}
#endif
static cairo_surface_t *
cr_image_surface_create (VALUE self, VALUE format, VALUE width, VALUE height)
{
cairo_format_t cr_format;
cr_format = NIL_P (format) ? CAIRO_FORMAT_ARGB32 : RVAL2CRFORMAT (format);
return cairo_image_surface_create (cr_format,
NUM2INT (width),
NUM2INT (height));
}
static cairo_surface_t *
cr_image_surface_create_for_data (VALUE self, VALUE rb_data, VALUE format,
VALUE width, VALUE height, VALUE stride)
{
unsigned char *data;
rb_data = StringValue (rb_data);
rb_str_modify (rb_data);
data = (unsigned char *)StringValuePtr (rb_data);
return cairo_image_surface_create_for_data (data,
RVAL2CRFORMAT (format),
NUM2INT (width),
NUM2INT (height),
NUM2INT (stride));
}
static VALUE
cr_image_surface_initialize (int argc, VALUE *argv, VALUE self)
{
cairo_surface_t *surface;
VALUE arg1, arg2, arg3, arg4, arg5;
int n;
n = rb_scan_args (argc, argv, "23", &arg1, &arg2, &arg3, &arg4, &arg5);
if (n == 2)
surface = cr_image_surface_create (self, Qnil, arg1, arg2);
else if (n == 3)
surface = cr_image_surface_create (self, arg1, arg2, arg3);
else if (n == 5)
surface =
cr_image_surface_create_for_data (self, arg1, arg2, arg3, arg4, arg5);
else
rb_raise (rb_eArgError,
"invalid argument (expect "
"(width, height) or "
"(format, width, height) or "
"(data, format, width, height, stride)): %s",
rb_cairo__inspect (rb_ary_new3 (4, arg1, arg2, arg3, arg4)));
cr_surface_check_status (surface);
DATA_PTR (self) = surface;
if (rb_block_given_p ())
yield_and_finish (self);
return Qnil;
}
static VALUE
cr_image_surface_get_data (VALUE self)
{
unsigned char *data;
cairo_surface_t *surface;
surface = _SELF;
data = cairo_image_surface_get_data (surface);
if (data)
return rb_str_new ((const char *)data,
cairo_image_surface_get_stride (surface) *
cairo_image_surface_get_height (surface));
else
return Qnil;
}
static VALUE
cr_image_surface_get_format (VALUE self)
{
return INT2NUM (cairo_image_surface_get_format (_SELF));
}
static VALUE
cr_image_surface_get_width (VALUE self)
{
return INT2NUM (cairo_image_surface_get_width (_SELF));
}
static VALUE
cr_image_surface_get_height (VALUE self)
{
return INT2NUM (cairo_image_surface_get_height (_SELF));
}
static VALUE
cr_image_surface_get_stride (VALUE self)
{
return INT2NUM (cairo_image_surface_get_stride (_SELF));
}
/* printing surfaces */
#define DEFINE_SURFACE(type) \
static VALUE \
cr_ ## type ## _surface_initialize (int argc, VALUE *argv, VALUE self) \
{ \
VALUE target, rb_width_in_points, rb_height_in_points; \
VALUE arg2, arg3; \
cairo_surface_t *surface; \
double width_in_points, height_in_points; \
\
rb_scan_args (argc, argv, "21", &target, &arg2, &arg3); \
if (argc == 2) \
{ \
VALUE paper; \
\
paper = arg2; \
cr_paper_to_size_in_points (paper, \
&rb_width_in_points, \
&rb_height_in_points); \
} \
else \
{ \
rb_width_in_points = arg2; \
rb_height_in_points = arg3; \
} \
\
width_in_points = NUM2DBL (rb_width_in_points); \
height_in_points = NUM2DBL (rb_height_in_points); \
\
if (rb_respond_to (target, rb_cairo__io_id_write)) \
{ \
rb_cairo__io_callback_closure_t *closure; \
\
closure = rb_cairo__io_closure_new (target); \
surface = \
cairo_ ## type ## _surface_create_for_stream ( \
rb_cairo__io_write_func, \
(void *) closure, \
width_in_points, \
height_in_points); \
\
if (cairo_surface_status (surface)) \
{ \
rb_cairo__io_closure_destroy (closure); \
} \
else \
{ \
rb_ivar_set (self, rb_cairo__io_id_output, target); \
cairo_surface_set_user_data (surface, &cr_closure_key, \
closure, \
rb_cairo__io_closure_free); \
cairo_surface_set_user_data (surface, &cr_object_holder_key, \
cr_object_holder_new (self), \
cr_object_holder_free); \
} \
} \
else \
{ \
surface = \
cairo_ ## type ## _surface_create (StringValueCStr (target), \
width_in_points, \
height_in_points); \
} \
\
cr_surface_check_status (surface); \
DATA_PTR (self) = surface; \
if (rb_block_given_p ()) \
yield_and_finish (self); \
return Qnil; \
}
#define DEFINE_SURFACE_SET_SIZE(type) \
static VALUE \
cr_ ## type ## _surface_set_size (int argc, VALUE *argv, VALUE self) \
{ \
VALUE arg1, arg2; \
VALUE width_in_points, height_in_points; \
\
rb_scan_args(argc, argv, "11", &arg1, &arg2); \
if (argc == 1) \
{ \
VALUE paper; \
\
paper = arg1; \
cr_paper_to_size_in_points (paper, \
&width_in_points, \
&height_in_points); \
} \
else \
{ \
width_in_points = arg1; \
height_in_points = arg2; \
} \
\
cairo_ ## type ## _surface_set_size (_SELF, \
NUM2DBL (width_in_points), \
NUM2DBL (height_in_points)); \
cr_surface_check_status (_SELF); \
return Qnil; \
}
#ifdef CAIRO_HAS_PDF_SURFACE
/* PDF-surface functions */
DEFINE_SURFACE(pdf)
DEFINE_SURFACE_SET_SIZE(pdf)
# if CAIRO_CHECK_VERSION(1, 10, 0)
static VALUE
cr_pdf_surface_restrict_to_version (VALUE self, VALUE version)
{
cairo_pdf_surface_restrict_to_version (_SELF, RVAL2CRPDFVERSION (version));
cr_surface_check_status (_SELF);
return Qnil;
}
# endif
#endif
#ifdef CAIRO_HAS_PS_SURFACE
/* PS-surface functions */
DEFINE_SURFACE(ps)
DEFINE_SURFACE_SET_SIZE(ps)
static VALUE
cr_ps_surface_dsc_comment (VALUE self, VALUE comment)
{
cairo_ps_surface_dsc_comment (_SELF, StringValueCStr (comment));
cr_surface_check_status (_SELF);
return Qnil;
}
static VALUE
cr_ps_surface_dsc_begin_setup (VALUE self)
{
cairo_ps_surface_dsc_begin_setup (_SELF);
cr_surface_check_status (_SELF);
if (rb_block_given_p ())
return rb_yield (self);
else
return Qnil;
}
static VALUE
cr_ps_surface_dsc_begin_page_setup (VALUE self)
{
cairo_ps_surface_dsc_begin_page_setup (_SELF);
cr_surface_check_status (_SELF);
if (rb_block_given_p ())
return rb_yield (self);
else
return Qnil;
}
# if CAIRO_CHECK_VERSION(1, 5, 2)
static VALUE
cr_ps_surface_restrict_to_level (VALUE self, VALUE level)
{
cairo_ps_surface_restrict_to_level (_SELF, RVAL2CRPSLEVEL (level));
cr_surface_check_status (_SELF);
return Qnil;
}
static VALUE
cr_ps_surface_get_eps (VALUE self)
{
return cairo_ps_surface_get_eps (_SELF) ? Qtrue : Qfalse;
}
static VALUE
cr_ps_surface_set_eps (VALUE self, VALUE eps)
{
cairo_ps_surface_set_eps (_SELF, RTEST (eps));
cr_surface_check_status (_SELF);
return Qnil;
}
# endif
#endif
#ifdef RB_CAIRO_HAS_QUARTZ_SURFACE
/* Quartz-surface functions */
#include
BOOL rbobj_to_nsobj (VALUE obj, id* nsobj);
VALUE ocid_to_rbobj (VALUE context_obj, id ocid);
static VALUE
cr_quartz_surface_initialize (int argc, VALUE *argv, VALUE self)
{
id objc_object = nil;
CGContextRef context;
unsigned int width, height;
cairo_surface_t *surface = NULL;
cairo_format_t format = CAIRO_FORMAT_ARGB32;
VALUE arg1, arg2, arg3, rb_width, rb_height;
static VALUE rb_cOSXCGContextRef = Qnil;
rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3);
if (argc == 2)
{
rb_width = arg1;
rb_height = arg2;
}
else
{
switch (TYPE (arg1))
{
case T_NIL:
break;
case T_STRING:
case T_SYMBOL:
case T_FIXNUM:
format = RVAL2CRFORMAT (arg1);
break;
default:
if (NIL_P (rb_cOSXCGContextRef))
rb_cOSXCGContextRef =
rb_const_get (rb_const_get (rb_cObject, rb_intern ("OSX")),
rb_intern ("CGContextRef"));
if (RTEST (rb_obj_is_kind_of (arg1, rb_cOSXCGContextRef)))
rbobj_to_nsobj (arg1, &objc_object);
else
rb_raise (rb_eArgError,
"invalid argument (expect "
"(width, height), "
"(format, width, height) or "
"(cg_context, width, height)): %s",
rb_cairo__inspect (rb_ary_new3 (3, arg1, arg2, arg3)));
break;
}
rb_width = arg2;
rb_height = arg3;
}
width = NUM2UINT (rb_width);
height = NUM2UINT (rb_height);
if (objc_object == nil)
{
surface = cairo_quartz_surface_create (format, width, height);
}
else
{
context = (CGContextRef)objc_object;
surface =
cairo_quartz_surface_create_for_cg_context (context, width, height);
}
cr_surface_check_status (surface);
DATA_PTR (self) = surface;
if (rb_block_given_p ())
yield_and_finish (self);
return Qnil;
}
static VALUE
cr_quartz_surface_get_cg_context (VALUE self)
{
CGContextRef context;
id objc_object;
context = cairo_quartz_surface_get_cg_context (_SELF);
objc_object = (id)context;
return ocid_to_rbobj (Qnil, objc_object);
}
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
/* Win32 surface functions */
/* from dl/dl.h (ruby 1.9) */
# if SIZEOF_LONG == SIZEOF_VOIDP
# define PTR2NUM(x) (ULONG2NUM((unsigned long)(x)))
# define NUM2PTR(x) ((void *)(NUM2ULONG(x)))
# else
# define PTR2NUM(x) (ULL2NUM((unsigned long long)(x)))
# define NUM2PTR(x) ((void *)(NUM2ULL(x)))
# endif
static VALUE
cr_win32_surface_initialize (int argc, VALUE *argv, VALUE self)
{
cairo_surface_t *surface = NULL;
VALUE arg1, arg2, arg3, arg4;
VALUE hdc, format, width, height;
rb_scan_args (argc, argv, "13", &arg1, &arg2, &arg3, &arg4);
switch (argc)
{
case 1:
hdc = arg1;
surface = cairo_win32_surface_create (NUM2PTR (hdc));
break;
case 2:
width = arg1;
height = arg2;
surface = cairo_win32_surface_create_with_dib (CAIRO_FORMAT_ARGB32,
NUM2INT (width),
NUM2INT (height));
break;
case 3:
if (NIL_P (arg1) ||
(rb_cairo__is_kind_of (arg1, rb_cNumeric) &&
NUM2INT (arg1) != CAIRO_FORMAT_RGB24))
{
# if CAIRO_CHECK_VERSION(1, 4, 0)
HDC win32_hdc;
hdc = arg1;
width = arg2;
height = arg3;
win32_hdc = NIL_P (hdc) ? NULL : NUM2PTR (hdc);
surface = cairo_win32_surface_create_with_ddb (win32_hdc,
CAIRO_FORMAT_RGB24,
NUM2INT (width),
NUM2INT (height));
# else
rb_raise (rb_eArgError,
"Cairo::Win32Surface.new(hdc, width, height) "
"is available since cairo >= 1.4.0");
# endif
}
else
{
format = arg1;
width = arg2;
height = arg3;
surface = cairo_win32_surface_create_with_dib (RVAL2CRFORMAT (format),
NUM2INT (width),
NUM2INT (height));
}
break;
case 4:
{
# if CAIRO_CHECK_VERSION(1, 4, 0)
HDC win32_hdc;
hdc = arg1;
format = arg2;
width = arg3;
height = arg4;
win32_hdc = NIL_P (hdc) ? NULL : (HDC) NUM2UINT (hdc);
surface = cairo_win32_surface_create_with_ddb (win32_hdc,
RVAL2CRFORMAT (format),
NUM2INT (width),
NUM2INT (height));
# else
rb_raise (rb_eArgError,
"Cairo::Win32Surface.new(hdc, format, width, height) "
"is available since cairo >= 1.4.0");
# endif
}
break;
}
if (!surface)
rb_cairo_check_status (CAIRO_STATUS_INVALID_FORMAT);
cr_surface_check_status (surface);
DATA_PTR (self) = surface;
if (rb_block_given_p ())
yield_and_finish (self);
return Qnil;
}
static VALUE
cr_win32_surface_get_hdc (VALUE self)
{
HDC hdc;
hdc = cairo_win32_surface_get_dc (_SELF);
if (!hdc)
return Qnil;
else
return PTR2NUM (hdc);
}
# if CAIRO_CHECK_VERSION(1, 4, 0)
static VALUE
cr_win32_surface_get_image (VALUE self)
{
cairo_surface_t *surface;
surface = cairo_win32_surface_get_image (_SELF);
if (!surface)
return Qnil;
cr_surface_check_status (surface);
return CRSURFACE2RVAL (surface);
}
# endif
#endif
#ifdef CAIRO_HAS_SVG_SURFACE
/* SVG-surface functions */
DEFINE_SURFACE(svg)
static VALUE
cr_svg_surface_restrict_to_version (VALUE self, VALUE version)
{
cairo_svg_surface_restrict_to_version (_SELF, RVAL2CRSVGVERSION (version));
cr_surface_check_status (_SELF);
return Qnil;
}
#endif
#ifdef RB_CAIRO_HAS_WIN32_PRINTING_SURFACE
/* Win32 printing surface functions */
static VALUE
cr_win32_printing_surface_initialize (VALUE self, VALUE hdc)
{
cairo_surface_t *surface = NULL;
surface = cairo_win32_printing_surface_create (NUM2PTR (hdc));
cr_surface_check_status (surface);
DATA_PTR (self) = surface;
if (rb_block_given_p ())
yield_and_finish (self);
return Qnil;
}
#endif
#ifdef RB_CAIRO_HAS_QUARTZ_IMAGE_SURFACE
/* Quartz image surface functions */
static VALUE
cr_quartz_image_surface_initialize (VALUE self, VALUE image_surface)
{
cairo_surface_t *surface;
surface = cairo_quartz_image_surface_create (RVAL2CRSURFACE (image_surface));
cr_surface_check_status (surface);
DATA_PTR (self) = surface;
if (rb_block_given_p ())
yield_and_finish (self);
return Qnil;
}
static VALUE
cr_quartz_image_surface_get_image (VALUE self)
{
cairo_surface_t *surface;
surface = cairo_quartz_image_surface_get_image (_SELF);
if (!surface)
return Qnil;
cr_surface_check_status (surface);
return CRSURFACE2RVAL (surface);
}
#endif
#ifdef CAIRO_HAS_SCRIPT_SURFACE
/* script surface functions */
static VALUE
cr_script_surface_initialize (int argc, VALUE *argv, VALUE self)
{
cairo_surface_t *surface = NULL, *target = NULL;
cairo_device_t *device;
double width = 0.0, height = 0.0;
cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA;
VALUE arg1, arg2, arg3, arg4;
rb_scan_args (argc, argv, "22", &arg1, &arg2, &arg3, &arg4);
device = RVAL2CRDEVICE (arg1);
if (argc == 2)
{
target = RVAL2CRSURFACE (arg2);
}
else
{
width = NUM2DBL (arg2);
height = NUM2DBL (arg3);
switch (TYPE (arg4))
{
case T_NIL:
break;
case T_STRING:
case T_SYMBOL:
case T_FIXNUM:
content = RVAL2CRCONTENT (arg4);
break;
default:
rb_raise (rb_eArgError,
"invalid argument (expect "
"(device, width, height), "
"(device, width, height, content) or "
"(device, surface)): %s",
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
break;
}
}
if (target)
surface = cairo_script_surface_create_for_target (device, target);
else
surface = cairo_script_surface_create (device, content, width, height);
cr_surface_check_status (surface);
DATA_PTR (self) = surface;
if (rb_block_given_p ())
yield_and_finish (self);
return Qnil;
}
#endif
#ifdef CAIRO_HAS_RECORDING_SURFACE
/* recording surface functions */
static VALUE
cr_recording_surface_initialize (int argc, VALUE *argv, VALUE self)
{
VALUE arg1, arg2, arg3, arg4, arg5;
cairo_surface_t *surface;
cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA;
cairo_rectangle_t extents;
const char *error_message =
"invalid argument (expect "
"(x, y, width, height), "
"([x, y, width, height]),"
"(x, y, width, height, content) or "
"([x, y, width, height], content)): %s";
rb_scan_args (argc, argv, "14", &arg1, &arg2, &arg3, &arg4, &arg5);
if (argc == 1 || argc == 2)
{
VALUE rb_extents;
rb_extents = rb_check_array_type (arg1);
if (RARRAY_LEN (rb_extents) != 4)
rb_raise (rb_eArgError, error_message, rb_cairo__inspect (arg1));
extents.x = NUM2DBL (RARRAY_PTR (rb_extents)[0]);
extents.y = NUM2DBL (RARRAY_PTR (rb_extents)[1]);
extents.width = NUM2DBL (RARRAY_PTR (rb_extents)[2]);
extents.height = NUM2DBL (RARRAY_PTR (rb_extents)[3]);
if (!NIL_P (arg2))
content = RVAL2CRCONTENT (arg2);
}
else if (argc == 4 || argc == 5)
{
extents.x = NUM2DBL (arg1);
extents.y = NUM2DBL (arg2);
extents.width = NUM2DBL (arg3);
extents.height = NUM2DBL (arg4);
if (!NIL_P (arg5))
content = RVAL2CRCONTENT (arg5);
}
else
{
rb_raise (rb_eArgError, error_message,
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
}
surface = cairo_recording_surface_create (content, &extents);
cr_surface_check_status (surface);
DATA_PTR (self) = surface;
if (rb_block_given_p ())
yield_and_finish (self);
return Qnil;
}
static VALUE
cr_recording_surface_get_ink_extents (VALUE self)
{
cairo_surface_t *surface;
double x, y, width, height;
surface = _SELF;
cairo_recording_surface_ink_extents (surface, &x, &y, &width, &height);
cr_surface_check_status (surface);
return rb_ary_new3 (4,
rb_float_new (x), rb_float_new (y),
rb_float_new (width), rb_float_new (height));
}
# if CAIRO_CHECK_VERSION(1, 11, 4)
static VALUE
cr_recording_surface_get_extents (VALUE self)
{
cairo_surface_t *surface;
cairo_rectangle_t extents;
surface = _SELF;
cairo_recording_surface_get_extents (surface, &extents);
cr_surface_check_status (surface);
return rb_ary_new3 (4,
rb_float_new (extents.x),
rb_float_new (extents.y),
rb_float_new (extents.width),
rb_float_new (extents.height));
}
# endif
#endif
#ifdef RB_CAIRO_HAS_GL_SURFACE
/* GL surface functions */
static VALUE
cr_gl_surface_initialize (int argc, VALUE *argv, VALUE self)
{
cairo_surface_t *surface;
cairo_device_t *device;
int width, height;
cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA;
VALUE rb_device, rb_width, rb_height, rb_content;
rb_scan_args (argc, argv, "31",
&rb_device, &rb_width, &rb_height, &rb_content);
device = RVAL2CRDEVICE (rb_device);
width = NUM2INT (rb_width);
height = NUM2INT (rb_height);
switch (TYPE (rb_content))
{
case T_NIL:
break;
case T_STRING:
case T_SYMBOL:
case T_FIXNUM:
content = RVAL2CRCONTENT (rb_content);
break;
default:
rb_raise (rb_eArgError,
"invalid argument (expect "
"(device, width, height) or "
"(device, width, height, content)): %s",
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
break;
}
surface = cairo_gl_surface_create (device, content, width, height);
cr_surface_check_status (surface);
DATA_PTR (self) = surface;
if (rb_block_given_p ())
yield_and_finish (self);
return Qnil;
}
static VALUE
cr_gl_texture_surface_initialize (int argc, VALUE *argv, VALUE self)
{
cairo_surface_t *surface;
cairo_device_t *device;
unsigned int texture;
int width, height;
cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA;
VALUE rb_device, rb_texture, rb_width, rb_height, rb_content;
rb_scan_args (argc, argv, "41",
&rb_device, &rb_texture, &rb_width, &rb_height, &rb_content);
device = RVAL2CRDEVICE (rb_device);
texture = NUM2UINT (rb_texture);
width = NUM2INT (rb_width);
height = NUM2INT (rb_height);
switch (TYPE (rb_content))
{
case T_NIL:
break;
case T_STRING:
case T_SYMBOL:
case T_FIXNUM:
content = RVAL2CRCONTENT (rb_content);
break;
default:
rb_raise (rb_eArgError,
"invalid argument (expect "
"(device, texture, width, height) or "
"(device, texture, width, height, content)): %s",
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
break;
}
surface = cairo_gl_surface_create_for_texture (device, content,
texture,
width,
height);
cr_surface_check_status (surface);
DATA_PTR (self) = surface;
if (rb_block_given_p ())
yield_and_finish (self);
return Qnil;
}
static VALUE
cr_gl_surface_set_size (VALUE self, VALUE width, VALUE height)
{
cairo_surface_t *surface = NULL;
surface = _SELF;
cairo_gl_surface_set_size (surface, NUM2INT (width), NUM2INT (height));
cr_surface_check_status (surface);
return Qnil;
}
static VALUE
cr_gl_surface_get_width (VALUE self)
{
return INT2NUM (cairo_gl_surface_get_width (_SELF));
}
static VALUE
cr_gl_surface_get_height (VALUE self)
{
return INT2NUM (cairo_gl_surface_get_height (_SELF));
}
static VALUE
cr_gl_surface_swap_buffers (VALUE self)
{
cairo_surface_t *surface = NULL;
surface = _SELF;
cairo_gl_surface_swapbuffers (surface);
cr_surface_check_status (surface);
return Qnil;
}
#endif
#ifdef CAIRO_HAS_TEE_SURFACE
/* tee surface functions */
static VALUE
cr_tee_surface_initialize (VALUE self, VALUE master)
{
cairo_surface_t *surface = NULL;
surface = cairo_tee_surface_create (RVAL2CRSURFACE (master));
cr_surface_check_status (surface);
DATA_PTR (self) = surface;
rb_iv_set (self, "surfaces", rb_ary_new3 (1, master));
if (rb_block_given_p ())
yield_and_finish (self);
return Qnil;
}
static VALUE
cr_tee_surface_add (VALUE self, VALUE target)
{
cairo_surface_t *surface = NULL;
surface = _SELF;
cairo_tee_surface_add (surface, RVAL2CRSURFACE (target));
cr_surface_check_status (surface);
rb_ary_push (rb_iv_get (self, "surfaces"), target);
return Qnil;
}
static VALUE
cr_tee_surface_shift_operator (VALUE self, VALUE target)
{
cr_tee_surface_add (self, target);
return self;
}
static VALUE
cr_tee_surface_remove (VALUE self, VALUE target_or_index)
{
cairo_surface_t *surface = NULL, *target;
VALUE rb_surfaces;
int i;
surface = _SELF;
if (rb_cairo__is_kind_of (target_or_index, rb_cCairo_Surface))
{
target = RVAL2CRSURFACE (target_or_index);
}
else
{
VALUE index;
index = rb_check_to_integer (target_or_index, "to_int");
if (NIL_P (index))
rb_raise (rb_eArgError,
"invalid argument (expect (surface) or (index)): %s",
rb_cairo__inspect (target_or_index));
target = cairo_tee_surface_index (surface, NUM2INT (index));
}
cairo_tee_surface_remove (surface, target);
cr_surface_check_status (surface);
rb_surfaces = rb_iv_get (self, "surfaces");
for (i = 0; i < RARRAY_LEN (rb_surfaces); i++)
{
VALUE rb_marked_surface;
cairo_surface_t *marked_surface;
rb_marked_surface = RARRAY_PTR (rb_surfaces)[i];
marked_surface = RVAL2CRSURFACE (rb_marked_surface);
if (marked_surface == target)
{
rb_ary_delete (rb_surfaces, rb_marked_surface);
break;
}
}
return Qnil;
}
static VALUE
cr_tee_surface_array_reference (VALUE self, VALUE index)
{
cairo_surface_t *surface = NULL, *target;
surface = _SELF;
index = rb_Integer (index);
target = cairo_tee_surface_index (surface, NUM2UINT (index));
cr_surface_check_status (surface);
cr_surface_check_status (target);
return CRSURFACE2RVAL (target);
}
#endif
#ifdef CAIRO_HAS_XML_SURFACE
/* XML surface functions */
static VALUE
cr_xml_surface_initialize (int argc, VALUE *argv, VALUE self)
{
cairo_surface_t *surface;
cairo_device_t *device;
double width, height;
cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA;
VALUE rb_device, rb_width, rb_height, rb_content;
rb_scan_args (argc, argv, "31",
&rb_device, &rb_width, &rb_height, &rb_content);
device = RVAL2CRDEVICE (rb_device);
width = NUM2DBL (rb_width);
height = NUM2DBL (rb_height);
switch (TYPE (rb_content))
{
case T_NIL:
break;
case T_STRING:
case T_SYMBOL:
case T_FIXNUM:
content = RVAL2CRCONTENT (rb_content);
break;
default:
rb_raise (rb_eArgError,
"invalid argument (expect "
"(device, width, height) or "
"(device, width, height, content)): %s",
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
break;
}
surface = cairo_xml_surface_create (device, content, width, height);
cr_surface_check_status (surface);
DATA_PTR (self) = surface;
if (rb_block_given_p ())
yield_and_finish (self);
return Qnil;
}
#endif
static int
cr_finish_all_guarded_surfaces_at_end_iter (VALUE key, VALUE value, VALUE data)
{
cr_surface_finish (key);
return ST_CONTINUE;
}
static void
cr_finish_all_guarded_surfaces_at_end (VALUE data)
{
rb_hash_foreach (rb_cairo__gc_guarded_objects (rb_cCairo_Surface),
cr_finish_all_guarded_surfaces_at_end_iter,
Qnil);
}
void
Init_cairo_surface (void)
{
cr_id_parse = rb_intern ("parse");
cr_id_size = rb_intern ("size");
cr_id_set_unit = rb_intern ("unit=");
rb_cCairo_Surface =
rb_define_class_under (rb_mCairo, "Surface", rb_cObject);
rb_define_alloc_func (rb_cCairo_Surface, cr_surface_allocate);
rb_cairo__initialize_gc_guard_holder_class (rb_cCairo_Surface);
rb_set_end_proc(cr_finish_all_guarded_surfaces_at_end, Qnil);
rb_define_singleton_method (rb_cCairo_Surface, "image_supported?",
cr_surface_image_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Surface, "pdf_supported?",
cr_surface_pdf_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Surface, "ps_supported?",
cr_surface_ps_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Surface, "quartz_supported?",
cr_surface_quartz_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Surface, "win32_supported?",
cr_surface_win32_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Surface, "svg_supported?",
cr_surface_svg_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Surface, "win32_printing_supported?",
cr_surface_win32_printing_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Surface, "quartz_image_supported?",
cr_surface_quartz_image_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Surface, "script_supported?",
cr_surface_script_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Surface, "recording_supported?",
cr_surface_recording_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Surface, "gl_supported?",
cr_surface_gl_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Surface, "gl_texture_supported?",
cr_surface_gl_texture_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Surface, "tee_supported?",
cr_surface_tee_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Surface, "xml_supported?",
cr_surface_xml_supported_p, 0);
rb_define_method (rb_cCairo_Surface, "initialize",
cr_surface_initialize, -1);
rb_define_method (rb_cCairo_Surface, "create_similar",
cr_surface_create_similar, -1);
#if CAIRO_CHECK_VERSION(1, 11, 4)
rb_define_method (rb_cCairo_Surface, "create_similar_image",
cr_surface_create_similar_image, -1);
rb_define_method (rb_cCairo_Surface, "map_to_image",
cr_surface_map_to_image, -1);
rb_define_method (rb_cCairo_Surface, "unmap_image",
cr_surface_unmap_image, 1);
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
rb_define_method (rb_cCairo_Surface, "sub_rectangle_surface",
cr_surface_create_sub_rectangle_surface, 4);
rb_define_method (rb_cCairo_Surface, "device",
cr_surface_get_device, 0);
#endif
rb_define_method (rb_cCairo_Surface, "destroy", cr_surface_destroy, 0);
rb_define_method (rb_cCairo_Surface, "finish", cr_surface_finish, 0);
rb_define_method (rb_cCairo_Surface, "content", cr_surface_get_content, 0);
#if CAIRO_CHECK_VERSION(1, 10, 0)
rb_define_method (rb_cCairo_Surface, "get_mime_data",
cr_surface_get_mime_data, 1);
rb_define_method (rb_cCairo_Surface, "set_mime_data",
cr_surface_set_mime_data, 2);
#endif
#if CAIRO_CHECK_VERSION(1, 11, 4)
rb_define_method (rb_cCairo_Surface, "supported_mime_type?",
cr_surface_supported_mime_type_p, 1);
#endif
rb_define_method (rb_cCairo_Surface, "font_options",
cr_surface_get_font_options, 0);
rb_define_method (rb_cCairo_Surface, "flush", cr_surface_flush, 0);
rb_define_method (rb_cCairo_Surface, "mark_dirty", cr_surface_mark_dirty, -1);
rb_define_method (rb_cCairo_Surface, "set_device_offset",
cr_surface_set_device_offset, 2);
rb_define_method (rb_cCairo_Surface, "device_offset",
cr_surface_get_device_offset, 0);
rb_define_method (rb_cCairo_Surface, "set_fallback_resolution",
cr_surface_set_fallback_resolution, 2);
#if CAIRO_CHECK_VERSION(1, 7, 2)
rb_define_method (rb_cCairo_Surface, "fallback_resolution",
cr_surface_get_fallback_resolution, 0);
#endif
#if CAIRO_CHECK_VERSION(1, 5, 2)
rb_define_method (rb_cCairo_Surface, "copy_page",
cr_surface_copy_page, 2);
rb_define_method (rb_cCairo_Surface, "show_page",
cr_surface_show_page, 2);
#endif
#ifdef CAIRO_HAS_PNG_FUNCTIONS
rb_define_method (rb_cCairo_Surface, "write_to_png",
cr_surface_write_to_png_generic, 1);
#endif
RB_CAIRO_DEF_SETTERS (rb_cCairo_Surface);
/* image surface */
rb_cCairo_ImageSurface =
rb_define_class_under (rb_mCairo, "ImageSurface", rb_cCairo_Surface);
#ifdef CAIRO_HAS_PNG_FUNCTIONS
rb_define_singleton_method (rb_cCairo_ImageSurface, "from_png",
cr_image_surface_create_from_png_generic, 1);
#endif
rb_define_method (rb_cCairo_ImageSurface, "initialize",
cr_image_surface_initialize, -1);
rb_define_method (rb_cCairo_ImageSurface, "data",
cr_image_surface_get_data, 0);
rb_define_method (rb_cCairo_ImageSurface, "format",
cr_image_surface_get_format, 0);
rb_define_method (rb_cCairo_ImageSurface, "width",
cr_image_surface_get_width, 0);
rb_define_method (rb_cCairo_ImageSurface, "height",
cr_image_surface_get_height, 0);
rb_define_method (rb_cCairo_ImageSurface, "stride",
cr_image_surface_get_stride, 0);
/* PDF surface */
rb_cCairo_PDFSurface =
rb_define_class_under (rb_mCairo, "PDFSurface", rb_cCairo_Surface);
#ifdef CAIRO_HAS_PDF_SURFACE
rb_define_method (rb_cCairo_PDFSurface, "initialize",
cr_pdf_surface_initialize, -1);
rb_define_method (rb_cCairo_PDFSurface, "set_size",
cr_pdf_surface_set_size, -1);
# if CAIRO_CHECK_VERSION(1, 10, 0)
rb_define_method (rb_cCairo_PDFSurface, "restrict_to_version",
cr_pdf_surface_restrict_to_version, 1);
# endif
RB_CAIRO_DEF_SETTERS (rb_cCairo_PDFSurface);
#endif
/* PS surface */
rb_cCairo_PSSurface =
rb_define_class_under (rb_mCairo, "PSSurface", rb_cCairo_Surface);
#ifdef CAIRO_HAS_PS_SURFACE
rb_define_method (rb_cCairo_PSSurface, "initialize",
cr_ps_surface_initialize, -1);
rb_define_method (rb_cCairo_PSSurface, "set_size", cr_ps_surface_set_size, -1);
rb_define_method (rb_cCairo_PSSurface, "dsc_comment",
cr_ps_surface_dsc_comment, 1);
rb_define_method (rb_cCairo_PSSurface, "dsc_begin_setup",
cr_ps_surface_dsc_begin_setup, 0);
rb_define_method (rb_cCairo_PSSurface, "dsc_begin_page_setup",
cr_ps_surface_dsc_begin_page_setup, 0);
# if CAIRO_CHECK_VERSION(1, 5, 2)
rb_define_method (rb_cCairo_PSSurface, "restrict_to_level",
cr_ps_surface_restrict_to_level, 1);
rb_define_method (rb_cCairo_PSSurface, "eps?", cr_ps_surface_get_eps, 0);
rb_define_method (rb_cCairo_PSSurface, "set_eps", cr_ps_surface_set_eps, 1);
# endif
RB_CAIRO_DEF_SETTERS (rb_cCairo_PSSurface);
#endif
/* XLib surface */
rb_cCairo_XLibSurface =
rb_define_class_under (rb_mCairo, "XLibSurface", rb_cCairo_Surface);
/* XCB surface */
rb_cCairo_XCBSurface =
rb_define_class_under (rb_mCairo, "XCBSurface", rb_cCairo_Surface);
/* Quartz surface */
rb_cCairo_QuartzSurface =
rb_define_class_under (rb_mCairo, "QuartzSurface", rb_cCairo_Surface);
#ifdef RB_CAIRO_HAS_QUARTZ_SURFACE
rb_define_method (rb_cCairo_QuartzSurface, "initialize",
cr_quartz_surface_initialize, -1);
rb_define_method (rb_cCairo_QuartzSurface, "cg_context",
cr_quartz_surface_get_cg_context, 0);
#endif
/* Win32 surface */
rb_cCairo_Win32Surface =
rb_define_class_under (rb_mCairo, "Win32Surface", rb_cCairo_Surface);
#ifdef CAIRO_HAS_WIN32_SURFACE
rb_define_method (rb_cCairo_Win32Surface, "initialize",
cr_win32_surface_initialize, -1);
rb_define_method (rb_cCairo_Win32Surface, "hdc",
cr_win32_surface_get_hdc, 0);
# if CAIRO_CHECK_VERSION(1, 4, 0)
rb_define_method (rb_cCairo_Win32Surface, "image",
cr_win32_surface_get_image, 0);
# endif
#endif
/* SVG surface */
rb_cCairo_SVGSurface =
rb_define_class_under (rb_mCairo, "SVGSurface", rb_cCairo_Surface);
#ifdef CAIRO_HAS_SVG_SURFACE
rb_define_method (rb_cCairo_SVGSurface, "initialize",
cr_svg_surface_initialize, -1);
rb_define_method (rb_cCairo_SVGSurface, "restrict_to_version",
cr_svg_surface_restrict_to_version, 1);
RB_CAIRO_DEF_SETTERS (rb_cCairo_SVGSurface);
#endif
/* Win32 printing surface */
rb_cCairo_Win32PrintingSurface =
rb_define_class_under (rb_mCairo, "Win32PrintingSurface", rb_cCairo_Surface);
#ifdef RB_CAIRO_HAS_WIN32_PRINTING_SURFACE
rb_define_method (rb_cCairo_Win32PrintingSurface, "initialize",
cr_win32_printing_surface_initialize, -1);
rb_define_method (rb_cCairo_Win32PrintingSurface, "hdc",
cr_win32_surface_get_hdc, 0);
#endif
/* Quartz image surface */
rb_cCairo_QuartzImageSurface =
rb_define_class_under (rb_mCairo, "QuartzImageSurface", rb_cCairo_Surface);
#ifdef RB_CAIRO_HAS_QUARTZ_IMAGE_SURFACE
rb_define_method (rb_cCairo_QuartzImageSurface, "initialize",
cr_quartz_image_surface_initialize, 1);
rb_define_method (rb_cCairo_QuartzImageSurface, "image",
cr_quartz_image_surface_get_image, 0);
#endif
/* script surface */
rb_cCairo_ScriptSurface =
rb_define_class_under (rb_mCairo, "ScriptSurface", rb_cCairo_Surface);
#ifdef CAIRO_HAS_SCRIPT_SURFACE
rb_define_method (rb_cCairo_ScriptSurface, "initialize",
cr_script_surface_initialize, -1);
RB_CAIRO_DEF_SETTERS (rb_cCairo_ScriptSurface);
#endif
/* Qt surface */
rb_cCairo_QtSurface =
rb_define_class_under (rb_mCairo, "QtSurface", rb_cCairo_Surface);
/* recording surface */
rb_cCairo_RecordingSurface =
rb_define_class_under (rb_mCairo, "RecordingSurface", rb_cCairo_Surface);
#ifdef CAIRO_HAS_RECORDING_SURFACE
rb_define_method (rb_cCairo_RecordingSurface, "initialize",
cr_recording_surface_initialize, -1);
rb_define_method (rb_cCairo_RecordingSurface, "ink_extents",
cr_recording_surface_get_ink_extents, 0);
# if CAIRO_CHECK_VERSION(1, 11, 4)
rb_define_method (rb_cCairo_RecordingSurface, "extents",
cr_recording_surface_get_extents, 0);
# endif
#endif
/* VG surface */
rb_cCairo_VGSurface =
rb_define_class_under (rb_mCairo, "VGSurface", rb_cCairo_Surface);
/* GL surface */
rb_cCairo_GLSurface =
rb_define_class_under (rb_mCairo, "GLSurface", rb_cCairo_Surface);
rb_cCairo_GLTextureSurface =
rb_define_class_under (rb_mCairo, "GLTextureSurface", rb_cCairo_GLSurface);
#ifdef RB_CAIRO_HAS_GL_SURFACE
rb_define_method (rb_cCairo_GLSurface, "initialize",
cr_gl_surface_initialize, 1);
rb_define_method (rb_cCairo_GLSurface, "set_size",
cr_gl_surface_set_size, 2);
rb_define_method (rb_cCairo_GLSurface, "width",
cr_gl_surface_get_width, 0);
rb_define_method (rb_cCairo_GLSurface, "height",
cr_gl_surface_get_height, 0);
rb_define_method (rb_cCairo_GLSurface, "swap_buffers",
cr_gl_surface_swap_buffers, 0);
RB_CAIRO_DEF_SETTERS (rb_cCairo_GLSurface);
rb_define_method (rb_cCairo_GLTextureSurface, "initialize",
cr_gl_texture_surface_initialize, 1);
RB_CAIRO_DEF_SETTERS (rb_cCairo_GLTextureSurface);
#endif
/* DRM surface */
rb_cCairo_DRMSurface =
rb_define_class_under (rb_mCairo, "DRMSurface", rb_cCairo_Surface);
/* tee surface */
rb_cCairo_TeeSurface =
rb_define_class_under (rb_mCairo, "TeeSurface", rb_cCairo_Surface);
#ifdef CAIRO_HAS_TEE_SURFACE
rb_define_method (rb_cCairo_TeeSurface, "initialize",
cr_tee_surface_initialize, 1);
rb_define_method (rb_cCairo_TeeSurface, "add",
cr_tee_surface_add, 1);
rb_define_method (rb_cCairo_TeeSurface, "<<",
cr_tee_surface_shift_operator, 1);
rb_define_method (rb_cCairo_TeeSurface, "remove",
cr_tee_surface_remove, 1);
rb_define_method (rb_cCairo_TeeSurface, "[]",
cr_tee_surface_array_reference, 1);
RB_CAIRO_DEF_SETTERS (rb_cCairo_TeeSurface);
#endif
/* XML surface */
rb_cCairo_XMLSurface =
rb_define_class_under (rb_mCairo, "XMLSurface", rb_cCairo_Surface);
#ifdef CAIRO_HAS_XML_SURFACE
rb_define_method (rb_cCairo_XMLSurface, "initialize",
cr_xml_surface_initialize, -1);
RB_CAIRO_DEF_SETTERS (rb_cCairo_XMLSurface);
#endif
/* Skia surface */
rb_cCairo_SkiaSurface =
rb_define_class_under (rb_mCairo, "SkiaSurface", rb_cCairo_Surface);
/* sub surface */
rb_cCairo_SubSurface =
rb_define_class_under (rb_mCairo, "SubSurface", rb_cCairo_Surface);
/* Cogl surface */
rb_cCairo_CoglSurface =
rb_define_class_under (rb_mCairo, "CoglSurface", rb_cCairo_Surface);
}
cairo-1.12.8/ext/cairo/rb_cairo_glyph.c 0000644 0000041 0000041 00000006376 12256106703 017772 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-08-16 08:16:39 $
*
* Copyright 2005 Øyvind Kolås
* Copyright 2004-2005 MenTaLguY
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
VALUE rb_cCairo_Glyph;
#define _SELF(self) (RVAL2CRGLYPH(self))
cairo_glyph_t *
rb_cairo_glyph_from_ruby_object (VALUE obj)
{
cairo_glyph_t *glyph;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_Glyph))
{
rb_raise (rb_eTypeError, "not a cairo glyph");
}
Data_Get_Struct (obj, cairo_glyph_t, glyph);
return glyph;
}
static void
cr_glyph_free (void *ptr)
{
if (ptr)
{
xfree (ptr);
}
}
VALUE
rb_cairo_glyph_to_ruby_object (cairo_glyph_t *glyph)
{
if (glyph)
{
cairo_glyph_t *new_glyph;
new_glyph = ALLOC (cairo_glyph_t);
*new_glyph = *glyph;
return Data_Wrap_Struct (rb_cCairo_Glyph, NULL, cr_glyph_free, new_glyph);
}
else
{
return Qnil;
}
}
static VALUE
cr_glyph_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, cr_glyph_free, NULL);
}
static VALUE
cr_glyph_initialize (VALUE self, VALUE index, VALUE x, VALUE y)
{
cairo_glyph_t *glyph;
glyph = ALLOC (cairo_glyph_t);
glyph->index = NUM2ULONG (index);
glyph->x = NUM2DBL (x);
glyph->y = NUM2DBL (y);
DATA_PTR (self) = glyph;
return Qnil;
}
static VALUE
cr_glyph_index (VALUE self)
{
return ULONG2NUM (_SELF(self)->index);
}
static VALUE
cr_glyph_x (VALUE self)
{
return rb_float_new (_SELF(self)->x);
}
static VALUE
cr_glyph_y (VALUE self)
{
return rb_float_new (_SELF(self)->y);
}
static VALUE
cr_glyph_set_index (VALUE self, VALUE index)
{
_SELF(self)->index = NUM2ULONG (index);
return self;
}
static VALUE
cr_glyph_set_x (VALUE self, VALUE x)
{
_SELF(self)->x = NUM2DBL (x);
return self;
}
static VALUE
cr_glyph_set_y (VALUE self, VALUE y)
{
_SELF(self)->y = NUM2DBL (y);
return self;
}
static VALUE
cr_glyph_to_s (VALUE self)
{
VALUE ret;
ret = rb_str_new2 ("#<");
rb_str_cat2 (ret, rb_class2name (CLASS_OF (self)));
rb_str_cat2 (ret, ": ");
rb_str_cat2 (ret, "index=");
rb_str_concat (ret, rb_inspect (cr_glyph_index (self)));
rb_str_cat2 (ret, ", ");
rb_str_cat2 (ret, "x=");
rb_str_concat (ret, rb_inspect (cr_glyph_x (self)));
rb_str_cat2 (ret, ", ");
rb_str_cat2 (ret, "y=");
rb_str_concat (ret, rb_inspect (cr_glyph_y (self)));
rb_str_cat2 (ret, ">");
return ret;
}
void
Init_cairo_glyph (void)
{
rb_cCairo_Glyph = rb_define_class_under (rb_mCairo, "Glyph", rb_cObject);
rb_define_alloc_func (rb_cCairo_Glyph, cr_glyph_allocate);
rb_define_method (rb_cCairo_Glyph, "initialize", cr_glyph_initialize, 3);
rb_define_method (rb_cCairo_Glyph, "index", cr_glyph_index, 0);
rb_define_method (rb_cCairo_Glyph, "x", cr_glyph_x, 0);
rb_define_method (rb_cCairo_Glyph, "y", cr_glyph_y, 0);
rb_define_method (rb_cCairo_Glyph, "set_index", cr_glyph_set_index, 1);
rb_define_method (rb_cCairo_Glyph, "set_x", cr_glyph_set_x, 1);
rb_define_method (rb_cCairo_Glyph, "set_y", cr_glyph_set_y, 1);
rb_define_method (rb_cCairo_Glyph, "to_s", cr_glyph_to_s, 0);
RB_CAIRO_DEF_SETTERS (rb_cCairo_Glyph);
}
cairo-1.12.8/ext/cairo/extconf.rb 0000755 0000041 0000041 00000012114 12256106703 016624 0 ustar www-data www-data #!/usr/bin/env ruby
# vim: filetype=ruby:expandtab:shiftwidth=2:tabstop=8:softtabstop=2 :
require 'pathname'
require 'English'
require 'mkmf'
require 'fileutils'
begin
require 'pkg-config'
rescue LoadError
require 'rubygems'
require 'pkg-config'
end
checking_for(checking_message("GCC")) do
if macro_defined?("__GNUC__", "")
$CFLAGS += ' -Wall'
true
else
false
end
end
package = "cairo"
module_name = "cairo"
major, minor, micro = 1, 2, 0
base_dir = Pathname(__FILE__).dirname.parent.parent
checking_for(checking_message("Win32 OS")) do
case RUBY_PLATFORM
when /cygwin|mingw|mswin32/
$defs << "-DRUBY_CAIRO_PLATFORM_WIN32"
import_library_name = "libruby-#{module_name}.a"
$DLDFLAGS << " -Wl,--out-implib=#{import_library_name}"
$cleanfiles << import_library_name
if with_config('vendor-override', true)
binary_base_dir = base_dir + "vendor" + "local"
$CFLAGS += " -I#{binary_base_dir}/include"
pkg_config_dir = binary_base_dir + "lib" + "pkgconfig"
PKGConfig.add_path(pkg_config_dir.to_s)
PKGConfig.set_override_variable("prefix", binary_base_dir.to_s)
end
true
else
false
end
end
def package_platform
if File.exist?("/etc/debian_version")
:debian
elsif File.exist?("/etc/fedora-release")
:fedora
elsif File.exist?("/etc/redhat-release")
:redhat
elsif find_executable("brew")
:homebrew
elsif find_executable("port")
:macports
else
:unknown
end
end
def super_user?
Process.uid.zero?
end
def normalize_native_package_info(native_package_info)
native_package_info ||= {}
native_package_info = native_package_info.dup
native_package_info[:fedora] ||= native_package_info[:redhat]
native_package_info
end
def install_missing_native_package(native_package_info)
platform = package_platform
native_package_info = normalize_native_package_info(native_package_info)
package = native_package_info[platform]
return false if package.nil?
need_super_user_priviledge = true
case platform
when :debian
install_command = "apt-get install -V -y #{package}"
when :fedora, :redhat
install_command = "yum install -y #{package}"
when :homebrew
need_super_user_priviledge = false
install_command = "brew install #{package}"
when :macports
install_command = "port install -y #{package}"
else
return false
end
have_priviledge = (not need_super_user_priviledge or super_user?)
unless have_priviledge
sudo = find_executable("sudo")
end
installing_message = "installing '#{package}' native package... "
message("%s", installing_message)
failed_to_get_super_user_priviledge = false
if have_priviledge
succeeded = xsystem(install_command)
else
if sudo
install_command = "#{sudo} #{install_command}"
succeeded = xsystem(install_command)
else
succeeded = false
failed_to_get_super_user_priviledge = true
end
end
if failed_to_get_super_user_priviledge
result_message = "require super user privilege"
else
result_message = succeeded ? "succeeded" : "failed"
end
Logging.postpone do
"#{installing_message}#{result_message}\n"
end
message("#{result_message}\n")
error_message = nil
unless succeeded
if failed_to_get_super_user_priviledge
error_message = <<-EOM
'#{package}' native package is required.
run the following command as super user to install required native package:
\# #{install_command}
EOM
else
error_message = <<-EOM
failed to run '#{install_command}'.
EOM
end
end
if error_message
message("%s", error_message)
Logging.message("%s", error_message)
end
Logging.message("--------------------\n\n")
succeeded
end
def required_pkg_config_package(package_info, native_package_info=nil)
if package_info.is_a?(Array)
required_package_info = package_info
else
required_package_info = [package_info]
end
return true if PKGConfig.have_package(*required_package_info)
native_package_info ||= {}
return false unless install_missing_native_package(native_package_info)
PKGConfig.have_package(*required_package_info)
end
unless required_pkg_config_package([package, major, minor, micro],
:debian => "libcairo2-dev",
:redhat => "cairo-devel",
:homebrew => "cairo",
:macports => "cairo")
exit(false)
end
checking_for(checking_message("Mac OS X")) do
case RUBY_PLATFORM
when /darwin/
if have_macro("CAIRO_HAS_QUARTZ_SURFACE", ["cairo.h"])
checking_for("RubyCocoa") do
begin
require 'osx/cocoa'
$defs << "-DHAVE_RUBY_COCOA"
$DLDFLAGS << " -Wl,-framework,RubyCocoa"
true
rescue LoadError
false
end
end
end
true
else
false
end
end
$defs << "-DRB_CAIRO_COMPILATION"
have_header("ruby/st.h") unless have_macro("HAVE_RUBY_ST_H", "ruby.h")
have_header("ruby/io.h") unless have_macro("HAVE_RUBY_IO_H", "ruby.h")
have_func("rb_errinfo", "ruby.h")
have_type("enum ruby_value_type", "ruby.h")
create_makefile(module_name)
cairo-1.12.8/ext/cairo/rb_cairo_io.c 0000644 0000041 0000041 00000010173 12256106703 017244 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* Copyright 2005-2010 Kouhei Sutou
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
#include "rb_cairo_io.h"
ID rb_cairo__io_id_read;
ID rb_cairo__io_id_write;
ID rb_cairo__io_id_output;
/* read/write callback */
rb_cairo__io_callback_closure_t *
rb_cairo__io_closure_new (VALUE target)
{
rb_cairo__io_callback_closure_t *closure;
closure = ALLOC (rb_cairo__io_callback_closure_t);
closure->target = target;
closure->error = Qnil;
return closure;
}
void
rb_cairo__io_closure_destroy (rb_cairo__io_callback_closure_t *closure)
{
xfree (closure);
}
void
rb_cairo__io_closure_free (void *closure)
{
rb_cairo__io_closure_destroy ((rb_cairo__io_callback_closure_t *) closure);
}
static VALUE
rb_cairo__io_func_rescue (VALUE io_closure)
{
rb_cairo__io_callback_closure_t *closure;
closure = (rb_cairo__io_callback_closure_t *)io_closure;
closure->error = RB_ERRINFO;
return Qnil;
}
static VALUE
rb_cairo__io_func_invoke (VALUE user_data)
{
rb_cairo__io_invoke_data_t *data;
data = (rb_cairo__io_invoke_data_t *)user_data;
return rb_rescue2 (data->func, data->data,
rb_cairo__io_func_rescue, data->data, rb_eException,
(VALUE)0);
}
/* write callback */
static VALUE
rb_cairo__io_write_func_invoke (VALUE write_closure)
{
VALUE output, data;
long written_bytes;
rb_cairo__io_callback_closure_t *closure;
unsigned int length;
closure = (rb_cairo__io_callback_closure_t *)write_closure;
output = closure->target;
data = rb_str_new ((const char *)closure->data, closure->length);
length = RSTRING_LEN (data);
while (length != 0)
{
VALUE rb_written_bytes = rb_funcall (output,
rb_cairo__io_id_write, 1, data);
written_bytes = NUM2LONG (rb_written_bytes);
data = rb_str_substr (data, written_bytes,
RSTRING_LEN (data) - written_bytes);
length -= written_bytes;
}
return Qnil;
}
cairo_status_t
rb_cairo__io_write_func (void *write_closure,
const unsigned char *data, unsigned int length)
{
rb_cairo__io_callback_closure_t *closure;
rb_cairo__io_invoke_data_t invoke_data;
closure = (rb_cairo__io_callback_closure_t *)write_closure;
closure->data = (unsigned char *)data;
closure->length = length;
invoke_data.func = rb_cairo__io_write_func_invoke;
invoke_data.data = (VALUE)closure;
rb_cairo__invoke_callback (rb_cairo__io_func_invoke, (VALUE)&invoke_data);
if (NIL_P (closure->error))
return CAIRO_STATUS_SUCCESS;
else
return CAIRO_STATUS_WRITE_ERROR;
}
/* read callback */
static VALUE
rb_cairo__io_read_func_invoke (VALUE read_closure)
{
VALUE input, result;
rb_cairo__io_callback_closure_t *closure;
unsigned int length, rest;
closure = (rb_cairo__io_callback_closure_t *)read_closure;
input = closure->target;
length = closure->length;
result = rb_str_new2 ("");
for (rest = length; rest != 0; rest = length - RSTRING_LEN (result))
{
rb_str_concat (result,
rb_funcall (input,
rb_cairo__io_id_read, 1, INT2NUM (rest)));
}
memcpy ((void *)closure->data, (const void *)StringValuePtr (result), length);
return Qnil;
}
cairo_status_t
rb_cairo__io_read_func (void *read_closure,
unsigned char *data, unsigned int length)
{
rb_cairo__io_callback_closure_t *closure;
rb_cairo__io_invoke_data_t invoke_data;
closure = (rb_cairo__io_callback_closure_t *)read_closure;
closure->data = data;
closure->length = length;
invoke_data.func = rb_cairo__io_read_func_invoke;
invoke_data.data = (VALUE)closure;
rb_cairo__invoke_callback (rb_cairo__io_func_invoke, (VALUE)&invoke_data);
if (NIL_P (closure->error))
return CAIRO_STATUS_SUCCESS;
else
return CAIRO_STATUS_READ_ERROR;
}
void
Init_cairo_io (void)
{
rb_cairo__io_id_read = rb_intern ("read");
rb_cairo__io_id_write = rb_intern ("write");
rb_cairo__io_id_output = rb_intern ("output");
}
cairo-1.12.8/ext/cairo/rb_cairo_text_extents.c 0000644 0000041 0000041 00000013121 12256106703 021367 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-08-17 05:41:28 $
*
* Copyright 2005 Øyvind Kolås
* Copyright 2004-2005 MenTaLguY
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
VALUE rb_cCairo_TextExtents;
#define _SELF(self) (RVAL2CRTEXTEXTENTS(self))
cairo_text_extents_t *
rb_cairo_text_extents_from_ruby_object (VALUE obj)
{
cairo_text_extents_t *extents;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_TextExtents))
{
rb_raise (rb_eTypeError, "not a cairo text_extents");
}
Data_Get_Struct (obj, cairo_text_extents_t, extents);
return extents;
}
VALUE
rb_cairo_text_extents_to_ruby_object (cairo_text_extents_t *extents)
{
if (extents)
{
cairo_text_extents_t *new_extents = ALLOC (cairo_text_extents_t);
*new_extents = *extents;
return Data_Wrap_Struct (rb_cCairo_TextExtents, NULL, -1, new_extents);
}
else
{
return Qnil;
}
}
static VALUE
cr_text_extents_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, -1, NULL);
}
static VALUE
cr_text_extents_initialize (VALUE self)
{
cairo_text_extents_t *extents;
extents = ALLOC (cairo_text_extents_t);
extents->x_bearing = 0.0;
extents->y_bearing = -1.0;
extents->width = 0.0;
extents->height = 1.0;
extents->x_advance = 1.0;
extents->y_advance = 0.0;
DATA_PTR (self) = extents;
return Qnil;
}
static VALUE
cr_text_extents_x_bearing (VALUE self)
{
return rb_float_new (_SELF(self)->x_bearing);
}
static VALUE
cr_text_extents_set_x_bearing (VALUE self, VALUE x_bearing)
{
_SELF(self)->x_bearing = NUM2DBL (x_bearing);
return Qnil;
}
static VALUE
cr_text_extents_y_bearing (VALUE self)
{
return rb_float_new (_SELF(self)->y_bearing);
}
static VALUE
cr_text_extents_set_y_bearing (VALUE self, VALUE y_bearing)
{
_SELF(self)->y_bearing = NUM2DBL (y_bearing);
return Qnil;
}
static VALUE
cr_text_extents_width (VALUE self)
{
return rb_float_new (_SELF(self)->width);
}
static VALUE
cr_text_extents_set_width (VALUE self, VALUE width)
{
_SELF(self)->width = NUM2DBL (width);
return Qnil;
}
static VALUE
cr_text_extents_height (VALUE self)
{
return rb_float_new (_SELF(self)->height);
}
static VALUE
cr_text_extents_set_height (VALUE self, VALUE height)
{
_SELF(self)->height = NUM2DBL (height);
return Qnil;
}
static VALUE
cr_text_extents_x_advance (VALUE self)
{
return rb_float_new (_SELF(self)->x_advance);
}
static VALUE
cr_text_extents_set_x_advance (VALUE self, VALUE x_advance)
{
_SELF(self)->x_advance = NUM2DBL (x_advance);
return Qnil;
}
static VALUE
cr_text_extents_y_advance (VALUE self)
{
return rb_float_new (_SELF(self)->y_advance);
}
static VALUE
cr_text_extents_set_y_advance (VALUE self, VALUE y_advance)
{
_SELF(self)->y_advance = NUM2DBL (y_advance);
return Qnil;
}
static VALUE
cr_text_extents_to_s (VALUE self)
{
VALUE ret;
ret = rb_str_new2 ("#<");
rb_str_cat2 (ret, rb_class2name (CLASS_OF (self)));
rb_str_cat2 (ret, ": ");
rb_str_cat2 (ret, "x_bearing=");
rb_str_concat (ret, rb_inspect (cr_text_extents_x_bearing (self)));
rb_str_cat2 (ret, ", ");
rb_str_cat2 (ret, "y_bearing=");
rb_str_concat (ret, rb_inspect (cr_text_extents_y_bearing (self)));
rb_str_cat2 (ret, ", ");
rb_str_cat2 (ret, "width=");
rb_str_concat (ret, rb_inspect (cr_text_extents_width (self)));
rb_str_cat2 (ret, ", ");
rb_str_cat2 (ret, "height=");
rb_str_concat (ret, rb_inspect (cr_text_extents_height (self)));
rb_str_cat2 (ret, ", ");
rb_str_cat2 (ret, "x_advance=");
rb_str_concat (ret, rb_inspect (cr_text_extents_x_advance (self)));
rb_str_cat2 (ret, ", ");
rb_str_cat2 (ret, "y_advance=");
rb_str_concat (ret, rb_inspect (cr_text_extents_y_advance (self)));
rb_str_cat2 (ret, ">");
return ret;
}
void
Init_cairo_text_extents (void)
{
rb_cCairo_TextExtents =
rb_define_class_under (rb_mCairo, "TextExtents", rb_cObject);
rb_define_alloc_func (rb_cCairo_TextExtents, cr_text_extents_allocate);
rb_define_method (rb_cCairo_TextExtents, "initialize",
cr_text_extents_initialize, 0);
rb_define_method (rb_cCairo_TextExtents, "x_bearing",
cr_text_extents_x_bearing, 0);
rb_define_method (rb_cCairo_TextExtents, "set_x_bearing",
cr_text_extents_set_x_bearing, 1);
rb_define_method (rb_cCairo_TextExtents, "y_bearing",
cr_text_extents_y_bearing, 0);
rb_define_method (rb_cCairo_TextExtents, "set_y_bearing",
cr_text_extents_set_y_bearing, 1);
rb_define_method (rb_cCairo_TextExtents, "width",
cr_text_extents_width, 0);
rb_define_method (rb_cCairo_TextExtents, "set_width",
cr_text_extents_set_width, 1);
rb_define_method (rb_cCairo_TextExtents, "height",
cr_text_extents_height, 0);
rb_define_method (rb_cCairo_TextExtents, "set_height",
cr_text_extents_set_height, 1);
rb_define_method (rb_cCairo_TextExtents, "x_advance",
cr_text_extents_x_advance, 0);
rb_define_method (rb_cCairo_TextExtents, "set_x_advance",
cr_text_extents_set_x_advance, 1);
rb_define_method (rb_cCairo_TextExtents, "y_advance",
cr_text_extents_y_advance, 0);
rb_define_method (rb_cCairo_TextExtents, "set_y_advance",
cr_text_extents_set_y_advance, 1);
rb_define_method (rb_cCairo_TextExtents, "to_s",
cr_text_extents_to_s, 0);
RB_CAIRO_DEF_SETTERS (rb_cCairo_TextExtents);
}
cairo-1.12.8/ext/cairo/rb_cairo_context.c 0000644 0000041 0000041 00000125122 12256106703 020322 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-09-26 13:52:08 $
*
* Copyright 2005-2010 Kouhei Sutou
* Copyright 2005 Øyvind Kolås
* Copyright 2004-2005 MenTaLguY
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
#ifdef HAVE_RUBY_ST_H
# include
#else
# include
#endif
VALUE rb_cCairo_Context;
VALUE rb_cCairo_Rectangle;
static ID cr_id_surface, cr_id_source;
static ID cr_id_plus, cr_id_minus, cr_id_multi, cr_id_div;
static cairo_user_data_key_t cr_object_holder_key;
#define _SELF (RVAL2CRCONTEXT(self))
static VALUE cr_get_current_point (VALUE self);
#if CAIRO_CHECK_VERSION(1, 3, 0)
static ID at_x, at_y, at_width, at_height;
static VALUE
cr_rectangle_initialize (VALUE self, VALUE x, VALUE y,
VALUE width, VALUE height)
{
rb_ivar_set (self, at_x, x);
rb_ivar_set (self, at_y, y);
rb_ivar_set (self, at_width, width);
rb_ivar_set (self, at_height, height);
return Qnil;
}
#endif
static inline void
cr_check_status (cairo_t *context)
{
rb_cairo_check_status (cairo_status (context));
}
/* Functions for manipulating state objects */
cairo_t *
rb_cairo_context_from_ruby_object (VALUE obj)
{
cairo_t *context;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_Context))
{
rb_raise (rb_eTypeError, "not a cairo graphics context");
}
Data_Get_Struct (obj, cairo_t, context);
if (!context)
rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
return context;
}
static rb_cairo__object_holder_t *
cr_object_holder_new (VALUE object)
{
return rb_cairo__object_holder_new (rb_cCairo_Context, object);
}
static void
cr_object_holder_free (void *ptr)
{
rb_cairo__object_holder_free (rb_cCairo_Context, ptr);
}
static void
cr_context_free (void *ptr)
{
if (ptr)
{
cairo_destroy ((cairo_t *) ptr);
}
}
VALUE
rb_cairo_context_to_ruby_object (cairo_t *cr)
{
if (cr)
{
cairo_reference (cr);
return Data_Wrap_Struct (rb_cCairo_Context, NULL, cr_context_free, cr);
}
else
{
return Qnil;
}
}
static VALUE
cr_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, cr_context_free, NULL);
}
static void
cr_set_user_data (cairo_t *cr, const cairo_user_data_key_t *key,
void *user_data, cairo_destroy_func_t destroy)
{
#if CAIRO_CHECK_VERSION(1, 4, 0)
cairo_set_user_data (cr, key, user_data, destroy);
#else
cairo_surface_t *surface;
surface = cairo_get_target (cr);
cairo_surface_set_user_data (surface, key, user_data, destroy);
#endif
}
static VALUE
cr_destroy (VALUE self)
{
cairo_t *cr;
cr = _SELF;
cr_set_user_data (cr, &cr_object_holder_key, NULL, NULL);
cairo_destroy (cr);
DATA_PTR (self) = NULL;
return Qnil;
}
static VALUE
cr_destroy_with_destroy_check (VALUE self)
{
if (DATA_PTR (self))
cr_destroy (self);
return Qnil;
}
static VALUE
cr_initialize (VALUE self, VALUE target)
{
cairo_t *cr;
VALUE result = Qnil;
cr = cairo_create (RVAL2CRSURFACE (target));
cr_check_status (cr);
rb_ivar_set (self, cr_id_surface, target);
cr_set_user_data (cr,
&cr_object_holder_key,
cr_object_holder_new(self),
cr_object_holder_free);
DATA_PTR (self) = cr;
if (rb_block_given_p ())
result = rb_ensure (rb_yield, self, cr_destroy_with_destroy_check, self);
return result;
}
static VALUE
cr_restore (VALUE self)
{
cairo_restore (_SELF);
cr_check_status (_SELF);
return Qnil;
}
static VALUE
cr_save (VALUE self)
{
VALUE result = Qnil;
cairo_save (_SELF);
cr_check_status (_SELF);
if (rb_block_given_p ())
{
result = rb_ensure (rb_yield, self, cr_restore, self);
}
return result;
}
static VALUE
cr_pop_group (VALUE self)
{
VALUE rb_pattern;
cairo_pattern_t *pattern;
pattern = cairo_pop_group (_SELF);
cr_check_status (_SELF);
rb_pattern = CRPATTERN2RVAL (pattern);
cairo_pattern_destroy (pattern);
return rb_pattern;
}
static VALUE
cr_pop_group_to_source (VALUE self)
{
cairo_pop_group_to_source (_SELF);
cr_check_status (_SELF);
return Qnil;
}
static VALUE
cr_pop_group_generic (int argc, VALUE *argv, VALUE self)
{
VALUE to_source;
rb_scan_args (argc, argv, "01", &to_source);
if (RVAL2CBOOL (to_source))
return cr_pop_group_to_source (self);
else
return cr_pop_group (self);
}
static VALUE
cr_push_group (int argc, VALUE *argv, VALUE self)
{
VALUE result = Qnil;
VALUE content, pop_to_source;
rb_scan_args (argc, argv, "02", &content, &pop_to_source);
if (NIL_P(content))
cairo_push_group (_SELF);
else
cairo_push_group_with_content (_SELF, RVAL2CRCONTENT(content));
cr_check_status (_SELF);
if (rb_block_given_p ())
{
int state = 0;
if (NIL_P (pop_to_source))
pop_to_source = Qtrue;
result = rb_protect (rb_yield, self, &state);
if (cairo_status(_SELF) == CAIRO_STATUS_SUCCESS)
{
if (RVAL2CBOOL (pop_to_source))
cr_pop_group_to_source (self);
else
result = cr_pop_group (self);
}
if (state)
rb_jump_tag (state);
}
return result;
}
/* Modify state */
static VALUE
cr_set_operator (VALUE self, VALUE operator)
{
cairo_set_operator (_SELF, RVAL2CROPERATOR (operator));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_set_source_rgb (int argc, VALUE *argv, VALUE self)
{
VALUE red, green, blue;
int n;
n = rb_scan_args (argc, argv, "12", &red, &green, &blue);
if (n == 1 && rb_cairo__is_kind_of (red, rb_cArray))
{
VALUE ary = red;
n = RARRAY_LEN (ary);
red = rb_ary_entry (ary, 0);
green = rb_ary_entry (ary, 1);
blue = rb_ary_entry (ary, 2);
}
if (n == 3)
{
cairo_set_source_rgb (_SELF,
NUM2DBL (red),
NUM2DBL (green),
NUM2DBL (blue));
}
else
{
VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
rb_raise (rb_eArgError,
"invalid RGB: %s (expect "
"(red, green, blue) or ([red, green, blue]))",
StringValuePtr (inspected_arg));
}
cr_check_status (_SELF);
rb_ivar_set (self, cr_id_source, Qnil);
return self;
}
static VALUE
cr_set_source_rgba (int argc, VALUE *argv, VALUE self)
{
VALUE red, green, blue, alpha;
int n;
n = rb_scan_args (argc, argv, "13", &red, &green, &blue, &alpha);
if (n == 1 && rb_cairo__is_kind_of (red, rb_cArray))
{
VALUE ary = red;
n = RARRAY_LEN (ary);
red = rb_ary_entry (ary, 0);
green = rb_ary_entry (ary, 1);
blue = rb_ary_entry (ary, 2);
alpha = rb_ary_entry (ary, 3);
}
if (n == 3)
{
cairo_set_source_rgb (_SELF,
NUM2DBL (red),
NUM2DBL (green),
NUM2DBL (blue));
}
else if (n == 4)
{
cairo_set_source_rgba (_SELF,
NUM2DBL (red),
NUM2DBL (green),
NUM2DBL (blue),
NUM2DBL (alpha));
}
else
{
VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
rb_raise (rb_eArgError,
"invalid RGB%s: %s (expect "
"(red, green, blue), (red, green, blue, alpha), "
"([red, green, blue]) or ([red, green, blue, alpha]))",
n == 4 ? "A" : "",
StringValuePtr (inspected_arg));
}
cr_check_status (_SELF);
rb_ivar_set (self, cr_id_source, Qnil);
return self;
}
static VALUE
cr_set_source_surface (VALUE self, VALUE surface, VALUE width, VALUE height)
{
cairo_set_source_surface (_SELF,
RVAL2CRSURFACE (surface),
NUM2DBL (width),
NUM2DBL (height));
cr_check_status (_SELF);
rb_ivar_set (self, cr_id_source, Qnil);
return self;
}
static VALUE
cr_set_source (VALUE self, VALUE pattern)
{
cairo_set_source (_SELF, RVAL2CRPATTERN (pattern));
cr_check_status (_SELF);
rb_ivar_set (self, cr_id_source, pattern);
return self;
}
static VALUE
cr_set_source_generic (int argc, VALUE *argv, VALUE self)
{
VALUE arg1, arg2, arg3, arg4;
int n;
n = rb_scan_args (argc, argv, "13", &arg1, &arg2, &arg3, &arg4);
if (n == 1 && rb_cairo__is_kind_of (arg1, rb_cArray))
{
return cr_set_source_rgba (argc, argv, self);
}
else if (n == 1 && rb_cairo__is_kind_of (arg1, rb_cCairo_Surface))
{
return cr_set_source_surface (self, arg1,
rb_float_new (0),
rb_float_new (0));
}
else if (n == 1)
{
return cr_set_source (self, arg1);
}
else if (n == 3 && rb_cairo__is_kind_of (arg1, rb_cCairo_Surface))
{
return cr_set_source_surface (self, arg1, arg2, arg3);
}
else if (n == 3 || n == 4)
{
return cr_set_source_rgba (argc, argv, self);
}
else
{
rb_raise (rb_eArgError,
"invalid argument (expect "
"(red, green, blue), (red, green, blue, alpha), "
"([red, green, blue]), ([red, green, blue, alpha]), "
"(surface), (pattern) or (surface, x, y))");
}
}
static VALUE
cr_set_tolerance (VALUE self, VALUE tolerance)
{
cairo_set_tolerance (_SELF, NUM2DBL (tolerance));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_set_antialias(VALUE self, VALUE antialias)
{
cairo_set_antialias(_SELF, RVAL2CRANTIALIAS (antialias));
cr_check_status(_SELF);
return self;
}
static VALUE
cr_set_fill_rule (VALUE self, VALUE rule)
{
cairo_set_fill_rule (_SELF, RVAL2CRFILLRULE (rule));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_set_line_width (VALUE self, VALUE width)
{
cairo_set_line_width (_SELF, NUM2DBL (width));
return self;
}
static VALUE
cr_set_line_cap (VALUE self, VALUE cap)
{
cairo_set_line_cap (_SELF, RVAL2CRLINECAP (cap));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_set_line_join (VALUE self, VALUE join)
{
cairo_set_line_join (_SELF, RVAL2CRLINEJOIN (join));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_set_dash (int argc, VALUE *argv, VALUE self)
{
VALUE dash_array, rb_offset;
double offset;
cairo_bool_t is_num;
rb_scan_args(argc, argv, "11", &dash_array, &rb_offset);
is_num = rb_cairo__is_kind_of (dash_array, rb_cNumeric);
if (!(NIL_P (dash_array) || is_num))
{
Check_Type (dash_array, T_ARRAY);
}
if (NIL_P (rb_offset))
offset = 0.0;
else
offset = NUM2DBL (rb_offset);
if (is_num)
{
double values[1];
values[0] = NUM2DBL (dash_array);
cairo_set_dash (_SELF, values, 1, offset);
}
else if (NIL_P (dash_array) || RARRAY_LEN (dash_array) == 0)
{
cairo_set_dash (_SELF, NULL, 0, offset);
}
else
{
int i, length;
double *values;
length = RARRAY_LEN (dash_array);
values = ALLOCA_N (double, length);
if (!values)
{
rb_cairo_check_status (CAIRO_STATUS_NO_MEMORY);
}
for (i = 0; i < length; i++)
{
values[i] = NUM2DBL (RARRAY_PTR (dash_array)[i]);
}
cairo_set_dash (_SELF, values, length, offset);
}
cr_check_status (_SELF);
return self;
}
static VALUE
cr_set_miter_limit (VALUE self, VALUE limit)
{
cairo_set_miter_limit (_SELF, NUM2DBL (limit));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_translate (VALUE self, VALUE tx, VALUE ty)
{
cairo_translate (_SELF, NUM2DBL (tx), NUM2DBL (ty));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_scale (VALUE self, VALUE sx, VALUE sy)
{
cairo_scale (_SELF, NUM2DBL (sx), NUM2DBL (sy));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_rotate (VALUE self, VALUE radians)
{
cairo_rotate (_SELF, NUM2DBL (radians));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_transform (VALUE self, VALUE matrix)
{
cairo_transform (_SELF, RVAL2CRMATRIX (matrix));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_set_matrix (VALUE self, VALUE matrix)
{
cairo_set_matrix (_SELF, RVAL2CRMATRIX (matrix));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_identity_matrix (VALUE self)
{
cairo_identity_matrix (_SELF);
cr_check_status (_SELF);
return self;
}
static VALUE
cr_user_to_device (VALUE self, VALUE x, VALUE y)
{
double pair[2];
pair[0] = NUM2DBL (x);
pair[1] = NUM2DBL (y);
cairo_user_to_device (_SELF, pair, pair + 1);
cr_check_status (_SELF);
return rb_cairo__float_array (pair, 2);
}
static VALUE
cr_user_to_device_distance (VALUE self, VALUE dx, VALUE dy)
{
double pair[2];
pair[0] = NUM2DBL (dx);
pair[1] = NUM2DBL (dy);
cairo_user_to_device_distance (_SELF, pair, pair + 1);
cr_check_status (_SELF);
return rb_cairo__float_array (pair, 2);
}
static VALUE
cr_device_to_user (VALUE self, VALUE x, VALUE y)
{
double pair[2];
pair[0] = NUM2DBL (x);
pair[1] = NUM2DBL (y);
cairo_device_to_user (_SELF, pair, pair + 1);
cr_check_status (_SELF);
return rb_cairo__float_array (pair, 2);
}
static VALUE
cr_device_to_user_distance (VALUE self, VALUE dx, VALUE dy)
{
double pair[2];
pair[0] = NUM2DBL (dx);
pair[1] = NUM2DBL (dy);
cairo_device_to_user_distance (_SELF, pair, pair + 1);
cr_check_status (_SELF);
return rb_cairo__float_array (pair, 2);
}
/* Path creation functions */
static VALUE
cr_new_path (VALUE self)
{
cairo_new_path (_SELF);
cr_check_status (_SELF);
return self;
}
static VALUE
cr_move_to (VALUE self, VALUE x, VALUE y)
{
cairo_move_to (_SELF, NUM2DBL (x), NUM2DBL (y));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_new_sub_path (VALUE self)
{
cairo_new_sub_path (_SELF);
cr_check_status (_SELF);
return self;
}
static VALUE
cr_line_to (VALUE self, VALUE x, VALUE y)
{
cairo_line_to (_SELF, NUM2DBL (x), NUM2DBL (y));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_curve_to (VALUE self, VALUE x1, VALUE y1,
VALUE x2, VALUE y2, VALUE x3, VALUE y3)
{
cairo_curve_to (_SELF, NUM2DBL (x1), NUM2DBL (y1),
NUM2DBL (x2), NUM2DBL (y2), NUM2DBL (x3), NUM2DBL (y3));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_quadratic_curve_to (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
{
VALUE current_point, x0, y0, cx1, cy1, cx2, cy2;
current_point = cr_get_current_point (self);
x0 = RARRAY_PTR (current_point)[0];
y0 = RARRAY_PTR (current_point)[1];
/* cx1 = x0 + 2 * ((x1 - x0) / 3.0) */
cx1 = rb_funcall (x0, cr_id_plus, 1,
rb_funcall (INT2NUM(2), cr_id_multi, 1,
rb_funcall (rb_funcall (x1, cr_id_minus, 1, x0),
cr_id_div, 1, rb_float_new (3.0))));
/* cy1 = y0 + 2 * ((y1 - y0) / 3.0) */
cy1 = rb_funcall (y0, cr_id_plus, 1,
rb_funcall (INT2NUM(2), cr_id_multi, 1,
rb_funcall (rb_funcall (y1, cr_id_minus, 1, y0),
cr_id_div, 1, rb_float_new (3.0))));
/* cx2 = cx1 + (x2 - x0) / 3.0 */
cx2 = rb_funcall (cx1, cr_id_plus, 1,
rb_funcall (rb_funcall (x2, cr_id_minus, 1, x0),
cr_id_div, 1, rb_float_new (3.0)));
/* cy2 = cy1 + (y2 - y0) / 3.0 */
cy2 = rb_funcall (cy1, cr_id_plus, 1,
rb_funcall (rb_funcall (y2, cr_id_minus, 1, y0),
cr_id_div, 1, rb_float_new (3.0)));
return cr_curve_to (self, cx1, cy1, cx2, cy2, x2, y2);
}
static VALUE
cr_curve_to_generic (int argc, VALUE *argv, VALUE self)
{
VALUE x1, y1, x2, y2, x3, y3;
rb_scan_args (argc, argv, "42", &x1, &y1, &x2, &y2, &x3, &y3);
if (!(argc == 4 || argc == 6))
{
VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
rb_raise (rb_eArgError,
"invalid argument: %s (expect "
"(x1, y1, x2, y2) (quadratic) or "
"(x1, y1, x2, y2, x3, y3) (cubic))",
StringValuePtr (inspected_arg));
}
if (argc == 4)
return cr_quadratic_curve_to (self, x1, y1, x2, y2);
else
return cr_curve_to (self, x1, y1, x2, y2, x3, y3);
}
static VALUE
cr_arc (VALUE self, VALUE xc, VALUE yc, VALUE radius,
VALUE angle1, VALUE angle2)
{
cairo_arc (_SELF, NUM2DBL (xc), NUM2DBL (yc), NUM2DBL (radius),
NUM2DBL (angle1), NUM2DBL (angle2));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_arc_negative (VALUE self, VALUE xc, VALUE yc, VALUE radius,
VALUE angle1, VALUE angle2)
{
cairo_arc_negative (_SELF, NUM2DBL (xc), NUM2DBL (yc), NUM2DBL (radius),
NUM2DBL (angle1), NUM2DBL (angle2));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_rel_move_to (VALUE self, VALUE x, VALUE y)
{
cairo_rel_move_to (_SELF, NUM2DBL (x), NUM2DBL (y));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_rel_line_to (VALUE self, VALUE x, VALUE y)
{
cairo_rel_line_to (_SELF, NUM2DBL (x), NUM2DBL (y));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_rel_curve_to (VALUE self, VALUE dx1, VALUE dy1,
VALUE dx2, VALUE dy2, VALUE dx3, VALUE dy3)
{
cairo_rel_curve_to (_SELF, NUM2DBL (dx1), NUM2DBL (dy1),
NUM2DBL (dx2), NUM2DBL (dy2),
NUM2DBL (dx3), NUM2DBL (dy3));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_rel_quadratic_curve_to (VALUE self, VALUE dx1, VALUE dy1,
VALUE dx2, VALUE dy2)
{
VALUE current_point, x0, y0;
current_point = cr_get_current_point (self);
x0 = RARRAY_PTR (current_point)[0];
y0 = RARRAY_PTR (current_point)[1];
return cr_quadratic_curve_to (self,
rb_funcall (dx1, cr_id_plus, 1, x0),
rb_funcall (dy1, cr_id_plus, 1, y0),
rb_funcall (dx2, cr_id_plus, 1, x0),
rb_funcall (dy2, cr_id_plus, 1, y0));
}
static VALUE
cr_rel_curve_to_generic (int argc, VALUE *argv, VALUE self)
{
VALUE dx1, dy1, dx2, dy2, dx3, dy3;
rb_scan_args (argc, argv, "42", &dx1, &dy1, &dx2, &dy2, &dx3, &dy3);
if (!(argc == 4 || argc == 6))
{
VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
rb_raise (rb_eArgError,
"invalid argument: %s (expect "
"(dx1, dy1, dx2, dy2) (quadratic) or "
"(dx1, dy1, dx2, dy2, dx3, dy3) (cubic))",
StringValuePtr (inspected_arg));
}
if (argc == 4)
return cr_rel_quadratic_curve_to (self, dx1, dy1, dx2, dy2);
else
return cr_rel_curve_to (self, dx1, dy1, dx2, dy2, dx3, dy3);
}
static VALUE
cr_rectangle (VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
{
cairo_rectangle (_SELF, NUM2DBL (x), NUM2DBL (y),
NUM2DBL (width), NUM2DBL (height));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_close_path (VALUE self)
{
cairo_close_path (_SELF);
cr_check_status (_SELF);
return self;
}
#if CAIRO_CHECK_VERSION(1, 5, 8)
static VALUE
cr_path_extents (VALUE self)
{
double x1, y1, x2, y2;
cairo_path_extents (_SELF, &x1, &y1, &x2, &y2);
cr_check_status (_SELF);
return rb_ary_new3 (4,
rb_float_new(x1), rb_float_new(y1),
rb_float_new(x2), rb_float_new(y2));
}
#endif
/* Painting functions */
static VALUE
cr_paint (VALUE self)
{
cairo_paint (_SELF);
cr_check_status (_SELF);
return self;
}
static VALUE
cr_paint_with_alpha (VALUE self, VALUE alpha)
{
cairo_paint_with_alpha (_SELF, NUM2DBL (alpha));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_paint_generic(int argc, VALUE *argv, VALUE self)
{
VALUE alpha;
int n;
n = rb_scan_args (argc, argv, "01", &alpha);
if (n == 0 || (n == 1 && NIL_P (alpha)))
{
return cr_paint (self);
}
if (n == 1)
{
return cr_paint_with_alpha (self, alpha);
}
else
{
rb_raise (rb_eArgError,
"invalid argument (expect () or (alpha))");
}
}
static VALUE
cr_mask(VALUE self, VALUE pattern)
{
cairo_mask (_SELF, RVAL2CRPATTERN (pattern));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_mask_surface (VALUE self, VALUE surface, VALUE x, VALUE y)
{
cairo_mask_surface (_SELF, RVAL2CRSURFACE (surface),
NUM2DBL (x), NUM2DBL (y));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_mask_generic (int argc, VALUE *argv, VALUE self)
{
VALUE arg1, arg2, arg3;
int n;
n = rb_scan_args (argc, argv, "12", &arg1, &arg2, &arg3);
if (n == 1)
{
return cr_mask (self, arg1);
}
else if (n == 3)
{
return cr_mask_surface (self, arg1, arg2, arg3);
}
else
{
rb_raise (rb_eArgError,
"invalid argument (expect (pattern) or (surface, x, y))");
}
}
static VALUE
cr_stroke (int argc, VALUE *argv, VALUE self)
{
VALUE preserve;
rb_scan_args (argc, argv, "01", &preserve);
if (rb_block_given_p ())
{
cr_new_path (self);
rb_yield (self);
}
if (RVAL2CBOOL (preserve))
cairo_stroke_preserve (_SELF);
else
cairo_stroke (_SELF);
cr_check_status (_SELF);
return self;
}
static VALUE
cr_fill (int argc, VALUE *argv, VALUE self)
{
VALUE preserve;
rb_scan_args (argc, argv, "01", &preserve);
if (rb_block_given_p ())
{
cr_new_path (self);
rb_yield (self);
}
if (RVAL2CBOOL (preserve))
cairo_fill_preserve (_SELF);
else
cairo_fill (_SELF);
cr_check_status (_SELF);
return self;
}
static VALUE
cr_copy_page (VALUE self)
{
cairo_copy_page (_SELF);
cr_check_status (_SELF);
return self;
}
static VALUE
cr_show_page (VALUE self)
{
cairo_show_page (_SELF);
cr_check_status (_SELF);
return self;
}
/* Insideness testing */
static VALUE
cr_in_stroke (VALUE self, VALUE x, VALUE y)
{
if (rb_block_given_p ())
{
cr_new_path (self);
rb_yield (self);
}
return CBOOL2RVAL (cairo_in_stroke (_SELF, NUM2DBL (x), NUM2DBL (y)));
}
static VALUE
cr_in_fill (VALUE self, VALUE x, VALUE y)
{
if (rb_block_given_p ())
{
cr_new_path (self);
rb_yield (self);
}
return CBOOL2RVAL (cairo_in_fill (_SELF, NUM2DBL (x), NUM2DBL (y)));
}
#if CAIRO_CHECK_VERSION(1, 10, 0)
static VALUE
cr_in_clip (VALUE self, VALUE x, VALUE y)
{
if (rb_block_given_p ())
{
cr_new_path (self);
rb_yield (self);
}
return CBOOL2RVAL (cairo_in_clip (_SELF, NUM2DBL (x), NUM2DBL (y)));
}
#endif
/* Rectangular extents */
static VALUE
cr_stroke_extents (VALUE self)
{
double extents[4];
if (rb_block_given_p ())
{
cr_new_path (self);
rb_yield (self);
}
cairo_stroke_extents (_SELF, extents, extents + 1, extents + 2, extents + 3);
return rb_cairo__float_array (extents, 4);
}
static VALUE
cr_fill_extents (VALUE self)
{
double extents[4];
if (rb_block_given_p ())
{
cr_new_path (self);
rb_yield (self);
}
cairo_fill_extents (_SELF, extents, extents + 1, extents + 2, extents + 3);
return rb_cairo__float_array (extents, 4);
}
/* Clipping */
static VALUE
cr_reset_clip (VALUE self)
{
cairo_reset_clip (_SELF);
cr_check_status (_SELF);
return self;
}
static VALUE
cr_clip (int argc, VALUE *argv, VALUE self)
{
VALUE preserve;
rb_scan_args(argc, argv, "01", &preserve);
if (rb_block_given_p ())
{
cr_new_path (self);
rb_yield (self);
}
if (RVAL2CBOOL (preserve))
cairo_clip_preserve(_SELF);
else
cairo_clip (_SELF);
cr_check_status (_SELF);
return self;
}
#if CAIRO_CHECK_VERSION(1, 3, 0)
static VALUE
cr_clip_extents (VALUE self)
{
double x1, y1, x2, y2;
cairo_clip_extents (_SELF, &x1, &y1, &x2, &y2);
cr_check_status (_SELF);
return rb_ary_new3 (4,
rb_float_new (x1), rb_float_new (y1),
rb_float_new (x2), rb_float_new (y2));
}
static VALUE
cr_clip_rectangle_list (VALUE self)
{
VALUE rb_rectangles;
cairo_rectangle_list_t *rectangles;
int i;
rectangles = cairo_copy_clip_rectangle_list (_SELF);
rb_cairo_check_status (rectangles->status);
rb_rectangles = rb_ary_new2 (rectangles->num_rectangles);
for (i = 0; i < rectangles->num_rectangles; i++) {
VALUE argv[4];
cairo_rectangle_t rectangle = rectangles->rectangles[i];
argv[0] = rb_float_new (rectangle.x);
argv[1] = rb_float_new (rectangle.y);
argv[2] = rb_float_new (rectangle.width);
argv[3] = rb_float_new (rectangle.height);
rb_ary_push (rb_rectangles,
rb_class_new_instance (4, argv, rb_cCairo_Rectangle));
}
cairo_rectangle_list_destroy (rectangles);
return rb_rectangles;
}
#endif
/* Font/Text functions */
static VALUE
cr_select_font_face (int argc, VALUE *argv, VALUE self)
{
VALUE rb_family, rb_slant, rb_weight;
const char *family;
cairo_font_slant_t slant;
cairo_font_weight_t weight;
rb_scan_args(argc, argv, "03", &rb_family, &rb_slant, &rb_weight);
if (NIL_P (rb_family))
{
family = "";
}
else if (rb_cairo__is_kind_of (rb_family, rb_cString))
{
family = RSTRING_PTR (rb_family);
}
else if (rb_cairo__is_kind_of (rb_family, rb_cSymbol))
{
family = rb_id2name (SYM2ID (rb_family));
}
else
{
rb_raise (rb_eArgError,
"family name should be nil, String or Symbol: %s",
rb_cairo__inspect (rb_family));
}
if (NIL_P (rb_slant))
slant = CAIRO_FONT_SLANT_NORMAL;
else
slant = RVAL2CRFONTSLANT (rb_slant);
if (NIL_P (rb_weight))
weight = CAIRO_FONT_WEIGHT_NORMAL;
else
weight = RVAL2CRFONTWEIGHT (rb_weight);
cairo_select_font_face (_SELF, family, slant, weight);
cr_check_status (_SELF);
return self;
}
static VALUE
cr_set_font_size (VALUE self, VALUE scale)
{
cairo_set_font_size (_SELF, NUM2DBL (scale));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_set_font_matrix (VALUE self, VALUE matrix)
{
cairo_set_font_matrix (_SELF, RVAL2CRMATRIX (matrix));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_get_font_matrix (VALUE self)
{
cairo_matrix_t matrix;
cairo_get_font_matrix (_SELF, &matrix);
cr_check_status (_SELF);
return CRMATRIX2RVAL (&matrix);
}
static VALUE
cr_set_font_options (VALUE self, VALUE options)
{
cairo_set_font_options (_SELF, RVAL2CRFONTOPTIONS (options));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_get_font_options (VALUE self)
{
cairo_font_options_t *options = cairo_font_options_create ();
rb_cairo_check_status (cairo_font_options_status (options));
cairo_get_font_options (_SELF, options);
rb_cairo_check_status (cairo_font_options_status (options));
return CRFONTOPTIONS2RVAL (options);
}
static VALUE
cr_set_scaled_font (VALUE self, VALUE scaled_font)
{
cairo_set_scaled_font (_SELF, RVAL2CRSCALEDFONT (scaled_font));
cr_check_status (_SELF);
return self;
}
#if CAIRO_CHECK_VERSION(1, 3, 16)
static VALUE
cr_get_scaled_font (VALUE self)
{
return CRSCALEDFONT2RVAL (cairo_get_scaled_font (_SELF));
}
#endif
static VALUE
cr_show_text (VALUE self, VALUE utf8)
{
cairo_show_text (_SELF, RVAL2CSTR (utf8));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_show_glyphs (VALUE self, VALUE rb_glyphs)
{
int count;
cairo_glyph_t *glyphs;
RB_CAIRO__GLYPHS_TO_ARRAY (rb_glyphs, glyphs, count);
cairo_show_glyphs (_SELF, glyphs, count);
cr_check_status (_SELF);
return self;
}
#if CAIRO_CHECK_VERSION(1, 8, 0)
static VALUE
cr_show_text_glyphs (VALUE self, VALUE rb_utf8, VALUE rb_glyphs,
VALUE rb_clusters, VALUE rb_cluster_flags)
{
cairo_t *cr;
const char *utf8;
int utf8_len;
cairo_glyph_t *glyphs = NULL;
int num_glyphs = 0;
cairo_text_cluster_t *clusters = NULL;
int num_clusters = 0;
cairo_text_cluster_flags_t cluster_flags;
cr = _SELF;
utf8 = RSTRING_PTR (rb_utf8);
utf8_len = RSTRING_LEN (rb_utf8);
rb_cairo__glyphs_from_ruby_object (rb_glyphs, &glyphs, &num_glyphs);
rb_cairo__text_clusters_from_ruby_object (rb_clusters,
&clusters, &num_clusters);
cluster_flags = RVAL2CRTEXTCLUSTERFLAGS (rb_cluster_flags);
cairo_show_text_glyphs (cr, utf8, utf8_len,
glyphs, num_glyphs,
clusters, num_clusters,
cluster_flags);
if (glyphs)
cairo_glyph_free (glyphs);
if (clusters)
cairo_text_cluster_free (clusters);
return self;
}
#endif
static VALUE
cr_get_font_face (VALUE self)
{
cairo_font_face_t *face;
face = cairo_get_font_face (_SELF);
rb_cairo_check_status (cairo_font_face_status (face));
return CRFONTFACE2RVAL (face);
}
static VALUE
cr_font_extents (VALUE self)
{
cairo_font_extents_t extents;
cairo_font_extents (_SELF, &extents);
cr_check_status (_SELF);
return CRFONTEXTENTS2RVAL (&extents);
}
static VALUE
cr_set_font_face (VALUE self, VALUE face)
{
cairo_set_font_face (_SELF, NIL_P (face) ? NULL : RVAL2CRFONTFACE (face));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_text_extents (VALUE self, VALUE utf8)
{
cairo_text_extents_t extents;
cairo_text_extents (_SELF, StringValuePtr (utf8), &extents);
cr_check_status (_SELF);
return CRTEXTEXTENTS2RVAL (&extents);
}
static VALUE
cr_glyph_extents (VALUE self, VALUE rb_glyphs)
{
cairo_text_extents_t extents;
cairo_glyph_t *glyphs;
int length;
RB_CAIRO__GLYPHS_TO_ARRAY (rb_glyphs, glyphs, length);
cairo_glyph_extents (_SELF, glyphs, length, &extents);
cr_check_status (_SELF);
return CRTEXTEXTENTS2RVAL (&extents);
}
static VALUE
cr_text_path (VALUE self, VALUE utf8)
{
cairo_text_path (_SELF, StringValuePtr (utf8));
cr_check_status (_SELF);
return self;
}
static VALUE
cr_glyph_path (VALUE self, VALUE rb_glyphs)
{
int count;
cairo_glyph_t *glyphs;
RB_CAIRO__GLYPHS_TO_ARRAY (rb_glyphs, glyphs, count);
cairo_glyph_path (_SELF, glyphs, count);
cr_check_status (_SELF);
return self;
}
/* Query functions */
static VALUE
cr_get_operator (VALUE self)
{
return INT2FIX (cairo_get_operator (_SELF));
}
static VALUE
cr_get_source (VALUE self)
{
VALUE rb_source = Qnil;
cairo_pattern_t *source;
source = cairo_get_source (_SELF);
if (source)
{
rb_cairo_check_status (cairo_pattern_status (source));
rb_source = rb_ivar_get (self, cr_id_source);
if (NIL_P (rb_source) || RVAL2CRPATTERN (rb_source) != source)
{
rb_source = CRPATTERN2RVAL (source);
rb_ivar_set (self, cr_id_source, rb_source);
}
}
else
{
rb_source = Qnil;
rb_ivar_set (self, cr_id_source, rb_source);
}
return rb_source;
}
static VALUE
cr_get_tolerance (VALUE self)
{
return rb_float_new (cairo_get_tolerance (_SELF));
}
static VALUE
cr_get_antialias(VALUE self)
{
return INT2NUM (cairo_get_antialias (_SELF));
}
#if CAIRO_CHECK_VERSION(1, 5, 10)
static VALUE
cr_has_current_point(VALUE self)
{
return RTEST (cairo_has_current_point (_SELF));
}
#endif
static VALUE
cr_get_current_point (VALUE self)
{
double point[2];
cairo_get_current_point (_SELF, point, point + 1);
return rb_cairo__float_array (point, 2);
}
static VALUE
cr_get_fill_rule (VALUE self)
{
return INT2FIX (cairo_get_fill_rule (_SELF));
}
static VALUE
cr_get_line_width (VALUE self)
{
return rb_float_new (cairo_get_line_width (_SELF));
}
static VALUE
cr_get_line_cap (VALUE self)
{
return INT2FIX (cairo_get_line_cap (_SELF));
}
static VALUE
cr_get_line_join (VALUE self)
{
return INT2FIX (cairo_get_line_join (_SELF));
}
static VALUE
cr_get_miter_limit (VALUE self)
{
return rb_float_new (cairo_get_miter_limit (_SELF));
}
#if CAIRO_CHECK_VERSION(1, 3, 0)
static VALUE
cr_get_dash_count (VALUE self)
{
return INT2NUM (cairo_get_dash_count (_SELF));
}
static VALUE
cr_get_dash (VALUE self)
{
int count;
double *dashes, offset;
count = cairo_get_dash_count (_SELF);
dashes = ALLOCA_N (double, count);
cairo_get_dash (_SELF, dashes, &offset);
return rb_ary_new3 (2,
rb_cairo__float_array (dashes, count),
rb_float_new (offset));
}
#endif
static VALUE
cr_get_matrix (VALUE self)
{
cairo_matrix_t matrix;
cairo_get_matrix (_SELF, &matrix);
cr_check_status (_SELF);
return CRMATRIX2RVAL (&matrix);
}
static VALUE
cr_get_target (VALUE self)
{
cairo_surface_t *surface;
VALUE rb_surface = Qnil;
surface = cairo_get_target (_SELF);
rb_cairo_check_status (cairo_surface_status (surface));
if (RTEST (rb_ivar_defined (self, cr_id_surface)))
rb_surface = rb_ivar_get (self, cr_id_surface);
if (NIL_P (rb_surface) || RVAL2CRSURFACE (rb_surface) != surface)
{
rb_surface = CRSURFACE2RVAL (surface);
rb_ivar_set (self, cr_id_surface, rb_surface);
}
return rb_surface;
}
static VALUE
cr_get_group_target (VALUE self)
{
cairo_surface_t *surface;
surface = cairo_get_group_target (_SELF);
if (!surface)
return Qnil;
rb_cairo_check_status (cairo_surface_status (surface));
return CRSURFACE2RVAL (surface);
}
/* Paths */
static VALUE
cr_copy_path (VALUE self)
{
cairo_path_t *path;
path = cairo_copy_path (_SELF);
rb_cairo_check_status (path->status);
return CRPATH2RVAL (path);
}
static VALUE
cr_copy_path_flat (VALUE self)
{
cairo_path_t *path;
path = cairo_copy_path_flat (_SELF);
rb_cairo_check_status (path->status);
return CRPATH2RVAL (path);
}
static VALUE
cr_copy_append_path (VALUE self, VALUE path)
{
cairo_append_path (_SELF, RVAL2CRPATH (path));
cr_check_status (_SELF);
return self;
}
static int
cr_destroy_all_guarded_contexts_at_end_iter (VALUE key, VALUE value, VALUE data)
{
cr_destroy (key);
return ST_CONTINUE;
}
static void
cr_destroy_all_guarded_contexts_at_end (VALUE data)
{
rb_hash_foreach (rb_cairo__gc_guarded_objects (rb_cCairo_Context),
cr_destroy_all_guarded_contexts_at_end_iter,
Qnil);
}
void
Init_cairo_context (void)
{
cr_id_surface = rb_intern ("surface");
cr_id_source = rb_intern ("source");
cr_id_plus = rb_intern ("+");
cr_id_minus = rb_intern ("-");
cr_id_multi = rb_intern ("*");
cr_id_div = rb_intern ("/");
#if CAIRO_CHECK_VERSION(1, 3, 0)
rb_cCairo_Rectangle =
rb_define_class_under (rb_mCairo, "Rectangle", rb_cObject);
at_x = rb_intern ("@x");
at_y = rb_intern ("@y");
at_width = rb_intern ("@width");
at_height = rb_intern ("@height");
rb_define_attr (rb_cCairo_Rectangle, "x", CR_TRUE, CR_TRUE);
rb_define_attr (rb_cCairo_Rectangle, "y", CR_TRUE, CR_TRUE);
rb_define_attr (rb_cCairo_Rectangle, "width", CR_TRUE, CR_TRUE);
rb_define_attr (rb_cCairo_Rectangle, "height", CR_TRUE, CR_TRUE);
rb_define_method (rb_cCairo_Rectangle, "initialize",
cr_rectangle_initialize, 4);
#endif
rb_cCairo_Context =
rb_define_class_under (rb_mCairo, "Context", rb_cObject);
rb_define_alloc_func (rb_cCairo_Context, cr_allocate);
rb_cairo__initialize_gc_guard_holder_class (rb_cCairo_Context);
rb_set_end_proc(cr_destroy_all_guarded_contexts_at_end, Qnil);
/* Functions for manipulating state objects */
rb_define_method (rb_cCairo_Context, "initialize", cr_initialize, 1);
rb_define_method (rb_cCairo_Context, "destroy", cr_destroy, 0);
rb_define_method (rb_cCairo_Context, "save", cr_save, 0);
rb_define_method (rb_cCairo_Context, "restore", cr_restore, 0);
rb_define_method (rb_cCairo_Context, "push_group", cr_push_group, -1);
rb_define_method (rb_cCairo_Context, "pop_group", cr_pop_group_generic, -1);
rb_define_method (rb_cCairo_Context, "pop_group_to_source",
cr_pop_group_to_source, 0);
/* Modify state */
rb_define_method (rb_cCairo_Context, "set_operator", cr_set_operator, 1);
rb_define_method (rb_cCairo_Context, "set_source", cr_set_source_generic, -1);
rb_define_method (rb_cCairo_Context, "set_source_rgb",
cr_set_source_rgb, -1);
rb_define_method (rb_cCairo_Context, "set_source_rgba",
cr_set_source_rgba, -1);
rb_define_method (rb_cCairo_Context, "set_tolerance", cr_set_tolerance, 1);
rb_define_method (rb_cCairo_Context, "set_antialias", cr_set_antialias, 1);
rb_define_method (rb_cCairo_Context, "set_fill_rule", cr_set_fill_rule, 1);
rb_define_method (rb_cCairo_Context, "set_line_width", cr_set_line_width, 1);
rb_define_method (rb_cCairo_Context, "set_line_cap", cr_set_line_cap, 1);
rb_define_method (rb_cCairo_Context, "set_line_join", cr_set_line_join, 1);
rb_define_method (rb_cCairo_Context, "set_dash", cr_set_dash, -1);
rb_define_method (rb_cCairo_Context, "set_miter_limit",
cr_set_miter_limit, 1);
rb_define_method (rb_cCairo_Context, "translate", cr_translate, 2);
rb_define_method (rb_cCairo_Context, "scale", cr_scale, 2);
rb_define_method (rb_cCairo_Context, "rotate", cr_rotate, 1);
rb_define_method (rb_cCairo_Context, "transform", cr_transform, 1);
rb_define_method (rb_cCairo_Context, "set_matrix", cr_set_matrix, 1);
rb_define_method (rb_cCairo_Context, "identity_matrix",
cr_identity_matrix, 0);
rb_define_method (rb_cCairo_Context, "user_to_device", cr_user_to_device, 2);
rb_define_method (rb_cCairo_Context, "user_to_device_distance",
cr_user_to_device_distance, 2);
rb_define_method (rb_cCairo_Context, "device_to_user", cr_device_to_user, 2);
rb_define_method (rb_cCairo_Context, "device_to_user_distance",
cr_device_to_user_distance, 2);
/* Path creation functions */
rb_define_method (rb_cCairo_Context, "new_path", cr_new_path, 0);
rb_define_method (rb_cCairo_Context, "move_to", cr_move_to, 2);
rb_define_method (rb_cCairo_Context, "new_sub_path", cr_new_sub_path, 0);
rb_define_method (rb_cCairo_Context, "line_to", cr_line_to, 2);
rb_define_method (rb_cCairo_Context, "curve_to", cr_curve_to_generic, -1);
rb_define_method (rb_cCairo_Context, "arc", cr_arc, 5);
rb_define_method (rb_cCairo_Context, "arc_negative", cr_arc_negative, 5);
rb_define_method (rb_cCairo_Context, "rel_move_to", cr_rel_move_to, 2);
rb_define_method (rb_cCairo_Context, "rel_line_to", cr_rel_line_to, 2);
rb_define_method (rb_cCairo_Context, "rel_curve_to",
cr_rel_curve_to_generic, -1);
rb_define_method (rb_cCairo_Context, "rectangle", cr_rectangle, 4);
rb_define_method (rb_cCairo_Context, "close_path", cr_close_path, 0);
#if CAIRO_CHECK_VERSION(1, 5, 8)
rb_define_method (rb_cCairo_Context, "path_extents", cr_path_extents, 0);
#endif
/* Painting functions */
rb_define_method (rb_cCairo_Context, "paint", cr_paint_generic, -1);
rb_define_method (rb_cCairo_Context, "mask", cr_mask_generic, -1);
rb_define_method (rb_cCairo_Context, "stroke", cr_stroke, -1);
rb_define_method (rb_cCairo_Context, "fill", cr_fill, -1);
rb_define_method (rb_cCairo_Context, "copy_page", cr_copy_page, 0);
rb_define_method (rb_cCairo_Context, "show_page", cr_show_page, 0);
/* Insideness testing */
rb_define_method (rb_cCairo_Context, "in_stroke?", cr_in_stroke, 2);
rb_define_method (rb_cCairo_Context, "in_fill?", cr_in_fill, 2);
#if CAIRO_CHECK_VERSION(1, 10, 0)
rb_define_method (rb_cCairo_Context, "in_clip?", cr_in_clip, 2);
#endif
/* Rectangular extents */
rb_define_method (rb_cCairo_Context, "stroke_extents", cr_stroke_extents, 0);
rb_define_method (rb_cCairo_Context, "fill_extents", cr_fill_extents, 0);
/* Clipping */
rb_define_method (rb_cCairo_Context, "reset_clip", cr_reset_clip, 0);
rb_define_method (rb_cCairo_Context, "clip", cr_clip, -1);
#if CAIRO_CHECK_VERSION(1, 3, 0)
rb_define_method (rb_cCairo_Context, "clip_extents", cr_clip_extents, 0);
rb_define_method (rb_cCairo_Context, "clip_rectangle_list",
cr_clip_rectangle_list, 0);
#endif
/* Font/Text functions */
rb_define_method (rb_cCairo_Context, "select_font_face",
cr_select_font_face, -1);
rb_define_method (rb_cCairo_Context, "set_font_size", cr_set_font_size, 1);
rb_define_method (rb_cCairo_Context, "set_font_matrix",
cr_set_font_matrix, 1);
rb_define_method (rb_cCairo_Context, "font_matrix", cr_get_font_matrix, 0);
rb_define_method (rb_cCairo_Context, "set_font_options",
cr_set_font_options, 1);
rb_define_method (rb_cCairo_Context, "font_options", cr_get_font_options, 0);
rb_define_method (rb_cCairo_Context, "set_font_face", cr_set_font_face, 1);
rb_define_method (rb_cCairo_Context, "font_face", cr_get_font_face, 0);
rb_define_method (rb_cCairo_Context, "set_scaled_font",
cr_set_scaled_font, 1);
#if CAIRO_CHECK_VERSION(1, 3, 16)
rb_define_method (rb_cCairo_Context, "scaled_font", cr_get_scaled_font, 0);
#endif
rb_define_method (rb_cCairo_Context, "show_text", cr_show_text, 1);
rb_define_method (rb_cCairo_Context, "show_glyphs", cr_show_glyphs, 1);
#if CAIRO_CHECK_VERSION(1, 8, 0)
rb_define_method (rb_cCairo_Context, "show_text_glyphs",
cr_show_text_glyphs, 4);
#endif
rb_define_method (rb_cCairo_Context, "text_path", cr_text_path, 1);
rb_define_method (rb_cCairo_Context, "glyph_path", cr_glyph_path, 1);
rb_define_method (rb_cCairo_Context, "text_extents", cr_text_extents, 1);
rb_define_method (rb_cCairo_Context, "glyph_extents", cr_glyph_extents, 1);
rb_define_method (rb_cCairo_Context, "font_extents", cr_font_extents, 0);
/* Query functions */
rb_define_method (rb_cCairo_Context, "operator", cr_get_operator, 0);
rb_define_method (rb_cCairo_Context, "source", cr_get_source, 0);
rb_define_method (rb_cCairo_Context, "tolerance", cr_get_tolerance, 0);
rb_define_method (rb_cCairo_Context, "antialias", cr_get_antialias, 0);
#if CAIRO_CHECK_VERSION(1, 5, 10)
rb_define_method (rb_cCairo_Context, "have_current_point?",
cr_has_current_point, 0);
rb_define_alias (rb_cCairo_Context,
"has_current_point?", "have_current_point?");
#endif
rb_define_method (rb_cCairo_Context, "current_point",
cr_get_current_point, 0);
rb_define_method (rb_cCairo_Context, "fill_rule", cr_get_fill_rule, 0);
rb_define_method (rb_cCairo_Context, "line_width", cr_get_line_width, 0);
rb_define_method (rb_cCairo_Context, "line_cap", cr_get_line_cap, 0);
rb_define_method (rb_cCairo_Context, "line_join", cr_get_line_join, 0);
rb_define_method (rb_cCairo_Context, "miter_limit", cr_get_miter_limit, 0);
#if CAIRO_CHECK_VERSION(1, 3, 0)
rb_define_method (rb_cCairo_Context, "dash_count", cr_get_dash_count, 0);
rb_define_method (rb_cCairo_Context, "dash", cr_get_dash, 0);
#endif
rb_define_method (rb_cCairo_Context, "matrix", cr_get_matrix, 0);
rb_define_method (rb_cCairo_Context, "target", cr_get_target, 0);
rb_define_method (rb_cCairo_Context, "group_target", cr_get_group_target, 0);
/* Paths */
rb_define_method (rb_cCairo_Context, "copy_path", cr_copy_path, 0);
rb_define_method (rb_cCairo_Context, "copy_path_flat", cr_copy_path_flat, 0);
rb_define_method (rb_cCairo_Context, "append_path", cr_copy_append_path, 1);
RB_CAIRO_DEF_SETTERS (rb_cCairo_Context);
}
cairo-1.12.8/ext/cairo/rb_cairo_io.h 0000644 0000041 0000041 00000002577 12256106703 017262 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* Copyright 2005-2010 Kouhei Sutou
*
* This file is made available under the same terms as Ruby
*
*/
#ifndef RB_CAIRO_IO_H
#define RB_CAIRO_IO_H
#include
typedef struct rb_cairo__io_callback_closure {
VALUE target;
VALUE error;
unsigned char *data;
unsigned int length;
} rb_cairo__io_callback_closure_t;
typedef struct rb_cairo__io_invoke_data {
cr_callback_func_t func;
VALUE data;
} rb_cairo__io_invoke_data_t;
RB_CAIRO_VAR ID rb_cairo__io_id_read;
RB_CAIRO_VAR ID rb_cairo__io_id_write;
RB_CAIRO_VAR ID rb_cairo__io_id_output;
rb_cairo__io_callback_closure_t *
rb_cairo__io_closure_new (VALUE target);
void rb_cairo__io_closure_destroy (rb_cairo__io_callback_closure_t *closure);
void rb_cairo__io_closure_free (void *closure);
cairo_status_t rb_cairo__io_write_func (void *write_closure,
const unsigned char *data,
unsigned int length);
cairo_status_t rb_cairo__io_read_func (void *read_closure,
unsigned char *data,
unsigned int length);
#endif
cairo-1.12.8/ext/cairo/rb_cairo_path.c 0000644 0000041 0000041 00000026476 12256106703 017606 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-04-04 03:52:31 $
*
* Copyright 2005 Kouhei Sutou
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
#define _SELF(self) (RVAL2CRPATH (self))
VALUE rb_cCairo_Point;
VALUE rb_cCairo_Path;
VALUE rb_cCairo_PathData;
VALUE rb_cCairo_PathMoveTo;
VALUE rb_cCairo_PathLineTo;
VALUE rb_cCairo_PathCurveTo;
VALUE rb_cCairo_PathClosePath;
static ID id_new, id_current_path;
static ID id_at_x, id_at_y, id_at_type, id_at_points, id_at_context;
static VALUE
cr_point_new (VALUE x, VALUE y)
{
return rb_funcall (rb_cCairo_Point, id_new, 2, x, y);
}
static VALUE
cr_point_initialize (VALUE self, VALUE x, VALUE y)
{
rb_ivar_set (self, id_at_x, x);
rb_ivar_set (self, id_at_y, y);
return Qnil;
}
static VALUE
cr_point_to_a (VALUE self)
{
return rb_ary_new3 (2,
rb_ivar_get (self, id_at_x),
rb_ivar_get (self, id_at_y));
}
static VALUE
cr_path_data_initialize (VALUE self, VALUE type, VALUE points)
{
rb_ivar_set (self, id_at_type, type);
rb_ivar_set (self, id_at_points, points);
return Qnil;
}
static VALUE
cr_path_data_move_to_p (VALUE self)
{
return CBOOL2RVAL (RVAL2CRPATHDATATYPE (rb_ivar_get (self, id_at_type)) ==
CAIRO_PATH_MOVE_TO);
}
static VALUE
cr_path_data_line_to_p (VALUE self)
{
return CBOOL2RVAL (RVAL2CRPATHDATATYPE (rb_ivar_get (self, id_at_type)) ==
CAIRO_PATH_LINE_TO);
}
static VALUE
cr_path_data_curve_to_p (VALUE self)
{
return CBOOL2RVAL (RVAL2CRPATHDATATYPE (rb_ivar_get (self, id_at_type)) ==
CAIRO_PATH_CURVE_TO);
}
static VALUE
cr_path_data_close_path_p (VALUE self)
{
return CBOOL2RVAL (RVAL2CRPATHDATATYPE (rb_ivar_get (self, id_at_type)) ==
CAIRO_PATH_CLOSE_PATH);
}
static VALUE
cr_path_data_each (VALUE self)
{
return rb_ary_each (rb_ivar_get (self, id_at_points));
}
static VALUE
cr_path_data_to_a (VALUE self)
{
return rb_ary_new3 (2,
rb_ivar_get (self, id_at_type),
rb_ivar_get (self, id_at_points));
}
static VALUE
cr_path_data_to_ruby_object (cairo_path_data_t *data)
{
VALUE rb_data = Qnil;
switch (data->header.type)
{
case CAIRO_PATH_MOVE_TO:
rb_data = rb_funcall (rb_cCairo_PathMoveTo, id_new, 2,
rb_float_new (data[1].point.x),
rb_float_new (data[1].point.y));
break;
case CAIRO_PATH_LINE_TO:
rb_data = rb_funcall (rb_cCairo_PathLineTo, id_new, 2,
rb_float_new (data[1].point.x),
rb_float_new (data[1].point.y));
break;
case CAIRO_PATH_CURVE_TO:
rb_data = rb_funcall (rb_cCairo_PathCurveTo, id_new, 6,
rb_float_new (data[1].point.x),
rb_float_new (data[1].point.y),
rb_float_new (data[2].point.x),
rb_float_new (data[2].point.y),
rb_float_new (data[3].point.x),
rb_float_new (data[3].point.y));
break;
case CAIRO_PATH_CLOSE_PATH:
rb_data = rb_funcall (rb_cCairo_PathClosePath, id_new, 0);
break;
}
return rb_data;
}
static VALUE
cr_path_move_to_initialize (int argc, VALUE *argv, VALUE self)
{
VALUE point, x, y;
VALUE super_argv[2];
rb_scan_args (argc, argv, "11", &x, &y);
if (argc == 1)
point = x;
else
point = cr_point_new (x, y);
super_argv[0] = INT2NUM (CAIRO_PATH_MOVE_TO);
super_argv[1] = rb_ary_new3 (1, point);
rb_call_super (2, super_argv);
return Qnil;
}
static VALUE
cr_path_line_to_initialize (int argc, VALUE *argv, VALUE self)
{
VALUE point, x, y;
VALUE super_argv[2];
rb_scan_args (argc, argv, "11", &x, &y);
if (argc == 1)
point = x;
else
point = cr_point_new (x, y);
super_argv[0] = INT2NUM (CAIRO_PATH_LINE_TO);
super_argv[1] = rb_ary_new3 (1, point);
rb_call_super (2, super_argv);
return Qnil;
}
static VALUE
cr_path_curve_to_initialize (int argc, VALUE *argv, VALUE self)
{
VALUE point1, point2, point3, x1, y1, x2, y2, x3, y3;
VALUE super_argv[2];
rb_scan_args (argc, argv, "33", &x1, &y1, &x2, &y2, &x3, &y3);
if (argc == 3)
{
point1 = x1;
point2 = y1;
point3 = x2;
}
else if (argc == 6)
{
point1 = cr_point_new (x1, y1);
point2 = cr_point_new (x2, y2);
point3 = cr_point_new (x3, y3);
}
else
{
VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
rb_raise (rb_eArgError,
"invalid argument: %s (expect "
"(point1, point2, point3) or "
"(x1, y1, x2, y2, x3, y3))",
StringValuePtr (inspected_arg));
}
super_argv[0] = INT2NUM (CAIRO_PATH_CURVE_TO);
super_argv[1] = rb_ary_new3 (3, point1, point2, point3);
rb_call_super (2, super_argv);
return Qnil;
}
static VALUE
cr_path_close_path_initialize (VALUE self)
{
VALUE super_argv[2];
super_argv[0] = INT2NUM (CAIRO_PATH_CLOSE_PATH);
super_argv[1] = rb_ary_new ();
rb_call_super (2, super_argv);
return Qnil;
}
static void
cr_path_free (void *ptr)
{
if (ptr)
{
cairo_path_destroy ((cairo_path_t *)ptr);
}
}
cairo_path_t *
rb_cairo_path_from_ruby_object (VALUE obj)
{
VALUE context;
cairo_t *cr;
cairo_path_t *path, *copied_path;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_Path))
{
rb_raise (rb_eTypeError, "not a cairo path");
}
Data_Get_Struct (obj, cairo_path_t, path);
context = rb_ivar_get (obj, id_at_context);
if (NIL_P (context))
return path;
cr = RVAL2CRCONTEXT (context);
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
return path;
copied_path = cairo_copy_path (cr);
rb_ivar_set (obj, id_current_path, CRPATH2RVAL (copied_path));
return copied_path;
}
static void
cr_path_ensure_internal_context (VALUE rb_path, cairo_path_t *path)
{
cairo_surface_t *surface;
cairo_t *cr;
if (!NIL_P (rb_ivar_get (rb_path, id_at_context)))
return;
surface = cairo_image_surface_create (CAIRO_FORMAT_A1, 1, 1);
cr = cairo_create (surface);
if (path->num_data > 0)
cairo_append_path (cr, path);
rb_cairo_check_status (cairo_status (cr));
rb_ivar_set (rb_path, id_at_context, CRCONTEXT2RVAL (cr));
cairo_destroy (cr);
}
VALUE
rb_cairo_path_to_ruby_object (cairo_path_t *path)
{
if (path)
{
VALUE rb_path;
rb_path = Data_Wrap_Struct (rb_cCairo_Path, NULL, cr_path_free, path);
cr_path_ensure_internal_context (rb_path, path);
return rb_path;
}
else
{
return Qnil;
}
}
static VALUE
cr_path_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, cr_path_free, NULL);
}
static VALUE
cr_path_initialize (VALUE self)
{
cairo_path_t *path;
path = ALLOC(cairo_path_t);
path->status = CAIRO_STATUS_SUCCESS;
path->data = NULL;
path->num_data = 0;
DATA_PTR (self) = path;
cr_path_ensure_internal_context (self, path);
return Qnil;
}
static VALUE
cr_path_empty_p (VALUE self)
{
cairo_path_t *path = _SELF (self);
return CBOOL2RVAL (path->num_data == 0);
}
static int
cairo_path_get_size (cairo_path_t *path)
{
int i, size;
for (i = 0, size = 0; i < path->num_data; i += path->data[i].header.length)
size++;
return size;
}
static VALUE
cr_path_size (VALUE self)
{
cairo_path_t *path = _SELF (self);
return INT2NUM (cairo_path_get_size (path));
}
static VALUE
cr_path_ref (VALUE self, VALUE index)
{
cairo_path_t *path = _SELF (self);
int i, requested_index, real_index;
requested_index = NUM2INT (index);
if (requested_index < 0)
{
requested_index += cairo_path_get_size (path);
if (requested_index < 0)
return Qnil;
}
for (i = 0, real_index = 0; i < requested_index; i++)
{
if (real_index >= path->num_data)
return Qnil;
real_index += path->data[real_index].header.length;
}
if (real_index < path->num_data)
return cr_path_data_to_ruby_object (&path->data[real_index]);
else
return Qnil;
}
static VALUE
cr_path_each (VALUE self)
{
cairo_path_t *path = _SELF(self);
int i;
for (i = 0; i < path->num_data; i += path->data[i].header.length)
{
rb_yield (cr_path_data_to_ruby_object (&(path->data[i])));
}
return self;
}
void
Init_cairo_path (void)
{
id_new = rb_intern ("new");
id_current_path = rb_intern ("current_path");
id_at_x = rb_intern ("@x");
id_at_y = rb_intern ("@y");
id_at_type = rb_intern ("@type");
id_at_points = rb_intern ("@points");
id_at_context = rb_intern ("@context");
rb_cCairo_Point = rb_define_class_under (rb_mCairo, "Point", rb_cObject);
rb_define_attr (rb_cCairo_Point, "x", CR_TRUE, CR_FALSE);
rb_define_attr (rb_cCairo_Point, "y", CR_TRUE, CR_FALSE);
rb_define_method (rb_cCairo_Point, "initialize", cr_point_initialize, 2);
rb_define_method (rb_cCairo_Point, "to_a", cr_point_to_a, 0);
rb_define_alias (rb_cCairo_Point, "to_ary", "to_a");
rb_cCairo_PathData = rb_define_class_under (rb_mCairo, "PathData", rb_cObject);
rb_include_module (rb_cCairo_PathData, rb_mEnumerable);
rb_define_attr (rb_cCairo_PathData, "type", CR_TRUE, CR_FALSE);
rb_define_attr (rb_cCairo_PathData, "points", CR_TRUE, CR_FALSE);
rb_define_method (rb_cCairo_PathData, "initialize",
cr_path_data_initialize, 2);
rb_define_method (rb_cCairo_PathData, "move_to?", cr_path_data_move_to_p, 0);
rb_define_method (rb_cCairo_PathData, "line_to?", cr_path_data_line_to_p, 0);
rb_define_method (rb_cCairo_PathData, "curve_to?",
cr_path_data_curve_to_p, 0);
rb_define_method (rb_cCairo_PathData, "close_path?",
cr_path_data_close_path_p, 0);
rb_define_method (rb_cCairo_PathData, "each", cr_path_data_each, 0);
rb_define_method (rb_cCairo_PathData, "to_a", cr_path_data_to_a, 0);
rb_define_alias (rb_cCairo_PathData, "to_ary", "to_a");
rb_cCairo_PathMoveTo =
rb_define_class_under (rb_mCairo, "PathMoveTo", rb_cCairo_PathData);
rb_define_method (rb_cCairo_PathMoveTo, "initialize",
cr_path_move_to_initialize, -1);
rb_cCairo_PathLineTo =
rb_define_class_under (rb_mCairo, "PathLineTo", rb_cCairo_PathData);
rb_define_method (rb_cCairo_PathLineTo, "initialize",
cr_path_line_to_initialize, -1);
rb_cCairo_PathCurveTo =
rb_define_class_under (rb_mCairo, "PathCurveTo", rb_cCairo_PathData);
rb_define_method (rb_cCairo_PathCurveTo, "initialize",
cr_path_curve_to_initialize, -1);
rb_cCairo_PathClosePath =
rb_define_class_under (rb_mCairo, "PathClosePath", rb_cCairo_PathData);
rb_define_method (rb_cCairo_PathClosePath, "initialize",
cr_path_close_path_initialize, 0);
rb_cCairo_Path = rb_define_class_under (rb_mCairo, "Path", rb_cObject);
rb_define_alloc_func (rb_cCairo_Path, cr_path_allocate);
rb_include_module (rb_cCairo_Path, rb_mEnumerable);
rb_define_method (rb_cCairo_Path, "initialize", cr_path_initialize, 0);
rb_define_method (rb_cCairo_Path, "empty?", cr_path_empty_p, 0);
rb_define_method (rb_cCairo_Path, "size", cr_path_size, 0);
rb_define_alias (rb_cCairo_Path, "length", "size");
rb_define_method (rb_cCairo_Path, "[]", cr_path_ref, 1);
rb_define_method (rb_cCairo_Path, "each", cr_path_each, 0);
}
cairo-1.12.8/ext/cairo/rb_cairo_font_face.c 0000644 0000041 0000041 00000047410 12256106703 020565 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-09-26 14:13:58 $
*
* Copyright 2005 Øyvind Kolås
* Copyright 2004-2005 MenTaLguY
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
VALUE rb_cCairo_FontFace;
VALUE rb_cCairo_ToyFontFace = Qnil;
VALUE rb_cCairo_UserFontFace = Qnil;
VALUE rb_cCairo_UserFontFace_TextToGlyphsData = Qnil;
#if CAIRO_CHECK_VERSION(1, 7, 6)
static cairo_user_data_key_t ruby_object_key;
static ID cr_id_call;
static ID cr_id_new;
static ID cr_id_init;
static ID cr_id_render_glyph;
static ID cr_id_text_to_glyphs;
static ID cr_id_unicode_to_glyph;
static ID cr_id_at_glyphs;
static ID cr_id_at_clusters;
static ID cr_id_at_cluster_flags;
static ID cr_id_at_need_glyphs;
static ID cr_id_at_need_clusters;
static ID cr_id_at_need_cluster_flags;
#endif
#define _SELF (RVAL2CRFONTFACE(self))
static inline void
cr_font_face_check_status (cairo_font_face_t *face)
{
rb_cairo_check_status (cairo_font_face_status (face));
}
cairo_font_face_t *
rb_cairo_font_face_from_ruby_object (VALUE obj)
{
cairo_font_face_t *face;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_FontFace))
{
rb_raise (rb_eTypeError,
"not a cairo font face: %s",
rb_cairo__inspect (obj));
}
Data_Get_Struct (obj, cairo_font_face_t, face);
if (!face)
rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
cr_font_face_check_status (face);
return face;
}
static void
cr_font_face_free (void *ptr)
{
if (ptr)
{
cairo_font_face_t *face = ptr;
cairo_font_face_destroy (face);
}
}
VALUE
rb_cairo_font_face_to_ruby_object (cairo_font_face_t *face)
{
if (face)
{
VALUE klass;
switch (cairo_font_face_get_type (face))
{
#if CAIRO_CHECK_VERSION(1, 7, 6)
case CAIRO_FONT_TYPE_TOY:
klass = rb_cCairo_ToyFontFace;
break;
case CAIRO_FONT_TYPE_USER:
klass = rb_cCairo_UserFontFace;
break;
#endif
default:
klass = rb_cCairo_FontFace;
break;
}
cairo_font_face_reference (face);
return Data_Wrap_Struct (klass, NULL, cr_font_face_free, face);
}
else
{
return Qnil;
}
}
static VALUE
cr_font_face_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, cr_font_face_free, NULL);
}
#if CAIRO_CHECK_VERSION(1, 7, 6)
static VALUE
cr_toy_font_face_initialize (int argc, VALUE *argv, VALUE self)
{
cairo_font_face_t *face;
VALUE rb_family, rb_slant, rb_weight;
const char *family;
cairo_font_slant_t slant;
cairo_font_weight_t weight;
rb_scan_args (argc, argv, "03", &rb_family, &rb_slant, &rb_weight);
if (NIL_P (rb_family))
{
family = "";
}
else if (rb_cairo__is_kind_of (rb_family, rb_cString))
{
family = RSTRING_PTR (rb_family);
}
else if (rb_cairo__is_kind_of (rb_family, rb_cSymbol))
{
family = rb_id2name (SYM2ID (rb_family));
}
else
{
rb_raise (rb_eArgError,
"family name should be nil, String or Symbol: %s",
rb_cairo__inspect (rb_family));
}
if (NIL_P (rb_slant))
slant = CAIRO_FONT_SLANT_NORMAL;
else
slant = RVAL2CRFONTSLANT (rb_slant);
if (NIL_P (rb_weight))
weight = CAIRO_FONT_WEIGHT_NORMAL;
else
weight = RVAL2CRFONTWEIGHT (rb_weight);
face = cairo_toy_font_face_create (family, slant, weight);
cr_font_face_check_status (face);
DATA_PTR (self) = face;
return Qnil;
}
static VALUE
cr_toy_font_face_get_family (VALUE self)
{
return CSTR2RVAL (cairo_toy_font_face_get_family (_SELF));
}
static VALUE
cr_toy_font_face_get_slant (VALUE self)
{
return INT2NUM (cairo_toy_font_face_get_slant (_SELF));
}
static VALUE
cr_toy_font_face_get_weight (VALUE self)
{
return INT2NUM (cairo_toy_font_face_get_weight (_SELF));
}
typedef struct cr_user_font_face_invoke_data
{
VALUE receiver;
ID method;
int argc;
VALUE *argv;
cairo_status_t *status;
VALUE result;
cr_callback_func_t after_hook;
void *after_hook_data;
} cr_user_font_face_invoke_data_t;
static VALUE
cr_user_font_face_invoke_body (VALUE user_data)
{
cr_user_font_face_invoke_data_t *data;
VALUE result;
data = (cr_user_font_face_invoke_data_t *)user_data;
result = rb_funcall2 (data->receiver, data->method, data->argc, data->argv);
data->result = result;
if (data->after_hook)
result = data->after_hook(user_data);
return result;
}
static VALUE
cr_user_font_face_invoke_rescue (VALUE user_data, VALUE exception)
{
cr_user_font_face_invoke_data_t *data;
data = (cr_user_font_face_invoke_data_t *)user_data;
*(data->status) = rb_cairo__exception_to_status (exception);
if (*(data->status) == (cairo_status_t)-1)
rb_exc_raise (exception);
return Qnil;
}
static VALUE
cr_user_font_face_invoke_func (VALUE user_data)
{
return rb_rescue2 (cr_user_font_face_invoke_body, user_data,
cr_user_font_face_invoke_rescue, user_data, rb_eException,
(VALUE)0);
}
static VALUE
cr_user_font_face_init_func_after (VALUE user_data)
{
cr_user_font_face_invoke_data_t *data;
cairo_font_extents_t *extents;
data = (cr_user_font_face_invoke_data_t *)user_data;
extents = data->after_hook_data;
*extents = *(RVAL2CRFONTEXTENTS (data->argv[2]));
return data->result;
}
static cairo_status_t
cr_user_font_face_init_func (cairo_scaled_font_t *scaled_font,
cairo_t *cr, cairo_font_extents_t *extents)
{
cairo_status_t status = CAIRO_STATUS_SUCCESS;
cairo_font_face_t *face;
VALUE self;
VALUE receiver = Qnil;
ID id_method_name = cr_id_call;
face = cairo_scaled_font_get_font_face (scaled_font);
self = (VALUE)cairo_font_face_get_user_data (face, &ruby_object_key);
receiver = rb_ivar_get (self, cr_id_init);
if (NIL_P (receiver) && rb_obj_respond_to (self, cr_id_init, Qtrue))
{
receiver = self;
id_method_name = cr_id_init;
}
if (!NIL_P (receiver))
{
cr_user_font_face_invoke_data_t data;
VALUE argv[3];
argv[0] = CRSCALEDFONT2RVAL (scaled_font);
argv[1] = CRCONTEXT2RVAL (cr);
argv[2] = CRFONTEXTENTS2RVAL (extents);
data.receiver = receiver;
data.method = id_method_name;
data.argc = 3;
data.argv = argv;
data.status = &status;
data.after_hook = cr_user_font_face_init_func_after;
data.after_hook_data = extents;
rb_cairo__invoke_callback (cr_user_font_face_invoke_func, (VALUE)&data);
}
return status;
}
static VALUE
cr_user_font_face_render_glyph_func_after (VALUE user_data)
{
cr_user_font_face_invoke_data_t *data;
cairo_text_extents_t *extents;
data = (cr_user_font_face_invoke_data_t *)user_data;
extents = data->after_hook_data;
*extents = *(RVAL2CRTEXTEXTENTS (data->argv[3]));
return data->result;
}
static cairo_status_t
cr_user_font_face_render_glyph_func (cairo_scaled_font_t *scaled_font,
unsigned long glyph,
cairo_t *cr,
cairo_text_extents_t *extents)
{
cairo_status_t status = CAIRO_STATUS_SUCCESS;
cairo_font_face_t *face;
VALUE self;
VALUE receiver = Qnil;
ID id_method_name = cr_id_call;
face = cairo_scaled_font_get_font_face (scaled_font);
self = (VALUE)cairo_font_face_get_user_data (face, &ruby_object_key);
receiver = rb_ivar_get (self, cr_id_render_glyph);
if (NIL_P (receiver) && rb_obj_respond_to (self, cr_id_render_glyph, Qtrue))
{
receiver = self;
id_method_name = cr_id_render_glyph;
}
if (!NIL_P (receiver))
{
cr_user_font_face_invoke_data_t data;
VALUE argv[4];
argv[0] = CRSCALEDFONT2RVAL (scaled_font);
argv[1] = ULONG2NUM (glyph);
argv[2] = CRCONTEXT2RVAL (cr);
argv[3] = CRTEXTEXTENTS2RVAL (extents);
data.receiver = receiver;
data.method = id_method_name;
data.argc = 4;
data.argv = argv;
data.status = &status;
data.after_hook = cr_user_font_face_render_glyph_func_after;
data.after_hook_data = extents;
rb_cairo__invoke_callback (cr_user_font_face_invoke_func, (VALUE)&data);
}
return status;
}
typedef struct _cr_text_to_glyphs_after_hook_data {
VALUE text_to_glyphs_data;
cairo_glyph_t **glyphs;
int *num_glyphs;
cairo_text_cluster_t **clusters;
int *num_clusters;
cairo_text_cluster_flags_t *cluster_flags;
} cr_text_to_glyphs_after_hook_data_t;
static VALUE
cr_user_font_face_text_to_glyphs_func_after (VALUE user_data)
{
cr_user_font_face_invoke_data_t *data;
cr_text_to_glyphs_after_hook_data_t *after_hook_data;
VALUE text_to_glyphs_data;
data = (cr_user_font_face_invoke_data_t *)user_data;
after_hook_data = data->after_hook_data;
text_to_glyphs_data = after_hook_data->text_to_glyphs_data;
if (after_hook_data->glyphs)
{
VALUE rb_glyphs;
rb_glyphs = rb_ivar_get (text_to_glyphs_data, cr_id_at_glyphs);
rb_cairo__glyphs_from_ruby_object (rb_glyphs,
after_hook_data->glyphs,
after_hook_data->num_glyphs);
}
if (after_hook_data->clusters)
{
VALUE rb_clusters;
rb_clusters = rb_ivar_get (text_to_glyphs_data, cr_id_at_clusters);
rb_cairo__text_clusters_from_ruby_object (rb_clusters,
after_hook_data->clusters,
after_hook_data->num_clusters);
}
if (after_hook_data->cluster_flags)
{
VALUE rb_cluster_flags;
rb_cluster_flags = rb_ivar_get (text_to_glyphs_data,
cr_id_at_cluster_flags);
*(after_hook_data->cluster_flags) =
RVAL2CRTEXTCLUSTERFLAGS (rb_cluster_flags);
}
return data->result;
}
static cairo_status_t
cr_user_font_face_text_to_glyphs_func (cairo_scaled_font_t *scaled_font,
const char *utf8, int utf8_len,
cairo_glyph_t **glyphs, int *num_glyphs,
cairo_text_cluster_t **clusters,
int *num_clusters,
cairo_text_cluster_flags_t *cluster_flags)
{
cairo_status_t status = CAIRO_INT_STATUS_UNSUPPORTED;
cairo_font_face_t *face;
VALUE self;
VALUE receiver = Qnil;
ID id_method_name = cr_id_call;
face = cairo_scaled_font_get_font_face (scaled_font);
self = (VALUE)cairo_font_face_get_user_data (face, &ruby_object_key);
receiver = rb_ivar_get (self, cr_id_text_to_glyphs);
if (NIL_P (receiver) && rb_obj_respond_to (self, cr_id_text_to_glyphs, Qtrue))
{
receiver = self;
id_method_name = cr_id_text_to_glyphs;
}
if (NIL_P (receiver))
{
if (num_glyphs)
*num_glyphs = -1;
}
else
{
cr_user_font_face_invoke_data_t data;
cr_text_to_glyphs_after_hook_data_t after_hook_data;
VALUE text_to_glyphs_data;
VALUE argv[3];
argv[0] = CRSCALEDFONT2RVAL (scaled_font);
argv[1] = rb_str_new (utf8, utf8_len);
text_to_glyphs_data = rb_funcall (rb_cCairo_UserFontFace_TextToGlyphsData,
cr_id_new,
3,
CBOOL2RVAL (glyphs != NULL),
CBOOL2RVAL (clusters != NULL),
CBOOL2RVAL (cluster_flags != NULL));
argv[2] = text_to_glyphs_data;
data.receiver = receiver;
data.method = id_method_name;
data.argc = 3;
data.argv = argv;
data.status = &status;
data.after_hook = cr_user_font_face_text_to_glyphs_func_after;
data.after_hook_data = &after_hook_data;
after_hook_data.text_to_glyphs_data = text_to_glyphs_data;
after_hook_data.glyphs = glyphs;
after_hook_data.num_glyphs = num_glyphs;
after_hook_data.clusters = clusters;
after_hook_data.num_clusters = num_clusters;
after_hook_data.cluster_flags = cluster_flags;
rb_cairo__invoke_callback (cr_user_font_face_invoke_func, (VALUE)&data);
}
return status;
}
static VALUE
cr_user_font_face_unicode_to_glyph_func_after (VALUE user_data)
{
cr_user_font_face_invoke_data_t *data;
unsigned long *glyph_index;
data = (cr_user_font_face_invoke_data_t *)user_data;
glyph_index = data->after_hook_data;
*glyph_index = NUM2ULONG (data->result);
return data->result;
}
static cairo_status_t
cr_user_font_face_unicode_to_glyph_func (cairo_scaled_font_t *scaled_font,
unsigned long unicode,
unsigned long *glyph_index)
{
cairo_status_t status = CAIRO_STATUS_SUCCESS;
cairo_font_face_t *face;
VALUE self;
VALUE receiver = Qnil;
ID id_method_name = cr_id_call;
face = cairo_scaled_font_get_font_face (scaled_font);
self = (VALUE)cairo_font_face_get_user_data (face, &ruby_object_key);
receiver = rb_ivar_get (self, cr_id_unicode_to_glyph);
if (NIL_P (receiver) &&
rb_obj_respond_to (self, cr_id_unicode_to_glyph, Qtrue))
{
receiver = self;
id_method_name = cr_id_unicode_to_glyph;
}
if (NIL_P (receiver))
{
*glyph_index = unicode;
}
else
{
cr_user_font_face_invoke_data_t data;
VALUE argv[2];
argv[0] = CRSCALEDFONT2RVAL (scaled_font);
argv[1] = ULONG2NUM (unicode);
data.receiver = receiver;
data.method = id_method_name;
data.argc = 2;
data.argv = argv;
data.status = &status;
data.after_hook = cr_user_font_face_unicode_to_glyph_func_after;
data.after_hook_data = glyph_index;
rb_cairo__invoke_callback (cr_user_font_face_invoke_func, (VALUE)&data);
}
return status;
}
static VALUE
cr_user_font_face_initialize (VALUE self)
{
cairo_font_face_t *face;
face = cairo_user_font_face_create ();
cr_font_face_check_status (face);
cairo_font_face_set_user_data (face, &ruby_object_key, (void *)self, NULL);
cairo_user_font_face_set_init_func
(face, cr_user_font_face_init_func);
cairo_user_font_face_set_render_glyph_func
(face, cr_user_font_face_render_glyph_func);
cairo_user_font_face_set_text_to_glyphs_func
(face, cr_user_font_face_text_to_glyphs_func);
cairo_user_font_face_set_unicode_to_glyph_func
(face, cr_user_font_face_unicode_to_glyph_func);
rb_ivar_set (self, cr_id_init, Qnil);
rb_ivar_set (self, cr_id_render_glyph, Qnil);
rb_ivar_set (self, cr_id_text_to_glyphs, Qnil);
rb_ivar_set (self, cr_id_unicode_to_glyph, Qnil);
DATA_PTR (self) = face;
return Qnil;
}
static VALUE
cr_user_font_face_on_init (VALUE self)
{
rb_ivar_set (self, cr_id_init, rb_block_proc ());
return self;
}
static VALUE
cr_user_font_face_on_render_glyph (VALUE self)
{
rb_ivar_set (self, cr_id_render_glyph, rb_block_proc ());
return self;
}
static VALUE
cr_user_font_face_on_text_to_glyphs (VALUE self)
{
rb_ivar_set (self, cr_id_text_to_glyphs, rb_block_proc ());
return self;
}
static VALUE
cr_user_font_face_on_unicode_to_glyph (VALUE self)
{
rb_ivar_set (self, cr_id_unicode_to_glyph, rb_block_proc ());
return self;
}
static VALUE
cr_text_to_glyphs_data_initialize (VALUE self,
VALUE need_glyphs, VALUE need_clusters,
VALUE need_cluster_flags)
{
rb_ivar_set (self, cr_id_at_glyphs, Qnil);
rb_ivar_set (self, cr_id_at_clusters, Qnil);
rb_ivar_set (self, cr_id_at_cluster_flags, INT2NUM (0));
rb_ivar_set (self, cr_id_at_need_glyphs, need_glyphs);
rb_ivar_set (self, cr_id_at_need_clusters, need_clusters);
rb_ivar_set (self, cr_id_at_need_cluster_flags, need_cluster_flags);
return Qnil;
}
static VALUE
cr_text_to_glyphs_data_get_cluster_flags (VALUE self)
{
return rb_ivar_get (self, cr_id_at_cluster_flags);
}
static VALUE
cr_text_to_glyphs_data_set_cluster_flags (VALUE self, VALUE cluster_flags)
{
rb_ivar_set (self, cr_id_at_cluster_flags,
INT2NUM (RVAL2CRTEXTCLUSTERFLAGS (cluster_flags)));
return Qnil;
}
static VALUE
cr_text_to_glyphs_data_need_glyphs (VALUE self)
{
return rb_ivar_get (self, cr_id_at_need_glyphs);
}
static VALUE
cr_text_to_glyphs_data_need_clusters (VALUE self)
{
return rb_ivar_get (self, cr_id_at_need_clusters);
}
static VALUE
cr_text_to_glyphs_data_need_cluster_flags (VALUE self)
{
return rb_ivar_get (self, cr_id_at_need_cluster_flags);
}
#endif
void
Init_cairo_font (void)
{
#if CAIRO_CHECK_VERSION(1, 7, 6)
cr_id_call = rb_intern ("call");
cr_id_new = rb_intern ("new");
cr_id_init = rb_intern ("init");
cr_id_render_glyph = rb_intern ("render_glyph");
cr_id_text_to_glyphs = rb_intern ("text_to_glyphs");
cr_id_unicode_to_glyph = rb_intern ("unicode_to_glyph");
cr_id_at_glyphs = rb_intern ("@glyphs");
cr_id_at_clusters = rb_intern ("@clusters");
cr_id_at_cluster_flags = rb_intern ("@cluster_flags");
cr_id_at_need_glyphs = rb_intern ("@need_glyphs");
cr_id_at_need_clusters = rb_intern ("@need_clusters");
cr_id_at_need_cluster_flags = rb_intern ("@need_cluster_flags");
#endif
rb_cCairo_FontFace =
rb_define_class_under (rb_mCairo, "FontFace", rb_cObject);
rb_define_alloc_func (rb_cCairo_FontFace, cr_font_face_allocate);
#if CAIRO_CHECK_VERSION(1, 7, 6)
rb_cCairo_ToyFontFace =
rb_define_class_under (rb_mCairo, "ToyFontFace", rb_cCairo_FontFace);
rb_define_method (rb_cCairo_ToyFontFace, "initialize",
cr_toy_font_face_initialize, -1);
rb_define_method (rb_cCairo_ToyFontFace, "family",
cr_toy_font_face_get_family, 0);
rb_define_method (rb_cCairo_ToyFontFace, "slant",
cr_toy_font_face_get_slant, 0);
rb_define_method (rb_cCairo_ToyFontFace, "weight",
cr_toy_font_face_get_weight, 0);
rb_cCairo_UserFontFace =
rb_define_class_under (rb_mCairo, "UserFontFace", rb_cCairo_FontFace);
rb_define_method (rb_cCairo_UserFontFace, "initialize",
cr_user_font_face_initialize, 0);
rb_define_method (rb_cCairo_UserFontFace, "on_init",
cr_user_font_face_on_init, 0);
rb_define_method (rb_cCairo_UserFontFace, "on_render_glyph",
cr_user_font_face_on_render_glyph, 0);
rb_define_method (rb_cCairo_UserFontFace, "on_text_to_glyphs",
cr_user_font_face_on_text_to_glyphs, 0);
rb_define_method (rb_cCairo_UserFontFace, "on_unicode_to_glyph",
cr_user_font_face_on_unicode_to_glyph, 0);
rb_cCairo_UserFontFace_TextToGlyphsData =
rb_define_class_under (rb_cCairo_UserFontFace,
"TextToGlyphsData", rb_cObject);
rb_attr (rb_cCairo_UserFontFace_TextToGlyphsData, rb_intern ("glyphs"),
CR_TRUE, CR_TRUE, CR_TRUE);
rb_attr (rb_cCairo_UserFontFace_TextToGlyphsData, rb_intern ("clusters"),
CR_TRUE, CR_TRUE, CR_TRUE);
rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
"initialize", cr_text_to_glyphs_data_initialize, 3);
rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
"cluster_flags",
cr_text_to_glyphs_data_get_cluster_flags, 0);
rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
"cluster_flags=",
cr_text_to_glyphs_data_set_cluster_flags, 1);
rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
"need_glyphs?", cr_text_to_glyphs_data_need_glyphs, 0);
rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
"need_clusters?", cr_text_to_glyphs_data_need_clusters, 0);
rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
"need_cluster_flags?",
cr_text_to_glyphs_data_need_cluster_flags, 0);
RB_CAIRO_DEF_SETTERS (rb_cCairo_UserFontFace_TextToGlyphsData);
#endif
}
cairo-1.12.8/ext/cairo/rb_cairo_text_cluster.c 0000644 0000041 0000041 00000007000 12256106703 021355 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-08-16 08:16:40 $
*
* Copyright 2008 Kouhei Sutou
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
VALUE rb_cCairo_TextCluster = Qnil;
#if CAIRO_CHECK_VERSION(1, 7, 2)
#define _SELF(self) (RVAL2CRTEXTCLUSTER(self))
cairo_text_cluster_t *
rb_cairo_text_cluster_from_ruby_object (VALUE obj)
{
cairo_text_cluster_t *cluster;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_TextCluster))
{
rb_raise (rb_eTypeError,
"not a cairo cluster: %s", rb_cairo__inspect (obj));
}
Data_Get_Struct (obj, cairo_text_cluster_t, cluster);
return cluster;
}
static void
cr_text_cluster_free (void *ptr)
{
if (ptr)
{
xfree (ptr);
}
}
VALUE
rb_cairo_text_cluster_to_ruby_object (cairo_text_cluster_t *cluster)
{
if (cluster)
{
cairo_text_cluster_t *new_cluster;
new_cluster = ALLOC (cairo_text_cluster_t);
*new_cluster = *cluster;
return Data_Wrap_Struct (rb_cCairo_TextCluster, NULL,
cr_text_cluster_free, new_cluster);
}
else
{
return Qnil;
}
}
static VALUE
cr_text_cluster_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, cr_text_cluster_free, NULL);
}
static VALUE
cr_text_cluster_initialize (VALUE self, VALUE num_bytes, VALUE num_glyphs)
{
cairo_text_cluster_t *cluster;
cluster = ALLOC (cairo_text_cluster_t);
cluster->num_bytes = NUM2INT (num_bytes);
cluster->num_glyphs = NUM2INT (num_glyphs);
DATA_PTR (self) = cluster;
return Qnil;
}
static VALUE
cr_text_cluster_num_bytes (VALUE self)
{
return INT2NUM (_SELF(self)->num_bytes);
}
static VALUE
cr_text_cluster_num_glyphs (VALUE self)
{
return INT2NUM (_SELF(self)->num_glyphs);
}
static VALUE
cr_text_cluster_set_num_bytes (VALUE self, VALUE num_bytes)
{
_SELF(self)->num_bytes = NUM2INT (num_bytes);
return self;
}
static VALUE
cr_text_cluster_set_num_glyphs (VALUE self, VALUE num_glyphs)
{
_SELF(self)->num_glyphs = NUM2INT (num_glyphs);
return self;
}
static VALUE
cr_text_cluster_to_s (VALUE self)
{
VALUE ret;
ret = rb_str_new2 ("#<");
rb_str_cat2 (ret, rb_class2name (CLASS_OF (self)));
rb_str_cat2 (ret, ": ");
rb_str_cat2 (ret, "num_bytes=");
rb_str_concat (ret, rb_inspect (cr_text_cluster_num_bytes (self)));
rb_str_cat2 (ret, ", ");
rb_str_cat2 (ret, "num_glyphs=");
rb_str_concat (ret, rb_inspect (cr_text_cluster_num_glyphs (self)));
rb_str_cat2 (ret, ">");
return ret;
}
#endif
void
Init_cairo_text_cluster (void)
{
#if CAIRO_CHECK_VERSION(1, 7, 2)
rb_cCairo_TextCluster = rb_define_class_under (rb_mCairo, "TextCluster", rb_cObject);
rb_define_alloc_func (rb_cCairo_TextCluster, cr_text_cluster_allocate);
rb_define_method (rb_cCairo_TextCluster, "initialize",
cr_text_cluster_initialize, 2);
rb_define_method (rb_cCairo_TextCluster, "num_bytes",
cr_text_cluster_num_bytes, 0);
rb_define_method (rb_cCairo_TextCluster, "num_glyphs",
cr_text_cluster_num_glyphs, 0);
rb_define_method (rb_cCairo_TextCluster, "set_num_bytes",
cr_text_cluster_set_num_bytes, 1);
rb_define_method (rb_cCairo_TextCluster, "set_num_glyphs",
cr_text_cluster_set_num_glyphs, 1);
rb_define_method (rb_cCairo_TextCluster, "to_s", cr_text_cluster_to_s, 0);
RB_CAIRO_DEF_SETTERS (rb_cCairo_TextCluster);
#endif
}
cairo-1.12.8/ext/cairo/rb_cairo_matrix.c 0000644 0000041 0000041 00000020773 12256106703 020150 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-08-14 12:37:50 $
*
* Copyright 2006-2008 Kouhei Sutou
* Copyright 2005 Øyvind Kolås
* Copyright 2004-2005 MenTaLguY
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
VALUE rb_cCairo_Matrix;
static ID cr_id_equal;
#define _SELF (RVAL2CRMATRIX(self))
cairo_matrix_t *
rb_cairo_matrix_from_ruby_object (VALUE obj)
{
cairo_matrix_t *matrix;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_Matrix))
{
rb_raise (rb_eTypeError, "not a cairo matrix");
}
Data_Get_Struct (obj, cairo_matrix_t, matrix);
return matrix;
}
static void
cr_matrix_free (void *ptr)
{
if (ptr)
{
xfree ((cairo_matrix_t *) ptr);
}
}
VALUE
rb_cairo_matrix_to_ruby_object (cairo_matrix_t *matrix)
{
if (matrix)
{
cairo_matrix_t *new_matrix = ALLOC (cairo_matrix_t);
*new_matrix = *matrix;
return Data_Wrap_Struct (rb_cCairo_Matrix, NULL,
cr_matrix_free, new_matrix);
}
else
{
return Qnil;
}
}
static VALUE
cr_matrix_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, cr_matrix_free, NULL);
}
static VALUE
cr_matrix_initialize (VALUE self,
VALUE xx, VALUE yx,
VALUE xy, VALUE yy,
VALUE x0, VALUE y0)
{
cairo_matrix_t *matrix = ALLOC (cairo_matrix_t);
cairo_matrix_init (matrix,
NUM2DBL (xx), NUM2DBL (yx),
NUM2DBL (xy), NUM2DBL (yy),
NUM2DBL (x0), NUM2DBL (y0));
DATA_PTR (self) = matrix;
return Qnil;
}
static VALUE
cr_matrix_init_identity (VALUE self)
{
cairo_matrix_t matrix;
cairo_matrix_init_identity (&matrix);
return CRMATRIX2RVAL (&matrix);
}
static VALUE
cr_matrix_init_translate (VALUE self, VALUE tx, VALUE ty)
{
cairo_matrix_t matrix;
cairo_matrix_init_translate (&matrix, NUM2DBL (tx), NUM2DBL (ty));
return CRMATRIX2RVAL (&matrix);
}
static VALUE
cr_matrix_init_scale (VALUE self, VALUE sx, VALUE sy)
{
cairo_matrix_t matrix;
cairo_matrix_init_scale (&matrix, NUM2DBL (sx), NUM2DBL (sy));
return CRMATRIX2RVAL (&matrix);
}
static VALUE
cr_matrix_init_rotate (VALUE self, VALUE radius)
{
cairo_matrix_t matrix;
cairo_matrix_init_rotate (&matrix, NUM2DBL (radius));
return CRMATRIX2RVAL (&matrix);
}
static VALUE
cr_matrix_identity (VALUE self)
{
cairo_matrix_init_identity (_SELF);
return self;
}
static VALUE
cr_matrix_translate (VALUE self, VALUE tx, VALUE ty)
{
cairo_matrix_translate (_SELF, NUM2DBL (tx), NUM2DBL (ty));
return self;
}
static VALUE
cr_matrix_scale (VALUE self, VALUE sx, VALUE sy)
{
cairo_matrix_scale (_SELF, NUM2DBL (sx), NUM2DBL (sy));
return self;
}
static VALUE
cr_matrix_rotate (VALUE self, VALUE radians)
{
cairo_matrix_rotate (_SELF, NUM2DBL (radians));
return self;
}
static VALUE
cr_matrix_invert (VALUE self)
{
rb_cairo_check_status (cairo_matrix_invert (_SELF));
return self;
}
static VALUE
cr_matrix_multiply (VALUE self, VALUE other)
{
cairo_matrix_multiply (_SELF, _SELF, RVAL2CRMATRIX (other));
return self;
}
static VALUE
cr_matrix_transform_distance (VALUE self, VALUE dx, VALUE dy)
{
double pair[2];
pair[0] = NUM2DBL (dx);
pair[1] = NUM2DBL (dy);
cairo_matrix_transform_distance (_SELF, pair, pair + 1);
return rb_cairo__float_array (pair, 2);
}
static VALUE
cr_matrix_transform_point (VALUE self, VALUE x, VALUE y)
{
double pair[2];
pair[0] = NUM2DBL (x);
pair[1] = NUM2DBL (y);
cairo_matrix_transform_point (_SELF, pair, pair + 1);
return rb_cairo__float_array (pair, 2);
}
/* Accessors */
static VALUE
cr_matrix_get_xx (VALUE self)
{
return rb_float_new (_SELF->xx);
}
static VALUE
cr_matrix_set_xx (VALUE self, VALUE xx)
{
_SELF->xx = NUM2DBL (xx);
return Qnil;
}
static VALUE
cr_matrix_get_yx (VALUE self)
{
return rb_float_new (_SELF->yx);
}
static VALUE
cr_matrix_set_yx (VALUE self, VALUE yx)
{
_SELF->yx = NUM2DBL (yx);
return Qnil;
}
static VALUE
cr_matrix_get_xy (VALUE self)
{
return rb_float_new (_SELF->xy);
}
static VALUE
cr_matrix_set_xy (VALUE self, VALUE xy)
{
_SELF->xy = NUM2DBL (xy);
return Qnil;
}
static VALUE
cr_matrix_get_yy (VALUE self)
{
return rb_float_new (_SELF->yy);
}
static VALUE
cr_matrix_set_yy (VALUE self, VALUE yy)
{
_SELF->yy = NUM2DBL (yy);
return Qnil;
}
static VALUE
cr_matrix_get_x0 (VALUE self)
{
return rb_float_new (_SELF->x0);
}
static VALUE
cr_matrix_set_x0 (VALUE self, VALUE x0)
{
_SELF->x0 = NUM2DBL (x0);
return Qnil;
}
static VALUE
cr_matrix_get_y0 (VALUE self)
{
return rb_float_new (_SELF->y0);
}
static VALUE
cr_matrix_set_y0 (VALUE self, VALUE y0)
{
_SELF->y0 = NUM2DBL (y0);
return Qnil;
}
/* Utilities */
static VALUE
cr_matrix_set (VALUE self,
VALUE xx, VALUE yx,
VALUE xy, VALUE yy,
VALUE x0, VALUE y0)
{
cairo_matrix_init (_SELF,
NUM2DBL (xx), NUM2DBL (yx),
NUM2DBL (xy), NUM2DBL (yy),
NUM2DBL (x0), NUM2DBL (y0));
return self;
}
static VALUE
cr_matrix_to_a (VALUE self)
{
cairo_matrix_t *matrix = _SELF;
double affine[6];
affine[0] = matrix->xx;
affine[1] = matrix->yx;
affine[2] = matrix->xy;
affine[3] = matrix->yy;
affine[4] = matrix->x0;
affine[5] = matrix->y0;
return rb_cairo__float_array (affine, 6);
}
static VALUE
cr_matrix_to_s(VALUE self)
{
VALUE ret;
ret = rb_str_new2 ("#<");
rb_str_cat2 (ret, rb_class2name (CLASS_OF (self)));
rb_str_cat2 (ret, ":");
rb_str_concat (ret, rb_inspect (cr_matrix_to_a (self)));
rb_str_cat2 (ret, ">");
return ret;
}
static VALUE
cr_matrix_equal (VALUE self, VALUE other)
{
if (!rb_cairo__is_kind_of (other, rb_cCairo_Matrix))
return Qfalse;
return rb_funcall (cr_matrix_to_a (self),
cr_id_equal, 1,
cr_matrix_to_a (other));
}
void
Init_cairo_matrix (void)
{
cr_id_equal = rb_intern ("==");
rb_cCairo_Matrix =
rb_define_class_under (rb_mCairo, "Matrix", rb_cObject);
rb_define_alloc_func (rb_cCairo_Matrix, cr_matrix_allocate);
rb_define_singleton_method (rb_cCairo_Matrix, "identity",
cr_matrix_init_identity, 0);
rb_define_singleton_method (rb_cCairo_Matrix, "translate",
cr_matrix_init_translate, 2);
rb_define_singleton_method (rb_cCairo_Matrix, "scale",
cr_matrix_init_scale, 2);
rb_define_singleton_method (rb_cCairo_Matrix, "rotate",
cr_matrix_init_rotate, 1);
rb_define_method (rb_cCairo_Matrix, "initialize", cr_matrix_initialize, 6);
rb_define_method (rb_cCairo_Matrix, "identity!", cr_matrix_identity, 0);
rb_define_method (rb_cCairo_Matrix, "translate!", cr_matrix_translate, 2);
rb_define_method (rb_cCairo_Matrix, "scale!", cr_matrix_scale, 2);
rb_define_method (rb_cCairo_Matrix, "rotate!", cr_matrix_rotate, 1);
rb_define_method (rb_cCairo_Matrix, "invert!", cr_matrix_invert, 0);
rb_define_method (rb_cCairo_Matrix, "multiply!", cr_matrix_multiply, 1);
rb_define_method (rb_cCairo_Matrix, "transform_distance",
cr_matrix_transform_distance, 2);
rb_define_method (rb_cCairo_Matrix, "transform_point",
cr_matrix_transform_point, 2);
/* Accessors */
rb_define_method (rb_cCairo_Matrix, "xx", cr_matrix_get_xx, 0);
rb_define_method (rb_cCairo_Matrix, "set_xx", cr_matrix_set_xx, 1);
rb_define_method (rb_cCairo_Matrix, "yx", cr_matrix_get_yx, 0);
rb_define_method (rb_cCairo_Matrix, "set_yx", cr_matrix_set_yx, 1);
rb_define_method (rb_cCairo_Matrix, "xy", cr_matrix_get_xy, 0);
rb_define_method (rb_cCairo_Matrix, "set_xy", cr_matrix_set_xy, 1);
rb_define_method (rb_cCairo_Matrix, "yy", cr_matrix_get_yy, 0);
rb_define_method (rb_cCairo_Matrix, "set_yy", cr_matrix_set_yy, 1);
rb_define_method (rb_cCairo_Matrix, "x0", cr_matrix_get_x0, 0);
rb_define_method (rb_cCairo_Matrix, "set_x0", cr_matrix_set_x0, 1);
rb_define_method (rb_cCairo_Matrix, "y0", cr_matrix_get_y0, 0);
rb_define_method (rb_cCairo_Matrix, "set_y0", cr_matrix_set_y0, 1);
/* Utilities */
rb_define_method (rb_cCairo_Matrix, "set", cr_matrix_set, 6);
rb_define_method (rb_cCairo_Matrix, "to_a", cr_matrix_to_a, 0);
rb_define_method (rb_cCairo_Matrix, "to_s", cr_matrix_to_s, 0);
rb_define_method (rb_cCairo_Matrix, "==", cr_matrix_equal, 1);
RB_CAIRO_DEF_SETTERS (rb_cCairo_Matrix);
}
cairo-1.12.8/ext/cairo/rb_cairo_font_options.c 0000644 0000041 0000041 00000011753 12256106703 021363 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-09-19 12:56:27 $
*
* Copyright 2005-2008 Kouhei Sutou
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
#define _SELF(self) (RVAL2CRFONTOPTIONS(self))
VALUE rb_cCairo_FontOptions;
static inline void
cr_options_check_status (cairo_font_options_t *options)
{
rb_cairo_check_status (cairo_font_options_status (options));
}
cairo_font_options_t *
rb_cairo_font_options_from_ruby_object (VALUE obj)
{
cairo_font_options_t *options;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_FontOptions))
{
rb_raise (rb_eTypeError, "not a cairo font options");
}
Data_Get_Struct (obj, cairo_font_options_t, options);
return options;
}
static void
cr_options_free (void *ptr)
{
if (ptr)
{
cairo_font_options_destroy ((cairo_font_options_t *) ptr);
}
}
VALUE
rb_cairo_font_options_to_ruby_object (cairo_font_options_t *options)
{
if (options)
{
return Data_Wrap_Struct (rb_cCairo_FontOptions, NULL,
cr_options_free, options);
}
else
{
return Qnil;
}
}
static VALUE
cr_options_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, cr_options_free, NULL);
}
static VALUE
cr_options_create (VALUE self)
{
cairo_font_options_t *options;
options = cairo_font_options_create ();
cr_options_check_status (options);
DATA_PTR (self) = options;
return Qnil;
}
static VALUE
cr_options_copy (VALUE self)
{
cairo_font_options_t *options;
options = cairo_font_options_copy (_SELF (self));
cr_options_check_status (options);
return CRFONTOPTIONS2RVAL (options);
}
static VALUE
cr_options_merge (VALUE self, VALUE other)
{
cairo_font_options_merge (_SELF (self), _SELF (other));
return self;
}
static VALUE
cr_options_equal (VALUE self, VALUE other)
{
return CBOOL2RVAL (cairo_font_options_equal (_SELF (self), _SELF (other)));
}
static VALUE
cr_options_hash (VALUE self)
{
return INT2NUM (cairo_font_options_hash (_SELF (self)));
}
static VALUE
cr_options_set_antialias (VALUE self, VALUE antialias)
{
cairo_font_options_set_antialias (_SELF (self), RVAL2CRANTIALIAS (antialias));
return self;
}
static VALUE
cr_options_get_antialias (VALUE self)
{
return INT2NUM (cairo_font_options_get_antialias (_SELF (self)));
}
static VALUE
cr_options_set_subpixel_order (VALUE self, VALUE subpixel_order)
{
cairo_font_options_set_subpixel_order (_SELF (self),
RVAL2CRSUBPIXELORDER (subpixel_order));
return self;
}
static VALUE
cr_options_get_subpixel_order (VALUE self)
{
return INT2NUM (cairo_font_options_get_subpixel_order (_SELF (self)));
}
static VALUE
cr_options_set_hint_style (VALUE self, VALUE hint_style)
{
cairo_font_options_set_hint_style (_SELF (self),
RVAL2CRHINTSTYLE (hint_style));
return self;
}
static VALUE
cr_options_get_hint_style (VALUE self)
{
return INT2NUM (cairo_font_options_get_hint_style (_SELF (self)));
}
static VALUE
cr_options_set_hint_metrics (VALUE self, VALUE hint_metrics)
{
cairo_font_options_set_hint_metrics (_SELF (self),
RVAL2CRHINTMETRICS (hint_metrics));
return self;
}
static VALUE
cr_options_get_hint_metrics (VALUE self)
{
return INT2NUM (cairo_font_options_get_hint_metrics (_SELF (self)));
}
void
Init_cairo_font_options (void)
{
rb_cCairo_FontOptions =
rb_define_class_under (rb_mCairo, "FontOptions", rb_cObject);
rb_define_alloc_func (rb_cCairo_FontOptions, cr_options_allocate);
rb_define_method (rb_cCairo_FontOptions, "initialize", cr_options_create, 0);
rb_define_method (rb_cCairo_FontOptions, "dup", cr_options_copy, 0);
rb_define_method (rb_cCairo_FontOptions, "merge!", cr_options_merge, 1);
rb_define_alias (rb_cCairo_FontOptions, "update", "merge!");
rb_define_method (rb_cCairo_FontOptions, "eql?", cr_options_equal, 1);
rb_define_method (rb_cCairo_FontOptions, "hash", cr_options_hash, 0);
rb_define_method (rb_cCairo_FontOptions, "set_antialias",
cr_options_set_antialias, 1);
rb_define_method (rb_cCairo_FontOptions, "antialias",
cr_options_get_antialias, 0);
rb_define_method (rb_cCairo_FontOptions, "set_subpixel_order",
cr_options_set_subpixel_order, 1);
rb_define_method (rb_cCairo_FontOptions, "subpixel_order",
cr_options_get_subpixel_order, 0);
rb_define_method (rb_cCairo_FontOptions, "set_hint_style",
cr_options_set_hint_style, 1);
rb_define_method (rb_cCairo_FontOptions, "hint_style",
cr_options_get_hint_style, 0);
rb_define_method (rb_cCairo_FontOptions, "set_hint_metrics",
cr_options_set_hint_metrics, 1);
rb_define_method (rb_cCairo_FontOptions, "hint_metrics",
cr_options_get_hint_metrics, 0);
RB_CAIRO_DEF_SETTERS (rb_cCairo_FontOptions);
}
cairo-1.12.8/ext/cairo/rb_cairo.c 0000644 0000041 0000041 00000006407 12256106703 016562 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2009-12-13 11:27:45 $
*
* Copyright 2006-2008 Kouhei Sutou
* Copyright 2005 Øyvind Kolås
* Copyright 2004-2005 MenTaLguY
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
VALUE rb_mCairo, rb_mCairo_Color, rb_cCairo_Color_Base, rb_cCairo_Paper;
static ID id__add_one_arg_setter;
void
rb_cairo_def_setters (VALUE klass)
{
rb_funcall (rb_mCairo, id__add_one_arg_setter, 1, klass);
}
static VALUE
rb_cairo_satisfied_version (int argc, VALUE *argv, VALUE self)
{
VALUE major, minor, micro;
rb_scan_args (argc, argv, "21", &major, &minor, µ);
if (NIL_P (micro))
micro = UINT2NUM (0);
return CBOOL2RVAL (CAIRO_VERSION_MAJOR > NUM2UINT(major) ||
(CAIRO_VERSION_MAJOR == NUM2UINT(major) &&
CAIRO_VERSION_MINOR > NUM2UINT(minor)) ||
(CAIRO_VERSION_MAJOR == NUM2UINT(major) &&
CAIRO_VERSION_MINOR == NUM2UINT(minor) &&
CAIRO_VERSION_MICRO >= NUM2UINT(micro)));
}
void
Init_cairo ()
{
int major, minor, micro;
id__add_one_arg_setter = rb_intern("__add_one_arg_setter");
rb_mCairo = rb_define_module ("Cairo");
rb_define_const (rb_mCairo, "BUILD_VERSION",
rb_ary_new3 (3,
INT2FIX (CAIRO_VERSION_MAJOR),
INT2FIX (CAIRO_VERSION_MINOR),
INT2FIX (CAIRO_VERSION_MICRO)));
major = cairo_version () / 10000;
minor = (cairo_version () % 10000) / 100;
micro = cairo_version () % 100;
rb_define_const (rb_mCairo, "VERSION",
rb_ary_new3 (3,
INT2FIX (major),
INT2FIX (minor),
INT2FIX (micro)));
rb_define_const (rb_mCairo, "MAJOR_VERSION", INT2FIX (major));
rb_define_const (rb_mCairo, "MINOR_VERSION", INT2FIX (minor));
rb_define_const (rb_mCairo, "MICRO_VERSION", INT2FIX (micro));
rb_define_const (rb_mCairo, "BINDINGS_VERSION",
rb_ary_new3 (4,
INT2FIX (RB_CAIRO_VERSION_MAJOR),
INT2FIX (RB_CAIRO_VERSION_MINOR),
INT2FIX (RB_CAIRO_VERSION_MICRO),
Qnil));
rb_define_module_function (rb_mCairo, "satisfied_version?",
rb_cairo_satisfied_version, -1);
rb_mCairo_Color = rb_const_get (rb_mCairo, rb_intern ("Color"));
rb_cCairo_Color_Base = rb_const_get (rb_mCairo_Color, rb_intern ("Base"));
rb_cCairo_Paper = rb_const_get (rb_mCairo, rb_intern ("Paper"));
Init_cairo_private ();
Init_cairo_io ();
Init_cairo_constants ();
Init_cairo_context ();
Init_cairo_path ();
Init_cairo_matrix ();
Init_cairo_region ();
Init_cairo_device ();
Init_cairo_surface ();
Init_cairo_exception ();
Init_cairo_font ();
Init_cairo_font_extents ();
Init_cairo_font_options ();
Init_cairo_scaled_font ();
Init_cairo_text_extents ();
Init_cairo_pattern ();
Init_cairo_glyph ();
Init_cairo_text_cluster ();
}
cairo-1.12.8/ext/cairo/rb_cairo_constants.c 0000644 0000041 0000041 00000056233 12256106703 020660 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-09-19 12:56:27 $
*
* Copyright 2005-2012 Kouhei Sutou
* Copyright 2005 Øyvind Kolås
* Copyright 2004-2005 MenTaLguY
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
VALUE rb_mCairo_Operator;
VALUE rb_mCairo_Antialias;
VALUE rb_mCairo_FillRule;
VALUE rb_mCairo_LineCap;
VALUE rb_mCairo_LineJoin;
VALUE rb_mCairo_FontSlant;
VALUE rb_mCairo_FontWeight;
VALUE rb_mCairo_SubpixelOrder;
VALUE rb_mCairo_HintStyle;
VALUE rb_mCairo_HintMetrics;
VALUE rb_mCairo_PathDataType;
VALUE rb_mCairo_Content;
VALUE rb_mCairo_Format;
VALUE rb_mCairo_Extend;
VALUE rb_mCairo_Filter;
VALUE rb_mCairo_SVGVersion = Qnil;
VALUE rb_mCairo_PSLevel = Qnil;
VALUE rb_mCairo_TextClusterFlag = Qnil;
VALUE rb_mCairo_PDFVersion = Qnil;
VALUE rb_mCairo_ScriptMode = Qnil;
VALUE rb_mCairo_MimeType = Qnil;
VALUE rb_mCairo_RegionOverlap = Qnil;
#define CAIRO_OPERATOR_MIN CAIRO_OPERATOR_CLEAR
#if CAIRO_CHECK_VERSION(1, 10, 0)
# define CAIRO_OPERATOR_MAX CAIRO_OPERATOR_HSL_LUMINOSITY
#else
# define CAIRO_OPERATOR_MAX CAIRO_OPERATOR_SATURATE
#endif
#define CAIRO_ANTIALIAS_MIN CAIRO_ANTIALIAS_DEFAULT
#if CAIRO_CHECK_VERSION(1, 11, 4)
# define CAIRO_ANTIALIAS_MAX CAIRO_ANTIALIAS_BEST
#else
# define CAIRO_ANTIALIAS_MAX CAIRO_ANTIALIAS_SUBPIXEL
#endif
#define CAIRO_FILL_RULE_MIN CAIRO_FILL_RULE_WINDING
#define CAIRO_FILL_RULE_MAX CAIRO_FILL_RULE_EVEN_ODD
#define CAIRO_LINE_CAP_MIN CAIRO_LINE_CAP_BUTT
#define CAIRO_LINE_CAP_MAX CAIRO_LINE_CAP_SQUARE
#define CAIRO_LINE_JOIN_MIN CAIRO_LINE_JOIN_MITER
#define CAIRO_LINE_JOIN_MAX CAIRO_LINE_JOIN_BEVEL
#define CAIRO_FONT_SLANT_MIN CAIRO_FONT_SLANT_NORMAL
#define CAIRO_FONT_SLANT_MAX CAIRO_FONT_SLANT_OBLIQUE
#define CAIRO_FONT_WEIGHT_MIN CAIRO_FONT_WEIGHT_NORMAL
#define CAIRO_FONT_WEIGHT_MAX CAIRO_FONT_WEIGHT_BOLD
#define CAIRO_SUBPIXEL_ORDER_MIN CAIRO_SUBPIXEL_ORDER_DEFAULT
#define CAIRO_SUBPIXEL_ORDER_MAX CAIRO_SUBPIXEL_ORDER_VBGR
#define CAIRO_HINT_STYLE_MIN CAIRO_HINT_STYLE_DEFAULT
#define CAIRO_HINT_STYLE_MAX CAIRO_HINT_STYLE_FULL
#define CAIRO_HINT_METRICS_MIN CAIRO_HINT_METRICS_DEFAULT
#define CAIRO_HINT_METRICS_MAX CAIRO_HINT_METRICS_ON
#define CAIRO_PATH_MIN CAIRO_PATH_MOVE_TO
#define CAIRO_PATH_MAX CAIRO_PATH_CLOSE_PATH
#define CAIRO_CONTENT_MIN CAIRO_CONTENT_COLOR
#define CAIRO_CONTENT_MAX CAIRO_CONTENT_COLOR_ALPHA
#if CAIRO_CHECK_VERSION(1, 10, 0)
# define CAIRO_FORMAT_MIN CAIRO_FORMAT_INVALID
#else
# define CAIRO_FORMAT_MIN CAIRO_FORMAT_ARGB32
#endif
#if CAIRO_CHECK_VERSION(1, 11, 4)
# define CAIRO_FORMAT_MAX CAIRO_FORMAT_RGB30
#else
# define CAIRO_FORMAT_MAX CAIRO_FORMAT_RGB16_565
#endif
#define CAIRO_EXTEND_MIN CAIRO_EXTEND_NONE
#define CAIRO_EXTEND_MAX CAIRO_EXTEND_PAD
#define CAIRO_FILTER_MIN CAIRO_FILTER_FAST
#define CAIRO_FILTER_MAX CAIRO_FILTER_GAUSSIAN
#define CAIRO_SVG_VERSION_MIN CAIRO_SVG_VERSION_1_1
#define CAIRO_SVG_VERSION_MAX CAIRO_SVG_VERSION_1_2
#define CAIRO_PS_LEVEL_MIN CAIRO_PS_LEVEL_2
#define CAIRO_PS_LEVEL_MAX CAIRO_PS_LEVEL_3
#define CAIRO_PDF_VERSION_MIN CAIRO_PDF_VERSION_1_4
#define CAIRO_PDF_VERSION_MAX CAIRO_PDF_VERSION_1_5
#define CAIRO_TEXT_CLUSTER_FLAG_MIN 0
#define CAIRO_TEXT_CLUSTER_FLAG_MAX CAIRO_TEXT_CLUSTER_FLAG_BACKWARD
#if CAIRO_CHECK_VERSION(1, 11, 4)
# define CAIRO_SCRIPT_MODE_MIN CAIRO_SCRIPT_MODE_ASCII
# define CAIRO_SCRIPT_MODE_MAX CAIRO_SCRIPT_MODE_BINARY
#else
# define CAIRO_SCRIPT_MODE_MIN CAIRO_SCRIPT_MODE_BINARY
# define CAIRO_SCRIPT_MODE_MAX CAIRO_SCRIPT_MODE_ASCII
#endif
#define CAIRO_REGION_OVERLAP_MIN CAIRO_REGION_OVERLAP_IN
#define CAIRO_REGION_OVERLAP_MAX CAIRO_REGION_OVERLAP_PART
#define DEFINE_RVAL2ENUM(name, const_name) \
cairo_ ## name ## _t \
rb_cairo_ ## name ## _from_ruby_object (VALUE rb_ ## name) \
{ \
cairo_ ## name ## _t name; \
\
if (!rb_cairo__is_kind_of (rb_ ## name, rb_cNumeric)) \
rb_ ## name = rb_cairo__const_get (rb_ ## name, \
# const_name "_"); \
\
name = FIX2INT (rb_ ## name); \
if (name < CAIRO_ ## const_name ## _MIN || \
name > CAIRO_ ## const_name ## _MAX) \
{ \
rb_raise (rb_eArgError, \
"invalid %s: %d (expect %d <= %s <= %d)", \
#name, name, \
CAIRO_ ## const_name ## _MIN, \
#name, \
CAIRO_ ## const_name ## _MAX); \
} \
return name; \
}
DEFINE_RVAL2ENUM(operator, OPERATOR)
DEFINE_RVAL2ENUM(antialias, ANTIALIAS)
DEFINE_RVAL2ENUM(fill_rule, FILL_RULE)
DEFINE_RVAL2ENUM(line_cap, LINE_CAP)
DEFINE_RVAL2ENUM(line_join, LINE_JOIN)
DEFINE_RVAL2ENUM(font_slant, FONT_SLANT)
DEFINE_RVAL2ENUM(font_weight, FONT_WEIGHT)
DEFINE_RVAL2ENUM(subpixel_order, SUBPIXEL_ORDER)
DEFINE_RVAL2ENUM(hint_style, HINT_STYLE)
DEFINE_RVAL2ENUM(hint_metrics, HINT_METRICS)
DEFINE_RVAL2ENUM(path_data_type, PATH)
DEFINE_RVAL2ENUM(content, CONTENT)
DEFINE_RVAL2ENUM(format, FORMAT)
DEFINE_RVAL2ENUM(extend, EXTEND)
DEFINE_RVAL2ENUM(filter, FILTER)
#ifdef CAIRO_HAS_SVG_SURFACE
DEFINE_RVAL2ENUM(svg_version, SVG_VERSION)
#endif
#ifdef CAIRO_HAS_PS_SURFACE
# if CAIRO_CHECK_VERSION(1, 5, 2)
DEFINE_RVAL2ENUM(ps_level, PS_LEVEL)
#define PS_LEVEL_ENUM_DEFINED 1
# endif
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
# if CAIRO_CHECK_VERSION(1, 10, 0)
DEFINE_RVAL2ENUM(pdf_version, PDF_VERSION)
#define PDF_VERSION_ENUM_DEFINED 1
# endif
#endif
#if CAIRO_CHECK_VERSION(1, 7, 6)
DEFINE_RVAL2ENUM(text_cluster_flags, TEXT_CLUSTER_FLAG)
#endif
#ifdef CAIRO_HAS_SCRIPT_SURFACE
DEFINE_RVAL2ENUM(script_mode, SCRIPT_MODE)
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
DEFINE_RVAL2ENUM(region_overlap, REGION_OVERLAP)
#endif
#if defined(RB_CAIRO_PLATFORM_WIN32) && !defined(PS_LEVEL_ENUM_DEFINED)
void
rb_cairo_ps_level_from_ruby_object (VALUE rb_ps_level)
{
/* dummy */
}
#endif
#ifdef CAIRO_HAS_SVG_SURFACE
static VALUE
cr_svg_get_versions (VALUE self)
{
VALUE rb_versions;
int i, num_versions;
cairo_svg_version_t const *versions;
cairo_svg_get_versions (&versions, &num_versions);
rb_versions = rb_ary_new2 (num_versions);
for (i = 0; i < num_versions; i++)
{
rb_ary_push (rb_versions, INT2NUM (versions[i]));
}
return rb_versions;
}
static VALUE
cr_svg_version_to_string (int argc, VALUE *argv, VALUE self)
{
if (argc == 0)
{
return rb_call_super (argc, argv);
}
else
{
VALUE version;
const char *ver_str;
rb_scan_args (argc, argv, "1", &version);
ver_str = cairo_svg_version_to_string (RVAL2CRSVGVERSION(version));
return rb_str_new2 (ver_str);
}
}
#endif
#if CAIRO_CHECK_VERSION(1, 5, 8)
static VALUE
cr_format_stride_for_width (VALUE self, VALUE format, VALUE width)
{
return INT2NUM (cairo_format_stride_for_width (RVAL2CRFORMAT (format),
NUM2INT (width)));
}
#endif
#ifdef CAIRO_HAS_PS_SURFACE
# if CAIRO_CHECK_VERSION(1, 5, 8)
static VALUE
cr_ps_get_levels (VALUE self)
{
VALUE rb_levels;
const cairo_ps_level_t *levels;
int i, n_levels;
cairo_ps_get_levels (&levels, &n_levels);
rb_levels = rb_ary_new2 (n_levels);
for (i = 0; i < n_levels; i++)
{
rb_ary_push (rb_levels, INT2NUM (levels[i]));
}
return rb_levels;
}
static VALUE
cr_ps_level_to_string (int argc, VALUE *argv, VALUE self)
{
if (argc == 0)
{
return rb_call_super (argc, argv);
}
else
{
VALUE level;
rb_scan_args (argc, argv, "1", &level);
return rb_str_new2 (cairo_ps_level_to_string (RVAL2CRPSLEVEL (level)));
}
}
# endif
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
# if CAIRO_CHECK_VERSION(1, 10, 0)
static VALUE
cr_pdf_get_versions (VALUE self)
{
VALUE rb_versions;
const cairo_pdf_version_t *versions;
int i, n_versions;
cairo_pdf_get_versions (&versions, &n_versions);
rb_versions = rb_ary_new2 (n_versions);
for (i = 0; i < n_versions; i++)
{
rb_ary_push (rb_versions, INT2NUM (versions[i]));
}
return rb_versions;
}
static VALUE
cr_pdf_version_to_string (int argc, VALUE *argv, VALUE self)
{
if (argc == 0)
{
return rb_call_super (argc, argv);
}
else
{
VALUE version;
rb_scan_args (argc, argv, "1", &version);
return rb_str_new2 (cairo_pdf_version_to_string (RVAL2CRPDFVERSION (version)));
}
}
# endif
#endif
void
Init_cairo_constants (void)
{
/* cairo_operator_t */
rb_mCairo_Operator = rb_define_module_under (rb_mCairo, "Operator");
rb_define_const (rb_mCairo_Operator, "CLEAR",
INT2FIX (CAIRO_OPERATOR_CLEAR));
rb_define_const (rb_mCairo_Operator, "SOURCE",
INT2FIX (CAIRO_OPERATOR_SOURCE));
rb_define_const (rb_mCairo_Operator, "OVER",
INT2FIX (CAIRO_OPERATOR_OVER));
rb_define_const (rb_mCairo_Operator, "IN",
INT2FIX (CAIRO_OPERATOR_IN));
rb_define_const (rb_mCairo_Operator, "OUT",
INT2FIX (CAIRO_OPERATOR_OUT));
rb_define_const (rb_mCairo_Operator, "ATOP",
INT2FIX (CAIRO_OPERATOR_ATOP));
rb_define_const (rb_mCairo_Operator, "DEST",
INT2FIX (CAIRO_OPERATOR_DEST));
rb_define_const (rb_mCairo_Operator, "DEST_OVER",
INT2FIX (CAIRO_OPERATOR_DEST_OVER));
rb_define_const (rb_mCairo_Operator, "DEST_IN",
INT2FIX (CAIRO_OPERATOR_DEST_IN));
rb_define_const (rb_mCairo_Operator, "DEST_OUT",
INT2FIX (CAIRO_OPERATOR_DEST_OUT));
rb_define_const (rb_mCairo_Operator, "DEST_ATOP",
INT2FIX (CAIRO_OPERATOR_DEST_ATOP));
rb_define_const (rb_mCairo_Operator, "XOR",
INT2FIX (CAIRO_OPERATOR_XOR));
rb_define_const (rb_mCairo_Operator, "ADD",
INT2FIX (CAIRO_OPERATOR_ADD));
rb_define_const (rb_mCairo_Operator, "SATURATE",
INT2FIX (CAIRO_OPERATOR_SATURATE));
#if CAIRO_CHECK_VERSION(1, 10, 0)
rb_define_const (rb_mCairo_Operator, "MULTIPLY",
INT2FIX (CAIRO_OPERATOR_MULTIPLY));
rb_define_const (rb_mCairo_Operator, "SCREEN",
INT2FIX (CAIRO_OPERATOR_SCREEN));
rb_define_const (rb_mCairo_Operator, "OVERLAY",
INT2FIX (CAIRO_OPERATOR_OVERLAY));
rb_define_const (rb_mCairo_Operator, "DARKEN",
INT2FIX (CAIRO_OPERATOR_DARKEN));
rb_define_const (rb_mCairo_Operator, "LIGHTEN",
INT2FIX (CAIRO_OPERATOR_LIGHTEN));
rb_define_const (rb_mCairo_Operator, "COLOR_DODGE",
INT2FIX (CAIRO_OPERATOR_COLOR_DODGE));
rb_define_const (rb_mCairo_Operator, "COLOR_BURN",
INT2FIX (CAIRO_OPERATOR_COLOR_BURN));
rb_define_const (rb_mCairo_Operator, "HARD_LIGHT",
INT2FIX (CAIRO_OPERATOR_HARD_LIGHT));
rb_define_const (rb_mCairo_Operator, "SOFT_LIGHT",
INT2FIX (CAIRO_OPERATOR_SOFT_LIGHT));
rb_define_const (rb_mCairo_Operator, "DIFFERENCE",
INT2FIX (CAIRO_OPERATOR_DIFFERENCE));
rb_define_const (rb_mCairo_Operator, "EXCLUSION",
INT2FIX (CAIRO_OPERATOR_EXCLUSION));
rb_define_const (rb_mCairo_Operator, "HSL_HUE",
INT2FIX (CAIRO_OPERATOR_HSL_HUE));
rb_define_const (rb_mCairo_Operator, "HSL_SATURATION",
INT2FIX (CAIRO_OPERATOR_HSL_SATURATION));
rb_define_const (rb_mCairo_Operator, "HSL_COLOR",
INT2FIX (CAIRO_OPERATOR_HSL_COLOR));
rb_define_const (rb_mCairo_Operator, "HSL_LUMINOSITY",
INT2FIX (CAIRO_OPERATOR_HSL_LUMINOSITY));
#endif
/* cairo_antialias_t */
rb_mCairo_Antialias = rb_define_module_under (rb_mCairo, "Antialias");
rb_define_const (rb_mCairo_Antialias, "DEFAULT",
INT2FIX (CAIRO_ANTIALIAS_DEFAULT));
rb_define_const (rb_mCairo_Antialias, "NONE",
INT2FIX (CAIRO_ANTIALIAS_NONE));
rb_define_const (rb_mCairo_Antialias, "GRAY",
INT2FIX (CAIRO_ANTIALIAS_GRAY));
rb_define_const (rb_mCairo_Antialias, "SUBPIXEL",
INT2FIX (CAIRO_ANTIALIAS_SUBPIXEL));
#if CAIRO_CHECK_VERSION(1, 11, 4)
rb_define_const (rb_mCairo_Antialias, "FAST",
INT2FIX (CAIRO_ANTIALIAS_FAST));
rb_define_const (rb_mCairo_Antialias, "GOOD",
INT2FIX (CAIRO_ANTIALIAS_GOOD));
rb_define_const (rb_mCairo_Antialias, "BEST",
INT2FIX (CAIRO_ANTIALIAS_BEST));
#endif
/* cairo_fill_rule_t */
rb_mCairo_FillRule = rb_define_module_under (rb_mCairo, "FillRule");
rb_define_const (rb_mCairo_FillRule, "WINDING",
INT2FIX (CAIRO_FILL_RULE_WINDING));
rb_define_const (rb_mCairo_FillRule, "EVEN_ODD",
INT2FIX (CAIRO_FILL_RULE_EVEN_ODD));
/* cairo_line_cap_t */
rb_mCairo_LineCap = rb_define_module_under (rb_mCairo, "LineCap");
rb_define_const (rb_mCairo_LineCap, "BUTT",
INT2FIX (CAIRO_LINE_CAP_BUTT));
rb_define_const (rb_mCairo_LineCap, "ROUND",
INT2FIX (CAIRO_LINE_CAP_ROUND));
rb_define_const (rb_mCairo_LineCap, "SQUARE",
INT2FIX (CAIRO_LINE_CAP_SQUARE));
/* cairo_line_join_t */
rb_mCairo_LineJoin = rb_define_module_under (rb_mCairo, "LineJoin");
rb_define_const (rb_mCairo_LineJoin, "MITER",
INT2FIX (CAIRO_LINE_JOIN_MITER));
rb_define_const (rb_mCairo_LineJoin, "ROUND",
INT2FIX (CAIRO_LINE_JOIN_ROUND));
rb_define_const (rb_mCairo_LineJoin, "BEVEL",
INT2FIX (CAIRO_LINE_JOIN_BEVEL));
/* cairo_font_slant_t */
rb_mCairo_FontSlant = rb_define_module_under (rb_mCairo, "FontSlant");
rb_define_const (rb_mCairo_FontSlant, "NORMAL",
INT2FIX (CAIRO_FONT_SLANT_NORMAL));
rb_define_const (rb_mCairo_FontSlant, "ITALIC",
INT2FIX (CAIRO_FONT_SLANT_ITALIC));
rb_define_const (rb_mCairo_FontSlant, "OBLIQUE",
INT2FIX (CAIRO_FONT_SLANT_OBLIQUE));
/* cairo_font_weight_t */
rb_mCairo_FontWeight = rb_define_module_under (rb_mCairo, "FontWeight");
rb_define_const (rb_mCairo_FontWeight, "NORMAL",
INT2FIX (CAIRO_FONT_WEIGHT_NORMAL));
rb_define_const (rb_mCairo_FontWeight, "BOLD",
INT2FIX (CAIRO_FONT_WEIGHT_BOLD));
/* cairo_subpixel_order_t */
rb_mCairo_SubpixelOrder = rb_define_module_under (rb_mCairo, "SubpixelOrder");
rb_define_const (rb_mCairo_SubpixelOrder, "DEFAULT",
INT2FIX (CAIRO_SUBPIXEL_ORDER_DEFAULT));
rb_define_const (rb_mCairo_SubpixelOrder, "RGB",
INT2FIX (CAIRO_SUBPIXEL_ORDER_RGB));
rb_define_const (rb_mCairo_SubpixelOrder, "BGR",
INT2FIX (CAIRO_SUBPIXEL_ORDER_BGR));
rb_define_const (rb_mCairo_SubpixelOrder, "VRGB",
INT2FIX (CAIRO_SUBPIXEL_ORDER_VRGB));
rb_define_const (rb_mCairo_SubpixelOrder, "VBGR",
INT2FIX (CAIRO_SUBPIXEL_ORDER_VBGR));
/* cairo_hint_style_t */
rb_mCairo_HintStyle = rb_define_module_under (rb_mCairo, "HintStyle");
rb_define_const (rb_mCairo_HintStyle, "DEFAULT",
INT2FIX (CAIRO_HINT_STYLE_DEFAULT));
rb_define_const (rb_mCairo_HintStyle, "NONE",
INT2FIX (CAIRO_HINT_STYLE_NONE));
rb_define_const (rb_mCairo_HintStyle, "SLIGHT",
INT2FIX (CAIRO_HINT_STYLE_SLIGHT));
rb_define_const (rb_mCairo_HintStyle, "MEDIUM",
INT2FIX (CAIRO_HINT_STYLE_MEDIUM));
rb_define_const (rb_mCairo_HintStyle, "FULL",
INT2FIX (CAIRO_HINT_STYLE_FULL));
/* cairo_hint_metrics_t */
rb_mCairo_HintMetrics = rb_define_module_under (rb_mCairo, "HintMetrics");
rb_define_const (rb_mCairo_HintMetrics, "DEFAULT",
INT2FIX (CAIRO_HINT_METRICS_DEFAULT));
rb_define_const (rb_mCairo_HintMetrics, "ON",
INT2FIX (CAIRO_HINT_METRICS_ON));
rb_define_const (rb_mCairo_HintMetrics, "OFF",
INT2FIX (CAIRO_HINT_METRICS_OFF));
/* cairo_path_data_type_t */
rb_mCairo_PathDataType = rb_define_module_under (rb_mCairo, "PathDataType");
rb_define_const (rb_mCairo_PathDataType, "MOVE_TO",
INT2FIX (CAIRO_PATH_MOVE_TO));
rb_define_const (rb_mCairo_PathDataType, "LINE_TO",
INT2FIX (CAIRO_PATH_LINE_TO));
rb_define_const (rb_mCairo_PathDataType, "CURVE_TO",
INT2FIX (CAIRO_PATH_CURVE_TO));
rb_define_const (rb_mCairo_PathDataType, "CLOSE_PATH",
INT2FIX (CAIRO_PATH_CLOSE_PATH));
/* cairo_content_t */
rb_mCairo_Content = rb_define_module_under (rb_mCairo, "Content");
rb_define_const (rb_mCairo_Content, "COLOR",
INT2FIX (CAIRO_CONTENT_COLOR));
rb_define_const (rb_mCairo_Content, "ALPHA",
INT2FIX (CAIRO_CONTENT_ALPHA));
rb_define_const (rb_mCairo_Content, "COLOR_ALPHA",
INT2FIX (CAIRO_CONTENT_COLOR_ALPHA));
/* cairo_format_t */
rb_mCairo_Format = rb_define_module_under (rb_mCairo, "Format");
#if CAIRO_CHECK_VERSION(1, 10, 0)
rb_define_const (rb_mCairo_Format, "INVALID",
INT2FIX (CAIRO_FORMAT_INVALID));
#endif
rb_define_const (rb_mCairo_Format, "ARGB32",
INT2FIX (CAIRO_FORMAT_ARGB32));
rb_define_const (rb_mCairo_Format, "RGB24",
INT2FIX (CAIRO_FORMAT_RGB24));
rb_define_const (rb_mCairo_Format, "A8",
INT2FIX (CAIRO_FORMAT_A8));
rb_define_const (rb_mCairo_Format, "A1",
INT2FIX (CAIRO_FORMAT_A1));
rb_define_const (rb_mCairo_Format, "RGB16_565",
INT2FIX (CAIRO_FORMAT_RGB16_565));
#if CAIRO_CHECK_VERSION(1, 11, 4)
rb_define_const (rb_mCairo_Format, "RGB30",
INT2FIX (CAIRO_FORMAT_RGB30));
#endif
#if CAIRO_CHECK_VERSION(1, 5, 8)
rb_define_singleton_method (rb_mCairo_Format, "stride_for_width",
cr_format_stride_for_width, 2);
#endif
/* cairo_extend_t */
rb_mCairo_Extend = rb_define_module_under (rb_mCairo, "Extend");
rb_define_const (rb_mCairo_Extend, "NONE",
INT2FIX (CAIRO_EXTEND_NONE));
rb_define_const (rb_mCairo_Extend, "REPEAT",
INT2FIX (CAIRO_EXTEND_REPEAT));
rb_define_const (rb_mCairo_Extend, "REFLECT",
INT2FIX (CAIRO_EXTEND_REFLECT));
rb_define_const (rb_mCairo_Extend, "PAD",
INT2FIX (CAIRO_EXTEND_PAD));
/* cairo_filter_t */
rb_mCairo_Filter = rb_define_module_under (rb_mCairo, "Filter");
rb_define_const (rb_mCairo_Filter, "FAST",
INT2FIX (CAIRO_FILTER_FAST));
rb_define_const (rb_mCairo_Filter, "GOOD",
INT2FIX (CAIRO_FILTER_GOOD));
rb_define_const (rb_mCairo_Filter, "BEST",
INT2FIX (CAIRO_FILTER_BEST));
rb_define_const (rb_mCairo_Filter, "NEAREST",
INT2FIX (CAIRO_FILTER_NEAREST));
rb_define_const (rb_mCairo_Filter, "BILINEAR",
INT2FIX (CAIRO_FILTER_BILINEAR));
rb_define_const (rb_mCairo_Filter, "GAUSSIAN",
INT2FIX (CAIRO_FILTER_GAUSSIAN));
#ifdef CAIRO_HAS_SVG_SURFACE
/* cairo_svg_version_t */
rb_mCairo_SVGVersion = rb_define_module_under (rb_mCairo, "SVGVersion");
rb_define_const (rb_mCairo_SVGVersion, "VERSION_1_1",
INT2FIX (CAIRO_SVG_VERSION_1_1));
rb_define_const (rb_mCairo_SVGVersion, "VERSION_1_2",
INT2FIX (CAIRO_SVG_VERSION_1_2));
rb_define_singleton_method (rb_mCairo_SVGVersion, "list",
cr_svg_get_versions, 0);
rb_define_singleton_method (rb_mCairo_SVGVersion, "name",
cr_svg_version_to_string, -1);
#endif
#ifdef CAIRO_HAS_PS_SURFACE
# if CAIRO_CHECK_VERSION(1, 5, 2)
/* cairo_ps_level_t */
rb_mCairo_PSLevel = rb_define_module_under (rb_mCairo, "PSLevel");
rb_define_const (rb_mCairo_PSLevel, "LEVEL_2", INT2FIX (CAIRO_PS_LEVEL_2));
rb_define_const (rb_mCairo_PSLevel, "LEVEL_3", INT2FIX (CAIRO_PS_LEVEL_3));
rb_define_singleton_method (rb_mCairo_PSLevel, "list",
cr_ps_get_levels, 0);
rb_define_singleton_method (rb_mCairo_PSLevel, "name",
cr_ps_level_to_string, -1);
# endif
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
# if CAIRO_CHECK_VERSION(1, 10, 0)
/* cairo_pdf_version_t */
rb_mCairo_PDFVersion = rb_define_module_under (rb_mCairo, "PDFVersion");
rb_define_const (rb_mCairo_PDFVersion, "VERSION_1_4",
INT2FIX (CAIRO_PDF_VERSION_1_4));
rb_define_const (rb_mCairo_PDFVersion, "VERSION_1_5",
INT2FIX (CAIRO_PDF_VERSION_1_5));
rb_define_singleton_method (rb_mCairo_PDFVersion, "list",
cr_pdf_get_versions, 0);
rb_define_singleton_method (rb_mCairo_PDFVersion, "name",
cr_pdf_version_to_string, -1);
# endif
#endif
#if CAIRO_CHECK_VERSION(1, 7, 6)
/* cairo_text_cluster_flags_t */
rb_mCairo_TextClusterFlag =
rb_define_module_under (rb_mCairo, "TextClusterFlag");
rb_define_const (rb_mCairo_TextClusterFlag, "BACKWARD",
INT2FIX (CAIRO_TEXT_CLUSTER_FLAG_BACKWARD));
#endif
#ifdef CAIRO_HAS_SCRIPT_SURFACE
/* cairo_script_mode_t */
rb_mCairo_ScriptMode = rb_define_module_under (rb_mCairo, "ScriptMode");
rb_define_const (rb_mCairo_ScriptMode, "BINARY",
INT2FIX (CAIRO_SCRIPT_MODE_BINARY));
rb_define_const (rb_mCairo_ScriptMode, "ASCII",
INT2FIX (CAIRO_SCRIPT_MODE_ASCII));
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
rb_mCairo_MimeType = rb_define_module_under (rb_mCairo, "MimeType");
rb_define_const (rb_mCairo_MimeType, "JPEG",
rb_str_new2 (CAIRO_MIME_TYPE_JPEG));
rb_define_const (rb_mCairo_MimeType, "PNG",
rb_str_new2 (CAIRO_MIME_TYPE_PNG));
rb_define_const (rb_mCairo_MimeType, "JP2",
rb_str_new2 (CAIRO_MIME_TYPE_JP2));
rb_define_const (rb_mCairo_MimeType, "URI",
rb_str_new2 (CAIRO_MIME_TYPE_URI));
#endif
#if CAIRO_CHECK_VERSION(1, 11, 4)
rb_define_const (rb_mCairo_MimeType, "UNIQUE_ID",
rb_str_new2 (CAIRO_MIME_TYPE_UNIQUE_ID));
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
rb_mCairo_RegionOverlap = rb_define_module_under (rb_mCairo, "RegionOverlap");
rb_define_const (rb_mCairo_RegionOverlap, "IN",
INT2FIX (CAIRO_REGION_OVERLAP_IN));
rb_define_const (rb_mCairo_RegionOverlap, "OUT",
INT2FIX (CAIRO_REGION_OVERLAP_OUT));
rb_define_const (rb_mCairo_RegionOverlap, "PART",
INT2FIX (CAIRO_REGION_OVERLAP_PART));
#endif
}
cairo-1.12.8/ext/cairo/cairo.def 0000644 0000041 0000041 00000011425 12256106703 016407 0 ustar www-data www-data EXPORTS
Init_cairo
rb_mCairo DATA
rb_cCairo_Context DATA
rb_cCairo_Rectangle DATA
rb_cCairo_Path DATA
rb_cCairo_PathData DATA
rb_cCairo_PathMoveTo DATA
rb_cCairo_PathLineTo DATA
rb_cCairo_PathCurveTo DATA
rb_cCairo_PathClosePath DATA
rb_cCairo_Matrix DATA
rb_cCairo_Region DATA
rb_cCairo_Pattern DATA
rb_cCairo_SolidPattern DATA
rb_cCairo_SurfacePattern DATA
rb_cCairo_GradientPattern DATA
rb_cCairo_LinearPattern DATA
rb_cCairo_RadialPattern DATA
rb_cCairo_MeshPattern DATA
rb_cCairo_RasterSourcePattern DATA
rb_cCairo_FontFace DATA
rb_cCairo_ToyFontFace DATA
rb_cCairo_UserFontFace DATA
rb_cCairo_UserFontFace_TextToGlyphsData DATA
rb_cCairo_FontExtents DATA
rb_cCairo_FontOptions DATA
rb_cCairo_ScaledFont DATA
rb_cCairo_TextExtents DATA
rb_cCairo_Glyph DATA
rb_cCairo_TextCluster DATA
rb_cCairo_Surface DATA
rb_cCairo_ImageSurface DATA
rb_cCairo_PDFSurface DATA
rb_cCairo_PSSurface DATA
rb_cCairo_SVGSurface DATA
rb_cCairo_Win32Surface DATA
rb_cCairo_Win32PrintingSurface DATA
rb_cCairo_QuartzSurface DATA
rb_cCairo_QuartzImageSurface DATA
rb_cCairo_ScriptSurface DATA
rb_cCairo_QtSurface DATA
rb_cCairo_RecordingSurface DATA
rb_cCairo_VGSurface DATA
rb_cCairo_GLSurface DATA
rb_cCairo_GLTextureSurface DATA
rb_cCairo_DRMSurface DATA
rb_cCairo_TeeSurface DATA
rb_cCairo_XMLSurface DATA
rb_cCairo_SkiaSurface DATA
rb_cCairo_SubSurface DATA
rb_cCairo_CoglSurface DATA
rb_cCairo_Device DATA
rb_cCairo_DRMDevice DATA
rb_cCairo_GLDevice DATA
rb_cCairo_ScriptDevice DATA
rb_cCairo_XCBDevice DATA
rb_cCairo_XlibDevice DATA
rb_cCairo_XMLDevice DATA
rb_cCairo_CoglDevice DATA
rb_cCairo_Win32Device DATA
rb_mCairo_Operator DATA
rb_mCairo_Antialias DATA
rb_mCairo_FillRule DATA
rb_mCairo_LineCap DATA
rb_mCairo_LineJoin DATA
rb_mCairo_FontSlant DATA
rb_mCairo_FontWeight DATA
rb_mCairo_SubpixelOrder DATA
rb_mCairo_HintStyle DATA
rb_mCairo_HintMetrics DATA
rb_mCairo_PathDataType DATA
rb_mCairo_Content DATA
rb_mCairo_Format DATA
rb_mCairo_Extend DATA
rb_mCairo_Filter DATA
rb_mCairo_SVGVersion DATA
rb_mCairo_PSLevel DATA
rb_mCairo_PDFVersion DATA
rb_mCairo_TextClusterFlag DATA
rb_mCairo_ScriptMode DATA
rb_mCairo_MimeType DATA
rb_mCairo_Color DATA
rb_cCairo_Color_Base DATA
rb_cCairo_Paper DATA
rb_cairo_context_from_ruby_object
rb_cairo_context_to_ruby_object
rb_cairo_path_from_ruby_object
rb_cairo_path_to_ruby_object
rb_cairo_matrix_from_ruby_object
rb_cairo_matrix_to_ruby_object
rb_cairo_region_from_ruby_object
rb_cairo_region_to_ruby_object
rb_cairo_pattern_from_ruby_object
rb_cairo_pattern_to_ruby_object
rb_cairo_font_face_from_ruby_object
rb_cairo_font_face_to_ruby_object
rb_cairo_font_extents_from_ruby_object
rb_cairo_font_extents_to_ruby_object
rb_cairo_font_options_to_ruby_object
rb_cairo_font_options_from_ruby_object
rb_cairo_scaled_font_to_ruby_object
rb_cairo_scaled_font_from_ruby_object
rb_cairo_text_extents_from_ruby_object
rb_cairo_text_extents_to_ruby_object
rb_cairo_glyph_from_ruby_object
rb_cairo_glyph_to_ruby_object
rb_cairo_text_cluster_from_ruby_object
rb_cairo_text_cluster_to_ruby_object
rb_cairo_surface_from_ruby_object
rb_cairo_surface_to_ruby_object
rb_cairo_surface_to_ruby_object_with_destroy
rb_cairo_device_from_ruby_object
rb_cairo_device_to_ruby_object
rb_cairo_operator_from_ruby_object
rb_cairo_antialias_from_ruby_object
rb_cairo_fill_rule_from_ruby_object
rb_cairo_line_cap_from_ruby_object
rb_cairo_line_join_from_ruby_object
rb_cairo_font_slant_from_ruby_object
rb_cairo_font_weight_from_ruby_object
rb_cairo_subpixel_order_from_ruby_object
rb_cairo_hint_style_from_ruby_object
rb_cairo_hint_metrics_from_ruby_object
rb_cairo_path_data_type_from_ruby_object
rb_cairo_content_from_ruby_object
rb_cairo_format_from_ruby_object
rb_cairo_extend_from_ruby_object
rb_cairo_filter_from_ruby_object
rb_cairo_svg_version_from_ruby_object
rb_cairo_ps_level_from_ruby_object
rb_cairo_pdf_version_from_ruby_object
rb_cairo_text_cluster_flags_from_ruby_object
rb_cairo_check_status
cairo-1.12.8/ext/cairo/rb_cairo_device.c 0000644 0000041 0000041 00000032056 12256106703 020100 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* Copyright 2010-2012 Kouhei Sutou
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
#include "rb_cairo_io.h"
#ifdef HAVE_RUBY_ST_H
# include
#else
# include
#endif
#ifdef CAIRO_HAS_XML_SURFACE
# include
#endif
#if defined(CAIRO_HAS_SCRIPT_SURFACE) || defined(CAIRO_HAS_XML_SURFACE)
# define NEED_DEFINE_OUTPUT_INITIALIZE 1
#endif
VALUE rb_cCairo_Device = Qnil;
VALUE rb_cCairo_DRMDevice = Qnil;
VALUE rb_cCairo_GLDevice = Qnil;
VALUE rb_cCairo_ScriptDevice = Qnil;
VALUE rb_cCairo_XCBDevice = Qnil;
VALUE rb_cCairo_XlibDevice = Qnil;
VALUE rb_cCairo_XMLDevice = Qnil;
VALUE rb_cCairo_CoglDevice = Qnil;
VALUE rb_cCairo_Win32Device = Qnil;
#if CAIRO_CHECK_VERSION(1, 10, 0)
static cairo_user_data_key_t cr_closure_key;
static cairo_user_data_key_t cr_object_holder_key;
static cairo_user_data_key_t cr_finished_key;
#define _SELF (RVAL2CRDEVICE(self))
static inline void
cr_device_check_status (cairo_device_t *device)
{
rb_cairo_check_status (cairo_device_status (device));
}
static VALUE
cr_device_get_klass (cairo_device_t *device)
{
VALUE klass;
cairo_device_type_t type;
type = cairo_device_get_type (device);
switch (type)
{
case CAIRO_DEVICE_TYPE_DRM:
klass = rb_cCairo_DRMDevice;
break;
case CAIRO_DEVICE_TYPE_GL:
klass = rb_cCairo_GLDevice;
break;
case CAIRO_DEVICE_TYPE_SCRIPT:
klass = rb_cCairo_ScriptDevice;
break;
case CAIRO_DEVICE_TYPE_XCB:
klass = rb_cCairo_XCBDevice;
break;
case CAIRO_DEVICE_TYPE_XLIB:
klass = rb_cCairo_XlibDevice;
break;
case CAIRO_DEVICE_TYPE_XML:
klass = rb_cCairo_XMLDevice;
break;
# if CAIRO_CHECK_VERSION(1, 11, 4)
case CAIRO_DEVICE_TYPE_COGL:
klass = rb_cCairo_CoglDevice;
break;
case CAIRO_DEVICE_TYPE_WIN32:
klass = rb_cCairo_Win32Device;
break;
# endif
default:
klass = rb_cCairo_Device;
break;
}
if (NIL_P (klass))
rb_raise (rb_eArgError, "unknown device type: %d", type);
return klass;
}
static VALUE
cr_device_script_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_SCRIPT_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
static VALUE
cr_device_xml_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_XML_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
/* constructor/de-constructor */
cairo_device_t *
rb_cairo_device_from_ruby_object (VALUE obj)
{
cairo_device_t *device;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_Device))
{
rb_raise (rb_eTypeError, "not a cairo device");
}
Data_Get_Struct (obj, cairo_device_t, device);
if (!device)
rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
return device;
}
#ifdef NEED_DEFINE_OUTPUT_INITIALIZE
static rb_cairo__object_holder_t *
cr_object_holder_new (VALUE object)
{
return rb_cairo__object_holder_new (rb_cCairo_Device, object);
}
static void
cr_object_holder_free (void *ptr)
{
rb_cairo__object_holder_free (rb_cCairo_Device, ptr);
}
#endif
static void
cr_device_free (void *ptr)
{
cairo_device_t *device = ptr;
if (device)
cairo_device_destroy (device);
}
VALUE
rb_cairo_device_to_ruby_object (cairo_device_t *device)
{
if (device)
{
VALUE klass;
klass = cr_device_get_klass (device);
cairo_device_reference (device);
return Data_Wrap_Struct (klass, NULL, cr_device_free, device);
}
else
{
return Qnil;
}
}
VALUE
rb_cairo_device_to_ruby_object_with_destroy (cairo_device_t *device)
{
VALUE rb_device;
rb_device = rb_cairo_device_to_ruby_object (device);
if (device)
cairo_device_destroy (device);
return rb_device;
}
static VALUE
cr_device_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, cr_device_free, NULL);
}
static VALUE
cr_device_initialize (int argc, VALUE *argv, VALUE self)
{
rb_raise(rb_eNotImpError,
"%s class creation isn't supported on this cairo installation",
rb_obj_classname(self));
return Qnil;
}
/* Backend device manipulation */
static VALUE
cr_device_destroy (VALUE self)
{
cairo_device_t *device;
device = _SELF;
cairo_device_destroy (device);
DATA_PTR (self) = NULL;
return self;
}
static VALUE
cr_device_finish (VALUE self)
{
cairo_device_t *device;
rb_cairo__io_callback_closure_t *closure;
device = _SELF;
closure = cairo_device_get_user_data (device, &cr_closure_key);
cairo_device_finish (device);
cairo_device_set_user_data (device, &cr_finished_key, (void *)CR_TRUE, NULL);
cairo_device_set_user_data (device, &cr_object_holder_key, NULL, NULL);
if (closure && !NIL_P (closure->error))
rb_exc_raise (closure->error);
cr_device_check_status (device);
return self;
}
static VALUE
cr_device_flush (VALUE self)
{
cairo_device_flush (_SELF);
cr_device_check_status (_SELF);
return self;
}
static VALUE
cr_device_release (VALUE self)
{
cairo_device_release (_SELF);
cr_device_check_status (_SELF);
return self;
}
static VALUE
cr_device_acquire (VALUE self)
{
cairo_device_acquire (_SELF);
cr_device_check_status (_SELF);
if (rb_block_given_p ())
return rb_ensure (rb_yield, self, cr_device_release, self);
else
return self;
}
static int
cr_finish_all_guarded_devices_at_end_iter (VALUE key, VALUE value, VALUE data)
{
cr_device_finish (key);
return ST_CONTINUE;
}
static void
cr_finish_all_guarded_devices_at_end (VALUE data)
{
rb_hash_foreach (rb_cairo__gc_guarded_objects (rb_cCairo_Device),
cr_finish_all_guarded_devices_at_end_iter,
Qnil);
}
#ifdef NEED_DEFINE_OUTPUT_INITIALIZE
static void
yield_and_finish (VALUE self)
{
cairo_device_t *device;
rb_yield (self);
device = _SELF;
if (!cairo_device_get_user_data (device, &cr_finished_key))
cr_device_finish (self);
}
#endif
#define DEFINE_OUTPUT_INITIALIZE(type) \
static VALUE \
cr_ ## type ## _device_initialize (VALUE self, \
VALUE file_name_or_output) \
{ \
cairo_device_t *device; \
\
if (rb_respond_to (file_name_or_output, rb_cairo__io_id_write)) \
{ \
rb_cairo__io_callback_closure_t *closure; \
\
closure = rb_cairo__io_closure_new (file_name_or_output); \
device = \
cairo_ ## type ## _create_for_stream (rb_cairo__io_write_func, \
(void *)closure); \
if (cairo_device_status (device)) \
{ \
rb_cairo__io_closure_destroy (closure); \
} \
else \
{ \
rb_ivar_set (self, rb_cairo__io_id_output, \
file_name_or_output); \
cairo_device_set_user_data (device, &cr_closure_key, \
closure, \
rb_cairo__io_closure_free); \
cairo_device_set_user_data (device, &cr_object_holder_key, \
cr_object_holder_new (self), \
cr_object_holder_free); \
} \
} \
else \
{ \
const char *file_name; \
file_name = StringValueCStr (file_name_or_output); \
device = cairo_ ## type ## _create (file_name); \
} \
\
cr_device_check_status (device); \
DATA_PTR (self) = device; \
if (rb_block_given_p ()) \
yield_and_finish (self); \
return Qnil; \
}
# ifdef CAIRO_HAS_SCRIPT_SURFACE
DEFINE_OUTPUT_INITIALIZE(script)
static VALUE
cr_script_device_write_comment (VALUE self, VALUE comment)
{
cairo_device_t *device;
device = _SELF;
cairo_script_write_comment (device,
StringValuePtr (comment),
RSTRING_LEN (comment));
cr_device_check_status (device);
return Qnil;
}
static VALUE
cr_script_device_set_mode (VALUE self, VALUE mode)
{
cairo_device_t *device;
device = _SELF;
cairo_script_set_mode (device, RVAL2CRSCRIPTMODE (mode));
cr_device_check_status (device);
return Qnil;
}
static VALUE
cr_script_device_get_mode (VALUE self)
{
return INT2NUM (cairo_script_get_mode (_SELF));
}
static VALUE
cr_script_device_reply (VALUE self, VALUE recording_surface)
{
cairo_device_t *device;
device = _SELF;
cairo_script_from_recording_surface (device,
RVAL2CRSURFACE (recording_surface));
cr_device_check_status (device);
return Qnil;
}
# endif
# ifdef CAIRO_HAS_XML_SURFACE
DEFINE_OUTPUT_INITIALIZE(xml)
static VALUE
cr_xml_device_reply (VALUE self, VALUE recording_surface)
{
cairo_device_t *device;
device = _SELF;
cairo_xml_for_recording_surface (device,
RVAL2CRSURFACE (recording_surface));
cr_device_check_status (device);
return Qnil;
}
# endif
#endif
void
Init_cairo_device (void)
{
#if CAIRO_CHECK_VERSION(1, 10, 0)
rb_cCairo_Device =
rb_define_class_under (rb_mCairo, "Device", rb_cObject);
rb_define_alloc_func (rb_cCairo_Device, cr_device_allocate);
rb_cairo__initialize_gc_guard_holder_class (rb_cCairo_Device);
rb_set_end_proc(cr_finish_all_guarded_devices_at_end, Qnil);
rb_define_singleton_method (rb_cCairo_Device, "script_supported?",
cr_device_script_supported_p, 0);
rb_define_singleton_method (rb_cCairo_Device, "xml_supported?",
cr_device_xml_supported_p, 0);
rb_define_method (rb_cCairo_Device, "initialize", cr_device_initialize, -1);
rb_define_method (rb_cCairo_Device, "destroy", cr_device_destroy, 0);
rb_define_method (rb_cCairo_Device, "finish", cr_device_finish, 0);
rb_define_method (rb_cCairo_Device, "flush", cr_device_flush, 0);
rb_define_method (rb_cCairo_Device, "acquire", cr_device_acquire, 0);
rb_define_method (rb_cCairo_Device, "release", cr_device_release, 0);
RB_CAIRO_DEF_SETTERS (rb_cCairo_Device);
rb_cCairo_DRMDevice =
rb_define_class_under (rb_mCairo, "DRMDevice", rb_cCairo_Device);
rb_cCairo_GLDevice =
rb_define_class_under (rb_mCairo, "GLDevice", rb_cCairo_Device);
rb_cCairo_ScriptDevice =
rb_define_class_under (rb_mCairo, "ScriptDevice", rb_cCairo_Device);
# ifdef CAIRO_HAS_SCRIPT_SURFACE
rb_define_method (rb_cCairo_ScriptDevice, "initialize",
cr_script_device_initialize, 1);
rb_define_method (rb_cCairo_ScriptDevice, "write_comment",
cr_script_device_write_comment, 1);
rb_define_method (rb_cCairo_ScriptDevice, "set_mode",
cr_script_device_set_mode, 1);
rb_define_method (rb_cCairo_ScriptDevice, "mode",
cr_script_device_get_mode, 0);
rb_define_method (rb_cCairo_ScriptDevice, "reply",
cr_script_device_reply, 1);
RB_CAIRO_DEF_SETTERS (rb_cCairo_ScriptDevice);
# endif
rb_cCairo_XCBDevice =
rb_define_class_under (rb_mCairo, "XCBDevice", rb_cCairo_Device);
rb_cCairo_XlibDevice =
rb_define_class_under (rb_mCairo, "XlibDevice", rb_cCairo_Device);
rb_cCairo_XMLDevice =
rb_define_class_under (rb_mCairo, "XMLDevice", rb_cCairo_Device);
# ifdef CAIRO_HAS_XML_SURFACE
rb_define_method (rb_cCairo_XMLDevice, "initialize",
cr_xml_device_initialize, 1);
rb_define_method (rb_cCairo_XMLDevice, "reply",
cr_xml_device_reply, 1);
RB_CAIRO_DEF_SETTERS (rb_cCairo_XMLDevice);
# endif
rb_cCairo_CoglDevice =
rb_define_class_under (rb_mCairo, "CoglDevice", rb_cCairo_Device);
rb_cCairo_Win32Device =
rb_define_class_under (rb_mCairo, "Win32Device", rb_cCairo_Device);
#endif
}
cairo-1.12.8/ext/cairo/rb_cairo_private.h 0000644 0000041 0000041 00000007660 12256106703 020323 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-08-17 07:21:42 $
*
* Copyright 2005-2008 Kouhei Sutou
*
* This file is made available under the same terms as Ruby
*
*/
#ifndef RB_CAIRO_PRIVATE_H
#define RB_CAIRO_PRIVATE_H
#define CR_TRUE 1
#define CR_FALSE 0
#define CAIRO_INT_STATUS_UNSUPPORTED 100
#define CSTR2RVAL(str) rb_str_new2(str)
#define RVAL2CSTR(str) StringValueCStr(str)
#define CBOOL2RVAL(bool) (bool ? Qtrue : Qfalse)
#define RVAL2CBOOL(bool) RTEST(bool)
#ifndef RSTRING_LEN
# define RSTRING_LEN(string) (RSTRING(string)->len)
#endif
#ifndef RARRAY_PTR
# define RARRAY_PTR(array) (RARRAY(array)->ptr)
#endif
#ifndef RARRAY_LEN
# define RARRAY_LEN(array) (RARRAY(array)->len)
#endif
#ifdef HAVE_RB_ERRINFO
# define RB_ERRINFO (rb_errinfo())
#else
# define RB_ERRINFO (ruby_errinfo)
#endif
extern void Init_cairo_private (void);
extern void Init_cairo_io (void);
extern void Init_cairo_constants (void);
extern void Init_cairo_context (void);
extern void Init_cairo_path (void);
extern void Init_cairo_matrix (void);
extern void Init_cairo_region (void);
extern void Init_cairo_device (void);
extern void Init_cairo_surface (void);
extern void Init_cairo_quartz_surface (void);
extern void Init_cairo_exception (void);
extern void Init_cairo_font (void);
extern void Init_cairo_font_extents (void);
extern void Init_cairo_font_options (void);
extern void Init_cairo_scaled_font (void);
extern void Init_cairo_text_extents (void);
extern void Init_cairo_pattern (void);
extern void Init_cairo_glyph (void);
extern void Init_cairo_text_cluster (void);
#define RB_CAIRO__GLYPHS_TO_ARRAY(rb_array, glyphs, length) \
do \
{ \
Check_Type (rb_array, T_ARRAY); \
length = RARRAY_LEN (rb_array); \
glyphs = ALLOCA_N (cairo_glyph_t, length); \
\
if (!glyphs) \
rb_cairo_check_status (CAIRO_STATUS_NO_MEMORY); \
\
rb_cairo__glyphs_to_array (rb_array, glyphs, length); \
} while (0)
VALUE rb_cairo__float_array (double *values, unsigned count);
void rb_cairo__glyphs_to_array (VALUE rb_array, cairo_glyph_t *glyphs, int length);
VALUE rb_cairo__const_get (VALUE name, const char *prefix);
cairo_bool_t rb_cairo__is_kind_of (VALUE object, VALUE klass);
typedef struct rb_cairo__object_holder {
VALUE object;
} rb_cairo__object_holder_t;
rb_cairo__object_holder_t *rb_cairo__object_holder_new (VALUE klass, VALUE object);
void rb_cairo__object_holder_free (VALUE klass, void *ptr);
void rb_cairo__initialize_gc_guard_holder_class (VALUE klass);
void rb_cairo__gc_guard_add (VALUE klass, VALUE object);
void rb_cairo__gc_guard_remove (VALUE klass, VALUE object);
VALUE rb_cairo__gc_guarded_objects (VALUE klass);
const char *rb_cairo__inspect (VALUE object);
#if CAIRO_CHECK_VERSION(1, 7, 2)
VALUE rb_cairo__glyphs_to_ruby_object (cairo_glyph_t *glyphs, int num_glyphs);
void rb_cairo__glyphs_from_ruby_object (VALUE rb_glyphs,
cairo_glyph_t **glyphs, int *num_glyphs);
VALUE rb_cairo__text_clusters_to_ruby_object (cairo_text_cluster_t *clusters,
int num_clusters);
void rb_cairo__text_clusters_from_ruby_object (VALUE rb_clusters,
cairo_text_cluster_t **clusters,
int *num_clusters);
#endif
cairo_status_t rb_cairo__exception_to_status (VALUE exception);
typedef VALUE (*cr_callback_func_t) (VALUE user_data);
VALUE rb_cairo__invoke_callback (cr_callback_func_t func, VALUE user_data);
#endif
cairo-1.12.8/ext/cairo/rb_cairo_scaled_font.c 0000644 0000041 0000041 00000014662 12256106703 021125 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-09-19 12:56:27 $
*
* Copyright 2005-2008 Kouhei Sutou
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
VALUE rb_cCairo_ScaledFont;
#define _SELF(self) (RVAL2CRSCALEDFONT(self))
static inline void
cr_scaled_font_check_status (cairo_scaled_font_t *font)
{
rb_cairo_check_status (cairo_scaled_font_status (font));
}
cairo_scaled_font_t *
rb_cairo_scaled_font_from_ruby_object (VALUE obj)
{
cairo_scaled_font_t *font;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_ScaledFont))
{
rb_raise (rb_eTypeError, "not a cairo scaled font");
}
Data_Get_Struct (obj, cairo_scaled_font_t, font);
return font;
}
static void
cr_scaled_font_free (void *ptr)
{
if (ptr)
{
cairo_scaled_font_destroy ((cairo_scaled_font_t *) ptr);
}
}
VALUE
rb_cairo_scaled_font_to_ruby_object (cairo_scaled_font_t *font)
{
if (font)
{
cairo_scaled_font_reference (font);
return Data_Wrap_Struct (rb_cCairo_ScaledFont, NULL,
cr_scaled_font_free, font);
}
else
{
return Qnil;
}
}
static VALUE
cr_scaled_font_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, cr_scaled_font_free, NULL);
}
static VALUE
cr_scaled_font_initialize (VALUE self, VALUE face, VALUE matrix,
VALUE ctm, VALUE options)
{
cairo_scaled_font_t *font;
font = cairo_scaled_font_create (RVAL2CRFONTFACE (face),
RVAL2CRMATRIX (matrix),
RVAL2CRMATRIX (ctm),
RVAL2CRFONTOPTIONS (options));
cr_scaled_font_check_status (font);
DATA_PTR (self) = font;
return Qnil;
}
static VALUE
cr_scaled_font_extents (VALUE self)
{
cairo_font_extents_t extents;
cairo_scaled_font_extents (_SELF (self), &extents);
cr_scaled_font_check_status (_SELF (self));
return CRFONTEXTENTS2RVAL (&extents);
}
static VALUE
cr_scaled_font_text_extents (VALUE self, VALUE utf8)
{
cairo_text_extents_t extents;
cairo_scaled_font_text_extents (_SELF (self), StringValueCStr (utf8),
&extents);
cr_scaled_font_check_status (_SELF (self));
return CRTEXTEXTENTS2RVAL (&extents);
}
static VALUE
cr_scaled_font_glyph_extents (VALUE self, VALUE rb_glyphs)
{
cairo_text_extents_t extents;
cairo_glyph_t *glyphs;
int count;
RB_CAIRO__GLYPHS_TO_ARRAY (rb_glyphs, glyphs, count);
cairo_scaled_font_glyph_extents (_SELF (self), glyphs, count, &extents);
cr_scaled_font_check_status (_SELF (self));
return CRTEXTEXTENTS2RVAL (&extents);
}
#if CAIRO_CHECK_VERSION(1, 7, 6)
static VALUE
cr_scaled_font_text_to_glyphs (VALUE self, VALUE rb_x, VALUE rb_y, VALUE rb_utf8)
{
double x, y;
const char *utf8;
int utf8_len;
cairo_glyph_t *glyphs = NULL;
int num_glyphs;
cairo_text_cluster_t *clusters = NULL;
int num_clusters;
cairo_text_cluster_flags_t cluster_flags;
cairo_status_t status;
VALUE rb_glyphs, rb_clusters;
x = NUM2DBL (rb_x);
y = NUM2DBL (rb_y);
utf8 = RSTRING_PTR (rb_utf8);
utf8_len = RSTRING_LEN (rb_utf8);
status = cairo_scaled_font_text_to_glyphs (_SELF (self),
x, y, utf8, utf8_len,
&glyphs, &num_glyphs,
&clusters, &num_clusters,
&cluster_flags);
rb_cairo_check_status (status);
rb_glyphs = rb_cairo__glyphs_to_ruby_object (glyphs, num_glyphs);
cairo_glyph_free (glyphs);
rb_clusters = rb_cairo__text_clusters_to_ruby_object (clusters, num_clusters);
cairo_text_cluster_free (clusters);
return rb_ary_new3 (3, rb_glyphs, rb_clusters, INT2NUM (cluster_flags));
}
#endif
static VALUE
cr_scaled_font_get_font_face (VALUE self)
{
cairo_font_face_t *face;
face = cairo_scaled_font_get_font_face (_SELF (self));
cr_scaled_font_check_status (_SELF (self));
return CRFONTFACE2RVAL (face);
}
static VALUE
cr_scaled_font_get_font_matrix (VALUE self)
{
cairo_matrix_t font_matrix;
cairo_scaled_font_get_font_matrix (_SELF (self), &font_matrix);
cr_scaled_font_check_status (_SELF (self));
return CRMATRIX2RVAL (&font_matrix);
}
static VALUE
cr_scaled_font_get_ctm (VALUE self)
{
cairo_matrix_t ctm;
cairo_scaled_font_get_font_matrix (_SELF (self), &ctm);
cr_scaled_font_check_status (_SELF (self));
return CRMATRIX2RVAL (&ctm);
}
static VALUE
cr_scaled_font_get_font_options (VALUE self)
{
cairo_font_options_t *options;
options = cairo_font_options_create();
cairo_scaled_font_get_font_options (_SELF (self), options);
cr_scaled_font_check_status (_SELF (self));
rb_cairo_check_status (cairo_font_options_status (options));
return CRFONTOPTIONS2RVAL (options);
}
#if CAIRO_CHECK_VERSION(1, 7, 2)
static VALUE
cr_scaled_font_get_scale_matrix (VALUE self)
{
cairo_matrix_t matrix;
cairo_scaled_font_get_scale_matrix (_SELF (self), &matrix);
cr_scaled_font_check_status (_SELF (self));
return CRMATRIX2RVAL (&matrix);
}
#endif
void
Init_cairo_scaled_font (void)
{
rb_cCairo_ScaledFont =
rb_define_class_under (rb_mCairo, "ScaledFont", rb_cObject);
rb_define_alloc_func (rb_cCairo_ScaledFont, cr_scaled_font_allocate);
rb_define_method (rb_cCairo_ScaledFont, "initialize",
cr_scaled_font_initialize, 4);
rb_define_method (rb_cCairo_ScaledFont, "extents", cr_scaled_font_extents, 0);
rb_define_method (rb_cCairo_ScaledFont, "text_extents",
cr_scaled_font_text_extents, 1);
rb_define_method (rb_cCairo_ScaledFont, "glyph_extents",
cr_scaled_font_glyph_extents, 1);
#if CAIRO_CHECK_VERSION(1, 7, 2)
rb_define_method (rb_cCairo_ScaledFont, "text_to_glyphs",
cr_scaled_font_text_to_glyphs, 3);
#endif
rb_define_method (rb_cCairo_ScaledFont, "font_face",
cr_scaled_font_get_font_face, 0);
rb_define_method (rb_cCairo_ScaledFont, "font_matrix",
cr_scaled_font_get_font_matrix, 0);
rb_define_method (rb_cCairo_ScaledFont, "ctm", cr_scaled_font_get_ctm, 0);
rb_define_method (rb_cCairo_ScaledFont, "font_options",
cr_scaled_font_get_font_options, 0);
#if CAIRO_CHECK_VERSION(1, 7, 2)
rb_define_method (rb_cCairo_ScaledFont, "scale_matrix",
cr_scaled_font_get_scale_matrix, 0);
#endif
}
cairo-1.12.8/ext/cairo/rb_cairo_exception.c 0000644 0000041 0000041 00000037711 12256106703 020642 0 ustar www-data www-data /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* $Author: kou $
* $Date: 2008-08-16 12:52:16 $
*
* Copyright 2005 Øyvind Kolås
* Copyright 2004-2005 MenTaLguY
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#include "rb_cairo_private.h"
static VALUE rb_eCairo_InvalidRestoreError;
static VALUE rb_eCairo_InvalidPopGroupError;
static VALUE rb_eCairo_NoCurrentPointError;
static VALUE rb_eCairo_InvalidMatrixError;
static VALUE rb_eCairo_InvalidStatusError;
static VALUE rb_eCairo_NullPointerError;
static VALUE rb_eCairo_InvalidStringError;
static VALUE rb_eCairo_InvalidPathDataError;
static VALUE rb_eCairo_ReadError;
static VALUE rb_eCairo_WriteError;
static VALUE rb_eCairo_SurfaceFinishedError;
static VALUE rb_eCairo_SurfaceTypeMismatchError;
static VALUE rb_eCairo_PatternTypeMismatchError;
static VALUE rb_eCairo_InvalidContentError;
static VALUE rb_eCairo_InvalidFormatError;
static VALUE rb_eCairo_InvalidVisualError;
static VALUE rb_eCairo_FileNotFoundError;
static VALUE rb_eCairo_InvalidDashError;
static VALUE rb_eCairo_InvalidDscCommentError;
#if CAIRO_CHECK_VERSION(1, 3, 0)
static VALUE rb_eCairo_InvalidIndexError;
static VALUE rb_eCairo_ClipNotRepresentableError;
#endif
#if CAIRO_CHECK_VERSION(1, 5, 6)
static VALUE rb_eCairo_TempFileError;
static VALUE rb_eCairo_InvalidStrideError;
#endif
#if CAIRO_CHECK_VERSION(1, 7, 2)
static VALUE rb_eCairo_FontTypeMismatch;
static VALUE rb_eCairo_UserFontImmutable;
static VALUE rb_eCairo_UserFontError;
static VALUE rb_eCairo_NegativeCount;
static VALUE rb_eCairo_InvalidClusters;
static VALUE rb_eCairo_InvalidSlant;
static VALUE rb_eCairo_InvalidWeight;
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
static VALUE rb_eCairo_InvalidSize;
static VALUE rb_eCairo_UserFontNotImplemented;
static VALUE rb_eCairo_DeviceTypeMismatch;
static VALUE rb_eCairo_DeviceError;
#endif
#if CAIRO_CHECK_VERSION(1, 11, 2)
static VALUE rb_eCairo_InvalidMeshConstruction;
static VALUE rb_eCairo_DeviceFinished;
#endif
void
rb_cairo_check_status (cairo_status_t status)
{
const char *string = cairo_status_to_string (status);
switch (status)
{
case CAIRO_STATUS_SUCCESS:
break;
case CAIRO_STATUS_NO_MEMORY:
rb_raise (rb_eNoMemError, "%s", string);
break;
case CAIRO_STATUS_INVALID_RESTORE:
rb_raise (rb_eCairo_InvalidRestoreError, "%s", string);
break;
case CAIRO_STATUS_INVALID_POP_GROUP:
rb_raise (rb_eCairo_InvalidPopGroupError, "%s", string);
break;
case CAIRO_STATUS_NO_CURRENT_POINT:
rb_raise (rb_eCairo_NoCurrentPointError, "%s", string);
break;
case CAIRO_STATUS_INVALID_MATRIX:
rb_raise (rb_eCairo_InvalidMatrixError, "%s", string);
break;
case CAIRO_STATUS_INVALID_STATUS:
rb_raise (rb_eCairo_InvalidStatusError, "%s", string);
break;
case CAIRO_STATUS_NULL_POINTER:
rb_raise (rb_eCairo_NullPointerError, "%s", string);
break;
case CAIRO_STATUS_INVALID_STRING:
rb_raise (rb_eCairo_InvalidStringError, "%s", string);
break;
case CAIRO_STATUS_INVALID_PATH_DATA:
rb_raise (rb_eCairo_InvalidPathDataError, "%s", string);
break;
case CAIRO_STATUS_READ_ERROR:
rb_raise (rb_eCairo_ReadError, "%s", string);
break;
case CAIRO_STATUS_WRITE_ERROR:
rb_raise (rb_eCairo_WriteError, "%s", string);
break;
case CAIRO_STATUS_SURFACE_FINISHED:
rb_raise (rb_eCairo_SurfaceFinishedError, "%s", string);
break;
case CAIRO_STATUS_SURFACE_TYPE_MISMATCH:
rb_raise (rb_eCairo_SurfaceTypeMismatchError, "%s", string);
break;
case CAIRO_STATUS_PATTERN_TYPE_MISMATCH:
rb_raise (rb_eCairo_PatternTypeMismatchError, "%s", string);
break;
case CAIRO_STATUS_INVALID_CONTENT:
rb_raise (rb_eCairo_InvalidContentError, "%s", string);
break;
case CAIRO_STATUS_INVALID_FORMAT:
rb_raise (rb_eCairo_InvalidFormatError, "%s", string);
break;
case CAIRO_STATUS_INVALID_VISUAL:
rb_raise (rb_eCairo_InvalidVisualError, "%s", string);
break;
case CAIRO_STATUS_FILE_NOT_FOUND:
rb_raise (rb_eCairo_FileNotFoundError, "%s", string);
break;
case CAIRO_STATUS_INVALID_DASH:
rb_raise (rb_eCairo_InvalidDashError, "%s", string);
break;
case CAIRO_STATUS_INVALID_DSC_COMMENT:
rb_raise (rb_eCairo_InvalidDscCommentError, "%s", string);
break;
#if CAIRO_CHECK_VERSION(1, 3, 0)
case CAIRO_STATUS_INVALID_INDEX:
rb_raise (rb_eCairo_InvalidIndexError, "%s", string);
break;
case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE:
rb_raise (rb_eCairo_ClipNotRepresentableError, "%s", string);
break;
#endif
#if CAIRO_CHECK_VERSION(1, 5, 6)
case CAIRO_STATUS_TEMP_FILE_ERROR:
rb_raise (rb_eCairo_TempFileError, "%s", string);
break;
case CAIRO_STATUS_INVALID_STRIDE:
rb_raise (rb_eCairo_InvalidStringError, "%s", string);
break;
#endif
#if CAIRO_CHECK_VERSION(1, 7, 2)
case CAIRO_STATUS_FONT_TYPE_MISMATCH:
rb_raise (rb_eCairo_FontTypeMismatch, "%s", string);
break;
case CAIRO_STATUS_USER_FONT_IMMUTABLE:
rb_raise (rb_eCairo_UserFontImmutable, "%s", string);
break;
case CAIRO_STATUS_USER_FONT_ERROR:
rb_raise (rb_eCairo_UserFontError, "%s", string);
break;
case CAIRO_STATUS_NEGATIVE_COUNT:
rb_raise (rb_eCairo_NegativeCount, "%s", string);
break;
case CAIRO_STATUS_INVALID_CLUSTERS:
rb_raise (rb_eCairo_InvalidClusters, "%s", string);
break;
case CAIRO_STATUS_INVALID_SLANT:
rb_raise (rb_eCairo_InvalidSlant, "%s", string);
break;
case CAIRO_STATUS_INVALID_WEIGHT:
rb_raise (rb_eCairo_InvalidWeight, "%s", string);
break;
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
case CAIRO_STATUS_INVALID_SIZE:
rb_raise (rb_eCairo_InvalidSize, "%s", string);
break;
case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED:
rb_raise (rb_eCairo_UserFontNotImplemented, "%s", string);
break;
case CAIRO_STATUS_DEVICE_TYPE_MISMATCH:
rb_raise (rb_eCairo_DeviceTypeMismatch, "%s", string);
break;
case CAIRO_STATUS_DEVICE_ERROR:
rb_raise (rb_eCairo_DeviceError, "%s", string);
break;
#endif
#if CAIRO_CHECK_VERSION(1, 11, 2)
case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION:
rb_raise (rb_eCairo_InvalidMeshConstruction, "%s", string);
break;
case CAIRO_STATUS_DEVICE_FINISHED:
rb_raise (rb_eCairo_DeviceFinished, "%s", string);
break;
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
case CAIRO_STATUS_LAST_STATUS:
#else
default:
#endif
rb_raise (rb_eArgError, "bug: %s: %d", string, status);
break;
}
}
cairo_status_t
rb_cairo__exception_to_status (VALUE exception)
{
if (NIL_P (exception))
return CAIRO_STATUS_SUCCESS;
else if (rb_cairo__is_kind_of (exception, rb_eNoMemError))
return CAIRO_STATUS_NO_MEMORY;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidRestoreError))
return CAIRO_STATUS_INVALID_RESTORE;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidPopGroupError))
return CAIRO_STATUS_INVALID_POP_GROUP;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_NoCurrentPointError))
return CAIRO_STATUS_NO_CURRENT_POINT;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidMatrixError))
return CAIRO_STATUS_INVALID_MATRIX;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidStatusError))
return CAIRO_STATUS_INVALID_STATUS;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_NullPointerError))
return CAIRO_STATUS_NULL_POINTER;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidStringError))
return CAIRO_STATUS_INVALID_STRING;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidPathDataError))
return CAIRO_STATUS_INVALID_PATH_DATA;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_ReadError))
return CAIRO_STATUS_READ_ERROR;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_WriteError))
return CAIRO_STATUS_WRITE_ERROR;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_SurfaceFinishedError))
return CAIRO_STATUS_SURFACE_FINISHED;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_SurfaceTypeMismatchError))
return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_PatternTypeMismatchError))
return CAIRO_STATUS_PATTERN_TYPE_MISMATCH;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidContentError))
return CAIRO_STATUS_INVALID_CONTENT;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidFormatError))
return CAIRO_STATUS_INVALID_FORMAT;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidVisualError))
return CAIRO_STATUS_INVALID_VISUAL;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_FileNotFoundError))
return CAIRO_STATUS_FILE_NOT_FOUND;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidDashError))
return CAIRO_STATUS_INVALID_DASH;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidDscCommentError))
return CAIRO_STATUS_INVALID_DSC_COMMENT;
#if CAIRO_CHECK_VERSION(1, 3, 0)
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidIndexError))
return CAIRO_STATUS_INVALID_INDEX;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_ClipNotRepresentableError))
return CAIRO_STATUS_CLIP_NOT_REPRESENTABLE;
#endif
#if CAIRO_CHECK_VERSION(1, 5, 6)
else if (rb_cairo__is_kind_of (exception, rb_eCairo_TempFileError))
return CAIRO_STATUS_TEMP_FILE_ERROR;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidStringError))
return CAIRO_STATUS_INVALID_STRIDE;
#endif
#if CAIRO_CHECK_VERSION(1, 7, 2)
else if (rb_cairo__is_kind_of (exception, rb_eCairo_FontTypeMismatch))
return CAIRO_STATUS_FONT_TYPE_MISMATCH;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_UserFontImmutable))
return CAIRO_STATUS_USER_FONT_IMMUTABLE;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_UserFontError))
return CAIRO_STATUS_USER_FONT_ERROR;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_NegativeCount))
return CAIRO_STATUS_NEGATIVE_COUNT;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidClusters))
return CAIRO_STATUS_INVALID_CLUSTERS;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidSlant))
return CAIRO_STATUS_INVALID_SLANT;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidWeight))
return CAIRO_STATUS_INVALID_WEIGHT;
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidSize))
return CAIRO_STATUS_INVALID_SIZE;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_UserFontNotImplemented))
return CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_DeviceTypeMismatch))
return CAIRO_STATUS_DEVICE_TYPE_MISMATCH;
else if (rb_cairo__is_kind_of (exception, rb_eCairo_DeviceError))
return CAIRO_STATUS_DEVICE_ERROR;
#endif
return -1;
}
void
Init_cairo_exception ()
{
VALUE rb_eCairo_Error;
rb_eCairo_Error =
rb_define_class_under (rb_mCairo, "Error", rb_eStandardError);
rb_eCairo_InvalidRestoreError =
rb_define_class_under (rb_mCairo, "InvalidRestoreError",
rb_eCairo_Error);
rb_eCairo_InvalidPopGroupError =
rb_define_class_under (rb_mCairo, "InvalidPopGroupError",
rb_eCairo_Error);
rb_eCairo_NoCurrentPointError =
rb_define_class_under (rb_mCairo, "NoCurrentPointError",
rb_eCairo_Error);
rb_eCairo_InvalidMatrixError =
rb_define_class_under (rb_mCairo, "InvalidMatrixError",
rb_eArgError);
rb_eCairo_InvalidStatusError =
rb_define_class_under (rb_mCairo, "InvalidStatusError",
rb_eArgError);
rb_eCairo_NullPointerError =
rb_define_class_under (rb_mCairo, "NullPointerError",
rb_eTypeError);
rb_eCairo_InvalidStringError =
rb_define_class_under (rb_mCairo, "InvalidStringError",
rb_eArgError);
rb_eCairo_InvalidPathDataError =
rb_define_class_under (rb_mCairo, "InvalidPathDataError",
rb_eArgError);
rb_eCairo_ReadError =
rb_define_class_under (rb_mCairo, "ReadError",
rb_eIOError);
rb_eCairo_WriteError =
rb_define_class_under (rb_mCairo, "WriteError",
rb_eIOError);
rb_eCairo_SurfaceFinishedError =
rb_define_class_under (rb_mCairo, "SurfaceFinishedError",
rb_eCairo_Error);
rb_eCairo_SurfaceTypeMismatchError =
rb_define_class_under (rb_mCairo, "SurfaceTypeMismatchError",
rb_eTypeError);
rb_eCairo_PatternTypeMismatchError =
rb_define_class_under (rb_mCairo, "PatternTypeMismatchError",
rb_eTypeError);
rb_eCairo_InvalidContentError =
rb_define_class_under (rb_mCairo, "InvalidContentError",
rb_eArgError);
rb_eCairo_InvalidFormatError =
rb_define_class_under (rb_mCairo, "InvalidFormatError",
rb_eArgError);
rb_eCairo_InvalidVisualError =
rb_define_class_under (rb_mCairo, "InvalidVisualError",
rb_eArgError);
rb_eCairo_FileNotFoundError =
rb_define_class_under (rb_mCairo, "FileNotFound",
rb_eCairo_Error);
rb_eCairo_InvalidDashError =
rb_define_class_under (rb_mCairo, "InvalidDashError",
rb_eArgError);
rb_eCairo_InvalidDscCommentError =
rb_define_class_under (rb_mCairo, "InvalidDscCommentError",
rb_eArgError);
#if CAIRO_CHECK_VERSION(1, 3, 0)
rb_eCairo_InvalidIndexError =
rb_define_class_under (rb_mCairo, "InvalidIndexError",
rb_eArgError);
rb_eCairo_ClipNotRepresentableError =
rb_define_class_under (rb_mCairo, "ClipNotRepresentableError",
rb_eCairo_Error);
#endif
#if CAIRO_CHECK_VERSION(1, 5, 6)
rb_eCairo_TempFileError =
rb_define_class_under (rb_mCairo, "TempFileError",
rb_eCairo_Error);
rb_eCairo_InvalidStrideError =
rb_define_class_under (rb_mCairo, "InvalidStrideError",
rb_eArgError);
#endif
#if CAIRO_CHECK_VERSION(1, 7, 2)
rb_eCairo_FontTypeMismatch =
rb_define_class_under (rb_mCairo, "FontTypeMismatch",
rb_eCairo_Error);
rb_eCairo_UserFontImmutable =
rb_define_class_under (rb_mCairo, "UserFontImmutable",
rb_eCairo_Error);
rb_eCairo_UserFontError =
rb_define_class_under (rb_mCairo, "UserFontError",
rb_eCairo_Error);
rb_eCairo_NegativeCount =
rb_define_class_under (rb_mCairo, "NegativeCount",
rb_eCairo_Error);
rb_eCairo_InvalidClusters =
rb_define_class_under (rb_mCairo, "InvalidClusters",
rb_eArgError);
rb_eCairo_InvalidSlant =
rb_define_class_under (rb_mCairo, "InvalidSlant",
rb_eCairo_Error);
rb_eCairo_InvalidWeight =
rb_define_class_under (rb_mCairo, "InvalidWeight",
rb_eArgError);
#endif
#if CAIRO_CHECK_VERSION(1, 10, 0)
rb_eCairo_InvalidSize =
rb_define_class_under (rb_mCairo, "InvalidSize",
rb_eArgError);
rb_eCairo_UserFontNotImplemented =
rb_define_class_under (rb_mCairo, "UserFontNotImplemented",
rb_eCairo_Error);
rb_eCairo_DeviceTypeMismatch =
rb_define_class_under (rb_mCairo, "DeviceTypeMismatch",
rb_eArgError);
rb_eCairo_DeviceError =
rb_define_class_under (rb_mCairo, "DeviceError",
rb_eCairo_Error);
#endif
#if CAIRO_CHECK_VERSION(1, 11, 2)
rb_eCairo_InvalidMeshConstruction =
rb_define_class_under (rb_mCairo, "InvalidMeshConstruction",
rb_eArgError);
rb_eCairo_DeviceFinished =
rb_define_class_under (rb_mCairo, "DeviceFinished",
rb_eCairo_Error);
#endif
}
cairo-1.12.8/ext/cairo/depend 0000644 0000041 0000041 00000000142 12256106703 016006 0 ustar www-data www-data install-so: install-headers
install-headers:
$(INSTALL_DATA) $(srcdir)/rb_cairo.h $(RUBYARCHDIR)
cairo-1.12.8/COPYING 0000644 0000041 0000041 00000005101 12256106703 013762 0 ustar www-data www-data Rcairo is copyrighted free software by the persons listed in AUTHORS
distributed under the same conditions as ruby; which follow:
Ruby is copyrighted free software by Yukihiro Matsumoto .
You can redistribute it and/or modify it under either the terms of the GPL
(see the file GPL), or the conditions below:
1. You may make and give away verbatim copies of the source form of the
software without restriction, provided that you duplicate all of the
original copyright notices and associated disclaimers.
2. You may modify your copy of the software in any way, provided that
you do at least ONE of the following:
a) place your modifications in the Public Domain or otherwise
make them Freely Available, such as by posting said
modifications to Usenet or an equivalent medium, or by allowing
the author to include your modifications in the software.
b) use the modified software only within your corporation or
organization.
c) give non-standard binaries non-standard names, with
instructions on where to get the original software distribution.
d) make other distribution arrangements with the author.
3. You may distribute the software in object code or binary form,
provided that you do at least ONE of the following:
a) distribute the binaries and library files of the software,
together with instructions (in the manual page or equivalent)
on where to get the original distribution.
b) accompany the distribution with the machine-readable source of
the software.
c) give non-standard binaries non-standard names, with
instructions on where to get the original software distribution.
d) make other distribution arrangements with the author.
4. You may modify and include the part of the software into any other
software (possibly commercial). But some files in the distribution
are not written by the author, so that they are not under these terms.
For the list of those files and their copying conditions, see the
file LEGAL.
5. The scripts and library files supplied as input to or produced as
output from the software do not automatically fall under the
copyright of the software, but belong to whomever generated them,
and may be sold commercially, and may be aggregated with this
software.
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.