Commit 29724e7a authored by Jan Hambrecht's avatar Jan Hambrecht

implemented pattern fill style loading


svn path=/trunk/koffice/; revision=692028
parent ec065b78
......@@ -729,6 +729,8 @@ QBrush KoShape::loadOdfFill( const KoXmlElement & element, KoShapeLoadingContext
return KoOasisStyles::loadOasisFillStyle( styleStack, fill, context.koLoadingContext().oasisStyles() );
else if( fill == "gradient" )
return KoOasisStyles::loadOasisGradientStyle( styleStack, context.koLoadingContext().oasisStyles(), size() );
else if( fill == "bitmap" )
return KoOasisStyles::loadOasisPatternStyle( styleStack, context.koLoadingContext() );
return QBrush();
}
......
/* This file is part of the KDE project
Copyright (C) 2004-2006 David Faure <faure@kde.org>
Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -22,6 +23,8 @@
#include "KoGenStyles.h"
#include "KoXmlNS.h"
#include "KoUnit.h"
#include "KoPictureShared.h"
#include "KoOasisLoadingContext.h"
#include <QBrush>
#include <QBuffer>
......@@ -34,6 +37,8 @@
#include <KoStyleStack.h>
#include <KoXmlReader.h>
#include <KoXmlWriter.h>
#include <KoStore.h>
#include <KoStoreDevice.h>
#include <math.h>
......@@ -1791,6 +1796,64 @@ QBrush KoOasisStyles::loadOasisFillStyle( const KoStyleStack &styleStack, const
return tmpBrush;
}
QBrush KoOasisStyles::loadOasisPatternStyle( const KoStyleStack &styleStack, KoOasisLoadingContext & context )
{
QString styleName = styleStack.property( KoXmlNS::draw, "fill-image-name" );
KoXmlElement* e = context.oasisStyles().drawStyles()[styleName];
if( ! e )
return QBrush();
const QString href = e->attributeNS( KoXmlNS::xlink, "href", QString() );
if( href.isEmpty() )
return QBrush();
QString strExtension;
const int result=href.lastIndexOf(".");
if (result>=0)
{
strExtension=href.mid(result+1); // As we are using KoPicture, the extension should be without the dot.
}
QString filename(href);
KoPictureShared picture;
KoStore* store = context.store();
if ( store->open( filename ) )
{
KoStoreDevice dev(store);
if ( ! picture.load( &dev, strExtension ) )
kWarning() << "Cannot load picture: " << filename << " " << href << endl;
store->close();
}
QSize imageSize = picture.getOriginalSize();
// optional attributes which can override original image size
if( e->hasAttributeNS( KoXmlNS::draw, "fill-image-height" ) && e->hasAttributeNS( KoXmlNS::draw, "fill-image-width" ) )
{
QString height = e->attributeNS( KoXmlNS::draw, "fill-image-height", QString() );
double newHeight = 0.0;
if( height.endsWith( '%' ) )
newHeight = 0.01 * height.remove( "%" ).toDouble() * imageSize.height();
else
newHeight = KoUnit::parseValue( height );
QString width = e->attributeNS( KoXmlNS::draw, "fill-image-width", QString() );
double newWidth = 0.0;
if( width.endsWith( '%' ) )
newWidth = 0.01 * width.remove( "%" ).toDouble() * imageSize.width();
else
newWidth = KoUnit::parseValue( width );
if( newHeight > 0.0 )
imageSize.setHeight( static_cast<int>( newHeight ) );
if( newWidth > 0.0 )
imageSize.setWidth( static_cast<int>( newWidth ) );
}
QBrush resultBrush( picture.generatePixmap( imageSize ) );
return resultBrush;
}
QPen KoOasisStyles::loadOasisStrokeStyle( const KoStyleStack &styleStack, const QString & stroke, const KoOasisStyles & oasisStyles )
{
QPen tmpPen;
......
/* This file is part of the KDE project
Copyright (C) 2004-2006 David Faure <faure@kde.org>
Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -30,6 +31,7 @@ class KoXmlWriter;
class QBrush;
class KoGenStyle;
class KoStyleStack;
class KoOasisLoadingContext;
/**
* Repository of styles used during loading of OASIS/OOo file
......@@ -154,6 +156,9 @@ public:
/// Loads gradient style from style stack and oasisStyles adapted to the given size and returns a brush
static QBrush loadOasisGradientStyle( const KoStyleStack &styleStack, const KoOasisStyles & oasisStyles, const QSizeF &size );
/// Loads pattern style from style stack and oasisstyle
static QBrush loadOasisPatternStyle( const KoStyleStack &styleStack, KoOasisLoadingContext & context );
static QBrush loadOasisFillStyle( const KoStyleStack &styleStack, const QString & fill, const KoOasisStyles & oasisStyles );
static QPen loadOasisStrokeStyle( const KoStyleStack &styleStack, const QString & stroke, const KoOasisStyles & oasisStyles );
......
......@@ -24,6 +24,7 @@
#include <QPainter>
//Added by qt3to4:
#include <QPixmap>
#include <Q3DragObject>
#include <kdebug.h>
#include <kurl.h>
......
......@@ -30,7 +30,7 @@
class KoXmlWriter;
class QPainter;
class QSize;
class Q3DragObject;
class KoPictureBase;
......
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