grph-trf.lmt /size: 4841 b    last modification: 2023-12-21 09:44
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-- see grph-trf-todo.lua for older preliminary code for the rest
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     = isdimen("d_grph_rotate_x_size")
17local d_grph_rotate_y_size     = isdimen("d_grph_rotate_y_size")
18local d_grph_rotate_x_position = isdimen("d_grph_rotate_x_position")
19local d_grph_rotate_y_position = isdimen("d_grph_rotate_y_position")
20local d_grph_rotate_x_offset   = isdimen("d_grph_rotate_x_offset")
21local d_grph_rotate_y_offset   = isdimen("d_grph_rotate_y_offset")
22local d_grph_rotate_new_width  = isdimen("d_grph_rotate_new_width")
23local d_grph_rotate_new_height = isdimen("d_grph_rotate_new_height")
24local d_grph_rotate_new_depth  = isdimen("d_grph_rotate_new_depth")
25
26local function analyzerotate(rotation,width,height,depth,total,notfit,obeydepth)
27    --
28 -- print(rotation,width,height,depth,notfit,obeydepth)
29    --
30    local sin       = sind(rotation)
31    local cos       = cosd(rotation)
32    local abssin    = abs(sin)
33    local abscos    = abs(cos)
34    local xsize     = 0
35    local ysize     = 0
36    local xposition = 0
37    local yposition = 0
38    local xoffset   = 0
39    local yoffset   = 0
40    local newwidth  = width
41    local newheight = height
42    local newdepth  = depth
43 -- print(sin,cos)
44    if sin > 0 then
45        if cos > 0 then
46            xsize     = cos * width + sin * total
47            ysize     = sin * width + cos * total
48            yposition =               cos * total
49            if notfit then
50                xoffset  = - sin * height
51                newwidth = sin * depth + cos * width
52            else
53                newwidth = xsize + xposition - xoffset
54            end
55            if obeydepth then
56                yoffset = cos * depth
57            end
58            newheight = ysize - yoffset
59            newdepth  = yoffset
60         -- print("case 1, done")
61        else
62            xsize     = abscos * width +    sin * total
63            ysize     =    sin * width + abscos * total
64            xposition = abscos * width
65            if notfit then
66                xoffset = - xsize + sin * depth
67            end
68            if obeydepth then
69                yoffset  = abscos * height
70                newwidth = abssin * total + abscos * width + xoffset
71            else
72                newwidth = xsize
73            end
74            newheight = ysize - yoffset
75            newdepth  = yoffset
76         -- print("case 2, done")
77        end
78    else
79        if cos < 0 then
80            xsize     = abscos * width + abssin * total
81            ysize     = abssin * width + abscos * total
82            xposition = xsize
83            yposition = abssin * width
84            if notfit then
85                xoffset = - xsize + abssin * height
86            end
87            if obeydepth then
88                yoffset = ysize + cos * depth
89            end
90            newwidth  = notfit and (abssin * height) or xsize
91            newheight = ysize - yoffset
92            newdepth  = yoffset
93         -- print("case 3, done")
94        else
95            xsize     =    cos * width + abssin * total
96            ysize     = abssin * width +    cos * total
97            xposition =                  abssin * total
98            yposition =                     cos * total
99            if notfit then
100                xoffset = - abssin * depth
101                newwidth = xsize + xoffset
102            else
103                newwidth = xsize
104            end
105            if obeydepth then
106                yoffset = cos * depth
107            end
108            newheight = ysize - yoffset + sin * width
109            newdepth  =         yoffset - sin * width
110         -- print("case 4, done")
111        end
112    end
113    setdimension("d_grph_rotate_x_size",     xsize)
114    setdimension("d_grph_rotate_y_size",     ysize)
115    setdimension("d_grph_rotate_x_position", xposition)
116    setdimension("d_grph_rotate_y_position", yposition)
117    setdimension("d_grph_rotate_x_offset",   xoffset)
118    setdimension("d_grph_rotate_y_offset",   yoffset)
119    setdimension("d_grph_rotate_new_width",  newwidth)
120    setdimension("d_grph_rotate_new_height", newheight)
121    setdimension("d_grph_rotate_new_depth",  newdepth)
122end
123
124interfaces.implement {
125    name      = "analyzerotate",
126    actions   = analyzerotate,
127    arguments = {
128--         "integer",
129        "number",
130        "dimension",
131        "dimension",
132        "dimension",
133        "dimension",
134        "conditional",
135        "conditional",
136    },
137}
138