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 std::string_view chunk(
reinterpret_cast<const char*
>(pDest), nLen);
507 aString +=
" Title:" + OStringToOUString(chunk, RTL_TEXTENCODING_ASCII_US) +
"\n";
512 nRemainingBytes = pDest ? (nBytesRead - (pDest - pBuf)) : 0;
513 if (nRemainingBytes >= 10)
516 nRemainingBytes -= 10;
517 if (nRemainingBytes && *pDest ==
' ')
522 nLen =
ImplGetLen(pDest, std::min<sal_uInt32>(nRemainingBytes, 32));
525 std::string_view chunk(
reinterpret_cast<const char*
>(pDest), nLen);
526 aString +=
" Creator:" + OStringToOUString(chunk, RTL_TEXTENCODING_ASCII_US) +
"\n";
530 nRemainingBytes = pDest ? (nBytesRead - (pDest - pBuf)) : 0;
531 if (nRemainingBytes >= 15)
534 nRemainingBytes -= 15;
535 if (nRemainingBytes && *pDest ==
' ')
540 nLen =
ImplGetLen(pDest, std::min<sal_uInt32>(nRemainingBytes, 32));
543 std::string_view chunk(
reinterpret_cast<const char*
>(pDest), nLen);
546 aString +=
" CreationDate:" + OStringToOUString(chunk, RTL_TEXTENCODING_ASCII_US) +
"\n";
551 nRemainingBytes = pDest ? (nBytesRead - (pDest - pBuf)) : 0;
552 if (nRemainingBytes >= 16)
555 nRemainingBytes -= 16;
556 sal_uInt32
nCount = std::min<sal_uInt32>(nRemainingBytes, 4U);
558 if (
nCount && nNumber < 10)
560 aString +=
" LanguageLevel:" + OUString::number( nNumber );
581 bool bRetValue =
false;
582 bool bHasPreview =
false;
583 sal_uInt32 nSignature = 0, nPSStreamPos, nPSSize = 0;
584 sal_uInt32 nSizeWMF = 0;
585 sal_uInt32 nPosWMF = 0;
586 sal_uInt32 nSizeTIFF = 0;
587 sal_uInt32 nPosTIFF = 0;
589 auto nOrigPos = nPSStreamPos = rStream.
Tell();
592 rStream.
SetEndian( SvStreamEndian::LITTLE );
594 if ( nSignature == 0xc6d3d0c5 )
602 if (nPosWMF &&
checkSeek(rStream, nOrigPos + nPosWMF))
605 bHasPreview = bRetValue =
true;
614 if (nPosTIFF && nSizeTIFF &&
checkSeek(rStream, nOrigPos + nPosTIFF))
619 rStream.
Seek( nOrigPos + nPosTIFF );
620 bHasPreview = bRetValue =
true;
627 nPSStreamPos = nOrigPos;
631 std::vector<sal_uInt8> aHeader(22, 0);
632 rStream.
Seek( nPSStreamPos );
639 rStream.
Seek(nPSStreamPos);
641 SAL_WARN_IF(!bOk,
"filter.eps",
"eps claims to be: " << nPSSize <<
" in size, but only " << rStream.
remainingSize() <<
" remains");
645 sal_uInt32 nBufStartPos = rStream.
Tell();
649 sal_uInt32 nBytesRead =
aBuf.getSize();
650 sal_uInt32 nSecurityCount = 32;
653 if (!bHasPreview && nBytesRead >= nSecurityCount)
656 sal_uInt32 nRemainingBytes = pDest ? (nBytesRead - (pDest -
aBuf.getData())) : 0;
657 if (nRemainingBytes >= 15)
660 nSecurityCount = nRemainingBytes - 15;
666 bOk = pDest && nWidth > 0 && nHeight > 0 && ( ( nBitDepth == 1 ) || ( nBitDepth == 8 ) ) && nScanLines;
674 rStream.
Seek( nBufStartPos + ( pDest -
aBuf.getData() ) );
678 bool bIsValid =
true;
686 if ( --nBitsLeft < 0 )
688 while ( bIsValid && ( nBitsLeft != 7 ) )
691 bIsValid = rStream.
good();
697 if ( --nScanLines < 0 )
712 nByte -= (
'A' - 10 );
720 nDat |= ( nByte ^ 0xf );
731 if ( nBitDepth == 1 )
744 Size aSize( nWidth, nHeight );
745 pVDev->EnableOutput(
false );
754 bHasPreview = bRetValue =
true;
762 sal_uInt32 nRemainingBytes = pDest ? (nBytesRead - (pDest -
aBuf.getData())) : 0;
763 if (nRemainingBytes >= 14)
766 nSecurityCount = std::min<sal_uInt32>(nRemainingBytes - 14, 100);
768 nNumb[0] = nNumb[1] = nNumb[2] = nNumb[3] = 0;
769 for (
int i = 0; (
i < 4 ) && nSecurityCount;
i++ )
773 bool bFail = nSecurityCount == 0;
779 if (!bFail && nWidth > 0 && nHeight > 0)
813 rStream.
Seek( nOrigPos );
static OutputDevice * GetDefaultDevice()
Get the default "device" (in this case the default window).
Container for the binary data, whose responsibility is to manage the make it as simple as possible to...
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)
bool ImportEpsGraphic(SvStream &rStream, Graphic &rGraphic)
static const sal_uInt8 * ImplSearchEntry(const sal_uInt8 *pSource, sal_uInt8 const *pDest, size_t nComp, size_t nSize)
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 void MakeAsMeta(Graphic &rGraphic)
static bool RenderAsBMPThroughGS(const sal_uInt8 *pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic)
static tools::Long ImplGetNumber(const sal_uInt8 *&rBuf, sal_uInt32 &nSecurityCount)
static void MakePreview(const sal_uInt8 *pBuf, sal_uInt32 nBytesRead, tools::Long nWidth, tools::Long nHeight, Graphic &rGraphic)
static void WriteFileInThread(void *wData)
static bool RenderAsBMP(const sal_uInt8 *pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic)
static int ImplGetLen(const sal_uInt8 *pBuf, int nMax)
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)