-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfontmode.c
246 lines (202 loc) · 6.03 KB
/
fontmode.c
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/* $Id$ */
/*
* COPYRIGHT
*
* PCB, interactive printed circuit board design
* Copyright (C) 2006 DJ Delorie
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Contact addresses for paper mail and Email:
* DJ Delorie, 334 North Road, Deerfield NH 03037-1110, USA
* dj@delorie.com
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "global.h"
#include <math.h>
#include <memory.h>
#include <limits.h>
#include "create.h"
#include "data.h"
#include "draw.h"
#include "misc.h"
#include "move.h"
#include "remove.h"
#include "rtree.h"
#include "strflags.h"
#include "undo.h"
#ifdef HAVE_LIBDMALLOC
#include <dmalloc.h>
#endif
RCSID ("$Id$");
/* FIXME - we currently hardcode the grid and PCB size. What we
should do in the future is scan the font for its extents, and size
the grid appropriately. Also, when we convert back to a font, we
should search the grid for the gridlines and use them to figure out
where the symbols are. */
#define CELL_SIZE 10000
#define CELL_OFFSET 1000
#define XYtoSym(x,y) ((x1 + CELL_OFFSET) / CELL_SIZE - 1 \
+ 16 * ((y1 + CELL_OFFSET) / CELL_SIZE - 1))
static const char fontedit_syntax[] = "FontEdit()";
static const char fontedit_help[] =
"Convert the current font to a PCB for editing";
/* %start-doc actions FontEdit
%end-doc */
static int
FontEdit (int argc, char **argv, int Ux, int Uy)
{
FontType *font;
SymbolType *symbol;
LayerTypePtr lfont, lorig, lwidth, lgrid;
int s, l;
if (hid_actionl ("New", "Font", 0))
return 1;
while (PCB->Data->LayerN > 4)
MoveLayer (4, -1);
for (l = 0; l < 4; l++)
{
MoveLayerToGroup (l, l);
}
PCB->MaxWidth = CELL_SIZE * 18;
PCB->MaxHeight = CELL_SIZE * ((MAX_FONTPOSITION + 15) / 16 + 2);
PCB->Grid = 500.0;
PCB->Data->Layer[0].Name = strdup ("Font");
PCB->Data->Layer[1].Name = strdup ("OrigFont");
PCB->Data->Layer[2].Name = strdup ("Width");
PCB->Data->Layer[3].Name = strdup ("Grid");
hid_action ("PCBChanged");
hid_action ("LayersChanged");
lfont = PCB->Data->Layer + 0;
lorig = PCB->Data->Layer + 1;
lwidth = PCB->Data->Layer + 2;
lgrid = PCB->Data->Layer + 3;
font = &PCB->Font;
for (s = 0; s <= MAX_FONTPOSITION; s++)
{
int ox = (s % 16 + 1) * CELL_SIZE;
int oy = (s / 16 + 1) * CELL_SIZE;
int w, miny, maxy, maxx = 0;
symbol = &font->Symbol[s];
miny = 500;
maxy = font->MaxHeight;
for (l = 0; l < symbol->LineN; l++)
{
CreateDrawnLineOnLayer (lfont,
symbol->Line[l].Point1.X + ox,
symbol->Line[l].Point1.Y + oy,
symbol->Line[l].Point2.X + ox,
symbol->Line[l].Point2.Y + oy,
symbol->Line[l].Thickness,
symbol->Line[l].Thickness, NoFlags ());
CreateDrawnLineOnLayer (lorig, symbol->Line[l].Point1.X + ox,
symbol->Line[l].Point1.Y + oy,
symbol->Line[l].Point2.X + ox,
symbol->Line[l].Point2.Y + oy,
symbol->Line[l].Thickness,
symbol->Line[l].Thickness, NoFlags ());
if (maxx < symbol->Line[l].Point1.X)
maxx = symbol->Line[l].Point1.X;
if (maxx < symbol->Line[l].Point2.X)
maxx = symbol->Line[l].Point2.X;
}
w = maxx + symbol->Delta + ox;
CreateDrawnLineOnLayer (lwidth,
w, miny + oy,
w, maxy + oy, 100, 100, NoFlags ());
}
for (l = 0; l < 16; l++)
{
int x = (l + 1) * CELL_SIZE;
CreateDrawnLineOnLayer (lgrid, x, 0, x, PCB->MaxHeight, 100, 100,
NoFlags ());
}
for (l = 0; l <= MAX_FONTPOSITION / 16 + 1; l++)
{
int y = (l + 1) * CELL_SIZE;
CreateDrawnLineOnLayer (lgrid, 0, y, PCB->MaxWidth, y, 100, 100,
NoFlags ());
}
return 0;
}
static const char fontsave_syntax[] = "FontSave()";
static const char fontsave_help[] = "Convert the current PCB back to a font";
/* %start-doc actions FontSave
%end-doc */
static int
FontSave (int argc, char **argv, int Ux, int Uy)
{
FontTypePtr font;
SymbolTypePtr symbol;
int i;
LayerTypePtr lfont, lwidth;
font = &PCB->Font;
lfont = PCB->Data->Layer + 0;
lwidth = PCB->Data->Layer + 2;
for (i = 0; i <= MAX_FONTPOSITION; i++)
{
font->Symbol[i].LineN = 0;
font->Symbol[i].Valid = 0;
font->Symbol[i].Width = 0;
}
for (i = 0; i < lfont->LineN; i++)
{
LineTypePtr l = &lfont->Line[i];
int x1 = l->Point1.X;
int y1 = l->Point1.Y;
int x2 = l->Point2.X;
int y2 = l->Point2.Y;
int ox, oy, s;
s = XYtoSym (x1, y1);
ox = (s % 16 + 1) * CELL_SIZE;
oy = (s / 16 + 1) * CELL_SIZE;
symbol = &PCB->Font.Symbol[s];
x1 -= ox;
y1 -= oy;
x2 -= ox;
y2 -= oy;
if (symbol->Width < x1)
symbol->Width = x1;
if (symbol->Width < x2)
symbol->Width = x2;
symbol->Valid = 1;
CreateNewLineInSymbol (symbol, x1, y1, x2, y2, l->Thickness);
}
for (i = 0; i < lwidth->LineN; i++)
{
LineTypePtr l = &lwidth->Line[i];
int x1 = l->Point1.X;
int y1 = l->Point1.Y;
int ox, oy, s;
s = XYtoSym (x1, y1);
ox = (s % 16 + 1) * CELL_SIZE;
oy = (s / 16 + 1) * CELL_SIZE;
symbol = &PCB->Font.Symbol[s];
x1 -= ox;
symbol->Delta = x1 - symbol->Width;
}
SetFontInfo (font);
return 0;
}
HID_Action fontmode_action_list[] = {
{"FontEdit", 0, FontEdit,
fontedit_help, fontedit_syntax},
{"FontSave", 0, FontSave,
fontsave_help, fontsave_syntax}
};
REGISTER_ACTIONS (fontmode_action_list)