31 #include <osl/process.h>
32 #include <osl/file.hxx>
33 #include <osl/thread.h>
34 #include <rtl/byteseq.hxx>
39 #include <string_view>
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"
195 # define EXESUFFIX ""
205 osl::FileBase::getSystemPathFromFileURL(aTempOutput.
GetURL(), output);
207 osl::FileBase::getSystemPathFromFileURL(aTempInput.
GetURL(), input);
210 sal_uInt64
nCount = pInputStream->WriteBytes(pBuf, nBytesRead);
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;
335 oslFileError eFileErr = osl_readFile(pOut, aBuf, 32000, &nCount);
336 while (eFileErr == osl_File_E_None && nCount)
338 aMemStm.
WriteBytes(aBuf, sal::static_int_cast<std::size_t>(nCount));
339 eFileErr = osl_readFile(pOut, aBuf, 32000, &nCount);
352 if (pOut) osl_closeFile(pOut);
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);
437 aWMFBuf.resize(rStrm.
ReadBytes(aWMFBuf.data(), nSizeWMF));
439 nSizeWMF = aWMFBuf.size();
441 std::vector<sal_uInt8> aTIFFBuf;
444 aTIFFBuf.resize(nSizeTIFF);
445 aTIFFBuf.resize(rStrm.
ReadBytes(aTIFFBuf.data(), 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;
513 pDest =
ImplSearchEntry( pBuf, reinterpret_cast<sal_uInt8 const *>(
"%%Creator:"), nBytesRead - 32, 10 );
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;
533 pDest =
ImplSearchEntry( pBuf, reinterpret_cast<sal_uInt8 const *>(
"%%CreationDate:"), nBytesRead - 32, 15 );
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;
557 pDest =
ImplSearchEntry( pBuf, reinterpret_cast<sal_uInt8 const *>(
"%%LanguageLevel:"), nBytesRead - 4, 16 );
558 nRemainingBytes = pDest ? (nBytesRead - (pDest - pBuf)) : 0;
559 if (nRemainingBytes >= 16)
562 nRemainingBytes -= 16;
563 sal_uInt32
nCount = std::min<sal_uInt32>(nRemainingBytes, 4
U);
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 );
642 bool bOk =
ImplSearchEntry(pHeader, reinterpret_cast<sal_uInt8 const *>(
"%!PS-Adobe"), 10, 10) &&
643 ImplSearchEntry(pHeader + 15, reinterpret_cast<sal_uInt8 const *>(
"EPS"), 3, 3);
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;
673 pDest =
ImplSearchEntry(pDest, reinterpret_cast<sal_uInt8 const *>(
"%"), nSecurityCount, 1);
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 );
bool ImportEpsGraphic(SvStream &rStream, Graphic &rGraphic)
std::enable_if< std::is_signed< T >::value, bool >::type checked_sub(T a, T b, T &result)
static bool RenderAsBMPThroughGS(const sal_uInt8 *pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic)
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
constexpr::Color COL_RED(0x80, 0x00, 0x00)
#define STREAM_SEEK_TO_END
sal_uInt64 Seek(sal_uInt64 nPos)
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)
exports com.sun.star.xml. input
static OutputDevice * GetDefaultDevice()
Get the default "device" (in this case the default window).
constexpr tools::Long Width() const
std::size_t GetEndOfData() const
static void WriteFileInThread(void *wData)
const GDIMetaFile & GetGDIMetaFile() const
SvStream & WriteUInt32(sal_uInt32 nUInt32)
sal_uInt64 remainingSize()
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_LIGHTRED
#define SAL_N_ELEMENTS(arr)
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
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)
bool checkSeek(SvStream &rSt, sal_uInt64 nOffset)
OUString const & GetURL() const
static bool RenderAsBMP(const sal_uInt8 *pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic)
static void MakePreview(sal_uInt8 *pBuf, sal_uInt32 nBytesRead, tools::Long nWidth, tools::Long nHeight, Graphic &rGraphic)
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::size_t WriteBytes(const void *pData, std::size_t nSize)
std::enable_if< std::is_signed< T >::value, bool >::type checked_multiply(T a, T b, T &result)
static bool RenderAsBMPThroughConvert(const sal_uInt8 *pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic)
static tools::Long ImplGetNumber(sal_uInt8 *&rBuf, sal_uInt32 &nSecurityCount)
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
static ErrCode Import(SvStream &rIStm, Graphic &rGraphic, ConvertDataFormat nFormat=ConvertDataFormat::Unknown)
Intended to be used to feed into CreateFromData to create a BitmapEx.
static oslProcessError runProcessWithPathSearch(const OUString &rProgName, rtl_uString *pArgs[], sal_uInt32 nArgs, oslProcess *pProcess, oslFileHandle *pIn, oslFileHandle *pOut, oslFileHandle *pErr)
void SetColor(const Color &)
std::size_t ReadBytes(void *pData, std::size_t nSize)
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SvStreamEndian GetEndian() const
static void MakeAsMeta(Graphic &rGraphic)
SvStream & ReadChar(char &rChar)
#define SAL_WARN_IF(condition, area, stream)
MapMode GetPrefMapMode() const
constexpr tools::Long Height() const
void SetEndian(SvStreamEndian SvStreamEndian)
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
BitmapEx CreateFromData(sal_uInt8 const *pData, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int32 nStride, vcl::PixelFormat ePixelFormat, bool bReversColors, bool bReverseAlpha)
Copy block of image data into the bitmap.
std::unique_ptr< ::osl::File > m_pFile
static sal_uInt8 * ImplSearchEntry(sal_uInt8 *pSource, sal_uInt8 const *pDest, size_t nComp, size_t nSize)
static bool RenderAsEMF(const sal_uInt8 *pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic)
SvStream * GetStream(StreamMode eMode)
void SetPixel(tools::Long nY, tools::Long nX, Color nColor)
void EnableKillingFile(bool bEnable=true)
static int ImplGetLen(sal_uInt8 *pBuf, int nMax)