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

Открытие всех Xml переделано на XmlLiteReader. Класс Folder переименован в...

Открытие всех Xml переделано на XmlLiteReader. Класс Folder переименован в CDocument. Сделано, чтобы темповая папка создавалась новая, если с таким именем уже есть.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63359 954022d7-b5bf-4e40-9824-e11837661b57
parent 3959b216
#include "XpsFile.h"
#include "XpsLib/Folder.h"
#include "XpsLib/Document.h"
#include "../DesktopEditor/common/File.h"
#include "../DesktopEditor/common/Directory.h"
#include "../DesktopEditor/fontengine/FontManager.h"
#include "../DesktopEditor/fontengine/ApplicationFonts.h"
#include "../DesktopEditor/graphics/GraphicsRenderer.h"
#include "../PdfWriter/PdfRenderer.h"
#include "../ASCOfficeUtils/ASCOfficeUtilsLib/OfficeUtils.h"
......@@ -13,11 +14,6 @@ using namespace XPS;
CXpsFile::CXpsFile(CApplicationFonts* pAppFonts)
{
std::wstring wsTemp = NSFile::CFileBinary::GetTempPath();
wsTemp += L"/XPS/";
m_wsTempDirectory = wsTemp;
NSDirectory::CreateDirectory(m_wsTempDirectory);
m_pAppFonts = pAppFonts;
//
......@@ -25,23 +21,35 @@ CXpsFile::CXpsFile(CApplicationFonts* pAppFonts)
CFontsCache* pMeasurerCache = new CFontsCache();
pMeasurerCache->SetStreams(pAppFonts->GetStreams());
m_pFontManager->SetOwnerCache(pMeasurerCache);
m_wsTempFolder = L"";
SetTempFolder(NSFile::CFileBinary::GetTempPath());
}
CXpsFile::~CXpsFile()
{
if (L"" != m_wsTempFolder)
NSDirectory::DeleteDirectory(m_wsTempFolder);
Close();
NSDirectory::DeleteDirectory(m_wsTempDirectory);
RELEASEINTERFACE(m_pFontManager);
}
std::wstring CXpsFile::GetTempDirectory() const
std::wstring CXpsFile::GetTempFolder() const
{
return m_wsTempDirectory;
return m_wsTempFolder;
}
void CXpsFile::SetTempDirectory(const std::wstring& wsDirectory)
void CXpsFile::SetTempFolder(const std::wstring& wsPath)
{
NSDirectory::DeleteDirectory(m_wsTempDirectory);
m_wsTempDirectory = wsDirectory;
m_wsTempDirectory += L"/XPS/";
NSDirectory::CreateDirectory(m_wsTempDirectory);
if (L"" != m_wsTempFolder)
NSDirectory::DeleteDirectory(m_wsTempFolder);
int nCounter = 0;
m_wsTempFolder = wsPath + L"\\XPS\\";
while (NSDirectory::Exists(m_wsTempFolder))
{
m_wsTempFolder = wsPath + L"\\XPS" + std::to_wstring(nCounter) + L"\\";
nCounter++;
}
NSDirectory::CreateDirectory(m_wsTempFolder);
}
bool CXpsFile::LoadFromFile(const std::wstring& wsSrcFileName, const std::wstring& wsXmlOptions)
{
......@@ -49,52 +57,52 @@ bool CXpsFile::LoadFromFile(const std::wstring& wsSrcFileName, const std
// Zip-
COfficeUtils oUtils(NULL);
if (S_OK != oUtils.ExtractToDirectory(wsSrcFileName, m_wsTempDirectory, NULL, 0))
if (S_OK != oUtils.ExtractToDirectory(wsSrcFileName, m_wsTempFolder, NULL, 0))
return false;
m_pFolder = new XPS::Folder(m_pFontManager);
if (!m_pFolder)
m_pDocument = new XPS::CDocument(m_pFontManager);
if (!m_pDocument)
return false;
std::wstring wsPath = m_wsTempDirectory + L"/";
m_pFolder->ReadFromPath(wsPath);
std::wstring wsPath = m_wsTempFolder + L"/";
m_pDocument->ReadFromPath(wsPath);
return true;
}
void CXpsFile::Close()
{
if (m_pFolder)
if (m_pDocument)
{
m_pFolder->Close();
delete m_pFolder;
m_pFolder = NULL;
m_pDocument->Close();
delete m_pDocument;
m_pDocument = NULL;
}
}
int CXpsFile::GetPagesCount()
{
if (!m_pFolder)
if (!m_pDocument)
return 0;
return m_pFolder->GetPageCount();
return m_pDocument->GetPageCount();
}
void CXpsFile::GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY)
{
int nW = 0, nH = 0;
if (m_pFolder)
m_pFolder->GetPageSize(nPageIndex, nW, nH);
if (m_pDocument)
m_pDocument->GetPageSize(nPageIndex, nW, nH);
*pdWidth = nW * 25.4 / 96;
*pdHeight = nH * 25.4 / 96;
*pdDpiX = 96;
*pdDpiY = 96;
*pdDpiX = 25.4;
*pdDpiY = 25.4;
}
void CXpsFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak)
{
if (!m_pFolder)
if (!m_pDocument)
return;
m_pFolder->DrawPage(nPageIndex, pRenderer, pBreak);
m_pDocument->DrawPage(nPageIndex, pRenderer, pBreak);
}
void CXpsFile::ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType)
{
......@@ -135,3 +143,35 @@ void CXpsFile::ConvertToRaster(int nPageIndex, const std::wstring& wsDst
oFrame.SaveFile(wsDstPath, nImageType);
RELEASEINTERFACE(pFontManager);
}
void CXpsFile::ConvertToPdf(const std::wstring& wsPath)
{
CPdfRenderer oPdf(m_pAppFonts);
bool bBreak = false;
int nPagesCount = GetPagesCount();
for (int nPageIndex = 0; nPageIndex < nPagesCount; nPageIndex++)
{
oPdf.NewPage();
oPdf.BeginCommand(c_nPageType);
double dPageDpiX, dPageDpiY;
double dWidth, dHeight;
GetPageInfo(nPageIndex, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY);
dWidth *= 25.4 / dPageDpiX;
dHeight *= 25.4 / dPageDpiY;
oPdf.put_Width(dWidth);
oPdf.put_Height(dHeight);
DrawPageOnRenderer(&oPdf, nPageIndex, &bBreak);
oPdf.EndCommand(c_nPageType);
#ifdef _DEBUG
printf("page %d / %d\n", nPageIndex + 1, nPagesCount);
#endif
}
oPdf.SaveToFile(wsPath);
}
\ No newline at end of file
......@@ -5,7 +5,7 @@
namespace XPS
{
class Folder;
class CDocument;
}
class IRenderer;
......@@ -20,19 +20,20 @@ public:
bool LoadFromFile(const std::wstring& wsSrcFileName, const std::wstring& wsXmlOptions = L"");
void Close();
std::wstring GetTempDirectory() const;
void SetTempDirectory(const std::wstring& wsPath);
std::wstring GetTempFolder() const;
void SetTempFolder(const std::wstring& wsPath);
int GetPagesCount();
void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY);
void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
void ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType);
void ConvertToPdf(const std::wstring& wsDstPath);
private:
CApplicationFonts* m_pAppFonts;
CFontManager* m_pFontManager;
std::wstring m_wsTempDirectory;
XPS::Folder* m_pFolder;
std::wstring m_wsTempFolder;
XPS::CDocument* m_pDocument;
};
#endif // _XPS_FILE_H
\ No newline at end of file
......@@ -42,7 +42,8 @@ Global
{84BACD6F-275B-4C60-AC5A-F541919728C5}.Release|Mixed Platforms.Build.0 = Release|Win32
{84BACD6F-275B-4C60-AC5A-F541919728C5}.Release|Win32.ActiveCfg = Release|Win32
{84BACD6F-275B-4C60-AC5A-F541919728C5}.Release|Win32.Build.0 = Release|Win32
{84BACD6F-275B-4C60-AC5A-F541919728C5}.Release|x64.ActiveCfg = Release|Win32
{84BACD6F-275B-4C60-AC5A-F541919728C5}.Release|x64.ActiveCfg = Release|x64
{84BACD6F-275B-4C60-AC5A-F541919728C5}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -123,8 +123,9 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;UNICODE;_UNICODE;_USE_LIBXML2_READER_;LIBXML_READER_ENABLED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\Common\DocxFormat\Source\XML\libxml2\XML\include;D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\DesktopEditor\freetype-2.5.2\include;D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\DesktopEditor\agg-2.4\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
......@@ -139,14 +140,14 @@
<ItemGroup>
<ClCompile Include="XpsFile.cpp" />
<ClCompile Include="XpsLib\ContextState.cpp" />
<ClCompile Include="XpsLib\Folder.cpp" />
<ClCompile Include="XpsLib\Document.cpp" />
<ClCompile Include="XpsLib\Page.cpp" />
<ClCompile Include="XpsLib\Utils.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="XpsFile.h" />
<ClInclude Include="XpsLib\ContextState.h" />
<ClInclude Include="XpsLib\Folder.h" />
<ClInclude Include="XpsLib\Document.h" />
<ClInclude Include="XpsLib\FontList.h" />
<ClInclude Include="XpsLib\Page.h" />
<ClInclude Include="XpsLib\Utils.h" />
......
......@@ -12,6 +12,8 @@
#include "../../DesktopEditor/common/String.h"
#include "../../DesktopEditor/fontengine/ApplicationFonts.h"
#include <iostream>
std::vector<std::wstring> GetAllFilesInFolder(std::wstring wsFolder, std::wstring wsExt)
{
std::vector<std::wstring> vwsNames;
......@@ -35,9 +37,13 @@ std::vector<std::wstring> GetAllFilesInFolder(std::wstring wsFolder, std::wstrin
}
return vwsNames;
}
void ConvertFolder(CXpsFile& oReader, std::wstring wsFolderPath)
void ConvertFolderToRaster(const std::wstring& wsFolderPath)
{
oReader.Close();
CApplicationFonts oFonts;
oFonts.Initialize();
CXpsFile oReader(&oFonts);
oReader.SetTempFolder(L"D:/Test Files/Temp/");
std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, L"xps");
for (int nIndex = 0; nIndex < vFiles.size(); nIndex++)
......@@ -63,14 +69,39 @@ void ConvertFolder(CXpsFile& oReader, std::wstring wsFolderPath)
}
}
}
void ConvertFolderToPdf(const std::wstring& wsFolderPath)
{
CApplicationFonts oFonts;
oFonts.Initialize();
CXpsFile oReader(&oFonts);
oReader.SetTempFolder(L"D:/Test Files/Temp/");
std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, L"xps");
for (int nIndex = 0; nIndex < vFiles.size(); nIndex++)
{
std::wstring wsFilePath = wsFolderPath;
wsFilePath.append(vFiles.at(nIndex));
std::wstring wsFilePathName = (wsFilePath.substr(0, wsFilePath.size() - 4));
if (oReader.LoadFromFile(wsFilePath.c_str()))
{
printf("%d of %d %S\n", nIndex + 1, vFiles.size(), vFiles.at(nIndex).c_str());
std::wstring wsDstFilePath = wsFilePathName + L".pdf";
oReader.ConvertToPdf(wsDstFilePath);
oReader.Close();
}
else
{
printf("%d of %d %S error\n", nIndex, vFiles.size(), vFiles.at(nIndex).c_str());
}
}
}
void main()
{
CApplicationFonts oFonts;
oFonts.Initialize();
//ConvertFolderToRaster(L"D:/Test Files//Xps//");
ConvertFolderToPdf(L"D:/Test Files//Xps//");
CXpsFile oFile(&oFonts);
oFile.SetTempDirectory(L"D:/Test Files/Temp/");
ConvertFolder(oFile, L"D:/Test Files//");
char q;
std::cin >> q;
}
......@@ -129,8 +129,9 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;UNICODE;_UNICODE;_USE_LIBXML2_READER_;LIBXML_READER_ENABLED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\DesktopEditor\freetype-2.5.2\include;D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\DesktopEditor\agg-2.4\include;D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\Common\DocxFormat\Source\XML\libxml2\XML\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
......@@ -149,12 +150,15 @@
<ItemGroup>
<ClCompile Include="..\..\Common\DocxFormat\Source\Base\unicode_util.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\..\Common\DocxFormat\Source\XML\libxml2\libxml2.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\..\Common\DocxFormat\Source\XML\stringcommon.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
......
......@@ -10,13 +10,17 @@
#include <stdio.h>
#ifdef _DEBUG
#pragma comment(lib, "../x64/Debug/XpsFile.lib")
#pragma comment(lib, "../../Common/DocxFormat/Source/XML/libxml2/win_build/x64/Debug/libxml2.lib")
#pragma comment(lib, "../../ASCOfficeUtils/ASCOfficeUtilsLib/Win/x64/Debug/ASCOfficeUtilsLib.lib")
#pragma comment(lib, "../x64/Debug/XpsFile.lib")
#pragma comment(lib, "../../DesktopEditor/Qt_build/graphics/project/debug/graphics.lib")
#pragma comment(lib, "../../PdfWriter/x64/Debug/PdfWriter.lib")
#else
#pragma comment(lib, "../x64/Release/XpsFile.lib")
#pragma comment(lib, "../../Common/DocxFormat/Source/XML/libxml2/win_build/x64/Release/libxml2.lib")
#pragma comment(lib, "../../ASCOfficeUtils/ASCOfficeUtilsLib/Win/x64/Release/ASCOfficeUtilsLib.lib")
#pragma comment(lib, "../../DesktopEditor/Qt_build/graphics/project/release/graphics.lib")
#pragma comment(lib, "../../PdfWriter/x64/Release/PdfWriter.lib")
#endif
......
#include "Document.h"
#include "../../Common/DocxFormat/Source/XML/xmlutils.h"
namespace XPS
{
CDocument::CDocument(CFontManager* pFontManager)
{
m_pFontManager = pFontManager;
m_mPages.clear();
}
CDocument::~CDocument()
{
Close();
}
bool CDocument::ReadFromPath(const std::wstring& wsPath)
{
Close();
m_wsPath = wsPath;
XmlUtils::CXmlLiteReader oReader;
std::wstring wsRelsPath = NormalizePath(wsPath + L"_rels/.rels");
clock_t oBeginTime = clock();
if (!oReader.FromFile(wsRelsPath))
return false;
clock_t oEndTime = clock();
double dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC;
printf("%S %fseconds\n", wsRelsPath.c_str(), dElapsedSecs);
if (!oReader.ReadNextNode())
return false;
std::wstring wsName = oReader.GetName();
if (L"Relationships" != wsName)
return false;
std::wstring wsFile;
while (oReader.ReadNextNode())
{
wsName = oReader.GetName();
if (L"Relationship" == wsName)
{
std::wstring wsAttr;
ReadAttribute(oReader, L"Type", wsAttr);
if (L"http://schemas.microsoft.com/xps/2005/06/fixedrepresentation" == wsAttr)
{
ReadAttribute(oReader, L"Target", wsFile);
break;
}
}
}
if (wsFile.empty())
return false;
oReader.Clear();
oBeginTime = clock();
if (!oReader.FromFile(wsPath + wsFile))
return false;
oEndTime = clock();
dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC;
printf("%S %fseconds\n", (wsPath + wsFile).c_str(), dElapsedSecs);
if (!oReader.ReadNextNode())
return false;
wsName = oReader.GetName();
if (L"FixedDocumentSequence" != wsName)
return false;
wsFile.clear();
while (oReader.ReadNextNode())
{
wsName = oReader.GetName();
if (L"DocumentReference" == wsName)
{
ReadAttribute(oReader, L"Source", wsFile);
break;
}
}
if (wsFile.empty())
return false;
oReader.Clear();
oBeginTime = clock();
if (!oReader.FromFile(m_wsPath + wsFile))
return false;
oEndTime = clock();
dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC;
printf("%S %fseconds\n", (m_wsPath + wsFile).c_str(), dElapsedSecs);
if (!oReader.ReadNextNode())
return false;
wsName = oReader.GetName();
if (L"FixedDocument" != wsName)
return false;
std::wstring wsFilePath = GetPath(m_wsPath + wsFile);
std::wstring wsPagePath;
std::wstring wsSource;
int nIndex = 0;
while (oReader.ReadNextNode())
{
wsName = oReader.GetName();
if (L"PageContent" == wsName)
{
ReadAttribute(oReader, L"Source", wsSource);
if ('/' == wsSource[0])
wsPagePath = m_wsPath + wsSource;
else
wsPagePath = wsFilePath + wsSource;
m_mPages.insert(std::pair<int, XPS::Page*>(nIndex++, new XPS::Page(wsPagePath, wsPath, &m_oFontList, m_pFontManager, this)));
}
}
return true;
//Close();
//m_wsPath = wsPath;
//XmlUtils::CXmlNode oNode;
//XmlUtils::CXmlNodes arrNodes;
//XmlUtils::CXmlNode oSubnode;
//
//std::wstring wsRelsPath = NormalizePath(wsPath + L"_rels/.rels");
//clock_t oBeginTime = clock();
//if (!oNode.FromXmlFile(wsRelsPath.c_str()))
// return false;
//clock_t oEndTime = clock();
//double dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC;
//printf("%S %fseconds\n", wsRelsPath.c_str(), dElapsedSecs);
//// Checking root node
//if (L"Relationships" != oNode.GetName())
// return false;
//if (!oNode.GetNodes(L"Relationship", arrNodes))
// return false;
//std::wstring wsFile;
//for (int nIndex = 0, nCount = arrNodes.GetCount(); nIndex < nCount; nIndex++)
//{
// arrNodes.GetAt(nIndex, oNode);
// if (L"http://schemas.microsoft.com/xps/2005/06/fixedrepresentation" == oNode.GetAttribute(L"Type"))
// {
// wsFile = oNode.GetAttribute(L"Target");
// break;
// }
// if (nIndex == nCount - 1)
// return false;
//}
//oBeginTime = clock();
//if (!oNode.FromXmlFile((wsPath + wsFile).c_str()))
// return false;
//oEndTime = clock();
//dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC;
//printf("%S %fseconds\n", (wsPath + wsFile).c_str(), dElapsedSecs);
//// Checking root node
//if (L"FixedDocumentSequence" != oNode.GetName())
// return false;
//if (!oNode.GetNode(L"DocumentReference", oSubnode))
// return false;
//wsFile = oSubnode.GetAttribute(L"Source");
//oBeginTime = clock();
//if (!oNode.FromXmlFile((m_wsPath + wsFile).c_str()))
// return false;
//oEndTime = clock();
//dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC;
//printf("%S %fseconds\n", (m_wsPath + wsFile).c_str(), dElapsedSecs);
//if (L"FixedDocument" != oNode.GetName())
// return false;
//if (!oNode.GetNodes(L"PageContent", arrNodes))
// return false;
//std::wstring wsFilePath = GetPath(m_wsPath + wsFile);
//std::wstring wsPagePath;
//std::wstring wsSource;
//for (int nIndex = 0, nCount = arrNodes.GetCount(); nIndex < nCount; nIndex++)
//{
// arrNodes.GetAt(nIndex, oNode);
// wsSource = oNode.GetAttribute(L"Source");
// if('/' == wsSource[0])
// wsPagePath = m_wsPath + wsSource;
// else
// wsPagePath = wsFilePath + wsSource;
// m_mPages.insert(std::pair<int, XPS::Page*>(nIndex, new XPS::Page(wsPagePath, wsPath, &m_oFontList, m_pFontManager)));
//}
//return true;
}
int CDocument::GetPageCount()const
{
return (int)m_mPages.size();
}
void CDocument::GetPageSize(int nPageIndex, int& nW, int& nH)
{
std::map<int, XPS::Page*>::const_iterator oIter = m_mPages.find(nPageIndex);
if (oIter != m_mPages.end())
oIter->second->GetSize(nW, nH);
}
void CDocument::DrawPage(int nPageIndex, IRenderer* pRenderer, bool* pbBreak)
{
std::map<int, XPS::Page*>::const_iterator oIter = m_mPages.find(nPageIndex);
if (oIter != m_mPages.end())
oIter->second->Draw(pRenderer, pbBreak);
}
void CDocument::Close()
{
for (std::map<int, XPS::Page*>::iterator oIter = m_mPages.begin(); oIter != m_mPages.end(); oIter++)
{
if (oIter->second)
delete oIter->second;
}
m_mPages.clear();
m_oFontList.Clear();
}
}
\ No newline at end of file
#ifndef _XPS_XPSLIB_FOLDER_H
#define _XPS_XPSLIB_FOLDER_H
#ifndef _XPS_XPSLIB_DOCUMENT_H
#define _XPS_XPSLIB_DOCUMENT_H
#include "FontList.h"
#include "Page.h"
......@@ -15,11 +15,11 @@
namespace XPS
{
class Folder
class CDocument
{
public:
Folder(CFontManager* pFontManager);
~Folder();
CDocument(CFontManager* pFontManager);
~CDocument();
bool ReadFromPath(const std::wstring& wsPath);
int GetPageCount() const;
......@@ -36,4 +36,4 @@ namespace XPS
};
}
#endif //_XPS_XPSLIB_FOLDER_H
\ No newline at end of file
#endif //_XPS_XPSLIB_DOCUMENT_H
\ No newline at end of file
#include "Folder.h"
#include "../../Common/DocxFormat/Source/XML/xmlutils.h"
namespace XPS
{
Folder::Folder(CFontManager* pFontManager)
{
m_pFontManager = pFontManager;
m_mPages.clear();
}
Folder::~Folder()
{
Close();
}
bool Folder::ReadFromPath(const std::wstring& wsPath)
{
Close();
m_wsPath = wsPath;
XmlUtils::CXmlNode oNode;
XmlUtils::CXmlNodes arrNodes;
XmlUtils::CXmlNode oSubnode;
std::wstring wsRelsPath = NormalizePath(wsPath + L"_rels/.rels");
if (!oNode.FromXmlFile(wsRelsPath.c_str()))
return false;
// Checking root node
if (L"Relationships" != oNode.GetName())
return false;
if (!oNode.GetNodes(L"Relationship", arrNodes))
return false;
std::wstring wsFile;
for (int nIndex = 0, nCount = arrNodes.GetCount(); nIndex < nCount; nIndex++)
{
arrNodes.GetAt(nIndex, oNode);
if (L"http://schemas.microsoft.com/xps/2005/06/fixedrepresentation" == oNode.GetAttribute(L"Type"))
{
wsFile = oNode.GetAttribute(L"Target");
break;
}
if (nIndex == nCount - 1)
return false;
}
if (!oNode.FromXmlFile((wsPath + wsFile).c_str()))
return false;;
// Checking root node
if (L"FixedDocumentSequence" != oNode.GetName())
return false;
if (!oNode.GetNode(L"DocumentReference", oSubnode))
return false;
wsFile = oSubnode.GetAttribute(L"Source");
if (!oNode.FromXmlFile((m_wsPath + wsFile).c_str()))
return false;
if (L"FixedDocument" != oNode.GetName())
return false;
if (!oNode.GetNodes(L"PageContent", arrNodes))
return false;
std::wstring wsFilePath = GetPath(m_wsPath + wsFile);
std::wstring wsPagePath;
std::wstring wsSource;
for (int nIndex = 0, nCount = arrNodes.GetCount(); nIndex < nCount; nIndex++)
{
arrNodes.GetAt(nIndex, oNode);
wsSource = oNode.GetAttribute(L"Source");
if('/' == wsSource[0])
wsPagePath = m_wsPath + wsSource;
else
wsPagePath = wsFilePath + wsSource;
m_mPages.insert(std::pair<int, XPS::Page*>(nIndex, new XPS::Page(wsPagePath, wsPath, &m_oFontList, m_pFontManager)));
}
return true;
}
int Folder::GetPageCount()const
{
return (int)m_mPages.size();
}
void Folder::GetPageSize(int nPageIndex, int& nW, int& nH)
{
std::map<int, XPS::Page*>::const_iterator oIter = m_mPages.find(nPageIndex);
if (oIter != m_mPages.end())
oIter->second->GetSize(nW, nH);
}
void Folder::DrawPage(int nPageIndex, IRenderer* pRenderer, bool* pbBreak)
{
std::map<int, XPS::Page*>::const_iterator oIter = m_mPages.find(nPageIndex);
if (oIter != m_mPages.end())
oIter->second->Draw(pRenderer, pbBreak);
}
void Folder::Close()
{
for (std::map<int, XPS::Page*>::iterator oIter = m_mPages.begin(); oIter != m_mPages.end(); oIter++)
{
if (oIter->second)
delete oIter->second;
}
m_mPages.clear();
m_oFontList.Clear();
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -11,10 +11,12 @@
namespace XPS
{
class CDocument;
class Page
{
public:
Page(const std::wstring& wsFile, const std::wstring& Path, CFontList* pFontList, CFontManager* pFontManager);
Page(const std::wstring& wsFile, const std::wstring& Path, CFontList* pFontList, CFontManager* pFontManager, CDocument* pDocument);
~Page();
void GetSize(int& nW, int& nH) const;
......@@ -22,14 +24,24 @@ 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);
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 GetDataFromNode(std::wstring& wsString, XmlUtils::CXmlNode& oNode);
void TransformToRenderer(const std::wstring& wsString, IRenderer* pRenderer, CContextState* pState);
void ResetTransform(IRenderer* pRenderer, CContextState* pState);
......@@ -41,6 +53,7 @@ namespace XPS
std::wstring m_wsRootPath;
CFontList* m_pFontList;
CFontManager* m_pFontManager;
CDocument* m_pDocument;
};
}
......
#include "Utils.h"
#include "../../DesktopEditor/common/String.h"
#include "../../DesktopEditor/common/Types.h"
#include "../../Common/DocxFormat/Source/XML/xmlutils.h"
namespace XPS
{
......@@ -149,4 +150,29 @@ namespace XPS
}
return arrResult;
}
void ReadAttribute(XmlUtils::CXmlLiteReader& oReader, const wchar_t* wsAttrName, std::wstring& wsAttr)
{
if (oReader.GetAttributesCount() <= 0)
return;
if (!oReader.MoveToFirstAttribute())
return;
std::wstring wsName = oReader.GetName();
while (!wsName.empty())
{
if (wsAttrName == wsName)
{
wsAttr = oReader.GetText();
break;
}
if (!oReader.MoveToNextAttribute())
break;
wsName = oReader.GetName();
}
oReader.MoveToElement();
}
}
\ No newline at end of file
......@@ -4,6 +4,11 @@
#include <string>
#include <vector>
namespace XmlUtils
{
class CXmlLiteReader;
}
namespace XPS
{
bool IsAlpha(wchar_t wChar);
......@@ -19,6 +24,8 @@ namespace XPS
std::wstring RemoveNamespace(const std::wstring& wsString);
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);
}
#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