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()
{
......
......@@ -93,8 +93,10 @@ void CSvmFile::PlayMetaFile()
Read_SVM_HEADER();
if (m_pOutput)
{
m_pOutput->Begin();
// + прозрачную заливку ???
}
for (unsigned int action = 0; action < m_oHeader.actionCount; ++action)
{
unsigned short actionType;
......@@ -112,12 +114,22 @@ void CSvmFile::PlayMetaFile()
case META_POLYLINE_ACTION: Read_META_POLYLINE(); break;
case META_POLYGON_ACTION: Read_META_POLYGON(); break;
case META_POLYPOLYGON_ACTION: Read_META_POLYPOLYGON(); break;
case META_LINE_ACTION: Read_META_LINE(); break;
case META_TEXT_ACTION: Read_META_TEXT(); break;
case META_TEXTARRAY_ACTION: Read_META_ARRAYTEXT(); break;
case META_TEXTALIGN_ACTION: Read_META_TEXTALIGN(); break;
case META_TEXTRECT_ACTION: Read_META_TEXTRECT(); break;
case META_TEXTLANGUAGE_ACTION:
case META_STRETCHTEXT_ACTION:
case META_TEXTLINECOLOR_ACTION:
case META_TEXTLINE_ACTION:
break;
case META_MAPMODE_ACTION: Read_META_SETMAPMODE(); break;
case META_FONT_ACTION: Read_META_FONT(); break;
case META_BMPSCALE_ACTION: Read_META_BMPSCALE(); break;
case META_BMP_ACTION: Read_META_BMP(); break;
case META_LINECOLOR_ACTION: Read_META_SETLINECOLOR(); break;
case META_FILLCOLOR_ACTION: Read_META_SETFILLCOLOR(); break;
......@@ -132,6 +144,7 @@ void CSvmFile::PlayMetaFile()
case META_POP_ACTION: Read_META_POP(); break;
case META_TRANSPARENT_ACTION: Read_META_TRANSPARENT(); break;
case META_FLOATTRANSPARENT_ACTION: Read_META_FLOATTRANSPARENT(); break;
case META_ROUNDRECT_ACTION:
case META_ELLIPSE_ACTION:
......@@ -140,11 +153,7 @@ void CSvmFile::PlayMetaFile()
case META_CHORD_ACTION:
case META_PIXEL_ACTION:
case META_POINT_ACTION:
case META_LINE_ACTION:
case META_STRETCHTEXT_ACTION:
case META_TEXTRECT_ACTION:
case META_BMP_ACTION:
case META_BMPSCALEPART_ACTION:
case META_BMPEX_ACTION:
case META_BMPEXSCALE_ACTION:
......@@ -157,14 +166,9 @@ void CSvmFile::PlayMetaFile()
case META_ISECTRECTCLIPREGION_ACTION:
case META_ISECTREGIONCLIPREGION_ACTION:
case META_MOVECLIPREGION_ACTION:
case META_TEXTALIGN_ACTION:
case META_EPS_ACTION:
case META_REFPOINT_ACTION:
case META_TEXTLINECOLOR_ACTION:
case META_TEXTLINE_ACTION:
case META_FLOATTRANSPARENT_ACTION:
case META_LAYOUTMODE_ACTION:
case META_TEXTLANGUAGE_ACTION:
case META_OVERLINECOLOR_ACTION:
case META_RENDERGRAPHIC_ACTION:
case META_COMMENT_ACTION:
......@@ -172,7 +176,7 @@ void CSvmFile::PlayMetaFile()
case META_NULL_ACTION:
default:
#ifdef _DEBUG
if (actionType != 512 && m_unRecordSize > 0)
if (actionType != 512 && m_unRecordSize > 0 && m_pOutput)
{
std::wstring name;
if (actionType == 0)
......@@ -189,7 +193,22 @@ void CSvmFile::PlayMetaFile()
#endif
break;
}
#ifdef _DEBUG
/* if (actionType != 512 && m_unRecordSize > 0 && !m_pOutput)
{
std::wstring name;
if (actionType == 0)
name = actionNames[0].actionName;
else if (actionType == 512)
name = L"META_COMMENT_ACTION";
else if (100 <= actionType && actionType <= META_LAST_ACTION)
name = actionNames[actionType - 99].actionName;
else
name = L"(out of bounds)";
std::wcout << name << L"\t(" << actionType << L") " << L"\tversion = " << m_currentActionVersion << L"\t; totalSize = " << m_unRecordSize << L"\n";
} */
#endif
m_currentActionType = actionType;
int need_skip = m_unRecordSize - (m_oStream.Tell() - m_unRecordPos);
......@@ -199,7 +218,33 @@ void CSvmFile::PlayMetaFile()
m_pOutput->End();
}
void CSvmFile::Read_META_LINE()
{
TSvmPoint start, end;
m_oStream >> start;
m_oStream >> end;
if (m_currentActionVersion >= 2)
{
TSvmLineInfo line_info;
m_oStream >> line_info;
CSvmPen *last_pen = dynamic_cast<CSvmPen *>(m_oPlayer.GetLastObject(SVM_OBJECT_PEN));
if (last_pen)
{
last_pen->Width = line_info.width;
switch(line_info.style)
{
case LINE_SOLID: last_pen->PenStyle = PS_SOLID ; break;
case LINE_DASH: last_pen->PenStyle = PS_DASH ; break;
}
}
}
MoveTo(start.x, start.y);
LineTo(end.x, end.y);
}
void CSvmFile::Read_META_RECTANGLE()
{
TSvmRect oBox;
......@@ -217,22 +262,20 @@ void CSvmFile::Read_SVM_HEADER()
{
m_oStream >> m_oHeader;
//m_pDC->SetWindowExt ( m_oHeader.boundRect.nRight - m_oHeader.boundRect.nLeft,
// m_oHeader.boundRect.nBottom - m_oHeader.boundRect.nTop);
m_oBoundingBox = m_oHeader.boundRect;
m_pDC->SetWindowExt ( m_oHeader.boundRect.nRight - m_oHeader.boundRect.nLeft,
m_oHeader.boundRect.nBottom - m_oHeader.boundRect.nTop);
m_pDC->SetWindowScale( (double)m_oHeader.mapMode.scaleX.numerator/m_oHeader.mapMode.scaleX.denominator,
(double)m_oHeader.mapMode.scaleY.numerator/m_oHeader.mapMode.scaleY.denominator);
m_pDC->SetMapMode(m_oHeader.mapMode, true);
m_oBoundingBox.nRight *= m_pDC->m_dPixelWidthPrefered;
m_oBoundingBox.nBottom *= m_pDC->m_dPixelHeightPrefered;
//m_pDC->SetWindowScale( (double)m_oHeader.mapMode.scaleX.numerator/m_oHeader.mapMode.scaleX.denominator,
// (double)m_oHeader.mapMode.scaleY.numerator/m_oHeader.mapMode.scaleY.denominator);
//
//if (m_pOutput)
//{
// TRect oRect = m_oHeader.boundRect;// GetBoundingBox();
// m_pDC->SetWindowOff(oRect.nLeft, oRect.nTop);
// m_pDC->SetWindowExt(oRect.nRight - oRect.nLeft, oRect.nBottom - oRect.nTop);
//}
//else
{
m_bFirstPoint = true;
}
}
void CSvmFile::Read_META_POLYLINE()
{
......@@ -258,19 +301,32 @@ void CSvmFile::Read_META_POLYLINE()
}
if (m_currentActionVersion >= 3)
{
unsigned char bHasPolyFlags = 0;
m_oStream >> bHasPolyFlags;
if ( bHasPolyFlags )
{
}
//read flags
//enum PolyFlags
//{
// POLY_NORMAL,
// POLY_SMOOTH,
// POLY_CONTROL,
// POLY_SYMMTR
//};
}
if (polygon.count < 1) return;
if (polygon.points.size() < 1) return;
MoveTo(polygon.points[0].x, polygon.points[0].y);
for (int i = 1; i < polygon.count; i++)
for (int i = 1; i < polygon.points.size(); i++)
{
LineTo(polygon.points[i].x, polygon.points[i].y);
}
ClosePath();
DrawPath(true, true);
DrawPath(true, true);//false);
}
void CSvmFile::Read_META_POLYGON()
......@@ -279,11 +335,11 @@ void CSvmFile::Read_META_POLYGON()
m_oStream >> polygon;
if (polygon.count < 1) return;
if (polygon.points.size() < 1) return;
MoveTo(polygon.points[0].x, polygon.points[0].y);
for (int i = 1; i < polygon.count; i++)
for (int i = 1; i < polygon.points.size(); i++)
{
LineTo(polygon.points[i].x, polygon.points[i].y);
}
......@@ -291,7 +347,7 @@ void CSvmFile::Read_META_POLYGON()
DrawPath(true, true);
}
void CSvmFile::Read_META_POLYPOLYGON(std::vector<TSvmPolygon> & polygons)
void CSvmFile::Read_META_POLYPOLYGON(std::vector<TSvmPolygon> & polygons, std::vector<TSvmPolygon> & complexPolygons)
{
unsigned short ushNumberOfPolygons;
m_oStream >> ushNumberOfPolygons;
......@@ -306,8 +362,6 @@ void CSvmFile::Read_META_POLYPOLYGON(std::vector<TSvmPolygon> & polygons)
polygons.push_back(poligon);
}
std::vector<TSvmPolygon> complexPolygons;
if (m_currentActionVersion > 1)
{
unsigned short complexPolygonCount;
......@@ -320,6 +374,11 @@ void CSvmFile::Read_META_POLYPOLYGON(std::vector<TSvmPolygon> & polygons)
unsigned short complexPolygonIndex;
m_oStream >> complexPolygonIndex;
if (complexPolygonIndex >= complexPolygons.size())
{
complexPolygons.resize(complexPolygonIndex+1);
}
m_oStream >> complexPolygons[complexPolygonIndex];
}
}
......@@ -327,13 +386,19 @@ void CSvmFile::Read_META_POLYPOLYGON(std::vector<TSvmPolygon> & polygons)
void CSvmFile::Read_META_POLYPOLYGON()
{
std::vector<TSvmPolygon> polygons;
Read_META_POLYPOLYGON(polygons);
std::vector<TSvmPolygon> complexPolygons;
Read_META_POLYPOLYGON(polygons, complexPolygons);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (polygons.size() < 1) return;
////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (m_pOutput)
{
m_pOutput->StartPath();
for (unsigned short ushPolygonIndex = 0; ushPolygonIndex < polygons.size(); ushPolygonIndex++)
{
unsigned short ushPointsCount = polygons[ushPolygonIndex].count;
unsigned short ushPointsCount = polygons[ushPolygonIndex].points.size();
if (ushPointsCount <= 0)
continue;
......@@ -345,21 +410,22 @@ void CSvmFile::Read_META_POLYPOLYGON()
}
ClosePath();
}
//for (unsigned short ushPolygonIndex = 0; ushPolygonIndex < ushNumberOfPolygons; ushPolygonIndex++)
//{
// unsigned short ushPointsCount = complexPolygons[ushPolygonIndex].count;
for (unsigned short ushPolygonIndex = 0; ushPolygonIndex < complexPolygons.size(); ushPolygonIndex++)
{
unsigned short ushPointsCount = complexPolygons[ushPolygonIndex].points.size();
// if (ushPointsCount <= 0)
// continue;
if (ushPointsCount <= 0)
continue;
// MoveTo(complexPolygons[ushPolygonIndex].points[0].x, complexPolygons[ushPolygonIndex].points[0].y);
// for (int i = 1; i < ushPointsCount; i++)
// {
// LineTo(complexPolygons[ushPolygonIndex].points[i].x, complexPolygons[ushPolygonIndex].points[i].y);
// }
// ClosePath();
//}
MoveTo(complexPolygons[ushPolygonIndex].points[0].x, complexPolygons[ushPolygonIndex].points[0].y);
for (int i = 1; i < ushPointsCount; i++)
{
LineTo(complexPolygons[ushPolygonIndex].points[i].x, complexPolygons[ushPolygonIndex].points[i].y);
}
ClosePath();
}
DrawPath(true, true);
}
}
void CSvmFile::Read_META_SETMAPMODE()
......@@ -448,6 +514,39 @@ void CSvmFile::Read_META_ARRAYTEXT()
}
DrawText(sText, sText.length(), startPoint.x, startPoint.y);
}
void CSvmFile::Read_META_TEXTRECT()
{
TSvmRect rect;
unsigned short style;
std::wstring sText;
m_oStream >> rect;
parseString(m_oStream, sText, m_currentActionVersion, m_currentCharset);
m_oStream >> style;
if ( m_currentActionVersion >= 2 )
{
}
DrawText(sText, sText.length(), rect);
}
void CSvmFile::Read_META_TEXTALIGN()
{
unsigned short nTmp16;
m_oStream >> nTmp16;
unsigned int align = 0;
switch(nTmp16)
{
case 0: align = TA_TOP; break;
case 1: align = TA_BASELINE;break;
case 2: align = TA_BOTTOM; break;
}
m_pDC->SetTextAlign(align);
}
void CSvmFile::Read_META_SETTEXTCOLOR()
{
TSvmColor oColor;
......@@ -501,12 +600,14 @@ void CSvmFile::Read_META_SETLINECOLOR()
void CSvmFile::Read_META_GRADIENTEX()
{
std::vector<TSvmPolygon> polygons;
Read_META_POLYPOLYGON(polygons);
std::vector<TSvmPolygon> complexPolygons;
Read_META_POLYPOLYGON(polygons, complexPolygons);
CSvmBrush* pBrush = new CSvmBrush();
if (!pBrush)
return SetError();
pBrush->BrushStyle = BS_PATHGRADIENT;
pBrush->BrushStyle = BS_LINEARGRADIENT;//BS_PATHGRADIENT;
unsigned short nTmp16;
......@@ -530,7 +631,9 @@ void CSvmFile::Read_META_GRADIENTEX()
void CSvmFile::Read_META_TRANSPARENT()
{
std::vector<TSvmPolygon> polygons;
Read_META_POLYPOLYGON(polygons);
std::vector<TSvmPolygon> complexPolygons;
Read_META_POLYPOLYGON(polygons, complexPolygons);
unsigned short nPercent;
......@@ -545,7 +648,7 @@ void CSvmFile::Read_META_TRANSPARENT()
if (!pBrush)
return SetError();
if (last_brush)
if ((last_brush) /*&& (last_brush->BrushStyle > 0)*/) //skip Nofill
{
pBrush->BrushStyle = last_brush->BrushStyle;
pBrush->BrushHatch = last_brush->BrushHatch;
......@@ -563,7 +666,7 @@ void CSvmFile::Read_META_TRANSPARENT()
for (unsigned short ushPolygonIndex = 0; ushPolygonIndex < polygons.size(); ushPolygonIndex++)
{
unsigned short ushPointsCount = polygons[ushPolygonIndex].count;
unsigned short ushPointsCount = polygons[ushPolygonIndex].points.size();
if (ushPointsCount <= 0)
continue;
......@@ -581,6 +684,49 @@ void CSvmFile::Read_META_TRANSPARENT()
DrawPath(false, true);
}
void CSvmFile::Read_META_FLOATTRANSPARENT()
{
// тут возможен также вариант svg
CSvmFile metaFile(m_oStream.GetCurPtr() , m_unRecordSize);
metaFile.SetOutputDevice(m_pOutput);
metaFile.PlayMetaFile();
int skip_size = metaFile.m_oStream.Tell();
m_oStream.Skip( skip_size);
TSvmPoint point;
TSvmSize size;
m_oStream >> point;
m_oStream >> size;
///////////////////////////////////////////////////
CSvmBrush* pBrush = new CSvmBrush();
if (!pBrush)
return SetError();
pBrush->BrushStyle = BS_LINEARGRADIENT;
m_oStream >> pBrush->BrushBounds;
unsigned short nTmp16;
m_oStream >> nTmp16;
ESvmGradientStyle gradientStyle = (ESvmGradientStyle) nTmp16;
m_oStream >> pBrush->Color;
m_oStream >> pBrush->Color2;
m_oStream >> pBrush->BrushStyleEx;
m_oStream >> nTmp16; //Border
m_oStream >> nTmp16; //OfsX
m_oStream >> nTmp16; //OfsY
m_oStream >> nTmp16; //IntensityStart
m_oStream >> nTmp16; //IntensityEnd
m_oStream >> nTmp16; //StepCount;
m_oPlayer.RegisterObject((CSvmObjectBase*)pBrush);
}
void CSvmFile::Read_META_GRADIENT()
{
CSvmBrush* pBrush = new CSvmBrush();
......@@ -664,39 +810,37 @@ void CSvmFile::Read_META_RASTEROP()
}
void CSvmFile::Read_META_BMPSCALE()
void CSvmFile::Read_META_BMP()
{
TSvmBitmapSize size;
TSvmBitmapPoint point;
m_oStream >> size;
m_oStream >> point;
unsigned int rOffset = 0;
}
void CSvmFile::Read_META_BMPSCALE()
{
unsigned int nHeaderSize = 0;
unsigned int nTmp32;
unsigned short nTmp16 = 0;
bool bRet = false;
m_oStream >> nTmp16;
m_oStream >> rOffset;
m_oStream >> nHeaderSize;
if ( ( 0x4D42 == nTmp16 ) || ( 0x4142 == nTmp16 ) )
{
if ( 0x4142 == nTmp16 )
{
m_oStream.Skip( 12 );
m_oStream.Skip( 12 );//не то !!!
m_oStream >> nTmp16;
m_oStream.Skip( 8 );
m_oStream >> nTmp32;
rOffset = nTmp32 - 28UL;;
nHeaderSize = nTmp32 - 28UL;;
bRet = ( 0x4D42 == nTmp16 );
}
else
{
m_oStream.Skip( 8L );
m_oStream.Skip( 4 );
m_oStream >> nTmp32;
rOffset = nTmp32 - 14UL;
nHeaderSize = nTmp32 - 14;
}
}
......@@ -719,7 +863,11 @@ void CSvmFile::Read_META_BMPSCALE()
else
nColors = 0;
if( ZCOMPRESS == bitmap_info.nCompression && m_pOutput )
BYTE *pBgraBuffer = NULL;
unsigned int ulWidth = 0, ulHeight = 0;
if( ZCOMPRESS == bitmap_info.nCompression )
{
COfficeUtils OfficeUtils(NULL);
......@@ -731,61 +879,93 @@ void CSvmFile::Read_META_BMPSCALE()
if (destSize > 0 && m_pOutput && destBuf )
{
if (OfficeUtils.Uncompress(destBuf, &destSize, srcBuf, srcSize) == S_OK)
if (OfficeUtils.Uncompress(destBuf, &destSize, srcBuf, srcSize) != S_OK)
{
//memcpy(destBuf,&bitmap_info,40);
//unsigned int ulWidth=0, ulHeight=0;
//BYTE* bufBGRA = NULL;
//MetaFile::ReadImage(destBuf, destSize, 0, &bufBGRA, &ulWidth, &ulHeight);
int size_BGRA = bitmap_info.nWidth * bitmap_info.nHeight * 4;
delete []destBuf;
return;
}
}
m_oStream.Skip(srcSize);
BYTE* bufBGRA = new BYTE [size_BGRA];
if (bufBGRA)
{
BYTE* bufBGRA1 = bufBGRA;
int nCount = bitmap_info.nHeight;
for( int j = bitmap_info.nHeight-1; j>=0; j--)
{
for( long i=0; i < bitmap_info.nWidth; i+=3 )
MetaFile::ReadImage((BYTE*)&bitmap_info, bitmap_info.nSize, destBuf, destSize, &pBgraBuffer, &ulWidth, &ulHeight);
delete []destBuf;
}
else
{
*bufBGRA1 = destBuf[j * bitmap_info.nWidth + i + 0]; bufBGRA1++;
*bufBGRA1 = destBuf[j * bitmap_info.nWidth + i + 1]; bufBGRA1++;
*bufBGRA1 = destBuf[j * bitmap_info.nWidth + i + 2]; bufBGRA1++;
*bufBGRA1 = 0xff; bufBGRA1++;
BYTE *Header = new BYTE [ nHeaderSize];
memcpy(Header, &bitmap_info, bitmap_info.nSize);
m_oStream.ReadBytes(Header + bitmap_info.nSize, nHeaderSize - bitmap_info.nSize);
MetaFile::ReadImage(Header , nHeaderSize, m_oStream.GetCurPtr(), bitmap_info.nSizeImage, &pBgraBuffer, &ulWidth, &ulHeight);
m_oStream.Skip(bitmap_info.nSizeImage);
delete Header;
}
if (bitmap_info.nHeight > m_oBoundingBox.nRight &&
bitmap_info.nWidth > m_oBoundingBox.nBottom)
{
m_oBoundingBox.nRight = bitmap_info.nWidth;
m_oBoundingBox.nBottom = bitmap_info.nHeight;
}
//for ( int i=0, j=0 ; i < destSize, j < size_BGRA; i+=3, j+=4)
//{
// bufBGRA[j+0] = destBuf[i+0];
// bufBGRA[j+1] = destBuf[i+1];
// bufBGRA[j+2] = destBuf[i+2];
// bufBGRA[j+3] = 0xff;
//}
double dX = point.x, dY = point.y, dX1 = point.x + size.cx, dY1 =point.y + size.cy;
TranslatePoint(point.x, point.y, dX, dY);
TranslatePoint(point.x + size.cx, point.y + size.cy, dX1, dY1);
TSvmSize size;
TSvmPoint point;
m_oStream >> point;
m_oStream >> size.cx;
m_oStream >> size.cy;
MapMode aMapMode_new, aMapMode_old;
//
aMapMode_old.unit = m_pDC->GetMapMode();
aMapMode_new.unit = MAP_RELATIVE;
m_pDC->SetMapMode(aMapMode_new);
if (pBgraBuffer && m_pOutput)
{
double w = m_oHeader.boundRect.nRight-m_oHeader.boundRect.nLeft;
double h = m_oHeader.boundRect.nBottom-m_oHeader.boundRect.nTop;
w /= size.cx;
h /= size.cy;
double dX = point.x, dY = point.y, dX1 = point.x + size.cx, dY1 = point.y + size.cy;
dX *= w;
dX1 *= w;
dY *= h;
dY1 *= h;
//dX /= w;
//dX1 /= w;
//
//dY /= h;
//dY1 /= h;
//dX *= bitmap_info.nWidth;
//dX1 *= bitmap_info.nWidth;
//
//dY *= bitmap_info.nHeight;
//dY1 *= bitmap_info.nHeight;
TranslatePoint(dX, dY, dX, dY);
TranslatePoint(dX + dX1, dY + dY1, dX1, dY1);
dX1 = dX1-dX;
dY1 = dY1-dY;
MapMode aMapMode;
aMapMode.unit = MAP_PIXEL;//MAP_MM;
//Fraction( 1000, aHeader.nXPelsPerMeter )
//Fraction( 1000, aHeader.nYPelsPerMeter )
if (m_pOutput)
{
m_pOutput->DrawBitmap( dX, dY, dX1, dY1, pBgraBuffer, bitmap_info.nWidth, bitmap_info.nHeight);
}
delete []pBgraBuffer;
m_pDC->SetMapMode(aMapMode);
UpdateOutputDC();
m_pOutput->DrawBitmap(dX, dY, dX1, dY1, bufBGRA, bitmap_info.nWidth, bitmap_info.nHeight);
//m_pOutput->DrawBitmap(dX, dY, dX1, dY1, bufBGRA, ulWidth, ulHeight);
delete []bufBGRA;
}
}
delete []destBuf;
}
}
UpdateOutputDC();
m_pDC->SetMapMode(aMapMode_old);
}
} // namespace MetaFile
......@@ -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()
{
//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()
{
......@@ -147,9 +171,12 @@ class CSvmFile : virtual public IMetaFileBase
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,14 +661,7 @@ unsigned int CSvmDC::GetStretchMode()
{
return m_ulStretchMode;
}
double CSvmDC::GetPixelWidth()
{
return m_dPixelWidth;
}
double CSvmDC::GetPixelHeight()
{
return m_dPixelHeight;
}
void CSvmDC::SetPixelWidth(double dPixelW)
{
m_dPixelWidth = dPixelW;
......
......@@ -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();
......@@ -131,6 +130,12 @@ public:
UpdatePixelMetrics();
}
double m_dPixelWidth;
double m_dPixelHeight;
double m_dPixelWidthPrefered;
double m_dPixelHeightPrefered;
private:
void SetPixelWidth(double dPixelW);
......@@ -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