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

Исправлен баг с тем что неработал клип у патов, немного переделана схема...

Исправлен баг с тем что неработал клип у патов, немного переделана схема работы со стеком трансформов, на манер клипов. Добавлен класс для чтения статических ресурсов, теперь отдельный файл читается только 1 раз, а не как раньше заново на каждой странице. Полностью переделан парсинг строки с патом, теперь он быстрый и делается за один проход строки. Удалены старые функции чтения Xml, теперь только новые через XmlLiteReader. Доработано чтение пунктирных линий, стилей окончания и соединения линий. 

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63410 954022d7-b5bf-4e40-9824-e11837661b57
parent a2f0d339
......@@ -13,6 +13,7 @@
#include "../../DesktopEditor/fontengine/ApplicationFonts.h"
#include <iostream>
#include <ctime>
std::vector<std::wstring> GetAllFilesInFolder(std::wstring wsFolder, std::wstring wsExt)
{
......@@ -99,9 +100,15 @@ void ConvertFolderToPdf(const std::wstring& wsFolderPath)
void main()
{
clock_t oBeginTime = clock();
//ConvertFolderToRaster(L"D:/Test Files//Xps//");
ConvertFolderToPdf(L"D:/Test Files//Xps//");
clock_t oEndTime = clock();
double dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC;
printf("%fseconds\n", dElapsedSecs);
char q;
std::cin >> q;
}
......@@ -6,35 +6,27 @@
namespace XPS
{
CContextState::CContextState() : m_oCurrentTransform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
CContextState::CContextState(IRenderer* pRenderer) : m_oCurrentTransform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0), m_pRenderer(pRenderer)
{
m_lTransformStack.push_back(m_oCurrentTransform);
}
CContextState::~CContextState()
{
}
void CContextState::AddFigure(const std::wstring& wsKey, const std::wstring& wsValue)
{
m_mFigures.insert(std::pair<std::wstring, std::wstring>(wsKey, wsValue));
}
std::wstring CContextState::GetFigure(const std::wstring& wsKey)
{
std::map<std::wstring, std::wstring>::iterator oIter = m_mFigures.find(wsKey);
if (oIter != m_mFigures.end())
return oIter->second;
return L"";
}
m_vClipStack.clear();
m_lTransformStack.clear();
}
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()
{
m_lTransformStack.pop_back();
m_oCurrentTransform = m_lTransformStack.back();
SetTransformToRenderer();
}
double CContextState::NormalizeTransform()
{
......@@ -46,13 +38,51 @@ namespace XPS
oMatrix.sy /= dDet;
oMatrix.shy /= dDet;
SetTransformToRenderer();
return dDet;
}
void CContextState::SetTransformToRenderer(IRenderer* pRenderer)
void CContextState::PushClip(const CWString& wsClip)
{
m_vClipStack.push_back(wsClip);
SetClipToRenderer(wsClip);
}
void CContextState::PopClip()
{
pRenderer->SetTransform(m_oCurrentTransform.m_agg_mtx.sx, m_oCurrentTransform.m_agg_mtx.shy,
m_oCurrentTransform.m_agg_mtx.shx, m_oCurrentTransform.m_agg_mtx.sy,
xpsUnitToMM(m_oCurrentTransform.m_agg_mtx.tx), xpsUnitToMM(m_oCurrentTransform.m_agg_mtx.ty));
m_vClipStack.pop_back();
if (m_pRenderer)
{
m_pRenderer->BeginCommand(c_nResetClipType);
m_pRenderer->EndCommand(c_nResetClipType);
for (int nIndex = 0, nCount = m_vClipStack.size(); nIndex < nCount; nIndex++)
{
CWString wsClip = m_vClipStack.at(nIndex);
SetClipToRenderer(wsClip);
}
}
}
void CContextState::SetTransformToRenderer()
{
if (m_pRenderer)
{
m_pRenderer->SetTransform(m_oCurrentTransform.m_agg_mtx.sx, m_oCurrentTransform.m_agg_mtx.shy,
m_oCurrentTransform.m_agg_mtx.shx, m_oCurrentTransform.m_agg_mtx.sy,
xpsUnitToMM(m_oCurrentTransform.m_agg_mtx.tx), xpsUnitToMM(m_oCurrentTransform.m_agg_mtx.ty));
}
}
void CContextState::SetClipToRenderer(const CWString& wsClip)
{
if (!wsClip.empty() && m_pRenderer)
{
m_pRenderer->PathCommandStart();
m_pRenderer->BeginCommand(c_nClipType);
m_pRenderer->BeginCommand(c_nPathType);
bool bWinding = VmlToRenderer(wsClip.c_str(), m_pRenderer);
m_pRenderer->put_ClipMode(bWinding ? c_nClipRegionTypeWinding : c_nClipRegionTypeEvenOdd);
m_pRenderer->EndCommand(c_nPathType);
m_pRenderer->EndCommand(c_nClipType);
m_pRenderer->PathCommandEnd();
}
}
}
\ No newline at end of file
#ifndef _XPS_XPSLIB_CONTEXTSTATE_H
#define _XPS_XPSLIB_CONTEXTSTATE_H
#include "Utils.h"
#include "../../DesktopEditor/graphics/Matrix.h"
#include "../../DesktopEditor/graphics/IRenderer.h"
......@@ -13,21 +15,26 @@ namespace XPS
{
public:
CContextState();
CContextState(IRenderer* pRenderer);
~CContextState();
void AddFigure(const std::wstring& wsKey, const std::wstring& wsName);
std::wstring GetFigure(const std::wstring& wsKey);
void PushTransform(const double arrTransform[6]);
void PopTransform();
void PushClip(const CWString& wsClip);
void PopClip();
void PushTransform(const double arrTransform[6]);
void PopTransform();
double NormalizeTransform();
void SetTransformToRenderer(IRenderer* pRenderer);
public:
private:
void SetClipToRenderer(const CWString& wsClip);
void SetTransformToRenderer();
private:
Aggplus::CMatrix m_oCurrentTransform;
std::list<Aggplus::CMatrix> m_lTransformStack;
std::map<std::wstring, std::wstring> m_mFigures;
Aggplus::CMatrix m_oCurrentTransform;
std::list<Aggplus::CMatrix> m_lTransformStack;
std::vector<CWString> m_vClipStack;
IRenderer* m_pRenderer;
};
}
......
......@@ -249,5 +249,24 @@ namespace XPS
}
m_mPages.clear();
m_oFontList.Clear();
for (std::map<std::wstring, CStaticResource*>::iterator oIter = m_mStaticResources.begin(); oIter != m_mStaticResources.end(); oIter++)
{
if (oIter->second)
delete oIter->second;
}
m_mStaticResources.clear();
}
CStaticResource* CDocument::GetStaticResource(const std::wstring& wsPath)
{
for (auto oIt : m_mStaticResources)
{
if (oIt.first == wsPath)
return oIt.second;
}
CStaticResource* pStaticResource = new CStaticResource(wsPath);
m_mStaticResources.insert(std::pair<std::wstring, CStaticResource*>(wsPath, pStaticResource));
return pStaticResource;
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@
#include "FontList.h"
#include "Page.h"
#include <map>
#include <vector>
#define UNICODE
#define _UNICODE
......@@ -15,6 +16,8 @@
namespace XPS
{
class CPath;
class CStaticResource;
class CDocument
{
public:
......@@ -26,13 +29,109 @@ 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);
private:
std::wstring m_wsPath;
std::map<int, XPS::Page*> m_mPages;
CFontList m_oFontList;
CFontManager* m_pFontManager;
std::wstring m_wsPath;
std::map<int, XPS::Page*> m_mPages;
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;
};
}
......
This diff is collapsed.
......@@ -12,6 +12,7 @@
namespace XPS
{
class CDocument;
class CStaticResource;
class Page
{
......@@ -24,36 +25,30 @@ namespace XPS
private:
void DrawCanvas(XmlUtils::CXmlLiteReader& oReader, IRenderer* pRenderer, CContextState* pState, bool* pbBreak);
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);
void CanvasTransform(XmlUtils::CXmlLiteReader& oRNode, 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::CXmlNode& oNode, IRenderer* pRenderer, CContextState* pState, bool* pbBreak);
void DrawGlyph(XmlUtils::CXmlNode& oNode, IRenderer* pRenderer, CContextState* pState);
void DrawPath(XmlUtils::CXmlNode& oNode, IRenderer* pRenderer, CContextState* pState);
void CanvasTransform(XmlUtils::CXmlNode& oNode, IRenderer* pRenderer, CContextState* pState);
void FillToRenderer(XmlUtils::CXmlNode& oNode, IRenderer* pRenderer);
void GetDataFromNode(std::wstring& wsString, XmlUtils::CXmlNode& oNode);
bool VmlToRenderer(std::wstring& wsValue, IRenderer* pRenderer);
void TransformToRenderer(const std::wstring& wsString, IRenderer* pRenderer, CContextState* pState);
void ResetTransform(IRenderer* pRenderer, CContextState* pState);
void PrepareVmlString(std::wstring& wsString);
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);
bool ClipToRenderer (const wchar_t* wsString, CContextState* pState);
bool TransformToRenderer(const wchar_t* wsString, CContextState* pState);
private:
std::wstring m_wsPagePath;
std::wstring m_wsRootPath;
CFontList* m_pFontList;
CFontManager* m_pFontManager;
CDocument* m_pDocument;
std::wstring m_wsPagePath;
std::wstring m_wsRootPath;
CFontList* m_pFontList;
CFontManager* m_pFontManager;
CDocument* m_pDocument;
CStaticResource* m_pStaticResource;
bool m_bDeleteStaticResource;
int m_nCounter;
};
}
......
This diff is collapsed.
......@@ -9,14 +9,48 @@ namespace XmlUtils
class CXmlLiteReader;
}
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;
};
bool IsAlpha(wchar_t wChar);
double GetDouble(const std::wstring& wsString);
int GetInteger(const std::wstring& wsString);
bool GetBool(const std::wstring& wsString);
void GetBgra(const std::wstring& wsString, int& nBgr, int& nAlpha);
unsigned char GetCapStyle(const wchar_t* wsCapStyle);
std::wstring NormalizePath(const std::wstring& wsPath);
std::wstring GetPath(const std::wstring& wsPath);
std::wstring GetFileName(const std::wstring& wsPath);
......@@ -26,6 +60,7 @@ namespace XPS
std::vector<std::vector<std::wstring>> Split(const std::wstring& wsString, wchar_t wDelim1, wchar_t wDelim2);
void ReadAttribute(XmlUtils::CXmlLiteReader& oReader, const wchar_t* wsAttrName, std::wstring& wsAttr);
bool VmlToRenderer(const wchar_t* wsString, IRenderer* pRenderer);
}
#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