/*
10 * Copyright (C) 2018 Authors
11 * Released under GNU LGPL v2.1+, read the file
'COPYING' for more information.
108 SVDMatrix(
unsigned int rowSize,
unsigned int colSize)
114 d =
new double[
size];
115 for (
unsigned int i=0 ; i<
size ; i++)
119 SVDMatrix(
double *vals,
unsigned int rowSize,
unsigned int colSize)
125 d =
new double[
size];
126 for (
unsigned int i=0 ; i<
size ; i++)
131 SVDMatrix(
const SVDMatrix &other)
137 SVDMatrix &operator=(
const SVDMatrix &other)
148 double& operator() (
unsigned int row,
unsigned int col)
150 if (row >= rows || col >= cols)
152 return d[cols*row + col];
155 double operator() (
unsigned int row,
unsigned int col)
const
157 if (row >= rows || col >= cols)
159 return d[cols*row + col];
162 unsigned int getRows()
167 unsigned int getCols()
172 SVDMatrix multiply(
const SVDMatrix &other)
174 if (cols != other.rows)
179 SVDMatrix
result(rows, other.cols);
180 for (
unsigned int i=0 ; i<rows ; i++)
182 for (
unsigned int j=0 ; j<other.cols ; j++)
185 for (
unsigned int k=0 ; k<cols ; k++)
188 sum += d[i*cols +k] * other(k, j);
197 SVDMatrix transpose()
199 SVDMatrix
result(cols, rows);
200 for (
unsigned int i=0 ; i<rows ; i++){
201 for (
unsigned int j=0 ; j<cols ; j++){
202 result(j, i) = d[i*cols + j];
220 void assign(
const SVDMatrix &other)
230 badval = other.badval;
231 d =
new double[
size];
232 for (
unsigned int i=0 ; i<
size ; i++){
273class SingularValueDecomposition
282 SingularValueDecomposition (
const SVDMatrix &mat) :
292 virtual ~SingularValueDecomposition()
double getS(
unsigned int index);
348 if (fabs(a) > fabs(b))
351 r = fabs(a) * sqrt(1+r*r);
356 r = fabs(b) * sqrt(1+r*r);
367void SingularValueDecomposition::calculate()
373 int nu = (m > n) ? m : n;
374 s_size = (m+1 < n) ? m+1 : n;
375 s =
new double[s_size];
376 U = SVDMatrix(m, nu);
378 double *e =
new double[n];
379 double *work =
new double[m];
386 int nct = (m-1<n) ? m-1 : n;
387 int nrtx = (n-2<m) ? n-2 : m;
388 int nrt = (nrtx>0) ? nrtx : 0;
389 for (
int k = 0; k < 2; k++) {
396 for (
int i = k; i < m; i++) {
403 for (
int i = k; i < m; i++) {
410 for (
int j = k+1; j <
n; j++) {
411 if ((k < nct) & (s[k] != 0.0)) {
416 for (
int i = k; i < m; i++) {
417 t += A(i, k) * A(i, j);
420 for (
int i = k; i < m; i++) {
421 A(i, j) += t*A(i, k);
430 if (wantu & (k < nct)) {
435 for (
int i = k; i < m; i++) {
445 for (
int i = k+1; i <
n; i++) {
452 for (
int i = k+1; i <
n; i++) {
458 if ((k+1 < m) & (e[k] != 0.0)) {
462 for (
int i = k+1; i < m; i++) {
465 for (
int j = k+1; j <
n; j++) {
466 for (
int i = k+1; i < m; i++) {
467 work[i] += e[j]*A(i, j);
470 for (
int j = k+1; j <
n; j++) {
471 double t = -e[j]/e[k+1];
472 for (
int i = k+1; i < m; i++) {
473 A(i, j) += t*work[i];
482 for (
int i = k+1; i <
n; i++) {
491 int p = (
n < m+1) ? n : m+1;
493 s[nct] = A(nct, nct);
499 e[nrt] = A(nrt, p-1);
506 for (
int j = nct; j < nu; j++) {
507 for (
int i = 0; i < m; i++) {
512 for (
int k = nct-1; k >= 0; k--) {
514 for (
int j = k+1; j < nu; j++) {
516 for (
int i = k; i < m; i++) {
517 t += U(i, k)*U(i, j);
520 for (
int i = k; i < m; i++) {
521 U(i, j) += t*U(i, k);
524 for (
int i = k; i < m; i++ ) {
527 U(k, k) = 1.0 + U(k, k);
528 for (
int i = 0; i < k-1; i++) {
532 for (
int i = 0; i < m; i++) {
543 for (
int k = n-1; k >= 0; k--) {
544 if ((k < nrt) & (e[k] != 0.0)) {
545 for (
int j = k+1; j < nu; j++) {
547 for (
int i = k+1; i <
n; i++) {
548 t += V(i, k)*V(i, j);
551 for (
int i = k+1; i <
n; i++) {
552 V(i, j) += t*V(i, k);
556 for (
int i = 0; i <
n; i++) {
570 double eps = 2.22e-16;
571 double tiny = 1.6e-291;
587 for (k = p-2; k >= -1; k--) {
592 tiny + eps*(fabs(s[k]) + fabs(s[k+1]))) {
601 for (ks = p-1; ks >= k; ks--) {
605 double t = (ks != p ? fabs(e[ks]) : 0.) +
606 (ks != k+1 ? fabs(e[ks-1]) : 0.);
607 if (fabs(s[ks]) <= tiny + eps*t) {
614 }
else if (ks == p-1) {
632 for (
int j = p-2; j >= k; j--) {
642 for (
int i = 0; i <
n; i++) {
643 t = cs*V(i, j) + sn*V(i, p-1);
644 V(i, p-1) = -sn*V(i, j) + cs*V(i, p-1);
657 for (
int j = k; j < p; j++) {
665 for (
int i = 0; i < m; i++) {
666 t = cs*U(i, j) + sn*U(i, k-1);
667 U(i, k-1) = -sn*U(i, j) + cs*U(i, k-1);
681 double scale = fabs(s[p-1]);
682 double d = fabs(s[p-2]);
683 if (d>scale)
scale=d;
685 if (d>scale)
scale=d;
687 if (d>scale)
scale=d;
689 if (d>scale)
scale=d;
690 double sp = s[p-1]/
scale;
691 double spm1 = s[p-2]/
scale;
692 double epm1 = e[p-2]/
scale;
693 double sk = s[k]/
scale;
694 double ek = e[k]/
scale;
695 double b = ((spm1 + sp)*(spm1 - sp) + epm1*epm1)/2.0;
696 double c = (sp*epm1)*(sp*epm1);
698 if ((b != 0.0) | (
c != 0.0)) {
705 double f = (sk + sp)*(sk - sp) +
shift;
710 for (
int j = k; j < p-1; j++) {
717 f = cs*s[j] + sn*e[j];
718 e[j] = cs*e[j] - sn*s[j];
722 for (
int i = 0; i <
n; i++) {
723 t = cs*V(i, j) + sn*V(i, j+1);
724 V(i, j+1) = -sn*V(i, j) + cs*V(i, j+1);
732 f = cs*e[j] + sn*s[j+1];
733 s[j+1] = -sn*e[j] + cs*s[j+1];
736 if (wantu && (j < m-1)) {
737 for (
int i = 0; i < m; i++) {
738 t = cs*U(i, j) + sn*U(i, j+1);
739 U(i, j+1) = -sn*U(i, j) + cs*U(i, j+1);
755 s[k] = (s[k] < 0.0 ? -s[k] : 0.0);
757 for (
int i = 0; i <= pp; i++) {
766 if (s[k] >= s[k+1]) {
772 if (wantv && (k < n-1)) {
773 for (
int i = 0; i <
n; i++) {
774 t = V(i, k+1); V(i, k+1) = V(i, k); V(i, k) = t;
777 if (wantu && (k < m-1)) {
778 for (
int i = 0; i < m; i++) {
779 t = U(i, k+1); U(i, k+1) = U(i, k); U(i, k) = t;
800SVDMatrix &SingularValueDecomposition::getU()
810SVDMatrix &SingularValueDecomposition::getV()
818double SingularValueDecomposition::getS(
unsigned int index)
829double SingularValueDecomposition::norm2()
839double SingularValueDecomposition::cond()
848int SingularValueDecomposition::rank()
850 double eps =
pow(2.0,-52.0);
851 double tol = 3.0*s[0]*eps;
853 for (
int i = 0; i < 3; i++)
897 out.
printf(
"matrix(%.3f %.3f %.3f %.3f %.3f %.3f)",
898 tf[0], tf[1], tf[2], tf[3], tf[4], tf[5]);
941 return itemTransform;
949 double &rotate,
double &,
double &,
950 double &xscale,
double &yscale)
958 SingularValueDecomposition svd(mat);
960 SVDMatrix U = svd.getU();
961 SVDMatrix V = svd.getV();
962 SVDMatrix Vt = V.transpose();
963 SVDMatrix UVt = U.multiply(Vt);
964 double s0 = svd.getS(0);
965 double s1 = svd.getS(1);
996 Glib::ustring nodeName =
node->
name();
1000 if (nodeName ==
"metadata" || nodeName ==
"svg:metadata")
1003 if (!mchild || strcmp(mchild->
name(),
"rdf:RDF"))
1006 if (!rchild || strcmp(rchild->
name(),
"cc:Work"))
1009 cchild ; cchild = cchild->next())
1011 Glib::ustring ccName = cchild->
name();
1012 Glib::ustring ccVal;
1026 if (!is<SPItem>(reprobj))
1031 if (nodeName ==
"image" || nodeName ==
"svg:image") {
1033 if (href.size() > 0 &&
imageTable.count(href) == 0) {
1036 auto mimetype = uri.getMimeType();
1038 if (mimetype.substr(0, 6) !=
"image/") {
1042 auto ext = mimetype.substr(6);
1043 auto newName = Glib::ustring(
"Pictures/image") + std::to_string(
imageTable.size()) +
"." + ext;
1047 auto ze = zf.
newEntry(newName.raw(),
"");
1051 g_warning(
"Could not handle URI '%.100s'", href.c_str());
1074 outs.
writeString(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1075 outs.
writeString(
"<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">\n");
1079 outs.
writeString(
"*************************************************************************\n");
1081 outs.
printf (
" Generated by Inkscape: %s", ctime(&tim));
1083 outs.
writeString(
"*************************************************************************\n");
1087 outs.
writeString(
"<manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\">\n");
1088 outs.
writeString(
" <manifest:file-entry manifest:media-type=\"application/vnd.oasis.opendocument.graphics\" manifest:full-path=\"/\"/>\n");
1089 outs.
writeString(
" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/>\n");
1090 outs.
writeString(
" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"styles.xml\"/>\n");
1091 outs.
writeString(
" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"meta.xml\"/>\n");
1092 outs.
writeString(
" <!--List our images here-->\n");
1093 std::map<Glib::ustring, Glib::ustring>::iterator iter;
1096 Glib::ustring newName = iter->second;
1101 outs.
printf(
" <manifest:file-entry manifest:media-type=\"");
1103 outs.
printf(
"%s", mimesubtype.c_str());
1104 outs.
printf(
"\" manifest:full-path=\"");
1108 outs.
printf(
"</manifest:manifest>\n");
1132 std::map<Glib::ustring, Glib::ustring>::iterator iter;
1134 Glib::ustring creator = InkscapeVersion;
1135 iter =
metadata.find(
"dc:creator");
1138 creator = iter->second;
1142 Glib::ustring moddate;
1145 struct tm * timeinfo;
1147 timeinfo = localtime (&rawtime);
1148 strftime (
buf,80,
"%Y-%m-%d %H:%M:%S",timeinfo);
1149 moddate = Glib::ustring(
buf);
1154 date = iter->second;
1161 outs.
writeString(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1164 outs.
writeString(
"*************************************************************************\n");
1166 outs.
printf (
" Generated by Inkscape: %s", ctime(&tim));
1168 outs.
writeString(
"*************************************************************************\n");
1172 outs.
writeString(
"xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n");
1173 outs.
writeString(
"xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n");
1174 outs.
writeString(
"xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n");
1175 outs.
writeString(
"xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n");
1176 outs.
writeString(
"xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n");
1177 outs.
writeString(
"xmlns:ooo=\"http://openoffice.org/2004/office\"\n");
1178 outs.
writeString(
"xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n");
1179 outs.
writeString(
"xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n");
1182 Glib::ustring tmp = Glib::ustring::compose(
" <meta:generator>%1</meta:generator>\n", InkscapeVersion);
1183 tmp += Glib::ustring::compose(
" <meta:initial-creator>%1</meta:initial-creator>\n", creator);
1184 tmp += Glib::ustring::compose(
" <meta:creation-date>%1</meta:creation-date>\n", date);
1185 tmp += Glib::ustring::compose(
" <dc:date>%1</dc:date>\n", moddate);
1189 Glib::ustring
name = iter->first;
1190 Glib::ustring value = iter->second;
1191 if (!
name.empty() && !value.empty())
1193 tmp = Glib::ustring::compose(
" <%1>%2</%3>\n",
name, value,
name);
1232 for (
const auto & pit : pv) {
1234 double destx = pit.initialPoint()[X];
1235 double desty = pit.initialPoint()[Y];
1236 if (fabs(destx)<1.0) destx = 0.0;
1237 if (fabs(desty)<1.0) desty = 0.0;
1238 outs.
printf(
"M %.3f %.3f ", destx, desty);
1245 double destx = cit->finalPoint()[X];
1246 double desty = cit->finalPoint()[Y];
1247 if (fabs(destx)<1.0) destx = 0.0;
1248 if (fabs(desty)<1.0) desty = 0.0;
1249 outs.
printf(
"L %.3f %.3f ", destx, desty);
1252 std::vector<Geom::Point> points = cubic->controlPoints();
1253 for (
unsigned i = 1; i <= 3; i++) {
1254 if (fabs(points[i][X])<1.0) points[i][X] = 0.0;
1255 if (fabs(points[i][Y])<1.0) points[i][Y] = 0.0;
1257 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]);
1260 g_error (
"logical error, because pathv_to_linear_and_cubic_beziers was used");
1291 if (style->
fill.isColor())
1293 guint32 fillCol = style->
fill.getColor().toRGBA();
1295 int r = (fillCol >> 24) & 0xff;
1296 int g = (fillCol >> 16) & 0xff;
1297 int b = (fillCol >> 8) & 0xff;
1298 snprintf(
buf, 15,
"#%02x%02x%02x", r, g, b);
1301 double opacityPercent = 100.0 *
1303 snprintf(
buf, 15,
"%.3f%%", opacityPercent);
1306 else if (style->
fill.isPaintserver())
1308 auto gradient = cast<SPGradient>(SP_STYLE_FILL_SERVER(style));
1311 si.
fill =
"gradient";
1316 if (style->
stroke.isColor())
1320 int r = (strokeCol >> 24) & 0xff;
1321 int g = (strokeCol >> 16) & 0xff;
1322 int b = (strokeCol >> 8) & 0xff;
1323 snprintf(
buf, 15,
"#%02x%02x%02x", r, g, b);
1328 double opacityPercent = 100.0 *
1330 snprintf(
buf, 15,
"%.3f%%", opacityPercent);
1333 else if (style->
stroke.isPaintserver())
1335 auto gradient = cast<SPGradient>(SP_STYLE_STROKE_SERVER(style));
1343 bool styleMatch =
false;
1344 std::vector<StyleInfo>::iterator iter;
1350 Glib::ustring styleName = iter->name;
1363 Glib::ustring styleName = Glib::ustring::compose(
"style%1",
styleTable.size());
1364 si.
name = styleName;
1368 output = Glib::ustring::compose (
"<style:style style:name=\"%1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n", si.
name);
1369 output +=
"<style:graphic-properties";
1370 if (si.
fill ==
"gradient")
1372 output += Glib::ustring::compose (
" draw:fill=\"gradient\" draw:fill-gradient-name=\"%1\"", gradientNameFill);
1376 output += Glib::ustring(
" draw:fill=\"") + si.
fill +
"\"";
1377 if(si.
fill !=
"none")
1379 output += Glib::ustring::compose(
" draw:fill-color=\"%1\"", si.
fillColor);
1382 if (si.
stroke ==
"gradient")
1385 output += Glib::ustring::compose (
" draw:stroke=\"gradient\" draw:stroke-gradient-name=\"%1\"", gradientNameStroke);
1389 output += Glib::ustring(
" draw:stroke=\"") + si.
stroke +
"\"";
1392 output += Glib::ustring::compose (
" svg:stroke-width=\"%1\" svg:stroke-color=\"%2\" ", si.
strokeWidth, si.
strokeColor);
1395 output +=
"/>\n</style:style>\n";
1402 Glib::ustring& gradientName, Glib::ustring& output,
bool checkFillGradient)
1416 if ((checkFillGradient? (!style->
fill.isPaintserver()) : (!style->
stroke.isPaintserver())))
1422 auto gradient = cast<SPGradient>((checkFillGradient?(SP_STYLE_FILL_SERVER(style)) :(SP_STYLE_STROKE_SERVER(style))));
1424 if (gradient ==
nullptr)
1434 auto color = stop->getColor().toRGBA(
false);
1435 auto opacity = stop->getColor().getOpacity();
1440 Glib::ustring gradientName2;
1441 if (is<SPLinearGradient>(gradient))
1443 gi.
style =
"linear";
1444 auto linGrad = cast<SPLinearGradient>(gradient);
1445 gi.
x1 = linGrad->x1.value;
1446 gi.
y1 = linGrad->y1.value;
1447 gi.
x2 = linGrad->x2.value;
1448 gi.
y2 = linGrad->y2.value;
1449 gradientName2 = Glib::ustring::compose(
"ImportedLinearGradient%1",
gradientTable.size());
1451 else if (is<SPRadialGradient>(gradient))
1453 gi.
style =
"radial";
1454 auto radGrad = cast<SPRadialGradient>(gradient);
1456 gi.
cx = (radGrad->cx.value-bbox->left())/bbox->width();
1457 gi.
cy = (radGrad->cy.value-bbox->top())/bbox->height();
1458 gradientName2 = Glib::ustring::compose(
"ImportedRadialGradient%1",
gradientTable.size());
1462 g_warning(
"not a supported gradient type");
1467 bool gradientMatch =
false;
1468 std::vector<GradientInfo>::iterator iter;
1474 gradientName = iter->name;
1476 gradientMatch =
true;
1487 gradientName = gradientName2;
1488 gi.
name = gradientName;
1494 if (gi.
style ==
"linear")
1507 if (gi.
stops.size() < 2)
1509 g_warning(
"Need at least 2 stops for a linear gradient");
1512 output += Glib::ustring::compose(
"<draw:gradient draw:name=\"%1\"", gi.
name);
1513 output += Glib::ustring::compose(
" draw:display-name=\"%1\"", gi.
name);
1514 output +=
" draw:style=\"linear\"";
1515 snprintf(
buf, 127,
" draw:start-color=\"#%06lx\" draw:end-color=\"#%06lx\"", gi.
stops[0].rgb, gi.
stops[1].rgb);
1518 double angle = (gi.
y2-gi.
y1);
1519 angle = (angle != 0.) ? (atan((gi.
x2-gi.
x1)/(gi.
y2-gi.
y1))* 180. / M_PI) : 90;
1520 angle = (angle < 0)?(180+angle):angle;
1522 output += Glib::ustring::compose(
" draw:start-intensity=\"%1\" draw:end-intensity=\"%2\" draw:angle=\"%3\"/>\n",
1523 gi.
stops[0].opacity * 100.0, gi.
stops[1].opacity * 100.0, angle);
1525 else if (gi.
style ==
"radial")
1539 if (gi.
stops.size() < 2)
1541 g_warning(
"Need at least 2 stops for a radial gradient");
1544 output += Glib::ustring::compose(
"<draw:gradient draw:name=\"%1\" draw:display-name=\"%1\" ", gi.
name);
1545 snprintf(
buf, 127,
"draw:cx=\"%05.3f\" draw:cy=\"%05.3f\" ", gi.
cx*100, gi.
cy*100);
1546 output += Glib::ustring(
"draw:style=\"radial\" ") +
buf;
1547 snprintf(
buf, 127,
"draw:start-color=\"#%06lx\" draw:end-color=\"#%06lx\" ", gi.
stops[0].rgb, gi.
stops[1].rgb);
1549 snprintf(
buf, 127,
"draw:start-intensity=\"%f%%\" draw:end-intensity=\"%f%%\" ", gi.
stops[0].opacity*100.0, gi.
stops[1].opacity*100.0);
1555 g_warning(
"unsupported gradient style '%s'", gi.
style.c_str());
1576 if (!is<SPItem>(reprobj))
1580 auto item = cast<SPItem>(reprobj);
1582 Glib::ustring nodeName =
node->
name();
1590 double bbox_x = bbox->min()[
Geom::X];
1591 double bbox_y = bbox->min()[
Geom::Y];
1592 double bbox_width = (*bbox)[
Geom::X].extent();
1593 double bbox_height = (*bbox)[
Geom::Y].extent();
1604 if (nodeName ==
"svg" || nodeName ==
"svg:svg")
1617 else if (nodeName ==
"g" || nodeName ==
"svg:g")
1621 couts.
printf(
"<draw:g id=\"%s\">\n",
id.c_str());
1625 couts.
printf(
"<draw:g>\n");
1638 couts.
printf(
"</draw:g> <!-- id=\"%s\" -->\n",
id.c_str());
1642 couts.
printf(
"</draw:g>\n");
1648 Glib::ustring gradientNameFill;
1649 Glib::ustring gradientNameStroke;
1650 Glib::ustring outputFill;
1651 Glib::ustring outputStroke;
1652 Glib::ustring outputStyle;
1664 if (nodeName ==
"image" || nodeName ==
"svg:image")
1666 if (!is<SPImage>(
item))
1668 g_warning(
"<image> is not an SPImage.");
1672 auto img = cast<SPImage>(
item);
1673 double ix = img->x.value;
1674 double iy = img->y.value;
1675 double iwidth = img->width.value;
1676 double iheight = img->height.value;
1681 iwidth = xscale * iwidth;
1682 iheight = yscale * iheight;
1689 std::map<Glib::ustring, Glib::ustring>::iterator iter =
imageTable.find(href);
1692 g_warning(
"image '%s' not in table", href.c_str());
1695 Glib::ustring newName = iter->second;
1697 couts.
printf(
"<draw:frame ");
1700 couts.
printf(
"id=\"%s\" ",
id.c_str());
1702 couts.
printf(
"draw:style-name=\"gr1\" draw:text-style-name=\"P1\" draw:layer=\"layout\" ");
1704 couts.
printf(
"svg:width=\"%.3fcm\" svg:height=\"%.3fcm\" ",
1706 if (!itemTransformString.empty())
1708 couts.
printf(
"draw:transform=\"%s translate(%.3fcm, %.3fcm)\" ",
1709 itemTransformString.c_str(), ix, iy);
1713 couts.
printf(
"draw:transform=\"translate(%.3fcm, %.3fcm)\" ", ix, iy);
1717 couts.
printf(
" <draw:image xlink:href=\"%s\" xlink:type=\"simple\"\n",
1719 couts.
writeString(
" xlink:show=\"embed\" xlink:actuate=\"onLoad\">\n");
1726 auto process_curve = [&,
this] (
SPCurve const &
curve) {
1731 couts.
printf(
"id=\"%s\" ",
id.c_str());
1734 std::map<Glib::ustring, Glib::ustring>::iterator siter;
1738 Glib::ustring styleName = siter->second;
1739 couts.
printf(
"draw:style-name=\"%s\" ", styleName.c_str());
1742 couts.
printf(
"draw:layer=\"layout\" svg:x=\"%.3fcm\" svg:y=\"%.3fcm\" ",
1744 couts.
printf(
"svg:width=\"%.3fcm\" svg:height=\"%.3fcm\" ",
1745 bbox_width, bbox_height);
1746 couts.
printf(
"svg:viewBox=\"0.0 0.0 %.3f %.3f\"",
1747 bbox_width * 1000.0, bbox_height * 1000.0);
1749 couts.
printf(
" svg:d=\"");
1751 tf, bbox_x, bbox_y);
1755 couts.
printf(
" <!-- %d nodes -->\n", nrPoints);
1759 if (
auto shape = cast<SPShape>(
item)) {
1760 if (shape->curve()) {
1761 process_curve(*shape->curve());
1763 }
else if (is<SPText>(
item) || is<SPFlowtext>(
item)) {
1778 outs.
writeString(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1781 outs.
writeString(
"*************************************************************************\n");
1783 outs.
printf (
" Generated by Inkscape: %s", ctime(&tim));
1785 outs.
writeString(
"*************************************************************************\n");
1789 outs.
writeString(
" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n");
1790 outs.
writeString(
" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"\n");
1791 outs.
writeString(
" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"\n");
1792 outs.
writeString(
" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"\n");
1793 outs.
writeString(
" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"\n");
1794 outs.
writeString(
" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"\n");
1795 outs.
writeString(
" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n");
1796 outs.
writeString(
" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n");
1797 outs.
writeString(
" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n");
1798 outs.
writeString(
" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"\n");
1799 outs.
writeString(
" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n");
1800 outs.
writeString(
" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"\n");
1801 outs.
writeString(
" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"\n");
1802 outs.
writeString(
" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"\n");
1803 outs.
writeString(
" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n");
1804 outs.
writeString(
" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"\n");
1805 outs.
writeString(
" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"\n");
1806 outs.
writeString(
" xmlns:ooo=\"http://openoffice.org/2004/office\"\n");
1807 outs.
writeString(
" xmlns:ooow=\"http://openoffice.org/2004/writer\"\n");
1808 outs.
writeString(
" xmlns:oooc=\"http://openoffice.org/2004/calc\"\n");
1809 outs.
writeString(
" xmlns:dom=\"http://www.w3.org/2001/xml-events\"\n");
1810 outs.
writeString(
" xmlns:xforms=\"http://www.w3.org/2002/xforms\"\n");
1811 outs.
writeString(
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n");
1812 outs.
writeString(
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
1813 outs.
writeString(
" xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n");
1814 outs.
writeString(
" xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n");
1818 outs.
writeString(
"*************************************************************************\n");
1820 outs.
writeString(
" Style entries have been pulled from the svg style and\n");
1821 outs.
writeString(
" representation attributes in the SVG tree. The tree elements\n");
1822 outs.
writeString(
" then refer to them by name, in the ODF manner\n");
1823 outs.
writeString(
"*************************************************************************\n");
1842 outs.
writeString(
"<!-- ####### 'Standard' styles ####### -->\n");
1843 outs.
writeString(
"<style:style style:name=\"dp1\" style:family=\"drawing-page\"/>\n");
1844 outs.
writeString(
"<style:style style:name=\"standard\" style:family=\"graphic\">\n");
1849 outs.
writeString(
"<style:style style:name=\"gr1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n");
1850 outs.
writeString(
" <style:graphic-properties draw:stroke=\"none\" draw:fill=\"none\"\n");
1851 outs.
writeString(
" draw:textarea-horizontal-align=\"center\"\n");
1852 outs.
writeString(
" draw:textarea-vertical-align=\"middle\" draw:color-mode=\"standard\"\n");
1853 outs.
writeString(
" draw:luminance=\"0%\" draw:contrast=\"0%\" draw:gamma=\"100%\" draw:red=\"0%\"\n");
1854 outs.
writeString(
" draw:green=\"0%\" draw:blue=\"0%\" fo:clip=\"rect(0cm 0cm 0cm 0cm)\"\n");
1855 outs.
writeString(
" draw:image-opacity=\"100%\" style:mirror=\"none\"/>\n");
1857 outs.
writeString(
"<style:style style:name=\"P1\" style:family=\"paragraph\">\n");
1858 outs.
writeString(
" <style:paragraph-properties fo:text-align=\"center\"/>\n");
1864 outs.
writeString(
" <draw:layer draw:name=\"layout\"/>\n");
1865 outs.
writeString(
" <draw:layer draw:name=\"background\"/>\n");
1866 outs.
writeString(
" <draw:layer draw:name=\"backgroundobjects\"/>\n");
1867 outs.
writeString(
" <draw:layer draw:name=\"controls\"/>\n");
1868 outs.
writeString(
" <draw:layer draw:name=\"measurelines\"/>\n");
1871 outs.
writeString(
"<style:master-page style:name=\"Default\"\n");
1872 outs.
writeString(
" style:page-master-name=\"PM1\" draw:style-name=\"dp1\"/>\n");
1889 outs.
writeString(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1892 outs.
writeString(
"*************************************************************************\n");
1894 outs.
printf (
" Generated by Inkscape: %s", ctime(&tim));
1896 outs.
writeString(
"*************************************************************************\n");
1900 outs.
writeString(
" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n");
1901 outs.
writeString(
" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"\n");
1902 outs.
writeString(
" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"\n");
1903 outs.
writeString(
" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"\n");
1904 outs.
writeString(
" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"\n");
1905 outs.
writeString(
" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"\n");
1906 outs.
writeString(
" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n");
1907 outs.
writeString(
" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n");
1908 outs.
writeString(
" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n");
1909 outs.
writeString(
" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"\n");
1910 outs.
writeString(
" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n");
1911 outs.
writeString(
" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"\n");
1912 outs.
writeString(
" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"\n");
1913 outs.
writeString(
" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"\n");
1914 outs.
writeString(
" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n");
1915 outs.
writeString(
" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"\n");
1916 outs.
writeString(
" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"\n");
1917 outs.
writeString(
" xmlns:ooo=\"http://openoffice.org/2004/office\"\n");
1918 outs.
writeString(
" xmlns:ooow=\"http://openoffice.org/2004/writer\"\n");
1919 outs.
writeString(
" xmlns:oooc=\"http://openoffice.org/2004/calc\"\n");
1920 outs.
writeString(
" xmlns:dom=\"http://www.w3.org/2001/xml-events\"\n");
1921 outs.
writeString(
" xmlns:xforms=\"http://www.w3.org/2002/xforms\"\n");
1922 outs.
writeString(
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n");
1923 outs.
writeString(
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
1924 outs.
writeString(
" xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n");
1925 outs.
writeString(
" xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n");
1930 outs.
writeString(
"*************************************************************************\n");
1932 outs.
writeString(
" This section is the heart of SVG-ODF conversion. We are\n");
1933 outs.
writeString(
" starting with simple conversions, and will slowly evolve\n");
1934 outs.
writeString(
" into a 'smarter' translation as time progresses. Any help\n");
1935 outs.
writeString(
" in improving .odg export is welcome.\n");
1936 outs.
writeString(
"*************************************************************************\n");
1941 outs.
writeString(
"<draw:page draw:name=\"page1\" draw:style-name=\"dp1\"\n");
1942 outs.
writeString(
" draw:master-page-name=\"Default\">\n");
1957 outs.
writeString(
"<!-- ######### CONVERSION FROM SVG ENDS ######## -->\n");
1991 char *oldlocale = g_strdup (setlocale (LC_NUMERIC,
nullptr));
1992 setlocale (LC_NUMERIC,
"C");
1995 g_warning(
"Failed to convert SVG tree");
1996 setlocale (LC_NUMERIC, oldlocale);
2000 setlocale (LC_NUMERIC, oldlocale);
2019 ze = zf.
newEntry(
"styles.xml",
"ODF style file");
2055 g_warning(
"Failed to write manifest");
2061 g_warning(
"Failed to write content");
2067 g_warning(
"Failed to write metafile");
2087 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI
"\">\n"
2088 "<name>" N_(
"OpenDocument Drawing Output")
"</name>\n"
2089 "<id>org.inkscape.output.odf</id>\n"
2091 "<extension>.odg</extension>\n"
2092 "<mimetype>text/x-povray-script</mimetype>\n"
2093 "<filetypename>" N_(
"OpenDocument drawing (*.odg)")
"</filetypename>\n"
2094 "<filetypetooltip>" N_(
"OpenDocument drawing file")
"</filetypetooltip>\n"
2096 "</inkscape-extension>",
2097 std::make_unique<OdfOutput>());
3x3 affine transformation matrix.
Lookup dictionary for attributes/properties.
Phoebe DOM Implementation.
Hand-rolled LLVM-style RTTI system for class hierarchies where dynamic_cast isn't fast enough.
3x3 matrix representing an affine transformation.
bool isIdentity(Coord eps=EPSILON) const
Check whether this matrix is an identity matrix.
Affine inverse() const
Compute the inverse matrix.
Bezier curve with compile-time specified order.
Axis-aligned rectangle that can be empty.
Two-dimensional point that doubles as a vector.
constexpr Coord y() const noexcept
constexpr Coord x() const noexcept
The object that is the basis for the Extension system.
std::vector< GradientStop > stops
bool equals(const GradientInfo &other)
bool check(Inkscape::Extension::Extension *module) override
Make sure that we are in the database.
bool writeContentHeader(Writer &outs)
Write the header for the content.xml file.
std::map< Glib::ustring, Glib::ustring > styleLookupTable
std::map< Glib::ustring, Glib::ustring > imageTable
std::map< Glib::ustring, Glib::ustring > gradientLookupTable
void save(Inkscape::Extension::Output *mod, SPDocument *doc, char const *filename) override
Descends into the SVG tree, mapping things to ODF when appropriate.
void preprocess(ZipFile &zf, SPDocument *doc, Inkscape::XML::Node *node)
FIRST PASS.
bool writeContentFooter(Writer &outs)
Write the footer for the content.xml file.
bool processStyle(SPItem *item, const Glib::ustring &id, const Glib::ustring &gradientNameFill, const Glib::ustring &gradientNameStroke, Glib::ustring &output)
std::vector< GradientInfo > gradientTable
void reset()
Resets class to its pristine condition, ready to use again.
bool writeManifest(ZipFile &zf)
Writes the manifest.
bool writeTree(Writer &couts, Writer &souts, SPDocument *doc, Inkscape::XML::Node *node)
SECOND PASS.
std::vector< StyleInfo > styleTable
bool writeMeta(ZipFile &zf)
This writes the document meta information to meta.xml.
std::map< Glib::ustring, Glib::ustring > metadata
static void init()
This is the definition of PovRay output.
bool writeStyleHeader(Writer &outs)
Write the header for the content.xml file.
bool writeContent(ZipFile &zf, SPDocument *doc)
Write the content.xml file.
bool processGradient(SPItem *item, const Glib::ustring &id, Geom::Affine &tf, Glib::ustring &gradientName, Glib::ustring &output, bool checkFillGradient=true)
bool writeStyleFooter(Writer &outs)
Write the footer for the style.xml file.
bool equals(const StyleInfo &other)
Glib::ustring strokeColor
Glib::ustring fillOpacity
Glib::ustring strokeOpacity
Glib::ustring strokeWidth
Writer & printf(char const *fmt,...) override G_GNUC_PRINTF(2
Provide printf()-like formatting.
Writer & writeString(const char *str) override
Writes the specified character string to this output writer.
Writer & writeUString(const Glib::ustring &val) override
Writes the specified unicode string to this output writer.
This class is for sending a stream to a character buffer.
virtual std::vector< unsigned char > & getBuffer()
Class for placing a Writer on an open OutputStream.
void close() override
Close the underlying OutputStream.
This class is for sending a stream to a Glib::ustring.
virtual Glib::ustring & getString()
This interface and its descendants are for unicode character-oriented output.
virtual Writer & printf(char const *fmt,...) G_GNUC_PRINTF(2
virtual Writer & writeString(const char *str)=0
virtual Writer & writeUString(const Glib::ustring &val)=0
Represents an URI as per RFC 2396.
static URI from_dirname(char const *path)
URI of a local directory.
std::string str(char const *baseuri=nullptr) const
Return the string representation of this URI.
Interface for refcounted XML nodes.
virtual Node * next()=0
Get the next sibling of this node.
virtual char const * name() const =0
Get the name of the element node.
virtual Node * firstChild()=0
Get the first child of this node.
virtual char const * attribute(char const *key) const =0
Get the string representation of a node's attribute.
virtual char const * content() const =0
Get the content of a text or comment node.
virtual NodeType type() const =0
Get the type of the node.
Wrapper around a Geom::PathVector object.
Typed SVG document implementation.
SPRoot * getRoot()
Returns our SPRoot.
char const * getDocumentBase() const
Inkscape::XML::Node * getReprRoot()
SPObject * getObjectByRepr(Inkscape::XML::Node *repr) const
SPGradient * getVector(bool force_private=false)
Returns private vector of given gradient (the gradient at the end of the href chain which has stops),...
Base class for visual SVG elements.
Geom::OptRect documentVisualBounds() const
Get item's visual bbox in document coordinate system.
Geom::Affine i2doc_affine() const
Returns the accumulated transformation of the item and all its ancestors, including root's viewport.
SPObject is an abstract base class of all of the document nodes at the SVG document level.
SPStyle * style
Represents the style properties, whether from presentation attributes, the style attribute,...
SPStop * getNextStop()
Virtual write: write object attributes to repr.
T< SPAttr::FILL, SPIPaint > fill
fill
T< SPAttr::STROKE, SPIPaint > stroke
stroke
T< SPAttr::STROKE_WIDTH, SPILength > stroke_width
stroke-width
T< SPAttr::FILL_OPACITY, SPIScale24 > fill_opacity
fill-opacity
T< SPAttr::STROKE_OPACITY, SPIScale24 > stroke_opacity
stroke-opacity
virtual void setUncompressedData(const std::vector< unsigned char > &val)
This class sits over the zlib and gzip code to implement a PKWare or Info-Zip .zip file reader and wr...
virtual bool writeFile(const std::string &fileName)
virtual ZipEntry * newEntry(const std::string &fileNameArg, const std::string &commentArg)
A way to clear the N_ macro, which is defined as an inline function.
Integral and real coordinate types and some basic utilities.
Inkscape::Extension::Extension: Frontend to certain, possibly pluggable, actions.
Specific curve type functions for Inkscape, not provided by lib2geom.
bool is_straight_curve(Geom::BezierCurve const &c)
Geom::PathVector pathv_to_linear_and_cubic_beziers(Geom::PathVector const &pathv)
Specific geometry functions for Inkscape, not provided my lib2geom.
Inkscape::XML::Node * node
Mini static library that contains the version of Inkscape.
TODO: insert short description here.
void shift(T &a, T &b, T const &c)
SBasisN< n > sqrt(SBasisN< n > const &a, int k)
Inkscape::IO::OutputStreamWriter OutputStreamWriter
static void gatherText(Inkscape::XML::Node *node, Glib::ustring &buf)
static Glib::ustring formatTransform(Geom::Affine &tf)
static int writePath(Writer &outs, Geom::PathVector const &pathv, Geom::Affine const &tf, double xoff, double yoff)
Writes an SVG path as an ODF <draw:path> and returns the number of points written.
static double svd_hypot(double a, double b)
static void analyzeTransform(Geom::Affine &tf, double &rotate, double &, double &, double &xscale, double &yscale)
Get some fun facts from the transform.
static Geom::Affine getODFItemTransform(const SPItem *item)
Get the transform for an item, including parents, but without root viewBox transformation.
Inkscape::IO::StringOutputStream StringOutputStream
static Geom::Affine getODFTransform(const SPItem *item)
Get the general transform from SVG pixels to ODF cm.
static Glib::ustring getAttribute(Inkscape::XML::Node *node, char const *attrName)
Get the value of a node/attribute pair.
static Geom::OptRect getODFBoundingBox(const SPItem *item)
Get the bounding box of an item, as mapped onto an ODF document, in cm.
Inkscape::IO::BufferOutputStream BufferOutputStream
void build_from_mem(gchar const *buffer, std::unique_ptr< Implementation::Implementation > in_imp)
Create a module from a buffer holding an XML description.
Glib::ustring get_file_extension(Glib::ustring const &path)
@ TEXT_NODE
Text node, e.g. "Some text" in <group>Some text</group> is represented by a text node.
char const * version_string
full version string
OpenDocument (drawing) input and output.
PathVector - a sequence of subpaths.
Singleton class to access the preferences file in a convenient way.
TODO: insert short description here.
SVG <image> implementation.
Some things pertinent to all visible shapes: SPItem, SPItemView, SPItemCtx.
TODO: insert short description here.
double sum(const double alpha[16], const double &x, const double &y)
TODO: insert short description here.
SPRoot: SVG <svg> implementation.
TODO: insert short description here.
SPStyle internal: classes that are internal to SPStyle.
SPStyle - a style object for SPItem objects.
Inkscape::Text::Layout const * te_get_layout(SPItem const *item)
void init(int argc, char **argv, Toy *t, int width=600, int height=600)