diff --git a/HwpFile/HWPFile.cpp b/HwpFile/HWPFile.cpp index 36d259623f..2ba4cc9871 100644 --- a/HwpFile/HWPFile.cpp +++ b/HwpFile/HWPFile.cpp @@ -3,6 +3,8 @@ #include "HwpDoc/HWPFile_Private.h" #include "../DesktopEditor/common/File.h" +#include "HwpDoc/Conversion/Converter2OOXML.h" + CHWPFile::CHWPFile(const std::wstring& wsFileName) : m_pInternal(new HWP::CHWPFile_Private(wsFileName)) {} @@ -13,6 +15,11 @@ CHWPFile::~CHWPFile() delete m_pInternal; } +void CHWPFile::SetTempDirectory(const std::wstring& wsTempDirectory) +{ + m_wsTempDirectory = wsTempDirectory; +} + bool CHWPFile::Open() { if (nullptr == m_pInternal) @@ -26,3 +33,13 @@ void CHWPFile::Close() if (nullptr != m_pInternal) m_pInternal->Close(); } + +bool CHWPFile::ConvertToOOXML(const std::wstring& wsFilePath) +{ + HWP::CConverter2OOXML oConverter; + + oConverter.SetHWPFile(m_pInternal); + oConverter.SetTempDirectory(m_wsTempDirectory); + + return oConverter.ConvertTo(wsFilePath); +} diff --git a/HwpFile/HWPFile.h b/HwpFile/HWPFile.h index 1802d7ae30..5151f1292c 100644 --- a/HwpFile/HWPFile.h +++ b/HwpFile/HWPFile.h @@ -14,12 +14,16 @@ namespace HWP { class CHWPFile_Private; } class HWP_FILE_DECL_EXPORT CHWPFile { HWP::CHWPFile_Private *m_pInternal; + std::wstring m_wsTempDirectory; public: CHWPFile(const std::wstring& wsFileName); ~CHWPFile(); + void SetTempDirectory(const std::wstring& wsTempDirectory); + bool Open(); void Close(); + bool ConvertToOOXML(const std::wstring& wsFilePath); }; #endif // HWPFILE_H diff --git a/HwpFile/HWPFile.pro b/HwpFile/HWPFile.pro index 13643ef77c..b87e7c01f1 100644 --- a/HwpFile/HWPFile.pro +++ b/HwpFile/HWPFile.pro @@ -18,6 +18,9 @@ DEFINES += HWPFILE_USE_DYNAMIC_LIBRARY SOURCES += \ HWPFile.cpp \ + HwpDoc/Conversion/Converter2OOXML.cpp \ + HwpDoc/Conversion/Transform.cpp \ + HwpDoc/Conversion/WriterContext.cpp \ HwpDoc/HWPDocInfo.cpp \ HwpDoc/HWPElements/HWPRecord.cpp \ HwpDoc/HWPElements/HWPRecordBinData.cpp \ @@ -85,6 +88,10 @@ SOURCES += \ HEADERS += \ HWPFile.h \ HwpDoc/Common.h \ + HwpDoc/Conversion/Converter2OOXML.h \ + HwpDoc/Conversion/Transform.h \ + HwpDoc/Conversion/Types.h \ + HwpDoc/Conversion/WriterContext.h \ HwpDoc/Errors.h \ HwpDoc/HWPDocInfo.h \ HwpDoc/HWPElements/HWPRecord.h \ diff --git a/HwpFile/HwpDoc/Conversion/Converter2OOXML.cpp b/HwpFile/HwpDoc/Conversion/Converter2OOXML.cpp new file mode 100644 index 0000000000..42fff1a989 --- /dev/null +++ b/HwpFile/HwpDoc/Conversion/Converter2OOXML.cpp @@ -0,0 +1,28 @@ +#include "Converter2OOXML.h" + +namespace HWP +{ +CConverter2OOXML::CConverter2OOXML() + : m_pHWPFile(nullptr) +{} + +void CConverter2OOXML::SetHWPFile(CHWPFile_Private* pHWPFile) +{ + m_pHWPFile = pHWPFile; +} + +void CConverter2OOXML::SetTempDirectory(const STRING& sTempDirectory) +{ + m_sTempDirectory = sTempDirectory; +} + +bool CConverter2OOXML::ConvertTo(const STRING& sFilePath) +{ + if (nullptr == m_pHWPFile || sFilePath.empty()) + return false; + + std::vector arSections = m_pHWPFile->GetSections(); + + return false; +} +} diff --git a/HwpFile/HwpDoc/Conversion/Converter2OOXML.h b/HwpFile/HwpDoc/Conversion/Converter2OOXML.h new file mode 100644 index 0000000000..ae411267b9 --- /dev/null +++ b/HwpFile/HwpDoc/Conversion/Converter2OOXML.h @@ -0,0 +1,21 @@ +#ifndef CONVERTER2OOXML_H +#define CONVERTER2OOXML_H + +#include "../HWPFile_Private.h" + +namespace HWP +{ +class CConverter2OOXML +{ + CHWPFile_Private *m_pHWPFile; + STRING m_sTempDirectory; +public: + CConverter2OOXML(); + + void SetHWPFile(CHWPFile_Private* pHWPFile); + void SetTempDirectory(const STRING& sTempDirectory); + bool ConvertTo(const STRING& sFilePath); +}; +} + +#endif // CONVERTER2OOXML_H diff --git a/HwpFile/HwpDoc/Conversion/Transform.cpp b/HwpFile/HwpDoc/Conversion/Transform.cpp new file mode 100644 index 0000000000..7fa8f6ece4 --- /dev/null +++ b/HwpFile/HwpDoc/Conversion/Transform.cpp @@ -0,0 +1,9 @@ +#include "Transform.h" + +namespace HWP +{ +CTransform::CTransform() +{ + +} +} diff --git a/HwpFile/HwpDoc/Conversion/Transform.h b/HwpFile/HwpDoc/Conversion/Transform.h new file mode 100644 index 0000000000..f9639fae9e --- /dev/null +++ b/HwpFile/HwpDoc/Conversion/Transform.h @@ -0,0 +1,63 @@ +#ifndef TRANSFORM_H +#define TRANSFORM_H + +#include "../HWPElements/HWPRecordBorderFill.h" + +#include "Types.h" + +namespace HWP +{ +class CTransform +{ +public: + CTransform(); + + static int TranslateHWP2Office(int nHWPValue) + { + return (int)(nHWPValue * ((double)21000 / 59529)); + } + + static short ToLineWidth(short shHWPThick) + { + switch(shHWPThick) + { + case 0: // 0.1mm + return 10; + case 1: // 0.12mm + return 12; + case 2: // 0.15mm + return 15; + case 3: // 0.2mm + return 20; + case 4: // 0.25mm + return 25; + case 5: // 0.3mm + return 30; + case 6: // 0.4mm + return 40; + case 7: // 0.5mm + return 50; + case 8: // 0.6mm + return 60; + case 9: // 0.7mm + return 70; + case 10: // 1.0mm + return 100; + case 11: // 1.5mm + return 150; + case 12: // 2.0mm + return 200; + case 13: // 3.0mm + return 300; + case 14: // 4.0mm + return 400; + case 15: // 5.0mm + return 500; + default: + return 0; + } + } +}; +} + +#endif // TRANSFORM_H diff --git a/HwpFile/HwpDoc/Conversion/Types.h b/HwpFile/HwpDoc/Conversion/Types.h new file mode 100644 index 0000000000..4cc8ffbbbb --- /dev/null +++ b/HwpFile/HwpDoc/Conversion/Types.h @@ -0,0 +1,15 @@ +#ifndef TYPES_H +#define TYPES_H + +namespace HWP +{ + struct TBorderLine + { + int m_nColor; + int m_nInnerLineWidth; + int m_nOuterLineWudth; + int nLineDistance; + }; +} + +#endif // TYPES_H diff --git a/HwpFile/HwpDoc/Conversion/WriterContext.cpp b/HwpFile/HwpDoc/Conversion/WriterContext.cpp new file mode 100644 index 0000000000..cdff0113d2 --- /dev/null +++ b/HwpFile/HwpDoc/Conversion/WriterContext.cpp @@ -0,0 +1,212 @@ +#include "WriterContext.h" +#include "../HWPFile_Private.h" + +namespace HWP +{ +CWriterContext::CWriterContext() + : m_eType(EHanType::NONE), m_pHWPFile(nullptr) +{} + +CWriterContext::~CWriterContext() +{ + if (nullptr != m_pHWPFile) + delete m_pHWPFile; +} + +VECTOR CWriterContext::GetSections() +{ + switch(m_eType) + { + case EHanType::NONE: break; + case EHanType::HWP: + { + if (nullptr != m_pHWPFile) + return m_pHWPFile->GetSections(); + + break; + } + case EHanType::HWPX: + break; + } + + return VECTOR(); +} + +STRING CWriterContext::DetectHancom(const STRING& sPathToFile) +{ + STRING sDetectingType; + + CHWPFile_Private* pHwpTemp = new CHWPFile_Private(sPathToFile); + if (nullptr != pHwpTemp) + { + if (pHwpTemp->Detect()) + { + sDetectingType = L"HWP"; + pHwpTemp->Close(); + } + + delete pHwpTemp; + } + + if (!sDetectingType.empty()) + return sDetectingType; + + //TODO:: добавить HWPX + + return sDetectingType; +} + +bool CWriterContext::Detect() +{ + switch(m_eType) + { + case EHanType::HWP: + { + if (nullptr == m_pHWPFile) + return false; + + return m_pHWPFile->Detect(); + } + case EHanType::NONE: + case EHanType::HWPX: + return false; + } +} + +bool CWriterContext::Open(const STRING& sPathToFile, const STRING& sHanType) +{ + if (L"HWP" == sHanType) + { + m_eType = EHanType::HWP; + m_pHWPFile = new CHWPFile_Private(sPathToFile); + + if (nullptr == m_pHWPFile) + return false; + + return m_pHWPFile->Open(); + } + + return false; +} + +void CWriterContext::Close() +{ + switch (m_eType) + { + case EHanType::HWP: + { + if (nullptr != m_pHWPFile) + m_pHWPFile->Close(); + break; + } + case EHanType::NONE: + case EHanType::HWPX: + break; + } +} + +const CHWPDocInfo* CWriterContext::GetDocInfo() +{ + switch (m_eType) + { + case EHanType::HWP: + { + if (nullptr == m_pHWPFile) + return nullptr; + + return m_pHWPFile->GetDocInfo(); + } + case EHanType::NONE: + case EHanType::HWPX: + return nullptr; + } +} + +const CHWPRecordBorderFill* CWriterContext::GetBorderFill(short shId) +{ + const CHWPDocInfo* pDocInfo = GetDocInfo(); + + if (nullptr == pDocInfo || 0 >= shId) + return nullptr; + + return (CHWPRecordBorderFill*)pDocInfo->GetBorderFill(shId - 1); +} + +const CHWPRecordParaShape* CWriterContext::GetParaShape(int nId) +{ + const CHWPDocInfo* pDocInfo = GetDocInfo(); + + if (nullptr == pDocInfo || 0 >= nId) + return nullptr; + + return (CHWPRecordParaShape*)pDocInfo->GetParaShape(nId); +} + +const CHWPRecordStyle* CWriterContext::GetParaStyle(short shId) +{ + const CHWPDocInfo* pDocInfo = GetDocInfo(); + + if (nullptr == pDocInfo || 0 >= shId) + return nullptr; + + return (CHWPRecordStyle*)pDocInfo->GetStyle(shId); +} + +const CHWPRecordCharShape* CWriterContext::GetCharShape(int nId) +{ + const CHWPDocInfo* pDocInfo = GetDocInfo(); + + if (nullptr == pDocInfo || 0 >= nId) + return nullptr; + + return (CHWPRecordCharShape*)pDocInfo->GetCharShape(nId); +} + +const CHWPRecordNumbering* CWriterContext::GetNumbering(short shId) +{ + const CHWPDocInfo* pDocInfo = GetDocInfo(); + + if (nullptr == pDocInfo || 0 >= shId) + return nullptr; + + return (CHWPRecordNumbering*)pDocInfo->GetNumbering(shId); +} + +const CHWPRecordBullet* CWriterContext::GetBullet(short shId) +{ + const CHWPDocInfo* pDocInfo = GetDocInfo(); + + if (nullptr == pDocInfo || 0 >= shId) + return nullptr; + + return (CHWPRecordBullet*)pDocInfo->GetBullet(shId - 1); +} + +const CHwpRecordTabDef* CWriterContext::GetTabDef(short shId) +{ + const CHWPDocInfo* pDocInfo = GetDocInfo(); + + if (nullptr == pDocInfo || 0 >= shId) + return nullptr; + + return (CHwpRecordTabDef*)pDocInfo->GetTabDef(shId); +} + +STRING CWriterContext::GetBinFilename(const STRING& sId) +{ + //TODO::реализовать + return STRING(); +} + +bool CWriterContext::GetBinBytes(const STRING& sId, CHWPStream& oBuffer) +{ + //TODO::реализовать + return false; +} + +STRING CWriterContext::GetBinFormat(const STRING& sId) +{ + //TODO::реализовать + return STRING(); +} +} diff --git a/HwpFile/HwpDoc/Conversion/WriterContext.h b/HwpFile/HwpDoc/Conversion/WriterContext.h new file mode 100644 index 0000000000..b890cb333f --- /dev/null +++ b/HwpFile/HwpDoc/Conversion/WriterContext.h @@ -0,0 +1,47 @@ +#ifndef WRITERCONTEXT_H +#define WRITERCONTEXT_H + +#include "../HWPFile.h" +#include "../HanType.h" +#include "../HWPSection.h" + +#include "../HWPElements/HWPRecordParaShape.h" +#include "../HWPElements/HWPRecordStyle.h" +#include "../HWPElements/HWPRecordCharShape.h" +#include "../HWPElements/HWPRecordNumbering.h" +#include "../HWPElements/HWPRecordBullet.h" +#include "../HWPElements/HwpRecordTabDef.h" + +namespace HWP +{ +class CWriterContext +{ + EHanType m_eType; + CHWPFile_Private* m_pHWPFile; + int m_nVersion; +public: + CWriterContext(); + ~CWriterContext(); + + VECTOR GetSections(); + STRING DetectHancom(const STRING& sPathToFile); + bool Detect(); + bool Open(const STRING& sPathToFile, const STRING& sHanType); + void Close(); + + const CHWPDocInfo* GetDocInfo(); + const CHWPRecordBorderFill* GetBorderFill(short shId); + const CHWPRecordParaShape* GetParaShape(int nId); + const CHWPRecordStyle* GetParaStyle(short shId); + const CHWPRecordCharShape* GetCharShape(int nId); + const CHWPRecordNumbering* GetNumbering(short shId); + const CHWPRecordBullet* GetBullet(short shId); + const CHwpRecordTabDef* GetTabDef(short shId); + + STRING GetBinFilename(const STRING& sId); + bool GetBinBytes(const STRING& sId, CHWPStream& oBuffer); + STRING GetBinFormat(const STRING& sId); +}; +} + +#endif // WRITERCONTEXT_H diff --git a/HwpFile/HwpDoc/HWPDocInfo.cpp b/HwpFile/HwpDoc/HWPDocInfo.cpp index e6daf9e766..7bca3671f6 100644 --- a/HwpFile/HwpDoc/HWPDocInfo.cpp +++ b/HwpFile/HwpDoc/HWPDocInfo.cpp @@ -1,14 +1,34 @@ #include "HWPDocInfo.h" #include "HWPElements/HWPRecordBinData.h" +#include "HWPElements/HWPRecordDocumentProperties.h" +#include "HWPElements/HWPRecordIDMaping.h" +#include "HWPElements/HWPRecordFaceName.h" +#include "HWPElements/HWPRecordBorderFill.h" +#include "HWPElements/HWPRecordCharShape.h" +#include "HwpDoc/HWPElements/HWPRecordBullet.h" +#include "HwpDoc/HWPElements/HWPRecordNumbering.h" +#include "HwpDoc/HWPElements/HWPRecordParaShape.h" +#include "HwpDoc/HWPElements/HWPRecordStyle.h" +#include "HwpDoc/HWPElements/HwpRecordTabDef.h" namespace HWP { +ECompatDoc GetCompatDoc(int nValue) +{ + switch(static_cast(nValue)) + { + case ECompatDoc::HWP: return ECompatDoc::HWP; + case ECompatDoc::OLD_HWP: return ECompatDoc::OLD_HWP; + case ECompatDoc::MS_WORD: return ECompatDoc::MS_WORD; + default: + return ECompatDoc::UNKNOWN; + } +} + CHWPDocInfo::CHWPDocInfo(EHanType eHanType) : m_eHanType(eHanType) -{ - -} +{} // CHWPDocInfo::CHWPDocInfo(CHWPXFile* pHWPXFile) // : m_eHanType(EHanType::HWPX), m_pParentHWPX(pHWPXFile) @@ -18,25 +38,25 @@ CHWPDocInfo::CHWPDocInfo(CHWPFile_Private* pHWPFile) : m_eHanType(EHanType::HWP), m_pParentHWP(pHWPFile) {} -#define REMOVE_LIST_DATA(list) \ - for (CHWPRecord* pRecord : list) \ +CHWPDocInfo::~CHWPDocInfo() +{ + #define REMOVE_LIST_DATA(array) \ + for (CHWPRecord* pRecord : array) \ { \ if (nullptr != pRecord) \ delete pRecord; \ } \ - list.clear() \ + array.clear() \ -CHWPDocInfo::~CHWPDocInfo() -{ - REMOVE_LIST_DATA(m_lRecords); - REMOVE_LIST_DATA(m_lFaseNames); - REMOVE_LIST_DATA(m_lBorderFills); - REMOVE_LIST_DATA(m_lCharShapes); - REMOVE_LIST_DATA(m_lNumberings); - REMOVE_LIST_DATA(m_lBullets); - REMOVE_LIST_DATA(m_lParaShapes); - REMOVE_LIST_DATA(m_lStyles); - REMOVE_LIST_DATA(m_lTabDefs); + REMOVE_LIST_DATA(m_arRecords); + REMOVE_LIST_DATA(m_arFaseNames); + REMOVE_LIST_DATA(m_arBorderFills); + REMOVE_LIST_DATA(m_arCharShapes); + REMOVE_LIST_DATA(m_arNumberings); + REMOVE_LIST_DATA(m_arBullets); + REMOVE_LIST_DATA(m_arParaShapes); + REMOVE_LIST_DATA(m_arStyles); + REMOVE_LIST_DATA(m_arTabDefs); for (std::pair oBinData : m_mBinDatas) { @@ -68,19 +88,151 @@ bool CHWPDocInfo::Parse(CHWPStream& oBuffer, int nVersion) CHWPRecord *pRecord = nullptr; EHWPTag eTag = GetTagFromNum(nTagNum); + #define CREATE_AND_ADD_RECORD(type_record, array) \ + pRecord = new type_record(*this, nTagNum, nLevel, nSize, oBuffer, nOff, nVersion); \ + if (nullptr != pRecord) \ + array.push_back(pRecord) + switch (eTag) { - case EHWPTag::HWPTAG_BIN_DATA: + case HWPTAG_DOCUMENT_PROPERTIES: + { + CREATE_AND_ADD_RECORD(CHWPRecordDocumentProperties, m_arRecords); + break; + } + case HWPTAG_ID_MAPPINGS: + { + CREATE_AND_ADD_RECORD(CHWPRecordIDMaping, m_arRecords); + break; + } + case HWPTAG_BIN_DATA: { CHWPRecordBinData *pBindData = new CHWPRecordBinData(*this, nTagNum, nLevel, nSize, oBuffer, nOff, nVersion); if (nullptr != pBindData) m_mBinDatas.insert(std::make_pair(pBindData->GetItemID(), pBindData)); + + break; + } + case HWPTAG_FACE_NAME: + { + CREATE_AND_ADD_RECORD(CHWPRecordFaceName, m_arFaseNames); + break; + } + case HWPTAG_BORDER_FILL: + { + CREATE_AND_ADD_RECORD(CHWPRecordBorderFill, m_arBorderFills); + break; + } + case HWPTAG_CHAR_SHAPE: + { + CREATE_AND_ADD_RECORD(CHWPRecordCharShape, m_arCharShapes); + break; + } + case HWPTAG_TAB_DEF: + { + CREATE_AND_ADD_RECORD(CHwpRecordTabDef, m_arTabDefs); + break; + } + case HWPTAG_NUMBERING: + { + CREATE_AND_ADD_RECORD(CHWPRecordNumbering, m_arNumberings); + break; + } + case HWPTAG_BULLET: + { + CREATE_AND_ADD_RECORD(CHWPRecordBullet, m_arBullets); + break; + } + case HWPTAG_PARA_SHAPE: + { + CREATE_AND_ADD_RECORD(CHWPRecordParaShape, m_arParaShapes); + break; + } + case HWPTAG_STYLE: + { + CREATE_AND_ADD_RECORD(CHWPRecordStyle, m_arStyles); + break; + } + case HWPTAG_COMPATIBLE_DOCUMENT: + { + int nCompatDoc; + oBuffer.ReadInt(nCompatDoc); + + m_eCompatibleDoc = GetCompatDoc(nCompatDoc); + break; + } + case HWPTAG_LAYOUT_COMPATIBILITY: + case HWPTAG_DOC_DATA: + case HWPTAG_DISTRIBUTE_DOC_DATA: + case HWPTAG_TRACKCHANGE: + case HWPTAG_MEMO_SHAPE: + case HWPTAG_FORBIDDEN_CHAR: + case HWPTAG_TRACK_CHANGE: + case HWPTAG_TRACK_CHANGE_AUTHOR: + default: + { + oBuffer.Skip(nSize); + break; } - default: break; } } return true; } + +#define GET_RECORD(array_records, index) \ + if (array_records.size() <= index) \ + return nullptr; \ + return array_records[index] + +const CHWPRecord* CHWPDocInfo::GetRecord(int nIndex) const +{ + GET_RECORD(m_arRecords, nIndex); +} + +const CHWPRecord* CHWPDocInfo::GetFaceName(int nIndex) const +{ + GET_RECORD(m_arFaseNames, nIndex); +} + +const CHWPRecord* CHWPDocInfo::GetBorderFill(int nIndex) const +{ + GET_RECORD(m_arBorderFills, nIndex); +} + +const CHWPRecord* CHWPDocInfo::GetCharShape(int nIndex) const +{ + GET_RECORD(m_arCharShapes, nIndex); +} + +const CHWPRecord* CHWPDocInfo::GetNumbering(int nIndex) const +{ + GET_RECORD(m_arNumberings, nIndex); +} + +const CHWPRecord* CHWPDocInfo::GetBullet(int nIndex) const +{ + GET_RECORD(m_arBullets, nIndex); +} + +const CHWPRecord* CHWPDocInfo::GetParaShape(int nIndex) const +{ + GET_RECORD(m_arParaShapes, nIndex); +} + +const CHWPRecord* CHWPDocInfo::GetStyle(int nIndex) const +{ + GET_RECORD(m_arStyles, nIndex); +} + +const CHWPRecord* CHWPDocInfo::GetTabDef(int nIndex) const +{ + GET_RECORD(m_arTabDefs, nIndex); +} + +CHWPFile_Private* CHWPDocInfo::GetParentHWP() +{ + return m_pParentHWP; +} } diff --git a/HwpFile/HwpDoc/HWPDocInfo.h b/HwpFile/HwpDoc/HWPDocInfo.h index 430682ca5f..e085d8cc77 100644 --- a/HwpFile/HwpDoc/HWPDocInfo.h +++ b/HwpFile/HwpDoc/HWPDocInfo.h @@ -6,30 +6,36 @@ #include "HWPElements/HWPRecord.h" #include -#include namespace HWP { +enum class ECompatDoc +{ + HWP, + OLD_HWP, + MS_WORD, + UNKNOWN +}; + class CHWPFile_Private; class CHWPDocInfo { EHanType m_eHanType; // CHWPXFile *m_pParentHWPX; CHWPFile_Private *m_pParentHWP; - std::list m_lRecords; + VECTOR m_arRecords; std::map m_mBinDatas; - std::list m_lFaseNames; - std::list m_lBorderFills; - std::list m_lCharShapes; - std::list m_lNumberings; - std::list m_lBullets; - std::list m_lParaShapes; - std::list m_lStyles; - std::list m_lTabDefs; - - // CCompatDoc m_oCompatibleDoc; + VECTOR m_arFaseNames; + VECTOR m_arBorderFills; + VECTOR m_arCharShapes; + VECTOR m_arNumberings; + VECTOR m_arBullets; + VECTOR m_arParaShapes; + VECTOR m_arStyles; + VECTOR m_arTabDefs; + ECompatDoc m_eCompatibleDoc; public: CHWPDocInfo(EHanType eHanType); // CHWPDocInfo(CHWPXFile* pHWPXFile); @@ -38,6 +44,18 @@ public: ~CHWPDocInfo(); bool Parse(CHWPStream& oBuffer, int nVersion); + + const CHWPRecord* GetRecord(int nIndex) const; + const CHWPRecord* GetFaceName(int nIndex) const; + const CHWPRecord* GetBorderFill(int nIndex) const; + const CHWPRecord* GetCharShape(int nIndex) const; + const CHWPRecord* GetNumbering(int nIndex) const; + const CHWPRecord* GetBullet(int nIndex) const; + const CHWPRecord* GetParaShape(int nIndex) const; + const CHWPRecord* GetStyle(int nIndex) const; + const CHWPRecord* GetTabDef(int nIndex) const; + + CHWPFile_Private* GetParentHWP(); }; } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordBinData.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordBinData.cpp index 636870e0d1..1aa4c86fb1 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordBinData.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordBinData.cpp @@ -11,6 +11,4 @@ STRING CHWPRecordBinData::GetItemID() const { return m_sItemID; } - - } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.cpp index ac5214d947..220a95a879 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.cpp @@ -63,7 +63,7 @@ CFill::CFill() CFill::CFill(CHWPStream& oBuffer, int nOff, int nSize) { - BYTE *pCurrentPosition = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.ReadInt(m_nFillType); @@ -135,7 +135,7 @@ CFill::CFill(CHWPStream& oBuffer, int nOff, int nSize) if (CHECK_FLAG(m_nFillType, 0x02)) oBuffer.ReadByte(m_chAlpha); - m_nSize = oBuffer.GetCurPtr() - pCurrentPosition; + m_nSize = oBuffer.GetDistanceToLastPos(true); } int CFill::GetSize() const @@ -165,7 +165,6 @@ CHWPRecordBorderFill::CHWPRecordBorderFill(int nTagNum, int nLevel, int nSize) CHWPRecordBorderFill::CHWPRecordBorderFill(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) : CHWPRecord(nTagNum, nLevel, nSize), m_pParent(&oDocInfo) { - BYTE *pCurrentPosition = oBuffer.GetCurPtr(); short shTypeBits; oBuffer.ReadShort(shTypeBits); diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.cpp index 66f161db83..9ae7e2fa41 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.cpp @@ -5,9 +5,7 @@ namespace HWP CHWPRecordBullet::CHWPRecordBullet(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) : CHWPRecord(nTagNum, nLevel, nSize), m_pParent(&oDocInfo) { - BYTE* pOldCurentPos = oBuffer.GetCurPtr(); - - #define CHECK_SIZE() nSize > (oBuffer.GetCurPtr() - pOldCurentPos) + oBuffer.SavePosition(); int nTypeBits; oBuffer.ReadInt(nTypeBits); @@ -23,19 +21,19 @@ CHWPRecordBullet::CHWPRecordBullet(CHWPDocInfo& oDocInfo, int nTagNum, int nLeve oBuffer.Skip(2); //TODO:: ByteBuffer.wrap(buf, offset, 2).order(ByteOrder.LITTLE_ENDIAN).getChar(); - if (CHECK_SIZE()) + if (nSize > oBuffer.GetDistanceToLastPos()) oBuffer.ReadInt(m_nBulletImage); - if (CHECK_SIZE()) + if (nSize > oBuffer.GetDistanceToLastPos()) oBuffer.ReadByte(m_chBright); - if (CHECK_SIZE()) + if (nSize > oBuffer.GetDistanceToLastPos()) oBuffer.ReadByte(m_chContrast); - if (CHECK_SIZE()) + if (nSize > oBuffer.GetDistanceToLastPos()) oBuffer.ReadByte(m_chImageEffect); - if (CHECK_SIZE()) + if (nSize > oBuffer.GetDistanceToLastPos(true)) { short shValue; oBuffer.ReadShort(shValue); diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.cpp index 293587dd5a..c12e6e96da 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.cpp @@ -68,7 +68,7 @@ EShadow GetShadow(int nValue) CHWPRecordCharShape::CHWPRecordCharShape(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) : CHWPRecord(nTagNum, nLevel, nSize), m_pParent(&oDocInfo) { - BYTE* pOldCurentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); for (int nIndex = 0; nIndex < MAX_ELEMENTS; ++nIndex) { @@ -128,12 +128,12 @@ CHWPRecordCharShape::CHWPRecordCharShape(CHWPDocInfo& oDocInfo, int nTagNum, int oBuffer.ReadColor(m_nShadeColor); oBuffer.ReadColor(m_nShadeColor); - #define CHECK_SIZE (nSize > (oBuffer.GetCurPtr() - pOldCurentPos)) - - if (CHECK_SIZE) + if (nSize > oBuffer.GetDistanceToLastPos()) oBuffer.ReadShort(m_shBorderFillIDRef); - if (nVersion > 5030 && CHECK_SIZE) + if (nVersion > 5030 && nSize > oBuffer.GetDistanceToLastPos()) oBuffer.ReadColor(m_nStrikeOutColor); + + oBuffer.RemoveLastSavedPos(); } } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.h b/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.h index bd283708f4..515a4aa74a 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.h +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.h @@ -58,7 +58,7 @@ enum class EAccent TWOARAEA }; -EAccent GetAccent(int nValue) +inline EAccent GetAccent(int nValue) { switch(static_cast(nValue)) { diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordCtrlData.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordCtrlData.cpp index 8537be7ee5..6bbca3eded 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordCtrlData.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordCtrlData.cpp @@ -29,4 +29,13 @@ EParamItemType GetParamItemType(int nValue) CHWPRecordCtrlData::CHWPRecordCtrlData(int nTagNum, int nLevel, int nSize) : CHWPRecord(nTagNum, nLevel, nSize) {} + +int CHWPRecordCtrlData::ParseCtrl(CCtrl& oCtrl, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) +{ + // TODO:: Вернуться к этому моменту + // Само по себе содержание документа Hankom не позволяет понять, как его интерпретировать. + + oBuffer.Skip(nSize); + return nSize; +} } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordCtrlData.h b/HwpFile/HwpDoc/HWPElements/HWPRecordCtrlData.h index 527afba7f2..5ec12bccba 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordCtrlData.h +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordCtrlData.h @@ -3,6 +3,7 @@ #include "../HWPStream.h" #include "HWPRecord.h" +#include "../Paragraph/Ctrl.h" #include namespace HWP @@ -43,6 +44,8 @@ class CHWPRecordCtrlData : public CHWPRecord LIST m_arParamSets; public: CHWPRecordCtrlData(int nTagNum, int nLevel, int nSize); + + static int ParseCtrl(CCtrl& oCtrl, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); }; } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordCtrlHeader.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordCtrlHeader.cpp index af6e1c3888..d6027218f7 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordCtrlHeader.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordCtrlHeader.cpp @@ -96,6 +96,8 @@ CCtrl* CHWPRecordCtrlHeader::Parse(int nTagNum, int nLevel, int nSize, CHWPStrea oBuffer.Skip(nTempSize); } + oBuffer.RemoveLastSavedPos(); + return pCtrl; } } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordFormObject.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordFormObject.cpp index 2071141553..59e3900b16 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordFormObject.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordFormObject.cpp @@ -14,8 +14,10 @@ int CHWPRecordFormObject::ParseCtrl(CCtrlForm& oForm, int nSize, CHWPStream& oBu oBuffer.Skip(4); // tbp+ oBuffer.Skip(4); // Длина строки? - oBuffer.ReadString(m_sFormStr, EStringCharacter::UTF16); + short shLen = oBuffer.ReadShort() * 2; + oBuffer.Skip(shLen); + // oBuffer.ReadString(m_sFormStr, EStringCharacter::UTF16); - return oBuffer.GetDistanceToLastPos(); + return oBuffer.GetDistanceToLastPos(true); } } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordFormObject.h b/HwpFile/HwpDoc/HWPElements/HWPRecordFormObject.h index 71ea067829..eb0cf73ad8 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordFormObject.h +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordFormObject.h @@ -8,11 +8,11 @@ namespace HWP { class CHWPRecordFormObject : public CHWPRecord { - STRING m_sFormStr; + static STRING m_sFormStr; public: CHWPRecordFormObject(int nTagNum, int nLevel, int nSize); - int ParseCtrl(CCtrlForm& oForm, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); + static int ParseCtrl(CCtrlForm& oForm, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); }; } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordIDMaping.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordIDMaping.cpp index bbf7fbc1c2..f80b0a2f99 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordIDMaping.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordIDMaping.cpp @@ -39,10 +39,10 @@ CHWPRecordIDMaping::CHWPRecordIDMaping(CHWPDocInfo& oDocInfo, int nTagNum, int n { int nCount; oBuffer.ReadInt(nCount); + m_arIdMappingNum.push_back(nCount); m_arCounts[nIndex] = nCount; - //TODO:: BinData } } } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordNumbering.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordNumbering.cpp index b23ff150f6..2cc51fb051 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordNumbering.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordNumbering.cpp @@ -5,7 +5,7 @@ namespace HWP CHWPRecordNumbering::CHWPRecordNumbering(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) : CHWPRecord(nTagNum, nLevel, nSize), m_pParent(&oDocInfo) { - BYTE *pOldCurentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); for (int nIndex = 0; nIndex < 7; ++nIndex) { @@ -25,15 +25,13 @@ CHWPRecordNumbering::CHWPRecordNumbering(CHWPDocInfo& oDocInfo, int nTagNum, int oBuffer.ReadShort(m_shStart); - #define CHECK_SIZE (nSize > (oBuffer.GetCurPtr() - pOldCurentPos)) - - if (nVersion > 5025 && CHECK_SIZE) //TODO:: добавить проверку offset-off < size + if (nVersion > 5025 && (nSize > oBuffer.GetDistanceToLastPos())) //TODO:: добавить проверку offset-off < size { for (int nIndex = 0; nIndex < 7; ++nIndex) oBuffer.ReadInt(m_arNumbering[nIndex].m_nStartNumber); } - if (nVersion > 5100 && CHECK_SIZE) //TODO:: добавить проверку offset-off < size + if (nVersion > 5100 && (nSize > oBuffer.GetDistanceToLastPos())) //TODO:: добавить проверку offset-off < size { for (int nIndex = 0; nIndex < 3; ++nIndex) { @@ -52,5 +50,7 @@ CHWPRecordNumbering::CHWPRecordNumbering(CHWPDocInfo& oDocInfo, int nTagNum, int for (int nIndex = 0; nIndex < 3; ++nIndex) oBuffer.ReadInt(m_arExtLevelStart[nIndex]); } + + oBuffer.RemoveLastSavedPos(); } } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordParaRangeTag.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordParaRangeTag.cpp index dddf3640bc..7ed009f964 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordParaRangeTag.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordParaRangeTag.cpp @@ -30,6 +30,8 @@ int CHWPRecordParaRangeTag::Parse(CHWPPargraph& oPara, int nTagNum, int nLevel, oPara.AddRangeTag(pRangeTag); } + + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); return nSize; } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordParaText.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordParaText.cpp index ddd7cdce23..a4fdc352ad 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordParaText.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordParaText.cpp @@ -23,15 +23,20 @@ CHWPRecordParaText::CHWPRecordParaText(int nTagNum, int nLevel, int nSize) LIST CHWPRecordParaText::Parse(int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { + oBuffer.SavePosition(); + STRING sText; oBuffer.ReadString(sText, nSize, EStringCharacter::UTF16); if (sText.empty()) + { + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); return LIST(); + } std::wregex oRegex(L"[\\u0000\\u000a\\u000d\\u0018-\\u001f]|[\\u0001\\u0002-\\u0009\\u000b-\\u000c\\u000e-\\u0017].{6}[\\u0001\\u0002-\\u0009\\u000b-\\u000c\\u000e-\\u0017]"); std::wsregex_iterator itCurrent(sText.begin(), sText.end(), oRegex); - std::wsregex_iterator itEnd; + std::wsregex_iterator itEnd = std::wsregex_iterator(); int nPrevIndex = 0; @@ -135,17 +140,18 @@ LIST CHWPRecordParaText::Parse(int nTagNum, int nLevel, int nSize, CHWPS default: break; } - - nPrevIndex = itCurrent->position() + itCurrent->length(); - } - - if (nPrevIndex < sText.length()) - { - // write final text - arParas.push_back(new CParaText(L"____", sText.substr(nPrevIndex), nPrevIndex)); } + nPrevIndex = itCurrent->position() + itCurrent->length(); + ++itCurrent; } + if (nPrevIndex < sText.length()) + { + // write final text + arParas.push_back(new CParaText(L"____", sText.substr(nPrevIndex), nPrevIndex)); + } + + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); return arParas; } } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordStyle.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordStyle.cpp index d288c3b216..e18eb9d03d 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordStyle.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordStyle.cpp @@ -19,5 +19,4 @@ CHWPRecordStyle::CHWPRecordStyle(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, m_nParaShape = oBuffer.ReadShort(); m_nCharShape = oBuffer.ReadShort(); } - } diff --git a/HwpFile/HwpDoc/HWPElements/HWPTag.h b/HwpFile/HwpDoc/HWPElements/HWPTag.h index f1249d2a02..5235fdcf20 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPTag.h +++ b/HwpFile/HwpDoc/HWPElements/HWPTag.h @@ -66,57 +66,57 @@ inline EHWPTag GetTagFromNum(int nTagNum) { switch (static_cast(nTagNum)) { - case EHWPTag::HWPTAG_DOCUMENT_PROPERTIES: - case EHWPTag::HWPTAG_ID_MAPPINGS: - case EHWPTag::HWPTAG_BIN_DATA: - case EHWPTag::HWPTAG_FACE_NAME: - case EHWPTag::HWPTAG_BORDER_FILL: - case EHWPTag::HWPTAG_CHAR_SHAPE: - case EHWPTag::HWPTAG_TAB_DEF: - case EHWPTag::HWPTAG_NUMBERING: - case EHWPTag::HWPTAG_BULLET: - case EHWPTag::HWPTAG_PARA_SHAPE: - case EHWPTag::HWPTAG_STYLE: - case EHWPTag::HWPTAG_DISTRIBUTE_DOC_DATA: - case EHWPTag::HWPTAG_COMPATIBLE_DOCUMENT: - case EHWPTag::HWPTAG_LAYOUT_COMPATIBILITY: - case EHWPTag::HWPTAG_TRACKCHANGE: - case EHWPTag::HWPTAG_PARA_HEADER: - case EHWPTag::HWPTAG_PARA_TEXT: - case EHWPTag::HWPTAG_PARA_CHAR_SHAPE: - case EHWPTag::HWPTAG_PARA_LINE_SEG: - case EHWPTag::HWPTAG_PARA_RANGE_TAG: - case EHWPTag::HWPTAG_CTRL_HEADER: - case EHWPTag::HWPTAG_LIST_HEADER: - case EHWPTag::HWPTAG_PAGE_DEF: - case EHWPTag::HWPTAG_FOOTNOTE_SHAPE: - case EHWPTag::HWPTAG_PAGE_BORDER_FILL: - case EHWPTag::HWPTAG_SHAPE_COMPONENT: - case EHWPTag::HWPTAG_TABLE: - case EHWPTag::HWPTAG_SHAPE_COMPONENT_LINE: - case EHWPTag::HWPTAG_SHAPE_COMPONENT_RECTANGLE: - case EHWPTag::HWPTAG_SHAPE_COMPONENT_ELLIPSE: - case EHWPTag::HWPTAG_SHAPE_COMPONENT_ARC: - case EHWPTag::HWPTAG_SHAPE_COMPONENT_POLYGON: - case EHWPTag::HWPTAG_SHAPE_COMPONENT_CURVE: - case EHWPTag::HWPTAG_SHAPE_COMPONENT_OLE: - case EHWPTag::HWPTAG_SHAPE_COMPONENT_PICTURE: - case EHWPTag::HWPTAG_SHAPE_COMPONENT_CONTAINER: - case EHWPTag::HWPTAG_CTRL_DATA: - case EHWPTag::HWPTAG_EQEDIT: - case EHWPTag::HWPTAG_SHAPE_COMPONENT_TEXTART: - case EHWPTag::HWPTAG_FORM_OBJECT: - case EHWPTag::HWPTAG_MEMO_SHAPE: - case EHWPTag::HWPTAG_MEMO_LIST: - case EHWPTag::HWPTAG_FORBIDDEN_CHAR: - case EHWPTag::HWPTAG_CHART_DATA: - case EHWPTag::HWPTAG_TRACK_CHANGE: - case EHWPTag::HWPTAG_TRACK_CHANGE_AUTHOR: - case EHWPTag::HWPTAG_VIDEO_DATA: - case EHWPTag::HWPTAG_SHAPE_COMPONENT_UNKNOWN: + case HWPTAG_DOCUMENT_PROPERTIES: + case HWPTAG_ID_MAPPINGS: + case HWPTAG_BIN_DATA: + case HWPTAG_FACE_NAME: + case HWPTAG_BORDER_FILL: + case HWPTAG_CHAR_SHAPE: + case HWPTAG_TAB_DEF: + case HWPTAG_NUMBERING: + case HWPTAG_BULLET: + case HWPTAG_PARA_SHAPE: + case HWPTAG_STYLE: + case HWPTAG_DISTRIBUTE_DOC_DATA: + case HWPTAG_COMPATIBLE_DOCUMENT: + case HWPTAG_LAYOUT_COMPATIBILITY: + case HWPTAG_TRACKCHANGE: + case HWPTAG_PARA_HEADER: + case HWPTAG_PARA_TEXT: + case HWPTAG_PARA_CHAR_SHAPE: + case HWPTAG_PARA_LINE_SEG: + case HWPTAG_PARA_RANGE_TAG: + case HWPTAG_CTRL_HEADER: + case HWPTAG_LIST_HEADER: + case HWPTAG_PAGE_DEF: + case HWPTAG_FOOTNOTE_SHAPE: + case HWPTAG_PAGE_BORDER_FILL: + case HWPTAG_SHAPE_COMPONENT: + case HWPTAG_TABLE: + case HWPTAG_SHAPE_COMPONENT_LINE: + case HWPTAG_SHAPE_COMPONENT_RECTANGLE: + case HWPTAG_SHAPE_COMPONENT_ELLIPSE: + case HWPTAG_SHAPE_COMPONENT_ARC: + case HWPTAG_SHAPE_COMPONENT_POLYGON: + case HWPTAG_SHAPE_COMPONENT_CURVE: + case HWPTAG_SHAPE_COMPONENT_OLE: + case HWPTAG_SHAPE_COMPONENT_PICTURE: + case HWPTAG_SHAPE_COMPONENT_CONTAINER: + case HWPTAG_CTRL_DATA: + case HWPTAG_EQEDIT: + case HWPTAG_SHAPE_COMPONENT_TEXTART: + case HWPTAG_FORM_OBJECT: + case HWPTAG_MEMO_SHAPE: + case HWPTAG_MEMO_LIST: + case HWPTAG_FORBIDDEN_CHAR: + case HWPTAG_CHART_DATA: + case HWPTAG_TRACK_CHANGE: + case HWPTAG_TRACK_CHANGE_AUTHOR: + case HWPTAG_VIDEO_DATA: + case HWPTAG_SHAPE_COMPONENT_UNKNOWN: return static_cast(nTagNum); default: - return EHWPTag::null; + return null; } } diff --git a/HwpFile/HwpDoc/HWPElements/HwpRecordTabDef.cpp b/HwpFile/HwpDoc/HWPElements/HwpRecordTabDef.cpp index 3d499503b2..fad59bfea0 100644 --- a/HwpFile/HwpDoc/HWPElements/HwpRecordTabDef.cpp +++ b/HwpFile/HwpDoc/HWPElements/HwpRecordTabDef.cpp @@ -46,6 +46,8 @@ CHwpRecordTabDef::CHwpRecordTabDef(CHWPDocInfo& oDocInfo, int nTagNum, int nLeve m_arTabs.push_back(pTab); } + + oBuffer.RemoveLastSavedPos(); } } diff --git a/HwpFile/HwpDoc/HWPFile_Private.cpp b/HwpFile/HwpDoc/HWPFile_Private.cpp index e37a3d6124..4cd507e342 100644 --- a/HwpFile/HwpDoc/HWPFile_Private.cpp +++ b/HwpFile/HwpDoc/HWPFile_Private.cpp @@ -1,9 +1,13 @@ #include "HWPFile_Private.h" #include "HWPDocInfo.h" +#include "../OfficeUtils/src/OfficeUtils.h" #include "../DesktopEditor/common/Directory.h" + #include +#define DEFAULT_BUFFER_SIZE 8096 + namespace HWP { CHWPFile_Private::CHWPFile_Private(const STRING& sFileName) @@ -16,7 +20,7 @@ CHWPFile_Private::~CHWPFile_Private() CLEAR_ARRAY(CHWPSection, m_arViewTexts); } -std::vector CHWPFile_Private::GetSections() +VECTOR CHWPFile_Private::GetSections() { if (m_oFileHeader.Distributable()) return m_arViewTexts; @@ -220,8 +224,86 @@ bool CHWPFile_Private::GetChildStream(const STRING& sEntryName, ECompressed eCom bool CHWPFile_Private::Unzip(CHWPStream& oInput, CHWPStream& oBuffer) { - //TODO:: реализовать - return false; + unsigned char* pInBuffer = new(std::nothrow) unsigned char[oInput.GetSize()]; + + if (nullptr == pInBuffer) + return false; + + unsigned char* pOutBuffer = new(std::nothrow) unsigned char[DEFAULT_BUFFER_SIZE]; + + if (nullptr == pOutBuffer) + { + delete[] pInBuffer; + return false; + } + + CInflate oInflater; + + oInflater.SetOut(pOutBuffer, DEFAULT_BUFFER_SIZE); + oInflater.Init2(); + oInflater.SetIn(pInBuffer, 0); + + int nRes = DEFLATE_OK; + + while (DEFLATE_OK == nRes) + { + const unsigned int unSize = oInput.ReadBytes((BYTE*)pInBuffer, DEFAULT_BUFFER_SIZE); + + oInflater.SetIn(pInBuffer, unSize); + + if (0 == unSize) + break; + + while (oInflater.GetAvailIn() > 0) + { + nRes = oInflater.Process(DEFLATE_SYNC_FLUSH); + + if (DEFLATE_OK != nRes && DEFLATE_STREAM_END != nRes) + break; + + if (oInflater.GetAvailOut() == 0) + oBuffer.WriteBytes((BYTE*)pOutBuffer, DEFAULT_BUFFER_SIZE); + + if (DEFLATE_STREAM_END == nRes) + break; + + oInflater.SetOut(pOutBuffer, DEFAULT_BUFFER_SIZE); + } + } + + bool bEnd = false; + + while (true) + { + nRes = oInflater.Process(DEFLATE_FINISH); + + if (DEFLATE_OK != nRes && DEFLATE_STREAM_END != nRes) + { + oInflater.End(); + } + + if (DEFLATE_STREAM_END == nRes) + bEnd = true; + + if (oInflater.GetAvailOut() < DEFAULT_BUFFER_SIZE) + { + unsigned long ulSize = DEFAULT_BUFFER_SIZE - oInflater.GetAvailOut(); + oBuffer.WriteBytes((BYTE*)pOutBuffer, ulSize); + oInflater.SetOut(pOutBuffer, DEFAULT_BUFFER_SIZE); + } + + if (bEnd) + break; + } + + oInflater.End(); + + delete[] pInBuffer; + delete[] pOutBuffer; + + oBuffer.MoveToStart(); + + return DEFLATE_OK == nRes || DEFLATE_STREAM_END == nRes; } bool CHWPFile_Private::Decrypt(CHWPStream& oInput, CHWPStream& oBuffer) @@ -235,7 +317,7 @@ bool CHWPFile_Private::Decrypt(CHWPStream& oInput, CHWPStream& oBuffer) EHWPTag eTag = GetTagFromNum(nTagNum); - if (EHWPTag::HWPTAG_DISTRIBUTE_DOC_DATA != eTag) + if (HWPTAG_DISTRIBUTE_DOC_DATA != eTag) return false; if (256 != nSize) @@ -257,7 +339,7 @@ bool CHWPFile_Private::GetBodyText(int nVersion) if (m_oFileHeader.Compressed()) { CHWPStream oTempBuffer; - if (!m_oOleFile.Read(*pSection, oTempBuffer) && !Unzip(oTempBuffer, oBuffer)) + if (!m_oOleFile.Read(*pSection, oTempBuffer) || !Unzip(oTempBuffer, oBuffer)) return false; } else if (!m_oOleFile.Read(*pSection, oBuffer)) @@ -282,14 +364,14 @@ bool CHWPFile_Private::GetViewText(int nVersion) if (m_oFileHeader.Compressed()) { CHWPStream oTempDecryptBuffer, oTempBuffer; - if (!m_oOleFile.Read(*pSection, oTempDecryptBuffer) && !!Decrypt(oTempDecryptBuffer, oTempBuffer) && !Unzip(oTempBuffer, oBuffer)) + if (!m_oOleFile.Read(*pSection, oTempDecryptBuffer) || !Decrypt(oTempDecryptBuffer, oTempBuffer) || !Unzip(oTempBuffer, oBuffer)) return false; } else { CHWPStream oTempBuffer; - if (!m_oOleFile.Read(*pSection, oTempBuffer) && !Decrypt(oTempBuffer, oBuffer)) + if (!m_oOleFile.Read(*pSection, oTempBuffer) || !Decrypt(oTempBuffer, oBuffer)) return false; } diff --git a/HwpFile/HwpDoc/HWPSection.cpp b/HwpFile/HwpDoc/HWPSection.cpp index 09e3a51c3b..5881daccf9 100644 --- a/HwpFile/HwpDoc/HWPSection.cpp +++ b/HwpFile/HwpDoc/HWPSection.cpp @@ -10,6 +10,8 @@ #include "Paragraph/CharShape.h" #include "Paragraph/CtrlHeadFoot.h" #include "Paragraph/CtrlTable.h" +#include "Paragraph/CtrlNote.h" +#include "Paragraph/CtrlForm.h" #include "Paragraph/CtrlGeneralShape.h" #include "Paragraph/CtrlShapeRect.h" @@ -21,6 +23,7 @@ #include "Paragraph/CtrlShapeCurve.h" #include "Paragraph/CtrlShapeOle.h" #include "Paragraph/CtrlShapeTextArt.h" +#include "Paragraph/CtrlShapeVideo.h" #include "Paragraph/CellParagraph.h" #include "Paragraph/CapParagraph.h" @@ -29,6 +32,8 @@ #include "HWPElements/HWPRecordParaRangeTag.h" #include "HWPElements/HWPRecordCtrlHeader.h" #include "HWPElements/HWPRecordListHeader.h" +#include "HWPElements/HWPRecordFormObject.h" +#include "HWPElements/HWPRecordCtrlData.h" namespace HWP { @@ -42,18 +47,25 @@ CHWPSection::~CHWPSection() bool CHWPSection::Parse(CHWPStream& oBuffer, int nVersion) { + oBuffer.MoveToStart(); + int nHeader, nTagNum, nLevel, nSize; while (oBuffer.CanRead()) { oBuffer.ReadInt(nHeader); + oBuffer.Skip(-4); nTagNum = nHeader & 0x3FF; // 10 bits (0 - 9 bit) nLevel = (nHeader & 0xFFC00) >> 10; // 10 bits (10-19 bit) nSize = (nHeader & 0xFFF00000) >> 20; // 12 bits (20-31 bit) if (nLevel > 0) { - return true; + if (m_arParas.empty()) + return false; + + ParseRecurse(*m_arParas.back(), nLevel, oBuffer, 0, nVersion); + continue; } if (0xFFF == nSize) @@ -67,7 +79,7 @@ bool CHWPSection::Parse(CHWPStream& oBuffer, int nVersion) EHWPTag eTag = GetTagFromNum(nTagNum); - if (0 == nLevel && EHWPTag::HWPTAG_PARA_HEADER == eTag) + if (0 == nLevel && HWPTAG_PARA_HEADER == eTag) { CHWPPargraph *pCurrPara = CHWPPargraph::Parse(nTagNum, nLevel, nSize, oBuffer, 0, nVersion); @@ -96,6 +108,7 @@ int CHWPSection::ParseRecurse(CHWPPargraph& oCurrPara, int nRunLevel, CHWPStream while (oBuffer.CanRead()) { oBuffer.ReadInt(nHeader); + oBuffer.Skip(-4); nTagNum = nHeader & 0x3FF; // 10 bits (0 - 9 bit) nLevel = (nHeader & 0xFFC00) >> 10; // 10 bits (10-19 bit) nSize = (nHeader & 0xFFF00000) >> 20; // 12 bits (20-31 bit) @@ -334,11 +347,415 @@ int CHWPSection::ParseRecurse(CHWPPargraph& oCurrPara, int nRunLevel, CHWPStream } } - return oBuffer.GetDistanceToLastPos(); + return oBuffer.GetDistanceToLastPos(true); } int CHWPSection::ParseCtrlRecurse(CCtrl& oCurrCtrl, int nRunLevel, CHWPStream& oBuffer, int nOff, int nVersion) { + CCtrl* pCtrl = &oCurrCtrl; + + oBuffer.SavePosition(); + + int nHeader, nTagNum, nLevel, nSize, nHeaderSize; + + while (oBuffer.CanRead()) + { + oBuffer.ReadInt(nHeader); + oBuffer.Skip(-4); + nTagNum = nHeader & 0x3FF; // 10 bits (0 - 9 bit) + nLevel = (nHeader & 0xFFC00) >> 10; // 10 bits (10-19 bit) + nSize = (nHeader & 0xFFF00000) >> 20; // 12 bits (20-31 bit) + + if (0xFFF == nSize) + { + nHeaderSize = 8; + //TODO:: buf[off+7]<<24&0xFF000000 | buf[off+6]<<16&0xFF0000 | buf[off+5]<<8&0xFF00 | buf[off+4]&0xFF; + oBuffer.Skip(4); + oBuffer.ReadInt(nSize); + oBuffer.Skip(-8); + } + else + { + nHeaderSize = 4; + } + + if (nLevel < nRunLevel) + break; + + EHWPTag eTag = GetTagFromNum(nTagNum); + + if (nLevel > nRunLevel) + { + switch(eTag) + { + case HWPTAG_PARA_HEADER: + { + if (nullptr != dynamic_cast(pCtrl)) + ParseCtrlRecurse(*(CCtrlCommon*)pCtrl, nLevel, oBuffer, 0, nVersion); + else + { + oBuffer.Skip(nHeaderSize); + oBuffer.Skip(nSize); + } + break; + } + case HWPTAG_PARA_TEXT: + { + if (nullptr != dynamic_cast(pCtrl)) + { + CHWPPargraph* pLastPara = ((CCtrlCommon*)pCtrl)->GetLastPara(); + ParseRecurse(*pLastPara, nLevel, oBuffer, 0, nVersion); + } + else + { + oBuffer.Skip(nHeaderSize); + oBuffer.Skip(nSize); + } + break; + } + case HWPTAG_LIST_HEADER: + { + oBuffer.Skip(nHeaderSize); + + int nSubParaCount = CHWPRecordListHeader::GetCount(nTagNum, nLevel, nSize, oBuffer, 0, nVersion); + + if (nullptr != dynamic_cast(pCtrl)) + { + ParseListAppend(*(CCtrlCommon*)pCtrl, nSize - 6, oBuffer, 0, nVersion); + CCtrlTable *pCtrlTable = (CCtrlTable*)pCtrl; + if (pCtrlTable->HaveCells()) + { + //TODO:: проверить + break; + } + + CCapParagraph* pNewPara = new CCapParagraph(); + pCtrlTable->AddCaption(pNewPara); + ParseRecurse(*pNewPara, nLevel, oBuffer, 0, nVersion); + } + else if (nullptr != dynamic_cast(pCtrl) || + nullptr != dynamic_cast(pCtrl)) + { + CCtrlCommon* pCtrlCommon = (CCtrlCommon*)pCtrl; + oBuffer.Skip(-6); + + pCtrlCommon->SetTextVerAlign(CHWPRecordListHeader::GetVertAlign(6, oBuffer, 0, nVersion)); + + ParseListAppend(*pCtrlCommon, nSize - 6, oBuffer, 0, nVersion); + ParseCtrlRecurse(*pCtrlCommon, nLevel, oBuffer, 0, nVersion); + } + else if (nullptr != dynamic_cast(pCtrl) || + nullptr != dynamic_cast(pCtrl)) + { + ParseListAppend(*pCtrl, nSize - 6, oBuffer, 0, nVersion); + ParseCtrlRecurse(*pCtrl, nLevel, oBuffer, 0, nVersion); + } + else + oBuffer.Skip(nSize - 6); + + break; + } + case HWPTAG_PAGE_DEF: + case HWPTAG_FOOTNOTE_SHAPE: + case HWPTAG_PAGE_BORDER_FILL: + { + if (nullptr != dynamic_cast(pCtrl)) + ParseCtrlRecurse(*(CCtrlSectionDef*)pCtrl, nLevel, oBuffer, 0, nVersion); + + break; + } + case HWPTAG_SHAPE_COMPONENT: + case HWPTAG_SHAPE_COMPONENT_PICTURE: + case HWPTAG_SHAPE_COMPONENT_LINE: + case HWPTAG_SHAPE_COMPONENT_RECTANGLE: + case HWPTAG_SHAPE_COMPONENT_ELLIPSE: + case HWPTAG_SHAPE_COMPONENT_ARC: + case HWPTAG_SHAPE_COMPONENT_POLYGON: + case HWPTAG_SHAPE_COMPONENT_CURVE: + case HWPTAG_SHAPE_COMPONENT_OLE: + case HWPTAG_EQEDIT: + case HWPTAG_SHAPE_COMPONENT_TEXTART: + case HWPTAG_SHAPE_COMPONENT_UNKNOWN: + { + if (nullptr != dynamic_cast(pCtrl)) + ParseCtrlRecurse(*(CCtrlGeneralShape*)pCtrl, nLevel, oBuffer, 0, nVersion); + else + return oBuffer.GetDistanceToLastPos(true); + + break; + } + case HWPTAG_TABLE: + { + ParseCtrlRecurse(*pCtrl, nLevel, oBuffer, 0, nVersion); + break; + } + case HWPTAG_CTRL_HEADER: + { + return oBuffer.GetDistanceToLastPos(true); + } + case HWPTAG_PARA_RANGE_TAG: + case HWPTAG_CTRL_DATA: + case HWPTAG_FORM_OBJECT: + case HWPTAG_MEMO_SHAPE: + case HWPTAG_MEMO_LIST: + case HWPTAG_CHART_DATA: + case HWPTAG_VIDEO_DATA: + default: + { + ParseCtrlRecurse(*pCtrl, nLevel, oBuffer, 0, nVersion); + break; + } + } + } + else if (nLevel == nRunLevel) + { + oBuffer.Skip(nHeaderSize); + + switch (eTag) + { + case HWPTAG_PARA_HEADER: + { + if (nullptr != dynamic_cast(pCtrl)) + { + CCtrlTable *pCtrltable = (CCtrlTable*)pCtrl; + if (!pCtrltable->HaveCells()) + { + CHWPPargraph *pNewPara = CHWPPargraph::Parse(nTagNum, nLevel, nSize, oBuffer, 0, nVersion); + pCtrltable->AddParagraph(pNewPara); + ParseRecurse(*pNewPara, nLevel, oBuffer, 0, nVersion); + } + else + { + CTblCell* pCell = pCtrltable->GetLastCell(); + + CCellParagraph* pNewPara = new CCellParagraph(); + pCell->AddParagraph(pNewPara); + + CHWPPargraph::Parse(*pNewPara, nSize, oBuffer, 0, nVersion); + ParseRecurse(*pNewPara, nLevel, oBuffer, 0, nVersion); + } + } + else if (nullptr != dynamic_cast(pCtrl)) + { + CHWPPargraph *pNewPara = CHWPPargraph::Parse(nTagNum, nLevel, nSize, oBuffer, 0, nVersion); + ((CCtrlCommon*)pCtrl)->AddParagraph(pNewPara); + CHWPPargraph::Parse(*pNewPara, nSize, oBuffer, 0, nVersion); + ParseRecurse(*pNewPara, nLevel, oBuffer, 0, nVersion); + } + else if (nullptr != dynamic_cast(pCtrl)) + { + CCtrlCommon *pCtrlCommon = (CCtrlCommon*)(pCtrl); + if (0 < pCtrlCommon->GetCaptionWidth() && pCtrlCommon->CaptionsEmpty()) + { + CCapParagraph *pNewPara = new CCapParagraph(); + pCtrlCommon->AddCaption(pNewPara); + CHWPPargraph::Parse(*pNewPara, nSize, oBuffer, 0, nVersion); + ParseRecurse(*pNewPara, nLevel, oBuffer, 0, nVersion); + } + else + { + CHWPPargraph *pNewPara = CHWPPargraph::Parse(nTagNum, nLevel, nSize, oBuffer, 0, nVersion); + pCtrlCommon->AddParagraph(pNewPara); + CHWPPargraph::Parse(*pNewPara, nLevel, oBuffer, 0, nVersion); + ParseRecurse(*pNewPara, nLevel, oBuffer, 0, nVersion); + } + } + else if (nullptr != dynamic_cast(pCtrl)) + { + CHWPPargraph *pNewPara = CHWPPargraph::Parse(nTagNum, nLevel, nSize, oBuffer, 0, nVersion); + ((CCtrlHeadFoot*)pCtrl)->AddParagraph(pNewPara); + ParseRecurse(*pNewPara, nLevel, oBuffer, 0, nVersion); + } + else if (nullptr != dynamic_cast(pCtrl)) + { + CHWPPargraph *pNewPara = CHWPPargraph::Parse(nTagNum, nLevel, nSize, oBuffer, 0, nVersion); + ((CCtrlSectionDef*)pCtrl)->AddParagraph(pNewPara); + ParseRecurse(*pNewPara, nLevel, oBuffer, 0, nVersion); + } + else if (nullptr != dynamic_cast(pCtrl)) + { + CHWPPargraph *pNewPara = CHWPPargraph::Parse(nTagNum, nLevel, nSize, oBuffer, 0, nVersion); + ((CCtrlNote*)pCtrl)->AddParagraph(pNewPara); + ParseRecurse(*pNewPara, nLevel, oBuffer, 0, nVersion); + } + else + { + //TODO:: проверить + CHWPPargraph *pNewPara = CHWPPargraph::Parse(nTagNum, nLevel, nSize, oBuffer, 0, nVersion); + ParseRecurse(*pNewPara, nLevel, oBuffer, 0, nVersion); + delete pNewPara; + } + + break; + } + case HWPTAG_CTRL_HEADER: + { + oBuffer.Skip(-nHeaderSize); + return true; + } + case HWPTAG_PAGE_DEF: + { + if (nullptr != dynamic_cast(pCtrl)) + ((CCtrlSectionDef*)pCtrl)->SetPage(CPage::Parse(nLevel, nSize, oBuffer, 0, nVersion)); + + break; + } + case HWPTAG_FOOTNOTE_SHAPE: + { + if (nullptr == dynamic_cast(pCtrl)) + break; + + CCtrlSectionDef *pSecDef = (CCtrlSectionDef*)pCtrl; + pSecDef->AddNoteShape(CNoteShape::Parse(nLevel, nSize, oBuffer, 0, nVersion)); + + break; + } + case HWPTAG_PAGE_BORDER_FILL: + { + if (nullptr == dynamic_cast(pCtrl)) + break; + + CCtrlSectionDef *pSecDef = (CCtrlSectionDef*)pCtrl; + pSecDef->AddPageBorderFill(CPageBorderFill::Parse(nLevel, nSize, oBuffer, 0, nVersion)); + + break; + } + case HWPTAG_TABLE: + { + int nLen = CCtrlTable::ParseCtrl(*(CCtrlTable*)pCtrl, nSize, oBuffer, 0, nVersion); + break; + } + case HWPTAG_LIST_HEADER: + { + if (nullptr == dynamic_cast(pCtrl)) + { + oBuffer.Skip(nSize); + break; + } + + EVertAlign eVerAlign = CHWPRecordListHeader::GetVertAlign(nSize, oBuffer, 0, nVersion); + + CTblCell* pCell = new CTblCell(nSize - 6, oBuffer, 0, nVersion); + pCell->SetVertAlign(eVerAlign); + + ((CCtrlTable*)pCtrl)->AddCell(pCell); + + break; + } + case HWPTAG_SHAPE_COMPONENT: + { + if(nullptr != dynamic_cast(pCtrl)) + { + oBuffer.Skip(-nHeaderSize); + ParseContainerRecurse(*(CCtrlContainer*)pCtrl, nLevel, oBuffer, 0, nVersion); + } + else if (nullptr != dynamic_cast(pCtrl)) + { + CCtrlGeneralShape *pNewCtrl = CCtrlGeneralShape::Parse(*(CCtrlGeneralShape*)pCtrl, nSize, oBuffer, 0, nVersion); + CHWPPargraph *pParentPara = ((CCtrlGeneralShape*)pCtrl)->GetParent(); + int nCtrlIbdex = pParentPara->IndexOf(pCtrl); + + if (nCtrlIbdex >= 0) + pParentPara->SetCtrl(pNewCtrl, nCtrlIbdex); + else + pParentPara->AddCtrl(pNewCtrl); + + //TODO:: проверить + pCtrl = pNewCtrl; + } + + break; + } + + #define PROCESS_SHAPE_COMPONENT(type_conponent) \ + if (nullptr == dynamic_cast(pCtrl)) \ + { \ + oBuffer.Skip(nSize); \ + break; \ + } \ + type_conponent::ParseElement(*(type_conponent*)pCtrl, nSize, oBuffer, 0, nVersion) + + case HWPTAG_SHAPE_COMPONENT_PICTURE: + { + PROCESS_SHAPE_COMPONENT(CCtrlShapePic); + break; + } + case HWPTAG_SHAPE_COMPONENT_LINE: + { + PROCESS_SHAPE_COMPONENT(CCtrlShapeLine); + break; + } + case HWPTAG_SHAPE_COMPONENT_RECTANGLE: + { + PROCESS_SHAPE_COMPONENT(CCtrlShapeRect); + break; + } + case HWPTAG_SHAPE_COMPONENT_ELLIPSE: + { + PROCESS_SHAPE_COMPONENT(CCtrlShapeEllipse); + break; + } + case HWPTAG_SHAPE_COMPONENT_ARC: + { + PROCESS_SHAPE_COMPONENT(CCtrlShapeArc); + break; + } + case HWPTAG_SHAPE_COMPONENT_POLYGON: + { + PROCESS_SHAPE_COMPONENT(CCtrlShapePolygon); + break; + } + case HWPTAG_SHAPE_COMPONENT_CURVE: + { + PROCESS_SHAPE_COMPONENT(CCtrlShapeCurve); + break; + } + case HWPTAG_SHAPE_COMPONENT_OLE: + { + PROCESS_SHAPE_COMPONENT(CCtrlShapeOle); + break; + } + case HWPTAG_EQEDIT: + { + PROCESS_SHAPE_COMPONENT(CCtrlEqEdit); + break; + } + case HWPTAG_VIDEO_DATA: + { + PROCESS_SHAPE_COMPONENT(CCtrlShapeVideo); + break; + } + case HWPTAG_SHAPE_COMPONENT_TEXTART: + { + PROCESS_SHAPE_COMPONENT(CCtrlShapeTextArt); + break; + } + case HWPTAG_FORM_OBJECT: + { + if (nullptr == dynamic_cast(pCtrl)) + { + oBuffer.Skip(nSize); + break; + } + + CHWPRecordFormObject::ParseCtrl(*(CCtrlForm*)pCtrl, nSize, oBuffer, 0, nVersion); + break; + } + case HWPTAG_CTRL_DATA: + { + CHWPRecordCtrlData::ParseCtrl(*pCtrl, nSize, oBuffer, 0, nVersion); + break; + } + case HWPTAG_SHAPE_COMPONENT_UNKNOWN: + default: + { + oBuffer.Skip(nSize); + break; + } + } + } + } + return 0; } diff --git a/HwpFile/HwpDoc/HWPStream.cpp b/HwpFile/HwpDoc/HWPStream.cpp index c6b4de120e..1b5412131a 100644 --- a/HwpFile/HwpDoc/HWPStream.cpp +++ b/HwpFile/HwpDoc/HWPStream.cpp @@ -5,34 +5,32 @@ namespace HWP { CHWPStream::CHWPStream() - : m_pBegin(nullptr), m_pCur(nullptr), m_pEnd(nullptr), m_bExternalBuffer(true) + : m_pBegin(nullptr), m_pCur(nullptr), m_pEnd(nullptr), m_bExternalBuffer(false) {} -CHWPStream::CHWPStream(unsigned int unSize) - : m_bExternalBuffer(false) +CHWPStream::CHWPStream(unsigned long ulSize) + : m_pBegin(nullptr), m_pCur(nullptr), m_pEnd(nullptr), m_bExternalBuffer(false) { - m_pBegin = new(std::nothrow) BYTE[unSize]; - m_pCur = m_pBegin; - m_pEnd = m_pBegin + unSize; + Expand(ulSize); } -CHWPStream::CHWPStream(BYTE* pBuffer, unsigned int unSize, bool bExternalBuffer) - : m_pBegin(pBuffer), m_pCur(pBuffer), m_pEnd(pBuffer + unSize), m_bExternalBuffer(bExternalBuffer) +CHWPStream::CHWPStream(BYTE* pBuffer, unsigned long ulSize, bool bExternalBuffer) + : m_pBegin(pBuffer), m_pCur(pBuffer), m_pEnd(pBuffer + ulSize), m_bExternalBuffer(bExternalBuffer) {} CHWPStream::~CHWPStream() { if (nullptr != m_pBegin && !m_bExternalBuffer) - delete[] m_pBegin; + free(m_pBegin); m_pBegin = nullptr; } -void CHWPStream::SetStream(BYTE* pBuffer, unsigned int unSize, bool bExternalBuffer) +void CHWPStream::SetStream(BYTE* pBuffer, unsigned long ulSize, bool bExternalBuffer) { m_pBegin = pBuffer; m_pCur = pBuffer; - m_pEnd = pBuffer + unSize; + m_pEnd = pBuffer + ulSize; m_bExternalBuffer = bExternalBuffer; } @@ -42,9 +40,34 @@ BYTE* CHWPStream::GetCurPtr() return m_pCur; } -unsigned int CHWPStream::Tell() const +unsigned long CHWPStream::Tell() const { - return m_pCur - m_pBegin; + return (!IsValid()) ? 0 : m_pCur - m_pBegin; +} + +unsigned long CHWPStream::SizeToEnd() const +{ + return (!IsValid() || IsEof()) ? 0 : m_pEnd - m_pCur; +} + +void CHWPStream::Expand(unsigned long ulSize) +{ + if (nullptr != m_pBegin) + { + unsigned long ulCurrentPos = Tell(); + unsigned long ulNewSize = GetSize() + ulSize; + + m_pBegin = (BYTE*)realloc(m_pBegin, ulNewSize); + m_pEnd = m_pBegin + ulNewSize; + m_pCur = m_pBegin + ulCurrentPos; + } + else + { + m_pBegin = (BYTE*)malloc(ulSize); + m_pBegin[0] = 0x11; + m_pEnd = m_pBegin + ulSize; + m_pCur = m_pBegin; + } } bool CHWPStream::ReadChar(CHAR& chValue) @@ -218,22 +241,34 @@ bool CHWPStream::ReadString(STRING& sValue, int nLength, EStringCharacter eChara return true; } -bool CHWPStream::ReadBytes(char* pBytes, unsigned int unSize) +unsigned long CHWPStream::ReadBytes(BYTE* pBytes, unsigned long unSize) { - if (nullptr == pBytes || !CanRead(unSize)) - return false; + if (!IsValid() || IsEof()) + return 0; - memcpy(pBytes, m_pCur, unSize); - m_pCur += unSize; - return true; + unsigned long ulNewSize = (std::min)(unSize, SizeToEnd()); + + memcpy(pBytes, m_pCur, ulNewSize); + m_pCur += ulNewSize; + return ulNewSize; } -void CHWPStream::Skip(unsigned int unStep) +void CHWPStream::Skip(int nStep) { - if (m_pCur + unStep > m_pEnd) - m_pCur = m_pEnd; - else - m_pCur += unStep; + if (nStep > 0) + { + if (m_pCur + nStep > m_pEnd) + m_pCur = m_pEnd; + else + m_pCur += nStep; + } + else if (nStep < 0) + { + if (m_pCur + nStep > m_pBegin) + m_pCur += nStep; + else + m_pCur = m_pBegin; + } } void CHWPStream::MoveToStart() @@ -272,7 +307,7 @@ bool CHWPStream::IsEof() const unsigned int CHWPStream::GetSize() const { - return (unsigned int)(m_pEnd - m_pCur); + return (unsigned int)(m_pEnd - m_pBegin); } void CHWPStream::SavePosition() @@ -303,4 +338,16 @@ BYTE CHWPStream::operator[](unsigned int unPosition) const return *(m_pCur + unPosition); } + +bool CHWPStream::WriteBytes(const BYTE* pBuffer, unsigned long ulSize) +{ + unsigned long ulSizeToEnd = SizeToEnd(); + + if (ulSize > ulSizeToEnd) + Expand(ulSize - ulSizeToEnd); + + memcpy(m_pCur, pBuffer, ulSize); + m_pCur += ulSize; + return true; +} } diff --git a/HwpFile/HwpDoc/HWPStream.h b/HwpFile/HwpDoc/HWPStream.h index ff54e3f876..e30ee06627 100644 --- a/HwpFile/HwpDoc/HWPStream.h +++ b/HwpFile/HwpDoc/HWPStream.h @@ -24,14 +24,17 @@ class CHWPStream bool m_bExternalBuffer; public: CHWPStream(); - CHWPStream(unsigned int unSize); - CHWPStream(BYTE* pBuffer, unsigned int unSize, bool bExternalBuffer = true); + CHWPStream(unsigned long ulSize); + CHWPStream(BYTE* pBuffer, unsigned long ulSize, bool bExternalBuffer = true); ~CHWPStream(); - void SetStream(BYTE* pBuffer, unsigned int unSize, bool bExternalBuffer = true); + void SetStream(BYTE* pBuffer, unsigned long ulSize, bool bExternalBuffer = true); BYTE* GetCurPtr(); - unsigned int Tell() const; + unsigned long Tell() const; + unsigned long SizeToEnd() const; + + void Expand(unsigned long ulSize); bool ReadChar(CHAR& chValue); bool ReadFloat(float& fValue); @@ -45,9 +48,9 @@ public: BYTE ReadByte(); bool ReadString(STRING& sValue, EStringCharacter eCharacter); bool ReadString(STRING& sValue, int nLength, EStringCharacter eCharacter); - bool ReadBytes(BYTE* pBytes, unsigned int unSize); + unsigned long ReadBytes(BYTE* pBytes, unsigned long unSize); - void Skip(unsigned int unStep); + void Skip(int nStep); void MoveToStart(); void MoveTo(unsigned int unPosition); @@ -61,6 +64,9 @@ public: int GetDistanceToLastPos(bool bRemoveLastPos = false); BYTE operator[](unsigned int unPosition) const; + + + bool WriteBytes(const BYTE* pBuffer, unsigned long ulSize); }; #define CHECK_FLAG(value, flag) ((value) & flag) == flag diff --git a/HwpFile/HwpDoc/OLEdoc/CompoundFile.cpp b/HwpFile/HwpDoc/OLEdoc/CompoundFile.cpp index 5a1b099654..ee8f4116ee 100644 --- a/HwpFile/HwpDoc/OLEdoc/CompoundFile.cpp +++ b/HwpFile/HwpDoc/OLEdoc/CompoundFile.cpp @@ -89,7 +89,7 @@ bool CCompoundFile::Read(const CDirectoryEntry& oEntry, CHWPStream& oBuffer) if (oEntry.GetStreamSize() < m_nMiniStreamCutoffSize) { - if ( m_arDirectoryEntries.empty()) + if (m_arDirectoryEntries.empty()) return false; arStreamContainerSectors = m_arDirectoryEntries.at(0)->GetSecNums(); @@ -509,7 +509,6 @@ void CCompoundFile::ParseDirectorySector(CHWPStream& oBuffer) { oBuffer.MoveTo(64 + nIndex); - //TODO:: проверить данный момент short shEntryNameLen; STRING sDirectiryEnryName; diff --git a/HwpFile/HwpDoc/Paragraph/CharShape.cpp b/HwpFile/HwpDoc/Paragraph/CharShape.cpp index 445ac5c2e0..59a06a10d6 100644 --- a/HwpFile/HwpDoc/Paragraph/CharShape.cpp +++ b/HwpFile/HwpDoc/Paragraph/CharShape.cpp @@ -1,4 +1,6 @@ #include "CharShape.h" +#include "CtrlCharacter.h" +#include "ParaText.h" namespace HWP { @@ -11,17 +13,25 @@ CCharShape::CCharShape(int nStart, int nID) { } -std::list CCharShape::Parse(int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) +int CCharShape::GetStart() const { - BYTE *pOldCurentPos = oBuffer.GetCurPtr(); + return m_nStart; +} - #define CHECK_SIZE (nSize - 8 >= (oBuffer.GetCurPtr() - pOldCurentPos)) +int CCharShape::GetCharShapeID() const +{ + return m_nCharShapeID; +} - std::list arCharShapes; +VECTOR CCharShape::Parse(int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) +{ + oBuffer.SavePosition(); + + VECTOR arCharShapes; int nStart, nCharShapeID; - while (CHECK_SIZE) + while (nSize - 8 >= oBuffer.GetDistanceToLastPos()) { oBuffer.ReadInt(nStart); oBuffer.ReadInt(nCharShapeID); @@ -29,19 +39,74 @@ std::list CCharShape::Parse(int nTagNum, int nLevel, int nSize, CHW arCharShapes.push_back(new CCharShape(nStart, nCharShapeID)); } + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); + return arCharShapes; } -int CCharShape::FillCharShape(int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion, const VECTOR& arParas) +int CCharShape::FillCharShape(int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion, std::vector& arParas) { if (arParas.empty()) return 0; - // std::list arCharShape = Parse(nTagNum, nLevel, nSize, oBuffer, nOff, nVersion); + oBuffer.SavePosition(); - //TODO:: перенести реализацию + VECTOR arCharShape = Parse(nTagNum, nLevel, nSize, oBuffer, nOff, nVersion); - oBuffer.Skip(nSize); + for (CCharShape* pCharShape : arCharShape) + { + if (0 == pCharShape->m_nStart) + { + for (CCtrl* pCtrl : arParas) + { + if (nullptr != dynamic_cast(pCtrl)) + ((CParaText*)pCtrl)->SetCharShapeID(pCharShape->m_nCharShapeID); + + if (nullptr != dynamic_cast(pCtrl)) + ((CCtrlCharacter*)pCtrl)->SetCharShapeID(pCharShape->m_nCharShapeID); + } + } + else if (0 < pCharShape->m_nStart) + { + VECTOR::const_reverse_iterator itFound = std::find_if(arParas.crbegin(), arParas.crend(), + [pCharShape](CCtrl* pCurCtrl) + { if (nullptr == dynamic_cast(pCurCtrl)) return false; + return ((CParaText*)pCurCtrl)->GetStartIDx() <= pCharShape->m_nStart && pCharShape->m_nStart < ((CParaText*)pCurCtrl)->GetStartIDx() + ((CParaText*)pCurCtrl)->GetSize(); }); + + if (itFound != arParas.crend()) + { + CParaText* pParaText = (CParaText*)*itFound; + + if (pParaText->GetStartIDx() == pCharShape->m_nStart) + pParaText->SetCharShapeID(pCharShape->m_nCharShapeID); + else + { + // split + int nLenToSplit = pCharShape->m_nStart - pParaText->GetStartIDx(); + + STRING sSplitLeftText = pParaText->GetText().substr(0, nLenToSplit); + STRING sSplitRightText = pParaText->GetText().substr(nLenToSplit); + + pParaText->SetText(sSplitLeftText); + + CParaText *pNewParaText = new CParaText(L"____", sSplitRightText, pCharShape->m_nStart, pCharShape->m_nCharShapeID); + + arParas.insert(itFound.base() + 1, pNewParaText); + } + } + + for (CCtrl* pCtrl : arParas) + { + if (nullptr != dynamic_cast(pCtrl) && ((CParaText*)pCtrl)->GetStartIDx() > pCharShape->m_nStart) + ((CParaText*)pCtrl)->SetCharShapeID(pCharShape->m_nCharShapeID); + + if (nullptr != dynamic_cast(pCtrl)) + ((CCtrlCharacter*)pCtrl)->SetCharShapeID(pCharShape->m_nCharShapeID); + } + } + } + + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); return nSize; } diff --git a/HwpFile/HwpDoc/Paragraph/CharShape.h b/HwpFile/HwpDoc/Paragraph/CharShape.h index fe3d43acf2..172991f26e 100644 --- a/HwpFile/HwpDoc/Paragraph/CharShape.h +++ b/HwpFile/HwpDoc/Paragraph/CharShape.h @@ -15,8 +15,11 @@ public: CCharShape(); CCharShape(int nStart, int nID); - static LIST Parse(int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - static int FillCharShape(int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion, const VECTOR& arParas); + int GetStart() const; + int GetCharShapeID() const; + + static VECTOR Parse(int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); + static int FillCharShape(int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion, VECTOR& arParas); }; } diff --git a/HwpFile/HwpDoc/Paragraph/Ctrl.cpp b/HwpFile/HwpDoc/Paragraph/Ctrl.cpp index 41f50013d7..b0f0b2cc7e 100644 --- a/HwpFile/HwpDoc/Paragraph/Ctrl.cpp +++ b/HwpFile/HwpDoc/Paragraph/Ctrl.cpp @@ -10,6 +10,9 @@ CCtrl::CCtrl(const STRING& sCtrlID) : m_sCtrlID(sCtrlID), m_bFullFilled(false) {} +CCtrl::~CCtrl() +{} + void CCtrl::SetID(const STRING& sCtrlID) { m_sCtrlID = sCtrlID; @@ -29,4 +32,13 @@ void CCtrl::SetFullFilled() { m_bFullFilled = true; } + +bool CCtrl::Equals(CCtrl* pFirstCtrl, CCtrl* pSecondCtrl) +{ + if (nullptr == pFirstCtrl || nullptr == pSecondCtrl) + return false; + + return pFirstCtrl->m_sCtrlID == pSecondCtrl->m_sCtrlID && + pFirstCtrl->m_bFullFilled == pSecondCtrl->m_bFullFilled; +} } diff --git a/HwpFile/HwpDoc/Paragraph/Ctrl.h b/HwpFile/HwpDoc/Paragraph/Ctrl.h index edfb319dd1..d1a2a517f6 100644 --- a/HwpFile/HwpDoc/Paragraph/Ctrl.h +++ b/HwpFile/HwpDoc/Paragraph/Ctrl.h @@ -13,6 +13,7 @@ protected: public: CCtrl(); CCtrl(const STRING& sCtrlID); + virtual ~CCtrl(); void SetID(const STRING& sCtrlID); STRING GetID() const; @@ -21,6 +22,8 @@ public: void SetFullFilled(); virtual int GetSize() = 0; + + static bool Equals(CCtrl* pFirstCtrl, CCtrl* pSecondCtrl); }; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.cpp b/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.cpp index 37220b5063..1c4060432f 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.cpp @@ -16,6 +16,9 @@ CCtrlAutoNumber::CCtrlAutoNumber(const STRING& sCtrlID, int nSize, CHWPStream& o m_eNumType = GetNumType(nAttr & 0xF); m_eNumShape = GetNumberShape2(nAttr >> 4 & 0xFF); m_bSuperscript = CHECK_FLAG(nAttr >> 12, 0x01); + + m_nSize = 4; + m_bFullFilled = true; } int CCtrlAutoNumber::GetSize() diff --git a/HwpFile/HwpDoc/Paragraph/CtrlCharacter.cpp b/HwpFile/HwpDoc/Paragraph/CtrlCharacter.cpp index ed218d9c73..af935e3480 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlCharacter.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlCharacter.cpp @@ -14,4 +14,9 @@ int CCtrlCharacter::GetSize() { return 1; } + +void CCtrlCharacter::SetCharShapeID(int nCharShapeID) +{ + m_nCharShapeID = nCharShapeID; +} } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlCharacter.h b/HwpFile/HwpDoc/Paragraph/CtrlCharacter.h index 0b45e3ebaf..7f8f702d9b 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlCharacter.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlCharacter.h @@ -22,6 +22,8 @@ public: CCtrlCharacter(const STRING& sCtrlID, ECtrlCharType eCtrlChar, int nCharShapeID); int GetSize() override; + + void SetCharShapeID(int nCharShapeID); }; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlClick.cpp b/HwpFile/HwpDoc/Paragraph/CtrlClick.cpp index d5702347ef..ed45bcb503 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlClick.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlClick.cpp @@ -5,7 +5,7 @@ namespace HWP CCtrlClick::CCtrlClick(const STRING& sCtrlId, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) : CCtrl(sCtrlId) { - BYTE* pOldCurrentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.Skip(4); oBuffer.Skip(1); @@ -15,7 +15,7 @@ CCtrlClick::CCtrlClick(const STRING& sCtrlId, int nSize, CHWPStream& oBuffer, in oBuffer.Skip(4); oBuffer.Skip(4); - m_nSize = oBuffer.GetCurPtr() - pOldCurrentPos; + m_nSize = oBuffer.GetDistanceToLastPos(true); } int CCtrlClick::GetSize() diff --git a/HwpFile/HwpDoc/Paragraph/CtrlColumnDef.cpp b/HwpFile/HwpDoc/Paragraph/CtrlColumnDef.cpp index 81816d4070..ccef4ce5d6 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlColumnDef.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlColumnDef.cpp @@ -9,7 +9,7 @@ CCtrlColumnDef::CCtrlColumnDef(const STRING& sCtrlID) CCtrlColumnDef::CCtrlColumnDef(const STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) : CCtrl(sCtrlID) { - BYTE* pOldCurrentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); short shAttrLowBits; oBuffer.ReadShort(shAttrLowBits); @@ -39,7 +39,7 @@ CCtrlColumnDef::CCtrlColumnDef(const STRING& sCtrlID, int nSize, CHWPStream& oBu m_nAttr = shAttrHighBits << 16 | shAttrLowBits; - m_nSize = oBuffer.GetCurPtr() - pOldCurrentPos; + m_nSize = oBuffer.GetDistanceToLastPos(true); m_bFullFilled = true; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlCommon.cpp b/HwpFile/HwpDoc/Paragraph/CtrlCommon.cpp index ac91f5ffe4..6c7497f0e3 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlCommon.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlCommon.cpp @@ -96,7 +96,7 @@ namespace HWP CCtrlCommon::CCtrlCommon(const STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) : CCtrl(sCtrlID) { - BYTE *pOldCurentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.ReadInt(m_nObjAttr); @@ -126,10 +126,10 @@ namespace HWP oBuffer.ReadInt(m_nObjInstanceID); oBuffer.ReadInt(m_nBlockPageBreak); - if (nSize > (oBuffer.GetCurPtr() - pOldCurentPos)) + if (nSize > oBuffer.GetDistanceToLastPos()) oBuffer.ReadString(m_sObjDesc, EStringCharacter::UTF16); - m_nSize = oBuffer.GetCurPtr() - pOldCurentPos; + m_nSize = oBuffer.GetDistanceToLastPos(true); } void CCtrlCommon::SetTextVerAlign(EVertAlign eVertAlign) @@ -137,11 +137,36 @@ namespace HWP m_eTextVerAlign = eVertAlign; } + void CCtrlCommon::AddParagraph(CHWPPargraph* pParagraph) + { + m_arParas.push_back(pParagraph); + } + + void CCtrlCommon::AddCaption(CCapParagraph* pCapPara) + { + m_arCaption.push_back(pCapPara); + } + int CCtrlCommon::GetSize() { return m_nSize; } + CHWPPargraph* CCtrlCommon::GetLastPara() + { + return (!m_arParas.empty()) ? m_arParas.back() : nullptr; + } + + int CCtrlCommon::GetCaptionWidth() const + { + return m_nCaptionWidth; + } + + bool CCtrlCommon::CaptionsEmpty() const + { + return m_arCaption.empty(); + } + int CCtrlCommon::ParseCtrl(CCtrlCommon& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { STRING sCtrlId; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlCommon.h b/HwpFile/HwpDoc/Paragraph/CtrlCommon.h index f1335e13e5..5cd2c3e0e9 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlCommon.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlCommon.h @@ -120,7 +120,7 @@ class CCtrlCommon : public CCtrl int m_nBlockPageBreak; STRING m_sObjDesc; - // std::list m_arParas; + VECTOR m_arParas; int m_nCaptionAttr; int m_nCaptionWidth; int m_nCaptionSpacing; @@ -140,8 +140,16 @@ public: void SetTextVerAlign(EVertAlign eVertAlign); + void AddParagraph(CHWPPargraph* pParagraph); + void AddCaption(CCapParagraph* pCapPara); + int GetSize() override; + CHWPPargraph* GetLastPara(); + + int GetCaptionWidth() const; + bool CaptionsEmpty() const; + static int ParseCtrl(CCtrlCommon& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); static int ParseCaption(CCtrlCommon& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); }; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlContainer.cpp b/HwpFile/HwpDoc/Paragraph/CtrlContainer.cpp index 169bb4cf17..b13eb661f5 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlContainer.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlContainer.cpp @@ -51,12 +51,12 @@ CCtrlGeneralShape* CCtrlContainer::GetLastShape() int CCtrlContainer::ParseElement(CCtrlContainer& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { - BYTE *pOldCurentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.ReadShort(oObj.m_shNElement); if (oObj.m_shNElement <= 0) - return oBuffer.GetCurPtr() - pOldCurentPos; + return oBuffer.GetDistanceToLastPos(true); oObj.m_arCtrlIdList.reserve(oObj.m_shNElement); @@ -69,7 +69,7 @@ int CCtrlContainer::ParseElement(CCtrlContainer& oObj, int nSize, CHWPStream& oB #define CREATE_OBJECT(class_name) \ { \ - pChldObj = new class_name(sCtrlId, nSize - (oBuffer.GetCurPtr() - pOldCurentPos), oBuffer, 0, nVersion); \ + pChldObj = new class_name(sCtrlId, nSize - oBuffer.GetDistanceToLastPos(), oBuffer, 0, nVersion); \ class_name::ParseCtrl((class_name&)pChldObj, nSize, oBuffer, 0, nVersion); \ pChldObj->SetID(sCtrlId); \ } @@ -102,12 +102,12 @@ int CCtrlContainer::ParseElement(CCtrlContainer& oObj, int nSize, CHWPStream& oB oObj.m_arShapes[unIndex] = pChldObj; } - return oBuffer.GetCurPtr() - pOldCurentPos; + return oBuffer.GetDistanceToLastPos(true); } int CCtrlContainer::ParseCtrl(CCtrlContainer& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { - BYTE *pOldCurentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); CCtrlObjElement::ParseCtrl(oObj, nSize, oBuffer, nOff, nVersion); @@ -120,6 +120,6 @@ int CCtrlContainer::ParseCtrl(CCtrlContainer& oObj, int nSize, CHWPStream& oBuff oBuffer.Skip(4); - return oBuffer.GetCurPtr() - pOldCurentPos; + return oBuffer.GetDistanceToLastPos(true); } } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlEqEdit.cpp b/HwpFile/HwpDoc/Paragraph/CtrlEqEdit.cpp index 8b1fe1a241..766186dafd 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlEqEdit.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlEqEdit.cpp @@ -15,7 +15,7 @@ CCtrlEqEdit::CCtrlEqEdit(const STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int CCtrlEqEdit::ParseElement(CCtrlEqEdit& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { - BYTE* pOldCurentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oObj.m_bFullFilled = true; @@ -26,10 +26,15 @@ int CCtrlEqEdit::ParseElement(CCtrlEqEdit& oObj, int nSize, CHWPStream& oBuffer, oBuffer.ReadInt(oObj.m_nBaseline); oBuffer.ReadString(oObj.m_sVersion, EStringCharacter::UTF16); - if (oBuffer.GetCurPtr() - pOldCurentPos +2 > nSize) - return nSize; + if (oBuffer.GetDistanceToLastPos() + 2 <= nSize) + { + short shLen = oBuffer.ReadShort(); - oBuffer.ReadString(oObj.m_sFont, EStringCharacter::UTF16); + if (oBuffer.GetDistanceToLastPos() + shLen <= nSize) + oBuffer.ReadString(oObj.m_sFont, shLen, EStringCharacter::UTF16); + } + + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); return nSize; } @@ -42,7 +47,10 @@ int CCtrlEqEdit::ParseCtrl(CCtrlEqEdit& oObj, int nSize, CHWPStream& oBuffer, in int CCtrlEqEdit::ParseListHeaderAppend(CCtrlEqEdit& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { if (24 != nSize) + { + oBuffer.Skip(nSize); return nSize; + } oBuffer.Skip(2); oBuffer.ReadInt(oObj.m_nCaptionAttr); diff --git a/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.cpp b/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.cpp index b5f48bba22..86ef27eec1 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.cpp @@ -19,13 +19,13 @@ CCtrlHeadFoot::CCtrlHeadFoot(const STRING& sCtrlID) CCtrlHeadFoot::CCtrlHeadFoot(const STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion, bool bIsHeader) : CCtrl(sCtrlID), m_bIsHeader(bIsHeader) { - BYTE *pOldCurentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.ReadInt(m_nAttr); m_eWhichPage = GetPageRange(m_nAttr & 0x03); oBuffer.ReadInt(m_nSerialInSec); - m_nSize = oBuffer.GetCurPtr() - pOldCurentPos; + m_nSize = oBuffer.GetDistanceToLastPos(true); } int CCtrlHeadFoot::GetSize() @@ -33,18 +33,26 @@ int CCtrlHeadFoot::GetSize() return m_nSize; } +void CCtrlHeadFoot::AddParagraph(CHWPPargraph* pParagraph) +{ + m_arParas.push_back(pParagraph); +} + int CCtrlHeadFoot::ParseListHeaderAppend(CCtrlHeadFoot& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { - BYTE *pOldCurentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.Skip(2); oBuffer.ReadInt(oObj.m_nTextWidth); oBuffer.ReadInt(oObj.m_nTextHeight); oBuffer.ReadByte(oObj.m_chRefLevelText); oBuffer.ReadByte(oObj.m_chRefLevelNum); - oBuffer.Skip(nSize - (oBuffer.GetCurPtr() - pOldCurentPos)); + + if (nSize - oBuffer.GetDistanceToLastPos()) + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos()); + oObj.m_bFullFilled = true; - return oBuffer.GetCurPtr() - pOldCurentPos; + return oBuffer.GetDistanceToLastPos(true); } } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.h b/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.h index 4f0569e43b..27e31d9e12 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.h @@ -33,10 +33,11 @@ class CCtrlHeadFoot : public CCtrl public: CCtrlHeadFoot(const STRING& sCtrlID); CCtrlHeadFoot(const STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion, bool bIsHeader); - ~CCtrlHeadFoot(); int GetSize() override; + void AddParagraph(CHWPPargraph* pParagraph); + static int ParseListHeaderAppend(CCtrlHeadFoot& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); }; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.cpp b/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.cpp index 4846140b85..04f1d71fc3 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.cpp @@ -21,7 +21,7 @@ CCtrlNewNumber::CCtrlNewNumber(const STRING& sCtrlID, int nSize, CHWPStream& oBu m_bFullFilled = true; - m_nSize = oBuffer.GetDistanceToLastPos(); + m_nSize = oBuffer.GetDistanceToLastPos(true); } int CCtrlNewNumber::GetSize() diff --git a/HwpFile/HwpDoc/Paragraph/CtrlNote.cpp b/HwpFile/HwpDoc/Paragraph/CtrlNote.cpp index 914bbfafd1..604a732ecb 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlNote.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlNote.cpp @@ -2,6 +2,9 @@ namespace HWP { +CCtrlNote::CCtrlNote() +{} + CCtrlNote::CCtrlNote(const STRING& sCtrlID) : CCtrl(sCtrlID) {} @@ -18,4 +21,9 @@ int CCtrlNote::GetSize() { return m_nSize; } + +void CCtrlNote::AddParagraph(CHWPPargraph* pParagraph) +{ + m_arParas.push_back(pParagraph); +} } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlNote.h b/HwpFile/HwpDoc/Paragraph/CtrlNote.h index 8d205bd2b7..c335d2ed8a 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlNote.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlNote.h @@ -11,12 +11,15 @@ class CCtrlNote : public CCtrl { int m_nSize; - std::list m_arParas; + VECTOR m_arParas; public: + CCtrlNote(); CCtrlNote(const STRING& sCtrlID); CCtrlNote(const STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); int GetSize() override; + + void AddParagraph(CHWPPargraph* pParagraph); }; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlObjElement.cpp b/HwpFile/HwpDoc/Paragraph/CtrlObjElement.cpp index 9b474549f0..9a6c9946b7 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlObjElement.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlObjElement.cpp @@ -20,7 +20,7 @@ int CCtrlObjElement::GetSize() int CCtrlObjElement::ParseCtrl(CCtrlObjElement& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { - BYTE *pOldCurrentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); CCtrlCommon::ParseCtrl(oObj, nSize, oBuffer, nOff, nVersion); @@ -52,6 +52,6 @@ int CCtrlObjElement::ParseCtrl(CCtrlObjElement& oObj, int nSize, CHWPStream& oBu oBuffer.ReadDouble(oObj.m_arMatrixSeq[nIndex]); } - return oBuffer.GetCurPtr() - pOldCurrentPos; + return oBuffer.GetDistanceToLastPos(true); } } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.cpp b/HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.cpp index 997062c0d6..d42f33f1b3 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.cpp @@ -31,7 +31,7 @@ CCtrlPageNumPos::CCtrlPageNumPos(const STRING& sCtrlID) CCtrlPageNumPos::CCtrlPageNumPos(const STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) : CCtrl(sCtrlID) { - BYTE* pOldCurrentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); int nAttr; oBuffer.ReadInt(nAttr); @@ -44,7 +44,7 @@ CCtrlPageNumPos::CCtrlPageNumPos(const STRING& sCtrlID, int nSize, CHWPStream& o oBuffer.ReadString(m_sPostfix, 2, EStringCharacter::UTF16); oBuffer.ReadString(m_sConstantDash, 2, EStringCharacter::UTF16); - m_nSize = oBuffer.GetCurPtr() - pOldCurrentPos; + m_nSize = oBuffer.GetDistanceToLastPos(true); } int CCtrlPageNumPos::GetSize() diff --git a/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.cpp b/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.cpp index f26806e13f..6f0b80a0e7 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.cpp @@ -3,11 +3,11 @@ namespace HWP { CCtrlSectionDef::CCtrlSectionDef(const STRING& sCtrlID) - : CCtrl(sCtrlID) + : CCtrl(sCtrlID), m_pPage(nullptr) {} CCtrlSectionDef::CCtrlSectionDef(const STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) - : CCtrl(sCtrlID) + : CCtrl(sCtrlID), m_pPage(nullptr) { oBuffer.SavePosition(); @@ -40,7 +40,18 @@ CCtrlSectionDef::CCtrlSectionDef(const STRING& sCtrlID, int nSize, CHWPStream& o oBuffer.ReadShort(m_shLang); m_bFullFilled = true; - m_nSize = oBuffer.GetDistanceToLastPos(); + m_nSize = oBuffer.GetDistanceToLastPos(true); +} + +CCtrlSectionDef::~CCtrlSectionDef() +{ + if (nullptr != m_pPage) + delete m_pPage; +} + +void CCtrlSectionDef::SetPage(CPage* pPage) +{ + m_pPage = pPage; } void CCtrlSectionDef::AddHeadFoot(CCtrlHeadFoot* pHeadFoot) @@ -48,6 +59,21 @@ void CCtrlSectionDef::AddHeadFoot(CCtrlHeadFoot* pHeadFoot) m_arHeaderFooter.push_back(pHeadFoot); } +void CCtrlSectionDef::AddParagraph(CHWPPargraph* pParagraph) +{ + m_arParas.push_back(pParagraph); +} + +void CCtrlSectionDef::AddNoteShape(CNoteShape* pNoteShape) +{ + m_arNoteShapes.push_back(pNoteShape); +} + +void CCtrlSectionDef::AddPageBorderFill(CPageBorderFill* pPageBorderFill) +{ + m_arBorderFills.push_back(pPageBorderFill); +} + int CCtrlSectionDef::GetSize() { return m_nSize; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.h b/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.h index b999c99b73..01f399c2f3 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.h @@ -37,18 +37,24 @@ class CCtrlSectionDef : public CCtrl short m_shEquation; short m_shLang; - // CPage m_oPage; - LIST m_arHeaderFooter; - // LIST m_arNoteShapes; - // LIST m_arBorderFills; + CPage *m_pPage; + VECTOR m_arHeaderFooter; + VECTOR m_arNoteShapes; + VECTOR m_arBorderFills; - // LIST m_arParas; + VECTOR m_arParas; public: CCtrlSectionDef(const STRING& sCtrlID); CCtrlSectionDef(const STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); + ~CCtrlSectionDef(); + + void SetPage(CPage* pPage); void AddHeadFoot(CCtrlHeadFoot* pHeadFoot); + void AddParagraph(CHWPPargraph* pParagraph); + void AddNoteShape(CNoteShape* pNoteShape); + void AddPageBorderFill(CPageBorderFill* pPageBorderFill); int GetSize() override; }; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeArc.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeArc.cpp index 0374120b2e..7aefb58119 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeArc.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeArc.cpp @@ -15,6 +15,8 @@ CCtrlShapeArc::CCtrlShapeArc(const STRING& sCtrlID, int nSize, CHWPStream& oBuff int CCtrlShapeArc::ParseElement(CCtrlShapeArc& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { + oBuffer.SavePosition(); + oObj.m_eType = GetArcType(oBuffer.ReadByte()); oBuffer.ReadInt(oObj.m_nCenterX); oBuffer.ReadInt(oObj.m_nCenterY); @@ -23,6 +25,8 @@ int CCtrlShapeArc::ParseElement(CCtrlShapeArc& oObj, int nSize, CHWPStream& oBuf oBuffer.ReadInt(oObj.m_nAxixX2); oBuffer.ReadInt(oObj.m_nAxixY2); + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); + return nSize; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.cpp index b1030e7b2a..b5f044b0a0 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.cpp @@ -15,6 +15,8 @@ CCtrlShapeCurve::CCtrlShapeCurve(const STRING& sCtrlID, int nSize, CHWPStream& o int CCtrlShapeCurve::ParseElement(CCtrlShapeCurve& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { + oBuffer.SavePosition(); + oBuffer.ReadInt(oObj.m_nPoints); if (0 < oObj.m_nPoints) @@ -36,6 +38,8 @@ int CCtrlShapeCurve::ParseElement(CCtrlShapeCurve& oObj, int nSize, CHWPStream& oBuffer.Skip(4); + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); + return nSize; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.cpp index c6e558ccbc..86b1000ac1 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.cpp @@ -15,6 +15,8 @@ CCtrlShapeEllipse::CCtrlShapeEllipse(const STRING& sCtrlID, int nSize, CHWPStrea int CCtrlShapeEllipse::ParseElement(CCtrlShapeEllipse& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { + oBuffer.SavePosition(); + int nAttr; oBuffer.ReadInt(nAttr); @@ -37,19 +39,21 @@ int CCtrlShapeEllipse::ParseElement(CCtrlShapeEllipse& oObj, int nSize, CHWPStre oBuffer.ReadInt(oObj.m_nEndX2); oBuffer.ReadInt(oObj.m_nEndY2); + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); + return nSize; } int CCtrlShapeEllipse::ParseCtrl(CCtrlShapeEllipse& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { + oBuffer.SavePosition(); CCtrlGeneralShape::ParseCtrl(oObj, nSize, oBuffer, nOff, nVersion); - - return oObj.GetSize(); + return oBuffer.GetDistanceToLastPos(true); } int CCtrlShapeEllipse::ParseListHeaderAppend(CCtrlShapeEllipse& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { - BYTE* pOldCurrentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.Skip(2); @@ -60,16 +64,16 @@ int CCtrlShapeEllipse::ParseListHeaderAppend(CCtrlShapeEllipse& oObj, int nSize, oBuffer.ReadInt(oObj.m_nMaxTxtWidth); - if (nSize > oBuffer.GetCurPtr() - pOldCurrentPos) + if (nSize > oBuffer.GetDistanceToLastPos()) { oBuffer.Skip(10); STRING sFieldName; oBuffer.ReadString(sFieldName, EStringCharacter::UTF16); - oBuffer.Skip(nSize - (oBuffer.GetCurPtr() - pOldCurrentPos)); + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos()); } - return oBuffer.GetCurPtr() - pOldCurrentPos; + return oBuffer.GetDistanceToLastPos(true); } } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeLine.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeLine.cpp index 7f874dbe26..4b2f0f3f62 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeLine.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeLine.cpp @@ -15,7 +15,7 @@ CCtrlShapeLine::CCtrlShapeLine(const STRING& sCtrlID, int nSize, CHWPStream& oBu int CCtrlShapeLine::ParseElement(CCtrlShapeLine& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { - BYTE* pOldCurrentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); if (L"loc$" == oObj.GetID()) oBuffer.Skip(4); @@ -25,12 +25,16 @@ int CCtrlShapeLine::ParseElement(CCtrlShapeLine& oObj, int nSize, CHWPStream& oB oBuffer.ReadInt(oObj.m_nEndX); oBuffer.ReadInt(oObj.m_nEndY); - if (nSize == oBuffer.GetCurPtr() - pOldCurrentPos) + if (nSize == oBuffer.GetDistanceToLastPos()) + { + oBuffer.RemoveLastSavedPos(); return nSize; + } oBuffer.ReadShort(oObj.m_shAttr); oBuffer.Skip(2); + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); return nSize; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeOle.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeOle.cpp index cc76d4477e..56566f9a1b 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeOle.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeOle.cpp @@ -15,6 +15,8 @@ CCtrlShapeOle::CCtrlShapeOle(const STRING& sCtrlID, int nSize, CHWPStream& oBuff int CCtrlShapeOle::ParseElement(CCtrlShapeOle& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { + oBuffer.SavePosition(); + oBuffer.ReadInt(oObj.m_nAttr); oBuffer.ReadInt(oObj.m_nExtentX); oBuffer.ReadInt(oObj.m_nExtentY); @@ -23,7 +25,7 @@ int CCtrlShapeOle::ParseElement(CCtrlShapeOle& oObj, int nSize, CHWPStream& oBuf oBuffer.ReadInt(oObj.m_nBorderThick); oBuffer.ReadInt(oObj.m_nBorderAttr); - return nSize; + return oBuffer.GetDistanceToLastPos(true); } int CCtrlShapeOle::ParseCtrl(CCtrlShapeOle& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapePic.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapePic.cpp index f747ec9dd4..795999cbff 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapePic.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapePic.cpp @@ -21,6 +21,7 @@ CPicColor::CPicColor(CHWPStream& oBuffer, int nOff, int nSize) oBuffer.ReadInt(m_nType); oBuffer.ReadInt(m_nRGB); + oBuffer.Skip(nSize - 8); m_nSize = nSize; } @@ -41,7 +42,7 @@ int CPicEffect::GetSize() CShadow::CShadow(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize) : CPicEffect(nTypeNum), m_pColor(nullptr) { - BYTE* pOldCurrentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.ReadInt(m_nStyle); oBuffer.ReadInt(m_nTransparency); @@ -53,9 +54,9 @@ CShadow::CShadow(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize) oBuffer.ReadFloat(m_fMagnifyX); oBuffer.ReadFloat(m_fMagnifyY); oBuffer.ReadInt(m_nRotation); - m_pColor = new CPicColor(oBuffer, nOff, nSize - (oBuffer.GetCurPtr() - pOldCurrentPos)); + m_pColor = new CPicColor(oBuffer, nOff, nSize - oBuffer.GetDistanceToLastPos()); - m_nSize = oBuffer.GetCurPtr() - pOldCurrentPos; + m_nSize = oBuffer.GetDistanceToLastPos(true); } CShadow::~CShadow() @@ -67,13 +68,13 @@ CShadow::~CShadow() CNeon::CNeon(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize) : CPicEffect(nTypeNum), m_pColor(nullptr) { - BYTE* pOldCurrentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.ReadFloat(m_fTransparency); oBuffer.ReadFloat(m_fRadius); - m_pColor = new CPicColor(oBuffer, nOff, nSize - (oBuffer.GetCurPtr() - pOldCurrentPos)); + m_pColor = new CPicColor(oBuffer, nOff, nSize - oBuffer.GetDistanceToLastPos()); - m_nSize = oBuffer.GetCurPtr() - pOldCurrentPos; + m_nSize = oBuffer.GetDistanceToLastPos(true); } CNeon::~CNeon() @@ -93,7 +94,7 @@ CSoftEdge::CSoftEdge(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize) CReflect::CReflect(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize) : CPicEffect(nTypeNum) { - BYTE* pOldCurrentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.ReadInt(m_nStyle); oBuffer.ReadFloat(m_fRadius); @@ -110,7 +111,7 @@ CReflect::CReflect(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize) oBuffer.ReadFloat(m_fEndPos); oBuffer.ReadFloat(m_fOffsetDirection); - m_nSize = oBuffer.GetCurPtr() - pOldCurrentPos; + m_nSize = oBuffer.GetDistanceToLastPos(true); } CCtrlShapePic::CCtrlShapePic() @@ -136,7 +137,7 @@ CCtrlShapePic::~CCtrlShapePic() int CCtrlShapePic::ParseElement(CCtrlShapePic& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { - BYTE* pOldCurentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.ReadColor(oObj.m_nBorderColor); oBuffer.ReadInt(oObj.m_nBorderThick); @@ -166,7 +167,12 @@ int CCtrlShapePic::ParseElement(CCtrlShapePic& oObj, int nSize, CHWPStream& oBuf oBuffer.ReadByte(oObj.m_chBorderAlpha); - #define CAN_READ() if ((oBuffer.GetCurPtr() - pOldCurentPos) >= nSize) return nSize + #define CAN_READ() \ + if (oBuffer.GetDistanceToLastPos() >= nSize) \ + { \ + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); \ + return nSize; \ + } CAN_READ(); @@ -184,7 +190,7 @@ int CCtrlShapePic::ParseElement(CCtrlShapePic& oObj, int nSize, CHWPStream& oBuf oObj.m_arPicEffect.push_back(pEffect); \ } - if (oObj.m_nPicEffectInfo && (oBuffer.GetCurPtr() - pOldCurentPos) < nSize) + if (oObj.m_nPicEffectInfo && oBuffer.GetDistanceToLastPos() < nSize) { ADD_EFFECT(0x1, CShadow, 56) ADD_EFFECT(0x2, CNeon, 28) @@ -197,9 +203,11 @@ int CCtrlShapePic::ParseElement(CCtrlShapePic& oObj, int nSize, CHWPStream& oBuf oBuffer.ReadInt(oObj.m_nIniPicWidth); oBuffer.ReadInt(oObj.m_nIniPicHeight); - if (nSize - (oBuffer.GetCurPtr() - pOldCurentPos) >= 1) + if (nSize - oBuffer.GetDistanceToLastPos() >= 1) oBuffer.ReadByte(oObj.m_chPicAlpha); + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); + return nSize; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.cpp index 456c9fabee..710fa607dd 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.cpp @@ -15,7 +15,7 @@ CCtrlShapePolygon::CCtrlShapePolygon(const STRING& sCtrlID, int nSize, CHWPStrea int CCtrlShapePolygon::ParseElement(CCtrlShapePolygon& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { - BYTE* pOldCurentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.ReadInt(oObj.m_nPoints); @@ -30,9 +30,11 @@ int CCtrlShapePolygon::ParseElement(CCtrlShapePolygon& oObj, int nSize, CHWPStre } } - if (4 == (nSize - (oBuffer.GetCurPtr() - pOldCurentPos))) + if (4 == (nSize - oBuffer.GetDistanceToLastPos())) oBuffer.Skip(4); + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); + return nSize; } @@ -43,7 +45,7 @@ int CCtrlShapePolygon::ParseCtrl(CCtrlShapePolygon& oObj, int nSize, CHWPStream& int CCtrlShapePolygon::ParseListHeaderAppend(CCtrlShapePolygon& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { - BYTE* pOldCurentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.Skip(2); @@ -55,16 +57,16 @@ int CCtrlShapePolygon::ParseListHeaderAppend(CCtrlShapePolygon& oObj, int nSize, oBuffer.Skip(13); - if (nSize > (oBuffer.GetCurPtr() - pOldCurentPos)) + if (nSize > oBuffer.GetDistanceToLastPos()) { oBuffer.Skip(10); STRING sFieldName; oBuffer.ReadString(sFieldName, EStringCharacter::UTF16); - oBuffer.Skip(nSize - (oBuffer.GetCurPtr() - pOldCurentPos)); + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos()); } - return oBuffer.GetCurPtr() - pOldCurentPos; + return oBuffer.GetDistanceToLastPos(true); } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeRect.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeRect.cpp index 16c6eb9237..118222284c 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeRect.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeRect.cpp @@ -15,6 +15,8 @@ CCtrlShapeRect::CCtrlShapeRect(const STRING& sCtrlID, int nSize, CHWPStream& oBu int CCtrlShapeRect::ParseElement(CCtrlShapeRect& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { + oBuffer.SavePosition(); + oBuffer.ReadByte(oObj.m_chCurv); for (unsigned int unIndex = 0; unIndex < 4; ++unIndex) @@ -23,6 +25,7 @@ int CCtrlShapeRect::ParseElement(CCtrlShapeRect& oObj, int nSize, CHWPStream& oB oBuffer.ReadInt(oObj.m_arPoints[unIndex].m_nY); } + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); return nSize; } @@ -33,7 +36,7 @@ int CCtrlShapeRect::ParseCtrl(CCtrlShapeRect& oObj, int nSize, CHWPStream& oBuff int CCtrlShapeRect::ParseListHeaderAppend(CCtrlShapeRect& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { - BYTE* pOldCurentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.Skip(2); @@ -48,16 +51,16 @@ int CCtrlShapeRect::ParseListHeaderAppend(CCtrlShapeRect& oObj, int nSize, CHWPS oBuffer.Skip(13); - if (nSize > (oBuffer.GetCurPtr() - pOldCurentPos)) + if (nSize > oBuffer.GetDistanceToLastPos()) { oBuffer.Skip(10); STRING sFieldName; oBuffer.ReadString(sFieldName, EStringCharacter::UTF16); - oBuffer.Skip(nSize - (oBuffer.GetCurPtr() - pOldCurentPos)); + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos()); } - return oBuffer.GetCurPtr() - pOldCurentPos; + return oBuffer.GetDistanceToLastPos(true); } } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.cpp index 715cece684..f0211431fc 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.cpp @@ -20,6 +20,7 @@ int CCtrlShapeTextArt::ParseElement(CCtrlShapeTextArt& oObj, int nSize, CHWPStre // [HWP ambiguous] following 120bytes are unknown. // Document doesn't mention about this at all. + oBuffer.Skip(nSize); return nSize; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.cpp index 21d566a2e2..17d4d0eaf7 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.cpp @@ -12,6 +12,8 @@ CCtrlShapeVideo::CCtrlShapeVideo(const STRING& sCtrlID, int nSize, CHWPStream& o int CCtrlShapeVideo::ParseElement(CCtrlShapeVideo& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { + oBuffer.SavePosition(); + oBuffer.ReadInt(oObj.m_nVideoType); if (0 == oObj.m_nVideoType) @@ -23,6 +25,7 @@ int CCtrlShapeVideo::ParseElement(CCtrlShapeVideo& oObj, int nSize, CHWPStream& oBuffer.ReadShort(m_sBinID); oObj.m_sThumnailBinID = std::to_wstring(m_sBinID - 1); + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); return nSize; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlTable.cpp b/HwpFile/HwpDoc/Paragraph/CtrlTable.cpp index 416b1540f8..e34b411297 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlTable.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlTable.cpp @@ -25,9 +25,24 @@ CCtrlTable::~CCtrlTable() } } +void CCtrlTable::AddCell(CTblCell* pCell) +{ + m_arCells.push_back(pCell); +} + +bool CCtrlTable::HaveCells() +{ + return !m_arCells.empty(); +} + +CTblCell* CCtrlTable::GetLastCell() +{ + return (!m_arCells.empty()) ? m_arCells.back() : nullptr; +} + int CCtrlTable::ParseCtrl(CCtrlTable& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { - BYTE *pOldCurentPos = oBuffer.GetCurPtr(); + oBuffer.SavePosition(); oBuffer.ReadInt(oObj.m_nAttr); oBuffer.ReadShort(oObj.m_shNRows); @@ -44,11 +59,11 @@ int CCtrlTable::ParseCtrl(CCtrlTable& oObj, int nSize, CHWPStream& oBuffer, int oBuffer.ReadShort(oObj.m_shBorderFillID); - if (nVersion >= 5010 && ((oBuffer.GetCurPtr() - pOldCurentPos) < nSize)) + if (nVersion >= 5010 && (oBuffer.GetDistanceToLastPos() < nSize)) { oBuffer.ReadShort(oObj.m_shValidZoneSize); - if (0 < oObj.m_shValidZoneSize && ((oBuffer.GetCurPtr() - pOldCurentPos) < nSize)) + if (0 < oObj.m_shValidZoneSize && (oBuffer.GetDistanceToLastPos() < nSize)) { for (unsigned int unIndex = 0; unIndex < oObj.m_shValidZoneSize; ++unIndex) { @@ -68,13 +83,17 @@ int CCtrlTable::ParseCtrl(CCtrlTable& oObj, int nSize, CHWPStream& oBuffer, int } } + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); return nSize; } int CCtrlTable::ParseListHeaderAppend(CCtrlTable& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) { if (24 != nSize) + { + oBuffer.Skip(nSize); return nSize; + } oBuffer.Skip(2); oBuffer.ReadInt(oObj.m_nCaptionAttr); diff --git a/HwpFile/HwpDoc/Paragraph/CtrlTable.h b/HwpFile/HwpDoc/Paragraph/CtrlTable.h index 2b4e6dc240..61ccd99770 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlTable.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlTable.h @@ -34,6 +34,12 @@ public: CCtrlTable(const STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); ~CCtrlTable(); + void AddCell(CTblCell* pCell); + + bool HaveCells(); + + CTblCell* GetLastCell(); + static int ParseCtrl(CCtrlTable& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); static int ParseListHeaderAppend(CCtrlTable& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); }; diff --git a/HwpFile/HwpDoc/Paragraph/HWPPargraph.cpp b/HwpFile/HwpDoc/Paragraph/HWPPargraph.cpp index ccf9cf1f4d..ec3a4249e4 100644 --- a/HwpFile/HwpDoc/Paragraph/HWPPargraph.cpp +++ b/HwpFile/HwpDoc/Paragraph/HWPPargraph.cpp @@ -48,7 +48,7 @@ void CHWPPargraph::SetCtrl(CCtrl* pCtrl, unsigned int unIndex) m_arP[unIndex] = pCtrl; } -VECTOR CHWPPargraph::GetCtrls() +VECTOR& CHWPPargraph::GetCtrls() { return m_arP; } @@ -105,6 +105,7 @@ int CHWPPargraph::Parse(CHWPPargraph& oPara, int nSize, CHWPStream& oBuffer, int oBuffer.ReadShort(shCangeTrackingMerge); } + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); return nSize; } @@ -132,4 +133,17 @@ CCtrl* CHWPPargraph::FindLastElement(const STRING& sID) return nullptr; } +int CHWPPargraph::IndexOf(CCtrl* pCtrl) +{ + if (nullptr == pCtrl || m_arP.empty()) + return -1; + + VECTOR::const_iterator itFound = std::find_if(m_arP.cbegin(), m_arP.cend(), [pCtrl](CCtrl *pCurrCtrl){ return CCtrl::Equals(pCurrCtrl, pCtrl); }); + + if (itFound != m_arP.cend()) + return itFound - m_arP.cbegin(); + + return -1; +} + } diff --git a/HwpFile/HwpDoc/Paragraph/HWPPargraph.h b/HwpFile/HwpDoc/Paragraph/HWPPargraph.h index fbc9934bf8..7356d6ad70 100644 --- a/HwpFile/HwpDoc/Paragraph/HWPPargraph.h +++ b/HwpFile/HwpDoc/Paragraph/HWPPargraph.h @@ -30,7 +30,7 @@ public: void SetCtrl(CCtrl* pCtrl, unsigned int unIndex); - VECTOR GetCtrls(); + VECTOR& GetCtrls(); unsigned int GetCountCtrls() const; @@ -39,6 +39,8 @@ public: CCtrl* FindFirstElement(const STRING& sID, bool bFullfilled, unsigned int& nIndex) const; CCtrl* FindLastElement(const STRING& sID); + + int IndexOf(CCtrl* pCtrl); }; } diff --git a/HwpFile/HwpDoc/Paragraph/ParaText.cpp b/HwpFile/HwpDoc/Paragraph/ParaText.cpp index fcf5084c87..1bab10c848 100644 --- a/HwpFile/HwpDoc/Paragraph/ParaText.cpp +++ b/HwpFile/HwpDoc/Paragraph/ParaText.cpp @@ -6,8 +6,32 @@ CParaText::CParaText(const STRING& sCtrlID, const STRING& sText, int nStartIDx) : CCtrl(sCtrlID), m_sText(sText), m_nStartIDx(nStartIDx) {} +CParaText::CParaText(const STRING& sCtrlID, const STRING& sText, int nStartIDx, int nCharShapeID) + : CCtrl(sCtrlID), m_sText(sText), m_nStartIDx(nStartIDx), m_nCharShapeID(nCharShapeID) +{} + int CParaText::GetSize() { return m_sText.length(); } + +int CParaText::GetStartIDx() const +{ + return m_nStartIDx; +} + +STRING CParaText::GetText() const +{ + return m_sText; +} + +void CParaText::SetCharShapeID(int nCharShapeID) +{ + m_nCharShapeID = nCharShapeID; +} + +void CParaText::SetText(const STRING& sText) +{ + m_sText = sText; +} } diff --git a/HwpFile/HwpDoc/Paragraph/ParaText.h b/HwpFile/HwpDoc/Paragraph/ParaText.h index 7993797be1..a55a6677b9 100644 --- a/HwpFile/HwpDoc/Paragraph/ParaText.h +++ b/HwpFile/HwpDoc/Paragraph/ParaText.h @@ -9,11 +9,17 @@ class CParaText : public CCtrl { STRING m_sText; int m_nStartIDx; - // int m_nCharShapeID; + int m_nCharShapeID; public: CParaText(const STRING& sCtrlID, const STRING& sText, int nStartIDx); + CParaText(const STRING& sCtrlID, const STRING& sText, int nStartIDx, int nCharShapeID); int GetSize() override; + int GetStartIDx() const; + STRING GetText() const; + + void SetCharShapeID(int nCharShapeID); + void SetText(const STRING& sText); }; } diff --git a/HwpFile/HwpDoc/Paragraph/TblCell.cpp b/HwpFile/HwpDoc/Paragraph/TblCell.cpp index decb61599e..4d59d9469a 100644 --- a/HwpFile/HwpDoc/Paragraph/TblCell.cpp +++ b/HwpFile/HwpDoc/Paragraph/TblCell.cpp @@ -5,6 +5,8 @@ namespace HWP CTblCell::CTblCell(int nSize, CHWPStream& oBuffer, int nOff, int nVersion) : m_nSize(nSize) { + oBuffer.SavePosition(); + oBuffer.Skip(2); oBuffer.ReadShort(m_shColAddr); @@ -18,6 +20,18 @@ CTblCell::CTblCell(int nSize, CHWPStream& oBuffer, int nOff, int nVersion) m_arMargin[unIndex] = oBuffer.ReadShort(); oBuffer.ReadShort(m_shBorderFill); + + oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); +} + +void CTblCell::SetVertAlign(EVertAlign eVertAlign) +{ + m_eVertAlign = eVertAlign; +} + +void CTblCell::AddParagraph(CCellParagraph* pParagraph) +{ + m_arParas.push_back(pParagraph); } int CTblCell::GetSize() diff --git a/HwpFile/HwpDoc/Paragraph/TblCell.h b/HwpFile/HwpDoc/Paragraph/TblCell.h index 6521c18645..3216c28f94 100644 --- a/HwpFile/HwpDoc/Paragraph/TblCell.h +++ b/HwpFile/HwpDoc/Paragraph/TblCell.h @@ -26,6 +26,10 @@ class CTblCell public: CTblCell(int nSize, CHWPStream& oBuffer, int nOff, int nVersion); + void SetVertAlign(EVertAlign eVertAlign); + + void AddParagraph(CCellParagraph* pParagraph); + int GetSize(); }; }