forked from rmanohar/layout
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathattrib.h
More file actions
169 lines (146 loc) · 4.13 KB
/
attrib.h
File metadata and controls
169 lines (146 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*************************************************************************
*
* Copyright (c) 2024 Rajit Manohar
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
**************************************************************************
*/
#ifndef __ACT_LAYOUT_ATTRIB_H__
#define __ACT_LAYOUT_ATTRIB_H__
class TransformMat;
/*
* These are used as alignment markers. They can be used for an umber
* of different purposes, including multi-deck gridded cells.
*
* **Currently only using an attrib_list of length at most 1 until we
* include multi-deck support**
*
* Alignment marker offsets are in the local coordinate system of the
* paint.
*
*/
class LayoutEdgeAttrib {
public:
struct attrib_list {
const char *name;
long offset; // this offset is relative to assuming
// the bottom left corner of the
// actual layout bounding box is (0,0).
struct attrib_list *next;
};
private:
/* at the moment, we have the same attribute for the horizontal edge
as the vertical edge
*/
attrib_list *_left, *_right, *_top, *_bot;
attrib_list *dup (attrib_list *l, long adj = 0);
/*
Merge y into x.
Both lists have to be sorted by offset.
*/
bool merge (attrib_list **x, attrib_list *y);
void freelist (attrib_list *l);
public:
LayoutEdgeAttrib() {
_left = NULL;
_right = NULL;
_top = NULL;
_bot = NULL;
}
~LayoutEdgeAttrib() {
clear ();
}
void mkCopy (LayoutEdgeAttrib &le) {
clearleft ();
clearright ();
cleartop ();
clearbot ();
_left = dup (le._left);
_right = dup (le._right);
_top = dup (le._top);
_bot = dup (le._bot);
}
void clearleft() {
freelist (_left);
_left = NULL;
}
void clearright() {
freelist (_right);
_right = NULL;
}
void cleartop() {
freelist (_top);
_top = NULL;
}
void clearbot() {
freelist (_bot);
_bot = NULL;
}
void clear () {
clearleft();
clearright();
cleartop();
clearbot();
}
attrib_list *left() { return _left; }
attrib_list *right() { return _right; }
attrib_list *top() { return _top; }
attrib_list *bot() { return _bot; }
static void print (FILE *fp, attrib_list *l);
/* compute alignment between two sets of markers; returns amt that
should be added to l2 to get to l1's offset */
/* XXX: when we support multiple independent attributes, we will
need multiple shift amounts for alignment
*/
static bool align (attrib_list *l1, attrib_list *l2, long *amt);
void setleft(attrib_list *x, long adj = 0) {
clearleft();
_left = dup (x, adj);
}
void setright(attrib_list *x, long adj = 0) {
clearright();
_right = dup(x, adj);
}
void settop(attrib_list *x, long adj = 0) {
cleartop();
_top = dup (x, adj);
}
void setbot(attrib_list *x, long adj = 0) {
clearbot();
_bot = dup (x, adj);
}
bool mergeleft(attrib_list *x, long adj = 0) {
return merge (&_left, dup (x, adj));
}
bool mergeright(attrib_list *x, long adj = 0) {
return merge (&_right, dup (x, adj));
}
bool mergetop(attrib_list *x, long adj = 0) {
return merge (&_top, dup (x, adj));
}
bool mergebot(attrib_list *x, long adj = 0) {
return merge (&_bot, dup (x, adj));
}
void swaplr ();
void swaptb ();
void swap45();
attrib_list *flipsign (attrib_list *x);
void adjust (attrib_list *x, long adj);
LayoutEdgeAttrib *Clone();
LayoutEdgeAttrib *Clone (TransformMat *m);
};
#endif /* __ACT_LAYOUT_ATTRIB_H__ */