mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Fix getButtonIcons with base64 image
This commit is contained in:
@ -1003,7 +1003,7 @@ BYTE* CPdfReader::GetAPWidget(int nRasterW, int nRasterH, int nBackgroundColor,
|
||||
oRes.ClearWithoutAttack();
|
||||
return bRes;
|
||||
}
|
||||
BYTE* CPdfReader::GetButtonIcon(int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nButtonWidget, const char* sIconView)
|
||||
BYTE* CPdfReader::GetButtonIcon(int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, bool bBase64, int nButtonWidget, const char* sIconView)
|
||||
{
|
||||
if (!m_pPDFDocument || !m_pPDFDocument->getCatalog())
|
||||
return NULL;
|
||||
@ -1112,6 +1112,51 @@ BYTE* CPdfReader::GetButtonIcon(int nRasterW, int nRasterH, int nBackgroundColor
|
||||
oRes.AddInt(nHeight);
|
||||
oWidth.free(); oHeight.free();
|
||||
|
||||
if (bBase64)
|
||||
{
|
||||
int nLength = 0;
|
||||
Object oLength;
|
||||
if (oImDict->lookup("Length", &oLength)->isInt())
|
||||
nLength = oLength.getInt();
|
||||
oLength.free();
|
||||
if (oImDict->lookup("DL", &oLength)->isInt())
|
||||
nLength = oLength.getInt();
|
||||
oLength.free();
|
||||
|
||||
bool bNew = false;
|
||||
BYTE* pBuffer = NULL;
|
||||
Stream* pImage = oIm.getStream()->getUndecodedStream();
|
||||
pImage->reset();
|
||||
MemStream* pMemory = dynamic_cast<MemStream*>(pImage);
|
||||
if (pImage->getKind() == strWeird && pMemory)
|
||||
{
|
||||
if (pMemory->getBufPtr() + nLength == pMemory->getBufEnd())
|
||||
pBuffer = (BYTE*)pMemory->getBufPtr();
|
||||
else
|
||||
nLength = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
bNew = true;
|
||||
pBuffer = new BYTE[nLength];
|
||||
BYTE* pBufferPtr = pBuffer;
|
||||
for (int nI = 0; nI < nLength; ++nI)
|
||||
*pBufferPtr++ = (BYTE)pImage->getChar();
|
||||
}
|
||||
|
||||
char* cData64 = NULL;
|
||||
int nData64Dst = 0;
|
||||
NSFile::CBase64Converter::Encode(pBuffer, nLength, cData64, nData64Dst, NSBase64::B64_BASE64_FLAG_NOCRLF);
|
||||
|
||||
oRes.WriteString((BYTE*)cData64, nData64Dst);
|
||||
|
||||
nMKLength++;
|
||||
if (bNew)
|
||||
RELEASEARRAYOBJECTS(pBuffer);
|
||||
RELEASEARRAYOBJECTS(cData64);
|
||||
continue;
|
||||
}
|
||||
|
||||
BYTE* pBgraData = new BYTE[nWidth * nHeight * 4];
|
||||
unsigned int nColor = (unsigned int)nBackgroundColor;
|
||||
unsigned int nSize = (unsigned int)(nWidth * nHeight);
|
||||
@ -1333,13 +1378,32 @@ BYTE* CPdfReader::GetButtonIcon(int nRasterW, int nRasterH, int nBackgroundColor
|
||||
oStr.free(); oStrRef.free(); oResources.free();
|
||||
|
||||
nMKLength++;
|
||||
unsigned long long npSubMatrix = (unsigned long long)pBgraData;
|
||||
unsigned int npSubMatrix1 = npSubMatrix & 0xFFFFFFFF;
|
||||
oRes.AddInt(npSubMatrix1);
|
||||
oRes.AddInt(npSubMatrix >> 32);
|
||||
|
||||
if (bBase64)
|
||||
{
|
||||
BYTE* pPngBuffer = NULL;
|
||||
int nPngSize = 0;
|
||||
pFrame->Encode(pPngBuffer, nPngSize, 4);
|
||||
|
||||
char* cData64 = NULL;
|
||||
int nData64Dst = 0;
|
||||
NSFile::CBase64Converter::Encode(pPngBuffer, nPngSize, cData64, nData64Dst, NSBase64::B64_BASE64_FLAG_NOCRLF);
|
||||
|
||||
oRes.WriteString((BYTE*)cData64, nData64Dst);
|
||||
|
||||
RELEASEARRAYOBJECTS(cData64);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned long long npSubMatrix = (unsigned long long)pBgraData;
|
||||
unsigned int npSubMatrix1 = npSubMatrix & 0xFFFFFFFF;
|
||||
oRes.AddInt(npSubMatrix1);
|
||||
oRes.AddInt(npSubMatrix >> 32);
|
||||
|
||||
pFrame->ClearNoAttack();
|
||||
}
|
||||
|
||||
delete gfx;
|
||||
pFrame->ClearNoAttack();
|
||||
RELEASEOBJECT(pFrame);
|
||||
RELEASEOBJECT(pRenderer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user