summaryrefslogtreecommitdiffstats
path: root/src/extension/internal
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-04-20 21:21:33 +0000
committerMarkus Engel <markus.engel@tum.de>2013-04-20 21:21:33 +0000
commit39580f4b417374ccba9d504f028388b2a2932506 (patch)
treea4337231a1b27403dceb49810ea618297ed0b659 /src/extension/internal
parentMerging of EventContext classes complete. (diff)
parentGroup bbox update (Bug 1168979) (diff)
downloadinkscape-39580f4b417374ccba9d504f028388b2a2932506.tar.gz
inkscape-39580f4b417374ccba9d504f028388b2a2932506.zip
merged from trunk (r12287)
(bzr r11608.1.99)
Diffstat (limited to 'src/extension/internal')
-rw-r--r--src/extension/internal/odf.cpp120
-rw-r--r--src/extension/internal/odf.h4
2 files changed, 50 insertions, 74 deletions
diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp
index 9fc6ecfdb..b23378fc3 100644
--- a/src/extension/internal/odf.cpp
+++ b/src/extension/internal/odf.cpp
@@ -47,7 +47,7 @@
#include <stdio.h>
#include <time.h>
#include <vector>
-
+#include <math.h>
//# Inkscape includes
#include "clear-n_.h"
@@ -1315,8 +1315,9 @@ writePath(Writer &outs, Geom::PathVector const &pathv,
return nrPoints;
}
-bool OdfOutput::processStyle(Writer &outs, SPItem *item, const Glib::ustring &id, const Glib::ustring &gradientNameFill)//, Glib::ustring &styleString)
+bool OdfOutput::processStyle(SPItem *item, const Glib::ustring &id, const Glib::ustring &gradientNameFill, const Glib::ustring &gradientNameStroke, Glib::ustring& output)
{
+ output.clear();
if (!item)
{
return false;
@@ -1408,40 +1409,39 @@ bool OdfOutput::processStyle(Writer &outs, SPItem *item, const Glib::ustring &id
styleTable.push_back(si);
styleLookupTable[id] = styleName;
- Glib::ustring tmpstring = Glib::ustring::compose ("<style:style style:name=\"%1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n", si.name);
- // Glib::ustring tmpstring;
- tmpstring += "<style:graphic-properties ";
+ output = Glib::ustring::compose ("<style:style style:name=\"%1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n", si.name);
+ output += "<style:graphic-properties";
if (si.fill == "gradient")
{
- tmpstring += Glib::ustring::compose (" draw:fill=\"gradient\" draw:fill-gradient-name=\"%1\"", gradientNameFill);
+ output += Glib::ustring::compose (" draw:fill=\"gradient\" draw:fill-gradient-name=\"%1\"", gradientNameFill);
}
else
{
- tmpstring += Glib::ustring(" draw:fill=\"") + si.fill + "\"";
+ output += Glib::ustring(" draw:fill=\"") + si.fill + "\"";
if(si.fill != "none")
{
- tmpstring += Glib::ustring::compose(" draw:fill-color=\"%1\" draw:fill-opacity=\"%2\"", si.fillColor, si.fillOpacity);
+ output += Glib::ustring::compose(" draw:fill-color=\"%1\"", si.fillColor);
}
}
if (si.stroke == "gradient")
{
- tmpstring += Glib::ustring (" draw:stroke=\"gradient\" draw:stroke-gradient-name=\"NotYetProgrammedPleaseBePatient\"");
+ //does not seem to be supported by Open Office.org
+ output += Glib::ustring::compose (" draw:stroke=\"gradient\" draw:stroke-gradient-name=\"%1\"", gradientNameStroke);
}
else
{
- tmpstring += Glib::ustring(" draw:stroke=\"") + si.stroke + "\"";
+ output += Glib::ustring(" draw:stroke=\"") + si.stroke + "\"";
if (si.stroke != "none")
{
- tmpstring += Glib::ustring::compose (" svg:stroke-width=\"%1\" svg:stroke-color=\"%2\" svg:stroke-opacity=\"%3\" ", si.strokeWidth, si.strokeColor, si.strokeOpacity);
+ output += Glib::ustring::compose (" svg:stroke-width=\"%1\" svg:stroke-color=\"%2\" ", si.strokeWidth, si.strokeColor);
}
}
- tmpstring += "/>\n</style:style>\n";
- outs.writeUString (tmpstring);
+ output += "/>\n</style:style>\n";
return true;
}
-bool OdfOutput::processGradient(Writer &outs, SPItem *item,
+bool OdfOutput::processGradient(SPItem *item,
const Glib::ustring &id, Geom::Affine &/*tf*/,
Glib::ustring& gradientName, Glib::ustring& output, bool checkFillGradient)
{
@@ -1481,6 +1481,7 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item,
gi.stops.push_back(gs);
}
+ Glib::ustring gradientName2;
if (SP_IS_LINEARGRADIENT(gradient))
{
gi.style = "linear";
@@ -1489,13 +1490,16 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item,
gi.y1 = linGrad->y1.value;
gi.x2 = linGrad->x2.value;
gi.y2 = linGrad->y2.value;
+ gradientName2 = Glib::ustring::compose("ImportedLinearGradient%1", gradientTable.size());
}
else if (SP_IS_RADIALGRADIENT(gradient))
{
gi.style = "radial";
SPRadialGradient *radGrad = SP_RADIALGRADIENT(gradient);
- gi.cx = radGrad->cx.computed * 100.0;//ODG cx is percentages
- gi.cy = radGrad->cy.computed * 100.0;
+ Geom::OptRect bbox = item->documentVisualBounds();
+ gi.cx = (radGrad->cx.value-bbox->left())/bbox->width();
+ gi.cy = (radGrad->cy.value-bbox->top())/bbox->height();
+ gradientName2 = Glib::ustring::compose("ImportedRadialGradient%1", gradientTable.size());
}
else
{
@@ -1511,7 +1515,6 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item,
if (gi.equals(*iter))
{
//map to existing gradientTable entry
- // Glib::ustring gradientName = iter->name;
gradientName = iter->name;
gradientLookupTable[id] = gradientName;
gradientMatch = true;
@@ -1525,8 +1528,7 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item,
}
// No match, let us write a new entry
- // Glib::ustring gradientName = Glib::ustring::compose("gradient%1", gradientTable.size());
- gradientName = Glib::ustring::compose("gradient%1", gradientTable.size());
+ gradientName = gradientName2;
gi.name = gradientName;
gradientTable.push_back(gi);
gradientLookupTable[id] = gradientName;
@@ -1552,16 +1554,17 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item,
return false;
}
output += Glib::ustring::compose("<draw:gradient draw:name=\"%1\"", gi.name);
- // "<draw:gradient id=\"%1\" draw:name=\"%2\"\n", gi.name, gi.name);
- output += Glib::ustring::compose(" draw:display-name=\"imported linear %1\"", gradientCount);
+ output += Glib::ustring::compose(" draw:display-name=\"%1\"", gi.name);
output += " draw:style=\"linear\"";
- // outs.writeUString (tmpstring);
- // outs.printf(" draw:start-color=\"#%06lx\" draw:end-color=\"#%06lx\"\n", gi.stops[0].rgb, gi.stops[1].rgb);
snprintf(buf, 127, " draw:start-color=\"#%06lx\" draw:end-color=\"#%06lx\"", gi.stops[0].rgb, gi.stops[1].rgb);
output += buf;
- output += Glib::ustring::compose(" draw:start-intensity=\"%1\" draw:end-intensity=\"%2\" draw:angle=\"0\" draw:border=\"0%%\"/>\n",
- gi.stops[0].opacity * 100.0, gi.stops[1].opacity * 100.0);
- // outs.writeUString (tmpstring);
+ //TODO: apply maths, to define begin of gradient, taking gradient begin and end, as well as object boundary into account
+ double angle = (gi.y2-gi.y1);
+ angle = (angle != 0.) ? (atan((gi.x2-gi.x1)/(gi.y2-gi.y1))* 180. / pi) : 90;
+ angle = (angle < 0)?(180+angle):angle;
+ angle = angle * 10; //why do we need this: precision?????????????
+ output += Glib::ustring::compose(" draw:start-intensity=\"%1\" draw:end-intensity=\"%2\" draw:angle=\"%3\"/>\n",
+ gi.stops[0].opacity * 100.0, gi.stops[1].opacity * 100.0, angle);// draw:border=\"0%%\"
}
else if (gi.style == "radial")
{
@@ -1582,33 +1585,14 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item,
g_warning("Need at least 2 stops for a radial gradient");
return false;
}
- /*
- outs.printf("<svg:radialGradient ");
- outs.printf("id=\"%s\" ", gi.name.c_str());
- outs.printf("draw:name=\"%s\"\n", gi.name.c_str());
- outs.printf(" draw:display-name=\"imported radial %d\"\n",
- gradientCount);
- outs.printf(" svg:gradientUnits=\"objectBoundingBox\"\n");
- outs.printf(" svg:cx=\"%05.3f\" svg:cy=\"%05.3f\"\n",
- gi.cx, gi.cy);
- outs.printf(" svg:fx=\"%05.3f\" svg:fy=\"%05.3f\"\n",
- gi.fx, gi.fy);
- outs.printf(" svg:r=\"%05.3f\">\n",
- gi.r);
- outs.printf(" <svg:stop\n");
- outs.printf(" svg:stop-color=\"#%06lx\"\n",
- gi.stops[0].rgb);
- outs.printf(" svg:stop-opacity=\"%f%%\"\n",
- gi.stops[0].opacity * 100.0);
- outs.printf(" svg:offset=\"0\"/>\n");
- outs.printf(" <svg:stop\n");
- outs.printf(" svg:stop-color=\"#%06lx\"\n",
- gi.stops[1].rgb);
- outs.printf(" svg:stop-opacity=\"%f%%\"\n",
- gi.stops[1].opacity * 100.0);
- outs.printf(" svg:offset=\"1\"/>\n");
- outs.printf("</svg:radialGradient>\n");
- */
+ output += Glib::ustring::compose("<draw:gradient draw:name=\"%1\" draw:display-name=\"%1\" ", gi.name);
+ snprintf(buf, 127, "draw:cx=\"%05.3f\" draw:cy=\"%05.3f\" ", gi.cx*100, gi.cy*100);
+ output += Glib::ustring("draw:style=\"radial\" ") + buf;
+ snprintf(buf, 127, "draw:start-color=\"#%06lx\" draw:end-color=\"#%06lx\" ", gi.stops[0].rgb, gi.stops[1].rgb);
+ output += buf;
+ snprintf(buf, 127, "draw:start-intensity=\"%f%%\" draw:end-intensity=\"%f%%\" ", gi.stops[0].opacity*100.0, gi.stops[1].opacity*100.0);
+ output += buf;
+ output += "/>\n";//draw:border=\"0%\"
}
else
{
@@ -1709,14 +1693,16 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts,
Glib::ustring gradientNameStroke;
Glib::ustring outputFill;
Glib::ustring outputStroke;
- // Glib::ustring styleString;
-
- processGradient(souts, item, id, tf, gradientNameFill, outputFill, 1);
+ Glib::ustring outputStyle;
+
+ processGradient(item, id, tf, gradientNameFill, outputFill, 1);
+ processGradient(item, id, tf, gradientNameStroke, outputStroke, 0);
souts.writeUString(outputFill);
+ souts.writeUString(outputStroke);
//# STYLE
- processStyle(souts, item, id, gradientNameFill);//, styleString);
-
+ processStyle(item, id, gradientNameFill, gradientNameStroke, outputStyle);
+ souts.writeUString(outputStyle);
//# ITEM DATA
if (nodeName == "image" || nodeName == "svg:image")
@@ -1806,25 +1792,15 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts,
Glib::ustring styleName = siter->second;
couts.printf("draw:style-name=\"%s\" ", styleName.c_str());
}
- // couts.writeUString(styleString);
-
- // std::map<Glib::ustring, Glib::ustring>::iterator giter;
- // giter = gradientLookupTable.find(id);
- // if (giter != gradientLookupTable.end())
- // {
- // Glib::ustring gradientName = giter->second;
- // couts.printf("draw:fill-gradient-name=\"%s\" ",
- // gradientName.c_str());
- // }
couts.printf("draw:layer=\"layout\" svg:x=\"%.3fcm\" svg:y=\"%.3fcm\" ",
bbox_x, bbox_y);
couts.printf("svg:width=\"%.3fcm\" svg:height=\"%.3fcm\" ",
bbox_width, bbox_height);
- couts.printf("svg:viewBox=\"0.0 0.0 %.3f %.3f\"\n",
+ couts.printf("svg:viewBox=\"0.0 0.0 %.3f %.3f\"",
bbox_width * 1000.0, bbox_height * 1000.0);
- couts.printf(" svg:d=\"");
+ couts.printf(" svg:d=\"");
int nrPoints = writePath(couts, curve->get_pathvector(),
tf, bbox_x, bbox_y);
couts.writeString("\"");
@@ -1915,9 +1891,9 @@ bool OdfOutput::writeStyleFooter(Writer &outs)
outs.writeString("<!-- ####### 'Standard' styles ####### -->\n");
outs.writeString("<style:style style:name=\"dp1\" style:family=\"drawing-page\"/>\n");
outs.writeString("<style:style style:name=\"standard\" style:family=\"graphic\">\n");
-
+
///TODO: add default document style here
-
+
outs.writeString("</style:style>\n");
outs.writeString("<style:style style:name=\"gr1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n");
outs.writeString(" <style:graphic-properties draw:stroke=\"none\" draw:fill=\"none\"\n");
diff --git a/src/extension/internal/odf.h b/src/extension/internal/odf.h
index 5fcad2630..6b915e347 100644
--- a/src/extension/internal/odf.h
+++ b/src/extension/internal/odf.h
@@ -313,9 +313,9 @@ private:
bool writeStyle(ZipFile &zf);
- bool processStyle(Writer &outs, SPItem *item, const Glib::ustring &id, const Glib::ustring &gradientNameFill);//, Glib::ustring &styleString);
+ bool processStyle(SPItem *item, const Glib::ustring &id, const Glib::ustring &gradientNameFill, const Glib::ustring &gradientNameStroke, Glib::ustring& output);
- bool processGradient(Writer &outs, SPItem *item,
+ bool processGradient(SPItem *item,
const Glib::ustring &id, Geom::Affine &tf, Glib::ustring& gradientName, Glib::ustring& output, bool checkFillGradient = 1);
bool writeStyleHeader(Writer &outs);