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
stroke = styleStack.property( KoXmlNS::presentation, "stroke" );
}
KoLineBorder * border = 0;
if( stroke == "solid" )
{
border = new KoLineBorder();
}
else if( stroke == "dash" )
if( stroke == "solid" || stroke == "dash" )
{
border = new KoLineBorder();
if( styleStack.hasProperty( KoXmlNS::draw, "stroke-dash" ) )
{
QString dashStyleName = styleStack.property( KoXmlNS::draw, "stroke-dash" );
// TODO load dashes
}
}
else
return 0;
QPen pen = KoOasisStyles::loadOasisStrokeStyle( styleStack, stroke, context.koLoadingContext().oasisStyles() );
if ( styleStack.hasProperty( KoXmlNS::svg, "stroke-color" ) )
border->setColor( styleStack.property( KoXmlNS::svg, "stroke-color" ) );
if ( styleStack.hasProperty( KoXmlNS::svg, "stroke-opacity" ) )
{
QColor color = border->color();
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 );
}
KoLineBorder * border = new KoLineBorder();
border->setLineWidth( pen.width() );
border->setColor( pen.color() );
border->setJoinStyle( pen.joinStyle() );
border->setLineStyle( pen.style(), pen.dashPattern() );
return border;
return border;
}
else
return 0;
}
QMatrix KoShape::parseOdfTransform( const QString &transform )
......
......@@ -21,9 +21,11 @@
#include "KoDom.h"
#include "KoGenStyles.h"
#include "KoXmlNS.h"
#include "KoUnit.h"
#include <QBrush>
#include <QBuffer>
#include <QPen>
#include <kdebug.h>
#include <kglobal.h>
......@@ -1608,6 +1610,63 @@ QBrush KoOasisStyles::loadOasisFillStyle( const KoStyleStack &styleStack, const
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
{
return d->defaultStyles[family];
......
......@@ -151,6 +151,8 @@ public:
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:
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