From 17ff038eda24f39c002be1f5cab46f7729b561da Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Fri, 12 Apr 2013 23:27:16 +0200 Subject: odg export: some work on gradients (bzr r12276) --- src/extension/internal/odf.cpp | 87 +++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 53 deletions(-) (limited to 'src/extension/internal/odf.cpp') diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index 9fc6ecfdb..70798099d 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -1315,7 +1315,7 @@ 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(Writer &outs, SPItem *item, const Glib::ustring &id, const Glib::ustring &gradientNameFill, const Glib::ustring &gradientNameStroke) { if (!item) { @@ -1409,8 +1409,7 @@ bool OdfOutput::processStyle(Writer &outs, SPItem *item, const Glib::ustring &id styleLookupTable[id] = styleName; Glib::ustring tmpstring = Glib::ustring::compose ("\n", si.name); - // Glib::ustring tmpstring; - tmpstring += "cx.computed * 100.0;//ODG cx is percentages - gi.cy = radGrad->cy.computed * 100.0; + SPRadialGradient tmpGrad = *radGrad; + tmpGrad.cx.unit= SVGLength::PERCENT; + tmpGrad.cy.unit= SVGLength::PERCENT; + gi.cx = tmpGrad.cx.computed;// * 100.0;//ODG cx is percentages + gi.cy = tmpGrad.cy.computed;// * 100.0; } else { @@ -1511,7 +1516,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,7 +1529,6 @@ 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()); gi.name = gradientName; gradientTable.push_back(gi); @@ -1552,16 +1555,12 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item, return false; } output += Glib::ustring::compose("\n", - gi.stops[0].opacity * 100.0, gi.stops[1].opacity * 100.0); - // outs.writeUString (tmpstring); + output += Glib::ustring::compose(" draw:start-intensity=\"%1\" draw:end-intensity=\"%2\" draw:angle=\"0\"/>\n", + gi.stops[0].opacity * 100.0, gi.stops[1].opacity * 100.0);// draw:border=\"0%%\" } else if (gi.style == "radial") { @@ -1582,33 +1581,14 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item, g_warning("Need at least 2 stops for a radial gradient"); return false; } - /* - outs.printf("\n", - gi.r); - outs.printf(" \n"); - outs.printf(" \n"); - outs.printf("\n"); - */ + output += Glib::ustring::compose("second; couts.printf("draw:style-name=\"%s\" ", styleName.c_str()); } - // couts.writeUString(styleString); + // couts.writeUString(styleString); // std::map::iterator giter; // giter = gradientLookupTable.find(id); @@ -1821,10 +1802,10 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, 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 +1896,9 @@ bool OdfOutput::writeStyleFooter(Writer &outs) outs.writeString("\n"); outs.writeString("\n"); outs.writeString("\n"); - + ///TODO: add default document style here - + outs.writeString("\n"); outs.writeString("\n"); outs.writeString(" Date: Sat, 20 Apr 2013 20:26:11 +0200 Subject: minor odg export update (bzr r12285.1.1) --- src/extension/internal/odf.cpp | 69 ++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 37 deletions(-) (limited to 'src/extension/internal/odf.cpp') diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index 70798099d..b23378fc3 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -47,7 +47,7 @@ #include #include #include - +#include //# 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, const Glib::ustring &gradientNameStroke) +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,37 +1409,34 @@ bool OdfOutput::processStyle(Writer &outs, SPItem *item, const Glib::ustring &id styleTable.push_back(si); styleLookupTable[id] = styleName; - Glib::ustring tmpstring = Glib::ustring::compose ("\n", si.name); - tmpstring += "\n", si.name); + output += "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); - SPRadialGradient tmpGrad = *radGrad; - tmpGrad.cx.unit= SVGLength::PERCENT; - tmpGrad.cy.unit= SVGLength::PERCENT; - gi.cx = tmpGrad.cx.computed;// * 100.0;//ODG cx is percentages - gi.cy = tmpGrad.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 { @@ -1529,7 +1528,7 @@ bool OdfOutput::processGradient(SPItem *item, } // No match, let us write a new entry - gradientName = Glib::ustring::compose("gradient%1", gradientTable.size()); + gradientName = gradientName2; gi.name = gradientName; gradientTable.push_back(gi); gradientLookupTable[id] = gradientName; @@ -1555,12 +1554,17 @@ bool OdfOutput::processGradient(SPItem *item, return false; } output += Glib::ustring::compose("\n", - gi.stops[0].opacity * 100.0, gi.stops[1].opacity * 100.0);// draw:border=\"0%%\" + //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") { @@ -1581,8 +1585,8 @@ bool OdfOutput::processGradient(SPItem *item, g_warning("Need at least 2 stops for a radial gradient"); return false; } - output += Glib::ustring::compose("second; couts.printf("draw:style-name=\"%s\" ", styleName.c_str()); } - // couts.writeUString(styleString); - - // std::map::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); -- cgit v1.2.3