From d63c9d696eb6e2539528b99afc21f4086c9defe3 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 23 May 2021 20:48:35 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro (cherry picked from commit 8b78a8791bc539bcffe7159f9d9714d577cb3d7d) --- filters/karbon/wmf/Makefile.am | 4 +- filters/karbon/wmf/wmfexport.cc | 263 ----------------------- filters/karbon/wmf/wmfexport.cpp | 263 +++++++++++++++++++++++ filters/karbon/wmf/wmfimport.cc | 78 ------- filters/karbon/wmf/wmfimport.cpp | 78 +++++++ filters/karbon/wmf/wmfimportparser.cc | 371 --------------------------------- filters/karbon/wmf/wmfimportparser.cpp | 371 +++++++++++++++++++++++++++++++++ 7 files changed, 714 insertions(+), 714 deletions(-) delete mode 100644 filters/karbon/wmf/wmfexport.cc create mode 100644 filters/karbon/wmf/wmfexport.cpp delete mode 100644 filters/karbon/wmf/wmfimport.cc create mode 100644 filters/karbon/wmf/wmfimport.cpp delete mode 100644 filters/karbon/wmf/wmfimportparser.cc create mode 100644 filters/karbon/wmf/wmfimportparser.cpp (limited to 'filters/karbon/wmf') diff --git a/filters/karbon/wmf/Makefile.am b/filters/karbon/wmf/Makefile.am index 561aaa1f..6ab547e2 100644 --- a/filters/karbon/wmf/Makefile.am +++ b/filters/karbon/wmf/Makefile.am @@ -13,11 +13,11 @@ kde_module_LTLIBRARIES = libwmfimport.la libwmfexport.la libwmfimport_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_QT) -lkjs -ltdefx -ltdeio -ltdeparts libwmfimport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KOWMF) ../../../karbon/libkarboncommon.la -libwmfimport_la_SOURCES = wmfimport.cc wmfimportparser.cc +libwmfimport_la_SOURCES = wmfimport.cpp wmfimportparser.cpp libwmfexport_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_QT) -lkjs -ltdefx -ltdeio -ltdeparts libwmfexport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KOWMF) ../../../karbon/libkarboncommon.la -libwmfexport_la_SOURCES = wmfexport.cc +libwmfexport_la_SOURCES = wmfexport.cpp noinst_HEADERS = wmfimport.h wmfimportparser.h wmfexport.h diff --git a/filters/karbon/wmf/wmfexport.cc b/filters/karbon/wmf/wmfexport.cc deleted file mode 100644 index de929ca8..00000000 --- a/filters/karbon/wmf/wmfexport.cc +++ /dev/null @@ -1,263 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2003 thierry lorthiois (lorthioist@wanadoo.fr) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License version 2 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "vdocument.h" -#include "vcolor.h" -#include "vcomposite.h" -#include "vdashpattern.h" -#include "vdocument.h" -#include "vlayer.h" -#include "vpath.h" -#include "vsegment.h" -#include "vfill.h" -#include "vstroke.h" -#include "vtext.h" -#include "vflattencmd.h" - -#include "wmfexport.h" -#include "kowmfwrite.h" - -/* -TODO: bs.wmf stroke in red with MSword and in brown with Kword ?? -*/ - -typedef KGenericFactory WmfExportFactory; -K_EXPORT_COMPONENT_FACTORY( libwmfexport, WmfExportFactory( "kofficefilters" ) ) - - -WmfExport::WmfExport( KoFilter *, const char *, const TQStringList&) : - KoFilter() -{ -} - -WmfExport::~WmfExport() -{ -} - -KoFilter::ConversionStatus WmfExport::convert( const TQCString& from, const TQCString& to ) -{ - if( to != "image/x-wmf" || from != "application/x-karbon" ) { - return KoFilter::NotImplemented; - } - - KoStoreDevice* storeIn = m_chain->storageFile( "root", KoStore::Read ); - - if( !storeIn ) { - return KoFilter::StupidError; - } - - // open Placeable Wmf file - mWmf = new KoWmfWrite( m_chain->outputFile() ); - if( !mWmf->begin() ) { - delete mWmf; - return KoFilter::WrongFormat; - } - - TQDomDocument domIn; - domIn.setContent( storeIn ); - TQDomElement docNode = domIn.documentElement(); - - // Load the document. - mDoc = new VDocument; - mDoc->load( docNode ); - - // Process the document. - mDoc->accept( *this ); - - mWmf->end(); - - delete mWmf; - delete mDoc; - - return KoFilter::OK; -} - - -void WmfExport::visitVDocument( VDocument& document ) { - int width; - int height; - - mDoc = &document; - mListPa.setAutoDelete( true ); - - // resolution - mDpi = 1000; - width = (int)(POINT_TO_INCH( document.width() ) * mDpi); - height = (int)(POINT_TO_INCH( document.height() ) * mDpi); - - mWmf->setDefaultDpi( mDpi ); - mWmf->setWindow( 0, 0, width, height ); - - if ( (document.width() != 0) && (document.height() != 0) ) { - mScaleX = (double)width / document.width(); - mScaleY = (double)height / document.height(); - } - - // Export layers. - VVisitor::visitVDocument( document ); - -} - - -void WmfExport::visitVPath( VPath& composite ) { - TQPen pen; - TQBrush brush; - - getPen( pen, composite.stroke() ); - getBrush( brush, composite.fill() ); - - VVisitor::visitVPath( composite ); - - if ( mListPa.count() > 0 ) { - mWmf->setPen( pen ); - if( (brush.style() == TQt::NoBrush) - && (mListPa.count() == 1) ) { - mWmf->drawPolyline( *mListPa.first() ); - } - else { - mWmf->setBrush( brush ); - - if ( mListPa.count() == 1 ) { - mWmf->drawPolygon( *mListPa.first() ); - } - else { - // combined path - mWmf->drawPolyPolygon( mListPa ); - } - } - } - mListPa.clear(); -} - - -// Export segment. -void WmfExport::visitVSubpath( VSubpath& path ) { - VSubpath *newPath; - VSubpathIterator itr( path ); - VFlattenCmd cmd( 0L, INCH_TO_POINT(0.3 / (double)mDpi) ); - TQPointArray *pa = new TQPointArray( path.count() ); - int nbrPoint=0; // number of points in the path - - for( ; itr.current(); ++itr ) { - VSegment *segment= itr.current(); - if (segment->isCurve()) { - newPath = new VSubpath( mDoc ); - - // newPath duplicate the list of curve - newPath->moveTo( itr.current()->prev()->knot() ); - newPath->append( itr.current()->clone() ); - while( itr.current()->next() ) { - if ( itr.current()->next()->isCurve() ) { - newPath->append( itr.current()->next()->clone() ); - } - else { - break; - } - ++itr; - } - - // flatten the curve - cmd.visit( *newPath ); - - // adjust the number of points - pa->resize( pa->size() + newPath->count() - 2 ); - - // Ommit the first segment and insert points - newPath->first(); - while( newPath->next() ) { - pa->setPoint( nbrPoint++, coordX( newPath->current()->knot().x() ), - coordY( newPath->current()->knot().y() ) ); - } - delete newPath; - } else if (segment->isLine()) { - pa->setPoint( nbrPoint++, coordX( itr.current()->knot().x() ), - coordY( itr.current()->knot().y() ) ); - } else if (segment->isBegin()) { - // start a new polygon - pa->setPoint( nbrPoint++, coordX( itr.current()->knot().x() ), - coordY( itr.current()->knot().y() ) ); - } - } - - // adjust the number of points - if ( nbrPoint > 1 ) { - pa->resize( nbrPoint ); - mListPa.append( pa ); - } - else { - delete pa; - // TODO: check why we have empty path - kdDebug() << "WmfExport::visitVSubpath : Empty path ?" << endl; - } -} - - -void WmfExport::visitVText( VText& text ) { - // TODO: export text - visitVSubpath( text.basePath() ); -} - - -void WmfExport::getBrush( TQBrush& brush, const VFill *fill ) { - if( (fill->type() == VFill::solid) || (fill->type() == VFill::grad) - || (fill->type() == VFill::patt) ) { - if ( fill->color().opacity() < 0.1 ) { - brush.setStyle( Qt::NoBrush ); - } - else { - brush.setStyle( Qt::SolidPattern ); - brush.setColor( fill->color() ); - } - } - else { - brush.setStyle( Qt::NoBrush ); - } -} - - -void WmfExport::getPen( TQPen& pen, const VStroke *stroke ) { - if( (stroke->type() == VStroke::solid) || (stroke->type() == VStroke::grad) - || (stroke->type() == VStroke::patt) ) { - // TODO : Dash pattern. - - if ( stroke->lineCap() == VStroke::capRound ) { - pen.setCapStyle( Qt::RoundCap ); - } - else { - pen.setCapStyle( Qt::SquareCap ); - } - pen.setStyle( Qt::SolidLine ); - pen.setColor( stroke->color() ); - pen.setWidth( coordX( stroke->lineWidth() ) ); - } - else { - pen.setStyle( Qt::NoPen ); - } -} - - -#include - diff --git a/filters/karbon/wmf/wmfexport.cpp b/filters/karbon/wmf/wmfexport.cpp new file mode 100644 index 00000000..de929ca8 --- /dev/null +++ b/filters/karbon/wmf/wmfexport.cpp @@ -0,0 +1,263 @@ +/* This file is part of the KDE project + * Copyright (c) 2003 thierry lorthiois (lorthioist@wanadoo.fr) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "vdocument.h" +#include "vcolor.h" +#include "vcomposite.h" +#include "vdashpattern.h" +#include "vdocument.h" +#include "vlayer.h" +#include "vpath.h" +#include "vsegment.h" +#include "vfill.h" +#include "vstroke.h" +#include "vtext.h" +#include "vflattencmd.h" + +#include "wmfexport.h" +#include "kowmfwrite.h" + +/* +TODO: bs.wmf stroke in red with MSword and in brown with Kword ?? +*/ + +typedef KGenericFactory WmfExportFactory; +K_EXPORT_COMPONENT_FACTORY( libwmfexport, WmfExportFactory( "kofficefilters" ) ) + + +WmfExport::WmfExport( KoFilter *, const char *, const TQStringList&) : + KoFilter() +{ +} + +WmfExport::~WmfExport() +{ +} + +KoFilter::ConversionStatus WmfExport::convert( const TQCString& from, const TQCString& to ) +{ + if( to != "image/x-wmf" || from != "application/x-karbon" ) { + return KoFilter::NotImplemented; + } + + KoStoreDevice* storeIn = m_chain->storageFile( "root", KoStore::Read ); + + if( !storeIn ) { + return KoFilter::StupidError; + } + + // open Placeable Wmf file + mWmf = new KoWmfWrite( m_chain->outputFile() ); + if( !mWmf->begin() ) { + delete mWmf; + return KoFilter::WrongFormat; + } + + TQDomDocument domIn; + domIn.setContent( storeIn ); + TQDomElement docNode = domIn.documentElement(); + + // Load the document. + mDoc = new VDocument; + mDoc->load( docNode ); + + // Process the document. + mDoc->accept( *this ); + + mWmf->end(); + + delete mWmf; + delete mDoc; + + return KoFilter::OK; +} + + +void WmfExport::visitVDocument( VDocument& document ) { + int width; + int height; + + mDoc = &document; + mListPa.setAutoDelete( true ); + + // resolution + mDpi = 1000; + width = (int)(POINT_TO_INCH( document.width() ) * mDpi); + height = (int)(POINT_TO_INCH( document.height() ) * mDpi); + + mWmf->setDefaultDpi( mDpi ); + mWmf->setWindow( 0, 0, width, height ); + + if ( (document.width() != 0) && (document.height() != 0) ) { + mScaleX = (double)width / document.width(); + mScaleY = (double)height / document.height(); + } + + // Export layers. + VVisitor::visitVDocument( document ); + +} + + +void WmfExport::visitVPath( VPath& composite ) { + TQPen pen; + TQBrush brush; + + getPen( pen, composite.stroke() ); + getBrush( brush, composite.fill() ); + + VVisitor::visitVPath( composite ); + + if ( mListPa.count() > 0 ) { + mWmf->setPen( pen ); + if( (brush.style() == TQt::NoBrush) + && (mListPa.count() == 1) ) { + mWmf->drawPolyline( *mListPa.first() ); + } + else { + mWmf->setBrush( brush ); + + if ( mListPa.count() == 1 ) { + mWmf->drawPolygon( *mListPa.first() ); + } + else { + // combined path + mWmf->drawPolyPolygon( mListPa ); + } + } + } + mListPa.clear(); +} + + +// Export segment. +void WmfExport::visitVSubpath( VSubpath& path ) { + VSubpath *newPath; + VSubpathIterator itr( path ); + VFlattenCmd cmd( 0L, INCH_TO_POINT(0.3 / (double)mDpi) ); + TQPointArray *pa = new TQPointArray( path.count() ); + int nbrPoint=0; // number of points in the path + + for( ; itr.current(); ++itr ) { + VSegment *segment= itr.current(); + if (segment->isCurve()) { + newPath = new VSubpath( mDoc ); + + // newPath duplicate the list of curve + newPath->moveTo( itr.current()->prev()->knot() ); + newPath->append( itr.current()->clone() ); + while( itr.current()->next() ) { + if ( itr.current()->next()->isCurve() ) { + newPath->append( itr.current()->next()->clone() ); + } + else { + break; + } + ++itr; + } + + // flatten the curve + cmd.visit( *newPath ); + + // adjust the number of points + pa->resize( pa->size() + newPath->count() - 2 ); + + // Ommit the first segment and insert points + newPath->first(); + while( newPath->next() ) { + pa->setPoint( nbrPoint++, coordX( newPath->current()->knot().x() ), + coordY( newPath->current()->knot().y() ) ); + } + delete newPath; + } else if (segment->isLine()) { + pa->setPoint( nbrPoint++, coordX( itr.current()->knot().x() ), + coordY( itr.current()->knot().y() ) ); + } else if (segment->isBegin()) { + // start a new polygon + pa->setPoint( nbrPoint++, coordX( itr.current()->knot().x() ), + coordY( itr.current()->knot().y() ) ); + } + } + + // adjust the number of points + if ( nbrPoint > 1 ) { + pa->resize( nbrPoint ); + mListPa.append( pa ); + } + else { + delete pa; + // TODO: check why we have empty path + kdDebug() << "WmfExport::visitVSubpath : Empty path ?" << endl; + } +} + + +void WmfExport::visitVText( VText& text ) { + // TODO: export text + visitVSubpath( text.basePath() ); +} + + +void WmfExport::getBrush( TQBrush& brush, const VFill *fill ) { + if( (fill->type() == VFill::solid) || (fill->type() == VFill::grad) + || (fill->type() == VFill::patt) ) { + if ( fill->color().opacity() < 0.1 ) { + brush.setStyle( Qt::NoBrush ); + } + else { + brush.setStyle( Qt::SolidPattern ); + brush.setColor( fill->color() ); + } + } + else { + brush.setStyle( Qt::NoBrush ); + } +} + + +void WmfExport::getPen( TQPen& pen, const VStroke *stroke ) { + if( (stroke->type() == VStroke::solid) || (stroke->type() == VStroke::grad) + || (stroke->type() == VStroke::patt) ) { + // TODO : Dash pattern. + + if ( stroke->lineCap() == VStroke::capRound ) { + pen.setCapStyle( Qt::RoundCap ); + } + else { + pen.setCapStyle( Qt::SquareCap ); + } + pen.setStyle( Qt::SolidLine ); + pen.setColor( stroke->color() ); + pen.setWidth( coordX( stroke->lineWidth() ) ); + } + else { + pen.setStyle( Qt::NoPen ); + } +} + + +#include + diff --git a/filters/karbon/wmf/wmfimport.cc b/filters/karbon/wmf/wmfimport.cc deleted file mode 100644 index f7dcdcf3..00000000 --- a/filters/karbon/wmf/wmfimport.cc +++ /dev/null @@ -1,78 +0,0 @@ -/* - Copyright (C) 2000, S.R.Haque . - This file is part of the KDE project - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - -DESCRIPTION -*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "wmfimport.h" -#include "wmfimportparser.h" - -typedef KGenericFactory WMFImportFactory; -K_EXPORT_COMPONENT_FACTORY( libwmfimport, WMFImportFactory( "kofficefilters" ) ) - - -WMFImport::WMFImport( KoFilter *, const char *, const TQStringList&) : - KoFilter() -{ -} - -WMFImport::~WMFImport() -{ -} - -KoFilter::ConversionStatus WMFImport::convert( const TQCString& from, const TQCString& to ) -{ - if( to != "application/x-karbon" || from != "image/x-wmf" ) - return KoFilter::NotImplemented; - - WMFImportParser wmfParser; - if( !wmfParser.load( m_chain->inputFile() ) ) { - return KoFilter::WrongFormat; - } - - // Do the conversion! - VDocument document; - if (!wmfParser.play( document )) { - return KoFilter::WrongFormat; - } - - KoStoreDevice* out = m_chain->storageFile( "root", KoStore::Write ); - if( !out ) { - kdError(3800) << "Unable to open output file!" << endl; - return KoFilter::StorageCreationError; - } - TQDomDocument outdoc = document.saveXML(); - TQCString content = outdoc.toCString(); - // kdDebug() << " content : " << content << endl; - out->writeBlock( content , content.length() ); - - return KoFilter::OK; -} - - -#include diff --git a/filters/karbon/wmf/wmfimport.cpp b/filters/karbon/wmf/wmfimport.cpp new file mode 100644 index 00000000..f7dcdcf3 --- /dev/null +++ b/filters/karbon/wmf/wmfimport.cpp @@ -0,0 +1,78 @@ +/* + Copyright (C) 2000, S.R.Haque . + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + +DESCRIPTION +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "wmfimport.h" +#include "wmfimportparser.h" + +typedef KGenericFactory WMFImportFactory; +K_EXPORT_COMPONENT_FACTORY( libwmfimport, WMFImportFactory( "kofficefilters" ) ) + + +WMFImport::WMFImport( KoFilter *, const char *, const TQStringList&) : + KoFilter() +{ +} + +WMFImport::~WMFImport() +{ +} + +KoFilter::ConversionStatus WMFImport::convert( const TQCString& from, const TQCString& to ) +{ + if( to != "application/x-karbon" || from != "image/x-wmf" ) + return KoFilter::NotImplemented; + + WMFImportParser wmfParser; + if( !wmfParser.load( m_chain->inputFile() ) ) { + return KoFilter::WrongFormat; + } + + // Do the conversion! + VDocument document; + if (!wmfParser.play( document )) { + return KoFilter::WrongFormat; + } + + KoStoreDevice* out = m_chain->storageFile( "root", KoStore::Write ); + if( !out ) { + kdError(3800) << "Unable to open output file!" << endl; + return KoFilter::StorageCreationError; + } + TQDomDocument outdoc = document.saveXML(); + TQCString content = outdoc.toCString(); + // kdDebug() << " content : " << content << endl; + out->writeBlock( content , content.length() ); + + return KoFilter::OK; +} + + +#include diff --git a/filters/karbon/wmf/wmfimportparser.cc b/filters/karbon/wmf/wmfimportparser.cc deleted file mode 100644 index 275490fe..00000000 --- a/filters/karbon/wmf/wmfimportparser.cc +++ /dev/null @@ -1,371 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2003 thierry lorthiois (lorthioist@wanadoo.fr) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License version 2 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include -#include -#include -#include - -#include "wmfimportparser.h" - -/* -bug : see motar.wmf -*/ - -WMFImportParser::WMFImportParser() : KoWmfRead() { -} - - -bool WMFImportParser::play( VDocument& doc ) -{ - mDoc = &doc; - mScaleX = mScaleY = 1; - - // Play the wmf file - return KoWmfRead::play( ); -} - - -//----------------------------------------------------------------------------- -// Virtual Painter - -bool WMFImportParser::begin() { - TQRect bounding = boundingRect(); - - mBackgroundMode = Qt::TransparentMode; - mCurrentOrg.setX( bounding.left() ); - mCurrentOrg.setY( bounding.top() ); - - if ( isStandard() ) { - mDoc->setUnit( KoUnit::U_PT ); - mDoc->setWidth( bounding.width() ); - mDoc->setHeight( bounding.height() ); - } - else { - // Placeable Wmf store the boundingRect() in pixel and the default DPI - // The placeable format doesn't have informations on witch Unit to use - // so we choose millimeters by default - mDoc->setUnit( KoUnit::U_MM ); - mDoc->setWidth( INCH_TO_POINT( (double)bounding.width() / defaultDpi() ) ); - mDoc->setHeight( INCH_TO_POINT( (double)bounding.height() / defaultDpi() ) ); - } - if ( (bounding.width() != 0) && (bounding.height() != 0) ) { - mScaleX = mDoc->width() / (double)bounding.width(); - mScaleY = mDoc->height() / (double)bounding.height(); - } - return true; -} - - -bool WMFImportParser::end() { - return true; -} - - -void WMFImportParser::save() { -} - - -void WMFImportParser::restore() { -} - - -void WMFImportParser::setFont( const TQFont & ) { -} - - -void WMFImportParser::setPen( const TQPen &pen ) { - mPen = pen; -} - - -const TQPen &WMFImportParser::pen() const { - return mPen; -} - - -void WMFImportParser::setBrush( const TQBrush &brush ) { - mBrush = brush; -} - - -void WMFImportParser::setBackgroundColor( const TQColor &c ) { - mBackgroundColor = c; -} - - -void WMFImportParser::setBackgroundMode( Qt::BGMode mode ) { - mBackgroundMode = mode; -} - - -void WMFImportParser::setRasterOp( TQt::RasterOp ) { -} - - -void WMFImportParser::setWindowOrg( int left, int top ) { - mCurrentOrg.setX( left ); - mCurrentOrg.setY( top ); -} - - -void WMFImportParser::setWindowExt( int width, int height ) { - // the wmf file can change width/height during the drawing - if ( (width != 0) && (height != 0) ) { - mScaleX = mDoc->width() / (double)width; - mScaleY = mDoc->height() / (double)height; - } -} - - -void WMFImportParser::setWorldMatrix( const TQWMatrix &, bool ) { -} - - -void WMFImportParser::setClipRegion( const TQRegion & ) { -} - - -TQRegion WMFImportParser::clipRegion() { - return mClippingRegion; -} - - -void WMFImportParser::moveTo( int left, int top ) { - mCurrentPoint.setX( left ); - mCurrentPoint.setY( top ); -} - - -void WMFImportParser::lineTo( int left, int top ) { - VPath *line = new VPath( mDoc ); - line->moveTo( KoPoint( coordX(mCurrentPoint.x()), coordY(mCurrentPoint.y()) ) ); - line->lineTo( KoPoint( coordX(left), coordY(top) ) ); - appendPen( *line ); - - mDoc->append( line ); - mCurrentPoint.setX( left ); - mCurrentPoint.setY( top ); -} - - -void WMFImportParser::drawRect( int left, int top, int width, int height ) { - VRectangle *rectangle; - - rectangle = new VRectangle( mDoc, KoPoint( coordX(left), coordY(top) ), scaleW(width), scaleH(height), 0 ); - appendPen( *rectangle ); - appendBrush( *rectangle ); - - mDoc->append( rectangle ); -} - - -void WMFImportParser::drawRoundRect( int left, int top, int width, int height, int roudw, int ) { - VRectangle *rectangle; - - // TODO : round rectangle - rectangle = new VRectangle( mDoc, KoPoint( coordX(left), coordY(top) ), scaleW(width), scaleH(height), roudw ); - appendPen( *rectangle ); - appendBrush( *rectangle ); - - mDoc->append( rectangle ); -} - - -void WMFImportParser::drawEllipse( int left, int top, int width, int height ) { - VEllipse *ellipse; - - ellipse = new VEllipse( mDoc, KoPoint( coordX(left), coordY(top+height) ), scaleW(width), scaleH(height) ); - appendPen( *ellipse ); - appendBrush( *ellipse ); - - mDoc->append( ellipse ); -} - - -void WMFImportParser::drawArc( int x, int y, int w, int h, int aStart, int aLen ) { - double start = (aStart * 180) / 2880.0; - double end = (aLen * 180) / 2880.0; - end += start; - VEllipse::VEllipseType type = VEllipse::arc; - - VEllipse *arc = new VEllipse( mDoc, KoPoint( coordX(x), coordY(y+h) ), scaleW(w), scaleH(h), type, start, end ); - appendPen( *arc ); - - mDoc->append( arc ); -} - - -void WMFImportParser::drawPie( int x, int y, int w, int h, int aStart, int aLen ) { - double start = (aStart * 180) / 2880.0; - double end = (aLen * 180) / 2880.0; - end += start; - VEllipse::VEllipseType type = VEllipse::cut; - - VEllipse *arc = new VEllipse( mDoc, KoPoint( coordX(x), coordY(y+h) ), scaleW(w), scaleH(h), type, start, end ); - appendPen( *arc ); - appendBrush( *arc ); - - mDoc->append( arc ); -} - - -void WMFImportParser::drawChord( int x, int y, int w, int h, int aStart, int aLen ) { - double start = (aStart * 180) / 2880.0; - double end = (aLen * 180) / 2880.0; - end += start; - VEllipse::VEllipseType type = VEllipse::section; - - VEllipse *arc = new VEllipse( mDoc, KoPoint( coordX(x), coordY(y+h) ), scaleW(w), scaleH(h), type, start, end ); - appendPen( *arc ); - appendBrush( *arc ); - - mDoc->append( arc ); -} - - -void WMFImportParser::drawPolyline( const TQPointArray &pa ) { - VPath *polyline = new VPath( mDoc ); - appendPen( *polyline ); - appendPoints( *polyline, pa ); - - mDoc->append( polyline ); -} - - -void WMFImportParser::drawPolygon( const TQPointArray &pa, bool ) { - VPath *polygon = new VPath( mDoc ); - appendPen( *polygon ); - appendBrush( *polygon ); - appendPoints( *polygon, pa ); - - polygon->close(); - mDoc->append( polygon ); -} - - -void WMFImportParser::drawPolyPolygon( TQPtrList& listPa, bool ) { - VPath *path = new VPath( mDoc ); - - if ( listPa.count() > 0 ) { - appendPen( *path ); - appendBrush( *path ); - appendPoints( *path, *listPa.first() ); - path->close(); - - while ( listPa.next() ) { - VPath *newPath = new VPath( mDoc ); - appendPoints( *newPath, *listPa.current() ); - newPath->close(); - path->combine( *newPath ); - } - - mDoc->append( path ); - } -} - - -void WMFImportParser::drawImage( int , int , const TQImage &, int , int , int , int ) {} - - -void WMFImportParser::drawText( int , int , int , int , int , const TQString& , double ) {} - - -//----------------------------------------------------------------------------- -// Utilities - -void WMFImportParser::appendPen( VObject& obj ) -{ - VStroke stroke( mDoc ); - stroke.setLineCap( VStroke::capRound ); - - if ( mPen.style() == TQt::NoPen ) { - stroke.setType( VStroke::none ); - } - else { - TQValueList dashes; - stroke.setType( VStroke::solid ); - switch ( mPen.style() ) { - case TQt::DashLine : - stroke.dashPattern().setArray( dashes << MM_TO_POINT(3) << MM_TO_POINT(2) ); - break; - case TQt::DotLine : - stroke.dashPattern().setArray( dashes << MM_TO_POINT(1) << MM_TO_POINT(1) ); - break; - case TQt::DashDotLine : - stroke.dashPattern().setArray( dashes << MM_TO_POINT(3) << MM_TO_POINT(1) << MM_TO_POINT(1) << MM_TO_POINT(1) ); - break; - case TQt::DashDotDotLine : - stroke.dashPattern().setArray( dashes << MM_TO_POINT(3) << MM_TO_POINT(1) << MM_TO_POINT(1) << MM_TO_POINT(1) << MM_TO_POINT(1) << MM_TO_POINT(1) ); - break; - default: - break; - } - } - stroke.setColor( TQColor(mPen.color()) ); - double width = mPen.width() * mScaleX; - stroke.setLineWidth( ((width < 0.99) ? 1 : width) ); - obj.setStroke( stroke ); -} - - -void WMFImportParser::appendBrush( VObject& obj ) -{ - VFill fill( mBackgroundColor ); - fill.setColor( TQColor(mBrush.color()) ); - - switch ( mBrush.style() ) { - case TQt::NoBrush : - fill.setType( VFill::none ); - break; - case TQt::SolidPattern : - fill.setType( VFill::solid ); - break; - case TQt::CustomPattern : - // TODO: bitmap pattern brush - fill.setType( VFill::solid ); - //fill.pattern(). - break; - default : - // TODO: pattern brush - if ( mBackgroundMode == TQt::OpaqueMode ) { - fill.setColor( mBackgroundColor ); - fill.setType( VFill::solid ); - } - else { - fill.setType( VFill::none ); - } - break; - } - obj.setFill( fill ); -} - - -void WMFImportParser::appendPoints(VPath &path, const TQPointArray& pa) -{ - // list of point array - if ( pa.size() > 0 ) { - path.moveTo( KoPoint( coordX(pa.point(0).x()), coordY(pa.point(0).y()) ) ); - } - for ( uint i=1 ; i < pa.size() ; i++ ) { - path.lineTo( KoPoint( coordX(pa.point(i).x()), coordY(pa.point(i).y()) ) ); - } -} - diff --git a/filters/karbon/wmf/wmfimportparser.cpp b/filters/karbon/wmf/wmfimportparser.cpp new file mode 100644 index 00000000..275490fe --- /dev/null +++ b/filters/karbon/wmf/wmfimportparser.cpp @@ -0,0 +1,371 @@ +/* This file is part of the KDE project + * Copyright (c) 2003 thierry lorthiois (lorthioist@wanadoo.fr) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include +#include +#include + +#include "wmfimportparser.h" + +/* +bug : see motar.wmf +*/ + +WMFImportParser::WMFImportParser() : KoWmfRead() { +} + + +bool WMFImportParser::play( VDocument& doc ) +{ + mDoc = &doc; + mScaleX = mScaleY = 1; + + // Play the wmf file + return KoWmfRead::play( ); +} + + +//----------------------------------------------------------------------------- +// Virtual Painter + +bool WMFImportParser::begin() { + TQRect bounding = boundingRect(); + + mBackgroundMode = Qt::TransparentMode; + mCurrentOrg.setX( bounding.left() ); + mCurrentOrg.setY( bounding.top() ); + + if ( isStandard() ) { + mDoc->setUnit( KoUnit::U_PT ); + mDoc->setWidth( bounding.width() ); + mDoc->setHeight( bounding.height() ); + } + else { + // Placeable Wmf store the boundingRect() in pixel and the default DPI + // The placeable format doesn't have informations on witch Unit to use + // so we choose millimeters by default + mDoc->setUnit( KoUnit::U_MM ); + mDoc->setWidth( INCH_TO_POINT( (double)bounding.width() / defaultDpi() ) ); + mDoc->setHeight( INCH_TO_POINT( (double)bounding.height() / defaultDpi() ) ); + } + if ( (bounding.width() != 0) && (bounding.height() != 0) ) { + mScaleX = mDoc->width() / (double)bounding.width(); + mScaleY = mDoc->height() / (double)bounding.height(); + } + return true; +} + + +bool WMFImportParser::end() { + return true; +} + + +void WMFImportParser::save() { +} + + +void WMFImportParser::restore() { +} + + +void WMFImportParser::setFont( const TQFont & ) { +} + + +void WMFImportParser::setPen( const TQPen &pen ) { + mPen = pen; +} + + +const TQPen &WMFImportParser::pen() const { + return mPen; +} + + +void WMFImportParser::setBrush( const TQBrush &brush ) { + mBrush = brush; +} + + +void WMFImportParser::setBackgroundColor( const TQColor &c ) { + mBackgroundColor = c; +} + + +void WMFImportParser::setBackgroundMode( Qt::BGMode mode ) { + mBackgroundMode = mode; +} + + +void WMFImportParser::setRasterOp( TQt::RasterOp ) { +} + + +void WMFImportParser::setWindowOrg( int left, int top ) { + mCurrentOrg.setX( left ); + mCurrentOrg.setY( top ); +} + + +void WMFImportParser::setWindowExt( int width, int height ) { + // the wmf file can change width/height during the drawing + if ( (width != 0) && (height != 0) ) { + mScaleX = mDoc->width() / (double)width; + mScaleY = mDoc->height() / (double)height; + } +} + + +void WMFImportParser::setWorldMatrix( const TQWMatrix &, bool ) { +} + + +void WMFImportParser::setClipRegion( const TQRegion & ) { +} + + +TQRegion WMFImportParser::clipRegion() { + return mClippingRegion; +} + + +void WMFImportParser::moveTo( int left, int top ) { + mCurrentPoint.setX( left ); + mCurrentPoint.setY( top ); +} + + +void WMFImportParser::lineTo( int left, int top ) { + VPath *line = new VPath( mDoc ); + line->moveTo( KoPoint( coordX(mCurrentPoint.x()), coordY(mCurrentPoint.y()) ) ); + line->lineTo( KoPoint( coordX(left), coordY(top) ) ); + appendPen( *line ); + + mDoc->append( line ); + mCurrentPoint.setX( left ); + mCurrentPoint.setY( top ); +} + + +void WMFImportParser::drawRect( int left, int top, int width, int height ) { + VRectangle *rectangle; + + rectangle = new VRectangle( mDoc, KoPoint( coordX(left), coordY(top) ), scaleW(width), scaleH(height), 0 ); + appendPen( *rectangle ); + appendBrush( *rectangle ); + + mDoc->append( rectangle ); +} + + +void WMFImportParser::drawRoundRect( int left, int top, int width, int height, int roudw, int ) { + VRectangle *rectangle; + + // TODO : round rectangle + rectangle = new VRectangle( mDoc, KoPoint( coordX(left), coordY(top) ), scaleW(width), scaleH(height), roudw ); + appendPen( *rectangle ); + appendBrush( *rectangle ); + + mDoc->append( rectangle ); +} + + +void WMFImportParser::drawEllipse( int left, int top, int width, int height ) { + VEllipse *ellipse; + + ellipse = new VEllipse( mDoc, KoPoint( coordX(left), coordY(top+height) ), scaleW(width), scaleH(height) ); + appendPen( *ellipse ); + appendBrush( *ellipse ); + + mDoc->append( ellipse ); +} + + +void WMFImportParser::drawArc( int x, int y, int w, int h, int aStart, int aLen ) { + double start = (aStart * 180) / 2880.0; + double end = (aLen * 180) / 2880.0; + end += start; + VEllipse::VEllipseType type = VEllipse::arc; + + VEllipse *arc = new VEllipse( mDoc, KoPoint( coordX(x), coordY(y+h) ), scaleW(w), scaleH(h), type, start, end ); + appendPen( *arc ); + + mDoc->append( arc ); +} + + +void WMFImportParser::drawPie( int x, int y, int w, int h, int aStart, int aLen ) { + double start = (aStart * 180) / 2880.0; + double end = (aLen * 180) / 2880.0; + end += start; + VEllipse::VEllipseType type = VEllipse::cut; + + VEllipse *arc = new VEllipse( mDoc, KoPoint( coordX(x), coordY(y+h) ), scaleW(w), scaleH(h), type, start, end ); + appendPen( *arc ); + appendBrush( *arc ); + + mDoc->append( arc ); +} + + +void WMFImportParser::drawChord( int x, int y, int w, int h, int aStart, int aLen ) { + double start = (aStart * 180) / 2880.0; + double end = (aLen * 180) / 2880.0; + end += start; + VEllipse::VEllipseType type = VEllipse::section; + + VEllipse *arc = new VEllipse( mDoc, KoPoint( coordX(x), coordY(y+h) ), scaleW(w), scaleH(h), type, start, end ); + appendPen( *arc ); + appendBrush( *arc ); + + mDoc->append( arc ); +} + + +void WMFImportParser::drawPolyline( const TQPointArray &pa ) { + VPath *polyline = new VPath( mDoc ); + appendPen( *polyline ); + appendPoints( *polyline, pa ); + + mDoc->append( polyline ); +} + + +void WMFImportParser::drawPolygon( const TQPointArray &pa, bool ) { + VPath *polygon = new VPath( mDoc ); + appendPen( *polygon ); + appendBrush( *polygon ); + appendPoints( *polygon, pa ); + + polygon->close(); + mDoc->append( polygon ); +} + + +void WMFImportParser::drawPolyPolygon( TQPtrList& listPa, bool ) { + VPath *path = new VPath( mDoc ); + + if ( listPa.count() > 0 ) { + appendPen( *path ); + appendBrush( *path ); + appendPoints( *path, *listPa.first() ); + path->close(); + + while ( listPa.next() ) { + VPath *newPath = new VPath( mDoc ); + appendPoints( *newPath, *listPa.current() ); + newPath->close(); + path->combine( *newPath ); + } + + mDoc->append( path ); + } +} + + +void WMFImportParser::drawImage( int , int , const TQImage &, int , int , int , int ) {} + + +void WMFImportParser::drawText( int , int , int , int , int , const TQString& , double ) {} + + +//----------------------------------------------------------------------------- +// Utilities + +void WMFImportParser::appendPen( VObject& obj ) +{ + VStroke stroke( mDoc ); + stroke.setLineCap( VStroke::capRound ); + + if ( mPen.style() == TQt::NoPen ) { + stroke.setType( VStroke::none ); + } + else { + TQValueList dashes; + stroke.setType( VStroke::solid ); + switch ( mPen.style() ) { + case TQt::DashLine : + stroke.dashPattern().setArray( dashes << MM_TO_POINT(3) << MM_TO_POINT(2) ); + break; + case TQt::DotLine : + stroke.dashPattern().setArray( dashes << MM_TO_POINT(1) << MM_TO_POINT(1) ); + break; + case TQt::DashDotLine : + stroke.dashPattern().setArray( dashes << MM_TO_POINT(3) << MM_TO_POINT(1) << MM_TO_POINT(1) << MM_TO_POINT(1) ); + break; + case TQt::DashDotDotLine : + stroke.dashPattern().setArray( dashes << MM_TO_POINT(3) << MM_TO_POINT(1) << MM_TO_POINT(1) << MM_TO_POINT(1) << MM_TO_POINT(1) << MM_TO_POINT(1) ); + break; + default: + break; + } + } + stroke.setColor( TQColor(mPen.color()) ); + double width = mPen.width() * mScaleX; + stroke.setLineWidth( ((width < 0.99) ? 1 : width) ); + obj.setStroke( stroke ); +} + + +void WMFImportParser::appendBrush( VObject& obj ) +{ + VFill fill( mBackgroundColor ); + fill.setColor( TQColor(mBrush.color()) ); + + switch ( mBrush.style() ) { + case TQt::NoBrush : + fill.setType( VFill::none ); + break; + case TQt::SolidPattern : + fill.setType( VFill::solid ); + break; + case TQt::CustomPattern : + // TODO: bitmap pattern brush + fill.setType( VFill::solid ); + //fill.pattern(). + break; + default : + // TODO: pattern brush + if ( mBackgroundMode == TQt::OpaqueMode ) { + fill.setColor( mBackgroundColor ); + fill.setType( VFill::solid ); + } + else { + fill.setType( VFill::none ); + } + break; + } + obj.setFill( fill ); +} + + +void WMFImportParser::appendPoints(VPath &path, const TQPointArray& pa) +{ + // list of point array + if ( pa.size() > 0 ) { + path.moveTo( KoPoint( coordX(pa.point(0).x()), coordY(pa.point(0).y()) ) ); + } + for ( uint i=1 ; i < pa.size() ; i++ ) { + path.lineTo( KoPoint( coordX(pa.point(i).x()), coordY(pa.point(i).y()) ) ); + } +} + -- cgit v1.2.1