Class: Squib::Graphics::CairoContextWrapper Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/squib/graphics/cairo_context_wrapper.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Wrapper class for the Cairo context. Private.

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cairo_cxt) ⇒ CairoContextWrapper

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:

API:

  • private



17
18
19
# File 'lib/squib/graphics/cairo_context_wrapper.rb', line 17

def initialize(cairo_cxt)
  @cairo_cxt = cairo_cxt
end

Instance Attribute Details

#cairo_cxtObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:

API:

  • private



13
14
15
# File 'lib/squib/graphics/cairo_context_wrapper.rb', line 13

def cairo_cxt
  @cairo_cxt
end

Instance Method Details

#fancy_stroke(draw) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convenience method for a common task

API:

  • private



86
87
88
89
90
91
92
93
# File 'lib/squib/graphics/cairo_context_wrapper.rb', line 86

def fancy_stroke(draw)
  set_source_squibcolor draw.stroke_color
  set_line_width draw.stroke_width
  set_line_join draw.join
  set_line_cap draw.cap
  set_dash draw.dash
  stroke
end

#fill_n_stroke(draw) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convenience method for a common task

API:

  • private



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/squib/graphics/cairo_context_wrapper.rb', line 60

def fill_n_stroke(draw)
  return stroke_n_fill(draw) if draw.stroke_strategy == :stroke_first
  set_source_squibcolor draw.fill_color
  fill_preserve
  set_source_squibcolor draw.stroke_color
  set_line_width draw.stroke_width
  set_line_join draw.join
  set_line_cap draw.cap
  set_dash draw.dash
  stroke
end

#flip(vertical, horizontal, x, y) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Flip either vertical or horizontal depending From the cairo website: cairographics.org/matrix_transform/ cairo.Matrix(fx, 0, 0,

fy, cx*(1-fx), cy*(fy-1))

fx/fy = 1 means ‘no flip’, fx/fy = -1 are used for horizontal/vertical flip

API:

  • private



106
107
108
109
110
111
# File 'lib/squib/graphics/cairo_context_wrapper.rb', line 106

def flip(vertical, horizontal, x, y)
  v = vertical   ? -1.0 : 1.0
  h = horizontal ? -1.0 : 1.0
  transform Cairo::Matrix.new(v, 0.0,     0.0,
                              h, x * (1 - v), y * (1 - h))
end

#rotate_about(x, y, angle) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



95
96
97
98
99
# File 'lib/squib/graphics/cairo_context_wrapper.rb', line 95

def rotate_about(x, y, angle)
  translate(x, y)
  rotate(angle)
  translate(-x, -y)
end

#set_source_squibcolor(arg) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:

API:

  • private



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/squib/graphics/cairo_context_wrapper.rb', line 34

def set_source_squibcolor(arg)
  raise 'nil is not a valid color' if arg.nil?
  if match = arg.match(LINEAR_GRADIENT)
    x1, y1, x2, y2 = match.captures
    linear = Cairo::LinearPattern.new(x1.to_f, y1.to_f, x2.to_f, y2.to_f)
    arg.scan(STOPS).each do |color, offset|
      linear.add_color_stop(offset.to_f, color)
    end
    linear.matrix = matrix # match the coordinate systems - see bug 127

    @cairo_cxt.set_source(linear)
  elsif match = arg.match(RADIAL_GRADIENT)
    x1, y1, r1, x2, y2, r2 = match.captures
    radial = Cairo::RadialPattern.new(x1.to_f, y1.to_f, r1.to_f,
                                      x2.to_f, y2.to_f, r2.to_f)
    radial.matrix = matrix # match the coordinate systems - see bug 127

    arg.scan(STOPS).each do |color, offset|
      radial.add_color_stop(offset.to_f, color)
    end
    @cairo_cxt.set_source(radial)
  else
    @cairo_cxt.set_source_color(arg)
  end
end

#stroke_n_fill(draw) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/squib/graphics/cairo_context_wrapper.rb', line 72

def stroke_n_fill(draw)
  return fill_n_stroke(draw) if draw.stroke_strategy == :fill_first
  set_source_squibcolor draw.stroke_color
  set_line_width draw.stroke_width
  set_line_join draw.join
  set_line_cap draw.cap
  set_dash draw.dash
  stroke_preserve
  set_source_squibcolor draw.fill_color
  fill
end