xref: /trunk/main/svtools/source/filter/wmf/wmfwr.hxx (revision 161f4cd1)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _WMFWR_HXX
25 #define _WMFWR_HXX
26 
27 #include <tools/bigint.hxx>
28 #include <tools/debug.hxx>
29 #include <vcl/metaact.hxx>
30 #include <vcl/graph.hxx>
31 #include <vcl/gdimtf.hxx>
32 #include <vcl/virdev.hxx>
33 #include <svtools/fltcall.hxx>
34 
35 // -----------------------------------------------------------------------------
36 
37 #define MAXOBJECTHANDLES 16
38 
39 // -----------------------------------------------------------------------------
40 
41 struct WMFWriterAttrStackMember
42 {
43 	struct WMFWriterAttrStackMember * pSucc;
44 	Color aLineColor;
45 	Color aFillColor;
46     Color aTextColor;
47 	LineInfo aLineInfo;
48     TextAlign eTextAlign;
49 	RasterOp eRasterOp;
50 	Font aFont;
51 	MapMode aMapMode;
52 	Region aClipRegion;
53     sal_uInt16 nFlags;
54 };
55 
56 // -------------
57 // - WMFWriter -
58 // -------------
59 
60 class StarSymbolToMSMultiFont;
61 class LineInfo;
62 namespace basegfx { class B2DPolygon; }
63 
64 class WMFWriter
65 {
66 private:
67 
68 	sal_Bool			bStatus;
69 
70 	sal_uLong					nLastPercent; // Mit welcher Zahl pCallback zuletzt aufgerufen wurde.
71 	FilterConfigItem*		pFilterConfigItem;
72 
73 	com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator > xStatusIndicator;
74 
75 	SvStream*				pWMF;
76 	VirtualDevice*			pVirDev;
77     StarSymbolToMSMultiFont *pConvert;
78 	MapMode					aTargetMapMode;
79 	Size					aTargetSize;
80 	sal_uInt16					nTargetDivisor;
81 
82 	sal_uLong nMetafileHeaderPos;
83 	sal_uInt32 nMaxRecordSize; // in Worten
84 	sal_uLong nActRecordPos;
85 
86 	// Aktuelle Attribute im Quell-Metafile:
87 	Color	  aSrcLineColor;
88 	Color	  aSrcFillColor;
89     Color     aSrcTextColor;
90 	LineInfo  aSrcLineInfo;
91 	RasterOp  eSrcRasterOp;
92     FontAlign eSrcTextAlign;
93 	Font      aSrcFont;
94 	MapMode   aSrcMapMode;
95 	sal_Bool      bSrcIsClipping;
96 	Region    aSrcClipRegion;
97 	WMFWriterAttrStackMember * pAttrStack;
98 
99 	sal_uInt32	  eSrcHorTextAlign;
100 
101 	// Aktuelle Attribute im Ziel-Metafile:
102 	Color	  aDstLineColor;
103 	Color	  aDstFillColor;
104 	Color     aDstTextColor;
105 	LineInfo  aDstLineInfo;
106 	RasterOp  eDstROP2;
107 	FontAlign eDstTextAlign;
108 	Font      aDstFont;
109 
110 	sal_uInt32	  eDstHorTextAlign;
111 
112 	sal_Bool      bDstIsClipping; // ???: derzeit unberuecksichtigt
113 	Region    aDstClipRegion; // ???: derzeit unberuecksichtigt
114 	sal_Bool bHandleAllocated[MAXOBJECTHANDLES];             // Welche Handles vergeben sind
115 	sal_uInt16 nDstPenHandle,nDstFontHandle,nDstBrushHandle; // Welche Handles die jeweiligen
116 														 // Selected-Objects besitzen
117 														 // 0xffff = keines:
118 
119 	// Damit nicht bei jeder Operation alle Attribute verglichen werden muessen:
120 
121 	sal_uLong nNumberOfActions; // Anzahl der Actions im GDIMetafile
122 	sal_uLong nNumberOfBitmaps; // Anzahl der Bitmaps
123 	sal_uLong nWrittenActions;  // Anzahl der bereits verarbeiteten Actions beim Schreiben der Orders
124 	sal_uLong nWrittenBitmaps;  // Anzahl der bereits geschriebenen Bitmaps
125 	sal_uLong nActBitmapPercent; // Wieviel Prozent die naechste Bitmap schon geschrieben ist.
126 
127     sal_Bool bEmbedEMF; // optionally embedd EMF data into WMF
128 
129 	void MayCallback();
130 		// Berechnet anhand der obigen 5 Parameter eine Prozentzahl
131 		// und macht dann ggf. einen Callback. Setzt bStatus auf FALSE wenn User abbrechen
132 		// moechte.
133 
134 	void CountActionsAndBitmaps(const GDIMetaFile & rMTF);
135 		// Zaehlt die Bitmaps und Actions (nNumberOfActions und nNumberOfBitmaps muessen
136 		// zu Anfang auf 0 gesetzt werden, weil diese Methode rekursiv ist)
137 
138 	void WritePointXY(const Point & rPoint);
139 	void WritePointYX(const Point & rPoint);
140 	sal_Int32 ScaleWidth( sal_Int32 nDX );
141 	void WriteSize(const Size & rSize);
142 	void WriteHeightWidth(const Size & rSize);
143 	void WriteRectangle(const Rectangle & rRect);
144 	void WriteColor(const Color & rColor);
145 
146 	void WriteRecordHeader(sal_uInt32 nSizeWords, sal_uInt16 nType);
147 		// nSizeWords ist die Groesse des gesammten Records in Anzahl Worte.
148 		// Wenn nSizeWords unbekannt ist, dann 0 einsetzen (siehe UpdateRecordHeader()).
149 
150 	void UpdateRecordHeader();
151 		// berichtig die Groesse des Records nach dem Schreiben der Parameter, wenn
152 		// nSizeWords bei Aufruf von WriteRecordHeader(..) unbekannt war.
153 		// fuegt ggf. noch ein BYTE 0 ein damit Anzahl Bytes immer gerade.
154 
155 	void WMFRecord_Arc(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt);
156 	void WMFRecord_Chord(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt);
157 	void WMFRecord_CreateBrushIndirect(const Color& rColor);
158 	void WMFRecord_CreateFontIndirect(const Font & rFont);
159 	void WMFRecord_CreatePenIndirect(const Color& rColor, const LineInfo& rLineInfo );
160 	void WMFRecord_DeleteObject(sal_uInt16 nObjectHandle);
161 	void WMFRecord_Ellipse(const Rectangle & rRect);
162 	void WMFRecord_Escape( sal_uInt32 nEsc, sal_uInt32 nLen, const sal_Int8* pData );
163 	sal_Bool WMFRecord_Escape_Unicode( const Point& rPoint, const String& rStr, const sal_Int32 * pDXAry );
164 	void WMFRecord_ExtTextOut(const Point & rPoint, const String & rString, const sal_Int32 * pDXAry);
165 
166     void TrueExtTextOut(const Point & rPoint, const String & rString,
167         const ByteString & rByteString, const sal_Int32 * pDXAry);
168     void TrueTextOut(const Point & rPoint, const ByteString& rString);
169 	void WMFRecord_LineTo(const Point & rPoint);
170 	void WMFRecord_MoveTo(const Point & rPoint);
171 	void WMFRecord_Pie(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt);
172 	void WMFRecord_Polygon(const Polygon & rPoly);
173 	void WMFRecord_PolyLine(const Polygon & rPoly);
174 	void WMFRecord_PolyPolygon(const PolyPolygon & rPolyPoly);
175 	void WMFRecord_Rectangle(const Rectangle & rRect);
176 	void WMFRecord_RestoreDC();
177 	void WMFRecord_RoundRect(const Rectangle & rRect, long nHorzRound, long nVertRound);
178 	void WMFRecord_SaveDC();
179 	void WMFRecord_SelectObject(sal_uInt16 nObjectHandle);
180 	void WMFRecord_SetBkColor(const Color & rColor);
181 	void WMFRecord_SetBkMode(sal_Bool bTransparent);
182 	void WMFRecord_SetStretchBltMode();
183 	void WMFRecord_SetPixel(const Point & rPoint, const Color & rColor);
184 	void WMFRecord_SetROP2(RasterOp eROP);
185 	void WMFRecord_SetTextAlign(FontAlign eFontAlign, sal_uInt32 eHorTextAlign);
186 	void WMFRecord_SetTextColor(const Color & rColor);
187 	void WMFRecord_SetWindowExt(const Size & rSize);
188 	void WMFRecord_SetWindowOrg(const Point & rPoint);
189 	void WMFRecord_StretchDIB(const Point & rPoint, const Size & rSize, const Bitmap & rBitmap, sal_uInt32 nROP = 0UL );
190 	void WMFRecord_TextOut(const Point & rPoint, const String & rString);
191 	void WMFRecord_EndOfFile();
192 	void WMFRecord_IntersectClipRect( const Rectangle& rRect);
193 
194 	sal_uInt16 AllocHandle();
195 	void FreeHandle(sal_uInt16 nObjectHandle);
196 	void CreateSelectDeletePen( const Color& rColor, const LineInfo& rLineInfo );
197 	void CreateSelectDeleteFont(const Font & rFont);
198 	void CreateSelectDeleteBrush(const Color& rColor);
199 
200 	void SetLineAndFillAttr();
201 	void SetAllAttr();
202 
203     void HandleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon);
204 	void WriteRecords(const GDIMetaFile & rMTF);
205 
206 	void WriteHeader(const GDIMetaFile & rMTF, sal_Bool bPlaceable);
207 	void UpdateHeader();
208 
209     void WriteEmbeddedEMF( const GDIMetaFile& rMTF );
210     void WriteEMFRecord( SvMemoryStream& rStream, sal_uInt32 nCurSize,
211                             sal_uInt32 nRemainingSize,
212                             sal_uInt32 nTotalSize,
213                             sal_uInt32 nRecCounts,
214                             sal_uInt16 nCheckSum );
215 
216 	sal_uInt16 CalcSaveTargetMapMode(MapMode& rMapMode, const Size& rPrefSize);
217 
218 public:
219 
WMFWriter()220 	WMFWriter() {}
221 
222 	sal_Bool WriteWMF(const GDIMetaFile & rMTF, SvStream & rTargetStream, FilterConfigItem* pFilterConfigItem, sal_Bool bPlaceable=sal_True);
223 };
224 
225 #endif
226