LibreOffice Module vcl (master)  1
SvmReader.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sal/log.hxx>
21 #include <osl/thread.h>
22 #include <tools/stream.hxx>
23 #include <tools/vcompat.hxx>
24 
25 #include <vcl/filter/SvmReader.hxx>
26 #include <vcl/TypeSerializer.hxx>
27 #include <vcl/dibtools.hxx>
28 #include <vcl/gdimtf.hxx>
29 #include <vcl/metaact.hxx>
30 
31 #include "SvmConverter.hxx"
32 
33 namespace
34 {
35 class DepthGuard
36 {
37 private:
39  rtl_TextEncoding m_eOrigCharSet;
40 
41 public:
42  DepthGuard(ImplMetaReadData& rData, SvStream const& rIStm)
43  : m_rData(rData)
44  , m_eOrigCharSet(m_rData.meActualCharSet)
45  {
46  ++m_rData.mnParseDepth;
47  m_rData.meActualCharSet = rIStm.GetStreamCharSet();
48  }
49  bool TooDeep() const { return m_rData.mnParseDepth > 1024; }
50  ~DepthGuard()
51  {
52  --m_rData.mnParseDepth;
53  m_rData.meActualCharSet = m_eOrigCharSet;
54  }
55 };
56 }
57 
59  : mrStream(rIStm)
60 {
61 }
62 
64 {
65  if (mrStream.GetError())
66  {
67  SAL_WARN("vcl.gdi", "Stream error: " << mrStream.GetError());
68  return mrStream;
69  }
70 
71  sal_uInt64 nStmPos = mrStream.Tell();
72  SvStreamEndian nOldFormat = mrStream.GetEndian();
73 
74  mrStream.SetEndian(SvStreamEndian::LITTLE);
75 
76  try
77  {
78  char aId[7];
79  aId[0] = 0;
80  aId[6] = 0;
81  mrStream.ReadBytes(aId, 6);
82  if (mrStream.good() && !strcmp(aId, "VCLMTF"))
83  {
84  // new format
85  sal_uInt32 nStmCompressMode = 0;
86  sal_uInt32 nCount = 0;
87  std::unique_ptr<VersionCompatRead> pCompat(new VersionCompatRead(mrStream));
88 
89  mrStream.ReadUInt32(nStmCompressMode);
90  TypeSerializer aSerializer(mrStream);
91  MapMode aMapMode;
92  aSerializer.readMapMode(aMapMode);
93  rMetaFile.SetPrefMapMode(aMapMode);
94  Size aSize;
95  aSerializer.readSize(aSize);
96  rMetaFile.SetPrefSize(aSize);
97  mrStream.ReadUInt32(nCount);
98 
99  pCompat.reset(); // destructor writes stuff into the header
100 
101  std::unique_ptr<ImplMetaReadData> xReadData;
102  if (!pData)
103  {
104  xReadData.reset(new ImplMetaReadData);
105  pData = xReadData.get();
106  }
107  DepthGuard aDepthGuard(*pData, mrStream);
108 
109  if (aDepthGuard.TooDeep())
110  throw std::runtime_error("too much recursion");
111 
112  for (sal_uInt32 nAction = 0; (nAction < nCount) && !mrStream.eof(); nAction++)
113  {
115  if (pAction)
116  {
117  if (pAction->GetType() == MetaActionType::COMMENT)
118  {
119  MetaCommentAction* pCommentAct
120  = static_cast<MetaCommentAction*>(pAction.get());
121 
122  if (pCommentAct->GetComment() == "EMF_PLUS")
123  rMetaFile.UseCanvas(true);
124  }
125  rMetaFile.AddAction(pAction);
126  }
127  }
128  }
129  else
130  {
131  mrStream.Seek(nStmPos);
132  SVMConverter(mrStream, rMetaFile);
133  }
134  }
135  catch (...)
136  {
137  SAL_WARN("vcl", "GDIMetaFile exception during load");
139  };
140 
141  // check for errors
142  if (mrStream.GetError())
143  {
144  rMetaFile.Clear();
145  mrStream.Seek(nStmPos);
146  }
147 
148  mrStream.SetEndian(nOldFormat);
149  return mrStream;
150 }
151 
153 {
155  sal_uInt16 nTmp = 0;
156  mrStream.ReadUInt16(nTmp);
157  MetaActionType nType = static_cast<MetaActionType>(nTmp);
158 
159  switch (nType)
160  {
162  return DefaultHandler();
164  return PixelHandler();
166  return PointHandler();
168  return LineHandler();
170  return RectHandler();
172  return RoundRectHandler();
174  return EllipseHandler();
175  case MetaActionType::ARC:
176  return ArcHandler();
177  case MetaActionType::PIE:
178  return PieHandler();
180  return ChordHandler();
182  return PolyLineHandler();
184  return PolygonHandler();
186  return PolyPolygonHandler();
188  return TextHandler(pData);
190  return TextArrayHandler(pData);
192  return StretchTextHandler(pData);
194  return TextRectHandler(pData);
196  return TextLineHandler();
197  case MetaActionType::BMP:
198  return BmpHandler();
200  return BmpScaleHandler();
202  return BmpScalePartHandler();
204  return BmpExHandler();
206  return BmpExScaleHandler();
208  return BmpExScalePartHandler();
210  return MaskHandler();
212  return MaskScaleHandler();
214  return MaskScalePartHandler();
216  return GradientHandler();
218  return GradientExHandler();
220  return HatchHandler();
222  return WallpaperHandler();
224  return ClipRegionHandler();
230  return MoveClipRegionHandler();
232  return LineColorHandler();
234  return FillColorHandler();
236  return TextColorHandler();
238  return TextFillColorHandler();
240  return TextLineColorHandler();
242  return OverlineColorHandler();
244  return TextAlignHandler();
246  return MapModeHandler();
248  return FontHandler(pData);
250  return PushHandler();
251  case MetaActionType::POP:
252  return PopHandler();
254  return RasterOpHandler();
256  return TransparentHandler();
258  return FloatTransparentHandler(pData);
259  case MetaActionType::EPS:
260  return EPSHandler();
262  return RefPointHandler();
264  return CommentHandler();
266  return LayoutModeHandler();
268  return TextLanguageHandler();
269 
270  default:
271  {
272  VersionCompatRead aCompat(mrStream);
273  }
274  break;
275  }
276 
277  return pAction;
278 }
279 
281 {
282  sal_uInt32 nTmp(0);
283  mrStream.ReadUInt32(nTmp);
284  rColor = ::Color(ColorTransparency, nTmp);
285 }
286 
288 {
290 
291  VersionCompatRead aCompat(mrStream);
292  Color aColor;
293  ReadColor(aColor);
294  bool aBool(false);
295  mrStream.ReadCharAsBool(aBool);
296 
297  pAction->SetSetting(aBool);
298  pAction->SetColor(aColor);
299 
300  return pAction;
301 }
302 
304 {
306 
307  VersionCompatRead aCompat(mrStream);
308 
309  Color aColor;
310  ReadColor(aColor);
311  bool aBool(false);
312  mrStream.ReadCharAsBool(aBool);
313 
314  pAction->SetColor(aColor);
315  pAction->SetSetting(aBool);
316 
317  return pAction;
318 }
319 
321 {
323 
324  VersionCompatRead aCompat(mrStream);
325  TypeSerializer aSerializer(mrStream);
326 
327  tools::Rectangle aRectangle;
328  aSerializer.readRectangle(aRectangle);
329  pAction->SetRect(aRectangle);
330 
331  return pAction;
332 }
333 
335 {
337 
338  VersionCompatRead aCompat(mrStream);
339  TypeSerializer aSerializer(mrStream);
340 
341  Point aPoint;
342  aSerializer.readPoint(aPoint);
343  pAction->SetPoint(aPoint);
344 
345  return pAction;
346 }
347 
349 {
351 
352  VersionCompatRead aCompat(mrStream);
353  TypeSerializer aSerializer(mrStream);
354 
355  Point aPoint;
356  aSerializer.readPoint(aPoint);
357  Color aColor;
358  ReadColor(aColor);
359 
360  pAction->SetPoint(aPoint);
361  pAction->SetColor(aColor);
362 
363  return pAction;
364 }
365 
367 {
369 
370  VersionCompatRead aCompat(mrStream);
371 
372  // Version 1
373  TypeSerializer aSerializer(mrStream);
374  Point aPoint;
375  Point aEndPoint;
376  aSerializer.readPoint(aPoint);
377  aSerializer.readPoint(aEndPoint);
378 
379  pAction->SetStartPoint(aPoint);
380  pAction->SetEndPoint(aEndPoint);
381 
382  // Version 2
383  if (aCompat.GetVersion() >= 2)
384  {
385  LineInfo aLineInfo;
386  ReadLineInfo(mrStream, aLineInfo);
387  pAction->SetLineInfo(aLineInfo);
388  }
389 
390  return pAction;
391 }
392 
394 {
396 
397  VersionCompatRead aCompat(mrStream);
398  TypeSerializer aSerializer(mrStream);
399 
400  tools::Rectangle aRectangle;
401  aSerializer.readRectangle(aRectangle);
402  sal_uInt32 HorzRound(0);
403  sal_uInt32 VertRound(0);
404  mrStream.ReadUInt32(HorzRound).ReadUInt32(VertRound);
405 
406  pAction->SetRect(aRectangle);
407  pAction->SetHorzRound(HorzRound);
408  pAction->SetVertRound(VertRound);
409 
410  return pAction;
411 }
412 
414 {
416 
417  VersionCompatRead aCompat(mrStream);
418  TypeSerializer aSerializer(mrStream);
419 
420  tools::Rectangle aRectangle;
421  aSerializer.readRectangle(aRectangle);
422 
423  pAction->SetRect(aRectangle);
424 
425  return pAction;
426 }
427 
429 {
431 
432  VersionCompatRead aCompat(mrStream);
433  TypeSerializer aSerializer(mrStream);
434 
435  tools::Rectangle aRectangle;
436  aSerializer.readRectangle(aRectangle);
437  Point aPoint;
438  aSerializer.readPoint(aPoint);
439  Point aEndPoint;
440  aSerializer.readPoint(aEndPoint);
441 
442  pAction->SetRect(aRectangle);
443  pAction->SetStartPoint(aPoint);
444  pAction->SetEndPoint(aEndPoint);
445 
446  return pAction;
447 }
448 
450 {
452 
453  VersionCompatRead aCompat(mrStream);
454  TypeSerializer aSerializer(mrStream);
455 
456  tools::Rectangle aRectangle;
457  aSerializer.readRectangle(aRectangle);
458  Point aPoint;
459  aSerializer.readPoint(aPoint);
460  Point aEndPoint;
461  aSerializer.readPoint(aEndPoint);
462 
463  pAction->SetRect(aRectangle);
464  pAction->SetStartPoint(aPoint);
465  pAction->SetEndPoint(aEndPoint);
466 
467  return pAction;
468 }
469 
471 {
473 
474  VersionCompatRead aCompat(mrStream);
475  TypeSerializer aSerializer(mrStream);
476 
477  tools::Rectangle aRectangle;
478  aSerializer.readRectangle(aRectangle);
479  Point aPoint;
480  aSerializer.readPoint(aPoint);
481  Point aEndPoint;
482  aSerializer.readPoint(aEndPoint);
483 
484  pAction->SetRect(aRectangle);
485  pAction->SetStartPoint(aPoint);
486  pAction->SetEndPoint(aEndPoint);
487 
488  return pAction;
489 }
490 
492 {
494 
495  VersionCompatRead aCompat(mrStream);
496 
497  // Version 1
498  tools::Polygon aPolygon;
499  ReadPolygon(mrStream, aPolygon);
500 
501  // Version 2
502  if (aCompat.GetVersion() >= 2)
503  {
504  LineInfo aLineInfo;
505  ReadLineInfo(mrStream, aLineInfo);
506  pAction->SetLineInfo(aLineInfo);
507  }
508  if (aCompat.GetVersion() >= 3)
509  {
510  sal_uInt8 bHasPolyFlags(0);
511  mrStream.ReadUChar(bHasPolyFlags);
512  if (bHasPolyFlags)
513  aPolygon.Read(mrStream);
514  }
515  pAction->SetPolygon(aPolygon);
516 
517  return pAction;
518 }
519 
521 {
523 
524  VersionCompatRead aCompat(mrStream);
525 
526  tools::Polygon aPolygon;
527  ReadPolygon(mrStream, aPolygon); // Version 1
528 
529  if (aCompat.GetVersion() >= 2) // Version 2
530  {
531  sal_uInt8 bHasPolyFlags(0);
532  mrStream.ReadUChar(bHasPolyFlags);
533  if (bHasPolyFlags)
534  aPolygon.Read(mrStream);
535  }
536 
537  pAction->SetPolygon(aPolygon);
538 
539  return pAction;
540 }
541 
543 {
545 
546  VersionCompatRead aCompat(mrStream);
547  tools::PolyPolygon aPolyPolygon;
548  ReadPolyPolygon(mrStream, aPolyPolygon); // Version 1
549 
550  if (aCompat.GetVersion() < 2) // Version 2
551  {
552  pAction->SetPolyPolygon(aPolyPolygon);
553  return pAction;
554  }
555 
556  sal_uInt16 nNumberOfComplexPolygons(0);
557  mrStream.ReadUInt16(nNumberOfComplexPolygons);
558  const size_t nMinRecordSize = sizeof(sal_uInt16);
559  const size_t nMaxRecords = mrStream.remainingSize() / nMinRecordSize;
560  if (nNumberOfComplexPolygons > nMaxRecords)
561  {
562  SAL_WARN("vcl.gdi", "Parsing error: " << nMaxRecords << " max possible entries, but "
563  << nNumberOfComplexPolygons
564  << " claimed, truncating");
565  nNumberOfComplexPolygons = nMaxRecords;
566  }
567  for (sal_uInt16 i = 0; i < nNumberOfComplexPolygons; ++i)
568  {
569  sal_uInt16 nIndex(0);
570  mrStream.ReadUInt16(nIndex);
571  tools::Polygon aPoly;
572  aPoly.Read(mrStream);
573  if (nIndex >= aPolyPolygon.Count())
574  {
575  SAL_WARN("vcl.gdi", "svm contains polygon index " << nIndex
576  << " outside possible range "
577  << aPolyPolygon.Count());
578  continue;
579  }
580  aPolyPolygon.Replace(aPoly, nIndex);
581  }
582 
583  pAction->SetPolyPolygon(aPolyPolygon);
584 
585  return pAction;
586 }
587 
589 {
591 
592  VersionCompatRead aCompat(mrStream);
593  TypeSerializer aSerializer(mrStream);
594 
595  Point aPoint;
596  aSerializer.readPoint(aPoint);
598  sal_uInt16 nTmpIndex(0);
599  mrStream.ReadUInt16(nTmpIndex);
600  sal_uInt16 nTmpLen(0);
601  mrStream.ReadUInt16(nTmpLen);
602 
603  pAction->SetPoint(aPoint);
604 
605  if (aCompat.GetVersion() >= 2) // Version 2
607 
608  if (nTmpIndex > aStr.getLength())
609  {
610  SAL_WARN("vcl.gdi", "inconsistent offset");
611  nTmpIndex = aStr.getLength();
612  }
613 
614  if (nTmpLen > aStr.getLength() - nTmpIndex)
615  {
616  SAL_WARN("vcl.gdi", "inconsistent len");
617  nTmpLen = aStr.getLength() - nTmpIndex;
618  }
619 
620  pAction->SetIndex(nTmpIndex);
621  pAction->SetLen(nTmpLen);
622 
623  pAction->SetText(aStr);
624 
625  return pAction;
626 }
627 
629 {
630  rtl::Reference<MetaTextArrayAction> pAction(new MetaTextArrayAction);
631 
632  std::vector<sal_Int32> aArray;
633 
634  VersionCompatRead aCompat(mrStream);
635  TypeSerializer aSerializer(mrStream);
636 
637  Point aPoint;
638  aSerializer.readPoint(aPoint);
639  pAction->SetPoint(aPoint);
640 
642  pAction->SetText(aStr);
643 
644  sal_uInt16 nTmpIndex(0);
645  mrStream.ReadUInt16(nTmpIndex);
646 
647  sal_uInt16 nTmpLen(0);
648  mrStream.ReadUInt16(nTmpLen);
649 
650  sal_Int32 nAryLen(0);
651  mrStream.ReadInt32(nAryLen);
652 
653  if (nTmpLen > aStr.getLength() - nTmpIndex)
654  {
655  SAL_WARN("vcl.gdi", "inconsistent offset and len");
656  pAction->SetIndex(0);
657  pAction->SetLen(aStr.getLength());
658  return pAction;
659  }
660 
661  pAction->SetIndex(nTmpIndex);
662  pAction->SetLen(nTmpLen);
663 
664  if (nAryLen)
665  {
666  // #i9762#, #106172# Ensure that DX array is at least mnLen entries long
667  if (nTmpLen >= nAryLen)
668  {
669  try
670  {
671  aArray.resize(nTmpLen);
672  sal_Int32 i;
673  sal_Int32 val(0);
674  for (i = 0; i < nAryLen; i++)
675  {
676  mrStream.ReadInt32(val);
677  aArray[i] = val;
678  }
679  // #106172# setup remainder
680  for (; i < nTmpLen; i++)
681  aArray[i] = 0;
682  }
683  catch (std::bad_alloc&)
684  {
685  }
686  }
687  else
688  {
689  return pAction;
690  }
691  }
692 
693  if (aCompat.GetVersion() >= 2) // Version 2
694  {
696  pAction->SetText(aStr);
697 
698  if (nTmpLen > aStr.getLength() - nTmpIndex)
699  {
700  SAL_WARN("vcl.gdi", "inconsistent offset and len");
701  pAction->SetIndex(0);
702  pAction->SetLen(aStr.getLength());
703  aArray.clear();
704  }
705  }
706 
707  if (!aArray.empty())
708  pAction->SetDXArray(std::move(aArray));
709 
710  return pAction;
711 }
712 
714 {
716 
717  VersionCompatRead aCompat(mrStream);
718  TypeSerializer aSerializer(mrStream);
719 
720  Point aPoint;
721  aSerializer.readPoint(aPoint);
723  sal_uInt32 nTmpWidth(0);
724  mrStream.ReadUInt32(nTmpWidth);
725  sal_uInt16 nTmpIndex(0);
726  mrStream.ReadUInt16(nTmpIndex);
727  sal_uInt16 nTmpLen(0);
728  mrStream.ReadUInt16(nTmpLen);
729 
730  pAction->SetPoint(aPoint);
731  pAction->SetWidth(nTmpWidth);
732 
733  if (aCompat.GetVersion() >= 2) // Version 2
735 
736  if (nTmpIndex > aStr.getLength())
737  {
738  SAL_WARN("vcl.gdi", "inconsistent offset");
739  nTmpIndex = aStr.getLength();
740  }
741 
742  if (nTmpLen > aStr.getLength() - nTmpIndex)
743  {
744  SAL_WARN("vcl.gdi", "inconsistent len");
745  nTmpLen = aStr.getLength() - nTmpIndex;
746  }
747 
748  pAction->SetIndex(nTmpIndex);
749  pAction->SetLen(nTmpLen);
750 
751  pAction->SetText(aStr);
752 
753  return pAction;
754 }
755 
757 {
759 
760  VersionCompatRead aCompat(mrStream);
761  TypeSerializer aSerializer(mrStream);
762 
763  tools::Rectangle aRect;
764  aSerializer.readRectangle(aRect);
766  sal_uInt16 nTmp(0);
767  mrStream.ReadUInt16(nTmp);
768 
769  pAction->SetRect(aRect);
770  pAction->SetStyle(static_cast<DrawTextFlags>(nTmp));
771 
772  if (aCompat.GetVersion() >= 2) // Version 2
774 
775  pAction->SetText(aStr);
776 
777  return pAction;
778 }
779 
781 {
783 
784  VersionCompatRead aCompat(mrStream);
785  TypeSerializer aSerializer(mrStream);
786 
787  Point aPos;
788  aSerializer.readPoint(aPos);
789  sal_Int32 nTempWidth(0);
790  mrStream.ReadInt32(nTempWidth);
791 
792  pAction->SetStartPoint(aPos);
793  pAction->SetWidth(nTempWidth);
794 
795  sal_uInt32 nTempStrikeout(0);
796  mrStream.ReadUInt32(nTempStrikeout);
797  sal_uInt32 nTempUnderline(0);
798  mrStream.ReadUInt32(nTempUnderline);
799 
800  pAction->SetStrikeout(static_cast<FontStrikeout>(nTempStrikeout & SAL_MAX_ENUM));
801  pAction->SetUnderline(static_cast<FontLineStyle>(nTempUnderline & SAL_MAX_ENUM));
802 
803  if (aCompat.GetVersion() >= 2)
804  {
805  sal_uInt32 nTempOverline(0);
806  mrStream.ReadUInt32(nTempOverline);
807  pAction->SetOverline(static_cast<FontLineStyle>(nTempOverline & SAL_MAX_ENUM));
808  }
809 
810  return pAction;
811 }
812 
814 {
816 
817  VersionCompatRead aCompat(mrStream);
818  Bitmap aBmp;
819  ReadDIB(aBmp, mrStream, true);
820  TypeSerializer aSerializer(mrStream);
821  Point aPoint;
822  aSerializer.readPoint(aPoint);
823 
824  pAction->SetBitmap(aBmp);
825  pAction->SetPoint(aPoint);
826 
827  return pAction;
828 }
829 
830 namespace
831 {
832 void sanitizeNegativeSizeDimensions(Size& rSize)
833 {
834  if (rSize.Width() < 0)
835  {
836  SAL_WARN("vcl.gdi", "sanitizeNegativeSizeDimensions: negative width");
837  rSize.setWidth(0);
838  }
839 
840  if (rSize.Height() < 0)
841  {
842  SAL_WARN("vcl.gdi", "sanitizeNegativeSizeDimensions: negative height");
843  rSize.setHeight(0);
844  }
845 }
846 }
847 
849 {
851 
852  VersionCompatRead aCompat(mrStream);
853  Bitmap aBmp;
854  ReadDIB(aBmp, mrStream, true);
855  TypeSerializer aSerializer(mrStream);
856  Point aPoint;
857  aSerializer.readPoint(aPoint);
858 
859  Size aSz;
860  aSerializer.readSize(aSz);
861  sanitizeNegativeSizeDimensions(aSz);
862 
863  pAction->SetBitmap(aBmp);
864  pAction->SetPoint(aPoint);
865  pAction->SetSize(aSz);
866 
867  return pAction;
868 }
869 
871 {
872  rtl::Reference<MetaBmpScalePartAction> pAction(new MetaBmpScalePartAction);
873 
874  VersionCompatRead aCompat(mrStream);
875  Bitmap aBmp;
876  ReadDIB(aBmp, mrStream, true);
877  TypeSerializer aSerializer(mrStream);
878  Point aDestPoint;
879  aSerializer.readPoint(aDestPoint);
880  Size aDestSize;
881  aSerializer.readSize(aDestSize);
882  Point aSrcPoint;
883  aSerializer.readPoint(aSrcPoint);
884  Size aSrcSize;
885  aSerializer.readSize(aSrcSize);
886 
887  pAction->SetBitmap(aBmp);
888  pAction->SetDestPoint(aDestPoint);
889  pAction->SetDestSize(aDestSize);
890  pAction->SetSrcPoint(aSrcPoint);
891  pAction->SetSrcSize(aSrcSize);
892 
893  return pAction;
894 }
895 
897 {
899 
900  VersionCompatRead aCompat(mrStream);
901  BitmapEx aBmpEx;
902  ReadDIBBitmapEx(aBmpEx, mrStream);
903  TypeSerializer aSerializer(mrStream);
904  Point aPoint;
905  aSerializer.readPoint(aPoint);
906 
907  pAction->SetPoint(aPoint);
908  pAction->SetBitmapEx(aBmpEx);
909 
910  return pAction;
911 }
912 
914 {
916 
917  VersionCompatRead aCompat(mrStream);
918  BitmapEx aBmpEx;
919  ReadDIBBitmapEx(aBmpEx, mrStream);
920  TypeSerializer aSerializer(mrStream);
921  Point aPoint;
922  aSerializer.readPoint(aPoint);
923 
924  Size aSize;
925  aSerializer.readSize(aSize);
926  sanitizeNegativeSizeDimensions(aSize);
927 
928  pAction->SetBitmapEx(aBmpEx);
929  pAction->SetPoint(aPoint);
930  pAction->SetSize(aSize);
931 
932  return pAction;
933 }
934 
936 {
937  rtl::Reference<MetaBmpExScalePartAction> pAction(new MetaBmpExScalePartAction);
938 
939  VersionCompatRead aCompat(mrStream);
940  BitmapEx aBmpEx;
941  ReadDIBBitmapEx(aBmpEx, mrStream);
942  TypeSerializer aSerializer(mrStream);
943  Point aDstPoint;
944  aSerializer.readPoint(aDstPoint);
945  Size aDstSize;
946  aSerializer.readSize(aDstSize);
947  Point aSrcPoint;
948  aSerializer.readPoint(aSrcPoint);
949  Size aSrcSize;
950  aSerializer.readSize(aSrcSize);
951 
952  pAction->SetBitmapEx(aBmpEx);
953  pAction->SetDestPoint(aDstPoint);
954  pAction->SetDestSize(aDstSize);
955  pAction->SetSrcPoint(aSrcPoint);
956  pAction->SetSrcSize(aSrcSize);
957 
958  return pAction;
959 }
960 
962 {
964 
965  VersionCompatRead aCompat(mrStream);
966  Bitmap aBmp;
967  ReadDIB(aBmp, mrStream, true);
968  TypeSerializer aSerializer(mrStream);
969  Point aPoint;
970  aSerializer.readPoint(aPoint);
971 
972  pAction->SetBitmap(aBmp);
973  pAction->SetPoint(aPoint);
974 
975  return pAction;
976 }
977 
979 {
981 
982  VersionCompatRead aCompat(mrStream);
983  Bitmap aBmp;
984  ReadDIB(aBmp, mrStream, true);
985  TypeSerializer aSerializer(mrStream);
986  Point aPoint;
987  aSerializer.readPoint(aPoint);
988  Size aSize;
989  aSerializer.readSize(aSize);
990 
991  pAction->SetBitmap(aBmp);
992  pAction->SetPoint(aPoint);
993  pAction->SetSize(aSize);
994 
995  return pAction;
996 }
997 
999 {
1001 
1002  VersionCompatRead aCompat(mrStream);
1003  Bitmap aBmp;
1004  ReadDIB(aBmp, mrStream, true);
1005  Color aColor;
1006  ReadColor(aColor);
1007  TypeSerializer aSerializer(mrStream);
1008  Point aDstPt;
1009  aSerializer.readPoint(aDstPt);
1010  Size aDstSz;
1011  aSerializer.readSize(aDstSz);
1012  Point aSrcPt;
1013  aSerializer.readPoint(aSrcPt);
1014  Size aSrcSz;
1015  aSerializer.readSize(aSrcSz);
1016 
1017  pAction->SetBitmap(aBmp);
1018  pAction->SetColor(aColor);
1019  pAction->SetDestPoint(aDstPt);
1020  pAction->SetDestSize(aDstSz);
1021  pAction->SetSrcPoint(aSrcPt);
1022  pAction->SetSrcSize(aSrcSz);
1023 
1024  return pAction;
1025 }
1026 
1028 {
1030 
1031  VersionCompatRead aCompat(mrStream);
1032  TypeSerializer aSerializer(mrStream);
1033 
1034  tools::Rectangle aRect;
1035  aSerializer.readRectangle(aRect);
1036  Gradient aGradient;
1037  aSerializer.readGradient(aGradient);
1038 
1039  pAction->SetRect(aRect);
1040  pAction->SetGradient(aGradient);
1041 
1042  return pAction;
1043 }
1044 
1046 {
1048 
1049  VersionCompatRead aCompat(mrStream);
1050  tools::PolyPolygon aPolyPoly;
1051  ReadPolyPolygon(mrStream, aPolyPoly);
1052  TypeSerializer aSerializer(mrStream);
1053  Gradient aGradient;
1054  aSerializer.readGradient(aGradient);
1055 
1056  pAction->SetGradient(aGradient);
1057  pAction->SetPolyPolygon(aPolyPoly);
1058 
1059  return pAction;
1060 }
1061 
1063 {
1065 
1066  VersionCompatRead aCompat(mrStream);
1067  tools::PolyPolygon aPolyPoly;
1068  ReadPolyPolygon(mrStream, aPolyPoly);
1069  Hatch aHatch;
1070  ReadHatch(mrStream, aHatch);
1071 
1072  pAction->SetPolyPolygon(aPolyPoly);
1073  pAction->SetHatch(aHatch);
1074 
1075  return pAction;
1076 }
1077 
1079 {
1080  rtl::Reference<MetaWallpaperAction> pAction(new MetaWallpaperAction);
1081 
1082  VersionCompatRead aCompat(mrStream);
1083  Wallpaper aWallpaper;
1084  ReadWallpaper(mrStream, aWallpaper);
1085 
1086  pAction->SetWallpaper(aWallpaper);
1087 
1088  return pAction;
1089 }
1090 
1092 {
1094 
1095  VersionCompatRead aCompat(mrStream);
1096  vcl::Region aRegion;
1097  ReadRegion(mrStream, aRegion);
1098  bool aClip(false);
1099  mrStream.ReadCharAsBool(aClip);
1100 
1101  pAction->SetRegion(aRegion);
1102  pAction->SetClipping(aClip);
1103 
1104  return pAction;
1105 }
1106 
1108 {
1110 
1111  VersionCompatRead aCompat(mrStream);
1112  TypeSerializer aSerializer(mrStream);
1113  tools::Rectangle aRect;
1114  aSerializer.readRectangle(aRect);
1115 
1116  pAction->SetRect(aRect);
1117 
1118  return pAction;
1119 }
1120 
1122 {
1124 
1125  VersionCompatRead aCompat(mrStream);
1126  vcl::Region aRegion;
1127  ReadRegion(mrStream, aRegion);
1128  pAction->SetRegion(aRegion);
1129 
1130  return pAction;
1131 }
1132 
1134 {
1136 
1137  VersionCompatRead aCompat(mrStream);
1138  sal_Int32 nTmpHM(0), nTmpVM(0);
1139  mrStream.ReadInt32(nTmpHM).ReadInt32(nTmpVM);
1140 
1141  pAction->SetHorzMove(nTmpHM);
1142  pAction->SetVertMove(nTmpVM);
1143 
1144  return pAction;
1145 }
1146 
1148 {
1150 
1151  VersionCompatRead aCompat(mrStream);
1152  Color aColor;
1153  ReadColor(aColor);
1154 
1155  pAction->SetColor(aColor);
1156 
1157  return pAction;
1158 }
1159 
1161 {
1163 
1164  VersionCompatRead aCompat(mrStream);
1165  Color aColor;
1166  ReadColor(aColor);
1167  bool bSet(false);
1168  mrStream.ReadCharAsBool(bSet);
1169 
1170  pAction->SetColor(aColor);
1171  pAction->SetSetting(bSet);
1172 
1173  return pAction;
1174 }
1175 
1177 {
1179 
1180  VersionCompatRead aCompat(mrStream);
1181  Color aColor;
1182  ReadColor(aColor);
1183  bool bSet(false);
1184  mrStream.ReadCharAsBool(bSet);
1185 
1186  pAction->SetColor(aColor);
1187  pAction->SetSetting(bSet);
1188 
1189  return pAction;
1190 }
1191 
1193 {
1195 
1196  VersionCompatRead aCompat(mrStream);
1197  Color aColor;
1198  ReadColor(aColor);
1199  bool bSet(false);
1200  mrStream.ReadCharAsBool(bSet);
1201 
1202  pAction->SetColor(aColor);
1203  pAction->SetSetting(bSet);
1204 
1205  return pAction;
1206 }
1207 
1209 {
1211 
1212  VersionCompatRead aCompat(mrStream);
1213  sal_uInt16 nTmp16(0);
1214  mrStream.ReadUInt16(nTmp16);
1215 
1216  pAction->SetTextAlign(static_cast<TextAlign>(nTmp16));
1217 
1218  return pAction;
1219 }
1220 
1222 {
1224 
1225  VersionCompatRead aCompat(mrStream);
1226  TypeSerializer aSerializer(mrStream);
1227  MapMode aMapMode;
1228  aSerializer.readMapMode(aMapMode);
1229 
1230  pAction->SetMapMode(aMapMode);
1231 
1232  return pAction;
1233 }
1234 
1236 {
1238 
1239  VersionCompatRead aCompat(mrStream);
1240  vcl::Font aFont;
1241  ReadFont(mrStream, aFont);
1242  pData->meActualCharSet = aFont.GetCharSet();
1243  if (pData->meActualCharSet == RTL_TEXTENCODING_DONTKNOW)
1244  pData->meActualCharSet = osl_getThreadTextEncoding();
1245 
1246  pAction->SetFont(aFont);
1247 
1248  return pAction;
1249 }
1250 
1252 {
1254 
1255  VersionCompatRead aCompat(mrStream);
1256  sal_uInt16 nTmp(0);
1257  mrStream.ReadUInt16(nTmp);
1258 
1259  pAction->SetPushFlags(static_cast<vcl::PushFlags>(nTmp));
1260 
1261  return pAction;
1262 }
1263 
1265 {
1267 
1268  VersionCompatRead aCompat(mrStream);
1269 
1270  return pAction;
1271 }
1272 
1274 {
1276 
1277  sal_uInt16 nTmp16(0);
1278 
1279  VersionCompatRead aCompat(mrStream);
1280  mrStream.ReadUInt16(nTmp16);
1281 
1282  pAction->SetRasterOp(static_cast<RasterOp>(nTmp16));
1283 
1284  return pAction;
1285 }
1286 
1288 {
1290 
1291  VersionCompatRead aCompat(mrStream);
1292  tools::PolyPolygon aPolyPoly;
1293  ReadPolyPolygon(mrStream, aPolyPoly);
1294  sal_uInt16 nTransPercent(0);
1295  mrStream.ReadUInt16(nTransPercent);
1296 
1297  pAction->SetPolyPolygon(aPolyPoly);
1298  pAction->SetTransparence(nTransPercent);
1299 
1300  return pAction;
1301 }
1302 
1304 {
1306 
1307  VersionCompatRead aCompat(mrStream);
1308  GDIMetaFile aMtf;
1309  SvmReader aReader(mrStream);
1310  aReader.Read(aMtf, pData);
1311  TypeSerializer aSerializer(mrStream);
1312  Point aPoint;
1313  aSerializer.readPoint(aPoint);
1314 
1315  Size aSize;
1316  aSerializer.readSize(aSize);
1317  sanitizeNegativeSizeDimensions(aSize);
1318 
1319  Gradient aGradient;
1320  aSerializer.readGradient(aGradient);
1321 
1322  pAction->SetGDIMetaFile(aMtf);
1323  pAction->SetPoint(aPoint);
1324  pAction->SetSize(aSize);
1325  pAction->SetGradient(aGradient);
1326 
1327  return pAction;
1328 }
1329 
1331 {
1333 
1334  VersionCompatRead aCompat(mrStream);
1335  TypeSerializer aSerializer(mrStream);
1336  GfxLink aGfxLink;
1337  aSerializer.readGfxLink(aGfxLink);
1338  Point aPoint;
1339  aSerializer.readPoint(aPoint);
1340  Size aSize;
1341  aSerializer.readSize(aSize);
1342  GDIMetaFile aSubst;
1343  Read(aSubst);
1344 
1345  pAction->SetLink(aGfxLink);
1346  pAction->SetPoint(aPoint);
1347  pAction->SetSize(aSize);
1348  pAction->SetSubstitute(aSubst);
1349 
1350  return pAction;
1351 }
1352 
1354 {
1356 
1357  VersionCompatRead aCompat(mrStream);
1358  TypeSerializer aSerializer(mrStream);
1359 
1360  Point aRefPoint;
1361  aSerializer.readPoint(aRefPoint);
1362  bool bSet(false);
1363  mrStream.ReadCharAsBool(bSet);
1364 
1365  pAction->SetRefPoint(aRefPoint);
1366  pAction->SetSetting(bSet);
1367 
1368  return pAction;
1369 }
1370 
1372 {
1374 
1375  VersionCompatRead aCompat(mrStream);
1376  OString aComment;
1378  sal_Int32 nValue(0);
1379  sal_uInt32 nDataSize(0);
1380  mrStream.ReadInt32(nValue).ReadUInt32(nDataSize);
1381 
1382  if (nDataSize > mrStream.remainingSize())
1383  {
1384  SAL_WARN("vcl.gdi", "Parsing error: " << mrStream.remainingSize() << " available data, but "
1385  << nDataSize << " claimed, truncating");
1386  nDataSize = mrStream.remainingSize();
1387  }
1388 
1389  SAL_INFO("vcl.gdi", "MetaCommentAction::Read " << aComment);
1390 
1391  std::unique_ptr<sal_uInt8[]> pData;
1392  pData.reset();
1393 
1394  if (nDataSize)
1395  {
1396  pData.reset(new sal_uInt8[nDataSize]);
1397  mrStream.ReadBytes(pData.get(), nDataSize);
1398  }
1399 
1400  pAction->SetComment(aComment);
1401  pAction->SetDataSize(nDataSize);
1402  pAction->SetValue(nValue);
1403  pAction->SetData(pData.get(), nDataSize);
1404 
1405  return pAction;
1406 }
1407 
1409 {
1411 
1412  VersionCompatRead aCompat(mrStream);
1413  sal_uInt32 tmp(0);
1414  mrStream.ReadUInt32(tmp);
1415 
1416  pAction->SetLayoutMode(static_cast<vcl::text::ComplexTextLayoutFlags>(tmp));
1417 
1418  return pAction;
1419 }
1420 
1422 {
1424 
1425  VersionCompatRead aCompat(mrStream);
1426  sal_uInt16 nTmp = 0;
1427  mrStream.ReadUInt16(nTmp);
1428 
1429  pAction->SetTextLanguage(static_cast<LanguageType>(nTmp));
1430 
1431  return pAction;
1432 }
1433 
1435 {
1437 }
1438 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 Count() const
rtl::Reference< MetaAction > FillColorHandler()
Definition: SvmReader.cxx:303
rtl::Reference< MetaAction > EPSHandler()
Definition: SvmReader.cxx:1330
rtl::Reference< MetaAction > PopHandler()
Definition: SvmReader.cxx:1264
Definition: hatch.hxx:46
sal_Int32 nIndex
SvStream & mrStream
Definition: SvmReader.hxx:29
bool ReadDIB(Bitmap &rTarget, SvStream &rIStm, bool bFileHeader, bool bMSOFormat)
Definition: dibtools.cxx:1709
rtl_TextEncoding meActualCharSet
Definition: metaact.hxx:54
void setWidth(tools::Long nWidth)
SvStream & ReadPolyPolygon(SvStream &rIStream, tools::PolyPolygon &rPolyPoly)
void readPoint(Point &rPoint)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
rtl::Reference< MetaAction > TransparentHandler()
Definition: SvmReader.cxx:1287
void readMapMode(MapMode &rMapMode)
rtl::Reference< MetaAction > TextColorHandler()
Definition: SvmReader.cxx:1147
rtl::Reference< MetaAction > ISectRectClipRegionHandler()
Definition: SvmReader.cxx:1107
std::unique_ptr< sal_Int32[]> pData
void readRectangle(Rectangle &rRectangle)
rtl::Reference< MetaAction > BmpScaleHandler()
Definition: SvmReader.cxx:848
SvStream & ReadPolygon(SvStream &rIStream, tools::Polygon &rPoly)
rtl::Reference< MetaAction > ClipRegionHandler()
Definition: SvmReader.cxx:1091
SvStream & ReadCharAsBool(bool &rBool)
void SetPrefSize(const Size &rSize)
Definition: gdimtf.hxx:173
void Clear()
Definition: gdimtf.cxx:270
sal_uInt64 Seek(sal_uInt64 nPos)
rtl::Reference< MetaAction > LayoutModeHandler()
Definition: SvmReader.cxx:1408
rtl::Reference< MetaAction > StretchTextHandler(const ImplMetaReadData *pData)
Definition: SvmReader.cxx:713
rtl::Reference< MetaAction > TextHandler(const ImplMetaReadData *pData)
Definition: SvmReader.cxx:588
rtl::Reference< MetaAction > BmpHandler()
Definition: SvmReader.cxx:813
SvStream & ReadWallpaper(SvStream &rIStm, Wallpaper &rImplWallpaper)
Definition: wall.cxx:30
rtl::Reference< MetaAction > TextAlignHandler()
Definition: SvmReader.cxx:1208
rtl::Reference< MetaAction > PolygonHandler()
Definition: SvmReader.cxx:520
rtl::Reference< MetaAction > EllipseHandler()
Definition: SvmReader.cxx:413
rtl::Reference< MetaAction > PushHandler()
Definition: SvmReader.cxx:1251
SvStream & Read(GDIMetaFile &rMetaFile, ImplMetaReadData *pData=nullptr)
Definition: SvmReader.cxx:63
rtl::Reference< MetaAction > TextLineColorHandler()
Definition: SvmReader.cxx:1176
rtl::Reference< MetaAction > RectHandler()
Definition: SvmReader.cxx:320
void Read(SvStream &rIStream)
constexpr tools::Long Width() const
OString read_uInt16_lenPrefixed_uInt8s_ToOString(SvStream &rStrm)
rtl::Reference< MetaAction > BmpExScaleHandler()
Definition: SvmReader.cxx:913
ErrCode GetError() const
const Sequence< Sequence< double > > & m_rData
bool ReadDIBBitmapEx(BitmapEx &rTarget, SvStream &rIStm, bool bFileHeader, bool bMSOFormat)
Definition: dibtools.cxx:1718
bool eof() const
int nCount
rtl::Reference< MetaAction > BmpExHandler()
Definition: SvmReader.cxx:896
MetaActionType
rtl::Reference< MetaAction > PolyPolygonHandler()
Definition: SvmReader.cxx:542
rtl::Reference< MetaAction > RoundRectHandler()
Definition: SvmReader.cxx:393
sal_uInt64 remainingSize()
rtl::Reference< MetaAction > PieHandler()
Definition: SvmReader.cxx:449
void readSize(Size &rSize)
rtl::Reference< MetaAction > MetaActionHandler(ImplMetaReadData *pData)
Definition: SvmReader.cxx:152
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
rtl::Reference< MetaAction > ArcHandler()
Definition: SvmReader.cxx:428
void Replace(const Polygon &rPoly, sal_uInt16 nPos)
SvStream & ReadLineInfo(SvStream &rIStm, LineInfo &rLineInfo)
Definition: lineinfo.cxx:142
int i
rtl::Reference< MetaAction > GradientHandler()
Definition: SvmReader.cxx:1027
SvmReader(SvStream &rIStm)
Definition: SvmReader.cxx:58
rtl::Reference< MetaAction > LineHandler()
Definition: SvmReader.cxx:366
rtl::Reference< MetaAction > TextArrayHandler(const ImplMetaReadData *pData)
Definition: SvmReader.cxx:628
rtl::Reference< MetaAction > ISectRegionClipRegionHandler()
Definition: SvmReader.cxx:1121
OUString read_uInt16_lenPrefixed_uInt16s_ToOUString(SvStream &rStrm)
void UseCanvas(bool _bUseCanvas)
Definition: gdimtf.cxx:2333
void SetError(ErrCode nErrorCode)
SvStream & ReadUChar(unsigned char &rChar)
ColorTransparency
rtl::Reference< MetaAction > TextRectHandler(const ImplMetaReadData *pData)
Definition: SvmReader.cxx:756
rtl::Reference< MetaAction > BmpExScalePartHandler()
Definition: SvmReader.cxx:935
rtl::Reference< MetaAction > TextLineHandler()
Definition: SvmReader.cxx:780
SvStream & ReadRegion(SvStream &rIStrm, vcl::Region &rRegion)
Definition: region.cxx:1530
SvStream & ReadHatch(SvStream &rIStm, Hatch &rHatch)
Definition: gdi/hatch.cxx:79
SvStream & ReadInt32(sal_Int32 &rInt32)
rtl::Reference< MetaAction > OverlineColorHandler()
Definition: SvmReader.cxx:1192
std::size_t ReadBytes(void *pData, std::size_t nSize)
rtl::Reference< MetaAction > RefPointHandler()
Definition: SvmReader.cxx:1353
rtl::Reference< MetaAction > RasterOpHandler()
Definition: SvmReader.cxx:1273
rtl::Reference< MetaAction > PixelHandler()
Definition: SvmReader.cxx:348
rtl::Reference< MetaAction > HatchHandler()
Definition: SvmReader.cxx:1062
SvStreamEndian GetEndian() const
rtl::Reference< MetaAction > MaskHandler()
Definition: SvmReader.cxx:961
rtl::Reference< MetaAction > PointHandler()
Definition: SvmReader.cxx:334
rtl::Reference< MetaAction > MaskScalePartHandler()
Definition: SvmReader.cxx:998
constexpr tools::Long Height() const
unsigned char sal_uInt8
SvStream & ReadFont(SvStream &rIStm, vcl::Font &rFont)
Definition: font/font.cxx:565
sal_uInt16 GetVersion() const
void AddAction(const rtl::Reference< MetaAction > &pAction)
Definition: gdimtf.cxx:581
void SetEndian(SvStreamEndian SvStreamEndian)
rtl::Reference< MetaAction > LineColorHandler()
Definition: SvmReader.cxx:287
#define SAL_INFO(area, stream)
#define SAL_MAX_ENUM
#define SVSTREAM_FILEFORMAT_ERROR
Definition: errcode.hxx:260
rtl_TextEncoding GetStreamCharSet() const
sal_uInt64 Tell() const
QPRO_FUNC_TYPE nType
rtl::Reference< MetaAction > TextLanguageHandler()
Definition: SvmReader.cxx:1421
rtl::Reference< MetaAction > MapModeHandler()
Definition: SvmReader.cxx:1221
rtl::Reference< MetaAction > MoveClipRegionHandler()
Definition: SvmReader.cxx:1133
rtl::Reference< MetaAction > ChordHandler()
Definition: SvmReader.cxx:470
rtl::Reference< MetaAction > MaskScaleHandler()
Definition: SvmReader.cxx:978
bool good() const
void setHeight(tools::Long nHeight)
#define SAL_WARN(area, stream)
void readGfxLink(GfxLink &rGfxLink)
DepthGuard(HWPFile &rFile)
SvStreamEndian
const OString & GetComment() const
Definition: metaact.hxx:1692
rtl::Reference< MetaAction > PolyLineHandler()
Definition: SvmReader.cxx:491
static rtl::Reference< MetaAction > DefaultHandler()
Definition: SvmReader.cxx:1434
rtl::Reference< MetaAction > GradientExHandler()
Definition: SvmReader.cxx:1045
Converts old SVGDI aka SVM1 format data to current VCLMTF aka SVM2 format metafile data...
void readGradient(Gradient &rGradient)
rtl::Reference< MetaAction > TextFillColorHandler()
Definition: SvmReader.cxx:1160
rtl::Reference< MetaAction > FontHandler(ImplMetaReadData *pData)
Definition: SvmReader.cxx:1235
aStr
rtl::Reference< MetaAction > BmpScalePartHandler()
Definition: SvmReader.cxx:870
rtl_TextEncoding GetCharSet() const
Definition: font/font.cxx:887
rtl::Reference< MetaAction > WallpaperHandler()
Definition: SvmReader.cxx:1078
rtl::Reference< MetaAction > FloatTransparentHandler(ImplMetaReadData *pData)
Definition: SvmReader.cxx:1303
sal_Int16 nValue
void SetPrefMapMode(const MapMode &rMapMode)
Definition: gdimtf.hxx:176
void ReadColor(::Color &rColor)
Definition: SvmReader.cxx:280
OUString ReadUniOrByteString(rtl_TextEncoding eSrcCharSet)
rtl::Reference< MetaAction > CommentHandler()
Definition: SvmReader.cxx:1371
OUString aId