odf.cpp revision 294291ae552cefe0a7e38e80153ec4a2d36b459e
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * OpenDocument <drawing> input and output
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * This is an an entry in the extensions mechanism to begin to enable
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * the inputting and outputting of OpenDocument Format (ODF) files from
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * within Inkscape. Although the initial implementations will be very lossy
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * due to the differences in the models of SVG and ODF, they will hopefully
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * improve greatly with time. People should consider this to be a framework
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * that can be continously upgraded for ever improving fidelity. Potential
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * developers should especially look in preprocess() and writeTree() to see how
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * the SVG tree is scanned, read, translated, and then written to ODF.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * Bob Jamison
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * Abhishek Sharma
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * Kris De Gussem
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * Copyright (C) 2006, 2007 Bob Jamison
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * Copyright (C) 2013 Kris De Gussem
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * This library is free software; you can redistribute it and/or
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * modify it under the terms of the GNU Lesser General Public
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * License as published by the Free Software Foundation; either
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * version 2.1 of the License, or (at your option) any later version.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * This library is distributed in the hope that it will be useful,
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * but WITHOUT ANY WARRANTY; without even the implied warranty of
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter * Lesser General Public License for more details.
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter * You should have received a copy of the GNU Lesser General Public
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * License along with this library; if not, write to the Free Software
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter//# System includes
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter//# Inkscape includes
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter//# DOM-specific includes
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter//# Shorthand notation
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_sutertypedef Inkscape::IO::BufferOutputStream BufferOutputStream;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_sutertypedef Inkscape::IO::OutputStreamWriter OutputStreamWriter;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_sutertypedef Inkscape::IO::StringOutputStream StringOutputStream;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter//########################################################################
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter//# C L A S S SingularValueDecomposition
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter//########################################################################
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter SVDMatrix(unsigned int rowSize, unsigned int colSize)
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter d = new double[size];
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (unsigned int i=0 ; i<size ; i++)
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter SVDMatrix(double *vals, unsigned int rowSize, unsigned int colSize)
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter d = new double[size];
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (unsigned int i=0 ; i<size ; i++)
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter return *this;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double& operator() (unsigned int row, unsigned int col)
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double operator() (unsigned int row, unsigned int col) const
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter unsigned int getRows()
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter unsigned int getCols()
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (unsigned int i=0 ; i<rows ; i++)
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (unsigned int k=0 ; k<cols ; k++)
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter //sum += a[i][k] * b[k][j];
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter for (unsigned int i=0 ; i<rows ; i++){
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter for (unsigned int j=0 ; j<cols ; j++){
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter virtual void init()
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter d = new double[size];
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (unsigned int i=0 ; i<size ; i++){
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter unsigned int rows;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter unsigned int cols;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter unsigned int size;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * ====================================================
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * This class is ported almost verbatim from the public domain
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * JAMA Matrix package. It is modified to handle only 3x3 matrices
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * and our Geom::Affine affine transform class. We give full
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * attribution to them, along with many thanks. JAMA can be found at:
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * ====================================================
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * Singular Value Decomposition.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * For an m-by-n matrix A with m >= n, the singular value decomposition is
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * an m-by-n orthogonal matrix U, an n-by-n diagonal matrix S, and
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * an n-by-n orthogonal matrix V so that A = U*S*V'.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * The singular values, sigma[k] = S[k][k], are ordered so that
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * sigma[0] >= sigma[1] >= ... >= sigma[n-1].
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * The singular value decompostion always exists, so the constructor will
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * never fail. The matrix condition number and the effective numerical
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * rank can be computed from this decomposition.
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter /** Construct the singular value decomposition
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter @param A Rectangular matrix
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter @return Structure to access U, S and V.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter SingularValueDecomposition (const SVDMatrix &mat) :
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter * Return the left singular vectors
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter * Return the right singular vectors
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter * Return the s[index] value
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * @return max(S)
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * Two norm condition number
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * @return max(S)/min(S)
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * Effective numerical matrix rank
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter * @return Number of nonnegligible singular values.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter unsigned int s_size;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suterstatic double svd_hypot(double a, double b)
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter else if (b != 0)
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Initialize.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter int nu = (m > n) ? m : n;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter s = new double[s_size];
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double *e = new double[n];
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double *work = new double[m];
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Reduce A to bidiagonal form, storing the diagonal elements
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // in s and the super-diagonal elements in e.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int k = 0; k < 2; k++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Compute the transformation for the k-th column and
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // place the k-th diagonal in s[k].
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Compute 2-norm of k-th column without under/overflow.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = k; i < m; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter s[k] = svd_hypot(s[k],A(i, k));
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter if (s[k] != 0.0) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter if (A(k, k) < 0.0) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter s[k] = -s[k];
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = k; i < m; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter A(i, k) /= s[k];
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter A(k, k) += 1.0;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter s[k] = -s[k];
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int j = k+1; j < n; j++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Apply the transformation.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double t = 0;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = k; i < m; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter t += A(i, k) * A(i, j);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter t = -t/A(k, k);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = k; i < m; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter A(i, j) += t*A(i, k);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Place the k-th row of A into e for the
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // subsequent calculation of the row transformation.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter e[j] = A(k, j);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Place the transformation in U for subsequent back
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // multiplication.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = k; i < m; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter U(i, k) = A(i, k);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Compute the k-th row transformation and place the
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // k-th super-diagonal in e[k].
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Compute 2-norm without under/overflow.
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter for (int i = k+1; i < n; i++) {
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter e[k] = svd_hypot(e[k],e[i]);
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter if (e[k] != 0.0) {
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter e[k] = -e[k];
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter for (int i = k+1; i < n; i++) {
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter e[i] /= e[k];
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter e[k] = -e[k];
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter // Apply the transformation.
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter for (int i = k+1; i < m; i++) {
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter for (int j = k+1; j < n; j++) {
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter for (int i = k+1; i < m; i++) {
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter work[i] += e[j]*A(i, j);
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter for (int j = k+1; j < n; j++) {
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter double t = -e[j]/e[k+1];
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter for (int i = k+1; i < m; i++) {
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter A(i, j) += t*work[i];
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter // Place the transformation in V for subsequent
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter // back multiplication.
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter for (int i = k+1; i < n; i++) {
4b96f5a934679a5e6841dadd9da652f935c135abkenneth_suter V(i, k) = e[i];
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Set up the final bidiagonal matrix or order p.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // If required, generate U.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = 0; i < m; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter U(i, j) = 0.0;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter U(j, j) = 1.0;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter if (s[k] != 0.0) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double t = 0;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = k; i < m; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter t += U(i, k)*U(i, j);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter t = -t/U(k, k);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = k; i < m; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter U(i, j) += t*U(i, k);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = k; i < m; i++ ) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter U(i, k) = -U(i, k);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter U(k, k) = 1.0 + U(k, k);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = 0; i < k-1; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter U(i, k) = 0.0;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = 0; i < m; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter U(i, k) = 0.0;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter U(k, k) = 1.0;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // If required, generate V.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int k = n-1; k >= 0; k--) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double t = 0;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = k+1; i < n; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter t += V(i, k)*V(i, j);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter t = -t/V(k+1, k);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = k+1; i < n; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter V(i, j) += t*V(i, k);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = 0; i < n; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter V(i, k) = 0.0;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter V(k, k) = 1.0;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Main iteration loop for the singular values.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter //double eps = pow(2.0,-52.0);
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter //double tiny = pow(2.0,-966.0);
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter //let's just calculate these now
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter //a double can be e ± 308.25, so this is safe
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter while (p > 0) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Here is where a test for too many iterations would go.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // This section of the program inspects for
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // negligible elements in the s and e arrays. On
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // completion the variables kase and k are set as follows.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // kase = 1 if s(p) and e[k-1] are negligible and k<p
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // kase = 2 if s(k) is negligible and k<p
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // kase = 3 if e[k-1] is negligible, k<p, and
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // s(k), ..., s(p) are not negligible (qr step).
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // kase = 4 if e(p-1) is negligible (convergence).
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter if (k == -1) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter if (k == p-2) {
857225469c51bedb8c0566aa7757800cfaac4075kenneth_suter // Perform the task indicated by kase.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Deflate negligible s(p).
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double f = e[p-2];
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int j = p-2; j >= k; j--) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double t = svd_hypot(s[j],f);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double cs = s[j]/t;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double sn = f/t;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter if (j != k) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = 0; i < n; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Split at negligible s(k).
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double f = e[k-1];
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int j = k; j < p; j++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double t = svd_hypot(s[j],f);
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double cs = s[j]/t;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double sn = f/t;
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter e[j] = cs*e[j];
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter for (int i = 0; i < m; i++) {
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Perform one qr step.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter // Calculate the shift.
e7b89fa07f734d79858edc56f1078a08f8b66d46kenneth_suter double b = ((spm1 + sp)*(spm1 - sp) + epm1*epm1)/2.0;
7d3f4266f65e3151ca1a30321657d6083d6ec513kenneth_suter if (b < 0.0) {
b9126d47d00474e66e7e5881452b9385ffe38c94kenneth_suter // Chase zeros.
b9126d47d00474e66e7e5881452b9385ffe38c94kenneth_suter for (int j = k; j < p-1; j++) {
b9126d47d00474e66e7e5881452b9385ffe38c94kenneth_suter double t = svd_hypot(f,g);
b9126d47d00474e66e7e5881452b9385ffe38c94kenneth_suter double cs = f/t;
b9126d47d00474e66e7e5881452b9385ffe38c94kenneth_suter double sn = g/t;
b9126d47d00474e66e7e5881452b9385ffe38c94kenneth_suter if (j != k) {
if (wantv) {
t = svd_hypot(f,g);
cs = f/t;
sn = g/t;
if (wantv) {
for (int i = 0; i <= pp; i++) {
while (k < pp) {
delete [] work;
return s[index];
if (s[i] > tol)
if (valstr)
return val;
return ext;
return str;
Geom::Affine doc2dt_tf = Geom::Affine(Geom::Scale(1.0, -1.0)); /// @fixme hardcoded desktop transform
return tf;
if (bbox) {
return bbox;
return itemTransform;
if (!reprobj)
if (ze)
outs.writeString("<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">\n");
outs.writeString("<manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\">\n");
outs.writeString(" <manifest:file-entry manifest:media-type=\"application/vnd.oasis.opendocument.graphics\" manifest:full-path=\"/\"/>\n");
outs.writeString(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/>\n");
outs.writeString(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"styles.xml\"/>\n");
outs.writeString(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"meta.xml\"/>\n");
* This writes the document meta information to meta.xml
outs.writeString("xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n");
Glib::ustring tmp = Glib::ustring::compose(" <meta:generator>%1</meta:generator>\n", InkscapeVersion);
using Geom::X;
using Geom::Y;
int nrPoints = 0;
Geom::PathVector pv = pathv_to_linear_and_cubic_beziers(pathv * tf * Geom::Translate(xoff, yoff) * Geom::Scale(1000.));
nrPoints++;
if (fabs(points[i][X])<1.0) points[i][X] = 0.0; // Why is this needed? Shouldn't we just round all numbers then?
outs.printf("C %.3f %.3f %.3f %.3f %.3f %.3f ", points[1][X],points[1][Y], points[2][X],points[2][Y], points[3][X],points[3][Y]);
nrPoints++;
return nrPoints;
bool OdfOutput::processStyle(SPItem *item, const Glib::ustring &id, const Glib::ustring &gradientNameFill, const Glib::ustring &gradientNameStroke, Glib::ustring& output)
if (!item)
if (!style)
if (gradient)
if (gradient)
bool styleMatch = false;
styleMatch = true;
if (styleMatch)
output = Glib::ustring::compose ("<style:style style:name=\"%1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n", si.name);
output += Glib::ustring::compose (" draw:fill=\"gradient\" draw:fill-gradient-name=\"%1\"", gradientNameFill);
output += Glib::ustring::compose (" draw:stroke=\"gradient\" draw:stroke-gradient-name=\"%1\"", gradientNameStroke);
output += Glib::ustring::compose (" svg:stroke-width=\"%1\" svg:stroke-color=\"%2\" ", si.strokeWidth, si.strokeColor);
if (!item)
if (!style)
SPGradient *gradient = SP_GRADIENT((checkFillGradient?(SP_STYLE_FILL_SERVER(style)) :(SP_STYLE_STROKE_SERVER(style))));
bool gradientMatch = false;
gradientMatch = true;
if (gradientMatch)
// int gradientCount = gradientTable.size();
snprintf(buf, 127, " draw:start-color=\"#%06lx\" draw:end-color=\"#%06lx\"", gi.stops[0].rgb, gi.stops[1].rgb);
//TODO: apply maths, to define begin of gradient, taking gradient begin and end, as well as object boundary into account
output += Glib::ustring::compose(" draw:start-intensity=\"%1\" draw:end-intensity=\"%2\" draw:angle=\"%3\"/>\n",
output += Glib::ustring::compose("<draw:gradient draw:name=\"%1\" draw:display-name=\"%1\" ", gi.name);
snprintf(buf, 127, "draw:start-color=\"#%06lx\" draw:end-color=\"#%06lx\" ", gi.stops[0].rgb, gi.stops[1].rgb);
snprintf(buf, 127, "draw:start-intensity=\"%f%%\" draw:end-intensity=\"%f%%\" ", gi.stops[0].opacity*100.0, gi.stops[1].opacity*100.0);
if (!reprobj)
if (!bbox) {
double rotate;
double xskew;
double yskew;
double xscale;
double yscale;
if (curve)
* Write the header for the content.xml file
outs.writeString(" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n");
* Write the footer for the style.xml file
outs.writeString("<style:style style:name=\"gr1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n");
outs.writeString(" draw:luminance=\"0%\" draw:contrast=\"0%\" draw:gamma=\"100%\" draw:red=\"0%\"\n");
* Write the header for the content.xml file
outs.writeString(" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n");
* Write the footer for the content.xml file
* Write the content.xml file. Writes the namesspace headers, then
//Content.xml stream
//Style.xml stream
reset();
"<mimetype>text/x-povray-script</mimetype>\n"
new OdfOutput());
return TRUE;