File: rsvg2.rb

package info (click to toggle)
ruby-gnome2 3.1.0-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 16,072 kB
  • ctags: 17,433
  • sloc: ansic: 93,621; ruby: 62,273; xml: 335; sh: 246; makefile: 25
file content (109 lines) | stat: -rw-r--r-- 2,901 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Copyright (C) 2004-2015  Ruby-GNOME2 Project Team
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

require "glib2"
require "gdk_pixbuf2"
require "cairo"

base_dir = Pathname.new(__FILE__).dirname.dirname.expand_path
vendor_dir = base_dir + "vendor" + "local"
vendor_bin_dir = vendor_dir + "bin"
GLib.prepend_dll_path(vendor_bin_dir)

if vendor_dir.exist?
  require "pango"

  gdk_pixbuf2_spec = Gem.loaded_specs["gdk_pixbuf2"]
  gdk_pixbuf2_base_dir = Pathname.new(gdk_pixbuf2_spec.gem_dir)
  gdk_pixbuf2_module_dir =
    gdk_pixbuf2_base_dir + "vendor" + "local" + "lib" +
    "gdk-pixbuf-2.0" + "2.10.0"
  gdk_pixbuf2_loaders_cache_path = gdk_pixbuf2_module_dir + "loaders.cache"
  need_loaders_cache_update = false
  if gdk_pixbuf2_loaders_cache_path.exist?
    gdk_pixbuf2_loaders_cache_path.open do |cache|
      need_loaders_cache_update = cache.each_line.none? do |line|
        /\A"svg"/ === line
      end
    end
  else
    need_loaders_cache_update = true
  end
  if need_loaders_cache_update
    pid = spawn("gdk-pixbuf-query-loaders.exe",
                :out => [gdk_pixbuf2_loaders_cache_path.to_s, "w"])
    Process.waitpid(pid)
  end
end

begin
  major, minor, = RUBY_VERSION.split(/\./)
  require "#{major}.#{minor}/rsvg2.so"
rescue LoadError
  require "rsvg2.so"
end

module RSVG
  LOG_DOMAIN = "librsvg"

  class << self
    def cairo_available?
      true
    end
  end

  class Handle
    class << self
      # For backward compatibility
      def new_from_data(data)
        new(:data => data)
      end

      # For backward compatibility
      def new_from_file(file_name, options={})
        new(options.merge(:file_name => file_name))
      end
    end
  end

  module Version
    MAJOR, MINOR, MICRO = BUILD_VERSION
    STRING = "#{MAJOR}.#{MINOR}.#{MICRO}"

    class << self
      def or_later?(major, minor, micro=nil)
        micro || 0
        version = [
          MAJOR,
          MINOR,
          MICRO,
        ]
        (version <=> [major, minor, micro]) >= 0
      end
    end
  end

end

module Cairo
  class Context
    def render_rsvg_handle(handle, *args, &block)
      handle.render_cairo(self, *args, &block)
    end
  end
end

GLib::Log.set_log_domain(RSVG::LOG_DOMAIN)