Class: Quartz::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyquartz/context.rb

Constant Summary collapse

@@ModeNameToNumber =
{
  :fill => 0,
  :eo_fill => 1,
  :stoke => 2,
  :fill_stroke => 3,
  :eo_fill_stroke => 4,
}

Instance Method Summary collapse

Instance Method Details

#add_rounded_rect(rect, radius) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/rubyquartz/context.rb', line 95

def add_rounded_rect(rect, radius)
  top_mid_x = rect.mid_x
  top_mid_y = rect.max_y
  
  top_left_x = rect.min_x
  top_left_y = rect.max_y
  
  top_right_x = rect.max_x
  top_right_y = rect.max_y
  
  bottom_right_x = rect.max_x
  bottom_right_y = rect.min_y
  
  moveto(top_mid_x, top_mid_y)
  arc_to_point(top_left_x, top_left_y, rect.origin.x, rect.origin.y, radius)
  arc_to_point(rect.origin.x, rect.origin.y, bottom_right_x, bottom_right_y, radius)
  arc_to_point(bottom_right_x, bottom_right_y, top_right_x, top_right_y, radius)
  arc_to_point(top_right_x, top_right_y, top_left_x, top_left_y, radius)
  close_path
end

#draw(drawable) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rubyquartz/context.rb', line 65

def draw(drawable)
  case drawable
  when PDFPage
    draw_pdf_page(drawable)
  when Image
    size = drawable.size
    draw_image(0, 0, size.width, size.height, drawable)
  else
    raise "Don't know how to draw #{drawable}"
  end
end

#draw_path(mode) ⇒ Object



53
54
55
# File 'lib/rubyquartz/context.rb', line 53

def draw_path(mode)
  _draw_path(@@ModeNameToNumber[mode])
end

#draw_text(text, options = {}) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rubyquartz/context.rb', line 77

def draw_text(text, options={})
  x = options[:x] || 0
  y = options[:y] || 0
  background = options[:background] || false
  if options[:flip]
    height = text.height_used
    gsave {
      translate(x, y)
      scale(1, -1)
      translate(0, -height)
      _draw_text(text, 0, 0, background)
    }
  else
    _draw_text(text, x, y, background)
  end

end

#fill_rect(*components) ⇒ Object



57
58
59
# File 'lib/rubyquartz/context.rb', line 57

def fill_rect(*components)
  _fill_rect(components[0], components[1], components[2], components[3])
end

#gsaveObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rubyquartz/context.rb', line 39

def gsave
  _gsave
  success = true
  if block_given?
    begin
      yield self
    ensure
      grestore
      success = false
    end
  end
  success
end

#stroke_rect(*components) ⇒ Object



61
62
63
# File 'lib/rubyquartz/context.rb', line 61

def stroke_rect(*components)
  _stroke_rect(components[0], components[1], components[2], components[3])
end