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