1 /**
2 * OpenDocument <drawing> input and output
3 *
4 * This is an an entry in the extensions mechanism to begin to enable
5 * the inputting and outputting of OpenDocument Format (ODF) files from
6 * within Inkscape. Although the initial implementations will be very lossy
7 * do to the differences in the models of SVG and ODF, they will hopefully
8 * improve greatly with time.
9 *
10 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
11 *
12 * Authors:
13 * Bob Jamison
14 *
15 * Copyright (C) 2006 Bob Jamison
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
21 *
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this library; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 */
34 #ifdef HAVE_CONFIG_H
35 # include <config.h>
36 #endif
38 #include "odf.h"
40 //# System includes
41 #include <stdio.h>
42 #include <time.h>
43 #include <vector>
46 //# Inkscape includes
47 #include "clear-n_.h"
48 #include "inkscape.h"
49 #include <style.h>
50 #include "display/curve.h"
51 #include "libnr/n-art-bpath.h"
52 #include "extension/system.h"
54 #include "xml/repr.h"
55 #include "xml/attribute-record.h"
56 #include "sp-image.h"
57 #include "sp-path.h"
58 #include "sp-text.h"
59 #include "sp-flowtext.h"
60 #include "svg/svg.h"
61 #include "text-editing.h"
64 //# DOM-specific includes
65 #include "dom/dom.h"
66 #include "dom/util/ziptool.h"
67 #include "dom/io/domstream.h"
68 #include "dom/io/bufferstream.h"
75 namespace Inkscape
76 {
77 namespace Extension
78 {
79 namespace Internal
80 {
82 //# Shorthand notation
83 typedef org::w3c::dom::DOMString DOMString;
84 typedef org::w3c::dom::io::OutputStreamWriter OutputStreamWriter;
85 typedef org::w3c::dom::io::BufferOutputStream BufferOutputStream;
88 //########################################################################
89 //# C L A S S SingularValueDecomposition
90 //########################################################################
91 #include <math.h>
93 /**
94 *
95 * ====================================================
96 *
97 * NOTE:
98 * This class is ported almost verbatim from the public domain
99 * JAMA Matrix package. It is modified to handle only 3x3 matrices
100 * and our NR::Matrix affine transform class. We give full
101 * attribution to them, along with many thanks. JAMA can be found at:
102 * http://math.nist.gov/javanumerics/jama
103 *
104 * ====================================================
105 *
106 * Singular Value Decomposition.
107 * <P>
108 * For an m-by-n matrix A with m >= n, the singular value decomposition is
109 * an m-by-n orthogonal matrix U, an n-by-n diagonal matrix S, and
110 * an n-by-n orthogonal matrix V so that A = U*S*V'.
111 * <P>
112 * The singular values, sigma[k] = S[k][k], are ordered so that
113 * sigma[0] >= sigma[1] >= ... >= sigma[n-1].
114 * <P>
115 * The singular value decompostion always exists, so the constructor will
116 * never fail. The matrix condition number and the effective numerical
117 * rank can be computed from this decomposition.
118 */
119 class SingularValueDecomposition
120 {
121 public:
123 /** Construct the singular value decomposition
124 @param A Rectangular matrix
125 @return Structure to access U, S and V.
126 */
128 SingularValueDecomposition (const NR::Matrix &matrixArg)
129 {
130 matrix = matrixArg;
131 calculate();
132 }
134 virtual ~SingularValueDecomposition()
135 {}
137 /**
138 * Return the left singular vectors
139 * @return U
140 */
141 NR::Matrix getU();
143 /**
144 * Return the right singular vectors
145 * @return V
146 */
147 NR::Matrix getV();
149 /**
150 * Return the three singular values along the diagonal
151 */
152 void getSingularValues(double &s0, double &s1, double &s2);
154 /**
155 * Two norm
156 * @return max(S)
157 */
158 double norm2();
160 /**
161 * Two norm condition number
162 * @return max(S)/min(S)
163 */
164 double cond();
166 /**
167 * Effective numerical matrix rank
168 * @return Number of nonnegligible singular values.
169 */
170 int rank();
172 private:
174 void calculate();
176 NR::Matrix matrix;
177 double A[3][3];
178 double U[3][3];
179 double s[3];
180 double V[3][3];
182 };
185 static double hypot(double a, double b)
186 {
187 double r;
189 if (fabs(a) > fabs(b))
190 {
191 r = b/a;
192 r = fabs(a) * sqrt(1+r*r);
193 }
194 else if (b != 0)
195 {
196 r = a/b;
197 r = fabs(b) * sqrt(1+r*r);
198 }
199 else
200 {
201 r = 0.0;
202 }
203 return r;
204 }
208 void SingularValueDecomposition::calculate()
209 {
210 // Initialize.
211 A[0][0] = matrix[0];
212 A[0][1] = matrix[2];
213 A[0][2] = matrix[4];
214 A[1][0] = matrix[1];
215 A[1][1] = matrix[3];
216 A[1][2] = matrix[5];
217 A[2][0] = 0.0;
218 A[2][1] = 0.0;
219 A[2][2] = 1.0;
221 double e[3];
222 double work[3];
223 bool wantu = true;
224 bool wantv = true;
225 int m = 3;
226 int n = 3;
227 int nu = 3;
229 // Reduce A to bidiagonal form, storing the diagonal elements
230 // in s and the super-diagonal elements in e.
232 int nct = 2;
233 int nrt = 1;
234 for (int k = 0; k < 2; k++) {
235 if (k < nct) {
237 // Compute the transformation for the k-th column and
238 // place the k-th diagonal in s[k].
239 // Compute 2-norm of k-th column without under/overflow.
240 s[k] = 0;
241 for (int i = k; i < m; i++) {
242 s[k] = hypot(s[k],A[i][k]);
243 }
244 if (s[k] != 0.0) {
245 if (A[k][k] < 0.0) {
246 s[k] = -s[k];
247 }
248 for (int i = k; i < m; i++) {
249 A[i][k] /= s[k];
250 }
251 A[k][k] += 1.0;
252 }
253 s[k] = -s[k];
254 }
255 for (int j = k+1; j < n; j++) {
256 if ((k < nct) & (s[k] != 0.0)) {
258 // Apply the transformation.
260 double t = 0;
261 for (int i = k; i < m; i++) {
262 t += A[i][k]*A[i][j];
263 }
264 t = -t/A[k][k];
265 for (int i = k; i < m; i++) {
266 A[i][j] += t*A[i][k];
267 }
268 }
270 // Place the k-th row of A into e for the
271 // subsequent calculation of the row transformation.
273 e[j] = A[k][j];
274 }
275 if (wantu & (k < nct)) {
277 // Place the transformation in U for subsequent back
278 // multiplication.
280 for (int i = k; i < m; i++) {
281 U[i][k] = A[i][k];
282 }
283 }
284 if (k < nrt) {
286 // Compute the k-th row transformation and place the
287 // k-th super-diagonal in e[k].
288 // Compute 2-norm without under/overflow.
289 e[k] = 0;
290 for (int i = k+1; i < n; i++) {
291 e[k] = hypot(e[k],e[i]);
292 }
293 if (e[k] != 0.0) {
294 if (e[k+1] < 0.0) {
295 e[k] = -e[k];
296 }
297 for (int i = k+1; i < n; i++) {
298 e[i] /= e[k];
299 }
300 e[k+1] += 1.0;
301 }
302 e[k] = -e[k];
303 if ((k+1 < m) & (e[k] != 0.0)) {
305 // Apply the transformation.
307 for (int i = k+1; i < m; i++) {
308 work[i] = 0.0;
309 }
310 for (int j = k+1; j < n; j++) {
311 for (int i = k+1; i < m; i++) {
312 work[i] += e[j]*A[i][j];
313 }
314 }
315 for (int j = k+1; j < n; j++) {
316 double t = -e[j]/e[k+1];
317 for (int i = k+1; i < m; i++) {
318 A[i][j] += t*work[i];
319 }
320 }
321 }
322 if (wantv) {
324 // Place the transformation in V for subsequent
325 // back multiplication.
327 for (int i = k+1; i < n; i++) {
328 V[i][k] = e[i];
329 }
330 }
331 }
332 }
334 // Set up the final bidiagonal matrix or order p.
336 int p = 3;
337 if (nct < n) {
338 s[nct] = A[nct][nct];
339 }
340 if (m < p) {
341 s[p-1] = 0.0;
342 }
343 if (nrt+1 < p) {
344 e[nrt] = A[nrt][p-1];
345 }
346 e[p-1] = 0.0;
348 // If required, generate U.
350 if (wantu) {
351 for (int j = nct; j < nu; j++) {
352 for (int i = 0; i < m; i++) {
353 U[i][j] = 0.0;
354 }
355 U[j][j] = 1.0;
356 }
357 for (int k = nct-1; k >= 0; k--) {
358 if (s[k] != 0.0) {
359 for (int j = k+1; j < nu; j++) {
360 double t = 0;
361 for (int i = k; i < m; i++) {
362 t += U[i][k]*U[i][j];
363 }
364 t = -t/U[k][k];
365 for (int i = k; i < m; i++) {
366 U[i][j] += t*U[i][k];
367 }
368 }
369 for (int i = k; i < m; i++ ) {
370 U[i][k] = -U[i][k];
371 }
372 U[k][k] = 1.0 + U[k][k];
373 for (int i = 0; i < k-1; i++) {
374 U[i][k] = 0.0;
375 }
376 } else {
377 for (int i = 0; i < m; i++) {
378 U[i][k] = 0.0;
379 }
380 U[k][k] = 1.0;
381 }
382 }
383 }
385 // If required, generate V.
387 if (wantv) {
388 for (int k = n-1; k >= 0; k--) {
389 if ((k < nrt) & (e[k] != 0.0)) {
390 for (int j = k+1; j < nu; j++) {
391 double t = 0;
392 for (int i = k+1; i < n; i++) {
393 t += V[i][k]*V[i][j];
394 }
395 t = -t/V[k+1][k];
396 for (int i = k+1; i < n; i++) {
397 V[i][j] += t*V[i][k];
398 }
399 }
400 }
401 for (int i = 0; i < n; i++) {
402 V[i][k] = 0.0;
403 }
404 V[k][k] = 1.0;
405 }
406 }
408 // Main iteration loop for the singular values.
410 int pp = p-1;
411 int iter = 0;
412 double eps = pow(2.0,-52.0);
413 double tiny = pow(2.0,-966.0);
414 while (p > 0) {
415 int k,kase;
417 // Here is where a test for too many iterations would go.
419 // This section of the program inspects for
420 // negligible elements in the s and e arrays. On
421 // completion the variables kase and k are set as follows.
423 // kase = 1 if s(p) and e[k-1] are negligible and k<p
424 // kase = 2 if s(k) is negligible and k<p
425 // kase = 3 if e[k-1] is negligible, k<p, and
426 // s(k), ..., s(p) are not negligible (qr step).
427 // kase = 4 if e(p-1) is negligible (convergence).
429 for (k = p-2; k >= -1; k--) {
430 if (k == -1) {
431 break;
432 }
433 if (fabs(e[k]) <=
434 tiny + eps*(fabs(s[k]) + fabs(s[k+1]))) {
435 e[k] = 0.0;
436 break;
437 }
438 }
439 if (k == p-2) {
440 kase = 4;
441 } else {
442 int ks;
443 for (ks = p-1; ks >= k; ks--) {
444 if (ks == k) {
445 break;
446 }
447 double t = (ks != p ? fabs(e[ks]) : 0.) +
448 (ks != k+1 ? fabs(e[ks-1]) : 0.);
449 if (fabs(s[ks]) <= tiny + eps*t) {
450 s[ks] = 0.0;
451 break;
452 }
453 }
454 if (ks == k) {
455 kase = 3;
456 } else if (ks == p-1) {
457 kase = 1;
458 } else {
459 kase = 2;
460 k = ks;
461 }
462 }
463 k++;
465 // Perform the task indicated by kase.
467 switch (kase) {
469 // Deflate negligible s(p).
471 case 1: {
472 double f = e[p-2];
473 e[p-2] = 0.0;
474 for (int j = p-2; j >= k; j--) {
475 double t = hypot(s[j],f);
476 double cs = s[j]/t;
477 double sn = f/t;
478 s[j] = t;
479 if (j != k) {
480 f = -sn*e[j-1];
481 e[j-1] = cs*e[j-1];
482 }
483 if (wantv) {
484 for (int i = 0; i < n; i++) {
485 t = cs*V[i][j] + sn*V[i][p-1];
486 V[i][p-1] = -sn*V[i][j] + cs*V[i][p-1];
487 V[i][j] = t;
488 }
489 }
490 }
491 }
492 break;
494 // Split at negligible s(k).
496 case 2: {
497 double f = e[k-1];
498 e[k-1] = 0.0;
499 for (int j = k; j < p; j++) {
500 double t = hypot(s[j],f);
501 double cs = s[j]/t;
502 double sn = f/t;
503 s[j] = t;
504 f = -sn*e[j];
505 e[j] = cs*e[j];
506 if (wantu) {
507 for (int i = 0; i < m; i++) {
508 t = cs*U[i][j] + sn*U[i][k-1];
509 U[i][k-1] = -sn*U[i][j] + cs*U[i][k-1];
510 U[i][j] = t;
511 }
512 }
513 }
514 }
515 break;
517 // Perform one qr step.
519 case 3: {
521 // Calculate the shift.
523 double scale = 0.0;
524 double d = fabs(s[p-1]);
525 if (d>scale) scale=d;
526 d = fabs(s[p-2]);
527 if (d>scale) scale=d;
528 d = fabs(e[p-2]);
529 if (d>scale) scale=d;
530 d = fabs(s[k]);
531 if (d>scale) scale=d;
532 d = fabs(e[k]);
533 if (d>scale) scale=d;
534 double sp = s[p-1]/scale;
535 double spm1 = s[p-2]/scale;
536 double epm1 = e[p-2]/scale;
537 double sk = s[k]/scale;
538 double ek = e[k]/scale;
539 double b = ((spm1 + sp)*(spm1 - sp) + epm1*epm1)/2.0;
540 double c = (sp*epm1)*(sp*epm1);
541 double shift = 0.0;
542 if ((b != 0.0) | (c != 0.0)) {
543 shift = sqrt(b*b + c);
544 if (b < 0.0) {
545 shift = -shift;
546 }
547 shift = c/(b + shift);
548 }
549 double f = (sk + sp)*(sk - sp) + shift;
550 double g = sk*ek;
552 // Chase zeros.
554 for (int j = k; j < p-1; j++) {
555 double t = hypot(f,g);
556 double cs = f/t;
557 double sn = g/t;
558 if (j != k) {
559 e[j-1] = t;
560 }
561 f = cs*s[j] + sn*e[j];
562 e[j] = cs*e[j] - sn*s[j];
563 g = sn*s[j+1];
564 s[j+1] = cs*s[j+1];
565 if (wantv) {
566 for (int i = 0; i < n; i++) {
567 t = cs*V[i][j] + sn*V[i][j+1];
568 V[i][j+1] = -sn*V[i][j] + cs*V[i][j+1];
569 V[i][j] = t;
570 }
571 }
572 t = hypot(f,g);
573 cs = f/t;
574 sn = g/t;
575 s[j] = t;
576 f = cs*e[j] + sn*s[j+1];
577 s[j+1] = -sn*e[j] + cs*s[j+1];
578 g = sn*e[j+1];
579 e[j+1] = cs*e[j+1];
580 if (wantu && (j < m-1)) {
581 for (int i = 0; i < m; i++) {
582 t = cs*U[i][j] + sn*U[i][j+1];
583 U[i][j+1] = -sn*U[i][j] + cs*U[i][j+1];
584 U[i][j] = t;
585 }
586 }
587 }
588 e[p-2] = f;
589 iter = iter + 1;
590 }
591 break;
593 // Convergence.
595 case 4: {
597 // Make the singular values positive.
599 if (s[k] <= 0.0) {
600 s[k] = (s[k] < 0.0 ? -s[k] : 0.0);
601 if (wantv) {
602 for (int i = 0; i <= pp; i++) {
603 V[i][k] = -V[i][k];
604 }
605 }
606 }
608 // Order the singular values.
610 while (k < pp) {
611 if (s[k] >= s[k+1]) {
612 break;
613 }
614 double t = s[k];
615 s[k] = s[k+1];
616 s[k+1] = t;
617 if (wantv && (k < n-1)) {
618 for (int i = 0; i < n; i++) {
619 t = V[i][k+1]; V[i][k+1] = V[i][k]; V[i][k] = t;
620 }
621 }
622 if (wantu && (k < m-1)) {
623 for (int i = 0; i < m; i++) {
624 t = U[i][k+1]; U[i][k+1] = U[i][k]; U[i][k] = t;
625 }
626 }
627 k++;
628 }
629 iter = 0;
630 p--;
631 }
632 break;
633 }
634 }
637 }
641 /**
642 * Return the left singular vectors
643 * @return U
644 */
645 NR::Matrix SingularValueDecomposition::getU()
646 {
647 NR::Matrix mat(U[0][0], U[1][0], U[0][1],
648 U[1][1], U[2][0], U[2][1]);
649 return mat;
650 }
652 /**
653 * Return the right singular vectors
654 * @return V
655 */
657 NR::Matrix SingularValueDecomposition::getV()
658 {
659 NR::Matrix mat(V[0][0], V[1][0], V[0][1],
660 V[1][1], V[2][0], V[2][1]);
661 return mat;
662 }
664 /**
665 * Return the three singular values along the diagonal
666 */
667 void SingularValueDecomposition::getSingularValues(
668 double &s0, double &s1, double &s2)
669 {
670 s0 = s[0];
671 s1 = s[1];
672 s2 = s[2];
673 }
675 /**
676 * Two norm
677 * @return max(S)
678 */
679 double SingularValueDecomposition::norm2()
680 {
681 return s[0];
682 }
684 /**
685 * Two norm condition number
686 * @return max(S)/min(S)
687 */
689 double SingularValueDecomposition::cond()
690 {
691 return s[0]/s[2];
692 }
694 /**
695 * Effective numerical matrix rank
696 * @return Number of nonnegligible singular values.
697 */
698 int SingularValueDecomposition::rank()
699 {
700 double eps = pow(2.0,-52.0);
701 double tol = 3.0*s[0]*eps;
702 int r = 0;
703 for (int i = 0; i < 3; i++)
704 {
705 if (s[i] > tol)
706 r++;
707 }
708 return r;
709 }
711 //########################################################################
712 //# E N D C L A S S SingularValueDecomposition
713 //########################################################################
718 //#define pxToCm 0.0275
719 #define pxToCm 0.04
720 #define piToRad 0.0174532925
721 #define docHeightCm 22.86
724 //########################################################################
725 //# O U T P U T
726 //########################################################################
728 static std::string getAttribute( Inkscape::XML::Node *node, char *attrName)
729 {
730 std::string val;
731 char *valstr = (char *)node->attribute(attrName);
732 if (valstr)
733 val = (const char *)valstr;
734 return val;
735 }
738 static std::string getExtension(const std::string &fname)
739 {
740 std::string ext;
742 unsigned int pos = fname.rfind('.');
743 if (pos == fname.npos)
744 {
745 ext = "";
746 }
747 else
748 {
749 ext = fname.substr(pos);
750 }
751 return ext;
752 }
755 static std::string formatTransform(NR::Matrix &tf)
756 {
757 std::string str;
758 if (!tf.test_identity())
759 {
760 char buf[128];
761 snprintf(buf, 127, "matrix(%.3f %.3f %.3f %.3f %.3f %.3f)",
762 tf[0], tf[1], tf[2], tf[3], tf[4], tf[5]);
763 str = buf;
764 }
765 return str;
766 }
770 /**
771 * Method descends into the repr tree, converting image and style info
772 * into forms compatible in ODF.
773 */
774 void
775 OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node)
776 {
778 std::string nodeName = node->name();
779 std::string id = getAttribute(node, "id");
781 if (nodeName == "image" || nodeName == "svg:image")
782 {
783 //g_message("image");
784 std::string href = getAttribute(node, "xlink:href");
785 if (href.size() > 0)
786 {
787 std::string oldName = href;
788 std::string ext = getExtension(oldName);
789 if (ext == ".jpeg")
790 ext = ".jpg";
791 if (imageTable.find(oldName) == imageTable.end())
792 {
793 char buf[64];
794 snprintf(buf, 63, "Pictures/image%d%s",
795 imageTable.size(), ext.c_str());
796 std::string newName = buf;
797 imageTable[oldName] = newName;
798 std::string comment = "old name was: ";
799 comment.append(oldName);
800 URI oldUri(oldName);
801 //g_message("oldpath:%s", oldUri.getNativePath().c_str());
802 //# if relative to the documentURI, get proper path
803 URI resUri = documentUri.resolve(oldUri);
804 DOMString pathName = resUri.getNativePath();
805 //g_message("native path:%s", pathName.c_str());
806 ZipEntry *ze = zf.addFile(pathName, comment);
807 if (ze)
808 {
809 ze->setFileName(newName);
810 }
811 else
812 {
813 g_warning("Could not load image file '%s'", pathName.c_str());
814 }
815 }
816 }
817 }
821 SPObject *reprobj = SP_ACTIVE_DOCUMENT->getObjectByRepr(node);
822 if (!reprobj)
823 return;
824 if (!SP_IS_ITEM(reprobj))
825 {
826 return;
827 }
828 SPItem *item = SP_ITEM(reprobj);
829 SPStyle *style = SP_OBJECT_STYLE(item);
830 if (style && id.size()>0)
831 {
832 StyleInfo si;
833 if (style->fill.type == SP_PAINT_TYPE_COLOR)
834 {
835 guint32 fillCol =
836 sp_color_get_rgba32_ualpha(&style->fill.value.color, 0);
837 char buf[16];
838 int r = (fillCol >> 24) & 0xff;
839 int g = (fillCol >> 16) & 0xff;
840 int b = (fillCol >> 8) & 0xff;
841 //g_message("## %s %lx", id.c_str(), (unsigned int)fillCol);
842 snprintf(buf, 15, "#%02x%02x%02x", r, g, b);
843 si.fillColor = buf;
844 si.fill = "solid";
845 double opacityPercent = 100.0 *
846 (SP_SCALE24_TO_FLOAT(style->fill_opacity.value));
847 snprintf(buf, 15, "%.2f%%", opacityPercent);
848 si.fillOpacity = buf;
849 }
850 if (style->stroke.type == SP_PAINT_TYPE_COLOR)
851 {
852 guint32 strokeCol =
853 sp_color_get_rgba32_ualpha(&style->stroke.value.color, 0);
854 char buf[16];
855 int r = (strokeCol >> 24) & 0xff;
856 int g = (strokeCol >> 16) & 0xff;
857 int b = (strokeCol >> 8) & 0xff;
858 snprintf(buf, 15, "#%02x%02x%02x", r, g, b);
859 si.strokeColor = buf;
860 snprintf(buf, 15, "%.2fpt", style->stroke_width.value);
861 si.strokeWidth = buf;
862 si.stroke = "solid";
863 double opacityPercent = 100.0 *
864 (SP_SCALE24_TO_FLOAT(style->stroke_opacity.value));
865 snprintf(buf, 15, "%.2f%%", opacityPercent);
866 si.strokeOpacity = buf;
867 }
869 //Look for existing identical style;
870 bool styleMatch = false;
871 std::vector<StyleInfo>::iterator iter;
872 for (iter=styleTable.begin() ; iter!=styleTable.end() ; iter++)
873 {
874 if (si.equals(*iter))
875 {
876 //map to existing styleTable entry
877 std::string styleName = iter->name;
878 //g_message("found duplicate style:%s", styleName.c_str());
879 styleLookupTable[id] = styleName;
880 styleMatch = true;
881 break;
882 }
883 }
884 //None found, make a new pair or entries
885 if (!styleMatch)
886 {
887 char buf[16];
888 snprintf(buf, 15, "style%d", styleTable.size());
889 std::string styleName = buf;
890 si.name = styleName;
891 styleTable.push_back(si);
892 styleLookupTable[id] = styleName;
893 }
894 }
897 for (Inkscape::XML::Node *child = node->firstChild() ;
898 child ; child = child->next())
899 preprocess(zf, child);
900 }
904 bool OdfOutput::writeManifest(ZipFile &zf)
905 {
906 BufferOutputStream bouts;
907 OutputStreamWriter outs(bouts);
909 time_t tim;
910 time(&tim);
912 outs.printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
913 outs.printf("<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">\n");
914 outs.printf("\n");
915 outs.printf("\n");
916 outs.printf("<!--\n");
917 outs.printf("*************************************************************************\n");
918 outs.printf(" file: manifest.xml\n");
919 outs.printf(" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr>
920 outs.printf(" http://www.inkscape.org\n");
921 outs.printf("*************************************************************************\n");
922 outs.printf("-->\n");
923 outs.printf("\n");
924 outs.printf("\n");
925 outs.printf("<manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\">\n");
926 outs.printf(" <manifest:file-entry manifest:media-type=\"application/vnd.oasis.opendocument.graphics\" manifest:full-path=\"/\"/>\n");
927 outs.printf(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/>\n");
928 outs.printf(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"meta.xml\"/>\n");
929 outs.printf(" <!--List our images here-->\n");
930 std::map<std::string, std::string>::iterator iter;
931 for (iter = imageTable.begin() ; iter!=imageTable.end() ; iter++)
932 {
933 std::string oldName = iter->first;
934 std::string newName = iter->second;
936 std::string ext = getExtension(oldName);
937 if (ext == ".jpeg")
938 ext = ".jpg";
939 outs.printf(" <manifest:file-entry manifest:media-type=\"");
940 if (ext == ".gif")
941 outs.printf("image/gif");
942 else if (ext == ".png")
943 outs.printf("image/png");
944 else if (ext == ".jpg")
945 outs.printf("image/jpeg");
946 outs.printf("\" manifest:full-path=\"");
947 outs.printf((char *)newName.c_str());
948 outs.printf("\"/>\n");
949 }
950 outs.printf("</manifest:manifest>\n");
952 outs.close();
954 //Make our entry
955 ZipEntry *ze = zf.newEntry("META-INF/manifest.xml", "ODF file manifest");
956 ze->setUncompressedData(bouts.getBuffer());
957 ze->finish();
959 return true;
960 }
963 bool OdfOutput::writeMeta(ZipFile &zf)
964 {
965 BufferOutputStream bouts;
966 OutputStreamWriter outs(bouts);
968 time_t tim;
969 time(&tim);
971 outs.printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
972 outs.printf("\n");
973 outs.printf("\n");
974 outs.printf("<!--\n");
975 outs.printf("*************************************************************************\n");
976 outs.printf(" file: meta.xml\n");
977 outs.printf(" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr>
978 outs.printf(" http://www.inkscape.org\n");
979 outs.printf("*************************************************************************\n");
980 outs.printf("-->\n");
981 outs.printf("\n");
982 outs.printf("\n");
983 outs.printf("<office:document-meta\n");
984 outs.printf("xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n");
985 outs.printf("xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n");
986 outs.printf("xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n");
987 outs.printf("xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n");
988 outs.printf("xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n");
989 outs.printf("xmlns:ooo=\"http://openoffice.org/2004/office\"\n");
990 outs.printf("xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n");
991 outs.printf("xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n");
992 outs.printf("office:version=\"1.0\">\n");
993 outs.printf("<office:meta>\n");
994 outs.printf(" <meta:generator>Inkscape.org - 0.44</meta:generator>\n");
995 outs.printf(" <meta:initial-creator>clark kent</meta:initial-creator>\n");
996 outs.printf(" <meta:creation-date>2006-04-13T17:12:29</meta:creation-date>\n");
997 outs.printf(" <dc:creator>clark kent</dc:creator>\n");
998 outs.printf(" <dc:date>2006-04-13T17:13:20</dc:date>\n");
999 outs.printf(" <dc:language>en-US</dc:language>\n");
1000 outs.printf(" <meta:editing-cycles>2</meta:editing-cycles>\n");
1001 outs.printf(" <meta:editing-duration>PT56S</meta:editing-duration>\n");
1002 outs.printf(" <meta:user-defined meta:name=\"Info 1\"/>\n");
1003 outs.printf(" <meta:user-defined meta:name=\"Info 2\"/>\n");
1004 outs.printf(" <meta:user-defined meta:name=\"Info 3\"/>\n");
1005 outs.printf(" <meta:user-defined meta:name=\"Info 4\"/>\n");
1006 outs.printf(" <meta:document-statistic meta:object-count=\"2\"/>\n");
1007 outs.printf("</office:meta>\n");
1008 outs.printf("</office:document-meta>\n");
1009 outs.printf("\n");
1010 outs.printf("\n");
1013 outs.close();
1015 //Make our entry
1016 ZipEntry *ze = zf.newEntry("meta.xml", "ODF info file");
1017 ze->setUncompressedData(bouts.getBuffer());
1018 ze->finish();
1020 return true;
1021 }
1024 bool OdfOutput::writeStyle(Writer &outs)
1025 {
1026 outs.printf("<office:automatic-styles>\n");
1027 outs.printf("<!-- ####### 'Standard' styles ####### -->\n");
1028 outs.printf("<style:style style:name=\"dp1\" style:family=\"drawing-page\"/>\n");
1029 outs.printf("<style:style style:name=\"gr1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n");
1030 outs.printf(" <style:graphic-properties draw:stroke=\"none\" draw:fill=\"none\"\n");
1031 outs.printf(" draw:textarea-horizontal-align=\"center\"\n");
1032 outs.printf(" draw:textarea-vertical-align=\"middle\" draw:color-mode=\"standard\"\n");
1033 outs.printf(" draw:luminance=\"0%\" draw:contrast=\"0%\" draw:gamma=\"100%\" draw:red=\"0%\"\n");
1034 outs.printf(" draw:green=\"0%\" draw:blue=\"0%\" fo:clip=\"rect(0cm 0cm 0cm 0cm)\"\n");
1035 outs.printf(" draw:image-opacity=\"100%\" style:mirror=\"none\"/>\n");
1036 outs.printf("</style:style>\n");
1037 outs.printf("<style:style style:name=\"P1\" style:family=\"paragraph\">\n");
1038 outs.printf(" <style:paragraph-properties fo:text-align=\"center\"/>\n");
1039 outs.printf("</style:style>\n");
1041 //## Dump our style table
1042 outs.printf("<!-- ####### Styles from Inkscape document ####### -->\n");
1043 std::vector<StyleInfo>::iterator iter;
1044 for (iter = styleTable.begin() ; iter != styleTable.end() ; iter++)
1045 {
1046 outs.printf("<style:style style:name=\"%s\"", iter->name.c_str());
1047 StyleInfo s(*iter);
1048 outs.printf(" style:family=\"graphic\" style:parent-style-name=\"standard\">\n");
1049 outs.printf(" <style:graphic-properties");
1050 outs.printf(" draw:fill=\"%s\" ", s.fill.c_str());
1051 if (s.fill != "none")
1052 {
1053 outs.printf(" draw:fill-color=\"%s\" ", s.fillColor.c_str());
1054 outs.printf(" draw:fill-opacity=\"%s\" ", s.fillOpacity.c_str());
1055 }
1056 outs.printf(" draw:stroke=\"%s\" ", s.stroke.c_str());
1057 if (s.stroke != "none")
1058 {
1059 outs.printf(" svg:stroke-width=\"%s\" ", s.strokeWidth.c_str());
1060 outs.printf(" svg:stroke-color=\"%s\" ", s.strokeColor.c_str());
1061 outs.printf(" svg:stroke-opacity=\"%s\" ", s.strokeOpacity.c_str());
1062 }
1063 outs.printf("/>\n");
1064 outs.printf("</style:style>\n");
1065 }
1067 outs.printf("</office:automatic-styles>\n");
1068 outs.printf("\n");
1070 return true;
1071 }
1074 static void
1075 writePath(Writer &outs, NArtBpath const *bpath,
1076 NR::Matrix &tf, double xoff, double yoff)
1077 {
1078 bool closed = false;
1079 NArtBpath *bp = (NArtBpath *)bpath;
1080 for ( ; bp->code != NR_END; bp++)
1081 {
1082 NR::Point const p1(bp->c(1) * tf);
1083 NR::Point const p2(bp->c(2) * tf);
1084 NR::Point const p3(bp->c(3) * tf);
1085 double x1 = (p1[NR::X] * pxToCm - xoff) * 1000.0;
1086 double y1 = (p1[NR::Y] * pxToCm - yoff) * 1000.0;
1087 double x2 = (p2[NR::X] * pxToCm - xoff) * 1000.0;
1088 double y2 = (p2[NR::Y] * pxToCm - yoff) * 1000.0;
1089 double x3 = (p3[NR::X] * pxToCm - xoff) * 1000.0;
1090 double y3 = (p3[NR::Y] * pxToCm - yoff) * 1000.0;
1092 switch (bp->code)
1093 {
1094 case NR_LINETO:
1095 outs.printf("L %.3f,%.3f ", x3 , y3);
1096 break;
1098 case NR_CURVETO:
1099 outs.printf("C %.3f,%.3f %.3f,%.3f %.3f,%.3f ",
1100 x1, y1, x2, y2, x3, y3);
1101 break;
1103 case NR_MOVETO_OPEN:
1104 case NR_MOVETO:
1105 if (closed)
1106 outs.printf("z ");
1107 closed = ( bp->code == NR_MOVETO );
1108 outs.printf("M %.3f,%.3f ", x3 , y3);
1109 break;
1111 default:
1112 break;
1114 }
1116 }
1118 if (closed)
1119 outs.printf("z");;
1121 }
1125 bool OdfOutput::writeTree(Writer &outs, Inkscape::XML::Node *node)
1126 {
1127 //# Get the SPItem, if applicable
1128 SPObject *reprobj = SP_ACTIVE_DOCUMENT->getObjectByRepr(node);
1129 if (!reprobj)
1130 return true;
1131 if (!SP_IS_ITEM(reprobj))
1132 {
1133 return true;
1134 }
1135 SPItem *item = SP_ITEM(reprobj);
1138 std::string nodeName = node->name();
1139 std::string id = getAttribute(node, "id");
1141 NR::Matrix tf = sp_item_i2d_affine(item);
1142 NR::Rect bbox = sp_item_bbox_desktop(item);
1144 //Flip Y into document coordinates
1145 double doc_height = sp_document_height(SP_ACTIVE_DOCUMENT);
1146 NR::Matrix doc2dt_tf = NR::Matrix(NR::scale(1, -1));
1147 doc2dt_tf = doc2dt_tf * NR::Matrix(NR::translate(0, doc_height));
1148 tf = tf * doc2dt_tf;
1149 bbox = bbox * doc2dt_tf;
1151 double x = pxToCm * bbox.min()[NR::X];
1152 double y = pxToCm * bbox.min()[NR::Y];
1153 double width = pxToCm * ( bbox.max()[NR::X] - bbox.min()[NR::X] );
1154 double height = pxToCm * ( bbox.max()[NR::Y] - bbox.min()[NR::Y] );
1157 //# Do our stuff
1158 SPCurve *curve = NULL;
1160 //g_message("##### %s #####", nodeName.c_str());
1162 if (nodeName == "svg" || nodeName == "svg:svg")
1163 {
1164 //# Iterate through the children
1165 for (Inkscape::XML::Node *child = node->firstChild() ; child ; child = child->next())
1166 {
1167 if (!writeTree(outs, child))
1168 return false;
1169 }
1170 return true;
1171 }
1172 else if (nodeName == "g" || nodeName == "svg:g")
1173 {
1174 if (id.size() > 0)
1175 outs.printf("<draw:g id=\"%s\">\n", id.c_str());
1176 else
1177 outs.printf("<draw:g>\n");
1178 //# Iterate through the children
1179 for (Inkscape::XML::Node *child = node->firstChild() ; child ; child = child->next())
1180 {
1181 if (!writeTree(outs, child))
1182 return false;
1183 }
1184 if (id.size() > 0)
1185 outs.printf("</draw:g> <!-- id=\"%s\" -->\n", id.c_str());
1186 else
1187 outs.printf("</draw:g>\n");
1188 return true;
1189 }
1190 else if (nodeName == "image" || nodeName == "svg:image")
1191 {
1192 if (!SP_IS_IMAGE(item))
1193 {
1194 g_warning("<image> is not an SPImage. Why? ;-)");
1195 return false;
1196 }
1198 SPImage *img = SP_IMAGE(item);
1199 double ix = img->x.computed;
1200 double iy = img->y.computed;
1201 double iwidth = img->width.computed;
1202 double iheight = img->height.computed;
1204 NR::Rect ibbox(NR::Point(ix, iy), NR::Point(iwidth, iheight));
1205 ix = pxToCm * ibbox.min()[NR::X];
1206 iy = pxToCm * ibbox.min()[NR::Y];
1207 iwidth = pxToCm * ( ibbox.max()[NR::X] - ibbox.min()[NR::X] );
1208 iheight = pxToCm * ( ibbox.max()[NR::Y] - ibbox.min()[NR::Y] );
1210 NR::Matrix itemTransform = item->transform;
1211 std::string itemTransformString = formatTransform(itemTransform);
1213 SingularValueDecomposition svd(itemTransform);
1214 double scale1, rotate, scale2;
1215 svd.getSingularValues(scale1, rotate, scale2);
1216 g_message("s1:%f rot:%f s2:%f", scale1, rotate, scale2);
1218 std::string href = getAttribute(node, "xlink:href");
1219 std::map<std::string, std::string>::iterator iter = imageTable.find(href);
1220 if (iter == imageTable.end())
1221 {
1222 g_warning("image '%s' not in table", href.c_str());
1223 return false;
1224 }
1225 std::string newName = iter->second;
1227 outs.printf("<draw:frame ");
1228 if (id.size() > 0)
1229 outs.printf("id=\"%s\" ", id.c_str());
1230 outs.printf("draw:style-name=\"gr1\" draw:text-style-name=\"P1\" draw:layer=\"layout\" ");
1231 outs.printf("svg:x=\"%.3fcm\" svg:y=\"%.3fcm\" ",
1232 ix, iy);
1233 outs.printf("svg:width=\"%.3fcm\" svg:height=\"%.3fcm\" ",
1234 iwidth, iheight);
1235 if (itemTransformString.size() > 0)
1236 outs.printf("draw:transform=\"%s\" ", itemTransformString.c_str());
1238 outs.printf(">\n");
1239 outs.printf(" <draw:image xlink:href=\"%s\" xlink:type=\"simple\"\n",
1240 newName.c_str());
1241 outs.printf(" xlink:show=\"embed\" xlink:actuate=\"onLoad\">\n");
1242 outs.printf(" <text:p/>\n");
1243 outs.printf(" </draw:image>\n");
1244 outs.printf("</draw:frame>\n");
1245 return true;
1246 }
1247 else if (SP_IS_SHAPE(item))
1248 {
1249 //g_message("### %s is a shape", nodeName.c_str());
1250 curve = sp_shape_get_curve(SP_SHAPE(item));
1251 }
1252 else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item))
1253 {
1254 curve = te_get_layout(item)->convertToCurves();
1255 }
1257 if (curve)
1258 {
1259 //### Default <path> output
1261 outs.printf("<draw:path ");
1262 if (id.size()>0)
1263 outs.printf("id=\"%s\" ", id.c_str());
1265 std::map<std::string, std::string>::iterator iter;
1266 iter = styleLookupTable.find(id);
1267 if (iter != styleLookupTable.end())
1268 {
1269 std::string styleName = iter->second;
1270 outs.printf("draw:style-name=\"%s\" ", styleName.c_str());
1271 }
1273 outs.printf("draw:layer=\"layout\" svg:x=\"%.3fcm\" svg:y=\"%.3fcm\" ",
1274 x, y);
1275 outs.printf("svg:width=\"%.3fcm\" svg:height=\"%.3fcm\" ",
1276 width, height);
1277 outs.printf("svg:viewBox=\"0.0 0.0 %.3f %.3f\"\n",
1278 width * 1000.0, height * 1000.0);
1280 outs.printf(" svg:d=\"");
1281 writePath(outs, curve->bpath, tf, x, y);
1282 outs.printf("\"");
1284 outs.printf(">\n");
1285 outs.printf("</draw:path>\n");
1288 sp_curve_unref(curve);
1289 }
1291 return true;
1292 }
1297 bool OdfOutput::writeContent(ZipFile &zf, Inkscape::XML::Node *node)
1298 {
1299 BufferOutputStream bouts;
1300 OutputStreamWriter outs(bouts);
1302 time_t tim;
1303 time(&tim);
1305 outs.printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1306 outs.printf("\n");
1307 outs.printf("\n");
1308 outs.printf("<!--\n");
1309 outs.printf("*************************************************************************\n");
1310 outs.printf(" file: content.xml\n");
1311 outs.printf(" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr>
1312 outs.printf(" http://www.inkscape.org\n");
1313 outs.printf("*************************************************************************\n");
1314 outs.printf("-->\n");
1315 outs.printf("\n");
1316 outs.printf("\n");
1317 outs.printf("<office:document-content\n");
1318 outs.printf(" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n");
1319 outs.printf(" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"\n");
1320 outs.printf(" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"\n");
1321 outs.printf(" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"\n");
1322 outs.printf(" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"\n");
1323 outs.printf(" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"\n");
1324 outs.printf(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n");
1325 outs.printf(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n");
1326 outs.printf(" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n");
1327 outs.printf(" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"\n");
1328 outs.printf(" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n");
1329 outs.printf(" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"\n");
1330 outs.printf(" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"\n");
1331 outs.printf(" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"\n");
1332 outs.printf(" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n");
1333 outs.printf(" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"\n");
1334 outs.printf(" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"\n");
1335 outs.printf(" xmlns:ooo=\"http://openoffice.org/2004/office\"\n");
1336 outs.printf(" xmlns:ooow=\"http://openoffice.org/2004/writer\"\n");
1337 outs.printf(" xmlns:oooc=\"http://openoffice.org/2004/calc\"\n");
1338 outs.printf(" xmlns:dom=\"http://www.w3.org/2001/xml-events\"\n");
1339 outs.printf(" xmlns:xforms=\"http://www.w3.org/2002/xforms\"\n");
1340 outs.printf(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n");
1341 outs.printf(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
1342 outs.printf(" xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n");
1343 outs.printf(" xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n");
1344 outs.printf(" office:version=\"1.0\">\n");
1345 outs.printf("\n");
1346 outs.printf("\n");
1347 outs.printf("<office:scripts/>\n");
1348 outs.printf("\n");
1349 outs.printf("\n");
1350 //AffineTransform trans = new AffineTransform();
1351 //trans.scale(12.0, 12.0);
1352 outs.printf("<!-- ######### CONVERSION FROM SVG STARTS ######## -->\n");
1353 outs.printf("<!--\n");
1354 outs.printf("*************************************************************************\n");
1355 outs.printf(" S T Y L E S\n");
1356 outs.printf(" Style entries have been pulled from the svg style and\n");
1357 outs.printf(" representation attributes in the SVG tree. The tree elements\n");
1358 outs.printf(" then refer to them by name, in the ODF manner\n");
1359 outs.printf("*************************************************************************\n");
1360 outs.printf("-->\n");
1361 outs.printf("\n");
1362 outs.printf("\n");
1364 if (!writeStyle(outs))
1365 {
1366 g_warning("Failed to write styles");
1367 return false;
1368 }
1370 outs.printf("\n");
1371 outs.printf("\n");
1372 outs.printf("\n");
1373 outs.printf("\n");
1374 outs.printf("<!--\n");
1375 outs.printf("*************************************************************************\n");
1376 outs.printf(" D R A W I N G\n");
1377 outs.printf(" This section is the heart of SVG-ODF conversion. We are\n");
1378 outs.printf(" starting with simple conversions, and will slowly evolve\n");
1379 outs.printf(" into a 'smarter' translation as time progresses. Any help\n");
1380 outs.printf(" in improving .odg export is welcome.\n");
1381 outs.printf("*************************************************************************\n");
1382 outs.printf("-->\n");
1383 outs.printf("\n");
1384 outs.printf("\n");
1385 outs.printf("<office:body>\n");
1386 outs.printf("<office:drawing>\n");
1387 outs.printf("<draw:page draw:name=\"page1\" draw:style-name=\"dp1\"\n");
1388 outs.printf(" draw:master-page-name=\"Default\">\n");
1389 outs.printf("\n");
1390 outs.printf("\n");
1392 if (!writeTree(outs, node))
1393 {
1394 g_warning("Failed to convert SVG tree");
1395 return false;
1396 }
1398 outs.printf("\n");
1399 outs.printf("\n");
1401 outs.printf("</draw:page>\n");
1402 outs.printf("</office:drawing>\n");
1404 outs.printf("\n");
1405 outs.printf("\n");
1406 outs.printf("<!-- ######### CONVERSION FROM SVG ENDS ######## -->\n");
1407 outs.printf("\n");
1408 outs.printf("\n");
1410 outs.printf("</office:body>\n");
1411 outs.printf("</office:document-content>\n");
1412 outs.printf("\n");
1413 outs.printf("\n");
1414 outs.printf("\n");
1415 outs.printf("<!--\n");
1416 outs.printf("*************************************************************************\n");
1417 outs.printf(" E N D O F F I L E\n");
1418 outs.printf(" Have a nice day - ishmal\n");
1419 outs.printf("*************************************************************************\n");
1420 outs.printf("-->\n");
1421 outs.printf("\n");
1422 outs.printf("\n");
1426 //Make our entry
1427 ZipEntry *ze = zf.newEntry("content.xml", "ODF master content file");
1428 ze->setUncompressedData(bouts.getBuffer());
1429 ze->finish();
1431 return true;
1432 }
1437 /**
1438 * Descends into the SVG tree, mapping things to ODF when appropriate
1439 */
1440 void
1441 OdfOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *uri)
1442 {
1443 ZipFile zf;
1444 styleTable.clear();
1445 styleLookupTable.clear();
1446 imageTable.clear();
1447 preprocess(zf, doc->rroot);
1448 g_message("native file:%s\n", uri);
1449 documentUri = URI(uri);
1451 if (!writeManifest(zf))
1452 {
1453 g_warning("Failed to write manifest");
1454 return;
1455 }
1457 if (!writeMeta(zf))
1458 {
1459 g_warning("Failed to write metafile");
1460 return;
1461 }
1463 if (!writeContent(zf, doc->rroot))
1464 {
1465 g_warning("Failed to write content");
1466 return;
1467 }
1469 if (!zf.writeFile(uri))
1470 {
1471 return;
1472 }
1473 }
1476 /**
1477 * This is the definition of PovRay output. This function just
1478 * calls the extension system with the memory allocated XML that
1479 * describes the data.
1480 */
1481 void
1482 OdfOutput::init()
1483 {
1484 Inkscape::Extension::build_from_mem(
1485 "<inkscape-extension>\n"
1486 "<name>" N_("OpenDocument Drawing Output") "</name>\n"
1487 "<id>org.inkscape.output.odf</id>\n"
1488 "<output>\n"
1489 "<extension>.odg</extension>\n"
1490 "<mimetype>text/x-povray-script</mimetype>\n"
1491 "<filetypename>" N_("OpenDocument drawing (*.odg)") "</filetypename>\n"
1492 "<filetypetooltip>" N_("OpenDocument drawing file") "</filetypetooltip>\n"
1493 "</output>\n"
1494 "</inkscape-extension>",
1495 new OdfOutput());
1496 }
1498 /**
1499 * Make sure that we are in the database
1500 */
1501 bool
1502 OdfOutput::check (Inkscape::Extension::Extension *module)
1503 {
1504 /* We don't need a Key
1505 if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_POV))
1506 return FALSE;
1507 */
1509 return TRUE;
1510 }
1514 //########################################################################
1515 //# I N P U T
1516 //########################################################################
1520 //#######################
1521 //# L A T E R !!! :-)
1522 //#######################
1536 } //namespace Internal
1537 } //namespace Extension
1538 } //namespace Inkscape
1541 //########################################################################
1542 //# E N D O F F I L E
1543 //########################################################################
1545 /*
1546 Local Variables:
1547 mode:c++
1548 c-file-style:"stroustrup"
1549 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1550 indent-tabs-mode:nil
1551 fill-column:99
1552 End:
1553 */
1554 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :