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

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

Добавлены новые записи. Исправлены баги при чтении картинок. Исправлены баги с вычислением координат и начального сдвига.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62165 954022d7-b5bf-4e40-9824-e11837661b57
parent 98411309
......@@ -5,6 +5,7 @@
namespace MetaFile
{
bool ReadImageCoreHeader(BYTE* pHeaderBuffer, unsigned long ulHeaderBufferLen, BYTE* pImageBuffer, unsigned long ulImageBufferLen, BYTE** ppDstBuffer, unsigned long* pulWidth, unsigned long* pulHeight)
{
CDataStream oHeaderStream;
......@@ -98,22 +99,13 @@ namespace MetaFile
else if (BI_BITCOUNT_1 == ushBitCount)
{
// , 2-
TWmfRGB oColor1, oColor2;
oColor1.r = *pBuffer; pBuffer++; lBufLen--;
oColor1.g = *pBuffer; pBuffer++; lBufLen--;
oColor1.b = *pBuffer; pBuffer++; lBufLen--;
pBuffer++; lBufLen--;
oColor2.r = *pBuffer; pBuffer++; lBufLen--;
oColor2.g = *pBuffer; pBuffer++; lBufLen--;
oColor2.b = *pBuffer; pBuffer++; lBufLen--;
pBuffer++; lBufLen--;
TRgbQuad oColor1, oColor2;
oHeaderStream >> oColor1 >> oColor2;
//
long lCalcLen = (((nWidth * ushPlanes * ushBitCount + 31) & ~31) / 8) * abs(nHeight);
//if (lCalcLen != lBufLen)
// return false;
if (lCalcLen != lBufLen)
return false;
pBgraBuffer = new BYTE[nWidth * nHeight * 4 * sizeof(BYTE)];
if (NULL == pBgraBuffer)
......@@ -145,10 +137,10 @@ namespace MetaFile
for (int nBitIndex = nBitCount; nBitIndex > 0; nBitIndex /= 2)
{
int nBit = (nByte & nBitIndex);
TWmfRGB oColor = (nBit ? oColor2 : oColor1);
pBgraBuffer[nIndex * 4 + 0] = oColor.b;
pBgraBuffer[nIndex * 4 + 1] = oColor.g;
pBgraBuffer[nIndex * 4 + 2] = oColor.r;
TRgbQuad* pColor = (nBit ? &oColor2 : &oColor1);
pBgraBuffer[nIndex * 4 + 0] = pColor->b;
pBgraBuffer[nIndex * 4 + 1] = pColor->g;
pBgraBuffer[nIndex * 4 + 2] = pColor->r;
pBgraBuffer[nIndex * 4 + 3] = 255;
nIndex++;
}
......@@ -177,22 +169,17 @@ namespace MetaFile
if (0 != unColorUsed)
ushColorTableLen = (std::min)((unsigned short)256, (unsigned short)unColorUsed);
TWmfRGB oColorTable[256];
TRgbQuad oColorTable[256];
if (lBufLen < ushColorTableLen * 4)
return false;
//
for (unsigned short ushIndex = 0; ushIndex < ushColorTableLen; ushIndex++)
{
oColorTable[ushIndex].r = *pBuffer; pBuffer++; lBufLen--;
oColorTable[ushIndex].g = *pBuffer; pBuffer++; lBufLen--;
oColorTable[ushIndex].b = *pBuffer; pBuffer++; lBufLen--;
pBuffer++; lBufLen--;
oHeaderStream >> oColorTable[ushIndex];
}
// 1 - 1
// 4.
int nAdd = 0;
while (0 != div_t(div(nWidth + nAdd, 4)).rem)
......@@ -200,7 +187,7 @@ namespace MetaFile
nAdd++;
}
if (lBufLen < nWidth * nHeight)
if (lBufLen < (nWidth + nAdd) * nHeight)
return false;
pBgraBuffer = new BYTE[nWidth * nHeight * 4 * sizeof(BYTE)];
......
......@@ -21,6 +21,13 @@ namespace MetaFile
#define METAFILE_RGBA(r, g, b) ((DWORD)( ( (BYTE)(r) )| ( ( (BYTE)(g) ) << 8 ) | ( ( (BYTE)(b) ) << 16 ) | ( (BYTE)(0) << 24 ) ) )
struct TRgbQuad
{
unsigned char r;
unsigned char g;
unsigned char b;
};
class CDataStream
{
public:
......@@ -422,6 +429,15 @@ namespace MetaFile
return *this;
}
CDataStream& operator>>(TRgbQuad& oRGB)
{
*this >> oRGB.b;
*this >> oRGB.g;
*this >> oRGB.r;
Skip(1); // reserved
return *this;
}
bool IsValid() const
{
......
......@@ -102,6 +102,7 @@ namespace MetaFile
}
void PlayMetaFile()
{
m_lTest = 0;
unsigned long ulSize, ulType;
unsigned long ulNumber = 0;
......@@ -130,21 +131,9 @@ namespace MetaFile
//-----------------------------------------------------------
// 2.3.1 Bitmap
//-----------------------------------------------------------
case EMR_BITBLT:
{
Read_EMR_BITBLT();
break;
}
case EMR_STRETCHDIBITS:
{
Read_EMR_STRETCHDIBITS();
break;
}
case EMR_SETDIBITSTODEVICE:
{
Read_EMR_SETDIBITSTODEVICE();
break;
}
case EMR_BITBLT: Read_EMR_BITBLT(); break;
case EMR_STRETCHDIBITS: Read_EMR_STRETCHDIBITS(); break;
case EMR_SETDIBITSTODEVICE: Read_EMR_SETDIBITSTODEVICE(); break;
//-----------------------------------------------------------
// 2.3.2 Clipping
//-----------------------------------------------------------
......@@ -152,9 +141,9 @@ namespace MetaFile
case EMR_INTERSECTCLIPRECT: Read_EMR_INTERSECTCLIPRECT(); break;
case EMR_SELECTCLIPPATH: Read_EMR_SELECTCLIPPATH(); break;
case EMR_SETMETARGN: Read_EMR_SETMETARGN(); break;
//-----------------------------------------------------------
// 2.3.4 Control
//-----------------------------------------------------------
//-----------------------------------------------------------
// 2.3.4 Control
//-----------------------------------------------------------
case EMR_HEADER:
{
Read_EMR_HEADER();
......@@ -169,67 +158,24 @@ namespace MetaFile
//-----------------------------------------------------------
// 2.3.5 Drawing
//-----------------------------------------------------------
case EMR_EXTTEXTOUTW:
{
Read_EMR_EXTTEXTOUTW();
break;
}
case EMR_POLYGON16:
{
Read_EMR_POLYGON16();
break;
}
case EMR_POLYPOLYGON16:
{
Read_EMR_POLYPOLYGON16();
break;
}
case EMR_LINETO:
{
Read_EMR_LINETO();
break;
}
case EMR_POLYBEZIERTO16:
{
Read_EMR_POLYBEZIERTO16();
break;
}
case EMR_POLYLINETO16:
{
Read_EMR_POLYLINETO16();
break;
}
case EMR_STROKEANDFILLPATH:
{
Read_EMR_STROKEANDFILLPATH();
break;
}
case EMR_STROKEPATH:
{
Read_EMR_STROKEPATH();
break;
}
case EMR_FILLPATH:
{
Read_EMR_FILLPATH();
break;
}
case EMR_RECTANGLE:
{
Read_EMR_RECTANGLE();
break;
}
case EMR_POLYLINE16:
{
Read_EMR_POLYLINE16();
break;
}
case EMR_ELLIPSE: Read_EMR_ELLIPSE(); break;
case EMR_POLYBEZIER16: Read_EMR_POLYBEZIER16(); break;
case EMR_ROUNDRECT: Read_EMR_ROUNDRECT(); break;
//-----------------------------------------------------------
// 2.3.7 Object Creation
//-----------------------------------------------------------
case EMR_EXTTEXTOUTW: Read_EMR_EXTTEXTOUTW(); break;
case EMR_POLYGON16: Read_EMR_POLYGON16(); break;
case EMR_POLYPOLYGON16: Read_EMR_POLYPOLYGON16(); break;
case EMR_LINETO: Read_EMR_LINETO(); break;
case EMR_POLYBEZIERTO16: Read_EMR_POLYBEZIERTO16(); break;
case EMR_POLYLINETO16: Read_EMR_POLYLINETO16(); break;
case EMR_STROKEANDFILLPATH: Read_EMR_STROKEANDFILLPATH(); break;
case EMR_STROKEPATH: Read_EMR_STROKEPATH(); break;
case EMR_FILLPATH: Read_EMR_FILLPATH(); break;
case EMR_RECTANGLE: Read_EMR_RECTANGLE(); break;
case EMR_POLYLINE16: Read_EMR_POLYLINE16(); break;
case EMR_ELLIPSE: Read_EMR_ELLIPSE(); break;
case EMR_POLYBEZIER16: Read_EMR_POLYBEZIER16(); break;
case EMR_ROUNDRECT: Read_EMR_ROUNDRECT(); break;
case EMR_POLYPOLYLINE16: Read_EMR_POLYPOLYLINE16(); break;
//-----------------------------------------------------------
// 2.3.7 Object Creation
//-----------------------------------------------------------
case EMR_CREATEBRUSHINDIRECT:
{
Read_EMR_CREATEBRUSHINDIRECT();
......@@ -256,9 +202,9 @@ namespace MetaFile
break;
}
case EMR_CREATEPALETTE: Read_EMR_CREATEPALETTE(); break;
//-----------------------------------------------------------
// 2.3.8 Object Manipulation
//-----------------------------------------------------------
//-----------------------------------------------------------
// 2.3.8 Object Manipulation
//-----------------------------------------------------------
case EMR_SELECTOBJECT:
{
Read_EMR_SELECTOBJECT();
......@@ -270,9 +216,9 @@ namespace MetaFile
break;
}
case EMR_SELECTPALETTE: Read_EMR_SELECTPALETTE(); break;
//-----------------------------------------------------------
// 2.3.10 Path Bracket
//-----------------------------------------------------------
//-----------------------------------------------------------
// 2.3.10 Path Bracket
//-----------------------------------------------------------
case EMR_BEGINPATH:
{
Read_EMR_BEGINPATH();
......@@ -388,9 +334,9 @@ namespace MetaFile
}
case EMR_SETROP2: Read_EMR_SETROP2(); break;
case EMR_REALIZEPALETTE: Read_EMR_REALIZEPALETTE(); break;
//-----------------------------------------------------------
// 2.3.12 Transform
//-----------------------------------------------------------
//-----------------------------------------------------------
// 2.3.12 Transform
//-----------------------------------------------------------
case EMR_SETWORLDTRANSFORM:
{
Read_EMR_SETWORLDTRANSFORM();
......@@ -501,26 +447,26 @@ namespace MetaFile
return true;
}
long TranslateX(long lSrcX)
double TranslateX(long lSrcX)
{
long lDstX;
double dDstX;
TEmfWindow* pWindow = m_pDC->GetWindow();
TEmfWindow* pViewport = m_pDC->GetViewport();
lDstX = pWindow->lX + (unsigned long)((double)(lSrcX - pViewport->lX / m_pDC->GetPixelWidth()) * m_pDC->GetPixelWidth());
return lDstX;
dDstX = pWindow->lX + (double)((double)(lSrcX - pViewport->lX / m_pDC->GetPixelWidth()) * m_pDC->GetPixelWidth());
return dDstX;
}
long TranslateY(long lSrcY)
double TranslateY(long lSrcY)
{
long lDstY;
double dDstY;
TEmfWindow* pWindow = m_pDC->GetWindow();
TEmfWindow* pViewport = m_pDC->GetViewport();
lDstY = pWindow->lY + (unsigned long)((double)(lSrcY - pViewport->lY / m_pDC->GetPixelHeight()) * m_pDC->GetPixelHeight());
dDstY = pWindow->lY + (double)((double)(lSrcY - pViewport->lY / m_pDC->GetPixelHeight()) * m_pDC->GetPixelHeight());
return lDstY;
return dDstY;
}
void MoveTo(TEmfPointL& oPoint)
......@@ -542,6 +488,8 @@ namespace MetaFile
{
m_pOutput->MoveTo(lX, lY);
}
m_pDC->SetCurPos(lX, lY);
}
void LineTo(long lX, long lY)
{
......@@ -554,6 +502,8 @@ namespace MetaFile
{
m_pOutput->LineTo(lX, lY);
}
m_pDC->SetCurPos(lX, lY);
}
void LineTo(TEmfPointL& oPoint)
{
......@@ -574,6 +524,8 @@ namespace MetaFile
{
m_pOutput->CurveTo(oPoint1.x, oPoint1.y, oPoint2.x, oPoint2.y, oPointE.x, oPointE.y);
}
m_pDC->SetCurPos(oPointE.x, oPointE.y);
}
void ClosePath()
{
......@@ -596,12 +548,14 @@ namespace MetaFile
{
m_pOutput->ArcTo(lL, lT, lR, lB, dStart, dSweep);
}
// TODO:
}
void DrawPath(bool bStroke, bool bFill)
{
if (m_pPath && m_pOutput)
{
m_pPath->Draw(m_pOutput, bStroke, bFill);
//m_pPath->Draw(m_pOutput, bStroke, bFill);
}
else if (m_pOutput)
{
......@@ -805,8 +759,7 @@ namespace MetaFile
m_oStream >> oXForm;
m_oStream >> ulMode;
TEmfXForm* pCurTransform = m_pDC->GetTransform();
pCurTransform->Multiply(oXForm, ulMode);
m_pDC->MultiplyTransform(oXForm, ulMode);
UpdateOutputDC();
}
void Read_EMR_SETWORLDTRANSFORM()
......@@ -815,8 +768,7 @@ namespace MetaFile
m_oStream >> oXForm;
TEmfXForm* pCurTransform = m_pDC->GetTransform();
pCurTransform->Multiply(oXForm, MWT_SET);
m_pDC->MultiplyTransform(oXForm, MWT_SET);
UpdateOutputDC();
}
void Read_EMR_CREATEBRUSHINDIRECT()
......@@ -839,7 +791,6 @@ namespace MetaFile
m_pDC->SetTextColor(oColor);
UpdateOutputDC();
}
void Read_EMR_EXTTEXTOUTW()
{
TEmfExtTextoutW oText;
......@@ -864,8 +815,17 @@ namespace MetaFile
std::wstring wsText((wchar_t*)pUnicode);
long lX = oText.wEmrText.Reference.x;
long lY = oText.wEmrText.Reference.y;
if (m_pDC->GetTextAlign() & TA_UPDATECP)
{
lX = m_pDC->GetCurPos().x;
lY = m_pDC->GetCurPos().y;
}
if (m_pOutput)
m_pOutput->DrawText(wsText.c_str(), ulCharsCount, oText.wEmrText.Reference.x, oText.wEmrText.Reference.y);
m_pOutput->DrawText(wsText.c_str(), ulCharsCount, lX, lY);
delete[] pUnicode;
delete[] pDx;
......@@ -1163,7 +1123,8 @@ namespace MetaFile
{
TEmfRectL oBounds;
m_oStream >> oBounds;
if (m_pOutput && m_pPath)
if (m_pPath)
{
m_pPath->Draw(m_pOutput, false, true);
RELEASEOBJECT(m_pPath);
......@@ -1325,7 +1286,8 @@ namespace MetaFile
{
unsigned long ulRop2Mode;
m_oStream >> ulRop2Mode;
m_pDC->SetRop2Mode(ulRop2Mode);
UpdateOutputDC();
}
void Read_EMR_CREATEPALETTE()
{
......@@ -1378,6 +1340,56 @@ namespace MetaFile
ClosePath();
DrawPath(true, true);
}
void Read_EMR_POLYPOLYLINE16()
{
TEmfRectL oBounds;
m_oStream >> oBounds;
unsigned long ulNumberOfPolylines;
m_oStream >> ulNumberOfPolylines;
unsigned long ulTotalPointsCount;
m_oStream >> ulTotalPointsCount;
if (0 == ulNumberOfPolylines && 0 == ulTotalPointsCount)
return;
else if (0 == ulNumberOfPolylines || 0 == ulTotalPointsCount)
return SetError();
unsigned long* pPolylinePointCount = new unsigned long[ulNumberOfPolylines];
for (unsigned long ulIndex = 0; ulIndex < ulNumberOfPolylines; ulIndex++)
{
m_oStream >> pPolylinePointCount[ulIndex];
}
for (unsigned long ulPolyIndex = 0, ulStartPointIndex = 0; ulPolyIndex < ulNumberOfPolylines; ulPolyIndex++)
{
unsigned long ulCurrentPolylinePointsCount = pPolylinePointCount[ulPolyIndex];
if (0 == ulCurrentPolylinePointsCount)
continue;
TEmfPointS oPoint;
m_oStream >> oPoint;
MoveTo(oPoint);
for (unsigned long ulPointIndex = 1; ulPointIndex < ulCurrentPolylinePointsCount; ulPointIndex++)
{
unsigned long ulRealPointIndex = ulPointIndex + ulStartPointIndex;
if (ulRealPointIndex >= ulTotalPointsCount)
{
delete[] pPolylinePointCount;
return SetError();
}
m_oStream >> oPoint;
LineTo(oPoint);
}
DrawPath(true, false);
}
delete[] pPolylinePointCount;
}
private:
......@@ -1395,6 +1407,8 @@ namespace MetaFile
CEmfPath* m_pPath;
long m_lTest;
friend class CEmfRendererOutput;
friend class CEmfPlayer;
};
......
......@@ -166,9 +166,9 @@ namespace MetaFile
long lType = (bStroke ? 1 : 0) + (bFill ? 2 : 0);
pOutput->DrawPath(lType);
pOutput->EndPath();
Clear();
}
Clear();
}
void CEmfPath::Clear()
{
......
......@@ -220,19 +220,22 @@ namespace MetaFile
m_pPen = &m_oDefaultPen;
m_pFont = NULL;
m_oTransform.Init();
m_oInverseTransform.Init();
m_oTextColor.Init();
m_oBgColor.Init();
m_ulTextAlign = 0;
m_ulBgMode = 0;
m_ulTextAlign = TA_BASELINE | TA_LEFT | TA_NOUPDATECP;
m_ulBgMode = TRANSPARENT;
m_ulMiterLimit = 0;
m_ulFillMode = 0;
m_ulFillMode = WINDING;
m_ulStretchMode = 0;
m_oWindow.Init();
m_oViewport.Init();
m_dPixelHeight = 1;
m_dPixelWidth = 1;
m_pPen = NULL;
m_pPen = NULL;
m_pFont = NULL;
m_oCurPos.x = 0;
m_oCurPos.y = 0;
}
CEmfDC::~CEmfDC()
{
......@@ -247,7 +250,9 @@ namespace MetaFile
pNewDC->m_pBrush = m_pBrush;
pNewDC->m_pPen = m_pPen;
pNewDC->m_pFont = m_pFont;
pNewDC->m_pPalette = m_pPalette;
pNewDC->m_oTransform.Copy(&m_oTransform);
pNewDC->m_oInverseTransform.Copy(&m_oInverseTransform);
pNewDC->m_oTextColor.Copy(&m_oTextColor);
pNewDC->m_oBgColor.Copy(&m_oBgColor);
pNewDC->m_ulTextAlign = m_ulTextAlign;
......@@ -255,10 +260,12 @@ namespace MetaFile
pNewDC->m_ulMiterLimit = m_ulMiterLimit;
pNewDC->m_ulFillMode = m_ulFillMode;
pNewDC->m_ulStretchMode = m_ulStretchMode;
pNewDC->m_oWindow.Copy(&m_oWindow);
pNewDC->m_oViewport.Copy(&m_oViewport);
pNewDC->m_ulRop2Mode = m_ulRop2Mode;
pNewDC->m_dPixelHeight = m_dPixelHeight;
pNewDC->m_dPixelWidth = m_dPixelWidth;
pNewDC->m_oWindow.Copy(&m_oWindow);
pNewDC->m_oViewport.Copy(&m_oViewport);
pNewDC->m_oCurPos = m_oCurPos;
return pNewDC;
}
......@@ -324,6 +331,34 @@ namespace MetaFile
{
return &m_oTransform;
}
TEmfXForm* CEmfDC::GetInverseTransform()
{
return &m_oInverseTransform;
}
void CEmfDC::MultiplyTransform(TEmfXForm& oForm, unsigned long ulMode)
{
m_oTransform.Multiply(oForm, ulMode);
//
TEmfXForm* pT = &m_oTransform;
double dDet = pT->M11 * pT->M22 - pT->M12 * pT->M21;
if (dDet < 0.0001 && dDet > 0.0001)
{
m_oInverseTransform.M11 = 1;
m_oInverseTransform.M12 = 0;
m_oInverseTransform.M21 = 0;
m_oInverseTransform.M22 = 1;
m_oInverseTransform.Dx = 0;
m_oInverseTransform.Dy = 0;
}
m_oInverseTransform.M11 = pT->M22 / dDet;
m_oInverseTransform.M12 = -pT->M12 / dDet;
m_oInverseTransform.M21 = -pT->M21 / dDet;
m_oInverseTransform.M22 = pT->M22 / dDet;
m_oInverseTransform.Dx = pT->Dy * pT->M21 / dDet - pT->Dx * pT->M22 / dDet;
m_oInverseTransform.Dy = pT->Dx * pT->M12 / dDet - pT->Dy * pT->M11 / dDet;
}
void CEmfDC::SetTextColor(TEmfColor& oColor)
{
m_oTextColor.Copy(&oColor);
......@@ -511,4 +546,17 @@ namespace MetaFile
{
return m_pPalette;
}
void CEmfDC::SetCurPos(TEmfPointL& oPoint)
{
SetCurPos(oPoint.x, oPoint.y);
}
void CEmfDC::SetCurPos(long lX, long lY)
{
m_oCurPos.x = lX;
m_oCurPos.y = lY;
}
TEmfPointL& CEmfDC::GetCurPos()
{
return m_oCurPos;
}
}
\ No newline at end of file
......@@ -53,6 +53,8 @@ namespace MetaFile
void SetMapMode(unsigned long ulMapMode);
unsigned long GetMapMode();
TEmfXForm* GetTransform();
TEmfXForm* GetInverseTransform();
void MultiplyTransform(TEmfXForm& oForm, unsigned long ulMode);
void SetTextColor(TEmfColor& oColor);
TEmfColor& GetTextColor();
void SetBrush(CEmfLogBrushEx* pBrush);
......@@ -89,6 +91,9 @@ namespace MetaFile
void SetPalette(CEmfLogPalette* pPalette);
void RemovePalette(CEmfLogPalette* pPalette);
CEmfLogPalette* GetPalette();
void SetCurPos(TEmfPointL& oPoint);
void SetCurPos(long lX, long lY);
TEmfPointL& GetCurPos();
private:
......@@ -106,6 +111,7 @@ namespace MetaFile
CEmfLogFont* m_pFont;
CEmfLogPalette* m_pPalette;
TEmfXForm m_oTransform;
TEmfXForm m_oInverseTransform;
TEmfColor m_oTextColor;
TEmfColor m_oBgColor;
unsigned long m_ulTextAlign;
......@@ -118,6 +124,7 @@ namespace MetaFile
double m_dPixelHeight;
TEmfWindow m_oWindow;
TEmfWindow m_oViewport;
TEmfPointL m_oCurPos;
};
}
......
......@@ -92,6 +92,14 @@ namespace MetaFile
{
long x;
long y;
TEmfPointL& operator=(TEmfPointL& oPoint)
{
x = oPoint.x;
y = oPoint.y;
return *this;
}
};
struct TEmfPointS
......@@ -228,6 +236,14 @@ namespace MetaFile
Copy(&oOther);
}
}
void Apply(double* pX, double* pY)
{
double dX = *pX;
double dY = *pY;
*pX = dX * M11 + dY * M21 + Dx;
*pY = dX * M12 + dY * M22 + Dy;
}
};
struct TEmfEmrText
......
......@@ -75,13 +75,9 @@ namespace MetaFile
pBufferPtr += 4;
}
double dX = TransX(lX);
double dY = TransX(lY);
double dX1 = TransX(lX + lW);
double dY1 = TransY(lY + lH);
m_pRenderer->DrawImage(&oImage, dX, dY, dX1 - dX, dY1 - dY);
TEmfPointD oTL = TranslatePoint(lX, lY);
TEmfPointD oBR = TranslatePoint(lX + lW, lY + lH);
m_pRenderer->DrawImage(&oImage, oTL.x, oTL.y, oBR.x - oTL.x, oBR.y - oTL.y);
}
void DrawText(const wchar_t* wsText, unsigned long ulCharsCount, long lX, long lY)
{
......@@ -99,10 +95,16 @@ namespace MetaFile
TEmfLogFont* pLogFont = &pFont->LogFontEx.LogFont;
TEmfRectL* pBounds = &m_pEmfFile->m_oHeader.oBounds;
TEmfRectL* pFrame = &m_pEmfFile->m_oHeader.oFrame;
long lLogicalFontHeight = pLogFont->Height;
if (lLogicalFontHeight < 0)
lLogicalFontHeight = -lLogicalFontHeight;
if (lLogicalFontHeight < 0.01)
lLogicalFontHeight = 18;
double dFontHeight = TransY(std::abs(pLogFont->Height)) / 25.4 * 72;
TEmfRectL* pBounds = m_pEmfFile->GetDCBounds();
TEmfPointD oHeightPoint = TranslatePoint(0, lLogicalFontHeight + pBounds->lTop);
double dFontHeight = oHeightPoint.y / 25.4 * 72;
std::wstring wsFaceName((const wchar_t*)pLogFont->FaceName);
m_pRenderer->put_FontName(wsFaceName);
m_pRenderer->put_FontSize(dFontHeight);
......@@ -157,8 +159,9 @@ namespace MetaFile
fUndSize *= (float)fKoef / 2;
}
double dX = TransX(lX);
double dY = TransX(lY);
TEmfPointD oTextPoint = TranslatePoint(lX, lY);
double dX = oTextPoint.x;
double dY = oTextPoint.y;
//
unsigned long ulTextAlign = pDC->GetTextAlign();
......@@ -284,42 +287,36 @@ namespace MetaFile
}
void MoveTo(long lX, long lY)
{
CheckStartPath();
double dX = TransX(lX);
double dY = TransY(lY);
m_pRenderer->PathCommandMoveTo(dX, dY);
CheckStartPath(true);
TEmfPointD oPoint = TranslatePoint(lX, lY);
m_pRenderer->PathCommandMoveTo(oPoint.x, oPoint.y);
}
void LineTo(long lX, long lY)
{
CheckStartPath();
double dX = TransX(lX);
double dY = TransY(lY);
m_pRenderer->PathCommandLineTo(dX, dY);
CheckStartPath(false);
TEmfPointD oPoint = TranslatePoint(lX, lY);
m_pRenderer->PathCommandLineTo(oPoint.x, oPoint.y);
}
void CurveTo(long lX1, long lY1, long lX2, long lY2, long lXe, long lYe)
{
CheckStartPath();
CheckStartPath(false);
double dX1 = TransX(lX1), dX2 = TransX(lX2), dXe = TransX(lXe);
double dY1 = TransY(lY1), dY2 = TransY(lY2), dYe = TransY(lYe);
m_pRenderer->PathCommandCurveTo(dX1, dY1, dX2, dY2, dXe, dYe);
TEmfPointD oPoint1 = TranslatePoint(lX1, lY1);
TEmfPointD oPoint2 = TranslatePoint(lX2, lY2);
TEmfPointD oPointE = TranslatePoint(lXe, lYe);
m_pRenderer->PathCommandCurveTo(oPoint1.x, oPoint1.y, oPoint2.x, oPoint2.y, oPointE.x, oPointE.y);
}
void ArcTo(long lLeft, long lTop, long lRight, long lBottom, double dStart, double dSweep)
{
CheckStartPath();
double dL = TransX(lLeft);
double dT = TransY(lTop);
double dR = TransX(lRight);
double dB = TransY(lBottom);
CheckStartPath(false);
m_pRenderer->PathCommandArcTo(dL, dT, dR - dL, dB - dT, dStart, dSweep);
TEmfPointD oTL = TranslatePoint(lLeft, lTop);
TEmfPointD oBR = TranslatePoint(lRight, lBottom);
m_pRenderer->PathCommandArcTo(oTL.x, oTL.y, oBR.x - oTL.x, oBR.y - oTL.y, dStart, dSweep);
}
void ClosePath()
{
CheckStartPath();
CheckStartPath(false);
m_pRenderer->PathCommandClose();
}
......@@ -368,11 +365,20 @@ namespace MetaFile
private:
void CheckStartPath()
void CheckStartPath(bool bMoveTo)
{
if (!m_bStartedPath)
{
StartPath();
if (!bMoveTo)
{
CEmfDC* pDC = m_pEmfFile->GetDC();
if (!pDC)
return;
MoveTo(pDC->GetCurPos().x, pDC->GetCurPos().y);
}
}
}
void CheckEndPath()
......@@ -384,19 +390,22 @@ namespace MetaFile
}
}
double TransX(long _lX)
{
long lX = m_pEmfFile->TranslateY(_lX);
TEmfRectL* pBounds = m_pEmfFile->GetDCBounds();
long lL = pBounds->lLeft;
return m_dScaleX * (double)(lX - lL) + m_dX;
}
double TransY(long _lY)
TEmfPointD TranslatePoint(long lX, long lY)
{
long lY = m_pEmfFile->TranslateY(_lY);
double dX = m_pEmfFile->TranslateX(lX);
double dY = m_pEmfFile->TranslateY(lY);
//
TEmfRectL* pBounds = m_pEmfFile->GetDCBounds();
long lT = pBounds->lTop;
return m_dScaleY * (double)(lY - lT) + m_dY;
double dT = pBounds->lTop;
double dL = pBounds->lLeft;
TEmfXForm* pInverse = m_pEmfFile->GetDC()->GetInverseTransform();
pInverse->Apply(&dL, &dT);
TEmfPointD oPoint;
oPoint.x = m_dScaleX * (double)(dX - dL) + m_dX;
oPoint.y = m_dScaleY * (double)(dY - dT) + m_dY;
return oPoint;
}
bool UpdateBrush()
......@@ -479,7 +488,7 @@ namespace MetaFile
else if (2 == ulPenJoin)
nJoinStyle = 2;
double dMiterLimit = pDC->GetMiterLimit() * m_dScaleX;
double dMiterLimit = pDC->GetMiterLimit() * m_dScaleX * pDC->GetPixelWidth();
// TODO: , PS_SOLID.
// TODO: PS_USERSTYLE
......@@ -498,17 +507,17 @@ namespace MetaFile
m_pRenderer->put_PenAlpha(255);
m_pRenderer->put_PenMiterLimit(dMiterLimit);
//// TO DO: AVSRenderer, ushROPMode
//// .
//// Pen'a, .
//switch (pDC->ushROPMode)
//{
// case R2_BLACK: m_pRenderer->put_PenColor(0); break;
// case R2_NOP: m_pRenderer->put_PenAlpha(0); break;
// case R2_COPYPEN: break;
// case R2_WHITE: m_pRenderer->put_PenColor(METAFILE_RGBA(255, 255, 255)); break;
//}
// TO DO: AVSRenderer, ushROPMode
// .
// Pen'a, .
switch (pDC->GetRop2Mode())
{
case R2_BLACK: m_pRenderer->put_PenColor(METAFILE_RGBA(0, 0, 0)); break;
case R2_NOP: m_pRenderer->put_PenAlpha(0); break;
case R2_COPYPEN: break;
case R2_WHITE: m_pRenderer->put_PenColor(METAFILE_RGBA(255, 255, 255)); break;
}
if (PS_NULL == ulPenStyle)
return false;
......
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