Commit 89c92d4e authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

SvmFile

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62776 954022d7-b5bf-4e40-9824-e11837661b57
parent f8ff1723
......@@ -44,6 +44,23 @@ namespace MetaFile
m_dScaleY = (nB - nT <= 0) ? 1 : m_dH / (double)(nB - nT);
m_bStartedPath = false;
//int alpha = 0xff;
//m_pRenderer->put_BrushAlpha1(alpha);
//m_pRenderer->put_BrushType(c_BrushTypeSolid);
//m_pRenderer->put_BrushColor1(0xffffff);
//m_pRenderer->BeginCommand(c_nPathType);
//m_pRenderer->PathCommandStart();
//m_pRenderer->PathCommandMoveTo(pBounds->nLeft , pBounds->nTop);
//m_pRenderer->PathCommandLineTo(pBounds->nRight , pBounds->nTop);
//m_pRenderer->PathCommandLineTo(pBounds->nRight , pBounds->nBottom);
//m_pRenderer->PathCommandLineTo(pBounds->nLeft , pBounds->nBottom);
//m_pRenderer->PathCommandLineTo(pBounds->nLeft , pBounds->nTop);
//m_pRenderer->PathCommandClose();
//m_pRenderer->DrawPath(c_nWindingFillMode);
//m_pRenderer->EndCommand(c_nPathType);
//m_pRenderer->PathCommandEnd();
}
~CMetaFileRenderer()
{
......
......@@ -18,6 +18,15 @@ class CSvmFile : virtual public IMetaFileBase
m_currentCharset = 0;
m_currentActionType = 0;
};
CSvmFile(BYTE *Data, int DataSize): m_oPlayer(this)
{
m_oStream.SetStream(Data, DataSize);
m_pDC = m_oPlayer.GetDC();
m_currentActionVersion = 0;
m_currentCharset = 0;
m_currentActionType = 0;
}
~CSvmFile()
{
......@@ -36,19 +45,34 @@ class CSvmFile : virtual public IMetaFileBase
}
TRect* GetBounds()
{
return &m_oHeader.boundRect;//&m_oBoundingBox;//
return &m_oBoundingBox;
}
TRect* GetDCBounds()
{
return &m_oHeader.boundRect;
//if ( MAP_RELATIVE == m_pDC->GetMapMode())
//{
TSvmWindow* pViewport = m_pDC->GetViewport();
m_oDCRect.nLeft = pViewport->lX;
m_oDCRect.nTop = pViewport->lY;
m_oDCRect.nRight = pViewport->ulW + pViewport->lX;
m_oDCRect.nBottom = pViewport->ulH + pViewport->lY;
return &m_oDCRect;
//}
//else
{
return &m_oHeader.boundRect;
}
}
double GetPixelHeight()
{
return m_pDC->GetPixelHeight();
return m_pDC->m_dPixelHeight;
}
double GetPixelWidth()
{
return m_pDC->GetPixelWidth();
return m_pDC->m_dPixelWidth;
}
int GetTextColor()
{
......@@ -140,16 +164,19 @@ class CSvmFile : virtual public IMetaFileBase
unsigned short m_currentActionVersion;
unsigned short m_currentCharset;
unsigned short m_currentActionType;
unsigned short m_currentActionType;
unsigned int m_unRecordSize;
unsigned int m_unRecordPos;
bool m_bFirstPoint;
TRect m_oBoundingBox;
//TRect m_oRect;
TRect m_oDCRect;
friend class CSvmPlayer;
void Read_META_LINE();
void Read_META_RECTANGLE();
void Read_SVM_HEADER();
void Read_META_POLYGON();
......@@ -157,20 +184,24 @@ class CSvmFile : virtual public IMetaFileBase
void Read_META_POLYPOLYGON();
void Read_META_TEXT();
void Read_META_ARRAYTEXT();
void Read_META_TEXTALIGN();
void Read_META_TEXTRECT();
void Read_META_SETMAPMODE();
void Read_META_SETTEXTCOLOR();
void Read_META_SETFILLCOLOR();
void Read_META_SETLINECOLOR();
void Read_META_FONT();
void Read_META_BMPSCALE();
void Read_META_BMP();
void Read_META_RASTEROP();
void Read_META_PUSH();
void Read_META_POP();
void Read_META_GRADIENT();
void Read_META_GRADIENTEX();
void Read_META_TRANSPARENT();
void Read_META_FLOATTRANSPARENT();
void Read_META_POLYPOLYGON(std::vector<TSvmPolygon> & polygons);
void Read_META_POLYPOLYGON(std::vector<TSvmPolygon> & polygons, std::vector<TSvmPolygon> & complexPolygons);
//-------------------------------------------------------------------------------------------------------
......@@ -183,12 +214,13 @@ class CSvmFile : virtual public IMetaFileBase
TSvmWindow* pWindow = m_pDC->GetWindow();
TSvmWindow* pViewport = m_pDC->GetViewport();
dX = (double)((double)(nX - pWindow->lX) * m_pDC->GetPixelWidth()) + pViewport->lX;
dY = (double)((double)(nY - pWindow->lY) * m_pDC->GetPixelHeight()) + pViewport->lY;
dX = (double)((double)(nX - pWindow->lX) * m_pDC->m_dPixelWidth) + pViewport->lX;
dY = (double)((double)(nY - pWindow->lY) * m_pDC->m_dPixelHeight) + pViewport->lY;
// Координаты приходят уже с примененной матрицей. Поэтому сначала мы умножаем на матрицу преобразования,
// вычитаем начальные координаты и умножаем на обратную матрицу преобразования.
TRect* pBounds = GetDCBounds();
double dT = pBounds->nTop;
double dL = pBounds->nLeft;
......@@ -272,8 +304,6 @@ class CSvmFile : virtual public IMetaFileBase
}
else
{
RegisterPoint(nX, nY);
RegisterPoint(nX + nW, nY + nH);
}
}
void MoveTo(TSvmPoint& oPoint)
......@@ -303,7 +333,6 @@ class CSvmFile : virtual public IMetaFileBase
{
double dX = nX, dY = nY;
TranslatePoint(nX, nY, dX, dY);
//RegisterPoint(nX, nY);
//if (m_pPath)
//{
......@@ -394,6 +423,42 @@ class CSvmFile : virtual public IMetaFileBase
if (m_pOutput)
m_pOutput->UpdateDC();
}
void DrawText(std::wstring& wsString, unsigned int unCharsCount, TSvmRect& rect)
{
int nX = rect.l;
int nY = rect.t;
int nX1 = rect.r;
int nY1 = rect.b;
if (m_pDC->GetTextAlign() & TA_UPDATECP)
{
nX = m_pDC->GetCurPos().x;
nY = m_pDC->GetCurPos().y;
}
if (m_pOutput)
{
double dX = nX, dY = nY, dX1 = nX1, dY1 = nY1;
TranslatePoint(nX, nY, dX, dY);
TranslatePoint(nX1, nY1, dX1, dY1);
double* pdDx = new double[unCharsCount];
if (pdDx)
{
for (unsigned int unCharIndex = 0; unCharIndex < unCharsCount; unCharIndex++)
{
pdDx[unCharIndex] = (dX1 - dX)/unCharsCount;
}
}
m_pOutput->DrawString(wsString, unCharsCount, dX, dY, pdDx);
if (pdDx)
delete[] pdDx;
}
}
void DrawText(std::wstring& wsString, unsigned int unCharsCount, int _nX, int _nY, int* pnDx = NULL)
{
int nX = _nX;
......@@ -439,24 +504,28 @@ class CSvmFile : virtual public IMetaFileBase
}
TRect GetBoundingBox()
{
TRect oBB = m_oBoundingBox;
TRect oBB = m_oHeader.boundRect;
if (abs(oBB.nRight - oBB.nLeft) <= 1)
oBB.nRight = oBB.nLeft + 1024;
if (abs(oBB.nBottom - oBB.nTop) <= 1)
oBB.nBottom = m_oBoundingBox.nTop + 1024;
oBB.nBottom = oBB.nTop + 1024;
return oBB;
}
void RegisterPoint(short shX, short shY)
{
shX *= m_pDC->m_dPixelWidth;
shY *= m_pDC->m_dPixelHeight;
if (m_bFirstPoint)
{
m_oBoundingBox.nLeft = shX;
m_oBoundingBox.nRight = shX;
m_oBoundingBox.nTop = shY;
m_oBoundingBox.nBottom = shY;
m_bFirstPoint = false;
}
else
......
......@@ -141,7 +141,7 @@ TSvmRect::TSvmRect()
{
l = t = r = b = 0;
}
CDataStream& operator>>(CDataStream &stream, TSvmBitmapSize &s)
CDataStream& operator>>(CDataStream &stream, TSvmSize &s)
{
stream >> s.cx;
stream >> s.cy;
......@@ -155,13 +155,7 @@ CDataStream& operator>>(CDataStream &stream, TSvmPoint &p)
return stream;
}
CDataStream& operator>>(CDataStream &stream, TSvmBitmapPoint &p)
{
stream >> p.x;
stream >> p.y;
return stream;
}
CSvmBrush::CSvmBrush() : Color(255, 255, 255)
{
BrushStyle = BS_SOLID;
......@@ -228,9 +222,10 @@ TSvmPolygon::TSvmPolygon(CDataStream &stream)
}
CDataStream& operator>>(CDataStream &stream, TSvmPolygon &p)
{
stream >> p.count;
unsigned short count;
stream >> count;
for (int i = 0; i < p.count; i++)
for (int i = 0; i < count; i++)
{
TSvmPoint point;
stream >> point;
......
......@@ -142,10 +142,10 @@ struct TSvmRect
struct TSvmPolygon
{
TSvmPolygon(){ count = 0; }
TSvmPolygon(){}
TSvmPolygon(CDataStream &stream);
std::vector<TSvmPoint> points;
unsigned short count;
};
struct TSvmColor
......@@ -339,6 +339,8 @@ class CSvmPen : public CSvmObjectBase, public IPen
public:
CSvmPen()
{
Width = 1;
PenStyle = PS_NULL;
}
~CSvmPen()
{
......@@ -372,8 +374,7 @@ CDataStream& operator>>(CDataStream &stream, VersionCompat &compat);
CDataStream& operator>>(CDataStream &stream, Fraction &fract);
CDataStream& operator>>(CDataStream &stream, MapMode &mm);
CDataStream& operator>>(CDataStream &stream, SvmHeader &header);
CDataStream& operator>>(CDataStream &stream, TSvmBitmapSize &s);
CDataStream& operator>>(CDataStream &stream, TSvmBitmapPoint &s);
CDataStream& operator>>(CDataStream &stream, TSvmSize &s);
CDataStream& operator>>(CDataStream &stream, TSvmPoint &p);
CDataStream& operator>>(CDataStream &stream, TSvmRect &p);
CDataStream& operator>>(CDataStream &stream, TSvmPolygon &p);
......
......@@ -268,11 +268,11 @@ void CSvmPlayer::Pop()
// else
// SetMapMode();
//}
if ( m_nFlags & PUSH_CLIPREGION )
{
GetDC()->GetClip()->ClipOnRenderer(m_pFile->m_pOutput);
GetDC()->GetClip()->Reset();
}
//if ( m_nFlags & PUSH_CLIPREGION )
//{
// GetDC()->GetClip()->ClipOnRenderer(m_pFile->m_pOutput);
// GetDC()->GetClip()->Reset();
//}
m_nFlags = 0;
//if ( m_nFlags & PUSH_REFPOINT )
......@@ -341,11 +341,11 @@ void CSvmPlayer::Push(int nFlags) //
// else
// pData->mpMapMode = NULL;
//}
if ( nFlags & PUSH_CLIPREGION )
{
GetDC()->GetClip()->Reset();
//new region
}
//if ( nFlags & PUSH_CLIPREGION )
//{
// GetDC()->GetClip()->Reset();
// //new region
//}
//if ( nFlags & PUSH_REFPOINT )
//{
// if ( mbRefPoint )
......@@ -405,8 +405,10 @@ CSvmDC::CSvmDC()
m_ulStretchMode = 0;
m_oWindow.Init();
m_oViewport.Init();
m_dPixelHeight = 1;
m_dPixelWidth = 1;
m_dPixelHeight = m_dPixelHeightPrefered = 1;
m_dPixelWidth = m_dPixelWidthPrefered = 1;
m_oCurPos.x = 0;
m_oCurPos.y = 0;
m_unArcDirection = AD_COUNTERCLOCKWISE;
......@@ -435,44 +437,76 @@ CSvmDC* CSvmDC::Copy()
pNewDC->m_ulFillMode = m_ulFillMode;
pNewDC->m_ulStretchMode = m_ulStretchMode;
pNewDC->m_ulRop2Mode = m_ulRop2Mode;
pNewDC->m_dPixelHeight = m_dPixelHeight;
pNewDC->m_dPixelWidth = m_dPixelWidth;
pNewDC->m_dPixelHeightPrefered = m_dPixelHeightPrefered;
pNewDC->m_dPixelWidthPrefered = m_dPixelWidthPrefered;
pNewDC->m_oWindow.Copy(&m_oWindow);
pNewDC->m_oViewport.Copy(&m_oViewport);
pNewDC->m_oCurPos = m_oCurPos;
pNewDC->m_oClip = m_oClip;
//pNewDC->m_oClip = m_oClip;
pNewDC->m_unArcDirection = m_unArcDirection;
return pNewDC;
}
void CSvmDC::SetMapMode(MapMode & mapMode)
ESvmMapUnit CSvmDC::GetMapMode()
{
return m_ulMapMode;
}
void CSvmDC::SetMapMode(MapMode & mapMode, bool prefered )
{
m_ulMapMode = (ESvmMapUnit)mapMode.unit;
double dPixel = 1.;//
switch (m_ulMapMode)
{
case MAP_MM: // 1 unit = 1 mm
{
double dPixel = 1. * 72 / 25.4;
dPixel = 1. * 72 / 25.4;
SetPixelWidth(dPixel);
SetPixelHeight(dPixel);
}break;
case MAP_CM: // 1 unit = 1 cm = 10 mm
{
double dPixel = 10. * 72 / 25.4;
dPixel = 10. * 72 / 25.4;
SetPixelWidth(dPixel);
SetPixelHeight(dPixel);
}break;
case MAP_100TH_MM:
{
dPixel = 1. * 72 / 2540.;
SetPixelWidth(dPixel);
SetPixelHeight(dPixel);
}break;
case MAP_10TH_MM:
{
dPixel = 1. * 72 / 254.;
SetPixelWidth(dPixel);
SetPixelHeight(dPixel);
}break;
case MAP_1000TH_INCH:
{
dPixel = 1. * 72 / 1000.;
SetPixelWidth(dPixel);
SetPixelHeight(dPixel);
}break;
case MAP_100TH_INCH:
{
dPixel = 1.* 72 / 100.;
SetPixelWidth(dPixel);
SetPixelHeight(dPixel);
}break;
case MAP_10TH_INCH:
//
break;
{
dPixel = 1. * 72 / 10.;
SetPixelWidth(dPixel);
SetPixelHeight(dPixel);
}break;
case MAP_INCH: // 1 unit = 1 inch
{
double dPixel = 1. * 72;
dPixel = 1. * 72;
SetPixelWidth(dPixel);
SetPixelHeight(dPixel);
}break;
......@@ -488,7 +522,7 @@ void CSvmDC::SetMapMode(MapMode & mapMode)
}break;
case MAP_PIXEL:
{
double dPixel = 1. * 3. /4.;
dPixel = 0.5;// /72.; //todooo
SetPixelWidth(dPixel);
SetPixelHeight(dPixel);
}break;
......@@ -502,6 +536,15 @@ void CSvmDC::SetMapMode(MapMode & mapMode)
case MAP_LASTENUMDUMMY:
break;
}
if (prefered )
{
m_dPixelHeightPrefered = m_dPixelHeight;
m_dPixelWidthPrefered = m_dPixelWidth;
}
UpdatePixelMetrics();
}
TXForm* CSvmDC::GetTransform()
......@@ -607,7 +650,8 @@ CSvmPen* CSvmDC::GetPen()
}
CSvmClip* CSvmDC::GetClip()
{
return &m_oClip;
return NULL;;
//return &m_oClip;
}
void CSvmDC::SetStretchMode(unsigned int& oMode)
{
......@@ -617,19 +661,12 @@ unsigned int CSvmDC::GetStretchMode()
{
return m_ulStretchMode;
}
double CSvmDC::GetPixelWidth()
{
return m_dPixelWidth;
}
double CSvmDC::GetPixelHeight()
{
return m_dPixelHeight;
}
void CSvmDC::SetPixelWidth(double dPixelW)
void CSvmDC::SetPixelWidth(double dPixelW)
{
m_dPixelWidth = dPixelW;
}
void CSvmDC::SetPixelHeight(double dPixelH)
void CSvmDC::SetPixelHeight(double dPixelH)
{
m_dPixelHeight = dPixelH;
}
......@@ -640,7 +677,7 @@ void CSvmDC::SetWindowOrigin(TSvmPoint& oPoint)
UpdatePixelMetrics();
}
void CSvmDC::SetWindowExtents(TSvmSize& oPoint)
void CSvmDC::SetWindowExtents(TSvmSize& oPoint)
{
m_oWindow.ulW = oPoint.cx;
m_oWindow.ulH = oPoint.cy;
......
......@@ -63,7 +63,8 @@ public:
~CSvmDC();
CSvmDC* Copy();
void SetMapMode(MapMode &mapMode);
ESvmMapUnit GetMapMode();
void SetMapMode(MapMode &mapMode, bool prefered = false);
TXForm* GetTransform();
TXForm* GetInverseTransform();
void MultiplyTransform(TXForm& oForm, unsigned int ulMode);
......@@ -91,8 +92,6 @@ public:
CSvmPen* GetPen();
void SetStretchMode(unsigned int& oMode);
unsigned int GetStretchMode();
double GetPixelWidth();
double GetPixelHeight();
void SetWindowOrigin(TSvmPoint& oPoint);
void SetWindowExtents(TSvmSize& oPoint);
TSvmWindow* GetWindow();
......@@ -130,6 +129,12 @@ public:
m_oWindow.ulH = shH;
UpdatePixelMetrics();
}
double m_dPixelWidth;
double m_dPixelHeight;
double m_dPixelWidthPrefered;
double m_dPixelHeightPrefered;
private:
......@@ -152,12 +157,12 @@ private:
unsigned int m_ulFillMode;
unsigned int m_ulStretchMode;
unsigned int m_ulRop2Mode;
double m_dPixelWidth;
double m_dPixelHeight;
TSvmWindow m_oWindow;
TSvmWindow m_oViewport;
TSvmPoint m_oCurPos;
CSvmClip m_oClip;
//CSvmClip m_oClip;
unsigned int m_unArcDirection;
};
......
......@@ -62,7 +62,10 @@ void ConvertFolder(CMetaFile &oMetaFile, std::wstring wsFolderPath, const int nT
if (oMetaFile.LoadFromFile(wsFilePath.c_str()))
{
std::wstring wsDstFilePath = (wsFilePath.substr(0, wsFilePath.size() - 3)).append(L"bmp");
oMetaFile.ConvertToRaster(wsDstFilePath.c_str(), 1, 1980);
double w, h, x, y;
oMetaFile.GetBounds(&x, &y, &w, &h);
oMetaFile.ConvertToRaster(wsDstFilePath.c_str(), 1, w);
oMetaFile.Close();
}
......
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