Method: PDF::Writer::Graphics#rounded_rectangle

Defined in:
lib/pdf/writer/graphics.rb

#rounded_rectangle(x, y, w, h, r) ⇒ Object

Draw a rounded rectangle with corners (x, y) and (x + w, y - h) and corner radius r. The radius should be significantly smaller than h and w.

New Point

(x + w, y - h)

Subpath

New



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/pdf/writer/graphics.rb', line 376

def rounded_rectangle(x, y, w, h, r)
  x1 = x
  x2 = x1 + w
  y1 = y
  y2 = y1 - h

  r1 = r
  r2 = r / 2.0

  points = [
    [ x1 + r1, y1,      :line  ],
    [ x2 - r1, y1,      :line  ],
    [ x2 - r2, y1,      :curve ], # cp1
    [ x2,      y1 - r2,        ], # cp2
    [ x2,      y1 - r1,        ], # ep
    [ x2,      y2 + r1, :line  ],
    [ x2,      y2 + r2, :curve ], # cp1
    [ x2 - r2, y2,             ], # cp2
    [ x2 - r1, y2,             ], # ep
    [ x1 + r1, y2,      :line  ],
    [ x1 + r2, y2,      :curve ], # cp1
    [ x1,      y2 + r2,        ], # cp2
    [ x1,      y2 + r1,        ], # ep
    [ x1,      y1 - r1, :line  ],
    [ x1,      y1 - r2, :curve ], # cp1
    [ x1 + r2, y1,             ], # cp2
    [ x1 + r1, y1,             ], # ep
  ]
  polygon(points)
  move_to(x2, y2)
  self
end