bump product version to 6.3.0.0.beta1
[LibreOffice.git] / emfio / inc / mtftools.hxx
blobfc1ec644d9dc4ccc01008e3ce58a1097eef20a52
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
34 #define ERROR 0
35 #define NULLREGION 1
36 #define COMPLEXREGION 3
38 #define RGN_AND 1
39 #define RGN_OR 2
40 #define RGN_XOR 3
41 #define RGN_DIFF 4
42 #define RGN_COPY 5
44 namespace emfio
46 enum class BkMode
48 NONE = 0,
49 Transparent = 1,
50 OPAQUE = 2,
54 /* xform stuff */
55 #define MWT_IDENTITY 1
56 #define MWT_LEFTMULTIPLY 2
57 #define MWT_RIGHTMULTIPLY 3
58 #define MWT_SET 4
60 #define ENHMETA_STOCK_OBJECT 0x80000000
62 /* Stock Logical Objects */
63 #define WHITE_BRUSH 0
64 #define LTGRAY_BRUSH 1
65 #define GRAY_BRUSH 2
66 #define DKGRAY_BRUSH 3
67 #define BLACK_BRUSH 4
68 #define NULL_BRUSH 5
69 #define WHITE_PEN 6
70 #define BLACK_PEN 7
71 #define NULL_PEN 8
72 #define ANSI_FIXED_FONT 11
73 #define ANSI_VAR_FONT 12
74 #define SYSTEM_FIXED_FONT 16
76 namespace emfio
78 enum class WMFRasterOp {
79 NONE = 0,
80 Black = 1,
81 Not = 6,
82 XorPen = 7,
83 Nop = 11,
84 CopyPen = 13
88 /* Mapping modes */
89 #define MM_TEXT 1
90 #define MM_LOMETRIC 2
91 #define MM_HIMETRIC 3
92 #define MM_LOENGLISH 4
93 #define MM_HIENGLISH 5
94 #define MM_TWIPS 6
95 #define MM_ISOTROPIC 7
96 #define MM_ANISOTROPIC 8
98 /* Graphics modes */
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
106 #define HALFTONE 4
107 #define STRETCH_ANDSCANS BLACKONWHITE
108 #define STRETCH_ORSCANS WHITEONBLACK
109 #define STRETCH_DELETESCANS COLORONCOLOR
111 #define LF_FACESIZE 32
113 namespace emfio
115 struct LOGFONTW
117 sal_Int32 lfHeight;
118 sal_Int32 lfWidth;
119 sal_Int32 lfEscapement;
120 sal_Int32 lfOrientation;
121 sal_Int32 lfWeight;
122 sal_uInt8 lfItalic;
123 sal_uInt8 lfUnderline;
124 sal_uInt8 lfStrikeOut;
125 sal_uInt8 lfCharSet;
126 sal_uInt8 lfOutPrecision;
127 sal_uInt8 lfClipPrecision;
128 sal_uInt8 lfQuality;
129 sal_uInt8 lfPitchAndFamily;
130 OUString alfFaceName;
131 LOGFONTW()
132 : lfHeight(0)
133 , lfWidth(0)
134 , lfEscapement(0)
135 , lfOrientation(0)
136 , lfWeight(0)
137 , lfItalic(0)
138 , lfUnderline(0)
139 , lfStrikeOut(0)
140 , lfCharSet(0)
141 , lfOutPrecision(0)
142 , lfClipPrecision(0)
143 , lfQuality(0)
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
170 #define PS_SOLID 0
171 #define PS_DASH 1
172 #define PS_DOT 2
173 #define PS_DASHDOT 3
174 #define PS_DASHDOTDOT 4
175 #define PS_NULL 5
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
197 /*WINVER >= 0x0400*/
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
211 /*WINVER >= 0x0400*/
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
221 /* Font Families */
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
229 #define FW_THIN 100
230 #define FW_EXTRALIGHT 200
231 #define FW_LIGHT 300
232 #define FW_NORMAL 400
233 #define FW_MEDIUM 500
234 #define FW_SEMIBOLD 600
235 #define FW_BOLD 700
236 #define FW_EXTRABOLD 800
237 #define FW_ULTRALIGHT 200
238 #define FW_ULTRABOLD 800
239 #define FW_BLACK 900
241 #define BS_SOLID 0
242 #define BS_NULL 1
243 #define BS_HOLLOW 1
244 #define BS_HATCHED 2
245 #define BS_PATTERN 3
246 #define BS_INDEXED 4
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
257 //Scalar constants
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 ==================================
265 namespace emfio
267 class WinMtfClipPath
269 basegfx::utils::B2DClipState maClip;
271 public:
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
292 bool bClosed;
294 public:
296 WinMtfPathObj() :
297 bClosed(true)
300 void Init()
302 Clear();
303 bClosed = true;
306 void ClosePath();
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
320 vcl::Font aFont;
322 explicit WinMtfFontStyle(LOGFONTW const & rLogFont);
325 enum class WinMtfFillStyleType
327 Solid, Pattern
330 struct WinMtfFillStyle : GDIObj
332 Color aFillColor;
333 bool bTransparent;
334 WinMtfFillStyleType aType;
335 Bitmap aBmp;
337 WinMtfFillStyle()
338 : aFillColor(COL_BLACK)
339 , bTransparent(false)
340 , aType(WinMtfFillStyleType::Solid)
343 WinMtfFillStyle(const Color& rColor, bool bTrans = false)
344 : aFillColor(rColor)
345 , bTransparent(bTrans)
346 , aType(WinMtfFillStyleType::Solid)
349 explicit WinMtfFillStyle(Bitmap const & rBmp)
350 : bTransparent(false)
351 , aType(WinMtfFillStyleType::Pattern)
352 , aBmp(rBmp)
355 bool operator==(const WinMtfFillStyle& rStyle)
357 return aFillColor == rStyle.aFillColor
358 && bTransparent == rStyle.bTransparent
359 && aType == rStyle.aType;
363 struct WinMtfLineStyle : GDIObj
365 Color aLineColor;
366 LineInfo aLineInfo;
367 bool bTransparent;
369 WinMtfLineStyle()
370 : aLineColor(COL_BLACK)
371 , bTransparent(false)
374 WinMtfLineStyle(const Color& rColor, bool bTrans = false)
375 : aLineColor(rColor)
376 , bTransparent(bTrans)
379 WinMtfLineStyle(const Color& rColor, const LineInfo& rStyle, bool bTrans)
380 : aLineColor(rColor)
381 , aLineInfo(rStyle)
382 , bTransparent(bTrans)
385 bool operator==(const WinMtfLineStyle& rStyle)
387 return aLineColor == rStyle.aLineColor
388 && bTransparent == rStyle.bTransparent
389 && aLineInfo == rStyle.aLineInfo;
393 struct XForm
395 float eM11;
396 float eM12;
397 float eM21;
398 float eM22;
399 float eDx;
400 float eDy;
402 XForm()
403 : eM11(1.0f)
404 , eM12(0.0f)
405 , eM21(0.0f)
406 , eM22(1.0f)
407 , eDx(0.0f)
408 , eDy(0.0f)
412 SvStream& operator >> (SvStream& rInStream, XForm& rXForm);
414 struct SaveStruct
416 BkMode nBkMode;
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;
425 vcl::Font aFont;
426 Color aBkColor;
427 Color aTextColor;
428 sal_uInt32 nTextAlign;
429 RasterOp eRasterOp;
431 Point aActPos;
432 WinMtfPathObj maPathObj;
433 WinMtfClipPath maClipPath;
434 XForm aXForm;
436 bool bFillStyleSelected;
439 struct BSaveStruct
441 BitmapEx aBmpEx;
442 tools::Rectangle aOutRect;
443 sal_uInt32 nWinRop;
445 BSaveStruct(const Bitmap& rBmp, const tools::Rectangle& rOutRect, sal_uInt32 nRop)
446 : aBmpEx(rBmp)
447 , aOutRect(rOutRect)
448 , nWinRop(nRop)
451 BSaveStruct(const BitmapEx& rBmpEx, const tools::Rectangle& rOutRect, sal_uInt32 nRop)
452 : aBmpEx(rBmpEx)
453 , aOutRect(rOutRect)
454 , nWinRop(nRop)
458 class EMFIO_DLLPUBLIC MtfTools
460 MtfTools(MtfTools const &) = delete;
461 MtfTools& operator =(MtfTools const &) = delete;
463 protected:
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;
475 vcl::Font maFont;
476 sal_uInt32 mnLatestTextAlign;
477 sal_uInt32 mnTextAlign;
478 Color maLatestTextColor;
479 Color maTextColor;
480 Color maLatestBkColor;
481 Color maBkColor;
482 ComplexTextLayoutFlags mnLatestTextLayoutMode;
483 ComplexTextLayoutFlags mnTextLayoutMode;
484 BkMode mnLatestBkMode;
485 BkMode mnBkMode;
486 RasterOp meLatestRasterOp;
487 RasterOp meRasterOp;
489 std::vector< std::unique_ptr<GDIObj> > mvGDIObj;
490 Point maActPos;
491 WMFRasterOp mnRop;
492 std::vector< std::shared_ptr<SaveStruct> > mvSaveStack;
494 sal_uInt32 mnGfxMode;
495 sal_uInt32 mnMapMode;
497 XForm maXForm;
498 sal_Int32 mnDevOrgX;
499 sal_Int32 mnDevOrgY;
500 sal_Int32 mnDevWidth;
501 sal_Int32 mnDevHeight;
502 sal_Int32 mnWinOrgX;
503 sal_Int32 mnWinOrgY;
504 sal_Int32 mnWinExtX;
505 sal_Int32 mnWinExtY;
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;
518 sal_uInt32 mnEndPos;
519 std::vector<std::unique_ptr<BSaveStruct>> maBmpSaveList;
521 bool mbNopMode : 1;
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);
545 public:
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);
567 void Push();
568 void Pop();
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);
582 void CreateObject();
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);
600 void DrawArc(
601 const tools::Rectangle& rRect,
602 const Point& rStartAngle,
603 const Point& rEndAngle,
604 bool bDrawTo = false
606 void DrawPie(
607 const tools::Rectangle& rRect,
608 const Point& rStartAngle,
609 const Point& rEndAngle
611 void DrawChord(
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,
623 bool bDrawTo,
624 bool bRecordPath
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);
638 void SetClipPath(
639 const tools::PolyPolygon& rPolyPoly,
640 sal_Int32 nClippingMode,
641 bool bIsMapped
643 void SetDefaultClipPath();
644 void UpdateClipRegion();
645 void AddFromGDIMetaFile(GDIMetaFile& rGDIMetaFile);
647 void PassEMFPlus(void const * pBuffer, sal_uInt32 nLength);
648 void PassEMFPlusHeaderInfo();
650 Color ReadColor();
652 explicit MtfTools(GDIMetaFile& rGDIMetaFile, SvStream& rStreamWMF);
653 ~MtfTools() COVERITY_NOEXCEPT_FALSE;
657 #endif
659 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */