mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Refactoring
This commit is contained in:
@ -28,6 +28,7 @@ SOURCES += \
|
||||
HwpDoc/Chart/Bar.cpp \
|
||||
HwpDoc/Chart/Brush.cpp \
|
||||
HwpDoc/Chart/CategoryScale.cpp \
|
||||
HwpDoc/Chart/ChartReader.cpp \
|
||||
HwpDoc/Chart/Contour.cpp \
|
||||
HwpDoc/Chart/ContourGradient.cpp \
|
||||
HwpDoc/Chart/Coor.cpp \
|
||||
@ -156,6 +157,8 @@ HEADERS += \
|
||||
HwpDoc/Chart/Brush.h \
|
||||
HwpDoc/Chart/CategoryScale.h \
|
||||
HwpDoc/Chart/ChartObject.h \
|
||||
HwpDoc/Chart/ChartReader.h \
|
||||
HwpDoc/Chart/Common.h \
|
||||
HwpDoc/Chart/Contour.h \
|
||||
HwpDoc/Chart/ContourGradient.h \
|
||||
HwpDoc/Chart/Coor.h \
|
||||
|
||||
32
HwpFile/HwpDoc/Chart/ChartReader.cpp
Normal file
32
HwpFile/HwpDoc/Chart/ChartReader.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "ChartReader.h"
|
||||
|
||||
#include "VtChart.h"
|
||||
|
||||
namespace HWP { namespace CHART
|
||||
{
|
||||
CChartReader::CChartReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CChartReader::ReadFromOle(CHWPStream& oOleData)
|
||||
{
|
||||
oOleData.Skip(44); //Unknown data
|
||||
|
||||
short shStoredNameLength;
|
||||
oOleData.ReadShort(shStoredNameLength);
|
||||
|
||||
HWP_STRING sStoredName;
|
||||
oOleData.ReadString(sStoredName, shStoredNameLength, EStringCharacter::ASCII);
|
||||
|
||||
// if ("VtChart" == sStoredName)
|
||||
|
||||
|
||||
CVtChart oVtChart;
|
||||
|
||||
if (!oVtChart.Read(oOleData))
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
}}
|
||||
17
HwpFile/HwpDoc/Chart/ChartReader.h
Normal file
17
HwpFile/HwpDoc/Chart/ChartReader.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef CHARTREADER_H
|
||||
#define CHARTREADER_H
|
||||
|
||||
#include "../HWPStream.h"
|
||||
|
||||
namespace HWP { namespace CHART
|
||||
{
|
||||
class CChartReader
|
||||
{
|
||||
public:
|
||||
CChartReader();
|
||||
|
||||
bool ReadFromOle(CHWPStream& oOleData);
|
||||
};
|
||||
}}
|
||||
|
||||
#endif // CHARTREADER_H
|
||||
11
HwpFile/HwpDoc/Chart/Common.h
Normal file
11
HwpFile/HwpDoc/Chart/Common.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace HWP { namespace CHART
|
||||
{
|
||||
typedef int8_t CHART_INT;
|
||||
}}
|
||||
|
||||
#endif // COMMON_H
|
||||
@ -4,6 +4,9 @@
|
||||
#include "../../../DesktopEditor/common/Directory.h"
|
||||
#include "../../../DesktopEditor/common/StringBuilder.h"
|
||||
|
||||
#include "../OLEdoc/CompoundFile.h"
|
||||
#include "../Chart/ChartReader.h"
|
||||
|
||||
namespace HWP
|
||||
{
|
||||
COleConverter::COleConverter()
|
||||
@ -25,13 +28,13 @@ void COleConverter::SetTempDir(const std::wstring& wsTempDir)
|
||||
{
|
||||
m_wsTempDir = wsTempDir;
|
||||
}
|
||||
void COleConverter::CreateChartData(const std::wstring& wsChartData)
|
||||
void COleConverter::CreateChartData(CHWPStream& oOOXMLStream)
|
||||
{
|
||||
const std::wstring wsPath = m_wsTempDir + FILE_SEPARATOR_STR + L"word" + FILE_SEPARATOR_STR + L"charts" + FILE_SEPARATOR_STR;
|
||||
|
||||
NSFile::CFileBinary oChartFile;
|
||||
oChartFile.CreateFileW(wsPath + L"chart" + std::to_wstring(m_unCountCharts) + L".xml");
|
||||
oChartFile.WriteStringUTF8(wsChartData);
|
||||
oChartFile.WriteFile(oOOXMLStream.GetCurPtr(), oOOXMLStream.SizeToEnd());
|
||||
oChartFile.CloseFile();
|
||||
|
||||
NSStringUtils::CStringBuilder oColorData;
|
||||
@ -91,20 +94,24 @@ void COleConverter::CreateChartData(const std::wstring& wsChartData)
|
||||
|
||||
void COleConverter::CreateChart(CHWPStream& oOleStream)
|
||||
{
|
||||
std::string sData = std::string(oOleStream.GetCurPtr(), oOleStream.GetSize());
|
||||
oOleStream.Skip(4);
|
||||
|
||||
size_t unBegin = sData.find("<?xml");
|
||||
CCompoundFile oCompoundFile(oOleStream);
|
||||
|
||||
if (std::string::npos == unBegin)
|
||||
if (!oCompoundFile.Open())
|
||||
return;
|
||||
|
||||
size_t unEnd = sData.find("</c:chartSpace>", unBegin);
|
||||
CHWPStream oContentData;
|
||||
if (!oCompoundFile.GetComponent(L"OOXMLChartContents", oContentData) || true)
|
||||
{
|
||||
if (!oCompoundFile.GetComponent(L"Contents", oContentData))
|
||||
return;
|
||||
|
||||
if (std::string::npos == unEnd)
|
||||
return;
|
||||
CHART::CChartReader oChartReader;
|
||||
|
||||
const std::string sCharDataA = sData.substr(unBegin, unEnd - unBegin + 15);
|
||||
const std::wstring wsChartData = UTF8_TO_U(sCharDataA);
|
||||
if (!oChartReader.ReadFromOle(oContentData))
|
||||
return;
|
||||
}
|
||||
|
||||
const std::wstring wsPath = m_wsTempDir + FILE_SEPARATOR_STR + L"word" + FILE_SEPARATOR_STR + L"charts";
|
||||
|
||||
@ -113,7 +120,7 @@ void COleConverter::CreateChart(CHWPStream& oOleStream)
|
||||
|
||||
++m_unCountCharts;
|
||||
|
||||
CreateChartData(wsChartData);
|
||||
CreateChartData(oContentData);
|
||||
|
||||
const std::wstring wsRelsPath = wsPath + FILE_SEPARATOR_STR + L"_rels";
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ class COleConverter
|
||||
unsigned int m_unCountCharts;
|
||||
std::wstring m_wsTempDir;
|
||||
|
||||
void CreateChartData(const std::wstring& wsChartData);
|
||||
void CreateChartData(CHWPStream& oOOXMLStream);
|
||||
public:
|
||||
COleConverter();
|
||||
|
||||
|
||||
@ -209,6 +209,19 @@ bool CHWPFile::GetChildStream(const HWP_STRING& sEntryName, ECompressed eCompres
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CHWPFile::GetOLEObject(const HWP_STRING& sEntryName, CHWPStream& oBuffer)
|
||||
{
|
||||
if (!m_oFileHeader.Compressed())
|
||||
return GetComponent(sEntryName, oBuffer);
|
||||
|
||||
CHWPStream oTempBuffer;
|
||||
|
||||
if (!GetComponent(sEntryName, oTempBuffer))
|
||||
return false;
|
||||
|
||||
return Unzip(oTempBuffer, oBuffer);
|
||||
}
|
||||
|
||||
bool CHWPFile::Unzip(CHWPStream& oInput, CHWPStream& oBuffer)
|
||||
{
|
||||
unsigned char* pInBuffer = new(std::nothrow) unsigned char[DEFAULT_BUFFER_SIZE];
|
||||
|
||||
@ -33,6 +33,7 @@ public:
|
||||
bool GetDocInfo(int nVersion);
|
||||
bool GetComponent(const HWP_STRING& sEntryName, CHWPStream& oBuffer);
|
||||
bool GetChildStream(const HWP_STRING& sEntryName, ECompressed eCompressed, CHWPStream& oBuffer);
|
||||
bool GetOLEObject(const HWP_STRING& sEntryName, CHWPStream& oBuffer);
|
||||
private:
|
||||
CDirectoryEntry* FindChildEntry(const HWP_STRING& sBasePath, const CDirectoryEntry& oBaseEntry, const HWP_STRING& sEntryName) const;
|
||||
HWP_STRING SaveChildEntry(const HWP_STRING& sRootPath, const HWP_STRING& sEntryName, ECompressed eCompressed);
|
||||
|
||||
@ -7,7 +7,19 @@ namespace HWP
|
||||
CCompoundFile::CCompoundFile(const HWP_STRING& sFileName)
|
||||
: m_nSectorSize(512)
|
||||
{
|
||||
m_oFile.OpenFile(sFileName);
|
||||
BYTE* pBuffer;
|
||||
DWORD unSize;
|
||||
|
||||
if (!NSFile::CFileBinary::ReadAllBytes(sFileName, &pBuffer, unSize))
|
||||
return;
|
||||
|
||||
m_oData.SetStream((HWP_BYTE*)pBuffer, unSize, false);
|
||||
}
|
||||
|
||||
CCompoundFile::CCompoundFile(CHWPStream& oBuffer)
|
||||
: m_nSectorSize(512)
|
||||
{
|
||||
m_oData.SetStream(oBuffer.GetCurPtr(), oBuffer.SizeToEnd());
|
||||
}
|
||||
|
||||
CCompoundFile::~CCompoundFile()
|
||||
@ -108,9 +120,8 @@ bool CCompoundFile::Read(const CDirectoryEntry& oEntry, CHWPStream& oBuffer)
|
||||
|
||||
int nSatID = arStreamContainerSectors.at(nStreamIndex);
|
||||
|
||||
DWORD dwSizeRead;
|
||||
m_oFile.SeekFile((nSatID + 1) * m_nSectorSize + nStreamOffset * 64);
|
||||
m_oFile.ReadFile((BYTE*)oBuffer.GetCurPtr(), nRemainSize >= 64 ? 64 : nRemainSize, dwSizeRead);
|
||||
m_oData.MoveTo((nSatID + 1) * m_nSectorSize + nStreamOffset * 64);
|
||||
const DWORD dwSizeRead{m_oData.ReadBytes((HWP_BYTE*)oBuffer.GetCurPtr(), nRemainSize >= 64 ? 64 : nRemainSize)};
|
||||
|
||||
oBuffer.Skip(dwSizeRead);
|
||||
nRemainSize -= dwSizeRead;
|
||||
@ -124,9 +135,8 @@ bool CCompoundFile::Read(const CDirectoryEntry& oEntry, CHWPStream& oBuffer)
|
||||
continue;
|
||||
|
||||
// readStream
|
||||
DWORD dwSizeRead;
|
||||
m_oFile.SeekFile((nSecNum + 1) * m_nSectorSize);
|
||||
m_oFile.ReadFile((BYTE*)oBuffer.GetCurPtr(), nRemainSize >= m_nSectorSize ? m_nSectorSize : nRemainSize, dwSizeRead);
|
||||
m_oData.MoveTo((nSecNum + 1) * m_nSectorSize);
|
||||
const DWORD dwSizeRead{m_oData.ReadBytes((HWP_BYTE*)oBuffer.GetCurPtr(), nRemainSize >= m_nSectorSize ? m_nSectorSize : nRemainSize)};
|
||||
|
||||
oBuffer.Skip(dwSizeRead);
|
||||
nRemainSize -= dwSizeRead;
|
||||
@ -145,15 +155,14 @@ bool CCompoundFile::Open()
|
||||
if (!oBuffer.IsValid())
|
||||
return false;
|
||||
|
||||
DWORD dwSizeRead;
|
||||
m_oFile.ReadFile((BYTE*)oBuffer.GetCurPtr(), m_nSectorSize, dwSizeRead);
|
||||
const DWORD dwSizeRead{m_oData.ReadBytes((HWP_BYTE*)oBuffer.GetCurPtr(), m_nSectorSize)};
|
||||
|
||||
if (dwSizeRead != m_nSectorSize || !ParseHeader(oBuffer))
|
||||
return false;
|
||||
|
||||
if (0x0004 == m_nMajorVersion)
|
||||
{
|
||||
m_oFile.SeekFile(4096);
|
||||
m_oData.MoveTo(4096);
|
||||
m_nSectorSize = 4096;
|
||||
oBuffer.Clear();
|
||||
oBuffer.Expand(m_nSectorSize);
|
||||
@ -329,7 +338,7 @@ bool CCompoundFile::Open()
|
||||
|
||||
void CCompoundFile::Close()
|
||||
{
|
||||
m_oFile.CloseFile();
|
||||
m_oData.Clear();
|
||||
}
|
||||
|
||||
void CCompoundFile::AddSiblings(VECTOR<int>& arIndexs, int nCurrentIndex) const
|
||||
@ -372,9 +381,8 @@ VECTOR<int> CCompoundFile::GetSecIDsFromSAT(int nSecID, int nSatIndex, int nSecI
|
||||
if (!oBuffer.IsValid())
|
||||
return VECTOR<int>();
|
||||
|
||||
DWORD dwSizeRead;
|
||||
m_oFile.SeekFile((nSecID + 1) * m_nSectorSize);
|
||||
m_oFile.ReadFile((BYTE*)oBuffer.GetCurPtr(), m_nSectorSize, dwSizeRead);
|
||||
m_oData.MoveTo((nSecID + 1) * m_nSectorSize);
|
||||
const DWORD dwSizeRead{m_oData.ReadBytes((HWP_BYTE*)oBuffer.GetCurPtr(), m_nSectorSize)};
|
||||
|
||||
if (dwSizeRead != m_nSectorSize)
|
||||
return VECTOR<int>();
|
||||
@ -405,9 +413,8 @@ void CCompoundFile::ReadDirectorySector(int nSecID)
|
||||
if (!oBuffer.IsValid())
|
||||
return;
|
||||
|
||||
DWORD dwSizeRead;
|
||||
m_oFile.SeekFile((nSecID + 1) * m_nSectorSize);
|
||||
m_oFile.ReadFile((BYTE*)oBuffer.GetCurPtr(), m_nSectorSize, dwSizeRead);
|
||||
m_oData.MoveTo((nSecID + 1) * m_nSectorSize);
|
||||
const DWORD dwSizeRead{m_oData.ReadBytes((HWP_BYTE*)oBuffer.GetCurPtr(), m_nSectorSize)};
|
||||
|
||||
if (dwSizeRead == m_nSectorSize)
|
||||
ParseDirectorySector(oBuffer);
|
||||
@ -420,9 +427,8 @@ void CCompoundFile::ReadSSATSector(int nSecID)
|
||||
if (!oBuffer.IsValid())
|
||||
return;
|
||||
|
||||
DWORD dwSizeRead;
|
||||
m_oFile.SeekFile((nSecID + 1) * m_nSectorSize);
|
||||
m_oFile.ReadFile((BYTE*)oBuffer.GetCurPtr(), m_nSectorSize, dwSizeRead);
|
||||
m_oData.MoveTo((nSecID + 1) * m_nSectorSize);
|
||||
const DWORD dwSizeRead{m_oData.ReadBytes((HWP_BYTE*)oBuffer.GetCurPtr(), m_nSectorSize)};
|
||||
|
||||
if (dwSizeRead == m_nSectorSize)
|
||||
ParseSSATSector(oBuffer);
|
||||
@ -435,9 +441,8 @@ void CCompoundFile::ReadMSATSector(int nSecID)
|
||||
if (!oBuffer.IsValid())
|
||||
return;
|
||||
|
||||
DWORD dwSizeRead;
|
||||
m_oFile.SeekFile((nSecID + 1) * m_nSectorSize);
|
||||
m_oFile.ReadFile((BYTE*)oBuffer.GetCurPtr(), m_nSectorSize, dwSizeRead);
|
||||
m_oData.MoveTo((nSecID + 1) * m_nSectorSize);
|
||||
const DWORD dwSizeRead{m_oData.ReadBytes((HWP_BYTE*)oBuffer.GetCurPtr(), m_nSectorSize)};
|
||||
|
||||
if (dwSizeRead == m_nSectorSize)
|
||||
ParseMSATSector(oBuffer);
|
||||
@ -607,7 +612,8 @@ void CCompoundFile::ParseMSATSector(CHWPStream& oBuffer)
|
||||
|
||||
bool CCompoundFile::ParseHeader(CHWPStream& oBuffer)
|
||||
{
|
||||
CheckSignature(oBuffer);
|
||||
if (!CheckSignature(oBuffer))
|
||||
return false;
|
||||
|
||||
oBuffer.Skip(16); // Header CLSID
|
||||
m_nMinorVersion = oBuffer.ReadShort();
|
||||
|
||||
@ -10,7 +10,8 @@ namespace HWP
|
||||
{
|
||||
class CCompoundFile
|
||||
{
|
||||
NSFile::CFileBinary m_oFile;
|
||||
CHWPStream m_oData;
|
||||
|
||||
int m_nMinorVersion;
|
||||
int m_nMajorVersion;
|
||||
int m_nSectorSize;
|
||||
@ -33,6 +34,7 @@ class CCompoundFile
|
||||
VECTOR<CDirectoryEntry*> m_arDirectoryEntries;
|
||||
public:
|
||||
CCompoundFile(const HWP_STRING& sFileName);
|
||||
CCompoundFile(CHWPStream& oBuffer);
|
||||
~CCompoundFile();
|
||||
|
||||
const CDirectoryEntry* GetEntry(const HWP_STRING& sFileName) const;
|
||||
|
||||
Reference in New Issue
Block a user