Pass r_NoHolesPolygonDicer a POLYAREA *, not a PLINE *
[geda-pcb/gde.git] / src / fontmode.c
blobbd9fcee72039a18476742816b4a516d9066c53eb
1 /* $Id$ */
3 /*
4 * COPYRIGHT
6 * PCB, interactive printed circuit board design
7 * Copyright (C) 2006 DJ Delorie
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Contact addresses for paper mail and Email:
24 * DJ Delorie, 334 North Road, Deerfield NH 03037-1110, USA
25 * dj@delorie.com
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
33 #include "global.h"
35 #include <math.h>
36 #include <memory.h>
37 #include <limits.h>
40 #include "create.h"
41 #include "data.h"
42 #include "draw.h"
43 #include "misc.h"
44 #include "move.h"
45 #include "remove.h"
46 #include "rtree.h"
47 #include "strflags.h"
48 #include "undo.h"
50 #ifdef HAVE_LIBDMALLOC
51 #include <dmalloc.h>
52 #endif
54 RCSID ("$Id$");
56 /* FIXME - we currently hardcode the grid and PCB size. What we
57 should do in the future is scan the font for its extents, and size
58 the grid appropriately. Also, when we convert back to a font, we
59 should search the grid for the gridlines and use them to figure out
60 where the symbols are. */
62 #define CELL_SIZE 10000
63 #define CELL_OFFSET 1000
65 #define XYtoSym(x,y) ((x1 + CELL_OFFSET) / CELL_SIZE - 1 \
66 + 16 * ((y1 + CELL_OFFSET) / CELL_SIZE - 1))
68 static const char fontedit_syntax[] = "FontEdit()";
70 static const char fontedit_help[] =
71 "Convert the current font to a PCB for editing";
73 /* %start-doc actions FontEdit
75 %end-doc */
77 static int
78 FontEdit (int argc, char **argv, int Ux, int Uy)
80 FontType *font;
81 SymbolType *symbol;
82 LayerTypePtr lfont, lorig, lwidth, lgrid;
83 int s, l;
85 if (hid_actionl ("New", "Font", 0))
86 return 1;
88 while (PCB->Data->LayerN > 4)
89 MoveLayer (4, -1);
90 for (l = 0; l < 4; l++)
92 MoveLayerToGroup (l, l);
94 PCB->MaxWidth = CELL_SIZE * 18;
95 PCB->MaxHeight = CELL_SIZE * ((MAX_FONTPOSITION + 15) / 16 + 2);
96 PCB->Grid = 500.0;
97 PCB->Data->Layer[0].Name = MyStrdup ("Font", "FontEdit");
98 PCB->Data->Layer[1].Name = MyStrdup ("OrigFont", "FontEdit");
99 PCB->Data->Layer[2].Name = MyStrdup ("Width", "FontEdit");
100 PCB->Data->Layer[3].Name = MyStrdup ("Grid", "FontEdit");
101 hid_action ("PCBChanged");
102 hid_action ("LayersChanged");
104 lfont = PCB->Data->Layer + 0;
105 lorig = PCB->Data->Layer + 1;
106 lwidth = PCB->Data->Layer + 2;
107 lgrid = PCB->Data->Layer + 3;
109 font = &PCB->Font;
110 for (s = 0; s <= MAX_FONTPOSITION; s++)
112 int ox = (s % 16 + 1) * CELL_SIZE;
113 int oy = (s / 16 + 1) * CELL_SIZE;
114 int w, miny, maxy, maxx = 0;
116 symbol = &font->Symbol[s];
118 miny = 500;
119 maxy = font->MaxHeight;
121 for (l = 0; l < symbol->LineN; l++)
123 CreateDrawnLineOnLayer (lfont,
124 symbol->Line[l].Point1.X + ox,
125 symbol->Line[l].Point1.Y + oy,
126 symbol->Line[l].Point2.X + ox,
127 symbol->Line[l].Point2.Y + oy,
128 symbol->Line[l].Thickness,
129 symbol->Line[l].Thickness, NoFlags ());
130 CreateDrawnLineOnLayer (lorig, symbol->Line[l].Point1.X + ox,
131 symbol->Line[l].Point1.Y + oy,
132 symbol->Line[l].Point2.X + ox,
133 symbol->Line[l].Point2.Y + oy,
134 symbol->Line[l].Thickness,
135 symbol->Line[l].Thickness, NoFlags ());
136 if (maxx < symbol->Line[l].Point1.X)
137 maxx = symbol->Line[l].Point1.X;
138 if (maxx < symbol->Line[l].Point2.X)
139 maxx = symbol->Line[l].Point2.X;
141 w = maxx + symbol->Delta + ox;
142 CreateDrawnLineOnLayer (lwidth,
143 w, miny + oy,
144 w, maxy + oy, 100, 100, NoFlags ());
147 for (l = 0; l < 16; l++)
149 int x = (l + 1) * CELL_SIZE;
150 CreateDrawnLineOnLayer (lgrid, x, 0, x, PCB->MaxHeight, 100, 100,
151 NoFlags ());
153 for (l = 0; l <= MAX_FONTPOSITION / 16 + 1; l++)
155 int y = (l + 1) * CELL_SIZE;
156 CreateDrawnLineOnLayer (lgrid, 0, y, PCB->MaxWidth, y, 100, 100,
157 NoFlags ());
159 return 0;
162 static const char fontsave_syntax[] = "FontSave()";
164 static const char fontsave_help[] = "Convert the current PCB back to a font";
166 /* %start-doc actions FontSave
168 %end-doc */
170 static int
171 FontSave (int argc, char **argv, int Ux, int Uy)
173 FontTypePtr font;
174 SymbolTypePtr symbol;
175 int i;
176 LayerTypePtr lfont, lwidth;
178 font = &PCB->Font;
179 lfont = PCB->Data->Layer + 0;
180 lwidth = PCB->Data->Layer + 2;
182 for (i = 0; i <= MAX_FONTPOSITION; i++)
184 font->Symbol[i].LineN = 0;
185 font->Symbol[i].Valid = 0;
186 font->Symbol[i].Width = 0;
189 for (i = 0; i < lfont->LineN; i++)
191 LineTypePtr l = &lfont->Line[i];
192 int x1 = l->Point1.X;
193 int y1 = l->Point1.Y;
194 int x2 = l->Point2.X;
195 int y2 = l->Point2.Y;
196 int ox, oy, s;
198 s = XYtoSym (x1, y1);
199 ox = (s % 16 + 1) * CELL_SIZE;
200 oy = (s / 16 + 1) * CELL_SIZE;
201 symbol = &PCB->Font.Symbol[s];
203 x1 -= ox;
204 y1 -= oy;
205 x2 -= ox;
206 y2 -= oy;
208 if (symbol->Width < x1)
209 symbol->Width = x1;
210 if (symbol->Width < x2)
211 symbol->Width = x2;
212 symbol->Valid = 1;
214 CreateNewLineInSymbol (symbol, x1, y1, x2, y2, l->Thickness);
217 for (i = 0; i < lwidth->LineN; i++)
219 LineTypePtr l = &lwidth->Line[i];
220 int x1 = l->Point1.X;
221 int y1 = l->Point1.Y;
222 int ox, oy, s;
224 s = XYtoSym (x1, y1);
225 ox = (s % 16 + 1) * CELL_SIZE;
226 oy = (s / 16 + 1) * CELL_SIZE;
227 symbol = &PCB->Font.Symbol[s];
229 x1 -= ox;
231 symbol->Delta = x1 - symbol->Width;
234 SetFontInfo (font);
236 return 0;
239 HID_Action fontmode_action_list[] = {
240 {"FontEdit", 0, FontEdit,
241 fontedit_help, fontedit_syntax},
242 {"FontSave", 0, FontSave,
243 fontsave_help, fontsave_syntax}
246 REGISTER_ACTIONS (fontmode_action_list)