31#include <osl/process.h>
32#include <osl/file.hxx>
33#include <osl/thread.h>
34#include <rtl/byteseq.hxx>
56 while ( nComp-- >= nSize )
59 for (
i = 0;
i < nSize;
i++ )
61 if ( ( pSource[
i]&~0x20 ) != ( pDest[
i]&~0x20 ) )
76 bool bNegative =
false;
78 while (nSecurityCount && (*rBuf ==
' ' || *rBuf == 0x9))
83 while ( nSecurityCount && ( *rBuf !=
' ' ) && ( *rBuf != 0x9 ) && ( *rBuf != 0xd ) && ( *rBuf != 0xa ) )
95 if ( ( *rBuf <
'0' ) || ( *rBuf >
'9' ) )
99 const bool bFail = o3tl::checked_multiply<tools::Long>(nRetValue, 10, nRetValue) ||
100 o3tl::checked_add<tools::Long>(nRetValue, *rBuf -
'0', nRetValue);
110 nRetValue = -nRetValue;
118 while( nLen != nMax )
121 if ( nDat == 0x0a || nDat == 0x25 )
141 pVDev->EnableOutput(
false );
152 rtl_uString* pArgs[], sal_uInt32 nArgs, oslProcess *pProcess,
153 oslFileHandle *pIn, oslFileHandle *pOut, oslFileHandle *pErr)
155 oslProcessError
result = osl_Process_E_None;
156 oslSecurity pSecurity = osl_getCurrentSecurity();
174 OUString path(o3tl::toU(_wgetenv(L
"PATH")));
176 oslFileError
err = osl_searchFileURL(rProgName.pData, path.pData, &url.pData);
177 if (
err != osl_File_E_None)
178 result = osl_Process_E_NotFound;
180 result = osl_executeProcess_WithRedirectedIO(url.pData,
181 pArgs, nArgs, osl_Process_HIDDEN,
182 pSecurity,
nullptr,
nullptr, 0, pProcess, pIn,
pOut, pErr);
184 result = osl_executeProcess_WithRedirectedIO(rProgName.pData,
185 pArgs, nArgs, osl_Process_SEARCHPATH | osl_Process_HIDDEN,
186 pSecurity,
nullptr,
nullptr, 0, pProcess, pIn,
pOut, pErr);
188 osl_freeSecurityHandle( pSecurity );
193# define EXESUFFIX ".exe"
205 osl::FileBase::getSystemPathFromFileURL(aTempOutput.
GetURL(), output);
207 osl::FileBase::getSystemPathFromFileURL(aTempInput.
GetURL(), input);
228 OUString arg1(
"-usebbfrominput");
230 OUString arg3(
"emf:-OO -drawbb -nfw");
232 rtl_uString *
args[] =
234 arg1.pData, arg2.pData, arg3.pData, input.pData, output.pData
237 oslFileHandle pIn =
nullptr;
238 oslFileHandle
pOut =
nullptr;
239 oslFileHandle pErr =
nullptr;
243 &aProcess, &pIn, &
pOut, &pErr);
245 if (eErr!=osl_Process_E_None)
249 if (pIn) osl_closeFile(pIn);
250 osl_joinProcess(aProcess);
251 osl_freeProcessHandle(aProcess);
252 bool bEMFSupported=
true;
255 rtl::ByteSequence seq;
256 if (osl_File_E_None == osl_readLine(
pOut,
reinterpret_cast<sal_Sequence **
>(&seq)))
258 OString
line(
reinterpret_cast<const char *
>(seq.getConstArray()), seq.getLength() );
259 if (
line.startsWith(
"Unsupported output format"))
264 if (pErr) osl_closeFile(pErr);
265 if (
nCount == nBytesRead && bEMFSupported)
281 sal_uInt32 m_nBytesToWrite;
291 WriteData *wdata =
static_cast<WriteData *
>(wData);
292 osl_writeFile(wdata->m_pFile, wdata->m_pBuf, wdata->m_nBytesToWrite, &
nCount);
300 if (wdata->m_pFile) osl_closeFile(wdata->m_pFile);
307 std::initializer_list<std::u16string_view> aProgNames,
308 rtl_uString* pArgs[],
size_t nArgs)
310 oslProcess aProcess =
nullptr;
311 oslFileHandle pIn =
nullptr;
312 oslFileHandle
pOut =
nullptr;
313 oslFileHandle pErr =
nullptr;
314 oslProcessError eErr = osl_Process_E_Unknown;
315 for (
const auto& rProgName : aProgNames)
318 if (eErr == osl_Process_E_None)
321 if (eErr!=osl_Process_E_None)
327 Data.m_nBytesToWrite = nBytesRead;
336 while (eFileErr == osl_File_E_None &&
nCount)
353 if (pErr) osl_closeFile(pErr);
354 osl_joinProcess(aProcess);
355 osl_freeProcessHandle(aProcess);
356 osl_joinWithThread(hThread);
357 osl_destroyThread(hThread);
365 OUString arg1(
"-density");
368 OUString arg2(
"300x300");
370 OUString arg3(
"eps:-");
372 OUString arg4(
"bmp:-");
373 rtl_uString *
args[] =
375 arg1.pData, arg2.pData, arg3.pData, arg4.pData
387 OUString arg2(
"-dBATCH");
388 OUString arg3(
"-dNOPAUSE");
389 OUString arg4(
"-dPARANOIDSAFER");
390 OUString arg5(
"-dEPSCrop");
391 OUString arg6(
"-dTextAlphaBits=4");
392 OUString arg7(
"-dGraphicsAlphaBits=4");
393 OUString arg8(
"-r300x300");
394 OUString arg9(
"-sDEVICE=bmp16m");
395 OUString arg10(
"-sOutputFile=-");
397 rtl_uString *
args[] =
399 arg1.pData, arg2.pData, arg3.pData, arg4.pData, arg5.pData,
400 arg6.pData, arg7.pData, arg8.pData, arg9.pData, arg10.pData,
428 sal_uInt32 nPosWMF, sal_uInt32 nSizeWMF, sal_uInt32 nPosTIFF, sal_uInt32 nSizeTIFF )
430 OString aComment(
"EPSReplacementGraphic");
431 if ( nSizeWMF || nSizeTIFF )
433 std::vector<sal_uInt8> aWMFBuf;
436 aWMFBuf.resize(nSizeWMF);
439 nSizeWMF = aWMFBuf.size();
441 std::vector<sal_uInt8> aTIFFBuf;
444 aTIFFBuf.resize(nSizeTIFF);
447 nSizeTIFF = aTIFFBuf.size();
450 sal_uInt32
const nMagic = 0xc6d3d0c5;
451 sal_uInt32 nPPos = 28 + nSizeWMF + nSizeTIFF;
452 sal_uInt32 nWPos = nSizeWMF ? 28 : 0;
453 sal_uInt32 nTPos = nSizeTIFF ? 28 + nSizeWMF : 0;
459 aReplacement.
WriteBytes(aWMFBuf.data(), nSizeWMF);
460 aReplacement.
WriteBytes(aTIFFBuf.data(), nSizeTIFF);
475 pVDev->EnableOutput(
false );
477 pVDev->SetLineColor(
COL_RED );
478 pVDev->SetFillColor();
483 pVDev->SetFont( aFont );
486 pVDev->DrawRect( aRect );
491 sal_uInt32 nRemainingBytes = pDest ? (nBytesRead - (pDest - pBuf)) : 0;
492 if (nRemainingBytes >= 8)
495 nRemainingBytes -= 8;
496 if (nRemainingBytes && *pDest ==
' ')
501 nLen =
ImplGetLen(pDest, std::min<sal_uInt32>(nRemainingBytes, 32));
504 sal_uInt8 aOldValue(pDest[ nLen ]); pDest[ nLen ] = 0;
505 if ( strcmp(
reinterpret_cast<char*
>(pDest),
"none" ) != 0 )
507 const char* pStr =
reinterpret_cast<char*
>(pDest);
508 aString +=
" Title:" + OUString(pStr, strlen(pStr), RTL_TEXTENCODING_ASCII_US) +
"\n";
510 pDest[ nLen ] = aOldValue;
514 nRemainingBytes = pDest ? (nBytesRead - (pDest - pBuf)) : 0;
515 if (nRemainingBytes >= 10)
518 nRemainingBytes -= 10;
519 if (nRemainingBytes && *pDest ==
' ')
524 nLen =
ImplGetLen(pDest, std::min<sal_uInt32>(nRemainingBytes, 32));
527 sal_uInt8 aOldValue(pDest[nLen]); pDest[nLen] = 0;
528 const char* pStr =
reinterpret_cast<char*
>(pDest);
529 aString +=
" Creator:" + OUString(pStr, strlen(pStr), RTL_TEXTENCODING_ASCII_US) +
"\n";
530 pDest[nLen] = aOldValue;
534 nRemainingBytes = pDest ? (nBytesRead - (pDest - pBuf)) : 0;
535 if (nRemainingBytes >= 15)
538 nRemainingBytes -= 15;
539 if (nRemainingBytes && *pDest ==
' ')
544 nLen =
ImplGetLen(pDest, std::min<sal_uInt32>(nRemainingBytes, 32));
547 sal_uInt8 aOldValue(pDest[ nLen ]); pDest[ nLen ] = 0;
548 if ( strcmp(
reinterpret_cast<char*
>(pDest),
"none" ) != 0 )
550 aString +=
" CreationDate:" + OUString::createFromAscii(
reinterpret_cast<char*
>(pDest) ) +
"\n";
551 const char* pStr =
reinterpret_cast<char*
>(pDest);
552 aString +=
" CreationDate:" + OUString(pStr, strlen(pStr), RTL_TEXTENCODING_ASCII_US) +
"\n";
554 pDest[ nLen ] = aOldValue;
558 nRemainingBytes = pDest ? (nBytesRead - (pDest - pBuf)) : 0;
559 if (nRemainingBytes >= 16)
562 nRemainingBytes -= 16;
563 sal_uInt32
nCount = std::min<sal_uInt32>(nRemainingBytes, 4U);
565 if (
nCount && nNumber < 10)
567 aString +=
" LanguageLevel:" + OUString::number( nNumber );
588 bool bRetValue =
false;
589 bool bHasPreview =
false;
590 sal_uInt32 nSignature = 0, nPSStreamPos, nPSSize = 0;
591 sal_uInt32 nSizeWMF = 0;
592 sal_uInt32 nPosWMF = 0;
593 sal_uInt32 nSizeTIFF = 0;
594 sal_uInt32 nPosTIFF = 0;
596 auto nOrigPos = nPSStreamPos = rStream.
Tell();
599 rStream.
SetEndian( SvStreamEndian::LITTLE );
601 if ( nSignature == 0xc6d3d0c5 )
609 if (nPosWMF &&
checkSeek(rStream, nOrigPos + nPosWMF))
612 bHasPreview = bRetValue =
true;
621 if (nPosTIFF && nSizeTIFF &&
checkSeek(rStream, nOrigPos + nPosTIFF))
626 rStream.
Seek( nOrigPos + nPosTIFF );
627 bHasPreview = bRetValue =
true;
634 nPSStreamPos = nOrigPos;
638 std::vector<sal_uInt8> aHeader(22, 0);
639 rStream.
Seek( nPSStreamPos );
646 rStream.
Seek(nPSStreamPos);
648 SAL_WARN_IF(!bOk,
"filter.eps",
"eps claims to be: " << nPSSize <<
" in size, but only " << rStream.
remainingSize() <<
" remains");
652 std::unique_ptr<sal_uInt8[]> pBuf(
new sal_uInt8[ nPSSize ] );
654 sal_uInt32 nBufStartPos = rStream.
Tell();
655 sal_uInt32 nBytesRead = rStream.
ReadBytes(pBuf.get(), nPSSize);
656 if ( nBytesRead == nPSSize )
658 sal_uInt32 nSecurityCount = 32;
661 if (!bHasPreview && nBytesRead >= nSecurityCount)
664 sal_uInt32 nRemainingBytes = pDest ? (nBytesRead - (pDest - pBuf.get())) : 0;
665 if (nRemainingBytes >= 15)
668 nSecurityCount = nRemainingBytes - 15;
674 bOk = pDest && nWidth > 0 && nHeight > 0 && ( ( nBitDepth == 1 ) || ( nBitDepth == 8 ) ) && nScanLines;
682 rStream.
Seek( nBufStartPos + ( pDest - pBuf.get() ) );
686 bool bIsValid =
true;
694 if ( --nBitsLeft < 0 )
696 while ( bIsValid && ( nBitsLeft != 7 ) )
699 bIsValid = rStream.
good();
705 if ( --nScanLines < 0 )
720 nByte -= (
'A' - 10 );
728 nDat |= ( nByte ^ 0xf );
739 if ( nBitDepth == 1 )
752 Size aSize( nWidth, nHeight );
753 pVDev->EnableOutput(
false );
762 bHasPreview = bRetValue =
true;
770 sal_uInt32 nRemainingBytes = pDest ? (nBytesRead - (pDest - pBuf.get())) : 0;
771 if (nRemainingBytes >= 14)
774 nSecurityCount = std::min<sal_uInt32>(nRemainingBytes - 14, 100);
776 nNumb[0] = nNumb[1] = nNumb[2] = nNumb[3] = 0;
777 for (
int i = 0; (
i < 4 ) && nSecurityCount;
i++ )
781 bool bFail = nSecurityCount == 0;
787 if (!bFail && nWidth > 0 && nHeight > 0)
794 bHasPreview =
RenderAsEMF(pBuf.get(), nBytesRead, aGraphic);
796 bHasPreview =
RenderAsBMP(pBuf.get(), nBytesRead, aGraphic);
802 MakePreview(pBuf.get(), nBytesRead, nWidth, nHeight,
821 rStream.
Seek( nOrigPos );
static OutputDevice * GetDefaultDevice()
Get the default "device" (in this case the default window).
static ErrCode Import(SvStream &rIStm, Graphic &rGraphic, ConvertDataFormat nFormat=ConvertDataFormat::Unknown)
const GDIMetaFile & GetGDIMetaFile() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
MapMode GetPrefMapMode() const
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
std::size_t GetEndOfData() const
void SetEndian(SvStreamEndian SvStreamEndian)
std::size_t WriteBytes(const void *pData, std::size_t nSize)
SvStream & WriteUInt32(sal_uInt32 nUInt32)
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
SvStreamEndian GetEndian() const
SvStream & ReadChar(char &rChar)
sal_uInt64 Seek(sal_uInt64 nPos)
std::size_t ReadBytes(void *pData, std::size_t nSize)
sal_uInt64 remainingSize()
void EnableKillingFile(bool bEnable=true)
SvStream * GetStream(StreamMode eMode)
OUString const & GetURL() const
void SetColor(const Color &)
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_RED(0x80, 0x00, 0x00)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
std::unique_ptr< ::osl::File > m_pFile
static bool RenderAsBMPThroughHelper(const sal_uInt8 *pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic, std::initializer_list< std::u16string_view > aProgNames, rtl_uString *pArgs[], size_t nArgs)
static bool RenderAsEMF(const sal_uInt8 *pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic)
static sal_uInt8 * ImplSearchEntry(sal_uInt8 *pSource, sal_uInt8 const *pDest, size_t nComp, size_t nSize)
static void MakePreview(sal_uInt8 *pBuf, sal_uInt32 nBytesRead, tools::Long nWidth, tools::Long nHeight, Graphic &rGraphic)
bool ImportEpsGraphic(SvStream &rStream, Graphic &rGraphic)
static oslProcessError runProcessWithPathSearch(const OUString &rProgName, rtl_uString *pArgs[], sal_uInt32 nArgs, oslProcess *pProcess, oslFileHandle *pIn, oslFileHandle *pOut, oslFileHandle *pErr)
static void CreateMtfReplacementAction(GDIMetaFile &rMtf, SvStream &rStrm, sal_uInt32 nOrigPos, sal_uInt32 nPSSize, sal_uInt32 nPosWMF, sal_uInt32 nSizeWMF, sal_uInt32 nPosTIFF, sal_uInt32 nSizeTIFF)
static int ImplGetLen(sal_uInt8 *pBuf, int nMax)
static void MakeAsMeta(Graphic &rGraphic)
static bool RenderAsBMPThroughGS(const sal_uInt8 *pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic)
static tools::Long ImplGetNumber(sal_uInt8 *&rBuf, sal_uInt32 &nSecurityCount)
static void WriteFileInThread(void *wData)
static bool RenderAsBMP(const sal_uInt8 *pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic)
static bool RenderAsBMPThroughConvert(const sal_uInt8 *pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_N_ELEMENTS(arr)
std::enable_if< std::is_signed< T >::value, bool >::type checked_add(T a, T b, T &result)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
std::enable_if< std::is_signed< T >::value, bool >::type checked_multiply(T a, T b, T &result)
std::enable_if< std::is_signed< T >::value, bool >::type checked_sub(T a, T b, T &result)
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.
#define STREAM_SEEK_TO_END
TOOLS_DLLPUBLIC bool checkSeek(SvStream &rSt, sal_uInt64 nOffset)