22#include <osl/thread.h>
71 bool isDefault()
const {
return !
isRead; }
73 enum PenStyle { PEN_NULL, PEN_SOLID, PEN_DOT, PEN_DASH, PEN_DASHDOT };
74 enum BrushStyle { BRUSH_SOLID, BRUSH_HORZ, BRUSH_VERT,
75 BRUSH_CROSS, BRUSH_DIAGCROSS, BRUSH_UPDIAG, BRUSH_DOWNDIAG,
76 BRUSH_25, BRUSH_50, BRUSH_75 };
93 unsigned char nbyte[8] = {0};
98 for (
unsigned char & ny : nbyte) {
99 stream.ReadChar(
reinterpret_cast<char&
>(ny) );
100 for (
short nx=0;
nx<8;
nx++) {
106 sal_uInt32 nHiBytes = (((((
static_cast<sal_uInt32
>(nbyte[0])<<8)|
107 static_cast<sal_uInt32
>(nbyte[1]))<<8)|
108 static_cast<sal_uInt32
>(nbyte[2]))<<8)|
109 static_cast<sal_uInt32
>(nbyte[3]);
110 sal_uInt32 nLoBytes = (((((
static_cast<sal_uInt32
>(nbyte[4])<<8)|
111 static_cast<sal_uInt32
>(nbyte[5]))<<8)|
112 static_cast<sal_uInt32
>(nbyte[6]))<<8)|
113 static_cast<sal_uInt32
>(nbyte[7]);
123 if (nHiBytes==0xffffffff && nLoBytes==0xffffffff)
brushStyle=BRUSH_SOLID;
124 else if (nHiBytes==0xff000000 && nLoBytes==0x00000000)
brushStyle=BRUSH_HORZ;
125 else if (nHiBytes==0x80808080 && nLoBytes==0x80808080)
brushStyle=BRUSH_VERT;
126 else if (nHiBytes==0xff808080 && nLoBytes==0x80808080)
brushStyle=BRUSH_CROSS;
127 else if (nHiBytes==0x01824428 && nLoBytes==0x10284482)
brushStyle=BRUSH_DIAGCROSS;
128 else if (nHiBytes==0x80402010 && nLoBytes==0x08040201)
brushStyle=BRUSH_UPDIAG;
129 else if (nHiBytes==0x01020408 && nLoBytes==0x10204080)
brushStyle=BRUSH_DOWNDIAG;
145enum class PictDrawingMethod {
151 typedef class PictReaderInternal::Pattern
Pattern;
172 PictDrawingMethod eActMethod;
191 Color ReadRGBColor();
197 sal_uInt64 ReadPixPattern(Pattern &pattern);
200 sal_uInt8 ReadAndDrawRect(PictDrawingMethod eMethod);
201 sal_uInt8 ReadAndDrawSameRect(PictDrawingMethod eMethod);
204 sal_uInt8 ReadAndDrawRoundRect(PictDrawingMethod eMethod);
205 sal_uInt8 ReadAndDrawSameRoundRect(PictDrawingMethod eMethod);
208 sal_uInt8 ReadAndDrawOval(PictDrawingMethod eMethod);
209 sal_uInt8 ReadAndDrawSameOval(PictDrawingMethod eMethod);
212 sal_uInt64 ReadAndDrawPolygon(PictDrawingMethod eMethod);
213 sal_uInt8 ReadAndDrawSamePolygon(PictDrawingMethod eMethod);
216 sal_uInt8 ReadAndDrawArc(PictDrawingMethod eMethod);
217 sal_uInt8 ReadAndDrawSameArc(PictDrawingMethod eMethod);
219 sal_uInt64 ReadAndDrawRgn(PictDrawingMethod eMethod);
220 sal_uInt8 ReadAndDrawSameRgn(PictDrawingMethod eMethod);
223 bool IsInvisible( PictDrawingMethod eMethod )
const {
225 if ( eMethod == PictDrawingMethod::FRAME && nActPenSize.
IsEmpty() )
return true;
229 void DrawingMethod(PictDrawingMethod eMethod);
231 sal_uInt64 ReadAndDrawText();
233 sal_uInt64 ReadPixMapEtc(
BitmapEx & rBitmap,
bool bBaseAddr,
bool bColorTable,
235 bool bMode,
bool bMaskRgn);
240 sal_uInt64 ReadData(sal_uInt16 nOpcode);
246 void SetFillColor(
const Color& rColor );
249 static rtl_TextEncoding GetTextEncoding (sal_uInt16 fId = 0xFFFF);
259 , eActMethod(PictDrawingMethod::
UNDEFINED)
277 if (
nx == nWidth )
break;
279 if (
nx == nWidth )
break;
281 if (
nx == nWidth )
break;
283 if (
nx == nWidth )
break;
285 if (
nx == nWidth )
break;
287 if (
nx == nWidth )
break;
289 if (
nx == nWidth )
break;
294 if (
nx == nWidth )
break;
296 if (
nx == nWidth )
break;
298 if (
nx == nWidth )
break;
303 if (
nx == nWidth )
break;
313rtl_TextEncoding PictReader::GetTextEncoding (sal_uInt16 fId) {
314 static rtl_TextEncoding enc = []()
316 rtl_TextEncoding def = osl_getThreadTextEncoding();
319 case RTL_TEXTENCODING_APPLE_ROMAN:
320 case RTL_TEXTENCODING_APPLE_ARABIC:
321 case RTL_TEXTENCODING_APPLE_CENTEURO:
322 case RTL_TEXTENCODING_APPLE_CROATIAN:
323 case RTL_TEXTENCODING_APPLE_CYRILLIC:
324 case RTL_TEXTENCODING_APPLE_DEVANAGARI:
325 case RTL_TEXTENCODING_APPLE_FARSI:
326 case RTL_TEXTENCODING_APPLE_GREEK:
327 case RTL_TEXTENCODING_APPLE_GUJARATI:
328 case RTL_TEXTENCODING_APPLE_GURMUKHI:
329 case RTL_TEXTENCODING_APPLE_HEBREW:
330 case RTL_TEXTENCODING_APPLE_ICELAND:
331 case RTL_TEXTENCODING_APPLE_ROMANIAN:
332 case RTL_TEXTENCODING_APPLE_THAI:
333 case RTL_TEXTENCODING_APPLE_TURKISH:
334 case RTL_TEXTENCODING_APPLE_UKRAINIAN:
335 case RTL_TEXTENCODING_APPLE_CHINSIMP:
336 case RTL_TEXTENCODING_APPLE_CHINTRAD:
337 case RTL_TEXTENCODING_APPLE_JAPANESE:
338 case RTL_TEXTENCODING_APPLE_KOREAN:
343 return RTL_TEXTENCODING_APPLE_ROMAN;
345 if (fId == 13)
return RTL_TEXTENCODING_ADOBE_DINGBATS;
346 if (fId == 23)
return RTL_TEXTENCODING_ADOBE_SYMBOL;
350void PictReader::SetLineColor(
const Color& rColor )
355void PictReader::SetFillColor(
const Color& rColor )
360Point PictReader::ReadPoint()
366 Point aPoint(nx - aBoundingRect.
Left(), ny - aBoundingRect.
Top());
368 SAL_INFO(
"filter.pict",
"ReadPoint: " << aPoint);
376 pPict->
ReadChar(
reinterpret_cast<char&
>(ndh) );
385 pPict->
ReadChar(
reinterpret_cast<char&
>(ndv) );
390Point PictReader::ReadUnsignedDeltaH(
Point aBase)
399Point PictReader::ReadUnsignedDeltaV(
Point aBase)
408Size PictReader::ReadSize()
417Color PictReader::ReadColor()
438Color PictReader::ReadRGBColor()
440 sal_uInt16 nR(0), nG(0), nB(0);
448 Point aTopLeft = ReadPoint();
449 Point aBottomRight = ReadPoint();
450 if (!pPict->
good() || aTopLeft.
X() > aBottomRight.
X() || aTopLeft.
Y() > aBottomRight.
Y())
452 SAL_WARN(
"filter.pict",
"broken rectangle");
453 pPict->
SetError( SVSTREAM_FILEFORMAT_ERROR );
459 SAL_INFO(
"filter.pict",
"ReadRectangle: " << rRect);
467 sal_uInt64 nDataSize =
static_cast<sal_uInt64
>(nSize);
469 const size_t nMaxPossiblePoints = pPict->
remainingSize() / 2 *
sizeof(sal_uInt16);
470 if (nSize > nMaxPossiblePoints)
472 SAL_WARN(
"filter.pict",
"pict record claims to have: " << nSize <<
" points, but only " << nMaxPossiblePoints <<
" possible, clamping");
473 nSize = nMaxPossiblePoints;
476 for (sal_uInt16 i = 0;
i < nSize; ++
i)
488sal_uInt64 PictReader::ReadPixPattern(PictReader::Pattern &pattern)
494 sal_uInt64 nDataSize;
496 sal_uInt16 nPatType(0);
499 pattern.read(*pPict);
501 nDataSize=ReadPixMapEtc(aBMP,
false,
true,
nullptr,
nullptr,
false,
false);
503 if (nDataSize!=0xffffffff) nDataSize+=10;
505 else if (nPatType==2) {
506 pattern.read(*pPict);
508 sal_uInt16 nR, nG, nB;
511 pattern.setColor(col);
514 else nDataSize=0xffffffff;
519sal_uInt8 PictReader::ReadAndDrawRect(PictDrawingMethod eMethod)
521 ReadRectangle(aLastRect);
522 ReadAndDrawSameRect(eMethod);
526sal_uInt8 PictReader::ReadAndDrawSameRect(PictDrawingMethod eMethod)
528 if (IsInvisible(eMethod))
return 0;
529 DrawingMethod(eMethod);
534sal_uInt8 PictReader::ReadAndDrawRoundRect(PictDrawingMethod eMethod)
536 ReadRectangle(aLastRoundRect);
537 ReadAndDrawSameRoundRect(eMethod);
541sal_uInt8 PictReader::ReadAndDrawSameRoundRect(PictDrawingMethod eMethod)
543 if (IsInvisible(eMethod))
return 0;
544 DrawingMethod(eMethod);
549sal_uInt8 PictReader::ReadAndDrawOval(PictDrawingMethod eMethod)
551 ReadRectangle(aLastOval);
552 ReadAndDrawSameOval(eMethod);
556sal_uInt8 PictReader::ReadAndDrawSameOval(PictDrawingMethod eMethod)
558 if (IsInvisible(eMethod))
return 0;
559 DrawingMethod(eMethod);
564sal_uInt64 PictReader::ReadAndDrawPolygon(PictDrawingMethod eMethod)
566 sal_uInt64 nDataSize;
568 ReadAndDrawSamePolygon(eMethod);
572sal_uInt8 PictReader::ReadAndDrawSamePolygon(PictDrawingMethod eMethod)
574 if (IsInvisible(eMethod))
return 0;
575 DrawingMethod(eMethod);
581sal_uInt8 PictReader::ReadAndDrawArc(PictDrawingMethod eMethod)
583 ReadRectangle(aLastArcRect);
584 ReadAndDrawSameArc(eMethod);
588sal_uInt8 PictReader::ReadAndDrawSameArc(PictDrawingMethod eMethod)
590 short nstartAngle, narcAngle;
593 if (!pPict->
good() || IsInvisible(eMethod))
return 4;
594 DrawingMethod(eMethod);
597 nstartAngle = nstartAngle + narcAngle;
598 narcAngle=-narcAngle;
606sal_uInt64 PictReader::ReadAndDrawRgn(PictDrawingMethod eMethod)
625 ReadAndDrawSameRgn(eMethod);
626 return static_cast<sal_uInt64
>(nSize);
629sal_uInt8 PictReader::ReadAndDrawSameRgn(PictDrawingMethod eMethod)
631 if (IsInvisible(eMethod))
return 0;
632 DrawingMethod(eMethod);
637void PictReader::DrawingMethod(PictDrawingMethod eMethod)
639 if( eActMethod==eMethod )
return;
641 case PictDrawingMethod::FRAME:
642 if (eActPenPattern.isDefault())
645 SetLineColor(eActPenPattern.getColor(aActBackColor, aActForeColor));
646 SetFillColor( COL_TRANSPARENT );
649 case PictDrawingMethod::PAINT:
651 if (eActPenPattern.isDefault())
652 SetFillColor( aActForeColor );
654 SetFillColor(eActPenPattern.getColor(aActBackColor, aActForeColor));
657 case PictDrawingMethod::ERASE:
659 if (eActBackPattern.isDefault())
660 SetFillColor( aActBackColor );
662 SetFillColor(eActBackPattern.getColor(COL_BLACK, aActBackColor));
665 case PictDrawingMethod::INVERT:
667 SetFillColor( COL_BLACK );
670 case PictDrawingMethod::FILL:
672 if (eActFillPattern.isDefault())
673 SetFillColor( aActForeColor );
675 SetFillColor(eActFillPattern.getColor(aActBackColor, aActForeColor));
678 case PictDrawingMethod::TEXT:
691sal_uInt64 PictReader::ReadAndDrawText()
697 sal_uInt32 nLen =
static_cast<sal_uInt32
>(nByteLen)&0x000000ff;
698 sal_uInt32 nDataLen = nLen + 1;
701 if (IsInvisible( PictDrawingMethod::TEXT ))
return nDataLen;
702 DrawingMethod( PictDrawingMethod::TEXT );
705 while ( nLen > 0 &&
static_cast<unsigned char>(sText[ nLen - 1 ]) < 32 )
708 OUString aString( sText, strlen(sText), aActFont.
GetCharSet());
709 pVirDev->
DrawText(
Point( aTextPosition.
X(), aTextPosition.
Y() ), aString );
713sal_uInt64 PictReader::ReadPixMapEtc(
BitmapEx &rBitmap,
bool bBaseAddr,
bool bColorTable,
tools::Rectangle* pSrcRect,
716 std::unique_ptr<vcl::bitmap::RawBitmap> pBitmap;
717 sal_uInt16 nPackType(0), nPixelSize(0), nCmpCount(0), nCmpSize(0);
718 sal_uInt8 nDat(0), nRed(0), nGreen(0), nBlue(0);
721 size_t nDataSize = 0;
731 sal_uInt16 nRowBytes(0), nBndX(0), nBndY(0), nWidth(0), nHeight(0);
735 nHeight = nHeight - nBndY;
740 nWidth = nWidth - nBndX;
744 std::vector<Color> aPalette;
745 const bool bNotMonoChrome = (nRowBytes & 0x8000) != 0;
750 sal_uInt32 nPackSize;
751 sal_uInt16 nPixelType;
752 sal_uInt32 nPlaneBytes;
753 sal_uInt32 nHRes, nVRes;
762 sal_uInt16 nColTabSize(0);
765 if (nColTabSize > 255)
770 aPalette.resize(nColTabSize);
772 for (
size_t i = 0;
i < nColTabSize; ++
i)
777 aPalette[
i] =
Color(nRed, nGreen, nBlue);
780 nDataSize += 8 + nColTabSize * 8;
786 nPixelSize = nCmpCount = 1;
789 aPalette[0] =
Color(0xff, 0xff, 0xff);
790 aPalette[1] =
Color(0, 0, 0);
794 if ( pSrcRect !=
nullptr)
796 sal_uInt16 nTop, nLeft, nBottom, nRight;
803 if ( pDestRect !=
nullptr )
805 Point aTL = ReadPoint();
806 Point aBR = ReadPoint();
828 if ( nPixelSize == 1 || nPixelSize == 2 || nPixelSize == 4 || nPixelSize == 8 )
830 sal_uInt16 nSrcBPL, nDestBPL;
833 if ( nPixelSize == 1 ) nSrcBPL = ( nWidth + 7 ) >> 3;
834 else if ( nPixelSize == 2 ) nSrcBPL = ( nWidth + 3 ) >> 2;
835 else if ( nPixelSize == 4 ) nSrcBPL = ( nWidth + 1 ) >> 1;
836 else nSrcBPL = nWidth;
837 nDestBPL = ( nSrcBPL + 3 ) & 0xfffc;
838 if (!nRowBytes || nRowBytes < nSrcBPL || nRowBytes > nDestBPL)
841 if (nRowBytes < 8 || nPackType == 1)
848 size_t nByteCountSize = nRowBytes > 250 ?
sizeof(sal_uInt16) :
sizeof(
sal_uInt8);
855 for (sal_uInt16 ny = 0;
ny < nHeight; ++
ny)
858 if ( nRowBytes < 8 || nPackType == 1 )
860 for (
size_t i = 0;
i < nRowBytes; ++
i)
864 SetByte(nx, ny, *pBitmap, nPixelSize, nDat, nWidth, aPalette);
866 nDataSize += nRowBytes;
870 sal_uInt16 nByteCount(0);
871 if ( nRowBytes > 250 )
874 nDataSize += 2 +
static_cast<sal_uInt32
>(nByteCount);
880 nByteCount =
static_cast<sal_uInt16
>(nByteCountAsByte) & 0x00ff;
881 nDataSize += 1 + nByteCount;
884 while (pPict->
good() && nByteCount)
888 if ( ( nFlagCounterByte & 0x80 ) == 0 )
890 nCount =
static_cast<sal_uInt16
>(nFlagCounterByte) + 1;
895 SetByte(nx, ny, *pBitmap, nPixelSize, nDat, nWidth, aPalette);
901 nCount =
static_cast<sal_uInt16
>( 1 - sal_Int16(
static_cast<sal_uInt16
>(nFlagCounterByte) | 0xff00 ) );
906 SetByte(nx, ny, *pBitmap, nPixelSize, nDat, nWidth, aPalette);
914 else if ( nPixelSize == 16 )
916 sal_uInt8 nByteCountAsByte, nFlagCounterByte;
917 sal_uInt16 nByteCount,
nCount, nD;
918 sal_uInt64 nSrcBitsPos;
920 if (nWidth > nRowBytes / 2)
923 if (nRowBytes < 8 || nPackType == 1)
930 size_t nByteCountSize = nRowBytes > 250 ?
sizeof(sal_uInt16) :
sizeof(
sal_uInt8);
937 for (sal_uInt16 ny = 0;
ny < nHeight; ++
ny)
940 if ( nRowBytes < 8 || nPackType == 1 )
942 for (
size_t i = 0;
i < nWidth; ++
i)
945 nRed =
static_cast<sal_uInt8>( nD >> 7 );
946 nGreen =
static_cast<sal_uInt8>( nD >> 2 );
947 nBlue =
static_cast<sal_uInt8>( nD << 3 );
948 pBitmap->SetPixel(ny, nx++,
Color(nRed, nGreen, nBlue));
950 nDataSize +=
static_cast<sal_uInt32
>(nWidth) * 2;
954 nSrcBitsPos = pPict->
Tell();
955 if ( nRowBytes > 250 )
963 nByteCount =
static_cast<sal_uInt16
>(nByteCountAsByte) & 0x00ff;
966 while ( nx != nWidth )
969 if ( (nFlagCounterByte & 0x80) == 0)
971 nCount=
static_cast<sal_uInt16
>(nFlagCounterByte)+1;
972 if ( nCount + nx > nWidth)
984 nRed =
static_cast<sal_uInt8>( nD >> 7 );
985 nGreen =
static_cast<sal_uInt8>( nD >> 2 );
986 nBlue =
static_cast<sal_uInt8>( nD << 3 );
987 pBitmap->SetPixel(ny, nx++,
Color(nRed, nGreen, nBlue));
994 nCount=(1-sal_Int16(
static_cast<sal_uInt16
>(nFlagCounterByte)|0xff00));
995 if ( nCount + nx > nWidth )
998 nRed =
static_cast<sal_uInt8>( nD >> 7 );
999 nGreen =
static_cast<sal_uInt8>( nD >> 2 );
1000 nBlue =
static_cast<sal_uInt8>( nD << 3 );
1001 for (
size_t i = 0;
i <
nCount; ++
i)
1003 pBitmap->SetPixel(ny, nx++,
Color(nRed, nGreen, nBlue));
1007 nDataSize += nByteCount;
1008 pPict->
Seek(nSrcBitsPos+nByteCount);
1012 else if ( nPixelSize == 32 )
1014 sal_uInt16 nByteCount;
1016 sal_uInt64 nSrcBitsPos;
1017 if ( nRowBytes != 4*nWidth )
1020 if ( nRowBytes < 8 || nPackType == 1 )
1023 const size_t nMaxRows = nMaxPixels / nWidth;
1024 if (nHeight > nMaxRows)
1026 const size_t nMaxCols = nMaxPixels / nHeight;
1027 if (nWidth > nMaxCols)
1032 for (sal_uInt16 ny = 0;
ny < nHeight; ++
ny)
1034 for (sal_uInt16 nx = 0;
nx < nWidth; ++
nx)
1038 pBitmap->SetPixel(ny, nx,
Color(nRed, nGreen, nBlue));
1040 nDataSize +=
static_cast<sal_uInt32
>(nWidth) * 4;
1043 else if ( nPackType == 2 )
1046 const size_t nMaxRows = nMaxPixels / nWidth;
1047 if (nHeight > nMaxRows)
1049 const size_t nMaxCols = nMaxPixels / nHeight;
1050 if (nWidth > nMaxCols)
1055 for (sal_uInt16 ny = 0;
ny < nHeight; ++
ny)
1057 for (sal_uInt16 nx = 0;
nx < nWidth; ++
nx)
1060 pBitmap->SetPixel(ny, nx,
Color(nRed, nGreen, nBlue));
1062 nDataSize +=
static_cast<sal_uInt32
>(nWidth) * 3;
1069 if ( ( nCmpCount == 3 ) || ( nCmpCount == 4 ) )
1071 size_t nByteCountSize = nRowBytes > 250 ?
sizeof(sal_uInt16) :
sizeof(
sal_uInt8);
1078 nWidth = pBitmap->Width();
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 )
1093 nByteCount = nByteCountAsByte;
1097 while (i < aScanline.size())
1100 if ( ( nFlagCounterByte & 0x80 ) == 0)
1102 nCount =
static_cast<sal_uInt16
>(nFlagCounterByte) + 1;
1103 if ((i + nCount) > aScanline.size())
1104 nCount = aScanline.size() -
i;
1110 aScanline[
i++ ] = nDat;
1117 nCount = ( 1 - sal_Int16(
static_cast<sal_uInt16
>(nFlagCounterByte) | 0xff00 ) );
1118 if (( i + nCount) > aScanline.size())
1119 nCount = aScanline.size() -
i;
1122 aScanline[
i++ ] = nDat;
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 += nByteCount;
1131 pPict->
Seek( nSrcBitsPos + nByteCount );
1142void PictReader::ReadHeader()
1149 sal_uInt64 nStartPos = pPict->
Tell();
1171 int confidence[2] = { 0, 0};
1172 for ( st = 0; st < 3 + 513; st++ )
1174 int actualConfid = 20;
1176 if (st < 2) nOffset = nStartPos+st*512;
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 = nStartPos+509+st;
1188 pPict->
Seek(nOffset+10);
1190 if (!pPict->
good())
break;
1191 if (sBuf[0] == 0x11 || (sBuf[0] == 0x00 && sBuf[1] == 0x11)) ;
1194 pPict->
Seek(nOffset);
1199 if (x1 > x2 || y1 > y2)
continue;
1200 if (x1 < -2048 || x2 > 2048 || y1 < -2048 || y2 > 2048 ||
1201 (x1 == x2 && y1 == y2) )
1203 else if (x2 < x1+8 || y2 < y1+8)
1205 if (st >= 3 && actualConfid != 20)
continue;
1208 if (!pPict->
good())
continue;
1212 if ( sBuf[ 0 ] == 0x11 && sBuf[ 1 ] == 0x01 ) {
1214 if (st < 2) { confidence[st] = --actualConfid;
continue; }
1215 IsVersion2 =
false;
return;
1217 if (sBuf[0] != 0x00)
continue;
1225 while ( sBuf[0] == 0x00 && numZero < 10);
1226 actualConfid -= (numZero-1);
1227 if (!pPict->
good())
continue;
1228 if (sBuf[0] != 0x11)
continue;
1230 if (sBuf[1] == 0x01 ) {
1232 if (st < 2) { confidence[st] = --actualConfid;
continue; }
1233 IsVersion2 =
false;
return;
1235 if (sBuf[1] != 0x02 )
continue;
1238 short nExtVer, nReserved;
1242 if (!pPict->
good())
continue;
1244 if ( nExtVer == -2 )
1246 sal_Int32 nHResFixed, nVResFixed;
1249 if (x1 > x2 || y1 > y2)
continue;
1250 if (st < 2 && actualConfid != 20) { confidence[st] = actualConfid;
continue; }
1252 double fHRes = nHResFixed;
1254 double fVRes = nVResFixed;
1262 else if (nExtVer == -1 ) {
1263 if (st < 2 && actualConfid != 20) { confidence[st] = actualConfid;
continue; }
1269 pPict->
SetError(SVSTREAM_FILEFORMAT_ERROR);
1272#if OSL_DEBUG_LEVEL > 0
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 "?";
1304sal_uInt64 PictReader::ReadData(sal_uInt16 nOpcode)
1307 sal_uInt64 nDataSize=0;
1308 PictDrawingMethod shapeDMethod = PictDrawingMethod::UNDEFINED;
1309 switch (nOpcode & 7) {
1310 case 0: shapeDMethod = PictDrawingMethod::FRAME;
break;
1311 case 1: shapeDMethod = PictDrawingMethod::PAINT;
break;
1312 case 2: shapeDMethod = PictDrawingMethod::ERASE;
break;
1313 case 3: shapeDMethod = PictDrawingMethod::INVERT;
break;
1314 case 4: shapeDMethod = PictDrawingMethod::FILL;
break;
1318#if OSL_DEBUG_LEVEL > 0
1319 SAL_INFO(
"filter.pict",
"Operation: 0x" << OUString::number(nOpcode, 16) <<
" [" <<
operationName(nOpcode) <<
"]");
1329 sal_uInt16 nUSHORT(0);
1333 ReadRectangle(aRect);
1345 nDataSize = eActBackPattern.read(*pPict);
1346 eActMethod = PictDrawingMethod::UNDEFINED;
1351 sal_uInt16 nUSHORT(0);
1353 if (nUSHORT <= 1) aActFont.
SetFamily(FAMILY_SWISS);
1354 else if (nUSHORT <= 12) aActFont.
SetFamily(FAMILY_DECORATIVE);
1355 else if (nUSHORT <= 20) aActFont.
SetFamily(FAMILY_ROMAN);
1356 else if (nUSHORT == 21) aActFont.
SetFamily(FAMILY_SWISS);
1357 else if (nUSHORT == 22) aActFont.
SetFamily(FAMILY_MODERN);
1358 else if (nUSHORT <= 1023) aActFont.
SetFamily(FAMILY_SWISS);
1360 aActFont.
SetCharSet(GetTextEncoding(nUSHORT));
1361 eActMethod = PictDrawingMethod::UNDEFINED;
1368 if ( (nFace & 0x01)!=0 ) aActFont.
SetWeight(WEIGHT_BOLD);
1370 if ( (nFace & 0x02)!=0 ) aActFont.
SetItalic(ITALIC_NORMAL);
1372 if ( (nFace & 0x04)!=0 ) aActFont.
SetUnderline(LINESTYLE_SINGLE);
1374 if ( (nFace & 0x08)!=0 ) aActFont.
SetOutline(
true);
1376 if ( (nFace & 0x10)!=0 ) aActFont.
SetShadow(
true);
1378 eActMethod = PictDrawingMethod::UNDEFINED;
1391 nActPenSize=ReadSize();
1392 eActMethod = PictDrawingMethod::UNDEFINED;
1398 sal_uInt16 nUSHORT(0);
1403 switch (nUSHORT & 0x0007) {
1414 eActMethod = PictDrawingMethod::UNDEFINED;
1419 nDataSize=eActPenPattern.read(*pPict);
1420 eActMethod = PictDrawingMethod::UNDEFINED;
1424 nDataSize=eActFillPattern.read(*pPict);
1425 eActMethod = PictDrawingMethod::UNDEFINED;
1429 aActOvalSize=ReadSize();
1439 sal_uInt16 nUSHORT(0);
1442 eActMethod = PictDrawingMethod::UNDEFINED;
1448 aActForeColor=ReadColor();
1449 eActMethod = PictDrawingMethod::UNDEFINED;
1454 aActBackColor=ReadColor();
1467 nDataSize=ReadPixPattern(eActBackPattern);
1468 eActMethod = PictDrawingMethod::UNDEFINED;
1472 nDataSize=ReadPixPattern(eActPenPattern);
1473 eActMethod = PictDrawingMethod::UNDEFINED;
1477 nDataSize=ReadPixPattern(eActFillPattern);
1478 eActMethod = PictDrawingMethod::UNDEFINED;
1496 aActForeColor=ReadRGBColor();
1497 eActMethod = PictDrawingMethod::UNDEFINED;
1502 aActBackColor=ReadRGBColor();
1503 eActMethod = PictDrawingMethod::UNDEFINED;
1524 aPoint=ReadPoint(); aPenPosition=ReadPoint();
1530 if (IsInvisible( PictDrawingMethod::FRAME ))
break;
1531 DrawingMethod( PictDrawingMethod::FRAME );
1536 aPoint=aPenPosition; aPenPosition=ReadPoint();
1542 if (IsInvisible( PictDrawingMethod::FRAME ))
break;
1543 DrawingMethod( PictDrawingMethod::FRAME );
1549 aPenPosition=ReadDeltaH(aPoint);
1550 aPenPosition=ReadDeltaV(aPenPosition);
1556 if ( IsInvisible(PictDrawingMethod::FRAME) )
break;
1557 DrawingMethod( PictDrawingMethod::FRAME );
1562 aPoint=aPenPosition;
1563 aPenPosition=ReadDeltaH(aPoint);
1564 aPenPosition=ReadDeltaV(aPenPosition);
1570 if (IsInvisible( PictDrawingMethod::FRAME ))
break;
1571 DrawingMethod( PictDrawingMethod::FRAME );
1580 sal_uInt16 nUSHORT(0);
1582 nDataSize=2+nUSHORT;
1586 aTextPosition=ReadPoint();
1587 nDataSize=4+ReadAndDrawText();
1591 aTextPosition=ReadUnsignedDeltaH(aTextPosition);
1592 nDataSize=1+ReadAndDrawText();
1596 aTextPosition=ReadUnsignedDeltaV(aTextPosition);
1597 nDataSize=1+ReadAndDrawText();
1601 aTextPosition=ReadUnsignedDeltaH(aTextPosition);
1602 aTextPosition=ReadUnsignedDeltaV(aTextPosition);
1603 nDataSize=2+ReadAndDrawText();
1607 sal_uInt16 nUSHORT(0);
1608 pPict->
ReadUInt16( nUSHORT ); nDataSize=nUSHORT+2;
1610 if (nUSHORT <= 1) aActFont.
SetFamily(FAMILY_SWISS);
1611 else if (nUSHORT <= 12) aActFont.
SetFamily(FAMILY_DECORATIVE);
1612 else if (nUSHORT <= 20) aActFont.
SetFamily(FAMILY_ROMAN);
1613 else if (nUSHORT == 21) aActFont.
SetFamily(FAMILY_SWISS);
1614 else if (nUSHORT == 22) aActFont.
SetFamily(FAMILY_MODERN);
1615 else if (nUSHORT <= 1023) aActFont.
SetFamily(FAMILY_SWISS);
1617 aActFont.
SetCharSet(GetTextEncoding(nUSHORT));
1620 sal_uInt16 nLen =
static_cast<sal_uInt16
>(nByteLen)&0x00ff;
1622 sFName[pPict->
ReadBytes(sFName, nLen)] = 0;
1623 OUString aString( sFName, strlen(sFName), osl_getThreadTextEncoding() );
1625 eActMethod = PictDrawingMethod::UNDEFINED;
1634 sal_uInt16 nUSHORT(0);
1636 nDataSize=2+nUSHORT;
1641 sal_uInt16 nUSHORT(0);
1643 nDataSize=2+nUSHORT;
1651 nDataSize=ReadAndDrawRect(shapeDMethod);
1665 nDataSize=ReadAndDrawSameRect(shapeDMethod);
1679 nDataSize=ReadAndDrawRoundRect(shapeDMethod);
1693 nDataSize=ReadAndDrawSameRoundRect(shapeDMethod);
1707 nDataSize=ReadAndDrawOval(shapeDMethod);
1721 nDataSize=ReadAndDrawSameOval(shapeDMethod);
1735 nDataSize=ReadAndDrawArc(shapeDMethod);
1749 nDataSize=ReadAndDrawSameArc(shapeDMethod);
1763 nDataSize=ReadAndDrawPolygon(shapeDMethod);
1770 sal_uInt16 nUSHORT(0);
1771 pPict->
ReadUInt16( nUSHORT ); nDataSize=nUSHORT;
1779 nDataSize=ReadAndDrawSamePolygon(shapeDMethod);
1793 nDataSize=ReadAndDrawRgn(shapeDMethod);
1800 sal_uInt16 nUSHORT(0);
1801 pPict->
ReadUInt16( nUSHORT ); nDataSize=nUSHORT;
1809 nDataSize=ReadAndDrawSameRgn(shapeDMethod);
1821 nDataSize=ReadPixMapEtc(aBmp,
false,
true, &aSrcRect, &aDestRect,
true,
false);
1822 DrawingMethod( PictDrawingMethod::PAINT );
1829 nDataSize=ReadPixMapEtc(aBmp,
false,
true, &aSrcRect, &aDestRect,
true,
true);
1830 DrawingMethod( PictDrawingMethod::PAINT );
1841 sal_uInt16 nUSHORT(0);
1842 pPict->
ReadUInt16( nUSHORT ); nDataSize=2+nUSHORT;
1848 nDataSize=ReadPixMapEtc(aBmp,
false,
true, &aSrcRect, &aDestRect,
true,
false);
1849 DrawingMethod( PictDrawingMethod::PAINT );
1856 nDataSize=ReadPixMapEtc(aBmp,
false,
true, &aSrcRect, &aDestRect,
true,
true);
1857 DrawingMethod( PictDrawingMethod::PAINT );
1864 nDataSize=ReadPixMapEtc(aBmp,
true,
false, &aSrcRect, &aDestRect,
true,
false);
1865 DrawingMethod( PictDrawingMethod::PAINT );
1872 nDataSize=ReadPixMapEtc(aBmp,
true,
false, &aSrcRect, &aDestRect,
true,
true);
1873 DrawingMethod( PictDrawingMethod::PAINT );
1882 sal_uInt16 nUSHORT(0);
1883 pPict->
ReadUInt16( nUSHORT ); nDataSize=2+nUSHORT;
1892 sal_uInt16 nUSHORT(0);
1897 sal_uInt16 nUSHORT(0);
1898 if (nOpcode<=0x00af) { pPict->
ReadUInt16( nUSHORT ); nDataSize=2+nUSHORT; }
1899 else if (nOpcode<=0x00cf) { nDataSize=0; }
1900 else if (nOpcode<=0x00fe) { sal_uInt32 nTemp(0); pPict->
ReadUInt32(nTemp) ; nDataSize = nTemp; nDataSize+=4; }
1903 else if (nOpcode==0x00ff) { nDataSize=IsVersion2 ? 2 : 0; }
1904 else if (nOpcode<=0x01ff) { nDataSize=2; }
1905 else if (nOpcode<=0x0bfe) { nDataSize=4; }
1906 else if (nOpcode<=0x0bff) { nDataSize=22; }
1907 else if (nOpcode==0x0c00) { nDataSize=24; }
1908 else if (nOpcode<=0x7eff) { nDataSize=24; }
1909 else if (nOpcode<=0x7fff) { nDataSize=254; }
1910 else if (nOpcode<=0x80ff) { nDataSize=0; }
1911 else { sal_uInt32 nTemp(0); pPict->
ReadUInt32(nTemp) ; nDataSize = nTemp; nDataSize+=4; }
1914 if (nDataSize==0xffffffff) {
1915 pPict->
SetError(SVSTREAM_FILEFORMAT_ERROR);
1928 pPict = &rStreamPict;
1929 nOrigPos = pPict->
Tell();
1934 nActPenSize =
Size(1,1);
1936 eActMethod = PictDrawingMethod::UNDEFINED;
1937 aActOvalSize =
Size(1,1);
1948 rGDIMetaFile.
Record(pVirDev);
1954 aPenPosition=
Point(-aBoundingRect.
Left(),-aBoundingRect.
Top());
1955 aTextPosition=aPenPosition;
1966 nOpcode=
static_cast<sal_uInt16
>(nOneByteOpcode);
1974 pPict->
SetError(SVSTREAM_FILEFORMAT_ERROR);
1978 if (nOpcode==0x00ff)
1981 nSize=ReadData(nOpcode);
1995 pPict->
SetError(SVSTREAM_FILEFORMAT_ERROR);
2001 rGDIMetaFile.
Stop();
2012 rStreamPict.
SetError(SVSTREAM_FILEFORMAT_ERROR);
2018 PictReader aPictReader;
2019 aPictReader.ReadPict(rStreamPict, rGDIMetaFile);
static BitmapColor getColor(const BitmapReadAccess *pReadAcc, tools::Long nZ)
sal_uInt8 GetBlue() const
sal_uInt8 GetGreen() const
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
void EnableOutput(bool bEnable=true)
void SetFont(const vcl::Font &rNewFont)
void SetRasterOp(RasterOp eRasterOp)
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
constexpr tools::Long Y() const
constexpr tools::Long X() const
virtual void ResetError()
void SetEndian(SvStreamEndian SvStreamEndian)
SvStream & ReadInt16(sal_Int16 &rInt16)
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
SvStreamEndian GetEndian() const
void SetError(ErrCode nErrorCode)
SvStream & ReadChar(char &rChar)
sal_uInt64 Seek(sal_uInt64 nPos)
SvStream & ReadInt32(sal_Int32 &rInt32)
std::size_t ReadBytes(void *pData, std::size_t nSize)
sal_uInt64 SeekRel(sal_Int64 nPos)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
sal_uInt64 remainingSize()
SvStream & ReadUChar(unsigned char &rChar)
static VclPtr< reference_type > Create(Arg &&... arg)
A construction helper for VclPtr.
void SetFontSize(const Size &)
void SetOutline(bool bOutline)
void SetTransparent(bool bTransparent)
void SetFillColor(const Color &)
void SetColor(const Color &)
void SetItalic(FontItalic)
void SetWeight(FontWeight)
void SetFamily(FontFamily)
void SetUnderline(FontLineStyle)
void SetCharSet(rtl_TextEncoding)
void SetAlignment(TextAlign)
void SetFamilyName(const OUString &rFamilyName)
rtl_TextEncoding GetCharSet() const
void SetShadow(bool bShadow)
Intended to be used to feed into CreateFromData to create a BitmapEx.
void SetPixel(tools::Long nY, tools::Long nX, Color nColor)
constexpr ::Color COL_LIGHTRED(0xFF, 0x00, 0x00)
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_LIGHTCYAN(0x00, 0xFF, 0xFF)
constexpr ::Color COL_LIGHTMAGENTA(0xFF, 0x00, 0xFF)
constexpr ::Color COL_YELLOW(0xFF, 0xFF, 0x00)
constexpr ::Color COL_LIGHTGRAY(0xC0, 0xC0, 0xC0)
constexpr ::Color COL_LIGHTBLUE(0x00, 0x00, 0xFF)
constexpr ::Color COL_LIGHTGREEN(0x00, 0xFF, 0x00)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
Reference< XOutputStream > stream
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)
void ReadPictFile(SvStream &rStreamPict, GDIMetaFile &rGDIMetaFile)
Function to access PictReader::ReadPict for unit testing.
static const char * operationName(sal_uInt16 nOpcode)
enum BrushStyle brushStyle
bool ImportPictGraphic(SvStream &rIStm, Graphic &rGraphic)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
RttiCompleteObjectLocator col
void drawRectangle(VirtualDevice *dev, bool drawFrame, tools::Rectangle const &orig, Size const &pSize)
draws a rectangle knowing penSize
void drawEllipse(VirtualDevice *dev, bool drawFrame, tools::Rectangle const &orig, Size const &pSize)
draws an ellipse knowing penSize
void drawLine(VirtualDevice *dev, Point const &orig, Point const &dest, Size const &pSize)
draws a line from orig to dest knowing penSize
void drawArc(VirtualDevice *dev, bool drawFrame, tools::Rectangle const &orig, const double &angle1, const double &angle2, Size const &pSize)
draws an arc in a b2dpolygon knowing penSize
void drawPolygon(VirtualDevice *dev, bool drawFrame, tools::Polygon const &orig, Size const &pSize)
draws a polygon knowing penSize
void drawRoundRectangle(VirtualDevice *dev, bool drawFrame, tools::Rectangle const &orig, Size const &ovalSize, Size const &pSize)
draws a rounded rectangle knowing penSize
constexpr double deg2rad(double v)
void SetLineColor(const css::uno::Reference< css::beans::XPropertySet > &xGridProperties, sal_Int32 nColor)
void ReadHeader(SvStream &rStream, ODbaseIndex::NDXHeader &rHeader)
constexpr double alpha[nDetails]
BitmapEx CreateFromData(sal_uInt8 const *pData, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int32 nStride, sal_Int8 nBitCount, bool bReversColors, bool bReverseAlpha)
Copy block of image data into the bitmap.
TOOLS_DLLPUBLIC bool checkSeek(SvStream &rSt, sal_uInt64 nOffset)