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
......@@ -2,7 +2,9 @@
#include <stdio.h>
#include "../../DesktopEditor/common/String.h"
#include "../../DesktopEditor/graphics/structures.h"
#include "Document.h"
#include "StaticResources.h"
#include <ctime>
......@@ -14,6 +16,8 @@
#define xpsUnitToMM(x) ((x) * 25.4 / 96)
#endif
#define IsFromResource(String) (!String.empty() && '{' == String[0])
namespace XPS
{
static double GetAdvance(CFontManager* pFontManager, const std::wstring& wsChar, const std::wstring& wsGid, const bool& bGid)
......@@ -38,16 +42,9 @@ namespace XPS
m_pFontList = pFontList;
m_pFontManager = pFontManager;
m_pDocument = pDocument;
m_pStaticResource = NULL;
m_bDeleteStaticResource = false;
m_nCounter = 0;
}
Page::~Page()
{
if (m_bDeleteStaticResource)
RELEASEOBJECT(m_pStaticResource);
}
void Page::GetSize(int& nW, int& nH) const
{
......@@ -201,7 +198,7 @@ namespace XPS
}
void Page::DrawCanvas(XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState, bool* pbBreak)
{
bool bTransform = false, bClip = false, bOpacity = false;
bool bTransform = false, bClip = false, bOpacity = false, bResource = false;
if (oReader.MoveToFirstAttribute())
{
CWString wsAttrName = oReader.GetName();
......@@ -236,11 +233,11 @@ namespace XPS
if (wsNodeName == L"FixedPage.Resources")
{
ReadPageResources(oReader, pRenderer, pState);
bResource = ReadResource(oReader, pRenderer, pState);
}
else if (wsNodeName == L"Canvas.Resources")
{
ReadResourceDictionary(oReader, pRenderer, pState);
bResource = ReadResource(oReader, pRenderer, pState);
}
else if (wsNodeName == L"Glyphs")
{
......@@ -250,10 +247,11 @@ namespace XPS
{
DrawCanvas(oReader, pRenderer, pState, pbBreak);
}
else if (wsNodeName == L"Canvas.RenderTransform")
else if (wsNodeName == L"Canvas.RenderTransform" && !bTransform)
{
if (!bTransform)
bTransform = ReadTransform(oReader, pRenderer, pState);
CWString wsTransform;
ReadTransform(oReader, wsTransform);
bTransform = TransformToRenderer(wsTransform.c_str(), pState);
}
else if (wsNodeName == L"Path")
{
......@@ -298,47 +296,52 @@ namespace XPS
if (bOpacity)
pState->PopOpacity();
if (bResource)
pState->PopResource();
}
void Page::ReadPageResources(XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState)
bool Page::ReadResource(XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState)
{
if (oReader.IsEmptyNode())
return;
return false;
std::wstring wsNodeName;
CWString wsNodeName;
int nCurDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nCurDepth))
{
wsNodeName = oReader.GetName();
if (L"ResourceDictionary" == wsNodeName)
if (wsNodeName == L"ResourceDictionary")
{
std::wstring wsSource;
CWString wsSource;
ReadAttribute(oReader, L"Source", wsSource);
if (!wsSource.empty())
{
std::wstring wsPath = m_wsRootPath + wsSource;
m_pStaticResource = m_pDocument->GetStaticResource(wsPath);
m_bDeleteStaticResource = false;
std::wstring wsPath = m_wsRootPath + wsSource.c_str();
pState->PushResource(m_pDocument->GetStaticResource(wsPath.c_str()), false);
}
else
{
m_pStaticResource = new CStaticResource(oReader);
m_bDeleteStaticResource = true;
pState->PushResource(new CStaticResource(oReader), true);
}
return true;
}
}
}
return false;
}
bool Page::ClipToRenderer(const wchar_t* wsString, CContextState* pState)
{
CWString wsClip;
wsClip.create(wsString, true);
if (!wsClip.empty())
{
if ('{' == wsClip[0] && wsClip.size() >= 17)
if (IsFromResource(wsClip))
{
CWString wsKey((wchar_t*)(wsClip.c_str() + 16), false, wsClip.size() - 17);
wsClip = m_pStaticResource->Get(wsKey.c_str());
CWString wsPathTransform;
pState->GetPathGeometry(wsClip, wsClip, wsPathTransform);
}
pState->PushClip(wsClip);
return true;
}
......@@ -486,7 +489,7 @@ namespace XPS
if (L"Glyphs.RenderTransform" == wsNodeName)
{
wsTransform = ReadMatrixTransform(oReader);
ReadTransform(oReader, wsTransform);
}
}
}
......@@ -568,40 +571,6 @@ namespace XPS
if (bOpacity)
pState->PopOpacity();
}
bool Page::ReadTransform(XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState)
{
std::wstring wsNodeName;
int nCurDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nCurDepth))
{
wsNodeName = oReader.GetName();
wsNodeName = RemoveNamespace(wsNodeName);
if (L"MatrixTransform" == wsNodeName)
{
std::wstring wsMatrix;
ReadAttribute(oReader, L"Matrix", wsMatrix);
return TransformToRenderer(wsMatrix.c_str(), pState);
}
}
return false;
}
CWString Page::ReadMatrixTransform(XmlUtils::CXmlLiteReader& oReader)
{
CWString wsNodeName, wsTransform;
int nCurDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nCurDepth))
{
wsNodeName = oReader.GetName();
if (wsNodeName == L"MatrixTransform")
{
ReadAttribute(oReader, L"Matrix", wsTransform);
break;
}
}
return wsTransform;
}
CWString Page::ReadClip(XmlUtils::CXmlLiteReader& oReader)
{
CWString wsClip;
......@@ -611,10 +580,11 @@ namespace XPS
void Page::DrawPath(XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState)
{
bool bTransform = false, bClip = false, bOpacity = false;
bool bFillSetted = false;
double dPenSize = 1.0;
std::wstring wsData;
bool bStroke = false;
bool bFill = false;
int nFillBgr = 0, nFillAlpha = 255, nStrokeBgr = 0, nStrokeAlpha = 255;
......@@ -628,8 +598,7 @@ namespace XPS
LONG lDashPatternSize = 0;
double dDashOffset = 0.0;
CWString wsClip, wsTransform;
CWString wsClip, wsTransform, wsPathData, wsPathTransform;
if (oReader.MoveToFirstAttribute())
{
std::wstring wsAttrName = oReader.GetName();
......@@ -711,13 +680,13 @@ namespace XPS
}
else if (L"Fill" == wsAttrName)
{
bFillSetted = true;
bFill = true;
std::wstring wsFill = oReader.GetText();
GetBgra(wsFill, nFillBgr, nFillAlpha);
}
else if (L"Data" == wsAttrName)
{
wsData = oReader.GetText();
wsPathData.create(oReader.GetText(), true);
}
if (!oReader.MoveToNextAttribute())
......@@ -728,28 +697,45 @@ namespace XPS
}
oReader.MoveToElement();
bool bFill = bFillSetted;
if (!bFillSetted)
if (bStroke)
{
if (!oReader.IsEmptyNode())
pRenderer->put_PenColor(nStrokeBgr & 0x00FFFFFF);
pRenderer->put_PenAlpha(nStrokeAlpha * pState->GetCurrentOpacity());
}
if (bFill)
{
pRenderer->put_BrushType(c_BrushTypeSolid);
pRenderer->put_BrushColor1(nFillBgr & 0x00FFFFFF);
pRenderer->put_BrushAlpha1(nFillAlpha * pState->GetCurrentOpacity());
}
if (!oReader.IsEmptyNode())
{
CWString wsNodeName;
int nCurDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nCurDepth))
{
CWString wsNodeName;
int nCurDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nCurDepth))
wsNodeName = oReader.GetName();
if (wsNodeName == L"Path.RenderTransform")
{
wsNodeName = oReader.GetName();
if (wsNodeName == L"Path.Fill")
{
bFill = FillToRenderer(oReader, pRenderer);
}
else if (wsNodeName == L"Path.Data")
{
ReadPathData(oReader, wsData);
}
else if (wsNodeName == L"Path.RenderTransform")
{
wsTransform = ReadMatrixTransform(oReader);
}
ReadTransform(oReader, wsTransform);
}
else if (wsNodeName == L"Path.Clip")
{
wsClip = ReadClip(oReader);
}
else if (wsNodeName == L"Path.Fill" && !bFill)
{
bFill = FillToRenderer(oReader, pRenderer, pState);
}
else if (wsNodeName == L"Path.Stroke" && !bStroke)
{
bStroke = StrokeToRenderer(oReader, pRenderer, pState);
}
else if (wsNodeName == L"Path.Data" && wsPathData.empty())
{
ReadPathData(oReader, wsPathData, wsPathTransform);
}
}
}
......@@ -788,19 +774,6 @@ namespace XPS
pRenderer->put_PenLineEndCap(nEndCap);
}
if (bStroke)
{
pRenderer->put_PenColor(nStrokeBgr & 0x00FFFFFF);
pRenderer->put_PenAlpha(nStrokeAlpha * pState->GetCurrentOpacity());
}
if (bFill)
{
pRenderer->put_BrushType(c_BrushTypeSolid);
pRenderer->put_BrushColor1(nFillBgr & 0x00FFFFFF);
pRenderer->put_BrushAlpha1(nFillAlpha * pState->GetCurrentOpacity());
}
pRenderer->put_PenLineJoin(nJoinStyle);
if (nJoinStyle == Aggplus::LineJoinMiter)
pRenderer->put_PenMiterLimit(xpsUnitToMM(dMiter));
......@@ -809,39 +782,14 @@ namespace XPS
pRenderer->BeginCommand(c_nPathType);
pRenderer->PathCommandStart();
bool bWindingFillMode = false;
if (L'{' == wsData[0])
{
const wchar_t* wsValue = NULL;
if (m_pStaticResource)
{
CWString wsKey(((wchar_t*)wsData.c_str() + 16), false, wsData.length() - 17);
wsValue = m_pStaticResource->Get(wsKey);
}
if (IsFromResource(wsPathData))
pState->GetPathGeometry(wsPathData, wsPathData, wsPathTransform);
if (NULL != wsValue)
{
bWindingFillMode = VmlToRenderer(wsValue, pRenderer);
}
else
{
pRenderer->EndCommand(c_nPathType);
pRenderer->PathCommandEnd();
if (bClip)
pState->PopClip();
bool bPathTransform = false;
if (!wsPathTransform.empty())
bPathTransform = TransformToRenderer(wsPathTransform.c_str(), pState);
if (bTransform)
pState->PopTransform();
if (bOpacity)
pState->PopOpacity();
return;
}
}
else
bWindingFillMode = VmlToRenderer(wsData.c_str(), pRenderer);
bool bWindingFillMode = VmlToRenderer(wsPathData.c_str(), pRenderer);
int nMode = bStroke ? c_nStroke : 0;
if (bFill)
......@@ -851,6 +799,9 @@ namespace XPS
pRenderer->EndCommand(c_nPathType);
pRenderer->PathCommandEnd();
if (bPathTransform)
pState->PopTransform();
if (bTransform)
pState->PopTransform();
......@@ -860,7 +811,7 @@ namespace XPS
if (bOpacity)
pState->PopOpacity();
}
bool Page::FillToRenderer(XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer)
bool Page::FillToRenderer (XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState)
{
if (!oReader.IsEmptyNode())
{
......@@ -879,7 +830,7 @@ namespace XPS
GetBgra(wsColor, nBgr, nAlpha);
pRenderer->put_BrushType(c_BrushTypeSolid);
pRenderer->put_BrushColor1(nBgr & 0x00FFFFFF);
pRenderer->put_BrushAlpha1(nAlpha);
pRenderer->put_BrushAlpha1((double)nAlpha * pState->GetCurrentOpacity());
return true;
}
else if (L"ImageBrush" == wsNodeName)
......@@ -895,124 +846,46 @@ namespace XPS
return false;
}
void Page::ReadPathData(XmlUtils::CXmlLiteReader& oReader, std::wstring& wsData)
bool Page::StrokeToRenderer(XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState)
{
wsData = L"";
if (oReader.IsEmptyNode())
return;
CWString wsNodeName;
int nCurDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nCurDepth))
if (!oReader.IsEmptyNode())
{
wsNodeName = oReader.GetName();
if (wsNodeName == L"PathGeometry")
std::wstring wsNodeName;
int nCurDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nCurDepth))
{
return ReadPathGeometry(oReader, wsData);
}
}
}
void Page::ReadPathGeometry(XmlUtils::CXmlLiteReader& oReader, std::wstring& wsData)
{
if (oReader.IsEmptyNode())
return;
std::wstring wsFillMode;
ReadAttribute(oReader, L"FillRule", wsFillMode);
if (L"EvenOdd" == wsFillMode)
wsData += L"F 0 ";
else
wsData += L"F 1 ";
wsNodeName = oReader.GetName();
wsNodeName = RemoveNamespace(wsNodeName);
std::wstring wsNodeName;
int nCurDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nCurDepth))
{
wsNodeName = oReader.GetName();
if (L"PathFigure" == wsNodeName)
{
ReadPathFigure(oReader, wsData);
if (L"SolidColorBrush" == wsNodeName)
{
int nBgr, nAlpha;
std::wstring wsColor;
ReadAttribute(oReader, L"Color", wsColor);
GetBgra(wsColor, nBgr, nAlpha);
pRenderer->put_PenColor(nBgr & 0x00FFFFFF);
pRenderer->put_PenAlpha((double)nAlpha * pState->GetCurrentOpacity());
return true;
}
}
}
return false;
}
void Page::ReadPathFigure(XmlUtils::CXmlLiteReader& oReader, std::wstring& wsData)
void Page::ReadPathData(XmlUtils::CXmlLiteReader& oReader, CWString& wsData, CWString& wsTransform)
{
wsData = L"";
if (oReader.IsEmptyNode())
return;
std::wstring wsStartPoint;
ReadAttribute(oReader, L"StartPoint", wsStartPoint);
wsData += L" M " + wsStartPoint;
std::wstring wsNodeName;
std::wstring wsText;
CWString wsNodeName;
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;
}
if (wsNodeName == L"PathGeometry")
return ReadPathGeometry(oReader, wsData, wsTransform);
}
std::wstring wsClosed;
ReadAttribute(oReader, L"IsClosed", wsClosed);
if (GetBool(wsClosed))
wsData += L" Z ";
}
}
\ No newline at end of file
......@@ -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