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 .
21 #include <osl/thread.h>
22 #include <sal/log.hxx>
23 #include <vcl/BitmapTools.hxx>
24 #include <vcl/graph.hxx>
25 #include <vcl/gdimtf.hxx>
26 #include <tools/poly.hxx>
27 #include <tools/fract.hxx>
28 #include <tools/stream.hxx>
29 #include <vcl/virdev.hxx>
36 #include <vcl/FilterConfigItem.hxx>
37 // complete FilterConfigItem for GraphicImport under -fsanitize=function
39 namespace PictReaderInternal
{
40 //! utilitary class to store a pattern, ...
44 Pattern() : penStyle(PEN_SOLID
),
45 brushStyle(BRUSH_SOLID
),
51 //! reads black/white pattern from SvStream
52 sal_uLong
read(SvStream
&stream
);
54 void setColor(Color col
) { isColor
= true; color
= col
; }
55 /** returns a color which can be "used" to replace the pattern,
56 * created from ForeColor and BackColor, ...
58 * note: maybe, we must also use some mode PatCopy, ... to define the color
60 Color
getColor(Color bkColor
, Color fgColor
) const {
61 if (isColor
) return color
;
62 // we create a gray pattern from nBitCount
63 double alpha
= nBitCount
/ 64.0;
64 return Color(sal_uInt8(alpha
*fgColor
.GetRed()+(1.0-alpha
)*bkColor
.GetRed()),
65 sal_uInt8(alpha
*fgColor
.GetGreen()+(1.0-alpha
)*bkColor
.GetGreen()),
66 sal_uInt8(alpha
*fgColor
.GetBlue()+(1.0-alpha
)*bkColor
.GetBlue()));
69 //! returns true if this is the default pattern
70 bool isDefault() const { return !isRead
; }
72 enum PenStyle
{ PEN_NULL
, PEN_SOLID
, PEN_DOT
, PEN_DASH
, PEN_DASHDOT
};
73 enum BrushStyle
{ BRUSH_SOLID
, BRUSH_HORZ
, BRUSH_VERT
,
74 BRUSH_CROSS
, BRUSH_DIAGCROSS
, BRUSH_UPDIAG
, BRUSH_DOWNDIAG
,
75 BRUSH_25
, BRUSH_50
, BRUSH_75
};
77 enum PenStyle penStyle
;
78 enum BrushStyle brushStyle
;
81 bool isColor
; // true if it is a color pattern
85 // flag to know if the pattern came from reading the picture, or if it is the default pattern
89 sal_uLong
Pattern::read(SvStream
&stream
) {
90 unsigned char nbyte
[8];
91 sal_uLong nHiBytes
, nLoBytes
;
94 // count the no of bits in pattern which are set to 1:
96 for (unsigned char & ny
: nbyte
) {
97 stream
.ReadChar( reinterpret_cast<char&>(ny
) );
98 for (short nx
=0; nx
<8; nx
++) {
99 if ( (ny
& (1<<nx
)) != 0 ) nBitCount
++;
103 // store pattern in 2 long words:
104 nHiBytes
=(((((static_cast<sal_uLong
>(nbyte
[0])<<8)|
105 static_cast<sal_uLong
>(nbyte
[1]))<<8)|
106 static_cast<sal_uLong
>(nbyte
[2]))<<8)|
107 static_cast<sal_uLong
>(nbyte
[3]);
108 nLoBytes
=(((((static_cast<sal_uLong
>(nbyte
[4])<<8)|
109 static_cast<sal_uLong
>(nbyte
[5]))<<8)|
110 static_cast<sal_uLong
>(nbyte
[6]))<<8)|
111 static_cast<sal_uLong
>(nbyte
[7]);
113 // create a PenStyle:
114 if (nBitCount
<=0) penStyle
=PEN_NULL
;
115 else if (nBitCount
<=16) penStyle
=PEN_DOT
;
116 else if (nBitCount
<=32) penStyle
=PEN_DASHDOT
;
117 else if (nBitCount
<=48) penStyle
=PEN_DASH
;
118 else penStyle
=PEN_SOLID
;
120 // create a BrushStyle:
121 if (nHiBytes
==0xffffffff && nLoBytes
==0xffffffff) brushStyle
=BRUSH_SOLID
;
122 else if (nHiBytes
==0xff000000 && nLoBytes
==0x00000000) brushStyle
=BRUSH_HORZ
;
123 else if (nHiBytes
==0x80808080 && nLoBytes
==0x80808080) brushStyle
=BRUSH_VERT
;
124 else if (nHiBytes
==0xff808080 && nLoBytes
==0x80808080) brushStyle
=BRUSH_CROSS
;
125 else if (nHiBytes
==0x01824428 && nLoBytes
==0x10284482) brushStyle
=BRUSH_DIAGCROSS
;
126 else if (nHiBytes
==0x80402010 && nLoBytes
==0x08040201) brushStyle
=BRUSH_UPDIAG
;
127 else if (nHiBytes
==0x01020408 && nLoBytes
==0x10204080) brushStyle
=BRUSH_DOWNDIAG
;
128 else if (nBitCount
<=24) brushStyle
=BRUSH_25
;
129 else if (nBitCount
<=40) brushStyle
=BRUSH_50
;
130 else if (nBitCount
<=56) brushStyle
=BRUSH_75
;
131 else brushStyle
=BRUSH_SOLID
;
139 //============================ PictReader ==================================
141 enum class PictDrawingMethod
{
142 FRAME
, PAINT
, ERASE
, INVERT
, FILL
,
147 typedef class PictReaderInternal::Pattern Pattern
;
150 SvStream
* pPict
; // The Pict file to read.
151 VclPtr
<VirtualDevice
> pVirDev
; // Here the drawing method will be called.
152 // A recording into the GDIMetaFile will take place.
154 sal_uLong nOrigPos
; // Initial position in pPict.
155 bool IsVersion2
; // If it is a version 2 Pictfile.
156 tools::Rectangle aBoundingRect
; // Min/Max-Rectangle for the whole drawing.
162 Pattern eActPenPattern
;
163 Pattern eActFillPattern
;
164 Pattern eActBackPattern
;
166 // Note: Postscript mode is stored by setting eActRop to RasterOp::N1
168 PictDrawingMethod eActMethod
;
177 Point
ReadDeltaH(Point aBase
);
178 Point
ReadDeltaV(Point aBase
);
180 Point
ReadUnsignedDeltaH(Point aBase
);
181 Point
ReadUnsignedDeltaV(Point aBase
);
187 Color
ReadRGBColor();
189 void ReadRectangle(tools::Rectangle
& rRect
);
191 sal_uLong
ReadPolygon(tools::Polygon
& rPoly
);
193 sal_uLong
ReadPixPattern(Pattern
&pattern
);
195 tools::Rectangle aLastRect
;
196 sal_uLong
ReadAndDrawRect(PictDrawingMethod eMethod
);
197 sal_uLong
ReadAndDrawSameRect(PictDrawingMethod eMethod
);
199 tools::Rectangle aLastRoundRect
;
200 sal_uLong
ReadAndDrawRoundRect(PictDrawingMethod eMethod
);
201 sal_uLong
ReadAndDrawSameRoundRect(PictDrawingMethod eMethod
);
203 tools::Rectangle aLastOval
;
204 sal_uLong
ReadAndDrawOval(PictDrawingMethod eMethod
);
205 sal_uLong
ReadAndDrawSameOval(PictDrawingMethod eMethod
);
207 tools::Polygon aLastPolygon
;
208 sal_uLong
ReadAndDrawPolygon(PictDrawingMethod eMethod
);
209 sal_uLong
ReadAndDrawSamePolygon(PictDrawingMethod eMethod
);
211 tools::Rectangle aLastArcRect
;
212 sal_uLong
ReadAndDrawArc(PictDrawingMethod eMethod
);
213 sal_uLong
ReadAndDrawSameArc(PictDrawingMethod eMethod
);
215 sal_uLong
ReadAndDrawRgn(PictDrawingMethod eMethod
);
216 sal_uLong
ReadAndDrawSameRgn(PictDrawingMethod eMethod
);
218 // returns true if there's no need to print the shape/text/frame
219 bool IsInvisible( PictDrawingMethod eMethod
) const {
220 if ( eActROP
== RasterOp::N1
) return true;
221 if ( eMethod
== PictDrawingMethod::FRAME
&& ( nActPenSize
.Width() == 0 || nActPenSize
.Height() == 0 ) ) return true;
225 void DrawingMethod(PictDrawingMethod eMethod
);
227 sal_uLong
ReadAndDrawText();
229 sal_uLong
ReadPixMapEtc(BitmapEx
& rBitmap
, bool bBaseAddr
, bool bColorTable
,
230 tools::Rectangle
* pSrcRect
, tools::Rectangle
* pDestRect
,
231 bool bMode
, bool bMaskRgn
);
234 // Reads the header of the Pict file, set IsVersion and aBoundingRect
236 sal_uLong
ReadData(sal_uInt16 nOpcode
);
237 // Reads the date of anOopcode and executes the operation.
238 // The number of data bytes belonging to the opcode will be returned
241 void SetLineColor( const Color
& rColor
);
242 void SetFillColor( const Color
& rColor
);
244 // OSNOLA: returns the text encoding which must be used for system id
245 static rtl_TextEncoding
GetTextEncoding (sal_uInt16 fId
= 0xFFFF);
254 , eActROP(RasterOp::OverPaint
)
255 , eActMethod(PictDrawingMethod::UNDEFINED
)
257 aActFont
.SetCharSet(GetTextEncoding());
260 void ReadPict( SvStream
& rStreamPict
, GDIMetaFile
& rGDIMetaFile
);
261 // reads a pict file from the stream and fills the GDIMetaFile
265 static void SetByte(sal_uInt16
& nx
, sal_uInt16 ny
, vcl::bitmap::RawBitmap
& rBitmap
, sal_uInt16 nPixelSize
, sal_uInt8 nDat
, sal_uInt16 nWidth
, std::vector
<Color
> const & rvPalette
)
270 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[(nDat
>> 7) & 1]);
271 if ( nx
== nWidth
) break;
272 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[(nDat
>> 6) & 1]);
273 if ( nx
== nWidth
) break;
274 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[(nDat
>> 5) & 1]);
275 if ( nx
== nWidth
) break;
276 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[(nDat
>> 4) & 1]);
277 if ( nx
== nWidth
) break;
278 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[(nDat
>> 3) & 1]);
279 if ( nx
== nWidth
) break;
280 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[(nDat
>> 2) & 1]);
281 if ( nx
== nWidth
) break;
282 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[(nDat
>> 1) & 1]);
283 if ( nx
== nWidth
) break;
284 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[nDat
& 1]);
287 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[nDat
>> 6]);
288 if ( nx
== nWidth
) break;
289 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[(nDat
>>4)&3]);
290 if ( nx
== nWidth
) break;
291 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[(nDat
>>2)&3]);
292 if ( nx
== nWidth
) break;
293 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[nDat
& 3]);
296 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[nDat
>> 4]);
297 if ( nx
== nWidth
) break;
298 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[nDat
& 0x0f]);
301 rBitmap
.SetPixel(ny
, nx
++, rvPalette
[nDat
]);
306 //=================== methods of PictReader ==============================
307 rtl_TextEncoding
PictReader::GetTextEncoding (sal_uInt16 fId
) {
308 static rtl_TextEncoding enc
= [&]()
310 rtl_TextEncoding def
= osl_getThreadTextEncoding();
311 // we keep osl_getThreadTextEncoding only if it is a mac encoding
313 case RTL_TEXTENCODING_APPLE_ROMAN
:
314 case RTL_TEXTENCODING_APPLE_ARABIC
:
315 case RTL_TEXTENCODING_APPLE_CENTEURO
:
316 case RTL_TEXTENCODING_APPLE_CROATIAN
:
317 case RTL_TEXTENCODING_APPLE_CYRILLIC
:
318 case RTL_TEXTENCODING_APPLE_DEVANAGARI
:
319 case RTL_TEXTENCODING_APPLE_FARSI
:
320 case RTL_TEXTENCODING_APPLE_GREEK
:
321 case RTL_TEXTENCODING_APPLE_GUJARATI
:
322 case RTL_TEXTENCODING_APPLE_GURMUKHI
:
323 case RTL_TEXTENCODING_APPLE_HEBREW
:
324 case RTL_TEXTENCODING_APPLE_ICELAND
:
325 case RTL_TEXTENCODING_APPLE_ROMANIAN
:
326 case RTL_TEXTENCODING_APPLE_THAI
:
327 case RTL_TEXTENCODING_APPLE_TURKISH
:
328 case RTL_TEXTENCODING_APPLE_UKRAINIAN
:
329 case RTL_TEXTENCODING_APPLE_CHINSIMP
:
330 case RTL_TEXTENCODING_APPLE_CHINTRAD
:
331 case RTL_TEXTENCODING_APPLE_JAPANESE
:
332 case RTL_TEXTENCODING_APPLE_KOREAN
:
337 return RTL_TEXTENCODING_APPLE_ROMAN
;
339 if (fId
== 13) return RTL_TEXTENCODING_ADOBE_DINGBATS
; // CHECKME
340 if (fId
== 23) return RTL_TEXTENCODING_ADOBE_SYMBOL
;
344 void PictReader::SetLineColor( const Color
& rColor
)
346 pVirDev
->SetLineColor( rColor
);
349 void PictReader::SetFillColor( const Color
& rColor
)
351 pVirDev
->SetFillColor( rColor
);
354 Point
PictReader::ReadPoint()
358 pPict
->ReadInt16( ny
).ReadInt16( nx
);
360 Point
aPoint( static_cast<long>(nx
) - aBoundingRect
.Left(),
361 static_cast<long>(ny
) - aBoundingRect
.Top() );
363 SAL_INFO("filter.pict", "ReadPoint: " << aPoint
);
367 Point
PictReader::ReadDeltaH(Point aBase
)
371 pPict
->ReadChar( reinterpret_cast<char&>(ndh
) );
373 return Point( aBase
.X() + static_cast<long>(ndh
), aBase
.Y() );
376 Point
PictReader::ReadDeltaV(Point aBase
)
380 pPict
->ReadChar( reinterpret_cast<char&>(ndv
) );
382 return Point( aBase
.X(), aBase
.Y() + static_cast<long>(ndv
) );
385 Point
PictReader::ReadUnsignedDeltaH(Point aBase
)
389 pPict
->ReadUChar( ndh
);
391 return Point( aBase
.X() + static_cast<long>(ndh
), aBase
.Y() );
394 Point
PictReader::ReadUnsignedDeltaV(Point aBase
)
398 pPict
->ReadUChar( ndv
);
400 return Point( aBase
.X(), aBase
.Y() + static_cast<long>(ndv
) );
403 Size
PictReader::ReadSize()
407 pPict
->ReadInt16( ny
).ReadInt16( nx
);
409 return Size( static_cast<long>(nx
), static_cast<long>(ny
) );
412 Color
PictReader::ReadColor()
417 pPict
->ReadUInt32( nCol
);
420 case 33: aCol
=COL_BLACK
; break;
421 case 30: aCol
=COL_WHITE
; break;
422 case 205: aCol
=COL_LIGHTRED
; break;
423 case 341: aCol
=COL_LIGHTGREEN
; break;
424 case 409: aCol
=COL_LIGHTBLUE
; break;
425 case 273: aCol
=COL_LIGHTCYAN
; break;
426 case 137: aCol
=COL_LIGHTMAGENTA
; break;
427 case 69: aCol
=COL_YELLOW
; break;
428 default: aCol
=COL_LIGHTGRAY
;
434 Color
PictReader::ReadRGBColor()
436 sal_uInt16 nR
, nG
, nB
;
438 pPict
->ReadUInt16( nR
).ReadUInt16( nG
).ReadUInt16( nB
);
439 return Color( static_cast<sal_uInt8
>( nR
>> 8 ), static_cast<sal_uInt8
>( nG
>> 8 ), static_cast<sal_uInt8
>( nB
>> 8 ) );
443 void PictReader::ReadRectangle(tools::Rectangle
& rRect
)
445 Point aTopLeft
, aBottomRight
;
447 aTopLeft
=ReadPoint();
448 aBottomRight
=ReadPoint();
449 rRect
=tools::Rectangle(aTopLeft
,aBottomRight
);
451 SAL_INFO("filter.pict", "ReadRectangle: " << rRect
);
454 sal_uLong
PictReader::ReadPolygon(tools::Polygon
& rPoly
)
457 pPict
->ReadUInt16(nSize
);
459 sal_uLong nDataSize
= static_cast<sal_uLong
>(nSize
);
461 const size_t nMaxPossiblePoints
= pPict
->remainingSize() / 2 * sizeof(sal_uInt16
);
462 if (nSize
> nMaxPossiblePoints
)
464 SAL_WARN("filter.pict", "pict record claims to have: " << nSize
<< " points, but only " << nMaxPossiblePoints
<< " possible, clamping");
465 nSize
= nMaxPossiblePoints
;
467 rPoly
.SetSize(nSize
);
468 for (sal_uInt16 i
= 0; i
< nSize
; ++i
)
470 rPoly
.SetPoint(ReadPoint(), i
);
480 sal_uLong
PictReader::ReadPixPattern(PictReader::Pattern
&pattern
)
482 // Don't know if this is correct because no picture which contains PixPatterns found.
483 // Here again the attempt to calculate the size of the date to create simple StarView-Styles
484 // from them. Luckily a PixPattern always contains a normal pattern.
491 pPict
->ReadUInt16( nPatType
);
493 pattern
.read(*pPict
);
494 nDataSize
=ReadPixMapEtc(aBMP
,false,true,nullptr,nullptr,false,false);
495 // CHANGEME: use average pixmap colors to update the pattern, ...
496 if (nDataSize
!=0xffffffff) nDataSize
+=10;
498 else if (nPatType
==2) {
499 pattern
.read(*pPict
);
501 sal_uInt16 nR
, nG
, nB
;
502 pPict
->ReadUInt16( nR
).ReadUInt16( nG
).ReadUInt16( nB
);
503 Color
col(static_cast<sal_uInt8
>( nR
>> 8 ), static_cast<sal_uInt8
>( nG
>> 8 ), static_cast<sal_uInt8
>( nB
>> 8 ) );
504 pattern
.setColor(col
);
507 else nDataSize
=0xffffffff;
512 sal_uLong
PictReader::ReadAndDrawRect(PictDrawingMethod eMethod
)
514 ReadRectangle(aLastRect
);
515 ReadAndDrawSameRect(eMethod
);
519 sal_uLong
PictReader::ReadAndDrawSameRect(PictDrawingMethod eMethod
)
521 if (IsInvisible(eMethod
)) return 0;
522 DrawingMethod(eMethod
);
523 PictReaderShape::drawRectangle( pVirDev
, eMethod
== PictDrawingMethod::FRAME
, aLastRect
, nActPenSize
);
527 sal_uLong
PictReader::ReadAndDrawRoundRect(PictDrawingMethod eMethod
)
529 ReadRectangle(aLastRoundRect
);
530 ReadAndDrawSameRoundRect(eMethod
);
534 sal_uLong
PictReader::ReadAndDrawSameRoundRect(PictDrawingMethod eMethod
)
536 if (IsInvisible(eMethod
)) return 0;
537 DrawingMethod(eMethod
);
538 PictReaderShape::drawRoundRectangle( pVirDev
, eMethod
== PictDrawingMethod::FRAME
, aLastRoundRect
, aActOvalSize
, nActPenSize
);
542 sal_uLong
PictReader::ReadAndDrawOval(PictDrawingMethod eMethod
)
544 ReadRectangle(aLastOval
);
545 ReadAndDrawSameOval(eMethod
);
549 sal_uLong
PictReader::ReadAndDrawSameOval(PictDrawingMethod eMethod
)
551 if (IsInvisible(eMethod
)) return 0;
552 DrawingMethod(eMethod
);
553 PictReaderShape::drawEllipse( pVirDev
, eMethod
== PictDrawingMethod::FRAME
, aLastOval
, nActPenSize
);
557 sal_uLong
PictReader::ReadAndDrawPolygon(PictDrawingMethod eMethod
)
560 nDataSize
=ReadPolygon(aLastPolygon
);
561 ReadAndDrawSamePolygon(eMethod
);
565 sal_uLong
PictReader::ReadAndDrawSamePolygon(PictDrawingMethod eMethod
)
567 if (IsInvisible(eMethod
)) return 0;
568 DrawingMethod(eMethod
);
569 PictReaderShape::drawPolygon( pVirDev
, eMethod
== PictDrawingMethod::FRAME
, aLastPolygon
, nActPenSize
);
574 sal_uLong
PictReader::ReadAndDrawArc(PictDrawingMethod eMethod
)
576 ReadRectangle(aLastArcRect
);
577 ReadAndDrawSameArc(eMethod
);
581 sal_uLong
PictReader::ReadAndDrawSameArc(PictDrawingMethod eMethod
)
583 short nstartAngle
, narcAngle
;
586 pPict
->ReadInt16( nstartAngle
).ReadInt16( narcAngle
);
587 if (IsInvisible(eMethod
)) return 4;
588 DrawingMethod(eMethod
);
591 nstartAngle
= nstartAngle
+ narcAngle
;
592 narcAngle
=-narcAngle
;
594 const double pi
= 2 * acos(0.0);
595 fAng1
= static_cast<double>(nstartAngle
) * pi
/ 180.0;
596 fAng2
= static_cast<double>(nstartAngle
+ narcAngle
) * pi
/ 180.0;
597 PictReaderShape::drawArc( pVirDev
, eMethod
== PictDrawingMethod::FRAME
, aLastArcRect
, fAng1
, fAng2
, nActPenSize
);
601 sal_uLong
PictReader::ReadAndDrawRgn(PictDrawingMethod eMethod
)
605 pPict
->ReadUInt16( nSize
);
608 // a region data is a mask and is probably coded as
609 // - the first 8 bytes: bdbox ( which can be read by ReadRectangle )
610 // - then a list of line modifiers: y_i, a_0, b_0, a_1, b_1, ..., a_{n_i}, b_{n_i}, 0x7fff
612 // where y_i is the increasing sequences of line coordinates
613 // and on each line: a0 < b0 < a1 < b1 < ... < a_{n_i} < b_{n_i}
615 // it can be probably decoded as :
616 // M=an empty mask: ie. (0, 0, ... ) with (left_box-right_box+1) zeroes
617 // then for each line (y_i):
618 // - takes M and inverts all values in [a_0,b_0-1], in [a_1,b_1-1] ...
619 // - sets M = new y_i line mask
620 ReadAndDrawSameRgn(eMethod
);
621 return static_cast<sal_uLong
>(nSize
);
624 sal_uLong
PictReader::ReadAndDrawSameRgn(PictDrawingMethod eMethod
)
626 if (IsInvisible(eMethod
)) return 0;
627 DrawingMethod(eMethod
);
628 // DISPLAY: ...???...
632 void PictReader::DrawingMethod(PictDrawingMethod eMethod
)
634 if( eActMethod
==eMethod
) return;
636 case PictDrawingMethod::FRAME
:
637 if (eActPenPattern
.isDefault())
638 SetLineColor( aActForeColor
);
640 SetLineColor(eActPenPattern
.getColor(aActBackColor
, aActForeColor
));
641 SetFillColor( COL_TRANSPARENT
);
642 pVirDev
->SetRasterOp(eActROP
);
644 case PictDrawingMethod::PAINT
:
645 SetLineColor( COL_TRANSPARENT
);
646 if (eActPenPattern
.isDefault())
647 SetFillColor( aActForeColor
);
649 SetFillColor(eActPenPattern
.getColor(aActBackColor
, aActForeColor
));
650 pVirDev
->SetRasterOp(eActROP
);
652 case PictDrawingMethod::ERASE
:
653 SetLineColor( COL_TRANSPARENT
);
654 if (eActBackPattern
.isDefault())
655 SetFillColor( aActBackColor
);// Osnola: previously aActForeColor
657 SetFillColor(eActBackPattern
.getColor(COL_BLACK
, aActBackColor
));
658 pVirDev
->SetRasterOp(RasterOp::OverPaint
);
660 case PictDrawingMethod::INVERT
: // checkme
661 SetLineColor( COL_TRANSPARENT
);
662 SetFillColor( COL_BLACK
);
663 pVirDev
->SetRasterOp(RasterOp::Invert
);
665 case PictDrawingMethod::FILL
:
666 SetLineColor( COL_TRANSPARENT
);
667 if (eActFillPattern
.isDefault())
668 SetFillColor( aActForeColor
);
670 SetFillColor(eActFillPattern
.getColor(aActBackColor
, aActForeColor
));
671 pVirDev
->SetRasterOp(RasterOp::OverPaint
);
673 case PictDrawingMethod::TEXT
:
674 aActFont
.SetColor(aActForeColor
);
675 aActFont
.SetFillColor(aActBackColor
);
676 aActFont
.SetTransparent(true);
677 pVirDev
->SetFont(aActFont
);
678 pVirDev
->SetRasterOp(RasterOp::OverPaint
);
681 break; // -Wall undefined not handled...
686 sal_uLong
PictReader::ReadAndDrawText()
689 sal_uInt32 nLen
, nDataLen
;
692 pPict
->ReadChar( nByteLen
); nLen
=static_cast<sal_uLong
>(nByteLen
)&0x000000ff;
694 pPict
->ReadBytes(&sText
, nLen
);
696 if (IsInvisible( PictDrawingMethod::TEXT
)) return nDataLen
;
697 DrawingMethod( PictDrawingMethod::TEXT
);
699 // remove annoying control characters:
700 while ( nLen
> 0 && static_cast<unsigned char>(sText
[ nLen
- 1 ]) < 32 )
703 OUString
aString( sText
, strlen(sText
), aActFont
.GetCharSet());
704 pVirDev
->DrawText( Point( aTextPosition
.X(), aTextPosition
.Y() ), aString
);
708 sal_uLong
PictReader::ReadPixMapEtc( BitmapEx
&rBitmap
, bool bBaseAddr
, bool bColorTable
, tools::Rectangle
* pSrcRect
,
709 tools::Rectangle
* pDestRect
, bool bMode
, bool bMaskRgn
)
711 std::unique_ptr
<vcl::bitmap::RawBitmap
> pBitmap
;
712 sal_uInt16
nPackType(0), nPixelSize(0), nCmpCount(0), nCmpSize(0);
713 sal_uInt8
nDat(0), nRed(0), nGreen(0), nBlue(0);
715 // The calculation of nDataSize is considering the size of the whole data.
716 size_t nDataSize
= 0;
718 // conditionally skip BaseAddr
725 // Read PixMap or Bitmap structure;
726 sal_uInt16
nRowBytes(0), nBndX(0), nBndY(0), nWidth(0), nHeight(0);
727 pPict
->ReadUInt16(nRowBytes
).ReadUInt16(nBndY
).ReadUInt16(nBndX
).ReadUInt16(nHeight
).ReadUInt16(nWidth
);
730 nHeight
= nHeight
- nBndY
;
735 nWidth
= nWidth
- nBndX
;
738 sal_uInt16 nDstBitCount
= 1;
740 std::vector
<Color
> aPalette
;
741 const bool bNotMonoChrome
= (nRowBytes
& 0x8000) != 0;
746 sal_uInt32 nPackSize
;
747 sal_uInt16 nPixelType
;
748 sal_uInt32 nPlaneBytes
;
749 sal_uInt32 nHRes
, nVRes
;
750 pPict
->ReadUInt16( nVersion
).ReadUInt16( nPackType
).ReadUInt32( nPackSize
).ReadUInt32( nHRes
).ReadUInt32( nVRes
).ReadUInt16( nPixelType
).ReadUInt16( nPixelSize
).ReadUInt16( nCmpCount
).ReadUInt16( nCmpSize
).ReadUInt32( nPlaneBytes
);
755 nDstBitCount
= nPixelSize
;
756 if ( nDstBitCount
> 8 )
758 else if ( nDstBitCount
== 2 )
764 sal_uInt16
nColTabSize(0);
765 pPict
->ReadUInt16(nColTabSize
);
767 if (nColTabSize
> 255)
772 aPalette
.resize(nColTabSize
);
774 for (size_t i
= 0; i
< nColTabSize
; ++i
)
778 pPict
->ReadUChar( nRed
).ReadUChar( nDummy
).ReadUChar( nGreen
).ReadUChar( nDummy
).ReadUChar( nBlue
).ReadUChar( nDummy
);
779 aPalette
[i
] = Color(nRed
, nGreen
, nBlue
);
782 nDataSize
+= 8 + nColTabSize
* 8;
788 nPixelSize
= nCmpCount
= nCmpSize
= 1;
791 aPalette
[0] = Color(0xff, 0xff, 0xff);
792 aPalette
[1] = Color(0, 0, 0);
795 // conditionally read source rectangle:
796 if ( pSrcRect
!= nullptr)
798 sal_uInt16 nTop
, nLeft
, nBottom
, nRight
;
799 pPict
->ReadUInt16( nTop
).ReadUInt16( nLeft
).ReadUInt16( nBottom
).ReadUInt16( nRight
);
800 *pSrcRect
= tools::Rectangle( static_cast<sal_uLong
>(nLeft
), static_cast<sal_uLong
>(nTop
), static_cast<sal_uLong
>(nRight
), static_cast<sal_uLong
>(nBottom
) );
804 // conditionally read destination rectangle:
805 if ( pDestRect
!= nullptr )
810 *pDestRect
= tools::Rectangle( aTL
, aBR
);
814 // conditionally read mode (or skip it):
821 // conditionally read region (or skip it):
825 pPict
->ReadUInt16( nSize
);
826 pPict
->SeekRel( nSize
- 2 );
827 nDataSize
+= static_cast<sal_uLong
>(nSize
);
830 // read and write Bitmap bits:
831 if ( nPixelSize
== 1 || nPixelSize
== 2 || nPixelSize
== 4 || nPixelSize
== 8 )
833 sal_uInt16 nSrcBPL
, nDestBPL
;
836 if ( nPixelSize
== 1 ) nSrcBPL
= ( nWidth
+ 7 ) >> 3;
837 else if ( nPixelSize
== 2 ) nSrcBPL
= ( nWidth
+ 3 ) >> 2;
838 else if ( nPixelSize
== 4 ) nSrcBPL
= ( nWidth
+ 1 ) >> 1;
839 else nSrcBPL
= nWidth
;
840 nDestBPL
= ( nSrcBPL
+ 3 ) & 0xfffc;
841 if (!nRowBytes
|| nRowBytes
< nSrcBPL
|| nRowBytes
> nDestBPL
)
844 if (nRowBytes
< 8 || nPackType
== 1)
846 if (nHeight
> pPict
->remainingSize() / (sizeof(sal_uInt8
) * nRowBytes
))
851 size_t nByteCountSize
= nRowBytes
> 250 ? sizeof(sal_uInt16
) : sizeof(sal_uInt8
);
852 if (nHeight
> pPict
->remainingSize() / nByteCountSize
)
856 pBitmap
.reset(new vcl::bitmap::RawBitmap( Size(nWidth
, nHeight
), 24 ));
858 for (sal_uInt16 ny
= 0; ny
< nHeight
; ++ny
)
861 if ( nRowBytes
< 8 || nPackType
== 1 )
863 for (size_t i
= 0; i
< nRowBytes
; ++i
)
865 pPict
->ReadUChar( nDat
);
867 SetByte(nx
, ny
, *pBitmap
, nPixelSize
, nDat
, nWidth
, aPalette
);
869 nDataSize
+= nRowBytes
;
873 sal_uInt16
nByteCount(0);
874 if ( nRowBytes
> 250 )
876 pPict
->ReadUInt16( nByteCount
);
877 nDataSize
+= 2 + static_cast<sal_uLong
>(nByteCount
);
881 sal_uInt8
nByteCountAsByte(0);
882 pPict
->ReadUChar( nByteCountAsByte
);
883 nByteCount
= static_cast<sal_uInt16
>(nByteCountAsByte
) & 0x00ff;
884 nDataSize
+= 1 + static_cast<sal_uLong
>(nByteCount
);
887 while (pPict
->good() && nByteCount
)
889 sal_uInt8
nFlagCounterByte(0);
890 pPict
->ReadUChar(nFlagCounterByte
);
891 if ( ( nFlagCounterByte
& 0x80 ) == 0 )
893 nCount
= static_cast<sal_uInt16
>(nFlagCounterByte
) + 1;
894 for (size_t i
= 0; i
< nCount
; ++i
)
896 pPict
->ReadUChar( nDat
);
898 SetByte(nx
, ny
, *pBitmap
, nPixelSize
, nDat
, nWidth
, aPalette
);
900 nByteCount
-= 1 + nCount
;
904 nCount
= static_cast<sal_uInt16
>( 1 - sal_Int16( static_cast<sal_uInt16
>(nFlagCounterByte
) | 0xff00 ) );
905 pPict
->ReadUChar( nDat
);
906 for (size_t i
= 0; i
< nCount
; ++i
)
909 SetByte(nx
, ny
, *pBitmap
, nPixelSize
, nDat
, nWidth
, aPalette
);
917 else if ( nPixelSize
== 16 )
919 sal_uInt8 nByteCountAsByte
, nFlagCounterByte
;
920 sal_uInt16 nByteCount
, nCount
, nD
;
921 sal_uLong nSrcBitsPos
;
923 if (nWidth
> nRowBytes
/ 2)
926 if (nRowBytes
< 8 || nPackType
== 1)
928 if (nHeight
> pPict
->remainingSize() / (sizeof(sal_uInt8
) * nRowBytes
))
933 size_t nByteCountSize
= nRowBytes
> 250 ? sizeof(sal_uInt16
) : sizeof(sal_uInt8
);
934 if (nHeight
> pPict
->remainingSize() / nByteCountSize
)
938 pBitmap
.reset(new vcl::bitmap::RawBitmap( Size(nWidth
, nHeight
), 24 ));
940 for (sal_uInt16 ny
= 0; ny
< nHeight
; ++ny
)
943 if ( nRowBytes
< 8 || nPackType
== 1 )
945 for (size_t i
= 0; i
< nWidth
; ++i
)
947 pPict
->ReadUInt16( nD
);
948 nRed
= static_cast<sal_uInt8
>( nD
>> 7 );
949 nGreen
= static_cast<sal_uInt8
>( nD
>> 2 );
950 nBlue
= static_cast<sal_uInt8
>( nD
<< 3 );
951 pBitmap
->SetPixel(ny
, nx
++, Color(nRed
, nGreen
, nBlue
));
953 nDataSize
+= static_cast<sal_uLong
>(nWidth
) * 2;
957 nSrcBitsPos
= pPict
->Tell();
958 if ( nRowBytes
> 250 )
960 pPict
->ReadUInt16( nByteCount
);
965 pPict
->ReadUChar( nByteCountAsByte
);
966 nByteCount
= static_cast<sal_uInt16
>(nByteCountAsByte
) & 0x00ff;
969 while ( nx
!= nWidth
)
971 pPict
->ReadUChar( nFlagCounterByte
);
972 if ( (nFlagCounterByte
& 0x80) == 0)
974 nCount
=static_cast<sal_uInt16
>(nFlagCounterByte
)+1;
975 if ( nCount
+ nx
> nWidth
)
976 nCount
= nWidth
- nx
;
977 if (pPict
->remainingSize() < sizeof(sal_uInt16
) * nCount
)
979 /* SJ: the RLE decoding seems not to be correct here,
980 I don't want to change this until I have a bugdoc for
981 this case. Have a look at 32bit, there I changed the
982 encoding, so that it is used a straight forward array
984 for (size_t i
= 0; i
< nCount
; ++i
)
986 pPict
->ReadUInt16( nD
);
987 nRed
= static_cast<sal_uInt8
>( nD
>> 7 );
988 nGreen
= static_cast<sal_uInt8
>( nD
>> 2 );
989 nBlue
= static_cast<sal_uInt8
>( nD
<< 3 );
990 pBitmap
->SetPixel(ny
, nx
++, Color(nRed
, nGreen
, nBlue
));
995 if (pPict
->remainingSize() < sizeof(sal_uInt16
))
997 nCount
=(1-sal_Int16(static_cast<sal_uInt16
>(nFlagCounterByte
)|0xff00));
998 if ( nCount
+ nx
> nWidth
)
999 nCount
= nWidth
- nx
;
1000 pPict
->ReadUInt16( nD
);
1001 nRed
= static_cast<sal_uInt8
>( nD
>> 7 );
1002 nGreen
= static_cast<sal_uInt8
>( nD
>> 2 );
1003 nBlue
= static_cast<sal_uInt8
>( nD
<< 3 );
1004 for (size_t i
= 0; i
< nCount
; ++i
)
1006 pBitmap
->SetPixel(ny
, nx
++, Color(nRed
, nGreen
, nBlue
));
1010 nDataSize
+=static_cast<sal_uLong
>(nByteCount
);
1011 pPict
->Seek(nSrcBitsPos
+static_cast<sal_uLong
>(nByteCount
));
1015 else if ( nPixelSize
== 32 )
1017 sal_uInt16 nByteCount
;
1019 sal_uLong nSrcBitsPos
;
1020 if ( nRowBytes
!= 4*nWidth
)
1023 if ( nRowBytes
< 8 || nPackType
== 1 )
1025 const size_t nMaxPixels
= pPict
->remainingSize() / 4;
1026 const size_t nMaxRows
= nMaxPixels
/ nWidth
;
1027 if (nHeight
> nMaxRows
)
1029 const size_t nMaxCols
= nMaxPixels
/ nHeight
;
1030 if (nWidth
> nMaxCols
)
1033 pBitmap
.reset(new vcl::bitmap::RawBitmap( Size(nWidth
, nHeight
), 24 ));
1035 for (sal_uInt16 ny
= 0; ny
< nHeight
; ++ny
)
1037 for (sal_uInt16 nx
= 0; nx
< nWidth
; ++nx
)
1040 pPict
->ReadUChar( nDummy
).ReadUChar( nRed
).ReadUChar( nGreen
).ReadUChar( nBlue
);
1041 pBitmap
->SetPixel(ny
, nx
, Color(nRed
, nGreen
, nBlue
));
1043 nDataSize
+= static_cast<sal_uLong
>(nWidth
) * 4;
1046 else if ( nPackType
== 2 )
1048 const size_t nMaxPixels
= pPict
->remainingSize() / 3;
1049 const size_t nMaxRows
= nMaxPixels
/ nWidth
;
1050 if (nHeight
> nMaxRows
)
1052 const size_t nMaxCols
= nMaxPixels
/ nHeight
;
1053 if (nWidth
> nMaxCols
)
1056 pBitmap
.reset(new vcl::bitmap::RawBitmap( Size(nWidth
, nHeight
), 24 ));
1058 for (sal_uInt16 ny
= 0; ny
< nHeight
; ++ny
)
1060 for (sal_uInt16 nx
= 0; nx
< nWidth
; ++nx
)
1062 pPict
->ReadUChar( nRed
).ReadUChar( nGreen
).ReadUChar( nBlue
);
1063 pBitmap
->SetPixel(ny
, nx
, Color(nRed
, nGreen
, nBlue
));
1065 nDataSize
+= static_cast<sal_uLong
>(nWidth
) * 3;
1070 sal_uInt8 nByteCountAsByte
;
1071 sal_uInt8 nFlagCounterByte
;
1072 if ( ( nCmpCount
== 3 ) || ( nCmpCount
== 4 ) )
1074 size_t nByteCountSize
= nRowBytes
> 250 ? sizeof(sal_uInt16
) : sizeof(sal_uInt8
);
1075 if (nHeight
> pPict
->remainingSize() / nByteCountSize
)
1078 pBitmap
.reset(new vcl::bitmap::RawBitmap( Size(nWidth
, nHeight
), 24 ));
1080 size_t nByteWidth
= static_cast<size_t>(nWidth
) * nCmpCount
;
1081 std::vector
<sal_uInt8
> aScanline(nByteWidth
);
1082 for (sal_uInt16 ny
= 0; ny
< nHeight
; ++ny
)
1084 nSrcBitsPos
= pPict
->Tell();
1085 if ( nRowBytes
> 250 )
1087 pPict
->ReadUInt16( nByteCount
);
1092 pPict
->ReadUChar( nByteCountAsByte
);
1093 nByteCount
= nByteCountAsByte
;
1097 while (i
< aScanline
.size())
1099 pPict
->ReadUChar( nFlagCounterByte
);
1100 if ( ( nFlagCounterByte
& 0x80 ) == 0)
1102 nCount
= static_cast<sal_uInt16
>(nFlagCounterByte
) + 1;
1103 if ((i
+ nCount
) > aScanline
.size())
1104 nCount
= aScanline
.size() - i
;
1105 if (pPict
->remainingSize() < nCount
)
1109 pPict
->ReadUChar( nDat
);
1110 aScanline
[ i
++ ] = nDat
;
1115 if (pPict
->remainingSize() < 1)
1117 nCount
= ( 1 - sal_Int16( static_cast<sal_uInt16
>(nFlagCounterByte
) | 0xff00 ) );
1118 if (( i
+ nCount
) > aScanline
.size())
1119 nCount
= aScanline
.size() - i
;
1120 pPict
->ReadUChar( nDat
);
1122 aScanline
[ i
++ ] = nDat
;
1125 sal_uInt8
* pTmp
= aScanline
.data();
1126 if ( nCmpCount
== 4 )
1128 for (sal_uInt16 nx
= 0; nx
< nWidth
; pTmp
++)
1129 pBitmap
->SetPixel(ny
, nx
++, Color(*pTmp
, pTmp
[ nWidth
], pTmp
[ 2 * nWidth
]));
1130 nDataSize
+= static_cast<sal_uLong
>(nByteCount
);
1131 pPict
->Seek( nSrcBitsPos
+ static_cast<sal_uLong
>(nByteCount
) );
1138 rBitmap
= vcl::bitmap::CreateFromData(std::move(*pBitmap
));
1142 void PictReader::ReadHeader()
1147 // previous code considers pPict->Tell() as the normal starting position,
1148 // can we have nStartPos != 0 ?
1149 sal_uLong nStartPos
= pPict
->Tell();
1151 // a picture file begins by 512 bytes (reserved to the application) followed by the picture data
1152 // while clipboard, pictures stored in a document often contain only the picture data.
1155 // - some Pict v.1 use 0x00 0x11 0x01 ( instead of 0x11 0x01) to store the version op
1156 // (we consider here this as another standard for Pict. v.1 )
1157 // - some files seem to contain extra garbage data at the beginning
1158 // - some picture data seem to contain extra NOP opcode(0x00) between the bounding box and the version opcode
1160 // This code looks hard to find a picture header, ie. it looks at positions
1161 // - nStartPos+0, nStartPos+512 with potential extra NOP codes between bdbox and version (at most 9 extra NOP)
1162 // - 512..1024 with more strict bdbox checking and no extra NOP codes
1165 // - if the header can begin at nStartPos+0 and at nStartPos+512, we try to choose the more
1166 // <<probable>> ( using the variable confidence)
1167 // - svtools/source/filter.vcl/filter/{filter.cxx,filter2.cxx} only check for standard Pict,
1168 // this may cause future problems
1171 int confidence
[2] = { 0, 0};
1172 for ( st
= 0; st
< 3 + 513; st
++ )
1174 int actualConfid
= 20; // the actual confidence
1175 pPict
->ResetError();
1176 if (st
< 2) nOffset
= nStartPos
+st
*512;
1178 // choose nStartPos+0 or nStartPos+512 even if there are a little dubious
1179 int actPos
= -1, actConf
=0;
1180 if (confidence
[0] > 0) { actPos
= 0; actConf
= confidence
[0]; }
1181 if (confidence
[1] > 0 && confidence
[1] >= actConf
) actPos
= 1;
1182 if (actPos
< 0) continue;
1183 nOffset
= nStartPos
+actPos
*512;
1186 nOffset
= 509+st
; // illogical : more logical will be nStartPos+509+st or to consider that nStartPos=0
1187 // a small test to check if versionOp code exists after the bdbox ( with no extra NOP codes)
1188 pPict
->Seek(nOffset
+10);
1189 pPict
->ReadBytes(sBuf
, 2);
1190 if (!pPict
->good()) break;
1191 if (sBuf
[0] == 0x11 || (sBuf
[0] == 0x00 && sBuf
[1] == 0x11)) ; // maybe ok
1194 pPict
->Seek(nOffset
);
1196 // 2 bytes to store size ( version 1 ) ignored
1197 pPict
->SeekRel( 2 );
1198 pPict
->ReadInt16( y1
).ReadInt16( x1
).ReadInt16( y2
).ReadInt16( x2
); // frame rectangle of the picture
1199 if (x1
> x2
|| y1
> y2
) continue; // bad bdbox
1200 if (x1
< -2048 || x2
> 2048 || y1
< -2048 || y2
> 2048 || // origin|dest is very small|large
1201 (x1
== x2
&& y1
== y2
) ) // 1 pixel pict is dubious
1203 else if (x2
< x1
+8 || y2
< y1
+8) // a little dubious
1205 if (st
>= 3 && actualConfid
!= 20) continue;
1206 aBoundingRect
=tools::Rectangle( x1
,y1
, x2
, y2
);
1208 if (!pPict
->good()) continue;
1210 pPict
->ReadBytes(sBuf
, 2);
1212 if ( sBuf
[ 0 ] == 0x11 && sBuf
[ 1 ] == 0x01 ) {
1213 // pict v1 must be rare and we do only few tests
1214 if (st
< 2) { confidence
[st
] = --actualConfid
; continue; }
1215 IsVersion2
= false; return;
1217 if (sBuf
[0] != 0x00) continue; // unrecoverable error
1223 pPict
->ReadBytes(sBuf
, 2);
1225 while ( sBuf
[0] == 0x00 && numZero
< 10);
1226 actualConfid
-= (numZero
-1); // extra nop are dubious
1227 if (!pPict
->good()) continue;
1228 if (sBuf
[0] != 0x11) continue; // not a version opcode
1229 // abnormal version 1 file
1230 if (sBuf
[1] == 0x01 ) {
1231 // pict v1 must be rare and we do only few tests
1232 if (st
< 2) { confidence
[st
] = --actualConfid
; continue; }
1233 IsVersion2
= false; return;
1235 if (sBuf
[1] != 0x02 ) continue; // not a version 2 file
1238 short nExtVer
, nReserved
;
1239 // 3 Bytes ignored : end of version arg 0x02FF (ie: 0xFF), HeaderOp : 0x0C00
1240 pPict
->SeekRel( 3 );
1241 pPict
->ReadInt16( nExtVer
).ReadInt16( nReserved
);
1242 if (!pPict
->good()) continue;
1244 if ( nExtVer
== -2 ) // extended version 2 picture
1246 sal_Int32 nHResFixed
, nVResFixed
;
1247 pPict
->ReadInt32( nHResFixed
).ReadInt32( nVResFixed
);
1248 pPict
->ReadInt16( y1
).ReadInt16( x1
).ReadInt16( y2
).ReadInt16( x2
); // reading the optimal bounding rect
1249 if (x1
> x2
|| y1
> y2
) continue; // bad bdbox
1250 if (st
< 2 && actualConfid
!= 20) { confidence
[st
] = actualConfid
; continue; }
1252 double fHRes
= nHResFixed
;
1254 double fVRes
= nVResFixed
;
1258 aBoundingRect
=tools::Rectangle( x1
,y1
, x2
, y2
);
1259 pPict
->SeekRel( 4 ); // 4 bytes reserved
1262 else if (nExtVer
== -1 ) { // basic version 2 picture
1263 if (st
< 2 && actualConfid
!= 20) { confidence
[st
] = actualConfid
; continue; }
1264 pPict
->SeekRel( 16); // bdbox(4 fixed number)
1265 pPict
->SeekRel(4); // 4 bytes reserved
1269 pPict
->SetError(SVSTREAM_FILEFORMAT_ERROR
);
1272 #if OSL_DEBUG_LEVEL > 0
1273 static const char* operationName(sal_uInt16 nOpcode
)
1275 // add here whatever makes the debugging easier for you, otherwise you'll
1276 // see only the operation's opcode
1279 case 0x0001: return "Clip";
1280 case 0x0003: return "TxFont";
1281 case 0x0004: return "TxFace";
1282 case 0x0008: return "PnMode";
1283 case 0x0009: return "PnPat";
1284 case 0x000d: return "TxSize";
1285 case 0x001a: return "RGBFgCol";
1286 case 0x001d: return "HiliteColor";
1287 case 0x0020: return "Line";
1288 case 0x0022: return "ShortLine";
1289 case 0x0028: return "LongText";
1290 case 0x0029: return "DHText";
1291 case 0x002a: return "DVText";
1292 case 0x002c: return "fontName";
1293 case 0x002e: return "glyphState";
1294 case 0x0031: return "paintRect";
1295 case 0x0038: return "frameSameRect";
1296 case 0x0070: return "framePoly";
1297 case 0x0071: return "paintPoly";
1298 case 0x00a1: return "LongComment";
1299 default: return "?";
1304 sal_uLong
PictReader::ReadData(sal_uInt16 nOpcode
)
1308 sal_uLong nDataSize
=0;
1309 PictDrawingMethod shapeDMethod
= PictDrawingMethod::UNDEFINED
;
1310 switch (nOpcode
& 7) {
1311 case 0: shapeDMethod
= PictDrawingMethod::FRAME
; break;
1312 case 1: shapeDMethod
= PictDrawingMethod::PAINT
; break;
1313 case 2: shapeDMethod
= PictDrawingMethod::ERASE
; break;
1314 case 3: shapeDMethod
= PictDrawingMethod::INVERT
; break;
1315 case 4: shapeDMethod
= PictDrawingMethod::FILL
; break;
1319 #if OSL_DEBUG_LEVEL > 0
1320 SAL_INFO("filter.pict", "Operation: 0x" << OUString::number(nOpcode
, 16) << " [" << operationName(nOpcode
) << "]");
1329 case 0x0001: { // Clip
1330 tools::Rectangle aRect
;
1331 pPict
->ReadUInt16( nUSHORT
);
1333 ReadRectangle(aRect
);
1334 // checkme: do we really want to extend the rectangle here ?
1335 // I do that because the clipping is often used to clean a region,
1336 // before drawing some text and also to draw this text.
1337 // So using a too small region can lead to clip the end of the text ;
1338 // but this can be discussable...
1339 aRect
.setWidth(aRect
.getWidth()+1);
1340 aRect
.setHeight(aRect
.getHeight()+1);
1341 pVirDev
->SetClipRegion( vcl::Region( aRect
) );
1344 case 0x0002: // BkPat
1345 nDataSize
= eActBackPattern
.read(*pPict
);
1346 eActMethod
= PictDrawingMethod::UNDEFINED
;
1349 case 0x0003: // TxFont
1350 pPict
->ReadUInt16( nUSHORT
);
1351 if (nUSHORT
<= 1) aActFont
.SetFamily(FAMILY_SWISS
);
1352 else if (nUSHORT
<= 12) aActFont
.SetFamily(FAMILY_DECORATIVE
);
1353 else if (nUSHORT
<= 20) aActFont
.SetFamily(FAMILY_ROMAN
);
1354 else if (nUSHORT
== 21) aActFont
.SetFamily(FAMILY_SWISS
);
1355 else if (nUSHORT
== 22) aActFont
.SetFamily(FAMILY_MODERN
);
1356 else if (nUSHORT
<= 1023) aActFont
.SetFamily(FAMILY_SWISS
);
1357 else aActFont
.SetFamily(FAMILY_ROMAN
);
1358 aActFont
.SetCharSet(GetTextEncoding(nUSHORT
));
1359 eActMethod
= PictDrawingMethod::UNDEFINED
;
1363 case 0x0004: { // TxFace
1365 pPict
->ReadChar( nFace
);
1366 if ( (nFace
& 0x01)!=0 ) aActFont
.SetWeight(WEIGHT_BOLD
);
1367 else aActFont
.SetWeight(WEIGHT_NORMAL
);
1368 if ( (nFace
& 0x02)!=0 ) aActFont
.SetItalic(ITALIC_NORMAL
);
1369 else aActFont
.SetItalic(ITALIC_NONE
);
1370 if ( (nFace
& 0x04)!=0 ) aActFont
.SetUnderline(LINESTYLE_SINGLE
);
1371 else aActFont
.SetUnderline(LINESTYLE_NONE
);
1372 if ( (nFace
& 0x08)!=0 ) aActFont
.SetOutline(true);
1373 else aActFont
.SetOutline(false);
1374 if ( (nFace
& 0x10)!=0 ) aActFont
.SetShadow(true);
1375 else aActFont
.SetShadow(false);
1376 eActMethod
= PictDrawingMethod::UNDEFINED
;
1380 case 0x0005: // TxMode
1384 case 0x0006: // SpExtra
1388 case 0x0007: { // PnSize
1389 nActPenSize
=ReadSize();
1390 eActMethod
= PictDrawingMethod::UNDEFINED
;
1394 case 0x0008: // PnMode
1395 pPict
->ReadUInt16( nUSHORT
);
1396 // internal code for postscript command (Quickdraw Reference Drawing B-30,B-34)
1397 if (nUSHORT
==23) eActROP
= RasterOp::N1
;
1399 switch (nUSHORT
& 0x0007) {
1400 case 0: eActROP
=RasterOp::OverPaint
; break; // Copy
1401 case 1: eActROP
=RasterOp::OverPaint
; break; // Or
1402 case 2: eActROP
=RasterOp::Xor
; break; // Xor
1403 case 3: eActROP
=RasterOp::OverPaint
; break; // Bic
1404 case 4: eActROP
=RasterOp::Invert
; break; // notCopy
1405 case 5: eActROP
=RasterOp::OverPaint
; break; // notOr
1406 case 6: eActROP
=RasterOp::Xor
; break; // notXor
1407 case 7: eActROP
=RasterOp::OverPaint
; break; // notBic
1410 eActMethod
= PictDrawingMethod::UNDEFINED
;
1414 case 0x0009: // PnPat
1415 nDataSize
=eActPenPattern
.read(*pPict
);
1416 eActMethod
= PictDrawingMethod::UNDEFINED
;
1419 case 0x000a: // FillPat
1420 nDataSize
=eActFillPattern
.read(*pPict
);
1421 eActMethod
= PictDrawingMethod::UNDEFINED
;
1424 case 0x000b: // OvSize
1425 aActOvalSize
=ReadSize();
1429 case 0x000c: // Origin
1433 case 0x000d: // TxSize
1435 pPict
->ReadUInt16( nUSHORT
);
1436 aActFont
.SetFontSize( Size( 0, static_cast<long>(nUSHORT
) ) );
1437 eActMethod
= PictDrawingMethod::UNDEFINED
;
1442 case 0x000e: // FgColor
1443 aActForeColor
=ReadColor();
1444 eActMethod
= PictDrawingMethod::UNDEFINED
;
1448 case 0x000f: // BkColor
1449 aActBackColor
=ReadColor();
1453 case 0x0010: // TxRatio
1457 case 0x0011: // VersionOp
1461 case 0x0012: // BkPixPat
1462 nDataSize
=ReadPixPattern(eActBackPattern
);
1463 eActMethod
= PictDrawingMethod::UNDEFINED
;
1466 case 0x0013: // PnPixPat
1467 nDataSize
=ReadPixPattern(eActPenPattern
);
1468 eActMethod
= PictDrawingMethod::UNDEFINED
;
1471 case 0x0014: // FillPixPat
1472 nDataSize
=ReadPixPattern(eActFillPattern
);
1473 eActMethod
= PictDrawingMethod::UNDEFINED
;
1476 case 0x0015: // PnLocHFrac
1480 case 0x0016: // ChExtra
1484 case 0x0017: // Reserved (0 Bytes)
1485 case 0x0018: // Reserved (0 Bytes)
1486 case 0x0019: // Reserved (0 Bytes)
1490 case 0x001a: // RGBFgCol
1491 aActForeColor
=ReadRGBColor();
1492 eActMethod
= PictDrawingMethod::UNDEFINED
;
1496 case 0x001b: // RGBBkCol
1497 aActBackColor
=ReadRGBColor();
1498 eActMethod
= PictDrawingMethod::UNDEFINED
;
1502 case 0x001c: // HiliteMode
1506 case 0x001d: // HiliteColor
1510 case 0x001e: // DefHilite
1514 case 0x001f: // OpColor
1518 case 0x0020: // Line
1519 aPoint
=ReadPoint(); aPenPosition
=ReadPoint();
1522 if (IsInvisible( PictDrawingMethod::FRAME
)) break;
1523 DrawingMethod( PictDrawingMethod::FRAME
);
1524 PictReaderShape::drawLine(pVirDev
, aPoint
,aPenPosition
, nActPenSize
);
1527 case 0x0021: // LineFrom
1528 aPoint
=aPenPosition
; aPenPosition
=ReadPoint();
1531 if (IsInvisible( PictDrawingMethod::FRAME
)) break;
1532 DrawingMethod( PictDrawingMethod::FRAME
);
1533 PictReaderShape::drawLine(pVirDev
, aPoint
,aPenPosition
, nActPenSize
);
1536 case 0x0022: // ShortLine
1538 aPenPosition
=ReadDeltaH(aPoint
);
1539 aPenPosition
=ReadDeltaV(aPenPosition
);
1542 if ( IsInvisible(PictDrawingMethod::FRAME
) ) break;
1543 DrawingMethod( PictDrawingMethod::FRAME
);
1544 PictReaderShape::drawLine(pVirDev
, aPoint
,aPenPosition
, nActPenSize
);
1547 case 0x0023: // ShortLineFrom
1548 aPoint
=aPenPosition
;
1549 aPenPosition
=ReadDeltaH(aPoint
);
1550 aPenPosition
=ReadDeltaV(aPenPosition
);
1553 if (IsInvisible( PictDrawingMethod::FRAME
)) break;
1554 DrawingMethod( PictDrawingMethod::FRAME
);
1555 PictReaderShape::drawLine(pVirDev
, aPoint
,aPenPosition
, nActPenSize
);
1558 case 0x0024: // Reserved (n Bytes)
1559 case 0x0025: // Reserved (n Bytes)
1560 case 0x0026: // Reserved (n Bytes)
1561 case 0x0027: // Reserved (n Bytes)
1562 pPict
->ReadUInt16( nUSHORT
);
1563 nDataSize
=2+nUSHORT
;
1566 case 0x0028: // LongText
1567 aTextPosition
=ReadPoint();
1568 nDataSize
=4+ReadAndDrawText();
1571 case 0x0029: // DHText
1572 aTextPosition
=ReadUnsignedDeltaH(aTextPosition
);
1573 nDataSize
=1+ReadAndDrawText();
1576 case 0x002a: // DVText
1577 aTextPosition
=ReadUnsignedDeltaV(aTextPosition
);
1578 nDataSize
=1+ReadAndDrawText();
1581 case 0x002b: // DHDVText
1582 aTextPosition
=ReadUnsignedDeltaH(aTextPosition
);
1583 aTextPosition
=ReadUnsignedDeltaV(aTextPosition
);
1584 nDataSize
=2+ReadAndDrawText();
1587 case 0x002c: { // fontName
1588 char sFName
[ 256 ], nByteLen
;
1590 pPict
->ReadUInt16( nUSHORT
); nDataSize
=nUSHORT
+2;
1591 pPict
->ReadUInt16( nUSHORT
);
1592 if (nUSHORT
<= 1) aActFont
.SetFamily(FAMILY_SWISS
);
1593 else if (nUSHORT
<= 12) aActFont
.SetFamily(FAMILY_DECORATIVE
);
1594 else if (nUSHORT
<= 20) aActFont
.SetFamily(FAMILY_ROMAN
);
1595 else if (nUSHORT
== 21) aActFont
.SetFamily(FAMILY_SWISS
);
1596 else if (nUSHORT
== 22) aActFont
.SetFamily(FAMILY_MODERN
);
1597 else if (nUSHORT
<= 1023) aActFont
.SetFamily(FAMILY_SWISS
);
1598 else aActFont
.SetFamily(FAMILY_ROMAN
);
1599 aActFont
.SetCharSet(GetTextEncoding(nUSHORT
));
1600 pPict
->ReadChar( nByteLen
); nLen
=static_cast<sal_uInt16
>(nByteLen
)&0x00ff;
1601 pPict
->ReadBytes(&sFName
, nLen
);
1603 OUString
aString( sFName
, strlen(sFName
), osl_getThreadTextEncoding() );
1604 aActFont
.SetFamilyName( aString
);
1605 eActMethod
= PictDrawingMethod::UNDEFINED
;
1608 case 0x002d: // lineJustify
1612 case 0x002e: // glyphState
1613 pPict
->ReadUInt16( nUSHORT
);
1614 nDataSize
=2+nUSHORT
;
1617 case 0x002f: // Reserved (n Bytes)
1618 pPict
->ReadUInt16( nUSHORT
);
1619 nDataSize
=2+nUSHORT
;
1622 case 0x0030: // frameRect
1623 case 0x0031: // paintRect
1624 case 0x0032: // eraseRect
1625 case 0x0033: // invertRect
1626 case 0x0034: // fillRect
1627 nDataSize
=ReadAndDrawRect(shapeDMethod
);
1630 case 0x0035: // Reserved (8 Bytes)
1631 case 0x0036: // Reserved (8 Bytes)
1632 case 0x0037: // Reserved (8 Bytes)
1636 case 0x0038: // frameSameRect
1637 case 0x0039: // paintSameRect
1638 case 0x003a: // eraseSameRect
1639 case 0x003b: // invertSameRect
1640 case 0x003c: // fillSameRect
1641 nDataSize
=ReadAndDrawSameRect(shapeDMethod
);
1644 case 0x003d: // Reserved (0 Bytes)
1645 case 0x003e: // Reserved (0 Bytes)
1646 case 0x003f: // Reserved (0 Bytes)
1650 case 0x0040: // frameRRect
1651 case 0x0041: // paintRRect
1652 case 0x0042: // eraseRRect
1653 case 0x0043: // invertRRect
1654 case 0x0044: // fillRRect
1655 nDataSize
=ReadAndDrawRoundRect(shapeDMethod
);
1658 case 0x0045: // Reserved (8 Bytes)
1659 case 0x0046: // Reserved (8 Bytes)
1660 case 0x0047: // Reserved (8 Bytes)
1664 case 0x0048: // frameSameRRect
1665 case 0x0049: // paintSameRRect
1666 case 0x004a: // eraseSameRRect
1667 case 0x004b: // invertSameRRect
1668 case 0x004c: // fillSameRRect
1669 nDataSize
=ReadAndDrawSameRoundRect(shapeDMethod
);
1672 case 0x004d: // Reserved (0 Bytes)
1673 case 0x004e: // Reserved (0 Bytes)
1674 case 0x004f: // Reserved (0 Bytes)
1678 case 0x0050: // frameOval
1679 case 0x0051: // paintOval
1680 case 0x0052: // eraseOval
1681 case 0x0053: // invertOval
1682 case 0x0054: // fillOval
1683 nDataSize
=ReadAndDrawOval(shapeDMethod
);
1686 case 0x0055: // Reserved (8 Bytes)
1687 case 0x0056: // Reserved (8 Bytes)
1688 case 0x0057: // Reserved (8 Bytes)
1692 case 0x0058: // frameSameOval
1693 case 0x0059: // paintSameOval
1694 case 0x005a: // eraseSameOval
1695 case 0x005b: // invertSameOval
1696 case 0x005c: // fillSameOval
1697 nDataSize
=ReadAndDrawSameOval(shapeDMethod
);
1700 case 0x005d: // Reserved (0 Bytes)
1701 case 0x005e: // Reserved (0 Bytes)
1702 case 0x005f: // Reserved (0 Bytes)
1706 case 0x0060: // frameArc
1707 case 0x0061: // paintArc
1708 case 0x0062: // eraseArc
1709 case 0x0063: // invertArc
1710 case 0x0064: // fillArc
1711 nDataSize
=ReadAndDrawArc(shapeDMethod
);
1714 case 0x0065: // Reserved (12 Bytes)
1715 case 0x0066: // Reserved (12 Bytes)
1716 case 0x0067: // Reserved (12 Bytes)
1720 case 0x0068: // frameSameArc
1721 case 0x0069: // paintSameArc
1722 case 0x006a: // eraseSameArc
1723 case 0x006b: // invertSameArc
1724 case 0x006c: // fillSameArc
1725 nDataSize
=ReadAndDrawSameArc(shapeDMethod
);
1728 case 0x006d: // Reserved (4 Bytes)
1729 case 0x006e: // Reserved (4 Bytes)
1730 case 0x006f: // Reserved (4 Bytes)
1734 case 0x0070: // framePoly
1735 case 0x0071: // paintPoly
1736 case 0x0072: // erasePoly
1737 case 0x0073: // invertPoly
1738 case 0x0074: // fillPoly
1739 nDataSize
=ReadAndDrawPolygon(shapeDMethod
);
1742 case 0x0075: // Reserved (Polygon-Size)
1743 case 0x0076: // Reserved (Polygon-Size)
1744 case 0x0077: // Reserved (Polygon-Size)
1745 pPict
->ReadUInt16( nUSHORT
); nDataSize
=nUSHORT
;
1748 case 0x0078: // frameSamePoly
1749 case 0x0079: // paintSamePoly
1750 case 0x007a: // eraseSamePoly
1751 case 0x007b: // invertSamePoly
1752 case 0x007c: // fillSamePoly
1753 nDataSize
=ReadAndDrawSamePolygon(shapeDMethod
);
1756 case 0x007d: // Reserved (0 Bytes)
1757 case 0x007e: // Reserved (0 Bytes)
1758 case 0x007f: // Reserved (0 Bytes)
1762 case 0x0080: // frameRgn
1763 case 0x0081: // paintRgn
1764 case 0x0082: // eraseRgn
1765 case 0x0083: // invertRgn
1766 case 0x0084: // fillRgn
1767 nDataSize
=ReadAndDrawRgn(shapeDMethod
);
1770 case 0x0085: // Reserved (Region-Size)
1771 case 0x0086: // Reserved (Region-Size)
1772 case 0x0087: // Reserved (Region-Size)
1773 pPict
->ReadUInt16( nUSHORT
); nDataSize
=nUSHORT
;
1776 case 0x0088: // frameSameRgn
1777 case 0x0089: // paintSameRgn
1778 case 0x008a: // eraseSameRgn
1779 case 0x008b: // invertSameRgn
1780 case 0x008c: // fillSameRgn
1781 nDataSize
=ReadAndDrawSameRgn(shapeDMethod
);
1784 case 0x008d: // Reserved (0 Bytes)
1785 case 0x008e: // Reserved (0 Bytes)
1786 case 0x008f: // Reserved (0 Bytes)
1790 case 0x0090: { // BitsRect
1792 tools::Rectangle aSrcRect
, aDestRect
;
1793 nDataSize
=ReadPixMapEtc(aBmp
, false, true, &aSrcRect
, &aDestRect
, true, false);
1794 DrawingMethod( PictDrawingMethod::PAINT
);
1795 pVirDev
->DrawBitmapEx(aDestRect
.TopLeft(),aDestRect
.GetSize(),aBmp
);
1798 case 0x0091: { // BitsRgn
1800 tools::Rectangle aSrcRect
, aDestRect
;
1801 nDataSize
=ReadPixMapEtc(aBmp
, false, true, &aSrcRect
, &aDestRect
, true, true);
1802 DrawingMethod( PictDrawingMethod::PAINT
);
1803 pVirDev
->DrawBitmapEx(aDestRect
.TopLeft(),aDestRect
.GetSize(),aBmp
);
1806 case 0x0092: // Reserved (n Bytes)
1807 case 0x0093: // Reserved (n Bytes)
1808 case 0x0094: // Reserved (n Bytes)
1809 case 0x0095: // Reserved (n Bytes)
1810 case 0x0096: // Reserved (n Bytes)
1811 case 0x0097: // Reserved (n Bytes)
1812 pPict
->ReadUInt16( nUSHORT
); nDataSize
=2+nUSHORT
;
1815 case 0x0098: { // PackBitsRect
1817 tools::Rectangle aSrcRect
, aDestRect
;
1818 nDataSize
=ReadPixMapEtc(aBmp
, false, true, &aSrcRect
, &aDestRect
, true, false);
1819 DrawingMethod( PictDrawingMethod::PAINT
);
1820 pVirDev
->DrawBitmapEx(aDestRect
.TopLeft(),aDestRect
.GetSize(),aBmp
);
1823 case 0x0099: { // PackBitsRgn
1825 tools::Rectangle aSrcRect
, aDestRect
;
1826 nDataSize
=ReadPixMapEtc(aBmp
, false, true, &aSrcRect
, &aDestRect
, true, true);
1827 DrawingMethod( PictDrawingMethod::PAINT
);
1828 pVirDev
->DrawBitmapEx(aDestRect
.TopLeft(),aDestRect
.GetSize(),aBmp
);
1831 case 0x009a: { // DirectBitsRect
1833 tools::Rectangle aSrcRect
, aDestRect
;
1834 nDataSize
=ReadPixMapEtc(aBmp
, true, false, &aSrcRect
, &aDestRect
, true, false);
1835 DrawingMethod( PictDrawingMethod::PAINT
);
1836 pVirDev
->DrawBitmapEx(aDestRect
.TopLeft(),aDestRect
.GetSize(),aBmp
);
1839 case 0x009b: { // DirectBitsRgn
1841 tools::Rectangle aSrcRect
, aDestRect
;
1842 nDataSize
=ReadPixMapEtc(aBmp
, true, false, &aSrcRect
, &aDestRect
, true, true);
1843 DrawingMethod( PictDrawingMethod::PAINT
);
1844 pVirDev
->DrawBitmapEx(aDestRect
.TopLeft(),aDestRect
.GetSize(),aBmp
);
1847 case 0x009c: // Reserved (n Bytes)
1848 case 0x009d: // Reserved (n Bytes)
1849 case 0x009e: // Reserved (n Bytes)
1850 case 0x009f: // Reserved (n Bytes)
1851 pPict
->ReadUInt16( nUSHORT
); nDataSize
=2+nUSHORT
;
1854 case 0x00a0: // ShortComment
1858 case 0x00a1: // LongComment
1859 pPict
->SeekRel(2); pPict
->ReadUInt16( nUSHORT
); nDataSize
=4+nUSHORT
;
1862 default: // 0x00a2 bis 0xffff (most times reserved)
1863 if (nOpcode
<=0x00af) { pPict
->ReadUInt16( nUSHORT
); nDataSize
=2+nUSHORT
; }
1864 else if (nOpcode
<=0x00cf) { nDataSize
=0; }
1865 else if (nOpcode
<=0x00fe) { sal_uInt32 nTemp
; pPict
->ReadUInt32( nTemp
) ; nDataSize
= nTemp
; nDataSize
+=4; }
1866 // Osnola: checkme: in the Quickdraw Ref examples ( for pict v2)
1867 // 0x00ff(EndOfPict) is also not followed by any data...
1868 else if (nOpcode
==0x00ff) { nDataSize
=IsVersion2
? 2 : 0; } // OpEndPic
1869 else if (nOpcode
<=0x01ff) { nDataSize
=2; }
1870 else if (nOpcode
<=0x0bfe) { nDataSize
=4; }
1871 else if (nOpcode
<=0x0bff) { nDataSize
=22; }
1872 else if (nOpcode
==0x0c00) { nDataSize
=24; } // HeaderOp
1873 else if (nOpcode
<=0x7eff) { nDataSize
=24; }
1874 else if (nOpcode
<=0x7fff) { nDataSize
=254; }
1875 else if (nOpcode
<=0x80ff) { nDataSize
=0; }
1876 else { sal_uInt32 nTemp
; pPict
->ReadUInt32( nTemp
) ; nDataSize
= nTemp
; nDataSize
+=4; }
1879 if (nDataSize
==0xffffffff) {
1880 pPict
->SetError(SVSTREAM_FILEFORMAT_ERROR
);
1886 void PictReader::ReadPict( SvStream
& rStreamPict
, GDIMetaFile
& rGDIMetaFile
)
1890 sal_uInt8 nOneByteOpcode
;
1893 pPict
= &rStreamPict
;
1894 nOrigPos
= pPict
->Tell();
1895 SvStreamEndian nOrigNumberFormat
= pPict
->GetEndian();
1897 aActForeColor
= COL_BLACK
;
1898 aActBackColor
= COL_WHITE
;
1899 nActPenSize
= Size(1,1);
1900 eActROP
= RasterOp::OverPaint
;
1901 eActMethod
= PictDrawingMethod::UNDEFINED
;
1902 aActOvalSize
= Size(1,1);
1904 aActFont
.SetCharSet( GetTextEncoding());
1905 aActFont
.SetFamily(FAMILY_SWISS
);
1906 aActFont
.SetFontSize(Size(0,12));
1907 aActFont
.SetAlignment(ALIGN_BASELINE
);
1909 aHRes
= aVRes
= Fraction( 1, 1 );
1911 pVirDev
= VclPtr
<VirtualDevice
>::Create();
1912 pVirDev
->EnableOutput(false);
1913 rGDIMetaFile
.Record(pVirDev
);
1915 pPict
->SetEndian(SvStreamEndian::BIG
);
1919 aPenPosition
=Point(-aBoundingRect
.Left(),-aBoundingRect
.Top());
1920 aTextPosition
=aPenPosition
;
1922 sal_uInt64 nPos
=pPict
->Tell();
1927 pPict
->ReadUInt16( nOpcode
);
1930 pPict
->ReadUChar( nOneByteOpcode
);
1931 nOpcode
=static_cast<sal_uInt16
>(nOneByteOpcode
);
1934 if (pPict
->GetError())
1939 pPict
->SetError(SVSTREAM_FILEFORMAT_ERROR
);
1943 if (nOpcode
==0x00ff)
1946 nSize
=ReadData(nOpcode
);
1961 pVirDev
->SetClipRegion();
1962 rGDIMetaFile
.Stop();
1963 pVirDev
.disposeAndClear();
1965 rGDIMetaFile
.SetPrefMapMode( MapMode( MapUnit::MapInch
, Point(), aHRes
, aVRes
) );
1966 rGDIMetaFile
.SetPrefSize( aBoundingRect
.GetSize() );
1968 pPict
->SetEndian(nOrigNumberFormat
);
1970 if (pPict
->GetError()) pPict
->Seek(nOrigPos
);
1973 rStreamPict
.SetError(SVSTREAM_FILEFORMAT_ERROR
);
1979 void ReadPictFile(SvStream
&rStreamPict
, GDIMetaFile
& rGDIMetaFile
)
1981 PictReader aPictReader
;
1982 aPictReader
.ReadPict(rStreamPict
, rGDIMetaFile
);
1987 //================== GraphicImport - the exported function ================
1989 extern "C" SAL_DLLPUBLIC_EXPORT
bool
1990 iptGraphicImport( SvStream
& rIStm
, Graphic
& rGraphic
, FilterConfigItem
* )
1995 pict::ReadPictFile( rIStm
, aMTF
);
1997 if ( !rIStm
.GetError() )
1999 rGraphic
= Graphic( aMTF
);
2006 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */