Module: Cairo

Defined in:
lib/tagen/cairo.rb,
lib/tagen/cairo.rb

Overview

  • *Install*: gem(cairo)

a wrap to Cairo.

this library is deprecated, please don't use it.

Defined Under Namespace

Classes: Context, FontExtents, ImageSurface, PDFSurface, TextExtents

Class Method Summary (collapse)

Class Method Details

+ (Array<Numeric>) compute_wh(w, h, rotate = 0, scale = 1)

compute width height by rotate and scale

Parameters:

Returns:



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
# File 'lib/tagen/cairo.rb', line 34

def self.compute_wh(w, h, rotate=0,scale=1) 
# selection=[x,y,w,h]
	w,h=1,1 if w<=0 or h<=0
	w,h = w*scale.to_f, h*scale.to_f

	radius = 0

	rotate = rotate*180/Math::PI if String===rotate
	rotate %= 360

	unless rotate.zero?
		radius = rotate / 180.0 * Math::PI
		if (90 < rotate and rotate < 180) or (270 < rotate and rotate < 360)
			radius -= Math::PI / 2
		end
	end
	inner_angle1 = Math.atan(w/h)
	inner_angle2 = Math.atan(h/w)
	diagonal = Math.sqrt(w**2 + h**2)

	angle1 = radius + inner_angle1
	angle2 = radius + inner_angle2

	bottom1 = diagonal * Math.cos(angle1)
	length1 = (bottom1 * Math.tan(angle1)).abs.to_up
	bottom2 = diagonal * Math.cos(angle2)
	length2 = (bottom2 * Math.tan(angle2)).abs.to_up

	if (0 <= rotate and rotate <= 90) or (180 <= rotate and rotate <= 270)
		[length1, length2]
	else
		[length2, length1]
	end
end