1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_SOURCE_FILTER_WMF_WINMTF_HXX
21 #define INCLUDED_VCL_SOURCE_FILTER_WMF_WINMTF_HXX
23 #include <sot/object.hxx>
24 #include <vcl/graph.hxx>
25 #include <basegfx/tools/b2dclipstate.hxx>
26 #include <vcl/font.hxx>
27 #include <vcl/bmpacc.hxx>
28 #include <vcl/lineinfo.hxx>
29 #include <vcl/fltcall.hxx>
33 #define COMPLEXREGION 3
50 #define MWT_IDENTITY 1
51 #define MWT_LEFTMULTIPLY 2
52 #define MWT_RIGHTMULTIPLY 3
55 #define ENHMETA_STOCK_OBJECT 0x80000000
57 /* Stock Logical Objects */
59 #define LTGRAY_BRUSH 1
61 #define DKGRAY_BRUSH 3
67 #define ANSI_FIXED_FONT 11
68 #define ANSI_VAR_FONT 12
69 #define SYSTEM_FIXED_FONT 16
72 #define R2_MASKNOTPEN 3
82 #define MM_LOENGLISH 4
83 #define MM_HIENGLISH 5
85 #define MM_ISOTROPIC 7
86 #define MM_ANISOTROPIC 8
89 #define GM_COMPATIBLE 1
92 /* StretchBlt() modes */
93 #define BLACKONWHITE 1
94 #define WHITEONBLACK 2
95 #define COLORONCOLOR 3
97 #define STRETCH_ANDSCANS BLACKONWHITE
98 #define STRETCH_ORSCANS WHITEONBLACK
99 #define STRETCH_DELETESCANS COLORONCOLOR
101 #define LF_FACESIZE 32
107 sal_Int32 lfEscapement
;
108 sal_Int32 lfOrientation
;
111 sal_uInt8 lfUnderline
;
112 sal_uInt8 lfStrikeOut
;
114 sal_uInt8 lfOutPrecision
;
115 sal_uInt8 lfClipPrecision
;
117 sal_uInt8 lfPitchAndFamily
;
118 OUString alfFaceName
;
120 struct WMF_EXTERNALHEADER
;
122 #define TA_NOUPDATECP 0x0000
123 #define TA_UPDATECP 0x0001
124 #define TA_LEFT 0x0000
125 #define TA_RIGHT 0x0002
126 #define TA_CENTER 0x0006
127 #define TA_RIGHT_CENTER (TA_RIGHT | TA_CENTER)
128 #define TA_TOP 0x0000
129 #define TA_BOTTOM 0x0008
130 #define TA_BASELINE 0x0018
132 #define SRCCOPY 0x00CC0020L
133 #define SRCPAINT 0x00EE0086L
134 #define SRCAND 0x008800C6L
135 #define SRCINVERT 0x00660046L
136 #define SRCERASE 0x00440328L
137 #define PATCOPY 0x00F00021L
138 #define PATINVERT 0x005A0049L
139 #define BLACKNESS 0x00000042L
140 #define WHITENESS 0x00FF0062L
146 #define PS_DASHDOTDOT 4
148 #define PS_INSIDEFRAME 6
149 #define PS_STYLE_MASK 15
151 #define PS_ENDCAP_ROUND 0x000
152 #define PS_ENDCAP_SQUARE 0x100
153 #define PS_ENDCAP_FLAT 0x200
155 #define PS_JOIN_ROUND 0x0000
156 #define PS_JOIN_BEVEL 0x1000
157 #define PS_JOIN_MITER 0x2000
160 #define ANSI_CHARSET 0
161 #define DEFAULT_CHARSET 1
162 #define SYMBOL_CHARSET 2
163 #define SHIFTJIS_CHARSET 128
164 #define HANGEUL_CHARSET 129
165 #define GB2312_CHARSET 134
166 #define CHINESEBIG5_CHARSET 136
167 #define OEM_CHARSET 255
169 #define JOHAB_CHARSET 130
170 #define HEBREW_CHARSET 177
171 #define ARABIC_CHARSET 178
172 #define GREEK_CHARSET 161
173 #define TURKISH_CHARSET 162
174 #define VIETNAMESE_CHARSET 163
175 #define THAI_CHARSET 222
176 #define EASTEUROPE_CHARSET 238
177 #define RUSSIAN_CHARSET 204
178 #define MAC_CHARSET 77
179 #define BALTIC_CHARSET 186
181 #define ETO_CLIPPED 0x0004
183 #define ETO_GLYPH_INDEX 0x0010
184 #define ETO_RTLREADING 0x0080
185 /*_WIN32_WINNT >= 0x0500*/
186 #define ETO_PDY 0x2000
188 #define DEFAULT_PITCH 0x00
189 #define FIXED_PITCH 0x01
190 #define VARIABLE_PITCH 0x02
193 #define FF_DONTCARE 0x00
194 #define FF_ROMAN 0x10
195 #define FF_SWISS 0x20
196 #define FF_MODERN 0x30
197 #define FF_SCRIPT 0x40
198 #define FF_DECORATIVE 0x50
201 #define FW_EXTRALIGHT 200
203 #define FW_NORMAL 400
204 #define FW_MEDIUM 500
205 #define FW_SEMIBOLD 600
207 #define FW_EXTRABOLD 800
208 #define FW_ULTRALIGHT 200
209 #define FW_ULTRABOLD 800
218 #define BS_DIBPATTERN 5
219 #define BS_DIBPATTERNPT 6
220 #define BS_PATTERN8X8 7
221 #define BS_DIBPATTERN8X8 8
222 #define BS_MONOPATTERN 9
225 #define RDH_RECTANGLES 1
227 #define W_MFCOMMENT 15
229 #define PRIVATE_ESCAPE_UNICODE 2
233 #define UNDOCUMENTED_WIN_RCL_RELATION 32
234 #define MS_FIXPOINT_BITCOUNT_28_4 4
235 #define HUNDREDTH_MILLIMETERS_PER_MILLIINCH 2.54
236 #define MILLIINCH_PER_TWIPS 1.44
238 //============================ WMFReader ==================================
242 basegfx::tools::B2DClipState maClip
;
245 WinMtfClipPath(): maClip() {};
247 void setClipPath( const tools::PolyPolygon
& rPolyPolygon
, sal_Int32 nClippingMode
);
248 void intersectClipRect( const Rectangle
& rRect
);
249 void excludeClipRect( const Rectangle
& rRect
);
250 void moveClipRegion( const Size
& rSize
);
251 void setDefaultClipPath();
253 bool isEmpty() const { return maClip
.isCleared(); }
255 basegfx::B2DPolyPolygon
getClipPath() const;
257 bool operator==( const WinMtfClipPath
& rPath
) const
259 return maClip
== rPath
.maClip
;
263 class WinMtfPathObj
: public tools::PolyPolygon
280 void AddPoint( const Point
& rPoint
);
281 void AddPolygon( const Polygon
& rPoly
);
282 void AddPolyLine( const Polygon
& rPoly
);
283 void AddPolyPolygon( const tools::PolyPolygon
& rPolyPolygon
);
286 struct WinMtfFontStyle
290 WinMtfFontStyle( LOGFONTW
& rLogFont
);
298 } WinMtfFillStyleType
;
300 struct WinMtfFillStyle
304 WinMtfFillStyleType aType
;
308 : aFillColor(Color(COL_BLACK
))
309 , bTransparent(false)
310 , aType(FillStyleSolid
)
313 WinMtfFillStyle(const Color
& rColor
, bool bTrans
= false)
315 , bTransparent(bTrans
)
316 , aType(FillStyleSolid
)
319 WinMtfFillStyle(Bitmap
& rBmp
)
320 : bTransparent(false)
321 , aType(FillStylePattern
)
325 bool operator==( const WinMtfFillStyle
& rStyle
)
327 return aFillColor
== rStyle
.aFillColor
328 && bTransparent
== rStyle
.bTransparent
329 && aType
== rStyle
.aType
;
332 bool operator==(WinMtfFillStyle
* pStyle
)
334 return aFillColor
== pStyle
->aFillColor
335 && bTransparent
== pStyle
->bTransparent
336 && aType
== pStyle
->aType
;
339 WinMtfFillStyle
& operator=(const WinMtfFillStyle
& rStyle
)
341 aFillColor
= rStyle
.aFillColor
;
342 bTransparent
= rStyle
.bTransparent
;
344 aType
= rStyle
.aType
;
348 WinMtfFillStyle
& operator=(WinMtfFillStyle
* pStyle
)
350 aFillColor
= pStyle
->aFillColor
;
351 bTransparent
= pStyle
->bTransparent
;
353 aType
= pStyle
->aType
;
358 struct WinMtfLineStyle
365 : aLineColor (COL_BLACK
)
366 , bTransparent(false)
369 WinMtfLineStyle(const Color
& rColor
, bool bTrans
= false)
370 : aLineColor (rColor
)
371 , bTransparent(bTrans
)
374 WinMtfLineStyle( const Color
& rColor
, const LineInfo
& rStyle
, bool bTrans
= false)
375 : aLineColor (rColor
)
377 , bTransparent(bTrans
)
380 bool operator==( const WinMtfLineStyle
& rStyle
)
382 return aLineColor
== rStyle
.aLineColor
383 && bTransparent
== rStyle
.bTransparent
384 && aLineInfo
== rStyle
.aLineInfo
;
387 bool operator==(WinMtfLineStyle
* pStyle
)
389 return aLineColor
== pStyle
->aLineColor
390 && bTransparent
== pStyle
->bTransparent
391 && aLineInfo
== pStyle
->aLineInfo
;
394 WinMtfLineStyle
& operator=( const WinMtfLineStyle
& rStyle
)
396 aLineColor
= rStyle
.aLineColor
;
397 bTransparent
= rStyle
.bTransparent
;
398 aLineInfo
= rStyle
.aLineInfo
;
402 WinMtfLineStyle
& operator=( WinMtfLineStyle
* pStyle
)
404 aLineColor
= pStyle
->aLineColor
;
405 bTransparent
= pStyle
->bTransparent
;
406 aLineInfo
= pStyle
->aLineInfo
;
433 sal_uInt32 nMapMode
, nGfxMode
;
434 ComplexTextLayoutMode nTextLayoutMode
;
435 sal_Int32 nWinOrgX
, nWinOrgY
, nWinExtX
, nWinExtY
;
436 sal_Int32 nDevOrgX
, nDevOrgY
, nDevWidth
, nDevHeight
;
438 WinMtfLineStyle aLineStyle
;
439 WinMtfFillStyle aFillStyle
;
444 sal_uInt32 nTextAlign
;
448 WinMtfPathObj aPathObj
;
449 WinMtfClipPath aClipPath
;
453 bool bFillStyleSelected
;
456 typedef std::shared_ptr
<SaveStruct
> SaveStructPtr
;
463 WinMtfFillStyle aStyle
;
465 BSaveStruct(const Bitmap
& rBmp
, const Rectangle
& rOutRect
,
466 sal_uInt32 nRop
, WinMtfFillStyle
& rStyle
)
474 typedef ::std::vector
< BSaveStruct
* > BSaveStructList_impl
;
497 GDIObj(GDIObjectType eT
, void* pS
)
503 void Set(GDIObjectType eT
, void* pS
)
517 delete static_cast<WinMtfLineStyle
*>(pStyle
);
520 delete static_cast<WinMtfFillStyle
*>(pStyle
);
523 delete static_cast<WinMtfFontStyle
*>(pStyle
);
527 OSL_FAIL( "unsupported style deleted" );
541 WinMtfPathObj aPathObj
;
542 WinMtfClipPath aClipPath
;
544 WinMtfLineStyle maLatestLineStyle
;
545 WinMtfLineStyle maLineStyle
;
546 WinMtfFillStyle maLatestFillStyle
;
547 WinMtfFillStyle maFillStyle
;
548 WinMtfFillStyle m_NopFillStyle
;
549 vcl::Font maLatestFont
;
551 sal_uInt32 mnLatestTextAlign
;
552 sal_uInt32 mnTextAlign
;
553 Color maLatestTextColor
;
555 Color maLatestBkColor
;
557 ComplexTextLayoutMode mnLatestTextLayoutMode
;
558 ComplexTextLayoutMode mnTextLayoutMode
;
559 BkMode mnLatestBkMode
;
561 RasterOp meLatestRasterOp
;
564 std::vector
< GDIObj
* > vGDIObj
;
570 bool mbFillStyleSelected
;
571 bool mbClipNeedsUpdate
;
574 std::vector
< SaveStructPtr
> vSaveStack
;
576 sal_uInt32 mnGfxMode
;
577 sal_uInt32 mnMapMode
;
580 sal_Int32 mnDevOrgX
, mnDevOrgY
;
581 sal_Int32 mnDevWidth
, mnDevHeight
;
582 sal_Int32 mnWinOrgX
, mnWinOrgY
; // aktuel window origin
583 sal_Int32 mnWinExtX
, mnWinExtY
; // aktuel window extend
587 sal_Int32 mnPixX
, mnPixY
; // Reference Device in pixel
588 sal_Int32 mnMillX
, mnMillY
; // Reference Device in Mill
589 Rectangle mrclFrame
; // rectangle in logical units 1/100th mm
590 Rectangle mrclBounds
;
592 GDIMetaFile
* mpGDIMetaFile
;
594 void UpdateLineStyle();
595 void UpdateFillStyle();
597 Point
ImplMap( const Point
& rPt
);
598 Point
ImplScale( const Point
& rPt
);
599 Size
ImplMap( const Size
& rSize
, bool bDoWorldTransform
= true);
600 Rectangle
ImplMap( const Rectangle
& rRectangle
);
601 void ImplMap( vcl::Font
& rFont
);
602 Polygon
& ImplMap( Polygon
& rPolygon
);
603 tools::PolyPolygon
& ImplMap( tools::PolyPolygon
& rPolyPolygon
);
604 Polygon
& ImplScale( Polygon
& rPolygon
);
605 tools::PolyPolygon
& ImplScale( tools::PolyPolygon
& rPolyPolygon
);
606 void ImplResizeObjectArry( sal_uInt32 nNewEntry
);
607 void ImplSetNonPersistentLineColorTransparenz();
608 void ImplDrawClippedPolyPolygon( const tools::PolyPolygon
& rPolyPoly
);
609 void ImplDrawBitmap( const Point
& rPos
, const Size
& rSize
, const BitmapEx
& rBitmap
);
613 void SetDevByWin(); //Hack to set varying defaults for incompletely defined files.
614 void SetDevOrg( const Point
& rPoint
);
615 void SetDevOrgOffset( sal_Int32 nXAdd
, sal_Int32 nYAdd
);
616 void SetDevExt( const Size
& rSize
,bool regular
= true);
617 void ScaleDevExt( double fX
, double fY
);
619 void SetWinOrg( const Point
& rPoint
, bool bIsEMF
= false);
620 void SetWinOrgOffset( sal_Int32 nX
, sal_Int32 nY
);
621 void SetWinExt( const Size
& rSize
, bool bIsEMF
= false);
622 void ScaleWinExt( double fX
, double fY
);
624 void SetrclBounds( const Rectangle
& rRect
);
625 void SetrclFrame( const Rectangle
& rRect
);
626 void SetRefPix( const Size
& rSize
);
627 void SetRefMill( const Size
& rSize
);
629 sal_uInt32
GetMapMode() const { return mnMapMode
; };
630 void SetMapMode( sal_uInt32 mnMapMode
);
631 void SetWorldTransform( const XForm
& rXForm
);
632 const XForm
& GetWorldTransform() const { return maXForm
; }
633 void ModifyWorldTransform( const XForm
& rXForm
, sal_uInt32 nMode
);
638 sal_uInt32
SetRasterOp( sal_uInt32 nRasterOp
);
639 void StrokeAndFillPath( bool bStroke
, bool bFill
);
641 void SetGfxMode( sal_Int32 nGfxMode
){ mnGfxMode
= nGfxMode
; };
642 sal_Int32
GetGfxMode() const { return mnGfxMode
; };
643 void SetBkMode( BkMode nMode
);
644 void SetBkColor( const Color
& rColor
);
645 void SetTextColor( const Color
& rColor
);
646 void SetTextAlign( sal_uInt32 nAlign
);
647 void CreateObject( GDIObjectType
, void* pStyle
= NULL
);
648 void CreateObject( sal_Int32 nIndex
, GDIObjectType
, void* pStyle
= NULL
);
649 void DeleteObject( sal_Int32 nIndex
);
650 void SelectObject( sal_Int32 nIndex
);
651 rtl_TextEncoding
GetCharSet(){ return maFont
.GetCharSet(); };
652 WinMtfFillStyle
& GetFillStyle () { return maFillStyle
; }
653 const vcl::Font
& GetFont() const { return maFont
;}
654 void SetTextLayoutMode( ComplexTextLayoutMode nLayoutMode
);
656 void ClearPath(){ aPathObj
.Init(); };
657 void ClosePath(){ aPathObj
.ClosePath(); };
658 const tools::PolyPolygon
& GetPathObj(){ return aPathObj
; };
660 void MoveTo( const Point
& rPoint
, bool bRecordPath
= false );
661 void LineTo( const Point
& rPoint
, bool bRecordPath
= false );
662 void DrawPixel( const Point
& rSource
, const Color
& rColor
);
663 void DrawRect( const Rectangle
& rRect
, bool bEdge
= true );
664 void DrawRoundRect( const Rectangle
& rRect
, const Size
& rSize
);
665 void DrawEllipse( const Rectangle
& rRect
);
667 const Rectangle
& rRect
,
668 const Point
& rStartAngle
,
669 const Point
& rEndAngle
,
673 const Rectangle
& rRect
,
674 const Point
& rStartAngle
,
675 const Point
& rEndAngle
678 const Rectangle
& rRect
,
679 const Point
& rStartAngle
,
680 const Point
& rEndAngle
682 void DrawPolygon( Polygon
& rPolygon
, bool bRecordPath
= false );
683 void DrawPolygon( Polygon
& rPolygon
, bool /*bDrawTo*/, bool bRecordPath
)
685 //For ReadAndDrawPolygon template compatibility
686 DrawPolygon(rPolygon
, bRecordPath
);
688 void DrawPolyPolygon( tools::PolyPolygon
& rPolyPolygon
, bool bRecordPath
= false );
691 bool bDrawTo
= false,
692 bool bRecordPath
= false
696 bool bDrawTo
= false,
697 bool bRecordPath
= false
699 void DrawText( Point
& rPosition
,
701 long* pDXArry
= NULL
,
702 bool bRecordPath
= false,
703 sal_Int32 nGraphicsMode
= GM_COMPATIBLE
);
705 void ResolveBitmapActions( BSaveStructList_impl
& rSaveList
);
707 void IntersectClipRect( const Rectangle
& rRect
);
708 void ExcludeClipRect( const Rectangle
& rRect
);
709 void MoveClipRegion( const Size
& rSize
);
711 const tools::PolyPolygon
& rPolyPoly
,
712 sal_Int32 nClippingMode
,
715 void SetDefaultClipPath();
716 void UpdateClipRegion();
717 void AddFromGDIMetaFile( GDIMetaFile
& rGDIMetaFile
);
719 void PassEMFPlus( void* pBuffer
, sal_uInt32 nLength
);
720 void PassEMFPlusHeaderInfo();
722 WinMtfOutput( GDIMetaFile
& rGDIMetaFile
);
723 virtual ~WinMtfOutput();
731 SvStream
* pWMF
; // the WMF/EMF file to be read
733 sal_uInt32 nStartPos
, nEndPos
;
734 BSaveStructList_impl aBmpSaveList
;
736 FilterConfigItem
* pFilterConfigItem
;
738 com::sun::star::uno::Reference
< com::sun::star::task::XStatusIndicator
> xStatusIndicator
;
740 // assures aSampledBrush is the actual brush of the GDIMetaFile
743 void Callback( sal_uInt16 nPercent
);
747 SvStream
& rStreamWMF
,
748 FilterConfigItem
* pConfigItem
= NULL
753 class EnhWMFReader
: public WinMtf
756 sal_Int32 nRecordCount
;
760 // reads and converts the rectangle
761 static Rectangle
ReadRectangle( sal_Int32
, sal_Int32
, sal_Int32
, sal_Int32
);
764 EnhWMFReader(SvStream
& rStreamWMF
, GDIMetaFile
& rGDIMetaFile
, FilterConfigItem
* pConfigItem
= NULL
);
768 void ReadEMFPlusComment(sal_uInt32 length
, bool& bHaveDC
);
770 template <class T
> void ReadAndDrawPolyPolygon();
771 template <class T
> void ReadAndDrawPolyLine();
772 template <class T
> Polygon
ReadPolygon(sal_uInt32 nStartIndex
, sal_uInt32 nPoints
);
773 template <class T
, class Drawer
> void ReadAndDrawPolygon(Drawer drawer
, const bool skipFirst
);
775 Rectangle
ReadRectangle();
778 class WMFReader
: public WinMtf
782 sal_uInt16 nUnitsPerInch
;
786 SvMemoryStream
* pEMFStream
;
788 // total number of comment records containing EMF data
789 sal_uInt32 nEMFRecCount
;
791 // number of EMF records read
794 // total size of embedded EMF data
797 sal_uInt32 nSkipActions
;
798 sal_uInt32 nCurrentAction
;
799 sal_uInt32 nUnicodeEscapeAction
;
801 WMF_EXTERNALHEADER
* pExternalHeader
;
803 // reads header of the WMF-Datei
806 // reads parameters of the record with the functionnumber nFunction.
807 void ReadRecordParams( sal_uInt16 nFunction
);
809 Point
ReadPoint(); // reads and converts a point (first X then Y)
810 Point
ReadYX(); // reads and converts a point (first Y then X)
811 Rectangle
ReadRectangle(); // reads and converts a rectangle
813 bool GetPlaceableBound( Rectangle
& rSize
, SvStream
* pStrm
);
817 WMFReader(SvStream
& rStreamWMF
, GDIMetaFile
& rGDIMetaFile
,
818 FilterConfigItem
* pConfigItem
= NULL
,
819 WMF_EXTERNALHEADER
* pExtHeader
= NULL
);
822 // read WMF file from stream and fill the GDIMetaFile
828 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */