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

Реализована работа со стеком ресурсов (а не только с FixedPage как раньше).

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63492 954022d7-b5bf-4e40-9824-e11837661b57
parent 7db254af
......@@ -142,7 +142,9 @@
<ClCompile Include="XpsLib\ContextState.cpp" />
<ClCompile Include="XpsLib\Document.cpp" />
<ClCompile Include="XpsLib\Page.cpp" />
<ClCompile Include="XpsLib\StaticResources.cpp" />
<ClCompile Include="XpsLib\Utils.cpp" />
<ClCompile Include="XpsLib\WString.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="XpsFile.h" />
......@@ -150,7 +152,9 @@
<ClInclude Include="XpsLib\Document.h" />
<ClInclude Include="XpsLib\FontList.h" />
<ClInclude Include="XpsLib\Page.h" />
<ClInclude Include="XpsLib\StaticResources.h" />
<ClInclude Include="XpsLib\Utils.h" />
<ClInclude Include="XpsLib\WString.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
......
#include "ContextState.h"
#include "StaticResources.h"
#ifndef xpsUnitToMM
#define xpsUnitToMM(x) ((x) * 25.4 / 96)
......@@ -16,13 +17,16 @@ namespace XPS
m_vClipStack.clear();
m_lTransformStack.clear();
m_vOpacity.clear();
while (m_vResourcesStack.size())
PopResource();
}
void CContextState::PushOpacity(const double& dOpacity)
void CContextState::PushOpacity(const double& dOpacity)
{
m_dCurOpacity *= dOpacity;
m_vOpacity.push_back(m_dCurOpacity);
}
void CContextState::PopOpacity()
void CContextState::PopOpacity()
{
m_vOpacity.pop_back();
if (m_vOpacity.size())
......@@ -34,14 +38,14 @@ namespace XPS
{
return m_dCurOpacity;
}
void CContextState::PushTransform(const double arrTransform[6])
void CContextState::PushTransform(const double arrTransform[6])
{
Aggplus::CMatrix oTransform(arrTransform[0], arrTransform[1], arrTransform[2], arrTransform[3], arrTransform[4], arrTransform[5]);
m_oCurrentTransform.Multiply(&oTransform);
m_lTransformStack.push_back(m_oCurrentTransform);
SetTransformToRenderer();
}
void CContextState::PopTransform()
void CContextState::PopTransform()
{
m_lTransformStack.pop_back();
m_oCurrentTransform = m_lTransformStack.back();
......@@ -61,12 +65,12 @@ namespace XPS
return dDet;
}
void CContextState::PushClip(const CWString& wsClip)
void CContextState::PushClip(const CWString& wsClip)
{
m_vClipStack.push_back(wsClip);
SetClipToRenderer(wsClip);
}
void CContextState::PopClip()
void CContextState::PopClip()
{
m_vClipStack.pop_back();
if (m_pRenderer)
......@@ -81,7 +85,7 @@ namespace XPS
}
}
}
void CContextState::SetTransformToRenderer()
void CContextState::SetTransformToRenderer()
{
if (m_pRenderer)
{
......@@ -90,7 +94,7 @@ namespace XPS
xpsUnitToMM(m_oCurrentTransform.m_agg_mtx.tx), xpsUnitToMM(m_oCurrentTransform.m_agg_mtx.ty));
}
}
void CContextState::SetClipToRenderer(const CWString& wsClip)
void CContextState::SetClipToRenderer(const CWString& wsClip)
{
if (!wsClip.empty() && m_pRenderer)
{
......@@ -104,4 +108,39 @@ namespace XPS
m_pRenderer->PathCommandEnd();
}
}
void CContextState::PushResource(CStaticResource* pResource, bool bOwn)
{
m_vResourcesStack.push_back(TStaticRecource(pResource, bOwn));
}
void CContextState::PopResource()
{
if (m_vResourcesStack.size())
{
TStaticRecource& oPair = m_vResourcesStack.at(m_vResourcesStack.size() - 1);
if (oPair.pResource && oPair.bOwn)
delete oPair.pResource;
m_vResourcesStack.pop_back();
}
}
void CContextState::GetPathGeometry(const CWString& _wsKey, CWString& wsPathData, CWString& wsPathTransform)
{
if (_wsKey.size() < 17)
return;
CWString wsKey((wchar_t*)(_wsKey.c_str() + 16), false, _wsKey.size() - 17);
const wchar_t* wsPath;
CStaticResource* pResource;
for (int nIndex = m_vResourcesStack.size() - 1; nIndex >= 0; nIndex--)
{
pResource = m_vResourcesStack.at(nIndex).pResource;
wsPath = pResource->Get(wsKey);
if (NULL != wsPath)
{
wsPathData.create(wsPath, true);
return;
}
}
}
}
\ No newline at end of file
......@@ -11,8 +11,24 @@
namespace XPS
{
class CStaticResource;
class CContextState
{
private:
struct TStaticRecource
{
TStaticRecource(CStaticResource* resource, bool own)
{
pResource = resource;
bOwn = own;
}
CStaticResource* pResource;
bool bOwn;
};
public:
CContextState(IRenderer* pRenderer);
......@@ -26,6 +42,10 @@ namespace XPS
void PushTransform(const double arrTransform[6]);
void PopTransform();
double NormalizeTransform();
void PushResource(CStaticResource* pResource, bool bOwn);
void PopResource();
void GetPathGeometry(const CWString& wsKey, CWString& wsPathData, CWString& wsPathTransform);
private:
......@@ -40,6 +60,7 @@ namespace XPS
IRenderer* m_pRenderer;
std::vector<double> m_vOpacity;
double m_dCurOpacity;
std::vector<TStaticRecource>m_vResourcesStack;
};
}
......
#include "Document.h"
#include "StaticResources.h"
#include "../../Common/DocxFormat/Source/XML/xmlutils.h"
namespace XPS
......@@ -257,7 +259,7 @@ namespace XPS
}
m_mStaticResources.clear();
}
CStaticResource* CDocument::GetStaticResource(const std::wstring& wsPath)
CStaticResource* CDocument::GetStaticResource(const wchar_t* wsPath)
{
for (auto oIt : m_mStaticResources)
{
......
......@@ -29,7 +29,7 @@ namespace XPS
void GetPageSize(int nPageIndex, int& nW, int& nH);
void DrawPage(int nPageIndex, IRenderer* pRenderer, bool* pbBreak);
void Close();
CStaticResource* GetStaticResource(const std::wstring& wsPath);
CStaticResource* GetStaticResource(const wchar_t* wsPath);
private:
......@@ -38,101 +38,7 @@ namespace XPS
CFontList m_oFontList;
CFontManager* m_pFontManager;
std::map<std::wstring, CStaticResource*> m_mStaticResources;
};
class CStaticResource
{
public:
CStaticResource(const std::wstring& wsPath)
{
clock_t oBeginTime = clock();
XmlUtils::CXmlLiteReader oReader;
if (!oReader.FromFile(wsPath))
return;
Parse(oReader);
clock_t oEndTime = clock();
double dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC;
printf("\n\nSTATIC RESOURCE %S %fseconds\n\n", wsPath.c_str() , dElapsedSecs);
}
CStaticResource(XmlUtils::CXmlLiteReader& oReader)
{
if (oReader.IsEmptyNode())
return;
Parse(oReader);
}
~CStaticResource()
{
}
const wchar_t* Get(const wchar_t* wsKey)
{
CWString _wsKey((wchar_t*)wsKey, false);
std::map<CWString, CWString>::iterator oIter = m_mFigures.find(_wsKey);
if (oIter != m_mFigures.end())
return oIter->second.c_str();
return NULL;
}
const wchar_t* Get(CWString wsKey)
{
std::map<CWString, CWString>::iterator oIter = m_mFigures.find(wsKey);
if (oIter != m_mFigures.end())
return oIter->second.c_str();
return NULL;
}
private:
void Parse(XmlUtils::CXmlLiteReader& oReader)
{
CWString wsNodeName;
CWString wsAttrName;
int nCurDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nCurDepth))
{
wsNodeName = oReader.GetName();
if (wsNodeName == L"PathGeometry")
{
CWString wsKey, wsValue;
if (oReader.MoveToFirstAttribute())
{
wsAttrName = oReader.GetName();
while (!wsAttrName.empty())
{
if (wsAttrName == L"x:Key")
wsKey.create(oReader.GetText(), true);
else if (wsAttrName == L"Figures")
wsValue.create(oReader.GetText(), true);
if (!oReader.MoveToNextAttribute())
break;
wsAttrName = oReader.GetName();
}
oReader.MoveToElement();
}
if (!wsKey.empty() && !wsValue.empty())
Add(wsKey, wsValue);
}
}
}
void Add(const CWString& wsKey, const CWString& wsValue)
{
m_mFigures.insert(std::pair<CWString, CWString>(wsKey, wsValue));
}
private:
std::map<CWString, CWString> m_mFigures;
};
};
}
#endif //_XPS_XPSLIB_DOCUMENT_H
\ No newline at end of file
This diff is collapsed.
......@@ -25,20 +25,17 @@ namespace XPS
private:
void DrawCanvas (XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState, bool* pbBreak);
void ReadPageResources(XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState);
void DrawGlyph (XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState);
bool ReadTransform (XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState);
void DrawPath (XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState);
bool FillToRenderer (XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer);
void ReadPathData (XmlUtils::CXmlLiteReader& oReader, std::wstring& wsData);
void ReadPathGeometry (XmlUtils::CXmlLiteReader& oReader, std::wstring& wsData);
void ReadPathFigure (XmlUtils::CXmlLiteReader& oReader, std::wstring& wsData);
void DrawCanvas (XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState, bool* pbBreak);
bool ReadResource (XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState);
void DrawGlyph (XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState);
void DrawPath (XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState);
bool FillToRenderer (XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState);
bool StrokeToRenderer(XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState);
void ReadPathData (XmlUtils::CXmlLiteReader& oReader, CWString& wsData, CWString& wsTranform);
bool ClipToRenderer (const wchar_t* wsString, CContextState* pState);
bool TransformToRenderer(const wchar_t* wsString, CContextState* pState);
CWString ReadMatrixTransform(XmlUtils::CXmlLiteReader& oReader);
CWString ReadClip (XmlUtils::CXmlLiteReader& oReader);
......@@ -49,10 +46,6 @@ namespace XPS
CFontList* m_pFontList;
CFontManager* m_pFontManager;
CDocument* m_pDocument;
CStaticResource* m_pStaticResource;
bool m_bDeleteStaticResource;
int m_nCounter;
};
}
......
......@@ -4,8 +4,6 @@
#include "../../Common/DocxFormat/Source/XML/xmlutils.h"
#include "../../DesktopEditor/graphics/IRenderer.h"
#define MAX_STRING_LEN 2147483648
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
......@@ -299,205 +297,6 @@ namespace XPS
namespace XPS
{
class CWStringBuffer
{
public:
CWStringBuffer(const wchar_t* wsString, unsigned int unLen)
{
if (unLen)
{
m_pBuffer = new wchar_t[unLen + 1];
m_pBuffer[unLen] = 0x00;
memcpy(m_pBuffer, wsString, sizeof(wchar_t) * unLen);
}
else
{
m_pBuffer = NULL;
}
m_nRefCount = 1;
}
void AddRef()
{
m_nRefCount++;
}
int Release()
{
return --m_nRefCount;
}
void Free()
{
RELEASEARRAYOBJECTS(m_pBuffer);
}
wchar_t operator[](const unsigned int& unIndex) const
{
return m_pBuffer[unIndex];
}
private:
wchar_t* m_pBuffer;
int m_nRefCount;
friend class CWString;
};
CWString::CWString()
{
m_bOwnBuffer = false;
m_pBuffer = NULL;
m_unLen = 0;
}
CWString::CWString(const wchar_t* wsString)
{
m_bOwnBuffer = false;
m_pBuffer = NULL;
m_unLen = 0;
create(wsString, false);
}
CWString::CWString(wchar_t* wsString, bool bCopy, int nLen)
{
m_bOwnBuffer = false;
m_pBuffer = NULL;
m_unLen = 0;
create(wsString, bCopy, nLen);
}
CWString::CWString(const CWString& wsString)
{
m_unLen = wsString.m_unLen;
m_bOwnBuffer = wsString.m_bOwnBuffer;
m_pBuffer = wsString.m_pBuffer;
if (m_bOwnBuffer && m_pBuffer)
((CWStringBuffer*)m_pBuffer)->AddRef();
}
CWString::~CWString()
{
clear();
}
void CWString::create(const wchar_t* wsString, bool bCopy, int nLen)
{
clear();
unsigned int unLen = -1 == nLen ? min(wcslen(wsString), MAX_STRING_LEN) : (unsigned int)nLen;
m_unLen = unLen;
if (bCopy)
{
if (unLen)
{
m_pBuffer = (void*)(new CWStringBuffer(wsString, m_unLen));
m_bOwnBuffer = true;
}
}
else
{
m_pBuffer = (void*)wsString;
m_bOwnBuffer = false;
}
}
void CWString::clear()
{
if (m_bOwnBuffer)
{
CWStringBuffer* pWStringBuffer = (CWStringBuffer*)m_pBuffer;
if (pWStringBuffer && !pWStringBuffer->Release())
delete pWStringBuffer;
}
m_bOwnBuffer = false;
m_pBuffer = NULL;
m_unLen = 0;
}
void CWString::operator=(const wchar_t* wsString)
{
clear();
create(wsString, false);
}
void CWString::operator=(const CWString& wsString)
{
clear();
m_unLen = wsString.m_unLen;
m_bOwnBuffer = wsString.m_bOwnBuffer;
m_pBuffer = wsString.m_pBuffer;
if (m_bOwnBuffer && m_pBuffer)
((CWStringBuffer*)m_pBuffer)->AddRef();
}
const wchar_t* CWString::c_str() const
{
if (m_bOwnBuffer)
{
CWStringBuffer* pWStringBuffer = (CWStringBuffer*)m_pBuffer;
if (pWStringBuffer)
return pWStringBuffer->m_pBuffer;
return NULL;
}
return (const wchar_t*)m_pBuffer;
}
bool CWString::operator<(const CWString& wsString) const
{
const wchar_t* wsLeft = this->c_str();
const wchar_t* wsRight = wsString.c_str();
unsigned int unLen = min(m_unLen, wsString.m_unLen);
for (unsigned int unPos = 0; unPos < unLen; unPos++)
{
if (wsLeft[unPos] < wsRight[unPos])
return true;
else if (wsLeft[unPos] > wsRight[unPos])
return false;
}
return (m_unLen > wsString.m_unLen);
}
bool CWString::operator>(const CWString& wsString) const
{
return !operator<(wsString);
}
bool CWString::operator==(const CWString& wsString) const
{
const wchar_t* wsLeft = this->c_str();
const wchar_t* wsRight = wsString.c_str();
if (m_unLen != wsString.m_unLen)
return false;
for (unsigned int unPos = 0; unPos < m_unLen; unPos++)
{
if (wsLeft[unPos] != wsRight[unPos])
return false;
}
return true;
}
bool CWString::operator==(const wchar_t* wsString) const
{
const wchar_t* wsLeft = this->c_str();
unsigned unLen = min(wcslen(wsString), MAX_STRING_LEN);
if (m_unLen != unLen)
return false;
for (unsigned int unPos = 0; unPos < m_unLen; unPos++)
{
if (wsLeft[unPos] != wsString[unPos])
return false;
}
return true;
}
unsigned int CWString::size() const
{
return m_unLen;
}
wchar_t CWString::operator[](const unsigned int& unIndex) const
{
return this->c_str()[unIndex];
}
bool CWString::empty() const
{
return 0 == m_unLen;
}
int GetDigit(wchar_t wChar)
{
if (wChar >= '0' && wChar <= '9')
......@@ -1185,4 +984,162 @@ namespace XPS
else
return false; //
}
void ReadTransform (XmlUtils::CXmlLiteReader& oReader, CWString& wsTransform, CWString* pwsKey)
{
CWString wsNodeName;
int nCurDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nCurDepth))
{
wsNodeName = oReader.GetName();
if (wsNodeName == L"MatrixTransform")
{
if (oReader.GetAttributesCount() <= 0)
return;
if (!oReader.MoveToFirstAttribute())
return;
CWString wsAttrName = oReader.GetName();
while (!wsAttrName.empty())
{
if (wsAttrName == L"Matrix")
wsTransform.create(oReader.GetText(), true);
else if (wsAttrName == L"x:Key" && pwsKey)
pwsKey->create(oReader.GetText(), true);
}
oReader.MoveToElement();
}
}
}
void ReadPathGeometry(XmlUtils::CXmlLiteReader& oReader, CWString& wsData, CWString& wsTransform, CWString* pwsKey)
{
bool bEvenOdd = true;
CWString wsAttrName;
if (oReader.MoveToFirstAttribute())
{
wsAttrName = oReader.GetName();
while (!wsAttrName.empty())
{
if (wsAttrName == L"x:Key" && pwsKey)
pwsKey->create(oReader.GetText(), true);
else if (wsAttrName == L"Figures")
wsData.create(oReader.GetText(), true);
else if (wsAttrName == L"Transform")
wsTransform.create(oReader.GetText(), true);
else if (wsAttrName == L"FillRule")
{
CWString wsFillingRule = oReader.GetText();
bEvenOdd = wsFillingRule == L"EvenOdd" ? true : false;
}
if (!oReader.MoveToNextAttribute())
break;
wsAttrName = oReader.GetName();
}
oReader.MoveToElement();
}
if (oReader.IsEmptyNode())
return;
CWString wsNodeName;
int nCurDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nCurDepth))
{
wsNodeName = oReader.GetName();
if (wsNodeName == L"PathGeometry.Transform" && wsTransform.empty())
ReadTransform(oReader, wsTransform);
else if (wsNodeName == L"PathFigure" && wsData.empty())
ReadPathFigure(oReader, wsData, bEvenOdd);
}
}
void ReadPathFigure (XmlUtils::CXmlLiteReader& oReader, CWString& _wsData, bool bEvenOdd)
{
// TODO:
std::wstring wsData;
if (oReader.IsEmptyNode())
return;
if (!bEvenOdd)
wsData = L"F 1";
std::wstring wsStartPoint;
ReadAttribute(oReader, L"StartPoint", wsStartPoint);
wsData += L" M " + wsStartPoint;
std::wstring wsNodeName;
std::wstring wsText;
int nCurDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nCurDepth))
{
wsNodeName = oReader.GetName();
wsText.empty();
if (L"PolyLineSegment" == wsNodeName)
{
ReadAttribute(oReader, L"Points", wsText);
wsData += L" L " + wsText;
}
else if (L"PolyBezierSegment" == wsNodeName)
{
ReadAttribute(oReader, L"Points", wsText);
wsData += L" C " + wsText;
}
else if (L"PolyQuadraticBezierSegment" == wsNodeName)
{
ReadAttribute(oReader, L"Points", wsText);
wsData += L" Q " + wsText;
}
else if (L"ArcSegment" == wsNodeName)
{
std::wstring wsSize, wsRotationAngle, wsIsLargeArc, wsSweepDirection, wsPoint;
if (oReader.MoveToFirstAttribute())
{
std::wstring wsAttrName = oReader.GetName();
while (!wsAttrName.empty())
{
if (L"Size" == wsAttrName)
wsSize = oReader.GetText();
else if (L"RotationAngle" == wsAttrName)
wsRotationAngle = oReader.GetText();
else if (L"IsLargeArc" == wsAttrName)
wsIsLargeArc = oReader.GetText();
else if (L"SweepDirection" == wsAttrName)
wsSweepDirection = oReader.GetText();
else if (L"Point" == wsAttrName)
wsPoint = oReader.GetText();
if (!oReader.MoveToNextAttribute())
break;
wsAttrName = oReader.GetName();
}
oReader.MoveToElement();
}
wsData += L" A " + wsSize + L" " + wsRotationAngle + L" ";
if (GetBool(wsIsLargeArc))
wsData += L"1 ";
else
wsData += L"0 ";
if (L"Counterclockwise" == wsSweepDirection)
wsData += L"0 ";
else
wsData += L"1 ";
wsData += wsPoint;
}
}
std::wstring wsClosed;
ReadAttribute(oReader, L"IsClosed", wsClosed);
if (GetBool(wsClosed))
wsData += L" Z ";
_wsData.create(wsData.c_str(), true);
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include "WString.h"
namespace XmlUtils
{
......@@ -13,34 +14,6 @@ class IRenderer;
namespace XPS
{
class CWStringBuffer;
class CWString
{
public:
CWString();
CWString(const wchar_t* wsString);
CWString(const CWString& wsString);
CWString(wchar_t* wsString, bool bCopy, int nLen = -1);
~CWString();
void create(const wchar_t*, bool bCopy, int nLen = -1);
void operator=(const wchar_t* wsString);
void operator=(const CWString& wsString);
bool operator<(const CWString& wsString) const;
bool operator>(const CWString& wsString) const;
bool operator==(const CWString& wsString) const;
bool operator==(const wchar_t* wsString) const;
unsigned int size() const;
bool empty() const;
wchar_t operator[](const unsigned int& unIndex) const;
const wchar_t* c_str() const;
void clear();
private:
void* m_pBuffer;
unsigned int m_unLen;
bool m_bOwnBuffer;
};
struct TIndicesEntry
{
public:
......@@ -102,6 +75,10 @@ namespace XPS
void ReadAttribute(XmlUtils::CXmlLiteReader& oReader, const wchar_t* wsAttrName, CWString& wsAttr);
bool VmlToRenderer(const wchar_t* wsString, IRenderer* pRenderer);
bool GetNextGlyph(const wchar_t* wsIndices, int& nIndicesPos, const int& nIndicesLen, unsigned short* pUtf16, int& nUtf16Pos, const int& nUtf16Len, TIndicesEntry& oEntry);
void ReadTransform (XmlUtils::CXmlLiteReader& oReader, CWString& wsTransform, CWString* pwsKey = NULL);
void ReadPathGeometry(XmlUtils::CXmlLiteReader& oReader, CWString& wsData, CWString& wsTransform, CWString* pwsKey = NULL);
void ReadPathFigure (XmlUtils::CXmlLiteReader& oReader, CWString& _wsData, bool bEvenOdd);
}
#endif // _XPS_XPSLIB_UTILS_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