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_EMFIO_INC_MTFTOOLS_HXX
21 #define INCLUDED_EMFIO_INC_MTFTOOLS_HXX
23 #include <basegfx/utils/b2dclipstate.hxx>
24 #include <tools/poly.hxx>
25 #include <vcl/font.hxx>
26 #include <vcl/bitmap.hxx>
27 #include <vcl/bitmapex.hxx>
28 #include <vcl/lineinfo.hxx>
29 #include <vcl/outdevstate.hxx>
30 #include <vcl/FilterConfigItem.hxx>
32 #include "emfiodllapi.h"
36 #define COMPLEXREGION 3
55 #define MWT_IDENTITY 1
56 #define MWT_LEFTMULTIPLY 2
57 #define MWT_RIGHTMULTIPLY 3
60 #define ENHMETA_STOCK_OBJECT 0x80000000
62 /* Stock Logical Objects */
64 #define LTGRAY_BRUSH 1
66 #define DKGRAY_BRUSH 3
72 #define ANSI_FIXED_FONT 11
73 #define ANSI_VAR_FONT 12
74 #define SYSTEM_FIXED_FONT 16
78 enum class WMFRasterOp
{
92 #define MM_LOENGLISH 4
93 #define MM_HIENGLISH 5
95 #define MM_ISOTROPIC 7
96 #define MM_ANISOTROPIC 8
99 #define GM_COMPATIBLE 1
100 #define GM_ADVANCED 2
102 /* StretchBlt() modes */
103 #define BLACKONWHITE 1
104 #define WHITEONBLACK 2
105 #define COLORONCOLOR 3
107 #define STRETCH_ANDSCANS BLACKONWHITE
108 #define STRETCH_ORSCANS WHITEONBLACK
109 #define STRETCH_DELETESCANS COLORONCOLOR
111 #define LF_FACESIZE 32
119 sal_Int32 lfEscapement
;
120 sal_Int32 lfOrientation
;
123 sal_uInt8 lfUnderline
;
124 sal_uInt8 lfStrikeOut
;
126 sal_uInt8 lfOutPrecision
;
127 sal_uInt8 lfClipPrecision
;
129 sal_uInt8 lfPitchAndFamily
;
130 OUString alfFaceName
;
144 , lfPitchAndFamily(0)
150 #define TA_NOUPDATECP 0x0000
151 #define TA_UPDATECP 0x0001
152 #define TA_LEFT 0x0000
153 #define TA_RIGHT 0x0002
154 #define TA_CENTER 0x0006
155 #define TA_RIGHT_CENTER (TA_RIGHT | TA_CENTER)
156 #define TA_TOP 0x0000
157 #define TA_BOTTOM 0x0008
158 #define TA_BASELINE 0x0018
160 #define SRCCOPY 0x00CC0020L
161 #define SRCPAINT 0x00EE0086L
162 #define SRCAND 0x008800C6L
163 #define SRCINVERT 0x00660046L
164 #define SRCERASE 0x00440328L
165 #define PATCOPY 0x00F00021L
166 #define PATINVERT 0x005A0049L
167 #define BLACKNESS 0x00000042L
168 #define WHITENESS 0x00FF0062L
174 #define PS_DASHDOTDOT 4
176 #define PS_INSIDEFRAME 6
177 #define PS_STYLE_MASK 15
179 #define PS_ENDCAP_ROUND 0x000
180 #define PS_ENDCAP_SQUARE 0x100
181 #define PS_ENDCAP_FLAT 0x200
182 #define PS_ENDCAP_STYLE_MASK 0xF00
184 #define PS_JOIN_ROUND 0x0000
185 #define PS_JOIN_BEVEL 0x1000
186 #define PS_JOIN_MITER 0x2000
187 #define PS_JOIN_STYLE_MASK 0xF000
189 #define ANSI_CHARSET 0
190 #define DEFAULT_CHARSET 1
191 #define SYMBOL_CHARSET 2
192 #define SHIFTJIS_CHARSET 128
193 #define HANGEUL_CHARSET 129
194 #define GB2312_CHARSET 134
195 #define CHINESEBIG5_CHARSET 136
196 #define OEM_CHARSET 255
198 #define JOHAB_CHARSET 130
199 #define HEBREW_CHARSET 177
200 #define ARABIC_CHARSET 178
201 #define GREEK_CHARSET 161
202 #define TURKISH_CHARSET 162
203 #define VIETNAMESE_CHARSET 163
204 #define THAI_CHARSET 222
205 #define EASTEUROPE_CHARSET 238
206 #define RUSSIAN_CHARSET 204
207 #define MAC_CHARSET 77
208 #define BALTIC_CHARSET 186
210 #define ETO_CLIPPED 0x0004
212 #define ETO_GLYPH_INDEX 0x0010
213 #define ETO_RTLREADING 0x0080
214 /*_WIN32_WINNT >= 0x0500*/
215 #define ETO_PDY 0x2000
217 #define DEFAULT_PITCH 0x00
218 #define FIXED_PITCH 0x01
219 #define VARIABLE_PITCH 0x02
222 #define FF_DONTCARE 0x00
223 #define FF_ROMAN 0x10
224 #define FF_SWISS 0x20
225 #define FF_MODERN 0x30
226 #define FF_SCRIPT 0x40
227 #define FF_DECORATIVE 0x50
230 #define FW_EXTRALIGHT 200
232 #define FW_NORMAL 400
233 #define FW_MEDIUM 500
234 #define FW_SEMIBOLD 600
236 #define FW_EXTRABOLD 800
237 #define FW_ULTRALIGHT 200
238 #define FW_ULTRABOLD 800
247 #define BS_DIBPATTERN 5
248 #define BS_DIBPATTERNPT 6
249 #define BS_PATTERN8X8 7
250 #define BS_DIBPATTERN8X8 8
251 #define BS_MONOPATTERN 9
253 #define RDH_RECTANGLES 1
254 #define W_MFCOMMENT 15
255 #define PRIVATE_ESCAPE_UNICODE 2
258 #define UNDOCUMENTED_WIN_RCL_RELATION 32
259 #define MS_FIXPOINT_BITCOUNT_28_4 4
260 #define HUNDREDTH_MILLIMETERS_PER_MILLIINCH 2.54
261 #define MILLIINCH_PER_TWIPS 1.44
263 //============================ WmfReader ==================================
269 basegfx::utils::B2DClipState maClip
;
272 WinMtfClipPath() : maClip() {};
274 void setClipPath(const tools::PolyPolygon
& rPolyPolygon
, sal_Int32 nClippingMode
);
275 void intersectClipRect(const tools::Rectangle
& rRect
);
276 void excludeClipRect(const tools::Rectangle
& rRect
);
277 void moveClipRegion(const Size
& rSize
);
278 void setDefaultClipPath();
280 bool isEmpty() const { return maClip
.isCleared(); }
282 basegfx::B2DPolyPolygon
const & getClipPath() const;
284 bool operator==(const WinMtfClipPath
& rPath
) const
286 return maClip
== rPath
.maClip
;
290 class WinMtfPathObj
: public tools::PolyPolygon
307 void AddPoint(const Point
& rPoint
);
308 void AddPolygon(const tools::Polygon
& rPoly
);
309 void AddPolyLine(const tools::Polygon
& rPoly
);
310 void AddPolyPolygon(const tools::PolyPolygon
& rPolyPolygon
);
313 struct EMFIO_DLLPUBLIC GDIObj
315 virtual ~GDIObj() = default; // Polymorphic base class
318 struct EMFIO_DLLPUBLIC WinMtfFontStyle
: GDIObj
322 explicit WinMtfFontStyle(LOGFONTW
const & rLogFont
);
325 enum class WinMtfFillStyleType
330 struct WinMtfFillStyle
: GDIObj
334 WinMtfFillStyleType aType
;
338 : aFillColor(COL_BLACK
)
339 , bTransparent(false)
340 , aType(WinMtfFillStyleType::Solid
)
343 WinMtfFillStyle(const Color
& rColor
, bool bTrans
= false)
345 , bTransparent(bTrans
)
346 , aType(WinMtfFillStyleType::Solid
)
349 explicit WinMtfFillStyle(Bitmap
const & rBmp
)
350 : bTransparent(false)
351 , aType(WinMtfFillStyleType::Pattern
)
355 bool operator==(const WinMtfFillStyle
& rStyle
)
357 return aFillColor
== rStyle
.aFillColor
358 && bTransparent
== rStyle
.bTransparent
359 && aType
== rStyle
.aType
;
363 struct WinMtfLineStyle
: GDIObj
370 : aLineColor(COL_BLACK
)
371 , bTransparent(false)
374 WinMtfLineStyle(const Color
& rColor
, bool bTrans
= false)
376 , bTransparent(bTrans
)
379 WinMtfLineStyle(const Color
& rColor
, const LineInfo
& rStyle
, bool bTrans
)
382 , bTransparent(bTrans
)
385 bool operator==(const WinMtfLineStyle
& rStyle
)
387 return aLineColor
== rStyle
.aLineColor
388 && bTransparent
== rStyle
.bTransparent
389 && aLineInfo
== rStyle
.aLineInfo
;
412 SvStream
& operator >> (SvStream
& rInStream
, XForm
& rXForm
);
417 sal_uInt32 nMapMode
, nGfxMode
;
418 ComplexTextLayoutFlags nTextLayoutMode
;
419 sal_Int32 nWinOrgX
, nWinOrgY
, nWinExtX
, nWinExtY
;
420 sal_Int32 nDevOrgX
, nDevOrgY
, nDevWidth
, nDevHeight
;
422 WinMtfLineStyle aLineStyle
;
423 WinMtfFillStyle aFillStyle
;
428 sal_uInt32 nTextAlign
;
432 WinMtfPathObj maPathObj
;
433 WinMtfClipPath maClipPath
;
436 bool bFillStyleSelected
;
442 tools::Rectangle aOutRect
;
445 BSaveStruct(const Bitmap
& rBmp
, const tools::Rectangle
& rOutRect
, sal_uInt32 nRop
)
451 BSaveStruct(const BitmapEx
& rBmpEx
, const tools::Rectangle
& rOutRect
, sal_uInt32 nRop
)
458 class EMFIO_DLLPUBLIC MtfTools
460 MtfTools(MtfTools
const &) = delete;
461 MtfTools
& operator =(MtfTools
const &) = delete;
464 WinMtfPathObj maPathObj
;
465 WinMtfClipPath maClipPath
;
467 WinMtfLineStyle maLatestLineStyle
;
468 WinMtfLineStyle maLineStyle
;
469 WinMtfLineStyle maNopLineStyle
;
470 WinMtfFillStyle maLatestFillStyle
;
471 WinMtfFillStyle maFillStyle
;
472 WinMtfFillStyle maNopFillStyle
;
474 vcl::Font maLatestFont
;
476 sal_uInt32 mnLatestTextAlign
;
477 sal_uInt32 mnTextAlign
;
478 Color maLatestTextColor
;
480 Color maLatestBkColor
;
482 ComplexTextLayoutFlags mnLatestTextLayoutMode
;
483 ComplexTextLayoutFlags mnTextLayoutMode
;
484 BkMode mnLatestBkMode
;
486 RasterOp meLatestRasterOp
;
489 std::vector
< std::unique_ptr
<GDIObj
> > mvGDIObj
;
492 std::vector
< std::shared_ptr
<SaveStruct
> > mvSaveStack
;
494 sal_uInt32 mnGfxMode
;
495 sal_uInt32 mnMapMode
;
500 sal_Int32 mnDevWidth
;
501 sal_Int32 mnDevHeight
;
507 sal_Int32 mnPixX
; // Reference Device in pixel
508 sal_Int32 mnPixY
; // Reference Device in pixel
509 sal_Int32 mnMillX
; // Reference Device in Mill
510 sal_Int32 mnMillY
; // Reference Device in Mill
511 tools::Rectangle mrclFrame
;
512 tools::Rectangle mrclBounds
;
514 GDIMetaFile
* mpGDIMetaFile
;
516 SvStream
* mpInputStream
; // the WMF/EMF file to be read
517 sal_uInt32 mnStartPos
;
519 std::vector
<std::unique_ptr
<BSaveStruct
>> maBmpSaveList
;
522 bool mbFillStyleSelected
: 1;
523 bool mbClipNeedsUpdate
: 1;
524 bool mbComplexClip
: 1;
525 bool mbIsMapWinSet
: 1;
526 bool mbIsMapDevSet
: 1;
528 void UpdateLineStyle();
529 void UpdateFillStyle();
531 Point
ImplMap(const Point
& rPt
);
532 Point
ImplScale(const Point
& rPt
);
533 Size
ImplMap(const Size
& rSize
, bool bDoWorldTransform
= true);
534 tools::Rectangle
ImplMap(const tools::Rectangle
& rRectangle
);
535 void ImplMap(vcl::Font
& rFont
);
536 tools::Polygon
& ImplMap(tools::Polygon
& rPolygon
);
537 tools::PolyPolygon
& ImplMap(tools::PolyPolygon
& rPolyPolygon
);
538 void ImplScale(tools::Polygon
& rPolygon
);
539 tools::PolyPolygon
& ImplScale(tools::PolyPolygon
& rPolyPolygon
);
540 void ImplResizeObjectArry(sal_uInt32 nNewEntry
);
541 void ImplSetNonPersistentLineColorTransparenz();
542 void ImplDrawClippedPolyPolygon(const tools::PolyPolygon
& rPolyPoly
);
543 void ImplDrawBitmap(const Point
& rPos
, const Size
& rSize
, const BitmapEx
& rBitmap
);
547 void SetDevByWin(); //Hack to set varying defaults for incompletely defined files.
548 void SetDevOrg(const Point
& rPoint
);
549 void SetDevOrgOffset(sal_Int32 nXAdd
, sal_Int32 nYAdd
);
550 void SetDevExt(const Size
& rSize
, bool regular
= true);
551 void ScaleDevExt(double fX
, double fY
);
553 void SetWinOrg(const Point
& rPoint
, bool bIsEMF
= false);
554 void SetWinOrgOffset(sal_Int32 nX
, sal_Int32 nY
);
555 void SetWinExt(const Size
& rSize
, bool bIsEMF
= false);
556 void ScaleWinExt(double fX
, double fY
);
558 void SetrclBounds(const tools::Rectangle
& rRect
);
559 void SetrclFrame(const tools::Rectangle
& rRect
);
560 void SetRefPix(const Size
& rSize
);
561 void SetRefMill(const Size
& rSize
);
563 void SetMapMode(sal_uInt32 mnMapMode
);
564 void SetWorldTransform(const XForm
& rXForm
);
565 void ModifyWorldTransform(const XForm
& rXForm
, sal_uInt32 nMode
);
570 WMFRasterOp
SetRasterOp(WMFRasterOp nRasterOp
);
571 void StrokeAndFillPath(bool bStroke
, bool bFill
);
573 void SetGfxMode(sal_Int32 nGfxMode
) { mnGfxMode
= nGfxMode
; };
574 sal_Int32
GetGfxMode() const { return mnGfxMode
; };
575 void SetBkMode(BkMode nMode
);
576 void SetBkColor(const Color
& rColor
);
577 void SetTextColor(const Color
& rColor
);
578 void SetTextAlign(sal_uInt32 nAlign
);
580 void CreateObject(std::unique_ptr
<GDIObj
> pObject
);
581 void CreateObjectIndexed(sal_Int32 nIndex
, std::unique_ptr
<GDIObj
> pObject
);
584 void DeleteObject(sal_Int32 nIndex
);
585 void SelectObject(sal_Int32 nIndex
);
586 rtl_TextEncoding
GetCharSet() { return maFont
.GetCharSet(); };
587 const vcl::Font
& GetFont() const { return maFont
; }
588 void SetTextLayoutMode(ComplexTextLayoutFlags nLayoutMode
);
590 void ClearPath() { maPathObj
.Init(); };
591 void ClosePath() { maPathObj
.ClosePath(); };
592 const tools::PolyPolygon
& GetPathObj() { return maPathObj
; };
594 void MoveTo(const Point
& rPoint
, bool bRecordPath
= false);
595 void LineTo(const Point
& rPoint
, bool bRecordPath
= false);
596 void DrawPixel(const Point
& rSource
, const Color
& rColor
);
597 void DrawRect(const tools::Rectangle
& rRect
, bool bEdge
= true);
598 void DrawRoundRect(const tools::Rectangle
& rRect
, const Size
& rSize
);
599 void DrawEllipse(const tools::Rectangle
& rRect
);
601 const tools::Rectangle
& rRect
,
602 const Point
& rStartAngle
,
603 const Point
& rEndAngle
,
607 const tools::Rectangle
& rRect
,
608 const Point
& rStartAngle
,
609 const Point
& rEndAngle
612 const tools::Rectangle
& rRect
,
613 const Point
& rStartAngle
,
614 const Point
& rEndAngle
616 void DrawPolygon(tools::Polygon rPolygon
, bool bRecordPath
);
617 void DrawPolyPolygon(tools::PolyPolygon
& rPolyPolygon
, bool bRecordPath
= false);
618 void DrawPolyLine(tools::Polygon rPolygon
,
619 bool bDrawTo
= false,
620 bool bRecordPath
= false
622 void DrawPolyBezier(tools::Polygon rPolygon
,
626 void DrawText(Point
& rPosition
,
627 OUString
const & rString
,
628 long* pDXArry
= nullptr,
629 long* pDYArry
= nullptr,
630 bool bRecordPath
= false,
631 sal_Int32 nGraphicsMode
= GM_COMPATIBLE
);
633 void ResolveBitmapActions(std::vector
<std::unique_ptr
<BSaveStruct
>>& rSaveList
);
635 void IntersectClipRect(const tools::Rectangle
& rRect
);
636 void ExcludeClipRect(const tools::Rectangle
& rRect
);
637 void MoveClipRegion(const Size
& rSize
);
639 const tools::PolyPolygon
& rPolyPoly
,
640 sal_Int32 nClippingMode
,
643 void SetDefaultClipPath();
644 void UpdateClipRegion();
645 void AddFromGDIMetaFile(GDIMetaFile
& rGDIMetaFile
);
647 void PassEMFPlus(void const * pBuffer
, sal_uInt32 nLength
);
648 void PassEMFPlusHeaderInfo();
652 explicit MtfTools(GDIMetaFile
& rGDIMetaFile
, SvStream
& rStreamWMF
);
653 ~MtfTools() COVERITY_NOEXCEPT_FALSE
;
659 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */