diff --git a/HwpFile/HWPFile.pro b/HwpFile/HWPFile.pro index 02c33c778f..acf94e85a8 100644 --- a/HwpFile/HWPFile.pro +++ b/HwpFile/HWPFile.pro @@ -44,6 +44,8 @@ SOURCES += \ HwpDoc/Paragraph/CtrlForm.cpp \ HwpDoc/Paragraph/CtrlGeneralShape.cpp \ HwpDoc/Paragraph/CtrlHeadFoot.cpp \ + HwpDoc/Paragraph/CtrlNewNumber.cpp \ + HwpDoc/Paragraph/CtrlNote.cpp \ HwpDoc/Paragraph/CtrlObjElement.cpp \ HwpDoc/Paragraph/CtrlPageNumPos.cpp \ HwpDoc/Paragraph/CtrlShapeArc.cpp \ @@ -60,9 +62,13 @@ SOURCES += \ HwpDoc/Paragraph/CtrlTalbe.cpp \ HwpDoc/Paragraph/HWPPargraph.cpp \ HwpDoc/Paragraph/LineSeg.cpp \ - HwpDoc/Paragraph/TblCell.cpp + HwpDoc/Paragraph/TblCell.cpp \ + HwpDoc/Section/NoteShape.cpp \ + HwpDoc/Section/Page.cpp \ + HwpDoc/Section/PageBorderFill.cpp HEADERS += \ + HwpDoc/Common.h \ HwpDoc/Errors.h \ HwpDoc/HWPDocInfo.h \ HwpDoc/HWPElements/HWPRecord.h \ @@ -97,6 +103,8 @@ HEADERS += \ HwpDoc/Paragraph/CtrlForm.h \ HwpDoc/Paragraph/CtrlGeneralShape.h \ HwpDoc/Paragraph/CtrlHeadFoot.h \ + HwpDoc/Paragraph/CtrlNewNumber.h \ + HwpDoc/Paragraph/CtrlNote.h \ HwpDoc/Paragraph/CtrlObjElement.h \ HwpDoc/Paragraph/CtrlPageNumPos.h \ HwpDoc/Paragraph/CtrlShapeArc.h \ @@ -115,5 +123,8 @@ HEADERS += \ HwpDoc/Paragraph/LineSeg.h \ HwpDoc/Paragraph/Point.h \ HwpDoc/Paragraph/RangeTag.h \ - HwpDoc/Paragraph/TblCell.h + HwpDoc/Paragraph/TblCell.h \ + HwpDoc/Section/NoteShape.h \ + HwpDoc/Section/Page.h \ + HwpDoc/Section/PageBorderFill.h diff --git a/HwpFile/HwpDoc/Common.h b/HwpFile/HwpDoc/Common.h new file mode 100644 index 0000000000..55e91bb8a3 --- /dev/null +++ b/HwpFile/HwpDoc/Common.h @@ -0,0 +1,8 @@ +#ifndef COMMON_H +#define COMMON_H + +#define CHAR char16_t +#define STRING std::string +#define BYTE char + +#endif // COMMON_H diff --git a/HwpFile/HwpDoc/HWPFile.h b/HwpFile/HwpDoc/HWPFile.h index 28297b3d00..eac92b8000 100644 --- a/HwpFile/HwpDoc/HWPFile.h +++ b/HwpFile/HwpDoc/HWPFile.h @@ -2,6 +2,7 @@ #define HWPFILE_H #include "HwpFileHeader.h" +#include namespace HWP { diff --git a/HwpFile/HwpDoc/HWPStream.cpp b/HwpFile/HwpDoc/HWPStream.cpp index b143682d09..8e2e01f584 100644 --- a/HwpFile/HwpDoc/HWPStream.cpp +++ b/HwpFile/HwpDoc/HWPStream.cpp @@ -3,13 +3,13 @@ namespace HWP { CHWPStream::CHWPStream() - : m_pBegin(nullptr), m_pCur(nullptr), m_pEnd(nullptr) + : m_pBegin(nullptr), m_pCur(nullptr), m_pEnd(nullptr), m_pSavedPosition(nullptr) { } CHWPStream::CHWPStream(BYTE* pBuffer, unsigned int unSize) - : m_pBegin(pBuffer), m_pCur(pBuffer), m_pEnd(pBuffer + unSize) + : m_pBegin(pBuffer), m_pCur(pBuffer), m_pEnd(pBuffer + unSize), m_pSavedPosition(nullptr) {} void CHWPStream::SetStream(BYTE* pBuffer, unsigned int unSize) @@ -24,6 +24,13 @@ BYTE* CHWPStream::GetCurPtr() return m_pCur; } +bool CHWPStream::ReadChar(CHAR& chValue) +{ + //TODO:: реализовать + Skip(2); + return true; +} + bool CHWPStream::ReadFloat(float& fValue) { //TODO:: реализовать @@ -172,6 +179,16 @@ unsigned int CHWPStream::GetLength() const return (unsigned int)(m_pEnd - m_pCur); } +void CHWPStream::SavePosition() +{ + m_pSavedPosition = m_pCur; +} + +int CHWPStream::GetDistanceToLastPos() +{ + return (nullptr != m_pSavedPosition) ? m_pCur - m_pSavedPosition : 0; +} + BYTE CHWPStream::operator[](unsigned int unPosition) const { if (m_pCur >= m_pEnd) diff --git a/HwpFile/HwpDoc/HWPStream.h b/HwpFile/HwpDoc/HWPStream.h index 0207d5ea19..509b2a1927 100644 --- a/HwpFile/HwpDoc/HWPStream.h +++ b/HwpFile/HwpDoc/HWPStream.h @@ -2,16 +2,16 @@ #define HWPSTREAM_H #include +#include "Common.h" namespace HWP { -typedef char BYTE; - class CHWPStream { BYTE* m_pBegin; BYTE* m_pCur; BYTE* m_pEnd; + BYTE* m_pSavedPosition; public: CHWPStream(); CHWPStream(BYTE* pBuffer, unsigned int unSize); @@ -20,6 +20,7 @@ public: BYTE* GetCurPtr(); + bool ReadChar(CHAR& chValue); bool ReadFloat(float& fValue); bool ReadDouble(double& dValue); bool ReadInt(int& nValue); @@ -28,8 +29,8 @@ public: short ReadShort(); bool ReadByte(BYTE& chValue); BYTE ReadByte(); - bool ReadString(std::string& sValue); - bool ReadString(std::string& sValue, int nLength); + bool ReadString(STRING& sValue); + bool ReadString(STRING& sValue, int nLength); void Skip(unsigned int unStep); @@ -38,6 +39,9 @@ public: bool IsEof() const; unsigned int GetLength() const; + void SavePosition(); + int GetDistanceToLastPos(); + BYTE operator[](unsigned int unPosition) const; }; diff --git a/HwpFile/HwpDoc/Paragraph/Ctrl.h b/HwpFile/HwpDoc/Paragraph/Ctrl.h index b674ba72d6..7c0d9a7913 100644 --- a/HwpFile/HwpDoc/Paragraph/Ctrl.h +++ b/HwpFile/HwpDoc/Paragraph/Ctrl.h @@ -8,11 +8,8 @@ namespace HWP class CCtrl { std::string m_sCtrlID; +protected: bool m_bFullFilled; - - friend class CCtrlColumnDef; - friend class CCtrlHeadFoot; - friend class CCtrlEqEdit; public: CCtrl(); CCtrl(const std::string& sCtrlID); diff --git a/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.cpp b/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.cpp index d0ae460dd2..5563114dfd 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.cpp @@ -3,23 +3,6 @@ namespace HWP { -ENumType GetNumType(int nValue) -{ - switch(static_cast(nValue)) - { - case ENumType::PAGE: - case ENumType::FOOTNOTE: - case ENumType::ENDNOTE: - case ENumType::FIGURE: - case ENumType::TABLE: - case ENumType::EQUATION: - case ENumType::TOTAL_PAGE: - return static_cast(nValue); - default: - return ENumType::null; - } -} - CCtrlAutoNumber::CCtrlAutoNumber(const std::string& sCtrlID) : CCtrl(sCtrlID) {} diff --git a/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.h b/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.h index 1b3f685954..bce810087e 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.h @@ -20,6 +20,23 @@ enum class ENumType null }; +ENumType GetNumType(int nValue) +{ + switch(static_cast(nValue)) + { + case ENumType::PAGE: + case ENumType::FOOTNOTE: + case ENumType::ENDNOTE: + case ENumType::FIGURE: + case ENumType::TABLE: + case ENumType::EQUATION: + case ENumType::TOTAL_PAGE: + return static_cast(nValue); + default: + return ENumType::null; + } +} + class CCtrlAutoNumber : public CCtrl { int m_nSize; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.cpp b/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.cpp new file mode 100644 index 0000000000..9c30701f21 --- /dev/null +++ b/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.cpp @@ -0,0 +1,27 @@ +#include "CtrlNewNumber.h" + +namespace HWP +{ +CCtrlNewNumber::CCtrlNewNumber(const std::string& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) + : CCtrl(sCtrlID) +{ + oBuffer.SavePosition(); + + int nAttr; + oBuffer.ReadInt(nAttr); + + m_eNumType = GetNumType(nAttr & 0xF); + m_eNumShape = GetNumberShape2((nAttr >> 4) & 0xF); + + oBuffer.ReadShort(m_shNum); + + m_bFullFilled = true; + + m_nSize = oBuffer.GetDistanceToLastPos(); +} + +int CCtrlNewNumber::GetSize() +{ + return m_nSize; +} +} diff --git a/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.h b/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.h new file mode 100644 index 0000000000..dd2d2a4e09 --- /dev/null +++ b/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.h @@ -0,0 +1,22 @@ +#ifndef CTRLNEWNUMBER_H +#define CTRLNEWNUMBER_H + +#include "CtrlAutoNumber.h" + +namespace HWP +{ +class CCtrlNewNumber : public CCtrl +{ + int m_nSize; + + ENumType m_eNumType; + ENumberShape2 m_eNumShape; + short m_shNum; +public: + CCtrlNewNumber(const std::string& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); + + int GetSize() override; +}; +} + +#endif // CTRLNEWNUMBER_H diff --git a/HwpFile/HwpDoc/Paragraph/CtrlNote.cpp b/HwpFile/HwpDoc/Paragraph/CtrlNote.cpp new file mode 100644 index 0000000000..30180af5f3 --- /dev/null +++ b/HwpFile/HwpDoc/Paragraph/CtrlNote.cpp @@ -0,0 +1,17 @@ +#include "CtrlNote.h" + +namespace HWP +{ +CCtrlNote::CCtrlNote(const std::string& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) + : CCtrl(sCtrlID) +{ + oBuffer.Skip(8); + m_bFullFilled = true; + m_nSize = 8; +} + +int CCtrlNote::GetSize() +{ + return m_nSize; +} +} diff --git a/HwpFile/HwpDoc/Paragraph/CtrlNote.h b/HwpFile/HwpDoc/Paragraph/CtrlNote.h new file mode 100644 index 0000000000..38ab5b3fb9 --- /dev/null +++ b/HwpFile/HwpDoc/Paragraph/CtrlNote.h @@ -0,0 +1,22 @@ +#ifndef CTRLNOTE_H +#define CTRLNOTE_H + +#include "HWPPargraph.h" +#include "Ctrl.h" +#include + +namespace HWP +{ +class CCtrlNote : public CCtrl +{ + int m_nSize; + + std::list m_arParas; +public: + CCtrlNote(const std::string& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); + + int GetSize() override; +}; +} + +#endif // CTRLNOTE_H diff --git a/HwpFile/HwpDoc/Section/NoteShape.cpp b/HwpFile/HwpDoc/Section/NoteShape.cpp new file mode 100644 index 0000000000..b8c0bc151f --- /dev/null +++ b/HwpFile/HwpDoc/Section/NoteShape.cpp @@ -0,0 +1,55 @@ +#include "NoteShape.h" + +namespace HWP +{ +ENoteNumbering GetNoteNumbering(int nValue) +{ + switch(static_cast(nValue)) + { + case ENoteNumbering::CONTINUOUS: return ENoteNumbering::CONTINUOUS; + case ENoteNumbering::ON_SECTION: return ENoteNumbering::ON_SECTION; + case ENoteNumbering::ON_PAGE: return ENoteNumbering::ON_PAGE; + default: + return ENoteNumbering::UNKNOWN; + } +} + +CNoteShape::CNoteShape() +{} + +CNoteShape* CNoteShape::Parse(int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) +{ + CNoteShape* pNoteShape = new CNoteShape(); + + if (nullptr == pNoteShape) + return nullptr; + + pNoteShape->m_eNumberShape = GetNumberShape2(oBuffer.ReadByte()); + + BYTE chAttr; + oBuffer.ReadByte(chAttr); + + pNoteShape->m_chPlacement = (BYTE)(chAttr & 0x03); + pNoteShape->m_eNumbering = GetNoteNumbering((chAttr >> 2) & 0x03); + pNoteShape->m_bSuperscript = CHECK_FLAG(chAttr >> 4, 0x01); + pNoteShape->m_bBeneathText = CHECK_FLAG(chAttr >> 5, 0x01); + oBuffer.Skip(2); + + oBuffer.ReadChar(pNoteShape->m_chUserChar); + oBuffer.ReadChar(pNoteShape->m_chPrefixChar); + oBuffer.ReadChar(pNoteShape->m_chSuffixChar); + oBuffer.ReadShort(pNoteShape->m_shNewNumber); + oBuffer.ReadInt(pNoteShape->m_nNoteLineLength); + oBuffer.ReadShort(pNoteShape->m_shSpacingAboveLine); + oBuffer.ReadShort(pNoteShape->m_shSpacingBelowLine); + oBuffer.ReadShort(pNoteShape->m_shSpacingBetweenNotes); + + pNoteShape->m_eNoteLineType = GetLineStyle1(oBuffer.ReadByte()); + oBuffer.ReadByte(pNoteShape->m_chNoteLineWidth); + oBuffer.ReadColor(pNoteShape->m_nNoteLineColor); + + return pNoteShape; +} + + +} diff --git a/HwpFile/HwpDoc/Section/NoteShape.h b/HwpFile/HwpDoc/Section/NoteShape.h new file mode 100644 index 0000000000..1457bc5ce6 --- /dev/null +++ b/HwpFile/HwpDoc/Section/NoteShape.h @@ -0,0 +1,54 @@ +#ifndef NOTESHAPE_H +#define NOTESHAPE_H + +#include "../HWPElements/HwpRecordTypes.h" +#include "../HWPStream.h" + +namespace HWP +{ +enum class ENoteNumbering +{ + CONTINUOUS, + ON_SECTION, + ON_PAGE, + UNKNOWN +}; + +//TODO:: проверить данный enum +// в олигинале и EachColumn и EndOfDocument имеют одинаковые значения +enum class ENotePlacement +{ + EachColumn, + MergedColumn, + RightMostColumn, + + EndOfDocument, + EndOfSection +}; + +class CNoteShape +{ + ENumberShape2 m_eNumberShape; + BYTE m_chPlacement; + ENoteNumbering m_eNumbering; + bool m_bSuperscript; + bool m_bBeneathText; + char16_t m_chUserChar; + char16_t m_chPrefixChar; + char16_t m_chSuffixChar; + short m_shNewNumber; + int m_nNoteLineLength; + short m_shSpacingAboveLine; + short m_shSpacingBelowLine; + short m_shSpacingBetweenNotes; + ELineStyle1 m_eNoteLineType; + BYTE m_chNoteLineWidth; + int m_nNoteLineColor; +public: + CNoteShape(); + + static CNoteShape* Parse(int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); +}; +} + +#endif // NOTESHAPE_H diff --git a/HwpFile/HwpDoc/Section/Page.cpp b/HwpFile/HwpDoc/Section/Page.cpp new file mode 100644 index 0000000000..fe56b8b3a1 --- /dev/null +++ b/HwpFile/HwpDoc/Section/Page.cpp @@ -0,0 +1,33 @@ +#include "Page.h" + +namespace HWP +{ +HWP::CPage::CPage() +{} + +CPage* CPage::Parse(int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) +{ + CPage *pPage = new CPage(); + + if (nullptr == pPage) + return nullptr; + + oBuffer.ReadInt(pPage->m_nWidth); + oBuffer.ReadInt(pPage->m_nHeight); + oBuffer.ReadInt(pPage->m_nMarginLeft); + oBuffer.ReadInt(pPage->m_nMarginRight); + oBuffer.ReadInt(pPage->m_nMarginTop); + oBuffer.ReadInt(pPage->m_nMarginBottom); + oBuffer.ReadInt(pPage->m_nMarginHeader); + oBuffer.ReadInt(pPage->m_nMarginFooter); + oBuffer.ReadInt(pPage->m_nMarginGutter); + + int nAttr; + oBuffer.ReadInt(nAttr); + + pPage->m_bLandscape = CHECK_FLAG(nAttr, 0x01); + pPage->m_chGutterType = (BYTE)((nAttr >> 1) & 0x03); + + return pPage; +} +} diff --git a/HwpFile/HwpDoc/Section/Page.h b/HwpFile/HwpDoc/Section/Page.h new file mode 100644 index 0000000000..4de462984a --- /dev/null +++ b/HwpFile/HwpDoc/Section/Page.h @@ -0,0 +1,28 @@ +#ifndef PAGE_H +#define PAGE_H + +#include "../HWPStream.h" + +namespace HWP +{ +class CPage +{ + bool m_bLandscape; + int m_nWidth; + int m_nHeight; + BYTE m_chGutterType; + int m_nMarginLeft; + int m_nMarginRight; + int m_nMarginTop; + int m_nMarginBottom; + int m_nMarginHeader; + int m_nMarginFooter; + int m_nMarginGutter; +public: + CPage(); + + static CPage* Parse(int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); +}; +} + +#endif // PAGE_H diff --git a/HwpFile/HwpDoc/Section/PageBorderFill.cpp b/HwpFile/HwpDoc/Section/PageBorderFill.cpp new file mode 100644 index 0000000000..1cd25dec0a --- /dev/null +++ b/HwpFile/HwpDoc/Section/PageBorderFill.cpp @@ -0,0 +1,28 @@ +#include "PageBorderFill.h" + +namespace HWP +{ +CPageBorderFill::CPageBorderFill() +{} + +CPageBorderFill* CPageBorderFill::Parse(int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) +{ + CPageBorderFill* pBorderFill = new CPageBorderFill(); + + int nAttr; + oBuffer.ReadInt(nAttr); + + pBorderFill->m_bTextBorder = CHECK_FLAG(nAttr, 0x01); + pBorderFill->m_bHeaderInside = CHECK_FLAG(nAttr, 0x02); + pBorderFill->m_bHeaderInside = CHECK_FLAG(nAttr, 0x04); + pBorderFill->m_chFillArea = (BYTE)((nAttr >> 3) & 0x03); + + oBuffer.ReadShort(pBorderFill->m_shOffsetLeft); + oBuffer.ReadShort(pBorderFill->m_shOffsetRight); + oBuffer.ReadShort(pBorderFill->m_shOffsetTop); + oBuffer.ReadShort(pBorderFill->m_shOffsetBottom); + oBuffer.ReadShort(pBorderFill->m_shBorderFill); + + return pBorderFill; +} +} diff --git a/HwpFile/HwpDoc/Section/PageBorderFill.h b/HwpFile/HwpDoc/Section/PageBorderFill.h new file mode 100644 index 0000000000..5701a0adbf --- /dev/null +++ b/HwpFile/HwpDoc/Section/PageBorderFill.h @@ -0,0 +1,26 @@ +#ifndef PAGEBORDERFILL_H +#define PAGEBORDERFILL_H + +#include "../HWPStream.h" + +namespace HWP +{ +class CPageBorderFill +{ + bool m_bTextBorder; + bool m_bHeaderInside; + bool m_bFooterInside; + BYTE m_chFillArea; + short m_shOffsetLeft; + short m_shOffsetRight; + short m_shOffsetTop; + short m_shOffsetBottom; + short m_shBorderFill; +public: + CPageBorderFill(); + + static CPageBorderFill* Parse(int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); +}; +} + +#endif // PAGEBORDERFILL_H