[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/filters
From: Jan Hambrecht <jaham () gmx ! net>
Date: 2008-07-25 23:36:46
Message-ID: 1217029006.043467.8796.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 837898 by jaham:
implement text support for wmf import filter
M +47 -4 karbon/wmf/wmfimportparser.cc
M +1 -0 karbon/wmf/wmfimportparser.h
M +40 -7 libkowmf/kowmfreadprivate.cc
--- trunk/koffice/filters/karbon/wmf/wmfimportparser.cc #837897:837898
@@ -33,7 +33,7 @@
#include <pathshapes/rectangle/KoRectangleShape.h>
#include <pathshapes/ellipse/KoEllipseShape.h>
#include <pictureshape/PictureShape.h>
-
+#include <simpletextshape/SimpleTextShape.h>
#include <kdebug.h>
/*
@@ -125,7 +125,8 @@
}
-void WMFImportParser::setFont( const QFont & ) {
+void WMFImportParser::setFont( const QFont &font ) {
+ mFont = font;
}
@@ -375,8 +376,50 @@
}
-void WMFImportParser::drawText( int , int , int , int , int , const QString& , \
double ) {
- kDebug() << "importing text is not supported";
+void WMFImportParser::drawText( int x, int y, int , int , int flags, const QString& \
text, double rotation ) { + enum TextFlags { CurrentPosition = 0x01, AlignHCenter \
= 0x06, AlignBottom = 0x08 }; +
+ if ( flags & CurrentPosition ) {
+ // (left, top) position = current logical position
+ x = mCurrentPoint.x();
+ y = mCurrentPoint.y();
+ }
+
+ // adjust font size
+ QFont font = mFont;
+ font.setPointSizeF( coordY( mFont.pointSize() ) );
+
+ SimpleTextShape * textShape = new SimpleTextShape();
+ textShape->setFont( font );
+ textShape->setText( text );
+
+ // determine y-offset from given baseline position
+ qreal yOffset = 0.0;
+ if( flags & AlignBottom )
+ yOffset -= textShape->baselineOffset();
+
+ textShape->setPosition( QPointF( coordX(x), coordY(y)+yOffset ) );
+
+ // set text anchor
+ qreal xOffset = 0.0;
+ if( flags & AlignHCenter ) {
+ textShape->setTextAnchor( SimpleTextShape::AnchorMiddle );
+ xOffset = -0.5 * textShape->size().width();
+ }
+
+ if ( rotation ) {
+ // we rotate around the anchor point
+ QPointF anchor( -xOffset, -yOffset );
+ QMatrix matrix;
+ matrix.translate( anchor.x(), anchor.y() );
+ matrix.rotate ( rotation );
+ matrix.translate( -anchor.x(), -anchor.y() );
+ textShape->applyTransformation( matrix );
+ }
+
+ textShape->setBackground( new KoColorBackground( mPen.color() ) );
+
+ mDoc->add( textShape );
}
--- trunk/koffice/filters/karbon/wmf/wmfimportparser.h #837897:837898
@@ -132,6 +132,7 @@
double mScaleY;
// current position in WMF coordinate (INT16)
QPoint mCurrentPoint;
+ QFont mFont;
};
#endif
--- trunk/koffice/filters/libkowmf/kowmfreadprivate.cc #837897:837898
@@ -675,6 +675,9 @@
stream >> color;
mTextColor = qtColor( color );
+ // TODO: not sure if that is the right thing to do here
+ // but the actual reader has to get the color somehow (jaham)
+ mReadWmf->setPen( QPen(mTextColor) );
}
@@ -684,19 +687,49 @@
}
-void KoWmfReadPrivate::textOut( quint32, QDataStream& )
+void KoWmfReadPrivate::textOut( quint32, QDataStream& stream )
{
- if ( mNbrFunc ) {
- kDebug() <<"textOut : unimplemented";
- }
+ qint16 textLength;
+
+ stream >> textLength;
+
+ QByteArray text;
+ text.resize( textLength );
+
+ stream.readRawData( text.data(), textLength );
+
+ qint16 x, y;
+
+ stream >> y;
+ stream >> x;
+
+ mReadWmf->drawText( x, y, -1, -1, mTextAlign, text, static_cast<double>( \
mTextRotation ) ); }
-void KoWmfReadPrivate::extTextOut( quint32 , QDataStream& )
+void KoWmfReadPrivate::extTextOut( quint32 , QDataStream& stream )
{
- if ( mNbrFunc ) {
- kDebug() <<"extTextOut : unimplemented";
+ qint16 parm[8];
+ for( int i = 0; i < 4; ++i )
+ stream >> parm[i];
+
+ quint16 textLength = parm[ 2 ];
+
+ QByteArray text;
+ text.resize( textLength );
+
+ if ( parm[ 3 ] != 0 ) // ETO_CLIPPED flag add 4 parameters
+ {
+ for( int i = 0; i < 4; ++i )
+ stream >> parm[4+i];
+ stream.readRawData( text.data(), textLength );
}
+ else
+ {
+ stream.readRawData( text.data(), textLength );
+ }
+
+ mReadWmf->drawText( parm[ 1 ], parm[ 0 ], -1, -1, mTextAlign, text, \
static_cast<double>( mTextRotation ) ); }
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic