From 5c9af0b9251b767d88e4c191120e2eb2d7066a93 Mon Sep 17 00:00:00 2001 From: ka Date: Fri, 4 Feb 2011 14:52:54 +0100 Subject: ka102: added/removed files for SVG import and module cleanup --- .../source/filter.vcl/filter/FilterConfigCache.cxx | 596 ------ .../source/filter.vcl/filter/FilterConfigCache.hxx | 145 -- .../source/filter.vcl/filter/FilterConfigItem.cxx | 623 ------ .../filter.vcl/filter/SvFilterOptionsDialog.cxx | 270 --- .../filter.vcl/filter/SvFilterOptionsDialog.hxx | 105 - svtools/source/filter.vcl/filter/exportdialog.cxx | 1513 ------------- svtools/source/filter.vcl/filter/exportdialog.hrc | 99 - svtools/source/filter.vcl/filter/exportdialog.hxx | 216 -- svtools/source/filter.vcl/filter/exportdialog.src | 529 ----- svtools/source/filter.vcl/filter/filter.cxx | 2199 ------------------- svtools/source/filter.vcl/filter/filter2.cxx | 1339 ------------ svtools/source/filter.vcl/filter/sgf.ini | 118 - svtools/source/filter.vcl/filter/sgfbram.cxx | 662 ------ svtools/source/filter.vcl/filter/sgvmain.cxx | 1130 ---------- svtools/source/filter.vcl/filter/sgvspln.cxx | 890 -------- svtools/source/filter.vcl/filter/sgvtext.cxx | 1334 ------------ svtools/source/filter.vcl/igif/decode.cxx | 215 -- svtools/source/filter.vcl/igif/decode.hxx | 68 - svtools/source/filter.vcl/igif/gifread.cxx | 858 -------- svtools/source/filter.vcl/ixbm/xbmread.cxx | 398 ---- svtools/source/filter.vcl/ixpm/rgbtable.hxx | 695 ------ svtools/source/filter.vcl/ixpm/xpmread.cxx | 702 ------ svtools/source/filter.vcl/jpeg/jpeg.cxx | 779 ------- svtools/source/filter.vcl/jpeg/jpeg.h | 71 - svtools/source/filter.vcl/jpeg/jpegc.c | 284 --- svtools/source/filter.vcl/wmf/emfwr.cxx | 1415 ------------ svtools/source/filter.vcl/wmf/emfwr.hxx | 100 - svtools/source/filter.vcl/wmf/enhwmf.cxx | 1343 ------------ svtools/source/filter.vcl/wmf/winmtf.cxx | 2203 ------------------- svtools/source/filter.vcl/wmf/winmtf.hxx | 777 ------- svtools/source/filter.vcl/wmf/winwmf.cxx | 1431 ------------- svtools/source/filter.vcl/wmf/wmf.cxx | 114 - svtools/source/filter.vcl/wmf/wmfwr.cxx | 2096 ------------------ svtools/source/filter.vcl/wmf/wmfwr.hxx | 229 -- svtools/source/filter/FilterConfigCache.cxx | 597 ++++++ svtools/source/filter/FilterConfigCache.hxx | 145 ++ svtools/source/filter/FilterConfigItem.cxx | 623 ++++++ svtools/source/filter/SvFilterOptionsDialog.cxx | 270 +++ svtools/source/filter/SvFilterOptionsDialog.hxx | 105 + svtools/source/filter/exportdialog.cxx | 1513 +++++++++++++ svtools/source/filter/exportdialog.hrc | 99 + svtools/source/filter/exportdialog.hxx | 216 ++ svtools/source/filter/exportdialog.src | 529 +++++ svtools/source/filter/filter.cxx | 2260 ++++++++++++++++++++ svtools/source/filter/filter2.cxx | 1354 ++++++++++++ svtools/source/filter/igif/decode.cxx | 215 ++ svtools/source/filter/igif/decode.hxx | 68 + svtools/source/filter/igif/gifread.cxx | 858 ++++++++ svtools/source/filter/ixbm/xbmread.cxx | 398 ++++ svtools/source/filter/ixpm/rgbtable.hxx | 695 ++++++ svtools/source/filter/ixpm/xpmread.cxx | 702 ++++++ svtools/source/filter/jpeg/jpeg.cxx | 779 +++++++ svtools/source/filter/jpeg/jpeg.h | 71 + svtools/source/filter/jpeg/jpegc.c | 284 +++ svtools/source/filter/sgf.ini | 118 + svtools/source/filter/sgfbram.cxx | 662 ++++++ svtools/source/filter/sgvmain.cxx | 1130 ++++++++++ svtools/source/filter/sgvspln.cxx | 890 ++++++++ svtools/source/filter/sgvtext.cxx | 1334 ++++++++++++ svtools/source/filter/wmf/emfwr.cxx | 1436 +++++++++++++ svtools/source/filter/wmf/emfwr.hxx | 100 + svtools/source/filter/wmf/enhwmf.cxx | 1343 ++++++++++++ svtools/source/filter/wmf/winmtf.cxx | 2203 +++++++++++++++++++ svtools/source/filter/wmf/winmtf.hxx | 777 +++++++ svtools/source/filter/wmf/winwmf.cxx | 1431 +++++++++++++ svtools/source/filter/wmf/wmf.cxx | 114 + svtools/source/filter/wmf/wmfwr.cxx | 2124 ++++++++++++++++++ svtools/source/filter/wmf/wmfwr.hxx | 229 ++ 68 files changed, 25672 insertions(+), 25546 deletions(-) delete mode 100644 svtools/source/filter.vcl/filter/FilterConfigCache.cxx delete mode 100644 svtools/source/filter.vcl/filter/FilterConfigCache.hxx delete mode 100644 svtools/source/filter.vcl/filter/FilterConfigItem.cxx delete mode 100644 svtools/source/filter.vcl/filter/SvFilterOptionsDialog.cxx delete mode 100644 svtools/source/filter.vcl/filter/SvFilterOptionsDialog.hxx delete mode 100644 svtools/source/filter.vcl/filter/exportdialog.cxx delete mode 100755 svtools/source/filter.vcl/filter/exportdialog.hrc delete mode 100755 svtools/source/filter.vcl/filter/exportdialog.hxx delete mode 100644 svtools/source/filter.vcl/filter/exportdialog.src delete mode 100644 svtools/source/filter.vcl/filter/filter.cxx delete mode 100644 svtools/source/filter.vcl/filter/filter2.cxx delete mode 100644 svtools/source/filter.vcl/filter/sgf.ini delete mode 100644 svtools/source/filter.vcl/filter/sgfbram.cxx delete mode 100644 svtools/source/filter.vcl/filter/sgvmain.cxx delete mode 100644 svtools/source/filter.vcl/filter/sgvspln.cxx delete mode 100644 svtools/source/filter.vcl/filter/sgvtext.cxx delete mode 100644 svtools/source/filter.vcl/igif/decode.cxx delete mode 100644 svtools/source/filter.vcl/igif/decode.hxx delete mode 100644 svtools/source/filter.vcl/igif/gifread.cxx delete mode 100644 svtools/source/filter.vcl/ixbm/xbmread.cxx delete mode 100644 svtools/source/filter.vcl/ixpm/rgbtable.hxx delete mode 100644 svtools/source/filter.vcl/ixpm/xpmread.cxx delete mode 100644 svtools/source/filter.vcl/jpeg/jpeg.cxx delete mode 100644 svtools/source/filter.vcl/jpeg/jpeg.h delete mode 100644 svtools/source/filter.vcl/jpeg/jpegc.c delete mode 100644 svtools/source/filter.vcl/wmf/emfwr.cxx delete mode 100644 svtools/source/filter.vcl/wmf/emfwr.hxx delete mode 100644 svtools/source/filter.vcl/wmf/enhwmf.cxx delete mode 100644 svtools/source/filter.vcl/wmf/winmtf.cxx delete mode 100644 svtools/source/filter.vcl/wmf/winmtf.hxx delete mode 100644 svtools/source/filter.vcl/wmf/winwmf.cxx delete mode 100644 svtools/source/filter.vcl/wmf/wmf.cxx delete mode 100644 svtools/source/filter.vcl/wmf/wmfwr.cxx delete mode 100644 svtools/source/filter.vcl/wmf/wmfwr.hxx create mode 100644 svtools/source/filter/FilterConfigCache.cxx create mode 100644 svtools/source/filter/FilterConfigCache.hxx create mode 100644 svtools/source/filter/FilterConfigItem.cxx create mode 100644 svtools/source/filter/SvFilterOptionsDialog.cxx create mode 100644 svtools/source/filter/SvFilterOptionsDialog.hxx create mode 100644 svtools/source/filter/exportdialog.cxx create mode 100644 svtools/source/filter/exportdialog.hrc create mode 100644 svtools/source/filter/exportdialog.hxx create mode 100644 svtools/source/filter/exportdialog.src create mode 100644 svtools/source/filter/filter.cxx create mode 100644 svtools/source/filter/filter2.cxx create mode 100644 svtools/source/filter/igif/decode.cxx create mode 100644 svtools/source/filter/igif/decode.hxx create mode 100644 svtools/source/filter/igif/gifread.cxx create mode 100644 svtools/source/filter/ixbm/xbmread.cxx create mode 100644 svtools/source/filter/ixpm/rgbtable.hxx create mode 100644 svtools/source/filter/ixpm/xpmread.cxx create mode 100644 svtools/source/filter/jpeg/jpeg.cxx create mode 100644 svtools/source/filter/jpeg/jpeg.h create mode 100644 svtools/source/filter/jpeg/jpegc.c create mode 100644 svtools/source/filter/sgf.ini create mode 100644 svtools/source/filter/sgfbram.cxx create mode 100644 svtools/source/filter/sgvmain.cxx create mode 100644 svtools/source/filter/sgvspln.cxx create mode 100644 svtools/source/filter/sgvtext.cxx create mode 100644 svtools/source/filter/wmf/emfwr.cxx create mode 100644 svtools/source/filter/wmf/emfwr.hxx create mode 100644 svtools/source/filter/wmf/enhwmf.cxx create mode 100644 svtools/source/filter/wmf/winmtf.cxx create mode 100644 svtools/source/filter/wmf/winmtf.hxx create mode 100644 svtools/source/filter/wmf/winwmf.cxx create mode 100644 svtools/source/filter/wmf/wmf.cxx create mode 100644 svtools/source/filter/wmf/wmfwr.cxx create mode 100644 svtools/source/filter/wmf/wmfwr.hxx (limited to 'svtools') diff --git a/svtools/source/filter.vcl/filter/FilterConfigCache.cxx b/svtools/source/filter.vcl/filter/FilterConfigCache.cxx deleted file mode 100644 index 48408609cf98..000000000000 --- a/svtools/source/filter.vcl/filter/FilterConfigCache.cxx +++ /dev/null @@ -1,596 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" -#include "FilterConfigCache.hxx" -#include -#include -#include -#include -#include -#include -#include - -#define TOKEN_COUNT_FOR_OWN_FILTER 3 -// #define TOKEN_INDEX_FOR_IDENT 0 -#define TOKEN_INDEX_FOR_FILTER 1 -// #define TOKEN_INDEX_FOR_HASDIALOG 2 - -using namespace ::com::sun::star::lang ; // XMultiServiceFactory -using namespace ::com::sun::star::container ; // XNameAccess -using namespace ::com::sun::star::uno ; // Reference -using namespace ::com::sun::star::beans ; // PropertyValue -using namespace ::utl ; // getProcessServiceFactory(); -using ::rtl::OUString; - -const char* FilterConfigCache::FilterConfigCacheEntry::InternalPixelFilterNameList[] = -{ - IMP_BMP, IMP_GIF, IMP_PNG,IMP_JPEG, IMP_XBM, IMP_XPM, - EXP_BMP, EXP_JPEG, EXP_PNG, NULL -}; - -const char* FilterConfigCache::FilterConfigCacheEntry::InternalVectorFilterNameList[] = -{ - IMP_SVMETAFILE, IMP_WMF, IMP_EMF, IMP_SVSGF, IMP_SVSGV, - EXP_SVMETAFILE, EXP_WMF, EXP_EMF, EXP_SVG, NULL -}; - -const char* FilterConfigCache::FilterConfigCacheEntry::ExternalPixelFilterNameList[] = -{ - "egi", "icd", "ipd", "ipx", "ipb", "epb", "epg", - "epp", "ira", "era", "itg", "iti", "eti", "exp", NULL -}; - -sal_Bool FilterConfigCache::FilterConfigCacheEntry::IsValid() -{ - return sFilterName.Len() != 0; -} - -sal_Bool FilterConfigCache::bInitialized = sal_False; -sal_Int32 FilterConfigCache::nIndType = -1; -sal_Int32 FilterConfigCache::nIndUIName = -1; -sal_Int32 FilterConfigCache::nIndDocumentService = -1; -sal_Int32 FilterConfigCache::nIndFilterService = -1; -sal_Int32 FilterConfigCache::nIndFlags = -1; -sal_Int32 FilterConfigCache::nIndUserData = -1; -sal_Int32 FilterConfigCache::nIndFileFormatVersion = -1; -sal_Int32 FilterConfigCache::nIndTemplateName = -1; - -sal_Bool FilterConfigCache::FilterConfigCacheEntry::CreateFilterName( const OUString& rUserDataEntry ) -{ - bIsPixelFormat = bIsInternalFilter = sal_False; - sFilterName = String( rUserDataEntry ); - const char** pPtr; - for ( pPtr = InternalPixelFilterNameList; *pPtr && ( bIsInternalFilter == sal_False ); pPtr++ ) - { - if ( sFilterName.EqualsIgnoreCaseAscii( *pPtr ) ) - { - bIsInternalFilter = sal_True; - bIsPixelFormat = sal_True; - } - } - for ( pPtr = InternalVectorFilterNameList; *pPtr && ( bIsInternalFilter == sal_False ); pPtr++ ) - { - if ( sFilterName.EqualsIgnoreCaseAscii( *pPtr ) ) - bIsInternalFilter = sal_True; - } - if ( !bIsInternalFilter ) - { - for ( pPtr = ExternalPixelFilterNameList; *pPtr && ( bIsPixelFormat == sal_False ); pPtr++ ) - { - if ( sFilterName.EqualsIgnoreCaseAscii( *pPtr ) ) - bIsPixelFormat = sal_True; - } - String aTemp( OUString::createFromAscii( SVLIBRARY( "?" ) ) ); - xub_StrLen nIndex = aTemp.Search( (sal_Unicode)'?' ); - aTemp.Replace( nIndex, 1, sFilterName ); - sFilterName = aTemp; - } - return sFilterName.Len() != 0; -} - -String FilterConfigCache::FilterConfigCacheEntry::GetShortName() -{ - String aShortName; - if ( lExtensionList.getLength() ) - { - aShortName = lExtensionList[ 0 ]; - if ( aShortName.SearchAscii( "*.", 0 ) == 0 ) - aShortName.Erase( 0, 2 ); - } - return aShortName; -} - -/** helper to open the configuration root of the underlying - config package - - @param sPackage - specify, which config package should be opened. - Must be one of the defined static values TYPEPKG or FILTERPKG. - - @return A valid object if open was successfull. The access on opened - data will be readonly. It returns NULL in case open failed. - - @throws It let pass RuntimeExceptions only. - */ -Reference< XInterface > openConfig(const char* sPackage) - throw(RuntimeException) -{ - static OUString TYPEPKG( RTL_CONSTASCII_USTRINGPARAM( "types" ) ); - static OUString FILTERPKG( RTL_CONSTASCII_USTRINGPARAM( "filters" ) ); - - Reference< XMultiServiceFactory > xSMGR = getProcessServiceFactory(); - Reference< XInterface > xCfg; - try - { - // get access to config API (not to file!) - Reference< XMultiServiceFactory > xConfigProvider( xSMGR->createInstance( - OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")), UNO_QUERY); - - if (xConfigProvider.is()) - { - Sequence< Any > lParams(1); - PropertyValue aParam ; - - // define cfg path for open - aParam.Name = OUString::createFromAscii("nodepath"); - if (TYPEPKG.equalsIgnoreAsciiCaseAscii(sPackage)) - aParam.Value <<= OUString::createFromAscii("/org.openoffice.TypeDetection.Types/Types"); - if (FILTERPKG.equalsIgnoreAsciiCaseAscii(sPackage)) - aParam.Value <<= OUString::createFromAscii("/org.openoffice.TypeDetection.GraphicFilter/Filters"); - lParams[0] = makeAny(aParam); - - // get access to file - xCfg = xConfigProvider->createInstanceWithArguments( - OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess"), lParams); - } - } - catch(const RuntimeException&) - { throw; } - catch(const Exception&) - { xCfg.clear(); } - - return xCfg; -} - -void FilterConfigCache::ImplInit() -{ - static OUString STYPE ( RTL_CONSTASCII_USTRINGPARAM( "Type" ) ); - static OUString SUINAME ( RTL_CONSTASCII_USTRINGPARAM( "UIName" ) ); - static OUString SDOCUMENTSERVICE ( RTL_CONSTASCII_USTRINGPARAM( "DocumentService" ) ); - static OUString SFILTERSERVICE ( RTL_CONSTASCII_USTRINGPARAM( "FilterService" ) ); - static OUString STEMPLATENAME ( RTL_CONSTASCII_USTRINGPARAM( "TemplateName" ) ); - static OUString SFILEFORMATVERSION ( RTL_CONSTASCII_USTRINGPARAM( "FileFormatVersion" ) ); - static OUString SUICOMPONENT ( RTL_CONSTASCII_USTRINGPARAM( "UIComponent" ) ); - static OUString SFLAGS ( RTL_CONSTASCII_USTRINGPARAM( "Flags" ) ); - static OUString SUSERDATA ( RTL_CONSTASCII_USTRINGPARAM( "UserData" ) ); - static OUString SMEDIATYPE ( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); - static OUString SEXTENSIONS ( RTL_CONSTASCII_USTRINGPARAM( "Extensions" ) ); - static OUString SFORMATNAME ( RTL_CONSTASCII_USTRINGPARAM( "FormatName" ) ); - static OUString SREALFILTERNAME ( RTL_CONSTASCII_USTRINGPARAM( "RealFilterName" ) ); - - // get access to config - Reference< XNameAccess > xTypeAccess ( openConfig("types" ), UNO_QUERY ); - Reference< XNameAccess > xFilterAccess( openConfig("filters"), UNO_QUERY ); - - if ( xTypeAccess.is() && xFilterAccess.is() ) - { - Sequence< OUString > lAllFilter = xFilterAccess->getElementNames(); - sal_Int32 nAllFilterCount = lAllFilter.getLength(); - - for ( sal_Int32 i = 0; i < nAllFilterCount; i++ ) - { - OUString sInternalFilterName = lAllFilter[ i ]; - Reference< XPropertySet > xFilterSet; - xFilterAccess->getByName( sInternalFilterName ) >>= xFilterSet; - if (!xFilterSet.is()) - continue; - - FilterConfigCacheEntry aEntry; - - aEntry.sInternalFilterName = sInternalFilterName; - xFilterSet->getPropertyValue(STYPE) >>= aEntry.sType; - xFilterSet->getPropertyValue(SUINAME) >>= aEntry.sUIName; - xFilterSet->getPropertyValue(SREALFILTERNAME) >>= aEntry.sFilterType; - Sequence< OUString > lFlags; - xFilterSet->getPropertyValue(SFLAGS) >>= lFlags; - if (lFlags.getLength()!=1 || !lFlags[0].getLength()) - continue; - if (lFlags[0].equalsIgnoreAsciiCaseAscii("import")) - aEntry.nFlags = 1; - else - if (lFlags[0].equalsIgnoreAsciiCaseAscii("export")) - aEntry.nFlags = 2; - - OUString sUIComponent; - xFilterSet->getPropertyValue(SUICOMPONENT) >>= sUIComponent; - aEntry.bHasDialog = sUIComponent.getLength(); - - ::rtl::OUString sFormatName; - xFilterSet->getPropertyValue(SFORMATNAME) >>= sFormatName; - aEntry.CreateFilterName( sFormatName ); - - Reference< XPropertySet > xTypeSet; - xTypeAccess->getByName( aEntry.sType ) >>= xTypeSet; - if (!xTypeSet.is()) - continue; - - xTypeSet->getPropertyValue(SMEDIATYPE) >>= aEntry.sMediaType; - xTypeSet->getPropertyValue(SEXTENSIONS) >>= aEntry.lExtensionList; - - // The first extension will be used - // to generate our internal FilterType ( BMP, WMF ... ) - String aExtension( aEntry.GetShortName() ); - if (aExtension.Len() != 3) - continue; - - if ( aEntry.nFlags & 1 ) - aImport.push_back( aEntry ); - if ( aEntry.nFlags & 2 ) - aExport.push_back( aEntry ); - - // bFilterEntryCreated!? - if (!( aEntry.nFlags & 3 )) - continue; //? Entry was already inserted ... but following code will be supressed?! - } - } -}; - -const char* FilterConfigCache::InternalFilterListForSvxLight[] = -{ - "bmp","1","SVBMP", - "bmp","2","SVBMP", - "dxf","1","idx", - "eps","1","ips", - "eps","2","eps", - "gif","1","SVIGIF", - "gif","2","egi", - "jpg","1","SVIJPEG", - "jpg","2","SVEJPEG", - "sgv","1","SVSGV", - "sgf","1","SVSGF", - "met","1","ime", - "met","2","eme", - "png","1","SVIPNG", - "png","2","SVEPNG", - "pct","1","ipt", - "pct","2","ept", - "pcd","1","icd", - "psd","1","ipd", - "pcx","1","ipx", - "pbm","1","ipb", - "pbm","2","epb", - "pgm","1","ipb", - "pgm","2","epg", - "ppm","1","ipb", - "ppm","2","epp", - "ras","1","ira", - "ras","2","era", - "svm","1","SVMETAFILE", - "svm","2","SVMETAFILE", - "tga","1","itg", - "tif","1","iti", - "tif","2","eti", - "emf","1","SVEMF", - "emf","2","SVEMF", - "wmf","1","SVWMF", - "wmf","2","SVWMF", - "xbm","1","SVIXBM", - "xpm","1","SVIXPM", - "xpm","2","exp", - "svg","2","SVESVG", - NULL -}; - -void FilterConfigCache::ImplInitSmart() -{ - const char** pPtr; - for ( pPtr = InternalFilterListForSvxLight; *pPtr; pPtr++ ) - { - FilterConfigCacheEntry aEntry; - - OUString sExtension( OUString::createFromAscii( *pPtr++ ) ); - - aEntry.lExtensionList.realloc( 1 ); - aEntry.lExtensionList[ 0 ] = sExtension; - - aEntry.sType = sExtension; - aEntry.sUIName = sExtension; - - ByteString sFlags( *pPtr++ ); - aEntry.nFlags = sFlags.ToInt32(); - - OUString sUserData( OUString::createFromAscii( *pPtr ) ); - aEntry.CreateFilterName( sUserData ); - - if ( aEntry.nFlags & 1 ) - aImport.push_back( aEntry ); - if ( aEntry.nFlags & 2 ) - aExport.push_back( aEntry ); - } -} - -// ------------------------------------------------------------------------ - -FilterConfigCache::FilterConfigCache( sal_Bool bConfig ) : - bUseConfig ( bConfig ) -{ - if ( bUseConfig ) - ImplInit(); - else - ImplInitSmart(); -} - -FilterConfigCache::~FilterConfigCache() -{ - -} - -String FilterConfigCache::GetImportFilterName( sal_uInt16 nFormat ) -{ - if( nFormat < aImport.size() ) - return aImport[ nFormat ].sFilterName; - return String::EmptyString(); -} - -sal_uInt16 FilterConfigCache::GetImportFormatNumber( const String& rFormatName ) -{ - CacheVector::iterator aIter( aImport.begin() ); - while ( aIter != aImport.end() ) - { - if ( aIter->sUIName.equalsIgnoreAsciiCase( rFormatName ) ) - break; - aIter++; - } - return sal::static_int_cast< sal_uInt16 >(aIter == aImport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aImport.begin()); -} - -sal_uInt16 FilterConfigCache::GetImportFormatNumberForMediaType( const String& rMediaType ) -{ - CacheVector::iterator aIter( aImport.begin() ); - while ( aIter != aImport.end() ) - { - if ( aIter->sMediaType.equalsIgnoreAsciiCase( rMediaType ) ) - break; - aIter++; - } - return sal::static_int_cast< sal_uInt16 >(aIter == aImport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aImport.begin()); -} - -sal_uInt16 FilterConfigCache::GetImportFormatNumberForShortName( const String& rShortName ) -{ - CacheVector::iterator aIter( aImport.begin() ); - while ( aIter != aImport.end() ) - { - if ( aIter->GetShortName().EqualsIgnoreCaseAscii( rShortName ) ) - break; - aIter++; - } - return sal::static_int_cast< sal_uInt16 >(aIter == aImport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aImport.begin()); -} - -sal_uInt16 FilterConfigCache::GetImportFormatNumberForTypeName( const String& rType ) -{ - CacheVector::iterator aIter( aImport.begin() ); - while ( aIter != aImport.end() ) - { - if ( aIter->sType.equalsIgnoreAsciiCase( rType ) ) - break; - aIter++; - } - return sal::static_int_cast< sal_uInt16 >(aIter == aImport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aImport.begin()); -} - -String FilterConfigCache::GetImportFormatName( sal_uInt16 nFormat ) -{ - if( nFormat < aImport.size() ) - return aImport[ nFormat ].sUIName; - return String::EmptyString(); -} - -String FilterConfigCache::GetImportFormatMediaType( sal_uInt16 nFormat ) -{ - if( nFormat < aImport.size() ) - return aImport[ nFormat ].sMediaType; - return String::EmptyString(); -} - -String FilterConfigCache::GetImportFormatShortName( sal_uInt16 nFormat ) -{ - if( nFormat < aImport.size() ) - return aImport[ nFormat ].GetShortName(); - return String::EmptyString(); -} - -String FilterConfigCache::GetImportFormatExtension( sal_uInt16 nFormat, sal_Int32 nEntry ) -{ - if ( (nFormat < aImport.size()) && (nEntry < aImport[ nFormat ].lExtensionList.getLength()) ) - return aImport[ nFormat ].lExtensionList[ nEntry ]; - return String::EmptyString(); -} - -String FilterConfigCache::GetImportFilterType( sal_uInt16 nFormat ) -{ - if( nFormat < aImport.size() ) - return aImport[ nFormat ].sType; - return String::EmptyString(); -} - -String FilterConfigCache::GetImportFilterTypeName( sal_uInt16 nFormat ) -{ - if( nFormat < aImport.size() ) - return aImport[ nFormat ].sFilterType; - return String::EmptyString(); -} - -String FilterConfigCache::GetImportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry ) -{ - String aWildcard( GetImportFormatExtension( nFormat, nEntry ) ); - if ( aWildcard.Len() ) - aWildcard.Insert( UniString::CreateFromAscii( "*.", 2 ), 0 ); - return aWildcard; -} - -sal_Bool FilterConfigCache::IsImportInternalFilter( sal_uInt16 nFormat ) -{ - return (nFormat < aImport.size()) && aImport[ nFormat ].bIsInternalFilter; -} - -sal_Bool FilterConfigCache::IsImportPixelFormat( sal_uInt16 nFormat ) -{ - return (nFormat < aImport.size()) && aImport[ nFormat ].bIsPixelFormat; -} - -sal_Bool FilterConfigCache::IsImportDialog( sal_uInt16 nFormat ) -{ - return (nFormat < aImport.size()) && aImport[ nFormat ].bHasDialog; -} - -// ------------------------------------------------------------------------ - -String FilterConfigCache::GetExportFilterName( sal_uInt16 nFormat ) -{ - if( nFormat < aExport.size() ) - return aExport[ nFormat ].sFilterName; - return String::EmptyString(); -} - -sal_uInt16 FilterConfigCache::GetExportFormatNumber( const String& rFormatName ) -{ - CacheVector::iterator aIter( aExport.begin() ); - while ( aIter != aExport.end() ) - { - if ( aIter->sUIName.equalsIgnoreAsciiCase( rFormatName ) ) - break; - aIter++; - } - return sal::static_int_cast< sal_uInt16 >(aIter == aExport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aExport.begin()); -} - -sal_uInt16 FilterConfigCache::GetExportFormatNumberForMediaType( const String& rMediaType ) -{ - CacheVector::iterator aIter( aExport.begin() ); - while ( aIter != aExport.end() ) - { - if ( aIter->sMediaType.equalsIgnoreAsciiCase( rMediaType ) ) - break; - aIter++; - } - return sal::static_int_cast< sal_uInt16 >(aIter == aExport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aExport.begin()); -} - -sal_uInt16 FilterConfigCache::GetExportFormatNumberForShortName( const String& rShortName ) -{ - CacheVector::iterator aIter( aExport.begin() ); - while ( aIter != aExport.end() ) - { - if ( aIter->GetShortName().EqualsIgnoreCaseAscii( rShortName ) ) - break; - aIter++; - } - return sal::static_int_cast< sal_uInt16 >(aIter == aExport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aExport.begin()); -} - -sal_uInt16 FilterConfigCache::GetExportFormatNumberForTypeName( const String& rType ) -{ - CacheVector::iterator aIter( aExport.begin() ); - while ( aIter != aExport.end() ) - { - if ( aIter->sType.equalsIgnoreAsciiCase( rType ) ) - break; - aIter++; - } - return sal::static_int_cast< sal_uInt16 >(aIter == aExport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aExport.begin()); -} - -String FilterConfigCache::GetExportFormatName( sal_uInt16 nFormat ) -{ - if( nFormat < aExport.size() ) - return aExport[ nFormat ].sUIName; - return String::EmptyString(); -} - -String FilterConfigCache::GetExportFormatMediaType( sal_uInt16 nFormat ) -{ - if( nFormat < aExport.size() ) - return aExport[ nFormat ].sMediaType; - return String::EmptyString(); -} - -String FilterConfigCache::GetExportFormatShortName( sal_uInt16 nFormat ) -{ - if( nFormat < aExport.size() ) - return aExport[ nFormat ].GetShortName(); - return String::EmptyString(); -} - -String FilterConfigCache::GetExportFormatExtension( sal_uInt16 nFormat, sal_Int32 nEntry ) -{ - if ( (nFormat < aExport.size()) && (nEntry < aExport[ nFormat ].lExtensionList.getLength()) ) - return aExport[ nFormat ].lExtensionList[ nEntry ]; - return String::EmptyString(); -} - -String FilterConfigCache::GetExportFilterTypeName( sal_uInt16 nFormat ) -{ - if( nFormat < aExport.size() ) - return aExport[ nFormat ].sFilterType; - return String::EmptyString(); -} - -String FilterConfigCache::GetExportInternalFilterName( sal_uInt16 nFormat ) -{ - if( nFormat < aExport.size() ) - return aExport[ nFormat ].sInternalFilterName; - return String::EmptyString(); -} - -String FilterConfigCache::GetExportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry ) -{ - String aWildcard( GetExportFormatExtension( nFormat, nEntry ) ); - if ( aWildcard.Len() ) - aWildcard.Insert( UniString::CreateFromAscii( "*.", 2 ), 0 ); - return aWildcard; -} - -sal_Bool FilterConfigCache::IsExportInternalFilter( sal_uInt16 nFormat ) -{ - return (nFormat < aExport.size()) && aExport[ nFormat ].bIsInternalFilter; -} - -sal_Bool FilterConfigCache::IsExportPixelFormat( sal_uInt16 nFormat ) -{ - return (nFormat < aExport.size()) && aExport[ nFormat ].bIsPixelFormat; -} - -sal_Bool FilterConfigCache::IsExportDialog( sal_uInt16 nFormat ) -{ - return (nFormat < aExport.size()) && aExport[ nFormat ].bHasDialog; -} - -// ------------------------------------------------------------------------ diff --git a/svtools/source/filter.vcl/filter/FilterConfigCache.hxx b/svtools/source/filter.vcl/filter/FilterConfigCache.hxx deleted file mode 100644 index 2c6b7361e540..000000000000 --- a/svtools/source/filter.vcl/filter/FilterConfigCache.hxx +++ /dev/null @@ -1,145 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - - -#ifndef _FILTER_CONFIG_CACHE_HXX_ -#define _FILTER_CONFIG_CACHE_HXX_ - -#include "svtools/svtdllapi.h" -#include -#include -#include -#include -#include - -#ifndef INCLUDED_VECTOR -#include -#define INCLUDED_VECTOR -#endif - -class SVT_DLLPUBLIC FilterConfigCache -{ - struct FilterConfigCacheEntry - { - ::rtl::OUString sInternalFilterName; - ::rtl::OUString sType; - ::com::sun::star::uno::Sequence< ::rtl::OUString > lExtensionList; - ::rtl::OUString sUIName; - ::rtl::OUString sDocumentService; - ::rtl::OUString sFilterService; - ::rtl::OUString sTemplateName; - - ::rtl::OUString sMediaType; - ::rtl::OUString sFilterType; - - sal_Int32 nFlags; - sal_Int32 nFileFormatVersion; - - // user data - String sFilterName; - sal_Bool bHasDialog : 1; - sal_Bool bIsInternalFilter : 1; - sal_Bool bIsPixelFormat : 1; - - sal_Bool IsValid(); - sal_Bool CreateFilterName( const ::rtl::OUString& rUserDataEntry ); - String GetShortName( ); - - static const char* InternalPixelFilterNameList[]; - static const char* InternalVectorFilterNameList[]; - static const char* ExternalPixelFilterNameList[]; - }; - - typedef std::vector< FilterConfigCacheEntry > CacheVector; - - - CacheVector aImport; - CacheVector aExport; - sal_Bool bUseConfig; - - static sal_Bool bInitialized; - static sal_Int32 nIndType; - static sal_Int32 nIndUIName; - static sal_Int32 nIndDocumentService; - static sal_Int32 nIndFilterService; - static sal_Int32 nIndFlags; - static sal_Int32 nIndUserData; - static sal_Int32 nIndFileFormatVersion; - static sal_Int32 nIndTemplateName; - - static const char* InternalFilterListForSvxLight[]; - - SVT_DLLPRIVATE void ImplInit(); - SVT_DLLPRIVATE void ImplInitSmart(); - - public : - - sal_uInt16 GetImportFormatCount() const - { return sal::static_int_cast< sal_uInt16 >(aImport.size()); }; - sal_uInt16 GetImportFormatNumber( const String& rFormatName ); - sal_uInt16 GetImportFormatNumberForMediaType( const String& rMediaType ); - sal_uInt16 GetImportFormatNumberForShortName( const String& rShortName ); - sal_uInt16 GetImportFormatNumberForTypeName( const String& rType ); - String GetImportFilterName( sal_uInt16 nFormat ); - String GetImportFormatName( sal_uInt16 nFormat ); - String GetImportFormatExtension( sal_uInt16 nFormat, sal_Int32 nEntry = 0); - String GetImportFormatMediaType( sal_uInt16 nFormat ); - String GetImportFormatShortName( sal_uInt16 nFormat ); - String GetImportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry ); - String GetImportFilterType( sal_uInt16 nFormat ); - String GetImportFilterTypeName( sal_uInt16 nFormat ); - - sal_Bool IsImportInternalFilter( sal_uInt16 nFormat ); - sal_Bool IsImportPixelFormat( sal_uInt16 nFormat ); - sal_Bool IsImportDialog( sal_uInt16 nFormat ); - - sal_uInt16 GetExportFormatCount() const - { return sal::static_int_cast< sal_uInt16 >(aExport.size()); }; - sal_uInt16 GetExportFormatNumber( const String& rFormatName ); - sal_uInt16 GetExportFormatNumberForMediaType( const String& rMediaType ); - sal_uInt16 GetExportFormatNumberForShortName( const String& rShortName ); - sal_uInt16 GetExportFormatNumberForTypeName( const String& rType ); - String GetExportFilterName( sal_uInt16 nFormat ); - String GetExportFormatName( sal_uInt16 nFormat ); - String GetExportFormatExtension( sal_uInt16 nFormat, sal_Int32 nEntry = 0 ); - String GetExportFormatMediaType( sal_uInt16 nFormat ); - String GetExportFormatShortName( sal_uInt16 nFormat ); - String GetExportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry ); - String GetExportFilterTypeName( sal_uInt16 nFormat ); - String GetExportInternalFilterName( sal_uInt16 nFormat ); - - sal_Bool IsExportInternalFilter( sal_uInt16 nFormat ); - sal_Bool IsExportPixelFormat( sal_uInt16 nFormat ); - sal_Bool IsExportDialog( sal_uInt16 nFormat ); - - FilterConfigCache( sal_Bool bUseConfig ); - ~FilterConfigCache(); - -}; - -#endif // _FILTER_CONFIG_CACHE_HXX_ - diff --git a/svtools/source/filter.vcl/filter/FilterConfigItem.cxx b/svtools/source/filter.vcl/filter/FilterConfigItem.cxx deleted file mode 100644 index 312f62af9d84..000000000000 --- a/svtools/source/filter.vcl/filter/FilterConfigItem.cxx +++ /dev/null @@ -1,623 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -using ::rtl::OUString; -using namespace ::utl ; // getProcessServiceFactory -using namespace ::com::sun::star::lang ; // XMultiServiceFactory -using namespace ::com::sun::star::beans ; // PropertyValue -using namespace ::com::sun::star::uno ; // Reference -using namespace ::com::sun::star::util ; // XChangesBatch -using namespace ::com::sun::star::awt ; // Size -using namespace ::com::sun::star::container ; // -using namespace ::com::sun::star::task ; // XStatusIndicator - -static sal_Bool ImpIsTreeAvailable( Reference< XMultiServiceFactory >& rXCfgProv, const String& rTree ) -{ - sal_Bool bAvailable = rTree.Len() != 0; - if ( bAvailable ) - { - xub_StrLen nTokenCount = rTree.GetTokenCount( (sal_Unicode)'/' ); - xub_StrLen i = 0; - - if ( rTree.GetChar( 0 ) == (sal_Unicode)'/' ) - i++; - if ( rTree.GetChar( rTree.Len() - 1 ) == (sal_Unicode)'/' ) - nTokenCount--; - - Any aAny; - aAny <<= (OUString)rTree.GetToken( i++, (sal_Unicode)'/' ); - - // creation arguments: nodepath - PropertyValue aPathArgument; - aPathArgument.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); - aPathArgument.Value = aAny; - - Sequence< Any > aArguments( 1 ); - aArguments[ 0 ] <<= aPathArgument; - - Reference< XInterface > xReadAccess; - try - { - xReadAccess = rXCfgProv->createInstanceWithArguments( - OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" ) ), - aArguments ); - } - catch ( ::com::sun::star::uno::Exception& ) - { - bAvailable = sal_False; - } - if ( xReadAccess.is() ) - { - for ( ; bAvailable && ( i < nTokenCount ); i++ ) - { - Reference< XHierarchicalNameAccess > xHierarchicalNameAccess - ( xReadAccess, UNO_QUERY ); - - if ( !xHierarchicalNameAccess.is() ) - bAvailable = sal_False; - else - { - String aNode( rTree.GetToken( i, (sal_Unicode)'/' ) ); - if ( !xHierarchicalNameAccess->hasByHierarchicalName( aNode ) ) - bAvailable = sal_False; - else - { - Any a( xHierarchicalNameAccess->getByHierarchicalName( aNode ) ); - try - { - a >>= xReadAccess; - } - catch ( ::com::sun::star::uno::Exception& ) - { - bAvailable = sal_False; - } - } - } - } - } - } - return bAvailable; -} - -void FilterConfigItem::ImpInitTree( const String& rSubTree ) -{ - bModified = sal_False; - - OUString sTree( ConfigManager::GetConfigBaseURL() ); - sTree += rSubTree; - Reference< XMultiServiceFactory > xSMGR = getProcessServiceFactory(); // get global uno service manager - - Reference< XMultiServiceFactory > xCfgProv( - xSMGR->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) ) ), - UNO_QUERY ); - - if ( xCfgProv.is() ) - { - if ( ImpIsTreeAvailable( xCfgProv, String( sTree ) ) ) - { - Any aAny; - // creation arguments: nodepath - PropertyValue aPathArgument; - aAny <<= sTree; - aPathArgument.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); - aPathArgument.Value = aAny; - - // creation arguments: commit mode - PropertyValue aModeArgument; - sal_Bool bAsyncron = sal_True; - aAny <<= bAsyncron; - aModeArgument.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "lazywrite" ) ); - aModeArgument.Value = aAny; - - Sequence< Any > aArguments( 2 ); - aArguments[ 0 ] <<= aPathArgument; - aArguments[ 1 ] <<= aModeArgument; - - try - { - xUpdatableView = xCfgProv->createInstanceWithArguments( - OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationUpdateAccess" ) ), - aArguments ); - if ( xUpdatableView.is() ) - xPropSet = Reference< XPropertySet >( xUpdatableView, UNO_QUERY ); - } - catch ( ::com::sun::star::uno::Exception& ) - { - DBG_ERROR( "FilterConfigItem::FilterConfigItem - Could not access configuration Key" ); - } - } - } -} - -FilterConfigItem::FilterConfigItem( const OUString& rSubTree ) -{ - ImpInitTree( rSubTree ); -} - -FilterConfigItem::FilterConfigItem( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >* pFilterData ) -{ - if ( pFilterData ) - aFilterData = *pFilterData; -} - -FilterConfigItem::FilterConfigItem( const OUString& rSubTree, - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >* pFilterData ) -{ - ImpInitTree( rSubTree ); - - if ( pFilterData ) - aFilterData = *pFilterData; -}; - -FilterConfigItem::~FilterConfigItem() -{ - if ( xUpdatableView.is() ) - { - if ( xPropSet.is() && bModified ) - { - Reference< XChangesBatch > xUpdateControl( xUpdatableView, UNO_QUERY ); - if ( xUpdateControl.is() ) - { - try - { - xUpdateControl->commitChanges(); - } - catch ( ::com::sun::star::uno::Exception& ) - { - DBG_ERROR( "FilterConfigItem::FilterConfigItem - Could not update configuration data" ); - } - } - } - } -} - -sal_Bool FilterConfigItem::ImplGetPropertyValue( Any& rAny, const Reference< XPropertySet >& rXPropSet, const OUString& rString, sal_Bool bTestPropertyAvailability ) -{ - sal_Bool bRetValue = sal_True; - - if ( rXPropSet.is() ) - { - if ( bTestPropertyAvailability ) - { - bRetValue = sal_False; - try - { - Reference< XPropertySetInfo > - aXPropSetInfo( rXPropSet->getPropertySetInfo() ); - if ( aXPropSetInfo.is() ) - bRetValue = aXPropSetInfo->hasPropertyByName( rString ); - } - catch( ::com::sun::star::uno::Exception& ) - { - // - } - } - if ( bRetValue ) - { - try - { - rAny = rXPropSet->getPropertyValue( rString ); - if ( !rAny.hasValue() ) - bRetValue = sal_False; - } - catch( ::com::sun::star::uno::Exception& ) - { - bRetValue = sal_False; - } - } - } - else - bRetValue = sal_False; - return bRetValue; -} - - -// if property is available it returns a pointer, -// otherwise the result is null -PropertyValue* FilterConfigItem::GetPropertyValue( Sequence< PropertyValue >& rPropSeq, const OUString& rName ) -{ - PropertyValue* pPropValue = NULL; - - sal_Int32 i, nCount; - for ( i = 0, nCount = rPropSeq.getLength(); i < nCount; i++ ) - { - if ( rPropSeq[ i ].Name == rName ) - { - pPropValue = &rPropSeq[ i ]; - break; - } - } - return pPropValue; -} - -/* if PropertySequence already includes a PropertyValue using the same name, the - corresponding PropertyValue is replaced, otherwise the given PropertyValue - will be appended */ - -sal_Bool FilterConfigItem::WritePropertyValue( Sequence< PropertyValue >& rPropSeq, const PropertyValue& rPropValue ) -{ - sal_Bool bRet = sal_False; - if ( rPropValue.Name.getLength() ) - { - sal_Int32 i, nCount; - for ( i = 0, nCount = rPropSeq.getLength(); i < nCount; i++ ) - { - if ( rPropSeq[ i ].Name == rPropValue.Name ) - break; - } - if ( i == nCount ) - rPropSeq.realloc( ++nCount ); - - rPropSeq[ i ] = rPropValue; - - bRet = sal_True; - } - return bRet; -} - -sal_Bool FilterConfigItem::ReadBool( const OUString& rKey, sal_Bool bDefault ) -{ - Any aAny; - sal_Bool bRetValue = bDefault; - PropertyValue* pPropVal = GetPropertyValue( aFilterData, rKey ); - if ( pPropVal ) - { - pPropVal->Value >>= bRetValue; - } - else if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) - { - aAny >>= bRetValue; - } - PropertyValue aBool; - aBool.Name = rKey; - aBool.Value <<= bRetValue; - WritePropertyValue( aFilterData, aBool ); - return bRetValue; -} - -sal_Int32 FilterConfigItem::ReadInt32( const OUString& rKey, sal_Int32 nDefault ) -{ - Any aAny; - sal_Int32 nRetValue = nDefault; - PropertyValue* pPropVal = GetPropertyValue( aFilterData, rKey ); - if ( pPropVal ) - { - pPropVal->Value >>= nRetValue; - } - else if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) - { - aAny >>= nRetValue; - } - PropertyValue aInt32; - aInt32.Name = rKey; - aInt32.Value <<= nRetValue; - WritePropertyValue( aFilterData, aInt32 ); - return nRetValue; -} - - -Size FilterConfigItem::ReadSize( const OUString& rKey, const Size& rDefault ) -{ - Any aAny; - Size aRetValue( rDefault ); - - const OUString sWidth( RTL_CONSTASCII_USTRINGPARAM( "LogicalWidth" ) ); - const OUString sHeight( RTL_CONSTASCII_USTRINGPARAM( "LogicalHeight" ) ); - - Reference< XPropertySet > aXPropSet; - try - { - PropertyValue* pPropWidth = GetPropertyValue( aFilterData, sWidth ); - PropertyValue* pPropHeight= GetPropertyValue( aFilterData, sHeight ); - if ( pPropWidth && pPropHeight ) - { - pPropWidth->Value >>= aRetValue.Width; - pPropHeight->Value >>= aRetValue.Height; - } - else if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) - { - if ( aAny >>= aXPropSet ) - { - if ( ImplGetPropertyValue( aAny, aXPropSet, sWidth, sal_True ) ) - aAny >>= aRetValue.Width; - if ( ImplGetPropertyValue( aAny, aXPropSet, sHeight, sal_True ) ) - aAny >>= aRetValue.Height; - } - } - } - catch ( ::com::sun::star::uno::Exception& ) - { - DBG_ERROR( "FilterConfigItem::ReadSize - could not read PropertyValue" ); - } - PropertyValue aWidth; - aWidth.Name = sWidth; - aWidth.Value <<= aRetValue.Width; - WritePropertyValue( aFilterData, aWidth ); - PropertyValue aHeight; - aHeight.Name = sHeight; - aHeight.Value <<= aRetValue.Height; - WritePropertyValue( aFilterData, aHeight ); - return aRetValue; -} - -OUString FilterConfigItem::ReadString( const OUString& rKey, const OUString& rDefault ) -{ - Any aAny; - OUString aRetValue( rDefault ); - PropertyValue* pPropVal = GetPropertyValue( aFilterData, rKey ); - if ( pPropVal ) - { - pPropVal->Value >>= aRetValue; - } - else if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) - { - aAny >>= aRetValue; - } - PropertyValue aString; - aString.Name = rKey; - aString.Value <<= aRetValue; - WritePropertyValue( aFilterData, aString ); - return aRetValue; -} - -Any FilterConfigItem::ReadAny( const ::rtl::OUString& rKey, const Any& rDefault ) -{ - Any aAny, aRetValue( rDefault ); - PropertyValue* pPropVal = GetPropertyValue( aFilterData, rKey ); - if ( pPropVal ) - { - aRetValue = pPropVal->Value; - } - else if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) - { - aRetValue = aAny; - } - PropertyValue aPropValue; - aPropValue.Name = rKey; - aPropValue.Value = aRetValue; - WritePropertyValue( aFilterData, aPropValue ); - return aRetValue; -} - -void FilterConfigItem::WriteBool( const OUString& rKey, sal_Bool bNewValue ) -{ - PropertyValue aBool; - aBool.Name = rKey; - aBool.Value <<= bNewValue; - WritePropertyValue( aFilterData, aBool ); - - if ( xPropSet.is() ) - { - Any aAny; - if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) - { - sal_Bool bOldValue; - if ( aAny >>= bOldValue ) - { - if ( bOldValue != bNewValue ) - { - aAny <<= bNewValue; - try - { - xPropSet->setPropertyValue( rKey, aAny ); - bModified = sal_True; - } - catch ( ::com::sun::star::uno::Exception& ) - { - DBG_ERROR( "FilterConfigItem::WriteBool - could not set PropertyValue" ); - } - } - } - } - } -} - -void FilterConfigItem::WriteInt32( const OUString& rKey, sal_Int32 nNewValue ) -{ - PropertyValue aInt32; - aInt32.Name = rKey; - aInt32.Value <<= nNewValue; - WritePropertyValue( aFilterData, aInt32 ); - - if ( xPropSet.is() ) - { - Any aAny; - - if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) - { - sal_Int32 nOldValue; - if ( aAny >>= nOldValue ) - { - if ( nOldValue != nNewValue ) - { - aAny <<= nNewValue; - try - { - xPropSet->setPropertyValue( rKey, aAny ); - bModified = sal_True; - } - catch ( ::com::sun::star::uno::Exception& ) - { - DBG_ERROR( "FilterConfigItem::WriteInt32 - could not set PropertyValue" ); - } - } - } - } - } -} - -void FilterConfigItem::WriteSize( const OUString& rKey, const Size& rNewValue ) -{ - const OUString sWidth( RTL_CONSTASCII_USTRINGPARAM( "LogicalWidth" ) ); - const OUString sHeight( RTL_CONSTASCII_USTRINGPARAM( "LogicalHeight" ) ); - - PropertyValue aWidth; - aWidth.Name = sWidth; - aWidth.Value <<= rNewValue.Width; - WritePropertyValue( aFilterData, aWidth ); - - PropertyValue aHeight; - aHeight.Name = sHeight; - aHeight.Value <<= rNewValue.Height; - WritePropertyValue( aFilterData, aHeight ); - - if ( xPropSet.is() ) - { - Any aAny; - sal_Int32 nOldWidth = rNewValue.Width; - sal_Int32 nOldHeight = rNewValue.Height; - - if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) - { - try - { - Reference< XPropertySet > aXPropSet; - if ( aAny >>= aXPropSet ) - { - if ( ImplGetPropertyValue( aAny, aXPropSet, sWidth, sal_True ) ) - aAny >>= nOldWidth; - if ( ImplGetPropertyValue( aAny, aXPropSet, sHeight, sal_True ) ) - aAny >>= nOldHeight; - } - if ( ( nOldWidth != rNewValue.Width ) || ( nOldHeight != rNewValue.Height ) ) - { - aAny <<= rNewValue.Width; - aXPropSet->setPropertyValue( sWidth, aAny ); - aAny <<= rNewValue.Height; - aXPropSet->setPropertyValue( sHeight, aAny ); - bModified = sal_True; - } - } - catch ( ::com::sun::star::uno::Exception& ) - { - DBG_ERROR( "FilterConfigItem::WriteSize - could not read PropertyValue" ); - } - } - } -} - -void FilterConfigItem::WriteString( const OUString& rKey, const OUString& rNewValue ) -{ - PropertyValue aString; - aString.Name = rKey; - aString.Value <<= rNewValue; - WritePropertyValue( aFilterData, aString ); - - if ( xPropSet.is() ) - { - Any aAny; - - if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) - { - OUString aOldValue; - if ( aAny >>= aOldValue ) - { - if ( aOldValue != rNewValue ) - { - aAny <<= rNewValue; - try - { - xPropSet->setPropertyValue( rKey, aAny ); - bModified = sal_True; - } - catch ( ::com::sun::star::uno::Exception& ) - { - DBG_ERROR( "FilterConfigItem::WriteInt32 - could not set PropertyValue" ); - } - } - } - } - } -} - -void FilterConfigItem::WriteAny( const OUString& rKey, const Any& rNewAny ) -{ - PropertyValue aPropValue; - aPropValue.Name = rKey; - aPropValue.Value = rNewAny; - WritePropertyValue( aFilterData, aPropValue ); - if ( xPropSet.is() ) - { - Any aAny; - if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) - { - if ( aAny != rNewAny ) - { - try - { - xPropSet->setPropertyValue( rKey, rNewAny ); - bModified = sal_True; - } - catch ( com::sun::star::uno::Exception& ) - { - DBG_ERROR( "FilterConfigItem::WriteAny - could not set PropertyValue" ); - - } - } - } - } -} - -// ------------------------------------------------------------------------ - -Sequence< PropertyValue > FilterConfigItem::GetFilterData() const -{ - return aFilterData; -} - -// ------------------------------------------------------------------------ - -Reference< XStatusIndicator > FilterConfigItem::GetStatusIndicator() const -{ - Reference< XStatusIndicator > xStatusIndicator; - const rtl::OUString sStatusIndicator( RTL_CONSTASCII_USTRINGPARAM( "StatusIndicator" ) ); - - sal_Int32 i, nCount = aFilterData.getLength(); - for ( i = 0; i < nCount; i++ ) - { - if ( aFilterData[ i ].Name == sStatusIndicator ) - { - aFilterData[ i ].Value >>= xStatusIndicator; - break; - } - } - return xStatusIndicator; -} - diff --git a/svtools/source/filter.vcl/filter/SvFilterOptionsDialog.cxx b/svtools/source/filter.vcl/filter/SvFilterOptionsDialog.cxx deleted file mode 100644 index 1c4eeeff1bbf..000000000000 --- a/svtools/source/filter.vcl/filter/SvFilterOptionsDialog.cxx +++ /dev/null @@ -1,270 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#include "SvFilterOptionsDialog.hxx" -#include -#include -#include "FilterConfigCache.hxx" -#include -#include -#include -#include -#include "exportdialog.hxx" -#include -#include -#include -#include -#include -#include -#include -#include -#include "vcl/svapp.hxx" - -using namespace ::rtl; -using namespace ::com::sun::star; - -// ------------------------- -// - SvFilterOptionsDialog - -// ------------------------- - -uno::Reference< uno::XInterface > - SAL_CALL SvFilterOptionsDialog_CreateInstance( - const uno::Reference< lang::XMultiServiceFactory > & _rxFactory ) -{ - return static_cast< ::cppu::OWeakObject* > ( new SvFilterOptionsDialog( _rxFactory ) ); -} - -OUString SvFilterOptionsDialog_getImplementationName() - throw( uno::RuntimeException ) -{ - return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.SvFilterOptionsDialog" ) ); -} -#define SERVICE_NAME "com.sun.star.ui.dialog.FilterOptionsDialog" -sal_Bool SAL_CALL SvFilterOptionsDialog_supportsService( const OUString& ServiceName ) - throw( uno::RuntimeException ) -{ - return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) ); -} - -uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog_getSupportedServiceNames() - throw( uno::RuntimeException ) -{ - uno::Sequence< OUString > aRet(1); - OUString* pArray = aRet.getArray(); - pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) ); - return aRet; -} -#undef SERVICE_NAME - -// ----------------------------------------------------------------------------- - -SvFilterOptionsDialog::SvFilterOptionsDialog( const uno::Reference< lang::XMultiServiceFactory > xMgr ) : - mxMgr ( xMgr ), - meFieldUnit ( FUNIT_CM ), - mbExportSelection ( sal_False ) -{ -} - -// ----------------------------------------------------------------------------- - -SvFilterOptionsDialog::~SvFilterOptionsDialog() -{ -} - -// ----------------------------------------------------------------------------- - -void SAL_CALL SvFilterOptionsDialog::acquire() throw() -{ - OWeakObject::acquire(); -} - -// ----------------------------------------------------------------------------- - -void SAL_CALL SvFilterOptionsDialog::release() throw() -{ - OWeakObject::release(); -} - -// XInitialization -void SAL_CALL SvFilterOptionsDialog::initialize( const uno::Sequence< uno::Any > & ) - throw ( uno::Exception, uno::RuntimeException ) -{ -} - -// XServiceInfo -OUString SAL_CALL SvFilterOptionsDialog::getImplementationName() - throw( uno::RuntimeException ) -{ - return SvFilterOptionsDialog_getImplementationName(); -} -sal_Bool SAL_CALL SvFilterOptionsDialog::supportsService( const OUString& rServiceName ) - throw( uno::RuntimeException ) -{ - return SvFilterOptionsDialog_supportsService( rServiceName ); -} -uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog::getSupportedServiceNames() - throw ( uno::RuntimeException ) -{ - return SvFilterOptionsDialog_getSupportedServiceNames(); -} - - -// XPropertyAccess -uno::Sequence< beans::PropertyValue > SvFilterOptionsDialog::getPropertyValues() - throw ( uno::RuntimeException ) -{ - sal_Int32 i, nCount; - for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ ) - { - if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) ) - break; - } - if ( i == nCount ) - maMediaDescriptor.realloc( ++nCount ); - - // the "FilterData" Property is an Any that will contain our PropertySequence of Values - maMediaDescriptor[ i ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "FilterData" ) ); - maMediaDescriptor[ i ].Value <<= maFilterDataSequence; - return maMediaDescriptor; -} - -void SvFilterOptionsDialog::setPropertyValues( const uno::Sequence< beans::PropertyValue > & aProps ) - throw ( beans::UnknownPropertyException, beans::PropertyVetoException, - lang::IllegalArgumentException, lang::WrappedTargetException, - uno::RuntimeException ) -{ - maMediaDescriptor = aProps; - - sal_Int32 i, nCount; - for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ ) - { - if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) ) - { - maMediaDescriptor[ i ].Value >>= maFilterDataSequence; - } - else if ( maMediaDescriptor[ i ].Name.equalsAscii( "SelectionOnly" ) ) - { - maMediaDescriptor[ i ].Value >>= mbExportSelection; - } - } -} - -// XExecutableDialog -void SvFilterOptionsDialog::setTitle( const OUString& aTitle ) - throw ( uno::RuntimeException ) -{ - maDialogTitle = aTitle; -} - -sal_Int16 SvFilterOptionsDialog::execute() - throw ( uno::RuntimeException ) -{ - sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL; - - String aFilterNameStr( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) ); - String aInternalFilterName; - sal_Int32 j, nCount = maMediaDescriptor.getLength(); - for ( j = 0; j < nCount; j++ ) - { - if ( maMediaDescriptor[ j ].Name.equals( aFilterNameStr ) ) - { - OUString aStr; - maMediaDescriptor[ j ].Value >>= aStr; - aInternalFilterName = aStr; - aInternalFilterName.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "draw_" ) ), String(), 0 ); - aInternalFilterName.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "impress_" ) ), String(), 0 ); - break; - } - } - if ( aInternalFilterName.Len() ) - { - GraphicFilter aGraphicFilter( sal_True ); - - sal_uInt16 nFormat, nFilterCount = aGraphicFilter.pConfig->GetExportFormatCount(); - for ( nFormat = 0; nFormat < nFilterCount; nFormat++ ) - { - if ( aGraphicFilter.pConfig->GetExportInternalFilterName( nFormat ) == aInternalFilterName ) - break; - } - if ( nFormat < nFilterCount ) - { - FltCallDialogParameter aFltCallDlgPara( Application::GetDefDialogParent(), NULL, meFieldUnit ); - aFltCallDlgPara.aFilterData = maFilterDataSequence; - - ByteString aResMgrName( "svt", 3 ); - ResMgr* pResMgr; - - pResMgr = ResMgr::CreateResMgr( aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() ); - aFltCallDlgPara.pResMgr = pResMgr; - - aFltCallDlgPara.aFilterExt = aGraphicFilter.pConfig->GetExportFormatShortName( nFormat ); - sal_Bool bIsPixelFormat( aGraphicFilter.pConfig->IsExportPixelFormat( nFormat ) ); - if ( ExportDialog( aFltCallDlgPara, mxMgr, mxSourceDocument, mbExportSelection, bIsPixelFormat ).Execute() == RET_OK ) - nRet = ui::dialogs::ExecutableDialogResults::OK; - - delete pResMgr; - - // taking the out parameter from the dialog - maFilterDataSequence = aFltCallDlgPara.aFilterData; - } - } - return nRet; -} - -// XEmporter -void SvFilterOptionsDialog::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc ) - throw ( lang::IllegalArgumentException, uno::RuntimeException ) -{ - mxSourceDocument = xDoc; - - // try to set the corresponding metric unit - String aConfigPath; - uno::Reference< lang::XServiceInfo > xServiceInfo - ( xDoc, uno::UNO_QUERY ); - if ( xServiceInfo.is() ) - { - if ( xServiceInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ) ) - aConfigPath = String( RTL_CONSTASCII_USTRINGPARAM( "Office.Impress/Layout/Other/MeasureUnit" ) ); - else if ( xServiceInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ) ) - aConfigPath = String( RTL_CONSTASCII_USTRINGPARAM( "Office.Draw/Layout/Other/MeasureUnit" ) ); - if ( aConfigPath.Len() ) - { - FilterConfigItem aConfigItem( aConfigPath ); - String aPropertyName; - SvtSysLocale aSysLocale; - if ( aSysLocale.GetLocaleDataPtr()->getMeasurementSystemEnum() == MEASURE_METRIC ) - aPropertyName = String( RTL_CONSTASCII_USTRINGPARAM( "Metric" ) ); - else - aPropertyName = String( RTL_CONSTASCII_USTRINGPARAM( "NonMetric" ) ); - meFieldUnit = (FieldUnit)aConfigItem.ReadInt32( aPropertyName, FUNIT_CM ); - } - } -} - diff --git a/svtools/source/filter.vcl/filter/SvFilterOptionsDialog.hxx b/svtools/source/filter.vcl/filter/SvFilterOptionsDialog.hxx deleted file mode 100644 index 027fac99c2e8..000000000000 --- a/svtools/source/filter.vcl/filter/SvFilterOptionsDialog.hxx +++ /dev/null @@ -1,105 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _SV_FILTER_OPTIONS_DIALOG_HXX_ -#define _SV_FILTER_OPTIONS_DIALOG_HXX_ - -#include -#include -#include -#include -#include -#include -#include -#include - -class SvFilterOptionsDialog : public cppu::WeakImplHelper5 -< - com::sun::star::document::XExporter, - com::sun::star::ui::dialogs::XExecutableDialog, - com::sun::star::beans::XPropertyAccess, - com::sun::star::lang::XInitialization, - com::sun::star::lang::XServiceInfo -> -{ - const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > - mxMgr; - com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > - maMediaDescriptor; - com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > - maFilterDataSequence; - com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > - mxSourceDocument; - - rtl::OUString maDialogTitle; - FieldUnit meFieldUnit; - sal_Bool mbExportSelection; - -public: - - SvFilterOptionsDialog( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > _rxORB ); - ~SvFilterOptionsDialog(); - - // XInterface - virtual void SAL_CALL acquire() throw(); - virtual void SAL_CALL release() throw(); - - // XInitialization - virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< com::sun::star::uno::Any > & aArguments ) - throw ( com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException ); - - // XServiceInfo - virtual rtl::OUString SAL_CALL getImplementationName() - throw ( com::sun::star::uno::RuntimeException ); - virtual sal_Bool SAL_CALL supportsService( const rtl::OUString& ServiceName ) - throw ( com::sun::star::uno::RuntimeException ); - virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() - throw ( com::sun::star::uno::RuntimeException ); - - // XPropertyAccess - virtual com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPropertyValues() - throw ( com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > & aProps ) - throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, - ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - // XExecuteDialog - virtual sal_Int16 SAL_CALL execute() - throw ( com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) - throw ( ::com::sun::star::uno::RuntimeException ); - - // XExporter - virtual void SAL_CALL setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc ) - throw ( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException ); - -}; - - -#endif // _SV_FILTER_OPTIONS_DIALOG_HXX_ - diff --git a/svtools/source/filter.vcl/filter/exportdialog.cxx b/svtools/source/filter.vcl/filter/exportdialog.cxx deleted file mode 100644 index 20cc46a30ab5..000000000000 --- a/svtools/source/filter.vcl/filter/exportdialog.cxx +++ /dev/null @@ -1,1513 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#ifndef GCC -# pragma hdrstop -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "exportdialog.hxx" -#include "exportdialog.hrc" - -#define FORMAT_UNKNOWN 0 -#define FORMAT_JPG 1 -#define FORMAT_PNG 2 -#define FORMAT_BMP 3 -#define FORMAT_GIF 4 -#define FORMAT_PBM 5 -#define FORMAT_PGM 6 -#define FORMAT_PPM 7 -#define FORMAT_PCT 8 -#define FORMAT_RAS 9 -#define FORMAT_TIF 10 -#define FORMAT_XPM 11 -#define FORMAT_WMF 12 -#define FORMAT_EMF 13 -#define FORMAT_EPS 14 -#define FORMAT_MET 15 -#define FORMAT_SVG 16 -#define FORMAT_SVM 17 - -#define UNIT_DEFAULT -1 -#define UNIT_INCH 0 -#define UNIT_CM 1 -#define UNIT_MM 2 -#define UNIT_POINT 3 -#define UNIT_PIXEL 4 -#define UNIT_MAX_ID UNIT_PIXEL - -using namespace ::com::sun::star; - -static sal_Int16 GetFilterFormat( String& rExt ) -{ - sal_Int16 nFormat = FORMAT_UNKNOWN; - ByteString aExt( rExt, RTL_TEXTENCODING_UTF8 ); - if ( aExt.Equals( "JPG" ) ) - nFormat = FORMAT_JPG; - else if ( aExt.Equals( "PNG" ) ) - nFormat = FORMAT_PNG; - else if ( aExt.Equals( "BMP" ) ) - nFormat = FORMAT_BMP; - else if ( aExt.Equals( "GIF" ) ) - nFormat = FORMAT_GIF; - else if ( aExt.Equals( "PBM" ) ) - nFormat = FORMAT_PBM; - else if ( aExt.Equals( "PGM" ) ) - nFormat = FORMAT_PGM; - else if ( aExt.Equals( "PPM" ) ) - nFormat = FORMAT_PPM; - else if ( aExt.Equals( "PCT" ) ) - nFormat = FORMAT_PCT; - else if ( aExt.Equals( "RAS" ) ) - nFormat = FORMAT_RAS; - else if ( aExt.Equals( "TIF" ) ) - nFormat = FORMAT_TIF; - else if ( aExt.Equals( "XPM" ) ) - nFormat = FORMAT_XPM; - else if ( aExt.Equals( "WMF" ) ) - nFormat = FORMAT_WMF; - else if ( aExt.Equals( "EMF" ) ) - nFormat = FORMAT_EMF; - else if ( aExt.Equals( "EPS" ) ) - nFormat = FORMAT_EPS; - else if ( aExt.Equals( "MET" ) ) - nFormat = FORMAT_MET; - else if ( aExt.Equals( "SVG" ) ) - nFormat = FORMAT_SVG; - else if ( aExt.Equals( "SVM" ) ) - nFormat = FORMAT_SVM; - return nFormat; -} - -static MapUnit GetMapUnit( sal_Int32 nUnit ) -{ - MapUnit aMapUnit( MAP_PIXEL ); - switch( nUnit ) - { - case UNIT_INCH : aMapUnit = MAP_INCH; break; - case UNIT_CM : aMapUnit = MAP_CM; break; - case UNIT_MM : aMapUnit = MAP_MM; break; - case UNIT_POINT : aMapUnit = MAP_POINT; break; - case UNIT_PIXEL : aMapUnit = MAP_PIXEL; break; - } - return aMapUnit; -} - -sal_Int32 ExportDialog::GetDefaultUnit() -{ - sal_Int32 nDefaultUnit = UNIT_CM; - switch( mrFltCallPara.eFieldUnit ) - { -// case FUNIT_NONE : -// case FUNIT_PERCENT : -// case FUNIT_CUSTOM : - default: nDefaultUnit = UNIT_CM; break; - - case FUNIT_MILE : // PASSTHROUGH INTENDED - case FUNIT_FOOT : - case FUNIT_TWIP : - case FUNIT_PICA : nDefaultUnit = UNIT_INCH; break; - - case FUNIT_KM : // PASSTHROUGH INTENDED - case FUNIT_M : - case FUNIT_100TH_MM : nDefaultUnit = UNIT_CM; break; - - case FUNIT_INCH : nDefaultUnit = UNIT_INCH; break; - case FUNIT_CM : nDefaultUnit = UNIT_CM; break; - case FUNIT_MM : nDefaultUnit = UNIT_MM; break; - case FUNIT_POINT : nDefaultUnit = UNIT_POINT; break; - } - return nDefaultUnit; -} - -static basegfx::B2DRange GetShapeRangeForXShape( const uno::Reference< drawing::XShape >& rxShape, - const uno::Reference< graphic::XPrimitiveFactory2D >& rxPrimitiveFactory2D, const uno::Sequence< beans::PropertyValue >& rViewInformation ) -{ - basegfx::B2DRange aShapeRange; - - const uno::Sequence< beans::PropertyValue > aParams; - const uno::Sequence< uno::Reference< graphic::XPrimitive2D > > aPrimitiveSequence( rxPrimitiveFactory2D->createPrimitivesFromXShape( rxShape, aParams ) ); - - const sal_Int32 nCount = aPrimitiveSequence.getLength(); - for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ ) - { - const geometry::RealRectangle2D aRect( aPrimitiveSequence[ nIndex ]->getRange( rViewInformation ) ); - aShapeRange.expand( basegfx::B2DTuple( aRect.X1, aRect.Y1 ) ); - aShapeRange.expand( basegfx::B2DTuple( aRect.X2, aRect.Y2 ) ); - } - return aShapeRange; -} - -uno::Sequence< beans::PropertyValue > ExportDialog::GetFilterData( sal_Bool bUpdateConfig ) -{ - if ( bUpdateConfig ) - { - sal_Int32 nUnit = maLbSizeX.GetSelectEntryPos(); - if ( nUnit < 0 ) - nUnit = UNIT_CM; - - if ( ( mnInitialResolutionUnit == UNIT_DEFAULT ) && ( nUnit == GetDefaultUnit() ) ) - nUnit = UNIT_DEFAULT; - - // updating ui configuration - if ( mbIsPixelFormat ) - { - if ( nUnit > UNIT_MAX_ID ) - nUnit = UNIT_PIXEL; - - sal_Int32 nResolution = maNfResolution.GetValue(); - if ( nResolution < 1 ) - nResolution = 96; - - mpOptionsItem->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelExportUnit" ) ), nUnit ); - mpOptionsItem->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelExportResolution" ) ), nResolution ); - mpOptionsItem->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelExportResolutionUnit" ) ), maLbResolution.GetSelectEntryPos() ); - } - else - { - if ( nUnit >= UNIT_PIXEL ) - nUnit = UNIT_CM; - - mpOptionsItem->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "VectorExportUnit" ) ), nUnit ); - } - } - - FilterConfigItem* pFilterOptions; - if ( bUpdateConfig ) - pFilterOptions = mpFilterOptionsItem; - else - { - uno::Sequence< beans::PropertyValue > aFilterData( mpFilterOptionsItem->GetFilterData() ); - pFilterOptions = new FilterConfigItem( &aFilterData ); - } - - const String sLogicalWidth( String( RTL_CONSTASCII_USTRINGPARAM( "LogicalWidth" ) ) ); - const String sLogicalHeight( String( RTL_CONSTASCII_USTRINGPARAM( "LogicalHeight" ) ) ); - if ( mbIsPixelFormat ) - { - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelWidth" ) ), static_cast< sal_Int32 >( maSize.Width ) ); - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelHeight" ) ), static_cast< sal_Int32 >( maSize.Height ) ); - if ( maResolution.Width && maResolution.Height ) - { - const double f100thmmPerPixelX = 100000.0 / maResolution.Width; - const double f100thmmPerPixelY = 100000.0 / maResolution.Height; - sal_Int32 nLogicalWidth = static_cast< sal_Int32 >( f100thmmPerPixelX * maSize.Width ); - sal_Int32 nLogicalHeight= static_cast< sal_Int32 >( f100thmmPerPixelY * maSize.Height ); - if ( nLogicalWidth && nLogicalHeight ) - { - pFilterOptions->WriteInt32( sLogicalWidth, nLogicalWidth ); - pFilterOptions->WriteInt32( sLogicalHeight, nLogicalHeight ); - } - } - } - else - { - pFilterOptions->WriteInt32( sLogicalWidth, static_cast< sal_Int32 >( maSize.Width ) ); - pFilterOptions->WriteInt32( sLogicalHeight, static_cast< sal_Int32 >( maSize.Height ) ); - } - switch ( mnFormat ) - { - case FORMAT_JPG : - { - sal_Int32 nColor = maLbColorDepth.GetSelectEntryPos(); - if ( nColor == 1 ) - nColor = 0; - else - nColor = 1; - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "ColorMode" ) ), nColor ); - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Quality" ) ), static_cast< sal_Int32 >( maSbCompression.GetThumbPos() ) ); - } - break; - - case FORMAT_PNG : - { - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Compression" ) ), static_cast< sal_Int32 >( maSbCompression.GetThumbPos() ) ); - sal_Int32 nInterlace = 0; - if ( maCbInterlaced.IsChecked() ) - nInterlace++; - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Interlaced" ) ), nInterlace ); - } - break; - - case FORMAT_BMP : - { - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Color" ) ), maLbColorDepth.GetSelectEntryPos() + 1 ); - pFilterOptions->WriteBool( String( RTL_CONSTASCII_USTRINGPARAM( "RLE_Coding" ) ), maCbRLEEncoding.IsChecked() ); - } - break; - - case FORMAT_GIF : - { - sal_Int32 nValue = 0; - if ( maCbInterlaced.IsChecked() ) - nValue++; - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Interlaced" ) ), nValue ); - - nValue = 0; - if ( maCbSaveTransparency.IsChecked() ) - nValue++; - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Translucent" ) ), nValue ); - } - break; - - case FORMAT_PBM : - case FORMAT_PGM : - case FORMAT_PPM : - { - sal_Int32 nFormat = 0; - if ( maRbText.IsChecked() ) - nFormat++; - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "FileFormat" ) ), nFormat ); - } - break; - - case FORMAT_EPS : - { - sal_Int32 nCheck = 0; - if ( maCbEPSPreviewTIFF.IsChecked() ) - nCheck++; - if ( maCbEPSPreviewEPSI.IsChecked() ) - nCheck += 2; - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Preview" ) ), nCheck ); - - nCheck = 1; - if ( maRbEPSLevel2.IsChecked() ) - nCheck++; - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ), nCheck ); - - nCheck = 1; - if ( maRbEPSColorFormat2.IsChecked() ) - nCheck++; - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "ColorFormat" ) ), nCheck ); - - nCheck = 1; - if ( maRbEPSCompressionNone.IsChecked() ) - nCheck++; - pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "CompressionMode" ) ), nCheck ); - } - break; - } - - uno::Sequence< beans::PropertyValue > aRet( pFilterOptions->GetFilterData() ); - if ( bUpdateConfig == sal_False ) - delete pFilterOptions; - return aRet; -} - -// -awt::Size ExportDialog::GetOriginalSize() -{ - basegfx::B2DRange aShapesRange; - - if ( mxPage.is () ) - { - uno::Reference< beans::XPropertySet > xPagePropSet( mxPage, uno::UNO_QUERY ); - if ( xPagePropSet.is() ) - { - sal_Int32 nWidth = 0; - sal_Int32 nHeight= 0; - com::sun::star::uno::Any aAny; - aAny = xPagePropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ) ) ); - aAny >>= nWidth; - aAny = xPagePropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" ) ) ); - aAny >>= nHeight; - aShapesRange = basegfx::B2DRange( 0, 0, nWidth, nHeight ); - } - } - else - { - uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory( - mxMgr->createInstance( String( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.PrimitiveFactory2D" ) ) ), uno::UNO_QUERY ); - if ( xPrimitiveFactory.is() ) - { - basegfx::B2DHomMatrix aViewTransformation( Application::GetDefaultDevice()->GetViewTransformation() ); - com::sun::star::geometry::AffineMatrix2D aTransformation; - aTransformation.m00 = aViewTransformation.get(0,0); - aTransformation.m01 = aViewTransformation.get(0,1); - aTransformation.m02 = aViewTransformation.get(0,2); - aTransformation.m10 = aViewTransformation.get(1,0); - aTransformation.m11 = aViewTransformation.get(1,1); - aTransformation.m12 = aViewTransformation.get(1,2); - - const rtl::OUString sViewTransformation( RTL_CONSTASCII_USTRINGPARAM( "ViewTransformation" ) ); - uno::Sequence< beans::PropertyValue > aViewInformation( 1 ); - aViewInformation[ 0 ].Value <<= aTransformation; - aViewInformation[ 0 ].Name = sViewTransformation; - - if ( mxShape.is() ) - aShapesRange = GetShapeRangeForXShape( mxShape, xPrimitiveFactory, aViewInformation ); - else if ( mxShapes.is() ) - { - const sal_Int32 nCount = mxShapes->getCount(); - for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ ) - { - uno::Reference< drawing::XShape > xShape; - mxShapes->getByIndex( nIndex ) >>= xShape; - aShapesRange.expand( GetShapeRangeForXShape( xShape, xPrimitiveFactory, aViewInformation ) ); - } - } - } - } - return awt::Size( static_cast(aShapesRange.getWidth()), static_cast(aShapesRange.getHeight()) ); -} - -void ExportDialog::GetGraphicSource() -{ - if ( mxSourceDocument.is() ) - { - uno::Reference< frame::XModel > xModel( mxSourceDocument, uno::UNO_QUERY ); - if ( xModel.is() ) - { - uno::Reference< frame::XController > xController( xModel->getCurrentController() ); - if ( xController.is() ) - { - if ( mbExportSelection ) // check if there is a selection - { - uno::Reference< view::XSelectionSupplier > xSelectionSupplier( xController, uno::UNO_QUERY ); - if ( xSelectionSupplier.is() ) - { - uno::Any aAny( xSelectionSupplier->getSelection() ); - if ( ! ( aAny >>= mxShapes ) ) - aAny >>= mxShape; - } - } - if ( !mxShape.is() && !mxShapes.is() ) - { - uno::Reference< drawing::XDrawView > xDrawView( xController, uno::UNO_QUERY ); - if ( xDrawView.is() ) - { - uno::Reference< drawing::XDrawPage > xCurrentPage( xDrawView->getCurrentPage() ); - if ( xCurrentPage.is() ) - { - mxPage = xCurrentPage; // exporting whole page - } - } - } - } - } - } -} - -sal_Bool ExportDialog::GetGraphicStream() -{ - sal_Bool bRet = sal_False; - - if ( !IsTempExportAvailable() ) - { - delete mpTempStream, mpTempStream = new SvMemoryStream(); - maBitmap = Bitmap(); - return bRet; - } - - sal_Bool bRecreateOutputStream = mpTempStream->Tell() == 0; - - static uno::Sequence< beans::PropertyValue > aOldFilterData; - uno::Sequence< beans::PropertyValue > aNewFilterData( GetFilterData( sal_False ) ); - if ( aOldFilterData != aNewFilterData ) - { - aOldFilterData = aNewFilterData; - bRecreateOutputStream = sal_True; - } - try - { - if ( bRecreateOutputStream ) - { - delete mpTempStream, mpTempStream = new SvMemoryStream(); - maBitmap = Bitmap(); - - uno::Reference < io::XStream > xStream( new utl::OStreamWrapper( *mpTempStream ) ); - uno::Reference < io::XOutputStream > xOutputStream( xStream->getOutputStream() ); - - uno::Reference< document::XExporter > xGraphicExporter( - mxMgr->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GraphicExportFilter") ) ), uno::UNO_QUERY_THROW ); - uno::Reference< document::XFilter > xFilter( xGraphicExporter, uno::UNO_QUERY_THROW ); - - sal_Int32 nProperties = 2; - uno::Sequence< beans::PropertyValue > aFilterData( nProperties ); - - - rtl::OUString sFormat( maExt ); - uno::Sequence< beans::PropertyValue > aDescriptor( 3 ); - aDescriptor[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("OutputStream") ); - aDescriptor[0].Value <<= xOutputStream; - aDescriptor[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FilterName") ); - aDescriptor[1].Value <<= sFormat; - aDescriptor[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FilterData") ); - aDescriptor[2].Value <<= aNewFilterData; - - uno::Reference< lang::XComponent > xSourceDoc; - if ( mxPage.is() ) - xSourceDoc = uno::Reference< lang::XComponent >( mxPage, uno::UNO_QUERY_THROW ); - else if ( mxShapes.is() ) - xSourceDoc = uno::Reference< lang::XComponent >( mxShapes, uno::UNO_QUERY_THROW ); - else if ( mxShape.is() ) - xSourceDoc = uno::Reference< lang::XComponent >( mxShape, uno::UNO_QUERY_THROW );; - if ( xSourceDoc.is() ) - { - xGraphicExporter->setSourceDocument( xSourceDoc ); - xFilter->filter( aDescriptor ); - bRet = sal_True; - - if ( mnFormat == FORMAT_JPG ) - { - mpTempStream->Seek( STREAM_SEEK_TO_BEGIN ); - maBitmap = GetGraphicBitmap( *mpTempStream ); - mpTempStream->Seek( STREAM_SEEK_TO_END ); - } - } - } - else - bRet = sal_True; - } - catch( uno::Exception& ) - { - - // ups - - } - return bRet; -} - -Bitmap ExportDialog::GetGraphicBitmap( SvStream& rInputStream ) -{ - Bitmap aRet; - Graphic aGraphic; - GraphicFilter aFilter( sal_False ); - if ( aFilter.ImportGraphic( aGraphic, String(), rInputStream, GRFILTER_FORMAT_NOTFOUND, NULL, 0, NULL ) == GRFILTER_OK ) - { - aRet = aGraphic.GetBitmap(); - } - return aRet; -} - -sal_uInt32 ExportDialog::GetRawFileSize() const -{ - sal_uInt64 nRawFileSize = 0; - if ( mbIsPixelFormat ) - { - sal_Int32 nBitsPerPixel = 24; - String aEntry( maLbColorDepth.GetSelectEntry() ); - if ( ms1BitTreshold == aEntry ) - nBitsPerPixel = 1; - else if ( ms1BitDithered == aEntry ) - nBitsPerPixel = 1; - else if ( ms4BitGrayscale == aEntry ) - nBitsPerPixel = 4; - else if ( ms4BitColorPalette == aEntry ) - nBitsPerPixel = 8; - else if ( ms8BitGrayscale == aEntry ) - nBitsPerPixel = 8; - else if ( ms8BitColorPalette == aEntry ) - nBitsPerPixel = 8; - else if ( ms24BitColor == aEntry ) - nBitsPerPixel = 24; - - if ( mbIsPixelFormat ) - { - nRawFileSize = ( maSize.Width * nBitsPerPixel + 7 ) &~ 7; // rounding up to 8 bits - nRawFileSize /= 8; // in bytes - nRawFileSize *= maSize.Height; - } - if ( nRawFileSize > SAL_MAX_UINT32 ) - nRawFileSize = 0; - } - return static_cast< sal_uInt32 >( nRawFileSize ); -} - -// checks if the source dimension/resolution is not too big -// to determine the exact graphic output size and preview for jpg -sal_Bool ExportDialog::IsTempExportAvailable() const -{ - return GetRawFileSize() < static_cast< sal_uInt32 >( mnMaxFilesizeForRealtimePreview ); -} - -ExportDialog::ExportDialog( FltCallDialogParameter& rPara, - const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > rxMgr, - const com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& rxSourceDocument, - sal_Bool bExportSelection, sal_Bool bIsPixelFormat ) : - ModalDialog ( rPara.pWindow, ResId( DLG_EXPORT, *rPara.pResMgr ) ), - mrFltCallPara ( rPara ), - mpMgr ( rPara.pResMgr ), - mxMgr ( rxMgr ), - mxSourceDocument ( rxSourceDocument ), - maFlExportSize ( this, ResId( FL_EXPORT_SIZE, *rPara.pResMgr ) ), - maFtSizeX ( this, ResId( FT_SIZEX, *rPara.pResMgr ) ), - maMfSizeX ( this, ResId( MF_SIZEX, *rPara.pResMgr ) ), - maLbSizeX ( this, ResId( LB_SIZEX, *rPara.pResMgr ) ), - maFtSizeY ( this, ResId( FT_SIZEY, *rPara.pResMgr ) ), - maMfSizeY ( this, ResId( MF_SIZEY, *rPara.pResMgr ) ), - maLbSizeY ( this, ResId( LB_SIZEY, *rPara.pResMgr ) ), - maFtResolution ( this, ResId( FT_RESOLUTION, *rPara.pResMgr ) ), - maNfResolution ( this, ResId( NF_RESOLUTION, *rPara.pResMgr ) ), - maLbResolution ( this, ResId( LB_RESOLUTION, *rPara.pResMgr ) ), - maFlColorDepth ( this, ResId( FL_COLOR_DEPTH, *rPara.pResMgr ) ), - maLbColorDepth ( this, ResId( LB_COLOR_DEPTH, *rPara.pResMgr ) ), - maFlJPGQuality ( this, ResId( FL_JPG_QUALITY, *rPara.pResMgr ) ), - maFlMode ( this, ResId( FL_MODE, *rPara.pResMgr ) ), - maFlPBMOptions ( this, ResId( FL_PBM_OPTIONS, *rPara.pResMgr ) ), - maSbCompression ( this, ResId( SB_COMPRESSION, *rPara.pResMgr ) ), - maNfCompression ( this, ResId( NF_COMPRESSION, *rPara.pResMgr ) ), - maFtJPGMin ( this, ResId( FT_JPG_MIN, *rPara.pResMgr ) ), - maFtJPGMax ( this, ResId( FT_JPG_MAX, *rPara.pResMgr ) ), - maFtPNGMin ( this, ResId( FT_PNG_MIN, *rPara.pResMgr ) ), - maFtPNGMax ( this, ResId( FT_PNG_MAX, *rPara.pResMgr ) ), - maCbJPGPreview ( this, ResId( CB_JPG_PREVIEW, *rPara.pResMgr ) ), - maCbInterlaced ( this, ResId( CB_INTERLACED, *rPara.pResMgr ) ), - maCbRLEEncoding ( this, ResId( CB_RLE_ENCODING, *rPara.pResMgr ) ), - maFlGIFDrawingObjects ( this, ResId( FL_GIF_DRAWING_OBJECTS, *rPara.pResMgr ) ), - maCbSaveTransparency ( this, ResId( CB_SAVE_TRANSPARENCY, *rPara.pResMgr ) ), - maRbBinary ( this, ResId( RB_BINARY, *rPara.pResMgr ) ), - maRbText ( this, ResId( RB_TEXT, *rPara.pResMgr ) ), - maFlEPSPreview ( this, ResId( FL_EPS_PREVIEW, *rPara.pResMgr ) ), - maCbEPSPreviewTIFF ( this, ResId( CB_EPS_PREVIEW_TIFF, *rPara.pResMgr ) ), - maCbEPSPreviewEPSI ( this, ResId( CB_EPS_PREVIEW_EPSI, *rPara.pResMgr ) ), - maFlEPSVersion ( this, ResId( FL_EPS_VERSION, *rPara.pResMgr ) ), - maRbEPSLevel1 ( this, ResId( RB_EPS_LEVEL1, *rPara.pResMgr ) ), - maRbEPSLevel2 ( this, ResId( RB_EPS_LEVEL2, *rPara.pResMgr ) ), - maFlEPSColorFormat ( this, ResId( FL_EPS_COLOR_FORMAT, *rPara.pResMgr ) ), - maRbEPSColorFormat1 ( this, ResId( RB_EPS_COLOR_FORMAT1, *rPara.pResMgr ) ), - maRbEPSColorFormat2 ( this, ResId( RB_EPS_COLOR_FORMAT2, *rPara.pResMgr ) ), - maFlCompression ( this, ResId( FL_COMPRESSION, *rPara.pResMgr ) ), - maRbEPSCompressionLZW ( this, ResId( RB_EPS_COMPRESSION_LZW, *rPara.pResMgr ) ), - maRbEPSCompressionNone ( this, ResId( RB_EPS_COMPRESSION_NONE, *rPara.pResMgr ) ), - maFlEstimatedSize ( this, ResId( FL_ESTIMATED_SIZE, *rPara.pResMgr ) ), - maFtEstimatedSize ( this, ResId( FT_ESTIMATED_SIZE, *rPara.pResMgr ) ), - msEstimatedSizePix1 ( ResId( STR_ESTIMATED_SIZE_PIX_1, *rPara.pResMgr ) ), - msEstimatedSizePix2 ( ResId( STR_ESTIMATED_SIZE_PIX_2, *rPara.pResMgr ) ), - msEstimatedSizeVec ( ResId( STR_ESTIMATED_SIZE_VEC, *rPara.pResMgr ) ), - maFlButtons ( this, ResId( FL_BUTTONS, *rPara.pResMgr ) ), - maFbJPGPreview ( this, ResId( FB_JPG_PREVIEW, *rPara.pResMgr ) ), - maSbZoom ( this, ResId( SB_ZOOM, *rPara.pResMgr ) ), - maNfZoom ( this, ResId( NF_ZOOM, *rPara.pResMgr ) ), - maSbJPGPreviewHorz ( this, ResId( SB_JPG_PREVIEW_HORZ, *rPara.pResMgr ) ), - maSbJPGPreviewVert ( this, ResId( SB_JPG_PREVIEW_VERT, *rPara.pResMgr ) ), - maBtnOK ( this, ResId( BTN_OK, *rPara.pResMgr ) ), - maBtnCancel ( this, ResId( BTN_CANCEL, *rPara.pResMgr ) ), - maBtnHelp ( this, ResId( BTN_HELP, *rPara.pResMgr ) ), - ms1BitTreshold ( ResId( STR_1BIT_THRESHOLD, *rPara.pResMgr ) ), - ms1BitDithered ( ResId( STR_1BIT_DITHERED, *rPara.pResMgr ) ), - ms4BitGrayscale ( ResId( STR_4BIT_GRAYSCALE, *rPara.pResMgr ) ), - ms4BitColorPalette ( ResId( STR_4BIT_COLOR_PALETTE, *rPara.pResMgr ) ), - ms8BitGrayscale ( ResId( STR_8BIT_GRAYSCALE, *rPara.pResMgr ) ), - ms8BitColorPalette ( ResId( STR_8BIT_COLOR_PALETTE, *rPara.pResMgr ) ), - ms24BitColor ( ResId( STR_24BIT_TRUE_COLOR, *rPara.pResMgr ) ), - maExt ( rPara.aFilterExt ), - mnFormat ( FORMAT_UNKNOWN ), - mnMaxFilesizeForRealtimePreview( 0 ), - mpTempStream ( new SvMemoryStream() ), - maOriginalSize ( awt::Size( 0, 0 ) ), - mbPreview ( sal_False ), - mbIsPixelFormat ( bIsPixelFormat ), - mbExportSelection ( bExportSelection ), - mbPreserveAspectRatio ( sal_True ) -{ - GetGraphicSource(); - - maExt.ToUpperAscii(); - - String aFilterConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/Graphic/Export/" ) ); - mpOptionsItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData ); - aFilterConfigPath.Append( maExt ); - mpFilterOptionsItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData ); - - mnInitialResolutionUnit = mbIsPixelFormat - ? mpOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelExportUnit" ) ), UNIT_DEFAULT ) - : mpOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "VectorExportUnit" ) ), UNIT_DEFAULT ); - - mnMaxFilesizeForRealtimePreview = mpOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "MaxFilesizeForRealtimePreview" ) ), 0 ); - maFtEstimatedSize.SetText( String( RTL_CONSTASCII_USTRINGPARAM( " \n " ) ) ); - - String aTitle( maExt ); - aTitle += String( ResId( DLG_EXPORT_TITLE, *mpMgr ) ); - SetText( aTitle ); - - mnFormat = GetFilterFormat( maExt ); - - Size aResolution( Application::GetDefaultDevice()->LogicToPixel( Size( 100, 100 ), MAP_CM ) ); - maResolution.Width = aResolution.Width(); - maResolution.Height= aResolution.Height(); - maOriginalSize = GetOriginalSize(); - if ( bIsPixelFormat ) - { - double fPixelsPer100thmm = static_cast< double >( maResolution.Width ) / 100000.0; - maSize = awt::Size( static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Width ) + 0.5 ), - static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Height ) + 0.5 ) ); - } - else - { - maSize = maOriginalSize; - } - - // Size - maLbSizeX.SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) ); - - maSbCompression.SetScrollHdl( LINK( this, ExportDialog, SbCompressionUpdateHdl ) ); - maNfCompression.SetModifyHdl( LINK( this, ExportDialog, UpdateHdl ) ); - - maMfSizeX.SetModifyHdl( LINK( this, ExportDialog, UpdateHdlMtfSizeX ) ); - maMfSizeY.SetModifyHdl( LINK( this, ExportDialog, UpdateHdlMtfSizeY ) ); - - maNfResolution.SetModifyHdl( LINK( this, ExportDialog, UpdateHdlNfResolution ) ); - maLbResolution.SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) ); - - maLbColorDepth.SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) ); - - maCbInterlaced.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); - - maCbSaveTransparency.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); - - maCbEPSPreviewTIFF.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); - maCbEPSPreviewEPSI.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); - - maRbEPSCompressionLZW.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); - maRbEPSCompressionNone.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); - - maRbBinary.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); - maRbText.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); - - - // JPG Preview -// maCbJPGPreview.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); -maCbJPGPreview.Enable( sal_False ); - - maSbJPGPreviewVert.SetScrollHdl( LINK( this, ExportDialog, UpdateHdl ) ); - maSbJPGPreviewHorz.SetScrollHdl( LINK( this, ExportDialog, UpdateHdl ) ); - maSbZoom.SetScrollHdl( LINK( this, ExportDialog, UpdateHdl ) ); - - // BMP - maCbRLEEncoding.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); - - // EPS - maRbEPSLevel1.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); - maRbEPSLevel2.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); - - maBtnOK.SetClickHdl( LINK( this, ExportDialog, OK ) ); - - setupLayout(); - updateControls(); - - FreeResource(); -} - -void ExportDialog::createSizeControls( vcl::RowOrColumn& rLayout ) -{ - size_t nIndex; - Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) ); - long nIndent = aBorder.Width(); - - // Size controls - rLayout.addWindow( &maFlExportSize ); - - Size aLbMax( maLbSizeX.GetSizePixel() ); - aLbMax.Width() = Max( aLbMax.Width(), maLbResolution.GetSizePixel().Width() ); - - boost::shared_ptr< vcl::LabelColumn > xSizeColumns( new vcl::LabelColumn( &rLayout ) ); - rLayout.addChild( xSizeColumns ); - - // row 1 - boost::shared_ptr< vcl::RowOrColumn > xColumn( new vcl::RowOrColumn( xSizeColumns.get(), false ) ); - xSizeColumns->addRow( &maFtSizeX, xColumn, nIndent ); - Size aMinSize( maMfSizeX.GetSizePixel() ); - nIndex = xColumn->addWindow( &maMfSizeX ); - xColumn->setMinimumSize( nIndex, aMinSize ); - nIndex = xColumn->addWindow( &maLbSizeX ); - xColumn->setMinimumSize( nIndex, aLbMax ); - - // row 2 - xColumn = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( xSizeColumns.get(), false ) ); - xSizeColumns->addRow( &maFtSizeY, xColumn, nIndent ); - nIndex = xColumn->addWindow( &maMfSizeY ); - xColumn->setMinimumSize( nIndex, aMinSize ); - nIndex = xColumn->addWindow( &maLbSizeY ); - xColumn->setMinimumSize( nIndex, aLbMax ); - - // row 3 - if ( mbIsPixelFormat ) // TODO: (metafileresolutionsupport) - { - xColumn = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( xSizeColumns.get(), false ) ); - xSizeColumns->addRow( &maFtResolution, xColumn, nIndent ); - nIndex = xColumn->addWindow( &maNfResolution ); - xColumn->setMinimumSize( nIndex, aMinSize ); - nIndex = xColumn->addWindow( &maLbResolution ); - xColumn->setMinimumSize( nIndex, aLbMax ); - } - - sal_Int32 nUnit = mnInitialResolutionUnit; - if ( nUnit == UNIT_DEFAULT ) - nUnit = GetDefaultUnit(); - - if ( !mbIsPixelFormat ) - { - maLbSizeX.RemoveEntry( UNIT_PIXEL ); // removing pixel - if ( nUnit >= UNIT_PIXEL ) - nUnit = UNIT_CM; - } - else if ( nUnit > UNIT_MAX_ID ) - nUnit = UNIT_PIXEL; - if ( nUnit < 0 ) - nUnit = UNIT_CM; - maLbSizeX.SelectEntryPos( static_cast< USHORT >( nUnit ) ); - - if ( mbIsPixelFormat ) // TODO: (metafileresolutionsupport) should be supported for vector formats also... this makes - { // sense eg for bitmap fillings in metafiles, to preserve high dpi output - // (atm without special vector support the bitmaps are rendered with 96dpi) - sal_Int32 nResolution = mpOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelExportResolution" ) ), 96 ); - if ( nResolution < 1 ) - nResolution = 96; - maNfResolution.SetValue( nResolution ); - - sal_Int32 nResolutionUnit = mpOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelExportResolutionUnit" ) ), 1 ); - if ( ( nResolutionUnit < 0 ) || ( nResolutionUnit > 2 ) ) - nResolutionUnit = 1; - maLbResolution.SelectEntryPos( static_cast< USHORT >( nResolutionUnit ) ); - } - - boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); - rLayout.addChild( xSpacer ); -} - -void ExportDialog::createColorDepthControls( vcl::RowOrColumn& rLayout ) -{ - // Color Depth - Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) ); - long nIndent = aBorder.Width(); - - boost::shared_ptr< vcl::RowOrColumn > xRow( new vcl::RowOrColumn( &rLayout, false ) ); - rLayout.addChild( xRow ); - xRow->addWindow( &maFlColorDepth ); - - xRow = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( &rLayout, false ) ); - rLayout.addChild( xRow ); - boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( &rLayout, nIndent ) ); - xRow->addChild( xIndenter ); - boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( &rLayout, true ) ); - xIndenter->setChild( xRows ); - xRows->addWindow( &maLbColorDepth ); - - boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); - rLayout.addChild( xSpacer ); -} - -void ExportDialog::createScrollBar( vcl::RowOrColumn& rLayout ) -{ - boost::shared_ptr< vcl::RowOrColumn > xRow( new vcl::RowOrColumn( &rLayout, false ) ); - rLayout.addChild( xRow ); - - Size aMinSize( maSbCompression.GetSizePixel() ); - size_t nIndex = xRow->addWindow( &maSbCompression ); - xRow->setMinimumSize( nIndex, aMinSize ); - aMinSize = maNfCompression.GetSizePixel(); - nIndex = xRow->addWindow( &maNfCompression ); - xRow->setMinimumSize( nIndex, aMinSize ); -} - -void ExportDialog::createFilterOptions( vcl::RowOrColumn& rLayout ) -{ - Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) ); - long nIndent = aBorder.Width(); - - switch( mnFormat ) - { - case FORMAT_JPG : - { - sal_Int32 nColor = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "ColorMode" ) ), 0 ); - if ( nColor == 1 ) - nColor = 0; - else - nColor = 1; - maLbColorDepth.InsertEntry( ms8BitGrayscale ); - maLbColorDepth.InsertEntry( ms24BitColor ); - maLbColorDepth.SelectEntryPos( nColor ); - createColorDepthControls( maLayout ); - - rLayout.addWindow( &maFlJPGQuality ); - - // Quality - boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( &rLayout, nIndent ) ); - rLayout.addChild( xIndenter ); - boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( &rLayout, true ) ); - xIndenter->setChild( xRows ); - createScrollBar( *xRows.get() ); - xRows->addWindow( &maFtJPGMin ); - xRows->addWindow( &maFtJPGMax ); - if ( maCbJPGPreview.IsEnabled() ) - xRows->addWindow( &maCbJPGPreview ); - - boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); - rLayout.addChild( xSpacer ); - - sal_Int32 nQuality = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Quality" ) ), 75 ); - if ( ( nQuality < 1 ) || ( nQuality > 100 ) ) - nQuality = 75; - - maSbCompression.SetRangeMin( 1 ); - maSbCompression.SetRangeMax( 100 ); - maNfCompression.SetMin( 1 ); - maNfCompression.SetMax( 100 ); - maNfCompression.SetValue( nQuality ); - maNfCompression.SetStrictFormat( sal_True ); - if ( maCbJPGPreview.IsEnabled() ) - maCbJPGPreview.Check( sal_False ); - } - break; - case FORMAT_PNG : - { - rLayout.addWindow( &maFlCompression ); - - // Compression 1..9 - boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( &rLayout, nIndent ) ); - rLayout.addChild( xIndenter ); - boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( &rLayout, true ) ); - xIndenter->setChild( xRows ); - createScrollBar( *xRows.get() ); - xRows->addWindow( &maFtPNGMin ); - xRows->addWindow( &maFtPNGMax ); - boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); - rLayout.addChild( xSpacer ); - - // Interlaced - rLayout.addWindow( &maFlMode ); - xIndenter.reset( new vcl::Indenter( &rLayout, nIndent ) ); - rLayout.addChild( xIndenter ); - xRows.reset( new vcl::RowOrColumn( &rLayout, true ) ); - xIndenter->setChild( xRows ); - xRows->addWindow( &maCbInterlaced ); - - xSpacer.reset( new vcl::Spacer( &rLayout, 2 ) ); - rLayout.addChild( xSpacer ); - - sal_Int32 nCompression = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Compression" ) ), 6 ); - if ( ( nCompression < 1 ) || ( nCompression > 9 ) ) - nCompression = 6; - maSbCompression.SetRangeMin( 1 ); - maSbCompression.SetRangeMax( 9 ); - maNfCompression.SetMin( 1 ); - maNfCompression.SetMax( 9 ); - maNfCompression.SetValue( 9 ); - maNfCompression.SetStrictFormat( sal_True ); - - maCbInterlaced.Check( mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Interlaced" ) ), 0 ) != 0 ); - } - break; - case FORMAT_BMP : - { - sal_Int32 nColor = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Color" ) ), 0 ); - if ( nColor == 0 ) - nColor = 6; - else - nColor--; - maLbColorDepth.InsertEntry( ms1BitTreshold ); - maLbColorDepth.InsertEntry( ms1BitDithered ); - maLbColorDepth.InsertEntry( ms4BitGrayscale ); - maLbColorDepth.InsertEntry( ms4BitColorPalette ); - maLbColorDepth.InsertEntry( ms8BitGrayscale ); - maLbColorDepth.InsertEntry( ms8BitColorPalette ); - maLbColorDepth.InsertEntry( ms24BitColor ); - maLbColorDepth.SelectEntryPos( nColor ); - createColorDepthControls( maLayout ); - - rLayout.addWindow( &maFlCompression ); - // RLE coding - boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( &rLayout, nIndent ) ); - rLayout.addChild( xIndenter ); - boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( &rLayout, true ) ); - xIndenter->setChild( xRows ); - xRows->addWindow( &maCbRLEEncoding ); - boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); - rLayout.addChild( xSpacer ); - - maCbRLEEncoding.Check( mpFilterOptionsItem->ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "RLE_Coding" ) ), sal_True ) ); - } - break; - case FORMAT_GIF : - { - rLayout.addWindow( &maFlMode ); - boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( &rLayout, nIndent ) ); - rLayout.addChild( xIndenter ); - boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( &rLayout, true ) ); - xIndenter->setChild( xRows ); - xRows->addWindow( &maCbInterlaced ); - boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); - rLayout.addChild( xSpacer ); - - rLayout.addWindow( &maFlGIFDrawingObjects ); - xIndenter = boost::shared_ptr< vcl::Indenter >( new vcl::Indenter( &rLayout, nIndent ) ); - rLayout.addChild( xIndenter ); - xRows = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( &rLayout, true ) ); - xIndenter->setChild( xRows ); - xRows->addWindow( &maCbSaveTransparency ); - xSpacer.reset( new vcl::Spacer( &rLayout, 2 ) ); - rLayout.addChild( xSpacer ); - - maCbInterlaced.Check( mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Interlaced" ) ), 1 ) != 0 ); - maCbSaveTransparency.Check( mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Translucent" ) ), 1 ) != 0 ); - } - break; - case FORMAT_PBM : - case FORMAT_PGM : - case FORMAT_PPM : - { - rLayout.addWindow( &maFlJPGQuality ); - - // RB Binary / Text - boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( &rLayout, nIndent ) ); - rLayout.addChild( xIndenter ); - boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( &rLayout, true ) ); - xIndenter->setChild( xRows ); - xRows->addWindow( &maRbBinary ); - xRows->addWindow( &maRbText ); - boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); - rLayout.addChild( xSpacer ); - - sal_Int32 nFormat = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "FileFormat" ) ), 1 ); - maRbBinary.Check( nFormat == 0 ); - maRbText.Check( nFormat != 0 ); - } - break; - case FORMAT_EPS : - { - boost::shared_ptr< vcl::RowOrColumn > xColumns( new vcl::RowOrColumn( &rLayout, false ) ); - rLayout.addChild( xColumns ); - boost::shared_ptr< vcl::RowOrColumn > xLeft( new vcl::RowOrColumn( &rLayout, true ) ); - xColumns->addChild( xLeft ); - - xLeft->addWindow( &maFlEPSPreview ); - boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( xLeft.get(), nIndent ) ); - xLeft->addChild( xIndenter ); - boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( xLeft.get(), true ) ); - xIndenter->setChild( xRows ); - xRows->addWindow( &maCbEPSPreviewTIFF ); - xRows->addWindow( &maCbEPSPreviewEPSI ); - boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( xLeft.get(), 2 ) ); - xLeft->addChild( xSpacer ); - - xLeft->addWindow( &maFlEPSVersion ); - xIndenter = boost::shared_ptr< vcl::Indenter >( new vcl::Indenter( xLeft.get(), nIndent ) ); - xLeft->addChild( xIndenter ); - xRows = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( xLeft.get(), true ) ); - xIndenter->setChild( xRows ); - xRows->addWindow( &maRbEPSLevel1 ); - xRows->addWindow( &maRbEPSLevel2 ); - xSpacer.reset( new vcl::Spacer( xLeft.get(), 2 ) ); - xLeft->addChild( xSpacer ); - - boost::shared_ptr< vcl::RowOrColumn > xRight( new vcl::RowOrColumn( &rLayout, true ) ); - xColumns->addChild( xRight ); - - xRight->addWindow( &maFlEPSColorFormat ); - xIndenter = boost::shared_ptr< vcl::Indenter >( new vcl::Indenter( xRight.get(), nIndent ) ); - xRight->addChild( xIndenter ); - xRows = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( xRight.get(), true ) ); - xIndenter->setChild( xRows ); - xRows->addWindow( &maRbEPSColorFormat1 ); - xRows->addWindow( &maRbEPSColorFormat2 ); - xSpacer.reset( new vcl::Spacer( xRight.get(), 2 ) ); - xRight->addChild( xSpacer ); - - xRight->addWindow( &maFlCompression ); - xIndenter = boost::shared_ptr< vcl::Indenter >( new vcl::Indenter( xRight.get(), nIndent ) ); - xRight->addChild( xIndenter ); - xRows = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( xRight.get(), true ) ); - xIndenter->setChild( xRows ); - xRows->addWindow( &maRbEPSCompressionLZW ); - xRows->addWindow( &maRbEPSCompressionNone ); - - xSpacer.reset( new vcl::Spacer( &rLayout, 2 ) ); - rLayout.addChild( xSpacer ); - - sal_Int32 nPreview = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Preview" ) ), 0 ); - sal_Int32 nVersion = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ), 2 ); - sal_Int32 nColor = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "ColorFormat" ) ), 0 ); - sal_Int32 nCompr = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "CompressionMode" ) ), 2 ); - - mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "TextMode" ) ), 0 ); - - maCbEPSPreviewTIFF.Check( ( nPreview & 1 ) != 0 ); - maCbEPSPreviewEPSI.Check( ( nPreview & 2 ) != 0 ); - - maRbEPSLevel1.Check( nVersion == 1 ); - maRbEPSLevel2.Check( nVersion == 2 ); - - maRbEPSColorFormat1.Check( nColor == 1 ); - maRbEPSColorFormat2.Check( nColor != 1 ); - - maRbEPSCompressionLZW.Check( nCompr == 1 ); - maRbEPSCompressionNone.Check( nCompr != 1 ); - } - break; - } -} - -void ExportDialog::createButtons( vcl::RowOrColumn& rLayout ) -{ - rLayout.addWindow( &maFlButtons ); - boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); - rLayout.addChild( xSpacer ); - - Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) ); - - boost::shared_ptr< vcl::RowOrColumn > xButtons( new vcl::RowOrColumn( &rLayout, false ) ); - size_t nIndex = rLayout.addChild( xButtons ); - rLayout.setBorders( nIndex, aBorder.Width(), 0, aBorder.Width(), aBorder.Width() ); - - Size aMinSize( maBtnCancel.GetSizePixel() ); - // insert help button - xButtons->setMinimumSize( xButtons->addWindow( &maBtnHelp ), aMinSize ); - - // insert a spacer, cancel and OK buttons are right aligned - - xSpacer.reset( new vcl::Spacer( xButtons.get(), 2 ) ); - xButtons->addChild( xSpacer ); - xButtons->setMinimumSize( xButtons->addWindow( &maBtnOK ), aMinSize ); - xButtons->setMinimumSize( xButtons->addWindow( &maBtnCancel ), aMinSize ); -} - -void ExportDialog::setupLayout() -{ - Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) ); - maLayout.setParentWindow( this ); - maLayout.setOuterBorder( aBorder.Width() ); - - createSizeControls( maLayout ); - createFilterOptions( maLayout ); - - if ( mnMaxFilesizeForRealtimePreview || mbIsPixelFormat ) - { - maLayout.addWindow( &maFlEstimatedSize ); - maLayout.addWindow( &maFtEstimatedSize ); - } - createButtons( maLayout ); - - maLayout.show(); - maDialogSize = maLayout.getOptimalSize( WINDOWSIZE_PREFERRED ); - maLayout.setManagedArea( Rectangle( Point(), maDialogSize ) ); - SetOutputSizePixel( Size( mbPreview ? maDialogSize.Width() * 2 : maDialogSize.Width(), maDialogSize.Height() ) ); - - maRectFlButtons = Rectangle( maFlButtons.GetPosPixel(), maFlButtons.GetSizePixel() ); - maRectBtnHelp = Rectangle( maBtnHelp.GetPosPixel(), maBtnHelp.GetSizePixel() ); - maRectBtnOK = Rectangle( maBtnOK.GetPosPixel(), maBtnOK.GetSizePixel() ); - maRectBtnCancel = Rectangle( maBtnCancel.GetPosPixel(), maBtnOK.GetSizePixel() ); - - maLbSizeY.Hide(); -} - -static rtl::OUString ImpValueOfInKB( const sal_Int64& rVal ) -{ - double fVal( static_cast( rVal ) ); - fVal /= ( 1 << 10 ); - fVal += 0.05; - rtl::OUStringBuffer aVal( rtl::OUString::valueOf( fVal ) ); - sal_Int32 nX( rtl::OUString( aVal.getStr() ).indexOf( '.', 0 ) ); - if ( nX > 0 ) - aVal.setLength( nX + 2 ); - return aVal.makeStringAndClear(); -} - -sal_Int32 static GetZoomValueFromThumbPos( sal_Int32 nThumbPos ) -{ - sal_Int32 nProz = 0; - if ( nThumbPos <= 50 ) - nProz = nThumbPos * 2; // so a range of 50 represents 100% - else - nProz = ( ( nThumbPos - 50 ) * 60 ) + 100; // we want to scale up to 3000% - return nProz; -} - -void ExportDialog::updatePreview() -{ - // JPG -// maCbJPGPreview.Enable( IsTempExportAvailable() ); - -// if ( maCbJPGPreview.IsEnabled() && maCbJPGPreview.IsChecked() ) - if ( mbPreview ) - { - long nScrollBarSize = Application::GetSettings().GetStyleSettings().GetScrollBarSize(); - - Point aPreviewPos( maDialogSize.Width(), 0 ); - Size aPreviewSize( maDialogSize.Width(), maFlButtons.GetPosPixel().Y() ); - - Point aFixedBitmapPos( aPreviewPos ); - Size aFixedBitmapSize( aPreviewSize ); - - maSbZoom.Show( sal_False ); - maSbZoom.SetPosPixel( Point( aPreviewPos.X(), aPreviewPos.Y() ) ); - maSbZoom.SetSizePixel( Size( aPreviewSize.Width() / 4, nScrollBarSize ) ); - maNfZoom.Show( sal_False ); - maNfZoom.SetPosPixel( Point( aPreviewPos.X() + aPreviewSize.Width() / 4, aPreviewPos.Y() ) ); - maNfZoom.SetSizePixel( Size( aPreviewSize.Width() / 6, nScrollBarSize ) ); - maNfZoom.SetValue( GetZoomValueFromThumbPos( maSbZoom.GetThumbPos() ) ); - maFbJPGPreview.Show( sal_True ); - - sal_Int32 nZoom = GetZoomValueFromThumbPos( maSbZoom.GetThumbPos() ); - double fSizePixelX = static_cast< double >( maSize.Width * nZoom ) / 100.0; - double fSizePixelY = static_cast< double >( maSize.Height * nZoom ) / 100.0; - - double fXRatio = fSizePixelX / maSize.Width; // the size of each pixel - double fYRatio = fSizePixelY / maSize.Height; - - sal_Bool bHorzSb = fSizePixelX > aFixedBitmapSize.Width(); - sal_Bool bVertSb = fSizePixelY > aFixedBitmapSize.Height(); - if ( bHorzSb ) - { - aFixedBitmapSize.Height() -= nScrollBarSize; - - maSbJPGPreviewHorz.Show( sal_True ); - maSbJPGPreviewHorz.SetPosPixel( Point( aFixedBitmapPos.X(), aFixedBitmapPos.Y() + aFixedBitmapSize.Height() ) ); - maSbJPGPreviewHorz.SetSizePixel( Size( aFixedBitmapSize.Width(), nScrollBarSize ) ); - } - else - { - maSbJPGPreviewHorz.Show( sal_False ); - } - - - if ( bVertSb ) - { - aFixedBitmapSize.Width() -= nScrollBarSize; - - maSbJPGPreviewVert.Show( sal_True ); - maSbJPGPreviewVert.SetPosPixel( Point( aFixedBitmapPos.X() + aFixedBitmapSize.Width(), aFixedBitmapPos.Y() ) ); - maSbJPGPreviewVert.SetSizePixel( Size( nScrollBarSize, aFixedBitmapSize.Height() ) ); - } - else - { - maSbJPGPreviewVert.Show( sal_False ); - } - - Point aPos( 0, 0 ); - Size aSize; - if ( fXRatio > 1.0 ) - { - aSize.Width() = maSize.Width > aFixedBitmapSize.Width() ? maSize.Width : aFixedBitmapSize.Width(); - aSize.Width() /= static_cast(fXRatio); - } - else - { - aSize.Width() = maSize.Width < aFixedBitmapSize.Width() ? maSize.Width : aFixedBitmapSize.Width(); - aSize.Width() /= static_cast(fXRatio); - } - - if ( fYRatio > 1.0 ) - { - aSize.Height() = maSize.Height > aFixedBitmapSize.Height() ? maSize.Height : aFixedBitmapSize.Height(); - aSize.Height() /= static_cast(fYRatio); - } - else - { - aSize.Height() = maSize.Height < aFixedBitmapSize.Height() ? maSize.Height : aFixedBitmapSize.Height(); - aSize.Height() /= static_cast(fYRatio); - } - - if ( aSize.Width() < maSize.Width ) - { - sal_Int32 nXDiff = static_cast< sal_Int32 >( ( ( ( maSize.Width - aSize.Width() ) * maSbJPGPreviewHorz.GetThumbPos() ) / 100.0 ) ); - aPos.X() += nXDiff; - } - if ( aSize.Height() < maSize.Height ) - { - sal_Int32 nYDiff = static_cast< sal_Int32 >( ( ( ( maSize.Height - aSize.Height() ) * maSbJPGPreviewVert.GetThumbPos() ) / 100.0 ) ); - aPos.Y() += nYDiff; - } - - Bitmap aCroppedBitmap( maBitmap ); - aCroppedBitmap.Crop( Rectangle( aPos, aSize ) ); - aSize = aCroppedBitmap.GetSizePixel(); - aSize = Size( static_cast(aSize.Width() * fXRatio), static_cast(aSize.Height() * fYRatio) ); - aCroppedBitmap.Scale( aSize ); - - if ( aSize.Width() > aFixedBitmapSize.Width() ) - aSize.Width() = aFixedBitmapSize.Width(); - if ( aSize.Height() > aFixedBitmapSize.Height() ) - aSize.Height() = aFixedBitmapSize.Height(); - Point aPoint( aFixedBitmapPos ); - if ( aSize.Width() < aFixedBitmapSize.Width() ) - aPoint.X() += ( aFixedBitmapSize.Width() - aSize.Width() ) / 2; - if ( aSize.Height() < aFixedBitmapSize.Height() ) - aPoint.Y() += ( aFixedBitmapSize.Height() - aSize.Height() ) / 2; - - maFbJPGPreview.SetPosPixel( aPoint ); - maFbJPGPreview.SetSizePixel( aSize ); - maFbJPGPreview.SetBitmap( aCroppedBitmap ); - - SetOutputSizePixel( Size( maDialogSize.Width() * 2, maDialogSize.Height() ) ); - - maFlButtons.SetSizePixel( Size( maRectFlButtons.GetWidth() * 2, maRectFlButtons.GetHeight() ) ); - maBtnHelp.SetPosPixel( Point( maRectBtnHelp.Left() + maDialogSize.Width(), maRectBtnHelp.Top() ) ); - maBtnOK.SetPosPixel( Point( maRectBtnOK.Left() + maDialogSize.Width(), maRectBtnOK.Top() ) ); - maBtnCancel.SetPosPixel( Point( maRectBtnCancel.Left() + maDialogSize.Width(), maRectBtnCancel.Top() ) ); - } - else - { - maSbZoom.Show( sal_False ); - maNfZoom.Show( sal_False ); - maFbJPGPreview.Show( sal_False ); - maSbJPGPreviewHorz.Show( sal_False ); - maSbJPGPreviewVert.Show( sal_False ); - - SetOutputSizePixel( maDialogSize ); - - maFlButtons.SetSizePixel( Size( maRectFlButtons.GetWidth(), maRectFlButtons.GetHeight() ) ); - maBtnHelp.SetPosPixel( Point( maRectBtnHelp.Left(), maRectBtnHelp.Top() ) ); - maBtnOK.SetPosPixel( Point( maRectBtnOK.Left(), maRectBtnOK.Top() ) ); - maBtnCancel.SetPosPixel( Point( maRectBtnCancel.Left(), maRectBtnCancel.Top() ) ); - } -} - -void ExportDialog::updateControls() -{ - GetGraphicStream(); - - // Size Controls - if ( !mbIsPixelFormat ) - { - awt::Size aSize100thmm( maSize ); - Size aSize( LogicToLogic( Size( aSize100thmm.Width * 100, aSize100thmm.Height * 100 ), MAP_100TH_MM, - MapMode( GetMapUnit( maLbSizeX.GetSelectEntryPos() ) ) ) ); - maMfSizeX.SetValue( aSize.Width() ); - maMfSizeY.SetValue( aSize.Height() ); - } - else - { - MapUnit aMapUnit( GetMapUnit( maLbSizeX.GetSelectEntryPos() ) ); - if ( aMapUnit == MAP_PIXEL ) - { // calculating pixel count via resolution and original graphic size - maMfSizeX.SetDecimalDigits( 0 ); - maMfSizeY.SetDecimalDigits( 0 ); - maMfSizeX.SetValue( maSize.Width ); - maMfSizeY.SetValue( maSize.Height ); - } - else - { - maMfSizeX.SetDecimalDigits( 2 ); - maMfSizeY.SetDecimalDigits( 2 ); - double fRatio; - switch( GetMapUnit( maLbSizeX.GetSelectEntryPos() ) ) - { - case MAP_INCH : fRatio = static_cast< double >( maResolution.Width ) * 0.0254; break; - case MAP_MM : fRatio = static_cast< double >( maResolution.Width ) * 0.001; break; - case MAP_POINT :fRatio = ( static_cast< double >( maResolution.Width ) * 0.0254 ) / 72.0; break; - default: - case MAP_CM : fRatio = static_cast< double >( maResolution.Width ) * 0.01; break; - } - maMfSizeX.SetValue( static_cast< sal_Int32 >( ( static_cast< double >( maSize.Width * 100 ) / fRatio ) + 0.5 ) ); - maMfSizeY.SetValue( static_cast< sal_Int32 >( ( static_cast< double >( maSize.Height * 100 ) / fRatio ) + 0.5 ) ); - } - } - sal_Int32 nResolution = 0; - switch( maLbResolution.GetSelectEntryPos() ) - { - case 0 : nResolution = maResolution.Width / 100; break; // pixels / cm - case 2 : nResolution = maResolution.Width; break; // pixels / meter - default: - case 1 : nResolution = static_cast< sal_Int32 >(maResolution.Width * 0.0254); break; // pixels / inch - } - maNfResolution.SetValue( nResolution ); - - if ( maSbCompression.IsVisible() ) - maSbCompression.SetThumbPos( maNfCompression.GetValue() ); - - // updating estimated size - sal_Int64 nRealFileSize( mpTempStream->Tell() ); - if ( mbIsPixelFormat ) - { - String aEst( nRealFileSize ? msEstimatedSizePix2 : msEstimatedSizePix1 ); - sal_Int64 nRawFileSize( GetRawFileSize() ); - xub_StrLen nInd = aEst.Search( '%' ); - aEst.Replace( nInd, 2, ImpValueOfInKB( nRawFileSize ) ); - - if ( nRealFileSize ) - { - nInd = aEst.Search( '%', nInd ); - aEst.Replace( nInd, 2, ImpValueOfInKB( nRealFileSize ) ); - } - maFtEstimatedSize.SetText( aEst ); - } - else - { - if ( mnMaxFilesizeForRealtimePreview ) - { - String aEst( msEstimatedSizeVec ); - xub_StrLen nInd = aEst.Search( '%', 0 ); - aEst.Replace( nInd, 2, ImpValueOfInKB( nRealFileSize ) ); - maFtEstimatedSize.SetText( aEst ); - } - } - updatePreview(); - - // EPS - if ( maRbEPSLevel1.IsVisible() ) - { - sal_Bool bEnabled = maRbEPSLevel1.IsChecked() == sal_False; - maRbEPSColorFormat1.Enable( bEnabled ); - maRbEPSColorFormat2.Enable( bEnabled ); - maRbEPSCompressionLZW.Enable( bEnabled ); - maRbEPSCompressionNone.Enable( bEnabled ); - } -} - -ExportDialog::~ExportDialog() -{ - delete mpFilterOptionsItem; - delete mpOptionsItem; -} - - -/************************************************************************* -|* -|* Speichert eingestellte Werte in ini-Datei -|* -\************************************************************************/ -IMPL_LINK( ExportDialog, UpdateHdl, void *, EMPTYARG ) -{ - updateControls(); - return 0; -} - -IMPL_LINK( ExportDialog, UpdateHdlMtfSizeX, void *, EMPTYARG ) -{ - double fRatio = static_cast< double >( maOriginalSize.Height ) / maOriginalSize.Width; - - if ( mbIsPixelFormat ) - { - switch( GetMapUnit( maLbSizeX.GetSelectEntryPos() ) ) - { - case MAP_INCH : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.0254 * maMfSizeX.GetValue() / 100.0 + 0.5 ); break; - case MAP_CM : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.01 * maMfSizeX.GetValue() / 100.0 + 0.5 ); break; - case MAP_MM : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.001 * maMfSizeX.GetValue() / 100.0 + 0.5 ); break; - case MAP_POINT : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.0254 * maMfSizeX.GetValue() / 100.0 * 72 + 0.5 ); break; - default: - case MAP_PIXEL : maSize.Width = maMfSizeX.GetValue(); break; - } - maSize.Height = static_cast< sal_Int32 >( fRatio * maSize.Width + 0.5 ); - } - else - { - Fraction aFract( 1, 100 ); - sal_Int32 nWidth = maMfSizeX.GetValue(); - sal_Int32 nHeight= static_cast< sal_Int32 >( nWidth * fRatio ); - const Size aSource( static_cast< sal_Int32 >( nWidth ), static_cast< sal_Int32 >( nHeight ) ); - MapMode aSourceMapMode( GetMapUnit( maLbSizeX.GetSelectEntryPos() ),Point(), aFract, aFract ); - Size aDest( LogicToLogic( aSource, aSourceMapMode, MAP_100TH_MM ) ); - - maSize.Width = aDest.Width(); - if ( mbPreserveAspectRatio ) - maSize.Height = aDest.Height(); - } - updateControls(); - return 0; -} - -IMPL_LINK( ExportDialog, UpdateHdlMtfSizeY, void *, EMPTYARG ) -{ - double fRatio = static_cast< double >( maOriginalSize.Width ) / maOriginalSize.Height; - - if ( mbIsPixelFormat ) - { - switch( GetMapUnit( maLbSizeX.GetSelectEntryPos() ) ) - { - case MAP_INCH : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.0254 * maMfSizeY.GetValue() / 100.0 + 0.5 ); break; - case MAP_CM : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.01 * maMfSizeY.GetValue() / 100.0 + 0.5 ); break; - case MAP_MM : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.001 * maMfSizeY.GetValue() / 100.0 + 0.5 ); break; - case MAP_POINT : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.0254 * maMfSizeY.GetValue() / 100.0 * 72 + 0.5 ); break; - default: - case MAP_PIXEL : maSize.Height = maMfSizeY.GetValue(); break; - } - maSize.Width = static_cast< sal_Int32 >( fRatio * maSize.Height + 0.5 ); - } - else - { - Fraction aFract( 1, 100 ); - sal_Int32 nHeight= maMfSizeY.GetValue(); - sal_Int32 nWidth = static_cast< sal_Int32 >( nHeight * fRatio ); - const Size aSource( static_cast< sal_Int32 >( nWidth ), static_cast< sal_Int32 >( nHeight ) ); - MapMode aSourceMapMode( GetMapUnit( maLbSizeX.GetSelectEntryPos() ),Point(), aFract, aFract ); - Size aDest( LogicToLogic( aSource, aSourceMapMode, MAP_100TH_MM ) ); - - maSize.Height = aDest.Height(); - if ( mbPreserveAspectRatio ) - maSize.Width = aDest.Width(); - } - updateControls(); - return 0; -} - -IMPL_LINK( ExportDialog, UpdateHdlNfResolution, void *, EMPTYARG ) -{ - sal_Int32 nResolution = maNfResolution.GetValue(); - if ( maLbResolution.GetSelectEntryPos() == 0 ) // pixels / cm - nResolution *= 100; - else if ( maLbResolution.GetSelectEntryPos() == 1 ) // pixels / inch - nResolution = static_cast< sal_Int32 >( ( ( static_cast< double >( nResolution ) + 0.5 ) / 0.0254 ) ); - maResolution.Width = nResolution; - maResolution.Height= nResolution; - - updateControls(); - return 0; -} - -IMPL_LINK( ExportDialog, SbCompressionUpdateHdl, void *, EMPTYARG ) -{ - maNfCompression.SetValue( maSbCompression.GetThumbPos() ); - updateControls(); - return 0; -} - -IMPL_LINK( ExportDialog, OK, void *, EMPTYARG ) -{ - // writing config parameter - - - mrFltCallPara.aFilterData = GetFilterData( sal_True ); - EndDialog( RET_OK ); - - return 0; -} - diff --git a/svtools/source/filter.vcl/filter/exportdialog.hrc b/svtools/source/filter.vcl/filter/exportdialog.hrc deleted file mode 100755 index e230bcd2c5c3..000000000000 --- a/svtools/source/filter.vcl/filter/exportdialog.hrc +++ /dev/null @@ -1,99 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#include - -#define BTN_OK 1 -#define BTN_CANCEL 1 -#define BTN_HELP 1 - -#define FL_EXPORT_SIZE 1 -#define FL_COLOR_DEPTH 2 -#define FL_JPG_QUALITY 3 -#define FL_COMPRESSION 4 -#define FL_MODE 5 -#define FL_GIF_DRAWING_OBJECTS 6 -#define FL_PBM_OPTIONS 7 -#define FL_EPS_PREVIEW 8 -#define FL_EPS_VERSION 9 -#define FL_EPS_COLOR_FORMAT 10 -#define FL_ESTIMATED_SIZE 11 -#define FL_BUTTONS 12 - -#define FT_SIZEX 1 -#define FT_SIZEY 2 -#define FT_RESOLUTION 3 -#define FT_JPG_MIN 4 -#define FT_JPG_MAX 5 -#define FT_PNG_MIN 6 -#define FT_PNG_MAX 7 -#define FT_ESTIMATED_SIZE 8 - -#define NF_RESOLUTION 1 -#define NF_COMPRESSION 2 -#define NF_ZOOM 3 - -#define MF_SIZEX 1 -#define MF_SIZEY 2 - -#define LB_SIZEX 1 -#define LB_SIZEY 2 -#define LB_RESOLUTION 3 -#define LB_COLOR_DEPTH 4 - -#define RB_BINARY 1 -#define RB_TEXT 2 -#define RB_EPS_LEVEL1 3 -#define RB_EPS_LEVEL2 4 -#define RB_EPS_COLOR_FORMAT1 5 -#define RB_EPS_COLOR_FORMAT2 6 -#define RB_EPS_COMPRESSION_LZW 7 -#define RB_EPS_COMPRESSION_NONE 8 - -#define CB_JPG_PREVIEW 1 -#define CB_INTERLACED 2 -#define CB_RLE_ENCODING 3 -#define CB_SAVE_TRANSPARENCY 4 -#define CB_EPS_PREVIEW_TIFF 5 -#define CB_EPS_PREVIEW_EPSI 6 - -#define FB_JPG_PREVIEW 1 - -#define SB_COMPRESSION 1 -#define SB_JPG_PREVIEW_HORZ 2 -#define SB_JPG_PREVIEW_VERT 3 -#define SB_ZOOM 4 - -#define STR_1BIT_THRESHOLD 1 -#define STR_1BIT_DITHERED 2 -#define STR_4BIT_GRAYSCALE 3 -#define STR_4BIT_COLOR_PALETTE 4 -#define STR_8BIT_GRAYSCALE 5 -#define STR_8BIT_COLOR_PALETTE 6 -#define STR_24BIT_TRUE_COLOR 7 -#define STR_ESTIMATED_SIZE_PIX_1 8 -#define STR_ESTIMATED_SIZE_PIX_2 9 -#define STR_ESTIMATED_SIZE_VEC 10 diff --git a/svtools/source/filter.vcl/filter/exportdialog.hxx b/svtools/source/filter.vcl/filter/exportdialog.hxx deleted file mode 100755 index 20a9ac3ea832..000000000000 --- a/svtools/source/filter.vcl/filter/exportdialog.hxx +++ /dev/null @@ -1,216 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - - -#ifndef _EXPORTDIALOG_HXX_ -#define _EXPORTDIALOG_HXX_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/************************************************************************* -|* -|* Dialog zum Einstellen von Filteroptionen bei Pixelformaten -|* -\************************************************************************/ - -class FilterConfigItem; -class ExportDialog : public ModalDialog -{ -private: - - FltCallDialogParameter& - mrFltCallPara; - - ResMgr* mpMgr; - - const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > - mxMgr; - const com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& - mxSourceDocument; - - FixedLine maFlExportSize; - FixedText maFtSizeX; - MetricField maMfSizeX; - ListBox maLbSizeX; - FixedText maFtSizeY; - MetricField maMfSizeY; - ListBox maLbSizeY; - FixedText maFtResolution; - NumericField maNfResolution; - ListBox maLbResolution; - FixedLine maFlColorDepth; - ListBox maLbColorDepth; - FixedLine maFlJPGQuality; - FixedLine maFlMode; - FixedLine maFlPBMOptions; - ScrollBar maSbCompression; - NumericField maNfCompression; - FixedText maFtJPGMin; - FixedText maFtJPGMax; - FixedText maFtPNGMin; - FixedText maFtPNGMax; - CheckBox maCbJPGPreview; - CheckBox maCbInterlaced; - CheckBox maCbRLEEncoding; - FixedLine maFlGIFDrawingObjects; - CheckBox maCbSaveTransparency; - RadioButton maRbBinary; - RadioButton maRbText; - FixedLine maFlEPSPreview; - CheckBox maCbEPSPreviewTIFF; - CheckBox maCbEPSPreviewEPSI; - FixedLine maFlEPSVersion; - RadioButton maRbEPSLevel1; - RadioButton maRbEPSLevel2; - FixedLine maFlEPSColorFormat; - RadioButton maRbEPSColorFormat1; - RadioButton maRbEPSColorFormat2; - FixedLine maFlCompression; - RadioButton maRbEPSCompressionLZW; - RadioButton maRbEPSCompressionNone; - FixedLine maFlEstimatedSize; - FixedText maFtEstimatedSize; - String msEstimatedSizePix1; - String msEstimatedSizePix2; - String msEstimatedSizeVec; - FixedLine maFlButtons; - FixedBitmap maFbJPGPreview; - ScrollBar maSbZoom; - NumericField maNfZoom; - ScrollBar maSbJPGPreviewHorz; - ScrollBar maSbJPGPreviewVert; - OKButton maBtnOK; - CancelButton maBtnCancel; - HelpButton maBtnHelp; - - String ms1BitTreshold; - String ms1BitDithered; - String ms4BitGrayscale; - String ms4BitColorPalette; - String ms8BitGrayscale; - String ms8BitColorPalette; - String ms24BitColor; - - vcl::RowOrColumn maLayout; - Size maDialogSize; - - FilterConfigItem* mpOptionsItem; - FilterConfigItem* mpFilterOptionsItem; - - String maExt; - String maEstimatedSizeText; - sal_Int16 mnFormat; - sal_Int32 mnMaxFilesizeForRealtimePreview; - - Rectangle maRectFlButtons; - Rectangle maRectBtnHelp; - Rectangle maRectBtnOK; - Rectangle maRectBtnCancel; - - SvStream* mpTempStream; - Bitmap maBitmap; - - com::sun::star::awt::Size - maOriginalSize; // the original graphic size in 1/100mm - com::sun::star::awt::Size - maSize; // for vector graphics it always contains the logical size in 1/100mm - - sal_Bool mbPreview; - sal_Bool mbIsPixelFormat; - sal_Bool mbExportSelection; - sal_Bool mbPreserveAspectRatio; - - sal_Int32 mnInitialResolutionUnit; - - // for pixel graphics it always contains the pixel count - com::sun::star::awt::Size - maResolution; // it always contains the number of pixels per meter - - com::sun::star::uno::Reference< com::sun::star::drawing::XShape > - mxShape; - com::sun::star::uno::Reference< com::sun::star::drawing::XShapes > - mxShapes; - com::sun::star::uno::Reference< com::sun::star::drawing::XDrawPage > - mxPage; - - - DECL_LINK( UpdateHdl,void* p ); - DECL_LINK( UpdateHdlMtfSizeX,void* p ); - DECL_LINK( UpdateHdlMtfSizeY,void* p ); - DECL_LINK( UpdateHdlNfResolution,void* p ); - DECL_LINK( SbCompressionUpdateHdl,void* p ); - DECL_LINK( NfCompressionUpdateHdlX,void* p ); - - DECL_LINK( OK, void* p ); - - void createSizeControls( vcl::RowOrColumn& ); - void createColorDepthControls( vcl::RowOrColumn& ); - void createFilterOptions( vcl::RowOrColumn& ); - void createButtons( vcl::RowOrColumn& ); - void createScrollBar( vcl::RowOrColumn& ); - void setupLayout(); - void updatePreview(); - void updateControls(); - - void GetGraphicSource(); - sal_Bool GetGraphicStream(); - Bitmap GetGraphicBitmap( SvStream& rStream ); - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > - GetFilterData( sal_Bool bUpdateConfig ); - - sal_uInt32 GetRawFileSize() const; - sal_Bool IsTempExportAvailable() const; - - com::sun::star::awt::Size - GetOriginalSize(); - - sal_Int32 GetDefaultUnit(); - -public: - ExportDialog( FltCallDialogParameter& rPara, - const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > rxMgr, - const com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& rxSourceDocument, - sal_Bool bExportSelection, sal_Bool bIsExportVectorFormat ); - ~ExportDialog(); -}; - - - -#endif // _EXPORTDIALOG_HXX_ - diff --git a/svtools/source/filter.vcl/filter/exportdialog.src b/svtools/source/filter.vcl/filter/exportdialog.src deleted file mode 100644 index c9e87989a314..000000000000 --- a/svtools/source/filter.vcl/filter/exportdialog.src +++ /dev/null @@ -1,529 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include "exportdialog.hrc" - -String DLG_EXPORT_TITLE -{ - Text [ en-US ] = " Options" ; -}; - -ModalDialog DLG_EXPORT -{ - HelpID = "svtools:ModalDialog:DLG_EXPORT"; - OutputSize = TRUE ; - SVLook = TRUE ; - Size = MAP_APPFONT ( 178 , 135 ) ; - Moveable = TRUE ; - Closeable = TRUE ; - - FixedLine FL_EXPORT_SIZE - { - Hide = TRUE; - Size = MAP_APPFONT ( 110 , 8 ) ; - Text [ en-US ] = "Size" ; - }; - FixedText FT_SIZEX - { - Hide = TRUE; - Size = MAP_APPFONT ( 41 , 10 ) ; - Text [ en-US ] = "Width:" ; - }; - MetricField MF_SIZEX - { - HelpID = "svtools:MetricField:DLG_EXPORT:MF_SIZEX"; - Hide = TRUE; - Border = TRUE; - Size = MAP_APPFONT ( 30, 12 ) ; - TabStop = TRUE; - Repeat = TRUE; - Spin = FALSE; - StrictFormat = TRUE; - DecimalDigits = 2; - Unit = FUNIT_NONE; - Maximum = 99999; - Last = 255; - }; - ListBox LB_SIZEX - { - HelpID = "svtools:ListBox:DLG_EXPORT:LB_SIZEX"; - Hide = TRUE; - Border = TRUE ; - Size = MAP_APPFONT ( 60, 80 ) ; - DropDown = TRUE ; - Sort = FALSE ; - StringList [ en-US ] = - { - < "inches" ; > ; - < "cm" ; Default ; > ; - < "mm" ; > ; - < "points" ; > ; - < "pixels" ; > ; - }; - }; - FixedText FT_SIZEY - { - Hide = TRUE; - Size = MAP_APPFONT ( 41 , 10 ) ; - Text [ en-US ] = "Height:" ; - }; - MetricField MF_SIZEY - { - HelpID = "svtools:MetricField:DLG_EXPORT:MF_SIZEY"; - Hide = TRUE; - Border = TRUE; - Size = MAP_APPFONT ( 30, 12 ); - TabStop = TRUE; - Repeat = TRUE; - Spin = FALSE; - StrictFormat = TRUE; - DecimalDigits = 2; - Unit = FUNIT_NONE; - Maximum = 99999; - Last = 255 ; - }; - ListBox LB_SIZEY - { - HelpID = "svtools:ListBox:DLG_EXPORT:LB_SIZEY"; - Hide = TRUE; - Border = TRUE ; - Size = MAP_APPFONT ( 60, 80 ) ; - DropDown = TRUE ; - Sort = FALSE ; - StringList [ en-US ] = - { - < "inches" ; > ; - < "cm" ; Default ; > ; - < "mm" ; > ; - < "points" ; > ; - < "pixels" ; > ; - }; - }; - FixedText FT_RESOLUTION - { - Hide = TRUE; - Size = MAP_APPFONT ( 41 , 10 ) ; - Text [ en-US ] = "Resolution:" ; - }; - NumericField NF_RESOLUTION - { - HelpID = "svtools:NumericField:DLG_EXPORT:NF_RESOLUTION"; - Hide = TRUE; - Border = TRUE ; - Size = MAP_APPFONT ( 30, 12 ) ; - TabStop = TRUE ; - Repeat = TRUE ; - Spin = FALSE ; - Maximum = 99999; - Last = 255 ; - }; - ListBox LB_RESOLUTION - { - HelpID = "svtools:ListBox:DLG_EXPORT:LB_RESOLUTION"; - Hide = TRUE; - Border = TRUE ; - Size = MAP_APPFONT ( 60, 80 ) ; - DropDown = TRUE ; - Sort = FALSE ; - StringList [ en-US ] = - { - < "pixels/cm" ; > ; - < "pixels/inch" ; Default ; > ; - < "pixels/meter" ; > ; - }; - }; - FixedLine FL_COLOR_DEPTH - { - Hide = TRUE; - Size = MAP_APPFONT ( 110 , 8 ) ; - Text [ en-US ] = "Color Depth" ; - }; - ListBox LB_COLOR_DEPTH - { - HelpID = "svtools:ListBox:DLG_EXPORT:LB_COLOR_DEPTH"; - Hide = TRUE; - Border = TRUE ; - Size = MAP_APPFONT ( 60, 80 ) ; - DropDown = TRUE ; - Sort = FALSE ; - }; - String STR_1BIT_THRESHOLD - { - Text [ en-US ] = "1 bit threshold"; - }; - String STR_1BIT_DITHERED - { - Text [ en-US ] = "1 bit dithered"; - }; - String STR_4BIT_GRAYSCALE - { - Text [ en-US ] = "4 bit grayscale"; - }; - String STR_4BIT_COLOR_PALETTE - { - Text [ en-US ] = "4 bit color"; - }; - String STR_8BIT_GRAYSCALE - { - Text [ en-US ] = "8 bit grayscale"; - }; - String STR_8BIT_COLOR_PALETTE - { - Text [ en-US ] = "8 bit color"; - }; - String STR_24BIT_TRUE_COLOR - { - Text [ en-US ] = "24 bit true color"; - }; - FixedLine FL_JPG_QUALITY - { - Hide = TRUE; - Size = MAP_APPFONT ( 110 , 8 ) ; - Text [ en-US ] = "Quality" ; - }; - FixedLine FL_COMPRESSION - { - Hide = TRUE; - Size = MAP_APPFONT ( 110 , 8 ) ; - Text [ en-US ] = "Compression" ; - }; - FixedLine FL_MODE - { - Hide = TRUE; - Size = MAP_APPFONT ( 110 , 8 ) ; - Text [ en-US ] = "Mode" ; - }; - FixedLine FL_PBM_OPTIONS - { - Hide = TRUE; - Size = MAP_APPFONT ( 110 , 8 ) ; - Text [ en-US ] = "File Format" ; - }; - ScrollBar SB_COMPRESSION - { - Hide = TRUE; - Size = MAP_APPFONT ( 48, 10 ) ; - VScroll = FALSE ; - HScroll = TRUE; - Drag = TRUE ; - }; - NumericField NF_COMPRESSION - { - HelpID = "svtools:NumericField:DLG_EXPORT:NF_COMPRESSION"; - Hide = TRUE; - Border = TRUE ; - Size = MAP_APPFONT ( 30, 12 ) ; - TabStop = TRUE ; - Repeat = TRUE ; - Spin = FALSE ; - Maximum = 99999; - Last = 255 ; - }; - FixedText FT_JPG_MIN - { - Hide = TRUE; - Size = MAP_APPFONT ( 41 , 10 ) ; - Text [ en-US ] = "1 is minimum Quality and smallest file size." ; - }; - FixedText FT_JPG_MAX - { - Hide = TRUE; - Size = MAP_APPFONT ( 41 , 10 ) ; - Text [ en-US ] = "100 is maximum Quality and biggest file size." ; - }; - FixedText FT_PNG_MIN - { - Hide = TRUE; - Size = MAP_APPFONT ( 41 , 10 ) ; - Text [ en-US ] = "0 is biggest file size and fastest loading." ; - }; - FixedText FT_PNG_MAX - { - Hide = TRUE; - Size = MAP_APPFONT ( 41 , 10 ) ; - Text [ en-US ] = "9 is smallest file size and slowest loading." ; - }; - CheckBox CB_JPG_PREVIEW - { - HelpID = "svtools:CheckBox:DLG_EXPORT:CB_JPG_PREVIEW"; - Hide = TRUE; - Size = MAP_APPFONT ( 60 , 10 ) ; - Text [ en-US ] = "Preview" ; - }; - CheckBox CB_INTERLACED - { - HelpID = "svtools:CheckBox:DLG_EXPORT:CB_INTERLACED"; - Hide = TRUE; - Size = MAP_APPFONT ( 60 , 10 ) ; - Text [ en-US ] = "Interlaced" ; - }; - CheckBox CB_RLE_ENCODING - { - HelpID = "svtools:CheckBox:DLG_EXPORT:CB_RLE_ENCODING"; - Hide = TRUE; - Size = MAP_APPFONT ( 60 , 10 ) ; - Text [ en-US ] = "RLE encoding" ; - }; - FixedLine FL_GIF_DRAWING_OBJECTS - { - Hide = TRUE; - Size = MAP_APPFONT ( 110 , 8 ) ; - Text [ en-US ] = "Drawing Objects" ; - }; - CheckBox CB_SAVE_TRANSPARENCY - { - HelpID = "svtools:CheckBox:DLG_EXPORT:CB_SAVE_TRANSPARENCY"; - Hide = TRUE; - Size = MAP_APPFONT ( 60 , 10 ) ; - Text [ en-US ] = "Save transparency" ; - }; - RadioButton RB_BINARY - { - HelpID = "svtools:RadioButton:DLG_EXPORT:RB_BINARY"; - Hide = TRUE; - Size = MAP_APPFONT ( 105 , 10 ) ; - Text [ en-US ] = "Binary" ; - }; - RadioButton RB_TEXT - { - HelpID = "svtools:RadioButton:DLG_EXPORT:RB_TEXT"; - Hide = TRUE; - Size = MAP_APPFONT ( 105 , 10 ) ; - Text [ en-US ] = "Text" ; - }; - FixedLine FL_EPS_PREVIEW - { - Hide = TRUE; - Size = MAP_APPFONT ( 110 , 8 ) ; - Text [ en-US ] = "Preview" ; - }; - CheckBox CB_EPS_PREVIEW_TIFF - { - HelpID = "svtools:CheckBox:DLG_EXPORT:CB_EPS_PREVIEW_TIFF"; - Hide = TRUE; - Size = MAP_APPFONT ( 60 , 10 ) ; - Text [ en-US ] = "Image Preview (TIFF)" ; - }; - CheckBox CB_EPS_PREVIEW_EPSI - { - HelpID = "svtools:CheckBox:DLG_EXPORT:CB_EPS_PREVIEW_EPSI"; - Hide = TRUE; - Size = MAP_APPFONT ( 60 , 10 ) ; - Text [ en-US ] = "Interchange (EPSI)" ; - }; - FixedLine FL_EPS_VERSION - { - Hide = TRUE; - Size = MAP_APPFONT ( 41 , 10 ) ; - Text [ en-US ] = "Version" ; - }; - RadioButton RB_EPS_LEVEL1 - { - HelpID = "svtools:RadioButton:DLG_EXPORT:RB_EPS_LEVEL1"; - Hide = TRUE; - Size = MAP_APPFONT ( 105 , 10 ) ; - Text [ en-US ] = "Level 1" ; - }; - RadioButton RB_EPS_LEVEL2 - { - HelpID = "svtools:RadioButton:DLG_EXPORT:RB_EPS_LEVEL2"; - Hide = TRUE; - Size = MAP_APPFONT ( 105 , 10 ) ; - Text [ en-US ] = "Level 2" ; - }; - FixedLine FL_EPS_COLOR_FORMAT - { - Hide = TRUE; - Size = MAP_APPFONT ( 41 , 10 ) ; - Text [ en-US ] = "Color format" ; - }; - RadioButton RB_EPS_COLOR_FORMAT1 - { - HelpID = "svtools:RadioButton:DLG_EXPORT:RB_EPS_COLOR_FORMAT1"; - Hide = TRUE; - Size = MAP_APPFONT ( 105 , 10 ) ; - Text [ en-US ] = "Color" ; - }; - RadioButton RB_EPS_COLOR_FORMAT2 - { - HelpID = "svtools:RadioButton:DLG_EXPORT:RB_EPS_COLOR_FORMAT2"; - Hide = TRUE; - Size = MAP_APPFONT ( 105 , 10 ) ; - Text [ en-US ] = "Grayscale" ; - }; - RadioButton RB_EPS_COMPRESSION_LZW - { - HelpID = "svtools:RadioButton:DLG_EXPORT:RB_EPS_COMPRESSION_LZW"; - Hide = TRUE; - Size = MAP_APPFONT ( 105 , 10 ) ; - Text [ en-US ] = "LZW encoding" ; - }; - RadioButton RB_EPS_COMPRESSION_NONE - { - HelpID = "svtools:RadioButton:DLG_EXPORT:RB_EPS_COMPRESSION_NONE"; - Hide = TRUE; - Size = MAP_APPFONT ( 105 , 10 ) ; - Text [ en-US ] = "None" ; - }; - FixedLine FL_ESTIMATED_SIZE - { - Hide = TRUE; - Size = MAP_APPFONT ( 41 , 10 ) ; - }; - FixedText FT_ESTIMATED_SIZE - { - Hide = TRUE; - Size = MAP_APPFONT ( 41 , 10 ) ; - }; - String STR_ESTIMATED_SIZE_PIX_1 - { - Text [ en-US ] = "The picture needs about %1 KB of memory."; - }; - String STR_ESTIMATED_SIZE_PIX_2 - { - Text [ en-US ] = "The picture needs about %1 KB of memory,\n the file size is %2 KB."; - }; - String STR_ESTIMATED_SIZE_VEC - { - Text [ en-US ] = "The file size is %1 KB."; - }; - FixedLine FL_BUTTONS - { - Hide = TRUE; - Size = MAP_APPFONT ( 41 , 10 ) ; - }; - FixedBitmap FB_JPG_PREVIEW - { - Hide = TRUE; - OutputSize = TRUE ; - Scale = TRUE; - Border = TRUE; - }; - ScrollBar SB_ZOOM - { - Hide = TRUE; - Size = MAP_APPFONT ( 48, 10 ); - VScroll = FALSE; - HScroll = TRUE; - Drag = TRUE; - MinPos = 5; - MaxPos = 100; - ThumbPos = 50; - }; - NumericField NF_ZOOM - { - HelpID = "svtools:NumericField:DLG_EXPORT:NF_ZOOM"; - Hide = TRUE; - Border = TRUE ; - Size = MAP_APPFONT ( 30, 12 ) ; - TabStop = TRUE ; - Repeat = TRUE ; - Spin = FALSE ; - Maximum = 3000; - Last = 255 ; - }; - ScrollBar SB_JPG_PREVIEW_HORZ - { - Hide = TRUE; - Size = MAP_APPFONT ( 48, 10 ); - VScroll = FALSE; - HScroll = TRUE; - Drag = TRUE; - MinPos = 0; - MaxPos = 100; - ThumbPos = 50; - }; - ScrollBar SB_JPG_PREVIEW_VERT - { - Hide = TRUE; - Size = MAP_APPFONT ( 48, 10 ); - VScroll = TRUE; - HScroll = FALSE; - Drag = TRUE; - MinPos = 0; - MaxPos = 100; - ThumbPos = 50; - }; - OKButton BTN_OK - { - Hide = TRUE; - Size = MAP_APPFONT ( 50 , 14 ) ; - TabStop = TRUE ; - DefButton = TRUE ; - }; - CancelButton BTN_CANCEL - { - Hide = TRUE; - Size = MAP_APPFONT ( 50 , 14 ) ; - TabStop = TRUE ; - }; - HelpButton BTN_HELP - { - Hide = TRUE; - Size = MAP_APPFONT ( 50 , 14 ) ; - TabStop = TRUE ; - }; -}; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/svtools/source/filter.vcl/filter/filter.cxx b/svtools/source/filter.vcl/filter/filter.cxx deleted file mode 100644 index 7e0729082841..000000000000 --- a/svtools/source/filter.vcl/filter/filter.cxx +++ /dev/null @@ -1,2199 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#if defined UNX && defined ALPHA -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "FilterConfigCache.hxx" -#include -#include -#include -#include "gifread.hxx" -#include "jpeg.hxx" -#include "xbmread.hxx" -#include "xpmread.hxx" -#include -#include -#include "sgffilt.hxx" -#include "osl/module.hxx" -#include -#include -#include -#include -#include -#ifndef _COM_SUN_STAR_UNO_XTYPEPROVIDER_HPP_ -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "SvFilterOptionsDialog.hxx" - -#define PMGCHUNG_msOG 0x6d734f47 // Microsoft Office Animated GIF - -#if (defined OS2 && !defined ICC) - -#define IMPORT_FUNCTION_NAME "_GraphicImport" -#define EXPORT_FUNCTION_NAME "_GraphicExport" -#define IMPDLG_FUNCTION_NAME "_DoImportDialog" -#define EXPDLG_FUNCTION_NAME "_DoExportDialog" - -#else - -#define IMPORT_FUNCTION_NAME "GraphicImport" -#define EXPORT_FUNCTION_NAME "GraphicExport" -#define IMPDLG_FUNCTION_NAME "DoImportDialog" -#define EXPDLG_FUNCTION_NAME "DoExportDialog" - -#endif - - -// ----------- -// - statics - -// ----------- - -using namespace ::rtl; -using namespace ::com::sun::star; - -static List* pFilterHdlList = NULL; - -static ::osl::Mutex& getListMutex() -{ - static ::osl::Mutex s_aListProtection; - return s_aListProtection; -} - -static GraphicFilter* pGraphicFilter=0; - -// ------------------------- -// - ImpFilterOutputStream - -// ------------------------- - -class ImpFilterOutputStream : public ::cppu::WeakImplHelper1< ::com::sun::star::io::XOutputStream > -{ -protected: - - SvStream& mrStm; - - virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< sal_Int8 >& rData ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) { mrStm.Write( rData.getConstArray(), rData.getLength() ); } - virtual void SAL_CALL flush() throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) { mrStm.Flush(); } - virtual void SAL_CALL closeOutput() throw() {} - -public: - - ImpFilterOutputStream( SvStream& rStm ) : mrStm( rStm ) {} - ~ImpFilterOutputStream() {} -}; - -BOOL ImplDirEntryHelper::Exists( const INetURLObject& rObj ) -{ - BOOL bExists = FALSE; - - try - { - ::rtl::OUString aTitle; - ::ucbhelper::Content aCnt( rObj.GetMainURL( INetURLObject::NO_DECODE ), - ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() ); - - bExists = aCnt.isDocument(); - } - catch( ::com::sun::star::ucb::CommandAbortedException& ) - { - DBG_ERRORFILE( "CommandAbortedException" ); - } - catch( ::com::sun::star::ucb::ContentCreationException& ) - { - DBG_ERRORFILE( "ContentCreationException" ); - } - catch( ... ) - { -// DBG_ERRORFILE( "Any other exception" ); - } - return bExists; -} - -// ----------------------------------------------------------------------------- - -void ImplDirEntryHelper::Kill( const String& rMainUrl ) -{ - try - { - ::ucbhelper::Content aCnt( rMainUrl, - ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() ); - - aCnt.executeCommand( ::rtl::OUString::createFromAscii( "delete" ), - ::com::sun::star::uno::makeAny( sal_Bool( sal_True ) ) ); - } - catch( ::com::sun::star::ucb::CommandAbortedException& ) - { - DBG_ERRORFILE( "CommandAbortedException" ); - } - catch( ... ) - { - DBG_ERRORFILE( "Any other exception" ); - } -} - -// -------------------- -// - Helper functions - -// -------------------- - -//-------------------------------------------------------------------------- - -BYTE* ImplSearchEntry( BYTE* pSource, BYTE* pDest, ULONG nComp, ULONG nSize ) -{ - while ( nComp-- >= nSize ) - { - ULONG i; - for ( i = 0; i < nSize; i++ ) - { - if ( ( pSource[i]&~0x20 ) != ( pDest[i]&~0x20 ) ) - break; - } - if ( i == nSize ) - return pSource; - pSource++; - } - return NULL; -} - -//-------------------------------------------------------------------------- - -inline String ImpGetExtension( const String &rPath ) -{ - String aExt; - INetURLObject aURL( rPath ); - aExt = aURL.GetFileExtension().toAsciiUpperCase(); - return aExt; -} - -/************************************************************************* -|* -|* ImpPeekGraphicFormat() -|* -|* Beschreibung: -|* Diese Funktion kann zweierlei: -|* 1.) Datei anlesen, Dateiformat ermitteln -|* Eingabe-prarameter: -|* rPath - Dateipfad -|* rFormatExtension - Inhalt egal -|* bTest - setze FALSE -|* Ausgabe-parameter: -|* Funkionswert - TRUE wenn Erfolg -|* rFormatExtension - Bei Erfolg: uebliche Dateiendung -|* des Formats (Grossbuchstaben) -|* 2.) Datei anlesen, Dateiformat ueberpruefen -|* Eingabe-prarameter: -|* rPath - Dateipfad -|* rFormatExtension - uebliche Dateiendung des Formats -|* (Grossbuchstaben) -|* bTest - setze TRUE -|* Ausgabe-parameter: -|* Funkionswert - FALSE, wenn die Datei bestimmt nicht -|* vom uebgebenen Format ist. -|* TRUE, wenn die Datei WAHRSCHEINLICH von -|* dem Format ist, ODER WENN DAS FORMAT -|* DIESER FUNKTION NICHT BEKANNT IST! -|* -|* Ersterstellung OH 26.05.95 -|* Letzte Aenderung OH 07.08.95 -|* -*************************************************************************/ - -static BOOL ImpPeekGraphicFormat( SvStream& rStream, String& rFormatExtension, BOOL bTest ) -{ - USHORT i; - BYTE sFirstBytes[ 256 ]; - ULONG nFirstLong,nSecondLong; - ULONG nStreamPos = rStream.Tell(); - - rStream.Seek( STREAM_SEEK_TO_END ); - ULONG nStreamLen = rStream.Tell() - nStreamPos; - rStream.Seek( nStreamPos ); - - if ( !nStreamLen ) - { - SvLockBytes* pLockBytes = rStream.GetLockBytes(); - if ( pLockBytes ) - pLockBytes->SetSynchronMode( TRUE ); - - rStream.Seek( STREAM_SEEK_TO_END ); - nStreamLen = rStream.Tell() - nStreamPos; - rStream.Seek( nStreamPos ); - } - // Die ersten 256 Bytes in einen Buffer laden: - if( nStreamLen >= 256 ) - rStream.Read( sFirstBytes, 256 ); - else - { - rStream.Read( sFirstBytes, nStreamLen ); - - for( i = (USHORT) nStreamLen; i < 256; i++ ) - sFirstBytes[ i ]=0; - } - - if( rStream.GetError() ) - return FALSE; - - // Die ersten 8 Bytes in nFirstLong, nSecondLong unterbringen, - // Big-Endian: - for( i = 0, nFirstLong = 0L, nSecondLong = 0L; i < 4; i++ ) - { - nFirstLong=(nFirstLong<<8)|(ULONG)sFirstBytes[i]; - nSecondLong=(nSecondLong<<8)|(ULONG)sFirstBytes[i+4]; - } - - // Folgende Variable ist nur bei bTest==TRUE interessant. Sie - // bleibt FALSE, wenn das Format (rFormatExtension) hier noch nicht - // einprogrammiert wurde. - BOOL bSomethingTested = FALSE; - - // Nun werden die verschieden Formate ueberprueft. Dabei ist die - // Reihenfolge nicht egal. Z.b. koennte eine MET-Datei auch durch - // den BMP-Test gehen, umgekehrt kann eine BMP-Datei kaum durch den - // MET-Test gehen. Also sollte MET vor BMP getestet werden. - // Theoretisch waere aber vielleicht auch eine BMP-Datei denkbar, - // die durch den MET-Test geht. - // Diese Probleme gibt es natuerlich nicht nur bei MET und BMP. - // Deshalb wird im Falle der Uberpruefung eines Formats (bTest==TRUE) - // nur genau dieses eine Format getestet. Alles andere koennte fatale - // Folgen haben, z.B. wenn der Benutzer sagt, es sei BMP-Datei (und es - // ist BMP-Datei), und hier wuerde die Datei durch den MET-Test gehen... - - //--------------------------- MET ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "MET", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested=TRUE; - if( sFirstBytes[2] == 0xd3 ) - { - rStream.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); - rStream.Seek( nStreamPos ); - USHORT nFieldSize; - BYTE nMagic; - BOOL bOK=TRUE; - rStream >> nFieldSize >> nMagic; - for (i=0; i<3; i++) { - if (nFieldSize<6) { bOK=FALSE; break; } - if (nStreamLen < rStream.Tell() + nFieldSize ) { bOK=FALSE; break; } - rStream.SeekRel(nFieldSize-3); - rStream >> nFieldSize >> nMagic; - if (nMagic!=0xd3) { bOK=FALSE; break; } - } - rStream.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); - if (bOK && !rStream.GetError()) { - rFormatExtension= UniString::CreateFromAscii( "MET", 3 ); - return TRUE; - } - } - } - - //--------------------------- BMP ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "BMP", 3 ) == COMPARE_EQUAL ) ) - { - BYTE nOffs; - - bSomethingTested=TRUE; - - // OS/2-Bitmaparray ('BA') koennen wir evtl. auch lesen, - // dementspr. muessen wir den Offset anpassen, - // um auf die erste Bitmap im Array zu stossen - if ( sFirstBytes[0] == 0x42 && sFirstBytes[1] == 0x41 ) - nOffs = 14; - else - nOffs = 0; - - // Jetzt testen wir zunaechst auf 'BM' - if ( sFirstBytes[0+nOffs]==0x42 && sFirstBytes[1+nOffs]==0x4d ) - { - // unter OS/2 koennen die Reserved-Flags != 0 sein - // (was sie eigentlich nicht duerften); - // in diesem Fall testen wir die Groesse des BmpInfoHeaders - if ( ( sFirstBytes[6+nOffs]==0x00 && - sFirstBytes[7+nOffs]==0x00 && - sFirstBytes[8+nOffs]==0x00 && - sFirstBytes[9+nOffs]==0x00 ) || - sFirstBytes[14+nOffs] == 0x28 || - sFirstBytes[14+nOffs] == 0x0c ) - { - rFormatExtension = UniString::CreateFromAscii( "BMP", 3 ); - return TRUE; - } - } - } - - //--------------------------- WMF/EMF ------------------------------------ - - if( !bTest || - ( rFormatExtension.CompareToAscii( "WMF", 3 ) == COMPARE_EQUAL ) || - ( rFormatExtension.CompareToAscii( "EMF", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested = TRUE; - - if ( nFirstLong==0xd7cdc69a || nFirstLong==0x01000900 ) - { - rFormatExtension = UniString::CreateFromAscii( "WMF", 3 ); - return TRUE; - } - else if( nFirstLong == 0x01000000 && sFirstBytes[ 40 ] == 0x20 && sFirstBytes[ 41 ] == 0x45 && - sFirstBytes[ 42 ] == 0x4d && sFirstBytes[ 43 ] == 0x46 ) - { - rFormatExtension = UniString::CreateFromAscii( "EMF", 3 ); - return TRUE; - } - } - - //--------------------------- PCX ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "PCX", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested=TRUE; - if (sFirstBytes[0]==0x0a) - { - BYTE nVersion=sFirstBytes[1]; - BYTE nEncoding=sFirstBytes[2]; - if( ( nVersion==0 || nVersion==2 || nVersion==3 || nVersion==5 ) && nEncoding<=1 ) - { - rFormatExtension = UniString::CreateFromAscii( "PCX", 3 ); - return TRUE; - } - } - } - - //--------------------------- TIF ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "TIF", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested=TRUE; - if ( nFirstLong==0x49492a00 || nFirstLong==0x4d4d002a ) - { - rFormatExtension=UniString::CreateFromAscii( "TIF", 3 ); - return TRUE; - } - } - - //--------------------------- GIF ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "GIF", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested=TRUE; - if ( nFirstLong==0x47494638 && (sFirstBytes[4]==0x37 || sFirstBytes[4]==0x39) && sFirstBytes[5]==0x61 ) - { - rFormatExtension = UniString::CreateFromAscii( "GIF", 3 ); - return TRUE; - } - } - - //--------------------------- PNG ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "PNG", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested=TRUE; - if (nFirstLong==0x89504e47 && nSecondLong==0x0d0a1a0a) - { - rFormatExtension = UniString::CreateFromAscii( "PNG", 3 ); - return TRUE; - } - } - - //--------------------------- JPG ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "JPG", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested=TRUE; - if ( ( nFirstLong==0xffd8ffe0 && sFirstBytes[6]==0x4a && sFirstBytes[7]==0x46 && sFirstBytes[8]==0x49 && sFirstBytes[9]==0x46 ) || - ( nFirstLong==0xffd8fffe ) || ( 0xffd8ff00 == ( nFirstLong & 0xffffff00 ) ) ) - { - rFormatExtension = UniString::CreateFromAscii( "JPG", 3 ); - return TRUE; - } - } - - //--------------------------- SVM ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "SVM", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested=TRUE; - if( nFirstLong==0x53564744 && sFirstBytes[4]==0x49 ) - { - rFormatExtension = UniString::CreateFromAscii( "SVM", 3 ); - return TRUE; - } - else if( sFirstBytes[0]==0x56 && sFirstBytes[1]==0x43 && sFirstBytes[2]==0x4C && - sFirstBytes[3]==0x4D && sFirstBytes[4]==0x54 && sFirstBytes[5]==0x46 ) - { - rFormatExtension = UniString::CreateFromAscii( "SVM", 3 ); - return TRUE; - } - } - - //--------------------------- PCD ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "PCD", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested = TRUE; - if( nStreamLen >= 2055 ) - { - char sBuf[8]; - rStream.Seek( nStreamPos + 2048 ); - rStream.Read( sBuf, 7 ); - - if( strncmp( sBuf, "PCD_IPI", 7 ) == 0 ) - { - rFormatExtension = UniString::CreateFromAscii( "PCD", 3 ); - return TRUE; - } - } - } - - //--------------------------- PSD ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "PSD", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested = TRUE; - if ( ( nFirstLong == 0x38425053 ) && ( (nSecondLong >> 16 ) == 1 ) ) - { - rFormatExtension = UniString::CreateFromAscii( "PSD", 3 ); - return TRUE; - } - } - - //--------------------------- EPS ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "EPS", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested = TRUE; - if ( ( nFirstLong == 0xC5D0D3C6 ) || ( ImplSearchEntry( sFirstBytes, (BYTE*)"%!PS-Adobe", 10, 10 ) && - ImplSearchEntry( &sFirstBytes[15], (BYTE*)"EPS", 3, 3 ) ) ) - { - rFormatExtension = UniString::CreateFromAscii( "EPS", 3 ); - return TRUE; - } - } - - //--------------------------- DXF ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "DXF", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested=TRUE; - - i=0; - while (i<256 && sFirstBytes[i]<=32) - i++; - - if (i<256) - { - if( sFirstBytes[i]=='0' ) - i++; - else - i=256; - } - while( i<256 && sFirstBytes[i]<=32 ) - i++; - - if (i+7<256) - { - if (strncmp((char*)(sFirstBytes+i),"SECTION",7)==0) - { - rFormatExtension = UniString::CreateFromAscii( "DXF", 3 ); - return TRUE; - } - } - - if( strncmp( (char*) sFirstBytes, "AutoCAD Binary DXF", 18 ) == 0 ) - { - rFormatExtension = UniString::CreateFromAscii( "DXF", 3 ); - return TRUE; - } - } - - //--------------------------- PCT ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "PCT", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested = TRUE; - BYTE sBuf[3]; - // store number format - sal_uInt16 oldNumberFormat = rStream.GetNumberFormatInt(); - sal_uInt32 nOffset; // in ms documents the pict format is used without the first 512 bytes - for ( nOffset = 0; ( nOffset <= 512 ) && ( ( nStreamPos + nOffset + 14 ) <= nStreamLen ); nOffset += 512 ) - { - short y1,x1,y2,x2; - bool bdBoxOk = true; - - rStream.Seek( nStreamPos + nOffset); - // size of the pict in version 1 pict ( 2bytes) : ignored - rStream.SeekRel(2); - // bounding box (bytes 2 -> 9) - rStream.SetNumberFormatInt(NUMBERFORMAT_INT_BIGENDIAN); - rStream >> y1 >> x1 >> y2 >> x2; - rStream.SetNumberFormatInt(oldNumberFormat); // reset format - - if (x1 > x2 || y1 > y2 || // bad bdbox - (x1 == x2 && y1 == y2) || // 1 pixel picture - x2-x1 > 2048 || y2-y1 > 2048 ) // picture anormaly big - bdBoxOk = false; - - // read version op - rStream.Read( sBuf,3 ); - // see http://developer.apple.com/legacy/mac/library/documentation/mac/pdf/Imaging_With_QuickDraw/Appendix_A.pdf - // normal version 2 - page A23 and A24 - if ( sBuf[ 0 ] == 0x00 && sBuf[ 1 ] == 0x11 && sBuf[ 2 ] == 0x02) - { - rFormatExtension = UniString::CreateFromAscii( "PCT", 3 ); - return TRUE; - } - // normal version 1 - page A25 - else if (sBuf[ 0 ] == 0x11 && sBuf[ 1 ] == 0x01 && bdBoxOk) { - rFormatExtension = UniString::CreateFromAscii( "PCT", 3 ); - return TRUE; - } - // previous code kept in order to do not break any compatibility - // probably eroneous - else if ( sBuf[ 0 ] == 0x00 && sBuf[ 1 ] == 0x11 && sBuf[ 2 ] == 0x01 && bdBoxOk) - { - rFormatExtension = UniString::CreateFromAscii( "PCT", 3 ); - return TRUE; - } - } - } - - //------------------------- PBM + PGM + PPM --------------------------- - if( !bTest || - ( rFormatExtension.CompareToAscii( "PBM", 3 ) == COMPARE_EQUAL ) || - ( rFormatExtension.CompareToAscii( "PGM", 3 ) == COMPARE_EQUAL ) || - ( rFormatExtension.CompareToAscii( "PPM", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested=TRUE; - if ( sFirstBytes[ 0 ] == 'P' ) - { - switch( sFirstBytes[ 1 ] ) - { - case '1' : - case '4' : - rFormatExtension = UniString::CreateFromAscii( "PBM", 3 ); - return TRUE; - - case '2' : - case '5' : - rFormatExtension = UniString::CreateFromAscii( "PGM", 3 ); - return TRUE; - - case '3' : - case '6' : - rFormatExtension = UniString::CreateFromAscii( "PPM", 3 ); - return TRUE; - } - } - } - - //--------------------------- RAS( SUN RasterFile )------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "RAS", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested=TRUE; - if( nFirstLong == 0x59a66a95 ) - { - rFormatExtension = UniString::CreateFromAscii( "RAS", 3 ); - return TRUE; - } - } - - //--------------------------- XPM ------------------------------------ - if( !bTest ) - { - bSomethingTested = TRUE; - if( ImplSearchEntry( sFirstBytes, (BYTE*)"/* XPM */", 256, 9 ) ) - { - rFormatExtension = UniString::CreateFromAscii( "XPM", 3 ); - return TRUE; - } - } - else if( rFormatExtension.CompareToAscii( "XPM", 3 ) == COMPARE_EQUAL ) - { - bSomethingTested = TRUE; - return TRUE; - } - - //--------------------------- XBM ------------------------------------ - if( !bTest ) - { - ULONG nSize = ( nStreamLen > 2048 ) ? 2048 : nStreamLen; - BYTE* pBuf = new BYTE [ nSize ]; - - rStream.Seek( nStreamPos ); - rStream.Read( pBuf, nSize ); - BYTE* pPtr = ImplSearchEntry( pBuf, (BYTE*)"#define", nSize, 7 ); - - if( pPtr ) - { - if( ImplSearchEntry( pPtr, (BYTE*)"_width", pBuf + nSize - pPtr, 6 ) ) - { - rFormatExtension = UniString::CreateFromAscii( "XBM", 3 ); - delete[] pBuf; - return TRUE; - } - } - delete[] pBuf; - } - else if( rFormatExtension.CompareToAscii( "XBM", 3 ) == COMPARE_EQUAL ) - { - bSomethingTested = TRUE; - return TRUE; - } - - //--------------------------- TGA ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "TGA", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested = TRUE; - if( rFormatExtension.CompareToAscii( "TGA", 3 ) == COMPARE_EQUAL ) - return TRUE; - } - - //--------------------------- SGV ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "SGV", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested = TRUE; - if( rFormatExtension.CompareToAscii( "SGV", 3 ) == COMPARE_EQUAL ) - return TRUE; - } - - //--------------------------- SGF ------------------------------------ - if( !bTest || ( rFormatExtension.CompareToAscii( "SGF", 3 ) == COMPARE_EQUAL ) ) - { - bSomethingTested=TRUE; - if( sFirstBytes[ 0 ] == 'J' && sFirstBytes[ 1 ] == 'J' ) - { - rFormatExtension = UniString::CreateFromAscii( "SGF", 3 ); - return TRUE; - } - } - - return bTest && !bSomethingTested; -} - -//-------------------------------------------------------------------------- - -sal_uInt16 GraphicFilter::ImpTestOrFindFormat( const String& rPath, SvStream& rStream, sal_uInt16& rFormat ) -{ - sal_uInt16 n = pConfig->GetImportFormatCount(); - - // ggf. Filter bzw. Format durch anlesen ermitteln, - // oder durch anlesen zusichern, dass das Format stimmt: - if( rFormat == GRFILTER_FORMAT_DONTKNOW ) - { - String aFormatExt; - if( ImpPeekGraphicFormat( rStream, aFormatExt, FALSE ) ) - { - for( sal_uInt16 i = 0; i < n; i++ ) - { - if( pConfig->GetImportFormatExtension( i ).EqualsIgnoreCaseAscii( aFormatExt ) ) - { - rFormat = i; - return GRFILTER_OK; - } - } - } - // ggf. Filter anhand der Datei-Endung raussuchen: - if( rPath.Len() ) - { - String aExt( ImpGetExtension( rPath ) ); - for( sal_uInt16 i = 0; i < n; i++ ) - { - if( pConfig->GetImportFormatExtension( i ).EqualsIgnoreCaseAscii( aExt ) ) - { - rFormat = i; - return GRFILTER_OK; - } - } - } - return GRFILTER_FORMATERROR; - } - else - { - String aTmpStr( pConfig->GetImportFormatExtension( rFormat ) ); - if( !ImpPeekGraphicFormat( rStream, aTmpStr, TRUE ) ) - return GRFILTER_FORMATERROR; - if ( pConfig->GetImportFormatExtension( rFormat ).EqualsIgnoreCaseAscii( "pcd" ) ) - { - sal_Int32 nBase = 2; // default Base0 - if ( pConfig->GetImportFilterType( rFormat ).EqualsIgnoreCaseAscii( "pcd_Photo_CD_Base4" ) ) - nBase = 1; - else if ( pConfig->GetImportFilterType( rFormat ).EqualsIgnoreCaseAscii( "pcd_Photo_CD_Base16" ) ) - nBase = 0; - String aFilterConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/Graphic/Import/PCD" ) ); - FilterConfigItem aFilterConfigItem( aFilterConfigPath ); - aFilterConfigItem.WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Resolution" ) ), nBase ); - } - } - - return GRFILTER_OK; -} - -//-------------------------------------------------------------------------- - -static Graphic ImpGetScaledGraphic( const Graphic& rGraphic, FilterConfigItem& rConfigItem ) -{ - Graphic aGraphic; - ByteString aResMgrName( "svt", 3 ); - ResMgr* pResMgr; - - pResMgr = ResMgr::CreateResMgr( aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() ); - - sal_Int32 nLogicalWidth = rConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "LogicalWidth" ) ), 0 ); - sal_Int32 nLogicalHeight = rConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "LogicalHeight" ) ), 0 ); - - if ( rGraphic.GetType() != GRAPHIC_NONE ) - { - sal_Int32 nMode = rConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "ExportMode" ) ), -1 ); - - if ( nMode == -1 ) // the property is not there, this is possible, if the graphic filter - { // is called via UnoGraphicExporter and not from a graphic export Dialog - nMode = 0; // then we are defaulting this mode to 0 - if ( nLogicalWidth || nLogicalHeight ) - nMode = 2; - } - - - Size aOriginalSize; - Size aPrefSize( rGraphic.GetPrefSize() ); - MapMode aPrefMapMode( rGraphic.GetPrefMapMode() ); - if ( aPrefMapMode == MAP_PIXEL ) - aOriginalSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM ); - else - aOriginalSize = Application::GetDefaultDevice()->LogicToLogic( aPrefSize, aPrefMapMode, MAP_100TH_MM ); - if ( !nLogicalWidth ) - nLogicalWidth = aOriginalSize.Width(); - if ( !nLogicalHeight ) - nLogicalHeight = aOriginalSize.Height(); - if( rGraphic.GetType() == GRAPHIC_BITMAP ) - { - - // Aufloesung wird eingestellt - if( nMode == 1 ) - { - Bitmap aBitmap( rGraphic.GetBitmap() ); - MapMode aMap( MAP_100TH_INCH ); - - sal_Int32 nDPI = rConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Resolution" ) ), 75 ); - Fraction aFrac( 1, Min( Max( nDPI, sal_Int32( 75 ) ), sal_Int32( 600 ) ) ); - - aMap.SetScaleX( aFrac ); - aMap.SetScaleY( aFrac ); - - Size aOldSize = aBitmap.GetSizePixel(); - aBitmap.SetPrefMapMode( aMap ); - aBitmap.SetPrefSize( Size( aOldSize.Width() * 100, - aOldSize.Height() * 100 ) ); - - aGraphic = Graphic( aBitmap ); - } - // Groesse wird eingestellt - else if( nMode == 2 ) - { - BitmapEx aBitmapEx( rGraphic.GetBitmapEx() ); - aBitmapEx.SetPrefMapMode( MapMode( MAP_100TH_MM ) ); - aBitmapEx.SetPrefSize( Size( nLogicalWidth, nLogicalHeight ) ); - aGraphic = Graphic( aBitmapEx ); - } - else - aGraphic = rGraphic; - - sal_Int32 nColors = rConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Color" ) ), 0 ); // #92767# - if ( nColors ) // graphic conversion necessary ? - { - BitmapEx aBmpEx( aGraphic.GetBitmapEx() ); - aBmpEx.Convert( (BmpConversion)nColors ); // the entries in the xml section have the same meaning as - aGraphic = aBmpEx; // they have in the BmpConversion enum, so it should be - } // allowed to cast them - } - else - { - if( ( nMode == 1 ) || ( nMode == 2 ) ) - { - GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() ); - ::com::sun::star::awt::Size aDefaultSize( 10000, 10000 ); - Size aNewSize( OutputDevice::LogicToLogic( Size( nLogicalWidth, nLogicalHeight ), MAP_100TH_MM, aMtf.GetPrefMapMode() ) ); - - if( aNewSize.Width() && aNewSize.Height() ) - { - const Size aPreferredSize( aMtf.GetPrefSize() ); - aMtf.Scale( Fraction( aNewSize.Width(), aPreferredSize.Width() ), - Fraction( aNewSize.Height(), aPreferredSize.Height() ) ); - } - aGraphic = Graphic( aMtf ); - } - else - aGraphic = rGraphic; - } - - } - else - aGraphic = rGraphic; - - delete pResMgr; - - return aGraphic; -} - -static String ImpCreateFullFilterPath( const String& rPath, const String& rFilterName ) -{ - ::rtl::OUString aPathURL; - - ::osl::FileBase::getFileURLFromSystemPath( rPath, aPathURL ); - aPathURL += String( '/' ); - - ::rtl::OUString aSystemPath; - ::osl::FileBase::getSystemPathFromFileURL( aPathURL, aSystemPath ); - aSystemPath += ::rtl::OUString( rFilterName ); - - return String( aSystemPath ); -} - - -// -------------------------- -// - ImpFilterLibCacheEntry - -// -------------------------- - -class ImpFilterLibCache; - -struct ImpFilterLibCacheEntry -{ - ImpFilterLibCacheEntry* mpNext; - osl::Module maLibrary; - String maFiltername; - PFilterCall mpfnImport; - PFilterDlgCall mpfnImportDlg; - - ImpFilterLibCacheEntry( const String& rPathname, const String& rFiltername ); - int operator==( const String& rFiltername ) const { return maFiltername == rFiltername; } - - PFilterCall GetImportFunction(); - PFilterDlgCall GetImportDlgFunction(); - PFilterCall GetExportFunction() { return (PFilterCall) maLibrary.getFunctionSymbol( UniString::CreateFromAscii( EXPORT_FUNCTION_NAME ) ); } - PFilterDlgCall GetExportDlgFunction() { return (PFilterDlgCall) maLibrary.getFunctionSymbol( UniString::CreateFromAscii( EXPDLG_FUNCTION_NAME ) ); } -}; - -// ------------------------------------------------------------------------ - -ImpFilterLibCacheEntry::ImpFilterLibCacheEntry( const String& rPathname, const String& rFiltername ) : - mpNext ( NULL ), - maLibrary ( rPathname ), - maFiltername ( rFiltername ), - mpfnImport ( NULL ), - mpfnImportDlg ( NULL ) -{ -} - -// ------------------------------------------------------------------------ - -PFilterCall ImpFilterLibCacheEntry::GetImportFunction() -{ - if( !mpfnImport ) - mpfnImport = (PFilterCall) maLibrary.getFunctionSymbol( UniString::CreateFromAscii( IMPORT_FUNCTION_NAME ) ); - - return mpfnImport; -} - -// ------------------------------------------------------------------------ - -PFilterDlgCall ImpFilterLibCacheEntry::GetImportDlgFunction() -{ - if( !mpfnImportDlg ) - mpfnImportDlg = (PFilterDlgCall)maLibrary.getFunctionSymbol( UniString::CreateFromAscii( IMPDLG_FUNCTION_NAME ) ); - - return mpfnImportDlg; -} - -// --------------------- -// - ImpFilterLibCache - -// --------------------- - -class ImpFilterLibCache -{ - ImpFilterLibCacheEntry* mpFirst; - ImpFilterLibCacheEntry* mpLast; - -public: - ImpFilterLibCache(); - ~ImpFilterLibCache(); - - ImpFilterLibCacheEntry* GetFilter( const String& rFilterPath, const String& rFiltername ); -}; - -// ------------------------------------------------------------------------ - -ImpFilterLibCache::ImpFilterLibCache() : - mpFirst ( NULL ), - mpLast ( NULL ) -{ -} - -// ------------------------------------------------------------------------ - -ImpFilterLibCache::~ImpFilterLibCache() -{ - ImpFilterLibCacheEntry* pEntry = mpFirst; - while( pEntry ) - { - ImpFilterLibCacheEntry* pNext = pEntry->mpNext; - delete pEntry; - pEntry = pNext; - } -} - -// ------------------------------------------------------------------------ - -ImpFilterLibCacheEntry* ImpFilterLibCache::GetFilter( const String& rFilterPath, const String& rFilterName ) -{ - ImpFilterLibCacheEntry* pEntry = mpFirst; - - while( pEntry ) - { - if( *pEntry == rFilterName ) - break; - else - pEntry = pEntry->mpNext; - } - if( !pEntry ) - { - String aPhysicalName( ImpCreateFullFilterPath( rFilterPath, rFilterName ) ); - pEntry = new ImpFilterLibCacheEntry( aPhysicalName, rFilterName ); - - if ( pEntry->maLibrary.is() ) - { - if( !mpFirst ) - mpFirst = mpLast = pEntry; - else - mpLast = mpLast->mpNext = pEntry; - } - else - { - delete pEntry; - pEntry = NULL; - } - } - return pEntry; -}; - -// ------------------------------------------------------------------------ - -namespace { struct Cache : public rtl::Static {}; } - -// ----------------- -// - GraphicFilter - -// ----------------- - -GraphicFilter::GraphicFilter( sal_Bool bConfig ) : - bUseConfig ( bConfig ), - nExpGraphHint ( 0 ) -{ - ImplInit(); -} - -// ------------------------------------------------------------------------ - -GraphicFilter::~GraphicFilter() -{ - { - ::osl::MutexGuard aGuard( getListMutex() ); - pFilterHdlList->Remove( (void*)this ); - if ( !pFilterHdlList->Count() ) - { - delete pFilterHdlList, pFilterHdlList = NULL; - delete pConfig; - } - } - - - delete pErrorEx; -} - -// ------------------------------------------------------------------------ - -void GraphicFilter::ImplInit() -{ - { - ::osl::MutexGuard aGuard( getListMutex() ); - - if ( !pFilterHdlList ) - { - pFilterHdlList = new List; - pConfig = new FilterConfigCache( bUseConfig ); - } - else - pConfig = ((GraphicFilter*)pFilterHdlList->First())->pConfig; - - pFilterHdlList->Insert( (void*)this ); - } - - if( bUseConfig ) - { -#if defined WNT - rtl::OUString url(RTL_CONSTASCII_USTRINGPARAM("$BRAND_BASE_DIR/program")); -#else - rtl::OUString url(RTL_CONSTASCII_USTRINGPARAM("$OOO_BASE_DIR/program")); -#endif - rtl::Bootstrap::expandMacros(url); //TODO: detect failure - utl::LocalFileHelper::ConvertURLToPhysicalName(url, aFilterPath); - } - - pErrorEx = new FilterErrorEx; - bAbort = sal_False; -} - -// ------------------------------------------------------------------------ - -ULONG GraphicFilter::ImplSetError( ULONG nError, const SvStream* pStm ) -{ - pErrorEx->nFilterError = nError; - pErrorEx->nStreamError = pStm ? pStm->GetError() : ERRCODE_NONE; - return nError; -} -// ------------------------------------------------------------------------ - -USHORT GraphicFilter::GetImportFormatCount() -{ - return pConfig->GetImportFormatCount(); -} - -// ------------------------------------------------------------------------ - -USHORT GraphicFilter::GetImportFormatNumber( const String& rFormatName ) -{ - return pConfig->GetImportFormatNumber( rFormatName ); -} - -// ------------------------------------------------------------------------ - -USHORT GraphicFilter::GetImportFormatNumberForMediaType( const String& rMediaType ) -{ - return pConfig->GetImportFormatNumberForMediaType( rMediaType ); -} - -// ------------------------------------------------------------------------ - -USHORT GraphicFilter::GetImportFormatNumberForShortName( const String& rShortName ) -{ - return pConfig->GetImportFormatNumberForShortName( rShortName ); -} - -// ------------------------------------------------------------------------ - -sal_uInt16 GraphicFilter::GetImportFormatNumberForTypeName( const String& rType ) -{ - return pConfig->GetImportFormatNumberForTypeName( rType ); -} - -// ------------------------------------------------------------------------ - -String GraphicFilter::GetImportFormatName( USHORT nFormat ) -{ - return pConfig->GetImportFormatName( nFormat ); -} - -// ------------------------------------------------------------------------ - -String GraphicFilter::GetImportFormatTypeName( USHORT nFormat ) -{ - return pConfig->GetImportFilterTypeName( nFormat ); -} - -// ------------------------------------------------------------------------ - -String GraphicFilter::GetImportFormatMediaType( USHORT nFormat ) -{ - return pConfig->GetImportFormatMediaType( nFormat ); -} - -// ------------------------------------------------------------------------ - -String GraphicFilter::GetImportFormatShortName( USHORT nFormat ) -{ - return pConfig->GetImportFormatShortName( nFormat ); -} - -// ------------------------------------------------------------------------ - -String GraphicFilter::GetImportOSFileType( USHORT ) -{ - String aOSFileType; - return aOSFileType; -} - -// ------------------------------------------------------------------------ - -String GraphicFilter::GetImportWildcard( USHORT nFormat, sal_Int32 nEntry ) -{ - return pConfig->GetImportWildcard( nFormat, nEntry ); -} - -// ------------------------------------------------------------------------ - -BOOL GraphicFilter::IsImportPixelFormat( USHORT nFormat ) -{ - return pConfig->IsImportPixelFormat( nFormat ); -} - -// ------------------------------------------------------------------------ - -USHORT GraphicFilter::GetExportFormatCount() -{ - return pConfig->GetExportFormatCount(); -} - -// ------------------------------------------------------------------------ - -USHORT GraphicFilter::GetExportFormatNumber( const String& rFormatName ) -{ - return pConfig->GetExportFormatNumber( rFormatName ); -} - -// ------------------------------------------------------------------------ - -USHORT GraphicFilter::GetExportFormatNumberForMediaType( const String& rMediaType ) -{ - return pConfig->GetExportFormatNumberForMediaType( rMediaType ); -} - -// ------------------------------------------------------------------------ - -USHORT GraphicFilter::GetExportFormatNumberForShortName( const String& rShortName ) -{ - return pConfig->GetExportFormatNumberForShortName( rShortName ); -} - -// ------------------------------------------------------------------------ - -sal_uInt16 GraphicFilter::GetExportFormatNumberForTypeName( const String& rType ) -{ - return pConfig->GetExportFormatNumberForTypeName( rType ); -} - -// ------------------------------------------------------------------------ - -String GraphicFilter::GetExportFormatName( USHORT nFormat ) -{ - return pConfig->GetExportFormatName( nFormat ); -} - -// ------------------------------------------------------------------------ - -String GraphicFilter::GetExportFormatTypeName( USHORT nFormat ) -{ - return pConfig->GetExportFilterTypeName( nFormat ); -} - -// ------------------------------------------------------------------------ - -String GraphicFilter::GetExportFormatMediaType( USHORT nFormat ) -{ - return pConfig->GetExportFormatMediaType( nFormat ); -} - -// ------------------------------------------------------------------------ - -String GraphicFilter::GetExportFormatShortName( USHORT nFormat ) -{ - return pConfig->GetExportFormatShortName( nFormat ); -} - -// ------------------------------------------------------------------------ - -String GraphicFilter::GetExportOSFileType( USHORT ) -{ - String aOSFileType; - return aOSFileType; -} - -// ------------------------------------------------------------------------ - -String GraphicFilter::GetExportWildcard( USHORT nFormat, sal_Int32 nEntry ) -{ - return pConfig->GetExportWildcard( nFormat, nEntry ); -} - -// ------------------------------------------------------------------------ - -BOOL GraphicFilter::IsExportPixelFormat( USHORT nFormat ) -{ - return pConfig->IsExportPixelFormat( nFormat ); -} - -// ------------------------------------------------------------------------ - -USHORT GraphicFilter::CanImportGraphic( const INetURLObject& rPath, - USHORT nFormat, USHORT* pDeterminedFormat ) -{ - sal_uInt16 nRetValue = GRFILTER_FORMATERROR; - DBG_ASSERT( rPath.GetProtocol() != INET_PROT_NOT_VALID, "GraphicFilter::CanImportGraphic() : ProtType == INET_PROT_NOT_VALID" ); - - String aMainUrl( rPath.GetMainURL( INetURLObject::NO_DECODE ) ); - SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aMainUrl, STREAM_READ | STREAM_SHARE_DENYNONE ); - if ( pStream ) - { - nRetValue = CanImportGraphic( aMainUrl, *pStream, nFormat, pDeterminedFormat ); - delete pStream; - } - return nRetValue; -} - -// ------------------------------------------------------------------------ - -USHORT GraphicFilter::CanImportGraphic( const String& rMainUrl, SvStream& rIStream, - USHORT nFormat, USHORT* pDeterminedFormat ) -{ - ULONG nStreamPos = rIStream.Tell(); - sal_uInt16 nRes = ImpTestOrFindFormat( rMainUrl, rIStream, nFormat ); - - rIStream.Seek(nStreamPos); - - if( nRes==GRFILTER_OK && pDeterminedFormat!=NULL ) - *pDeterminedFormat = nFormat; - - return (USHORT) ImplSetError( nRes, &rIStream ); -} - -// ------------------------------------------------------------------------ -//SJ: TODO, we need to create a GraphicImporter component -USHORT GraphicFilter::ImportGraphic( Graphic& rGraphic, const INetURLObject& rPath, - USHORT nFormat, USHORT * pDeterminedFormat, sal_uInt32 nImportFlags ) -{ - sal_uInt16 nRetValue = GRFILTER_FORMATERROR; - DBG_ASSERT( rPath.GetProtocol() != INET_PROT_NOT_VALID, "GraphicFilter::ImportGraphic() : ProtType == INET_PROT_NOT_VALID" ); - - String aMainUrl( rPath.GetMainURL( INetURLObject::NO_DECODE ) ); - SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aMainUrl, STREAM_READ | STREAM_SHARE_DENYNONE ); - if ( pStream ) - { - nRetValue = ImportGraphic( rGraphic, aMainUrl, *pStream, nFormat, pDeterminedFormat, nImportFlags ); - delete pStream; - } - return nRetValue; -} - -USHORT GraphicFilter::ImportGraphic( Graphic& rGraphic, const String& rPath, SvStream& rIStream, - USHORT nFormat, USHORT* pDeterminedFormat, sal_uInt32 nImportFlags ) -{ - return ImportGraphic( rGraphic, rPath, rIStream, nFormat, pDeterminedFormat, nImportFlags, NULL ); -} - -//------------------------------------------------------------------------- - -USHORT GraphicFilter::ImportGraphic( Graphic& rGraphic, const String& rPath, SvStream& rIStream, - USHORT nFormat, USHORT* pDeterminedFormat, sal_uInt32 nImportFlags, - com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData ) -{ - String aFilterName; - ULONG nStmBegin; - USHORT nStatus; - GraphicReader* pContext = rGraphic.GetContext(); - GfxLinkType eLinkType = GFX_LINK_TYPE_NONE; - BOOL bDummyContext = ( pContext == (GraphicReader*) 1 ); - const BOOL bLinkSet = rGraphic.IsLink(); - FilterConfigItem* pFilterConfigItem = NULL; - - Size aPreviewSizeHint( 0, 0 ); - sal_Bool bAllowPartialStreamRead = sal_False; - sal_Bool bCreateNativeLink = sal_True; - - ResetLastError(); - - if ( pFilterData ) - { - sal_Int32 i; - for ( i = 0; i < pFilterData->getLength(); i++ ) - { - if ( (*pFilterData)[ i ].Name.equalsAscii( "PreviewSizeHint" ) ) - { - awt::Size aSize; - if ( (*pFilterData)[ i ].Value >>= aSize ) - { - aPreviewSizeHint = Size( aSize.Width, aSize.Height ); - if ( aSize.Width || aSize.Height ) - nImportFlags |= GRFILTER_I_FLAGS_FOR_PREVIEW; - else - nImportFlags &=~GRFILTER_I_FLAGS_FOR_PREVIEW; - } - } - else if ( (*pFilterData)[ i ].Name.equalsAscii( "AllowPartialStreamRead" ) ) - { - (*pFilterData)[ i ].Value >>= bAllowPartialStreamRead; - if ( bAllowPartialStreamRead ) - nImportFlags |= GRFILTER_I_FLAGS_ALLOW_PARTIAL_STREAMREAD; - else - nImportFlags &=~GRFILTER_I_FLAGS_ALLOW_PARTIAL_STREAMREAD; - } - else if ( (*pFilterData)[ i ].Name.equalsAscii( "CreateNativeLink" ) ) - { - (*pFilterData)[ i ].Value >>= bCreateNativeLink; - } - } - } - - if( !pContext || bDummyContext ) - { - if( bDummyContext ) - { - rGraphic.SetContext( NULL ); - nStmBegin = 0; - } - else - nStmBegin = rIStream.Tell(); - - bAbort = FALSE; - nStatus = ImpTestOrFindFormat( rPath, rIStream, nFormat ); - // Falls Pending, geben wir GRFILTER_OK zurueck, - // um mehr Bytes anzufordern - if( rIStream.GetError() == ERRCODE_IO_PENDING ) - { - rGraphic.SetContext( (GraphicReader*) 1 ); - rIStream.ResetError(); - rIStream.Seek( nStmBegin ); - return (USHORT) ImplSetError( GRFILTER_OK ); - } - - rIStream.Seek( nStmBegin ); - - if( ( nStatus != GRFILTER_OK ) || rIStream.GetError() ) - return (USHORT) ImplSetError( ( nStatus != GRFILTER_OK ) ? nStatus : GRFILTER_OPENERROR, &rIStream ); - - if( pDeterminedFormat ) - *pDeterminedFormat = nFormat; - - aFilterName = pConfig->GetImportFilterName( nFormat ); - } - else - { - if( pContext && !bDummyContext ) - aFilterName = pContext->GetUpperFilterName(); - - nStmBegin = 0; - nStatus = GRFILTER_OK; - } - - // read graphic - if ( pConfig->IsImportInternalFilter( nFormat ) ) - { - if( aFilterName.EqualsIgnoreCaseAscii( IMP_GIF ) ) - { - if( rGraphic.GetContext() == (GraphicReader*) 1 ) - rGraphic.SetContext( NULL ); - - if( !ImportGIF( rIStream, rGraphic ) ) - nStatus = GRFILTER_FILTERERROR; - else - eLinkType = GFX_LINK_TYPE_NATIVE_GIF; - } - else if( aFilterName.EqualsIgnoreCaseAscii( IMP_PNG ) ) - { - if ( rGraphic.GetContext() == (GraphicReader*) 1 ) - rGraphic.SetContext( NULL ); - - vcl::PNGReader aPNGReader( rIStream ); - - // ignore animation for previews and set preview size - if( aPreviewSizeHint.Width() || aPreviewSizeHint.Height() ) - { - // position the stream at the end of the image if requested - if( !bAllowPartialStreamRead ) - aPNGReader.GetChunks(); - } - else - { - // check if this PNG contains a GIF chunk! - const std::vector< vcl::PNGReader::ChunkData >& rChunkData = aPNGReader.GetChunks(); - std::vector< vcl::PNGReader::ChunkData >::const_iterator aIter( rChunkData.begin() ); - std::vector< vcl::PNGReader::ChunkData >::const_iterator aEnd ( rChunkData.end() ); - while( aIter != aEnd ) - { - // Microsoft Office is storing Animated GIFs in following chunk - if ( aIter->nType == PMGCHUNG_msOG ) - { - sal_uInt32 nChunkSize = aIter->aData.size(); - if ( nChunkSize > 11 ) - { - const std::vector< sal_uInt8 >& rData = aIter->aData; - SvMemoryStream aIStrm( (void*)&rData[ 11 ], nChunkSize - 11, STREAM_READ ); - ImportGIF( aIStrm, rGraphic ); - eLinkType = GFX_LINK_TYPE_NATIVE_PNG; - break; - } - } - aIter++; - } - } - - if ( eLinkType == GFX_LINK_TYPE_NONE ) - { - BitmapEx aBmpEx( aPNGReader.Read( aPreviewSizeHint ) ); - if ( aBmpEx.IsEmpty() ) - nStatus = GRFILTER_FILTERERROR; - else - { - rGraphic = aBmpEx; - eLinkType = GFX_LINK_TYPE_NATIVE_PNG; - } - } - } - else if( aFilterName.EqualsIgnoreCaseAscii( IMP_JPEG ) ) - { - if( rGraphic.GetContext() == (GraphicReader*) 1 ) - rGraphic.SetContext( NULL ); - - // set LOGSIZE flag always, if not explicitly disabled - // (see #90508 and #106763) - if( 0 == ( nImportFlags & GRFILTER_I_FLAGS_DONT_SET_LOGSIZE_FOR_JPEG ) ) - nImportFlags |= GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG; - - if( !ImportJPEG( rIStream, rGraphic, NULL, nImportFlags ) ) - nStatus = GRFILTER_FILTERERROR; - else - eLinkType = GFX_LINK_TYPE_NATIVE_JPG; - } - else if( aFilterName.EqualsIgnoreCaseAscii( IMP_XBM ) ) - { - if( rGraphic.GetContext() == (GraphicReader*) 1 ) - rGraphic.SetContext( NULL ); - - if( !ImportXBM( rIStream, rGraphic ) ) - nStatus = GRFILTER_FILTERERROR; - } - else if( aFilterName.EqualsIgnoreCaseAscii( IMP_XPM ) ) - { - if( rGraphic.GetContext() == (GraphicReader*) 1 ) - rGraphic.SetContext( NULL ); - - if( !ImportXPM( rIStream, rGraphic ) ) - nStatus = GRFILTER_FILTERERROR; - } - else if( aFilterName.EqualsIgnoreCaseAscii( IMP_BMP ) || - aFilterName.EqualsIgnoreCaseAscii( IMP_SVMETAFILE ) ) - { - // SV interne Importfilter fuer Bitmaps und MetaFiles - rIStream >> rGraphic; - if( rIStream.GetError() ) - nStatus = GRFILTER_FORMATERROR; - } - else if( aFilterName.EqualsIgnoreCaseAscii( IMP_WMF ) || - aFilterName.EqualsIgnoreCaseAscii( IMP_EMF ) ) - { - GDIMetaFile aMtf; - if( !ConvertWMFToGDIMetaFile( rIStream, aMtf, NULL ) ) - nStatus = GRFILTER_FORMATERROR; - else - { - rGraphic = aMtf; - eLinkType = GFX_LINK_TYPE_NATIVE_WMF; - } - } - else if( aFilterName.EqualsIgnoreCaseAscii( IMP_SVSGF ) - || aFilterName.EqualsIgnoreCaseAscii( IMP_SVSGV ) ) - { - USHORT nVersion; - unsigned char nTyp = CheckSgfTyp( rIStream, nVersion ); - - switch( nTyp ) - { - case SGF_BITIMAGE: - { - SvMemoryStream aTempStream; - if( aTempStream.GetError() ) - return GRFILTER_OPENERROR; - - if( !SgfBMapFilter( rIStream, aTempStream ) ) - nStatus = GRFILTER_FILTERERROR; - else - { - aTempStream.Seek( 0L ); - aTempStream >> rGraphic; - - if( aTempStream.GetError() ) - nStatus = GRFILTER_FILTERERROR; - } - } - break; - - case SGF_SIMPVECT: - { - GDIMetaFile aMtf; - if( !SgfVectFilter( rIStream, aMtf ) ) - nStatus = GRFILTER_FILTERERROR; - else - rGraphic = Graphic( aMtf ); - } - break; - - case SGF_STARDRAW: - { - if( nVersion != SGV_VERSION ) - nStatus = GRFILTER_VERSIONERROR; - else - { - GDIMetaFile aMtf; - if( !SgfSDrwFilter( rIStream, aMtf, - INetURLObject(aFilterPath) ) ) - { - nStatus = GRFILTER_FILTERERROR; - } - else - rGraphic = Graphic( aMtf ); - } - } - break; - - default: - { - nStatus = GRFILTER_FORMATERROR; - } - break; - } - } - else - nStatus = GRFILTER_FILTERERROR; - } - else - { - ImpFilterLibCacheEntry* pFilter = NULL; - - // find first filter in filter pathes - xub_StrLen i, nTokenCount = aFilterPath.GetTokenCount( ';' ); - ImpFilterLibCache &rCache = Cache::get(); - for( i = 0; ( i < nTokenCount ) && ( pFilter == NULL ); i++ ) - pFilter = rCache.GetFilter( aFilterPath.GetToken(i), aFilterName ); - if( !pFilter ) - nStatus = GRFILTER_FILTERERROR; - else - { - PFilterCall pFunc = pFilter->GetImportFunction(); - - if( !pFunc ) - nStatus = GRFILTER_FILTERERROR; - else - { - String aShortName; - if( nFormat != GRFILTER_FORMAT_DONTKNOW ) - { - aShortName = GetImportFormatShortName( nFormat ).ToUpperAscii(); - if ( ( pFilterConfigItem == NULL ) && aShortName.EqualsAscii( "PCD" ) ) - { - String aFilterConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/Graphic/Import/PCD" ) ); - pFilterConfigItem = new FilterConfigItem( aFilterConfigPath ); - } - } - if( !(*pFunc)( rIStream, rGraphic, pFilterConfigItem, sal_False ) ) - nStatus = GRFILTER_FORMATERROR; - else - { - // try to set link type if format matches - if( nFormat != GRFILTER_FORMAT_DONTKNOW ) - { - if( aShortName.CompareToAscii( TIF_SHORTNAME ) == COMPARE_EQUAL ) - eLinkType = GFX_LINK_TYPE_NATIVE_TIF; - else if( aShortName.CompareToAscii( MET_SHORTNAME ) == COMPARE_EQUAL ) - eLinkType = GFX_LINK_TYPE_NATIVE_MET; - else if( aShortName.CompareToAscii( PCT_SHORTNAME ) == COMPARE_EQUAL ) - eLinkType = GFX_LINK_TYPE_NATIVE_PCT; - } - } - } - } - } - - if( nStatus == GRFILTER_OK && bCreateNativeLink && ( eLinkType != GFX_LINK_TYPE_NONE ) && !rGraphic.GetContext() && !bLinkSet ) - { - const ULONG nStmEnd = rIStream.Tell(); - const ULONG nBufSize = nStmEnd - nStmBegin; - - if( nBufSize ) - { - BYTE* pBuf=0; - try - { - pBuf = new BYTE[ nBufSize ]; - } - catch (std::bad_alloc) - { - nStatus = GRFILTER_TOOBIG; - } - - if( nStatus == GRFILTER_OK ) - { - rIStream.Seek( nStmBegin ); - rIStream.Read( pBuf, nBufSize ); - rGraphic.SetLink( GfxLink( pBuf, nBufSize, eLinkType, TRUE ) ); - } - } - } - - // Set error code or try to set native buffer - if( nStatus != GRFILTER_OK ) - { - if( bAbort ) - nStatus = GRFILTER_ABORT; - - ImplSetError( nStatus, &rIStream ); - rIStream.Seek( nStmBegin ); - rGraphic.Clear(); - } - - delete pFilterConfigItem; - return nStatus; -} - - -// ------------------------------------------------------------------------ - -USHORT GraphicFilter::ExportGraphic( const Graphic& rGraphic, const INetURLObject& rPath, - sal_uInt16 nFormat, const uno::Sequence< beans::PropertyValue >* pFilterData ) -{ - sal_uInt16 nRetValue = GRFILTER_FORMATERROR; - DBG_ASSERT( rPath.GetProtocol() != INET_PROT_NOT_VALID, "GraphicFilter::ExportGraphic() : ProtType == INET_PROT_NOT_VALID" ); - BOOL bAlreadyExists = ImplDirEntryHelper::Exists( rPath ); - - String aMainUrl( rPath.GetMainURL( INetURLObject::NO_DECODE ) ); - SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aMainUrl, STREAM_WRITE | STREAM_TRUNC ); - if ( pStream ) - { - nRetValue = ExportGraphic( rGraphic, aMainUrl, *pStream, nFormat, pFilterData ); - delete pStream; - - if( ( GRFILTER_OK != nRetValue ) && !bAlreadyExists ) - ImplDirEntryHelper::Kill( aMainUrl ); - } - return nRetValue; -} - -// ------------------------------------------------------------------------ - -USHORT GraphicFilter::ExportGraphic( const Graphic& rGraphic, const String& rPath, - SvStream& rOStm, sal_uInt16 nFormat, const uno::Sequence< beans::PropertyValue >* pFilterData ) -{ - USHORT nFormatCount = GetExportFormatCount(); - - ResetLastError(); - nExpGraphHint = 0; - - if( nFormat == GRFILTER_FORMAT_DONTKNOW ) - { - INetURLObject aURL( rPath ); - String aExt( aURL.GetFileExtension().toAsciiUpperCase() ); - - - for( USHORT i = 0; i < nFormatCount; i++ ) - { - if ( pConfig->GetExportFormatExtension( i ).EqualsIgnoreCaseAscii( aExt ) ) - { - nFormat=i; - break; - } - } - } - if( nFormat >= nFormatCount ) - return (USHORT) ImplSetError( GRFILTER_FORMATERROR ); - - FilterConfigItem aConfigItem( (uno::Sequence< beans::PropertyValue >*)pFilterData ); - String aFilterName( pConfig->GetExportFilterName( nFormat ) ); - - bAbort = FALSE; - USHORT nStatus = GRFILTER_OK; - GraphicType eType; - Graphic aGraphic( rGraphic ); - - aGraphic = ImpGetScaledGraphic( rGraphic, aConfigItem ); - eType = aGraphic.GetType(); - - if( pConfig->IsExportPixelFormat( nFormat ) ) - { - if( eType != GRAPHIC_BITMAP ) - { - Size aSizePixel; - ULONG nColorCount,nBitsPerPixel,nNeededMem,nMaxMem; - VirtualDevice aVirDev; - - // Maximalen Speicherbedarf fuer das Bildes holen: -// if( GetOptionsConfig() ) -// nMaxMem = (UINT32)GetOptionsConfig()->ReadKey( "VEC-TO-PIX-MAX-KB", "1024" ).ToInt32(); -// else - nMaxMem = 1024; - - nMaxMem *= 1024; // In Bytes - - // Berechnen, wie gross das Bild normalerweise werden wuerde: - aSizePixel=aVirDev.LogicToPixel(aGraphic.GetPrefSize(),aGraphic.GetPrefMapMode()); - - // Berechnen, wieviel Speicher das Bild benoetigen wuerde: - nColorCount=aVirDev.GetColorCount(); - if (nColorCount<=2) nBitsPerPixel=1; - else if (nColorCount<=4) nBitsPerPixel=2; - else if (nColorCount<=16) nBitsPerPixel=4; - else if (nColorCount<=256) nBitsPerPixel=8; - else if (nColorCount<=65536) nBitsPerPixel=16; - else nBitsPerPixel=24; - nNeededMem=((ULONG)aSizePixel.Width()*(ULONG)aSizePixel.Height()*nBitsPerPixel+7)/8; - - // ggf. Groesse des Bildes einschraenken: - if (nMaxMemIsExportInternalFilter( nFormat ) ) - { - if( aFilterName.EqualsIgnoreCaseAscii( EXP_BMP ) ) - { - Bitmap aBmp( aGraphic.GetBitmap() ); - sal_Int32 nColorRes = aConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Colors" ) ), 0 ); - if ( nColorRes && ( nColorRes <= (USHORT)BMP_CONVERSION_24BIT) ) - { - if( !aBmp.Convert( (BmpConversion) nColorRes ) ) - aBmp = aGraphic.GetBitmap(); - } - ResMgr* pResMgr = CREATERESMGR( svt ); - sal_Bool bRleCoding = aConfigItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "RLE_Coding" ) ), sal_True ); - // Wollen wir RLE-Kodiert speichern? - aBmp.Write( rOStm, bRleCoding ); - delete pResMgr; - - if( rOStm.GetError() ) - nStatus = GRFILTER_IOERROR; - } - else if( aFilterName.EqualsIgnoreCaseAscii( EXP_SVMETAFILE ) ) - { - sal_Int32 nVersion = aConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ), 0 ) ; - if ( nVersion ) - rOStm.SetVersion( nVersion ); - GDIMetaFile aMTF; - - if ( eType != GRAPHIC_BITMAP ) - aMTF = aGraphic.GetGDIMetaFile(); - else - { - VirtualDevice aVirDev; - - aMTF.Record( &aVirDev ); - aGraphic.Draw( &aVirDev, Point(), aGraphic.GetPrefSize() ); - aMTF.Stop(); - aMTF.SetPrefSize( aGraphic.GetPrefSize() ); - aMTF.SetPrefMapMode( aGraphic.GetPrefMapMode() ); - } - rOStm << aMTF; - if( rOStm.GetError() ) - nStatus = GRFILTER_IOERROR; - } - else if ( aFilterName.EqualsIgnoreCaseAscii( EXP_WMF ) ) - { - if( eType == GRAPHIC_GDIMETAFILE ) - { - if ( !ConvertGDIMetaFileToWMF( aGraphic.GetGDIMetaFile(), rOStm, &aConfigItem ) ) - nStatus = GRFILTER_FORMATERROR; - } - else - { - Bitmap aBmp( aGraphic.GetBitmap() ); - GDIMetaFile aMTF; - VirtualDevice aVirDev; - - aMTF.Record( &aVirDev ); - aVirDev.DrawBitmap( Point(), aBmp ); - aMTF.Stop(); - aMTF.SetPrefSize( aBmp.GetSizePixel() ); - - if( !ConvertGDIMetaFileToWMF( aMTF, rOStm, &aConfigItem ) ) - nStatus = GRFILTER_FORMATERROR; - } - if( rOStm.GetError() ) - nStatus = GRFILTER_IOERROR; - } - else if ( aFilterName.EqualsIgnoreCaseAscii( EXP_EMF ) ) - { - if( eType == GRAPHIC_GDIMETAFILE ) - { - if ( !ConvertGDIMetaFileToEMF( aGraphic.GetGDIMetaFile(), rOStm, &aConfigItem ) ) - nStatus = GRFILTER_FORMATERROR; - } - else - { - Bitmap aBmp( aGraphic.GetBitmap() ); - GDIMetaFile aMTF; - VirtualDevice aVirDev; - - aMTF.Record( &aVirDev ); - aVirDev.DrawBitmap( Point(), aBmp ); - aMTF.Stop(); - aMTF.SetPrefSize( aBmp.GetSizePixel() ); - - if( !ConvertGDIMetaFileToEMF( aMTF, rOStm, &aConfigItem ) ) - nStatus = GRFILTER_FORMATERROR; - } - if( rOStm.GetError() ) - nStatus = GRFILTER_IOERROR; - } - else if( aFilterName.EqualsIgnoreCaseAscii( EXP_JPEG ) ) - { - bool bExportedGrayJPEG = false; - if( !ExportJPEG( rOStm, aGraphic, pFilterData, &bExportedGrayJPEG ) ) - nStatus = GRFILTER_FORMATERROR; - nExpGraphHint = bExportedGrayJPEG ? GRFILTER_OUTHINT_GREY : 0; - - if( rOStm.GetError() ) - nStatus = GRFILTER_IOERROR; - } - else if ( aFilterName.EqualsIgnoreCaseAscii( EXP_PNG ) ) - { - vcl::PNGWriter aPNGWriter( aGraphic.GetBitmapEx(), pFilterData ); - if ( pFilterData ) - { - sal_Int32 k, j, i = 0; - for ( i = 0; i < pFilterData->getLength(); i++ ) - { - if ( (*pFilterData)[ i ].Name.equalsAscii( "AdditionalChunks" ) ) - { - com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > aAdditionalChunkSequence; - if ( (*pFilterData)[ i ].Value >>= aAdditionalChunkSequence ) - { - for ( j = 0; j < aAdditionalChunkSequence.getLength(); j++ ) - { - if ( aAdditionalChunkSequence[ j ].Name.getLength() == 4 ) - { - sal_uInt32 nChunkType = 0; - for ( k = 0; k < 4; k++ ) - { - nChunkType <<= 8; - nChunkType |= (sal_uInt8)aAdditionalChunkSequence[ j ].Name[ k ]; - } - com::sun::star::uno::Sequence< sal_Int8 > aByteSeq; - if ( aAdditionalChunkSequence[ j ].Value >>= aByteSeq ) - { - std::vector< vcl::PNGWriter::ChunkData >& rChunkData = aPNGWriter.GetChunks(); - if ( rChunkData.size() ) - { - sal_uInt32 nChunkLen = aByteSeq.getLength(); - - vcl::PNGWriter::ChunkData aChunkData; - aChunkData.nType = nChunkType; - if ( nChunkLen ) - { - aChunkData.aData.resize( nChunkLen ); - rtl_copyMemory( &aChunkData.aData[ 0 ], aByteSeq.getConstArray(), nChunkLen ); - } - std::vector< vcl::PNGWriter::ChunkData >::iterator aIter = rChunkData.end() - 1; - rChunkData.insert( aIter, aChunkData ); - } - } - } - } - } - } - } - } - aPNGWriter.Write( rOStm ); - - if( rOStm.GetError() ) - nStatus = GRFILTER_IOERROR; - } - else if( aFilterName.EqualsIgnoreCaseAscii( EXP_SVG ) ) - { - try - { - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() ); - - if( xMgr.is() ) - { - ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > xSaxWriter( xMgr->createInstance( - ::rtl::OUString::createFromAscii( "com.sun.star.xml.sax.Writer" ) ), ::com::sun::star::uno::UNO_QUERY ); - - ::com::sun::star::uno::Reference< ::com::sun::star::svg::XSVGWriter > xSVGWriter( xMgr->createInstance( - ::rtl::OUString::createFromAscii( "com.sun.star.svg.SVGWriter" ) ), ::com::sun::star::uno::UNO_QUERY ); - - if( xSaxWriter.is() && xSVGWriter.is() ) - { - ::com::sun::star::uno::Reference< ::com::sun::star::io::XActiveDataSource > xActiveDataSource( - xSaxWriter, ::com::sun::star::uno::UNO_QUERY ); - - if( xActiveDataSource.is() ) - { - const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xStmIf( - static_cast< ::cppu::OWeakObject* >( new ImpFilterOutputStream( rOStm ) ) ); - - SvMemoryStream aMemStm( 65535, 65535 ); - - aMemStm.SetCompressMode( COMPRESSMODE_FULL ); - ( (GDIMetaFile&) aGraphic.GetGDIMetaFile() ).Write( aMemStm ); - - xActiveDataSource->setOutputStream( ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >( - xStmIf, ::com::sun::star::uno::UNO_QUERY ) ); - ::com::sun::star::uno::Sequence< sal_Int8 > aMtfSeq( (sal_Int8*) aMemStm.GetData(), aMemStm.Tell() ); - xSVGWriter->write( xSaxWriter, aMtfSeq ); - } - } - } - } - catch( ::com::sun::star::uno::Exception& ) - { - nStatus = GRFILTER_IOERROR; - } - } - else - nStatus = GRFILTER_FILTERERROR; - } - else - { - xub_StrLen i, nTokenCount = aFilterPath.GetTokenCount( ';' ); - for ( i = 0; i < nTokenCount; i++ ) - { - String aPhysicalName( ImpCreateFullFilterPath( aFilterPath.GetToken( i ), aFilterName ) ); - osl::Module aLibrary( aPhysicalName ); - - PFilterCall pFunc = (PFilterCall) aLibrary.getFunctionSymbol( UniString::CreateFromAscii( EXPORT_FUNCTION_NAME ) ); - // Dialog in DLL ausfuehren - if( pFunc ) - { - if ( !(*pFunc)( rOStm, aGraphic, &aConfigItem, sal_False ) ) - nStatus = GRFILTER_FORMATERROR; - break; - } - else - nStatus = GRFILTER_FILTERERROR; - } - } - } - if( nStatus != GRFILTER_OK ) - { - if( bAbort ) - nStatus = GRFILTER_ABORT; - - ImplSetError( nStatus, &rOStm ); - } - return nStatus; -} - -// ------------------------------------------------------------------------ - -BOOL GraphicFilter::Setup( USHORT ) -{ - return FALSE; -} - -/* ------------------------------------------------------------------------ - No Import filter has a dialog, so - the following two methods are obsolete */ - -BOOL GraphicFilter::HasImportDialog( USHORT ) -{ - return sal_True; -// return pConfig->IsImportDialog( nFormat ); -} - -// ------------------------------------------------------------------------ - -BOOL GraphicFilter::DoImportDialog( Window*, USHORT ) -{ - return sal_True; -} - -// ------------------------------------------------------------------------ - -BOOL GraphicFilter::HasExportDialog( USHORT nFormat ) -{ - return pConfig->IsExportDialog( nFormat ); -} - -// ------------------------------------------------------------------------ - -BOOL GraphicFilter::DoExportDialog( Window* pWindow, USHORT nFormat ) -{ - return DoExportDialog( pWindow, nFormat, FUNIT_MM ); -} - -BOOL GraphicFilter::DoExportDialog( Window*, USHORT nFormat, FieldUnit ) -{ - sal_Bool bRet = sal_False; - com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > - xSMgr( ::comphelper::getProcessServiceFactory() ); - - uno::Reference< com::sun::star::uno::XInterface > xFilterOptionsDialog - ( xSMgr->createInstance( rtl::OUString::createFromAscii( "com.sun.star.svtools.SvFilterOptionsDialog" ) ), - com::sun::star::uno::UNO_QUERY ); - if ( xFilterOptionsDialog.is() ) - { - com::sun::star::uno::Reference< com::sun::star::ui::dialogs::XExecutableDialog > xExecutableDialog - ( xFilterOptionsDialog, ::com::sun::star::uno::UNO_QUERY ); - com::sun::star::uno::Reference< com::sun::star::beans::XPropertyAccess > xPropertyAccess - ( xFilterOptionsDialog, ::com::sun::star::uno::UNO_QUERY ); - if ( xExecutableDialog.is() && xPropertyAccess.is() ) - { - com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aMediaDescriptor( 1 ); - aMediaDescriptor[ 0 ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) ); - rtl::OUString aStr( pConfig->GetExportInternalFilterName( nFormat ) ); - aMediaDescriptor[ 0 ].Value <<= aStr; - xPropertyAccess->setPropertyValues( aMediaDescriptor ); - bRet = xExecutableDialog->execute() == com::sun::star::ui::dialogs::ExecutableDialogResults::OK; - } - } - return bRet; -} - -// ------------------------------------------------------------------------ - -const FilterErrorEx& GraphicFilter::GetLastError() const -{ - return *pErrorEx; -} - -// ------------------------------------------------------------------------ - -void GraphicFilter::ResetLastError() -{ - pErrorEx->nFilterError = pErrorEx->nStreamError = 0UL; -} - -// ------------------------------------------------------------------------ - -const Link GraphicFilter::GetFilterCallback() const -{ - const Link aLink( LINK( this, GraphicFilter, FilterCallback ) ); - return aLink; -} - -// ------------------------------------------------------------------------ - -IMPL_LINK( GraphicFilter, FilterCallback, ConvertData*, pData ) -{ - long nRet = 0L; - - if( pData ) - { - USHORT nFormat = GRFILTER_FORMAT_DONTKNOW; - ByteString aShortName; - switch( pData->mnFormat ) - { - case( CVT_BMP ): aShortName = BMP_SHORTNAME; break; - case( CVT_GIF ): aShortName = GIF_SHORTNAME; break; - case( CVT_JPG ): aShortName = JPG_SHORTNAME; break; - case( CVT_MET ): aShortName = MET_SHORTNAME; break; - case( CVT_PCT ): aShortName = PCT_SHORTNAME; break; - case( CVT_PNG ): aShortName = PNG_SHORTNAME; break; - case( CVT_SVM ): aShortName = SVM_SHORTNAME; break; - case( CVT_TIF ): aShortName = TIF_SHORTNAME; break; - case( CVT_WMF ): aShortName = WMF_SHORTNAME; break; - case( CVT_EMF ): aShortName = EMF_SHORTNAME; break; - - default: - break; - } - if( GRAPHIC_NONE == pData->maGraphic.GetType() || pData->maGraphic.GetContext() ) // Import - { - // Import - nFormat = GetImportFormatNumberForShortName( String( aShortName.GetBuffer(), RTL_TEXTENCODING_UTF8 ) ); - nRet = ImportGraphic( pData->maGraphic, String(), pData->mrStm ) == 0; - } - else if( aShortName.Len() ) - { - // Export - nFormat = GetExportFormatNumberForShortName( String( aShortName.GetBuffer(), RTL_TEXTENCODING_UTF8 ) ); - nRet = ExportGraphic( pData->maGraphic, String(), pData->mrStm, nFormat ) == 0; - } - } - return nRet; -} - -// ------------------------------------------------------------------------ - -GraphicFilter* GraphicFilter::GetGraphicFilter() -{ - if( !pGraphicFilter ) - { - pGraphicFilter = new GraphicFilter; - pGraphicFilter->GetImportFormatCount(); - } - return pGraphicFilter; -} - -int GraphicFilter::LoadGraphic( const String &rPath, const String &rFilterName, - Graphic& rGraphic, GraphicFilter* pFilter, - USHORT* pDeterminedFormat ) -{ - if ( !pFilter ) - pFilter = GetGraphicFilter(); - - const USHORT nFilter = rFilterName.Len() && pFilter->GetImportFormatCount() - ? pFilter->GetImportFormatNumber( rFilterName ) - : GRFILTER_FORMAT_DONTKNOW; - - SvStream* pStream = NULL; - INetURLObject aURL( rPath ); - - if ( aURL.HasError() || INET_PROT_NOT_VALID == aURL.GetProtocol() ) - { - aURL.SetSmartProtocol( INET_PROT_FILE ); - aURL.SetSmartURL( rPath ); - } - else if ( INET_PROT_FILE != aURL.GetProtocol() ) - { - pStream = ::utl::UcbStreamHelper::CreateStream( rPath, STREAM_READ ); - } - - int nRes = GRFILTER_OK; - if ( !pStream ) - nRes = pFilter->ImportGraphic( rGraphic, aURL, nFilter, pDeterminedFormat ); - else - nRes = pFilter->ImportGraphic( rGraphic, rPath, *pStream, nFilter, pDeterminedFormat ); - -#ifdef DBG_UTIL - if( nRes ) - DBG_WARNING2( "GrafikFehler [%d] - [%s]", nRes, rPath.GetBuffer() ); -#endif - - return nRes; -} - diff --git a/svtools/source/filter.vcl/filter/filter2.cxx b/svtools/source/filter.vcl/filter/filter2.cxx deleted file mode 100644 index d91ec1a19772..000000000000 --- a/svtools/source/filter.vcl/filter/filter2.cxx +++ /dev/null @@ -1,1339 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#include -#include -#include -#include -#include -#include -#include -#include "FilterConfigCache.hxx" -#include - -#define DATA_SIZE 640 - -BYTE* ImplSearchEntry( BYTE* , BYTE* , ULONG , ULONG ); - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -GraphicDescriptor::GraphicDescriptor( const INetURLObject& rPath ) : - pFileStm( ::utl::UcbStreamHelper::CreateStream( rPath.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ) ), - aPathExt( rPath.GetFileExtension().toAsciiLowerCase() ), - bOwnStream( TRUE ) -{ - ImpConstruct(); -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -GraphicDescriptor::GraphicDescriptor( SvStream& rInStream, const String* pPath) : - pFileStm ( &rInStream ), - bOwnStream ( FALSE ) -{ - ImpConstruct(); - - if ( pPath ) - { - INetURLObject aURL( *pPath ); - aPathExt = aURL.GetFileExtension().toAsciiLowerCase(); - } -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -GraphicDescriptor::~GraphicDescriptor() -{ - if ( bOwnStream ) - delete pFileStm; -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::Detect( BOOL bExtendedInfo ) -{ - BOOL bRet = FALSE; - if ( pFileStm && !pFileStm->GetError() ) - { - SvStream& rStm = *pFileStm; - UINT16 nOldFormat = rStm.GetNumberFormatInt(); - - if ( ImpDetectGIF( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectJPG( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectBMP( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectPNG( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectTIF( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectPCX( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectDXF( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectMET( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectSGF( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectSGV( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectSVM( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectWMF( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectEMF( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectPCT( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectXBM( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectXPM( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectPBM( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectPGM( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectPPM( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectRAS( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectTGA( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectPSD( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectEPS( rStm, bExtendedInfo ) ) bRet = TRUE; - else if ( ImpDetectPCD( rStm, bExtendedInfo ) ) bRet = TRUE; - - rStm.SetNumberFormatInt( nOldFormat ); - } - return bRet; -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -void GraphicDescriptor::ImpConstruct() -{ - nFormat = GFF_NOT; - nBitsPerPixel = 0; - nPlanes = 0; - bCompressed = FALSE; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectBMP( SvStream& rStm, BOOL bExtendedInfo ) -{ - UINT16 nTemp16; - BOOL bRet = FALSE; - sal_Int32 nStmPos = rStm.Tell(); - - rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); - rStm >> nTemp16; - - // OS/2-BitmapArray - if ( nTemp16 == 0x4142 ) - { - rStm.SeekRel( 0x0c ); - rStm >> nTemp16; - } - - // Bitmap - if ( nTemp16 == 0x4d42 ) - { - nFormat = GFF_BMP; - bRet = TRUE; - - if ( bExtendedInfo ) - { - UINT32 nTemp32; - UINT32 nCompression; - - // bis zur ersten Information - rStm.SeekRel( 0x10 ); - - // PixelBreite auslesen - rStm >> nTemp32; - aPixSize.Width() = nTemp32; - - // PixelHoehe auslesen - rStm >> nTemp32; - aPixSize.Height() = nTemp32; - - // Planes auslesen - rStm >> nTemp16; - nPlanes = nTemp16; - - // BitCount auslesen - rStm >> nTemp16; - nBitsPerPixel = nTemp16; - - // Compression auslesen - rStm >> nTemp32; - bCompressed = ( ( nCompression = nTemp32 ) > 0 ); - - // logische Breite - rStm.SeekRel( 4 ); - rStm >> nTemp32; - if ( nTemp32 ) - aLogSize.Width() = ( aPixSize.Width() * 100000 ) / nTemp32; - - // logische Hoehe - rStm >> nTemp32; - if ( nTemp32 ) - aLogSize.Height() = ( aPixSize.Height() * 100000 ) / nTemp32; - - // Wir wollen noch etwas feiner differenzieren und - // auf sinnvolle Werte ueberpruefen ( Bug-Id #29001 ) - if ( ( nBitsPerPixel > 24 ) || ( nCompression > 3 ) ) - { - nFormat = GFF_NOT; - bRet = FALSE; - } - } - } - rStm.Seek( nStmPos ); - return bRet; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectGIF( SvStream& rStm, BOOL bExtendedInfo ) -{ - UINT32 n32; - UINT16 n16; - BOOL bRet = FALSE; - BYTE cByte; - - sal_Int32 nStmPos = rStm.Tell(); - rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); - rStm >> n32; - - if ( n32 == 0x38464947 ) - { - rStm >> n16; - if ( ( n16 == 0x6137 ) || ( n16 == 0x6139 ) ) - { - nFormat = GFF_GIF; - bRet = TRUE; - - if ( bExtendedInfo ) - { - UINT16 nTemp16; - - // PixelBreite auslesen - rStm >> nTemp16; - aPixSize.Width() = nTemp16; - - // PixelHoehe auslesen - rStm >> nTemp16; - aPixSize.Height() = nTemp16; - - // Bits/Pixel auslesen - rStm >> cByte; - nBitsPerPixel = ( ( cByte & 112 ) >> 4 ) + 1; - } - } - } - rStm.Seek( nStmPos ); - return bRet; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -// returns the next jpeg marker, a return value of 0 represents an error -sal_uInt8 ImpDetectJPG_GetNextMarker( SvStream& rStm ) -{ - sal_uInt8 nByte; - do - { - do - { - rStm >> nByte; - if ( rStm.IsEof() || rStm.GetError() ) // as 0 is not allowed as marker, - return 0; // we can use it as errorcode - } - while ( nByte != 0xff ); - do - { - rStm >> nByte; - if ( rStm.IsEof() || rStm.GetError() ) - return 0; - } - while( nByte == 0xff ); - } - while( nByte == 0 ); // 0xff00 represents 0xff and not a marker, - // the marker detection has to be restartet. - return nByte; -} - -BOOL GraphicDescriptor::ImpDetectJPG( SvStream& rStm, BOOL bExtendedInfo ) -{ - UINT32 nTemp32; - BOOL bRet = FALSE; - - sal_Int32 nStmPos = rStm.Tell(); - - rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); - rStm >> nTemp32; - - // compare upper 24 bits - if( 0xffd8ff00 == ( nTemp32 & 0xffffff00 ) ) - { - nFormat = GFF_JPG; - bRet = TRUE; - - if ( bExtendedInfo ) - { - rStm.SeekRel( -2 ); - - sal_uInt32 nError( rStm.GetError() ); - - sal_Bool bScanFailure = sal_False; - sal_Bool bScanFinished = sal_False; - - while( !bScanFailure && !bScanFinished && !rStm.IsEof() && !rStm.GetError() ) - { - sal_uInt8 nMarker = ImpDetectJPG_GetNextMarker( rStm ); - switch( nMarker ) - { - // fixed size marker, not having a two byte length parameter - case 0xd0 : // RST0 - case 0xd1 : - case 0xd2 : - case 0xd3 : - case 0xd4 : - case 0xd5 : - case 0xd6 : - case 0xd7 : // RST7 - case 0x01 : // TEM - break; - - case 0xd8 : // SOI (has already been checked, there should not be a second one) - case 0x00 : // marker is invalid, we should stop now - bScanFailure = sal_True; - break; - - case 0xd9 : // EOI - bScanFinished = sal_True; - break; - - // per default we assume marker segments conaining a length parameter - default : - { - sal_uInt16 nLength; - rStm >> nLength; - - if ( nLength < 2 ) - bScanFailure = sal_True; - else - { - sal_uInt32 nNextMarkerPos = rStm.Tell() + nLength - 2; - switch( nMarker ) - { - case 0xe0 : // APP0 Marker - { - if ( nLength == 16 ) - { - sal_Int32 nIdentifier; - rStm >> nIdentifier; - if ( nIdentifier == 0x4a464946 ) // JFIF Identifier - { - sal_uInt8 nStringTerminator; - sal_uInt8 nMajorRevision; - sal_uInt8 nMinorRevision; - sal_uInt8 nUnits; - sal_uInt16 nHorizontalResolution; - sal_uInt16 nVerticalResolution; - sal_uInt8 nHorzThumbnailPixelCount; - sal_uInt8 nVertThumbnailPixelCount; - - rStm >> nStringTerminator - >> nMajorRevision - >> nMinorRevision - >> nUnits - >> nHorizontalResolution - >> nVerticalResolution - >> nHorzThumbnailPixelCount - >> nVertThumbnailPixelCount; - - // setting the logical size - if ( nUnits && nHorizontalResolution && nVerticalResolution ) - { - MapMode aMap; - aMap.SetMapUnit( nUnits == 1 ? MAP_INCH : MAP_CM ); - aMap.SetScaleX( Fraction( 1, nHorizontalResolution ) ); - aMap.SetScaleY( Fraction( 1, nVerticalResolution ) ); - aLogSize = OutputDevice::LogicToLogic( aPixSize, aMap, MapMode( MAP_100TH_MM ) ); - } - } - } - } - break; - - // Start of Frame Markers - case 0xc0 : // SOF0 - case 0xc1 : // SOF1 - case 0xc2 : // SOF2 - case 0xc3 : // SOF3 - case 0xc5 : // SOF5 - case 0xc6 : // SOF6 - case 0xc7 : // SOF7 - case 0xc9 : // SOF9 - case 0xca : // SOF10 - case 0xcb : // SOF11 - case 0xcd : // SOF13 - case 0xce : // SOF14 - case 0xcf : // SOF15 - { - sal_uInt8 nSamplePrecision; - sal_uInt16 nNumberOfLines; - sal_uInt16 nSamplesPerLine; - sal_uInt8 nNumberOfImageComponents; - sal_uInt8 nComponentsIdentifier; - sal_uInt8 nHorizontalSamplingFactor; - sal_uInt8 nVerticalSamplingFactor; - sal_uInt8 nQuantizationTableDestinationSelector; - rStm >> nSamplePrecision - >> nNumberOfLines - >> nSamplesPerLine - >> nNumberOfImageComponents - >> nComponentsIdentifier - >> nHorizontalSamplingFactor - >> nQuantizationTableDestinationSelector; - nVerticalSamplingFactor = nHorizontalSamplingFactor & 0xf; - nHorizontalSamplingFactor >>= 4; - - aPixSize.Height() = nNumberOfLines; - aPixSize.Width() = nSamplesPerLine; - nBitsPerPixel = ( nNumberOfImageComponents == 3 ? 24 : nNumberOfImageComponents == 1 ? 8 : 0 ); - nPlanes = 1; - - bScanFinished = sal_True; - } - break; - } - rStm.Seek( nNextMarkerPos ); - } - } - break; - } - } - rStm.SetError( nError ); - } - } - rStm.Seek( nStmPos ); - return bRet; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectPCD( SvStream& rStm, BOOL ) -{ - BOOL bRet = FALSE; - - sal_Int32 nStmPos = rStm.Tell(); - rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); - - UINT32 nTemp32; - UINT16 nTemp16; - BYTE cByte; - - rStm.SeekRel( 2048 ); - rStm >> nTemp32; - rStm >> nTemp16; - rStm >> cByte; - - if ( ( nTemp32 == 0x5f444350 ) && - ( nTemp16 == 0x5049 ) && - ( cByte == 0x49 ) ) - { - nFormat = GFF_PCD; - bRet = TRUE; - } - rStm.Seek( nStmPos ); - return bRet; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectPCX( SvStream& rStm, BOOL bExtendedInfo ) -{ - // ! Because 0x0a can be interpreted as LF too ... - // we cant be shure that this special sign represent a PCX file only. - // Every Ascii file is possible here :-( - // We must detect the whole header. - bExtendedInfo = TRUE; - - BOOL bRet = FALSE; - BYTE cByte; - - sal_Int32 nStmPos = rStm.Tell(); - rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); - rStm >> cByte; - - if ( cByte == 0x0a ) - { - nFormat = GFF_PCX; - bRet = TRUE; - - if ( bExtendedInfo ) - { - UINT16 nTemp16; - USHORT nXmin; - USHORT nXmax; - USHORT nYmin; - USHORT nYmax; - USHORT nDPIx; - USHORT nDPIy; - - - rStm.SeekRel( 1 ); - - // Kompression lesen - rStm >> cByte; - bCompressed = ( cByte > 0 ); - - bRet = (cByte==0 || cByte ==1); - - // Bits/Pixel lesen - rStm >> cByte; - nBitsPerPixel = cByte; - - // Bildabmessungen - rStm >> nTemp16; - nXmin = nTemp16; - rStm >> nTemp16; - nYmin = nTemp16; - rStm >> nTemp16; - nXmax = nTemp16; - rStm >> nTemp16; - nYmax = nTemp16; - - aPixSize.Width() = nXmax - nXmin + 1; - aPixSize.Height() = nYmax - nYmin + 1; - - // Aufloesung - rStm >> nTemp16; - nDPIx = nTemp16; - rStm >> nTemp16; - nDPIy = nTemp16; - - // logische Groesse setzen - MapMode aMap( MAP_INCH, Point(), - Fraction( 1, nDPIx ), Fraction( 1, nDPIy ) ); - aLogSize = OutputDevice::LogicToLogic( aPixSize, aMap, - MapMode( MAP_100TH_MM ) ); - - - // Anzahl Farbebenen - rStm.SeekRel( 49 ); - rStm >> cByte; - nPlanes = cByte; - - bRet = (nPlanes<=4); - } - } - - rStm.Seek( nStmPos ); - return bRet; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectPNG( SvStream& rStm, BOOL bExtendedInfo ) -{ - UINT32 nTemp32; - BOOL bRet = FALSE; - - sal_Int32 nStmPos = rStm.Tell(); - rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); - rStm >> nTemp32; - - if ( nTemp32 == 0x89504e47 ) - { - rStm >> nTemp32; - if ( nTemp32 == 0x0d0a1a0a ) - { - nFormat = GFF_PNG; - bRet = TRUE; - - if ( bExtendedInfo ) - { - BYTE cByte; - - // IHDR-Chunk - rStm.SeekRel( 8 ); - - // Breite einlesen - rStm >> nTemp32; - aPixSize.Width() = nTemp32; - - // Hoehe einlesen - rStm >> nTemp32; - aPixSize.Height() = nTemp32; - - // Bits/Pixel einlesen - rStm >> cByte; - nBitsPerPixel = cByte; - - // Planes immer 1; - // Kompression immer - nPlanes = 1; - bCompressed = TRUE; - - UINT32 nLen32; - - rStm.SeekRel( 8 ); - - // so lange ueberlesen, bis wir den pHYs-Chunk haben oder - // den Anfang der Bilddaten - rStm >> nLen32; - rStm >> nTemp32; - while( ( nTemp32 != 0x70485973 ) && ( nTemp32 != 0x49444154 ) ) - { - rStm.SeekRel( 4 + nLen32 ); - rStm >> nLen32; - rStm >> nTemp32; - } - - if ( nTemp32 == 0x70485973 ) - { - ULONG nXRes; - ULONG nYRes; - - // horizontale Aufloesung - rStm >> nTemp32; - nXRes = nTemp32; - - // vertikale Aufloesung - rStm >> nTemp32; - nYRes = nTemp32; - - // Unit einlesen - rStm >> cByte; - - if ( cByte ) - { - if ( nXRes ) - aLogSize.Width() = ( aPixSize.Width() * 100000 ) / - nTemp32; - - if ( nYRes ) - aLogSize.Height() = ( aPixSize.Height() * 100000 ) / - nTemp32; - } - } - } - } - } - rStm.Seek( nStmPos ); - return bRet; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectTIF( SvStream& rStm, BOOL bExtendedInfo ) -{ - BOOL bDetectOk = FALSE; - BOOL bRet = FALSE; - BYTE cByte1; - BYTE cByte2; - - sal_Int32 nStmPos = rStm.Tell(); - rStm >> cByte1; - rStm >> cByte2; - if ( cByte1 == cByte2 ) - { - if ( cByte1 == 0x49 ) - { - rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); - bDetectOk = TRUE; - } - else if ( cByte1 == 0x4d ) - { - rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); - bDetectOk = TRUE; - } - - if ( bDetectOk ) - { - UINT16 nTemp16; - - rStm >> nTemp16; - if ( nTemp16 == 0x2a ) - { - nFormat = GFF_TIF; - bRet = TRUE; - - if ( bExtendedInfo ) - { - ULONG nCount; - ULONG nMax = DATA_SIZE - 48; - UINT32 nTemp32; - BOOL bOk = FALSE; - - // Offset des ersten IFD einlesen - rStm >> nTemp32; - rStm.SeekRel( ( nCount = ( nTemp32 + 2 ) ) - 0x08 ); - - if ( nCount < nMax ) - { - // Tag's lesen, bis wir auf Tag256 ( Width ) treffen - // nicht mehr Bytes als DATA_SIZE lesen - rStm >> nTemp16; - while ( nTemp16 != 256 ) - { - bOk = nCount < nMax; - if ( !bOk ) - { - break; - } - rStm.SeekRel( 10 ); - rStm >> nTemp16; - nCount += 12; - } - - if ( bOk ) - { - // Breite lesen - rStm >> nTemp16; - rStm.SeekRel( 4 ); - if ( nTemp16 == 3 ) - { - rStm >> nTemp16; - aPixSize.Width() = nTemp16; - rStm.SeekRel( 2 ); - } - else - { - rStm >> nTemp32; - aPixSize.Width() = nTemp32; - } - nCount += 12; - - // Hoehe lesen - rStm.SeekRel( 2 ); - rStm >> nTemp16; - rStm.SeekRel( 4 ); - if ( nTemp16 == 3 ) - { - rStm >> nTemp16; - aPixSize.Height() = nTemp16; - rStm.SeekRel( 2 ); - } - else - { - rStm >> nTemp32; - aPixSize.Height() = nTemp32; - } - nCount += 12; - - // ggf. Bits/Pixel lesen - rStm >> nTemp16; - if ( nTemp16 == 258 ) - { - rStm.SeekRel( 6 ); - rStm >> nTemp16; - nBitsPerPixel = nTemp16; - rStm.SeekRel( 2 ); - nCount += 12; - } - else - rStm.SeekRel( -2 ); - - // ggf. Compression lesen - rStm >> nTemp16; - if ( nTemp16 == 259 ) - { - rStm.SeekRel( 6 ); - rStm >> nTemp16; - bCompressed = ( nTemp16 > 1 ); - rStm.SeekRel( 2 ); - nCount += 12; - } - else - rStm.SeekRel( -2 ); - } - } - } - } - } - } - rStm.Seek( nStmPos ); - return bRet; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectXBM( SvStream&, BOOL ) -{ - BOOL bRet = aPathExt.CompareToAscii( "xbm", 3 ) == COMPARE_EQUAL; - if (bRet) - nFormat = GFF_XBM; - - return bRet; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectXPM( SvStream&, BOOL ) -{ - BOOL bRet = aPathExt.CompareToAscii( "xpm", 3 ) == COMPARE_EQUAL; - if (bRet) - nFormat = GFF_XPM; - - return bRet; -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectPBM( SvStream& rStm, BOOL ) -{ - BOOL bRet = FALSE; - - // erst auf Datei Extension pruefen, da diese aussagekraeftiger ist - // als die 2 ID Bytes - - if ( aPathExt.CompareToAscii( "pbm", 3 ) == COMPARE_EQUAL ) - bRet = TRUE; - else - { - sal_Int32 nStmPos = rStm.Tell(); - BYTE nFirst, nSecond; - rStm >> nFirst >> nSecond; - if ( nFirst == 'P' && ( ( nSecond == '1' ) || ( nSecond == '4' ) ) ) - bRet = TRUE; - rStm.Seek( nStmPos ); - } - - if ( bRet ) - nFormat = GFF_PBM; - - return bRet; -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectPGM( SvStream& rStm, BOOL ) -{ - BOOL bRet = FALSE; - - if ( aPathExt.CompareToAscii( "pgm", 3 ) == COMPARE_EQUAL ) - bRet = TRUE; - else - { - BYTE nFirst, nSecond; - sal_Int32 nStmPos = rStm.Tell(); - rStm >> nFirst >> nSecond; - if ( nFirst == 'P' && ( ( nSecond == '2' ) || ( nSecond == '5' ) ) ) - bRet = TRUE; - rStm.Seek( nStmPos ); - } - - if ( bRet ) - nFormat = GFF_PGM; - - return bRet; -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectPPM( SvStream& rStm, BOOL ) -{ - BOOL bRet = FALSE; - - if ( aPathExt.CompareToAscii( "ppm", 3 ) == COMPARE_EQUAL ) - bRet = TRUE; - else - { - BYTE nFirst, nSecond; - sal_Int32 nStmPos = rStm.Tell(); - rStm >> nFirst >> nSecond; - if ( nFirst == 'P' && ( ( nSecond == '3' ) || ( nSecond == '6' ) ) ) - bRet = TRUE; - rStm.Seek( nStmPos ); - } - - if ( bRet ) - nFormat = GFF_PPM; - - return bRet; -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectRAS( SvStream& rStm, BOOL ) -{ - UINT32 nMagicNumber; - BOOL bRet = FALSE; - sal_Int32 nStmPos = rStm.Tell(); - rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); - rStm >> nMagicNumber; - if ( nMagicNumber == 0x59a66a95 ) - { - nFormat = GFF_RAS; - bRet = TRUE; - } - rStm.Seek( nStmPos ); - return bRet; -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectTGA( SvStream&, BOOL ) -{ - BOOL bRet = aPathExt.CompareToAscii( "tga", 3 ) == COMPARE_EQUAL; - if (bRet) - nFormat = GFF_TGA; - - return bRet; -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectPSD( SvStream& rStm, BOOL bExtendedInfo ) -{ - BOOL bRet = FALSE; - - UINT32 nMagicNumber; - sal_Int32 nStmPos = rStm.Tell(); - rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); - rStm >> nMagicNumber; - if ( nMagicNumber == 0x38425053 ) - { - UINT16 nVersion; - rStm >> nVersion; - if ( nVersion == 1 ) - { - bRet = TRUE; - if ( bExtendedInfo ) - { - UINT16 nChannels; - UINT32 nRows; - UINT32 nColumns; - UINT16 nDepth; - UINT16 nMode; - rStm.SeekRel( 6 ); // Pad - rStm >> nChannels >> nRows >> nColumns >> nDepth >> nMode; - if ( ( nDepth == 1 ) || ( nDepth == 8 ) || ( nDepth == 16 ) ) - { - nBitsPerPixel = ( nDepth == 16 ) ? 8 : nDepth; - switch ( nChannels ) - { - case 4 : - case 3 : - nBitsPerPixel = 24; - case 2 : - case 1 : - aPixSize.Width() = nColumns; - aPixSize.Height() = nRows; - break; - default: - bRet = FALSE; - } - } - else - bRet = FALSE; - } - } - } - - if ( bRet ) - nFormat = GFF_PSD; - rStm.Seek( nStmPos ); - return bRet; -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectEPS( SvStream& rStm, BOOL ) -{ - // es wird die EPS mit Vorschaubild Variante und die Extensionuebereinstimmung - // geprueft - - sal_uInt32 nFirstLong; - sal_uInt8 nFirstBytes[20]; - BOOL bRet = FALSE; - - sal_Int32 nStmPos = rStm.Tell(); - rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); - rStm >> nFirstLong; - rStm.SeekRel( -4 ); - rStm.Read( &nFirstBytes, 20 ); - - if ( ( nFirstLong == 0xC5D0D3C6 ) || ( aPathExt.CompareToAscii( "eps", 3 ) == COMPARE_EQUAL ) || - ( ImplSearchEntry( nFirstBytes, (sal_uInt8*)"%!PS-Adobe", 10, 10 ) - && ImplSearchEntry( &nFirstBytes[15], (sal_uInt8*)"EPS", 3, 3 ) ) ) - { - nFormat = GFF_EPS; - bRet = TRUE; - } - rStm.Seek( nStmPos ); - return bRet; -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectDXF( SvStream&, BOOL ) -{ - BOOL bRet = aPathExt.CompareToAscii( "dxf", 3 ) == COMPARE_EQUAL; - if (bRet) - nFormat = GFF_DXF; - - return bRet; -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectMET( SvStream&, BOOL ) -{ - BOOL bRet = aPathExt.CompareToAscii( "met", 3 ) == COMPARE_EQUAL; - if (bRet) - nFormat = GFF_MET; - - return bRet; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectPCT( SvStream& rStm, BOOL ) -{ - BOOL bRet = aPathExt.CompareToAscii( "pct", 3 ) == COMPARE_EQUAL; - if (bRet) - nFormat = GFF_PCT; - else - { - sal_Int32 nStmPos = rStm.Tell(); - - BYTE sBuf[4]; - - rStm.SeekRel( 522 ); - rStm.Read( sBuf, 3 ); - - if( !rStm.GetError() ) - { - if ( ( sBuf[0] == 0x00 ) && ( sBuf[1] == 0x11 ) && - ( ( sBuf[2] == 0x01 ) || ( sBuf[2] == 0x02 ) ) ) - { - bRet = TRUE; - nFormat = GFF_PCT; - } - } - rStm.Seek( nStmPos ); - } - - return bRet; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectSGF( SvStream& rStm, BOOL ) -{ - BOOL bRet = FALSE; - if( aPathExt.CompareToAscii( "sgf", 3 ) == COMPARE_EQUAL ) - bRet = TRUE; - else - { - sal_Int32 nStmPos = rStm.Tell(); - - BYTE nFirst, nSecond; - - rStm >> nFirst >> nSecond; - - if( nFirst == 'J' && nSecond == 'J' ) - bRet = TRUE; - - rStm.Seek( nStmPos ); - } - - if( bRet ) - nFormat = GFF_SGF; - - return bRet; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectSGV( SvStream&, BOOL ) -{ - BOOL bRet = aPathExt.CompareToAscii( "sgv", 3 ) == COMPARE_EQUAL; - if (bRet) - nFormat = GFF_SGV; - - return bRet; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectSVM( SvStream& rStm, BOOL bExtendedInfo ) -{ - UINT32 n32; - BOOL bRet = FALSE; - BYTE cByte; - - sal_Int32 nStmPos = rStm.Tell(); - rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); - rStm >> n32; - if ( n32 == 0x44475653 ) - { - rStm >> cByte; - if ( cByte == 0x49 ) - { - nFormat = GFF_SVM; - bRet = TRUE; - - if ( bExtendedInfo ) - { - UINT32 nTemp32; - UINT16 nTemp16; - - rStm.SeekRel( 0x04 ); - - // Breite auslesen - rStm >> nTemp32; - aLogSize.Width() = nTemp32; - - // Hoehe auslesen - rStm >> nTemp32; - aLogSize.Height() = nTemp32; - - // Map-Unit auslesen und PrefSize ermitteln - rStm >> nTemp16; - aLogSize = OutputDevice::LogicToLogic( aLogSize, - MapMode( (MapUnit) nTemp16 ), - MapMode( MAP_100TH_MM ) ); - } - } - } - else - { - rStm.SeekRel( -4L ); - rStm >> n32; - - if( n32 == 0x4D4C4356 ) - { - UINT16 nTmp16; - - rStm >> nTmp16; - - if( nTmp16 == 0x4654 ) - { - nFormat = GFF_SVM; - bRet = TRUE; - - if( bExtendedInfo ) - { - MapMode aMapMode; - - rStm.SeekRel( 0x06 ); - rStm >> aMapMode; - rStm >> aLogSize; - aLogSize = OutputDevice::LogicToLogic( aLogSize, aMapMode, MapMode( MAP_100TH_MM ) ); - } - } - } - } - rStm.Seek( nStmPos ); - return bRet; -} - - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectWMF( SvStream&, BOOL ) -{ - BOOL bRet = aPathExt.CompareToAscii( "wmf",3 ) == COMPARE_EQUAL; - if (bRet) - nFormat = GFF_WMF; - - return bRet; -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -BOOL GraphicDescriptor::ImpDetectEMF( SvStream&, BOOL ) -{ - BOOL bRet = aPathExt.CompareToAscii( "emf", 3 ) == COMPARE_EQUAL; - if (bRet) - nFormat = GFF_EMF; - - return bRet; -} - -/************************************************************************* -|* -|* -|* -\************************************************************************/ - -String GraphicDescriptor::GetImportFormatShortName( sal_uInt16 nFormat ) -{ - ByteString aKeyName; - - switch( nFormat ) - { - case( GFF_BMP ) : aKeyName = "bmp"; break; - case( GFF_GIF ) : aKeyName = "gif"; break; - case( GFF_JPG ) : aKeyName = "jpg"; break; - case( GFF_PCD ) : aKeyName = "pcd"; break; - case( GFF_PCX ) : aKeyName = "pcx"; break; - case( GFF_PNG ) : aKeyName = "png"; break; - case( GFF_XBM ) : aKeyName = "xbm"; break; - case( GFF_XPM ) : aKeyName = "xpm"; break; - case( GFF_PBM ) : aKeyName = "pbm"; break; - case( GFF_PGM ) : aKeyName = "pgm"; break; - case( GFF_PPM ) : aKeyName = "ppm"; break; - case( GFF_RAS ) : aKeyName = "ras"; break; - case( GFF_TGA ) : aKeyName = "tga"; break; - case( GFF_PSD ) : aKeyName = "psd"; break; - case( GFF_EPS ) : aKeyName = "eps"; break; - case( GFF_TIF ) : aKeyName = "tif"; break; - case( GFF_DXF ) : aKeyName = "dxf"; break; - case( GFF_MET ) : aKeyName = "met"; break; - case( GFF_PCT ) : aKeyName = "pct"; break; - case( GFF_SGF ) : aKeyName = "sgf"; break; - case( GFF_SGV ) : aKeyName = "sgv"; break; - case( GFF_SVM ) : aKeyName = "svm"; break; - case( GFF_WMF ) : aKeyName = "wmf"; break; - case( GFF_EMF ) : aKeyName = "emf"; break; - } - - return String( aKeyName, RTL_TEXTENCODING_ASCII_US ); -} - - diff --git a/svtools/source/filter.vcl/filter/sgf.ini b/svtools/source/filter.vcl/filter/sgf.ini deleted file mode 100644 index 7444e40c8836..000000000000 --- a/svtools/source/filter.vcl/filter/sgf.ini +++ /dev/null @@ -1,118 +0,0 @@ -#Family : (Roman,Swiss,Modern,Script,Decora); -#CharSet : (Ansi,IBMPC,Mac,Symbol,System); Default is System -#Attribute: (Bold,Ital,Sans,Serf,Fixd); - -[SGV Fonts fuer StarView] -#IF-ID Fontname Attribute SV-Fam ChSet Width FontName - 3848=(ITC Zapf Dingbats) Decora () - 5720=(Symbol) Serf Decora Symbol () - 5721=(Symbol) Bold Serf Decora Symbol () - 5723=(Symbol Sans) Sans Decora Symbol () - 5724=(Symbol Sans) Bold Sans Decora Symbol () - 90133=(Dom Casual) Sans Script () - 90326=(Brush) Bold Ital Serf Script () - 90349=(Park Avenue) Ital Serf Script () - 90508=(Uncial) Sans Roman () - 91118=(Antique Olive) Bold Sans Swiss () - 91119=(Antique Olive) Sans Swiss () - 91120=(Antique Olive Compact) Bold Sans Swiss () - 91335=(ITC Benguiat) Bold Serf Roman () - 91336=(ITC Benguiat) Bold Ital Serf Roman () - 91846=(Antique Olive) Ital Sans Roman () -#92500=(CG Times) Serf Roman () -#92501=(CG Times) Ital Serf Roman () -#92504=(CG Times) Bold Serf Roman () -#92505=(CG Times) Bold Ital Serf Roman () -#93950=(Courier) Serf Fixd Modern () -#93951=(Courier) Ital Serf Fixd Modern () -#93952=(Courier) Bold Serf Fixd Modern () -#93953=(Courier) Bold Ital Serf Fixd Modern () -#94021=(Univers) Sans Swiss () -#94022=(Univers) Ital Sans Swiss () -#94023=(Univers) Bold Sans Swiss () -#94024=(Univers) Bold Ital Sans Swiss () -102004=(Avanti) Bold Ital Sans Swiss () -102005=(Avanti) Ital Sans Swiss () -102007=(Booklet) Bold Sans Roman () -102008=(Booklet) Bold Ital Sans Roman () -102009=(Booklet) Ital Sans Roman () -102010=(Centuri) Sans Roman () -102011=(Centuri) Bold Sans Roman () -102012=(Centuri) Bold Ital Sans Roman () -102013=(Centuri) Ital Sans Roman () -102014=(Paltus) Bold Sans Roman () -102015=(Paltus) Sans Roman () -102016=(Paltus) Bold Ital Sans Roman () -102017=(Paltus) Ital Sans Roman () -102018=(Sans) Sans Swiss () -102019=(Sans) Bold Sans Swiss () -102020=(Sans) Bold Ital Sans Swiss () -102021=(Sans) Ital Sans Swiss () -102022=(SansCondensed) Sans Swiss () -102023=(SansCondensed) Bold Sans Swiss () -102024=(SansCondensed) Bold Ital Sans Swiss () -102025=(SansCondensed) Ital Sans Swiss () -102026=(PS-Roman) Sans Roman () -102027=(PS-Roman) Bold Sans Roman () -102028=(PS-Roman) Bold Ital Sans Roman () -102029=(PS-Roman) Ital Sans Roman () -200111=(Chalenge) Sans () -200112=(Chalenge) Bold Sans () -200113=(Chalenge) Ital Sans () -200114=(Chalenge) Bold Ital Sans () -200121=(Office) Sans () -200122=(Office) Bold Sans () -200123=(Office) Ital Sans () -200124=(Office) Bold Ital Sans () -200131=(Milano) Sans () -200132=(Milano) Bold Sans () -200133=(Milano) Ital Sans () -200134=(Milano) Bold Ital Sans () -200141=(Atlantic) Sans Roman () -200142=(Atlantic) Bold Sans Roman () -200143=(Atlantic) Ital Sans Roman () -200144=(Atlantic) Bold Ital Sans Roman () -200151=(Pentagon) Sans () -200152=(Pentagon) Bold Sans () -200153=(Pentagon) Ital Sans () -200154=(Pentagon) Bold Ital Sans () -200161=(Classico) Sans () -200162=(Classico) Bold Sans () -200163=(Classico) Ital Sans () -200164=(Classico) Bold Ital Sans () -200211=(Westcost) Sans () -200212=(Westcost) Bold Sans () -200213=(Westcost) Ital Sans () -200214=(Westcost) Bold Ital Sans () -200221=(Finish) Sans () -200222=(Finish) Bold Sans () -200223=(Finish) Ital Sans () -200224=(Finish) Bold Ital Sans () -200231=(Classic) Sans () -200232=(Classic) Bold Sans () -200233=(Classic) Ital Sans () -200234=(Classic) Bold Ital Sans () -200241=(Hilton) Sans () -200242=(Hilton) Bold Sans () -200243=(Hilton) Ital Sans () -200244=(Hilton) Bold Ital Sans () -200251=(Progress) Sans () -200252=(Progress) Bold Sans () -200253=(Progress) Ital Sans () -200254=(Progress) Bold Ital Sans () -200261=(PrestigeElite) Sans () -200262=(PrestigeElite) Bold Sans () -200263=(PrestigeElite) Ital Sans () -200271=(Ovetti) Bold Sans () -200272=(Ovetti) Sans () -200301=(Cescendo) Sans () -200302=(Funky) Sans Decora () -200303=(Speed) Sans Decora () -200304=(Skyline) Sans Decora () -200305=(Calculator) Sans Decora () -200306=(Xpress) Sans Decora () -200307=(Console) Sans Decora () -200308=(Paisley) Sans () -200309=(Nova) Sans () -200310=(New York) Sans Decora () -200311=(Shanghai) Sans Decora () diff --git a/svtools/source/filter.vcl/filter/sgfbram.cxx b/svtools/source/filter.vcl/filter/sgfbram.cxx deleted file mode 100644 index 3d1a71f5a2db..000000000000 --- a/svtools/source/filter.vcl/filter/sgfbram.cxx +++ /dev/null @@ -1,662 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#include -#include -#include -#include -#include -#include -#include "sgffilt.hxx" -#include "sgfbram.hxx" - -/************************************************************************* -|* -|* operator>>( SvStream&, SgfHeader& ) -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -SvStream& operator>>(SvStream& rIStream, SgfHeader& rHead) -{ - rIStream.Read((char*)&rHead.Magic,SgfHeaderSize); -#if defined OSL_BIGENDIAN - rHead.Magic =SWAPSHORT(rHead.Magic ); - rHead.Version=SWAPSHORT(rHead.Version); - rHead.Typ =SWAPSHORT(rHead.Typ ); - rHead.Xsize =SWAPSHORT(rHead.Xsize ); - rHead.Ysize =SWAPSHORT(rHead.Ysize ); - rHead.Xoffs =SWAPSHORT(rHead.Xoffs ); - rHead.Yoffs =SWAPSHORT(rHead.Yoffs ); - rHead.Planes =SWAPSHORT(rHead.Planes ); - rHead.SwGrCol=SWAPSHORT(rHead.SwGrCol); - rHead.OfsLo =SWAPSHORT(rHead.OfsLo ); - rHead.OfsHi =SWAPSHORT(rHead.OfsHi ); -#endif - return rIStream; -} - - -/************************************************************************* -|* -|* SgfHeader::ChkMagic() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -BOOL SgfHeader::ChkMagic() -{ return Magic=='J'*256+'J'; } - -UINT32 SgfHeader::GetOffset() -{ return UINT32(OfsLo)+0x00010000*UINT32(OfsHi); } - - -/************************************************************************* -|* -|* operator>>( SvStream&, SgfEntry& ) -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -SvStream& operator>>(SvStream& rIStream, SgfEntry& rEntr) -{ - rIStream.Read((char*)&rEntr.Typ,SgfEntrySize); -#if defined OSL_BIGENDIAN - rEntr.Typ =SWAPSHORT(rEntr.Typ ); - rEntr.iFrei=SWAPSHORT(rEntr.iFrei); - rEntr.lFreiLo=SWAPSHORT (rEntr.lFreiLo); - rEntr.lFreiHi=SWAPSHORT (rEntr.lFreiHi); - rEntr.OfsLo=SWAPSHORT(rEntr.OfsLo); - rEntr.OfsHi=SWAPSHORT(rEntr.OfsHi); -#endif - return rIStream; -} - -UINT32 SgfEntry::GetOffset() -{ return UINT32(OfsLo)+0x00010000*UINT32(OfsHi); } - - -/************************************************************************* -|* -|* operator>>( SvStream&, SgfVector& ) -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -SvStream& operator>>(SvStream& rIStream, SgfVector& rVect) -{ - rIStream.Read((char*)&rVect,sizeof(rVect)); -#if defined OSL_BIGENDIAN - rVect.Flag =SWAPSHORT(rVect.Flag ); - rVect.x =SWAPSHORT(rVect.x ); - rVect.y =SWAPSHORT(rVect.y ); - rVect.OfsLo=SWAPLONG (rVect.OfsLo); - rVect.OfsHi=SWAPLONG (rVect.OfsHi); -#endif - return rIStream; -} - - -/************************************************************************* -|* -|* operator<<( SvStream&, BmpFileHeader& ) -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -SvStream& operator<<(SvStream& rOStream, BmpFileHeader& rHead) -{ -#if defined OSL_BIGENDIAN - rHead.Typ =SWAPSHORT(rHead.Typ ); - rHead.SizeLo =SWAPSHORT(rHead.SizeLo ); - rHead.SizeHi =SWAPSHORT(rHead.SizeHi ); - rHead.Reserve1=SWAPSHORT(rHead.Reserve1); - rHead.Reserve2=SWAPSHORT(rHead.Reserve2); - rHead.OfsLo =SWAPSHORT(rHead.OfsLo ); - rHead.OfsHi =SWAPSHORT(rHead.OfsHi ); -#endif - rOStream.Write((char*)&rHead,sizeof(rHead)); -#if defined OSL_BIGENDIAN - rHead.Typ =SWAPSHORT(rHead.Typ ); - rHead.SizeLo =SWAPSHORT(rHead.SizeLo ); - rHead.SizeHi =SWAPSHORT(rHead.SizeHi ); - rHead.Reserve1=SWAPSHORT(rHead.Reserve1); - rHead.Reserve2=SWAPSHORT(rHead.Reserve2); - rHead.OfsLo =SWAPSHORT(rHead.OfsLo ); - rHead.OfsHi =SWAPSHORT(rHead.OfsHi ); -#endif - return rOStream; -} - -void BmpFileHeader::SetSize(UINT32 Size) -{ - SizeLo=UINT16(Size & 0x0000FFFF); - SizeHi=UINT16((Size & 0xFFFF0000)>>16); -} - -void BmpFileHeader::SetOfs(UINT32 Ofs) -{ - OfsLo=UINT16(Ofs & 0x0000FFFF); - OfsHi=UINT16((Ofs & 0xFFFF0000)>>16); -} - -UINT32 BmpFileHeader::GetOfs() -{ - return UINT32(OfsLo)+0x00010000*UINT32(OfsHi); -} - -/************************************************************************* -|* -|* operator<<( SvStream&, BmpInfoHeader& ) -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -SvStream& operator<<(SvStream& rOStream, BmpInfoHeader& rInfo) -{ -#if defined OSL_BIGENDIAN - rInfo.Size =SWAPLONG (rInfo.Size ); - rInfo.Width =SWAPLONG (rInfo.Width ); - rInfo.Hight =SWAPLONG (rInfo.Hight ); - rInfo.Planes =SWAPSHORT(rInfo.Planes ); - rInfo.PixBits =SWAPSHORT(rInfo.PixBits ); - rInfo.Compress=SWAPLONG (rInfo.Compress); - rInfo.ImgSize =SWAPLONG (rInfo.ImgSize ); - rInfo.xDpmm =SWAPLONG (rInfo.xDpmm ); - rInfo.yDpmm =SWAPLONG (rInfo.yDpmm ); - rInfo.ColUsed =SWAPLONG (rInfo.ColUsed ); - rInfo.ColMust =SWAPLONG (rInfo.ColMust ); -#endif - rOStream.Write((char*)&rInfo,sizeof(rInfo)); -#if defined OSL_BIGENDIAN - rInfo.Size =SWAPLONG (rInfo.Size ); - rInfo.Width =SWAPLONG (rInfo.Width ); - rInfo.Hight =SWAPLONG (rInfo.Hight ); - rInfo.Planes =SWAPSHORT(rInfo.Planes ); - rInfo.PixBits =SWAPSHORT(rInfo.PixBits ); - rInfo.Compress=SWAPLONG (rInfo.Compress); - rInfo.ImgSize =SWAPLONG (rInfo.ImgSize ); - rInfo.xDpmm =SWAPLONG (rInfo.xDpmm ); - rInfo.yDpmm =SWAPLONG (rInfo.yDpmm ); - rInfo.ColUsed =SWAPLONG (rInfo.ColUsed ); - rInfo.ColMust =SWAPLONG (rInfo.ColMust ); -#endif - return rOStream; -} - - -/************************************************************************* -|* -|* operator<<( SvStream&, RGBQuad& ) -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -SvStream& operator<<(SvStream& rOStream, const RGBQuad& rQuad) -{ - rOStream.Write((char*)&rQuad,sizeof(rQuad)); - return rOStream; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// PcxExpand /////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -class PcxExpand -{ -private: - USHORT Count; - BYTE Data; -public: - PcxExpand() { Count=0; } - BYTE GetByte(SvStream& rInp); -}; - -BYTE PcxExpand::GetByte(SvStream& rInp) -{ - if (Count>0) { - Count--; - } else { - rInp.Read((char*)&Data,1); - if ((Data & 0xC0) == 0xC0) { - Count=(Data & 0x3F) -1; - rInp.Read((char*)&Data,1); - } - } - return Data; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// SgfBMapFilter /////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////// - - -/************************************************************************* -|* -|* SgfFilterBmp() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -BOOL SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&) -{ - BmpFileHeader aBmpHead; - BmpInfoHeader aBmpInfo; - USHORT nWdtInp=(rHead.Xsize+7)/8; // Breite der Input-Bitmap in Bytes - USHORT nWdtOut; // Breite der Output-Bitmap in Bytes - USHORT nColors; // Anzahl der Farben (1,16,256) - USHORT nColBits; // Anzahl der Bits/Pixel (2, 4, 8) - USHORT i,j,k; // Spaltenzaehler, Zeilenzaehler, Planezaehler - USHORT a,b; // Hilfsvariable - BYTE pl1 = 0,pl2= 0; // Masken fuer die Planes - BYTE* pBuf=NULL; // Buffer fuer eine Pixelzeile - PcxExpand aPcx; - ULONG nOfs; - BYTE cRGB[4]; - - if (rHead.Planes<=1) nColBits=1; else nColBits=4; if (rHead.Typ==4) nColBits=8; - nColors=1<>aHead; - if (aHead.ChkMagic() && (aHead.Typ==SgfBitImag0 || aHead.Typ==SgfBitImag1 || - aHead.Typ==SgfBitImag2 || aHead.Typ==SgfBitImgMo)) { - nNext=aHead.GetOffset(); - while (nNext && !bRdFlag && !rInp.GetError() && !rOut.GetError()) { - rInp.Seek(nFileStart+nNext); - rInp>>aEntr; - nNext=aEntr.GetOffset(); - if (aEntr.Typ==aHead.Typ) { - bRdFlag=TRUE; - switch(aEntr.Typ) { - case SgfBitImag0: - case SgfBitImag1: - case SgfBitImag2: - case SgfBitImgMo: bRet=SgfFilterBMap(rInp,rOut,aHead,aEntr); break; - } - } - } // while(nNext) - } - if (rInp.GetError()) bRet=FALSE; - return(bRet); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// SgfVectFilter /////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -// Fuer StarDraw Embedded SGF-Vector -long SgfVectXofs=0; -long SgfVectYofs=0; -long SgfVectXmul=0; -long SgfVectYmul=0; -long SgfVectXdiv=0; -long SgfVectYdiv=0; -BOOL SgfVectScal=FALSE; - -//////////////////////////////////////////////////////////// -// Hpgl2SvFarbe //////////////////////////////////////////// -//////////////////////////////////////////////////////////// - -Color Hpgl2SvFarbe( BYTE nFarb ) -{ - ULONG nColor = COL_BLACK; - - switch (nFarb & 0x07) { - case 0: nColor=COL_WHITE; break; - case 1: nColor=COL_YELLOW; break; - case 2: nColor=COL_LIGHTMAGENTA; break; - case 3: nColor=COL_LIGHTRED; break; - case 4: nColor=COL_LIGHTCYAN; break; - case 5: nColor=COL_LIGHTGREEN; break; - case 6: nColor=COL_LIGHTBLUE; break; - case 7: nColor=COL_BLACK; break; - } - Color aColor( nColor ); - return aColor; -} - -/************************************************************************* -|* -|* SgfFilterVect() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -BOOL SgfFilterVect(SvStream& rInp, SgfHeader& rHead, SgfEntry&, GDIMetaFile& rMtf) -{ - VirtualDevice aOutDev; - SgfVector aVect; - BYTE nFarb; - BYTE nFrb0=7; - BYTE nLTyp; - BYTE nOTyp; - BOOL bEoDt=FALSE; - BOOL bPDwn=FALSE; - Point aP0(0,0); - Point aP1(0,0); - String Msg; - USHORT RecNr=0; - - rMtf.Record(&aOutDev); - aOutDev.SetLineColor(Color(COL_BLACK)); - aOutDev.SetFillColor(Color(COL_BLACK)); - - while (!bEoDt && !rInp.GetError()) { - rInp>>aVect; RecNr++; - nFarb=(BYTE) (aVect.Flag & 0x000F); - nLTyp=(BYTE)((aVect.Flag & 0x00F0) >>4); - nOTyp=(BYTE)((aVect.Flag & 0x0F00) >>8); - bEoDt=(aVect.Flag & 0x4000) !=0; - bPDwn=(aVect.Flag & 0x8000) !=0; - - long x=aVect.x-rHead.Xoffs; - long y=rHead.Ysize-(aVect.y-rHead.Yoffs); - if (SgfVectScal) { - if (SgfVectXdiv==0) SgfVectXdiv=rHead.Xsize; - if (SgfVectYdiv==0) SgfVectYdiv=rHead.Ysize; - if (SgfVectXdiv==0) SgfVectXdiv=1; - if (SgfVectYdiv==0) SgfVectYdiv=1; - x=SgfVectXofs+ x *SgfVectXmul /SgfVectXdiv; - y=SgfVectYofs+ y *SgfVectXmul /SgfVectYdiv; - } - aP1=Point(x,y); - if (!bEoDt && !rInp.GetError()) { - if (bPDwn && nLTyp<=6) { - switch(nOTyp) { - case 1: if (nFarb!=nFrb0) { - switch(rHead.SwGrCol) { - case SgfVectFarb: aOutDev.SetLineColor(Hpgl2SvFarbe(nFarb)); break; - case SgfVectGray: break; - case SgfVectWdth: break; - } - } - aOutDev.DrawLine(aP0,aP1); break; // Linie - case 2: break; // Kreis - case 3: break; // Text - case 5: aOutDev.DrawRect(Rectangle(aP0,aP1)); break; // Rechteck (solid) - } - } - aP0=aP1; - nFrb0=nFarb; - } - } - rMtf.Stop(); - rMtf.WindStart(); - MapMode aMap( MAP_10TH_MM, Point(), - Fraction( 1, 4 ), Fraction( 1, 4 ) ); - rMtf.SetPrefMapMode( aMap ); - rMtf.SetPrefSize( Size( (short)rHead.Xsize, (short)rHead.Ysize ) ); - return TRUE; -} - - -/************************************************************************* -|* -|* SgfVectFilter() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -BOOL SgfVectFilter(SvStream& rInp, GDIMetaFile& rMtf) -{ - ULONG nFileStart; // Offset des SgfHeaders. Im allgemeinen 0. - SgfHeader aHead; - SgfEntry aEntr; - ULONG nNext; - BOOL bRdFlag=FALSE; // Grafikentry gelesen ? - BOOL bRet=FALSE; // Returncode - - nFileStart=rInp.Tell(); - rInp>>aHead; - if (aHead.ChkMagic() && aHead.Typ==SGF_SIMPVECT) { - nNext=aHead.GetOffset(); - while (nNext && !bRdFlag && !rInp.GetError()) { - rInp.Seek(nFileStart+nNext); - rInp>>aEntr; - nNext=aEntr.GetOffset(); - if (aEntr.Typ==aHead.Typ) { - bRet=SgfFilterVect(rInp,aHead,aEntr,rMtf); - } - } // while(nNext) - if (bRdFlag) { - if (!rInp.GetError()) bRet=TRUE; // Scheinbar Ok - } - } - return(bRet); -} - - -/************************************************************************* -|* -|* SgfFilterPScr() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -BOOL SgfFilterPScr(SvStream&, SgfHeader&, SgfEntry&) -{ - return FALSE; // PostSrcipt wird noch nicht unterstuetzt ! -} - - -/************************************************************************* -|* -|* CheckSgfTyp() -|* -|* Beschreibung Feststellen, um was fuer ein SGF/SGV es sich handelt. -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -BYTE CheckSgfTyp(SvStream& rInp, USHORT& nVersion) -{ -#if OSL_DEBUG_LEVEL > 1 // Recordgroessen checken. Neuer Compiler hat vielleichte anderes Allignment! - if (sizeof(SgfHeader)!=SgfHeaderSize || - sizeof(SgfEntry) !=SgfEntrySize || - sizeof(SgfVector)!=SgfVectorSize || - sizeof(BmpFileHeader)!=BmpFileHeaderSize || - sizeof(BmpInfoHeader)!=BmpInfoHeaderSize || - sizeof(RGBQuad )!=RGBQuadSize ) return SGF_DONTKNOW; -#endif - - ULONG nPos; - SgfHeader aHead; - nVersion=0; - nPos=rInp.Tell(); - rInp>>aHead; - rInp.Seek(nPos); - if (aHead.ChkMagic()) { - nVersion=aHead.Version; - switch(aHead.Typ) { - case SgfBitImag0: - case SgfBitImag1: - case SgfBitImag2: - case SgfBitImgMo: return SGF_BITIMAGE; - case SgfSimpVect: return SGF_SIMPVECT; - case SgfPostScrp: return SGF_POSTSCRP; - case SgfStarDraw: return SGF_STARDRAW; - default : return SGF_DONTKNOW; - } - } else { - return SGF_DONTKNOW; - } -} diff --git a/svtools/source/filter.vcl/filter/sgvmain.cxx b/svtools/source/filter.vcl/filter/sgvmain.cxx deleted file mode 100644 index 293c6dab7964..000000000000 --- a/svtools/source/filter.vcl/filter/sgvmain.cxx +++ /dev/null @@ -1,1130 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#include -#include -#include -#include -#include -#include "sgffilt.hxx" -#include "sgfbram.hxx" -#include "sgvmain.hxx" -#include "sgvspln.hxx" -#include - -//#if OSL_DEBUG_LEVEL > 1 -//#include "Debug.c" -//#endif - -#define SWAPPOINT(p) { \ - p.x=SWAPSHORT(p.x); \ - p.y=SWAPSHORT(p.y); } - -#define SWAPPAGE(p) { \ - p.Next =SWAPLONG (p.Next ); \ - p.nList =SWAPLONG (p.nList ); \ - p.ListEnd=SWAPLONG (p.ListEnd); \ - p.Paper.Size.x=SWAPSHORT(p.Paper.Size.x); \ - p.Paper.Size.y=SWAPSHORT(p.Paper.Size.y); \ - p.Paper.RandL =SWAPSHORT(p.Paper.RandL ); \ - p.Paper.RandR =SWAPSHORT(p.Paper.RandR ); \ - p.Paper.RandO =SWAPSHORT(p.Paper.RandO ); \ - p.Paper.RandU =SWAPSHORT(p.Paper.RandU ); \ - SWAPPOINT(p.U); \ - UINT16 iTemp; \ - for (iTemp=0;iTemp<20;iTemp++) { \ - rPage.HlpLnH[iTemp]=SWAPSHORT(rPage.HlpLnH[iTemp]); \ - rPage.HlpLnV[iTemp]=SWAPSHORT(rPage.HlpLnV[iTemp]); }} - -#define SWAPOBJK(o) { \ - o.Last =SWAPLONG (o.Last ); \ - o.Next =SWAPLONG (o.Next ); \ - o.MemSize =SWAPSHORT(o.MemSize ); \ - SWAPPOINT(o.ObjMin); \ - SWAPPOINT(o.ObjMax); } - -#define SWAPLINE(l) { \ - l.LMSize=SWAPSHORT(l.LMSize); \ - l.LDicke=SWAPSHORT(l.LDicke); } - -#define SWAPAREA(a) { \ - a.FDummy2=SWAPSHORT(a.FDummy2); \ - a.FMuster=SWAPSHORT(a.FMuster); } - -#define SWAPTEXT(t) { \ - SWAPLINE(t.L); \ - SWAPAREA(t.F); \ - t.FontLo =SWAPSHORT(t.FontLo ); \ - t.FontHi =SWAPSHORT(t.FontHi ); \ - t.Grad =SWAPSHORT(t.Grad ); \ - t.Breite =SWAPSHORT(t.Breite ); \ - t.Schnitt=SWAPSHORT(t.Schnitt); \ - t.LnFeed =SWAPSHORT(t.LnFeed ); \ - t.Slant =SWAPSHORT(t.Slant ); \ - SWAPLINE(t.ShdL); \ - SWAPAREA(t.ShdF); \ - SWAPPOINT(t.ShdVers); \ - SWAPAREA(t.BackF); } - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// -// Einschraenkungen: -// -// - Flaechenmuster werden den unter StarView verfuegbaren Mustern angenaehert. -// - Linienenden werden unter StarView immer rund dargestellt und gehen ueber -// den Endpunkt der Linie hinaus. -// - Linienmuster werden den unter StarView verfuegbaren Mustern angenaehert. -// Transparent/Opak wird zur Zeit noch nicht beruecksichtigt. -// - Keine gedrehten Ellipsen -// -// -// -// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Fuer Fontuebersetzung /////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////// -SgfFontLst* pSgfFonts = 0; - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Fuer Kreisunterarten, Text und gedrehte Rechtecke /////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////// -void RotatePoint(PointType& P, INT16 cx, INT16 cy, double sn, double cs) -{ - INT16 dx,dy; - double x1,y1; - dx=P.x-cx; - dy=P.y-cy; - x1=dx*cs-dy*sn; - y1=dy*cs+dx*sn; - P.x=cx+INT16(x1); - P.y=cy+INT16(y1); -} - -void RotatePoint(Point& P, INT16 cx, INT16 cy, double sn, double cs) -{ - INT16 dx,dy; - double x1,y1; - dx=(INT16)(P.X()-cx); - dy=(INT16)(P.Y()-cy); - x1=dx*cs-dy*sn; - y1=dy*cs+dx*sn; - P=Point(cx+INT16(x1),cy+INT16(y1)); -} - -INT16 iMulDiv(INT16 a, INT16 Mul, INT16 Div) -{ - INT32 Temp; - Temp=INT32(a)*INT32(Mul)/INT32(Div); - return INT16(Temp); -} - -UINT16 MulDiv(UINT16 a, UINT16 Mul, UINT16 Div) -{ - UINT32 Temp; - Temp=UINT32(a)*UINT32(Mul)/UINT32(Div); - return UINT16(Temp); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// SgfFilterSDrw /////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -SvStream& operator>>(SvStream& rIStream, DtHdType& rDtHd) -{ - rIStream.Read((char*)&rDtHd.Reserved[0],DtHdSize); - return rIStream; -} - -void DtHdOverSeek(SvStream& rInp) -{ - ULONG FPos=rInp.Tell(); - FPos+=(ULONG)DtHdSize; - rInp.Seek(FPos); -// rInp.seekg(rInp.tellg()+(ULONG)DtHdSize); -} - - -SvStream& operator>>(SvStream& rIStream, PageType& rPage) -{ - rIStream.Read((char*)&rPage.Next,PageSize); -#if defined OSL_BIGENDIAN - SWAPPAGE(rPage); -#endif - return rIStream; -} - -void ObjkOverSeek(SvStream& rInp, ObjkType& rObjk) -{ - ULONG Siz; - Siz=(ULONG)rObjk.MemSize+rObjk.Last; // ObjSize+ObjAnhSize - rInp.Seek(rInp.Tell()+Siz); -} - -SvStream& operator>>(SvStream& rInp, ObjkType& rObjk) -{ // Die Fileposition im Stream bleibt unveraendert! - ULONG nPos; - nPos=rInp.Tell(); - rInp.Read((char*)&rObjk.Last,ObjkSize); -#if defined OSL_BIGENDIAN - SWAPOBJK(rObjk); -#endif -#ifdef InArbeit - ULONG nPos1=rInp.Tell(); - if(nPos == nPos1) InfoBox( NULL, "tellg funkt nich" ).Execute(); -#endif - rInp.Seek(nPos); -#ifdef InArbeit - if (rInp.Tell() != nPos) InfoBox( NULL, "seekg funkt nich" ).Execute(); -#endif - return rInp; -} -SvStream& operator>>(SvStream& rInp, StrkType& rStrk) -{ - rInp.Read((char*)&rStrk.Last,StrkSize); -#if defined OSL_BIGENDIAN - SWAPOBJK (rStrk); - SWAPLINE (rStrk.L); - SWAPPOINT(rStrk.Pos1); - SWAPPOINT(rStrk.Pos2); -#endif - return rInp; -} -SvStream& operator>>(SvStream& rInp, RectType& rRect) -{ - rInp.Read((char*)&rRect.Last,RectSize); -#if defined OSL_BIGENDIAN - SWAPOBJK (rRect); - SWAPLINE (rRect.L); - SWAPAREA (rRect.F); - SWAPPOINT(rRect.Pos1); - SWAPPOINT(rRect.Pos2); - rRect.Radius =SWAPSHORT(rRect.Radius ); - rRect.DrehWink=SWAPSHORT(rRect.DrehWink); - rRect.Slant =SWAPSHORT(rRect.Slant ); -#endif - return rInp; -} -SvStream& operator>>(SvStream& rInp, PolyType& rPoly) -{ - rInp.Read((char*)&rPoly.Last,PolySize); -#if defined OSL_BIGENDIAN - SWAPOBJK (rPoly); - SWAPLINE (rPoly.L); - SWAPAREA (rPoly.F); - // rPoly.EckP=SWAPLONG(rPoly.EckP); -#endif - return rInp; -} -SvStream& operator>>(SvStream& rInp, SplnType& rSpln) -{ - rInp.Read((char*)&rSpln.Last,SplnSize); -#if defined OSL_BIGENDIAN - SWAPOBJK (rSpln); - SWAPLINE (rSpln.L); - SWAPAREA (rSpln.F); - // rSpln.EckP=SWAPLONG(rSpln.EckP); -#endif - return rInp; -} -SvStream& operator>>(SvStream& rInp, CircType& rCirc) -{ - rInp.Read((char*)&rCirc.Last,CircSize); -#if defined OSL_BIGENDIAN - SWAPOBJK (rCirc); - SWAPLINE (rCirc.L); - SWAPAREA (rCirc.F); - SWAPPOINT(rCirc.Radius); - SWAPPOINT(rCirc.Center); - rCirc.DrehWink =SWAPSHORT(rCirc.DrehWink ); - rCirc.StartWink=SWAPSHORT(rCirc.StartWink); - rCirc.RelWink =SWAPSHORT(rCirc.RelWink ); -#endif - return rInp; -} -SvStream& operator>>(SvStream& rInp, TextType& rText) -{ - rInp.Read((char*)&rText.Last,TextSize); -#if defined OSL_BIGENDIAN - SWAPOBJK (rText); - SWAPTEXT (rText.T); - SWAPPOINT(rText.Pos1); - SWAPPOINT(rText.Pos2); - rText.TopOfs =SWAPSHORT(rText.TopOfs ); - rText.DrehWink=SWAPSHORT(rText.DrehWink); - rText.BoxSlant=SWAPSHORT(rText.BoxSlant); - rText.BufSize =SWAPSHORT(rText.BufSize ); - //rText.Buf =SWAPLONG (rText.Buf ); - //rText.Ext =SWAPLONG (rText.Ext ); - SWAPPOINT(rText.FitSize); - rText.FitBreit=SWAPSHORT(rText.FitBreit); -#endif - rText.Buffer=NULL; - return rInp; -} -SvStream& operator>>(SvStream& rInp, BmapType& rBmap) -{ - rInp.Read((char*)&rBmap.Last,BmapSize); -#if defined OSL_BIGENDIAN - SWAPOBJK (rBmap); - SWAPAREA (rBmap.F); - SWAPPOINT(rBmap.Pos1); - SWAPPOINT(rBmap.Pos2); - rBmap.DrehWink=SWAPSHORT(rBmap.DrehWink); - rBmap.Slant =SWAPSHORT(rBmap.Slant ); - SWAPPOINT(rBmap.PixSize); -#endif - return rInp; -} -SvStream& operator>>(SvStream& rInp, GrupType& rGrup) -{ - rInp.Read((char*)&rGrup.Last,GrupSize); -#if defined OSL_BIGENDIAN - SWAPOBJK (rGrup); - rGrup.SbLo =SWAPSHORT(rGrup.SbLo ); - rGrup.SbHi =SWAPSHORT(rGrup.SbHi ); - rGrup.UpLo =SWAPSHORT(rGrup.UpLo ); - rGrup.UpHi =SWAPSHORT(rGrup.UpHi ); - rGrup.ChartSize=SWAPSHORT(rGrup.ChartSize); - rGrup.ChartPtr =SWAPLONG (rGrup.ChartPtr ); -#endif - return rInp; -} - - - -/************************************************************************* -|* -|* Sgv2SvFarbe() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -Color Sgv2SvFarbe(BYTE nFrb1, BYTE nFrb2, BYTE nInts) -{ - UINT16 r1=0,g1=0,b1=0,r2=0,g2=0,b2=0; - BYTE nInt2=100-nInts; - switch(nFrb1 & 0x07) { - case 0: r1=0xFF; g1=0xFF; b1=0xFF; break; - case 1: r1=0xFF; g1=0xFF; break; - case 2: g1=0xFF; b1=0xFF; break; - case 3: g1=0xFF; break; - case 4: r1=0xFF; b1=0xFF; break; - case 5: r1=0xFF; break; - case 6: b1=0xFF; break; - case 7: break; - } - switch(nFrb2 & 0x07) { - case 0: r2=0xFF; g2=0xFF; b2=0xFF; break; - case 1: r2=0xFF; g2=0xFF; break; - case 2: g2=0xFF; b2=0xFF; break; - case 3: g2=0xFF; break; - case 4: r2=0xFF; b2=0xFF; break; - case 5: r2=0xFF; break; - case 6: b2=0xFF; break; - case 7: break; - } - r1=(UINT16)((UINT32)r1*nInts/100+(UINT32)r2*nInt2/100); - g1=(UINT16)((UINT32)g1*nInts/100+(UINT32)g2*nInt2/100); - b1=(UINT16)((UINT32)b1*nInts/100+(UINT32)b2*nInt2/100); - Color aColor( (sal_uInt8)r1, (sal_uInt8)g1, (sal_uInt8)b1 ); - return aColor; -} - -void SetLine(ObjLineType& rLine, OutputDevice& rOut) -{ -/* !!! - PenStyle aStyle=PEN_SOLID; - switch(rLine.LMuster & 0x07) { - case 0: aStyle=PEN_NULL; break; - case 1: aStyle=PEN_SOLID; break; - case 2: aStyle=PEN_DOT; break; // . . . . . . . . . . . . . . - case 3: aStyle=PEN_DASH; break; // __ __ __ __ __ __ __ __ __ - case 4: aStyle=PEN_DASH; break; // ___ ___ ___ ___ ___ ___ ___ - case 5: aStyle=PEN_DASHDOT; break; // __ . __ . __ . __ . __ . __ - case 6: aStyle=PEN_DASHDOT; break; // __ _ __ _ __ _ __ _ __ _ __ - case 7: aStyle=PEN_DASHDOT; break; // ___ _ _ ___ _ _ ___ _ _ ___ - } - Pen aPen(Sgv2SvFarbe(rLine.LFarbe,rLine.LBFarbe,rLine.LIntens),rLine.LDicke,aStyle); - SetPen(aPen,rOut); -*/ - if( 0 == ( rLine.LMuster & 0x07 ) ) - rOut.SetLineColor(); - else - rOut.SetLineColor( Sgv2SvFarbe(rLine.LFarbe,rLine.LBFarbe,rLine.LIntens) ); -} - -void SetArea(ObjAreaType& rArea, OutputDevice& rOut) -{ -/* - BrushStyle aStyle=BRUSH_SOLID; - switch(rArea.FMuster & 0x00FF) { - case 0: aStyle=BRUSH_NULL; break; - case 1: aStyle=BRUSH_SOLID; break; - case 2: case 4: case 6: case 8: - case 10: case 12: case 14: case 16: - case 43: case 45: aStyle=BRUSH_VERT; break; - case 3: case 5: case 7: case 9: - case 11: case 13: case 15: case 17: - case 42: case 44: aStyle=BRUSH_HORZ; break; - case 18: case 20: case 22: case 24: - case 26: case 28: case 30: case 32: - case 46: case 48: aStyle=BRUSH_UPDIAG; break; - case 19: case 21: case 23: case 25: - case 27: case 29: case 31: case 33: - case 47: case 49: aStyle=BRUSH_DOWNDIAG; break; - case 34: case 35: case 36: case 37: aStyle=BRUSH_CROSS; break; - case 38: case 39: case 40: case 41: aStyle=BRUSH_DIAGCROSS; break; - default: aStyle=BRUSH_DIAGCROSS; break; - } - Brush aBrush(Sgv2SvFarbe(rArea.FFarbe,rArea.FBFarbe,rArea.FIntens),aStyle); - aBrush.SetTransparent((rArea.FMuster & 0x80) !=0L); - SetBrush(aBrush,rOut); -*/ - if( 0 == ( rArea.FMuster & 0x00FF ) ) - rOut.SetFillColor(); - else - rOut.SetFillColor( Sgv2SvFarbe( rArea.FFarbe,rArea.FBFarbe,rArea.FIntens ) ); -} - -/************************************************************************* -|* -|* ObjkType::DrawObjekt() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -void ObjkType::Draw(OutputDevice&) -{ -// ShowSDObjk(*this); -} - -void Obj0Type::Draw(OutputDevice&) {} - -/************************************************************************* -|* -|* StrkType::DrawObjekt() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -void StrkType::Draw(OutputDevice& rOut) -{ - SetLine(L,rOut); - rOut.DrawLine(Point(Pos1.x,Pos1.y),Point(Pos2.x,Pos2.y)); // !!! -} - -/************************************************************************* -|* -|* RectType::DrawObjekt() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -void SgfAreaColorIntens(UINT16 Muster, BYTE Col1, BYTE Col2, BYTE Int, OutputDevice& rOut) -{ - ObjAreaType F; - F.FMuster=Muster; - F.FFarbe=Col2; - F.FBFarbe=Col1; - F.FIntens=Int; - SetArea(F,rOut); -} - -void DrawSlideRect(INT16 x1, INT16 y1, INT16 x2, INT16 y2, ObjAreaType& F, OutputDevice& rOut) -{ - INT16 i,i0,b,b0; - INT16 Int1,Int2; - INT16 Col1,Col2; - // ClipMerk: HgdClipRec; - INT16 cx,cy; - INT16 MaxR; - INT32 dx,dy; - - rOut.SetLineColor(); - if (x1>x2) { i=x1; x1=x2; x2=i; } - if (y1>y2) { i=y1; y1=y2; y2=i; } - Col1=F.FBFarbe & 0x87; Col2=F.FFarbe & 0x87; - Int1=100-F.FIntens; Int2=F.FIntens; - if (Int1==Int2) { - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut); - rOut.DrawRect(Rectangle(x1,y1,x2,y2)); - } else { - b0=Int1; - switch (F.FBFarbe & 0x38) { - case 0x08: { // vertikal - i0=y1; - i=y1; - while (i<=y2) { - b=Int1+INT16((INT32)(Int2-Int1)*(INT32)(i-y1) /(INT32)(y2-y1+1)); - if (b!=b0) { - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut); - rOut.DrawRect(Rectangle(x1,i0,x2,i-1)); - i0=i; b0=b; - } - i++; - } - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut); - rOut.DrawRect(Rectangle(x1,i0,x2,y2)); - } break; - case 0x28: { // horizontal - i0=x1; - i=x1; - while (i<=x2) { - b=Int1+INT16((INT32)(Int2-Int1)*(INT32)(i-x1) /(INT32)(x2-x1+1)); - if (b!=b0) { - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut); - rOut.DrawRect(Rectangle(i0,y1,i-1,y2)); - i0=i; b0=b; - } - i++; - } - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut); - rOut.DrawRect(Rectangle(i0,y1,x2,y2)); - } break; - - case 0x18: case 0x38: { // Kreis - Region ClipMerk=rOut.GetClipRegion(); - double a; - - rOut.SetClipRegion(Region(Rectangle(x1,y1,x2,y2))); - cx=(x1+x2) /2; - cy=(y1+y2) /2; - dx=x2-x1+1; - dy=y2-y1+1; - a=sqrt((double)(dx*dx+dy*dy)); - MaxR=INT16(a) /2 +1; - b0=Int2; - i0=MaxR; if (MaxR<1) MaxR=1; - i=MaxR; - while (i>=0) { - b=Int1+INT16((INT32(Int2-Int1)*INT32(i)) /INT32(MaxR)); - if (b!=b0) { - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut); - //if (i0>200 || (Col1 & $80)!=0 || (Col2 & $80)!=0) { - // then begin { Fallunterscheidung fuer etwas bessere Performance } - // s2:=i0-i+2; - // SetPenSize(s2); - // s2:=s2 div 2; - // Circle(cx,cy,i0-s2,i0-s2);{} - // else - rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0)); - i0=i; b0=b; - } - i--; - } - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int1,rOut); - rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0)); - rOut.SetClipRegion(ClipMerk); - } break; // Kreis - } - } -} - - -void RectType::Draw(OutputDevice& rOut) -{ - if (L.LMuster!=0) L.LMuster=1; // keine Linienmuster hier, nur an oder aus - SetArea(F,rOut); - if (DrehWink==0) { - if ((F.FBFarbe & 0x38)==0 || Radius!=0) { - SetLine(L,rOut); - rOut.DrawRect(Rectangle(Pos1.x,Pos1.y,Pos2.x,Pos2.y),Radius,Radius); - } else { - DrawSlideRect(Pos1.x,Pos1.y,Pos2.x,Pos2.y,F,rOut); - if (L.LMuster!=0) { - SetLine(L,rOut); - rOut.SetFillColor(); - rOut.DrawRect(Rectangle(Pos1.x,Pos1.y,Pos2.x,Pos2.y)); - } - } - } else { - Point aPts[4]; - USHORT i; - double sn,cs; - sn=sin(double(DrehWink)*3.14159265359/18000); - cs=cos(double(DrehWink)*3.14159265359/18000); - aPts[0]=Point(Pos1.x,Pos1.y); - aPts[1]=Point(Pos2.x,Pos1.y); - aPts[2]=Point(Pos2.x,Pos2.y); - aPts[3]=Point(Pos1.x,Pos2.y); - for (i=0;i<4;i++) { - RotatePoint(aPts[i],Pos1.x,Pos1.y,sn,cs); - } - SetLine(L,rOut); - Polygon aPoly(4,aPts); - rOut.DrawPolygon(aPoly); - } -} - -/************************************************************************* -|* -|* PolyType::Draw() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -void PolyType::Draw(OutputDevice& rOut) -{ - if ((Flags & PolyClosBit) !=0) SetArea(F,rOut); - SetLine(L,rOut); - Polygon aPoly(nPoints); - USHORT i; - for(i=0;i0) rOut.DrawPolygon(aPoly); - } else { - Spline2Poly(aSpln,FALSE,aPoly); - if (aPoly.GetSize()>0) rOut.DrawPolyLine(aPoly); - } -} - -/************************************************************************* -|* -|* CircType::Draw() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -void DrawSlideCirc(INT16 cx, INT16 cy, INT16 rx, INT16 ry, ObjAreaType& F, OutputDevice& rOut) -{ - INT16 x1=cx-rx; - INT16 y1=cy-ry; - INT16 x2=cx+rx; - INT16 y2=cy+ry; - - INT16 i,i0,b,b0; - INT16 Int1,Int2; - INT16 Col1,Col2; - - rOut.SetLineColor(); - Col1=F.FBFarbe & 0x87; Col2=F.FFarbe & 0x87; - Int1=100-F.FIntens; Int2=F.FIntens; - if (Int1==Int2) { - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut); - rOut.DrawEllipse(Rectangle(x1,y1,x2,y2)); - } else { - b0=Int1; - switch (F.FBFarbe & 0x38) { - case 0x08: { // vertikal - Region ClipMerk=rOut.GetClipRegion(); - i0=y1; - i=y1; - while (i<=y2) { - b=Int1+INT16((INT32)(Int2-Int1)*(INT32)(i-y1) /(INT32)(y2-y1+1)); - if (b!=b0) { - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut); - rOut.SetClipRegion(Rectangle(x1,i0,x2,i-1)); - rOut.DrawEllipse(Rectangle(x1,y1,x2,y2)); - i0=i; b0=b; - } - i++; - } - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut); - rOut.SetClipRegion(Rectangle(x1,i0,x2,y2)); - rOut.DrawEllipse(Rectangle(x1,y1,x2,y2)); - rOut.SetClipRegion(ClipMerk); - } break; - case 0x28: { // horizontal - Region ClipMerk=rOut.GetClipRegion(); - i0=x1; - i=x1; - while (i<=x2) { - b=Int1+INT16((INT32)(Int2-Int1)*(INT32)(i-x1) /(INT32)(x2-x1+1)); - if (b!=b0) { - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut); - rOut.SetClipRegion(Rectangle(i0,y1,i-1,y2)); - rOut.DrawEllipse(Rectangle(x1,y1,x2,y2)); - i0=i; b0=b; - } - i++; - } - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut); - rOut.SetClipRegion(Rectangle(i0,y1,x2,y2)); - rOut.DrawEllipse(Rectangle(x1,y1,x2,y2)); - rOut.SetClipRegion(ClipMerk); - } break; - - case 0x18: case 0x38: { // Kreis - INT16 MaxR; - - if (rx<1) rx=1; - if (ry<1) ry=1; - MaxR=rx; - b0=Int2; - i0=MaxR; if (MaxR<1) MaxR=1; - i=MaxR; - while (i>=0) { - b=Int1+INT16((INT32(Int2-Int1)*INT32(i)) /INT32(MaxR)); - if (b!=b0) { - INT32 temp=INT32(i0)*INT32(ry)/INT32(rx); - INT16 j0=INT16(temp); - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut); - rOut.DrawEllipse(Rectangle(cx-i0,cy-j0,cx+i0,cy+j0)); - i0=i; b0=b; - } - i--; - } - SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int1,rOut); - rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0)); - } break; // Kreis - } - } -} - - -void CircType::Draw(OutputDevice& rOut) -{ - Rectangle aRect(Center.x-Radius.x,Center.y-Radius.y,Center.x+Radius.x,Center.y+Radius.y); - - if (L.LMuster!=0) L.LMuster=1; // keine Linienmuster hier, nur an oder aus - SetArea(F,rOut); - if ((Flags & 0x03)==CircFull) { - if ((F.FBFarbe & 0x38)==0) { - SetLine(L,rOut); - rOut.DrawEllipse(aRect); - } else { - DrawSlideCirc(Center.x,Center.y,Radius.x,Radius.y,F,rOut); - if (L.LMuster!=0) { - SetLine(L,rOut); - rOut.SetFillColor(); - rOut.DrawEllipse(aRect); - } - } - } else { - PointType a,b; - Point aStrt,aEnde; - double sn,cs; - - a.x=Center.x+Radius.x; a.y=Center.y; b=a; - sn=sin(double(StartWink)*3.14159265359/18000); - cs=cos(double(StartWink)*3.14159265359/18000); - RotatePoint(a,Center.x,Center.y,sn,cs); - sn=sin(double(StartWink+RelWink)*3.14159265359/18000); - cs=cos(double(StartWink+RelWink)*3.14159265359/18000); - RotatePoint(b,Center.x,Center.y,sn,cs); - if (Radius.x!=Radius.y) { - if (Radius.x<1) Radius.x=1; - if (Radius.y<1) Radius.y=1; - a.y = a.y - Center.y; - b.y = b.y - Center.y; - a.y=iMulDiv(a.y,Radius.y,Radius.x); - b.y=iMulDiv(b.y,Radius.y,Radius.x); - a.y = a.y + Center.y; - b.y = b.y + Center.y; - } - aStrt=Point(a.x,a.y); - aEnde=Point(b.x,b.y); - SetLine(L,rOut); - switch (Flags & 0x03) { - case CircArc : rOut.DrawArc(aRect,aEnde,aStrt); break; - case CircSect: - case CircAbsn: rOut.DrawPie(aRect,aEnde,aStrt); break; - } - } -} - -/************************************************************************* -|* -|* BmapType::Draw() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ - -void BmapType::Draw(OutputDevice& rOut) -{ - //ifstream aInp; - unsigned char nSgfTyp; - USHORT nVersion; - String aStr( - reinterpret_cast< char const * >(&Filename[ 1 ]), - (xub_StrLen)Filename[ 0 ], RTL_TEXTENCODING_UTF8 ); - INetURLObject aFNam( aStr ); - - SvStream* pInp = ::utl::UcbStreamHelper::CreateStream( aFNam.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ); - if ( pInp ) - { - nSgfTyp=CheckSgfTyp( *pInp,nVersion); - switch(nSgfTyp) { - case SGF_BITIMAGE: { - GraphicFilter aFlt; - Graphic aGrf; - USHORT nRet; - nRet=aFlt.ImportGraphic(aGrf,aFNam); - aGrf.Draw(&rOut,Point(Pos1.x,Pos1.y),Size(Pos2.x-Pos1.x,Pos2.y-Pos1.y)); - } break; - case SGF_SIMPVECT: { - GDIMetaFile aMtf; - SgfVectXofs=Pos1.x; - SgfVectYofs=Pos1.y; - SgfVectXmul=Pos2.x-Pos1.x; - SgfVectYmul=Pos2.y-Pos1.y; - SgfVectXdiv=0; - SgfVectYdiv=0; - SgfVectScal=TRUE; - SgfVectFilter(*pInp,aMtf); - SgfVectXofs=0; - SgfVectYofs=0; - SgfVectXmul=0; - SgfVectYmul=0; - SgfVectXdiv=0; - SgfVectYdiv=0; - SgfVectScal=FALSE; - aMtf.Play(&rOut); - } break; - } - delete pInp; - } -} - - -/************************************************************************* -|* -|* GrupType::... -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -UINT32 GrupType::GetSubPtr() -{ - return UINT32(SbLo)+0x00010000*UINT32(SbHi); -} - -/************************************************************************* -|* -|* DrawObjkList() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -void DrawObjkList( SvStream& rInp, OutputDevice& rOut ) -{ - ObjkType aObjk; - USHORT nGrpCnt=0; - BOOL bEnde=FALSE; - do { - rInp>>aObjk; - if (!rInp.GetError()) { - switch(aObjk.Art) { - case ObjStrk: { StrkType aStrk; rInp>>aStrk; if (!rInp.GetError()) aStrk.Draw(rOut); } break; - case ObjRect: { RectType aRect; rInp>>aRect; if (!rInp.GetError()) aRect.Draw(rOut); } break; - case ObjCirc: { CircType aCirc; rInp>>aCirc; if (!rInp.GetError()) aCirc.Draw(rOut); } break; - case ObjText: { - TextType aText; - rInp>>aText; - if (!rInp.GetError()) { - aText.Buffer=new UCHAR[aText.BufSize+1]; // Ein mehr fuer LookAhead bei CK-Trennung - rInp.Read((char* )aText.Buffer,aText.BufSize); - if (!rInp.GetError()) aText.Draw(rOut); - delete[] aText.Buffer; - } - } break; - case ObjBmap: { - BmapType aBmap; - rInp>>aBmap; - if (!rInp.GetError()) { - aBmap.Draw(rOut); - } - } break; - case ObjPoly: { - PolyType aPoly; - rInp>>aPoly; - if (!rInp.GetError()) { - aPoly.EckP=new PointType[aPoly.nPoints]; - rInp.Read((char*)aPoly.EckP,4*aPoly.nPoints); -#if defined OSL_BIGENDIAN - for(short i=0;i>aSpln; - if (!rInp.GetError()) { - aSpln.EckP=new PointType[aSpln.nPoints]; - rInp.Read((char*)aSpln.EckP,4*aSpln.nPoints); -#if defined OSL_BIGENDIAN - for(short i=0;i>aGrup; - if (!rInp.GetError()) { - rInp.Seek(rInp.Tell()+aGrup.Last); // Obj-Anhaengsel - if(aGrup.GetSubPtr()!=0L) nGrpCnt++;// DrawObjkList(rInp,rOut ); - } - } break; - default: { - aObjk.Draw(rOut); // Objektbezeichnung auf 2. Screen - ObjkOverSeek(rInp,aObjk); // zum naechsten Objekt - } - } - } // if rInp - if (!rInp.GetError()) { - if (aObjk.Next==0L) { - if (nGrpCnt==0) bEnde=TRUE; - else nGrpCnt--; - } - } else { - bEnde=TRUE; // Lesefehler - } - } while (!bEnde); -} - -/************************************************************************* -|* -|* SkipObjkList() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -void SkipObjkList(SvStream& rInp) -{ - ObjkType aObjk; - do - { - rInp>>aObjk; - if(aObjk.Art==ObjGrup) { - GrupType aGrup; - rInp>>aGrup; - rInp.Seek(rInp.Tell()+aGrup.Last); // Obj-Anhaengsel - if(aGrup.GetSubPtr()!=0L) SkipObjkList(rInp); - } else { - ObjkOverSeek(rInp,aObjk); // zum naechsten Objekt - } - } while (aObjk.Next!=0L && !rInp.GetError()); -} - -/************************************************************************* -|* -|* SgfFilterSDrw() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -BOOL SgfFilterSDrw( SvStream& rInp, SgfHeader&, SgfEntry&, GDIMetaFile& rMtf ) -{ - BOOL bRet = FALSE; - PageType aPage; - VirtualDevice aOutDev; - OutputDevice* pOutDev; - ULONG nStdPos; - ULONG nZchPos; - USHORT Num; - - pOutDev=&aOutDev; - DtHdOverSeek(rInp); // DataHeader weglesen - - nStdPos=rInp.Tell(); - do { // Standardseiten weglesen - rInp>>aPage; - if (aPage.nList!=0) SkipObjkList(rInp); - } while (aPage.Next!=0L && !rInp.GetError()); - -// ShowMsg("Zeichnungseite(n)\n"); - nZchPos=rInp.Tell(); - rInp>>aPage; - - rMtf.Record(pOutDev); - Num=aPage.StdPg; - if (Num!=0) { - rInp.Seek(nStdPos); - while(Num>1 && aPage.Next!=0L && !rInp.GetError()) { // Standardseite suchen - rInp>>aPage; - if (aPage.nList!=0) SkipObjkList(rInp); - Num--; - } - rInp>>aPage; - if(Num==1 && aPage.nList!=0L) DrawObjkList( rInp,*pOutDev ); - rInp.Seek(nZchPos); - nZchPos=rInp.Tell(); - rInp>>aPage; - } - if (aPage.nList!=0L) DrawObjkList(rInp,*pOutDev ); - - rMtf.Stop(); - rMtf.WindStart(); - MapMode aMap(MAP_10TH_MM,Point(),Fraction(1,4),Fraction(1,4)); - rMtf.SetPrefMapMode(aMap); - rMtf.SetPrefSize(Size((INT16)aPage.Paper.Size.x,(INT16)aPage.Paper.Size.y)); - bRet=TRUE; - return bRet; -} - - - -/************************************************************************* -|* -|* SgfSDrwFilter() -|* -|* Beschreibung -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -BOOL SgfSDrwFilter(SvStream& rInp, GDIMetaFile& rMtf, INetURLObject aIniPath ) -{ -#if OSL_DEBUG_LEVEL > 1 // Recordgroessen checken. Neuer Compiler hat vielleichte anderes Alignment! - if (sizeof(ObjTextType)!=ObjTextTypeSize) return FALSE; -#endif - - ULONG nFileStart; // Offset des SgfHeaders. Im allgemeinen 0. - SgfHeader aHead; - SgfEntry aEntr; - ULONG nNext; - BOOL bRdFlag=FALSE; // Grafikentry gelesen ? - BOOL bRet=FALSE; // Returncode - - aIniPath.Append( String::CreateFromAscii( "sgf.ini", 7 ) ); -// aIniPath.ToAbs(); - - pSgfFonts = new SgfFontLst; - - pSgfFonts->AssignFN( aIniPath.GetMainURL( INetURLObject::NO_DECODE ) ); - nFileStart=rInp.Tell(); - rInp>>aHead; - if (aHead.ChkMagic() && aHead.Typ==SgfStarDraw && aHead.Version==SGV_VERSION) { - nNext=aHead.GetOffset(); - while (nNext && !bRdFlag && !rInp.GetError()) { - rInp.Seek(nFileStart+nNext); - rInp>>aEntr; - nNext=aEntr.GetOffset(); - if (aEntr.Typ==aHead.Typ) { - bRet=SgfFilterSDrw( rInp,aHead,aEntr,rMtf ); - } - } // while(nNext) - if (bRdFlag) { - if (!rInp.GetError()) bRet=TRUE; // Scheinbar Ok - } - } - delete pSgfFonts; - return(bRet); -} - -/* -Bitmap Dither(BYTE Intens) -{ - Bitmap aBmp; - BmpInfoHeader Info; - - -const dmatrix: array[0..7,0..7] of byte = - (( 0, 48, 12, 60, 3, 51, 15, 63 ), - ( 32, 16, 44, 28, 35, 19, 47, 31 ), - ( 8, 56, 4, 52, 11, 59, 7, 55 ), - ( 40, 24, 36, 20, 43, 27, 39, 23 ), - ( 2, 50, 14, 62, 1, 49, 13, 61 ), - ( 34, 18, 46, 30, 33, 17, 45, 29 ), - ( 10, 58, 6, 54, 9, 57, 5, 53 ), - ( 42, 26, 38, 22, 41, 25, 37, 21 )); - - - cmatrix: array[0..7,0..7] of byte; - dmatrixn,dmatrixi: array[0..7] of byte; - - -procedure SetColorIntens(col0,col1,bal: integer); -var cmatrix0: array[0..63] of byte absolute cmatrix; - dmatrix0: array[0..63] of byte absolute dmatrix; - n,i: integer; - b,bit: byte; -begin -if col0=col1 then bal:=0; -if bal<=32 then - begin - plotcolor0:=col0 and $1F; plotcolor1:=col1 and $1F; - plotbal:=bal; - end -else - begin - plotcolor0:=col1 and $1F; plotcolor1:=col0 and $1F; - plotbal:=64-bal; - end; -for n:=0 to 63 do - if plotbal<=dmatrix0[n] then cmatrix0[n]:=col0 else cmatrix0[n]:=col1; -end; -*/ - diff --git a/svtools/source/filter.vcl/filter/sgvspln.cxx b/svtools/source/filter.vcl/filter/sgvspln.cxx deleted file mode 100644 index d695e171a194..000000000000 --- a/svtools/source/filter.vcl/filter/sgvspln.cxx +++ /dev/null @@ -1,890 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#include - - -#include - -#if defined( PM2 ) && defined( __BORLANDC__ ) -#pragma option -Od -#endif - -extern "C" { - -/*.pn 277 */ -/*.hlAnhang: C - Programme*/ -/*.hrKonstanten- und Macro-Definitionen*/ -/*.fe Die Include-Datei u_const.h ist in das Verzeichnis zu stellen, */ -/*.fe wo der Compiler nach Include-Dateien sucht. */ - - -/*----------------------- FILE u_const.h ---------------------------*/ - -#define IEEE - -/* IEEE - Norm fuer die Darstellung von Gleitkommazahlen: - - 8 Byte lange Gleitkommazahlen, mit - - 53 Bit Mantisse ==> Mantissenbereich: 2 hoch 52 versch. Zahlen - mit 0.1 <= Zahl < 1.0, - 1 Vorzeichen-Bit - 11 Bit Exponent ==> Exponentenbereich: -1024...+1023 - - Die 1. Zeile ( #define IEEE ) ist zu loeschen, falls die Maschine - bzw. der Compiler keine Gleitpunktzahlen gemaess der IEEE-Norm - benutzt. Zusaetzlich muessen die Zahlen MAXEXPON, MINEXPON - (s.u.) angepasst werden. - */ - -#ifdef IEEE /*----------- Falls IEEE Norm --------------------*/ - -#define MACH_EPS 2.220446049250313e-016 /* Maschinengenauigkeit */ - /* IBM-AT: = 2 hoch -52 */ -/* MACH_EPS ist die kleinste positive, auf der Maschine darstellbare - Zahl x, die der Bedingung genuegt: 1.0 + x > 1.0 */ - -#define EPSQUAD 4.930380657631324e-032 -#define EPSROOT 1.490116119384766e-008 - -#define POSMAX 8.98846567431158e+307 /* groesste positive Zahl */ -#define POSMIN 5.56268464626800e-309 /* kleinste positive Zahl */ -#define MAXROOT 9.48075190810918e+153 - -#define BASIS 2 /* Basis der Zahlendarst. */ -#ifndef PI -#define PI 3.141592653589793e+000 -#endif -#define EXP_1 2.718281828459045e+000 - -#else /*------------------ sonst -----------------------*/ - -double exp (double); -double atan (double); -double pow (double,double); -double sqrt (double); - -double masch() /* MACH_EPS maschinenunabhaengig bestimmen */ -{ - double eps = 1.0, x = 2.0, y = 1.0; - while ( y < x ) - { eps *= 0.5; - x = 1.0 + eps; - } - eps *= 2.0; return (eps); -} - -short basis() /* BASIS maschinenunabhaengig bestimmen */ -{ - double x = 1.0, one = 1.0, b = 1.0; - - while ( (x + one) - x == one ) x *= 2.0; - while ( (x + b) == x ) b *= 2.0; - - return ( (short) ((x + b) - x) ); -} - -#define BASIS basis() /* Basis der Zahlendarst. */ - -/* Falls die Maschine (der Compiler) keine IEEE-Darstellung fuer - Gleitkommazahlen nutzt, muessen die folgenden 2 Konstanten an- - gepasst werden. - */ - -#define MAXEXPON 1023.0 /* groesster Exponent */ -#define MINEXPON -1024.0 /* kleinster Exponent */ - - -#define MACH_EPS masch() -#define EPSQUAD MACH_EPS * MACH_EPS -#define EPSROOT sqrt(MACH_EPS) - -#define POSMAX pow ((double) BASIS, MAXEXPON) -#define POSMIN pow ((double) BASIS, MINEXPON) -#define MAXROOT sqrt(POSMAX) - -#define PI 4.0 * atan (1.0) -#define EXP_1 exp(1.0) - -#endif /*-------------- ENDE ifdef ----------------------*/ - - -#define NEGMAX -POSMIN /* groesste negative Zahl */ -#define NEGMIN -POSMAX /* kleinste negative Zahl */ - -#define TRUE 1 -#define FALSE 0 - - -/* Definition von Funktionsmakros: - */ - -#define abs(X) ((X) >= 0 ? (X) : -(X)) /* Absolutbetrag von X */ -#define sign(X, Y) (Y < 0 ? -abs(X) : abs(X)) /* Vorzeichen von */ - /* Y mal abs(X) */ -#define sqr(X) ((X) * (X)) /* Quadrat von X */ - -/*------------------- ENDE FILE u_const.h --------------------------*/ - - - - - - - - - -/*.HL Anhang: C - Programme*/ -/*.HRGleichungssysteme fuer Tridiagonalmatrizen*/ - -/*.FE P 3.7 TRIDIAGONALE GLEICHUNGSSYSTEME*/ - - -/*---------------------- MODUL TRIDIAGONAL ------------------------*/ - -USHORT TriDiagGS(BOOL rep, USHORT n, double* lower, - double* diag, double* upper, double* b) - /************************/ - /* GAUSS-Verfahren fuer */ - /* Tridiagonalmatrizen */ - /************************/ - -/*====================================================================*/ -/* */ -/* trdiag bestimmt die Loesung x des linearen Gleichungssystems */ -/* A * x = b mit tridiagonaler n x n Koeffizientenmatrix A, die in */ -/* den 3 Vektoren lower, upper und diag wie folgt abgespeichert ist: */ -/* */ -/* ( diag[0] upper[0] 0 0 . . . 0 ) */ -/* ( lower[1] diag[1] upper[1] 0 . . . ) */ -/* ( 0 lower[2] diag[2] upper[2] 0 . ) */ -/* A = ( . 0 lower[3] . . . ) */ -/* ( . . . . . 0 ) */ -/* ( . . . . . ) */ -/* ( . . . upper[n-2] ) */ -/* ( 0 . . . 0 lower[n-1] diag[n-1] ) */ -/* */ -/*====================================================================*/ -/* */ -/* Anwendung: */ -/* ========= */ -/* Vorwiegend fuer diagonaldominante Tridiagonalmatrizen, wie */ -/* sie bei der Spline-Interpolation auftreten. */ -/* Fuer diagonaldominante Matrizen existiert immer eine LU- */ -/* Zerlegung; fuer nicht diagonaldominante Tridiagonalmatrizen */ -/* sollte die Funktion band vorgezogen werden, da diese mit */ -/* Spaltenpivotsuche arbeitet und daher numerisch stabiler ist. */ -/* */ -/*====================================================================*/ -/* */ -/* Eingabeparameter: */ -/* ================ */ -/* n Dimension der Matrix ( > 1 ) USHORT n */ -/* */ -/* lower untere Nebendiagonale double lower[n] */ -/* diag Hauptdiagonale double diag[n] */ -/* upper obere Nebendiagonale double upper[n] */ -/* */ -/* bei rep != 0 enthalten lower, diag und upper die */ -/* Dreieckzerlegung der Ausgangsmatrix. */ -/* */ -/* b rechte Seite des Systems double b[n] */ -/* rep = 0 erstmaliger Aufruf BOOL rep */ -/* !=0 wiederholter Aufruf */ -/* fuer gleiche Matrix, */ -/* aber verschiedenes b. */ -/* */ -/* Ausgabeparameter: */ -/* ================ */ -/* b Loesungsvektor des Systems; double b[n] */ -/* die urspruengliche rechte Seite wird ueberspeichert */ -/* */ -/* lower ) enthalten bei rep = 0 die Zerlegung der Matrix; */ -/* diag ) die urspruenglichen Werte von lower u. diag werden */ -/* upper ) ueberschrieben */ -/* */ -/* Die Determinante der Matrix ist bei rep = 0 durch */ -/* det A = diag[0] * ... * diag[n-1] bestimmt. */ -/* */ -/* Rueckgabewert: */ -/* ============= */ -/* = 0 alles ok */ -/* = 1 n < 2 gewaehlt */ -/* = 2 Die Dreieckzerlegung der Matrix existiert nicht */ -/* */ -/*====================================================================*/ -/* */ -/* Benutzte Funktionen: */ -/* =================== */ -/* */ -/* Aus der C Bibliothek: fabs() */ -/* */ -/*====================================================================*/ - -/*.cp 5 */ -{ - USHORT i; - short j; - -// double fabs(double); - - if ( n < 2 ) return(1); /* n mindestens 2 */ - - /* Wenn rep = 0 ist, */ - /* Dreieckzerlegung der */ - if (rep == 0) /* Matrix u. det be- */ - { /* stimmen */ - for (i = 1; i < n; i++) - { if ( fabs(diag[i-1]) < MACH_EPS ) /* Wenn ein diag[i] = 0 */ - return(2); /* ist, ex. keine Zerle- */ - lower[i] /= diag[i-1]; /* gung. */ - diag[i] -= lower[i] * upper[i-1]; - } - } - - if ( fabs(diag[n-1]) < MACH_EPS ) return(2); - - for (i = 1; i < n; i++) /* Vorwaertselimination */ - b[i] -= lower[i] * b[i-1]; - - b[n-1] /= diag[n-1]; /* Rueckwaertselimination */ - for (j = n-2; j >= 0; j--) { - i=j; - b[i] = ( b[i] - upper[i] * b[i+1] ) / diag[i]; - } - return(0); -} - -/*----------------------- ENDE TRIDIAGONAL -------------------------*/ - - - - - - - - - -/*.HL Anhang: C - Programme*/ -/*.HRGleichungssysteme mit zyklisch tridiagonalen Matrizen*/ - -/*.FE P 3.8 SYSTEME MIT ZYKLISCHEN TRIDIAGONALMATRIZEN */ - - -/*---------------- MODUL ZYKLISCH TRIDIAGONAL ----------------------*/ - - -USHORT ZyklTriDiagGS(BOOL rep, USHORT n, double* lower, double* diag, - double* upper, double* lowrow, double* ricol, double* b) - /******************************/ - /* Systeme mit zyklisch tri- */ - /* diagonalen Matrizen */ - /******************************/ - -/*====================================================================*/ -/* */ -/* tzdiag bestimmt die Loesung x des linearen Gleichungssystems */ -/* A * x = b mit zyklisch tridiagonaler n x n Koeffizienten- */ -/* matrix A, die in den 5 Vektoren lower, upper, diag, lowrow und */ -/* ricol wie folgt abgespeichert ist: */ -/* */ -/* ( diag[0] upper[0] 0 0 . . 0 ricol[0] ) */ -/* ( lower[1] diag[1] upper[1] 0 . . 0 ) */ -/* ( 0 lower[2] diag[2] upper[2] 0 . ) */ -/* A = ( . 0 lower[3] . . . . ) */ -/* ( . . . . . 0 ) */ -/* ( . . . . . ) */ -/* ( 0 . . . upper[n-2] ) */ -/* ( lowrow[0] 0 . . 0 lower[n-1] diag[n-1] ) */ -/* */ -/* Speicherplatz fuer lowrow[1],..,lowrow[n-3] und ricol[1],..., */ -/* ricol[n-3] muss zusaetzlich bereitgestellt werden, da dieser */ -/* fuer die Aufnahme der Zerlegungsmatrix verfuegbar sein muss, die */ -/* auf die 5 genannten Vektoren ueberspeichert wird. */ -/* */ -/*====================================================================*/ -/* */ -/* Anwendung: */ -/* ========= */ -/* Vorwiegend fuer diagonaldominante zyklische Tridiagonalmatri- */ -/* zen wie sie bei der Spline-Interpolation auftreten. */ -/* Fuer diagonaldominante Matrizen existiert immer eine LU- */ -/* Zerlegung. */ -/* */ -/*====================================================================*/ -/* */ -/* Eingabeparameter: */ -/* ================ */ -/* n Dimension der Matrix ( > 2 ) USHORT n */ -/* lower untere Nebendiagonale double lower[n] */ -/* diag Hauptdiagonale double diag[n] */ -/* upper obere Nebendiagonale double upper[n] */ -/* b rechte Seite des Systems double b[n] */ -/* rep = 0 erstmaliger Aufruf BOOL rep */ -/* !=0 wiederholter Aufruf */ -/* fuer gleiche Matrix, */ -/* aber verschiedenes b. */ -/* */ -/* Ausgabeparameter: */ -/* ================ */ -/* b Loesungsvektor des Systems, double b[n] */ -/* die urspruengliche rechte Seite wird ueberspeichert */ -/* */ -/* lower ) enthalten bei rep = 0 die Zerlegung der Matrix; */ -/* diag ) die urspruenglichen Werte von lower u. diag werden */ -/* upper ) ueberschrieben */ -/* lowrow ) double lowrow[n-2] */ -/* ricol ) double ricol[n-2] */ -/* */ -/* Die Determinante der Matrix ist bei rep = 0 durch */ -/* det A = diag[0] * ... * diag[n-1] bestimmt. */ -/* */ -/* Rueckgabewert: */ -/* ============= */ -/* = 0 alles ok */ -/* = 1 n < 3 gewaehlt */ -/* = 2 Die Zerlegungsmatrix existiert nicht */ -/* */ -/*====================================================================*/ -/* */ -/* Benutzte Funktionen: */ -/* =================== */ -/* */ -/* Aus der C Bibliothek: fabs() */ -/* */ -/*====================================================================*/ - -/*.cp 5 */ -{ - double temp; // fabs(double); - USHORT i; - short j; - - if ( n < 3 ) return(1); - - if (rep == 0) /* Wenn rep = 0 ist, */ - { /* Zerlegung der */ - lower[0] = upper[n-1] = 0.0; /* Matrix berechnen. */ - - if ( fabs (diag[0]) < MACH_EPS ) return(2); - /* Ist ein Diagonalelement */ - temp = 1.0 / diag[0]; /* betragsmaessig kleiner */ - upper[0] *= temp; /* MACH_EPS, so ex. keine */ - ricol[0] *= temp; /* Zerlegung. */ - - for (i = 1; i < n-2; i++) - { diag[i] -= lower[i] * upper[i-1]; - if ( fabs(diag[i]) < MACH_EPS ) return(2); - temp = 1.0 / diag[i]; - upper[i] *= temp; - ricol[i] = -lower[i] * ricol[i-1] * temp; - } - - diag[n-2] -= lower[n-2] * upper[n-3]; - if ( fabs(diag[n-2]) < MACH_EPS ) return(2); - - for (i = 1; i < n-2; i++) - lowrow[i] = -lowrow[i-1] * upper[i-1]; - - lower[n-1] -= lowrow[n-3] * upper[n-3]; - upper[n-2] = ( upper[n-2] - lower[n-2] * ricol[n-3] ) / diag[n-2]; - - for (temp = 0.0, i = 0; i < n-2; i++) - temp -= lowrow[i] * ricol[i]; - diag[n-1] += temp - lower[n-1] * upper[n-2]; - - if ( fabs(diag[n-1]) < MACH_EPS ) return(2); - } /* end if ( rep == 0 ) */ - - b[0] /= diag[0]; /* Vorwaertselemination */ - for (i = 1; i < n-1; i++) - b[i] = ( b[i] - b[i-1] * lower[i] ) / diag[i]; - - for (temp = 0.0, i = 0; i < n-2; i++) - temp -= lowrow[i] * b[i]; - - b[n-1] = ( b[n-1] + temp - lower[n-1] * b[n-2] ) / diag[n-1]; - - b[n-2] -= b[n-1] * upper[n-2]; /* Rueckwaertselimination */ - for (j = n-3; j >= 0; j--) { - i=j; - b[i] -= upper[i] * b[i+1] + ricol[i] * b[n-1]; - } - return(0); -} - -/*------------------ ENDE ZYKLISCH TRIDIAGONAL ---------------------*/ - - -} // extern "C" - - -/************************************************************************* -|* -|* NaturalSpline() -|* -|* Beschreibung Berechnet die Koeffizienten eines natuerlichen -|* kubischen Polynomsplines mit n Stuetzstellen. -|* Ersterstellung JOE 17-08.93 -|* Letzte Aenderung JOE 17-08.93 -|* -*************************************************************************/ - -USHORT NaturalSpline(USHORT n, double* x, double* y, - double Marg0, double MargN, - BYTE MargCond, - double* b, double* c, double* d) -{ - USHORT i; - double* a; - double* h; - USHORT error; - - if (n<2) return 1; - if ( (MargCond & ~3) ) return 2; - a=new double[n+1]; - h=new double[n+1]; - for (i=0;i=MAXROOT) { - alphX=0.0; - alphY=sign(1.0,y[1]-y[0]); - } else { - alphX=sign(sqrt(1.0/(1.0+Marg01*Marg01)),x[1]-x[0]); - alphY=alphX*Marg01; - } - if (abs(MargN1)>=MAXROOT) { - betX=0.0; - betY=sign(1.0,y[n]-y[n-1]); - } else { - betX=sign(sqrt(1.0/(1.0+MargN1*MargN1)),x[n]-x[n-1]); - betY=betX*MargN1; - } - } - } // switch MargCond - if (MargCond==3) { - Error=PeriodicSpline(n,T,x,bx,cx,dx); - if (Error!=0) return(Error+4); - Error=PeriodicSpline(n,T,y,by,cy,dy); - if (Error!=0) return(Error+10); - } else { - Error=NaturalSpline(n,T,x,alphX,betX,MargCond,bx,cx,dx); - if (Error!=0) return(Error+4); - Error=NaturalSpline(n,T,y,alphY,betY,MargCond,by,cy,dy); - if (Error!=0) return(Error+9); - } - return 0; -} - - - -/************************************************************************* -|* -|* CalcSpline() -|* -|* Beschreibung Berechnet die Koeffizienten eines parametrischen -|* natuerlichen oder periodischen kubischen -|* Polynomsplines. Die Eckpunkte des uebergebenen -|* Polygons werden als Stuetzstellen angenommen. -|* n liefert die Anzahl der Teilpolynome. -|* Ist die Berechnung fehlerfrei verlaufen, so -|* liefert die Funktion TRUE. Nur in diesem Fall -|* ist Speicher fuer die Koeffizientenarrays -|* allokiert, der dann spaeter vom Aufrufer mittels -|* delete freizugeben ist. -|* Ersterstellung JOE 17-08.93 -|* Letzte Aenderung JOE 17-08.93 -|* -*************************************************************************/ - -BOOL CalcSpline(Polygon& rPoly, BOOL Periodic, USHORT& n, - double*& ax, double*& ay, double*& bx, double*& by, - double*& cx, double*& cy, double*& dx, double*& dy, double*& T) -{ - BYTE Marg; - double Marg01,Marg02; - double MargN1,MargN2; - USHORT i; - Point P0(-32768,-32768); - Point Pt; - - n=rPoly.GetSize(); - ax=new double[rPoly.GetSize()+2]; - ay=new double[rPoly.GetSize()+2]; - - n=0; - for (i=0;i0) n--; // n Korregieren (Anzahl der Teilpolynome) - - BOOL bRet = FALSE; - if ( ( Marg == 3 && n >= 3 ) || ( Marg == 2 && n >= 2 ) ) - { - bRet = ParaSpline(n,ax,ay,Marg,Marg01,Marg01,MargN1,MargN2,FALSE,T,bx,cx,dx,by,cy,dy) == 0; - } - if ( bRet == FALSE ) - { - delete[] ax; - delete[] ay; - delete[] bx; - delete[] by; - delete[] cx; - delete[] cy; - delete[] dx; - delete[] dy; - delete[] T; - n=0; - } - return bRet; -} - - -/************************************************************************* -|* -|* Spline2Poly() -|* -|* Beschreibung Konvertiert einen parametrichen kubischen -|* Polynomspline Spline (natuerlich oder periodisch) -|* in ein angenaehertes Polygon. -|* Die Funktion liefert FALSE, wenn ein Fehler bei -|* der Koeffizientenberechnung aufgetreten ist oder -|* das Polygon zu gross wird (>PolyMax=16380). Im 1. -|* Fall hat das Polygon 0, im 2. Fall PolyMax Punkte. -|* Um Koordinatenueberlaeufe zu vermeiden werden diese -|* auf +/-32000 begrenzt. -|* Ersterstellung JOE 23.06.93 -|* Letzte Aenderung JOE 23.06.93 -|* -*************************************************************************/ -BOOL Spline2Poly(Polygon& rSpln, BOOL Periodic, Polygon& rPoly) -{ - short MinKoord=-32000; // zur Vermeidung - short MaxKoord=32000; // von Ueberlaeufen - - double* ax; // Koeffizienten der Polynome - double* ay; - double* bx; - double* by; - double* cx; - double* cy; - double* dx; - double* dy; - double* tv; - - double Step; // Schrittweite fuer t - double dt1,dt2,dt3; // Delta t, y, ^3 - double t; - BOOL bEnde; // Teilpolynom zu Ende? - USHORT n; // Anzahl der zu zeichnenden Teilpolynome - USHORT i; // aktuelles Teilpolynom - BOOL bOk; // noch alles ok? - USHORT PolyMax=16380;// Maximale Anzahl von Polygonpunkten - long x,y; - - bOk=CalcSpline(rSpln,Periodic,n,ax,ay,bx,by,cx,cy,dx,dy,tv); - if (bOk) { - Step =10; - - rPoly.SetSize(1); - rPoly.SetPoint(Point(short(ax[0]),short(ay[0])),0); // erster Punkt - i=0; - while (i=tv[i+1]; - if (bEnde) t=tv[i+1]; - dt1=t-tv[i]; dt2=dt1*dt1; dt3=dt2*dt1; - x=long(ax[i]+bx[i]*dt1+cx[i]*dt2+dx[i]*dt3); - y=long(ay[i]+by[i]*dt1+cy[i]*dt2+dy[i]*dt3); - if (xMaxKoord) x=MaxKoord; - if (yMaxKoord) y=MaxKoord; - if (rPoly.GetSize() - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#include -#include -#include -#include "sgffilt.hxx" -#include "sgfbram.hxx" -#include "sgvmain.hxx" -// #include "Debug.c" - -extern SgfFontLst* pSgfFonts; - -#ifndef abs -#define abs(x) ((x)<0 ? -(x) : (x)) -#endif - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// -// Einschraenkungen: Schatten nur grau, 2D und mit fixem Abstand. -// -// -// -// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -// AbsBase.Pas - -// die folgenden Werte sind in % vom maximalen Schriftgrad der Zeile */ -#define UndlSpace 5 /* Untersteichungsabstand von der Baseline */ -#define UndlWidth 6 /* Untersteichungsdicke */ -#define UndlSpac2 7 /* Zwischenraum bei doppelter Unterstreichung */ -#define StrkSpace 25 /* Abstand der Durchstreichlinie von der Baseline*/ -#define StrkWidth 5 /* Durchstreichungsliniendicke */ -#define StrkSpac2 7 /* Zwischenraum bei doppelter Durchstreichung */ -#define OutlWidth 2 /* Strichstaerke ist 2% vom Schriftgrad */ - -// vvv Sonderzeichen im TextBuffer vvv -#define TextEnd 0 /* ^@ Ende der Zeichenkette */ -#define HardSpace 6 /* ^F Hartspace (wird nicht umbrochen) ,' ' */ -#define GrafText 7 /* ^G Im Text eingebundene Grafik (future) */ -#define Tabulator 9 /* ^I Tabulatorzeichen, Pfeil */ -#define LineFeed 10 /* ^J Neue Zeile */ -#define SoftTrennK 11 /* ^K Zeichen fuer k-c-Austausch bei Trennung, 'k' */ -#define AbsatzEnd 13 /* ^M Neuer Absatz =CR */ -#define HardTrenn 16 /* ^P Hartes Trennzeichen (wird nicht umbrochen), '-' */ -#define SoftTrennAdd 19 /* ^S Zusatz-Zeichen Trennung von z.b."Schiff-fahrt" */ -#define Paragraf 21 /* ^U Zeichen welches fuer Paragraf-Zeichen */ -#define Escape 27 /* ^[ Escapesequenz einleiten */ -#define SoftTrenn 31 /* ^_ Weiches Trennzeichen, '-' nur Zeilenende */ -#define MaxEscValLen 8 -#define MaxEscLen (MaxEscValLen+3) - -//============================================================================== -// Escapesequenzen: [Esc][Esc] also mind. 4 Char -// Max. Laenge von Value soll sein: 8 Char (7+Vorzeichen). Demnach max. Laenge -// einer Escapesequenz: 11 Char. -// Identifer: - -#define EscFont 'F' /* FontID, z.B. 92500 fuer CG Times */ -#define EscGrad 'G' /* Schriftgrad 1..255 fuer <0)) || - ((F.FBFarbe!=L.LBFarbe) && (F.FIntens<100)); -} - - -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -// Misc.Pas - -short hPoint2Sgf(short a) -{ - long b; - b=long(a)*127*SgfDpmm/(144*5); - return short(b); -} - -short Sgf2hPoint(short a) -{ - long b; - b=long(a)*5*144/(127*SgfDpmm); - return short(b); -} - -// End of Misc.Pas -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// - - - -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -// AbsRead.Pas - -// ====================================================================== -// Function GetTopToBaseLine() Function GetBaseLineToBtm() -// -// Abstand von Zeilenoberkante bis BaseLine bzw. von BaseLine bis -// Unterkante berechnen. Alles in SGF-Units. -// ====================================================================== - -USHORT GetTopToBaseLine(USHORT MaxGrad) -{ - long ret; - ret=long(MaxGrad)*long(CharTopToBase) /long(100); - return USHORT(ret); -} - -// ====================================================================== -// Function GetTextChar() Function GetTextCharConv() -// -// Liest ein Zeichen aus dem Textbuffer, wertet dabei eventuell -// auftretende Escapesequenzen aus und setzt dementsprechend den -// Ein-/Ausgabeparameter AktAtr. Index wird entsprechend erhoeht. -// Der Parameter Rest muss immer die Anzahl der Zeichen beinhalten, -// den angeforderten Zeichen in der aktuellen Zeile noch folgen. -// Ansonsten funktioniert die Silbentrennung nicht richtig. Gibt man -// stattdessen die Konstante NoTrenn an, wird in keinem Fall -// getrennt, die Konstante DoTrenn bewirkt dagegen, dass ueberall dort -// getrennt wird, wo ein SoftTrenner vorkommt. -// -// SoftTrenner werden immer in ein Minuszeichen konvertiert. -// GetTextCharConv() konvertiert zusaetzlich HardSpace und AbsatzEnde -// in Spaces sowie HardTrenner in Minuszeichen. TextEnde wird immer -// als Char(0) geliefert. -// ====================================================================== - - - -UCHAR ConvertTextChar(UCHAR c) -{ - if (c<32) { - switch (c) { - case HardSpace : c=' '; break; - case AbsatzEnd : c=' '; break; - case SoftTrenn : c='-'; break; - case HardTrenn : c='-'; break; - case SoftTrennK : c='-'; break; - case SoftTrennAdd: c='-'; - } - } - return c; -} - - - -USHORT GetSchnittBit(UCHAR c) -{ - USHORT r=0; - switch (c) { - case EscBold : r=TextBoldBit; break; - case EscRSlnt: r=TextRSlnBit; break; - case EscUndln: r=TextUndlBit; break; - case EscStrik: r=TextStrkBit; break; - case EscDbUnd: r=TextDbUnBit; break; - case EscDbStk: r=TextDbStBit; break; - case EscSupSc: r=TextSupSBit; break; - case EscSubSc: r=TextSubSBit; break; - case EscKaptF: r=TextKaptBit; break; - case EscLSlnt: r=TextLSlnBit; break; - case Esc2DShd: r=TextSh2DBit; break; - case Esc3DShd: r=TextSh3DBit; break; - case Esc4DShd: r=TextSh4DBit; break; - case EscEbShd: r=TextShEbBit; - } - return r; -} - - - -long ChgValue(long Def, long Min, long Max, UCHAR FlgVal, long NumVal) -{ - long r=0; - - if (FlgVal==EscDeflt) { - r=Def; // zurueck auf Default - } else { - if (NumVal!=EscNoVal) r=NumVal; // Hart setzen - } - - if (Min!=0 || Max!=0) { - if (r>Max) r=Max; - if (r'9'); - if (EoVal==FALSE) { c=TBuf[Index]; Index++; } - i--; - } while (i>0 && EoVal==FALSE); - NumVal=Sgn*NumVal; - } - q=!CheckTextOutl(AktAtr.F,AktAtr.L); - - switch (Ident) { - case EscFont : AktAtr.SetFont(ULONG (ChgValue(Atr0.GetFont(),0,0 ,FlgVal,NumVal)));break; - case EscGrad : AktAtr.Grad =USHORT(ChgValue(Atr0.Grad, 2,2000 ,FlgVal,NumVal)); break; - case EscBreit: AktAtr.Breite =USHORT(ChgValue(Atr0.Breite, 1,1000 ,FlgVal,NumVal)); break; - case EscKaptS: AktAtr.Kapit =(BYTE)(ChgValue(Atr0.Kapit, 1,255 ,FlgVal,NumVal)); break; - case EscLFeed: AktAtr.LnFeed =USHORT(ChgValue(Atr0.LnFeed, 1,65535 ,FlgVal,NumVal)); break; - case EscSlant: AktAtr.Slant =USHORT(ChgValue(Atr0.Slant, 1,MaxCharSlant ,FlgVal,NumVal)); break; - case EscVPos : AktAtr.ChrVPos=char (ChgValue(Atr0.ChrVPos,-128,127 ,FlgVal,NumVal)); break; - case EscZAbst: AktAtr.ZAbst =(BYTE)(ChgValue(Atr0.ZAbst, 1,255 ,FlgVal,NumVal)); break; - case EscHJust: AktAtr.Justify=(BYTE)(ChgValue(Atr0.Justify & 0x0F,0,5 ,FlgVal,NumVal)); break; - case EscFarbe: { AktAtr.L.LFarbe =(BYTE)(ChgValue(Atr0.L.LFarbe,0,7 ,FlgVal,NumVal)); if (q) AktAtr.F.FFarbe =AktAtr.L.LFarbe; } break; - case EscBFarb: { AktAtr.L.LBFarbe=(BYTE)(ChgValue(Atr0.L.LBFarbe,0,255,FlgVal,NumVal)); if (q) AktAtr.F.FBFarbe=AktAtr.L.LBFarbe; } break; - case EscInts : { AktAtr.L.LIntens=(BYTE)(ChgValue(Atr0.L.LIntens,0,100,FlgVal,NumVal)); if (q) AktAtr.F.FIntens=AktAtr.L.LIntens; } break; - - case EscMustr: { AktAtr.F.FMuster=USHORT(ChgValue(Atr0.F.FMuster,0,65535,FlgVal,NumVal)); } break; - case EscMFarb: { AktAtr.F.FFarbe =(BYTE)(ChgValue(Atr0.F.FFarbe,0,7 ,FlgVal,NumVal)); } break; - case EscMBFrb: { AktAtr.F.FBFarbe=(BYTE)(ChgValue(Atr0.F.FBFarbe,0,255,FlgVal,NumVal)); } break; - case EscMInts: { AktAtr.F.FIntens=(BYTE)(ChgValue(Atr0.F.FIntens,0,100,FlgVal,NumVal)); } break; - - case EscSMstr: { AktAtr.ShdF.FMuster=USHORT(ChgValue(Atr0.ShdF.FMuster,0,65535,FlgVal,NumVal)); } break; - case EscSFarb: { AktAtr.ShdL.LFarbe =(BYTE)(ChgValue(Atr0.ShdL.LFarbe,0,7 ,FlgVal,NumVal)); AktAtr.ShdF.FFarbe =AktAtr.ShdL.LFarbe; } break; - case EscSBFrb: { AktAtr.ShdL.LBFarbe=(BYTE)(ChgValue(Atr0.ShdL.LBFarbe,0,255,FlgVal,NumVal)); AktAtr.ShdF.FBFarbe=AktAtr.ShdL.LBFarbe; } break; - case EscSInts: { AktAtr.ShdL.LIntens=(BYTE)(ChgValue(Atr0.ShdL.LIntens,0,100,FlgVal,NumVal)); AktAtr.ShdF.FIntens=AktAtr.ShdL.LIntens; } break; - case EscSDist: { AktAtr.ShdVers.x=(short)ChgValue(Atr0.ShdVers.x,0,30000,FlgVal,NumVal); AktAtr.ShdVers.y=AktAtr.ShdVers.x; } break; - case EscSXDst: { AktAtr.ShdVers.x=(short)ChgValue(Atr0.ShdVers.x,0,30000,FlgVal,NumVal); } break; - case EscSYDst: { AktAtr.ShdVers.y=(short)ChgValue(Atr0.ShdVers.y,0,30000,FlgVal,NumVal); } break; - - case EscBold : ChgSchnittBit(TextBoldBit,0,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - case EscRSlnt: ChgSchnittBit(TextRSlnBit,TextLSlnBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - case EscUndln: ChgSchnittBit(TextUndlBit,TextDbUnBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - case EscStrik: ChgSchnittBit(TextStrkBit,TextDbStBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - case EscDbUnd: ChgSchnittBit(TextDbUnBit,TextUndlBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - case EscDbStk: ChgSchnittBit(TextDbStBit,TextStrkBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - case EscSupSc: ChgSchnittBit(TextSupSBit,TextSubSBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - case EscSubSc: ChgSchnittBit(TextSubSBit,TextSupSBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - case EscKaptF: ChgSchnittBit(TextKaptBit,0,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - case EscLSlnt: ChgSchnittBit(TextLSlnBit,TextRSlnBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - case Esc2DShd: ChgSchnittBit(TextSh2DBit,TextSh3DBit,TextSh4DBit,TextShEbBit,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - case Esc3DShd: ChgSchnittBit(TextSh3DBit,TextSh2DBit,TextSh4DBit,TextShEbBit,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - case Esc4DShd: ChgSchnittBit(TextSh4DBit,TextSh2DBit,TextSh3DBit,TextShEbBit,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - case EscEbShd: ChgSchnittBit(TextShEbBit,TextSh2DBit,TextSh3DBit,TextSh4DBit,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; - } //endcase - if (TBuf[Index]==Escape) Index++; // zweites Esc weglesen } - } // if Ende==FALSE - } while (Ende==FALSE && ScanEsc==FALSE); - if (Ende==FALSE) c=Escape; - return c; -} // end of ProcessOne - - -UCHAR GetTextChar(UCHAR* TBuf, USHORT& Index, - ObjTextType& Atr0, ObjTextType& AktAtr, - USHORT Rest, BOOL ScanEsc) -{ - UCHAR c,c0,nc; - - c=ProcessOne(TBuf,Index,Atr0,AktAtr,ScanEsc); - if (ScanEsc==FALSE) { - if (c==SoftTrennAdd || c==SoftTrennK || c==SoftTrenn) { - nc=GetNextChar(TBuf,Index); - c0=c; - if (Rest==0 || Rest==DoTrenn || - nc==' ' || nc==AbsatzEnd || nc==TextEnd) c='-'; - else { - c=ProcessOne(TBuf,Index,Atr0,AktAtr,ScanEsc); // den Trenner ueberspringen - if (c0==SoftTrennAdd) { - if (c>=32) c=ProcessOne(TBuf,Index,Atr0,AktAtr,ScanEsc); // und hier noch 'nen Buchstaben ueberspringen - } - } - } - if ((Rest==1 || Rest==DoTrenn) && GetNextChar(TBuf,Index)==SoftTrennK) { - if (c=='c') c='k'; - else if (c=='C') c='K'; - } - } - return c; -} - - // HardSpace und HardTrenn muessen explizit konvertiert werden ! } - // if AktAtr.Schnitt and TextKaptBit =TextKaptBit then c:=UpCase(c);(explizit) } - - // Bei der Trennmethode SoftTrennAdd wird davon ausgegangen, dass der zu } - // trennende Konsonant bereits 3x mal im TextBuf vorhanden ist, z.b.: } - // "Schiff-fahrt". Wenn nicht getrennt, dann wird "-f" entfernt. } - - - -UCHAR GetTextCharConv(UCHAR* TBuf, USHORT& Index, - ObjTextType& Atr0, ObjTextType& AktAtr, - USHORT Rest, BOOL ScanEsc) -{ - UCHAR c; - - c=GetTextChar(TBuf,Index,Atr0,AktAtr,Rest,ScanEsc); - if (c<32) { - switch (c) { - case HardSpace : c=' '; break; - case AbsatzEnd : c=' '; break; - case HardTrenn : c='-'; - } - } - return c; -} - - -// ====================================================================== -// Function GetLineFeed() -// -// Benoetigter Zeilenabstand in SGF-Units. ChrVPos wird beruecksichtigt. -// ====================================================================== -USHORT GetLineFeed(UCHAR* TBuf, USHORT Index, ObjTextType Atr0, ObjTextType AktAtr, - USHORT nChar, USHORT& LF, USHORT& MaxGrad) -{ - UCHAR c=0; - BOOL AbsEnd=FALSE; - ULONG LF100=0; - ULONG MaxLF100=0; - BOOL LFauto=0; - BOOL First=TRUE; - USHORT Grad; - USHORT i=0; - USHORT r=1; - - MaxGrad=0; - while (!AbsEnd && nChar>0) { - nChar--; - c=GetTextChar(TBuf,Index,Atr0,AktAtr,nChar,FALSE); - i++; - AbsEnd=(c==TextEnd || c==AbsatzEnd); - if (First || (!AbsEnd && c!=' ' && c!=HardTrenn)) { - LFauto=(AktAtr.LnFeed & 0x8000)==0; - LF100=AktAtr.LnFeed & 0x7FFF; - if (LFauto) LF100=LF100*AktAtr.Grad; else LF100*=LF100; - if (AktAtr.ChrVPos>0) LF100-=AktAtr.ChrVPos*100; - if (LF100>MaxLF100) MaxLF100=LF100; - Grad=AktAtr.Grad; - if (AktAtr.ChrVPos>0) Grad=Grad-AktAtr.ChrVPos; - if (Grad>MaxGrad) MaxGrad=Grad; - First=FALSE; - } - if (!AbsEnd && c!=' ') r=i; - } - MaxGrad=hPoint2Sgf(MaxGrad); - if (MaxLF100<=4000) { // sonst Overflowgefahr - LF=USHORT(hPoint2Sgf(short(MaxLF100)) /100); - } else { - LF=USHORT(hPoint2Sgf(short(MaxLF100) /100)); - } - - return r; -} - -// End of AbsRead.Pas -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// - - - -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -// iFont.Pas - -#define DefaultSlant 1500 /* Default: Italic ist 15deg */ -#define SuperSubFact 60 /* SuperScript/SubScript: 60% vom Schriftgrad */ -#define DefaultSpace 40 /* Default: Space ist 40% vom SchriftGrad */ - -USHORT SetTextContext(OutputDevice& rOut, ObjTextType& Atr, BOOL Kapt, USHORT Dreh, - USHORT FitXMul, USHORT FitXDiv, USHORT FitYMul, USHORT FitYDiv) -{ - SgfFontOne* pSgfFont; // Font aus dem IniFile - Font aFont; - Color aColor; - ULONG Grad; - ULONG Brei; - String FNam; - USHORT StdBrei=50; // Durchschnittliche Zeichenbreite in % von Schriftgrad - BOOL bFit=(FitXMul!=1 || FitXDiv!=1 || FitYMul!=1 || FitYDiv!=1); - - pSgfFont = pSgfFonts->GetFontDesc(Atr.GetFont()); - - if ( pSgfFont!=NULL ) - { - FNam =pSgfFont->SVFName; - StdBrei=pSgfFont->SVWidth; - if (pSgfFont->Fixd) aFont.SetPitch(PITCH_FIXED); else aFont.SetPitch(PITCH_VARIABLE); - aFont.SetFamily(pSgfFont->SVFamil); - aFont.SetCharSet(pSgfFont->SVChSet); - aFont.SetName(FNam); - } - else - { // Falls nich im Inifile, sind hier einige Fonts hart kodiert - aFont.SetPitch(PITCH_VARIABLE); - switch (Atr.GetFont()) { - case 92500: case 92501: case 92504: case 92505: - { -#if defined(WNT) || defined(PM2) - FNam=String::CreateFromAscii( "Times New Roman" ); // CG Times ist unter Windows und OS/2 Times New Roman -#else - FNam=String::CreateFromAscii( "Times" ); // ansonsten ist das einfach Times -#endif - StdBrei=40; - aFont.SetFamily(FAMILY_ROMAN); - } break; - case 94021: case 94022: case 94023: case 94024: { -#if defined(WNT) - FNam=String::CreateFromAscii( "Arial", 5 ); // Univers ist unter Windows Arial -#else - FNam=String::CreateFromAscii( "Helvetica" ); // und ansonsten Helvetica -#endif - aFont.SetFamily(FAMILY_SWISS); - StdBrei=47; - } break; - case 93950: case 93951: case 93952: case 93953: { -#if defined(WNT) - FNam=String::CreateFromAscii( "Courier New" ); // Der Vector-Courierfont unter Windows heisst Courier New -#else - FNam=String::CreateFromAscii( "Courier" ); // ansonsten ist und bleibt Courier immer Courier -#endif - aFont.SetFamily(FAMILY_ROMAN); - aFont.SetPitch(PITCH_FIXED); - } break; - default: FNam=String::CreateFromAscii( "Helvetica", 9 ); - } - aFont.SetName(FNam); - //aFont.SetCharSet(CHARSET_SYSTEM); - } - - Grad=ULONG(Atr.Grad); - if ((Atr.Schnitt & TextKaptBit) !=0 && Kapt) Grad=Grad*ULONG(Atr.Kapit)/100; - if ((Atr.Schnitt & TextSupSBit) !=0 || (Atr.Schnitt & TextSubSBit) !=0) Grad=Grad*SuperSubFact/100; - Brei=Grad; - if (Atr.Breite!=100 || bFit) { - if (bFit) { - Grad=Grad*ULONG(FitYMul)/ULONG(FitYDiv); - Brei=Brei*ULONG(FitXMul)/ULONG(FitXDiv); - } - Brei=Brei*ULONG(Atr.Breite)/100; - Brei=Brei*ULONG(StdBrei)/100; - aFont.SetSize(Size(hPoint2Sgf(USHORT(Brei)),hPoint2Sgf(USHORT(Grad)))); - } else { - aFont.SetSize(Size(0,hPoint2Sgf(USHORT(Grad)))); - } - - aColor=Sgv2SvFarbe(Atr.L.LFarbe,Atr.L.LBFarbe,Atr.L.LIntens); aFont.SetColor(aColor); - aColor=Sgv2SvFarbe(Atr.F.FFarbe,Atr.F.FBFarbe,Atr.F.FIntens); aFont.SetFillColor(aColor); - aFont.SetTransparent(TRUE); - aFont.SetAlign(ALIGN_BASELINE); - - Dreh/=10; Dreh=3600-Dreh; if (Dreh==3600) Dreh=0; - aFont.SetOrientation(Dreh); - - if ((Atr.Schnitt & TextBoldBit) !=0) aFont.SetWeight(WEIGHT_BOLD); - if ((Atr.Schnitt & TextRSlnBit) !=0) aFont.SetItalic(ITALIC_NORMAL); - if ((Atr.Schnitt & TextUndlBit) !=0) aFont.SetUnderline(UNDERLINE_SINGLE); - if ((Atr.Schnitt & TextDbUnBit) !=0) aFont.SetUnderline(UNDERLINE_DOUBLE); - if ((Atr.Schnitt & TextStrkBit) !=0) aFont.SetStrikeout(STRIKEOUT_SINGLE); - if ((Atr.Schnitt & TextDbStBit) !=0) aFont.SetStrikeout(STRIKEOUT_DOUBLE); - if ((Atr.Schnitt & TextSh2DBit) !=0) aFont.SetShadow(TRUE); - if ((Atr.Schnitt & TextSh3DBit) !=0) aFont.SetShadow(TRUE); - if ((Atr.Schnitt & TextSh4DBit) !=0) aFont.SetShadow(TRUE); - if ((Atr.Schnitt & TextShEbBit) !=0) aFont.SetShadow(TRUE); - if (CheckTextOutl(Atr.F,Atr.L)) aFont.SetOutline(TRUE); - - if (aFont!=rOut.GetFont()) rOut.SetFont(aFont); - - return 0; -} - -// iFont.Pas -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// - - -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -// Absatz.Pas - -struct ProcChrSta { - USHORT Index; - USHORT ChrXP; - UCHAR OutCh; - BOOL Kapt; - ObjTextType Attrib; -}; - -void InitProcessCharState(ProcChrSta& State, ObjTextType& AktAtr, USHORT IndexA) -{ - State.Attrib=AktAtr; - State.OutCh=0; - State.Index=IndexA; - State.ChrXP=0; - State.Kapt=FALSE; -} - -BOOL UpcasePossible(UCHAR c) -{ - if ((c>='a' && c<='z') || c == 0xe4 || c == 0xf6 || c == 0xfc ) return TRUE; - else return FALSE; -} - -UCHAR Upcase(UCHAR c) -{ - if ((c>=(UCHAR)'a' && c<=(UCHAR)'z')) c=(c-(UCHAR)'a')+(UCHAR)'A'; - else if ( c == 0xe4 ) c = 0xc4; - else if ( c == 0xf6 ) c = 0xd6; - else if ( c == 0xfc ) c = 0xdc; - return c; -} - -USHORT GetCharWidth(OutputDevice& rOut, UCHAR c) -{ - UCHAR c1; - USHORT ChrWidth; - - c1 = ByteString::Convert((char)c,RTL_TEXTENCODING_IBM_437, gsl_getSystemTextEncoding() ); - if (c==' ') - { - ChrWidth=(USHORT)rOut.GetTextWidth( String('A') ); - if (rOut.GetFont().GetPitch()!=PITCH_FIXED) { - ChrWidth=MulDiv(ChrWidth,DefaultSpace,100); - } - } else { - // with MaxChar == 255 c cannot be greater than MaxChar - // assert if MaxChar is ever changed - OSL_ENSURE( MaxChar == 255, "MaxChar not 255" ); - if (c>=MinChar /*&& c<=MaxChar*/) - { - ChrWidth=(USHORT)rOut.GetTextWidth(String((char)c1)); - } - else - { - ChrWidth=(USHORT)rOut.GetTextWidth(String('A')); - } - } - return ChrWidth; -} - -UCHAR ProcessChar(OutputDevice& rOut, UCHAR* TBuf, ProcChrSta& R, ObjTextType& Atr0, - USHORT& nChars, USHORT Rest, - short* Line, UCHAR* cLine) -{ - USHORT KernDist=0; // Wert fuer Kerning - USHORT ChrWidth; - UCHAR c; - UCHAR c1; - BOOL AbsEnd; - - c=GetTextChar(TBuf,R.Index,Atr0,R.Attrib,Rest,FALSE); // versucht evtl. zu trennen, wenn Rest entsprechenden Wert besitzt - - AbsEnd=(c==AbsatzEnd || c==TextEnd); - if (AbsEnd==FALSE) { - R.OutCh=ConvertTextChar(c); // von HardTrenn nach '-', ... - R.Kapt=(R.Attrib.Schnitt & TextKaptBit) !=0 && UpcasePossible(R.OutCh); - if (R.Kapt) R.OutCh=Upcase(R.OutCh); - SetTextContext(rOut,R.Attrib,R.Kapt,0,1,1,1,1); - - if (R.Kapt) c1=Upcase(c); else c1=c; - ChrWidth=GetCharWidth(rOut,c1); - - if (R.Attrib.ZAbst!=100) { // Spezial-Zeichenabstand ? - ULONG Temp; - Temp=ULONG(ChrWidth)*ULONG(R.Attrib.ZAbst)/100; - ChrWidth=USHORT(Temp); - } - nChars++; - if (R.ChrXP>32000) R.ChrXP=32000; - Line[nChars]=R.ChrXP-KernDist; - cLine[nChars]=c; - R.ChrXP+=ChrWidth-KernDist; // Position fuer den naechsten Character - } - return c; -} - -void FormatLine(UCHAR* TBuf, USHORT& Index, ObjTextType& Atr0, ObjTextType& AktAtr, - USHORT UmbWdt, USHORT AdjWdt, - short* Line, USHORT& nChars, - double, double, - UCHAR* cLine, BOOL TextFit) -{ - VirtualDevice vOut; - UCHAR c,c0; - UCHAR ct; - BOOL First; // erster Char ? - BYTE Just = 0; // Absatzformatierung - BOOL Border; // Rand der Box erreicht ? - BOOL Border0; - BOOL AbsEnd; // Ende des Absatzes erreicht ? - ProcChrSta* R=new ProcChrSta; - ProcChrSta* R0=new ProcChrSta; - ProcChrSta* WErec=new ProcChrSta; - USHORT WEnChar; - ProcChrSta* WErec0=new ProcChrSta; - USHORT WEnChar0; - ProcChrSta* TRrec=new ProcChrSta; - USHORT TRnChar; - - USHORT WordEndCnt; // Justieren und Trennen - BOOL WordEnd; - BOOL Trenn; - - short BoxRest; // zum Quetschen und formatieren - USHORT i,j,k,h; - USHORT re,li; - - vOut.SetMapMode(MapMode(MAP_10TH_MM,Point(),Fraction(1,4),Fraction(1,4))); - - nChars=0; - SetTextContext(vOut,AktAtr,FALSE,0,1,1,1,1); - InitProcessCharState(*R,AktAtr,Index); - (*R0)=(*R); (*WErec)=(*R); WEnChar=0; c0=0; Border0=FALSE; - Border=FALSE; First=TRUE; - WordEndCnt=0; - - do { // mal schauen, wieviele Worte so in die Zeile passen - if (Border) c=ProcessChar(vOut,TBuf,*R,Atr0,nChars,DoTrenn,Line,cLine); - else c=ProcessChar(vOut,TBuf,*R,Atr0,nChars,NoTrenn,Line,cLine); - AbsEnd=(c==AbsatzEnd || c==TextEnd); - //if not AbsEnd then - { - if (First) { - Just=R->Attrib.Justify & 0x0F; // Absatzformat steht wenn, dann am Anfang - } - Border=R->ChrXP>UmbWdt; - WordEnd=(AbsEnd || (c==' ')) && (c0!=' ') && (c0!=0); - Trenn=c=='-'; - if (WordEnd && !Border0) { - WordEndCnt++; - (*WErec)=(*R0); - WEnChar=nChars-1; - } - if (Trenn && !Border) { - WordEndCnt++; - (*WErec)=(*R); - WEnChar=nChars; - } - } - (*R0)=(*R); c0=c; - Border0=Border; - First=FALSE; - AbsEnd=AbsEnd || (nChars>=MaxLineChars); - } while (!(AbsEnd || (Border && ((WordEndCnt>0) || WordEnd || Trenn)))); - - if (Border) { // Trennen und Quetschen - (*WErec0)=(*WErec); WEnChar0=WEnChar; - AbsEnd=FALSE; c0=0; - (*R)=(*WErec); nChars=WEnChar; - (*TRrec)=(*R); TRnChar=nChars; - Border0=FALSE; Border=FALSE; - do { // erst mal gucken wieviele Silben noch reinpassen - ct=ProcessChar(vOut,TBuf,*TRrec,Atr0,TRnChar,DoTrenn,Line,cLine); - c=ProcessChar(vOut,TBuf,*R,Atr0,nChars,NoTrenn,Line,cLine); - AbsEnd=(ct==AbsatzEnd) || (ct==TextEnd) || (nChars>=MaxLineChars); - - Border=TRrec->ChrXP>UmbWdt; - WordEnd=AbsEnd || ((AbsEnd || (c==' ')) && (c0!=' ') && (c0!=0)); - Trenn=ct=='-'; - if (WordEnd && (!Border0 || (WordEndCnt==0))) { - WordEndCnt++; - (*WErec)=(*R0); - if (AbsEnd) WEnChar=nChars; else WEnChar=nChars-1; - (*TRrec)=(*R); TRnChar=nChars; // zum weitersuchen - } - if (Trenn && (!Border || (WordEndCnt==0))) { - WordEndCnt++; // merken, dass man hier trennen kann - (*WErec)=(*TRrec); - WEnChar=TRnChar; - (*TRrec)=(*R); TRnChar=nChars; // zum weitersuchen - } - (*R0)=(*R); c0=c; - Border0=Border; - Border=R->ChrXP>UmbWdt; - } while (!(AbsEnd || (Border && ((WordEndCnt>0) || WordEnd || Trenn)))); - - while (WErec0->IndexIndex) { // damit Line[] auch garantiert stimmt } - c=ProcessChar(vOut,TBuf,*WErec0,Atr0,WEnChar0,WEnChar-WEnChar0-1,Line,cLine); - } - - (*R)=(*WErec); nChars=WEnChar; - - if (UmbWdt>=R->ChrXP) { - BoxRest=UmbWdt-R->ChrXP; - } else { // Zusammenquetschen - BoxRest=R->ChrXP-UmbWdt; // um soviel muss gequetscht werden - for (i=2;i<=nChars;i++) { // 1. CharPosition bleibt ! - Line[i]-=(i-1)*(BoxRest) /(nChars-1); - } - R->ChrXP=UmbWdt; - Line[nChars+1]=UmbWdt; - } - } - - if (!AbsEnd) { - do { // Leerzeichen weglesen - (*WErec)=(*R); - c=GetTextChar(TBuf,R->Index,Atr0,R->Attrib,NoTrenn,FALSE); - nChars++; - Line[nChars]=R->ChrXP; - cLine[nChars]=c; - } while (c==' '); - if (c!=' ' && c!=AbsatzEnd && c!=TextEnd) { - nChars--; - (*R)=(*WErec); - } - } - - if (AbsEnd && nCharsChrXP; // Damit AbsatzEnde auch weggelesen wird - Line[nChars+1]=R->ChrXP; // denn die Breite von CR oder #0 ist nun mal sehr klein - if (TBuf[R->Index-1]!=AbsatzEnd && TBuf[R->Index-1]!=TextEnd) { - c=GetTextChar(TBuf,R->Index,Atr0,R->Attrib,NoTrenn,FALSE); // Kleine Korrektur. Notig, wenn nur 1 Wort in - } - } - - BoxRest=AdjWdt-R->ChrXP; - if (TextFit) Just=THJustLeft; - - switch (Just) { - case THJustLeft: break; // Links - case THJustCenter: { - BoxRest=BoxRest /2; // Mitte - for (i=1;i<=nChars;i++) Line[i]=Line[i]+BoxRest; - } break; - case THJustRight: { // Rechts - for (i=1;i<=nChars;i++) Line[i]=Line[i]+BoxRest; - } break; - case THJustDrvOut: - case THJustBlock: { // Block und Austreibend - re=nChars; - if (Just==THJustDrvOut) re--; - while (re>=1 && (cLine[re]==' ' || cLine[re]==TextEnd || cLine[re]==AbsatzEnd)) re--; - li=1; - while (li<=re && (cLine[li]==' ' || cLine[li]==TextEnd || cLine[li]==AbsatzEnd)) li++; - if (Just==THJustDrvOut) BoxRest=AdjWdt-Line[re+1]; - - j=0; // Anzahl der Spaces ermitteln - for (i=li;i<=re;i++) { - if (cLine[i]==' ') { - j++; - } - } - - if (j==0) { // nur 1 Wort ? -> Strecken ! - for (i=li+1;i<=re;i++) { // von links nach rechts - Line[i]=Line[i]+MulDiv(i-li,BoxRest,re-li+1-1); - } - } else { - k=0; h=0; - for (i=li;i<=re;i++) { // j Spaces aufbohren ! - if (cLine[i]==' ') { // Space gefunden ! - k++; - h=MulDiv(k,BoxRest,j); - } - Line[i]=Line[i]+h; - } - } - for (i=re+1;i<=nChars;i++) Line[i]=Line[i]+BoxRest; // und den Rest anpassen - Line[nChars+1]=AdjWdt; - } break; - case THJustLocked: { //Gesperrt - re=nChars-1; - while (re>=1 && (cLine[re]==' ' || cLine[re]==TextEnd || cLine[re]==AbsatzEnd)) re--; - li=1; - while (li<=re && (cLine[li]==' ' || cLine[li]==TextEnd || cLine[li]==AbsatzEnd)) li++; - BoxRest=AdjWdt-Line[re+1]; - for (i=li+1;i<=re;i++) { // Strecken von links nach rechts - Line[i]=Line[i]+MulDiv(i-li,BoxRest,re-li+1-1); - } - for (i=re+1;i<=nChars;i++) Line[i]=Line[i]+BoxRest; // und den Rest anpassen - Line[nChars+1]=AdjWdt; - } break; - } - Index=R->Index; - AktAtr=R->Attrib; - delete R; - delete R0; - delete WErec; - delete WErec0; - delete TRrec; -} - - - -// End of Absatz.Pas -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// - - -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -// DrawText.Pas - -void DrawChar(OutputDevice& rOut, UCHAR c, ObjTextType T, PointType Pos, USHORT DrehWink, - USHORT FitXMul, USHORT FitXDiv, USHORT FitYMul, USHORT FitYDiv) -{ - SetTextContext(rOut,T,UpcasePossible(c),DrehWink,FitXMul,FitXDiv,FitYMul,FitYDiv); - if ((T.Schnitt & TextKaptBit)!=0 && UpcasePossible(c)) c=Upcase(c); - String s( (char)c, RTL_TEXTENCODING_IBM_437 ); - rOut.DrawText( Point( Pos.x, Pos.y ), s ); -} - -/************************************************************************* -|* -|* TextType::Draw() -|* -|* Beschreibung -|* Ersterstellung JOE 09.08.93 -|* Letzte Aenderung JOE 09.08.93 -|* -*************************************************************************/ -void TextType::Draw(OutputDevice& rOut) -{ - if ((Flags & TextOutlBit)!=0) return; // Sourcetext fuer Outliner !! - - ObjTextType T1,T2; - USHORT Index1; - USHORT Index2; - UCHAR c = TextEnd; - USHORT l; // Anzahl der Zeichen in der Zeile - USHORT i; - short yPos0; - short xPos; - short yPos; - USHORT LF; - USHORT MaxGrad; - short xSize; - short xSAdj; - short ySize; - double sn,cs; - USHORT TopToBase; - BOOL Ende = 0; - USHORT lc; - BOOL LineFit; // FitSize.x=0? oder Flags -> jede Zeile stretchen - BOOL TextFit; - short* xLine; - UCHAR* cLine; // Buffer fuer FormatLine - USHORT FitXMul; - USHORT FitXDiv; - USHORT FitYMul; - USHORT FitYDiv; - BOOL Fehler; - UCHAR* Buf=Buffer; // Zeiger auf die Buchstaben - - pSgfFonts->ReadList(); - xLine=new short[ChrXPosArrSize]; - cLine=new UCHAR[CharLineSize]; - - TextFit=(Flags & TextFitBits)!=0; - LineFit=FALSE; - LineFit=((Flags & TextFitZBit)!=0); - if (TextFit && FitSize.x==0) LineFit=TRUE; - - if (DrehWink==0) { - sn=0.0; - cs=1.0; - } else { - sn=sin(double(DrehWink)*3.14159265359/18000); - cs=cos(double(DrehWink)*3.14159265359/18000); - } - - T1=T; Index1=0; yPos=0; xPos=0; - if (TextFit) { - ySize=Pos2.y-Pos1.y; - xSize=32000 /2; // Umbruch - xSAdj=Pos2.x-Pos1.x; // zum Ausrichten bei Zentriert/Blocksatz - //if (xSize<=0) { xSize=32000 /2; LineFit=TRUE; } - FitXMul=sal::static_int_cast< USHORT >(abs(Pos2.x-Pos1.x)); FitXDiv=FitSize.x; if (FitXDiv==0) FitXDiv=1; - FitYMul=sal::static_int_cast< USHORT >(abs(Pos2.y-Pos1.y)); FitYDiv=FitSize.y; if (FitYDiv==0) FitYDiv=1; - } else { - xSize=Pos2.x-Pos1.x; - xSAdj=xSize; - ySize=Pos2.y-Pos1.y; - FitXMul=1; FitXDiv=1; - FitYMul=1; FitYDiv=1; - } - if (xSize<0) xSize=0; - if (xSAdj<0) xSAdj=0; - - do { - T2=T1; Index2=Index1; - FormatLine(Buf,Index2,T,T2,xSize,xSAdj,xLine,l,sn,cs,cLine,LineFit); - Fehler=(Index2==Index1); - if (!Fehler) { - lc=GetLineFeed(Buf,Index1,T,T1,l,LF,MaxGrad); - if (TextFit) { - if (LineFit) FitXDiv=xLine[lc+1]; - if (FitXDiv>0) { - long Temp; - for (i=1;i<=l+1;i++) { - Temp=long(xLine[i])*long(FitXMul) /long(FitXDiv); - xLine[i]=short(Temp); - } - LF=MulDiv(LF,FitYMul,FitYDiv); - MaxGrad=MulDiv(MaxGrad,FitYMul,FitYDiv); - } else { - FitXDiv=1; // 0 gibts nicht - } - } - yPos0=yPos; - TopToBase=GetTopToBaseLine(MaxGrad); - yPos=yPos+TopToBase; - Ende=(yPos0+short(MulDiv(MaxGrad,CharTopToBtm,100))>ySize) && !TextFit; - if (!Ende) { - T2=T1; Index2=Index1; - i=1; - while (i<=l) { - c=GetTextCharConv(Buf,Index2,T,T2,l-i,FALSE); - long xp1,yp1; // wegen Overflowgefahr - PointType Pos; - xp1=long(Pos1.x)+xPos+long(xLine[i]); - yp1=long(Pos1.y)+yPos; - if (xp1>32000) xp1=32000; if (xp1<-12000) xp1=-12000; - if (yp1>32000) yp1=32000; if (yp1<-12000) yp1=-12000; - Pos.x=short(xp1); - Pos.y=short(yp1); - - if (DrehWink!=0) RotatePoint(Pos,Pos1.x,Pos1.y,sn,cs); - DrawChar(rOut,c,T2,Pos,DrehWink,FitXMul,FitXDiv,FitYMul,FitYDiv); - i++; - } // while i<=l - yPos=yPos0+LF; - T1=T2; Index1=Index2; // Fuer die naechste Zeile - } // if ObjMin.y+yPos<=Obj_Max.y - } // if !Fehler - } while (c!=TextEnd && !Ende && !Fehler); - delete[] cLine; - delete[] xLine; -} - -// End of DrawText.Pas -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// - -// nicht mehr benoetigt, da der Pointer nun extra gefuehrt wird -// (DEC Alpha hat naemlich 64Bit-Pointer!) -//UCHAR* TextType::GetBufPtr() -//{ -// ULONG Temp; -// Temp=ULONG(BufLo)+0x00010000*ULONG(BufHi); -// return (UCHAR*)Temp; -//} -// -//void TextType::SetBufPtr(UCHAR* Ptr) -//{ -// ULONG Temp=(ULONG)Ptr; -// BufLo=USHORT(Temp & 0x0000FFFF); -// BufHi=USHORT((Temp & 0xFFFF0000)>>16); -//} - -UINT32 ObjTextType::GetFont() -{ - return ULONG(FontLo)+0x00010000*ULONG(FontHi); -} - -void ObjTextType::SetFont(UINT32 FontID) -{ - FontLo=USHORT(FontID & 0x0000FFFF); - FontHi=USHORT((FontID & 0xFFFF0000)>>16); -} - - -///////////////////////////////////////////////////////////////////////////////// -// SGF.Ini lesen //////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// -SgfFontOne::SgfFontOne() -{ - Next=NULL; - IFID=0; - Bold=FALSE; - Ital=FALSE; - Sans=FALSE; - Serf=FALSE; - Fixd=FALSE; - SVFamil=FAMILY_DONTKNOW; - SVChSet=RTL_TEXTENCODING_DONTKNOW; - SVWidth=40; -} - -void SgfFontOne::ReadOne( ByteString& ID, ByteString& Dsc ) -{ - USHORT i,j,n; - ByteString s; - - if ( Dsc.Len() < 4 || ( Dsc.GetChar( 0 ) != '(' ) ) - return; - i=1; // Erster Buchstabe des IF-Fontnamen. Davor ist eine '(' - while ( i < Dsc.Len() && ( Dsc.GetChar( i ) !=')' ) ) - i++; - Dsc.Erase(0,i+1); // IF-Fontname loeschen inkl. () - - if ( Dsc.Len() < 2 || ( Dsc.GetChar( Dsc.Len() - 1 ) !=')' ) ) - return; - i=Dsc.Len()-2; // hier ist die ')' des SV-Fontnames - j=0; - while ( i > 0 && ( Dsc.GetChar( i ) != '(' ) ) - { - i--; - j++; - } - SVFName=String(Dsc,i+1,j); // SV-Fontname rausholen - Dsc.Erase(i,j); - - IFID = (UINT32)ID.ToInt32(); - n=Dsc.GetTokenCount(' '); - for (i=0;i(s.ToInt32()); - } - } -} - -///////////////////////////////////////////////////////////////////////////////// - -SgfFontLst::SgfFontLst() -{ - pList=NULL; - Last=NULL; - LastID=0; - LastLn=NULL; - Tried=FALSE; -} - -SgfFontLst::~SgfFontLst() -{ - RausList(); -} - -void SgfFontLst::RausList() -{ - SgfFontOne* P; - SgfFontOne* P1; - P=pList; - while (P!=NULL) { - P1=P->Next; - delete P; - P=P1; - } - pList=NULL; - Last=NULL; - Tried=FALSE; - LastID=0; - LastLn=NULL; -} - -void SgfFontLst::AssignFN(const String& rFName) -{ FNam=rFName; } - -void SgfFontLst::ReadList() -{ - if (!Tried) { - Tried=TRUE; - LastID=0; - LastLn=NULL; - SgfFontOne* P,P1; - Config aCfg(FNam); - aCfg.SetGroup("SGV Fonts fuer StarView"); - USHORT Anz=aCfg.GetKeyCount(); - USHORT i; - ByteString FID,Dsc; - - for (i=0;iNext=P; else pList=P; Last=P; // einklinken - P->ReadOne(FID,Dsc); // und Zeile interpretieren - } - } - } -} - -SgfFontOne* SgfFontLst::GetFontDesc(UINT32 ID) -{ - if (ID!=LastID) { - SgfFontOne* P; - P=pList; - while (P!=NULL && P->IFID!=ID) P=P->Next; - LastID=ID; - LastLn=P; - } - return LastLn; -} diff --git a/svtools/source/filter.vcl/igif/decode.cxx b/svtools/source/filter.vcl/igif/decode.cxx deleted file mode 100644 index bfe77319b81a..000000000000 --- a/svtools/source/filter.vcl/igif/decode.cxx +++ /dev/null @@ -1,215 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#include "decode.hxx" - -// ------------------------------------------------------------------------ - -struct GIFLZWTableEntry -{ - GIFLZWTableEntry* pPrev; - GIFLZWTableEntry* pFirst; - BYTE nData; -}; - -// ------------------------------------------------------------------------ - -GIFLZWDecompressor::GIFLZWDecompressor( BYTE cDataSize ) : - nInputBitsBuf ( 0 ), - nOutBufDataLen ( 0 ), - nInputBitsBufSize ( 0 ), - bEOIFound ( FALSE ), - nDataSize ( cDataSize ) -{ - pOutBuf = new BYTE[ 4096 ]; - - nClearCode = 1 << nDataSize; - nEOICode = nClearCode + 1; - nTableSize = nEOICode + 1; - nCodeSize = nDataSize + 1; - nOldCode = 0xffff; - pOutBufData = pOutBuf + 4096; - - pTable = new GIFLZWTableEntry[ 4098 ]; - - for( USHORT i = 0; i < nTableSize; i++ ) - { - pTable[i].pPrev = NULL; - pTable[i].pFirst = pTable + i; - pTable[i].nData = (BYTE) i; - } -} - -// ------------------------------------------------------------------------ - -GIFLZWDecompressor::~GIFLZWDecompressor() -{ - delete[] pOutBuf; - delete[] pTable; -} - -// ------------------------------------------------------------------------ - -HPBYTE GIFLZWDecompressor::DecompressBlock( HPBYTE pSrc, BYTE cBufSize, - ULONG& rCount, BOOL& rEOI ) -{ - ULONG nTargetSize = 4096; - ULONG nCount = 0; - HPBYTE pTarget = (HPBYTE) rtl_allocateMemory( nTargetSize ); - HPBYTE pTmpTarget = pTarget; - - nBlockBufSize = cBufSize; - nBlockBufPos = 0; - pBlockBuf = pSrc; - - while( ProcessOneCode() ) - { - nCount += nOutBufDataLen; - - if( nCount > nTargetSize ) - { - ULONG nNewSize = nTargetSize << 1; - ULONG nOffset = pTmpTarget - pTarget; - HPBYTE pTmp = (HPBYTE) rtl_allocateMemory( nNewSize ); - - memcpy( pTmp, pTarget, nTargetSize ); - rtl_freeMemory( pTarget ); - - nTargetSize = nNewSize; - pTmpTarget = ( pTarget = pTmp ) + nOffset; - } - - memcpy( pTmpTarget, pOutBufData, nOutBufDataLen ); - pTmpTarget += nOutBufDataLen; - pOutBufData += nOutBufDataLen; - nOutBufDataLen = 0; - - if ( bEOIFound ) - break; - } - - rCount = nCount; - rEOI = bEOIFound; - - return pTarget; -} - -// ------------------------------------------------------------------------ - -void GIFLZWDecompressor::AddToTable( USHORT nPrevCode, USHORT nCodeFirstData ) -{ - GIFLZWTableEntry* pE; - - if( nTableSize < 4096 ) - { - pE = pTable + nTableSize; - pE->pPrev = pTable + nPrevCode; - pE->pFirst = pE->pPrev->pFirst; - pE->nData = pTable[ nCodeFirstData ].pFirst->nData; - nTableSize++; - - if ( ( nTableSize == (USHORT) (1 << nCodeSize) ) && ( nTableSize < 4096 ) ) - nCodeSize++; - } -} - -// ------------------------------------------------------------------------ - -BOOL GIFLZWDecompressor::ProcessOneCode() -{ - GIFLZWTableEntry* pE; - USHORT nCode; - BOOL bRet = FALSE; - BOOL bEndOfBlock = FALSE; - - while( nInputBitsBufSize < nCodeSize ) - { - if( nBlockBufPos >= nBlockBufSize ) - { - bEndOfBlock = TRUE; - break; - } - - nInputBitsBuf |= ( (ULONG) pBlockBuf[ nBlockBufPos++ ] ) << nInputBitsBufSize; - nInputBitsBufSize += 8; - } - - if ( !bEndOfBlock ) - { - // Einen Code aus dem Eingabe-Buffer holen: - nCode = sal::static_int_cast< USHORT >( - ( (USHORT) nInputBitsBuf ) & ( ~( 0xffff << nCodeSize ) )); - nInputBitsBuf >>= nCodeSize; - nInputBitsBufSize = nInputBitsBufSize - nCodeSize; - - if ( nCode < nClearCode ) - { - if ( nOldCode != 0xffff ) - AddToTable( nOldCode, nCode ); - } - else if ( ( nCode > nEOICode ) && ( nCode <= nTableSize ) ) - { - if ( nCode == nTableSize ) - AddToTable( nOldCode, nOldCode ); - else - AddToTable( nOldCode, nCode ); - } - else - { - if ( nCode == nClearCode ) - { - nTableSize = nEOICode + 1; - nCodeSize = nDataSize + 1; - nOldCode = 0xffff; - nOutBufDataLen = 0; - } - else - bEOIFound = TRUE; - - return TRUE; - } - - nOldCode = nCode; - - // Zeichen(/-folge) des Codes nCode in den Ausgabe-Buffer schreiben: - pE = pTable + nCode; - do - { - nOutBufDataLen++; - *(--pOutBufData) = pE->nData; - pE = pE->pPrev; - } - while( pE ); - - bRet = TRUE; - } - - return bRet; -} diff --git a/svtools/source/filter.vcl/igif/decode.hxx b/svtools/source/filter.vcl/igif/decode.hxx deleted file mode 100644 index 3c6a61e7508d..000000000000 --- a/svtools/source/filter.vcl/igif/decode.hxx +++ /dev/null @@ -1,68 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _DECODE_HXX -#define _DECODE_HXX - -#ifndef _BMPACC_HXX -#include -#endif - -struct GIFLZWTableEntry; - -class GIFLZWDecompressor -{ - GIFLZWTableEntry* pTable; - HPBYTE pOutBuf; - HPBYTE pOutBufData; - HPBYTE pBlockBuf; - ULONG nInputBitsBuf; - USHORT nTableSize; - USHORT nClearCode; - USHORT nEOICode; - USHORT nCodeSize; - USHORT nOldCode; - USHORT nOutBufDataLen; - USHORT nInputBitsBufSize; - BOOL bEOIFound; - BYTE nDataSize; - BYTE nBlockBufSize; - BYTE nBlockBufPos; - - void AddToTable(USHORT nPrevCode, USHORT nCodeFirstData); - BOOL ProcessOneCode(); - - -public: - - GIFLZWDecompressor( BYTE cDataSize ); - ~GIFLZWDecompressor(); - - HPBYTE DecompressBlock( HPBYTE pSrc, BYTE cBufSize, ULONG& rCount, BOOL& rEOI ); -}; - -#endif diff --git a/svtools/source/filter.vcl/igif/gifread.cxx b/svtools/source/filter.vcl/igif/gifread.cxx deleted file mode 100644 index e4020c727ff4..000000000000 --- a/svtools/source/filter.vcl/igif/gifread.cxx +++ /dev/null @@ -1,858 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#define _GIFPRIVATE - -#include "decode.hxx" -#include "gifread.hxx" - -// ----------- -// - Defines - -// ----------- - -#define NO_PENDING( rStm ) ( ( rStm ).GetError() != ERRCODE_IO_PENDING ) - -// ------------- -// - GIFReader - -// ------------- - -GIFReader::GIFReader( SvStream& rStm ) : - aGPalette ( 256 ), - aLPalette ( 256 ), - rIStm ( rStm ), - pAcc8 ( NULL ), - pAcc1 ( NULL ), - nLastPos ( rStm.Tell() ), - nLogWidth100 ( 0UL ), - nLogHeight100 ( 0UL ), - nLoops ( 1 ), - eActAction ( GLOBAL_HEADER_READING ), - bGCTransparent ( FALSE ), - bImGraphicReady ( FALSE ) -{ - maUpperName = UniString::CreateFromAscii( "SVIGIF", 6 ); - pSrcBuf = new BYTE[ 256 ]; - ClearImageExtensions(); -} - -// ------------------------------------------------------------------------ - -GIFReader::~GIFReader() -{ - aImGraphic.SetContext( NULL ); - - if( pAcc1 ) - aBmp1.ReleaseAccess( pAcc1 ); - - if( pAcc8 ) - aBmp8.ReleaseAccess( pAcc8 ); - - delete[] pSrcBuf; -} - -// ------------------------------------------------------------------------ - -void GIFReader::ClearImageExtensions() -{ - nGCDisposalMethod = 0; - bGCTransparent = FALSE; - nTimer = 0; -} - -// ------------------------------------------------------------------------ - -BOOL GIFReader::CreateBitmaps( long nWidth, long nHeight, BitmapPalette* pPal, - BOOL bWatchForBackgroundColor ) -{ - const Size aSize( nWidth, nHeight ); - - if( bGCTransparent ) - { - const Color aWhite( COL_WHITE ); - - aBmp1 = Bitmap( aSize, 1 ); - - if( !aAnimation.Count() ) - aBmp1.Erase( aWhite ); - - pAcc1 = aBmp1.AcquireWriteAccess(); - - if( pAcc1 ) - { - cTransIndex1 = (BYTE) pAcc1->GetBestPaletteIndex( aWhite ); - cNonTransIndex1 = cTransIndex1 ? 0 : 1; - } - else - bStatus = FALSE; - } - - if( bStatus ) - { - aBmp8 = Bitmap( aSize, 8, pPal ); - - if( !!aBmp8 && bWatchForBackgroundColor && aAnimation.Count() ) - aBmp8.Erase( (*pPal)[ nBackgroundColor ] ); - else - aBmp8.Erase( Color( COL_WHITE ) ); - - pAcc8 = aBmp8.AcquireWriteAccess(); - bStatus = ( pAcc8 != NULL ); - } - - return bStatus; -} - -// ------------------------------------------------------------------------ - -BOOL GIFReader::ReadGlobalHeader() -{ - char pBuf[ 7 ]; - BYTE nRF; - BYTE nAspect; - BOOL bRet = FALSE; - - rIStm.Read( pBuf, 6 ); - if( NO_PENDING( rIStm ) ) - { - pBuf[ 6 ] = 0; - if( !strcmp( pBuf, "GIF87a" ) || !strcmp( pBuf, "GIF89a" ) ) - { - rIStm.Read( pBuf, 7 ); - if( NO_PENDING( rIStm ) ) - { - SvMemoryStream aMemStm; - - aMemStm.SetBuffer( pBuf, 7, FALSE, 7 ); - aMemStm >> nGlobalWidth; - aMemStm >> nGlobalHeight; - aMemStm >> nRF; - aMemStm >> nBackgroundColor; - aMemStm >> nAspect; - - bGlobalPalette = (BOOL) ( nRF & 0x80 ); - - if( bGlobalPalette ) - ReadPaletteEntries( &aGPalette, 1 << ( ( nRF & 7 ) + 1 ) ); - else - nBackgroundColor = 0; - - if( NO_PENDING( rIStm ) ) - bRet = TRUE; - } - } - else - bStatus = FALSE; - } - - return bRet; -} - -// ------------------------------------------------------------------------ - -void GIFReader::ReadPaletteEntries( BitmapPalette* pPal, ULONG nCount ) -{ - const ULONG nLen = 3UL * nCount; - BYTE* pBuf = new BYTE[ nLen ]; - - rIStm.Read( pBuf, nLen ); - if( NO_PENDING( rIStm ) ) - { - BYTE* pTmp = pBuf; - - for( ULONG i = 0UL; i < nCount; ) - { - BitmapColor& rColor = (*pPal)[ (USHORT) i++ ]; - - rColor.SetRed( *pTmp++ ); - rColor.SetGreen( *pTmp++ ); - rColor.SetBlue( *pTmp++ ); - } - - // nach Moeglichkeit noch einige Standardfarben unterbringen - if( nCount < 256UL ) - { - (*pPal)[ 255UL ] = Color( COL_WHITE ); - - if( nCount < 255UL ) - (*pPal)[ 254UL ] = Color( COL_BLACK ); - } - } - - delete[] pBuf; -} - -// ------------------------------------------------------------------------ - -BOOL GIFReader::ReadExtension() -{ - BYTE cFunction; - BYTE cSize; - BYTE cByte; - BOOL bRet = FALSE; - BOOL bOverreadDataBlocks = FALSE; - - // Extension-Label - rIStm >> cFunction; - if( NO_PENDING( rIStm ) ) - { - // Block-Laenge - rIStm >> cSize; - - switch( cFunction ) - { - // 'Graphic Control Extension' - case( 0xf9 ) : - { - BYTE cFlags; - - rIStm >> cFlags; - rIStm >> nTimer; - rIStm >> nGCTransparentIndex; - rIStm >> cByte; - - if ( NO_PENDING( rIStm ) ) - { - nGCDisposalMethod = ( cFlags >> 2) & 7; - bGCTransparent = ( cFlags & 1 ) ? TRUE : FALSE; - bStatus = ( cSize == 4 ) && ( cByte == 0 ); - bRet = TRUE; - } - } - break; - - // Application-Extension - case ( 0xff ) : - { - if ( NO_PENDING( rIStm ) ) - { - // default diese Extension ueberlesen - bOverreadDataBlocks = TRUE; - - // Appl.-Extension hat Laenge 11 - if ( cSize == 0x0b ) - { - ByteString aAppId; - ByteString aAppCode; - - rIStm.Read( aAppId.AllocBuffer( 8 ), 8 ); - rIStm.Read( aAppCode.AllocBuffer( 3 ), 3 ); - rIStm >> cSize; - - // NetScape-Extension - if( aAppId == "NETSCAPE" && aAppCode == "2.0" && cSize == 3 ) - { - rIStm >> cByte; - - // Loop-Extension - if ( cByte == 0x01 ) - { - rIStm >> cByte; - nLoops = cByte; - rIStm >> cByte; - nLoops |= ( (USHORT) cByte << 8 ); - rIStm >> cByte; - - bStatus = ( cByte == 0 ); - bRet = NO_PENDING( rIStm ); - bOverreadDataBlocks = FALSE; - - // Netscape interpretiert den LoopCount - // als reine Anzahl der _Wiederholungen_; - // bei uns ist es die Gesamtanzahl der - // Durchlaeufe - if( nLoops ) - nLoops++; - } - else - rIStm.SeekRel( -1 ); - } - else if ( aAppId == "STARDIV " && aAppCode == "5.0" && cSize == 9 ) - { - rIStm >> cByte; - - // Loop-Extension - if ( cByte == 0x01 ) - { - rIStm >> nLogWidth100 >> nLogHeight100; - rIStm >> cByte; - bStatus = ( cByte == 0 ); - bRet = NO_PENDING( rIStm ); - bOverreadDataBlocks = FALSE; - } - else - rIStm.SeekRel( -1 ); - } - - } - } - } - break; - - // alles andere ueberlesen - default: - bOverreadDataBlocks = TRUE; - break; - } - - // Sub-Blocks ueberlesen - if ( bOverreadDataBlocks ) - { - bRet = TRUE; - while( cSize && bStatus && !rIStm.IsEof() ) - { - USHORT nCount = (USHORT) cSize + 1; - char* pBuffer = new char[ nCount ]; - - bRet = FALSE; - rIStm.Read( pBuffer, nCount ); - if( NO_PENDING( rIStm ) ) - { - cSize = (BYTE) pBuffer[ cSize ]; - bRet = TRUE; - } - else - cSize = 0; - - delete[] pBuffer; - } - } - } - - return bRet; -} - -// ------------------------------------------------------------------------ - -BOOL GIFReader::ReadLocalHeader() -{ - BYTE pBuf[ 9 ]; - BOOL bRet = FALSE; - - rIStm.Read( pBuf, 9 ); - if( NO_PENDING( rIStm ) ) - { - SvMemoryStream aMemStm; - BitmapPalette* pPal; - BYTE nFlags; - - aMemStm.SetBuffer( (char*) pBuf, 9, FALSE, 9 ); - aMemStm >> nImagePosX; - aMemStm >> nImagePosY; - aMemStm >> nImageWidth; - aMemStm >> nImageHeight; - aMemStm >> nFlags; - - // Falls Interlaced, ersten Startwert vorgeben - bInterlaced = ( ( nFlags & 0x40 ) == 0x40 ); - nLastInterCount = 7; - nLastImageY = 0; - - if( nFlags & 0x80 ) - { - pPal = &aLPalette; - ReadPaletteEntries( pPal, 1 << ( (nFlags & 7 ) + 1 ) ); - } - else - pPal = &aGPalette; - - // Falls alles soweit eingelesen werden konnte, kann - // nun das lokale Bild angelegt werden; - // es wird uebergeben, ob der BackgroundColorIndex evtl. - // beruecksichtigt werden soll ( wenn Globale Farbtab. und - // diese auch fuer dieses Bild gilt ) - if( NO_PENDING( rIStm ) ) - { - CreateBitmaps( nImageWidth, nImageHeight, pPal, bGlobalPalette && ( pPal == &aGPalette ) ); - bRet = TRUE; - } - } - - return bRet; -} - -// ------------------------------------------------------------------------ - -ULONG GIFReader::ReadNextBlock() -{ - ULONG nRet = 0UL; - ULONG nRead; - BYTE cBlockSize; - - rIStm >> cBlockSize; - - if ( rIStm.IsEof() ) - nRet = 4UL; - else if ( NO_PENDING( rIStm ) ) - { - if ( cBlockSize == 0 ) - nRet = 2UL; - else - { - rIStm.Read( pSrcBuf, cBlockSize ); - - if( NO_PENDING( rIStm ) ) - { - if( bOverreadBlock ) - nRet = 3UL; - else - { - BOOL bEOI; - HPBYTE pTarget = pDecomp->DecompressBlock( pSrcBuf, cBlockSize, nRead, bEOI ); - - nRet = ( bEOI ? 3 : 1 ); - - if( nRead && !bOverreadBlock ) - FillImages( pTarget, nRead ); - - rtl_freeMemory( pTarget ); - } - } - } - } - - return nRet; -} - -// ------------------------------------------------------------------------ - -void GIFReader::FillImages( HPBYTE pBytes, ULONG nCount ) -{ - for( ULONG i = 0UL; i < nCount; i++ ) - { - if( nImageX >= nImageWidth ) - { - if( bInterlaced ) - { - long nT1, nT2; - - // falls Interlaced, werden die Zeilen kopiert - if( nLastInterCount ) - { - long nMinY = Min( (long) nLastImageY + 1, (long) nImageHeight - 1 ); - long nMaxY = Min( (long) nLastImageY + nLastInterCount, (long) nImageHeight - 1 ); - - // letzte gelesene Zeile kopieren, wenn Zeilen - // nicht zusanmmenfallen ( kommt vorm wenn wir am Ende des Bildes sind ) - if( ( nMinY > nLastImageY ) && ( nLastImageY < ( nImageHeight - 1 ) ) ) - { - HPBYTE pScanline8 = pAcc8->GetScanline( nYAcc ); - ULONG nSize8 = pAcc8->GetScanlineSize(); - HPBYTE pScanline1 = 0; - ULONG nSize1 = 0; - - if( bGCTransparent ) - { - pScanline1 = pAcc1->GetScanline( nYAcc ); - nSize1 = pAcc1->GetScanlineSize(); - } - - for( long j = nMinY; j <= nMaxY; j++ ) - { - memcpy( pAcc8->GetScanline( j ), pScanline8, nSize8 ); - - if( bGCTransparent ) - memcpy( pAcc1->GetScanline( j ), pScanline1, nSize1 ); - } - } - } - - nT1 = ( ++nImageY ) << 3; - nLastInterCount = 7; - - if( nT1 >= nImageHeight ) - { - nT2 = nImageY - ( ( nImageHeight + 7 ) >> 3 ); - nT1 = ( nT2 << 3 ) + 4; - nLastInterCount = 3; - - if( nT1 >= nImageHeight ) - { - nT2 -= ( nImageHeight + 3 ) >> 3; - nT1 = ( nT2 << 2 ) + 2; - nLastInterCount = 1; - - if( nT1 >= nImageHeight ) - { - nT2 -= ( nImageHeight + 1 ) >> 2; - nT1 = ( nT2 << 1 ) + 1; - nLastInterCount = 0; - } - } - } - - nLastImageY = (USHORT) nT1; - nYAcc = nT1; - } - else - { - nLastImageY = ++nImageY; - nYAcc = nImageY; - } - - // Zeile faengt von vorne an - nImageX = 0; - } - - if( nImageY < nImageHeight ) - { - const BYTE cTmp = pBytes[ i ]; - - if( bGCTransparent ) - { - if( cTmp == nGCTransparentIndex ) - pAcc1->SetPixel( nYAcc, nImageX++, cTransIndex1 ); - else - { - pAcc8->SetPixel( nYAcc, nImageX, cTmp ); - pAcc1->SetPixel( nYAcc, nImageX++, cNonTransIndex1 ); - } - } - else - pAcc8->SetPixel( nYAcc, nImageX++, cTmp ); - } - else - { - bOverreadBlock = TRUE; - break; - } - } -} - -// ------------------------------------------------------------------------ - -void GIFReader::CreateNewBitmaps() -{ - AnimationBitmap aAnimBmp; - - aBmp8.ReleaseAccess( pAcc8 ); - pAcc8 = NULL; - - if( bGCTransparent ) - { - aBmp1.ReleaseAccess( pAcc1 ); - pAcc1 = NULL; - aAnimBmp.aBmpEx = BitmapEx( aBmp8, aBmp1 ); - } - else - aAnimBmp.aBmpEx = BitmapEx( aBmp8 ); - - aAnimBmp.aPosPix = Point( nImagePosX, nImagePosY ); - aAnimBmp.aSizePix = Size( nImageWidth, nImageHeight ); - aAnimBmp.nWait = ( nTimer != 65535 ) ? nTimer : ANIMATION_TIMEOUT_ON_CLICK; - aAnimBmp.bUserInput = FALSE; - - if( nGCDisposalMethod == 2 ) - aAnimBmp.eDisposal = DISPOSE_BACK; - else if( nGCDisposalMethod == 3 ) - aAnimBmp.eDisposal = DISPOSE_PREVIOUS; - else - aAnimBmp.eDisposal = DISPOSE_NOT; - - aAnimation.Insert( aAnimBmp ); - - if( aAnimation.Count() == 1 ) - { - aAnimation.SetDisplaySizePixel( Size( nGlobalWidth, nGlobalHeight ) ); - aAnimation.SetLoopCount( nLoops ); - } -} - -// ------------------------------------------------------------------------ - -const Graphic& GIFReader::GetIntermediateGraphic() -{ - // Intermediate-Graphic nur erzeugen, wenn schon - // Daten vorliegen, aber die Graphic noch nicht - // vollstaendig eingelesen wurde - if ( bImGraphicReady && !aAnimation.Count() ) - { - Bitmap aBmp; - - aBmp8.ReleaseAccess( pAcc8 ); - - if ( bGCTransparent ) - { - aBmp1.ReleaseAccess( pAcc1 ); - aImGraphic = BitmapEx( aBmp8, aBmp1 ); - - pAcc1 = aBmp1.AcquireWriteAccess(); - bStatus = bStatus && ( pAcc1 != NULL ); - } - else - aImGraphic = aBmp8; - - pAcc8 = aBmp8.AcquireWriteAccess(); - bStatus = bStatus && ( pAcc8 != NULL ); - } - - return aImGraphic; -} - -// ------------------------------------------------------------------------ - -BOOL GIFReader::ProcessGIF() -{ - BOOL bRead = FALSE; - BOOL bEnd = FALSE; - - if ( !bStatus ) - eActAction = ABORT_READING; - - // Stream an die richtige Stelle bringen - rIStm.Seek( nLastPos ); - - switch( eActAction ) - { - // naechsten Marker lesen - case( MARKER_READING ): - { - BYTE cByte; - - rIStm >> cByte; - - if( rIStm.IsEof() ) - eActAction = END_READING; - else if( NO_PENDING( rIStm ) ) - { - bRead = TRUE; - - if( cByte == '!' ) - eActAction = EXTENSION_READING; - else if( cByte == ',' ) - eActAction = LOCAL_HEADER_READING; - else if( cByte == ';' ) - eActAction = END_READING; - else - eActAction = ABORT_READING; - } - } - break; - - // ScreenDescriptor lesen - case( GLOBAL_HEADER_READING ): - { - if( ( bRead = ReadGlobalHeader() ) == TRUE ) - { - ClearImageExtensions(); - eActAction = MARKER_READING; - } - } - break; - - - // Extension lesen - case( EXTENSION_READING ): - { - if( ( bRead = ReadExtension() ) == TRUE ) - eActAction = MARKER_READING; - } - break; - - - // Image-Descriptor lesen - case( LOCAL_HEADER_READING ): - { - if( ( bRead = ReadLocalHeader() ) == TRUE ) - { - nYAcc = nImageX = nImageY = 0; - eActAction = FIRST_BLOCK_READING; - } - } - break; - - - // ersten Datenblock lesen - case( FIRST_BLOCK_READING ): - { - BYTE cDataSize; - - rIStm >> cDataSize; - - if( rIStm.IsEof() ) - eActAction = ABORT_READING; - else if( cDataSize > 12 ) - bStatus = FALSE; - else if( NO_PENDING( rIStm ) ) - { - bRead = TRUE; - pDecomp = new GIFLZWDecompressor( cDataSize ); - eActAction = NEXT_BLOCK_READING; - bOverreadBlock = FALSE; - } - else - eActAction = FIRST_BLOCK_READING; - } - break; - - // naechsten Datenblock lesen - case( NEXT_BLOCK_READING ): - { - USHORT nLastX = nImageX; - USHORT nLastY = nImageY; - ULONG nRet = ReadNextBlock(); - - // Return: 0:Pending / 1:OK; / 2:OK und letzter Block: / 3:EOI / 4:HardAbort - if( nRet ) - { - bRead = TRUE; - - if ( nRet == 1UL ) - { - bImGraphicReady = TRUE; - eActAction = NEXT_BLOCK_READING; - bOverreadBlock = FALSE; - } - else - { - if( nRet == 2UL ) - { - delete pDecomp; - CreateNewBitmaps(); - eActAction = MARKER_READING; - ClearImageExtensions(); - } - else if( nRet == 3UL ) - { - eActAction = NEXT_BLOCK_READING; - bOverreadBlock = TRUE; - } - else - { - delete pDecomp; - CreateNewBitmaps(); - eActAction = ABORT_READING; - ClearImageExtensions(); - } - } - } - else - { - nImageX = nLastX; - nImageY = nLastY; - } - } - break; - - // ein Fehler trat auf - case( ABORT_READING ): - { - bEnd = TRUE; - eActAction = END_READING; - } - break; - - default: - break; - } - - // Stream an die richtige Stelle bringen, - // falls Daten gelesen werden konnten - // entweder alte Position oder aktuelle Position - if( bRead || bEnd ) - nLastPos = rIStm.Tell(); - - return bRead; -} - -// ------------------------------------------------------------------------ - -ReadState GIFReader::ReadGIF( Graphic& rGraphic ) -{ - ReadState eReadState; - - bStatus = TRUE; - - while( ProcessGIF() && ( eActAction != END_READING ) ) {} - - if( !bStatus ) - eReadState = GIFREAD_ERROR; - else if( eActAction == END_READING ) - eReadState = GIFREAD_OK; - else - { - if ( rIStm.GetError() == ERRCODE_IO_PENDING ) - rIStm.ResetError(); - - eReadState = GIFREAD_NEED_MORE; - } - - if( aAnimation.Count() == 1 ) - { - rGraphic = aAnimation.Get( 0 ).aBmpEx; - - if( nLogWidth100 && nLogHeight100 ) - { - rGraphic.SetPrefSize( Size( nLogWidth100, nLogHeight100 ) ); - rGraphic.SetPrefMapMode( MAP_100TH_MM ); - } - } - else - rGraphic = aAnimation; - - return eReadState; -} - - -// ------------- -// - ImportGIF - -// ------------- - -BOOL ImportGIF( SvStream & rStm, Graphic& rGraphic ) -{ - GIFReader* pGIFReader = (GIFReader*) rGraphic.GetContext(); - USHORT nOldFormat = rStm.GetNumberFormatInt(); - ReadState eReadState; - BOOL bRet = TRUE; - - rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); - - if( !pGIFReader ) - pGIFReader = new GIFReader( rStm ); - - rGraphic.SetContext( NULL ); - eReadState = pGIFReader->ReadGIF( rGraphic ); - - if( eReadState == GIFREAD_ERROR ) - { - bRet = FALSE; - delete pGIFReader; - } - else if( eReadState == GIFREAD_OK ) - delete pGIFReader; - else - { - rGraphic = pGIFReader->GetIntermediateGraphic(); - rGraphic.SetContext( pGIFReader ); - } - - rStm.SetNumberFormatInt( nOldFormat ); - - return bRet; -} diff --git a/svtools/source/filter.vcl/ixbm/xbmread.cxx b/svtools/source/filter.vcl/ixbm/xbmread.cxx deleted file mode 100644 index 9c7faaafa88c..000000000000 --- a/svtools/source/filter.vcl/ixbm/xbmread.cxx +++ /dev/null @@ -1,398 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#define XBMMINREAD 512 - -#define _XBMPRIVATE -#include -#include "xbmread.hxx" - -// ------------- -// - XBMReader - -// ------------- - -XBMReader::XBMReader( SvStream& rStm ) : - rIStm ( rStm ), - pAcc1 ( NULL ), - nLastPos ( rStm.Tell() ), - nWidth ( 0 ), - nHeight ( 0 ), - bStatus ( TRUE ) -{ - pHexTable = new short[ 256 ]; - maUpperName = String::CreateFromAscii( "SVIXBM", 6 ); - InitTable(); -} - -// ------------------------------------------------------------------------ - -XBMReader::~XBMReader() -{ - delete[] pHexTable; - - if( pAcc1 ) - aBmp1.ReleaseAccess( pAcc1 ); -} - -// ------------------------------------------------------------------------ - -void XBMReader::InitTable() -{ - memset( pHexTable, 0, sizeof( short ) ); - - pHexTable['0'] = 0; - pHexTable['1'] = 1; - pHexTable['2'] = 2; - pHexTable['3'] = 3; - pHexTable['4'] = 4; - pHexTable['5'] = 5; - pHexTable['6'] = 6; - pHexTable['7'] = 7; - pHexTable['8'] = 8; - pHexTable['9'] = 9; - pHexTable['A'] = 10; - pHexTable['B'] = 11; - pHexTable['C'] = 12; - pHexTable['D'] = 13; - pHexTable['E'] = 14; - pHexTable['F'] = 15; - pHexTable['X'] = 0; - pHexTable['a'] = 10; - pHexTable['b'] = 11; - pHexTable['c'] = 12; - pHexTable['d'] = 13; - pHexTable['e'] = 14; - pHexTable['f'] = 15; - pHexTable['x'] = 0; - pHexTable[' '] = -1; - pHexTable[','] = -1; - pHexTable['}'] = -1; - pHexTable['\n'] = -1; - pHexTable['\t'] = -1; - pHexTable['\0'] = -1; -} - -// ------------------------------------------------------------------------ - -ByteString XBMReader::FindTokenLine( SvStream* pInStm, const char* pTok1, - const char* pTok2, const char* pTok3 ) -{ - ByteString aRet; - long nPos1; - long nPos2; - long nPos3; - - bStatus = FALSE; - - do - { - if( !pInStm->ReadLine( aRet ) ) - break; - - if( pTok1 ) - { - if( ( nPos1 = aRet.Search( pTok1 ) ) != STRING_NOTFOUND ) - { - bStatus = TRUE; - - if( pTok2 ) - { - bStatus = FALSE; - - if( ( ( nPos2 = aRet.Search( pTok2 ) ) != STRING_NOTFOUND ) && - ( nPos2 > nPos1 ) ) - { - bStatus = TRUE; - - if( pTok3 ) - { - bStatus = FALSE; - - if( ( ( nPos3 = aRet.Search( pTok3 ) ) != STRING_NOTFOUND ) && ( nPos3 > nPos2 ) ) - bStatus = TRUE; - } - } - } - } - } - } - while( !bStatus ); - - return aRet; -} - -// ------------------------------------------------------------------------ - -long XBMReader::ParseDefine( const sal_Char* pDefine ) -{ - long nRet = 0; - char* pTmp = (char*) pDefine; - unsigned char cTmp; - - // bis zum Ende gehen - pTmp += ( strlen( pDefine ) - 1 ); - cTmp = *pTmp--; - - // letzte Ziffer suchen - while( pHexTable[ cTmp ] == -1 ) - cTmp = *pTmp--; - - // bis vor die Zahl laufen - while( pHexTable[ cTmp ] != -1 ) - cTmp = *pTmp--; - - // auf Anfang der Zahl gehen - pTmp += 2; - - // Hex lesen - if( ( pTmp[0] == '0' ) && ( ( pTmp[1] == 'X' ) || ( pTmp[1] == 'x' ) ) ) - { - pTmp += 2; - cTmp = *pTmp++; - - while ( pHexTable[ cTmp ] != -1 ) - { - nRet = ( nRet << 4 ) + pHexTable[ cTmp ]; - cTmp = *pTmp++; - } - } - // Dezimal lesen - else - { - cTmp = *pTmp++; - while( ( cTmp >= '0' ) && ( cTmp <= '9' ) ) - { - nRet = nRet * 10 + ( cTmp - '0' ); - cTmp = *pTmp++; - } - } - - return nRet; -} - -// ------------------------------------------------------------------------ - -BOOL XBMReader::ParseData( SvStream* pInStm, const ByteString& aLastLine, XBMFormat eFormat ) -{ - ByteString aLine; - long nRow = 0; - long nCol = 0; - long nBits = ( eFormat == XBM10 ) ? 16 : 8; - long nBit; - USHORT nValue; - USHORT nDigits; - BOOL bFirstLine = TRUE; - - while( nRow < nHeight ) - { - if( bFirstLine ) - { - xub_StrLen nPos; - - // einfuehrende geschweifte Klammer loeschen - if( (nPos = ( aLine = aLastLine ).Search( '{' ) ) != STRING_NOTFOUND ) - aLine.Erase( 0, nPos + 1 ); - - bFirstLine = FALSE; - } - else if( !pInStm->ReadLine( aLine ) ) - break; - - if( aLine.Len() ) - { - const USHORT nCount = aLine.GetTokenCount( ',' ); - - for( USHORT i = 0; ( i < nCount ) && ( nRow < nHeight ); i++ ) - { - const ByteString aToken( aLine.GetToken( i, ',' ) ); - const xub_StrLen nLen = aToken.Len(); - BOOL bProcessed = FALSE; - - nBit = nDigits = nValue = 0; - - for( xub_StrLen n = 0UL; n < nLen; n++ ) - { - const unsigned char cChar = aToken.GetChar( n ); - const short nTable = pHexTable[ cChar ]; - - if( isxdigit( cChar ) || !nTable ) - { - nValue = ( nValue << 4 ) + nTable; - nDigits++; - bProcessed = TRUE; - } - else if( ( nTable < 0 ) && nDigits ) - { - bProcessed = TRUE; - break; - } - } - - if( bProcessed ) - { - while( ( nCol < nWidth ) && ( nBit < nBits ) ) - pAcc1->SetPixel( nRow, nCol++, ( nValue & ( 1 << nBit++ ) ) ? aBlack : aWhite ); - - if( nCol == nWidth ) - nCol = 0, nRow++; - } - } - } - } - - return TRUE; -} - -// ------------------------------------------------------------------------ - -ReadState XBMReader::ReadXBM( Graphic& rGraphic ) -{ - ReadState eReadState; - BYTE cDummy; - - // sehen, ob wir _alles_ lesen koennen - rIStm.Seek( STREAM_SEEK_TO_END ); - rIStm >> cDummy; - - // falls wir nicht alles lesen koennen - // kehren wir zurueck und warten auf neue Daten - if ( rIStm.GetError() != ERRCODE_IO_PENDING ) - { - ByteString aLine; - int nValue; - - rIStm.Seek( nLastPos ); - bStatus = FALSE; - aLine = FindTokenLine( &rIStm, "#define", "_width" ); - - if ( bStatus ) - { - if ( ( nValue = (int) ParseDefine( aLine.GetBuffer() ) ) > 0 ) - { - nWidth = nValue; - aLine = FindTokenLine( &rIStm, "#define", "_height" ); - - // Falls die Hoehe nicht folgt, suchen wir noch - // einmal vom Anfang der Datei an - if ( !bStatus ) - { - rIStm.Seek( nLastPos ); - aLine = FindTokenLine( &rIStm, "#define", "_height" ); - } - } - else - bStatus = FALSE; - - if ( bStatus ) - { - if ( ( nValue = (int) ParseDefine( aLine.GetBuffer() ) ) > 0 ) - { - nHeight = nValue; - aLine = FindTokenLine( &rIStm, "static", "_bits" ); - - if ( bStatus ) - { - XBMFormat eFormat = XBM10; - - if ( aLine.Search( "short" ) != STRING_NOTFOUND ) - eFormat = XBM10; - else if ( aLine.Search( "char" ) != STRING_NOTFOUND ) - eFormat = XBM11; - else - bStatus = FALSE; - - if ( bStatus && nWidth && nHeight ) - { - aBmp1 = Bitmap( Size( nWidth, nHeight ), 1 ); - pAcc1 = aBmp1.AcquireWriteAccess(); - - if( pAcc1 ) - { - aWhite = pAcc1->GetBestMatchingColor( Color( COL_WHITE ) ); - aBlack = pAcc1->GetBestMatchingColor( Color( COL_BLACK ) ); - bStatus = ParseData( &rIStm, aLine, eFormat ); - } - else - bStatus = FALSE; - } - } - } - } - } - - if( bStatus ) - { - Bitmap aBlackBmp( Size( pAcc1->Width(), pAcc1->Height() ), 1 ); - - aBmp1.ReleaseAccess( pAcc1 ), pAcc1 = NULL; - aBlackBmp.Erase( Color( COL_BLACK ) ); - rGraphic = BitmapEx( aBlackBmp, aBmp1 ); - eReadState = XBMREAD_OK; - } - else - eReadState = XBMREAD_ERROR; - } - else - { - rIStm.ResetError(); - eReadState = XBMREAD_NEED_MORE; - } - - return eReadState; -} - -// ------------- -// - ImportXBM - -// ------------- - -BOOL ImportXBM( SvStream& rStm, Graphic& rGraphic ) -{ - XBMReader* pXBMReader = (XBMReader*) rGraphic.GetContext(); - ReadState eReadState; - BOOL bRet = TRUE; - - if( !pXBMReader ) - pXBMReader = new XBMReader( rStm ); - - rGraphic.SetContext( NULL ); - eReadState = pXBMReader->ReadXBM( rGraphic ); - - if( eReadState == XBMREAD_ERROR ) - { - bRet = FALSE; - delete pXBMReader; - } - else if( eReadState == XBMREAD_OK ) - delete pXBMReader; - else - rGraphic.SetContext( pXBMReader ); - - return bRet; -} diff --git a/svtools/source/filter.vcl/ixpm/rgbtable.hxx b/svtools/source/filter.vcl/ixpm/rgbtable.hxx deleted file mode 100644 index afdab883b369..000000000000 --- a/svtools/source/filter.vcl/ixpm/rgbtable.hxx +++ /dev/null @@ -1,695 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -struct XPMRGBTab -{ - const char* name; - BYTE red; - BYTE green; - BYTE blue; -}; - -static XPMRGBTab pRGBTable[] = { -{ "white", 255, 255, 255 }, -{ "black", 0, 0, 0 }, -{ "snow", 255, 250, 250 }, -{ "GhostWhite", 248, 248, 255 }, -{ "WhiteSmoke", 245, 245, 245 }, -{ "gainsboro", 220, 220, 220 }, -{ "FloralWhite", 255, 250, 240 }, -{ "OldLace", 253, 245, 230 }, -{ "linen", 250, 240, 230 }, -{ "AntiqueWhite", 250, 235, 215 }, -{ "PapayaWhip", 255, 239, 213 }, -{ "BlanchedAlmond", 255, 235, 205 }, -{ "bisque", 255, 228, 196 }, -{ "PeachPuff", 255, 218, 185 }, -{ "NavajoWhite", 255, 222, 173 }, -{ "moccasin", 255, 228, 181 }, -{ "cornsilk", 255, 248, 220 }, -{ "ivory", 255, 255, 240 }, -{ "LemonChiffon", 255, 250, 205 }, -{ "seashell", 255, 245, 238 }, -{ "honeydew", 240, 255, 240 }, -{ "MintCream", 245, 255, 250 }, -{ "azure", 240, 255, 255 }, -{ "AliceBlue", 240, 248, 255 }, -{ "lavender", 230, 230, 250 }, -{ "LavenderBlush", 255, 240, 245 }, -{ "MistyRose", 255, 228, 225 }, -{ "DarkSlateGray", 47, 79, 79 }, -{ "DarkSlateGrey", 47, 79, 79 }, -{ "DimGray", 105, 105, 105 }, -{ "DimGrey", 105, 105, 105 }, -{ "SlateGray", 112, 128, 144 }, -{ "SlateGrey", 112, 128, 144 }, -{ "LightSlateGray", 119, 136, 153 }, -{ "LightSlateGrey", 119, 136, 153 }, -{ "gray", 190, 190, 190 }, -{ "grey", 190, 190, 190 }, -{ "LightGrey", 211, 211, 211 }, -{ "LightGray", 211, 211, 211 }, -{ "MidnightBlue", 25, 25, 112 }, -{ "navy", 0, 0, 128 }, -{ "NavyBlue", 0, 0, 128 }, -{ "CornflowerBlue", 100, 149, 237 }, -{ "DarkSlateBlue", 72, 61, 139 }, -{ "SlateBlue", 106, 90, 205 }, -{ "MediumSlateBlue", 123, 104, 238 }, -{ "LightSlateBlue", 132, 112, 255 }, -{ "MediumBlue", 0, 0, 205 }, -{ "RoyalBlue", 65, 105, 225 }, -{ "blue", 0, 0, 255 }, -{ "DodgerBlue", 30, 144, 255 }, -{ "DeepSkyBlue", 0, 191, 255 }, -{ "SkyBlue", 135, 206, 235 }, -{ "LightSkyBlue", 135, 206, 250 }, -{ "SteelBlue", 70, 130, 180 }, -{ "LightSteelBlue", 176, 196, 222 }, -{ "LightBlue", 173, 216, 230 }, -{ "PowderBlue", 176, 224, 230 }, -{ "PaleTurquoise", 175, 238, 238 }, -{ "DarkTurquoise", 0, 206, 209 }, -{ "MediumTurquoise", 72, 209, 204 }, -{ "turquoise", 64, 224, 208 }, -{ "cyan", 0, 255, 255 }, -{ "LightCyan", 224, 255, 255 }, -{ "CadetBlue", 95, 158, 160 }, -{ "MediumAquamarine", 102, 205, 170 }, -{ "aquamarine", 127, 255, 212 }, -{ "DarkGreen", 0, 100, 0 }, -{ "DarkOliveGreen", 85, 107, 47 }, -{ "DarkSeaGreen", 143, 188, 143 }, -{ "SeaGreen", 46, 139, 87 }, -{ "MediumSeaGreen", 60, 179, 113 }, -{ "LightSeaGreen", 32, 178, 170 }, -{ "PaleGreen", 152, 251, 152 }, -{ "SpringGreen", 0, 255, 127 }, -{ "LawnGreen", 124, 252, 0 }, -{ "green", 0, 255, 0 }, -{ "chartreuse", 127, 255, 0 }, -{ "MediumSpringGreen", 0, 250, 154 }, -{ "GreenYellow", 173, 255 , 47 }, -{ "LimeGreen", 50, 205, 50 }, -{ "YellowGreen", 154, 205, 50 }, -{ "ForestGreen", 34, 139, 34 }, -{ "OliveDrab", 107, 142, 35 }, -{ "DarkKhaki", 189, 183, 107 }, -{ "khaki", 240, 230, 140 }, -{ "PaleGoldenrod", 238, 232, 170 }, -{ "LightGoldenrodYellow", 250, 250, 210 }, -{ "LightYellow", 255, 255, 224 }, -{ "yellow", 255, 255, 0 }, -{ "gold", 255, 215, 0 }, -{ "LightGoldenrod", 238, 221, 130 }, -{ "goldenrod", 218, 165, 32 }, -{ "DarkGoldenrod", 184, 134, 11 }, -{ "RosyBrown", 188, 143, 143 }, -{ "IndianRed", 205, 92, 92 }, -{ "SaddleBrown", 139, 69, 19 }, -{ "sienna", 160, 82, 45 }, -{ "peru", 205, 133, 63 }, -{ "burlywood", 222, 184, 135 }, -{ "beige", 245, 245, 220 }, -{ "wheat", 245, 222, 179 }, -{ "SandyBrown", 244, 164, 96 }, -{ "tan", 210, 180, 140 }, -{ "chocolate", 210, 105, 30 }, -{ "firebrick", 178, 34, 34 }, -{ "brown", 165, 42, 42 }, -{ "DarkSalmon", 233, 150, 122 }, -{ "salmon", 250, 128, 114 }, -{ "LightSalmon", 255, 160, 122 }, -{ "orange", 255, 165, 0 }, -{ "DarkOrange", 255, 140, 0 }, -{ "coral", 255, 127, 80 }, -{ "LightCoral", 240, 128, 128 }, -{ "tomato", 255, 99, 71 }, -{ "OrangeRed", 255, 69, 0 }, -{ "red", 255, 0, 0 }, -{ "HotPink", 255, 105, 180 }, -{ "DeepPink", 255, 20, 147 }, -{ "pink", 255, 192, 203 }, -{ "LightPink", 255, 182, 193 }, -{ "PaleVioletRed", 219, 112, 147 }, -{ "maroon", 176, 48, 96 }, -{ "MediumVioletRed", 199, 21, 133 }, -{ "VioletRed", 208, 32, 144 }, -{ "magenta", 255, 0, 255 }, -{ "violet", 238, 130, 238 }, -{ "plum", 221, 160, 221 }, -{ "orchid", 218, 112, 214 }, -{ "MediumOrchid", 186, 85, 211 }, -{ "DarkOrchid", 153, 50, 204 }, -{ "DarkViolet", 148, 0, 211 }, -{ "BlueViolet", 138, 43, 226 }, -{ "purple", 160, 32, 240 }, -{ "MediumPurple", 147, 112, 219 }, -{ "thistle", 216, 191, 216 }, -{ "snow1", 255, 250, 250 }, -{ "snow2", 238, 233, 233 }, -{ "snow3", 205, 201, 201 }, -{ "snow4", 139, 137, 137 }, -{ "seashell1", 255, 245, 238 }, -{ "seashell2", 238, 229, 222 }, -{ "seashell3", 205, 197, 191 }, -{ "seashell4", 139, 134, 130 }, -{ "AntiqueWhite1", 255, 239, 219 }, -{ "AntiqueWhite2", 238, 223, 204 }, -{ "AntiqueWhite3", 205, 192, 176 }, -{ "AntiqueWhite4", 139, 131, 120 }, -{ "bisque1", 255, 228, 196 }, -{ "bisque2", 238, 213, 183 }, -{ "bisque3", 205, 183, 158 }, -{ "bisque4", 139, 125, 107 }, -{ "PeachPuff1", 255, 218, 185 }, -{ "PeachPuff2", 238, 203, 173 }, -{ "PeachPuff3", 205, 175, 149 }, -{ "PeachPuff4", 139, 119, 101 }, -{ "NavajoWhite1", 255, 222, 173 }, -{ "NavajoWhite2", 238, 207, 161 }, -{ "NavajoWhite3", 205, 179, 139 }, -{ "NavajoWhite4", 139, 121, 94 }, -{ "LemonChiffon1", 255, 250, 205 }, -{ "LemonChiffon2", 238, 233, 191 }, -{ "LemonChiffon3", 205, 201, 165 }, -{ "LemonChiffon4", 139, 137, 112 }, -{ "cornsilk1", 255, 248, 220 }, -{ "cornsilk2", 238, 232, 205 }, -{ "cornsilk3", 205, 200, 177 }, -{ "cornsilk4", 139, 136, 120 }, -{ "ivory1", 255, 255, 240 }, -{ "ivory2", 238, 238, 224 }, -{ "ivory3", 205, 205, 193 }, -{ "ivory4", 139, 139, 131 }, -{ "honeydew1", 240, 255, 240 }, -{ "honeydew2", 224, 238, 224 }, -{ "honeydew3", 193, 205, 193 }, -{ "honeydew4", 131, 139, 131 }, -{ "LavenderBlush1", 255, 240, 245 }, -{ "LavenderBlush2", 238, 224, 229 }, -{ "LavenderBlush3", 205, 193, 197 }, -{ "LavenderBlush4", 139, 131, 134 }, -{ "MistyRose1", 255, 228, 225 }, -{ "MistyRose2", 238, 213, 210 }, -{ "MistyRose3", 205, 183, 181 }, -{ "MistyRose4", 139, 125, 123 }, -{ "azure1", 240, 255, 255 }, -{ "azure2", 224, 238, 238 }, -{ "azure3", 193, 205, 205 }, -{ "azure4", 131, 139, 139 }, -{ "SlateBlue1", 131, 111, 255 }, -{ "SlateBlue2", 122, 103, 238 }, -{ "SlateBlue3", 105, 89, 205 }, -{ "SlateBlue4", 71, 60, 139 }, -{ "RoyalBlue1", 72, 118, 255 }, -{ "RoyalBlue2", 67, 110, 238 }, -{ "RoyalBlue3", 58, 95, 205 }, -{ "RoyalBlue4", 39, 64, 139 }, -{ "blue1", 0, 0, 255 }, -{ "blue2", 0, 0, 238 }, -{ "blue3", 0, 0, 205 }, -{ "blue4", 0, 0, 139 }, -{ "DodgerBlue1", 30, 144, 255 }, -{ "DodgerBlue2", 28, 134, 238 }, -{ "DodgerBlue3", 24, 116, 205 }, -{ "DodgerBlue4", 16, 78, 139 }, -{ "SteelBlue1", 99, 184, 255 }, -{ "SteelBlue2", 92, 172, 238 }, -{ "SteelBlue3", 79, 148, 205 }, -{ "SteelBlue4", 54, 100, 139 }, -{ "DeepSkyBlue1", 0, 191, 255 }, -{ "DeepSkyBlue2", 0, 178, 238 }, -{ "DeepSkyBlue3", 0, 154, 205 }, -{ "DeepSkyBlue4", 0, 104, 139 }, -{ "SkyBlue1", 135, 206, 255 }, -{ "SkyBlue2", 126, 192, 238 }, -{ "SkyBlue3", 108, 166, 205 }, -{ "SkyBlue4", 74, 112, 139 }, -{ "LightSkyBlue1", 176, 226, 255 }, -{ "LightSkyBlue2", 164, 211, 238 }, -{ "LightSkyBlue3", 141, 182, 205 }, -{ "LightSkyBlue4", 96, 123, 139 }, -{ "SlateGray1", 198, 226, 255 }, -{ "SlateGray2", 185, 211, 238 }, -{ "SlateGray3", 159, 182, 205 }, -{ "SlateGray4", 108, 123, 139 }, -{ "LightSteelBlue1", 202, 225, 255 }, -{ "LightSteelBlue2", 188, 210, 238 }, -{ "LightSteelBlue3", 162, 181, 205 }, -{ "LightSteelBlue4", 110, 123, 139 }, -{ "LightBlue1", 191, 239, 255 }, -{ "LightBlue2", 178, 223, 238 }, -{ "LightBlue3", 154, 192, 205 }, -{ "LightBlue4", 104, 131, 139 }, -{ "LightCyan1", 224, 255, 255 }, -{ "LightCyan2", 209, 238, 238 }, -{ "LightCyan3", 180, 205, 205 }, -{ "LightCyan4", 122, 139, 139 }, -{ "PaleTurquoise1", 187, 255, 255 }, -{ "PaleTurquoise2", 174, 238, 238 }, -{ "PaleTurquoise3", 150, 205, 205 }, -{ "PaleTurquoise4", 102, 139, 139 }, -{ "CadetBlue1", 152, 245, 255 }, -{ "CadetBlue2", 142, 229, 238 }, -{ "CadetBlue3", 122, 197, 205 }, -{ "CadetBlue4", 83, 134, 139 }, -{ "turquoise1", 0, 245, 255 }, -{ "turquoise2", 0, 229, 238 }, -{ "turquoise3", 0, 197, 205 }, -{ "turquoise4", 0, 134, 139 }, -{ "cyan1", 0, 255, 255 }, -{ "cyan2", 0, 238, 238 }, -{ "cyan3", 0, 205, 205 }, -{ "cyan4", 0, 139, 139 }, -{ "DarkSlateGray1", 151, 255, 255 }, -{ "DarkSlateGray2", 141, 238, 238 }, -{ "DarkSlateGray3", 121, 205, 205 }, -{ "DarkSlateGray4", 82, 139, 139 }, -{ "aquamarine1", 127, 255, 212 }, -{ "aquamarine2", 118, 238, 198 }, -{ "aquamarine3", 102, 205, 170 }, -{ "aquamarine4", 69, 139, 116 }, -{ "DarkSeaGreen1", 193, 255, 193 }, -{ "DarkSeaGreen2", 180, 238, 180 }, -{ "DarkSeaGreen3", 155, 205, 155 }, -{ "DarkSeaGreen4", 105, 139, 105 }, -{ "SeaGreen1", 84, 255, 159 }, -{ "SeaGreen2", 78, 238, 148 }, -{ "SeaGreen3", 67, 205, 128 }, -{ "SeaGreen4", 46, 139, 87 }, -{ "PaleGreen1", 154, 255, 154 }, -{ "PaleGreen2", 144, 238, 144 }, -{ "PaleGreen3", 124, 205, 124 }, -{ "PaleGreen4", 84, 139, 84 }, -{ "SpringGreen1", 0, 255, 127 }, -{ "SpringGreen2", 0, 238, 118 }, -{ "SpringGreen3", 0, 205, 102 }, -{ "SpringGreen4", 0, 139, 69 }, -{ "green1", 0, 255, 0 }, -{ "green2", 0, 238, 0 }, -{ "green3", 0, 205, 0 }, -{ "green4", 0, 139, 0 }, -{ "chartreuse1", 127, 255, 0 }, -{ "chartreuse2", 118, 238, 0 }, -{ "chartreuse3", 102, 205, 0 }, -{ "chartreuse4", 69, 139, 0 }, -{ "OliveDrab1", 192, 255, 62 }, -{ "OliveDrab2", 179, 238, 58 }, -{ "OliveDrab3", 154, 205, 50 }, -{ "OliveDrab4", 105, 139, 34 }, -{ "DarkOliveGreen1", 202, 255, 112 }, -{ "DarkOliveGreen2", 188, 238, 104 }, -{ "DarkOliveGreen3", 162, 205, 90 }, -{ "DarkOliveGreen4", 110, 139, 61 }, -{ "khaki1", 255, 246, 143 }, -{ "khaki2", 238, 230, 133 }, -{ "khaki3", 205, 198, 115 }, -{ "khaki4", 139, 134, 78 }, -{ "LightGoldenrod1", 255, 236, 139 }, -{ "LightGoldenrod2", 238, 220, 130 }, -{ "LightGoldenrod3", 205, 190, 112 }, -{ "LightGoldenrod4", 139, 129, 76 }, -{ "LightYellow1", 255, 255, 224 }, -{ "LightYellow2", 238, 238, 209 }, -{ "LightYellow3", 205, 205, 180 }, -{ "LightYellow4", 139, 139, 122 }, -{ "yellow1", 255, 255, 0 }, -{ "yellow2", 238, 238, 0 }, -{ "yellow3", 205, 205, 0 }, -{ "yellow4", 139, 139, 0 }, -{ "gold1", 255, 215, 0 }, -{ "gold2", 238, 201, 0 }, -{ "gold3", 205, 173, 0 }, -{ "gold4", 139, 117, 0 }, -{ "goldenrod1", 255, 193, 37 }, -{ "goldenrod2", 238, 180, 34 }, -{ "goldenrod3", 205, 155, 29 }, -{ "goldenrod4", 139, 105, 20 }, -{ "DarkGoldenrod1", 255, 185, 15 }, -{ "DarkGoldenrod2", 238, 173, 14 }, -{ "DarkGoldenrod3", 205, 149, 12 }, -{ "DarkGoldenrod4", 139, 101, 8 }, -{ "RosyBrown1", 255, 193, 193 }, -{ "RosyBrown2", 238, 180, 180 }, -{ "RosyBrown3", 205, 155, 155 }, -{ "RosyBrown4", 139, 105, 105 }, -{ "IndianRed1", 255, 106, 106 }, -{ "IndianRed2", 238, 99, 99 }, -{ "IndianRed3", 205, 85, 85 }, -{ "IndianRed4", 139, 58, 58 }, -{ "sienna1", 255, 130, 71 }, -{ "sienna2", 238, 121, 66 }, -{ "sienna3", 205, 104, 57 }, -{ "sienna4", 139, 71, 38 }, -{ "burlywood1", 255, 211, 155 }, -{ "burlywood2", 238, 197, 145 }, -{ "burlywood3", 205, 170, 125 }, -{ "burlywood4", 139, 115, 85 }, -{ "wheat1", 255, 231, 186 }, -{ "wheat2", 238, 216, 174 }, -{ "wheat3", 205, 186, 150 }, -{ "wheat4", 139, 126, 102 }, -{ "tan1", 255, 165, 79 }, -{ "tan2", 238, 154, 73 }, -{ "tan3", 205, 133, 63 }, -{ "tan4", 139 , 90, 43 }, -{ "chocolate1", 255, 127, 36 }, -{ "chocolate2", 238, 118, 33 }, -{ "chocolate3", 205, 102, 29 }, -{ "chocolate4", 139, 69, 19 }, -{ "firebrick1", 255, 48, 48 }, -{ "firebrick2", 238, 44, 44 }, -{ "firebrick3", 205, 38, 38 }, -{ "firebrick4", 139, 26, 26 }, -{ "brown1", 255, 64, 64 }, -{ "brown2", 238, 59, 59 }, -{ "brown3", 205, 51, 51 }, -{ "brown4", 139, 35, 35 }, -{ "salmon1", 255, 140, 105 }, -{ "salmon2", 238, 130, 98 }, -{ "salmon3", 205, 112, 84 }, -{ "salmon4", 139, 76, 57 }, -{ "LightSalmon1", 255, 160, 122 }, -{ "LightSalmon2", 238, 149, 114 }, -{ "LightSalmon3", 205, 129, 98 }, -{ "LightSalmon4", 139, 87, 66 }, -{ "orange1", 255, 165, 0 }, -{ "orange2", 238, 154, 0 }, -{ "orange3", 205, 133, 0 }, -{ "orange4", 139 , 90, 0 }, -{ "DarkOrange1", 255, 127, 0 }, -{ "DarkOrange2", 238, 118, 0 }, -{ "DarkOrange3", 205, 102, 0 }, -{ "DarkOrange4", 139 , 69, 0 }, -{ "coral1", 255, 114, 86 }, -{ "coral2", 238, 106, 80 }, -{ "coral3", 205, 91, 69 }, -{ "coral4", 139, 62, 47 }, -{ "tomato1", 255, 99, 71 }, -{ "tomato2", 238, 92, 66 }, -{ "tomato3", 205, 79, 57 }, -{ "tomato4", 139, 54, 38 }, -{ "OrangeRed1", 255, 69, 0 }, -{ "OrangeRed2", 238, 64, 0 }, -{ "OrangeRed3", 205, 55, 0 }, -{ "OrangeRed4", 139, 37, 0 }, -{ "red1", 255, 0, 0 }, -{ "red2", 238, 0, 0 }, -{ "red3", 205, 0, 0 }, -{ "red4", 139, 0, 0 }, -{ "DeepPink1", 255, 20, 147 }, -{ "DeepPink2", 238, 18, 137 }, -{ "DeepPink3", 205, 16, 118 }, -{ "DeepPink4", 139, 10, 80 }, -{ "HotPink1", 255, 110, 180 }, -{ "HotPink2", 238, 106, 167 }, -{ "HotPink3", 205, 96, 144 }, -{ "HotPink4", 139, 58, 98 }, -{ "pink1", 255, 181, 197 }, -{ "pink2", 238, 169, 184 }, -{ "pink3", 205, 145, 158 }, -{ "pink4", 139, 99, 108 }, -{ "LightPink1", 255, 174, 185 }, -{ "LightPink2", 238, 162, 173 }, -{ "LightPink3", 205, 140, 149 }, -{ "LightPink4", 139, 95, 101 }, -{ "PaleVioletRed1", 255, 130, 171 }, -{ "PaleVioletRed2", 238, 121, 159 }, -{ "PaleVioletRed3", 205, 104, 137 }, -{ "PaleVioletRed4", 139, 71, 93 }, -{ "maroon1", 255, 52, 179 }, -{ "maroon2", 238, 48, 167 }, -{ "maroon3", 205, 41, 144 }, -{ "maroon4", 139, 28, 98 }, -{ "VioletRed1", 255, 62, 150 }, -{ "VioletRed2", 238, 58, 140 }, -{ "VioletRed3", 205, 50, 120 }, -{ "VioletRed4", 139, 34, 82 }, -{ "magenta1", 255, 0, 255 }, -{ "magenta2", 238, 0, 238 }, -{ "magenta3", 205, 0, 205 }, -{ "magenta4", 139, 0, 139 }, -{ "orchid1", 255, 131, 250 }, -{ "orchid2", 238, 122, 233 }, -{ "orchid3", 205, 105, 201 }, -{ "orchid4", 139, 71, 137 }, -{ "plum1", 255, 187, 255 }, -{ "plum2", 238, 174, 238 }, -{ "plum3", 205, 150, 205 }, -{ "plum4", 139, 102, 139 }, -{ "MediumOrchid1", 224, 102, 255 }, -{ "MediumOrchid2", 209, 95, 238 }, -{ "MediumOrchid3", 180, 82, 205 }, -{ "MediumOrchid4", 122, 55, 139 }, -{ "DarkOrchid1", 191, 62, 255 }, -{ "DarkOrchid2", 178, 58, 238 }, -{ "DarkOrchid3", 154, 50, 205 }, -{ "DarkOrchid4", 104, 34, 139 }, -{ "purple1", 155, 48, 255 }, -{ "purple2", 145, 44, 238 }, -{ "purple3", 125, 38, 205 }, -{ "purple4", 85, 26, 139 }, -{ "MediumPurple1", 171, 130, 255 }, -{ "MediumPurple2", 159, 121, 238 }, -{ "MediumPurple3", 137, 104, 205 }, -{ "MediumPurple4", 93, 71, 139 }, -{ "thistle1", 255, 225, 255 }, -{ "thistle2", 238, 210, 238 }, -{ "thistle3", 205, 181, 205 }, -{ "thistle4", 139, 123, 139 }, -{ "gray0", 0, 0, 0 }, -{ "grey0", 0, 0, 0 }, -{ "gray1", 3, 3, 3 }, -{ "grey1", 3, 3, 3 }, -{ "gray2", 5, 5, 5 }, -{ "grey2", 5, 5, 5 }, -{ "gray3", 8, 8, 8 }, -{ "grey3", 8, 8, 8 }, -{ "gray4", 10, 10, 10 }, -{ "grey4", 10, 10, 10 }, -{ "gray5", 13, 13, 13 }, -{ "grey5", 13, 13, 13 }, -{ "gray6", 15, 15, 15 }, -{ "grey6", 15, 15, 15 }, -{ "gray7", 18, 18, 18 }, -{ "grey7", 18, 18, 18 }, -{ "gray8", 20, 20, 20 }, -{ "grey8", 20, 20, 20 }, -{ "gray9", 23, 23, 23 }, -{ "grey9", 23, 23, 23 }, -{ "gray10", 26, 26, 26 }, -{ "grey10", 26, 26, 26 }, -{ "gray11", 28, 28, 28 }, -{ "grey11", 28, 28, 28 }, -{ "gray12", 31, 31, 31 }, -{ "grey12", 31, 31, 31 }, -{ "gray13", 33, 33, 33 }, -{ "grey13", 33, 33, 33 }, -{ "gray14", 36, 36, 36 }, -{ "grey14", 36, 36, 36 }, -{ "gray15", 38, 38, 38 }, -{ "grey15", 38, 38, 38 }, -{ "gray16", 41, 41, 41 }, -{ "grey16", 41, 41, 41 }, -{ "gray17", 43, 43, 43 }, -{ "grey17", 43, 43, 43 }, -{ "gray18", 46, 46, 46 }, -{ "grey18", 46, 46, 46 }, -{ "gray19", 48, 48, 48 }, -{ "grey19", 48, 48, 48 }, -{ "gray20", 51, 51, 51 }, -{ "grey20", 51, 51, 51 }, -{ "gray21", 54, 54, 54 }, -{ "grey21", 54, 54, 54 }, -{ "gray22", 56, 56, 56 }, -{ "grey22", 56, 56, 56 }, -{ "gray23", 59, 59, 59 }, -{ "grey23", 59, 59, 59 }, -{ "gray24", 61, 61, 61 }, -{ "grey24", 61, 61, 61 }, -{ "gray25", 64, 64, 64 }, -{ "grey25", 64, 64, 64 }, -{ "gray26", 66, 66, 66 }, -{ "grey26", 66, 66, 66 }, -{ "gray27", 69, 69, 69 }, -{ "grey27", 69, 69, 69 }, -{ "gray28", 71, 71, 71 }, -{ "grey28", 71, 71, 71 }, -{ "gray29", 74, 74, 74 }, -{ "grey29", 74, 74, 74 }, -{ "gray30", 77, 77, 77 }, -{ "grey30", 77, 77, 77 }, -{ "gray31", 79, 79, 79 }, -{ "grey31", 79, 79, 79 }, -{ "gray32", 82, 82, 82 }, -{ "grey32", 82, 82, 82 }, -{ "gray33", 84, 84, 84 }, -{ "grey33", 84, 84, 84 }, -{ "gray34", 87, 87, 87 }, -{ "grey34", 87, 87, 87 }, -{ "gray35", 89, 89, 89 }, -{ "grey35", 89, 89, 89 }, -{ "gray36", 92, 92, 92 }, -{ "grey36", 92, 92, 92 }, -{ "gray37", 94, 94, 94 }, -{ "grey37", 94, 94, 94 }, -{ "gray38", 97, 97, 97 }, -{ "grey38", 97, 97, 97 }, -{ "gray39", 99, 99, 99 }, -{ "grey39", 99, 99, 99 }, -{ "gray40", 102, 102, 102 }, -{ "grey40", 102, 102, 102 }, -{ "gray41", 105, 105, 105 }, -{ "grey41", 105, 105, 105 }, -{ "gray42", 107, 107, 107 }, -{ "grey42", 107, 107, 107 }, -{ "gray43", 110, 110, 110 }, -{ "grey43", 110, 110, 110 }, -{ "gray44", 112, 112, 112 }, -{ "grey44", 112, 112, 112 }, -{ "gray45", 115, 115, 115 }, -{ "grey45", 115, 115, 115 }, -{ "gray46", 117, 117, 117 }, -{ "grey46", 117, 117, 117 }, -{ "gray47", 120, 120, 120 }, -{ "grey47", 120, 120, 120 }, -{ "gray48", 122, 122, 122 }, -{ "grey48", 122, 122, 122 }, -{ "gray49", 125, 125, 125 }, -{ "grey49", 125, 125, 125 }, -{ "gray50", 127, 127, 127 }, -{ "grey50", 127, 127, 127 }, -{ "gray51", 130, 130, 130 }, -{ "grey51", 130, 130, 130 }, -{ "gray52", 133, 133, 133 }, -{ "grey52", 133, 133, 133 }, -{ "gray53", 135, 135, 135 }, -{ "grey53", 135, 135, 135 }, -{ "gray54", 138, 138, 138 }, -{ "grey54", 138, 138, 138 }, -{ "gray55", 140, 140, 140 }, -{ "grey55", 140, 140, 140 }, -{ "gray56", 143, 143, 143 }, -{ "grey56", 143, 143, 143 }, -{ "gray57", 145, 145, 145 }, -{ "grey57", 145, 145, 145 }, -{ "gray58", 148, 148, 148 }, -{ "grey58", 148, 148, 148 }, -{ "gray59", 150, 150, 150 }, -{ "grey59", 150, 150, 150 }, -{ "gray60", 153, 153, 153 }, -{ "grey60", 153, 153, 153 }, -{ "gray61", 156, 156, 156 }, -{ "grey61", 156, 156, 156 }, -{ "gray62", 158, 158, 158 }, -{ "grey62", 158, 158, 158 }, -{ "gray63", 161, 161, 161 }, -{ "grey63", 161, 161, 161 }, -{ "gray64", 163, 163, 163 }, -{ "grey64", 163, 163, 163 }, -{ "gray65", 166, 166, 166 }, -{ "grey65", 166, 166, 166 }, -{ "gray66", 168, 168, 168 }, -{ "grey66", 168, 168, 168 }, -{ "gray67", 171, 171, 171 }, -{ "grey67", 171, 171, 171 }, -{ "gray68", 173, 173, 173 }, -{ "grey68", 173, 173, 173 }, -{ "gray69", 176, 176, 176 }, -{ "grey69", 176, 176, 176 }, -{ "gray70", 179, 179, 179 }, -{ "grey70", 179, 179, 179 }, -{ "gray71", 181, 181, 181 }, -{ "grey71", 181, 181, 181 }, -{ "gray72", 184, 184, 184 }, -{ "grey72", 184, 184, 184 }, -{ "gray73", 186, 186, 186 }, -{ "grey73", 186, 186, 186 }, -{ "gray74", 189, 189, 189 }, -{ "grey74", 189, 189, 189 }, -{ "gray75", 191, 191, 191 }, -{ "grey75", 191, 191, 191 }, -{ "gray76", 194, 194, 194 }, -{ "grey76", 194, 194, 194 }, -{ "gray77", 196, 196, 196 }, -{ "grey77", 196, 196, 196 }, -{ "gray78", 199, 199, 199 }, -{ "grey78", 199, 199, 199 }, -{ "gray79", 201, 201, 201 }, -{ "grey79", 201, 201, 201 }, -{ "gray80", 204, 204, 204 }, -{ "grey80", 204, 204, 204 }, -{ "gray81", 207, 207, 207 }, -{ "grey81", 207, 207, 207 }, -{ "gray82", 209, 209, 209 }, -{ "grey82", 209, 209, 209 }, -{ "gray83", 212, 212, 212 }, -{ "grey83", 212, 212, 212 }, -{ "gray84", 214, 214, 214 }, -{ "grey84", 214, 214, 214 }, -{ "gray85", 217, 217, 217 }, -{ "grey85", 217, 217, 217 }, -{ "gray86", 219, 219, 219 }, -{ "grey86", 219, 219, 219 }, -{ "gray87", 222, 222, 222 }, -{ "grey87", 222, 222, 222 }, -{ "gray88", 224, 224, 224 }, -{ "grey88", 224, 224, 224 }, -{ "gray89", 227, 227, 227 }, -{ "grey89", 227, 227, 227 }, -{ "gray90", 229, 229, 229 }, -{ "grey90", 229, 229, 229 }, -{ "gray91", 232, 232, 232 }, -{ "grey91", 232, 232, 232 }, -{ "gray92", 235, 235, 235 }, -{ "grey92", 235, 235, 235 }, -{ "gray93", 237, 237, 237 }, -{ "grey93", 237, 237, 237 }, -{ "gray94", 240, 240, 240 }, -{ "grey94", 240, 240, 240 }, -{ "gray95", 242, 242, 242 }, -{ "grey95", 242, 242, 242 }, -{ "gray96", 245, 245, 245 }, -{ "grey96", 245, 245, 245 }, -{ "gray97", 247, 247, 247 }, -{ "grey97", 247, 247, 247 }, -{ "gray98", 250, 250, 250 }, -{ "grey98", 250, 250, 250 }, -{ "gray99", 252, 252, 252 }, -{ "grey99", 252, 252, 252 }, -{ "gray100", 255, 255, 255 }, -{ "grey100", 255, 255, 255 }, -{ "DarkGrey", 169, 169, 169 }, -{ "DarkGray", 169, 169, 169 }, -{ "DarkBlue", 0, 0, 139 }, -{ "DarkCyan", 0, 139, 139 }, -{ "DarkMagenta", 139, 0, 139 }, -{ "DarkRed", 139, 0, 0 }, -{ "LightGreen", 144, 238, 144 }, -{ NULL, 0 , 0, 0} -}; diff --git a/svtools/source/filter.vcl/ixpm/xpmread.cxx b/svtools/source/filter.vcl/ixpm/xpmread.cxx deleted file mode 100644 index 7575c94e3ed9..000000000000 --- a/svtools/source/filter.vcl/ixpm/xpmread.cxx +++ /dev/null @@ -1,702 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#ifndef _BMPACC_HXX -#include -#endif -#ifndef _GRAPH_HXX -#include -#endif -#include "rgbtable.hxx" -#define _XPMPRIVATE -#include "xpmread.hxx" - -// ------------- -// - XPMReader - -// ------------- - -XPMReader::XPMReader( SvStream& rStm ) : - mrIStm ( rStm ), - mpAcc ( NULL ), - mpMaskAcc ( NULL ), - mnLastPos ( rStm.Tell() ), - mnWidth ( 0 ), - mnHeight ( 0 ), - mnColors ( 0 ), - mnCpp ( 0 ), - mbTransparent ( FALSE ), - mbStatus ( TRUE ), - mnStatus ( 0 ), - mnIdentifier ( XPMIDENTIFIER ), - mcThisByte ( 0 ), - mnTempAvail ( 0 ), - mpFastColorTable( NULL ), - mpColMap ( NULL ) -{ - -} - -// ------------------------------------------------------------------------ - -XPMReader::~XPMReader() -{ - if( mpAcc ) - maBmp.ReleaseAccess( mpAcc ); -} - -// ------------------------------------------------------------------------ - -#ifdef _MSC_VER -#pragma optimize ("",off) -#endif - -ReadState XPMReader::ReadXPM( Graphic& rGraphic ) -{ - ReadState eReadState; - BYTE cDummy; - - // sehen, ob wir _alles_ lesen koennen - mrIStm.Seek( STREAM_SEEK_TO_END ); - mrIStm >> cDummy; - - // falls wir nicht alles lesen koennen - // kehren wir zurueck und warten auf neue Daten - if ( mrIStm.GetError() != ERRCODE_IO_PENDING ) - { - mrIStm.Seek( mnLastPos ); - mbStatus = TRUE; - - if ( mbStatus ) - { - mpStringBuf = new BYTE [ XPMSTRINGBUF ]; - mpTempBuf = new BYTE [ XPMTEMPBUFSIZE ]; - - if ( ( mbStatus = ImplGetString() ) == TRUE ) - { - mnIdentifier = XPMVALUES; // Bitmap informationen einholen - mnWidth = ImplGetULONG( 0 ); - mnHeight = ImplGetULONG( 1 ); - mnColors = ImplGetULONG( 2 ); - mnCpp = ImplGetULONG( 3 ); - } - if ( mnColors > ( SAL_MAX_UINT32 / ( 4 + mnCpp ) ) ) - mbStatus = sal_False; - if ( ( mnWidth * mnCpp ) >= XPMSTRINGBUF ) - mbStatus = sal_False; - if ( mbStatus && mnWidth && mnHeight && mnColors && mnCpp ) - { - mnIdentifier = XPMCOLORS; - - // mpColMap beinhaltet fuer jede vorhandene - // Farbe: ( mnCpp )Byte(s)-> ASCII Eintrag der der Farbe zugeordnet ist - // 1 Byte -> 0xff wenn Farbe transparent ist - // 3 Bytes -> RGB Wert der Farbe - mpColMap = new BYTE[ mnColors * ( 4 + mnCpp ) ]; - if ( mpColMap ) - { - for ( ULONG i = 0; i < mnColors; i++ ) - { - if ( ImplGetColor( i ) == FALSE ) - { - mbStatus = FALSE; - break; - } - } - } - else - mbStatus = sal_False; - - if ( mbStatus ) - { - // bei mehr als 256 Farben wird eine 24 Bit Grafik erstellt - sal_uInt16 nBits = 1; - if ( mnColors > 256 ) - nBits = 24; - else if ( mnColors > 16 ) - nBits = 8; - else if ( mnColors > 2 ) - nBits = 4; - else - nBits = 1; - - maBmp = Bitmap( Size( mnWidth, mnHeight ), nBits ); - mpAcc = maBmp.AcquireWriteAccess(); - - // mbTransparent ist TRUE wenn mindestens eine Farbe Transparent ist - if ( mbTransparent ) - { - maMaskBmp = Bitmap( Size( mnWidth, mnHeight ), 1 ); - if ( ( mpMaskAcc = maMaskBmp.AcquireWriteAccess() ) == NULL ) - mbStatus = FALSE; - } - if( mpAcc && mbStatus ) - { - ULONG i; - if ( mnColors <=256 ) // palette is only needed by using less than 257 - { // colors - - BYTE* pPtr = &mpColMap[mnCpp]; - - for ( i = 0; i < mnColors; i++ ) - { - mpAcc->SetPaletteColor( (BYTE)i, Color( pPtr[1], pPtr[2], pPtr[3] ) ); - pPtr += ( mnCpp + 4 ); - } - // using 2 charakters per pixel and less than 257 Colors we speed up - if ( mnCpp == 2 ) // by using a 64kb indexing table - { - mpFastColorTable = new BYTE[ 256 * 256 ]; - for ( pPtr = mpColMap, i = 0; i < mnColors; i++, pPtr += mnCpp + 4 ) - { - ULONG j = pPtr[ 0 ] << 8; - j += pPtr[ 1 ]; - mpFastColorTable[ j ] = (BYTE)i; - } - } - } - // now we get the bitmap data - mnIdentifier = XPMPIXELS; - for ( i = 0; i < mnHeight; i++ ) - { - if ( ImplGetScanLine( i ) == FALSE ) - { - mbStatus = FALSE; - break; - } - } - mnIdentifier = XPMEXTENSIONS; - } - } - } - - delete[] mpFastColorTable; - delete[] mpColMap; - delete[] mpStringBuf; - delete[] mpTempBuf; - - } - if( mbStatus ) - { - if ( mpMaskAcc ) - { - maMaskBmp.ReleaseAccess ( mpMaskAcc), mpMaskAcc = NULL; - maBmp.ReleaseAccess( mpAcc ), mpAcc = NULL; - rGraphic = Graphic( BitmapEx( maBmp, maMaskBmp ) ); - } - else - { - maBmp.ReleaseAccess( mpAcc ), mpAcc = NULL; - rGraphic = maBmp; - } - eReadState = XPMREAD_OK; - } - else - { - if ( mpMaskAcc ) maMaskBmp.ReleaseAccess ( mpMaskAcc), mpMaskAcc = NULL; - if ( mpAcc ) maBmp.ReleaseAccess( mpAcc ), mpAcc = NULL; - eReadState = XPMREAD_ERROR; - } - } - else - { - mrIStm.ResetError(); - eReadState = XPMREAD_NEED_MORE; - } - return eReadState; -} - -#ifdef _MSC_VER -#pragma optimize ("",on) -#endif - -// ------------------------------------------------------------------------ -// ImplGetColor ermittelt saemtliche Farbwerte, -// die Rueckgabe ist TRUE wenn saemtliche Farben zugeordnet werden konnten - -BOOL XPMReader::ImplGetColor( ULONG nNumb ) -{ - BYTE* pString = mpStringBuf; - BYTE* pPtr = ( mpColMap + nNumb * ( 4 + mnCpp ) ); - BOOL bStatus = ImplGetString(); - - if ( bStatus ) - { - for ( ULONG i = 0; i < mnCpp; i++ ) - *pPtr++ = *pString++; - bStatus = ImplGetColSub ( pPtr ); - } - return bStatus; -} - -// ------------------------------------------------------------------------ -// ImpGetScanLine liest den String mpBufSize aus und schreibt die Pixel in die -// Bitmap. Der Parameter nY gibt die horizontale Position an. - -BOOL XPMReader::ImplGetScanLine( ULONG nY ) -{ - BOOL bStatus = ImplGetString(); - BYTE* pString = mpStringBuf; - BYTE* pColor; - BitmapColor aWhite; - BitmapColor aBlack; - - if ( bStatus ) - { - if ( mpMaskAcc ) - { - aWhite = mpMaskAcc->GetBestMatchingColor( Color( COL_WHITE ) ); - aBlack = mpMaskAcc->GetBestMatchingColor( Color( COL_BLACK ) ); - } - if ( mnStringSize != ( mnWidth * mnCpp )) - bStatus = FALSE; - else - { - ULONG i, j; - if ( mpFastColorTable ) - { - for ( i = 0; i < mnWidth; i++ ) - { - j = (*pString++) << 8; - j += *pString++; - BYTE k = (BYTE)mpFastColorTable[ j ]; - mpAcc->SetPixel( nY, i, BitmapColor( (BYTE)k ) ); - - if ( mpMaskAcc ) - mpMaskAcc->SetPixel( nY, i, - ( mpColMap[ k * (mnCpp + 4) + mnCpp] ) ? aWhite : aBlack ); - } - } - else for ( i = 0; i < mnWidth; i++ ) - { - pColor = mpColMap; - for ( j = 0; j < mnColors; j++ ) - { - if ( ImplCompare( pString, pColor, mnCpp, XPMCASESENSITIVE ) == TRUE ) - { - if ( mnColors > 256 ) - mpAcc->SetPixel( nY, i, Color ( pColor[3], pColor[4], pColor[5] ) ); - else - mpAcc->SetPixel( nY, i, BitmapColor( (BYTE) j ) ); - - if ( mpMaskAcc ) - mpMaskAcc->SetPixel( nY, i, ( - pColor[ mnCpp ] ) ? aWhite : aBlack ); - - break; - } - pColor += ( mnCpp + 4 ); - } - pString += mnCpp; - } - - } - } - return bStatus; -} - -// ------------------------------------------------------------------------ -// versucht aus mpStringBuf einen Farbwert zu uebermitteln -// wurde eine Farbe gefunden wird an pDest[1]..pDest[2] der RGB wert geschrieben -// pDest[0] enthaelt 0xff wenn die Farbe transparent ist sonst 0 - -BOOL XPMReader::ImplGetColSub( BYTE* pDest ) -{ - unsigned char cTransparent[] = "None"; - - BOOL bColStatus = FALSE; - - if ( ImplGetColKey( 'c' ) || ImplGetColKey( 'm' ) || ImplGetColKey( 'g' ) ) - { - // hexentry for RGB or HSV color ? - if ( *mpPara == '#' ) - { - *pDest++ = 0; - bColStatus = TRUE; - switch ( mnParaSize ) - { - case 25 : - ImplGetRGBHex ( pDest, 6 ); - break; - case 13 : - ImplGetRGBHex ( pDest, 2 ); - break; - case 7 : - ImplGetRGBHex ( pDest, 0 ); - break; - default: - bColStatus = FALSE; - break; - } - } - // maybe pixel is transparent - else if ( ImplCompare( &cTransparent[0], mpPara, 4 )) - { - *pDest++ = 0xff; - bColStatus = TRUE; - mbTransparent = TRUE; - } - // last we will try to get the colorname - else if ( mnParaSize > 2 ) // name must enlarge the minimum size - { - ULONG i = 0; - while ( TRUE ) - { - if ( pRGBTable[ i ].name == NULL ) - break; - if ( pRGBTable[ i ].name[ mnParaSize ] == 0 ) - { - if ( ImplCompare ( (unsigned char*)pRGBTable[ i ].name, - mpPara, mnParaSize, XPMCASENONSENSITIVE ) ) - { - bColStatus = TRUE; - *pDest++ = 0; - *pDest++ = pRGBTable[ i ].red; - *pDest++ = pRGBTable[ i ].green; - *pDest++ = pRGBTable[ i ].blue; - } - } - i++; - } - } - } - return bColStatus; -} - -// ------------------------------------------------------------------------ -// ImplGetColKey durchsuch den String mpStringBuf nach einem Parameter 'nKey' -// und gibt einen BOOL zurueck. ( wenn TRUE werden mpPara und mnParaSize gesetzt ) - -BOOL XPMReader::ImplGetColKey( BYTE nKey ) -{ - BYTE nTemp, nPrev = ' '; - - mpPara = mpStringBuf + mnCpp + 1; - mnParaSize = 0; - - while ( *mpPara != 0 ) - { - if ( *mpPara == nKey ) - { - nTemp = *( mpPara + 1 ); - if ( nTemp == ' ' || nTemp == 0x09 ) - { - if ( nPrev == ' ' || nPrev == 0x09 ) - break; - } - } - nPrev = *mpPara; - mpPara++; - } - if ( *mpPara ) - { - mpPara++; - while ( (*mpPara == ' ') || (*mpPara == 0x09) ) - { - mpPara++; - } - if ( *mpPara != 0 ) - { - while ( *(mpPara+mnParaSize) != ' ' && *(mpPara+mnParaSize) != 0x09 && - *(mpPara+mnParaSize) != 0 ) - { - mnParaSize++; - } - } - } - return ( mnParaSize ) ? TRUE : FALSE; -} - -// ------------------------------------------------------------------------ -// ImplGetRGBHex uebersetzt den ASCII-Hexadezimalwert der sich bei mpPara befindet -// in einen RGB wert und schreibt diesen nach pDest -// folgende Formate muessen sich bei mpPara befinden: -// wenn nAdd = 0 : '#12ab12' -> RGB = 0x12, 0xab, 0x12 -// 2 : '#1234abcd1234' " " " " -// 6 : '#12345678abcdefab12345678' " " " " - - -void XPMReader::ImplGetRGBHex( BYTE* pDest,ULONG nAdd ) -{ - BYTE* pPtr = mpPara+1; - BYTE nHex, nTemp; - - for ( ULONG i = 0; i < 3; i++ ) - { - nHex = (*pPtr++) - '0'; - if ( nHex > 9 ) - nHex = ((nHex - 'A' + '0') & 7) + 10; - - nTemp = (*pPtr++) - '0'; - if ( nTemp > 9 ) - nTemp = ((nTemp - 'A' + '0') & 7) + 10; - nHex = ( nHex << 4 ) + nTemp; - - pPtr += nAdd; - *pDest++ = (BYTE)nHex; - } -} - -// ------------------------------------------------------------------------ -// ImplGetUlong gibt den wert einer bis zu 6stelligen ASCII-Dezimalzahl zurueck. - -ULONG XPMReader::ImplGetULONG( ULONG nPara ) -{ - if ( ImplGetPara ( nPara ) ) - { - ULONG nRetValue = 0; - BYTE* pPtr = mpPara; - - if ( ( mnParaSize > 6 ) || ( mnParaSize == 0 ) ) return 0; - for ( ULONG i = 0; i < mnParaSize; i++ ) - { - BYTE j = (*pPtr++) - 48; - if ( j > 9 ) return 0; // ascii is invalid - nRetValue*=10; - nRetValue+=j; - } - return nRetValue; - } - else return 0; -} - -// ------------------------------------------------------------------------ - -BOOL XPMReader::ImplCompare( BYTE* pSource, BYTE* pDest, ULONG nSize, ULONG nMode ) -{ - BOOL bRet = TRUE; - - if ( nMode == XPMCASENONSENSITIVE ) - { - for ( ULONG i = 0; i < nSize; i++ ) - { - if ( ( pSource[i]&~0x20 ) != ( pDest[i]&~0x20 ) ) - { - bRet = FALSE; - break; - } - } - } - else - { - for ( ULONG i = 0; i < nSize; i++ ) - { - if ( pSource[i] != pDest[i] ) - { - bRet = FALSE; - break; - } - } - } - return bRet; -} - -// ------------------------------------------------------------------------ -// ImplGetPara versucht den nNumb ( 0...x ) Parameter aus mpStringBuf zu ermitteln. -// Ein Parameter ist durch Spaces oder Tabs von den anderen getrennt. -// Konnte der Parameter gefunden werden ist der Rueckgabewert TRUE und mpPara + mnParaSize -// werden gesetzt. - -BOOL XPMReader::ImplGetPara ( ULONG nNumb ) -{ - BYTE nByte; - ULONG pSize = 0; - BYTE* pPtr = mpStringBuf; - ULONG nCount = 0; - - if ( ( *pPtr != ' ' ) && ( *pPtr != 0x09 ) ) - { - mpPara = pPtr; - mnParaSize = 0; - nCount = 0; - } - else - { - mpPara = NULL; - nCount = 0xffffffff; - } - - while ( pSize < mnStringSize ) - { - nByte = *pPtr; - - if ( mpPara ) - { - if ( ( nByte == ' ' ) || ( nByte == 0x09 ) ) - { - if ( nCount == nNumb ) - break; - else - mpPara = NULL; - } - else - mnParaSize++; - } - else - { - if ( ( nByte != ' ' ) && ( nByte != 0x09 ) ) - { - mpPara = pPtr; - mnParaSize = 1; - nCount++; - } - } - pSize++; - pPtr++; - } - return ( ( nCount == nNumb ) && ( mpPara ) ) ? TRUE : FALSE; -} - -// ------------------------------------------------------------------------ -// Der naechste String wird ausgelesen und in mpStringBuf (mit 0 abgeschlossen) abgelegt; -// mnStringSize enthaelt die Groesse des gelesenen Strings. -// Bemerkungen wie '//' und '/*.....*/' werden uebersprungen. - -BOOL XPMReader::ImplGetString( void ) -{ - BYTE sID[] = "/* XPM */"; - BYTE* pString = mpStringBuf; - - mnStringSize = 0; - mpStringBuf[0] = 0; - - while( mbStatus && ( mnStatus != XPMFINISHED ) ) - { - if ( mnTempAvail == 0 ) - { - mnTempAvail = mrIStm.Read( mpTempBuf, XPMTEMPBUFSIZE ); - if ( mnTempAvail == 0 ) - break; - - mpTempPtr = mpTempBuf; - - if ( mnIdentifier == XPMIDENTIFIER ) - { - if ( mnTempAvail <= 50 ) - { - mbStatus = FALSE; // file is too short to be a correct XPM format - break; - } - for ( int i = 0; i < 9; i++ ) // searching for "/* XPM */" - if ( *mpTempPtr++ != sID[i] ) - { - mbStatus = FALSE; - break; - } - mnTempAvail-=9; - mnIdentifier++; - } - } - mcLastByte = mcThisByte; - mcThisByte = *mpTempPtr++; - mnTempAvail--; - - if ( mnStatus & XPMDOUBLE ) - { - if ( mcThisByte == 0x0a ) - mnStatus &=~XPMDOUBLE; - continue; - } - if ( mnStatus & XPMREMARK ) - { - if ( ( mcThisByte == '/' ) && ( mcLastByte == '*' ) ) - mnStatus &=~XPMREMARK; - continue; - } - if ( mnStatus & XPMSTRING ) // characters in string - { - if ( mcThisByte == '"' ) - { - mnStatus &=~XPMSTRING; // end of parameter by eol - break; - } - if ( mnStringSize >= ( XPMSTRINGBUF - 1 ) ) - { - mbStatus = FALSE; - break; - } - *pString++ = mcThisByte; - pString[0] = 0; - mnStringSize++; - continue; - } - else - { // characters beside string - switch ( mcThisByte ) - { - case '*' : - if ( mcLastByte == '/' ) mnStatus |= XPMREMARK; - break; - case '/' : - if ( mcLastByte == '/' ) mnStatus |= XPMDOUBLE; - break; - case '"' : mnStatus |= XPMSTRING; - break; - case '{' : - if ( mnIdentifier == XPMDEFINITION ) - mnIdentifier++; - break; - case '}' : - if ( mnIdentifier == XPMENDEXT ) - mnStatus = XPMFINISHED; - break; - } - } - } - return mbStatus; -} - -// ------------- -// - ImportXPM - -// ------------- - -BOOL ImportXPM( SvStream& rStm, Graphic& rGraphic ) -{ - XPMReader* pXPMReader = (XPMReader*) rGraphic.GetContext(); - ReadState eReadState; - BOOL bRet = TRUE; - - if( !pXPMReader ) - pXPMReader = new XPMReader( rStm ); - - rGraphic.SetContext( NULL ); - eReadState = pXPMReader->ReadXPM( rGraphic ); - - if( eReadState == XPMREAD_ERROR ) - { - bRet = FALSE; - delete pXPMReader; - } - else if( eReadState == XPMREAD_OK ) - delete pXPMReader; - else - rGraphic.SetContext( pXPMReader ); - - return bRet; -} diff --git a/svtools/source/filter.vcl/jpeg/jpeg.cxx b/svtools/source/filter.vcl/jpeg/jpeg.cxx deleted file mode 100644 index a2de92171af3..000000000000 --- a/svtools/source/filter.vcl/jpeg/jpeg.cxx +++ /dev/null @@ -1,779 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#include - -extern "C" -{ - #define INT32 JPEG_INT32 - #include "stdio.h" - #include "jpeg.h" - #include "jpeglib.h" - #include "jerror.h" - #undef INT32 -} - -#define _JPEGPRIVATE -#include -#include "jpeg.hxx" -#include -#include - -// ----------- -// - Defines - -// ----------- - -using namespace ::com::sun::star; - -#define JPEGMINREAD 512 - -// ------------- -// - (C-Calls) - -// ------------- - -// ------------------------------------------------------------------------ - -extern "C" void* CreateBitmap( void* pJPEGReader, void* pJPEGCreateBitmapParam ) -{ - return ( (JPEGReader*) pJPEGReader )->CreateBitmap( pJPEGCreateBitmapParam ); -} - -// ------------------------------------------------------------------------ - -extern "C" void* GetScanline( void* pJPEGWriter, long nY ) -{ - return ( (JPEGWriter*) pJPEGWriter )->GetScanline( nY ); -} - -// ------------------------------------------------------------------------ - -struct JPEGCallbackStruct -{ - uno::Reference< task::XStatusIndicator > xStatusIndicator; -}; - -extern "C" long JPEGCallback( void* pCallbackData, long nPercent ) -{ - JPEGCallbackStruct* pS = (JPEGCallbackStruct*)pCallbackData; - if ( pS && pS->xStatusIndicator.is() ) - { - pS->xStatusIndicator->setValue( nPercent ); - } - return 0L; -} - -#define BUF_SIZE 4096 - -typedef struct -{ - struct jpeg_destination_mgr pub; /* public fields */ - - SvStream* outfile; /* target stream */ - JOCTET * buffer; /* start of buffer */ -} my_destination_mgr; - -typedef my_destination_mgr * my_dest_ptr; - -extern "C" void init_destination (j_compress_ptr cinfo) -{ - my_dest_ptr dest = (my_dest_ptr) cinfo->dest; - - /* Allocate the output buffer --- it will be released when done with image */ - dest->buffer = (JOCTET *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - BUF_SIZE * sizeof(JOCTET)); - - dest->pub.next_output_byte = dest->buffer; - dest->pub.free_in_buffer = BUF_SIZE; -} - -extern "C" int empty_output_buffer (j_compress_ptr cinfo) -{ - my_dest_ptr dest = (my_dest_ptr) cinfo->dest; - - if (dest->outfile->Write(dest->buffer, BUF_SIZE) != - (size_t) BUF_SIZE) - ERREXIT(cinfo, JERR_FILE_WRITE); - - dest->pub.next_output_byte = dest->buffer; - dest->pub.free_in_buffer = BUF_SIZE; - - return TRUE; -} - -extern "C" void term_destination (j_compress_ptr cinfo) -{ - my_dest_ptr dest = (my_dest_ptr) cinfo->dest; - size_t datacount = BUF_SIZE - dest->pub.free_in_buffer; - - /* Write any data remaining in the buffer */ - if (datacount > 0) { - if (dest->outfile->Write(dest->buffer, datacount) != datacount) - ERREXIT(cinfo, JERR_FILE_WRITE); - } -} - -extern "C" void jpeg_svstream_dest (j_compress_ptr cinfo, void* out) -{ - SvStream * outfile = (SvStream*)out; - my_dest_ptr dest; - - /* The destination object is made permanent so that multiple JPEG images - * can be written to the same file without re-executing jpeg_svstream_dest. - * This makes it dangerous to use this manager and a different destination - * manager serially with the same JPEG object, because their private object - * sizes may be different. Caveat programmer. - */ - if (cinfo->dest == NULL) { /* first time for this JPEG object? */ - cinfo->dest = (struct jpeg_destination_mgr *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, - sizeof(my_destination_mgr)); - } - - dest = (my_dest_ptr) cinfo->dest; - dest->pub.init_destination = init_destination; - dest->pub.empty_output_buffer = empty_output_buffer; - dest->pub.term_destination = term_destination; - dest->outfile = outfile; -} - -/* Expanded data source object for stdio input */ - -typedef struct { - struct jpeg_source_mgr pub; /* public fields */ - - SvStream * infile; /* source stream */ - JOCTET * buffer; /* start of buffer */ - boolean start_of_file; /* have we gotten any data yet? */ -} my_source_mgr; - -typedef my_source_mgr * my_src_ptr; - -/* - * Initialize source --- called by jpeg_read_header - * before any data is actually read. - */ - -extern "C" void init_source (j_decompress_ptr cinfo) -{ - my_src_ptr src = (my_src_ptr) cinfo->src; - - /* We reset the empty-input-file flag for each image, - * but we don't clear the input buffer. - * This is correct behavior for reading a series of images from one source. - */ - src->start_of_file = TRUE; -} - -long StreamRead( SvStream* pSvStm, void* pBuffer, long nBufferSize ) -{ - long nRead; - - if( pSvStm->GetError() != ERRCODE_IO_PENDING ) - { - long nActPos = pSvStm->Tell(); - - nRead = (long) pSvStm->Read( pBuffer, nBufferSize ); - - if( pSvStm->GetError() == ERRCODE_IO_PENDING ) - { - nRead = 0; - - // Damit wir wieder an die alte Position - // seeken koennen, setzen wir den Error temp.zurueck - pSvStm->ResetError(); - pSvStm->Seek( nActPos ); - pSvStm->SetError( ERRCODE_IO_PENDING ); - } - } - else - nRead = 0; - - return nRead; -} - -extern "C" int fill_input_buffer (j_decompress_ptr cinfo) -{ - my_src_ptr src = (my_src_ptr) cinfo->src; - size_t nbytes; - - nbytes = StreamRead(src->infile, src->buffer, BUF_SIZE); - - if (nbytes <= 0) { - if (src->start_of_file) /* Treat empty input file as fatal error */ - ERREXIT(cinfo, JERR_INPUT_EMPTY); - WARNMS(cinfo, JWRN_JPEG_EOF); - /* Insert a fake EOI marker */ - src->buffer[0] = (JOCTET) 0xFF; - src->buffer[1] = (JOCTET) JPEG_EOI; - nbytes = 2; - } - - src->pub.next_input_byte = src->buffer; - src->pub.bytes_in_buffer = nbytes; - src->start_of_file = FALSE; - - return TRUE; -} - -extern "C" void skip_input_data (j_decompress_ptr cinfo, long num_bytes) -{ - my_src_ptr src = (my_src_ptr) cinfo->src; - - /* Just a dumb implementation for now. Could use fseek() except - * it doesn't work on pipes. Not clear that being smart is worth - * any trouble anyway --- large skips are infrequent. - */ - if (num_bytes > 0) { - while (num_bytes > (long) src->pub.bytes_in_buffer) { - num_bytes -= (long) src->pub.bytes_in_buffer; - (void) fill_input_buffer(cinfo); - /* note we assume that fill_input_buffer will never return FALSE, - * so suspension need not be handled. - */ - } - src->pub.next_input_byte += (size_t) num_bytes; - src->pub.bytes_in_buffer -= (size_t) num_bytes; - } -} - -extern "C" void term_source (j_decompress_ptr) -{ - /* no work necessary here */ -} - -extern "C" void jpeg_svstream_src (j_decompress_ptr cinfo, void * in) -{ - my_src_ptr src; - SvStream * infile = (SvStream*)in; - - /* The source object and input buffer are made permanent so that a series - * of JPEG images can be read from the same file by calling jpeg_stdio_src - * only before the first one. (If we discarded the buffer at the end of - * one image, we'd likely lose the start of the next one.) - * This makes it unsafe to use this manager and a different source - * manager serially with the same JPEG object. Caveat programmer. - */ - if (cinfo->src == NULL) { /* first time for this JPEG object? */ - cinfo->src = (struct jpeg_source_mgr *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, - sizeof(my_source_mgr)); - src = (my_src_ptr) cinfo->src; - src->buffer = (JOCTET *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, - BUF_SIZE * sizeof(JOCTET)); - } - - src = (my_src_ptr) cinfo->src; - src->pub.init_source = init_source; - src->pub.fill_input_buffer = fill_input_buffer; - src->pub.skip_input_data = skip_input_data; - src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */ - src->pub.term_source = term_source; - src->infile = infile; - src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */ - src->pub.next_input_byte = NULL; /* until buffer loaded */ -} - -// -------------- -// - JPEGReader - -// -------------- - -JPEGReader::JPEGReader( SvStream& rStm, void* /*pCallData*/, sal_Bool bSetLS ) : - rIStm ( rStm ), - pAcc ( NULL ), - pAcc1 ( NULL ), - pBuffer ( NULL ), - nLastPos ( rStm.Tell() ), - nLastLines ( 0 ), - bSetLogSize ( bSetLS ) -{ - maUpperName = String::CreateFromAscii( "SVIJPEG", 7 ); - nFormerPos = nLastPos; -} - -// ------------------------------------------------------------------------ - -JPEGReader::~JPEGReader() -{ - if( pBuffer ) - rtl_freeMemory( pBuffer ); - - if( pAcc ) - aBmp.ReleaseAccess( pAcc ); - - if( pAcc1 ) - aBmp1.ReleaseAccess( pAcc1 ); -} - -// ------------------------------------------------------------------------ - -void* JPEGReader::CreateBitmap( void* pParam ) -{ - Size aSize( ((JPEGCreateBitmapParam*)pParam)->nWidth, - ((JPEGCreateBitmapParam*)pParam)->nHeight ); - sal_Bool bGray = ((JPEGCreateBitmapParam*)pParam)->bGray != 0; - - void* pBmpBuf = NULL; - - if( pAcc ) - aBmp.ReleaseAccess( pAcc ); - - if( bGray ) - { - BitmapPalette aGrayPal( 256 ); - - for( USHORT n = 0; n < 256; n++ ) - { - const BYTE cGray = (BYTE) n; - aGrayPal[ n ] = BitmapColor( cGray, cGray, cGray ); - } - - aBmp = Bitmap( aSize, 8, &aGrayPal ); - } - else - aBmp = Bitmap( aSize, 24 ); - - if ( bSetLogSize ) - { - unsigned long nUnit = ((JPEGCreateBitmapParam*)pParam)->density_unit; - - if( ( ( 1 == nUnit ) || ( 2 == nUnit ) ) && - ( (JPEGCreateBitmapParam*) pParam )->X_density && - ( (JPEGCreateBitmapParam*) pParam )->Y_density ) - { - Point aEmptyPoint; - Fraction aFractX( 1, ((JPEGCreateBitmapParam*)pParam)->X_density ); - Fraction aFractY( 1, ((JPEGCreateBitmapParam*)pParam)->Y_density ); - MapMode aMapMode( nUnit == 1 ? MAP_INCH : MAP_CM, aEmptyPoint, aFractX, aFractY ); - Size aPrefSize = OutputDevice::LogicToLogic( aSize, aMapMode, MAP_100TH_MM ); - - aBmp.SetPrefSize( aPrefSize ); - aBmp.SetPrefMapMode( MapMode( MAP_100TH_MM ) ); - } - } - - pAcc = aBmp.AcquireWriteAccess(); - - if( pAcc ) - { - long nAlignedWidth; - - const ULONG nFormat = pAcc->GetScanlineFormat(); - - if( - ( bGray && ( BMP_FORMAT_8BIT_PAL == nFormat ) ) || - ( !bGray && ( BMP_FORMAT_24BIT_TC_RGB == nFormat ) ) - ) - { - pBmpBuf = pAcc->GetBuffer(); - nAlignedWidth = pAcc->GetScanlineSize(); - ((JPEGCreateBitmapParam*)pParam)->bTopDown = pAcc->IsTopDown(); - } - else - { - nAlignedWidth = AlignedWidth4Bytes( aSize.Width() * ( bGray ? 8 : 24 ) ); - ((JPEGCreateBitmapParam*)pParam)->bTopDown = TRUE; - pBmpBuf = pBuffer = rtl_allocateMemory( nAlignedWidth * aSize.Height() ); - } - ((JPEGCreateBitmapParam*)pParam)->nAlignedWidth = nAlignedWidth; - } - - return pBmpBuf; -} - -// ------------------------------------------------------------------------ - -void JPEGReader::FillBitmap() -{ - if( pBuffer && pAcc ) - { - HPBYTE pTmp; - BitmapColor aColor; - long nAlignedWidth; - long nWidth = pAcc->Width(); - long nHeight = pAcc->Height(); - - if( pAcc->GetBitCount() == 8 ) - { - BitmapColor* pCols = new BitmapColor[ 256 ]; - - for( USHORT n = 0; n < 256; n++ ) - { - const BYTE cGray = (BYTE) n; - pCols[ n ] = pAcc->GetBestMatchingColor( BitmapColor( cGray, cGray, cGray ) ); - } - - nAlignedWidth = AlignedWidth4Bytes( pAcc->Width() * 8L ); - - for( long nY = 0L; nY < nHeight; nY++ ) - { - pTmp = (BYTE*) pBuffer + nY * nAlignedWidth; - - for( long nX = 0L; nX < nWidth; nX++ ) - pAcc->SetPixel( nY, nX, pCols[ *pTmp++ ] ); - } - - delete[] pCols; - } - else - { - nAlignedWidth = AlignedWidth4Bytes( pAcc->Width() * 24L ); - - for( long nY = 0L; nY < nHeight; nY++ ) - { - pTmp = (BYTE*) pBuffer + nY * nAlignedWidth; - - for( long nX = 0L; nX < nWidth; nX++ ) - { - aColor.SetRed( *pTmp++ ); - aColor.SetGreen( *pTmp++ ); - aColor.SetBlue( *pTmp++ ); - pAcc->SetPixel( nY, nX, aColor ); - } - } - } - } -} - -// ------------------------------------------------------------------------ - -Graphic JPEGReader::CreateIntermediateGraphic( const Bitmap& rBitmap, long nLines ) -{ - Graphic aGraphic; - const Size aSizePix( rBitmap.GetSizePixel() ); - - if( !nLastLines ) - { - if( pAcc1 ) - aBmp1.ReleaseAccess( pAcc1 ); - - aBmp1 = Bitmap( rBitmap.GetSizePixel(), 1 ); - aBmp1.Erase( Color( COL_WHITE ) ); - pAcc1 = aBmp1.AcquireWriteAccess(); - } - - if( nLines && ( nLines < aSizePix.Height() ) ) - { - if( pAcc1 ) - { - const long nNewLines = nLines - nLastLines; - - if( nNewLines ) - { - pAcc1->SetFillColor( Color( COL_BLACK ) ); - pAcc1->FillRect( Rectangle( Point( 0, nLastLines ), - Size( pAcc1->Width(), nNewLines ) ) ); - } - - aBmp1.ReleaseAccess( pAcc1 ); - aGraphic = BitmapEx( rBitmap, aBmp1 ); - pAcc1 = aBmp1.AcquireWriteAccess(); - } - else - aGraphic = rBitmap; - } - else - aGraphic = rBitmap; - - nLastLines = nLines; - - return aGraphic; -} - -// ------------------------------------------------------------------------ - -ReadState JPEGReader::Read( Graphic& rGraphic ) -{ - long nEndPos; - long nLines; - ReadState eReadState; - BOOL bRet = FALSE; - BYTE cDummy; - -#if 1 // TODO: is it possible to get rid of this seek to the end? - // check if the stream's end is already available - rIStm.Seek( STREAM_SEEK_TO_END ); - rIStm >> cDummy; - nEndPos = rIStm.Tell(); - - // else check if at least JPEGMINREAD bytes can be read - if( rIStm.GetError() == ERRCODE_IO_PENDING ) - { - rIStm.ResetError(); - if( ( nEndPos - nFormerPos ) < JPEGMINREAD ) - { - rIStm.Seek( nLastPos ); - return JPEGREAD_NEED_MORE; - } - } - - // seek back to the original position - rIStm.Seek( nLastPos ); -#endif - - Size aPreviewSize = GetPreviewSize(); - SetJpegPreviewSizeHint( aPreviewSize.Width(), aPreviewSize.Height() ); - - // read the (partial) image - ReadJPEG( this, &rIStm, &nLines ); - - if( pAcc ) - { - if( pBuffer ) - { - FillBitmap(); - rtl_freeMemory( pBuffer ); - pBuffer = NULL; - } - - aBmp.ReleaseAccess( pAcc ); - pAcc = NULL; - - if( rIStm.GetError() == ERRCODE_IO_PENDING ) - rGraphic = CreateIntermediateGraphic( aBmp, nLines ); - else - rGraphic = aBmp; - - bRet = TRUE; - } - else if( rIStm.GetError() == ERRCODE_IO_PENDING ) - bRet = TRUE; - - // Status setzen ( Pending hat immer Vorrang ) - if( rIStm.GetError() == ERRCODE_IO_PENDING ) - { - eReadState = JPEGREAD_NEED_MORE; - rIStm.ResetError(); - nFormerPos = rIStm.Tell(); - } - else - { - if( bRet ) - eReadState = JPEGREAD_OK; - else - eReadState = JPEGREAD_ERROR; - } - - return eReadState; -} - - -// -------------- -// - JPEGWriter - -// -------------- - -JPEGWriter::JPEGWriter( SvStream& rStm, const uno::Sequence< beans::PropertyValue >* pFilterData, bool* pExportWasGrey ) : - rOStm ( rStm ), - pAcc ( NULL ), - pBuffer ( NULL ), - pExpWasGrey ( pExportWasGrey ) -{ - FilterConfigItem aConfigItem( (uno::Sequence< beans::PropertyValue >*)pFilterData ); - bGreys = aConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "ColorMode" ) ), 0 ) != 0; - nQuality = aConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Quality" ) ), 75 ); - - if ( pFilterData ) - { - int nArgs = pFilterData->getLength(); - const beans::PropertyValue* pValues = pFilterData->getConstArray(); - while( nArgs-- ) - { - if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StatusIndicator" ) ) ) - { - pValues->Value >>= xStatusIndicator; - } - pValues++; - } - } -} - -// ------------------------------------------------------------------------ - -void* JPEGWriter::GetScanline( long nY ) -{ - void* pScanline = NULL; - - if( pAcc ) - { - if( bNative ) - pScanline = pAcc->GetScanline( nY ); - else if( pBuffer ) - { - BitmapColor aColor; - long nWidth = pAcc->Width(); - BYTE* pTmp = pBuffer; - - if( pAcc->HasPalette() ) - { - for( long nX = 0L; nX < nWidth; nX++ ) - { - aColor = pAcc->GetPaletteColor( (BYTE) pAcc->GetPixel( nY, nX ) ); - *pTmp++ = aColor.GetRed(); - if ( bGreys ) - continue; - *pTmp++ = aColor.GetGreen(); - *pTmp++ = aColor.GetBlue(); - } - } - else - { - for( long nX = 0L; nX < nWidth; nX++ ) - { - aColor = pAcc->GetPixel( nY, nX ); - *pTmp++ = aColor.GetRed(); - if ( bGreys ) - continue; - *pTmp++ = aColor.GetGreen(); - *pTmp++ = aColor.GetBlue(); - } - } - - pScanline = pBuffer; - } - } - - return pScanline; -} - -// ------------------------------------------------------------------------ - -BOOL JPEGWriter::Write( const Graphic& rGraphic ) -{ - BOOL bRet = FALSE; - - if ( xStatusIndicator.is() ) - { - rtl::OUString aMsg; - xStatusIndicator->start( aMsg, 100 ); - } - - Bitmap aGraphicBmp( rGraphic.GetBitmap() ); - - if ( bGreys ) - { - if ( !aGraphicBmp.Convert( BMP_CONVERSION_8BIT_GREYS ) ) - aGraphicBmp = rGraphic.GetBitmap(); - } - - pAcc = aGraphicBmp.AcquireReadAccess(); - - if ( !bGreys ) // bitmap was not explicitely converted into greyscale, - { // check if source is greyscale only - - sal_Bool bIsGrey = sal_True; - - long nWidth = pAcc->Width(); - for ( long nY = 0; bIsGrey && ( nY < pAcc->Height() ); nY++ ) - { - BitmapColor aColor; - for( long nX = 0L; bIsGrey && ( nX < nWidth ); nX++ ) - { - aColor = pAcc->HasPalette() ? pAcc->GetPaletteColor( (BYTE) pAcc->GetPixel( nY, nX ) ) - : pAcc->GetPixel( nY, nX ); - bIsGrey = ( aColor.GetRed() == aColor.GetGreen() ) && ( aColor.GetRed() == aColor.GetBlue() ); - } - } - if ( bIsGrey ) - bGreys = sal_True; - } - - if( pExpWasGrey ) - *pExpWasGrey = bGreys; - - if( pAcc ) - { - bNative = ( pAcc->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_RGB ); - - if( !bNative ) - pBuffer = new BYTE[ AlignedWidth4Bytes( bGreys ? pAcc->Width() * 8L : pAcc->Width() * 24L ) ]; - - JPEGCallbackStruct aCallbackData; - aCallbackData.xStatusIndicator = xStatusIndicator; - bRet = (BOOL) WriteJPEG( this, &rOStm, pAcc->Width(), pAcc->Height(), bGreys, nQuality, &aCallbackData ); - - delete[] pBuffer; - pBuffer = NULL; - - aGraphicBmp.ReleaseAccess( pAcc ); - pAcc = NULL; - } - if ( xStatusIndicator.is() ) - xStatusIndicator->end(); - - return bRet; -} - -// -------------- -// - ImportJPEG - -// -------------- - -BOOL ImportJPEG( SvStream& rStm, Graphic& rGraphic, void* pCallerData, sal_Int32 nImportFlags ) -{ - JPEGReader* pJPEGReader = (JPEGReader*) rGraphic.GetContext(); - ReadState eReadState; - BOOL bRet = TRUE; - - if( !pJPEGReader ) - pJPEGReader = new JPEGReader( rStm, pCallerData, ( nImportFlags & GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG ) != 0 ); - - if( nImportFlags & GRFILTER_I_FLAGS_FOR_PREVIEW ) - pJPEGReader->SetPreviewSize( Size(128,128) ); - else - pJPEGReader->DisablePreviewMode(); - - rGraphic.SetContext( NULL ); - eReadState = pJPEGReader->Read( rGraphic ); - - if( eReadState == JPEGREAD_ERROR ) - { - bRet = FALSE; - delete pJPEGReader; - } - else if( eReadState == JPEGREAD_OK ) - delete pJPEGReader; - else - rGraphic.SetContext( pJPEGReader ); - - return bRet; -} - -// -------------- -// - ExportJPEG - -// -------------- - -BOOL ExportJPEG( SvStream& rOStm, const Graphic& rGraphic, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >* pFilterData, - bool* pExportWasGrey - ) -{ - JPEGWriter aJPEGWriter( rOStm, pFilterData, pExportWasGrey ); - return aJPEGWriter.Write( rGraphic ); -} diff --git a/svtools/source/filter.vcl/jpeg/jpeg.h b/svtools/source/filter.vcl/jpeg/jpeg.h deleted file mode 100644 index 82a2f80a838c..000000000000 --- a/svtools/source/filter.vcl/jpeg/jpeg.h +++ /dev/null @@ -1,71 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _JPEG_H -#define _JPEG_H - -#if defined( ICC ) -#include -#endif - -#if defined (UNX) || defined(__MINGW32__) -#include -#endif - -struct JPEGCreateBitmapParam -{ - unsigned long nWidth; - unsigned long nHeight; - unsigned long density_unit; - unsigned long X_density; - unsigned long Y_density; - long bGray; - - long nAlignedWidth; // these members will be filled by the - long bTopDown; // CreateBitmap method in svtools -}; - -typedef struct my_error_mgr* my_error_ptr; -typedef unsigned char BYTE; -typedef unsigned char* HPBYTE; - -void* JPEGMalloc( size_t size ); -void JPEGFree( void *ptr ); -long JPEGCallback( void* pCallbackData, long nPercent ); - -long WriteJPEG( void* pJPEGWriter, void* pOStm, long nWidth, long nHeight, long bGreyScale, - long nQualityPercent, void* pCallbackData ); -void* GetScanline( void* pJPEGWriter, long nY ); - -void ReadJPEG( void* pJPEGReader, void* pIStm, long* pLines ); -void* CreateBitmap( void* pJPEGReader, void* pJPEGCreateBitmapParam ); - -/* TODO: when incompatible changes are possible again - the preview size hint should be redone */ -void SetJpegPreviewSizeHint( int nWidth, int nHeight ); - -#endif diff --git a/svtools/source/filter.vcl/jpeg/jpegc.c b/svtools/source/filter.vcl/jpeg/jpegc.c deleted file mode 100644 index 29b4749a7b51..000000000000 --- a/svtools/source/filter.vcl/jpeg/jpegc.c +++ /dev/null @@ -1,284 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include -#include -#include "setjmp.h" -#include "jpeglib.h" -#include "jerror.h" -#include "jpeg.h" -#include "rtl/alloc.h" -#include "osl/diagnose.h" - -struct my_error_mgr -{ - struct jpeg_error_mgr pub; - jmp_buf setjmp_buffer; -}; - -void jpeg_svstream_src (j_decompress_ptr cinfo, void* infile); -void jpeg_svstream_dest (j_compress_ptr cinfo, void* outfile); - -METHODDEF( void ) -my_error_exit (j_common_ptr cinfo) -{ - my_error_ptr myerr = (my_error_ptr) cinfo->err; - (*cinfo->err->output_message) (cinfo); - longjmp(myerr->setjmp_buffer, 1); -} - - -METHODDEF( void ) -my_output_message (j_common_ptr cinfo) -{ - char buffer[JMSG_LENGTH_MAX]; - (*cinfo->err->format_message) (cinfo, buffer); -} - -/* TODO: when incompatible changes are possible again - the preview size hint should be redone */ -static int nPreviewWidth = 0; -static int nPreviewHeight = 0; -void SetJpegPreviewSizeHint( int nWidth, int nHeight ) -{ - nPreviewWidth = nWidth; - nPreviewHeight = nHeight; -} - -void ReadJPEG( void* pJPEGReader, void* pIStm, long* pLines ) -{ - struct jpeg_decompress_struct cinfo; - struct my_error_mgr jerr; - struct JPEGCreateBitmapParam aCreateBitmapParam; - HPBYTE pDIB; - HPBYTE pTmp; - long nWidth; - long nHeight; - long nAlignedWidth; - JSAMPLE * range_limit; - HPBYTE pScanLineBuffer = NULL; - long nScanLineBufferComponents = 0; - // declare bDecompCreated volatile because of gcc - // warning: variable 'bDecompCreated' might be clobbered by `longjmp' or `vfork' - volatile long bDecompCreated = 0; - - /* Falls der Stream nicht ausreicht (IO_PENDING) - wird ueber ein longjmp in der Schleife nach Exit - gesprungen, wir geben dann die Anzahl - der bisher bearbeiteten Scanlines zurueck*/ - if ( setjmp( jerr.setjmp_buffer ) ) - goto Exit; - - cinfo.err = jpeg_std_error( &jerr.pub ); - jerr.pub.error_exit = my_error_exit; - jerr.pub.output_message = my_output_message; - - jpeg_create_decompress( &cinfo ); - bDecompCreated = 1; - jpeg_svstream_src( &cinfo, pIStm ); - jpeg_read_header( &cinfo, TRUE ); - - cinfo.scale_num = 1; - cinfo.scale_denom = 1; - cinfo.output_gamma = 1.0; - cinfo.raw_data_out = FALSE; - cinfo.quantize_colors = FALSE; - if ( cinfo.jpeg_color_space == JCS_YCbCr ) - cinfo.out_color_space = JCS_RGB; - else if ( cinfo.jpeg_color_space == JCS_YCCK ) - cinfo.out_color_space = JCS_CMYK; - - OSL_ASSERT(cinfo.out_color_space == JCS_CMYK || cinfo.out_color_space == JCS_GRAYSCALE || cinfo.out_color_space == JCS_RGB); - - /* change scale for preview import */ - if( nPreviewWidth || nPreviewHeight ) - { - if( nPreviewWidth == 0 ) { - nPreviewWidth = ( cinfo.image_width*nPreviewHeight )/cinfo.image_height; - if( nPreviewWidth <= 0 ) - nPreviewWidth = 1; - } else if( nPreviewHeight == 0 ) { - nPreviewHeight = ( cinfo.image_height*nPreviewWidth )/cinfo.image_width; - if( nPreviewHeight <= 0 ) - nPreviewHeight = 1; - } - - for( cinfo.scale_denom = 1; cinfo.scale_denom < 8; cinfo.scale_denom *= 2 ) - { - if( cinfo.image_width < nPreviewWidth * cinfo.scale_denom ) - break; - if( cinfo.image_height < nPreviewHeight * cinfo.scale_denom ) - break; - } - - if( cinfo.scale_denom > 1 ) - { - cinfo.dct_method = JDCT_FASTEST; - cinfo.do_fancy_upsampling = FALSE; - cinfo.do_block_smoothing = FALSE; - } - } - - jpeg_start_decompress( &cinfo ); - - nWidth = cinfo.output_width; - nHeight = cinfo.output_height; - aCreateBitmapParam.nWidth = nWidth; - aCreateBitmapParam.nHeight = nHeight; - - aCreateBitmapParam.density_unit = cinfo.density_unit; - aCreateBitmapParam.X_density = cinfo.X_density; - aCreateBitmapParam.Y_density = cinfo.Y_density; - aCreateBitmapParam.bGray = cinfo.output_components == 1; - pDIB = CreateBitmap( pJPEGReader, &aCreateBitmapParam ); - nAlignedWidth = aCreateBitmapParam.nAlignedWidth; - range_limit=cinfo.sample_range_limit; - - if ( cinfo.out_color_space == JCS_CMYK ) - { - nScanLineBufferComponents = cinfo.output_width * 4; - pScanLineBuffer = rtl_allocateMemory( nScanLineBufferComponents ); - } - - if( pDIB ) - { - if( aCreateBitmapParam.bTopDown ) - pTmp = pDIB; - else - { - pTmp = pDIB + ( nHeight - 1 ) * nAlignedWidth; - nAlignedWidth = -nAlignedWidth; - } - - for ( *pLines = 0; *pLines < nHeight; (*pLines)++ ) - { - if (pScanLineBuffer!=NULL) { // in other words cinfo.out_color_space == JCS_CMYK - int i; - int j; - jpeg_read_scanlines( &cinfo, (JSAMPARRAY) &pScanLineBuffer, 1 ); - // convert CMYK to RGB - for( i=0, j=0; i < nScanLineBufferComponents; i+=4, j+=3 ) - { - int c_=255-pScanLineBuffer[i+0]; - int m_=255-pScanLineBuffer[i+1]; - int y_=255-pScanLineBuffer[i+2]; - int k_=255-pScanLineBuffer[i+3]; - pTmp[j+0]=range_limit[ 255L - ( c_ + k_ ) ]; - pTmp[j+1]=range_limit[ 255L - ( m_ + k_ ) ]; - pTmp[j+2]=range_limit[ 255L - ( y_ + k_ ) ]; - } - } else { - jpeg_read_scanlines( &cinfo, (JSAMPARRAY) &pTmp, 1 ); - } - /* PENDING ??? */ - if ( cinfo.err->msg_code == 113 ) - break; - - pTmp += nAlignedWidth; - } - } - - jpeg_finish_decompress( &cinfo ); - if (pScanLineBuffer!=NULL) { - rtl_freeMemory( pScanLineBuffer ); - pScanLineBuffer=NULL; - } - -Exit: - - if( bDecompCreated ) - jpeg_destroy_decompress( &cinfo ); -} - -long WriteJPEG( void* pJPEGWriter, void* pOStm, - long nWidth, long nHeight, long bGreys, - long nQualityPercent, void* pCallbackData ) -{ - struct jpeg_compress_struct cinfo; - struct my_error_mgr jerr; - void* pScanline; - long nY; - // declare bCompCreated, bRet volatile because of gcc - // warning: variable 'bCompCreated' might be clobbered by `longjmp' or `vfork' - volatile long bCompCreated = 0; - volatile long bRet = 0; - - if ( setjmp( jerr.setjmp_buffer ) ) - goto Exit; - - cinfo.err = jpeg_std_error( &jerr.pub ); - jerr.pub.error_exit = my_error_exit; - jerr.pub.output_message = my_output_message; - - jpeg_create_compress( &cinfo ); - bCompCreated = 1; - - jpeg_svstream_dest( &cinfo, pOStm ); - - cinfo.image_width = (JDIMENSION) nWidth; - cinfo.image_height = (JDIMENSION) nHeight; - if ( bGreys ) - { - cinfo.input_components = 1; - cinfo.in_color_space = JCS_GRAYSCALE; - } - else - { - cinfo.input_components = 3; - cinfo.in_color_space = JCS_RGB; - } - - jpeg_set_defaults( &cinfo ); - jpeg_set_quality( &cinfo, (int) nQualityPercent, FALSE ); - - if ( ( nWidth > 128 ) || ( nHeight > 128 ) ) - jpeg_simple_progression( &cinfo ); - - jpeg_start_compress( &cinfo, TRUE ); - - for( nY = 0; nY < nHeight; nY++ ) - { - pScanline = GetScanline( pJPEGWriter, nY ); - - if( pScanline ) - jpeg_write_scanlines( &cinfo, (JSAMPARRAY) &pScanline, 1 ); - - if( JPEGCallback( pCallbackData, nY * 100L / nHeight ) ) - goto Exit; - } - - bRet = 1; - - jpeg_finish_compress(&cinfo); - -Exit: - - if ( bCompCreated ) - jpeg_destroy_compress( &cinfo ); - - return bRet; -} diff --git a/svtools/source/filter.vcl/wmf/emfwr.cxx b/svtools/source/filter.vcl/wmf/emfwr.cxx deleted file mode 100644 index f31fd4439e9f..000000000000 --- a/svtools/source/filter.vcl/wmf/emfwr.cxx +++ /dev/null @@ -1,1415 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#include "emfwr.hxx" -#include -#include -#include -#include - -// ----------- -// - Defines - -// ----------- - -#define WIN_EMR_HEADER 1 -#define WIN_EMR_POLYBEZIER 2 -#define WIN_EMR_POLYGON 3 -#define WIN_EMR_POLYLINE 4 -#define WIN_EMR_POLYBEZIERTO 5 -#define WIN_EMR_POLYLINETO 6 -#define WIN_EMR_POLYPOLYLINE 7 -#define WIN_EMR_POLYPOLYGON 8 -#define WIN_EMR_SETWINDOWEXTEX 9 -#define WIN_EMR_SETWINDOWORGEX 10 -#define WIN_EMR_SETVIEWPORTEXTEX 11 -#define WIN_EMR_SETVIEWPORTORGEX 12 -#define WIN_EMR_SETBRUSHORGEX 13 -#define WIN_EMR_EOF 14 -#define WIN_EMR_SETPIXELV 15 -#define WIN_EMR_SETMAPPERFLAGS 16 -#define WIN_EMR_SETMAPMODE 17 -#define WIN_EMR_SETBKMODE 18 -#define WIN_EMR_SETPOLYFILLMODE 19 -#define WIN_EMR_SETROP2 20 -#define WIN_EMR_SETSTRETCHBLTMODE 21 -#define WIN_EMR_SETTEXTALIGN 22 -#define WIN_EMR_SETCOLORADJUSTMENT 23 -#define WIN_EMR_SETTEXTCOLOR 24 -#define WIN_EMR_SETBKCOLOR 25 -#define WIN_EMR_OFFSETCLIPRGN 26 -#define WIN_EMR_MOVETOEX 27 -#define WIN_EMR_SETMETARGN 28 -#define WIN_EMR_EXCLUDECLIPRECT 29 -#define WIN_EMR_INTERSECTCLIPRECT 30 -#define WIN_EMR_SCALEVIEWPORTEXTEX 31 -#define WIN_EMR_SCALEWINDOWEXTEX 32 -#define WIN_EMR_SAVEDC 33 -#define WIN_EMR_RESTOREDC 34 -#define WIN_EMR_SETWORLDTRANSFORM 35 -#define WIN_EMR_MODIFYWORLDTRANSFORM 36 -#define WIN_EMR_SELECTOBJECT 37 -#define WIN_EMR_CREATEPEN 38 -#define WIN_EMR_CREATEBRUSHINDIRECT 39 -#define WIN_EMR_DELETEOBJECT 40 -#define WIN_EMR_ANGLEARC 41 -#define WIN_EMR_ELLIPSE 42 -#define WIN_EMR_RECTANGLE 43 -#define WIN_EMR_ROUNDRECT 44 -#define WIN_EMR_ARC 45 -#define WIN_EMR_CHORD 46 -#define WIN_EMR_PIE 47 -#define WIN_EMR_SELECTPALETTE 48 -#define WIN_EMR_CREATEPALETTE 49 -#define WIN_EMR_SETPALETTEENTRIES 50 -#define WIN_EMR_RESIZEPALETTE 51 -#define WIN_EMR_REALIZEPALETTE 52 -#define WIN_EMR_EXTFLOODFILL 53 -#define WIN_EMR_LINETO 54 -#define WIN_EMR_ARCTO 55 -#define WIN_EMR_POLYDRAW 56 -#define WIN_EMR_SETARCDIRECTION 57 -#define WIN_EMR_SETMITERLIMIT 58 -#define WIN_EMR_BEGINPATH 59 -#define WIN_EMR_ENDPATH 60 -#define WIN_EMR_CLOSEFIGURE 61 -#define WIN_EMR_FILLPATH 62 -#define WIN_EMR_STROKEANDFILLPATH 63 -#define WIN_EMR_STROKEPATH 64 -#define WIN_EMR_FLATTENPATH 65 -#define WIN_EMR_WIDENPATH 66 -#define WIN_EMR_SELECTCLIPPATH 67 -#define WIN_EMR_ABORTPATH 68 - -#define WIN_EMR_GDICOMMENT 70 -#define WIN_EMR_FILLRGN 71 -#define WIN_EMR_FRAMERGN 72 -#define WIN_EMR_INVERTRGN 73 -#define WIN_EMR_PAINTRGN 74 -#define WIN_EMR_EXTSELECTCLIPRGN 75 -#define WIN_EMR_BITBLT 76 -#define WIN_EMR_STRETCHBLT 77 -#define WIN_EMR_MASKBLT 78 -#define WIN_EMR_PLGBLT 79 -#define WIN_EMR_SETDIBITSTODEVICE 80 -#define WIN_EMR_STRETCHDIBITS 81 -#define WIN_EMR_EXTCREATEFONTINDIRECTW 82 -#define WIN_EMR_EXTTEXTOUTA 83 -#define WIN_EMR_EXTTEXTOUTW 84 -#define WIN_EMR_POLYBEZIER16 85 -#define WIN_EMR_POLYGON16 86 -#define WIN_EMR_POLYLINE16 87 -#define WIN_EMR_POLYBEZIERTO16 88 -#define WIN_EMR_POLYLINETO16 89 -#define WIN_EMR_POLYPOLYLINE16 90 -#define WIN_EMR_POLYPOLYGON16 91 -#define WIN_EMR_POLYDRAW16 92 -#define WIN_EMR_CREATEMONOBRUSH 93 -#define WIN_EMR_CREATEDIBPATTERNBRUSHPT 94 -#define WIN_EMR_EXTCREATEPEN 95 -#define WIN_EMR_POLYTEXTOUTA 96 -#define WIN_EMR_POLYTEXTOUTW 97 - -#define WIN_SRCCOPY 0x00CC0020L -#define WIN_SRCPAINT 0x00EE0086L -#define WIN_SRCAND 0x008800C6L -#define WIN_SRCINVERT 0x00660046L - -#define HANDLE_INVALID 0xffffffff -#define MAXHANDLES 65000 - -#define LINE_SELECT 0x00000001 -#define FILL_SELECT 0x00000002 -#define TEXT_SELECT 0x00000004 - -/* Text Alignment Options */ -#define TA_NOUPDATECP 0 -#define TA_UPDATECP 1 - -#define TA_LEFT 0 -#define TA_RIGHT 2 -#define TA_CENTER 6 - -#define TA_TOP 0 -#define TA_BOTTOM 8 -#define TA_BASELINE 24 -#define TA_RTLREADING 256 -#define TA_MASK (TA_BASELINE+TA_CENTER+TA_UPDATECP+TA_RTLREADING) - -#define MM_ANISOTROPIC 8 - -// ------------- -// - EMFWriter - -// ------------- - -BOOL EMFWriter::WriteEMF( const GDIMetaFile& rMtf, SvStream& rOStm, FilterConfigItem* pFilterConfigItem ) -{ - const ULONG nHeaderPos = rOStm.Tell(); - - mpHandlesUsed = new BOOL[ MAXHANDLES ]; - memset( mpHandlesUsed, 0, MAXHANDLES * sizeof( BOOL ) ); - mnHorTextAlign = mnHandleCount = mnLastPercent = mnRecordPos = mnRecordCount = 0; - mnLineHandle = mnFillHandle = mnTextHandle = HANDLE_INVALID; - mbRecordOpen = FALSE; - - mpStm = &rOStm; - maVDev.EnableOutput( FALSE ); - maVDev.SetMapMode( rMtf.GetPrefMapMode() ); - mpFilterConfigItem = pFilterConfigItem; - - // don't work with pixel as destination map mode -> higher resolution preferrable - maDestMapMode.SetMapUnit( MAP_100TH_MM ); - - const Size aMtfSizePix( maVDev.LogicToPixel( rMtf.GetPrefSize(), rMtf.GetPrefMapMode() ) ); - const Size aMtfSizeLog( maVDev.LogicToLogic( rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), MAP_100TH_MM ) ); - - // seek over header - // use [MS-EMF 2.2.11] HeaderExtension2 Object, otherwise resulting EMF cannot be converted with GetWinMetaFileBits() - rOStm.SeekRel( 108 ); - - // write initial values - - // set 100th mm map mode in EMF - ImplBeginRecord( WIN_EMR_SETMAPMODE ); - (*mpStm) << (INT32) MM_ANISOTROPIC; - ImplEndRecord(); - - ImplBeginRecord( WIN_EMR_SETVIEWPORTEXTEX ); - (*mpStm) << (INT32) maVDev.ImplGetDPIX() << (INT32) maVDev.ImplGetDPIY(); - ImplEndRecord(); - - ImplBeginRecord( WIN_EMR_SETWINDOWEXTEX ); - (*mpStm) << (INT32) 2540 << (INT32) 2540; - ImplEndRecord(); - - ImplBeginRecord( WIN_EMR_SETVIEWPORTORGEX ); - (*mpStm) << (INT32) 0 << (INT32) 0; - ImplEndRecord(); - - ImplBeginRecord( WIN_EMR_SETWINDOWORGEX ); - (*mpStm) << (INT32) 0 << (INT32) 0; - ImplEndRecord(); - - ImplWriteRasterOp( ROP_OVERPAINT ); - - ImplBeginRecord( WIN_EMR_SETBKMODE ); - (*mpStm) << (UINT32) 1; // TRANSPARENT - ImplEndRecord(); - - // write emf data - ImplWrite( rMtf ); - - ImplBeginRecord( WIN_EMR_EOF ); - (*mpStm)<< (sal_uInt32)0 // nPalEntries - << (sal_uInt32)0x10 // offPalEntries - << (sal_uInt32)0x14; // nSizeLast - ImplEndRecord(); - - - // write header - const ULONG nEndPos = mpStm->Tell(); mpStm->Seek( nHeaderPos ); - - (*mpStm) << (UINT32) 0x00000001 << (UINT32) 108 //use [MS-EMF 2.2.11] HeaderExtension2 Object - << (INT32) 0 << (INT32) 0 << (INT32) ( aMtfSizePix.Width() - 1 ) << (INT32) ( aMtfSizePix.Height() - 1 ) - << (INT32) 0 << (INT32) 0 << (INT32) ( aMtfSizeLog.Width() - 1 ) << (INT32) ( aMtfSizeLog.Height() - 1 ) - << (UINT32) 0x464d4520 << (UINT32) 0x10000 << (UINT32) ( nEndPos - nHeaderPos ) - << (UINT32) mnRecordCount << (UINT16) ( mnHandleCount + 1 ) << (UINT16) 0 << (UINT32) 0 << (UINT32) 0 << (UINT32) 0 - << (INT32) aMtfSizePix.Width() << (INT32) aMtfSizePix.Height() - << (INT32) ( aMtfSizeLog.Width() / 100 ) << (INT32) ( aMtfSizeLog.Height() / 100 ) - << (UINT32) 0 << (UINT32) 0 << (UINT32) 0 - << (INT32) ( aMtfSizeLog.Width() * 10 ) << (INT32) ( aMtfSizeLog.Height() * 10 ); //use [MS-EMF 2.2.11] HeaderExtension2 Object - - mpStm->Seek( nEndPos ); - delete[] mpHandlesUsed; - - return( mpStm->GetError() == ERRCODE_NONE ); -} - -// ----------------------------------------------------------------------------- - -ULONG EMFWriter::ImplAcquireHandle() -{ - ULONG nHandle = HANDLE_INVALID; - - for( ULONG i = 0; i < MAXHANDLES && ( HANDLE_INVALID == nHandle ); i++ ) - { - if( !mpHandlesUsed[ i ] ) - { - mpHandlesUsed[ i ] = TRUE; - - if( ( nHandle = i ) == mnHandleCount ) - mnHandleCount++; - } - } - - DBG_ASSERT( nHandle != HANDLE_INVALID, "No more handles available" ); - return( nHandle != HANDLE_INVALID ? nHandle + 1 : HANDLE_INVALID ); -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplReleaseHandle( ULONG nHandle ) -{ - DBG_ASSERT( nHandle && ( nHandle < MAXHANDLES ), "Handle out of range" ); - mpHandlesUsed[ nHandle - 1 ] = FALSE; -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplBeginRecord( sal_uInt32 nType ) -{ - DBG_ASSERT( !mbRecordOpen, "Another record is already opened!" ); - - if( !mbRecordOpen ) - { - mbRecordOpen = TRUE; - mnRecordPos = mpStm->Tell(); - - (*mpStm) << nType; - mpStm->SeekRel( 4 ); - } -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplEndRecord() -{ - DBG_ASSERT( mbRecordOpen, "Record was not opened!" ); - - if( mbRecordOpen ) - { - sal_Int32 nFillBytes, nActPos = mpStm->Tell(); - mpStm->Seek( mnRecordPos + 4 ); - nFillBytes = nActPos - mnRecordPos; - nFillBytes += 3; // each record has to be dword aligned - nFillBytes ^= 3; - nFillBytes &= 3; - *mpStm << (sal_uInt32)( ( nActPos - mnRecordPos ) + nFillBytes ); - mpStm->Seek( nActPos ); - while( nFillBytes-- ) - *mpStm << (sal_uInt8)0; - mnRecordCount++; - mbRecordOpen = FALSE; - } -} - -// ----------------------------------------------------------------------------- - -BOOL EMFWriter::ImplPrepareHandleSelect( sal_uInt32& rHandle, ULONG nSelectType ) -{ - if( rHandle != HANDLE_INVALID ) - { - UINT32 nStockObject = 0x80000000; - - if( LINE_SELECT == nSelectType ) - nStockObject |= 0x00000007; - else if( FILL_SELECT == nSelectType ) - nStockObject |= 0x00000001; - else if( TEXT_SELECT == nSelectType ) - nStockObject |= 0x0000000a; - - // select stock object first - ImplBeginRecord( WIN_EMR_SELECTOBJECT ); - ( *mpStm ) << nStockObject; - ImplEndRecord(); - - // destroy handle of created object - ImplBeginRecord( WIN_EMR_DELETEOBJECT ); - ( *mpStm ) << rHandle; - ImplEndRecord(); - - // mark handle as free - ImplReleaseHandle( rHandle ); - } - - rHandle = ImplAcquireHandle(); - - return( HANDLE_INVALID != rHandle ); -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplCheckLineAttr() -{ - if( mbLineChanged && ImplPrepareHandleSelect( mnLineHandle, LINE_SELECT ) ) - { - sal_uInt32 nStyle = maVDev.IsLineColor() ? 0 : 5; - sal_uInt32 nWidth = 0, nHeight = 0; - - ImplBeginRecord( WIN_EMR_CREATEPEN ); - (*mpStm) << mnLineHandle << nStyle << nWidth << nHeight; - ImplWriteColor( maVDev.GetLineColor() ); - ImplEndRecord(); - - ImplBeginRecord( WIN_EMR_SELECTOBJECT ); - (*mpStm) << mnLineHandle; - ImplEndRecord(); - } -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplCheckFillAttr() -{ - if( mbFillChanged && ImplPrepareHandleSelect( mnFillHandle, FILL_SELECT ) ) - { - sal_uInt32 nStyle = maVDev.IsFillColor() ? 0 : 1; - sal_uInt32 nPatternStyle = 0; - - ImplBeginRecord( WIN_EMR_CREATEBRUSHINDIRECT ); - (*mpStm) << mnFillHandle << nStyle; - ImplWriteColor( maVDev.GetFillColor() ); - (*mpStm) << nPatternStyle; - ImplEndRecord(); - - ImplBeginRecord( WIN_EMR_SELECTOBJECT ); - (*mpStm) << mnFillHandle; - ImplEndRecord(); - } -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplCheckTextAttr() -{ - if( mbTextChanged && ImplPrepareHandleSelect( mnTextHandle, TEXT_SELECT ) ) - { - const Font& rFont = maVDev.GetFont(); - String aFontName( rFont.GetName() ); - sal_Int32 nWeight; - sal_uInt16 i; - sal_uInt8 nPitchAndFamily; - - ImplBeginRecord( WIN_EMR_EXTCREATEFONTINDIRECTW ); - (*mpStm) << mnTextHandle; - ImplWriteExtent( -rFont.GetSize().Height() ); - ImplWriteExtent( rFont.GetSize().Width() ); - (*mpStm) << (INT32) rFont.GetOrientation() << (INT32) rFont.GetOrientation(); - - switch( rFont.GetWeight() ) - { - case WEIGHT_THIN: nWeight = 100; break; - case WEIGHT_ULTRALIGHT: nWeight = 200; break; - case WEIGHT_LIGHT: nWeight = 300; break; - case WEIGHT_SEMILIGHT: nWeight = 300; break; - case WEIGHT_NORMAL: nWeight = 400; break; - case WEIGHT_MEDIUM: nWeight = 500; break; - case WEIGHT_SEMIBOLD: nWeight = 600; break; - case WEIGHT_BOLD: nWeight = 700; break; - case WEIGHT_ULTRABOLD: nWeight = 800; break; - case WEIGHT_BLACK: nWeight = 900; break; - default: nWeight = 0; break; - } - - (*mpStm) << nWeight; - (*mpStm) << (BYTE) ( ( ITALIC_NONE == rFont.GetItalic() ) ? 0 : 1 ); - (*mpStm) << (BYTE) ( ( UNDERLINE_NONE == rFont.GetUnderline() ) ? 0 : 1 ); - (*mpStm) << (BYTE) ( ( STRIKEOUT_NONE == rFont.GetStrikeout() ) ? 0 : 1 ); - (*mpStm) << (BYTE) ( ( RTL_TEXTENCODING_SYMBOL == rFont.GetCharSet() ) ? 2 : 0 ); - (*mpStm) << (BYTE) 0 << (BYTE) 0 << (BYTE) 0; - - switch( rFont.GetPitch() ) - { - case PITCH_FIXED: nPitchAndFamily = 0x01; break; - case PITCH_VARIABLE: nPitchAndFamily = 0x02; break; - default: nPitchAndFamily = 0x00; break; - } - - switch( rFont.GetFamily() ) - { - case FAMILY_DECORATIVE: nPitchAndFamily |= 0x50; break; - case FAMILY_MODERN: nPitchAndFamily |= 0x30; break; - case FAMILY_ROMAN: nPitchAndFamily |= 0x10; break; - case FAMILY_SCRIPT: nPitchAndFamily |= 0x40; break; - case FAMILY_SWISS: nPitchAndFamily |= 0x20; break; - default: break; - } - - (*mpStm) << nPitchAndFamily; - - for( i = 0; i < 32; i++ ) - (*mpStm) << (sal_Unicode) ( ( i < aFontName.Len() ) ? aFontName.GetChar( i ) : 0 ); - - // dummy elfFullName - for( i = 0; i < 64; i++ ) - (*mpStm) << (sal_Unicode) 0; - - // dummy elfStyle - for( i = 0; i < 32; i++ ) - (*mpStm) << (sal_Unicode) 0; - - // dummy elfVersion, elfStyleSize, elfMatch, elfReserved - (*mpStm) << (UINT32) 0 << (UINT32) 0 << (UINT32) 0 << (UINT32) 0 ; - - // dummy elfVendorId - (*mpStm) << (UINT32) 0; - - // dummy elfCulture - (*mpStm) << (UINT32) 0; - - // dummy elfPanose - (*mpStm) << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0; - - // fill record to get a record size divideable by 4 - (*mpStm) << (UINT16) 0; - - ImplEndRecord(); - - // TextAlign - UINT32 nTextAlign; - - switch( rFont.GetAlign() ) - { - case ALIGN_TOP: nTextAlign = TA_TOP; break; - case ALIGN_BOTTOM: nTextAlign = TA_BOTTOM; break; - default: nTextAlign = TA_BASELINE; break; - } - nTextAlign |= mnHorTextAlign; - - ImplBeginRecord( WIN_EMR_SETTEXTALIGN ); - (*mpStm) << nTextAlign; - ImplEndRecord(); - - // Text color - ImplBeginRecord( WIN_EMR_SETTEXTCOLOR ); - ImplWriteColor( maVDev.GetTextColor() ); - ImplEndRecord(); - - ImplBeginRecord( WIN_EMR_SELECTOBJECT ); - (*mpStm) << mnTextHandle; - ImplEndRecord(); - } -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplWriteColor( const Color& rColor ) -{ - UINT32 nCol = rColor.GetRed(); - - nCol |= ( (UINT32) rColor.GetGreen() ) << 8; - nCol |= ( (UINT32) rColor.GetBlue() ) << 16; - - (*mpStm) << nCol; -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplWriteRasterOp( RasterOp eRop ) -{ - UINT32 nROP2; - - switch( eRop ) - { - case ROP_INVERT: nROP2 = 6; break; - case ROP_XOR: nROP2 = 7; break; - default: nROP2 = 13;break; - } - - ImplBeginRecord( WIN_EMR_SETROP2 ); - (*mpStm) << nROP2; - ImplEndRecord(); -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplWriteExtent( long nExtent ) -{ - nExtent = maVDev.LogicToLogic( Size( nExtent, 0 ), maVDev.GetMapMode(), maDestMapMode ).Width(); - (*mpStm) << (INT32) nExtent; -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplWritePoint( const Point& rPoint ) -{ - const Point aPoint( maVDev.LogicToLogic( rPoint, maVDev.GetMapMode(), maDestMapMode )); - (*mpStm) << (INT32) aPoint.X() << (INT32) aPoint.Y(); -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplWriteSize( const Size& rSize) -{ - const Size aSize( maVDev.LogicToLogic( rSize, maVDev.GetMapMode(), maDestMapMode )); - (*mpStm) << (INT32) aSize.Width() << (INT32) aSize.Height(); -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplWriteRect( const Rectangle& rRect ) -{ - const Rectangle aRect( maVDev.LogicToLogic ( rRect, maVDev.GetMapMode(), maDestMapMode )); - (*mpStm) << aRect.Left() << aRect.Top() << aRect.Right() << aRect.Bottom(); -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplWritePolygonRecord( const Polygon& rPoly, BOOL bClose ) -{ - if( rPoly.GetSize() ) - { - if( rPoly.HasFlags() ) - ImplWritePath( rPoly, bClose ); - else - { - if( bClose ) - ImplCheckFillAttr(); - - ImplCheckLineAttr(); - - ImplBeginRecord( bClose ? WIN_EMR_POLYGON : WIN_EMR_POLYLINE ); - ImplWriteRect( rPoly.GetBoundRect() ); - (*mpStm) << (UINT32) rPoly.GetSize(); - - for( USHORT i = 0; i < rPoly.GetSize(); i++ ) - ImplWritePoint( rPoly[ i ] ); - - ImplEndRecord(); - } - } -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplWritePolyPolygonRecord( const PolyPolygon& rPolyPoly ) -{ - sal_uInt16 n, i, nPolyCount = rPolyPoly.Count(); - - if( nPolyCount ) - { - if( 1 == nPolyCount ) - ImplWritePolygonRecord( rPolyPoly[ 0 ], TRUE ); - else - { - sal_Bool bHasFlags = sal_False; - sal_uInt32 nTotalPoints = 0; - - for( i = 0; i < nPolyCount; i++ ) - { - nTotalPoints += rPolyPoly[ i ].GetSize(); - if ( rPolyPoly[ i ].HasFlags() ) - bHasFlags = sal_True; - } - if( nTotalPoints ) - { - if ( bHasFlags ) - ImplWritePath( rPolyPoly, sal_True ); - else - { - ImplCheckFillAttr(); - ImplCheckLineAttr(); - - ImplBeginRecord( WIN_EMR_POLYPOLYGON ); - ImplWriteRect( rPolyPoly.GetBoundRect() ); - (*mpStm) << (sal_uInt32)nPolyCount << nTotalPoints; - - for( i = 0; i < nPolyCount; i++ ) - (*mpStm) << (sal_uInt32)rPolyPoly[ i ].GetSize(); - - for( i = 0; i < nPolyCount; i++ ) - { - const Polygon& rPoly = rPolyPoly[ i ]; - - for( n = 0; n < rPoly.GetSize(); n++ ) - ImplWritePoint( rPoly[ n ] ); - } - ImplEndRecord(); - } - } - } - } -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplWritePath( const PolyPolygon& rPolyPoly, sal_Bool bClosed ) -{ - if ( bClosed ) - ImplCheckFillAttr(); - ImplCheckLineAttr(); - - ImplBeginRecord( WIN_EMR_BEGINPATH ); - ImplEndRecord(); - - sal_uInt16 i, n, o, nPolyCount = rPolyPoly.Count(); - for ( i = 0; i < nPolyCount; i++ ) - { - n = 0; - const Polygon& rPoly = rPolyPoly[ i ]; - while ( n < rPoly.GetSize() ) - { - if( n == 0 ) - { - ImplBeginRecord( WIN_EMR_MOVETOEX ); - ImplWritePoint( rPoly[ 0 ] ); - ImplEndRecord(); - n++; - continue; - } - - sal_uInt16 nBezPoints = 0; - - while ( ( ( nBezPoints + n + 2 ) < rPoly.GetSize() ) && ( rPoly.GetFlags( nBezPoints + n ) == POLY_CONTROL ) ) - nBezPoints += 3; - - if ( nBezPoints ) - { - ImplBeginRecord( WIN_EMR_POLYBEZIERTO ); - Polygon aNewPoly( nBezPoints + 1 ); - aNewPoly[ 0 ] = rPoly[ n - 1 ]; - for ( o = 0; o < nBezPoints; o++ ) - aNewPoly[ o + 1 ] = rPoly[ n + o ]; - ImplWriteRect( aNewPoly.GetBoundRect() ); - (*mpStm) << (sal_uInt32)nBezPoints; - for( o = 1; o < aNewPoly.GetSize(); o++ ) - ImplWritePoint( aNewPoly[ o ] ); - ImplEndRecord(); - n = n + nBezPoints; - } - else - { - sal_uInt16 nPoints = 1; - while( ( nPoints + n ) < rPoly.GetSize() && ( rPoly.GetFlags( nPoints + n ) != POLY_CONTROL ) ) - nPoints++; - - if ( nPoints > 1 ) - { - ImplBeginRecord( WIN_EMR_POLYLINETO ); - Polygon aNewPoly( nPoints + 1 ); - aNewPoly[ 0 ] = rPoly[ n - 1]; - for ( o = 1; o <= nPoints; o++ ) - aNewPoly[ o ] = rPoly[ n - 1 + o ]; - ImplWriteRect( aNewPoly.GetBoundRect() ); - (*mpStm) << (sal_uInt32)( nPoints ); - for( o = 1; o < aNewPoly.GetSize(); o++ ) - ImplWritePoint( aNewPoly[ o ] ); - ImplEndRecord(); - } - else - { - ImplBeginRecord( WIN_EMR_LINETO ); - ImplWritePoint( rPoly[ n ] ); - ImplEndRecord(); - } - n = n + nPoints; - } - if ( bClosed && ( n == rPoly.GetSize() ) ) - { - ImplBeginRecord( WIN_EMR_CLOSEFIGURE ); - ImplEndRecord(); - } - } - } - ImplBeginRecord( WIN_EMR_ENDPATH ); - ImplEndRecord(); - ImplBeginRecord( bClosed ? WIN_EMR_FILLPATH : WIN_EMR_STROKEPATH ); - ImplWriteRect( rPolyPoly.GetBoundRect() ); - ImplEndRecord(); -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplWriteBmpRecord( const Bitmap& rBmp, const Point& rPt, - const Size& rSz, UINT32 nROP ) -{ - if( !!rBmp ) - { - SvMemoryStream aMemStm( 65535, 65535 ); - const Size aBmpSizePixel( rBmp.GetSizePixel() ); - - ImplBeginRecord( WIN_EMR_STRETCHDIBITS ); - ImplWriteRect( Rectangle( rPt, rSz ) ); - ImplWritePoint( rPt ); - (*mpStm) << (INT32) 0 << (INT32) 0 << (INT32) aBmpSizePixel.Width() << (INT32) aBmpSizePixel.Height(); - - // write offset positions and sizes later - const ULONG nOffPos = mpStm->Tell(); - mpStm->SeekRel( 16 ); - - (*mpStm) << (UINT32) 0 << ( ( ROP_XOR == maVDev.GetRasterOp() && WIN_SRCCOPY == nROP ) ? WIN_SRCINVERT : nROP ); - ImplWriteSize( rSz ); - - rBmp.Write( aMemStm, TRUE, FALSE ); - - UINT32 nDIBSize = aMemStm.Tell(), nHeaderSize, nCompression, nColsUsed, nPalCount, nImageSize; - UINT16 nBitCount; - - // get DIB parameters - aMemStm.Seek( 0 ); - aMemStm >> nHeaderSize; - aMemStm.SeekRel( 10 ); - aMemStm >> nBitCount >> nCompression >> nImageSize; - aMemStm.SeekRel( 8 ); - aMemStm >> nColsUsed; - - nPalCount = ( nBitCount <= 8 ) ? ( nColsUsed ? nColsUsed : ( 1 << (UINT32) nBitCount ) ) : - ( ( 3 == nCompression ) ? 12 : 0 ); - - mpStm->Write( aMemStm.GetData(), nDIBSize ); - - const ULONG nEndPos = mpStm->Tell(); - mpStm->Seek( nOffPos ); - (*mpStm) << (UINT32) 80 << (UINT32)( nHeaderSize + ( nPalCount << 2 ) ); - (*mpStm) << (UINT32)( 80 + ( nHeaderSize + ( nPalCount << 2 ) ) ) << nImageSize; - mpStm->Seek( nEndPos ); - - ImplEndRecord(); - } -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplWriteTextRecord( const Point& rPos, const String rText, const sal_Int32* pDXArray, sal_uInt32 nWidth ) -{ - xub_StrLen nLen = rText.Len(), i; - - if( nLen ) - { - sal_uInt32 nNormWidth; - sal_Int32* pOwnArray; - sal_Int32* pDX; - - // get text sizes - if( pDXArray ) - { - pOwnArray = NULL; - nNormWidth = maVDev.GetTextWidth( rText ); - pDX = (sal_Int32*) pDXArray; - } - else - { - pOwnArray = new sal_Int32[ nLen ]; - nNormWidth = maVDev.GetTextArray( rText, pOwnArray ); - pDX = pOwnArray; - } - - if( nLen > 1 ) - { - nNormWidth = pDX[ nLen - 2 ] + maVDev.GetTextWidth( rText.GetChar( nLen - 1 ) ); - - if( nWidth && nNormWidth && ( nWidth != nNormWidth ) ) - { - const double fFactor = (double) nWidth / nNormWidth; - - for( i = 0; i < ( nLen - 1 ); i++ ) - pDX[ i ] = FRound( pDX[ i ] * fFactor ); - } - } - - // write text record - ImplBeginRecord( WIN_EMR_EXTTEXTOUTW ); - - ImplWriteRect( Rectangle( rPos, Size( nNormWidth, maVDev.GetTextHeight() ) ) ); - (*mpStm) << (UINT32)1; - (*mpStm) << (INT32) 0 << (INT32) 0; - ImplWritePoint( rPos ); - (*mpStm) << (UINT32) nLen << (UINT32) 76 << (UINT32) 2; - (*mpStm) << (INT32) 0 << (INT32) 0 << (INT32) 0 << (INT32) 0; - (*mpStm) << (UINT32) ( 76 + ( nLen << 1 ) + ( (nLen & 1 ) ? 2 : 0 ) ); - - // write text - for( i = 0; i < nLen; i++ ) - (*mpStm) << (sal_Unicode)rText.GetChar( i ); - - // padding word - if( nLen & 1 ) - (*mpStm) << (UINT16) 0; - - // write DX array - ImplWriteExtent( pDX[ 0 ] ); - - if( nLen > 1 ) - { - for( i = 1; i < ( nLen - 1 ); i++ ) - ImplWriteExtent( pDX[ i ] - pDX[ i - 1 ] ); - - ImplWriteExtent( pDX[ nLen - 2 ] / ( nLen - 1 ) ); - } - - ImplEndRecord(); - delete[] pOwnArray; - } -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::Impl_handleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon) -{ - if(rLinePolygon.count()) - { - basegfx::B2DPolyPolygon aLinePolyPolygon(rLinePolygon); - basegfx::B2DPolyPolygon aFillPolyPolygon; - - rInfo.applyToB2DPolyPolygon(aLinePolyPolygon, aFillPolyPolygon); - - if(aLinePolyPolygon.count()) - { - for(sal_uInt32 a(0); a < aLinePolyPolygon.count(); a++) - { - const basegfx::B2DPolygon aCandidate(aLinePolyPolygon.getB2DPolygon(a)); - ImplWritePolygonRecord( Polygon(aCandidate), FALSE ); - } - } - - if(aFillPolyPolygon.count()) - { - const Color aOldLineColor(maVDev.GetLineColor()); - const Color aOldFillColor(maVDev.GetFillColor()); - - maVDev.SetLineColor(); - maVDev.SetFillColor(aOldLineColor); - - for(sal_uInt32 a(0); a < aFillPolyPolygon.count(); a++) - { - const Polygon aPolygon(aFillPolyPolygon.getB2DPolygon(a)); - ImplWritePolyPolygonRecord(PolyPolygon(Polygon(aPolygon))); - } - - maVDev.SetLineColor(aOldLineColor); - maVDev.SetFillColor(aOldFillColor); - } - } -} - -// ----------------------------------------------------------------------------- - -void EMFWriter::ImplWrite( const GDIMetaFile& rMtf ) -{ - for( ULONG j = 0, nActionCount = rMtf.GetActionCount(); j < nActionCount; j++ ) - { - const MetaAction* pAction = rMtf.GetAction( j ); - const USHORT nType = pAction->GetType(); - - switch( nType ) - { - case( META_PIXEL_ACTION ): - { - const MetaPixelAction* pA = (const MetaPixelAction*) pAction; - - ImplCheckLineAttr(); - ImplBeginRecord( WIN_EMR_SETPIXELV ); - ImplWritePoint( pA->GetPoint() ); - ImplWriteColor( pA->GetColor() ); - ImplEndRecord(); - } - break; - - case( META_POINT_ACTION ): - { - if( maVDev.IsLineColor() ) - { - const MetaPointAction* pA = (const MetaPointAction*) pAction; - - ImplCheckLineAttr(); - ImplBeginRecord( WIN_EMR_SETPIXELV ); - ImplWritePoint( pA->GetPoint() ); - ImplWriteColor( maVDev.GetLineColor() ); - ImplEndRecord(); - } - } - break; - - case( META_LINE_ACTION ): - { - if( maVDev.IsLineColor() ) - { - const MetaLineAction* pA = (const MetaLineAction*) pAction; - - if(pA->GetLineInfo().IsDefault()) - { - ImplCheckLineAttr(); - - ImplBeginRecord( WIN_EMR_MOVETOEX ); - ImplWritePoint( pA->GetStartPoint() ); - ImplEndRecord(); - - ImplBeginRecord( WIN_EMR_LINETO ); - ImplWritePoint( pA->GetEndPoint() ); - ImplEndRecord(); - - ImplBeginRecord( WIN_EMR_SETPIXELV ); - ImplWritePoint( pA->GetEndPoint() ); - ImplWriteColor( maVDev.GetLineColor() ); - ImplEndRecord(); - } - else - { - // LineInfo used; handle Dash/Dot and fat lines - basegfx::B2DPolygon aPolygon; - aPolygon.append(basegfx::B2DPoint(pA->GetStartPoint().X(), pA->GetStartPoint().Y())); - aPolygon.append(basegfx::B2DPoint(pA->GetEndPoint().X(), pA->GetEndPoint().Y())); - Impl_handleLineInfoPolyPolygons(pA->GetLineInfo(), aPolygon); - } - } - } - break; - - case( META_RECT_ACTION ): - { - if( maVDev.IsLineColor() || maVDev.IsFillColor() ) - { - const MetaRectAction* pA = (const MetaRectAction*) pAction; - - ImplCheckFillAttr(); - ImplCheckLineAttr(); - - ImplBeginRecord( WIN_EMR_RECTANGLE ); - ImplWriteRect( pA->GetRect() ); - ImplEndRecord(); - } - } - break; - - case( META_ROUNDRECT_ACTION ): - { - if( maVDev.IsLineColor() || maVDev.IsFillColor() ) - { - const MetaRoundRectAction* pA = (const MetaRoundRectAction*) pAction; - - ImplCheckFillAttr(); - ImplCheckLineAttr(); - - ImplBeginRecord( WIN_EMR_ROUNDRECT ); - ImplWriteRect( pA->GetRect() ); - ImplWriteSize( Size( pA->GetHorzRound(), pA->GetVertRound() ) ); - ImplEndRecord(); - } - } - break; - - case( META_ELLIPSE_ACTION ): - { - if( maVDev.IsLineColor() || maVDev.IsFillColor() ) - { - const MetaEllipseAction* pA = (const MetaEllipseAction*) pAction; - - ImplCheckFillAttr(); - ImplCheckLineAttr(); - - ImplBeginRecord( WIN_EMR_ELLIPSE ); - ImplWriteRect( pA->GetRect() ); - ImplEndRecord(); - } - } - break; - - case( META_ARC_ACTION ): - case( META_PIE_ACTION ): - case( META_CHORD_ACTION ): - case( META_POLYGON_ACTION ): - { - if( maVDev.IsLineColor() || maVDev.IsFillColor() ) - { - Polygon aPoly; - - switch( nType ) - { - case( META_ARC_ACTION ): - { - const MetaArcAction* pA = (const MetaArcAction*) pAction; - aPoly = Polygon( pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_ARC ); - } - break; - - case( META_PIE_ACTION ): - { - const MetaPieAction* pA = (const MetaPieAction*) pAction; - aPoly = Polygon( pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_PIE ); - } - break; - - case( META_CHORD_ACTION ): - { - const MetaChordAction* pA = (const MetaChordAction*) pAction; - aPoly = Polygon( pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_CHORD ); - } - break; - - case( META_POLYGON_ACTION ): - aPoly = ( (const MetaPolygonAction*) pAction )->GetPolygon(); - break; - } - - ImplWritePolygonRecord( aPoly, nType != META_ARC_ACTION ); - } - } - break; - - case( META_POLYLINE_ACTION ): - { - if( maVDev.IsLineColor() ) - { - const MetaPolyLineAction* pA = (const MetaPolyLineAction*) pAction; - const Polygon& rPoly = pA->GetPolygon(); - - if( rPoly.GetSize() ) - { - if(pA->GetLineInfo().IsDefault()) - { - ImplWritePolygonRecord( rPoly, FALSE ); - } - else - { - // LineInfo used; handle Dash/Dot and fat lines - Impl_handleLineInfoPolyPolygons(pA->GetLineInfo(), rPoly.getB2DPolygon()); - } - } - } - } - break; - - case( META_POLYPOLYGON_ACTION ): - { - if( maVDev.IsLineColor() || maVDev.IsFillColor() ) - ImplWritePolyPolygonRecord( ( (const MetaPolyPolygonAction*) pAction )->GetPolyPolygon() ); - } - break; - - case( META_GRADIENT_ACTION ): - { - const MetaGradientAction* pA = (const MetaGradientAction*) pAction; - GDIMetaFile aTmpMtf; - - maVDev.AddGradientActions( pA->GetRect(), pA->GetGradient(), aTmpMtf ); - ImplWrite( aTmpMtf ); - } - break; - - case META_HATCH_ACTION: - { - const MetaHatchAction* pA = (const MetaHatchAction*) pAction; - GDIMetaFile aTmpMtf; - - maVDev.AddHatchActions( pA->GetPolyPolygon(), pA->GetHatch(), aTmpMtf ); - ImplWrite( aTmpMtf ); - } - break; - - case META_TRANSPARENT_ACTION: - { - ImplCheckFillAttr(); - ImplCheckLineAttr(); - ImplWritePolyPolygonRecord( ( (MetaTransparentAction*) pAction )->GetPolyPolygon() ); - } - break; - - case META_FLOATTRANSPARENT_ACTION: - { - const MetaFloatTransparentAction* pA = (const MetaFloatTransparentAction*) pAction; - - GDIMetaFile aTmpMtf( pA->GetGDIMetaFile() ); - Point aSrcPt( aTmpMtf.GetPrefMapMode().GetOrigin() ); - const Size aSrcSize( aTmpMtf.GetPrefSize() ); - const Point aDestPt( pA->GetPoint() ); - const Size aDestSize( pA->GetSize() ); - const double fScaleX = aSrcSize.Width() ? (double) aDestSize.Width() / aSrcSize.Width() : 1.0; - const double fScaleY = aSrcSize.Height() ? (double) aDestSize.Height() / aSrcSize.Height() : 1.0; - long nMoveX, nMoveY; - - if( fScaleX != 1.0 || fScaleY != 1.0 ) - { - aTmpMtf.Scale( fScaleX, fScaleY ); - aSrcPt.X() = FRound( aSrcPt.X() * fScaleX ), aSrcPt.Y() = FRound( aSrcPt.Y() * fScaleY ); - } - - nMoveX = aDestPt.X() - aSrcPt.X(), nMoveY = aDestPt.Y() - aSrcPt.Y(); - - if( nMoveX || nMoveY ) - aTmpMtf.Move( nMoveX, nMoveY ); - - ImplCheckFillAttr(); - ImplCheckLineAttr(); - ImplCheckTextAttr(); - ImplWrite( aTmpMtf ); - } - break; - - case( META_EPS_ACTION ): - { - const MetaEPSAction* pA = (const MetaEPSAction*) pAction; - const GDIMetaFile aSubstitute( pA->GetSubstitute() ); - - for( ULONG i = 0, nCount = aSubstitute.GetActionCount(); i < nCount; i++ ) - { - const MetaAction* pSubstAct = aSubstitute.GetAction( i ); - if( pSubstAct->GetType() == META_BMPSCALE_ACTION ) - { - maVDev.Push( PUSH_ALL ); - ImplBeginRecord( WIN_EMR_SAVEDC ); - ImplEndRecord(); - - MapMode aMapMode( aSubstitute.GetPrefMapMode() ); - Size aOutSize( maVDev.LogicToLogic( pA->GetSize(), maVDev.GetMapMode(), aMapMode ) ); - aMapMode.SetScaleX( Fraction( aOutSize.Width(), aSubstitute.GetPrefSize().Width() ) ); - aMapMode.SetScaleY( Fraction( aOutSize.Height(), aSubstitute.GetPrefSize().Height() ) ); - aMapMode.SetOrigin( maVDev.LogicToLogic( pA->GetPoint(), maVDev.GetMapMode(), aMapMode ) ); - maVDev.SetMapMode( aMapMode ); - ImplWrite( aSubstitute ); - - maVDev.Pop(); - ImplBeginRecord( WIN_EMR_RESTOREDC ); - (*mpStm) << (INT32) -1; - ImplEndRecord(); - break; - } - } - } - break; - - case META_BMP_ACTION: - { - const MetaBmpAction* pA = (const MetaBmpAction *) pAction; - ImplWriteBmpRecord( pA->GetBitmap(), pA->GetPoint(), pA->GetBitmap().GetSizePixel(), WIN_SRCCOPY ); - } - break; - - case META_BMPSCALE_ACTION: - { - const MetaBmpScaleAction* pA = (const MetaBmpScaleAction*) pAction; - ImplWriteBmpRecord( pA->GetBitmap(), pA->GetPoint(), pA->GetSize(), WIN_SRCCOPY ); - } - break; - - case META_BMPSCALEPART_ACTION: - { - const MetaBmpScalePartAction* pA = (const MetaBmpScalePartAction*) pAction; - Bitmap aTmp( pA->GetBitmap() ); - - if( aTmp.Crop( Rectangle( pA->GetSrcPoint(), pA->GetSrcSize() ) ) ) - ImplWriteBmpRecord( aTmp, pA->GetDestPoint(), pA->GetDestSize(), WIN_SRCCOPY ); - } - break; - - case META_BMPEX_ACTION: - { - const MetaBmpExAction* pA = (const MetaBmpExAction *) pAction; - Bitmap aBmp( pA->GetBitmapEx().GetBitmap() ); - Bitmap aMsk( pA->GetBitmapEx().GetMask() ); - - if( !!aMsk ) - { - aBmp.Replace( aMsk, COL_WHITE ); - aMsk.Invert(); - ImplWriteBmpRecord( aMsk, pA->GetPoint(), aMsk.GetSizePixel(), WIN_SRCPAINT ); - ImplWriteBmpRecord( aBmp, pA->GetPoint(), aBmp.GetSizePixel(), WIN_SRCAND ); - } - else - ImplWriteBmpRecord( aBmp, pA->GetPoint(), aBmp.GetSizePixel(), WIN_SRCCOPY ); - } - break; - - case META_BMPEXSCALE_ACTION: - { - const MetaBmpExScaleAction* pA = (const MetaBmpExScaleAction*) pAction; - Bitmap aBmp( pA->GetBitmapEx().GetBitmap() ); - Bitmap aMsk( pA->GetBitmapEx().GetMask() ); - - if( !!aMsk ) - { - aBmp.Replace( aMsk, COL_WHITE ); - aMsk.Invert(); - ImplWriteBmpRecord( aMsk, pA->GetPoint(), pA->GetSize(), WIN_SRCPAINT ); - ImplWriteBmpRecord( aBmp, pA->GetPoint(), pA->GetSize(), WIN_SRCAND ); - } - else - ImplWriteBmpRecord( aBmp, pA->GetPoint(), pA->GetSize(), WIN_SRCCOPY ); - } - break; - - case META_BMPEXSCALEPART_ACTION: - { - const MetaBmpExScalePartAction* pA = (const MetaBmpExScalePartAction*) pAction; - BitmapEx aBmpEx( pA->GetBitmapEx() ); - aBmpEx.Crop( Rectangle( pA->GetSrcPoint(), pA->GetSrcSize() ) ); - Bitmap aBmp( aBmpEx.GetBitmap() ); - Bitmap aMsk( aBmpEx.GetMask() ); - - if( !!aMsk ) - { - aBmp.Replace( aMsk, COL_WHITE ); - aMsk.Invert(); - ImplWriteBmpRecord( aMsk, pA->GetDestPoint(), pA->GetDestSize(), WIN_SRCPAINT ); - ImplWriteBmpRecord( aBmp, pA->GetDestPoint(), pA->GetDestSize(), WIN_SRCAND ); - } - else - ImplWriteBmpRecord( aBmp, pA->GetDestPoint(), pA->GetDestSize(), WIN_SRCCOPY ); - } - break; - - case META_TEXT_ACTION: - { - const MetaTextAction* pA = (const MetaTextAction*) pAction; - const String aText( pA->GetText(), pA->GetIndex(), pA->GetLen() ); - - ImplCheckTextAttr(); - ImplWriteTextRecord( pA->GetPoint(), aText, NULL, 0 ); - } - break; - - case META_TEXTRECT_ACTION: - { - const MetaTextRectAction* pA = (const MetaTextRectAction*) pAction; - const String aText( pA->GetText() ); - - ImplCheckTextAttr(); - ImplWriteTextRecord( pA->GetRect().TopLeft(), aText, NULL, 0 ); - } - break; - - case META_TEXTARRAY_ACTION: - { - const MetaTextArrayAction* pA = (const MetaTextArrayAction*) pAction; - const String aText( pA->GetText(), pA->GetIndex(), pA->GetLen() ); - - ImplCheckTextAttr(); - ImplWriteTextRecord( pA->GetPoint(), aText, pA->GetDXArray(), 0 ); - } - break; - - case META_STRETCHTEXT_ACTION: - { - const MetaStretchTextAction* pA = (const MetaStretchTextAction*) pAction; - const String aText( pA->GetText(), pA->GetIndex(), pA->GetLen() ); - - ImplCheckTextAttr(); - ImplWriteTextRecord( pA->GetPoint(), aText, NULL, pA->GetWidth() ); - } - break; - - case( META_LINECOLOR_ACTION ): - { - ( (MetaAction*) pAction )->Execute( &maVDev ); - mbLineChanged = TRUE; - } - break; - - case( META_FILLCOLOR_ACTION ): - { - ( (MetaAction*) pAction )->Execute( &maVDev ); - mbFillChanged = TRUE; - } - break; - - case( META_TEXTCOLOR_ACTION ): - case( META_TEXTLINECOLOR_ACTION ): - case( META_TEXTFILLCOLOR_ACTION ): - case( META_TEXTALIGN_ACTION ): - case( META_FONT_ACTION ): - { - ( (MetaAction*) pAction )->Execute( &maVDev ); - mbTextChanged = TRUE; - } - break; - - case( META_ISECTRECTCLIPREGION_ACTION ): - { - ( (MetaAction*) pAction )->Execute( &maVDev ); - - ImplBeginRecord( WIN_EMR_INTERSECTCLIPRECT ); - ImplWriteRect( ( (MetaISectRectClipRegionAction*) pAction )->GetRect() ); - ImplEndRecord(); - } - break; - - case( META_CLIPREGION_ACTION ): - case( META_ISECTREGIONCLIPREGION_ACTION ): - case( META_MOVECLIPREGION_ACTION ): - { - ( (MetaAction*) pAction )->Execute( &maVDev ); - } - break; - - case( META_REFPOINT_ACTION ): - case( META_MAPMODE_ACTION ): - ( (MetaAction*) pAction )->Execute( &maVDev ); - break; - - case( META_PUSH_ACTION ): - { - ( (MetaAction*) pAction )->Execute( &maVDev ); - - ImplBeginRecord( WIN_EMR_SAVEDC ); - ImplEndRecord(); - } - break; - - case( META_POP_ACTION ): - { - ( (MetaAction*) pAction )->Execute( &maVDev ); - - ImplBeginRecord( WIN_EMR_RESTOREDC ); - (*mpStm) << (INT32) -1; - ImplEndRecord(); - - ImplWriteRasterOp( maVDev.GetRasterOp() ); - mbLineChanged = mbFillChanged = mbTextChanged = TRUE; - } - break; - - case( META_RASTEROP_ACTION ): - { - ( (MetaAction*) pAction )->Execute( &maVDev ); - ImplWriteRasterOp( ( (MetaRasterOpAction*) pAction )->GetRasterOp() ); - } - break; - - case( META_LAYOUTMODE_ACTION ): - { - sal_uInt32 nLayoutMode = ( (MetaLayoutModeAction*) pAction )->GetLayoutMode(); - mnHorTextAlign = 0; - if (nLayoutMode & TEXT_LAYOUT_BIDI_RTL) - { - mnHorTextAlign = TA_RIGHT | TA_RTLREADING; - } - if (nLayoutMode & TEXT_LAYOUT_TEXTORIGIN_RIGHT) - mnHorTextAlign |= TA_RIGHT; - else if (nLayoutMode & TEXT_LAYOUT_TEXTORIGIN_LEFT) - mnHorTextAlign &= ~TA_RIGHT; - break; - } - - case( META_MASK_ACTION ): - case( META_MASKSCALE_ACTION ): - case( META_MASKSCALEPART_ACTION ): - case( META_WALLPAPER_ACTION ): - case( META_TEXTLINE_ACTION ): - case( META_COMMENT_ACTION ): - case( META_GRADIENTEX_ACTION ): - { - // !!! >>> we don't want to support these actions - } - break; - - default: - DBG_ERROR( ( ByteString( "EMFWriter::ImplWriteActions: unsupported MetaAction #" ) += ByteString::CreateFromInt32( nType ) ).GetBuffer() ); - break; - } - } -} diff --git a/svtools/source/filter.vcl/wmf/emfwr.hxx b/svtools/source/filter.vcl/wmf/emfwr.hxx deleted file mode 100644 index 6334b5dfe16f..000000000000 --- a/svtools/source/filter.vcl/wmf/emfwr.hxx +++ /dev/null @@ -1,100 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _EMFWR_HXX -#define _EMFWR_HXX - -#include -#include -#include -#include -#include -#include - -// ------------- -// - EMFWriter - -// ------------- - -class LineInfo; -namespace basegfx { class B2DPolygon; } - -class EMFWriter -{ -private: - - VirtualDevice maVDev; - MapMode maDestMapMode; - FilterConfigItem* mpFilterConfigItem; - SvStream* mpStm; - BOOL* mpHandlesUsed; - ULONG mnHandleCount; - ULONG mnLastPercent; - ULONG mnRecordCount; - ULONG mnRecordPos; - BOOL mbRecordOpen; - BOOL mbLineChanged; - sal_uInt32 mnLineHandle; - BOOL mbFillChanged; - sal_uInt32 mnFillHandle; - BOOL mbTextChanged; - sal_uInt32 mnTextHandle; - sal_uInt32 mnHorTextAlign; - - void ImplBeginRecord( sal_uInt32 nType ); - void ImplEndRecord(); - - ULONG ImplAcquireHandle(); - void ImplReleaseHandle( ULONG nHandle ); - - BOOL ImplPrepareHandleSelect( sal_uInt32& rHandle, ULONG nSelectType ); - void ImplCheckLineAttr(); - void ImplCheckFillAttr(); - void ImplCheckTextAttr(); - - void ImplWriteColor( const Color& rColor ); - void ImplWriteRasterOp( RasterOp eRop ); - void ImplWriteExtent( long nExtent ); - void ImplWritePoint( const Point& rPoint ); - void ImplWriteSize( const Size& rSize); - void ImplWriteRect( const Rectangle& rRect ); - void ImplWritePath( const PolyPolygon& rPolyPoly, sal_Bool bClose ); - void ImplWritePolygonRecord( const Polygon& rPoly, BOOL bClose ); - void ImplWritePolyPolygonRecord( const PolyPolygon& rPolyPoly ); - void ImplWriteBmpRecord( const Bitmap& rBmp, const Point& rPt, const Size& rSz, UINT32 nROP ); - void ImplWriteTextRecord( const Point& rPos, const String rText, const sal_Int32* pDXArray, sal_uInt32 nWidth ); - - void Impl_handleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon); - void ImplWrite( const GDIMetaFile& rMtf ); - -public: - - EMFWriter() {} - - BOOL WriteEMF( const GDIMetaFile& rMtf, SvStream& rOStm, FilterConfigItem* pConfigItem = NULL ); -}; - -#endif // _EMFWR_HXX diff --git a/svtools/source/filter.vcl/wmf/enhwmf.cxx b/svtools/source/filter.vcl/wmf/enhwmf.cxx deleted file mode 100644 index 1e49e0d61446..000000000000 --- a/svtools/source/filter.vcl/wmf/enhwmf.cxx +++ /dev/null @@ -1,1343 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#include "winmtf.hxx" -#include - -//=========================== GDI-Array =================================== - -#define EMR_HEADER 1 -#define EMR_POLYBEZIER 2 -#define EMR_POLYGON 3 -#define EMR_POLYLINE 4 -#define EMR_POLYBEZIERTO 5 -#define EMR_POLYLINETO 6 -#define EMR_POLYPOLYLINE 7 -#define EMR_POLYPOLYGON 8 -#define EMR_SETWINDOWEXTEX 9 -#define EMR_SETWINDOWORGEX 10 -#define EMR_SETVIEWPORTEXTEX 11 -#define EMR_SETVIEWPORTORGEX 12 -#define EMR_SETBRUSHORGEX 13 -#define EMR_EOF 14 -#define EMR_SETPIXELV 15 -#define EMR_SETMAPPERFLAGS 16 -#define EMR_SETMAPMODE 17 -#define EMR_SETBKMODE 18 -#define EMR_SETPOLYFILLMODE 19 -#define EMR_SETROP2 20 -#define EMR_SETSTRETCHBLTMODE 21 -#define EMR_SETTEXTALIGN 22 -#define EMR_SETCOLORADJUSTMENT 23 -#define EMR_SETTEXTCOLOR 24 -#define EMR_SETBKCOLOR 25 -#define EMR_OFFSETCLIPRGN 26 -#define EMR_MOVETOEX 27 -#define EMR_SETMETARGN 28 -#define EMR_EXCLUDECLIPRECT 29 -#define EMR_INTERSECTCLIPRECT 30 -#define EMR_SCALEVIEWPORTEXTEX 31 -#define EMR_SCALEWINDOWEXTEX 32 -#define EMR_SAVEDC 33 -#define EMR_RESTOREDC 34 -#define EMR_SETWORLDTRANSFORM 35 -#define EMR_MODIFYWORLDTRANSFORM 36 -#define EMR_SELECTOBJECT 37 -#define EMR_CREATEPEN 38 -#define EMR_CREATEBRUSHINDIRECT 39 -#define EMR_DELETEOBJECT 40 -#define EMR_ANGLEARC 41 -#define EMR_ELLIPSE 42 -#define EMR_RECTANGLE 43 -#define EMR_ROUNDRECT 44 -#define EMR_ARC 45 -#define EMR_CHORD 46 -#define EMR_PIE 47 -#define EMR_SELECTPALETTE 48 -#define EMR_CREATEPALETTE 49 -#define EMR_SETPALETTEENTRIES 50 -#define EMR_RESIZEPALETTE 51 -#define EMR_REALIZEPALETTE 52 -#define EMR_EXTFLOODFILL 53 -#define EMR_LINETO 54 -#define EMR_ARCTO 55 -#define EMR_POLYDRAW 56 -#define EMR_SETARCDIRECTION 57 -#define EMR_SETMITERLIMIT 58 -#define EMR_BEGINPATH 59 -#define EMR_ENDPATH 60 -#define EMR_CLOSEFIGURE 61 -#define EMR_FILLPATH 62 -#define EMR_STROKEANDFILLPATH 63 -#define EMR_STROKEPATH 64 -#define EMR_FLATTENPATH 65 -#define EMR_WIDENPATH 66 -#define EMR_SELECTCLIPPATH 67 -#define EMR_ABORTPATH 68 - -#define EMR_GDICOMMENT 70 -#define EMR_FILLRGN 71 -#define EMR_FRAMERGN 72 -#define EMR_INVERTRGN 73 -#define EMR_PAINTRGN 74 -#define EMR_EXTSELECTCLIPRGN 75 -#define EMR_BITBLT 76 -#define EMR_STRETCHBLT 77 -#define EMR_MASKBLT 78 -#define EMR_PLGBLT 79 -#define EMR_SETDIBITSTODEVICE 80 -#define EMR_STRETCHDIBITS 81 -#define EMR_EXTCREATEFONTINDIRECTW 82 -#define EMR_EXTTEXTOUTA 83 -#define EMR_EXTTEXTOUTW 84 -#define EMR_POLYBEZIER16 85 -#define EMR_POLYGON16 86 -#define EMR_POLYLINE16 87 -#define EMR_POLYBEZIERTO16 88 -#define EMR_POLYLINETO16 89 -#define EMR_POLYPOLYLINE16 90 -#define EMR_POLYPOLYGON16 91 -#define EMR_POLYDRAW16 92 -#define EMR_CREATEMONOBRUSH 93 -#define EMR_CREATEDIBPATTERNBRUSHPT 94 -#define EMR_EXTCREATEPEN 95 -#define EMR_POLYTEXTOUTA 96 -#define EMR_POLYTEXTOUTW 97 - -// WINDOWS VERSION >= 0x400 -#define EMR_SETICMMODE 98 -#define EMR_CREATECOLORSPACE 99 -#define EMR_SETCOLORSPACE 100 -#define EMR_DELETECOLORSPACE 101 -#define EMR_GLSRECORD 102 -#define EMR_GLSBOUNDEDRECORD 103 -#define EMR_PIXELFORMAT 104 - -// WINDOWS VERSION >= 0x500 -#define EMR_DRAWESCAPE 105 -#define EMR_EXTESCAPE 106 -#define EMR_STARTDOC 107 -#define EMR_SMALLTEXTOUT 108 -#define EMR_FORCEUFIMAPPING 109 -#define EMR_NAMEDESCAPE 110 -#define EMR_COLORCORRECTPALETTE 111 -#define EMR_SETICMPROFILEA 112 -#define EMR_SETICMPROFILEW 113 -#define EMR_ALPHABLEND 114 -#define EMR_ALPHADIBBLEND 115 -#define EMR_TRANSPARENTBLT 116 -#define EMR_TRANSPARENTDIB 117 -#define EMR_GRADIENTFILL 118 -#define EMR_SETLINKEDUFIS 119 -#define EMR_SETTEXTJUSTIFICATION 120 - - -//----------------------------------------------------------------------------------- - -#ifdef OSL_BIGENDIAN -// currently unused -static float GetSwapFloat( SvStream& rSt ) -{ - float fTmp; - sal_Int8* pPtr = (sal_Int8*)&fTmp; - rSt >> pPtr[3] >> pPtr[2] >> pPtr[1] >> pPtr[0]; // Little Endian <-> Big Endian switch - return fTmp; -} -#endif - -SvStream& operator>>( SvStream& rIn, XForm& rXForm ) -{ - if ( sizeof( float ) != 4 ) - { - DBG_ERROR( "EnhWMFReader::sizeof( float ) != 4" ); - rXForm = XForm(); - } - else - { -#ifdef OSL_BIGENDIAN - rXForm.eM11 = GetSwapFloat( rIn ); - rXForm.eM12 = GetSwapFloat( rIn ); - rXForm.eM21 = GetSwapFloat( rIn ); - rXForm.eM22 = GetSwapFloat( rIn ); - rXForm.eDx = GetSwapFloat( rIn ); - rXForm.eDy = GetSwapFloat( rIn ); -#else - rIn >> rXForm.eM11 >> rXForm.eM12 >> rXForm.eM21 >> rXForm.eM22 - >> rXForm.eDx >> rXForm.eDy; -#endif - } - return rIn; -} - -static sal_Bool ImplReadRegion( PolyPolygon& rPolyPoly, SvStream& rSt, sal_uInt32 nLen ) -{ - sal_Bool bOk = sal_False; - if ( nLen ) - { - sal_uInt32 nHdSize, nType, nCount, nRgnSize, i; - rSt >> nHdSize - >> nType - >> nCount - >> nRgnSize; - - if ( nCount && ( nType == RDH_RECTANGLES ) && - ( nLen >= ( ( nCount << 4 ) + ( nHdSize - 16 ) ) ) ) - { - sal_Int32 nx1, ny1, nx2, ny2; - - for ( i = 0; i < nCount; i++ ) - { - rSt >> nx1 >> ny1 >> nx2 >> ny2; - - Rectangle aRect( Point( nx1, ny1 ), Point( nx2, ny2 ) ); - Polygon aPolygon( aRect ); - PolyPolygon aPolyPolyOr1( aPolygon ); - PolyPolygon aPolyPolyOr2( rPolyPoly ); - rPolyPoly.GetUnion( aPolyPolyOr1, aPolyPolyOr2 ); - rPolyPoly = aPolyPolyOr2; - } - bOk = sal_True; - } - } - return bOk; -} - -BOOL EnhWMFReader::ReadEnhWMF() -{ - sal_uInt32 nStretchBltMode = 0; - sal_uInt32 nRecType, nRecSize, nNextPos, - nW, nH, nPoints, nColor, nIndex, - nDat32, nNom1, nDen1, nNom2, nDen2; - sal_Int32 nX32, nY32, nx32, ny32; - sal_Int16 nX16, nY16; - - sal_Bool bFlag, bStatus = ReadHeader(); - - while( bStatus && nRecordCount-- ) - { - *pWMF >> nRecType >> nRecSize; - - if ( ( nRecSize < 8 ) || ( nRecSize & 3 ) ) // Parameter sind immer durch 4 teilbar - { - bStatus = FALSE; - break; - } - - nNextPos = pWMF->Tell() + ( nRecSize - 8 ); - - if ( nNextPos > nEndPos ) - { - bStatus = FALSE; - break; - } - - if( aBmpSaveList.Count() && ( nRecType != EMR_STRETCHBLT ) && ( nRecType != EMR_STRETCHDIBITS ) ) - pOut->ResolveBitmapActions( aBmpSaveList ); - - bFlag = sal_False; - - switch( nRecType ) - { - case EMR_POLYBEZIERTO : - bFlag = sal_True; - case EMR_POLYBEZIER : - { - pWMF->SeekRel( 16 ); - *pWMF >> nPoints; - sal_uInt16 i = 0; - if ( bFlag ) - { - i++; - nPoints++; - } - Polygon aPoly( (sal_uInt16)nPoints ); - for( ; i < (sal_uInt16)nPoints; i++ ) - { - *pWMF >> nX32 >> nY32; - aPoly[ i ] = Point( nX32, nY32 ); - } - pOut->DrawPolyBezier( aPoly, bFlag, bRecordPath ); - } - break; - - case EMR_POLYGON : - { - pWMF->SeekRel( 16 ); - *pWMF >> nPoints; - Polygon aPoly( (UINT16)nPoints ); - for( UINT16 k = 0; k < (UINT16)nPoints; k++ ) - { - *pWMF >> nX32 >> nY32; - aPoly[ k ] = Point( nX32, nY32 ); - } - pOut->DrawPolygon( aPoly, bRecordPath ); - } - break; - - case EMR_POLYLINETO : - bFlag = sal_True; - case EMR_POLYLINE : - { - pWMF->SeekRel( 0x10 ); - *pWMF >> nPoints; - UINT16 i = 0; - if ( bFlag ) - { - i++; - nPoints++; - } - Polygon aPolygon( (UINT16)nPoints ); - for ( ; i < (UINT16)nPoints; i++ ) - { - *pWMF >> nX32 >> nY32; - aPolygon[ i ] = Point( nX32, nY32 ); - } - pOut->DrawPolyLine( aPolygon, bFlag, bRecordPath ); - } - break; - - case EMR_POLYPOLYLINE : - { - UINT16* pnPoints; - - INT32 i, nPoly; - pWMF->SeekRel( 0x10 ); - - // Anzahl der Polygone: - *pWMF >> nPoly >> i; - - // taking the amount of points of each polygon, retrieving the total number of points - if ( static_cast< sal_uInt32 >(nPoly) < SAL_MAX_UINT32 / sizeof(UINT16) ) - { - if ( ( static_cast< sal_uInt32 >( nPoly ) * sizeof(UINT16) ) <= ( nEndPos - pWMF->Tell() ) ) - { - pnPoints = new UINT16[ nPoly ]; - - for ( i = 0; i < nPoly; i++ ) - { - *pWMF >> nPoints; - pnPoints[ i ] = (UINT16)nPoints; - } - - // Polygonpunkte holen: - - for ( i = 0; ( i < nPoly ) && !pWMF->IsEof(); i++ ) - { - Polygon aPoly( pnPoints[ i ] ); - for( UINT16 k = 0; k < pnPoints[ i ]; k++ ) - { - *pWMF >> nX32 >> nY32; - aPoly[ k ] = Point( nX32, nY32 ); - } - pOut->DrawPolyLine( aPoly, sal_False, bRecordPath ); - } - delete[] pnPoints; - } - } - } - break; - - case EMR_POLYPOLYGON : - { - UINT16* pnPoints; - Point* pPtAry; - - UINT32 i, nPoly, nGesPoints; - pWMF->SeekRel( 0x10 ); - - // Anzahl der Polygone: - *pWMF >> nPoly >> nGesPoints; - - if ( ( nGesPoints < SAL_MAX_UINT32 / sizeof(Point) ) && ( nPoly < SAL_MAX_UINT32 / sizeof(UINT16) ) ) - { - if ( ( nPoly * sizeof(UINT16) ) <= ( nEndPos - pWMF->Tell() ) ) - { - pnPoints = new UINT16[ nPoly ]; - - for ( i = 0; i < nPoly; i++ ) - { - *pWMF >> nPoints; - pnPoints[ i ] = (UINT16)nPoints; - } - - if ( ( nGesPoints * (sizeof(sal_uInt32)+sizeof(sal_uInt32)) ) <= ( nEndPos - pWMF->Tell() ) ) - { - // Polygonpunkte holen: - pPtAry = new Point[ nGesPoints ]; - - for ( i = 0; i < nGesPoints; i++ ) - { - *pWMF >> nX32 >> nY32; - pPtAry[ i ] = Point( nX32, nY32 ); - } - // PolyPolygon Actions erzeugen - PolyPolygon aPolyPoly( (UINT16)nPoly, pnPoints, pPtAry ); - pOut->DrawPolyPolygon( aPolyPoly, bRecordPath ); - delete[] pPtAry; - } - delete[] pnPoints; - } - } - } - break; - - case EMR_SETWINDOWEXTEX : - { // #75383# - *pWMF >> nW >> nH; - pOut->SetWinExt( Size( nW, nH ) ); - } - break; - - case EMR_SETWINDOWORGEX : - { - *pWMF >> nX32 >> nY32; - pOut->SetWinOrg( Point( nX32, nY32 ) ); - } - break; - - case EMR_SCALEWINDOWEXTEX : - { - *pWMF >> nNom1 >> nDen1 >> nNom2 >> nDen2; - pOut->ScaleWinExt( (double)nNom1 / nDen1, (double)nNom2 / nDen2 ); - } - break; - - case EMR_SETVIEWPORTORGEX : - { - *pWMF >> nX32 >> nY32; - pOut->SetDevOrg( Point( nX32, nY32 ) ); - } - break; - - case EMR_SCALEVIEWPORTEXTEX : - { - *pWMF >> nNom1 >> nDen1 >> nNom2 >> nDen2; - pOut->ScaleDevExt( (double)nNom1 / nDen1, (double)nNom2 / nDen2 ); - } - break; - - case EMR_SETVIEWPORTEXTEX : - { - *pWMF >> nW >> nH; - pOut->SetDevExt( Size( nW, nH ) ); - } - break; - - case EMR_EOF : - nRecordCount = 0; // #76846# - break; - - case EMR_SETPIXELV : - { - *pWMF >> nX32 >> nY32; - pOut->DrawPixel( Point( nX32, nY32 ), ReadColor() ); - } - break; - - case EMR_SETMAPMODE : - { - sal_uInt32 nMapMode; - *pWMF >> nMapMode; - pOut->SetMapMode( nMapMode ); - } - break; - - case EMR_SETBKMODE : - { - *pWMF >> nDat32; - pOut->SetBkMode( nDat32 ); - } - break; - - case EMR_SETPOLYFILLMODE : - break; - - case EMR_SETROP2 : - { - *pWMF >> nDat32; - pOut->SetRasterOp( nDat32 ); - } - break; - - case EMR_SETSTRETCHBLTMODE : - { - *pWMF >> nStretchBltMode; - } - break; - - case EMR_SETTEXTALIGN : - { - *pWMF >> nDat32; - pOut->SetTextAlign( nDat32 ); - } - break; - - case EMR_SETTEXTCOLOR : - { - pOut->SetTextColor( ReadColor() ); - } - break; - - case EMR_SETBKCOLOR : - { - pOut->SetBkColor( ReadColor() ); - } - break; - - case EMR_OFFSETCLIPRGN : - { - *pWMF >> nX32 >> nY32; - pOut->MoveClipRegion( Size( nX32, nY32 ) ); - } - break; - - case EMR_MOVETOEX : - { - *pWMF >> nX32 >> nY32; - pOut->MoveTo( Point( nX32, nY32 ), bRecordPath ); - } - break; - - case EMR_INTERSECTCLIPRECT : - { - *pWMF >> nX32 >> nY32 >> nx32 >> ny32; - pOut->IntersectClipRect( ReadRectangle( nX32, nY32, nx32, ny32 ) ); - } - break; - - case EMR_SAVEDC : - { - pOut->Push(); - } - break; - - case EMR_RESTOREDC : - { - pOut->Pop(); - } - break; - - case EMR_SETWORLDTRANSFORM : - { - XForm aTempXForm; - *pWMF >> aTempXForm; - pOut->SetWorldTransform( aTempXForm ); - } - break; - - case EMR_MODIFYWORLDTRANSFORM : - { - UINT32 nMode; - XForm aTempXForm; - *pWMF >> aTempXForm >> nMode; - pOut->ModifyWorldTransform( aTempXForm, nMode ); - } - break; - - case EMR_SELECTOBJECT : - { - *pWMF >> nIndex; - pOut->SelectObject( nIndex ); - } - break; - - case EMR_CREATEPEN : - { - *pWMF >> nIndex; - if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) - { - - LineInfo aLineInfo; - UINT32 nStyle; - Size aSize; - - *pWMF >> nStyle >> aSize.Width() >> aSize.Height(); - - if ( aSize.Width() ) - aLineInfo.SetWidth( aSize.Width() ); - - BOOL bTransparent = FALSE; - UINT16 nDashCount = 0; - UINT16 nDotCount = 0; - switch( nStyle ) - { - case PS_DASHDOTDOT : - nDotCount++; - case PS_DASHDOT : - nDashCount++; - case PS_DOT : - nDotCount++; - break; - case PS_DASH : - nDashCount++; - break; - case PS_NULL : - bTransparent = TRUE; - aLineInfo.SetStyle( LINE_NONE ); - break; - default : - case PS_INSIDEFRAME : - case PS_SOLID : - aLineInfo.SetStyle( LINE_SOLID ); - } - if ( nDashCount | nDotCount ) - { - aLineInfo.SetStyle( LINE_DASH ); - aLineInfo.SetDashCount( nDashCount ); - aLineInfo.SetDotCount( nDotCount ); - } - pOut->CreateObject( nIndex, GDI_PEN, new WinMtfLineStyle( ReadColor(), aLineInfo, bTransparent ) ); - } - } - break; - - case EMR_EXTCREATEPEN : - { - sal_Int32 elpHatch; - sal_uInt32 offBmi, cbBmi, offBits, cbBits, nStyle, nWidth, nBrushStyle, elpNumEntries; - Color aColorRef; - - *pWMF >> nIndex; - if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) - { - *pWMF >> offBmi >> cbBmi >> offBits >> cbBits >> nStyle >> nWidth >> nBrushStyle; - aColorRef = ReadColor(); - *pWMF >> elpHatch >> elpNumEntries; - - LineInfo aLineInfo; - if ( nWidth ) - aLineInfo.SetWidth( nWidth ); - - sal_Bool bTransparent = sal_False; - sal_uInt16 nDashCount = 0; - sal_uInt16 nDotCount = 0; - - switch( nStyle & PS_STYLE_MASK ) - { - case PS_DASHDOTDOT : - nDotCount++; - case PS_DASHDOT : - nDashCount++; - case PS_DOT : - nDotCount++; - break; - case PS_DASH : - nDashCount++; - break; - case PS_NULL : - bTransparent = sal_True; - aLineInfo.SetStyle( LINE_NONE ); - break; - - default : - case PS_INSIDEFRAME : - case PS_SOLID : - aLineInfo.SetStyle( LINE_SOLID ); - } - if ( nDashCount | nDotCount ) - { - aLineInfo.SetStyle( LINE_DASH ); - aLineInfo.SetDashCount( nDashCount ); - aLineInfo.SetDotCount( nDotCount ); - } - pOut->CreateObject( nIndex, GDI_PEN, new WinMtfLineStyle( aColorRef, aLineInfo, bTransparent ) ); - } - } - break; - - case EMR_CREATEBRUSHINDIRECT : - { - UINT32 nStyle; - *pWMF >> nIndex; - if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) - { - *pWMF >> nStyle; - pOut->CreateObject( nIndex, GDI_BRUSH, new WinMtfFillStyle( ReadColor(), ( nStyle == BS_HOLLOW ) ? TRUE : FALSE ) ); - } - } - break; - - case EMR_DELETEOBJECT : - { - *pWMF >> nIndex; - if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) - pOut->DeleteObject( nIndex ); - } - break; - - case EMR_ELLIPSE : - { - *pWMF >> nX32 >> nY32 >> nx32 >> ny32; - pOut->DrawEllipse( ReadRectangle( nX32, nY32, nx32, ny32 ) ); - } - break; - - case EMR_RECTANGLE : - { - *pWMF >> nX32 >> nY32 >> nx32 >> ny32; - pOut->DrawRect( ReadRectangle( nX32, nY32, nx32, ny32 ) ); - } - break; - - case EMR_ROUNDRECT : - { - *pWMF >> nX32 >> nY32 >> nx32 >> ny32 >> nW >> nH; - Size aSize( Size( nW, nH ) ); - pOut->DrawRoundRect( ReadRectangle( nX32, nY32, nx32, ny32 ), aSize ); - } - break; - - case EMR_ARC : - { - UINT32 nStartX, nStartY, nEndX, nEndY; - *pWMF >> nX32 >> nY32 >> nx32 >> ny32 >> nStartX >> nStartY >> nEndX >> nEndY; - pOut->DrawArc( ReadRectangle( nX32, nY32, nx32, ny32 ), Point( nStartX, nStartY ), Point( nEndX, nEndY ) ); - } - break; - - case EMR_CHORD : - { - UINT32 nStartX, nStartY, nEndX, nEndY; - *pWMF >> nX32 >> nY32 >> nx32 >> ny32 >> nStartX >> nStartY >> nEndX >> nEndY; - pOut->DrawChord( ReadRectangle( nX32, nY32, nx32, ny32 ), Point( nStartX, nStartY ), Point( nEndX, nEndY ) ); - } - break; - - case EMR_PIE : - { - UINT32 nStartX, nStartY, nEndX, nEndY; - *pWMF >> nX32 >> nY32 >> nx32 >> ny32 >> nStartX >> nStartY >> nEndX >> nEndY; - const Rectangle aRect( ReadRectangle( nX32, nY32, nx32, ny32 )); - - // #i73608# OutputDevice deviates from WMF - // semantics. start==end means full ellipse here. - if( nStartX == nEndX && nStartY == nEndY ) - pOut->DrawEllipse( aRect ); - else - pOut->DrawPie( aRect, Point( nStartX, nStartY ), Point( nEndX, nEndY ) ); - } - break; - - case EMR_LINETO : - { - *pWMF >> nX32 >> nY32; - pOut->LineTo( Point( nX32, nY32 ), bRecordPath ); - } - break; - - case EMR_ARCTO : - { - UINT32 nStartX, nStartY, nEndX, nEndY; - *pWMF >> nX32 >> nY32 >> nx32 >> ny32 >> nStartX >> nStartY >> nEndX >> nEndY; - pOut->DrawArc( ReadRectangle( nX32, nY32, nx32, ny32 ), Point( nStartX, nStartY ), Point( nEndX, nEndY ), TRUE ); - } - break; - - case EMR_BEGINPATH : - { - pOut->ClearPath(); - bRecordPath = sal_True; - } - break; - - case EMR_ABORTPATH : - pOut->ClearPath(); - case EMR_ENDPATH : - bRecordPath = sal_False; - break; - - case EMR_CLOSEFIGURE : - pOut->ClosePath(); - break; - - case EMR_FILLPATH : - pOut->StrokeAndFillPath( sal_False, sal_True ); - break; - - case EMR_STROKEANDFILLPATH : - pOut->StrokeAndFillPath( sal_True, sal_True ); - break; - - case EMR_STROKEPATH : - pOut->StrokeAndFillPath( sal_True, sal_False ); - break; - - case EMR_SELECTCLIPPATH : - { - sal_Int32 nClippingMode; - *pWMF >> nClippingMode; - pOut->SetClipPath( pOut->GetPathObj(), nClippingMode, sal_True ); - } - break; - - case EMR_EXTSELECTCLIPRGN : - { - sal_Int32 iMode, cbRgnData; - *pWMF >> cbRgnData - >> iMode; - - PolyPolygon aPolyPoly; - if ( cbRgnData ) - ImplReadRegion( aPolyPoly, *pWMF, nRecSize ); - pOut->SetClipPath( aPolyPoly, iMode, sal_False ); - } - break; - - case EMR_BITBLT : // PASSTHROUGH INTENDED - case EMR_STRETCHBLT : - { - INT32 xDest, yDest, cxDest, cyDest, xSrc, ySrc, cxSrc, cySrc; - UINT32 dwRop, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc; - XForm xformSrc; - - UINT32 nStart = pWMF->Tell() - 8; - - pWMF->SeekRel( 0x10 ); - *pWMF >> xDest >> yDest >> cxDest >> cyDest >> dwRop >> xSrc >> ySrc - >> xformSrc >> nColor >> iUsageSrc >> offBmiSrc >> cbBmiSrc - >> offBitsSrc >> cbBitsSrc; - - if ( nRecType == EMR_STRETCHBLT ) - *pWMF >> cxSrc >> cySrc; - else - cxSrc = cySrc = 0; - - Bitmap aBitmap; - Rectangle aRect( Point( xDest, yDest ), Size( cxDest+1, cyDest+1 ) ); - - cxDest = abs( (int)cxDest ); // sj: i37894, size can be negative - cyDest = abs( (int)cyDest ); // and also 122889 - - if ( (cbBitsSrc > (SAL_MAX_UINT32 - 14)) || ((SAL_MAX_UINT32 - 14) - cbBitsSrc < cbBmiSrc) ) - bStatus = FALSE; - else - { - UINT32 nSize = cbBmiSrc + cbBitsSrc + 14; - if ( nSize <= ( nEndPos - nStartPos ) ) - { - char* pBuf = new char[ nSize ]; - SvMemoryStream aTmp( pBuf, nSize, STREAM_READ | STREAM_WRITE ); - aTmp.ObjectOwnsMemory( TRUE ); - aTmp << (BYTE)'B' - << (BYTE)'M' - << (UINT32)cbBitsSrc - << (UINT16)0 - << (UINT16)0 - << (UINT32)cbBmiSrc + 14; - pWMF->Seek( nStart + offBmiSrc ); - pWMF->Read( pBuf + 14, cbBmiSrc ); - pWMF->Seek( nStart + offBitsSrc ); - pWMF->Read( pBuf + 14 + cbBmiSrc, cbBitsSrc ); - aTmp.Seek( 0 ); - aBitmap.Read( aTmp, TRUE ); - - // test if it is sensible to crop - if ( ( cxSrc > 0 ) && ( cySrc > 0 ) && - ( xSrc >= 0 ) && ( ySrc >= 0 ) && - ( xSrc + cxSrc <= aBitmap.GetSizePixel().Width() ) && - ( ySrc + cySrc <= aBitmap.GetSizePixel().Height() ) ) - { - Rectangle aCropRect( Point( xSrc, ySrc ), Size( cxSrc, cySrc ) ); - aBitmap.Crop( aCropRect ); - } - aBmpSaveList.Insert( new BSaveStruct( aBitmap, aRect, dwRop ), LIST_APPEND ); - } - } - } - break; - - case EMR_STRETCHDIBITS : - { - INT32 xDest, yDest, xSrc, ySrc, cxSrc, cySrc, cxDest, cyDest; - UINT32 offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, iUsageSrc, dwRop; - UINT32 nStart = pWMF->Tell() - 8; - - pWMF->SeekRel( 0x10 ); - *pWMF >> xDest >> yDest >> xSrc >> ySrc >> cxSrc >> cySrc >> offBmiSrc >> cbBmiSrc >> offBitsSrc - >> cbBitsSrc >> iUsageSrc >> dwRop >> cxDest >> cyDest; - - Bitmap aBitmap; - Rectangle aRect( Point( xDest, yDest ), Size( cxDest+1, cyDest+1 ) ); - - cxDest = abs( (int)cxDest ); // sj: i37894, size can be negative - cyDest = abs( (int)cyDest ); // and also 122889 - - if ( (cbBitsSrc > (SAL_MAX_UINT32 - 14)) || ((SAL_MAX_UINT32 - 14) - cbBitsSrc < cbBmiSrc) ) - bStatus = FALSE; - else - { - UINT32 nSize = cbBmiSrc + cbBitsSrc + 14; - if ( nSize <= ( nEndPos - nStartPos ) ) - { - char* pBuf = new char[ nSize ]; - SvMemoryStream aTmp( pBuf, nSize, STREAM_READ | STREAM_WRITE ); - aTmp.ObjectOwnsMemory( TRUE ); - aTmp << (BYTE)'B' - << (BYTE)'M' - << (UINT32)cbBitsSrc - << (UINT16)0 - << (UINT16)0 - << (UINT32)cbBmiSrc + 14; - pWMF->Seek( nStart + offBmiSrc ); - pWMF->Read( pBuf + 14, cbBmiSrc ); - pWMF->Seek( nStart + offBitsSrc ); - pWMF->Read( pBuf + 14 + cbBmiSrc, cbBitsSrc ); - aTmp.Seek( 0 ); - aBitmap.Read( aTmp, TRUE ); - - // test if it is sensible to crop - if ( ( cxSrc > 0 ) && ( cySrc > 0 ) && - ( xSrc >= 0 ) && ( ySrc >= 0 ) && - ( xSrc + cxSrc <= aBitmap.GetSizePixel().Width() ) && - ( ySrc + cySrc <= aBitmap.GetSizePixel().Height() ) ) - { - Rectangle aCropRect( Point( xSrc, ySrc ), Size( cxSrc, cySrc ) ); - aBitmap.Crop( aCropRect ); - } - aBmpSaveList.Insert( new BSaveStruct( aBitmap, aRect, dwRop ), LIST_APPEND ); - } - } - } - break; - - case EMR_EXTCREATEFONTINDIRECTW : - { - *pWMF >> nIndex; - if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) - { - LOGFONTW aLogFont; - *pWMF >> aLogFont.lfHeight >> aLogFont.lfWidth >> aLogFont.lfEscapement >> aLogFont.lfOrientation >> aLogFont.lfWeight >> aLogFont.lfItalic - >> aLogFont.lfUnderline >> aLogFont.lfStrikeOut >> aLogFont.lfCharSet >> aLogFont.lfOutPrecision >> aLogFont.lfClipPrecision - >> aLogFont.lfQuality >> aLogFont.lfPitchAndFamily; - - sal_Unicode lfFaceName[ LF_FACESIZE ]; - - for ( int i = 0; i < LF_FACESIZE; i++ ) - { - UINT16 nChar; - *pWMF >> nChar; - lfFaceName[ i ] = nChar; - } - aLogFont.alfFaceName = UniString( lfFaceName ); - pOut->CreateObject( nIndex, GDI_FONT, new WinMtfFontStyle( aLogFont ) ); - } - } - break; - - case EMR_EXTTEXTOUTA : - bFlag = sal_True; - case EMR_EXTTEXTOUTW : - { - sal_Int32 nLeft, nTop, nRight, nBottom, ptlReferenceX, ptlReferenceY, nGfxMode, nXScale, nYScale; - sal_uInt32 nCurPos, nLen, nOffString, nOptions, offDx; - sal_Int32* pDX = NULL; - - nCurPos = pWMF->Tell() - 8; - - *pWMF >> nLeft >> nTop >> nRight >> nBottom >> nGfxMode >> nXScale >> nYScale - >> ptlReferenceX >> ptlReferenceY >> nLen >> nOffString >> nOptions; - - pWMF->SeekRel( 0x10 ); - *pWMF >> offDx; - - sal_Int32 nTextLayoutMode = TEXT_LAYOUT_DEFAULT; - if ( nOptions & ETO_RTLREADING ) - nTextLayoutMode = TEXT_LAYOUT_BIDI_RTL | TEXT_LAYOUT_TEXTORIGIN_LEFT; - pOut->SetTextLayoutMode( nTextLayoutMode ); - DBG_ASSERT( ( nOptions & ( ETO_PDY | ETO_GLYPH_INDEX ) ) == 0, "SJ: ETO_PDY || ETO_GLYPH_INDEX in EMF" ); - - Point aPos( ptlReferenceX, ptlReferenceY ); - if ( nLen && ( nLen < SAL_MAX_UINT32 / sizeof(sal_Int32) ) ) - { - if ( offDx && (( nCurPos + offDx + nLen * 4 ) <= nNextPos ) ) - { - pWMF->Seek( nCurPos + offDx ); - if ( ( nLen * sizeof(sal_uInt32) ) <= ( nEndPos - pWMF->Tell() ) ) - { - pDX = new sal_Int32[ nLen ]; - sal_uInt32 i; - for ( i = 0; i < nLen; i++ ) - *pWMF >> pDX[ i ]; - } - } - pWMF->Seek( nCurPos + nOffString ); - String aText; - if ( bFlag ) - { - if ( nLen <= ( nEndPos - pWMF->Tell() ) ) - { - sal_Char* pBuf = new sal_Char[ nLen ]; - pWMF->Read( pBuf, nLen ); - aText = String( pBuf, (sal_uInt16)nLen, pOut->GetCharSet() ); - delete[] pBuf; - - if ( aText.Len() != nLen ) - { - sal_uInt16 i, j, k; - sal_Int32* pOldDx = pDX; - pDX = new sal_Int32[ aText.Len() ]; - for ( i = 0, j = 0; i < aText.Len(); i++ ) - { - ByteString aCharacter( aText.GetChar( i ), pOut->GetCharSet() ); - pDX[ i ] = 0; - for ( k = 0; ( k < aCharacter.Len() ) && ( j < nLen ) && ( i < aText.Len() ); k++ ) - pDX[ i ] += pOldDx[ j++ ]; - } - delete[] pOldDx; - } - } - } - else - { - if ( ( nLen * sizeof(sal_Unicode) ) <= ( nEndPos - pWMF->Tell() ) ) - { - sal_Unicode* pBuf = new sal_Unicode[ nLen ]; - pWMF->Read( pBuf, nLen << 1 ); -#ifdef OSL_BIGENDIAN - sal_Char nTmp, *pTmp = (sal_Char*)( pBuf + nLen ); - while ( pTmp-- != (sal_Char*)pBuf ) - { - nTmp = *pTmp--; - pTmp[ 1 ] = *pTmp; - *pTmp = nTmp; - } -#endif - aText = String( pBuf, (xub_StrLen)nLen ); - delete[] pBuf; - } - } - pOut->DrawText( aPos, aText, pDX, bRecordPath, nGfxMode ); - } - delete[] pDX; - } - break; - - case EMR_POLYBEZIERTO16 : - bFlag = sal_True; - case EMR_POLYBEZIER16 : - { - pWMF->SeekRel( 16 ); - *pWMF >> nPoints; - UINT16 i = 0; - if ( bFlag ) - { - i++; - nPoints++; - } - Polygon aPoly( (UINT16)nPoints ); - for( ; i < (UINT16)nPoints; i++ ) - { - *pWMF >> nX16 >> nY16; - aPoly[ i ] = Point( nX16, nY16 ); - } - pOut->DrawPolyBezier( aPoly, bFlag, bRecordPath ); // Line( aPoly, bFlag ); - } - break; - - case EMR_POLYGON16 : - { - pWMF->SeekRel( 16 ); - *pWMF >> nPoints; - Polygon aPoly( (UINT16)nPoints ); - for( UINT16 k = 0; k < (UINT16)nPoints; k++ ) - { - *pWMF >> nX16 >> nY16; - aPoly[ k ] = Point( nX16, nY16 ); - } - pOut->DrawPolygon( aPoly, bRecordPath ); - } - break; - - case EMR_POLYLINETO16 : - bFlag = sal_True; - case EMR_POLYLINE16 : - { - pWMF->SeekRel( 16 ); - *pWMF >> nPoints; - UINT16 i = 0; - if ( bFlag ) - { - i++; - nPoints++; - } - - Polygon aPoly( (UINT16)nPoints ); - for( ; i < (UINT16)nPoints; i++ ) - { - *pWMF >> nX16 >> nY16; - aPoly[ i ] = Point( nX16, nY16 ); - } - pOut->DrawPolyLine( aPoly, bFlag, bRecordPath ); - } - break; - - case EMR_POLYPOLYLINE16 : - { - UINT16* pnPoints; - - INT32 i, nPoly, nGesPoints; - pWMF->SeekRel( 0x10 ); - // Anzahl der Polygone: - *pWMF >> nPoly >> nGesPoints; - - // taking the amount of points of each polygon, retrieving the total number of points - if ( static_cast< sal_uInt32 >(nPoly) < SAL_MAX_UINT32 / sizeof(UINT16) ) - { - if ( ( static_cast< sal_uInt32 >( nPoly ) * sizeof(UINT16) ) <= ( nEndPos - pWMF->Tell() ) ) - { - pnPoints = new UINT16[ nPoly ]; - for ( i = 0; i < nPoly; i++ ) - { - *pWMF >> nPoints; - pnPoints[ i ] = (UINT16)nPoints; - } - // Polygonpunkte holen: - for ( i = 0; ( i < nPoly ) && !pWMF->IsEof(); i++ ) - { - Polygon aPolygon( pnPoints[ i ] ); - for ( UINT16 k = 0; k < pnPoints[ i ]; k++ ) - { - *pWMF >> nX16 >> nY16; - aPolygon[ k ] = Point( nX16, nY16 ); - } - pOut->DrawPolyLine( aPolygon, sal_False, bRecordPath ); - } - delete[] pnPoints; - } - } - } - break; - - case EMR_POLYPOLYGON16 : - { - UINT16* pnPoints; - Point* pPtAry; - - UINT32 i, nPoly, nGesPoints; - pWMF->SeekRel( 0x10 ); - // Anzahl der Polygone: - *pWMF >> nPoly >> nGesPoints; - if ( ( nGesPoints < SAL_MAX_UINT32 / sizeof(Point) ) && ( nPoly < SAL_MAX_UINT32 / sizeof(UINT16) ) ) - { - if ( ( static_cast< sal_uInt32 >( nPoly ) * sizeof( UINT16 ) ) <= ( nEndPos - pWMF->Tell() ) ) - { - pnPoints = new UINT16[ nPoly ]; - for ( i = 0; i < nPoly; i++ ) - { - *pWMF >> nPoints; - pnPoints[ i ] = (UINT16)nPoints; - } - if ( ( nGesPoints * (sizeof(sal_uInt16)+sizeof(sal_uInt16)) ) <= ( nEndPos - pWMF->Tell() ) ) - { - // Polygonpunkte holen: - pPtAry = new Point[ nGesPoints ]; - for ( i = 0; i < nGesPoints; i++ ) - { - *pWMF >> nX16 >> nY16; - pPtAry[ i ] = Point( nX16, nY16 ); - } - - // PolyPolygon Actions erzeugen - PolyPolygon aPolyPoly( (UINT16)nPoly, pnPoints, pPtAry ); - pOut->DrawPolyPolygon( aPolyPoly, bRecordPath ); - delete[] pPtAry; - } - delete[] pnPoints; - } - } - } - break; - - case EMR_FILLRGN : - { - sal_uInt32 nLen; - PolyPolygon aPolyPoly; - pWMF->SeekRel( 0x10 ); - *pWMF >> nLen >> nIndex; - - if ( ImplReadRegion( aPolyPoly, *pWMF, nRecSize ) ) - { - pOut->Push(); - pOut->SelectObject( nIndex ); - pOut->DrawPolyPolygon( aPolyPoly, sal_False ); - pOut->Pop(); - } - } - break; - - -#ifdef WIN_MTF_ASSERT - default : WinMtfAssertHandler( "Unknown Meta Action" ); break; - case EMR_MASKBLT : WinMtfAssertHandler( "MaskBlt" ); break; - case EMR_PLGBLT : WinMtfAssertHandler( "PlgBlt" ); break; - case EMR_SETDIBITSTODEVICE : WinMtfAssertHandler( "SetDIBitsToDevice" ); break; - case EMR_FRAMERGN : WinMtfAssertHandler( "FrameRgn" ); break; - case EMR_INVERTRGN : WinMtfAssertHandler( "InvertRgn" ); break; - case EMR_PAINTRGN : WinMtfAssertHandler( "PaintRgn" ); break; - case EMR_FLATTENPATH : WinMtfAssertHandler( "FlattenPath" ); break; - case EMR_WIDENPATH : WinMtfAssertHandler( "WidenPath" ); break; - case EMR_POLYDRAW : WinMtfAssertHandler( "Polydraw" ); break; - case EMR_SETARCDIRECTION : WinMtfAssertHandler( "SetArcDirection" ); break; - case EMR_SETPALETTEENTRIES : WinMtfAssertHandler( "SetPaletteEntries" ); break; - case EMR_RESIZEPALETTE : WinMtfAssertHandler( "ResizePalette" ); break; - case EMR_EXTFLOODFILL : WinMtfAssertHandler( "ExtFloodFill" ); break; - case EMR_ANGLEARC : WinMtfAssertHandler( "AngleArc" ); break; - case EMR_SETCOLORADJUSTMENT : WinMtfAssertHandler( "SetColorAdjustment" ); break; - case EMR_POLYDRAW16 : WinMtfAssertHandler( "PolyDraw16" ); break; - case EMR_CREATEDIBPATTERNBRUSHPT : WinMtfAssertHandler( "CreateDibPatternBrushPt" ); break; - case EMR_POLYTEXTOUTA : WinMtfAssertHandler( "PolyTextOutA" ); break; - case EMR_POLYTEXTOUTW : WinMtfAssertHandler( "PolyTextOutW" ); break; - case EMR_CREATECOLORSPACE : WinMtfAssertHandler( "CreateColorSpace" ); break; - case EMR_SETCOLORSPACE : WinMtfAssertHandler( "SetColorSpace" ); break; - case EMR_DELETECOLORSPACE : WinMtfAssertHandler( "DeleteColorSpace" ); break; - case EMR_GLSRECORD : WinMtfAssertHandler( "GlsRecord" ); break; - case EMR_GLSBOUNDEDRECORD : WinMtfAssertHandler( "GlsBoundRecord" ); break; - case EMR_PIXELFORMAT : WinMtfAssertHandler( "PixelFormat" ); break; - case EMR_DRAWESCAPE : WinMtfAssertHandler( "DrawEscape" ); break; - case EMR_EXTESCAPE : WinMtfAssertHandler( "ExtEscape" ); break; - case EMR_STARTDOC : WinMtfAssertHandler( "StartDoc" ); break; - case EMR_SMALLTEXTOUT : WinMtfAssertHandler( "SmallTextOut" ); break; - case EMR_FORCEUFIMAPPING : WinMtfAssertHandler( "ForceUFIMapping" ); break; - case EMR_NAMEDESCAPE : WinMtfAssertHandler( "NamedEscape" ); break; - case EMR_COLORCORRECTPALETTE : WinMtfAssertHandler( "ColorCorrectPalette" ); break; - case EMR_SETICMPROFILEA : WinMtfAssertHandler( "SetICMProfileA" ); break; - case EMR_SETICMPROFILEW : WinMtfAssertHandler( "SetICMProfileW" ); break; - case EMR_ALPHABLEND : WinMtfAssertHandler( "Alphablend" ); break; - case EMR_TRANSPARENTBLT : WinMtfAssertHandler( "TransparenBlt" ); break; - case EMR_TRANSPARENTDIB : WinMtfAssertHandler( "TransparenDib" ); break; - case EMR_GRADIENTFILL : WinMtfAssertHandler( "GradientFill" ); break; - case EMR_SETLINKEDUFIS : WinMtfAssertHandler( "SetLinkedUFIS" ); break; - - case EMR_SETMAPPERFLAGS : WinMtfAssertHandler( "SetMapperFlags", 0 ); break; - case EMR_SETICMMODE : WinMtfAssertHandler( "SetICMMode", 0 ); break; - case EMR_CREATEMONOBRUSH : WinMtfAssertHandler( "CreateMonoBrush", 0 ); break; - case EMR_SETBRUSHORGEX : WinMtfAssertHandler( "SetBrushOrgEx", 0 ); break; - case EMR_SETMETARGN : WinMtfAssertHandler( "SetMetArgn", 0 ); break; - case EMR_SETMITERLIMIT : WinMtfAssertHandler( "SetMiterLimit", 0 ); break; - case EMR_EXCLUDECLIPRECT : WinMtfAssertHandler( "ExcludeClipRect", 0 ); break; - case EMR_REALIZEPALETTE : WinMtfAssertHandler( "RealizePalette", 0 ); break; - case EMR_SELECTPALETTE : WinMtfAssertHandler( "SelectPalette", 0 ); break; - case EMR_CREATEPALETTE : WinMtfAssertHandler( "CreatePalette", 0 ); break; - case EMR_ALPHADIBBLEND : WinMtfAssertHandler( "AlphaDibBlend", 0 ); break; - case EMR_SETTEXTJUSTIFICATION : WinMtfAssertHandler( "SetTextJustification", 0 ); break; - - case EMR_GDICOMMENT : - case EMR_HEADER : // has already been read at ReadHeader() - break; -#endif - } - pWMF->Seek( nNextPos ); - } - if( aBmpSaveList.Count() ) - pOut->ResolveBitmapActions( aBmpSaveList ); - - if ( bStatus ) - pWMF->Seek(nEndPos); - - return bStatus; -}; - -//----------------------------------------------------------------------------------- - -BOOL EnhWMFReader::ReadHeader() -{ - UINT32 nUINT32, nHeaderSize, nPalEntries; - INT32 nLeft, nTop, nRight, nBottom; - - // METAFILEHEADER SPARE ICH MIR HIER - // Einlesen des METAHEADER - *pWMF >> nUINT32 >> nHeaderSize; - if ( nUINT32 != 1 ) // Typ - return FALSE; - - // bound size - Rectangle rclBounds; // rectangle in logical units 1/100th mm - *pWMF >> nLeft >> nTop >> nRight >> nBottom; - rclBounds.Left() = nLeft; - rclBounds.Top() = nTop; - rclBounds.Right() = nRight; - rclBounds.Bottom() = nBottom; - - // picture frame size - Rectangle rclFrame; // rectangle in device units - *pWMF >> nLeft >> nTop >> nRight >> nBottom; - rclFrame.Left() = nLeft; - rclFrame.Top() = nTop; - rclFrame.Right() = nRight; - rclFrame.Bottom() = nBottom; - - *pWMF >> nUINT32; // signature - - if ( nUINT32 != 0x464d4520 ) - return FALSE; - - *pWMF >> nUINT32; // nVersion - *pWMF >> nEndPos; // size of metafile - nEndPos += nStartPos; - - sal_uInt32 nStrmPos = pWMF->Tell(); // checking if nEndPos is valid - pWMF->Seek( STREAM_SEEK_TO_END ); - if ( pWMF->Tell() < nEndPos ) - nEndPos = pWMF->Tell(); - pWMF->Seek( nStrmPos ); - - *pWMF >> nRecordCount; - - if ( !nRecordCount ) - return FALSE; - - pWMF->SeekRel( 0xc ); - - sal_Int32 nPixX, nPixY, nMillX, nMillY; - *pWMF >> nPalEntries >> nPixX >> nPixY >> nMillX >> nMillY; - - pOut->SetrclFrame( rclFrame ); - pOut->SetrclBounds( rclBounds ); - pOut->SetRefPix( Size( nPixX, nPixY ) ); - pOut->SetRefMill( Size( nMillX, nMillY ) ); - - pWMF->Seek( nStartPos + nHeaderSize ); - return TRUE; -} - -//----------------------------------------------------------------------------------- - -Rectangle EnhWMFReader::ReadRectangle( INT32 x1, INT32 y1, INT32 x2, INT32 y2 ) -{ - Point aTL ( Point( x1, y1 ) ); - Point aBR( Point( --x2, --y2 ) ); - return Rectangle( aTL, aBR ); -} - -EnhWMFReader::~EnhWMFReader() -{ - -}; - diff --git a/svtools/source/filter.vcl/wmf/winmtf.cxx b/svtools/source/filter.vcl/wmf/winmtf.cxx deleted file mode 100644 index 787e6522b890..000000000000 --- a/svtools/source/filter.vcl/wmf/winmtf.cxx +++ /dev/null @@ -1,2203 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - - -#include "winmtf.hxx" -#include -#include -#include - -// ------------------------------------------------------------------------ - -#define WIN_MTF_MAX_CLIP_DEPTH 16 - -void WinMtfClipPath::ImpUpdateType() -{ - if ( !aPolyPoly.Count() ) - eType = EMPTY; - else if ( aPolyPoly.IsRect() ) - eType = RECTANGLE; - else - eType = COMPLEX; - - bNeedsUpdate = sal_True; -} - -void WinMtfClipPath::IntersectClipRect( const Rectangle& rRect ) -{ - if ( !aPolyPoly.Count() ) - aPolyPoly = Polygon( rRect ); - else if ( nDepth < WIN_MTF_MAX_CLIP_DEPTH ) - { - Polygon aPolygon( rRect ); - PolyPolygon aIntersection; - PolyPolygon aPolyPolyRect( aPolygon ); - aPolyPoly.GetIntersection( aPolyPolyRect, aIntersection ); - aPolyPoly = aIntersection; - nDepth++; - } - ImpUpdateType(); -} - -void WinMtfClipPath::ExcludeClipRect( const Rectangle& rRect ) -{ - if ( aPolyPoly.Count() && ( nDepth < WIN_MTF_MAX_CLIP_DEPTH ) ) - { - Polygon aPolygon( rRect ); - PolyPolygon aPolyPolyRect( aPolygon ); - PolyPolygon aDifference; - aPolyPoly.GetDifference( aPolyPolyRect, aDifference ); - aPolyPoly = aDifference; - nDepth++; - } - ImpUpdateType(); -} - -void WinMtfClipPath::SetClipPath( const PolyPolygon& rPolyPolygon, sal_Int32 nClippingMode ) -{ - if ( !rPolyPolygon.Count() ) - aPolyPoly = rPolyPolygon; - else if ( nDepth < WIN_MTF_MAX_CLIP_DEPTH ) - { - nDepth++; - - PolyPolygon aNewClipPath; - - // #115345# Watch out for empty aPolyPoly here - conceptually, - // an empty clip path is a rectangle of infinite size, but it - // is represented by an empty aPolyPoly. When intersecting - // rPolyPolygon with this _empty_ aPolyPoly, set algebra - // guarantees wrong results. - switch ( nClippingMode ) - { - case RGN_OR : - // #115345# clip stays empty, when ORing an arbitrary - // rPolyPolygon. Thus, we can save us the unnecessary - // clipper call. - if( aPolyPoly.Count() ) - aPolyPoly.GetUnion( rPolyPolygon, aNewClipPath ); - break; - case RGN_XOR : - // TODO: - // #115345# Cannot handle this case, for the time being - aPolyPoly.GetXOR( rPolyPolygon, aNewClipPath ); - break; - case RGN_DIFF : - // TODO: - // #115345# Cannot handle this case, for the time being - aPolyPoly.GetDifference( rPolyPolygon, aNewClipPath ); - break; - case RGN_AND : - // #115345# Clip becomes rPolyPolygon, when ANDing - // with an arbitrary rPolyPolygon - if( aPolyPoly.Count() ) - aPolyPoly.GetIntersection( rPolyPolygon, aNewClipPath ); - else - aNewClipPath = rPolyPolygon; - break; - case RGN_COPY : - aNewClipPath = rPolyPolygon; - break; - } - aPolyPoly = aNewClipPath; - } - ImpUpdateType(); -} - -void WinMtfClipPath::MoveClipRegion( const Size& rSize ) -{ - aPolyPoly.Move( rSize.Width(), rSize.Height() ); - bNeedsUpdate = sal_True; -} - -// ------------------------------------------------------------------------ - -void WinMtfPathObj::AddPoint( const Point& rPoint ) -{ - if ( bClosed ) - Insert( Polygon(), POLYPOLY_APPEND ); - Polygon& rPoly = ((PolyPolygon&)*this)[ Count() - 1 ]; - rPoly.Insert( rPoly.GetSize(), rPoint, POLY_NORMAL ); - bClosed = sal_False; -} - -void WinMtfPathObj::AddPolyLine( const Polygon& rPolyLine ) -{ - if ( bClosed ) - Insert( Polygon(), POLYPOLY_APPEND ); - Polygon& rPoly = ((PolyPolygon&)*this)[ Count() - 1 ]; - rPoly.Insert( rPoly.GetSize(), rPolyLine ); - bClosed = sal_False; -} - -void WinMtfPathObj::AddPolygon( const Polygon& rPoly ) -{ - Insert( rPoly, POLYPOLY_APPEND ); - bClosed = sal_True; -} - -void WinMtfPathObj::AddPolyPolygon( const PolyPolygon& rPolyPoly ) -{ - sal_uInt16 i, nCount = rPolyPoly.Count(); - for ( i = 0; i < nCount; i++ ) - Insert( rPolyPoly[ i ], POLYPOLY_APPEND ); - bClosed = sal_True; -} - -void WinMtfPathObj::ClosePath() -{ - if ( Count() ) - { - Polygon& rPoly = ((PolyPolygon&)*this)[ Count() - 1 ]; - if ( rPoly.GetSize() > 2 ) - { - Point aFirst( rPoly[ 0 ] ); - if ( aFirst != rPoly[ rPoly.GetSize() - 1 ] ) - rPoly.Insert( rPoly.GetSize(), aFirst, POLY_NORMAL ); - } - } - bClosed = sal_True; -} - -// ------------------------------------------------------------------------ - -WinMtfFontStyle::WinMtfFontStyle( LOGFONTW& rFont ) -{ - CharSet eCharSet; - if ( ( rFont.lfCharSet == OEM_CHARSET ) || ( rFont.lfCharSet == DEFAULT_CHARSET ) ) - eCharSet = gsl_getSystemTextEncoding(); - else - eCharSet = rtl_getTextEncodingFromWindowsCharset( rFont.lfCharSet ); - if ( eCharSet == RTL_TEXTENCODING_DONTKNOW ) - eCharSet = gsl_getSystemTextEncoding(); - aFont.SetCharSet( eCharSet ); - aFont.SetName( rFont.alfFaceName ); - FontFamily eFamily; - switch ( rFont.lfPitchAndFamily & 0xf0 ) - { - case FF_ROMAN: - eFamily = FAMILY_ROMAN; - break; - - case FF_SWISS: - eFamily = FAMILY_SWISS; - break; - - case FF_MODERN: - eFamily = FAMILY_MODERN; - break; - - case FF_SCRIPT: - eFamily = FAMILY_SCRIPT; - break; - - case FF_DECORATIVE: - eFamily = FAMILY_DECORATIVE; - break; - - default: - eFamily = FAMILY_DONTKNOW; - break; - } - aFont.SetFamily( eFamily ); - - FontPitch ePitch; - switch ( rFont.lfPitchAndFamily & 0x0f ) - { - case FIXED_PITCH: - ePitch = PITCH_FIXED; - break; - - case DEFAULT_PITCH: - case VARIABLE_PITCH: - default: - ePitch = PITCH_VARIABLE; - break; - } - aFont.SetPitch( ePitch ); - - FontWeight eWeight; - if( rFont.lfWeight <= FW_THIN ) - eWeight = WEIGHT_THIN; - else if( rFont.lfWeight <= FW_ULTRALIGHT ) - eWeight = WEIGHT_ULTRALIGHT; - else if( rFont.lfWeight <= FW_LIGHT ) - eWeight = WEIGHT_LIGHT; - else if( rFont.lfWeight < FW_MEDIUM ) - eWeight = WEIGHT_NORMAL; - else if( rFont.lfWeight == FW_MEDIUM ) - eWeight = WEIGHT_MEDIUM; - else if( rFont.lfWeight <= FW_SEMIBOLD ) - eWeight = WEIGHT_SEMIBOLD; - else if( rFont.lfWeight <= FW_BOLD ) - eWeight = WEIGHT_BOLD; - else if( rFont.lfWeight <= FW_ULTRABOLD ) - eWeight = WEIGHT_ULTRABOLD; - else - eWeight = WEIGHT_BLACK; - aFont.SetWeight( eWeight ); - - if( rFont.lfItalic ) - aFont.SetItalic( ITALIC_NORMAL ); - - if( rFont.lfUnderline ) - aFont.SetUnderline( UNDERLINE_SINGLE ); - - if( rFont.lfStrikeOut ) - aFont.SetStrikeout( STRIKEOUT_SINGLE ); - - if ( rFont.lfOrientation ) - aFont.SetOrientation( (short)rFont.lfOrientation ); - else - aFont.SetOrientation( (short)rFont.lfEscapement ); - - Size aFontSize( Size( rFont.lfWidth, rFont.lfHeight ) ); - if ( rFont.lfHeight > 0 ) - { - // converting the cell height into a font height - VirtualDevice aVDev; - aFont.SetSize( aFontSize ); - aVDev.SetFont( aFont ); - FontMetric aMetric( aVDev.GetFontMetric() ); - long nHeight = aMetric.GetAscent() + aMetric.GetDescent(); - if ( nHeight ) - { - double fHeight = ((double)aFontSize.Height() * rFont.lfHeight ) / nHeight; - aFontSize.Height() = (sal_Int32)( fHeight + 0.5 ); - } - } - else if ( aFontSize.Height() < 0 ) - aFontSize.Height() *= -1; - - if ( !rFont.lfWidth ) - { - VirtualDevice aVDev; - aFont.SetSize( aFontSize ); - aVDev.SetFont( aFont ); - FontMetric aMetric( aVDev.GetFontMetric() ); - aFontSize.Width() = aMetric.GetWidth(); - } - - aFont.SetSize( aFontSize ); -}; - -// ------------------------------------------------------------------------ - -#ifdef WIN_MTF_ASSERT -void WinMtfAssertHandler( const sal_Char* pAction, sal_uInt32 nFlags ) -{ - static sal_Bool bOnlyOnce; - static sal_Int32 nAssertCount; - - if ( nFlags & WIN_MTF_ASSERT_INIT ) - nAssertCount = 0; - if ( nFlags & WIN_MTF_ASSERT_ONCE ) - bOnlyOnce = sal_True; - if ( nFlags & WIN_MTF_ASSERT_MIFE ) - { - if ( ( nAssertCount == 0 ) || ( bOnlyOnce == sal_False ) ) - { - ByteString aText( "WMF/EMF Import: " ); - if ( pAction ) - { - ByteString aAction( pAction ); - aText.Append( aAction ); - } - aText.Append( " needs to be implemented (SJ)" ); - DBG_ASSERT( 0, aText.GetBuffer() ); - } - nAssertCount++; - } -} -#endif - -// ------------------------------------------------------------------------ - -WinMtf::WinMtf( WinMtfOutput* pWinMtfOutput, SvStream& rStreamWMF, FilterConfigItem* pConfigItem ) : - pOut ( pWinMtfOutput ), - pWMF ( &rStreamWMF ), - pFilterConfigItem ( pConfigItem ) -{ -#ifdef WIN_MTF_ASSERT - // we want to assert not implemented features, but we do this - // only once, so that nobody is handicaped by getting too much assertions - // I hope this will bring more testdocuments, without support of these - // testdocuments the implementation of missing features won't be possible. (SJ) - WinMtfAssertHandler( NULL, WIN_MTF_ASSERT_INIT | WIN_MTF_ASSERT_ONCE ); -#endif - - SvLockBytes *pLB = pWMF->GetLockBytes(); - if ( pLB ) - pLB->SetSynchronMode( TRUE ); - - nStartPos = pWMF->Tell(); - - pOut->SetDevOrg( Point() ); - if ( pFilterConfigItem ) - { - xStatusIndicator = pFilterConfigItem->GetStatusIndicator(); - if ( xStatusIndicator.is() ) - { - rtl::OUString aMsg; - xStatusIndicator->start( aMsg, 100 ); - } - } -} - -// ------------------------------------------------------------------------ - -WinMtf::~WinMtf() -{ - delete pOut; - - if ( xStatusIndicator.is() ) - xStatusIndicator->end(); -} - -// ------------------------------------------------------------------------ - -void WinMtf::Callback( USHORT nPercent ) -{ - if ( xStatusIndicator.is() ) - xStatusIndicator->setValue( nPercent ); -} - -// ------------------------------------------------------------------------ - -Color WinMtf::ReadColor() -{ - UINT32 nColor; - *pWMF >> nColor; - return Color( (BYTE)nColor, (BYTE)( nColor >> 8 ), (BYTE)( nColor >> 16 ) ); -}; - -//----------------------------------------------------------------------------------- -//----------------------------------------------------------------------------------- -//----------------------------------------------------------------------------------- - -Point WinMtfOutput::ImplMap( const Point& rPt ) -{ - if ( mnWinExtX && mnWinExtY ) - { - double fX2, fX = rPt.X(); - double fY2, fY = rPt.Y(); - - fX2 = fX * maXForm.eM11 + fY * maXForm.eM21 + maXForm.eDx; - fY2 = fX * maXForm.eM12 + fY * maXForm.eM22 + maXForm.eDy; - - if ( mnGfxMode == GM_COMPATIBLE ) - { - switch( mnMapMode ) - { - case MM_LOENGLISH : - { - fX2 -= mnWinOrgX; - fY2 = mnWinOrgY-fY2; - fX2 *= 25.40; - fY2 *= 25.40; - fX2 += mnDevOrgX; - fY2 += mnDevOrgY; - } - break; - case MM_HIENGLISH : - { - fX2 -= mnWinOrgX; - fY2 = mnWinOrgY-fY2; - fX2 *= 2.540; - fY2 *= 2.540; - fX2 += mnDevOrgX; - fY2 += mnDevOrgY; - } - break; - case MM_LOMETRIC : - { - fX2 -= mnWinOrgX; - fY2 = mnWinOrgY-fY2; - fX2 *= 10; - fY2 *= 10; - fX2 += mnDevOrgX; - fY2 += mnDevOrgY; - } - break; - case MM_HIMETRIC : - { - fX2 -= mnWinOrgX; - fY2 = mnWinOrgY-fY2; - fX2 += mnDevOrgX; - fY2 += mnDevOrgY; - } - break; - default : - { - fX2 -= mnWinOrgX; - fY2 -= mnWinOrgY; - fX2 /= mnWinExtX; - fY2 /= mnWinExtY; - fX2 *= mnDevWidth; - fY2 *= mnDevHeight; - fX2 += mnDevOrgX; - fY2 += mnDevOrgY; // fX2, fY2 now in device units - fX2 *= (double)mnMillX * 100.0 / (double)mnPixX; - fY2 *= (double)mnMillY * 100.0 / (double)mnPixY; - } - break; - } - fX2 -= mrclFrame.Left(); - fY2 -= mrclFrame.Top(); - } - return Point( FRound( fX2 ), FRound( fY2 ) ); - } - else - return Point(); -}; - -// ------------------------------------------------------------------------ - -Size WinMtfOutput::ImplMap( const Size& rSz ) -{ - if ( mnWinExtX && mnWinExtY ) - { - double fWidth = rSz.Width() * maXForm.eM11; - double fHeight = rSz.Height() * maXForm.eM22; - - if ( mnGfxMode == GM_COMPATIBLE ) - { - switch( mnMapMode ) - { - case MM_LOENGLISH : - { - fWidth *= 25.40; - fHeight*=-25.40; - } - break; - case MM_HIENGLISH : - { - fWidth *= 2.540; - fHeight*=-2.540; - } - break; - case MM_LOMETRIC : - { - fWidth *= 10; - fHeight*=-10; - } - break; - case MM_HIMETRIC : - { - fHeight *= -1; - } - break; - default : - { - fWidth /= mnWinExtX; - fHeight /= mnWinExtY; - fWidth *= mnDevWidth; - fHeight *= mnDevHeight; - fWidth *= (double)mnMillX * 100 / (double)mnPixX; - fHeight *= (double)mnMillY * 100 / (double)mnPixY; - } - break; - } - } - return Size( FRound( fWidth ), FRound( fHeight ) ); - } - else - return Size(); -} - -//----------------------------------------------------------------------------------- - -Rectangle WinMtfOutput::ImplMap( const Rectangle& rRect ) -{ - return Rectangle( ImplMap( rRect.TopLeft() ), ImplMap( rRect.GetSize() ) ); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::ImplMap( Font& rFont ) -{ - // !!! HACK: Wir setzen die Breite jetzt immer auf Null, - // da OS die Breite unterschiedlich interpretieren; - // muss spaeter in SV portabel gemacht werden ( KA 08.02.96 ) - Size aFontSize = ImplMap ( rFont.GetSize() ); - - if( aFontSize.Height() < 0 ) - aFontSize.Height() *= -1; - - rFont.SetSize( aFontSize ); - - if( ( mnWinExtX * mnWinExtY ) < 0 ) - rFont.SetOrientation( 3600 - rFont.GetOrientation() ); -} - -//----------------------------------------------------------------------------------- - -Polygon& WinMtfOutput::ImplMap( Polygon& rPolygon ) -{ - UINT16 nPoints = rPolygon.GetSize(); - for ( UINT16 i = 0; i < nPoints; i++ ) - { - rPolygon[ i ] = ImplMap( rPolygon[ i ] ); - } - return rPolygon; -} - -//----------------------------------------------------------------------------------- - -PolyPolygon& WinMtfOutput::ImplMap( PolyPolygon& rPolyPolygon ) -{ - UINT16 nPolys = rPolyPolygon.Count(); - for ( UINT16 i = 0; i < nPolys; ImplMap( rPolyPolygon[ i++ ] ) ) ; - return rPolyPolygon; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SelectObject( INT32 nIndex ) -{ - GDIObj* pGDIObj = NULL; - - if ( nIndex & ENHMETA_STOCK_OBJECT ) - pGDIObj = new GDIObj(); - else - { - nIndex &= 0xffff; // zur Sicherheit: mehr als 65535 nicht zulassen - - if ( (UINT32)nIndex < vGDIObj.size() ) - pGDIObj = vGDIObj[ nIndex ]; - } - - if( pGDIObj == NULL ) - return; - - if ( nIndex & ENHMETA_STOCK_OBJECT ) - { - UINT16 nStockId = (BYTE)nIndex; - switch( nStockId ) - { - case WHITE_BRUSH : - { - pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_WHITE ) ) ); - } - break; - case LTGRAY_BRUSH : - { - pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_LIGHTGRAY ) ) ); - } - break; - case GRAY_BRUSH : - case DKGRAY_BRUSH : - { - pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_GRAY ) ) ); - } - break; - case BLACK_BRUSH : - { - pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_BLACK ) ) ); - } - break; - case NULL_BRUSH : - { - pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_TRANSPARENT ), TRUE ) ); - } - break; - case WHITE_PEN : - { - pGDIObj->Set( GDI_PEN, new WinMtfLineStyle( Color( COL_WHITE ) ) ); - } - break; - case BLACK_PEN : - { - pGDIObj->Set( GDI_PEN, new WinMtfLineStyle( Color( COL_BLACK ) ) ); - } - break; - case NULL_PEN : - { - pGDIObj->Set( GDI_PEN, new WinMtfLineStyle( Color( COL_TRANSPARENT ), TRUE ) ); - } - break; - default: - break; - } - } - if ( pGDIObj->pStyle ) - { - switch( pGDIObj->eType ) - { - case GDI_PEN : - maLineStyle = (WinMtfLineStyle*)pGDIObj->pStyle; - break; - case GDI_BRUSH : - { - maFillStyle = (WinMtfFillStyle*)pGDIObj->pStyle; - mbFillStyleSelected = sal_True; - } - break; - case GDI_FONT : - maFont = ((WinMtfFontStyle*)pGDIObj->pStyle)->aFont; - break; - default: - break; // -Wall many options not handled. - } - } - if ( nIndex & ENHMETA_STOCK_OBJECT ) - delete pGDIObj; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetFont( const Font& rFont ) -{ - maFont = rFont; -} - -//----------------------------------------------------------------------------------- - -const Font& WinMtfOutput::GetFont() const -{ - return maFont; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetTextLayoutMode( const sal_uInt32 nTextLayoutMode ) -{ - mnTextLayoutMode = nTextLayoutMode; -} - -//----------------------------------------------------------------------------------- - -sal_uInt32 WinMtfOutput::GetTextLayoutMode() const -{ - return mnTextLayoutMode; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetBkMode( UINT32 nMode ) -{ - mnBkMode = nMode; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetBkColor( const Color& rColor ) -{ - maBkColor = rColor; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetTextColor( const Color& rColor ) -{ - maTextColor = rColor; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetTextAlign( UINT32 nAlign ) -{ - mnTextAlign = nAlign; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::ImplResizeObjectArry( UINT32 nNewEntrys ) -{ - sal_uInt32 i = vGDIObj.size(); - vGDIObj.resize( nNewEntrys ); - for ( ; i < nNewEntrys ; i++ ) - vGDIObj[ i ] = NULL; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::ImplDrawClippedPolyPolygon( const PolyPolygon& rPolyPoly ) -{ - if ( rPolyPoly.Count() ) - { - ImplSetNonPersistentLineColorTransparenz(); - if ( rPolyPoly.Count() == 1 ) - { - if ( rPolyPoly.IsRect() ) - mpGDIMetaFile->AddAction( new MetaRectAction( rPolyPoly.GetBoundRect() ) ); - else - { - Polygon aPoly( rPolyPoly[ 0 ] ); - sal_uInt16 nCount = aPoly.GetSize(); - if ( nCount ) - { - if ( aPoly[ nCount - 1 ] != aPoly[ 0 ] ) - { - Point aPoint( aPoly[ 0 ] ); - aPoly.Insert( nCount, aPoint ); - } - mpGDIMetaFile->AddAction( new MetaPolygonAction( aPoly ) ); - } - } - } - else - mpGDIMetaFile->AddAction( new MetaPolyPolygonAction( rPolyPoly ) ); - } -} - - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::CreateObject( GDIObjectType eType, void* pStyle ) -{ - if ( pStyle ) - { - if ( eType == GDI_FONT ) - { - ImplMap( ((WinMtfFontStyle*)pStyle)->aFont ); - if (!((WinMtfFontStyle*)pStyle)->aFont.GetHeight() ) - ((WinMtfFontStyle*)pStyle)->aFont.SetHeight( 423 ); // defaulting to 12pt - } - else if ( eType == GDI_PEN ) - { - Size aSize( ((WinMtfLineStyle*)pStyle)->aLineInfo.GetWidth(), 0 ); - ((WinMtfLineStyle*)pStyle)->aLineInfo.SetWidth( ImplMap( aSize ).Width() ); - if ( ((WinMtfLineStyle*)pStyle)->aLineInfo.GetStyle() == LINE_DASH ) - { - aSize.Width() += 1; - long nDotLen = ImplMap( aSize ).Width(); - ((WinMtfLineStyle*)pStyle)->aLineInfo.SetDistance( nDotLen ); - ((WinMtfLineStyle*)pStyle)->aLineInfo.SetDotLen( nDotLen ); - ((WinMtfLineStyle*)pStyle)->aLineInfo.SetDashLen( nDotLen * 4 ); - } - } - } - UINT32 nIndex; - for ( nIndex = 0; nIndex < vGDIObj.size(); nIndex++ ) - { - if ( vGDIObj[ nIndex ] == NULL ) - break; - } - if ( nIndex == vGDIObj.size() ) - ImplResizeObjectArry( vGDIObj.size() + 16 ); - - vGDIObj[ nIndex ] = new GDIObj( eType, pStyle ); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::CreateObject( INT32 nIndex, GDIObjectType eType, void* pStyle ) -{ - if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) - { - nIndex &= 0xffff; // zur Sicherheit: mehr als 65535 nicht zulassen - if ( pStyle ) - { - if ( eType == GDI_FONT ) - ImplMap( ((WinMtfFontStyle*)pStyle)->aFont ); - else if ( eType == GDI_PEN ) - { - Size aSize( ((WinMtfLineStyle*)pStyle)->aLineInfo.GetWidth(), 0 ); - ((WinMtfLineStyle*)pStyle)->aLineInfo.SetWidth( ImplMap( aSize ).Width() ); - if ( ((WinMtfLineStyle*)pStyle)->aLineInfo.GetStyle() == LINE_DASH ) - { - aSize.Width() += 1; - long nDotLen = ImplMap( aSize ).Width(); - ((WinMtfLineStyle*)pStyle)->aLineInfo.SetDistance( nDotLen ); - ((WinMtfLineStyle*)pStyle)->aLineInfo.SetDotLen( nDotLen ); - ((WinMtfLineStyle*)pStyle)->aLineInfo.SetDashLen( nDotLen * 4 ); - } - } - } - if ( (UINT32)nIndex >= vGDIObj.size() ) - ImplResizeObjectArry( nIndex + 16 ); - - if ( vGDIObj[ nIndex ] != NULL ) - delete vGDIObj[ nIndex ]; - - vGDIObj[ nIndex ] = new GDIObj( eType, pStyle ); - } - else - { - switch ( eType ) - { - case GDI_PEN : - delete (WinMtfLineStyle*)pStyle; - break; - case GDI_BRUSH : - delete (WinMtfFillStyle*)pStyle; - break; - case GDI_FONT : - delete (WinMtfFontStyle*)pStyle; - break; - - default: - DBG_ERROR( "unsupported style not deleted" ); - break; - } - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DeleteObject( sal_Int32 nIndex ) -{ - if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) - { - if ( (sal_uInt32)nIndex < vGDIObj.size() ) - { - delete vGDIObj[ nIndex ]; - vGDIObj[ nIndex ] = NULL; - } - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::IntersectClipRect( const Rectangle& rRect ) -{ - aClipPath.IntersectClipRect( ImplMap( rRect ) ); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::ExcludeClipRect( const Rectangle& rRect ) -{ - aClipPath.ExcludeClipRect( ImplMap( rRect ) ); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::MoveClipRegion( const Size& rSize ) -{ - aClipPath.MoveClipRegion( ImplMap( rSize ) ); -} - -void WinMtfOutput::SetClipPath( const PolyPolygon& rPolyPolygon, sal_Int32 nClippingMode, sal_Bool bIsMapped ) -{ - if ( bIsMapped ) - aClipPath.SetClipPath( rPolyPolygon, nClippingMode ); - else - { - PolyPolygon aPP( rPolyPolygon ); - aClipPath.SetClipPath( ImplMap( aPP ), nClippingMode ); - } -} - -//----------------------------------------------------------------------------------- -//----------------------------------------------------------------------------------- -//----------------------------------------------------------------------------------- - -WinMtfOutput::WinMtfOutput( GDIMetaFile& rGDIMetaFile ) : - mnLatestTextAlign ( 0 ), - mnTextAlign ( TA_LEFT | TA_TOP | TA_NOUPDATECP ), - maLatestBkColor ( 0x12345678 ), - maBkColor ( COL_WHITE ), - mnLatestTextLayoutMode( TEXT_LAYOUT_DEFAULT ), - mnTextLayoutMode ( TEXT_LAYOUT_DEFAULT ), - mnLatestBkMode ( 0 ), - mnBkMode ( OPAQUE ), - meLatestRasterOp ( ROP_INVERT ), - meRasterOp ( ROP_OVERPAINT ), - maActPos ( Point() ), - mbNopMode ( sal_False ), - mbFillStyleSelected ( sal_False ), - mnGfxMode ( GM_COMPATIBLE ), - mnMapMode ( MM_TEXT ), - mnDevOrgX ( 0 ), - mnDevOrgY ( 0 ), - mnDevWidth ( 1 ), - mnDevHeight ( 1 ), - mnWinOrgX ( 0 ), - mnWinOrgY ( 0 ), - mnWinExtX ( 1 ), - mnWinExtY ( 1 ), - mnPixX ( 100 ), - mnPixY ( 100 ), - mnMillX ( 1 ), - mnMillY ( 1 ), - mpGDIMetaFile ( &rGDIMetaFile ) -{ - mpGDIMetaFile->AddAction( new MetaPushAction( PUSH_CLIPREGION ) ); // The original clipregion has to be on top - // of the stack so it can always be restored - // this is necessary to be able to support - // SetClipRgn( NULL ) and similar ClipRgn actions (SJ) - - maFont.SetName( String( RTL_CONSTASCII_USTRINGPARAM( "Arial" )) ); // sj: #i57205#, we do have some scaling problems if using - maFont.SetCharSet( gsl_getSystemTextEncoding() ); // the default font then most times a x11 font is used, we - maFont.SetHeight( 423 ); // will prevent this defining a font - - maLatestLineStyle.aLineColor = Color( 0x12, 0x34, 0x56 ); - maLatestFillStyle.aFillColor = Color( 0x12, 0x34, 0x56 ); - - mnRop = R2_BLACK + 1; - SetRasterOp( R2_BLACK ); -}; - -//----------------------------------------------------------------------------------- - -WinMtfOutput::~WinMtfOutput() -{ - mpGDIMetaFile->AddAction( new MetaPopAction() ); - mpGDIMetaFile->SetPrefMapMode( MAP_100TH_MM ); - if ( mrclFrame.IsEmpty() ) - mpGDIMetaFile->SetPrefSize( Size( mnDevWidth, mnDevHeight ) ); - else - mpGDIMetaFile->SetPrefSize( mrclFrame.GetSize() ); - - for ( UINT32 i = 0; i < vGDIObj.size(); i++ ) - delete vGDIObj[ i ]; -}; - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::UpdateClipRegion() -{ - if ( aClipPath.bNeedsUpdate ) - { - aClipPath.bNeedsUpdate = sal_False; - - mpGDIMetaFile->AddAction( new MetaPopAction() ); // taking the orignal clipregion - mpGDIMetaFile->AddAction( new MetaPushAction( PUSH_CLIPREGION ) ); // - - switch ( aClipPath.GetType() ) - { - case RECTANGLE : - case COMPLEX : - { -// we will not generate a RegionClipRegion Action, because this action -// cannot be saved to the wmf format - saving to wmf always happens -// if the placeholder graphic for ole objects is generated. (SJ) - -// Region aClipRegion( aClipPath.GetClipPath() ); -// mpGDIMetaFile->AddAction( new MetaISectRegionClipRegionAction( aClipRegion ) ); - - Rectangle aClipRect( aClipPath.GetClipPath().GetBoundRect() ); - mpGDIMetaFile->AddAction( new MetaISectRectClipRegionAction( aClipRect ) ); - } - break; - case EMPTY: - break; // -Wall not handled. - } - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::ImplSetNonPersistentLineColorTransparenz() -{ - Color aColor( COL_TRANSPARENT); - WinMtfLineStyle aTransparentLine( aColor, TRUE ); - if ( ! ( maLatestLineStyle == aTransparentLine ) ) - { - maLatestLineStyle = aTransparentLine; - mpGDIMetaFile->AddAction( new MetaLineColorAction( aTransparentLine.aLineColor, !aTransparentLine.bTransparent ) ); - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::UpdateLineStyle() -{ - if (!( maLatestLineStyle == maLineStyle ) ) - { - maLatestLineStyle = maLineStyle; - mpGDIMetaFile->AddAction( new MetaLineColorAction( maLineStyle.aLineColor, !maLineStyle.bTransparent ) ); - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::UpdateFillStyle() -{ - if ( !mbFillStyleSelected ) // SJ: #i57205# taking care of bkcolor if no brush is selected - maFillStyle = WinMtfFillStyle( maBkColor, mnBkMode == TRANSPARENT ); - if (!( maLatestFillStyle == maFillStyle ) ) - { - maLatestFillStyle = maFillStyle; - mpGDIMetaFile->AddAction( new MetaFillColorAction( maFillStyle.aFillColor, !maFillStyle.bTransparent ) ); - } -} - -//----------------------------------------------------------------------------------- - -sal_uInt32 WinMtfOutput::SetRasterOp( UINT32 nRasterOp ) -{ - sal_uInt32 nRetROP = mnRop; - if ( nRasterOp != mnRop ) - { - mnRop = nRasterOp; - static WinMtfFillStyle aNopFillStyle; - static WinMtfLineStyle aNopLineStyle; - - if ( mbNopMode && ( nRasterOp != R2_NOP ) ) - { // beim uebergang von R2_NOP auf anderen Modus - // gesetzten Pen und Brush aktivieren - maFillStyle = aNopFillStyle; - maLineStyle = aNopLineStyle; - mbNopMode = sal_False; - } - switch( nRasterOp ) - { - case R2_NOT: - meRasterOp = ROP_INVERT; - break; - - case R2_XORPEN: - meRasterOp = ROP_XOR; - break; - - case R2_NOP: - { - meRasterOp = ROP_OVERPAINT; - if( mbNopMode == sal_False ) - { - aNopFillStyle = maFillStyle; - aNopLineStyle = maLineStyle; - maFillStyle = WinMtfFillStyle( Color( COL_TRANSPARENT ), TRUE ); - maLineStyle = WinMtfLineStyle( Color( COL_TRANSPARENT ), TRUE ); - mbNopMode = sal_True; - } - } - break; - - default: - meRasterOp = ROP_OVERPAINT; - break; - } - } - if ( nRetROP != nRasterOp ) - mpGDIMetaFile->AddAction( new MetaRasterOpAction( meRasterOp ) ); - return nRetROP; -}; - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::StrokeAndFillPath( sal_Bool bStroke, sal_Bool bFill ) -{ - if ( aPathObj.Count() ) - { - UpdateClipRegion(); - UpdateLineStyle(); - UpdateFillStyle(); - if ( bFill ) - { - if ( !bStroke ) - { - mpGDIMetaFile->AddAction( new MetaPushAction( PUSH_LINECOLOR ) ); - mpGDIMetaFile->AddAction( new MetaLineColorAction( Color(), FALSE ) ); - } - if ( aPathObj.Count() == 1 ) - mpGDIMetaFile->AddAction( new MetaPolygonAction( aPathObj.GetObject( 0 ) ) ); - else - mpGDIMetaFile->AddAction( new MetaPolyPolygonAction( aPathObj ) ); - - if ( !bStroke ) - mpGDIMetaFile->AddAction( new MetaPopAction() ); - } - else - { - sal_uInt16 i, nCount = aPathObj.Count(); - for ( i = 0; i < nCount; i++ ) - mpGDIMetaFile->AddAction( new MetaPolyLineAction( aPathObj[ i ], maLineStyle.aLineInfo ) ); - } - ClearPath(); - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DrawPixel( const Point& rSource, const Color& rColor ) -{ - mpGDIMetaFile->AddAction( new MetaPixelAction( ImplMap( rSource), rColor ) ); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::MoveTo( const Point& rPoint, sal_Bool bRecordPath ) -{ - Point aDest( ImplMap( rPoint ) ); - if ( bRecordPath ) - aPathObj.AddPoint( aDest ); - maActPos = aDest; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::LineTo( const Point& rPoint, sal_Bool bRecordPath ) -{ - UpdateClipRegion(); - - Point aDest( ImplMap( rPoint ) ); - if ( bRecordPath ) - aPathObj.AddPoint( aDest ); - else - { - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaLineAction( maActPos, aDest, maLineStyle.aLineInfo ) ); - } - maActPos = aDest; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DrawLine( const Point& rSource, const Point& rDest ) -{ - UpdateClipRegion(); - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaLineAction( ImplMap( rSource), ImplMap( rDest ), maLineStyle.aLineInfo ) ); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DrawRect( const Rectangle& rRect, BOOL bEdge ) -{ - UpdateClipRegion(); - UpdateFillStyle(); - - if ( aClipPath.GetType() == COMPLEX ) - { - Polygon aPoly( ImplMap( rRect ) ); - PolyPolygon aPolyPolyRect( aPoly ); - PolyPolygon aDest; - aClipPath.GetClipPath().GetIntersection( aPolyPolyRect, aDest ); - ImplDrawClippedPolyPolygon( aDest ); - } - else - { - if ( bEdge ) - { - if ( maLineStyle.aLineInfo.GetWidth() || ( maLineStyle.aLineInfo.GetStyle() == LINE_DASH ) ) - { - ImplSetNonPersistentLineColorTransparenz(); - mpGDIMetaFile->AddAction( new MetaRectAction( ImplMap( rRect ) ) ); - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaPolyLineAction( Polygon( ImplMap( rRect ) ),maLineStyle.aLineInfo ) ); - } - else - { - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaRectAction( ImplMap( rRect ) ) ); - } - } - else - { - ImplSetNonPersistentLineColorTransparenz(); - mpGDIMetaFile->AddAction( new MetaRectAction( ImplMap( rRect ) ) ); - } - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DrawRoundRect( const Rectangle& rRect, const Size& rSize ) -{ - UpdateClipRegion(); - UpdateLineStyle(); - UpdateFillStyle(); - mpGDIMetaFile->AddAction( new MetaRoundRectAction( ImplMap( rRect ), labs( ImplMap( rSize ).Width() ), labs( ImplMap( rSize ).Height() ) ) ); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DrawEllipse( const Rectangle& rRect ) -{ - UpdateClipRegion(); - UpdateFillStyle(); - - if ( maLineStyle.aLineInfo.GetWidth() || ( maLineStyle.aLineInfo.GetStyle() == LINE_DASH ) ) - { - Point aCenter( ImplMap( rRect.Center() ) ); - Size aRad( ImplMap( Size( rRect.GetWidth() / 2, rRect.GetHeight() / 2 ) ) ); - - ImplSetNonPersistentLineColorTransparenz(); - mpGDIMetaFile->AddAction( new MetaEllipseAction( ImplMap( rRect ) ) ); - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaPolyLineAction( Polygon( aCenter, aRad.Width(), aRad.Height() ), maLineStyle.aLineInfo ) ); - } - else - { - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaEllipseAction( ImplMap( rRect ) ) ); - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DrawArc( const Rectangle& rRect, const Point& rStart, const Point& rEnd, BOOL bTo ) -{ - UpdateClipRegion(); - UpdateLineStyle(); - UpdateFillStyle(); - - Rectangle aRect( ImplMap( rRect ) ); - Point aStart( ImplMap( rStart ) ); - Point aEnd( ImplMap( rEnd ) ); - - if ( maLineStyle.aLineInfo.GetWidth() || ( maLineStyle.aLineInfo.GetStyle() == LINE_DASH ) ) - { - if ( aStart == aEnd ) - { // SJ: #i53768# if start & end is identical, then we have to draw a full ellipse - Point aCenter( aRect.Center() ); - Size aRad( aRect.GetWidth() / 2, aRect.GetHeight() / 2 ); - - mpGDIMetaFile->AddAction( new MetaPolyLineAction( Polygon( aCenter, aRad.Width(), aRad.Height() ), maLineStyle.aLineInfo ) ); - } - else - mpGDIMetaFile->AddAction( new MetaPolyLineAction( Polygon( aRect, aStart, aEnd, POLY_ARC ), maLineStyle.aLineInfo ) ); - } - else - mpGDIMetaFile->AddAction( new MetaArcAction( aRect, aStart, aEnd ) ); - - if ( bTo ) - maActPos = aEnd; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DrawPie( const Rectangle& rRect, const Point& rStart, const Point& rEnd ) -{ - UpdateClipRegion(); - UpdateFillStyle(); - - Rectangle aRect( ImplMap( rRect ) ); - Point aStart( ImplMap( rStart ) ); - Point aEnd( ImplMap( rEnd ) ); - - if ( maLineStyle.aLineInfo.GetWidth() || ( maLineStyle.aLineInfo.GetStyle() == LINE_DASH ) ) - { - ImplSetNonPersistentLineColorTransparenz(); - mpGDIMetaFile->AddAction( new MetaPieAction( aRect, aStart, aEnd ) ); - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaPolyLineAction( Polygon( aRect, aStart, aEnd, POLY_PIE ), maLineStyle.aLineInfo ) ); - } - else - { - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaPieAction( aRect, aStart, aEnd ) ); - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DrawChord( const Rectangle& rRect, const Point& rStart, const Point& rEnd ) -{ - UpdateClipRegion(); - UpdateFillStyle(); - - Rectangle aRect( ImplMap( rRect ) ); - Point aStart( ImplMap( rStart ) ); - Point aEnd( ImplMap( rEnd ) ); - - if ( maLineStyle.aLineInfo.GetWidth() || ( maLineStyle.aLineInfo.GetStyle() == LINE_DASH ) ) - { - ImplSetNonPersistentLineColorTransparenz(); - mpGDIMetaFile->AddAction( new MetaChordAction( aRect, aStart, aEnd ) ); - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaPolyLineAction( Polygon( aRect, aStart, aEnd, POLY_CHORD ), maLineStyle.aLineInfo ) ); - } - else - { - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaChordAction( aRect, aStart, aEnd ) ); - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DrawPolygon( Polygon& rPolygon, sal_Bool bRecordPath ) -{ - UpdateClipRegion(); - ImplMap( rPolygon ); - if ( bRecordPath ) - aPathObj.AddPolygon( rPolygon ); - else - { - UpdateFillStyle(); - - if ( aClipPath.GetType() == COMPLEX ) - { - PolyPolygon aPolyPoly( rPolygon ); - PolyPolygon aDest; - aClipPath.GetClipPath().GetIntersection( aPolyPoly, aDest ); - ImplDrawClippedPolyPolygon( aDest ); - } - else - { - if ( maLineStyle.aLineInfo.GetWidth() || ( maLineStyle.aLineInfo.GetStyle() == LINE_DASH ) ) - { - USHORT nCount = rPolygon.GetSize(); - if ( nCount ) - { - if ( rPolygon[ nCount - 1 ] != rPolygon[ 0 ] ) - { - Point aPoint( rPolygon[ 0 ] ); - rPolygon.Insert( nCount, aPoint ); - } - } - ImplSetNonPersistentLineColorTransparenz(); - mpGDIMetaFile->AddAction( new MetaPolygonAction( rPolygon ) ); - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaPolyLineAction( rPolygon, maLineStyle.aLineInfo ) ); - } - else - { - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaPolygonAction( rPolygon ) ); - } - } - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DrawPolyPolygon( PolyPolygon& rPolyPolygon, sal_Bool bRecordPath ) -{ - UpdateClipRegion(); - - ImplMap( rPolyPolygon ); - - if ( bRecordPath ) - aPathObj.AddPolyPolygon( rPolyPolygon ); - else - { - UpdateFillStyle(); - - if ( aClipPath.GetType() == COMPLEX ) - { - PolyPolygon aDest; - aClipPath.GetClipPath().GetIntersection( rPolyPolygon, aDest ); - ImplDrawClippedPolyPolygon( aDest ); - } - else - { - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaPolyPolygonAction( rPolyPolygon ) ); - } - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DrawPolyLine( Polygon& rPolygon, sal_Bool bTo, sal_Bool bRecordPath ) -{ - UpdateClipRegion(); - - ImplMap( rPolygon ); - if ( bTo ) - { - rPolygon[ 0 ] = maActPos; - maActPos = rPolygon[ rPolygon.GetSize() - 1 ]; - } - if ( bRecordPath ) - aPathObj.AddPolyLine( rPolygon ); - else - { - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaPolyLineAction( rPolygon, maLineStyle.aLineInfo ) ); - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DrawPolyBezier( Polygon& rPolygon, sal_Bool bTo, sal_Bool bRecordPath ) -{ - UpdateClipRegion(); - - sal_uInt16 nPoints = rPolygon.GetSize(); - if ( ( nPoints >= 4 ) && ( ( ( nPoints - 4 ) % 3 ) == 0 ) ) - { - ImplMap( rPolygon ); - if ( bTo ) - { - rPolygon[ 0 ] = maActPos; - maActPos = rPolygon[ nPoints - 1 ]; - } - sal_uInt16 i; - for ( i = 0; ( i + 2 ) < nPoints; ) - { - rPolygon.SetFlags( i++, POLY_NORMAL ); - rPolygon.SetFlags( i++, POLY_CONTROL ); - rPolygon.SetFlags( i++, POLY_CONTROL ); - } - if ( bRecordPath ) - aPathObj.AddPolyLine( rPolygon ); - else - { - UpdateLineStyle(); - mpGDIMetaFile->AddAction( new MetaPolyLineAction( rPolygon, maLineStyle.aLineInfo ) ); - } - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::DrawText( Point& rPosition, String& rText, sal_Int32* pDXArry, sal_Bool bRecordPath, sal_Int32 nGfxMode ) -{ - UpdateClipRegion(); - - VirtualDevice* pVDev = NULL; - - rPosition = ImplMap( rPosition ); - - sal_Int32 nOldGfxMode = GetGfxMode(); - SetGfxMode( GM_COMPATIBLE ); - if ( pDXArry ) - { - sal_Int32 i, nSum, nLen = rText.Len(); - - for( i = 0, nSum = 0; i < nLen; i++ ) - { - sal_Int32 nTemp = ImplMap( Size( pDXArry[ i ], 0 ) ).Width(); - nSum += nTemp; - pDXArry[ i ] = nSum; - } - } - if ( mnLatestTextLayoutMode != mnTextLayoutMode ) - { - mnLatestTextLayoutMode = mnTextLayoutMode; - mpGDIMetaFile->AddAction( new MetaLayoutModeAction( mnTextLayoutMode ) ); - } - SetGfxMode( nGfxMode ); - sal_Bool bChangeFont = sal_False; - if ( mnLatestTextAlign != mnTextAlign ) - { - bChangeFont = sal_True; - mnLatestTextAlign = mnTextAlign; - TextAlign eTextAlign; - if ( ( mnTextAlign & TA_BASELINE) == TA_BASELINE ) - eTextAlign = ALIGN_BASELINE; - else if( ( mnTextAlign & TA_BOTTOM) == TA_BOTTOM ) - eTextAlign = ALIGN_BOTTOM; - else - eTextAlign = ALIGN_TOP; - mpGDIMetaFile->AddAction( new MetaTextAlignAction( eTextAlign ) ); - } - if ( maLatestTextColor != maTextColor ) - { - bChangeFont = sal_True; - maLatestTextColor = maTextColor; - mpGDIMetaFile->AddAction( new MetaTextColorAction( maTextColor ) ); - } - sal_Bool bChangeFillColor = sal_False; - if ( maLatestBkColor != maBkColor ) - { - bChangeFillColor = sal_True; - maLatestBkColor = maBkColor; - } - if ( mnLatestBkMode != mnBkMode ) - { - bChangeFillColor = sal_True; - mnLatestBkMode = mnBkMode; - } - if ( bChangeFillColor ) - { - bChangeFont = sal_True; - mpGDIMetaFile->AddAction( new MetaTextFillColorAction( maFont.GetFillColor(), !maFont.IsTransparent() ) ); - } - Font aTmp( maFont ); - aTmp.SetColor( maTextColor ); - aTmp.SetFillColor( maBkColor ); - - if( mnBkMode == TRANSPARENT ) - aTmp.SetTransparent( sal_True ); - else - aTmp.SetTransparent( sal_False ); - - if ( ( mnTextAlign & TA_BASELINE) == TA_BASELINE ) - aTmp.SetAlign( ALIGN_BASELINE ); - else if( ( mnTextAlign & TA_BOTTOM) == TA_BOTTOM ) - aTmp.SetAlign( ALIGN_BOTTOM ); - else - aTmp.SetAlign( ALIGN_TOP ); - - if ( nGfxMode == GM_ADVANCED ) - { - // check whether there is a font rotation applied via transformation - Point aP1( ImplMap( Point() ) ); - Point aP2( ImplMap( Point( 0, 100 ) ) ); - aP2.X() -= aP1.X(); - aP2.Y() -= aP1.Y(); - double fX = aP2.X(); - double fY = aP2.Y(); - if ( fX ) - { - double fOrientation = acos( fX / sqrt( fX * fX + fY * fY ) ) * 57.29577951308; - if ( fY > 0 ) - fOrientation = 360 - fOrientation; - fOrientation += 90; - fOrientation *= 10; - fOrientation += aTmp.GetOrientation(); - aTmp.SetOrientation( sal_Int16( fOrientation ) ); - } - } - - if( mnTextAlign & ( TA_UPDATECP | TA_RIGHT_CENTER ) ) - { - if ( !pVDev ) - pVDev = new VirtualDevice; - sal_Int32 nTextWidth; - pVDev->SetMapMode( MapMode( MAP_100TH_MM ) ); - pVDev->SetFont( maFont ); - if( pDXArry ) - { - UINT32 nLen = rText.Len(); - nTextWidth = pVDev->GetTextWidth( rText.GetChar( (sal_uInt16)( nLen - 1 ) ) ); - if( nLen > 1 ) - nTextWidth += pDXArry[ nLen - 2 ]; - } - else - nTextWidth = pVDev->GetTextWidth( rText ); - - if( mnTextAlign & TA_UPDATECP ) - rPosition = maActPos; - - if ( mnTextAlign & TA_RIGHT_CENTER ) - { - double fLenght = ( ( mnTextAlign & TA_RIGHT_CENTER ) == TA_RIGHT ) ? nTextWidth : nTextWidth >> 1; - rPosition.X() -= (sal_Int32)( fLenght * cos( maFont.GetOrientation() * F_PI1800 ) ); - rPosition.Y() -= (sal_Int32)(-( fLenght * sin( maFont.GetOrientation() * F_PI1800 ) ) ); - } - - if( mnTextAlign & TA_UPDATECP ) - maActPos.X() = rPosition.X() + nTextWidth; - } - if ( bChangeFont || ( maLatestFont != aTmp ) ) - { - maLatestFont = aTmp; - mpGDIMetaFile->AddAction( new MetaFontAction( aTmp ) ); - mpGDIMetaFile->AddAction( new MetaTextAlignAction( aTmp.GetAlign() ) ); - mpGDIMetaFile->AddAction( new MetaTextColorAction( aTmp.GetColor() ) ); - mpGDIMetaFile->AddAction( new MetaTextFillColorAction( aTmp.GetFillColor(), !aTmp.IsTransparent() ) ); - } - if ( bRecordPath ) - { - // ToDo - } - else - { - /* because text without dx array is badly scaled, we - will create such an array if necessary */ - sal_Int32* pDX = pDXArry; - if ( !pDXArry ) - { - pDX = new sal_Int32[ rText.Len() ]; - if ( !pVDev ) - pVDev = new VirtualDevice; - pVDev->SetMapMode( MAP_100TH_MM ); - pVDev->SetFont( maLatestFont ); - pVDev->GetTextArray( rText, pDX, 0, STRING_LEN ); - } - mpGDIMetaFile->AddAction( new MetaTextArrayAction( rPosition, rText, pDX, 0, STRING_LEN ) ); - if ( !pDXArry ) // this means we have created our own array - delete[] pDX; // which must be deleted - } - SetGfxMode( nOldGfxMode ); - delete pVDev; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::ImplDrawBitmap( const Point& rPos, const Size& rSize, const BitmapEx rBitmap ) -{ - BitmapEx aBmpEx( rBitmap ); - if ( aClipPath.GetType() == COMPLEX ) - { - VirtualDevice aVDev; - MapMode aMapMode( MAP_100TH_MM ); - aMapMode.SetOrigin( Point( -rPos.X(), -rPos.Y() ) ); - const Size aOutputSizePixel( aVDev.LogicToPixel( rSize, aMapMode ) ); - const Size aSizePixel( rBitmap.GetSizePixel() ); - if ( aOutputSizePixel.Width() && aOutputSizePixel.Height() ) - { - aMapMode.SetScaleX( Fraction( aSizePixel.Width(), aOutputSizePixel.Width() ) ); - aMapMode.SetScaleY( Fraction( aSizePixel.Height(), aOutputSizePixel.Height() ) ); - } - aVDev.SetMapMode( aMapMode ); - aVDev.SetOutputSizePixel( aSizePixel ); - aVDev.SetFillColor( Color( COL_BLACK ) ); - const PolyPolygon aClip( aClipPath.GetClipPath() ); - aVDev.DrawPolyPolygon( aClip ); - const Point aEmptyPoint; - - // #i50672# Extract whole VDev content (to match size of rBitmap) - aVDev.EnableMapMode( FALSE ); - Bitmap aMask( aVDev.GetBitmap( aEmptyPoint, aSizePixel ).CreateMask( Color( COL_WHITE ) ) ); - - if ( aBmpEx.IsTransparent() ) - { - if ( rBitmap.GetTransparentColor() == Color( COL_WHITE ) ) - aMask.CombineSimple( rBitmap.GetMask(), BMP_COMBINE_OR ); - else - aMask.CombineSimple( rBitmap.GetMask(), BMP_COMBINE_AND ); - aBmpEx = BitmapEx( rBitmap.GetBitmap(), aMask ); - } - else - aBmpEx = BitmapEx( rBitmap.GetBitmap(), aMask ); - } - if ( aBmpEx.IsTransparent() ) - mpGDIMetaFile->AddAction( new MetaBmpExScaleAction( rPos, rSize, aBmpEx ) ); - else - mpGDIMetaFile->AddAction( new MetaBmpScaleAction( rPos, rSize, aBmpEx.GetBitmap() ) ); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::ResolveBitmapActions( List& rSaveList ) -{ - UpdateClipRegion(); - - sal_uInt32 nObjects = rSaveList.Count(); - sal_uInt32 nObjectsLeft = nObjects; - - while ( nObjectsLeft ) - { - sal_uInt32 i, nObjectsOfSameSize = 0; - sal_uInt32 nObjectStartIndex = nObjects - nObjectsLeft; - - BSaveStruct* pSave = (BSaveStruct*)rSaveList.GetObject( nObjectStartIndex ); - Rectangle aRect( pSave->aOutRect ); - - for ( i = nObjectStartIndex; i < nObjects; ) - { - nObjectsOfSameSize++; - if ( ++i < nObjects ) - { - pSave = (BSaveStruct*)rSaveList.GetObject( i ); - if ( pSave->aOutRect != aRect ) - break; - } - } - Point aPos( ImplMap( aRect.TopLeft() ) ); - Size aSize( ImplMap( aRect.GetSize() ) ); - - for ( i = nObjectStartIndex; i < ( nObjectStartIndex + nObjectsOfSameSize ); i++ ) - { - pSave = (BSaveStruct*)rSaveList.GetObject( i ); - - sal_uInt32 nWinRop = pSave->nWinRop; - sal_uInt8 nRasterOperation = (sal_uInt8)( nWinRop >> 16 ); - - sal_uInt32 nUsed = 0; - if ( ( nRasterOperation & 0xf ) != ( nRasterOperation >> 4 ) ) - nUsed |= 1; // pattern is used - if ( ( nRasterOperation & 0x33 ) != ( ( nRasterOperation & 0xcc ) >> 2 ) ) - nUsed |= 2; // source is used - if ( ( nRasterOperation & 0xaa ) != ( ( nRasterOperation & 0x55 ) << 1 ) ) - nUsed |= 4; // destination is used - - if ( (nUsed & 1) && (( nUsed & 2 ) == 0) ) - { // patterns aren't well supported yet - sal_uInt32 nOldRop = SetRasterOp( ROP_OVERPAINT ); // in this case nRasterOperation is either 0 or 0xff - UpdateFillStyle(); - DrawRect( aRect, FALSE ); - SetRasterOp( nOldRop ); - } - else - { - sal_Bool bDrawn = sal_False; - - if ( i == nObjectStartIndex ) // optimizing, sometimes it is possible to create just one transparent bitmap - { - if ( nObjectsOfSameSize == 2 ) - { - BSaveStruct* pSave2 = (BSaveStruct*)rSaveList.GetObject( i + 1 ); - if ( ( pSave->aBmp.GetPrefSize() == pSave2->aBmp.GetPrefSize() ) && - ( pSave->aBmp.GetPrefMapMode() == pSave2->aBmp.GetPrefMapMode() ) ) - { - // TODO: Strictly speaking, we should - // check whether mask is monochrome, and - // whether image is black (upper branch) - // or white (lower branch). Otherwise, the - // effect is not the same as a masked - // bitmap. - if ( ( nWinRop == SRCPAINT ) && ( pSave2->nWinRop == SRCAND ) ) - { - Bitmap aMask( pSave->aBmp ); aMask.Invert(); - BitmapEx aBmpEx( pSave2->aBmp, aMask ); - ImplDrawBitmap( aPos, aSize, aBmpEx ); - bDrawn = sal_True; - i++; - } - // #i20085# This is just the other way - // around as above. Only difference: mask - // is inverted - else if ( ( nWinRop == SRCAND ) && ( pSave2->nWinRop == SRCPAINT ) ) - { - Bitmap aMask( pSave->aBmp ); - BitmapEx aBmpEx( pSave2->aBmp, aMask ); - ImplDrawBitmap( aPos, aSize, aBmpEx ); - bDrawn = sal_True; - i++; - } - } - } - } - - if ( !bDrawn ) - { - Push(); - sal_uInt32 nOldRop = SetRasterOp( R2_COPYPEN ); - Bitmap aBitmap( pSave->aBmp ); - sal_uInt32 nOperation = ( nRasterOperation & 0xf ); - switch( nOperation ) - { - case 0x1 : - case 0xe : - { - SetRasterOp( R2_XORPEN ); - ImplDrawBitmap( aPos, aSize, aBitmap ); - SetRasterOp( R2_COPYPEN ); - Bitmap aMask( aBitmap ); - aMask.Invert(); - BitmapEx aBmpEx( aBitmap, aMask ); - ImplDrawBitmap( aPos, aSize, aBmpEx ); - if ( nOperation == 0x1 ) - { - SetRasterOp( R2_NOT ); - DrawRect( aRect, FALSE ); - } - } - break; - case 0x7 : - case 0x8 : - { - Bitmap aMask( aBitmap ); - if ( ( nUsed & 1 ) && ( nRasterOperation & 0xb0 ) == 0xb0 ) // pattern used - { - aBitmap.Convert( BMP_CONVERSION_24BIT ); - aBitmap.Erase( maFillStyle.aFillColor ); - } - BitmapEx aBmpEx( aBitmap, aMask ); - ImplDrawBitmap( aPos, aSize, aBmpEx ); - if ( nOperation == 0x7 ) - { - SetRasterOp( R2_NOT ); - DrawRect( aRect, FALSE ); - } - } - break; - - case 0x4 : - case 0xb : - { - SetRasterOp( R2_NOT ); - DrawRect( aRect, FALSE ); - SetRasterOp( R2_COPYPEN ); - Bitmap aMask( aBitmap ); - aBitmap.Invert(); - BitmapEx aBmpEx( aBitmap, aMask ); - ImplDrawBitmap( aPos, aSize, aBmpEx ); - SetRasterOp( R2_XORPEN ); - ImplDrawBitmap( aPos, aSize, aBitmap ); - if ( nOperation == 0xb ) - { - SetRasterOp( R2_NOT ); - DrawRect( aRect, FALSE ); - } - } - break; - - case 0x2 : - case 0xd : - { - Bitmap aMask( aBitmap ); - aMask.Invert(); - BitmapEx aBmpEx( aBitmap, aMask ); - ImplDrawBitmap( aPos, aSize, aBmpEx ); - SetRasterOp( R2_XORPEN ); - ImplDrawBitmap( aPos, aSize, aBitmap ); - if ( nOperation == 0xd ) - { - SetRasterOp( R2_NOT ); - DrawRect( aRect, FALSE ); - } - } - break; - case 0x6 : - case 0x9 : - { - SetRasterOp( R2_XORPEN ); - ImplDrawBitmap( aPos, aSize, aBitmap ); - if ( nOperation == 0x9 ) - { - SetRasterOp( R2_NOT ); - DrawRect( aRect, FALSE ); - } - } - break; - - case 0x0 : // WHITENESS - case 0xf : // BLACKNESS - { // in this case nRasterOperation is either 0 or 0xff - maFillStyle = WinMtfFillStyle( Color( nRasterOperation, nRasterOperation, nRasterOperation ) ); - UpdateFillStyle(); - DrawRect( aRect, FALSE ); - } - break; - - case 0x3 : // only source is used - case 0xc : - { - if ( nRasterOperation == 0x33 ) - aBitmap.Invert(); - ImplDrawBitmap( aPos, aSize, aBitmap ); - } - break; - - case 0x5 : // only destination is used - { - SetRasterOp( R2_NOT ); - DrawRect( aRect, FALSE ); - } - case 0xa : // no operation - break; - } - SetRasterOp( nOldRop ); - Pop(); - } - } - } - nObjectsLeft -= nObjectsOfSameSize; - } - - void* pPtr; - for ( pPtr = rSaveList.First(); pPtr; pPtr = rSaveList.Next() ) - delete (BSaveStruct*)pPtr; - rSaveList.Clear(); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetDevOrg( const Point& rPoint ) -{ - mnDevOrgX = rPoint.X(); - mnDevOrgY = rPoint.Y(); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetDevOrgOffset( INT32 nXAdd, INT32 nYAdd ) -{ - mnDevOrgX += nXAdd; - mnDevOrgY += nYAdd; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetDevExt( const Size& rSize ) -{ - if ( rSize.Width() && rSize.Height() ) - { - switch( mnMapMode ) - { - case MM_ISOTROPIC : - case MM_ANISOTROPIC : - { - mnDevWidth = rSize.Width(); - mnDevHeight = rSize.Height(); - } - } - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::ScaleDevExt( double fX, double fY ) -{ - mnDevWidth = FRound( mnDevWidth * fX ); - mnDevHeight = FRound( mnDevHeight * fY ); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetWinOrg( const Point& rPoint ) -{ - mnWinOrgX = rPoint.X(); - mnWinOrgY = rPoint.Y(); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetWinOrgOffset( INT32 nXAdd, INT32 nYAdd ) -{ - mnWinOrgX += nXAdd; - mnWinOrgY += nYAdd; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetWinExt( const Size& rSize ) -{ - - if( rSize.Width() && rSize.Height() ) - { - switch( mnMapMode ) - { - case MM_ISOTROPIC : - case MM_ANISOTROPIC : - { - mnWinExtX = rSize.Width(); - mnWinExtY = rSize.Height(); - } - } - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::ScaleWinExt( double fX, double fY ) -{ - mnWinExtX = FRound( mnWinExtX * fX ); - mnWinExtY = FRound( mnWinExtY * fY ); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetrclBounds( const Rectangle& rRect ) -{ - mrclBounds = rRect; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetrclFrame( const Rectangle& rRect ) -{ - mrclFrame = rRect; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetRefPix( const Size& rSize ) -{ - mnPixX = rSize.Width(); - mnPixY = rSize.Height(); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetRefMill( const Size& rSize ) -{ - mnMillX = rSize.Width(); - mnMillY = rSize.Height(); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetMapMode( sal_uInt32 nMapMode ) -{ - mnMapMode = nMapMode; - if ( nMapMode == MM_TEXT ) - { - mnWinExtX = mnDevWidth; - mnWinExtY = mnDevHeight; - } - else if ( mnMapMode == MM_HIMETRIC ) - { - mnWinExtX = mnMillX * 100; - mnWinExtY = mnMillY * 100; - } -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::SetWorldTransform( const XForm& rXForm ) -{ - maXForm.eM11 = rXForm.eM11; - maXForm.eM12 = rXForm.eM12; - maXForm.eM21 = rXForm.eM21; - maXForm.eM22 = rXForm.eM22; - maXForm.eDx = rXForm.eDx; - maXForm.eDy = rXForm.eDy; -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::ModifyWorldTransform( const XForm& rXForm, UINT32 nMode ) -{ - switch( nMode ) - { - case MWT_IDENTITY : - { - maXForm.eM11 = maXForm.eM12 = maXForm.eM21 = maXForm.eM22 = 1.0f; - maXForm.eDx = maXForm.eDy = 0.0f; - } - break; - - case MWT_RIGHTMULTIPLY : - case MWT_LEFTMULTIPLY : - { - const XForm* pLeft; - const XForm* pRight; - - if ( nMode == MWT_LEFTMULTIPLY ) - { - pLeft = &rXForm; - pRight = &maXForm; - } - else - { - pLeft = &maXForm; - pRight = &rXForm; - } - - float aF[3][3]; - float bF[3][3]; - float cF[3][3]; - - aF[0][0] = pLeft->eM11; - aF[0][1] = pLeft->eM12; - aF[0][2] = 0; - aF[1][0] = pLeft->eM21; - aF[1][1] = pLeft->eM22; - aF[1][2] = 0; - aF[2][0] = pLeft->eDx; - aF[2][1] = pLeft->eDy; - aF[2][2] = 1; - - bF[0][0] = pRight->eM11; - bF[0][1] = pRight->eM12; - bF[0][2] = 0; - bF[1][0] = pRight->eM21; - bF[1][1] = pRight->eM22; - bF[1][2] = 0; - bF[2][0] = pRight->eDx; - bF[2][1] = pRight->eDy; - bF[2][2] = 1; - - int i, j, k; - for ( i = 0; i < 3; i++ ) - { - for ( j = 0; j < 3; j++ ) - { - cF[i][j] = 0; - for ( k = 0; k < 3; k++ ) - cF[i][j] += aF[i][k] * bF[k][j]; - } - } - maXForm.eM11 = cF[0][0]; - maXForm.eM12 = cF[0][1]; - maXForm.eM21 = cF[1][0]; - maXForm.eM22 = cF[1][1]; - maXForm.eDx = cF[2][0]; - maXForm.eDy = cF[2][1]; - } - break; - } - } - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::Push() // !! to be able to access the original ClipRegion it -{ // is not allowed to use the MetaPushAction() - UpdateClipRegion(); // (the original clip region is on top of the stack) (SJ) - SaveStructPtr pSave( new SaveStruct ); - - pSave->aLineStyle = maLineStyle; - pSave->aFillStyle = maFillStyle; - - pSave->aFont = maFont; - pSave->aTextColor = maTextColor; - pSave->nTextAlign = mnTextAlign; - pSave->nTextLayoutMode = mnTextLayoutMode; - pSave->nMapMode = mnMapMode; - pSave->nGfxMode = mnGfxMode; - pSave->nBkMode = mnBkMode; - pSave->aBkColor = maBkColor; - pSave->bFillStyleSelected = mbFillStyleSelected; - - pSave->aActPos = maActPos; - pSave->aXForm = maXForm; - pSave->eRasterOp = meRasterOp; - - pSave->nWinOrgX = mnWinOrgX; - pSave->nWinOrgY = mnWinOrgY; - pSave->nWinExtX = mnWinExtX; - pSave->nWinExtY = mnWinExtY; - pSave->nDevOrgX = mnDevOrgX; - pSave->nDevOrgY = mnDevOrgY; - pSave->nDevWidth = mnDevWidth; - pSave->nDevHeight = mnDevHeight; - - pSave->aPathObj = aPathObj; - pSave->aClipPath = aClipPath; - - vSaveStack.push_back( pSave ); -} - -//----------------------------------------------------------------------------------- - -void WinMtfOutput::Pop() -{ - // Die aktuellen Daten vom Stack holen - if( vSaveStack.size() ) - { - // Die aktuelle Daten auf dem Stack sichern - SaveStructPtr pSave( vSaveStack.back() ); - - maLineStyle = pSave->aLineStyle; - maFillStyle = pSave->aFillStyle; - - maFont = pSave->aFont; - maTextColor = pSave->aTextColor; - mnTextAlign = pSave->nTextAlign; - mnTextLayoutMode = pSave->nTextLayoutMode; - mnBkMode = pSave->nBkMode; - mnGfxMode = pSave->nGfxMode; - mnMapMode = pSave->nMapMode; - maBkColor = pSave->aBkColor; - mbFillStyleSelected = pSave->bFillStyleSelected; - - maActPos = pSave->aActPos; - maXForm = pSave->aXForm; - meRasterOp = pSave->eRasterOp; - - mnWinOrgX = pSave->nWinOrgX; - mnWinOrgY = pSave->nWinOrgY; - mnWinExtX = pSave->nWinExtX; - mnWinExtY = pSave->nWinExtY; - mnDevOrgX = pSave->nDevOrgX; - mnDevOrgY = pSave->nDevOrgY; - mnDevWidth = pSave->nDevWidth; - mnDevHeight = pSave->nDevHeight; - - aPathObj = pSave->aPathObj; - if ( ! ( aClipPath == pSave->aClipPath ) ) - { - aClipPath = pSave->aClipPath; - aClipPath.bNeedsUpdate = sal_True; - } - if ( meLatestRasterOp != meRasterOp ) - mpGDIMetaFile->AddAction( new MetaRasterOpAction( meRasterOp ) ); - vSaveStack.pop_back(); - } -} - -void WinMtfOutput::AddFromGDIMetaFile( GDIMetaFile& rGDIMetaFile ) -{ - rGDIMetaFile.Play( *mpGDIMetaFile, 0xFFFFFFFF ); -} - diff --git a/svtools/source/filter.vcl/wmf/winmtf.hxx b/svtools/source/filter.vcl/wmf/winmtf.hxx deleted file mode 100644 index fb4fd2fe0c57..000000000000 --- a/svtools/source/filter.vcl/wmf/winmtf.hxx +++ /dev/null @@ -1,777 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _WINMTF_HXX -#define _WINMTF_HXX - -#ifdef DBG_UTIL -#define WIN_MTF_ASSERT -#endif - -#include -#ifndef BOOST_SHARED_PTR_HPP_INCLUDED -#include -#endif -#ifndef _TOOL_DEBUG_HXX -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#define ERROR 0 -#define NULLREGION 1 -#define SIMPLEREGION 2 -#define COMPLEXREGION 3 - -#define RGN_AND 1 -#define RGN_OR 2 -#define RGN_XOR 3 -#define RGN_DIFF 4 -#define RGN_COPY 5 - -#define TRANSPARENT 1 -#define OPAQUE 2 -#define BKMODE_LAST 2 - -/* xform stuff */ -#define MWT_IDENTITY 1 -#define MWT_LEFTMULTIPLY 2 -#define MWT_RIGHTMULTIPLY 3 - -#define ENHMETA_STOCK_OBJECT 0x80000000 - -/* Stock Logical Objects */ -#define WHITE_BRUSH 0 -#define LTGRAY_BRUSH 1 -#define GRAY_BRUSH 2 -#define DKGRAY_BRUSH 3 -#define BLACK_BRUSH 4 -#define NULL_BRUSH 5 -#define HOLLOW_BRUSH NULL_BRUSH -#define WHITE_PEN 6 -#define BLACK_PEN 7 -#define NULL_PEN 8 -#define OEM_FIXED_FONT 10 -#define ANSI_FIXED_FONT 11 -#define ANSI_VAR_FONT 12 -#define SYSTEM_FONT 13 -#define DEVICE_DEFAULT_FONT 14 -#define DEFAULT_PALETTE 15 -#define SYSTEM_FIXED_FONT 16 - - -#define R2_BLACK 1 -#define R2_NOTMERGEPEN 2 -#define R2_MASKNOTPEN 3 -#define R2_NOTCOPYPEN 4 -#define R2_MASKPENNOT 5 -#define R2_NOT 6 -#define R2_XORPEN 7 -#define R2_NOTMASKPEN 8 -#define R2_MASKPEN 9 -#define R2_NOTXORPEN 10 -#define R2_NOP 11 -#define R2_MERGENOTPEN 12 -#define R2_COPYPEN 13 -#define R2_MERGEPENNOT 14 -#define R2_MERGEPEN 15 -#define R2_WHITE 16 - -/* Mapping Modes */ -#define MM_TEXT 1 -#define MM_LOMETRIC 2 -#define MM_HIMETRIC 3 -#define MM_LOENGLISH 4 -#define MM_HIENGLISH 5 -#define MM_TWIPS 6 -#define MM_ISOTROPIC 7 -#define MM_ANISOTROPIC 8 - - -/* Graphics Modes */ -#define GM_COMPATIBLE 1 -#define GM_ADVANCED 2 -#define GM_LAST 2 - -/* StretchBlt() Modes */ -#define BLACKONWHITE 1 -#define WHITEONBLACK 2 -#define COLORONCOLOR 3 -#define HALFTONE 4 -#define MAXSTRETCHBLTMODE 4 -#define STRETCH_ANDSCANS BLACKONWHITE -#define STRETCH_ORSCANS WHITEONBLACK -#define STRETCH_DELETESCANS COLORONCOLOR -#define STRETCH_HALFTONE HALFTONE - -#define LF_FACESIZE 32 - -struct LOGFONTW -{ - INT32 lfHeight; - INT32 lfWidth; - INT32 lfEscapement; - INT32 lfOrientation; - INT32 lfWeight; - BYTE lfItalic; - BYTE lfUnderline; - BYTE lfStrikeOut; - BYTE lfCharSet; - BYTE lfOutPrecision; - BYTE lfClipPrecision; - BYTE lfQuality; - BYTE lfPitchAndFamily; - String alfFaceName; -}; - -#define TA_NOUPDATECP 0x0000 -#define TA_UPDATECP 0x0001 -#define TA_LEFT 0x0000 -#define TA_RIGHT 0x0002 -#define TA_CENTER 0x0006 -#define TA_RIGHT_CENTER (TA_RIGHT | TA_CENTER) -#define TA_TOP 0x0000 -#define TA_BOTTOM 0x0008 -#define TA_BASELINE 0x0018 - -#define SRCCOPY 0x00CC0020L -#define SRCPAINT 0x00EE0086L -#define SRCAND 0x008800C6L -#define SRCINVERT 0x00660046L -#define SRCERASE 0x00440328L -#define NOTSRCCOPY 0x00330008L -#define NOTSRCERASE 0x001100A6L -#define MERGECOPY 0x00C000CAL -#define MERGEPAINT 0x00BB0226L -#define PATCOPY 0x00F00021L -#define PATPAINT 0x00FB0A09L -#define PATINVERT 0x005A0049L -#define DSTINVERT 0x00550009L -#define BLACKNESS 0x00000042L -#define WHITENESS 0x00FF0062L - -#define PS_SOLID 0 -#define PS_DASH 1 -#define PS_DOT 2 -#define PS_DASHDOT 3 -#define PS_DASHDOTDOT 4 -#define PS_NULL 5 -#define PS_INSIDEFRAME 6 -#define PS_USERSTYLE 7 -#define PS_ALTERNATE 8 -#define PS_STYLE_MASK 15 - -#define PS_ENDCAP_ROUND 0x000 -#define PS_ENDCAP_SQUARE 0x100 -#define PS_ENDCAP_FLAT 0x200 -#define PS_ENDCAP_MASK 0xF00 - -#define PS_JOIN_ROUND 0x0000 -#define PS_JOIN_BEVEL 0x1000 -#define PS_JOIN_MITER 0x2000 -#define PS_JOIN_MASK 0xF000 - -#define PS_COSMETIC 0x00000 -#define PS_GEOMETRIC 0x10000 -#define PS_TYPE_MASK 0xF0000 - -#define ANSI_CHARSET 0 -#define DEFAULT_CHARSET 1 -#define SYMBOL_CHARSET 2 -#define SHIFTJIS_CHARSET 128 -#define HANGEUL_CHARSET 129 -#define GB2312_CHARSET 134 -#define CHINESEBIG5_CHARSET 136 -#define OEM_CHARSET 255 -/*WINVER >= 0x0400*/ -#define JOHAB_CHARSET 130 -#define HEBREW_CHARSET 177 -#define ARABIC_CHARSET 178 -#define GREEK_CHARSET 161 -#define TURKISH_CHARSET 162 -#define VIETNAMESE_CHARSET 163 -#define THAI_CHARSET 222 -#define EASTEUROPE_CHARSET 238 -#define RUSSIAN_CHARSET 204 -#define MAC_CHARSET 77 -#define BALTIC_CHARSET 186 - -#define ETO_OPAQUE 0x0002 -#define ETO_CLIPPED 0x0004 -/*WINVER >= 0x0400*/ -#define ETO_GLYPH_INDEX 0x0010 -#define ETO_RTLREADING 0x0080 -#define ETO_NUMERICSLOCAL 0x0400 -#define ETO_NUMERICSLATIN 0x0800 -#define ETO_IGNORELANGUAGE 0x1000 -/*_WIN32_WINNT >= 0x0500*/ -#define ETO_PDY 0x2000 - - -#define DEFAULT_PITCH 0x00 -#define FIXED_PITCH 0x01 -#define VARIABLE_PITCH 0x02 - -/* Font Families */ -#define FF_DONTCARE 0x00 -#define FF_ROMAN 0x10 -#define FF_SWISS 0x20 -#define FF_MODERN 0x30 -#define FF_SCRIPT 0x40 -#define FF_DECORATIVE 0x50 - -#define FW_DONTCARE 0 -#define FW_THIN 100 -#define FW_EXTRALIGHT 200 -#define FW_LIGHT 300 -#define FW_NORMAL 400 -#define FW_MEDIUM 500 -#define FW_SEMIBOLD 600 -#define FW_BOLD 700 -#define FW_EXTRABOLD 800 -#define FW_HEAVY 900 -#define FW_ULTRALIGHT 200 -#define FW_REGULAR 400 -#define FW_DEMIBOLD 600 -#define FW_ULTRABOLD 800 -#define FW_BLACK 900 - -#define BS_SOLID 0 -#define BS_NULL 1 -#define BS_HOLLOW 1 -#define BS_HATCHED 2 -#define BS_PATTERN 3 -#define BS_INDEXED 4 -#define BS_DIBPATTERN 5 -#define BS_DIBPATTERNPT 6 -#define BS_PATTERN8X8 7 -#define BS_DIBPATTERN8X8 8 -#define BS_MONOPATTERN 9 - -#define W_HS_HORIZONTAL 0 -#define W_HS_VERTICAL 1 -#define W_HS_FDIAGONAL 2 -#define W_HS_BDIAGONAL 3 -#define W_HS_CROSS 4 -#define W_HS_DIAGCROSS 5 - -#define RDH_RECTANGLES 1 - -#define W_MFCOMMENT 15 - -#define PRIVATE_ESCAPE_UNICODE 2 - -//============================ WMFReader ================================== - - -#ifdef WIN_MTF_ASSERT -#define WIN_MTF_ASSERT_INIT 0x80000000 -#define WIN_MTF_ASSERT_ONCE 0x40000000 -#define WIN_MTF_ASSERT_MIFE 0x20000000 - -void WinMtfAssertHandler( const sal_Char*, sal_uInt32 nFlags = WIN_MTF_ASSERT_MIFE ); -#endif - -enum WinMtfClipPathType{ EMPTY, RECTANGLE, COMPLEX }; - -class WinMtfClipPath -{ - PolyPolygon aPolyPoly; - WinMtfClipPathType eType; - sal_Int32 nDepth; - - void ImpUpdateType(); - - public : - - sal_Bool bNeedsUpdate; - - WinMtfClipPath(): eType(EMPTY), nDepth( 0 ), bNeedsUpdate( sal_False ){}; - - void SetClipPath( const PolyPolygon& rPolyPolygon, sal_Int32 nClippingMode ); - void IntersectClipRect( const Rectangle& rRect ); - void ExcludeClipRect( const Rectangle& rRect ); - void MoveClipRegion( const Size& rSize ); - - WinMtfClipPathType GetType() const { return eType; }; - const PolyPolygon& GetClipPath() const { return aPolyPoly; }; - - sal_Bool operator==( const WinMtfClipPath& rPath ) - { - return ( rPath.eType == eType ) && - ( rPath.aPolyPoly == aPolyPoly ); - }; -}; - -class WinMtfPathObj : public PolyPolygon -{ - sal_Bool bClosed; - - public : - - WinMtfPathObj() { bClosed = sal_True; } - void Init() { Clear(); bClosed = sal_True; }; - void ClosePath(); - - void AddPoint( const Point& rPoint ); - void AddPolygon( const Polygon& rPoly ); - void AddPolyLine( const Polygon& rPoly ); - void AddPolyPolygon( const PolyPolygon& rPolyPolygon ); -}; - -struct WinMtfFontStyle -{ - Font aFont; - - WinMtfFontStyle( LOGFONTW& rLogFont ); -}; - -// ----------------------------------------------------------------------------- - -struct WinMtfFillStyle -{ - Color aFillColor; - BOOL bTransparent; - - WinMtfFillStyle() : - aFillColor ( Color( COL_BLACK ) ), - bTransparent( FALSE ) - { - }; - - WinMtfFillStyle( const Color& rColor, BOOL bTrans = FALSE ) : - aFillColor ( rColor ), - bTransparent( bTrans ) - { - }; - - BOOL operator==( const WinMtfFillStyle& rStyle ) - { return ( ( aFillColor == rStyle.aFillColor ) && ( bTransparent == rStyle.bTransparent ) ); }; - BOOL operator==( WinMtfFillStyle* pStyle ) - { return ( ( aFillColor == pStyle->aFillColor ) && ( bTransparent == pStyle->bTransparent ) ); }; - void operator=( const WinMtfFillStyle& rStyle ) { aFillColor = rStyle.aFillColor; bTransparent = rStyle.bTransparent; }; - void operator=( WinMtfFillStyle* pStyle ) { aFillColor = pStyle->aFillColor; bTransparent = pStyle->bTransparent; }; -}; - -// ----------------------------------------------------------------------------- - -struct WinMtfLineStyle -{ - Color aLineColor; - LineInfo aLineInfo; - BOOL bTransparent; - - WinMtfLineStyle() : - aLineColor ( COL_BLACK ), - bTransparent( FALSE ) {}; - - WinMtfLineStyle( const Color& rColor, BOOL bTrans = FALSE ) : - aLineColor ( rColor ), - bTransparent( bTrans ) {}; - - WinMtfLineStyle( const Color& rColor, const LineInfo rStyle, BOOL bTrans = FALSE ) : - aLineColor ( rColor ), - aLineInfo ( rStyle ), - bTransparent( bTrans ) {}; - - BOOL operator==( const WinMtfLineStyle& rStyle ) { return ( ( aLineColor == rStyle.aLineColor ) && ( bTransparent == rStyle.bTransparent ) && ( aLineInfo == rStyle.aLineInfo ) ); }; - BOOL operator==( WinMtfLineStyle* pStyle ) { return ( ( aLineColor == pStyle->aLineColor ) && ( bTransparent == pStyle->bTransparent ) && ( aLineInfo == pStyle->aLineInfo ) ); }; - void operator=( const WinMtfLineStyle& rStyle ) - { - aLineColor = rStyle.aLineColor; - bTransparent = rStyle.bTransparent; - aLineInfo = rStyle.aLineInfo; - }; - - void operator=( WinMtfLineStyle* pStyle ) - { - aLineColor = pStyle->aLineColor; - bTransparent = pStyle->bTransparent; - aLineInfo = pStyle->aLineInfo; - }; -}; - -// ----------------------------------------------------------------------------- - -struct XForm -{ - float eM11; - float eM12; - float eM21; - float eM22; - float eDx; - float eDy; - XForm() - { - eM11 = eM22 = 1.0f; - eDx = eDy = eM12 = eM21 = 0.0f; - }; - - friend SvStream& operator>>( SvStream& rIn, XForm& rXForm ); -}; - -// ----------------------------------------------------------------------------- - -struct SaveStruct -{ - sal_uInt32 nBkMode, nMapMode, nGfxMode, nTextLayoutMode; - sal_Int32 nWinOrgX, nWinOrgY, nWinExtX, nWinExtY; - sal_Int32 nDevOrgX, nDevOrgY, nDevWidth, nDevHeight; - - WinMtfLineStyle aLineStyle; - WinMtfFillStyle aFillStyle; - - Font aFont; - Color aBkColor; - Color aTextColor; - sal_uInt32 nTextAlign; - RasterOp eRasterOp; - - Point aActPos; - WinMtfPathObj aPathObj; - WinMtfClipPath aClipPath; - XForm aXForm; - - sal_Bool bRecordPath; - sal_Bool bFillStyleSelected; -}; - -typedef ::boost::shared_ptr< SaveStruct > SaveStructPtr; - -// ----------------------------------------------------------------------------- - -struct BSaveStruct -{ - Bitmap aBmp; - Rectangle aOutRect; - UINT32 nWinRop; - - BSaveStruct( const Bitmap& rBmp, const Rectangle& rOutRect, UINT32 nRop ) : - aBmp( rBmp ), aOutRect( rOutRect ), nWinRop( nRop ){}; -}; - -// ----------------------------------------------------------------------------- - -enum GDIObjectType { GDI_DUMMY = 0, GDI_PEN = 1, GDI_BRUSH = 2, GDI_FONT = 3, GDI_PALETTE = 4, GDI_BITMAP = 5, GDI_REGION = 6 }; - -struct GDIObj -{ - void* pStyle; - GDIObjectType eType; - - GDIObj() : - pStyle ( NULL ), - eType ( GDI_DUMMY ) - { - }; - - GDIObj( GDIObjectType eT, void* pS ) { pStyle = pS; eType = eT; }; - void Set( GDIObjectType eT, void* pS ) { pStyle = pS; eType = eT; }; - void Delete() - { - if ( pStyle ) - { - switch ( eType ) - { - case GDI_PEN : - delete (WinMtfLineStyle*)pStyle; - break; - case GDI_BRUSH : - delete (WinMtfFillStyle*)pStyle; - break; - case GDI_FONT : - delete (WinMtfFontStyle*)pStyle; - break; - - default: - DBG_ERROR( "unsupported style deleted" ); - break; - } - pStyle = NULL; - } - }; - - ~GDIObj() - { - Delete(); - } -}; - -// ----------------------------------------------------------------------------- - -class WinMtfOutput -{ - - WinMtfPathObj aPathObj; - WinMtfClipPath aClipPath; - - WinMtfLineStyle maLatestLineStyle; - WinMtfLineStyle maLineStyle; - WinMtfFillStyle maLatestFillStyle; - WinMtfFillStyle maFillStyle; - Font maLatestFont; - Font maFont; - sal_uInt32 mnLatestTextAlign; - sal_uInt32 mnTextAlign; - Color maLatestTextColor; - Color maTextColor; - Color maLatestBkColor; - Color maBkColor; - sal_uInt32 mnLatestTextLayoutMode; - sal_uInt32 mnTextLayoutMode; - sal_uInt32 mnLatestBkMode; - sal_uInt32 mnBkMode; - RasterOp meLatestRasterOp; - RasterOp meRasterOp; - - std::vector< GDIObj* > vGDIObj; - - Point maActPos; - - sal_uInt32 mnRop; - sal_Bool mbNopMode; - sal_Bool mbFillStyleSelected; - - std::vector< SaveStructPtr > vSaveStack; - - sal_uInt32 mnGfxMode; - sal_uInt32 mnMapMode; - XForm maXForm; - sal_Int32 mnDevOrgX, mnDevOrgY; - sal_Int32 mnDevWidth, mnDevHeight; - sal_Int32 mnWinOrgX, mnWinOrgY; // aktuelles Window-Origin - sal_Int32 mnWinExtX, mnWinExtY; // aktuelles Window-Extent - - sal_Int32 mnPixX, mnPixY; // Reference Device in pixel - sal_Int32 mnMillX, mnMillY; // Reference Device in Mill - Rectangle mrclFrame; // rectangle in logical units 1/100th mm - Rectangle mrclBounds; - - GDIMetaFile* mpGDIMetaFile; - - void UpdateLineStyle(); - void UpdateFillStyle(); - - Point ImplMap( const Point& rPt ); - Size ImplMap( const Size& rSz ); - Rectangle ImplMap( const Rectangle& rRectangle ); - void ImplMap( Font& rFont ); - Polygon& ImplMap( Polygon& rPolygon ); - PolyPolygon& ImplMap( PolyPolygon& rPolyPolygon ); - void ImplResizeObjectArry( UINT32 nNewEntry ); - void ImplSetNonPersistentLineColorTransparenz(); - void ImplDrawClippedPolyPolygon( const PolyPolygon& rPolyPoly ); - void ImplDrawBitmap( const Point& rPos, const Size& rSize, const BitmapEx rBitmap ); - - public: - - void SetDevOrg( const Point& rPoint ); - void SetDevOrgOffset( INT32 nXAdd, INT32 nYAdd ); - void SetDevExt( const Size& rSize ); - void ScaleDevExt( double fX, double fY ); - - void SetWinOrg( const Point& rPoint ); - void SetWinOrgOffset( INT32 nX, INT32 nY ); - void SetWinExt( const Size& rSize ); - void ScaleWinExt( double fX, double fY ); - - void SetrclBounds( const Rectangle& rRect ); - void SetrclFrame( const Rectangle& rRect ); - void SetRefPix( const Size& rSize ); - void SetRefMill( const Size& rSize ); - - sal_uInt32 GetMapMode() const { return mnMapMode; }; - void SetMapMode( sal_uInt32 mnMapMode ); - void SetWorldTransform( const XForm& rXForm ); - void ModifyWorldTransform( const XForm& rXForm, UINT32 nMode ); - - void Push(); - void Pop(); - - UINT32 SetRasterOp( UINT32 nRasterOp ); - void StrokeAndFillPath( sal_Bool bStroke, sal_Bool bFill ); - - void SetGfxMode( sal_Int32 nGfxMode ){ mnGfxMode = nGfxMode; }; - sal_Int32 GetGfxMode() const { return mnGfxMode; }; - void SetBkMode( UINT32 nMode ); - void SetBkColor( const Color& rColor ); - void SetTextColor( const Color& rColor ); - void SetTextAlign( UINT32 nAlign ); - void CreateObject( GDIObjectType, void* pStyle = NULL ); - void CreateObject( INT32 nIndex, GDIObjectType, void* pStyle = NULL ); - void DeleteObject( INT32 nIndex ); - void SelectObject( INT32 nIndex ); - CharSet GetCharSet(){ return maFont.GetCharSet(); }; - void SetFont( const Font& rFont ); - const Font& GetFont() const; - void SetTextLayoutMode( const sal_uInt32 nLayoutMode ); - sal_uInt32 GetTextLayoutMode() const; - - void ClearPath(){ aPathObj.Init(); }; - void ClosePath(){ aPathObj.ClosePath(); }; - const PolyPolygon& GetPathObj(){ return aPathObj; }; - - void MoveTo( const Point& rPoint, sal_Bool bRecordPath = sal_False ); - void LineTo( const Point& rPoint, sal_Bool bRecordPath = sal_False ); - void DrawPixel( const Point& rSource, const Color& rColor ); - void DrawLine( const Point& rSource, const Point& rDest ); - void DrawRect( const Rectangle& rRect, BOOL bEdge = TRUE ); - void DrawRoundRect( const Rectangle& rRect, const Size& rSize ); - void DrawEllipse( const Rectangle& rRect ); - void DrawArc( const Rectangle& rRect, const Point& rStartAngle, const Point& rEndAngle, BOOL bDrawTo = FALSE ); - void DrawPie( const Rectangle& rRect, const Point& rStartAngle, const Point& rEndAngle ); - void DrawChord( const Rectangle& rRect, const Point& rStartAngle, const Point& rEndAngle ); - void DrawPolygon( Polygon& rPolygon, sal_Bool bRecordPath = sal_False ); - void DrawPolyPolygon( PolyPolygon& rPolyPolygon, sal_Bool bRecordPath = sal_False ); - void DrawPolyLine( Polygon& rPolygon, sal_Bool bDrawTo = sal_False, sal_Bool bRecordPath = sal_False ); - void DrawPolyBezier( Polygon& rPolygin, sal_Bool bDrawTo = sal_False, sal_Bool bRecordPath = sal_False ); - void DrawText( Point& rPosition, String& rString, sal_Int32* pDXArry = NULL, sal_Bool bRecordPath = sal_False, - sal_Int32 nGraphicsMode = GM_COMPATIBLE ); - void ResolveBitmapActions( List& rSaveList ); - - void IntersectClipRect( const Rectangle& rRect ); - void ExcludeClipRect( const Rectangle& rRect ); - void MoveClipRegion( const Size& rSize ); - void SetClipPath( const PolyPolygon& rPolyPoly, sal_Int32 nClippingMode, sal_Bool bIsMapped ); - void UpdateClipRegion(); - void AddFromGDIMetaFile( GDIMetaFile& rGDIMetaFile ); - - WinMtfOutput( GDIMetaFile& rGDIMetaFile ); - virtual ~WinMtfOutput(); -}; - -// ----------------------------------------------------------------------------- - -class WinMtf -{ - protected: - - WinMtfOutput* pOut; // - SvStream* pWMF; // Die einzulesende WMF/EMF-Datei - - UINT32 nStartPos, nEndPos; - List aBmpSaveList; - - FilterConfigItem* pFilterConfigItem; - - com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator > xStatusIndicator; - - // Sorgt dafuer, das aSampledBrush der aktuelle Brush des GDIMetaFiles ist. - - Color ReadColor(); - void Callback( USHORT nPercent ); - - WinMtf( WinMtfOutput* pOut, SvStream& rStreamWMF, FilterConfigItem* pConfigItem = NULL ); - ~WinMtf(); - - public: - -}; - -//============================ EMFReader ================================== - -class EnhWMFReader : public WinMtf -{ - sal_Bool bRecordPath; - sal_Int32 nRecordCount; - - BOOL ReadHeader(); - Rectangle ReadRectangle( INT32, INT32, INT32, INT32 ); // Liesst und konvertiert ein Rechteck - void ImplExtTextOut( BOOL bWideCharakter ); - -public: - EnhWMFReader( SvStream& rStreamWMF, GDIMetaFile& rGDIMetaFile, FilterConfigItem* pConfigItem = NULL ) - : WinMtf( new WinMtfOutput( rGDIMetaFile ), rStreamWMF, pConfigItem ), bRecordPath( sal_False ) {}; - ~EnhWMFReader(); - - BOOL ReadEnhWMF(); -}; - -//============================ WMFReader ================================== - -class WMFReader : public WinMtf -{ -private: - - VirtualDevice aVDev; // just for the purpose of "IsFontAvailable" - UINT16 nUnitsPerInch; - sal_uInt32 nRecSize; - - // embedded EMF data - SvMemoryStream* pEMFStream; - - // total number of comment records containing EMF data - sal_uInt32 nEMFRecCount; - - // number of EMF records read - sal_uInt32 nEMFRec; - - // total size of embedded EMF data - sal_uInt32 nEMFSize; - - sal_uInt32 nSkipActions; - sal_uInt32 nCurrentAction; - sal_uInt32 nUnicodeEscapeAction; - - // Liesst den Kopf der WMF-Datei - BOOL ReadHeader(); - - // Liesst die Parameter des Rocords mit der Funktionsnummer nFunction. - void ReadRecordParams( USHORT nFunction ); - - Point ReadPoint(); // Liesst und konvertiert einen Punkt (erst X dann Y) - Point ReadYX(); // Liesst und konvertiert einen Punkt (erst Y dann X) - Rectangle ReadRectangle(); // Liesst und konvertiert ein Rechteck - Size ReadYXExt(); - sal_Bool GetPlaceableBound( Rectangle& rSize, SvStream* pStrm ); - -public: - - WMFReader( SvStream& rStreamWMF, GDIMetaFile& rGDIMetaFile, FilterConfigItem* pConfigItem = NULL ) - : WinMtf( new WinMtfOutput( rGDIMetaFile ), rStreamWMF, pConfigItem ) {}; - - ~WMFReader(); - - // Liesst aus dem Stream eine WMF-Datei und fuellt das GDIMetaFile - void ReadWMF(); -}; - -#endif - - diff --git a/svtools/source/filter.vcl/wmf/winwmf.cxx b/svtools/source/filter.vcl/wmf/winwmf.cxx deleted file mode 100644 index cea1ab490b04..000000000000 --- a/svtools/source/filter.vcl/wmf/winwmf.cxx +++ /dev/null @@ -1,1431 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#include "winmtf.hxx" -#include -#include -#include -#include - -//====================== MS-Windows-defines =============================== - -#define W_META_SETBKCOLOR 0x0201 -#define W_META_SETBKMODE 0x0102 -#define W_META_SETMAPMODE 0x0103 -#define W_META_SETROP2 0x0104 -#define W_META_SETRELABS 0x0105 -#define W_META_SETPOLYFILLMODE 0x0106 -#define W_META_SETSTRETCHBLTMODE 0x0107 -#define W_META_SETTEXTCHAREXTRA 0x0108 -#define W_META_SETTEXTCOLOR 0x0209 -#define W_META_SETTEXTJUSTIFICATION 0x020A -#define W_META_SETWINDOWORG 0x020B -#define W_META_SETWINDOWEXT 0x020C -#define W_META_SETVIEWPORTORG 0x020D -#define W_META_SETVIEWPORTEXT 0x020E -#define W_META_OFFSETWINDOWORG 0x020F -#define W_META_SCALEWINDOWEXT 0x0410 -#define W_META_OFFSETVIEWPORTORG 0x0211 -#define W_META_SCALEVIEWPORTEXT 0x0412 -#define W_META_LINETO 0x0213 -#define W_META_MOVETO 0x0214 -#define W_META_EXCLUDECLIPRECT 0x0415 -#define W_META_INTERSECTCLIPRECT 0x0416 -#define W_META_ARC 0x0817 -#define W_META_ELLIPSE 0x0418 -#define W_META_FLOODFILL 0x0419 -#define W_META_PIE 0x081A -#define W_META_RECTANGLE 0x041B -#define W_META_ROUNDRECT 0x061C -#define W_META_PATBLT 0x061D -#define W_META_SAVEDC 0x001E -#define W_META_SETPIXEL 0x041F -#define W_META_OFFSETCLIPRGN 0x0220 -#define W_META_TEXTOUT 0x0521 -#define W_META_BITBLT 0x0922 -#define W_META_STRETCHBLT 0x0B23 -#define W_META_POLYGON 0x0324 -#define W_META_POLYLINE 0x0325 -#define W_META_ESCAPE 0x0626 -#define W_META_RESTOREDC 0x0127 -#define W_META_FILLREGION 0x0228 -#define W_META_FRAMEREGION 0x0429 -#define W_META_INVERTREGION 0x012A -#define W_META_PAINTREGION 0x012B -#define W_META_SELECTCLIPREGION 0x012C -#define W_META_SELECTOBJECT 0x012D -#define W_META_SETTEXTALIGN 0x012E -#define W_META_DRAWTEXT 0x062F -#define W_META_CHORD 0x0830 -#define W_META_SETMAPPERFLAGS 0x0231 -#define W_META_EXTTEXTOUT 0x0a32 -#define W_META_SETDIBTODEV 0x0d33 -#define W_META_SELECTPALETTE 0x0234 -#define W_META_REALIZEPALETTE 0x0035 -#define W_META_ANIMATEPALETTE 0x0436 -#define W_META_SETPALENTRIES 0x0037 -#define W_META_POLYPOLYGON 0x0538 -#define W_META_RESIZEPALETTE 0x0139 -#define W_META_DIBBITBLT 0x0940 -#define W_META_DIBSTRETCHBLT 0x0b41 -#define W_META_DIBCREATEPATTERNBRUSH 0x0142 -#define W_META_STRETCHDIB 0x0f43 -#define W_META_EXTFLOODFILL 0x0548 -#define W_META_RESETDC 0x014C -#define W_META_STARTDOC 0x014D -#define W_META_STARTPAGE 0x004F -#define W_META_ENDPAGE 0x0050 -#define W_META_ABORTDOC 0x0052 -#define W_META_ENDDOC 0x005E -#define W_META_DELETEOBJECT 0x01f0 -#define W_META_CREATEPALETTE 0x00f7 -#define W_META_CREATEBRUSH 0x00F8 -#define W_META_CREATEPATTERNBRUSH 0x01F9 -#define W_META_CREATEPENINDIRECT 0x02FA -#define W_META_CREATEFONTINDIRECT 0x02FB -#define W_META_CREATEBRUSHINDIRECT 0x02FC -#define W_META_CREATEBITMAPINDIRECT 0x02FD -#define W_META_CREATEBITMAP 0x06FE -#define W_META_CREATEREGION 0x06FF - -//=================== Methoden von WMFReader ============================== - -inline Point WMFReader::ReadPoint() -{ - short nX, nY; - *pWMF >> nX >> nY; - return Point( nX, nY ); -} - -// ------------------------------------------------------------------------ - -inline Point WMFReader::ReadYX() -{ - short nX, nY; - *pWMF >> nY >> nX; - return Point( nX, nY ); -} - -// ------------------------------------------------------------------------ - -Rectangle WMFReader::ReadRectangle() -{ - Point aBR, aTL; - aBR = ReadYX(); - aTL = ReadYX(); - aBR.X()--; - aBR.Y()--; - return Rectangle( aTL, aBR ); -} - -// ------------------------------------------------------------------------ - -Size WMFReader::ReadYXExt() -{ - short nW, nH; - *pWMF >> nH >> nW; - return Size( nW, nH ); -} - -// ------------------------------------------------------------------------ - -void WMFReader::ReadRecordParams( USHORT nFunc ) -{ - switch( nFunc ) - { - case W_META_SETBKCOLOR: - { - pOut->SetBkColor( ReadColor() ); - } - break; - - case W_META_SETBKMODE: - { - USHORT nDat; - *pWMF >> nDat; - pOut->SetBkMode( nDat ); - } - break; - - // !!! - case W_META_SETMAPMODE: - { - sal_Int16 nMapMode; - *pWMF >> nMapMode; - pOut->SetMapMode( nMapMode ); - } - break; - - case W_META_SETROP2: - { - UINT16 nROP2; - *pWMF >> nROP2; - pOut->SetRasterOp( nROP2 ); - } - break; - - case W_META_SETTEXTCOLOR: - { - pOut->SetTextColor( ReadColor() ); - } - break; - - case W_META_SETWINDOWORG: - { - pOut->SetWinOrg( ReadYX() ); - } - break; - - case W_META_SETWINDOWEXT: - { - short nWidth, nHeight; - *pWMF >> nHeight >> nWidth; - pOut->SetWinExt( Size( nWidth, nHeight ) ); - } - break; - - case W_META_OFFSETWINDOWORG: - { - short nXAdd, nYAdd; - *pWMF >> nYAdd >> nXAdd; - pOut->SetWinOrgOffset( nXAdd, nYAdd ); - } - break; - - case W_META_SCALEWINDOWEXT: - { - short nXNum, nXDenom, nYNum, nYDenom; - *pWMF >> nYDenom >> nYNum >> nXDenom >> nXNum; - pOut->ScaleWinExt( (double)nXNum / nXDenom, (double)nYNum / nYDenom ); - } - break; - - case W_META_SETVIEWPORTORG: - case W_META_SETVIEWPORTEXT: - break; - - case W_META_OFFSETVIEWPORTORG: - { - short nXAdd, nYAdd; - *pWMF >> nYAdd >> nXAdd; - pOut->SetDevOrgOffset( nXAdd, nYAdd ); - } - break; - - case W_META_SCALEVIEWPORTEXT: - { - short nXNum, nXDenom, nYNum, nYDenom; - *pWMF >> nYDenom >> nYNum >> nXDenom >> nXNum; - pOut->ScaleDevExt( (double)nXNum / nXDenom, (double)nYNum / nYDenom ); - } - break; - - case W_META_LINETO: - { - pOut->LineTo( ReadYX() ); - } - break; - - case W_META_MOVETO: - { - pOut->MoveTo( ReadYX() ); - } - break; - - case W_META_INTERSECTCLIPRECT: - { - pOut->IntersectClipRect( ReadRectangle() ); - } - break; - - case W_META_RECTANGLE: - { - pOut->DrawRect( ReadRectangle() ); - } - break; - - case W_META_ROUNDRECT: - { - Size aSize( ReadYXExt() ); - pOut->DrawRoundRect( ReadRectangle(), Size( aSize.Width() / 2, aSize.Height() / 2 ) ); - } - break; - - case W_META_ELLIPSE: - { - pOut->DrawEllipse( ReadRectangle() ); - } - break; - - case W_META_ARC: - { - Point aEnd( ReadYX() ); - Point aStart( ReadYX() ); - Rectangle aRect( ReadRectangle() ); - aRect.Justify(); - pOut->DrawArc( aRect, aStart, aEnd ); - } - break; - - case W_META_PIE: - { - Point aEnd( ReadYX() ); - Point aStart( ReadYX() ); - Rectangle aRect( ReadRectangle() ); - aRect.Justify(); - - // #i73608# OutputDevice deviates from WMF - // semantics. start==end means full ellipse here. - if( aStart == aEnd ) - pOut->DrawEllipse( aRect ); - else - pOut->DrawPie( aRect, aStart, aEnd ); - } - break; - - case W_META_CHORD: - { - Point aEnd( ReadYX() ); - Point aStart( ReadYX() ); - Rectangle aRect( ReadRectangle() ); - aRect.Justify(); - pOut->DrawChord( aRect, aStart, aEnd ); - } - break; - - case W_META_POLYGON: - { - USHORT i,nPoints; - *pWMF >> nPoints; - Polygon aPoly( nPoints ); - for( i = 0; i < nPoints; i++ ) - aPoly[ i ] = ReadPoint(); - pOut->DrawPolygon( aPoly ); - } - break; - - case W_META_POLYPOLYGON: - { - USHORT i, nPoly, nPoints; - USHORT* pnPoints; - Point* pPtAry; - // Anzahl der Polygone: - *pWMF >> nPoly; - // Anzahl der Punkte eines jeden Polygons holen, Gesammtzahl der Punkte ermitteln: - pnPoints = new USHORT[ nPoly ]; - nPoints = 0; - for( i = 0; i < nPoly; i++ ) - { - *pWMF >> pnPoints[i]; - nPoints = nPoints + pnPoints[i]; - } - // Polygonpunkte holen: - pPtAry = (Point*) new char[ nPoints * sizeof(Point) ]; - for ( i = 0; i < nPoints; i++ ) - pPtAry[ i ] = ReadPoint(); - // PolyPolygon Actions erzeugen - PolyPolygon aPolyPoly( nPoly, pnPoints, pPtAry ); - pOut->DrawPolyPolygon( aPolyPoly ); - delete[] (char*) pPtAry; - delete[] pnPoints; - } - break; - - case W_META_POLYLINE: - { - USHORT i,nPoints; - *pWMF >> nPoints; - Polygon aPoly( nPoints ); - for( i = 0; i < nPoints; i++ ) - aPoly[ i ] = ReadPoint(); - pOut->DrawPolyLine( aPoly ); - } - break; - - case W_META_SAVEDC: - { - pOut->Push(); - } - break; - - case W_META_RESTOREDC: - { - pOut->Pop(); - } - break; - - case W_META_SETPIXEL: - { - const Color aColor = ReadColor(); - pOut->DrawPixel( ReadYX(), aColor ); - } - break; - - case W_META_OFFSETCLIPRGN: - { - pOut->MoveClipRegion( ReadYXExt() ); - } - break; - - case W_META_TEXTOUT: - { - USHORT nLength; - *pWMF >> nLength; - if ( nLength ) - { - char* pChar = new char[ ( nLength + 1 ) &~ 1 ]; - pWMF->Read( pChar, ( nLength + 1 ) &~ 1 ); - String aText( pChar, nLength, pOut->GetCharSet() ); - delete[] pChar; - Point aPosition( ReadYX() ); - pOut->DrawText( aPosition, aText ); - } - } - break; - - case W_META_EXTTEXTOUT: - { - sal_Int16 nDx, nDxTmp; - sal_uInt16 i, nLen, nOptions; - sal_Int32 nRecordPos, nRecordSize, nOriginalTextLen, nNewTextLen; - Point aPosition; - Rectangle aRect; - sal_Int32* pDXAry = NULL; - - pWMF->SeekRel(-6); - nRecordPos = pWMF->Tell(); - *pWMF >> nRecordSize; - pWMF->SeekRel(2); - aPosition = ReadYX(); - *pWMF >> nLen >> nOptions; - - sal_Int32 nTextLayoutMode = TEXT_LAYOUT_DEFAULT; - if ( nOptions & ETO_RTLREADING ) - nTextLayoutMode = TEXT_LAYOUT_BIDI_RTL | TEXT_LAYOUT_TEXTORIGIN_LEFT; - pOut->SetTextLayoutMode( nTextLayoutMode ); - DBG_ASSERT( ( nOptions & ( ETO_PDY | ETO_GLYPH_INDEX ) ) == 0, "SJ: ETO_PDY || ETO_GLYPH_INDEX in WMF" ); - - // Nur wenn der Text auch Zeichen enthaelt, macht die Ausgabe Sinn - if( nLen ) - { - nOriginalTextLen = nLen; - if( nOptions & ETO_CLIPPED ) - { - const Point aPt1( ReadPoint() ); - const Point aPt2( ReadPoint() ); - aRect = Rectangle( aPt1, aPt2 ); - } - char* pChar = new char[ ( nOriginalTextLen + 1 ) &~ 1 ]; - pWMF->Read( pChar, ( nOriginalTextLen + 1 ) &~ 1 ); - String aText( pChar, (sal_uInt16)nOriginalTextLen, pOut->GetCharSet() );// after this conversion the text may contain - nNewTextLen = aText.Len(); // less character (japanese version), so the - delete[] pChar; // dxAry will not fit - - if ( nNewTextLen ) - { - sal_uInt32 nMaxStreamPos = nRecordPos + ( nRecordSize << 1 ); - sal_Int32 nDxArySize = nMaxStreamPos - pWMF->Tell(); - sal_Int32 nDxAryEntries = nDxArySize >> 1; - sal_Bool bUseDXAry = FALSE; - - if ( ( ( nDxAryEntries % nOriginalTextLen ) == 0 ) && ( nNewTextLen <= nOriginalTextLen ) ) - { - pDXAry = new sal_Int32[ nNewTextLen ]; - for ( i = 0; i < nNewTextLen; i++ ) - { - if ( pWMF->Tell() >= nMaxStreamPos ) - break; - *pWMF >> nDx; - if ( nNewTextLen != nOriginalTextLen ) - { - ByteString aTmp( aText.GetChar( i ), pOut->GetCharSet() ); - if ( aTmp.Len() > 1 ) - { - sal_Int32 nDxCount = aTmp.Len() - 1; - if ( ( ( nDxCount * 2 ) + pWMF->Tell() ) > nMaxStreamPos ) - break; - while ( nDxCount-- ) - { - *pWMF >> nDxTmp; - nDx = nDx + nDxTmp; - } - } - } - pDXAry[ i ] = nDx; - } - if ( i == nNewTextLen ) - bUseDXAry = TRUE; - } - if ( pDXAry && bUseDXAry ) - pOut->DrawText( aPosition, aText, pDXAry ); - else - pOut->DrawText( aPosition, aText ); - } - } - delete[] pDXAry; - - } - break; - - case W_META_SELECTOBJECT: - { - INT16 nObjIndex; - *pWMF >> nObjIndex; - pOut->SelectObject( nObjIndex ); - } - break; - - case W_META_SETTEXTALIGN: - { - UINT16 nAlign; - *pWMF >> nAlign; - pOut->SetTextAlign( nAlign ); - } - break; - - case W_META_BITBLT: - { - // 0-3 : nWinROP #93454# - // 4-5 : y offset of source bitmap - // 6-7 : x offset of source bitmap - // 8-9 : used height of source bitmap - // 10-11 : used width of source bitmap - // 12-13 : destination position y (in pixel) - // 14-15 : destination position x (in pixel) - // 16-17 : dont know - // 18-19 : Width Bitmap in Pixel - // 20-21 : Height Bitmap in Pixel - // 22-23 : bytes per scanline - // 24 : planes - // 25 : bitcount - - sal_Int32 nWinROP; - sal_uInt16 nSx, nSy, nSxe, nSye, nDontKnow, nWidth, nHeight, nBytesPerScan; - sal_uInt8 nPlanes, nBitCount; - - *pWMF >> nWinROP - >> nSy >> nSx >> nSye >> nSxe; - Point aPoint( ReadYX() ); - *pWMF >> nDontKnow >> nWidth >> nHeight >> nBytesPerScan >> nPlanes >> nBitCount; - - if ( nWidth && nHeight && ( nPlanes == 1 ) && ( nBitCount == 1 ) ) - { - Bitmap aBmp( Size( nWidth, nHeight ), nBitCount ); - BitmapWriteAccess* pAcc; - pAcc = aBmp.AcquireWriteAccess(); - if ( pAcc ) - { - sal_uInt16 y, x, scan; - sal_Int8 i, nEightPixels; - for ( y = 0; y < nHeight; y++ ) - { - x = 0; - for ( scan = 0; scan < nBytesPerScan; scan++ ) - { - *pWMF >> nEightPixels; - for ( i = 7; i >= 0; i-- ) - { - if ( x < nWidth ) - { - pAcc->SetPixel( y, x, (nEightPixels>>i)&1 ); - } - x++; - } - } - } - aBmp.ReleaseAccess( pAcc ); - if ( nSye && nSxe && - ( ( nSx + nSxe ) <= aBmp.GetSizePixel().Width() ) && - ( ( nSy + nSye <= aBmp.GetSizePixel().Height() ) ) ) - { - Rectangle aCropRect( Point( nSx, nSy ), Size( nSxe, nSye ) ); - aBmp.Crop( aCropRect ); - } - Rectangle aDestRect( aPoint, Size( nSxe, nSye ) ); - aBmpSaveList.Insert( new BSaveStruct( aBmp, aDestRect, nWinROP ), LIST_APPEND ); - } - } - } - break; - - case W_META_STRETCHBLT: - case W_META_DIBBITBLT: - case W_META_DIBSTRETCHBLT: - case W_META_STRETCHDIB: - { - sal_Int32 nWinROP; - sal_uInt16 nSx, nSy, nSxe, nSye, nUsage; - Bitmap aBmp; - - *pWMF >> nWinROP; - - if( nFunc == W_META_STRETCHDIB ) - *pWMF >> nUsage; - - // nSye and nSxe is the number of pixels that has to been used - if( nFunc == W_META_STRETCHDIB || nFunc == W_META_STRETCHBLT || nFunc == W_META_DIBSTRETCHBLT ) - *pWMF >> nSye >> nSxe; - else - nSye = nSxe = 0; // set this to zero as indicator not to scale the bitmap later - - // nSy and nx is the offset of the first pixel - *pWMF >> nSy >> nSx; - - if( nFunc == W_META_STRETCHDIB || nFunc == W_META_DIBBITBLT || nFunc == W_META_DIBSTRETCHBLT ) - { - if ( nWinROP == PATCOPY ) - *pWMF >> nUsage; // i don't know anything of this parameter, so its called nUsage - // pOut->DrawRect( Rectangle( ReadYX(), aDestSize ), FALSE ); - - Size aDestSize( ReadYXExt() ); - if ( aDestSize.Width() && aDestSize.Height() ) // #92623# do not try to read buggy bitmaps - { - Rectangle aDestRect( ReadYX(), aDestSize ); - if ( nWinROP != PATCOPY ) - aBmp.Read( *pWMF, FALSE ); - - // test if it is sensible to crop - if ( nSye && nSxe && - ( ( nSx + nSxe ) <= aBmp.GetSizePixel().Width() ) && - ( ( nSy + nSye <= aBmp.GetSizePixel().Height() ) ) ) - { - Rectangle aCropRect( Point( nSx, nSy ), Size( nSxe, nSye ) ); - aBmp.Crop( aCropRect ); - } - aBmpSaveList.Insert( new BSaveStruct( aBmp, aDestRect, nWinROP ), LIST_APPEND ); - } - } - } - break; - - case W_META_DIBCREATEPATTERNBRUSH: - { - Bitmap aBmp; - BitmapReadAccess* pBmp; - UINT32 nRed = 0, nGreen = 0, nBlue = 0, nCount = 1; - UINT16 nFunction; - - *pWMF >> nFunction >> nFunction; - - aBmp.Read( *pWMF, FALSE ); - pBmp = aBmp.AcquireReadAccess(); - if ( pBmp ) - { - for ( INT32 y = 0; y < pBmp->Height(); y++ ) - { - for ( INT32 x = 0; x < pBmp->Width(); x++ ) - { - const BitmapColor aColor( pBmp->GetColor( y, x ) ); - - nRed += aColor.GetRed(); - nGreen += aColor.GetGreen(); - nBlue += aColor.GetBlue(); - } - } - nCount = pBmp->Height() * pBmp->Width(); - if ( !nCount ) - nCount++; - aBmp.ReleaseAccess( pBmp ); - } - Color aColor( (BYTE)( nRed / nCount ), (BYTE)( nGreen / nCount ), (BYTE)( nBlue / nCount ) ); - pOut->CreateObject( GDI_BRUSH, new WinMtfFillStyle( aColor, FALSE ) ); - } - break; - - case W_META_DELETEOBJECT: - { - INT16 nIndex; - *pWMF >> nIndex; - pOut->DeleteObject( nIndex ); - } - break; - - case W_META_CREATEPALETTE: - { - pOut->CreateObject( GDI_DUMMY ); - } - break; - - case W_META_CREATEBRUSH: - { - pOut->CreateObject( GDI_BRUSH, new WinMtfFillStyle( Color( COL_WHITE ), FALSE ) ); - } - break; - - case W_META_CREATEPATTERNBRUSH: - { - pOut->CreateObject( GDI_BRUSH, new WinMtfFillStyle( Color( COL_WHITE ), FALSE ) ); - } - break; - - case W_META_CREATEPENINDIRECT: - { - LineInfo aLineInfo; - USHORT nStyle, nWidth, nHeight; - - *pWMF >> nStyle >> nWidth >> nHeight; - - if ( nWidth ) - aLineInfo.SetWidth( nWidth ); - - BOOL bTransparent = FALSE; - UINT16 nDashCount = 0; - UINT16 nDotCount = 0; - switch( nStyle ) - { - case PS_DASHDOTDOT : - nDotCount++; - case PS_DASHDOT : - nDashCount++; - case PS_DOT : - nDotCount++; - break; - case PS_DASH : - nDashCount++; - break; - case PS_NULL : - bTransparent = TRUE; - aLineInfo.SetStyle( LINE_NONE ); - break; - default : - case PS_INSIDEFRAME : - case PS_SOLID : - aLineInfo.SetStyle( LINE_SOLID ); - } - if ( nDashCount | nDotCount ) - { - aLineInfo.SetStyle( LINE_DASH ); - aLineInfo.SetDashCount( nDashCount ); - aLineInfo.SetDotCount( nDotCount ); - } - pOut->CreateObject( GDI_PEN, new WinMtfLineStyle( ReadColor(), aLineInfo, bTransparent ) ); - } - break; - - case W_META_CREATEBRUSHINDIRECT: - { - USHORT nStyle; - *pWMF >> nStyle; - pOut->CreateObject( GDI_BRUSH, new WinMtfFillStyle( ReadColor(), ( nStyle == BS_HOLLOW ) ? TRUE : FALSE ) ); - } - break; - - case W_META_CREATEFONTINDIRECT: - { - Size aFontSize; - char lfFaceName[ LF_FACESIZE ]; - INT16 lfEscapement, lfOrientation, lfWeight; // ( ehemals USHORT ) - - LOGFONTW aLogFont; - aFontSize = ReadYXExt(); - *pWMF >> lfEscapement >> lfOrientation >> lfWeight - >> aLogFont.lfItalic >> aLogFont.lfUnderline >> aLogFont.lfStrikeOut >> aLogFont.lfCharSet >> aLogFont.lfOutPrecision - >> aLogFont.lfClipPrecision >> aLogFont.lfQuality >> aLogFont.lfPitchAndFamily; - pWMF->Read( lfFaceName, LF_FACESIZE ); - aLogFont.lfWidth = aFontSize.Width(); - aLogFont.lfHeight = aFontSize.Height(); - aLogFont.lfEscapement = lfEscapement; - aLogFont.lfOrientation = lfOrientation; - aLogFont.lfWeight = lfWeight; - - CharSet eCharSet; - if ( ( aLogFont.lfCharSet == OEM_CHARSET ) || ( aLogFont.lfCharSet == DEFAULT_CHARSET ) ) - eCharSet = gsl_getSystemTextEncoding(); - else - eCharSet = rtl_getTextEncodingFromWindowsCharset( aLogFont.lfCharSet ); - if ( eCharSet == RTL_TEXTENCODING_DONTKNOW ) - eCharSet = gsl_getSystemTextEncoding(); - if ( eCharSet == RTL_TEXTENCODING_SYMBOL ) - eCharSet = RTL_TEXTENCODING_MS_1252; - aLogFont.alfFaceName = UniString( lfFaceName, eCharSet ); - - pOut->CreateObject( GDI_FONT, new WinMtfFontStyle( aLogFont ) ); - } - break; - - case W_META_CREATEBITMAPINDIRECT: - { - pOut->CreateObject( GDI_DUMMY ); - } - break; - - case W_META_CREATEBITMAP: - { - pOut->CreateObject( GDI_DUMMY ); - } - break; - - case W_META_CREATEREGION: - { - pOut->CreateObject( GDI_DUMMY ); - } - break; - - case W_META_EXCLUDECLIPRECT : - { - pOut->ExcludeClipRect( ReadRectangle() ); - } - break; - - case W_META_PATBLT: - { - UINT32 nROP, nOldROP; - *pWMF >> nROP; - Size aSize = ReadYXExt(); - nOldROP = pOut->SetRasterOp( nROP ); - pOut->DrawRect( Rectangle( ReadYX(), aSize ), FALSE ); - pOut->SetRasterOp( nOldROP ); - } - break; - - case W_META_SELECTCLIPREGION: - { - sal_Int16 nObjIndex; - *pWMF >> nObjIndex; - if ( !nObjIndex ) - { - PolyPolygon aEmptyPolyPoly; - pOut->SetClipPath( aEmptyPolyPoly, RGN_COPY, sal_True ); - } - } - break; - - case W_META_ESCAPE : - { - // nRecSize has been checked previously to be greater than 3 - sal_uInt64 nMetaRecSize = static_cast< sal_uInt64 >( nRecSize - 2 ) * 2; - sal_uInt64 nMetaRecEndPos = pWMF->Tell() + nMetaRecSize; - - // taking care that nRecSize does not exceed the maximal stream position - if ( nMetaRecEndPos > nEndPos ) - { - pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR ); - break; - } - if ( nRecSize >= 4 ) // minimal escape lenght - { - sal_uInt16 nMode, nLen; - *pWMF >> nMode - >> nLen; - if ( ( nMode == W_MFCOMMENT ) && ( nLen >= 4 ) ) - { - sal_uInt32 nNewMagic; // we have to read int32 for - *pWMF >> nNewMagic; // META_ESCAPE_ENHANCED_METAFILE CommentIdentifier - - if( nNewMagic == 0x2c2a4f4f && nLen >= 14 ) - { - sal_uInt16 nMagic2; - *pWMF >> nMagic2; - if( nMagic2 == 0x0a ) // 2nd half of magic - { // continue with private escape - sal_uInt32 nCheck, nEsc; - *pWMF >> nCheck - >> nEsc; - - sal_uInt32 nEscLen = nLen - 14; - if ( nEscLen <= ( nRecSize * 2 ) ) - { -#ifdef OSL_BIGENDIAN - sal_uInt32 nTmp = SWAPLONG( nEsc ); - sal_uInt32 nCheckSum = rtl_crc32( 0, &nTmp, 4 ); -#else - sal_uInt32 nCheckSum = rtl_crc32( 0, &nEsc, 4 ); -#endif - sal_Int8* pData = NULL; - - if ( ( static_cast< sal_uInt64 >( nEscLen ) + pWMF->Tell() ) > nMetaRecEndPos ) - { - pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR ); - break; - } - if ( nEscLen > 0 ) - { - pData = new sal_Int8[ nEscLen ]; - pWMF->Read( pData, nEscLen ); - nCheckSum = rtl_crc32( nCheckSum, pData, nEscLen ); - } - if ( nCheck == nCheckSum ) - { - switch( nEsc ) - { - case PRIVATE_ESCAPE_UNICODE : - { // we will use text instead of polygons only if we have the correct font - if ( aVDev.IsFontAvailable( pOut->GetFont().GetName() ) ) - { - Point aPt; - String aString; - sal_uInt32 i, nStringLen, nDXCount; - sal_Int32* pDXAry = NULL; - SvMemoryStream aMemoryStream( nEscLen ); - aMemoryStream.Write( pData, nEscLen ); - aMemoryStream.Seek( STREAM_SEEK_TO_BEGIN ); - aMemoryStream >> aPt.X() - >> aPt.Y() - >> nStringLen; - - if ( ( static_cast< sal_uInt64 >( nStringLen ) * sizeof( sal_Unicode ) ) < ( nEscLen - aMemoryStream.Tell() ) ) - { - sal_Unicode* pBuf = aString.AllocBuffer( (xub_StrLen)nStringLen ); - for ( i = 0; i < nStringLen; i++ ) - aMemoryStream >> pBuf[ i ]; - aMemoryStream >> nDXCount; - if ( ( static_cast< sal_uInt64 >( nDXCount ) * sizeof( sal_Int32 ) ) >= ( nEscLen - aMemoryStream.Tell() ) ) - nDXCount = 0; - if ( nDXCount ) - pDXAry = new sal_Int32[ nDXCount ]; - for ( i = 0; i < nDXCount; i++ ) - aMemoryStream >> pDXAry[ i ]; - aMemoryStream >> nSkipActions; - pOut->DrawText( aPt, aString, pDXAry ); - delete[] pDXAry; - } - } - } - break; - } - } - delete[] pData; - } - } - } - else if ( (nNewMagic == static_cast< sal_uInt32 >(0x43464D57)) && (nLen >= 34) && ( (sal_Int32)(nLen + 10) <= (sal_Int32)(nRecSize * 2) )) - { - sal_uInt32 nComType, nVersion, nFlags, nComRecCount, - nCurRecSize, nRemainingSize, nEMFTotalSize; - sal_uInt16 nCheck; - - *pWMF >> nComType >> nVersion >> nCheck >> nFlags - >> nComRecCount >> nCurRecSize - >> nRemainingSize >> nEMFTotalSize; // the nRemainingSize is not mentioned in MSDN documentation - // but it seems to be required to read in data produced by OLE - - if( nComType == 0x01 && nVersion == 0x10000 && nComRecCount ) - { - if( !nEMFRec ) - { // first EMF comment - nEMFRecCount = nComRecCount; - nEMFSize = nEMFTotalSize; - pEMFStream = new SvMemoryStream( nEMFSize ); - } - else if( ( nEMFRecCount != nComRecCount ) || ( nEMFSize != nEMFTotalSize ) ) // add additional checks here - { - // total records should be the same as in previous comments - nEMFRecCount = 0xFFFFFFFF; - delete pEMFStream; - pEMFStream = NULL; - } - nEMFRec++; - - if( pEMFStream && nCurRecSize + 34 > nLen ) - { - nEMFRecCount = 0xFFFFFFFF; - delete pEMFStream; - pEMFStream = NULL; - } - - if( pEMFStream ) - { - sal_Int8* pBuf = new sal_Int8[ nCurRecSize ]; - sal_uInt32 nCount = pWMF->Read( pBuf, nCurRecSize ); - if( nCount == nCurRecSize ) - pEMFStream->Write( pBuf, nCount ); - delete[] pBuf; - } - } - } - } - } - } - break; - - case W_META_SETRELABS: - case W_META_SETPOLYFILLMODE: - case W_META_SETSTRETCHBLTMODE: - case W_META_SETTEXTCHAREXTRA: - case W_META_SETTEXTJUSTIFICATION: - case W_META_FLOODFILL : - case W_META_FILLREGION: - case W_META_FRAMEREGION: - case W_META_INVERTREGION: - case W_META_PAINTREGION: - case W_META_DRAWTEXT: - case W_META_SETMAPPERFLAGS: - case W_META_SETDIBTODEV: - case W_META_SELECTPALETTE: - case W_META_REALIZEPALETTE: - case W_META_ANIMATEPALETTE: - case W_META_SETPALENTRIES: - case W_META_RESIZEPALETTE: - case W_META_EXTFLOODFILL: - case W_META_RESETDC: - case W_META_STARTDOC: - case W_META_STARTPAGE: - case W_META_ENDPAGE: - case W_META_ABORTDOC: - case W_META_ENDDOC: - break; - } -} - -// ------------------------------------------------------------------------ - -BOOL WMFReader::ReadHeader() -{ - Rectangle aPlaceableBound; - sal_uInt32 nl, nStrmPos = pWMF->Tell(); - - // Einlesen des METAFILEHEADER, falls vorhanden - *pWMF >> nl; - - Size aWMFSize; - if ( nl == 0x9ac6cdd7L ) - { - INT16 nVal; - - // hmf (Unused) ueberlesen wir - pWMF->SeekRel(2); - - // BoundRect - *pWMF >> nVal; aPlaceableBound.Left() = nVal; - *pWMF >> nVal; aPlaceableBound.Top() = nVal; - *pWMF >> nVal; aPlaceableBound.Right() = nVal; - *pWMF >> nVal; aPlaceableBound.Bottom() = nVal; - - // inch - *pWMF >> nUnitsPerInch; - - // reserved - pWMF->SeekRel( 4 ); - - // checksum pruefen wir lieber nicht - pWMF->SeekRel( 2 ); - } - else - { - nUnitsPerInch = 96; - pWMF->Seek( nStrmPos + 18 ); // set the streampos to the start of the the metaactions - GetPlaceableBound( aPlaceableBound, pWMF ); - pWMF->Seek( nStrmPos ); - } - - pOut->SetWinOrg( aPlaceableBound.TopLeft() ); - aWMFSize = Size( labs( aPlaceableBound.GetWidth() ), labs( aPlaceableBound.GetHeight() ) ); - pOut->SetWinExt( aWMFSize ); - - Size aDevExt( 10000, 10000 ); - if( ( labs( aWMFSize.Width() ) > 1 ) && ( labs( aWMFSize.Height() ) > 1 ) ) - { - const Fraction aFrac( 1, nUnitsPerInch ); - MapMode aWMFMap( MAP_INCH, Point(), aFrac, aFrac ); - Size aSize100( OutputDevice::LogicToLogic( aWMFSize, aWMFMap, MAP_100TH_MM ) ); - aDevExt = Size( labs( aSize100.Width() ), labs( aSize100.Height() ) ); - } - pOut->SetDevExt( aDevExt ); - - // Einlesen des METAHEADER - *pWMF >> nl; // Typ und Headergroesse - - if( nl != 0x00090001 ) - { - pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR ); - return FALSE; - } - - pWMF->SeekRel( 2 ); // Version (von Windows) - pWMF->SeekRel( 4 ); // Size (der Datei in Words) - pWMF->SeekRel( 2 ); // NoObjects (Maximale Anzahl der gleichzeitigen Objekte) - pWMF->SeekRel( 4 ); // MaxRecord (Groesse des groessten Records in Words) - pWMF->SeekRel( 2 ); // NoParameters (Unused - - return TRUE; -} - -void WMFReader::ReadWMF() -{ - USHORT nFunction; - ULONG nPos, nPercent, nLastPercent; - - nSkipActions = 0; - nCurrentAction = 0; - nUnicodeEscapeAction = 0; - - pEMFStream = NULL; - nEMFRecCount = 0; - nEMFRec = 0; - nEMFSize = 0; - - sal_Bool bEMFAvailable = sal_False; - - pOut->SetMapMode( MM_ANISOTROPIC ); - pOut->SetWinOrg( Point() ); - pOut->SetWinExt( Size( 1, 1 ) ); - pOut->SetDevExt( Size( 10000, 10000 ) ); - - nEndPos=pWMF->Seek( STREAM_SEEK_TO_END ); - pWMF->Seek( nStartPos ); - Callback( (USHORT) ( nLastPercent = 0 ) ); - - if ( ReadHeader() ) - { - - nPos = pWMF->Tell(); - - if( nEndPos - nStartPos ) - { - while( TRUE ) - { - nCurrentAction++; - nPercent = ( nPos - nStartPos ) * 100 / ( nEndPos - nStartPos ); - - if( nLastPercent + 4 <= nPercent ) - { - Callback( (USHORT) nPercent ); - nLastPercent = nPercent; - } - *pWMF >> nRecSize >> nFunction; - - if( pWMF->GetError() || ( nRecSize < 3 ) || ( nRecSize==3 && nFunction==0 ) || pWMF->IsEof() ) - { - - if( pWMF->IsEof() ) - pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR ); - - break; - } - if ( !bEMFAvailable ) - { - if( aBmpSaveList.Count() && - ( nFunction != W_META_STRETCHDIB ) && - ( nFunction != W_META_DIBBITBLT ) && - ( nFunction != W_META_DIBSTRETCHBLT ) ) - { - pOut->ResolveBitmapActions( aBmpSaveList ); - } - if ( !nSkipActions ) - ReadRecordParams( nFunction ); - else - nSkipActions--; - - if( pEMFStream && nEMFRecCount == nEMFRec ) - { - GDIMetaFile aMeta; - pEMFStream->Seek( 0 ); - EnhWMFReader* pEMFReader = new EnhWMFReader ( *pEMFStream, aMeta ); - bEMFAvailable = pEMFReader->ReadEnhWMF(); - delete pEMFReader; // destroy first!!! - - if( bEMFAvailable ) - { - pOut->AddFromGDIMetaFile( aMeta ); - pOut->SetrclFrame( Rectangle(0, 0, aMeta.GetPrefSize().Width(), aMeta.GetPrefSize().Height() )); - - // the stream needs to be set to the wmf end position, - // otherwise the GfxLink that is created will be incorrect - // (leading to graphic loss after swapout/swapin). - // so we will proceed normally, but are ignoring further wmf - // records - } - else - { - // something went wrong - // continue with WMF, don't try this again - delete pEMFStream; - pEMFStream = NULL; - } - } - } - nPos += nRecSize * 2; - if ( nPos <= nEndPos ) - pWMF->Seek( nPos ); - else - pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR ); - } - } - else - pWMF->SetError( SVSTREAM_GENERALERROR ); - - if( !pWMF->GetError() && aBmpSaveList.Count() ) - pOut->ResolveBitmapActions( aBmpSaveList ); - } - if ( pWMF->GetError() ) - pWMF->Seek( nStartPos ); -} - -// ------------------------------------------------------------------------ - -static void GetWinExtMax( const Point& rSource, Rectangle& rPlaceableBound, const sal_Int16 nMapMode ) -{ - Point aSource( rSource ); - if ( nMapMode == MM_HIMETRIC ) - aSource.Y() = -rSource.Y(); - if ( aSource.X() < rPlaceableBound.Left() ) - rPlaceableBound.Left() = aSource.X(); - if ( aSource.X() > rPlaceableBound.Right() ) - rPlaceableBound.Right() = aSource.X(); - if ( aSource.Y() < rPlaceableBound.Top() ) - rPlaceableBound.Top() = aSource.Y(); - if ( aSource.Y() > rPlaceableBound.Bottom() ) - rPlaceableBound.Bottom() = aSource.Y(); -} - -static void GetWinExtMax( const Rectangle& rSource, Rectangle& rPlaceableBound, const sal_Int16 nMapMode ) -{ - GetWinExtMax( rSource.TopLeft(), rPlaceableBound, nMapMode ); - GetWinExtMax( rSource.BottomRight(), rPlaceableBound, nMapMode ); -} - -sal_Bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) -{ - sal_Bool bRet = sal_True; - - rPlaceableBound.Left() = (sal_Int32)0x7fffffff; - rPlaceableBound.Top() = (sal_Int32)0x7fffffff; - rPlaceableBound.Right() = (sal_Int32)0x80000000; - rPlaceableBound.Bottom() = (sal_Int32)0x80000000; - - sal_Int16 nMapMode = MM_ANISOTROPIC; - - sal_uInt16 nFunction; - sal_uInt32 nRSize; - sal_uInt32 nPos = pStm->Tell(); - sal_uInt32 nEnd = pStm->Seek( STREAM_SEEK_TO_END ); - - pStm->Seek( nPos ); - - if( nEnd - nPos ) - { - while( bRet ) - { - *pStm >> nRSize >> nFunction; - - if( pStm->GetError() || ( nRSize < 3 ) || ( nRSize==3 && nFunction==0 ) || pStm->IsEof() ) - { - if( pStm->IsEof() ) - { - pStm->SetError( SVSTREAM_FILEFORMAT_ERROR ); - bRet = sal_False; - } - break; - } - switch( nFunction ) - { - case W_META_SETWINDOWORG: - { - Point aWinOrg; - aWinOrg = ReadYX(); - rPlaceableBound.SetPos( aWinOrg ); - } - break; - - case W_META_SETWINDOWEXT: - { - Point aPos0( 0, 0 ); - sal_Int16 nWidth, nHeight; - *pStm >> nHeight >> nWidth; - rPlaceableBound.SetSize( Size( nWidth, nHeight ) ); - } - break; - - case W_META_SETMAPMODE : - *pStm >> nMapMode; - break; - - case W_META_MOVETO: - case W_META_LINETO: - GetWinExtMax( ReadYX(), rPlaceableBound, nMapMode ); - break; - - case W_META_RECTANGLE: - case W_META_INTERSECTCLIPRECT: - case W_META_EXCLUDECLIPRECT : - case W_META_ELLIPSE: - GetWinExtMax( ReadRectangle(), rPlaceableBound, nMapMode ); - break; - - case W_META_ROUNDRECT: - { - Size aSize( ReadYXExt() ); - GetWinExtMax( ReadRectangle(), rPlaceableBound, nMapMode ); - } - break; - - case W_META_ARC: - case W_META_PIE: - case W_META_CHORD: - { - Point aEnd( ReadYX() ); - Point aStart( ReadYX() ); - GetWinExtMax( ReadRectangle(), rPlaceableBound, nMapMode ); - } - break; - - case W_META_POLYGON: - { - USHORT i,nPoints; - *pStm >> nPoints; - for( i = 0; i < nPoints; i++ ) - GetWinExtMax( ReadPoint(), rPlaceableBound, nMapMode ); - } - break; - - case W_META_POLYPOLYGON: - { - USHORT i, nPoly, nPoints = 0; - *pStm >> nPoly; - for( i = 0; i < nPoly; i++ ) - { - sal_uInt16 nP; - *pStm >> nP; - nPoints = nPoints + nP; - } - for ( i = 0; i < nPoints; i++ ) - GetWinExtMax( ReadPoint(), rPlaceableBound, nMapMode ); - } - break; - - case W_META_POLYLINE: - { - USHORT i,nPoints; - *pStm >> nPoints; - for( i = 0; i < nPoints; i++ ) - GetWinExtMax( ReadPoint(), rPlaceableBound, nMapMode ); - } - break; - - case W_META_SETPIXEL: - { - const Color aColor = ReadColor(); - GetWinExtMax( ReadYX(), rPlaceableBound, nMapMode ); - } - break; - - case W_META_TEXTOUT: - { - USHORT nLength; - *pStm >> nLength; - // todo: we also have to take care of the text width - if ( nLength ) - { - pStm->SeekRel( ( nLength + 1 ) &~ 1 ); - GetWinExtMax( ReadYX(), rPlaceableBound, nMapMode ); - } - } - break; - - case W_META_EXTTEXTOUT: - { - sal_uInt16 nLen, nOptions; - sal_Int32 nRecordPos, nRecordSize; - Point aPosition; - Rectangle aRect; - - pStm->SeekRel(-6); - nRecordPos = pStm->Tell(); - *pStm >> nRecordSize; - pStm->SeekRel(2); - aPosition = ReadYX(); - *pStm >> nLen >> nOptions; - // todo: we also have to take care of the text width - if( nLen ) - GetWinExtMax( aPosition, rPlaceableBound, nMapMode ); - } - break; - case W_META_BITBLT: - case W_META_STRETCHBLT: - case W_META_DIBBITBLT: - case W_META_DIBSTRETCHBLT: - case W_META_STRETCHDIB: - { - sal_Int32 nWinROP; - sal_uInt16 nSx, nSy, nSxe, nSye, nUsage; - *pStm >> nWinROP; - - if( nFunction == W_META_STRETCHDIB ) - *pStm >> nUsage; - - // nSye and nSxe is the number of pixels that has to been used - if( nFunction == W_META_STRETCHDIB || nFunction == W_META_STRETCHBLT || nFunction == W_META_DIBSTRETCHBLT ) - *pStm >> nSye >> nSxe; - else - nSye = nSxe = 0; // set this to zero as indicator not to scale the bitmap later - - // nSy and nx is the offset of the first pixel - *pStm >> nSy >> nSx; - - if( nFunction == W_META_STRETCHDIB || nFunction == W_META_DIBBITBLT || nFunction == W_META_DIBSTRETCHBLT ) - { - if ( nWinROP == PATCOPY ) - *pStm >> nUsage; // i don't know anything of this parameter, so its called nUsage - // pOut->DrawRect( Rectangle( ReadYX(), aDestSize ), FALSE ); - - Size aDestSize( ReadYXExt() ); - if ( aDestSize.Width() && aDestSize.Height() ) // #92623# do not try to read buggy bitmaps - { - Rectangle aDestRect( ReadYX(), aDestSize ); - GetWinExtMax( aDestRect, rPlaceableBound, nMapMode ); - } - } - } - break; - - case W_META_PATBLT: - { - UINT32 nROP; - *pStm >> nROP; - Size aSize = ReadYXExt(); - GetWinExtMax( Rectangle( ReadYX(), aSize ), rPlaceableBound, nMapMode ); - } - break; - } - nPos += nRSize * 2; - if ( nPos <= nEnd ) - pStm->Seek( nPos ); - else - { - pStm->SetError( SVSTREAM_FILEFORMAT_ERROR ); - bRet = sal_False; - } - - } - } - else - { - pStm->SetError( SVSTREAM_GENERALERROR ); - bRet = sal_False; - } - return bRet; -} - -WMFReader::~WMFReader() -{ - if( pEMFStream ) - delete pEMFStream; -} - diff --git a/svtools/source/filter.vcl/wmf/wmf.cxx b/svtools/source/filter.vcl/wmf/wmf.cxx deleted file mode 100644 index 25ca9f721b33..000000000000 --- a/svtools/source/filter.vcl/wmf/wmf.cxx +++ /dev/null @@ -1,114 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#include "winmtf.hxx" -#include "emfwr.hxx" -#include "wmfwr.hxx" -#include - -// ----------------------------------------------------------------------------- - -BOOL ConvertWMFToGDIMetaFile( SvStream & rStreamWMF, GDIMetaFile & rGDIMetaFile, FilterConfigItem* pConfigItem ) -{ - UINT32 nMetaType; - UINT32 nOrgPos = rStreamWMF.Tell(); - UINT16 nOrigNumberFormat = rStreamWMF.GetNumberFormatInt(); - rStreamWMF.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); - rStreamWMF.Seek( 0x28 ); - rStreamWMF >> nMetaType; - rStreamWMF.Seek( nOrgPos ); - if ( nMetaType == 0x464d4520 ) - { - if ( EnhWMFReader( rStreamWMF, rGDIMetaFile, pConfigItem ).ReadEnhWMF() == FALSE ) - rStreamWMF.SetError( SVSTREAM_FILEFORMAT_ERROR ); - } - else - { - WMFReader( rStreamWMF, rGDIMetaFile, pConfigItem ).ReadWMF(); - } - rStreamWMF.SetNumberFormatInt( nOrigNumberFormat ); - return !rStreamWMF.GetError(); -} - -// ----------------------------------------------------------------------------- - -BOOL ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF, FilterConfigItem* pFilterConfigItem ) -{ - UINT32 nMetaType; - UINT32 nOrgPos = rStream.Tell(); - UINT16 nOrigNumberFormat = rStream.GetNumberFormatInt(); - rStream.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); - rStream.Seek( 0x28 ); - rStream >> nMetaType; - rStream.Seek( nOrgPos ); - if ( nMetaType == 0x464d4520 ) - { - if ( EnhWMFReader( rStream, rMTF, NULL ).ReadEnhWMF() == FALSE ) - rStream.SetError( SVSTREAM_FILEFORMAT_ERROR ); - } - else - { - WMFReader( rStream, rMTF, pFilterConfigItem ).ReadWMF(); - } - rStream.SetNumberFormatInt( nOrigNumberFormat ); - return !rStream.GetError(); -} - -// ----------------------------------------------------------------------------- - -BOOL ConvertGDIMetaFileToWMF( const GDIMetaFile & rMTF, SvStream & rTargetStream, - FilterConfigItem* pConfigItem, BOOL bPlaceable) -{ - WMFWriter aWMFWriter; - return aWMFWriter.WriteWMF( rMTF, rTargetStream, pConfigItem, bPlaceable ); -} - -// ----------------------------------------------------------------------------- - -BOOL ConvertGDIMetaFileToEMF( const GDIMetaFile & rMTF, SvStream & rTargetStream, - FilterConfigItem* pConfigItem ) -{ - EMFWriter aEMFWriter; - return aEMFWriter.WriteEMF( rMTF, rTargetStream, pConfigItem ); -} - -// ----------------------------------------------------------------------------- - -BOOL WriteWindowMetafile( SvStream& rStream, const GDIMetaFile& rMTF ) -{ - return WMFWriter().WriteWMF( rMTF, rStream, NULL ); -} - -// ----------------------------------------------------------------------------- - -BOOL WriteWindowMetafileBits( SvStream& rStream, const GDIMetaFile& rMTF ) -{ - return WMFWriter().WriteWMF( rMTF, rStream, NULL, FALSE ); -} diff --git a/svtools/source/filter.vcl/wmf/wmfwr.cxx b/svtools/source/filter.vcl/wmf/wmfwr.cxx deleted file mode 100644 index 4dff9732c7d0..000000000000 --- a/svtools/source/filter.vcl/wmf/wmfwr.cxx +++ /dev/null @@ -1,2096 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svtools.hxx" - -#include -#include "wmfwr.hxx" -#include -#include "emfwr.hxx" -#include -#include -#include -#include -#ifndef INCLUDED_I18NUTIL_UNICODE_HXX -#include //unicode::getUnicodeScriptType -#endif - -#include -#include -#include - -//====================== MS-Windows-defines =============================== - -#define W_META_SETBKCOLOR 0x0201 -#define W_META_SETBKMODE 0x0102 -#define W_META_SETMAPMODE 0x0103 -#define W_META_SETROP2 0x0104 -#define W_META_SETRELABS 0x0105 -#define W_META_SETPOLYFILLMODE 0x0106 -#define W_META_SETSTRETCHBLTMODE 0x0107 -#define W_META_SETTEXTCHAREXTRA 0x0108 -#define W_META_SETTEXTCOLOR 0x0209 -#define W_META_SETTEXTJUSTIFICATION 0x020A -#define W_META_SETWINDOWORG 0x020B -#define W_META_SETWINDOWEXT 0x020C -#define W_META_SETVIEWPORTORG 0x020D -#define W_META_SETVIEWPORTEXT 0x020E -#define W_META_OFFSETWINDOWORG 0x020F -#define W_META_SCALEWINDOWEXT 0x0410 -#define W_META_OFFSETVIEWPORTORG 0x0211 -#define W_META_SCALEVIEWPORTEXT 0x0412 -#define W_META_LINETO 0x0213 -#define W_META_MOVETO 0x0214 -#define W_META_EXCLUDECLIPRECT 0x0415 -#define W_META_INTERSECTCLIPRECT 0x0416 -#define W_META_ARC 0x0817 -#define W_META_ELLIPSE 0x0418 -#define W_META_FLOODFILL 0x0419 -#define W_META_PIE 0x081A -#define W_META_RECTANGLE 0x041B -#define W_META_ROUNDRECT 0x061C -#define W_META_PATBLT 0x061D -#define W_META_SAVEDC 0x001E -#define W_META_SETPIXEL 0x041F -#define W_META_OFFSETCLIPRGN 0x0220 -#define W_META_TEXTOUT 0x0521 -#define W_META_BITBLT 0x0922 -#define W_META_STRETCHBLT 0x0B23 -#define W_META_POLYGON 0x0324 -#define W_META_POLYLINE 0x0325 -#define W_META_ESCAPE 0x0626 -#define W_META_RESTOREDC 0x0127 -#define W_META_FILLREGION 0x0228 -#define W_META_FRAMEREGION 0x0429 -#define W_META_INVERTREGION 0x012A -#define W_META_PAINTREGION 0x012B -#define W_META_SELECTCLIPREGION 0x012C -#define W_META_SELECTOBJECT 0x012D -#define W_META_SETTEXTALIGN 0x012E -#define W_META_DRAWTEXT 0x062F -#define W_META_CHORD 0x0830 -#define W_META_SETMAPPERFLAGS 0x0231 -#define W_META_EXTTEXTOUT 0x0a32 -#define W_META_SETDIBTODEV 0x0d33 -#define W_META_SELECTPALETTE 0x0234 -#define W_META_REALIZEPALETTE 0x0035 -#define W_META_ANIMATEPALETTE 0x0436 -#define W_META_SETPALENTRIES 0x0037 -#define W_META_POLYPOLYGON 0x0538 -#define W_META_RESIZEPALETTE 0x0139 -#define W_META_DIBBITBLT 0x0940 -#define W_META_DIBSTRETCHBLT 0x0b41 -#define W_META_DIBCREATEPATTERNBRUSH 0x0142 -#define W_META_STRETCHDIB 0x0f43 -#define W_META_EXTFLOODFILL 0x0548 -#define W_META_RESETDC 0x014C -#define W_META_STARTDOC 0x014D -#define W_META_STARTPAGE 0x004F -#define W_META_ENDPAGE 0x0050 -#define W_META_ABORTDOC 0x0052 -#define W_META_ENDDOC 0x005E -#define W_META_DELETEOBJECT 0x01f0 -#define W_META_CREATEPALETTE 0x00f7 -#define W_META_CREATEBRUSH 0x00F8 -#define W_META_CREATEPATTERNBRUSH 0x01F9 -#define W_META_CREATEPENINDIRECT 0x02FA -#define W_META_CREATEFONTINDIRECT 0x02FB -#define W_META_CREATEBRUSHINDIRECT 0x02FC -#define W_META_CREATEBITMAPINDIRECT 0x02FD -#define W_META_CREATEBITMAP 0x06FE -#define W_META_CREATEREGION 0x06FF - -#define W_TRANSPARENT 1 -#define W_OPAQUE 2 - -#define W_R2_BLACK 1 -#define W_R2_NOTMERGEPEN 2 -#define W_R2_MASKNOTPEN 3 -#define W_R2_NOTCOPYPEN 4 -#define W_R2_MASKPENNOT 5 -#define W_R2_NOT 6 -#define W_R2_XORPEN 7 -#define W_R2_NOTMASKPEN 8 -#define W_R2_MASKPEN 9 -#define W_R2_NOTXORPEN 10 -#define W_R2_NOP 11 -#define W_R2_MERGENOTPEN 12 -#define W_R2_COPYPEN 13 -#define W_R2_MERGEPENNOT 14 -#define W_R2_MERGEPEN 15 -#define W_R2_WHITE 16 - -#define W_TA_NOUPDATECP 0x0000 -#define W_TA_UPDATECP 0x0001 -#define W_TA_LEFT 0x0000 -#define W_TA_RIGHT 0x0002 -#define W_TA_CENTER 0x0006 -#define W_TA_TOP 0x0000 -#define W_TA_BOTTOM 0x0008 -#define W_TA_BASELINE 0x0018 -#define W_TA_RTLREADING 0x0100 - -#define W_SRCCOPY 0x00CC0020L -#define W_SRCPAINT 0x00EE0086L -#define W_SRCAND 0x008800C6L -#define W_SRCINVERT 0x00660046L -#define W_SRCERASE 0x00440328L -#define W_NOTSRCCOPY 0x00330008L -#define W_NOTSRCERASE 0x001100A6L -#define W_MERGECOPY 0x00C000CAL -#define W_MERGEPAINT 0x00BB0226L -#define W_PATCOPY 0x00F00021L -#define W_PATPAINT 0x00FB0A09L -#define W_PATINVERT 0x005A0049L -#define W_DSTINVERT 0x00550009L -#define W_BLACKNESS 0x00000042L -#define W_WHITENESS 0x00FF0062L - -#define W_PS_SOLID 0 -#define W_PS_DASH 1 -#define W_PS_DOT 2 -#define W_PS_DASHDOT 3 -#define W_PS_DASHDOTDOT 4 -#define W_PS_NULL 5 -#define W_PS_INSIDEFRAME 6 - -#define W_LF_FACESIZE 32 - -#define W_ANSI_CHARSET 0 -#define W_DEFAULT_CHARSET 1 -#define W_SYMBOL_CHARSET 2 -#define W_SHIFTJIS_CHARSET 128 -#define W_HANGEUL_CHARSET 129 -#define W_GB2312_CHARSET 134 -#define W_CHINESEBIG5_CHARSET 136 -#define W_OEM_CHARSET 255 -/*WINVER >= 0x0400*/ -#define W_JOHAB_CHARSET 130 -#define W_HEBREW_CHARSET 177 -#define W_ARABIC_CHARSET 178 -#define W_GREEK_CHARSET 161 -#define W_TURKISH_CHARSET 162 -#define W_VIETNAMESE_CHARSET 163 -#define W_THAI_CHARSET 222 -#define W_EASTEUROPE_CHARSET 238 -#define W_RUSSIAN_CHARSET 204 -#define W_MAC_CHARSET 77 -#define W_BALTIC_CHARSET 186 - -#define W_DEFAULT_PITCH 0x00 -#define W_FIXED_PITCH 0x01 -#define W_VARIABLE_PITCH 0x02 - -#define W_FF_DONTCARE 0x00 -#define W_FF_ROMAN 0x10 -#define W_FF_SWISS 0x20 -#define W_FF_MODERN 0x30 -#define W_FF_SCRIPT 0x40 -#define W_FF_DECORATIVE 0x50 - -#define W_FW_DONTCARE 0 -#define W_FW_THIN 100 -#define W_FW_EXTRALIGHT 200 -#define W_FW_LIGHT 300 -#define W_FW_NORMAL 400 -#define W_FW_MEDIUM 500 -#define W_FW_SEMIBOLD 600 -#define W_FW_BOLD 700 -#define W_FW_EXTRABOLD 800 -#define W_FW_HEAVY 900 -#define W_FW_ULTRALIGHT 200 -#define W_FW_REGULAR 400 -#define W_FW_DEMIBOLD 600 -#define W_FW_ULTRABOLD 800 -#define W_FW_BLACK 900 - -#define W_BS_SOLID 0 -#define W_BS_HOLLOW 1 -#define W_BS_HATCHED 2 -#define W_BS_PATTERN 3 -#define W_BS_INDEXED 4 -#define W_BS_DIBPATTERN 5 - -#define W_HS_HORIZONTAL 0 -#define W_HS_VERTICAL 1 -#define W_HS_FDIAGONAL 2 -#define W_HS_BDIAGONAL 3 -#define W_HS_CROSS 4 -#define W_HS_DIAGCROSS 5 - -#define W_MFCOMMENT 15 - -#define PRIVATE_ESCAPE_UNICODE 2 - -/// copied from writerwordglue.cxx - -/* - Utility to categorize unicode characters into the best fit windows charset - range for exporting to ww6, or as a hint to non \u unicode token aware rtf - readers -*/ -rtl_TextEncoding getScriptClass(sal_Unicode cChar) -{ - using namespace com::sun::star::i18n; - - static ScriptTypeList aScripts[] = - { - { UnicodeScript_kBasicLatin, UnicodeScript_kBasicLatin, RTL_TEXTENCODING_MS_1252}, - { UnicodeScript_kLatin1Supplement, UnicodeScript_kLatin1Supplement, RTL_TEXTENCODING_MS_1252}, - { UnicodeScript_kLatinExtendedA, UnicodeScript_kLatinExtendedA, RTL_TEXTENCODING_MS_1250}, - { UnicodeScript_kLatinExtendedB, UnicodeScript_kLatinExtendedB, RTL_TEXTENCODING_MS_1257}, - { UnicodeScript_kGreek, UnicodeScript_kGreek, RTL_TEXTENCODING_MS_1253}, - { UnicodeScript_kCyrillic, UnicodeScript_kCyrillic, RTL_TEXTENCODING_MS_1251}, - { UnicodeScript_kHebrew, UnicodeScript_kHebrew, RTL_TEXTENCODING_MS_1255}, - { UnicodeScript_kArabic, UnicodeScript_kArabic, RTL_TEXTENCODING_MS_1256}, - { UnicodeScript_kThai, UnicodeScript_kThai, RTL_TEXTENCODING_MS_1258}, - { UnicodeScript_kScriptCount, UnicodeScript_kScriptCount, RTL_TEXTENCODING_MS_1252} - }; - return unicode::getUnicodeScriptType(cChar, aScripts, - RTL_TEXTENCODING_MS_1252); -} - -//========================== Methoden von WMFWriter ========================== - -void WMFWriter::MayCallback() -{ - if ( xStatusIndicator.is() ) - { - ULONG nPercent; - - // Wir gehen mal einfach so davon aus, dass 16386 Actions einer Bitmap entsprechen - // (in der Regel wird ein Metafile entweder nur Actions oder einige Bitmaps und fast - // keine Actions enthalten. Dann ist das Verhaeltnis ziemlich unwichtig) - - nPercent=((nWrittenBitmaps<<14)+(nActBitmapPercent<<14)/100+nWrittenActions) - *100 - /((nNumberOfBitmaps<<14)+nNumberOfActions); - - if ( nPercent >= nLastPercent + 3 ) - { - nLastPercent = nPercent; - if( nPercent <= 100 ) - xStatusIndicator->setValue( nPercent ); - } - } -} - -void WMFWriter::CountActionsAndBitmaps( const GDIMetaFile & rMTF ) -{ - ULONG nAction, nActionCount; - - nActionCount = rMTF.GetActionCount(); - - for ( nAction=0; nActionGetType() ) - { - case META_BMP_ACTION: - case META_BMPSCALE_ACTION: - case META_BMPSCALEPART_ACTION: - case META_BMPEX_ACTION: - case META_BMPEXSCALE_ACTION: - case META_BMPEXSCALEPART_ACTION: - nNumberOfBitmaps++; - break; - } - nNumberOfActions++; - } -} - - -void WMFWriter::WritePointXY(const Point & rPoint) -{ - Point aPt( pVirDev->LogicToLogic(rPoint,aSrcMapMode,aTargetMapMode) ); - *pWMF << ((short)aPt.X()) << ((short)aPt.Y()); -} - - -void WMFWriter::WritePointYX(const Point & rPoint) -{ - Point aPt( pVirDev->LogicToLogic(rPoint,aSrcMapMode,aTargetMapMode) ); - *pWMF << ((short)aPt.Y()) << ((short)aPt.X()); -} - - -sal_Int32 WMFWriter::ScaleWidth( sal_Int32 nDX ) -{ - Size aSz( pVirDev->LogicToLogic(Size(nDX,0),aSrcMapMode,aTargetMapMode) ); - return aSz.Width(); -} - - -void WMFWriter::WriteSize(const Size & rSize) -{ - Size aSz( pVirDev->LogicToLogic(rSize,aSrcMapMode,aTargetMapMode) ); - *pWMF << ((short)aSz.Width()) << ((short)aSz.Height()); -} - - -void WMFWriter::WriteHeightWidth(const Size & rSize) -{ - Size aSz( pVirDev->LogicToLogic(rSize,aSrcMapMode,aTargetMapMode) ); - *pWMF << ((short)aSz.Height()) << ((short)aSz.Width()); -} - - -void WMFWriter::WriteRectangle(const Rectangle & rRect) -{ - WritePointYX(Point(rRect.Right()+1,rRect.Bottom()+1)); - WritePointYX(rRect.TopLeft()); -} - - -void WMFWriter::WriteColor(const Color & rColor) -{ - *pWMF << (BYTE) rColor.GetRed() << (BYTE) rColor.GetGreen() << (BYTE) rColor.GetBlue() << (BYTE) 0; -} - - -void WMFWriter::WriteRecordHeader(sal_uInt32 nSizeWords, sal_uInt16 nType) -{ - nActRecordPos=pWMF->Tell(); - if (nSizeWords>nMaxRecordSize) nMaxRecordSize=nSizeWords; - *pWMF << nSizeWords << nType; -} - - -void WMFWriter::UpdateRecordHeader() -{ - ULONG nPos; - sal_uInt32 nSize; - - nPos=pWMF->Tell(); nSize=nPos-nActRecordPos; - if ((nSize & 1)!=0) { - *pWMF << (BYTE)0; - nPos++; nSize++; - } - nSize/=2; - if (nSize>nMaxRecordSize) nMaxRecordSize=nSize; - pWMF->Seek(nActRecordPos); - *pWMF << nSize; - pWMF->Seek(nPos); -} - - -void WMFWriter::WMFRecord_Arc(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt) -{ - WriteRecordHeader(0x0000000b,W_META_ARC); - WritePointYX(rEndPt); - WritePointYX(rStartPt); - WriteRectangle(rRect); -} - -void WMFWriter::WMFRecord_Chord(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt) -{ - WriteRecordHeader(0x0000000b,W_META_CHORD); - WritePointYX(rEndPt); - WritePointYX(rStartPt); - WriteRectangle(rRect); -} - - -void WMFWriter::WMFRecord_CreateBrushIndirect(const Color& rColor) -{ - WriteRecordHeader(0x00000007,W_META_CREATEBRUSHINDIRECT); - - if( rColor==Color(COL_TRANSPARENT) ) - *pWMF << (UINT16) W_BS_HOLLOW; - else - *pWMF << (UINT16) W_BS_SOLID; - - WriteColor( rColor ); - *pWMF << (UINT16) 0; -} - - -void WMFWriter::WMFRecord_CreateFontIndirect(const Font & rFont) -{ - USHORT nWeight,i; - BYTE nPitchFamily; - - WriteRecordHeader(0x00000000,W_META_CREATEFONTINDIRECT); - WriteHeightWidth(Size(rFont.GetSize().Width(),-rFont.GetSize().Height())); - *pWMF << (short)rFont.GetOrientation() << (short)rFont.GetOrientation(); - - switch (rFont.GetWeight()) { - case WEIGHT_THIN: nWeight=W_FW_THIN; break; - case WEIGHT_ULTRALIGHT: nWeight=W_FW_ULTRALIGHT; break; - case WEIGHT_LIGHT: nWeight=W_FW_LIGHT; break; - case WEIGHT_SEMILIGHT: nWeight=W_FW_LIGHT; break; - case WEIGHT_NORMAL: nWeight=W_FW_NORMAL; break; - case WEIGHT_MEDIUM: nWeight=W_FW_MEDIUM; break; - case WEIGHT_SEMIBOLD: nWeight=W_FW_SEMIBOLD; break; - case WEIGHT_BOLD: nWeight=W_FW_BOLD; break; - case WEIGHT_ULTRABOLD: nWeight=W_FW_ULTRABOLD; break; - case WEIGHT_BLACK: nWeight=W_FW_BLACK; break; - default: nWeight=W_FW_DONTCARE; - } - *pWMF << nWeight; - - if (rFont.GetItalic()==ITALIC_NONE) *pWMF << (BYTE)0; else *pWMF << (BYTE)1; - if (rFont.GetUnderline()==UNDERLINE_NONE) *pWMF << (BYTE)0; else *pWMF << (BYTE)1; - if (rFont.GetStrikeout()==STRIKEOUT_NONE) *pWMF << (BYTE)0; else *pWMF << (BYTE)1; - - CharSet eFontNameEncoding = rFont.GetCharSet(); - sal_uInt8 nCharSet = rtl_getBestWindowsCharsetFromTextEncoding( eFontNameEncoding ); - if ( eFontNameEncoding == RTL_TEXTENCODING_SYMBOL ) - eFontNameEncoding = RTL_TEXTENCODING_MS_1252; - if ( nCharSet == 1 ) - nCharSet = W_ANSI_CHARSET; - *pWMF << nCharSet; - - *pWMF << (BYTE)0 << (BYTE)0 << (BYTE)0; - - switch (rFont.GetPitch()) { - case PITCH_FIXED: nPitchFamily=W_FIXED_PITCH; break; - case PITCH_VARIABLE: nPitchFamily=W_VARIABLE_PITCH; break; - default: nPitchFamily=W_DEFAULT_PITCH; - } - switch (rFont.GetFamily()) { - case FAMILY_DECORATIVE: nPitchFamily|=W_FF_DECORATIVE; break; - case FAMILY_MODERN: nPitchFamily|=W_FF_MODERN; break; - case FAMILY_ROMAN: nPitchFamily|=W_FF_ROMAN; break; - case FAMILY_SCRIPT: nPitchFamily|=W_FF_SCRIPT; break; - case FAMILY_SWISS: nPitchFamily|=W_FF_SWISS; break; - default: nPitchFamily|=W_FF_DONTCARE; - } - *pWMF << nPitchFamily; - - ByteString aFontName( rFont.GetName(), eFontNameEncoding ); - for ( i = 0; i < W_LF_FACESIZE; i++ ) - { - sal_Char nChar = ( i < aFontName.Len() ) ? aFontName.GetChar( i ) : 0; - *pWMF << nChar; - } - UpdateRecordHeader(); -} - -void WMFWriter::WMFRecord_CreatePenIndirect(const Color& rColor, const LineInfo& rLineInfo ) -{ - WriteRecordHeader(0x00000008,W_META_CREATEPENINDIRECT); - USHORT nStyle = rColor == Color( COL_TRANSPARENT ) ? W_PS_NULL : W_PS_SOLID; - switch( rLineInfo.GetStyle() ) - { - case LINE_DASH : - { - if ( rLineInfo.GetDotCount() ) - { - if ( !rLineInfo.GetDashCount() ) - nStyle = W_PS_DOT; - else - { - if ( !rLineInfo.GetDotCount() == 1 ) - nStyle = W_PS_DASHDOT; - else - nStyle = W_PS_DASHDOTDOT; - } - } - else - nStyle = W_PS_DASH; - } - break; - case LINE_NONE : - nStyle = W_PS_NULL; - break; - default: - break; - } - *pWMF << nStyle; - - WriteSize( Size( rLineInfo.GetWidth(), 0 ) ); - WriteColor( rColor ); -} - -void WMFWriter::WMFRecord_DeleteObject(USHORT nObjectHandle) -{ - WriteRecordHeader(0x00000004,W_META_DELETEOBJECT); - *pWMF << nObjectHandle; -} - - -void WMFWriter::WMFRecord_Ellipse(const Rectangle & rRect) -{ - WriteRecordHeader(0x00000007,W_META_ELLIPSE); - WriteRectangle(rRect); -} - -bool IsStarSymbol(const String &rStr) -{ - return rStr.EqualsIgnoreCaseAscii("starsymbol") || - rStr.EqualsIgnoreCaseAscii("opensymbol"); -} - -void WMFWriter::WMFRecord_Escape( sal_uInt32 nEsc, sal_uInt32 nLen, const sal_Int8* pData ) -{ -#ifdef OSL_BIGENDIAN - sal_uInt32 nTmp = SWAPLONG( nEsc ); - sal_uInt32 nCheckSum = rtl_crc32( 0, &nTmp, 4 ); -#else - sal_uInt32 nCheckSum = rtl_crc32( 0, &nEsc, 4 ); -#endif - if ( nLen ) - nCheckSum = rtl_crc32( nCheckSum, pData, nLen ); - - WriteRecordHeader( 3 + 9 + ( ( nLen + 1 ) >> 1 ), W_META_ESCAPE ); - *pWMF << (sal_uInt16)W_MFCOMMENT - << (sal_uInt16)( nLen + 14 ) // we will always have a fourteen byte escape header: - << (sal_uInt16)0x4f4f // OO - << (sal_uInt32)0xa2c2a // evil magic number - << (sal_uInt32)nCheckSum // crc32 checksum about nEsc & pData - << (sal_uInt32)nEsc; // escape number - pWMF->Write( pData, nLen ); - if ( nLen & 1 ) - *pWMF << (sal_uInt8)0; // pad byte -} - -/* if return value is true, then a complete unicode string and also a polygon replacement has been written, - so there is no more action necessary -*/ -sal_Bool WMFWriter::WMFRecord_Escape_Unicode( const Point& rPoint, const String& rUniStr, const sal_Int32* pDXAry ) -{ - sal_Bool bEscapeUsed = sal_False; - - sal_uInt32 i, nStringLen = rUniStr.Len(); - if ( nStringLen ) - { - // first we will check if a comment is necessary - if ( aSrcFont.GetCharSet() != RTL_TEXTENCODING_SYMBOL ) // symbol is always byte character, so there is no unicode loss - { - const sal_Unicode* pBuf = rUniStr.GetBuffer(); - const rtl_TextEncoding aTextEncodingOrg = aSrcFont.GetCharSet(); - ByteString aByteStr( rUniStr, aTextEncodingOrg ); - String aUniStr2( aByteStr, aTextEncodingOrg ); - const sal_Unicode* pConversion = aUniStr2.GetBuffer(); // this is the unicode array after bytestring <-> unistring conversion - for ( i = 0; i < nStringLen; i++ ) - { - if ( *pBuf++ != *pConversion++ ) - break; - } - - if ( i != nStringLen ) // after conversion the characters are not original, - { // try again, with determining a better charset from unicode char - pBuf = rUniStr.GetBuffer(); - const sal_Unicode* pCheckChar = pBuf; - rtl_TextEncoding aTextEncoding = getScriptClass (*pCheckChar); // try the first character - for ( i = 1; i < nStringLen; i++) - { - if (aTextEncoding != aTextEncodingOrg) // found something - break; - pCheckChar++; - aTextEncoding = getScriptClass (*pCheckChar); // try the next character - } - - aByteStr = ByteString ( rUniStr, aTextEncoding ); - aUniStr2 = String ( aByteStr, aTextEncoding ); - pConversion = aUniStr2.GetBuffer(); // this is the unicode array after bytestring <-> unistring conversion - for ( i = 0; i < nStringLen; i++ ) - { - if ( *pBuf++ != *pConversion++ ) - break; - } - if (i == nStringLen) - { - aSrcFont.SetCharSet (aTextEncoding); - SetAllAttr(); - } - } - - if ( ( i != nStringLen ) || IsStarSymbol( aSrcFont.GetName() ) ) // after conversion the characters are not original, so we - { // will store the unicode string and a polypoly replacement - Color aOldFillColor( aSrcFillColor ); - Color aOldLineColor( aSrcLineColor ); - aSrcLineInfo = LineInfo(); - aSrcFillColor = aSrcTextColor; - aSrcLineColor = Color( COL_TRANSPARENT ); - SetLineAndFillAttr(); - pVirDev->SetFont( aSrcFont ); - std::vector aPolyPolyVec; - if ( pVirDev->GetTextOutlines( aPolyPolyVec, rUniStr ) ) - { - sal_uInt32 nDXCount = pDXAry ? nStringLen : 0; - sal_uInt32 nSkipActions = aPolyPolyVec.size(); - sal_Int32 nStrmLen = 8 + - + sizeof( nStringLen ) + ( nStringLen * 2 ) - + sizeof( nDXCount ) + ( nDXCount * 4 ) - + sizeof( nSkipActions ); - - SvMemoryStream aMemoryStream( nStrmLen ); - Point aPt( pVirDev->LogicToLogic( rPoint, aSrcMapMode, aTargetMapMode ) ); - aMemoryStream << aPt.X() - << aPt.Y() - << nStringLen; - for ( i = 0; i < nStringLen; i++ ) - aMemoryStream << rUniStr.GetChar( (sal_uInt16)i ); - aMemoryStream << nDXCount; - for ( i = 0; i < nDXCount; i++ ) - aMemoryStream << pDXAry[ i ]; - aMemoryStream << nSkipActions; - WMFRecord_Escape( PRIVATE_ESCAPE_UNICODE, nStrmLen, (const sal_Int8*)aMemoryStream.GetData() ); - - std::vector::iterator aIter( aPolyPolyVec.begin() ); - while ( aIter != aPolyPolyVec.end() ) - { - PolyPolygon aPolyPoly( *aIter++ ); - aPolyPoly.Move( rPoint.X(), rPoint.Y() ); - WMFRecord_PolyPolygon( aPolyPoly ); - } - aSrcFillColor = aOldFillColor; - aSrcLineColor = aOldLineColor; - bEscapeUsed = sal_True; - } - } - } - } - return bEscapeUsed; -} - -void WMFWriter::WMFRecord_ExtTextOut( const Point & rPoint, - const String & rString, const sal_Int32 * pDXAry ) -{ - sal_uInt16 nOriginalTextLen = rString.Len(); - - if ( (nOriginalTextLen <= 1) || (pDXAry == NULL) ) - { - WMFRecord_TextOut(rPoint, rString); - return; - } - rtl_TextEncoding eChrSet = aSrcFont.GetCharSet(); - ByteString aByteString(rString, eChrSet); - TrueExtTextOut(rPoint,rString,aByteString,pDXAry); -} - -void WMFWriter::TrueExtTextOut( const Point & rPoint, const String & rString, - const ByteString & rByteString, const sal_Int32 * pDXAry ) -{ - WriteRecordHeader( 0, W_META_EXTTEXTOUT ); - WritePointYX( rPoint ); - sal_uInt16 nNewTextLen = rByteString.Len(); - *pWMF << nNewTextLen << (sal_uInt16)0; - - sal_uInt16 i; - for ( i = 0; i < nNewTextLen; i++ ) - *pWMF << (sal_uInt8)rByteString.GetChar( i ); - if ( nNewTextLen & 1 ) - *pWMF << (sal_uInt8)0; - - sal_uInt16 nOriginalTextLen = rString.Len(); - sal_Int16* pConvertedDXAry = new sal_Int16[ nOriginalTextLen ]; - sal_Int32 j = 0; - pConvertedDXAry[ j++ ] = (sal_Int16)ScaleWidth( pDXAry[ 0 ] ); - for ( i = 1; i < ( nOriginalTextLen - 1 ); i++ ) - pConvertedDXAry[ j++ ] = (sal_Int16)ScaleWidth( pDXAry[ i ] - pDXAry[ i - 1 ] ); - pConvertedDXAry[ j ] = (sal_Int16)ScaleWidth( pDXAry[ nOriginalTextLen - 2 ] / ( nOriginalTextLen - 1 ) ); - - for ( i = 0; i < nOriginalTextLen; i++ ) - { - sal_Int16 nDx = pConvertedDXAry[ i ]; - *pWMF << nDx; - if ( nOriginalTextLen < nNewTextLen ) - { - ByteString aTemp( rString.GetChar( i ), aSrcFont.GetCharSet()); - j = aTemp.Len(); - while ( --j > 0 ) - *pWMF << (sal_uInt16)0; - } - } - delete[] pConvertedDXAry; - UpdateRecordHeader(); -} - -void WMFWriter::WMFRecord_LineTo(const Point & rPoint) -{ - WriteRecordHeader(0x00000005,W_META_LINETO); - WritePointYX(rPoint); -} - - -void WMFWriter::WMFRecord_MoveTo(const Point & rPoint) -{ - WriteRecordHeader(0x00000005,W_META_MOVETO); - WritePointYX(rPoint); -} - - -void WMFWriter::WMFRecord_Pie(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt) -{ - WriteRecordHeader(0x0000000b,W_META_PIE); - WritePointYX(rEndPt); - WritePointYX(rStartPt); - WriteRectangle(rRect); -} - - -void WMFWriter::WMFRecord_Polygon(const Polygon & rPoly) -{ - USHORT nSize,i; - - Polygon aSimplePoly; - if ( rPoly.HasFlags() ) - rPoly.AdaptiveSubdivide( aSimplePoly ); - else - aSimplePoly = rPoly; - nSize = aSimplePoly.GetSize(); - WriteRecordHeader(((ULONG)nSize)*2+4,W_META_POLYGON); - *pWMF << nSize; - for (i=0; iGetSize(); - for (j=0; jGetPoint(j)); - } - UpdateRecordHeader(); -} - - -void WMFWriter::WMFRecord_Rectangle(const Rectangle & rRect) -{ - WriteRecordHeader( 0x00000007,W_META_RECTANGLE ); - WriteRectangle( rRect ); -} - - -void WMFWriter::WMFRecord_RestoreDC() -{ - WriteRecordHeader(0x00000004,W_META_RESTOREDC); - *pWMF << (short)-1; -} - - -void WMFWriter::WMFRecord_RoundRect(const Rectangle & rRect, long nHorzRound, long nVertRound) -{ - WriteRecordHeader(0x00000009,W_META_ROUNDRECT); - WriteHeightWidth(Size(nHorzRound,nVertRound)); - WriteRectangle(rRect); -} - - -void WMFWriter::WMFRecord_SaveDC() -{ - WriteRecordHeader(0x00000003,W_META_SAVEDC); -} - - -void WMFWriter::WMFRecord_SelectObject(USHORT nObjectHandle) -{ - WriteRecordHeader(0x00000004,W_META_SELECTOBJECT); - *pWMF << nObjectHandle; -} - - -void WMFWriter::WMFRecord_SetBkColor(const Color & rColor) -{ - WriteRecordHeader(0x00000005,W_META_SETBKCOLOR); - WriteColor(rColor); -} - - -void WMFWriter::WMFRecord_SetBkMode(BOOL bTransparent) -{ - WriteRecordHeader(0x00000004,W_META_SETBKMODE); - if (bTransparent==TRUE) *pWMF << (USHORT)W_TRANSPARENT; - else *pWMF << (USHORT)W_OPAQUE; -} - -void WMFWriter::WMFRecord_SetStretchBltMode() -{ - WriteRecordHeader( 0x00000004, W_META_SETSTRETCHBLTMODE ); - *pWMF << (USHORT) 3; // STRETCH_DELETESCANS -} - -void WMFWriter::WMFRecord_SetPixel(const Point & rPoint, const Color & rColor) -{ - WriteRecordHeader(0x00000007,W_META_SETPIXEL); - WriteColor(rColor); - WritePointYX(rPoint); -} - - -void WMFWriter::WMFRecord_SetROP2(RasterOp eROP) -{ - USHORT nROP2; - - switch (eROP) { - case ROP_INVERT: nROP2=W_R2_NOT; break; - case ROP_XOR: nROP2=W_R2_XORPEN; break; - default: nROP2=W_R2_COPYPEN; - } - WriteRecordHeader(0x00000004,W_META_SETROP2); - *pWMF << nROP2; -} - - -void WMFWriter::WMFRecord_SetTextAlign(FontAlign eFontAlign, UINT32 eHorTextAlign) -{ - USHORT nAlign; - - switch (eFontAlign) { - case ALIGN_TOP: nAlign=W_TA_TOP; break; - case ALIGN_BOTTOM: nAlign=W_TA_BOTTOM; break; - default: nAlign=W_TA_BASELINE; - } - nAlign|=eHorTextAlign; - nAlign|=W_TA_NOUPDATECP; - - WriteRecordHeader(0x00000004,W_META_SETTEXTALIGN); - *pWMF << nAlign; -} - - -void WMFWriter::WMFRecord_SetTextColor(const Color & rColor) -{ - WriteRecordHeader(0x00000005,W_META_SETTEXTCOLOR); - WriteColor(rColor); -} - - -void WMFWriter::WMFRecord_SetWindowExt(const Size & rSize) -{ - WriteRecordHeader(0x00000005,W_META_SETWINDOWEXT); - WriteHeightWidth(rSize); -} - - -void WMFWriter::WMFRecord_SetWindowOrg(const Point & rPoint) -{ - WriteRecordHeader(0x00000005,W_META_SETWINDOWORG); - WritePointYX(rPoint); -} - - -void WMFWriter::WMFRecord_StretchDIB( const Point & rPoint, const Size & rSize, - const Bitmap & rBitmap, sal_uInt32 nROP ) -{ - ULONG nPosAnf,nPosEnd; - - nActBitmapPercent=50; - MayCallback(); - - WriteRecordHeader(0x00000000,W_META_STRETCHDIB); - - // Die Reihenfolge im Metafile soll jetzt sein: - // einige Parameter (laenge 22), dann die Bitmap ohne FILEHEADER. - // Da aber *pWMF << rBitmap einen FILEHEADER der Laenge 14 - // erzeugt, schreiben wir zuerst die Bitmap an die richtige Position - // Und ueberschreiben hinterher den FILEHEADER mit den Parametern. - nPosAnf=pWMF->Tell(); // Position merken, wo Parameter hin sollen - *pWMF << (long)0 << (long)0; // 8 bytes auffuellen (diese 8 bytes + - // 14 bytes ueberfluessigen FILEHEADER - // = 22 bytes Parameter) - *pWMF << rBitmap; // Bitmap schreiben - - // Parameter schreiben: - nPosEnd=pWMF->Tell(); - pWMF->Seek(nPosAnf); - - // Raster-Op bestimmen, falls nichts uebergeben wurde - if( !nROP ) - { - switch( eSrcRasterOp ) - { - case ROP_INVERT: nROP = W_DSTINVERT; break; - case ROP_XOR: nROP = W_SRCINVERT; break; - default: nROP = W_SRCCOPY; - } - } - - *pWMF << nROP << - (short) 0 << - (short) rBitmap.GetSizePixel().Height() << - (short) rBitmap.GetSizePixel().Width() << - (short) 0 << - (short) 0; - - WriteHeightWidth(rSize); - WritePointYX(rPoint); - pWMF->Seek(nPosEnd); - - UpdateRecordHeader(); - - nWrittenBitmaps++; - nActBitmapPercent=0; -} - - -void WMFWriter::WMFRecord_TextOut(const Point & rPoint, const String & rStr) -{ - rtl_TextEncoding eChrSet = aSrcFont.GetCharSet(); - ByteString aString( rStr, eChrSet ); - TrueTextOut(rPoint, aString); -} - -void WMFWriter::TrueTextOut(const Point & rPoint, const ByteString& rString) -{ - USHORT nLen,i; - - WriteRecordHeader(0,W_META_TEXTOUT); - nLen=rString.Len(); - *pWMF << nLen; - for ( i = 0; i < nLen; i++ ) - *pWMF << (BYTE)rString.GetChar( i ); - if ((nLen&1)!=0) *pWMF << (BYTE)0; - WritePointYX(rPoint); - UpdateRecordHeader(); -} - -void WMFWriter::WMFRecord_EndOfFile() -{ - WriteRecordHeader(0x00000003,0x0000); -} - - -void WMFWriter::WMFRecord_IntersectClipRect( const Rectangle& rRect ) -{ - WriteRecordHeader( 0x00000007, W_META_INTERSECTCLIPRECT ); - WriteRectangle(rRect); -} - - -USHORT WMFWriter::AllocHandle() -{ - USHORT i; - - for (i=0; iSetFont(aSrcFont); - if ( aDstFont.GetName() != aSrcFont.GetName() ) - { - FontCharMap aFontCharMap; - if ( pVirDev->GetFontCharMap( aFontCharMap ) ) - { - if ( ( aFontCharMap.GetFirstChar() & 0xff00 ) == 0xf000 ) - aSrcFont.SetCharSet( RTL_TEXTENCODING_SYMBOL ); - else if ( aSrcFont.GetCharSet() == RTL_TEXTENCODING_SYMBOL ) - aSrcFont.SetCharSet( RTL_TEXTENCODING_MS_1252 ); - } - } - aDstFont = aSrcFont; - CreateSelectDeleteFont(aDstFont); - } -} - - -void WMFWriter::HandleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon) -{ - if(rLinePolygon.count()) - { - basegfx::B2DPolyPolygon aLinePolyPolygon(rLinePolygon); - basegfx::B2DPolyPolygon aFillPolyPolygon; - - rInfo.applyToB2DPolyPolygon(aLinePolyPolygon, aFillPolyPolygon); - - if(aLinePolyPolygon.count()) - { - aSrcLineInfo = rInfo; - SetLineAndFillAttr(); - - for(sal_uInt32 a(0); a < aLinePolyPolygon.count(); a++) - { - const basegfx::B2DPolygon aCandidate(aLinePolyPolygon.getB2DPolygon(a)); - WMFRecord_PolyLine(Polygon(aCandidate)); - } - } - - if(aFillPolyPolygon.count()) - { - const Color aOldLineColor(aSrcLineColor); - const Color aOldFillColor(aSrcFillColor); - - aSrcLineColor = Color( COL_TRANSPARENT ); - aSrcFillColor = aOldLineColor; - SetLineAndFillAttr(); - - for(sal_uInt32 a(0); a < aFillPolyPolygon.count(); a++) - { - const Polygon aPolygon(aFillPolyPolygon.getB2DPolygon(a)); - WMFRecord_Polygon(Polygon(aPolygon)); - } - - aSrcLineColor = aOldLineColor; - aSrcFillColor = aOldFillColor; - SetLineAndFillAttr(); - } - } -} - -void WMFWriter::WriteRecords( const GDIMetaFile & rMTF ) -{ - ULONG nA, nACount; - MetaAction* pMA; - - if( bStatus ) - { - nACount = rMTF.GetActionCount(); - - WMFRecord_SetStretchBltMode(); - - for( nA=0; nAGetType() ) - { - case META_PIXEL_ACTION: - { - const MetaPixelAction* pA = (const MetaPixelAction *) pMA; - aSrcLineInfo = LineInfo(); - SetLineAndFillAttr(); - WMFRecord_SetPixel( pA->GetPoint(), pA->GetColor() ); - } - break; - - case META_POINT_ACTION: - { - const MetaPointAction* pA = (const MetaPointAction*) pMA; - const Point& rPt = pA->GetPoint(); - aSrcLineInfo = LineInfo(); - SetLineAndFillAttr(); - WMFRecord_MoveTo( rPt); - WMFRecord_LineTo( rPt ); - } - break; - - case META_LINE_ACTION: - { - const MetaLineAction* pA = (const MetaLineAction *) pMA; - if(pA->GetLineInfo().IsDefault()) - { - aSrcLineInfo = pA->GetLineInfo(); - SetLineAndFillAttr(); - WMFRecord_MoveTo( pA->GetStartPoint() ); - WMFRecord_LineTo( pA->GetEndPoint() ); - } - else - { - // LineInfo used; handle Dash/Dot and fat lines - basegfx::B2DPolygon aPolygon; - aPolygon.append(basegfx::B2DPoint(pA->GetStartPoint().X(), pA->GetStartPoint().Y())); - aPolygon.append(basegfx::B2DPoint(pA->GetEndPoint().X(), pA->GetEndPoint().Y())); - HandleLineInfoPolyPolygons(pA->GetLineInfo(), aPolygon); - } - } - break; - - case META_RECT_ACTION: - { - const MetaRectAction* pA = (const MetaRectAction*) pMA; - aSrcLineInfo = LineInfo(); - SetLineAndFillAttr(); - WMFRecord_Rectangle( pA->GetRect() ); - } - break; - - case META_ROUNDRECT_ACTION: - { - const MetaRoundRectAction* pA = (const MetaRoundRectAction*) pMA; - aSrcLineInfo = LineInfo(); - SetLineAndFillAttr(); - WMFRecord_RoundRect( pA->GetRect(), pA->GetHorzRound(), pA->GetVertRound() ); - } - break; - - case META_ELLIPSE_ACTION: - { - const MetaEllipseAction* pA = (const MetaEllipseAction*) pMA; - aSrcLineInfo = LineInfo(); - SetLineAndFillAttr(); - WMFRecord_Ellipse( pA->GetRect() ); - } - break; - - case META_ARC_ACTION: - { - const MetaArcAction* pA = (const MetaArcAction*) pMA; - aSrcLineInfo = LineInfo(); - SetLineAndFillAttr(); - WMFRecord_Arc( pA->GetRect(),pA->GetStartPoint(),pA->GetEndPoint() ); - } - break; - - case META_PIE_ACTION: - { - const MetaPieAction* pA = (const MetaPieAction*) pMA; - aSrcLineInfo = LineInfo(); - SetLineAndFillAttr(); - WMFRecord_Pie( pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint() ); - } - break; - - - case META_CHORD_ACTION: - { - const MetaChordAction* pA = (const MetaChordAction*) pMA; - aSrcLineInfo = LineInfo(); - SetLineAndFillAttr(); - WMFRecord_Chord( pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint() ); - } - break; - - case META_POLYLINE_ACTION: - { - const MetaPolyLineAction* pA = (const MetaPolyLineAction*) pMA; - const Polygon& rPoly = pA->GetPolygon(); - - if( rPoly.GetSize() ) - { - if(pA->GetLineInfo().IsDefault()) - { - aSrcLineInfo = pA->GetLineInfo(); - SetLineAndFillAttr(); - WMFRecord_PolyLine( rPoly ); - } - else - { - // LineInfo used; handle Dash/Dot and fat lines - HandleLineInfoPolyPolygons(pA->GetLineInfo(), rPoly.getB2DPolygon()); - } - } - } - break; - - case META_POLYGON_ACTION: - { - const MetaPolygonAction* pA = (const MetaPolygonAction*) pMA; - aSrcLineInfo = LineInfo(); - SetLineAndFillAttr(); - WMFRecord_Polygon( pA->GetPolygon() ); - } - break; - - case META_POLYPOLYGON_ACTION: - { - const MetaPolyPolygonAction* pA = (const MetaPolyPolygonAction*) pMA; - aSrcLineInfo = LineInfo(); - SetLineAndFillAttr(); - WMFRecord_PolyPolygon( pA->GetPolyPolygon() ); - } - break; - - case META_TEXTRECT_ACTION: - { - const MetaTextRectAction * pA = (const MetaTextRectAction*)pMA; - String aTemp( pA->GetText() ); - aSrcLineInfo = LineInfo(); - SetAllAttr(); - - Point aPos( pA->GetRect().TopLeft() ); - if ( !WMFRecord_Escape_Unicode( aPos, aTemp, NULL ) ) - WMFRecord_TextOut( aPos, aTemp ); - } - break; - - case META_TEXT_ACTION: - { - const MetaTextAction * pA = (const MetaTextAction*) pMA; - String aTemp( pA->GetText(), pA->GetIndex(), pA->GetLen() ); - aSrcLineInfo = LineInfo(); - SetAllAttr(); - if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, NULL ) ) - WMFRecord_TextOut( pA->GetPoint(), aTemp ); - } - break; - - case META_TEXTARRAY_ACTION: - { - const MetaTextArrayAction* pA = (const MetaTextArrayAction*) pMA; - - String aTemp( pA->GetText(), pA->GetIndex(), pA->GetLen() ); - aSrcLineInfo = LineInfo(); - SetAllAttr(); - if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, pA->GetDXArray() ) ) - WMFRecord_ExtTextOut( pA->GetPoint(), aTemp, pA->GetDXArray() ); - } - break; - - case META_STRETCHTEXT_ACTION: - { - const MetaStretchTextAction* pA = (const MetaStretchTextAction *) pMA; - String aTemp( pA->GetText(), pA->GetIndex(), pA->GetLen() ); - - sal_uInt16 nLen,i; - sal_Int32 nNormSize; - - pVirDev->SetFont( aSrcFont ); - nLen = aTemp.Len(); - sal_Int32* pDXAry = nLen ? new sal_Int32[ nLen ] : NULL; - nNormSize = pVirDev->GetTextArray( aTemp, pDXAry ); - for ( i = 0; i < ( nLen - 1 ); i++ ) - pDXAry[ i ] = pDXAry[ i ] * (sal_Int32)pA->GetWidth() / nNormSize; - if ( ( nLen <= 1 ) || ( (sal_Int32)pA->GetWidth() == nNormSize ) ) - delete[] pDXAry, pDXAry = NULL; - aSrcLineInfo = LineInfo(); - SetAllAttr(); - if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, pDXAry ) ) - WMFRecord_ExtTextOut( pA->GetPoint(), aTemp, pDXAry ); - delete[] pDXAry; - } - break; - - case META_BMP_ACTION: - { - const MetaBmpAction* pA = (const MetaBmpAction *) pMA; - WMFRecord_StretchDIB( pA->GetPoint(), pA->GetBitmap().GetSizePixel(), pA->GetBitmap() ); - } - break; - - case META_BMPSCALE_ACTION: - { - const MetaBmpScaleAction* pA = (const MetaBmpScaleAction*) pMA; - WMFRecord_StretchDIB( pA->GetPoint(), pA->GetSize(), pA->GetBitmap() ); - } - break; - - case META_BMPSCALEPART_ACTION: - { - const MetaBmpScalePartAction* pA = (const MetaBmpScalePartAction*) pMA; - Bitmap aTmp( pA->GetBitmap() ); - - if( aTmp.Crop( Rectangle( pA->GetSrcPoint(), pA->GetSrcSize() ) ) ) - WMFRecord_StretchDIB( pA->GetDestPoint(), pA->GetDestSize(), aTmp ); - } - break; - - case META_BMPEX_ACTION: - { - const MetaBmpExAction* pA = (const MetaBmpExAction *) pMA; - Bitmap aBmp( pA->GetBitmapEx().GetBitmap() ); - Bitmap aMsk( pA->GetBitmapEx().GetMask() ); - - if( !!aMsk ) - { - aBmp.Replace( aMsk, COL_WHITE ); - aMsk.Invert(); - WMFRecord_StretchDIB( pA->GetPoint(), aMsk.GetSizePixel(), aBmp, W_SRCPAINT ); - WMFRecord_StretchDIB( pA->GetPoint(), aBmp.GetSizePixel(), aBmp, W_SRCAND ); - } - else - WMFRecord_StretchDIB( pA->GetPoint(), aBmp.GetSizePixel(), aBmp ); - } - break; - - case META_BMPEXSCALE_ACTION: - { - const MetaBmpExScaleAction* pA = (const MetaBmpExScaleAction*) pMA; - Bitmap aBmp( pA->GetBitmapEx().GetBitmap() ); - Bitmap aMsk( pA->GetBitmapEx().GetMask() ); - - if( !!aMsk ) - { - aBmp.Replace( aMsk, COL_WHITE ); - aMsk.Invert(); - WMFRecord_StretchDIB( pA->GetPoint(), pA->GetSize(), aMsk, W_SRCPAINT ); - WMFRecord_StretchDIB( pA->GetPoint(), pA->GetSize(), aBmp, W_SRCAND ); - } - else - WMFRecord_StretchDIB( pA->GetPoint(), pA->GetSize(), aBmp ); - } - break; - - case META_BMPEXSCALEPART_ACTION: - { - const MetaBmpExScalePartAction* pA = (const MetaBmpExScalePartAction*) pMA; - BitmapEx aBmpEx( pA->GetBitmapEx() ); - aBmpEx.Crop( Rectangle( pA->GetSrcPoint(), pA->GetSrcSize() ) ); - Bitmap aBmp( aBmpEx.GetBitmap() ); - Bitmap aMsk( aBmpEx.GetMask() ); - - if( !!aMsk ) - { - aBmp.Replace( aMsk, COL_WHITE ); - aMsk.Invert(); - WMFRecord_StretchDIB( pA->GetDestPoint(), pA->GetDestSize(), aMsk, W_SRCPAINT ); - WMFRecord_StretchDIB( pA->GetDestPoint(), pA->GetDestSize(), aBmp, W_SRCAND ); - } - else - WMFRecord_StretchDIB( pA->GetDestPoint(), pA->GetDestSize(), aBmp ); - } - break; - - case META_GRADIENT_ACTION: - { - const MetaGradientAction* pA = (const MetaGradientAction*) pMA; - GDIMetaFile aTmpMtf; - - pVirDev->AddGradientActions( pA->GetRect(), pA->GetGradient(), aTmpMtf ); - WriteRecords( aTmpMtf ); - } - break; - - case META_HATCH_ACTION: - { - const MetaHatchAction* pA = (const MetaHatchAction*) pMA; - GDIMetaFile aTmpMtf; - - pVirDev->AddHatchActions( pA->GetPolyPolygon(), pA->GetHatch(), aTmpMtf ); - WriteRecords( aTmpMtf ); - } - break; - - case META_WALLPAPER_ACTION: - { - const MetaWallpaperAction* pA = (const MetaWallpaperAction*) pMA; - const Color& rColor = pA->GetWallpaper().GetColor(); - const Color aOldLineColor( aSrcLineColor ); - const Color aOldFillColor( aSrcFillColor ); - - aSrcLineColor = rColor; - aSrcFillColor = rColor; - aSrcLineInfo = LineInfo(); - SetLineAndFillAttr(); - WMFRecord_Rectangle( pA->GetRect() ); - aSrcLineColor = aOldLineColor; - aSrcFillColor = aOldFillColor; - } - break; - - case META_ISECTRECTCLIPREGION_ACTION: - { - const MetaISectRectClipRegionAction* pA = (const MetaISectRectClipRegionAction*) pMA; - WMFRecord_IntersectClipRect( pA->GetRect() ); - } - break; - - case META_LINECOLOR_ACTION: - { - const MetaLineColorAction* pA = (const MetaLineColorAction*) pMA; - - if( pA->IsSetting() ) - aSrcLineColor = pA->GetColor(); - else - aSrcLineColor = Color( COL_TRANSPARENT ); - } - break; - - case META_FILLCOLOR_ACTION: - { - const MetaFillColorAction* pA = (const MetaFillColorAction*) pMA; - - if( pA->IsSetting() ) - aSrcFillColor = pA->GetColor(); - else - aSrcFillColor = Color( COL_TRANSPARENT ); - } - break; - - case META_TEXTCOLOR_ACTION: - { - const MetaTextColorAction* pA = (const MetaTextColorAction*) pMA; - aSrcTextColor = pA->GetColor(); - } - break; - - case META_TEXTFILLCOLOR_ACTION: - { - const MetaTextFillColorAction* pA = (const MetaTextFillColorAction*) pMA; - if( pA->IsSetting() ) - aSrcFont.SetFillColor( pA->GetColor() ); - else - aSrcFont.SetFillColor( Color( COL_TRANSPARENT ) ); - } - break; - - case META_TEXTALIGN_ACTION: - { - const MetaTextAlignAction* pA = (const MetaTextAlignAction*) pMA; - eSrcTextAlign = pA->GetTextAlign(); - } - break; - - case META_MAPMODE_ACTION: - { - const MetaMapModeAction* pA = (const MetaMapModeAction*) pMA; - - if (aSrcMapMode!=pA->GetMapMode()) - { - if( pA->GetMapMode().GetMapUnit() == MAP_RELATIVE ) - { - MapMode aMM = pA->GetMapMode(); - Fraction aScaleX = aMM.GetScaleX(); - Fraction aScaleY = aMM.GetScaleY(); - - Point aOrigin = aSrcMapMode.GetOrigin(); - BigInt aX( aOrigin.X() ); - aX *= BigInt( aScaleX.GetDenominator() ); - if( aOrigin.X() >= 0 ) - if( aScaleX.GetNumerator() >= 0 ) - aX += BigInt( aScaleX.GetNumerator()/2 ); - else - aX -= BigInt( (aScaleX.GetNumerator()+1)/2 ); - else - if( aScaleX.GetNumerator() >= 0 ) - aX -= BigInt( (aScaleX.GetNumerator()-1)/2 ); - else - aX += BigInt( aScaleX.GetNumerator()/2 ); - aX /= BigInt( aScaleX.GetNumerator() ); - aOrigin.X() = (long)aX + aMM.GetOrigin().X(); - BigInt aY( aOrigin.Y() ); - aY *= BigInt( aScaleY.GetDenominator() ); - if( aOrigin.Y() >= 0 ) - if( aScaleY.GetNumerator() >= 0 ) - aY += BigInt( aScaleY.GetNumerator()/2 ); - else - aY -= BigInt( (aScaleY.GetNumerator()+1)/2 ); - else - if( aScaleY.GetNumerator() >= 0 ) - aY -= BigInt( (aScaleY.GetNumerator()-1)/2 ); - else - aY += BigInt( aScaleY.GetNumerator()/2 ); - aY /= BigInt( aScaleY.GetNumerator() ); - aOrigin.Y() = (long)aY + aMM.GetOrigin().Y(); - aSrcMapMode.SetOrigin( aOrigin ); - - aScaleX *= aSrcMapMode.GetScaleX(); - aScaleY *= aSrcMapMode.GetScaleY(); - aSrcMapMode.SetScaleX( aScaleX ); - aSrcMapMode.SetScaleY( aScaleY ); - } - else - aSrcMapMode=pA->GetMapMode(); - } - } - break; - - case META_FONT_ACTION: - { - const MetaFontAction* pA = (const MetaFontAction*) pMA; - aSrcFont = pA->GetFont(); - - if ( aSrcFont.GetCharSet() == RTL_TEXTENCODING_DONTKNOW ) - aSrcFont.SetCharSet( GetExtendedTextEncoding( gsl_getSystemTextEncoding() ) ); - if ( aSrcFont.GetCharSet() == RTL_TEXTENCODING_UNICODE ) - aSrcFont.SetCharSet( RTL_TEXTENCODING_MS_1252 ); - eSrcTextAlign = aSrcFont.GetAlign(); - aSrcTextColor = aSrcFont.GetColor(); - aSrcFont.SetAlign( ALIGN_BASELINE ); - aSrcFont.SetColor( COL_WHITE ); - } - break; - - case META_PUSH_ACTION: - { - const MetaPushAction* pA = (const MetaPushAction*)pMA; - - WMFWriterAttrStackMember* pAt = new WMFWriterAttrStackMember; - pAt->nFlags = pA->GetFlags(); - pAt->aClipRegion = aSrcClipRegion; - pAt->aLineColor=aSrcLineColor; - pAt->aFillColor=aSrcFillColor; - pAt->eRasterOp=eSrcRasterOp; - pAt->aFont=aSrcFont; - pAt->eTextAlign=eSrcTextAlign; - pAt->aTextColor=aSrcTextColor; - pAt->aMapMode=aSrcMapMode; - pAt->aLineInfo=aDstLineInfo; - pAt->pSucc=pAttrStack; - pAttrStack=pAt; - - SetAllAttr(); // update ( now all source attributes are equal to the destination attributes ) - WMFRecord_SaveDC(); - - } - break; - - case META_POP_ACTION: - { - WMFWriterAttrStackMember * pAt=pAttrStack; - - if( pAt ) - { - aDstLineInfo = pAt->aLineInfo; - aDstLineColor = pAt->aLineColor; - if ( pAt->nFlags & PUSH_LINECOLOR ) - aSrcLineColor = pAt->aLineColor; - aDstFillColor = pAt->aFillColor; - if ( pAt->nFlags & PUSH_FILLCOLOR ) - aSrcFillColor = pAt->aFillColor; - eDstROP2 = pAt->eRasterOp; - if ( pAt->nFlags & PUSH_RASTEROP ) - eSrcRasterOp = pAt->eRasterOp; - aDstFont = pAt->aFont; - if ( pAt->nFlags & PUSH_FONT ) - aSrcFont = pAt->aFont; - eDstTextAlign = pAt->eTextAlign; - if ( pAt->nFlags & ( PUSH_FONT | PUSH_TEXTALIGN ) ) - eSrcTextAlign = pAt->eTextAlign; - aDstTextColor = pAt->aTextColor; - if ( pAt->nFlags & ( PUSH_FONT | PUSH_TEXTCOLOR ) ) - aSrcTextColor = pAt->aTextColor; - if ( pAt->nFlags & PUSH_MAPMODE ) - aSrcMapMode = pAt->aMapMode; - aDstClipRegion = pAt->aClipRegion; - if ( pAt->nFlags & PUSH_CLIPREGION ) - aSrcClipRegion = pAt->aClipRegion; - - WMFRecord_RestoreDC(); - pAttrStack = pAt->pSucc; - delete pAt; - } - } - break; - - case META_EPS_ACTION : - { - const MetaEPSAction* pA = (const MetaEPSAction*)pMA; - const GDIMetaFile aGDIMetaFile( pA->GetSubstitute() ); - - INT32 nCount = aGDIMetaFile.GetActionCount(); - for ( INT32 i = 0; i < nCount; i++ ) - { - const MetaAction* pMetaAct = aGDIMetaFile.GetAction( i ); - if ( pMetaAct->GetType() == META_BMPSCALE_ACTION ) - { - const MetaBmpScaleAction* pBmpScaleAction = (const MetaBmpScaleAction*)pMetaAct; - WMFRecord_StretchDIB( pA->GetPoint(), pA->GetSize(), pBmpScaleAction->GetBitmap() ); - break; - } - } - } - break; - - case META_RASTEROP_ACTION: - { - const MetaRasterOpAction* pA = (const MetaRasterOpAction*) pMA; - eSrcRasterOp=pA->GetRasterOp(); - } - break; - - case META_TRANSPARENT_ACTION: - { - aSrcLineInfo = LineInfo(); - SetLineAndFillAttr(); - WMFRecord_PolyPolygon( ( (MetaTransparentAction*) pMA )->GetPolyPolygon() ); - } - break; - - case META_FLOATTRANSPARENT_ACTION: - { - const MetaFloatTransparentAction* pA = (const MetaFloatTransparentAction*) pMA; - - GDIMetaFile aTmpMtf( pA->GetGDIMetaFile() ); - Point aSrcPt( aTmpMtf.GetPrefMapMode().GetOrigin() ); - const Size aSrcSize( aTmpMtf.GetPrefSize() ); - const Point aDestPt( pA->GetPoint() ); - const Size aDestSize( pA->GetSize() ); - const double fScaleX = aSrcSize.Width() ? (double) aDestSize.Width() / aSrcSize.Width() : 1.0; - const double fScaleY = aSrcSize.Height() ? (double) aDestSize.Height() / aSrcSize.Height() : 1.0; - long nMoveX, nMoveY; - - aSrcLineInfo = LineInfo(); - SetAllAttr(); - - if( fScaleX != 1.0 || fScaleY != 1.0 ) - { - aTmpMtf.Scale( fScaleX, fScaleY ); - aSrcPt.X() = FRound( aSrcPt.X() * fScaleX ), aSrcPt.Y() = FRound( aSrcPt.Y() * fScaleY ); - } - - nMoveX = aDestPt.X() - aSrcPt.X(), nMoveY = aDestPt.Y() - aSrcPt.Y(); - - if( nMoveX || nMoveY ) - aTmpMtf.Move( nMoveX, nMoveY ); - - WriteRecords( aTmpMtf ); - } - break; - - case( META_LAYOUTMODE_ACTION ): - { - sal_uInt32 nLayoutMode = ( (MetaLayoutModeAction*) pMA )->GetLayoutMode(); - eSrcHorTextAlign = 0; // TA_LEFT - if (nLayoutMode & TEXT_LAYOUT_BIDI_RTL) - { - eSrcHorTextAlign = W_TA_RIGHT | W_TA_RTLREADING; - } - if (nLayoutMode & TEXT_LAYOUT_TEXTORIGIN_RIGHT) - eSrcHorTextAlign |= W_TA_RIGHT; - else if (nLayoutMode & TEXT_LAYOUT_TEXTORIGIN_LEFT) - eSrcHorTextAlign &= ~W_TA_RIGHT; - break; - } - - // Unsupported Actions - case META_MASK_ACTION: - case META_MASKSCALE_ACTION: - case META_MASKSCALEPART_ACTION: - { - DBG_ERROR( "Unsupported action: MetaMask...Action!" ); - } - break; - - case META_CLIPREGION_ACTION: - break; - - case META_ISECTREGIONCLIPREGION_ACTION: - { - DBG_ERROR( "Unsupported action: MetaISectRegionClipRegionAction!" ); - } - break; - - case META_MOVECLIPREGION_ACTION: - { - DBG_ERROR( "Unsupported action: MetaMoveClipRegionAction!" ); - } - break; - } - - nWrittenActions++; - MayCallback(); - - if (pWMF->GetError()) - bStatus=FALSE; - - if(bStatus==FALSE) - break; - } - } -} - -// ------------------------------------------------------------------------ - -void WMFWriter::WriteHeader( const GDIMetaFile &, BOOL bPlaceable ) -{ - if( bPlaceable ) - { - USHORT nCheckSum, nValue; - Size aSize( pVirDev->LogicToLogic(Size(1,1),MapMode(MAP_INCH), aTargetMapMode) ); - USHORT nUnitsPerInch = (USHORT) ( ( aSize.Width() + aSize.Height() ) >> 1 ); - - nCheckSum=0; - nValue=0xcdd7; nCheckSum^=nValue; *pWMF << nValue; - nValue=0x9ac6; nCheckSum^=nValue; *pWMF << nValue; - nValue=0x0000; nCheckSum^=nValue; *pWMF << nValue; - nValue=0x0000; nCheckSum^=nValue; *pWMF << nValue; - nValue=0x0000; nCheckSum^=nValue; *pWMF << nValue; - nValue=(USHORT) aTargetSize.Width(); nCheckSum^=nValue; *pWMF << nValue; - nValue=(USHORT) aTargetSize.Height(); nCheckSum^=nValue; *pWMF << nValue; - nValue=nUnitsPerInch; nCheckSum^=nValue; *pWMF << nValue; - nValue=0x0000; nCheckSum^=nValue; *pWMF << nValue; - nValue=0x0000; nCheckSum^=nValue; *pWMF << nValue; - *pWMF << nCheckSum; - } - - nMetafileHeaderPos=pWMF->Tell(); - *pWMF << (sal_uInt16)0x0001 // Typ: Datei - << (sal_uInt16)0x0009 // Headerlaenge in Worten - << (sal_uInt16)0x0300 // Version als BCD-Zahl - << (sal_uInt32) 0x00000000 // Dateilaenge (ohne 1. Header), wird spaeter durch UpdateHeader() berichtigt - << (sal_uInt16)MAXOBJECTHANDLES // Maximalezahl der gleichzeitigen Objekte - << (sal_uInt32) 0x00000000 // Maximale Record-laenge, wird spaeter durch UpdateHeader() berichtigt - << (sal_uInt16)0x0000; // Reserved -} - -// ------------------------------------------------------------------------ - -void WMFWriter::UpdateHeader() -{ - ULONG nPos; - sal_uInt32 nFileSize; - - nPos=pWMF->Tell(); // Endposition = Gesammtgroesse der Datei - nFileSize=nPos-nMetafileHeaderPos; // Groesse des 1. Headers abziehen - if ((nFileSize&1)!=0) { // ggf. auf ganze Worte aufrunden - *pWMF << (BYTE)0; - nPos++; - nFileSize++; - } - nFileSize>>=1; // In Anzahl Worte umrechnen - pWMF->Seek(nMetafileHeaderPos+6); // Zum Dateigroessen-Eintrag im zweiten Header - *pWMF << nFileSize; // Dateigroesse berichtigen - pWMF->SeekRel(2); // Zum Max-Record-Laenge-Eintrag im zweiten Header - *pWMF << nMaxRecordSize; // und berichtigen - pWMF->Seek(nPos); -} - -// ------------------------------------------------------------------------ - -BOOL WMFWriter::WriteWMF( const GDIMetaFile& rMTF, SvStream& rTargetStream, - FilterConfigItem* pFConfigItem, BOOL bPlaceable ) -{ - WMFWriterAttrStackMember * pAt; - - bEmbedEMF = TRUE; - bStatus=TRUE; - pConvert = 0; - pVirDev = new VirtualDevice; - - pFilterConfigItem = pFConfigItem; - if ( pFilterConfigItem ) - { - xStatusIndicator = pFilterConfigItem->GetStatusIndicator(); - if ( xStatusIndicator.is() ) - { - rtl::OUString aMsg; - xStatusIndicator->start( aMsg, 100 ); - } - } - nLastPercent=0; - - pWMF=&rTargetStream; - pWMF->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); - - nMaxRecordSize=0; - - aSrcMapMode=rMTF.GetPrefMapMode(); - - if( bPlaceable ) - { - aTargetMapMode = aSrcMapMode; - aTargetSize = rMTF.GetPrefSize(); - nTargetDivisor = CalcSaveTargetMapMode(aTargetMapMode, aTargetSize); - aTargetSize.Width() /= nTargetDivisor; - aTargetSize.Height() /= nTargetDivisor; - } - else - { - aTargetMapMode = MapMode( MAP_INCH ); - - const long nUnit = pVirDev->LogicToPixel( Size( 1, 1 ), aTargetMapMode ).Width(); - const Fraction aFrac( 1, nUnit ); - - aTargetMapMode.SetScaleX( aFrac ); - aTargetMapMode.SetScaleY( aFrac ); - aTargetSize = pVirDev->LogicToLogic( rMTF.GetPrefSize(), aSrcMapMode, aTargetMapMode ); - } - - pVirDev->SetMapMode( aTargetMapMode ); - - pAttrStack=NULL; - - for (USHORT i=0; ipSucc; - delete pAt; - } - - delete pVirDev; - delete pConvert; - - if ( xStatusIndicator.is() ) - xStatusIndicator->end(); - - return bStatus; -} - -// ------------------------------------------------------------------------ - -USHORT WMFWriter::CalcSaveTargetMapMode(MapMode& rMapMode, - const Size& rPrefSize) -{ - Fraction aDivFrac(2, 1); - USHORT nDivisor = 1; - - Size aSize = pVirDev->LogicToLogic( rPrefSize, aSrcMapMode, rMapMode ); - - while( nDivisor <= 64 && (aSize.Width() > 32767 || aSize.Height() > 32767) ) - { - Fraction aFrac = rMapMode.GetScaleX(); - - aFrac *= aDivFrac; - rMapMode.SetScaleX(aFrac); - aFrac = rMapMode.GetScaleY(); - aFrac *= aDivFrac; - rMapMode.SetScaleY(aFrac); - nDivisor <<= 1; - aSize = pVirDev->LogicToLogic( rPrefSize, aSrcMapMode, rMapMode ); - } - - return nDivisor; -} - -// ------------------------------------------------------------------------ - -void WMFWriter::WriteEmbeddedEMF( const GDIMetaFile& rMTF ) -{ - EMFWriter aEMFWriter; - SvMemoryStream aStream; - - if( aEMFWriter.WriteEMF( rMTF, aStream ) ) - { - sal_Size nTotalSize = aStream.Tell(); - if( nTotalSize > SAL_MAX_UINT32 ) - return; - aStream.Seek( 0 ); - sal_uInt32 nRemainingSize = static_cast< sal_uInt32 >( nTotalSize ); - sal_uInt32 nRecCounts = ( (nTotalSize - 1) / 0x2000 ) + 1; - sal_uInt16 nCheckSum = 0, nWord; - - sal_uInt32 nPos = 0; - - while( nPos + 1 < nTotalSize ) - { - aStream >> nWord; - nCheckSum ^= nWord; - nPos += 2; - } - - nCheckSum = static_cast< sal_uInt16 >( nCheckSum * -1 ); - - aStream.Seek( 0 ); - while( nRemainingSize > 0 ) - { - sal_uInt32 nCurSize; - if( nRemainingSize > 0x2000 ) - { - nCurSize = 0x2000; - nRemainingSize -= 0x2000; - } - else - { - nCurSize = nRemainingSize; - nRemainingSize = 0; - } - WriteEMFRecord( aStream, - nCurSize, - nRemainingSize, - nTotalSize, - nRecCounts, - nCheckSum ); - nCheckSum = 0; - } - } -} - -// ------------------------------------------------------------------------ - -void WMFWriter::WriteEMFRecord( SvMemoryStream& rStream, sal_uInt32 nCurSize, sal_uInt32 nRemainingSize, - sal_uInt32 nTotalSize, sal_uInt32 nRecCounts, sal_uInt16 nCheckSum ) -{ - // according to http://msdn.microsoft.com/en-us/library/dd366152%28PROT.13%29.aspx - WriteRecordHeader( 0, W_META_ESCAPE ); - *pWMF << (sal_uInt16)W_MFCOMMENT // same as META_ESCAPE_ENHANCED_METAFILE - << (sal_uInt16)( nCurSize + 34 ) // we will always have a 34 byte escape header: - << (sal_uInt32) 0x43464D57 // WMFC - << (sal_uInt32) 0x00000001 // Comment type - << (sal_uInt32) 0x00010000 // version - << nCheckSum // check sum - << (sal_uInt32) 0 // flags = 0 - << nRecCounts // total number of records - << nCurSize // size of this record's data - << nRemainingSize // remaining size of data in following records, missing in MSDN documentation - << nTotalSize; // total size of EMF stream - - pWMF->Write( static_cast< const sal_Char* >( rStream.GetData() ) + rStream.Tell(), nCurSize ); - rStream.SeekRel( nCurSize ); - UpdateRecordHeader(); -} diff --git a/svtools/source/filter.vcl/wmf/wmfwr.hxx b/svtools/source/filter.vcl/wmf/wmfwr.hxx deleted file mode 100644 index 9fe698b22c2e..000000000000 --- a/svtools/source/filter.vcl/wmf/wmfwr.hxx +++ /dev/null @@ -1,229 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _WMFWR_HXX -#define _WMFWR_HXX - -#include -#include -#include -#include -#include -#include -#include - -// ----------------------------------------------------------------------------- - -#define MAXOBJECTHANDLES 16 - -// ----------------------------------------------------------------------------- - -struct WMFWriterAttrStackMember -{ - struct WMFWriterAttrStackMember * pSucc; - Color aLineColor; - Color aFillColor; - Color aTextColor; - LineInfo aLineInfo; - TextAlign eTextAlign; - RasterOp eRasterOp; - Font aFont; - MapMode aMapMode; - Region aClipRegion; - sal_uInt16 nFlags; -}; - -// ------------- -// - WMFWriter - -// ------------- - -class StarSymbolToMSMultiFont; -class LineInfo; -namespace basegfx { class B2DPolygon; } - -class WMFWriter -{ -private: - - BOOL bStatus; - - ULONG nLastPercent; // Mit welcher Zahl pCallback zuletzt aufgerufen wurde. - FilterConfigItem* pFilterConfigItem; - - com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator > xStatusIndicator; - - SvStream* pWMF; - VirtualDevice* pVirDev; - StarSymbolToMSMultiFont *pConvert; - MapMode aTargetMapMode; - Size aTargetSize; - USHORT nTargetDivisor; - - ULONG nMetafileHeaderPos; - sal_uInt32 nMaxRecordSize; // in Worten - ULONG nActRecordPos; - - // Aktuelle Attribute im Quell-Metafile: - Color aSrcLineColor; - Color aSrcFillColor; - Color aSrcTextColor; - LineInfo aSrcLineInfo; - RasterOp eSrcRasterOp; - FontAlign eSrcTextAlign; - Font aSrcFont; - MapMode aSrcMapMode; - BOOL bSrcIsClipping; - Region aSrcClipRegion; - WMFWriterAttrStackMember * pAttrStack; - - UINT32 eSrcHorTextAlign; - - // Aktuelle Attribute im Ziel-Metafile: - Color aDstLineColor; - Color aDstFillColor; - Color aDstTextColor; - LineInfo aDstLineInfo; - RasterOp eDstROP2; - FontAlign eDstTextAlign; - Font aDstFont; - - UINT32 eDstHorTextAlign; - - BOOL bDstIsClipping; // ???: derzeit unberuecksichtigt - Region aDstClipRegion; // ???: derzeit unberuecksichtigt - BOOL bHandleAllocated[MAXOBJECTHANDLES]; // Welche Handles vergeben sind - USHORT nDstPenHandle,nDstFontHandle,nDstBrushHandle; // Welche Handles die jeweiligen - // Selected-Objects besitzen - // 0xffff = keines: - - // Damit nicht bei jeder Operation alle Attribute verglichen werden muessen: - - ULONG nNumberOfActions; // Anzahl der Actions im GDIMetafile - ULONG nNumberOfBitmaps; // Anzahl der Bitmaps - ULONG nWrittenActions; // Anzahl der bereits verarbeiteten Actions beim Schreiben der Orders - ULONG nWrittenBitmaps; // Anzahl der bereits geschriebenen Bitmaps - ULONG nActBitmapPercent; // Wieviel Prozent die naechste Bitmap schon geschrieben ist. - - BOOL bEmbedEMF; // optionally embedd EMF data into WMF - - void MayCallback(); - // Berechnet anhand der obigen 5 Parameter eine Prozentzahl - // und macht dann ggf. einen Callback. Setzt bStatus auf FALSE wenn User abbrechen - // moechte. - - void CountActionsAndBitmaps(const GDIMetaFile & rMTF); - // Zaehlt die Bitmaps und Actions (nNumberOfActions und nNumberOfBitmaps muessen - // zu Anfang auf 0 gesetzt werden, weil diese Methode rekursiv ist) - - void WritePointXY(const Point & rPoint); - void WritePointYX(const Point & rPoint); - sal_Int32 ScaleWidth( sal_Int32 nDX ); - void WriteSize(const Size & rSize); - void WriteHeightWidth(const Size & rSize); - void WriteRectangle(const Rectangle & rRect); - void WriteColor(const Color & rColor); - - void WriteRecordHeader(sal_uInt32 nSizeWords, sal_uInt16 nType); - // nSizeWords ist die Groesse des gesammten Records in Anzahl Worte. - // Wenn nSizeWords unbekannt ist, dann 0 einsetzen (siehe UpdateRecordHeader()). - - void UpdateRecordHeader(); - // berichtig die Groesse des Records nach dem Schreiben der Parameter, wenn - // nSizeWords bei Aufruf von WriteRecordHeader(..) unbekannt war. - // fuegt ggf. noch ein BYTE 0 ein damit Anzahl Bytes immer gerade. - - void WMFRecord_Arc(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt); - void WMFRecord_Chord(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt); - void WMFRecord_CreateBrushIndirect(const Color& rColor); - void WMFRecord_CreateFontIndirect(const Font & rFont); - void WMFRecord_CreatePenIndirect(const Color& rColor, const LineInfo& rLineInfo ); - void WMFRecord_DeleteObject(USHORT nObjectHandle); - void WMFRecord_Ellipse(const Rectangle & rRect); - void WMFRecord_Escape( sal_uInt32 nEsc, sal_uInt32 nLen, const sal_Int8* pData ); - sal_Bool WMFRecord_Escape_Unicode( const Point& rPoint, const String& rStr, const sal_Int32 * pDXAry ); - void WMFRecord_ExtTextOut(const Point & rPoint, const String & rString, const sal_Int32 * pDXAry); - - void TrueExtTextOut(const Point & rPoint, const String & rString, - const ByteString & rByteString, const sal_Int32 * pDXAry); - void TrueTextOut(const Point & rPoint, const ByteString& rString); - void WMFRecord_LineTo(const Point & rPoint); - void WMFRecord_MoveTo(const Point & rPoint); - void WMFRecord_Pie(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt); - void WMFRecord_Polygon(const Polygon & rPoly); - void WMFRecord_PolyLine(const Polygon & rPoly); - void WMFRecord_PolyPolygon(const PolyPolygon & rPolyPoly); - void WMFRecord_Rectangle(const Rectangle & rRect); - void WMFRecord_RestoreDC(); - void WMFRecord_RoundRect(const Rectangle & rRect, long nHorzRound, long nVertRound); - void WMFRecord_SaveDC(); - void WMFRecord_SelectObject(USHORT nObjectHandle); - void WMFRecord_SetBkColor(const Color & rColor); - void WMFRecord_SetBkMode(BOOL bTransparent); - void WMFRecord_SetStretchBltMode(); - void WMFRecord_SetPixel(const Point & rPoint, const Color & rColor); - void WMFRecord_SetROP2(RasterOp eROP); - void WMFRecord_SetTextAlign(FontAlign eFontAlign, UINT32 eHorTextAlign); - void WMFRecord_SetTextColor(const Color & rColor); - void WMFRecord_SetWindowExt(const Size & rSize); - void WMFRecord_SetWindowOrg(const Point & rPoint); - void WMFRecord_StretchDIB(const Point & rPoint, const Size & rSize, const Bitmap & rBitmap, sal_uInt32 nROP = 0UL ); - void WMFRecord_TextOut(const Point & rPoint, const String & rString); - void WMFRecord_EndOfFile(); - void WMFRecord_IntersectClipRect( const Rectangle& rRect); - - USHORT AllocHandle(); - void FreeHandle(USHORT nObjectHandle); - void CreateSelectDeletePen( const Color& rColor, const LineInfo& rLineInfo ); - void CreateSelectDeleteFont(const Font & rFont); - void CreateSelectDeleteBrush(const Color& rColor); - - void SetLineAndFillAttr(); - void SetAllAttr(); - - void HandleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon); - void WriteRecords(const GDIMetaFile & rMTF); - - void WriteHeader(const GDIMetaFile & rMTF, BOOL bPlaceable); - void UpdateHeader(); - - void WriteEmbeddedEMF( const GDIMetaFile& rMTF ); - void WriteEMFRecord( SvMemoryStream& rStream, sal_uInt32 nCurSize, - sal_uInt32 nRemainingSize, - sal_uInt32 nTotalSize, - sal_uInt32 nRecCounts, - sal_uInt16 nCheckSum ); - - USHORT CalcSaveTargetMapMode(MapMode& rMapMode, const Size& rPrefSize); - -public: - - WMFWriter() {} - - BOOL WriteWMF(const GDIMetaFile & rMTF, SvStream & rTargetStream, FilterConfigItem* pFilterConfigItem, BOOL bPlaceable=TRUE); -}; - -#endif diff --git a/svtools/source/filter/FilterConfigCache.cxx b/svtools/source/filter/FilterConfigCache.cxx new file mode 100644 index 000000000000..979eba91767d --- /dev/null +++ b/svtools/source/filter/FilterConfigCache.cxx @@ -0,0 +1,597 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include "FilterConfigCache.hxx" +#include +#include +#include +#include +#include +#include +#include + +#define TOKEN_COUNT_FOR_OWN_FILTER 3 +// #define TOKEN_INDEX_FOR_IDENT 0 +#define TOKEN_INDEX_FOR_FILTER 1 +// #define TOKEN_INDEX_FOR_HASDIALOG 2 + +using namespace ::com::sun::star::lang ; // XMultiServiceFactory +using namespace ::com::sun::star::container ; // XNameAccess +using namespace ::com::sun::star::uno ; // Reference +using namespace ::com::sun::star::beans ; // PropertyValue +using namespace ::utl ; // getProcessServiceFactory(); +using ::rtl::OUString; + +const char* FilterConfigCache::FilterConfigCacheEntry::InternalPixelFilterNameList[] = +{ + IMP_BMP, IMP_GIF, IMP_PNG,IMP_JPEG, IMP_XBM, IMP_XPM, + EXP_BMP, EXP_JPEG, EXP_PNG, NULL +}; + +const char* FilterConfigCache::FilterConfigCacheEntry::InternalVectorFilterNameList[] = +{ + IMP_SVMETAFILE, IMP_WMF, IMP_EMF, IMP_SVSGF, IMP_SVSGV, IMP_SVG, + EXP_SVMETAFILE, EXP_WMF, EXP_EMF, EXP_SVG, NULL +}; + +const char* FilterConfigCache::FilterConfigCacheEntry::ExternalPixelFilterNameList[] = +{ + "egi", "icd", "ipd", "ipx", "ipb", "epb", "epg", + "epp", "ira", "era", "itg", "iti", "eti", "exp", NULL +}; + +sal_Bool FilterConfigCache::FilterConfigCacheEntry::IsValid() +{ + return sFilterName.Len() != 0; +} + +sal_Bool FilterConfigCache::bInitialized = sal_False; +sal_Int32 FilterConfigCache::nIndType = -1; +sal_Int32 FilterConfigCache::nIndUIName = -1; +sal_Int32 FilterConfigCache::nIndDocumentService = -1; +sal_Int32 FilterConfigCache::nIndFilterService = -1; +sal_Int32 FilterConfigCache::nIndFlags = -1; +sal_Int32 FilterConfigCache::nIndUserData = -1; +sal_Int32 FilterConfigCache::nIndFileFormatVersion = -1; +sal_Int32 FilterConfigCache::nIndTemplateName = -1; + +sal_Bool FilterConfigCache::FilterConfigCacheEntry::CreateFilterName( const OUString& rUserDataEntry ) +{ + bIsPixelFormat = bIsInternalFilter = sal_False; + sFilterName = String( rUserDataEntry ); + const char** pPtr; + for ( pPtr = InternalPixelFilterNameList; *pPtr && ( bIsInternalFilter == sal_False ); pPtr++ ) + { + if ( sFilterName.EqualsIgnoreCaseAscii( *pPtr ) ) + { + bIsInternalFilter = sal_True; + bIsPixelFormat = sal_True; + } + } + for ( pPtr = InternalVectorFilterNameList; *pPtr && ( bIsInternalFilter == sal_False ); pPtr++ ) + { + if ( sFilterName.EqualsIgnoreCaseAscii( *pPtr ) ) + bIsInternalFilter = sal_True; + } + if ( !bIsInternalFilter ) + { + for ( pPtr = ExternalPixelFilterNameList; *pPtr && ( bIsPixelFormat == sal_False ); pPtr++ ) + { + if ( sFilterName.EqualsIgnoreCaseAscii( *pPtr ) ) + bIsPixelFormat = sal_True; + } + String aTemp( OUString::createFromAscii( SVLIBRARY( "?" ) ) ); + xub_StrLen nIndex = aTemp.Search( (sal_Unicode)'?' ); + aTemp.Replace( nIndex, 1, sFilterName ); + sFilterName = aTemp; + } + return sFilterName.Len() != 0; +} + +String FilterConfigCache::FilterConfigCacheEntry::GetShortName() +{ + String aShortName; + if ( lExtensionList.getLength() ) + { + aShortName = lExtensionList[ 0 ]; + if ( aShortName.SearchAscii( "*.", 0 ) == 0 ) + aShortName.Erase( 0, 2 ); + } + return aShortName; +} + +/** helper to open the configuration root of the underlying + config package + + @param sPackage + specify, which config package should be opened. + Must be one of the defined static values TYPEPKG or FILTERPKG. + + @return A valid object if open was successfull. The access on opened + data will be readonly. It returns NULL in case open failed. + + @throws It let pass RuntimeExceptions only. + */ +Reference< XInterface > openConfig(const char* sPackage) + throw(RuntimeException) +{ + static OUString TYPEPKG( RTL_CONSTASCII_USTRINGPARAM( "types" ) ); + static OUString FILTERPKG( RTL_CONSTASCII_USTRINGPARAM( "filters" ) ); + + Reference< XMultiServiceFactory > xSMGR = getProcessServiceFactory(); + Reference< XInterface > xCfg; + try + { + // get access to config API (not to file!) + Reference< XMultiServiceFactory > xConfigProvider( xSMGR->createInstance( + OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")), UNO_QUERY); + + if (xConfigProvider.is()) + { + Sequence< Any > lParams(1); + PropertyValue aParam ; + + // define cfg path for open + aParam.Name = OUString::createFromAscii("nodepath"); + if (TYPEPKG.equalsIgnoreAsciiCaseAscii(sPackage)) + aParam.Value <<= OUString::createFromAscii("/org.openoffice.TypeDetection.Types/Types"); + if (FILTERPKG.equalsIgnoreAsciiCaseAscii(sPackage)) + aParam.Value <<= OUString::createFromAscii("/org.openoffice.TypeDetection.GraphicFilter/Filters"); + lParams[0] = makeAny(aParam); + + // get access to file + xCfg = xConfigProvider->createInstanceWithArguments( + OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess"), lParams); + } + } + catch(const RuntimeException&) + { throw; } + catch(const Exception&) + { xCfg.clear(); } + + return xCfg; +} + +void FilterConfigCache::ImplInit() +{ + static OUString STYPE ( RTL_CONSTASCII_USTRINGPARAM( "Type" ) ); + static OUString SUINAME ( RTL_CONSTASCII_USTRINGPARAM( "UIName" ) ); + static OUString SDOCUMENTSERVICE ( RTL_CONSTASCII_USTRINGPARAM( "DocumentService" ) ); + static OUString SFILTERSERVICE ( RTL_CONSTASCII_USTRINGPARAM( "FilterService" ) ); + static OUString STEMPLATENAME ( RTL_CONSTASCII_USTRINGPARAM( "TemplateName" ) ); + static OUString SFILEFORMATVERSION ( RTL_CONSTASCII_USTRINGPARAM( "FileFormatVersion" ) ); + static OUString SUICOMPONENT ( RTL_CONSTASCII_USTRINGPARAM( "UIComponent" ) ); + static OUString SFLAGS ( RTL_CONSTASCII_USTRINGPARAM( "Flags" ) ); + static OUString SUSERDATA ( RTL_CONSTASCII_USTRINGPARAM( "UserData" ) ); + static OUString SMEDIATYPE ( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); + static OUString SEXTENSIONS ( RTL_CONSTASCII_USTRINGPARAM( "Extensions" ) ); + static OUString SFORMATNAME ( RTL_CONSTASCII_USTRINGPARAM( "FormatName" ) ); + static OUString SREALFILTERNAME ( RTL_CONSTASCII_USTRINGPARAM( "RealFilterName" ) ); + + // get access to config + Reference< XNameAccess > xTypeAccess ( openConfig("types" ), UNO_QUERY ); + Reference< XNameAccess > xFilterAccess( openConfig("filters"), UNO_QUERY ); + + if ( xTypeAccess.is() && xFilterAccess.is() ) + { + Sequence< OUString > lAllFilter = xFilterAccess->getElementNames(); + sal_Int32 nAllFilterCount = lAllFilter.getLength(); + + for ( sal_Int32 i = 0; i < nAllFilterCount; i++ ) + { + OUString sInternalFilterName = lAllFilter[ i ]; + Reference< XPropertySet > xFilterSet; + xFilterAccess->getByName( sInternalFilterName ) >>= xFilterSet; + if (!xFilterSet.is()) + continue; + + FilterConfigCacheEntry aEntry; + + aEntry.sInternalFilterName = sInternalFilterName; + xFilterSet->getPropertyValue(STYPE) >>= aEntry.sType; + xFilterSet->getPropertyValue(SUINAME) >>= aEntry.sUIName; + xFilterSet->getPropertyValue(SREALFILTERNAME) >>= aEntry.sFilterType; + Sequence< OUString > lFlags; + xFilterSet->getPropertyValue(SFLAGS) >>= lFlags; + if (lFlags.getLength()!=1 || !lFlags[0].getLength()) + continue; + if (lFlags[0].equalsIgnoreAsciiCaseAscii("import")) + aEntry.nFlags = 1; + else + if (lFlags[0].equalsIgnoreAsciiCaseAscii("export")) + aEntry.nFlags = 2; + + OUString sUIComponent; + xFilterSet->getPropertyValue(SUICOMPONENT) >>= sUIComponent; + aEntry.bHasDialog = sUIComponent.getLength(); + + ::rtl::OUString sFormatName; + xFilterSet->getPropertyValue(SFORMATNAME) >>= sFormatName; + aEntry.CreateFilterName( sFormatName ); + + Reference< XPropertySet > xTypeSet; + xTypeAccess->getByName( aEntry.sType ) >>= xTypeSet; + if (!xTypeSet.is()) + continue; + + xTypeSet->getPropertyValue(SMEDIATYPE) >>= aEntry.sMediaType; + xTypeSet->getPropertyValue(SEXTENSIONS) >>= aEntry.lExtensionList; + + // The first extension will be used + // to generate our internal FilterType ( BMP, WMF ... ) + String aExtension( aEntry.GetShortName() ); + if (aExtension.Len() != 3) + continue; + + if ( aEntry.nFlags & 1 ) + aImport.push_back( aEntry ); + if ( aEntry.nFlags & 2 ) + aExport.push_back( aEntry ); + + // bFilterEntryCreated!? + if (!( aEntry.nFlags & 3 )) + continue; //? Entry was already inserted ... but following code will be supressed?! + } + } +}; + +const char* FilterConfigCache::InternalFilterListForSvxLight[] = +{ + "bmp","1","SVBMP", + "bmp","2","SVBMP", + "dxf","1","idx", + "eps","1","ips", + "eps","2","eps", + "gif","1","SVIGIF", + "gif","2","egi", + "jpg","1","SVIJPEG", + "jpg","2","SVEJPEG", + "sgv","1","SVSGV", + "sgf","1","SVSGF", + "met","1","ime", + "met","2","eme", + "png","1","SVIPNG", + "png","2","SVEPNG", + "pct","1","ipt", + "pct","2","ept", + "pcd","1","icd", + "psd","1","ipd", + "pcx","1","ipx", + "pbm","1","ipb", + "pbm","2","epb", + "pgm","1","ipb", + "pgm","2","epg", + "ppm","1","ipb", + "ppm","2","epp", + "ras","1","ira", + "ras","2","era", + "svm","1","SVMETAFILE", + "svm","2","SVMETAFILE", + "tga","1","itg", + "tif","1","iti", + "tif","2","eti", + "emf","1","SVEMF", + "emf","2","SVEMF", + "wmf","1","SVWMF", + "wmf","2","SVWMF", + "xbm","1","SVIXBM", + "xpm","1","SVIXPM", + "xpm","2","exp", + "svg","1","SVISVG", + "svg","2","SVESVG", + NULL +}; + +void FilterConfigCache::ImplInitSmart() +{ + const char** pPtr; + for ( pPtr = InternalFilterListForSvxLight; *pPtr; pPtr++ ) + { + FilterConfigCacheEntry aEntry; + + OUString sExtension( OUString::createFromAscii( *pPtr++ ) ); + + aEntry.lExtensionList.realloc( 1 ); + aEntry.lExtensionList[ 0 ] = sExtension; + + aEntry.sType = sExtension; + aEntry.sUIName = sExtension; + + ByteString sFlags( *pPtr++ ); + aEntry.nFlags = sFlags.ToInt32(); + + OUString sUserData( OUString::createFromAscii( *pPtr ) ); + aEntry.CreateFilterName( sUserData ); + + if ( aEntry.nFlags & 1 ) + aImport.push_back( aEntry ); + if ( aEntry.nFlags & 2 ) + aExport.push_back( aEntry ); + } +} + +// ------------------------------------------------------------------------ + +FilterConfigCache::FilterConfigCache( sal_Bool bConfig ) : + bUseConfig ( bConfig ) +{ + if ( bUseConfig ) + ImplInit(); + else + ImplInitSmart(); +} + +FilterConfigCache::~FilterConfigCache() +{ + +} + +String FilterConfigCache::GetImportFilterName( sal_uInt16 nFormat ) +{ + if( nFormat < aImport.size() ) + return aImport[ nFormat ].sFilterName; + return String::EmptyString(); +} + +sal_uInt16 FilterConfigCache::GetImportFormatNumber( const String& rFormatName ) +{ + CacheVector::iterator aIter( aImport.begin() ); + while ( aIter != aImport.end() ) + { + if ( aIter->sUIName.equalsIgnoreAsciiCase( rFormatName ) ) + break; + aIter++; + } + return sal::static_int_cast< sal_uInt16 >(aIter == aImport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aImport.begin()); +} + +sal_uInt16 FilterConfigCache::GetImportFormatNumberForMediaType( const String& rMediaType ) +{ + CacheVector::iterator aIter( aImport.begin() ); + while ( aIter != aImport.end() ) + { + if ( aIter->sMediaType.equalsIgnoreAsciiCase( rMediaType ) ) + break; + aIter++; + } + return sal::static_int_cast< sal_uInt16 >(aIter == aImport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aImport.begin()); +} + +sal_uInt16 FilterConfigCache::GetImportFormatNumberForShortName( const String& rShortName ) +{ + CacheVector::iterator aIter( aImport.begin() ); + while ( aIter != aImport.end() ) + { + if ( aIter->GetShortName().EqualsIgnoreCaseAscii( rShortName ) ) + break; + aIter++; + } + return sal::static_int_cast< sal_uInt16 >(aIter == aImport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aImport.begin()); +} + +sal_uInt16 FilterConfigCache::GetImportFormatNumberForTypeName( const String& rType ) +{ + CacheVector::iterator aIter( aImport.begin() ); + while ( aIter != aImport.end() ) + { + if ( aIter->sType.equalsIgnoreAsciiCase( rType ) ) + break; + aIter++; + } + return sal::static_int_cast< sal_uInt16 >(aIter == aImport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aImport.begin()); +} + +String FilterConfigCache::GetImportFormatName( sal_uInt16 nFormat ) +{ + if( nFormat < aImport.size() ) + return aImport[ nFormat ].sUIName; + return String::EmptyString(); +} + +String FilterConfigCache::GetImportFormatMediaType( sal_uInt16 nFormat ) +{ + if( nFormat < aImport.size() ) + return aImport[ nFormat ].sMediaType; + return String::EmptyString(); +} + +String FilterConfigCache::GetImportFormatShortName( sal_uInt16 nFormat ) +{ + if( nFormat < aImport.size() ) + return aImport[ nFormat ].GetShortName(); + return String::EmptyString(); +} + +String FilterConfigCache::GetImportFormatExtension( sal_uInt16 nFormat, sal_Int32 nEntry ) +{ + if ( (nFormat < aImport.size()) && (nEntry < aImport[ nFormat ].lExtensionList.getLength()) ) + return aImport[ nFormat ].lExtensionList[ nEntry ]; + return String::EmptyString(); +} + +String FilterConfigCache::GetImportFilterType( sal_uInt16 nFormat ) +{ + if( nFormat < aImport.size() ) + return aImport[ nFormat ].sType; + return String::EmptyString(); +} + +String FilterConfigCache::GetImportFilterTypeName( sal_uInt16 nFormat ) +{ + if( nFormat < aImport.size() ) + return aImport[ nFormat ].sFilterType; + return String::EmptyString(); +} + +String FilterConfigCache::GetImportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry ) +{ + String aWildcard( GetImportFormatExtension( nFormat, nEntry ) ); + if ( aWildcard.Len() ) + aWildcard.Insert( UniString::CreateFromAscii( "*.", 2 ), 0 ); + return aWildcard; +} + +sal_Bool FilterConfigCache::IsImportInternalFilter( sal_uInt16 nFormat ) +{ + return (nFormat < aImport.size()) && aImport[ nFormat ].bIsInternalFilter; +} + +sal_Bool FilterConfigCache::IsImportPixelFormat( sal_uInt16 nFormat ) +{ + return (nFormat < aImport.size()) && aImport[ nFormat ].bIsPixelFormat; +} + +sal_Bool FilterConfigCache::IsImportDialog( sal_uInt16 nFormat ) +{ + return (nFormat < aImport.size()) && aImport[ nFormat ].bHasDialog; +} + +// ------------------------------------------------------------------------ + +String FilterConfigCache::GetExportFilterName( sal_uInt16 nFormat ) +{ + if( nFormat < aExport.size() ) + return aExport[ nFormat ].sFilterName; + return String::EmptyString(); +} + +sal_uInt16 FilterConfigCache::GetExportFormatNumber( const String& rFormatName ) +{ + CacheVector::iterator aIter( aExport.begin() ); + while ( aIter != aExport.end() ) + { + if ( aIter->sUIName.equalsIgnoreAsciiCase( rFormatName ) ) + break; + aIter++; + } + return sal::static_int_cast< sal_uInt16 >(aIter == aExport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aExport.begin()); +} + +sal_uInt16 FilterConfigCache::GetExportFormatNumberForMediaType( const String& rMediaType ) +{ + CacheVector::iterator aIter( aExport.begin() ); + while ( aIter != aExport.end() ) + { + if ( aIter->sMediaType.equalsIgnoreAsciiCase( rMediaType ) ) + break; + aIter++; + } + return sal::static_int_cast< sal_uInt16 >(aIter == aExport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aExport.begin()); +} + +sal_uInt16 FilterConfigCache::GetExportFormatNumberForShortName( const String& rShortName ) +{ + CacheVector::iterator aIter( aExport.begin() ); + while ( aIter != aExport.end() ) + { + if ( aIter->GetShortName().EqualsIgnoreCaseAscii( rShortName ) ) + break; + aIter++; + } + return sal::static_int_cast< sal_uInt16 >(aIter == aExport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aExport.begin()); +} + +sal_uInt16 FilterConfigCache::GetExportFormatNumberForTypeName( const String& rType ) +{ + CacheVector::iterator aIter( aExport.begin() ); + while ( aIter != aExport.end() ) + { + if ( aIter->sType.equalsIgnoreAsciiCase( rType ) ) + break; + aIter++; + } + return sal::static_int_cast< sal_uInt16 >(aIter == aExport.end() ? GRFILTER_FORMAT_NOTFOUND : aIter - aExport.begin()); +} + +String FilterConfigCache::GetExportFormatName( sal_uInt16 nFormat ) +{ + if( nFormat < aExport.size() ) + return aExport[ nFormat ].sUIName; + return String::EmptyString(); +} + +String FilterConfigCache::GetExportFormatMediaType( sal_uInt16 nFormat ) +{ + if( nFormat < aExport.size() ) + return aExport[ nFormat ].sMediaType; + return String::EmptyString(); +} + +String FilterConfigCache::GetExportFormatShortName( sal_uInt16 nFormat ) +{ + if( nFormat < aExport.size() ) + return aExport[ nFormat ].GetShortName(); + return String::EmptyString(); +} + +String FilterConfigCache::GetExportFormatExtension( sal_uInt16 nFormat, sal_Int32 nEntry ) +{ + if ( (nFormat < aExport.size()) && (nEntry < aExport[ nFormat ].lExtensionList.getLength()) ) + return aExport[ nFormat ].lExtensionList[ nEntry ]; + return String::EmptyString(); +} + +String FilterConfigCache::GetExportFilterTypeName( sal_uInt16 nFormat ) +{ + if( nFormat < aExport.size() ) + return aExport[ nFormat ].sFilterType; + return String::EmptyString(); +} + +String FilterConfigCache::GetExportInternalFilterName( sal_uInt16 nFormat ) +{ + if( nFormat < aExport.size() ) + return aExport[ nFormat ].sInternalFilterName; + return String::EmptyString(); +} + +String FilterConfigCache::GetExportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry ) +{ + String aWildcard( GetExportFormatExtension( nFormat, nEntry ) ); + if ( aWildcard.Len() ) + aWildcard.Insert( UniString::CreateFromAscii( "*.", 2 ), 0 ); + return aWildcard; +} + +sal_Bool FilterConfigCache::IsExportInternalFilter( sal_uInt16 nFormat ) +{ + return (nFormat < aExport.size()) && aExport[ nFormat ].bIsInternalFilter; +} + +sal_Bool FilterConfigCache::IsExportPixelFormat( sal_uInt16 nFormat ) +{ + return (nFormat < aExport.size()) && aExport[ nFormat ].bIsPixelFormat; +} + +sal_Bool FilterConfigCache::IsExportDialog( sal_uInt16 nFormat ) +{ + return (nFormat < aExport.size()) && aExport[ nFormat ].bHasDialog; +} + +// ------------------------------------------------------------------------ diff --git a/svtools/source/filter/FilterConfigCache.hxx b/svtools/source/filter/FilterConfigCache.hxx new file mode 100644 index 000000000000..2c6b7361e540 --- /dev/null +++ b/svtools/source/filter/FilterConfigCache.hxx @@ -0,0 +1,145 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#ifndef _FILTER_CONFIG_CACHE_HXX_ +#define _FILTER_CONFIG_CACHE_HXX_ + +#include "svtools/svtdllapi.h" +#include +#include +#include +#include +#include + +#ifndef INCLUDED_VECTOR +#include +#define INCLUDED_VECTOR +#endif + +class SVT_DLLPUBLIC FilterConfigCache +{ + struct FilterConfigCacheEntry + { + ::rtl::OUString sInternalFilterName; + ::rtl::OUString sType; + ::com::sun::star::uno::Sequence< ::rtl::OUString > lExtensionList; + ::rtl::OUString sUIName; + ::rtl::OUString sDocumentService; + ::rtl::OUString sFilterService; + ::rtl::OUString sTemplateName; + + ::rtl::OUString sMediaType; + ::rtl::OUString sFilterType; + + sal_Int32 nFlags; + sal_Int32 nFileFormatVersion; + + // user data + String sFilterName; + sal_Bool bHasDialog : 1; + sal_Bool bIsInternalFilter : 1; + sal_Bool bIsPixelFormat : 1; + + sal_Bool IsValid(); + sal_Bool CreateFilterName( const ::rtl::OUString& rUserDataEntry ); + String GetShortName( ); + + static const char* InternalPixelFilterNameList[]; + static const char* InternalVectorFilterNameList[]; + static const char* ExternalPixelFilterNameList[]; + }; + + typedef std::vector< FilterConfigCacheEntry > CacheVector; + + + CacheVector aImport; + CacheVector aExport; + sal_Bool bUseConfig; + + static sal_Bool bInitialized; + static sal_Int32 nIndType; + static sal_Int32 nIndUIName; + static sal_Int32 nIndDocumentService; + static sal_Int32 nIndFilterService; + static sal_Int32 nIndFlags; + static sal_Int32 nIndUserData; + static sal_Int32 nIndFileFormatVersion; + static sal_Int32 nIndTemplateName; + + static const char* InternalFilterListForSvxLight[]; + + SVT_DLLPRIVATE void ImplInit(); + SVT_DLLPRIVATE void ImplInitSmart(); + + public : + + sal_uInt16 GetImportFormatCount() const + { return sal::static_int_cast< sal_uInt16 >(aImport.size()); }; + sal_uInt16 GetImportFormatNumber( const String& rFormatName ); + sal_uInt16 GetImportFormatNumberForMediaType( const String& rMediaType ); + sal_uInt16 GetImportFormatNumberForShortName( const String& rShortName ); + sal_uInt16 GetImportFormatNumberForTypeName( const String& rType ); + String GetImportFilterName( sal_uInt16 nFormat ); + String GetImportFormatName( sal_uInt16 nFormat ); + String GetImportFormatExtension( sal_uInt16 nFormat, sal_Int32 nEntry = 0); + String GetImportFormatMediaType( sal_uInt16 nFormat ); + String GetImportFormatShortName( sal_uInt16 nFormat ); + String GetImportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry ); + String GetImportFilterType( sal_uInt16 nFormat ); + String GetImportFilterTypeName( sal_uInt16 nFormat ); + + sal_Bool IsImportInternalFilter( sal_uInt16 nFormat ); + sal_Bool IsImportPixelFormat( sal_uInt16 nFormat ); + sal_Bool IsImportDialog( sal_uInt16 nFormat ); + + sal_uInt16 GetExportFormatCount() const + { return sal::static_int_cast< sal_uInt16 >(aExport.size()); }; + sal_uInt16 GetExportFormatNumber( const String& rFormatName ); + sal_uInt16 GetExportFormatNumberForMediaType( const String& rMediaType ); + sal_uInt16 GetExportFormatNumberForShortName( const String& rShortName ); + sal_uInt16 GetExportFormatNumberForTypeName( const String& rType ); + String GetExportFilterName( sal_uInt16 nFormat ); + String GetExportFormatName( sal_uInt16 nFormat ); + String GetExportFormatExtension( sal_uInt16 nFormat, sal_Int32 nEntry = 0 ); + String GetExportFormatMediaType( sal_uInt16 nFormat ); + String GetExportFormatShortName( sal_uInt16 nFormat ); + String GetExportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry ); + String GetExportFilterTypeName( sal_uInt16 nFormat ); + String GetExportInternalFilterName( sal_uInt16 nFormat ); + + sal_Bool IsExportInternalFilter( sal_uInt16 nFormat ); + sal_Bool IsExportPixelFormat( sal_uInt16 nFormat ); + sal_Bool IsExportDialog( sal_uInt16 nFormat ); + + FilterConfigCache( sal_Bool bUseConfig ); + ~FilterConfigCache(); + +}; + +#endif // _FILTER_CONFIG_CACHE_HXX_ + diff --git a/svtools/source/filter/FilterConfigItem.cxx b/svtools/source/filter/FilterConfigItem.cxx new file mode 100644 index 000000000000..312f62af9d84 --- /dev/null +++ b/svtools/source/filter/FilterConfigItem.cxx @@ -0,0 +1,623 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using ::rtl::OUString; +using namespace ::utl ; // getProcessServiceFactory +using namespace ::com::sun::star::lang ; // XMultiServiceFactory +using namespace ::com::sun::star::beans ; // PropertyValue +using namespace ::com::sun::star::uno ; // Reference +using namespace ::com::sun::star::util ; // XChangesBatch +using namespace ::com::sun::star::awt ; // Size +using namespace ::com::sun::star::container ; // +using namespace ::com::sun::star::task ; // XStatusIndicator + +static sal_Bool ImpIsTreeAvailable( Reference< XMultiServiceFactory >& rXCfgProv, const String& rTree ) +{ + sal_Bool bAvailable = rTree.Len() != 0; + if ( bAvailable ) + { + xub_StrLen nTokenCount = rTree.GetTokenCount( (sal_Unicode)'/' ); + xub_StrLen i = 0; + + if ( rTree.GetChar( 0 ) == (sal_Unicode)'/' ) + i++; + if ( rTree.GetChar( rTree.Len() - 1 ) == (sal_Unicode)'/' ) + nTokenCount--; + + Any aAny; + aAny <<= (OUString)rTree.GetToken( i++, (sal_Unicode)'/' ); + + // creation arguments: nodepath + PropertyValue aPathArgument; + aPathArgument.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); + aPathArgument.Value = aAny; + + Sequence< Any > aArguments( 1 ); + aArguments[ 0 ] <<= aPathArgument; + + Reference< XInterface > xReadAccess; + try + { + xReadAccess = rXCfgProv->createInstanceWithArguments( + OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" ) ), + aArguments ); + } + catch ( ::com::sun::star::uno::Exception& ) + { + bAvailable = sal_False; + } + if ( xReadAccess.is() ) + { + for ( ; bAvailable && ( i < nTokenCount ); i++ ) + { + Reference< XHierarchicalNameAccess > xHierarchicalNameAccess + ( xReadAccess, UNO_QUERY ); + + if ( !xHierarchicalNameAccess.is() ) + bAvailable = sal_False; + else + { + String aNode( rTree.GetToken( i, (sal_Unicode)'/' ) ); + if ( !xHierarchicalNameAccess->hasByHierarchicalName( aNode ) ) + bAvailable = sal_False; + else + { + Any a( xHierarchicalNameAccess->getByHierarchicalName( aNode ) ); + try + { + a >>= xReadAccess; + } + catch ( ::com::sun::star::uno::Exception& ) + { + bAvailable = sal_False; + } + } + } + } + } + } + return bAvailable; +} + +void FilterConfigItem::ImpInitTree( const String& rSubTree ) +{ + bModified = sal_False; + + OUString sTree( ConfigManager::GetConfigBaseURL() ); + sTree += rSubTree; + Reference< XMultiServiceFactory > xSMGR = getProcessServiceFactory(); // get global uno service manager + + Reference< XMultiServiceFactory > xCfgProv( + xSMGR->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) ) ), + UNO_QUERY ); + + if ( xCfgProv.is() ) + { + if ( ImpIsTreeAvailable( xCfgProv, String( sTree ) ) ) + { + Any aAny; + // creation arguments: nodepath + PropertyValue aPathArgument; + aAny <<= sTree; + aPathArgument.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); + aPathArgument.Value = aAny; + + // creation arguments: commit mode + PropertyValue aModeArgument; + sal_Bool bAsyncron = sal_True; + aAny <<= bAsyncron; + aModeArgument.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "lazywrite" ) ); + aModeArgument.Value = aAny; + + Sequence< Any > aArguments( 2 ); + aArguments[ 0 ] <<= aPathArgument; + aArguments[ 1 ] <<= aModeArgument; + + try + { + xUpdatableView = xCfgProv->createInstanceWithArguments( + OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationUpdateAccess" ) ), + aArguments ); + if ( xUpdatableView.is() ) + xPropSet = Reference< XPropertySet >( xUpdatableView, UNO_QUERY ); + } + catch ( ::com::sun::star::uno::Exception& ) + { + DBG_ERROR( "FilterConfigItem::FilterConfigItem - Could not access configuration Key" ); + } + } + } +} + +FilterConfigItem::FilterConfigItem( const OUString& rSubTree ) +{ + ImpInitTree( rSubTree ); +} + +FilterConfigItem::FilterConfigItem( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >* pFilterData ) +{ + if ( pFilterData ) + aFilterData = *pFilterData; +} + +FilterConfigItem::FilterConfigItem( const OUString& rSubTree, + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >* pFilterData ) +{ + ImpInitTree( rSubTree ); + + if ( pFilterData ) + aFilterData = *pFilterData; +}; + +FilterConfigItem::~FilterConfigItem() +{ + if ( xUpdatableView.is() ) + { + if ( xPropSet.is() && bModified ) + { + Reference< XChangesBatch > xUpdateControl( xUpdatableView, UNO_QUERY ); + if ( xUpdateControl.is() ) + { + try + { + xUpdateControl->commitChanges(); + } + catch ( ::com::sun::star::uno::Exception& ) + { + DBG_ERROR( "FilterConfigItem::FilterConfigItem - Could not update configuration data" ); + } + } + } + } +} + +sal_Bool FilterConfigItem::ImplGetPropertyValue( Any& rAny, const Reference< XPropertySet >& rXPropSet, const OUString& rString, sal_Bool bTestPropertyAvailability ) +{ + sal_Bool bRetValue = sal_True; + + if ( rXPropSet.is() ) + { + if ( bTestPropertyAvailability ) + { + bRetValue = sal_False; + try + { + Reference< XPropertySetInfo > + aXPropSetInfo( rXPropSet->getPropertySetInfo() ); + if ( aXPropSetInfo.is() ) + bRetValue = aXPropSetInfo->hasPropertyByName( rString ); + } + catch( ::com::sun::star::uno::Exception& ) + { + // + } + } + if ( bRetValue ) + { + try + { + rAny = rXPropSet->getPropertyValue( rString ); + if ( !rAny.hasValue() ) + bRetValue = sal_False; + } + catch( ::com::sun::star::uno::Exception& ) + { + bRetValue = sal_False; + } + } + } + else + bRetValue = sal_False; + return bRetValue; +} + + +// if property is available it returns a pointer, +// otherwise the result is null +PropertyValue* FilterConfigItem::GetPropertyValue( Sequence< PropertyValue >& rPropSeq, const OUString& rName ) +{ + PropertyValue* pPropValue = NULL; + + sal_Int32 i, nCount; + for ( i = 0, nCount = rPropSeq.getLength(); i < nCount; i++ ) + { + if ( rPropSeq[ i ].Name == rName ) + { + pPropValue = &rPropSeq[ i ]; + break; + } + } + return pPropValue; +} + +/* if PropertySequence already includes a PropertyValue using the same name, the + corresponding PropertyValue is replaced, otherwise the given PropertyValue + will be appended */ + +sal_Bool FilterConfigItem::WritePropertyValue( Sequence< PropertyValue >& rPropSeq, const PropertyValue& rPropValue ) +{ + sal_Bool bRet = sal_False; + if ( rPropValue.Name.getLength() ) + { + sal_Int32 i, nCount; + for ( i = 0, nCount = rPropSeq.getLength(); i < nCount; i++ ) + { + if ( rPropSeq[ i ].Name == rPropValue.Name ) + break; + } + if ( i == nCount ) + rPropSeq.realloc( ++nCount ); + + rPropSeq[ i ] = rPropValue; + + bRet = sal_True; + } + return bRet; +} + +sal_Bool FilterConfigItem::ReadBool( const OUString& rKey, sal_Bool bDefault ) +{ + Any aAny; + sal_Bool bRetValue = bDefault; + PropertyValue* pPropVal = GetPropertyValue( aFilterData, rKey ); + if ( pPropVal ) + { + pPropVal->Value >>= bRetValue; + } + else if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) + { + aAny >>= bRetValue; + } + PropertyValue aBool; + aBool.Name = rKey; + aBool.Value <<= bRetValue; + WritePropertyValue( aFilterData, aBool ); + return bRetValue; +} + +sal_Int32 FilterConfigItem::ReadInt32( const OUString& rKey, sal_Int32 nDefault ) +{ + Any aAny; + sal_Int32 nRetValue = nDefault; + PropertyValue* pPropVal = GetPropertyValue( aFilterData, rKey ); + if ( pPropVal ) + { + pPropVal->Value >>= nRetValue; + } + else if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) + { + aAny >>= nRetValue; + } + PropertyValue aInt32; + aInt32.Name = rKey; + aInt32.Value <<= nRetValue; + WritePropertyValue( aFilterData, aInt32 ); + return nRetValue; +} + + +Size FilterConfigItem::ReadSize( const OUString& rKey, const Size& rDefault ) +{ + Any aAny; + Size aRetValue( rDefault ); + + const OUString sWidth( RTL_CONSTASCII_USTRINGPARAM( "LogicalWidth" ) ); + const OUString sHeight( RTL_CONSTASCII_USTRINGPARAM( "LogicalHeight" ) ); + + Reference< XPropertySet > aXPropSet; + try + { + PropertyValue* pPropWidth = GetPropertyValue( aFilterData, sWidth ); + PropertyValue* pPropHeight= GetPropertyValue( aFilterData, sHeight ); + if ( pPropWidth && pPropHeight ) + { + pPropWidth->Value >>= aRetValue.Width; + pPropHeight->Value >>= aRetValue.Height; + } + else if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) + { + if ( aAny >>= aXPropSet ) + { + if ( ImplGetPropertyValue( aAny, aXPropSet, sWidth, sal_True ) ) + aAny >>= aRetValue.Width; + if ( ImplGetPropertyValue( aAny, aXPropSet, sHeight, sal_True ) ) + aAny >>= aRetValue.Height; + } + } + } + catch ( ::com::sun::star::uno::Exception& ) + { + DBG_ERROR( "FilterConfigItem::ReadSize - could not read PropertyValue" ); + } + PropertyValue aWidth; + aWidth.Name = sWidth; + aWidth.Value <<= aRetValue.Width; + WritePropertyValue( aFilterData, aWidth ); + PropertyValue aHeight; + aHeight.Name = sHeight; + aHeight.Value <<= aRetValue.Height; + WritePropertyValue( aFilterData, aHeight ); + return aRetValue; +} + +OUString FilterConfigItem::ReadString( const OUString& rKey, const OUString& rDefault ) +{ + Any aAny; + OUString aRetValue( rDefault ); + PropertyValue* pPropVal = GetPropertyValue( aFilterData, rKey ); + if ( pPropVal ) + { + pPropVal->Value >>= aRetValue; + } + else if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) + { + aAny >>= aRetValue; + } + PropertyValue aString; + aString.Name = rKey; + aString.Value <<= aRetValue; + WritePropertyValue( aFilterData, aString ); + return aRetValue; +} + +Any FilterConfigItem::ReadAny( const ::rtl::OUString& rKey, const Any& rDefault ) +{ + Any aAny, aRetValue( rDefault ); + PropertyValue* pPropVal = GetPropertyValue( aFilterData, rKey ); + if ( pPropVal ) + { + aRetValue = pPropVal->Value; + } + else if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) + { + aRetValue = aAny; + } + PropertyValue aPropValue; + aPropValue.Name = rKey; + aPropValue.Value = aRetValue; + WritePropertyValue( aFilterData, aPropValue ); + return aRetValue; +} + +void FilterConfigItem::WriteBool( const OUString& rKey, sal_Bool bNewValue ) +{ + PropertyValue aBool; + aBool.Name = rKey; + aBool.Value <<= bNewValue; + WritePropertyValue( aFilterData, aBool ); + + if ( xPropSet.is() ) + { + Any aAny; + if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) + { + sal_Bool bOldValue; + if ( aAny >>= bOldValue ) + { + if ( bOldValue != bNewValue ) + { + aAny <<= bNewValue; + try + { + xPropSet->setPropertyValue( rKey, aAny ); + bModified = sal_True; + } + catch ( ::com::sun::star::uno::Exception& ) + { + DBG_ERROR( "FilterConfigItem::WriteBool - could not set PropertyValue" ); + } + } + } + } + } +} + +void FilterConfigItem::WriteInt32( const OUString& rKey, sal_Int32 nNewValue ) +{ + PropertyValue aInt32; + aInt32.Name = rKey; + aInt32.Value <<= nNewValue; + WritePropertyValue( aFilterData, aInt32 ); + + if ( xPropSet.is() ) + { + Any aAny; + + if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) + { + sal_Int32 nOldValue; + if ( aAny >>= nOldValue ) + { + if ( nOldValue != nNewValue ) + { + aAny <<= nNewValue; + try + { + xPropSet->setPropertyValue( rKey, aAny ); + bModified = sal_True; + } + catch ( ::com::sun::star::uno::Exception& ) + { + DBG_ERROR( "FilterConfigItem::WriteInt32 - could not set PropertyValue" ); + } + } + } + } + } +} + +void FilterConfigItem::WriteSize( const OUString& rKey, const Size& rNewValue ) +{ + const OUString sWidth( RTL_CONSTASCII_USTRINGPARAM( "LogicalWidth" ) ); + const OUString sHeight( RTL_CONSTASCII_USTRINGPARAM( "LogicalHeight" ) ); + + PropertyValue aWidth; + aWidth.Name = sWidth; + aWidth.Value <<= rNewValue.Width; + WritePropertyValue( aFilterData, aWidth ); + + PropertyValue aHeight; + aHeight.Name = sHeight; + aHeight.Value <<= rNewValue.Height; + WritePropertyValue( aFilterData, aHeight ); + + if ( xPropSet.is() ) + { + Any aAny; + sal_Int32 nOldWidth = rNewValue.Width; + sal_Int32 nOldHeight = rNewValue.Height; + + if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) + { + try + { + Reference< XPropertySet > aXPropSet; + if ( aAny >>= aXPropSet ) + { + if ( ImplGetPropertyValue( aAny, aXPropSet, sWidth, sal_True ) ) + aAny >>= nOldWidth; + if ( ImplGetPropertyValue( aAny, aXPropSet, sHeight, sal_True ) ) + aAny >>= nOldHeight; + } + if ( ( nOldWidth != rNewValue.Width ) || ( nOldHeight != rNewValue.Height ) ) + { + aAny <<= rNewValue.Width; + aXPropSet->setPropertyValue( sWidth, aAny ); + aAny <<= rNewValue.Height; + aXPropSet->setPropertyValue( sHeight, aAny ); + bModified = sal_True; + } + } + catch ( ::com::sun::star::uno::Exception& ) + { + DBG_ERROR( "FilterConfigItem::WriteSize - could not read PropertyValue" ); + } + } + } +} + +void FilterConfigItem::WriteString( const OUString& rKey, const OUString& rNewValue ) +{ + PropertyValue aString; + aString.Name = rKey; + aString.Value <<= rNewValue; + WritePropertyValue( aFilterData, aString ); + + if ( xPropSet.is() ) + { + Any aAny; + + if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) + { + OUString aOldValue; + if ( aAny >>= aOldValue ) + { + if ( aOldValue != rNewValue ) + { + aAny <<= rNewValue; + try + { + xPropSet->setPropertyValue( rKey, aAny ); + bModified = sal_True; + } + catch ( ::com::sun::star::uno::Exception& ) + { + DBG_ERROR( "FilterConfigItem::WriteInt32 - could not set PropertyValue" ); + } + } + } + } + } +} + +void FilterConfigItem::WriteAny( const OUString& rKey, const Any& rNewAny ) +{ + PropertyValue aPropValue; + aPropValue.Name = rKey; + aPropValue.Value = rNewAny; + WritePropertyValue( aFilterData, aPropValue ); + if ( xPropSet.is() ) + { + Any aAny; + if ( ImplGetPropertyValue( aAny, xPropSet, rKey, sal_True ) ) + { + if ( aAny != rNewAny ) + { + try + { + xPropSet->setPropertyValue( rKey, rNewAny ); + bModified = sal_True; + } + catch ( com::sun::star::uno::Exception& ) + { + DBG_ERROR( "FilterConfigItem::WriteAny - could not set PropertyValue" ); + + } + } + } + } +} + +// ------------------------------------------------------------------------ + +Sequence< PropertyValue > FilterConfigItem::GetFilterData() const +{ + return aFilterData; +} + +// ------------------------------------------------------------------------ + +Reference< XStatusIndicator > FilterConfigItem::GetStatusIndicator() const +{ + Reference< XStatusIndicator > xStatusIndicator; + const rtl::OUString sStatusIndicator( RTL_CONSTASCII_USTRINGPARAM( "StatusIndicator" ) ); + + sal_Int32 i, nCount = aFilterData.getLength(); + for ( i = 0; i < nCount; i++ ) + { + if ( aFilterData[ i ].Name == sStatusIndicator ) + { + aFilterData[ i ].Value >>= xStatusIndicator; + break; + } + } + return xStatusIndicator; +} + diff --git a/svtools/source/filter/SvFilterOptionsDialog.cxx b/svtools/source/filter/SvFilterOptionsDialog.cxx new file mode 100644 index 000000000000..1c4eeeff1bbf --- /dev/null +++ b/svtools/source/filter/SvFilterOptionsDialog.cxx @@ -0,0 +1,270 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include "SvFilterOptionsDialog.hxx" +#include +#include +#include "FilterConfigCache.hxx" +#include +#include +#include +#include +#include "exportdialog.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include "vcl/svapp.hxx" + +using namespace ::rtl; +using namespace ::com::sun::star; + +// ------------------------- +// - SvFilterOptionsDialog - +// ------------------------- + +uno::Reference< uno::XInterface > + SAL_CALL SvFilterOptionsDialog_CreateInstance( + const uno::Reference< lang::XMultiServiceFactory > & _rxFactory ) +{ + return static_cast< ::cppu::OWeakObject* > ( new SvFilterOptionsDialog( _rxFactory ) ); +} + +OUString SvFilterOptionsDialog_getImplementationName() + throw( uno::RuntimeException ) +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.SvFilterOptionsDialog" ) ); +} +#define SERVICE_NAME "com.sun.star.ui.dialog.FilterOptionsDialog" +sal_Bool SAL_CALL SvFilterOptionsDialog_supportsService( const OUString& ServiceName ) + throw( uno::RuntimeException ) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) ); +} + +uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog_getSupportedServiceNames() + throw( uno::RuntimeException ) +{ + uno::Sequence< OUString > aRet(1); + OUString* pArray = aRet.getArray(); + pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) ); + return aRet; +} +#undef SERVICE_NAME + +// ----------------------------------------------------------------------------- + +SvFilterOptionsDialog::SvFilterOptionsDialog( const uno::Reference< lang::XMultiServiceFactory > xMgr ) : + mxMgr ( xMgr ), + meFieldUnit ( FUNIT_CM ), + mbExportSelection ( sal_False ) +{ +} + +// ----------------------------------------------------------------------------- + +SvFilterOptionsDialog::~SvFilterOptionsDialog() +{ +} + +// ----------------------------------------------------------------------------- + +void SAL_CALL SvFilterOptionsDialog::acquire() throw() +{ + OWeakObject::acquire(); +} + +// ----------------------------------------------------------------------------- + +void SAL_CALL SvFilterOptionsDialog::release() throw() +{ + OWeakObject::release(); +} + +// XInitialization +void SAL_CALL SvFilterOptionsDialog::initialize( const uno::Sequence< uno::Any > & ) + throw ( uno::Exception, uno::RuntimeException ) +{ +} + +// XServiceInfo +OUString SAL_CALL SvFilterOptionsDialog::getImplementationName() + throw( uno::RuntimeException ) +{ + return SvFilterOptionsDialog_getImplementationName(); +} +sal_Bool SAL_CALL SvFilterOptionsDialog::supportsService( const OUString& rServiceName ) + throw( uno::RuntimeException ) +{ + return SvFilterOptionsDialog_supportsService( rServiceName ); +} +uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog::getSupportedServiceNames() + throw ( uno::RuntimeException ) +{ + return SvFilterOptionsDialog_getSupportedServiceNames(); +} + + +// XPropertyAccess +uno::Sequence< beans::PropertyValue > SvFilterOptionsDialog::getPropertyValues() + throw ( uno::RuntimeException ) +{ + sal_Int32 i, nCount; + for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ ) + { + if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) ) + break; + } + if ( i == nCount ) + maMediaDescriptor.realloc( ++nCount ); + + // the "FilterData" Property is an Any that will contain our PropertySequence of Values + maMediaDescriptor[ i ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "FilterData" ) ); + maMediaDescriptor[ i ].Value <<= maFilterDataSequence; + return maMediaDescriptor; +} + +void SvFilterOptionsDialog::setPropertyValues( const uno::Sequence< beans::PropertyValue > & aProps ) + throw ( beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException ) +{ + maMediaDescriptor = aProps; + + sal_Int32 i, nCount; + for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ ) + { + if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) ) + { + maMediaDescriptor[ i ].Value >>= maFilterDataSequence; + } + else if ( maMediaDescriptor[ i ].Name.equalsAscii( "SelectionOnly" ) ) + { + maMediaDescriptor[ i ].Value >>= mbExportSelection; + } + } +} + +// XExecutableDialog +void SvFilterOptionsDialog::setTitle( const OUString& aTitle ) + throw ( uno::RuntimeException ) +{ + maDialogTitle = aTitle; +} + +sal_Int16 SvFilterOptionsDialog::execute() + throw ( uno::RuntimeException ) +{ + sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL; + + String aFilterNameStr( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) ); + String aInternalFilterName; + sal_Int32 j, nCount = maMediaDescriptor.getLength(); + for ( j = 0; j < nCount; j++ ) + { + if ( maMediaDescriptor[ j ].Name.equals( aFilterNameStr ) ) + { + OUString aStr; + maMediaDescriptor[ j ].Value >>= aStr; + aInternalFilterName = aStr; + aInternalFilterName.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "draw_" ) ), String(), 0 ); + aInternalFilterName.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "impress_" ) ), String(), 0 ); + break; + } + } + if ( aInternalFilterName.Len() ) + { + GraphicFilter aGraphicFilter( sal_True ); + + sal_uInt16 nFormat, nFilterCount = aGraphicFilter.pConfig->GetExportFormatCount(); + for ( nFormat = 0; nFormat < nFilterCount; nFormat++ ) + { + if ( aGraphicFilter.pConfig->GetExportInternalFilterName( nFormat ) == aInternalFilterName ) + break; + } + if ( nFormat < nFilterCount ) + { + FltCallDialogParameter aFltCallDlgPara( Application::GetDefDialogParent(), NULL, meFieldUnit ); + aFltCallDlgPara.aFilterData = maFilterDataSequence; + + ByteString aResMgrName( "svt", 3 ); + ResMgr* pResMgr; + + pResMgr = ResMgr::CreateResMgr( aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() ); + aFltCallDlgPara.pResMgr = pResMgr; + + aFltCallDlgPara.aFilterExt = aGraphicFilter.pConfig->GetExportFormatShortName( nFormat ); + sal_Bool bIsPixelFormat( aGraphicFilter.pConfig->IsExportPixelFormat( nFormat ) ); + if ( ExportDialog( aFltCallDlgPara, mxMgr, mxSourceDocument, mbExportSelection, bIsPixelFormat ).Execute() == RET_OK ) + nRet = ui::dialogs::ExecutableDialogResults::OK; + + delete pResMgr; + + // taking the out parameter from the dialog + maFilterDataSequence = aFltCallDlgPara.aFilterData; + } + } + return nRet; +} + +// XEmporter +void SvFilterOptionsDialog::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc ) + throw ( lang::IllegalArgumentException, uno::RuntimeException ) +{ + mxSourceDocument = xDoc; + + // try to set the corresponding metric unit + String aConfigPath; + uno::Reference< lang::XServiceInfo > xServiceInfo + ( xDoc, uno::UNO_QUERY ); + if ( xServiceInfo.is() ) + { + if ( xServiceInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ) ) + aConfigPath = String( RTL_CONSTASCII_USTRINGPARAM( "Office.Impress/Layout/Other/MeasureUnit" ) ); + else if ( xServiceInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ) ) + aConfigPath = String( RTL_CONSTASCII_USTRINGPARAM( "Office.Draw/Layout/Other/MeasureUnit" ) ); + if ( aConfigPath.Len() ) + { + FilterConfigItem aConfigItem( aConfigPath ); + String aPropertyName; + SvtSysLocale aSysLocale; + if ( aSysLocale.GetLocaleDataPtr()->getMeasurementSystemEnum() == MEASURE_METRIC ) + aPropertyName = String( RTL_CONSTASCII_USTRINGPARAM( "Metric" ) ); + else + aPropertyName = String( RTL_CONSTASCII_USTRINGPARAM( "NonMetric" ) ); + meFieldUnit = (FieldUnit)aConfigItem.ReadInt32( aPropertyName, FUNIT_CM ); + } + } +} + diff --git a/svtools/source/filter/SvFilterOptionsDialog.hxx b/svtools/source/filter/SvFilterOptionsDialog.hxx new file mode 100644 index 000000000000..027fac99c2e8 --- /dev/null +++ b/svtools/source/filter/SvFilterOptionsDialog.hxx @@ -0,0 +1,105 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SV_FILTER_OPTIONS_DIALOG_HXX_ +#define _SV_FILTER_OPTIONS_DIALOG_HXX_ + +#include +#include +#include +#include +#include +#include +#include +#include + +class SvFilterOptionsDialog : public cppu::WeakImplHelper5 +< + com::sun::star::document::XExporter, + com::sun::star::ui::dialogs::XExecutableDialog, + com::sun::star::beans::XPropertyAccess, + com::sun::star::lang::XInitialization, + com::sun::star::lang::XServiceInfo +> +{ + const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > + mxMgr; + com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > + maMediaDescriptor; + com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > + maFilterDataSequence; + com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + mxSourceDocument; + + rtl::OUString maDialogTitle; + FieldUnit meFieldUnit; + sal_Bool mbExportSelection; + +public: + + SvFilterOptionsDialog( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > _rxORB ); + ~SvFilterOptionsDialog(); + + // XInterface + virtual void SAL_CALL acquire() throw(); + virtual void SAL_CALL release() throw(); + + // XInitialization + virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< com::sun::star::uno::Any > & aArguments ) + throw ( com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException ); + + // XServiceInfo + virtual rtl::OUString SAL_CALL getImplementationName() + throw ( com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService( const rtl::OUString& ServiceName ) + throw ( com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() + throw ( com::sun::star::uno::RuntimeException ); + + // XPropertyAccess + virtual com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPropertyValues() + throw ( com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > & aProps ) + throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, + ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + // XExecuteDialog + virtual sal_Int16 SAL_CALL execute() + throw ( com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) + throw ( ::com::sun::star::uno::RuntimeException ); + + // XExporter + virtual void SAL_CALL setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc ) + throw ( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException ); + +}; + + +#endif // _SV_FILTER_OPTIONS_DIALOG_HXX_ + diff --git a/svtools/source/filter/exportdialog.cxx b/svtools/source/filter/exportdialog.cxx new file mode 100644 index 000000000000..20cc46a30ab5 --- /dev/null +++ b/svtools/source/filter/exportdialog.cxx @@ -0,0 +1,1513 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#ifndef GCC +# pragma hdrstop +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "exportdialog.hxx" +#include "exportdialog.hrc" + +#define FORMAT_UNKNOWN 0 +#define FORMAT_JPG 1 +#define FORMAT_PNG 2 +#define FORMAT_BMP 3 +#define FORMAT_GIF 4 +#define FORMAT_PBM 5 +#define FORMAT_PGM 6 +#define FORMAT_PPM 7 +#define FORMAT_PCT 8 +#define FORMAT_RAS 9 +#define FORMAT_TIF 10 +#define FORMAT_XPM 11 +#define FORMAT_WMF 12 +#define FORMAT_EMF 13 +#define FORMAT_EPS 14 +#define FORMAT_MET 15 +#define FORMAT_SVG 16 +#define FORMAT_SVM 17 + +#define UNIT_DEFAULT -1 +#define UNIT_INCH 0 +#define UNIT_CM 1 +#define UNIT_MM 2 +#define UNIT_POINT 3 +#define UNIT_PIXEL 4 +#define UNIT_MAX_ID UNIT_PIXEL + +using namespace ::com::sun::star; + +static sal_Int16 GetFilterFormat( String& rExt ) +{ + sal_Int16 nFormat = FORMAT_UNKNOWN; + ByteString aExt( rExt, RTL_TEXTENCODING_UTF8 ); + if ( aExt.Equals( "JPG" ) ) + nFormat = FORMAT_JPG; + else if ( aExt.Equals( "PNG" ) ) + nFormat = FORMAT_PNG; + else if ( aExt.Equals( "BMP" ) ) + nFormat = FORMAT_BMP; + else if ( aExt.Equals( "GIF" ) ) + nFormat = FORMAT_GIF; + else if ( aExt.Equals( "PBM" ) ) + nFormat = FORMAT_PBM; + else if ( aExt.Equals( "PGM" ) ) + nFormat = FORMAT_PGM; + else if ( aExt.Equals( "PPM" ) ) + nFormat = FORMAT_PPM; + else if ( aExt.Equals( "PCT" ) ) + nFormat = FORMAT_PCT; + else if ( aExt.Equals( "RAS" ) ) + nFormat = FORMAT_RAS; + else if ( aExt.Equals( "TIF" ) ) + nFormat = FORMAT_TIF; + else if ( aExt.Equals( "XPM" ) ) + nFormat = FORMAT_XPM; + else if ( aExt.Equals( "WMF" ) ) + nFormat = FORMAT_WMF; + else if ( aExt.Equals( "EMF" ) ) + nFormat = FORMAT_EMF; + else if ( aExt.Equals( "EPS" ) ) + nFormat = FORMAT_EPS; + else if ( aExt.Equals( "MET" ) ) + nFormat = FORMAT_MET; + else if ( aExt.Equals( "SVG" ) ) + nFormat = FORMAT_SVG; + else if ( aExt.Equals( "SVM" ) ) + nFormat = FORMAT_SVM; + return nFormat; +} + +static MapUnit GetMapUnit( sal_Int32 nUnit ) +{ + MapUnit aMapUnit( MAP_PIXEL ); + switch( nUnit ) + { + case UNIT_INCH : aMapUnit = MAP_INCH; break; + case UNIT_CM : aMapUnit = MAP_CM; break; + case UNIT_MM : aMapUnit = MAP_MM; break; + case UNIT_POINT : aMapUnit = MAP_POINT; break; + case UNIT_PIXEL : aMapUnit = MAP_PIXEL; break; + } + return aMapUnit; +} + +sal_Int32 ExportDialog::GetDefaultUnit() +{ + sal_Int32 nDefaultUnit = UNIT_CM; + switch( mrFltCallPara.eFieldUnit ) + { +// case FUNIT_NONE : +// case FUNIT_PERCENT : +// case FUNIT_CUSTOM : + default: nDefaultUnit = UNIT_CM; break; + + case FUNIT_MILE : // PASSTHROUGH INTENDED + case FUNIT_FOOT : + case FUNIT_TWIP : + case FUNIT_PICA : nDefaultUnit = UNIT_INCH; break; + + case FUNIT_KM : // PASSTHROUGH INTENDED + case FUNIT_M : + case FUNIT_100TH_MM : nDefaultUnit = UNIT_CM; break; + + case FUNIT_INCH : nDefaultUnit = UNIT_INCH; break; + case FUNIT_CM : nDefaultUnit = UNIT_CM; break; + case FUNIT_MM : nDefaultUnit = UNIT_MM; break; + case FUNIT_POINT : nDefaultUnit = UNIT_POINT; break; + } + return nDefaultUnit; +} + +static basegfx::B2DRange GetShapeRangeForXShape( const uno::Reference< drawing::XShape >& rxShape, + const uno::Reference< graphic::XPrimitiveFactory2D >& rxPrimitiveFactory2D, const uno::Sequence< beans::PropertyValue >& rViewInformation ) +{ + basegfx::B2DRange aShapeRange; + + const uno::Sequence< beans::PropertyValue > aParams; + const uno::Sequence< uno::Reference< graphic::XPrimitive2D > > aPrimitiveSequence( rxPrimitiveFactory2D->createPrimitivesFromXShape( rxShape, aParams ) ); + + const sal_Int32 nCount = aPrimitiveSequence.getLength(); + for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ ) + { + const geometry::RealRectangle2D aRect( aPrimitiveSequence[ nIndex ]->getRange( rViewInformation ) ); + aShapeRange.expand( basegfx::B2DTuple( aRect.X1, aRect.Y1 ) ); + aShapeRange.expand( basegfx::B2DTuple( aRect.X2, aRect.Y2 ) ); + } + return aShapeRange; +} + +uno::Sequence< beans::PropertyValue > ExportDialog::GetFilterData( sal_Bool bUpdateConfig ) +{ + if ( bUpdateConfig ) + { + sal_Int32 nUnit = maLbSizeX.GetSelectEntryPos(); + if ( nUnit < 0 ) + nUnit = UNIT_CM; + + if ( ( mnInitialResolutionUnit == UNIT_DEFAULT ) && ( nUnit == GetDefaultUnit() ) ) + nUnit = UNIT_DEFAULT; + + // updating ui configuration + if ( mbIsPixelFormat ) + { + if ( nUnit > UNIT_MAX_ID ) + nUnit = UNIT_PIXEL; + + sal_Int32 nResolution = maNfResolution.GetValue(); + if ( nResolution < 1 ) + nResolution = 96; + + mpOptionsItem->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelExportUnit" ) ), nUnit ); + mpOptionsItem->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelExportResolution" ) ), nResolution ); + mpOptionsItem->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelExportResolutionUnit" ) ), maLbResolution.GetSelectEntryPos() ); + } + else + { + if ( nUnit >= UNIT_PIXEL ) + nUnit = UNIT_CM; + + mpOptionsItem->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "VectorExportUnit" ) ), nUnit ); + } + } + + FilterConfigItem* pFilterOptions; + if ( bUpdateConfig ) + pFilterOptions = mpFilterOptionsItem; + else + { + uno::Sequence< beans::PropertyValue > aFilterData( mpFilterOptionsItem->GetFilterData() ); + pFilterOptions = new FilterConfigItem( &aFilterData ); + } + + const String sLogicalWidth( String( RTL_CONSTASCII_USTRINGPARAM( "LogicalWidth" ) ) ); + const String sLogicalHeight( String( RTL_CONSTASCII_USTRINGPARAM( "LogicalHeight" ) ) ); + if ( mbIsPixelFormat ) + { + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelWidth" ) ), static_cast< sal_Int32 >( maSize.Width ) ); + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelHeight" ) ), static_cast< sal_Int32 >( maSize.Height ) ); + if ( maResolution.Width && maResolution.Height ) + { + const double f100thmmPerPixelX = 100000.0 / maResolution.Width; + const double f100thmmPerPixelY = 100000.0 / maResolution.Height; + sal_Int32 nLogicalWidth = static_cast< sal_Int32 >( f100thmmPerPixelX * maSize.Width ); + sal_Int32 nLogicalHeight= static_cast< sal_Int32 >( f100thmmPerPixelY * maSize.Height ); + if ( nLogicalWidth && nLogicalHeight ) + { + pFilterOptions->WriteInt32( sLogicalWidth, nLogicalWidth ); + pFilterOptions->WriteInt32( sLogicalHeight, nLogicalHeight ); + } + } + } + else + { + pFilterOptions->WriteInt32( sLogicalWidth, static_cast< sal_Int32 >( maSize.Width ) ); + pFilterOptions->WriteInt32( sLogicalHeight, static_cast< sal_Int32 >( maSize.Height ) ); + } + switch ( mnFormat ) + { + case FORMAT_JPG : + { + sal_Int32 nColor = maLbColorDepth.GetSelectEntryPos(); + if ( nColor == 1 ) + nColor = 0; + else + nColor = 1; + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "ColorMode" ) ), nColor ); + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Quality" ) ), static_cast< sal_Int32 >( maSbCompression.GetThumbPos() ) ); + } + break; + + case FORMAT_PNG : + { + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Compression" ) ), static_cast< sal_Int32 >( maSbCompression.GetThumbPos() ) ); + sal_Int32 nInterlace = 0; + if ( maCbInterlaced.IsChecked() ) + nInterlace++; + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Interlaced" ) ), nInterlace ); + } + break; + + case FORMAT_BMP : + { + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Color" ) ), maLbColorDepth.GetSelectEntryPos() + 1 ); + pFilterOptions->WriteBool( String( RTL_CONSTASCII_USTRINGPARAM( "RLE_Coding" ) ), maCbRLEEncoding.IsChecked() ); + } + break; + + case FORMAT_GIF : + { + sal_Int32 nValue = 0; + if ( maCbInterlaced.IsChecked() ) + nValue++; + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Interlaced" ) ), nValue ); + + nValue = 0; + if ( maCbSaveTransparency.IsChecked() ) + nValue++; + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Translucent" ) ), nValue ); + } + break; + + case FORMAT_PBM : + case FORMAT_PGM : + case FORMAT_PPM : + { + sal_Int32 nFormat = 0; + if ( maRbText.IsChecked() ) + nFormat++; + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "FileFormat" ) ), nFormat ); + } + break; + + case FORMAT_EPS : + { + sal_Int32 nCheck = 0; + if ( maCbEPSPreviewTIFF.IsChecked() ) + nCheck++; + if ( maCbEPSPreviewEPSI.IsChecked() ) + nCheck += 2; + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Preview" ) ), nCheck ); + + nCheck = 1; + if ( maRbEPSLevel2.IsChecked() ) + nCheck++; + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ), nCheck ); + + nCheck = 1; + if ( maRbEPSColorFormat2.IsChecked() ) + nCheck++; + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "ColorFormat" ) ), nCheck ); + + nCheck = 1; + if ( maRbEPSCompressionNone.IsChecked() ) + nCheck++; + pFilterOptions->WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "CompressionMode" ) ), nCheck ); + } + break; + } + + uno::Sequence< beans::PropertyValue > aRet( pFilterOptions->GetFilterData() ); + if ( bUpdateConfig == sal_False ) + delete pFilterOptions; + return aRet; +} + +// +awt::Size ExportDialog::GetOriginalSize() +{ + basegfx::B2DRange aShapesRange; + + if ( mxPage.is () ) + { + uno::Reference< beans::XPropertySet > xPagePropSet( mxPage, uno::UNO_QUERY ); + if ( xPagePropSet.is() ) + { + sal_Int32 nWidth = 0; + sal_Int32 nHeight= 0; + com::sun::star::uno::Any aAny; + aAny = xPagePropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ) ) ); + aAny >>= nWidth; + aAny = xPagePropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" ) ) ); + aAny >>= nHeight; + aShapesRange = basegfx::B2DRange( 0, 0, nWidth, nHeight ); + } + } + else + { + uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory( + mxMgr->createInstance( String( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.PrimitiveFactory2D" ) ) ), uno::UNO_QUERY ); + if ( xPrimitiveFactory.is() ) + { + basegfx::B2DHomMatrix aViewTransformation( Application::GetDefaultDevice()->GetViewTransformation() ); + com::sun::star::geometry::AffineMatrix2D aTransformation; + aTransformation.m00 = aViewTransformation.get(0,0); + aTransformation.m01 = aViewTransformation.get(0,1); + aTransformation.m02 = aViewTransformation.get(0,2); + aTransformation.m10 = aViewTransformation.get(1,0); + aTransformation.m11 = aViewTransformation.get(1,1); + aTransformation.m12 = aViewTransformation.get(1,2); + + const rtl::OUString sViewTransformation( RTL_CONSTASCII_USTRINGPARAM( "ViewTransformation" ) ); + uno::Sequence< beans::PropertyValue > aViewInformation( 1 ); + aViewInformation[ 0 ].Value <<= aTransformation; + aViewInformation[ 0 ].Name = sViewTransformation; + + if ( mxShape.is() ) + aShapesRange = GetShapeRangeForXShape( mxShape, xPrimitiveFactory, aViewInformation ); + else if ( mxShapes.is() ) + { + const sal_Int32 nCount = mxShapes->getCount(); + for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ ) + { + uno::Reference< drawing::XShape > xShape; + mxShapes->getByIndex( nIndex ) >>= xShape; + aShapesRange.expand( GetShapeRangeForXShape( xShape, xPrimitiveFactory, aViewInformation ) ); + } + } + } + } + return awt::Size( static_cast(aShapesRange.getWidth()), static_cast(aShapesRange.getHeight()) ); +} + +void ExportDialog::GetGraphicSource() +{ + if ( mxSourceDocument.is() ) + { + uno::Reference< frame::XModel > xModel( mxSourceDocument, uno::UNO_QUERY ); + if ( xModel.is() ) + { + uno::Reference< frame::XController > xController( xModel->getCurrentController() ); + if ( xController.is() ) + { + if ( mbExportSelection ) // check if there is a selection + { + uno::Reference< view::XSelectionSupplier > xSelectionSupplier( xController, uno::UNO_QUERY ); + if ( xSelectionSupplier.is() ) + { + uno::Any aAny( xSelectionSupplier->getSelection() ); + if ( ! ( aAny >>= mxShapes ) ) + aAny >>= mxShape; + } + } + if ( !mxShape.is() && !mxShapes.is() ) + { + uno::Reference< drawing::XDrawView > xDrawView( xController, uno::UNO_QUERY ); + if ( xDrawView.is() ) + { + uno::Reference< drawing::XDrawPage > xCurrentPage( xDrawView->getCurrentPage() ); + if ( xCurrentPage.is() ) + { + mxPage = xCurrentPage; // exporting whole page + } + } + } + } + } + } +} + +sal_Bool ExportDialog::GetGraphicStream() +{ + sal_Bool bRet = sal_False; + + if ( !IsTempExportAvailable() ) + { + delete mpTempStream, mpTempStream = new SvMemoryStream(); + maBitmap = Bitmap(); + return bRet; + } + + sal_Bool bRecreateOutputStream = mpTempStream->Tell() == 0; + + static uno::Sequence< beans::PropertyValue > aOldFilterData; + uno::Sequence< beans::PropertyValue > aNewFilterData( GetFilterData( sal_False ) ); + if ( aOldFilterData != aNewFilterData ) + { + aOldFilterData = aNewFilterData; + bRecreateOutputStream = sal_True; + } + try + { + if ( bRecreateOutputStream ) + { + delete mpTempStream, mpTempStream = new SvMemoryStream(); + maBitmap = Bitmap(); + + uno::Reference < io::XStream > xStream( new utl::OStreamWrapper( *mpTempStream ) ); + uno::Reference < io::XOutputStream > xOutputStream( xStream->getOutputStream() ); + + uno::Reference< document::XExporter > xGraphicExporter( + mxMgr->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GraphicExportFilter") ) ), uno::UNO_QUERY_THROW ); + uno::Reference< document::XFilter > xFilter( xGraphicExporter, uno::UNO_QUERY_THROW ); + + sal_Int32 nProperties = 2; + uno::Sequence< beans::PropertyValue > aFilterData( nProperties ); + + + rtl::OUString sFormat( maExt ); + uno::Sequence< beans::PropertyValue > aDescriptor( 3 ); + aDescriptor[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("OutputStream") ); + aDescriptor[0].Value <<= xOutputStream; + aDescriptor[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FilterName") ); + aDescriptor[1].Value <<= sFormat; + aDescriptor[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FilterData") ); + aDescriptor[2].Value <<= aNewFilterData; + + uno::Reference< lang::XComponent > xSourceDoc; + if ( mxPage.is() ) + xSourceDoc = uno::Reference< lang::XComponent >( mxPage, uno::UNO_QUERY_THROW ); + else if ( mxShapes.is() ) + xSourceDoc = uno::Reference< lang::XComponent >( mxShapes, uno::UNO_QUERY_THROW ); + else if ( mxShape.is() ) + xSourceDoc = uno::Reference< lang::XComponent >( mxShape, uno::UNO_QUERY_THROW );; + if ( xSourceDoc.is() ) + { + xGraphicExporter->setSourceDocument( xSourceDoc ); + xFilter->filter( aDescriptor ); + bRet = sal_True; + + if ( mnFormat == FORMAT_JPG ) + { + mpTempStream->Seek( STREAM_SEEK_TO_BEGIN ); + maBitmap = GetGraphicBitmap( *mpTempStream ); + mpTempStream->Seek( STREAM_SEEK_TO_END ); + } + } + } + else + bRet = sal_True; + } + catch( uno::Exception& ) + { + + // ups + + } + return bRet; +} + +Bitmap ExportDialog::GetGraphicBitmap( SvStream& rInputStream ) +{ + Bitmap aRet; + Graphic aGraphic; + GraphicFilter aFilter( sal_False ); + if ( aFilter.ImportGraphic( aGraphic, String(), rInputStream, GRFILTER_FORMAT_NOTFOUND, NULL, 0, NULL ) == GRFILTER_OK ) + { + aRet = aGraphic.GetBitmap(); + } + return aRet; +} + +sal_uInt32 ExportDialog::GetRawFileSize() const +{ + sal_uInt64 nRawFileSize = 0; + if ( mbIsPixelFormat ) + { + sal_Int32 nBitsPerPixel = 24; + String aEntry( maLbColorDepth.GetSelectEntry() ); + if ( ms1BitTreshold == aEntry ) + nBitsPerPixel = 1; + else if ( ms1BitDithered == aEntry ) + nBitsPerPixel = 1; + else if ( ms4BitGrayscale == aEntry ) + nBitsPerPixel = 4; + else if ( ms4BitColorPalette == aEntry ) + nBitsPerPixel = 8; + else if ( ms8BitGrayscale == aEntry ) + nBitsPerPixel = 8; + else if ( ms8BitColorPalette == aEntry ) + nBitsPerPixel = 8; + else if ( ms24BitColor == aEntry ) + nBitsPerPixel = 24; + + if ( mbIsPixelFormat ) + { + nRawFileSize = ( maSize.Width * nBitsPerPixel + 7 ) &~ 7; // rounding up to 8 bits + nRawFileSize /= 8; // in bytes + nRawFileSize *= maSize.Height; + } + if ( nRawFileSize > SAL_MAX_UINT32 ) + nRawFileSize = 0; + } + return static_cast< sal_uInt32 >( nRawFileSize ); +} + +// checks if the source dimension/resolution is not too big +// to determine the exact graphic output size and preview for jpg +sal_Bool ExportDialog::IsTempExportAvailable() const +{ + return GetRawFileSize() < static_cast< sal_uInt32 >( mnMaxFilesizeForRealtimePreview ); +} + +ExportDialog::ExportDialog( FltCallDialogParameter& rPara, + const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > rxMgr, + const com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& rxSourceDocument, + sal_Bool bExportSelection, sal_Bool bIsPixelFormat ) : + ModalDialog ( rPara.pWindow, ResId( DLG_EXPORT, *rPara.pResMgr ) ), + mrFltCallPara ( rPara ), + mpMgr ( rPara.pResMgr ), + mxMgr ( rxMgr ), + mxSourceDocument ( rxSourceDocument ), + maFlExportSize ( this, ResId( FL_EXPORT_SIZE, *rPara.pResMgr ) ), + maFtSizeX ( this, ResId( FT_SIZEX, *rPara.pResMgr ) ), + maMfSizeX ( this, ResId( MF_SIZEX, *rPara.pResMgr ) ), + maLbSizeX ( this, ResId( LB_SIZEX, *rPara.pResMgr ) ), + maFtSizeY ( this, ResId( FT_SIZEY, *rPara.pResMgr ) ), + maMfSizeY ( this, ResId( MF_SIZEY, *rPara.pResMgr ) ), + maLbSizeY ( this, ResId( LB_SIZEY, *rPara.pResMgr ) ), + maFtResolution ( this, ResId( FT_RESOLUTION, *rPara.pResMgr ) ), + maNfResolution ( this, ResId( NF_RESOLUTION, *rPara.pResMgr ) ), + maLbResolution ( this, ResId( LB_RESOLUTION, *rPara.pResMgr ) ), + maFlColorDepth ( this, ResId( FL_COLOR_DEPTH, *rPara.pResMgr ) ), + maLbColorDepth ( this, ResId( LB_COLOR_DEPTH, *rPara.pResMgr ) ), + maFlJPGQuality ( this, ResId( FL_JPG_QUALITY, *rPara.pResMgr ) ), + maFlMode ( this, ResId( FL_MODE, *rPara.pResMgr ) ), + maFlPBMOptions ( this, ResId( FL_PBM_OPTIONS, *rPara.pResMgr ) ), + maSbCompression ( this, ResId( SB_COMPRESSION, *rPara.pResMgr ) ), + maNfCompression ( this, ResId( NF_COMPRESSION, *rPara.pResMgr ) ), + maFtJPGMin ( this, ResId( FT_JPG_MIN, *rPara.pResMgr ) ), + maFtJPGMax ( this, ResId( FT_JPG_MAX, *rPara.pResMgr ) ), + maFtPNGMin ( this, ResId( FT_PNG_MIN, *rPara.pResMgr ) ), + maFtPNGMax ( this, ResId( FT_PNG_MAX, *rPara.pResMgr ) ), + maCbJPGPreview ( this, ResId( CB_JPG_PREVIEW, *rPara.pResMgr ) ), + maCbInterlaced ( this, ResId( CB_INTERLACED, *rPara.pResMgr ) ), + maCbRLEEncoding ( this, ResId( CB_RLE_ENCODING, *rPara.pResMgr ) ), + maFlGIFDrawingObjects ( this, ResId( FL_GIF_DRAWING_OBJECTS, *rPara.pResMgr ) ), + maCbSaveTransparency ( this, ResId( CB_SAVE_TRANSPARENCY, *rPara.pResMgr ) ), + maRbBinary ( this, ResId( RB_BINARY, *rPara.pResMgr ) ), + maRbText ( this, ResId( RB_TEXT, *rPara.pResMgr ) ), + maFlEPSPreview ( this, ResId( FL_EPS_PREVIEW, *rPara.pResMgr ) ), + maCbEPSPreviewTIFF ( this, ResId( CB_EPS_PREVIEW_TIFF, *rPara.pResMgr ) ), + maCbEPSPreviewEPSI ( this, ResId( CB_EPS_PREVIEW_EPSI, *rPara.pResMgr ) ), + maFlEPSVersion ( this, ResId( FL_EPS_VERSION, *rPara.pResMgr ) ), + maRbEPSLevel1 ( this, ResId( RB_EPS_LEVEL1, *rPara.pResMgr ) ), + maRbEPSLevel2 ( this, ResId( RB_EPS_LEVEL2, *rPara.pResMgr ) ), + maFlEPSColorFormat ( this, ResId( FL_EPS_COLOR_FORMAT, *rPara.pResMgr ) ), + maRbEPSColorFormat1 ( this, ResId( RB_EPS_COLOR_FORMAT1, *rPara.pResMgr ) ), + maRbEPSColorFormat2 ( this, ResId( RB_EPS_COLOR_FORMAT2, *rPara.pResMgr ) ), + maFlCompression ( this, ResId( FL_COMPRESSION, *rPara.pResMgr ) ), + maRbEPSCompressionLZW ( this, ResId( RB_EPS_COMPRESSION_LZW, *rPara.pResMgr ) ), + maRbEPSCompressionNone ( this, ResId( RB_EPS_COMPRESSION_NONE, *rPara.pResMgr ) ), + maFlEstimatedSize ( this, ResId( FL_ESTIMATED_SIZE, *rPara.pResMgr ) ), + maFtEstimatedSize ( this, ResId( FT_ESTIMATED_SIZE, *rPara.pResMgr ) ), + msEstimatedSizePix1 ( ResId( STR_ESTIMATED_SIZE_PIX_1, *rPara.pResMgr ) ), + msEstimatedSizePix2 ( ResId( STR_ESTIMATED_SIZE_PIX_2, *rPara.pResMgr ) ), + msEstimatedSizeVec ( ResId( STR_ESTIMATED_SIZE_VEC, *rPara.pResMgr ) ), + maFlButtons ( this, ResId( FL_BUTTONS, *rPara.pResMgr ) ), + maFbJPGPreview ( this, ResId( FB_JPG_PREVIEW, *rPara.pResMgr ) ), + maSbZoom ( this, ResId( SB_ZOOM, *rPara.pResMgr ) ), + maNfZoom ( this, ResId( NF_ZOOM, *rPara.pResMgr ) ), + maSbJPGPreviewHorz ( this, ResId( SB_JPG_PREVIEW_HORZ, *rPara.pResMgr ) ), + maSbJPGPreviewVert ( this, ResId( SB_JPG_PREVIEW_VERT, *rPara.pResMgr ) ), + maBtnOK ( this, ResId( BTN_OK, *rPara.pResMgr ) ), + maBtnCancel ( this, ResId( BTN_CANCEL, *rPara.pResMgr ) ), + maBtnHelp ( this, ResId( BTN_HELP, *rPara.pResMgr ) ), + ms1BitTreshold ( ResId( STR_1BIT_THRESHOLD, *rPara.pResMgr ) ), + ms1BitDithered ( ResId( STR_1BIT_DITHERED, *rPara.pResMgr ) ), + ms4BitGrayscale ( ResId( STR_4BIT_GRAYSCALE, *rPara.pResMgr ) ), + ms4BitColorPalette ( ResId( STR_4BIT_COLOR_PALETTE, *rPara.pResMgr ) ), + ms8BitGrayscale ( ResId( STR_8BIT_GRAYSCALE, *rPara.pResMgr ) ), + ms8BitColorPalette ( ResId( STR_8BIT_COLOR_PALETTE, *rPara.pResMgr ) ), + ms24BitColor ( ResId( STR_24BIT_TRUE_COLOR, *rPara.pResMgr ) ), + maExt ( rPara.aFilterExt ), + mnFormat ( FORMAT_UNKNOWN ), + mnMaxFilesizeForRealtimePreview( 0 ), + mpTempStream ( new SvMemoryStream() ), + maOriginalSize ( awt::Size( 0, 0 ) ), + mbPreview ( sal_False ), + mbIsPixelFormat ( bIsPixelFormat ), + mbExportSelection ( bExportSelection ), + mbPreserveAspectRatio ( sal_True ) +{ + GetGraphicSource(); + + maExt.ToUpperAscii(); + + String aFilterConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/Graphic/Export/" ) ); + mpOptionsItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData ); + aFilterConfigPath.Append( maExt ); + mpFilterOptionsItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData ); + + mnInitialResolutionUnit = mbIsPixelFormat + ? mpOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelExportUnit" ) ), UNIT_DEFAULT ) + : mpOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "VectorExportUnit" ) ), UNIT_DEFAULT ); + + mnMaxFilesizeForRealtimePreview = mpOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "MaxFilesizeForRealtimePreview" ) ), 0 ); + maFtEstimatedSize.SetText( String( RTL_CONSTASCII_USTRINGPARAM( " \n " ) ) ); + + String aTitle( maExt ); + aTitle += String( ResId( DLG_EXPORT_TITLE, *mpMgr ) ); + SetText( aTitle ); + + mnFormat = GetFilterFormat( maExt ); + + Size aResolution( Application::GetDefaultDevice()->LogicToPixel( Size( 100, 100 ), MAP_CM ) ); + maResolution.Width = aResolution.Width(); + maResolution.Height= aResolution.Height(); + maOriginalSize = GetOriginalSize(); + if ( bIsPixelFormat ) + { + double fPixelsPer100thmm = static_cast< double >( maResolution.Width ) / 100000.0; + maSize = awt::Size( static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Width ) + 0.5 ), + static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Height ) + 0.5 ) ); + } + else + { + maSize = maOriginalSize; + } + + // Size + maLbSizeX.SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) ); + + maSbCompression.SetScrollHdl( LINK( this, ExportDialog, SbCompressionUpdateHdl ) ); + maNfCompression.SetModifyHdl( LINK( this, ExportDialog, UpdateHdl ) ); + + maMfSizeX.SetModifyHdl( LINK( this, ExportDialog, UpdateHdlMtfSizeX ) ); + maMfSizeY.SetModifyHdl( LINK( this, ExportDialog, UpdateHdlMtfSizeY ) ); + + maNfResolution.SetModifyHdl( LINK( this, ExportDialog, UpdateHdlNfResolution ) ); + maLbResolution.SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) ); + + maLbColorDepth.SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) ); + + maCbInterlaced.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); + + maCbSaveTransparency.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); + + maCbEPSPreviewTIFF.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); + maCbEPSPreviewEPSI.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); + + maRbEPSCompressionLZW.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); + maRbEPSCompressionNone.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); + + maRbBinary.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); + maRbText.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); + + + // JPG Preview +// maCbJPGPreview.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); +maCbJPGPreview.Enable( sal_False ); + + maSbJPGPreviewVert.SetScrollHdl( LINK( this, ExportDialog, UpdateHdl ) ); + maSbJPGPreviewHorz.SetScrollHdl( LINK( this, ExportDialog, UpdateHdl ) ); + maSbZoom.SetScrollHdl( LINK( this, ExportDialog, UpdateHdl ) ); + + // BMP + maCbRLEEncoding.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); + + // EPS + maRbEPSLevel1.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); + maRbEPSLevel2.SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) ); + + maBtnOK.SetClickHdl( LINK( this, ExportDialog, OK ) ); + + setupLayout(); + updateControls(); + + FreeResource(); +} + +void ExportDialog::createSizeControls( vcl::RowOrColumn& rLayout ) +{ + size_t nIndex; + Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) ); + long nIndent = aBorder.Width(); + + // Size controls + rLayout.addWindow( &maFlExportSize ); + + Size aLbMax( maLbSizeX.GetSizePixel() ); + aLbMax.Width() = Max( aLbMax.Width(), maLbResolution.GetSizePixel().Width() ); + + boost::shared_ptr< vcl::LabelColumn > xSizeColumns( new vcl::LabelColumn( &rLayout ) ); + rLayout.addChild( xSizeColumns ); + + // row 1 + boost::shared_ptr< vcl::RowOrColumn > xColumn( new vcl::RowOrColumn( xSizeColumns.get(), false ) ); + xSizeColumns->addRow( &maFtSizeX, xColumn, nIndent ); + Size aMinSize( maMfSizeX.GetSizePixel() ); + nIndex = xColumn->addWindow( &maMfSizeX ); + xColumn->setMinimumSize( nIndex, aMinSize ); + nIndex = xColumn->addWindow( &maLbSizeX ); + xColumn->setMinimumSize( nIndex, aLbMax ); + + // row 2 + xColumn = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( xSizeColumns.get(), false ) ); + xSizeColumns->addRow( &maFtSizeY, xColumn, nIndent ); + nIndex = xColumn->addWindow( &maMfSizeY ); + xColumn->setMinimumSize( nIndex, aMinSize ); + nIndex = xColumn->addWindow( &maLbSizeY ); + xColumn->setMinimumSize( nIndex, aLbMax ); + + // row 3 + if ( mbIsPixelFormat ) // TODO: (metafileresolutionsupport) + { + xColumn = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( xSizeColumns.get(), false ) ); + xSizeColumns->addRow( &maFtResolution, xColumn, nIndent ); + nIndex = xColumn->addWindow( &maNfResolution ); + xColumn->setMinimumSize( nIndex, aMinSize ); + nIndex = xColumn->addWindow( &maLbResolution ); + xColumn->setMinimumSize( nIndex, aLbMax ); + } + + sal_Int32 nUnit = mnInitialResolutionUnit; + if ( nUnit == UNIT_DEFAULT ) + nUnit = GetDefaultUnit(); + + if ( !mbIsPixelFormat ) + { + maLbSizeX.RemoveEntry( UNIT_PIXEL ); // removing pixel + if ( nUnit >= UNIT_PIXEL ) + nUnit = UNIT_CM; + } + else if ( nUnit > UNIT_MAX_ID ) + nUnit = UNIT_PIXEL; + if ( nUnit < 0 ) + nUnit = UNIT_CM; + maLbSizeX.SelectEntryPos( static_cast< USHORT >( nUnit ) ); + + if ( mbIsPixelFormat ) // TODO: (metafileresolutionsupport) should be supported for vector formats also... this makes + { // sense eg for bitmap fillings in metafiles, to preserve high dpi output + // (atm without special vector support the bitmaps are rendered with 96dpi) + sal_Int32 nResolution = mpOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelExportResolution" ) ), 96 ); + if ( nResolution < 1 ) + nResolution = 96; + maNfResolution.SetValue( nResolution ); + + sal_Int32 nResolutionUnit = mpOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PixelExportResolutionUnit" ) ), 1 ); + if ( ( nResolutionUnit < 0 ) || ( nResolutionUnit > 2 ) ) + nResolutionUnit = 1; + maLbResolution.SelectEntryPos( static_cast< USHORT >( nResolutionUnit ) ); + } + + boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); + rLayout.addChild( xSpacer ); +} + +void ExportDialog::createColorDepthControls( vcl::RowOrColumn& rLayout ) +{ + // Color Depth + Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) ); + long nIndent = aBorder.Width(); + + boost::shared_ptr< vcl::RowOrColumn > xRow( new vcl::RowOrColumn( &rLayout, false ) ); + rLayout.addChild( xRow ); + xRow->addWindow( &maFlColorDepth ); + + xRow = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( &rLayout, false ) ); + rLayout.addChild( xRow ); + boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( &rLayout, nIndent ) ); + xRow->addChild( xIndenter ); + boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( &rLayout, true ) ); + xIndenter->setChild( xRows ); + xRows->addWindow( &maLbColorDepth ); + + boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); + rLayout.addChild( xSpacer ); +} + +void ExportDialog::createScrollBar( vcl::RowOrColumn& rLayout ) +{ + boost::shared_ptr< vcl::RowOrColumn > xRow( new vcl::RowOrColumn( &rLayout, false ) ); + rLayout.addChild( xRow ); + + Size aMinSize( maSbCompression.GetSizePixel() ); + size_t nIndex = xRow->addWindow( &maSbCompression ); + xRow->setMinimumSize( nIndex, aMinSize ); + aMinSize = maNfCompression.GetSizePixel(); + nIndex = xRow->addWindow( &maNfCompression ); + xRow->setMinimumSize( nIndex, aMinSize ); +} + +void ExportDialog::createFilterOptions( vcl::RowOrColumn& rLayout ) +{ + Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) ); + long nIndent = aBorder.Width(); + + switch( mnFormat ) + { + case FORMAT_JPG : + { + sal_Int32 nColor = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "ColorMode" ) ), 0 ); + if ( nColor == 1 ) + nColor = 0; + else + nColor = 1; + maLbColorDepth.InsertEntry( ms8BitGrayscale ); + maLbColorDepth.InsertEntry( ms24BitColor ); + maLbColorDepth.SelectEntryPos( nColor ); + createColorDepthControls( maLayout ); + + rLayout.addWindow( &maFlJPGQuality ); + + // Quality + boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( &rLayout, nIndent ) ); + rLayout.addChild( xIndenter ); + boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( &rLayout, true ) ); + xIndenter->setChild( xRows ); + createScrollBar( *xRows.get() ); + xRows->addWindow( &maFtJPGMin ); + xRows->addWindow( &maFtJPGMax ); + if ( maCbJPGPreview.IsEnabled() ) + xRows->addWindow( &maCbJPGPreview ); + + boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); + rLayout.addChild( xSpacer ); + + sal_Int32 nQuality = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Quality" ) ), 75 ); + if ( ( nQuality < 1 ) || ( nQuality > 100 ) ) + nQuality = 75; + + maSbCompression.SetRangeMin( 1 ); + maSbCompression.SetRangeMax( 100 ); + maNfCompression.SetMin( 1 ); + maNfCompression.SetMax( 100 ); + maNfCompression.SetValue( nQuality ); + maNfCompression.SetStrictFormat( sal_True ); + if ( maCbJPGPreview.IsEnabled() ) + maCbJPGPreview.Check( sal_False ); + } + break; + case FORMAT_PNG : + { + rLayout.addWindow( &maFlCompression ); + + // Compression 1..9 + boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( &rLayout, nIndent ) ); + rLayout.addChild( xIndenter ); + boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( &rLayout, true ) ); + xIndenter->setChild( xRows ); + createScrollBar( *xRows.get() ); + xRows->addWindow( &maFtPNGMin ); + xRows->addWindow( &maFtPNGMax ); + boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); + rLayout.addChild( xSpacer ); + + // Interlaced + rLayout.addWindow( &maFlMode ); + xIndenter.reset( new vcl::Indenter( &rLayout, nIndent ) ); + rLayout.addChild( xIndenter ); + xRows.reset( new vcl::RowOrColumn( &rLayout, true ) ); + xIndenter->setChild( xRows ); + xRows->addWindow( &maCbInterlaced ); + + xSpacer.reset( new vcl::Spacer( &rLayout, 2 ) ); + rLayout.addChild( xSpacer ); + + sal_Int32 nCompression = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Compression" ) ), 6 ); + if ( ( nCompression < 1 ) || ( nCompression > 9 ) ) + nCompression = 6; + maSbCompression.SetRangeMin( 1 ); + maSbCompression.SetRangeMax( 9 ); + maNfCompression.SetMin( 1 ); + maNfCompression.SetMax( 9 ); + maNfCompression.SetValue( 9 ); + maNfCompression.SetStrictFormat( sal_True ); + + maCbInterlaced.Check( mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Interlaced" ) ), 0 ) != 0 ); + } + break; + case FORMAT_BMP : + { + sal_Int32 nColor = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Color" ) ), 0 ); + if ( nColor == 0 ) + nColor = 6; + else + nColor--; + maLbColorDepth.InsertEntry( ms1BitTreshold ); + maLbColorDepth.InsertEntry( ms1BitDithered ); + maLbColorDepth.InsertEntry( ms4BitGrayscale ); + maLbColorDepth.InsertEntry( ms4BitColorPalette ); + maLbColorDepth.InsertEntry( ms8BitGrayscale ); + maLbColorDepth.InsertEntry( ms8BitColorPalette ); + maLbColorDepth.InsertEntry( ms24BitColor ); + maLbColorDepth.SelectEntryPos( nColor ); + createColorDepthControls( maLayout ); + + rLayout.addWindow( &maFlCompression ); + // RLE coding + boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( &rLayout, nIndent ) ); + rLayout.addChild( xIndenter ); + boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( &rLayout, true ) ); + xIndenter->setChild( xRows ); + xRows->addWindow( &maCbRLEEncoding ); + boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); + rLayout.addChild( xSpacer ); + + maCbRLEEncoding.Check( mpFilterOptionsItem->ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "RLE_Coding" ) ), sal_True ) ); + } + break; + case FORMAT_GIF : + { + rLayout.addWindow( &maFlMode ); + boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( &rLayout, nIndent ) ); + rLayout.addChild( xIndenter ); + boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( &rLayout, true ) ); + xIndenter->setChild( xRows ); + xRows->addWindow( &maCbInterlaced ); + boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); + rLayout.addChild( xSpacer ); + + rLayout.addWindow( &maFlGIFDrawingObjects ); + xIndenter = boost::shared_ptr< vcl::Indenter >( new vcl::Indenter( &rLayout, nIndent ) ); + rLayout.addChild( xIndenter ); + xRows = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( &rLayout, true ) ); + xIndenter->setChild( xRows ); + xRows->addWindow( &maCbSaveTransparency ); + xSpacer.reset( new vcl::Spacer( &rLayout, 2 ) ); + rLayout.addChild( xSpacer ); + + maCbInterlaced.Check( mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Interlaced" ) ), 1 ) != 0 ); + maCbSaveTransparency.Check( mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Translucent" ) ), 1 ) != 0 ); + } + break; + case FORMAT_PBM : + case FORMAT_PGM : + case FORMAT_PPM : + { + rLayout.addWindow( &maFlJPGQuality ); + + // RB Binary / Text + boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( &rLayout, nIndent ) ); + rLayout.addChild( xIndenter ); + boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( &rLayout, true ) ); + xIndenter->setChild( xRows ); + xRows->addWindow( &maRbBinary ); + xRows->addWindow( &maRbText ); + boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); + rLayout.addChild( xSpacer ); + + sal_Int32 nFormat = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "FileFormat" ) ), 1 ); + maRbBinary.Check( nFormat == 0 ); + maRbText.Check( nFormat != 0 ); + } + break; + case FORMAT_EPS : + { + boost::shared_ptr< vcl::RowOrColumn > xColumns( new vcl::RowOrColumn( &rLayout, false ) ); + rLayout.addChild( xColumns ); + boost::shared_ptr< vcl::RowOrColumn > xLeft( new vcl::RowOrColumn( &rLayout, true ) ); + xColumns->addChild( xLeft ); + + xLeft->addWindow( &maFlEPSPreview ); + boost::shared_ptr< vcl::Indenter > xIndenter( new vcl::Indenter( xLeft.get(), nIndent ) ); + xLeft->addChild( xIndenter ); + boost::shared_ptr< vcl::RowOrColumn > xRows( new vcl::RowOrColumn( xLeft.get(), true ) ); + xIndenter->setChild( xRows ); + xRows->addWindow( &maCbEPSPreviewTIFF ); + xRows->addWindow( &maCbEPSPreviewEPSI ); + boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( xLeft.get(), 2 ) ); + xLeft->addChild( xSpacer ); + + xLeft->addWindow( &maFlEPSVersion ); + xIndenter = boost::shared_ptr< vcl::Indenter >( new vcl::Indenter( xLeft.get(), nIndent ) ); + xLeft->addChild( xIndenter ); + xRows = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( xLeft.get(), true ) ); + xIndenter->setChild( xRows ); + xRows->addWindow( &maRbEPSLevel1 ); + xRows->addWindow( &maRbEPSLevel2 ); + xSpacer.reset( new vcl::Spacer( xLeft.get(), 2 ) ); + xLeft->addChild( xSpacer ); + + boost::shared_ptr< vcl::RowOrColumn > xRight( new vcl::RowOrColumn( &rLayout, true ) ); + xColumns->addChild( xRight ); + + xRight->addWindow( &maFlEPSColorFormat ); + xIndenter = boost::shared_ptr< vcl::Indenter >( new vcl::Indenter( xRight.get(), nIndent ) ); + xRight->addChild( xIndenter ); + xRows = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( xRight.get(), true ) ); + xIndenter->setChild( xRows ); + xRows->addWindow( &maRbEPSColorFormat1 ); + xRows->addWindow( &maRbEPSColorFormat2 ); + xSpacer.reset( new vcl::Spacer( xRight.get(), 2 ) ); + xRight->addChild( xSpacer ); + + xRight->addWindow( &maFlCompression ); + xIndenter = boost::shared_ptr< vcl::Indenter >( new vcl::Indenter( xRight.get(), nIndent ) ); + xRight->addChild( xIndenter ); + xRows = boost::shared_ptr< vcl::RowOrColumn >( new vcl::RowOrColumn( xRight.get(), true ) ); + xIndenter->setChild( xRows ); + xRows->addWindow( &maRbEPSCompressionLZW ); + xRows->addWindow( &maRbEPSCompressionNone ); + + xSpacer.reset( new vcl::Spacer( &rLayout, 2 ) ); + rLayout.addChild( xSpacer ); + + sal_Int32 nPreview = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Preview" ) ), 0 ); + sal_Int32 nVersion = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ), 2 ); + sal_Int32 nColor = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "ColorFormat" ) ), 0 ); + sal_Int32 nCompr = mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "CompressionMode" ) ), 2 ); + + mpFilterOptionsItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "TextMode" ) ), 0 ); + + maCbEPSPreviewTIFF.Check( ( nPreview & 1 ) != 0 ); + maCbEPSPreviewEPSI.Check( ( nPreview & 2 ) != 0 ); + + maRbEPSLevel1.Check( nVersion == 1 ); + maRbEPSLevel2.Check( nVersion == 2 ); + + maRbEPSColorFormat1.Check( nColor == 1 ); + maRbEPSColorFormat2.Check( nColor != 1 ); + + maRbEPSCompressionLZW.Check( nCompr == 1 ); + maRbEPSCompressionNone.Check( nCompr != 1 ); + } + break; + } +} + +void ExportDialog::createButtons( vcl::RowOrColumn& rLayout ) +{ + rLayout.addWindow( &maFlButtons ); + boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( &rLayout, 2 ) ); + rLayout.addChild( xSpacer ); + + Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) ); + + boost::shared_ptr< vcl::RowOrColumn > xButtons( new vcl::RowOrColumn( &rLayout, false ) ); + size_t nIndex = rLayout.addChild( xButtons ); + rLayout.setBorders( nIndex, aBorder.Width(), 0, aBorder.Width(), aBorder.Width() ); + + Size aMinSize( maBtnCancel.GetSizePixel() ); + // insert help button + xButtons->setMinimumSize( xButtons->addWindow( &maBtnHelp ), aMinSize ); + + // insert a spacer, cancel and OK buttons are right aligned + + xSpacer.reset( new vcl::Spacer( xButtons.get(), 2 ) ); + xButtons->addChild( xSpacer ); + xButtons->setMinimumSize( xButtons->addWindow( &maBtnOK ), aMinSize ); + xButtons->setMinimumSize( xButtons->addWindow( &maBtnCancel ), aMinSize ); +} + +void ExportDialog::setupLayout() +{ + Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) ); + maLayout.setParentWindow( this ); + maLayout.setOuterBorder( aBorder.Width() ); + + createSizeControls( maLayout ); + createFilterOptions( maLayout ); + + if ( mnMaxFilesizeForRealtimePreview || mbIsPixelFormat ) + { + maLayout.addWindow( &maFlEstimatedSize ); + maLayout.addWindow( &maFtEstimatedSize ); + } + createButtons( maLayout ); + + maLayout.show(); + maDialogSize = maLayout.getOptimalSize( WINDOWSIZE_PREFERRED ); + maLayout.setManagedArea( Rectangle( Point(), maDialogSize ) ); + SetOutputSizePixel( Size( mbPreview ? maDialogSize.Width() * 2 : maDialogSize.Width(), maDialogSize.Height() ) ); + + maRectFlButtons = Rectangle( maFlButtons.GetPosPixel(), maFlButtons.GetSizePixel() ); + maRectBtnHelp = Rectangle( maBtnHelp.GetPosPixel(), maBtnHelp.GetSizePixel() ); + maRectBtnOK = Rectangle( maBtnOK.GetPosPixel(), maBtnOK.GetSizePixel() ); + maRectBtnCancel = Rectangle( maBtnCancel.GetPosPixel(), maBtnOK.GetSizePixel() ); + + maLbSizeY.Hide(); +} + +static rtl::OUString ImpValueOfInKB( const sal_Int64& rVal ) +{ + double fVal( static_cast( rVal ) ); + fVal /= ( 1 << 10 ); + fVal += 0.05; + rtl::OUStringBuffer aVal( rtl::OUString::valueOf( fVal ) ); + sal_Int32 nX( rtl::OUString( aVal.getStr() ).indexOf( '.', 0 ) ); + if ( nX > 0 ) + aVal.setLength( nX + 2 ); + return aVal.makeStringAndClear(); +} + +sal_Int32 static GetZoomValueFromThumbPos( sal_Int32 nThumbPos ) +{ + sal_Int32 nProz = 0; + if ( nThumbPos <= 50 ) + nProz = nThumbPos * 2; // so a range of 50 represents 100% + else + nProz = ( ( nThumbPos - 50 ) * 60 ) + 100; // we want to scale up to 3000% + return nProz; +} + +void ExportDialog::updatePreview() +{ + // JPG +// maCbJPGPreview.Enable( IsTempExportAvailable() ); + +// if ( maCbJPGPreview.IsEnabled() && maCbJPGPreview.IsChecked() ) + if ( mbPreview ) + { + long nScrollBarSize = Application::GetSettings().GetStyleSettings().GetScrollBarSize(); + + Point aPreviewPos( maDialogSize.Width(), 0 ); + Size aPreviewSize( maDialogSize.Width(), maFlButtons.GetPosPixel().Y() ); + + Point aFixedBitmapPos( aPreviewPos ); + Size aFixedBitmapSize( aPreviewSize ); + + maSbZoom.Show( sal_False ); + maSbZoom.SetPosPixel( Point( aPreviewPos.X(), aPreviewPos.Y() ) ); + maSbZoom.SetSizePixel( Size( aPreviewSize.Width() / 4, nScrollBarSize ) ); + maNfZoom.Show( sal_False ); + maNfZoom.SetPosPixel( Point( aPreviewPos.X() + aPreviewSize.Width() / 4, aPreviewPos.Y() ) ); + maNfZoom.SetSizePixel( Size( aPreviewSize.Width() / 6, nScrollBarSize ) ); + maNfZoom.SetValue( GetZoomValueFromThumbPos( maSbZoom.GetThumbPos() ) ); + maFbJPGPreview.Show( sal_True ); + + sal_Int32 nZoom = GetZoomValueFromThumbPos( maSbZoom.GetThumbPos() ); + double fSizePixelX = static_cast< double >( maSize.Width * nZoom ) / 100.0; + double fSizePixelY = static_cast< double >( maSize.Height * nZoom ) / 100.0; + + double fXRatio = fSizePixelX / maSize.Width; // the size of each pixel + double fYRatio = fSizePixelY / maSize.Height; + + sal_Bool bHorzSb = fSizePixelX > aFixedBitmapSize.Width(); + sal_Bool bVertSb = fSizePixelY > aFixedBitmapSize.Height(); + if ( bHorzSb ) + { + aFixedBitmapSize.Height() -= nScrollBarSize; + + maSbJPGPreviewHorz.Show( sal_True ); + maSbJPGPreviewHorz.SetPosPixel( Point( aFixedBitmapPos.X(), aFixedBitmapPos.Y() + aFixedBitmapSize.Height() ) ); + maSbJPGPreviewHorz.SetSizePixel( Size( aFixedBitmapSize.Width(), nScrollBarSize ) ); + } + else + { + maSbJPGPreviewHorz.Show( sal_False ); + } + + + if ( bVertSb ) + { + aFixedBitmapSize.Width() -= nScrollBarSize; + + maSbJPGPreviewVert.Show( sal_True ); + maSbJPGPreviewVert.SetPosPixel( Point( aFixedBitmapPos.X() + aFixedBitmapSize.Width(), aFixedBitmapPos.Y() ) ); + maSbJPGPreviewVert.SetSizePixel( Size( nScrollBarSize, aFixedBitmapSize.Height() ) ); + } + else + { + maSbJPGPreviewVert.Show( sal_False ); + } + + Point aPos( 0, 0 ); + Size aSize; + if ( fXRatio > 1.0 ) + { + aSize.Width() = maSize.Width > aFixedBitmapSize.Width() ? maSize.Width : aFixedBitmapSize.Width(); + aSize.Width() /= static_cast(fXRatio); + } + else + { + aSize.Width() = maSize.Width < aFixedBitmapSize.Width() ? maSize.Width : aFixedBitmapSize.Width(); + aSize.Width() /= static_cast(fXRatio); + } + + if ( fYRatio > 1.0 ) + { + aSize.Height() = maSize.Height > aFixedBitmapSize.Height() ? maSize.Height : aFixedBitmapSize.Height(); + aSize.Height() /= static_cast(fYRatio); + } + else + { + aSize.Height() = maSize.Height < aFixedBitmapSize.Height() ? maSize.Height : aFixedBitmapSize.Height(); + aSize.Height() /= static_cast(fYRatio); + } + + if ( aSize.Width() < maSize.Width ) + { + sal_Int32 nXDiff = static_cast< sal_Int32 >( ( ( ( maSize.Width - aSize.Width() ) * maSbJPGPreviewHorz.GetThumbPos() ) / 100.0 ) ); + aPos.X() += nXDiff; + } + if ( aSize.Height() < maSize.Height ) + { + sal_Int32 nYDiff = static_cast< sal_Int32 >( ( ( ( maSize.Height - aSize.Height() ) * maSbJPGPreviewVert.GetThumbPos() ) / 100.0 ) ); + aPos.Y() += nYDiff; + } + + Bitmap aCroppedBitmap( maBitmap ); + aCroppedBitmap.Crop( Rectangle( aPos, aSize ) ); + aSize = aCroppedBitmap.GetSizePixel(); + aSize = Size( static_cast(aSize.Width() * fXRatio), static_cast(aSize.Height() * fYRatio) ); + aCroppedBitmap.Scale( aSize ); + + if ( aSize.Width() > aFixedBitmapSize.Width() ) + aSize.Width() = aFixedBitmapSize.Width(); + if ( aSize.Height() > aFixedBitmapSize.Height() ) + aSize.Height() = aFixedBitmapSize.Height(); + Point aPoint( aFixedBitmapPos ); + if ( aSize.Width() < aFixedBitmapSize.Width() ) + aPoint.X() += ( aFixedBitmapSize.Width() - aSize.Width() ) / 2; + if ( aSize.Height() < aFixedBitmapSize.Height() ) + aPoint.Y() += ( aFixedBitmapSize.Height() - aSize.Height() ) / 2; + + maFbJPGPreview.SetPosPixel( aPoint ); + maFbJPGPreview.SetSizePixel( aSize ); + maFbJPGPreview.SetBitmap( aCroppedBitmap ); + + SetOutputSizePixel( Size( maDialogSize.Width() * 2, maDialogSize.Height() ) ); + + maFlButtons.SetSizePixel( Size( maRectFlButtons.GetWidth() * 2, maRectFlButtons.GetHeight() ) ); + maBtnHelp.SetPosPixel( Point( maRectBtnHelp.Left() + maDialogSize.Width(), maRectBtnHelp.Top() ) ); + maBtnOK.SetPosPixel( Point( maRectBtnOK.Left() + maDialogSize.Width(), maRectBtnOK.Top() ) ); + maBtnCancel.SetPosPixel( Point( maRectBtnCancel.Left() + maDialogSize.Width(), maRectBtnCancel.Top() ) ); + } + else + { + maSbZoom.Show( sal_False ); + maNfZoom.Show( sal_False ); + maFbJPGPreview.Show( sal_False ); + maSbJPGPreviewHorz.Show( sal_False ); + maSbJPGPreviewVert.Show( sal_False ); + + SetOutputSizePixel( maDialogSize ); + + maFlButtons.SetSizePixel( Size( maRectFlButtons.GetWidth(), maRectFlButtons.GetHeight() ) ); + maBtnHelp.SetPosPixel( Point( maRectBtnHelp.Left(), maRectBtnHelp.Top() ) ); + maBtnOK.SetPosPixel( Point( maRectBtnOK.Left(), maRectBtnOK.Top() ) ); + maBtnCancel.SetPosPixel( Point( maRectBtnCancel.Left(), maRectBtnCancel.Top() ) ); + } +} + +void ExportDialog::updateControls() +{ + GetGraphicStream(); + + // Size Controls + if ( !mbIsPixelFormat ) + { + awt::Size aSize100thmm( maSize ); + Size aSize( LogicToLogic( Size( aSize100thmm.Width * 100, aSize100thmm.Height * 100 ), MAP_100TH_MM, + MapMode( GetMapUnit( maLbSizeX.GetSelectEntryPos() ) ) ) ); + maMfSizeX.SetValue( aSize.Width() ); + maMfSizeY.SetValue( aSize.Height() ); + } + else + { + MapUnit aMapUnit( GetMapUnit( maLbSizeX.GetSelectEntryPos() ) ); + if ( aMapUnit == MAP_PIXEL ) + { // calculating pixel count via resolution and original graphic size + maMfSizeX.SetDecimalDigits( 0 ); + maMfSizeY.SetDecimalDigits( 0 ); + maMfSizeX.SetValue( maSize.Width ); + maMfSizeY.SetValue( maSize.Height ); + } + else + { + maMfSizeX.SetDecimalDigits( 2 ); + maMfSizeY.SetDecimalDigits( 2 ); + double fRatio; + switch( GetMapUnit( maLbSizeX.GetSelectEntryPos() ) ) + { + case MAP_INCH : fRatio = static_cast< double >( maResolution.Width ) * 0.0254; break; + case MAP_MM : fRatio = static_cast< double >( maResolution.Width ) * 0.001; break; + case MAP_POINT :fRatio = ( static_cast< double >( maResolution.Width ) * 0.0254 ) / 72.0; break; + default: + case MAP_CM : fRatio = static_cast< double >( maResolution.Width ) * 0.01; break; + } + maMfSizeX.SetValue( static_cast< sal_Int32 >( ( static_cast< double >( maSize.Width * 100 ) / fRatio ) + 0.5 ) ); + maMfSizeY.SetValue( static_cast< sal_Int32 >( ( static_cast< double >( maSize.Height * 100 ) / fRatio ) + 0.5 ) ); + } + } + sal_Int32 nResolution = 0; + switch( maLbResolution.GetSelectEntryPos() ) + { + case 0 : nResolution = maResolution.Width / 100; break; // pixels / cm + case 2 : nResolution = maResolution.Width; break; // pixels / meter + default: + case 1 : nResolution = static_cast< sal_Int32 >(maResolution.Width * 0.0254); break; // pixels / inch + } + maNfResolution.SetValue( nResolution ); + + if ( maSbCompression.IsVisible() ) + maSbCompression.SetThumbPos( maNfCompression.GetValue() ); + + // updating estimated size + sal_Int64 nRealFileSize( mpTempStream->Tell() ); + if ( mbIsPixelFormat ) + { + String aEst( nRealFileSize ? msEstimatedSizePix2 : msEstimatedSizePix1 ); + sal_Int64 nRawFileSize( GetRawFileSize() ); + xub_StrLen nInd = aEst.Search( '%' ); + aEst.Replace( nInd, 2, ImpValueOfInKB( nRawFileSize ) ); + + if ( nRealFileSize ) + { + nInd = aEst.Search( '%', nInd ); + aEst.Replace( nInd, 2, ImpValueOfInKB( nRealFileSize ) ); + } + maFtEstimatedSize.SetText( aEst ); + } + else + { + if ( mnMaxFilesizeForRealtimePreview ) + { + String aEst( msEstimatedSizeVec ); + xub_StrLen nInd = aEst.Search( '%', 0 ); + aEst.Replace( nInd, 2, ImpValueOfInKB( nRealFileSize ) ); + maFtEstimatedSize.SetText( aEst ); + } + } + updatePreview(); + + // EPS + if ( maRbEPSLevel1.IsVisible() ) + { + sal_Bool bEnabled = maRbEPSLevel1.IsChecked() == sal_False; + maRbEPSColorFormat1.Enable( bEnabled ); + maRbEPSColorFormat2.Enable( bEnabled ); + maRbEPSCompressionLZW.Enable( bEnabled ); + maRbEPSCompressionNone.Enable( bEnabled ); + } +} + +ExportDialog::~ExportDialog() +{ + delete mpFilterOptionsItem; + delete mpOptionsItem; +} + + +/************************************************************************* +|* +|* Speichert eingestellte Werte in ini-Datei +|* +\************************************************************************/ +IMPL_LINK( ExportDialog, UpdateHdl, void *, EMPTYARG ) +{ + updateControls(); + return 0; +} + +IMPL_LINK( ExportDialog, UpdateHdlMtfSizeX, void *, EMPTYARG ) +{ + double fRatio = static_cast< double >( maOriginalSize.Height ) / maOriginalSize.Width; + + if ( mbIsPixelFormat ) + { + switch( GetMapUnit( maLbSizeX.GetSelectEntryPos() ) ) + { + case MAP_INCH : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.0254 * maMfSizeX.GetValue() / 100.0 + 0.5 ); break; + case MAP_CM : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.01 * maMfSizeX.GetValue() / 100.0 + 0.5 ); break; + case MAP_MM : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.001 * maMfSizeX.GetValue() / 100.0 + 0.5 ); break; + case MAP_POINT : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.0254 * maMfSizeX.GetValue() / 100.0 * 72 + 0.5 ); break; + default: + case MAP_PIXEL : maSize.Width = maMfSizeX.GetValue(); break; + } + maSize.Height = static_cast< sal_Int32 >( fRatio * maSize.Width + 0.5 ); + } + else + { + Fraction aFract( 1, 100 ); + sal_Int32 nWidth = maMfSizeX.GetValue(); + sal_Int32 nHeight= static_cast< sal_Int32 >( nWidth * fRatio ); + const Size aSource( static_cast< sal_Int32 >( nWidth ), static_cast< sal_Int32 >( nHeight ) ); + MapMode aSourceMapMode( GetMapUnit( maLbSizeX.GetSelectEntryPos() ),Point(), aFract, aFract ); + Size aDest( LogicToLogic( aSource, aSourceMapMode, MAP_100TH_MM ) ); + + maSize.Width = aDest.Width(); + if ( mbPreserveAspectRatio ) + maSize.Height = aDest.Height(); + } + updateControls(); + return 0; +} + +IMPL_LINK( ExportDialog, UpdateHdlMtfSizeY, void *, EMPTYARG ) +{ + double fRatio = static_cast< double >( maOriginalSize.Width ) / maOriginalSize.Height; + + if ( mbIsPixelFormat ) + { + switch( GetMapUnit( maLbSizeX.GetSelectEntryPos() ) ) + { + case MAP_INCH : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.0254 * maMfSizeY.GetValue() / 100.0 + 0.5 ); break; + case MAP_CM : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.01 * maMfSizeY.GetValue() / 100.0 + 0.5 ); break; + case MAP_MM : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.001 * maMfSizeY.GetValue() / 100.0 + 0.5 ); break; + case MAP_POINT : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.0254 * maMfSizeY.GetValue() / 100.0 * 72 + 0.5 ); break; + default: + case MAP_PIXEL : maSize.Height = maMfSizeY.GetValue(); break; + } + maSize.Width = static_cast< sal_Int32 >( fRatio * maSize.Height + 0.5 ); + } + else + { + Fraction aFract( 1, 100 ); + sal_Int32 nHeight= maMfSizeY.GetValue(); + sal_Int32 nWidth = static_cast< sal_Int32 >( nHeight * fRatio ); + const Size aSource( static_cast< sal_Int32 >( nWidth ), static_cast< sal_Int32 >( nHeight ) ); + MapMode aSourceMapMode( GetMapUnit( maLbSizeX.GetSelectEntryPos() ),Point(), aFract, aFract ); + Size aDest( LogicToLogic( aSource, aSourceMapMode, MAP_100TH_MM ) ); + + maSize.Height = aDest.Height(); + if ( mbPreserveAspectRatio ) + maSize.Width = aDest.Width(); + } + updateControls(); + return 0; +} + +IMPL_LINK( ExportDialog, UpdateHdlNfResolution, void *, EMPTYARG ) +{ + sal_Int32 nResolution = maNfResolution.GetValue(); + if ( maLbResolution.GetSelectEntryPos() == 0 ) // pixels / cm + nResolution *= 100; + else if ( maLbResolution.GetSelectEntryPos() == 1 ) // pixels / inch + nResolution = static_cast< sal_Int32 >( ( ( static_cast< double >( nResolution ) + 0.5 ) / 0.0254 ) ); + maResolution.Width = nResolution; + maResolution.Height= nResolution; + + updateControls(); + return 0; +} + +IMPL_LINK( ExportDialog, SbCompressionUpdateHdl, void *, EMPTYARG ) +{ + maNfCompression.SetValue( maSbCompression.GetThumbPos() ); + updateControls(); + return 0; +} + +IMPL_LINK( ExportDialog, OK, void *, EMPTYARG ) +{ + // writing config parameter + + + mrFltCallPara.aFilterData = GetFilterData( sal_True ); + EndDialog( RET_OK ); + + return 0; +} + diff --git a/svtools/source/filter/exportdialog.hrc b/svtools/source/filter/exportdialog.hrc new file mode 100644 index 000000000000..e230bcd2c5c3 --- /dev/null +++ b/svtools/source/filter/exportdialog.hrc @@ -0,0 +1,99 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include + +#define BTN_OK 1 +#define BTN_CANCEL 1 +#define BTN_HELP 1 + +#define FL_EXPORT_SIZE 1 +#define FL_COLOR_DEPTH 2 +#define FL_JPG_QUALITY 3 +#define FL_COMPRESSION 4 +#define FL_MODE 5 +#define FL_GIF_DRAWING_OBJECTS 6 +#define FL_PBM_OPTIONS 7 +#define FL_EPS_PREVIEW 8 +#define FL_EPS_VERSION 9 +#define FL_EPS_COLOR_FORMAT 10 +#define FL_ESTIMATED_SIZE 11 +#define FL_BUTTONS 12 + +#define FT_SIZEX 1 +#define FT_SIZEY 2 +#define FT_RESOLUTION 3 +#define FT_JPG_MIN 4 +#define FT_JPG_MAX 5 +#define FT_PNG_MIN 6 +#define FT_PNG_MAX 7 +#define FT_ESTIMATED_SIZE 8 + +#define NF_RESOLUTION 1 +#define NF_COMPRESSION 2 +#define NF_ZOOM 3 + +#define MF_SIZEX 1 +#define MF_SIZEY 2 + +#define LB_SIZEX 1 +#define LB_SIZEY 2 +#define LB_RESOLUTION 3 +#define LB_COLOR_DEPTH 4 + +#define RB_BINARY 1 +#define RB_TEXT 2 +#define RB_EPS_LEVEL1 3 +#define RB_EPS_LEVEL2 4 +#define RB_EPS_COLOR_FORMAT1 5 +#define RB_EPS_COLOR_FORMAT2 6 +#define RB_EPS_COMPRESSION_LZW 7 +#define RB_EPS_COMPRESSION_NONE 8 + +#define CB_JPG_PREVIEW 1 +#define CB_INTERLACED 2 +#define CB_RLE_ENCODING 3 +#define CB_SAVE_TRANSPARENCY 4 +#define CB_EPS_PREVIEW_TIFF 5 +#define CB_EPS_PREVIEW_EPSI 6 + +#define FB_JPG_PREVIEW 1 + +#define SB_COMPRESSION 1 +#define SB_JPG_PREVIEW_HORZ 2 +#define SB_JPG_PREVIEW_VERT 3 +#define SB_ZOOM 4 + +#define STR_1BIT_THRESHOLD 1 +#define STR_1BIT_DITHERED 2 +#define STR_4BIT_GRAYSCALE 3 +#define STR_4BIT_COLOR_PALETTE 4 +#define STR_8BIT_GRAYSCALE 5 +#define STR_8BIT_COLOR_PALETTE 6 +#define STR_24BIT_TRUE_COLOR 7 +#define STR_ESTIMATED_SIZE_PIX_1 8 +#define STR_ESTIMATED_SIZE_PIX_2 9 +#define STR_ESTIMATED_SIZE_VEC 10 diff --git a/svtools/source/filter/exportdialog.hxx b/svtools/source/filter/exportdialog.hxx new file mode 100644 index 000000000000..20a9ac3ea832 --- /dev/null +++ b/svtools/source/filter/exportdialog.hxx @@ -0,0 +1,216 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#ifndef _EXPORTDIALOG_HXX_ +#define _EXPORTDIALOG_HXX_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/************************************************************************* +|* +|* Dialog zum Einstellen von Filteroptionen bei Pixelformaten +|* +\************************************************************************/ + +class FilterConfigItem; +class ExportDialog : public ModalDialog +{ +private: + + FltCallDialogParameter& + mrFltCallPara; + + ResMgr* mpMgr; + + const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > + mxMgr; + const com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& + mxSourceDocument; + + FixedLine maFlExportSize; + FixedText maFtSizeX; + MetricField maMfSizeX; + ListBox maLbSizeX; + FixedText maFtSizeY; + MetricField maMfSizeY; + ListBox maLbSizeY; + FixedText maFtResolution; + NumericField maNfResolution; + ListBox maLbResolution; + FixedLine maFlColorDepth; + ListBox maLbColorDepth; + FixedLine maFlJPGQuality; + FixedLine maFlMode; + FixedLine maFlPBMOptions; + ScrollBar maSbCompression; + NumericField maNfCompression; + FixedText maFtJPGMin; + FixedText maFtJPGMax; + FixedText maFtPNGMin; + FixedText maFtPNGMax; + CheckBox maCbJPGPreview; + CheckBox maCbInterlaced; + CheckBox maCbRLEEncoding; + FixedLine maFlGIFDrawingObjects; + CheckBox maCbSaveTransparency; + RadioButton maRbBinary; + RadioButton maRbText; + FixedLine maFlEPSPreview; + CheckBox maCbEPSPreviewTIFF; + CheckBox maCbEPSPreviewEPSI; + FixedLine maFlEPSVersion; + RadioButton maRbEPSLevel1; + RadioButton maRbEPSLevel2; + FixedLine maFlEPSColorFormat; + RadioButton maRbEPSColorFormat1; + RadioButton maRbEPSColorFormat2; + FixedLine maFlCompression; + RadioButton maRbEPSCompressionLZW; + RadioButton maRbEPSCompressionNone; + FixedLine maFlEstimatedSize; + FixedText maFtEstimatedSize; + String msEstimatedSizePix1; + String msEstimatedSizePix2; + String msEstimatedSizeVec; + FixedLine maFlButtons; + FixedBitmap maFbJPGPreview; + ScrollBar maSbZoom; + NumericField maNfZoom; + ScrollBar maSbJPGPreviewHorz; + ScrollBar maSbJPGPreviewVert; + OKButton maBtnOK; + CancelButton maBtnCancel; + HelpButton maBtnHelp; + + String ms1BitTreshold; + String ms1BitDithered; + String ms4BitGrayscale; + String ms4BitColorPalette; + String ms8BitGrayscale; + String ms8BitColorPalette; + String ms24BitColor; + + vcl::RowOrColumn maLayout; + Size maDialogSize; + + FilterConfigItem* mpOptionsItem; + FilterConfigItem* mpFilterOptionsItem; + + String maExt; + String maEstimatedSizeText; + sal_Int16 mnFormat; + sal_Int32 mnMaxFilesizeForRealtimePreview; + + Rectangle maRectFlButtons; + Rectangle maRectBtnHelp; + Rectangle maRectBtnOK; + Rectangle maRectBtnCancel; + + SvStream* mpTempStream; + Bitmap maBitmap; + + com::sun::star::awt::Size + maOriginalSize; // the original graphic size in 1/100mm + com::sun::star::awt::Size + maSize; // for vector graphics it always contains the logical size in 1/100mm + + sal_Bool mbPreview; + sal_Bool mbIsPixelFormat; + sal_Bool mbExportSelection; + sal_Bool mbPreserveAspectRatio; + + sal_Int32 mnInitialResolutionUnit; + + // for pixel graphics it always contains the pixel count + com::sun::star::awt::Size + maResolution; // it always contains the number of pixels per meter + + com::sun::star::uno::Reference< com::sun::star::drawing::XShape > + mxShape; + com::sun::star::uno::Reference< com::sun::star::drawing::XShapes > + mxShapes; + com::sun::star::uno::Reference< com::sun::star::drawing::XDrawPage > + mxPage; + + + DECL_LINK( UpdateHdl,void* p ); + DECL_LINK( UpdateHdlMtfSizeX,void* p ); + DECL_LINK( UpdateHdlMtfSizeY,void* p ); + DECL_LINK( UpdateHdlNfResolution,void* p ); + DECL_LINK( SbCompressionUpdateHdl,void* p ); + DECL_LINK( NfCompressionUpdateHdlX,void* p ); + + DECL_LINK( OK, void* p ); + + void createSizeControls( vcl::RowOrColumn& ); + void createColorDepthControls( vcl::RowOrColumn& ); + void createFilterOptions( vcl::RowOrColumn& ); + void createButtons( vcl::RowOrColumn& ); + void createScrollBar( vcl::RowOrColumn& ); + void setupLayout(); + void updatePreview(); + void updateControls(); + + void GetGraphicSource(); + sal_Bool GetGraphicStream(); + Bitmap GetGraphicBitmap( SvStream& rStream ); + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > + GetFilterData( sal_Bool bUpdateConfig ); + + sal_uInt32 GetRawFileSize() const; + sal_Bool IsTempExportAvailable() const; + + com::sun::star::awt::Size + GetOriginalSize(); + + sal_Int32 GetDefaultUnit(); + +public: + ExportDialog( FltCallDialogParameter& rPara, + const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > rxMgr, + const com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& rxSourceDocument, + sal_Bool bExportSelection, sal_Bool bIsExportVectorFormat ); + ~ExportDialog(); +}; + + + +#endif // _EXPORTDIALOG_HXX_ + diff --git a/svtools/source/filter/exportdialog.src b/svtools/source/filter/exportdialog.src new file mode 100644 index 000000000000..c9e87989a314 --- /dev/null +++ b/svtools/source/filter/exportdialog.src @@ -0,0 +1,529 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "exportdialog.hrc" + +String DLG_EXPORT_TITLE +{ + Text [ en-US ] = " Options" ; +}; + +ModalDialog DLG_EXPORT +{ + HelpID = "svtools:ModalDialog:DLG_EXPORT"; + OutputSize = TRUE ; + SVLook = TRUE ; + Size = MAP_APPFONT ( 178 , 135 ) ; + Moveable = TRUE ; + Closeable = TRUE ; + + FixedLine FL_EXPORT_SIZE + { + Hide = TRUE; + Size = MAP_APPFONT ( 110 , 8 ) ; + Text [ en-US ] = "Size" ; + }; + FixedText FT_SIZEX + { + Hide = TRUE; + Size = MAP_APPFONT ( 41 , 10 ) ; + Text [ en-US ] = "Width:" ; + }; + MetricField MF_SIZEX + { + HelpID = "svtools:MetricField:DLG_EXPORT:MF_SIZEX"; + Hide = TRUE; + Border = TRUE; + Size = MAP_APPFONT ( 30, 12 ) ; + TabStop = TRUE; + Repeat = TRUE; + Spin = FALSE; + StrictFormat = TRUE; + DecimalDigits = 2; + Unit = FUNIT_NONE; + Maximum = 99999; + Last = 255; + }; + ListBox LB_SIZEX + { + HelpID = "svtools:ListBox:DLG_EXPORT:LB_SIZEX"; + Hide = TRUE; + Border = TRUE ; + Size = MAP_APPFONT ( 60, 80 ) ; + DropDown = TRUE ; + Sort = FALSE ; + StringList [ en-US ] = + { + < "inches" ; > ; + < "cm" ; Default ; > ; + < "mm" ; > ; + < "points" ; > ; + < "pixels" ; > ; + }; + }; + FixedText FT_SIZEY + { + Hide = TRUE; + Size = MAP_APPFONT ( 41 , 10 ) ; + Text [ en-US ] = "Height:" ; + }; + MetricField MF_SIZEY + { + HelpID = "svtools:MetricField:DLG_EXPORT:MF_SIZEY"; + Hide = TRUE; + Border = TRUE; + Size = MAP_APPFONT ( 30, 12 ); + TabStop = TRUE; + Repeat = TRUE; + Spin = FALSE; + StrictFormat = TRUE; + DecimalDigits = 2; + Unit = FUNIT_NONE; + Maximum = 99999; + Last = 255 ; + }; + ListBox LB_SIZEY + { + HelpID = "svtools:ListBox:DLG_EXPORT:LB_SIZEY"; + Hide = TRUE; + Border = TRUE ; + Size = MAP_APPFONT ( 60, 80 ) ; + DropDown = TRUE ; + Sort = FALSE ; + StringList [ en-US ] = + { + < "inches" ; > ; + < "cm" ; Default ; > ; + < "mm" ; > ; + < "points" ; > ; + < "pixels" ; > ; + }; + }; + FixedText FT_RESOLUTION + { + Hide = TRUE; + Size = MAP_APPFONT ( 41 , 10 ) ; + Text [ en-US ] = "Resolution:" ; + }; + NumericField NF_RESOLUTION + { + HelpID = "svtools:NumericField:DLG_EXPORT:NF_RESOLUTION"; + Hide = TRUE; + Border = TRUE ; + Size = MAP_APPFONT ( 30, 12 ) ; + TabStop = TRUE ; + Repeat = TRUE ; + Spin = FALSE ; + Maximum = 99999; + Last = 255 ; + }; + ListBox LB_RESOLUTION + { + HelpID = "svtools:ListBox:DLG_EXPORT:LB_RESOLUTION"; + Hide = TRUE; + Border = TRUE ; + Size = MAP_APPFONT ( 60, 80 ) ; + DropDown = TRUE ; + Sort = FALSE ; + StringList [ en-US ] = + { + < "pixels/cm" ; > ; + < "pixels/inch" ; Default ; > ; + < "pixels/meter" ; > ; + }; + }; + FixedLine FL_COLOR_DEPTH + { + Hide = TRUE; + Size = MAP_APPFONT ( 110 , 8 ) ; + Text [ en-US ] = "Color Depth" ; + }; + ListBox LB_COLOR_DEPTH + { + HelpID = "svtools:ListBox:DLG_EXPORT:LB_COLOR_DEPTH"; + Hide = TRUE; + Border = TRUE ; + Size = MAP_APPFONT ( 60, 80 ) ; + DropDown = TRUE ; + Sort = FALSE ; + }; + String STR_1BIT_THRESHOLD + { + Text [ en-US ] = "1 bit threshold"; + }; + String STR_1BIT_DITHERED + { + Text [ en-US ] = "1 bit dithered"; + }; + String STR_4BIT_GRAYSCALE + { + Text [ en-US ] = "4 bit grayscale"; + }; + String STR_4BIT_COLOR_PALETTE + { + Text [ en-US ] = "4 bit color"; + }; + String STR_8BIT_GRAYSCALE + { + Text [ en-US ] = "8 bit grayscale"; + }; + String STR_8BIT_COLOR_PALETTE + { + Text [ en-US ] = "8 bit color"; + }; + String STR_24BIT_TRUE_COLOR + { + Text [ en-US ] = "24 bit true color"; + }; + FixedLine FL_JPG_QUALITY + { + Hide = TRUE; + Size = MAP_APPFONT ( 110 , 8 ) ; + Text [ en-US ] = "Quality" ; + }; + FixedLine FL_COMPRESSION + { + Hide = TRUE; + Size = MAP_APPFONT ( 110 , 8 ) ; + Text [ en-US ] = "Compression" ; + }; + FixedLine FL_MODE + { + Hide = TRUE; + Size = MAP_APPFONT ( 110 , 8 ) ; + Text [ en-US ] = "Mode" ; + }; + FixedLine FL_PBM_OPTIONS + { + Hide = TRUE; + Size = MAP_APPFONT ( 110 , 8 ) ; + Text [ en-US ] = "File Format" ; + }; + ScrollBar SB_COMPRESSION + { + Hide = TRUE; + Size = MAP_APPFONT ( 48, 10 ) ; + VScroll = FALSE ; + HScroll = TRUE; + Drag = TRUE ; + }; + NumericField NF_COMPRESSION + { + HelpID = "svtools:NumericField:DLG_EXPORT:NF_COMPRESSION"; + Hide = TRUE; + Border = TRUE ; + Size = MAP_APPFONT ( 30, 12 ) ; + TabStop = TRUE ; + Repeat = TRUE ; + Spin = FALSE ; + Maximum = 99999; + Last = 255 ; + }; + FixedText FT_JPG_MIN + { + Hide = TRUE; + Size = MAP_APPFONT ( 41 , 10 ) ; + Text [ en-US ] = "1 is minimum Quality and smallest file size." ; + }; + FixedText FT_JPG_MAX + { + Hide = TRUE; + Size = MAP_APPFONT ( 41 , 10 ) ; + Text [ en-US ] = "100 is maximum Quality and biggest file size." ; + }; + FixedText FT_PNG_MIN + { + Hide = TRUE; + Size = MAP_APPFONT ( 41 , 10 ) ; + Text [ en-US ] = "0 is biggest file size and fastest loading." ; + }; + FixedText FT_PNG_MAX + { + Hide = TRUE; + Size = MAP_APPFONT ( 41 , 10 ) ; + Text [ en-US ] = "9 is smallest file size and slowest loading." ; + }; + CheckBox CB_JPG_PREVIEW + { + HelpID = "svtools:CheckBox:DLG_EXPORT:CB_JPG_PREVIEW"; + Hide = TRUE; + Size = MAP_APPFONT ( 60 , 10 ) ; + Text [ en-US ] = "Preview" ; + }; + CheckBox CB_INTERLACED + { + HelpID = "svtools:CheckBox:DLG_EXPORT:CB_INTERLACED"; + Hide = TRUE; + Size = MAP_APPFONT ( 60 , 10 ) ; + Text [ en-US ] = "Interlaced" ; + }; + CheckBox CB_RLE_ENCODING + { + HelpID = "svtools:CheckBox:DLG_EXPORT:CB_RLE_ENCODING"; + Hide = TRUE; + Size = MAP_APPFONT ( 60 , 10 ) ; + Text [ en-US ] = "RLE encoding" ; + }; + FixedLine FL_GIF_DRAWING_OBJECTS + { + Hide = TRUE; + Size = MAP_APPFONT ( 110 , 8 ) ; + Text [ en-US ] = "Drawing Objects" ; + }; + CheckBox CB_SAVE_TRANSPARENCY + { + HelpID = "svtools:CheckBox:DLG_EXPORT:CB_SAVE_TRANSPARENCY"; + Hide = TRUE; + Size = MAP_APPFONT ( 60 , 10 ) ; + Text [ en-US ] = "Save transparency" ; + }; + RadioButton RB_BINARY + { + HelpID = "svtools:RadioButton:DLG_EXPORT:RB_BINARY"; + Hide = TRUE; + Size = MAP_APPFONT ( 105 , 10 ) ; + Text [ en-US ] = "Binary" ; + }; + RadioButton RB_TEXT + { + HelpID = "svtools:RadioButton:DLG_EXPORT:RB_TEXT"; + Hide = TRUE; + Size = MAP_APPFONT ( 105 , 10 ) ; + Text [ en-US ] = "Text" ; + }; + FixedLine FL_EPS_PREVIEW + { + Hide = TRUE; + Size = MAP_APPFONT ( 110 , 8 ) ; + Text [ en-US ] = "Preview" ; + }; + CheckBox CB_EPS_PREVIEW_TIFF + { + HelpID = "svtools:CheckBox:DLG_EXPORT:CB_EPS_PREVIEW_TIFF"; + Hide = TRUE; + Size = MAP_APPFONT ( 60 , 10 ) ; + Text [ en-US ] = "Image Preview (TIFF)" ; + }; + CheckBox CB_EPS_PREVIEW_EPSI + { + HelpID = "svtools:CheckBox:DLG_EXPORT:CB_EPS_PREVIEW_EPSI"; + Hide = TRUE; + Size = MAP_APPFONT ( 60 , 10 ) ; + Text [ en-US ] = "Interchange (EPSI)" ; + }; + FixedLine FL_EPS_VERSION + { + Hide = TRUE; + Size = MAP_APPFONT ( 41 , 10 ) ; + Text [ en-US ] = "Version" ; + }; + RadioButton RB_EPS_LEVEL1 + { + HelpID = "svtools:RadioButton:DLG_EXPORT:RB_EPS_LEVEL1"; + Hide = TRUE; + Size = MAP_APPFONT ( 105 , 10 ) ; + Text [ en-US ] = "Level 1" ; + }; + RadioButton RB_EPS_LEVEL2 + { + HelpID = "svtools:RadioButton:DLG_EXPORT:RB_EPS_LEVEL2"; + Hide = TRUE; + Size = MAP_APPFONT ( 105 , 10 ) ; + Text [ en-US ] = "Level 2" ; + }; + FixedLine FL_EPS_COLOR_FORMAT + { + Hide = TRUE; + Size = MAP_APPFONT ( 41 , 10 ) ; + Text [ en-US ] = "Color format" ; + }; + RadioButton RB_EPS_COLOR_FORMAT1 + { + HelpID = "svtools:RadioButton:DLG_EXPORT:RB_EPS_COLOR_FORMAT1"; + Hide = TRUE; + Size = MAP_APPFONT ( 105 , 10 ) ; + Text [ en-US ] = "Color" ; + }; + RadioButton RB_EPS_COLOR_FORMAT2 + { + HelpID = "svtools:RadioButton:DLG_EXPORT:RB_EPS_COLOR_FORMAT2"; + Hide = TRUE; + Size = MAP_APPFONT ( 105 , 10 ) ; + Text [ en-US ] = "Grayscale" ; + }; + RadioButton RB_EPS_COMPRESSION_LZW + { + HelpID = "svtools:RadioButton:DLG_EXPORT:RB_EPS_COMPRESSION_LZW"; + Hide = TRUE; + Size = MAP_APPFONT ( 105 , 10 ) ; + Text [ en-US ] = "LZW encoding" ; + }; + RadioButton RB_EPS_COMPRESSION_NONE + { + HelpID = "svtools:RadioButton:DLG_EXPORT:RB_EPS_COMPRESSION_NONE"; + Hide = TRUE; + Size = MAP_APPFONT ( 105 , 10 ) ; + Text [ en-US ] = "None" ; + }; + FixedLine FL_ESTIMATED_SIZE + { + Hide = TRUE; + Size = MAP_APPFONT ( 41 , 10 ) ; + }; + FixedText FT_ESTIMATED_SIZE + { + Hide = TRUE; + Size = MAP_APPFONT ( 41 , 10 ) ; + }; + String STR_ESTIMATED_SIZE_PIX_1 + { + Text [ en-US ] = "The picture needs about %1 KB of memory."; + }; + String STR_ESTIMATED_SIZE_PIX_2 + { + Text [ en-US ] = "The picture needs about %1 KB of memory,\n the file size is %2 KB."; + }; + String STR_ESTIMATED_SIZE_VEC + { + Text [ en-US ] = "The file size is %1 KB."; + }; + FixedLine FL_BUTTONS + { + Hide = TRUE; + Size = MAP_APPFONT ( 41 , 10 ) ; + }; + FixedBitmap FB_JPG_PREVIEW + { + Hide = TRUE; + OutputSize = TRUE ; + Scale = TRUE; + Border = TRUE; + }; + ScrollBar SB_ZOOM + { + Hide = TRUE; + Size = MAP_APPFONT ( 48, 10 ); + VScroll = FALSE; + HScroll = TRUE; + Drag = TRUE; + MinPos = 5; + MaxPos = 100; + ThumbPos = 50; + }; + NumericField NF_ZOOM + { + HelpID = "svtools:NumericField:DLG_EXPORT:NF_ZOOM"; + Hide = TRUE; + Border = TRUE ; + Size = MAP_APPFONT ( 30, 12 ) ; + TabStop = TRUE ; + Repeat = TRUE ; + Spin = FALSE ; + Maximum = 3000; + Last = 255 ; + }; + ScrollBar SB_JPG_PREVIEW_HORZ + { + Hide = TRUE; + Size = MAP_APPFONT ( 48, 10 ); + VScroll = FALSE; + HScroll = TRUE; + Drag = TRUE; + MinPos = 0; + MaxPos = 100; + ThumbPos = 50; + }; + ScrollBar SB_JPG_PREVIEW_VERT + { + Hide = TRUE; + Size = MAP_APPFONT ( 48, 10 ); + VScroll = TRUE; + HScroll = FALSE; + Drag = TRUE; + MinPos = 0; + MaxPos = 100; + ThumbPos = 50; + }; + OKButton BTN_OK + { + Hide = TRUE; + Size = MAP_APPFONT ( 50 , 14 ) ; + TabStop = TRUE ; + DefButton = TRUE ; + }; + CancelButton BTN_CANCEL + { + Hide = TRUE; + Size = MAP_APPFONT ( 50 , 14 ) ; + TabStop = TRUE ; + }; + HelpButton BTN_HELP + { + Hide = TRUE; + Size = MAP_APPFONT ( 50 , 14 ) ; + TabStop = TRUE ; + }; +}; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/svtools/source/filter/filter.cxx b/svtools/source/filter/filter.cxx new file mode 100644 index 000000000000..086f57061d7a --- /dev/null +++ b/svtools/source/filter/filter.cxx @@ -0,0 +1,2260 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#if defined UNX && defined ALPHA +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FilterConfigCache.hxx" +#include +#include +#include +#include "gifread.hxx" +#include "jpeg.hxx" +#include "xbmread.hxx" +#include "xpmread.hxx" +#include +#include +#include "sgffilt.hxx" +#include "osl/module.hxx" +#include +#include +#include +#include +#include +#ifndef _COM_SUN_STAR_UNO_XTYPEPROVIDER_HPP_ +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SvFilterOptionsDialog.hxx" + +#define PMGCHUNG_msOG 0x6d734f47 // Microsoft Office Animated GIF + +#if (defined OS2 && !defined ICC) + +#define IMPORT_FUNCTION_NAME "_GraphicImport" +#define EXPORT_FUNCTION_NAME "_GraphicExport" +#define IMPDLG_FUNCTION_NAME "_DoImportDialog" +#define EXPDLG_FUNCTION_NAME "_DoExportDialog" + +#else + +#define IMPORT_FUNCTION_NAME "GraphicImport" +#define EXPORT_FUNCTION_NAME "GraphicExport" +#define IMPDLG_FUNCTION_NAME "DoImportDialog" +#define EXPDLG_FUNCTION_NAME "DoExportDialog" + +#endif + + +// ----------- +// - statics - +// ----------- + +using namespace ::rtl; +using namespace ::com::sun::star; + +static List* pFilterHdlList = NULL; + +static ::osl::Mutex& getListMutex() +{ + static ::osl::Mutex s_aListProtection; + return s_aListProtection; +} + +static GraphicFilter* pGraphicFilter=0; + +// ------------------------- +// - ImpFilterOutputStream - +// ------------------------- + +class ImpFilterOutputStream : public ::cppu::WeakImplHelper1< ::com::sun::star::io::XOutputStream > +{ +protected: + + SvStream& mrStm; + + virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< sal_Int8 >& rData ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) { mrStm.Write( rData.getConstArray(), rData.getLength() ); } + virtual void SAL_CALL flush() throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) { mrStm.Flush(); } + virtual void SAL_CALL closeOutput() throw() {} + +public: + + ImpFilterOutputStream( SvStream& rStm ) : mrStm( rStm ) {} + ~ImpFilterOutputStream() {} +}; + +BOOL ImplDirEntryHelper::Exists( const INetURLObject& rObj ) +{ + BOOL bExists = FALSE; + + try + { + ::rtl::OUString aTitle; + ::ucbhelper::Content aCnt( rObj.GetMainURL( INetURLObject::NO_DECODE ), + ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() ); + + bExists = aCnt.isDocument(); + } + catch( ::com::sun::star::ucb::CommandAbortedException& ) + { + DBG_ERRORFILE( "CommandAbortedException" ); + } + catch( ::com::sun::star::ucb::ContentCreationException& ) + { + DBG_ERRORFILE( "ContentCreationException" ); + } + catch( ... ) + { +// DBG_ERRORFILE( "Any other exception" ); + } + return bExists; +} + +// ----------------------------------------------------------------------------- + +void ImplDirEntryHelper::Kill( const String& rMainUrl ) +{ + try + { + ::ucbhelper::Content aCnt( rMainUrl, + ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() ); + + aCnt.executeCommand( ::rtl::OUString::createFromAscii( "delete" ), + ::com::sun::star::uno::makeAny( sal_Bool( sal_True ) ) ); + } + catch( ::com::sun::star::ucb::CommandAbortedException& ) + { + DBG_ERRORFILE( "CommandAbortedException" ); + } + catch( ... ) + { + DBG_ERRORFILE( "Any other exception" ); + } +} + +// -------------------- +// - Helper functions - +// -------------------- + +//-------------------------------------------------------------------------- + +BYTE* ImplSearchEntry( BYTE* pSource, BYTE* pDest, ULONG nComp, ULONG nSize ) +{ + while ( nComp-- >= nSize ) + { + ULONG i; + for ( i = 0; i < nSize; i++ ) + { + if ( ( pSource[i]&~0x20 ) != ( pDest[i]&~0x20 ) ) + break; + } + if ( i == nSize ) + return pSource; + pSource++; + } + return NULL; +} + +//-------------------------------------------------------------------------- + +inline String ImpGetExtension( const String &rPath ) +{ + String aExt; + INetURLObject aURL( rPath ); + aExt = aURL.GetFileExtension().toAsciiUpperCase(); + return aExt; +} + +/************************************************************************* +|* +|* ImpPeekGraphicFormat() +|* +|* Beschreibung: +|* Diese Funktion kann zweierlei: +|* 1.) Datei anlesen, Dateiformat ermitteln +|* Eingabe-prarameter: +|* rPath - Dateipfad +|* rFormatExtension - Inhalt egal +|* bTest - setze FALSE +|* Ausgabe-parameter: +|* Funkionswert - TRUE wenn Erfolg +|* rFormatExtension - Bei Erfolg: uebliche Dateiendung +|* des Formats (Grossbuchstaben) +|* 2.) Datei anlesen, Dateiformat ueberpruefen +|* Eingabe-prarameter: +|* rPath - Dateipfad +|* rFormatExtension - uebliche Dateiendung des Formats +|* (Grossbuchstaben) +|* bTest - setze TRUE +|* Ausgabe-parameter: +|* Funkionswert - FALSE, wenn die Datei bestimmt nicht +|* vom uebgebenen Format ist. +|* TRUE, wenn die Datei WAHRSCHEINLICH von +|* dem Format ist, ODER WENN DAS FORMAT +|* DIESER FUNKTION NICHT BEKANNT IST! +|* +|* Ersterstellung OH 26.05.95 +|* Letzte Aenderung OH 07.08.95 +|* +*************************************************************************/ + +static BOOL ImpPeekGraphicFormat( SvStream& rStream, String& rFormatExtension, BOOL bTest ) +{ + USHORT i; + BYTE sFirstBytes[ 256 ]; + ULONG nFirstLong,nSecondLong; + ULONG nStreamPos = rStream.Tell(); + + rStream.Seek( STREAM_SEEK_TO_END ); + ULONG nStreamLen = rStream.Tell() - nStreamPos; + rStream.Seek( nStreamPos ); + + if ( !nStreamLen ) + { + SvLockBytes* pLockBytes = rStream.GetLockBytes(); + if ( pLockBytes ) + pLockBytes->SetSynchronMode( TRUE ); + + rStream.Seek( STREAM_SEEK_TO_END ); + nStreamLen = rStream.Tell() - nStreamPos; + rStream.Seek( nStreamPos ); + } + // Die ersten 256 Bytes in einen Buffer laden: + if( nStreamLen >= 256 ) + rStream.Read( sFirstBytes, 256 ); + else + { + rStream.Read( sFirstBytes, nStreamLen ); + + for( i = (USHORT) nStreamLen; i < 256; i++ ) + sFirstBytes[ i ]=0; + } + + if( rStream.GetError() ) + return FALSE; + + // Die ersten 8 Bytes in nFirstLong, nSecondLong unterbringen, + // Big-Endian: + for( i = 0, nFirstLong = 0L, nSecondLong = 0L; i < 4; i++ ) + { + nFirstLong=(nFirstLong<<8)|(ULONG)sFirstBytes[i]; + nSecondLong=(nSecondLong<<8)|(ULONG)sFirstBytes[i+4]; + } + + // Folgende Variable ist nur bei bTest==TRUE interessant. Sie + // bleibt FALSE, wenn das Format (rFormatExtension) hier noch nicht + // einprogrammiert wurde. + BOOL bSomethingTested = FALSE; + + // Nun werden die verschieden Formate ueberprueft. Dabei ist die + // Reihenfolge nicht egal. Z.b. koennte eine MET-Datei auch durch + // den BMP-Test gehen, umgekehrt kann eine BMP-Datei kaum durch den + // MET-Test gehen. Also sollte MET vor BMP getestet werden. + // Theoretisch waere aber vielleicht auch eine BMP-Datei denkbar, + // die durch den MET-Test geht. + // Diese Probleme gibt es natuerlich nicht nur bei MET und BMP. + // Deshalb wird im Falle der Uberpruefung eines Formats (bTest==TRUE) + // nur genau dieses eine Format getestet. Alles andere koennte fatale + // Folgen haben, z.B. wenn der Benutzer sagt, es sei BMP-Datei (und es + // ist BMP-Datei), und hier wuerde die Datei durch den MET-Test gehen... + + //--------------------------- MET ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "MET", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested=TRUE; + if( sFirstBytes[2] == 0xd3 ) + { + rStream.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); + rStream.Seek( nStreamPos ); + USHORT nFieldSize; + BYTE nMagic; + BOOL bOK=TRUE; + rStream >> nFieldSize >> nMagic; + for (i=0; i<3; i++) { + if (nFieldSize<6) { bOK=FALSE; break; } + if (nStreamLen < rStream.Tell() + nFieldSize ) { bOK=FALSE; break; } + rStream.SeekRel(nFieldSize-3); + rStream >> nFieldSize >> nMagic; + if (nMagic!=0xd3) { bOK=FALSE; break; } + } + rStream.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); + if (bOK && !rStream.GetError()) { + rFormatExtension= UniString::CreateFromAscii( "MET", 3 ); + return TRUE; + } + } + } + + //--------------------------- BMP ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "BMP", 3 ) == COMPARE_EQUAL ) ) + { + BYTE nOffs; + + bSomethingTested=TRUE; + + // OS/2-Bitmaparray ('BA') koennen wir evtl. auch lesen, + // dementspr. muessen wir den Offset anpassen, + // um auf die erste Bitmap im Array zu stossen + if ( sFirstBytes[0] == 0x42 && sFirstBytes[1] == 0x41 ) + nOffs = 14; + else + nOffs = 0; + + // Jetzt testen wir zunaechst auf 'BM' + if ( sFirstBytes[0+nOffs]==0x42 && sFirstBytes[1+nOffs]==0x4d ) + { + // unter OS/2 koennen die Reserved-Flags != 0 sein + // (was sie eigentlich nicht duerften); + // in diesem Fall testen wir die Groesse des BmpInfoHeaders + if ( ( sFirstBytes[6+nOffs]==0x00 && + sFirstBytes[7+nOffs]==0x00 && + sFirstBytes[8+nOffs]==0x00 && + sFirstBytes[9+nOffs]==0x00 ) || + sFirstBytes[14+nOffs] == 0x28 || + sFirstBytes[14+nOffs] == 0x0c ) + { + rFormatExtension = UniString::CreateFromAscii( "BMP", 3 ); + return TRUE; + } + } + } + + //--------------------------- WMF/EMF ------------------------------------ + + if( !bTest || + ( rFormatExtension.CompareToAscii( "WMF", 3 ) == COMPARE_EQUAL ) || + ( rFormatExtension.CompareToAscii( "EMF", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested = TRUE; + + if ( nFirstLong==0xd7cdc69a || nFirstLong==0x01000900 ) + { + rFormatExtension = UniString::CreateFromAscii( "WMF", 3 ); + return TRUE; + } + else if( nFirstLong == 0x01000000 && sFirstBytes[ 40 ] == 0x20 && sFirstBytes[ 41 ] == 0x45 && + sFirstBytes[ 42 ] == 0x4d && sFirstBytes[ 43 ] == 0x46 ) + { + rFormatExtension = UniString::CreateFromAscii( "EMF", 3 ); + return TRUE; + } + } + + //--------------------------- PCX ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "PCX", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested=TRUE; + if (sFirstBytes[0]==0x0a) + { + BYTE nVersion=sFirstBytes[1]; + BYTE nEncoding=sFirstBytes[2]; + if( ( nVersion==0 || nVersion==2 || nVersion==3 || nVersion==5 ) && nEncoding<=1 ) + { + rFormatExtension = UniString::CreateFromAscii( "PCX", 3 ); + return TRUE; + } + } + } + + //--------------------------- TIF ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "TIF", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested=TRUE; + if ( nFirstLong==0x49492a00 || nFirstLong==0x4d4d002a ) + { + rFormatExtension=UniString::CreateFromAscii( "TIF", 3 ); + return TRUE; + } + } + + //--------------------------- GIF ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "GIF", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested=TRUE; + if ( nFirstLong==0x47494638 && (sFirstBytes[4]==0x37 || sFirstBytes[4]==0x39) && sFirstBytes[5]==0x61 ) + { + rFormatExtension = UniString::CreateFromAscii( "GIF", 3 ); + return TRUE; + } + } + + //--------------------------- PNG ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "PNG", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested=TRUE; + if (nFirstLong==0x89504e47 && nSecondLong==0x0d0a1a0a) + { + rFormatExtension = UniString::CreateFromAscii( "PNG", 3 ); + return TRUE; + } + } + + //--------------------------- JPG ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "JPG", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested=TRUE; + if ( ( nFirstLong==0xffd8ffe0 && sFirstBytes[6]==0x4a && sFirstBytes[7]==0x46 && sFirstBytes[8]==0x49 && sFirstBytes[9]==0x46 ) || + ( nFirstLong==0xffd8fffe ) || ( 0xffd8ff00 == ( nFirstLong & 0xffffff00 ) ) ) + { + rFormatExtension = UniString::CreateFromAscii( "JPG", 3 ); + return TRUE; + } + } + + //--------------------------- SVM ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "SVM", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested=TRUE; + if( nFirstLong==0x53564744 && sFirstBytes[4]==0x49 ) + { + rFormatExtension = UniString::CreateFromAscii( "SVM", 3 ); + return TRUE; + } + else if( sFirstBytes[0]==0x56 && sFirstBytes[1]==0x43 && sFirstBytes[2]==0x4C && + sFirstBytes[3]==0x4D && sFirstBytes[4]==0x54 && sFirstBytes[5]==0x46 ) + { + rFormatExtension = UniString::CreateFromAscii( "SVM", 3 ); + return TRUE; + } + } + + //--------------------------- PCD ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "PCD", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested = TRUE; + if( nStreamLen >= 2055 ) + { + char sBuf[8]; + rStream.Seek( nStreamPos + 2048 ); + rStream.Read( sBuf, 7 ); + + if( strncmp( sBuf, "PCD_IPI", 7 ) == 0 ) + { + rFormatExtension = UniString::CreateFromAscii( "PCD", 3 ); + return TRUE; + } + } + } + + //--------------------------- PSD ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "PSD", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested = TRUE; + if ( ( nFirstLong == 0x38425053 ) && ( (nSecondLong >> 16 ) == 1 ) ) + { + rFormatExtension = UniString::CreateFromAscii( "PSD", 3 ); + return TRUE; + } + } + + //--------------------------- EPS ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "EPS", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested = TRUE; + if ( ( nFirstLong == 0xC5D0D3C6 ) || ( ImplSearchEntry( sFirstBytes, (BYTE*)"%!PS-Adobe", 10, 10 ) && + ImplSearchEntry( &sFirstBytes[15], (BYTE*)"EPS", 3, 3 ) ) ) + { + rFormatExtension = UniString::CreateFromAscii( "EPS", 3 ); + return TRUE; + } + } + + //--------------------------- DXF ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "DXF", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested=TRUE; + + i=0; + while (i<256 && sFirstBytes[i]<=32) + i++; + + if (i<256) + { + if( sFirstBytes[i]=='0' ) + i++; + else + i=256; + } + while( i<256 && sFirstBytes[i]<=32 ) + i++; + + if (i+7<256) + { + if (strncmp((char*)(sFirstBytes+i),"SECTION",7)==0) + { + rFormatExtension = UniString::CreateFromAscii( "DXF", 3 ); + return TRUE; + } + } + + if( strncmp( (char*) sFirstBytes, "AutoCAD Binary DXF", 18 ) == 0 ) + { + rFormatExtension = UniString::CreateFromAscii( "DXF", 3 ); + return TRUE; + } + } + + //--------------------------- PCT ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "PCT", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested = TRUE; + BYTE sBuf[3]; + // store number format + sal_uInt16 oldNumberFormat = rStream.GetNumberFormatInt(); + sal_uInt32 nOffset; // in ms documents the pict format is used without the first 512 bytes + for ( nOffset = 0; ( nOffset <= 512 ) && ( ( nStreamPos + nOffset + 14 ) <= nStreamLen ); nOffset += 512 ) + { + short y1,x1,y2,x2; + bool bdBoxOk = true; + + rStream.Seek( nStreamPos + nOffset); + // size of the pict in version 1 pict ( 2bytes) : ignored + rStream.SeekRel(2); + // bounding box (bytes 2 -> 9) + rStream.SetNumberFormatInt(NUMBERFORMAT_INT_BIGENDIAN); + rStream >> y1 >> x1 >> y2 >> x2; + rStream.SetNumberFormatInt(oldNumberFormat); // reset format + + if (x1 > x2 || y1 > y2 || // bad bdbox + (x1 == x2 && y1 == y2) || // 1 pixel picture + x2-x1 > 2048 || y2-y1 > 2048 ) // picture anormaly big + bdBoxOk = false; + + // read version op + rStream.Read( sBuf,3 ); + // see http://developer.apple.com/legacy/mac/library/documentation/mac/pdf/Imaging_With_QuickDraw/Appendix_A.pdf + // normal version 2 - page A23 and A24 + if ( sBuf[ 0 ] == 0x00 && sBuf[ 1 ] == 0x11 && sBuf[ 2 ] == 0x02) + { + rFormatExtension = UniString::CreateFromAscii( "PCT", 3 ); + return TRUE; + } + // normal version 1 - page A25 + else if (sBuf[ 0 ] == 0x11 && sBuf[ 1 ] == 0x01 && bdBoxOk) { + rFormatExtension = UniString::CreateFromAscii( "PCT", 3 ); + return TRUE; + } + // previous code kept in order to do not break any compatibility + // probably eroneous + else if ( sBuf[ 0 ] == 0x00 && sBuf[ 1 ] == 0x11 && sBuf[ 2 ] == 0x01 && bdBoxOk) + { + rFormatExtension = UniString::CreateFromAscii( "PCT", 3 ); + return TRUE; + } + } + } + + //------------------------- PBM + PGM + PPM --------------------------- + if( !bTest || + ( rFormatExtension.CompareToAscii( "PBM", 3 ) == COMPARE_EQUAL ) || + ( rFormatExtension.CompareToAscii( "PGM", 3 ) == COMPARE_EQUAL ) || + ( rFormatExtension.CompareToAscii( "PPM", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested=TRUE; + if ( sFirstBytes[ 0 ] == 'P' ) + { + switch( sFirstBytes[ 1 ] ) + { + case '1' : + case '4' : + rFormatExtension = UniString::CreateFromAscii( "PBM", 3 ); + return TRUE; + + case '2' : + case '5' : + rFormatExtension = UniString::CreateFromAscii( "PGM", 3 ); + return TRUE; + + case '3' : + case '6' : + rFormatExtension = UniString::CreateFromAscii( "PPM", 3 ); + return TRUE; + } + } + } + + //--------------------------- RAS( SUN RasterFile )------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "RAS", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested=TRUE; + if( nFirstLong == 0x59a66a95 ) + { + rFormatExtension = UniString::CreateFromAscii( "RAS", 3 ); + return TRUE; + } + } + + //--------------------------- XPM ------------------------------------ + if( !bTest ) + { + bSomethingTested = TRUE; + if( ImplSearchEntry( sFirstBytes, (BYTE*)"/* XPM */", 256, 9 ) ) + { + rFormatExtension = UniString::CreateFromAscii( "XPM", 3 ); + return TRUE; + } + } + else if( rFormatExtension.CompareToAscii( "XPM", 3 ) == COMPARE_EQUAL ) + { + bSomethingTested = TRUE; + return TRUE; + } + + //--------------------------- XBM ------------------------------------ + if( !bTest ) + { + ULONG nSize = ( nStreamLen > 2048 ) ? 2048 : nStreamLen; + BYTE* pBuf = new BYTE [ nSize ]; + + rStream.Seek( nStreamPos ); + rStream.Read( pBuf, nSize ); + BYTE* pPtr = ImplSearchEntry( pBuf, (BYTE*)"#define", nSize, 7 ); + + if( pPtr ) + { + if( ImplSearchEntry( pPtr, (BYTE*)"_width", pBuf + nSize - pPtr, 6 ) ) + { + rFormatExtension = UniString::CreateFromAscii( "XBM", 3 ); + delete[] pBuf; + return TRUE; + } + } + delete[] pBuf; + } + else if( rFormatExtension.CompareToAscii( "XBM", 3 ) == COMPARE_EQUAL ) + { + bSomethingTested = TRUE; + return TRUE; + } + + //--------------------------- SVG ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "SVG", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested=TRUE; + + // just a simple test for the extension + if( rFormatExtension.CompareToAscii( "SVG", 3 ) == COMPARE_EQUAL ) + return TRUE; + } + + //--------------------------- TGA ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "TGA", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested = TRUE; + + // just a simple test for the extension + if( rFormatExtension.CompareToAscii( "TGA", 3 ) == COMPARE_EQUAL ) + return TRUE; + } + + //--------------------------- SGV ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "SGV", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested = TRUE; + + // just a simple test for the extension + if( rFormatExtension.CompareToAscii( "SGV", 3 ) == COMPARE_EQUAL ) + return TRUE; + } + + //--------------------------- SGF ------------------------------------ + if( !bTest || ( rFormatExtension.CompareToAscii( "SGF", 3 ) == COMPARE_EQUAL ) ) + { + bSomethingTested=TRUE; + if( sFirstBytes[ 0 ] == 'J' && sFirstBytes[ 1 ] == 'J' ) + { + rFormatExtension = UniString::CreateFromAscii( "SGF", 3 ); + return TRUE; + } + } + + return bTest && !bSomethingTested; +} + +//-------------------------------------------------------------------------- + +sal_uInt16 GraphicFilter::ImpTestOrFindFormat( const String& rPath, SvStream& rStream, sal_uInt16& rFormat ) +{ + sal_uInt16 n = pConfig->GetImportFormatCount(); + + // ggf. Filter bzw. Format durch anlesen ermitteln, + // oder durch anlesen zusichern, dass das Format stimmt: + if( rFormat == GRFILTER_FORMAT_DONTKNOW ) + { + String aFormatExt; + if( ImpPeekGraphicFormat( rStream, aFormatExt, FALSE ) ) + { + for( sal_uInt16 i = 0; i < n; i++ ) + { + if( pConfig->GetImportFormatExtension( i ).EqualsIgnoreCaseAscii( aFormatExt ) ) + { + rFormat = i; + return GRFILTER_OK; + } + } + } + // ggf. Filter anhand der Datei-Endung raussuchen: + if( rPath.Len() ) + { + String aExt( ImpGetExtension( rPath ) ); + for( sal_uInt16 i = 0; i < n; i++ ) + { + if( pConfig->GetImportFormatExtension( i ).EqualsIgnoreCaseAscii( aExt ) ) + { + rFormat = i; + return GRFILTER_OK; + } + } + } + return GRFILTER_FORMATERROR; + } + else + { + String aTmpStr( pConfig->GetImportFormatExtension( rFormat ) ); + if( !ImpPeekGraphicFormat( rStream, aTmpStr, TRUE ) ) + return GRFILTER_FORMATERROR; + if ( pConfig->GetImportFormatExtension( rFormat ).EqualsIgnoreCaseAscii( "pcd" ) ) + { + sal_Int32 nBase = 2; // default Base0 + if ( pConfig->GetImportFilterType( rFormat ).EqualsIgnoreCaseAscii( "pcd_Photo_CD_Base4" ) ) + nBase = 1; + else if ( pConfig->GetImportFilterType( rFormat ).EqualsIgnoreCaseAscii( "pcd_Photo_CD_Base16" ) ) + nBase = 0; + String aFilterConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/Graphic/Import/PCD" ) ); + FilterConfigItem aFilterConfigItem( aFilterConfigPath ); + aFilterConfigItem.WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Resolution" ) ), nBase ); + } + } + + return GRFILTER_OK; +} + +//-------------------------------------------------------------------------- + +static Graphic ImpGetScaledGraphic( const Graphic& rGraphic, FilterConfigItem& rConfigItem ) +{ + Graphic aGraphic; + ByteString aResMgrName( "svt", 3 ); + ResMgr* pResMgr; + + pResMgr = ResMgr::CreateResMgr( aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() ); + + sal_Int32 nLogicalWidth = rConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "LogicalWidth" ) ), 0 ); + sal_Int32 nLogicalHeight = rConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "LogicalHeight" ) ), 0 ); + + if ( rGraphic.GetType() != GRAPHIC_NONE ) + { + sal_Int32 nMode = rConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "ExportMode" ) ), -1 ); + + if ( nMode == -1 ) // the property is not there, this is possible, if the graphic filter + { // is called via UnoGraphicExporter and not from a graphic export Dialog + nMode = 0; // then we are defaulting this mode to 0 + if ( nLogicalWidth || nLogicalHeight ) + nMode = 2; + } + + + Size aOriginalSize; + Size aPrefSize( rGraphic.GetPrefSize() ); + MapMode aPrefMapMode( rGraphic.GetPrefMapMode() ); + if ( aPrefMapMode == MAP_PIXEL ) + aOriginalSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM ); + else + aOriginalSize = Application::GetDefaultDevice()->LogicToLogic( aPrefSize, aPrefMapMode, MAP_100TH_MM ); + if ( !nLogicalWidth ) + nLogicalWidth = aOriginalSize.Width(); + if ( !nLogicalHeight ) + nLogicalHeight = aOriginalSize.Height(); + if( rGraphic.GetType() == GRAPHIC_BITMAP ) + { + + // Aufloesung wird eingestellt + if( nMode == 1 ) + { + Bitmap aBitmap( rGraphic.GetBitmap() ); + MapMode aMap( MAP_100TH_INCH ); + + sal_Int32 nDPI = rConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Resolution" ) ), 75 ); + Fraction aFrac( 1, Min( Max( nDPI, sal_Int32( 75 ) ), sal_Int32( 600 ) ) ); + + aMap.SetScaleX( aFrac ); + aMap.SetScaleY( aFrac ); + + Size aOldSize = aBitmap.GetSizePixel(); + aBitmap.SetPrefMapMode( aMap ); + aBitmap.SetPrefSize( Size( aOldSize.Width() * 100, + aOldSize.Height() * 100 ) ); + + aGraphic = Graphic( aBitmap ); + } + // Groesse wird eingestellt + else if( nMode == 2 ) + { + BitmapEx aBitmapEx( rGraphic.GetBitmapEx() ); + aBitmapEx.SetPrefMapMode( MapMode( MAP_100TH_MM ) ); + aBitmapEx.SetPrefSize( Size( nLogicalWidth, nLogicalHeight ) ); + aGraphic = Graphic( aBitmapEx ); + } + else + aGraphic = rGraphic; + + sal_Int32 nColors = rConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Color" ) ), 0 ); // #92767# + if ( nColors ) // graphic conversion necessary ? + { + BitmapEx aBmpEx( aGraphic.GetBitmapEx() ); + aBmpEx.Convert( (BmpConversion)nColors ); // the entries in the xml section have the same meaning as + aGraphic = aBmpEx; // they have in the BmpConversion enum, so it should be + } // allowed to cast them + } + else + { + if( ( nMode == 1 ) || ( nMode == 2 ) ) + { + GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() ); + ::com::sun::star::awt::Size aDefaultSize( 10000, 10000 ); + Size aNewSize( OutputDevice::LogicToLogic( Size( nLogicalWidth, nLogicalHeight ), MAP_100TH_MM, aMtf.GetPrefMapMode() ) ); + + if( aNewSize.Width() && aNewSize.Height() ) + { + const Size aPreferredSize( aMtf.GetPrefSize() ); + aMtf.Scale( Fraction( aNewSize.Width(), aPreferredSize.Width() ), + Fraction( aNewSize.Height(), aPreferredSize.Height() ) ); + } + aGraphic = Graphic( aMtf ); + } + else + aGraphic = rGraphic; + } + + } + else + aGraphic = rGraphic; + + delete pResMgr; + + return aGraphic; +} + +static String ImpCreateFullFilterPath( const String& rPath, const String& rFilterName ) +{ + ::rtl::OUString aPathURL; + + ::osl::FileBase::getFileURLFromSystemPath( rPath, aPathURL ); + aPathURL += String( '/' ); + + ::rtl::OUString aSystemPath; + ::osl::FileBase::getSystemPathFromFileURL( aPathURL, aSystemPath ); + aSystemPath += ::rtl::OUString( rFilterName ); + + return String( aSystemPath ); +} + + +// -------------------------- +// - ImpFilterLibCacheEntry - +// -------------------------- + +class ImpFilterLibCache; + +struct ImpFilterLibCacheEntry +{ + ImpFilterLibCacheEntry* mpNext; + osl::Module maLibrary; + String maFiltername; + PFilterCall mpfnImport; + PFilterDlgCall mpfnImportDlg; + + ImpFilterLibCacheEntry( const String& rPathname, const String& rFiltername ); + int operator==( const String& rFiltername ) const { return maFiltername == rFiltername; } + + PFilterCall GetImportFunction(); + PFilterDlgCall GetImportDlgFunction(); + PFilterCall GetExportFunction() { return (PFilterCall) maLibrary.getFunctionSymbol( UniString::CreateFromAscii( EXPORT_FUNCTION_NAME ) ); } + PFilterDlgCall GetExportDlgFunction() { return (PFilterDlgCall) maLibrary.getFunctionSymbol( UniString::CreateFromAscii( EXPDLG_FUNCTION_NAME ) ); } +}; + +// ------------------------------------------------------------------------ + +ImpFilterLibCacheEntry::ImpFilterLibCacheEntry( const String& rPathname, const String& rFiltername ) : + mpNext ( NULL ), + maLibrary ( rPathname ), + maFiltername ( rFiltername ), + mpfnImport ( NULL ), + mpfnImportDlg ( NULL ) +{ +} + +// ------------------------------------------------------------------------ + +PFilterCall ImpFilterLibCacheEntry::GetImportFunction() +{ + if( !mpfnImport ) + mpfnImport = (PFilterCall) maLibrary.getFunctionSymbol( UniString::CreateFromAscii( IMPORT_FUNCTION_NAME ) ); + + return mpfnImport; +} + +// ------------------------------------------------------------------------ + +PFilterDlgCall ImpFilterLibCacheEntry::GetImportDlgFunction() +{ + if( !mpfnImportDlg ) + mpfnImportDlg = (PFilterDlgCall)maLibrary.getFunctionSymbol( UniString::CreateFromAscii( IMPDLG_FUNCTION_NAME ) ); + + return mpfnImportDlg; +} + +// --------------------- +// - ImpFilterLibCache - +// --------------------- + +class ImpFilterLibCache +{ + ImpFilterLibCacheEntry* mpFirst; + ImpFilterLibCacheEntry* mpLast; + +public: + ImpFilterLibCache(); + ~ImpFilterLibCache(); + + ImpFilterLibCacheEntry* GetFilter( const String& rFilterPath, const String& rFiltername ); +}; + +// ------------------------------------------------------------------------ + +ImpFilterLibCache::ImpFilterLibCache() : + mpFirst ( NULL ), + mpLast ( NULL ) +{ +} + +// ------------------------------------------------------------------------ + +ImpFilterLibCache::~ImpFilterLibCache() +{ + ImpFilterLibCacheEntry* pEntry = mpFirst; + while( pEntry ) + { + ImpFilterLibCacheEntry* pNext = pEntry->mpNext; + delete pEntry; + pEntry = pNext; + } +} + +// ------------------------------------------------------------------------ + +ImpFilterLibCacheEntry* ImpFilterLibCache::GetFilter( const String& rFilterPath, const String& rFilterName ) +{ + ImpFilterLibCacheEntry* pEntry = mpFirst; + + while( pEntry ) + { + if( *pEntry == rFilterName ) + break; + else + pEntry = pEntry->mpNext; + } + if( !pEntry ) + { + String aPhysicalName( ImpCreateFullFilterPath( rFilterPath, rFilterName ) ); + pEntry = new ImpFilterLibCacheEntry( aPhysicalName, rFilterName ); + + if ( pEntry->maLibrary.is() ) + { + if( !mpFirst ) + mpFirst = mpLast = pEntry; + else + mpLast = mpLast->mpNext = pEntry; + } + else + { + delete pEntry; + pEntry = NULL; + } + } + return pEntry; +}; + +// ------------------------------------------------------------------------ + +namespace { struct Cache : public rtl::Static {}; } + +// ----------------- +// - GraphicFilter - +// ----------------- + +GraphicFilter::GraphicFilter( sal_Bool bConfig ) : + bUseConfig ( bConfig ), + nExpGraphHint ( 0 ) +{ + ImplInit(); +} + +// ------------------------------------------------------------------------ + +GraphicFilter::~GraphicFilter() +{ + { + ::osl::MutexGuard aGuard( getListMutex() ); + pFilterHdlList->Remove( (void*)this ); + if ( !pFilterHdlList->Count() ) + { + delete pFilterHdlList, pFilterHdlList = NULL; + delete pConfig; + } + } + + + delete pErrorEx; +} + +// ------------------------------------------------------------------------ + +void GraphicFilter::ImplInit() +{ + { + ::osl::MutexGuard aGuard( getListMutex() ); + + if ( !pFilterHdlList ) + { + pFilterHdlList = new List; + pConfig = new FilterConfigCache( bUseConfig ); + } + else + pConfig = ((GraphicFilter*)pFilterHdlList->First())->pConfig; + + pFilterHdlList->Insert( (void*)this ); + } + + if( bUseConfig ) + { +#if defined WNT + rtl::OUString url(RTL_CONSTASCII_USTRINGPARAM("$BRAND_BASE_DIR/program")); +#else + rtl::OUString url(RTL_CONSTASCII_USTRINGPARAM("$OOO_BASE_DIR/program")); +#endif + rtl::Bootstrap::expandMacros(url); //TODO: detect failure + utl::LocalFileHelper::ConvertURLToPhysicalName(url, aFilterPath); + } + + pErrorEx = new FilterErrorEx; + bAbort = sal_False; +} + +// ------------------------------------------------------------------------ + +ULONG GraphicFilter::ImplSetError( ULONG nError, const SvStream* pStm ) +{ + pErrorEx->nFilterError = nError; + pErrorEx->nStreamError = pStm ? pStm->GetError() : ERRCODE_NONE; + return nError; +} +// ------------------------------------------------------------------------ + +USHORT GraphicFilter::GetImportFormatCount() +{ + return pConfig->GetImportFormatCount(); +} + +// ------------------------------------------------------------------------ + +USHORT GraphicFilter::GetImportFormatNumber( const String& rFormatName ) +{ + return pConfig->GetImportFormatNumber( rFormatName ); +} + +// ------------------------------------------------------------------------ + +USHORT GraphicFilter::GetImportFormatNumberForMediaType( const String& rMediaType ) +{ + return pConfig->GetImportFormatNumberForMediaType( rMediaType ); +} + +// ------------------------------------------------------------------------ + +USHORT GraphicFilter::GetImportFormatNumberForShortName( const String& rShortName ) +{ + return pConfig->GetImportFormatNumberForShortName( rShortName ); +} + +// ------------------------------------------------------------------------ + +sal_uInt16 GraphicFilter::GetImportFormatNumberForTypeName( const String& rType ) +{ + return pConfig->GetImportFormatNumberForTypeName( rType ); +} + +// ------------------------------------------------------------------------ + +String GraphicFilter::GetImportFormatName( USHORT nFormat ) +{ + return pConfig->GetImportFormatName( nFormat ); +} + +// ------------------------------------------------------------------------ + +String GraphicFilter::GetImportFormatTypeName( USHORT nFormat ) +{ + return pConfig->GetImportFilterTypeName( nFormat ); +} + +// ------------------------------------------------------------------------ + +String GraphicFilter::GetImportFormatMediaType( USHORT nFormat ) +{ + return pConfig->GetImportFormatMediaType( nFormat ); +} + +// ------------------------------------------------------------------------ + +String GraphicFilter::GetImportFormatShortName( USHORT nFormat ) +{ + return pConfig->GetImportFormatShortName( nFormat ); +} + +// ------------------------------------------------------------------------ + +String GraphicFilter::GetImportOSFileType( USHORT ) +{ + String aOSFileType; + return aOSFileType; +} + +// ------------------------------------------------------------------------ + +String GraphicFilter::GetImportWildcard( USHORT nFormat, sal_Int32 nEntry ) +{ + return pConfig->GetImportWildcard( nFormat, nEntry ); +} + +// ------------------------------------------------------------------------ + +BOOL GraphicFilter::IsImportPixelFormat( USHORT nFormat ) +{ + return pConfig->IsImportPixelFormat( nFormat ); +} + +// ------------------------------------------------------------------------ + +USHORT GraphicFilter::GetExportFormatCount() +{ + return pConfig->GetExportFormatCount(); +} + +// ------------------------------------------------------------------------ + +USHORT GraphicFilter::GetExportFormatNumber( const String& rFormatName ) +{ + return pConfig->GetExportFormatNumber( rFormatName ); +} + +// ------------------------------------------------------------------------ + +USHORT GraphicFilter::GetExportFormatNumberForMediaType( const String& rMediaType ) +{ + return pConfig->GetExportFormatNumberForMediaType( rMediaType ); +} + +// ------------------------------------------------------------------------ + +USHORT GraphicFilter::GetExportFormatNumberForShortName( const String& rShortName ) +{ + return pConfig->GetExportFormatNumberForShortName( rShortName ); +} + +// ------------------------------------------------------------------------ + +sal_uInt16 GraphicFilter::GetExportFormatNumberForTypeName( const String& rType ) +{ + return pConfig->GetExportFormatNumberForTypeName( rType ); +} + +// ------------------------------------------------------------------------ + +String GraphicFilter::GetExportFormatName( USHORT nFormat ) +{ + return pConfig->GetExportFormatName( nFormat ); +} + +// ------------------------------------------------------------------------ + +String GraphicFilter::GetExportFormatTypeName( USHORT nFormat ) +{ + return pConfig->GetExportFilterTypeName( nFormat ); +} + +// ------------------------------------------------------------------------ + +String GraphicFilter::GetExportFormatMediaType( USHORT nFormat ) +{ + return pConfig->GetExportFormatMediaType( nFormat ); +} + +// ------------------------------------------------------------------------ + +String GraphicFilter::GetExportFormatShortName( USHORT nFormat ) +{ + return pConfig->GetExportFormatShortName( nFormat ); +} + +// ------------------------------------------------------------------------ + +String GraphicFilter::GetExportOSFileType( USHORT ) +{ + String aOSFileType; + return aOSFileType; +} + +// ------------------------------------------------------------------------ + +String GraphicFilter::GetExportWildcard( USHORT nFormat, sal_Int32 nEntry ) +{ + return pConfig->GetExportWildcard( nFormat, nEntry ); +} + +// ------------------------------------------------------------------------ + +BOOL GraphicFilter::IsExportPixelFormat( USHORT nFormat ) +{ + return pConfig->IsExportPixelFormat( nFormat ); +} + +// ------------------------------------------------------------------------ + +USHORT GraphicFilter::CanImportGraphic( const INetURLObject& rPath, + USHORT nFormat, USHORT* pDeterminedFormat ) +{ + sal_uInt16 nRetValue = GRFILTER_FORMATERROR; + DBG_ASSERT( rPath.GetProtocol() != INET_PROT_NOT_VALID, "GraphicFilter::CanImportGraphic() : ProtType == INET_PROT_NOT_VALID" ); + + String aMainUrl( rPath.GetMainURL( INetURLObject::NO_DECODE ) ); + SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aMainUrl, STREAM_READ | STREAM_SHARE_DENYNONE ); + if ( pStream ) + { + nRetValue = CanImportGraphic( aMainUrl, *pStream, nFormat, pDeterminedFormat ); + delete pStream; + } + return nRetValue; +} + +// ------------------------------------------------------------------------ + +USHORT GraphicFilter::CanImportGraphic( const String& rMainUrl, SvStream& rIStream, + USHORT nFormat, USHORT* pDeterminedFormat ) +{ + ULONG nStreamPos = rIStream.Tell(); + sal_uInt16 nRes = ImpTestOrFindFormat( rMainUrl, rIStream, nFormat ); + + rIStream.Seek(nStreamPos); + + if( nRes==GRFILTER_OK && pDeterminedFormat!=NULL ) + *pDeterminedFormat = nFormat; + + return (USHORT) ImplSetError( nRes, &rIStream ); +} + +// ------------------------------------------------------------------------ +//SJ: TODO, we need to create a GraphicImporter component +USHORT GraphicFilter::ImportGraphic( Graphic& rGraphic, const INetURLObject& rPath, + USHORT nFormat, USHORT * pDeterminedFormat, sal_uInt32 nImportFlags ) +{ + sal_uInt16 nRetValue = GRFILTER_FORMATERROR; + DBG_ASSERT( rPath.GetProtocol() != INET_PROT_NOT_VALID, "GraphicFilter::ImportGraphic() : ProtType == INET_PROT_NOT_VALID" ); + + String aMainUrl( rPath.GetMainURL( INetURLObject::NO_DECODE ) ); + SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aMainUrl, STREAM_READ | STREAM_SHARE_DENYNONE ); + if ( pStream ) + { + nRetValue = ImportGraphic( rGraphic, aMainUrl, *pStream, nFormat, pDeterminedFormat, nImportFlags ); + delete pStream; + } + return nRetValue; +} + +USHORT GraphicFilter::ImportGraphic( Graphic& rGraphic, const String& rPath, SvStream& rIStream, + USHORT nFormat, USHORT* pDeterminedFormat, sal_uInt32 nImportFlags ) +{ + return ImportGraphic( rGraphic, rPath, rIStream, nFormat, pDeterminedFormat, nImportFlags, NULL ); +} + +//------------------------------------------------------------------------- + +USHORT GraphicFilter::ImportGraphic( Graphic& rGraphic, const String& rPath, SvStream& rIStream, + USHORT nFormat, USHORT* pDeterminedFormat, sal_uInt32 nImportFlags, + com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData ) +{ + String aFilterName; + ULONG nStmBegin; + USHORT nStatus; + GraphicReader* pContext = rGraphic.GetContext(); + GfxLinkType eLinkType = GFX_LINK_TYPE_NONE; + BOOL bDummyContext = ( pContext == (GraphicReader*) 1 ); + const BOOL bLinkSet = rGraphic.IsLink(); + FilterConfigItem* pFilterConfigItem = NULL; + + Size aPreviewSizeHint( 0, 0 ); + sal_Bool bAllowPartialStreamRead = sal_False; + sal_Bool bCreateNativeLink = sal_True; + + ResetLastError(); + + if ( pFilterData ) + { + sal_Int32 i; + for ( i = 0; i < pFilterData->getLength(); i++ ) + { + if ( (*pFilterData)[ i ].Name.equalsAscii( "PreviewSizeHint" ) ) + { + awt::Size aSize; + if ( (*pFilterData)[ i ].Value >>= aSize ) + { + aPreviewSizeHint = Size( aSize.Width, aSize.Height ); + if ( aSize.Width || aSize.Height ) + nImportFlags |= GRFILTER_I_FLAGS_FOR_PREVIEW; + else + nImportFlags &=~GRFILTER_I_FLAGS_FOR_PREVIEW; + } + } + else if ( (*pFilterData)[ i ].Name.equalsAscii( "AllowPartialStreamRead" ) ) + { + (*pFilterData)[ i ].Value >>= bAllowPartialStreamRead; + if ( bAllowPartialStreamRead ) + nImportFlags |= GRFILTER_I_FLAGS_ALLOW_PARTIAL_STREAMREAD; + else + nImportFlags &=~GRFILTER_I_FLAGS_ALLOW_PARTIAL_STREAMREAD; + } + else if ( (*pFilterData)[ i ].Name.equalsAscii( "CreateNativeLink" ) ) + { + (*pFilterData)[ i ].Value >>= bCreateNativeLink; + } + } + } + + if( !pContext || bDummyContext ) + { + if( bDummyContext ) + { + rGraphic.SetContext( NULL ); + nStmBegin = 0; + } + else + nStmBegin = rIStream.Tell(); + + bAbort = FALSE; + nStatus = ImpTestOrFindFormat( rPath, rIStream, nFormat ); + // Falls Pending, geben wir GRFILTER_OK zurueck, + // um mehr Bytes anzufordern + if( rIStream.GetError() == ERRCODE_IO_PENDING ) + { + rGraphic.SetContext( (GraphicReader*) 1 ); + rIStream.ResetError(); + rIStream.Seek( nStmBegin ); + return (USHORT) ImplSetError( GRFILTER_OK ); + } + + rIStream.Seek( nStmBegin ); + + if( ( nStatus != GRFILTER_OK ) || rIStream.GetError() ) + return (USHORT) ImplSetError( ( nStatus != GRFILTER_OK ) ? nStatus : GRFILTER_OPENERROR, &rIStream ); + + if( pDeterminedFormat ) + *pDeterminedFormat = nFormat; + + aFilterName = pConfig->GetImportFilterName( nFormat ); + } + else + { + if( pContext && !bDummyContext ) + aFilterName = pContext->GetUpperFilterName(); + + nStmBegin = 0; + nStatus = GRFILTER_OK; + } + + // read graphic + if ( pConfig->IsImportInternalFilter( nFormat ) ) + { + if( aFilterName.EqualsIgnoreCaseAscii( IMP_GIF ) ) + { + if( rGraphic.GetContext() == (GraphicReader*) 1 ) + rGraphic.SetContext( NULL ); + + if( !ImportGIF( rIStream, rGraphic ) ) + nStatus = GRFILTER_FILTERERROR; + else + eLinkType = GFX_LINK_TYPE_NATIVE_GIF; + } + else if( aFilterName.EqualsIgnoreCaseAscii( IMP_PNG ) ) + { + if ( rGraphic.GetContext() == (GraphicReader*) 1 ) + rGraphic.SetContext( NULL ); + + vcl::PNGReader aPNGReader( rIStream ); + + // ignore animation for previews and set preview size + if( aPreviewSizeHint.Width() || aPreviewSizeHint.Height() ) + { + // position the stream at the end of the image if requested + if( !bAllowPartialStreamRead ) + aPNGReader.GetChunks(); + } + else + { + // check if this PNG contains a GIF chunk! + const std::vector< vcl::PNGReader::ChunkData >& rChunkData = aPNGReader.GetChunks(); + std::vector< vcl::PNGReader::ChunkData >::const_iterator aIter( rChunkData.begin() ); + std::vector< vcl::PNGReader::ChunkData >::const_iterator aEnd ( rChunkData.end() ); + while( aIter != aEnd ) + { + // Microsoft Office is storing Animated GIFs in following chunk + if ( aIter->nType == PMGCHUNG_msOG ) + { + sal_uInt32 nChunkSize = aIter->aData.size(); + if ( nChunkSize > 11 ) + { + const std::vector< sal_uInt8 >& rData = aIter->aData; + SvMemoryStream aIStrm( (void*)&rData[ 11 ], nChunkSize - 11, STREAM_READ ); + ImportGIF( aIStrm, rGraphic ); + eLinkType = GFX_LINK_TYPE_NATIVE_PNG; + break; + } + } + aIter++; + } + } + + if ( eLinkType == GFX_LINK_TYPE_NONE ) + { + BitmapEx aBmpEx( aPNGReader.Read( aPreviewSizeHint ) ); + if ( aBmpEx.IsEmpty() ) + nStatus = GRFILTER_FILTERERROR; + else + { + rGraphic = aBmpEx; + eLinkType = GFX_LINK_TYPE_NATIVE_PNG; + } + } + } + else if( aFilterName.EqualsIgnoreCaseAscii( IMP_JPEG ) ) + { + if( rGraphic.GetContext() == (GraphicReader*) 1 ) + rGraphic.SetContext( NULL ); + + // set LOGSIZE flag always, if not explicitly disabled + // (see #90508 and #106763) + if( 0 == ( nImportFlags & GRFILTER_I_FLAGS_DONT_SET_LOGSIZE_FOR_JPEG ) ) + nImportFlags |= GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG; + + if( !ImportJPEG( rIStream, rGraphic, NULL, nImportFlags ) ) + nStatus = GRFILTER_FILTERERROR; + else + eLinkType = GFX_LINK_TYPE_NATIVE_JPG; + } + else if( aFilterName.EqualsIgnoreCaseAscii( IMP_SVG ) ) + { + if( rGraphic.GetContext() == (GraphicReader*) 1 ) + rGraphic.SetContext( NULL ); + + vcl::SVGReader aSVGReader( rIStream ); + GDIMetaFile aSVGMtf; + + if( 0 == aSVGReader.Read( aSVGMtf ).GetActionCount() ) + nStatus = GRFILTER_FILTERERROR; + else + rGraphic = Graphic( aSVGMtf ); + + // Dont set any GfxLink here, since the MetaRenderGraphicAction + // inside the just read MetaFile contains excatly this native data; + // setting a Ç´fxLink would also affect other program parts, since + // GfxLinks are preferably written to the file format in general, + // which would be a bad idea in case of SVG files, since earlier + // implementations are not able to handle native SVG data in any + // case. (KA 01/19/2011) + } + else if( aFilterName.EqualsIgnoreCaseAscii( IMP_XBM ) ) + { + if( rGraphic.GetContext() == (GraphicReader*) 1 ) + rGraphic.SetContext( NULL ); + + if( !ImportXBM( rIStream, rGraphic ) ) + nStatus = GRFILTER_FILTERERROR; + } + else if( aFilterName.EqualsIgnoreCaseAscii( IMP_XPM ) ) + { + if( rGraphic.GetContext() == (GraphicReader*) 1 ) + rGraphic.SetContext( NULL ); + + if( !ImportXPM( rIStream, rGraphic ) ) + nStatus = GRFILTER_FILTERERROR; + } + else if( aFilterName.EqualsIgnoreCaseAscii( IMP_BMP ) || + aFilterName.EqualsIgnoreCaseAscii( IMP_SVMETAFILE ) ) + { + // SV interne Importfilter fuer Bitmaps und MetaFiles + rIStream >> rGraphic; + if( rIStream.GetError() ) + nStatus = GRFILTER_FORMATERROR; + } + else if( aFilterName.EqualsIgnoreCaseAscii( IMP_WMF ) || + aFilterName.EqualsIgnoreCaseAscii( IMP_EMF ) ) + { + GDIMetaFile aMtf; + if( !ConvertWMFToGDIMetaFile( rIStream, aMtf, NULL ) ) + nStatus = GRFILTER_FORMATERROR; + else + { + rGraphic = aMtf; + eLinkType = GFX_LINK_TYPE_NATIVE_WMF; + } + } + else if( aFilterName.EqualsIgnoreCaseAscii( IMP_SVSGF ) + || aFilterName.EqualsIgnoreCaseAscii( IMP_SVSGV ) ) + { + USHORT nVersion; + unsigned char nTyp = CheckSgfTyp( rIStream, nVersion ); + + switch( nTyp ) + { + case SGF_BITIMAGE: + { + SvMemoryStream aTempStream; + if( aTempStream.GetError() ) + return GRFILTER_OPENERROR; + + if( !SgfBMapFilter( rIStream, aTempStream ) ) + nStatus = GRFILTER_FILTERERROR; + else + { + aTempStream.Seek( 0L ); + aTempStream >> rGraphic; + + if( aTempStream.GetError() ) + nStatus = GRFILTER_FILTERERROR; + } + } + break; + + case SGF_SIMPVECT: + { + GDIMetaFile aMtf; + if( !SgfVectFilter( rIStream, aMtf ) ) + nStatus = GRFILTER_FILTERERROR; + else + rGraphic = Graphic( aMtf ); + } + break; + + case SGF_STARDRAW: + { + if( nVersion != SGV_VERSION ) + nStatus = GRFILTER_VERSIONERROR; + else + { + GDIMetaFile aMtf; + if( !SgfSDrwFilter( rIStream, aMtf, + INetURLObject(aFilterPath) ) ) + { + nStatus = GRFILTER_FILTERERROR; + } + else + rGraphic = Graphic( aMtf ); + } + } + break; + + default: + { + nStatus = GRFILTER_FORMATERROR; + } + break; + } + } + else + nStatus = GRFILTER_FILTERERROR; + } + else + { + ImpFilterLibCacheEntry* pFilter = NULL; + + // find first filter in filter pathes + xub_StrLen i, nTokenCount = aFilterPath.GetTokenCount( ';' ); + ImpFilterLibCache &rCache = Cache::get(); + for( i = 0; ( i < nTokenCount ) && ( pFilter == NULL ); i++ ) + pFilter = rCache.GetFilter( aFilterPath.GetToken(i), aFilterName ); + if( !pFilter ) + nStatus = GRFILTER_FILTERERROR; + else + { + PFilterCall pFunc = pFilter->GetImportFunction(); + + if( !pFunc ) + nStatus = GRFILTER_FILTERERROR; + else + { + String aShortName; + if( nFormat != GRFILTER_FORMAT_DONTKNOW ) + { + aShortName = GetImportFormatShortName( nFormat ).ToUpperAscii(); + if ( ( pFilterConfigItem == NULL ) && aShortName.EqualsAscii( "PCD" ) ) + { + String aFilterConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/Graphic/Import/PCD" ) ); + pFilterConfigItem = new FilterConfigItem( aFilterConfigPath ); + } + } + if( !(*pFunc)( rIStream, rGraphic, pFilterConfigItem, sal_False ) ) + nStatus = GRFILTER_FORMATERROR; + else + { + // try to set link type if format matches + if( nFormat != GRFILTER_FORMAT_DONTKNOW ) + { + if( aShortName.CompareToAscii( TIF_SHORTNAME ) == COMPARE_EQUAL ) + eLinkType = GFX_LINK_TYPE_NATIVE_TIF; + else if( aShortName.CompareToAscii( MET_SHORTNAME ) == COMPARE_EQUAL ) + eLinkType = GFX_LINK_TYPE_NATIVE_MET; + else if( aShortName.CompareToAscii( PCT_SHORTNAME ) == COMPARE_EQUAL ) + eLinkType = GFX_LINK_TYPE_NATIVE_PCT; + } + } + } + } + } + + if( nStatus == GRFILTER_OK && bCreateNativeLink && ( eLinkType != GFX_LINK_TYPE_NONE ) && !rGraphic.GetContext() && !bLinkSet ) + { + const ULONG nStmEnd = rIStream.Tell(); + const ULONG nBufSize = nStmEnd - nStmBegin; + + if( nBufSize ) + { + BYTE* pBuf=0; + try + { + pBuf = new BYTE[ nBufSize ]; + } + catch (std::bad_alloc) + { + nStatus = GRFILTER_TOOBIG; + } + + if( nStatus == GRFILTER_OK ) + { + rIStream.Seek( nStmBegin ); + rIStream.Read( pBuf, nBufSize ); + rGraphic.SetLink( GfxLink( pBuf, nBufSize, eLinkType, TRUE ) ); + } + } + } + + // Set error code or try to set native buffer + if( nStatus != GRFILTER_OK ) + { + if( bAbort ) + nStatus = GRFILTER_ABORT; + + ImplSetError( nStatus, &rIStream ); + rIStream.Seek( nStmBegin ); + rGraphic.Clear(); + } + + delete pFilterConfigItem; + return nStatus; +} + + +// ------------------------------------------------------------------------ + +USHORT GraphicFilter::ExportGraphic( const Graphic& rGraphic, const INetURLObject& rPath, + sal_uInt16 nFormat, const uno::Sequence< beans::PropertyValue >* pFilterData ) +{ + sal_uInt16 nRetValue = GRFILTER_FORMATERROR; + DBG_ASSERT( rPath.GetProtocol() != INET_PROT_NOT_VALID, "GraphicFilter::ExportGraphic() : ProtType == INET_PROT_NOT_VALID" ); + BOOL bAlreadyExists = ImplDirEntryHelper::Exists( rPath ); + + String aMainUrl( rPath.GetMainURL( INetURLObject::NO_DECODE ) ); + SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aMainUrl, STREAM_WRITE | STREAM_TRUNC ); + if ( pStream ) + { + nRetValue = ExportGraphic( rGraphic, aMainUrl, *pStream, nFormat, pFilterData ); + delete pStream; + + if( ( GRFILTER_OK != nRetValue ) && !bAlreadyExists ) + ImplDirEntryHelper::Kill( aMainUrl ); + } + return nRetValue; +} + +// ------------------------------------------------------------------------ + +USHORT GraphicFilter::ExportGraphic( const Graphic& rGraphic, const String& rPath, + SvStream& rOStm, sal_uInt16 nFormat, const uno::Sequence< beans::PropertyValue >* pFilterData ) +{ + USHORT nFormatCount = GetExportFormatCount(); + + ResetLastError(); + nExpGraphHint = 0; + + if( nFormat == GRFILTER_FORMAT_DONTKNOW ) + { + INetURLObject aURL( rPath ); + String aExt( aURL.GetFileExtension().toAsciiUpperCase() ); + + + for( USHORT i = 0; i < nFormatCount; i++ ) + { + if ( pConfig->GetExportFormatExtension( i ).EqualsIgnoreCaseAscii( aExt ) ) + { + nFormat=i; + break; + } + } + } + if( nFormat >= nFormatCount ) + return (USHORT) ImplSetError( GRFILTER_FORMATERROR ); + + FilterConfigItem aConfigItem( (uno::Sequence< beans::PropertyValue >*)pFilterData ); + String aFilterName( pConfig->GetExportFilterName( nFormat ) ); + + bAbort = FALSE; + USHORT nStatus = GRFILTER_OK; + GraphicType eType; + Graphic aGraphic( rGraphic ); + + aGraphic = ImpGetScaledGraphic( rGraphic, aConfigItem ); + eType = aGraphic.GetType(); + + if( pConfig->IsExportPixelFormat( nFormat ) ) + { + if( eType != GRAPHIC_BITMAP ) + { + Size aSizePixel; + ULONG nColorCount,nBitsPerPixel,nNeededMem,nMaxMem; + VirtualDevice aVirDev; + + // Maximalen Speicherbedarf fuer das Bildes holen: +// if( GetOptionsConfig() ) +// nMaxMem = (UINT32)GetOptionsConfig()->ReadKey( "VEC-TO-PIX-MAX-KB", "1024" ).ToInt32(); +// else + nMaxMem = 1024; + + nMaxMem *= 1024; // In Bytes + + // Berechnen, wie gross das Bild normalerweise werden wuerde: + aSizePixel=aVirDev.LogicToPixel(aGraphic.GetPrefSize(),aGraphic.GetPrefMapMode()); + + // Berechnen, wieviel Speicher das Bild benoetigen wuerde: + nColorCount=aVirDev.GetColorCount(); + if (nColorCount<=2) nBitsPerPixel=1; + else if (nColorCount<=4) nBitsPerPixel=2; + else if (nColorCount<=16) nBitsPerPixel=4; + else if (nColorCount<=256) nBitsPerPixel=8; + else if (nColorCount<=65536) nBitsPerPixel=16; + else nBitsPerPixel=24; + nNeededMem=((ULONG)aSizePixel.Width()*(ULONG)aSizePixel.Height()*nBitsPerPixel+7)/8; + + // ggf. Groesse des Bildes einschraenken: + if (nMaxMemIsExportInternalFilter( nFormat ) ) + { + if( aFilterName.EqualsIgnoreCaseAscii( EXP_BMP ) ) + { + Bitmap aBmp( aGraphic.GetBitmap() ); + sal_Int32 nColorRes = aConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Colors" ) ), 0 ); + if ( nColorRes && ( nColorRes <= (USHORT)BMP_CONVERSION_24BIT) ) + { + if( !aBmp.Convert( (BmpConversion) nColorRes ) ) + aBmp = aGraphic.GetBitmap(); + } + ResMgr* pResMgr = CREATERESMGR( svt ); + sal_Bool bRleCoding = aConfigItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "RLE_Coding" ) ), sal_True ); + // Wollen wir RLE-Kodiert speichern? + aBmp.Write( rOStm, bRleCoding ); + delete pResMgr; + + if( rOStm.GetError() ) + nStatus = GRFILTER_IOERROR; + } + else if( aFilterName.EqualsIgnoreCaseAscii( EXP_SVMETAFILE ) ) + { + sal_Int32 nVersion = aConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ), 0 ) ; + if ( nVersion ) + rOStm.SetVersion( nVersion ); + GDIMetaFile aMTF; + + if ( eType != GRAPHIC_BITMAP ) + aMTF = aGraphic.GetGDIMetaFile(); + else + { + VirtualDevice aVirDev; + + aMTF.Record( &aVirDev ); + aGraphic.Draw( &aVirDev, Point(), aGraphic.GetPrefSize() ); + aMTF.Stop(); + aMTF.SetPrefSize( aGraphic.GetPrefSize() ); + aMTF.SetPrefMapMode( aGraphic.GetPrefMapMode() ); + } + aMTF.Write( rOStm, GDIMETAFILE_WRITE_REPLACEMENT_RENDERGRAPHIC ); + if( rOStm.GetError() ) + nStatus = GRFILTER_IOERROR; + } + else if ( aFilterName.EqualsIgnoreCaseAscii( EXP_WMF ) ) + { + if( eType == GRAPHIC_GDIMETAFILE ) + { + if ( !ConvertGDIMetaFileToWMF( aGraphic.GetGDIMetaFile(), rOStm, &aConfigItem ) ) + nStatus = GRFILTER_FORMATERROR; + } + else + { + Bitmap aBmp( aGraphic.GetBitmap() ); + GDIMetaFile aMTF; + VirtualDevice aVirDev; + + aMTF.Record( &aVirDev ); + aVirDev.DrawBitmap( Point(), aBmp ); + aMTF.Stop(); + aMTF.SetPrefSize( aBmp.GetSizePixel() ); + + if( !ConvertGDIMetaFileToWMF( aMTF, rOStm, &aConfigItem ) ) + nStatus = GRFILTER_FORMATERROR; + } + if( rOStm.GetError() ) + nStatus = GRFILTER_IOERROR; + } + else if ( aFilterName.EqualsIgnoreCaseAscii( EXP_EMF ) ) + { + if( eType == GRAPHIC_GDIMETAFILE ) + { + if ( !ConvertGDIMetaFileToEMF( aGraphic.GetGDIMetaFile(), rOStm, &aConfigItem ) ) + nStatus = GRFILTER_FORMATERROR; + } + else + { + Bitmap aBmp( aGraphic.GetBitmap() ); + GDIMetaFile aMTF; + VirtualDevice aVirDev; + + aMTF.Record( &aVirDev ); + aVirDev.DrawBitmap( Point(), aBmp ); + aMTF.Stop(); + aMTF.SetPrefSize( aBmp.GetSizePixel() ); + + if( !ConvertGDIMetaFileToEMF( aMTF, rOStm, &aConfigItem ) ) + nStatus = GRFILTER_FORMATERROR; + } + if( rOStm.GetError() ) + nStatus = GRFILTER_IOERROR; + } + else if( aFilterName.EqualsIgnoreCaseAscii( EXP_JPEG ) ) + { + bool bExportedGrayJPEG = false; + if( !ExportJPEG( rOStm, aGraphic, pFilterData, &bExportedGrayJPEG ) ) + nStatus = GRFILTER_FORMATERROR; + nExpGraphHint = bExportedGrayJPEG ? GRFILTER_OUTHINT_GREY : 0; + + if( rOStm.GetError() ) + nStatus = GRFILTER_IOERROR; + } + else if ( aFilterName.EqualsIgnoreCaseAscii( EXP_PNG ) ) + { + vcl::PNGWriter aPNGWriter( aGraphic.GetBitmapEx(), pFilterData ); + if ( pFilterData ) + { + sal_Int32 k, j, i = 0; + for ( i = 0; i < pFilterData->getLength(); i++ ) + { + if ( (*pFilterData)[ i ].Name.equalsAscii( "AdditionalChunks" ) ) + { + com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > aAdditionalChunkSequence; + if ( (*pFilterData)[ i ].Value >>= aAdditionalChunkSequence ) + { + for ( j = 0; j < aAdditionalChunkSequence.getLength(); j++ ) + { + if ( aAdditionalChunkSequence[ j ].Name.getLength() == 4 ) + { + sal_uInt32 nChunkType = 0; + for ( k = 0; k < 4; k++ ) + { + nChunkType <<= 8; + nChunkType |= (sal_uInt8)aAdditionalChunkSequence[ j ].Name[ k ]; + } + com::sun::star::uno::Sequence< sal_Int8 > aByteSeq; + if ( aAdditionalChunkSequence[ j ].Value >>= aByteSeq ) + { + std::vector< vcl::PNGWriter::ChunkData >& rChunkData = aPNGWriter.GetChunks(); + if ( rChunkData.size() ) + { + sal_uInt32 nChunkLen = aByteSeq.getLength(); + + vcl::PNGWriter::ChunkData aChunkData; + aChunkData.nType = nChunkType; + if ( nChunkLen ) + { + aChunkData.aData.resize( nChunkLen ); + rtl_copyMemory( &aChunkData.aData[ 0 ], aByteSeq.getConstArray(), nChunkLen ); + } + std::vector< vcl::PNGWriter::ChunkData >::iterator aIter = rChunkData.end() - 1; + rChunkData.insert( aIter, aChunkData ); + } + } + } + } + } + } + } + } + aPNGWriter.Write( rOStm ); + + if( rOStm.GetError() ) + nStatus = GRFILTER_IOERROR; + } + else if( aFilterName.EqualsIgnoreCaseAscii( EXP_SVG ) ) + { + bool bDone = false; + + // do we have a native SVG RenderGraphic, whose data can be written directly? + if( ( GRAPHIC_GDIMETAFILE == eType ) && aGraphic.IsRenderGraphic() ) + { + const ::vcl::RenderGraphic aRenderGraphic( aGraphic.GetRenderGraphic() ); + + if( aRenderGraphic.GetGraphicDataLength() && + aRenderGraphic.GetGraphicDataMimeType().equalsIgnoreAsciiCase( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/svg+xml" ) ) ) ) + { + rOStm.Write( aRenderGraphic.GetGraphicData().get(), + aRenderGraphic.GetGraphicDataLength() ); + + if( rOStm.GetError() ) + { + nStatus = GRFILTER_IOERROR; + } + } + } + + if( !bDone ) + { + // do the normal GDIMetaFile export instead + try + { + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() ); + + if( xMgr.is() ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > xSaxWriter( xMgr->createInstance( + ::rtl::OUString::createFromAscii( "com.sun.star.xml.sax.Writer" ) ), ::com::sun::star::uno::UNO_QUERY ); + + ::com::sun::star::uno::Reference< ::com::sun::star::svg::XSVGWriter > xSVGWriter( xMgr->createInstance( + ::rtl::OUString::createFromAscii( "com.sun.star.svg.SVGWriter" ) ), ::com::sun::star::uno::UNO_QUERY ); + + if( xSaxWriter.is() && xSVGWriter.is() ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::io::XActiveDataSource > xActiveDataSource( + xSaxWriter, ::com::sun::star::uno::UNO_QUERY ); + + if( xActiveDataSource.is() ) + { + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xStmIf( + static_cast< ::cppu::OWeakObject* >( new ImpFilterOutputStream( rOStm ) ) ); + + SvMemoryStream aMemStm( 65535, 65535 ); + + aMemStm.SetCompressMode( COMPRESSMODE_FULL ); + ( (GDIMetaFile&) aGraphic.GetGDIMetaFile() ).Write( aMemStm ); + + xActiveDataSource->setOutputStream( ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >( + xStmIf, ::com::sun::star::uno::UNO_QUERY ) ); + ::com::sun::star::uno::Sequence< sal_Int8 > aMtfSeq( (sal_Int8*) aMemStm.GetData(), aMemStm.Tell() ); + xSVGWriter->write( xSaxWriter, aMtfSeq ); + } + } + } + } + catch( ::com::sun::star::uno::Exception& ) + { + nStatus = GRFILTER_IOERROR; + } + } + } + else + nStatus = GRFILTER_FILTERERROR; + } + else + { + xub_StrLen i, nTokenCount = aFilterPath.GetTokenCount( ';' ); + for ( i = 0; i < nTokenCount; i++ ) + { + String aPhysicalName( ImpCreateFullFilterPath( aFilterPath.GetToken( i ), aFilterName ) ); + osl::Module aLibrary( aPhysicalName ); + + PFilterCall pFunc = (PFilterCall) aLibrary.getFunctionSymbol( UniString::CreateFromAscii( EXPORT_FUNCTION_NAME ) ); + // Dialog in DLL ausfuehren + if( pFunc ) + { + if ( !(*pFunc)( rOStm, aGraphic, &aConfigItem, sal_False ) ) + nStatus = GRFILTER_FORMATERROR; + break; + } + else + nStatus = GRFILTER_FILTERERROR; + } + } + } + if( nStatus != GRFILTER_OK ) + { + if( bAbort ) + nStatus = GRFILTER_ABORT; + + ImplSetError( nStatus, &rOStm ); + } + return nStatus; +} + +// ------------------------------------------------------------------------ + +BOOL GraphicFilter::Setup( USHORT ) +{ + return FALSE; +} + +/* ------------------------------------------------------------------------ + No Import filter has a dialog, so + the following two methods are obsolete */ + +BOOL GraphicFilter::HasImportDialog( USHORT ) +{ + return sal_True; +// return pConfig->IsImportDialog( nFormat ); +} + +// ------------------------------------------------------------------------ + +BOOL GraphicFilter::DoImportDialog( Window*, USHORT ) +{ + return sal_True; +} + +// ------------------------------------------------------------------------ + +BOOL GraphicFilter::HasExportDialog( USHORT nFormat ) +{ + return pConfig->IsExportDialog( nFormat ); +} + +// ------------------------------------------------------------------------ + +BOOL GraphicFilter::DoExportDialog( Window* pWindow, USHORT nFormat ) +{ + return DoExportDialog( pWindow, nFormat, FUNIT_MM ); +} + +BOOL GraphicFilter::DoExportDialog( Window*, USHORT nFormat, FieldUnit ) +{ + sal_Bool bRet = sal_False; + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > + xSMgr( ::comphelper::getProcessServiceFactory() ); + + uno::Reference< com::sun::star::uno::XInterface > xFilterOptionsDialog + ( xSMgr->createInstance( rtl::OUString::createFromAscii( "com.sun.star.svtools.SvFilterOptionsDialog" ) ), + com::sun::star::uno::UNO_QUERY ); + if ( xFilterOptionsDialog.is() ) + { + com::sun::star::uno::Reference< com::sun::star::ui::dialogs::XExecutableDialog > xExecutableDialog + ( xFilterOptionsDialog, ::com::sun::star::uno::UNO_QUERY ); + com::sun::star::uno::Reference< com::sun::star::beans::XPropertyAccess > xPropertyAccess + ( xFilterOptionsDialog, ::com::sun::star::uno::UNO_QUERY ); + if ( xExecutableDialog.is() && xPropertyAccess.is() ) + { + com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aMediaDescriptor( 1 ); + aMediaDescriptor[ 0 ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) ); + rtl::OUString aStr( pConfig->GetExportInternalFilterName( nFormat ) ); + aMediaDescriptor[ 0 ].Value <<= aStr; + xPropertyAccess->setPropertyValues( aMediaDescriptor ); + bRet = xExecutableDialog->execute() == com::sun::star::ui::dialogs::ExecutableDialogResults::OK; + } + } + return bRet; +} + +// ------------------------------------------------------------------------ + +const FilterErrorEx& GraphicFilter::GetLastError() const +{ + return *pErrorEx; +} + +// ------------------------------------------------------------------------ + +void GraphicFilter::ResetLastError() +{ + pErrorEx->nFilterError = pErrorEx->nStreamError = 0UL; +} + +// ------------------------------------------------------------------------ + +const Link GraphicFilter::GetFilterCallback() const +{ + const Link aLink( LINK( this, GraphicFilter, FilterCallback ) ); + return aLink; +} + +// ------------------------------------------------------------------------ + +IMPL_LINK( GraphicFilter, FilterCallback, ConvertData*, pData ) +{ + long nRet = 0L; + + if( pData ) + { + USHORT nFormat = GRFILTER_FORMAT_DONTKNOW; + ByteString aShortName; + switch( pData->mnFormat ) + { + case( CVT_BMP ): aShortName = BMP_SHORTNAME; break; + case( CVT_GIF ): aShortName = GIF_SHORTNAME; break; + case( CVT_JPG ): aShortName = JPG_SHORTNAME; break; + case( CVT_MET ): aShortName = MET_SHORTNAME; break; + case( CVT_PCT ): aShortName = PCT_SHORTNAME; break; + case( CVT_PNG ): aShortName = PNG_SHORTNAME; break; + case( CVT_SVM ): aShortName = SVM_SHORTNAME; break; + case( CVT_TIF ): aShortName = TIF_SHORTNAME; break; + case( CVT_WMF ): aShortName = WMF_SHORTNAME; break; + case( CVT_EMF ): aShortName = EMF_SHORTNAME; break; + case( CVT_SVG ): aShortName = SVG_SHORTNAME; break; + + default: + break; + } + if( GRAPHIC_NONE == pData->maGraphic.GetType() || pData->maGraphic.GetContext() ) // Import + { + // Import + nFormat = GetImportFormatNumberForShortName( String( aShortName.GetBuffer(), RTL_TEXTENCODING_UTF8 ) ); + nRet = ImportGraphic( pData->maGraphic, String(), pData->mrStm ) == 0; + } + else if( aShortName.Len() ) + { + // Export + nFormat = GetExportFormatNumberForShortName( String( aShortName.GetBuffer(), RTL_TEXTENCODING_UTF8 ) ); + nRet = ExportGraphic( pData->maGraphic, String(), pData->mrStm, nFormat ) == 0; + } + } + return nRet; +} + +// ------------------------------------------------------------------------ + +GraphicFilter* GraphicFilter::GetGraphicFilter() +{ + if( !pGraphicFilter ) + { + pGraphicFilter = new GraphicFilter; + pGraphicFilter->GetImportFormatCount(); + } + return pGraphicFilter; +} + +int GraphicFilter::LoadGraphic( const String &rPath, const String &rFilterName, + Graphic& rGraphic, GraphicFilter* pFilter, + USHORT* pDeterminedFormat ) +{ + if ( !pFilter ) + pFilter = GetGraphicFilter(); + + const USHORT nFilter = rFilterName.Len() && pFilter->GetImportFormatCount() + ? pFilter->GetImportFormatNumber( rFilterName ) + : GRFILTER_FORMAT_DONTKNOW; + + SvStream* pStream = NULL; + INetURLObject aURL( rPath ); + + if ( aURL.HasError() || INET_PROT_NOT_VALID == aURL.GetProtocol() ) + { + aURL.SetSmartProtocol( INET_PROT_FILE ); + aURL.SetSmartURL( rPath ); + } + else if ( INET_PROT_FILE != aURL.GetProtocol() ) + { + pStream = ::utl::UcbStreamHelper::CreateStream( rPath, STREAM_READ ); + } + + int nRes = GRFILTER_OK; + if ( !pStream ) + nRes = pFilter->ImportGraphic( rGraphic, aURL, nFilter, pDeterminedFormat ); + else + nRes = pFilter->ImportGraphic( rGraphic, rPath, *pStream, nFilter, pDeterminedFormat ); + +#ifdef DBG_UTIL + if( nRes ) + DBG_WARNING2( "GrafikFehler [%d] - [%s]", nRes, rPath.GetBuffer() ); +#endif + + return nRes; +} diff --git a/svtools/source/filter/filter2.cxx b/svtools/source/filter/filter2.cxx new file mode 100644 index 000000000000..15bdc5c5d080 --- /dev/null +++ b/svtools/source/filter/filter2.cxx @@ -0,0 +1,1354 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include "FilterConfigCache.hxx" +#include + +#define DATA_SIZE 640 + +BYTE* ImplSearchEntry( BYTE* , BYTE* , ULONG , ULONG ); + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +GraphicDescriptor::GraphicDescriptor( const INetURLObject& rPath ) : + pFileStm( ::utl::UcbStreamHelper::CreateStream( rPath.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ) ), + aPathExt( rPath.GetFileExtension().toAsciiLowerCase() ), + bOwnStream( TRUE ) +{ + ImpConstruct(); +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +GraphicDescriptor::GraphicDescriptor( SvStream& rInStream, const String* pPath) : + pFileStm ( &rInStream ), + bOwnStream ( FALSE ) +{ + ImpConstruct(); + + if ( pPath ) + { + INetURLObject aURL( *pPath ); + aPathExt = aURL.GetFileExtension().toAsciiLowerCase(); + } +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +GraphicDescriptor::~GraphicDescriptor() +{ + if ( bOwnStream ) + delete pFileStm; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::Detect( BOOL bExtendedInfo ) +{ + BOOL bRet = FALSE; + if ( pFileStm && !pFileStm->GetError() ) + { + SvStream& rStm = *pFileStm; + UINT16 nOldFormat = rStm.GetNumberFormatInt(); + + if ( ImpDetectGIF( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectJPG( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectBMP( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectPNG( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectTIF( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectPCX( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectDXF( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectMET( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectSGF( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectSGV( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectSVM( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectWMF( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectEMF( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectSVG( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectPCT( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectXBM( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectXPM( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectPBM( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectPGM( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectPPM( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectRAS( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectTGA( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectPSD( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectEPS( rStm, bExtendedInfo ) ) bRet = TRUE; + else if ( ImpDetectPCD( rStm, bExtendedInfo ) ) bRet = TRUE; + + rStm.SetNumberFormatInt( nOldFormat ); + } + return bRet; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +void GraphicDescriptor::ImpConstruct() +{ + nFormat = GFF_NOT; + nBitsPerPixel = 0; + nPlanes = 0; + bCompressed = FALSE; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectBMP( SvStream& rStm, BOOL bExtendedInfo ) +{ + UINT16 nTemp16; + BOOL bRet = FALSE; + sal_Int32 nStmPos = rStm.Tell(); + + rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); + rStm >> nTemp16; + + // OS/2-BitmapArray + if ( nTemp16 == 0x4142 ) + { + rStm.SeekRel( 0x0c ); + rStm >> nTemp16; + } + + // Bitmap + if ( nTemp16 == 0x4d42 ) + { + nFormat = GFF_BMP; + bRet = TRUE; + + if ( bExtendedInfo ) + { + UINT32 nTemp32; + UINT32 nCompression; + + // bis zur ersten Information + rStm.SeekRel( 0x10 ); + + // PixelBreite auslesen + rStm >> nTemp32; + aPixSize.Width() = nTemp32; + + // PixelHoehe auslesen + rStm >> nTemp32; + aPixSize.Height() = nTemp32; + + // Planes auslesen + rStm >> nTemp16; + nPlanes = nTemp16; + + // BitCount auslesen + rStm >> nTemp16; + nBitsPerPixel = nTemp16; + + // Compression auslesen + rStm >> nTemp32; + bCompressed = ( ( nCompression = nTemp32 ) > 0 ); + + // logische Breite + rStm.SeekRel( 4 ); + rStm >> nTemp32; + if ( nTemp32 ) + aLogSize.Width() = ( aPixSize.Width() * 100000 ) / nTemp32; + + // logische Hoehe + rStm >> nTemp32; + if ( nTemp32 ) + aLogSize.Height() = ( aPixSize.Height() * 100000 ) / nTemp32; + + // Wir wollen noch etwas feiner differenzieren und + // auf sinnvolle Werte ueberpruefen ( Bug-Id #29001 ) + if ( ( nBitsPerPixel > 24 ) || ( nCompression > 3 ) ) + { + nFormat = GFF_NOT; + bRet = FALSE; + } + } + } + rStm.Seek( nStmPos ); + return bRet; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectGIF( SvStream& rStm, BOOL bExtendedInfo ) +{ + UINT32 n32; + UINT16 n16; + BOOL bRet = FALSE; + BYTE cByte; + + sal_Int32 nStmPos = rStm.Tell(); + rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); + rStm >> n32; + + if ( n32 == 0x38464947 ) + { + rStm >> n16; + if ( ( n16 == 0x6137 ) || ( n16 == 0x6139 ) ) + { + nFormat = GFF_GIF; + bRet = TRUE; + + if ( bExtendedInfo ) + { + UINT16 nTemp16; + + // PixelBreite auslesen + rStm >> nTemp16; + aPixSize.Width() = nTemp16; + + // PixelHoehe auslesen + rStm >> nTemp16; + aPixSize.Height() = nTemp16; + + // Bits/Pixel auslesen + rStm >> cByte; + nBitsPerPixel = ( ( cByte & 112 ) >> 4 ) + 1; + } + } + } + rStm.Seek( nStmPos ); + return bRet; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +// returns the next jpeg marker, a return value of 0 represents an error +sal_uInt8 ImpDetectJPG_GetNextMarker( SvStream& rStm ) +{ + sal_uInt8 nByte; + do + { + do + { + rStm >> nByte; + if ( rStm.IsEof() || rStm.GetError() ) // as 0 is not allowed as marker, + return 0; // we can use it as errorcode + } + while ( nByte != 0xff ); + do + { + rStm >> nByte; + if ( rStm.IsEof() || rStm.GetError() ) + return 0; + } + while( nByte == 0xff ); + } + while( nByte == 0 ); // 0xff00 represents 0xff and not a marker, + // the marker detection has to be restartet. + return nByte; +} + +BOOL GraphicDescriptor::ImpDetectJPG( SvStream& rStm, BOOL bExtendedInfo ) +{ + UINT32 nTemp32; + BOOL bRet = FALSE; + + sal_Int32 nStmPos = rStm.Tell(); + + rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); + rStm >> nTemp32; + + // compare upper 24 bits + if( 0xffd8ff00 == ( nTemp32 & 0xffffff00 ) ) + { + nFormat = GFF_JPG; + bRet = TRUE; + + if ( bExtendedInfo ) + { + rStm.SeekRel( -2 ); + + sal_uInt32 nError( rStm.GetError() ); + + sal_Bool bScanFailure = sal_False; + sal_Bool bScanFinished = sal_False; + + while( !bScanFailure && !bScanFinished && !rStm.IsEof() && !rStm.GetError() ) + { + sal_uInt8 nMarker = ImpDetectJPG_GetNextMarker( rStm ); + switch( nMarker ) + { + // fixed size marker, not having a two byte length parameter + case 0xd0 : // RST0 + case 0xd1 : + case 0xd2 : + case 0xd3 : + case 0xd4 : + case 0xd5 : + case 0xd6 : + case 0xd7 : // RST7 + case 0x01 : // TEM + break; + + case 0xd8 : // SOI (has already been checked, there should not be a second one) + case 0x00 : // marker is invalid, we should stop now + bScanFailure = sal_True; + break; + + case 0xd9 : // EOI + bScanFinished = sal_True; + break; + + // per default we assume marker segments conaining a length parameter + default : + { + sal_uInt16 nLength; + rStm >> nLength; + + if ( nLength < 2 ) + bScanFailure = sal_True; + else + { + sal_uInt32 nNextMarkerPos = rStm.Tell() + nLength - 2; + switch( nMarker ) + { + case 0xe0 : // APP0 Marker + { + if ( nLength == 16 ) + { + sal_Int32 nIdentifier; + rStm >> nIdentifier; + if ( nIdentifier == 0x4a464946 ) // JFIF Identifier + { + sal_uInt8 nStringTerminator; + sal_uInt8 nMajorRevision; + sal_uInt8 nMinorRevision; + sal_uInt8 nUnits; + sal_uInt16 nHorizontalResolution; + sal_uInt16 nVerticalResolution; + sal_uInt8 nHorzThumbnailPixelCount; + sal_uInt8 nVertThumbnailPixelCount; + + rStm >> nStringTerminator + >> nMajorRevision + >> nMinorRevision + >> nUnits + >> nHorizontalResolution + >> nVerticalResolution + >> nHorzThumbnailPixelCount + >> nVertThumbnailPixelCount; + + // setting the logical size + if ( nUnits && nHorizontalResolution && nVerticalResolution ) + { + MapMode aMap; + aMap.SetMapUnit( nUnits == 1 ? MAP_INCH : MAP_CM ); + aMap.SetScaleX( Fraction( 1, nHorizontalResolution ) ); + aMap.SetScaleY( Fraction( 1, nVerticalResolution ) ); + aLogSize = OutputDevice::LogicToLogic( aPixSize, aMap, MapMode( MAP_100TH_MM ) ); + } + } + } + } + break; + + // Start of Frame Markers + case 0xc0 : // SOF0 + case 0xc1 : // SOF1 + case 0xc2 : // SOF2 + case 0xc3 : // SOF3 + case 0xc5 : // SOF5 + case 0xc6 : // SOF6 + case 0xc7 : // SOF7 + case 0xc9 : // SOF9 + case 0xca : // SOF10 + case 0xcb : // SOF11 + case 0xcd : // SOF13 + case 0xce : // SOF14 + case 0xcf : // SOF15 + { + sal_uInt8 nSamplePrecision; + sal_uInt16 nNumberOfLines; + sal_uInt16 nSamplesPerLine; + sal_uInt8 nNumberOfImageComponents; + sal_uInt8 nComponentsIdentifier; + sal_uInt8 nHorizontalSamplingFactor; + sal_uInt8 nVerticalSamplingFactor; + sal_uInt8 nQuantizationTableDestinationSelector; + rStm >> nSamplePrecision + >> nNumberOfLines + >> nSamplesPerLine + >> nNumberOfImageComponents + >> nComponentsIdentifier + >> nHorizontalSamplingFactor + >> nQuantizationTableDestinationSelector; + nVerticalSamplingFactor = nHorizontalSamplingFactor & 0xf; + nHorizontalSamplingFactor >>= 4; + + aPixSize.Height() = nNumberOfLines; + aPixSize.Width() = nSamplesPerLine; + nBitsPerPixel = ( nNumberOfImageComponents == 3 ? 24 : nNumberOfImageComponents == 1 ? 8 : 0 ); + nPlanes = 1; + + bScanFinished = sal_True; + } + break; + } + rStm.Seek( nNextMarkerPos ); + } + } + break; + } + } + rStm.SetError( nError ); + } + } + rStm.Seek( nStmPos ); + return bRet; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectPCD( SvStream& rStm, BOOL ) +{ + BOOL bRet = FALSE; + + sal_Int32 nStmPos = rStm.Tell(); + rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); + + UINT32 nTemp32; + UINT16 nTemp16; + BYTE cByte; + + rStm.SeekRel( 2048 ); + rStm >> nTemp32; + rStm >> nTemp16; + rStm >> cByte; + + if ( ( nTemp32 == 0x5f444350 ) && + ( nTemp16 == 0x5049 ) && + ( cByte == 0x49 ) ) + { + nFormat = GFF_PCD; + bRet = TRUE; + } + rStm.Seek( nStmPos ); + return bRet; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectPCX( SvStream& rStm, BOOL bExtendedInfo ) +{ + // ! Because 0x0a can be interpreted as LF too ... + // we cant be shure that this special sign represent a PCX file only. + // Every Ascii file is possible here :-( + // We must detect the whole header. + bExtendedInfo = TRUE; + + BOOL bRet = FALSE; + BYTE cByte; + + sal_Int32 nStmPos = rStm.Tell(); + rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); + rStm >> cByte; + + if ( cByte == 0x0a ) + { + nFormat = GFF_PCX; + bRet = TRUE; + + if ( bExtendedInfo ) + { + UINT16 nTemp16; + USHORT nXmin; + USHORT nXmax; + USHORT nYmin; + USHORT nYmax; + USHORT nDPIx; + USHORT nDPIy; + + + rStm.SeekRel( 1 ); + + // Kompression lesen + rStm >> cByte; + bCompressed = ( cByte > 0 ); + + bRet = (cByte==0 || cByte ==1); + + // Bits/Pixel lesen + rStm >> cByte; + nBitsPerPixel = cByte; + + // Bildabmessungen + rStm >> nTemp16; + nXmin = nTemp16; + rStm >> nTemp16; + nYmin = nTemp16; + rStm >> nTemp16; + nXmax = nTemp16; + rStm >> nTemp16; + nYmax = nTemp16; + + aPixSize.Width() = nXmax - nXmin + 1; + aPixSize.Height() = nYmax - nYmin + 1; + + // Aufloesung + rStm >> nTemp16; + nDPIx = nTemp16; + rStm >> nTemp16; + nDPIy = nTemp16; + + // logische Groesse setzen + MapMode aMap( MAP_INCH, Point(), + Fraction( 1, nDPIx ), Fraction( 1, nDPIy ) ); + aLogSize = OutputDevice::LogicToLogic( aPixSize, aMap, + MapMode( MAP_100TH_MM ) ); + + + // Anzahl Farbebenen + rStm.SeekRel( 49 ); + rStm >> cByte; + nPlanes = cByte; + + bRet = (nPlanes<=4); + } + } + + rStm.Seek( nStmPos ); + return bRet; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectPNG( SvStream& rStm, BOOL bExtendedInfo ) +{ + UINT32 nTemp32; + BOOL bRet = FALSE; + + sal_Int32 nStmPos = rStm.Tell(); + rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); + rStm >> nTemp32; + + if ( nTemp32 == 0x89504e47 ) + { + rStm >> nTemp32; + if ( nTemp32 == 0x0d0a1a0a ) + { + nFormat = GFF_PNG; + bRet = TRUE; + + if ( bExtendedInfo ) + { + BYTE cByte; + + // IHDR-Chunk + rStm.SeekRel( 8 ); + + // Breite einlesen + rStm >> nTemp32; + aPixSize.Width() = nTemp32; + + // Hoehe einlesen + rStm >> nTemp32; + aPixSize.Height() = nTemp32; + + // Bits/Pixel einlesen + rStm >> cByte; + nBitsPerPixel = cByte; + + // Planes immer 1; + // Kompression immer + nPlanes = 1; + bCompressed = TRUE; + + UINT32 nLen32; + + rStm.SeekRel( 8 ); + + // so lange ueberlesen, bis wir den pHYs-Chunk haben oder + // den Anfang der Bilddaten + rStm >> nLen32; + rStm >> nTemp32; + while( ( nTemp32 != 0x70485973 ) && ( nTemp32 != 0x49444154 ) ) + { + rStm.SeekRel( 4 + nLen32 ); + rStm >> nLen32; + rStm >> nTemp32; + } + + if ( nTemp32 == 0x70485973 ) + { + ULONG nXRes; + ULONG nYRes; + + // horizontale Aufloesung + rStm >> nTemp32; + nXRes = nTemp32; + + // vertikale Aufloesung + rStm >> nTemp32; + nYRes = nTemp32; + + // Unit einlesen + rStm >> cByte; + + if ( cByte ) + { + if ( nXRes ) + aLogSize.Width() = ( aPixSize.Width() * 100000 ) / + nTemp32; + + if ( nYRes ) + aLogSize.Height() = ( aPixSize.Height() * 100000 ) / + nTemp32; + } + } + } + } + } + rStm.Seek( nStmPos ); + return bRet; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectTIF( SvStream& rStm, BOOL bExtendedInfo ) +{ + BOOL bDetectOk = FALSE; + BOOL bRet = FALSE; + BYTE cByte1; + BYTE cByte2; + + sal_Int32 nStmPos = rStm.Tell(); + rStm >> cByte1; + rStm >> cByte2; + if ( cByte1 == cByte2 ) + { + if ( cByte1 == 0x49 ) + { + rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); + bDetectOk = TRUE; + } + else if ( cByte1 == 0x4d ) + { + rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); + bDetectOk = TRUE; + } + + if ( bDetectOk ) + { + UINT16 nTemp16; + + rStm >> nTemp16; + if ( nTemp16 == 0x2a ) + { + nFormat = GFF_TIF; + bRet = TRUE; + + if ( bExtendedInfo ) + { + ULONG nCount; + ULONG nMax = DATA_SIZE - 48; + UINT32 nTemp32; + BOOL bOk = FALSE; + + // Offset des ersten IFD einlesen + rStm >> nTemp32; + rStm.SeekRel( ( nCount = ( nTemp32 + 2 ) ) - 0x08 ); + + if ( nCount < nMax ) + { + // Tag's lesen, bis wir auf Tag256 ( Width ) treffen + // nicht mehr Bytes als DATA_SIZE lesen + rStm >> nTemp16; + while ( nTemp16 != 256 ) + { + bOk = nCount < nMax; + if ( !bOk ) + { + break; + } + rStm.SeekRel( 10 ); + rStm >> nTemp16; + nCount += 12; + } + + if ( bOk ) + { + // Breite lesen + rStm >> nTemp16; + rStm.SeekRel( 4 ); + if ( nTemp16 == 3 ) + { + rStm >> nTemp16; + aPixSize.Width() = nTemp16; + rStm.SeekRel( 2 ); + } + else + { + rStm >> nTemp32; + aPixSize.Width() = nTemp32; + } + nCount += 12; + + // Hoehe lesen + rStm.SeekRel( 2 ); + rStm >> nTemp16; + rStm.SeekRel( 4 ); + if ( nTemp16 == 3 ) + { + rStm >> nTemp16; + aPixSize.Height() = nTemp16; + rStm.SeekRel( 2 ); + } + else + { + rStm >> nTemp32; + aPixSize.Height() = nTemp32; + } + nCount += 12; + + // ggf. Bits/Pixel lesen + rStm >> nTemp16; + if ( nTemp16 == 258 ) + { + rStm.SeekRel( 6 ); + rStm >> nTemp16; + nBitsPerPixel = nTemp16; + rStm.SeekRel( 2 ); + nCount += 12; + } + else + rStm.SeekRel( -2 ); + + // ggf. Compression lesen + rStm >> nTemp16; + if ( nTemp16 == 259 ) + { + rStm.SeekRel( 6 ); + rStm >> nTemp16; + bCompressed = ( nTemp16 > 1 ); + rStm.SeekRel( 2 ); + nCount += 12; + } + else + rStm.SeekRel( -2 ); + } + } + } + } + } + } + rStm.Seek( nStmPos ); + return bRet; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectXBM( SvStream&, BOOL ) +{ + BOOL bRet = aPathExt.CompareToAscii( "xbm", 3 ) == COMPARE_EQUAL; + if (bRet) + nFormat = GFF_XBM; + + return bRet; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectXPM( SvStream&, BOOL ) +{ + BOOL bRet = aPathExt.CompareToAscii( "xpm", 3 ) == COMPARE_EQUAL; + if (bRet) + nFormat = GFF_XPM; + + return bRet; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectPBM( SvStream& rStm, BOOL ) +{ + BOOL bRet = FALSE; + + // erst auf Datei Extension pruefen, da diese aussagekraeftiger ist + // als die 2 ID Bytes + + if ( aPathExt.CompareToAscii( "pbm", 3 ) == COMPARE_EQUAL ) + bRet = TRUE; + else + { + sal_Int32 nStmPos = rStm.Tell(); + BYTE nFirst, nSecond; + rStm >> nFirst >> nSecond; + if ( nFirst == 'P' && ( ( nSecond == '1' ) || ( nSecond == '4' ) ) ) + bRet = TRUE; + rStm.Seek( nStmPos ); + } + + if ( bRet ) + nFormat = GFF_PBM; + + return bRet; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectPGM( SvStream& rStm, BOOL ) +{ + BOOL bRet = FALSE; + + if ( aPathExt.CompareToAscii( "pgm", 3 ) == COMPARE_EQUAL ) + bRet = TRUE; + else + { + BYTE nFirst, nSecond; + sal_Int32 nStmPos = rStm.Tell(); + rStm >> nFirst >> nSecond; + if ( nFirst == 'P' && ( ( nSecond == '2' ) || ( nSecond == '5' ) ) ) + bRet = TRUE; + rStm.Seek( nStmPos ); + } + + if ( bRet ) + nFormat = GFF_PGM; + + return bRet; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectPPM( SvStream& rStm, BOOL ) +{ + BOOL bRet = FALSE; + + if ( aPathExt.CompareToAscii( "ppm", 3 ) == COMPARE_EQUAL ) + bRet = TRUE; + else + { + BYTE nFirst, nSecond; + sal_Int32 nStmPos = rStm.Tell(); + rStm >> nFirst >> nSecond; + if ( nFirst == 'P' && ( ( nSecond == '3' ) || ( nSecond == '6' ) ) ) + bRet = TRUE; + rStm.Seek( nStmPos ); + } + + if ( bRet ) + nFormat = GFF_PPM; + + return bRet; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectRAS( SvStream& rStm, BOOL ) +{ + UINT32 nMagicNumber; + BOOL bRet = FALSE; + sal_Int32 nStmPos = rStm.Tell(); + rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); + rStm >> nMagicNumber; + if ( nMagicNumber == 0x59a66a95 ) + { + nFormat = GFF_RAS; + bRet = TRUE; + } + rStm.Seek( nStmPos ); + return bRet; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectTGA( SvStream&, BOOL ) +{ + BOOL bRet = aPathExt.CompareToAscii( "tga", 3 ) == COMPARE_EQUAL; + if (bRet) + nFormat = GFF_TGA; + + return bRet; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectPSD( SvStream& rStm, BOOL bExtendedInfo ) +{ + BOOL bRet = FALSE; + + UINT32 nMagicNumber; + sal_Int32 nStmPos = rStm.Tell(); + rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); + rStm >> nMagicNumber; + if ( nMagicNumber == 0x38425053 ) + { + UINT16 nVersion; + rStm >> nVersion; + if ( nVersion == 1 ) + { + bRet = TRUE; + if ( bExtendedInfo ) + { + UINT16 nChannels; + UINT32 nRows; + UINT32 nColumns; + UINT16 nDepth; + UINT16 nMode; + rStm.SeekRel( 6 ); // Pad + rStm >> nChannels >> nRows >> nColumns >> nDepth >> nMode; + if ( ( nDepth == 1 ) || ( nDepth == 8 ) || ( nDepth == 16 ) ) + { + nBitsPerPixel = ( nDepth == 16 ) ? 8 : nDepth; + switch ( nChannels ) + { + case 4 : + case 3 : + nBitsPerPixel = 24; + case 2 : + case 1 : + aPixSize.Width() = nColumns; + aPixSize.Height() = nRows; + break; + default: + bRet = FALSE; + } + } + else + bRet = FALSE; + } + } + } + + if ( bRet ) + nFormat = GFF_PSD; + rStm.Seek( nStmPos ); + return bRet; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectEPS( SvStream& rStm, BOOL ) +{ + // es wird die EPS mit Vorschaubild Variante und die Extensionuebereinstimmung + // geprueft + + sal_uInt32 nFirstLong; + sal_uInt8 nFirstBytes[20]; + BOOL bRet = FALSE; + + sal_Int32 nStmPos = rStm.Tell(); + rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); + rStm >> nFirstLong; + rStm.SeekRel( -4 ); + rStm.Read( &nFirstBytes, 20 ); + + if ( ( nFirstLong == 0xC5D0D3C6 ) || ( aPathExt.CompareToAscii( "eps", 3 ) == COMPARE_EQUAL ) || + ( ImplSearchEntry( nFirstBytes, (sal_uInt8*)"%!PS-Adobe", 10, 10 ) + && ImplSearchEntry( &nFirstBytes[15], (sal_uInt8*)"EPS", 3, 3 ) ) ) + { + nFormat = GFF_EPS; + bRet = TRUE; + } + rStm.Seek( nStmPos ); + return bRet; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectDXF( SvStream&, BOOL ) +{ + BOOL bRet = aPathExt.CompareToAscii( "dxf", 3 ) == COMPARE_EQUAL; + if (bRet) + nFormat = GFF_DXF; + + return bRet; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectMET( SvStream&, BOOL ) +{ + BOOL bRet = aPathExt.CompareToAscii( "met", 3 ) == COMPARE_EQUAL; + if (bRet) + nFormat = GFF_MET; + + return bRet; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectPCT( SvStream& rStm, BOOL ) +{ + BOOL bRet = aPathExt.CompareToAscii( "pct", 3 ) == COMPARE_EQUAL; + if (bRet) + nFormat = GFF_PCT; + else + { + sal_Int32 nStmPos = rStm.Tell(); + + BYTE sBuf[4]; + + rStm.SeekRel( 522 ); + rStm.Read( sBuf, 3 ); + + if( !rStm.GetError() ) + { + if ( ( sBuf[0] == 0x00 ) && ( sBuf[1] == 0x11 ) && + ( ( sBuf[2] == 0x01 ) || ( sBuf[2] == 0x02 ) ) ) + { + bRet = TRUE; + nFormat = GFF_PCT; + } + } + rStm.Seek( nStmPos ); + } + + return bRet; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectSGF( SvStream& rStm, BOOL ) +{ + BOOL bRet = FALSE; + if( aPathExt.CompareToAscii( "sgf", 3 ) == COMPARE_EQUAL ) + bRet = TRUE; + else + { + sal_Int32 nStmPos = rStm.Tell(); + + BYTE nFirst, nSecond; + + rStm >> nFirst >> nSecond; + + if( nFirst == 'J' && nSecond == 'J' ) + bRet = TRUE; + + rStm.Seek( nStmPos ); + } + + if( bRet ) + nFormat = GFF_SGF; + + return bRet; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectSGV( SvStream&, BOOL ) +{ + BOOL bRet = aPathExt.CompareToAscii( "sgv", 3 ) == COMPARE_EQUAL; + if (bRet) + nFormat = GFF_SGV; + + return bRet; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectSVM( SvStream& rStm, BOOL bExtendedInfo ) +{ + UINT32 n32; + BOOL bRet = FALSE; + BYTE cByte; + + sal_Int32 nStmPos = rStm.Tell(); + rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); + rStm >> n32; + if ( n32 == 0x44475653 ) + { + rStm >> cByte; + if ( cByte == 0x49 ) + { + nFormat = GFF_SVM; + bRet = TRUE; + + if ( bExtendedInfo ) + { + UINT32 nTemp32; + UINT16 nTemp16; + + rStm.SeekRel( 0x04 ); + + // Breite auslesen + rStm >> nTemp32; + aLogSize.Width() = nTemp32; + + // Hoehe auslesen + rStm >> nTemp32; + aLogSize.Height() = nTemp32; + + // Map-Unit auslesen und PrefSize ermitteln + rStm >> nTemp16; + aLogSize = OutputDevice::LogicToLogic( aLogSize, + MapMode( (MapUnit) nTemp16 ), + MapMode( MAP_100TH_MM ) ); + } + } + } + else + { + rStm.SeekRel( -4L ); + rStm >> n32; + + if( n32 == 0x4D4C4356 ) + { + UINT16 nTmp16; + + rStm >> nTmp16; + + if( nTmp16 == 0x4654 ) + { + nFormat = GFF_SVM; + bRet = TRUE; + + if( bExtendedInfo ) + { + MapMode aMapMode; + + rStm.SeekRel( 0x06 ); + rStm >> aMapMode; + rStm >> aLogSize; + aLogSize = OutputDevice::LogicToLogic( aLogSize, aMapMode, MapMode( MAP_100TH_MM ) ); + } + } + } + } + rStm.Seek( nStmPos ); + return bRet; +} + + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectWMF( SvStream&, BOOL ) +{ + BOOL bRet = aPathExt.CompareToAscii( "wmf",3 ) == COMPARE_EQUAL; + if (bRet) + nFormat = GFF_WMF; + + return bRet; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectEMF( SvStream&, BOOL ) +{ + BOOL bRet = aPathExt.CompareToAscii( "emf", 3 ) == COMPARE_EQUAL; + if (bRet) + nFormat = GFF_EMF; + + return bRet; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +BOOL GraphicDescriptor::ImpDetectSVG( SvStream& rStm, BOOL bExtendedInfo ) +{ + BOOL bRet = aPathExt.CompareToAscii( "svg", 3 ) == COMPARE_EQUAL; + if (bRet) + nFormat = GFF_SVG; + + return bRet; +} + +/************************************************************************* +|* +|* +|* +\************************************************************************/ + +String GraphicDescriptor::GetImportFormatShortName( sal_uInt16 nFormat ) +{ + ByteString aKeyName; + + switch( nFormat ) + { + case( GFF_BMP ) : aKeyName = "bmp"; break; + case( GFF_GIF ) : aKeyName = "gif"; break; + case( GFF_JPG ) : aKeyName = "jpg"; break; + case( GFF_PCD ) : aKeyName = "pcd"; break; + case( GFF_PCX ) : aKeyName = "pcx"; break; + case( GFF_PNG ) : aKeyName = "png"; break; + case( GFF_XBM ) : aKeyName = "xbm"; break; + case( GFF_XPM ) : aKeyName = "xpm"; break; + case( GFF_PBM ) : aKeyName = "pbm"; break; + case( GFF_PGM ) : aKeyName = "pgm"; break; + case( GFF_PPM ) : aKeyName = "ppm"; break; + case( GFF_RAS ) : aKeyName = "ras"; break; + case( GFF_TGA ) : aKeyName = "tga"; break; + case( GFF_PSD ) : aKeyName = "psd"; break; + case( GFF_EPS ) : aKeyName = "eps"; break; + case( GFF_TIF ) : aKeyName = "tif"; break; + case( GFF_DXF ) : aKeyName = "dxf"; break; + case( GFF_MET ) : aKeyName = "met"; break; + case( GFF_PCT ) : aKeyName = "pct"; break; + case( GFF_SGF ) : aKeyName = "sgf"; break; + case( GFF_SGV ) : aKeyName = "sgv"; break; + case( GFF_SVM ) : aKeyName = "svm"; break; + case( GFF_WMF ) : aKeyName = "wmf"; break; + case( GFF_EMF ) : aKeyName = "emf"; break; + case( GFF_SVG ) : aKeyName = "svg"; break; + } + + return String( aKeyName, RTL_TEXTENCODING_ASCII_US ); +} diff --git a/svtools/source/filter/igif/decode.cxx b/svtools/source/filter/igif/decode.cxx new file mode 100644 index 000000000000..bfe77319b81a --- /dev/null +++ b/svtools/source/filter/igif/decode.cxx @@ -0,0 +1,215 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include "decode.hxx" + +// ------------------------------------------------------------------------ + +struct GIFLZWTableEntry +{ + GIFLZWTableEntry* pPrev; + GIFLZWTableEntry* pFirst; + BYTE nData; +}; + +// ------------------------------------------------------------------------ + +GIFLZWDecompressor::GIFLZWDecompressor( BYTE cDataSize ) : + nInputBitsBuf ( 0 ), + nOutBufDataLen ( 0 ), + nInputBitsBufSize ( 0 ), + bEOIFound ( FALSE ), + nDataSize ( cDataSize ) +{ + pOutBuf = new BYTE[ 4096 ]; + + nClearCode = 1 << nDataSize; + nEOICode = nClearCode + 1; + nTableSize = nEOICode + 1; + nCodeSize = nDataSize + 1; + nOldCode = 0xffff; + pOutBufData = pOutBuf + 4096; + + pTable = new GIFLZWTableEntry[ 4098 ]; + + for( USHORT i = 0; i < nTableSize; i++ ) + { + pTable[i].pPrev = NULL; + pTable[i].pFirst = pTable + i; + pTable[i].nData = (BYTE) i; + } +} + +// ------------------------------------------------------------------------ + +GIFLZWDecompressor::~GIFLZWDecompressor() +{ + delete[] pOutBuf; + delete[] pTable; +} + +// ------------------------------------------------------------------------ + +HPBYTE GIFLZWDecompressor::DecompressBlock( HPBYTE pSrc, BYTE cBufSize, + ULONG& rCount, BOOL& rEOI ) +{ + ULONG nTargetSize = 4096; + ULONG nCount = 0; + HPBYTE pTarget = (HPBYTE) rtl_allocateMemory( nTargetSize ); + HPBYTE pTmpTarget = pTarget; + + nBlockBufSize = cBufSize; + nBlockBufPos = 0; + pBlockBuf = pSrc; + + while( ProcessOneCode() ) + { + nCount += nOutBufDataLen; + + if( nCount > nTargetSize ) + { + ULONG nNewSize = nTargetSize << 1; + ULONG nOffset = pTmpTarget - pTarget; + HPBYTE pTmp = (HPBYTE) rtl_allocateMemory( nNewSize ); + + memcpy( pTmp, pTarget, nTargetSize ); + rtl_freeMemory( pTarget ); + + nTargetSize = nNewSize; + pTmpTarget = ( pTarget = pTmp ) + nOffset; + } + + memcpy( pTmpTarget, pOutBufData, nOutBufDataLen ); + pTmpTarget += nOutBufDataLen; + pOutBufData += nOutBufDataLen; + nOutBufDataLen = 0; + + if ( bEOIFound ) + break; + } + + rCount = nCount; + rEOI = bEOIFound; + + return pTarget; +} + +// ------------------------------------------------------------------------ + +void GIFLZWDecompressor::AddToTable( USHORT nPrevCode, USHORT nCodeFirstData ) +{ + GIFLZWTableEntry* pE; + + if( nTableSize < 4096 ) + { + pE = pTable + nTableSize; + pE->pPrev = pTable + nPrevCode; + pE->pFirst = pE->pPrev->pFirst; + pE->nData = pTable[ nCodeFirstData ].pFirst->nData; + nTableSize++; + + if ( ( nTableSize == (USHORT) (1 << nCodeSize) ) && ( nTableSize < 4096 ) ) + nCodeSize++; + } +} + +// ------------------------------------------------------------------------ + +BOOL GIFLZWDecompressor::ProcessOneCode() +{ + GIFLZWTableEntry* pE; + USHORT nCode; + BOOL bRet = FALSE; + BOOL bEndOfBlock = FALSE; + + while( nInputBitsBufSize < nCodeSize ) + { + if( nBlockBufPos >= nBlockBufSize ) + { + bEndOfBlock = TRUE; + break; + } + + nInputBitsBuf |= ( (ULONG) pBlockBuf[ nBlockBufPos++ ] ) << nInputBitsBufSize; + nInputBitsBufSize += 8; + } + + if ( !bEndOfBlock ) + { + // Einen Code aus dem Eingabe-Buffer holen: + nCode = sal::static_int_cast< USHORT >( + ( (USHORT) nInputBitsBuf ) & ( ~( 0xffff << nCodeSize ) )); + nInputBitsBuf >>= nCodeSize; + nInputBitsBufSize = nInputBitsBufSize - nCodeSize; + + if ( nCode < nClearCode ) + { + if ( nOldCode != 0xffff ) + AddToTable( nOldCode, nCode ); + } + else if ( ( nCode > nEOICode ) && ( nCode <= nTableSize ) ) + { + if ( nCode == nTableSize ) + AddToTable( nOldCode, nOldCode ); + else + AddToTable( nOldCode, nCode ); + } + else + { + if ( nCode == nClearCode ) + { + nTableSize = nEOICode + 1; + nCodeSize = nDataSize + 1; + nOldCode = 0xffff; + nOutBufDataLen = 0; + } + else + bEOIFound = TRUE; + + return TRUE; + } + + nOldCode = nCode; + + // Zeichen(/-folge) des Codes nCode in den Ausgabe-Buffer schreiben: + pE = pTable + nCode; + do + { + nOutBufDataLen++; + *(--pOutBufData) = pE->nData; + pE = pE->pPrev; + } + while( pE ); + + bRet = TRUE; + } + + return bRet; +} diff --git a/svtools/source/filter/igif/decode.hxx b/svtools/source/filter/igif/decode.hxx new file mode 100644 index 000000000000..3c6a61e7508d --- /dev/null +++ b/svtools/source/filter/igif/decode.hxx @@ -0,0 +1,68 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _DECODE_HXX +#define _DECODE_HXX + +#ifndef _BMPACC_HXX +#include +#endif + +struct GIFLZWTableEntry; + +class GIFLZWDecompressor +{ + GIFLZWTableEntry* pTable; + HPBYTE pOutBuf; + HPBYTE pOutBufData; + HPBYTE pBlockBuf; + ULONG nInputBitsBuf; + USHORT nTableSize; + USHORT nClearCode; + USHORT nEOICode; + USHORT nCodeSize; + USHORT nOldCode; + USHORT nOutBufDataLen; + USHORT nInputBitsBufSize; + BOOL bEOIFound; + BYTE nDataSize; + BYTE nBlockBufSize; + BYTE nBlockBufPos; + + void AddToTable(USHORT nPrevCode, USHORT nCodeFirstData); + BOOL ProcessOneCode(); + + +public: + + GIFLZWDecompressor( BYTE cDataSize ); + ~GIFLZWDecompressor(); + + HPBYTE DecompressBlock( HPBYTE pSrc, BYTE cBufSize, ULONG& rCount, BOOL& rEOI ); +}; + +#endif diff --git a/svtools/source/filter/igif/gifread.cxx b/svtools/source/filter/igif/gifread.cxx new file mode 100644 index 000000000000..e4020c727ff4 --- /dev/null +++ b/svtools/source/filter/igif/gifread.cxx @@ -0,0 +1,858 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#define _GIFPRIVATE + +#include "decode.hxx" +#include "gifread.hxx" + +// ----------- +// - Defines - +// ----------- + +#define NO_PENDING( rStm ) ( ( rStm ).GetError() != ERRCODE_IO_PENDING ) + +// ------------- +// - GIFReader - +// ------------- + +GIFReader::GIFReader( SvStream& rStm ) : + aGPalette ( 256 ), + aLPalette ( 256 ), + rIStm ( rStm ), + pAcc8 ( NULL ), + pAcc1 ( NULL ), + nLastPos ( rStm.Tell() ), + nLogWidth100 ( 0UL ), + nLogHeight100 ( 0UL ), + nLoops ( 1 ), + eActAction ( GLOBAL_HEADER_READING ), + bGCTransparent ( FALSE ), + bImGraphicReady ( FALSE ) +{ + maUpperName = UniString::CreateFromAscii( "SVIGIF", 6 ); + pSrcBuf = new BYTE[ 256 ]; + ClearImageExtensions(); +} + +// ------------------------------------------------------------------------ + +GIFReader::~GIFReader() +{ + aImGraphic.SetContext( NULL ); + + if( pAcc1 ) + aBmp1.ReleaseAccess( pAcc1 ); + + if( pAcc8 ) + aBmp8.ReleaseAccess( pAcc8 ); + + delete[] pSrcBuf; +} + +// ------------------------------------------------------------------------ + +void GIFReader::ClearImageExtensions() +{ + nGCDisposalMethod = 0; + bGCTransparent = FALSE; + nTimer = 0; +} + +// ------------------------------------------------------------------------ + +BOOL GIFReader::CreateBitmaps( long nWidth, long nHeight, BitmapPalette* pPal, + BOOL bWatchForBackgroundColor ) +{ + const Size aSize( nWidth, nHeight ); + + if( bGCTransparent ) + { + const Color aWhite( COL_WHITE ); + + aBmp1 = Bitmap( aSize, 1 ); + + if( !aAnimation.Count() ) + aBmp1.Erase( aWhite ); + + pAcc1 = aBmp1.AcquireWriteAccess(); + + if( pAcc1 ) + { + cTransIndex1 = (BYTE) pAcc1->GetBestPaletteIndex( aWhite ); + cNonTransIndex1 = cTransIndex1 ? 0 : 1; + } + else + bStatus = FALSE; + } + + if( bStatus ) + { + aBmp8 = Bitmap( aSize, 8, pPal ); + + if( !!aBmp8 && bWatchForBackgroundColor && aAnimation.Count() ) + aBmp8.Erase( (*pPal)[ nBackgroundColor ] ); + else + aBmp8.Erase( Color( COL_WHITE ) ); + + pAcc8 = aBmp8.AcquireWriteAccess(); + bStatus = ( pAcc8 != NULL ); + } + + return bStatus; +} + +// ------------------------------------------------------------------------ + +BOOL GIFReader::ReadGlobalHeader() +{ + char pBuf[ 7 ]; + BYTE nRF; + BYTE nAspect; + BOOL bRet = FALSE; + + rIStm.Read( pBuf, 6 ); + if( NO_PENDING( rIStm ) ) + { + pBuf[ 6 ] = 0; + if( !strcmp( pBuf, "GIF87a" ) || !strcmp( pBuf, "GIF89a" ) ) + { + rIStm.Read( pBuf, 7 ); + if( NO_PENDING( rIStm ) ) + { + SvMemoryStream aMemStm; + + aMemStm.SetBuffer( pBuf, 7, FALSE, 7 ); + aMemStm >> nGlobalWidth; + aMemStm >> nGlobalHeight; + aMemStm >> nRF; + aMemStm >> nBackgroundColor; + aMemStm >> nAspect; + + bGlobalPalette = (BOOL) ( nRF & 0x80 ); + + if( bGlobalPalette ) + ReadPaletteEntries( &aGPalette, 1 << ( ( nRF & 7 ) + 1 ) ); + else + nBackgroundColor = 0; + + if( NO_PENDING( rIStm ) ) + bRet = TRUE; + } + } + else + bStatus = FALSE; + } + + return bRet; +} + +// ------------------------------------------------------------------------ + +void GIFReader::ReadPaletteEntries( BitmapPalette* pPal, ULONG nCount ) +{ + const ULONG nLen = 3UL * nCount; + BYTE* pBuf = new BYTE[ nLen ]; + + rIStm.Read( pBuf, nLen ); + if( NO_PENDING( rIStm ) ) + { + BYTE* pTmp = pBuf; + + for( ULONG i = 0UL; i < nCount; ) + { + BitmapColor& rColor = (*pPal)[ (USHORT) i++ ]; + + rColor.SetRed( *pTmp++ ); + rColor.SetGreen( *pTmp++ ); + rColor.SetBlue( *pTmp++ ); + } + + // nach Moeglichkeit noch einige Standardfarben unterbringen + if( nCount < 256UL ) + { + (*pPal)[ 255UL ] = Color( COL_WHITE ); + + if( nCount < 255UL ) + (*pPal)[ 254UL ] = Color( COL_BLACK ); + } + } + + delete[] pBuf; +} + +// ------------------------------------------------------------------------ + +BOOL GIFReader::ReadExtension() +{ + BYTE cFunction; + BYTE cSize; + BYTE cByte; + BOOL bRet = FALSE; + BOOL bOverreadDataBlocks = FALSE; + + // Extension-Label + rIStm >> cFunction; + if( NO_PENDING( rIStm ) ) + { + // Block-Laenge + rIStm >> cSize; + + switch( cFunction ) + { + // 'Graphic Control Extension' + case( 0xf9 ) : + { + BYTE cFlags; + + rIStm >> cFlags; + rIStm >> nTimer; + rIStm >> nGCTransparentIndex; + rIStm >> cByte; + + if ( NO_PENDING( rIStm ) ) + { + nGCDisposalMethod = ( cFlags >> 2) & 7; + bGCTransparent = ( cFlags & 1 ) ? TRUE : FALSE; + bStatus = ( cSize == 4 ) && ( cByte == 0 ); + bRet = TRUE; + } + } + break; + + // Application-Extension + case ( 0xff ) : + { + if ( NO_PENDING( rIStm ) ) + { + // default diese Extension ueberlesen + bOverreadDataBlocks = TRUE; + + // Appl.-Extension hat Laenge 11 + if ( cSize == 0x0b ) + { + ByteString aAppId; + ByteString aAppCode; + + rIStm.Read( aAppId.AllocBuffer( 8 ), 8 ); + rIStm.Read( aAppCode.AllocBuffer( 3 ), 3 ); + rIStm >> cSize; + + // NetScape-Extension + if( aAppId == "NETSCAPE" && aAppCode == "2.0" && cSize == 3 ) + { + rIStm >> cByte; + + // Loop-Extension + if ( cByte == 0x01 ) + { + rIStm >> cByte; + nLoops = cByte; + rIStm >> cByte; + nLoops |= ( (USHORT) cByte << 8 ); + rIStm >> cByte; + + bStatus = ( cByte == 0 ); + bRet = NO_PENDING( rIStm ); + bOverreadDataBlocks = FALSE; + + // Netscape interpretiert den LoopCount + // als reine Anzahl der _Wiederholungen_; + // bei uns ist es die Gesamtanzahl der + // Durchlaeufe + if( nLoops ) + nLoops++; + } + else + rIStm.SeekRel( -1 ); + } + else if ( aAppId == "STARDIV " && aAppCode == "5.0" && cSize == 9 ) + { + rIStm >> cByte; + + // Loop-Extension + if ( cByte == 0x01 ) + { + rIStm >> nLogWidth100 >> nLogHeight100; + rIStm >> cByte; + bStatus = ( cByte == 0 ); + bRet = NO_PENDING( rIStm ); + bOverreadDataBlocks = FALSE; + } + else + rIStm.SeekRel( -1 ); + } + + } + } + } + break; + + // alles andere ueberlesen + default: + bOverreadDataBlocks = TRUE; + break; + } + + // Sub-Blocks ueberlesen + if ( bOverreadDataBlocks ) + { + bRet = TRUE; + while( cSize && bStatus && !rIStm.IsEof() ) + { + USHORT nCount = (USHORT) cSize + 1; + char* pBuffer = new char[ nCount ]; + + bRet = FALSE; + rIStm.Read( pBuffer, nCount ); + if( NO_PENDING( rIStm ) ) + { + cSize = (BYTE) pBuffer[ cSize ]; + bRet = TRUE; + } + else + cSize = 0; + + delete[] pBuffer; + } + } + } + + return bRet; +} + +// ------------------------------------------------------------------------ + +BOOL GIFReader::ReadLocalHeader() +{ + BYTE pBuf[ 9 ]; + BOOL bRet = FALSE; + + rIStm.Read( pBuf, 9 ); + if( NO_PENDING( rIStm ) ) + { + SvMemoryStream aMemStm; + BitmapPalette* pPal; + BYTE nFlags; + + aMemStm.SetBuffer( (char*) pBuf, 9, FALSE, 9 ); + aMemStm >> nImagePosX; + aMemStm >> nImagePosY; + aMemStm >> nImageWidth; + aMemStm >> nImageHeight; + aMemStm >> nFlags; + + // Falls Interlaced, ersten Startwert vorgeben + bInterlaced = ( ( nFlags & 0x40 ) == 0x40 ); + nLastInterCount = 7; + nLastImageY = 0; + + if( nFlags & 0x80 ) + { + pPal = &aLPalette; + ReadPaletteEntries( pPal, 1 << ( (nFlags & 7 ) + 1 ) ); + } + else + pPal = &aGPalette; + + // Falls alles soweit eingelesen werden konnte, kann + // nun das lokale Bild angelegt werden; + // es wird uebergeben, ob der BackgroundColorIndex evtl. + // beruecksichtigt werden soll ( wenn Globale Farbtab. und + // diese auch fuer dieses Bild gilt ) + if( NO_PENDING( rIStm ) ) + { + CreateBitmaps( nImageWidth, nImageHeight, pPal, bGlobalPalette && ( pPal == &aGPalette ) ); + bRet = TRUE; + } + } + + return bRet; +} + +// ------------------------------------------------------------------------ + +ULONG GIFReader::ReadNextBlock() +{ + ULONG nRet = 0UL; + ULONG nRead; + BYTE cBlockSize; + + rIStm >> cBlockSize; + + if ( rIStm.IsEof() ) + nRet = 4UL; + else if ( NO_PENDING( rIStm ) ) + { + if ( cBlockSize == 0 ) + nRet = 2UL; + else + { + rIStm.Read( pSrcBuf, cBlockSize ); + + if( NO_PENDING( rIStm ) ) + { + if( bOverreadBlock ) + nRet = 3UL; + else + { + BOOL bEOI; + HPBYTE pTarget = pDecomp->DecompressBlock( pSrcBuf, cBlockSize, nRead, bEOI ); + + nRet = ( bEOI ? 3 : 1 ); + + if( nRead && !bOverreadBlock ) + FillImages( pTarget, nRead ); + + rtl_freeMemory( pTarget ); + } + } + } + } + + return nRet; +} + +// ------------------------------------------------------------------------ + +void GIFReader::FillImages( HPBYTE pBytes, ULONG nCount ) +{ + for( ULONG i = 0UL; i < nCount; i++ ) + { + if( nImageX >= nImageWidth ) + { + if( bInterlaced ) + { + long nT1, nT2; + + // falls Interlaced, werden die Zeilen kopiert + if( nLastInterCount ) + { + long nMinY = Min( (long) nLastImageY + 1, (long) nImageHeight - 1 ); + long nMaxY = Min( (long) nLastImageY + nLastInterCount, (long) nImageHeight - 1 ); + + // letzte gelesene Zeile kopieren, wenn Zeilen + // nicht zusanmmenfallen ( kommt vorm wenn wir am Ende des Bildes sind ) + if( ( nMinY > nLastImageY ) && ( nLastImageY < ( nImageHeight - 1 ) ) ) + { + HPBYTE pScanline8 = pAcc8->GetScanline( nYAcc ); + ULONG nSize8 = pAcc8->GetScanlineSize(); + HPBYTE pScanline1 = 0; + ULONG nSize1 = 0; + + if( bGCTransparent ) + { + pScanline1 = pAcc1->GetScanline( nYAcc ); + nSize1 = pAcc1->GetScanlineSize(); + } + + for( long j = nMinY; j <= nMaxY; j++ ) + { + memcpy( pAcc8->GetScanline( j ), pScanline8, nSize8 ); + + if( bGCTransparent ) + memcpy( pAcc1->GetScanline( j ), pScanline1, nSize1 ); + } + } + } + + nT1 = ( ++nImageY ) << 3; + nLastInterCount = 7; + + if( nT1 >= nImageHeight ) + { + nT2 = nImageY - ( ( nImageHeight + 7 ) >> 3 ); + nT1 = ( nT2 << 3 ) + 4; + nLastInterCount = 3; + + if( nT1 >= nImageHeight ) + { + nT2 -= ( nImageHeight + 3 ) >> 3; + nT1 = ( nT2 << 2 ) + 2; + nLastInterCount = 1; + + if( nT1 >= nImageHeight ) + { + nT2 -= ( nImageHeight + 1 ) >> 2; + nT1 = ( nT2 << 1 ) + 1; + nLastInterCount = 0; + } + } + } + + nLastImageY = (USHORT) nT1; + nYAcc = nT1; + } + else + { + nLastImageY = ++nImageY; + nYAcc = nImageY; + } + + // Zeile faengt von vorne an + nImageX = 0; + } + + if( nImageY < nImageHeight ) + { + const BYTE cTmp = pBytes[ i ]; + + if( bGCTransparent ) + { + if( cTmp == nGCTransparentIndex ) + pAcc1->SetPixel( nYAcc, nImageX++, cTransIndex1 ); + else + { + pAcc8->SetPixel( nYAcc, nImageX, cTmp ); + pAcc1->SetPixel( nYAcc, nImageX++, cNonTransIndex1 ); + } + } + else + pAcc8->SetPixel( nYAcc, nImageX++, cTmp ); + } + else + { + bOverreadBlock = TRUE; + break; + } + } +} + +// ------------------------------------------------------------------------ + +void GIFReader::CreateNewBitmaps() +{ + AnimationBitmap aAnimBmp; + + aBmp8.ReleaseAccess( pAcc8 ); + pAcc8 = NULL; + + if( bGCTransparent ) + { + aBmp1.ReleaseAccess( pAcc1 ); + pAcc1 = NULL; + aAnimBmp.aBmpEx = BitmapEx( aBmp8, aBmp1 ); + } + else + aAnimBmp.aBmpEx = BitmapEx( aBmp8 ); + + aAnimBmp.aPosPix = Point( nImagePosX, nImagePosY ); + aAnimBmp.aSizePix = Size( nImageWidth, nImageHeight ); + aAnimBmp.nWait = ( nTimer != 65535 ) ? nTimer : ANIMATION_TIMEOUT_ON_CLICK; + aAnimBmp.bUserInput = FALSE; + + if( nGCDisposalMethod == 2 ) + aAnimBmp.eDisposal = DISPOSE_BACK; + else if( nGCDisposalMethod == 3 ) + aAnimBmp.eDisposal = DISPOSE_PREVIOUS; + else + aAnimBmp.eDisposal = DISPOSE_NOT; + + aAnimation.Insert( aAnimBmp ); + + if( aAnimation.Count() == 1 ) + { + aAnimation.SetDisplaySizePixel( Size( nGlobalWidth, nGlobalHeight ) ); + aAnimation.SetLoopCount( nLoops ); + } +} + +// ------------------------------------------------------------------------ + +const Graphic& GIFReader::GetIntermediateGraphic() +{ + // Intermediate-Graphic nur erzeugen, wenn schon + // Daten vorliegen, aber die Graphic noch nicht + // vollstaendig eingelesen wurde + if ( bImGraphicReady && !aAnimation.Count() ) + { + Bitmap aBmp; + + aBmp8.ReleaseAccess( pAcc8 ); + + if ( bGCTransparent ) + { + aBmp1.ReleaseAccess( pAcc1 ); + aImGraphic = BitmapEx( aBmp8, aBmp1 ); + + pAcc1 = aBmp1.AcquireWriteAccess(); + bStatus = bStatus && ( pAcc1 != NULL ); + } + else + aImGraphic = aBmp8; + + pAcc8 = aBmp8.AcquireWriteAccess(); + bStatus = bStatus && ( pAcc8 != NULL ); + } + + return aImGraphic; +} + +// ------------------------------------------------------------------------ + +BOOL GIFReader::ProcessGIF() +{ + BOOL bRead = FALSE; + BOOL bEnd = FALSE; + + if ( !bStatus ) + eActAction = ABORT_READING; + + // Stream an die richtige Stelle bringen + rIStm.Seek( nLastPos ); + + switch( eActAction ) + { + // naechsten Marker lesen + case( MARKER_READING ): + { + BYTE cByte; + + rIStm >> cByte; + + if( rIStm.IsEof() ) + eActAction = END_READING; + else if( NO_PENDING( rIStm ) ) + { + bRead = TRUE; + + if( cByte == '!' ) + eActAction = EXTENSION_READING; + else if( cByte == ',' ) + eActAction = LOCAL_HEADER_READING; + else if( cByte == ';' ) + eActAction = END_READING; + else + eActAction = ABORT_READING; + } + } + break; + + // ScreenDescriptor lesen + case( GLOBAL_HEADER_READING ): + { + if( ( bRead = ReadGlobalHeader() ) == TRUE ) + { + ClearImageExtensions(); + eActAction = MARKER_READING; + } + } + break; + + + // Extension lesen + case( EXTENSION_READING ): + { + if( ( bRead = ReadExtension() ) == TRUE ) + eActAction = MARKER_READING; + } + break; + + + // Image-Descriptor lesen + case( LOCAL_HEADER_READING ): + { + if( ( bRead = ReadLocalHeader() ) == TRUE ) + { + nYAcc = nImageX = nImageY = 0; + eActAction = FIRST_BLOCK_READING; + } + } + break; + + + // ersten Datenblock lesen + case( FIRST_BLOCK_READING ): + { + BYTE cDataSize; + + rIStm >> cDataSize; + + if( rIStm.IsEof() ) + eActAction = ABORT_READING; + else if( cDataSize > 12 ) + bStatus = FALSE; + else if( NO_PENDING( rIStm ) ) + { + bRead = TRUE; + pDecomp = new GIFLZWDecompressor( cDataSize ); + eActAction = NEXT_BLOCK_READING; + bOverreadBlock = FALSE; + } + else + eActAction = FIRST_BLOCK_READING; + } + break; + + // naechsten Datenblock lesen + case( NEXT_BLOCK_READING ): + { + USHORT nLastX = nImageX; + USHORT nLastY = nImageY; + ULONG nRet = ReadNextBlock(); + + // Return: 0:Pending / 1:OK; / 2:OK und letzter Block: / 3:EOI / 4:HardAbort + if( nRet ) + { + bRead = TRUE; + + if ( nRet == 1UL ) + { + bImGraphicReady = TRUE; + eActAction = NEXT_BLOCK_READING; + bOverreadBlock = FALSE; + } + else + { + if( nRet == 2UL ) + { + delete pDecomp; + CreateNewBitmaps(); + eActAction = MARKER_READING; + ClearImageExtensions(); + } + else if( nRet == 3UL ) + { + eActAction = NEXT_BLOCK_READING; + bOverreadBlock = TRUE; + } + else + { + delete pDecomp; + CreateNewBitmaps(); + eActAction = ABORT_READING; + ClearImageExtensions(); + } + } + } + else + { + nImageX = nLastX; + nImageY = nLastY; + } + } + break; + + // ein Fehler trat auf + case( ABORT_READING ): + { + bEnd = TRUE; + eActAction = END_READING; + } + break; + + default: + break; + } + + // Stream an die richtige Stelle bringen, + // falls Daten gelesen werden konnten + // entweder alte Position oder aktuelle Position + if( bRead || bEnd ) + nLastPos = rIStm.Tell(); + + return bRead; +} + +// ------------------------------------------------------------------------ + +ReadState GIFReader::ReadGIF( Graphic& rGraphic ) +{ + ReadState eReadState; + + bStatus = TRUE; + + while( ProcessGIF() && ( eActAction != END_READING ) ) {} + + if( !bStatus ) + eReadState = GIFREAD_ERROR; + else if( eActAction == END_READING ) + eReadState = GIFREAD_OK; + else + { + if ( rIStm.GetError() == ERRCODE_IO_PENDING ) + rIStm.ResetError(); + + eReadState = GIFREAD_NEED_MORE; + } + + if( aAnimation.Count() == 1 ) + { + rGraphic = aAnimation.Get( 0 ).aBmpEx; + + if( nLogWidth100 && nLogHeight100 ) + { + rGraphic.SetPrefSize( Size( nLogWidth100, nLogHeight100 ) ); + rGraphic.SetPrefMapMode( MAP_100TH_MM ); + } + } + else + rGraphic = aAnimation; + + return eReadState; +} + + +// ------------- +// - ImportGIF - +// ------------- + +BOOL ImportGIF( SvStream & rStm, Graphic& rGraphic ) +{ + GIFReader* pGIFReader = (GIFReader*) rGraphic.GetContext(); + USHORT nOldFormat = rStm.GetNumberFormatInt(); + ReadState eReadState; + BOOL bRet = TRUE; + + rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); + + if( !pGIFReader ) + pGIFReader = new GIFReader( rStm ); + + rGraphic.SetContext( NULL ); + eReadState = pGIFReader->ReadGIF( rGraphic ); + + if( eReadState == GIFREAD_ERROR ) + { + bRet = FALSE; + delete pGIFReader; + } + else if( eReadState == GIFREAD_OK ) + delete pGIFReader; + else + { + rGraphic = pGIFReader->GetIntermediateGraphic(); + rGraphic.SetContext( pGIFReader ); + } + + rStm.SetNumberFormatInt( nOldFormat ); + + return bRet; +} diff --git a/svtools/source/filter/ixbm/xbmread.cxx b/svtools/source/filter/ixbm/xbmread.cxx new file mode 100644 index 000000000000..9c7faaafa88c --- /dev/null +++ b/svtools/source/filter/ixbm/xbmread.cxx @@ -0,0 +1,398 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#define XBMMINREAD 512 + +#define _XBMPRIVATE +#include +#include "xbmread.hxx" + +// ------------- +// - XBMReader - +// ------------- + +XBMReader::XBMReader( SvStream& rStm ) : + rIStm ( rStm ), + pAcc1 ( NULL ), + nLastPos ( rStm.Tell() ), + nWidth ( 0 ), + nHeight ( 0 ), + bStatus ( TRUE ) +{ + pHexTable = new short[ 256 ]; + maUpperName = String::CreateFromAscii( "SVIXBM", 6 ); + InitTable(); +} + +// ------------------------------------------------------------------------ + +XBMReader::~XBMReader() +{ + delete[] pHexTable; + + if( pAcc1 ) + aBmp1.ReleaseAccess( pAcc1 ); +} + +// ------------------------------------------------------------------------ + +void XBMReader::InitTable() +{ + memset( pHexTable, 0, sizeof( short ) ); + + pHexTable['0'] = 0; + pHexTable['1'] = 1; + pHexTable['2'] = 2; + pHexTable['3'] = 3; + pHexTable['4'] = 4; + pHexTable['5'] = 5; + pHexTable['6'] = 6; + pHexTable['7'] = 7; + pHexTable['8'] = 8; + pHexTable['9'] = 9; + pHexTable['A'] = 10; + pHexTable['B'] = 11; + pHexTable['C'] = 12; + pHexTable['D'] = 13; + pHexTable['E'] = 14; + pHexTable['F'] = 15; + pHexTable['X'] = 0; + pHexTable['a'] = 10; + pHexTable['b'] = 11; + pHexTable['c'] = 12; + pHexTable['d'] = 13; + pHexTable['e'] = 14; + pHexTable['f'] = 15; + pHexTable['x'] = 0; + pHexTable[' '] = -1; + pHexTable[','] = -1; + pHexTable['}'] = -1; + pHexTable['\n'] = -1; + pHexTable['\t'] = -1; + pHexTable['\0'] = -1; +} + +// ------------------------------------------------------------------------ + +ByteString XBMReader::FindTokenLine( SvStream* pInStm, const char* pTok1, + const char* pTok2, const char* pTok3 ) +{ + ByteString aRet; + long nPos1; + long nPos2; + long nPos3; + + bStatus = FALSE; + + do + { + if( !pInStm->ReadLine( aRet ) ) + break; + + if( pTok1 ) + { + if( ( nPos1 = aRet.Search( pTok1 ) ) != STRING_NOTFOUND ) + { + bStatus = TRUE; + + if( pTok2 ) + { + bStatus = FALSE; + + if( ( ( nPos2 = aRet.Search( pTok2 ) ) != STRING_NOTFOUND ) && + ( nPos2 > nPos1 ) ) + { + bStatus = TRUE; + + if( pTok3 ) + { + bStatus = FALSE; + + if( ( ( nPos3 = aRet.Search( pTok3 ) ) != STRING_NOTFOUND ) && ( nPos3 > nPos2 ) ) + bStatus = TRUE; + } + } + } + } + } + } + while( !bStatus ); + + return aRet; +} + +// ------------------------------------------------------------------------ + +long XBMReader::ParseDefine( const sal_Char* pDefine ) +{ + long nRet = 0; + char* pTmp = (char*) pDefine; + unsigned char cTmp; + + // bis zum Ende gehen + pTmp += ( strlen( pDefine ) - 1 ); + cTmp = *pTmp--; + + // letzte Ziffer suchen + while( pHexTable[ cTmp ] == -1 ) + cTmp = *pTmp--; + + // bis vor die Zahl laufen + while( pHexTable[ cTmp ] != -1 ) + cTmp = *pTmp--; + + // auf Anfang der Zahl gehen + pTmp += 2; + + // Hex lesen + if( ( pTmp[0] == '0' ) && ( ( pTmp[1] == 'X' ) || ( pTmp[1] == 'x' ) ) ) + { + pTmp += 2; + cTmp = *pTmp++; + + while ( pHexTable[ cTmp ] != -1 ) + { + nRet = ( nRet << 4 ) + pHexTable[ cTmp ]; + cTmp = *pTmp++; + } + } + // Dezimal lesen + else + { + cTmp = *pTmp++; + while( ( cTmp >= '0' ) && ( cTmp <= '9' ) ) + { + nRet = nRet * 10 + ( cTmp - '0' ); + cTmp = *pTmp++; + } + } + + return nRet; +} + +// ------------------------------------------------------------------------ + +BOOL XBMReader::ParseData( SvStream* pInStm, const ByteString& aLastLine, XBMFormat eFormat ) +{ + ByteString aLine; + long nRow = 0; + long nCol = 0; + long nBits = ( eFormat == XBM10 ) ? 16 : 8; + long nBit; + USHORT nValue; + USHORT nDigits; + BOOL bFirstLine = TRUE; + + while( nRow < nHeight ) + { + if( bFirstLine ) + { + xub_StrLen nPos; + + // einfuehrende geschweifte Klammer loeschen + if( (nPos = ( aLine = aLastLine ).Search( '{' ) ) != STRING_NOTFOUND ) + aLine.Erase( 0, nPos + 1 ); + + bFirstLine = FALSE; + } + else if( !pInStm->ReadLine( aLine ) ) + break; + + if( aLine.Len() ) + { + const USHORT nCount = aLine.GetTokenCount( ',' ); + + for( USHORT i = 0; ( i < nCount ) && ( nRow < nHeight ); i++ ) + { + const ByteString aToken( aLine.GetToken( i, ',' ) ); + const xub_StrLen nLen = aToken.Len(); + BOOL bProcessed = FALSE; + + nBit = nDigits = nValue = 0; + + for( xub_StrLen n = 0UL; n < nLen; n++ ) + { + const unsigned char cChar = aToken.GetChar( n ); + const short nTable = pHexTable[ cChar ]; + + if( isxdigit( cChar ) || !nTable ) + { + nValue = ( nValue << 4 ) + nTable; + nDigits++; + bProcessed = TRUE; + } + else if( ( nTable < 0 ) && nDigits ) + { + bProcessed = TRUE; + break; + } + } + + if( bProcessed ) + { + while( ( nCol < nWidth ) && ( nBit < nBits ) ) + pAcc1->SetPixel( nRow, nCol++, ( nValue & ( 1 << nBit++ ) ) ? aBlack : aWhite ); + + if( nCol == nWidth ) + nCol = 0, nRow++; + } + } + } + } + + return TRUE; +} + +// ------------------------------------------------------------------------ + +ReadState XBMReader::ReadXBM( Graphic& rGraphic ) +{ + ReadState eReadState; + BYTE cDummy; + + // sehen, ob wir _alles_ lesen koennen + rIStm.Seek( STREAM_SEEK_TO_END ); + rIStm >> cDummy; + + // falls wir nicht alles lesen koennen + // kehren wir zurueck und warten auf neue Daten + if ( rIStm.GetError() != ERRCODE_IO_PENDING ) + { + ByteString aLine; + int nValue; + + rIStm.Seek( nLastPos ); + bStatus = FALSE; + aLine = FindTokenLine( &rIStm, "#define", "_width" ); + + if ( bStatus ) + { + if ( ( nValue = (int) ParseDefine( aLine.GetBuffer() ) ) > 0 ) + { + nWidth = nValue; + aLine = FindTokenLine( &rIStm, "#define", "_height" ); + + // Falls die Hoehe nicht folgt, suchen wir noch + // einmal vom Anfang der Datei an + if ( !bStatus ) + { + rIStm.Seek( nLastPos ); + aLine = FindTokenLine( &rIStm, "#define", "_height" ); + } + } + else + bStatus = FALSE; + + if ( bStatus ) + { + if ( ( nValue = (int) ParseDefine( aLine.GetBuffer() ) ) > 0 ) + { + nHeight = nValue; + aLine = FindTokenLine( &rIStm, "static", "_bits" ); + + if ( bStatus ) + { + XBMFormat eFormat = XBM10; + + if ( aLine.Search( "short" ) != STRING_NOTFOUND ) + eFormat = XBM10; + else if ( aLine.Search( "char" ) != STRING_NOTFOUND ) + eFormat = XBM11; + else + bStatus = FALSE; + + if ( bStatus && nWidth && nHeight ) + { + aBmp1 = Bitmap( Size( nWidth, nHeight ), 1 ); + pAcc1 = aBmp1.AcquireWriteAccess(); + + if( pAcc1 ) + { + aWhite = pAcc1->GetBestMatchingColor( Color( COL_WHITE ) ); + aBlack = pAcc1->GetBestMatchingColor( Color( COL_BLACK ) ); + bStatus = ParseData( &rIStm, aLine, eFormat ); + } + else + bStatus = FALSE; + } + } + } + } + } + + if( bStatus ) + { + Bitmap aBlackBmp( Size( pAcc1->Width(), pAcc1->Height() ), 1 ); + + aBmp1.ReleaseAccess( pAcc1 ), pAcc1 = NULL; + aBlackBmp.Erase( Color( COL_BLACK ) ); + rGraphic = BitmapEx( aBlackBmp, aBmp1 ); + eReadState = XBMREAD_OK; + } + else + eReadState = XBMREAD_ERROR; + } + else + { + rIStm.ResetError(); + eReadState = XBMREAD_NEED_MORE; + } + + return eReadState; +} + +// ------------- +// - ImportXBM - +// ------------- + +BOOL ImportXBM( SvStream& rStm, Graphic& rGraphic ) +{ + XBMReader* pXBMReader = (XBMReader*) rGraphic.GetContext(); + ReadState eReadState; + BOOL bRet = TRUE; + + if( !pXBMReader ) + pXBMReader = new XBMReader( rStm ); + + rGraphic.SetContext( NULL ); + eReadState = pXBMReader->ReadXBM( rGraphic ); + + if( eReadState == XBMREAD_ERROR ) + { + bRet = FALSE; + delete pXBMReader; + } + else if( eReadState == XBMREAD_OK ) + delete pXBMReader; + else + rGraphic.SetContext( pXBMReader ); + + return bRet; +} diff --git a/svtools/source/filter/ixpm/rgbtable.hxx b/svtools/source/filter/ixpm/rgbtable.hxx new file mode 100644 index 000000000000..afdab883b369 --- /dev/null +++ b/svtools/source/filter/ixpm/rgbtable.hxx @@ -0,0 +1,695 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +struct XPMRGBTab +{ + const char* name; + BYTE red; + BYTE green; + BYTE blue; +}; + +static XPMRGBTab pRGBTable[] = { +{ "white", 255, 255, 255 }, +{ "black", 0, 0, 0 }, +{ "snow", 255, 250, 250 }, +{ "GhostWhite", 248, 248, 255 }, +{ "WhiteSmoke", 245, 245, 245 }, +{ "gainsboro", 220, 220, 220 }, +{ "FloralWhite", 255, 250, 240 }, +{ "OldLace", 253, 245, 230 }, +{ "linen", 250, 240, 230 }, +{ "AntiqueWhite", 250, 235, 215 }, +{ "PapayaWhip", 255, 239, 213 }, +{ "BlanchedAlmond", 255, 235, 205 }, +{ "bisque", 255, 228, 196 }, +{ "PeachPuff", 255, 218, 185 }, +{ "NavajoWhite", 255, 222, 173 }, +{ "moccasin", 255, 228, 181 }, +{ "cornsilk", 255, 248, 220 }, +{ "ivory", 255, 255, 240 }, +{ "LemonChiffon", 255, 250, 205 }, +{ "seashell", 255, 245, 238 }, +{ "honeydew", 240, 255, 240 }, +{ "MintCream", 245, 255, 250 }, +{ "azure", 240, 255, 255 }, +{ "AliceBlue", 240, 248, 255 }, +{ "lavender", 230, 230, 250 }, +{ "LavenderBlush", 255, 240, 245 }, +{ "MistyRose", 255, 228, 225 }, +{ "DarkSlateGray", 47, 79, 79 }, +{ "DarkSlateGrey", 47, 79, 79 }, +{ "DimGray", 105, 105, 105 }, +{ "DimGrey", 105, 105, 105 }, +{ "SlateGray", 112, 128, 144 }, +{ "SlateGrey", 112, 128, 144 }, +{ "LightSlateGray", 119, 136, 153 }, +{ "LightSlateGrey", 119, 136, 153 }, +{ "gray", 190, 190, 190 }, +{ "grey", 190, 190, 190 }, +{ "LightGrey", 211, 211, 211 }, +{ "LightGray", 211, 211, 211 }, +{ "MidnightBlue", 25, 25, 112 }, +{ "navy", 0, 0, 128 }, +{ "NavyBlue", 0, 0, 128 }, +{ "CornflowerBlue", 100, 149, 237 }, +{ "DarkSlateBlue", 72, 61, 139 }, +{ "SlateBlue", 106, 90, 205 }, +{ "MediumSlateBlue", 123, 104, 238 }, +{ "LightSlateBlue", 132, 112, 255 }, +{ "MediumBlue", 0, 0, 205 }, +{ "RoyalBlue", 65, 105, 225 }, +{ "blue", 0, 0, 255 }, +{ "DodgerBlue", 30, 144, 255 }, +{ "DeepSkyBlue", 0, 191, 255 }, +{ "SkyBlue", 135, 206, 235 }, +{ "LightSkyBlue", 135, 206, 250 }, +{ "SteelBlue", 70, 130, 180 }, +{ "LightSteelBlue", 176, 196, 222 }, +{ "LightBlue", 173, 216, 230 }, +{ "PowderBlue", 176, 224, 230 }, +{ "PaleTurquoise", 175, 238, 238 }, +{ "DarkTurquoise", 0, 206, 209 }, +{ "MediumTurquoise", 72, 209, 204 }, +{ "turquoise", 64, 224, 208 }, +{ "cyan", 0, 255, 255 }, +{ "LightCyan", 224, 255, 255 }, +{ "CadetBlue", 95, 158, 160 }, +{ "MediumAquamarine", 102, 205, 170 }, +{ "aquamarine", 127, 255, 212 }, +{ "DarkGreen", 0, 100, 0 }, +{ "DarkOliveGreen", 85, 107, 47 }, +{ "DarkSeaGreen", 143, 188, 143 }, +{ "SeaGreen", 46, 139, 87 }, +{ "MediumSeaGreen", 60, 179, 113 }, +{ "LightSeaGreen", 32, 178, 170 }, +{ "PaleGreen", 152, 251, 152 }, +{ "SpringGreen", 0, 255, 127 }, +{ "LawnGreen", 124, 252, 0 }, +{ "green", 0, 255, 0 }, +{ "chartreuse", 127, 255, 0 }, +{ "MediumSpringGreen", 0, 250, 154 }, +{ "GreenYellow", 173, 255 , 47 }, +{ "LimeGreen", 50, 205, 50 }, +{ "YellowGreen", 154, 205, 50 }, +{ "ForestGreen", 34, 139, 34 }, +{ "OliveDrab", 107, 142, 35 }, +{ "DarkKhaki", 189, 183, 107 }, +{ "khaki", 240, 230, 140 }, +{ "PaleGoldenrod", 238, 232, 170 }, +{ "LightGoldenrodYellow", 250, 250, 210 }, +{ "LightYellow", 255, 255, 224 }, +{ "yellow", 255, 255, 0 }, +{ "gold", 255, 215, 0 }, +{ "LightGoldenrod", 238, 221, 130 }, +{ "goldenrod", 218, 165, 32 }, +{ "DarkGoldenrod", 184, 134, 11 }, +{ "RosyBrown", 188, 143, 143 }, +{ "IndianRed", 205, 92, 92 }, +{ "SaddleBrown", 139, 69, 19 }, +{ "sienna", 160, 82, 45 }, +{ "peru", 205, 133, 63 }, +{ "burlywood", 222, 184, 135 }, +{ "beige", 245, 245, 220 }, +{ "wheat", 245, 222, 179 }, +{ "SandyBrown", 244, 164, 96 }, +{ "tan", 210, 180, 140 }, +{ "chocolate", 210, 105, 30 }, +{ "firebrick", 178, 34, 34 }, +{ "brown", 165, 42, 42 }, +{ "DarkSalmon", 233, 150, 122 }, +{ "salmon", 250, 128, 114 }, +{ "LightSalmon", 255, 160, 122 }, +{ "orange", 255, 165, 0 }, +{ "DarkOrange", 255, 140, 0 }, +{ "coral", 255, 127, 80 }, +{ "LightCoral", 240, 128, 128 }, +{ "tomato", 255, 99, 71 }, +{ "OrangeRed", 255, 69, 0 }, +{ "red", 255, 0, 0 }, +{ "HotPink", 255, 105, 180 }, +{ "DeepPink", 255, 20, 147 }, +{ "pink", 255, 192, 203 }, +{ "LightPink", 255, 182, 193 }, +{ "PaleVioletRed", 219, 112, 147 }, +{ "maroon", 176, 48, 96 }, +{ "MediumVioletRed", 199, 21, 133 }, +{ "VioletRed", 208, 32, 144 }, +{ "magenta", 255, 0, 255 }, +{ "violet", 238, 130, 238 }, +{ "plum", 221, 160, 221 }, +{ "orchid", 218, 112, 214 }, +{ "MediumOrchid", 186, 85, 211 }, +{ "DarkOrchid", 153, 50, 204 }, +{ "DarkViolet", 148, 0, 211 }, +{ "BlueViolet", 138, 43, 226 }, +{ "purple", 160, 32, 240 }, +{ "MediumPurple", 147, 112, 219 }, +{ "thistle", 216, 191, 216 }, +{ "snow1", 255, 250, 250 }, +{ "snow2", 238, 233, 233 }, +{ "snow3", 205, 201, 201 }, +{ "snow4", 139, 137, 137 }, +{ "seashell1", 255, 245, 238 }, +{ "seashell2", 238, 229, 222 }, +{ "seashell3", 205, 197, 191 }, +{ "seashell4", 139, 134, 130 }, +{ "AntiqueWhite1", 255, 239, 219 }, +{ "AntiqueWhite2", 238, 223, 204 }, +{ "AntiqueWhite3", 205, 192, 176 }, +{ "AntiqueWhite4", 139, 131, 120 }, +{ "bisque1", 255, 228, 196 }, +{ "bisque2", 238, 213, 183 }, +{ "bisque3", 205, 183, 158 }, +{ "bisque4", 139, 125, 107 }, +{ "PeachPuff1", 255, 218, 185 }, +{ "PeachPuff2", 238, 203, 173 }, +{ "PeachPuff3", 205, 175, 149 }, +{ "PeachPuff4", 139, 119, 101 }, +{ "NavajoWhite1", 255, 222, 173 }, +{ "NavajoWhite2", 238, 207, 161 }, +{ "NavajoWhite3", 205, 179, 139 }, +{ "NavajoWhite4", 139, 121, 94 }, +{ "LemonChiffon1", 255, 250, 205 }, +{ "LemonChiffon2", 238, 233, 191 }, +{ "LemonChiffon3", 205, 201, 165 }, +{ "LemonChiffon4", 139, 137, 112 }, +{ "cornsilk1", 255, 248, 220 }, +{ "cornsilk2", 238, 232, 205 }, +{ "cornsilk3", 205, 200, 177 }, +{ "cornsilk4", 139, 136, 120 }, +{ "ivory1", 255, 255, 240 }, +{ "ivory2", 238, 238, 224 }, +{ "ivory3", 205, 205, 193 }, +{ "ivory4", 139, 139, 131 }, +{ "honeydew1", 240, 255, 240 }, +{ "honeydew2", 224, 238, 224 }, +{ "honeydew3", 193, 205, 193 }, +{ "honeydew4", 131, 139, 131 }, +{ "LavenderBlush1", 255, 240, 245 }, +{ "LavenderBlush2", 238, 224, 229 }, +{ "LavenderBlush3", 205, 193, 197 }, +{ "LavenderBlush4", 139, 131, 134 }, +{ "MistyRose1", 255, 228, 225 }, +{ "MistyRose2", 238, 213, 210 }, +{ "MistyRose3", 205, 183, 181 }, +{ "MistyRose4", 139, 125, 123 }, +{ "azure1", 240, 255, 255 }, +{ "azure2", 224, 238, 238 }, +{ "azure3", 193, 205, 205 }, +{ "azure4", 131, 139, 139 }, +{ "SlateBlue1", 131, 111, 255 }, +{ "SlateBlue2", 122, 103, 238 }, +{ "SlateBlue3", 105, 89, 205 }, +{ "SlateBlue4", 71, 60, 139 }, +{ "RoyalBlue1", 72, 118, 255 }, +{ "RoyalBlue2", 67, 110, 238 }, +{ "RoyalBlue3", 58, 95, 205 }, +{ "RoyalBlue4", 39, 64, 139 }, +{ "blue1", 0, 0, 255 }, +{ "blue2", 0, 0, 238 }, +{ "blue3", 0, 0, 205 }, +{ "blue4", 0, 0, 139 }, +{ "DodgerBlue1", 30, 144, 255 }, +{ "DodgerBlue2", 28, 134, 238 }, +{ "DodgerBlue3", 24, 116, 205 }, +{ "DodgerBlue4", 16, 78, 139 }, +{ "SteelBlue1", 99, 184, 255 }, +{ "SteelBlue2", 92, 172, 238 }, +{ "SteelBlue3", 79, 148, 205 }, +{ "SteelBlue4", 54, 100, 139 }, +{ "DeepSkyBlue1", 0, 191, 255 }, +{ "DeepSkyBlue2", 0, 178, 238 }, +{ "DeepSkyBlue3", 0, 154, 205 }, +{ "DeepSkyBlue4", 0, 104, 139 }, +{ "SkyBlue1", 135, 206, 255 }, +{ "SkyBlue2", 126, 192, 238 }, +{ "SkyBlue3", 108, 166, 205 }, +{ "SkyBlue4", 74, 112, 139 }, +{ "LightSkyBlue1", 176, 226, 255 }, +{ "LightSkyBlue2", 164, 211, 238 }, +{ "LightSkyBlue3", 141, 182, 205 }, +{ "LightSkyBlue4", 96, 123, 139 }, +{ "SlateGray1", 198, 226, 255 }, +{ "SlateGray2", 185, 211, 238 }, +{ "SlateGray3", 159, 182, 205 }, +{ "SlateGray4", 108, 123, 139 }, +{ "LightSteelBlue1", 202, 225, 255 }, +{ "LightSteelBlue2", 188, 210, 238 }, +{ "LightSteelBlue3", 162, 181, 205 }, +{ "LightSteelBlue4", 110, 123, 139 }, +{ "LightBlue1", 191, 239, 255 }, +{ "LightBlue2", 178, 223, 238 }, +{ "LightBlue3", 154, 192, 205 }, +{ "LightBlue4", 104, 131, 139 }, +{ "LightCyan1", 224, 255, 255 }, +{ "LightCyan2", 209, 238, 238 }, +{ "LightCyan3", 180, 205, 205 }, +{ "LightCyan4", 122, 139, 139 }, +{ "PaleTurquoise1", 187, 255, 255 }, +{ "PaleTurquoise2", 174, 238, 238 }, +{ "PaleTurquoise3", 150, 205, 205 }, +{ "PaleTurquoise4", 102, 139, 139 }, +{ "CadetBlue1", 152, 245, 255 }, +{ "CadetBlue2", 142, 229, 238 }, +{ "CadetBlue3", 122, 197, 205 }, +{ "CadetBlue4", 83, 134, 139 }, +{ "turquoise1", 0, 245, 255 }, +{ "turquoise2", 0, 229, 238 }, +{ "turquoise3", 0, 197, 205 }, +{ "turquoise4", 0, 134, 139 }, +{ "cyan1", 0, 255, 255 }, +{ "cyan2", 0, 238, 238 }, +{ "cyan3", 0, 205, 205 }, +{ "cyan4", 0, 139, 139 }, +{ "DarkSlateGray1", 151, 255, 255 }, +{ "DarkSlateGray2", 141, 238, 238 }, +{ "DarkSlateGray3", 121, 205, 205 }, +{ "DarkSlateGray4", 82, 139, 139 }, +{ "aquamarine1", 127, 255, 212 }, +{ "aquamarine2", 118, 238, 198 }, +{ "aquamarine3", 102, 205, 170 }, +{ "aquamarine4", 69, 139, 116 }, +{ "DarkSeaGreen1", 193, 255, 193 }, +{ "DarkSeaGreen2", 180, 238, 180 }, +{ "DarkSeaGreen3", 155, 205, 155 }, +{ "DarkSeaGreen4", 105, 139, 105 }, +{ "SeaGreen1", 84, 255, 159 }, +{ "SeaGreen2", 78, 238, 148 }, +{ "SeaGreen3", 67, 205, 128 }, +{ "SeaGreen4", 46, 139, 87 }, +{ "PaleGreen1", 154, 255, 154 }, +{ "PaleGreen2", 144, 238, 144 }, +{ "PaleGreen3", 124, 205, 124 }, +{ "PaleGreen4", 84, 139, 84 }, +{ "SpringGreen1", 0, 255, 127 }, +{ "SpringGreen2", 0, 238, 118 }, +{ "SpringGreen3", 0, 205, 102 }, +{ "SpringGreen4", 0, 139, 69 }, +{ "green1", 0, 255, 0 }, +{ "green2", 0, 238, 0 }, +{ "green3", 0, 205, 0 }, +{ "green4", 0, 139, 0 }, +{ "chartreuse1", 127, 255, 0 }, +{ "chartreuse2", 118, 238, 0 }, +{ "chartreuse3", 102, 205, 0 }, +{ "chartreuse4", 69, 139, 0 }, +{ "OliveDrab1", 192, 255, 62 }, +{ "OliveDrab2", 179, 238, 58 }, +{ "OliveDrab3", 154, 205, 50 }, +{ "OliveDrab4", 105, 139, 34 }, +{ "DarkOliveGreen1", 202, 255, 112 }, +{ "DarkOliveGreen2", 188, 238, 104 }, +{ "DarkOliveGreen3", 162, 205, 90 }, +{ "DarkOliveGreen4", 110, 139, 61 }, +{ "khaki1", 255, 246, 143 }, +{ "khaki2", 238, 230, 133 }, +{ "khaki3", 205, 198, 115 }, +{ "khaki4", 139, 134, 78 }, +{ "LightGoldenrod1", 255, 236, 139 }, +{ "LightGoldenrod2", 238, 220, 130 }, +{ "LightGoldenrod3", 205, 190, 112 }, +{ "LightGoldenrod4", 139, 129, 76 }, +{ "LightYellow1", 255, 255, 224 }, +{ "LightYellow2", 238, 238, 209 }, +{ "LightYellow3", 205, 205, 180 }, +{ "LightYellow4", 139, 139, 122 }, +{ "yellow1", 255, 255, 0 }, +{ "yellow2", 238, 238, 0 }, +{ "yellow3", 205, 205, 0 }, +{ "yellow4", 139, 139, 0 }, +{ "gold1", 255, 215, 0 }, +{ "gold2", 238, 201, 0 }, +{ "gold3", 205, 173, 0 }, +{ "gold4", 139, 117, 0 }, +{ "goldenrod1", 255, 193, 37 }, +{ "goldenrod2", 238, 180, 34 }, +{ "goldenrod3", 205, 155, 29 }, +{ "goldenrod4", 139, 105, 20 }, +{ "DarkGoldenrod1", 255, 185, 15 }, +{ "DarkGoldenrod2", 238, 173, 14 }, +{ "DarkGoldenrod3", 205, 149, 12 }, +{ "DarkGoldenrod4", 139, 101, 8 }, +{ "RosyBrown1", 255, 193, 193 }, +{ "RosyBrown2", 238, 180, 180 }, +{ "RosyBrown3", 205, 155, 155 }, +{ "RosyBrown4", 139, 105, 105 }, +{ "IndianRed1", 255, 106, 106 }, +{ "IndianRed2", 238, 99, 99 }, +{ "IndianRed3", 205, 85, 85 }, +{ "IndianRed4", 139, 58, 58 }, +{ "sienna1", 255, 130, 71 }, +{ "sienna2", 238, 121, 66 }, +{ "sienna3", 205, 104, 57 }, +{ "sienna4", 139, 71, 38 }, +{ "burlywood1", 255, 211, 155 }, +{ "burlywood2", 238, 197, 145 }, +{ "burlywood3", 205, 170, 125 }, +{ "burlywood4", 139, 115, 85 }, +{ "wheat1", 255, 231, 186 }, +{ "wheat2", 238, 216, 174 }, +{ "wheat3", 205, 186, 150 }, +{ "wheat4", 139, 126, 102 }, +{ "tan1", 255, 165, 79 }, +{ "tan2", 238, 154, 73 }, +{ "tan3", 205, 133, 63 }, +{ "tan4", 139 , 90, 43 }, +{ "chocolate1", 255, 127, 36 }, +{ "chocolate2", 238, 118, 33 }, +{ "chocolate3", 205, 102, 29 }, +{ "chocolate4", 139, 69, 19 }, +{ "firebrick1", 255, 48, 48 }, +{ "firebrick2", 238, 44, 44 }, +{ "firebrick3", 205, 38, 38 }, +{ "firebrick4", 139, 26, 26 }, +{ "brown1", 255, 64, 64 }, +{ "brown2", 238, 59, 59 }, +{ "brown3", 205, 51, 51 }, +{ "brown4", 139, 35, 35 }, +{ "salmon1", 255, 140, 105 }, +{ "salmon2", 238, 130, 98 }, +{ "salmon3", 205, 112, 84 }, +{ "salmon4", 139, 76, 57 }, +{ "LightSalmon1", 255, 160, 122 }, +{ "LightSalmon2", 238, 149, 114 }, +{ "LightSalmon3", 205, 129, 98 }, +{ "LightSalmon4", 139, 87, 66 }, +{ "orange1", 255, 165, 0 }, +{ "orange2", 238, 154, 0 }, +{ "orange3", 205, 133, 0 }, +{ "orange4", 139 , 90, 0 }, +{ "DarkOrange1", 255, 127, 0 }, +{ "DarkOrange2", 238, 118, 0 }, +{ "DarkOrange3", 205, 102, 0 }, +{ "DarkOrange4", 139 , 69, 0 }, +{ "coral1", 255, 114, 86 }, +{ "coral2", 238, 106, 80 }, +{ "coral3", 205, 91, 69 }, +{ "coral4", 139, 62, 47 }, +{ "tomato1", 255, 99, 71 }, +{ "tomato2", 238, 92, 66 }, +{ "tomato3", 205, 79, 57 }, +{ "tomato4", 139, 54, 38 }, +{ "OrangeRed1", 255, 69, 0 }, +{ "OrangeRed2", 238, 64, 0 }, +{ "OrangeRed3", 205, 55, 0 }, +{ "OrangeRed4", 139, 37, 0 }, +{ "red1", 255, 0, 0 }, +{ "red2", 238, 0, 0 }, +{ "red3", 205, 0, 0 }, +{ "red4", 139, 0, 0 }, +{ "DeepPink1", 255, 20, 147 }, +{ "DeepPink2", 238, 18, 137 }, +{ "DeepPink3", 205, 16, 118 }, +{ "DeepPink4", 139, 10, 80 }, +{ "HotPink1", 255, 110, 180 }, +{ "HotPink2", 238, 106, 167 }, +{ "HotPink3", 205, 96, 144 }, +{ "HotPink4", 139, 58, 98 }, +{ "pink1", 255, 181, 197 }, +{ "pink2", 238, 169, 184 }, +{ "pink3", 205, 145, 158 }, +{ "pink4", 139, 99, 108 }, +{ "LightPink1", 255, 174, 185 }, +{ "LightPink2", 238, 162, 173 }, +{ "LightPink3", 205, 140, 149 }, +{ "LightPink4", 139, 95, 101 }, +{ "PaleVioletRed1", 255, 130, 171 }, +{ "PaleVioletRed2", 238, 121, 159 }, +{ "PaleVioletRed3", 205, 104, 137 }, +{ "PaleVioletRed4", 139, 71, 93 }, +{ "maroon1", 255, 52, 179 }, +{ "maroon2", 238, 48, 167 }, +{ "maroon3", 205, 41, 144 }, +{ "maroon4", 139, 28, 98 }, +{ "VioletRed1", 255, 62, 150 }, +{ "VioletRed2", 238, 58, 140 }, +{ "VioletRed3", 205, 50, 120 }, +{ "VioletRed4", 139, 34, 82 }, +{ "magenta1", 255, 0, 255 }, +{ "magenta2", 238, 0, 238 }, +{ "magenta3", 205, 0, 205 }, +{ "magenta4", 139, 0, 139 }, +{ "orchid1", 255, 131, 250 }, +{ "orchid2", 238, 122, 233 }, +{ "orchid3", 205, 105, 201 }, +{ "orchid4", 139, 71, 137 }, +{ "plum1", 255, 187, 255 }, +{ "plum2", 238, 174, 238 }, +{ "plum3", 205, 150, 205 }, +{ "plum4", 139, 102, 139 }, +{ "MediumOrchid1", 224, 102, 255 }, +{ "MediumOrchid2", 209, 95, 238 }, +{ "MediumOrchid3", 180, 82, 205 }, +{ "MediumOrchid4", 122, 55, 139 }, +{ "DarkOrchid1", 191, 62, 255 }, +{ "DarkOrchid2", 178, 58, 238 }, +{ "DarkOrchid3", 154, 50, 205 }, +{ "DarkOrchid4", 104, 34, 139 }, +{ "purple1", 155, 48, 255 }, +{ "purple2", 145, 44, 238 }, +{ "purple3", 125, 38, 205 }, +{ "purple4", 85, 26, 139 }, +{ "MediumPurple1", 171, 130, 255 }, +{ "MediumPurple2", 159, 121, 238 }, +{ "MediumPurple3", 137, 104, 205 }, +{ "MediumPurple4", 93, 71, 139 }, +{ "thistle1", 255, 225, 255 }, +{ "thistle2", 238, 210, 238 }, +{ "thistle3", 205, 181, 205 }, +{ "thistle4", 139, 123, 139 }, +{ "gray0", 0, 0, 0 }, +{ "grey0", 0, 0, 0 }, +{ "gray1", 3, 3, 3 }, +{ "grey1", 3, 3, 3 }, +{ "gray2", 5, 5, 5 }, +{ "grey2", 5, 5, 5 }, +{ "gray3", 8, 8, 8 }, +{ "grey3", 8, 8, 8 }, +{ "gray4", 10, 10, 10 }, +{ "grey4", 10, 10, 10 }, +{ "gray5", 13, 13, 13 }, +{ "grey5", 13, 13, 13 }, +{ "gray6", 15, 15, 15 }, +{ "grey6", 15, 15, 15 }, +{ "gray7", 18, 18, 18 }, +{ "grey7", 18, 18, 18 }, +{ "gray8", 20, 20, 20 }, +{ "grey8", 20, 20, 20 }, +{ "gray9", 23, 23, 23 }, +{ "grey9", 23, 23, 23 }, +{ "gray10", 26, 26, 26 }, +{ "grey10", 26, 26, 26 }, +{ "gray11", 28, 28, 28 }, +{ "grey11", 28, 28, 28 }, +{ "gray12", 31, 31, 31 }, +{ "grey12", 31, 31, 31 }, +{ "gray13", 33, 33, 33 }, +{ "grey13", 33, 33, 33 }, +{ "gray14", 36, 36, 36 }, +{ "grey14", 36, 36, 36 }, +{ "gray15", 38, 38, 38 }, +{ "grey15", 38, 38, 38 }, +{ "gray16", 41, 41, 41 }, +{ "grey16", 41, 41, 41 }, +{ "gray17", 43, 43, 43 }, +{ "grey17", 43, 43, 43 }, +{ "gray18", 46, 46, 46 }, +{ "grey18", 46, 46, 46 }, +{ "gray19", 48, 48, 48 }, +{ "grey19", 48, 48, 48 }, +{ "gray20", 51, 51, 51 }, +{ "grey20", 51, 51, 51 }, +{ "gray21", 54, 54, 54 }, +{ "grey21", 54, 54, 54 }, +{ "gray22", 56, 56, 56 }, +{ "grey22", 56, 56, 56 }, +{ "gray23", 59, 59, 59 }, +{ "grey23", 59, 59, 59 }, +{ "gray24", 61, 61, 61 }, +{ "grey24", 61, 61, 61 }, +{ "gray25", 64, 64, 64 }, +{ "grey25", 64, 64, 64 }, +{ "gray26", 66, 66, 66 }, +{ "grey26", 66, 66, 66 }, +{ "gray27", 69, 69, 69 }, +{ "grey27", 69, 69, 69 }, +{ "gray28", 71, 71, 71 }, +{ "grey28", 71, 71, 71 }, +{ "gray29", 74, 74, 74 }, +{ "grey29", 74, 74, 74 }, +{ "gray30", 77, 77, 77 }, +{ "grey30", 77, 77, 77 }, +{ "gray31", 79, 79, 79 }, +{ "grey31", 79, 79, 79 }, +{ "gray32", 82, 82, 82 }, +{ "grey32", 82, 82, 82 }, +{ "gray33", 84, 84, 84 }, +{ "grey33", 84, 84, 84 }, +{ "gray34", 87, 87, 87 }, +{ "grey34", 87, 87, 87 }, +{ "gray35", 89, 89, 89 }, +{ "grey35", 89, 89, 89 }, +{ "gray36", 92, 92, 92 }, +{ "grey36", 92, 92, 92 }, +{ "gray37", 94, 94, 94 }, +{ "grey37", 94, 94, 94 }, +{ "gray38", 97, 97, 97 }, +{ "grey38", 97, 97, 97 }, +{ "gray39", 99, 99, 99 }, +{ "grey39", 99, 99, 99 }, +{ "gray40", 102, 102, 102 }, +{ "grey40", 102, 102, 102 }, +{ "gray41", 105, 105, 105 }, +{ "grey41", 105, 105, 105 }, +{ "gray42", 107, 107, 107 }, +{ "grey42", 107, 107, 107 }, +{ "gray43", 110, 110, 110 }, +{ "grey43", 110, 110, 110 }, +{ "gray44", 112, 112, 112 }, +{ "grey44", 112, 112, 112 }, +{ "gray45", 115, 115, 115 }, +{ "grey45", 115, 115, 115 }, +{ "gray46", 117, 117, 117 }, +{ "grey46", 117, 117, 117 }, +{ "gray47", 120, 120, 120 }, +{ "grey47", 120, 120, 120 }, +{ "gray48", 122, 122, 122 }, +{ "grey48", 122, 122, 122 }, +{ "gray49", 125, 125, 125 }, +{ "grey49", 125, 125, 125 }, +{ "gray50", 127, 127, 127 }, +{ "grey50", 127, 127, 127 }, +{ "gray51", 130, 130, 130 }, +{ "grey51", 130, 130, 130 }, +{ "gray52", 133, 133, 133 }, +{ "grey52", 133, 133, 133 }, +{ "gray53", 135, 135, 135 }, +{ "grey53", 135, 135, 135 }, +{ "gray54", 138, 138, 138 }, +{ "grey54", 138, 138, 138 }, +{ "gray55", 140, 140, 140 }, +{ "grey55", 140, 140, 140 }, +{ "gray56", 143, 143, 143 }, +{ "grey56", 143, 143, 143 }, +{ "gray57", 145, 145, 145 }, +{ "grey57", 145, 145, 145 }, +{ "gray58", 148, 148, 148 }, +{ "grey58", 148, 148, 148 }, +{ "gray59", 150, 150, 150 }, +{ "grey59", 150, 150, 150 }, +{ "gray60", 153, 153, 153 }, +{ "grey60", 153, 153, 153 }, +{ "gray61", 156, 156, 156 }, +{ "grey61", 156, 156, 156 }, +{ "gray62", 158, 158, 158 }, +{ "grey62", 158, 158, 158 }, +{ "gray63", 161, 161, 161 }, +{ "grey63", 161, 161, 161 }, +{ "gray64", 163, 163, 163 }, +{ "grey64", 163, 163, 163 }, +{ "gray65", 166, 166, 166 }, +{ "grey65", 166, 166, 166 }, +{ "gray66", 168, 168, 168 }, +{ "grey66", 168, 168, 168 }, +{ "gray67", 171, 171, 171 }, +{ "grey67", 171, 171, 171 }, +{ "gray68", 173, 173, 173 }, +{ "grey68", 173, 173, 173 }, +{ "gray69", 176, 176, 176 }, +{ "grey69", 176, 176, 176 }, +{ "gray70", 179, 179, 179 }, +{ "grey70", 179, 179, 179 }, +{ "gray71", 181, 181, 181 }, +{ "grey71", 181, 181, 181 }, +{ "gray72", 184, 184, 184 }, +{ "grey72", 184, 184, 184 }, +{ "gray73", 186, 186, 186 }, +{ "grey73", 186, 186, 186 }, +{ "gray74", 189, 189, 189 }, +{ "grey74", 189, 189, 189 }, +{ "gray75", 191, 191, 191 }, +{ "grey75", 191, 191, 191 }, +{ "gray76", 194, 194, 194 }, +{ "grey76", 194, 194, 194 }, +{ "gray77", 196, 196, 196 }, +{ "grey77", 196, 196, 196 }, +{ "gray78", 199, 199, 199 }, +{ "grey78", 199, 199, 199 }, +{ "gray79", 201, 201, 201 }, +{ "grey79", 201, 201, 201 }, +{ "gray80", 204, 204, 204 }, +{ "grey80", 204, 204, 204 }, +{ "gray81", 207, 207, 207 }, +{ "grey81", 207, 207, 207 }, +{ "gray82", 209, 209, 209 }, +{ "grey82", 209, 209, 209 }, +{ "gray83", 212, 212, 212 }, +{ "grey83", 212, 212, 212 }, +{ "gray84", 214, 214, 214 }, +{ "grey84", 214, 214, 214 }, +{ "gray85", 217, 217, 217 }, +{ "grey85", 217, 217, 217 }, +{ "gray86", 219, 219, 219 }, +{ "grey86", 219, 219, 219 }, +{ "gray87", 222, 222, 222 }, +{ "grey87", 222, 222, 222 }, +{ "gray88", 224, 224, 224 }, +{ "grey88", 224, 224, 224 }, +{ "gray89", 227, 227, 227 }, +{ "grey89", 227, 227, 227 }, +{ "gray90", 229, 229, 229 }, +{ "grey90", 229, 229, 229 }, +{ "gray91", 232, 232, 232 }, +{ "grey91", 232, 232, 232 }, +{ "gray92", 235, 235, 235 }, +{ "grey92", 235, 235, 235 }, +{ "gray93", 237, 237, 237 }, +{ "grey93", 237, 237, 237 }, +{ "gray94", 240, 240, 240 }, +{ "grey94", 240, 240, 240 }, +{ "gray95", 242, 242, 242 }, +{ "grey95", 242, 242, 242 }, +{ "gray96", 245, 245, 245 }, +{ "grey96", 245, 245, 245 }, +{ "gray97", 247, 247, 247 }, +{ "grey97", 247, 247, 247 }, +{ "gray98", 250, 250, 250 }, +{ "grey98", 250, 250, 250 }, +{ "gray99", 252, 252, 252 }, +{ "grey99", 252, 252, 252 }, +{ "gray100", 255, 255, 255 }, +{ "grey100", 255, 255, 255 }, +{ "DarkGrey", 169, 169, 169 }, +{ "DarkGray", 169, 169, 169 }, +{ "DarkBlue", 0, 0, 139 }, +{ "DarkCyan", 0, 139, 139 }, +{ "DarkMagenta", 139, 0, 139 }, +{ "DarkRed", 139, 0, 0 }, +{ "LightGreen", 144, 238, 144 }, +{ NULL, 0 , 0, 0} +}; diff --git a/svtools/source/filter/ixpm/xpmread.cxx b/svtools/source/filter/ixpm/xpmread.cxx new file mode 100644 index 000000000000..7575c94e3ed9 --- /dev/null +++ b/svtools/source/filter/ixpm/xpmread.cxx @@ -0,0 +1,702 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#ifndef _BMPACC_HXX +#include +#endif +#ifndef _GRAPH_HXX +#include +#endif +#include "rgbtable.hxx" +#define _XPMPRIVATE +#include "xpmread.hxx" + +// ------------- +// - XPMReader - +// ------------- + +XPMReader::XPMReader( SvStream& rStm ) : + mrIStm ( rStm ), + mpAcc ( NULL ), + mpMaskAcc ( NULL ), + mnLastPos ( rStm.Tell() ), + mnWidth ( 0 ), + mnHeight ( 0 ), + mnColors ( 0 ), + mnCpp ( 0 ), + mbTransparent ( FALSE ), + mbStatus ( TRUE ), + mnStatus ( 0 ), + mnIdentifier ( XPMIDENTIFIER ), + mcThisByte ( 0 ), + mnTempAvail ( 0 ), + mpFastColorTable( NULL ), + mpColMap ( NULL ) +{ + +} + +// ------------------------------------------------------------------------ + +XPMReader::~XPMReader() +{ + if( mpAcc ) + maBmp.ReleaseAccess( mpAcc ); +} + +// ------------------------------------------------------------------------ + +#ifdef _MSC_VER +#pragma optimize ("",off) +#endif + +ReadState XPMReader::ReadXPM( Graphic& rGraphic ) +{ + ReadState eReadState; + BYTE cDummy; + + // sehen, ob wir _alles_ lesen koennen + mrIStm.Seek( STREAM_SEEK_TO_END ); + mrIStm >> cDummy; + + // falls wir nicht alles lesen koennen + // kehren wir zurueck und warten auf neue Daten + if ( mrIStm.GetError() != ERRCODE_IO_PENDING ) + { + mrIStm.Seek( mnLastPos ); + mbStatus = TRUE; + + if ( mbStatus ) + { + mpStringBuf = new BYTE [ XPMSTRINGBUF ]; + mpTempBuf = new BYTE [ XPMTEMPBUFSIZE ]; + + if ( ( mbStatus = ImplGetString() ) == TRUE ) + { + mnIdentifier = XPMVALUES; // Bitmap informationen einholen + mnWidth = ImplGetULONG( 0 ); + mnHeight = ImplGetULONG( 1 ); + mnColors = ImplGetULONG( 2 ); + mnCpp = ImplGetULONG( 3 ); + } + if ( mnColors > ( SAL_MAX_UINT32 / ( 4 + mnCpp ) ) ) + mbStatus = sal_False; + if ( ( mnWidth * mnCpp ) >= XPMSTRINGBUF ) + mbStatus = sal_False; + if ( mbStatus && mnWidth && mnHeight && mnColors && mnCpp ) + { + mnIdentifier = XPMCOLORS; + + // mpColMap beinhaltet fuer jede vorhandene + // Farbe: ( mnCpp )Byte(s)-> ASCII Eintrag der der Farbe zugeordnet ist + // 1 Byte -> 0xff wenn Farbe transparent ist + // 3 Bytes -> RGB Wert der Farbe + mpColMap = new BYTE[ mnColors * ( 4 + mnCpp ) ]; + if ( mpColMap ) + { + for ( ULONG i = 0; i < mnColors; i++ ) + { + if ( ImplGetColor( i ) == FALSE ) + { + mbStatus = FALSE; + break; + } + } + } + else + mbStatus = sal_False; + + if ( mbStatus ) + { + // bei mehr als 256 Farben wird eine 24 Bit Grafik erstellt + sal_uInt16 nBits = 1; + if ( mnColors > 256 ) + nBits = 24; + else if ( mnColors > 16 ) + nBits = 8; + else if ( mnColors > 2 ) + nBits = 4; + else + nBits = 1; + + maBmp = Bitmap( Size( mnWidth, mnHeight ), nBits ); + mpAcc = maBmp.AcquireWriteAccess(); + + // mbTransparent ist TRUE wenn mindestens eine Farbe Transparent ist + if ( mbTransparent ) + { + maMaskBmp = Bitmap( Size( mnWidth, mnHeight ), 1 ); + if ( ( mpMaskAcc = maMaskBmp.AcquireWriteAccess() ) == NULL ) + mbStatus = FALSE; + } + if( mpAcc && mbStatus ) + { + ULONG i; + if ( mnColors <=256 ) // palette is only needed by using less than 257 + { // colors + + BYTE* pPtr = &mpColMap[mnCpp]; + + for ( i = 0; i < mnColors; i++ ) + { + mpAcc->SetPaletteColor( (BYTE)i, Color( pPtr[1], pPtr[2], pPtr[3] ) ); + pPtr += ( mnCpp + 4 ); + } + // using 2 charakters per pixel and less than 257 Colors we speed up + if ( mnCpp == 2 ) // by using a 64kb indexing table + { + mpFastColorTable = new BYTE[ 256 * 256 ]; + for ( pPtr = mpColMap, i = 0; i < mnColors; i++, pPtr += mnCpp + 4 ) + { + ULONG j = pPtr[ 0 ] << 8; + j += pPtr[ 1 ]; + mpFastColorTable[ j ] = (BYTE)i; + } + } + } + // now we get the bitmap data + mnIdentifier = XPMPIXELS; + for ( i = 0; i < mnHeight; i++ ) + { + if ( ImplGetScanLine( i ) == FALSE ) + { + mbStatus = FALSE; + break; + } + } + mnIdentifier = XPMEXTENSIONS; + } + } + } + + delete[] mpFastColorTable; + delete[] mpColMap; + delete[] mpStringBuf; + delete[] mpTempBuf; + + } + if( mbStatus ) + { + if ( mpMaskAcc ) + { + maMaskBmp.ReleaseAccess ( mpMaskAcc), mpMaskAcc = NULL; + maBmp.ReleaseAccess( mpAcc ), mpAcc = NULL; + rGraphic = Graphic( BitmapEx( maBmp, maMaskBmp ) ); + } + else + { + maBmp.ReleaseAccess( mpAcc ), mpAcc = NULL; + rGraphic = maBmp; + } + eReadState = XPMREAD_OK; + } + else + { + if ( mpMaskAcc ) maMaskBmp.ReleaseAccess ( mpMaskAcc), mpMaskAcc = NULL; + if ( mpAcc ) maBmp.ReleaseAccess( mpAcc ), mpAcc = NULL; + eReadState = XPMREAD_ERROR; + } + } + else + { + mrIStm.ResetError(); + eReadState = XPMREAD_NEED_MORE; + } + return eReadState; +} + +#ifdef _MSC_VER +#pragma optimize ("",on) +#endif + +// ------------------------------------------------------------------------ +// ImplGetColor ermittelt saemtliche Farbwerte, +// die Rueckgabe ist TRUE wenn saemtliche Farben zugeordnet werden konnten + +BOOL XPMReader::ImplGetColor( ULONG nNumb ) +{ + BYTE* pString = mpStringBuf; + BYTE* pPtr = ( mpColMap + nNumb * ( 4 + mnCpp ) ); + BOOL bStatus = ImplGetString(); + + if ( bStatus ) + { + for ( ULONG i = 0; i < mnCpp; i++ ) + *pPtr++ = *pString++; + bStatus = ImplGetColSub ( pPtr ); + } + return bStatus; +} + +// ------------------------------------------------------------------------ +// ImpGetScanLine liest den String mpBufSize aus und schreibt die Pixel in die +// Bitmap. Der Parameter nY gibt die horizontale Position an. + +BOOL XPMReader::ImplGetScanLine( ULONG nY ) +{ + BOOL bStatus = ImplGetString(); + BYTE* pString = mpStringBuf; + BYTE* pColor; + BitmapColor aWhite; + BitmapColor aBlack; + + if ( bStatus ) + { + if ( mpMaskAcc ) + { + aWhite = mpMaskAcc->GetBestMatchingColor( Color( COL_WHITE ) ); + aBlack = mpMaskAcc->GetBestMatchingColor( Color( COL_BLACK ) ); + } + if ( mnStringSize != ( mnWidth * mnCpp )) + bStatus = FALSE; + else + { + ULONG i, j; + if ( mpFastColorTable ) + { + for ( i = 0; i < mnWidth; i++ ) + { + j = (*pString++) << 8; + j += *pString++; + BYTE k = (BYTE)mpFastColorTable[ j ]; + mpAcc->SetPixel( nY, i, BitmapColor( (BYTE)k ) ); + + if ( mpMaskAcc ) + mpMaskAcc->SetPixel( nY, i, + ( mpColMap[ k * (mnCpp + 4) + mnCpp] ) ? aWhite : aBlack ); + } + } + else for ( i = 0; i < mnWidth; i++ ) + { + pColor = mpColMap; + for ( j = 0; j < mnColors; j++ ) + { + if ( ImplCompare( pString, pColor, mnCpp, XPMCASESENSITIVE ) == TRUE ) + { + if ( mnColors > 256 ) + mpAcc->SetPixel( nY, i, Color ( pColor[3], pColor[4], pColor[5] ) ); + else + mpAcc->SetPixel( nY, i, BitmapColor( (BYTE) j ) ); + + if ( mpMaskAcc ) + mpMaskAcc->SetPixel( nY, i, ( + pColor[ mnCpp ] ) ? aWhite : aBlack ); + + break; + } + pColor += ( mnCpp + 4 ); + } + pString += mnCpp; + } + + } + } + return bStatus; +} + +// ------------------------------------------------------------------------ +// versucht aus mpStringBuf einen Farbwert zu uebermitteln +// wurde eine Farbe gefunden wird an pDest[1]..pDest[2] der RGB wert geschrieben +// pDest[0] enthaelt 0xff wenn die Farbe transparent ist sonst 0 + +BOOL XPMReader::ImplGetColSub( BYTE* pDest ) +{ + unsigned char cTransparent[] = "None"; + + BOOL bColStatus = FALSE; + + if ( ImplGetColKey( 'c' ) || ImplGetColKey( 'm' ) || ImplGetColKey( 'g' ) ) + { + // hexentry for RGB or HSV color ? + if ( *mpPara == '#' ) + { + *pDest++ = 0; + bColStatus = TRUE; + switch ( mnParaSize ) + { + case 25 : + ImplGetRGBHex ( pDest, 6 ); + break; + case 13 : + ImplGetRGBHex ( pDest, 2 ); + break; + case 7 : + ImplGetRGBHex ( pDest, 0 ); + break; + default: + bColStatus = FALSE; + break; + } + } + // maybe pixel is transparent + else if ( ImplCompare( &cTransparent[0], mpPara, 4 )) + { + *pDest++ = 0xff; + bColStatus = TRUE; + mbTransparent = TRUE; + } + // last we will try to get the colorname + else if ( mnParaSize > 2 ) // name must enlarge the minimum size + { + ULONG i = 0; + while ( TRUE ) + { + if ( pRGBTable[ i ].name == NULL ) + break; + if ( pRGBTable[ i ].name[ mnParaSize ] == 0 ) + { + if ( ImplCompare ( (unsigned char*)pRGBTable[ i ].name, + mpPara, mnParaSize, XPMCASENONSENSITIVE ) ) + { + bColStatus = TRUE; + *pDest++ = 0; + *pDest++ = pRGBTable[ i ].red; + *pDest++ = pRGBTable[ i ].green; + *pDest++ = pRGBTable[ i ].blue; + } + } + i++; + } + } + } + return bColStatus; +} + +// ------------------------------------------------------------------------ +// ImplGetColKey durchsuch den String mpStringBuf nach einem Parameter 'nKey' +// und gibt einen BOOL zurueck. ( wenn TRUE werden mpPara und mnParaSize gesetzt ) + +BOOL XPMReader::ImplGetColKey( BYTE nKey ) +{ + BYTE nTemp, nPrev = ' '; + + mpPara = mpStringBuf + mnCpp + 1; + mnParaSize = 0; + + while ( *mpPara != 0 ) + { + if ( *mpPara == nKey ) + { + nTemp = *( mpPara + 1 ); + if ( nTemp == ' ' || nTemp == 0x09 ) + { + if ( nPrev == ' ' || nPrev == 0x09 ) + break; + } + } + nPrev = *mpPara; + mpPara++; + } + if ( *mpPara ) + { + mpPara++; + while ( (*mpPara == ' ') || (*mpPara == 0x09) ) + { + mpPara++; + } + if ( *mpPara != 0 ) + { + while ( *(mpPara+mnParaSize) != ' ' && *(mpPara+mnParaSize) != 0x09 && + *(mpPara+mnParaSize) != 0 ) + { + mnParaSize++; + } + } + } + return ( mnParaSize ) ? TRUE : FALSE; +} + +// ------------------------------------------------------------------------ +// ImplGetRGBHex uebersetzt den ASCII-Hexadezimalwert der sich bei mpPara befindet +// in einen RGB wert und schreibt diesen nach pDest +// folgende Formate muessen sich bei mpPara befinden: +// wenn nAdd = 0 : '#12ab12' -> RGB = 0x12, 0xab, 0x12 +// 2 : '#1234abcd1234' " " " " +// 6 : '#12345678abcdefab12345678' " " " " + + +void XPMReader::ImplGetRGBHex( BYTE* pDest,ULONG nAdd ) +{ + BYTE* pPtr = mpPara+1; + BYTE nHex, nTemp; + + for ( ULONG i = 0; i < 3; i++ ) + { + nHex = (*pPtr++) - '0'; + if ( nHex > 9 ) + nHex = ((nHex - 'A' + '0') & 7) + 10; + + nTemp = (*pPtr++) - '0'; + if ( nTemp > 9 ) + nTemp = ((nTemp - 'A' + '0') & 7) + 10; + nHex = ( nHex << 4 ) + nTemp; + + pPtr += nAdd; + *pDest++ = (BYTE)nHex; + } +} + +// ------------------------------------------------------------------------ +// ImplGetUlong gibt den wert einer bis zu 6stelligen ASCII-Dezimalzahl zurueck. + +ULONG XPMReader::ImplGetULONG( ULONG nPara ) +{ + if ( ImplGetPara ( nPara ) ) + { + ULONG nRetValue = 0; + BYTE* pPtr = mpPara; + + if ( ( mnParaSize > 6 ) || ( mnParaSize == 0 ) ) return 0; + for ( ULONG i = 0; i < mnParaSize; i++ ) + { + BYTE j = (*pPtr++) - 48; + if ( j > 9 ) return 0; // ascii is invalid + nRetValue*=10; + nRetValue+=j; + } + return nRetValue; + } + else return 0; +} + +// ------------------------------------------------------------------------ + +BOOL XPMReader::ImplCompare( BYTE* pSource, BYTE* pDest, ULONG nSize, ULONG nMode ) +{ + BOOL bRet = TRUE; + + if ( nMode == XPMCASENONSENSITIVE ) + { + for ( ULONG i = 0; i < nSize; i++ ) + { + if ( ( pSource[i]&~0x20 ) != ( pDest[i]&~0x20 ) ) + { + bRet = FALSE; + break; + } + } + } + else + { + for ( ULONG i = 0; i < nSize; i++ ) + { + if ( pSource[i] != pDest[i] ) + { + bRet = FALSE; + break; + } + } + } + return bRet; +} + +// ------------------------------------------------------------------------ +// ImplGetPara versucht den nNumb ( 0...x ) Parameter aus mpStringBuf zu ermitteln. +// Ein Parameter ist durch Spaces oder Tabs von den anderen getrennt. +// Konnte der Parameter gefunden werden ist der Rueckgabewert TRUE und mpPara + mnParaSize +// werden gesetzt. + +BOOL XPMReader::ImplGetPara ( ULONG nNumb ) +{ + BYTE nByte; + ULONG pSize = 0; + BYTE* pPtr = mpStringBuf; + ULONG nCount = 0; + + if ( ( *pPtr != ' ' ) && ( *pPtr != 0x09 ) ) + { + mpPara = pPtr; + mnParaSize = 0; + nCount = 0; + } + else + { + mpPara = NULL; + nCount = 0xffffffff; + } + + while ( pSize < mnStringSize ) + { + nByte = *pPtr; + + if ( mpPara ) + { + if ( ( nByte == ' ' ) || ( nByte == 0x09 ) ) + { + if ( nCount == nNumb ) + break; + else + mpPara = NULL; + } + else + mnParaSize++; + } + else + { + if ( ( nByte != ' ' ) && ( nByte != 0x09 ) ) + { + mpPara = pPtr; + mnParaSize = 1; + nCount++; + } + } + pSize++; + pPtr++; + } + return ( ( nCount == nNumb ) && ( mpPara ) ) ? TRUE : FALSE; +} + +// ------------------------------------------------------------------------ +// Der naechste String wird ausgelesen und in mpStringBuf (mit 0 abgeschlossen) abgelegt; +// mnStringSize enthaelt die Groesse des gelesenen Strings. +// Bemerkungen wie '//' und '/*.....*/' werden uebersprungen. + +BOOL XPMReader::ImplGetString( void ) +{ + BYTE sID[] = "/* XPM */"; + BYTE* pString = mpStringBuf; + + mnStringSize = 0; + mpStringBuf[0] = 0; + + while( mbStatus && ( mnStatus != XPMFINISHED ) ) + { + if ( mnTempAvail == 0 ) + { + mnTempAvail = mrIStm.Read( mpTempBuf, XPMTEMPBUFSIZE ); + if ( mnTempAvail == 0 ) + break; + + mpTempPtr = mpTempBuf; + + if ( mnIdentifier == XPMIDENTIFIER ) + { + if ( mnTempAvail <= 50 ) + { + mbStatus = FALSE; // file is too short to be a correct XPM format + break; + } + for ( int i = 0; i < 9; i++ ) // searching for "/* XPM */" + if ( *mpTempPtr++ != sID[i] ) + { + mbStatus = FALSE; + break; + } + mnTempAvail-=9; + mnIdentifier++; + } + } + mcLastByte = mcThisByte; + mcThisByte = *mpTempPtr++; + mnTempAvail--; + + if ( mnStatus & XPMDOUBLE ) + { + if ( mcThisByte == 0x0a ) + mnStatus &=~XPMDOUBLE; + continue; + } + if ( mnStatus & XPMREMARK ) + { + if ( ( mcThisByte == '/' ) && ( mcLastByte == '*' ) ) + mnStatus &=~XPMREMARK; + continue; + } + if ( mnStatus & XPMSTRING ) // characters in string + { + if ( mcThisByte == '"' ) + { + mnStatus &=~XPMSTRING; // end of parameter by eol + break; + } + if ( mnStringSize >= ( XPMSTRINGBUF - 1 ) ) + { + mbStatus = FALSE; + break; + } + *pString++ = mcThisByte; + pString[0] = 0; + mnStringSize++; + continue; + } + else + { // characters beside string + switch ( mcThisByte ) + { + case '*' : + if ( mcLastByte == '/' ) mnStatus |= XPMREMARK; + break; + case '/' : + if ( mcLastByte == '/' ) mnStatus |= XPMDOUBLE; + break; + case '"' : mnStatus |= XPMSTRING; + break; + case '{' : + if ( mnIdentifier == XPMDEFINITION ) + mnIdentifier++; + break; + case '}' : + if ( mnIdentifier == XPMENDEXT ) + mnStatus = XPMFINISHED; + break; + } + } + } + return mbStatus; +} + +// ------------- +// - ImportXPM - +// ------------- + +BOOL ImportXPM( SvStream& rStm, Graphic& rGraphic ) +{ + XPMReader* pXPMReader = (XPMReader*) rGraphic.GetContext(); + ReadState eReadState; + BOOL bRet = TRUE; + + if( !pXPMReader ) + pXPMReader = new XPMReader( rStm ); + + rGraphic.SetContext( NULL ); + eReadState = pXPMReader->ReadXPM( rGraphic ); + + if( eReadState == XPMREAD_ERROR ) + { + bRet = FALSE; + delete pXPMReader; + } + else if( eReadState == XPMREAD_OK ) + delete pXPMReader; + else + rGraphic.SetContext( pXPMReader ); + + return bRet; +} diff --git a/svtools/source/filter/jpeg/jpeg.cxx b/svtools/source/filter/jpeg/jpeg.cxx new file mode 100644 index 000000000000..a2de92171af3 --- /dev/null +++ b/svtools/source/filter/jpeg/jpeg.cxx @@ -0,0 +1,779 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include + +extern "C" +{ + #define INT32 JPEG_INT32 + #include "stdio.h" + #include "jpeg.h" + #include "jpeglib.h" + #include "jerror.h" + #undef INT32 +} + +#define _JPEGPRIVATE +#include +#include "jpeg.hxx" +#include +#include + +// ----------- +// - Defines - +// ----------- + +using namespace ::com::sun::star; + +#define JPEGMINREAD 512 + +// ------------- +// - (C-Calls) - +// ------------- + +// ------------------------------------------------------------------------ + +extern "C" void* CreateBitmap( void* pJPEGReader, void* pJPEGCreateBitmapParam ) +{ + return ( (JPEGReader*) pJPEGReader )->CreateBitmap( pJPEGCreateBitmapParam ); +} + +// ------------------------------------------------------------------------ + +extern "C" void* GetScanline( void* pJPEGWriter, long nY ) +{ + return ( (JPEGWriter*) pJPEGWriter )->GetScanline( nY ); +} + +// ------------------------------------------------------------------------ + +struct JPEGCallbackStruct +{ + uno::Reference< task::XStatusIndicator > xStatusIndicator; +}; + +extern "C" long JPEGCallback( void* pCallbackData, long nPercent ) +{ + JPEGCallbackStruct* pS = (JPEGCallbackStruct*)pCallbackData; + if ( pS && pS->xStatusIndicator.is() ) + { + pS->xStatusIndicator->setValue( nPercent ); + } + return 0L; +} + +#define BUF_SIZE 4096 + +typedef struct +{ + struct jpeg_destination_mgr pub; /* public fields */ + + SvStream* outfile; /* target stream */ + JOCTET * buffer; /* start of buffer */ +} my_destination_mgr; + +typedef my_destination_mgr * my_dest_ptr; + +extern "C" void init_destination (j_compress_ptr cinfo) +{ + my_dest_ptr dest = (my_dest_ptr) cinfo->dest; + + /* Allocate the output buffer --- it will be released when done with image */ + dest->buffer = (JOCTET *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + BUF_SIZE * sizeof(JOCTET)); + + dest->pub.next_output_byte = dest->buffer; + dest->pub.free_in_buffer = BUF_SIZE; +} + +extern "C" int empty_output_buffer (j_compress_ptr cinfo) +{ + my_dest_ptr dest = (my_dest_ptr) cinfo->dest; + + if (dest->outfile->Write(dest->buffer, BUF_SIZE) != + (size_t) BUF_SIZE) + ERREXIT(cinfo, JERR_FILE_WRITE); + + dest->pub.next_output_byte = dest->buffer; + dest->pub.free_in_buffer = BUF_SIZE; + + return TRUE; +} + +extern "C" void term_destination (j_compress_ptr cinfo) +{ + my_dest_ptr dest = (my_dest_ptr) cinfo->dest; + size_t datacount = BUF_SIZE - dest->pub.free_in_buffer; + + /* Write any data remaining in the buffer */ + if (datacount > 0) { + if (dest->outfile->Write(dest->buffer, datacount) != datacount) + ERREXIT(cinfo, JERR_FILE_WRITE); + } +} + +extern "C" void jpeg_svstream_dest (j_compress_ptr cinfo, void* out) +{ + SvStream * outfile = (SvStream*)out; + my_dest_ptr dest; + + /* The destination object is made permanent so that multiple JPEG images + * can be written to the same file without re-executing jpeg_svstream_dest. + * This makes it dangerous to use this manager and a different destination + * manager serially with the same JPEG object, because their private object + * sizes may be different. Caveat programmer. + */ + if (cinfo->dest == NULL) { /* first time for this JPEG object? */ + cinfo->dest = (struct jpeg_destination_mgr *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + sizeof(my_destination_mgr)); + } + + dest = (my_dest_ptr) cinfo->dest; + dest->pub.init_destination = init_destination; + dest->pub.empty_output_buffer = empty_output_buffer; + dest->pub.term_destination = term_destination; + dest->outfile = outfile; +} + +/* Expanded data source object for stdio input */ + +typedef struct { + struct jpeg_source_mgr pub; /* public fields */ + + SvStream * infile; /* source stream */ + JOCTET * buffer; /* start of buffer */ + boolean start_of_file; /* have we gotten any data yet? */ +} my_source_mgr; + +typedef my_source_mgr * my_src_ptr; + +/* + * Initialize source --- called by jpeg_read_header + * before any data is actually read. + */ + +extern "C" void init_source (j_decompress_ptr cinfo) +{ + my_src_ptr src = (my_src_ptr) cinfo->src; + + /* We reset the empty-input-file flag for each image, + * but we don't clear the input buffer. + * This is correct behavior for reading a series of images from one source. + */ + src->start_of_file = TRUE; +} + +long StreamRead( SvStream* pSvStm, void* pBuffer, long nBufferSize ) +{ + long nRead; + + if( pSvStm->GetError() != ERRCODE_IO_PENDING ) + { + long nActPos = pSvStm->Tell(); + + nRead = (long) pSvStm->Read( pBuffer, nBufferSize ); + + if( pSvStm->GetError() == ERRCODE_IO_PENDING ) + { + nRead = 0; + + // Damit wir wieder an die alte Position + // seeken koennen, setzen wir den Error temp.zurueck + pSvStm->ResetError(); + pSvStm->Seek( nActPos ); + pSvStm->SetError( ERRCODE_IO_PENDING ); + } + } + else + nRead = 0; + + return nRead; +} + +extern "C" int fill_input_buffer (j_decompress_ptr cinfo) +{ + my_src_ptr src = (my_src_ptr) cinfo->src; + size_t nbytes; + + nbytes = StreamRead(src->infile, src->buffer, BUF_SIZE); + + if (nbytes <= 0) { + if (src->start_of_file) /* Treat empty input file as fatal error */ + ERREXIT(cinfo, JERR_INPUT_EMPTY); + WARNMS(cinfo, JWRN_JPEG_EOF); + /* Insert a fake EOI marker */ + src->buffer[0] = (JOCTET) 0xFF; + src->buffer[1] = (JOCTET) JPEG_EOI; + nbytes = 2; + } + + src->pub.next_input_byte = src->buffer; + src->pub.bytes_in_buffer = nbytes; + src->start_of_file = FALSE; + + return TRUE; +} + +extern "C" void skip_input_data (j_decompress_ptr cinfo, long num_bytes) +{ + my_src_ptr src = (my_src_ptr) cinfo->src; + + /* Just a dumb implementation for now. Could use fseek() except + * it doesn't work on pipes. Not clear that being smart is worth + * any trouble anyway --- large skips are infrequent. + */ + if (num_bytes > 0) { + while (num_bytes > (long) src->pub.bytes_in_buffer) { + num_bytes -= (long) src->pub.bytes_in_buffer; + (void) fill_input_buffer(cinfo); + /* note we assume that fill_input_buffer will never return FALSE, + * so suspension need not be handled. + */ + } + src->pub.next_input_byte += (size_t) num_bytes; + src->pub.bytes_in_buffer -= (size_t) num_bytes; + } +} + +extern "C" void term_source (j_decompress_ptr) +{ + /* no work necessary here */ +} + +extern "C" void jpeg_svstream_src (j_decompress_ptr cinfo, void * in) +{ + my_src_ptr src; + SvStream * infile = (SvStream*)in; + + /* The source object and input buffer are made permanent so that a series + * of JPEG images can be read from the same file by calling jpeg_stdio_src + * only before the first one. (If we discarded the buffer at the end of + * one image, we'd likely lose the start of the next one.) + * This makes it unsafe to use this manager and a different source + * manager serially with the same JPEG object. Caveat programmer. + */ + if (cinfo->src == NULL) { /* first time for this JPEG object? */ + cinfo->src = (struct jpeg_source_mgr *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + sizeof(my_source_mgr)); + src = (my_src_ptr) cinfo->src; + src->buffer = (JOCTET *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + BUF_SIZE * sizeof(JOCTET)); + } + + src = (my_src_ptr) cinfo->src; + src->pub.init_source = init_source; + src->pub.fill_input_buffer = fill_input_buffer; + src->pub.skip_input_data = skip_input_data; + src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */ + src->pub.term_source = term_source; + src->infile = infile; + src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */ + src->pub.next_input_byte = NULL; /* until buffer loaded */ +} + +// -------------- +// - JPEGReader - +// -------------- + +JPEGReader::JPEGReader( SvStream& rStm, void* /*pCallData*/, sal_Bool bSetLS ) : + rIStm ( rStm ), + pAcc ( NULL ), + pAcc1 ( NULL ), + pBuffer ( NULL ), + nLastPos ( rStm.Tell() ), + nLastLines ( 0 ), + bSetLogSize ( bSetLS ) +{ + maUpperName = String::CreateFromAscii( "SVIJPEG", 7 ); + nFormerPos = nLastPos; +} + +// ------------------------------------------------------------------------ + +JPEGReader::~JPEGReader() +{ + if( pBuffer ) + rtl_freeMemory( pBuffer ); + + if( pAcc ) + aBmp.ReleaseAccess( pAcc ); + + if( pAcc1 ) + aBmp1.ReleaseAccess( pAcc1 ); +} + +// ------------------------------------------------------------------------ + +void* JPEGReader::CreateBitmap( void* pParam ) +{ + Size aSize( ((JPEGCreateBitmapParam*)pParam)->nWidth, + ((JPEGCreateBitmapParam*)pParam)->nHeight ); + sal_Bool bGray = ((JPEGCreateBitmapParam*)pParam)->bGray != 0; + + void* pBmpBuf = NULL; + + if( pAcc ) + aBmp.ReleaseAccess( pAcc ); + + if( bGray ) + { + BitmapPalette aGrayPal( 256 ); + + for( USHORT n = 0; n < 256; n++ ) + { + const BYTE cGray = (BYTE) n; + aGrayPal[ n ] = BitmapColor( cGray, cGray, cGray ); + } + + aBmp = Bitmap( aSize, 8, &aGrayPal ); + } + else + aBmp = Bitmap( aSize, 24 ); + + if ( bSetLogSize ) + { + unsigned long nUnit = ((JPEGCreateBitmapParam*)pParam)->density_unit; + + if( ( ( 1 == nUnit ) || ( 2 == nUnit ) ) && + ( (JPEGCreateBitmapParam*) pParam )->X_density && + ( (JPEGCreateBitmapParam*) pParam )->Y_density ) + { + Point aEmptyPoint; + Fraction aFractX( 1, ((JPEGCreateBitmapParam*)pParam)->X_density ); + Fraction aFractY( 1, ((JPEGCreateBitmapParam*)pParam)->Y_density ); + MapMode aMapMode( nUnit == 1 ? MAP_INCH : MAP_CM, aEmptyPoint, aFractX, aFractY ); + Size aPrefSize = OutputDevice::LogicToLogic( aSize, aMapMode, MAP_100TH_MM ); + + aBmp.SetPrefSize( aPrefSize ); + aBmp.SetPrefMapMode( MapMode( MAP_100TH_MM ) ); + } + } + + pAcc = aBmp.AcquireWriteAccess(); + + if( pAcc ) + { + long nAlignedWidth; + + const ULONG nFormat = pAcc->GetScanlineFormat(); + + if( + ( bGray && ( BMP_FORMAT_8BIT_PAL == nFormat ) ) || + ( !bGray && ( BMP_FORMAT_24BIT_TC_RGB == nFormat ) ) + ) + { + pBmpBuf = pAcc->GetBuffer(); + nAlignedWidth = pAcc->GetScanlineSize(); + ((JPEGCreateBitmapParam*)pParam)->bTopDown = pAcc->IsTopDown(); + } + else + { + nAlignedWidth = AlignedWidth4Bytes( aSize.Width() * ( bGray ? 8 : 24 ) ); + ((JPEGCreateBitmapParam*)pParam)->bTopDown = TRUE; + pBmpBuf = pBuffer = rtl_allocateMemory( nAlignedWidth * aSize.Height() ); + } + ((JPEGCreateBitmapParam*)pParam)->nAlignedWidth = nAlignedWidth; + } + + return pBmpBuf; +} + +// ------------------------------------------------------------------------ + +void JPEGReader::FillBitmap() +{ + if( pBuffer && pAcc ) + { + HPBYTE pTmp; + BitmapColor aColor; + long nAlignedWidth; + long nWidth = pAcc->Width(); + long nHeight = pAcc->Height(); + + if( pAcc->GetBitCount() == 8 ) + { + BitmapColor* pCols = new BitmapColor[ 256 ]; + + for( USHORT n = 0; n < 256; n++ ) + { + const BYTE cGray = (BYTE) n; + pCols[ n ] = pAcc->GetBestMatchingColor( BitmapColor( cGray, cGray, cGray ) ); + } + + nAlignedWidth = AlignedWidth4Bytes( pAcc->Width() * 8L ); + + for( long nY = 0L; nY < nHeight; nY++ ) + { + pTmp = (BYTE*) pBuffer + nY * nAlignedWidth; + + for( long nX = 0L; nX < nWidth; nX++ ) + pAcc->SetPixel( nY, nX, pCols[ *pTmp++ ] ); + } + + delete[] pCols; + } + else + { + nAlignedWidth = AlignedWidth4Bytes( pAcc->Width() * 24L ); + + for( long nY = 0L; nY < nHeight; nY++ ) + { + pTmp = (BYTE*) pBuffer + nY * nAlignedWidth; + + for( long nX = 0L; nX < nWidth; nX++ ) + { + aColor.SetRed( *pTmp++ ); + aColor.SetGreen( *pTmp++ ); + aColor.SetBlue( *pTmp++ ); + pAcc->SetPixel( nY, nX, aColor ); + } + } + } + } +} + +// ------------------------------------------------------------------------ + +Graphic JPEGReader::CreateIntermediateGraphic( const Bitmap& rBitmap, long nLines ) +{ + Graphic aGraphic; + const Size aSizePix( rBitmap.GetSizePixel() ); + + if( !nLastLines ) + { + if( pAcc1 ) + aBmp1.ReleaseAccess( pAcc1 ); + + aBmp1 = Bitmap( rBitmap.GetSizePixel(), 1 ); + aBmp1.Erase( Color( COL_WHITE ) ); + pAcc1 = aBmp1.AcquireWriteAccess(); + } + + if( nLines && ( nLines < aSizePix.Height() ) ) + { + if( pAcc1 ) + { + const long nNewLines = nLines - nLastLines; + + if( nNewLines ) + { + pAcc1->SetFillColor( Color( COL_BLACK ) ); + pAcc1->FillRect( Rectangle( Point( 0, nLastLines ), + Size( pAcc1->Width(), nNewLines ) ) ); + } + + aBmp1.ReleaseAccess( pAcc1 ); + aGraphic = BitmapEx( rBitmap, aBmp1 ); + pAcc1 = aBmp1.AcquireWriteAccess(); + } + else + aGraphic = rBitmap; + } + else + aGraphic = rBitmap; + + nLastLines = nLines; + + return aGraphic; +} + +// ------------------------------------------------------------------------ + +ReadState JPEGReader::Read( Graphic& rGraphic ) +{ + long nEndPos; + long nLines; + ReadState eReadState; + BOOL bRet = FALSE; + BYTE cDummy; + +#if 1 // TODO: is it possible to get rid of this seek to the end? + // check if the stream's end is already available + rIStm.Seek( STREAM_SEEK_TO_END ); + rIStm >> cDummy; + nEndPos = rIStm.Tell(); + + // else check if at least JPEGMINREAD bytes can be read + if( rIStm.GetError() == ERRCODE_IO_PENDING ) + { + rIStm.ResetError(); + if( ( nEndPos - nFormerPos ) < JPEGMINREAD ) + { + rIStm.Seek( nLastPos ); + return JPEGREAD_NEED_MORE; + } + } + + // seek back to the original position + rIStm.Seek( nLastPos ); +#endif + + Size aPreviewSize = GetPreviewSize(); + SetJpegPreviewSizeHint( aPreviewSize.Width(), aPreviewSize.Height() ); + + // read the (partial) image + ReadJPEG( this, &rIStm, &nLines ); + + if( pAcc ) + { + if( pBuffer ) + { + FillBitmap(); + rtl_freeMemory( pBuffer ); + pBuffer = NULL; + } + + aBmp.ReleaseAccess( pAcc ); + pAcc = NULL; + + if( rIStm.GetError() == ERRCODE_IO_PENDING ) + rGraphic = CreateIntermediateGraphic( aBmp, nLines ); + else + rGraphic = aBmp; + + bRet = TRUE; + } + else if( rIStm.GetError() == ERRCODE_IO_PENDING ) + bRet = TRUE; + + // Status setzen ( Pending hat immer Vorrang ) + if( rIStm.GetError() == ERRCODE_IO_PENDING ) + { + eReadState = JPEGREAD_NEED_MORE; + rIStm.ResetError(); + nFormerPos = rIStm.Tell(); + } + else + { + if( bRet ) + eReadState = JPEGREAD_OK; + else + eReadState = JPEGREAD_ERROR; + } + + return eReadState; +} + + +// -------------- +// - JPEGWriter - +// -------------- + +JPEGWriter::JPEGWriter( SvStream& rStm, const uno::Sequence< beans::PropertyValue >* pFilterData, bool* pExportWasGrey ) : + rOStm ( rStm ), + pAcc ( NULL ), + pBuffer ( NULL ), + pExpWasGrey ( pExportWasGrey ) +{ + FilterConfigItem aConfigItem( (uno::Sequence< beans::PropertyValue >*)pFilterData ); + bGreys = aConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "ColorMode" ) ), 0 ) != 0; + nQuality = aConfigItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Quality" ) ), 75 ); + + if ( pFilterData ) + { + int nArgs = pFilterData->getLength(); + const beans::PropertyValue* pValues = pFilterData->getConstArray(); + while( nArgs-- ) + { + if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StatusIndicator" ) ) ) + { + pValues->Value >>= xStatusIndicator; + } + pValues++; + } + } +} + +// ------------------------------------------------------------------------ + +void* JPEGWriter::GetScanline( long nY ) +{ + void* pScanline = NULL; + + if( pAcc ) + { + if( bNative ) + pScanline = pAcc->GetScanline( nY ); + else if( pBuffer ) + { + BitmapColor aColor; + long nWidth = pAcc->Width(); + BYTE* pTmp = pBuffer; + + if( pAcc->HasPalette() ) + { + for( long nX = 0L; nX < nWidth; nX++ ) + { + aColor = pAcc->GetPaletteColor( (BYTE) pAcc->GetPixel( nY, nX ) ); + *pTmp++ = aColor.GetRed(); + if ( bGreys ) + continue; + *pTmp++ = aColor.GetGreen(); + *pTmp++ = aColor.GetBlue(); + } + } + else + { + for( long nX = 0L; nX < nWidth; nX++ ) + { + aColor = pAcc->GetPixel( nY, nX ); + *pTmp++ = aColor.GetRed(); + if ( bGreys ) + continue; + *pTmp++ = aColor.GetGreen(); + *pTmp++ = aColor.GetBlue(); + } + } + + pScanline = pBuffer; + } + } + + return pScanline; +} + +// ------------------------------------------------------------------------ + +BOOL JPEGWriter::Write( const Graphic& rGraphic ) +{ + BOOL bRet = FALSE; + + if ( xStatusIndicator.is() ) + { + rtl::OUString aMsg; + xStatusIndicator->start( aMsg, 100 ); + } + + Bitmap aGraphicBmp( rGraphic.GetBitmap() ); + + if ( bGreys ) + { + if ( !aGraphicBmp.Convert( BMP_CONVERSION_8BIT_GREYS ) ) + aGraphicBmp = rGraphic.GetBitmap(); + } + + pAcc = aGraphicBmp.AcquireReadAccess(); + + if ( !bGreys ) // bitmap was not explicitely converted into greyscale, + { // check if source is greyscale only + + sal_Bool bIsGrey = sal_True; + + long nWidth = pAcc->Width(); + for ( long nY = 0; bIsGrey && ( nY < pAcc->Height() ); nY++ ) + { + BitmapColor aColor; + for( long nX = 0L; bIsGrey && ( nX < nWidth ); nX++ ) + { + aColor = pAcc->HasPalette() ? pAcc->GetPaletteColor( (BYTE) pAcc->GetPixel( nY, nX ) ) + : pAcc->GetPixel( nY, nX ); + bIsGrey = ( aColor.GetRed() == aColor.GetGreen() ) && ( aColor.GetRed() == aColor.GetBlue() ); + } + } + if ( bIsGrey ) + bGreys = sal_True; + } + + if( pExpWasGrey ) + *pExpWasGrey = bGreys; + + if( pAcc ) + { + bNative = ( pAcc->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_RGB ); + + if( !bNative ) + pBuffer = new BYTE[ AlignedWidth4Bytes( bGreys ? pAcc->Width() * 8L : pAcc->Width() * 24L ) ]; + + JPEGCallbackStruct aCallbackData; + aCallbackData.xStatusIndicator = xStatusIndicator; + bRet = (BOOL) WriteJPEG( this, &rOStm, pAcc->Width(), pAcc->Height(), bGreys, nQuality, &aCallbackData ); + + delete[] pBuffer; + pBuffer = NULL; + + aGraphicBmp.ReleaseAccess( pAcc ); + pAcc = NULL; + } + if ( xStatusIndicator.is() ) + xStatusIndicator->end(); + + return bRet; +} + +// -------------- +// - ImportJPEG - +// -------------- + +BOOL ImportJPEG( SvStream& rStm, Graphic& rGraphic, void* pCallerData, sal_Int32 nImportFlags ) +{ + JPEGReader* pJPEGReader = (JPEGReader*) rGraphic.GetContext(); + ReadState eReadState; + BOOL bRet = TRUE; + + if( !pJPEGReader ) + pJPEGReader = new JPEGReader( rStm, pCallerData, ( nImportFlags & GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG ) != 0 ); + + if( nImportFlags & GRFILTER_I_FLAGS_FOR_PREVIEW ) + pJPEGReader->SetPreviewSize( Size(128,128) ); + else + pJPEGReader->DisablePreviewMode(); + + rGraphic.SetContext( NULL ); + eReadState = pJPEGReader->Read( rGraphic ); + + if( eReadState == JPEGREAD_ERROR ) + { + bRet = FALSE; + delete pJPEGReader; + } + else if( eReadState == JPEGREAD_OK ) + delete pJPEGReader; + else + rGraphic.SetContext( pJPEGReader ); + + return bRet; +} + +// -------------- +// - ExportJPEG - +// -------------- + +BOOL ExportJPEG( SvStream& rOStm, const Graphic& rGraphic, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >* pFilterData, + bool* pExportWasGrey + ) +{ + JPEGWriter aJPEGWriter( rOStm, pFilterData, pExportWasGrey ); + return aJPEGWriter.Write( rGraphic ); +} diff --git a/svtools/source/filter/jpeg/jpeg.h b/svtools/source/filter/jpeg/jpeg.h new file mode 100644 index 000000000000..82a2f80a838c --- /dev/null +++ b/svtools/source/filter/jpeg/jpeg.h @@ -0,0 +1,71 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _JPEG_H +#define _JPEG_H + +#if defined( ICC ) +#include +#endif + +#if defined (UNX) || defined(__MINGW32__) +#include +#endif + +struct JPEGCreateBitmapParam +{ + unsigned long nWidth; + unsigned long nHeight; + unsigned long density_unit; + unsigned long X_density; + unsigned long Y_density; + long bGray; + + long nAlignedWidth; // these members will be filled by the + long bTopDown; // CreateBitmap method in svtools +}; + +typedef struct my_error_mgr* my_error_ptr; +typedef unsigned char BYTE; +typedef unsigned char* HPBYTE; + +void* JPEGMalloc( size_t size ); +void JPEGFree( void *ptr ); +long JPEGCallback( void* pCallbackData, long nPercent ); + +long WriteJPEG( void* pJPEGWriter, void* pOStm, long nWidth, long nHeight, long bGreyScale, + long nQualityPercent, void* pCallbackData ); +void* GetScanline( void* pJPEGWriter, long nY ); + +void ReadJPEG( void* pJPEGReader, void* pIStm, long* pLines ); +void* CreateBitmap( void* pJPEGReader, void* pJPEGCreateBitmapParam ); + +/* TODO: when incompatible changes are possible again + the preview size hint should be redone */ +void SetJpegPreviewSizeHint( int nWidth, int nHeight ); + +#endif diff --git a/svtools/source/filter/jpeg/jpegc.c b/svtools/source/filter/jpeg/jpegc.c new file mode 100644 index 000000000000..29b4749a7b51 --- /dev/null +++ b/svtools/source/filter/jpeg/jpegc.c @@ -0,0 +1,284 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include +#include +#include "setjmp.h" +#include "jpeglib.h" +#include "jerror.h" +#include "jpeg.h" +#include "rtl/alloc.h" +#include "osl/diagnose.h" + +struct my_error_mgr +{ + struct jpeg_error_mgr pub; + jmp_buf setjmp_buffer; +}; + +void jpeg_svstream_src (j_decompress_ptr cinfo, void* infile); +void jpeg_svstream_dest (j_compress_ptr cinfo, void* outfile); + +METHODDEF( void ) +my_error_exit (j_common_ptr cinfo) +{ + my_error_ptr myerr = (my_error_ptr) cinfo->err; + (*cinfo->err->output_message) (cinfo); + longjmp(myerr->setjmp_buffer, 1); +} + + +METHODDEF( void ) +my_output_message (j_common_ptr cinfo) +{ + char buffer[JMSG_LENGTH_MAX]; + (*cinfo->err->format_message) (cinfo, buffer); +} + +/* TODO: when incompatible changes are possible again + the preview size hint should be redone */ +static int nPreviewWidth = 0; +static int nPreviewHeight = 0; +void SetJpegPreviewSizeHint( int nWidth, int nHeight ) +{ + nPreviewWidth = nWidth; + nPreviewHeight = nHeight; +} + +void ReadJPEG( void* pJPEGReader, void* pIStm, long* pLines ) +{ + struct jpeg_decompress_struct cinfo; + struct my_error_mgr jerr; + struct JPEGCreateBitmapParam aCreateBitmapParam; + HPBYTE pDIB; + HPBYTE pTmp; + long nWidth; + long nHeight; + long nAlignedWidth; + JSAMPLE * range_limit; + HPBYTE pScanLineBuffer = NULL; + long nScanLineBufferComponents = 0; + // declare bDecompCreated volatile because of gcc + // warning: variable 'bDecompCreated' might be clobbered by `longjmp' or `vfork' + volatile long bDecompCreated = 0; + + /* Falls der Stream nicht ausreicht (IO_PENDING) + wird ueber ein longjmp in der Schleife nach Exit + gesprungen, wir geben dann die Anzahl + der bisher bearbeiteten Scanlines zurueck*/ + if ( setjmp( jerr.setjmp_buffer ) ) + goto Exit; + + cinfo.err = jpeg_std_error( &jerr.pub ); + jerr.pub.error_exit = my_error_exit; + jerr.pub.output_message = my_output_message; + + jpeg_create_decompress( &cinfo ); + bDecompCreated = 1; + jpeg_svstream_src( &cinfo, pIStm ); + jpeg_read_header( &cinfo, TRUE ); + + cinfo.scale_num = 1; + cinfo.scale_denom = 1; + cinfo.output_gamma = 1.0; + cinfo.raw_data_out = FALSE; + cinfo.quantize_colors = FALSE; + if ( cinfo.jpeg_color_space == JCS_YCbCr ) + cinfo.out_color_space = JCS_RGB; + else if ( cinfo.jpeg_color_space == JCS_YCCK ) + cinfo.out_color_space = JCS_CMYK; + + OSL_ASSERT(cinfo.out_color_space == JCS_CMYK || cinfo.out_color_space == JCS_GRAYSCALE || cinfo.out_color_space == JCS_RGB); + + /* change scale for preview import */ + if( nPreviewWidth || nPreviewHeight ) + { + if( nPreviewWidth == 0 ) { + nPreviewWidth = ( cinfo.image_width*nPreviewHeight )/cinfo.image_height; + if( nPreviewWidth <= 0 ) + nPreviewWidth = 1; + } else if( nPreviewHeight == 0 ) { + nPreviewHeight = ( cinfo.image_height*nPreviewWidth )/cinfo.image_width; + if( nPreviewHeight <= 0 ) + nPreviewHeight = 1; + } + + for( cinfo.scale_denom = 1; cinfo.scale_denom < 8; cinfo.scale_denom *= 2 ) + { + if( cinfo.image_width < nPreviewWidth * cinfo.scale_denom ) + break; + if( cinfo.image_height < nPreviewHeight * cinfo.scale_denom ) + break; + } + + if( cinfo.scale_denom > 1 ) + { + cinfo.dct_method = JDCT_FASTEST; + cinfo.do_fancy_upsampling = FALSE; + cinfo.do_block_smoothing = FALSE; + } + } + + jpeg_start_decompress( &cinfo ); + + nWidth = cinfo.output_width; + nHeight = cinfo.output_height; + aCreateBitmapParam.nWidth = nWidth; + aCreateBitmapParam.nHeight = nHeight; + + aCreateBitmapParam.density_unit = cinfo.density_unit; + aCreateBitmapParam.X_density = cinfo.X_density; + aCreateBitmapParam.Y_density = cinfo.Y_density; + aCreateBitmapParam.bGray = cinfo.output_components == 1; + pDIB = CreateBitmap( pJPEGReader, &aCreateBitmapParam ); + nAlignedWidth = aCreateBitmapParam.nAlignedWidth; + range_limit=cinfo.sample_range_limit; + + if ( cinfo.out_color_space == JCS_CMYK ) + { + nScanLineBufferComponents = cinfo.output_width * 4; + pScanLineBuffer = rtl_allocateMemory( nScanLineBufferComponents ); + } + + if( pDIB ) + { + if( aCreateBitmapParam.bTopDown ) + pTmp = pDIB; + else + { + pTmp = pDIB + ( nHeight - 1 ) * nAlignedWidth; + nAlignedWidth = -nAlignedWidth; + } + + for ( *pLines = 0; *pLines < nHeight; (*pLines)++ ) + { + if (pScanLineBuffer!=NULL) { // in other words cinfo.out_color_space == JCS_CMYK + int i; + int j; + jpeg_read_scanlines( &cinfo, (JSAMPARRAY) &pScanLineBuffer, 1 ); + // convert CMYK to RGB + for( i=0, j=0; i < nScanLineBufferComponents; i+=4, j+=3 ) + { + int c_=255-pScanLineBuffer[i+0]; + int m_=255-pScanLineBuffer[i+1]; + int y_=255-pScanLineBuffer[i+2]; + int k_=255-pScanLineBuffer[i+3]; + pTmp[j+0]=range_limit[ 255L - ( c_ + k_ ) ]; + pTmp[j+1]=range_limit[ 255L - ( m_ + k_ ) ]; + pTmp[j+2]=range_limit[ 255L - ( y_ + k_ ) ]; + } + } else { + jpeg_read_scanlines( &cinfo, (JSAMPARRAY) &pTmp, 1 ); + } + /* PENDING ??? */ + if ( cinfo.err->msg_code == 113 ) + break; + + pTmp += nAlignedWidth; + } + } + + jpeg_finish_decompress( &cinfo ); + if (pScanLineBuffer!=NULL) { + rtl_freeMemory( pScanLineBuffer ); + pScanLineBuffer=NULL; + } + +Exit: + + if( bDecompCreated ) + jpeg_destroy_decompress( &cinfo ); +} + +long WriteJPEG( void* pJPEGWriter, void* pOStm, + long nWidth, long nHeight, long bGreys, + long nQualityPercent, void* pCallbackData ) +{ + struct jpeg_compress_struct cinfo; + struct my_error_mgr jerr; + void* pScanline; + long nY; + // declare bCompCreated, bRet volatile because of gcc + // warning: variable 'bCompCreated' might be clobbered by `longjmp' or `vfork' + volatile long bCompCreated = 0; + volatile long bRet = 0; + + if ( setjmp( jerr.setjmp_buffer ) ) + goto Exit; + + cinfo.err = jpeg_std_error( &jerr.pub ); + jerr.pub.error_exit = my_error_exit; + jerr.pub.output_message = my_output_message; + + jpeg_create_compress( &cinfo ); + bCompCreated = 1; + + jpeg_svstream_dest( &cinfo, pOStm ); + + cinfo.image_width = (JDIMENSION) nWidth; + cinfo.image_height = (JDIMENSION) nHeight; + if ( bGreys ) + { + cinfo.input_components = 1; + cinfo.in_color_space = JCS_GRAYSCALE; + } + else + { + cinfo.input_components = 3; + cinfo.in_color_space = JCS_RGB; + } + + jpeg_set_defaults( &cinfo ); + jpeg_set_quality( &cinfo, (int) nQualityPercent, FALSE ); + + if ( ( nWidth > 128 ) || ( nHeight > 128 ) ) + jpeg_simple_progression( &cinfo ); + + jpeg_start_compress( &cinfo, TRUE ); + + for( nY = 0; nY < nHeight; nY++ ) + { + pScanline = GetScanline( pJPEGWriter, nY ); + + if( pScanline ) + jpeg_write_scanlines( &cinfo, (JSAMPARRAY) &pScanline, 1 ); + + if( JPEGCallback( pCallbackData, nY * 100L / nHeight ) ) + goto Exit; + } + + bRet = 1; + + jpeg_finish_compress(&cinfo); + +Exit: + + if ( bCompCreated ) + jpeg_destroy_compress( &cinfo ); + + return bRet; +} diff --git a/svtools/source/filter/sgf.ini b/svtools/source/filter/sgf.ini new file mode 100644 index 000000000000..7444e40c8836 --- /dev/null +++ b/svtools/source/filter/sgf.ini @@ -0,0 +1,118 @@ +#Family : (Roman,Swiss,Modern,Script,Decora); +#CharSet : (Ansi,IBMPC,Mac,Symbol,System); Default is System +#Attribute: (Bold,Ital,Sans,Serf,Fixd); + +[SGV Fonts fuer StarView] +#IF-ID Fontname Attribute SV-Fam ChSet Width FontName + 3848=(ITC Zapf Dingbats) Decora () + 5720=(Symbol) Serf Decora Symbol () + 5721=(Symbol) Bold Serf Decora Symbol () + 5723=(Symbol Sans) Sans Decora Symbol () + 5724=(Symbol Sans) Bold Sans Decora Symbol () + 90133=(Dom Casual) Sans Script () + 90326=(Brush) Bold Ital Serf Script () + 90349=(Park Avenue) Ital Serf Script () + 90508=(Uncial) Sans Roman () + 91118=(Antique Olive) Bold Sans Swiss () + 91119=(Antique Olive) Sans Swiss () + 91120=(Antique Olive Compact) Bold Sans Swiss () + 91335=(ITC Benguiat) Bold Serf Roman () + 91336=(ITC Benguiat) Bold Ital Serf Roman () + 91846=(Antique Olive) Ital Sans Roman () +#92500=(CG Times) Serf Roman () +#92501=(CG Times) Ital Serf Roman () +#92504=(CG Times) Bold Serf Roman () +#92505=(CG Times) Bold Ital Serf Roman () +#93950=(Courier) Serf Fixd Modern () +#93951=(Courier) Ital Serf Fixd Modern () +#93952=(Courier) Bold Serf Fixd Modern () +#93953=(Courier) Bold Ital Serf Fixd Modern () +#94021=(Univers) Sans Swiss () +#94022=(Univers) Ital Sans Swiss () +#94023=(Univers) Bold Sans Swiss () +#94024=(Univers) Bold Ital Sans Swiss () +102004=(Avanti) Bold Ital Sans Swiss () +102005=(Avanti) Ital Sans Swiss () +102007=(Booklet) Bold Sans Roman () +102008=(Booklet) Bold Ital Sans Roman () +102009=(Booklet) Ital Sans Roman () +102010=(Centuri) Sans Roman () +102011=(Centuri) Bold Sans Roman () +102012=(Centuri) Bold Ital Sans Roman () +102013=(Centuri) Ital Sans Roman () +102014=(Paltus) Bold Sans Roman () +102015=(Paltus) Sans Roman () +102016=(Paltus) Bold Ital Sans Roman () +102017=(Paltus) Ital Sans Roman () +102018=(Sans) Sans Swiss () +102019=(Sans) Bold Sans Swiss () +102020=(Sans) Bold Ital Sans Swiss () +102021=(Sans) Ital Sans Swiss () +102022=(SansCondensed) Sans Swiss () +102023=(SansCondensed) Bold Sans Swiss () +102024=(SansCondensed) Bold Ital Sans Swiss () +102025=(SansCondensed) Ital Sans Swiss () +102026=(PS-Roman) Sans Roman () +102027=(PS-Roman) Bold Sans Roman () +102028=(PS-Roman) Bold Ital Sans Roman () +102029=(PS-Roman) Ital Sans Roman () +200111=(Chalenge) Sans () +200112=(Chalenge) Bold Sans () +200113=(Chalenge) Ital Sans () +200114=(Chalenge) Bold Ital Sans () +200121=(Office) Sans () +200122=(Office) Bold Sans () +200123=(Office) Ital Sans () +200124=(Office) Bold Ital Sans () +200131=(Milano) Sans () +200132=(Milano) Bold Sans () +200133=(Milano) Ital Sans () +200134=(Milano) Bold Ital Sans () +200141=(Atlantic) Sans Roman () +200142=(Atlantic) Bold Sans Roman () +200143=(Atlantic) Ital Sans Roman () +200144=(Atlantic) Bold Ital Sans Roman () +200151=(Pentagon) Sans () +200152=(Pentagon) Bold Sans () +200153=(Pentagon) Ital Sans () +200154=(Pentagon) Bold Ital Sans () +200161=(Classico) Sans () +200162=(Classico) Bold Sans () +200163=(Classico) Ital Sans () +200164=(Classico) Bold Ital Sans () +200211=(Westcost) Sans () +200212=(Westcost) Bold Sans () +200213=(Westcost) Ital Sans () +200214=(Westcost) Bold Ital Sans () +200221=(Finish) Sans () +200222=(Finish) Bold Sans () +200223=(Finish) Ital Sans () +200224=(Finish) Bold Ital Sans () +200231=(Classic) Sans () +200232=(Classic) Bold Sans () +200233=(Classic) Ital Sans () +200234=(Classic) Bold Ital Sans () +200241=(Hilton) Sans () +200242=(Hilton) Bold Sans () +200243=(Hilton) Ital Sans () +200244=(Hilton) Bold Ital Sans () +200251=(Progress) Sans () +200252=(Progress) Bold Sans () +200253=(Progress) Ital Sans () +200254=(Progress) Bold Ital Sans () +200261=(PrestigeElite) Sans () +200262=(PrestigeElite) Bold Sans () +200263=(PrestigeElite) Ital Sans () +200271=(Ovetti) Bold Sans () +200272=(Ovetti) Sans () +200301=(Cescendo) Sans () +200302=(Funky) Sans Decora () +200303=(Speed) Sans Decora () +200304=(Skyline) Sans Decora () +200305=(Calculator) Sans Decora () +200306=(Xpress) Sans Decora () +200307=(Console) Sans Decora () +200308=(Paisley) Sans () +200309=(Nova) Sans () +200310=(New York) Sans Decora () +200311=(Shanghai) Sans Decora () diff --git a/svtools/source/filter/sgfbram.cxx b/svtools/source/filter/sgfbram.cxx new file mode 100644 index 000000000000..3d1a71f5a2db --- /dev/null +++ b/svtools/source/filter/sgfbram.cxx @@ -0,0 +1,662 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include +#include +#include +#include +#include +#include +#include "sgffilt.hxx" +#include "sgfbram.hxx" + +/************************************************************************* +|* +|* operator>>( SvStream&, SgfHeader& ) +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +SvStream& operator>>(SvStream& rIStream, SgfHeader& rHead) +{ + rIStream.Read((char*)&rHead.Magic,SgfHeaderSize); +#if defined OSL_BIGENDIAN + rHead.Magic =SWAPSHORT(rHead.Magic ); + rHead.Version=SWAPSHORT(rHead.Version); + rHead.Typ =SWAPSHORT(rHead.Typ ); + rHead.Xsize =SWAPSHORT(rHead.Xsize ); + rHead.Ysize =SWAPSHORT(rHead.Ysize ); + rHead.Xoffs =SWAPSHORT(rHead.Xoffs ); + rHead.Yoffs =SWAPSHORT(rHead.Yoffs ); + rHead.Planes =SWAPSHORT(rHead.Planes ); + rHead.SwGrCol=SWAPSHORT(rHead.SwGrCol); + rHead.OfsLo =SWAPSHORT(rHead.OfsLo ); + rHead.OfsHi =SWAPSHORT(rHead.OfsHi ); +#endif + return rIStream; +} + + +/************************************************************************* +|* +|* SgfHeader::ChkMagic() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +BOOL SgfHeader::ChkMagic() +{ return Magic=='J'*256+'J'; } + +UINT32 SgfHeader::GetOffset() +{ return UINT32(OfsLo)+0x00010000*UINT32(OfsHi); } + + +/************************************************************************* +|* +|* operator>>( SvStream&, SgfEntry& ) +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +SvStream& operator>>(SvStream& rIStream, SgfEntry& rEntr) +{ + rIStream.Read((char*)&rEntr.Typ,SgfEntrySize); +#if defined OSL_BIGENDIAN + rEntr.Typ =SWAPSHORT(rEntr.Typ ); + rEntr.iFrei=SWAPSHORT(rEntr.iFrei); + rEntr.lFreiLo=SWAPSHORT (rEntr.lFreiLo); + rEntr.lFreiHi=SWAPSHORT (rEntr.lFreiHi); + rEntr.OfsLo=SWAPSHORT(rEntr.OfsLo); + rEntr.OfsHi=SWAPSHORT(rEntr.OfsHi); +#endif + return rIStream; +} + +UINT32 SgfEntry::GetOffset() +{ return UINT32(OfsLo)+0x00010000*UINT32(OfsHi); } + + +/************************************************************************* +|* +|* operator>>( SvStream&, SgfVector& ) +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +SvStream& operator>>(SvStream& rIStream, SgfVector& rVect) +{ + rIStream.Read((char*)&rVect,sizeof(rVect)); +#if defined OSL_BIGENDIAN + rVect.Flag =SWAPSHORT(rVect.Flag ); + rVect.x =SWAPSHORT(rVect.x ); + rVect.y =SWAPSHORT(rVect.y ); + rVect.OfsLo=SWAPLONG (rVect.OfsLo); + rVect.OfsHi=SWAPLONG (rVect.OfsHi); +#endif + return rIStream; +} + + +/************************************************************************* +|* +|* operator<<( SvStream&, BmpFileHeader& ) +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +SvStream& operator<<(SvStream& rOStream, BmpFileHeader& rHead) +{ +#if defined OSL_BIGENDIAN + rHead.Typ =SWAPSHORT(rHead.Typ ); + rHead.SizeLo =SWAPSHORT(rHead.SizeLo ); + rHead.SizeHi =SWAPSHORT(rHead.SizeHi ); + rHead.Reserve1=SWAPSHORT(rHead.Reserve1); + rHead.Reserve2=SWAPSHORT(rHead.Reserve2); + rHead.OfsLo =SWAPSHORT(rHead.OfsLo ); + rHead.OfsHi =SWAPSHORT(rHead.OfsHi ); +#endif + rOStream.Write((char*)&rHead,sizeof(rHead)); +#if defined OSL_BIGENDIAN + rHead.Typ =SWAPSHORT(rHead.Typ ); + rHead.SizeLo =SWAPSHORT(rHead.SizeLo ); + rHead.SizeHi =SWAPSHORT(rHead.SizeHi ); + rHead.Reserve1=SWAPSHORT(rHead.Reserve1); + rHead.Reserve2=SWAPSHORT(rHead.Reserve2); + rHead.OfsLo =SWAPSHORT(rHead.OfsLo ); + rHead.OfsHi =SWAPSHORT(rHead.OfsHi ); +#endif + return rOStream; +} + +void BmpFileHeader::SetSize(UINT32 Size) +{ + SizeLo=UINT16(Size & 0x0000FFFF); + SizeHi=UINT16((Size & 0xFFFF0000)>>16); +} + +void BmpFileHeader::SetOfs(UINT32 Ofs) +{ + OfsLo=UINT16(Ofs & 0x0000FFFF); + OfsHi=UINT16((Ofs & 0xFFFF0000)>>16); +} + +UINT32 BmpFileHeader::GetOfs() +{ + return UINT32(OfsLo)+0x00010000*UINT32(OfsHi); +} + +/************************************************************************* +|* +|* operator<<( SvStream&, BmpInfoHeader& ) +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +SvStream& operator<<(SvStream& rOStream, BmpInfoHeader& rInfo) +{ +#if defined OSL_BIGENDIAN + rInfo.Size =SWAPLONG (rInfo.Size ); + rInfo.Width =SWAPLONG (rInfo.Width ); + rInfo.Hight =SWAPLONG (rInfo.Hight ); + rInfo.Planes =SWAPSHORT(rInfo.Planes ); + rInfo.PixBits =SWAPSHORT(rInfo.PixBits ); + rInfo.Compress=SWAPLONG (rInfo.Compress); + rInfo.ImgSize =SWAPLONG (rInfo.ImgSize ); + rInfo.xDpmm =SWAPLONG (rInfo.xDpmm ); + rInfo.yDpmm =SWAPLONG (rInfo.yDpmm ); + rInfo.ColUsed =SWAPLONG (rInfo.ColUsed ); + rInfo.ColMust =SWAPLONG (rInfo.ColMust ); +#endif + rOStream.Write((char*)&rInfo,sizeof(rInfo)); +#if defined OSL_BIGENDIAN + rInfo.Size =SWAPLONG (rInfo.Size ); + rInfo.Width =SWAPLONG (rInfo.Width ); + rInfo.Hight =SWAPLONG (rInfo.Hight ); + rInfo.Planes =SWAPSHORT(rInfo.Planes ); + rInfo.PixBits =SWAPSHORT(rInfo.PixBits ); + rInfo.Compress=SWAPLONG (rInfo.Compress); + rInfo.ImgSize =SWAPLONG (rInfo.ImgSize ); + rInfo.xDpmm =SWAPLONG (rInfo.xDpmm ); + rInfo.yDpmm =SWAPLONG (rInfo.yDpmm ); + rInfo.ColUsed =SWAPLONG (rInfo.ColUsed ); + rInfo.ColMust =SWAPLONG (rInfo.ColMust ); +#endif + return rOStream; +} + + +/************************************************************************* +|* +|* operator<<( SvStream&, RGBQuad& ) +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +SvStream& operator<<(SvStream& rOStream, const RGBQuad& rQuad) +{ + rOStream.Write((char*)&rQuad,sizeof(rQuad)); + return rOStream; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// PcxExpand /////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +class PcxExpand +{ +private: + USHORT Count; + BYTE Data; +public: + PcxExpand() { Count=0; } + BYTE GetByte(SvStream& rInp); +}; + +BYTE PcxExpand::GetByte(SvStream& rInp) +{ + if (Count>0) { + Count--; + } else { + rInp.Read((char*)&Data,1); + if ((Data & 0xC0) == 0xC0) { + Count=(Data & 0x3F) -1; + rInp.Read((char*)&Data,1); + } + } + return Data; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// SgfBMapFilter /////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////// + + +/************************************************************************* +|* +|* SgfFilterBmp() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +BOOL SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&) +{ + BmpFileHeader aBmpHead; + BmpInfoHeader aBmpInfo; + USHORT nWdtInp=(rHead.Xsize+7)/8; // Breite der Input-Bitmap in Bytes + USHORT nWdtOut; // Breite der Output-Bitmap in Bytes + USHORT nColors; // Anzahl der Farben (1,16,256) + USHORT nColBits; // Anzahl der Bits/Pixel (2, 4, 8) + USHORT i,j,k; // Spaltenzaehler, Zeilenzaehler, Planezaehler + USHORT a,b; // Hilfsvariable + BYTE pl1 = 0,pl2= 0; // Masken fuer die Planes + BYTE* pBuf=NULL; // Buffer fuer eine Pixelzeile + PcxExpand aPcx; + ULONG nOfs; + BYTE cRGB[4]; + + if (rHead.Planes<=1) nColBits=1; else nColBits=4; if (rHead.Typ==4) nColBits=8; + nColors=1<>aHead; + if (aHead.ChkMagic() && (aHead.Typ==SgfBitImag0 || aHead.Typ==SgfBitImag1 || + aHead.Typ==SgfBitImag2 || aHead.Typ==SgfBitImgMo)) { + nNext=aHead.GetOffset(); + while (nNext && !bRdFlag && !rInp.GetError() && !rOut.GetError()) { + rInp.Seek(nFileStart+nNext); + rInp>>aEntr; + nNext=aEntr.GetOffset(); + if (aEntr.Typ==aHead.Typ) { + bRdFlag=TRUE; + switch(aEntr.Typ) { + case SgfBitImag0: + case SgfBitImag1: + case SgfBitImag2: + case SgfBitImgMo: bRet=SgfFilterBMap(rInp,rOut,aHead,aEntr); break; + } + } + } // while(nNext) + } + if (rInp.GetError()) bRet=FALSE; + return(bRet); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// SgfVectFilter /////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +// Fuer StarDraw Embedded SGF-Vector +long SgfVectXofs=0; +long SgfVectYofs=0; +long SgfVectXmul=0; +long SgfVectYmul=0; +long SgfVectXdiv=0; +long SgfVectYdiv=0; +BOOL SgfVectScal=FALSE; + +//////////////////////////////////////////////////////////// +// Hpgl2SvFarbe //////////////////////////////////////////// +//////////////////////////////////////////////////////////// + +Color Hpgl2SvFarbe( BYTE nFarb ) +{ + ULONG nColor = COL_BLACK; + + switch (nFarb & 0x07) { + case 0: nColor=COL_WHITE; break; + case 1: nColor=COL_YELLOW; break; + case 2: nColor=COL_LIGHTMAGENTA; break; + case 3: nColor=COL_LIGHTRED; break; + case 4: nColor=COL_LIGHTCYAN; break; + case 5: nColor=COL_LIGHTGREEN; break; + case 6: nColor=COL_LIGHTBLUE; break; + case 7: nColor=COL_BLACK; break; + } + Color aColor( nColor ); + return aColor; +} + +/************************************************************************* +|* +|* SgfFilterVect() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +BOOL SgfFilterVect(SvStream& rInp, SgfHeader& rHead, SgfEntry&, GDIMetaFile& rMtf) +{ + VirtualDevice aOutDev; + SgfVector aVect; + BYTE nFarb; + BYTE nFrb0=7; + BYTE nLTyp; + BYTE nOTyp; + BOOL bEoDt=FALSE; + BOOL bPDwn=FALSE; + Point aP0(0,0); + Point aP1(0,0); + String Msg; + USHORT RecNr=0; + + rMtf.Record(&aOutDev); + aOutDev.SetLineColor(Color(COL_BLACK)); + aOutDev.SetFillColor(Color(COL_BLACK)); + + while (!bEoDt && !rInp.GetError()) { + rInp>>aVect; RecNr++; + nFarb=(BYTE) (aVect.Flag & 0x000F); + nLTyp=(BYTE)((aVect.Flag & 0x00F0) >>4); + nOTyp=(BYTE)((aVect.Flag & 0x0F00) >>8); + bEoDt=(aVect.Flag & 0x4000) !=0; + bPDwn=(aVect.Flag & 0x8000) !=0; + + long x=aVect.x-rHead.Xoffs; + long y=rHead.Ysize-(aVect.y-rHead.Yoffs); + if (SgfVectScal) { + if (SgfVectXdiv==0) SgfVectXdiv=rHead.Xsize; + if (SgfVectYdiv==0) SgfVectYdiv=rHead.Ysize; + if (SgfVectXdiv==0) SgfVectXdiv=1; + if (SgfVectYdiv==0) SgfVectYdiv=1; + x=SgfVectXofs+ x *SgfVectXmul /SgfVectXdiv; + y=SgfVectYofs+ y *SgfVectXmul /SgfVectYdiv; + } + aP1=Point(x,y); + if (!bEoDt && !rInp.GetError()) { + if (bPDwn && nLTyp<=6) { + switch(nOTyp) { + case 1: if (nFarb!=nFrb0) { + switch(rHead.SwGrCol) { + case SgfVectFarb: aOutDev.SetLineColor(Hpgl2SvFarbe(nFarb)); break; + case SgfVectGray: break; + case SgfVectWdth: break; + } + } + aOutDev.DrawLine(aP0,aP1); break; // Linie + case 2: break; // Kreis + case 3: break; // Text + case 5: aOutDev.DrawRect(Rectangle(aP0,aP1)); break; // Rechteck (solid) + } + } + aP0=aP1; + nFrb0=nFarb; + } + } + rMtf.Stop(); + rMtf.WindStart(); + MapMode aMap( MAP_10TH_MM, Point(), + Fraction( 1, 4 ), Fraction( 1, 4 ) ); + rMtf.SetPrefMapMode( aMap ); + rMtf.SetPrefSize( Size( (short)rHead.Xsize, (short)rHead.Ysize ) ); + return TRUE; +} + + +/************************************************************************* +|* +|* SgfVectFilter() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +BOOL SgfVectFilter(SvStream& rInp, GDIMetaFile& rMtf) +{ + ULONG nFileStart; // Offset des SgfHeaders. Im allgemeinen 0. + SgfHeader aHead; + SgfEntry aEntr; + ULONG nNext; + BOOL bRdFlag=FALSE; // Grafikentry gelesen ? + BOOL bRet=FALSE; // Returncode + + nFileStart=rInp.Tell(); + rInp>>aHead; + if (aHead.ChkMagic() && aHead.Typ==SGF_SIMPVECT) { + nNext=aHead.GetOffset(); + while (nNext && !bRdFlag && !rInp.GetError()) { + rInp.Seek(nFileStart+nNext); + rInp>>aEntr; + nNext=aEntr.GetOffset(); + if (aEntr.Typ==aHead.Typ) { + bRet=SgfFilterVect(rInp,aHead,aEntr,rMtf); + } + } // while(nNext) + if (bRdFlag) { + if (!rInp.GetError()) bRet=TRUE; // Scheinbar Ok + } + } + return(bRet); +} + + +/************************************************************************* +|* +|* SgfFilterPScr() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +BOOL SgfFilterPScr(SvStream&, SgfHeader&, SgfEntry&) +{ + return FALSE; // PostSrcipt wird noch nicht unterstuetzt ! +} + + +/************************************************************************* +|* +|* CheckSgfTyp() +|* +|* Beschreibung Feststellen, um was fuer ein SGF/SGV es sich handelt. +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +BYTE CheckSgfTyp(SvStream& rInp, USHORT& nVersion) +{ +#if OSL_DEBUG_LEVEL > 1 // Recordgroessen checken. Neuer Compiler hat vielleichte anderes Allignment! + if (sizeof(SgfHeader)!=SgfHeaderSize || + sizeof(SgfEntry) !=SgfEntrySize || + sizeof(SgfVector)!=SgfVectorSize || + sizeof(BmpFileHeader)!=BmpFileHeaderSize || + sizeof(BmpInfoHeader)!=BmpInfoHeaderSize || + sizeof(RGBQuad )!=RGBQuadSize ) return SGF_DONTKNOW; +#endif + + ULONG nPos; + SgfHeader aHead; + nVersion=0; + nPos=rInp.Tell(); + rInp>>aHead; + rInp.Seek(nPos); + if (aHead.ChkMagic()) { + nVersion=aHead.Version; + switch(aHead.Typ) { + case SgfBitImag0: + case SgfBitImag1: + case SgfBitImag2: + case SgfBitImgMo: return SGF_BITIMAGE; + case SgfSimpVect: return SGF_SIMPVECT; + case SgfPostScrp: return SGF_POSTSCRP; + case SgfStarDraw: return SGF_STARDRAW; + default : return SGF_DONTKNOW; + } + } else { + return SGF_DONTKNOW; + } +} diff --git a/svtools/source/filter/sgvmain.cxx b/svtools/source/filter/sgvmain.cxx new file mode 100644 index 000000000000..293c6dab7964 --- /dev/null +++ b/svtools/source/filter/sgvmain.cxx @@ -0,0 +1,1130 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include +#include +#include +#include +#include +#include "sgffilt.hxx" +#include "sgfbram.hxx" +#include "sgvmain.hxx" +#include "sgvspln.hxx" +#include + +//#if OSL_DEBUG_LEVEL > 1 +//#include "Debug.c" +//#endif + +#define SWAPPOINT(p) { \ + p.x=SWAPSHORT(p.x); \ + p.y=SWAPSHORT(p.y); } + +#define SWAPPAGE(p) { \ + p.Next =SWAPLONG (p.Next ); \ + p.nList =SWAPLONG (p.nList ); \ + p.ListEnd=SWAPLONG (p.ListEnd); \ + p.Paper.Size.x=SWAPSHORT(p.Paper.Size.x); \ + p.Paper.Size.y=SWAPSHORT(p.Paper.Size.y); \ + p.Paper.RandL =SWAPSHORT(p.Paper.RandL ); \ + p.Paper.RandR =SWAPSHORT(p.Paper.RandR ); \ + p.Paper.RandO =SWAPSHORT(p.Paper.RandO ); \ + p.Paper.RandU =SWAPSHORT(p.Paper.RandU ); \ + SWAPPOINT(p.U); \ + UINT16 iTemp; \ + for (iTemp=0;iTemp<20;iTemp++) { \ + rPage.HlpLnH[iTemp]=SWAPSHORT(rPage.HlpLnH[iTemp]); \ + rPage.HlpLnV[iTemp]=SWAPSHORT(rPage.HlpLnV[iTemp]); }} + +#define SWAPOBJK(o) { \ + o.Last =SWAPLONG (o.Last ); \ + o.Next =SWAPLONG (o.Next ); \ + o.MemSize =SWAPSHORT(o.MemSize ); \ + SWAPPOINT(o.ObjMin); \ + SWAPPOINT(o.ObjMax); } + +#define SWAPLINE(l) { \ + l.LMSize=SWAPSHORT(l.LMSize); \ + l.LDicke=SWAPSHORT(l.LDicke); } + +#define SWAPAREA(a) { \ + a.FDummy2=SWAPSHORT(a.FDummy2); \ + a.FMuster=SWAPSHORT(a.FMuster); } + +#define SWAPTEXT(t) { \ + SWAPLINE(t.L); \ + SWAPAREA(t.F); \ + t.FontLo =SWAPSHORT(t.FontLo ); \ + t.FontHi =SWAPSHORT(t.FontHi ); \ + t.Grad =SWAPSHORT(t.Grad ); \ + t.Breite =SWAPSHORT(t.Breite ); \ + t.Schnitt=SWAPSHORT(t.Schnitt); \ + t.LnFeed =SWAPSHORT(t.LnFeed ); \ + t.Slant =SWAPSHORT(t.Slant ); \ + SWAPLINE(t.ShdL); \ + SWAPAREA(t.ShdF); \ + SWAPPOINT(t.ShdVers); \ + SWAPAREA(t.BackF); } + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Einschraenkungen: +// +// - Flaechenmuster werden den unter StarView verfuegbaren Mustern angenaehert. +// - Linienenden werden unter StarView immer rund dargestellt und gehen ueber +// den Endpunkt der Linie hinaus. +// - Linienmuster werden den unter StarView verfuegbaren Mustern angenaehert. +// Transparent/Opak wird zur Zeit noch nicht beruecksichtigt. +// - Keine gedrehten Ellipsen +// +// +// +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Fuer Fontuebersetzung /////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////// +SgfFontLst* pSgfFonts = 0; + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Fuer Kreisunterarten, Text und gedrehte Rechtecke /////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////// +void RotatePoint(PointType& P, INT16 cx, INT16 cy, double sn, double cs) +{ + INT16 dx,dy; + double x1,y1; + dx=P.x-cx; + dy=P.y-cy; + x1=dx*cs-dy*sn; + y1=dy*cs+dx*sn; + P.x=cx+INT16(x1); + P.y=cy+INT16(y1); +} + +void RotatePoint(Point& P, INT16 cx, INT16 cy, double sn, double cs) +{ + INT16 dx,dy; + double x1,y1; + dx=(INT16)(P.X()-cx); + dy=(INT16)(P.Y()-cy); + x1=dx*cs-dy*sn; + y1=dy*cs+dx*sn; + P=Point(cx+INT16(x1),cy+INT16(y1)); +} + +INT16 iMulDiv(INT16 a, INT16 Mul, INT16 Div) +{ + INT32 Temp; + Temp=INT32(a)*INT32(Mul)/INT32(Div); + return INT16(Temp); +} + +UINT16 MulDiv(UINT16 a, UINT16 Mul, UINT16 Div) +{ + UINT32 Temp; + Temp=UINT32(a)*UINT32(Mul)/UINT32(Div); + return UINT16(Temp); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// SgfFilterSDrw /////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +SvStream& operator>>(SvStream& rIStream, DtHdType& rDtHd) +{ + rIStream.Read((char*)&rDtHd.Reserved[0],DtHdSize); + return rIStream; +} + +void DtHdOverSeek(SvStream& rInp) +{ + ULONG FPos=rInp.Tell(); + FPos+=(ULONG)DtHdSize; + rInp.Seek(FPos); +// rInp.seekg(rInp.tellg()+(ULONG)DtHdSize); +} + + +SvStream& operator>>(SvStream& rIStream, PageType& rPage) +{ + rIStream.Read((char*)&rPage.Next,PageSize); +#if defined OSL_BIGENDIAN + SWAPPAGE(rPage); +#endif + return rIStream; +} + +void ObjkOverSeek(SvStream& rInp, ObjkType& rObjk) +{ + ULONG Siz; + Siz=(ULONG)rObjk.MemSize+rObjk.Last; // ObjSize+ObjAnhSize + rInp.Seek(rInp.Tell()+Siz); +} + +SvStream& operator>>(SvStream& rInp, ObjkType& rObjk) +{ // Die Fileposition im Stream bleibt unveraendert! + ULONG nPos; + nPos=rInp.Tell(); + rInp.Read((char*)&rObjk.Last,ObjkSize); +#if defined OSL_BIGENDIAN + SWAPOBJK(rObjk); +#endif +#ifdef InArbeit + ULONG nPos1=rInp.Tell(); + if(nPos == nPos1) InfoBox( NULL, "tellg funkt nich" ).Execute(); +#endif + rInp.Seek(nPos); +#ifdef InArbeit + if (rInp.Tell() != nPos) InfoBox( NULL, "seekg funkt nich" ).Execute(); +#endif + return rInp; +} +SvStream& operator>>(SvStream& rInp, StrkType& rStrk) +{ + rInp.Read((char*)&rStrk.Last,StrkSize); +#if defined OSL_BIGENDIAN + SWAPOBJK (rStrk); + SWAPLINE (rStrk.L); + SWAPPOINT(rStrk.Pos1); + SWAPPOINT(rStrk.Pos2); +#endif + return rInp; +} +SvStream& operator>>(SvStream& rInp, RectType& rRect) +{ + rInp.Read((char*)&rRect.Last,RectSize); +#if defined OSL_BIGENDIAN + SWAPOBJK (rRect); + SWAPLINE (rRect.L); + SWAPAREA (rRect.F); + SWAPPOINT(rRect.Pos1); + SWAPPOINT(rRect.Pos2); + rRect.Radius =SWAPSHORT(rRect.Radius ); + rRect.DrehWink=SWAPSHORT(rRect.DrehWink); + rRect.Slant =SWAPSHORT(rRect.Slant ); +#endif + return rInp; +} +SvStream& operator>>(SvStream& rInp, PolyType& rPoly) +{ + rInp.Read((char*)&rPoly.Last,PolySize); +#if defined OSL_BIGENDIAN + SWAPOBJK (rPoly); + SWAPLINE (rPoly.L); + SWAPAREA (rPoly.F); + // rPoly.EckP=SWAPLONG(rPoly.EckP); +#endif + return rInp; +} +SvStream& operator>>(SvStream& rInp, SplnType& rSpln) +{ + rInp.Read((char*)&rSpln.Last,SplnSize); +#if defined OSL_BIGENDIAN + SWAPOBJK (rSpln); + SWAPLINE (rSpln.L); + SWAPAREA (rSpln.F); + // rSpln.EckP=SWAPLONG(rSpln.EckP); +#endif + return rInp; +} +SvStream& operator>>(SvStream& rInp, CircType& rCirc) +{ + rInp.Read((char*)&rCirc.Last,CircSize); +#if defined OSL_BIGENDIAN + SWAPOBJK (rCirc); + SWAPLINE (rCirc.L); + SWAPAREA (rCirc.F); + SWAPPOINT(rCirc.Radius); + SWAPPOINT(rCirc.Center); + rCirc.DrehWink =SWAPSHORT(rCirc.DrehWink ); + rCirc.StartWink=SWAPSHORT(rCirc.StartWink); + rCirc.RelWink =SWAPSHORT(rCirc.RelWink ); +#endif + return rInp; +} +SvStream& operator>>(SvStream& rInp, TextType& rText) +{ + rInp.Read((char*)&rText.Last,TextSize); +#if defined OSL_BIGENDIAN + SWAPOBJK (rText); + SWAPTEXT (rText.T); + SWAPPOINT(rText.Pos1); + SWAPPOINT(rText.Pos2); + rText.TopOfs =SWAPSHORT(rText.TopOfs ); + rText.DrehWink=SWAPSHORT(rText.DrehWink); + rText.BoxSlant=SWAPSHORT(rText.BoxSlant); + rText.BufSize =SWAPSHORT(rText.BufSize ); + //rText.Buf =SWAPLONG (rText.Buf ); + //rText.Ext =SWAPLONG (rText.Ext ); + SWAPPOINT(rText.FitSize); + rText.FitBreit=SWAPSHORT(rText.FitBreit); +#endif + rText.Buffer=NULL; + return rInp; +} +SvStream& operator>>(SvStream& rInp, BmapType& rBmap) +{ + rInp.Read((char*)&rBmap.Last,BmapSize); +#if defined OSL_BIGENDIAN + SWAPOBJK (rBmap); + SWAPAREA (rBmap.F); + SWAPPOINT(rBmap.Pos1); + SWAPPOINT(rBmap.Pos2); + rBmap.DrehWink=SWAPSHORT(rBmap.DrehWink); + rBmap.Slant =SWAPSHORT(rBmap.Slant ); + SWAPPOINT(rBmap.PixSize); +#endif + return rInp; +} +SvStream& operator>>(SvStream& rInp, GrupType& rGrup) +{ + rInp.Read((char*)&rGrup.Last,GrupSize); +#if defined OSL_BIGENDIAN + SWAPOBJK (rGrup); + rGrup.SbLo =SWAPSHORT(rGrup.SbLo ); + rGrup.SbHi =SWAPSHORT(rGrup.SbHi ); + rGrup.UpLo =SWAPSHORT(rGrup.UpLo ); + rGrup.UpHi =SWAPSHORT(rGrup.UpHi ); + rGrup.ChartSize=SWAPSHORT(rGrup.ChartSize); + rGrup.ChartPtr =SWAPLONG (rGrup.ChartPtr ); +#endif + return rInp; +} + + + +/************************************************************************* +|* +|* Sgv2SvFarbe() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +Color Sgv2SvFarbe(BYTE nFrb1, BYTE nFrb2, BYTE nInts) +{ + UINT16 r1=0,g1=0,b1=0,r2=0,g2=0,b2=0; + BYTE nInt2=100-nInts; + switch(nFrb1 & 0x07) { + case 0: r1=0xFF; g1=0xFF; b1=0xFF; break; + case 1: r1=0xFF; g1=0xFF; break; + case 2: g1=0xFF; b1=0xFF; break; + case 3: g1=0xFF; break; + case 4: r1=0xFF; b1=0xFF; break; + case 5: r1=0xFF; break; + case 6: b1=0xFF; break; + case 7: break; + } + switch(nFrb2 & 0x07) { + case 0: r2=0xFF; g2=0xFF; b2=0xFF; break; + case 1: r2=0xFF; g2=0xFF; break; + case 2: g2=0xFF; b2=0xFF; break; + case 3: g2=0xFF; break; + case 4: r2=0xFF; b2=0xFF; break; + case 5: r2=0xFF; break; + case 6: b2=0xFF; break; + case 7: break; + } + r1=(UINT16)((UINT32)r1*nInts/100+(UINT32)r2*nInt2/100); + g1=(UINT16)((UINT32)g1*nInts/100+(UINT32)g2*nInt2/100); + b1=(UINT16)((UINT32)b1*nInts/100+(UINT32)b2*nInt2/100); + Color aColor( (sal_uInt8)r1, (sal_uInt8)g1, (sal_uInt8)b1 ); + return aColor; +} + +void SetLine(ObjLineType& rLine, OutputDevice& rOut) +{ +/* !!! + PenStyle aStyle=PEN_SOLID; + switch(rLine.LMuster & 0x07) { + case 0: aStyle=PEN_NULL; break; + case 1: aStyle=PEN_SOLID; break; + case 2: aStyle=PEN_DOT; break; // . . . . . . . . . . . . . . + case 3: aStyle=PEN_DASH; break; // __ __ __ __ __ __ __ __ __ + case 4: aStyle=PEN_DASH; break; // ___ ___ ___ ___ ___ ___ ___ + case 5: aStyle=PEN_DASHDOT; break; // __ . __ . __ . __ . __ . __ + case 6: aStyle=PEN_DASHDOT; break; // __ _ __ _ __ _ __ _ __ _ __ + case 7: aStyle=PEN_DASHDOT; break; // ___ _ _ ___ _ _ ___ _ _ ___ + } + Pen aPen(Sgv2SvFarbe(rLine.LFarbe,rLine.LBFarbe,rLine.LIntens),rLine.LDicke,aStyle); + SetPen(aPen,rOut); +*/ + if( 0 == ( rLine.LMuster & 0x07 ) ) + rOut.SetLineColor(); + else + rOut.SetLineColor( Sgv2SvFarbe(rLine.LFarbe,rLine.LBFarbe,rLine.LIntens) ); +} + +void SetArea(ObjAreaType& rArea, OutputDevice& rOut) +{ +/* + BrushStyle aStyle=BRUSH_SOLID; + switch(rArea.FMuster & 0x00FF) { + case 0: aStyle=BRUSH_NULL; break; + case 1: aStyle=BRUSH_SOLID; break; + case 2: case 4: case 6: case 8: + case 10: case 12: case 14: case 16: + case 43: case 45: aStyle=BRUSH_VERT; break; + case 3: case 5: case 7: case 9: + case 11: case 13: case 15: case 17: + case 42: case 44: aStyle=BRUSH_HORZ; break; + case 18: case 20: case 22: case 24: + case 26: case 28: case 30: case 32: + case 46: case 48: aStyle=BRUSH_UPDIAG; break; + case 19: case 21: case 23: case 25: + case 27: case 29: case 31: case 33: + case 47: case 49: aStyle=BRUSH_DOWNDIAG; break; + case 34: case 35: case 36: case 37: aStyle=BRUSH_CROSS; break; + case 38: case 39: case 40: case 41: aStyle=BRUSH_DIAGCROSS; break; + default: aStyle=BRUSH_DIAGCROSS; break; + } + Brush aBrush(Sgv2SvFarbe(rArea.FFarbe,rArea.FBFarbe,rArea.FIntens),aStyle); + aBrush.SetTransparent((rArea.FMuster & 0x80) !=0L); + SetBrush(aBrush,rOut); +*/ + if( 0 == ( rArea.FMuster & 0x00FF ) ) + rOut.SetFillColor(); + else + rOut.SetFillColor( Sgv2SvFarbe( rArea.FFarbe,rArea.FBFarbe,rArea.FIntens ) ); +} + +/************************************************************************* +|* +|* ObjkType::DrawObjekt() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +void ObjkType::Draw(OutputDevice&) +{ +// ShowSDObjk(*this); +} + +void Obj0Type::Draw(OutputDevice&) {} + +/************************************************************************* +|* +|* StrkType::DrawObjekt() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +void StrkType::Draw(OutputDevice& rOut) +{ + SetLine(L,rOut); + rOut.DrawLine(Point(Pos1.x,Pos1.y),Point(Pos2.x,Pos2.y)); // !!! +} + +/************************************************************************* +|* +|* RectType::DrawObjekt() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +void SgfAreaColorIntens(UINT16 Muster, BYTE Col1, BYTE Col2, BYTE Int, OutputDevice& rOut) +{ + ObjAreaType F; + F.FMuster=Muster; + F.FFarbe=Col2; + F.FBFarbe=Col1; + F.FIntens=Int; + SetArea(F,rOut); +} + +void DrawSlideRect(INT16 x1, INT16 y1, INT16 x2, INT16 y2, ObjAreaType& F, OutputDevice& rOut) +{ + INT16 i,i0,b,b0; + INT16 Int1,Int2; + INT16 Col1,Col2; + // ClipMerk: HgdClipRec; + INT16 cx,cy; + INT16 MaxR; + INT32 dx,dy; + + rOut.SetLineColor(); + if (x1>x2) { i=x1; x1=x2; x2=i; } + if (y1>y2) { i=y1; y1=y2; y2=i; } + Col1=F.FBFarbe & 0x87; Col2=F.FFarbe & 0x87; + Int1=100-F.FIntens; Int2=F.FIntens; + if (Int1==Int2) { + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut); + rOut.DrawRect(Rectangle(x1,y1,x2,y2)); + } else { + b0=Int1; + switch (F.FBFarbe & 0x38) { + case 0x08: { // vertikal + i0=y1; + i=y1; + while (i<=y2) { + b=Int1+INT16((INT32)(Int2-Int1)*(INT32)(i-y1) /(INT32)(y2-y1+1)); + if (b!=b0) { + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut); + rOut.DrawRect(Rectangle(x1,i0,x2,i-1)); + i0=i; b0=b; + } + i++; + } + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut); + rOut.DrawRect(Rectangle(x1,i0,x2,y2)); + } break; + case 0x28: { // horizontal + i0=x1; + i=x1; + while (i<=x2) { + b=Int1+INT16((INT32)(Int2-Int1)*(INT32)(i-x1) /(INT32)(x2-x1+1)); + if (b!=b0) { + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut); + rOut.DrawRect(Rectangle(i0,y1,i-1,y2)); + i0=i; b0=b; + } + i++; + } + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut); + rOut.DrawRect(Rectangle(i0,y1,x2,y2)); + } break; + + case 0x18: case 0x38: { // Kreis + Region ClipMerk=rOut.GetClipRegion(); + double a; + + rOut.SetClipRegion(Region(Rectangle(x1,y1,x2,y2))); + cx=(x1+x2) /2; + cy=(y1+y2) /2; + dx=x2-x1+1; + dy=y2-y1+1; + a=sqrt((double)(dx*dx+dy*dy)); + MaxR=INT16(a) /2 +1; + b0=Int2; + i0=MaxR; if (MaxR<1) MaxR=1; + i=MaxR; + while (i>=0) { + b=Int1+INT16((INT32(Int2-Int1)*INT32(i)) /INT32(MaxR)); + if (b!=b0) { + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut); + //if (i0>200 || (Col1 & $80)!=0 || (Col2 & $80)!=0) { + // then begin { Fallunterscheidung fuer etwas bessere Performance } + // s2:=i0-i+2; + // SetPenSize(s2); + // s2:=s2 div 2; + // Circle(cx,cy,i0-s2,i0-s2);{} + // else + rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0)); + i0=i; b0=b; + } + i--; + } + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int1,rOut); + rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0)); + rOut.SetClipRegion(ClipMerk); + } break; // Kreis + } + } +} + + +void RectType::Draw(OutputDevice& rOut) +{ + if (L.LMuster!=0) L.LMuster=1; // keine Linienmuster hier, nur an oder aus + SetArea(F,rOut); + if (DrehWink==0) { + if ((F.FBFarbe & 0x38)==0 || Radius!=0) { + SetLine(L,rOut); + rOut.DrawRect(Rectangle(Pos1.x,Pos1.y,Pos2.x,Pos2.y),Radius,Radius); + } else { + DrawSlideRect(Pos1.x,Pos1.y,Pos2.x,Pos2.y,F,rOut); + if (L.LMuster!=0) { + SetLine(L,rOut); + rOut.SetFillColor(); + rOut.DrawRect(Rectangle(Pos1.x,Pos1.y,Pos2.x,Pos2.y)); + } + } + } else { + Point aPts[4]; + USHORT i; + double sn,cs; + sn=sin(double(DrehWink)*3.14159265359/18000); + cs=cos(double(DrehWink)*3.14159265359/18000); + aPts[0]=Point(Pos1.x,Pos1.y); + aPts[1]=Point(Pos2.x,Pos1.y); + aPts[2]=Point(Pos2.x,Pos2.y); + aPts[3]=Point(Pos1.x,Pos2.y); + for (i=0;i<4;i++) { + RotatePoint(aPts[i],Pos1.x,Pos1.y,sn,cs); + } + SetLine(L,rOut); + Polygon aPoly(4,aPts); + rOut.DrawPolygon(aPoly); + } +} + +/************************************************************************* +|* +|* PolyType::Draw() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +void PolyType::Draw(OutputDevice& rOut) +{ + if ((Flags & PolyClosBit) !=0) SetArea(F,rOut); + SetLine(L,rOut); + Polygon aPoly(nPoints); + USHORT i; + for(i=0;i0) rOut.DrawPolygon(aPoly); + } else { + Spline2Poly(aSpln,FALSE,aPoly); + if (aPoly.GetSize()>0) rOut.DrawPolyLine(aPoly); + } +} + +/************************************************************************* +|* +|* CircType::Draw() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +void DrawSlideCirc(INT16 cx, INT16 cy, INT16 rx, INT16 ry, ObjAreaType& F, OutputDevice& rOut) +{ + INT16 x1=cx-rx; + INT16 y1=cy-ry; + INT16 x2=cx+rx; + INT16 y2=cy+ry; + + INT16 i,i0,b,b0; + INT16 Int1,Int2; + INT16 Col1,Col2; + + rOut.SetLineColor(); + Col1=F.FBFarbe & 0x87; Col2=F.FFarbe & 0x87; + Int1=100-F.FIntens; Int2=F.FIntens; + if (Int1==Int2) { + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut); + rOut.DrawEllipse(Rectangle(x1,y1,x2,y2)); + } else { + b0=Int1; + switch (F.FBFarbe & 0x38) { + case 0x08: { // vertikal + Region ClipMerk=rOut.GetClipRegion(); + i0=y1; + i=y1; + while (i<=y2) { + b=Int1+INT16((INT32)(Int2-Int1)*(INT32)(i-y1) /(INT32)(y2-y1+1)); + if (b!=b0) { + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut); + rOut.SetClipRegion(Rectangle(x1,i0,x2,i-1)); + rOut.DrawEllipse(Rectangle(x1,y1,x2,y2)); + i0=i; b0=b; + } + i++; + } + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut); + rOut.SetClipRegion(Rectangle(x1,i0,x2,y2)); + rOut.DrawEllipse(Rectangle(x1,y1,x2,y2)); + rOut.SetClipRegion(ClipMerk); + } break; + case 0x28: { // horizontal + Region ClipMerk=rOut.GetClipRegion(); + i0=x1; + i=x1; + while (i<=x2) { + b=Int1+INT16((INT32)(Int2-Int1)*(INT32)(i-x1) /(INT32)(x2-x1+1)); + if (b!=b0) { + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut); + rOut.SetClipRegion(Rectangle(i0,y1,i-1,y2)); + rOut.DrawEllipse(Rectangle(x1,y1,x2,y2)); + i0=i; b0=b; + } + i++; + } + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int2,rOut); + rOut.SetClipRegion(Rectangle(i0,y1,x2,y2)); + rOut.DrawEllipse(Rectangle(x1,y1,x2,y2)); + rOut.SetClipRegion(ClipMerk); + } break; + + case 0x18: case 0x38: { // Kreis + INT16 MaxR; + + if (rx<1) rx=1; + if (ry<1) ry=1; + MaxR=rx; + b0=Int2; + i0=MaxR; if (MaxR<1) MaxR=1; + i=MaxR; + while (i>=0) { + b=Int1+INT16((INT32(Int2-Int1)*INT32(i)) /INT32(MaxR)); + if (b!=b0) { + INT32 temp=INT32(i0)*INT32(ry)/INT32(rx); + INT16 j0=INT16(temp); + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)b0,rOut); + rOut.DrawEllipse(Rectangle(cx-i0,cy-j0,cx+i0,cy+j0)); + i0=i; b0=b; + } + i--; + } + SgfAreaColorIntens(F.FMuster,(BYTE)Col1,(BYTE)Col2,(BYTE)Int1,rOut); + rOut.DrawEllipse(Rectangle(cx-i0,cy-i0,cx+i0,cy+i0)); + } break; // Kreis + } + } +} + + +void CircType::Draw(OutputDevice& rOut) +{ + Rectangle aRect(Center.x-Radius.x,Center.y-Radius.y,Center.x+Radius.x,Center.y+Radius.y); + + if (L.LMuster!=0) L.LMuster=1; // keine Linienmuster hier, nur an oder aus + SetArea(F,rOut); + if ((Flags & 0x03)==CircFull) { + if ((F.FBFarbe & 0x38)==0) { + SetLine(L,rOut); + rOut.DrawEllipse(aRect); + } else { + DrawSlideCirc(Center.x,Center.y,Radius.x,Radius.y,F,rOut); + if (L.LMuster!=0) { + SetLine(L,rOut); + rOut.SetFillColor(); + rOut.DrawEllipse(aRect); + } + } + } else { + PointType a,b; + Point aStrt,aEnde; + double sn,cs; + + a.x=Center.x+Radius.x; a.y=Center.y; b=a; + sn=sin(double(StartWink)*3.14159265359/18000); + cs=cos(double(StartWink)*3.14159265359/18000); + RotatePoint(a,Center.x,Center.y,sn,cs); + sn=sin(double(StartWink+RelWink)*3.14159265359/18000); + cs=cos(double(StartWink+RelWink)*3.14159265359/18000); + RotatePoint(b,Center.x,Center.y,sn,cs); + if (Radius.x!=Radius.y) { + if (Radius.x<1) Radius.x=1; + if (Radius.y<1) Radius.y=1; + a.y = a.y - Center.y; + b.y = b.y - Center.y; + a.y=iMulDiv(a.y,Radius.y,Radius.x); + b.y=iMulDiv(b.y,Radius.y,Radius.x); + a.y = a.y + Center.y; + b.y = b.y + Center.y; + } + aStrt=Point(a.x,a.y); + aEnde=Point(b.x,b.y); + SetLine(L,rOut); + switch (Flags & 0x03) { + case CircArc : rOut.DrawArc(aRect,aEnde,aStrt); break; + case CircSect: + case CircAbsn: rOut.DrawPie(aRect,aEnde,aStrt); break; + } + } +} + +/************************************************************************* +|* +|* BmapType::Draw() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ + +void BmapType::Draw(OutputDevice& rOut) +{ + //ifstream aInp; + unsigned char nSgfTyp; + USHORT nVersion; + String aStr( + reinterpret_cast< char const * >(&Filename[ 1 ]), + (xub_StrLen)Filename[ 0 ], RTL_TEXTENCODING_UTF8 ); + INetURLObject aFNam( aStr ); + + SvStream* pInp = ::utl::UcbStreamHelper::CreateStream( aFNam.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ); + if ( pInp ) + { + nSgfTyp=CheckSgfTyp( *pInp,nVersion); + switch(nSgfTyp) { + case SGF_BITIMAGE: { + GraphicFilter aFlt; + Graphic aGrf; + USHORT nRet; + nRet=aFlt.ImportGraphic(aGrf,aFNam); + aGrf.Draw(&rOut,Point(Pos1.x,Pos1.y),Size(Pos2.x-Pos1.x,Pos2.y-Pos1.y)); + } break; + case SGF_SIMPVECT: { + GDIMetaFile aMtf; + SgfVectXofs=Pos1.x; + SgfVectYofs=Pos1.y; + SgfVectXmul=Pos2.x-Pos1.x; + SgfVectYmul=Pos2.y-Pos1.y; + SgfVectXdiv=0; + SgfVectYdiv=0; + SgfVectScal=TRUE; + SgfVectFilter(*pInp,aMtf); + SgfVectXofs=0; + SgfVectYofs=0; + SgfVectXmul=0; + SgfVectYmul=0; + SgfVectXdiv=0; + SgfVectYdiv=0; + SgfVectScal=FALSE; + aMtf.Play(&rOut); + } break; + } + delete pInp; + } +} + + +/************************************************************************* +|* +|* GrupType::... +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +UINT32 GrupType::GetSubPtr() +{ + return UINT32(SbLo)+0x00010000*UINT32(SbHi); +} + +/************************************************************************* +|* +|* DrawObjkList() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +void DrawObjkList( SvStream& rInp, OutputDevice& rOut ) +{ + ObjkType aObjk; + USHORT nGrpCnt=0; + BOOL bEnde=FALSE; + do { + rInp>>aObjk; + if (!rInp.GetError()) { + switch(aObjk.Art) { + case ObjStrk: { StrkType aStrk; rInp>>aStrk; if (!rInp.GetError()) aStrk.Draw(rOut); } break; + case ObjRect: { RectType aRect; rInp>>aRect; if (!rInp.GetError()) aRect.Draw(rOut); } break; + case ObjCirc: { CircType aCirc; rInp>>aCirc; if (!rInp.GetError()) aCirc.Draw(rOut); } break; + case ObjText: { + TextType aText; + rInp>>aText; + if (!rInp.GetError()) { + aText.Buffer=new UCHAR[aText.BufSize+1]; // Ein mehr fuer LookAhead bei CK-Trennung + rInp.Read((char* )aText.Buffer,aText.BufSize); + if (!rInp.GetError()) aText.Draw(rOut); + delete[] aText.Buffer; + } + } break; + case ObjBmap: { + BmapType aBmap; + rInp>>aBmap; + if (!rInp.GetError()) { + aBmap.Draw(rOut); + } + } break; + case ObjPoly: { + PolyType aPoly; + rInp>>aPoly; + if (!rInp.GetError()) { + aPoly.EckP=new PointType[aPoly.nPoints]; + rInp.Read((char*)aPoly.EckP,4*aPoly.nPoints); +#if defined OSL_BIGENDIAN + for(short i=0;i>aSpln; + if (!rInp.GetError()) { + aSpln.EckP=new PointType[aSpln.nPoints]; + rInp.Read((char*)aSpln.EckP,4*aSpln.nPoints); +#if defined OSL_BIGENDIAN + for(short i=0;i>aGrup; + if (!rInp.GetError()) { + rInp.Seek(rInp.Tell()+aGrup.Last); // Obj-Anhaengsel + if(aGrup.GetSubPtr()!=0L) nGrpCnt++;// DrawObjkList(rInp,rOut ); + } + } break; + default: { + aObjk.Draw(rOut); // Objektbezeichnung auf 2. Screen + ObjkOverSeek(rInp,aObjk); // zum naechsten Objekt + } + } + } // if rInp + if (!rInp.GetError()) { + if (aObjk.Next==0L) { + if (nGrpCnt==0) bEnde=TRUE; + else nGrpCnt--; + } + } else { + bEnde=TRUE; // Lesefehler + } + } while (!bEnde); +} + +/************************************************************************* +|* +|* SkipObjkList() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +void SkipObjkList(SvStream& rInp) +{ + ObjkType aObjk; + do + { + rInp>>aObjk; + if(aObjk.Art==ObjGrup) { + GrupType aGrup; + rInp>>aGrup; + rInp.Seek(rInp.Tell()+aGrup.Last); // Obj-Anhaengsel + if(aGrup.GetSubPtr()!=0L) SkipObjkList(rInp); + } else { + ObjkOverSeek(rInp,aObjk); // zum naechsten Objekt + } + } while (aObjk.Next!=0L && !rInp.GetError()); +} + +/************************************************************************* +|* +|* SgfFilterSDrw() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +BOOL SgfFilterSDrw( SvStream& rInp, SgfHeader&, SgfEntry&, GDIMetaFile& rMtf ) +{ + BOOL bRet = FALSE; + PageType aPage; + VirtualDevice aOutDev; + OutputDevice* pOutDev; + ULONG nStdPos; + ULONG nZchPos; + USHORT Num; + + pOutDev=&aOutDev; + DtHdOverSeek(rInp); // DataHeader weglesen + + nStdPos=rInp.Tell(); + do { // Standardseiten weglesen + rInp>>aPage; + if (aPage.nList!=0) SkipObjkList(rInp); + } while (aPage.Next!=0L && !rInp.GetError()); + +// ShowMsg("Zeichnungseite(n)\n"); + nZchPos=rInp.Tell(); + rInp>>aPage; + + rMtf.Record(pOutDev); + Num=aPage.StdPg; + if (Num!=0) { + rInp.Seek(nStdPos); + while(Num>1 && aPage.Next!=0L && !rInp.GetError()) { // Standardseite suchen + rInp>>aPage; + if (aPage.nList!=0) SkipObjkList(rInp); + Num--; + } + rInp>>aPage; + if(Num==1 && aPage.nList!=0L) DrawObjkList( rInp,*pOutDev ); + rInp.Seek(nZchPos); + nZchPos=rInp.Tell(); + rInp>>aPage; + } + if (aPage.nList!=0L) DrawObjkList(rInp,*pOutDev ); + + rMtf.Stop(); + rMtf.WindStart(); + MapMode aMap(MAP_10TH_MM,Point(),Fraction(1,4),Fraction(1,4)); + rMtf.SetPrefMapMode(aMap); + rMtf.SetPrefSize(Size((INT16)aPage.Paper.Size.x,(INT16)aPage.Paper.Size.y)); + bRet=TRUE; + return bRet; +} + + + +/************************************************************************* +|* +|* SgfSDrwFilter() +|* +|* Beschreibung +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +BOOL SgfSDrwFilter(SvStream& rInp, GDIMetaFile& rMtf, INetURLObject aIniPath ) +{ +#if OSL_DEBUG_LEVEL > 1 // Recordgroessen checken. Neuer Compiler hat vielleichte anderes Alignment! + if (sizeof(ObjTextType)!=ObjTextTypeSize) return FALSE; +#endif + + ULONG nFileStart; // Offset des SgfHeaders. Im allgemeinen 0. + SgfHeader aHead; + SgfEntry aEntr; + ULONG nNext; + BOOL bRdFlag=FALSE; // Grafikentry gelesen ? + BOOL bRet=FALSE; // Returncode + + aIniPath.Append( String::CreateFromAscii( "sgf.ini", 7 ) ); +// aIniPath.ToAbs(); + + pSgfFonts = new SgfFontLst; + + pSgfFonts->AssignFN( aIniPath.GetMainURL( INetURLObject::NO_DECODE ) ); + nFileStart=rInp.Tell(); + rInp>>aHead; + if (aHead.ChkMagic() && aHead.Typ==SgfStarDraw && aHead.Version==SGV_VERSION) { + nNext=aHead.GetOffset(); + while (nNext && !bRdFlag && !rInp.GetError()) { + rInp.Seek(nFileStart+nNext); + rInp>>aEntr; + nNext=aEntr.GetOffset(); + if (aEntr.Typ==aHead.Typ) { + bRet=SgfFilterSDrw( rInp,aHead,aEntr,rMtf ); + } + } // while(nNext) + if (bRdFlag) { + if (!rInp.GetError()) bRet=TRUE; // Scheinbar Ok + } + } + delete pSgfFonts; + return(bRet); +} + +/* +Bitmap Dither(BYTE Intens) +{ + Bitmap aBmp; + BmpInfoHeader Info; + + +const dmatrix: array[0..7,0..7] of byte = + (( 0, 48, 12, 60, 3, 51, 15, 63 ), + ( 32, 16, 44, 28, 35, 19, 47, 31 ), + ( 8, 56, 4, 52, 11, 59, 7, 55 ), + ( 40, 24, 36, 20, 43, 27, 39, 23 ), + ( 2, 50, 14, 62, 1, 49, 13, 61 ), + ( 34, 18, 46, 30, 33, 17, 45, 29 ), + ( 10, 58, 6, 54, 9, 57, 5, 53 ), + ( 42, 26, 38, 22, 41, 25, 37, 21 )); + + + cmatrix: array[0..7,0..7] of byte; + dmatrixn,dmatrixi: array[0..7] of byte; + + +procedure SetColorIntens(col0,col1,bal: integer); +var cmatrix0: array[0..63] of byte absolute cmatrix; + dmatrix0: array[0..63] of byte absolute dmatrix; + n,i: integer; + b,bit: byte; +begin +if col0=col1 then bal:=0; +if bal<=32 then + begin + plotcolor0:=col0 and $1F; plotcolor1:=col1 and $1F; + plotbal:=bal; + end +else + begin + plotcolor0:=col1 and $1F; plotcolor1:=col0 and $1F; + plotbal:=64-bal; + end; +for n:=0 to 63 do + if plotbal<=dmatrix0[n] then cmatrix0[n]:=col0 else cmatrix0[n]:=col1; +end; +*/ + diff --git a/svtools/source/filter/sgvspln.cxx b/svtools/source/filter/sgvspln.cxx new file mode 100644 index 000000000000..d695e171a194 --- /dev/null +++ b/svtools/source/filter/sgvspln.cxx @@ -0,0 +1,890 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include + + +#include + +#if defined( PM2 ) && defined( __BORLANDC__ ) +#pragma option -Od +#endif + +extern "C" { + +/*.pn 277 */ +/*.hlAnhang: C - Programme*/ +/*.hrKonstanten- und Macro-Definitionen*/ +/*.fe Die Include-Datei u_const.h ist in das Verzeichnis zu stellen, */ +/*.fe wo der Compiler nach Include-Dateien sucht. */ + + +/*----------------------- FILE u_const.h ---------------------------*/ + +#define IEEE + +/* IEEE - Norm fuer die Darstellung von Gleitkommazahlen: + + 8 Byte lange Gleitkommazahlen, mit + + 53 Bit Mantisse ==> Mantissenbereich: 2 hoch 52 versch. Zahlen + mit 0.1 <= Zahl < 1.0, + 1 Vorzeichen-Bit + 11 Bit Exponent ==> Exponentenbereich: -1024...+1023 + + Die 1. Zeile ( #define IEEE ) ist zu loeschen, falls die Maschine + bzw. der Compiler keine Gleitpunktzahlen gemaess der IEEE-Norm + benutzt. Zusaetzlich muessen die Zahlen MAXEXPON, MINEXPON + (s.u.) angepasst werden. + */ + +#ifdef IEEE /*----------- Falls IEEE Norm --------------------*/ + +#define MACH_EPS 2.220446049250313e-016 /* Maschinengenauigkeit */ + /* IBM-AT: = 2 hoch -52 */ +/* MACH_EPS ist die kleinste positive, auf der Maschine darstellbare + Zahl x, die der Bedingung genuegt: 1.0 + x > 1.0 */ + +#define EPSQUAD 4.930380657631324e-032 +#define EPSROOT 1.490116119384766e-008 + +#define POSMAX 8.98846567431158e+307 /* groesste positive Zahl */ +#define POSMIN 5.56268464626800e-309 /* kleinste positive Zahl */ +#define MAXROOT 9.48075190810918e+153 + +#define BASIS 2 /* Basis der Zahlendarst. */ +#ifndef PI +#define PI 3.141592653589793e+000 +#endif +#define EXP_1 2.718281828459045e+000 + +#else /*------------------ sonst -----------------------*/ + +double exp (double); +double atan (double); +double pow (double,double); +double sqrt (double); + +double masch() /* MACH_EPS maschinenunabhaengig bestimmen */ +{ + double eps = 1.0, x = 2.0, y = 1.0; + while ( y < x ) + { eps *= 0.5; + x = 1.0 + eps; + } + eps *= 2.0; return (eps); +} + +short basis() /* BASIS maschinenunabhaengig bestimmen */ +{ + double x = 1.0, one = 1.0, b = 1.0; + + while ( (x + one) - x == one ) x *= 2.0; + while ( (x + b) == x ) b *= 2.0; + + return ( (short) ((x + b) - x) ); +} + +#define BASIS basis() /* Basis der Zahlendarst. */ + +/* Falls die Maschine (der Compiler) keine IEEE-Darstellung fuer + Gleitkommazahlen nutzt, muessen die folgenden 2 Konstanten an- + gepasst werden. + */ + +#define MAXEXPON 1023.0 /* groesster Exponent */ +#define MINEXPON -1024.0 /* kleinster Exponent */ + + +#define MACH_EPS masch() +#define EPSQUAD MACH_EPS * MACH_EPS +#define EPSROOT sqrt(MACH_EPS) + +#define POSMAX pow ((double) BASIS, MAXEXPON) +#define POSMIN pow ((double) BASIS, MINEXPON) +#define MAXROOT sqrt(POSMAX) + +#define PI 4.0 * atan (1.0) +#define EXP_1 exp(1.0) + +#endif /*-------------- ENDE ifdef ----------------------*/ + + +#define NEGMAX -POSMIN /* groesste negative Zahl */ +#define NEGMIN -POSMAX /* kleinste negative Zahl */ + +#define TRUE 1 +#define FALSE 0 + + +/* Definition von Funktionsmakros: + */ + +#define abs(X) ((X) >= 0 ? (X) : -(X)) /* Absolutbetrag von X */ +#define sign(X, Y) (Y < 0 ? -abs(X) : abs(X)) /* Vorzeichen von */ + /* Y mal abs(X) */ +#define sqr(X) ((X) * (X)) /* Quadrat von X */ + +/*------------------- ENDE FILE u_const.h --------------------------*/ + + + + + + + + + +/*.HL Anhang: C - Programme*/ +/*.HRGleichungssysteme fuer Tridiagonalmatrizen*/ + +/*.FE P 3.7 TRIDIAGONALE GLEICHUNGSSYSTEME*/ + + +/*---------------------- MODUL TRIDIAGONAL ------------------------*/ + +USHORT TriDiagGS(BOOL rep, USHORT n, double* lower, + double* diag, double* upper, double* b) + /************************/ + /* GAUSS-Verfahren fuer */ + /* Tridiagonalmatrizen */ + /************************/ + +/*====================================================================*/ +/* */ +/* trdiag bestimmt die Loesung x des linearen Gleichungssystems */ +/* A * x = b mit tridiagonaler n x n Koeffizientenmatrix A, die in */ +/* den 3 Vektoren lower, upper und diag wie folgt abgespeichert ist: */ +/* */ +/* ( diag[0] upper[0] 0 0 . . . 0 ) */ +/* ( lower[1] diag[1] upper[1] 0 . . . ) */ +/* ( 0 lower[2] diag[2] upper[2] 0 . ) */ +/* A = ( . 0 lower[3] . . . ) */ +/* ( . . . . . 0 ) */ +/* ( . . . . . ) */ +/* ( . . . upper[n-2] ) */ +/* ( 0 . . . 0 lower[n-1] diag[n-1] ) */ +/* */ +/*====================================================================*/ +/* */ +/* Anwendung: */ +/* ========= */ +/* Vorwiegend fuer diagonaldominante Tridiagonalmatrizen, wie */ +/* sie bei der Spline-Interpolation auftreten. */ +/* Fuer diagonaldominante Matrizen existiert immer eine LU- */ +/* Zerlegung; fuer nicht diagonaldominante Tridiagonalmatrizen */ +/* sollte die Funktion band vorgezogen werden, da diese mit */ +/* Spaltenpivotsuche arbeitet und daher numerisch stabiler ist. */ +/* */ +/*====================================================================*/ +/* */ +/* Eingabeparameter: */ +/* ================ */ +/* n Dimension der Matrix ( > 1 ) USHORT n */ +/* */ +/* lower untere Nebendiagonale double lower[n] */ +/* diag Hauptdiagonale double diag[n] */ +/* upper obere Nebendiagonale double upper[n] */ +/* */ +/* bei rep != 0 enthalten lower, diag und upper die */ +/* Dreieckzerlegung der Ausgangsmatrix. */ +/* */ +/* b rechte Seite des Systems double b[n] */ +/* rep = 0 erstmaliger Aufruf BOOL rep */ +/* !=0 wiederholter Aufruf */ +/* fuer gleiche Matrix, */ +/* aber verschiedenes b. */ +/* */ +/* Ausgabeparameter: */ +/* ================ */ +/* b Loesungsvektor des Systems; double b[n] */ +/* die urspruengliche rechte Seite wird ueberspeichert */ +/* */ +/* lower ) enthalten bei rep = 0 die Zerlegung der Matrix; */ +/* diag ) die urspruenglichen Werte von lower u. diag werden */ +/* upper ) ueberschrieben */ +/* */ +/* Die Determinante der Matrix ist bei rep = 0 durch */ +/* det A = diag[0] * ... * diag[n-1] bestimmt. */ +/* */ +/* Rueckgabewert: */ +/* ============= */ +/* = 0 alles ok */ +/* = 1 n < 2 gewaehlt */ +/* = 2 Die Dreieckzerlegung der Matrix existiert nicht */ +/* */ +/*====================================================================*/ +/* */ +/* Benutzte Funktionen: */ +/* =================== */ +/* */ +/* Aus der C Bibliothek: fabs() */ +/* */ +/*====================================================================*/ + +/*.cp 5 */ +{ + USHORT i; + short j; + +// double fabs(double); + + if ( n < 2 ) return(1); /* n mindestens 2 */ + + /* Wenn rep = 0 ist, */ + /* Dreieckzerlegung der */ + if (rep == 0) /* Matrix u. det be- */ + { /* stimmen */ + for (i = 1; i < n; i++) + { if ( fabs(diag[i-1]) < MACH_EPS ) /* Wenn ein diag[i] = 0 */ + return(2); /* ist, ex. keine Zerle- */ + lower[i] /= diag[i-1]; /* gung. */ + diag[i] -= lower[i] * upper[i-1]; + } + } + + if ( fabs(diag[n-1]) < MACH_EPS ) return(2); + + for (i = 1; i < n; i++) /* Vorwaertselimination */ + b[i] -= lower[i] * b[i-1]; + + b[n-1] /= diag[n-1]; /* Rueckwaertselimination */ + for (j = n-2; j >= 0; j--) { + i=j; + b[i] = ( b[i] - upper[i] * b[i+1] ) / diag[i]; + } + return(0); +} + +/*----------------------- ENDE TRIDIAGONAL -------------------------*/ + + + + + + + + + +/*.HL Anhang: C - Programme*/ +/*.HRGleichungssysteme mit zyklisch tridiagonalen Matrizen*/ + +/*.FE P 3.8 SYSTEME MIT ZYKLISCHEN TRIDIAGONALMATRIZEN */ + + +/*---------------- MODUL ZYKLISCH TRIDIAGONAL ----------------------*/ + + +USHORT ZyklTriDiagGS(BOOL rep, USHORT n, double* lower, double* diag, + double* upper, double* lowrow, double* ricol, double* b) + /******************************/ + /* Systeme mit zyklisch tri- */ + /* diagonalen Matrizen */ + /******************************/ + +/*====================================================================*/ +/* */ +/* tzdiag bestimmt die Loesung x des linearen Gleichungssystems */ +/* A * x = b mit zyklisch tridiagonaler n x n Koeffizienten- */ +/* matrix A, die in den 5 Vektoren lower, upper, diag, lowrow und */ +/* ricol wie folgt abgespeichert ist: */ +/* */ +/* ( diag[0] upper[0] 0 0 . . 0 ricol[0] ) */ +/* ( lower[1] diag[1] upper[1] 0 . . 0 ) */ +/* ( 0 lower[2] diag[2] upper[2] 0 . ) */ +/* A = ( . 0 lower[3] . . . . ) */ +/* ( . . . . . 0 ) */ +/* ( . . . . . ) */ +/* ( 0 . . . upper[n-2] ) */ +/* ( lowrow[0] 0 . . 0 lower[n-1] diag[n-1] ) */ +/* */ +/* Speicherplatz fuer lowrow[1],..,lowrow[n-3] und ricol[1],..., */ +/* ricol[n-3] muss zusaetzlich bereitgestellt werden, da dieser */ +/* fuer die Aufnahme der Zerlegungsmatrix verfuegbar sein muss, die */ +/* auf die 5 genannten Vektoren ueberspeichert wird. */ +/* */ +/*====================================================================*/ +/* */ +/* Anwendung: */ +/* ========= */ +/* Vorwiegend fuer diagonaldominante zyklische Tridiagonalmatri- */ +/* zen wie sie bei der Spline-Interpolation auftreten. */ +/* Fuer diagonaldominante Matrizen existiert immer eine LU- */ +/* Zerlegung. */ +/* */ +/*====================================================================*/ +/* */ +/* Eingabeparameter: */ +/* ================ */ +/* n Dimension der Matrix ( > 2 ) USHORT n */ +/* lower untere Nebendiagonale double lower[n] */ +/* diag Hauptdiagonale double diag[n] */ +/* upper obere Nebendiagonale double upper[n] */ +/* b rechte Seite des Systems double b[n] */ +/* rep = 0 erstmaliger Aufruf BOOL rep */ +/* !=0 wiederholter Aufruf */ +/* fuer gleiche Matrix, */ +/* aber verschiedenes b. */ +/* */ +/* Ausgabeparameter: */ +/* ================ */ +/* b Loesungsvektor des Systems, double b[n] */ +/* die urspruengliche rechte Seite wird ueberspeichert */ +/* */ +/* lower ) enthalten bei rep = 0 die Zerlegung der Matrix; */ +/* diag ) die urspruenglichen Werte von lower u. diag werden */ +/* upper ) ueberschrieben */ +/* lowrow ) double lowrow[n-2] */ +/* ricol ) double ricol[n-2] */ +/* */ +/* Die Determinante der Matrix ist bei rep = 0 durch */ +/* det A = diag[0] * ... * diag[n-1] bestimmt. */ +/* */ +/* Rueckgabewert: */ +/* ============= */ +/* = 0 alles ok */ +/* = 1 n < 3 gewaehlt */ +/* = 2 Die Zerlegungsmatrix existiert nicht */ +/* */ +/*====================================================================*/ +/* */ +/* Benutzte Funktionen: */ +/* =================== */ +/* */ +/* Aus der C Bibliothek: fabs() */ +/* */ +/*====================================================================*/ + +/*.cp 5 */ +{ + double temp; // fabs(double); + USHORT i; + short j; + + if ( n < 3 ) return(1); + + if (rep == 0) /* Wenn rep = 0 ist, */ + { /* Zerlegung der */ + lower[0] = upper[n-1] = 0.0; /* Matrix berechnen. */ + + if ( fabs (diag[0]) < MACH_EPS ) return(2); + /* Ist ein Diagonalelement */ + temp = 1.0 / diag[0]; /* betragsmaessig kleiner */ + upper[0] *= temp; /* MACH_EPS, so ex. keine */ + ricol[0] *= temp; /* Zerlegung. */ + + for (i = 1; i < n-2; i++) + { diag[i] -= lower[i] * upper[i-1]; + if ( fabs(diag[i]) < MACH_EPS ) return(2); + temp = 1.0 / diag[i]; + upper[i] *= temp; + ricol[i] = -lower[i] * ricol[i-1] * temp; + } + + diag[n-2] -= lower[n-2] * upper[n-3]; + if ( fabs(diag[n-2]) < MACH_EPS ) return(2); + + for (i = 1; i < n-2; i++) + lowrow[i] = -lowrow[i-1] * upper[i-1]; + + lower[n-1] -= lowrow[n-3] * upper[n-3]; + upper[n-2] = ( upper[n-2] - lower[n-2] * ricol[n-3] ) / diag[n-2]; + + for (temp = 0.0, i = 0; i < n-2; i++) + temp -= lowrow[i] * ricol[i]; + diag[n-1] += temp - lower[n-1] * upper[n-2]; + + if ( fabs(diag[n-1]) < MACH_EPS ) return(2); + } /* end if ( rep == 0 ) */ + + b[0] /= diag[0]; /* Vorwaertselemination */ + for (i = 1; i < n-1; i++) + b[i] = ( b[i] - b[i-1] * lower[i] ) / diag[i]; + + for (temp = 0.0, i = 0; i < n-2; i++) + temp -= lowrow[i] * b[i]; + + b[n-1] = ( b[n-1] + temp - lower[n-1] * b[n-2] ) / diag[n-1]; + + b[n-2] -= b[n-1] * upper[n-2]; /* Rueckwaertselimination */ + for (j = n-3; j >= 0; j--) { + i=j; + b[i] -= upper[i] * b[i+1] + ricol[i] * b[n-1]; + } + return(0); +} + +/*------------------ ENDE ZYKLISCH TRIDIAGONAL ---------------------*/ + + +} // extern "C" + + +/************************************************************************* +|* +|* NaturalSpline() +|* +|* Beschreibung Berechnet die Koeffizienten eines natuerlichen +|* kubischen Polynomsplines mit n Stuetzstellen. +|* Ersterstellung JOE 17-08.93 +|* Letzte Aenderung JOE 17-08.93 +|* +*************************************************************************/ + +USHORT NaturalSpline(USHORT n, double* x, double* y, + double Marg0, double MargN, + BYTE MargCond, + double* b, double* c, double* d) +{ + USHORT i; + double* a; + double* h; + USHORT error; + + if (n<2) return 1; + if ( (MargCond & ~3) ) return 2; + a=new double[n+1]; + h=new double[n+1]; + for (i=0;i=MAXROOT) { + alphX=0.0; + alphY=sign(1.0,y[1]-y[0]); + } else { + alphX=sign(sqrt(1.0/(1.0+Marg01*Marg01)),x[1]-x[0]); + alphY=alphX*Marg01; + } + if (abs(MargN1)>=MAXROOT) { + betX=0.0; + betY=sign(1.0,y[n]-y[n-1]); + } else { + betX=sign(sqrt(1.0/(1.0+MargN1*MargN1)),x[n]-x[n-1]); + betY=betX*MargN1; + } + } + } // switch MargCond + if (MargCond==3) { + Error=PeriodicSpline(n,T,x,bx,cx,dx); + if (Error!=0) return(Error+4); + Error=PeriodicSpline(n,T,y,by,cy,dy); + if (Error!=0) return(Error+10); + } else { + Error=NaturalSpline(n,T,x,alphX,betX,MargCond,bx,cx,dx); + if (Error!=0) return(Error+4); + Error=NaturalSpline(n,T,y,alphY,betY,MargCond,by,cy,dy); + if (Error!=0) return(Error+9); + } + return 0; +} + + + +/************************************************************************* +|* +|* CalcSpline() +|* +|* Beschreibung Berechnet die Koeffizienten eines parametrischen +|* natuerlichen oder periodischen kubischen +|* Polynomsplines. Die Eckpunkte des uebergebenen +|* Polygons werden als Stuetzstellen angenommen. +|* n liefert die Anzahl der Teilpolynome. +|* Ist die Berechnung fehlerfrei verlaufen, so +|* liefert die Funktion TRUE. Nur in diesem Fall +|* ist Speicher fuer die Koeffizientenarrays +|* allokiert, der dann spaeter vom Aufrufer mittels +|* delete freizugeben ist. +|* Ersterstellung JOE 17-08.93 +|* Letzte Aenderung JOE 17-08.93 +|* +*************************************************************************/ + +BOOL CalcSpline(Polygon& rPoly, BOOL Periodic, USHORT& n, + double*& ax, double*& ay, double*& bx, double*& by, + double*& cx, double*& cy, double*& dx, double*& dy, double*& T) +{ + BYTE Marg; + double Marg01,Marg02; + double MargN1,MargN2; + USHORT i; + Point P0(-32768,-32768); + Point Pt; + + n=rPoly.GetSize(); + ax=new double[rPoly.GetSize()+2]; + ay=new double[rPoly.GetSize()+2]; + + n=0; + for (i=0;i0) n--; // n Korregieren (Anzahl der Teilpolynome) + + BOOL bRet = FALSE; + if ( ( Marg == 3 && n >= 3 ) || ( Marg == 2 && n >= 2 ) ) + { + bRet = ParaSpline(n,ax,ay,Marg,Marg01,Marg01,MargN1,MargN2,FALSE,T,bx,cx,dx,by,cy,dy) == 0; + } + if ( bRet == FALSE ) + { + delete[] ax; + delete[] ay; + delete[] bx; + delete[] by; + delete[] cx; + delete[] cy; + delete[] dx; + delete[] dy; + delete[] T; + n=0; + } + return bRet; +} + + +/************************************************************************* +|* +|* Spline2Poly() +|* +|* Beschreibung Konvertiert einen parametrichen kubischen +|* Polynomspline Spline (natuerlich oder periodisch) +|* in ein angenaehertes Polygon. +|* Die Funktion liefert FALSE, wenn ein Fehler bei +|* der Koeffizientenberechnung aufgetreten ist oder +|* das Polygon zu gross wird (>PolyMax=16380). Im 1. +|* Fall hat das Polygon 0, im 2. Fall PolyMax Punkte. +|* Um Koordinatenueberlaeufe zu vermeiden werden diese +|* auf +/-32000 begrenzt. +|* Ersterstellung JOE 23.06.93 +|* Letzte Aenderung JOE 23.06.93 +|* +*************************************************************************/ +BOOL Spline2Poly(Polygon& rSpln, BOOL Periodic, Polygon& rPoly) +{ + short MinKoord=-32000; // zur Vermeidung + short MaxKoord=32000; // von Ueberlaeufen + + double* ax; // Koeffizienten der Polynome + double* ay; + double* bx; + double* by; + double* cx; + double* cy; + double* dx; + double* dy; + double* tv; + + double Step; // Schrittweite fuer t + double dt1,dt2,dt3; // Delta t, y, ^3 + double t; + BOOL bEnde; // Teilpolynom zu Ende? + USHORT n; // Anzahl der zu zeichnenden Teilpolynome + USHORT i; // aktuelles Teilpolynom + BOOL bOk; // noch alles ok? + USHORT PolyMax=16380;// Maximale Anzahl von Polygonpunkten + long x,y; + + bOk=CalcSpline(rSpln,Periodic,n,ax,ay,bx,by,cx,cy,dx,dy,tv); + if (bOk) { + Step =10; + + rPoly.SetSize(1); + rPoly.SetPoint(Point(short(ax[0]),short(ay[0])),0); // erster Punkt + i=0; + while (i=tv[i+1]; + if (bEnde) t=tv[i+1]; + dt1=t-tv[i]; dt2=dt1*dt1; dt3=dt2*dt1; + x=long(ax[i]+bx[i]*dt1+cx[i]*dt2+dx[i]*dt3); + y=long(ay[i]+by[i]*dt1+cy[i]*dt2+dy[i]*dt3); + if (xMaxKoord) x=MaxKoord; + if (yMaxKoord) y=MaxKoord; + if (rPoly.GetSize() + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include +#include +#include +#include "sgffilt.hxx" +#include "sgfbram.hxx" +#include "sgvmain.hxx" +// #include "Debug.c" + +extern SgfFontLst* pSgfFonts; + +#ifndef abs +#define abs(x) ((x)<0 ? -(x) : (x)) +#endif + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Einschraenkungen: Schatten nur grau, 2D und mit fixem Abstand. +// +// +// +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +// AbsBase.Pas + +// die folgenden Werte sind in % vom maximalen Schriftgrad der Zeile */ +#define UndlSpace 5 /* Untersteichungsabstand von der Baseline */ +#define UndlWidth 6 /* Untersteichungsdicke */ +#define UndlSpac2 7 /* Zwischenraum bei doppelter Unterstreichung */ +#define StrkSpace 25 /* Abstand der Durchstreichlinie von der Baseline*/ +#define StrkWidth 5 /* Durchstreichungsliniendicke */ +#define StrkSpac2 7 /* Zwischenraum bei doppelter Durchstreichung */ +#define OutlWidth 2 /* Strichstaerke ist 2% vom Schriftgrad */ + +// vvv Sonderzeichen im TextBuffer vvv +#define TextEnd 0 /* ^@ Ende der Zeichenkette */ +#define HardSpace 6 /* ^F Hartspace (wird nicht umbrochen) ,' ' */ +#define GrafText 7 /* ^G Im Text eingebundene Grafik (future) */ +#define Tabulator 9 /* ^I Tabulatorzeichen, Pfeil */ +#define LineFeed 10 /* ^J Neue Zeile */ +#define SoftTrennK 11 /* ^K Zeichen fuer k-c-Austausch bei Trennung, 'k' */ +#define AbsatzEnd 13 /* ^M Neuer Absatz =CR */ +#define HardTrenn 16 /* ^P Hartes Trennzeichen (wird nicht umbrochen), '-' */ +#define SoftTrennAdd 19 /* ^S Zusatz-Zeichen Trennung von z.b."Schiff-fahrt" */ +#define Paragraf 21 /* ^U Zeichen welches fuer Paragraf-Zeichen */ +#define Escape 27 /* ^[ Escapesequenz einleiten */ +#define SoftTrenn 31 /* ^_ Weiches Trennzeichen, '-' nur Zeilenende */ +#define MaxEscValLen 8 +#define MaxEscLen (MaxEscValLen+3) + +//============================================================================== +// Escapesequenzen: [Esc][Esc] also mind. 4 Char +// Max. Laenge von Value soll sein: 8 Char (7+Vorzeichen). Demnach max. Laenge +// einer Escapesequenz: 11 Char. +// Identifer: + +#define EscFont 'F' /* FontID, z.B. 92500 fuer CG Times */ +#define EscGrad 'G' /* Schriftgrad 1..255 fuer <0)) || + ((F.FBFarbe!=L.LBFarbe) && (F.FIntens<100)); +} + + +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +// Misc.Pas + +short hPoint2Sgf(short a) +{ + long b; + b=long(a)*127*SgfDpmm/(144*5); + return short(b); +} + +short Sgf2hPoint(short a) +{ + long b; + b=long(a)*5*144/(127*SgfDpmm); + return short(b); +} + +// End of Misc.Pas +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// + + + +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +// AbsRead.Pas + +// ====================================================================== +// Function GetTopToBaseLine() Function GetBaseLineToBtm() +// +// Abstand von Zeilenoberkante bis BaseLine bzw. von BaseLine bis +// Unterkante berechnen. Alles in SGF-Units. +// ====================================================================== + +USHORT GetTopToBaseLine(USHORT MaxGrad) +{ + long ret; + ret=long(MaxGrad)*long(CharTopToBase) /long(100); + return USHORT(ret); +} + +// ====================================================================== +// Function GetTextChar() Function GetTextCharConv() +// +// Liest ein Zeichen aus dem Textbuffer, wertet dabei eventuell +// auftretende Escapesequenzen aus und setzt dementsprechend den +// Ein-/Ausgabeparameter AktAtr. Index wird entsprechend erhoeht. +// Der Parameter Rest muss immer die Anzahl der Zeichen beinhalten, +// den angeforderten Zeichen in der aktuellen Zeile noch folgen. +// Ansonsten funktioniert die Silbentrennung nicht richtig. Gibt man +// stattdessen die Konstante NoTrenn an, wird in keinem Fall +// getrennt, die Konstante DoTrenn bewirkt dagegen, dass ueberall dort +// getrennt wird, wo ein SoftTrenner vorkommt. +// +// SoftTrenner werden immer in ein Minuszeichen konvertiert. +// GetTextCharConv() konvertiert zusaetzlich HardSpace und AbsatzEnde +// in Spaces sowie HardTrenner in Minuszeichen. TextEnde wird immer +// als Char(0) geliefert. +// ====================================================================== + + + +UCHAR ConvertTextChar(UCHAR c) +{ + if (c<32) { + switch (c) { + case HardSpace : c=' '; break; + case AbsatzEnd : c=' '; break; + case SoftTrenn : c='-'; break; + case HardTrenn : c='-'; break; + case SoftTrennK : c='-'; break; + case SoftTrennAdd: c='-'; + } + } + return c; +} + + + +USHORT GetSchnittBit(UCHAR c) +{ + USHORT r=0; + switch (c) { + case EscBold : r=TextBoldBit; break; + case EscRSlnt: r=TextRSlnBit; break; + case EscUndln: r=TextUndlBit; break; + case EscStrik: r=TextStrkBit; break; + case EscDbUnd: r=TextDbUnBit; break; + case EscDbStk: r=TextDbStBit; break; + case EscSupSc: r=TextSupSBit; break; + case EscSubSc: r=TextSubSBit; break; + case EscKaptF: r=TextKaptBit; break; + case EscLSlnt: r=TextLSlnBit; break; + case Esc2DShd: r=TextSh2DBit; break; + case Esc3DShd: r=TextSh3DBit; break; + case Esc4DShd: r=TextSh4DBit; break; + case EscEbShd: r=TextShEbBit; + } + return r; +} + + + +long ChgValue(long Def, long Min, long Max, UCHAR FlgVal, long NumVal) +{ + long r=0; + + if (FlgVal==EscDeflt) { + r=Def; // zurueck auf Default + } else { + if (NumVal!=EscNoVal) r=NumVal; // Hart setzen + } + + if (Min!=0 || Max!=0) { + if (r>Max) r=Max; + if (r'9'); + if (EoVal==FALSE) { c=TBuf[Index]; Index++; } + i--; + } while (i>0 && EoVal==FALSE); + NumVal=Sgn*NumVal; + } + q=!CheckTextOutl(AktAtr.F,AktAtr.L); + + switch (Ident) { + case EscFont : AktAtr.SetFont(ULONG (ChgValue(Atr0.GetFont(),0,0 ,FlgVal,NumVal)));break; + case EscGrad : AktAtr.Grad =USHORT(ChgValue(Atr0.Grad, 2,2000 ,FlgVal,NumVal)); break; + case EscBreit: AktAtr.Breite =USHORT(ChgValue(Atr0.Breite, 1,1000 ,FlgVal,NumVal)); break; + case EscKaptS: AktAtr.Kapit =(BYTE)(ChgValue(Atr0.Kapit, 1,255 ,FlgVal,NumVal)); break; + case EscLFeed: AktAtr.LnFeed =USHORT(ChgValue(Atr0.LnFeed, 1,65535 ,FlgVal,NumVal)); break; + case EscSlant: AktAtr.Slant =USHORT(ChgValue(Atr0.Slant, 1,MaxCharSlant ,FlgVal,NumVal)); break; + case EscVPos : AktAtr.ChrVPos=char (ChgValue(Atr0.ChrVPos,-128,127 ,FlgVal,NumVal)); break; + case EscZAbst: AktAtr.ZAbst =(BYTE)(ChgValue(Atr0.ZAbst, 1,255 ,FlgVal,NumVal)); break; + case EscHJust: AktAtr.Justify=(BYTE)(ChgValue(Atr0.Justify & 0x0F,0,5 ,FlgVal,NumVal)); break; + case EscFarbe: { AktAtr.L.LFarbe =(BYTE)(ChgValue(Atr0.L.LFarbe,0,7 ,FlgVal,NumVal)); if (q) AktAtr.F.FFarbe =AktAtr.L.LFarbe; } break; + case EscBFarb: { AktAtr.L.LBFarbe=(BYTE)(ChgValue(Atr0.L.LBFarbe,0,255,FlgVal,NumVal)); if (q) AktAtr.F.FBFarbe=AktAtr.L.LBFarbe; } break; + case EscInts : { AktAtr.L.LIntens=(BYTE)(ChgValue(Atr0.L.LIntens,0,100,FlgVal,NumVal)); if (q) AktAtr.F.FIntens=AktAtr.L.LIntens; } break; + + case EscMustr: { AktAtr.F.FMuster=USHORT(ChgValue(Atr0.F.FMuster,0,65535,FlgVal,NumVal)); } break; + case EscMFarb: { AktAtr.F.FFarbe =(BYTE)(ChgValue(Atr0.F.FFarbe,0,7 ,FlgVal,NumVal)); } break; + case EscMBFrb: { AktAtr.F.FBFarbe=(BYTE)(ChgValue(Atr0.F.FBFarbe,0,255,FlgVal,NumVal)); } break; + case EscMInts: { AktAtr.F.FIntens=(BYTE)(ChgValue(Atr0.F.FIntens,0,100,FlgVal,NumVal)); } break; + + case EscSMstr: { AktAtr.ShdF.FMuster=USHORT(ChgValue(Atr0.ShdF.FMuster,0,65535,FlgVal,NumVal)); } break; + case EscSFarb: { AktAtr.ShdL.LFarbe =(BYTE)(ChgValue(Atr0.ShdL.LFarbe,0,7 ,FlgVal,NumVal)); AktAtr.ShdF.FFarbe =AktAtr.ShdL.LFarbe; } break; + case EscSBFrb: { AktAtr.ShdL.LBFarbe=(BYTE)(ChgValue(Atr0.ShdL.LBFarbe,0,255,FlgVal,NumVal)); AktAtr.ShdF.FBFarbe=AktAtr.ShdL.LBFarbe; } break; + case EscSInts: { AktAtr.ShdL.LIntens=(BYTE)(ChgValue(Atr0.ShdL.LIntens,0,100,FlgVal,NumVal)); AktAtr.ShdF.FIntens=AktAtr.ShdL.LIntens; } break; + case EscSDist: { AktAtr.ShdVers.x=(short)ChgValue(Atr0.ShdVers.x,0,30000,FlgVal,NumVal); AktAtr.ShdVers.y=AktAtr.ShdVers.x; } break; + case EscSXDst: { AktAtr.ShdVers.x=(short)ChgValue(Atr0.ShdVers.x,0,30000,FlgVal,NumVal); } break; + case EscSYDst: { AktAtr.ShdVers.y=(short)ChgValue(Atr0.ShdVers.y,0,30000,FlgVal,NumVal); } break; + + case EscBold : ChgSchnittBit(TextBoldBit,0,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + case EscRSlnt: ChgSchnittBit(TextRSlnBit,TextLSlnBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + case EscUndln: ChgSchnittBit(TextUndlBit,TextDbUnBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + case EscStrik: ChgSchnittBit(TextStrkBit,TextDbStBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + case EscDbUnd: ChgSchnittBit(TextDbUnBit,TextUndlBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + case EscDbStk: ChgSchnittBit(TextDbStBit,TextStrkBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + case EscSupSc: ChgSchnittBit(TextSupSBit,TextSubSBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + case EscSubSc: ChgSchnittBit(TextSubSBit,TextSupSBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + case EscKaptF: ChgSchnittBit(TextKaptBit,0,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + case EscLSlnt: ChgSchnittBit(TextLSlnBit,TextRSlnBit,0,0 ,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + case Esc2DShd: ChgSchnittBit(TextSh2DBit,TextSh3DBit,TextSh4DBit,TextShEbBit,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + case Esc3DShd: ChgSchnittBit(TextSh3DBit,TextSh2DBit,TextSh4DBit,TextShEbBit,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + case Esc4DShd: ChgSchnittBit(TextSh4DBit,TextSh2DBit,TextSh3DBit,TextShEbBit,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + case EscEbShd: ChgSchnittBit(TextShEbBit,TextSh2DBit,TextSh3DBit,TextSh4DBit,FlgVal,Atr0.Schnitt,AktAtr.Schnitt); break; + } //endcase + if (TBuf[Index]==Escape) Index++; // zweites Esc weglesen } + } // if Ende==FALSE + } while (Ende==FALSE && ScanEsc==FALSE); + if (Ende==FALSE) c=Escape; + return c; +} // end of ProcessOne + + +UCHAR GetTextChar(UCHAR* TBuf, USHORT& Index, + ObjTextType& Atr0, ObjTextType& AktAtr, + USHORT Rest, BOOL ScanEsc) +{ + UCHAR c,c0,nc; + + c=ProcessOne(TBuf,Index,Atr0,AktAtr,ScanEsc); + if (ScanEsc==FALSE) { + if (c==SoftTrennAdd || c==SoftTrennK || c==SoftTrenn) { + nc=GetNextChar(TBuf,Index); + c0=c; + if (Rest==0 || Rest==DoTrenn || + nc==' ' || nc==AbsatzEnd || nc==TextEnd) c='-'; + else { + c=ProcessOne(TBuf,Index,Atr0,AktAtr,ScanEsc); // den Trenner ueberspringen + if (c0==SoftTrennAdd) { + if (c>=32) c=ProcessOne(TBuf,Index,Atr0,AktAtr,ScanEsc); // und hier noch 'nen Buchstaben ueberspringen + } + } + } + if ((Rest==1 || Rest==DoTrenn) && GetNextChar(TBuf,Index)==SoftTrennK) { + if (c=='c') c='k'; + else if (c=='C') c='K'; + } + } + return c; +} + + // HardSpace und HardTrenn muessen explizit konvertiert werden ! } + // if AktAtr.Schnitt and TextKaptBit =TextKaptBit then c:=UpCase(c);(explizit) } + + // Bei der Trennmethode SoftTrennAdd wird davon ausgegangen, dass der zu } + // trennende Konsonant bereits 3x mal im TextBuf vorhanden ist, z.b.: } + // "Schiff-fahrt". Wenn nicht getrennt, dann wird "-f" entfernt. } + + + +UCHAR GetTextCharConv(UCHAR* TBuf, USHORT& Index, + ObjTextType& Atr0, ObjTextType& AktAtr, + USHORT Rest, BOOL ScanEsc) +{ + UCHAR c; + + c=GetTextChar(TBuf,Index,Atr0,AktAtr,Rest,ScanEsc); + if (c<32) { + switch (c) { + case HardSpace : c=' '; break; + case AbsatzEnd : c=' '; break; + case HardTrenn : c='-'; + } + } + return c; +} + + +// ====================================================================== +// Function GetLineFeed() +// +// Benoetigter Zeilenabstand in SGF-Units. ChrVPos wird beruecksichtigt. +// ====================================================================== +USHORT GetLineFeed(UCHAR* TBuf, USHORT Index, ObjTextType Atr0, ObjTextType AktAtr, + USHORT nChar, USHORT& LF, USHORT& MaxGrad) +{ + UCHAR c=0; + BOOL AbsEnd=FALSE; + ULONG LF100=0; + ULONG MaxLF100=0; + BOOL LFauto=0; + BOOL First=TRUE; + USHORT Grad; + USHORT i=0; + USHORT r=1; + + MaxGrad=0; + while (!AbsEnd && nChar>0) { + nChar--; + c=GetTextChar(TBuf,Index,Atr0,AktAtr,nChar,FALSE); + i++; + AbsEnd=(c==TextEnd || c==AbsatzEnd); + if (First || (!AbsEnd && c!=' ' && c!=HardTrenn)) { + LFauto=(AktAtr.LnFeed & 0x8000)==0; + LF100=AktAtr.LnFeed & 0x7FFF; + if (LFauto) LF100=LF100*AktAtr.Grad; else LF100*=LF100; + if (AktAtr.ChrVPos>0) LF100-=AktAtr.ChrVPos*100; + if (LF100>MaxLF100) MaxLF100=LF100; + Grad=AktAtr.Grad; + if (AktAtr.ChrVPos>0) Grad=Grad-AktAtr.ChrVPos; + if (Grad>MaxGrad) MaxGrad=Grad; + First=FALSE; + } + if (!AbsEnd && c!=' ') r=i; + } + MaxGrad=hPoint2Sgf(MaxGrad); + if (MaxLF100<=4000) { // sonst Overflowgefahr + LF=USHORT(hPoint2Sgf(short(MaxLF100)) /100); + } else { + LF=USHORT(hPoint2Sgf(short(MaxLF100) /100)); + } + + return r; +} + +// End of AbsRead.Pas +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// + + + +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +// iFont.Pas + +#define DefaultSlant 1500 /* Default: Italic ist 15deg */ +#define SuperSubFact 60 /* SuperScript/SubScript: 60% vom Schriftgrad */ +#define DefaultSpace 40 /* Default: Space ist 40% vom SchriftGrad */ + +USHORT SetTextContext(OutputDevice& rOut, ObjTextType& Atr, BOOL Kapt, USHORT Dreh, + USHORT FitXMul, USHORT FitXDiv, USHORT FitYMul, USHORT FitYDiv) +{ + SgfFontOne* pSgfFont; // Font aus dem IniFile + Font aFont; + Color aColor; + ULONG Grad; + ULONG Brei; + String FNam; + USHORT StdBrei=50; // Durchschnittliche Zeichenbreite in % von Schriftgrad + BOOL bFit=(FitXMul!=1 || FitXDiv!=1 || FitYMul!=1 || FitYDiv!=1); + + pSgfFont = pSgfFonts->GetFontDesc(Atr.GetFont()); + + if ( pSgfFont!=NULL ) + { + FNam =pSgfFont->SVFName; + StdBrei=pSgfFont->SVWidth; + if (pSgfFont->Fixd) aFont.SetPitch(PITCH_FIXED); else aFont.SetPitch(PITCH_VARIABLE); + aFont.SetFamily(pSgfFont->SVFamil); + aFont.SetCharSet(pSgfFont->SVChSet); + aFont.SetName(FNam); + } + else + { // Falls nich im Inifile, sind hier einige Fonts hart kodiert + aFont.SetPitch(PITCH_VARIABLE); + switch (Atr.GetFont()) { + case 92500: case 92501: case 92504: case 92505: + { +#if defined(WNT) || defined(PM2) + FNam=String::CreateFromAscii( "Times New Roman" ); // CG Times ist unter Windows und OS/2 Times New Roman +#else + FNam=String::CreateFromAscii( "Times" ); // ansonsten ist das einfach Times +#endif + StdBrei=40; + aFont.SetFamily(FAMILY_ROMAN); + } break; + case 94021: case 94022: case 94023: case 94024: { +#if defined(WNT) + FNam=String::CreateFromAscii( "Arial", 5 ); // Univers ist unter Windows Arial +#else + FNam=String::CreateFromAscii( "Helvetica" ); // und ansonsten Helvetica +#endif + aFont.SetFamily(FAMILY_SWISS); + StdBrei=47; + } break; + case 93950: case 93951: case 93952: case 93953: { +#if defined(WNT) + FNam=String::CreateFromAscii( "Courier New" ); // Der Vector-Courierfont unter Windows heisst Courier New +#else + FNam=String::CreateFromAscii( "Courier" ); // ansonsten ist und bleibt Courier immer Courier +#endif + aFont.SetFamily(FAMILY_ROMAN); + aFont.SetPitch(PITCH_FIXED); + } break; + default: FNam=String::CreateFromAscii( "Helvetica", 9 ); + } + aFont.SetName(FNam); + //aFont.SetCharSet(CHARSET_SYSTEM); + } + + Grad=ULONG(Atr.Grad); + if ((Atr.Schnitt & TextKaptBit) !=0 && Kapt) Grad=Grad*ULONG(Atr.Kapit)/100; + if ((Atr.Schnitt & TextSupSBit) !=0 || (Atr.Schnitt & TextSubSBit) !=0) Grad=Grad*SuperSubFact/100; + Brei=Grad; + if (Atr.Breite!=100 || bFit) { + if (bFit) { + Grad=Grad*ULONG(FitYMul)/ULONG(FitYDiv); + Brei=Brei*ULONG(FitXMul)/ULONG(FitXDiv); + } + Brei=Brei*ULONG(Atr.Breite)/100; + Brei=Brei*ULONG(StdBrei)/100; + aFont.SetSize(Size(hPoint2Sgf(USHORT(Brei)),hPoint2Sgf(USHORT(Grad)))); + } else { + aFont.SetSize(Size(0,hPoint2Sgf(USHORT(Grad)))); + } + + aColor=Sgv2SvFarbe(Atr.L.LFarbe,Atr.L.LBFarbe,Atr.L.LIntens); aFont.SetColor(aColor); + aColor=Sgv2SvFarbe(Atr.F.FFarbe,Atr.F.FBFarbe,Atr.F.FIntens); aFont.SetFillColor(aColor); + aFont.SetTransparent(TRUE); + aFont.SetAlign(ALIGN_BASELINE); + + Dreh/=10; Dreh=3600-Dreh; if (Dreh==3600) Dreh=0; + aFont.SetOrientation(Dreh); + + if ((Atr.Schnitt & TextBoldBit) !=0) aFont.SetWeight(WEIGHT_BOLD); + if ((Atr.Schnitt & TextRSlnBit) !=0) aFont.SetItalic(ITALIC_NORMAL); + if ((Atr.Schnitt & TextUndlBit) !=0) aFont.SetUnderline(UNDERLINE_SINGLE); + if ((Atr.Schnitt & TextDbUnBit) !=0) aFont.SetUnderline(UNDERLINE_DOUBLE); + if ((Atr.Schnitt & TextStrkBit) !=0) aFont.SetStrikeout(STRIKEOUT_SINGLE); + if ((Atr.Schnitt & TextDbStBit) !=0) aFont.SetStrikeout(STRIKEOUT_DOUBLE); + if ((Atr.Schnitt & TextSh2DBit) !=0) aFont.SetShadow(TRUE); + if ((Atr.Schnitt & TextSh3DBit) !=0) aFont.SetShadow(TRUE); + if ((Atr.Schnitt & TextSh4DBit) !=0) aFont.SetShadow(TRUE); + if ((Atr.Schnitt & TextShEbBit) !=0) aFont.SetShadow(TRUE); + if (CheckTextOutl(Atr.F,Atr.L)) aFont.SetOutline(TRUE); + + if (aFont!=rOut.GetFont()) rOut.SetFont(aFont); + + return 0; +} + +// iFont.Pas +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +// Absatz.Pas + +struct ProcChrSta { + USHORT Index; + USHORT ChrXP; + UCHAR OutCh; + BOOL Kapt; + ObjTextType Attrib; +}; + +void InitProcessCharState(ProcChrSta& State, ObjTextType& AktAtr, USHORT IndexA) +{ + State.Attrib=AktAtr; + State.OutCh=0; + State.Index=IndexA; + State.ChrXP=0; + State.Kapt=FALSE; +} + +BOOL UpcasePossible(UCHAR c) +{ + if ((c>='a' && c<='z') || c == 0xe4 || c == 0xf6 || c == 0xfc ) return TRUE; + else return FALSE; +} + +UCHAR Upcase(UCHAR c) +{ + if ((c>=(UCHAR)'a' && c<=(UCHAR)'z')) c=(c-(UCHAR)'a')+(UCHAR)'A'; + else if ( c == 0xe4 ) c = 0xc4; + else if ( c == 0xf6 ) c = 0xd6; + else if ( c == 0xfc ) c = 0xdc; + return c; +} + +USHORT GetCharWidth(OutputDevice& rOut, UCHAR c) +{ + UCHAR c1; + USHORT ChrWidth; + + c1 = ByteString::Convert((char)c,RTL_TEXTENCODING_IBM_437, gsl_getSystemTextEncoding() ); + if (c==' ') + { + ChrWidth=(USHORT)rOut.GetTextWidth( String('A') ); + if (rOut.GetFont().GetPitch()!=PITCH_FIXED) { + ChrWidth=MulDiv(ChrWidth,DefaultSpace,100); + } + } else { + // with MaxChar == 255 c cannot be greater than MaxChar + // assert if MaxChar is ever changed + OSL_ENSURE( MaxChar == 255, "MaxChar not 255" ); + if (c>=MinChar /*&& c<=MaxChar*/) + { + ChrWidth=(USHORT)rOut.GetTextWidth(String((char)c1)); + } + else + { + ChrWidth=(USHORT)rOut.GetTextWidth(String('A')); + } + } + return ChrWidth; +} + +UCHAR ProcessChar(OutputDevice& rOut, UCHAR* TBuf, ProcChrSta& R, ObjTextType& Atr0, + USHORT& nChars, USHORT Rest, + short* Line, UCHAR* cLine) +{ + USHORT KernDist=0; // Wert fuer Kerning + USHORT ChrWidth; + UCHAR c; + UCHAR c1; + BOOL AbsEnd; + + c=GetTextChar(TBuf,R.Index,Atr0,R.Attrib,Rest,FALSE); // versucht evtl. zu trennen, wenn Rest entsprechenden Wert besitzt + + AbsEnd=(c==AbsatzEnd || c==TextEnd); + if (AbsEnd==FALSE) { + R.OutCh=ConvertTextChar(c); // von HardTrenn nach '-', ... + R.Kapt=(R.Attrib.Schnitt & TextKaptBit) !=0 && UpcasePossible(R.OutCh); + if (R.Kapt) R.OutCh=Upcase(R.OutCh); + SetTextContext(rOut,R.Attrib,R.Kapt,0,1,1,1,1); + + if (R.Kapt) c1=Upcase(c); else c1=c; + ChrWidth=GetCharWidth(rOut,c1); + + if (R.Attrib.ZAbst!=100) { // Spezial-Zeichenabstand ? + ULONG Temp; + Temp=ULONG(ChrWidth)*ULONG(R.Attrib.ZAbst)/100; + ChrWidth=USHORT(Temp); + } + nChars++; + if (R.ChrXP>32000) R.ChrXP=32000; + Line[nChars]=R.ChrXP-KernDist; + cLine[nChars]=c; + R.ChrXP+=ChrWidth-KernDist; // Position fuer den naechsten Character + } + return c; +} + +void FormatLine(UCHAR* TBuf, USHORT& Index, ObjTextType& Atr0, ObjTextType& AktAtr, + USHORT UmbWdt, USHORT AdjWdt, + short* Line, USHORT& nChars, + double, double, + UCHAR* cLine, BOOL TextFit) +{ + VirtualDevice vOut; + UCHAR c,c0; + UCHAR ct; + BOOL First; // erster Char ? + BYTE Just = 0; // Absatzformatierung + BOOL Border; // Rand der Box erreicht ? + BOOL Border0; + BOOL AbsEnd; // Ende des Absatzes erreicht ? + ProcChrSta* R=new ProcChrSta; + ProcChrSta* R0=new ProcChrSta; + ProcChrSta* WErec=new ProcChrSta; + USHORT WEnChar; + ProcChrSta* WErec0=new ProcChrSta; + USHORT WEnChar0; + ProcChrSta* TRrec=new ProcChrSta; + USHORT TRnChar; + + USHORT WordEndCnt; // Justieren und Trennen + BOOL WordEnd; + BOOL Trenn; + + short BoxRest; // zum Quetschen und formatieren + USHORT i,j,k,h; + USHORT re,li; + + vOut.SetMapMode(MapMode(MAP_10TH_MM,Point(),Fraction(1,4),Fraction(1,4))); + + nChars=0; + SetTextContext(vOut,AktAtr,FALSE,0,1,1,1,1); + InitProcessCharState(*R,AktAtr,Index); + (*R0)=(*R); (*WErec)=(*R); WEnChar=0; c0=0; Border0=FALSE; + Border=FALSE; First=TRUE; + WordEndCnt=0; + + do { // mal schauen, wieviele Worte so in die Zeile passen + if (Border) c=ProcessChar(vOut,TBuf,*R,Atr0,nChars,DoTrenn,Line,cLine); + else c=ProcessChar(vOut,TBuf,*R,Atr0,nChars,NoTrenn,Line,cLine); + AbsEnd=(c==AbsatzEnd || c==TextEnd); + //if not AbsEnd then + { + if (First) { + Just=R->Attrib.Justify & 0x0F; // Absatzformat steht wenn, dann am Anfang + } + Border=R->ChrXP>UmbWdt; + WordEnd=(AbsEnd || (c==' ')) && (c0!=' ') && (c0!=0); + Trenn=c=='-'; + if (WordEnd && !Border0) { + WordEndCnt++; + (*WErec)=(*R0); + WEnChar=nChars-1; + } + if (Trenn && !Border) { + WordEndCnt++; + (*WErec)=(*R); + WEnChar=nChars; + } + } + (*R0)=(*R); c0=c; + Border0=Border; + First=FALSE; + AbsEnd=AbsEnd || (nChars>=MaxLineChars); + } while (!(AbsEnd || (Border && ((WordEndCnt>0) || WordEnd || Trenn)))); + + if (Border) { // Trennen und Quetschen + (*WErec0)=(*WErec); WEnChar0=WEnChar; + AbsEnd=FALSE; c0=0; + (*R)=(*WErec); nChars=WEnChar; + (*TRrec)=(*R); TRnChar=nChars; + Border0=FALSE; Border=FALSE; + do { // erst mal gucken wieviele Silben noch reinpassen + ct=ProcessChar(vOut,TBuf,*TRrec,Atr0,TRnChar,DoTrenn,Line,cLine); + c=ProcessChar(vOut,TBuf,*R,Atr0,nChars,NoTrenn,Line,cLine); + AbsEnd=(ct==AbsatzEnd) || (ct==TextEnd) || (nChars>=MaxLineChars); + + Border=TRrec->ChrXP>UmbWdt; + WordEnd=AbsEnd || ((AbsEnd || (c==' ')) && (c0!=' ') && (c0!=0)); + Trenn=ct=='-'; + if (WordEnd && (!Border0 || (WordEndCnt==0))) { + WordEndCnt++; + (*WErec)=(*R0); + if (AbsEnd) WEnChar=nChars; else WEnChar=nChars-1; + (*TRrec)=(*R); TRnChar=nChars; // zum weitersuchen + } + if (Trenn && (!Border || (WordEndCnt==0))) { + WordEndCnt++; // merken, dass man hier trennen kann + (*WErec)=(*TRrec); + WEnChar=TRnChar; + (*TRrec)=(*R); TRnChar=nChars; // zum weitersuchen + } + (*R0)=(*R); c0=c; + Border0=Border; + Border=R->ChrXP>UmbWdt; + } while (!(AbsEnd || (Border && ((WordEndCnt>0) || WordEnd || Trenn)))); + + while (WErec0->IndexIndex) { // damit Line[] auch garantiert stimmt } + c=ProcessChar(vOut,TBuf,*WErec0,Atr0,WEnChar0,WEnChar-WEnChar0-1,Line,cLine); + } + + (*R)=(*WErec); nChars=WEnChar; + + if (UmbWdt>=R->ChrXP) { + BoxRest=UmbWdt-R->ChrXP; + } else { // Zusammenquetschen + BoxRest=R->ChrXP-UmbWdt; // um soviel muss gequetscht werden + for (i=2;i<=nChars;i++) { // 1. CharPosition bleibt ! + Line[i]-=(i-1)*(BoxRest) /(nChars-1); + } + R->ChrXP=UmbWdt; + Line[nChars+1]=UmbWdt; + } + } + + if (!AbsEnd) { + do { // Leerzeichen weglesen + (*WErec)=(*R); + c=GetTextChar(TBuf,R->Index,Atr0,R->Attrib,NoTrenn,FALSE); + nChars++; + Line[nChars]=R->ChrXP; + cLine[nChars]=c; + } while (c==' '); + if (c!=' ' && c!=AbsatzEnd && c!=TextEnd) { + nChars--; + (*R)=(*WErec); + } + } + + if (AbsEnd && nCharsChrXP; // Damit AbsatzEnde auch weggelesen wird + Line[nChars+1]=R->ChrXP; // denn die Breite von CR oder #0 ist nun mal sehr klein + if (TBuf[R->Index-1]!=AbsatzEnd && TBuf[R->Index-1]!=TextEnd) { + c=GetTextChar(TBuf,R->Index,Atr0,R->Attrib,NoTrenn,FALSE); // Kleine Korrektur. Notig, wenn nur 1 Wort in + } + } + + BoxRest=AdjWdt-R->ChrXP; + if (TextFit) Just=THJustLeft; + + switch (Just) { + case THJustLeft: break; // Links + case THJustCenter: { + BoxRest=BoxRest /2; // Mitte + for (i=1;i<=nChars;i++) Line[i]=Line[i]+BoxRest; + } break; + case THJustRight: { // Rechts + for (i=1;i<=nChars;i++) Line[i]=Line[i]+BoxRest; + } break; + case THJustDrvOut: + case THJustBlock: { // Block und Austreibend + re=nChars; + if (Just==THJustDrvOut) re--; + while (re>=1 && (cLine[re]==' ' || cLine[re]==TextEnd || cLine[re]==AbsatzEnd)) re--; + li=1; + while (li<=re && (cLine[li]==' ' || cLine[li]==TextEnd || cLine[li]==AbsatzEnd)) li++; + if (Just==THJustDrvOut) BoxRest=AdjWdt-Line[re+1]; + + j=0; // Anzahl der Spaces ermitteln + for (i=li;i<=re;i++) { + if (cLine[i]==' ') { + j++; + } + } + + if (j==0) { // nur 1 Wort ? -> Strecken ! + for (i=li+1;i<=re;i++) { // von links nach rechts + Line[i]=Line[i]+MulDiv(i-li,BoxRest,re-li+1-1); + } + } else { + k=0; h=0; + for (i=li;i<=re;i++) { // j Spaces aufbohren ! + if (cLine[i]==' ') { // Space gefunden ! + k++; + h=MulDiv(k,BoxRest,j); + } + Line[i]=Line[i]+h; + } + } + for (i=re+1;i<=nChars;i++) Line[i]=Line[i]+BoxRest; // und den Rest anpassen + Line[nChars+1]=AdjWdt; + } break; + case THJustLocked: { //Gesperrt + re=nChars-1; + while (re>=1 && (cLine[re]==' ' || cLine[re]==TextEnd || cLine[re]==AbsatzEnd)) re--; + li=1; + while (li<=re && (cLine[li]==' ' || cLine[li]==TextEnd || cLine[li]==AbsatzEnd)) li++; + BoxRest=AdjWdt-Line[re+1]; + for (i=li+1;i<=re;i++) { // Strecken von links nach rechts + Line[i]=Line[i]+MulDiv(i-li,BoxRest,re-li+1-1); + } + for (i=re+1;i<=nChars;i++) Line[i]=Line[i]+BoxRest; // und den Rest anpassen + Line[nChars+1]=AdjWdt; + } break; + } + Index=R->Index; + AktAtr=R->Attrib; + delete R; + delete R0; + delete WErec; + delete WErec0; + delete TRrec; +} + + + +// End of Absatz.Pas +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +// DrawText.Pas + +void DrawChar(OutputDevice& rOut, UCHAR c, ObjTextType T, PointType Pos, USHORT DrehWink, + USHORT FitXMul, USHORT FitXDiv, USHORT FitYMul, USHORT FitYDiv) +{ + SetTextContext(rOut,T,UpcasePossible(c),DrehWink,FitXMul,FitXDiv,FitYMul,FitYDiv); + if ((T.Schnitt & TextKaptBit)!=0 && UpcasePossible(c)) c=Upcase(c); + String s( (char)c, RTL_TEXTENCODING_IBM_437 ); + rOut.DrawText( Point( Pos.x, Pos.y ), s ); +} + +/************************************************************************* +|* +|* TextType::Draw() +|* +|* Beschreibung +|* Ersterstellung JOE 09.08.93 +|* Letzte Aenderung JOE 09.08.93 +|* +*************************************************************************/ +void TextType::Draw(OutputDevice& rOut) +{ + if ((Flags & TextOutlBit)!=0) return; // Sourcetext fuer Outliner !! + + ObjTextType T1,T2; + USHORT Index1; + USHORT Index2; + UCHAR c = TextEnd; + USHORT l; // Anzahl der Zeichen in der Zeile + USHORT i; + short yPos0; + short xPos; + short yPos; + USHORT LF; + USHORT MaxGrad; + short xSize; + short xSAdj; + short ySize; + double sn,cs; + USHORT TopToBase; + BOOL Ende = 0; + USHORT lc; + BOOL LineFit; // FitSize.x=0? oder Flags -> jede Zeile stretchen + BOOL TextFit; + short* xLine; + UCHAR* cLine; // Buffer fuer FormatLine + USHORT FitXMul; + USHORT FitXDiv; + USHORT FitYMul; + USHORT FitYDiv; + BOOL Fehler; + UCHAR* Buf=Buffer; // Zeiger auf die Buchstaben + + pSgfFonts->ReadList(); + xLine=new short[ChrXPosArrSize]; + cLine=new UCHAR[CharLineSize]; + + TextFit=(Flags & TextFitBits)!=0; + LineFit=FALSE; + LineFit=((Flags & TextFitZBit)!=0); + if (TextFit && FitSize.x==0) LineFit=TRUE; + + if (DrehWink==0) { + sn=0.0; + cs=1.0; + } else { + sn=sin(double(DrehWink)*3.14159265359/18000); + cs=cos(double(DrehWink)*3.14159265359/18000); + } + + T1=T; Index1=0; yPos=0; xPos=0; + if (TextFit) { + ySize=Pos2.y-Pos1.y; + xSize=32000 /2; // Umbruch + xSAdj=Pos2.x-Pos1.x; // zum Ausrichten bei Zentriert/Blocksatz + //if (xSize<=0) { xSize=32000 /2; LineFit=TRUE; } + FitXMul=sal::static_int_cast< USHORT >(abs(Pos2.x-Pos1.x)); FitXDiv=FitSize.x; if (FitXDiv==0) FitXDiv=1; + FitYMul=sal::static_int_cast< USHORT >(abs(Pos2.y-Pos1.y)); FitYDiv=FitSize.y; if (FitYDiv==0) FitYDiv=1; + } else { + xSize=Pos2.x-Pos1.x; + xSAdj=xSize; + ySize=Pos2.y-Pos1.y; + FitXMul=1; FitXDiv=1; + FitYMul=1; FitYDiv=1; + } + if (xSize<0) xSize=0; + if (xSAdj<0) xSAdj=0; + + do { + T2=T1; Index2=Index1; + FormatLine(Buf,Index2,T,T2,xSize,xSAdj,xLine,l,sn,cs,cLine,LineFit); + Fehler=(Index2==Index1); + if (!Fehler) { + lc=GetLineFeed(Buf,Index1,T,T1,l,LF,MaxGrad); + if (TextFit) { + if (LineFit) FitXDiv=xLine[lc+1]; + if (FitXDiv>0) { + long Temp; + for (i=1;i<=l+1;i++) { + Temp=long(xLine[i])*long(FitXMul) /long(FitXDiv); + xLine[i]=short(Temp); + } + LF=MulDiv(LF,FitYMul,FitYDiv); + MaxGrad=MulDiv(MaxGrad,FitYMul,FitYDiv); + } else { + FitXDiv=1; // 0 gibts nicht + } + } + yPos0=yPos; + TopToBase=GetTopToBaseLine(MaxGrad); + yPos=yPos+TopToBase; + Ende=(yPos0+short(MulDiv(MaxGrad,CharTopToBtm,100))>ySize) && !TextFit; + if (!Ende) { + T2=T1; Index2=Index1; + i=1; + while (i<=l) { + c=GetTextCharConv(Buf,Index2,T,T2,l-i,FALSE); + long xp1,yp1; // wegen Overflowgefahr + PointType Pos; + xp1=long(Pos1.x)+xPos+long(xLine[i]); + yp1=long(Pos1.y)+yPos; + if (xp1>32000) xp1=32000; if (xp1<-12000) xp1=-12000; + if (yp1>32000) yp1=32000; if (yp1<-12000) yp1=-12000; + Pos.x=short(xp1); + Pos.y=short(yp1); + + if (DrehWink!=0) RotatePoint(Pos,Pos1.x,Pos1.y,sn,cs); + DrawChar(rOut,c,T2,Pos,DrehWink,FitXMul,FitXDiv,FitYMul,FitYDiv); + i++; + } // while i<=l + yPos=yPos0+LF; + T1=T2; Index1=Index2; // Fuer die naechste Zeile + } // if ObjMin.y+yPos<=Obj_Max.y + } // if !Fehler + } while (c!=TextEnd && !Ende && !Fehler); + delete[] cLine; + delete[] xLine; +} + +// End of DrawText.Pas +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// + +// nicht mehr benoetigt, da der Pointer nun extra gefuehrt wird +// (DEC Alpha hat naemlich 64Bit-Pointer!) +//UCHAR* TextType::GetBufPtr() +//{ +// ULONG Temp; +// Temp=ULONG(BufLo)+0x00010000*ULONG(BufHi); +// return (UCHAR*)Temp; +//} +// +//void TextType::SetBufPtr(UCHAR* Ptr) +//{ +// ULONG Temp=(ULONG)Ptr; +// BufLo=USHORT(Temp & 0x0000FFFF); +// BufHi=USHORT((Temp & 0xFFFF0000)>>16); +//} + +UINT32 ObjTextType::GetFont() +{ + return ULONG(FontLo)+0x00010000*ULONG(FontHi); +} + +void ObjTextType::SetFont(UINT32 FontID) +{ + FontLo=USHORT(FontID & 0x0000FFFF); + FontHi=USHORT((FontID & 0xFFFF0000)>>16); +} + + +///////////////////////////////////////////////////////////////////////////////// +// SGF.Ini lesen //////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////// +SgfFontOne::SgfFontOne() +{ + Next=NULL; + IFID=0; + Bold=FALSE; + Ital=FALSE; + Sans=FALSE; + Serf=FALSE; + Fixd=FALSE; + SVFamil=FAMILY_DONTKNOW; + SVChSet=RTL_TEXTENCODING_DONTKNOW; + SVWidth=40; +} + +void SgfFontOne::ReadOne( ByteString& ID, ByteString& Dsc ) +{ + USHORT i,j,n; + ByteString s; + + if ( Dsc.Len() < 4 || ( Dsc.GetChar( 0 ) != '(' ) ) + return; + i=1; // Erster Buchstabe des IF-Fontnamen. Davor ist eine '(' + while ( i < Dsc.Len() && ( Dsc.GetChar( i ) !=')' ) ) + i++; + Dsc.Erase(0,i+1); // IF-Fontname loeschen inkl. () + + if ( Dsc.Len() < 2 || ( Dsc.GetChar( Dsc.Len() - 1 ) !=')' ) ) + return; + i=Dsc.Len()-2; // hier ist die ')' des SV-Fontnames + j=0; + while ( i > 0 && ( Dsc.GetChar( i ) != '(' ) ) + { + i--; + j++; + } + SVFName=String(Dsc,i+1,j); // SV-Fontname rausholen + Dsc.Erase(i,j); + + IFID = (UINT32)ID.ToInt32(); + n=Dsc.GetTokenCount(' '); + for (i=0;i(s.ToInt32()); + } + } +} + +///////////////////////////////////////////////////////////////////////////////// + +SgfFontLst::SgfFontLst() +{ + pList=NULL; + Last=NULL; + LastID=0; + LastLn=NULL; + Tried=FALSE; +} + +SgfFontLst::~SgfFontLst() +{ + RausList(); +} + +void SgfFontLst::RausList() +{ + SgfFontOne* P; + SgfFontOne* P1; + P=pList; + while (P!=NULL) { + P1=P->Next; + delete P; + P=P1; + } + pList=NULL; + Last=NULL; + Tried=FALSE; + LastID=0; + LastLn=NULL; +} + +void SgfFontLst::AssignFN(const String& rFName) +{ FNam=rFName; } + +void SgfFontLst::ReadList() +{ + if (!Tried) { + Tried=TRUE; + LastID=0; + LastLn=NULL; + SgfFontOne* P,P1; + Config aCfg(FNam); + aCfg.SetGroup("SGV Fonts fuer StarView"); + USHORT Anz=aCfg.GetKeyCount(); + USHORT i; + ByteString FID,Dsc; + + for (i=0;iNext=P; else pList=P; Last=P; // einklinken + P->ReadOne(FID,Dsc); // und Zeile interpretieren + } + } + } +} + +SgfFontOne* SgfFontLst::GetFontDesc(UINT32 ID) +{ + if (ID!=LastID) { + SgfFontOne* P; + P=pList; + while (P!=NULL && P->IFID!=ID) P=P->Next; + LastID=ID; + LastLn=P; + } + return LastLn; +} diff --git a/svtools/source/filter/wmf/emfwr.cxx b/svtools/source/filter/wmf/emfwr.cxx new file mode 100644 index 000000000000..4405db28966a --- /dev/null +++ b/svtools/source/filter/wmf/emfwr.cxx @@ -0,0 +1,1436 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include "emfwr.hxx" +#include +#include +#include +#include +#include + +// ----------- +// - Defines - +// ----------- + +#define WIN_EMR_HEADER 1 +#define WIN_EMR_POLYBEZIER 2 +#define WIN_EMR_POLYGON 3 +#define WIN_EMR_POLYLINE 4 +#define WIN_EMR_POLYBEZIERTO 5 +#define WIN_EMR_POLYLINETO 6 +#define WIN_EMR_POLYPOLYLINE 7 +#define WIN_EMR_POLYPOLYGON 8 +#define WIN_EMR_SETWINDOWEXTEX 9 +#define WIN_EMR_SETWINDOWORGEX 10 +#define WIN_EMR_SETVIEWPORTEXTEX 11 +#define WIN_EMR_SETVIEWPORTORGEX 12 +#define WIN_EMR_SETBRUSHORGEX 13 +#define WIN_EMR_EOF 14 +#define WIN_EMR_SETPIXELV 15 +#define WIN_EMR_SETMAPPERFLAGS 16 +#define WIN_EMR_SETMAPMODE 17 +#define WIN_EMR_SETBKMODE 18 +#define WIN_EMR_SETPOLYFILLMODE 19 +#define WIN_EMR_SETROP2 20 +#define WIN_EMR_SETSTRETCHBLTMODE 21 +#define WIN_EMR_SETTEXTALIGN 22 +#define WIN_EMR_SETCOLORADJUSTMENT 23 +#define WIN_EMR_SETTEXTCOLOR 24 +#define WIN_EMR_SETBKCOLOR 25 +#define WIN_EMR_OFFSETCLIPRGN 26 +#define WIN_EMR_MOVETOEX 27 +#define WIN_EMR_SETMETARGN 28 +#define WIN_EMR_EXCLUDECLIPRECT 29 +#define WIN_EMR_INTERSECTCLIPRECT 30 +#define WIN_EMR_SCALEVIEWPORTEXTEX 31 +#define WIN_EMR_SCALEWINDOWEXTEX 32 +#define WIN_EMR_SAVEDC 33 +#define WIN_EMR_RESTOREDC 34 +#define WIN_EMR_SETWORLDTRANSFORM 35 +#define WIN_EMR_MODIFYWORLDTRANSFORM 36 +#define WIN_EMR_SELECTOBJECT 37 +#define WIN_EMR_CREATEPEN 38 +#define WIN_EMR_CREATEBRUSHINDIRECT 39 +#define WIN_EMR_DELETEOBJECT 40 +#define WIN_EMR_ANGLEARC 41 +#define WIN_EMR_ELLIPSE 42 +#define WIN_EMR_RECTANGLE 43 +#define WIN_EMR_ROUNDRECT 44 +#define WIN_EMR_ARC 45 +#define WIN_EMR_CHORD 46 +#define WIN_EMR_PIE 47 +#define WIN_EMR_SELECTPALETTE 48 +#define WIN_EMR_CREATEPALETTE 49 +#define WIN_EMR_SETPALETTEENTRIES 50 +#define WIN_EMR_RESIZEPALETTE 51 +#define WIN_EMR_REALIZEPALETTE 52 +#define WIN_EMR_EXTFLOODFILL 53 +#define WIN_EMR_LINETO 54 +#define WIN_EMR_ARCTO 55 +#define WIN_EMR_POLYDRAW 56 +#define WIN_EMR_SETARCDIRECTION 57 +#define WIN_EMR_SETMITERLIMIT 58 +#define WIN_EMR_BEGINPATH 59 +#define WIN_EMR_ENDPATH 60 +#define WIN_EMR_CLOSEFIGURE 61 +#define WIN_EMR_FILLPATH 62 +#define WIN_EMR_STROKEANDFILLPATH 63 +#define WIN_EMR_STROKEPATH 64 +#define WIN_EMR_FLATTENPATH 65 +#define WIN_EMR_WIDENPATH 66 +#define WIN_EMR_SELECTCLIPPATH 67 +#define WIN_EMR_ABORTPATH 68 + +#define WIN_EMR_GDICOMMENT 70 +#define WIN_EMR_FILLRGN 71 +#define WIN_EMR_FRAMERGN 72 +#define WIN_EMR_INVERTRGN 73 +#define WIN_EMR_PAINTRGN 74 +#define WIN_EMR_EXTSELECTCLIPRGN 75 +#define WIN_EMR_BITBLT 76 +#define WIN_EMR_STRETCHBLT 77 +#define WIN_EMR_MASKBLT 78 +#define WIN_EMR_PLGBLT 79 +#define WIN_EMR_SETDIBITSTODEVICE 80 +#define WIN_EMR_STRETCHDIBITS 81 +#define WIN_EMR_EXTCREATEFONTINDIRECTW 82 +#define WIN_EMR_EXTTEXTOUTA 83 +#define WIN_EMR_EXTTEXTOUTW 84 +#define WIN_EMR_POLYBEZIER16 85 +#define WIN_EMR_POLYGON16 86 +#define WIN_EMR_POLYLINE16 87 +#define WIN_EMR_POLYBEZIERTO16 88 +#define WIN_EMR_POLYLINETO16 89 +#define WIN_EMR_POLYPOLYLINE16 90 +#define WIN_EMR_POLYPOLYGON16 91 +#define WIN_EMR_POLYDRAW16 92 +#define WIN_EMR_CREATEMONOBRUSH 93 +#define WIN_EMR_CREATEDIBPATTERNBRUSHPT 94 +#define WIN_EMR_EXTCREATEPEN 95 +#define WIN_EMR_POLYTEXTOUTA 96 +#define WIN_EMR_POLYTEXTOUTW 97 + +#define WIN_SRCCOPY 0x00CC0020L +#define WIN_SRCPAINT 0x00EE0086L +#define WIN_SRCAND 0x008800C6L +#define WIN_SRCINVERT 0x00660046L + +#define HANDLE_INVALID 0xffffffff +#define MAXHANDLES 65000 + +#define LINE_SELECT 0x00000001 +#define FILL_SELECT 0x00000002 +#define TEXT_SELECT 0x00000004 + +/* Text Alignment Options */ +#define TA_NOUPDATECP 0 +#define TA_UPDATECP 1 + +#define TA_LEFT 0 +#define TA_RIGHT 2 +#define TA_CENTER 6 + +#define TA_TOP 0 +#define TA_BOTTOM 8 +#define TA_BASELINE 24 +#define TA_RTLREADING 256 +#define TA_MASK (TA_BASELINE+TA_CENTER+TA_UPDATECP+TA_RTLREADING) + +#define MM_ANISOTROPIC 8 + +// ------------- +// - EMFWriter - +// ------------- + +BOOL EMFWriter::WriteEMF( const GDIMetaFile& rMtf, SvStream& rOStm, FilterConfigItem* pFilterConfigItem ) +{ + const ULONG nHeaderPos = rOStm.Tell(); + + mpHandlesUsed = new BOOL[ MAXHANDLES ]; + memset( mpHandlesUsed, 0, MAXHANDLES * sizeof( BOOL ) ); + mnHorTextAlign = mnHandleCount = mnLastPercent = mnRecordPos = mnRecordCount = 0; + mnLineHandle = mnFillHandle = mnTextHandle = HANDLE_INVALID; + mbRecordOpen = FALSE; + + mpStm = &rOStm; + maVDev.EnableOutput( FALSE ); + maVDev.SetMapMode( rMtf.GetPrefMapMode() ); + mpFilterConfigItem = pFilterConfigItem; + + // don't work with pixel as destination map mode -> higher resolution preferrable + maDestMapMode.SetMapUnit( MAP_100TH_MM ); + + const Size aMtfSizePix( maVDev.LogicToPixel( rMtf.GetPrefSize(), rMtf.GetPrefMapMode() ) ); + const Size aMtfSizeLog( maVDev.LogicToLogic( rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), MAP_100TH_MM ) ); + + // seek over header + // use [MS-EMF 2.2.11] HeaderExtension2 Object, otherwise resulting EMF cannot be converted with GetWinMetaFileBits() + rOStm.SeekRel( 108 ); + + // write initial values + + // set 100th mm map mode in EMF + ImplBeginRecord( WIN_EMR_SETMAPMODE ); + (*mpStm) << (INT32) MM_ANISOTROPIC; + ImplEndRecord(); + + ImplBeginRecord( WIN_EMR_SETVIEWPORTEXTEX ); + (*mpStm) << (INT32) maVDev.ImplGetDPIX() << (INT32) maVDev.ImplGetDPIY(); + ImplEndRecord(); + + ImplBeginRecord( WIN_EMR_SETWINDOWEXTEX ); + (*mpStm) << (INT32) 2540 << (INT32) 2540; + ImplEndRecord(); + + ImplBeginRecord( WIN_EMR_SETVIEWPORTORGEX ); + (*mpStm) << (INT32) 0 << (INT32) 0; + ImplEndRecord(); + + ImplBeginRecord( WIN_EMR_SETWINDOWORGEX ); + (*mpStm) << (INT32) 0 << (INT32) 0; + ImplEndRecord(); + + ImplWriteRasterOp( ROP_OVERPAINT ); + + ImplBeginRecord( WIN_EMR_SETBKMODE ); + (*mpStm) << (UINT32) 1; // TRANSPARENT + ImplEndRecord(); + + // write emf data + ImplWrite( rMtf ); + + ImplBeginRecord( WIN_EMR_EOF ); + (*mpStm)<< (sal_uInt32)0 // nPalEntries + << (sal_uInt32)0x10 // offPalEntries + << (sal_uInt32)0x14; // nSizeLast + ImplEndRecord(); + + + // write header + const ULONG nEndPos = mpStm->Tell(); mpStm->Seek( nHeaderPos ); + + (*mpStm) << (UINT32) 0x00000001 << (UINT32) 108 //use [MS-EMF 2.2.11] HeaderExtension2 Object + << (INT32) 0 << (INT32) 0 << (INT32) ( aMtfSizePix.Width() - 1 ) << (INT32) ( aMtfSizePix.Height() - 1 ) + << (INT32) 0 << (INT32) 0 << (INT32) ( aMtfSizeLog.Width() - 1 ) << (INT32) ( aMtfSizeLog.Height() - 1 ) + << (UINT32) 0x464d4520 << (UINT32) 0x10000 << (UINT32) ( nEndPos - nHeaderPos ) + << (UINT32) mnRecordCount << (UINT16) ( mnHandleCount + 1 ) << (UINT16) 0 << (UINT32) 0 << (UINT32) 0 << (UINT32) 0 + << (INT32) aMtfSizePix.Width() << (INT32) aMtfSizePix.Height() + << (INT32) ( aMtfSizeLog.Width() / 100 ) << (INT32) ( aMtfSizeLog.Height() / 100 ) + << (UINT32) 0 << (UINT32) 0 << (UINT32) 0 + << (INT32) ( aMtfSizeLog.Width() * 10 ) << (INT32) ( aMtfSizeLog.Height() * 10 ); //use [MS-EMF 2.2.11] HeaderExtension2 Object + + mpStm->Seek( nEndPos ); + delete[] mpHandlesUsed; + + return( mpStm->GetError() == ERRCODE_NONE ); +} + +// ----------------------------------------------------------------------------- + +ULONG EMFWriter::ImplAcquireHandle() +{ + ULONG nHandle = HANDLE_INVALID; + + for( ULONG i = 0; i < MAXHANDLES && ( HANDLE_INVALID == nHandle ); i++ ) + { + if( !mpHandlesUsed[ i ] ) + { + mpHandlesUsed[ i ] = TRUE; + + if( ( nHandle = i ) == mnHandleCount ) + mnHandleCount++; + } + } + + DBG_ASSERT( nHandle != HANDLE_INVALID, "No more handles available" ); + return( nHandle != HANDLE_INVALID ? nHandle + 1 : HANDLE_INVALID ); +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplReleaseHandle( ULONG nHandle ) +{ + DBG_ASSERT( nHandle && ( nHandle < MAXHANDLES ), "Handle out of range" ); + mpHandlesUsed[ nHandle - 1 ] = FALSE; +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplBeginRecord( sal_uInt32 nType ) +{ + DBG_ASSERT( !mbRecordOpen, "Another record is already opened!" ); + + if( !mbRecordOpen ) + { + mbRecordOpen = TRUE; + mnRecordPos = mpStm->Tell(); + + (*mpStm) << nType; + mpStm->SeekRel( 4 ); + } +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplEndRecord() +{ + DBG_ASSERT( mbRecordOpen, "Record was not opened!" ); + + if( mbRecordOpen ) + { + sal_Int32 nFillBytes, nActPos = mpStm->Tell(); + mpStm->Seek( mnRecordPos + 4 ); + nFillBytes = nActPos - mnRecordPos; + nFillBytes += 3; // each record has to be dword aligned + nFillBytes ^= 3; + nFillBytes &= 3; + *mpStm << (sal_uInt32)( ( nActPos - mnRecordPos ) + nFillBytes ); + mpStm->Seek( nActPos ); + while( nFillBytes-- ) + *mpStm << (sal_uInt8)0; + mnRecordCount++; + mbRecordOpen = FALSE; + } +} + +// ----------------------------------------------------------------------------- + +BOOL EMFWriter::ImplPrepareHandleSelect( sal_uInt32& rHandle, ULONG nSelectType ) +{ + if( rHandle != HANDLE_INVALID ) + { + UINT32 nStockObject = 0x80000000; + + if( LINE_SELECT == nSelectType ) + nStockObject |= 0x00000007; + else if( FILL_SELECT == nSelectType ) + nStockObject |= 0x00000001; + else if( TEXT_SELECT == nSelectType ) + nStockObject |= 0x0000000a; + + // select stock object first + ImplBeginRecord( WIN_EMR_SELECTOBJECT ); + ( *mpStm ) << nStockObject; + ImplEndRecord(); + + // destroy handle of created object + ImplBeginRecord( WIN_EMR_DELETEOBJECT ); + ( *mpStm ) << rHandle; + ImplEndRecord(); + + // mark handle as free + ImplReleaseHandle( rHandle ); + } + + rHandle = ImplAcquireHandle(); + + return( HANDLE_INVALID != rHandle ); +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplCheckLineAttr() +{ + if( mbLineChanged && ImplPrepareHandleSelect( mnLineHandle, LINE_SELECT ) ) + { + sal_uInt32 nStyle = maVDev.IsLineColor() ? 0 : 5; + sal_uInt32 nWidth = 0, nHeight = 0; + + ImplBeginRecord( WIN_EMR_CREATEPEN ); + (*mpStm) << mnLineHandle << nStyle << nWidth << nHeight; + ImplWriteColor( maVDev.GetLineColor() ); + ImplEndRecord(); + + ImplBeginRecord( WIN_EMR_SELECTOBJECT ); + (*mpStm) << mnLineHandle; + ImplEndRecord(); + } +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplCheckFillAttr() +{ + if( mbFillChanged && ImplPrepareHandleSelect( mnFillHandle, FILL_SELECT ) ) + { + sal_uInt32 nStyle = maVDev.IsFillColor() ? 0 : 1; + sal_uInt32 nPatternStyle = 0; + + ImplBeginRecord( WIN_EMR_CREATEBRUSHINDIRECT ); + (*mpStm) << mnFillHandle << nStyle; + ImplWriteColor( maVDev.GetFillColor() ); + (*mpStm) << nPatternStyle; + ImplEndRecord(); + + ImplBeginRecord( WIN_EMR_SELECTOBJECT ); + (*mpStm) << mnFillHandle; + ImplEndRecord(); + } +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplCheckTextAttr() +{ + if( mbTextChanged && ImplPrepareHandleSelect( mnTextHandle, TEXT_SELECT ) ) + { + const Font& rFont = maVDev.GetFont(); + String aFontName( rFont.GetName() ); + sal_Int32 nWeight; + sal_uInt16 i; + sal_uInt8 nPitchAndFamily; + + ImplBeginRecord( WIN_EMR_EXTCREATEFONTINDIRECTW ); + (*mpStm) << mnTextHandle; + ImplWriteExtent( -rFont.GetSize().Height() ); + ImplWriteExtent( rFont.GetSize().Width() ); + (*mpStm) << (INT32) rFont.GetOrientation() << (INT32) rFont.GetOrientation(); + + switch( rFont.GetWeight() ) + { + case WEIGHT_THIN: nWeight = 100; break; + case WEIGHT_ULTRALIGHT: nWeight = 200; break; + case WEIGHT_LIGHT: nWeight = 300; break; + case WEIGHT_SEMILIGHT: nWeight = 300; break; + case WEIGHT_NORMAL: nWeight = 400; break; + case WEIGHT_MEDIUM: nWeight = 500; break; + case WEIGHT_SEMIBOLD: nWeight = 600; break; + case WEIGHT_BOLD: nWeight = 700; break; + case WEIGHT_ULTRABOLD: nWeight = 800; break; + case WEIGHT_BLACK: nWeight = 900; break; + default: nWeight = 0; break; + } + + (*mpStm) << nWeight; + (*mpStm) << (BYTE) ( ( ITALIC_NONE == rFont.GetItalic() ) ? 0 : 1 ); + (*mpStm) << (BYTE) ( ( UNDERLINE_NONE == rFont.GetUnderline() ) ? 0 : 1 ); + (*mpStm) << (BYTE) ( ( STRIKEOUT_NONE == rFont.GetStrikeout() ) ? 0 : 1 ); + (*mpStm) << (BYTE) ( ( RTL_TEXTENCODING_SYMBOL == rFont.GetCharSet() ) ? 2 : 0 ); + (*mpStm) << (BYTE) 0 << (BYTE) 0 << (BYTE) 0; + + switch( rFont.GetPitch() ) + { + case PITCH_FIXED: nPitchAndFamily = 0x01; break; + case PITCH_VARIABLE: nPitchAndFamily = 0x02; break; + default: nPitchAndFamily = 0x00; break; + } + + switch( rFont.GetFamily() ) + { + case FAMILY_DECORATIVE: nPitchAndFamily |= 0x50; break; + case FAMILY_MODERN: nPitchAndFamily |= 0x30; break; + case FAMILY_ROMAN: nPitchAndFamily |= 0x10; break; + case FAMILY_SCRIPT: nPitchAndFamily |= 0x40; break; + case FAMILY_SWISS: nPitchAndFamily |= 0x20; break; + default: break; + } + + (*mpStm) << nPitchAndFamily; + + for( i = 0; i < 32; i++ ) + (*mpStm) << (sal_Unicode) ( ( i < aFontName.Len() ) ? aFontName.GetChar( i ) : 0 ); + + // dummy elfFullName + for( i = 0; i < 64; i++ ) + (*mpStm) << (sal_Unicode) 0; + + // dummy elfStyle + for( i = 0; i < 32; i++ ) + (*mpStm) << (sal_Unicode) 0; + + // dummy elfVersion, elfStyleSize, elfMatch, elfReserved + (*mpStm) << (UINT32) 0 << (UINT32) 0 << (UINT32) 0 << (UINT32) 0 ; + + // dummy elfVendorId + (*mpStm) << (UINT32) 0; + + // dummy elfCulture + (*mpStm) << (UINT32) 0; + + // dummy elfPanose + (*mpStm) << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0 << (BYTE) 0; + + // fill record to get a record size divideable by 4 + (*mpStm) << (UINT16) 0; + + ImplEndRecord(); + + // TextAlign + UINT32 nTextAlign; + + switch( rFont.GetAlign() ) + { + case ALIGN_TOP: nTextAlign = TA_TOP; break; + case ALIGN_BOTTOM: nTextAlign = TA_BOTTOM; break; + default: nTextAlign = TA_BASELINE; break; + } + nTextAlign |= mnHorTextAlign; + + ImplBeginRecord( WIN_EMR_SETTEXTALIGN ); + (*mpStm) << nTextAlign; + ImplEndRecord(); + + // Text color + ImplBeginRecord( WIN_EMR_SETTEXTCOLOR ); + ImplWriteColor( maVDev.GetTextColor() ); + ImplEndRecord(); + + ImplBeginRecord( WIN_EMR_SELECTOBJECT ); + (*mpStm) << mnTextHandle; + ImplEndRecord(); + } +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplWriteColor( const Color& rColor ) +{ + UINT32 nCol = rColor.GetRed(); + + nCol |= ( (UINT32) rColor.GetGreen() ) << 8; + nCol |= ( (UINT32) rColor.GetBlue() ) << 16; + + (*mpStm) << nCol; +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplWriteRasterOp( RasterOp eRop ) +{ + UINT32 nROP2; + + switch( eRop ) + { + case ROP_INVERT: nROP2 = 6; break; + case ROP_XOR: nROP2 = 7; break; + default: nROP2 = 13;break; + } + + ImplBeginRecord( WIN_EMR_SETROP2 ); + (*mpStm) << nROP2; + ImplEndRecord(); +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplWriteExtent( long nExtent ) +{ + nExtent = maVDev.LogicToLogic( Size( nExtent, 0 ), maVDev.GetMapMode(), maDestMapMode ).Width(); + (*mpStm) << (INT32) nExtent; +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplWritePoint( const Point& rPoint ) +{ + const Point aPoint( maVDev.LogicToLogic( rPoint, maVDev.GetMapMode(), maDestMapMode )); + (*mpStm) << (INT32) aPoint.X() << (INT32) aPoint.Y(); +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplWriteSize( const Size& rSize) +{ + const Size aSize( maVDev.LogicToLogic( rSize, maVDev.GetMapMode(), maDestMapMode )); + (*mpStm) << (INT32) aSize.Width() << (INT32) aSize.Height(); +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplWriteRect( const Rectangle& rRect ) +{ + const Rectangle aRect( maVDev.LogicToLogic ( rRect, maVDev.GetMapMode(), maDestMapMode )); + (*mpStm) << aRect.Left() << aRect.Top() << aRect.Right() << aRect.Bottom(); +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplWritePolygonRecord( const Polygon& rPoly, BOOL bClose ) +{ + if( rPoly.GetSize() ) + { + if( rPoly.HasFlags() ) + ImplWritePath( rPoly, bClose ); + else + { + if( bClose ) + ImplCheckFillAttr(); + + ImplCheckLineAttr(); + + ImplBeginRecord( bClose ? WIN_EMR_POLYGON : WIN_EMR_POLYLINE ); + ImplWriteRect( rPoly.GetBoundRect() ); + (*mpStm) << (UINT32) rPoly.GetSize(); + + for( USHORT i = 0; i < rPoly.GetSize(); i++ ) + ImplWritePoint( rPoly[ i ] ); + + ImplEndRecord(); + } + } +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplWritePolyPolygonRecord( const PolyPolygon& rPolyPoly ) +{ + sal_uInt16 n, i, nPolyCount = rPolyPoly.Count(); + + if( nPolyCount ) + { + if( 1 == nPolyCount ) + ImplWritePolygonRecord( rPolyPoly[ 0 ], TRUE ); + else + { + sal_Bool bHasFlags = sal_False; + sal_uInt32 nTotalPoints = 0; + + for( i = 0; i < nPolyCount; i++ ) + { + nTotalPoints += rPolyPoly[ i ].GetSize(); + if ( rPolyPoly[ i ].HasFlags() ) + bHasFlags = sal_True; + } + if( nTotalPoints ) + { + if ( bHasFlags ) + ImplWritePath( rPolyPoly, sal_True ); + else + { + ImplCheckFillAttr(); + ImplCheckLineAttr(); + + ImplBeginRecord( WIN_EMR_POLYPOLYGON ); + ImplWriteRect( rPolyPoly.GetBoundRect() ); + (*mpStm) << (sal_uInt32)nPolyCount << nTotalPoints; + + for( i = 0; i < nPolyCount; i++ ) + (*mpStm) << (sal_uInt32)rPolyPoly[ i ].GetSize(); + + for( i = 0; i < nPolyCount; i++ ) + { + const Polygon& rPoly = rPolyPoly[ i ]; + + for( n = 0; n < rPoly.GetSize(); n++ ) + ImplWritePoint( rPoly[ n ] ); + } + ImplEndRecord(); + } + } + } + } +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplWritePath( const PolyPolygon& rPolyPoly, sal_Bool bClosed ) +{ + if ( bClosed ) + ImplCheckFillAttr(); + ImplCheckLineAttr(); + + ImplBeginRecord( WIN_EMR_BEGINPATH ); + ImplEndRecord(); + + sal_uInt16 i, n, o, nPolyCount = rPolyPoly.Count(); + for ( i = 0; i < nPolyCount; i++ ) + { + n = 0; + const Polygon& rPoly = rPolyPoly[ i ]; + while ( n < rPoly.GetSize() ) + { + if( n == 0 ) + { + ImplBeginRecord( WIN_EMR_MOVETOEX ); + ImplWritePoint( rPoly[ 0 ] ); + ImplEndRecord(); + n++; + continue; + } + + sal_uInt16 nBezPoints = 0; + + while ( ( ( nBezPoints + n + 2 ) < rPoly.GetSize() ) && ( rPoly.GetFlags( nBezPoints + n ) == POLY_CONTROL ) ) + nBezPoints += 3; + + if ( nBezPoints ) + { + ImplBeginRecord( WIN_EMR_POLYBEZIERTO ); + Polygon aNewPoly( nBezPoints + 1 ); + aNewPoly[ 0 ] = rPoly[ n - 1 ]; + for ( o = 0; o < nBezPoints; o++ ) + aNewPoly[ o + 1 ] = rPoly[ n + o ]; + ImplWriteRect( aNewPoly.GetBoundRect() ); + (*mpStm) << (sal_uInt32)nBezPoints; + for( o = 1; o < aNewPoly.GetSize(); o++ ) + ImplWritePoint( aNewPoly[ o ] ); + ImplEndRecord(); + n = n + nBezPoints; + } + else + { + sal_uInt16 nPoints = 1; + while( ( nPoints + n ) < rPoly.GetSize() && ( rPoly.GetFlags( nPoints + n ) != POLY_CONTROL ) ) + nPoints++; + + if ( nPoints > 1 ) + { + ImplBeginRecord( WIN_EMR_POLYLINETO ); + Polygon aNewPoly( nPoints + 1 ); + aNewPoly[ 0 ] = rPoly[ n - 1]; + for ( o = 1; o <= nPoints; o++ ) + aNewPoly[ o ] = rPoly[ n - 1 + o ]; + ImplWriteRect( aNewPoly.GetBoundRect() ); + (*mpStm) << (sal_uInt32)( nPoints ); + for( o = 1; o < aNewPoly.GetSize(); o++ ) + ImplWritePoint( aNewPoly[ o ] ); + ImplEndRecord(); + } + else + { + ImplBeginRecord( WIN_EMR_LINETO ); + ImplWritePoint( rPoly[ n ] ); + ImplEndRecord(); + } + n = n + nPoints; + } + if ( bClosed && ( n == rPoly.GetSize() ) ) + { + ImplBeginRecord( WIN_EMR_CLOSEFIGURE ); + ImplEndRecord(); + } + } + } + ImplBeginRecord( WIN_EMR_ENDPATH ); + ImplEndRecord(); + ImplBeginRecord( bClosed ? WIN_EMR_FILLPATH : WIN_EMR_STROKEPATH ); + ImplWriteRect( rPolyPoly.GetBoundRect() ); + ImplEndRecord(); +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplWriteBmpRecord( const Bitmap& rBmp, const Point& rPt, + const Size& rSz, UINT32 nROP ) +{ + if( !!rBmp ) + { + SvMemoryStream aMemStm( 65535, 65535 ); + const Size aBmpSizePixel( rBmp.GetSizePixel() ); + + ImplBeginRecord( WIN_EMR_STRETCHDIBITS ); + ImplWriteRect( Rectangle( rPt, rSz ) ); + ImplWritePoint( rPt ); + (*mpStm) << (INT32) 0 << (INT32) 0 << (INT32) aBmpSizePixel.Width() << (INT32) aBmpSizePixel.Height(); + + // write offset positions and sizes later + const ULONG nOffPos = mpStm->Tell(); + mpStm->SeekRel( 16 ); + + (*mpStm) << (UINT32) 0 << ( ( ROP_XOR == maVDev.GetRasterOp() && WIN_SRCCOPY == nROP ) ? WIN_SRCINVERT : nROP ); + ImplWriteSize( rSz ); + + rBmp.Write( aMemStm, TRUE, FALSE ); + + UINT32 nDIBSize = aMemStm.Tell(), nHeaderSize, nCompression, nColsUsed, nPalCount, nImageSize; + UINT16 nBitCount; + + // get DIB parameters + aMemStm.Seek( 0 ); + aMemStm >> nHeaderSize; + aMemStm.SeekRel( 10 ); + aMemStm >> nBitCount >> nCompression >> nImageSize; + aMemStm.SeekRel( 8 ); + aMemStm >> nColsUsed; + + nPalCount = ( nBitCount <= 8 ) ? ( nColsUsed ? nColsUsed : ( 1 << (UINT32) nBitCount ) ) : + ( ( 3 == nCompression ) ? 12 : 0 ); + + mpStm->Write( aMemStm.GetData(), nDIBSize ); + + const ULONG nEndPos = mpStm->Tell(); + mpStm->Seek( nOffPos ); + (*mpStm) << (UINT32) 80 << (UINT32)( nHeaderSize + ( nPalCount << 2 ) ); + (*mpStm) << (UINT32)( 80 + ( nHeaderSize + ( nPalCount << 2 ) ) ) << nImageSize; + mpStm->Seek( nEndPos ); + + ImplEndRecord(); + } +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplWriteTextRecord( const Point& rPos, const String rText, const sal_Int32* pDXArray, sal_uInt32 nWidth ) +{ + xub_StrLen nLen = rText.Len(), i; + + if( nLen ) + { + sal_uInt32 nNormWidth; + sal_Int32* pOwnArray; + sal_Int32* pDX; + + // get text sizes + if( pDXArray ) + { + pOwnArray = NULL; + nNormWidth = maVDev.GetTextWidth( rText ); + pDX = (sal_Int32*) pDXArray; + } + else + { + pOwnArray = new sal_Int32[ nLen ]; + nNormWidth = maVDev.GetTextArray( rText, pOwnArray ); + pDX = pOwnArray; + } + + if( nLen > 1 ) + { + nNormWidth = pDX[ nLen - 2 ] + maVDev.GetTextWidth( rText.GetChar( nLen - 1 ) ); + + if( nWidth && nNormWidth && ( nWidth != nNormWidth ) ) + { + const double fFactor = (double) nWidth / nNormWidth; + + for( i = 0; i < ( nLen - 1 ); i++ ) + pDX[ i ] = FRound( pDX[ i ] * fFactor ); + } + } + + // write text record + ImplBeginRecord( WIN_EMR_EXTTEXTOUTW ); + + ImplWriteRect( Rectangle( rPos, Size( nNormWidth, maVDev.GetTextHeight() ) ) ); + (*mpStm) << (UINT32)1; + (*mpStm) << (INT32) 0 << (INT32) 0; + ImplWritePoint( rPos ); + (*mpStm) << (UINT32) nLen << (UINT32) 76 << (UINT32) 2; + (*mpStm) << (INT32) 0 << (INT32) 0 << (INT32) 0 << (INT32) 0; + (*mpStm) << (UINT32) ( 76 + ( nLen << 1 ) + ( (nLen & 1 ) ? 2 : 0 ) ); + + // write text + for( i = 0; i < nLen; i++ ) + (*mpStm) << (sal_Unicode)rText.GetChar( i ); + + // padding word + if( nLen & 1 ) + (*mpStm) << (UINT16) 0; + + // write DX array + ImplWriteExtent( pDX[ 0 ] ); + + if( nLen > 1 ) + { + for( i = 1; i < ( nLen - 1 ); i++ ) + ImplWriteExtent( pDX[ i ] - pDX[ i - 1 ] ); + + ImplWriteExtent( pDX[ nLen - 2 ] / ( nLen - 1 ) ); + } + + ImplEndRecord(); + delete[] pOwnArray; + } +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::Impl_handleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon) +{ + if(rLinePolygon.count()) + { + basegfx::B2DPolyPolygon aLinePolyPolygon(rLinePolygon); + basegfx::B2DPolyPolygon aFillPolyPolygon; + + rInfo.applyToB2DPolyPolygon(aLinePolyPolygon, aFillPolyPolygon); + + if(aLinePolyPolygon.count()) + { + for(sal_uInt32 a(0); a < aLinePolyPolygon.count(); a++) + { + const basegfx::B2DPolygon aCandidate(aLinePolyPolygon.getB2DPolygon(a)); + ImplWritePolygonRecord( Polygon(aCandidate), FALSE ); + } + } + + if(aFillPolyPolygon.count()) + { + const Color aOldLineColor(maVDev.GetLineColor()); + const Color aOldFillColor(maVDev.GetFillColor()); + + maVDev.SetLineColor(); + maVDev.SetFillColor(aOldLineColor); + + for(sal_uInt32 a(0); a < aFillPolyPolygon.count(); a++) + { + const Polygon aPolygon(aFillPolyPolygon.getB2DPolygon(a)); + ImplWritePolyPolygonRecord(PolyPolygon(Polygon(aPolygon))); + } + + maVDev.SetLineColor(aOldLineColor); + maVDev.SetFillColor(aOldFillColor); + } + } +} + +// ----------------------------------------------------------------------------- + +void EMFWriter::ImplWrite( const GDIMetaFile& rMtf ) +{ + for( ULONG j = 0, nActionCount = rMtf.GetActionCount(); j < nActionCount; j++ ) + { + const MetaAction* pAction = rMtf.GetAction( j ); + const USHORT nType = pAction->GetType(); + + switch( nType ) + { + case( META_PIXEL_ACTION ): + { + const MetaPixelAction* pA = (const MetaPixelAction*) pAction; + + ImplCheckLineAttr(); + ImplBeginRecord( WIN_EMR_SETPIXELV ); + ImplWritePoint( pA->GetPoint() ); + ImplWriteColor( pA->GetColor() ); + ImplEndRecord(); + } + break; + + case( META_POINT_ACTION ): + { + if( maVDev.IsLineColor() ) + { + const MetaPointAction* pA = (const MetaPointAction*) pAction; + + ImplCheckLineAttr(); + ImplBeginRecord( WIN_EMR_SETPIXELV ); + ImplWritePoint( pA->GetPoint() ); + ImplWriteColor( maVDev.GetLineColor() ); + ImplEndRecord(); + } + } + break; + + case( META_LINE_ACTION ): + { + if( maVDev.IsLineColor() ) + { + const MetaLineAction* pA = (const MetaLineAction*) pAction; + + if(pA->GetLineInfo().IsDefault()) + { + ImplCheckLineAttr(); + + ImplBeginRecord( WIN_EMR_MOVETOEX ); + ImplWritePoint( pA->GetStartPoint() ); + ImplEndRecord(); + + ImplBeginRecord( WIN_EMR_LINETO ); + ImplWritePoint( pA->GetEndPoint() ); + ImplEndRecord(); + + ImplBeginRecord( WIN_EMR_SETPIXELV ); + ImplWritePoint( pA->GetEndPoint() ); + ImplWriteColor( maVDev.GetLineColor() ); + ImplEndRecord(); + } + else + { + // LineInfo used; handle Dash/Dot and fat lines + basegfx::B2DPolygon aPolygon; + aPolygon.append(basegfx::B2DPoint(pA->GetStartPoint().X(), pA->GetStartPoint().Y())); + aPolygon.append(basegfx::B2DPoint(pA->GetEndPoint().X(), pA->GetEndPoint().Y())); + Impl_handleLineInfoPolyPolygons(pA->GetLineInfo(), aPolygon); + } + } + } + break; + + case( META_RECT_ACTION ): + { + if( maVDev.IsLineColor() || maVDev.IsFillColor() ) + { + const MetaRectAction* pA = (const MetaRectAction*) pAction; + + ImplCheckFillAttr(); + ImplCheckLineAttr(); + + ImplBeginRecord( WIN_EMR_RECTANGLE ); + ImplWriteRect( pA->GetRect() ); + ImplEndRecord(); + } + } + break; + + case( META_ROUNDRECT_ACTION ): + { + if( maVDev.IsLineColor() || maVDev.IsFillColor() ) + { + const MetaRoundRectAction* pA = (const MetaRoundRectAction*) pAction; + + ImplCheckFillAttr(); + ImplCheckLineAttr(); + + ImplBeginRecord( WIN_EMR_ROUNDRECT ); + ImplWriteRect( pA->GetRect() ); + ImplWriteSize( Size( pA->GetHorzRound(), pA->GetVertRound() ) ); + ImplEndRecord(); + } + } + break; + + case( META_ELLIPSE_ACTION ): + { + if( maVDev.IsLineColor() || maVDev.IsFillColor() ) + { + const MetaEllipseAction* pA = (const MetaEllipseAction*) pAction; + + ImplCheckFillAttr(); + ImplCheckLineAttr(); + + ImplBeginRecord( WIN_EMR_ELLIPSE ); + ImplWriteRect( pA->GetRect() ); + ImplEndRecord(); + } + } + break; + + case( META_ARC_ACTION ): + case( META_PIE_ACTION ): + case( META_CHORD_ACTION ): + case( META_POLYGON_ACTION ): + { + if( maVDev.IsLineColor() || maVDev.IsFillColor() ) + { + Polygon aPoly; + + switch( nType ) + { + case( META_ARC_ACTION ): + { + const MetaArcAction* pA = (const MetaArcAction*) pAction; + aPoly = Polygon( pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_ARC ); + } + break; + + case( META_PIE_ACTION ): + { + const MetaPieAction* pA = (const MetaPieAction*) pAction; + aPoly = Polygon( pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_PIE ); + } + break; + + case( META_CHORD_ACTION ): + { + const MetaChordAction* pA = (const MetaChordAction*) pAction; + aPoly = Polygon( pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_CHORD ); + } + break; + + case( META_POLYGON_ACTION ): + aPoly = ( (const MetaPolygonAction*) pAction )->GetPolygon(); + break; + } + + ImplWritePolygonRecord( aPoly, nType != META_ARC_ACTION ); + } + } + break; + + case( META_POLYLINE_ACTION ): + { + if( maVDev.IsLineColor() ) + { + const MetaPolyLineAction* pA = (const MetaPolyLineAction*) pAction; + const Polygon& rPoly = pA->GetPolygon(); + + if( rPoly.GetSize() ) + { + if(pA->GetLineInfo().IsDefault()) + { + ImplWritePolygonRecord( rPoly, FALSE ); + } + else + { + // LineInfo used; handle Dash/Dot and fat lines + Impl_handleLineInfoPolyPolygons(pA->GetLineInfo(), rPoly.getB2DPolygon()); + } + } + } + } + break; + + case( META_POLYPOLYGON_ACTION ): + { + if( maVDev.IsLineColor() || maVDev.IsFillColor() ) + ImplWritePolyPolygonRecord( ( (const MetaPolyPolygonAction*) pAction )->GetPolyPolygon() ); + } + break; + + case( META_GRADIENT_ACTION ): + { + const MetaGradientAction* pA = (const MetaGradientAction*) pAction; + GDIMetaFile aTmpMtf; + + maVDev.AddGradientActions( pA->GetRect(), pA->GetGradient(), aTmpMtf ); + ImplWrite( aTmpMtf ); + } + break; + + case META_HATCH_ACTION: + { + const MetaHatchAction* pA = (const MetaHatchAction*) pAction; + GDIMetaFile aTmpMtf; + + maVDev.AddHatchActions( pA->GetPolyPolygon(), pA->GetHatch(), aTmpMtf ); + ImplWrite( aTmpMtf ); + } + break; + + case META_TRANSPARENT_ACTION: + { + ImplCheckFillAttr(); + ImplCheckLineAttr(); + ImplWritePolyPolygonRecord( ( (MetaTransparentAction*) pAction )->GetPolyPolygon() ); + } + break; + + case META_FLOATTRANSPARENT_ACTION: + { + const MetaFloatTransparentAction* pA = (const MetaFloatTransparentAction*) pAction; + + GDIMetaFile aTmpMtf( pA->GetGDIMetaFile() ); + Point aSrcPt( aTmpMtf.GetPrefMapMode().GetOrigin() ); + const Size aSrcSize( aTmpMtf.GetPrefSize() ); + const Point aDestPt( pA->GetPoint() ); + const Size aDestSize( pA->GetSize() ); + const double fScaleX = aSrcSize.Width() ? (double) aDestSize.Width() / aSrcSize.Width() : 1.0; + const double fScaleY = aSrcSize.Height() ? (double) aDestSize.Height() / aSrcSize.Height() : 1.0; + long nMoveX, nMoveY; + + if( fScaleX != 1.0 || fScaleY != 1.0 ) + { + aTmpMtf.Scale( fScaleX, fScaleY ); + aSrcPt.X() = FRound( aSrcPt.X() * fScaleX ), aSrcPt.Y() = FRound( aSrcPt.Y() * fScaleY ); + } + + nMoveX = aDestPt.X() - aSrcPt.X(), nMoveY = aDestPt.Y() - aSrcPt.Y(); + + if( nMoveX || nMoveY ) + aTmpMtf.Move( nMoveX, nMoveY ); + + ImplCheckFillAttr(); + ImplCheckLineAttr(); + ImplCheckTextAttr(); + ImplWrite( aTmpMtf ); + } + break; + + case( META_EPS_ACTION ): + { + const MetaEPSAction* pA = (const MetaEPSAction*) pAction; + const GDIMetaFile aSubstitute( pA->GetSubstitute() ); + + for( ULONG i = 0, nCount = aSubstitute.GetActionCount(); i < nCount; i++ ) + { + const MetaAction* pSubstAct = aSubstitute.GetAction( i ); + if( pSubstAct->GetType() == META_BMPSCALE_ACTION ) + { + maVDev.Push( PUSH_ALL ); + ImplBeginRecord( WIN_EMR_SAVEDC ); + ImplEndRecord(); + + MapMode aMapMode( aSubstitute.GetPrefMapMode() ); + Size aOutSize( maVDev.LogicToLogic( pA->GetSize(), maVDev.GetMapMode(), aMapMode ) ); + aMapMode.SetScaleX( Fraction( aOutSize.Width(), aSubstitute.GetPrefSize().Width() ) ); + aMapMode.SetScaleY( Fraction( aOutSize.Height(), aSubstitute.GetPrefSize().Height() ) ); + aMapMode.SetOrigin( maVDev.LogicToLogic( pA->GetPoint(), maVDev.GetMapMode(), aMapMode ) ); + maVDev.SetMapMode( aMapMode ); + ImplWrite( aSubstitute ); + + maVDev.Pop(); + ImplBeginRecord( WIN_EMR_RESTOREDC ); + (*mpStm) << (INT32) -1; + ImplEndRecord(); + break; + } + } + } + break; + + case META_BMP_ACTION: + { + const MetaBmpAction* pA = (const MetaBmpAction *) pAction; + ImplWriteBmpRecord( pA->GetBitmap(), pA->GetPoint(), maVDev.PixelToLogic( pA->GetBitmap().GetSizePixel() ), WIN_SRCCOPY ); + } + break; + + case META_BMPSCALE_ACTION: + { + const MetaBmpScaleAction* pA = (const MetaBmpScaleAction*) pAction; + ImplWriteBmpRecord( pA->GetBitmap(), pA->GetPoint(), pA->GetSize(), WIN_SRCCOPY ); + } + break; + + case META_BMPSCALEPART_ACTION: + { + const MetaBmpScalePartAction* pA = (const MetaBmpScalePartAction*) pAction; + Bitmap aTmp( pA->GetBitmap() ); + + if( aTmp.Crop( Rectangle( pA->GetSrcPoint(), pA->GetSrcSize() ) ) ) + ImplWriteBmpRecord( aTmp, pA->GetDestPoint(), pA->GetDestSize(), WIN_SRCCOPY ); + } + break; + + case META_BMPEX_ACTION: + { + const MetaBmpExAction* pA = (const MetaBmpExAction *) pAction; + Bitmap aBmp( pA->GetBitmapEx().GetBitmap() ); + Bitmap aMsk( pA->GetBitmapEx().GetMask() ); + + if( !!aMsk ) + { + aBmp.Replace( aMsk, COL_WHITE ); + aMsk.Invert(); + ImplWriteBmpRecord( aMsk, pA->GetPoint(), maVDev.PixelToLogic( aMsk.GetSizePixel() ), WIN_SRCPAINT ); + ImplWriteBmpRecord( aBmp, pA->GetPoint(), maVDev.PixelToLogic( aBmp.GetSizePixel() ), WIN_SRCAND ); + } + else + ImplWriteBmpRecord( aBmp, pA->GetPoint(), aBmp.GetSizePixel(), WIN_SRCCOPY ); + } + break; + + case META_BMPEXSCALE_ACTION: + { + const MetaBmpExScaleAction* pA = (const MetaBmpExScaleAction*) pAction; + Bitmap aBmp( pA->GetBitmapEx().GetBitmap() ); + Bitmap aMsk( pA->GetBitmapEx().GetMask() ); + + if( !!aMsk ) + { + aBmp.Replace( aMsk, COL_WHITE ); + aMsk.Invert(); + ImplWriteBmpRecord( aMsk, pA->GetPoint(), pA->GetSize(), WIN_SRCPAINT ); + ImplWriteBmpRecord( aBmp, pA->GetPoint(), pA->GetSize(), WIN_SRCAND ); + } + else + ImplWriteBmpRecord( aBmp, pA->GetPoint(), pA->GetSize(), WIN_SRCCOPY ); + } + break; + + case META_BMPEXSCALEPART_ACTION: + { + const MetaBmpExScalePartAction* pA = (const MetaBmpExScalePartAction*) pAction; + BitmapEx aBmpEx( pA->GetBitmapEx() ); + aBmpEx.Crop( Rectangle( pA->GetSrcPoint(), pA->GetSrcSize() ) ); + Bitmap aBmp( aBmpEx.GetBitmap() ); + Bitmap aMsk( aBmpEx.GetMask() ); + + if( !!aMsk ) + { + aBmp.Replace( aMsk, COL_WHITE ); + aMsk.Invert(); + ImplWriteBmpRecord( aMsk, pA->GetDestPoint(), pA->GetDestSize(), WIN_SRCPAINT ); + ImplWriteBmpRecord( aBmp, pA->GetDestPoint(), pA->GetDestSize(), WIN_SRCAND ); + } + else + ImplWriteBmpRecord( aBmp, pA->GetDestPoint(), pA->GetDestSize(), WIN_SRCCOPY ); + } + break; + + case META_TEXT_ACTION: + { + const MetaTextAction* pA = (const MetaTextAction*) pAction; + const String aText( pA->GetText(), pA->GetIndex(), pA->GetLen() ); + + ImplCheckTextAttr(); + ImplWriteTextRecord( pA->GetPoint(), aText, NULL, 0 ); + } + break; + + case META_TEXTRECT_ACTION: + { + const MetaTextRectAction* pA = (const MetaTextRectAction*) pAction; + const String aText( pA->GetText() ); + + ImplCheckTextAttr(); + ImplWriteTextRecord( pA->GetRect().TopLeft(), aText, NULL, 0 ); + } + break; + + case META_TEXTARRAY_ACTION: + { + const MetaTextArrayAction* pA = (const MetaTextArrayAction*) pAction; + const String aText( pA->GetText(), pA->GetIndex(), pA->GetLen() ); + + ImplCheckTextAttr(); + ImplWriteTextRecord( pA->GetPoint(), aText, pA->GetDXArray(), 0 ); + } + break; + + case META_STRETCHTEXT_ACTION: + { + const MetaStretchTextAction* pA = (const MetaStretchTextAction*) pAction; + const String aText( pA->GetText(), pA->GetIndex(), pA->GetLen() ); + + ImplCheckTextAttr(); + ImplWriteTextRecord( pA->GetPoint(), aText, NULL, pA->GetWidth() ); + } + break; + + case( META_LINECOLOR_ACTION ): + { + ( (MetaAction*) pAction )->Execute( &maVDev ); + mbLineChanged = TRUE; + } + break; + + case( META_FILLCOLOR_ACTION ): + { + ( (MetaAction*) pAction )->Execute( &maVDev ); + mbFillChanged = TRUE; + } + break; + + case( META_TEXTCOLOR_ACTION ): + case( META_TEXTLINECOLOR_ACTION ): + case( META_TEXTFILLCOLOR_ACTION ): + case( META_TEXTALIGN_ACTION ): + case( META_FONT_ACTION ): + { + ( (MetaAction*) pAction )->Execute( &maVDev ); + mbTextChanged = TRUE; + } + break; + + case( META_ISECTRECTCLIPREGION_ACTION ): + { + ( (MetaAction*) pAction )->Execute( &maVDev ); + + ImplBeginRecord( WIN_EMR_INTERSECTCLIPRECT ); + ImplWriteRect( ( (MetaISectRectClipRegionAction*) pAction )->GetRect() ); + ImplEndRecord(); + } + break; + + case( META_CLIPREGION_ACTION ): + case( META_ISECTREGIONCLIPREGION_ACTION ): + case( META_MOVECLIPREGION_ACTION ): + { + ( (MetaAction*) pAction )->Execute( &maVDev ); + } + break; + + case( META_REFPOINT_ACTION ): + case( META_MAPMODE_ACTION ): + ( (MetaAction*) pAction )->Execute( &maVDev ); + break; + + case( META_PUSH_ACTION ): + { + ( (MetaAction*) pAction )->Execute( &maVDev ); + + ImplBeginRecord( WIN_EMR_SAVEDC ); + ImplEndRecord(); + } + break; + + case( META_POP_ACTION ): + { + ( (MetaAction*) pAction )->Execute( &maVDev ); + + ImplBeginRecord( WIN_EMR_RESTOREDC ); + (*mpStm) << (INT32) -1; + ImplEndRecord(); + + ImplWriteRasterOp( maVDev.GetRasterOp() ); + mbLineChanged = mbFillChanged = mbTextChanged = TRUE; + } + break; + + case( META_RASTEROP_ACTION ): + { + ( (MetaAction*) pAction )->Execute( &maVDev ); + ImplWriteRasterOp( ( (MetaRasterOpAction*) pAction )->GetRasterOp() ); + } + break; + + case( META_LAYOUTMODE_ACTION ): + { + sal_uInt32 nLayoutMode = ( (MetaLayoutModeAction*) pAction )->GetLayoutMode(); + mnHorTextAlign = 0; + if (nLayoutMode & TEXT_LAYOUT_BIDI_RTL) + { + mnHorTextAlign = TA_RIGHT | TA_RTLREADING; + } + if (nLayoutMode & TEXT_LAYOUT_TEXTORIGIN_RIGHT) + mnHorTextAlign |= TA_RIGHT; + else if (nLayoutMode & TEXT_LAYOUT_TEXTORIGIN_LEFT) + mnHorTextAlign &= ~TA_RIGHT; + break; + } + + case( META_MASK_ACTION ): + case( META_MASKSCALE_ACTION ): + case( META_MASKSCALEPART_ACTION ): + case( META_WALLPAPER_ACTION ): + case( META_TEXTLINE_ACTION ): + case( META_COMMENT_ACTION ): + case( META_GRADIENTEX_ACTION ): + { + // !!! >>> we don't want to support these actions + } + break; + + case( META_RENDERGRAPHIC_ACTION ): + { + const MetaRenderGraphicAction* pA = (const MetaRenderGraphicAction*) pAction; + const ::vcl::RenderGraphicRasterizer aRasterizer( pA->GetRenderGraphic() ); + const BitmapEx aBmpEx( aRasterizer.Rasterize( maVDev.LogicToPixel( pA->GetSize() ) ) ); + Bitmap aBmp( aBmpEx.GetBitmap() ); + Bitmap aMsk( aBmpEx.GetMask() ); + + if( !!aMsk ) + { + aBmp.Replace( aMsk, COL_WHITE ); + aMsk.Invert(); + ImplWriteBmpRecord( aMsk, pA->GetPoint(), pA->GetSize(), WIN_SRCPAINT ); + ImplWriteBmpRecord( aBmp, pA->GetPoint(), pA->GetSize(), WIN_SRCAND ); + } + else + ImplWriteBmpRecord( aBmp, pA->GetPoint(), pA->GetSize(), WIN_SRCCOPY ); + } + break; + + default: + DBG_ERROR( ( ByteString( "EMFWriter::ImplWriteActions: unsupported MetaAction #" ) += ByteString::CreateFromInt32( nType ) ).GetBuffer() ); + break; + } + } +} diff --git a/svtools/source/filter/wmf/emfwr.hxx b/svtools/source/filter/wmf/emfwr.hxx new file mode 100644 index 000000000000..6334b5dfe16f --- /dev/null +++ b/svtools/source/filter/wmf/emfwr.hxx @@ -0,0 +1,100 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EMFWR_HXX +#define _EMFWR_HXX + +#include +#include +#include +#include +#include +#include + +// ------------- +// - EMFWriter - +// ------------- + +class LineInfo; +namespace basegfx { class B2DPolygon; } + +class EMFWriter +{ +private: + + VirtualDevice maVDev; + MapMode maDestMapMode; + FilterConfigItem* mpFilterConfigItem; + SvStream* mpStm; + BOOL* mpHandlesUsed; + ULONG mnHandleCount; + ULONG mnLastPercent; + ULONG mnRecordCount; + ULONG mnRecordPos; + BOOL mbRecordOpen; + BOOL mbLineChanged; + sal_uInt32 mnLineHandle; + BOOL mbFillChanged; + sal_uInt32 mnFillHandle; + BOOL mbTextChanged; + sal_uInt32 mnTextHandle; + sal_uInt32 mnHorTextAlign; + + void ImplBeginRecord( sal_uInt32 nType ); + void ImplEndRecord(); + + ULONG ImplAcquireHandle(); + void ImplReleaseHandle( ULONG nHandle ); + + BOOL ImplPrepareHandleSelect( sal_uInt32& rHandle, ULONG nSelectType ); + void ImplCheckLineAttr(); + void ImplCheckFillAttr(); + void ImplCheckTextAttr(); + + void ImplWriteColor( const Color& rColor ); + void ImplWriteRasterOp( RasterOp eRop ); + void ImplWriteExtent( long nExtent ); + void ImplWritePoint( const Point& rPoint ); + void ImplWriteSize( const Size& rSize); + void ImplWriteRect( const Rectangle& rRect ); + void ImplWritePath( const PolyPolygon& rPolyPoly, sal_Bool bClose ); + void ImplWritePolygonRecord( const Polygon& rPoly, BOOL bClose ); + void ImplWritePolyPolygonRecord( const PolyPolygon& rPolyPoly ); + void ImplWriteBmpRecord( const Bitmap& rBmp, const Point& rPt, const Size& rSz, UINT32 nROP ); + void ImplWriteTextRecord( const Point& rPos, const String rText, const sal_Int32* pDXArray, sal_uInt32 nWidth ); + + void Impl_handleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon); + void ImplWrite( const GDIMetaFile& rMtf ); + +public: + + EMFWriter() {} + + BOOL WriteEMF( const GDIMetaFile& rMtf, SvStream& rOStm, FilterConfigItem* pConfigItem = NULL ); +}; + +#endif // _EMFWR_HXX diff --git a/svtools/source/filter/wmf/enhwmf.cxx b/svtools/source/filter/wmf/enhwmf.cxx new file mode 100644 index 000000000000..1e49e0d61446 --- /dev/null +++ b/svtools/source/filter/wmf/enhwmf.cxx @@ -0,0 +1,1343 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include "winmtf.hxx" +#include + +//=========================== GDI-Array =================================== + +#define EMR_HEADER 1 +#define EMR_POLYBEZIER 2 +#define EMR_POLYGON 3 +#define EMR_POLYLINE 4 +#define EMR_POLYBEZIERTO 5 +#define EMR_POLYLINETO 6 +#define EMR_POLYPOLYLINE 7 +#define EMR_POLYPOLYGON 8 +#define EMR_SETWINDOWEXTEX 9 +#define EMR_SETWINDOWORGEX 10 +#define EMR_SETVIEWPORTEXTEX 11 +#define EMR_SETVIEWPORTORGEX 12 +#define EMR_SETBRUSHORGEX 13 +#define EMR_EOF 14 +#define EMR_SETPIXELV 15 +#define EMR_SETMAPPERFLAGS 16 +#define EMR_SETMAPMODE 17 +#define EMR_SETBKMODE 18 +#define EMR_SETPOLYFILLMODE 19 +#define EMR_SETROP2 20 +#define EMR_SETSTRETCHBLTMODE 21 +#define EMR_SETTEXTALIGN 22 +#define EMR_SETCOLORADJUSTMENT 23 +#define EMR_SETTEXTCOLOR 24 +#define EMR_SETBKCOLOR 25 +#define EMR_OFFSETCLIPRGN 26 +#define EMR_MOVETOEX 27 +#define EMR_SETMETARGN 28 +#define EMR_EXCLUDECLIPRECT 29 +#define EMR_INTERSECTCLIPRECT 30 +#define EMR_SCALEVIEWPORTEXTEX 31 +#define EMR_SCALEWINDOWEXTEX 32 +#define EMR_SAVEDC 33 +#define EMR_RESTOREDC 34 +#define EMR_SETWORLDTRANSFORM 35 +#define EMR_MODIFYWORLDTRANSFORM 36 +#define EMR_SELECTOBJECT 37 +#define EMR_CREATEPEN 38 +#define EMR_CREATEBRUSHINDIRECT 39 +#define EMR_DELETEOBJECT 40 +#define EMR_ANGLEARC 41 +#define EMR_ELLIPSE 42 +#define EMR_RECTANGLE 43 +#define EMR_ROUNDRECT 44 +#define EMR_ARC 45 +#define EMR_CHORD 46 +#define EMR_PIE 47 +#define EMR_SELECTPALETTE 48 +#define EMR_CREATEPALETTE 49 +#define EMR_SETPALETTEENTRIES 50 +#define EMR_RESIZEPALETTE 51 +#define EMR_REALIZEPALETTE 52 +#define EMR_EXTFLOODFILL 53 +#define EMR_LINETO 54 +#define EMR_ARCTO 55 +#define EMR_POLYDRAW 56 +#define EMR_SETARCDIRECTION 57 +#define EMR_SETMITERLIMIT 58 +#define EMR_BEGINPATH 59 +#define EMR_ENDPATH 60 +#define EMR_CLOSEFIGURE 61 +#define EMR_FILLPATH 62 +#define EMR_STROKEANDFILLPATH 63 +#define EMR_STROKEPATH 64 +#define EMR_FLATTENPATH 65 +#define EMR_WIDENPATH 66 +#define EMR_SELECTCLIPPATH 67 +#define EMR_ABORTPATH 68 + +#define EMR_GDICOMMENT 70 +#define EMR_FILLRGN 71 +#define EMR_FRAMERGN 72 +#define EMR_INVERTRGN 73 +#define EMR_PAINTRGN 74 +#define EMR_EXTSELECTCLIPRGN 75 +#define EMR_BITBLT 76 +#define EMR_STRETCHBLT 77 +#define EMR_MASKBLT 78 +#define EMR_PLGBLT 79 +#define EMR_SETDIBITSTODEVICE 80 +#define EMR_STRETCHDIBITS 81 +#define EMR_EXTCREATEFONTINDIRECTW 82 +#define EMR_EXTTEXTOUTA 83 +#define EMR_EXTTEXTOUTW 84 +#define EMR_POLYBEZIER16 85 +#define EMR_POLYGON16 86 +#define EMR_POLYLINE16 87 +#define EMR_POLYBEZIERTO16 88 +#define EMR_POLYLINETO16 89 +#define EMR_POLYPOLYLINE16 90 +#define EMR_POLYPOLYGON16 91 +#define EMR_POLYDRAW16 92 +#define EMR_CREATEMONOBRUSH 93 +#define EMR_CREATEDIBPATTERNBRUSHPT 94 +#define EMR_EXTCREATEPEN 95 +#define EMR_POLYTEXTOUTA 96 +#define EMR_POLYTEXTOUTW 97 + +// WINDOWS VERSION >= 0x400 +#define EMR_SETICMMODE 98 +#define EMR_CREATECOLORSPACE 99 +#define EMR_SETCOLORSPACE 100 +#define EMR_DELETECOLORSPACE 101 +#define EMR_GLSRECORD 102 +#define EMR_GLSBOUNDEDRECORD 103 +#define EMR_PIXELFORMAT 104 + +// WINDOWS VERSION >= 0x500 +#define EMR_DRAWESCAPE 105 +#define EMR_EXTESCAPE 106 +#define EMR_STARTDOC 107 +#define EMR_SMALLTEXTOUT 108 +#define EMR_FORCEUFIMAPPING 109 +#define EMR_NAMEDESCAPE 110 +#define EMR_COLORCORRECTPALETTE 111 +#define EMR_SETICMPROFILEA 112 +#define EMR_SETICMPROFILEW 113 +#define EMR_ALPHABLEND 114 +#define EMR_ALPHADIBBLEND 115 +#define EMR_TRANSPARENTBLT 116 +#define EMR_TRANSPARENTDIB 117 +#define EMR_GRADIENTFILL 118 +#define EMR_SETLINKEDUFIS 119 +#define EMR_SETTEXTJUSTIFICATION 120 + + +//----------------------------------------------------------------------------------- + +#ifdef OSL_BIGENDIAN +// currently unused +static float GetSwapFloat( SvStream& rSt ) +{ + float fTmp; + sal_Int8* pPtr = (sal_Int8*)&fTmp; + rSt >> pPtr[3] >> pPtr[2] >> pPtr[1] >> pPtr[0]; // Little Endian <-> Big Endian switch + return fTmp; +} +#endif + +SvStream& operator>>( SvStream& rIn, XForm& rXForm ) +{ + if ( sizeof( float ) != 4 ) + { + DBG_ERROR( "EnhWMFReader::sizeof( float ) != 4" ); + rXForm = XForm(); + } + else + { +#ifdef OSL_BIGENDIAN + rXForm.eM11 = GetSwapFloat( rIn ); + rXForm.eM12 = GetSwapFloat( rIn ); + rXForm.eM21 = GetSwapFloat( rIn ); + rXForm.eM22 = GetSwapFloat( rIn ); + rXForm.eDx = GetSwapFloat( rIn ); + rXForm.eDy = GetSwapFloat( rIn ); +#else + rIn >> rXForm.eM11 >> rXForm.eM12 >> rXForm.eM21 >> rXForm.eM22 + >> rXForm.eDx >> rXForm.eDy; +#endif + } + return rIn; +} + +static sal_Bool ImplReadRegion( PolyPolygon& rPolyPoly, SvStream& rSt, sal_uInt32 nLen ) +{ + sal_Bool bOk = sal_False; + if ( nLen ) + { + sal_uInt32 nHdSize, nType, nCount, nRgnSize, i; + rSt >> nHdSize + >> nType + >> nCount + >> nRgnSize; + + if ( nCount && ( nType == RDH_RECTANGLES ) && + ( nLen >= ( ( nCount << 4 ) + ( nHdSize - 16 ) ) ) ) + { + sal_Int32 nx1, ny1, nx2, ny2; + + for ( i = 0; i < nCount; i++ ) + { + rSt >> nx1 >> ny1 >> nx2 >> ny2; + + Rectangle aRect( Point( nx1, ny1 ), Point( nx2, ny2 ) ); + Polygon aPolygon( aRect ); + PolyPolygon aPolyPolyOr1( aPolygon ); + PolyPolygon aPolyPolyOr2( rPolyPoly ); + rPolyPoly.GetUnion( aPolyPolyOr1, aPolyPolyOr2 ); + rPolyPoly = aPolyPolyOr2; + } + bOk = sal_True; + } + } + return bOk; +} + +BOOL EnhWMFReader::ReadEnhWMF() +{ + sal_uInt32 nStretchBltMode = 0; + sal_uInt32 nRecType, nRecSize, nNextPos, + nW, nH, nPoints, nColor, nIndex, + nDat32, nNom1, nDen1, nNom2, nDen2; + sal_Int32 nX32, nY32, nx32, ny32; + sal_Int16 nX16, nY16; + + sal_Bool bFlag, bStatus = ReadHeader(); + + while( bStatus && nRecordCount-- ) + { + *pWMF >> nRecType >> nRecSize; + + if ( ( nRecSize < 8 ) || ( nRecSize & 3 ) ) // Parameter sind immer durch 4 teilbar + { + bStatus = FALSE; + break; + } + + nNextPos = pWMF->Tell() + ( nRecSize - 8 ); + + if ( nNextPos > nEndPos ) + { + bStatus = FALSE; + break; + } + + if( aBmpSaveList.Count() && ( nRecType != EMR_STRETCHBLT ) && ( nRecType != EMR_STRETCHDIBITS ) ) + pOut->ResolveBitmapActions( aBmpSaveList ); + + bFlag = sal_False; + + switch( nRecType ) + { + case EMR_POLYBEZIERTO : + bFlag = sal_True; + case EMR_POLYBEZIER : + { + pWMF->SeekRel( 16 ); + *pWMF >> nPoints; + sal_uInt16 i = 0; + if ( bFlag ) + { + i++; + nPoints++; + } + Polygon aPoly( (sal_uInt16)nPoints ); + for( ; i < (sal_uInt16)nPoints; i++ ) + { + *pWMF >> nX32 >> nY32; + aPoly[ i ] = Point( nX32, nY32 ); + } + pOut->DrawPolyBezier( aPoly, bFlag, bRecordPath ); + } + break; + + case EMR_POLYGON : + { + pWMF->SeekRel( 16 ); + *pWMF >> nPoints; + Polygon aPoly( (UINT16)nPoints ); + for( UINT16 k = 0; k < (UINT16)nPoints; k++ ) + { + *pWMF >> nX32 >> nY32; + aPoly[ k ] = Point( nX32, nY32 ); + } + pOut->DrawPolygon( aPoly, bRecordPath ); + } + break; + + case EMR_POLYLINETO : + bFlag = sal_True; + case EMR_POLYLINE : + { + pWMF->SeekRel( 0x10 ); + *pWMF >> nPoints; + UINT16 i = 0; + if ( bFlag ) + { + i++; + nPoints++; + } + Polygon aPolygon( (UINT16)nPoints ); + for ( ; i < (UINT16)nPoints; i++ ) + { + *pWMF >> nX32 >> nY32; + aPolygon[ i ] = Point( nX32, nY32 ); + } + pOut->DrawPolyLine( aPolygon, bFlag, bRecordPath ); + } + break; + + case EMR_POLYPOLYLINE : + { + UINT16* pnPoints; + + INT32 i, nPoly; + pWMF->SeekRel( 0x10 ); + + // Anzahl der Polygone: + *pWMF >> nPoly >> i; + + // taking the amount of points of each polygon, retrieving the total number of points + if ( static_cast< sal_uInt32 >(nPoly) < SAL_MAX_UINT32 / sizeof(UINT16) ) + { + if ( ( static_cast< sal_uInt32 >( nPoly ) * sizeof(UINT16) ) <= ( nEndPos - pWMF->Tell() ) ) + { + pnPoints = new UINT16[ nPoly ]; + + for ( i = 0; i < nPoly; i++ ) + { + *pWMF >> nPoints; + pnPoints[ i ] = (UINT16)nPoints; + } + + // Polygonpunkte holen: + + for ( i = 0; ( i < nPoly ) && !pWMF->IsEof(); i++ ) + { + Polygon aPoly( pnPoints[ i ] ); + for( UINT16 k = 0; k < pnPoints[ i ]; k++ ) + { + *pWMF >> nX32 >> nY32; + aPoly[ k ] = Point( nX32, nY32 ); + } + pOut->DrawPolyLine( aPoly, sal_False, bRecordPath ); + } + delete[] pnPoints; + } + } + } + break; + + case EMR_POLYPOLYGON : + { + UINT16* pnPoints; + Point* pPtAry; + + UINT32 i, nPoly, nGesPoints; + pWMF->SeekRel( 0x10 ); + + // Anzahl der Polygone: + *pWMF >> nPoly >> nGesPoints; + + if ( ( nGesPoints < SAL_MAX_UINT32 / sizeof(Point) ) && ( nPoly < SAL_MAX_UINT32 / sizeof(UINT16) ) ) + { + if ( ( nPoly * sizeof(UINT16) ) <= ( nEndPos - pWMF->Tell() ) ) + { + pnPoints = new UINT16[ nPoly ]; + + for ( i = 0; i < nPoly; i++ ) + { + *pWMF >> nPoints; + pnPoints[ i ] = (UINT16)nPoints; + } + + if ( ( nGesPoints * (sizeof(sal_uInt32)+sizeof(sal_uInt32)) ) <= ( nEndPos - pWMF->Tell() ) ) + { + // Polygonpunkte holen: + pPtAry = new Point[ nGesPoints ]; + + for ( i = 0; i < nGesPoints; i++ ) + { + *pWMF >> nX32 >> nY32; + pPtAry[ i ] = Point( nX32, nY32 ); + } + // PolyPolygon Actions erzeugen + PolyPolygon aPolyPoly( (UINT16)nPoly, pnPoints, pPtAry ); + pOut->DrawPolyPolygon( aPolyPoly, bRecordPath ); + delete[] pPtAry; + } + delete[] pnPoints; + } + } + } + break; + + case EMR_SETWINDOWEXTEX : + { // #75383# + *pWMF >> nW >> nH; + pOut->SetWinExt( Size( nW, nH ) ); + } + break; + + case EMR_SETWINDOWORGEX : + { + *pWMF >> nX32 >> nY32; + pOut->SetWinOrg( Point( nX32, nY32 ) ); + } + break; + + case EMR_SCALEWINDOWEXTEX : + { + *pWMF >> nNom1 >> nDen1 >> nNom2 >> nDen2; + pOut->ScaleWinExt( (double)nNom1 / nDen1, (double)nNom2 / nDen2 ); + } + break; + + case EMR_SETVIEWPORTORGEX : + { + *pWMF >> nX32 >> nY32; + pOut->SetDevOrg( Point( nX32, nY32 ) ); + } + break; + + case EMR_SCALEVIEWPORTEXTEX : + { + *pWMF >> nNom1 >> nDen1 >> nNom2 >> nDen2; + pOut->ScaleDevExt( (double)nNom1 / nDen1, (double)nNom2 / nDen2 ); + } + break; + + case EMR_SETVIEWPORTEXTEX : + { + *pWMF >> nW >> nH; + pOut->SetDevExt( Size( nW, nH ) ); + } + break; + + case EMR_EOF : + nRecordCount = 0; // #76846# + break; + + case EMR_SETPIXELV : + { + *pWMF >> nX32 >> nY32; + pOut->DrawPixel( Point( nX32, nY32 ), ReadColor() ); + } + break; + + case EMR_SETMAPMODE : + { + sal_uInt32 nMapMode; + *pWMF >> nMapMode; + pOut->SetMapMode( nMapMode ); + } + break; + + case EMR_SETBKMODE : + { + *pWMF >> nDat32; + pOut->SetBkMode( nDat32 ); + } + break; + + case EMR_SETPOLYFILLMODE : + break; + + case EMR_SETROP2 : + { + *pWMF >> nDat32; + pOut->SetRasterOp( nDat32 ); + } + break; + + case EMR_SETSTRETCHBLTMODE : + { + *pWMF >> nStretchBltMode; + } + break; + + case EMR_SETTEXTALIGN : + { + *pWMF >> nDat32; + pOut->SetTextAlign( nDat32 ); + } + break; + + case EMR_SETTEXTCOLOR : + { + pOut->SetTextColor( ReadColor() ); + } + break; + + case EMR_SETBKCOLOR : + { + pOut->SetBkColor( ReadColor() ); + } + break; + + case EMR_OFFSETCLIPRGN : + { + *pWMF >> nX32 >> nY32; + pOut->MoveClipRegion( Size( nX32, nY32 ) ); + } + break; + + case EMR_MOVETOEX : + { + *pWMF >> nX32 >> nY32; + pOut->MoveTo( Point( nX32, nY32 ), bRecordPath ); + } + break; + + case EMR_INTERSECTCLIPRECT : + { + *pWMF >> nX32 >> nY32 >> nx32 >> ny32; + pOut->IntersectClipRect( ReadRectangle( nX32, nY32, nx32, ny32 ) ); + } + break; + + case EMR_SAVEDC : + { + pOut->Push(); + } + break; + + case EMR_RESTOREDC : + { + pOut->Pop(); + } + break; + + case EMR_SETWORLDTRANSFORM : + { + XForm aTempXForm; + *pWMF >> aTempXForm; + pOut->SetWorldTransform( aTempXForm ); + } + break; + + case EMR_MODIFYWORLDTRANSFORM : + { + UINT32 nMode; + XForm aTempXForm; + *pWMF >> aTempXForm >> nMode; + pOut->ModifyWorldTransform( aTempXForm, nMode ); + } + break; + + case EMR_SELECTOBJECT : + { + *pWMF >> nIndex; + pOut->SelectObject( nIndex ); + } + break; + + case EMR_CREATEPEN : + { + *pWMF >> nIndex; + if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) + { + + LineInfo aLineInfo; + UINT32 nStyle; + Size aSize; + + *pWMF >> nStyle >> aSize.Width() >> aSize.Height(); + + if ( aSize.Width() ) + aLineInfo.SetWidth( aSize.Width() ); + + BOOL bTransparent = FALSE; + UINT16 nDashCount = 0; + UINT16 nDotCount = 0; + switch( nStyle ) + { + case PS_DASHDOTDOT : + nDotCount++; + case PS_DASHDOT : + nDashCount++; + case PS_DOT : + nDotCount++; + break; + case PS_DASH : + nDashCount++; + break; + case PS_NULL : + bTransparent = TRUE; + aLineInfo.SetStyle( LINE_NONE ); + break; + default : + case PS_INSIDEFRAME : + case PS_SOLID : + aLineInfo.SetStyle( LINE_SOLID ); + } + if ( nDashCount | nDotCount ) + { + aLineInfo.SetStyle( LINE_DASH ); + aLineInfo.SetDashCount( nDashCount ); + aLineInfo.SetDotCount( nDotCount ); + } + pOut->CreateObject( nIndex, GDI_PEN, new WinMtfLineStyle( ReadColor(), aLineInfo, bTransparent ) ); + } + } + break; + + case EMR_EXTCREATEPEN : + { + sal_Int32 elpHatch; + sal_uInt32 offBmi, cbBmi, offBits, cbBits, nStyle, nWidth, nBrushStyle, elpNumEntries; + Color aColorRef; + + *pWMF >> nIndex; + if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) + { + *pWMF >> offBmi >> cbBmi >> offBits >> cbBits >> nStyle >> nWidth >> nBrushStyle; + aColorRef = ReadColor(); + *pWMF >> elpHatch >> elpNumEntries; + + LineInfo aLineInfo; + if ( nWidth ) + aLineInfo.SetWidth( nWidth ); + + sal_Bool bTransparent = sal_False; + sal_uInt16 nDashCount = 0; + sal_uInt16 nDotCount = 0; + + switch( nStyle & PS_STYLE_MASK ) + { + case PS_DASHDOTDOT : + nDotCount++; + case PS_DASHDOT : + nDashCount++; + case PS_DOT : + nDotCount++; + break; + case PS_DASH : + nDashCount++; + break; + case PS_NULL : + bTransparent = sal_True; + aLineInfo.SetStyle( LINE_NONE ); + break; + + default : + case PS_INSIDEFRAME : + case PS_SOLID : + aLineInfo.SetStyle( LINE_SOLID ); + } + if ( nDashCount | nDotCount ) + { + aLineInfo.SetStyle( LINE_DASH ); + aLineInfo.SetDashCount( nDashCount ); + aLineInfo.SetDotCount( nDotCount ); + } + pOut->CreateObject( nIndex, GDI_PEN, new WinMtfLineStyle( aColorRef, aLineInfo, bTransparent ) ); + } + } + break; + + case EMR_CREATEBRUSHINDIRECT : + { + UINT32 nStyle; + *pWMF >> nIndex; + if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) + { + *pWMF >> nStyle; + pOut->CreateObject( nIndex, GDI_BRUSH, new WinMtfFillStyle( ReadColor(), ( nStyle == BS_HOLLOW ) ? TRUE : FALSE ) ); + } + } + break; + + case EMR_DELETEOBJECT : + { + *pWMF >> nIndex; + if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) + pOut->DeleteObject( nIndex ); + } + break; + + case EMR_ELLIPSE : + { + *pWMF >> nX32 >> nY32 >> nx32 >> ny32; + pOut->DrawEllipse( ReadRectangle( nX32, nY32, nx32, ny32 ) ); + } + break; + + case EMR_RECTANGLE : + { + *pWMF >> nX32 >> nY32 >> nx32 >> ny32; + pOut->DrawRect( ReadRectangle( nX32, nY32, nx32, ny32 ) ); + } + break; + + case EMR_ROUNDRECT : + { + *pWMF >> nX32 >> nY32 >> nx32 >> ny32 >> nW >> nH; + Size aSize( Size( nW, nH ) ); + pOut->DrawRoundRect( ReadRectangle( nX32, nY32, nx32, ny32 ), aSize ); + } + break; + + case EMR_ARC : + { + UINT32 nStartX, nStartY, nEndX, nEndY; + *pWMF >> nX32 >> nY32 >> nx32 >> ny32 >> nStartX >> nStartY >> nEndX >> nEndY; + pOut->DrawArc( ReadRectangle( nX32, nY32, nx32, ny32 ), Point( nStartX, nStartY ), Point( nEndX, nEndY ) ); + } + break; + + case EMR_CHORD : + { + UINT32 nStartX, nStartY, nEndX, nEndY; + *pWMF >> nX32 >> nY32 >> nx32 >> ny32 >> nStartX >> nStartY >> nEndX >> nEndY; + pOut->DrawChord( ReadRectangle( nX32, nY32, nx32, ny32 ), Point( nStartX, nStartY ), Point( nEndX, nEndY ) ); + } + break; + + case EMR_PIE : + { + UINT32 nStartX, nStartY, nEndX, nEndY; + *pWMF >> nX32 >> nY32 >> nx32 >> ny32 >> nStartX >> nStartY >> nEndX >> nEndY; + const Rectangle aRect( ReadRectangle( nX32, nY32, nx32, ny32 )); + + // #i73608# OutputDevice deviates from WMF + // semantics. start==end means full ellipse here. + if( nStartX == nEndX && nStartY == nEndY ) + pOut->DrawEllipse( aRect ); + else + pOut->DrawPie( aRect, Point( nStartX, nStartY ), Point( nEndX, nEndY ) ); + } + break; + + case EMR_LINETO : + { + *pWMF >> nX32 >> nY32; + pOut->LineTo( Point( nX32, nY32 ), bRecordPath ); + } + break; + + case EMR_ARCTO : + { + UINT32 nStartX, nStartY, nEndX, nEndY; + *pWMF >> nX32 >> nY32 >> nx32 >> ny32 >> nStartX >> nStartY >> nEndX >> nEndY; + pOut->DrawArc( ReadRectangle( nX32, nY32, nx32, ny32 ), Point( nStartX, nStartY ), Point( nEndX, nEndY ), TRUE ); + } + break; + + case EMR_BEGINPATH : + { + pOut->ClearPath(); + bRecordPath = sal_True; + } + break; + + case EMR_ABORTPATH : + pOut->ClearPath(); + case EMR_ENDPATH : + bRecordPath = sal_False; + break; + + case EMR_CLOSEFIGURE : + pOut->ClosePath(); + break; + + case EMR_FILLPATH : + pOut->StrokeAndFillPath( sal_False, sal_True ); + break; + + case EMR_STROKEANDFILLPATH : + pOut->StrokeAndFillPath( sal_True, sal_True ); + break; + + case EMR_STROKEPATH : + pOut->StrokeAndFillPath( sal_True, sal_False ); + break; + + case EMR_SELECTCLIPPATH : + { + sal_Int32 nClippingMode; + *pWMF >> nClippingMode; + pOut->SetClipPath( pOut->GetPathObj(), nClippingMode, sal_True ); + } + break; + + case EMR_EXTSELECTCLIPRGN : + { + sal_Int32 iMode, cbRgnData; + *pWMF >> cbRgnData + >> iMode; + + PolyPolygon aPolyPoly; + if ( cbRgnData ) + ImplReadRegion( aPolyPoly, *pWMF, nRecSize ); + pOut->SetClipPath( aPolyPoly, iMode, sal_False ); + } + break; + + case EMR_BITBLT : // PASSTHROUGH INTENDED + case EMR_STRETCHBLT : + { + INT32 xDest, yDest, cxDest, cyDest, xSrc, ySrc, cxSrc, cySrc; + UINT32 dwRop, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc; + XForm xformSrc; + + UINT32 nStart = pWMF->Tell() - 8; + + pWMF->SeekRel( 0x10 ); + *pWMF >> xDest >> yDest >> cxDest >> cyDest >> dwRop >> xSrc >> ySrc + >> xformSrc >> nColor >> iUsageSrc >> offBmiSrc >> cbBmiSrc + >> offBitsSrc >> cbBitsSrc; + + if ( nRecType == EMR_STRETCHBLT ) + *pWMF >> cxSrc >> cySrc; + else + cxSrc = cySrc = 0; + + Bitmap aBitmap; + Rectangle aRect( Point( xDest, yDest ), Size( cxDest+1, cyDest+1 ) ); + + cxDest = abs( (int)cxDest ); // sj: i37894, size can be negative + cyDest = abs( (int)cyDest ); // and also 122889 + + if ( (cbBitsSrc > (SAL_MAX_UINT32 - 14)) || ((SAL_MAX_UINT32 - 14) - cbBitsSrc < cbBmiSrc) ) + bStatus = FALSE; + else + { + UINT32 nSize = cbBmiSrc + cbBitsSrc + 14; + if ( nSize <= ( nEndPos - nStartPos ) ) + { + char* pBuf = new char[ nSize ]; + SvMemoryStream aTmp( pBuf, nSize, STREAM_READ | STREAM_WRITE ); + aTmp.ObjectOwnsMemory( TRUE ); + aTmp << (BYTE)'B' + << (BYTE)'M' + << (UINT32)cbBitsSrc + << (UINT16)0 + << (UINT16)0 + << (UINT32)cbBmiSrc + 14; + pWMF->Seek( nStart + offBmiSrc ); + pWMF->Read( pBuf + 14, cbBmiSrc ); + pWMF->Seek( nStart + offBitsSrc ); + pWMF->Read( pBuf + 14 + cbBmiSrc, cbBitsSrc ); + aTmp.Seek( 0 ); + aBitmap.Read( aTmp, TRUE ); + + // test if it is sensible to crop + if ( ( cxSrc > 0 ) && ( cySrc > 0 ) && + ( xSrc >= 0 ) && ( ySrc >= 0 ) && + ( xSrc + cxSrc <= aBitmap.GetSizePixel().Width() ) && + ( ySrc + cySrc <= aBitmap.GetSizePixel().Height() ) ) + { + Rectangle aCropRect( Point( xSrc, ySrc ), Size( cxSrc, cySrc ) ); + aBitmap.Crop( aCropRect ); + } + aBmpSaveList.Insert( new BSaveStruct( aBitmap, aRect, dwRop ), LIST_APPEND ); + } + } + } + break; + + case EMR_STRETCHDIBITS : + { + INT32 xDest, yDest, xSrc, ySrc, cxSrc, cySrc, cxDest, cyDest; + UINT32 offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, iUsageSrc, dwRop; + UINT32 nStart = pWMF->Tell() - 8; + + pWMF->SeekRel( 0x10 ); + *pWMF >> xDest >> yDest >> xSrc >> ySrc >> cxSrc >> cySrc >> offBmiSrc >> cbBmiSrc >> offBitsSrc + >> cbBitsSrc >> iUsageSrc >> dwRop >> cxDest >> cyDest; + + Bitmap aBitmap; + Rectangle aRect( Point( xDest, yDest ), Size( cxDest+1, cyDest+1 ) ); + + cxDest = abs( (int)cxDest ); // sj: i37894, size can be negative + cyDest = abs( (int)cyDest ); // and also 122889 + + if ( (cbBitsSrc > (SAL_MAX_UINT32 - 14)) || ((SAL_MAX_UINT32 - 14) - cbBitsSrc < cbBmiSrc) ) + bStatus = FALSE; + else + { + UINT32 nSize = cbBmiSrc + cbBitsSrc + 14; + if ( nSize <= ( nEndPos - nStartPos ) ) + { + char* pBuf = new char[ nSize ]; + SvMemoryStream aTmp( pBuf, nSize, STREAM_READ | STREAM_WRITE ); + aTmp.ObjectOwnsMemory( TRUE ); + aTmp << (BYTE)'B' + << (BYTE)'M' + << (UINT32)cbBitsSrc + << (UINT16)0 + << (UINT16)0 + << (UINT32)cbBmiSrc + 14; + pWMF->Seek( nStart + offBmiSrc ); + pWMF->Read( pBuf + 14, cbBmiSrc ); + pWMF->Seek( nStart + offBitsSrc ); + pWMF->Read( pBuf + 14 + cbBmiSrc, cbBitsSrc ); + aTmp.Seek( 0 ); + aBitmap.Read( aTmp, TRUE ); + + // test if it is sensible to crop + if ( ( cxSrc > 0 ) && ( cySrc > 0 ) && + ( xSrc >= 0 ) && ( ySrc >= 0 ) && + ( xSrc + cxSrc <= aBitmap.GetSizePixel().Width() ) && + ( ySrc + cySrc <= aBitmap.GetSizePixel().Height() ) ) + { + Rectangle aCropRect( Point( xSrc, ySrc ), Size( cxSrc, cySrc ) ); + aBitmap.Crop( aCropRect ); + } + aBmpSaveList.Insert( new BSaveStruct( aBitmap, aRect, dwRop ), LIST_APPEND ); + } + } + } + break; + + case EMR_EXTCREATEFONTINDIRECTW : + { + *pWMF >> nIndex; + if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) + { + LOGFONTW aLogFont; + *pWMF >> aLogFont.lfHeight >> aLogFont.lfWidth >> aLogFont.lfEscapement >> aLogFont.lfOrientation >> aLogFont.lfWeight >> aLogFont.lfItalic + >> aLogFont.lfUnderline >> aLogFont.lfStrikeOut >> aLogFont.lfCharSet >> aLogFont.lfOutPrecision >> aLogFont.lfClipPrecision + >> aLogFont.lfQuality >> aLogFont.lfPitchAndFamily; + + sal_Unicode lfFaceName[ LF_FACESIZE ]; + + for ( int i = 0; i < LF_FACESIZE; i++ ) + { + UINT16 nChar; + *pWMF >> nChar; + lfFaceName[ i ] = nChar; + } + aLogFont.alfFaceName = UniString( lfFaceName ); + pOut->CreateObject( nIndex, GDI_FONT, new WinMtfFontStyle( aLogFont ) ); + } + } + break; + + case EMR_EXTTEXTOUTA : + bFlag = sal_True; + case EMR_EXTTEXTOUTW : + { + sal_Int32 nLeft, nTop, nRight, nBottom, ptlReferenceX, ptlReferenceY, nGfxMode, nXScale, nYScale; + sal_uInt32 nCurPos, nLen, nOffString, nOptions, offDx; + sal_Int32* pDX = NULL; + + nCurPos = pWMF->Tell() - 8; + + *pWMF >> nLeft >> nTop >> nRight >> nBottom >> nGfxMode >> nXScale >> nYScale + >> ptlReferenceX >> ptlReferenceY >> nLen >> nOffString >> nOptions; + + pWMF->SeekRel( 0x10 ); + *pWMF >> offDx; + + sal_Int32 nTextLayoutMode = TEXT_LAYOUT_DEFAULT; + if ( nOptions & ETO_RTLREADING ) + nTextLayoutMode = TEXT_LAYOUT_BIDI_RTL | TEXT_LAYOUT_TEXTORIGIN_LEFT; + pOut->SetTextLayoutMode( nTextLayoutMode ); + DBG_ASSERT( ( nOptions & ( ETO_PDY | ETO_GLYPH_INDEX ) ) == 0, "SJ: ETO_PDY || ETO_GLYPH_INDEX in EMF" ); + + Point aPos( ptlReferenceX, ptlReferenceY ); + if ( nLen && ( nLen < SAL_MAX_UINT32 / sizeof(sal_Int32) ) ) + { + if ( offDx && (( nCurPos + offDx + nLen * 4 ) <= nNextPos ) ) + { + pWMF->Seek( nCurPos + offDx ); + if ( ( nLen * sizeof(sal_uInt32) ) <= ( nEndPos - pWMF->Tell() ) ) + { + pDX = new sal_Int32[ nLen ]; + sal_uInt32 i; + for ( i = 0; i < nLen; i++ ) + *pWMF >> pDX[ i ]; + } + } + pWMF->Seek( nCurPos + nOffString ); + String aText; + if ( bFlag ) + { + if ( nLen <= ( nEndPos - pWMF->Tell() ) ) + { + sal_Char* pBuf = new sal_Char[ nLen ]; + pWMF->Read( pBuf, nLen ); + aText = String( pBuf, (sal_uInt16)nLen, pOut->GetCharSet() ); + delete[] pBuf; + + if ( aText.Len() != nLen ) + { + sal_uInt16 i, j, k; + sal_Int32* pOldDx = pDX; + pDX = new sal_Int32[ aText.Len() ]; + for ( i = 0, j = 0; i < aText.Len(); i++ ) + { + ByteString aCharacter( aText.GetChar( i ), pOut->GetCharSet() ); + pDX[ i ] = 0; + for ( k = 0; ( k < aCharacter.Len() ) && ( j < nLen ) && ( i < aText.Len() ); k++ ) + pDX[ i ] += pOldDx[ j++ ]; + } + delete[] pOldDx; + } + } + } + else + { + if ( ( nLen * sizeof(sal_Unicode) ) <= ( nEndPos - pWMF->Tell() ) ) + { + sal_Unicode* pBuf = new sal_Unicode[ nLen ]; + pWMF->Read( pBuf, nLen << 1 ); +#ifdef OSL_BIGENDIAN + sal_Char nTmp, *pTmp = (sal_Char*)( pBuf + nLen ); + while ( pTmp-- != (sal_Char*)pBuf ) + { + nTmp = *pTmp--; + pTmp[ 1 ] = *pTmp; + *pTmp = nTmp; + } +#endif + aText = String( pBuf, (xub_StrLen)nLen ); + delete[] pBuf; + } + } + pOut->DrawText( aPos, aText, pDX, bRecordPath, nGfxMode ); + } + delete[] pDX; + } + break; + + case EMR_POLYBEZIERTO16 : + bFlag = sal_True; + case EMR_POLYBEZIER16 : + { + pWMF->SeekRel( 16 ); + *pWMF >> nPoints; + UINT16 i = 0; + if ( bFlag ) + { + i++; + nPoints++; + } + Polygon aPoly( (UINT16)nPoints ); + for( ; i < (UINT16)nPoints; i++ ) + { + *pWMF >> nX16 >> nY16; + aPoly[ i ] = Point( nX16, nY16 ); + } + pOut->DrawPolyBezier( aPoly, bFlag, bRecordPath ); // Line( aPoly, bFlag ); + } + break; + + case EMR_POLYGON16 : + { + pWMF->SeekRel( 16 ); + *pWMF >> nPoints; + Polygon aPoly( (UINT16)nPoints ); + for( UINT16 k = 0; k < (UINT16)nPoints; k++ ) + { + *pWMF >> nX16 >> nY16; + aPoly[ k ] = Point( nX16, nY16 ); + } + pOut->DrawPolygon( aPoly, bRecordPath ); + } + break; + + case EMR_POLYLINETO16 : + bFlag = sal_True; + case EMR_POLYLINE16 : + { + pWMF->SeekRel( 16 ); + *pWMF >> nPoints; + UINT16 i = 0; + if ( bFlag ) + { + i++; + nPoints++; + } + + Polygon aPoly( (UINT16)nPoints ); + for( ; i < (UINT16)nPoints; i++ ) + { + *pWMF >> nX16 >> nY16; + aPoly[ i ] = Point( nX16, nY16 ); + } + pOut->DrawPolyLine( aPoly, bFlag, bRecordPath ); + } + break; + + case EMR_POLYPOLYLINE16 : + { + UINT16* pnPoints; + + INT32 i, nPoly, nGesPoints; + pWMF->SeekRel( 0x10 ); + // Anzahl der Polygone: + *pWMF >> nPoly >> nGesPoints; + + // taking the amount of points of each polygon, retrieving the total number of points + if ( static_cast< sal_uInt32 >(nPoly) < SAL_MAX_UINT32 / sizeof(UINT16) ) + { + if ( ( static_cast< sal_uInt32 >( nPoly ) * sizeof(UINT16) ) <= ( nEndPos - pWMF->Tell() ) ) + { + pnPoints = new UINT16[ nPoly ]; + for ( i = 0; i < nPoly; i++ ) + { + *pWMF >> nPoints; + pnPoints[ i ] = (UINT16)nPoints; + } + // Polygonpunkte holen: + for ( i = 0; ( i < nPoly ) && !pWMF->IsEof(); i++ ) + { + Polygon aPolygon( pnPoints[ i ] ); + for ( UINT16 k = 0; k < pnPoints[ i ]; k++ ) + { + *pWMF >> nX16 >> nY16; + aPolygon[ k ] = Point( nX16, nY16 ); + } + pOut->DrawPolyLine( aPolygon, sal_False, bRecordPath ); + } + delete[] pnPoints; + } + } + } + break; + + case EMR_POLYPOLYGON16 : + { + UINT16* pnPoints; + Point* pPtAry; + + UINT32 i, nPoly, nGesPoints; + pWMF->SeekRel( 0x10 ); + // Anzahl der Polygone: + *pWMF >> nPoly >> nGesPoints; + if ( ( nGesPoints < SAL_MAX_UINT32 / sizeof(Point) ) && ( nPoly < SAL_MAX_UINT32 / sizeof(UINT16) ) ) + { + if ( ( static_cast< sal_uInt32 >( nPoly ) * sizeof( UINT16 ) ) <= ( nEndPos - pWMF->Tell() ) ) + { + pnPoints = new UINT16[ nPoly ]; + for ( i = 0; i < nPoly; i++ ) + { + *pWMF >> nPoints; + pnPoints[ i ] = (UINT16)nPoints; + } + if ( ( nGesPoints * (sizeof(sal_uInt16)+sizeof(sal_uInt16)) ) <= ( nEndPos - pWMF->Tell() ) ) + { + // Polygonpunkte holen: + pPtAry = new Point[ nGesPoints ]; + for ( i = 0; i < nGesPoints; i++ ) + { + *pWMF >> nX16 >> nY16; + pPtAry[ i ] = Point( nX16, nY16 ); + } + + // PolyPolygon Actions erzeugen + PolyPolygon aPolyPoly( (UINT16)nPoly, pnPoints, pPtAry ); + pOut->DrawPolyPolygon( aPolyPoly, bRecordPath ); + delete[] pPtAry; + } + delete[] pnPoints; + } + } + } + break; + + case EMR_FILLRGN : + { + sal_uInt32 nLen; + PolyPolygon aPolyPoly; + pWMF->SeekRel( 0x10 ); + *pWMF >> nLen >> nIndex; + + if ( ImplReadRegion( aPolyPoly, *pWMF, nRecSize ) ) + { + pOut->Push(); + pOut->SelectObject( nIndex ); + pOut->DrawPolyPolygon( aPolyPoly, sal_False ); + pOut->Pop(); + } + } + break; + + +#ifdef WIN_MTF_ASSERT + default : WinMtfAssertHandler( "Unknown Meta Action" ); break; + case EMR_MASKBLT : WinMtfAssertHandler( "MaskBlt" ); break; + case EMR_PLGBLT : WinMtfAssertHandler( "PlgBlt" ); break; + case EMR_SETDIBITSTODEVICE : WinMtfAssertHandler( "SetDIBitsToDevice" ); break; + case EMR_FRAMERGN : WinMtfAssertHandler( "FrameRgn" ); break; + case EMR_INVERTRGN : WinMtfAssertHandler( "InvertRgn" ); break; + case EMR_PAINTRGN : WinMtfAssertHandler( "PaintRgn" ); break; + case EMR_FLATTENPATH : WinMtfAssertHandler( "FlattenPath" ); break; + case EMR_WIDENPATH : WinMtfAssertHandler( "WidenPath" ); break; + case EMR_POLYDRAW : WinMtfAssertHandler( "Polydraw" ); break; + case EMR_SETARCDIRECTION : WinMtfAssertHandler( "SetArcDirection" ); break; + case EMR_SETPALETTEENTRIES : WinMtfAssertHandler( "SetPaletteEntries" ); break; + case EMR_RESIZEPALETTE : WinMtfAssertHandler( "ResizePalette" ); break; + case EMR_EXTFLOODFILL : WinMtfAssertHandler( "ExtFloodFill" ); break; + case EMR_ANGLEARC : WinMtfAssertHandler( "AngleArc" ); break; + case EMR_SETCOLORADJUSTMENT : WinMtfAssertHandler( "SetColorAdjustment" ); break; + case EMR_POLYDRAW16 : WinMtfAssertHandler( "PolyDraw16" ); break; + case EMR_CREATEDIBPATTERNBRUSHPT : WinMtfAssertHandler( "CreateDibPatternBrushPt" ); break; + case EMR_POLYTEXTOUTA : WinMtfAssertHandler( "PolyTextOutA" ); break; + case EMR_POLYTEXTOUTW : WinMtfAssertHandler( "PolyTextOutW" ); break; + case EMR_CREATECOLORSPACE : WinMtfAssertHandler( "CreateColorSpace" ); break; + case EMR_SETCOLORSPACE : WinMtfAssertHandler( "SetColorSpace" ); break; + case EMR_DELETECOLORSPACE : WinMtfAssertHandler( "DeleteColorSpace" ); break; + case EMR_GLSRECORD : WinMtfAssertHandler( "GlsRecord" ); break; + case EMR_GLSBOUNDEDRECORD : WinMtfAssertHandler( "GlsBoundRecord" ); break; + case EMR_PIXELFORMAT : WinMtfAssertHandler( "PixelFormat" ); break; + case EMR_DRAWESCAPE : WinMtfAssertHandler( "DrawEscape" ); break; + case EMR_EXTESCAPE : WinMtfAssertHandler( "ExtEscape" ); break; + case EMR_STARTDOC : WinMtfAssertHandler( "StartDoc" ); break; + case EMR_SMALLTEXTOUT : WinMtfAssertHandler( "SmallTextOut" ); break; + case EMR_FORCEUFIMAPPING : WinMtfAssertHandler( "ForceUFIMapping" ); break; + case EMR_NAMEDESCAPE : WinMtfAssertHandler( "NamedEscape" ); break; + case EMR_COLORCORRECTPALETTE : WinMtfAssertHandler( "ColorCorrectPalette" ); break; + case EMR_SETICMPROFILEA : WinMtfAssertHandler( "SetICMProfileA" ); break; + case EMR_SETICMPROFILEW : WinMtfAssertHandler( "SetICMProfileW" ); break; + case EMR_ALPHABLEND : WinMtfAssertHandler( "Alphablend" ); break; + case EMR_TRANSPARENTBLT : WinMtfAssertHandler( "TransparenBlt" ); break; + case EMR_TRANSPARENTDIB : WinMtfAssertHandler( "TransparenDib" ); break; + case EMR_GRADIENTFILL : WinMtfAssertHandler( "GradientFill" ); break; + case EMR_SETLINKEDUFIS : WinMtfAssertHandler( "SetLinkedUFIS" ); break; + + case EMR_SETMAPPERFLAGS : WinMtfAssertHandler( "SetMapperFlags", 0 ); break; + case EMR_SETICMMODE : WinMtfAssertHandler( "SetICMMode", 0 ); break; + case EMR_CREATEMONOBRUSH : WinMtfAssertHandler( "CreateMonoBrush", 0 ); break; + case EMR_SETBRUSHORGEX : WinMtfAssertHandler( "SetBrushOrgEx", 0 ); break; + case EMR_SETMETARGN : WinMtfAssertHandler( "SetMetArgn", 0 ); break; + case EMR_SETMITERLIMIT : WinMtfAssertHandler( "SetMiterLimit", 0 ); break; + case EMR_EXCLUDECLIPRECT : WinMtfAssertHandler( "ExcludeClipRect", 0 ); break; + case EMR_REALIZEPALETTE : WinMtfAssertHandler( "RealizePalette", 0 ); break; + case EMR_SELECTPALETTE : WinMtfAssertHandler( "SelectPalette", 0 ); break; + case EMR_CREATEPALETTE : WinMtfAssertHandler( "CreatePalette", 0 ); break; + case EMR_ALPHADIBBLEND : WinMtfAssertHandler( "AlphaDibBlend", 0 ); break; + case EMR_SETTEXTJUSTIFICATION : WinMtfAssertHandler( "SetTextJustification", 0 ); break; + + case EMR_GDICOMMENT : + case EMR_HEADER : // has already been read at ReadHeader() + break; +#endif + } + pWMF->Seek( nNextPos ); + } + if( aBmpSaveList.Count() ) + pOut->ResolveBitmapActions( aBmpSaveList ); + + if ( bStatus ) + pWMF->Seek(nEndPos); + + return bStatus; +}; + +//----------------------------------------------------------------------------------- + +BOOL EnhWMFReader::ReadHeader() +{ + UINT32 nUINT32, nHeaderSize, nPalEntries; + INT32 nLeft, nTop, nRight, nBottom; + + // METAFILEHEADER SPARE ICH MIR HIER + // Einlesen des METAHEADER + *pWMF >> nUINT32 >> nHeaderSize; + if ( nUINT32 != 1 ) // Typ + return FALSE; + + // bound size + Rectangle rclBounds; // rectangle in logical units 1/100th mm + *pWMF >> nLeft >> nTop >> nRight >> nBottom; + rclBounds.Left() = nLeft; + rclBounds.Top() = nTop; + rclBounds.Right() = nRight; + rclBounds.Bottom() = nBottom; + + // picture frame size + Rectangle rclFrame; // rectangle in device units + *pWMF >> nLeft >> nTop >> nRight >> nBottom; + rclFrame.Left() = nLeft; + rclFrame.Top() = nTop; + rclFrame.Right() = nRight; + rclFrame.Bottom() = nBottom; + + *pWMF >> nUINT32; // signature + + if ( nUINT32 != 0x464d4520 ) + return FALSE; + + *pWMF >> nUINT32; // nVersion + *pWMF >> nEndPos; // size of metafile + nEndPos += nStartPos; + + sal_uInt32 nStrmPos = pWMF->Tell(); // checking if nEndPos is valid + pWMF->Seek( STREAM_SEEK_TO_END ); + if ( pWMF->Tell() < nEndPos ) + nEndPos = pWMF->Tell(); + pWMF->Seek( nStrmPos ); + + *pWMF >> nRecordCount; + + if ( !nRecordCount ) + return FALSE; + + pWMF->SeekRel( 0xc ); + + sal_Int32 nPixX, nPixY, nMillX, nMillY; + *pWMF >> nPalEntries >> nPixX >> nPixY >> nMillX >> nMillY; + + pOut->SetrclFrame( rclFrame ); + pOut->SetrclBounds( rclBounds ); + pOut->SetRefPix( Size( nPixX, nPixY ) ); + pOut->SetRefMill( Size( nMillX, nMillY ) ); + + pWMF->Seek( nStartPos + nHeaderSize ); + return TRUE; +} + +//----------------------------------------------------------------------------------- + +Rectangle EnhWMFReader::ReadRectangle( INT32 x1, INT32 y1, INT32 x2, INT32 y2 ) +{ + Point aTL ( Point( x1, y1 ) ); + Point aBR( Point( --x2, --y2 ) ); + return Rectangle( aTL, aBR ); +} + +EnhWMFReader::~EnhWMFReader() +{ + +}; + diff --git a/svtools/source/filter/wmf/winmtf.cxx b/svtools/source/filter/wmf/winmtf.cxx new file mode 100644 index 000000000000..787e6522b890 --- /dev/null +++ b/svtools/source/filter/wmf/winmtf.cxx @@ -0,0 +1,2203 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + + +#include "winmtf.hxx" +#include +#include +#include + +// ------------------------------------------------------------------------ + +#define WIN_MTF_MAX_CLIP_DEPTH 16 + +void WinMtfClipPath::ImpUpdateType() +{ + if ( !aPolyPoly.Count() ) + eType = EMPTY; + else if ( aPolyPoly.IsRect() ) + eType = RECTANGLE; + else + eType = COMPLEX; + + bNeedsUpdate = sal_True; +} + +void WinMtfClipPath::IntersectClipRect( const Rectangle& rRect ) +{ + if ( !aPolyPoly.Count() ) + aPolyPoly = Polygon( rRect ); + else if ( nDepth < WIN_MTF_MAX_CLIP_DEPTH ) + { + Polygon aPolygon( rRect ); + PolyPolygon aIntersection; + PolyPolygon aPolyPolyRect( aPolygon ); + aPolyPoly.GetIntersection( aPolyPolyRect, aIntersection ); + aPolyPoly = aIntersection; + nDepth++; + } + ImpUpdateType(); +} + +void WinMtfClipPath::ExcludeClipRect( const Rectangle& rRect ) +{ + if ( aPolyPoly.Count() && ( nDepth < WIN_MTF_MAX_CLIP_DEPTH ) ) + { + Polygon aPolygon( rRect ); + PolyPolygon aPolyPolyRect( aPolygon ); + PolyPolygon aDifference; + aPolyPoly.GetDifference( aPolyPolyRect, aDifference ); + aPolyPoly = aDifference; + nDepth++; + } + ImpUpdateType(); +} + +void WinMtfClipPath::SetClipPath( const PolyPolygon& rPolyPolygon, sal_Int32 nClippingMode ) +{ + if ( !rPolyPolygon.Count() ) + aPolyPoly = rPolyPolygon; + else if ( nDepth < WIN_MTF_MAX_CLIP_DEPTH ) + { + nDepth++; + + PolyPolygon aNewClipPath; + + // #115345# Watch out for empty aPolyPoly here - conceptually, + // an empty clip path is a rectangle of infinite size, but it + // is represented by an empty aPolyPoly. When intersecting + // rPolyPolygon with this _empty_ aPolyPoly, set algebra + // guarantees wrong results. + switch ( nClippingMode ) + { + case RGN_OR : + // #115345# clip stays empty, when ORing an arbitrary + // rPolyPolygon. Thus, we can save us the unnecessary + // clipper call. + if( aPolyPoly.Count() ) + aPolyPoly.GetUnion( rPolyPolygon, aNewClipPath ); + break; + case RGN_XOR : + // TODO: + // #115345# Cannot handle this case, for the time being + aPolyPoly.GetXOR( rPolyPolygon, aNewClipPath ); + break; + case RGN_DIFF : + // TODO: + // #115345# Cannot handle this case, for the time being + aPolyPoly.GetDifference( rPolyPolygon, aNewClipPath ); + break; + case RGN_AND : + // #115345# Clip becomes rPolyPolygon, when ANDing + // with an arbitrary rPolyPolygon + if( aPolyPoly.Count() ) + aPolyPoly.GetIntersection( rPolyPolygon, aNewClipPath ); + else + aNewClipPath = rPolyPolygon; + break; + case RGN_COPY : + aNewClipPath = rPolyPolygon; + break; + } + aPolyPoly = aNewClipPath; + } + ImpUpdateType(); +} + +void WinMtfClipPath::MoveClipRegion( const Size& rSize ) +{ + aPolyPoly.Move( rSize.Width(), rSize.Height() ); + bNeedsUpdate = sal_True; +} + +// ------------------------------------------------------------------------ + +void WinMtfPathObj::AddPoint( const Point& rPoint ) +{ + if ( bClosed ) + Insert( Polygon(), POLYPOLY_APPEND ); + Polygon& rPoly = ((PolyPolygon&)*this)[ Count() - 1 ]; + rPoly.Insert( rPoly.GetSize(), rPoint, POLY_NORMAL ); + bClosed = sal_False; +} + +void WinMtfPathObj::AddPolyLine( const Polygon& rPolyLine ) +{ + if ( bClosed ) + Insert( Polygon(), POLYPOLY_APPEND ); + Polygon& rPoly = ((PolyPolygon&)*this)[ Count() - 1 ]; + rPoly.Insert( rPoly.GetSize(), rPolyLine ); + bClosed = sal_False; +} + +void WinMtfPathObj::AddPolygon( const Polygon& rPoly ) +{ + Insert( rPoly, POLYPOLY_APPEND ); + bClosed = sal_True; +} + +void WinMtfPathObj::AddPolyPolygon( const PolyPolygon& rPolyPoly ) +{ + sal_uInt16 i, nCount = rPolyPoly.Count(); + for ( i = 0; i < nCount; i++ ) + Insert( rPolyPoly[ i ], POLYPOLY_APPEND ); + bClosed = sal_True; +} + +void WinMtfPathObj::ClosePath() +{ + if ( Count() ) + { + Polygon& rPoly = ((PolyPolygon&)*this)[ Count() - 1 ]; + if ( rPoly.GetSize() > 2 ) + { + Point aFirst( rPoly[ 0 ] ); + if ( aFirst != rPoly[ rPoly.GetSize() - 1 ] ) + rPoly.Insert( rPoly.GetSize(), aFirst, POLY_NORMAL ); + } + } + bClosed = sal_True; +} + +// ------------------------------------------------------------------------ + +WinMtfFontStyle::WinMtfFontStyle( LOGFONTW& rFont ) +{ + CharSet eCharSet; + if ( ( rFont.lfCharSet == OEM_CHARSET ) || ( rFont.lfCharSet == DEFAULT_CHARSET ) ) + eCharSet = gsl_getSystemTextEncoding(); + else + eCharSet = rtl_getTextEncodingFromWindowsCharset( rFont.lfCharSet ); + if ( eCharSet == RTL_TEXTENCODING_DONTKNOW ) + eCharSet = gsl_getSystemTextEncoding(); + aFont.SetCharSet( eCharSet ); + aFont.SetName( rFont.alfFaceName ); + FontFamily eFamily; + switch ( rFont.lfPitchAndFamily & 0xf0 ) + { + case FF_ROMAN: + eFamily = FAMILY_ROMAN; + break; + + case FF_SWISS: + eFamily = FAMILY_SWISS; + break; + + case FF_MODERN: + eFamily = FAMILY_MODERN; + break; + + case FF_SCRIPT: + eFamily = FAMILY_SCRIPT; + break; + + case FF_DECORATIVE: + eFamily = FAMILY_DECORATIVE; + break; + + default: + eFamily = FAMILY_DONTKNOW; + break; + } + aFont.SetFamily( eFamily ); + + FontPitch ePitch; + switch ( rFont.lfPitchAndFamily & 0x0f ) + { + case FIXED_PITCH: + ePitch = PITCH_FIXED; + break; + + case DEFAULT_PITCH: + case VARIABLE_PITCH: + default: + ePitch = PITCH_VARIABLE; + break; + } + aFont.SetPitch( ePitch ); + + FontWeight eWeight; + if( rFont.lfWeight <= FW_THIN ) + eWeight = WEIGHT_THIN; + else if( rFont.lfWeight <= FW_ULTRALIGHT ) + eWeight = WEIGHT_ULTRALIGHT; + else if( rFont.lfWeight <= FW_LIGHT ) + eWeight = WEIGHT_LIGHT; + else if( rFont.lfWeight < FW_MEDIUM ) + eWeight = WEIGHT_NORMAL; + else if( rFont.lfWeight == FW_MEDIUM ) + eWeight = WEIGHT_MEDIUM; + else if( rFont.lfWeight <= FW_SEMIBOLD ) + eWeight = WEIGHT_SEMIBOLD; + else if( rFont.lfWeight <= FW_BOLD ) + eWeight = WEIGHT_BOLD; + else if( rFont.lfWeight <= FW_ULTRABOLD ) + eWeight = WEIGHT_ULTRABOLD; + else + eWeight = WEIGHT_BLACK; + aFont.SetWeight( eWeight ); + + if( rFont.lfItalic ) + aFont.SetItalic( ITALIC_NORMAL ); + + if( rFont.lfUnderline ) + aFont.SetUnderline( UNDERLINE_SINGLE ); + + if( rFont.lfStrikeOut ) + aFont.SetStrikeout( STRIKEOUT_SINGLE ); + + if ( rFont.lfOrientation ) + aFont.SetOrientation( (short)rFont.lfOrientation ); + else + aFont.SetOrientation( (short)rFont.lfEscapement ); + + Size aFontSize( Size( rFont.lfWidth, rFont.lfHeight ) ); + if ( rFont.lfHeight > 0 ) + { + // converting the cell height into a font height + VirtualDevice aVDev; + aFont.SetSize( aFontSize ); + aVDev.SetFont( aFont ); + FontMetric aMetric( aVDev.GetFontMetric() ); + long nHeight = aMetric.GetAscent() + aMetric.GetDescent(); + if ( nHeight ) + { + double fHeight = ((double)aFontSize.Height() * rFont.lfHeight ) / nHeight; + aFontSize.Height() = (sal_Int32)( fHeight + 0.5 ); + } + } + else if ( aFontSize.Height() < 0 ) + aFontSize.Height() *= -1; + + if ( !rFont.lfWidth ) + { + VirtualDevice aVDev; + aFont.SetSize( aFontSize ); + aVDev.SetFont( aFont ); + FontMetric aMetric( aVDev.GetFontMetric() ); + aFontSize.Width() = aMetric.GetWidth(); + } + + aFont.SetSize( aFontSize ); +}; + +// ------------------------------------------------------------------------ + +#ifdef WIN_MTF_ASSERT +void WinMtfAssertHandler( const sal_Char* pAction, sal_uInt32 nFlags ) +{ + static sal_Bool bOnlyOnce; + static sal_Int32 nAssertCount; + + if ( nFlags & WIN_MTF_ASSERT_INIT ) + nAssertCount = 0; + if ( nFlags & WIN_MTF_ASSERT_ONCE ) + bOnlyOnce = sal_True; + if ( nFlags & WIN_MTF_ASSERT_MIFE ) + { + if ( ( nAssertCount == 0 ) || ( bOnlyOnce == sal_False ) ) + { + ByteString aText( "WMF/EMF Import: " ); + if ( pAction ) + { + ByteString aAction( pAction ); + aText.Append( aAction ); + } + aText.Append( " needs to be implemented (SJ)" ); + DBG_ASSERT( 0, aText.GetBuffer() ); + } + nAssertCount++; + } +} +#endif + +// ------------------------------------------------------------------------ + +WinMtf::WinMtf( WinMtfOutput* pWinMtfOutput, SvStream& rStreamWMF, FilterConfigItem* pConfigItem ) : + pOut ( pWinMtfOutput ), + pWMF ( &rStreamWMF ), + pFilterConfigItem ( pConfigItem ) +{ +#ifdef WIN_MTF_ASSERT + // we want to assert not implemented features, but we do this + // only once, so that nobody is handicaped by getting too much assertions + // I hope this will bring more testdocuments, without support of these + // testdocuments the implementation of missing features won't be possible. (SJ) + WinMtfAssertHandler( NULL, WIN_MTF_ASSERT_INIT | WIN_MTF_ASSERT_ONCE ); +#endif + + SvLockBytes *pLB = pWMF->GetLockBytes(); + if ( pLB ) + pLB->SetSynchronMode( TRUE ); + + nStartPos = pWMF->Tell(); + + pOut->SetDevOrg( Point() ); + if ( pFilterConfigItem ) + { + xStatusIndicator = pFilterConfigItem->GetStatusIndicator(); + if ( xStatusIndicator.is() ) + { + rtl::OUString aMsg; + xStatusIndicator->start( aMsg, 100 ); + } + } +} + +// ------------------------------------------------------------------------ + +WinMtf::~WinMtf() +{ + delete pOut; + + if ( xStatusIndicator.is() ) + xStatusIndicator->end(); +} + +// ------------------------------------------------------------------------ + +void WinMtf::Callback( USHORT nPercent ) +{ + if ( xStatusIndicator.is() ) + xStatusIndicator->setValue( nPercent ); +} + +// ------------------------------------------------------------------------ + +Color WinMtf::ReadColor() +{ + UINT32 nColor; + *pWMF >> nColor; + return Color( (BYTE)nColor, (BYTE)( nColor >> 8 ), (BYTE)( nColor >> 16 ) ); +}; + +//----------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------- + +Point WinMtfOutput::ImplMap( const Point& rPt ) +{ + if ( mnWinExtX && mnWinExtY ) + { + double fX2, fX = rPt.X(); + double fY2, fY = rPt.Y(); + + fX2 = fX * maXForm.eM11 + fY * maXForm.eM21 + maXForm.eDx; + fY2 = fX * maXForm.eM12 + fY * maXForm.eM22 + maXForm.eDy; + + if ( mnGfxMode == GM_COMPATIBLE ) + { + switch( mnMapMode ) + { + case MM_LOENGLISH : + { + fX2 -= mnWinOrgX; + fY2 = mnWinOrgY-fY2; + fX2 *= 25.40; + fY2 *= 25.40; + fX2 += mnDevOrgX; + fY2 += mnDevOrgY; + } + break; + case MM_HIENGLISH : + { + fX2 -= mnWinOrgX; + fY2 = mnWinOrgY-fY2; + fX2 *= 2.540; + fY2 *= 2.540; + fX2 += mnDevOrgX; + fY2 += mnDevOrgY; + } + break; + case MM_LOMETRIC : + { + fX2 -= mnWinOrgX; + fY2 = mnWinOrgY-fY2; + fX2 *= 10; + fY2 *= 10; + fX2 += mnDevOrgX; + fY2 += mnDevOrgY; + } + break; + case MM_HIMETRIC : + { + fX2 -= mnWinOrgX; + fY2 = mnWinOrgY-fY2; + fX2 += mnDevOrgX; + fY2 += mnDevOrgY; + } + break; + default : + { + fX2 -= mnWinOrgX; + fY2 -= mnWinOrgY; + fX2 /= mnWinExtX; + fY2 /= mnWinExtY; + fX2 *= mnDevWidth; + fY2 *= mnDevHeight; + fX2 += mnDevOrgX; + fY2 += mnDevOrgY; // fX2, fY2 now in device units + fX2 *= (double)mnMillX * 100.0 / (double)mnPixX; + fY2 *= (double)mnMillY * 100.0 / (double)mnPixY; + } + break; + } + fX2 -= mrclFrame.Left(); + fY2 -= mrclFrame.Top(); + } + return Point( FRound( fX2 ), FRound( fY2 ) ); + } + else + return Point(); +}; + +// ------------------------------------------------------------------------ + +Size WinMtfOutput::ImplMap( const Size& rSz ) +{ + if ( mnWinExtX && mnWinExtY ) + { + double fWidth = rSz.Width() * maXForm.eM11; + double fHeight = rSz.Height() * maXForm.eM22; + + if ( mnGfxMode == GM_COMPATIBLE ) + { + switch( mnMapMode ) + { + case MM_LOENGLISH : + { + fWidth *= 25.40; + fHeight*=-25.40; + } + break; + case MM_HIENGLISH : + { + fWidth *= 2.540; + fHeight*=-2.540; + } + break; + case MM_LOMETRIC : + { + fWidth *= 10; + fHeight*=-10; + } + break; + case MM_HIMETRIC : + { + fHeight *= -1; + } + break; + default : + { + fWidth /= mnWinExtX; + fHeight /= mnWinExtY; + fWidth *= mnDevWidth; + fHeight *= mnDevHeight; + fWidth *= (double)mnMillX * 100 / (double)mnPixX; + fHeight *= (double)mnMillY * 100 / (double)mnPixY; + } + break; + } + } + return Size( FRound( fWidth ), FRound( fHeight ) ); + } + else + return Size(); +} + +//----------------------------------------------------------------------------------- + +Rectangle WinMtfOutput::ImplMap( const Rectangle& rRect ) +{ + return Rectangle( ImplMap( rRect.TopLeft() ), ImplMap( rRect.GetSize() ) ); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::ImplMap( Font& rFont ) +{ + // !!! HACK: Wir setzen die Breite jetzt immer auf Null, + // da OS die Breite unterschiedlich interpretieren; + // muss spaeter in SV portabel gemacht werden ( KA 08.02.96 ) + Size aFontSize = ImplMap ( rFont.GetSize() ); + + if( aFontSize.Height() < 0 ) + aFontSize.Height() *= -1; + + rFont.SetSize( aFontSize ); + + if( ( mnWinExtX * mnWinExtY ) < 0 ) + rFont.SetOrientation( 3600 - rFont.GetOrientation() ); +} + +//----------------------------------------------------------------------------------- + +Polygon& WinMtfOutput::ImplMap( Polygon& rPolygon ) +{ + UINT16 nPoints = rPolygon.GetSize(); + for ( UINT16 i = 0; i < nPoints; i++ ) + { + rPolygon[ i ] = ImplMap( rPolygon[ i ] ); + } + return rPolygon; +} + +//----------------------------------------------------------------------------------- + +PolyPolygon& WinMtfOutput::ImplMap( PolyPolygon& rPolyPolygon ) +{ + UINT16 nPolys = rPolyPolygon.Count(); + for ( UINT16 i = 0; i < nPolys; ImplMap( rPolyPolygon[ i++ ] ) ) ; + return rPolyPolygon; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SelectObject( INT32 nIndex ) +{ + GDIObj* pGDIObj = NULL; + + if ( nIndex & ENHMETA_STOCK_OBJECT ) + pGDIObj = new GDIObj(); + else + { + nIndex &= 0xffff; // zur Sicherheit: mehr als 65535 nicht zulassen + + if ( (UINT32)nIndex < vGDIObj.size() ) + pGDIObj = vGDIObj[ nIndex ]; + } + + if( pGDIObj == NULL ) + return; + + if ( nIndex & ENHMETA_STOCK_OBJECT ) + { + UINT16 nStockId = (BYTE)nIndex; + switch( nStockId ) + { + case WHITE_BRUSH : + { + pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_WHITE ) ) ); + } + break; + case LTGRAY_BRUSH : + { + pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_LIGHTGRAY ) ) ); + } + break; + case GRAY_BRUSH : + case DKGRAY_BRUSH : + { + pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_GRAY ) ) ); + } + break; + case BLACK_BRUSH : + { + pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_BLACK ) ) ); + } + break; + case NULL_BRUSH : + { + pGDIObj->Set( GDI_BRUSH, new WinMtfFillStyle( Color( COL_TRANSPARENT ), TRUE ) ); + } + break; + case WHITE_PEN : + { + pGDIObj->Set( GDI_PEN, new WinMtfLineStyle( Color( COL_WHITE ) ) ); + } + break; + case BLACK_PEN : + { + pGDIObj->Set( GDI_PEN, new WinMtfLineStyle( Color( COL_BLACK ) ) ); + } + break; + case NULL_PEN : + { + pGDIObj->Set( GDI_PEN, new WinMtfLineStyle( Color( COL_TRANSPARENT ), TRUE ) ); + } + break; + default: + break; + } + } + if ( pGDIObj->pStyle ) + { + switch( pGDIObj->eType ) + { + case GDI_PEN : + maLineStyle = (WinMtfLineStyle*)pGDIObj->pStyle; + break; + case GDI_BRUSH : + { + maFillStyle = (WinMtfFillStyle*)pGDIObj->pStyle; + mbFillStyleSelected = sal_True; + } + break; + case GDI_FONT : + maFont = ((WinMtfFontStyle*)pGDIObj->pStyle)->aFont; + break; + default: + break; // -Wall many options not handled. + } + } + if ( nIndex & ENHMETA_STOCK_OBJECT ) + delete pGDIObj; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetFont( const Font& rFont ) +{ + maFont = rFont; +} + +//----------------------------------------------------------------------------------- + +const Font& WinMtfOutput::GetFont() const +{ + return maFont; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetTextLayoutMode( const sal_uInt32 nTextLayoutMode ) +{ + mnTextLayoutMode = nTextLayoutMode; +} + +//----------------------------------------------------------------------------------- + +sal_uInt32 WinMtfOutput::GetTextLayoutMode() const +{ + return mnTextLayoutMode; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetBkMode( UINT32 nMode ) +{ + mnBkMode = nMode; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetBkColor( const Color& rColor ) +{ + maBkColor = rColor; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetTextColor( const Color& rColor ) +{ + maTextColor = rColor; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetTextAlign( UINT32 nAlign ) +{ + mnTextAlign = nAlign; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::ImplResizeObjectArry( UINT32 nNewEntrys ) +{ + sal_uInt32 i = vGDIObj.size(); + vGDIObj.resize( nNewEntrys ); + for ( ; i < nNewEntrys ; i++ ) + vGDIObj[ i ] = NULL; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::ImplDrawClippedPolyPolygon( const PolyPolygon& rPolyPoly ) +{ + if ( rPolyPoly.Count() ) + { + ImplSetNonPersistentLineColorTransparenz(); + if ( rPolyPoly.Count() == 1 ) + { + if ( rPolyPoly.IsRect() ) + mpGDIMetaFile->AddAction( new MetaRectAction( rPolyPoly.GetBoundRect() ) ); + else + { + Polygon aPoly( rPolyPoly[ 0 ] ); + sal_uInt16 nCount = aPoly.GetSize(); + if ( nCount ) + { + if ( aPoly[ nCount - 1 ] != aPoly[ 0 ] ) + { + Point aPoint( aPoly[ 0 ] ); + aPoly.Insert( nCount, aPoint ); + } + mpGDIMetaFile->AddAction( new MetaPolygonAction( aPoly ) ); + } + } + } + else + mpGDIMetaFile->AddAction( new MetaPolyPolygonAction( rPolyPoly ) ); + } +} + + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::CreateObject( GDIObjectType eType, void* pStyle ) +{ + if ( pStyle ) + { + if ( eType == GDI_FONT ) + { + ImplMap( ((WinMtfFontStyle*)pStyle)->aFont ); + if (!((WinMtfFontStyle*)pStyle)->aFont.GetHeight() ) + ((WinMtfFontStyle*)pStyle)->aFont.SetHeight( 423 ); // defaulting to 12pt + } + else if ( eType == GDI_PEN ) + { + Size aSize( ((WinMtfLineStyle*)pStyle)->aLineInfo.GetWidth(), 0 ); + ((WinMtfLineStyle*)pStyle)->aLineInfo.SetWidth( ImplMap( aSize ).Width() ); + if ( ((WinMtfLineStyle*)pStyle)->aLineInfo.GetStyle() == LINE_DASH ) + { + aSize.Width() += 1; + long nDotLen = ImplMap( aSize ).Width(); + ((WinMtfLineStyle*)pStyle)->aLineInfo.SetDistance( nDotLen ); + ((WinMtfLineStyle*)pStyle)->aLineInfo.SetDotLen( nDotLen ); + ((WinMtfLineStyle*)pStyle)->aLineInfo.SetDashLen( nDotLen * 4 ); + } + } + } + UINT32 nIndex; + for ( nIndex = 0; nIndex < vGDIObj.size(); nIndex++ ) + { + if ( vGDIObj[ nIndex ] == NULL ) + break; + } + if ( nIndex == vGDIObj.size() ) + ImplResizeObjectArry( vGDIObj.size() + 16 ); + + vGDIObj[ nIndex ] = new GDIObj( eType, pStyle ); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::CreateObject( INT32 nIndex, GDIObjectType eType, void* pStyle ) +{ + if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) + { + nIndex &= 0xffff; // zur Sicherheit: mehr als 65535 nicht zulassen + if ( pStyle ) + { + if ( eType == GDI_FONT ) + ImplMap( ((WinMtfFontStyle*)pStyle)->aFont ); + else if ( eType == GDI_PEN ) + { + Size aSize( ((WinMtfLineStyle*)pStyle)->aLineInfo.GetWidth(), 0 ); + ((WinMtfLineStyle*)pStyle)->aLineInfo.SetWidth( ImplMap( aSize ).Width() ); + if ( ((WinMtfLineStyle*)pStyle)->aLineInfo.GetStyle() == LINE_DASH ) + { + aSize.Width() += 1; + long nDotLen = ImplMap( aSize ).Width(); + ((WinMtfLineStyle*)pStyle)->aLineInfo.SetDistance( nDotLen ); + ((WinMtfLineStyle*)pStyle)->aLineInfo.SetDotLen( nDotLen ); + ((WinMtfLineStyle*)pStyle)->aLineInfo.SetDashLen( nDotLen * 4 ); + } + } + } + if ( (UINT32)nIndex >= vGDIObj.size() ) + ImplResizeObjectArry( nIndex + 16 ); + + if ( vGDIObj[ nIndex ] != NULL ) + delete vGDIObj[ nIndex ]; + + vGDIObj[ nIndex ] = new GDIObj( eType, pStyle ); + } + else + { + switch ( eType ) + { + case GDI_PEN : + delete (WinMtfLineStyle*)pStyle; + break; + case GDI_BRUSH : + delete (WinMtfFillStyle*)pStyle; + break; + case GDI_FONT : + delete (WinMtfFontStyle*)pStyle; + break; + + default: + DBG_ERROR( "unsupported style not deleted" ); + break; + } + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DeleteObject( sal_Int32 nIndex ) +{ + if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 ) + { + if ( (sal_uInt32)nIndex < vGDIObj.size() ) + { + delete vGDIObj[ nIndex ]; + vGDIObj[ nIndex ] = NULL; + } + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::IntersectClipRect( const Rectangle& rRect ) +{ + aClipPath.IntersectClipRect( ImplMap( rRect ) ); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::ExcludeClipRect( const Rectangle& rRect ) +{ + aClipPath.ExcludeClipRect( ImplMap( rRect ) ); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::MoveClipRegion( const Size& rSize ) +{ + aClipPath.MoveClipRegion( ImplMap( rSize ) ); +} + +void WinMtfOutput::SetClipPath( const PolyPolygon& rPolyPolygon, sal_Int32 nClippingMode, sal_Bool bIsMapped ) +{ + if ( bIsMapped ) + aClipPath.SetClipPath( rPolyPolygon, nClippingMode ); + else + { + PolyPolygon aPP( rPolyPolygon ); + aClipPath.SetClipPath( ImplMap( aPP ), nClippingMode ); + } +} + +//----------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------- + +WinMtfOutput::WinMtfOutput( GDIMetaFile& rGDIMetaFile ) : + mnLatestTextAlign ( 0 ), + mnTextAlign ( TA_LEFT | TA_TOP | TA_NOUPDATECP ), + maLatestBkColor ( 0x12345678 ), + maBkColor ( COL_WHITE ), + mnLatestTextLayoutMode( TEXT_LAYOUT_DEFAULT ), + mnTextLayoutMode ( TEXT_LAYOUT_DEFAULT ), + mnLatestBkMode ( 0 ), + mnBkMode ( OPAQUE ), + meLatestRasterOp ( ROP_INVERT ), + meRasterOp ( ROP_OVERPAINT ), + maActPos ( Point() ), + mbNopMode ( sal_False ), + mbFillStyleSelected ( sal_False ), + mnGfxMode ( GM_COMPATIBLE ), + mnMapMode ( MM_TEXT ), + mnDevOrgX ( 0 ), + mnDevOrgY ( 0 ), + mnDevWidth ( 1 ), + mnDevHeight ( 1 ), + mnWinOrgX ( 0 ), + mnWinOrgY ( 0 ), + mnWinExtX ( 1 ), + mnWinExtY ( 1 ), + mnPixX ( 100 ), + mnPixY ( 100 ), + mnMillX ( 1 ), + mnMillY ( 1 ), + mpGDIMetaFile ( &rGDIMetaFile ) +{ + mpGDIMetaFile->AddAction( new MetaPushAction( PUSH_CLIPREGION ) ); // The original clipregion has to be on top + // of the stack so it can always be restored + // this is necessary to be able to support + // SetClipRgn( NULL ) and similar ClipRgn actions (SJ) + + maFont.SetName( String( RTL_CONSTASCII_USTRINGPARAM( "Arial" )) ); // sj: #i57205#, we do have some scaling problems if using + maFont.SetCharSet( gsl_getSystemTextEncoding() ); // the default font then most times a x11 font is used, we + maFont.SetHeight( 423 ); // will prevent this defining a font + + maLatestLineStyle.aLineColor = Color( 0x12, 0x34, 0x56 ); + maLatestFillStyle.aFillColor = Color( 0x12, 0x34, 0x56 ); + + mnRop = R2_BLACK + 1; + SetRasterOp( R2_BLACK ); +}; + +//----------------------------------------------------------------------------------- + +WinMtfOutput::~WinMtfOutput() +{ + mpGDIMetaFile->AddAction( new MetaPopAction() ); + mpGDIMetaFile->SetPrefMapMode( MAP_100TH_MM ); + if ( mrclFrame.IsEmpty() ) + mpGDIMetaFile->SetPrefSize( Size( mnDevWidth, mnDevHeight ) ); + else + mpGDIMetaFile->SetPrefSize( mrclFrame.GetSize() ); + + for ( UINT32 i = 0; i < vGDIObj.size(); i++ ) + delete vGDIObj[ i ]; +}; + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::UpdateClipRegion() +{ + if ( aClipPath.bNeedsUpdate ) + { + aClipPath.bNeedsUpdate = sal_False; + + mpGDIMetaFile->AddAction( new MetaPopAction() ); // taking the orignal clipregion + mpGDIMetaFile->AddAction( new MetaPushAction( PUSH_CLIPREGION ) ); // + + switch ( aClipPath.GetType() ) + { + case RECTANGLE : + case COMPLEX : + { +// we will not generate a RegionClipRegion Action, because this action +// cannot be saved to the wmf format - saving to wmf always happens +// if the placeholder graphic for ole objects is generated. (SJ) + +// Region aClipRegion( aClipPath.GetClipPath() ); +// mpGDIMetaFile->AddAction( new MetaISectRegionClipRegionAction( aClipRegion ) ); + + Rectangle aClipRect( aClipPath.GetClipPath().GetBoundRect() ); + mpGDIMetaFile->AddAction( new MetaISectRectClipRegionAction( aClipRect ) ); + } + break; + case EMPTY: + break; // -Wall not handled. + } + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::ImplSetNonPersistentLineColorTransparenz() +{ + Color aColor( COL_TRANSPARENT); + WinMtfLineStyle aTransparentLine( aColor, TRUE ); + if ( ! ( maLatestLineStyle == aTransparentLine ) ) + { + maLatestLineStyle = aTransparentLine; + mpGDIMetaFile->AddAction( new MetaLineColorAction( aTransparentLine.aLineColor, !aTransparentLine.bTransparent ) ); + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::UpdateLineStyle() +{ + if (!( maLatestLineStyle == maLineStyle ) ) + { + maLatestLineStyle = maLineStyle; + mpGDIMetaFile->AddAction( new MetaLineColorAction( maLineStyle.aLineColor, !maLineStyle.bTransparent ) ); + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::UpdateFillStyle() +{ + if ( !mbFillStyleSelected ) // SJ: #i57205# taking care of bkcolor if no brush is selected + maFillStyle = WinMtfFillStyle( maBkColor, mnBkMode == TRANSPARENT ); + if (!( maLatestFillStyle == maFillStyle ) ) + { + maLatestFillStyle = maFillStyle; + mpGDIMetaFile->AddAction( new MetaFillColorAction( maFillStyle.aFillColor, !maFillStyle.bTransparent ) ); + } +} + +//----------------------------------------------------------------------------------- + +sal_uInt32 WinMtfOutput::SetRasterOp( UINT32 nRasterOp ) +{ + sal_uInt32 nRetROP = mnRop; + if ( nRasterOp != mnRop ) + { + mnRop = nRasterOp; + static WinMtfFillStyle aNopFillStyle; + static WinMtfLineStyle aNopLineStyle; + + if ( mbNopMode && ( nRasterOp != R2_NOP ) ) + { // beim uebergang von R2_NOP auf anderen Modus + // gesetzten Pen und Brush aktivieren + maFillStyle = aNopFillStyle; + maLineStyle = aNopLineStyle; + mbNopMode = sal_False; + } + switch( nRasterOp ) + { + case R2_NOT: + meRasterOp = ROP_INVERT; + break; + + case R2_XORPEN: + meRasterOp = ROP_XOR; + break; + + case R2_NOP: + { + meRasterOp = ROP_OVERPAINT; + if( mbNopMode == sal_False ) + { + aNopFillStyle = maFillStyle; + aNopLineStyle = maLineStyle; + maFillStyle = WinMtfFillStyle( Color( COL_TRANSPARENT ), TRUE ); + maLineStyle = WinMtfLineStyle( Color( COL_TRANSPARENT ), TRUE ); + mbNopMode = sal_True; + } + } + break; + + default: + meRasterOp = ROP_OVERPAINT; + break; + } + } + if ( nRetROP != nRasterOp ) + mpGDIMetaFile->AddAction( new MetaRasterOpAction( meRasterOp ) ); + return nRetROP; +}; + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::StrokeAndFillPath( sal_Bool bStroke, sal_Bool bFill ) +{ + if ( aPathObj.Count() ) + { + UpdateClipRegion(); + UpdateLineStyle(); + UpdateFillStyle(); + if ( bFill ) + { + if ( !bStroke ) + { + mpGDIMetaFile->AddAction( new MetaPushAction( PUSH_LINECOLOR ) ); + mpGDIMetaFile->AddAction( new MetaLineColorAction( Color(), FALSE ) ); + } + if ( aPathObj.Count() == 1 ) + mpGDIMetaFile->AddAction( new MetaPolygonAction( aPathObj.GetObject( 0 ) ) ); + else + mpGDIMetaFile->AddAction( new MetaPolyPolygonAction( aPathObj ) ); + + if ( !bStroke ) + mpGDIMetaFile->AddAction( new MetaPopAction() ); + } + else + { + sal_uInt16 i, nCount = aPathObj.Count(); + for ( i = 0; i < nCount; i++ ) + mpGDIMetaFile->AddAction( new MetaPolyLineAction( aPathObj[ i ], maLineStyle.aLineInfo ) ); + } + ClearPath(); + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DrawPixel( const Point& rSource, const Color& rColor ) +{ + mpGDIMetaFile->AddAction( new MetaPixelAction( ImplMap( rSource), rColor ) ); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::MoveTo( const Point& rPoint, sal_Bool bRecordPath ) +{ + Point aDest( ImplMap( rPoint ) ); + if ( bRecordPath ) + aPathObj.AddPoint( aDest ); + maActPos = aDest; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::LineTo( const Point& rPoint, sal_Bool bRecordPath ) +{ + UpdateClipRegion(); + + Point aDest( ImplMap( rPoint ) ); + if ( bRecordPath ) + aPathObj.AddPoint( aDest ); + else + { + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaLineAction( maActPos, aDest, maLineStyle.aLineInfo ) ); + } + maActPos = aDest; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DrawLine( const Point& rSource, const Point& rDest ) +{ + UpdateClipRegion(); + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaLineAction( ImplMap( rSource), ImplMap( rDest ), maLineStyle.aLineInfo ) ); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DrawRect( const Rectangle& rRect, BOOL bEdge ) +{ + UpdateClipRegion(); + UpdateFillStyle(); + + if ( aClipPath.GetType() == COMPLEX ) + { + Polygon aPoly( ImplMap( rRect ) ); + PolyPolygon aPolyPolyRect( aPoly ); + PolyPolygon aDest; + aClipPath.GetClipPath().GetIntersection( aPolyPolyRect, aDest ); + ImplDrawClippedPolyPolygon( aDest ); + } + else + { + if ( bEdge ) + { + if ( maLineStyle.aLineInfo.GetWidth() || ( maLineStyle.aLineInfo.GetStyle() == LINE_DASH ) ) + { + ImplSetNonPersistentLineColorTransparenz(); + mpGDIMetaFile->AddAction( new MetaRectAction( ImplMap( rRect ) ) ); + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaPolyLineAction( Polygon( ImplMap( rRect ) ),maLineStyle.aLineInfo ) ); + } + else + { + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaRectAction( ImplMap( rRect ) ) ); + } + } + else + { + ImplSetNonPersistentLineColorTransparenz(); + mpGDIMetaFile->AddAction( new MetaRectAction( ImplMap( rRect ) ) ); + } + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DrawRoundRect( const Rectangle& rRect, const Size& rSize ) +{ + UpdateClipRegion(); + UpdateLineStyle(); + UpdateFillStyle(); + mpGDIMetaFile->AddAction( new MetaRoundRectAction( ImplMap( rRect ), labs( ImplMap( rSize ).Width() ), labs( ImplMap( rSize ).Height() ) ) ); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DrawEllipse( const Rectangle& rRect ) +{ + UpdateClipRegion(); + UpdateFillStyle(); + + if ( maLineStyle.aLineInfo.GetWidth() || ( maLineStyle.aLineInfo.GetStyle() == LINE_DASH ) ) + { + Point aCenter( ImplMap( rRect.Center() ) ); + Size aRad( ImplMap( Size( rRect.GetWidth() / 2, rRect.GetHeight() / 2 ) ) ); + + ImplSetNonPersistentLineColorTransparenz(); + mpGDIMetaFile->AddAction( new MetaEllipseAction( ImplMap( rRect ) ) ); + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaPolyLineAction( Polygon( aCenter, aRad.Width(), aRad.Height() ), maLineStyle.aLineInfo ) ); + } + else + { + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaEllipseAction( ImplMap( rRect ) ) ); + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DrawArc( const Rectangle& rRect, const Point& rStart, const Point& rEnd, BOOL bTo ) +{ + UpdateClipRegion(); + UpdateLineStyle(); + UpdateFillStyle(); + + Rectangle aRect( ImplMap( rRect ) ); + Point aStart( ImplMap( rStart ) ); + Point aEnd( ImplMap( rEnd ) ); + + if ( maLineStyle.aLineInfo.GetWidth() || ( maLineStyle.aLineInfo.GetStyle() == LINE_DASH ) ) + { + if ( aStart == aEnd ) + { // SJ: #i53768# if start & end is identical, then we have to draw a full ellipse + Point aCenter( aRect.Center() ); + Size aRad( aRect.GetWidth() / 2, aRect.GetHeight() / 2 ); + + mpGDIMetaFile->AddAction( new MetaPolyLineAction( Polygon( aCenter, aRad.Width(), aRad.Height() ), maLineStyle.aLineInfo ) ); + } + else + mpGDIMetaFile->AddAction( new MetaPolyLineAction( Polygon( aRect, aStart, aEnd, POLY_ARC ), maLineStyle.aLineInfo ) ); + } + else + mpGDIMetaFile->AddAction( new MetaArcAction( aRect, aStart, aEnd ) ); + + if ( bTo ) + maActPos = aEnd; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DrawPie( const Rectangle& rRect, const Point& rStart, const Point& rEnd ) +{ + UpdateClipRegion(); + UpdateFillStyle(); + + Rectangle aRect( ImplMap( rRect ) ); + Point aStart( ImplMap( rStart ) ); + Point aEnd( ImplMap( rEnd ) ); + + if ( maLineStyle.aLineInfo.GetWidth() || ( maLineStyle.aLineInfo.GetStyle() == LINE_DASH ) ) + { + ImplSetNonPersistentLineColorTransparenz(); + mpGDIMetaFile->AddAction( new MetaPieAction( aRect, aStart, aEnd ) ); + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaPolyLineAction( Polygon( aRect, aStart, aEnd, POLY_PIE ), maLineStyle.aLineInfo ) ); + } + else + { + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaPieAction( aRect, aStart, aEnd ) ); + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DrawChord( const Rectangle& rRect, const Point& rStart, const Point& rEnd ) +{ + UpdateClipRegion(); + UpdateFillStyle(); + + Rectangle aRect( ImplMap( rRect ) ); + Point aStart( ImplMap( rStart ) ); + Point aEnd( ImplMap( rEnd ) ); + + if ( maLineStyle.aLineInfo.GetWidth() || ( maLineStyle.aLineInfo.GetStyle() == LINE_DASH ) ) + { + ImplSetNonPersistentLineColorTransparenz(); + mpGDIMetaFile->AddAction( new MetaChordAction( aRect, aStart, aEnd ) ); + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaPolyLineAction( Polygon( aRect, aStart, aEnd, POLY_CHORD ), maLineStyle.aLineInfo ) ); + } + else + { + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaChordAction( aRect, aStart, aEnd ) ); + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DrawPolygon( Polygon& rPolygon, sal_Bool bRecordPath ) +{ + UpdateClipRegion(); + ImplMap( rPolygon ); + if ( bRecordPath ) + aPathObj.AddPolygon( rPolygon ); + else + { + UpdateFillStyle(); + + if ( aClipPath.GetType() == COMPLEX ) + { + PolyPolygon aPolyPoly( rPolygon ); + PolyPolygon aDest; + aClipPath.GetClipPath().GetIntersection( aPolyPoly, aDest ); + ImplDrawClippedPolyPolygon( aDest ); + } + else + { + if ( maLineStyle.aLineInfo.GetWidth() || ( maLineStyle.aLineInfo.GetStyle() == LINE_DASH ) ) + { + USHORT nCount = rPolygon.GetSize(); + if ( nCount ) + { + if ( rPolygon[ nCount - 1 ] != rPolygon[ 0 ] ) + { + Point aPoint( rPolygon[ 0 ] ); + rPolygon.Insert( nCount, aPoint ); + } + } + ImplSetNonPersistentLineColorTransparenz(); + mpGDIMetaFile->AddAction( new MetaPolygonAction( rPolygon ) ); + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaPolyLineAction( rPolygon, maLineStyle.aLineInfo ) ); + } + else + { + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaPolygonAction( rPolygon ) ); + } + } + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DrawPolyPolygon( PolyPolygon& rPolyPolygon, sal_Bool bRecordPath ) +{ + UpdateClipRegion(); + + ImplMap( rPolyPolygon ); + + if ( bRecordPath ) + aPathObj.AddPolyPolygon( rPolyPolygon ); + else + { + UpdateFillStyle(); + + if ( aClipPath.GetType() == COMPLEX ) + { + PolyPolygon aDest; + aClipPath.GetClipPath().GetIntersection( rPolyPolygon, aDest ); + ImplDrawClippedPolyPolygon( aDest ); + } + else + { + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaPolyPolygonAction( rPolyPolygon ) ); + } + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DrawPolyLine( Polygon& rPolygon, sal_Bool bTo, sal_Bool bRecordPath ) +{ + UpdateClipRegion(); + + ImplMap( rPolygon ); + if ( bTo ) + { + rPolygon[ 0 ] = maActPos; + maActPos = rPolygon[ rPolygon.GetSize() - 1 ]; + } + if ( bRecordPath ) + aPathObj.AddPolyLine( rPolygon ); + else + { + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaPolyLineAction( rPolygon, maLineStyle.aLineInfo ) ); + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DrawPolyBezier( Polygon& rPolygon, sal_Bool bTo, sal_Bool bRecordPath ) +{ + UpdateClipRegion(); + + sal_uInt16 nPoints = rPolygon.GetSize(); + if ( ( nPoints >= 4 ) && ( ( ( nPoints - 4 ) % 3 ) == 0 ) ) + { + ImplMap( rPolygon ); + if ( bTo ) + { + rPolygon[ 0 ] = maActPos; + maActPos = rPolygon[ nPoints - 1 ]; + } + sal_uInt16 i; + for ( i = 0; ( i + 2 ) < nPoints; ) + { + rPolygon.SetFlags( i++, POLY_NORMAL ); + rPolygon.SetFlags( i++, POLY_CONTROL ); + rPolygon.SetFlags( i++, POLY_CONTROL ); + } + if ( bRecordPath ) + aPathObj.AddPolyLine( rPolygon ); + else + { + UpdateLineStyle(); + mpGDIMetaFile->AddAction( new MetaPolyLineAction( rPolygon, maLineStyle.aLineInfo ) ); + } + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::DrawText( Point& rPosition, String& rText, sal_Int32* pDXArry, sal_Bool bRecordPath, sal_Int32 nGfxMode ) +{ + UpdateClipRegion(); + + VirtualDevice* pVDev = NULL; + + rPosition = ImplMap( rPosition ); + + sal_Int32 nOldGfxMode = GetGfxMode(); + SetGfxMode( GM_COMPATIBLE ); + if ( pDXArry ) + { + sal_Int32 i, nSum, nLen = rText.Len(); + + for( i = 0, nSum = 0; i < nLen; i++ ) + { + sal_Int32 nTemp = ImplMap( Size( pDXArry[ i ], 0 ) ).Width(); + nSum += nTemp; + pDXArry[ i ] = nSum; + } + } + if ( mnLatestTextLayoutMode != mnTextLayoutMode ) + { + mnLatestTextLayoutMode = mnTextLayoutMode; + mpGDIMetaFile->AddAction( new MetaLayoutModeAction( mnTextLayoutMode ) ); + } + SetGfxMode( nGfxMode ); + sal_Bool bChangeFont = sal_False; + if ( mnLatestTextAlign != mnTextAlign ) + { + bChangeFont = sal_True; + mnLatestTextAlign = mnTextAlign; + TextAlign eTextAlign; + if ( ( mnTextAlign & TA_BASELINE) == TA_BASELINE ) + eTextAlign = ALIGN_BASELINE; + else if( ( mnTextAlign & TA_BOTTOM) == TA_BOTTOM ) + eTextAlign = ALIGN_BOTTOM; + else + eTextAlign = ALIGN_TOP; + mpGDIMetaFile->AddAction( new MetaTextAlignAction( eTextAlign ) ); + } + if ( maLatestTextColor != maTextColor ) + { + bChangeFont = sal_True; + maLatestTextColor = maTextColor; + mpGDIMetaFile->AddAction( new MetaTextColorAction( maTextColor ) ); + } + sal_Bool bChangeFillColor = sal_False; + if ( maLatestBkColor != maBkColor ) + { + bChangeFillColor = sal_True; + maLatestBkColor = maBkColor; + } + if ( mnLatestBkMode != mnBkMode ) + { + bChangeFillColor = sal_True; + mnLatestBkMode = mnBkMode; + } + if ( bChangeFillColor ) + { + bChangeFont = sal_True; + mpGDIMetaFile->AddAction( new MetaTextFillColorAction( maFont.GetFillColor(), !maFont.IsTransparent() ) ); + } + Font aTmp( maFont ); + aTmp.SetColor( maTextColor ); + aTmp.SetFillColor( maBkColor ); + + if( mnBkMode == TRANSPARENT ) + aTmp.SetTransparent( sal_True ); + else + aTmp.SetTransparent( sal_False ); + + if ( ( mnTextAlign & TA_BASELINE) == TA_BASELINE ) + aTmp.SetAlign( ALIGN_BASELINE ); + else if( ( mnTextAlign & TA_BOTTOM) == TA_BOTTOM ) + aTmp.SetAlign( ALIGN_BOTTOM ); + else + aTmp.SetAlign( ALIGN_TOP ); + + if ( nGfxMode == GM_ADVANCED ) + { + // check whether there is a font rotation applied via transformation + Point aP1( ImplMap( Point() ) ); + Point aP2( ImplMap( Point( 0, 100 ) ) ); + aP2.X() -= aP1.X(); + aP2.Y() -= aP1.Y(); + double fX = aP2.X(); + double fY = aP2.Y(); + if ( fX ) + { + double fOrientation = acos( fX / sqrt( fX * fX + fY * fY ) ) * 57.29577951308; + if ( fY > 0 ) + fOrientation = 360 - fOrientation; + fOrientation += 90; + fOrientation *= 10; + fOrientation += aTmp.GetOrientation(); + aTmp.SetOrientation( sal_Int16( fOrientation ) ); + } + } + + if( mnTextAlign & ( TA_UPDATECP | TA_RIGHT_CENTER ) ) + { + if ( !pVDev ) + pVDev = new VirtualDevice; + sal_Int32 nTextWidth; + pVDev->SetMapMode( MapMode( MAP_100TH_MM ) ); + pVDev->SetFont( maFont ); + if( pDXArry ) + { + UINT32 nLen = rText.Len(); + nTextWidth = pVDev->GetTextWidth( rText.GetChar( (sal_uInt16)( nLen - 1 ) ) ); + if( nLen > 1 ) + nTextWidth += pDXArry[ nLen - 2 ]; + } + else + nTextWidth = pVDev->GetTextWidth( rText ); + + if( mnTextAlign & TA_UPDATECP ) + rPosition = maActPos; + + if ( mnTextAlign & TA_RIGHT_CENTER ) + { + double fLenght = ( ( mnTextAlign & TA_RIGHT_CENTER ) == TA_RIGHT ) ? nTextWidth : nTextWidth >> 1; + rPosition.X() -= (sal_Int32)( fLenght * cos( maFont.GetOrientation() * F_PI1800 ) ); + rPosition.Y() -= (sal_Int32)(-( fLenght * sin( maFont.GetOrientation() * F_PI1800 ) ) ); + } + + if( mnTextAlign & TA_UPDATECP ) + maActPos.X() = rPosition.X() + nTextWidth; + } + if ( bChangeFont || ( maLatestFont != aTmp ) ) + { + maLatestFont = aTmp; + mpGDIMetaFile->AddAction( new MetaFontAction( aTmp ) ); + mpGDIMetaFile->AddAction( new MetaTextAlignAction( aTmp.GetAlign() ) ); + mpGDIMetaFile->AddAction( new MetaTextColorAction( aTmp.GetColor() ) ); + mpGDIMetaFile->AddAction( new MetaTextFillColorAction( aTmp.GetFillColor(), !aTmp.IsTransparent() ) ); + } + if ( bRecordPath ) + { + // ToDo + } + else + { + /* because text without dx array is badly scaled, we + will create such an array if necessary */ + sal_Int32* pDX = pDXArry; + if ( !pDXArry ) + { + pDX = new sal_Int32[ rText.Len() ]; + if ( !pVDev ) + pVDev = new VirtualDevice; + pVDev->SetMapMode( MAP_100TH_MM ); + pVDev->SetFont( maLatestFont ); + pVDev->GetTextArray( rText, pDX, 0, STRING_LEN ); + } + mpGDIMetaFile->AddAction( new MetaTextArrayAction( rPosition, rText, pDX, 0, STRING_LEN ) ); + if ( !pDXArry ) // this means we have created our own array + delete[] pDX; // which must be deleted + } + SetGfxMode( nOldGfxMode ); + delete pVDev; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::ImplDrawBitmap( const Point& rPos, const Size& rSize, const BitmapEx rBitmap ) +{ + BitmapEx aBmpEx( rBitmap ); + if ( aClipPath.GetType() == COMPLEX ) + { + VirtualDevice aVDev; + MapMode aMapMode( MAP_100TH_MM ); + aMapMode.SetOrigin( Point( -rPos.X(), -rPos.Y() ) ); + const Size aOutputSizePixel( aVDev.LogicToPixel( rSize, aMapMode ) ); + const Size aSizePixel( rBitmap.GetSizePixel() ); + if ( aOutputSizePixel.Width() && aOutputSizePixel.Height() ) + { + aMapMode.SetScaleX( Fraction( aSizePixel.Width(), aOutputSizePixel.Width() ) ); + aMapMode.SetScaleY( Fraction( aSizePixel.Height(), aOutputSizePixel.Height() ) ); + } + aVDev.SetMapMode( aMapMode ); + aVDev.SetOutputSizePixel( aSizePixel ); + aVDev.SetFillColor( Color( COL_BLACK ) ); + const PolyPolygon aClip( aClipPath.GetClipPath() ); + aVDev.DrawPolyPolygon( aClip ); + const Point aEmptyPoint; + + // #i50672# Extract whole VDev content (to match size of rBitmap) + aVDev.EnableMapMode( FALSE ); + Bitmap aMask( aVDev.GetBitmap( aEmptyPoint, aSizePixel ).CreateMask( Color( COL_WHITE ) ) ); + + if ( aBmpEx.IsTransparent() ) + { + if ( rBitmap.GetTransparentColor() == Color( COL_WHITE ) ) + aMask.CombineSimple( rBitmap.GetMask(), BMP_COMBINE_OR ); + else + aMask.CombineSimple( rBitmap.GetMask(), BMP_COMBINE_AND ); + aBmpEx = BitmapEx( rBitmap.GetBitmap(), aMask ); + } + else + aBmpEx = BitmapEx( rBitmap.GetBitmap(), aMask ); + } + if ( aBmpEx.IsTransparent() ) + mpGDIMetaFile->AddAction( new MetaBmpExScaleAction( rPos, rSize, aBmpEx ) ); + else + mpGDIMetaFile->AddAction( new MetaBmpScaleAction( rPos, rSize, aBmpEx.GetBitmap() ) ); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::ResolveBitmapActions( List& rSaveList ) +{ + UpdateClipRegion(); + + sal_uInt32 nObjects = rSaveList.Count(); + sal_uInt32 nObjectsLeft = nObjects; + + while ( nObjectsLeft ) + { + sal_uInt32 i, nObjectsOfSameSize = 0; + sal_uInt32 nObjectStartIndex = nObjects - nObjectsLeft; + + BSaveStruct* pSave = (BSaveStruct*)rSaveList.GetObject( nObjectStartIndex ); + Rectangle aRect( pSave->aOutRect ); + + for ( i = nObjectStartIndex; i < nObjects; ) + { + nObjectsOfSameSize++; + if ( ++i < nObjects ) + { + pSave = (BSaveStruct*)rSaveList.GetObject( i ); + if ( pSave->aOutRect != aRect ) + break; + } + } + Point aPos( ImplMap( aRect.TopLeft() ) ); + Size aSize( ImplMap( aRect.GetSize() ) ); + + for ( i = nObjectStartIndex; i < ( nObjectStartIndex + nObjectsOfSameSize ); i++ ) + { + pSave = (BSaveStruct*)rSaveList.GetObject( i ); + + sal_uInt32 nWinRop = pSave->nWinRop; + sal_uInt8 nRasterOperation = (sal_uInt8)( nWinRop >> 16 ); + + sal_uInt32 nUsed = 0; + if ( ( nRasterOperation & 0xf ) != ( nRasterOperation >> 4 ) ) + nUsed |= 1; // pattern is used + if ( ( nRasterOperation & 0x33 ) != ( ( nRasterOperation & 0xcc ) >> 2 ) ) + nUsed |= 2; // source is used + if ( ( nRasterOperation & 0xaa ) != ( ( nRasterOperation & 0x55 ) << 1 ) ) + nUsed |= 4; // destination is used + + if ( (nUsed & 1) && (( nUsed & 2 ) == 0) ) + { // patterns aren't well supported yet + sal_uInt32 nOldRop = SetRasterOp( ROP_OVERPAINT ); // in this case nRasterOperation is either 0 or 0xff + UpdateFillStyle(); + DrawRect( aRect, FALSE ); + SetRasterOp( nOldRop ); + } + else + { + sal_Bool bDrawn = sal_False; + + if ( i == nObjectStartIndex ) // optimizing, sometimes it is possible to create just one transparent bitmap + { + if ( nObjectsOfSameSize == 2 ) + { + BSaveStruct* pSave2 = (BSaveStruct*)rSaveList.GetObject( i + 1 ); + if ( ( pSave->aBmp.GetPrefSize() == pSave2->aBmp.GetPrefSize() ) && + ( pSave->aBmp.GetPrefMapMode() == pSave2->aBmp.GetPrefMapMode() ) ) + { + // TODO: Strictly speaking, we should + // check whether mask is monochrome, and + // whether image is black (upper branch) + // or white (lower branch). Otherwise, the + // effect is not the same as a masked + // bitmap. + if ( ( nWinRop == SRCPAINT ) && ( pSave2->nWinRop == SRCAND ) ) + { + Bitmap aMask( pSave->aBmp ); aMask.Invert(); + BitmapEx aBmpEx( pSave2->aBmp, aMask ); + ImplDrawBitmap( aPos, aSize, aBmpEx ); + bDrawn = sal_True; + i++; + } + // #i20085# This is just the other way + // around as above. Only difference: mask + // is inverted + else if ( ( nWinRop == SRCAND ) && ( pSave2->nWinRop == SRCPAINT ) ) + { + Bitmap aMask( pSave->aBmp ); + BitmapEx aBmpEx( pSave2->aBmp, aMask ); + ImplDrawBitmap( aPos, aSize, aBmpEx ); + bDrawn = sal_True; + i++; + } + } + } + } + + if ( !bDrawn ) + { + Push(); + sal_uInt32 nOldRop = SetRasterOp( R2_COPYPEN ); + Bitmap aBitmap( pSave->aBmp ); + sal_uInt32 nOperation = ( nRasterOperation & 0xf ); + switch( nOperation ) + { + case 0x1 : + case 0xe : + { + SetRasterOp( R2_XORPEN ); + ImplDrawBitmap( aPos, aSize, aBitmap ); + SetRasterOp( R2_COPYPEN ); + Bitmap aMask( aBitmap ); + aMask.Invert(); + BitmapEx aBmpEx( aBitmap, aMask ); + ImplDrawBitmap( aPos, aSize, aBmpEx ); + if ( nOperation == 0x1 ) + { + SetRasterOp( R2_NOT ); + DrawRect( aRect, FALSE ); + } + } + break; + case 0x7 : + case 0x8 : + { + Bitmap aMask( aBitmap ); + if ( ( nUsed & 1 ) && ( nRasterOperation & 0xb0 ) == 0xb0 ) // pattern used + { + aBitmap.Convert( BMP_CONVERSION_24BIT ); + aBitmap.Erase( maFillStyle.aFillColor ); + } + BitmapEx aBmpEx( aBitmap, aMask ); + ImplDrawBitmap( aPos, aSize, aBmpEx ); + if ( nOperation == 0x7 ) + { + SetRasterOp( R2_NOT ); + DrawRect( aRect, FALSE ); + } + } + break; + + case 0x4 : + case 0xb : + { + SetRasterOp( R2_NOT ); + DrawRect( aRect, FALSE ); + SetRasterOp( R2_COPYPEN ); + Bitmap aMask( aBitmap ); + aBitmap.Invert(); + BitmapEx aBmpEx( aBitmap, aMask ); + ImplDrawBitmap( aPos, aSize, aBmpEx ); + SetRasterOp( R2_XORPEN ); + ImplDrawBitmap( aPos, aSize, aBitmap ); + if ( nOperation == 0xb ) + { + SetRasterOp( R2_NOT ); + DrawRect( aRect, FALSE ); + } + } + break; + + case 0x2 : + case 0xd : + { + Bitmap aMask( aBitmap ); + aMask.Invert(); + BitmapEx aBmpEx( aBitmap, aMask ); + ImplDrawBitmap( aPos, aSize, aBmpEx ); + SetRasterOp( R2_XORPEN ); + ImplDrawBitmap( aPos, aSize, aBitmap ); + if ( nOperation == 0xd ) + { + SetRasterOp( R2_NOT ); + DrawRect( aRect, FALSE ); + } + } + break; + case 0x6 : + case 0x9 : + { + SetRasterOp( R2_XORPEN ); + ImplDrawBitmap( aPos, aSize, aBitmap ); + if ( nOperation == 0x9 ) + { + SetRasterOp( R2_NOT ); + DrawRect( aRect, FALSE ); + } + } + break; + + case 0x0 : // WHITENESS + case 0xf : // BLACKNESS + { // in this case nRasterOperation is either 0 or 0xff + maFillStyle = WinMtfFillStyle( Color( nRasterOperation, nRasterOperation, nRasterOperation ) ); + UpdateFillStyle(); + DrawRect( aRect, FALSE ); + } + break; + + case 0x3 : // only source is used + case 0xc : + { + if ( nRasterOperation == 0x33 ) + aBitmap.Invert(); + ImplDrawBitmap( aPos, aSize, aBitmap ); + } + break; + + case 0x5 : // only destination is used + { + SetRasterOp( R2_NOT ); + DrawRect( aRect, FALSE ); + } + case 0xa : // no operation + break; + } + SetRasterOp( nOldRop ); + Pop(); + } + } + } + nObjectsLeft -= nObjectsOfSameSize; + } + + void* pPtr; + for ( pPtr = rSaveList.First(); pPtr; pPtr = rSaveList.Next() ) + delete (BSaveStruct*)pPtr; + rSaveList.Clear(); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetDevOrg( const Point& rPoint ) +{ + mnDevOrgX = rPoint.X(); + mnDevOrgY = rPoint.Y(); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetDevOrgOffset( INT32 nXAdd, INT32 nYAdd ) +{ + mnDevOrgX += nXAdd; + mnDevOrgY += nYAdd; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetDevExt( const Size& rSize ) +{ + if ( rSize.Width() && rSize.Height() ) + { + switch( mnMapMode ) + { + case MM_ISOTROPIC : + case MM_ANISOTROPIC : + { + mnDevWidth = rSize.Width(); + mnDevHeight = rSize.Height(); + } + } + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::ScaleDevExt( double fX, double fY ) +{ + mnDevWidth = FRound( mnDevWidth * fX ); + mnDevHeight = FRound( mnDevHeight * fY ); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetWinOrg( const Point& rPoint ) +{ + mnWinOrgX = rPoint.X(); + mnWinOrgY = rPoint.Y(); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetWinOrgOffset( INT32 nXAdd, INT32 nYAdd ) +{ + mnWinOrgX += nXAdd; + mnWinOrgY += nYAdd; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetWinExt( const Size& rSize ) +{ + + if( rSize.Width() && rSize.Height() ) + { + switch( mnMapMode ) + { + case MM_ISOTROPIC : + case MM_ANISOTROPIC : + { + mnWinExtX = rSize.Width(); + mnWinExtY = rSize.Height(); + } + } + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::ScaleWinExt( double fX, double fY ) +{ + mnWinExtX = FRound( mnWinExtX * fX ); + mnWinExtY = FRound( mnWinExtY * fY ); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetrclBounds( const Rectangle& rRect ) +{ + mrclBounds = rRect; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetrclFrame( const Rectangle& rRect ) +{ + mrclFrame = rRect; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetRefPix( const Size& rSize ) +{ + mnPixX = rSize.Width(); + mnPixY = rSize.Height(); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetRefMill( const Size& rSize ) +{ + mnMillX = rSize.Width(); + mnMillY = rSize.Height(); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetMapMode( sal_uInt32 nMapMode ) +{ + mnMapMode = nMapMode; + if ( nMapMode == MM_TEXT ) + { + mnWinExtX = mnDevWidth; + mnWinExtY = mnDevHeight; + } + else if ( mnMapMode == MM_HIMETRIC ) + { + mnWinExtX = mnMillX * 100; + mnWinExtY = mnMillY * 100; + } +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::SetWorldTransform( const XForm& rXForm ) +{ + maXForm.eM11 = rXForm.eM11; + maXForm.eM12 = rXForm.eM12; + maXForm.eM21 = rXForm.eM21; + maXForm.eM22 = rXForm.eM22; + maXForm.eDx = rXForm.eDx; + maXForm.eDy = rXForm.eDy; +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::ModifyWorldTransform( const XForm& rXForm, UINT32 nMode ) +{ + switch( nMode ) + { + case MWT_IDENTITY : + { + maXForm.eM11 = maXForm.eM12 = maXForm.eM21 = maXForm.eM22 = 1.0f; + maXForm.eDx = maXForm.eDy = 0.0f; + } + break; + + case MWT_RIGHTMULTIPLY : + case MWT_LEFTMULTIPLY : + { + const XForm* pLeft; + const XForm* pRight; + + if ( nMode == MWT_LEFTMULTIPLY ) + { + pLeft = &rXForm; + pRight = &maXForm; + } + else + { + pLeft = &maXForm; + pRight = &rXForm; + } + + float aF[3][3]; + float bF[3][3]; + float cF[3][3]; + + aF[0][0] = pLeft->eM11; + aF[0][1] = pLeft->eM12; + aF[0][2] = 0; + aF[1][0] = pLeft->eM21; + aF[1][1] = pLeft->eM22; + aF[1][2] = 0; + aF[2][0] = pLeft->eDx; + aF[2][1] = pLeft->eDy; + aF[2][2] = 1; + + bF[0][0] = pRight->eM11; + bF[0][1] = pRight->eM12; + bF[0][2] = 0; + bF[1][0] = pRight->eM21; + bF[1][1] = pRight->eM22; + bF[1][2] = 0; + bF[2][0] = pRight->eDx; + bF[2][1] = pRight->eDy; + bF[2][2] = 1; + + int i, j, k; + for ( i = 0; i < 3; i++ ) + { + for ( j = 0; j < 3; j++ ) + { + cF[i][j] = 0; + for ( k = 0; k < 3; k++ ) + cF[i][j] += aF[i][k] * bF[k][j]; + } + } + maXForm.eM11 = cF[0][0]; + maXForm.eM12 = cF[0][1]; + maXForm.eM21 = cF[1][0]; + maXForm.eM22 = cF[1][1]; + maXForm.eDx = cF[2][0]; + maXForm.eDy = cF[2][1]; + } + break; + } + } + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::Push() // !! to be able to access the original ClipRegion it +{ // is not allowed to use the MetaPushAction() + UpdateClipRegion(); // (the original clip region is on top of the stack) (SJ) + SaveStructPtr pSave( new SaveStruct ); + + pSave->aLineStyle = maLineStyle; + pSave->aFillStyle = maFillStyle; + + pSave->aFont = maFont; + pSave->aTextColor = maTextColor; + pSave->nTextAlign = mnTextAlign; + pSave->nTextLayoutMode = mnTextLayoutMode; + pSave->nMapMode = mnMapMode; + pSave->nGfxMode = mnGfxMode; + pSave->nBkMode = mnBkMode; + pSave->aBkColor = maBkColor; + pSave->bFillStyleSelected = mbFillStyleSelected; + + pSave->aActPos = maActPos; + pSave->aXForm = maXForm; + pSave->eRasterOp = meRasterOp; + + pSave->nWinOrgX = mnWinOrgX; + pSave->nWinOrgY = mnWinOrgY; + pSave->nWinExtX = mnWinExtX; + pSave->nWinExtY = mnWinExtY; + pSave->nDevOrgX = mnDevOrgX; + pSave->nDevOrgY = mnDevOrgY; + pSave->nDevWidth = mnDevWidth; + pSave->nDevHeight = mnDevHeight; + + pSave->aPathObj = aPathObj; + pSave->aClipPath = aClipPath; + + vSaveStack.push_back( pSave ); +} + +//----------------------------------------------------------------------------------- + +void WinMtfOutput::Pop() +{ + // Die aktuellen Daten vom Stack holen + if( vSaveStack.size() ) + { + // Die aktuelle Daten auf dem Stack sichern + SaveStructPtr pSave( vSaveStack.back() ); + + maLineStyle = pSave->aLineStyle; + maFillStyle = pSave->aFillStyle; + + maFont = pSave->aFont; + maTextColor = pSave->aTextColor; + mnTextAlign = pSave->nTextAlign; + mnTextLayoutMode = pSave->nTextLayoutMode; + mnBkMode = pSave->nBkMode; + mnGfxMode = pSave->nGfxMode; + mnMapMode = pSave->nMapMode; + maBkColor = pSave->aBkColor; + mbFillStyleSelected = pSave->bFillStyleSelected; + + maActPos = pSave->aActPos; + maXForm = pSave->aXForm; + meRasterOp = pSave->eRasterOp; + + mnWinOrgX = pSave->nWinOrgX; + mnWinOrgY = pSave->nWinOrgY; + mnWinExtX = pSave->nWinExtX; + mnWinExtY = pSave->nWinExtY; + mnDevOrgX = pSave->nDevOrgX; + mnDevOrgY = pSave->nDevOrgY; + mnDevWidth = pSave->nDevWidth; + mnDevHeight = pSave->nDevHeight; + + aPathObj = pSave->aPathObj; + if ( ! ( aClipPath == pSave->aClipPath ) ) + { + aClipPath = pSave->aClipPath; + aClipPath.bNeedsUpdate = sal_True; + } + if ( meLatestRasterOp != meRasterOp ) + mpGDIMetaFile->AddAction( new MetaRasterOpAction( meRasterOp ) ); + vSaveStack.pop_back(); + } +} + +void WinMtfOutput::AddFromGDIMetaFile( GDIMetaFile& rGDIMetaFile ) +{ + rGDIMetaFile.Play( *mpGDIMetaFile, 0xFFFFFFFF ); +} + diff --git a/svtools/source/filter/wmf/winmtf.hxx b/svtools/source/filter/wmf/winmtf.hxx new file mode 100644 index 000000000000..fb4fd2fe0c57 --- /dev/null +++ b/svtools/source/filter/wmf/winmtf.hxx @@ -0,0 +1,777 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _WINMTF_HXX +#define _WINMTF_HXX + +#ifdef DBG_UTIL +#define WIN_MTF_ASSERT +#endif + +#include +#ifndef BOOST_SHARED_PTR_HPP_INCLUDED +#include +#endif +#ifndef _TOOL_DEBUG_HXX +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define ERROR 0 +#define NULLREGION 1 +#define SIMPLEREGION 2 +#define COMPLEXREGION 3 + +#define RGN_AND 1 +#define RGN_OR 2 +#define RGN_XOR 3 +#define RGN_DIFF 4 +#define RGN_COPY 5 + +#define TRANSPARENT 1 +#define OPAQUE 2 +#define BKMODE_LAST 2 + +/* xform stuff */ +#define MWT_IDENTITY 1 +#define MWT_LEFTMULTIPLY 2 +#define MWT_RIGHTMULTIPLY 3 + +#define ENHMETA_STOCK_OBJECT 0x80000000 + +/* Stock Logical Objects */ +#define WHITE_BRUSH 0 +#define LTGRAY_BRUSH 1 +#define GRAY_BRUSH 2 +#define DKGRAY_BRUSH 3 +#define BLACK_BRUSH 4 +#define NULL_BRUSH 5 +#define HOLLOW_BRUSH NULL_BRUSH +#define WHITE_PEN 6 +#define BLACK_PEN 7 +#define NULL_PEN 8 +#define OEM_FIXED_FONT 10 +#define ANSI_FIXED_FONT 11 +#define ANSI_VAR_FONT 12 +#define SYSTEM_FONT 13 +#define DEVICE_DEFAULT_FONT 14 +#define DEFAULT_PALETTE 15 +#define SYSTEM_FIXED_FONT 16 + + +#define R2_BLACK 1 +#define R2_NOTMERGEPEN 2 +#define R2_MASKNOTPEN 3 +#define R2_NOTCOPYPEN 4 +#define R2_MASKPENNOT 5 +#define R2_NOT 6 +#define R2_XORPEN 7 +#define R2_NOTMASKPEN 8 +#define R2_MASKPEN 9 +#define R2_NOTXORPEN 10 +#define R2_NOP 11 +#define R2_MERGENOTPEN 12 +#define R2_COPYPEN 13 +#define R2_MERGEPENNOT 14 +#define R2_MERGEPEN 15 +#define R2_WHITE 16 + +/* Mapping Modes */ +#define MM_TEXT 1 +#define MM_LOMETRIC 2 +#define MM_HIMETRIC 3 +#define MM_LOENGLISH 4 +#define MM_HIENGLISH 5 +#define MM_TWIPS 6 +#define MM_ISOTROPIC 7 +#define MM_ANISOTROPIC 8 + + +/* Graphics Modes */ +#define GM_COMPATIBLE 1 +#define GM_ADVANCED 2 +#define GM_LAST 2 + +/* StretchBlt() Modes */ +#define BLACKONWHITE 1 +#define WHITEONBLACK 2 +#define COLORONCOLOR 3 +#define HALFTONE 4 +#define MAXSTRETCHBLTMODE 4 +#define STRETCH_ANDSCANS BLACKONWHITE +#define STRETCH_ORSCANS WHITEONBLACK +#define STRETCH_DELETESCANS COLORONCOLOR +#define STRETCH_HALFTONE HALFTONE + +#define LF_FACESIZE 32 + +struct LOGFONTW +{ + INT32 lfHeight; + INT32 lfWidth; + INT32 lfEscapement; + INT32 lfOrientation; + INT32 lfWeight; + BYTE lfItalic; + BYTE lfUnderline; + BYTE lfStrikeOut; + BYTE lfCharSet; + BYTE lfOutPrecision; + BYTE lfClipPrecision; + BYTE lfQuality; + BYTE lfPitchAndFamily; + String alfFaceName; +}; + +#define TA_NOUPDATECP 0x0000 +#define TA_UPDATECP 0x0001 +#define TA_LEFT 0x0000 +#define TA_RIGHT 0x0002 +#define TA_CENTER 0x0006 +#define TA_RIGHT_CENTER (TA_RIGHT | TA_CENTER) +#define TA_TOP 0x0000 +#define TA_BOTTOM 0x0008 +#define TA_BASELINE 0x0018 + +#define SRCCOPY 0x00CC0020L +#define SRCPAINT 0x00EE0086L +#define SRCAND 0x008800C6L +#define SRCINVERT 0x00660046L +#define SRCERASE 0x00440328L +#define NOTSRCCOPY 0x00330008L +#define NOTSRCERASE 0x001100A6L +#define MERGECOPY 0x00C000CAL +#define MERGEPAINT 0x00BB0226L +#define PATCOPY 0x00F00021L +#define PATPAINT 0x00FB0A09L +#define PATINVERT 0x005A0049L +#define DSTINVERT 0x00550009L +#define BLACKNESS 0x00000042L +#define WHITENESS 0x00FF0062L + +#define PS_SOLID 0 +#define PS_DASH 1 +#define PS_DOT 2 +#define PS_DASHDOT 3 +#define PS_DASHDOTDOT 4 +#define PS_NULL 5 +#define PS_INSIDEFRAME 6 +#define PS_USERSTYLE 7 +#define PS_ALTERNATE 8 +#define PS_STYLE_MASK 15 + +#define PS_ENDCAP_ROUND 0x000 +#define PS_ENDCAP_SQUARE 0x100 +#define PS_ENDCAP_FLAT 0x200 +#define PS_ENDCAP_MASK 0xF00 + +#define PS_JOIN_ROUND 0x0000 +#define PS_JOIN_BEVEL 0x1000 +#define PS_JOIN_MITER 0x2000 +#define PS_JOIN_MASK 0xF000 + +#define PS_COSMETIC 0x00000 +#define PS_GEOMETRIC 0x10000 +#define PS_TYPE_MASK 0xF0000 + +#define ANSI_CHARSET 0 +#define DEFAULT_CHARSET 1 +#define SYMBOL_CHARSET 2 +#define SHIFTJIS_CHARSET 128 +#define HANGEUL_CHARSET 129 +#define GB2312_CHARSET 134 +#define CHINESEBIG5_CHARSET 136 +#define OEM_CHARSET 255 +/*WINVER >= 0x0400*/ +#define JOHAB_CHARSET 130 +#define HEBREW_CHARSET 177 +#define ARABIC_CHARSET 178 +#define GREEK_CHARSET 161 +#define TURKISH_CHARSET 162 +#define VIETNAMESE_CHARSET 163 +#define THAI_CHARSET 222 +#define EASTEUROPE_CHARSET 238 +#define RUSSIAN_CHARSET 204 +#define MAC_CHARSET 77 +#define BALTIC_CHARSET 186 + +#define ETO_OPAQUE 0x0002 +#define ETO_CLIPPED 0x0004 +/*WINVER >= 0x0400*/ +#define ETO_GLYPH_INDEX 0x0010 +#define ETO_RTLREADING 0x0080 +#define ETO_NUMERICSLOCAL 0x0400 +#define ETO_NUMERICSLATIN 0x0800 +#define ETO_IGNORELANGUAGE 0x1000 +/*_WIN32_WINNT >= 0x0500*/ +#define ETO_PDY 0x2000 + + +#define DEFAULT_PITCH 0x00 +#define FIXED_PITCH 0x01 +#define VARIABLE_PITCH 0x02 + +/* Font Families */ +#define FF_DONTCARE 0x00 +#define FF_ROMAN 0x10 +#define FF_SWISS 0x20 +#define FF_MODERN 0x30 +#define FF_SCRIPT 0x40 +#define FF_DECORATIVE 0x50 + +#define FW_DONTCARE 0 +#define FW_THIN 100 +#define FW_EXTRALIGHT 200 +#define FW_LIGHT 300 +#define FW_NORMAL 400 +#define FW_MEDIUM 500 +#define FW_SEMIBOLD 600 +#define FW_BOLD 700 +#define FW_EXTRABOLD 800 +#define FW_HEAVY 900 +#define FW_ULTRALIGHT 200 +#define FW_REGULAR 400 +#define FW_DEMIBOLD 600 +#define FW_ULTRABOLD 800 +#define FW_BLACK 900 + +#define BS_SOLID 0 +#define BS_NULL 1 +#define BS_HOLLOW 1 +#define BS_HATCHED 2 +#define BS_PATTERN 3 +#define BS_INDEXED 4 +#define BS_DIBPATTERN 5 +#define BS_DIBPATTERNPT 6 +#define BS_PATTERN8X8 7 +#define BS_DIBPATTERN8X8 8 +#define BS_MONOPATTERN 9 + +#define W_HS_HORIZONTAL 0 +#define W_HS_VERTICAL 1 +#define W_HS_FDIAGONAL 2 +#define W_HS_BDIAGONAL 3 +#define W_HS_CROSS 4 +#define W_HS_DIAGCROSS 5 + +#define RDH_RECTANGLES 1 + +#define W_MFCOMMENT 15 + +#define PRIVATE_ESCAPE_UNICODE 2 + +//============================ WMFReader ================================== + + +#ifdef WIN_MTF_ASSERT +#define WIN_MTF_ASSERT_INIT 0x80000000 +#define WIN_MTF_ASSERT_ONCE 0x40000000 +#define WIN_MTF_ASSERT_MIFE 0x20000000 + +void WinMtfAssertHandler( const sal_Char*, sal_uInt32 nFlags = WIN_MTF_ASSERT_MIFE ); +#endif + +enum WinMtfClipPathType{ EMPTY, RECTANGLE, COMPLEX }; + +class WinMtfClipPath +{ + PolyPolygon aPolyPoly; + WinMtfClipPathType eType; + sal_Int32 nDepth; + + void ImpUpdateType(); + + public : + + sal_Bool bNeedsUpdate; + + WinMtfClipPath(): eType(EMPTY), nDepth( 0 ), bNeedsUpdate( sal_False ){}; + + void SetClipPath( const PolyPolygon& rPolyPolygon, sal_Int32 nClippingMode ); + void IntersectClipRect( const Rectangle& rRect ); + void ExcludeClipRect( const Rectangle& rRect ); + void MoveClipRegion( const Size& rSize ); + + WinMtfClipPathType GetType() const { return eType; }; + const PolyPolygon& GetClipPath() const { return aPolyPoly; }; + + sal_Bool operator==( const WinMtfClipPath& rPath ) + { + return ( rPath.eType == eType ) && + ( rPath.aPolyPoly == aPolyPoly ); + }; +}; + +class WinMtfPathObj : public PolyPolygon +{ + sal_Bool bClosed; + + public : + + WinMtfPathObj() { bClosed = sal_True; } + void Init() { Clear(); bClosed = sal_True; }; + void ClosePath(); + + void AddPoint( const Point& rPoint ); + void AddPolygon( const Polygon& rPoly ); + void AddPolyLine( const Polygon& rPoly ); + void AddPolyPolygon( const PolyPolygon& rPolyPolygon ); +}; + +struct WinMtfFontStyle +{ + Font aFont; + + WinMtfFontStyle( LOGFONTW& rLogFont ); +}; + +// ----------------------------------------------------------------------------- + +struct WinMtfFillStyle +{ + Color aFillColor; + BOOL bTransparent; + + WinMtfFillStyle() : + aFillColor ( Color( COL_BLACK ) ), + bTransparent( FALSE ) + { + }; + + WinMtfFillStyle( const Color& rColor, BOOL bTrans = FALSE ) : + aFillColor ( rColor ), + bTransparent( bTrans ) + { + }; + + BOOL operator==( const WinMtfFillStyle& rStyle ) + { return ( ( aFillColor == rStyle.aFillColor ) && ( bTransparent == rStyle.bTransparent ) ); }; + BOOL operator==( WinMtfFillStyle* pStyle ) + { return ( ( aFillColor == pStyle->aFillColor ) && ( bTransparent == pStyle->bTransparent ) ); }; + void operator=( const WinMtfFillStyle& rStyle ) { aFillColor = rStyle.aFillColor; bTransparent = rStyle.bTransparent; }; + void operator=( WinMtfFillStyle* pStyle ) { aFillColor = pStyle->aFillColor; bTransparent = pStyle->bTransparent; }; +}; + +// ----------------------------------------------------------------------------- + +struct WinMtfLineStyle +{ + Color aLineColor; + LineInfo aLineInfo; + BOOL bTransparent; + + WinMtfLineStyle() : + aLineColor ( COL_BLACK ), + bTransparent( FALSE ) {}; + + WinMtfLineStyle( const Color& rColor, BOOL bTrans = FALSE ) : + aLineColor ( rColor ), + bTransparent( bTrans ) {}; + + WinMtfLineStyle( const Color& rColor, const LineInfo rStyle, BOOL bTrans = FALSE ) : + aLineColor ( rColor ), + aLineInfo ( rStyle ), + bTransparent( bTrans ) {}; + + BOOL operator==( const WinMtfLineStyle& rStyle ) { return ( ( aLineColor == rStyle.aLineColor ) && ( bTransparent == rStyle.bTransparent ) && ( aLineInfo == rStyle.aLineInfo ) ); }; + BOOL operator==( WinMtfLineStyle* pStyle ) { return ( ( aLineColor == pStyle->aLineColor ) && ( bTransparent == pStyle->bTransparent ) && ( aLineInfo == pStyle->aLineInfo ) ); }; + void operator=( const WinMtfLineStyle& rStyle ) + { + aLineColor = rStyle.aLineColor; + bTransparent = rStyle.bTransparent; + aLineInfo = rStyle.aLineInfo; + }; + + void operator=( WinMtfLineStyle* pStyle ) + { + aLineColor = pStyle->aLineColor; + bTransparent = pStyle->bTransparent; + aLineInfo = pStyle->aLineInfo; + }; +}; + +// ----------------------------------------------------------------------------- + +struct XForm +{ + float eM11; + float eM12; + float eM21; + float eM22; + float eDx; + float eDy; + XForm() + { + eM11 = eM22 = 1.0f; + eDx = eDy = eM12 = eM21 = 0.0f; + }; + + friend SvStream& operator>>( SvStream& rIn, XForm& rXForm ); +}; + +// ----------------------------------------------------------------------------- + +struct SaveStruct +{ + sal_uInt32 nBkMode, nMapMode, nGfxMode, nTextLayoutMode; + sal_Int32 nWinOrgX, nWinOrgY, nWinExtX, nWinExtY; + sal_Int32 nDevOrgX, nDevOrgY, nDevWidth, nDevHeight; + + WinMtfLineStyle aLineStyle; + WinMtfFillStyle aFillStyle; + + Font aFont; + Color aBkColor; + Color aTextColor; + sal_uInt32 nTextAlign; + RasterOp eRasterOp; + + Point aActPos; + WinMtfPathObj aPathObj; + WinMtfClipPath aClipPath; + XForm aXForm; + + sal_Bool bRecordPath; + sal_Bool bFillStyleSelected; +}; + +typedef ::boost::shared_ptr< SaveStruct > SaveStructPtr; + +// ----------------------------------------------------------------------------- + +struct BSaveStruct +{ + Bitmap aBmp; + Rectangle aOutRect; + UINT32 nWinRop; + + BSaveStruct( const Bitmap& rBmp, const Rectangle& rOutRect, UINT32 nRop ) : + aBmp( rBmp ), aOutRect( rOutRect ), nWinRop( nRop ){}; +}; + +// ----------------------------------------------------------------------------- + +enum GDIObjectType { GDI_DUMMY = 0, GDI_PEN = 1, GDI_BRUSH = 2, GDI_FONT = 3, GDI_PALETTE = 4, GDI_BITMAP = 5, GDI_REGION = 6 }; + +struct GDIObj +{ + void* pStyle; + GDIObjectType eType; + + GDIObj() : + pStyle ( NULL ), + eType ( GDI_DUMMY ) + { + }; + + GDIObj( GDIObjectType eT, void* pS ) { pStyle = pS; eType = eT; }; + void Set( GDIObjectType eT, void* pS ) { pStyle = pS; eType = eT; }; + void Delete() + { + if ( pStyle ) + { + switch ( eType ) + { + case GDI_PEN : + delete (WinMtfLineStyle*)pStyle; + break; + case GDI_BRUSH : + delete (WinMtfFillStyle*)pStyle; + break; + case GDI_FONT : + delete (WinMtfFontStyle*)pStyle; + break; + + default: + DBG_ERROR( "unsupported style deleted" ); + break; + } + pStyle = NULL; + } + }; + + ~GDIObj() + { + Delete(); + } +}; + +// ----------------------------------------------------------------------------- + +class WinMtfOutput +{ + + WinMtfPathObj aPathObj; + WinMtfClipPath aClipPath; + + WinMtfLineStyle maLatestLineStyle; + WinMtfLineStyle maLineStyle; + WinMtfFillStyle maLatestFillStyle; + WinMtfFillStyle maFillStyle; + Font maLatestFont; + Font maFont; + sal_uInt32 mnLatestTextAlign; + sal_uInt32 mnTextAlign; + Color maLatestTextColor; + Color maTextColor; + Color maLatestBkColor; + Color maBkColor; + sal_uInt32 mnLatestTextLayoutMode; + sal_uInt32 mnTextLayoutMode; + sal_uInt32 mnLatestBkMode; + sal_uInt32 mnBkMode; + RasterOp meLatestRasterOp; + RasterOp meRasterOp; + + std::vector< GDIObj* > vGDIObj; + + Point maActPos; + + sal_uInt32 mnRop; + sal_Bool mbNopMode; + sal_Bool mbFillStyleSelected; + + std::vector< SaveStructPtr > vSaveStack; + + sal_uInt32 mnGfxMode; + sal_uInt32 mnMapMode; + XForm maXForm; + sal_Int32 mnDevOrgX, mnDevOrgY; + sal_Int32 mnDevWidth, mnDevHeight; + sal_Int32 mnWinOrgX, mnWinOrgY; // aktuelles Window-Origin + sal_Int32 mnWinExtX, mnWinExtY; // aktuelles Window-Extent + + sal_Int32 mnPixX, mnPixY; // Reference Device in pixel + sal_Int32 mnMillX, mnMillY; // Reference Device in Mill + Rectangle mrclFrame; // rectangle in logical units 1/100th mm + Rectangle mrclBounds; + + GDIMetaFile* mpGDIMetaFile; + + void UpdateLineStyle(); + void UpdateFillStyle(); + + Point ImplMap( const Point& rPt ); + Size ImplMap( const Size& rSz ); + Rectangle ImplMap( const Rectangle& rRectangle ); + void ImplMap( Font& rFont ); + Polygon& ImplMap( Polygon& rPolygon ); + PolyPolygon& ImplMap( PolyPolygon& rPolyPolygon ); + void ImplResizeObjectArry( UINT32 nNewEntry ); + void ImplSetNonPersistentLineColorTransparenz(); + void ImplDrawClippedPolyPolygon( const PolyPolygon& rPolyPoly ); + void ImplDrawBitmap( const Point& rPos, const Size& rSize, const BitmapEx rBitmap ); + + public: + + void SetDevOrg( const Point& rPoint ); + void SetDevOrgOffset( INT32 nXAdd, INT32 nYAdd ); + void SetDevExt( const Size& rSize ); + void ScaleDevExt( double fX, double fY ); + + void SetWinOrg( const Point& rPoint ); + void SetWinOrgOffset( INT32 nX, INT32 nY ); + void SetWinExt( const Size& rSize ); + void ScaleWinExt( double fX, double fY ); + + void SetrclBounds( const Rectangle& rRect ); + void SetrclFrame( const Rectangle& rRect ); + void SetRefPix( const Size& rSize ); + void SetRefMill( const Size& rSize ); + + sal_uInt32 GetMapMode() const { return mnMapMode; }; + void SetMapMode( sal_uInt32 mnMapMode ); + void SetWorldTransform( const XForm& rXForm ); + void ModifyWorldTransform( const XForm& rXForm, UINT32 nMode ); + + void Push(); + void Pop(); + + UINT32 SetRasterOp( UINT32 nRasterOp ); + void StrokeAndFillPath( sal_Bool bStroke, sal_Bool bFill ); + + void SetGfxMode( sal_Int32 nGfxMode ){ mnGfxMode = nGfxMode; }; + sal_Int32 GetGfxMode() const { return mnGfxMode; }; + void SetBkMode( UINT32 nMode ); + void SetBkColor( const Color& rColor ); + void SetTextColor( const Color& rColor ); + void SetTextAlign( UINT32 nAlign ); + void CreateObject( GDIObjectType, void* pStyle = NULL ); + void CreateObject( INT32 nIndex, GDIObjectType, void* pStyle = NULL ); + void DeleteObject( INT32 nIndex ); + void SelectObject( INT32 nIndex ); + CharSet GetCharSet(){ return maFont.GetCharSet(); }; + void SetFont( const Font& rFont ); + const Font& GetFont() const; + void SetTextLayoutMode( const sal_uInt32 nLayoutMode ); + sal_uInt32 GetTextLayoutMode() const; + + void ClearPath(){ aPathObj.Init(); }; + void ClosePath(){ aPathObj.ClosePath(); }; + const PolyPolygon& GetPathObj(){ return aPathObj; }; + + void MoveTo( const Point& rPoint, sal_Bool bRecordPath = sal_False ); + void LineTo( const Point& rPoint, sal_Bool bRecordPath = sal_False ); + void DrawPixel( const Point& rSource, const Color& rColor ); + void DrawLine( const Point& rSource, const Point& rDest ); + void DrawRect( const Rectangle& rRect, BOOL bEdge = TRUE ); + void DrawRoundRect( const Rectangle& rRect, const Size& rSize ); + void DrawEllipse( const Rectangle& rRect ); + void DrawArc( const Rectangle& rRect, const Point& rStartAngle, const Point& rEndAngle, BOOL bDrawTo = FALSE ); + void DrawPie( const Rectangle& rRect, const Point& rStartAngle, const Point& rEndAngle ); + void DrawChord( const Rectangle& rRect, const Point& rStartAngle, const Point& rEndAngle ); + void DrawPolygon( Polygon& rPolygon, sal_Bool bRecordPath = sal_False ); + void DrawPolyPolygon( PolyPolygon& rPolyPolygon, sal_Bool bRecordPath = sal_False ); + void DrawPolyLine( Polygon& rPolygon, sal_Bool bDrawTo = sal_False, sal_Bool bRecordPath = sal_False ); + void DrawPolyBezier( Polygon& rPolygin, sal_Bool bDrawTo = sal_False, sal_Bool bRecordPath = sal_False ); + void DrawText( Point& rPosition, String& rString, sal_Int32* pDXArry = NULL, sal_Bool bRecordPath = sal_False, + sal_Int32 nGraphicsMode = GM_COMPATIBLE ); + void ResolveBitmapActions( List& rSaveList ); + + void IntersectClipRect( const Rectangle& rRect ); + void ExcludeClipRect( const Rectangle& rRect ); + void MoveClipRegion( const Size& rSize ); + void SetClipPath( const PolyPolygon& rPolyPoly, sal_Int32 nClippingMode, sal_Bool bIsMapped ); + void UpdateClipRegion(); + void AddFromGDIMetaFile( GDIMetaFile& rGDIMetaFile ); + + WinMtfOutput( GDIMetaFile& rGDIMetaFile ); + virtual ~WinMtfOutput(); +}; + +// ----------------------------------------------------------------------------- + +class WinMtf +{ + protected: + + WinMtfOutput* pOut; // + SvStream* pWMF; // Die einzulesende WMF/EMF-Datei + + UINT32 nStartPos, nEndPos; + List aBmpSaveList; + + FilterConfigItem* pFilterConfigItem; + + com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator > xStatusIndicator; + + // Sorgt dafuer, das aSampledBrush der aktuelle Brush des GDIMetaFiles ist. + + Color ReadColor(); + void Callback( USHORT nPercent ); + + WinMtf( WinMtfOutput* pOut, SvStream& rStreamWMF, FilterConfigItem* pConfigItem = NULL ); + ~WinMtf(); + + public: + +}; + +//============================ EMFReader ================================== + +class EnhWMFReader : public WinMtf +{ + sal_Bool bRecordPath; + sal_Int32 nRecordCount; + + BOOL ReadHeader(); + Rectangle ReadRectangle( INT32, INT32, INT32, INT32 ); // Liesst und konvertiert ein Rechteck + void ImplExtTextOut( BOOL bWideCharakter ); + +public: + EnhWMFReader( SvStream& rStreamWMF, GDIMetaFile& rGDIMetaFile, FilterConfigItem* pConfigItem = NULL ) + : WinMtf( new WinMtfOutput( rGDIMetaFile ), rStreamWMF, pConfigItem ), bRecordPath( sal_False ) {}; + ~EnhWMFReader(); + + BOOL ReadEnhWMF(); +}; + +//============================ WMFReader ================================== + +class WMFReader : public WinMtf +{ +private: + + VirtualDevice aVDev; // just for the purpose of "IsFontAvailable" + UINT16 nUnitsPerInch; + sal_uInt32 nRecSize; + + // embedded EMF data + SvMemoryStream* pEMFStream; + + // total number of comment records containing EMF data + sal_uInt32 nEMFRecCount; + + // number of EMF records read + sal_uInt32 nEMFRec; + + // total size of embedded EMF data + sal_uInt32 nEMFSize; + + sal_uInt32 nSkipActions; + sal_uInt32 nCurrentAction; + sal_uInt32 nUnicodeEscapeAction; + + // Liesst den Kopf der WMF-Datei + BOOL ReadHeader(); + + // Liesst die Parameter des Rocords mit der Funktionsnummer nFunction. + void ReadRecordParams( USHORT nFunction ); + + Point ReadPoint(); // Liesst und konvertiert einen Punkt (erst X dann Y) + Point ReadYX(); // Liesst und konvertiert einen Punkt (erst Y dann X) + Rectangle ReadRectangle(); // Liesst und konvertiert ein Rechteck + Size ReadYXExt(); + sal_Bool GetPlaceableBound( Rectangle& rSize, SvStream* pStrm ); + +public: + + WMFReader( SvStream& rStreamWMF, GDIMetaFile& rGDIMetaFile, FilterConfigItem* pConfigItem = NULL ) + : WinMtf( new WinMtfOutput( rGDIMetaFile ), rStreamWMF, pConfigItem ) {}; + + ~WMFReader(); + + // Liesst aus dem Stream eine WMF-Datei und fuellt das GDIMetaFile + void ReadWMF(); +}; + +#endif + + diff --git a/svtools/source/filter/wmf/winwmf.cxx b/svtools/source/filter/wmf/winwmf.cxx new file mode 100644 index 000000000000..cea1ab490b04 --- /dev/null +++ b/svtools/source/filter/wmf/winwmf.cxx @@ -0,0 +1,1431 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include "winmtf.hxx" +#include +#include +#include +#include + +//====================== MS-Windows-defines =============================== + +#define W_META_SETBKCOLOR 0x0201 +#define W_META_SETBKMODE 0x0102 +#define W_META_SETMAPMODE 0x0103 +#define W_META_SETROP2 0x0104 +#define W_META_SETRELABS 0x0105 +#define W_META_SETPOLYFILLMODE 0x0106 +#define W_META_SETSTRETCHBLTMODE 0x0107 +#define W_META_SETTEXTCHAREXTRA 0x0108 +#define W_META_SETTEXTCOLOR 0x0209 +#define W_META_SETTEXTJUSTIFICATION 0x020A +#define W_META_SETWINDOWORG 0x020B +#define W_META_SETWINDOWEXT 0x020C +#define W_META_SETVIEWPORTORG 0x020D +#define W_META_SETVIEWPORTEXT 0x020E +#define W_META_OFFSETWINDOWORG 0x020F +#define W_META_SCALEWINDOWEXT 0x0410 +#define W_META_OFFSETVIEWPORTORG 0x0211 +#define W_META_SCALEVIEWPORTEXT 0x0412 +#define W_META_LINETO 0x0213 +#define W_META_MOVETO 0x0214 +#define W_META_EXCLUDECLIPRECT 0x0415 +#define W_META_INTERSECTCLIPRECT 0x0416 +#define W_META_ARC 0x0817 +#define W_META_ELLIPSE 0x0418 +#define W_META_FLOODFILL 0x0419 +#define W_META_PIE 0x081A +#define W_META_RECTANGLE 0x041B +#define W_META_ROUNDRECT 0x061C +#define W_META_PATBLT 0x061D +#define W_META_SAVEDC 0x001E +#define W_META_SETPIXEL 0x041F +#define W_META_OFFSETCLIPRGN 0x0220 +#define W_META_TEXTOUT 0x0521 +#define W_META_BITBLT 0x0922 +#define W_META_STRETCHBLT 0x0B23 +#define W_META_POLYGON 0x0324 +#define W_META_POLYLINE 0x0325 +#define W_META_ESCAPE 0x0626 +#define W_META_RESTOREDC 0x0127 +#define W_META_FILLREGION 0x0228 +#define W_META_FRAMEREGION 0x0429 +#define W_META_INVERTREGION 0x012A +#define W_META_PAINTREGION 0x012B +#define W_META_SELECTCLIPREGION 0x012C +#define W_META_SELECTOBJECT 0x012D +#define W_META_SETTEXTALIGN 0x012E +#define W_META_DRAWTEXT 0x062F +#define W_META_CHORD 0x0830 +#define W_META_SETMAPPERFLAGS 0x0231 +#define W_META_EXTTEXTOUT 0x0a32 +#define W_META_SETDIBTODEV 0x0d33 +#define W_META_SELECTPALETTE 0x0234 +#define W_META_REALIZEPALETTE 0x0035 +#define W_META_ANIMATEPALETTE 0x0436 +#define W_META_SETPALENTRIES 0x0037 +#define W_META_POLYPOLYGON 0x0538 +#define W_META_RESIZEPALETTE 0x0139 +#define W_META_DIBBITBLT 0x0940 +#define W_META_DIBSTRETCHBLT 0x0b41 +#define W_META_DIBCREATEPATTERNBRUSH 0x0142 +#define W_META_STRETCHDIB 0x0f43 +#define W_META_EXTFLOODFILL 0x0548 +#define W_META_RESETDC 0x014C +#define W_META_STARTDOC 0x014D +#define W_META_STARTPAGE 0x004F +#define W_META_ENDPAGE 0x0050 +#define W_META_ABORTDOC 0x0052 +#define W_META_ENDDOC 0x005E +#define W_META_DELETEOBJECT 0x01f0 +#define W_META_CREATEPALETTE 0x00f7 +#define W_META_CREATEBRUSH 0x00F8 +#define W_META_CREATEPATTERNBRUSH 0x01F9 +#define W_META_CREATEPENINDIRECT 0x02FA +#define W_META_CREATEFONTINDIRECT 0x02FB +#define W_META_CREATEBRUSHINDIRECT 0x02FC +#define W_META_CREATEBITMAPINDIRECT 0x02FD +#define W_META_CREATEBITMAP 0x06FE +#define W_META_CREATEREGION 0x06FF + +//=================== Methoden von WMFReader ============================== + +inline Point WMFReader::ReadPoint() +{ + short nX, nY; + *pWMF >> nX >> nY; + return Point( nX, nY ); +} + +// ------------------------------------------------------------------------ + +inline Point WMFReader::ReadYX() +{ + short nX, nY; + *pWMF >> nY >> nX; + return Point( nX, nY ); +} + +// ------------------------------------------------------------------------ + +Rectangle WMFReader::ReadRectangle() +{ + Point aBR, aTL; + aBR = ReadYX(); + aTL = ReadYX(); + aBR.X()--; + aBR.Y()--; + return Rectangle( aTL, aBR ); +} + +// ------------------------------------------------------------------------ + +Size WMFReader::ReadYXExt() +{ + short nW, nH; + *pWMF >> nH >> nW; + return Size( nW, nH ); +} + +// ------------------------------------------------------------------------ + +void WMFReader::ReadRecordParams( USHORT nFunc ) +{ + switch( nFunc ) + { + case W_META_SETBKCOLOR: + { + pOut->SetBkColor( ReadColor() ); + } + break; + + case W_META_SETBKMODE: + { + USHORT nDat; + *pWMF >> nDat; + pOut->SetBkMode( nDat ); + } + break; + + // !!! + case W_META_SETMAPMODE: + { + sal_Int16 nMapMode; + *pWMF >> nMapMode; + pOut->SetMapMode( nMapMode ); + } + break; + + case W_META_SETROP2: + { + UINT16 nROP2; + *pWMF >> nROP2; + pOut->SetRasterOp( nROP2 ); + } + break; + + case W_META_SETTEXTCOLOR: + { + pOut->SetTextColor( ReadColor() ); + } + break; + + case W_META_SETWINDOWORG: + { + pOut->SetWinOrg( ReadYX() ); + } + break; + + case W_META_SETWINDOWEXT: + { + short nWidth, nHeight; + *pWMF >> nHeight >> nWidth; + pOut->SetWinExt( Size( nWidth, nHeight ) ); + } + break; + + case W_META_OFFSETWINDOWORG: + { + short nXAdd, nYAdd; + *pWMF >> nYAdd >> nXAdd; + pOut->SetWinOrgOffset( nXAdd, nYAdd ); + } + break; + + case W_META_SCALEWINDOWEXT: + { + short nXNum, nXDenom, nYNum, nYDenom; + *pWMF >> nYDenom >> nYNum >> nXDenom >> nXNum; + pOut->ScaleWinExt( (double)nXNum / nXDenom, (double)nYNum / nYDenom ); + } + break; + + case W_META_SETVIEWPORTORG: + case W_META_SETVIEWPORTEXT: + break; + + case W_META_OFFSETVIEWPORTORG: + { + short nXAdd, nYAdd; + *pWMF >> nYAdd >> nXAdd; + pOut->SetDevOrgOffset( nXAdd, nYAdd ); + } + break; + + case W_META_SCALEVIEWPORTEXT: + { + short nXNum, nXDenom, nYNum, nYDenom; + *pWMF >> nYDenom >> nYNum >> nXDenom >> nXNum; + pOut->ScaleDevExt( (double)nXNum / nXDenom, (double)nYNum / nYDenom ); + } + break; + + case W_META_LINETO: + { + pOut->LineTo( ReadYX() ); + } + break; + + case W_META_MOVETO: + { + pOut->MoveTo( ReadYX() ); + } + break; + + case W_META_INTERSECTCLIPRECT: + { + pOut->IntersectClipRect( ReadRectangle() ); + } + break; + + case W_META_RECTANGLE: + { + pOut->DrawRect( ReadRectangle() ); + } + break; + + case W_META_ROUNDRECT: + { + Size aSize( ReadYXExt() ); + pOut->DrawRoundRect( ReadRectangle(), Size( aSize.Width() / 2, aSize.Height() / 2 ) ); + } + break; + + case W_META_ELLIPSE: + { + pOut->DrawEllipse( ReadRectangle() ); + } + break; + + case W_META_ARC: + { + Point aEnd( ReadYX() ); + Point aStart( ReadYX() ); + Rectangle aRect( ReadRectangle() ); + aRect.Justify(); + pOut->DrawArc( aRect, aStart, aEnd ); + } + break; + + case W_META_PIE: + { + Point aEnd( ReadYX() ); + Point aStart( ReadYX() ); + Rectangle aRect( ReadRectangle() ); + aRect.Justify(); + + // #i73608# OutputDevice deviates from WMF + // semantics. start==end means full ellipse here. + if( aStart == aEnd ) + pOut->DrawEllipse( aRect ); + else + pOut->DrawPie( aRect, aStart, aEnd ); + } + break; + + case W_META_CHORD: + { + Point aEnd( ReadYX() ); + Point aStart( ReadYX() ); + Rectangle aRect( ReadRectangle() ); + aRect.Justify(); + pOut->DrawChord( aRect, aStart, aEnd ); + } + break; + + case W_META_POLYGON: + { + USHORT i,nPoints; + *pWMF >> nPoints; + Polygon aPoly( nPoints ); + for( i = 0; i < nPoints; i++ ) + aPoly[ i ] = ReadPoint(); + pOut->DrawPolygon( aPoly ); + } + break; + + case W_META_POLYPOLYGON: + { + USHORT i, nPoly, nPoints; + USHORT* pnPoints; + Point* pPtAry; + // Anzahl der Polygone: + *pWMF >> nPoly; + // Anzahl der Punkte eines jeden Polygons holen, Gesammtzahl der Punkte ermitteln: + pnPoints = new USHORT[ nPoly ]; + nPoints = 0; + for( i = 0; i < nPoly; i++ ) + { + *pWMF >> pnPoints[i]; + nPoints = nPoints + pnPoints[i]; + } + // Polygonpunkte holen: + pPtAry = (Point*) new char[ nPoints * sizeof(Point) ]; + for ( i = 0; i < nPoints; i++ ) + pPtAry[ i ] = ReadPoint(); + // PolyPolygon Actions erzeugen + PolyPolygon aPolyPoly( nPoly, pnPoints, pPtAry ); + pOut->DrawPolyPolygon( aPolyPoly ); + delete[] (char*) pPtAry; + delete[] pnPoints; + } + break; + + case W_META_POLYLINE: + { + USHORT i,nPoints; + *pWMF >> nPoints; + Polygon aPoly( nPoints ); + for( i = 0; i < nPoints; i++ ) + aPoly[ i ] = ReadPoint(); + pOut->DrawPolyLine( aPoly ); + } + break; + + case W_META_SAVEDC: + { + pOut->Push(); + } + break; + + case W_META_RESTOREDC: + { + pOut->Pop(); + } + break; + + case W_META_SETPIXEL: + { + const Color aColor = ReadColor(); + pOut->DrawPixel( ReadYX(), aColor ); + } + break; + + case W_META_OFFSETCLIPRGN: + { + pOut->MoveClipRegion( ReadYXExt() ); + } + break; + + case W_META_TEXTOUT: + { + USHORT nLength; + *pWMF >> nLength; + if ( nLength ) + { + char* pChar = new char[ ( nLength + 1 ) &~ 1 ]; + pWMF->Read( pChar, ( nLength + 1 ) &~ 1 ); + String aText( pChar, nLength, pOut->GetCharSet() ); + delete[] pChar; + Point aPosition( ReadYX() ); + pOut->DrawText( aPosition, aText ); + } + } + break; + + case W_META_EXTTEXTOUT: + { + sal_Int16 nDx, nDxTmp; + sal_uInt16 i, nLen, nOptions; + sal_Int32 nRecordPos, nRecordSize, nOriginalTextLen, nNewTextLen; + Point aPosition; + Rectangle aRect; + sal_Int32* pDXAry = NULL; + + pWMF->SeekRel(-6); + nRecordPos = pWMF->Tell(); + *pWMF >> nRecordSize; + pWMF->SeekRel(2); + aPosition = ReadYX(); + *pWMF >> nLen >> nOptions; + + sal_Int32 nTextLayoutMode = TEXT_LAYOUT_DEFAULT; + if ( nOptions & ETO_RTLREADING ) + nTextLayoutMode = TEXT_LAYOUT_BIDI_RTL | TEXT_LAYOUT_TEXTORIGIN_LEFT; + pOut->SetTextLayoutMode( nTextLayoutMode ); + DBG_ASSERT( ( nOptions & ( ETO_PDY | ETO_GLYPH_INDEX ) ) == 0, "SJ: ETO_PDY || ETO_GLYPH_INDEX in WMF" ); + + // Nur wenn der Text auch Zeichen enthaelt, macht die Ausgabe Sinn + if( nLen ) + { + nOriginalTextLen = nLen; + if( nOptions & ETO_CLIPPED ) + { + const Point aPt1( ReadPoint() ); + const Point aPt2( ReadPoint() ); + aRect = Rectangle( aPt1, aPt2 ); + } + char* pChar = new char[ ( nOriginalTextLen + 1 ) &~ 1 ]; + pWMF->Read( pChar, ( nOriginalTextLen + 1 ) &~ 1 ); + String aText( pChar, (sal_uInt16)nOriginalTextLen, pOut->GetCharSet() );// after this conversion the text may contain + nNewTextLen = aText.Len(); // less character (japanese version), so the + delete[] pChar; // dxAry will not fit + + if ( nNewTextLen ) + { + sal_uInt32 nMaxStreamPos = nRecordPos + ( nRecordSize << 1 ); + sal_Int32 nDxArySize = nMaxStreamPos - pWMF->Tell(); + sal_Int32 nDxAryEntries = nDxArySize >> 1; + sal_Bool bUseDXAry = FALSE; + + if ( ( ( nDxAryEntries % nOriginalTextLen ) == 0 ) && ( nNewTextLen <= nOriginalTextLen ) ) + { + pDXAry = new sal_Int32[ nNewTextLen ]; + for ( i = 0; i < nNewTextLen; i++ ) + { + if ( pWMF->Tell() >= nMaxStreamPos ) + break; + *pWMF >> nDx; + if ( nNewTextLen != nOriginalTextLen ) + { + ByteString aTmp( aText.GetChar( i ), pOut->GetCharSet() ); + if ( aTmp.Len() > 1 ) + { + sal_Int32 nDxCount = aTmp.Len() - 1; + if ( ( ( nDxCount * 2 ) + pWMF->Tell() ) > nMaxStreamPos ) + break; + while ( nDxCount-- ) + { + *pWMF >> nDxTmp; + nDx = nDx + nDxTmp; + } + } + } + pDXAry[ i ] = nDx; + } + if ( i == nNewTextLen ) + bUseDXAry = TRUE; + } + if ( pDXAry && bUseDXAry ) + pOut->DrawText( aPosition, aText, pDXAry ); + else + pOut->DrawText( aPosition, aText ); + } + } + delete[] pDXAry; + + } + break; + + case W_META_SELECTOBJECT: + { + INT16 nObjIndex; + *pWMF >> nObjIndex; + pOut->SelectObject( nObjIndex ); + } + break; + + case W_META_SETTEXTALIGN: + { + UINT16 nAlign; + *pWMF >> nAlign; + pOut->SetTextAlign( nAlign ); + } + break; + + case W_META_BITBLT: + { + // 0-3 : nWinROP #93454# + // 4-5 : y offset of source bitmap + // 6-7 : x offset of source bitmap + // 8-9 : used height of source bitmap + // 10-11 : used width of source bitmap + // 12-13 : destination position y (in pixel) + // 14-15 : destination position x (in pixel) + // 16-17 : dont know + // 18-19 : Width Bitmap in Pixel + // 20-21 : Height Bitmap in Pixel + // 22-23 : bytes per scanline + // 24 : planes + // 25 : bitcount + + sal_Int32 nWinROP; + sal_uInt16 nSx, nSy, nSxe, nSye, nDontKnow, nWidth, nHeight, nBytesPerScan; + sal_uInt8 nPlanes, nBitCount; + + *pWMF >> nWinROP + >> nSy >> nSx >> nSye >> nSxe; + Point aPoint( ReadYX() ); + *pWMF >> nDontKnow >> nWidth >> nHeight >> nBytesPerScan >> nPlanes >> nBitCount; + + if ( nWidth && nHeight && ( nPlanes == 1 ) && ( nBitCount == 1 ) ) + { + Bitmap aBmp( Size( nWidth, nHeight ), nBitCount ); + BitmapWriteAccess* pAcc; + pAcc = aBmp.AcquireWriteAccess(); + if ( pAcc ) + { + sal_uInt16 y, x, scan; + sal_Int8 i, nEightPixels; + for ( y = 0; y < nHeight; y++ ) + { + x = 0; + for ( scan = 0; scan < nBytesPerScan; scan++ ) + { + *pWMF >> nEightPixels; + for ( i = 7; i >= 0; i-- ) + { + if ( x < nWidth ) + { + pAcc->SetPixel( y, x, (nEightPixels>>i)&1 ); + } + x++; + } + } + } + aBmp.ReleaseAccess( pAcc ); + if ( nSye && nSxe && + ( ( nSx + nSxe ) <= aBmp.GetSizePixel().Width() ) && + ( ( nSy + nSye <= aBmp.GetSizePixel().Height() ) ) ) + { + Rectangle aCropRect( Point( nSx, nSy ), Size( nSxe, nSye ) ); + aBmp.Crop( aCropRect ); + } + Rectangle aDestRect( aPoint, Size( nSxe, nSye ) ); + aBmpSaveList.Insert( new BSaveStruct( aBmp, aDestRect, nWinROP ), LIST_APPEND ); + } + } + } + break; + + case W_META_STRETCHBLT: + case W_META_DIBBITBLT: + case W_META_DIBSTRETCHBLT: + case W_META_STRETCHDIB: + { + sal_Int32 nWinROP; + sal_uInt16 nSx, nSy, nSxe, nSye, nUsage; + Bitmap aBmp; + + *pWMF >> nWinROP; + + if( nFunc == W_META_STRETCHDIB ) + *pWMF >> nUsage; + + // nSye and nSxe is the number of pixels that has to been used + if( nFunc == W_META_STRETCHDIB || nFunc == W_META_STRETCHBLT || nFunc == W_META_DIBSTRETCHBLT ) + *pWMF >> nSye >> nSxe; + else + nSye = nSxe = 0; // set this to zero as indicator not to scale the bitmap later + + // nSy and nx is the offset of the first pixel + *pWMF >> nSy >> nSx; + + if( nFunc == W_META_STRETCHDIB || nFunc == W_META_DIBBITBLT || nFunc == W_META_DIBSTRETCHBLT ) + { + if ( nWinROP == PATCOPY ) + *pWMF >> nUsage; // i don't know anything of this parameter, so its called nUsage + // pOut->DrawRect( Rectangle( ReadYX(), aDestSize ), FALSE ); + + Size aDestSize( ReadYXExt() ); + if ( aDestSize.Width() && aDestSize.Height() ) // #92623# do not try to read buggy bitmaps + { + Rectangle aDestRect( ReadYX(), aDestSize ); + if ( nWinROP != PATCOPY ) + aBmp.Read( *pWMF, FALSE ); + + // test if it is sensible to crop + if ( nSye && nSxe && + ( ( nSx + nSxe ) <= aBmp.GetSizePixel().Width() ) && + ( ( nSy + nSye <= aBmp.GetSizePixel().Height() ) ) ) + { + Rectangle aCropRect( Point( nSx, nSy ), Size( nSxe, nSye ) ); + aBmp.Crop( aCropRect ); + } + aBmpSaveList.Insert( new BSaveStruct( aBmp, aDestRect, nWinROP ), LIST_APPEND ); + } + } + } + break; + + case W_META_DIBCREATEPATTERNBRUSH: + { + Bitmap aBmp; + BitmapReadAccess* pBmp; + UINT32 nRed = 0, nGreen = 0, nBlue = 0, nCount = 1; + UINT16 nFunction; + + *pWMF >> nFunction >> nFunction; + + aBmp.Read( *pWMF, FALSE ); + pBmp = aBmp.AcquireReadAccess(); + if ( pBmp ) + { + for ( INT32 y = 0; y < pBmp->Height(); y++ ) + { + for ( INT32 x = 0; x < pBmp->Width(); x++ ) + { + const BitmapColor aColor( pBmp->GetColor( y, x ) ); + + nRed += aColor.GetRed(); + nGreen += aColor.GetGreen(); + nBlue += aColor.GetBlue(); + } + } + nCount = pBmp->Height() * pBmp->Width(); + if ( !nCount ) + nCount++; + aBmp.ReleaseAccess( pBmp ); + } + Color aColor( (BYTE)( nRed / nCount ), (BYTE)( nGreen / nCount ), (BYTE)( nBlue / nCount ) ); + pOut->CreateObject( GDI_BRUSH, new WinMtfFillStyle( aColor, FALSE ) ); + } + break; + + case W_META_DELETEOBJECT: + { + INT16 nIndex; + *pWMF >> nIndex; + pOut->DeleteObject( nIndex ); + } + break; + + case W_META_CREATEPALETTE: + { + pOut->CreateObject( GDI_DUMMY ); + } + break; + + case W_META_CREATEBRUSH: + { + pOut->CreateObject( GDI_BRUSH, new WinMtfFillStyle( Color( COL_WHITE ), FALSE ) ); + } + break; + + case W_META_CREATEPATTERNBRUSH: + { + pOut->CreateObject( GDI_BRUSH, new WinMtfFillStyle( Color( COL_WHITE ), FALSE ) ); + } + break; + + case W_META_CREATEPENINDIRECT: + { + LineInfo aLineInfo; + USHORT nStyle, nWidth, nHeight; + + *pWMF >> nStyle >> nWidth >> nHeight; + + if ( nWidth ) + aLineInfo.SetWidth( nWidth ); + + BOOL bTransparent = FALSE; + UINT16 nDashCount = 0; + UINT16 nDotCount = 0; + switch( nStyle ) + { + case PS_DASHDOTDOT : + nDotCount++; + case PS_DASHDOT : + nDashCount++; + case PS_DOT : + nDotCount++; + break; + case PS_DASH : + nDashCount++; + break; + case PS_NULL : + bTransparent = TRUE; + aLineInfo.SetStyle( LINE_NONE ); + break; + default : + case PS_INSIDEFRAME : + case PS_SOLID : + aLineInfo.SetStyle( LINE_SOLID ); + } + if ( nDashCount | nDotCount ) + { + aLineInfo.SetStyle( LINE_DASH ); + aLineInfo.SetDashCount( nDashCount ); + aLineInfo.SetDotCount( nDotCount ); + } + pOut->CreateObject( GDI_PEN, new WinMtfLineStyle( ReadColor(), aLineInfo, bTransparent ) ); + } + break; + + case W_META_CREATEBRUSHINDIRECT: + { + USHORT nStyle; + *pWMF >> nStyle; + pOut->CreateObject( GDI_BRUSH, new WinMtfFillStyle( ReadColor(), ( nStyle == BS_HOLLOW ) ? TRUE : FALSE ) ); + } + break; + + case W_META_CREATEFONTINDIRECT: + { + Size aFontSize; + char lfFaceName[ LF_FACESIZE ]; + INT16 lfEscapement, lfOrientation, lfWeight; // ( ehemals USHORT ) + + LOGFONTW aLogFont; + aFontSize = ReadYXExt(); + *pWMF >> lfEscapement >> lfOrientation >> lfWeight + >> aLogFont.lfItalic >> aLogFont.lfUnderline >> aLogFont.lfStrikeOut >> aLogFont.lfCharSet >> aLogFont.lfOutPrecision + >> aLogFont.lfClipPrecision >> aLogFont.lfQuality >> aLogFont.lfPitchAndFamily; + pWMF->Read( lfFaceName, LF_FACESIZE ); + aLogFont.lfWidth = aFontSize.Width(); + aLogFont.lfHeight = aFontSize.Height(); + aLogFont.lfEscapement = lfEscapement; + aLogFont.lfOrientation = lfOrientation; + aLogFont.lfWeight = lfWeight; + + CharSet eCharSet; + if ( ( aLogFont.lfCharSet == OEM_CHARSET ) || ( aLogFont.lfCharSet == DEFAULT_CHARSET ) ) + eCharSet = gsl_getSystemTextEncoding(); + else + eCharSet = rtl_getTextEncodingFromWindowsCharset( aLogFont.lfCharSet ); + if ( eCharSet == RTL_TEXTENCODING_DONTKNOW ) + eCharSet = gsl_getSystemTextEncoding(); + if ( eCharSet == RTL_TEXTENCODING_SYMBOL ) + eCharSet = RTL_TEXTENCODING_MS_1252; + aLogFont.alfFaceName = UniString( lfFaceName, eCharSet ); + + pOut->CreateObject( GDI_FONT, new WinMtfFontStyle( aLogFont ) ); + } + break; + + case W_META_CREATEBITMAPINDIRECT: + { + pOut->CreateObject( GDI_DUMMY ); + } + break; + + case W_META_CREATEBITMAP: + { + pOut->CreateObject( GDI_DUMMY ); + } + break; + + case W_META_CREATEREGION: + { + pOut->CreateObject( GDI_DUMMY ); + } + break; + + case W_META_EXCLUDECLIPRECT : + { + pOut->ExcludeClipRect( ReadRectangle() ); + } + break; + + case W_META_PATBLT: + { + UINT32 nROP, nOldROP; + *pWMF >> nROP; + Size aSize = ReadYXExt(); + nOldROP = pOut->SetRasterOp( nROP ); + pOut->DrawRect( Rectangle( ReadYX(), aSize ), FALSE ); + pOut->SetRasterOp( nOldROP ); + } + break; + + case W_META_SELECTCLIPREGION: + { + sal_Int16 nObjIndex; + *pWMF >> nObjIndex; + if ( !nObjIndex ) + { + PolyPolygon aEmptyPolyPoly; + pOut->SetClipPath( aEmptyPolyPoly, RGN_COPY, sal_True ); + } + } + break; + + case W_META_ESCAPE : + { + // nRecSize has been checked previously to be greater than 3 + sal_uInt64 nMetaRecSize = static_cast< sal_uInt64 >( nRecSize - 2 ) * 2; + sal_uInt64 nMetaRecEndPos = pWMF->Tell() + nMetaRecSize; + + // taking care that nRecSize does not exceed the maximal stream position + if ( nMetaRecEndPos > nEndPos ) + { + pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR ); + break; + } + if ( nRecSize >= 4 ) // minimal escape lenght + { + sal_uInt16 nMode, nLen; + *pWMF >> nMode + >> nLen; + if ( ( nMode == W_MFCOMMENT ) && ( nLen >= 4 ) ) + { + sal_uInt32 nNewMagic; // we have to read int32 for + *pWMF >> nNewMagic; // META_ESCAPE_ENHANCED_METAFILE CommentIdentifier + + if( nNewMagic == 0x2c2a4f4f && nLen >= 14 ) + { + sal_uInt16 nMagic2; + *pWMF >> nMagic2; + if( nMagic2 == 0x0a ) // 2nd half of magic + { // continue with private escape + sal_uInt32 nCheck, nEsc; + *pWMF >> nCheck + >> nEsc; + + sal_uInt32 nEscLen = nLen - 14; + if ( nEscLen <= ( nRecSize * 2 ) ) + { +#ifdef OSL_BIGENDIAN + sal_uInt32 nTmp = SWAPLONG( nEsc ); + sal_uInt32 nCheckSum = rtl_crc32( 0, &nTmp, 4 ); +#else + sal_uInt32 nCheckSum = rtl_crc32( 0, &nEsc, 4 ); +#endif + sal_Int8* pData = NULL; + + if ( ( static_cast< sal_uInt64 >( nEscLen ) + pWMF->Tell() ) > nMetaRecEndPos ) + { + pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR ); + break; + } + if ( nEscLen > 0 ) + { + pData = new sal_Int8[ nEscLen ]; + pWMF->Read( pData, nEscLen ); + nCheckSum = rtl_crc32( nCheckSum, pData, nEscLen ); + } + if ( nCheck == nCheckSum ) + { + switch( nEsc ) + { + case PRIVATE_ESCAPE_UNICODE : + { // we will use text instead of polygons only if we have the correct font + if ( aVDev.IsFontAvailable( pOut->GetFont().GetName() ) ) + { + Point aPt; + String aString; + sal_uInt32 i, nStringLen, nDXCount; + sal_Int32* pDXAry = NULL; + SvMemoryStream aMemoryStream( nEscLen ); + aMemoryStream.Write( pData, nEscLen ); + aMemoryStream.Seek( STREAM_SEEK_TO_BEGIN ); + aMemoryStream >> aPt.X() + >> aPt.Y() + >> nStringLen; + + if ( ( static_cast< sal_uInt64 >( nStringLen ) * sizeof( sal_Unicode ) ) < ( nEscLen - aMemoryStream.Tell() ) ) + { + sal_Unicode* pBuf = aString.AllocBuffer( (xub_StrLen)nStringLen ); + for ( i = 0; i < nStringLen; i++ ) + aMemoryStream >> pBuf[ i ]; + aMemoryStream >> nDXCount; + if ( ( static_cast< sal_uInt64 >( nDXCount ) * sizeof( sal_Int32 ) ) >= ( nEscLen - aMemoryStream.Tell() ) ) + nDXCount = 0; + if ( nDXCount ) + pDXAry = new sal_Int32[ nDXCount ]; + for ( i = 0; i < nDXCount; i++ ) + aMemoryStream >> pDXAry[ i ]; + aMemoryStream >> nSkipActions; + pOut->DrawText( aPt, aString, pDXAry ); + delete[] pDXAry; + } + } + } + break; + } + } + delete[] pData; + } + } + } + else if ( (nNewMagic == static_cast< sal_uInt32 >(0x43464D57)) && (nLen >= 34) && ( (sal_Int32)(nLen + 10) <= (sal_Int32)(nRecSize * 2) )) + { + sal_uInt32 nComType, nVersion, nFlags, nComRecCount, + nCurRecSize, nRemainingSize, nEMFTotalSize; + sal_uInt16 nCheck; + + *pWMF >> nComType >> nVersion >> nCheck >> nFlags + >> nComRecCount >> nCurRecSize + >> nRemainingSize >> nEMFTotalSize; // the nRemainingSize is not mentioned in MSDN documentation + // but it seems to be required to read in data produced by OLE + + if( nComType == 0x01 && nVersion == 0x10000 && nComRecCount ) + { + if( !nEMFRec ) + { // first EMF comment + nEMFRecCount = nComRecCount; + nEMFSize = nEMFTotalSize; + pEMFStream = new SvMemoryStream( nEMFSize ); + } + else if( ( nEMFRecCount != nComRecCount ) || ( nEMFSize != nEMFTotalSize ) ) // add additional checks here + { + // total records should be the same as in previous comments + nEMFRecCount = 0xFFFFFFFF; + delete pEMFStream; + pEMFStream = NULL; + } + nEMFRec++; + + if( pEMFStream && nCurRecSize + 34 > nLen ) + { + nEMFRecCount = 0xFFFFFFFF; + delete pEMFStream; + pEMFStream = NULL; + } + + if( pEMFStream ) + { + sal_Int8* pBuf = new sal_Int8[ nCurRecSize ]; + sal_uInt32 nCount = pWMF->Read( pBuf, nCurRecSize ); + if( nCount == nCurRecSize ) + pEMFStream->Write( pBuf, nCount ); + delete[] pBuf; + } + } + } + } + } + } + break; + + case W_META_SETRELABS: + case W_META_SETPOLYFILLMODE: + case W_META_SETSTRETCHBLTMODE: + case W_META_SETTEXTCHAREXTRA: + case W_META_SETTEXTJUSTIFICATION: + case W_META_FLOODFILL : + case W_META_FILLREGION: + case W_META_FRAMEREGION: + case W_META_INVERTREGION: + case W_META_PAINTREGION: + case W_META_DRAWTEXT: + case W_META_SETMAPPERFLAGS: + case W_META_SETDIBTODEV: + case W_META_SELECTPALETTE: + case W_META_REALIZEPALETTE: + case W_META_ANIMATEPALETTE: + case W_META_SETPALENTRIES: + case W_META_RESIZEPALETTE: + case W_META_EXTFLOODFILL: + case W_META_RESETDC: + case W_META_STARTDOC: + case W_META_STARTPAGE: + case W_META_ENDPAGE: + case W_META_ABORTDOC: + case W_META_ENDDOC: + break; + } +} + +// ------------------------------------------------------------------------ + +BOOL WMFReader::ReadHeader() +{ + Rectangle aPlaceableBound; + sal_uInt32 nl, nStrmPos = pWMF->Tell(); + + // Einlesen des METAFILEHEADER, falls vorhanden + *pWMF >> nl; + + Size aWMFSize; + if ( nl == 0x9ac6cdd7L ) + { + INT16 nVal; + + // hmf (Unused) ueberlesen wir + pWMF->SeekRel(2); + + // BoundRect + *pWMF >> nVal; aPlaceableBound.Left() = nVal; + *pWMF >> nVal; aPlaceableBound.Top() = nVal; + *pWMF >> nVal; aPlaceableBound.Right() = nVal; + *pWMF >> nVal; aPlaceableBound.Bottom() = nVal; + + // inch + *pWMF >> nUnitsPerInch; + + // reserved + pWMF->SeekRel( 4 ); + + // checksum pruefen wir lieber nicht + pWMF->SeekRel( 2 ); + } + else + { + nUnitsPerInch = 96; + pWMF->Seek( nStrmPos + 18 ); // set the streampos to the start of the the metaactions + GetPlaceableBound( aPlaceableBound, pWMF ); + pWMF->Seek( nStrmPos ); + } + + pOut->SetWinOrg( aPlaceableBound.TopLeft() ); + aWMFSize = Size( labs( aPlaceableBound.GetWidth() ), labs( aPlaceableBound.GetHeight() ) ); + pOut->SetWinExt( aWMFSize ); + + Size aDevExt( 10000, 10000 ); + if( ( labs( aWMFSize.Width() ) > 1 ) && ( labs( aWMFSize.Height() ) > 1 ) ) + { + const Fraction aFrac( 1, nUnitsPerInch ); + MapMode aWMFMap( MAP_INCH, Point(), aFrac, aFrac ); + Size aSize100( OutputDevice::LogicToLogic( aWMFSize, aWMFMap, MAP_100TH_MM ) ); + aDevExt = Size( labs( aSize100.Width() ), labs( aSize100.Height() ) ); + } + pOut->SetDevExt( aDevExt ); + + // Einlesen des METAHEADER + *pWMF >> nl; // Typ und Headergroesse + + if( nl != 0x00090001 ) + { + pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR ); + return FALSE; + } + + pWMF->SeekRel( 2 ); // Version (von Windows) + pWMF->SeekRel( 4 ); // Size (der Datei in Words) + pWMF->SeekRel( 2 ); // NoObjects (Maximale Anzahl der gleichzeitigen Objekte) + pWMF->SeekRel( 4 ); // MaxRecord (Groesse des groessten Records in Words) + pWMF->SeekRel( 2 ); // NoParameters (Unused + + return TRUE; +} + +void WMFReader::ReadWMF() +{ + USHORT nFunction; + ULONG nPos, nPercent, nLastPercent; + + nSkipActions = 0; + nCurrentAction = 0; + nUnicodeEscapeAction = 0; + + pEMFStream = NULL; + nEMFRecCount = 0; + nEMFRec = 0; + nEMFSize = 0; + + sal_Bool bEMFAvailable = sal_False; + + pOut->SetMapMode( MM_ANISOTROPIC ); + pOut->SetWinOrg( Point() ); + pOut->SetWinExt( Size( 1, 1 ) ); + pOut->SetDevExt( Size( 10000, 10000 ) ); + + nEndPos=pWMF->Seek( STREAM_SEEK_TO_END ); + pWMF->Seek( nStartPos ); + Callback( (USHORT) ( nLastPercent = 0 ) ); + + if ( ReadHeader() ) + { + + nPos = pWMF->Tell(); + + if( nEndPos - nStartPos ) + { + while( TRUE ) + { + nCurrentAction++; + nPercent = ( nPos - nStartPos ) * 100 / ( nEndPos - nStartPos ); + + if( nLastPercent + 4 <= nPercent ) + { + Callback( (USHORT) nPercent ); + nLastPercent = nPercent; + } + *pWMF >> nRecSize >> nFunction; + + if( pWMF->GetError() || ( nRecSize < 3 ) || ( nRecSize==3 && nFunction==0 ) || pWMF->IsEof() ) + { + + if( pWMF->IsEof() ) + pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR ); + + break; + } + if ( !bEMFAvailable ) + { + if( aBmpSaveList.Count() && + ( nFunction != W_META_STRETCHDIB ) && + ( nFunction != W_META_DIBBITBLT ) && + ( nFunction != W_META_DIBSTRETCHBLT ) ) + { + pOut->ResolveBitmapActions( aBmpSaveList ); + } + if ( !nSkipActions ) + ReadRecordParams( nFunction ); + else + nSkipActions--; + + if( pEMFStream && nEMFRecCount == nEMFRec ) + { + GDIMetaFile aMeta; + pEMFStream->Seek( 0 ); + EnhWMFReader* pEMFReader = new EnhWMFReader ( *pEMFStream, aMeta ); + bEMFAvailable = pEMFReader->ReadEnhWMF(); + delete pEMFReader; // destroy first!!! + + if( bEMFAvailable ) + { + pOut->AddFromGDIMetaFile( aMeta ); + pOut->SetrclFrame( Rectangle(0, 0, aMeta.GetPrefSize().Width(), aMeta.GetPrefSize().Height() )); + + // the stream needs to be set to the wmf end position, + // otherwise the GfxLink that is created will be incorrect + // (leading to graphic loss after swapout/swapin). + // so we will proceed normally, but are ignoring further wmf + // records + } + else + { + // something went wrong + // continue with WMF, don't try this again + delete pEMFStream; + pEMFStream = NULL; + } + } + } + nPos += nRecSize * 2; + if ( nPos <= nEndPos ) + pWMF->Seek( nPos ); + else + pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR ); + } + } + else + pWMF->SetError( SVSTREAM_GENERALERROR ); + + if( !pWMF->GetError() && aBmpSaveList.Count() ) + pOut->ResolveBitmapActions( aBmpSaveList ); + } + if ( pWMF->GetError() ) + pWMF->Seek( nStartPos ); +} + +// ------------------------------------------------------------------------ + +static void GetWinExtMax( const Point& rSource, Rectangle& rPlaceableBound, const sal_Int16 nMapMode ) +{ + Point aSource( rSource ); + if ( nMapMode == MM_HIMETRIC ) + aSource.Y() = -rSource.Y(); + if ( aSource.X() < rPlaceableBound.Left() ) + rPlaceableBound.Left() = aSource.X(); + if ( aSource.X() > rPlaceableBound.Right() ) + rPlaceableBound.Right() = aSource.X(); + if ( aSource.Y() < rPlaceableBound.Top() ) + rPlaceableBound.Top() = aSource.Y(); + if ( aSource.Y() > rPlaceableBound.Bottom() ) + rPlaceableBound.Bottom() = aSource.Y(); +} + +static void GetWinExtMax( const Rectangle& rSource, Rectangle& rPlaceableBound, const sal_Int16 nMapMode ) +{ + GetWinExtMax( rSource.TopLeft(), rPlaceableBound, nMapMode ); + GetWinExtMax( rSource.BottomRight(), rPlaceableBound, nMapMode ); +} + +sal_Bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) +{ + sal_Bool bRet = sal_True; + + rPlaceableBound.Left() = (sal_Int32)0x7fffffff; + rPlaceableBound.Top() = (sal_Int32)0x7fffffff; + rPlaceableBound.Right() = (sal_Int32)0x80000000; + rPlaceableBound.Bottom() = (sal_Int32)0x80000000; + + sal_Int16 nMapMode = MM_ANISOTROPIC; + + sal_uInt16 nFunction; + sal_uInt32 nRSize; + sal_uInt32 nPos = pStm->Tell(); + sal_uInt32 nEnd = pStm->Seek( STREAM_SEEK_TO_END ); + + pStm->Seek( nPos ); + + if( nEnd - nPos ) + { + while( bRet ) + { + *pStm >> nRSize >> nFunction; + + if( pStm->GetError() || ( nRSize < 3 ) || ( nRSize==3 && nFunction==0 ) || pStm->IsEof() ) + { + if( pStm->IsEof() ) + { + pStm->SetError( SVSTREAM_FILEFORMAT_ERROR ); + bRet = sal_False; + } + break; + } + switch( nFunction ) + { + case W_META_SETWINDOWORG: + { + Point aWinOrg; + aWinOrg = ReadYX(); + rPlaceableBound.SetPos( aWinOrg ); + } + break; + + case W_META_SETWINDOWEXT: + { + Point aPos0( 0, 0 ); + sal_Int16 nWidth, nHeight; + *pStm >> nHeight >> nWidth; + rPlaceableBound.SetSize( Size( nWidth, nHeight ) ); + } + break; + + case W_META_SETMAPMODE : + *pStm >> nMapMode; + break; + + case W_META_MOVETO: + case W_META_LINETO: + GetWinExtMax( ReadYX(), rPlaceableBound, nMapMode ); + break; + + case W_META_RECTANGLE: + case W_META_INTERSECTCLIPRECT: + case W_META_EXCLUDECLIPRECT : + case W_META_ELLIPSE: + GetWinExtMax( ReadRectangle(), rPlaceableBound, nMapMode ); + break; + + case W_META_ROUNDRECT: + { + Size aSize( ReadYXExt() ); + GetWinExtMax( ReadRectangle(), rPlaceableBound, nMapMode ); + } + break; + + case W_META_ARC: + case W_META_PIE: + case W_META_CHORD: + { + Point aEnd( ReadYX() ); + Point aStart( ReadYX() ); + GetWinExtMax( ReadRectangle(), rPlaceableBound, nMapMode ); + } + break; + + case W_META_POLYGON: + { + USHORT i,nPoints; + *pStm >> nPoints; + for( i = 0; i < nPoints; i++ ) + GetWinExtMax( ReadPoint(), rPlaceableBound, nMapMode ); + } + break; + + case W_META_POLYPOLYGON: + { + USHORT i, nPoly, nPoints = 0; + *pStm >> nPoly; + for( i = 0; i < nPoly; i++ ) + { + sal_uInt16 nP; + *pStm >> nP; + nPoints = nPoints + nP; + } + for ( i = 0; i < nPoints; i++ ) + GetWinExtMax( ReadPoint(), rPlaceableBound, nMapMode ); + } + break; + + case W_META_POLYLINE: + { + USHORT i,nPoints; + *pStm >> nPoints; + for( i = 0; i < nPoints; i++ ) + GetWinExtMax( ReadPoint(), rPlaceableBound, nMapMode ); + } + break; + + case W_META_SETPIXEL: + { + const Color aColor = ReadColor(); + GetWinExtMax( ReadYX(), rPlaceableBound, nMapMode ); + } + break; + + case W_META_TEXTOUT: + { + USHORT nLength; + *pStm >> nLength; + // todo: we also have to take care of the text width + if ( nLength ) + { + pStm->SeekRel( ( nLength + 1 ) &~ 1 ); + GetWinExtMax( ReadYX(), rPlaceableBound, nMapMode ); + } + } + break; + + case W_META_EXTTEXTOUT: + { + sal_uInt16 nLen, nOptions; + sal_Int32 nRecordPos, nRecordSize; + Point aPosition; + Rectangle aRect; + + pStm->SeekRel(-6); + nRecordPos = pStm->Tell(); + *pStm >> nRecordSize; + pStm->SeekRel(2); + aPosition = ReadYX(); + *pStm >> nLen >> nOptions; + // todo: we also have to take care of the text width + if( nLen ) + GetWinExtMax( aPosition, rPlaceableBound, nMapMode ); + } + break; + case W_META_BITBLT: + case W_META_STRETCHBLT: + case W_META_DIBBITBLT: + case W_META_DIBSTRETCHBLT: + case W_META_STRETCHDIB: + { + sal_Int32 nWinROP; + sal_uInt16 nSx, nSy, nSxe, nSye, nUsage; + *pStm >> nWinROP; + + if( nFunction == W_META_STRETCHDIB ) + *pStm >> nUsage; + + // nSye and nSxe is the number of pixels that has to been used + if( nFunction == W_META_STRETCHDIB || nFunction == W_META_STRETCHBLT || nFunction == W_META_DIBSTRETCHBLT ) + *pStm >> nSye >> nSxe; + else + nSye = nSxe = 0; // set this to zero as indicator not to scale the bitmap later + + // nSy and nx is the offset of the first pixel + *pStm >> nSy >> nSx; + + if( nFunction == W_META_STRETCHDIB || nFunction == W_META_DIBBITBLT || nFunction == W_META_DIBSTRETCHBLT ) + { + if ( nWinROP == PATCOPY ) + *pStm >> nUsage; // i don't know anything of this parameter, so its called nUsage + // pOut->DrawRect( Rectangle( ReadYX(), aDestSize ), FALSE ); + + Size aDestSize( ReadYXExt() ); + if ( aDestSize.Width() && aDestSize.Height() ) // #92623# do not try to read buggy bitmaps + { + Rectangle aDestRect( ReadYX(), aDestSize ); + GetWinExtMax( aDestRect, rPlaceableBound, nMapMode ); + } + } + } + break; + + case W_META_PATBLT: + { + UINT32 nROP; + *pStm >> nROP; + Size aSize = ReadYXExt(); + GetWinExtMax( Rectangle( ReadYX(), aSize ), rPlaceableBound, nMapMode ); + } + break; + } + nPos += nRSize * 2; + if ( nPos <= nEnd ) + pStm->Seek( nPos ); + else + { + pStm->SetError( SVSTREAM_FILEFORMAT_ERROR ); + bRet = sal_False; + } + + } + } + else + { + pStm->SetError( SVSTREAM_GENERALERROR ); + bRet = sal_False; + } + return bRet; +} + +WMFReader::~WMFReader() +{ + if( pEMFStream ) + delete pEMFStream; +} + diff --git a/svtools/source/filter/wmf/wmf.cxx b/svtools/source/filter/wmf/wmf.cxx new file mode 100644 index 000000000000..25ca9f721b33 --- /dev/null +++ b/svtools/source/filter/wmf/wmf.cxx @@ -0,0 +1,114 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include "winmtf.hxx" +#include "emfwr.hxx" +#include "wmfwr.hxx" +#include + +// ----------------------------------------------------------------------------- + +BOOL ConvertWMFToGDIMetaFile( SvStream & rStreamWMF, GDIMetaFile & rGDIMetaFile, FilterConfigItem* pConfigItem ) +{ + UINT32 nMetaType; + UINT32 nOrgPos = rStreamWMF.Tell(); + UINT16 nOrigNumberFormat = rStreamWMF.GetNumberFormatInt(); + rStreamWMF.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); + rStreamWMF.Seek( 0x28 ); + rStreamWMF >> nMetaType; + rStreamWMF.Seek( nOrgPos ); + if ( nMetaType == 0x464d4520 ) + { + if ( EnhWMFReader( rStreamWMF, rGDIMetaFile, pConfigItem ).ReadEnhWMF() == FALSE ) + rStreamWMF.SetError( SVSTREAM_FILEFORMAT_ERROR ); + } + else + { + WMFReader( rStreamWMF, rGDIMetaFile, pConfigItem ).ReadWMF(); + } + rStreamWMF.SetNumberFormatInt( nOrigNumberFormat ); + return !rStreamWMF.GetError(); +} + +// ----------------------------------------------------------------------------- + +BOOL ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF, FilterConfigItem* pFilterConfigItem ) +{ + UINT32 nMetaType; + UINT32 nOrgPos = rStream.Tell(); + UINT16 nOrigNumberFormat = rStream.GetNumberFormatInt(); + rStream.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); + rStream.Seek( 0x28 ); + rStream >> nMetaType; + rStream.Seek( nOrgPos ); + if ( nMetaType == 0x464d4520 ) + { + if ( EnhWMFReader( rStream, rMTF, NULL ).ReadEnhWMF() == FALSE ) + rStream.SetError( SVSTREAM_FILEFORMAT_ERROR ); + } + else + { + WMFReader( rStream, rMTF, pFilterConfigItem ).ReadWMF(); + } + rStream.SetNumberFormatInt( nOrigNumberFormat ); + return !rStream.GetError(); +} + +// ----------------------------------------------------------------------------- + +BOOL ConvertGDIMetaFileToWMF( const GDIMetaFile & rMTF, SvStream & rTargetStream, + FilterConfigItem* pConfigItem, BOOL bPlaceable) +{ + WMFWriter aWMFWriter; + return aWMFWriter.WriteWMF( rMTF, rTargetStream, pConfigItem, bPlaceable ); +} + +// ----------------------------------------------------------------------------- + +BOOL ConvertGDIMetaFileToEMF( const GDIMetaFile & rMTF, SvStream & rTargetStream, + FilterConfigItem* pConfigItem ) +{ + EMFWriter aEMFWriter; + return aEMFWriter.WriteEMF( rMTF, rTargetStream, pConfigItem ); +} + +// ----------------------------------------------------------------------------- + +BOOL WriteWindowMetafile( SvStream& rStream, const GDIMetaFile& rMTF ) +{ + return WMFWriter().WriteWMF( rMTF, rStream, NULL ); +} + +// ----------------------------------------------------------------------------- + +BOOL WriteWindowMetafileBits( SvStream& rStream, const GDIMetaFile& rMTF ) +{ + return WMFWriter().WriteWMF( rMTF, rStream, NULL, FALSE ); +} diff --git a/svtools/source/filter/wmf/wmfwr.cxx b/svtools/source/filter/wmf/wmfwr.cxx new file mode 100644 index 000000000000..82d4101b48c9 --- /dev/null +++ b/svtools/source/filter/wmf/wmfwr.cxx @@ -0,0 +1,2124 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include +#include +#include "wmfwr.hxx" +#include +#include "emfwr.hxx" +#include +#include +#include +#include +#ifndef INCLUDED_I18NUTIL_UNICODE_HXX +#include //unicode::getUnicodeScriptType +#endif + +#include +#include +#include + +//====================== MS-Windows-defines =============================== + +#define W_META_SETBKCOLOR 0x0201 +#define W_META_SETBKMODE 0x0102 +#define W_META_SETMAPMODE 0x0103 +#define W_META_SETROP2 0x0104 +#define W_META_SETRELABS 0x0105 +#define W_META_SETPOLYFILLMODE 0x0106 +#define W_META_SETSTRETCHBLTMODE 0x0107 +#define W_META_SETTEXTCHAREXTRA 0x0108 +#define W_META_SETTEXTCOLOR 0x0209 +#define W_META_SETTEXTJUSTIFICATION 0x020A +#define W_META_SETWINDOWORG 0x020B +#define W_META_SETWINDOWEXT 0x020C +#define W_META_SETVIEWPORTORG 0x020D +#define W_META_SETVIEWPORTEXT 0x020E +#define W_META_OFFSETWINDOWORG 0x020F +#define W_META_SCALEWINDOWEXT 0x0410 +#define W_META_OFFSETVIEWPORTORG 0x0211 +#define W_META_SCALEVIEWPORTEXT 0x0412 +#define W_META_LINETO 0x0213 +#define W_META_MOVETO 0x0214 +#define W_META_EXCLUDECLIPRECT 0x0415 +#define W_META_INTERSECTCLIPRECT 0x0416 +#define W_META_ARC 0x0817 +#define W_META_ELLIPSE 0x0418 +#define W_META_FLOODFILL 0x0419 +#define W_META_PIE 0x081A +#define W_META_RECTANGLE 0x041B +#define W_META_ROUNDRECT 0x061C +#define W_META_PATBLT 0x061D +#define W_META_SAVEDC 0x001E +#define W_META_SETPIXEL 0x041F +#define W_META_OFFSETCLIPRGN 0x0220 +#define W_META_TEXTOUT 0x0521 +#define W_META_BITBLT 0x0922 +#define W_META_STRETCHBLT 0x0B23 +#define W_META_POLYGON 0x0324 +#define W_META_POLYLINE 0x0325 +#define W_META_ESCAPE 0x0626 +#define W_META_RESTOREDC 0x0127 +#define W_META_FILLREGION 0x0228 +#define W_META_FRAMEREGION 0x0429 +#define W_META_INVERTREGION 0x012A +#define W_META_PAINTREGION 0x012B +#define W_META_SELECTCLIPREGION 0x012C +#define W_META_SELECTOBJECT 0x012D +#define W_META_SETTEXTALIGN 0x012E +#define W_META_DRAWTEXT 0x062F +#define W_META_CHORD 0x0830 +#define W_META_SETMAPPERFLAGS 0x0231 +#define W_META_EXTTEXTOUT 0x0a32 +#define W_META_SETDIBTODEV 0x0d33 +#define W_META_SELECTPALETTE 0x0234 +#define W_META_REALIZEPALETTE 0x0035 +#define W_META_ANIMATEPALETTE 0x0436 +#define W_META_SETPALENTRIES 0x0037 +#define W_META_POLYPOLYGON 0x0538 +#define W_META_RESIZEPALETTE 0x0139 +#define W_META_DIBBITBLT 0x0940 +#define W_META_DIBSTRETCHBLT 0x0b41 +#define W_META_DIBCREATEPATTERNBRUSH 0x0142 +#define W_META_STRETCHDIB 0x0f43 +#define W_META_EXTFLOODFILL 0x0548 +#define W_META_RESETDC 0x014C +#define W_META_STARTDOC 0x014D +#define W_META_STARTPAGE 0x004F +#define W_META_ENDPAGE 0x0050 +#define W_META_ABORTDOC 0x0052 +#define W_META_ENDDOC 0x005E +#define W_META_DELETEOBJECT 0x01f0 +#define W_META_CREATEPALETTE 0x00f7 +#define W_META_CREATEBRUSH 0x00F8 +#define W_META_CREATEPATTERNBRUSH 0x01F9 +#define W_META_CREATEPENINDIRECT 0x02FA +#define W_META_CREATEFONTINDIRECT 0x02FB +#define W_META_CREATEBRUSHINDIRECT 0x02FC +#define W_META_CREATEBITMAPINDIRECT 0x02FD +#define W_META_CREATEBITMAP 0x06FE +#define W_META_CREATEREGION 0x06FF + +#define W_TRANSPARENT 1 +#define W_OPAQUE 2 + +#define W_R2_BLACK 1 +#define W_R2_NOTMERGEPEN 2 +#define W_R2_MASKNOTPEN 3 +#define W_R2_NOTCOPYPEN 4 +#define W_R2_MASKPENNOT 5 +#define W_R2_NOT 6 +#define W_R2_XORPEN 7 +#define W_R2_NOTMASKPEN 8 +#define W_R2_MASKPEN 9 +#define W_R2_NOTXORPEN 10 +#define W_R2_NOP 11 +#define W_R2_MERGENOTPEN 12 +#define W_R2_COPYPEN 13 +#define W_R2_MERGEPENNOT 14 +#define W_R2_MERGEPEN 15 +#define W_R2_WHITE 16 + +#define W_TA_NOUPDATECP 0x0000 +#define W_TA_UPDATECP 0x0001 +#define W_TA_LEFT 0x0000 +#define W_TA_RIGHT 0x0002 +#define W_TA_CENTER 0x0006 +#define W_TA_TOP 0x0000 +#define W_TA_BOTTOM 0x0008 +#define W_TA_BASELINE 0x0018 +#define W_TA_RTLREADING 0x0100 + +#define W_SRCCOPY 0x00CC0020L +#define W_SRCPAINT 0x00EE0086L +#define W_SRCAND 0x008800C6L +#define W_SRCINVERT 0x00660046L +#define W_SRCERASE 0x00440328L +#define W_NOTSRCCOPY 0x00330008L +#define W_NOTSRCERASE 0x001100A6L +#define W_MERGECOPY 0x00C000CAL +#define W_MERGEPAINT 0x00BB0226L +#define W_PATCOPY 0x00F00021L +#define W_PATPAINT 0x00FB0A09L +#define W_PATINVERT 0x005A0049L +#define W_DSTINVERT 0x00550009L +#define W_BLACKNESS 0x00000042L +#define W_WHITENESS 0x00FF0062L + +#define W_PS_SOLID 0 +#define W_PS_DASH 1 +#define W_PS_DOT 2 +#define W_PS_DASHDOT 3 +#define W_PS_DASHDOTDOT 4 +#define W_PS_NULL 5 +#define W_PS_INSIDEFRAME 6 + +#define W_LF_FACESIZE 32 + +#define W_ANSI_CHARSET 0 +#define W_DEFAULT_CHARSET 1 +#define W_SYMBOL_CHARSET 2 +#define W_SHIFTJIS_CHARSET 128 +#define W_HANGEUL_CHARSET 129 +#define W_GB2312_CHARSET 134 +#define W_CHINESEBIG5_CHARSET 136 +#define W_OEM_CHARSET 255 +/*WINVER >= 0x0400*/ +#define W_JOHAB_CHARSET 130 +#define W_HEBREW_CHARSET 177 +#define W_ARABIC_CHARSET 178 +#define W_GREEK_CHARSET 161 +#define W_TURKISH_CHARSET 162 +#define W_VIETNAMESE_CHARSET 163 +#define W_THAI_CHARSET 222 +#define W_EASTEUROPE_CHARSET 238 +#define W_RUSSIAN_CHARSET 204 +#define W_MAC_CHARSET 77 +#define W_BALTIC_CHARSET 186 + +#define W_DEFAULT_PITCH 0x00 +#define W_FIXED_PITCH 0x01 +#define W_VARIABLE_PITCH 0x02 + +#define W_FF_DONTCARE 0x00 +#define W_FF_ROMAN 0x10 +#define W_FF_SWISS 0x20 +#define W_FF_MODERN 0x30 +#define W_FF_SCRIPT 0x40 +#define W_FF_DECORATIVE 0x50 + +#define W_FW_DONTCARE 0 +#define W_FW_THIN 100 +#define W_FW_EXTRALIGHT 200 +#define W_FW_LIGHT 300 +#define W_FW_NORMAL 400 +#define W_FW_MEDIUM 500 +#define W_FW_SEMIBOLD 600 +#define W_FW_BOLD 700 +#define W_FW_EXTRABOLD 800 +#define W_FW_HEAVY 900 +#define W_FW_ULTRALIGHT 200 +#define W_FW_REGULAR 400 +#define W_FW_DEMIBOLD 600 +#define W_FW_ULTRABOLD 800 +#define W_FW_BLACK 900 + +#define W_BS_SOLID 0 +#define W_BS_HOLLOW 1 +#define W_BS_HATCHED 2 +#define W_BS_PATTERN 3 +#define W_BS_INDEXED 4 +#define W_BS_DIBPATTERN 5 + +#define W_HS_HORIZONTAL 0 +#define W_HS_VERTICAL 1 +#define W_HS_FDIAGONAL 2 +#define W_HS_BDIAGONAL 3 +#define W_HS_CROSS 4 +#define W_HS_DIAGCROSS 5 + +#define W_MFCOMMENT 15 + +#define PRIVATE_ESCAPE_UNICODE 2 + +/// copied from writerwordglue.cxx + +/* + Utility to categorize unicode characters into the best fit windows charset + range for exporting to ww6, or as a hint to non \u unicode token aware rtf + readers +*/ +rtl_TextEncoding getScriptClass(sal_Unicode cChar) +{ + using namespace com::sun::star::i18n; + + static ScriptTypeList aScripts[] = + { + { UnicodeScript_kBasicLatin, UnicodeScript_kBasicLatin, RTL_TEXTENCODING_MS_1252}, + { UnicodeScript_kLatin1Supplement, UnicodeScript_kLatin1Supplement, RTL_TEXTENCODING_MS_1252}, + { UnicodeScript_kLatinExtendedA, UnicodeScript_kLatinExtendedA, RTL_TEXTENCODING_MS_1250}, + { UnicodeScript_kLatinExtendedB, UnicodeScript_kLatinExtendedB, RTL_TEXTENCODING_MS_1257}, + { UnicodeScript_kGreek, UnicodeScript_kGreek, RTL_TEXTENCODING_MS_1253}, + { UnicodeScript_kCyrillic, UnicodeScript_kCyrillic, RTL_TEXTENCODING_MS_1251}, + { UnicodeScript_kHebrew, UnicodeScript_kHebrew, RTL_TEXTENCODING_MS_1255}, + { UnicodeScript_kArabic, UnicodeScript_kArabic, RTL_TEXTENCODING_MS_1256}, + { UnicodeScript_kThai, UnicodeScript_kThai, RTL_TEXTENCODING_MS_1258}, + { UnicodeScript_kScriptCount, UnicodeScript_kScriptCount, RTL_TEXTENCODING_MS_1252} + }; + return unicode::getUnicodeScriptType(cChar, aScripts, + RTL_TEXTENCODING_MS_1252); +} + +//========================== Methoden von WMFWriter ========================== + +void WMFWriter::MayCallback() +{ + if ( xStatusIndicator.is() ) + { + ULONG nPercent; + + // Wir gehen mal einfach so davon aus, dass 16386 Actions einer Bitmap entsprechen + // (in der Regel wird ein Metafile entweder nur Actions oder einige Bitmaps und fast + // keine Actions enthalten. Dann ist das Verhaeltnis ziemlich unwichtig) + + nPercent=((nWrittenBitmaps<<14)+(nActBitmapPercent<<14)/100+nWrittenActions) + *100 + /((nNumberOfBitmaps<<14)+nNumberOfActions); + + if ( nPercent >= nLastPercent + 3 ) + { + nLastPercent = nPercent; + if( nPercent <= 100 ) + xStatusIndicator->setValue( nPercent ); + } + } +} + +void WMFWriter::CountActionsAndBitmaps( const GDIMetaFile & rMTF ) +{ + ULONG nAction, nActionCount; + + nActionCount = rMTF.GetActionCount(); + + for ( nAction=0; nActionGetType() ) + { + case META_BMP_ACTION: + case META_BMPSCALE_ACTION: + case META_BMPSCALEPART_ACTION: + case META_BMPEX_ACTION: + case META_BMPEXSCALE_ACTION: + case META_BMPEXSCALEPART_ACTION: + case META_RENDERGRAPHIC_ACTION: + nNumberOfBitmaps++; + break; + } + nNumberOfActions++; + } +} + + +void WMFWriter::WritePointXY(const Point & rPoint) +{ + Point aPt( pVirDev->LogicToLogic(rPoint,aSrcMapMode,aTargetMapMode) ); + *pWMF << ((short)aPt.X()) << ((short)aPt.Y()); +} + + +void WMFWriter::WritePointYX(const Point & rPoint) +{ + Point aPt( pVirDev->LogicToLogic(rPoint,aSrcMapMode,aTargetMapMode) ); + *pWMF << ((short)aPt.Y()) << ((short)aPt.X()); +} + + +sal_Int32 WMFWriter::ScaleWidth( sal_Int32 nDX ) +{ + Size aSz( pVirDev->LogicToLogic(Size(nDX,0),aSrcMapMode,aTargetMapMode) ); + return aSz.Width(); +} + + +void WMFWriter::WriteSize(const Size & rSize) +{ + Size aSz( pVirDev->LogicToLogic(rSize,aSrcMapMode,aTargetMapMode) ); + *pWMF << ((short)aSz.Width()) << ((short)aSz.Height()); +} + + +void WMFWriter::WriteHeightWidth(const Size & rSize) +{ + Size aSz( pVirDev->LogicToLogic(rSize,aSrcMapMode,aTargetMapMode) ); + *pWMF << ((short)aSz.Height()) << ((short)aSz.Width()); +} + + +void WMFWriter::WriteRectangle(const Rectangle & rRect) +{ + WritePointYX(Point(rRect.Right()+1,rRect.Bottom()+1)); + WritePointYX(rRect.TopLeft()); +} + + +void WMFWriter::WriteColor(const Color & rColor) +{ + *pWMF << (BYTE) rColor.GetRed() << (BYTE) rColor.GetGreen() << (BYTE) rColor.GetBlue() << (BYTE) 0; +} + + +void WMFWriter::WriteRecordHeader(sal_uInt32 nSizeWords, sal_uInt16 nType) +{ + nActRecordPos=pWMF->Tell(); + if (nSizeWords>nMaxRecordSize) nMaxRecordSize=nSizeWords; + *pWMF << nSizeWords << nType; +} + + +void WMFWriter::UpdateRecordHeader() +{ + ULONG nPos; + sal_uInt32 nSize; + + nPos=pWMF->Tell(); nSize=nPos-nActRecordPos; + if ((nSize & 1)!=0) { + *pWMF << (BYTE)0; + nPos++; nSize++; + } + nSize/=2; + if (nSize>nMaxRecordSize) nMaxRecordSize=nSize; + pWMF->Seek(nActRecordPos); + *pWMF << nSize; + pWMF->Seek(nPos); +} + + +void WMFWriter::WMFRecord_Arc(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt) +{ + WriteRecordHeader(0x0000000b,W_META_ARC); + WritePointYX(rEndPt); + WritePointYX(rStartPt); + WriteRectangle(rRect); +} + +void WMFWriter::WMFRecord_Chord(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt) +{ + WriteRecordHeader(0x0000000b,W_META_CHORD); + WritePointYX(rEndPt); + WritePointYX(rStartPt); + WriteRectangle(rRect); +} + + +void WMFWriter::WMFRecord_CreateBrushIndirect(const Color& rColor) +{ + WriteRecordHeader(0x00000007,W_META_CREATEBRUSHINDIRECT); + + if( rColor==Color(COL_TRANSPARENT) ) + *pWMF << (UINT16) W_BS_HOLLOW; + else + *pWMF << (UINT16) W_BS_SOLID; + + WriteColor( rColor ); + *pWMF << (UINT16) 0; +} + + +void WMFWriter::WMFRecord_CreateFontIndirect(const Font & rFont) +{ + USHORT nWeight,i; + BYTE nPitchFamily; + + WriteRecordHeader(0x00000000,W_META_CREATEFONTINDIRECT); + WriteHeightWidth(Size(rFont.GetSize().Width(),-rFont.GetSize().Height())); + *pWMF << (short)rFont.GetOrientation() << (short)rFont.GetOrientation(); + + switch (rFont.GetWeight()) { + case WEIGHT_THIN: nWeight=W_FW_THIN; break; + case WEIGHT_ULTRALIGHT: nWeight=W_FW_ULTRALIGHT; break; + case WEIGHT_LIGHT: nWeight=W_FW_LIGHT; break; + case WEIGHT_SEMILIGHT: nWeight=W_FW_LIGHT; break; + case WEIGHT_NORMAL: nWeight=W_FW_NORMAL; break; + case WEIGHT_MEDIUM: nWeight=W_FW_MEDIUM; break; + case WEIGHT_SEMIBOLD: nWeight=W_FW_SEMIBOLD; break; + case WEIGHT_BOLD: nWeight=W_FW_BOLD; break; + case WEIGHT_ULTRABOLD: nWeight=W_FW_ULTRABOLD; break; + case WEIGHT_BLACK: nWeight=W_FW_BLACK; break; + default: nWeight=W_FW_DONTCARE; + } + *pWMF << nWeight; + + if (rFont.GetItalic()==ITALIC_NONE) *pWMF << (BYTE)0; else *pWMF << (BYTE)1; + if (rFont.GetUnderline()==UNDERLINE_NONE) *pWMF << (BYTE)0; else *pWMF << (BYTE)1; + if (rFont.GetStrikeout()==STRIKEOUT_NONE) *pWMF << (BYTE)0; else *pWMF << (BYTE)1; + + CharSet eFontNameEncoding = rFont.GetCharSet(); + sal_uInt8 nCharSet = rtl_getBestWindowsCharsetFromTextEncoding( eFontNameEncoding ); + if ( eFontNameEncoding == RTL_TEXTENCODING_SYMBOL ) + eFontNameEncoding = RTL_TEXTENCODING_MS_1252; + if ( nCharSet == 1 ) + nCharSet = W_ANSI_CHARSET; + *pWMF << nCharSet; + + *pWMF << (BYTE)0 << (BYTE)0 << (BYTE)0; + + switch (rFont.GetPitch()) { + case PITCH_FIXED: nPitchFamily=W_FIXED_PITCH; break; + case PITCH_VARIABLE: nPitchFamily=W_VARIABLE_PITCH; break; + default: nPitchFamily=W_DEFAULT_PITCH; + } + switch (rFont.GetFamily()) { + case FAMILY_DECORATIVE: nPitchFamily|=W_FF_DECORATIVE; break; + case FAMILY_MODERN: nPitchFamily|=W_FF_MODERN; break; + case FAMILY_ROMAN: nPitchFamily|=W_FF_ROMAN; break; + case FAMILY_SCRIPT: nPitchFamily|=W_FF_SCRIPT; break; + case FAMILY_SWISS: nPitchFamily|=W_FF_SWISS; break; + default: nPitchFamily|=W_FF_DONTCARE; + } + *pWMF << nPitchFamily; + + ByteString aFontName( rFont.GetName(), eFontNameEncoding ); + for ( i = 0; i < W_LF_FACESIZE; i++ ) + { + sal_Char nChar = ( i < aFontName.Len() ) ? aFontName.GetChar( i ) : 0; + *pWMF << nChar; + } + UpdateRecordHeader(); +} + +void WMFWriter::WMFRecord_CreatePenIndirect(const Color& rColor, const LineInfo& rLineInfo ) +{ + WriteRecordHeader(0x00000008,W_META_CREATEPENINDIRECT); + USHORT nStyle = rColor == Color( COL_TRANSPARENT ) ? W_PS_NULL : W_PS_SOLID; + switch( rLineInfo.GetStyle() ) + { + case LINE_DASH : + { + if ( rLineInfo.GetDotCount() ) + { + if ( !rLineInfo.GetDashCount() ) + nStyle = W_PS_DOT; + else + { + if ( !rLineInfo.GetDotCount() == 1 ) + nStyle = W_PS_DASHDOT; + else + nStyle = W_PS_DASHDOTDOT; + } + } + else + nStyle = W_PS_DASH; + } + break; + case LINE_NONE : + nStyle = W_PS_NULL; + break; + default: + break; + } + *pWMF << nStyle; + + WriteSize( Size( rLineInfo.GetWidth(), 0 ) ); + WriteColor( rColor ); +} + +void WMFWriter::WMFRecord_DeleteObject(USHORT nObjectHandle) +{ + WriteRecordHeader(0x00000004,W_META_DELETEOBJECT); + *pWMF << nObjectHandle; +} + + +void WMFWriter::WMFRecord_Ellipse(const Rectangle & rRect) +{ + WriteRecordHeader(0x00000007,W_META_ELLIPSE); + WriteRectangle(rRect); +} + +bool IsStarSymbol(const String &rStr) +{ + return rStr.EqualsIgnoreCaseAscii("starsymbol") || + rStr.EqualsIgnoreCaseAscii("opensymbol"); +} + +void WMFWriter::WMFRecord_Escape( sal_uInt32 nEsc, sal_uInt32 nLen, const sal_Int8* pData ) +{ +#ifdef OSL_BIGENDIAN + sal_uInt32 nTmp = SWAPLONG( nEsc ); + sal_uInt32 nCheckSum = rtl_crc32( 0, &nTmp, 4 ); +#else + sal_uInt32 nCheckSum = rtl_crc32( 0, &nEsc, 4 ); +#endif + if ( nLen ) + nCheckSum = rtl_crc32( nCheckSum, pData, nLen ); + + WriteRecordHeader( 3 + 9 + ( ( nLen + 1 ) >> 1 ), W_META_ESCAPE ); + *pWMF << (sal_uInt16)W_MFCOMMENT + << (sal_uInt16)( nLen + 14 ) // we will always have a fourteen byte escape header: + << (sal_uInt16)0x4f4f // OO + << (sal_uInt32)0xa2c2a // evil magic number + << (sal_uInt32)nCheckSum // crc32 checksum about nEsc & pData + << (sal_uInt32)nEsc; // escape number + pWMF->Write( pData, nLen ); + if ( nLen & 1 ) + *pWMF << (sal_uInt8)0; // pad byte +} + +/* if return value is true, then a complete unicode string and also a polygon replacement has been written, + so there is no more action necessary +*/ +sal_Bool WMFWriter::WMFRecord_Escape_Unicode( const Point& rPoint, const String& rUniStr, const sal_Int32* pDXAry ) +{ + sal_Bool bEscapeUsed = sal_False; + + sal_uInt32 i, nStringLen = rUniStr.Len(); + if ( nStringLen ) + { + // first we will check if a comment is necessary + if ( aSrcFont.GetCharSet() != RTL_TEXTENCODING_SYMBOL ) // symbol is always byte character, so there is no unicode loss + { + const sal_Unicode* pBuf = rUniStr.GetBuffer(); + const rtl_TextEncoding aTextEncodingOrg = aSrcFont.GetCharSet(); + ByteString aByteStr( rUniStr, aTextEncodingOrg ); + String aUniStr2( aByteStr, aTextEncodingOrg ); + const sal_Unicode* pConversion = aUniStr2.GetBuffer(); // this is the unicode array after bytestring <-> unistring conversion + for ( i = 0; i < nStringLen; i++ ) + { + if ( *pBuf++ != *pConversion++ ) + break; + } + + if ( i != nStringLen ) // after conversion the characters are not original, + { // try again, with determining a better charset from unicode char + pBuf = rUniStr.GetBuffer(); + const sal_Unicode* pCheckChar = pBuf; + rtl_TextEncoding aTextEncoding = getScriptClass (*pCheckChar); // try the first character + for ( i = 1; i < nStringLen; i++) + { + if (aTextEncoding != aTextEncodingOrg) // found something + break; + pCheckChar++; + aTextEncoding = getScriptClass (*pCheckChar); // try the next character + } + + aByteStr = ByteString ( rUniStr, aTextEncoding ); + aUniStr2 = String ( aByteStr, aTextEncoding ); + pConversion = aUniStr2.GetBuffer(); // this is the unicode array after bytestring <-> unistring conversion + for ( i = 0; i < nStringLen; i++ ) + { + if ( *pBuf++ != *pConversion++ ) + break; + } + if (i == nStringLen) + { + aSrcFont.SetCharSet (aTextEncoding); + SetAllAttr(); + } + } + + if ( ( i != nStringLen ) || IsStarSymbol( aSrcFont.GetName() ) ) // after conversion the characters are not original, so we + { // will store the unicode string and a polypoly replacement + Color aOldFillColor( aSrcFillColor ); + Color aOldLineColor( aSrcLineColor ); + aSrcLineInfo = LineInfo(); + aSrcFillColor = aSrcTextColor; + aSrcLineColor = Color( COL_TRANSPARENT ); + SetLineAndFillAttr(); + pVirDev->SetFont( aSrcFont ); + std::vector aPolyPolyVec; + if ( pVirDev->GetTextOutlines( aPolyPolyVec, rUniStr ) ) + { + sal_uInt32 nDXCount = pDXAry ? nStringLen : 0; + sal_uInt32 nSkipActions = aPolyPolyVec.size(); + sal_Int32 nStrmLen = 8 + + + sizeof( nStringLen ) + ( nStringLen * 2 ) + + sizeof( nDXCount ) + ( nDXCount * 4 ) + + sizeof( nSkipActions ); + + SvMemoryStream aMemoryStream( nStrmLen ); + Point aPt( pVirDev->LogicToLogic( rPoint, aSrcMapMode, aTargetMapMode ) ); + aMemoryStream << aPt.X() + << aPt.Y() + << nStringLen; + for ( i = 0; i < nStringLen; i++ ) + aMemoryStream << rUniStr.GetChar( (sal_uInt16)i ); + aMemoryStream << nDXCount; + for ( i = 0; i < nDXCount; i++ ) + aMemoryStream << pDXAry[ i ]; + aMemoryStream << nSkipActions; + WMFRecord_Escape( PRIVATE_ESCAPE_UNICODE, nStrmLen, (const sal_Int8*)aMemoryStream.GetData() ); + + std::vector::iterator aIter( aPolyPolyVec.begin() ); + while ( aIter != aPolyPolyVec.end() ) + { + PolyPolygon aPolyPoly( *aIter++ ); + aPolyPoly.Move( rPoint.X(), rPoint.Y() ); + WMFRecord_PolyPolygon( aPolyPoly ); + } + aSrcFillColor = aOldFillColor; + aSrcLineColor = aOldLineColor; + bEscapeUsed = sal_True; + } + } + } + } + return bEscapeUsed; +} + +void WMFWriter::WMFRecord_ExtTextOut( const Point & rPoint, + const String & rString, const sal_Int32 * pDXAry ) +{ + sal_uInt16 nOriginalTextLen = rString.Len(); + + if ( (nOriginalTextLen <= 1) || (pDXAry == NULL) ) + { + WMFRecord_TextOut(rPoint, rString); + return; + } + rtl_TextEncoding eChrSet = aSrcFont.GetCharSet(); + ByteString aByteString(rString, eChrSet); + TrueExtTextOut(rPoint,rString,aByteString,pDXAry); +} + +void WMFWriter::TrueExtTextOut( const Point & rPoint, const String & rString, + const ByteString & rByteString, const sal_Int32 * pDXAry ) +{ + WriteRecordHeader( 0, W_META_EXTTEXTOUT ); + WritePointYX( rPoint ); + sal_uInt16 nNewTextLen = rByteString.Len(); + *pWMF << nNewTextLen << (sal_uInt16)0; + + sal_uInt16 i; + for ( i = 0; i < nNewTextLen; i++ ) + *pWMF << (sal_uInt8)rByteString.GetChar( i ); + if ( nNewTextLen & 1 ) + *pWMF << (sal_uInt8)0; + + sal_uInt16 nOriginalTextLen = rString.Len(); + sal_Int16* pConvertedDXAry = new sal_Int16[ nOriginalTextLen ]; + sal_Int32 j = 0; + pConvertedDXAry[ j++ ] = (sal_Int16)ScaleWidth( pDXAry[ 0 ] ); + for ( i = 1; i < ( nOriginalTextLen - 1 ); i++ ) + pConvertedDXAry[ j++ ] = (sal_Int16)ScaleWidth( pDXAry[ i ] - pDXAry[ i - 1 ] ); + pConvertedDXAry[ j ] = (sal_Int16)ScaleWidth( pDXAry[ nOriginalTextLen - 2 ] / ( nOriginalTextLen - 1 ) ); + + for ( i = 0; i < nOriginalTextLen; i++ ) + { + sal_Int16 nDx = pConvertedDXAry[ i ]; + *pWMF << nDx; + if ( nOriginalTextLen < nNewTextLen ) + { + ByteString aTemp( rString.GetChar( i ), aSrcFont.GetCharSet()); + j = aTemp.Len(); + while ( --j > 0 ) + *pWMF << (sal_uInt16)0; + } + } + delete[] pConvertedDXAry; + UpdateRecordHeader(); +} + +void WMFWriter::WMFRecord_LineTo(const Point & rPoint) +{ + WriteRecordHeader(0x00000005,W_META_LINETO); + WritePointYX(rPoint); +} + + +void WMFWriter::WMFRecord_MoveTo(const Point & rPoint) +{ + WriteRecordHeader(0x00000005,W_META_MOVETO); + WritePointYX(rPoint); +} + + +void WMFWriter::WMFRecord_Pie(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt) +{ + WriteRecordHeader(0x0000000b,W_META_PIE); + WritePointYX(rEndPt); + WritePointYX(rStartPt); + WriteRectangle(rRect); +} + + +void WMFWriter::WMFRecord_Polygon(const Polygon & rPoly) +{ + USHORT nSize,i; + + Polygon aSimplePoly; + if ( rPoly.HasFlags() ) + rPoly.AdaptiveSubdivide( aSimplePoly ); + else + aSimplePoly = rPoly; + nSize = aSimplePoly.GetSize(); + WriteRecordHeader(((ULONG)nSize)*2+4,W_META_POLYGON); + *pWMF << nSize; + for (i=0; iGetSize(); + for (j=0; jGetPoint(j)); + } + UpdateRecordHeader(); +} + + +void WMFWriter::WMFRecord_Rectangle(const Rectangle & rRect) +{ + WriteRecordHeader( 0x00000007,W_META_RECTANGLE ); + WriteRectangle( rRect ); +} + + +void WMFWriter::WMFRecord_RestoreDC() +{ + WriteRecordHeader(0x00000004,W_META_RESTOREDC); + *pWMF << (short)-1; +} + + +void WMFWriter::WMFRecord_RoundRect(const Rectangle & rRect, long nHorzRound, long nVertRound) +{ + WriteRecordHeader(0x00000009,W_META_ROUNDRECT); + WriteHeightWidth(Size(nHorzRound,nVertRound)); + WriteRectangle(rRect); +} + + +void WMFWriter::WMFRecord_SaveDC() +{ + WriteRecordHeader(0x00000003,W_META_SAVEDC); +} + + +void WMFWriter::WMFRecord_SelectObject(USHORT nObjectHandle) +{ + WriteRecordHeader(0x00000004,W_META_SELECTOBJECT); + *pWMF << nObjectHandle; +} + + +void WMFWriter::WMFRecord_SetBkColor(const Color & rColor) +{ + WriteRecordHeader(0x00000005,W_META_SETBKCOLOR); + WriteColor(rColor); +} + + +void WMFWriter::WMFRecord_SetBkMode(BOOL bTransparent) +{ + WriteRecordHeader(0x00000004,W_META_SETBKMODE); + if (bTransparent==TRUE) *pWMF << (USHORT)W_TRANSPARENT; + else *pWMF << (USHORT)W_OPAQUE; +} + +void WMFWriter::WMFRecord_SetStretchBltMode() +{ + WriteRecordHeader( 0x00000004, W_META_SETSTRETCHBLTMODE ); + *pWMF << (USHORT) 3; // STRETCH_DELETESCANS +} + +void WMFWriter::WMFRecord_SetPixel(const Point & rPoint, const Color & rColor) +{ + WriteRecordHeader(0x00000007,W_META_SETPIXEL); + WriteColor(rColor); + WritePointYX(rPoint); +} + + +void WMFWriter::WMFRecord_SetROP2(RasterOp eROP) +{ + USHORT nROP2; + + switch (eROP) { + case ROP_INVERT: nROP2=W_R2_NOT; break; + case ROP_XOR: nROP2=W_R2_XORPEN; break; + default: nROP2=W_R2_COPYPEN; + } + WriteRecordHeader(0x00000004,W_META_SETROP2); + *pWMF << nROP2; +} + + +void WMFWriter::WMFRecord_SetTextAlign(FontAlign eFontAlign, UINT32 eHorTextAlign) +{ + USHORT nAlign; + + switch (eFontAlign) { + case ALIGN_TOP: nAlign=W_TA_TOP; break; + case ALIGN_BOTTOM: nAlign=W_TA_BOTTOM; break; + default: nAlign=W_TA_BASELINE; + } + nAlign|=eHorTextAlign; + nAlign|=W_TA_NOUPDATECP; + + WriteRecordHeader(0x00000004,W_META_SETTEXTALIGN); + *pWMF << nAlign; +} + + +void WMFWriter::WMFRecord_SetTextColor(const Color & rColor) +{ + WriteRecordHeader(0x00000005,W_META_SETTEXTCOLOR); + WriteColor(rColor); +} + + +void WMFWriter::WMFRecord_SetWindowExt(const Size & rSize) +{ + WriteRecordHeader(0x00000005,W_META_SETWINDOWEXT); + WriteHeightWidth(rSize); +} + + +void WMFWriter::WMFRecord_SetWindowOrg(const Point & rPoint) +{ + WriteRecordHeader(0x00000005,W_META_SETWINDOWORG); + WritePointYX(rPoint); +} + + +void WMFWriter::WMFRecord_StretchDIB( const Point & rPoint, const Size & rSize, + const Bitmap & rBitmap, sal_uInt32 nROP ) +{ + ULONG nPosAnf,nPosEnd; + + nActBitmapPercent=50; + MayCallback(); + + WriteRecordHeader(0x00000000,W_META_STRETCHDIB); + + // Die Reihenfolge im Metafile soll jetzt sein: + // einige Parameter (laenge 22), dann die Bitmap ohne FILEHEADER. + // Da aber *pWMF << rBitmap einen FILEHEADER der Laenge 14 + // erzeugt, schreiben wir zuerst die Bitmap an die richtige Position + // Und ueberschreiben hinterher den FILEHEADER mit den Parametern. + nPosAnf=pWMF->Tell(); // Position merken, wo Parameter hin sollen + *pWMF << (long)0 << (long)0; // 8 bytes auffuellen (diese 8 bytes + + // 14 bytes ueberfluessigen FILEHEADER + // = 22 bytes Parameter) + *pWMF << rBitmap; // Bitmap schreiben + + // Parameter schreiben: + nPosEnd=pWMF->Tell(); + pWMF->Seek(nPosAnf); + + // Raster-Op bestimmen, falls nichts uebergeben wurde + if( !nROP ) + { + switch( eSrcRasterOp ) + { + case ROP_INVERT: nROP = W_DSTINVERT; break; + case ROP_XOR: nROP = W_SRCINVERT; break; + default: nROP = W_SRCCOPY; + } + } + + *pWMF << nROP << + (short) 0 << + (short) rBitmap.GetSizePixel().Height() << + (short) rBitmap.GetSizePixel().Width() << + (short) 0 << + (short) 0; + + WriteHeightWidth(rSize); + WritePointYX(rPoint); + pWMF->Seek(nPosEnd); + + UpdateRecordHeader(); + + nWrittenBitmaps++; + nActBitmapPercent=0; +} + + +void WMFWriter::WMFRecord_TextOut(const Point & rPoint, const String & rStr) +{ + rtl_TextEncoding eChrSet = aSrcFont.GetCharSet(); + ByteString aString( rStr, eChrSet ); + TrueTextOut(rPoint, aString); +} + +void WMFWriter::TrueTextOut(const Point & rPoint, const ByteString& rString) +{ + USHORT nLen,i; + + WriteRecordHeader(0,W_META_TEXTOUT); + nLen=rString.Len(); + *pWMF << nLen; + for ( i = 0; i < nLen; i++ ) + *pWMF << (BYTE)rString.GetChar( i ); + if ((nLen&1)!=0) *pWMF << (BYTE)0; + WritePointYX(rPoint); + UpdateRecordHeader(); +} + +void WMFWriter::WMFRecord_EndOfFile() +{ + WriteRecordHeader(0x00000003,0x0000); +} + + +void WMFWriter::WMFRecord_IntersectClipRect( const Rectangle& rRect ) +{ + WriteRecordHeader( 0x00000007, W_META_INTERSECTCLIPRECT ); + WriteRectangle(rRect); +} + + +USHORT WMFWriter::AllocHandle() +{ + USHORT i; + + for (i=0; iSetFont(aSrcFont); + if ( aDstFont.GetName() != aSrcFont.GetName() ) + { + FontCharMap aFontCharMap; + if ( pVirDev->GetFontCharMap( aFontCharMap ) ) + { + if ( ( aFontCharMap.GetFirstChar() & 0xff00 ) == 0xf000 ) + aSrcFont.SetCharSet( RTL_TEXTENCODING_SYMBOL ); + else if ( aSrcFont.GetCharSet() == RTL_TEXTENCODING_SYMBOL ) + aSrcFont.SetCharSet( RTL_TEXTENCODING_MS_1252 ); + } + } + aDstFont = aSrcFont; + CreateSelectDeleteFont(aDstFont); + } +} + + +void WMFWriter::HandleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon) +{ + if(rLinePolygon.count()) + { + basegfx::B2DPolyPolygon aLinePolyPolygon(rLinePolygon); + basegfx::B2DPolyPolygon aFillPolyPolygon; + + rInfo.applyToB2DPolyPolygon(aLinePolyPolygon, aFillPolyPolygon); + + if(aLinePolyPolygon.count()) + { + aSrcLineInfo = rInfo; + SetLineAndFillAttr(); + + for(sal_uInt32 a(0); a < aLinePolyPolygon.count(); a++) + { + const basegfx::B2DPolygon aCandidate(aLinePolyPolygon.getB2DPolygon(a)); + WMFRecord_PolyLine(Polygon(aCandidate)); + } + } + + if(aFillPolyPolygon.count()) + { + const Color aOldLineColor(aSrcLineColor); + const Color aOldFillColor(aSrcFillColor); + + aSrcLineColor = Color( COL_TRANSPARENT ); + aSrcFillColor = aOldLineColor; + SetLineAndFillAttr(); + + for(sal_uInt32 a(0); a < aFillPolyPolygon.count(); a++) + { + const Polygon aPolygon(aFillPolyPolygon.getB2DPolygon(a)); + WMFRecord_Polygon(Polygon(aPolygon)); + } + + aSrcLineColor = aOldLineColor; + aSrcFillColor = aOldFillColor; + SetLineAndFillAttr(); + } + } +} + +void WMFWriter::WriteRecords( const GDIMetaFile & rMTF ) +{ + ULONG nA, nACount; + MetaAction* pMA; + + if( bStatus ) + { + nACount = rMTF.GetActionCount(); + + WMFRecord_SetStretchBltMode(); + + for( nA=0; nAGetType() ) + { + case META_PIXEL_ACTION: + { + const MetaPixelAction* pA = (const MetaPixelAction *) pMA; + aSrcLineInfo = LineInfo(); + SetLineAndFillAttr(); + WMFRecord_SetPixel( pA->GetPoint(), pA->GetColor() ); + } + break; + + case META_POINT_ACTION: + { + const MetaPointAction* pA = (const MetaPointAction*) pMA; + const Point& rPt = pA->GetPoint(); + aSrcLineInfo = LineInfo(); + SetLineAndFillAttr(); + WMFRecord_MoveTo( rPt); + WMFRecord_LineTo( rPt ); + } + break; + + case META_LINE_ACTION: + { + const MetaLineAction* pA = (const MetaLineAction *) pMA; + if(pA->GetLineInfo().IsDefault()) + { + aSrcLineInfo = pA->GetLineInfo(); + SetLineAndFillAttr(); + WMFRecord_MoveTo( pA->GetStartPoint() ); + WMFRecord_LineTo( pA->GetEndPoint() ); + } + else + { + // LineInfo used; handle Dash/Dot and fat lines + basegfx::B2DPolygon aPolygon; + aPolygon.append(basegfx::B2DPoint(pA->GetStartPoint().X(), pA->GetStartPoint().Y())); + aPolygon.append(basegfx::B2DPoint(pA->GetEndPoint().X(), pA->GetEndPoint().Y())); + HandleLineInfoPolyPolygons(pA->GetLineInfo(), aPolygon); + } + } + break; + + case META_RECT_ACTION: + { + const MetaRectAction* pA = (const MetaRectAction*) pMA; + aSrcLineInfo = LineInfo(); + SetLineAndFillAttr(); + WMFRecord_Rectangle( pA->GetRect() ); + } + break; + + case META_ROUNDRECT_ACTION: + { + const MetaRoundRectAction* pA = (const MetaRoundRectAction*) pMA; + aSrcLineInfo = LineInfo(); + SetLineAndFillAttr(); + WMFRecord_RoundRect( pA->GetRect(), pA->GetHorzRound(), pA->GetVertRound() ); + } + break; + + case META_ELLIPSE_ACTION: + { + const MetaEllipseAction* pA = (const MetaEllipseAction*) pMA; + aSrcLineInfo = LineInfo(); + SetLineAndFillAttr(); + WMFRecord_Ellipse( pA->GetRect() ); + } + break; + + case META_ARC_ACTION: + { + const MetaArcAction* pA = (const MetaArcAction*) pMA; + aSrcLineInfo = LineInfo(); + SetLineAndFillAttr(); + WMFRecord_Arc( pA->GetRect(),pA->GetStartPoint(),pA->GetEndPoint() ); + } + break; + + case META_PIE_ACTION: + { + const MetaPieAction* pA = (const MetaPieAction*) pMA; + aSrcLineInfo = LineInfo(); + SetLineAndFillAttr(); + WMFRecord_Pie( pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint() ); + } + break; + + + case META_CHORD_ACTION: + { + const MetaChordAction* pA = (const MetaChordAction*) pMA; + aSrcLineInfo = LineInfo(); + SetLineAndFillAttr(); + WMFRecord_Chord( pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint() ); + } + break; + + case META_POLYLINE_ACTION: + { + const MetaPolyLineAction* pA = (const MetaPolyLineAction*) pMA; + const Polygon& rPoly = pA->GetPolygon(); + + if( rPoly.GetSize() ) + { + if(pA->GetLineInfo().IsDefault()) + { + aSrcLineInfo = pA->GetLineInfo(); + SetLineAndFillAttr(); + WMFRecord_PolyLine( rPoly ); + } + else + { + // LineInfo used; handle Dash/Dot and fat lines + HandleLineInfoPolyPolygons(pA->GetLineInfo(), rPoly.getB2DPolygon()); + } + } + } + break; + + case META_POLYGON_ACTION: + { + const MetaPolygonAction* pA = (const MetaPolygonAction*) pMA; + aSrcLineInfo = LineInfo(); + SetLineAndFillAttr(); + WMFRecord_Polygon( pA->GetPolygon() ); + } + break; + + case META_POLYPOLYGON_ACTION: + { + const MetaPolyPolygonAction* pA = (const MetaPolyPolygonAction*) pMA; + aSrcLineInfo = LineInfo(); + SetLineAndFillAttr(); + WMFRecord_PolyPolygon( pA->GetPolyPolygon() ); + } + break; + + case META_TEXTRECT_ACTION: + { + const MetaTextRectAction * pA = (const MetaTextRectAction*)pMA; + String aTemp( pA->GetText() ); + aSrcLineInfo = LineInfo(); + SetAllAttr(); + + Point aPos( pA->GetRect().TopLeft() ); + if ( !WMFRecord_Escape_Unicode( aPos, aTemp, NULL ) ) + WMFRecord_TextOut( aPos, aTemp ); + } + break; + + case META_TEXT_ACTION: + { + const MetaTextAction * pA = (const MetaTextAction*) pMA; + String aTemp( pA->GetText(), pA->GetIndex(), pA->GetLen() ); + aSrcLineInfo = LineInfo(); + SetAllAttr(); + if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, NULL ) ) + WMFRecord_TextOut( pA->GetPoint(), aTemp ); + } + break; + + case META_TEXTARRAY_ACTION: + { + const MetaTextArrayAction* pA = (const MetaTextArrayAction*) pMA; + + String aTemp( pA->GetText(), pA->GetIndex(), pA->GetLen() ); + aSrcLineInfo = LineInfo(); + SetAllAttr(); + if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, pA->GetDXArray() ) ) + WMFRecord_ExtTextOut( pA->GetPoint(), aTemp, pA->GetDXArray() ); + } + break; + + case META_STRETCHTEXT_ACTION: + { + const MetaStretchTextAction* pA = (const MetaStretchTextAction *) pMA; + String aTemp( pA->GetText(), pA->GetIndex(), pA->GetLen() ); + + sal_uInt16 nLen,i; + sal_Int32 nNormSize; + + pVirDev->SetFont( aSrcFont ); + nLen = aTemp.Len(); + sal_Int32* pDXAry = nLen ? new sal_Int32[ nLen ] : NULL; + nNormSize = pVirDev->GetTextArray( aTemp, pDXAry ); + for ( i = 0; i < ( nLen - 1 ); i++ ) + pDXAry[ i ] = pDXAry[ i ] * (sal_Int32)pA->GetWidth() / nNormSize; + if ( ( nLen <= 1 ) || ( (sal_Int32)pA->GetWidth() == nNormSize ) ) + delete[] pDXAry, pDXAry = NULL; + aSrcLineInfo = LineInfo(); + SetAllAttr(); + if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, pDXAry ) ) + WMFRecord_ExtTextOut( pA->GetPoint(), aTemp, pDXAry ); + delete[] pDXAry; + } + break; + + case META_BMP_ACTION: + { + const MetaBmpAction* pA = (const MetaBmpAction *) pMA; + WMFRecord_StretchDIB( pA->GetPoint(), pA->GetBitmap().GetSizePixel(), pA->GetBitmap() ); + } + break; + + case META_BMPSCALE_ACTION: + { + const MetaBmpScaleAction* pA = (const MetaBmpScaleAction*) pMA; + WMFRecord_StretchDIB( pA->GetPoint(), pA->GetSize(), pA->GetBitmap() ); + } + break; + + case META_BMPSCALEPART_ACTION: + { + const MetaBmpScalePartAction* pA = (const MetaBmpScalePartAction*) pMA; + Bitmap aTmp( pA->GetBitmap() ); + + if( aTmp.Crop( Rectangle( pA->GetSrcPoint(), pA->GetSrcSize() ) ) ) + WMFRecord_StretchDIB( pA->GetDestPoint(), pA->GetDestSize(), aTmp ); + } + break; + + case META_BMPEX_ACTION: + { + const MetaBmpExAction* pA = (const MetaBmpExAction *) pMA; + Bitmap aBmp( pA->GetBitmapEx().GetBitmap() ); + Bitmap aMsk( pA->GetBitmapEx().GetMask() ); + + if( !!aMsk ) + { + aBmp.Replace( aMsk, COL_WHITE ); + aMsk.Invert(); + WMFRecord_StretchDIB( pA->GetPoint(), aMsk.GetSizePixel(), aBmp, W_SRCPAINT ); + WMFRecord_StretchDIB( pA->GetPoint(), aBmp.GetSizePixel(), aBmp, W_SRCAND ); + } + else + WMFRecord_StretchDIB( pA->GetPoint(), aBmp.GetSizePixel(), aBmp ); + } + break; + + case META_BMPEXSCALE_ACTION: + { + const MetaBmpExScaleAction* pA = (const MetaBmpExScaleAction*) pMA; + Bitmap aBmp( pA->GetBitmapEx().GetBitmap() ); + Bitmap aMsk( pA->GetBitmapEx().GetMask() ); + + if( !!aMsk ) + { + aBmp.Replace( aMsk, COL_WHITE ); + aMsk.Invert(); + WMFRecord_StretchDIB( pA->GetPoint(), pA->GetSize(), aMsk, W_SRCPAINT ); + WMFRecord_StretchDIB( pA->GetPoint(), pA->GetSize(), aBmp, W_SRCAND ); + } + else + WMFRecord_StretchDIB( pA->GetPoint(), pA->GetSize(), aBmp ); + } + break; + + case META_BMPEXSCALEPART_ACTION: + { + const MetaBmpExScalePartAction* pA = (const MetaBmpExScalePartAction*) pMA; + BitmapEx aBmpEx( pA->GetBitmapEx() ); + aBmpEx.Crop( Rectangle( pA->GetSrcPoint(), pA->GetSrcSize() ) ); + Bitmap aBmp( aBmpEx.GetBitmap() ); + Bitmap aMsk( aBmpEx.GetMask() ); + + if( !!aMsk ) + { + aBmp.Replace( aMsk, COL_WHITE ); + aMsk.Invert(); + WMFRecord_StretchDIB( pA->GetDestPoint(), pA->GetDestSize(), aMsk, W_SRCPAINT ); + WMFRecord_StretchDIB( pA->GetDestPoint(), pA->GetDestSize(), aBmp, W_SRCAND ); + } + else + WMFRecord_StretchDIB( pA->GetDestPoint(), pA->GetDestSize(), aBmp ); + } + break; + + case META_GRADIENT_ACTION: + { + const MetaGradientAction* pA = (const MetaGradientAction*) pMA; + GDIMetaFile aTmpMtf; + + pVirDev->AddGradientActions( pA->GetRect(), pA->GetGradient(), aTmpMtf ); + WriteRecords( aTmpMtf ); + } + break; + + case META_HATCH_ACTION: + { + const MetaHatchAction* pA = (const MetaHatchAction*) pMA; + GDIMetaFile aTmpMtf; + + pVirDev->AddHatchActions( pA->GetPolyPolygon(), pA->GetHatch(), aTmpMtf ); + WriteRecords( aTmpMtf ); + } + break; + + case META_WALLPAPER_ACTION: + { + const MetaWallpaperAction* pA = (const MetaWallpaperAction*) pMA; + const Color& rColor = pA->GetWallpaper().GetColor(); + const Color aOldLineColor( aSrcLineColor ); + const Color aOldFillColor( aSrcFillColor ); + + aSrcLineColor = rColor; + aSrcFillColor = rColor; + aSrcLineInfo = LineInfo(); + SetLineAndFillAttr(); + WMFRecord_Rectangle( pA->GetRect() ); + aSrcLineColor = aOldLineColor; + aSrcFillColor = aOldFillColor; + } + break; + + case META_ISECTRECTCLIPREGION_ACTION: + { + const MetaISectRectClipRegionAction* pA = (const MetaISectRectClipRegionAction*) pMA; + WMFRecord_IntersectClipRect( pA->GetRect() ); + } + break; + + case META_LINECOLOR_ACTION: + { + const MetaLineColorAction* pA = (const MetaLineColorAction*) pMA; + + if( pA->IsSetting() ) + aSrcLineColor = pA->GetColor(); + else + aSrcLineColor = Color( COL_TRANSPARENT ); + } + break; + + case META_FILLCOLOR_ACTION: + { + const MetaFillColorAction* pA = (const MetaFillColorAction*) pMA; + + if( pA->IsSetting() ) + aSrcFillColor = pA->GetColor(); + else + aSrcFillColor = Color( COL_TRANSPARENT ); + } + break; + + case META_TEXTCOLOR_ACTION: + { + const MetaTextColorAction* pA = (const MetaTextColorAction*) pMA; + aSrcTextColor = pA->GetColor(); + } + break; + + case META_TEXTFILLCOLOR_ACTION: + { + const MetaTextFillColorAction* pA = (const MetaTextFillColorAction*) pMA; + if( pA->IsSetting() ) + aSrcFont.SetFillColor( pA->GetColor() ); + else + aSrcFont.SetFillColor( Color( COL_TRANSPARENT ) ); + } + break; + + case META_TEXTALIGN_ACTION: + { + const MetaTextAlignAction* pA = (const MetaTextAlignAction*) pMA; + eSrcTextAlign = pA->GetTextAlign(); + } + break; + + case META_MAPMODE_ACTION: + { + const MetaMapModeAction* pA = (const MetaMapModeAction*) pMA; + + if (aSrcMapMode!=pA->GetMapMode()) + { + if( pA->GetMapMode().GetMapUnit() == MAP_RELATIVE ) + { + MapMode aMM = pA->GetMapMode(); + Fraction aScaleX = aMM.GetScaleX(); + Fraction aScaleY = aMM.GetScaleY(); + + Point aOrigin = aSrcMapMode.GetOrigin(); + BigInt aX( aOrigin.X() ); + aX *= BigInt( aScaleX.GetDenominator() ); + if( aOrigin.X() >= 0 ) + if( aScaleX.GetNumerator() >= 0 ) + aX += BigInt( aScaleX.GetNumerator()/2 ); + else + aX -= BigInt( (aScaleX.GetNumerator()+1)/2 ); + else + if( aScaleX.GetNumerator() >= 0 ) + aX -= BigInt( (aScaleX.GetNumerator()-1)/2 ); + else + aX += BigInt( aScaleX.GetNumerator()/2 ); + aX /= BigInt( aScaleX.GetNumerator() ); + aOrigin.X() = (long)aX + aMM.GetOrigin().X(); + BigInt aY( aOrigin.Y() ); + aY *= BigInt( aScaleY.GetDenominator() ); + if( aOrigin.Y() >= 0 ) + if( aScaleY.GetNumerator() >= 0 ) + aY += BigInt( aScaleY.GetNumerator()/2 ); + else + aY -= BigInt( (aScaleY.GetNumerator()+1)/2 ); + else + if( aScaleY.GetNumerator() >= 0 ) + aY -= BigInt( (aScaleY.GetNumerator()-1)/2 ); + else + aY += BigInt( aScaleY.GetNumerator()/2 ); + aY /= BigInt( aScaleY.GetNumerator() ); + aOrigin.Y() = (long)aY + aMM.GetOrigin().Y(); + aSrcMapMode.SetOrigin( aOrigin ); + + aScaleX *= aSrcMapMode.GetScaleX(); + aScaleY *= aSrcMapMode.GetScaleY(); + aSrcMapMode.SetScaleX( aScaleX ); + aSrcMapMode.SetScaleY( aScaleY ); + } + else + aSrcMapMode=pA->GetMapMode(); + } + } + break; + + case META_FONT_ACTION: + { + const MetaFontAction* pA = (const MetaFontAction*) pMA; + aSrcFont = pA->GetFont(); + + if ( aSrcFont.GetCharSet() == RTL_TEXTENCODING_DONTKNOW ) + aSrcFont.SetCharSet( GetExtendedTextEncoding( gsl_getSystemTextEncoding() ) ); + if ( aSrcFont.GetCharSet() == RTL_TEXTENCODING_UNICODE ) + aSrcFont.SetCharSet( RTL_TEXTENCODING_MS_1252 ); + eSrcTextAlign = aSrcFont.GetAlign(); + aSrcTextColor = aSrcFont.GetColor(); + aSrcFont.SetAlign( ALIGN_BASELINE ); + aSrcFont.SetColor( COL_WHITE ); + } + break; + + case META_PUSH_ACTION: + { + const MetaPushAction* pA = (const MetaPushAction*)pMA; + + WMFWriterAttrStackMember* pAt = new WMFWriterAttrStackMember; + pAt->nFlags = pA->GetFlags(); + pAt->aClipRegion = aSrcClipRegion; + pAt->aLineColor=aSrcLineColor; + pAt->aFillColor=aSrcFillColor; + pAt->eRasterOp=eSrcRasterOp; + pAt->aFont=aSrcFont; + pAt->eTextAlign=eSrcTextAlign; + pAt->aTextColor=aSrcTextColor; + pAt->aMapMode=aSrcMapMode; + pAt->aLineInfo=aDstLineInfo; + pAt->pSucc=pAttrStack; + pAttrStack=pAt; + + SetAllAttr(); // update ( now all source attributes are equal to the destination attributes ) + WMFRecord_SaveDC(); + + } + break; + + case META_POP_ACTION: + { + WMFWriterAttrStackMember * pAt=pAttrStack; + + if( pAt ) + { + aDstLineInfo = pAt->aLineInfo; + aDstLineColor = pAt->aLineColor; + if ( pAt->nFlags & PUSH_LINECOLOR ) + aSrcLineColor = pAt->aLineColor; + aDstFillColor = pAt->aFillColor; + if ( pAt->nFlags & PUSH_FILLCOLOR ) + aSrcFillColor = pAt->aFillColor; + eDstROP2 = pAt->eRasterOp; + if ( pAt->nFlags & PUSH_RASTEROP ) + eSrcRasterOp = pAt->eRasterOp; + aDstFont = pAt->aFont; + if ( pAt->nFlags & PUSH_FONT ) + aSrcFont = pAt->aFont; + eDstTextAlign = pAt->eTextAlign; + if ( pAt->nFlags & ( PUSH_FONT | PUSH_TEXTALIGN ) ) + eSrcTextAlign = pAt->eTextAlign; + aDstTextColor = pAt->aTextColor; + if ( pAt->nFlags & ( PUSH_FONT | PUSH_TEXTCOLOR ) ) + aSrcTextColor = pAt->aTextColor; + if ( pAt->nFlags & PUSH_MAPMODE ) + aSrcMapMode = pAt->aMapMode; + aDstClipRegion = pAt->aClipRegion; + if ( pAt->nFlags & PUSH_CLIPREGION ) + aSrcClipRegion = pAt->aClipRegion; + + WMFRecord_RestoreDC(); + pAttrStack = pAt->pSucc; + delete pAt; + } + } + break; + + case META_EPS_ACTION : + { + const MetaEPSAction* pA = (const MetaEPSAction*)pMA; + const GDIMetaFile aGDIMetaFile( pA->GetSubstitute() ); + + INT32 nCount = aGDIMetaFile.GetActionCount(); + for ( INT32 i = 0; i < nCount; i++ ) + { + const MetaAction* pMetaAct = aGDIMetaFile.GetAction( i ); + if ( pMetaAct->GetType() == META_BMPSCALE_ACTION ) + { + const MetaBmpScaleAction* pBmpScaleAction = (const MetaBmpScaleAction*)pMetaAct; + WMFRecord_StretchDIB( pA->GetPoint(), pA->GetSize(), pBmpScaleAction->GetBitmap() ); + break; + } + } + } + break; + + case META_RASTEROP_ACTION: + { + const MetaRasterOpAction* pA = (const MetaRasterOpAction*) pMA; + eSrcRasterOp=pA->GetRasterOp(); + } + break; + + case META_TRANSPARENT_ACTION: + { + aSrcLineInfo = LineInfo(); + SetLineAndFillAttr(); + WMFRecord_PolyPolygon( ( (MetaTransparentAction*) pMA )->GetPolyPolygon() ); + } + break; + + case META_FLOATTRANSPARENT_ACTION: + { + const MetaFloatTransparentAction* pA = (const MetaFloatTransparentAction*) pMA; + + GDIMetaFile aTmpMtf( pA->GetGDIMetaFile() ); + Point aSrcPt( aTmpMtf.GetPrefMapMode().GetOrigin() ); + const Size aSrcSize( aTmpMtf.GetPrefSize() ); + const Point aDestPt( pA->GetPoint() ); + const Size aDestSize( pA->GetSize() ); + const double fScaleX = aSrcSize.Width() ? (double) aDestSize.Width() / aSrcSize.Width() : 1.0; + const double fScaleY = aSrcSize.Height() ? (double) aDestSize.Height() / aSrcSize.Height() : 1.0; + long nMoveX, nMoveY; + + aSrcLineInfo = LineInfo(); + SetAllAttr(); + + if( fScaleX != 1.0 || fScaleY != 1.0 ) + { + aTmpMtf.Scale( fScaleX, fScaleY ); + aSrcPt.X() = FRound( aSrcPt.X() * fScaleX ), aSrcPt.Y() = FRound( aSrcPt.Y() * fScaleY ); + } + + nMoveX = aDestPt.X() - aSrcPt.X(), nMoveY = aDestPt.Y() - aSrcPt.Y(); + + if( nMoveX || nMoveY ) + aTmpMtf.Move( nMoveX, nMoveY ); + + WriteRecords( aTmpMtf ); + } + break; + + case( META_LAYOUTMODE_ACTION ): + { + sal_uInt32 nLayoutMode = ( (MetaLayoutModeAction*) pMA )->GetLayoutMode(); + eSrcHorTextAlign = 0; // TA_LEFT + if (nLayoutMode & TEXT_LAYOUT_BIDI_RTL) + { + eSrcHorTextAlign = W_TA_RIGHT | W_TA_RTLREADING; + } + if (nLayoutMode & TEXT_LAYOUT_TEXTORIGIN_RIGHT) + eSrcHorTextAlign |= W_TA_RIGHT; + else if (nLayoutMode & TEXT_LAYOUT_TEXTORIGIN_LEFT) + eSrcHorTextAlign &= ~W_TA_RIGHT; + break; + } + + // Unsupported Actions + case META_MASK_ACTION: + case META_MASKSCALE_ACTION: + case META_MASKSCALEPART_ACTION: + { + DBG_ERROR( "Unsupported action: MetaMask...Action!" ); + } + break; + + case META_CLIPREGION_ACTION: + break; + + case META_ISECTREGIONCLIPREGION_ACTION: + { + DBG_ERROR( "Unsupported action: MetaISectRegionClipRegionAction!" ); + } + break; + + case META_MOVECLIPREGION_ACTION: + { + DBG_ERROR( "Unsupported action: MetaMoveClipRegionAction!" ); + } + break; + + case( META_RENDERGRAPHIC_ACTION ): + { + const MetaRenderGraphicAction* pA = (const MetaRenderGraphicAction*) pMA; + const ::vcl::RenderGraphicRasterizer aRasterizer( pA->GetRenderGraphic() ); + const BitmapEx aBmpEx( aRasterizer.Rasterize( pVirDev->LogicToPixel( pA->GetSize(), aSrcMapMode ) ) ); + Bitmap aBmp( aBmpEx.GetBitmap() ); + Bitmap aMsk( aBmpEx.GetMask() ); + + if( !!aMsk ) + { + aBmp.Replace( aMsk, COL_WHITE ); + aMsk.Invert(); + WMFRecord_StretchDIB( pA->GetPoint(), pA->GetSize(), aMsk, W_SRCPAINT ); + WMFRecord_StretchDIB( pA->GetPoint(), pA->GetSize(), aBmp, W_SRCAND ); + } + else + WMFRecord_StretchDIB( pA->GetPoint(), pA->GetSize(), aBmp ); + } + break; + + default: + { + DBG_ERROR( "Unsupported meta action!" ); + } + break; + } + + nWrittenActions++; + MayCallback(); + + if (pWMF->GetError()) + bStatus=FALSE; + + if(bStatus==FALSE) + break; + } + } +} + +// ------------------------------------------------------------------------ + +void WMFWriter::WriteHeader( const GDIMetaFile &, BOOL bPlaceable ) +{ + if( bPlaceable ) + { + USHORT nCheckSum, nValue; + Size aSize( pVirDev->LogicToLogic(Size(1,1),MapMode(MAP_INCH), aTargetMapMode) ); + USHORT nUnitsPerInch = (USHORT) ( ( aSize.Width() + aSize.Height() ) >> 1 ); + + nCheckSum=0; + nValue=0xcdd7; nCheckSum^=nValue; *pWMF << nValue; + nValue=0x9ac6; nCheckSum^=nValue; *pWMF << nValue; + nValue=0x0000; nCheckSum^=nValue; *pWMF << nValue; + nValue=0x0000; nCheckSum^=nValue; *pWMF << nValue; + nValue=0x0000; nCheckSum^=nValue; *pWMF << nValue; + nValue=(USHORT) aTargetSize.Width(); nCheckSum^=nValue; *pWMF << nValue; + nValue=(USHORT) aTargetSize.Height(); nCheckSum^=nValue; *pWMF << nValue; + nValue=nUnitsPerInch; nCheckSum^=nValue; *pWMF << nValue; + nValue=0x0000; nCheckSum^=nValue; *pWMF << nValue; + nValue=0x0000; nCheckSum^=nValue; *pWMF << nValue; + *pWMF << nCheckSum; + } + + nMetafileHeaderPos=pWMF->Tell(); + *pWMF << (sal_uInt16)0x0001 // Typ: Datei + << (sal_uInt16)0x0009 // Headerlaenge in Worten + << (sal_uInt16)0x0300 // Version als BCD-Zahl + << (sal_uInt32) 0x00000000 // Dateilaenge (ohne 1. Header), wird spaeter durch UpdateHeader() berichtigt + << (sal_uInt16)MAXOBJECTHANDLES // Maximalezahl der gleichzeitigen Objekte + << (sal_uInt32) 0x00000000 // Maximale Record-laenge, wird spaeter durch UpdateHeader() berichtigt + << (sal_uInt16)0x0000; // Reserved +} + +// ------------------------------------------------------------------------ + +void WMFWriter::UpdateHeader() +{ + ULONG nPos; + sal_uInt32 nFileSize; + + nPos=pWMF->Tell(); // Endposition = Gesammtgroesse der Datei + nFileSize=nPos-nMetafileHeaderPos; // Groesse des 1. Headers abziehen + if ((nFileSize&1)!=0) { // ggf. auf ganze Worte aufrunden + *pWMF << (BYTE)0; + nPos++; + nFileSize++; + } + nFileSize>>=1; // In Anzahl Worte umrechnen + pWMF->Seek(nMetafileHeaderPos+6); // Zum Dateigroessen-Eintrag im zweiten Header + *pWMF << nFileSize; // Dateigroesse berichtigen + pWMF->SeekRel(2); // Zum Max-Record-Laenge-Eintrag im zweiten Header + *pWMF << nMaxRecordSize; // und berichtigen + pWMF->Seek(nPos); +} + +// ------------------------------------------------------------------------ + +BOOL WMFWriter::WriteWMF( const GDIMetaFile& rMTF, SvStream& rTargetStream, + FilterConfigItem* pFConfigItem, BOOL bPlaceable ) +{ + WMFWriterAttrStackMember * pAt; + + bEmbedEMF = TRUE; + bStatus=TRUE; + pConvert = 0; + pVirDev = new VirtualDevice; + + pFilterConfigItem = pFConfigItem; + if ( pFilterConfigItem ) + { + xStatusIndicator = pFilterConfigItem->GetStatusIndicator(); + if ( xStatusIndicator.is() ) + { + rtl::OUString aMsg; + xStatusIndicator->start( aMsg, 100 ); + } + } + nLastPercent=0; + + pWMF=&rTargetStream; + pWMF->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); + + nMaxRecordSize=0; + + aSrcMapMode=rMTF.GetPrefMapMode(); + + if( bPlaceable ) + { + aTargetMapMode = aSrcMapMode; + aTargetSize = rMTF.GetPrefSize(); + nTargetDivisor = CalcSaveTargetMapMode(aTargetMapMode, aTargetSize); + aTargetSize.Width() /= nTargetDivisor; + aTargetSize.Height() /= nTargetDivisor; + } + else + { + aTargetMapMode = MapMode( MAP_INCH ); + + const long nUnit = pVirDev->LogicToPixel( Size( 1, 1 ), aTargetMapMode ).Width(); + const Fraction aFrac( 1, nUnit ); + + aTargetMapMode.SetScaleX( aFrac ); + aTargetMapMode.SetScaleY( aFrac ); + aTargetSize = pVirDev->LogicToLogic( rMTF.GetPrefSize(), aSrcMapMode, aTargetMapMode ); + } + + pVirDev->SetMapMode( aTargetMapMode ); + + pAttrStack=NULL; + + for (USHORT i=0; ipSucc; + delete pAt; + } + + delete pVirDev; + delete pConvert; + + if ( xStatusIndicator.is() ) + xStatusIndicator->end(); + + return bStatus; +} + +// ------------------------------------------------------------------------ + +USHORT WMFWriter::CalcSaveTargetMapMode(MapMode& rMapMode, + const Size& rPrefSize) +{ + Fraction aDivFrac(2, 1); + USHORT nDivisor = 1; + + Size aSize = pVirDev->LogicToLogic( rPrefSize, aSrcMapMode, rMapMode ); + + while( nDivisor <= 64 && (aSize.Width() > 32767 || aSize.Height() > 32767) ) + { + Fraction aFrac = rMapMode.GetScaleX(); + + aFrac *= aDivFrac; + rMapMode.SetScaleX(aFrac); + aFrac = rMapMode.GetScaleY(); + aFrac *= aDivFrac; + rMapMode.SetScaleY(aFrac); + nDivisor <<= 1; + aSize = pVirDev->LogicToLogic( rPrefSize, aSrcMapMode, rMapMode ); + } + + return nDivisor; +} + +// ------------------------------------------------------------------------ + +void WMFWriter::WriteEmbeddedEMF( const GDIMetaFile& rMTF ) +{ + EMFWriter aEMFWriter; + SvMemoryStream aStream; + + if( aEMFWriter.WriteEMF( rMTF, aStream ) ) + { + sal_Size nTotalSize = aStream.Tell(); + if( nTotalSize > SAL_MAX_UINT32 ) + return; + aStream.Seek( 0 ); + sal_uInt32 nRemainingSize = static_cast< sal_uInt32 >( nTotalSize ); + sal_uInt32 nRecCounts = ( (nTotalSize - 1) / 0x2000 ) + 1; + sal_uInt16 nCheckSum = 0, nWord; + + sal_uInt32 nPos = 0; + + while( nPos + 1 < nTotalSize ) + { + aStream >> nWord; + nCheckSum ^= nWord; + nPos += 2; + } + + nCheckSum = static_cast< sal_uInt16 >( nCheckSum * -1 ); + + aStream.Seek( 0 ); + while( nRemainingSize > 0 ) + { + sal_uInt32 nCurSize; + if( nRemainingSize > 0x2000 ) + { + nCurSize = 0x2000; + nRemainingSize -= 0x2000; + } + else + { + nCurSize = nRemainingSize; + nRemainingSize = 0; + } + WriteEMFRecord( aStream, + nCurSize, + nRemainingSize, + nTotalSize, + nRecCounts, + nCheckSum ); + nCheckSum = 0; + } + } +} + +// ------------------------------------------------------------------------ + +void WMFWriter::WriteEMFRecord( SvMemoryStream& rStream, sal_uInt32 nCurSize, sal_uInt32 nRemainingSize, + sal_uInt32 nTotalSize, sal_uInt32 nRecCounts, sal_uInt16 nCheckSum ) +{ + // according to http://msdn.microsoft.com/en-us/library/dd366152%28PROT.13%29.aspx + WriteRecordHeader( 0, W_META_ESCAPE ); + *pWMF << (sal_uInt16)W_MFCOMMENT // same as META_ESCAPE_ENHANCED_METAFILE + << (sal_uInt16)( nCurSize + 34 ) // we will always have a 34 byte escape header: + << (sal_uInt32) 0x43464D57 // WMFC + << (sal_uInt32) 0x00000001 // Comment type + << (sal_uInt32) 0x00010000 // version + << nCheckSum // check sum + << (sal_uInt32) 0 // flags = 0 + << nRecCounts // total number of records + << nCurSize // size of this record's data + << nRemainingSize // remaining size of data in following records, missing in MSDN documentation + << nTotalSize; // total size of EMF stream + + pWMF->Write( static_cast< const sal_Char* >( rStream.GetData() ) + rStream.Tell(), nCurSize ); + rStream.SeekRel( nCurSize ); + UpdateRecordHeader(); +} diff --git a/svtools/source/filter/wmf/wmfwr.hxx b/svtools/source/filter/wmf/wmfwr.hxx new file mode 100644 index 000000000000..9fe698b22c2e --- /dev/null +++ b/svtools/source/filter/wmf/wmfwr.hxx @@ -0,0 +1,229 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _WMFWR_HXX +#define _WMFWR_HXX + +#include +#include +#include +#include +#include +#include +#include + +// ----------------------------------------------------------------------------- + +#define MAXOBJECTHANDLES 16 + +// ----------------------------------------------------------------------------- + +struct WMFWriterAttrStackMember +{ + struct WMFWriterAttrStackMember * pSucc; + Color aLineColor; + Color aFillColor; + Color aTextColor; + LineInfo aLineInfo; + TextAlign eTextAlign; + RasterOp eRasterOp; + Font aFont; + MapMode aMapMode; + Region aClipRegion; + sal_uInt16 nFlags; +}; + +// ------------- +// - WMFWriter - +// ------------- + +class StarSymbolToMSMultiFont; +class LineInfo; +namespace basegfx { class B2DPolygon; } + +class WMFWriter +{ +private: + + BOOL bStatus; + + ULONG nLastPercent; // Mit welcher Zahl pCallback zuletzt aufgerufen wurde. + FilterConfigItem* pFilterConfigItem; + + com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator > xStatusIndicator; + + SvStream* pWMF; + VirtualDevice* pVirDev; + StarSymbolToMSMultiFont *pConvert; + MapMode aTargetMapMode; + Size aTargetSize; + USHORT nTargetDivisor; + + ULONG nMetafileHeaderPos; + sal_uInt32 nMaxRecordSize; // in Worten + ULONG nActRecordPos; + + // Aktuelle Attribute im Quell-Metafile: + Color aSrcLineColor; + Color aSrcFillColor; + Color aSrcTextColor; + LineInfo aSrcLineInfo; + RasterOp eSrcRasterOp; + FontAlign eSrcTextAlign; + Font aSrcFont; + MapMode aSrcMapMode; + BOOL bSrcIsClipping; + Region aSrcClipRegion; + WMFWriterAttrStackMember * pAttrStack; + + UINT32 eSrcHorTextAlign; + + // Aktuelle Attribute im Ziel-Metafile: + Color aDstLineColor; + Color aDstFillColor; + Color aDstTextColor; + LineInfo aDstLineInfo; + RasterOp eDstROP2; + FontAlign eDstTextAlign; + Font aDstFont; + + UINT32 eDstHorTextAlign; + + BOOL bDstIsClipping; // ???: derzeit unberuecksichtigt + Region aDstClipRegion; // ???: derzeit unberuecksichtigt + BOOL bHandleAllocated[MAXOBJECTHANDLES]; // Welche Handles vergeben sind + USHORT nDstPenHandle,nDstFontHandle,nDstBrushHandle; // Welche Handles die jeweiligen + // Selected-Objects besitzen + // 0xffff = keines: + + // Damit nicht bei jeder Operation alle Attribute verglichen werden muessen: + + ULONG nNumberOfActions; // Anzahl der Actions im GDIMetafile + ULONG nNumberOfBitmaps; // Anzahl der Bitmaps + ULONG nWrittenActions; // Anzahl der bereits verarbeiteten Actions beim Schreiben der Orders + ULONG nWrittenBitmaps; // Anzahl der bereits geschriebenen Bitmaps + ULONG nActBitmapPercent; // Wieviel Prozent die naechste Bitmap schon geschrieben ist. + + BOOL bEmbedEMF; // optionally embedd EMF data into WMF + + void MayCallback(); + // Berechnet anhand der obigen 5 Parameter eine Prozentzahl + // und macht dann ggf. einen Callback. Setzt bStatus auf FALSE wenn User abbrechen + // moechte. + + void CountActionsAndBitmaps(const GDIMetaFile & rMTF); + // Zaehlt die Bitmaps und Actions (nNumberOfActions und nNumberOfBitmaps muessen + // zu Anfang auf 0 gesetzt werden, weil diese Methode rekursiv ist) + + void WritePointXY(const Point & rPoint); + void WritePointYX(const Point & rPoint); + sal_Int32 ScaleWidth( sal_Int32 nDX ); + void WriteSize(const Size & rSize); + void WriteHeightWidth(const Size & rSize); + void WriteRectangle(const Rectangle & rRect); + void WriteColor(const Color & rColor); + + void WriteRecordHeader(sal_uInt32 nSizeWords, sal_uInt16 nType); + // nSizeWords ist die Groesse des gesammten Records in Anzahl Worte. + // Wenn nSizeWords unbekannt ist, dann 0 einsetzen (siehe UpdateRecordHeader()). + + void UpdateRecordHeader(); + // berichtig die Groesse des Records nach dem Schreiben der Parameter, wenn + // nSizeWords bei Aufruf von WriteRecordHeader(..) unbekannt war. + // fuegt ggf. noch ein BYTE 0 ein damit Anzahl Bytes immer gerade. + + void WMFRecord_Arc(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt); + void WMFRecord_Chord(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt); + void WMFRecord_CreateBrushIndirect(const Color& rColor); + void WMFRecord_CreateFontIndirect(const Font & rFont); + void WMFRecord_CreatePenIndirect(const Color& rColor, const LineInfo& rLineInfo ); + void WMFRecord_DeleteObject(USHORT nObjectHandle); + void WMFRecord_Ellipse(const Rectangle & rRect); + void WMFRecord_Escape( sal_uInt32 nEsc, sal_uInt32 nLen, const sal_Int8* pData ); + sal_Bool WMFRecord_Escape_Unicode( const Point& rPoint, const String& rStr, const sal_Int32 * pDXAry ); + void WMFRecord_ExtTextOut(const Point & rPoint, const String & rString, const sal_Int32 * pDXAry); + + void TrueExtTextOut(const Point & rPoint, const String & rString, + const ByteString & rByteString, const sal_Int32 * pDXAry); + void TrueTextOut(const Point & rPoint, const ByteString& rString); + void WMFRecord_LineTo(const Point & rPoint); + void WMFRecord_MoveTo(const Point & rPoint); + void WMFRecord_Pie(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt); + void WMFRecord_Polygon(const Polygon & rPoly); + void WMFRecord_PolyLine(const Polygon & rPoly); + void WMFRecord_PolyPolygon(const PolyPolygon & rPolyPoly); + void WMFRecord_Rectangle(const Rectangle & rRect); + void WMFRecord_RestoreDC(); + void WMFRecord_RoundRect(const Rectangle & rRect, long nHorzRound, long nVertRound); + void WMFRecord_SaveDC(); + void WMFRecord_SelectObject(USHORT nObjectHandle); + void WMFRecord_SetBkColor(const Color & rColor); + void WMFRecord_SetBkMode(BOOL bTransparent); + void WMFRecord_SetStretchBltMode(); + void WMFRecord_SetPixel(const Point & rPoint, const Color & rColor); + void WMFRecord_SetROP2(RasterOp eROP); + void WMFRecord_SetTextAlign(FontAlign eFontAlign, UINT32 eHorTextAlign); + void WMFRecord_SetTextColor(const Color & rColor); + void WMFRecord_SetWindowExt(const Size & rSize); + void WMFRecord_SetWindowOrg(const Point & rPoint); + void WMFRecord_StretchDIB(const Point & rPoint, const Size & rSize, const Bitmap & rBitmap, sal_uInt32 nROP = 0UL ); + void WMFRecord_TextOut(const Point & rPoint, const String & rString); + void WMFRecord_EndOfFile(); + void WMFRecord_IntersectClipRect( const Rectangle& rRect); + + USHORT AllocHandle(); + void FreeHandle(USHORT nObjectHandle); + void CreateSelectDeletePen( const Color& rColor, const LineInfo& rLineInfo ); + void CreateSelectDeleteFont(const Font & rFont); + void CreateSelectDeleteBrush(const Color& rColor); + + void SetLineAndFillAttr(); + void SetAllAttr(); + + void HandleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon); + void WriteRecords(const GDIMetaFile & rMTF); + + void WriteHeader(const GDIMetaFile & rMTF, BOOL bPlaceable); + void UpdateHeader(); + + void WriteEmbeddedEMF( const GDIMetaFile& rMTF ); + void WriteEMFRecord( SvMemoryStream& rStream, sal_uInt32 nCurSize, + sal_uInt32 nRemainingSize, + sal_uInt32 nTotalSize, + sal_uInt32 nRecCounts, + sal_uInt16 nCheckSum ); + + USHORT CalcSaveTargetMapMode(MapMode& rMapMode, const Size& rPrefSize); + +public: + + WMFWriter() {} + + BOOL WriteWMF(const GDIMetaFile & rMTF, SvStream & rTargetStream, FilterConfigItem* pFilterConfigItem, BOOL bPlaceable=TRUE); +}; + +#endif -- cgit