Commit 320dce8d authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander Trofimov

Исправлены баги при отрисовке текста. Исправлены баги с обновлением...

Исправлены баги при отрисовке текста. Исправлены баги с обновлением DeviceContext в WMF. Добавлена обработка CharSet в wmf.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62364 954022d7-b5bf-4e40-9824-e11837661b57
parent eb320f77
......@@ -110,7 +110,6 @@ namespace MetaFile
oFrame.OpenFile(wsTempFileName);
// TODO: .
//::_wunlink(wsTempFileName.c_str());
NSFile::CFileBinary::Remove(wsTempFileName);
return false;
}
......@@ -122,10 +121,10 @@ namespace MetaFile
//
int lCalcLen = (((nWidth * ushPlanes * ushBitCount + 31) & ~31) / 8) * abs(nHeight);
if (lCalcLen != lBufLen)
if (lCalcLen > lBufLen)
return false;
pBgraBuffer = new BYTE[nWidth * nHeight * 4 * sizeof(BYTE)];
pBgraBuffer = new BYTE[nWidth * abs(nHeight) * 4 * sizeof(BYTE)];
if (NULL == pBgraBuffer)
return false;
......@@ -239,10 +238,10 @@ namespace MetaFile
}
int nScanLineBytes = (nWidth + nAdd) / 2;
if (lBufLen < (nScanLineBytes * nHeight))
if (lBufLen < (nScanLineBytes * abs(nHeight)))
return false;
pBgraBuffer = new BYTE[nWidth * nHeight * 4 * sizeof(BYTE)];
pBgraBuffer = new BYTE[nWidth * abs(nHeight) * 4 * sizeof(BYTE)];
if (NULL == pBgraBuffer)
return false;
......@@ -349,10 +348,10 @@ namespace MetaFile
nAdd++;
}
if (lBufLen < (nWidth + nAdd) * nHeight)
if (lBufLen < (nWidth + nAdd) * abs(nHeight))
return false;
pBgraBuffer = new BYTE[nWidth * nHeight * 4 * sizeof(BYTE)];
pBgraBuffer = new BYTE[nWidth * abs(nHeight) * 4 * sizeof(BYTE)];
if (NULL == pBgraBuffer)
return false;
......@@ -445,7 +444,7 @@ namespace MetaFile
nAdd++;
}
pBgraBuffer = new BYTE[nWidth * nHeight * 4 * sizeof(BYTE)];
pBgraBuffer = new BYTE[nWidth * abs(nHeight) * 4 * sizeof(BYTE)];
if (NULL == pBgraBuffer)
return false;
......@@ -522,7 +521,7 @@ namespace MetaFile
int nSize = nWidth * nHeight * 4;
pBgraBuffer = new BYTE[nWidth * nHeight * 4 * sizeof(BYTE)];
pBgraBuffer = new BYTE[nWidth * abs(nHeight) * 4 * sizeof(BYTE)];
if (NULL == pBgraBuffer)
return false;
......@@ -615,7 +614,7 @@ namespace MetaFile
int nSize = nWidth * nHeight * 4;
pBgraBuffer = new BYTE[(nWidth + nAdd) * nHeight * 4 * sizeof(BYTE)];
pBgraBuffer = new BYTE[(nWidth + nAdd) * abs(nHeight) * 4 * sizeof(BYTE)];
if (NULL == pBgraBuffer)
return false;
......@@ -732,6 +731,49 @@ namespace MetaFile
else // BitmapInfoHeader
ReadImageInfoHeader(pHeaderBuffer + 4, ulHeaderBufferLen - 4, pImageBuffer, ulImageBufferLen, ppDstBuffer, pulWidth, pulHeight);
}
void ReadImage(BYTE* pImageBuffer, unsigned int unBufferLen, unsigned int unColorUsage, BYTE** ppDstBuffer, unsigned int* punWidth, unsigned int* punHeight)
{
if (unBufferLen <= 0 || NULL == pImageBuffer)
return;
CDataStream oHeaderStream;
oHeaderStream.SetStream(pImageBuffer, unBufferLen);
//
unsigned int unHeaderSize;
oHeaderStream >> unHeaderSize;
if (unHeaderSize > unBufferLen)
return;
else if (unHeaderSize < 0x0000000C)
return;
else if (0x0000000C == unHeaderSize) // BitmapCoreHeader
ReadImageCoreHeader(pImageBuffer + 4, unHeaderSize - 4, pImageBuffer + unHeaderSize, unBufferLen - unHeaderSize, ppDstBuffer, punWidth, punHeight);
else // BitmapInfoHeader
{
unsigned short ushBitCount;
unsigned int unColorUsed;
oHeaderStream.Skip(10);
oHeaderStream >> ushBitCount;
oHeaderStream.Skip(16);
oHeaderStream >> unColorUsed;
if (DIB_RGB_COLORS == unColorUsage)
{
if (0 == unColorUsed && BI_BITCOUNT_1 == ushBitCount)
unColorUsed = 2;
else if (0 == unColorUsed && BI_BITCOUNT_3 == ushBitCount)
unColorUsed = 256;
unHeaderSize += 4 * unColorUsed; // RGBQuad
ReadImageInfoHeader(pImageBuffer + 4, unHeaderSize - 4, pImageBuffer + unHeaderSize, unBufferLen - unHeaderSize, ppDstBuffer, punWidth, punHeight);
}
else
{
// TODO:
}
}
}
double GetEllipseAngle(int nL, int nT, int nR, int nB, int nX, int nY)
{
double dX0 = (nL + nR) / 2.0;
......@@ -742,16 +784,16 @@ namespace MetaFile
if (nX >= dX0)
{
if (nY <= dY0)
nQuarter = 0;
else
nQuarter = 3;
else
nQuarter = 0;
}
else
{
if (nY <= dY0)
nQuarter = 1;
else
nQuarter = 2;
else
nQuarter = 1;
}
double dDist = sqrt((double)(nX - dX0) * (nX - dX0) + (nY - dY0) * (nY - dY0));
......@@ -767,4 +809,37 @@ namespace MetaFile
return dAngle;
}
void ProcessRasterOperation(unsigned int unRasterOperation, BYTE** ppBgra, unsigned int unWidth, unsigned int unHeight)
{
BYTE* pBgra = *ppBgra;
// SRCPAINT SRCAND , .
if (0x008800C6 == unRasterOperation) // SRCPAINT
{
BYTE* pCur = pBgra;
for (unsigned int unY = 0; unY < unHeight; unY++)
{
for (unsigned int unX = 0; unX < unWidth; unX++)
{
unsigned int unIndex = (unY * unWidth + unX) * 4;
if (0xff == pCur[unIndex + 0] && 0xff == pCur[unIndex + 1] && 0xff == pCur[unIndex + 2])
pCur[unIndex + 3] = 0;
}
}
}
else if (0x00EE0086 == unRasterOperation) // SRCAND
{
BYTE* pCur = pBgra;
for (unsigned int unY = 0; unY < unHeight; unY++)
{
for (unsigned int unX = 0; unX < unWidth; unX++)
{
unsigned int unIndex = (unY * unWidth + unX) * 4;
if (0 == pCur[unIndex + 0] && 0 == pCur[unIndex + 1] && 0 == pCur[unIndex + 2])
pCur[unIndex + 3] = 0;
}
}
}
}
}
......@@ -47,6 +47,10 @@ namespace MetaFile
pCur = pBuf;
pEnd = pBuf + unSize + 1;
};
BYTE* GetCurPtr()
{
return pCur;
}
unsigned char ReadUChar()
{
......@@ -66,7 +70,7 @@ namespace MetaFile
pCur += 2;
return ushResult;
};
unsigned int ReadULong()
unsigned int ReadULong()
{
if (pCur + 4 >= pEnd)
return 0;
......@@ -104,7 +108,7 @@ namespace MetaFile
{
return (short)ReadUShort();
};
int ReadLong()
int ReadLong()
{
return (int)ReadULong();
};
......@@ -770,6 +774,81 @@ namespace MetaFile
return *this;
}
CDataStream& operator>>(TWmfStretchBlt& oBitmap)
{
*this >> oBitmap.RasterOperation;
*this >> oBitmap.SrcHeight;
*this >> oBitmap.SrcWidth;
*this >> oBitmap.YSrc;
*this >> oBitmap.XSrc;
*this >> oBitmap.DestHeight;
*this >> oBitmap.DestWidth;
*this >> oBitmap.YDest;
*this >> oBitmap.XDest;
return *this;
}
CDataStream& operator>>(TWmfBitmap16& oBitmap)
{
*this >> oBitmap.Type;
*this >> oBitmap.Width;
*this >> oBitmap.Height;
*this >> oBitmap.WidthBytes;
*this >> oBitmap.Planes;
*this >> oBitmap.BitsPixel;
unsigned int unBitsCount = (((oBitmap.Width * oBitmap.BitsPixel + 15) >> 4) << 1) * oBitmap.Height;
if (CanRead() >= unBitsCount)
{
//oBitmap.Bits = new unsigned char[unBitsCount];
}
else
{
oBitmap.Bits = NULL;
oBitmap.Width = 0;
oBitmap.Height = 0;
}
return *this;
}
CDataStream& operator>>(TWmfBitBlt& oBitmap)
{
*this >> oBitmap.RasterOperation;
*this >> oBitmap.YSrc;
*this >> oBitmap.XSrc;
*this >> oBitmap.Height;
*this >> oBitmap.Width;
*this >> oBitmap.YDest;
*this >> oBitmap.XDest;
return *this;
}
CDataStream& operator>>(TWmfSetDibToDev& oBitmap)
{
*this >> oBitmap.ColorUsage;
*this >> oBitmap.ScanCount;
*this >> oBitmap.StartScan;
*this >> oBitmap.yDib;
*this >> oBitmap.xDib;
*this >> oBitmap.Height;
*this >> oBitmap.Width;
*this >> oBitmap.yDest;
*this >> oBitmap.xDest;
return *this;
}
CDataStream& operator>>(TWmfStretchDib& oBitmap)
{
*this >> oBitmap.RasterOperation;
*this >> oBitmap.ColorUsage;
*this >> oBitmap.SrcHeight;
*this >> oBitmap.SrcWidth;
*this >> oBitmap.YSrc;
*this >> oBitmap.XSrc;
*this >> oBitmap.DestHeight;
*this >> oBitmap.DestWidth;
*this >> oBitmap.yDst;
*this >> oBitmap.xDst;
return *this;
}
bool IsValid() const
{
......@@ -859,7 +938,9 @@ namespace MetaFile
};
void ReadImage(BYTE* pHeaderBuffer, unsigned int ulHeaderBufferLen, BYTE* pImageBuffer, unsigned int ulImageBufferLen, BYTE** ppDstBuffer, unsigned int* pulWidth, unsigned int* pulHeight);
void ReadImage(BYTE* pImageBuffer, unsigned int unBufferLen, unsigned int unColorUsage, BYTE** ppDstBuffer, unsigned int* punWidth, unsigned int* punHeight);
double GetEllipseAngle(int nL, int nT, int nR, int nB, int nX, int nY);
void ProcessRasterOperation(unsigned int unRasterOperation, BYTE** ppBgra, unsigned int unWidth, unsigned int unHeight);
};
#endif //_METAFILE_WMF_EMF_COMMON_H
......@@ -61,6 +61,7 @@ namespace MetaFile
oFile.ReadFile(m_pBufferData, lFileSize, lReadedSize);
m_oStream.SetStream(m_pBufferData, lFileSize);
oFile.CloseFile();
return true;
}
......@@ -80,7 +81,7 @@ namespace MetaFile
PlayMetaFile();
m_pOutput = pOutput;
ClearFile();
this->ClearFile();
}
CFontManager* GetFontManager()
{
......
......@@ -16,6 +16,7 @@ namespace MetaFile
virtual bool IsStrikeOut() = 0;
virtual bool IsUnderline() = 0;
virtual int GetEscapement() = 0;
virtual int GetCharSet() = 0;
};
class IBrush
......
......@@ -119,11 +119,6 @@ namespace MetaFile
m_pRenderer->put_FontStyle(lStyle);
//
m_pRenderer->put_BrushType(c_BrushTypeSolid);
m_pRenderer->put_BrushColor1(m_pFile->GetTextColor());
m_pRenderer->put_BrushAlpha1(255);
double dTheta = -((((double)pFont->GetEscapement()) / 10) * M_PI / 180);
double dCosTheta = (float)cos(dTheta);
......@@ -154,19 +149,6 @@ namespace MetaFile
if (bWithOutLast)
wsTempText.erase(ulCharsCount - 1);
//wchar_t* wsTempText = new wchar_t[ulCharsCount + 1];
//if (!wsTempText)
// return;
//wsTempText[ulCharsCount] = 0x0000;
//for (unsigned int unIndex = 0; unIndex < ulCharsCount; unIndex++)
//{
// wsTempText[unIndex] = wsText[unIndex];
//}
//if (bWithOutLast)
// wsTempText[ulCharsCount - 1] = 0x0000;
pFontManager->LoadString1(wsTempText, 0, 0);
TBBox oBox = pFontManager->MeasureString2();
......@@ -186,8 +168,6 @@ namespace MetaFile
m_pRenderer->put_FontCharSpace(dCharSpace * 25.4 / 72);
}
/*delete[] wsTempText;*/
pFontManager->LoadString1(wsText, 0, 0);
oBox = pFontManager->MeasureString2();
fL = (float)dMmToPt * (oBox.fMinX);
......@@ -278,8 +258,8 @@ namespace MetaFile
if (OPAQUE == m_pFile->GetTextBgMode())
{
m_pRenderer->put_BrushType(c_BrushTypeSolid);
m_pRenderer->put_BrushColor1(255);
m_pRenderer->put_BrushAlpha1(m_pFile->GetTextBgColor());
m_pRenderer->put_BrushAlpha1(255);
m_pRenderer->put_BrushColor1(m_pFile->GetTextBgColor());
m_pRenderer->BeginCommand(c_nPathType);
m_pRenderer->PathCommandStart();
......@@ -290,7 +270,7 @@ namespace MetaFile
m_pRenderer->PathCommandClose();
m_pRenderer->DrawPath(c_nWindingFillMode);
m_pRenderer->EndCommand(c_nPathType);
m_pRenderer->PathCommandStart();
m_pRenderer->PathCommandEnd();
}
//
......@@ -309,6 +289,11 @@ namespace MetaFile
m_pRenderer->PathCommandEnd();
}
//
m_pRenderer->put_BrushType(c_BrushTypeSolid);
m_pRenderer->put_BrushColor1(m_pFile->GetTextColor());
m_pRenderer->put_BrushAlpha1(255);
//
m_pRenderer->CommandDrawText(wsText, dX, dY, 0, 0, 0);
......
......@@ -656,38 +656,11 @@ namespace MetaFile
if (ReadImage(oBitmap.offBmiSrc, oBitmap.cbBmiSrc, oBitmap.offBitsSrc, oBitmap.cbBitsSrc, sizeof(TEmfStretchDIBITS) + 8, &pBgraBuffer, &ulWidth, &ulHeight))
{
// SRCPAINT SRCAND , .
if (0x008800C6 == oBitmap.BitBltRasterOperation) // SRCPAINT
{
BYTE* pCur = pBgraBuffer;
for (unsigned int unY = 0; unY < ulHeight; unY++)
{
for (unsigned int unX = 0; unX < ulWidth; unX++)
{
unsigned int unIndex = (unY * ulWidth + unX) * 4;
if (0xff == pCur[unIndex + 0] && 0xff == pCur[unIndex + 1] && 0xff == pCur[unIndex + 2])
pCur[unIndex + 3] = 0;
}
}
}
else if (0x00EE0086 == oBitmap.BitBltRasterOperation) // SRCAND
{
BYTE* pCur = pBgraBuffer;
for (unsigned int unY = 0; unY < ulHeight; unY++)
{
for (unsigned int unX = 0; unX < ulWidth; unX++)
{
unsigned int unIndex = (unY * ulWidth + unX) * 4;
if (0 == pCur[unIndex + 0] && 0 == pCur[unIndex + 1] && 0 == pCur[unIndex + 2])
pCur[unIndex + 3] = 0;
}
}
}
if (m_pOutput)
{
ProcessRasterOperation(oBitmap.BitBltRasterOperation, &pBgraBuffer, ulWidth, ulHeight);
m_pOutput->DrawBitmap(oBitmap.xDest, oBitmap.yDest, oBitmap.cxDest, oBitmap.cyDest, pBgraBuffer, ulWidth, ulHeight);
}
}
if (pBgraBuffer)
......
......@@ -118,6 +118,10 @@ namespace MetaFile
{
return LogFontEx.LogFont.Escapement;
}
int GetCharSet()
{
return LogFontEx.LogFont.CharSet;
}
public:
......
......@@ -35,6 +35,19 @@ namespace MetaFile
}
bool CMetaFile::LoadFromFile(const wchar_t *wsFilePath)
{
// TODO:
// FontManager, .
//------------------------------------------------------
RELEASEINTERFACE(m_pFontManager);
m_pFontManager = m_pAppFonts->GenerateFontManager();
CFontsCache* pMeasurerCache = new CFontsCache();
pMeasurerCache->SetStreams(m_pAppFonts->GetStreams());
m_pFontManager->SetOwnerCache(pMeasurerCache);
m_oWmfFile.SetFontManager(m_pFontManager);
m_oEmfFile.SetFontManager(m_pFontManager);
//------------------------------------------------------
// Wmf
m_oWmfFile.OpenFromFile(wsFilePath);
......@@ -184,11 +197,9 @@ namespace MetaFile
CFontsCache* pFontCache = new CFontsCache();
pFontCache->SetStreams(m_pAppFonts->GetStreams());
pFontManager->SetOwnerCache(pFontCache);
CImageFilesCache oCache;
CGraphicsRenderer oRenderer;
oRenderer.SetFontManager(pFontManager);
oRenderer.SetImageCache(&oCache);
if (-1 == nHeight)
{
......
......@@ -158,11 +158,9 @@
<ClInclude Include="Emf\EmfClip.h" />
<ClInclude Include="Emf\EmfFile.h" />
<ClInclude Include="Emf\EmfObjects.h" />
<ClInclude Include="Emf\EmfOutputDevice.h" />
<ClInclude Include="Emf\EmfPath.h" />
<ClInclude Include="Emf\EmfPlayer.h" />
<ClInclude Include="Emf\EmfTypes.h" />
<ClInclude Include="Emf\RendererOutput.h" />
<ClInclude Include="MetaFile.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="Wmf\RendererOutput.h" />
......
......@@ -75,15 +75,9 @@
<ClInclude Include="Emf\EmfTypes.h">
<Filter>Emf</Filter>
</ClInclude>
<ClInclude Include="Emf\EmfOutputDevice.h">
<Filter>Emf</Filter>
</ClInclude>
<ClInclude Include="Common.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Emf\RendererOutput.h">
<Filter>Emf</Filter>
</ClInclude>
<ClInclude Include="Emf\EmfPlayer.h">
<Filter>Emf</Filter>
</ClInclude>
......
This diff is collapsed.
......@@ -102,6 +102,10 @@ namespace MetaFile
{
return (int)Escapement;
}
int GetCharSet()
{
return (int)CharSet;
}
public:
......
......@@ -149,6 +149,7 @@ namespace MetaFile
{
CWmfObjectBase* pObject = oPos->second;
switch (pObject->GetType())
{
case WMF_OBJECT_BRUSH: m_pDC->SetBrush((CWmfBrush*)pObject); break;
......
......@@ -997,6 +997,63 @@ namespace MetaFile
TWmfColor Color;
unsigned short BurshHatch;
};
struct TWmfBitmap16
{
short Type;
short Width;
short Height;
short WidthBytes;
unsigned char Planes;
unsigned char BitsPixel;
unsigned char* Bits;
};
struct TWmfBitBlt
{
unsigned int RasterOperation;
short YSrc;
short XSrc;
short Height;
short Width;
short YDest;
short XDest;
};
struct TWmfSetDibToDev
{
unsigned short ColorUsage;
unsigned short ScanCount;
unsigned short StartScan;
unsigned short yDib;
unsigned short xDib;
unsigned short Height;
unsigned short Width;
unsigned short yDest;
unsigned short xDest;
};
struct TWmfStretchBlt
{
unsigned int RasterOperation;
short SrcHeight;
short SrcWidth;
short YSrc;
short XSrc;
short DestHeight;
short DestWidth;
short YDest;
short XDest;
};
struct TWmfStretchDib
{
unsigned int RasterOperation;
unsigned short ColorUsage;
short SrcHeight;
short SrcWidth;
short YSrc;
short XSrc;
short DestHeight;
short DestWidth;
short yDst;
short xDst;
};
}
#endif /* _WMF_TYPES_H_ */
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment