xfigimport.cpp
1/*
2 Copyright (C) 1998 Kai-Uwe Sattler <kus@iti.cs.uni-magdeburg.de>
3 Copyright (C) 2001, Rob Buis <rwlbuis@wanadoo.nl>
4 Copyright (C) 2003, Rob Buis <buis@kde.org>
5 This file is part of the KDE project
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21
22DESCRIPTION
23*/
24
25#include <assert.h>
26#include <fstream.h>
27#include <limits.h>
28#include <math.h>
29
30#include <GDocument.h>
31#include <GPage.h>
32#include <GGroup.h>
33#include <GPolyline.h>
34#include <GOval.h>
35#include <GPolygon.h>
36#include <GText.h>
37#include <xfigimport.h>
38#include <xfigimport.moc>
39
40#include <tqtl.h>
41#include <kdebug.h>
42
43#include <core/vdocument.h>
44namespace std { };
45using namespace std;
46
47#define RAD_FACTOR 180.0 / M_PI
48
49unsigned int colors[] = {
50 0x000090,
51 0x0000b0,
52 0x0000d0,
53 0x87ceff,
54 0x009000,
55 0x00b000,
56 0x00d000,
57 0x009090,
58 0x00b0b0,
59 0x00d0d0,
60 0x900000,
61 0xb00000,
62 0xd00000,
63 0x900090,
64 0xb000b0,
65 0xd000d0,
66 0x803000,
67 0xa04000,
68 0xc06000,
69 0xff8080,
70 0xffa0a0,
71 0xffc0c0,
72 0xffe0e0,
73 0xffd700
74};
75
76int arrow_ids[] = {
77 6, 1, 2, 7
78};
79
80struct PSFont {
81 const char* family;
82 TQFont::Weight weight;
83 bool italic;
84} psFontTable[] = {
85 { "times", TQFont::Normal, false }, // Times Roman
86 { "times", TQFont::Normal, true }, // Times Italic
87 { "times", TQFont::Bold, false }, // Times Bold
88 { "times", TQFont::Bold, true }, // Times Bold Italic
89 { "avantgarde", TQFont::Normal, false }, // AvantGarde Book
90 { "avantgarde", TQFont::Normal, true }, // AvantGarde Book Oblique
91 { "avantgarde", TQFont::DemiBold, false }, // AvantGarde Demi
92 { "avantgarde", TQFont::DemiBold, true }, // AvantGarde Demi Oblique
93 { "bookman", TQFont::Light, false }, // Bookman Light
94 { "bookman", TQFont::Light, true }, // Bookman Light Italic
95 { "bookman", TQFont::DemiBold, false }, // Bookman Demi
96 { "bookman", TQFont::DemiBold, true }, // Bookman Demi Italic
97 { "courier", TQFont::Normal, false }, // Courier
98 { "courier", TQFont::Normal, true }, // Courier Oblique
99 { "courier", TQFont::Bold, false }, // Courier Bold
100 { "courier", TQFont::Bold, true }, // Courier Bold Oblique
101 { "helvetica", TQFont::Normal, false }, // Helvetica
102 { "helvetica", TQFont::Normal, true }, // Helvetica Oblique
103 { "helvetica", TQFont::Bold, false }, // Helvetica Bold
104 { "helvetica", TQFont::Bold, true }, // Helvetica Bold Oblique
105 { "helvetica", TQFont::Normal, false }, // Helvetica Narrow
106 { "helvetica", TQFont::Normal, true }, // Helvetica Narrow Oblique
107 { "helvetica", TQFont::Bold, false }, // Helvetica Narrow Bold
108 { "helvetica", TQFont::Bold, true }, // Helvetica Narrow Bold Oblique
109 { "newcenturyschoolbook", TQFont::Normal, false },// New Century Schoolbook
110 { "newcenturyschoolbook", TQFont::Normal, true }, // New Century Italic
111 { "newcenturyschoolbook", TQFont::Bold, false }, // New Century Bold
112 { "newcenturyschoolbook", TQFont::Bold, true }, // New Century Bold Italic
113 { "palatino", TQFont::Normal, false }, // Palatino Roman
114 { "palatino", TQFont::Normal, true }, // Palatino Italic
115 { "palatino", TQFont::Bold, false }, // Palatino Bold
116 { "palatino", TQFont::Bold, true }, // Palatino Bold Italic
117 { "symbol", TQFont::Normal, false }, // Symbol
118 { "zapfchancery", TQFont::Normal, false }, // Zapf Chancery Medium Italic
119 { "zapfdingbats", TQFont::Normal, false }, // Zapf Dingbats
120};
121
122int hexstrToInt (const char *str) {
123 const int fak[] = { 16, 1 };
124 int value = 0, v;
125
126 for (int i = 0; i < 2; i++) {
127 if (str[i] >= '0' && str[i] <= '9')
128 v = str[i] - '0';
129 else
130 v = str[i] - 'a' + 10;
131 value += v * fak[i];
132 }
133
134 return value;
135}
136
137XFIGImport::XFIGImport( KoFilter *parent, const char *name ) : KoFilter(parent, name)
138{
139 fig_resolution = 1200.0 / 72.0;
140 coordinate_system = 2;
141
142 colorTable.insert (0, new TQColor (TQt::black));
143 colorTable.insert (1, new TQColor (TQt::blue));
144 colorTable.insert (2, new TQColor (TQt::green));
145 colorTable.insert (3, new TQColor (TQt::cyan));
146 colorTable.insert (4, new TQColor (TQt::red));
147 colorTable.insert (5, new TQColor (TQt::magenta));
148 colorTable.insert (6, new TQColor (TQt::yellow));
149 colorTable.insert (7, new TQColor (TQt::white));
150
151 for (int i = 0; i <= 23; i++)
152 colorTable.insert (i + 8, new TQColor (colors[i]));
153
154 objList.clear ();
155}
156
157XFIGImport::~XFIGImport()
158{
159}
160
161bool XFIGImport::filterImport( const TQString &file, KoDocument *doc,
162 const TQString &from, const TQString &to,
163 const TQString & ) {
164
165 if( to != "application/x-karbon" || from != "image/x-xfig" )
166 return false;
167
168 char buf[255];
169 int value;
170 KoPageLayout layout;
171
172 ifstream fin( file.local8Bit() );
173 if (! fin)
174 return false;
175
176 KIllustratorDocument *kidoc = (KIllustratorDocument *) doc;
177 GDocument *gdoc = kidoc->gdoc();
178 //GPage *activePage = gdoc->activePage();
179
180 layout = gdoc->activePage()->pageLayout ();
181
182 fin.getline (buf, 255);
183 if (::strncmp (buf, "#FIG 3", 6)) {
184 kdDebug() << "ERROR: no xfig file or wrong header" << endl;
185 return false;
186 }
187
188 if (buf[7] == '2') {
189 version = 320;
190 }
191 else if (buf[7] == '1') {
192 version = 310;
193 }
194 else {
195 kdDebug() << "ERROR: unsupported xfig version" << endl;
196 return false;
197 }
198
199 /*
200 * read the header
201 */
202
203 // orientation
204 fin.getline (buf, 255);
205 if (::strcmp (buf, "Landscape") == 0)
206 layout.orientation = PG_LANDSCAPE;
207 else if (::strcmp (buf, "Portrait") == 0)
208 layout.orientation = PG_PORTRAIT;
209 else
210 kdDebug() << "ERROR: invalid orientation" << endl;
211
212 // justification (don't know how to handle this)
213 fin.getline (buf, 255);
214
215 // units
216 fin.getline (buf, 255);
217 if (::strcmp (buf, "Metric") == 0)
218 layout.unit = PG_MM;
219 else if (::strcmp (buf, "Inches") == 0)
220 layout.unit = PG_INCH;
221 else
222 kdDebug() << "ERROR: invalid units" << endl;
223
224 if (version >= 320) {
225 // paper size (don't know how to handle this)
226 fin.getline (buf, 255);
227
228 // magnification
229 float magnification;
230 fin >> magnification;
231 fin.ignore (INT_MAX, '\n');
232
233 //multiple page (not supported yet)
234 fin.getline (buf, 255);
235
236 // transparent color (not supported yet)
237 int transColor;
238 fin >> transColor;
239 fin.ignore (INT_MAX, '\n');
240 }
241
242 // resolution and coordinate system
243 fin >> value >> coordinate_system;
244 fig_resolution = value / 72.0;
245 fin.ignore (INT_MAX, '\n');
246
247 // now read in the objects
248 while (! fin.eof ()) {
249 int tag = -1;
250 fin >> tag;
251 if (tag == -1) {
252 // EOF
253 buildDocument (gdoc);
254 return true;
255 }
256
257 switch (tag) {
258 case 0:
259 // a color pseudo object
260 parseColorObject (fin);
261 break;
262 case 1:
263 // a ellipse
264 parseEllipse (fin, gdoc);
265 break;
266 case 2:
267 // a polyline
268 parsePolyline (fin, gdoc);
269 break;
270 case 3:
271 // a spline
272 parseSpline (fin, gdoc);
273 break;
274 case 4:
275 // a text
276 parseText (fin, gdoc);
277 break;
278 case 5:
279 // an arc
280 parseArc (fin, gdoc);
281 break;
282 case 6:
283 // a compound object
284 parseCompoundObject (fin, gdoc);
285 break;
286 case -6:
287 // end of compound object --> ignore it
288 break;
289 default:
290 // should not occur
291 kdDebug() << "unknown object type: " << tag << endl;
292 break;
293 }
294 }
295 buildDocument (gdoc);
296 return true;
297}
298
299
300void XFIGImport::parseColorObject (istream& fin) {
301 int number, red, green, blue;
302 char buf[20], red_str[3], green_str[3], blue_str[3];
303
304 fin >> number >> buf;
305 strncpy (red_str, &buf[1], 2); red_str[2] = '\0';
306 strncpy (green_str, &buf[3], 2); green_str[2] = '\0';
307 strncpy (blue_str, &buf[5], 2); blue_str[2] = '\0';
308
309 red = hexstrToInt (red_str);
310 green = hexstrToInt (green_str);
311 blue = hexstrToInt (blue_str);
312
313 colorTable.insert (number, new TQColor (red, green, blue));
314}
315
316void XFIGImport::parseArc (istream& fin, GDocument* doc) {
317 int sub_type, line_style, thickness, pen_color, fill_color,
318 depth, pen_style, area_fill, cap_style, direction,
319 forward_arrow, backward_arrow, x1, y1, x2, y2, x3, y3;
320 float center_x, center_y;
321 float style_val;
322 GOval *obj = new GOval (doc);
323
324 // first line
325 fin >> sub_type >> line_style >> thickness >> pen_color >> fill_color
326 >> depth >> pen_style >> area_fill >> style_val >> cap_style
327 >> direction >> forward_arrow >> backward_arrow
328 >> center_x >> center_y >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
329
330 if (forward_arrow > 0) {
331 // forward arow line
332 fin.ignore (INT_MAX, '\n');
333 }
334
335 if (backward_arrow > 0) {
336 // backward arrow line
337 fin.ignore (INT_MAX, '\n');
338 }
339
340 // compute radius
341 float dx = x1 - center_x;
342 float dy = y1 - center_y;
343 float radius = sqrt (dx * dx + dy * dy);
344
345 if (radius==0) {
346 delete obj;
347 return;
348 }
349
350 Coord p1 ((center_x - radius) / fig_resolution,
351 (center_y - radius) / fig_resolution);
352 Coord p2 ((center_x + radius) / fig_resolution,
353 (center_y + radius) / fig_resolution);
354
355 obj->setStartPoint (p1);
356 obj->setEndPoint (p2);
357
358 if (sub_type == 0)
359 obj->setOutlineShape (GObject::OutlineInfo::PieShape);
360 else if (sub_type == 1)
361 obj->setOutlineShape (GObject::OutlineInfo::ArcShape);
362
363 p1 = Coord (center_x / fig_resolution, center_y /fig_resolution);
364 float m;
365
366 float angle1;
367 p2 = Coord (x1 / fig_resolution, y1 /fig_resolution);
368 if (p2.x () == p1.x ()) {
369 if (p2.y () > p1.y ())
370 angle1 = 90;
371 else
372 angle1 = -90;
373 }
374 else {
375 m = ((p2.y () - p1.y ()) / (p2.x () - p1.x ()));
376 if ( p2.x () > p1.x ())
377 angle1 = atan (m) * RAD_FACTOR;
378 else
379 angle1 = 180 + atan (m) * RAD_FACTOR;
380 }
381
382 float angle2;
383 p2 = Coord (x3 / fig_resolution, y3 /fig_resolution);
384 if (p2.x () == p1.x ()) {
385 if (p2.y () > p1.y ())
386 angle2 = 90;
387 else
388 angle2 = -90;
389 }
390 else {
391 m = ((p2.y () - p1.y ()) / (p2.x () - p1.x ()));
392 if ( p2.x () > p1.x ())
393 angle2 = atan (m) * RAD_FACTOR;
394 else
395 angle2 = 180 + atan (m) * RAD_FACTOR;
396 }
397
398 if (direction==0) // clockwise
399 obj->setAngles (angle2, angle1);
400 else if (direction==1) // counterclockwise
401 obj->setAngles (angle1, angle2);
402
403 // now set the properties
404 setProperties (obj, pen_color, pen_style, thickness, area_fill, fill_color);
405 objList.append( GObjectListItem( depth, obj ) );
406}
407
408void XFIGImport::parseEllipse (istream& fin, GDocument* doc) {
409 int sub_type, line_style, thickness, pen_color, fill_color,
410 depth, pen_style, area_fill, direction, center_x, center_y,
411 radius_x, radius_y, start_x, start_y, end_x, end_y;
412 float style_val, angle;
413 GOval *obj = new GOval (doc);
414
415 // first line
416 fin >> sub_type >> line_style >> thickness >> pen_color >> fill_color
417 >> depth >> pen_style >> area_fill >> style_val >> direction
418 >> angle >> center_x >> center_y >> radius_x >> radius_y
419 >> start_x >> start_y >> end_x >> end_y;
420 Coord p1, p2;
421
422 p1 = Coord ((center_x - radius_x) /fig_resolution,
423 (center_y - radius_y) /fig_resolution);
424 p2 = Coord ((center_x + radius_x) /fig_resolution,
425 (center_y + radius_y) /fig_resolution);
426
427 obj->setStartPoint (p1);
428 obj->setEndPoint (p2);
429
430 // now set the properties
431 setProperties (obj, pen_color, pen_style, thickness, area_fill, fill_color);
432 objList.append( GObjectListItem( depth, obj ) );
433}
434
435void XFIGImport::parsePolyline (istream& fin, GDocument* doc) {
436 int sub_type, line_style, thickness, pen_color, fill_color,
437 depth, pen_style, area_fill, join_style, cap_style, radius,
438 forward_arrow, backward_arrow, npoints;
439 float style_val;
440 GPolyline *obj = NULL;
441
442 // first line
443 fin >> sub_type >> line_style >> thickness >> pen_color >> fill_color
444 >> depth >> pen_style >> area_fill >> style_val >> join_style
445 >> cap_style >> radius >> forward_arrow >> backward_arrow
446 >> npoints;
447 fin.ignore (INT_MAX, '\n');
448
449 switch (sub_type) {
450 case 1: // polyline
451 obj = new GPolyline (doc);
452 break;
453 case 2: // box
454 obj = new GPolygon (doc);
455 break;
456 case 3: // polygon
457 obj = new GPolygon (doc);
458 break;
459 case 4: // arc-box
460 obj = new GPolygon (doc);
461 break;
462 case 5: // imported picture
463 return;
464 break;
465 default:
466 // doesn't occur
467 kdDebug() << "unknown subtype: " << sub_type << endl;
468 break;
469 }
470
471 assert (obj != NULL);
472
473 int arrow_type, arrow_style;
474 float arrow_thickness, arrow_width, arrow_height;
475 GObject::OutlineInfo oinfo;
476 oinfo.mask = GObject::OutlineInfo::Custom;
477 oinfo.startArrowId = oinfo.endArrowId = 0;
478
479 if (forward_arrow > 0) {
480
481 // forward arrow line
482 fin >> arrow_type >> arrow_style >> arrow_thickness
483 >> arrow_width >> arrow_height;
484 oinfo.endArrowId = arrow_ids[arrow_type];
485 if (oinfo.endArrowId == 1 && arrow_style == 0)
486 oinfo.endArrowId = 4;
487 fin.ignore (INT_MAX, '\n');
488 }
489
490 if (backward_arrow > 0) {
491 // backward arrow line
492 fin >> arrow_type >> arrow_style >> arrow_thickness
493 >> arrow_width >> arrow_height;
494 oinfo.startArrowId = arrow_ids[arrow_type];
495 if (oinfo.startArrowId == 1 && arrow_style == 0)
496 oinfo.startArrowId = 4;
497 fin.ignore (INT_MAX, '\n');
498 }
499 // points line
500 for (int i = 0; i < npoints; i++) {
501 int x, y;
502 fin >> x >> y;
503 if ((sub_type == 2 || sub_type == 3) && i == npoints -1)
504 // first point == last point
505 break;
506
507 Coord p (x / fig_resolution, y / fig_resolution);
508 obj->_addPoint (i, p);
509 }
510
511 if (oinfo.startArrowId || oinfo.endArrowId)
512 obj->setOutlineInfo (oinfo);
513
514 // now set the properties
515 setProperties (obj, pen_color, line_style, thickness, area_fill, fill_color);
516
517 // and insert the object
518 objList.append( GObjectListItem( depth, obj ) );
519}
520
521void XFIGImport::parseSpline (istream& fin, GDocument* doc)
522{
523 int sub_type, line_style, thickness, pen_color, fill_color, depth,
524 pen_style, area_fill, cap_style, forward_arrow, backward_arrow, npoints;
525 float style_val;
526
527 // this should be a spline
528 GPolyline *obj = 0L;
529 fin >> sub_type >> line_style >> thickness >> pen_color >> fill_color
530 >> depth >> pen_style >> area_fill >> style_val >> cap_style
531 >> forward_arrow >> backward_arrow >> npoints;
532 if (sub_type == 1 || sub_type == 3 || sub_type == 5)
533 obj = new GPolygon (doc);
534 else
535 obj = new GPolyline (doc);
536
537 int arrow_type, arrow_style;
538 float arrow_thickness, arrow_width, arrow_height;
539 GObject::OutlineInfo oinfo;
540 oinfo.mask = GObject::OutlineInfo::Custom;
541 oinfo.startArrowId = oinfo.endArrowId = 0;
542
543 if (forward_arrow > 0) {
544
545 // forward arrow line
546 fin >> arrow_type >> arrow_style >> arrow_thickness
547 >> arrow_width >> arrow_height;
548 oinfo.endArrowId = arrow_ids[arrow_type];
549 if (oinfo.endArrowId == 1 && arrow_style == 0)
550 oinfo.endArrowId = 4;
551 fin.ignore (INT_MAX, '\n');
552 }
553
554 if (backward_arrow > 0) {
555 // backward arrow line
556 fin >> arrow_type >> arrow_style >> arrow_thickness
557 >> arrow_width >> arrow_height;
558 oinfo.startArrowId = arrow_ids[arrow_type];
559 if (oinfo.startArrowId == 1 && arrow_style == 0)
560 oinfo.startArrowId = 4;
561 fin.ignore (INT_MAX, '\n');
562 }
563
564 // points line
565 for (int i = 0; i < npoints; i++) {
566 int x, y;
567 fin >> x >> y;
568 if ((sub_type == 1 || sub_type == 3 || sub_type == 5) && i == npoints -1)
569 // first point == last point
570 break;
571
572 Coord p (x / fig_resolution, y / fig_resolution);
573 obj->_addPoint (i, p);
574 }
575
576 // control points line
577 for (int i = 0; i < npoints; i++) {
578 float fac;
579 fin >> fac;
580 // ignore it now
581 // fin.ignore (INT_MAX, '\n');
582 }
583
584 if (oinfo.startArrowId || oinfo.endArrowId)
585 obj->setOutlineInfo (oinfo);
586
587 // now set the properties
588 setProperties (obj, pen_color, line_style, thickness, area_fill, fill_color);
589
590 // and insert the object
591 objList.append( GObjectListItem( depth, obj ) );
592}
593
594void XFIGImport::parseText (istream& fin, GDocument* doc)
595{
596 int sub_type, color, depth, pen_style, font, font_flags, x, y;
597 float font_size, angle, height, length;
598 GText *obj = new GText (doc);
599 char c;
600 char ocode[4];
601 bool finished = false;
602 TQString text;
603 TQFont qfont;
604
605 fin >> sub_type >> color >> depth >> pen_style >> font >> font_size
606 >> angle >> font_flags >> height >> length >> x >> y;
607
608 if (font_flags & 4) {
609 // PostScript font
610 if (font == -1)
611 font = 0;
612 qfont = TQFont (psFontTable[font].family, tqRound (font_size),
613 psFontTable[font].weight, psFontTable[font].italic);
614 }
615 else {
616 // LaTeX font
617 switch (font) {
618 case 1: // Roman
619 qfont.setFamily ("times");
620 break;
621 case 2: // Bold
622 qfont.setBold (true);
623 break;
624 case 3: // Italic
625 qfont.setItalic (true);
626 break;
627 case 4: // Sans Serif
628 qfont.setFamily ("helvetica");
629 break;
630 case 5: // Typewriter
631 qfont.setFamily ("Courier");
632 break;
633 default:
634 break;
635 }
636 }
637 qfont.setPointSize (tqRound (font_size));
638 obj->setFont (qfont);
639
640 while (! finished) {
641 fin.get (c);
642 if (c == '\\') {
643 fin.get (ocode, 4);
644 int code = (ocode[0] - '0') * 64 +
645 (ocode[1] - '0') * 8 +
646 (ocode[2] - '0');
647 if (code == 1)
648 finished = true;
649 else
650 text += (char) code;
651 }
652 else
653 text += c;
654 }
655 obj->setText (text);
656
657 if (sub_type == 1) {
658 GText::TextInfo ti = obj->getTextInfo ();
659 ti.align = GText::TextInfo::AlignCenter;
660 obj->setTextInfo (ti);
661 }
662 else if (sub_type == 2) {
663 GText::TextInfo ti = obj->getTextInfo ();
664 ti.align = GText::TextInfo::AlignRight;
665 obj->setTextInfo (ti);
666 }
667 Coord origin (x / fig_resolution, y / fig_resolution - qfont.pointSize ());
668 obj->setOrigin (origin);
669
670 if (angle != 0) {
671 // rotate the text
672 float nangle = angle * RAD_FACTOR;
673 TQWMatrix m1, m2, m3;
674 Coord rotCenter;
675
676 if (sub_type == 0) {
677 rotCenter = Coord (obj->boundingBox ().left (),
678 obj->boundingBox ().bottom ());
679 }
680 else if (sub_type == 1) {
681 rotCenter = Coord (obj->boundingBox ().width () / 2,
682 obj->boundingBox ().bottom ());
683 }
684 else if (sub_type == 2) {
685 rotCenter = Coord (obj->boundingBox ().right (),
686 obj->boundingBox ().bottom ());
687 }
688 m1.translate (-rotCenter.x (), -rotCenter.y ());
689 m2.rotate (-nangle);
690 m3.translate (rotCenter.x (), rotCenter.y ());
691 obj->transform (m1);
692 obj->transform (m2);
693 obj->transform (m3, true);
694 }
695
696 objList.append( GObjectListItem( depth, obj ) );
697}
698
699void XFIGImport::parseCompoundObject (istream& fin, GDocument* /*doc*/) {
700 int upperright_x, upperright_y, lowerleft_x, lowerleft_y;
701
702 fin >> upperright_x >> upperright_y >> lowerleft_x >> lowerleft_y;
703 fin.ignore (INT_MAX, '\n');
704}
705
706
710void XFIGImport::buildDocument (GDocument *doc) {
711 doc->setAutoUpdate (false);
712 // This will sort all object, by decreasing depth
713 qBubbleSort(objList);
714
715 // Now all we need to do is insert them in the document, in that order
716 TQValueList<GObjectListItem>::Iterator it=objList.begin();
717 for ( ; it != objList.end() ; ++it )
718 {
719 //kdDebug() << "Inserting object with depth=" << (*it).depth << endl;
720 GObject* obj = (*it).object;
721 obj->ref ();
722 doc->activePage()->insertObject (obj);
723 }
724 doc->setAutoUpdate (true);
725 objList.clear(); // save memory
726}
727
728void XFIGImport::setProperties (GObject* obj, int pen_color, int style,
729 int thickness, int area_fill, int fill_color) {
730 if (pen_color >= 0)
731 obj->setOutlineColor (*colorTable[pen_color]);
732
733 if (style < 1)
734 obj->setOutlineStyle (TQt::SolidLine);
735 else if (style == 1)
736 obj->setOutlineStyle (TQt::DashLine);
737 else if (style == 2)
738 obj->setOutlineStyle (TQt::DotLine);
739
740 obj->setOutlineWidth (thickness * 72.0 / 80.0);
741
742 if (area_fill == -1)
743 obj->setFillStyle (GObject::FillInfo::NoFill);
744 else {
745 obj->setFillStyle (GObject::FillInfo::SolidFill);
746 if (fill_color < 1) {
747 // for BLACK or DEFAULT color
748 int val = tqRound ((20 - area_fill) * 255.0 / 20.0);
749 obj->setFillColor (TQColor (val, val, val));
750 }
751 else if (fill_color == 7) {
752 // for WHITE color
753 int val = tqRound ( area_fill * 255.0 / 20.0);
754 obj->setFillColor (TQColor (val, val, val));
755 }
756 else
757 obj->setFillColor (*colorTable[fill_color]);
758 }
759}
760