Commit f3f9bce6 authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander Trofimov

Save/Restore CGraphicsRenderer; include CMetafile to drawing

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63113 954022d7-b5bf-4e40-9824-e11837661b57
parent 88c2be72
......@@ -426,6 +426,7 @@ namespace Aggplus
Status CGraphics::ResetClip()
{
m_oClip.Reset();
m_oClipState.Clear();
return Ok;
}
......@@ -444,19 +445,26 @@ namespace Aggplus
Status CGraphics::CombineClip(CGraphicsPath* pPath, agg::sbool_op_e op)
{
if (NULL == pPath)
return InvalidParameter;
if (!m_bIntegerGrid)
m_oClip.Combine(pPath, &m_oFullTransform, op);
else
{
CMatrix transform;
m_oClip.Combine(pPath, &transform, op);
}
return Ok;
return InternalClip(pPath, m_bIntegerGrid ? NULL : &m_oFullTransform, op);
}
Status CGraphics::InternalClip(CGraphicsPath* pPath, CMatrix* pTransform, agg::sbool_op_e op)
{
if (NULL == pPath)
return InvalidParameter;
m_oClip.Combine(pPath, pTransform, op);
// write to clips history
CGraphics_ClipStateRecord* pRecord = new CGraphics_ClipStateRecord();
pRecord->Path = (NULL != pPath) ? pPath->Clone() : NULL;
pRecord->Transform = (NULL != pTransform) ? new CMatrix(*pTransform) : new CMatrix();
pRecord->Operation = op;
m_oClipState.AddRecord(pRecord);
return Ok;
}
INT CGraphics::MeasureString(const std::wstring& strText, CFontManager* pManager, double* lWidth, double* lHeight)
{
if (NULL == pManager || NULL == lWidth || NULL == lHeight)
......
......@@ -38,6 +38,8 @@
#include "Brush.h"
#include "Image.h"
#include <vector>
#if defined(_WIN32) || defined (_WIN64)
namespace NSStringFormat
{
......@@ -140,6 +142,86 @@ public:
virtual INT Create(LONG lWidth, LONG lHeight, double dDPIX, double dDPIY) = 0;
};
class CGraphics_ClipStateRecord
{
public:
CGraphicsPath* Path;
Aggplus::CMatrix* Transform;
agg::sbool_op_e Operation;
public:
CGraphics_ClipStateRecord()
{
Path = NULL;
Transform = NULL;
Operation = agg::sbool_and;
}
~CGraphics_ClipStateRecord()
{
RELEASEOBJECT(Path);
RELEASEOBJECT(Transform);
}
CGraphics_ClipStateRecord* Clone() const
{
CGraphics_ClipStateRecord* pRet = new CGraphics_ClipStateRecord();
if (Path)
pRet->Path = Path->Clone();
if (Transform)
pRet->Transform = new CMatrix(*Transform);
pRet->Operation = Operation;
return pRet;
}
};
class CGraphics_ClipState
{
public:
std::vector<CGraphics_ClipStateRecord*> Records;
public:
CGraphics_ClipState()
{
}
CGraphics_ClipState(const CGraphics_ClipState& oSrc)
{
for (std::vector<CGraphics_ClipStateRecord*>::const_iterator i = oSrc.Records.begin(); i != oSrc.Records.end(); i++)
{
Records.push_back((*i)->Clone());
}
}
~CGraphics_ClipState()
{
Clear();
}
void AddRecord(CGraphics_ClipStateRecord* pRecord)
{
Records.push_back(pRecord);
}
void Clear()
{
for (std::vector<CGraphics_ClipStateRecord*>::iterator i = Records.begin(); i != Records.end(); i++)
{
CGraphics_ClipStateRecord* pRec = *i;
RELEASEOBJECT(pRec);
}
Records.clear();
}
CGraphics_ClipState* Clone() const
{
CGraphics_ClipState* pRet = new CGraphics_ClipState();
for (std::vector<CGraphics_ClipStateRecord*>::const_iterator i = Records.begin(); i != Records.end(); i++)
{
pRet->Records.push_back((*i)->Clone());
}
return pRet;
}
};
class CGraphics
{
......@@ -204,6 +286,8 @@ public:
double m_dDpiTile;
CGraphics_ClipState m_oClipState;
public:
CGraphics();
......@@ -247,6 +331,7 @@ public:
Status ResetClip();
Status ExclugeClip(CGraphicsPath* pPath);
Status CombineClip(CGraphicsPath* pPath, agg::sbool_op_e op);
Status InternalClip(CGraphicsPath* pPath, CMatrix* pTransform, agg::sbool_op_e op);
// измерение текста
INT MeasureString(const std::wstring& strText, CFontManager* pManager, double* lWidth, double* lHeight);
......
#include "GraphicsRenderer.h"
#include <algorithm>
#include "../raster/Metafile/MetaFile.h"
////////////////////////////////////////////////////////////////////////////////
......@@ -127,7 +128,7 @@ CGraphicsRenderer::CGraphicsRenderer()
m_pCache = NULL;
m_dGlobalAlpha = 1.0;
m_bGlobalAlphaEnabled = FALSE;
m_bGlobalAlphaEnabled = false;
}
CGraphicsRenderer::~CGraphicsRenderer()
{
......@@ -969,6 +970,17 @@ HRESULT CGraphicsRenderer::DrawImage(IGrObject* pImage, const double& x, const d
}
HRESULT CGraphicsRenderer::DrawImageFromFile(const std::wstring& bstrVal, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha)
{
#if 0
MetaFile::CMetaFile oMetafile(m_pFontManager ? m_pFontManager->m_pApplication : NULL);
if (oMetafile.LoadFromFile(bstrVal.c_str()))
{
this->Save();
bool bRet = oMetafile.DrawOnRenderer(this, x, y, w, h);
this->Restore();
return bRet ? S_OK : S_FALSE;
}
#endif
CCacheImage* pCacheImage = NULL;
if (NULL != m_pCache)
{
......@@ -976,7 +988,7 @@ HRESULT CGraphicsRenderer::DrawImageFromFile(const std::wstring& bstrVal, const
}
else
{
pCacheImage = new CCacheImage(bstrVal);
pCacheImage = new CCacheImage(NULL, bstrVal);
}
if (NULL != pCacheImage)
......@@ -1232,3 +1244,79 @@ void CGraphicsRenderer::AddRect(const double& x, const double& y, const double&
m_pPath->LineTo(x, y + h);
m_pPath->CloseFigure();
}
// SAVE/RESTORE section
class CGraphicsRenderer_State : public IGraphicsRenderer_State
{
public:
CGraphicsRenderer_State() : IGraphicsRenderer_State()
{
}
CGraphicsRenderer_State(const Aggplus::CGraphics_ClipState& oState) : IGraphicsRenderer_State(), m_oClipState(oState)
{
}
virtual ~CGraphicsRenderer_State()
{
}
public:
NSStructures::CPen m_oPen;
NSStructures::CBrush m_oBrush;
NSStructures::CFont m_oFont;
Aggplus::CMatrix m_oTransform;
double m_dGlobalAlpha;
bool m_bGlobalAlphaEnabled;
bool m_bIntegerGrid;
Aggplus::CGraphics_ClipState m_oClipState;
};
void CGraphicsRenderer::Save()
{
if (!m_pRenderer)
return;
CGraphicsRenderer_State* pState = new CGraphicsRenderer_State(m_pRenderer->m_oClipState);
pState->m_oPen = m_oPen;
pState->m_oBrush = m_oBrush;
pState->m_oFont = m_oFont;
pState->m_oTransform = *m_pRenderer->GetTransform();
pState->m_dGlobalAlpha = m_dGlobalAlpha;
pState->m_bGlobalAlphaEnabled = m_bGlobalAlphaEnabled;
pState->m_bIntegerGrid = m_pRenderer->m_bIntegerGrid;
m_arStates.push_back(pState);
}
void CGraphicsRenderer::Restore()
{
if (!m_pRenderer)
return;
if (0 == m_arStates.size())
return;
CGraphicsRenderer_State* pState = (CGraphicsRenderer_State*)m_arStates.at(m_arStates.size() - 1);
m_arStates.pop_back();
m_oPen = pState->m_oPen;
m_oBrush = pState->m_oBrush;
m_oFont = pState->m_oFont;
ApplyTransform(&pState->m_oTransform);
this->put_IntegerGrid(pState->m_bIntegerGrid);
this->put_GlobalAlphaEnabled(pState->m_bGlobalAlphaEnabled, pState->m_dGlobalAlpha);
m_pRenderer->ResetClip();
for (std::vector<Aggplus::CGraphics_ClipStateRecord*>::iterator i = pState->m_oClipState.Records.begin(); i != pState->m_oClipState.Records.end(); i++)
{
Aggplus::CGraphics_ClipStateRecord* pRecord = *i;
m_pRenderer->InternalClip(pRecord->Path, pRecord->Transform, pRecord->Operation);
}
RELEASEOBJECT(pState);
}
......@@ -6,6 +6,21 @@
#include "ImageFilesCache.h"
#include "../raster/BgraFrame.h"
class IGraphicsRenderer_State
{
public:
int Type;
IGraphicsRenderer_State()
{
// пока не используется
Type = 0;
}
virtual ~IGraphicsRenderer_State()
{
}
};
class CGraphicsRenderer : public IRenderer
{
private:
......@@ -42,7 +57,9 @@ private:
CImageFilesCache* m_pCache;
double m_dGlobalAlpha;
INT m_bGlobalAlphaEnabled;
bool m_bGlobalAlphaEnabled;
std::vector<IGraphicsRenderer_State*> m_arStates;
public:
CGraphicsRenderer();
......@@ -74,6 +91,9 @@ public:
void SetSwapRGB(bool bValue){ if (m_pRenderer) m_pRenderer->m_bSwapRGB = bValue; }
void SetTileImageDpi(const double& dDpi) { if (m_pRenderer) m_pRenderer->m_dDpiTile = dDpi; }
void Save();
void Restore();
public:
// тип рендерера-----------------------------------------------------------------------------
virtual HRESULT get_Type(LONG* lType);
......
......@@ -4,6 +4,9 @@
#include "Image.h"
#include "TemporaryCS.h"
#include <map>
#include "../fontengine/ApplicationFonts.h"
#include "../raster/Metafile/MetaFile.h"
#include "../common/File.h"
class CCacheImage
{
......@@ -12,12 +15,35 @@ private:
LONG m_lRef;
public:
CCacheImage() : m_oImage()
CCacheImage(CApplicationFonts* pFonts) : m_oImage()
{
m_lRef = 1;
}
CCacheImage(const std::wstring& strFile) : m_oImage(strFile)
CCacheImage(CApplicationFonts* pFonts, const std::wstring& strFile)
{
if (NULL == pFonts)
{
m_oImage.Create(strFile);
}
else
{
MetaFile::CMetaFile oMetafile(pFonts);
bool bIsMetafile = oMetafile.LoadFromFile(strFile.c_str());
if (!bIsMetafile)
{
m_oImage.Create(strFile);
}
else
{
std::wstring sTempFile = NSFile::CFileBinary::CreateTempFileWithUniqueName(NSFile::CFileBinary::GetTempPath(), L"AscMetafile_");
oMetafile.ConvertToRaster(sTempFile.c_str(), 4, 1000, -1);
m_oImage.Create(sTempFile);
NSFile::CFileBinary::Remove(sTempFile);
}
}
m_lRef = 1;
}
......@@ -53,11 +79,14 @@ private:
LONG m_lRef;
CApplicationFonts* m_pApplicationFonts;
NSCriticalSection::CRITICAL_SECTION m_oCS;
public:
CImageFilesCache()
CImageFilesCache(CApplicationFonts* pFonts = NULL)
{
m_pApplicationFonts = pFonts;
m_lMaxCount = 10;
m_lRef = 1;
......@@ -98,18 +127,20 @@ public:
if (nCount >= m_lMaxCount)
{
int nNeedDelete = nCount - m_lMaxCount;
std::map<std::wstring,CCacheImage*>::iterator it2 = m_mapImages.begin();
while (nNeedDelete > 0 && it2 != m_mapImages.end())
{
it2->second->Release();
m_mapImages.erase(it2);
it2++;
while (nNeedDelete > 0)
{
std::map<std::wstring,CCacheImage*>::iterator it2 = m_mapImages.begin();
if (it2 != m_mapImages.end())
{
it2->second->Release();
m_mapImages.erase(it2);
}
--nNeedDelete;
}
}
}
}
CCacheImage* pImage = new CCacheImage(strFile);
CCacheImage* pImage = new CCacheImage(m_pApplicationFonts, strFile);
m_mapImages[strFile] = pImage;
pImage->AddRef();
......
......@@ -6,6 +6,11 @@ namespace Aggplus
{
}
CMatrix::CMatrix(const CMatrix& oSrc) : m_agg_mtx()
{
m_agg_mtx = oSrc.m_agg_mtx;
}
CMatrix::CMatrix() : m_agg_mtx()
{
}
......
......@@ -15,6 +15,7 @@ class CMatrix
public:
CMatrix(double m11, double m12, double m21, double m22, double dx, double dy);
CMatrix();
CMatrix(const CMatrix& oSrc);
~CMatrix();
......
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