mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
refactoring
This commit is contained in:
@ -41,24 +41,24 @@ namespace XPS
|
||||
{
|
||||
m_pFontManager = pFontManager;
|
||||
m_mPages.clear();
|
||||
m_wsPath = NULL;
|
||||
m_wsPath = NULL;
|
||||
}
|
||||
CDocument::~CDocument()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
bool CDocument::Read(IFolder* pFolder)
|
||||
bool CDocument::Read(IFolder* pFolder)
|
||||
{
|
||||
Close();
|
||||
|
||||
m_wsPath = pFolder;
|
||||
m_wsPath = pFolder;
|
||||
|
||||
XmlUtils::CXmlLiteReader oReader;
|
||||
XmlUtils::CXmlLiteReader oReader;
|
||||
|
||||
if (!oReader.FromStringA(m_wsPath->readXml(L"_rels/.rels")))
|
||||
if (!oReader.FromStringA(m_wsPath->readXml(L"_rels/.rels")))
|
||||
return false;
|
||||
|
||||
if (!oReader.ReadNextNode())
|
||||
if (!oReader.ReadNextNode())
|
||||
return false;
|
||||
|
||||
std::wstring wsName = oReader.GetName();
|
||||
@ -87,15 +87,15 @@ namespace XPS
|
||||
|
||||
oReader.Clear();
|
||||
|
||||
std::wstring wsTargerFullPath = wsTargetFile;
|
||||
if (!m_wsPath->exists(wsTargerFullPath))
|
||||
std::wstring wsTargerFullPath = wsTargetFile;
|
||||
if (!m_wsPath->exists(wsTargerFullPath))
|
||||
{
|
||||
wsTargerFullPath = GetPath(L"_rels/.rels") + wsTargetFile;
|
||||
if (!m_wsPath->exists(wsTargerFullPath))
|
||||
wsTargerFullPath = GetPath(L"_rels/.rels") + wsTargetFile;
|
||||
if (!m_wsPath->exists(wsTargerFullPath))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!oReader.FromStringA(m_wsPath->readXml(wsTargerFullPath)))
|
||||
|
||||
if (!oReader.FromStringA(m_wsPath->readXml(wsTargerFullPath)))
|
||||
return false;
|
||||
|
||||
if (!oReader.ReadNextNode())
|
||||
@ -122,15 +122,15 @@ namespace XPS
|
||||
oReader.Clear();
|
||||
|
||||
|
||||
std::wstring wsSourceFullPath = wsSourceFile;
|
||||
if (!m_wsPath->exists(wsSourceFullPath))
|
||||
std::wstring wsSourceFullPath = wsSourceFile;
|
||||
if (!m_wsPath->exists(wsSourceFullPath))
|
||||
{
|
||||
wsSourceFullPath = GetPath(wsTargerFullPath) + wsSourceFile;
|
||||
if (!m_wsPath->exists(wsSourceFullPath))
|
||||
if (!m_wsPath->exists(wsSourceFullPath))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!oReader.FromStringA(m_wsPath->readXml(wsSourceFullPath)))
|
||||
if (!oReader.FromStringA(m_wsPath->readXml(wsSourceFullPath)))
|
||||
return false;
|
||||
|
||||
if (!oReader.ReadNextNode())
|
||||
@ -153,15 +153,15 @@ namespace XPS
|
||||
{
|
||||
ReadAttribute(oReader, L"Source", wsSource);
|
||||
|
||||
std::wstring wsPagePath = wsSource;
|
||||
if (!m_wsPath->exists(wsPagePath))
|
||||
std::wstring wsPagePath = wsSource;
|
||||
if (!m_wsPath->exists(wsPagePath))
|
||||
{
|
||||
wsPagePath = wsFilePath + wsSource;
|
||||
if (!m_wsPath->exists(wsPagePath))
|
||||
if (!m_wsPath->exists(wsPagePath))
|
||||
continue;
|
||||
}
|
||||
|
||||
m_mPages.insert(std::pair<int, XPS::Page*>(nIndex++, new XPS::Page(wsPagePath, m_wsPath, &m_oFontList, m_pFontManager, this)));
|
||||
m_mPages.insert(std::pair<int, XPS::Page*>(nIndex++, new XPS::Page(wsPagePath, m_wsPath, &m_oFontList, m_pFontManager, this)));
|
||||
}
|
||||
|
||||
}
|
||||
@ -200,7 +200,7 @@ namespace XPS
|
||||
delete oIter->second;
|
||||
}
|
||||
m_mStaticResources.clear();
|
||||
RELEASEOBJECT(m_wsPath);
|
||||
RELEASEOBJECT(m_wsPath);
|
||||
}
|
||||
CStaticResource* CDocument::GetStaticResource(const wchar_t* wsPath)
|
||||
{
|
||||
@ -210,7 +210,7 @@ namespace XPS
|
||||
return oIt.second;
|
||||
}
|
||||
|
||||
CStaticResource* pStaticResource = new CStaticResource(m_wsPath->readXml(wsPath));
|
||||
CStaticResource* pStaticResource = new CStaticResource(m_wsPath->readXml(wsPath));
|
||||
m_mStaticResources.insert(std::pair<std::wstring, CStaticResource*>(wsPath, pStaticResource));
|
||||
return pStaticResource;
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ namespace XPS
|
||||
CDocument(NSFonts::IFontManager* pFontManager);
|
||||
~CDocument();
|
||||
|
||||
bool Read(IFolder* pFolder);
|
||||
bool Read(IFolder* pFolder);
|
||||
int GetPageCount() const;
|
||||
void GetPageSize(int nPageIndex, int& nW, int& nH);
|
||||
void DrawPage(int nPageIndex, IRenderer* pRenderer, bool* pbBreak);
|
||||
@ -60,7 +60,7 @@ namespace XPS
|
||||
|
||||
private:
|
||||
|
||||
IFolder* m_wsPath;
|
||||
IFolder* m_wsPath;
|
||||
std::map<int, XPS::Page*> m_mPages;
|
||||
CFontList m_oFontList;
|
||||
NSFonts::IFontManager* m_pFontManager;
|
||||
|
||||
@ -58,7 +58,7 @@ namespace XPS
|
||||
{
|
||||
m_mList.clear();
|
||||
}
|
||||
void Check(const std::wstring& wsName, BYTE* data, DWORD length)
|
||||
void Check(const std::wstring& wsName, BYTE* data, DWORD length)
|
||||
{
|
||||
m_oCS.Enter();
|
||||
if (!Find(wsName))
|
||||
@ -68,9 +68,9 @@ namespace XPS
|
||||
unsigned char sKey[16];
|
||||
GetFontKey(wsName, sKey);
|
||||
|
||||
if (length >= 32)
|
||||
for (int nIndex = 0; nIndex < 32; nIndex++)
|
||||
data[nIndex] ^= sKey[nIndex % 16];
|
||||
if (length >= 32)
|
||||
for (int nIndex = 0; nIndex < 32; nIndex++)
|
||||
data[nIndex] ^= sKey[nIndex % 16];
|
||||
}
|
||||
m_oCS.Leave();
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ namespace XPS
|
||||
{
|
||||
XmlUtils::CXmlLiteReader oReader;
|
||||
|
||||
if (!oReader.FromStringA(m_wsRootPath->readXml(m_wsPagePath)))
|
||||
if (!oReader.FromStringA(m_wsRootPath->readXml(m_wsPagePath)))
|
||||
return;
|
||||
|
||||
if (!oReader.ReadNextNode())
|
||||
@ -173,7 +173,7 @@ namespace XPS
|
||||
{
|
||||
XmlUtils::CXmlLiteReader oReader;
|
||||
|
||||
if (!oReader.FromStringA(m_wsRootPath->readXml(m_wsPagePath)))
|
||||
if (!oReader.FromStringA(m_wsRootPath->readXml(m_wsPagePath)))
|
||||
return;
|
||||
|
||||
if (!oReader.ReadNextNode())
|
||||
@ -451,23 +451,23 @@ namespace XPS
|
||||
std::wstring wsRelativePath = (std::wstring::npos == nSlashPos) ? m_wsPagePath : m_wsPagePath.substr(0, nSlashPos + 1);
|
||||
wsFontPath = wsRelativePath + wsFontPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
wsFontPath = m_wsRootPath->getFullFilePath(wsFontPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
wsFontPath = m_wsRootPath->getFullFilePath(wsFontPath);
|
||||
}
|
||||
|
||||
std::wstring wsExt = GetFileExtension(wsFontPath);
|
||||
NSStringExt::ToLower(wsExt);
|
||||
if (L"odttf" == wsExt)
|
||||
{
|
||||
NSStringExt::ToLower(wsFontName);
|
||||
IFolder::CBuffer* buffer = NULL;
|
||||
m_wsRootPath->read(wsFontPath, buffer);
|
||||
m_pFontList->Check(wsFontName, buffer->Buffer, buffer->Size);
|
||||
if (CApplicationFontStreams::m_pMemoryStorage)
|
||||
CApplicationFontStreams::m_pMemoryStorage->Add(wsFontPath, buffer->Buffer, buffer->Size);
|
||||
m_wsRootPath->write(wsFontPath, buffer->Buffer, buffer->Size);
|
||||
RELEASEOBJECT(buffer);
|
||||
IFolder::CBuffer* buffer = NULL;
|
||||
m_wsRootPath->read(wsFontPath, buffer);
|
||||
m_pFontList->Check(wsFontName, buffer->Buffer, buffer->Size);
|
||||
if (CApplicationFontStreams::m_pMemoryStorage)
|
||||
CApplicationFontStreams::m_pMemoryStorage->Add(wsFontPath, buffer->Buffer, buffer->Size);
|
||||
m_wsRootPath->write(wsFontPath, buffer->Buffer, buffer->Size);
|
||||
RELEASEOBJECT(buffer);
|
||||
}
|
||||
wsFontPath = NormalizePath(wsFontPath);
|
||||
pRenderer->put_FontPath(wsFontPath);
|
||||
@ -638,7 +638,7 @@ namespace XPS
|
||||
int nIndicesPos = 0, nIndicesLen = wsIndices.size();
|
||||
int nUtf16Pos = 0;
|
||||
bool bRtoL = (nBidiLevel % 2 ? true : false);
|
||||
m_pFontManager->LoadFontFromFile(m_wsRootPath->getFullFilePath(wsFontPath), 0, (float)(dFontSize * 0.75), 96, 96);
|
||||
m_pFontManager->LoadFontFromFile(m_wsRootPath->getFullFilePath(wsFontPath), 0, (float)(dFontSize * 0.75), 96, 96);
|
||||
double dFontKoef = dFontSize / 100.0;
|
||||
|
||||
bool bNeedItalic = false, bNeedBold = false;
|
||||
@ -973,7 +973,7 @@ namespace XPS
|
||||
if (pBrush)
|
||||
{
|
||||
if (pBrush->IsImageBrush())
|
||||
((CImageBrush*)pBrush)->SetPaths(m_wsRootPath, GetPath(m_wsPagePath).c_str());
|
||||
((CImageBrush*)pBrush)->SetPaths(m_wsRootPath, GetPath(m_wsPagePath).c_str());
|
||||
|
||||
bFill = pBrush->SetToRenderer(pRenderer);
|
||||
if (bDeleteBrush)
|
||||
|
||||
@ -47,11 +47,11 @@
|
||||
|
||||
namespace XPS
|
||||
{
|
||||
CStaticResource::CStaticResource(const std::string& wsPath)
|
||||
CStaticResource::CStaticResource(const std::string& wsPath)
|
||||
{
|
||||
XmlUtils::CXmlLiteReader oReader;
|
||||
|
||||
if (!oReader.FromStringA(wsPath))
|
||||
if (!oReader.FromStringA(wsPath))
|
||||
return;
|
||||
|
||||
Parse(oReader);
|
||||
@ -152,33 +152,33 @@ namespace XPS
|
||||
}
|
||||
bool CImageBrush::SetToRenderer(IRenderer* pRenderer)
|
||||
{
|
||||
std::wstring wsPath = m_wsPath.c_stdstr();
|
||||
if (!m_wsRoot->exists(wsPath))
|
||||
std::wstring wsPath = m_wsPath.c_stdstr();
|
||||
if (!m_wsRoot->exists(wsPath))
|
||||
{
|
||||
wsPath = m_wsPage.c_stdstr() + m_wsPath.c_stdstr();
|
||||
if (!m_wsRoot->exists(wsPath))
|
||||
wsPath = m_wsPage.c_stdstr() + m_wsPath.c_stdstr();
|
||||
if (!m_wsRoot->exists(wsPath))
|
||||
return false;
|
||||
}
|
||||
|
||||
IFolder::CBuffer* buffer = NULL;
|
||||
m_wsRoot->read(wsPath, buffer);
|
||||
int nBase64BufferLen = NSBase64::Base64EncodeGetRequiredLength(buffer->Size);
|
||||
BYTE* pbBase64Buffer = new BYTE[nBase64BufferLen + 64];
|
||||
if (true == NSBase64::Base64Encode(buffer->Buffer, buffer->Size, pbBase64Buffer, &nBase64BufferLen))
|
||||
{
|
||||
pRenderer->put_BrushType(c_BrushTypeTexture);
|
||||
pRenderer->put_BrushTexturePath(L"data:," + NSFile::CUtf8Converter::GetUnicodeStringFromUTF8(pbBase64Buffer, nBase64BufferLen));
|
||||
RELEASEARRAYOBJECTS(pbBase64Buffer);
|
||||
RELEASEOBJECT(buffer);
|
||||
return true;
|
||||
}
|
||||
RELEASEARRAYOBJECTS(pbBase64Buffer);
|
||||
RELEASEOBJECT(buffer);
|
||||
return false;
|
||||
IFolder::CBuffer* buffer = NULL;
|
||||
m_wsRoot->read(wsPath, buffer);
|
||||
int nBase64BufferLen = NSBase64::Base64EncodeGetRequiredLength(buffer->Size);
|
||||
BYTE* pbBase64Buffer = new BYTE[nBase64BufferLen + 64];
|
||||
if (true == NSBase64::Base64Encode(buffer->Buffer, buffer->Size, pbBase64Buffer, &nBase64BufferLen))
|
||||
{
|
||||
pRenderer->put_BrushType(c_BrushTypeTexture);
|
||||
pRenderer->put_BrushTexturePath(L"data:," + NSFile::CUtf8Converter::GetUnicodeStringFromUTF8(pbBase64Buffer, nBase64BufferLen));
|
||||
RELEASEARRAYOBJECTS(pbBase64Buffer);
|
||||
RELEASEOBJECT(buffer);
|
||||
return true;
|
||||
}
|
||||
RELEASEARRAYOBJECTS(pbBase64Buffer);
|
||||
RELEASEOBJECT(buffer);
|
||||
return false;
|
||||
}
|
||||
void CImageBrush::SetPaths(IFolder* wsRoot, const wchar_t* wsPage)
|
||||
void CImageBrush::SetPaths(IFolder* wsRoot, const wchar_t* wsPage)
|
||||
{
|
||||
m_wsRoot = wsRoot;
|
||||
m_wsRoot = wsRoot;
|
||||
m_wsPage.create(wsPage, true);
|
||||
}
|
||||
bool CLinearGradientBrush::SetToRenderer(IRenderer* pRenderer)
|
||||
|
||||
@ -52,7 +52,7 @@ namespace XPS
|
||||
class CStaticResource
|
||||
{
|
||||
public:
|
||||
CStaticResource(const std::string& wsPath);
|
||||
CStaticResource(const std::string& wsPath);
|
||||
CStaticResource(XmlUtils::CXmlLiteReader& oReader);
|
||||
~CStaticResource();
|
||||
bool GetFigure(CWString& wsKey, CWString& wsFigure);
|
||||
@ -101,11 +101,11 @@ namespace XPS
|
||||
}
|
||||
bool SetToRenderer(IRenderer* pRenderer);
|
||||
bool IsImageBrush() { return true; }
|
||||
void SetPaths(IFolder* wsRoot, const wchar_t* wsPage);
|
||||
void SetPaths(IFolder* wsRoot, const wchar_t* wsPage);
|
||||
private:
|
||||
|
||||
CWString m_wsPath;
|
||||
IFolder* m_wsRoot;
|
||||
IFolder* m_wsRoot;
|
||||
CWString m_wsPage;
|
||||
};
|
||||
class CGradientBrush : public CBrush
|
||||
|
||||
Reference in New Issue
Block a user