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

Добавлен кроссплатформенный XpsFile.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62681 954022d7-b5bf-4e40-9824-e11837661b57
parent 485d09d6
...@@ -8679,6 +8679,9 @@ Test/HtmlTextEditor/Table/images/pencil.png svn_mime_002dtype=application%2Focte ...@@ -8679,6 +8679,9 @@ Test/HtmlTextEditor/Table/images/pencil.png svn_mime_002dtype=application%2Focte
Test/Units/DocxOdtTxt/OdtTemplate/Thumbnails/Thumbs.db svn_mime_002dtype=application%2Foctet-stream Test/Units/DocxOdtTxt/OdtTemplate/Thumbnails/Thumbs.db svn_mime_002dtype=application%2Foctet-stream
Test/Units/DocxOdtTxt/OdtTemplate/Thumbnails/thumbnail.png svn_mime_002dtype=application%2Foctet-stream Test/Units/DocxOdtTxt/OdtTemplate/Thumbnails/thumbnail.png svn_mime_002dtype=application%2Foctet-stream
Test/Units/DocxOdtTxt/image1.emf svn_mime_002dtype=application%2Foctet-stream Test/Units/DocxOdtTxt/image1.emf svn_mime_002dtype=application%2Foctet-stream
/XpsFile svnc_tsvn_003alogminsize=5
XpsFile/XpsFileTest svnc_tsvn_003alogminsize=5
XpsFile/XpsLib svnc_tsvn_003alogminsize=5
_tags/rev_61879/ASCHTMLRenderer/Resources/common.zip svn_mime_002dtype=application%2Foctet-stream _tags/rev_61879/ASCHTMLRenderer/Resources/common.zip svn_mime_002dtype=application%2Foctet-stream
_tags/rev_61879/ASCHTMLRenderer/Resources/imgtrackbar/b_bg_all.gif svn_mime_002dtype=application%2Foctet-stream _tags/rev_61879/ASCHTMLRenderer/Resources/imgtrackbar/b_bg_all.gif svn_mime_002dtype=application%2Foctet-stream
_tags/rev_61879/ASCHTMLRenderer/Resources/imgtrackbar/b_bg_off.gif svn_mime_002dtype=application%2Foctet-stream _tags/rev_61879/ASCHTMLRenderer/Resources/imgtrackbar/b_bg_off.gif svn_mime_002dtype=application%2Foctet-stream
#include "XpsFile.h"
#include "XpsLib/Folder.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 "../ASCOfficeUtils/ASCOfficeUtilsLib/OfficeUtils.h"
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;
//
m_pFontManager = pAppFonts->GenerateFontManager();
CFontsCache* pMeasurerCache = new CFontsCache();
pMeasurerCache->SetStreams(pAppFonts->GetStreams());
m_pFontManager->SetOwnerCache(pMeasurerCache);
}
CXpsFile::~CXpsFile()
{
Close();
NSDirectory::DeleteDirectory(m_wsTempDirectory);
RELEASEINTERFACE(m_pFontManager);
}
std::wstring CXpsFile::GetTempDirectory() const
{
return m_wsTempDirectory;
}
void CXpsFile::SetTempDirectory(const std::wstring& wsDirectory)
{
NSDirectory::DeleteDirectory(m_wsTempDirectory);
m_wsTempDirectory = wsDirectory;
m_wsTempDirectory += L"/XPS/";
NSDirectory::CreateDirectory(m_wsTempDirectory);
}
bool CXpsFile::LoadFromFile(const std::wstring& wsSrcFileName, const std::wstring& wsXmlOptions)
{
Close();
// Zip-
COfficeUtils oUtils(NULL);
if (S_OK != oUtils.ExtractToDirectory(wsSrcFileName, m_wsTempDirectory, NULL, 0))
return false;
m_pFolder = new XPS::Folder(m_pFontManager);
if (!m_pFolder)
return false;
std::wstring wsPath = m_wsTempDirectory + L"/";
m_pFolder->ReadFromPath(wsPath);
return true;
}
void CXpsFile::Close()
{
if (m_pFolder)
{
m_pFolder->Close();
delete m_pFolder;
m_pFolder = NULL;
}
}
int CXpsFile::GetPagesCount()
{
if (!m_pFolder)
return 0;
return m_pFolder->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);
*pdWidth = nW * 25.4 / 96;
*pdHeight = nH * 25.4 / 96;
*pdDpiX = 96;
*pdDpiY = 96;
}
void CXpsFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak)
{
if (!m_pFolder)
return;
m_pFolder->DrawPage(nPageIndex, pRenderer, pBreak);
}
void CXpsFile::ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType)
{
CFontManager *pFontManager = m_pAppFonts->GenerateFontManager();
CFontsCache* pFontCache = new CFontsCache();
pFontCache->SetStreams(m_pAppFonts->GetStreams());
pFontManager->SetOwnerCache(pFontCache);
CGraphicsRenderer oRenderer;
oRenderer.SetFontManager(pFontManager);
double dPageDpiX, dPageDpiY;
double dWidth, dHeight;
GetPageInfo(nPageIndex, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY);
int nWidth = (int)dWidth * 96 / dPageDpiX;
int nHeight = (int)dHeight * 96 / dPageDpiX;
BYTE* pBgraData = new BYTE[nWidth * nHeight * 4];
if (!pBgraData)
return;
memset(pBgraData, 0xff, nWidth * nHeight * 4);
CBgraFrame oFrame;
oFrame.put_Data(pBgraData);
oFrame.put_Width(nWidth);
oFrame.put_Height(nHeight);
oFrame.put_Stride(-4 * nWidth);
oRenderer.CreateFromBgraFrame(&oFrame);
oRenderer.SetSwapRGB(false);
oRenderer.put_Width(dWidth);
oRenderer.put_Height(dHeight);
bool bBreak = false;
DrawPageOnRenderer(&oRenderer, nPageIndex, &bBreak);
oFrame.SaveFile(wsDstPath, nImageType);
RELEASEINTERFACE(pFontManager);
}
\ No newline at end of file
#ifndef _XPS_FILE_H
#define _XPS_FILE_H
#include <string>
namespace XPS
{
class Folder;
}
class IRenderer;
class CApplicationFonts;
class CFontManager;
class CXpsFile
{
public:
CXpsFile(CApplicationFonts* pAppFonts);
~CXpsFile();
bool LoadFromFile(const std::wstring& wsSrcFileName, const std::wstring& wsXmlOptions = L"");
void Close();
std::wstring GetTempDirectory() const;
void SetTempDirectory(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);
private:
CApplicationFonts* m_pAppFonts;
CFontManager* m_pFontManager;
std::wstring m_wsTempDirectory;
XPS::Folder* m_pFolder;
};
#endif // _XPS_FILE_H
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XpsFile", "XpsFile.vcxproj", "{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XpsFileTest", "XpsFileTest\XpsFileTest.vcxproj", "{84BACD6F-275B-4C60-AC5A-F541919728C5}"
ProjectSection(ProjectDependencies) = postProject
{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B} = {DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}.Debug|Win32.ActiveCfg = Debug|Win32
{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}.Debug|Win32.Build.0 = Debug|Win32
{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}.Debug|x64.ActiveCfg = Debug|x64
{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}.Debug|x64.Build.0 = Debug|x64
{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}.Release|Mixed Platforms.Build.0 = Release|Win32
{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}.Release|Win32.ActiveCfg = Release|Win32
{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}.Release|Win32.Build.0 = Release|Win32
{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}.Release|x64.ActiveCfg = Release|x64
{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}.Release|x64.Build.0 = Release|x64
{84BACD6F-275B-4C60-AC5A-F541919728C5}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{84BACD6F-275B-4C60-AC5A-F541919728C5}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{84BACD6F-275B-4C60-AC5A-F541919728C5}.Debug|Win32.ActiveCfg = Debug|Win32
{84BACD6F-275B-4C60-AC5A-F541919728C5}.Debug|Win32.Build.0 = Debug|Win32
{84BACD6F-275B-4C60-AC5A-F541919728C5}.Debug|x64.ActiveCfg = Debug|x64
{84BACD6F-275B-4C60-AC5A-F541919728C5}.Debug|x64.Build.0 = Debug|x64
{84BACD6F-275B-4C60-AC5A-F541919728C5}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{DF16B0DF-A4CD-4389-B390-5ED72F4E2A2B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>XpsFile</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;UNICODE;_UNICODE;_USE_LIBXML2_READER_;LIBXML_READER_ENABLED</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>
<DisableSpecificWarnings>4267;4244;4800;4018;4005</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="XpsFile.cpp" />
<ClCompile Include="XpsLib\ContextState.cpp" />
<ClCompile Include="XpsLib\Folder.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\FontList.h" />
<ClInclude Include="XpsLib\Page.h" />
<ClInclude Include="XpsLib\Utils.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
// XpsFileTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "../XpsFile.h"
#include <vector>
#include <string>
#include "windows.h"
#include "../../DesktopEditor/common/String.h"
#include "../../DesktopEditor/fontengine/ApplicationFonts.h"
std::vector<std::wstring> GetAllFilesInFolder(std::wstring wsFolder, std::wstring wsExt)
{
std::vector<std::wstring> vwsNames;
std::wstring wsSearchPath = wsFolder;
wsSearchPath.append(L"*.");
wsSearchPath.append(wsExt);
WIN32_FIND_DATA oFindData;
HANDLE hFind = ::FindFirstFile(wsSearchPath.c_str(), &oFindData);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (!(oFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
vwsNames.push_back(oFindData.cFileName);
}
} while (::FindNextFile(hFind, &oFindData));
::FindClose(hFind);
}
return vwsNames;
}
void ConvertFolder(CXpsFile& oReader, std::wstring wsFolderPath)
{
oReader.Close();
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()))
{
int nPagesCount = oReader.GetPagesCount();
for (int nPageIndex = 0; nPageIndex < nPagesCount; nPageIndex++)
{
std::wstring wsDstFilePath = wsFilePathName + L"_" + std::to_wstring(nPageIndex) + L".png";
oReader.ConvertToRaster(nPageIndex, wsDstFilePath.c_str(), 4);
printf("%d of %d %S page %d / %d\n", nIndex, vFiles.size(), vFiles.at(nIndex).c_str(), nPageIndex, nPagesCount);
}
oReader.Close();
}
else
{
printf("%d of %d %S error\n", nIndex, vFiles.size(), vFiles.at(nIndex).c_str());
}
}
}
void main()
{
CApplicationFonts oFonts;
oFonts.Initialize();
CXpsFile oFile(&oFonts);
oFile.SetTempDirectory(L"D:/Test Files/Temp/");
ConvertFolder(oFile, L"D:/Test Files//");
}
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{84BACD6F-275B-4C60-AC5A-F541919728C5}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>XpsFileTest</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_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>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\Common\DocxFormat\Source\Base\unicode_util.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\..\Common\DocxFormat\Source\XML\libxml2\libxml2.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\..\Common\DocxFormat\Source\XML\stringcommon.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="XpsFileTest.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
// stdafx.cpp : source file that includes just the standard includes
// XpsFileTest.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#ifdef _DEBUG
#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")
#else
#pragma comment(lib, "../x64/Release/XpsFile.lib")
#pragma comment(lib, "../../DesktopEditor/Qt_build/graphics/project/release/graphics.lib")
#endif
// TODO: reference additional headers your program requires here
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <SDKDDKVer.h>
#include "ContextState.h"
#ifndef xpsUnitToMM
#define xpsUnitToMM(x) ((x) * 25.4 / 96)
#endif
namespace XPS
{
CContextState::CContextState() : m_oCurrentTransform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
{
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"";
}
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);
}
void CContextState::PopTransform()
{
m_lTransformStack.pop_back();
m_oCurrentTransform = m_lTransformStack.back();
}
double CContextState::NormalizeTransform()
{
agg::trans_affine& oMatrix = m_oCurrentTransform.m_agg_mtx;
double dDet = sqrt(oMatrix.sx * oMatrix.sy - oMatrix.shx * oMatrix.shy);
oMatrix.sx /= dDet;
oMatrix.shx /= dDet;
oMatrix.sy /= dDet;
oMatrix.shy /= dDet;
return dDet;
}
void CContextState::SetTransformToRenderer(IRenderer* pRenderer)
{
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));
}
}
\ No newline at end of file
#ifndef _XPS_XPSLIB_CONTEXTSTATE_H
#define _XPS_XPSLIB_CONTEXTSTATE_H
#include "../../DesktopEditor/graphics/Matrix.h"
#include "../../DesktopEditor/graphics/IRenderer.h"
#include <list>
#include <map>
namespace XPS
{
class CContextState
{
public:
CContextState();
~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();
double NormalizeTransform();
void SetTransformToRenderer(IRenderer* pRenderer);
public:
Aggplus::CMatrix m_oCurrentTransform;
std::list<Aggplus::CMatrix> m_lTransformStack;
std::map<std::wstring, std::wstring> m_mFigures;
};
}
#endif //_XPS_XPSLIB_CONTEXTSTATE_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
#ifndef _XPS_XPSLIB_FOLDER_H
#define _XPS_XPSLIB_FOLDER_H
#include "FontList.h"
#include "Page.h"
#include <map>
#define UNICODE
#define _UNICODE
#define _USE_LIBXML2_READER_
#define LIBXML_READER_ENABLED
#include "../../DesktopEditor/graphics/IRenderer.h"
#include "../../DesktopEditor/graphics/TemporaryCS.h"
namespace XPS
{
class Folder
{
public:
Folder(CFontManager* pFontManager);
~Folder();
bool ReadFromPath(const std::wstring& wsPath);
int GetPageCount() const;
void GetPageSize(int nPageIndex, int& nW, int& nH);
void DrawPage(int nPageIndex, IRenderer* pRenderer, bool* pbBreak);
void Close();
private:
std::wstring m_wsPath;
std::map<int, XPS::Page*> m_mPages;
CFontList m_oFontList;
CFontManager* m_pFontManager;
};
}
#endif //_XPS_XPSLIB_FOLDER_H
\ No newline at end of file
#ifndef _XPS_XPSLIB_FONTLIST_H
#define _XPS_XPSLIB_FONTLIST_H
#include <map>
#include <string>
#include <sstream>
#include "../../DesktopEditor/graphics/TemporaryCS.h"
#include "../../DesktopEditor/common/File.h"
#include "Utils.h"
namespace XPS
{
class CFontList
{
public:
CFontList()
{
m_oCS.InitializeCriticalSection();
}
~CFontList()
{
m_oCS.DeleteCriticalSection();
}
void Clear()
{
m_mList.clear();
}
void Check(const std::wstring& wsName, const std::wstring& wsFontPath)
{
m_oCS.Enter();
if (!Find(wsName))
{
Add(wsName);
unsigned char sKey[16];
GetFontKey(wsName, sKey);
NSFile::CFileBinary oFile;
oFile.OpenFile(wsFontPath, true);
unsigned char sFontData[32];
DWORD dwBytesRead;
oFile.ReadFile(sFontData, 32, dwBytesRead);
for (int nIndex = 0; nIndex < 32; nIndex++)
sFontData[nIndex] ^= sKey[nIndex % 16];
FILE* pFile = oFile.GetFileNative();
fseek(pFile, 0, SEEK_SET);
fwrite(sFontData, 1, 32, pFile);
fclose(pFile);
}
m_oCS.Leave();
}
private:
bool Find(const std::wstring& wsName)
{
std::map<std::wstring, bool>::iterator oIter = m_mList.find(wsName);
if (oIter != m_mList.end())
return oIter->second;
return false;
}
void Add(const std::wstring& wsName)
{
m_mList.insert(std::pair<std::wstring, bool>(wsName, true));
}
void GetFontKey(const std::wstring& wsName, unsigned char* sKey)
{
int k = 0;
for (int i = wsName.length() - 1; i >= 0; i--)
{
if ('-' != wsName[i])
{
sKey[k] = (unsigned char)GetIntegerFromHex(wsName.substr(i - 1, 2));
i--;
k++;
}
}
}
int GetIntegerFromHex(const std::wstring& wsString)
{
if (0 == wsString.size())
return 0;
std::wistringstream wiss(wsString);
int nValue = 0;
wiss >> std::hex >> nValue;
return nValue;
}
private:
NSCriticalSection::CRITICAL_SECTION m_oCS;
std::map<std::wstring, bool> m_mList;
};
}
#endif // _XPS_XPSLIB_FONTLIST_H
\ No newline at end of file
This diff is collapsed.
#ifndef _XPS_XPSLIB_PAGE_H
#define _XPS_XPSLIB_PAGE_H
#include "../../DesktopEditor/graphics/IRenderer.h"
#include "../../Common/DocxFormat/Source/XML/xmlutils.h"
#include "../../DesktopEditor/fontengine/FontManager.h"
#include "FontList.h"
#include "Utils.h"
#include "ContextState.h"
namespace XPS
{
class Page
{
public:
Page(const std::wstring& wsFile, const std::wstring& Path, CFontList* pFontList, CFontManager* pFontManager);
~Page();
void GetSize(int& nW, int& nH) const;
void Draw(IRenderer* pRenderer, bool* pbBreak);
private:
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);
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);
void PrepareVmlString(std::wstring& wsString);
private:
std::wstring m_wsPagePath;
std::wstring m_wsRootPath;
CFontList* m_pFontList;
CFontManager* m_pFontManager;
};
}
#endif // _XPS_XPSLIB_PAGE_H
\ No newline at end of file
#include "Utils.h"
#include "../../DesktopEditor/common/String.h"
#include "../../DesktopEditor/common/Types.h"
namespace XPS
{
int GetDigit(wchar_t wChar)
{
if (wChar >= '0' && wChar <= '9')
return (int)(wChar - '0');
if (wChar >= 'a' && wChar <= 'f')
return 10 + (int)(wChar - 'a');
if (wChar >= 'A' && wChar <= 'F')
return 10 + (int)(wChar - 'A');
return 0;
}
bool IsAlpha(wchar_t wChar)
{
return (((wChar >= 'A') && (wChar <= 'Z')) || ((wChar >= 'a') && (wChar <= 'z')));
}
double GetDouble(const std::wstring& wsString)
{
return _wtof(wsString.c_str());
}
int GetInteger(const std::wstring& wsString)
{
return _wtoi(wsString.c_str());
}
bool GetBool(const std::wstring& wsString)
{
std::wstring wsStr = wsString;
NSString::ToLower(wsStr);
if ((wsStr == L"true") || (wsStr == L"t") || (wsStr == L"1") || (wsStr == L"on"))
return true;
return false;
}
void GetBgra(const std::wstring& wsString, int& nBgr, int& nAlpha)
{
if (L'#' == wsString[0])
{
std::wstring wsStr = wsString.substr(1);
while (wsStr.length() < 6)
wsStr = L"0" + wsStr;
while (wsStr.length() < 8)
wsStr = L"F" + wsStr;
nAlpha = GetDigit(wsStr[0]);
nAlpha = nAlpha << 4;
nAlpha += GetDigit(wsStr[1]);
nBgr = GetDigit(wsStr[6]);
nBgr = nBgr << 4;
nBgr += GetDigit(wsStr[7]);
nBgr = nBgr << 4;
nBgr += GetDigit(wsStr[4]);
nBgr = nBgr << 4;
nBgr += GetDigit(wsStr[5]);
nBgr = nBgr << 4;
nBgr += GetDigit(wsStr[2]);
nBgr = nBgr << 4;
nBgr += GetDigit(wsStr[3]);
}
else if (L's' == wsString[0] && L'c' == wsString[1] && L'#' == wsString[2])
{
std::wstring wsStr = wsString.substr(3);
std::vector<std::wstring> arrElements = NSString::Split(wsStr, L',');
if (3 == arrElements.size())
{
nAlpha = 255;
nBgr = (((int)(min(GetDouble(arrElements[2]), 1.0) * 255)) << 16) + (((int)(min(GetDouble(arrElements[1]), 1.0) * 255)) << 8) + ((int)(min(GetDouble(arrElements[0]), 1.0) * 255));
}
else if (4 == arrElements.size())
{
nAlpha = GetDouble(arrElements[0]) * 255;
nBgr = (((int)(min(GetDouble(arrElements[3]), 1.0) * 255)) << 16) + (((int)(min(GetDouble(arrElements[2]), 1.0) * 255)) << 8) + ((int)(min(GetDouble(arrElements[1]), 1.0) * 255));
}
}
else
return;
}
std::wstring NormalizePath(const std::wstring& wsPath)
{
std::wstring wsResult = wsPath;
NSString::Replace(wsResult, L"/", L"\\");
while (std::wstring::npos != wsResult.find(L"\\\\"))
{
NSString::Replace(wsResult, L"\\\\", L"\\");
}
return wsResult;
}
std::wstring GetPath(const std::wstring& wsPath)
{
std::wstring wsResult;
wsResult = wsPath.substr(0, wsPath.find_last_of('/') + 1);
return wsResult;
}
std::wstring GetFileName(const std::wstring& wsPath)
{
int nCommaPos = wsPath.find_last_of(L'.');
int nSlashPos = wsPath.find_last_of(L'/');
if (std::wstring::npos == nCommaPos)
nCommaPos = wsPath.length();
if (std::wstring::npos == nSlashPos)
nSlashPos = -1;
if (nCommaPos < nSlashPos)
return L"";
std::wstring wsResult = wsPath.substr(nSlashPos + 1, nCommaPos - nSlashPos - 1);
return wsResult;
}
std::wstring GetFileExtension(const std::wstring& wsPath)
{
int nCommaPos = wsPath.find_last_of(L'.');
if (std::wstring::npos == nCommaPos)
return L"";
std::wstring wsResult = wsPath.substr(nCommaPos + 1);
return wsResult;
}
std::wstring RemoveNamespace(const std::wstring& wsString)
{
std::wstring wsResult;
int nPos = wsString.find(L":");
if (std::wstring::npos != nPos)
wsResult = wsString.substr(nPos + 1);
else
wsResult = wsString;
return wsResult;
}
std::vector<std::vector<std::wstring>> Split(const std::wstring& wsString, wchar_t wDelim1, wchar_t wDelim2)
{
std::vector<std::vector<std::wstring>> arrResult;
std::vector<std::wstring> arrStrings = NSString::Split(wsString, wDelim1);
int nCount = arrStrings.size();
for (int nIndex = 0; nIndex < nCount; nIndex++)
{
std::vector<std::wstring> arrStr = NSString::Split(arrStrings[nIndex], wDelim2);
arrResult.push_back(arrStr);
}
return arrResult;
}
}
\ No newline at end of file
#ifndef _XPS_XPSLIB_UTILS_H
#define _XPS_XPSLIB_UTILS_H
#include <string>
#include <vector>
namespace XPS
{
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);
std::wstring NormalizePath(const std::wstring& wsPath);
std::wstring GetPath(const std::wstring& wsPath);
std::wstring GetFileName(const std::wstring& wsPath);
std::wstring GetFileExtension(const std::wstring& wsPath);
std::wstring RemoveNamespace(const std::wstring& wsString);
std::vector<std::vector<std::wstring>> Split(const std::wstring& wsString, wchar_t wDelim1, wchar_t wDelim2);
}
#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