1if not modules then modules = { } end modules ['grph-trf'] = {
2 version = 1.001,
3 comment = "companion to grph-trf.mkiv",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9
10
11local sind, cosd, tand, abs = math.sind, math.cosd, math.tand, math.abs
12
13local isdimen = tex.isdimen
14local setdimension = tex.setdimensionvalue
15
16local d_grph_rotate_x_size <const> = isdimen("d_grph_rotate_x_size")
17local d_grph_rotate_y_size <const> = isdimen("d_grph_rotate_y_size")
18local d_grph_rotate_x_position <const> = isdimen("d_grph_rotate_x_position")
19local d_grph_rotate_y_position <const> = isdimen("d_grph_rotate_y_position")
20local d_grph_rotate_x_offset <const> = isdimen("d_grph_rotate_x_offset")
21local d_grph_rotate_y_offset <const> = isdimen("d_grph_rotate_y_offset")
22local d_grph_rotate_new_width <const> = isdimen("d_grph_rotate_new_width")
23local d_grph_rotate_new_height <const> = isdimen("d_grph_rotate_new_height")
24local d_grph_rotate_new_depth <const> = isdimen("d_grph_rotate_new_depth")
25
26local function analyzerotate(rotation,width,height,depth,total,notfit,obeydepth)
27
28
29
30 rotation = rotation % 360
31 if rotation < 0 then
32 rotation = 360 - rotation
33 end
34
35 local sin = sind(rotation)
36 local cos = cosd(rotation)
37 local abssin = abs(sin)
38 local abscos = abs(cos)
39 local xsize = 0
40 local ysize = 0
41 local xposition = 0
42 local yposition = 0
43 local xoffset = 0
44 local yoffset = 0
45 local newwidth = width
46 local newheight = height
47 local newdepth = depth
48
49 if sin > 0 then
50 if cos > 0 then
51 xsize = cos * width + sin * total
52 ysize = sin * width + cos * total
53 yposition = cos * total
54 if notfit then
55 xoffset = - sin * height
56 newwidth = sin * depth + cos * width
57 else
58 newwidth = xsize + xposition - xoffset
59 end
60 if obeydepth then
61 yoffset = cos * depth
62 end
63 newheight = ysize - yoffset
64 newdepth = yoffset
65
66 else
67 xsize = abscos * width + sin * total
68 ysize = sin * width + abscos * total
69 xposition = abscos * width
70 if notfit then
71 xoffset = - xsize + sin * depth
72 end
73 if obeydepth then
74 yoffset = abscos * height
75 newwidth = abssin * total + abscos * width + xoffset
76 else
77 newwidth = xsize
78 end
79 newheight = ysize - yoffset
80 newdepth = yoffset
81
82 end
83 else
84 if cos < 0 then
85 xsize = abscos * width + abssin * total
86 ysize = abssin * width + abscos * total
87 xposition = xsize
88 yposition = abssin * width
89 if notfit then
90 xoffset = - xsize + abssin * height
91 end
92 if obeydepth then
93 yoffset = ysize + cos * depth
94 end
95 newwidth = notfit and (abssin * height) or xsize
96 newheight = ysize - yoffset
97 newdepth = yoffset
98
99 else
100 xsize = cos * width + abssin * total
101 ysize = abssin * width + cos * total
102 xposition = abssin * total
103 yposition = cos * total
104 if notfit then
105 xoffset = - abssin * depth
106 newwidth = xsize + xoffset
107 else
108 newwidth = xsize
109 end
110 if obeydepth then
111 yoffset = cos * depth
112 end
113 newheight = ysize - yoffset + sin * width
114 newdepth = yoffset - sin * width
115
116 end
117 end
118 setdimension("d_grph_rotate_x_size", xsize)
119 setdimension("d_grph_rotate_y_size", ysize)
120 setdimension("d_grph_rotate_x_position", xposition)
121 setdimension("d_grph_rotate_y_position", yposition)
122 setdimension("d_grph_rotate_x_offset", xoffset)
123 setdimension("d_grph_rotate_y_offset", yoffset)
124 setdimension("d_grph_rotate_new_width", newwidth)
125 setdimension("d_grph_rotate_new_height", newheight)
126 setdimension("d_grph_rotate_new_depth", newdepth)
127end
128
129interfaces.implement {
130 name = "analyzerotate",
131 actions = analyzerotate,
132 arguments = {
133
134 "number",
135 "dimension",
136 "dimension",
137 "dimension",
138 "dimension",
139 "conditional",
140 "conditional",
141 },
142}
143 |