Commit c887ad50 authored by Jan Hambrecht's avatar Jan Hambrecht

implemneted loading of stroke dashes and moved loading code into KoOasisStyles


svn path=/trunk/koffice/; revision=689640
parent b67fbd6b
...@@ -731,47 +731,20 @@ KoShapeBorderModel * KoShape::loadOdfStroke( const KoXmlElement & element, KoSha ...@@ -731,47 +731,20 @@ KoShapeBorderModel * KoShape::loadOdfStroke( const KoXmlElement & element, KoSha
stroke = styleStack.property( KoXmlNS::presentation, "stroke" ); stroke = styleStack.property( KoXmlNS::presentation, "stroke" );
} }
KoLineBorder * border = 0; if( stroke == "solid" || stroke == "dash" )
if( stroke == "solid" )
{
border = new KoLineBorder();
}
else if( stroke == "dash" )
{ {
border = new KoLineBorder(); QPen pen = KoOasisStyles::loadOasisStrokeStyle( styleStack, stroke, context.koLoadingContext().oasisStyles() );
if( styleStack.hasProperty( KoXmlNS::draw, "stroke-dash" ) )
{
QString dashStyleName = styleStack.property( KoXmlNS::draw, "stroke-dash" );
// TODO load dashes
}
}
else
return 0;
if ( styleStack.hasProperty( KoXmlNS::svg, "stroke-color" ) ) KoLineBorder * border = new KoLineBorder();
border->setColor( styleStack.property( KoXmlNS::svg, "stroke-color" ) ); border->setLineWidth( pen.width() );
if ( styleStack.hasProperty( KoXmlNS::svg, "stroke-opacity" ) ) border->setColor( pen.color() );
{ border->setJoinStyle( pen.joinStyle() );
QColor color = border->color(); border->setLineStyle( pen.style(), pen.dashPattern() );
QString opacity = styleStack.property( KoXmlNS::svg, "stroke-opacity" );
color.setAlphaF( opacity.toDouble() );
border->setColor( color );
}
if( styleStack.hasProperty( KoXmlNS::svg, "stroke-width" ) )
border->setLineWidth( KoUnit::parseValue( styleStack.property( KoXmlNS::svg, "stroke-width" ) ) );
if( styleStack.hasProperty( KoXmlNS::draw, "stroke-linejoin" ) )
{
QString join = styleStack.property( KoXmlNS::draw, "stroke-linejoin" );
if( join == "bevel" )
border->setJoinStyle( Qt::BevelJoin );
else if( join == "round" )
border->setJoinStyle( Qt::RoundJoin );
else
border->setJoinStyle( Qt::MiterJoin );
}
return border; return border;
}
else
return 0;
} }
QMatrix KoShape::parseOdfTransform( const QString &transform ) QMatrix KoShape::parseOdfTransform( const QString &transform )
......
...@@ -21,9 +21,11 @@ ...@@ -21,9 +21,11 @@
#include "KoDom.h" #include "KoDom.h"
#include "KoGenStyles.h" #include "KoGenStyles.h"
#include "KoXmlNS.h" #include "KoXmlNS.h"
#include "KoUnit.h"
#include <QBrush> #include <QBrush>
#include <QBuffer> #include <QBuffer>
#include <QPen>
#include <kdebug.h> #include <kdebug.h>
#include <kglobal.h> #include <kglobal.h>
...@@ -1608,6 +1610,63 @@ QBrush KoOasisStyles::loadOasisFillStyle( const KoStyleStack &styleStack, const ...@@ -1608,6 +1610,63 @@ QBrush KoOasisStyles::loadOasisFillStyle( const KoStyleStack &styleStack, const
return tmpBrush; return tmpBrush;
} }
QPen KoOasisStyles::loadOasisStrokeStyle( const KoStyleStack &styleStack, const QString & stroke, const KoOasisStyles & oasisStyles )
{
QPen tmpPen;
if( stroke == "solid" || stroke == "dash" )
{
if ( styleStack.hasProperty( KoXmlNS::svg, "stroke-color" ) )
tmpPen.setColor( styleStack.property( KoXmlNS::svg, "stroke-color" ) );
if ( styleStack.hasProperty( KoXmlNS::svg, "stroke-opacity" ) )
{
QColor color = tmpPen.color();
QString opacity = styleStack.property( KoXmlNS::svg, "stroke-opacity" );
color.setAlphaF( opacity.toDouble() );
tmpPen.setColor( color );
}
if( styleStack.hasProperty( KoXmlNS::svg, "stroke-width" ) )
tmpPen.setWidthF( KoUnit::parseValue( styleStack.property( KoXmlNS::svg, "stroke-width" ) ) );
if( styleStack.hasProperty( KoXmlNS::draw, "stroke-linejoin" ) )
{
QString join = styleStack.property( KoXmlNS::draw, "stroke-linejoin" );
if( join == "bevel" )
tmpPen.setJoinStyle( Qt::BevelJoin );
else if( join == "round" )
tmpPen.setJoinStyle( Qt::RoundJoin );
else
tmpPen.setJoinStyle( Qt::MiterJoin );
}
if( stroke == "dash" && styleStack.hasProperty( KoXmlNS::draw, "stroke-dash" ) )
{
QString dashStyleName = styleStack.property( KoXmlNS::draw, "stroke-dash" );
KoXmlElement * dashElement = oasisStyles.drawStyles()[ dashStyleName ];
if( dashElement )
{
QVector<qreal> dashes;
if( dashElement->hasAttributeNS( KoXmlNS::draw, "dots1" ) )
{
double dotLength = KoUnit::parseValue( dashElement->attributeNS( KoXmlNS::draw, "dots1-length", QString() ) );
dashes.append( dotLength / tmpPen.width() );
double dotDistance = KoUnit::parseValue( dashElement->attributeNS( KoXmlNS::draw, "distance", QString() ) );
dashes.append( dotDistance / tmpPen.width() );
if( dashElement->hasAttributeNS( KoXmlNS::draw, "dots2" ) )
{
dotLength = KoUnit::parseValue( dashElement->attributeNS( KoXmlNS::draw, "dots2-length", QString() ) );
dashes.append( dotLength / tmpPen.width() );
dashes.append( dotDistance / tmpPen.width() );
}
tmpPen.setDashPattern( dashes );
}
}
}
}
return tmpPen;
}
const KoXmlElement* KoOasisStyles::defaultStyle( const QString& family ) const const KoXmlElement* KoOasisStyles::defaultStyle( const QString& family ) const
{ {
return d->defaultStyles[family]; return d->defaultStyles[family];
......
...@@ -151,6 +151,8 @@ public: ...@@ -151,6 +151,8 @@ public:
static QBrush loadOasisFillStyle( const KoStyleStack &styleStack, const QString & fill, const KoOasisStyles & oasisStyles ); static QBrush loadOasisFillStyle( const KoStyleStack &styleStack, const QString & fill, const KoOasisStyles & oasisStyles );
static QPen loadOasisStrokeStyle( const KoStyleStack &styleStack, const QString & stroke, const KoOasisStyles & oasisStyles );
private: private:
enum TypeAndLocation enum TypeAndLocation
{ {
......
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