mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-19 03:33:06 +08:00
Merge remote-tracking branch 'origin/develop' into feature/pdfwriter
# Conflicts: # PdfReader/PdfReader.cpp # PdfWriter/Src/Encrypt.cpp
This commit is contained in:
@ -73,6 +73,12 @@ EM_JS(int, js_free_id, (unsigned char* data), {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define OO_INLINE __forceinline
|
||||
#else
|
||||
#define OO_INLINE inline
|
||||
#endif
|
||||
|
||||
class CMemoryFontStream
|
||||
{
|
||||
public:
|
||||
@ -1097,6 +1103,8 @@ namespace PdfReader
|
||||
oFile.WriteFile((BYTE*)pData14, nSize14);
|
||||
oFile.CloseFile();
|
||||
wsFileName = wsTempFileName;
|
||||
|
||||
eFontType = fontTrueType;
|
||||
}
|
||||
#else
|
||||
else if ([&oMemoryFontStream, wsFontBaseName]()
|
||||
@ -1439,6 +1447,7 @@ namespace PdfReader
|
||||
case fontType1C:
|
||||
case fontType1COT:
|
||||
{
|
||||
Gfx8BitFont* pFont8bit = NULL;
|
||||
if (fofiType == fofiIdTrueType)
|
||||
{
|
||||
#ifdef FONTS_USE_ONLY_MEMORY_STREAMS
|
||||
@ -1461,9 +1470,9 @@ namespace PdfReader
|
||||
nLen = 0;
|
||||
}
|
||||
}
|
||||
else if (L"" != wsFileName)
|
||||
{
|
||||
char **ppEncoding = ((Gfx8BitFont *)pFont)->getEncoding();
|
||||
else if (L"" != wsFileName && (pFont8bit = dynamic_cast<Gfx8BitFont*>(pFont)) && pFont8bit->getHasEncoding())
|
||||
{
|
||||
char **ppEncoding = pFont8bit->getEncoding();
|
||||
if (!ppEncoding)
|
||||
break;
|
||||
|
||||
@ -1491,12 +1500,13 @@ namespace PdfReader
|
||||
}
|
||||
case fontTrueType:
|
||||
case fontTrueTypeOT:
|
||||
{
|
||||
if (fofiType == fofiIdType1PFB)
|
||||
{
|
||||
if (L"" != wsFileName)
|
||||
{
|
||||
if (fofiType == fofiIdType1PFB)
|
||||
{
|
||||
Gfx8BitFont* pFont8bit = dynamic_cast<Gfx8BitFont*>(pFont);
|
||||
if (L"" != wsFileName && pFont8bit && pFont8bit->getHasEncoding())
|
||||
{
|
||||
char **ppEncoding = ((Gfx8BitFont *)pFont)->getEncoding();
|
||||
char **ppEncoding = pFont8bit->getEncoding();
|
||||
if (!ppEncoding)
|
||||
break;
|
||||
|
||||
@ -1513,7 +1523,7 @@ namespace PdfReader
|
||||
{
|
||||
pCodeToGID[nIndex] = 0;
|
||||
char* sName = NULL;
|
||||
if ((sName = ppEncoding[nIndex]))
|
||||
if ((sName = ppEncoding[nIndex]))
|
||||
{
|
||||
unsigned short ushGID = m_pFontManager->GetNameIndex(AStringToWString(sName));
|
||||
pCodeToGID[nIndex] = ushGID;
|
||||
@ -3644,6 +3654,9 @@ namespace PdfReader
|
||||
double dPageHeight = pGState->getPageHeight();
|
||||
|
||||
std::wstring wsUnicodeText;
|
||||
|
||||
bool isCIDFont = pFont->isCIDFont();
|
||||
|
||||
if (NULL != oEntry.pCodeToUnicode && nCode < oEntry.unLenUnicode)
|
||||
{
|
||||
unsigned short unUnicode = oEntry.pCodeToUnicode[nCode];
|
||||
@ -3651,7 +3664,7 @@ namespace PdfReader
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pGState->getFont()->isCIDFont())
|
||||
if (isCIDFont)
|
||||
{
|
||||
// Значит кодировка была Identity-H или Identity-V, что означает, что иходные коды и есть юникодные значения
|
||||
wsUnicodeText = (wchar_t(nCode));
|
||||
@ -3672,11 +3685,15 @@ namespace PdfReader
|
||||
else
|
||||
unGidsCount = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int nCurCode = (0 == nCode ? 65534 : nCode);
|
||||
unGid = (unsigned int)nCurCode;
|
||||
unGidsCount = 1;
|
||||
else
|
||||
{
|
||||
bool isIdentity = true;
|
||||
if (!isCIDFont || ((GfxCIDFont*)pFont)->usesIdentityEncoding())
|
||||
{
|
||||
int nCurCode = (0 == nCode ? 65534 : nCode);
|
||||
unGid = (unsigned int)nCurCode;
|
||||
unGidsCount = 1;
|
||||
}
|
||||
}
|
||||
|
||||
float fAscent = pGState->getFontSize();
|
||||
@ -3814,6 +3831,22 @@ namespace PdfReader
|
||||
DoTransform(arrMatrix, &dShiftX, &dShiftY, true);
|
||||
m_pRenderer->DrawImage(&oImage, 0 + dShiftX, 0 + dShiftY, PDFCoordsToMM(1), PDFCoordsToMM(1));
|
||||
}
|
||||
|
||||
OO_INLINE bool CheckMask(const int& nComponentsCount, const int* pMaskColors, const unsigned char* pLine)
|
||||
{
|
||||
bool isMask = true;
|
||||
for (int nCompIndex = 0; nCompIndex < nComponentsCount; ++nCompIndex)
|
||||
{
|
||||
if (pMaskColors[nCompIndex * 2] > pLine[nCompIndex] || pLine[nCompIndex] > pMaskColors[nCompIndex * 2 + 1])
|
||||
{
|
||||
isMask = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isMask;
|
||||
}
|
||||
|
||||
void RendererOutputDev::drawImage(GfxState *pGState, Object *pRef, Stream *pStream, int nWidth, int nHeight, GfxImageColorMap *pColorMap, int *pMaskColors, GBool bInlineImg, GBool interpolate)
|
||||
{
|
||||
if (m_bDrawOnlyText)
|
||||
@ -3829,52 +3862,76 @@ namespace PdfReader
|
||||
if (!pBufferPtr)
|
||||
return;
|
||||
|
||||
Aggplus::CImage oImage;
|
||||
oImage.Create(pBufferPtr, nWidth, nHeight, -4 * nWidth);
|
||||
|
||||
|
||||
int nComponentsCount = pColorMap->getNumPixelComps();
|
||||
|
||||
// Пишем данные в pBufferPtr
|
||||
ImageStream *pImageStream = new ImageStream(pStream, nWidth, nComponentsCount, pColorMap->getBits());
|
||||
|
||||
pImageStream->reset();
|
||||
|
||||
unsigned char unAlpha = m_bTransparentGroup ? 255.0 * pGState->getFillOpacity() : 255;
|
||||
|
||||
unsigned char unPixel[32] ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
for (int nY = nHeight - 1; nY >= 0; nY--)
|
||||
int nStride = pImageStream->getVals();
|
||||
int nComps = pImageStream->getComps();
|
||||
int nWidthMax = nStride / nComps;
|
||||
int nCheckWidth = std::min(nWidth, nWidthMax);
|
||||
|
||||
// fast realization for some colorspaces (for wasm module)
|
||||
int nColorMapType = pColorMap->getFillType();
|
||||
GfxColorComp** pColorMapLookup = pColorMap->getLookup();
|
||||
if (!pColorMapLookup)
|
||||
nColorMapType = 0;
|
||||
|
||||
for (int nY = nHeight - 1; nY >= 0; --nY)
|
||||
{
|
||||
for (int nX = 0; nX < nWidth; nX++)
|
||||
unsigned char* pLine = pImageStream->getLine();
|
||||
unsigned char* pLineDst = pBufferPtr + 4 * nWidth * nY;
|
||||
|
||||
if (!pLine)
|
||||
{
|
||||
int nIndex = 4 * (nX + nY * nWidth);
|
||||
pImageStream->getPixel(unPixel);
|
||||
memset(pLineDst, 0, 4 * nWidth);
|
||||
continue;
|
||||
}
|
||||
|
||||
GfxRGB oRGB;
|
||||
pColorMap->getRGB(unPixel, &oRGB, gfxRenderingIntentAbsoluteColorimetric);
|
||||
pBufferPtr[nIndex + 0] = colToByte(oRGB.b);
|
||||
pBufferPtr[nIndex + 1] = colToByte(oRGB.g);
|
||||
pBufferPtr[nIndex + 2] = colToByte(oRGB.r);
|
||||
pBufferPtr[nIndex + 3] = unAlpha;
|
||||
|
||||
if (pMaskColors)
|
||||
for (int nX = 0; nX < nCheckWidth; ++nX)
|
||||
{
|
||||
if (2 == nColorMapType)
|
||||
{
|
||||
bool isMask = true;
|
||||
for (int nCompIndex = 0; nCompIndex < nComponentsCount; ++nCompIndex)
|
||||
{
|
||||
if (pMaskColors[nCompIndex * 2] > unPixel[nCompIndex] || unPixel[nCompIndex] > pMaskColors[nCompIndex * 2 + 1])
|
||||
{
|
||||
isMask = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isMask)
|
||||
pBufferPtr[nIndex + 3] = 0;
|
||||
pLineDst[2] = colToByte(clip01(pColorMapLookup[0][pLine[0]]));
|
||||
pLineDst[1] = colToByte(clip01(pColorMapLookup[1][pLine[1]]));
|
||||
pLineDst[0] = colToByte(clip01(pColorMapLookup[2][pLine[2]]));
|
||||
}
|
||||
else if (1 == nColorMapType)
|
||||
{
|
||||
pLineDst[0] = pLineDst[1] = pLineDst[2] = colToByte(clip01(pColorMapLookup[0][pLine[0]]));
|
||||
}
|
||||
else
|
||||
{
|
||||
GfxRGB oRGB;
|
||||
pColorMap->getRGB(pLine, &oRGB, gfxRenderingIntentAbsoluteColorimetric);
|
||||
pLineDst[0] = colToByte(oRGB.b);
|
||||
pLineDst[1] = colToByte(oRGB.g);
|
||||
pLineDst[2] = colToByte(oRGB.r);
|
||||
}
|
||||
|
||||
if (pMaskColors && CheckMask(nComponentsCount, pMaskColors, pLine))
|
||||
pLineDst[3] = 0;
|
||||
else
|
||||
pLineDst[3] = unAlpha;
|
||||
|
||||
pLine += nComps;
|
||||
pLineDst += 4;
|
||||
}
|
||||
}
|
||||
|
||||
bool bIsFlip = false;
|
||||
#ifdef USE_EXTERNAL_JPEG2000
|
||||
if (pStream->getKind() == strJPX)
|
||||
bIsFlip = true;
|
||||
#endif
|
||||
|
||||
Aggplus::CImage oImage;
|
||||
oImage.Create(pBufferPtr, nWidth, nHeight, bIsFlip ? (4 * nWidth) : (-4 * nWidth));
|
||||
|
||||
delete pImageStream;
|
||||
|
||||
double arrMatrix[6];
|
||||
@ -3902,6 +3959,27 @@ namespace PdfReader
|
||||
if (nMaskWidth <= 0 || nMaskHeight <= 0)
|
||||
drawImage(pGState, pRef, pStream, nWidth, nHeight, pColorMap, NULL, false, interpolate);
|
||||
|
||||
if (nMaskWidth > nWidth || nMaskHeight > nHeight)
|
||||
{
|
||||
// If the mask is higher resolution than the image, use
|
||||
// drawSoftMaskedImage() instead.
|
||||
|
||||
GfxImageColorMap *maskColorMap;
|
||||
Object maskDecode, decodeLow, decodeHigh;
|
||||
|
||||
decodeLow.initInt(bMaskInvert ? 0 : 1);
|
||||
decodeHigh.initInt(bMaskInvert ? 1 : 0);
|
||||
maskDecode.initArray(m_pXref);
|
||||
maskDecode.arrayAdd(&decodeLow);
|
||||
maskDecode.arrayAdd(&decodeHigh);
|
||||
maskColorMap = new GfxImageColorMap(1, &maskDecode, new GfxDeviceGrayColorSpace());
|
||||
maskDecode.free();
|
||||
drawSoftMaskedImage(pGState, pRef, pStream, nWidth, nHeight,
|
||||
pColorMap, pStreamRef, pMaskStream, nMaskWidth, nMaskHeight, maskColorMap, NULL, interpolate);
|
||||
delete maskColorMap;
|
||||
return;
|
||||
}
|
||||
|
||||
double dPageHeight = pGState->getPageHeight();
|
||||
|
||||
int nBufferSize = 4 * nWidth * nHeight;
|
||||
@ -3935,11 +4013,11 @@ namespace PdfReader
|
||||
unsigned char unMask = 0;
|
||||
for (int nY = nMaskHeight - 1; nY >= 0; nY--)
|
||||
{
|
||||
int nIndex = nY * nMaskWidth;
|
||||
for (int nX = 0; nX < nMaskWidth; nX++)
|
||||
{
|
||||
int nIndex = nX + nY * nMaskWidth;
|
||||
pMask->getPixel(&unMask);
|
||||
pMaskBuffer[nIndex] = unMask;
|
||||
pMaskBuffer[nIndex++] = unMask;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3949,9 +4027,9 @@ namespace PdfReader
|
||||
unsigned char unPixel[4] ={ 0, 0, 0, 0 };
|
||||
for (int nY = nHeight - 1; nY >= 0; nY--)
|
||||
{
|
||||
int nIndex = 4 * nY * nWidth;
|
||||
for (int nX = 0; nX < nWidth; nX++)
|
||||
{
|
||||
int nIndex = 4 * (nX + nY * nWidth);
|
||||
pImageStream->getPixel(unPixel);
|
||||
|
||||
int nNearestY = (std::min)((int)(nY / dScaleHeight), nMaskHeight - 1);
|
||||
@ -3968,6 +4046,8 @@ namespace PdfReader
|
||||
pBufferPtr[nIndex + 3] = 0;
|
||||
else
|
||||
pBufferPtr[nIndex + 3] = 255;
|
||||
|
||||
nIndex += 4;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3979,9 +4059,9 @@ namespace PdfReader
|
||||
unsigned char unMask = 0;
|
||||
for (int nY = nHeight - 1; nY >= 0; nY--)
|
||||
{
|
||||
int nIndex = 4 * nY * nWidth;
|
||||
for (int nX = 0; nX < nWidth; nX++)
|
||||
{
|
||||
int nIndex = 4 * (nX + nY * nWidth);
|
||||
pImageStream->getPixel(unPixel);
|
||||
pMask->getPixel(&unMask);
|
||||
GfxRGB oRGB;
|
||||
@ -3994,6 +4074,8 @@ namespace PdfReader
|
||||
pBufferPtr[nIndex + 3] = 0;
|
||||
else
|
||||
pBufferPtr[nIndex + 3] = 255;
|
||||
|
||||
nIndex += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user