Commit 9b9aa0df authored by Jan Hambrecht's avatar Jan Hambrecht

add support for saving and loading conical gradients to odf using koffice namespace

BUG:187454


svn path=/trunk/koffice/; revision=941149
parent f109d8f0
......@@ -209,6 +209,12 @@ QString KoOdfGraphicStyles::saveOasisGradientStyle(KoGenStyles &mainStyles, cons
gradientStyle.addAttributePt("svg:y1", gradient->start().y());
gradientStyle.addAttributePt("svg:x2", gradient->finalStop().x());
gradientStyle.addAttributePt("svg:y2", gradient->finalStop().y());
} else if (brush.style() == Qt::ConicalGradientPattern) {
const QConicalGradient * gradient = static_cast<const QConicalGradient*>(brush.gradient());
gradientStyle = KoGenStyle(KoGenStyle::StyleGradientConical /*no family name*/);
gradientStyle.addAttributePt("svg:cx", gradient->center().x());
gradientStyle.addAttributePt("svg:cy", gradient->center().y());
gradientStyle.addAttribute("draw:angle", QString("%1").arg(gradient->angle()));
}
const QGradient * gradient = brush.gradient();
if (gradient->spread() == QGradient::RepeatSpread)
......@@ -372,8 +378,44 @@ QBrush KoOdfGraphicStyles::loadOasisGradientStyle(const KoStyleStack &styleStack
stops.append(stop);
}
}
// TODO should the stops be sorted?
gradient->setStops(stops);
} else if (e->namespaceURI() == KoXmlNS::koffice) {
if (e->localName() == "conicalGradient") {
QPointF center;
center.setX(KoUnit::parseValue(e->attributeNS(KoXmlNS::svg, "cx", QString())));
center.setY(KoUnit::parseValue(e->attributeNS(KoXmlNS::svg, "cy", QString())));
qreal angle = KoUnit::parseValue(e->attributeNS(KoXmlNS::draw, "angle", QString()));
QConicalGradient * g = new QConicalGradient();
g->setCenter(center);
g->setAngle(angle);
gradient = g;
QString strSpread(e->attributeNS(KoXmlNS::svg, "spreadMethod", "pad"));
if (strSpread == "repeat")
gradient->setSpread(QGradient::RepeatSpread);
else if (strSpread == "reflect")
gradient->setSpread(QGradient::ReflectSpread);
else
gradient->setSpread(QGradient::PadSpread);
if (e->hasAttributeNS(KoXmlNS::svg, "gradientTransform"))
matrix = loadTransformation(e->attributeNS(KoXmlNS::svg, "gradientTransform", QString()));
QGradientStops stops;
// load stops
KoXmlElement colorstop;
forEachElement(colorstop, (*e)) {
if (colorstop.namespaceURI() == KoXmlNS::svg && colorstop.localName() == "stop") {
QGradientStop stop;
stop.second = QColor(colorstop.attributeNS(KoXmlNS::svg, "stop-color", QString()));
stop.second.setAlphaF(colorstop.attributeNS(KoXmlNS::svg, "stop-opacity", "1.0").toDouble());
stop.first = colorstop.attributeNS(KoXmlNS::svg, "offset", "0.0").toDouble();
stops.append(stop);
}
}
gradient->setStops(stops);
}
}
if (! gradient)
......
......@@ -66,7 +66,8 @@ public:
StyleStrokeDash, ///< draw:stroke-dash as in odf 14.14.7 Stroke Dash (office:styles)
StyleGradient, ///< draw:gradient as in odf 14.14.1 Gradient (office:styles)
StyleGradientLinear, ///< svg:linearGradient as in odf 14.14.2 SVG Gradients (office:styles)
StyleGradientRadial, ///< svg-radialGradient as in odf 14.14.2 SVG Gradients (office:styles)
StyleGradientRadial, ///< svg:radialGradient as in odf 14.14.2 SVG Gradients (office:styles)
StyleGradientConical, ///< koffice:conicalGradient koffice extension for conical gradients
StyleFillImage, ///< draw:fill-image as in odf 14.14.4 Fill Image (office:styles)
StyleDrawingPage, ///< style:drawing-page-properties as in odf 14.13.2 Drawing Page Style
StyleNumericBoolean, ///< number:boolean 14.7.6 Boolean Style not used
......
......@@ -41,6 +41,7 @@ static const struct {
{ KoGenStyle::StyleList, "text:list-style", 0, false },
{ KoGenStyle::StyleGradientLinear, "svg:linearGradient", 0, true },
{ KoGenStyle::StyleGradientRadial, "svg:radialGradient", 0, true },
{ KoGenStyle::StyleGradientConical, "koffice:conicalGradient", 0, true },
{ KoGenStyle::StyleStrokeDash, "draw:stroke-dash", 0, true },
{ KoGenStyle::StyleFillImage, "draw:fill-image", 0, true },
{ KoGenStyle::StyleHatch, "draw:hatch", "style:graphic-properties", true },
......
......@@ -160,6 +160,8 @@ void KoOdfStylesReader::insertOfficeStyles(const KoXmlElement& styles)
|| localName == "marker"
|| localName == "stroke-dash"
|| localName == "opacity"))
|| (ns == KoXmlNS::koffice && (
localName == "conicalGradient"))
) {
const QString name = e.attributeNS(KoXmlNS::draw, "name", QString());
Q_ASSERT(!name.isEmpty());
......@@ -170,7 +172,6 @@ void KoOdfStylesReader::insertOfficeStyles(const KoXmlElement& styles)
}
}
void KoOdfStylesReader::insertStyles(const KoXmlElement& styles, TypeAndLocation typeAndLocation)
{
//kDebug(30003) <<"Inserting styles from" << styles.tagName();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment