diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 15:18:56 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 15:18:56 +0000 |
commit | 95117e7fefa9ae82431dcdffd1e58495730f6f54 (patch) | |
tree | 158386e9f19cda5c69023d678c4d3313435a206d /extensions/source/svg |
initial import
Diffstat (limited to 'extensions/source/svg')
-rw-r--r-- | extensions/source/svg/makefile.mk | 134 | ||||
-rw-r--r-- | extensions/source/svg/svgaction.cxx | 1412 | ||||
-rw-r--r-- | extensions/source/svg/svgaction.hxx | 196 | ||||
-rw-r--r-- | extensions/source/svg/svgcom.hxx | 144 | ||||
-rw-r--r-- | extensions/source/svg/svgprinter.cxx | 364 | ||||
-rw-r--r-- | extensions/source/svg/svgprinter.hxx | 101 | ||||
-rw-r--r-- | extensions/source/svg/svguno.cxx | 167 | ||||
-rw-r--r-- | extensions/source/svg/svgwriter.cxx | 214 | ||||
-rw-r--r-- | extensions/source/svg/svgwriter.hxx | 94 |
9 files changed, 2826 insertions, 0 deletions
diff --git a/extensions/source/svg/makefile.mk b/extensions/source/svg/makefile.mk new file mode 100644 index 000000000000..9ea4ee0bd6a0 --- /dev/null +++ b/extensions/source/svg/makefile.mk @@ -0,0 +1,134 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:16:53 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=extensions +TARGET=svg + +UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb +ENABLE_EXCEPTIONS=TRUE +USE_DEFFILE=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +# --- Types ------------------------------------- + +UNOTYPES=\ + com.sun.star.uno.RuntimeException \ + com.sun.star.uno.TypeClass \ + com.sun.star.uno.XInterface \ + com.sun.star.uno.XWeak \ + com.sun.star.registry.XRegistryKey \ + com.sun.star.io.XInputStream \ + com.sun.star.io.XOutputStream \ + com.sun.star.lang.XComponent \ + com.sun.star.lang.XInitialization \ + com.sun.star.lang.XMultiServiceFactory \ + com.sun.star.lang.XSingleServiceFactory \ + com.sun.star.loader.XImplementationLoader \ + com.sun.star.registry.XImplementationRegistration \ + com.sun.star.registry.XRegistryKey \ + com.sun.star.registry.XSimpleRegistry \ + com.sun.star.xml.sax.XDocumentHandler \ + com.sun.star.xml.sax.XExtendedDocumentHandler \ + com.sun.star.svg.XSVGPrinter \ + com.sun.star.svg.XSVGWriter + +# --- Files ------------------------------------- + +CXXFILES= svgprinter.cxx \ + svguno.cxx \ + svgaction.cxx \ + svgwriter.cxx + +SLOFILES= $(SLO)$/svgprinter.obj \ + $(SLO)$/svguno.obj \ + $(SLO)$/svgwriter.obj \ + $(SLO)$/svgaction.obj + +# --- Library ----------------------------------- + +SHL1TARGET=$(TARGET)$(UPD)$(DLLPOSTFIX) +SHL1STDLIBS=\ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(VOSLIB) \ + $(SALLIB) \ + $(VCLLIB) \ + $(SVLLIB) \ + $(ONELIB) \ + $(TOOLSLIB) \ + $(XMLOFFLIB) + +SHL1DEPN= +SHL1IMPLIB= i$(SHL1TARGET) +SHL1LIBS= $(SLB)$/$(TARGET).lib +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME=$(SHL1TARGET) +DEF1EXPORTFILE=exports.dxp + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk diff --git a/extensions/source/svg/svgaction.cxx b/extensions/source/svg/svgaction.cxx new file mode 100644 index 000000000000..45ba9ca1c6ec --- /dev/null +++ b/extensions/source/svg/svgaction.cxx @@ -0,0 +1,1412 @@ +/************************************************************************* + * + * $RCSfile: svgaction.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "svgaction.hxx" +#include <vcl/virdev.hxx> +#include <vcl/cvtgrf.hxx> +#include <vcl/metric.hxx> + +// ----------- +// - Defines - +// ----------- + +// #define _SVG_WRITE_TSPAN +// #define _SVG_WRITE_STRIKEOUT + +// ----------- +// - statics - +// ----------- + +static const char aXMLElemSVG[] = "svg"; +static const char aXMLElemG[] = "g"; +static const char aXMLElemDefs[] = "defs"; +static const char aXMLElemClipPath[] = "clipPath"; +static const char aXMLElemLine[] = "line"; +static const char aXMLElemRect[] = "rect"; +static const char aXMLElemEllipse[] = "ellipse"; +static const char aXMLElemPath[] = "path"; +static const char aXMLElemPolygon[] = "polygon"; +static const char aXMLElemPolyLine[] = "polyline"; +static const char aXMLElemText[] = "text"; +static const char aXMLElemTSpan[] = "tspan"; +static const char aXMLElemImage[] = "image"; + +static const char aXMLAttrTransform[] = "transform"; +static const char aXMLAttrStyle[] = "style"; +static const char aXMLAttrId[] = "id"; + +static const char aXMLAttrD[] = "d"; +static const char aXMLAttrX[] = "x"; +static const char aXMLAttrY[] = "y"; +static const char aXMLAttrX1[] = "x1"; +static const char aXMLAttrY1[] = "y1"; +static const char aXMLAttrX2[] = "x2"; +static const char aXMLAttrY2[] = "y2"; +static const char aXMLAttrCX[] = "cx"; +static const char aXMLAttrCY[] = "cy"; +static const char aXMLAttrRX[] = "rx"; +static const char aXMLAttrRY[] = "ry"; +static const char aXMLAttrWidth[] = "width"; +static const char aXMLAttrHeight[] = "height"; +static const char aXMLAttrPoints[] = "points"; +static const char aXMLAttrXLinkHRef[] = "xlink:href"; + +static const sal_Unicode pBase64[] = +{ + //0 1 2 3 4 5 6 7 + 'A','B','C','D','E','F','G','H', // 0 + 'I','J','K','L','M','N','O','P', // 1 + 'Q','R','S','T','U','V','W','X', // 2 + 'Y','Z','a','b','c','d','e','f', // 3 + 'g','h','i','j','k','l','m','n', // 4 + 'o','p','q','r','s','t','u','v', // 5 + 'w','x','y','z','0','1','2','3', // 6 + '4','5','6','7','8','9','+','/' // 7 +}; + +// -------------- +// - FastString - +// -------------- + +FastString::FastString( sal_uInt32 nInitLen, sal_uInt32 nIncrement ) : + mnBufLen( nInitLen ), + mnCurLen( 0 ), + mnBufInc( nIncrement ), + mpBuffer( new sal_Unicode[ nInitLen * sizeof( sal_Unicode ) ] ), + mnPartPos( 0 ) +{ + DBG_ASSERT( nInitLen, "invalid initial length" ); + DBG_ASSERT( nIncrement, "invalid increment" ); +} + +// ----------------------------------------------------------------------------- + +FastString::FastString( sal_Char* pBufferForBase64Encoding, sal_uInt32 nBufLen ) : + mnBufInc( 2048 ), + mnPartPos( 0 ) +{ + DBG_ASSERT( pBufferForBase64Encoding && nBufLen, "invalid arguments" ); + + const sal_uInt32 nQuadCount = nBufLen / 3; + const sal_uInt32 nRest = nBufLen % 3; + + if( nQuadCount || nRest ) + { + mnBufLen = mnCurLen = ( ( nQuadCount + ( nRest ? 1 : 0 ) ) << 2 ); + mpBuffer = new sal_Unicode[ mnBufLen * sizeof( sal_Unicode ) ]; + + sal_Char* pTmpSrc = pBufferForBase64Encoding; + sal_Unicode* pTmpDst = mpBuffer; + + for( sal_uInt32 i = 0, nCharCount = 0; i < nQuadCount; i++ ) + { + const sal_Int32 nA = *pTmpSrc++; + const sal_Int32 nB = *pTmpSrc++; + const sal_Int32 nC = *pTmpSrc++; + + *pTmpDst++ = pBase64[ ( nA >> 2 ) & 0x3f ]; + *pTmpDst++ = pBase64[ ( ( nA << 4 ) & 0x30 ) + ( ( nB >> 4 ) & 0xf ) ]; + *pTmpDst++ = pBase64[ ( ( nB << 2 ) & 0x3c ) + ( ( nC >> 6 ) & 0x3 ) ]; + *pTmpDst++ = pBase64[ nC & 0x3f ]; + } + + if( 1 == nRest ) + { + const sal_Int32 nA = *pTmpSrc; + + *pTmpDst++ = pBase64[ ( nA >> 2 ) & 0x3f ]; + *pTmpDst++ = pBase64[ ( nA << 4 ) & 0x30 ]; + *pTmpDst++ = '='; + *pTmpDst = '='; + } + else if( 2 == nRest ) + { + const sal_Int32 nA = *pTmpSrc++; + const sal_Int32 nB = *pTmpSrc; + + *pTmpDst++ = pBase64[ ( nA >> 2 ) & 0x3f ]; + *pTmpDst++ = pBase64[ ( ( nA << 4 ) & 0x30 ) + ( ( nB >> 4 ) & 0xf ) ]; + *pTmpDst++ = pBase64[ ( nB << 2 ) & 0x3c ]; + *pTmpDst = '='; + } + } + else + { + mpBuffer = new sal_Unicode[ ( mnBufLen = 1 ) * sizeof( sal_Unicode ) ]; + mnCurLen = 0; + } +} + +// ----------------------------------------------------------------------------- + +FastString::~FastString() +{ + delete[] mpBuffer; +} + +// ----------------------------------------------------------------------------- + +FastString& FastString::operator+=( const NMSP_RTL::OUString& rStr ) +{ + if( rStr.getLength() ) + { + if( ( mnCurLen + rStr.getLength() ) > mnBufLen ) + { + const sal_uInt32 nNewBufLen = ( mnBufLen + ( ( ( mnCurLen + rStr.getLength() ) - mnBufLen ) / mnBufInc + 1 ) * mnBufInc ); + sal_Unicode* pNewBuffer = new sal_Unicode[ nNewBufLen * sizeof( sal_Unicode ) ]; + + HMEMCPY( pNewBuffer, mpBuffer, mnBufLen * sizeof( sal_Unicode ) ); + delete[] mpBuffer; + mpBuffer = pNewBuffer; + mnBufLen = nNewBufLen; + } + + HMEMCPY( mpBuffer + mnCurLen, rStr.getStr(), rStr.getLength() * sizeof( sal_Unicode ) ); + mnCurLen += rStr.getLength(); + + if( maString.getLength() ) + maString = NMSP_RTL::OUString(); + } + + return *this; +} + +// ----------------------------------------------------------------------------- + +const NMSP_RTL::OUString& FastString::GetString() const +{ + if( !maString.getLength() && mnCurLen ) + ( (FastString*) this )->maString = NMSP_RTL::OUString( mpBuffer, mnCurLen ); + + return maString; +} + +// ----------------------------------------------------------------------------- + +sal_Bool FastString::GetFirstPartString( const sal_uInt32 nPartLen, NMSP_RTL::OUString& rPartString ) +{ + const sal_uInt32 nLength = Min( mnCurLen, nPartLen ); + + mnPartPos = 0; + + if( nLength ) + { + rPartString = NMSP_RTL::OUString( mpBuffer, nLength ); + mnPartPos = nLength; + } + + return( rPartString.getLength() > 0 ); +} + +// ----------------------------------------------------------------------------- + +sal_Bool FastString::GetNextPartString( const sal_uInt32 nPartLen, NMSP_RTL::OUString& rPartString ) +{ + if( mnPartPos < mnCurLen ) + { + const sal_uInt32 nLength = Min( mnCurLen - mnPartPos, nPartLen ); + rPartString = NMSP_RTL::OUString( mpBuffer + mnPartPos, nLength ); + mnPartPos += nLength; + } + else + rPartString = NMSP_RTL::OUString(); + + return( rPartString.getLength() > 0 ); +} + +// ---------------------- +// - SVGAttributeWriter - +// ---------------------- + +SVGAttributeWriter::SVGAttributeWriter( SVGActionWriter& rParent, SvXMLExport& rExport ) : + mrParent( rParent ), + mrExport( rExport ), + mpElemFont( NULL ), + mpElemPaint( NULL ) +{ +} + +// ----------------------------------------------------------------------------- + +SVGAttributeWriter::~SVGAttributeWriter() +{ + delete mpElemPaint; + delete mpElemFont; +} + +// ----------------------------------------------------------------------------- + +NMSP_RTL::OUString SVGAttributeWriter::GetFontStyle( const Font& rFont ) +{ + FastString aStyle; + + // font family + aStyle += B2UCONST( "font-family:" ); + aStyle += NMSP_RTL::OUString( UniString( rFont.GetName() ) ); + + // font size + const Size aFontSize( mrParent.GetVDev().LogicToLogic( Size( 0, rFont.GetHeight() ), mrParent.GetVDev().GetMapMode(), MAP_POINT ) ); + + aStyle += B2UCONST( ";" ); + aStyle += B2UCONST( "font-size:" ); + aStyle += NMSP_RTL::OUString::valueOf( aFontSize.Height() ); + + if( !mrParent.HasDoublePoints() ) + aStyle += B2UCONST( "pt" ); + + // font style + if( rFont.GetItalic() != ITALIC_NONE ) + { + aStyle += B2UCONST( ";" ); + aStyle += B2UCONST( "font-style:" ); + + if( rFont.GetItalic() == ITALIC_OBLIQUE ) + aStyle += B2UCONST( "oblique" ); + else + aStyle += B2UCONST( "italic" ); + } + + // font weight + sal_Int32 nFontWeight; + + switch( rFont.GetWeight() ) + { + case WEIGHT_THIN: nFontWeight = 100; break; + case WEIGHT_ULTRALIGHT: nFontWeight = 200; break; + case WEIGHT_LIGHT: nFontWeight = 300; break; + case WEIGHT_SEMILIGHT: nFontWeight = 400; break; + case WEIGHT_NORMAL: nFontWeight = 400; break; + case WEIGHT_MEDIUM: nFontWeight = 500; break; + case WEIGHT_SEMIBOLD: nFontWeight = 600; break; + case WEIGHT_BOLD: nFontWeight = 700; break; + case WEIGHT_ULTRABOLD: nFontWeight = 800; break; + case WEIGHT_BLACK: nFontWeight = 900; break; + default: nFontWeight = 400; break; + } + + aStyle += B2UCONST( ";" ); + aStyle += B2UCONST( "font-weight:" ); + aStyle += NMSP_RTL::OUString::valueOf( nFontWeight ); + + // !!! + // font-variant + // font-stretch + // font-size-adjust + +#ifdef _SVG_WRITE_STRIKEOUT + + if( rFont.GetUnderline() != UNDERLINE_NONE || rFont.GetStrikeout() != STRIKEOUT_NONE ) + { + aStyle += B2UCONST( ";" ); + aStyle += B2UCONST( "text-decoration:" ); + + if( rFont.GetUnderline() != UNDERLINE_NONE ) + aStyle += B2UCONST( " underline" ); + + if( rFont.GetStrikeout() != STRIKEOUT_NONE ) + aStyle += B2UCONST( " line-trough" ); + } + +#else // _SVG_WRITE_STRIKEOUT + + if( rFont.GetUnderline() != UNDERLINE_NONE ) + { + aStyle += B2UCONST( ";" ); + aStyle += B2UCONST( "text-decoration:" ); + aStyle += B2UCONST( "underline" ); + } + +#endif // _SVG_WRITE_STRIKEOUT + + return aStyle.GetString(); +} + +// ----------------------------------------------------------------------------- + +NMSP_RTL::OUString SVGAttributeWriter::GetPaintStyle( const Color& rLineColor, const Color& rFillColor ) +{ + FastString aStyle; + + // line color + aStyle += B2UCONST( "stroke:" ); + + if( rLineColor.GetTransparency() == 255 ) + aStyle += B2UCONST( "none" ); + else + { + // line color value in rgb + aStyle += B2UCONST( "rgb(" ); + aStyle += NMSP_RTL::OUString::valueOf( (sal_Int32) rLineColor.GetRed() ); + aStyle += B2UCONST( "," ); + aStyle += NMSP_RTL::OUString::valueOf( (sal_Int32) rLineColor.GetGreen() ); + aStyle += B2UCONST( "," ); + aStyle += NMSP_RTL::OUString::valueOf( (sal_Int32) rLineColor.GetBlue() ); + aStyle += B2UCONST( ")" ); + + // line color opacity in percent if neccessary + if( rLineColor.GetTransparency() ) + { + aStyle += B2UCONST( ";" ); + aStyle += B2UCONST( "stroke-opacity:" ); + aStyle += NMSP_RTL::OUString::valueOf( (sal_Int32) ( ( 255 - (double) rLineColor.GetTransparency() ) / 2.55 ) ); + aStyle += B2UCONST( "%" ); + } + } + + // fill color + aStyle += B2UCONST( ";" ); + aStyle += B2UCONST( "fill:" ); + + if( rFillColor.GetTransparency() == 255 ) + aStyle += B2UCONST( "none" ); + else + { + // fill color value in rgb + aStyle += B2UCONST( "rgb(" ); + aStyle += NMSP_RTL::OUString::valueOf( (sal_Int32) rFillColor.GetRed() ); + aStyle += B2UCONST( "," ); + aStyle += NMSP_RTL::OUString::valueOf( (sal_Int32) rFillColor.GetGreen() ); + aStyle += B2UCONST( "," ); + aStyle += NMSP_RTL::OUString::valueOf( (sal_Int32) rFillColor.GetBlue() ); + aStyle += B2UCONST( ")" ); + + // fill color opacity in percent if neccessary + if( rFillColor.GetTransparency() ) + { + aStyle += B2UCONST( ";" ); + aStyle += B2UCONST( "fill-opacity:" ); + aStyle += NMSP_RTL::OUString::valueOf( (sal_Int32) ( ( 255 - (double) rFillColor.GetTransparency() ) / 2.55 ) ); + aStyle += B2UCONST( "%" ); + } + } + + return aStyle.GetString(); +} + +// ----------------------------------------------------------------------------- + +void SVGAttributeWriter::SetFontAttr( const Font& rFont ) +{ + if( !mpElemFont || ( rFont != maCurFont ) ) + { + delete mpElemPaint, mpElemPaint = NULL; + delete mpElemFont; + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStyle, GetFontStyle( maCurFont = rFont ) ); + mpElemFont = new SvXMLElementExport( mrExport, XML_NAMESPACE_NONE, aXMLElemG, TRUE, TRUE ); + } +} + +// ----------------------------------------------------------------------------- + +void SVGAttributeWriter::SetPaintAttr( const Color& rLineColor, const Color& rFillColor ) +{ + if( !mpElemPaint || ( rLineColor != maCurLineColor ) || ( rFillColor != maCurFillColor ) ) + { + delete mpElemPaint; + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStyle, GetPaintStyle( maCurLineColor = rLineColor, maCurFillColor = rFillColor ) ); + mpElemPaint = new SvXMLElementExport( mrExport, XML_NAMESPACE_NONE, aXMLElemG, TRUE, TRUE ); + } +} + +// ------------------- +// - SVGActionWriter - +// ------------------- + +SVGActionWriter::SVGActionWriter( SvXMLExport& rExport, const GDIMetaFile& rMtf, + VirtualDevice* pParentVDev, sal_Bool bWriteDoublePoints ) : + mrExport( rExport ), + mrMtf( rMtf ), + mpContext( NULL ), + mbClipAttrChanged( sal_False ), + mnCurClipId( 1 ), + mbDoublePoints( bWriteDoublePoints ) +{ + if( pParentVDev ) + { + mpVDev = pParentVDev; + mbDestroyVDev = sal_False; + maTargetMapMode = mpVDev->GetMapMode(); + } + else + { + mpVDev = new VirtualDevice; + mpVDev->EnableOutput( sal_False ); + mbDestroyVDev = sal_True; + maTargetMapMode = MAP_100TH_MM; + } + + mpVDev->Push(); + mpVDev->SetMapMode( mrMtf.GetPrefMapMode() ); + ImplWriteActions( mrMtf ); + mpVDev->Pop(); +} + +// ----------------------------------------------------------------------------- + +SVGActionWriter::~SVGActionWriter() +{ + DBG_ASSERT( !mpContext, "Not all contexts are closed" ); + + if( mbDestroyVDev ) + delete mpVDev; +} + +// ----------------------------------------------------------------------------- + +long SVGActionWriter::ImplMap( sal_Int32 nVal ) const +{ + return ImplMap( Size( nVal, nVal ) ).Width(); +} + +// ----------------------------------------------------------------------------- + +Point SVGActionWriter::ImplMap( const Point& rPt ) const +{ + return mpVDev->LogicToLogic( rPt, mpVDev->GetMapMode(), maTargetMapMode ); +} + +// ----------------------------------------------------------------------------- + +Size SVGActionWriter::ImplMap( const Size& rSz ) const +{ + return mpVDev->LogicToLogic( rSz, mpVDev->GetMapMode(), maTargetMapMode ); +} + +// ----------------------------------------------------------------------------- + +NMSP_RTL::OUString SVGActionWriter::GetValueString( sal_Int32 nVal, sal_Bool bDoublePoints ) +{ + if( !bDoublePoints ) + return NMSP_RTL::OUString::valueOf( nVal ); + else + { + const double fPoints = nVal * 72.0 / 2540.0; + const sal_Int32 nInt = (sal_Int32) fPoints; + + return( ( NMSP_RTL::OUString::valueOf( nInt ) += + NMSP_RTL::OUString::valueOf( (sal_Unicode) '.' ) ) += + NMSP_RTL::OUString::valueOf( labs( (sal_Int32) ( ( fPoints - nInt ) * 100.0 ) ) ) ); + } +} + +// ----------------------------------------------------------------------------- + +void SVGActionWriter::ImplWriteLine( const Point& rPt1, const Point& rPt2, const Color* pLineColor, + const NMSP_RTL::OUString* pStyle ) +{ + const Point aPt1( ImplMap( rPt1 ) ); + const Point aPt2( ImplMap( rPt2 ) ); + + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX1, GetValueString( aPt1.X(), mbDoublePoints ) ); + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY1, GetValueString( aPt1.Y(), mbDoublePoints ) ); + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX2, GetValueString( aPt2.X(), mbDoublePoints ) ); + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY2, GetValueString( aPt2.Y(), mbDoublePoints ) ); + + // add additional style if requested + if( pStyle ) + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStyle, *pStyle ); + + if( pLineColor ) + { + // !!! mrExport.AddAttribute( XML_NAMESPACE_NONE, ... ) + DBG_ERROR( "SVGActionWriter::ImplWriteLine: Line color not implemented" ); + } + + { + SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemLine, TRUE, TRUE ); + } +} + +// ----------------------------------------------------------------------------- + +void SVGActionWriter::ImplWriteRect( const Rectangle& rRect, long nRadX, long nRadY, + const NMSP_RTL::OUString* pStyle ) +{ + const Rectangle aRect( ImplMap( rRect ) ); + + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX, GetValueString( aRect.Left(), mbDoublePoints ) ); + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY, GetValueString( aRect.Top(), mbDoublePoints ) ); + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrWidth, GetValueString( aRect.GetWidth(), mbDoublePoints ) ); + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrHeight, GetValueString( aRect.GetHeight(), mbDoublePoints ) ); + + if( nRadX ) + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrRX, GetValueString( ImplMap( nRadX ), mbDoublePoints ) ); + + if( nRadY ) + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrRY, GetValueString( ImplMap( nRadY ), mbDoublePoints ) ); + + // add additional style if requested + if( pStyle ) + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStyle, *pStyle ); + + { + SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemRect, TRUE, TRUE ); + } +} + +// ----------------------------------------------------------------------------- + +void SVGActionWriter::ImplWriteEllipse( const Point& rCenter, long nRadX, long nRadY, + const NMSP_RTL::OUString* pStyle ) +{ + const Point aCenter( ImplMap( rCenter ) ); + + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrCX, GetValueString( aCenter.X(), mbDoublePoints ) ); + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrCY, GetValueString( aCenter.Y(), mbDoublePoints ) ); + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrRX, GetValueString( ImplMap( nRadX ), mbDoublePoints ) ); + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrRY, GetValueString( ImplMap( nRadY ), mbDoublePoints ) ); + + // add additional style if requested + if( pStyle ) + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStyle, *pStyle ); + + { + SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemEllipse, TRUE, TRUE ); + } +} + +// ----------------------------------------------------------------------------- + +void SVGActionWriter::ImplWritePolygon( const Polygon& rPoly, sal_Bool bLineOnly, + const NMSP_RTL::OUString* pStyle ) +{ + if( rPoly.GetSize() ) + { + FastString aStyle; + FastString aPoints; + USHORT i = 0, nSize = rPoly.GetSize(); + const NMSP_RTL::OUString aBlank( B2UCONST( " " ) ); + + // points + while( i < nSize ) + { + const Point aPolyPoint( ImplMap( rPoly[ i ] ) ); + + aPoints += GetValueString( aPolyPoint.X(), mbDoublePoints ); + aPoints += B2UCONST( "," ); + aPoints += GetValueString( aPolyPoint.Y(), mbDoublePoints ); + + if( ++i < nSize ) + aPoints += aBlank; + } + + // style + if( bLineOnly ) + { + aStyle += B2UCONST( "fill:none" ); + + if( pStyle ) + { + aStyle += B2UCONST( ";" ); + aStyle += *pStyle; + } + } + else if( pStyle ) + aStyle += *pStyle; + + // add point attribute + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrPoints, aPoints.GetString() ); + + // add style attribute + if( aStyle.GetLength() ) + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStyle, aStyle.GetString() ); + + { + // write polyline/polygon element + SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, bLineOnly ? aXMLElemPolyLine : aXMLElemPolygon, TRUE, TRUE ); + } + } +} + +// ----------------------------------------------------------------------------- + +void SVGActionWriter::ImplWritePolyPolygon( const PolyPolygon& rPolyPoly, sal_Bool bLineOnly, + const NMSP_RTL::OUString* pStyle ) +{ + if( rPolyPoly.Count() ) + { + if( rPolyPoly.Count() == 1 ) + ImplWritePolygon( rPolyPoly[ 0 ], bLineOnly, pStyle ); + else if( bLineOnly ) + { + for( long i = 0, nCount = rPolyPoly.Count(); i < nCount; i++ ) + ImplWritePolygon( rPolyPoly[ i ], sal_False, pStyle ); + } + else + { + FastString aPathData; + const NMSP_RTL::OUString aBlank( B2UCONST( " " ) ); + const NMSP_RTL::OUString aComma( B2UCONST( "," ) ); + Point aPolyPoint; + + for( long i = 0, nCount = rPolyPoly.Count(); i < nCount; i++ ) + { + const Polygon& rPoly = rPolyPoly[ i ]; + USHORT n = 1, nSize = rPoly.GetSize(); + + if( nSize > 1 ) + { + aPathData += B2UCONST( "M " ); + aPathData += GetValueString( ( aPolyPoint = ImplMap( rPoly[ 0 ] ) ).X(), mbDoublePoints ); + aPathData += aComma; + aPathData += GetValueString( aPolyPoint.Y(), mbDoublePoints ); + aPathData += B2UCONST( " L " ); + + while( n < nSize ) + { + aPathData += GetValueString( ( aPolyPoint = ImplMap( rPoly[ n ] ) ).X(), mbDoublePoints ); + aPathData += aComma; + aPathData += GetValueString( aPolyPoint.Y(), mbDoublePoints ); + + if( ++n < nSize ) + aPathData += aBlank; + } + + aPathData += B2UCONST( " Z" ); + + if( i < ( nCount - 1 ) ) + aPathData += aBlank; + } + } + + // add style attribute + if( pStyle && pStyle->getLength() ) + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStyle, *pStyle ); + + // add path data attribute + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrD, aPathData.GetString() ); + + { + // write polyline/polygon element + SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemPath, TRUE, TRUE ); + } + } + } +} + +// ----------------------------------------------------------------------------- + +void SVGActionWriter::ImplWriteGradientEx( const PolyPolygon& rPolyPoly, const Gradient& rGradient, + const NMSP_RTL::OUString* pStyle ) +{ + if( rPolyPoly.Count() ) + { + SvXMLElementExport aElemG( mrExport, XML_NAMESPACE_NONE, aXMLElemG, TRUE, TRUE ); + FastString aClipId; + FastString aClipStyle; + + aClipId += B2UCONST( "clip" ); + aClipId += NMSP_RTL::OUString::valueOf( ImplGetNextClipId() ); + + { + SvXMLElementExport aElemDefs( mrExport, XML_NAMESPACE_NONE, aXMLElemDefs, TRUE, TRUE ); + + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrId, aClipId.GetString() ); + + { + SvXMLElementExport aElemClipPath( mrExport, XML_NAMESPACE_NONE, aXMLElemClipPath, TRUE, TRUE ); + ImplWritePolyPolygon( rPolyPoly, sal_False ); + } + } + + // create new context with clippath set + aClipStyle += B2UCONST( "clip-path:URL(#" ); + aClipStyle += aClipId.GetString(); + aClipStyle += B2UCONST( ")" ); + + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStyle, aClipStyle.GetString() ); + + { + GDIMetaFile aTmpMtf; + SvXMLElementExport aElemG( mrExport, XML_NAMESPACE_NONE, aXMLElemG, TRUE, TRUE ); + + mpVDev->AddGradientActions( rPolyPoly.GetBoundRect(), rGradient, aTmpMtf ); + ImplWriteActions( aTmpMtf, pStyle ); + } + } +} + +// ----------------------------------------------------------------------------- + +void SVGActionWriter::ImplWriteText( const Point& rPos, const String& rText, + const long* pDXArray, long nWidth, + const NMSP_RTL::OUString* pStyle ) +{ + String aText( rText ); aText.EraseLeadingChars( ' ' ); + UINT32 nLen = aText.Len(), i; + + if( nLen ) + { + Size aNormSize; + long* pOwnArray; + long* pDX; + + // get text sizes + if( pDXArray ) + { + pOwnArray = NULL; +#ifdef _SVG_UNO3 + aNormSize = Size( mpVDev->GetTextWidth( aText ), 0 ); +#else + aNormSize = mpVDev->GetTextSize( aText ); +#endif + pDX = (long*) pDXArray; + } + else + { + pOwnArray = new long[ nLen ]; +#ifdef _SVG_UNO3 + aNormSize = Size( mpVDev->GetTextArray( aText, pOwnArray ), 0 ); +#else + aNormSize = mpVDev->GetTextArray( aText, pOwnArray ); +#endif + pDX = pOwnArray; + } + + if( nLen > 1 ) + { +#ifdef _SVG_UNO3 + aNormSize.Width() = pDX[ nLen - 2 ] + mpVDev->GetTextWidth( aText.GetChar( nLen - 1 ) ); +#else + aNormSize.Width() = pDX[ nLen - 2 ] + mpVDev->GetTextSize( aText[ (USHORT) ( nLen - 1 ) ] ).Width(); +#endif + + if( nWidth && aNormSize.Width() && ( nWidth != aNormSize.Width() ) ) + { + const double fFactor = (double) nWidth / aNormSize.Width(); + + for( i = 0; i < ( nLen - 1 ); i++ ) + pDX[ i ] = FRound( pDX[ i ] * fFactor ); + } + } + + FastString aStyle; + const Font& rFont = mpVDev->GetFont(); + const FontMetric aMetric( mpVDev->GetFontMetric() ); + Point aBaseLinePos( rPos ); + + // leading whitespaces erased? => adjust position + if( nLen < rText.Len() ) + { +#ifdef _SVG_UNO3 + aBaseLinePos.X() += mpVDev->GetTextWidth( ' ' ) * ( rText.Len() - nLen ); +#else + aBaseLinePos.X() += mpVDev->GetTextSize( ' ' ).Width() * ( rText.Len() - nLen ); +#endif + } + + // always adjust text position to match baseline alignment + switch( rFont.GetAlign() ) + { + case( ALIGN_TOP ): + aBaseLinePos.Y() += aMetric.GetAscent(); + break; + + case( ALIGN_BOTTOM ): + aBaseLinePos.Y() -= aMetric.GetDescent(); + break; + + default: + break; + } + + // get mapped text position + const Point aPt( ImplMap( aBaseLinePos ) ); + + // add additional style if requested + if( pStyle && pStyle->getLength() ) + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStyle, *pStyle ); + + // write text element +#ifdef _SVG_WRITE_TSPAN + if( pDXArray ) + { + SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemText, TRUE, TRUE ); + FastString aTSpanX; + const NMSP_RTL::OUString aSpace( ' ' ); + long i, nX, nCount; + + aTSpanX += GetValueString( aPt.X(), mbDoublePoints ); + aTSpanX += aSpace; + + for( i = 0, nX = aPt.X(), nCount = ( nLen - 1 ); i < nCount; ) + { + aTSpanX += GetValueString( aPt.X() + pDX[ i++ ], mbDoublePoints ); + aTSpanX += aSpace; + } + + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX, aTSpanX.GetString() ); + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY, GetValueString( aPt.Y(), mbDoublePoints ) ); + + { + SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemTSpan, TRUE, TRUE ); + mrExport.GetDocHandler()->characters( NMSP_RTL::OUString( UniString( aText ) ) ); + } + } + else +#endif // _SVG_WRITE_TSPAN + { + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX, GetValueString( aPt.X(), mbDoublePoints ) ); + mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY, GetValueString( aPt.Y(), mbDoublePoints ) ); + + SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemText, TRUE, TRUE ); + mrExport.GetDocHandler()->characters( NMSP_RTL::OUString( UniString( aText ) ) ); + } +#ifndef _SVG_WRITE_STRIKEOUT + + // write strikeout if neccessary + if( rFont.GetStrikeout() ) + { + const long nYStrikeoutPos = aBaseLinePos.Y() - FRound( aMetric.GetAscent() * 0.26 ); + const long nStrikeoutHeight = Max( (long) FRound( aMetric.GetLineHeight() * 0.05 ), (long) 1 ); + Polygon aPoly( 4 ); + + aPoly[ 0 ].X() = aBaseLinePos.X(); aPoly[ 0 ].Y() = nYStrikeoutPos - ( nStrikeoutHeight >> 1 ); + aPoly[ 1 ].X() = aBaseLinePos.X() + aNormSize.Width() - 1; aPoly[ 1 ].Y() = aPoly[ 0 ].Y(); + aPoly[ 2 ].X() = aPoly[ 1 ].X(); aPoly[ 2 ].Y() = aPoly[ 0 ].Y() + nStrikeoutHeight - 1; + aPoly[ 3 ].X() = aPoly[ 0 ].X(); aPoly[ 3 ].Y() = aPoly[ 2 ].Y(); + + ImplWritePolygon( aPoly, FALSE ); + } + +#endif // _SVG_WRITE_STRIKEOUT + + delete[] pOwnArray; + } +} + +// ----------------------------------------------------------------------------- + +void SVGActionWriter::ImplWriteBmp( const BitmapEx& rBmpEx, + const Point& rPt, const Size& rSz, + const Point& rSrcPt, const Size& rSrcSz, + const NMSP_RTL::OUString* pStyle ) +{ + if( !!rBmpEx ) + { + BitmapEx aBmpEx( rBmpEx ); + Point aPoint = Point(); + const Rectangle aBmpRect( aPoint, rBmpEx.GetSizePixel() ); + const Rectangle aSrcRect( rSrcPt, rSrcSz ); + + if( aSrcRect != aBmpRect ) + aBmpEx.Crop( aSrcRect ); + + if( !!aBmpEx ) + { + SvMemoryStream aOStm( 65535, 65535 ); + + if( GraphicConverter::Export( aOStm, rBmpEx, CVT_PNG ) == ERRCODE_NONE ) + { + const Point aPt( ImplMap( rPt ) ); + const Size aSz( ImplMap( rSz ) ); + FastString aImageData( (sal_Char*) aOStm.GetData(), aOStm.Tell() ); +#ifndef _SVG_UNO3 + XExtendedDocumentHandlerRef xExtDocHandler( mrExport.GetDocHandler(), USR_QUERY ); +#else + REF( NMSP_SAX::XExtendedDocumentHandler ) xExtDocHandler( mrExport.GetDocHandler(), NMSP_UNO::UNO_QUERY ); +#endif + + if( xExtDocHandler.is() ) + { + static const sal_uInt32 nPartLen = 64; + const NMSP_RTL::OUString aSpace( ' ' ); + const NMSP_RTL::OUString aLineFeed( NMSP_RTL::OUString::valueOf( (sal_Unicode) 0x0a ) ); + NMSP_RTL::OUString aString; + NMSP_RTL::OUString aImageString; + + aString = aLineFeed; + aString += B2UCONST( "<" ); + aString += NMSP_RTL::OUString::createFromAscii( aXMLElemImage ); + aString += aSpace; + + aString += NMSP_RTL::OUString::createFromAscii( aXMLAttrX ); + aString += B2UCONST( "=\"" ); + aString += GetValueString( aPt.X(), mbDoublePoints ); + aString += B2UCONST( "\" " ); + + aString += NMSP_RTL::OUString::createFromAscii( aXMLAttrY ); + aString += B2UCONST( "=\"" ); + aString += GetValueString( aPt.Y(), mbDoublePoints ); + aString += B2UCONST( "\" " ); + + aString += NMSP_RTL::OUString::createFromAscii( aXMLAttrWidth ); + aString += B2UCONST( "=\"" ); + aString += GetValueString( aSz.Width(), mbDoublePoints ); + aString += B2UCONST( "\" " ); + + aString += NMSP_RTL::OUString::createFromAscii( aXMLAttrHeight ); + aString += B2UCONST( "=\"" ); + aString += GetValueString( aSz.Height(), mbDoublePoints ); + aString += B2UCONST( "\" " ); + + aString += NMSP_RTL::OUString::createFromAscii( aXMLAttrXLinkHRef ); + aString += B2UCONST( "=\"data:image/png;base64," ); + + if( aImageData.GetFirstPartString( nPartLen, aImageString ) ) + { + xExtDocHandler->unknown( aString += aImageString ); + + while( aImageData.GetNextPartString( nPartLen, aImageString ) ) + { + xExtDocHandler->unknown( aLineFeed ); + xExtDocHandler->unknown( aImageString ); + } + } + + xExtDocHandler->unknown( B2UCONST( "\"/>" ) ); + } + } + } + } +} + +// ----------------------------------------------------------------------------- + +void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf, const NMSP_RTL::OUString* pStyle ) +{ + ImplAcquireContext(); + + for( ULONG i = 0, nCount = rMtf.GetActionCount(); i < nCount; i++ ) + { + const MetaAction* pAction = rMtf.GetAction( i ); + const USHORT nType = pAction->GetType(); + + switch( nType ) + { + case( META_PIXEL_ACTION ): + { + const MetaPixelAction* pA = (const MetaPixelAction*) pAction; + + mpContext->SetPaintAttr( pA->GetColor(), pA->GetColor() ); + ImplWriteLine( pA->GetPoint(), pA->GetPoint(), &pA->GetColor(), pStyle ); + } + break; + + case( META_POINT_ACTION ): + { + const MetaPointAction* pA = (const MetaPointAction*) pAction; + + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetLineColor() ); + ImplWriteLine( pA->GetPoint(), pA->GetPoint(), NULL, pStyle ); + } + break; + + case( META_LINE_ACTION ): + { + const MetaLineAction* pA = (const MetaLineAction*) pAction; + + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetLineColor() ); + ImplWriteLine( pA->GetStartPoint(), pA->GetEndPoint(), NULL, pStyle ); + } + break; + + case( META_RECT_ACTION ): + { + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + ImplWriteRect( ( (const MetaRectAction*) pAction )->GetRect(), 0, 0, pStyle ); + } + break; + + case( META_ROUNDRECT_ACTION ): + { + const MetaRoundRectAction* pA = (const MetaRoundRectAction*) pAction; + + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + ImplWriteRect( pA->GetRect(), pA->GetHorzRound(), pA->GetVertRound(), pStyle ); + } + break; + + case( META_ELLIPSE_ACTION ): + { + const MetaEllipseAction* pA = (const MetaEllipseAction*) pAction; + const Rectangle& rRect = pA->GetRect(); + + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + ImplWriteEllipse( rRect.Center(), rRect.GetWidth() >> 1, rRect.GetHeight() >> 1, pStyle ); + } + break; + + case( META_ARC_ACTION ): + case( META_PIE_ACTION ): + case( META_CHORD_ACTION ): + case( META_POLYGON_ACTION ): + { + 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; + } + + if( aPoly.GetSize() ) + { + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + ImplWritePolygon( aPoly, sal_False, pStyle ); + } + } + break; + + case( META_POLYLINE_ACTION ): + { + const MetaPolyLineAction* pA = (const MetaPolyLineAction*) pAction; + const Polygon& rPoly = pA->GetPolygon(); + + if( rPoly.GetSize() ) + { + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + ImplWritePolygon( rPoly, sal_True, pStyle ); + } + } + break; + + case( META_POLYPOLYGON_ACTION ): + { + const MetaPolyPolygonAction* pA = (const MetaPolyPolygonAction*) pAction; + const PolyPolygon& rPolyPoly = pA->GetPolyPolygon(); + + if( rPolyPoly.Count() ) + { + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + ImplWritePolyPolygon( rPolyPoly, sal_False, pStyle ); + } + } + break; + + case( META_GRADIENT_ACTION ): + { + const MetaGradientAction* pA = (const MetaGradientAction*) pAction; + GDIMetaFile aTmpMtf; + + mpVDev->AddGradientActions( pA->GetRect(), pA->GetGradient(), aTmpMtf ); + ImplWriteActions( aTmpMtf, pStyle ); + } + break; + + case( META_GRADIENTEX_ACTION ): + { + const MetaGradientExAction* pA = (const MetaGradientExAction*) pAction; + ImplWriteGradientEx( pA->GetPolyPolygon(), pA->GetGradient(), pStyle ); + } + break; + + case META_HATCH_ACTION: + { + const MetaHatchAction* pA = (const MetaHatchAction*) pAction; + GDIMetaFile aTmpMtf; + + mpVDev->AddHatchActions( pA->GetPolyPolygon(), pA->GetHatch(), aTmpMtf ); + ImplWriteActions( aTmpMtf, pStyle ); + } + break; + + case( META_TRANSPARENT_ACTION ): + { + // !!! + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + DBG_ERROR( "META_TRANSPARENT_ACTION not supported" ); + } + break; + + case( META_FLOATTRANSPARENT_ACTION ): + { + // !!! + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + DBG_ERROR( "META_FLOATTRANSPARENT_ACTION not supported" ); + } + break; + + case( META_EPS_ACTION ): + { + const MetaEPSAction* pA = (const MetaEPSAction*) pAction; + const GDIMetaFile aGDIMetaFile( pA->GetSubstitute() ); + sal_Bool bFound = sal_False; + + for( ULONG i = 0, nCount = aGDIMetaFile.GetActionCount(); ( i < nCount ) && !bFound; i++ ) + { + const MetaAction* pSubstAct = aGDIMetaFile.GetAction( i ); + + if( pSubstAct->GetType() == META_BMPSCALE_ACTION ) + { + bFound = sal_True; + const MetaBmpScaleAction* pBmpScaleAction = (const MetaBmpScaleAction*) pAction; + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + ImplWriteBmp( pBmpScaleAction->GetBitmap(), + pBmpScaleAction->GetPoint(), pBmpScaleAction->GetSize(), + Point(), pBmpScaleAction->GetBitmap().GetSizePixel(), pStyle ); + } + } + } + break; + + case( META_COMMENT_ACTION ): + { + const MetaCommentAction* pA = (const MetaCommentAction*) pAction; + String aSkipComment; + +#ifndef _SVG_UNO3 + if( pA->GetComment().ICompare( "XGRAD_SEQ_BEGIN" ) == COMPARE_EQUAL ) +#else + if( pA->GetComment().CompareIgnoreCaseToAscii( "XGRAD_SEQ_BEGIN" ) == COMPARE_EQUAL ) +#endif + { + const MetaGradientExAction* pGradAction = NULL; + sal_Bool bDone = sal_False; + + while( !bDone && ( ++i < nCount ) ) + { + pAction = rMtf.GetAction( i ); + + if( pAction->GetType() == META_GRADIENTEX_ACTION ) + pGradAction = (const MetaGradientExAction*) pAction; + else if( ( pAction->GetType() == META_COMMENT_ACTION ) && +#ifndef _SVG_UNO3 + ( ( (const MetaCommentAction*) pAction )->GetComment().ICompare( "XGRAD_SEQ_END" ) == COMPARE_EQUAL ) ) + +#else + ( ( (const MetaCommentAction*) pAction )->GetComment().CompareIgnoreCaseToAscii( "XGRAD_SEQ_END" ) == COMPARE_EQUAL ) ) +#endif + { + bDone = sal_True; + } + } + + if( pGradAction ) + ImplWriteGradientEx( pGradAction->GetPolyPolygon(), pGradAction->GetGradient(), pStyle ); + } + } + break; + + case( META_BMP_ACTION ): + { + const MetaBmpAction* pA = (const MetaBmpAction*) pAction; + + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + ImplWriteBmp( pA->GetBitmap(), + pA->GetPoint(), mpVDev->PixelToLogic( pA->GetBitmap().GetSizePixel() ), + Point(), pA->GetBitmap().GetSizePixel(), pStyle ); + } + break; + + case( META_BMPSCALE_ACTION ): + { + const MetaBmpScaleAction* pA = (const MetaBmpScaleAction*) pAction; + + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + ImplWriteBmp( pA->GetBitmap(), + pA->GetPoint(), pA->GetSize(), + Point(), pA->GetBitmap().GetSizePixel(), pStyle ); + } + break; + + case( META_BMPSCALEPART_ACTION ): + { + const MetaBmpScalePartAction* pA = (const MetaBmpScalePartAction*) pAction; + + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + ImplWriteBmp( pA->GetBitmap(), + pA->GetDestPoint(), pA->GetDestSize(), + pA->GetSrcPoint(), pA->GetSrcSize(), pStyle ); + } + break; + + case( META_BMPEX_ACTION ): + { + const MetaBmpExAction* pA = (const MetaBmpExAction*) pAction; + + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + ImplWriteBmp( pA->GetBitmapEx(), + pA->GetPoint(), mpVDev->PixelToLogic( pA->GetBitmapEx().GetSizePixel() ), + Point(), pA->GetBitmapEx().GetSizePixel(), pStyle ); + } + break; + + case( META_BMPEXSCALE_ACTION ): + { + const MetaBmpExScaleAction* pA = (const MetaBmpExScaleAction*) pAction; + + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + ImplWriteBmp( pA->GetBitmapEx(), + pA->GetPoint(), pA->GetSize(), + Point(), pA->GetBitmapEx().GetSizePixel(), pStyle ); + } + break; + + case( META_BMPEXSCALEPART_ACTION ): + { + const MetaBmpExScalePartAction* pA = (const MetaBmpExScalePartAction*) pAction; + + mpContext->SetPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() ); + ImplWriteBmp( pA->GetBitmapEx(), + pA->GetDestPoint(), pA->GetDestSize(), + pA->GetSrcPoint(), pA->GetSrcSize(), pStyle ); + } + break; + + case( META_TEXT_ACTION ): + { + const MetaTextAction* pA = (const MetaTextAction*) pAction; + + mpContext->SetFontAttr( mpVDev->GetFont() ); + mpContext->SetPaintAttr( COL_TRANSPARENT, mpVDev->GetFont().GetColor() ); + ImplWriteText( pA->GetPoint(), String( pA->GetText(), pA->GetIndex(), pA->GetLen() ), NULL, 0, pStyle ); + } + break; + + case( META_TEXTRECT_ACTION ): + { + const MetaTextRectAction* pA = (const MetaTextRectAction*) pAction; + + mpContext->SetFontAttr( mpVDev->GetFont() ); + mpContext->SetPaintAttr( COL_TRANSPARENT, mpVDev->GetFont().GetColor() ); + ImplWriteText( pA->GetRect().TopLeft(), pA->GetText(), NULL, 0, pStyle ); + } + break; + + case( META_TEXTARRAY_ACTION ): + { + const MetaTextArrayAction* pA = (const MetaTextArrayAction*) pAction; + const Point aPos( ImplMap( pA->GetPoint() ) ); + + mpContext->SetFontAttr( mpVDev->GetFont() ); + mpContext->SetPaintAttr( COL_TRANSPARENT, mpVDev->GetFont().GetColor() ); + ImplWriteText( pA->GetPoint(), String( pA->GetText(), pA->GetIndex(), pA->GetLen() ), pA->GetDXArray(), 0, pStyle ); + } + break; + + case( META_STRETCHTEXT_ACTION ): + { + const MetaStretchTextAction* pA = (const MetaStretchTextAction*) pAction; + + mpContext->SetFontAttr( mpVDev->GetFont() ); + mpContext->SetPaintAttr( COL_TRANSPARENT, mpVDev->GetFont().GetColor() ); + ImplWriteText( pA->GetPoint(), String( pA->GetText(), pA->GetIndex(), pA->GetLen() ), NULL, pA->GetWidth(), pStyle ); + } + break; + + case( META_CLIPREGION_ACTION ): + case( META_ISECTRECTCLIPREGION_ACTION ): + case( META_ISECTREGIONCLIPREGION_ACTION ): + case( META_MOVECLIPREGION_ACTION ): + { + ( (MetaAction*) pAction )->Execute( mpVDev ); + mbClipAttrChanged = sal_True; + } + break; + + case( META_REFPOINT_ACTION ): + case( META_MAPMODE_ACTION ): + case( META_LINECOLOR_ACTION ): + case( META_FILLCOLOR_ACTION ): + case( META_TEXTLINECOLOR_ACTION ): + case( META_TEXTFILLCOLOR_ACTION ): + case( META_TEXTCOLOR_ACTION ): + case( META_TEXTALIGN_ACTION ): + case( META_FONT_ACTION ): + case( META_PUSH_ACTION ): + case( META_POP_ACTION ): + { + ( (MetaAction*) pAction )->Execute( mpVDev ); + } + break; + + case( META_RASTEROP_ACTION ): + case( META_MASK_ACTION ): + case( META_MASKSCALE_ACTION ): + case( META_MASKSCALEPART_ACTION ): + case( META_WALLPAPER_ACTION ): + case( META_TEXTLINE_ACTION ): + { + // !!! >>> we don't want to support these actions + } + break; + + default: + DBG_ERROR( "SVGActionWriter::ImplWriteActions: unsupported MetaAction #" ); + break; + } + } + + ImplReleaseContext(); +} diff --git a/extensions/source/svg/svgaction.hxx b/extensions/source/svg/svgaction.hxx new file mode 100644 index 000000000000..7fa159450a72 --- /dev/null +++ b/extensions/source/svg/svgaction.hxx @@ -0,0 +1,196 @@ +/************************************************************************* + * + * $RCSfile: svgaction.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _SVGACTION_HXX +#define _SVGACTION_HXX + +#include "svgcom.hxx" + +// -------------- +// - FastString - +// -------------- + +class FastString +{ +private: + + NMSP_RTL::OUString maString; + sal_Unicode* mpBuffer; + sal_uInt32 mnBufLen; + sal_uInt32 mnCurLen; + sal_uInt32 mnBufInc; + sal_uInt32 mnPartPos; + +public: + + FastString( sal_uInt32 nInitLen = 2048, sal_uInt32 nIncrement = 2048 ); + FastString( sal_Char* pBufferForBase64Encoding, sal_uInt32 nBufLen ); + ~FastString(); + + FastString& operator+=( const NMSP_RTL::OUString& rStr ); + + const NMSP_RTL::OUString& GetString() const; + sal_Bool GetFirstPartString( const sal_uInt32 nPartLen, NMSP_RTL::OUString& rPartString ); + sal_Bool GetNextPartString( const sal_uInt32 nPartLen, NMSP_RTL::OUString& rPartString ); + + sal_uInt32 GetLength() const { return mnCurLen; } + void Clear() { mnCurLen = 0, maString = NMSP_RTL::OUString(); } +}; + +// ---------------------- +// - SVGAttributeWriter - +// ---------------------- + +class SVGActionWriter; + +class SVGAttributeWriter +{ +private: + + Font maCurFont; + Color maCurLineColor; + Color maCurFillColor; + SVGActionWriter& mrParent; + SvXMLExport& mrExport; + SvXMLElementExport* mpElemFont; + SvXMLElementExport* mpElemPaint; + + SVGAttributeWriter(); + +public: + + SVGAttributeWriter( SVGActionWriter& rParent, SvXMLExport& rExport ); + virtual ~SVGAttributeWriter(); + + NMSP_RTL::OUString GetFontStyle( const Font& rFont ); + NMSP_RTL::OUString GetPaintStyle( const Color& rLineColor, const Color& rFillColor ); + + void SetFontAttr( const Font& rFont ); + void SetPaintAttr( const Color& rLineColor, const Color& rFillColor ); +}; + +// ------------------- +// - SVGActionWriter - +// ------------------- + +class SVGAttributeWriter; +class SvXMLExport; +class GDIMetaFile; + +class SVGActionWriter +{ +private: + + Stack maContextStack; + SvXMLExport& mrExport; + const GDIMetaFile& mrMtf; + SVGAttributeWriter* mpContext; + VirtualDevice* mpVDev; + MapMode maTargetMapMode; + sal_Int32 mnCurClipId; + sal_Bool mbDestroyVDev; + sal_Bool mbPaintAttrChanged; + sal_Bool mbFontAttrChanged; + sal_Bool mbClipAttrChanged; + sal_Bool mbDoublePoints; + + SVGAttributeWriter* ImplAcquireContext() { maContextStack.Push( mpContext = new SVGAttributeWriter( *this, mrExport ) ); return mpContext; } + void ImplReleaseContext() { delete (SVGAttributeWriter*) maContextStack.Pop(); mpContext = (SVGAttributeWriter*) maContextStack.Top(); } + + long ImplMap( sal_Int32 nVal ) const; + Point ImplMap( const Point& rPt ) const; + Size ImplMap( const Size& rSz ) const; + inline Rectangle ImplMap( const Rectangle& rRect ) const { return Rectangle( ImplMap( rRect.TopLeft() ), ImplMap( rRect.GetSize() ) ); } + + void ImplWriteLine( const Point& rPt1, const Point& rPt2, const Color* pLineColor = NULL, const NMSP_RTL::OUString* pStyle = NULL ); + void ImplWriteRect( const Rectangle& rRect, long nRadX = 0, long nRadY = 0, const NMSP_RTL::OUString* pStyle = NULL ); + void ImplWriteEllipse( const Point& rCenter, long nRadX, long nRadY, const NMSP_RTL::OUString* pStyle = NULL ); + void ImplWritePolygon( const Polygon& rPoly, sal_Bool bLineOnly, const NMSP_RTL::OUString* pStyle = NULL ); + void ImplWritePolyPolygon( const PolyPolygon& rPolyPoly, sal_Bool bLineOnly, const NMSP_RTL::OUString* pStyle = NULL ); + void ImplWriteGradientEx( const PolyPolygon& rPolyPoly, const Gradient& rGradient, const NMSP_RTL::OUString* pStyle = NULL ); + void ImplWriteText( const Point& rPos, const String& rText, const long* pDXArray, long nWidth, const NMSP_RTL::OUString* pStyle = NULL ); + void ImplWriteBmp( const BitmapEx& rBmpEx, const Point& rPt, const Size& rSz, const Point& rSrcPt, const Size& rSrcSz, const NMSP_RTL::OUString* pStyle = NULL ); + + void ImplCheckFontAttributes(); + void ImplCheckPaintAttributes(); + + void ImplWriteActions( const GDIMetaFile& rMtf, const NMSP_RTL::OUString* pStyle = NULL ); + + sal_Int32 ImplGetNextClipId() { return mnCurClipId++; } + + SVGActionWriter(); + +public: + + static NMSP_RTL::OUString GetValueString( sal_Int32 nVal, sal_Bool bDoublePoints ); + +public: + + SVGActionWriter( SvXMLExport& rExport, const GDIMetaFile& rMtf, + VirtualDevice* pParentVDev = NULL, + sal_Bool bWriteDoublePoints = sal_False ); + virtual ~SVGActionWriter(); + + const VirtualDevice& GetVDev() const { return *mpVDev; } + BOOL HasDoublePoints() const { return mbDoublePoints; } +}; + +#endif diff --git a/extensions/source/svg/svgcom.hxx b/extensions/source/svg/svgcom.hxx new file mode 100644 index 000000000000..4827e95255fe --- /dev/null +++ b/extensions/source/svg/svgcom.hxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * $RCSfile: svgcom.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _SVGCOM_HXX +#define _SVGCOM_HXX + +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif +#ifndef __RTL_USTRING_ +#include <rtl/ustring> +#endif +#ifndef _DEBUG_HXX +#include <tools/debug.hxx> +#endif +#ifndef _STREAM_HXX +#include <tools/stream.hxx> +#endif +#ifndef _STRING_HXX +#include <tools/string.hxx> +#endif +#ifndef _URLOBJ_HXX +#include <tools/urlobj.hxx> +#endif +#ifndef _STACK_HXX +#include <tools/stack.hxx> +#endif +#ifndef _SALBTYPE_HXX +#include <vcl/salbtype.hxx> +#endif +#ifndef _GDIMTF_HXX +#include <vcl/gdimtf.hxx> +#endif +#ifndef _METAACT_HXX +#include <vcl/metaact.hxx> +#endif + +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> +#include <com/sun/star/svg/XSVGWriter.hpp> +#include <com/sun/star/svg/XSVGPrinter.hpp> + +#ifndef _XMLOFF_XMLEXP_HXX +#include <xmloff/xmlexp.hxx> +#endif +#ifndef _XMLOFF_NMSPMAP_HXX +#include <xmloff/nmspmap.hxx> +#endif + +// ----------------------------------------------------------------------------- + +#if SUPD >= 583 +#define _SVG_UNO3 1 +#else +#undef _SVG_UNO3 +#endif + +// ----------------------------------------------------------------------------- + +#define NMSP_CPPU cppu +#define NMSP_RTL rtl +#define NMSP_UNO com::sun::star::uno +#define NMSP_LANG com::sun::star::lang +#define NMSP_SAX com::sun::star::xml::sax +#define NMSP_SVG com::sun::star::svg +#define NMSP_REGISTRY com::sun::star::registry + + +#define REF( _def_Obj ) NMSP_UNO::Reference< _def_Obj > +#define SEQ( _def_Obj ) NMSP_UNO::Sequence< _def_Obj > +#define ANY NMSP_UNO::Any +#ifdef _SVG_UNO3 +#define B2UCONST( _def_pChar ) (NMSP_RTL::OUString(RTL_CONSTASCII_USTRINGPARAM(_def_pChar ))) +#else +#define B2UCONST( _def_pChar ) (NMSP_RTL::OUString::createFromAscii(_def_pChar)) +#endif + +#endif // _SYNCCOM_HXX diff --git a/extensions/source/svg/svgprinter.cxx b/extensions/source/svg/svgprinter.cxx new file mode 100644 index 000000000000..02cff8e4d25b --- /dev/null +++ b/extensions/source/svg/svgprinter.cxx @@ -0,0 +1,364 @@ +/************************************************************************* + * + * $RCSfile: svgprinter.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#define _RMPRINTER_EXT + +#include "svgprinter.hxx" +#include "svgaction.hxx" +#include <uno/mapping.hxx> +#include <vcl/print.hxx> +#include <vcl/virdev.hxx> + +static const char aXMLElemSVG[] = "svg"; +static const char aXMLElemMetaSVG[] = "staroffice:svgElementMeta"; +static const char aXMLElemDesc[] = "desc"; +static const char aXMLElemMeta[] = "metadata"; +static const char aXMLElemRect[] = "rect"; + +static const char aXMLAttrMetaSVGOuter[] = "isOuterElement"; +static const char aXMLAttrMetaSVGPage[] = "isPageElement"; +static const char aXMLAttrViewBox[] = "viewBox"; +static const char aXMLAttrX[] = "x"; +static const char aXMLAttrY[] = "y"; +static const char aXMLAttrWidth[] = "width"; +static const char aXMLAttrHeight[] = "height"; + +// ---------------- +// - SVGMtfExport - +// ---------------- + +class SVGPrinterExport : public SvXMLExport +{ +private: + + Printer maPrinter; + VirtualDevice* mpVDev; + SvXMLElementExport* mpOuterElement; + sal_uInt32 mnPage; + + SVGPrinterExport(); + + SvXMLElementExport* ImplCreateSVGElement( const JobSetup& rSetup, Size& rOutputSize ); + void ImplWriteMetaAttr( sal_Bool bOuter, sal_Bool bPage ); + +protected: + + virtual void _ExportMeta() {} + virtual void _ExportStyles( BOOL bUsed ) {} + virtual void _ExportAutoStyles() {} + virtual void _ExportContent() {} + virtual void _ExportMasterStyles() {} + virtual ULONG exportDoc( const char *pClass = 0 ) { return 0; } + +public: + +#ifndef _SVG_UNO3 + SVGPrinterExport( const XDocumentHandlerRef rxHandler, const JobSetup& rSetup, + const NMSP_RTL::OUString& rJobName, sal_uInt32 nCopies, sal_Bool bCollate ); +#else + SVGPrinterExport( const REF( NMSP_SAX::XDocumentHandler )& rxHandler, const JobSetup& rSetup, + const NMSP_RTL::OUString& rJobName, sal_uInt32 nCopies, sal_Bool bCollate ); +#endif + virtual ~SVGPrinterExport(); + + virtual void writePage( const JobSetup& rJobSetup, const GDIMetaFile& rMtf ); +}; + +// ----------------------------------------------------------------------------- + +#ifndef _SVG_UNO3 +SVGPrinterExport::SVGPrinterExport( const XDocumentHandlerRef rxHandler, const JobSetup& rSetup, + const NMSP_RTL::OUString& rJobName, sal_uInt32 nCopies, sal_Bool bCollate ) : +#else +SVGPrinterExport::SVGPrinterExport( const REF( NMSP_SAX::XDocumentHandler )& rxHandler, const JobSetup& rSetup, + const NMSP_RTL::OUString& rJobName, sal_uInt32 nCopies, sal_Bool bCollate ) : +#endif + SvXMLExport( NMSP_RTL::OUString(), rxHandler ), + mpVDev( NULL ), + mnPage( 0 ) +{ + maPrinter.SetJobSetup( rSetup ); + + GetDocHandler()->startDocument(); + +#ifndef _SVG_UNO3 + XExtendedDocumentHandlerRef xExtDocHandler( GetDocHandler(), USR_QUERY ); +#else + REF( NMSP_SAX::XExtendedDocumentHandler ) xExtDocHandler( GetDocHandler(), NMSP_UNO::UNO_QUERY ); +#endif + + if( xExtDocHandler.is() ) + { + NMSP_RTL::OUString aString; + const NMSP_RTL::OUString aLineFeed( NMSP_RTL::OUString::valueOf( (sal_Unicode) 0x0a ) ); + + // intro + xExtDocHandler->unknown( ( aString = B2UCONST( "<!DOCTYPE svg SYSTEM \"svg-19990812.dtd\" [" ) ) += aLineFeed ); + xExtDocHandler->unknown( ( aString = B2UCONST( "<!ELEMENT metadata (#PCDATA | staroffice:svgElementMeta)*> " ) += aLineFeed ) ); + xExtDocHandler->unknown( ( aString = B2UCONST( "<!ELEMENT staroffice:svgElementMeta ANY> " ) += aLineFeed ) ); + xExtDocHandler->unknown( ( aString = B2UCONST( "<!ATTLIST staroffice:svgElementMeta " ) += aLineFeed ) ); + + // ATTLIST + xExtDocHandler->unknown( ( aString = B2UCONST( "isOuterElement (true | false) \"false\" " ) += aLineFeed ) ); + xExtDocHandler->unknown( ( aString = B2UCONST( "isPageElement (true | false) \"true\"" ) += aLineFeed ) ); + + // end of intro + xExtDocHandler->unknown( ( aString = B2UCONST( ">" ) += aLineFeed ) ); + xExtDocHandler->unknown( ( aString = B2UCONST( "]>" ) ) ); + } + + // create outer element + Size aOutputSize; + + mpOuterElement = ImplCreateSVGElement( rSetup, aOutputSize ); + + // write description + SvXMLElementExport* pDescElem = new SvXMLElementExport( *this, XML_NAMESPACE_NONE, aXMLElemDesc, TRUE, TRUE ); + NMSP_RTL::OUString aDesc( B2UCONST( "document name: " ) ); + + GetDocHandler()->characters( aDesc += rJobName ); + delete pDescElem; + + // write meta attributes + ImplWriteMetaAttr( TRUE, FALSE ); +} + +// ----------------------------------------------------------------------------- + +SVGPrinterExport::~SVGPrinterExport() +{ + delete mpOuterElement; + GetDocHandler()->endDocument(); + delete mpVDev; +} + +// ----------------------------------------------------------------------------- + +SvXMLElementExport* SVGPrinterExport::ImplCreateSVGElement( const JobSetup& rSetup, Size& rOutputSize ) +{ + NMSP_RTL::OUString aAttr; + + delete mpVDev; + mpVDev = new VirtualDevice; + mpVDev->EnableOutput( FALSE ); + mpVDev->SetMapMode( MAP_100TH_MM ); + maPrinter.SetJobSetup( rSetup ); + + rOutputSize = maPrinter.PixelToLogic( maPrinter.GetOutputSizePixel(), mpVDev->GetMapMode() ); + + aAttr = SVGActionWriter::GetValueString( rOutputSize.Width(), sal_True ); + AddAttribute( XML_NAMESPACE_NONE, aXMLAttrWidth, aAttr ); + + aAttr = SVGActionWriter::GetValueString( rOutputSize.Height(), sal_True ); + AddAttribute( XML_NAMESPACE_NONE, aXMLAttrHeight, aAttr ); + + aAttr = B2UCONST( "0.0 0.0 " ); + aAttr += SVGActionWriter::GetValueString( rOutputSize.Width(), sal_True ); + aAttr += B2UCONST( " " ); + aAttr += SVGActionWriter::GetValueString( rOutputSize.Height(), sal_True ); + AddAttribute( XML_NAMESPACE_NONE, aXMLAttrViewBox, aAttr ); + + return( new SvXMLElementExport( *this, XML_NAMESPACE_NONE, aXMLElemSVG, TRUE, TRUE ) ); +} + +// ----------------------------------------------------------------------------- + +void SVGPrinterExport::ImplWriteMetaAttr( sal_Bool bOuter, sal_Bool bPage ) +{ + SvXMLElementExport aMetaData( *this, XML_NAMESPACE_NONE, aXMLElemMeta, TRUE, TRUE ); + NMSP_RTL::OUString aAttr; + + aAttr = bOuter ? B2UCONST( "true" ) : B2UCONST( "false" ); + AddAttribute( XML_NAMESPACE_NONE, aXMLAttrMetaSVGOuter, aAttr ); + + aAttr = bPage ? B2UCONST( "true" ) : B2UCONST( "false" ); + AddAttribute( XML_NAMESPACE_NONE, aXMLAttrMetaSVGPage, aAttr ); + + { + delete( new SvXMLElementExport( *this, XML_NAMESPACE_NONE, aXMLElemMetaSVG, TRUE, TRUE ) ); + } +} + +// ----------------------------------------------------------------------------- + +void SVGPrinterExport::writePage( const JobSetup& rSetup, const GDIMetaFile& rMtf ) +{ + Size aOutputSize; + NMSP_RTL::OUString aAttr; + SvXMLElementExport* pPageElem = ImplCreateSVGElement( rSetup, aOutputSize ); + + // write description + SvXMLElementExport* pDescElem = new SvXMLElementExport( *this, XML_NAMESPACE_NONE, aXMLElemDesc, TRUE, TRUE ); + NMSP_RTL::OUString aDesc( B2UCONST( "page: " ) ); + + GetDocHandler()->characters( aDesc += NMSP_RTL::OUString::valueOf( (sal_Int32) ++mnPage ) ); + delete pDescElem; + + // write meta attributes + ImplWriteMetaAttr( FALSE, TRUE ); + + // write dummy rect element + aAttr = B2UCONST( "0.0" ); + AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX, aAttr ); + AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY, aAttr ); + + aAttr = SVGActionWriter::GetValueString( aOutputSize.Width(), sal_True ); + AddAttribute( XML_NAMESPACE_NONE, aXMLAttrWidth, aAttr ); + + aAttr = SVGActionWriter::GetValueString( aOutputSize.Height(), sal_True ); + AddAttribute( XML_NAMESPACE_NONE, aXMLAttrHeight, aAttr ); + + delete( new SvXMLElementExport( *this, XML_NAMESPACE_NONE, aXMLElemRect, TRUE, TRUE ) ); + delete( new SVGActionWriter( *this, rMtf, mpVDev, TRUE ) ); + + delete pPageElem; +} + +// -------------- +// - SVGPrinter - +// -------------- + +SVGPrinter::SVGPrinter( const REF( NMSP_LANG::XMultiServiceFactory )& rxMgr ) : + mxFact( rxMgr ), + mpWriter( NULL ) +{ +} + +// ----------------------------------------------------------------------------- + +SVGPrinter::~SVGPrinter() +{ + delete mpWriter; +} + +// ----------------------------------------------------------------------------- + + +ANY SAL_CALL SVGPrinter::queryInterface( const NMSP_UNO::Type & rType ) throw( NMSP_UNO::RuntimeException ) +{ + const ANY aRet( NMSP_CPPU::queryInterface( rType, static_cast< NMSP_SVG::XSVGPrinter* >( this ) ) ); + + return( aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ) ); +} + +// ----------------------------------------------------------------------------- + +void SAL_CALL SVGPrinter::acquire() throw( NMSP_UNO::RuntimeException ) +{ + OWeakObject::acquire(); +} + +// ----------------------------------------------------------------------------- + +void SAL_CALL SVGPrinter::release() throw( NMSP_UNO::RuntimeException ) +{ + OWeakObject::release(); +} + +// ----------------------------------------------------------------------------- + +sal_Bool SAL_CALL SVGPrinter::startJob( const REF( NMSP_SAX::XDocumentHandler )& rxHandler, + const SEQ( sal_Int8 )& rJobSetupSeq, + const NMSP_RTL::OUString& rJobName, + sal_uInt32 nCopies, sal_Bool bCollate ) throw( NMSP_UNO::RuntimeException ) +{ + const sal_Bool bRet = ( mpWriter == NULL ); + + if( bRet ) + { + SvMemoryStream aMemStm( (char*) rJobSetupSeq.getConstArray(), rJobSetupSeq.getLength(), STREAM_READ ); + JobSetup aJobSetup; + + aMemStm.SetCompressMode( COMPRESSMODE_FULL ); + aMemStm >> aJobSetup; + +#ifndef _SVG_UNO3 + NMSP_UNO::Mapping ecpptosmart( CPPU_CURRENT_LANGUAGE_BINDING_NAME, "smart" ); + XDocumentHandlerRef xDocumentHandler( (XDocumentHandler*) ecpptosmart.mapInterface( rxHandler.get(), getCppuType( &rxHandler ) ) ); + xDocumentHandler->release(); +#else + const REF( NMSP_SAX::XDocumentHandler ) xDocumentHandler( rxHandler ); +#endif + + mpWriter = new SVGPrinterExport( xDocumentHandler, aJobSetup, rJobName, nCopies, bCollate ); + } + + return bRet; +} + +// ----------------------------------------------------------------------------- + +void SAL_CALL SVGPrinter::printPage( const SEQ( sal_Int8 )& rPrintPage ) throw( NMSP_UNO::RuntimeException ) +{ + SvMemoryStream aMemStm( (char*) rPrintPage.getConstArray(), rPrintPage.getLength(), STREAM_READ ); + PrinterPage aPage; + + aMemStm.SetCompressMode( COMPRESSMODE_FULL ); + aMemStm >> aPage; + mpWriter->writePage( aPage.GetJobSetup(), *aPage.GetGDIMetaFile() ); +} + +// ----------------------------------------------------------------------------- + +void SAL_CALL SVGPrinter::endJob() throw( NMSP_UNO::RuntimeException ) +{ + delete mpWriter, mpWriter = NULL; +} diff --git a/extensions/source/svg/svgprinter.hxx b/extensions/source/svg/svgprinter.hxx new file mode 100644 index 000000000000..a26baa0abd94 --- /dev/null +++ b/extensions/source/svg/svgprinter.hxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * $RCSfile: svgprinter.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _SVGPRINTER_HXX +#define _SVGPRINTER_HXX + +#include "svgcom.hxx" + +// ------------- +// - SVGWriter - +// ------------- + +class SVGPrinterExport; + +class SVGPrinter : public NMSP_CPPU::OWeakObject, NMSP_SVG::XSVGPrinter +{ +private: + + REF( NMSP_LANG::XMultiServiceFactory ) mxFact; + SVGPrinterExport* mpWriter; + + SVGPrinter(); + +public: + + SVGPrinter( const REF( NMSP_LANG::XMultiServiceFactory )& rxMgr ); + virtual ~SVGPrinter(); + + // XInterface + virtual ANY SAL_CALL queryInterface( const NMSP_UNO::Type & rType ) throw( NMSP_UNO::RuntimeException ); + virtual void SAL_CALL acquire() throw( NMSP_UNO::RuntimeException ); + virtual void SAL_CALL release() throw( NMSP_UNO::RuntimeException ); + + // XSVGPrinter + virtual sal_Bool SAL_CALL startJob( const REF( NMSP_SAX::XDocumentHandler )& rxHandler, + const SEQ( sal_Int8 )& rJobSetup, + const NMSP_RTL::OUString& rJobName, + sal_uInt32 nCopies, sal_Bool bCollate ) throw( NMSP_UNO::RuntimeException ); + virtual void SAL_CALL printPage( const SEQ( sal_Int8 )& rPrintPage ) throw( NMSP_UNO::RuntimeException ); + virtual void SAL_CALL endJob() throw( NMSP_UNO::RuntimeException ); +}; + +#endif diff --git a/extensions/source/svg/svguno.cxx b/extensions/source/svg/svguno.cxx new file mode 100644 index 000000000000..0d2f9b63474e --- /dev/null +++ b/extensions/source/svg/svguno.cxx @@ -0,0 +1,167 @@ +/************************************************************************* + * + * $RCSfile: svguno.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "svgcom.hxx" +#include "svgwriter.hxx" +#include "svgprinter.hxx" + +#include <cppuhelper/factory.hxx> +#include <uno/mapping.hxx> + +// ------------------- +// - factory methods - +// ------------------- + +#if SUPD>=590 +static REF( NMSP_UNO::XInterface ) SAL_CALL create_SVGWriter( const REF( NMSP_LANG::XMultiServiceFactory )& rxFact ) +#else +static REF( NMSP_UNO::XInterface ) create_SVGWriter( const REF( NMSP_LANG::XMultiServiceFactory )& rxFact ) +#endif +{ + return REF( NMSP_UNO::XInterface )( *new SVGWriter( rxFact ) ); +} + +// ----------------------------------------------------------------------------- + +#if SUPD>=590 +static REF( NMSP_UNO::XInterface ) SAL_CALL create_SVGPrinter( const REF( NMSP_LANG::XMultiServiceFactory )& rxFact ) +#else +static REF( NMSP_UNO::XInterface ) create_SVGPrinter( const REF( NMSP_LANG::XMultiServiceFactory )& rxFact ) +#endif +{ + return REF( NMSP_UNO::XInterface )( *new SVGPrinter( rxFact ) ); +} + +// ------------------------------------------ +// - component_getImplementationEnvironment - +// ------------------------------------------ + +extern "C" void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +// ----------------------- +// - component_writeInfo - +// ----------------------- + +extern "C" sal_Bool SAL_CALL component_writeInfo( void* pServiceManager, void* pRegistryKey ) +{ + sal_Bool bRet = sal_False; + + if( pRegistryKey ) + { + try + { + REF( NMSP_REGISTRY::XRegistryKey ) xNewKey1( + static_cast< NMSP_REGISTRY::XRegistryKey* >( pRegistryKey )->createKey( + B2UCONST( "/com.sun.star.comp.extensions.SVGWriter/UNO/SERVICES/com.sun.star.svg.SVGWriter" ) ) ); + REF( NMSP_REGISTRY::XRegistryKey ) xNewKey2( + static_cast< NMSP_REGISTRY::XRegistryKey* >( pRegistryKey )->createKey( + B2UCONST( "/com.sun.star.comp.extensions.SVGPrinter/UNO/SERVICES/com.sun.star.svg.SVGPrinter" ) ) ); + + bRet = sal_True; + } + catch( NMSP_REGISTRY::InvalidRegistryException& ) + { + OSL_ENSHURE( sal_False, "### InvalidRegistryException!" ); + } + } + + return bRet; +} + +// ------------------------ +// - component_getFactory - +// ------------------------ + +extern "C" void* SAL_CALL component_getFactory( const sal_Char* pImplName, void* pServiceManager, void* pRegistryKey ) +{ + REF( NMSP_LANG::XSingleServiceFactory ) xFactory; + void* pRet = 0; + + if( rtl_str_compare( pImplName, "com.sun.star.comp.extensions.SVGWriter" ) == 0 ) + { + const NMSP_RTL::OUString aServiceName( B2UCONST( "com.sun.star.svg.SVGWriter" ) ); + + xFactory = REF( NMSP_LANG::XSingleServiceFactory )( NMSP_CPPU::createSingleFactory( + reinterpret_cast< NMSP_LANG::XMultiServiceFactory* >( pServiceManager ), + B2UCONST( "com.sun.star.comp.extensions.SVGWriter" ), + create_SVGWriter, SEQ( NMSP_RTL::OUString )( &aServiceName, 1 ) ) ); + } + else if( rtl_str_compare( pImplName, "com.sun.star.comp.extensions.SVGPrinter" ) == 0 ) + { + const NMSP_RTL::OUString aServiceName( B2UCONST( "com.sun.star.svg.SVGPrinter" ) ); + + xFactory = REF( NMSP_LANG::XSingleServiceFactory )( NMSP_CPPU::createSingleFactory( + reinterpret_cast< NMSP_LANG::XMultiServiceFactory* >( pServiceManager ), + B2UCONST( "com.sun.star.comp.extensions.SVGPrinter" ), + create_SVGPrinter, SEQ( NMSP_RTL::OUString )( &aServiceName, 1 ) ) ); + } + + if( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} diff --git a/extensions/source/svg/svgwriter.cxx b/extensions/source/svg/svgwriter.cxx new file mode 100644 index 000000000000..b6db93a46e75 --- /dev/null +++ b/extensions/source/svg/svgwriter.cxx @@ -0,0 +1,214 @@ +/************************************************************************* + * + * $RCSfile: svgwriter.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "svgwriter.hxx" +#include "svgaction.hxx" +#include <uno/mapping.hxx> + +// ---------------- +// - SVGMtfExport - +// ---------------- + +class SVGMtfExport : public SvXMLExport +{ +private: + + SVGMtfExport(); + +protected: + + virtual void _ExportMeta() {} + virtual void _ExportStyles( BOOL bUsed ) {} + virtual void _ExportAutoStyles() {} + virtual void _ExportContent() {} + virtual void _ExportMasterStyles() {} + virtual ULONG exportDoc( const char *pClass = 0 ) { return 0; } + +public: + +#ifndef _SVG_UNO3 + SVGMtfExport( XDocumentHandlerRef& rXHandler ); +#else + SVGMtfExport( const REF( NMSP_SAX::XDocumentHandler )& rxHandler ); +#endif + virtual ~SVGMtfExport(); + + virtual void writeMtf( const GDIMetaFile& rMtf ); +}; + +// ----------------------------------------------------------------------------- + +#ifndef _SVG_UNO3 +SVGMtfExport::SVGMtfExport( XDocumentHandlerRef& rxHandler ) : +#else +SVGMtfExport::SVGMtfExport( const REF( NMSP_SAX::XDocumentHandler )& rxHandler ) : +#endif + SvXMLExport( NMSP_RTL::OUString(), rxHandler ) +{ + GetDocHandler()->startDocument(); +} + +// ----------------------------------------------------------------------------- + +SVGMtfExport::~SVGMtfExport() +{ + GetDocHandler()->endDocument(); +} + +// ----------------------------------------------------------------------------- + +void SVGMtfExport::writeMtf( const GDIMetaFile& rMtf ) +{ + const Size aSize( OutputDevice::LogicToLogic( rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), MAP_MM ) ); + NMSP_RTL::OUString aAttr; +#ifndef _SVG_UNO3 + XExtendedDocumentHandlerRef xExtDocHandler( GetDocHandler(), USR_QUERY ); +#else + REF( NMSP_SAX::XExtendedDocumentHandler ) xExtDocHandler( GetDocHandler(), NMSP_UNO::UNO_QUERY ); +#endif + + if( xExtDocHandler.is() ) + xExtDocHandler->unknown( B2UCONST( "<!DOCTYPE svg SYSTEM \"svg-19990812.dtd\">" ) ); + + aAttr = NMSP_RTL::OUString::valueOf( aSize.Width() ); + aAttr += B2UCONST( "mm" ); + AddAttribute( XML_NAMESPACE_NONE, "width", aAttr ); + + aAttr = NMSP_RTL::OUString::valueOf( aSize.Height() ); + aAttr += B2UCONST( "mm" ); + AddAttribute( XML_NAMESPACE_NONE, "height", aAttr ); + + aAttr = B2UCONST( "0 0 " ); + aAttr += NMSP_RTL::OUString::valueOf( aSize.Width() * 100L ); + aAttr += B2UCONST( " " ); + aAttr += NMSP_RTL::OUString::valueOf( aSize.Height() * 100L ); + AddAttribute( XML_NAMESPACE_NONE, "viewBox", aAttr ); + + { + SvXMLElementExport aSVG( *this, XML_NAMESPACE_NONE, "svg", TRUE, TRUE ); + SVGActionWriter* pWriter = new SVGActionWriter( *this, rMtf ); + + delete pWriter; + } +} + +// ------------- +// - SVGWriter - +// ------------- + +SVGWriter::SVGWriter( const REF( NMSP_LANG::XMultiServiceFactory )& rxMgr ) : + mxFact( rxMgr ) +{ +} + +// ----------------------------------------------------------------------------- + +SVGWriter::~SVGWriter() +{ +} + +// ----------------------------------------------------------------------------- + + +ANY SAL_CALL SVGWriter::queryInterface( const NMSP_UNO::Type & rType ) throw( NMSP_UNO::RuntimeException ) +{ + const ANY aRet( NMSP_CPPU::queryInterface( rType, static_cast< NMSP_SVG::XSVGWriter* >( this ) ) ); + + return( aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ) ); +} + +// ----------------------------------------------------------------------------- + +void SAL_CALL SVGWriter::acquire() throw( NMSP_UNO::RuntimeException ) +{ + OWeakObject::acquire(); +} + +// ----------------------------------------------------------------------------- + +void SAL_CALL SVGWriter::release() throw( NMSP_UNO::RuntimeException ) +{ + OWeakObject::release(); +} + +// ----------------------------------------------------------------------------- + +void SAL_CALL SVGWriter::write( const REF( NMSP_SAX::XDocumentHandler )& rxDocHandler, + const SEQ( sal_Int8 )& rMtfSeq ) throw( NMSP_UNO::RuntimeException ) +{ + SvMemoryStream aMemStm( (char*) rMtfSeq.getConstArray(), rMtfSeq.getLength(), STREAM_READ ); + GDIMetaFile aMtf; + + aMemStm.SetCompressMode( COMPRESSMODE_FULL ); + aMemStm >> aMtf; + +#ifndef _SVG_UNO3 + NMSP_UNO::Mapping ecpptosmart( CPPU_CURRENT_LANGUAGE_BINDING_NAME, "smart" ); + XDocumentHandlerRef xDocumentHandler( (XDocumentHandler*)ecpptosmart.mapInterface( rxDocHandler.get(), getCppuType(&rxDocHandler)) ); + xDocumentHandler->release(); +#else + const REF( NMSP_SAX::XDocumentHandler ) xDocumentHandler( rxDocHandler ); +#endif + + SVGMtfExport* pWriter = new SVGMtfExport( xDocumentHandler ); + pWriter->writeMtf( aMtf ); + delete pWriter; +} diff --git a/extensions/source/svg/svgwriter.hxx b/extensions/source/svg/svgwriter.hxx new file mode 100644 index 000000000000..51912d04cd5b --- /dev/null +++ b/extensions/source/svg/svgwriter.hxx @@ -0,0 +1,94 @@ +/************************************************************************* + * + * $RCSfile: svgwriter.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _SVGWRITER_HXX +#define _SVGWRITER_HXX + +#include "svgcom.hxx" + +// ------------- +// - SVGWriter - +// ------------- + +class SVGWriter : public NMSP_CPPU::OWeakObject, NMSP_SVG::XSVGWriter +{ +private: + + REF( NMSP_LANG::XMultiServiceFactory ) mxFact; + + SVGWriter(); + +public: + + SVGWriter( const REF( NMSP_LANG::XMultiServiceFactory )& rxMgr ); + virtual ~SVGWriter(); + + // XInterface + virtual ANY SAL_CALL queryInterface( const NMSP_UNO::Type & rType ) throw( NMSP_UNO::RuntimeException ); + virtual void SAL_CALL acquire() throw( NMSP_UNO::RuntimeException ); + virtual void SAL_CALL release() throw( NMSP_UNO::RuntimeException ); + + // XSVGWriter + virtual void SAL_CALL write( const REF( NMSP_SAX::XDocumentHandler )& rxDocHandler, + const SEQ( sal_Int8 )& rMtfSeq ) throw( NMSP_UNO::RuntimeException ); +}; + +#endif |