From e025ae2779231116acecfade0b4eb41df5b51087 Mon Sep 17 00:00:00 2001 From: Green Date: Sun, 6 Jul 2025 22:53:38 +0300 Subject: [PATCH] Refactoring --- HwpFile/HWPFile.pro | 2 +- HwpFile/HwpDoc/Common/XMLNode.h | 25 -- HwpFile/HwpDoc/Common/XMLReader.cpp | 150 ++++++--- HwpFile/HwpDoc/Common/XMLReader.h | 80 +++++ HwpFile/HwpDoc/HWPDocInfo.cpp | 86 ++--- HwpFile/HwpDoc/HWPDocInfo.h | 8 +- .../HwpDoc/HWPElements/HWPRecordBinData.cpp | 46 +-- HwpFile/HwpDoc/HWPElements/HWPRecordBinData.h | 4 +- .../HWPElements/HWPRecordBorderFill.cpp | 294 ++++++++++------- .../HwpDoc/HWPElements/HWPRecordBorderFill.h | 14 +- .../HwpDoc/HWPElements/HWPRecordBullet.cpp | 50 ++- HwpFile/HwpDoc/HWPElements/HWPRecordBullet.h | 4 +- .../HwpDoc/HWPElements/HWPRecordCharShape.cpp | 217 ++++++++----- .../HwpDoc/HWPElements/HWPRecordCharShape.h | 6 +- .../HWPRecordDocumentProperties.cpp | 24 +- .../HWPElements/HWPRecordDocumentProperties.h | 4 +- .../HwpDoc/HWPElements/HWPRecordFaceName.cpp | 79 +++-- .../HwpDoc/HWPElements/HWPRecordFaceName.h | 4 +- .../HwpDoc/HWPElements/HWPRecordNumbering.cpp | 92 +++--- .../HwpDoc/HWPElements/HWPRecordNumbering.h | 4 +- .../HwpDoc/HWPElements/HWPRecordParaShape.cpp | 244 +++++++++------ .../HwpDoc/HWPElements/HWPRecordParaShape.h | 6 +- HwpFile/HwpDoc/HWPElements/HWPRecordStyle.cpp | 41 ++- HwpFile/HwpDoc/HWPElements/HWPRecordStyle.h | 4 +- .../HwpDoc/HWPElements/HwpRecordTabDef.cpp | 59 ++-- HwpFile/HwpDoc/HWPElements/HwpRecordTabDef.h | 6 +- HwpFile/HwpDoc/HWPSection.cpp | 11 +- HwpFile/HwpDoc/HWPSection.h | 2 +- HwpFile/HwpDoc/HWPXFile.cpp | 44 ++- HwpFile/HwpDoc/HWPXFile.h | 2 +- HwpFile/HwpDoc/HwpFileHeader.cpp | 27 +- HwpFile/HwpDoc/HwpFileHeader.h | 4 +- HwpFile/HwpDoc/Paragraph/CapParagraph.cpp | 4 +- HwpFile/HwpDoc/Paragraph/CapParagraph.h | 2 +- HwpFile/HwpDoc/Paragraph/CellParagraph.cpp | 4 +- HwpFile/HwpDoc/Paragraph/CellParagraph.h | 2 +- HwpFile/HwpDoc/Paragraph/CommonObj.h | 3 - HwpFile/HwpDoc/Paragraph/Ctrl.cpp | 42 +-- HwpFile/HwpDoc/Paragraph/Ctrl.h | 4 +- HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.cpp | 98 +++--- HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.h | 4 +- HwpFile/HwpDoc/Paragraph/CtrlColumnDef.cpp | 47 ++- HwpFile/HwpDoc/Paragraph/CtrlColumnDef.h | 4 +- HwpFile/HwpDoc/Paragraph/CtrlCommon.cpp | 257 +++++++++------ HwpFile/HwpDoc/Paragraph/CtrlCommon.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlContainer.cpp | 49 +-- HwpFile/HwpDoc/Paragraph/CtrlContainer.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlEqEdit.cpp | 41 ++- HwpFile/HwpDoc/Paragraph/CtrlEqEdit.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlField.cpp | 65 ++-- HwpFile/HwpDoc/Paragraph/CtrlField.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlGeneralShape.cpp | 241 ++++++++------ HwpFile/HwpDoc/Paragraph/CtrlGeneralShape.h | 4 +- HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.cpp | 28 +- HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlNewNumber.cpp | 17 +- HwpFile/HwpDoc/Paragraph/CtrlNewNumber.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlNote.cpp | 12 +- HwpFile/HwpDoc/Paragraph/CtrlNote.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlObjElement.cpp | 130 +++++--- HwpFile/HwpDoc/Paragraph/CtrlObjElement.h | 4 +- HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.cpp | 15 +- HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.h | 4 +- HwpFile/HwpDoc/Paragraph/CtrlSectionDef.cpp | 222 ++++++++----- HwpFile/HwpDoc/Paragraph/CtrlSectionDef.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlShapeArc.cpp | 48 ++- HwpFile/HwpDoc/Paragraph/CtrlShapeArc.h | 2 +- .../HwpDoc/Paragraph/CtrlShapeConnectLine.cpp | 45 ++- .../HwpDoc/Paragraph/CtrlShapeConnectLine.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.cpp | 55 ++-- HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.cpp | 106 +++++-- HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlShapeLine.cpp | 33 +- HwpFile/HwpDoc/Paragraph/CtrlShapeLine.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlShapeOle.cpp | 19 +- HwpFile/HwpDoc/Paragraph/CtrlShapeOle.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlShapePic.cpp | 295 +++++++++++------- HwpFile/HwpDoc/Paragraph/CtrlShapePic.h | 12 +- HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.cpp | 25 +- HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlShapeRect.cpp | 37 ++- HwpFile/HwpDoc/Paragraph/CtrlShapeRect.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.cpp | 109 ++++--- HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.cpp | 33 +- HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.h | 2 +- HwpFile/HwpDoc/Paragraph/CtrlTable.cpp | 74 +++-- HwpFile/HwpDoc/Paragraph/CtrlTable.h | 2 +- HwpFile/HwpDoc/Paragraph/HWPPargraph.cpp | 180 ++++++----- HwpFile/HwpDoc/Paragraph/HWPPargraph.h | 6 +- HwpFile/HwpDoc/Paragraph/LineSeg.cpp | 13 +- HwpFile/HwpDoc/Paragraph/LineSeg.h | 4 +- HwpFile/HwpDoc/Paragraph/TblCell.cpp | 88 ++++-- HwpFile/HwpDoc/Paragraph/TblCell.h | 2 +- HwpFile/HwpDoc/Section/NoteShape.cpp | 2 +- HwpFile/HwpDoc/Section/NoteShape.h | 4 +- HwpFile/HwpDoc/Section/Page.cpp | 69 ++-- HwpFile/HwpDoc/Section/Page.h | 4 +- HwpFile/HwpDoc/Section/PageBorderFill.cpp | 61 ++-- HwpFile/HwpDoc/Section/PageBorderFill.h | 4 +- OfficeUtils/src/ZipFolder.h | 2 + 102 files changed, 2729 insertions(+), 1585 deletions(-) delete mode 100644 HwpFile/HwpDoc/Common/XMLNode.h create mode 100644 HwpFile/HwpDoc/Common/XMLReader.h diff --git a/HwpFile/HWPFile.pro b/HwpFile/HWPFile.pro index f1d3d1318d..89dfe87fae 100644 --- a/HwpFile/HWPFile.pro +++ b/HwpFile/HWPFile.pro @@ -99,8 +99,8 @@ SOURCES += \ HEADERS += \ HWPFile.h \ HwpDoc/Common/Common.h \ - HwpDoc/Common/XMLNode.h \ HwpDoc/Common/WriterContext.h \ + HwpDoc/Common/XMLReader.h \ HwpDoc/Conversion/ConversionState.h \ HwpDoc/Conversion/Converter2OOXML.h \ HwpDoc/Conversion/FootnoteConverter.h \ diff --git a/HwpFile/HwpDoc/Common/XMLNode.h b/HwpFile/HwpDoc/Common/XMLNode.h deleted file mode 100644 index 518ea10488..0000000000 --- a/HwpFile/HwpDoc/Common/XMLNode.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef XMLNODEH_H -#define XMLNODEH_H - -#include "../../../DesktopEditor/xml/include/xmlutils.h" - -namespace HWP -{ -class CXMLNode : public XmlUtils::CXmlNode -{ -public: - CXMLNode(); - CXMLNode(const XmlUtils::CXmlNode& oNode); - - bool GetAttributeBool(const std::wstring& wsName); - int GetAttributeColor(const std::wstring& wsName, const int& _default = 0x00000000); - CXMLNode GetChild(const std::wstring& wsName); - std::vector GetChilds(); - std::vector GetChilds(const std::wstring& wsName); -}; - -int ConvertWidthToHWP(const std::wstring& wsValue); -int ConvertHexToInt(const std::string& wsValue, const int& _default = 0x00000000); -} - -#endif // XMLNODEH_H diff --git a/HwpFile/HwpDoc/Common/XMLReader.cpp b/HwpFile/HwpDoc/Common/XMLReader.cpp index 82d133855b..edb1831268 100644 --- a/HwpFile/HwpDoc/Common/XMLReader.cpp +++ b/HwpFile/HwpDoc/Common/XMLReader.cpp @@ -1,86 +1,142 @@ -#include "XMLNode.h" +#include "XMLReader.h" namespace HWP { -CXMLNode::CXMLNode() - : XmlUtils::CXmlNode() +CXMLReader::CXMLReader() {} -CXMLNode::CXMLNode(const CXmlNode& oNode) - : XmlUtils::CXmlNode(oNode) -{} - -bool CXMLNode::GetAttributeBool(const std::wstring& wsName) +CXMLReader::CXMLReader(CXmlLiteReader& oReader) + // : XmlUtils::CXmlLiteReader(oReader) { - return L"1" == XmlUtils::CXmlNode::GetAttribute(wsName, L"0"); + oReader.ReadNextNode(); + FromString(oReader.GetInnerXml()); } -int CXMLNode::GetAttributeColor(const std::wstring& wsName, const int& _default) +bool CXMLReader::GetBool() { - return ConvertHexToInt(XmlUtils::CXmlNode::GetAttributeA(wsName), _default); + return "1" == GetText2A(); } -CXMLNode CXMLNode::GetChild(const std::wstring& wsName) +int CXMLReader::GetColor(const int& nDefault) { - return CXMLNode(XmlUtils::CXmlNode::GetNode(wsName)); + return ConvertHexToInt(GetText2A(), nDefault); } -std::vector CXMLNode::GetChilds() +int CXMLReader::GetInt() { - std::vector arChilds; - XmlUtils::CXmlNode::GetChilds(arChilds); - - std::vector arNewChilds(arChilds.size()); - for (unsigned int unIndex = 0; unIndex < arChilds.size(); ++unIndex) - arNewChilds[unIndex] = CXMLNode(arChilds[unIndex]); - - return arNewChilds; + return GetIntValue(*this); } -std::vector CXMLNode::GetChilds(const std::wstring& wsName) +double CXMLReader::GetDouble() { - std::vector arChilds{XmlUtils::CXmlNode::GetNodes(wsName)}; - - std::vector arNewChilds(arChilds.size()); - for (unsigned int unIndex = 0; unIndex < arChilds.size(); ++unIndex) - arNewChilds[unIndex] = CXMLNode(arChilds[unIndex]); - - return arNewChilds; + return GetDoubleValue(*this); } -int ConvertWidthToHWP(const std::wstring& wsValue) +template +T CXMLReader::GetAttribute(const std::string& sName, T _default, T (*GetValue)(CXMLReader& oReader)) { - if (wsValue.empty() || L"0.1" == wsValue || L"0.1 mm" == wsValue) + if (!MoveToFirstAttribute()) + return _default; + + T oValue = _default; + + do + { + if (sName == GetNameA()) + { + oValue = GetValue(*this); + break; + } + }while(MoveToNextAttribute()); + + MoveToElement(); + + return oValue; +} + +int CXMLReader::GetAttributeInt(const std::string& sName, int nDefault) +{ + return GetAttribute(sName, nDefault, &GetIntValue); +} + +bool CXMLReader::GetAttributeBool(const std::string& sName) +{ + return GetAttribute(sName, false, &GetBoolValue); +} + +double CXMLReader::GetAttributeDouble(const std::string& sName) +{ + return GetAttribute(sName, 0., &GetDoubleValue); +} + +std::string CXMLReader::GetAttributeA(const std::string& sName) +{ + return GetAttribute(sName, "", &GetTextAValue); +} + +std::wstring CXMLReader::GetAttribute(const std::string& sName) +{ + return GetAttribute(sName, L"", &GetTextValue); +} + +int CXMLReader::GetIntValue(CXMLReader& oXmlReader) +{ + return std::atoi(oXmlReader.GetText2A().c_str()); +} + +bool CXMLReader::GetBoolValue(CXMLReader& oXmlReader) +{ + return "1" == oXmlReader.GetText2A(); +} + +double CXMLReader::GetDoubleValue(CXMLReader& oXmlReader) +{ + return std::atof(oXmlReader.GetText2A().c_str()); +} + +std::string CXMLReader::GetTextAValue(CXMLReader& oXmlReader) +{ + return oXmlReader.GetText2A(); +} + +std::wstring CXMLReader::GetTextValue(CXMLReader& oXmlReader) +{ + return oXmlReader.GetText2(); +} + +int ConvertWidthToHWP(const std::string& sValue) +{ + if (sValue.empty() || "0.1" == sValue || "0.1 mm" == sValue) return 0; - else if (L"0.12" == wsValue || L"0.12 mm" == wsValue) + else if ("0.12" == sValue || "0.12 mm" == sValue) return 1; - else if (L"0.15" == wsValue || L"0.15 mm" == wsValue) + else if ("0.15" == sValue || "0.15 mm" == sValue) return 2; - else if (L"0.2" == wsValue || L"0.2 mm" == wsValue) + else if ("0.2" == sValue || "0.2 mm" == sValue) return 3; - else if (L"0.25" == wsValue || L"0.25 mm" == wsValue) + else if ("0.25" == sValue || "0.25 mm" == sValue) return 4; - else if (L"0.3" == wsValue || L"0.3 mm" == wsValue) + else if ("0.3" == sValue || "0.3 mm" == sValue) return 5; - else if (L"0.4" == wsValue || L"0.4 mm" == wsValue) + else if ("0.4" == sValue || "0.4 mm" == sValue) return 6; - else if (L"0.5" == wsValue || L"0.5 mm" == wsValue) + else if ("0.5" == sValue || "0.5 mm" == sValue) return 7; - else if (L"0.6" == wsValue || L"0.6 mm" == wsValue) + else if ("0.6" == sValue || "0.6 mm" == sValue) return 8; - else if (L"0.7" == wsValue || L"0.7 mm" == wsValue) + else if ("0.7" == sValue || "0.7 mm" == sValue) return 9; - else if (L"1.0" == wsValue || L"1.0 mm" == wsValue) + else if ("1.0" == sValue || "1.0 mm" == sValue) return 10; - else if (L"1.5" == wsValue || L"1.5 mm" == wsValue) + else if ("1.5" == sValue || "1.5 mm" == sValue) return 11; - else if (L"2.0" == wsValue || L"2.0 mm" == wsValue) + else if ("2.0" == sValue || "2.0 mm" == sValue) return 12; - else if (L"3.0" == wsValue || L"3.0 mm" == wsValue) + else if ("3.0" == sValue || "3.0 mm" == sValue) return 13; - else if (L"4.0" == wsValue || L"4.0 mm" == wsValue) + else if ("4.0" == sValue || "4.0 mm" == sValue) return 14; - else if (L"5.0" == wsValue || L"5.0 mm" == wsValue) + else if ("5.0" == sValue || "5.0 mm" == sValue) return 15; return 0; diff --git a/HwpFile/HwpDoc/Common/XMLReader.h b/HwpFile/HwpDoc/Common/XMLReader.h new file mode 100644 index 0000000000..55e961cf40 --- /dev/null +++ b/HwpFile/HwpDoc/Common/XMLReader.h @@ -0,0 +1,80 @@ +#ifndef XMLNODEH_H +#define XMLNODEH_H + +#include "../../../DesktopEditor/xml/include/xmlutils.h" + +namespace HWP +{ +class CXMLReader : public XmlUtils::CXmlLiteReader +{ +public: + CXMLReader(); + CXMLReader(XmlUtils::CXmlLiteReader& oReader); + + bool GetBool(); + int GetColor(const int& nDefault = 0x000000); + int GetInt(); + double GetDouble(); + + int GetAttributeInt(const std::string& sName, int nDefault = 0); + bool GetAttributeBool(const std::string& sName); + double GetAttributeDouble(const std::string& sName); + std::string GetAttributeA(const std::string& sName); + std::wstring GetAttribute(const std::string& sName); +private: + static int GetIntValue(CXMLReader& oXmlReader); + static bool GetBoolValue(CXMLReader& oXmlReader); + static double GetDoubleValue(CXMLReader& oXmlReader); + static std::string GetTextAValue(CXMLReader& oXmlReader); + static std::wstring GetTextValue(CXMLReader& oXmlReader); + + template + T GetAttribute(const std::string& sName, T _default, T (*GetValue)(CXMLReader& oXmlReader)); +}; + +#define WHILE_READ_NEXT_NODE_WITH_DEPTH(xml_reader, name_depth)\ + const int n##name_depth = xml_reader.GetDepth();\ + while (xml_reader.ReadNextSiblingNode2(n##name_depth)) + +#define WHILE_READ_NEXT_NODE_WITH_DEPTH_AND_NAME(xml_reader, name_depth)\ + const int n##name_depth##Depth = xml_reader.GetDepth();\ + std::string sNode##name_depth##Name;\ + while (xml_reader.ReadNextSiblingNode2(n##name_depth##Depth))\ + {\ + sNode##name_depth##Name = xml_reader.GetNameA(); + +#define WHILE_READ_NEXT_NODE(xml_reader) WHILE_READ_NEXT_NODE_WITH_DEPTH(xml_reader, Depth) + +#define WHILE_READ_NEXT_NODE_WITH_NAME(xml_reader)\ + const int nDepth = xml_reader.GetDepth();\ + std::string sNodeName;\ + while (xml_reader.ReadNextSiblingNode2(nDepth))\ + {\ + sNodeName = xml_reader.GetNameA(); + +#define WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(xml_reader, name_depth, node_name)\ + WHILE_READ_NEXT_NODE_WITH_DEPTH(xml_reader, name_depth)\ + {\ + if (node_name != xml_reader.GetNameA())\ + continue; + +#define WHILE_READ_NEXT_NODE_WITH_ONE_NAME(xml_reader, node_name) WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(xml_reader, Depth, node_name) + +#define END_WHILE } + +#define START_READ_ATTRIBUTES(xml_reader)\ + if (xml_reader.MoveToFirstAttribute())\ + {\ + std::string sAttributeName{xml_reader.GetNameA()};\ + do + +#define END_READ_ATTRIBUTES(xml_reader)\ + while(xml_reader.MoveToNextAttribute());\ + xml_reader.MoveToElement();\ + } + +int ConvertWidthToHWP(const std::string& sValue); +int ConvertHexToInt(const std::string& sValue, const int& _default = 0x00000000); +} + +#endif // XMLNODEH_H diff --git a/HwpFile/HwpDoc/HWPDocInfo.cpp b/HwpFile/HwpDoc/HWPDocInfo.cpp index 09d461a450..6d8b8c073c 100644 --- a/HwpFile/HwpDoc/HWPDocInfo.cpp +++ b/HwpFile/HwpDoc/HWPDocInfo.cpp @@ -182,81 +182,93 @@ bool CHWPDocInfo::Parse(CHWPStream& oBuffer, int nVersion) return true; } -bool CHWPDocInfo::Parse(CXMLNode& oNode, int nVersion) +bool CHWPDocInfo::Parse(CXMLReader& oReader, int nVersion) { - for (CXMLNode& oChild : oNode.GetChilds()) + WHILE_READ_NEXT_NODE_WITH_NAME(oReader) { - if (L"hh:beginNum" == oChild.GetName()) - m_arRecords.push_back(new CHWPRecordDocumentProperties(*this, oChild, nVersion)); - else if (L"hh:refList" == oChild.GetName()) - ReadRefList(oChild, nVersion); + if ("hh:beginNum" == sNodeName) + m_arRecords.push_back(new CHWPRecordDocumentProperties(*this, oReader, nVersion)); + else if ("hh:refList" == sNodeName) + ReadRefList(oReader, nVersion); } + END_WHILE return true; } -bool CHWPDocInfo::ReadRefList(CXMLNode& oNode, int nVersion) +bool CHWPDocInfo::ReadRefList(CXMLReader& oReader, int nVersion) { - for (CXMLNode& oChild : oNode.GetChilds()) + WHILE_READ_NEXT_NODE_WITH_NAME(oReader) { - if (L"hh:fontfaces" == oChild.GetName()) + if ("hh:fontfaces" == sNodeName) { - for (CXMLNode& oFontFaceNode : oChild.GetChilds(L"hh:fontface")) - for (CXMLNode& oFontNode : oFontFaceNode.GetChilds(L"hh:font")) - m_arFaseNames.push_back(new CHWPRecordFaceName(*this, oFontNode, nVersion)); + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, FontFace, "hh:fontface") + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Font, "hh:font") + m_arFaseNames.push_back(new CHWPRecordFaceName(*this, oReader, nVersion)); + END_WHILE + END_WHILE } - else if (L"hh:borderFills" == oChild.GetName()) + else if ("hh:borderFills" == sNodeName) { - for (CXMLNode& oBorderFillNode : oChild.GetChilds(L"hh:borderFill")) - m_arBorderFills.push_back(new CHWPRecordBorderFill(*this, oBorderFillNode, nVersion)); + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, BorderFill, "hh:borderFill") + m_arBorderFills.push_back(new CHWPRecordBorderFill(*this, oReader, nVersion)); + END_WHILE } - else if (L"hh:charProperties" == oChild.GetName()) + else if ("hh:charProperties" == sNodeName) { - for (CXMLNode& oCharPrNode : oChild.GetChilds(L"hh:charPr")) - m_arCharShapes.push_back(new CHWPRecordCharShape(*this, oCharPrNode, nVersion)); + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, CharPr, "hh:charPr") + m_arCharShapes.push_back(new CHWPRecordCharShape(*this, oReader, nVersion)); + END_WHILE } - else if (L"hh:tabProperties" == oChild.GetName()) + else if ("hh:tabProperties" == sNodeName) { - for (CXMLNode& oTabPrNode : oChild.GetChilds(L"hh:tabPr")) - m_arTabDefs.push_back(new CHwpRecordTabDef(*this, oTabPrNode, nVersion)); + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, TabPr, "hh:tabPr") + m_arTabDefs.push_back(new CHwpRecordTabDef(*this, oReader, nVersion)); + END_WHILE } - else if (L"hh:numberings" == oChild.GetName()) + else if ("hh:numberings" == sNodeName) { - for (CXMLNode& oNumberingNode : oChild.GetChilds(L"hh:numbering")) - m_arNumberings.push_back(new CHWPRecordNumbering(*this, oNumberingNode, nVersion)); + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Numbering, "hh:numbering") + m_arNumberings.push_back(new CHWPRecordNumbering(*this, oReader, nVersion)); + END_WHILE } - else if (L"hh:bullets" == oChild.GetName()) + else if ("hh:bullets" == sNodeName) { - for (CXMLNode& oBulletNode : oChild.GetChilds()) - m_arBullets.push_back(new CHWPRecordBullet(*this, oBulletNode, nVersion)); + WHILE_READ_NEXT_NODE_WITH_DEPTH(oReader, Bullet) + m_arBullets.push_back(new CHWPRecordBullet(*this, oReader, nVersion)); } - else if (L"hh:paraProperties" == oChild.GetName()) + else if ("hh:paraProperties" == sNodeName) { - for (CXMLNode& oParaPrNode : oChild.GetChilds(L"hh:paraPr")) - m_arParaShapes.push_back(new CHWPRecordParaShape(*this, oParaPrNode, nVersion)); + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, ParaPr, "hh:paraPr") + m_arParaShapes.push_back(new CHWPRecordParaShape(*this, oReader, nVersion)); + END_WHILE } - else if (L"hh:styles" == oChild.GetName()) + else if ("hh:styles" == sNodeName) { - for (CXMLNode& oStyleNode : oChild.GetChilds(L"hh:style")) - m_arStyles.push_back(new CHWPRecordStyle(*this, oStyleNode, nVersion)); + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Style, "hh:style") + m_arStyles.push_back(new CHWPRecordStyle(*this, oReader, nVersion)); + END_WHILE } } + END_WHILE return true; } -bool CHWPDocInfo::ReadContentHpf(CXMLNode& oNode, int nVersion) +bool CHWPDocInfo::ReadContentHpf(CXMLReader& oReader, int nVersion) { CHWPRecordBinData *pRecordBinData = nullptr; - for (CXMLNode& oChild : oNode.GetChilds(L"opf:manifest")) + WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "opf:manifest") { - for (CXMLNode& oGrandChild : oChild.GetChilds(L"opf:item")) + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Item, "opf:item") { - pRecordBinData = new CHWPRecordBinData(oGrandChild, nVersion); + pRecordBinData = new CHWPRecordBinData(oReader, nVersion); m_mBinDatas.insert(std::make_pair(pRecordBinData->GetItemID(), (HWP::CHWPRecord*)pRecordBinData)); } + END_WHILE } + END_WHILE return true; } diff --git a/HwpFile/HwpDoc/HWPDocInfo.h b/HwpFile/HwpDoc/HWPDocInfo.h index 5f84717996..0f6143cffc 100644 --- a/HwpFile/HwpDoc/HWPDocInfo.h +++ b/HwpFile/HwpDoc/HWPDocInfo.h @@ -4,7 +4,7 @@ #include "HanType.h" #include "HWPStream.h" #include "HWPElements/HWPRecord.h" -#include "Common/XMLNode.h" +#include "Common/XMLReader.h" #include @@ -46,8 +46,8 @@ public: ~CHWPDocInfo(); bool Parse(CHWPStream& oBuffer, int nVersion); - bool Parse(CXMLNode& oNode, int nVersion); - bool ReadContentHpf(CXMLNode& oNode, int nVersion); + bool Parse(CXMLReader& oReader, int nVersion); + bool ReadContentHpf(CXMLReader& oReader, int nVersion); const CHWPRecord* GetRecord(int nIndex) const; const CHWPRecord* GetFaceName(int nIndex) const; @@ -65,7 +65,7 @@ public: EHanType GetHanType() const; ECompatDoc GetCompatibleDoc() const; private: - bool ReadRefList(CXMLNode& oNode, int nVersion); + bool ReadRefList(CXMLReader& oReader, int nVersion); }; } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordBinData.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordBinData.cpp index 53ead34f05..5e2a02a5a9 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordBinData.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordBinData.cpp @@ -74,35 +74,41 @@ CHWPRecordBinData::CHWPRecordBinData(CHWPDocInfo& oDocInfo, int nTagNum, int nLe oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); } -CHWPRecordBinData::CHWPRecordBinData(CXMLNode& oNode, int nVersion) +CHWPRecordBinData::CHWPRecordBinData(CXMLReader& oReader, int nVersion) : CHWPRecord(EHWPTag::HWPTAG_BIN_DATA, 0, 0) { - m_sItemID = oNode.GetAttribute(L"id"); + std::string sType; + HWP_STRING sSubPath; - HWP_STRING sType = oNode.GetAttribute(L"isEmbeded"); + START_READ_ATTRIBUTES(oReader) + { + if ("id" == sAttributeName) + m_sItemID = oReader.GetText2(); + else if ("isEmbeded" == sAttributeName) + sType = oReader.GetText2A(); + else if ("href" == sAttributeName) + m_sAPath = oReader.GetText2(); + else if ("sub-path" == sAttributeName) + sSubPath = oReader.GetText2(); + else if ("media-type" == sAttributeName) + { + m_sFormat = oReader.GetText2(); - if (L"0" == sType) + std::wregex oRegex(L"image/(.*)"); + m_sFormat = std::regex_replace(m_sFormat, oRegex, L"$1"); + } + } + END_READ_ATTRIBUTES(oReader) + + if ("0" == sType) { m_eType = EType::LINK; - m_sAPath = oNode.GetAttribute(L"sub-path"); - - if (m_sAPath.empty()) - m_sAPath = oNode.GetAttribute(L"href"); + if (!sSubPath.empty()) + m_sAPath = sSubPath; } - else if (L"1" == sType) - { + else if ("1" == sType) m_eType = EType::EMBEDDING; - m_sAPath = oNode.GetAttribute(L"href"); - } - else - m_sAPath = oNode.GetAttribute(L"href"); - - m_sFormat = oNode.GetAttribute(L"media-type"); - - std::wregex oRegex(L"image/(.*)"); - - m_sFormat = std::regex_replace(m_sFormat, oRegex, L"$1"); } HWP_STRING CHWPRecordBinData::GetPath() const diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordBinData.h b/HwpFile/HwpDoc/HWPElements/HWPRecordBinData.h index c225fa3f17..269c8d4203 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordBinData.h +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordBinData.h @@ -4,7 +4,7 @@ #include "HWPRecord.h" #include "../HWPStream.h" #include "../HWPDocInfo.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -44,7 +44,7 @@ class CHWPRecordBinData : public CHWPRecord HWP_STRING m_sItemID; public: CHWPRecordBinData(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CHWPRecordBinData(CXMLNode& oNode, int nVersion); + CHWPRecordBinData(CXMLReader& oReader, int nVersion); HWP_STRING GetPath() const; HWP_STRING GetItemID() const; diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.cpp index e41b2e4b45..b899ef0f2e 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.cpp @@ -58,19 +58,26 @@ EColorFillPattern GetColorFillPattern(int nPattern) } } -void TBorder::ReadFromNode(CXMLNode& oNode) +void TBorder::Read(CXMLReader& oReader) { - m_eStyle = GetLineStyle2(oNode.GetAttribute(L"type")); - m_nColor = oNode.GetAttributeColor(L"color"); - m_chWidth = (HWP_BYTE)ConvertWidthToHWP(oNode.GetAttribute(L"width")); + START_READ_ATTRIBUTES(oReader) + { + if ("type" == sAttributeName) + m_eStyle = GetLineStyle2(oReader.GetText2()); + else if ("color" == sAttributeName) + m_nColor = oReader.GetInt(); + else if ("width" == sAttributeName) + m_chWidth = (HWP_BYTE)ConvertWidthToHWP(oReader.GetText2A()); + } + END_READ_ATTRIBUTES(oReader) } CFill::CFill() - : m_nFillType(0) + : m_nFillType(0), m_eHatchStyle(EColorFillPattern::NONE), m_eMode(EImageFillType::NONE), m_chAlpha(0xff) {} CFill::CFill(CHWPStream& oBuffer, int nOff, int nSize) - : m_nFillType(0) + : m_nFillType(0), m_eHatchStyle(EColorFillPattern::NONE), m_eMode(EImageFillType::NONE), m_chAlpha(0xff) { oBuffer.SavePosition(); @@ -147,81 +154,122 @@ CFill::CFill(CHWPStream& oBuffer, int nOff, int nSize) m_nSize = oBuffer.GetDistanceToLastPos(true); } -CFill::CFill(CXMLNode& oNode) - : m_nFillType(0) +CFill::CFill(CXMLReader& oReader) + : m_nFillType(0), m_eHatchStyle(EColorFillPattern::NONE), m_eMode(EImageFillType::NONE), m_chAlpha(0xff) { - for (CXMLNode& oChild : oNode.GetChilds()) + std::string sNodeName; + WHILE_READ_NEXT_NODE(oReader) { - if (L"hc:winBrush" == oChild.GetName()) + sNodeName = oReader.GetNameA(); + + if ("hc:winBrush" == sNodeName) { - ReadWinBrush(oChild); + ReadWinBrush(oReader); m_nFillType |= 0x01; } - else if (L"hc:gradation" == oChild.GetName()) + else if ("hc:gradation" == sNodeName) { - ReadGradation(oChild); + ReadGradation(oReader); m_nFillType |= 0x04; } - else if (L"hc:imgBrush" == oChild.GetName()) + else if ("hc:imgBrush" == sNodeName) { - ReadImgBrush(oChild); + ReadImgBrush(oReader); m_nFillType |= 0x02; } } } -void CFill::ReadWinBrush(CXMLNode& oNode) +void CFill::ReadWinBrush(CXMLReader& oReader) { - m_nFaceColor = oNode.GetAttributeColor(L"faceColor", 0xFFFFFFFF); - m_nHatchColor = oNode.GetAttributeColor(L"hatchColor", 0x000000); - m_eHatchStyle = GetColorFillPattern(oNode.GetAttributeInt(L"hatchStyle", -1)); - m_chAlpha = (HWP_BYTE)oNode.GetAttributeInt(L"alpha", 255); -} + m_eHatchStyle = EColorFillPattern::NONE; + m_chAlpha = 0xff; -void CFill::ReadGradation(CXMLNode& oNode) -{ - m_eGradType = ::HWP::GetGradFillType(oNode.GetAttributeInt(L"type")); - m_nAngle = oNode.GetAttributeInt(L"angle"); - m_nCenterX = oNode.GetAttributeInt(L"centerX"); - m_nCenterY = oNode.GetAttributeInt(L"centerY"); - m_nStep = oNode.GetAttributeInt(L"step"); - m_nColorNum = oNode.GetAttributeInt(L"colorNum"); - m_chStepCenter = (HWP_BYTE)oNode.GetAttributeInt(L"stepCenter"); - m_chAlpha = (HWP_BYTE)oNode.GetAttributeInt(L"alpha", 255); - - std::vector arChilds; - - oNode.GetNodes(L"hc:color", arChilds); - - m_arColors.resize(arChilds.size()); - - for (unsigned int unIndex = 0; unIndex < arChilds.size(); ++unIndex) - m_arColors[unIndex] = CXMLNode(arChilds[unIndex]).GetAttributeColor(L"value"); -} - -void CFill::ReadImgBrush(CXMLNode& oNode) -{ - m_eMode = GetImageFillType(oNode.GetAttributeInt(L"mode", (int)EImageFillType::NONE)); - - for (CXMLNode& oChild : oNode.GetChilds()) + START_READ_ATTRIBUTES(oReader) { - if (L"hc:img" == oChild.GetName()) + if ("faceColor" == sAttributeName) + m_nFaceColor = oReader.GetColor(0xFFFFFFFF); + else if ("hatchColor" == sAttributeName) + m_nHatchColor = oReader.GetColor(); + else if ("hatchStyle" == sAttributeName) + m_eHatchStyle = GetColorFillPattern(oReader.GetInt()); + else if ("alpha" == sAttributeName) + m_chAlpha = (HWP_BYTE)oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) +} + +void CFill::ReadGradation(CXMLReader& oReader) +{ + START_READ_ATTRIBUTES(oReader) + { + if ("type" == sAttributeName) + m_eGradType = ::HWP::GetGradFillType(oReader.GetInt()); + else if ("angle" == sAttributeName) + m_nAngle = oReader.GetInt(); + else if ("centerX" == sAttributeName) + m_nCenterX = oReader.GetInt(); + else if ("centerY" == sAttributeName) + m_nCenterY = oReader.GetInt(); + else if ("step" == sAttributeName) + m_nStep = oReader.GetInt(); + else if ("colorNum" == sAttributeName) + m_nColorNum = oReader.GetInt(); + else if ("stepCenter" == sAttributeName) + m_chStepCenter = (HWP_BYTE)oReader.GetInt(); + else if ("alpha" == sAttributeName) + m_chAlpha = (HWP_BYTE)oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + + WHILE_READ_NEXT_NODE(oReader) + { + if ("hc:color" != oReader.GetNameA()) + continue; + + START_READ_ATTRIBUTES(oReader) { - m_chBright = (HWP_BYTE)oChild.GetAttributeInt(L"bright"); - m_chContrast = (HWP_BYTE)oChild.GetAttributeInt(L"contrast"); + if ("value" != oReader.GetNameA()) + continue; - HWP_STRING sEffect = oChild.GetAttribute(L"effect"); - - if (L"REAL_PIC" == sEffect) - m_chEffect = 0; - else if (L"GRAY_SCALE" == sEffect) - m_chEffect = 1; - else if (L"BLACK_WHITE" == sEffect) - m_chEffect = 2; - - m_sBinItemID = oChild.GetAttribute(L"binaryItemIDRef"); - m_chAlpha = (HWP_BYTE)oChild.GetAttributeInt(L"alpha", 255); + m_arColors.push_back(oReader.GetColor()); } + END_READ_ATTRIBUTES(oReader) + } +} + +void CFill::ReadImgBrush(CXMLReader& oReader) +{ + m_eMode = GetImageFillType(oReader.GetAttributeInt("mode")); + + WHILE_READ_NEXT_NODE(oReader) + { + if ("hc:img" != oReader.GetNameA()) + continue; + + START_READ_ATTRIBUTES(oReader) + { + if ("bright" == sAttributeName) + m_chBright = (HWP_BYTE)oReader.GetInt(); + else if ("contrast" == sAttributeName) + m_chContrast = (HWP_BYTE)oReader.GetInt(); + else if ("effect" == sAttributeName) + { + const std::string sEffect{oReader.GetText2A()}; + + if ("REAL_PIC" == sEffect) + m_chEffect = 0; + else if ("GRAY_SCALE" == sEffect) + m_chEffect = 1; + else if ("BLACK_WHITE" == sEffect) + m_chEffect = 2; + } + else if ("binaryItemIDRef" == sAttributeName) + m_sBinItemID = oReader.GetText2(); + else if ("alpha" == sAttributeName) + m_chAlpha = (HWP_BYTE)oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } } @@ -333,65 +381,89 @@ CHWPRecordBorderFill::CHWPRecordBorderFill(CHWPDocInfo& oDocInfo, int nTagNum, i m_pFill = new CFill(oBuffer, 0, 0); // TODO:: перейти от использования off и size } -CHWPRecordBorderFill::CHWPRecordBorderFill(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion) +CHWPRecordBorderFill::CHWPRecordBorderFill(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion) : CHWPRecord(EHWPTag::HWPTAG_BORDER_FILL, 0, 0), m_pFill(nullptr) { - m_bThreeD = oNode.GetAttributeBool(L"threeD"); - m_bShadow = oNode.GetAttributeBool(L"shadow"); - m_bBreakCellSeparateLine = oNode.GetAttributeBool(L"breakCellSeparateLine"); - - HWP_STRING sChildName; - - for (CXMLNode& oChild : oNode.GetChilds()) + START_READ_ATTRIBUTES(oReader) { - if (L"hh:slash" == oChild.GetName()) + if ("threeD" == sAttributeName) + m_bThreeD = oReader.GetBool(); + else if ("shadow" == sAttributeName) + m_bShadow = oReader.GetBool(); + else if ("breakCellSeparateLine" == sAttributeName) + m_bBreakCellSeparateLine = oReader.GetBool(); + } + END_READ_ATTRIBUTES(oReader) + + std::string sNodeName; + WHILE_READ_NEXT_NODE(oReader) + { + sNodeName = oReader.GetNameA(); + + if ("hh:slash" == sNodeName) { - HWP_STRING sType = oChild.GetAttribute(L"type"); + START_READ_ATTRIBUTES(oReader) + { + if ("type" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - if (L"NONE" == sType) - m_chSlash = 0x0; - else if (L"CENTER" == sType) - m_chSlash = 0b010; - else if (L"CENTER_BELOW" == sType) - m_chSlash = 0b011; - else if (L"CENTER_ABOVE" == sType) - m_chSlash = 0b110; - else if (L"ALL" == sType) - m_chSlash = 0b111; - - m_chCrookedSlash = oChild.GetAttributeBool(L"Crooked"); - m_bCounterSlash = oChild.GetAttributeBool(L"isCounter"); + if ("NONE" == sType) + m_chSlash = 0x0; + else if ("CENTER" == sType) + m_chSlash = 0b010; + else if ("CENTER_BELOW" == sType) + m_chSlash = 0b011; + else if ("CENTER_ABOVE" == sType) + m_chSlash = 0b110; + else if ("ALL" == sType) + m_chSlash = 0b111; + } + else if ("Crooked" == sAttributeName) + m_chCrookedSlash = oReader.GetBool(); + else if ("isCounter" == sAttributeName) + m_bCounterSlash = oReader.GetBool(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hh:backSlash" == oChild.GetName()) + else if ("hh:backSlash" == sNodeName) { - HWP_STRING sType = oChild.GetAttribute(L"type"); + START_READ_ATTRIBUTES(oReader) + { + if ("type" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - if (L"NONE" == sType) - m_chBackSlash = 0x0; - else if (L"CENTER" == sType) - m_chBackSlash = 0b010; - else if (L"CENTER_BELOW" == sType) - m_chBackSlash = 0b011; - else if (L"CENTER_ABOVE" == sType) - m_chBackSlash = 0b110; - else if (L"ALL" == sType) - m_chBackSlash = 0b111; - - m_chCrookedBackSlash = oChild.GetAttributeBool(L"Crooked"); - m_bCounterBackSlash = oChild.GetAttributeBool(L"isCounter"); + if ("NONE" == sType) + m_chBackSlash = 0x0; + else if ("CENTER" == sType) + m_chBackSlash = 0b010; + else if ("CENTER_BELOW" == sType) + m_chBackSlash = 0b011; + else if ("CENTER_ABOVE" == sType) + m_chBackSlash = 0b110; + else if ("ALL" == sType) + m_chBackSlash = 0b111; + } + else if ("Crooked" == sAttributeName) + m_chCrookedBackSlash = oReader.GetBool(); + else if ("isCounter" == sAttributeName) + m_bCounterBackSlash = oReader.GetBool(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hh:leftBorder" == oChild.GetName()) - m_oLeft.ReadFromNode(oChild); - else if (L"hh:rightBorder" == oChild.GetName()) - m_oRight.ReadFromNode(oChild); - else if (L"hh:topBorder" == oChild.GetName()) - m_oTop.ReadFromNode(oChild); - else if (L"hh:bottomBorder" == oChild.GetName()) - m_oBottom.ReadFromNode(oChild); - else if (L"hh:diagonal" == oChild.GetName()) - m_oDiagonal.ReadFromNode(oChild); - else if (L"hc:fillBrush" == oChild.GetName()) - m_pFill = new CFill(oChild); + else if ("hh:leftBorder" == sNodeName) + m_oLeft.Read(oReader); + else if ("hh:rightBorder" == sNodeName) + m_oRight.Read(oReader); + else if ("hh:topBorder" == sNodeName) + m_oTop.Read(oReader); + else if ("hh:bottomBorder" == sNodeName) + m_oBottom.Read(oReader); + else if ("hh:diagonal" == sNodeName) + m_oDiagonal.Read(oReader); + else if ("hc:fillBrush" == sNodeName) + m_pFill = new CFill(oReader); } } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.h b/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.h index b84dbab16f..3b3557a60a 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.h +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.h @@ -4,7 +4,7 @@ #include "../HWPDocInfo.h" #include "HwpRecordTypes.h" #include "../HWPStream.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" #include namespace HWP @@ -15,7 +15,7 @@ struct TBorder HWP_BYTE m_chWidth; int m_nColor; - void ReadFromNode(CXMLNode& oNode); + void Read(CXMLReader& oReader); }; enum class EImageFillType @@ -86,13 +86,13 @@ class CFill : public IRef HWP_BYTE m_chAlpha; - void ReadWinBrush(CXMLNode& oNode); - void ReadGradation(CXMLNode& oNode); - void ReadImgBrush(CXMLNode& oNode); + void ReadWinBrush(CXMLReader& oReader); + void ReadGradation(CXMLReader& oReader); + void ReadImgBrush(CXMLReader& oReader); public: CFill(); CFill(CHWPStream& oBuffer, int nOff, int nSize); - CFill(CXMLNode& oNode); + CFill(CXMLReader& oReader); int GetSize() const; bool NoneFill() const; @@ -136,7 +136,7 @@ class CHWPRecordBorderFill : public CHWPRecord public: CHWPRecordBorderFill(int nTagNum, int nLevel, int nSize); CHWPRecordBorderFill(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CHWPRecordBorderFill(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion); + CHWPRecordBorderFill(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion); ~CHWPRecordBorderFill(); TBorder GetLeftBorder() const; diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.cpp index 91ee5db3a3..76d5b790ac 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.cpp @@ -45,25 +45,43 @@ CHWPRecordBullet::CHWPRecordBullet(CHWPDocInfo& oDocInfo, int nTagNum, int nLeve oBuffer.ReadChar(m_chCheckBulletChar); } -CHWPRecordBullet::CHWPRecordBullet(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion) +CHWPRecordBullet::CHWPRecordBullet(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion) : CHWPRecord(EHWPTag::HWPTAG_BULLET, 0, 0), m_pParent(&oDocInfo) { - std::wstring wsAttributeValue = oNode.GetAttribute(L"char"); - - if (!wsAttributeValue.empty()) - m_chBulletChar = wsAttributeValue.at(0); - - wsAttributeValue = oNode.GetAttribute(L"checkedChar"); - - if (!wsAttributeValue.empty()) - m_chCheckBulletChar = wsAttributeValue.at(0); - - m_nBulletImage = oNode.GetAttributeInt(L"useImage"); - - for (CXMLNode& oChild : oNode.GetChilds()) + START_READ_ATTRIBUTES(oReader) { - if (L"hc:img" == oChild.GetName()) - m_sBinItemRefID = oChild.GetAttribute(L"binaryItemIDRef"); + if ("char" == sAttributeName) + { + const HWP_STRING wsValue{oReader.GetText2()}; + + if (!wsValue.empty()) + m_chBulletChar = wsValue.at(0); + } + else if ("checkedChar" == sAttributeName) + { + const HWP_STRING wsValue{oReader.GetText2()}; + + if (!wsValue.empty()) + m_chCheckBulletChar = wsValue.at(0); + } + else if ("useImage" == sAttributeName) + m_nBulletImage = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + + WHILE_READ_NEXT_NODE(oReader) + { + if ("hc:img" != oReader.GetNameA()) + continue; + + START_READ_ATTRIBUTES(oReader) + { + if ("binaryItemIDRef" != sAttributeName) + continue; + + m_sBinItemRefID = oReader.GetText2(); + } + END_READ_ATTRIBUTES(oReader) } } } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.h b/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.h index 2037770d04..ac11bcbdfe 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.h +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.h @@ -5,7 +5,7 @@ #include "../HWPStream.h" #include "../HWPDocInfo.h" #include "HWPRecordNumbering.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -24,7 +24,7 @@ class CHWPRecordBullet : public CHWPRecord HWP_CHAR m_chCheckBulletChar; public: CHWPRecordBullet(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CHWPRecordBullet(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion); + CHWPRecordBullet(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion); }; } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.cpp index 3c472815f3..9d60028cc9 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.cpp @@ -107,15 +107,29 @@ EShadow GetShadow(const HWP_STRING& sValue) ELSE_STRING_IN_ENUM(NONE, EShadow); } -void CHWPRecordCharShape::ReadContainerData(CXMLNode& oNode, short arValues[], int nDefaultValue) +void CHWPRecordCharShape::ReadContainerData(CXMLReader& oReader, short arValues[], int nDefaultValue) { - arValues[(int)ELang::HANGUL] = oNode.GetAttributeInt(L"hangul", nDefaultValue); - arValues[(int)ELang::LATIN] = oNode.GetAttributeInt(L"latin", nDefaultValue); - arValues[(int)ELang::HANJA] = oNode.GetAttributeInt(L"hanja", nDefaultValue); - arValues[(int)ELang::JAPANESE] = oNode.GetAttributeInt(L"japanese", nDefaultValue); - arValues[(int)ELang::OTHER] = oNode.GetAttributeInt(L"other", nDefaultValue); - arValues[(int)ELang::SYMBOL] = oNode.GetAttributeInt(L"symbol", nDefaultValue); - arValues[(int)ELang::USER] = oNode.GetAttributeInt(L"user", nDefaultValue); + for (unsigned int unIndex = 0; unIndex < (int)ELang::MAX; ++unIndex) + arValues[unIndex] = nDefaultValue; + + START_READ_ATTRIBUTES(oReader) + { + if ("hangul" == sAttributeName) + arValues[(int)ELang::HANGUL] = oReader.GetInt(); + else if ("latin" == sAttributeName) + arValues[(int)ELang::LATIN] = oReader.GetInt(); + else if ("hanja" == sAttributeName) + arValues[(int)ELang::HANJA] = oReader.GetInt(); + else if ("japanese" == sAttributeName) + arValues[(int)ELang::JAPANESE] = oReader.GetInt(); + else if ("other" == sAttributeName) + arValues[(int)ELang::OTHER] = oReader.GetInt(); + else if ("symbol" == sAttributeName) + arValues[(int)ELang::SYMBOL] = oReader.GetInt(); + else if ("user" == sAttributeName) + arValues[(int)ELang::USER] = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } CHWPRecordCharShape::CHWPRecordCharShape(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) @@ -194,101 +208,138 @@ CHWPRecordCharShape::CHWPRecordCharShape(CHWPDocInfo& oDocInfo, int nTagNum, int oBuffer.RemoveLastSavedPos(); } -CHWPRecordCharShape::CHWPRecordCharShape(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion) +CHWPRecordCharShape::CHWPRecordCharShape(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion) : CHWPRecord(EHWPTag::HWPTAG_HWP_CHAR_SHAPE, 0, 0), m_pParent(&oDocInfo), - m_bItalic(false), m_bBold(false), m_bEmboss(false), m_bEngrave(false), - m_bSuperScript(false), m_bSubScript(false) + m_nHeight(1000), m_bItalic(false), m_bBold(false), m_eUnderline(EUnderline::NONE), + m_eUnderLineShape(ELineStyle1::SOLID), m_eOutline(EOutline::NONE), m_eShadow(EShadow::NONE), m_bEmboss(false), m_bEngrave(false), + m_bSuperScript(false), m_bSubScript(false), m_eStrikeOutShape(ELineStyle2::NONE), m_nShadeColor(0xFFFFFFFF) { - m_eUnderline = EUnderline::NONE; - m_eUnderLineShape = ELineStyle1::SOLID; - m_eOutline = EOutline::NONE; - m_eShadow = EShadow::NONE; - m_eStrikeOutShape = ELineStyle2::NONE; - - m_nHeight = oNode.GetAttributeInt(L"height", 1000); - m_nTextColor = oNode.GetAttributeColor(L"textColor", 0x000000); - m_nShadeColor = oNode.GetAttributeColor(L"shadeColor", 0xFFFFFFFF); - m_bUseFontSpace = oNode.GetAttributeBool(L"useFontSpace"); - m_bUseKerning = oNode.GetAttributeBool(L"useKerning"); - - m_eSymMark = GetAccent(oNode.GetAttribute(L"symMark")); - - m_shBorderFillIDRef = oNode.GetAttributeInt(L"borderFillIDRef"); - - for (CXMLNode& oChild : oNode.GetChilds()) + START_READ_ATTRIBUTES(oReader) { - if (L"hh:fontRef" == oChild.GetName()) + if ("height" == sAttributeName) + m_nHeight = oReader.GetInt(); + else if ("textColor" == sAttributeName) + m_nTextColor = oReader.GetColor(); + else if ("shadeColor" == sAttributeName) + m_nShadeColor = oReader.GetColor(0xFFFFFFFF); + else if ("useFontSpace" == sAttributeName) + m_bUseFontSpace = oReader.GetBool(); + else if ("useKerning" == sAttributeName) + m_bUseKerning = oReader.GetBool(); + else if ("symMark" == sAttributeName) + m_eSymMark = GetAccent(oReader.GetText2()); + else if ("borderFillIDRef" == sAttributeName) + m_shBorderFillIDRef = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + + std::string sNodeName; + WHILE_READ_NEXT_NODE(oReader) + { + sNodeName = oReader.GetNameA(); + + if ("hh:fontRef" == sNodeName) { if (nullptr == m_pParent) continue; const CHWPRecordFaceName* pFaceName = nullptr; - #define UPDATE_FACENAME(node_name, elang_type) \ - pFaceName = dynamic_cast(m_pParent->GetFaceName(oChild.GetAttributeInt(node_name))); \ - if (nullptr != pFaceName) \ - m_arFontNames[(int)elang_type] = pFaceName->GetFaceName() + #define UPDATE_FACENAME(elang_type)\ + {\ + pFaceName = dynamic_cast(m_pParent->GetFaceName(oReader.GetInt()));\ + if (nullptr != pFaceName)\ + m_arFontNames[(int)elang_type] = pFaceName->GetFaceName();\ + } - UPDATE_FACENAME(L"hangul", ELang::HANGUL); - UPDATE_FACENAME(L"latin", ELang::LATIN); - UPDATE_FACENAME(L"hanja", ELang::HANJA); - UPDATE_FACENAME(L"japanese", ELang::JAPANESE); - UPDATE_FACENAME(L"other", ELang::OTHER); - UPDATE_FACENAME(L"symbol", ELang::SYMBOL); - UPDATE_FACENAME(L"user", ELang::USER); + START_READ_ATTRIBUTES(oReader) + { + if ("hangul" == sAttributeName) + UPDATE_FACENAME(ELang::HANGUL) + else if ("latin" == sAttributeName) + UPDATE_FACENAME(ELang::LATIN) + else if ("hanja" == sAttributeName) + UPDATE_FACENAME(ELang::HANJA) + else if ("japanese" == sAttributeName) + UPDATE_FACENAME(ELang::JAPANESE) + else if ("other" == sAttributeName) + UPDATE_FACENAME(ELang::OTHER) + else if ("symbol" == sAttributeName) + UPDATE_FACENAME(ELang::SYMBOL) + else if ("user" == sAttributeName) + UPDATE_FACENAME(ELang::USER) + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hh:ratio" == oChild.GetName()) - ReadContainerData(oChild, m_arRatios, 100); - else if (L"hh:spacing" == oChild.GetName()) - ReadContainerData(oChild, m_arSpacings); - else if (L"hh:relSz" == oChild.GetName()) - ReadContainerData(oChild, m_arRelSizes, 100); - else if (L"hh:offset" == oChild.GetName()) - ReadContainerData(oChild, m_arCharOffset); - else if (L"hh:underline" == oChild.GetName()) + else if ("hh:ratio" == sNodeName) + ReadContainerData(oReader, m_arRatios, 100); + else if ("hh:spacing" == sNodeName) + ReadContainerData(oReader, m_arSpacings); + else if ("hh:relSz" == sNodeName) + ReadContainerData(oReader, m_arRelSizes, 100); + else if ("hh:offset" == sNodeName) + ReadContainerData(oReader, m_arCharOffset); + else if ("hh:underline" == sNodeName) { - m_eUnderline = GetUnderline(oChild.GetAttribute(L"type")); - m_eUnderLineShape = GetLineStyle1(oChild.GetAttribute(L"shape")); - m_nUnderlineColor = oChild.GetAttributeColor(L"color"); + START_READ_ATTRIBUTES(oReader) + { + if ("type" == sAttributeName) + m_eUnderline = GetUnderline(oReader.GetText2()); + else if ("shape" == sAttributeName) + m_eUnderLineShape = GetLineStyle1(oReader.GetText2()); + else if ("color" == sAttributeName) + m_nUnderlineColor = oReader.GetColor(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hh:strikeout" == oChild.GetName()) + else if ("hh:strikeout" == sNodeName) { - m_eStrikeOutShape = GetLineStyle2(oChild.GetAttribute(L"shape")); - m_nStrikeOutColor = oChild.GetAttributeColor(L"color"); + START_READ_ATTRIBUTES(oReader) + { + if ("shape" == sAttributeName) + m_eStrikeOutShape = GetLineStyle2(oReader.GetText2()); + else if ("color" == sAttributeName) + m_nStrikeOutColor = oReader.GetColor(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hh:outline" == sNodeName) + m_eOutline = GetOutline(oReader.GetAttribute("type")); + else if ("hh:shadow" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("type" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - if (L"3D" == oChild.GetAttribute(L"shape")) - m_eStrikeOutShape = ELineStyle2::NONE; + if ("DROP" == sType) + m_eShadow = EShadow::DISCRETE; + else if ("CONTINUOUS" == sType) + m_eShadow = EShadow::CONTINUOUS; + else + m_eShadow = EShadow::NONE; + } + else if ("color" == sAttributeName) + m_nShadowColor = oReader.GetColor(); + else if ("offsetX" == sAttributeName) + m_chShadowOffsetX = (HWP_BYTE)oReader.GetInt(); + else if ("offsetY" == sAttributeName) + m_chShadowOffsetY = (HWP_BYTE)oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hh:outline" == oChild.GetName()) - { - m_eOutline = GetOutline(oChild.GetAttribute(L"type")); - } - else if (L"hh:shadow" == oChild.GetName()) - { - HWP_STRING sType = oChild.GetAttribute(L"type"); - - if (L"DROP" == sType) - m_eShadow = EShadow::DISCRETE; - else if (L"CONTINUOUS" == sType) - m_eShadow = EShadow::CONTINUOUS; - else - m_eShadow = EShadow::NONE; - - m_nShadowColor = oChild.GetAttributeColor(L"color"); - m_chShadowOffsetX = (HWP_BYTE)oChild.GetAttributeInt(L"offsetX"); - m_chShadowOffsetY = (HWP_BYTE)oChild.GetAttributeInt(L"offsetY"); - } - else if (L"hh:italic" == oChild.GetName()) + else if ("hh:italic" == sNodeName) m_bItalic = true; - else if (L"hh:bold" == oChild.GetName()) + else if ("hh:bold" == sNodeName) m_bBold = true; - else if (L"hh:emboss" == oChild.GetName()) + else if ("hh:emboss" == sNodeName) m_bEmboss = true; - else if (L"hh:engrave" == oChild.GetName()) - m_bEmboss = true; - else if (L"hh:supscript" == oChild.GetName()) + else if ("hh:engrave" == sNodeName) + m_bEngrave = true; + else if ("hh:supscript" == sNodeName) m_bSuperScript = true; - else if (L"hh:subscript" == oChild.GetName()) + else if ("hh:subscript" == sNodeName) m_bSubScript = true; } } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.h b/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.h index d33a066452..4ebee45ba3 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.h +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordCharShape.h @@ -5,7 +5,7 @@ #include "../HWPStream.h" #include "HWPRecord.h" #include "HwpRecordTypes.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -100,10 +100,10 @@ class CHWPRecordCharShape : public CHWPRecord short m_shBorderFillIDRef; int m_nStrikeOutColor; - void ReadContainerData(CXMLNode& oNode, short arValues[], int nDefaultValue = 0); + void ReadContainerData(CXMLReader& oReader, short arValues[], int nDefaultValue = 0); public: CHWPRecordCharShape(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CHWPRecordCharShape(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion); + CHWPRecordCharShape(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion); bool Bold() const; bool Italic() const; diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordDocumentProperties.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordDocumentProperties.cpp index cada1bee0e..b68d223b3c 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordDocumentProperties.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordDocumentProperties.cpp @@ -16,14 +16,24 @@ CHWPRecordDocumentProperties::CHWPRecordDocumentProperties(CHWPDocInfo& oDocInfo oBuffer.ReadInt(m_nCharUnitLocInPara); } -CHWPRecordDocumentProperties::CHWPRecordDocumentProperties(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion) +CHWPRecordDocumentProperties::CHWPRecordDocumentProperties(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion) : CHWPRecord(EHWPTag::HWPTAG_DOCUMENT_PROPERTIES, 0, 0), m_pParent(&oDocInfo) { - m_shFigureStartNo = oNode.GetAttributeInt(L"page"); - m_shFootNoteStartNo = oNode.GetAttributeInt(L"footnote"); - m_shEndNoteStartNo = oNode.GetAttributeInt(L"endnote"); - m_shFigureStartNo = oNode.GetAttributeInt(L"pic"); - m_shTableStartNo = oNode.GetAttributeInt(L"tbl"); - m_shEqStartNo = oNode.GetAttributeInt(L"equation"); + START_READ_ATTRIBUTES(oReader) + { + if ("page" == sAttributeName) + m_shPageStartNo = oReader.GetInt(); + else if ("footnote" == sAttributeName) + m_shFootNoteStartNo = oReader.GetInt(); + else if ("endnote" == sAttributeName) + m_shEndNoteStartNo = oReader.GetInt(); + else if ("pic" == sAttributeName) + m_shFigureStartNo = oReader.GetInt(); + else if ("tbl" == sAttributeName) + m_shTableStartNo = oReader.GetInt(); + else if ("equation" == sAttributeName) + m_shEqStartNo = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordDocumentProperties.h b/HwpFile/HwpDoc/HWPElements/HWPRecordDocumentProperties.h index ab2dd86a1f..5693b1c55c 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordDocumentProperties.h +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordDocumentProperties.h @@ -4,7 +4,7 @@ #include "../HWPDocInfo.h" #include "../HWPStream.h" #include "HWPRecord.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -24,7 +24,7 @@ class CHWPRecordDocumentProperties : public CHWPRecord int m_nCharUnitLocInPara; public: CHWPRecordDocumentProperties(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CHWPRecordDocumentProperties(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion); + CHWPRecordDocumentProperties(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion); }; } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordFaceName.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordFaceName.cpp index 4652f37580..94a7b9dde4 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordFaceName.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordFaceName.cpp @@ -53,45 +53,72 @@ CHWPRecordFaceName::CHWPRecordFaceName(CHWPDocInfo& oDocInfo, int nTagNum, int n oBuffer.ReadString(m_sBasicFaceName, EStringCharacter::UTF16); } -CHWPRecordFaceName::CHWPRecordFaceName(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion) +CHWPRecordFaceName::CHWPRecordFaceName(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion) : CHWPRecord(EHWPTag::HWPTAG_FACE_NAME, 0, 0), m_pParent(&oDocInfo) { - m_sFaceName = oNode.GetAttribute(L"face"); + m_sFaceName = oReader.GetAttribute("face"); - for (CXMLNode& oChild: oNode.GetChilds()) + std::string sNodeName; + + WHILE_READ_NEXT_NODE(oReader) { - if (L"hh:substFont" == oChild.GetName()) + sNodeName = oReader.GetNameA(); + + if ("hh:substFont" == sNodeName) { m_bSubstExists = true; - m_sSubstFace = oChild.GetAttribute(L"face"); - HWP_STRING sType = oChild.GetAttribute(L"type"); + START_READ_ATTRIBUTES(oReader) + { + if ("face" == sAttributeName) + m_sSubstFace = oReader.GetText2(); + else if ("type" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - if (L"TTF" == sType) - m_eSubstType = EAltType::FFT; - else if (L"HFT" == sType) - m_eSubstType = EAltType::HFT; - else - m_eSubstType = EAltType::UNKNOWN; + if ("TTF" == sType) + m_eSubstType = EAltType::FFT; + else if ("HFT" == sType) + m_eSubstType = EAltType::HFT; + else + m_eSubstType = EAltType::UNKNOWN; + } + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hh:typeInfo" == oChild.GetName()) + else if ("hh:typeInfo" == sNodeName) { m_bAttrExists = true; - m_sBasicFaceName = oChild.GetAttribute(L"familyType"); + START_READ_ATTRIBUTES(oReader) + { + if ("familyType" == sAttributeName) + { + m_sBasicFaceName = oReader.GetText2(); - if (!m_sBasicFaceName.empty()) - m_bBasicFaceExists = true; - - m_chSerifStyle = (HWP_BYTE)oChild.GetAttributeInt(L"serifStyle"); - m_shWeight = oChild.GetAttributeInt(L"weight"); - m_shPropotion = oChild.GetAttributeInt(L"proportion"); - m_shContrast = oChild.GetAttributeInt(L"contrast"); - m_shStrokeVariation = oChild.GetAttributeInt(L"strokeVariation"); - m_shArmStyle = oChild.GetAttributeInt(L"armStyle"); - m_shLetterform = oChild.GetAttributeInt(L"letterform"); - m_shMidLine = oChild.GetAttributeInt(L"midline"); - m_shXHeight = oChild.GetAttributeInt(L"xHeight"); + if (!m_sBasicFaceName.empty()) + m_bBasicFaceExists = true; + } + else if ("serifStyle" == sAttributeName) + m_chSerifStyle = (HWP_BYTE)oReader.GetInt(); + else if ("weight" == sAttributeName) + m_shWeight = oReader.GetInt(); + else if ("proportion" == sAttributeName) + m_shPropotion = oReader.GetInt(); + else if ("contrast" == sAttributeName) + m_shContrast = oReader.GetInt(); + else if ("strokeVariation" == sAttributeName) + m_shStrokeVariation = oReader.GetInt(); + else if ("armStyle" == sAttributeName) + m_shArmStyle = oReader.GetInt(); + else if ("letterform" == sAttributeName) + m_shLetterform = oReader.GetInt(); + else if ("midline" == sAttributeName) + m_shMidLine = oReader.GetInt(); + else if ("xHeight" == sAttributeName) + m_shXHeight = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } } } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordFaceName.h b/HwpFile/HwpDoc/HWPElements/HWPRecordFaceName.h index cad477eb29..7db968951c 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordFaceName.h +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordFaceName.h @@ -1,7 +1,7 @@ #ifndef HWPRECORDFACENAME_H #define HWPRECORDFACENAME_H -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" #include "../HWPDocInfo.h" #include "../HWPStream.h" #include "HWPRecord.h" @@ -41,7 +41,7 @@ class CHWPRecordFaceName : public CHWPRecord short m_shXHeight; public: CHWPRecordFaceName(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CHWPRecordFaceName(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion); + CHWPRecordFaceName(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion); HWP_STRING GetFaceName() const; }; diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordNumbering.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordNumbering.cpp index 76ad9df268..24ab2ac9b9 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordNumbering.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordNumbering.cpp @@ -54,52 +54,70 @@ CHWPRecordNumbering::CHWPRecordNumbering(CHWPDocInfo& oDocInfo, int nTagNum, int oBuffer.RemoveLastSavedPos(); } -CHWPRecordNumbering::CHWPRecordNumbering(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion) +CHWPRecordNumbering::CHWPRecordNumbering(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion) : CHWPRecord(EHWPTag::HWPTAG_NUMBERING, 0, 0), m_pParent(&oDocInfo) { - m_shStart = oNode.GetAttributeInt(L"start", 1); + m_shStart = oReader.GetAttributeInt("start", 1); unsigned int unIndex = 0; - HWP_STRING sType; + short shLevel = 0; + std::string sNodeName, sNumFormat; - for (CXMLNode& oChild : oNode.GetChilds()) + WHILE_READ_NEXT_NODE(oReader) { - if (L"hh:paraHead" == oChild.GetName() || - L"paraHead" == oChild.GetName()) + sNodeName = oReader.GetNameA(); + + if ("hh:paraHead" == sNodeName || + "paraHead" == sNodeName) { - sType = oChild.GetAttribute(L"align"); + START_READ_ATTRIBUTES(oReader) + { + if ("align" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - if (L"LEFT" == sType) - m_arNumbering[unIndex].m_chAlign = 0; - else if (L"CENTER" == sType) - m_arNumbering[unIndex].m_chAlign = 1; - else if (L"RIGHT" == sType) - m_arNumbering[unIndex].m_chAlign = 2; + if ("LEFT" == sType) + m_arNumbering[unIndex].m_chAlign = 0; + else if ("CENTER" == sType) + m_arNumbering[unIndex].m_chAlign = 1; + else if ("RIGHT" == sType) + m_arNumbering[unIndex].m_chAlign = 2; + } + else if ("useInstWidth" == sAttributeName) + m_arNumbering[unIndex].m_bUseInstWidth = oReader.GetBool(); + else if ("autoIndent" == sAttributeName) + m_arNumbering[unIndex].m_bAutoIndent = oReader.GetBool(); + else if ("widthAdjust" == sAttributeName) + m_arNumbering[unIndex].m_shWidthAdjust = oReader.GetInt(); + else if ("textOffsetType" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - m_arNumbering[unIndex].m_bUseInstWidth = oChild.GetAttributeBool(L"useInstWidth"); - m_arNumbering[unIndex].m_bAutoIndent = oChild.GetAttributeBool(L"autoIndent"); - m_arNumbering[unIndex].m_shWidthAdjust = oChild.GetAttributeInt(L"widthAdjust"); + if ("PERCENT" == sType) + m_arNumbering[unIndex].m_chTextOffsetType = 0; + else if ("HWPUNIT" == sType) + m_arNumbering[unIndex].m_chTextOffsetType = 1; + } + else if ("textOffset" == sAttributeName) + m_arNumbering[unIndex].m_shTextOffset = oReader.GetInt(); + else if ("charPrIDRef" == sAttributeName) + m_arNumbering[unIndex].m_nCharShape = std::abs(oReader.GetInt()); + else if ("start" == sAttributeName) + m_arNumbering[unIndex].m_nStartNumber = oReader.GetInt(); + else if ("numFormat" == sAttributeName) + sNumFormat = oReader.GetText2A(); + else if ("level" == sAttributeName) + shLevel = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) - sType = oChild.GetAttribute(L"textOffsetType"); - - if (L"PERCENT" == sType) - m_arNumbering[unIndex].m_chTextOffsetType = 0; - else if (L"HWPUNIT" == sType) - m_arNumbering[unIndex].m_chTextOffsetType = 1; - - m_arNumbering[unIndex].m_shTextOffset = oChild.GetAttributeInt(L"textOffset"); - - short shLevel = oChild.GetAttributeInt(L"level"); - - sType = oChild.GetAttribute(L"numFormat"); - - if (L"DIGIT" == sType) + if ("DIGIT" == sNumFormat) { if (shLevel > 0 && shLevel < 11) m_arNumbering[unIndex].m_sNumFormat = L'^' + std::to_wstring(shLevel) + L'.'; } - else if (L"HANGUL_SYLLABLE" == sType || - L"HANGUL_JAMO" == sType) + else if ("HANGUL_SYLLABLE" == sNumFormat || + "HANGUL_JAMO" == sNumFormat) { switch (shLevel) { @@ -115,7 +133,7 @@ CHWPRecordNumbering::CHWPRecordNumbering(CHWPDocInfo& oDocInfo, CXMLNode& oNode, case 10: m_arNumbering[unIndex].m_sNumFormat = L"^차."; break; } } - else if (L"CIRCLED_DIGIT" == sType) + else if ("CIRCLED_DIGIT" == sNumFormat) { switch (shLevel) { @@ -131,7 +149,7 @@ CHWPRecordNumbering::CHWPRecordNumbering(CHWPDocInfo& oDocInfo, CXMLNode& oNode, case 10: m_arNumbering[unIndex].m_sNumFormat = L"^\u2469."; break; } } - else if (L"LATIN_SMALL" == sType) + else if ("LATIN_SMALL" == sNumFormat) { switch (shLevel) { @@ -147,7 +165,7 @@ CHWPRecordNumbering::CHWPRecordNumbering(CHWPDocInfo& oDocInfo, CXMLNode& oNode, case 10: m_arNumbering[unIndex].m_sNumFormat = L"^j."; break; } } - else if (L"CIRCLED_HANGUL_SYLLABLE" == sType) + else if ("CIRCLED_HANGUL_SYLLABLE" == sNumFormat) { switch (shLevel) { @@ -163,7 +181,7 @@ CHWPRecordNumbering::CHWPRecordNumbering(CHWPDocInfo& oDocInfo, CXMLNode& oNode, case 10: m_arNumbering[unIndex].m_sNumFormat = L"^\u3277."; break; } } - else if (L"ROMAN_SMALL" == sType) + else if ("ROMAN_SMALL" == sNumFormat) { switch (shLevel) { @@ -180,8 +198,6 @@ CHWPRecordNumbering::CHWPRecordNumbering(CHWPDocInfo& oDocInfo, CXMLNode& oNode, } } - m_arNumbering[unIndex].m_nCharShape = std::abs(oChild.GetAttributeInt(L"charPrIDRef")); - m_arNumbering[unIndex].m_nStartNumber = oChild.GetAttributeInt(L"start"); ++unIndex; } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordNumbering.h b/HwpFile/HwpDoc/HWPElements/HWPRecordNumbering.h index 6798cad30a..4e19482b56 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordNumbering.h +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordNumbering.h @@ -4,7 +4,7 @@ #include "../HWPDocInfo.h" #include "../HWPStream.h" #include "HWPRecord.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -36,7 +36,7 @@ class CHWPRecordNumbering : public CHWPRecord int m_arExtLevelStart[3]; public: CHWPRecordNumbering(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CHWPRecordNumbering(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion); + CHWPRecordNumbering(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion); short GetStart() const; HWP_STRING GetNumFormat(unsigned short ushIndex) const; diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordParaShape.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordParaShape.cpp index e28e664422..830d9e521b 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordParaShape.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordParaShape.cpp @@ -131,115 +131,171 @@ CHWPRecordParaShape::CHWPRecordParaShape(CHWPDocInfo& oDocInfo, int nTagNum, int oBuffer.Skip(8); } -CHWPRecordParaShape::CHWPRecordParaShape(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion) +CHWPRecordParaShape::CHWPRecordParaShape(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion) : CHWPRecord(EHWPTag::HWPTAG_PARA_SHAPE, 0, 0), m_pParent(&oDocInfo), m_eAlign(EHorizontalAlign::JUSTIFY), m_bWidowOrphan(false), m_bKeepWithNext(false), m_bPageBreakBefore(false), m_eVertAlign(EVerticalAlign::BASELINE), m_eHeadingType(EHeadingType::NONE), m_bConnect(false), m_bIgnoreMargin(false), m_bParaTailShape(false) { - m_shTabDef = oNode.GetAttributeInt(L"tabPrIDRef"); - m_chCondense = (HWP_BYTE)oNode.GetAttributeInt(L"condense"); + START_READ_ATTRIBUTES(oReader) + { + if ("tabPrIDRef" == sAttributeName) + m_shTabDef = oReader.GetInt(); + else if ("condense" == sAttributeName) + m_chCondense = (HWP_BYTE)oReader.GetInt(); + else if ("fontLineHeight" == sAttributeName) + m_bFontLineHeight = oReader.GetBool(); + else if ("snapToGrid" == sAttributeName) + m_bSnapToGrid = oReader.GetBool(); + } + END_READ_ATTRIBUTES(oReader) - m_bFontLineHeight = oNode.GetAttributeBool(L"fontLineHeight"); - m_bSnapToGrid = oNode.GetAttributeBool(L"snapToGrid"); - - for (CXMLNode& oChild : oNode.GetChilds()) - RecursiveParaShape(oChild); + WHILE_READ_NEXT_NODE(oReader) + RecursiveParaShape(oReader); } -void CHWPRecordParaShape::RecursiveParaShape(CXMLNode& oNode) +void CHWPRecordParaShape::RecursiveParaShape(CXMLReader& oReader) { - if (L"hh:align" == oNode.GetName()) + std::string sNodeName; + + WHILE_READ_NEXT_NODE(oReader) { - m_eAlign = ::HWP::GetHorizontalAlign(oNode.GetAttribute(L"horizontal")); - m_eVertAlign = ::HWP::GetVerticalAlign(oNode.GetAttribute(L"vertical")); - } - else if (L"hh:heading" == oNode.GetName()) - { - m_eHeadingType = ::HWP::GetHeadingType(oNode.GetAttribute(L"type")); - m_shHeadingIdRef = oNode.GetAttributeInt(L"idRef"); - m_chHeadingLevel = (HWP_BYTE)oNode.GetAttributeInt(L"level"); - } - else if (L"hh:breakSetting" == oNode.GetName()) - { - HWP_STRING sType = oNode.GetAttribute(L"breakLatinWord"); + sNodeName = oReader.GetNameA(); - if (L"KEEP_WORD" == sType) - m_chBreakLatinWord = 0; - else if (L"BREAK_WORD" == sType) - m_chBreakLatinWord = 1; + if ("hh:align" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("horizontal" == sAttributeName) + m_eAlign = ::HWP::GetHorizontalAlign(oReader.GetText2()); + else if ("vertical" == sAttributeName) + m_eVertAlign = ::HWP::GetVerticalAlign(oReader.GetText2()); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hh:heading" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("type" == sAttributeName) + m_eHeadingType = ::HWP::GetHeadingType(oReader.GetText2()); + else if ("idRef" == sAttributeName) + m_shHeadingIdRef = oReader.GetInt(); + else if ("level" == sAttributeName) + m_chHeadingLevel = (HWP_BYTE)oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hh:breakSetting" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("breakLatinWord" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - sType = oNode.GetAttribute(L"breakNonLatinWord"); + if ("KEEP_WORD" == sType) + m_chBreakLatinWord = 0; + else if ("BREAK_WORD" == sType) + m_chBreakLatinWord = 1; + } + else if ("breakNonLatinWord" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - if (L"KEEP_WORD" == sType) - m_chBreakNonLatinWord = 0; - else if (L"BREAK_WORD" == sType) - m_chBreakNonLatinWord = 1; + if ("KEEP_WORD" == sType) + m_chBreakNonLatinWord = 0; + else if ("BREAK_WORD" == sType) + m_chBreakNonLatinWord = 1; + } + else if ("widowOrphan" == sAttributeName) + m_bWidowOrphan = oReader.GetBool(); + else if ("keepWithNext" == sAttributeName) + m_bKeepWithNext = oReader.GetBool(); + else if ("pageBreakBefore" == sAttributeName) + m_bPageBreakBefore = oReader.GetBool(); + else if ("lineWrap" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - m_bWidowOrphan = oNode.GetAttributeBool(L"widowOrphan"); - m_bKeepWithNext = oNode.GetAttributeBool(L"keepWithNext"); - m_bPageBreakBefore = oNode.GetAttributeBool(L"pageBreakBefore"); + if ("BREAK" == sType) + m_chLineWrap = 0; + else if ("SQUEEZE" == sType) + m_chLineWrap = 1; + } + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hh:lineSpacing" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("type" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - sType = oNode.GetAttribute(L"lineWrap"); - - if (L"BREAK" == sType) - m_chLineWrap = 0; - else if (L"SQUEEZE" == sType) - m_chLineWrap = 1; - } - else if (L"hh:lineSpacing" == oNode.GetName()) - { - HWP_STRING sType = oNode.GetAttribute(L"type"); - - if (L"PERCENT" == sType) - m_nLineSpacingType = 0; - else if (L"FIXED" == sType) - m_nLineSpacingType = 1; - else if (L"BETWEENLINES" == sType) - m_nLineSpacingType = 2; - else if (L"AT_LEAST" == sType) - m_nLineSpacingType = 4; - - m_nLineSpacing = oNode.GetAttributeInt(L"value"); - } - else if (L"hh:border" == oNode.GetName()) - { - m_shBorderFill = oNode.GetAttributeInt(L"borderFillIDRef"); - m_shOffsetLeft = oNode.GetAttributeInt(L"offsetLeft"); - m_shOffsetRight = oNode.GetAttributeInt(L"offsetRight"); - m_shOffsetTop = oNode.GetAttributeInt(L"offsetTop"); - m_shOffsetBottom = oNode.GetAttributeInt(L"offsetBottom"); - - m_bConnect = oNode.GetAttributeBool(L"connect"); - m_bIgnoreMargin = oNode.GetAttributeBool(L"ignoreMargin"); - } - else if (L"hh:autoSpacing" == oNode.GetName()) - { - m_bAutoSpaceEAsianEng = oNode.GetAttributeBool(L"eAsianEng"); - m_bAutoSpaceEAsianNum = oNode.GetAttributeBool(L"eAsianNum"); - } - else if (L"hc:intent" == oNode.GetName()) - m_nIndent = oNode.GetAttributeInt(L"value"); - else if (L"hc:left" == oNode.GetName()) - m_nMarginLeft = oNode.GetAttributeInt(L"value"); - else if (L"hc:right" == oNode.GetName()) - m_nMarginRight = oNode.GetAttributeInt(L"value"); - else if (L"hc:prev" == oNode.GetName()) - m_nMarginPrev = oNode.GetAttributeInt(L"value"); - else if (L"hc:next" == oNode.GetName()) - m_nMarginNext = oNode.GetAttributeInt(L"value"); - else if (/*L"hp:switch" == oNode.GetName() || - L"hp:case" == oNode.GetName() || - L"hp:default" == oNode.GetName() ||*/ - L"hh:margin" == oNode.GetName()) - { - for (CXMLNode& oChild : oNode.GetChilds()) - RecursiveParaShape(oChild); - } - else if (L"hp:switch" == oNode.GetName()) - { - for (CXMLNode& oChild : oNode.GetChild(L"hp:default").GetChilds()) - RecursiveParaShape(oChild); + if ("PERCENT" == sType) + m_nLineSpacingType = 0; + else if ("FIXED" == sType) + m_nLineSpacingType = 1; + else if ("BETWEENLINES" == sType) + m_nLineSpacingType = 2; + else if ("AT_LEAST" == sType) + m_nLineSpacingType = 4; + } + else if ("value" == sAttributeName) + m_nLineSpacing = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hh:border" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("borderFillIDRef" == sAttributeName) + m_shBorderFill = oReader.GetInt(); + else if ("offsetLeft" == sAttributeName) + m_shOffsetLeft = oReader.GetInt(); + else if ("offsetRight" == sAttributeName) + m_shOffsetRight = oReader.GetInt(); + else if ("offsetTop" == sAttributeName) + m_shOffsetTop = oReader.GetInt(); + else if ("offsetBottom" == sAttributeName) + m_shOffsetBottom = oReader.GetInt(); + else if ("connect" == sAttributeName) + m_bConnect = oReader.GetBool(); + else if ("ignoreMargin" == sAttributeName) + m_bIgnoreMargin = oReader.GetBool(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hh:autoSpacing" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("eAsianEng" == sAttributeName) + m_bAutoSpaceEAsianEng = oReader.GetBool(); + else if ("eAsianNum" == sAttributeName) + m_bAutoSpaceEAsianNum = oReader.GetBool(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hc:intent" == sNodeName) + m_nIndent = oReader.GetAttributeInt("value"); + else if ("hc:left" == sNodeName) + m_nMarginLeft = oReader.GetAttributeInt("value"); + else if ("hc:right" == sNodeName) + m_nMarginRight = oReader.GetAttributeInt("value"); + else if ("hc:prev" == sNodeName) + m_nMarginPrev = oReader.GetAttributeInt("value"); + else if ("hc:next" == sNodeName) + m_nMarginNext = oReader.GetAttributeInt("value"); + else if ("hh:margin" == sNodeName || + "hp:switch" == sNodeName) + { + WHILE_READ_NEXT_NODE(oReader) + RecursiveParaShape(oReader); + } } } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordParaShape.h b/HwpFile/HwpDoc/HWPElements/HWPRecordParaShape.h index b2fe087dbe..35ea0b9587 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordParaShape.h +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordParaShape.h @@ -3,7 +3,7 @@ #include "HWPRecord.h" #include "../HWPDocInfo.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -74,10 +74,10 @@ class CHWPRecordParaShape : public CHWPRecord bool m_bAutoSpaceEAsianNum; int m_nLineSpacingType; - void RecursiveParaShape(CXMLNode& oNode); + void RecursiveParaShape(CXMLReader& oReader); public: CHWPRecordParaShape(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CHWPRecordParaShape(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion); + CHWPRecordParaShape(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion); EHorizontalAlign GetHorizantalAlign() const; EVerticalAlign GetVerticalAlign() const; diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordStyle.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordStyle.cpp index c287a95034..ecb12eaeac 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordStyle.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordStyle.cpp @@ -20,23 +20,36 @@ CHWPRecordStyle::CHWPRecordStyle(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, m_nCharShape = oBuffer.ReadShort(); } -CHWPRecordStyle::CHWPRecordStyle(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion) +CHWPRecordStyle::CHWPRecordStyle(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion) : CHWPRecord(EHWPTag::HWPTAG_STYLE, 0, 0), m_pParent(&oDocInfo) { - HWP_STRING sType = oNode.GetAttribute(L"type"); + START_READ_ATTRIBUTES(oReader) + { + if ("type" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - if (L"PARA" == sType) - m_chType = 0; - else if (L"CHAR" == sType) - m_chType = 1; - - m_sName = oNode.GetAttribute(L"name"); - m_sEngName = oNode.GetAttribute(L"engName"); - m_nParaShape = oNode.GetAttributeInt(L"paraPrIDRef"); - m_nCharShape = oNode.GetAttributeInt(L"charPrIDRef"); - m_chNextStyle = oNode.GetAttributeInt(L"nextStyleIDRef"); - m_shLangID = oNode.GetAttributeInt(L"langID"); - m_bLockForm = oNode.GetAttributeBool(L"lockForm"); + if ("PARA" == sType) + m_chType = 0; + else if ("CHAR" == sType) + m_chType = 1; + } + else if ("name" == sAttributeName) + m_sName = oReader.GetText2(); + else if ("engName" == sAttributeName) + m_sEngName = oReader.GetText2(); + else if ("paraPrIDRef" == sAttributeName) + m_nParaShape = oReader.GetInt(); + else if ("charPrIDRef" == sAttributeName) + m_nCharShape = oReader.GetInt(); + else if ("nextStyleIDRef" == sAttributeName) + m_chNextStyle = oReader.GetInt(); + else if ("langID" == sAttributeName) + m_shLangID = oReader.GetInt(); + else if ("lockForm" == sAttributeName) + m_bLockForm = oReader.GetBool(); + } + END_READ_ATTRIBUTES(oReader) } HWP_STRING CHWPRecordStyle::GetName() const diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordStyle.h b/HwpFile/HwpDoc/HWPElements/HWPRecordStyle.h index 6715dce63f..cf1c8eb341 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordStyle.h +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordStyle.h @@ -3,7 +3,7 @@ #include "HWPRecord.h" #include "../HWPDocInfo.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -22,7 +22,7 @@ class CHWPRecordStyle : public CHWPRecord public: CHWPRecordStyle(int nTagNum, int nLevel, int nSize); CHWPRecordStyle(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CHWPRecordStyle(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion); + CHWPRecordStyle(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion); HWP_STRING GetName() const; HWP_STRING GetEngName() const; diff --git a/HwpFile/HwpDoc/HWPElements/HwpRecordTabDef.cpp b/HwpFile/HwpDoc/HWPElements/HwpRecordTabDef.cpp index 26d9237bf7..cf2b9514c4 100644 --- a/HwpFile/HwpDoc/HWPElements/HwpRecordTabDef.cpp +++ b/HwpFile/HwpDoc/HWPElements/HwpRecordTabDef.cpp @@ -5,11 +5,18 @@ namespace HWP TTab::TTab() {} -TTab::TTab(CXMLNode& oNode) +TTab::TTab(CXMLReader& oReader) { - m_nPos = oNode.GetAttributeInt(L"pos"); - SetType(oNode.GetAttributeInt(L"type")); - m_eLeader = GetLineStyle2(oNode.GetAttribute(L"leader")); + START_READ_ATTRIBUTES(oReader) + { + if ("pos" == sAttributeName) + m_nPos = oReader.GetInt(); + else if ("type" == sAttributeName) + SetType(oReader.GetInt()); + else if ("leader" == sAttributeName) + m_eLeader = GetLineStyle2(oReader.GetText2()); + } + END_READ_ATTRIBUTES(oReader) } void TTab::SetType(int nValue) @@ -24,7 +31,7 @@ void TTab::SetType(int nValue) } CHwpRecordTabDef::CHwpRecordTabDef(int nTagNum, int nLevel, int nSize) - : CHWPRecord(nTagNum, nLevel, nSize), m_pParent(nullptr) + : CHWPRecord(nTagNum, nLevel, nSize), m_pParent(nullptr), m_nAttr(0), m_nCount(0) {} CHwpRecordTabDef::CHwpRecordTabDef(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) @@ -60,25 +67,35 @@ CHwpRecordTabDef::CHwpRecordTabDef(CHWPDocInfo& oDocInfo, int nTagNum, int nLeve oBuffer.RemoveLastSavedPos(); } -CHwpRecordTabDef::CHwpRecordTabDef(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion) - : CHWPRecord(EHWPTag::HWPTAG_TAB_DEF, 0, 0), m_pParent(&oDocInfo) +CHwpRecordTabDef::CHwpRecordTabDef(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion) + : CHWPRecord(EHWPTag::HWPTAG_TAB_DEF, 0, 0), m_pParent(&oDocInfo), m_nAttr(0), m_nCount(0) { - if (oNode.GetAttributeBool(L"autoTabLeft")) - m_nAttr |= 0x00000001; - else - m_nAttr &= 0xFFFFFFFE; - - if (oNode.GetAttributeBool(L"autoTabRight")) - m_nAttr |= 0x00000002; - else - m_nAttr &= 0xFFFFFFFD; - - for (CXMLNode& oChild : oNode.GetChilds(L"hp:switch")) - for (CXMLNode& oGrandChild : oChild.GetChilds(L"hp:default")) + START_READ_ATTRIBUTES(oReader) + { + if ("autoTabLeft" == sAttributeName) { - CXMLNode oTabItem{oGrandChild.GetChild(L"hh:tabItem")}; - m_arTabs.push_back(new TTab(oTabItem)); + if (oReader.GetBool()) + m_nAttr |= 0x00000001; + else + m_nAttr &= 0xFFFFFFFE; } + else if ("autoTabRight" == sAttributeName) + { + if (oReader.GetBool()) + m_nAttr |= 0x00000002; + else + m_nAttr &= 0xFFFFFFFD; + } + } + END_READ_ATTRIBUTES(oReader) + + WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "hp:switch") + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Child, "hp:default") + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, TabChild, "hh:tabItem") + m_arTabs.push_back(new TTab(oReader)); + END_WHILE + END_WHILE + END_WHILE } int CHwpRecordTabDef::GetCount() const diff --git a/HwpFile/HwpDoc/HWPElements/HwpRecordTabDef.h b/HwpFile/HwpDoc/HWPElements/HwpRecordTabDef.h index 4e28d7d914..b649656f5e 100644 --- a/HwpFile/HwpDoc/HWPElements/HwpRecordTabDef.h +++ b/HwpFile/HwpDoc/HWPElements/HwpRecordTabDef.h @@ -4,7 +4,7 @@ #include "HWPRecord.h" #include "../HWPDocInfo.h" #include "HwpRecordTypes.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -22,7 +22,7 @@ struct TTab TTab(); - TTab(CXMLNode& oNode); + TTab(CXMLReader& oReader); void SetType(int nValue); }; @@ -37,7 +37,7 @@ class CHwpRecordTabDef : public CHWPRecord public: CHwpRecordTabDef(int nTagNum, int nLevel, int nSize); CHwpRecordTabDef(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CHwpRecordTabDef(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion); + CHwpRecordTabDef(CHWPDocInfo& oDocInfo, CXMLReader& oReader, int nVersion); int GetCount() const; const TTab* GetTab(unsigned int unIndex) const; diff --git a/HwpFile/HwpDoc/HWPSection.cpp b/HwpFile/HwpDoc/HWPSection.cpp index 342a2dd04a..19849f704d 100644 --- a/HwpFile/HwpDoc/HWPSection.cpp +++ b/HwpFile/HwpDoc/HWPSection.cpp @@ -111,14 +111,11 @@ CHWPSection::~CHWPSection() CLEAR_ARRAY(CHWPPargraph, m_arParas); } -bool CHWPSection::Parse(CXMLNode& oNode, int nVersion) +bool CHWPSection::Parse(CXMLReader& oReader, int nVersion) { - std::vector arParagraphNodes{oNode.GetChilds(L"hp:p")}; - - m_arParas.resize(arParagraphNodes.size()); - - for (unsigned int unIndex = 0; unIndex < arParagraphNodes.size(); ++unIndex) - m_arParas[unIndex] = new CHWPPargraph(arParagraphNodes[unIndex], nVersion); + WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "hp:p") + m_arParas.push_back(new CHWPPargraph(oReader, nVersion)); + END_WHILE return true; } diff --git a/HwpFile/HwpDoc/HWPSection.h b/HwpFile/HwpDoc/HWPSection.h index dbeb8ffd24..6b362ab5ef 100644 --- a/HwpFile/HwpDoc/HWPSection.h +++ b/HwpFile/HwpDoc/HWPSection.h @@ -16,7 +16,7 @@ public: CHWPSection(); ~CHWPSection(); - bool Parse(CXMLNode& oNode, int nVersion); + bool Parse(CXMLReader& oReader, int nVersion); bool Parse(CHWPStream& oBuffer, int nVersion); int ParseRecurse(CHWPPargraph* oCurrPara, int nRunLevel, CHWPStream& oBuffer, int nOff, int nVersion); int ParseCtrlRecurse(CCtrl* oCurrCtrl, int nRunLevel, CHWPStream& oBuffer, int nOff, int nVersion); diff --git a/HwpFile/HwpDoc/HWPXFile.cpp b/HwpFile/HwpDoc/HWPXFile.cpp index 19377036d8..cf663fda23 100644 --- a/HwpFile/HwpDoc/HWPXFile.cpp +++ b/HwpFile/HwpDoc/HWPXFile.cpp @@ -116,7 +116,8 @@ VECTOR CHWPXFile::GetPathsToSections() const bool CHWPXFile::GetFileHeader() { CXMLNode oVersionXml{GetDocument(L"version.xml")}; - return m_oFileHeader.Parse(oVersionXml); + CXMLReader oReader{GetDocument(L"version.xml")}; + return m_oFileHeader.Parse(oReader); } const CHWPDocInfo* CHWPXFile::GetDocInfo() const @@ -146,11 +147,11 @@ bool CHWPXFile::GetChildStream(const HWP_STRING& sFileName, CHWPStream& oBuffer) bool CHWPXFile::GetDocInfo(int nVersion) { - CXMLNode oContent{GetDocument(L"Contents/content.hpf")}; - if (m_oDocInfo.ReadContentHpf(oContent, nVersion)) + CXMLReader oContentReader{GetDocument(L"Contents/content.hpf")}; + if (m_oDocInfo.ReadContentHpf(oContentReader, nVersion)) { - CXMLNode oHeader{GetDocument(L"Contents/header.xml")}; - return m_oDocInfo.Parse(oHeader, nVersion); + CXMLReader oHeaderReader{GetDocument(L"Contents/header.xml")}; + return m_oDocInfo.Parse(oHeaderReader, nVersion); } return false; @@ -158,10 +159,10 @@ bool CHWPXFile::GetDocInfo(int nVersion) bool CHWPXFile::ReadSection(const HWP_STRING& sName, int nVersion) { - CXMLNode oRootNode{GetDocument(sName)}; + CXMLReader oReader{GetDocument(sName)}; CHWPSection* pSection = new CHWPSection(); - const bool bResult = pSection->Parse(oRootNode, nVersion); + const bool bResult = pSection->Parse(oReader, nVersion); if (bResult) m_arSections.push_back(pSection); @@ -171,11 +172,34 @@ bool CHWPXFile::ReadSection(const HWP_STRING& sName, int nVersion) return bResult; } -CXMLNode CHWPXFile::GetDocument(const HWP_STRING& sEntryName) +CXMLReader CHWPXFile::GetDocument(const HWP_STRING& sEntryName) { if (nullptr == m_pZipFolder) - return CXMLNode(); + return CXMLReader(); - return CXMLNode(m_pZipFolder->getNodeFromFile(sEntryName)); + XmlUtils::CXmlLiteReader oTempReader{m_pZipFolder->getReaderFromFile(sEntryName)}; + + std::cout << oTempReader.GetNameA() << std::endl; + + if (oTempReader.IsValid()) + std::cout << "Valid" << std::endl; + else + std::cout << "No valid" << std::endl; + + oTempReader.ReadNextNode(); + + if (oTempReader.IsValid()) + std::cout << "Valid" << std::endl; + else + std::cout << "No valid" << std::endl; + + std::wcout << oTempReader.GetDepth() << L" _ " << oTempReader.GetName() << std::endl; + + CXMLReader oReader(oTempReader); + + std::wcout << oReader.GetInnerXml() << std::endl; + + + return oReader; } } diff --git a/HwpFile/HwpDoc/HWPXFile.h b/HwpFile/HwpDoc/HWPXFile.h index 867ad4cff4..88af44470b 100644 --- a/HwpFile/HwpDoc/HWPXFile.h +++ b/HwpFile/HwpDoc/HWPXFile.h @@ -32,7 +32,7 @@ private: bool GetFileHeader(); bool GetDocInfo(int nVersion); bool ReadSection(const HWP_STRING& sName, int nVersion); - CXMLNode GetDocument(const HWP_STRING& sEntryName); + CXMLReader GetDocument(const HWP_STRING& sEntryName); }; } diff --git a/HwpFile/HwpDoc/HwpFileHeader.cpp b/HwpFile/HwpDoc/HwpFileHeader.cpp index 7a5655eeed..3d6c723f89 100644 --- a/HwpFile/HwpDoc/HwpFileHeader.cpp +++ b/HwpFile/HwpDoc/HwpFileHeader.cpp @@ -60,15 +60,30 @@ bool CHwpFileHeader::Parse(CHWPStream& oBuffer) return true; } -bool CHwpFileHeader::Parse(CXMLNode& oNode) +bool CHwpFileHeader::Parse(CXMLReader& oReader) { - if (!oNode.IsValid()) + if (!oReader.IsValid()) return false; - m_sVersion += oNode.GetAttribute(L"major"); - m_sVersion += oNode.GetAttribute(L"minor"); - m_sVersion += oNode.GetAttribute(L"micro"); - m_sVersion += oNode.GetAttribute(L"buildNumber"); + HWP_STRING wsMajor, wsMinor, wsMicro, wsBuildNumber; + + START_READ_ATTRIBUTES(oReader) + { + if ("major" == sAttributeName) + wsMajor = oReader.GetText2(); + else if ("minor" == sAttributeName) + wsMinor = oReader.GetText2(); + else if ("micro" == sAttributeName) + wsMicro = oReader.GetText2(); + else if ("buildNumber" == sAttributeName) + wsBuildNumber = oReader.GetText2(); + } + END_READ_ATTRIBUTES(oReader) + + m_sVersion = ((!wsMajor.empty()) ? wsMajor : L"0") + + ((!wsMinor.empty()) ? wsMinor : L"0") + + ((!wsMicro.empty()) ? wsMicro : L"0") + + ((!wsBuildNumber.empty()) ? wsBuildNumber : L"0"); return true; } diff --git a/HwpFile/HwpDoc/HwpFileHeader.h b/HwpFile/HwpDoc/HwpFileHeader.h index 54103ca9c8..497f1ce23f 100644 --- a/HwpFile/HwpDoc/HwpFileHeader.h +++ b/HwpFile/HwpDoc/HwpFileHeader.h @@ -2,7 +2,7 @@ #define HWPFILEHEADER_H #include "HWPStream.h" -#include "Common/XMLNode.h" +#include "Common/XMLReader.h" namespace HWP { @@ -47,7 +47,7 @@ public: HWP_STRING GetVersion() const; bool Parse(CHWPStream& oBuffer); - bool Parse(CXMLNode& oNode); + bool Parse(CXMLReader& oReader); }; } diff --git a/HwpFile/HwpDoc/Paragraph/CapParagraph.cpp b/HwpFile/HwpDoc/Paragraph/CapParagraph.cpp index 144d56c1f5..493b92882c 100644 --- a/HwpFile/HwpDoc/Paragraph/CapParagraph.cpp +++ b/HwpFile/HwpDoc/Paragraph/CapParagraph.cpp @@ -6,8 +6,8 @@ CCapParagraph::CCapParagraph() : CHWPPargraph() {} -CCapParagraph::CCapParagraph(CXMLNode& oNode, int nVersion) - : CHWPPargraph(oNode, nVersion) +CCapParagraph::CCapParagraph(CXMLReader& oReader, int nVersion) + : CHWPPargraph(oReader, nVersion) {} EParagraphType CCapParagraph::GetType() const diff --git a/HwpFile/HwpDoc/Paragraph/CapParagraph.h b/HwpFile/HwpDoc/Paragraph/CapParagraph.h index a107e66b0f..09d1bae865 100644 --- a/HwpFile/HwpDoc/Paragraph/CapParagraph.h +++ b/HwpFile/HwpDoc/Paragraph/CapParagraph.h @@ -9,7 +9,7 @@ class CCapParagraph : public CHWPPargraph { public: CCapParagraph(); - CCapParagraph(CXMLNode& oNode, int nVersion); + CCapParagraph(CXMLReader& oReader, int nVersion); EParagraphType GetType() const override; }; diff --git a/HwpFile/HwpDoc/Paragraph/CellParagraph.cpp b/HwpFile/HwpDoc/Paragraph/CellParagraph.cpp index 8087a97027..b68ad224e9 100644 --- a/HwpFile/HwpDoc/Paragraph/CellParagraph.cpp +++ b/HwpFile/HwpDoc/Paragraph/CellParagraph.cpp @@ -7,8 +7,8 @@ CCellParagraph::CCellParagraph() { } -CCellParagraph::CCellParagraph(CXMLNode& oNode, int nVersion) - : CHWPPargraph(oNode, nVersion) +CCellParagraph::CCellParagraph(CXMLReader& oReader, int nVersion) + : CHWPPargraph(oReader, nVersion) {} EParagraphType CCellParagraph::GetType() const diff --git a/HwpFile/HwpDoc/Paragraph/CellParagraph.h b/HwpFile/HwpDoc/Paragraph/CellParagraph.h index 8f24372d76..267f6b539d 100644 --- a/HwpFile/HwpDoc/Paragraph/CellParagraph.h +++ b/HwpFile/HwpDoc/Paragraph/CellParagraph.h @@ -9,7 +9,7 @@ class CCellParagraph : public CHWPPargraph { public: CCellParagraph(); - CCellParagraph(CXMLNode& oNode, int nVersion); + CCellParagraph(CXMLReader& oReader, int nVersion); EParagraphType GetType() const override; }; diff --git a/HwpFile/HwpDoc/Paragraph/CommonObj.h b/HwpFile/HwpDoc/Paragraph/CommonObj.h index c6794c4f15..dee4dd99e5 100644 --- a/HwpFile/HwpDoc/Paragraph/CommonObj.h +++ b/HwpFile/HwpDoc/Paragraph/CommonObj.h @@ -2,9 +2,6 @@ #define COMMONOBJ_H #include "HWPPargraph.h" -#include -#include -#include namespace HWP { diff --git a/HwpFile/HwpDoc/Paragraph/Ctrl.cpp b/HwpFile/HwpDoc/Paragraph/Ctrl.cpp index 8257483ed0..3ecefd7705 100644 --- a/HwpFile/HwpDoc/Paragraph/Ctrl.cpp +++ b/HwpFile/HwpDoc/Paragraph/Ctrl.cpp @@ -50,27 +50,29 @@ bool CCtrl::Equals(CCtrl* pFirstCtrl, CCtrl* pSecondCtrl) pFirstCtrl->m_bFullFilled == pSecondCtrl->m_bFullFilled; } -CCtrl* CCtrl::GetCtrl(CXMLNode& oNode, int nVersion) +CCtrl* CCtrl::GetCtrl(CXMLReader& oReader, int nVersion) { - if (L"hp:colPr" == oNode.GetName()) - return new CCtrlColumnDef(L"dloc", oNode, nVersion); - else if (L"hp:header" == oNode.GetName()) - return new CCtrlHeadFoot(L"daeh", oNode, nVersion); - else if (L"hp:footer" == oNode.GetName()) - return new CCtrlHeadFoot(L"toof", oNode, nVersion); - else if (L"hp:footNote" == oNode.GetName()) - return new CCtrlNote(L" nf", oNode, nVersion); - else if (L"hp:endNote" == oNode.GetName()) - return new CCtrlNote(L" ne", oNode, nVersion); - else if (L"hp:autoNum" == oNode.GetName()) - return new CCtrlAutoNumber(L"onta", oNode, nVersion); - else if (L"hp:newNum" == oNode.GetName()) - return new CCtrlNewNumber(L"onwn", oNode, nVersion); - else if (L"hp:pageNum" == oNode.GetName()) - return new CCtrlPageNumPos(L"pngp", oNode, nVersion); - else if (L"hp:fieldBegin" == oNode.GetName() || - L"hp:fieldEnd" == oNode.GetName()) - return new CCtrlField(L"", oNode, nVersion); + const std::string sNodeName{oReader.GetNameA()}; + + if ("hp:colPr" == sNodeName) + return new CCtrlColumnDef(L"dloc", oReader, nVersion); + else if ("hp:header" == sNodeName) + return new CCtrlHeadFoot(L"daeh", oReader, nVersion); + else if ("hp:footer" == sNodeName) + return new CCtrlHeadFoot(L"toof", oReader, nVersion); + else if ("hp:footNote" == sNodeName) + return new CCtrlNote(L" nf", oReader, nVersion); + else if ("hp:endNote" == sNodeName) + return new CCtrlNote(L" ne", oReader, nVersion); + else if ("hp:autoNum" == sNodeName) + return new CCtrlAutoNumber(L"onta", oReader, nVersion); + else if ("hp:newNum" == sNodeName) + return new CCtrlNewNumber(L"onwn", oReader, nVersion); + else if ("hp:pageNum" == sNodeName) + return new CCtrlPageNumPos(L"pngp", oReader, nVersion); + else if ("hp:fieldBegin" == sNodeName || + "hp:fieldEnd" == sNodeName) + return new CCtrlField(L"", oReader, nVersion); return nullptr; } diff --git a/HwpFile/HwpDoc/Paragraph/Ctrl.h b/HwpFile/HwpDoc/Paragraph/Ctrl.h index ae50822346..3f61ef7970 100644 --- a/HwpFile/HwpDoc/Paragraph/Ctrl.h +++ b/HwpFile/HwpDoc/Paragraph/Ctrl.h @@ -2,7 +2,7 @@ #define CTRL_H #include "../Common/Common.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -46,7 +46,7 @@ public: void SetFullFilled(); static bool Equals(CCtrl* pFirstCtrl, CCtrl* pSecondCtrl); - static CCtrl* GetCtrl(CXMLNode& oNode, int nVersion); + static CCtrl* GetCtrl(CXMLReader& oReader, int nVersion); }; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.cpp b/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.cpp index fdab363ca2..aeb903fdd3 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.cpp @@ -44,57 +44,63 @@ CCtrlAutoNumber::CCtrlAutoNumber(const HWP_STRING& sCtrlID, int nSize, CHWPStrea m_bFullFilled = true; } -CCtrlAutoNumber::CCtrlAutoNumber(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) +CCtrlAutoNumber::CCtrlAutoNumber(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) : CCtrl(sCtrlID) { - m_eNumType = ::HWP::GetNumType(oNode.GetAttribute(L"numType")); + m_eNumType = ::HWP::GetNumType(oReader.GetAttribute("numType")); - HWP_STRING sType; - - for (CXMLNode& oChild : oNode.GetChilds()) + WHILE_READ_NEXT_NODE(oReader) { - m_bSuperscript = oChild.GetAttributeBool(L"supscript"); + START_READ_ATTRIBUTES(oReader) + { + if ("supscript" == sAttributeName) + m_bSuperscript = oReader.GetBool(); + else if ("type" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - sType = oChild.GetAttribute(L"type"); - - if (L"DIGIT" == sType) - m_eNumShape = ENumberShape2::DIGIT; - else if (L"CIRCLE_DIGIT" == sType) - m_eNumShape = ENumberShape2::CIRCLE_DIGIT; - else if (L"ROMAN_CAPITAL" == sType) - m_eNumShape = ENumberShape2::ROMAN_CAPITAL; - else if (L"ROMAN_SMALL" == sType) - m_eNumShape = ENumberShape2::ROMAN_SMALL; - else if (L"LATIN_CAPITAL" == sType) - m_eNumShape = ENumberShape2::LATIN_CAPITAL; - else if (L"LATIN_SMALL" == sType) - m_eNumShape = ENumberShape2::LATIN_SMALL; - else if (L"CIRCLED_LATIN_CAPITAL" == sType) - m_eNumShape = ENumberShape2::CIRCLED_LATIN_CAPITAL; - else if (L"CIRCLED_LATIN_SMALL" == sType) - m_eNumShape = ENumberShape2::CIRCLED_LATIN_SMALL; - else if (L"CIRCLED_HANGUL_SYLLABLE" == sType) - m_eNumShape = ENumberShape2::CIRCLED_HANGUL_SYLLABLE; - else if (L"HANGUL_JAMO" == sType) - m_eNumShape = ENumberShape2::HANGUL_JAMO; - else if (L"CIRCLED_HANGUL_JAMO" == sType) - m_eNumShape = ENumberShape2::CIRCLED_HANGUL_JAMO; - else if (L"HANGUL_PHONETIC" == sType) - m_eNumShape = ENumberShape2::HANGUL_PHONETIC; - else if (L"IDEOGRAPH" == sType) - m_eNumShape = ENumberShape2::IDEOGRAPH; - else if (L"CIRCLED_IDEOGRAPH" == sType) - m_eNumShape = ENumberShape2::CIRCLED_IDEOGRAPH; - else if (L"DECAGON_CIRCLE" == sType) - m_eNumShape = ENumberShape2::DECAGON_CIRCLE; - else if (L"DECAGON_CRICLE_HANGJA" == sType) - m_eNumShape = ENumberShape2::DECAGON_CRICLE_HANGJA; - else if (L"SYMBOL" == sType) - m_eNumShape = ENumberShape2::SYMBOL; - else if (L"USER_CHAR" == sType) - m_eNumShape = ENumberShape2::USER_HWP_CHAR; - - m_eNumShape = GetNumberShape2(oChild.GetAttributeInt(L"hp:autoNumFormat", oChild.GetAttributeInt(L"autoNumFormat"))); + if ("DIGIT" == sType) + m_eNumShape = ENumberShape2::DIGIT; + else if ("CIRCLE_DIGIT" == sType) + m_eNumShape = ENumberShape2::CIRCLE_DIGIT; + else if ("ROMAN_CAPITAL" == sType) + m_eNumShape = ENumberShape2::ROMAN_CAPITAL; + else if ("ROMAN_SMALL" == sType) + m_eNumShape = ENumberShape2::ROMAN_SMALL; + else if ("LATIN_CAPITAL" == sType) + m_eNumShape = ENumberShape2::LATIN_CAPITAL; + else if ("LATIN_SMALL" == sType) + m_eNumShape = ENumberShape2::LATIN_SMALL; + else if ("CIRCLED_LATIN_CAPITAL" == sType) + m_eNumShape = ENumberShape2::CIRCLED_LATIN_CAPITAL; + else if ("CIRCLED_LATIN_SMALL" == sType) + m_eNumShape = ENumberShape2::CIRCLED_LATIN_SMALL; + else if ("CIRCLED_HANGUL_SYLLABLE" == sType) + m_eNumShape = ENumberShape2::CIRCLED_HANGUL_SYLLABLE; + else if ("HANGUL_JAMO" == sType) + m_eNumShape = ENumberShape2::HANGUL_JAMO; + else if ("CIRCLED_HANGUL_JAMO" == sType) + m_eNumShape = ENumberShape2::CIRCLED_HANGUL_JAMO; + else if ("HANGUL_PHONETIC" == sType) + m_eNumShape = ENumberShape2::HANGUL_PHONETIC; + else if ("IDEOGRAPH" == sType) + m_eNumShape = ENumberShape2::IDEOGRAPH; + else if ("CIRCLED_IDEOGRAPH" == sType) + m_eNumShape = ENumberShape2::CIRCLED_IDEOGRAPH; + else if ("DECAGON_CIRCLE" == sType) + m_eNumShape = ENumberShape2::DECAGON_CIRCLE; + else if ("DECAGON_CRICLE_HANGJA" == sType) + m_eNumShape = ENumberShape2::DECAGON_CRICLE_HANGJA; + else if ("SYMBOL" == sType) + m_eNumShape = ENumberShape2::SYMBOL; + else if ("USER_CHAR" == sType) + m_eNumShape = ENumberShape2::USER_HWP_CHAR; + } + else if ("hp:autoNumFormat" == sAttributeName || + "autoNumFormat" == sAttributeName) + m_eNumShape = GetNumberShape2(oReader.GetInt()); + } + END_READ_ATTRIBUTES(oReader) } m_bFullFilled = true; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.h b/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.h index 9b7906a5c8..29cd53f1c7 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlAutoNumber.h @@ -5,7 +5,7 @@ #include "../HWPStream.h" #include "../HWPElements/HwpRecordTypes.h" #include "../Common/Common.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -31,7 +31,7 @@ class CCtrlAutoNumber : public CCtrl public: CCtrlAutoNumber(const HWP_STRING& sCtrlID); CCtrlAutoNumber(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlAutoNumber(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlAutoNumber(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); ECtrlObjectType GetCtrlType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlColumnDef.cpp b/HwpFile/HwpDoc/Paragraph/CtrlColumnDef.cpp index fa69f62886..22228cb0f2 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlColumnDef.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlColumnDef.cpp @@ -40,12 +40,17 @@ CCtrlColumnDef::CCtrlColumnDef(const HWP_STRING& sCtrlID, int nSize, CHWPStream& m_bFullFilled = true; } -CCtrlColumnDef::CCtrlColumnDef(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrl(sCtrlID) +CCtrlColumnDef::CCtrlColumnDef(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrl(sCtrlID), m_eColLineStyle(ELineStyle2::SOLID) { - m_eColLineStyle = ELineStyle2::SOLID; - m_shColCount = oNode.GetAttributeInt(L"colCount"); - m_bSameSz = oNode.GetAttributeBool(L"sameSz"); + START_READ_ATTRIBUTES(oReader) + { + if ("colCount" == sAttributeName) + m_shColCount = oReader.GetInt(); + else if ("sameSz" == sAttributeName) + m_bSameSz = oReader.GetBool(); + } + END_READ_ATTRIBUTES(oReader) if (!m_bSameSz) { @@ -54,19 +59,35 @@ CCtrlColumnDef::CCtrlColumnDef(const HWP_STRING& sCtrlID, CXMLNode& oNode, int n } unsigned int unColSzIndex = 0; + std::string sNodeName; - for (CXMLNode& oChild : oNode.GetChilds()) + WHILE_READ_NEXT_NODE(oReader) { - if (L"hp:colLine" == oChild.GetName()) + sNodeName = oReader.GetNameA(); + + if ("hp:colLine" == sNodeName) { - m_eColLineStyle = GetLineStyle2(oChild.GetAttribute(L"type")); - m_chColLineWidth = (HWP_BYTE)ConvertWidthToHWP(oChild.GetAttribute(L"width")); - m_nColLineColor = oChild.GetAttributeColor(L"color"); + START_READ_ATTRIBUTES(oReader) + { + if ("type" == sAttributeName) + m_eColLineStyle = GetLineStyle2(oReader.GetText2()); + else if ("width" == sAttributeName) + m_chColLineWidth = (HWP_BYTE)ConvertWidthToHWP(oReader.GetText2A()); + else if ("color" == sAttributeName) + m_nColLineColor = oReader.GetColor(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hp:colSz" == oChild.GetName()) + else if ("hp:colSz" == sNodeName) { - m_arColSzWidths[unColSzIndex] = oChild.GetAttributeInt(L"width"); - m_arColSzGaps[unColSzIndex++] = oChild.GetAttributeInt(L"gap"); + START_READ_ATTRIBUTES(oReader) + { + if ("width" == sAttributeName) + m_arColSzWidths[unColSzIndex] = oReader.GetInt(); + else if ("gap" == sAttributeName) + m_arColSzGaps[unColSzIndex++] = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlColumnDef.h b/HwpFile/HwpDoc/Paragraph/CtrlColumnDef.h index 1ae218e8c4..268b94c829 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlColumnDef.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlColumnDef.h @@ -4,7 +4,7 @@ #include "../HWPElements/HwpRecordTypes.h" #include "../HWPStream.h" #include "Ctrl.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -22,7 +22,7 @@ class CCtrlColumnDef : public CCtrl public: CCtrlColumnDef(const HWP_STRING& sCtrlID); CCtrlColumnDef(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlColumnDef(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlColumnDef(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); ECtrlObjectType GetCtrlType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlCommon.cpp b/HwpFile/HwpDoc/Paragraph/CtrlCommon.cpp index e28b3671cb..6b14cd883c 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlCommon.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlCommon.cpp @@ -240,113 +240,182 @@ namespace HWP oBuffer.ReadString(m_sObjDesc, EStringCharacter::UTF16); } - CCtrlCommon::CCtrlCommon(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) + CCtrlCommon::CCtrlCommon(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) : CCtrl(sCtrlID), m_bTreatAsChar(false), m_eVertRelTo(EVRelTo::PARA), m_eHorzRelTo(EHRelTo::PARA), m_nVertOffset(0), m_nHorzOffset(0), m_nWidth(0), m_nHeight(0), m_arOutMargin{0, 0, 0, 0}, m_arInMargin{0, 0, 0, 0}, m_eTextVerAlign(EVertAlign::TOP) { - m_nObjInstanceID = std::abs(oNode.GetAttributeInt(L"id")); + std::string sType; - HWP_STRING sType = oNode.GetAttribute(L"textFlow"); - - if (L"BOTH_SIDES" == sType) - m_chTextFlow = 0; - else if (L"LEFT_ONLY" == sType) - m_chTextFlow = 1; - else if (L"RIGHT_ONLY" == sType) - m_chTextFlow = 2; - else if (L"LARGEST_ONLY" == sType) - m_chTextFlow = 3; - - sType = oNode.GetAttribute(L"textWrap"); - - if (L"SQUARE" == sType) - m_eTextWrap = ETextWrap::SQUARE; - else if (L"TOP_AND_BOTTOM" == sType) - m_eTextWrap = ETextWrap::TOP_AND_BOTTOM; - else if (L"BEHIND_TEXT" == sType) - m_eTextWrap = ETextWrap::BEHIND_TEXT; - else if (L"IN_FRONT_OF_TEXT" == sType) - m_eTextWrap = ETextWrap::IN_FRONT_OF_TEXT; - - m_nZOrder = oNode.GetAttributeInt(L"zOrder"); - - sType = oNode.GetAttribute(L"numberingType"); - - if (L"NONE" == sType) - m_chNumeringType = 0; - else if (L"PICTURE" == sType) - m_chNumeringType = 1; - else if (L"TABLE" == sType) - m_chNumeringType = 2; - else if (L"EQUATION" == sType) - m_chNumeringType = 3; - - for (CXMLNode& oChild : oNode.GetChilds()) + START_READ_ATTRIBUTES(oReader) { - if (L"hp:sz" == oChild.GetName()) + if ("id" == sAttributeName) + m_nObjInstanceID = std::abs(oReader.GetInt()); + else if ("textFlow" == sAttributeName) { - m_nWidth = oChild.GetAttributeInt(L"width"); - m_eWidthRelTo = ::HWP::GetWidthRelTo(oChild.GetAttribute(L"widthRelTo")); - m_nHeight = oChild.GetAttributeInt(L"height"); - m_eHeightRelTo = ::HWP::GetHeightRelTo(oChild.GetAttribute(L"heightRelTo")); + sType = oReader.GetText2A(); + + if ("BOTH_SIDES" == sType) + m_chTextFlow = 0; + else if ("LEFT_ONLY" == sType) + m_chTextFlow = 1; + else if ("RIGHT_ONLY" == sType) + m_chTextFlow = 2; + else if ("LARGEST_ONLY" == sType) + m_chTextFlow = 3; } - else if (L"hp:pos" == oChild.GetName()) + else if ("textWrap" == sAttributeName) { - m_bTreatAsChar = oChild.GetAttributeBool(L"treatAsChar"); + sType = oReader.GetText2A(); - if (m_bTreatAsChar) - m_bAffectLSpacing = oChild.GetAttributeBool(L"affectLSpacing"); - else - m_bAllowOverlap = oChild.GetAttributeBool(L"allowOverlap"); - - m_eVertRelTo = GetVRelTo(oChild.GetAttribute(L"vertRelTo")); - m_eHorzRelTo = GetHRelTo(oChild.GetAttribute(L"horzRelTo")); - - if (EVRelTo::PARA == m_eVertRelTo) - m_bFlowWithText = oChild.GetAttributeBool(L"flowWithText"); - - m_eVertAlign = GetVertAlign(oChild.GetAttribute(L"vertAlign")); - m_eHorzAlign = GetHorzAlign(oChild.GetAttribute(L"horzAlign")); - m_nVertOffset = oChild.GetAttributeInt(L"vertOffset"); - m_nHorzOffset = oChild.GetAttributeInt(L"horzOffset"); + if ("SQUARE" == sType) + m_eTextWrap = ETextWrap::SQUARE; + else if ("TOP_AND_BOTTOM" == sType) + m_eTextWrap = ETextWrap::TOP_AND_BOTTOM; + else if ("BEHIND_TEXT" == sType) + m_eTextWrap = ETextWrap::BEHIND_TEXT; + else if ("IN_FRONT_OF_TEXT" == sType) + m_eTextWrap = ETextWrap::IN_FRONT_OF_TEXT; } - else if (L"hp:outMargin" == oChild.GetName()) + else if ("zOrder" == sAttributeName) + m_nZOrder = oReader.GetInt(); + else if ("numberingType" == sAttributeName) { - m_arOutMargin[0] = oChild.GetAttributeInt(L"left"); - m_arOutMargin[1] = oChild.GetAttributeInt(L"right"); - m_arOutMargin[2] = oChild.GetAttributeInt(L"top"); - m_arOutMargin[3] = oChild.GetAttributeInt(L"bottom"); + sType = oReader.GetText2A(); + + if ("NONE" == sType) + m_chNumeringType = 0; + else if ("PICTURE" == sType) + m_chNumeringType = 1; + else if ("TABLE" == sType) + m_chNumeringType = 2; + else if ("EQUATION" == sType) + m_chNumeringType = 3; } - else if (L"hp:inMargin" == oChild.GetName()) + } + END_READ_ATTRIBUTES(oReader) + + std::string sNodeName; + + WHILE_READ_NEXT_NODE(oReader) + { + sNodeName = oReader.GetNameA(); + + if ("hp:sz" == sNodeName) { - m_arInMargin[0] = oChild.GetAttributeInt(L"left"); - m_arInMargin[1] = oChild.GetAttributeInt(L"right"); - m_arInMargin[2] = oChild.GetAttributeInt(L"top"); - m_arInMargin[3] = oChild.GetAttributeInt(L"bottom"); - } - else if (L"hp:caption" == oChild.GetName()) - { - HWP_STRING sType = oChild.GetAttribute(L"side"); - - if (L"LEFT" == sType) - m_nCaptionAttr = 0b00; - else if (L"RIGHT" == sType) - m_nCaptionAttr = 0b01; - else if (L"TOP" == sType) - m_nCaptionAttr = 0b10; - else if (L"BOTTOM" == sType) - m_nCaptionAttr = 0b11; - - if (oChild.GetAttributeBool(L"fullSz")) - m_nCaptionAttr |= 0b100; - - m_nCaptionWidth = oChild.GetAttributeInt(L"width"); - m_nCaptionSpacing = oChild.GetAttributeInt(L"gap"); - m_nCaptionMaxW = oChild.GetAttributeInt(L"lastWidth"); - - for (CXMLNode& oSubList : oChild.GetChilds(L"hp:subList")) + START_READ_ATTRIBUTES(oReader) { - for (CXMLNode& oParagraph : oSubList.GetChilds(L"hp:p")) - m_arCaption.push_back(new CCapParagraph(oParagraph, nVersion)); + if ("width" == sAttributeName) + m_nWidth = oReader.GetInt(); + else if ("widthRelTo" == sAttributeName) + m_eWidthRelTo = ::HWP::GetWidthRelTo(oReader.GetText2()); + else if ("height" == sAttributeName) + m_nHeight = oReader.GetInt(); + else if ("heightRelTo" == sAttributeName) + m_eHeightRelTo = ::HWP::GetHeightRelTo(oReader.GetText2()); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hp:pos" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("treatAsChar" == sAttributeName) + m_bTreatAsChar = oReader.GetBool(); + else if ("affectLSpacing" == sAttributeName) + m_bAffectLSpacing = oReader.GetBool(); + else if ("allowOverlap" == sAttributeName) + m_bAllowOverlap = oReader.GetBool(); + else if ("vertRelTo" == sAttributeName) + m_eVertRelTo = GetVRelTo(oReader.GetText2()); + else if ("horzRelTo" == sAttributeName) + m_eHorzRelTo = GetHRelTo(oReader.GetText2()); + else if ("flowWithText" == sAttributeName) + m_bFlowWithText = oReader.GetBool(); + else if ("vertAlign" == sAttributeName) + m_eVertAlign = GetVertAlign(oReader.GetText2()); + else if ("horzAlign" == sAttributeName) + m_eHorzAlign = GetHorzAlign(oReader.GetText2()); + else if ("vertOffset" == sAttributeName) + m_nVertOffset = oReader.GetInt(); + else if ("horzOffset" == sAttributeName) + m_nHorzOffset = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hp:outMargin" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("left" == sAttributeName) + m_arOutMargin[0] = oReader.GetInt(); + else if ("right" == sAttributeName) + m_arOutMargin[1] = oReader.GetInt(); + else if ("top" == sAttributeName) + m_arOutMargin[2] = oReader.GetInt(); + else if ("bottom" == sAttributeName) + m_arOutMargin[3] = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hp:inMargin" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("left" == sAttributeName) + m_arInMargin[0] = oReader.GetInt(); + else if ("right" == sAttributeName) + m_arInMargin[1] = oReader.GetInt(); + else if ("top" == sAttributeName) + m_arInMargin[2] = oReader.GetInt(); + else if ("bottom" == sAttributeName) + m_arInMargin[3] = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hp:caption" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("side" == sAttributeName) + { + sType = oReader.GetText2A(); + + if ("LEFT" == sType) + m_nCaptionAttr = 0b00; + else if ("RIGHT" == sType) + m_nCaptionAttr = 0b01; + else if ("TOP" == sType) + m_nCaptionAttr = 0b10; + else if ("BOTTOM" == sType) + m_nCaptionAttr = 0b11; + } + else if ("fullSz" == sAttributeName) + { + if (oReader.GetBool()) + m_nCaptionAttr |= 0b100; + } + else if ("width" == sAttributeName) + m_nCaptionWidth = oReader.GetInt(); + else if ("gap" == sAttributeName) + m_nCaptionSpacing = oReader.GetInt(); + else if ("lastWidth" == sAttributeName) + m_nCaptionMaxW = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + + const int nChildDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode2(nChildDepth)) + { + if ("hp:subList" != oReader.GetNameA()) + continue; + + const int nSubChildDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode2(nSubChildDepth)) + { + if ("hp:p" != oReader.GetNameA()) + continue; + + m_arCaption.push_back(new CCapParagraph(oReader, nVersion)); + } } } } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlCommon.h b/HwpFile/HwpDoc/Paragraph/CtrlCommon.h index a3d80e3b8b..1e7ffc4b10 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlCommon.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlCommon.h @@ -114,7 +114,7 @@ public: CCtrlCommon(const HWP_STRING& sCtrlID); CCtrlCommon(const CCtrlCommon& oCtrlCommon); CCtrlCommon(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlCommon(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlCommon(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); virtual ~CCtrlCommon(); ECtrlObjectType GetCtrlType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlContainer.cpp b/HwpFile/HwpDoc/Paragraph/CtrlContainer.cpp index 42f98354d4..04a4a974d0 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlContainer.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlContainer.cpp @@ -25,31 +25,34 @@ CCtrlContainer::CCtrlContainer(const HWP_STRING& sCtrlID, int nSize, CHWPStream& : CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlContainer::CCtrlContainer(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlGeneralShape(sCtrlID, oNode, nVersion) +CCtrlContainer::CCtrlContainer(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlGeneralShape(sCtrlID, oReader, nVersion) { - for (CXMLNode& oChild : oNode.GetChilds()) + std::string sNodeName; + WHILE_READ_NEXT_NODE(oReader) { - if (L"hp:container" == oChild.GetName()) - m_arShapes.push_back(new CCtrlContainer(L"noc$", oChild, nVersion)); - else if (L"hp:line" == oChild.GetName()) - m_arShapes.push_back(new CCtrlShapeLine(L"nil$", oChild, nVersion)); - else if (L"hp:rect" == oChild.GetName()) - m_arShapes.push_back(new CCtrlShapeRect(L"cer$", oChild, nVersion)); - else if (L"hp:ellipse" == oChild.GetName()) - m_arShapes.push_back(new CCtrlShapeEllipse(L"lle$", oChild, nVersion)); - else if (L"hp:arc" == oChild.GetName()) - m_arShapes.push_back(new CCtrlShapeArc(L"cra$", oChild, nVersion)); - else if (L"hp:polygon" == oChild.GetName()) - m_arShapes.push_back(new CCtrlShapePolygon(L"lop$", oChild, nVersion)); - else if (L"hp:curve" == oChild.GetName()) - m_arShapes.push_back(new CCtrlShapeCurve(L"ruc$", oChild, nVersion)); - else if (L"hp:connectLine" == oChild.GetName()) - m_arShapes.push_back(new CCtrlShapeConnectLine(L"loc$", oChild, nVersion)); - else if (L"hp:pic" == oChild.GetName()) - m_arShapes.push_back(new CCtrlShapePic(L"cip$", oChild, nVersion)); - else if (L"hp:ole" == oChild.GetName()) - m_arShapes.push_back(new CCtrlShapeOle(L"elo$", oChild, nVersion)); + sNodeName = oReader.GetNameA(); + + if ("hp:container" == sNodeName) + m_arShapes.push_back(new CCtrlContainer(L"noc$", oReader, nVersion)); + else if ("hp:line" == sNodeName) + m_arShapes.push_back(new CCtrlShapeLine(L"nil$", oReader, nVersion)); + else if ("hp:rect" == sNodeName) + m_arShapes.push_back(new CCtrlShapeRect(L"cer$", oReader, nVersion)); + else if ("hp:ellipse" == sNodeName) + m_arShapes.push_back(new CCtrlShapeEllipse(L"lle$", oReader, nVersion)); + else if ("hp:arc" == sNodeName) + m_arShapes.push_back(new CCtrlShapeArc(L"cra$", oReader, nVersion)); + else if ("hp:polygon" == sNodeName) + m_arShapes.push_back(new CCtrlShapePolygon(L"lop$", oReader, nVersion)); + else if ("hp:curve" == sNodeName) + m_arShapes.push_back(new CCtrlShapeCurve(L"ruc$", oReader, nVersion)); + else if ("hp:connectLine" == sNodeName) + m_arShapes.push_back(new CCtrlShapeConnectLine(L"loc$", oReader, nVersion)); + else if ("hp:pic" == sNodeName) + m_arShapes.push_back(new CCtrlShapePic(L"cip$", oReader, nVersion)); + else if ("hp:ole" == sNodeName) + m_arShapes.push_back(new CCtrlShapeOle(L"elo$", oReader, nVersion)); } m_shNElement = m_arShapes.size(); diff --git a/HwpFile/HwpDoc/Paragraph/CtrlContainer.h b/HwpFile/HwpDoc/Paragraph/CtrlContainer.h index 3c92cf5d4d..590781d349 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlContainer.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlContainer.h @@ -14,7 +14,7 @@ public: CCtrlContainer(const HWP_STRING& sCtrlID); CCtrlContainer(const CCtrlGeneralShape& oShape); CCtrlContainer(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlContainer(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlContainer(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); ~CCtrlContainer(); diff --git a/HwpFile/HwpDoc/Paragraph/CtrlEqEdit.cpp b/HwpFile/HwpDoc/Paragraph/CtrlEqEdit.cpp index f0730e8dc6..093aa547ce 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlEqEdit.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlEqEdit.cpp @@ -17,23 +17,40 @@ CCtrlEqEdit::CCtrlEqEdit(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuff : CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlEqEdit::CCtrlEqEdit(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) +CCtrlEqEdit::CCtrlEqEdit(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) : CCtrlGeneralShape(sCtrlID) { - m_sVersion = oNode.GetAttribute(L"version"); - m_nBaseline = oNode.GetAttributeInt(L"baseLine"); - m_nColor = oNode.GetAttributeColor(L"textColor"); - m_nCharSize = oNode.GetAttributeInt(L"baseUnit"); + START_READ_ATTRIBUTES(oReader) + { + if ("version" == sAttributeName) + m_sVersion = oReader.GetText2(); + else if ("baseLine" == sAttributeName) + m_nBaseline = oReader.GetInt(); + else if ("textColor" == sAttributeName) + m_nColor = oReader.GetColor(); + else if ("baseUnit" == sAttributeName) + m_nCharSize = oReader.GetInt(); + else if ("lineMode" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - HWP_STRING sType = oNode.GetAttribute(L"lineMode"); + if ("LINE" == sType) + m_nAttr = 1; + else if ("CHAR" == sType) + m_nAttr = 0; + } + else if ("font" == sAttributeName) + m_sFont = oReader.GetText2(); + } + END_READ_ATTRIBUTES(oReader) - if (L"LINE" == sType) - m_nAttr = 1; - else if (L"CHAR" == sType) - m_nAttr = 0; + WHILE_READ_NEXT_NODE(oReader) + { + if ("hp:script" != oReader.GetNameA()) + continue; - m_sFont = oNode.GetAttribute(L"font"); - m_sEqn = oNode.GetChild(L"hp:script").GetText(); + m_sEqn = oReader.GetText2(); + } m_bFullFilled = true; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlEqEdit.h b/HwpFile/HwpDoc/Paragraph/CtrlEqEdit.h index e4602c5cbe..deca8a9137 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlEqEdit.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlEqEdit.h @@ -19,7 +19,7 @@ public: CCtrlEqEdit(const HWP_STRING& sCtrlID); CCtrlEqEdit(const CCtrlGeneralShape& oShape); CCtrlEqEdit(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlEqEdit(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlEqEdit(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); EShapeType GetShapeType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlField.cpp b/HwpFile/HwpDoc/Paragraph/CtrlField.cpp index 5a891c3bd9..d1ab08e187 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlField.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlField.cpp @@ -1,6 +1,4 @@ #include "CtrlField.h" -#include -#include namespace HWP { @@ -33,37 +31,50 @@ void CCtrlField::UpdateType(const HWP_STRING& sCtrlID) m_eType = EFieldType::BookmarkClosing; } -CCtrlField::CCtrlField(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) +CCtrlField::CCtrlField(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) : CCtrl(sCtrlID), m_eType(EFieldType::Unknown) { - if (L"hp:fieldBegin" == oNode.GetName()) + const std::string sNodeName{oReader.GetNameA()}; + HWP_STRING wsName; + + if ("hp:fieldBegin" == sNodeName) { - HWP_STRING sType = oNode.GetAttribute(L"type"); - - if (L"HYPERLINK" == sType) - m_eType = EFieldType::Hyperlink; - else if (L"BOOKMARK" == sType) - m_eType = EFieldType::Bookmark; - - m_nInstanceID = oNode.GetAttributeInt(L"fieldid"); - - HWP_STRING sName = oNode.GetAttribute(L"name"); - - if (!sName.empty() && EFieldType::Bookmark == m_eType) - AddStringParam(L"bookmarkname", sName); - - for (CXMLNode& oChild : oNode.GetChild(L"hp:parameters").GetChilds()) + START_READ_ATTRIBUTES(oReader) { - if (L"hp:stringParam" == oChild.GetName()) - AddStringParam(oChild.GetAttribute(L"name"), oChild.GetText()); - else if (L"hp:integerParam" == oChild.GetName()) - AddIntegerParam(oChild.GetAttribute(L"name"), std::stoi(oChild.GetText())); + if ("type" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; + + if ("HYPERLINK" == sType) + m_eType = EFieldType::Hyperlink; + else if ("BOOKMARK" == sType) + m_eType = EFieldType::Bookmark; + } + else if ("fieldid" == sAttributeName) + m_nInstanceID = oReader.GetInt(); + else if ("name" == sAttributeName) + wsName = oReader.GetText2(); } + END_READ_ATTRIBUTES(oReader) + + if (!wsName.empty() && EFieldType::Bookmark == m_eType) + AddStringParam(L"bookmarkname", wsName); + + WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "hp:parameters") + { + WHILE_READ_NEXT_NODE_WITH_DEPTH_AND_NAME(oReader, Child) + { + if ("hp:stringParam" == sNodeChildName) + AddStringParam(oReader.GetAttribute("name"), oReader.GetText2()); + else if ("hp:integerParam" == sNodeChildName) + AddIntegerParam(oReader.GetAttribute("name"), oReader.GetInt()); + } + END_WHILE + } + END_WHILE } - else if (L"hp:fieldEnd" == oNode.GetName()) - { - m_nInstanceID = oNode.GetAttributeInt(L"fieldid"); - } + else if ("hp:fieldEnd" == sNodeName) + m_nInstanceID = oReader.GetAttributeInt("fieldid"); } ECtrlObjectType CCtrlField::GetCtrlType() const diff --git a/HwpFile/HwpDoc/Paragraph/CtrlField.h b/HwpFile/HwpDoc/Paragraph/CtrlField.h index f84944566e..bda7d49c1c 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlField.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlField.h @@ -32,7 +32,7 @@ class CCtrlField : public CCtrl public: CCtrlField(const HWP_STRING& sCtrlID); CCtrlField(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlField(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlField(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); ECtrlObjectType GetCtrlType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlGeneralShape.cpp b/HwpFile/HwpDoc/Paragraph/CtrlGeneralShape.cpp index 8a3160f034..214ea11929 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlGeneralShape.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlGeneralShape.cpp @@ -62,118 +62,155 @@ CCtrlGeneralShape::CCtrlGeneralShape(const HWP_STRING& sCtrlID, int nSize, CHWPS InitData(); } -CCtrlGeneralShape::CCtrlGeneralShape(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlObjElement(sCtrlID, oNode, nVersion) +CCtrlGeneralShape::CCtrlGeneralShape(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlObjElement(sCtrlID, oReader, nVersion) { InitData(); - for (CXMLNode& oChild : oNode.GetChilds()) + std::string sNodeName; + + bool bHeadFill = false, bTailFill = false; + + WHILE_READ_NEXT_NODE(oReader) { - if (L"hp:lineShape" == oChild.GetName()) + sNodeName = oReader.GetNameA(); + + if ("hp:lineShape" == sNodeName) { - m_nLineColor = oChild.GetAttributeColor(L"color"); - m_nLineThick = std::abs(oChild.GetAttributeInt(L"width")); - m_eLineStyle = GetLineStyle2(oChild.GetAttribute(L"style")); + std::string sHeadStyle, sTailStyle; - HWP_STRING sType = oChild.GetAttribute(L"headStyle"); + START_READ_ATTRIBUTES(oReader) + { + if ("color" == sAttributeName) + m_nLineColor = oReader.GetInt(); + else if ("width" == sAttributeName) + m_nLineThick = oReader.GetInt(); + else if ("style" == sAttributeName) + m_eLineStyle = GetLineStyle2(oReader.GetText2()); + else if ("headStyle" == sAttributeName) + sHeadStyle = oReader.GetText2A(); + else if ("headfill" == sAttributeName) + bHeadFill = oReader.GetBool(); + else if ("headSz" == sAttributeName) + { + const std::string sHeadSz{oReader.GetText2A()}; - if (L"ARROW" == sType) + if ("SMALL_SMALL" == sHeadSz) + m_eLineHeadSz = ELineArrowSize::SMALL_SMALL; + else if ("SMALL_MEDIUM" == sHeadSz) + m_eLineHeadSz = ELineArrowSize::SMALL_MEDIUM; + else if ("SMALL_LARGE" == sHeadSz) + m_eLineHeadSz = ELineArrowSize::SMALL_LARGE; + else if ("MEDIUM_SMALL" == sHeadSz) + m_eLineHeadSz = ELineArrowSize::MEDIUM_SMALL; + else if ("MEDIUM_MEDIUM" == sHeadSz) + m_eLineHeadSz = ELineArrowSize::MEDIUM_MEDIUM; + else if ("MEDIUM_LARGE" == sHeadSz) + m_eLineHeadSz = ELineArrowSize::MEDIUM_LARGE; + else if ("LARGE_SMALL" == sHeadSz) + m_eLineHeadSz = ELineArrowSize::LARGE_SMALL; + else if ("LARGE_MEDIUM" == sHeadSz) + m_eLineHeadSz = ELineArrowSize::LARGE_MEDIUM; + else if ("LARGE_LARGE" == sHeadSz) + m_eLineHeadSz = ELineArrowSize::LARGE_LARGE; + else + m_eLineHeadSz = ELineArrowSize::MEDIUM_MEDIUM; + } + else if ("tailStyle" == sAttributeName) + sTailStyle = oReader.GetText2A(); + else if ("tailfill" == sAttributeName) + bTailFill = oReader.GetBool(); + else if ("tailSz" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; + + if ("SMALL_SMALL" == sType) + m_eLineTailSz = ELineArrowSize::SMALL_SMALL; + else if ("SMALL_MEDIUM" == sType) + m_eLineTailSz = ELineArrowSize::SMALL_MEDIUM; + else if ("SMALL_LARGE" == sType) + m_eLineTailSz = ELineArrowSize::SMALL_LARGE; + else if ("MEDIUM_SMALL" == sType) + m_eLineTailSz = ELineArrowSize::MEDIUM_SMALL; + else if ("MEDIUM_MEDIUM" == sType) + m_eLineTailSz = ELineArrowSize::MEDIUM_MEDIUM; + else if ("MEDIUM_LARGE" == sType) + m_eLineTailSz = ELineArrowSize::MEDIUM_LARGE; + else if ("LARGE_SMALL" == sType) + m_eLineTailSz = ELineArrowSize::LARGE_SMALL; + else if ("LARGE_MEDIUM" == sType) + m_eLineTailSz = ELineArrowSize::LARGE_MEDIUM; + else if ("LARGE_LARGE" == sType) + m_eLineTailSz = ELineArrowSize::LARGE_LARGE; + else + m_eLineTailSz = ELineArrowSize::MEDIUM_MEDIUM; + } + } + END_READ_ATTRIBUTES(oReader) + + if (sHeadStyle.empty()) + m_eLineHead = ELineArrowStyle::NORMAL; + else if ("ARROW" == sHeadStyle) m_eLineHead = ELineArrowStyle::ARROW; - else if (L"SPEAR" == sType) + else if ("SPEAR" == sHeadStyle) m_eLineHead = ELineArrowStyle::SPEAR; - else if (L"CONCAVE_ARROW" == sType) + else if ("CONCAVE_ARROW" == sHeadStyle) m_eLineHead = ELineArrowStyle::CONCAVE_ARROW; - else if (L"EMPTY_DIAMOND" == sType) - m_eLineHead = (oChild.GetAttributeBool(L"headfill")) ? ELineArrowStyle::DIAMOND : ELineArrowStyle::EMPTY_DIAMOND; - else if (L"EMPTY_CIRCLE" == sType) - m_eLineHead = (oChild.GetAttributeBool(L"headfill")) ? ELineArrowStyle::CIRCLE : ELineArrowStyle::EMPTY_CIRCLE; - else if (L"EMPTY_BOX" == sType) - m_eLineHead = (oChild.GetAttributeBool(L"headfill")) ? ELineArrowStyle::BOX : ELineArrowStyle::EMPTY_BOX; + else if ("EMPTY_DIAMOND" == sHeadStyle) + m_eLineHead = bHeadFill ? ELineArrowStyle::DIAMOND : ELineArrowStyle::EMPTY_DIAMOND; + else if ("EMPTY_CIRCLE" == sHeadStyle) + m_eLineHead = bHeadFill ? ELineArrowStyle::CIRCLE : ELineArrowStyle::EMPTY_CIRCLE; + else if ("EMPTY_BOX" == sHeadStyle) + m_eLineHead = bHeadFill ? ELineArrowStyle::BOX : ELineArrowStyle::EMPTY_BOX; else m_eLineHead = ELineArrowStyle::NORMAL; - sType = oChild.GetAttribute(L"headSz"); - - if (L"SMALL_SMALL" == sType) - m_eLineHeadSz = ELineArrowSize::SMALL_SMALL; - else if (L"SMALL_MEDIUM" == sType) - m_eLineHeadSz = ELineArrowSize::SMALL_MEDIUM; - else if (L"SMALL_LARGE" == sType) - m_eLineHeadSz = ELineArrowSize::SMALL_LARGE; - else if (L"MEDIUM_SMALL" == sType) - m_eLineHeadSz = ELineArrowSize::MEDIUM_SMALL; - else if (L"MEDIUM_MEDIUM" == sType) - m_eLineHeadSz = ELineArrowSize::MEDIUM_MEDIUM; - else if (L"MEDIUM_LARGE" == sType) - m_eLineHeadSz = ELineArrowSize::MEDIUM_LARGE; - else if (L"LARGE_SMALL" == sType) - m_eLineHeadSz = ELineArrowSize::LARGE_SMALL; - else if (L"LARGE_MEDIUM" == sType) - m_eLineHeadSz = ELineArrowSize::LARGE_MEDIUM; - else if (L"LARGE_LARGE" == sType) - m_eLineHeadSz = ELineArrowSize::LARGE_LARGE; - else - m_eLineHeadSz = ELineArrowSize::MEDIUM_MEDIUM; - - sType = oChild.GetAttribute(L"tailStyle"); - - if (L"ARROW" == sType) + if (sTailStyle.empty()) + m_eLineTail = ELineArrowStyle::NORMAL; + else if ("ARROW" == sTailStyle) m_eLineTail = ELineArrowStyle::ARROW; - else if (L"SPEAR" == sType) + else if ("SPEAR" == sTailStyle) m_eLineTail = ELineArrowStyle::SPEAR; - else if (L"CONCAVE_ARROW" == sType) + else if ("CONCAVE_ARROW" == sTailStyle) m_eLineTail = ELineArrowStyle::CONCAVE_ARROW; - else if (L"EMPTY_DIAMOND" == sType) - m_eLineTail = (oChild.GetAttributeBool(L"tailfill")) ? ELineArrowStyle::DIAMOND : ELineArrowStyle::EMPTY_DIAMOND; - else if (L"EMPTY_CIRCLE" == sType) - m_eLineTail = (oChild.GetAttributeBool(L"tailfill")) ? ELineArrowStyle::CIRCLE : ELineArrowStyle::EMPTY_CIRCLE; - else if (L"EMPTY_BOX" == sType) - m_eLineTail = (oChild.GetAttributeBool(L"tailfill")) ? ELineArrowStyle::BOX : ELineArrowStyle::EMPTY_BOX; + else if ("EMPTY_DIAMOND" == sTailStyle) + m_eLineTail = bTailFill ? ELineArrowStyle::DIAMOND : ELineArrowStyle::EMPTY_DIAMOND; + else if ("EMPTY_CIRCLE" == sTailStyle) + m_eLineTail = bTailFill ? ELineArrowStyle::CIRCLE : ELineArrowStyle::EMPTY_CIRCLE; + else if ("EMPTY_BOX" == sTailStyle) + m_eLineTail = bTailFill ? ELineArrowStyle::BOX : ELineArrowStyle::EMPTY_BOX; else m_eLineTail = ELineArrowStyle::NORMAL; - - sType = oChild.GetAttribute(L"tailSz"); - - if (L"SMALL_SMALL" == sType) - m_eLineTailSz = ELineArrowSize::SMALL_SMALL; - else if (L"SMALL_MEDIUM" == sType) - m_eLineTailSz = ELineArrowSize::SMALL_MEDIUM; - else if (L"SMALL_LARGE" == sType) - m_eLineTailSz = ELineArrowSize::SMALL_LARGE; - else if (L"MEDIUM_SMALL" == sType) - m_eLineTailSz = ELineArrowSize::MEDIUM_SMALL; - else if (L"MEDIUM_MEDIUM" == sType) - m_eLineTailSz = ELineArrowSize::MEDIUM_MEDIUM; - else if (L"MEDIUM_LARGE" == sType) - m_eLineTailSz = ELineArrowSize::MEDIUM_LARGE; - else if (L"LARGE_SMALL" == sType) - m_eLineTailSz = ELineArrowSize::LARGE_SMALL; - else if (L"LARGE_MEDIUM" == sType) - m_eLineTailSz = ELineArrowSize::LARGE_MEDIUM; - else if (L"LARGE_LARGE" == sType) - m_eLineTailSz = ELineArrowSize::LARGE_LARGE; - else - m_eLineTailSz = ELineArrowSize::MEDIUM_MEDIUM; } - else if (L"hc:fillBrush" == oChild.GetName()) - m_pFill = new CFill(oChild); - else if (L"hp:drawText" == oChild.GetName()) + else if ("hc:fillBrush" == sNodeName) + m_pFill = new CFill(oReader); + else if ("hp:drawText" == sNodeName) { - m_nMaxTxtWidth = oChild.GetAttributeInt(L"lastWidth"); + m_nMaxTxtWidth = oReader.GetAttributeInt("lastWidth"); - for (CXMLNode& oGrandChild : oChild.GetChilds()) + const int nChildDepth = oReader.GetDepth(); + std::string sChildNodeName; + while (oReader.ReadNextSiblingNode2(nChildDepth)) { - if (L"hp:textMargin" == oGrandChild.GetName()) + sChildNodeName = oReader.GetNameA(); + + if ("hp:textMargin" == sChildNodeName) { - m_shLeftSpace = oGrandChild.GetAttributeInt(L"left"); - m_shRightSpace = oGrandChild.GetAttributeInt(L"right"); - m_shTopSpace = oGrandChild.GetAttributeInt(L"top"); - m_shBottomSpace = oGrandChild.GetAttributeInt(L"bottom"); - } - else if (L"hp:subList" == oGrandChild.GetName()) - { - ReadSubList(oGrandChild, nVersion); + START_READ_ATTRIBUTES(oReader) + { + if ("left" == sAttributeName) + m_shLeftSpace = oReader.GetInt(); + else if ("right" == sAttributeName) + m_shRightSpace = oReader.GetInt(); + else if ("top" == sAttributeName) + m_shTopSpace = oReader.GetInt(); + else if ("bottom" == sAttributeName) + m_shBottomSpace = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } + else if ("hp:subList" == sChildNodeName) + ReadSubList(oReader, nVersion); } } } @@ -201,29 +238,27 @@ void CCtrlGeneralShape::InitData() m_pFill = nullptr; } -void CCtrlGeneralShape::ReadSubList(CXMLNode& oNode, int nVersion) +void CCtrlGeneralShape::ReadSubList(CXMLReader& oReader, int nVersion) { - m_eTextVerAlign = GetVertAlign(oNode.ReadAttributeInt(L"vertAlign")); + m_eTextVerAlign = GetVertAlign(oReader.GetAttributeInt("vertAlign")); - std::vector arChilds{oNode.GetChilds()}; + // CHWPPargraph* pLatestParagraph = nullptr; - for (unsigned int unIndex = 0; unIndex < arChilds.size(); ++unIndex) + WHILE_READ_NEXT_NODE(oReader) { - CHWPPargraph* pLatestParagraph = nullptr; + if ("hp:p" != oReader.GetNameA()) + continue; - if (L"hp:p" == arChilds[unIndex].GetName()) - { - CHWPPargraph* pParagraph = new CHWPPargraph(arChilds[unIndex], nVersion); + CHWPPargraph* pParagraph = new CHWPPargraph(oReader, nVersion); - if (nullptr == pParagraph) - continue; + if (nullptr == pParagraph) + continue; - m_arParas.push_back(pParagraph); - pLatestParagraph = pParagraph; - } + m_arParas.push_back(pParagraph); + // pLatestParagraph = pParagraph; - if (nullptr != pLatestParagraph && 0 != pLatestParagraph->GetCountCtrls() && ECtrlObjectType::ParaText == pLatestParagraph->GetCtrls().back()->GetCtrlType() && unIndex < arChilds.size() - 1) - pLatestParagraph->AddCtrl(new CCtrlCharacter(L" _", ECtrlCharType::PARAGRAPH_BREAK)); + // if (nullptr != pLatestParagraph && 0 != pLatestParagraph->GetCountCtrls() && ECtrlObjectType::ParaText == pLatestParagraph->GetCtrls().back()->GetCtrlType()) + // pLatestParagraph->AddCtrl(new CCtrlCharacter(L" _", ECtrlCharType::PARAGRAPH_BREAK)); } } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlGeneralShape.h b/HwpFile/HwpDoc/Paragraph/CtrlGeneralShape.h index 0f6d127da3..1693861d36 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlGeneralShape.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlGeneralShape.h @@ -53,13 +53,13 @@ class CCtrlGeneralShape : public CCtrlObjElement friend class CCtrlShapePolygon; friend class CCtrlShapeRect; - void ReadSubList(CXMLNode& oNode, int nVersion); + void ReadSubList(CXMLReader& oReader, int nVersion); public: CCtrlGeneralShape(); CCtrlGeneralShape(const HWP_STRING& sCtrlID); CCtrlGeneralShape(const CCtrlGeneralShape& oGeneralShape); CCtrlGeneralShape(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlGeneralShape(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlGeneralShape(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); virtual ~CCtrlGeneralShape(); ECtrlObjectType GetCtrlType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.cpp b/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.cpp index daa01db178..ff899e968c 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.cpp @@ -24,23 +24,33 @@ CCtrlHeadFoot::CCtrlHeadFoot(const HWP_STRING& sCtrlID, int nSize, CHWPStream& o oBuffer.ReadInt(m_nSerialInSec); } -CCtrlHeadFoot::CCtrlHeadFoot(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) +CCtrlHeadFoot::CCtrlHeadFoot(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) : CCtrl(sCtrlID) { m_bIsHeader = L"daeh" == sCtrlID; - m_eWhichPage = GetPageRange(oNode.GetAttributeInt(L"applyPageType")); + m_eWhichPage = GetPageRange(oReader.GetAttributeInt("applyPageType")); - for (CXMLNode& oChild : oNode.GetChilds(L"hp:subList")) + WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "hp:subList") { - m_chRefLevelNum = (HWP_BYTE)oChild.GetAttributeInt(L"hasNumRef"); - m_chRefLevelText = (HWP_BYTE)oChild.GetAttributeInt(L"hasTextRef"); - m_nTextHeight = oChild.GetAttributeInt(L"textHeight"); - m_nTextWidth = oChild.GetAttributeInt(L"textWidth"); + START_READ_ATTRIBUTES(oReader) + { + if ("hasNumRef" == sAttributeName) + m_chRefLevelNum = (HWP_BYTE)oReader.GetInt(); + else if ("hasTextRef" == sAttributeName) + m_chRefLevelText = (HWP_BYTE)oReader.GetInt(); + else if ("textHeight" == sAttributeName) + m_nTextHeight = oReader.GetInt(); + else if ("textWidth" == sAttributeName) + m_nTextWidth = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) - for (CXMLNode& oGrandChild : oChild.GetChilds(L"hp:p")) - m_arParas.push_back(new CHWPPargraph(oGrandChild, nVersion)); + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Child, "hp:p") + m_arParas.push_back(new CHWPPargraph(oReader, nVersion)); + END_WHILE } + END_WHILE m_bFullFilled = true; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.h b/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.h index bd1d55e0d5..926fbf70ed 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlHeadFoot.h @@ -31,7 +31,7 @@ class CCtrlHeadFoot : public CCtrl public: CCtrlHeadFoot(const HWP_STRING& sCtrlID); CCtrlHeadFoot(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion, bool bIsHeader); - CCtrlHeadFoot(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlHeadFoot(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); ECtrlObjectType GetCtrlType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.cpp b/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.cpp index b6f8dcfd10..b9e5cf34bf 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.cpp @@ -20,13 +20,20 @@ CCtrlNewNumber::CCtrlNewNumber(const HWP_STRING& sCtrlID, int nSize, CHWPStream& m_bFullFilled = true; } -CCtrlNewNumber::CCtrlNewNumber(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) +CCtrlNewNumber::CCtrlNewNumber(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) : CCtrl(sCtrlID) { - m_shNum = oNode.GetAttributeInt(L"num"); - m_eNumType = ::HWP::GetNumType(oNode.GetAttribute(L"numType")); - //TODO:: проверить данный момент - m_eNumShape = GetNumberShape2(oNode.GetAttributeInt(L"autoNumFormat")); + START_READ_ATTRIBUTES(oReader) + { + if ("num" == sAttributeName) + m_shNum = oReader.GetInt(); + else if ("numType" == sAttributeName) + m_eNumType = ::HWP::GetNumType(oReader.GetText2()); + //TODO:: проверить данный момент + else if ("autoNumFormat" == sAttributeName) + m_eNumShape = GetNumberShape2(oReader.GetInt()); + } + END_READ_ATTRIBUTES(oReader) m_bFullFilled = true; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.h b/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.h index 845b3f2e2f..9eb927620f 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlNewNumber.h @@ -13,7 +13,7 @@ class CCtrlNewNumber : public CCtrl public: CCtrlNewNumber(const HWP_STRING& sCtrlID); CCtrlNewNumber(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlNewNumber(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlNewNumber(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); ECtrlObjectType GetCtrlType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlNote.cpp b/HwpFile/HwpDoc/Paragraph/CtrlNote.cpp index da96c5ad66..e5f58a9004 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlNote.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlNote.cpp @@ -16,14 +16,14 @@ CCtrlNote::CCtrlNote(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, m_bFullFilled = true; } -CCtrlNote::CCtrlNote(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) +CCtrlNote::CCtrlNote(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) : CCtrl(sCtrlID) { - for (CXMLNode& oChild : oNode.GetChilds(L"hp:subList")) - { - for (CXMLNode& oGrandChild : oChild.GetChilds(L"hp:p")) - m_arParas.push_back(new CHWPPargraph(oGrandChild, nVersion)); - } + WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "hp:subList") + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Child, "hp:p") + m_arParas.push_back(new CHWPPargraph(oReader, nVersion)); + END_WHILE + END_WHILE m_bFullFilled = true; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlNote.h b/HwpFile/HwpDoc/Paragraph/CtrlNote.h index 679db83307..ee6b561bd6 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlNote.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlNote.h @@ -14,7 +14,7 @@ public: CCtrlNote(); CCtrlNote(const HWP_STRING& sCtrlID); CCtrlNote(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlNote(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlNote(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); ECtrlObjectType GetCtrlType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlObjElement.cpp b/HwpFile/HwpDoc/Paragraph/CtrlObjElement.cpp index 3577795689..55731e8222 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlObjElement.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlObjElement.cpp @@ -47,64 +47,113 @@ CCtrlObjElement::CCtrlObjElement(const HWP_STRING& sCtrlID, int nSize, CHWPStrea : CCtrlCommon(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -TMatrix ReadMatrix(CXMLNode& oNode) +TMatrix ReadMatrix(CXMLReader& oReader) { - return TMatrix + TMatrix oMatrix; + + START_READ_ATTRIBUTES(oReader) { - oNode.GetAttributeDouble(L"e1", 1.), - oNode.GetAttributeDouble(L"e2"), - oNode.GetAttributeDouble(L"e4"), - oNode.GetAttributeDouble(L"e5", 1.), - oNode.GetAttributeDouble(L"e3"), - oNode.GetAttributeDouble(L"e6"), - }; + if ("e1" == sAttributeName) + oMatrix.m_dM11 = oReader.GetDouble(); + else if ("e2" == sAttributeName) + oMatrix.m_dM12 = oReader.GetDouble(); + else if ("e3" == sAttributeName) + oMatrix.m_dDX = oReader.GetDouble(); + else if ("e4" == sAttributeName) + oMatrix.m_dM21 = oReader.GetDouble(); + else if ("e5" == sAttributeName) + oMatrix.m_dM22 = oReader.GetDouble(); + else if ("e6" == sAttributeName) + oMatrix.m_dDY = oReader.GetDouble(); + } + END_READ_ATTRIBUTES(oReader) + + return oMatrix; } -CCtrlObjElement::CCtrlObjElement(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlCommon(sCtrlID, oNode, nVersion) +CCtrlObjElement::CCtrlObjElement(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlCommon(sCtrlID, oReader, nVersion) { - m_shNGrp = oNode.GetAttributeInt(L"groupLevel"); + m_shNGrp = oReader.GetAttributeInt("groupLevel"); - for (CXMLNode& oChild : oNode.GetChilds()) + std::string sNodeName; + + WHILE_READ_NEXT_NODE(oReader) { - if (L"hp:offset" == oChild.GetName()) + sNodeName = oReader.GetNameA(); + + if ("hp:offset" == sNodeName) { - m_nXGrpOffset = oChild.GetAttributeInt(L"x"); - m_nYGrpOffset = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nXGrpOffset = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nYGrpOffset = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hp:orgSz" == oChild.GetName()) + + else if ("hp:orgSz" == sNodeName) { - m_nOrgWidth = oChild.GetAttributeInt(L"width"); - m_nOrgHeight = oChild.GetAttributeInt(L"height"); + START_READ_ATTRIBUTES(oReader) + { + if ("width" == sAttributeName) + m_nOrgWidth = oReader.GetInt(); + else if ("height" == sAttributeName) + m_nOrgHeight = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hp:curSz" == oChild.GetName()) + else if ("hp:curSz" == sNodeName) { - m_nCurWidth = oChild.GetAttributeInt(L"width"); - m_nCurHeight = oChild.GetAttributeInt(L"height"); + START_READ_ATTRIBUTES(oReader) + { + if ("width" == sAttributeName) + m_nCurWidth = oReader.GetInt(); + else if ("height" == sAttributeName) + m_nCurHeight = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hp:flip" == oChild.GetName()) + else if ("hp:flip" == sNodeName) { - m_bHorzFlip = oChild.GetAttributeBool(L"horizontal"); - m_bVerFlip = oChild.GetAttributeBool(L"vertical"); + START_READ_ATTRIBUTES(oReader) + { + if ("horizontal" == sAttributeName) + m_bHorzFlip = oReader.GetBool(); + else if ("vertical" == sAttributeName) + m_bVerFlip = oReader.GetBool(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hp:rotationInfo" == oChild.GetName()) + else if ("hp:rotationInfo" == sNodeName) { - m_shRotat = oChild.GetAttributeInt(L"angle"); - m_nXCenter = oChild.GetAttributeInt(L"centerX"); - m_nYCenter = oChild.GetAttributeInt(L"centerY"); + START_READ_ATTRIBUTES(oReader) + { + if ("angle" == sAttributeName) + m_shRotat = oReader.GetInt(); + else if ("centerX" == sAttributeName) + m_nXCenter = oReader.GetInt(); + else if ("centerY" == sAttributeName) + m_nYCenter = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hp:renderingInfo" == oChild.GetName()) + else if ("hp:renderingInfo" == sNodeName) { - for (CXMLNode& oGrandChild : oChild.GetChilds()) + WHILE_READ_NEXT_NODE_WITH_DEPTH_AND_NAME(oReader, Child) { // Сначала идёт 1 hc:transMatrix, а после попарно идут hc:scaMatrix с hc:rotMatrix - if (L"hc:transMatrix" == oGrandChild.GetName()) - m_arMatrixs.push_back(ReadMatrix(oGrandChild)); - else if (L"hc:scaMatrix" == oGrandChild.GetName()) - m_arMatrixs.push_back(ReadMatrix(oGrandChild)); - else if (L"hc:rotMatrix" == oGrandChild.GetName()) - m_arMatrixs.push_back(ReadMatrix(oGrandChild)); + + if ("hc:transMatrix" != sNodeChildName && + "hc:scaMatrix" != sNodeChildName && + "hc:rotMatrix" != sNodeChildName) + continue; + + m_arMatrixs.push_back(ReadMatrix(oReader)); } + END_WHILE } } } @@ -145,9 +194,14 @@ int CCtrlObjElement::GetFinalHeight() const return CCtrlCommon::GetHeight(); } +short CCtrlObjElement::GetGroupLevel() const +{ + return m_shNGrp; +} + TMatrix CCtrlObjElement::GetFinalMatrix() const { - if (m_arMatrixs.empty() || 0 == m_shNGrp) + if (m_arMatrixs.empty()) return TMatrix(); TMatrix oMatrix{m_arMatrixs.front()}; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlObjElement.h b/HwpFile/HwpDoc/Paragraph/CtrlObjElement.h index b1a2f5d39a..4aa9e3f11d 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlObjElement.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlObjElement.h @@ -44,7 +44,7 @@ public: CCtrlObjElement(const HWP_STRING& sCtrlID); CCtrlObjElement(const CCtrlObjElement& oObjElement); CCtrlObjElement(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlObjElement(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlObjElement(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); int GetCurWidth() const; int GetCurHeight() const; @@ -55,6 +55,8 @@ public: int GetFinalWidth() const; int GetFinalHeight() const; + short GetGroupLevel() const; + TMatrix GetFinalMatrix() const; bool HorzFlip() const; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.cpp b/HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.cpp index fdd6846b4b..0d131e7967 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.cpp @@ -54,13 +54,20 @@ CCtrlPageNumPos::CCtrlPageNumPos(const HWP_STRING& sCtrlID, int nSize, CHWPStrea oBuffer.ReadString(m_sConstantDash, 2, EStringCharacter::UTF16); } -CCtrlPageNumPos::CCtrlPageNumPos(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) +CCtrlPageNumPos::CCtrlPageNumPos(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) : CCtrl(sCtrlID) { - m_ePos = GetNumPos(oNode.GetAttribute(L"pos")); - m_eNumShape = GetNumberShape2(oNode.GetAttributeInt(L"formatType")); + START_READ_ATTRIBUTES(oReader) + { + if ("pos" == sAttributeName) + m_ePos = GetNumPos(oReader.GetText2()); + else if ("formatType" == sAttributeName) + m_eNumShape = GetNumberShape2(oReader.GetInt()); + else if ("sideChar" == sAttributeName) + m_sPostfix = oReader.GetText2(); + } + END_READ_ATTRIBUTES(oReader) - m_sPostfix = oNode.GetAttribute(L"sideChar"); m_sPrefix = m_sPostfix; } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.h b/HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.h index 036d306afd..e03f0198df 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlPageNumPos.h @@ -4,7 +4,7 @@ #include "Ctrl.h" #include "../HWPStream.h" #include "../HWPElements/HwpRecordTypes.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -34,7 +34,7 @@ class CCtrlPageNumPos : public CCtrl public: CCtrlPageNumPos(const HWP_STRING& sCtrlID); CCtrlPageNumPos(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlPageNumPos(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlPageNumPos(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); ENumPos GetPos() const; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.cpp b/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.cpp index bf36ad142e..f4f42918d7 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.cpp @@ -40,96 +40,170 @@ CCtrlSectionDef::CCtrlSectionDef(const HWP_STRING& sCtrlID, int nSize, CHWPStrea m_bFullFilled = true; } -CCtrlSectionDef::CCtrlSectionDef(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) +CCtrlSectionDef::CCtrlSectionDef(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) : CCtrl(sCtrlID), m_pPage(nullptr) { - HWP_STRING sType = oNode.GetAttribute(L"textDirection"); + std::string sType; - if (L"HORIZONTAL" == sType) - m_chTextDirection = 0; - else if (L"VERTICAL" == sType) - m_chTextDirection = 1; - - m_shSpaceColumns = oNode.GetAttributeInt(L"spaceColumns"); - m_nTabStop = oNode.GetAttributeInt(L"tabStop"); - m_nOutlineNumberingID = oNode.GetAttributeInt(L"outlineShapeIDRef"); - - for (CXMLNode& oChild : oNode.GetChilds()) + if (oReader.MoveToFirstAttribute()) { - if (L"hp:startNum" == oChild.GetName()) + std::string sAttributeName; + do { - sType = oChild.GetAttribute(L"pageStartsOn"); + sAttributeName = oReader.GetNameA(); - if (L"BOTH" == sType) - m_chPageStartOn = 0; - else if (L"EVEN" == sType) - m_chPageStartOn = 1; - else if (L"ODD" == sType) - m_chPageStartOn = 2; + if ("textDirection" == sAttributeName) + { + sType = oReader.GetText2A(); - m_shPageNum = oChild.GetAttributeInt(L"page"); - m_shFigure = oChild.GetAttributeInt(L"pic"); - m_shTable = oChild.GetAttributeInt(L"tbl"); - m_shEquation = oChild.GetAttributeInt(L"equation"); - } - else if (L"hp:grid" == oChild.GetName()) + if ("HORIZONTAL" == sType) + m_chTextDirection = 0; + else if ("VERTICAL" == sType) + m_chTextDirection = 1; + } + else if ("spaceColumns" == sAttributeName) + m_shSpaceColumns = oReader.GetInt(); + else if ("tabStop" == sAttributeName) + m_nTabStop = oReader.GetInt(); + else if ("outlineShapeIDRef" == sAttributeName) + m_nOutlineNumberingID = oReader.GetInt(); + }while(oReader.MoveToNextAttribute()); + + oReader.MoveToElement(); + } + + std::string sNodeName; + + WHILE_READ_NEXT_NODE(oReader) + { + sNodeName = oReader.GetNameA(); + + if ("hp:startNum" == sNodeName) { - m_shLineGrid = oChild.GetAttributeInt(L"lineGrid"); - m_shCharGrid = oChild.GetAttributeInt(L"charGrid"); + if (!oReader.MoveToFirstAttribute()) + continue; + + std::string sAttributeName; + + do + { + sAttributeName = oReader.GetNameA(); + + if ("pageStartsOn" == sAttributeName) + { + sType = oReader.GetText2A(); + + if ("BOTH" == sType) + m_chPageStartOn = 0; + else if ("EVEN" == sType) + m_chPageStartOn = 1; + else if ("ODD" == sType) + m_chPageStartOn = 2; + } + else if ("page" == sAttributeName) + m_shPageNum = oReader.GetInt(); + else if ("pic" == sAttributeName) + m_shFigure = oReader.GetInt(); + else if ("tbl" == sAttributeName) + m_shTable = oReader.GetInt(); + else if ("equation" == sAttributeName) + m_shEquation = oReader.GetInt(); + }while(oReader.MoveToNextAttribute()); + + oReader.MoveToElement(); } - else if (L"hp:visibility" == oChild.GetName()) + else if ("hp:grid" == sNodeName) { - m_bHideHeader = oChild.GetAttributeBool(L"hideFirstHeader"); - m_bHideFooter = oChild.GetAttributeBool(L"hideFirstFooter"); - m_bHideMasterPage = oChild.GetAttributeBool(L"hideFirstMasterPage"); + if (!oReader.MoveToFirstAttribute()) + continue; - sType = oChild.GetAttribute(L"border"); + std::string sAttributeName; - if (L"HIDE_FIRST" == sType) + do { - m_bHideBorder = true; - m_bShowFirstBorder = false; - } - else if (L"SHOW_FIRST" == sType) - { - m_bHideBorder = true; - m_bShowFirstBorder = true; - } - else if (L"SHOW_ALL" == sType) - { - m_bHideBorder = false; - m_bShowFirstBorder = false; - } + sAttributeName = oReader.GetNameA(); - sType = oChild.GetAttribute(L"fill"); + if ("lineGrid" == sAttributeName) + m_shLineGrid = oReader.GetInt(); + else if ("charGrid" == sAttributeName) + m_shCharGrid = oReader.GetInt(); + }while(oReader.MoveToNextAttribute()); - if (L"HIDE_FIRST" == sType) - { - m_bHideFill = true; - m_bShowFirstFill = false; - } - else if (L"SHOW_FIRST" == sType) - { - m_bHideFill = true; - m_bShowFirstFill = true; - } - else if (L"SHOW_ALL" == sType) - { - m_bHideFill = false; - m_bShowFirstFill = false; - } - - m_bHidePageNumPos = oChild.GetAttributeBool(L"hideFirstPageNum"); - m_bHideEmptyLine = oChild.GetAttributeBool(L"hideFirstEmptyLine"); + oReader.MoveToElement(); } - else if (L"hp:pagePr" == oChild.GetName()) - m_pPage = new CPage(oChild); - else if (L"hp:footNotePr" == oChild.GetName() || - L"hp:endNotePr" == oChild.GetName()) - m_arNoteShapes.push_back(new CNoteShape(oChild, nVersion)); - else if (L"hp:pageBorderFill" == oChild.GetName()) - m_arBorderFills.push_back(new CPageBorderFill(oChild, nVersion)); - else if (L"hp:masterPage" == oChild.GetName()) + else if ("hp:visibility" == sNodeName) + { + if (!oReader.MoveToFirstAttribute()) + continue; + + std::string sAttributeName; + + do + { + sAttributeName = oReader.GetNameA(); + + if ("hideFirstHeader" == sAttributeName) + m_bHideHeader = oReader.GetBool(); + else if ("hideFirstFooter" == sAttributeName) + m_bHideFooter = oReader.GetBool(); + else if ("hideFirstMasterPage" == sAttributeName) + m_bHideMasterPage = oReader.GetBool(); + else if ("border" == sAttributeName) + { + sType = oReader.GetText2A(); + + if ("HIDE_FIRST" == sType) + { + m_bHideBorder = true; + m_bShowFirstBorder = false; + } + else if ("SHOW_FIRST" == sType) + { + m_bHideBorder = true; + m_bShowFirstBorder = true; + } + else if ("SHOW_ALL" == sType) + { + m_bHideBorder = false; + m_bShowFirstBorder = false; + } + } + else if ("fill" == sAttributeName) + { + sType = oReader.GetText2A(); + + if ("HIDE_FIRST" == sType) + { + m_bHideFill = true; + m_bShowFirstFill = false; + } + else if ("SHOW_FIRST" == sType) + { + m_bHideFill = true; + m_bShowFirstFill = true; + } + else if ("SHOW_ALL" == sType) + { + m_bHideFill = false; + m_bShowFirstFill = false; + } + } + else if ("hp:visibility" == sAttributeName) + m_bHidePageNumPos = oReader.GetBool(); + else if ("hideFirstEmptyLine" == sAttributeName) + m_bHideEmptyLine = oReader.GetBool(); + }while(oReader.MoveToNextAttribute()); + + oReader.MoveToElement(); + } + else if ("hp:pagePr" == sNodeName) + m_pPage = new CPage(oReader); + else if ("hp:footNotePr" == sNodeName || + "hp:endNotePr" == sNodeName) + m_arNoteShapes.push_back(new CNoteShape(oReader, nVersion)); + else if ("hp:pageBorderFill" == sNodeName) + m_arBorderFills.push_back(new CPageBorderFill(oReader, nVersion)); + else if ("hp:masterPage" == sNodeName) { //TODO:: добавить реализацию } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.h b/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.h index a16478934d..04ebc2ad93 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlSectionDef.h @@ -45,7 +45,7 @@ class CCtrlSectionDef : public CCtrl public: CCtrlSectionDef(const HWP_STRING& sCtrlID); CCtrlSectionDef(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlSectionDef(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlSectionDef(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); ~CCtrlSectionDef(); ECtrlObjectType GetCtrlType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeArc.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeArc.cpp index 0ee8be0f52..01e655a367 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeArc.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeArc.cpp @@ -17,27 +17,49 @@ CCtrlShapeArc::CCtrlShapeArc(const HWP_STRING& sCtrlID, int nSize, CHWPStream& o : CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlShapeArc::CCtrlShapeArc(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlGeneralShape(sCtrlID, oNode, nVersion) +CCtrlShapeArc::CCtrlShapeArc(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlGeneralShape(sCtrlID, oReader, nVersion) { - m_eType = GetArcType(oNode.GetAttributeInt(L"type")); + m_eType = GetArcType(oReader.GetAttributeInt("type")); - for (CXMLNode& oChild : oNode.GetChilds()) + std::string sNodeName; + + WHILE_READ_NEXT_NODE(oReader) { - if (L"hp:center" == oChild.GetName()) + sNodeName = oReader.GetNameA(); + + if ("hp:center" == sNodeName) { - m_nCenterX = oChild.GetAttributeInt(L"x"); - m_nCenterY = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nCenterX = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nCenterY = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hp:ax1" == oChild.GetName()) + else if ("hp:ax1" == sNodeName) { - m_nAxixX1 = oChild.GetAttributeInt(L"x"); - m_nAxixY1 = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nAxixX1 = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nAxixY1 = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hp:ax2" == oChild.GetName()) + else if ("hp:ax2" == sNodeName) { - m_nAxixX2 = oChild.GetAttributeInt(L"x"); - m_nAxixY2 = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nAxixX2 = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nAxixY2 = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } } } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeArc.h b/HwpFile/HwpDoc/Paragraph/CtrlShapeArc.h index f9e891d572..f3407d46fd 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeArc.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeArc.h @@ -20,7 +20,7 @@ public: CCtrlShapeArc(const HWP_STRING& sCtrlID); CCtrlShapeArc(const CCtrlGeneralShape& oShape); CCtrlShapeArc(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlShapeArc(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlShapeArc(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); EShapeType GetShapeType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeConnectLine.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeConnectLine.cpp index d3f3fe44f2..7e18d57c4b 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeConnectLine.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeConnectLine.cpp @@ -25,28 +25,45 @@ CCtrlShapeConnectLine::CCtrlShapeConnectLine(const HWP_STRING& sCtrlID, int nSiz : CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlShapeConnectLine::CCtrlShapeConnectLine(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlGeneralShape(sCtrlID, oNode, nVersion) +CCtrlShapeConnectLine::CCtrlShapeConnectLine(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlGeneralShape(sCtrlID, oReader, nVersion) { - m_eType = GetConnectLineType(oNode.GetAttributeInt(L"type")); + m_eType = GetConnectLineType(oReader.GetAttributeInt("type")); - for (CXMLNode& oChild : oNode.GetChilds()) + WHILE_READ_NEXT_NODE_WITH_NAME(oReader) { - if (L"hp:startPt" == oChild.GetName()) + if ("hp:startPt" == sNodeName) { - m_oStartPt.m_nX = oChild.GetAttributeInt(L"x"); - m_oStartPt.m_nY = oChild.GetAttributeInt(L"y"); - m_oStartPt.m_shSubjectIDRef = oChild.GetAttributeInt(L"subjectIDRef"); - m_oStartPt.m_shSubjectIdx = oChild.GetAttributeInt(L"subjectIdx"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_oStartPt.m_nX = oReader.GetInt(); + else if ("y" == sAttributeName) + m_oStartPt.m_nY = oReader.GetInt(); + else if ("subjectIDRef" == sAttributeName) + m_oStartPt.m_shSubjectIDRef = oReader.GetInt(); + else if ("subjectIdx" == sAttributeName) + m_oStartPt.m_shSubjectIdx = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hp:endPt" == oChild.GetName()) + else if ("hp:endPt" == sNodeName) { - m_oEndPt.m_nX = oChild.GetAttributeInt(L"x"); - m_oEndPt.m_nY = oChild.GetAttributeInt(L"y"); - m_oEndPt.m_shSubjectIDRef = oChild.GetAttributeInt(L"subjectIDRef"); - m_oEndPt.m_shSubjectIdx = oChild.GetAttributeInt(L"subjectIdx"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_oEndPt.m_nX = oReader.GetInt(); + else if ("y" == sAttributeName) + m_oEndPt.m_nY = oReader.GetInt(); + else if ("subjectIDRef" == sAttributeName) + m_oEndPt.m_shSubjectIDRef = oReader.GetInt(); + else if ("subjectIdx" == sAttributeName) + m_oEndPt.m_shSubjectIdx = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } } + END_WHILE } EShapeType CCtrlShapeConnectLine::GetShapeType() const diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeConnectLine.h b/HwpFile/HwpDoc/Paragraph/CtrlShapeConnectLine.h index 2ac0ee7daf..a1971b08bc 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeConnectLine.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeConnectLine.h @@ -33,7 +33,7 @@ class CCtrlShapeConnectLine : public CCtrlGeneralShape TConnectPoint m_oEndPt; public: CCtrlShapeConnectLine(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlShapeConnectLine(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlShapeConnectLine(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); EShapeType GetShapeType() const override; }; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.cpp index 937b4016f4..39d34fd6e2 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.cpp @@ -17,34 +17,47 @@ CCtrlShapeCurve::CCtrlShapeCurve(const HWP_STRING& sCtrlID, int nSize, CHWPStrea : CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlShapeCurve::CCtrlShapeCurve(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlGeneralShape(sCtrlID, oNode, nVersion) +CCtrlShapeCurve::CCtrlShapeCurve(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlGeneralShape(sCtrlID, oReader, nVersion) { - std::vector arChilds{oNode.GetChilds(L"hp:seg")}; + // bool bReadedType + TPoint oPoint1{0, 0}, oPoint2{0, 0}; + HWP_BYTE chSegmentType = 0; - m_arPoints.resize(arChilds.size() + 1); - m_arSegmentType.resize(arChilds.size()); - - HWP_STRING sType; - - for (unsigned int unIndex = 0; unIndex < arChilds.size(); ++unIndex) + WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "hp:seg") { - sType = arChilds[unIndex].GetAttribute(L"type"); + chSegmentType = 0; + oPoint1 = {0, 0}; + oPoint2 = {0, 0}; - if (L"CURVE" == sType) - m_arSegmentType[unIndex] = 1; - else if (L"LINE" == sType) - m_arSegmentType[unIndex] = 0; - - m_arPoints[unIndex].m_nX = arChilds[unIndex].GetAttributeInt(L"x1"); - m_arPoints[unIndex].m_nY = arChilds[unIndex].GetAttributeInt(L"y1"); - - if (unIndex == arChilds.size() - 1) + START_READ_ATTRIBUTES(oReader) { - m_arPoints[unIndex + 1].m_nX = arChilds[unIndex].GetAttributeInt(L"x2"); - m_arPoints[unIndex + 1].m_nY = arChilds[unIndex].GetAttributeInt(L"y2"); + if ("type" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; + + if ("CURVE" == sType) + chSegmentType = 1; + else if ("LINE" == sType) + chSegmentType = 0; + } + else if ("x1" == sAttributeName) + oPoint1.m_nX = oReader.GetInt(); + else if ("y1" == sAttributeName) + oPoint1.m_nY = oReader.GetInt(); + else if ("x2" == sAttributeName) + oPoint2.m_nX = oReader.GetInt(); + else if ("y2" == sAttributeName) + oPoint2.m_nY = oReader.GetInt(); } + END_READ_ATTRIBUTES(oReader) + + m_arSegmentType.push_back(chSegmentType); + m_arPoints.push_back(oPoint1); } + END_WHILE + + m_arPoints.push_back(oPoint2); } EShapeType CCtrlShapeCurve::GetShapeType() const diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.h b/HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.h index 11a3bc1ab8..4ae6551bc8 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeCurve.h @@ -16,7 +16,7 @@ public: CCtrlShapeCurve(const HWP_STRING& sCtrlID); CCtrlShapeCurve(const CCtrlGeneralShape& oShape); CCtrlShapeCurve(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlShapeCurve(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlShapeCurve(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); EShapeType GetShapeType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.cpp index 30f534d17c..3a26304d08 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.cpp @@ -34,51 +34,101 @@ CCtrlShapeEllipse::CCtrlShapeEllipse(const HWP_STRING& sCtrlID, int nSize, CHWPS : CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlShapeEllipse::CCtrlShapeEllipse(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlGeneralShape(sCtrlID, oNode, nVersion) +CCtrlShapeEllipse::CCtrlShapeEllipse(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlGeneralShape(sCtrlID, oReader, nVersion) { - m_bIntervalDirty = oNode.GetAttributeBool(L"intervalDirty"); - m_bHasArcProperty = oNode.GetAttributeBool(L"hasArcPr"); - m_eArcType = GetArcType(oNode.GetAttribute(L"arcType")); - - for (CXMLNode& oChild : oNode.GetChilds()) + START_READ_ATTRIBUTES(oReader) { - if (L"hc:center" == oChild.GetName()) + if ("intervalDirty" == sAttributeName) + m_bIntervalDirty = oReader.GetBool(); + else if ("hasArcPr" == sAttributeName) + m_bHasArcProperty = oReader.GetBool(); + else if ("arcType" == sAttributeName) + m_eArcType = GetArcType(oReader.GetText2()); + } + END_READ_ATTRIBUTES(oReader) + + WHILE_READ_NEXT_NODE_WITH_NAME(oReader) + { + if ("hc:center" == sNodeName) { - m_nCenterX = oChild.GetAttributeInt(L"x"); - m_nCenterY = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nCenterX = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nCenterY = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hp:ax1" == oChild.GetName()) + else if ("hp:ax1" == sNodeName) { - m_nAxixX1 = oChild.GetAttributeInt(L"x"); - m_nAxixY1 = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nAxixX1 = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nAxixY1 = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hp:ax2" == oChild.GetName()) + else if ("hp:ax2" == sNodeName) { - m_nAxixX2 = oChild.GetAttributeInt(L"x"); - m_nAxixY2 = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nAxixX2 = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nAxixY2 = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hc:start1" == oChild.GetName()) + else if ("hp:start1" == sNodeName) { - m_nStartX1 = oChild.GetAttributeInt(L"x"); - m_nStartY1 = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nStartX1 = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nStartY1 = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hc:start2" == oChild.GetName()) + else if ("hp:start2" == sNodeName) { - m_nStartX2 = oChild.GetAttributeInt(L"x"); - m_nStartY2 = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nStartX2 = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nStartY2 = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hc:end1" == oChild.GetName()) + else if ("hp:end1" == sNodeName) { - m_nEndX1 = oChild.GetAttributeInt(L"x"); - m_nEndY1 = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nEndX1 = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nEndY1 = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hc:end2" == oChild.GetName()) + else if ("hp:end2" == sNodeName) { - m_nEndX2 = oChild.GetAttributeInt(L"x"); - m_nEndY2 = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nEndX2 = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nEndY2 = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } } + END_WHILE } EShapeType CCtrlShapeEllipse::GetShapeType() const diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.h b/HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.h index ad0b28ba7c..670dc4c994 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.h @@ -39,7 +39,7 @@ public: CCtrlShapeEllipse(const HWP_STRING& sCtrlID); CCtrlShapeEllipse(const CCtrlGeneralShape& oShape); CCtrlShapeEllipse(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlShapeEllipse(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlShapeEllipse(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); EShapeType GetShapeType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeLine.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeLine.cpp index 665df293f9..e92597eab1 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeLine.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeLine.cpp @@ -17,24 +17,37 @@ CCtrlShapeLine::CCtrlShapeLine(const HWP_STRING& sCtrlID, int nSize, CHWPStream& : CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlShapeLine::CCtrlShapeLine(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlGeneralShape(sCtrlID, oNode, nVersion) +CCtrlShapeLine::CCtrlShapeLine(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlGeneralShape(sCtrlID, oReader, nVersion) { - m_shAttr = (short)oNode.GetAttributeBool(L"isReverseHV"); + m_shAttr = (short)oReader.GetAttributeBool("isReverseHV"); - for (CXMLNode& oChild : oNode.GetChilds()) + WHILE_READ_NEXT_NODE_WITH_NAME(oReader) { - if (L"hc:startPt" == oChild.GetName()) + if ("hc:startPt" == sNodeName) { - m_nStartX = oChild.GetAttributeInt(L"x"); - m_nStartY = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nStartX = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nStartY = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hc:endPt" == oChild.GetName()) + else if ("hc:endPt" == sNodeName) { - m_nEndX = oChild.GetAttributeInt(L"x"); - m_nEndY = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nEndX = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nEndY = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } } + END_WHILE } EShapeType CCtrlShapeLine::GetShapeType() const diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeLine.h b/HwpFile/HwpDoc/Paragraph/CtrlShapeLine.h index 45aa7d8722..0e214b5129 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeLine.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeLine.h @@ -17,7 +17,7 @@ public: CCtrlShapeLine(const HWP_STRING& sCtrlID); CCtrlShapeLine(const CCtrlGeneralShape& oShape); CCtrlShapeLine(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlShapeLine(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlShapeLine(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); EShapeType GetShapeType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeOle.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeOle.cpp index d209927c52..0968510de6 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeOle.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeOle.cpp @@ -17,16 +17,23 @@ CCtrlShapeOle::CCtrlShapeOle(const HWP_STRING& sCtrlID, int nSize, CHWPStream& o : CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlShapeOle::CCtrlShapeOle(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlGeneralShape(sCtrlID, oNode, nVersion) +CCtrlShapeOle::CCtrlShapeOle(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlGeneralShape(sCtrlID, oReader, nVersion) { - m_sBinDataID = oNode.GetAttribute(L"binaryItemIDRef"); + m_sBinDataID = oReader.GetAttribute("binaryItemIDRef"); - for (CXMLNode& oChild : oNode.GetChilds(L"hc:extent")) + WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "hc:extent") { - m_nExtentX = oChild.GetAttributeInt(L"x"); - m_nExtentY = oChild.GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_nExtentX = oReader.GetInt(); + else if ("y" == sAttributeName) + m_nExtentY = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } + END_WHILE } EShapeType CCtrlShapeOle::GetShapeType() const diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeOle.h b/HwpFile/HwpDoc/Paragraph/CtrlShapeOle.h index 97bd07b4ec..33e2305dae 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeOle.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeOle.h @@ -19,7 +19,7 @@ public: CCtrlShapeOle(const HWP_STRING& sCtrlID); CCtrlShapeOle(const CCtrlGeneralShape& oShape); CCtrlShapeOle(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlShapeOle(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlShapeOle(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); EShapeType GetShapeType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapePic.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapePic.cpp index 9d49958d92..2fc3af9b34 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapePic.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapePic.cpp @@ -25,7 +25,7 @@ CPicColor::CPicColor(CHWPStream& oBuffer, int nOff, int nSize) m_nSize = nSize; } -CPicColor::CPicColor(CXMLNode& oNode) +CPicColor::CPicColor(CXMLReader& oReader) { //TODO:: проверить m_nType = 0; @@ -65,33 +65,54 @@ CShadow::CShadow(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize) m_nSize = oBuffer.GetDistanceToLastPos(true); } -CShadow::CShadow(CXMLNode& oNode, int nVersion) +CShadow::CShadow(CXMLReader& oReader, int nVersion) : CPicEffect(EPicEffectType::SHADOW), m_pColor(nullptr) { - m_nStyle = oNode.GetAttributeInt(L"style"); - m_nTransparency = oNode.GetAttributeInt(L"alpha"); - m_nBlur = oNode.GetAttributeInt(L"radius"); - m_nDirection = oNode.GetAttributeInt(L"direction"); - m_nDistance = oNode.GetAttributeInt(L"distance"); - m_nRotation = (int)oNode.GetAttributeBool(L"rotationStyle"); - - for (CXMLNode& oChild : oNode.GetChilds()) + START_READ_ATTRIBUTES(oReader) { - if (L"hp:skew" == oChild.GetName()) - { - m_fAngleX = oChild.GetAttributeDouble(L"x"); - m_fAngleY = oChild.GetAttributeDouble(L"y"); - } - else if (L"hp:scale" == oChild.GetName()) - { - m_fMagnifyX = oChild.GetAttributeDouble(L"x"); - m_fMagnifyY = oChild.GetAttributeDouble(L"y"); - } - else if (L"hp:effectsColor" == oChild.GetName()) - { - m_pColor = new CPicColor(oChild); - } + if ("style" == sAttributeName) + m_nStyle = oReader.GetInt(); + else if ("alpha" == sAttributeName) + m_nTransparency = oReader.GetInt(); + else if ("radius" == sAttributeName) + m_nBlur = oReader.GetInt(); + else if ("direction" == sAttributeName) + m_nDirection = oReader.GetInt(); + else if ("distance" == sAttributeName) + m_nDistance = oReader.GetInt(); + else if ("rotationStyle" == sAttributeName) + m_nRotation = (int)oReader.GetBool(); } + END_READ_ATTRIBUTES(oReader) + + WHILE_READ_NEXT_NODE_WITH_NAME(oReader) + { + if ("hp:skew" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_fAngleX = oReader.GetInt(); + else if ("y" == sAttributeName) + m_fAngleY = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hp:scale" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + m_fMagnifyX = oReader.GetInt(); + else if ("y" == sAttributeName) + m_fMagnifyY = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hp:effectsColor" == sNodeName) + m_pColor = new CPicColor(oReader); + } + END_WHILE } CShadow::~CShadow() @@ -112,14 +133,24 @@ CNeon::CNeon(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize) m_nSize = oBuffer.GetDistanceToLastPos(true); } -CNeon::CNeon(CXMLNode& oNode, int nVersion) +CNeon::CNeon(CXMLReader& oReader, int nVersion) : CPicEffect(EPicEffectType::GLOW), m_pColor(nullptr) { - m_fTransparency = oNode.GetAttributeDouble(L"alpha"); - m_fRadius = oNode.GetAttributeDouble(L"radius"); + START_READ_ATTRIBUTES(oReader) + { + if ("alpha" == sAttributeName) + m_fTransparency = oReader.GetDouble(); + else if ("radius" == sAttributeName) + m_fRadius = oReader.GetDouble(); + } + END_READ_ATTRIBUTES(oReader) - CXMLNode oChild{oNode.GetChild(L"hp:effectsColor")}; - m_pColor = new CPicColor(oChild); + WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "hp:effectsColor") + { + m_pColor = new CPicColor(oReader); + break; + } + END_WHILE } CNeon::~CNeon() @@ -136,10 +167,10 @@ CSoftEdge::CSoftEdge(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize) m_nSize = 4; } -CSoftEdge::CSoftEdge(CXMLNode& oNode, int nVersion) +CSoftEdge::CSoftEdge(CXMLReader& oReader, int nVersion) : CPicEffect(EPicEffectType::SOFT_EDGE) { - m_fRadius = oNode.GetAttributeDouble(L"radius"); + m_fRadius = oReader.GetAttributeDouble("radius"); } CReflect::CReflect(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize) @@ -165,38 +196,48 @@ CReflect::CReflect(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize) m_nSize = oBuffer.GetDistanceToLastPos(true); } -CReflect::CReflect(CXMLNode& oNode, int nVersion) +CReflect::CReflect(CXMLReader& oReader, int nVersion) : CPicEffect(EPicEffectType::REFLECT) { - m_fRadius = oNode.GetAttributeDouble(L"radius"); - m_fDirection = oNode.GetAttributeInt(L"direction"); - m_fDistance = oNode.GetAttributeInt(L"distance"); - m_nRotateStyle = (int)oNode.GetAttributeBool(L"rotationStyle"); - m_fOffsetDirection = oNode.GetAttributeInt(L"fadeDirection"); - - for (CXMLNode& oChild : oNode.GetChilds()) + START_READ_ATTRIBUTES(oReader) { - if (L"hp:skew" == oChild.GetName()) - { - m_fAngleX = oChild.GetAttributeDouble(L"x"); - m_fAngleY = oChild.GetAttributeDouble(L"y"); - } - else if (L"hp:scale" == oChild.GetName()) - { - m_fMagnifyX = oChild.GetAttributeDouble(L"x"); - m_fMagnifyY = oChild.GetAttributeDouble(L"y"); - } - else if (L"hp:alpha" == oChild.GetName()) - { - m_fStartTrans = oChild.GetAttributeDouble(L"start"); - m_fEndTrans = oChild.GetAttributeDouble(L"end"); - } - else if (L"hp:pos" == oChild.GetName()) - { - m_fStartPos = oChild.GetAttributeDouble(L"start"); - m_fEndPos = oChild.GetAttributeDouble(L"end"); - } + if ("radius" == sAttributeName) + m_fRadius = oReader.GetDouble(); + else if ("direction" == sAttributeName) + m_fDirection = oReader.GetDouble(); + else if ("distance" == sAttributeName) + m_fDistance = oReader.GetDouble(); + else if ("rotationStyle" == sAttributeName) + m_nRotateStyle = (int)oReader.GetBool(); + else if ("fadeDirection" == sAttributeName) + m_fOffsetDirection = oReader.GetDouble(); } + END_READ_ATTRIBUTES(oReader) + + #define READ_VALUES(value_1_name, value_1_variable, value_2_name, value_2_variable)\ + {\ + START_READ_ATTRIBUTES(oReader)\ + {\ + if (value_1_name == sAttributeName)\ + value_1_variable = oReader.GetDouble();\ + else if (value_2_name == sAttributeName)\ + value_2_variable = oReader.GetDouble();\ + }\ + END_READ_ATTRIBUTES(oReader)\ + } + + WHILE_READ_NEXT_NODE_WITH_NAME(oReader) + { + if ("hp:skew" == sNodeName) + READ_VALUES("x", m_fAngleX, "y", m_fAngleY) + else if ("hp:scale" == sNodeName) + READ_VALUES("x", m_fMagnifyX, "y", m_fMagnifyY) + else if ("hp:alpha" == sNodeName) + READ_VALUES("start", m_fStartTrans, "end", m_fEndTrans) + else if ("hp:pos" == sNodeName) + READ_VALUES("start", m_fStartPos, "end", m_fEndPos) + } + END_WHILE } CCtrlShapePic::CCtrlShapePic() @@ -215,69 +256,105 @@ CCtrlShapePic::CCtrlShapePic(const HWP_STRING& sCtrlID, int nSize, CHWPStream& o : CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlShapePic::CCtrlShapePic(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlGeneralShape(sCtrlID, oNode, nVersion) +CCtrlShapePic::CCtrlShapePic(const HWP_STRING& sCtrlID, HWP::CXMLReader& oReader, int nVersion) + : CCtrlGeneralShape(sCtrlID, oReader, nVersion) { - for (CXMLNode& oChild : oNode.GetChilds()) + WHILE_READ_NEXT_NODE_WITH_NAME(oReader) { - if (L"hp:imgRect" == oChild.GetName()) + if ("hp:imgRect" == sNodeName) { - for (CXMLNode& oGrandChild : oChild.GetChilds()) + #define READ_POINT(index_point)\ + {\ + START_READ_ATTRIBUTES(oReader)\ + {\ + if ("x" == sAttributeName)\ + m_arBorderPoints[index_point].m_nX = oReader.GetInt();\ + else if ("y" == sAttributeName)\ + m_arBorderPoints[index_point].m_nY = oReader.GetInt();\ + }\ + END_READ_ATTRIBUTES(oReader)\ + } + + WHILE_READ_NEXT_NODE_WITH_DEPTH_AND_NAME(oReader, Child) { - for (unsigned int unIndex = 0; unIndex < 4; ++unIndex) + if ("hc:pt0" == sNodeChildName) + READ_POINT(0) + else if ("hc:pt1" == sNodeChildName) + READ_POINT(1) + else if ("hc:pt2" == sNodeChildName) + READ_POINT(2) + else if ("hc:pt3" == sNodeChildName) + READ_POINT(3) + } + END_WHILE + } + else if ("hp:imgClip" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("left" == sAttributeName) + m_nCropLeft = oReader.GetInt(); + else if ("right" == sAttributeName) + m_nCropRight = oReader.GetInt(); + else if ("top" == sAttributeName) + m_nCropTop = oReader.GetInt(); + else if ("bottom" == sAttributeName) + m_nCropBottom = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hp:effects" == sNodeName) + { + WHILE_READ_NEXT_NODE_WITH_DEPTH_AND_NAME(oReader, Child) + { + if ("hp:shadow" == sNodeChildName) + m_arPicEffect.push_back(new CShadow(oReader, nVersion)); + else if ("hp:glow" == sNodeChildName) + m_arPicEffect.push_back(new CNeon(oReader, nVersion)); + else if ("hp:softEdge" == sNodeChildName) + m_arPicEffect.push_back(new CSoftEdge(oReader, nVersion)); + else if ("hp:reflection" == sNodeChildName) + m_arPicEffect.push_back(new CReflect(oReader, nVersion)); + } + END_WHILE + } + else if ("hc:img" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("bright" == sAttributeName) + m_chBright = (HWP_BYTE)oReader.GetInt(); + else if ("contrast" == sAttributeName) + m_chContrast = (HWP_BYTE)oReader.GetInt(); + else if ("effect" == sAttributeName) { - if ((L"hc:pt" + std::to_wstring(unIndex)) == oGrandChild.GetName()) - { - m_arBorderPoints[unIndex].m_nX = oGrandChild.GetAttributeInt(L"x"); - m_arBorderPoints[unIndex].m_nY = oGrandChild.GetAttributeInt(L"y"); - break; - } + const std::string sType{oReader.GetText2A()}; + + if ("REAL_PIC" == sType) + m_chEffect = 0; + else if ("GRAY_SCALE" == sType) + m_chEffect = 1; + else if ("BLACK_WHITE" == sType) + m_chEffect = 2; } + else if ("binaryItemIDRef" == sAttributeName) + m_sBinDataID = oReader.GetText2(); } + END_READ_ATTRIBUTES(oReader) } - else if (L"hp:imgClip" == oChild.GetName()) + else if ("hp:imgDim" == sNodeName) { - m_nCropLeft = oChild.GetAttributeInt(L"left"); - m_nCropRight = oChild.GetAttributeInt(L"right"); - m_nCropTop = oChild.GetAttributeInt(L"top"); - m_nCropBottom = oChild.GetAttributeInt(L"bottom"); - } - else if (L"hp:effects" == oChild.GetName()) - { - for (CXMLNode& oGrandChild : oChild.GetChilds()) + START_READ_ATTRIBUTES(oReader) { - if (L"hp:shadow" == oGrandChild.GetName()) - m_arPicEffect.push_back(new CShadow(oGrandChild, nVersion)); - else if (L"hp:glow" == oGrandChild.GetName()) - m_arPicEffect.push_back(new CNeon(oGrandChild, nVersion)); - else if (L"hp:softEdge" == oGrandChild.GetName()) - m_arPicEffect.push_back(new CSoftEdge(oGrandChild, nVersion)); - else if (L"hp:reflection" == oGrandChild.GetName()) - m_arPicEffect.push_back(new CReflect(oGrandChild, nVersion)); + if ("dimwidth" == sAttributeName) + m_nIniPicWidth = oReader.GetInt(); + else if ("dimheight" == sAttributeName) + m_nIniPicHeight = oReader.GetInt(); } - } - else if (L"hc:img" == oChild.GetName()) - { - m_chBright = (HWP_BYTE)oChild.GetAttributeInt(L"bright"); - m_chContrast = (HWP_BYTE)oChild.GetAttributeInt(L"contrast"); - - HWP_STRING sType = oChild.GetAttribute(L"effect"); - - if (L"REAL_PIC" == sType) - m_chEffect = 0; - else if (L"GRAY_SCALE" == sType) - m_chEffect = 1; - else if (L"BLACK_WHITE" == sType) - m_chEffect = 2; - - m_sBinDataID = oChild.GetAttribute(L"binaryItemIDRef"); - } - else if (L"hp:imgDim" == oChild.GetName()) - { - m_nIniPicWidth = oChild.GetAttributeInt(L"dimwidth"); - m_nIniPicHeight = oChild.GetAttributeInt(L"dimheight"); + END_READ_ATTRIBUTES(oReader) } } + END_WHILE } CCtrlShapePic::~CCtrlShapePic() diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapePic.h b/HwpFile/HwpDoc/Paragraph/CtrlShapePic.h index deaaa9479b..21c9b25e4d 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapePic.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapePic.h @@ -31,7 +31,7 @@ class CPicColor int m_nRGB; public: CPicColor(CHWPStream& oBuffer, int nOff, int nSize); - CPicColor(CXMLNode& oNode); + CPicColor(CXMLReader& oReader); }; class CPicEffect @@ -61,7 +61,7 @@ class CShadow : public CPicEffect CPicColor *m_pColor; public: CShadow(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize); - CShadow(CXMLNode& oNode, int nVersion); + CShadow(CXMLReader& oReader, int nVersion); ~CShadow(); }; @@ -72,7 +72,7 @@ class CNeon : public CPicEffect CPicColor *m_pColor; public: CNeon(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize); - CNeon(CXMLNode& oNode, int nVersion); + CNeon(CXMLReader& oReader, int nVersion); ~CNeon(); }; @@ -81,7 +81,7 @@ class CSoftEdge : public CPicEffect float m_fRadius; public: CSoftEdge(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize); - CSoftEdge(CXMLNode& oNode, int nVersion); + CSoftEdge(CXMLReader& oReader, int nVersion); }; class CReflect : public CPicEffect @@ -102,7 +102,7 @@ class CReflect : public CPicEffect float m_fOffsetDirection; public: CReflect(int nTypeNum, CHWPStream& oBuffer, int nOff, int nSize); - CReflect(CXMLNode& oNode, int nVersion); + CReflect(CXMLReader& oReader, int nVersion); }; class CCtrlShapePic : public CCtrlGeneralShape @@ -134,7 +134,7 @@ public: CCtrlShapePic(const HWP_STRING& sCtrlID); CCtrlShapePic(const CCtrlGeneralShape& oShape); CCtrlShapePic(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlShapePic(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlShapePic(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); ~CCtrlShapePic(); EShapeType GetShapeType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.cpp index a5fe6ce9e3..8de49245b7 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.cpp @@ -17,18 +17,27 @@ CCtrlShapePolygon::CCtrlShapePolygon(const HWP_STRING& sCtrlID, int nSize, CHWPS : CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlShapePolygon::CCtrlShapePolygon(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlGeneralShape(sCtrlID, oNode, nVersion) +CCtrlShapePolygon::CCtrlShapePolygon(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlGeneralShape(sCtrlID, oReader, nVersion) { - std::vector arChilds{oNode.GetChilds(L"hc:pt")}; + TPoint oPoint{0, 0}; - m_arPoints.resize(arChilds.size()); - - for (unsigned int unIndex = 0; unIndex < arChilds.size(); ++unIndex) + WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "hc:pt") { - m_arPoints[unIndex].m_nX = arChilds[unIndex].GetAttributeInt(L"x"); - m_arPoints[unIndex].m_nY = arChilds[unIndex].GetAttributeInt(L"y"); + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + oPoint.m_nX = oReader.GetInt(); + else if ("y" == sAttributeName) + oPoint.m_nY = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + + m_arPoints.push_back(oPoint); + + oPoint = {0, 0}; } + END_WHILE m_nPoints = m_arPoints.size(); } diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.h b/HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.h index 0aa129fde4..ef41a5921d 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapePolygon.h @@ -15,7 +15,7 @@ public: CCtrlShapePolygon(const HWP_STRING& sCtrlID); CCtrlShapePolygon(const CCtrlGeneralShape& oShape); CCtrlShapePolygon(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlShapePolygon(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlShapePolygon(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); EShapeType GetShapeType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeRect.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeRect.cpp index f01f39ecd2..54ef77b4f4 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeRect.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeRect.cpp @@ -17,20 +17,35 @@ CCtrlShapeRect::CCtrlShapeRect(const HWP_STRING& sCtrlID, int nSize, CHWPStream& : CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlShapeRect::CCtrlShapeRect(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlGeneralShape(sCtrlID, oNode, nVersion) +CCtrlShapeRect::CCtrlShapeRect(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlGeneralShape(sCtrlID, oReader, nVersion) { - m_chCurv = (HWP_BYTE)oNode.GetAttributeInt(L"ratio"); + m_chCurv = (HWP_BYTE)oReader.GetAttributeInt("ratio"); - for (unsigned int unIndex = 0; unIndex < 4; ++unIndex) - { - if ((L"hc:pt" + std::to_wstring(unIndex)) == oNode.GetName()) - { - m_arPoints[unIndex].m_nX = oNode.GetAttributeInt(L"x"); - m_arPoints[unIndex].m_nY = oNode.GetAttributeInt(L"y"); - break; - } + #define READ_POINT(point_index)\ + {\ + START_READ_ATTRIBUTES(oReader)\ + {\ + if ("x" == sAttributeName)\ + m_arPoints[point_index].m_nX = oReader.GetInt();\ + else if ("y" == sAttributeName)\ + m_arPoints[point_index].m_nY = oReader.GetInt();\ + }\ + END_READ_ATTRIBUTES(oReader)\ } + + WHILE_READ_NEXT_NODE_WITH_NAME(oReader) + { + if ("hc:pt0" == sNodeName) + READ_POINT(0) + else if ("hc:pt1" == sNodeName) + READ_POINT(1) + else if ("hc:pt2" == sNodeName) + READ_POINT(2) + else if ("hc:pt3" == sNodeName) + READ_POINT(3) + } + END_WHILE } EShapeType CCtrlShapeRect::GetShapeType() const diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeRect.h b/HwpFile/HwpDoc/Paragraph/CtrlShapeRect.h index ad12478cac..bab8e5102e 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeRect.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeRect.h @@ -15,7 +15,7 @@ public: CCtrlShapeRect(const HWP_STRING& sCtrlID); CCtrlShapeRect(const CCtrlGeneralShape& oShape); CCtrlShapeRect(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlShapeRect(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlShapeRect(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); EShapeType GetShapeType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.cpp index 7436ab8657..7d3a211d9a 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.cpp @@ -17,58 +17,79 @@ CCtrlShapeTextArt::CCtrlShapeTextArt(const HWP_STRING& sCtrlID, int nSize, CHWPS : CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlShapeTextArt::CCtrlShapeTextArt(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlGeneralShape(sCtrlID, oNode, nVersion) +CCtrlShapeTextArt::CCtrlShapeTextArt(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlGeneralShape(sCtrlID, oReader, nVersion) { - m_sText = oNode.GetAttribute(L"text"); + m_sText = oReader.GetAttribute("text"); - for (CXMLNode& oChild : oNode.GetChilds()) + #define READ_POINT(variable_point)\ + {\ + START_READ_ATTRIBUTES(oReader)\ + {\ + if ("x" == sAttributeName)\ + variable_point.m_nX = oReader.GetInt();\ + else if ("y" == sAttributeName)\ + variable_point.m_nY = oReader.GetInt();\ + }\ + END_READ_ATTRIBUTES(oReader)\ + } + + WHILE_READ_NEXT_NODE_WITH_NAME(oReader) { - if (L"hp:pt0" == oChild.GetName()) + if ("hp:pt0" == sNodeName) + READ_POINT(m_oPt0) + else if ("hp:pt1" == sNodeName) + READ_POINT(m_oPt1) + else if ("hp:pt2" == sNodeName) + READ_POINT(m_oPt2) + else if ("hp:pt3" == sNodeName) + READ_POINT(m_oPt3) + else if ("hp:textartPr" == sNodeName) { - m_oPt0.m_nX = oNode.GetAttributeInt(L"x"); - m_oPt0.m_nY = oNode.GetAttributeInt(L"y"); - } - else if (L"hp:pt1" == oChild.GetName()) - { - m_oPt1.m_nX = oNode.GetAttributeInt(L"x"); - m_oPt1.m_nY = oNode.GetAttributeInt(L"y"); - } - else if (L"hp:pt2" == oChild.GetName()) - { - m_oPt2.m_nX = oNode.GetAttributeInt(L"x"); - m_oPt2.m_nY = oNode.GetAttributeInt(L"y"); - } - else if (L"hp:pt3" == oChild.GetName()) - { - m_oPt3.m_nX = oNode.GetAttributeInt(L"x"); - m_oPt3.m_nY = oNode.GetAttributeInt(L"y"); - } - else if (L"hp:textartPr" == oChild.GetName()) - { - m_sFontName = oChild.GetAttribute(L"fontName"); - m_sFontStyle = oChild.GetAttribute(L"fontStyle"); - m_sFontType = oChild.GetAttribute(L"fontType"); - m_sTextShape = oChild.GetAttribute(L"textShape"); - m_sFontStyle = oChild.GetAttribute(L"fontStyle"); - m_shLineSpacing = oChild.GetAttributeInt(L"lineSpacing"); - m_shSpacing = oChild.GetAttributeInt(L"spacing"); - m_sAlign = oChild.GetAttribute(L"align"); - - //TODO:: реализовать shadows - } - else if (L"hp:outline" == oChild.GetName()) - { - std::vector arGrandChilds{oChild.GetChilds(L"hp:pt")}; - m_arOutline.resize(arGrandChilds.size()); - - for (unsigned int unIndex = 0; unIndex < arGrandChilds.size(); ++unIndex) + START_READ_ATTRIBUTES(oReader) { - m_arOutline[unIndex].m_nX = arGrandChilds[unIndex].GetAttributeInt(L"x"); - m_arOutline[unIndex].m_nY = arGrandChilds[unIndex].GetAttributeInt(L"y"); + if ("fontName" == sAttributeName) + m_sFontName = oReader.GetText2(); + else if ("fontStyle" == sAttributeName) + m_sFontStyle = oReader.GetText2(); + else if ("fontType" == sAttributeName) + m_sFontType = oReader.GetText2(); + else if ("textShape" == sAttributeName) + m_sTextShape = oReader.GetText2(); + else if ("align" == sAttributeName) + m_sAlign = oReader.GetText2(); + else if ("lineSpacing" == sAttributeName) + m_shLineSpacing = oReader.GetInt(); + else if ("spacing" == sAttributeName) + m_shSpacing = oReader.GetInt(); + + //TODO:: реализовать shadows } + END_READ_ATTRIBUTES(oReader) + } + else if ("hp:outline" == sNodeName) + { + TPoint oPoint{0, 0}; + + WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "hp:pt") + { + START_READ_ATTRIBUTES(oReader) + { + if ("x" == sAttributeName) + oPoint.m_nX = oReader.GetInt(); + else if ("y" == sAttributeName) + oPoint.m_nY = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + + m_arOutline.push_back(oPoint); + + oPoint = {0, 0}; + } + END_WHILE } } + END_WHILE } EShapeType CCtrlShapeTextArt::GetShapeType() const diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.h b/HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.h index 37ba39b597..e653789804 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeTextArt.h @@ -28,7 +28,7 @@ public: CCtrlShapeTextArt(const HWP_STRING& sCtrlID); CCtrlShapeTextArt(const CCtrlGeneralShape& oShape); CCtrlShapeTextArt(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlShapeTextArt(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlShapeTextArt(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); EShapeType GetShapeType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.cpp b/HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.cpp index afb2f8736a..6e9e816aa6 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.cpp @@ -14,21 +14,28 @@ CCtrlShapeVideo::CCtrlShapeVideo(const HWP_STRING& sCtrlID, int nSize, CHWPStrea : CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlShapeVideo::CCtrlShapeVideo(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlGeneralShape(sCtrlID, oNode, nVersion) +CCtrlShapeVideo::CCtrlShapeVideo(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlGeneralShape(sCtrlID, oReader, nVersion) { - HWP_STRING sType = oNode.GetAttribute(L"videotype"); + START_READ_ATTRIBUTES(oReader) + { + if ("type" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; - if (L"Local" == sType) - m_nVideoType = 0; - else if (L"Web" == sType) - m_nVideoType = 1; - - m_shVideoBinID = oNode.GetAttributeInt(L"fileIDRef"); - m_sThumnailBinID = oNode.GetAttribute(L"imageIDRef"); - - if (1 == m_nVideoType) - m_sWebURL = oNode.GetAttribute(L"tag"); + if ("Local" == sType) + m_nVideoType = 0; + else if ("Web" == sType) + m_nVideoType = 1; + } + else if ("fileIDRef" == sAttributeName) + m_shVideoBinID = oReader.GetInt(); + else if ("imageIDRef" == sAttributeName) + m_sThumnailBinID = oReader.GetInt(); + else if ("tag" == sAttributeName) + m_sWebURL = oReader.GetText2(); + } + END_READ_ATTRIBUTES(oReader) } EShapeType CCtrlShapeVideo::GetShapeType() const diff --git a/HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.h b/HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.h index d3716a2bfe..3e6469b823 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlShapeVideo.h @@ -15,7 +15,7 @@ public: CCtrlShapeVideo(const HWP_STRING& sCtrlID); CCtrlShapeVideo(const CCtrlGeneralShape& oShape); CCtrlShapeVideo(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlShapeVideo(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlShapeVideo(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); EShapeType GetShapeType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/CtrlTable.cpp b/HwpFile/HwpDoc/Paragraph/CtrlTable.cpp index 786b580bea..1be8bd1735 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlTable.cpp +++ b/HwpFile/HwpDoc/Paragraph/CtrlTable.cpp @@ -10,44 +10,72 @@ CCtrlTable::CCtrlTable(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer : CCtrlCommon(sCtrlID, nSize, oBuffer, nOff, nVersion) {} -CCtrlTable::CCtrlTable(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) - : CCtrlCommon(sCtrlID, oNode, nVersion) +CCtrlTable::CCtrlTable(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion) + : CCtrlCommon(sCtrlID, oReader, nVersion) { - m_shNRows = oNode.GetAttributeInt(L"rowCnt"); - m_shNCols = oNode.GetAttributeInt(L"colCnt"); - m_shCellSpacing = oNode.GetAttributeInt(L"cellSpacing"); - m_shBorderFillID = oNode.GetAttributeInt(L"borderFillIDRef"); - - for (CXMLNode& oChild : oNode.GetChilds()) + START_READ_ATTRIBUTES(oReader) { - if (L"hp:inMargin" == oChild.GetName()) + if ("rowCnt" == sAttributeName) + m_shNRows = oReader.GetInt(); + else if ("colCnt" == sAttributeName) + m_shNCols = oReader.GetInt(); + else if ("cellSpacing" == sAttributeName) + m_shCellSpacing = oReader.GetInt(); + else if ("borderFillIDRef" == sAttributeName) + m_shBorderFillID = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + + WHILE_READ_NEXT_NODE_WITH_NAME(oReader) + { + if ("hp:inMargin" == sNodeName) { - m_shInLSpace = oChild.GetAttributeInt(L"left"); - m_shInRSpace = oChild.GetAttributeInt(L"right"); - m_shInTSpace = oChild.GetAttributeInt(L"top"); - m_shInBSpace = oChild.GetAttributeInt(L"bottom"); + START_READ_ATTRIBUTES(oReader) + { + if ("left" == sAttributeName) + m_shInLSpace = oReader.GetInt(); + else if ("right" == sAttributeName) + m_shInRSpace = oReader.GetInt(); + else if ("top" == sAttributeName) + m_shInTSpace = oReader.GetInt(); + else if ("bottom" == sAttributeName) + m_shInBSpace = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } - else if (L"hp:cellzoneList" == oChild.GetName()) + else if ("hp:cellzoneList" == sNodeName) { - for (CXMLNode& oGrandChild : oChild.GetChilds(L"hp:cellzone")) + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Child, "hp:cellzone") { TCellZone* pCellZone = new TCellZone(); - pCellZone->m_shStartRowAddr = oGrandChild.GetAttributeInt(L"startRowAddr"); - pCellZone->m_shStartColAddr = oGrandChild.GetAttributeInt(L"startColAddr"); - pCellZone->m_shEndRowAddr = oGrandChild.GetAttributeInt(L"endRowAddr"); - pCellZone->m_shEndColAddr = oGrandChild.GetAttributeInt(L"endColAddr"); - pCellZone->m_shBorderFillIDRef = oGrandChild.GetAttributeInt(L"borderFillIDRef"); + START_READ_ATTRIBUTES(oReader) + { + if ("startRowAddr" == sAttributeName) + pCellZone->m_shStartRowAddr = oReader.GetInt(); + else if ("startColAddr" == sAttributeName) + pCellZone->m_shStartColAddr = oReader.GetInt(); + else if ("endRowAddr" == sAttributeName) + pCellZone->m_shEndRowAddr = oReader.GetInt(); + else if ("endColAddr" == sAttributeName) + pCellZone->m_shEndColAddr = oReader.GetInt(); + else if ("borderFillIDRef" == sAttributeName) + pCellZone->m_shBorderFillIDRef = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) m_arCellzoneList.push_back(pCellZone); } + END_WHILE } - else if(L"hp:tr" == oChild.GetName()) + else if ("hp:tr" == sNodeName) { - for (CXMLNode& oGrandChild : oChild.GetChilds(L"hp:tc")) - m_arCells.push_back(new CTblCell(oGrandChild, nVersion)); + WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Child, "hp:tc") + m_arCells.push_back(new CTblCell(oReader, nVersion)); + END_WHILE } } + END_WHILE } CCtrlTable::~CCtrlTable() diff --git a/HwpFile/HwpDoc/Paragraph/CtrlTable.h b/HwpFile/HwpDoc/Paragraph/CtrlTable.h index 8b4613299c..4c1dff33c9 100644 --- a/HwpFile/HwpDoc/Paragraph/CtrlTable.h +++ b/HwpFile/HwpDoc/Paragraph/CtrlTable.h @@ -32,7 +32,7 @@ class CCtrlTable : public CCtrlCommon public: CCtrlTable(const HWP_STRING& sCtrlID); CCtrlTable(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CCtrlTable(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion); + CCtrlTable(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion); ~CCtrlTable(); ECtrlObjectType GetCtrlType() const override; diff --git a/HwpFile/HwpDoc/Paragraph/HWPPargraph.cpp b/HwpFile/HwpDoc/Paragraph/HWPPargraph.cpp index b399fb85f4..e5b5d3b8ca 100644 --- a/HwpFile/HwpDoc/Paragraph/HWPPargraph.cpp +++ b/HwpFile/HwpDoc/Paragraph/HWPPargraph.cpp @@ -25,37 +25,56 @@ CHWPPargraph::CHWPPargraph() : m_pLineSegs(nullptr) {} -CHWPPargraph::CHWPPargraph(CXMLNode& oNode, int nVersion) +CHWPPargraph::CHWPPargraph(CXMLReader& oReader, int nVersion) : m_chBreakType(0), m_pLineSegs(nullptr) { - m_shParaShapeID = oNode.GetAttributeInt(L"paraPrIDRef"); - m_shParaStyleID = oNode.GetAttributeInt(L"styleIDRef"); - - if (oNode.GetAttributeBool(L"pageBreak")) - m_chBreakType |= 0b00000100; - else - m_chBreakType &= 0b11111011; - - if (oNode.GetAttributeBool(L"columnBreak")) - m_chBreakType |= 0b00001000; - else - m_chBreakType &= 0b11110111; + START_READ_ATTRIBUTES(oReader) + { + if ("paraPrIDRef" == sAttributeName) + m_shParaShapeID = oReader.GetInt(); + else if ("styleIDRef" == sAttributeName) + m_shParaStyleID = oReader.GetInt(); + else if ("pageBreak" == sAttributeName) + { + if (oReader.GetBool()) + m_chBreakType |= 0b00000100; + else + m_chBreakType &= 0b11111011; + } + else if ("columnBreak" == sAttributeName) + { + if (oReader.GetBool()) + m_chBreakType |= 0b00001000; + else + m_chBreakType &= 0b11110111; + } + } + END_READ_ATTRIBUTES(oReader) int nCharShapeID = 0; + std::string sNodeName; - for (CXMLNode& oChild : oNode.GetChilds()) + WHILE_READ_NEXT_NODE(oReader) { - if (L"hp:run" == oChild.GetName()) - { - nCharShapeID = oChild.GetAttributeInt(L"charPrIDRef"); + sNodeName = oReader.GetNameA(); - for (CXMLNode& oGrandChild : oChild.GetChilds()) - ParseHWPParagraph(oGrandChild, nCharShapeID, nVersion); - } - else if (L"hp:linesegarray" == oChild.GetName()) + if ("hp:run" == sNodeName) { - CXMLNode oGrandChild{oChild.GetChild(L"hp:lineseg")}; - m_pLineSegs = new CLineSeg(oGrandChild, nVersion); + nCharShapeID = oReader.GetAttributeInt("charPrIDRef"); + + WHILE_READ_NEXT_NODE(oReader) + ParseHWPParagraph(oReader, nCharShapeID, nVersion); + } + else if ("hp:linesegarray" == sNodeName) + { + WHILE_READ_NEXT_NODE(oReader) + { + if ("hp:lineseg" != oReader.GetNameA()) + continue; + + m_pLineSegs = new CLineSeg(oReader, nVersion); + break; + } } } @@ -69,79 +88,84 @@ CHWPPargraph::~CHWPPargraph() delete m_pLineSegs; } -bool CHWPPargraph::ParseHWPParagraph(CXMLNode& oNode, int nCharShapeID, int nVersion) +bool CHWPPargraph::ParseHWPParagraph(CXMLReader& oReader, int nCharShapeID, int nVersion) { const size_t unCurrentParaCount = m_arP.size(); - if (L"hp:secPr" == oNode.GetName()) - m_arP.push_back(new CCtrlSectionDef(L"dces", oNode, nVersion)); - else if (L"hp:ctrl" == oNode.GetName()) - { - for(CXMLNode& oChild : oNode.GetChilds()) - AddCtrl(CCtrl::GetCtrl(oChild, nVersion)); - } - else if (L"hp:t" == oNode.GetName()) - { - m_arP.push_back(new CParaText(L"____", oNode.GetText(), 0, nCharShapeID)); + const std::string sNodeName{oReader.GetNameA()}; - for(CXMLNode& oChild : oNode.GetChilds()) + if ("hp:secPr" == sNodeName) + m_arP.push_back(new CCtrlSectionDef(L"dces", oReader, nVersion)); + else if ("hp:ctrl" == sNodeName) + { + WHILE_READ_NEXT_NODE(oReader) + AddCtrl(CCtrl::GetCtrl(oReader, nVersion)); + } + else if ("hp:t" == sNodeName) + { + m_arP.push_back(new CParaText(L"____", oReader.GetText(), 0, nCharShapeID)); + + std::string sChildNodeName; + + WHILE_READ_NEXT_NODE(oReader) { - if (L"hp:lineBreak" == oChild.GetName()) + sChildNodeName = oReader.GetNameA(); + + if ("hp:lineBreak" == sChildNodeName) m_arP.push_back(new CCtrlCharacter(L" _", ECtrlCharType::LINE_BREAK)); - else if (L"hp:hyphen" == oChild.GetName()) + else if ("hp:hyphen" == sChildNodeName) m_arP.push_back(new CCtrlCharacter(L" _", ECtrlCharType::HARD_HYPHEN)); - else if (L"hp:nbSpace" == oChild.GetName()|| - L"hp:fwSpace" == oChild.GetName()) + else if ("hp:nbSpace" == sChildNodeName || + "hp:fwSpace" == sChildNodeName) m_arP.push_back(new CCtrlCharacter(L" _", ECtrlCharType::HARD_SPACE)); - else if (L"hp:tab" == oChild.GetName()) - m_arP.push_back(new CParaText(L"____", L"\t", 0)); + else if ("hp:tab" == sChildNodeName) + m_arP.push_back(new CCtrlCharacter(L" _", ECtrlCharType::TABULATION)); } } - else if (L"hp:tbl" == oNode.GetName()) - m_arP.push_back(new CCtrlTable(L" lbt", oNode, nVersion)); - else if (L"hp:pic" == oNode.GetName()) - m_arP.push_back(new CCtrlShapePic(L"cip$", oNode, nVersion)); - else if (L"hp:container" == oNode.GetName()) - m_arP.push_back(new CCtrlContainer(L"noc$", oNode, nVersion)); - else if (L"hp:ole" == oNode.GetName()) - m_arP.push_back(new CCtrlShapeOle(L"elo$", oNode, nVersion)); - else if (L"hp:equation" == oNode.GetName()) - m_arP.push_back(new CCtrlEqEdit(L"deqe", oNode, nVersion)); - else if (L"hp:line" == oNode.GetName()) - m_arP.push_back(new CCtrlShapeLine(L"nil$", oNode, nVersion)); - else if (L"hp:rect" == oNode.GetName()) - m_arP.push_back(new CCtrlShapeRect(L"cer$", oNode, nVersion)); - else if (L"hp:ellipse" == oNode.GetName()) - m_arP.push_back(new CCtrlShapeEllipse(L"lle$", oNode, nVersion)); - else if (L"hp:arc" == oNode.GetName()) - m_arP.push_back(new CCtrlShapeArc(L"cra$", oNode, nVersion)); - else if (L"hp:polygon" == oNode.GetName()) - m_arP.push_back(new CCtrlShapePolygon(L"lop$", oNode, nVersion)); - else if (L"hp:curve" == oNode.GetName()) - m_arP.push_back(new CCtrlShapeCurve(L"ruc$", oNode, nVersion)); - else if (L"hp:connectLine" == oNode.GetName()) - m_arP.push_back(new CCtrlShapeConnectLine(L"loc$", oNode, nVersion)); - else if (L"hp:textart" == oNode.GetName()) - m_arP.push_back(new CCtrlShapeTextArt(L"tat$", oNode, nVersion)); - else if (L"hp:video" == oNode.GetName()) - m_arP.push_back(new CCtrlShapeVideo(L"div$", oNode, nVersion)); + else if ("hp:tbl" == sNodeName) + m_arP.push_back(new CCtrlTable(L" lbt", oReader, nVersion)); + else if ("hp:pic" == sNodeName) + m_arP.push_back(new CCtrlShapePic(L"cip$", oReader, nVersion)); + else if ("hp:container" == sNodeName) + m_arP.push_back(new CCtrlContainer(L"noc$", oReader, nVersion)); + else if ("hp:ole" == sNodeName) + m_arP.push_back(new CCtrlShapeOle(L"elo$", oReader, nVersion)); + else if ("hp:equation" == sNodeName) + m_arP.push_back(new CCtrlEqEdit(L"deqe", oReader, nVersion)); + else if ("hp:line" == sNodeName) + m_arP.push_back(new CCtrlShapeLine(L"nil$", oReader, nVersion)); + else if ("hp:rect" == sNodeName) + m_arP.push_back(new CCtrlShapeRect(L"cer$", oReader, nVersion)); + else if ("hp:ellipse" == sNodeName) + m_arP.push_back(new CCtrlShapeEllipse(L"lle$", oReader, nVersion)); + else if ("hp:arc" == sNodeName) + m_arP.push_back(new CCtrlShapeArc(L"cra$", oReader, nVersion)); + else if ("hp:polygon" == sNodeName) + m_arP.push_back(new CCtrlShapePolygon(L"lop$", oReader, nVersion)); + else if ("hp:curve" == sNodeName) + m_arP.push_back(new CCtrlShapeCurve(L"ruc$", oReader, nVersion)); + else if ("hp:connectLine" == sNodeName) + m_arP.push_back(new CCtrlShapeConnectLine(L"loc$", oReader, nVersion)); + else if ("hp:textart" == sNodeName) + m_arP.push_back(new CCtrlShapeTextArt(L"tat$", oReader, nVersion)); + else if ("hp:video" == sNodeName) + m_arP.push_back(new CCtrlShapeVideo(L"div$", oReader, nVersion)); if (unCurrentParaCount != m_arP.size()) return true; - if (L"hp:switch" == oNode.GetName()) + if ("hp:switch" == sNodeName) { - for (CXMLNode& oCaseChild : oNode.GetChilds(L"hp:case")) + WHILE_READ_NEXT_NODE(oReader) { - for (CXMLNode& oChild : oCaseChild.GetChilds()) - if (ParseHWPParagraph(oChild, nCharShapeID, nVersion)) + if ("hp:case" != oReader.GetNameA() && + "hp:default" != oReader.GetNameA()) + continue; + + WHILE_READ_NEXT_NODE(oReader) + if (ParseHWPParagraph(oReader, nCharShapeID, nVersion)) return true; } - - CXMLNode oDefaultChild{oNode.GetChild(L"hp:default")}; - for (CXMLNode& oChild : oDefaultChild.GetChilds()) - if (ParseHWPParagraph(oChild, nCharShapeID, nVersion)) - return true; } return false; diff --git a/HwpFile/HwpDoc/Paragraph/HWPPargraph.h b/HwpFile/HwpDoc/Paragraph/HWPPargraph.h index 7a18af0306..ec481f3ff2 100644 --- a/HwpFile/HwpDoc/Paragraph/HWPPargraph.h +++ b/HwpFile/HwpDoc/Paragraph/HWPPargraph.h @@ -4,7 +4,7 @@ #include "LineSeg.h" #include "RangeTag.h" #include "Ctrl.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -26,10 +26,10 @@ class CHWPPargraph : public IRef VECTOR m_arP; //HWPTAG_PARA_TEXT - bool ParseHWPParagraph(CXMLNode& oNode, int nCharShapeID, int nVersion); + bool ParseHWPParagraph(CXMLReader& oReader, int nCharShapeID, int nVersion); public: CHWPPargraph(); - CHWPPargraph(CXMLNode& oNode, int nVersion); + CHWPPargraph(CXMLReader& oReader, int nVersion); virtual ~CHWPPargraph(); virtual EParagraphType GetType() const; diff --git a/HwpFile/HwpDoc/Paragraph/LineSeg.cpp b/HwpFile/HwpDoc/Paragraph/LineSeg.cpp index b781577bb9..30b79f73ad 100644 --- a/HwpFile/HwpDoc/Paragraph/LineSeg.cpp +++ b/HwpFile/HwpDoc/Paragraph/LineSeg.cpp @@ -20,11 +20,18 @@ CLineSeg::CLineSeg(int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); } -CLineSeg::CLineSeg(CXMLNode& oNode, int nVersion) +CLineSeg::CLineSeg(CXMLReader& oReader, int nVersion) { //TODO:: реализовать - m_nLineSpacing = oNode.GetAttributeInt(L"spacing"); - m_nTextHeight = oNode.GetAttributeInt(L"textheight"); + + START_READ_ATTRIBUTES(oReader) + { + if ("spacing" == sAttributeName) + m_nLineSpacing = oReader.GetInt(); + else if ("textheight" == sAttributeName) + m_nTextHeight = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } int CLineSeg::GetLineSpacing() const diff --git a/HwpFile/HwpDoc/Paragraph/LineSeg.h b/HwpFile/HwpDoc/Paragraph/LineSeg.h index 56419e161b..ea4ba534be 100644 --- a/HwpFile/HwpDoc/Paragraph/LineSeg.h +++ b/HwpFile/HwpDoc/Paragraph/LineSeg.h @@ -2,7 +2,7 @@ #define LINESEG_H #include "../HWPStream.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -20,7 +20,7 @@ class CLineSeg bool m_bIsHeadingApplied; public: CLineSeg(int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CLineSeg(CXMLNode& oNode, int nVersion); + CLineSeg(CXMLReader& oReader, int nVersion); int GetLineSpacing() const; }; diff --git a/HwpFile/HwpDoc/Paragraph/TblCell.cpp b/HwpFile/HwpDoc/Paragraph/TblCell.cpp index e5b6a61c2f..63669f6eaf 100644 --- a/HwpFile/HwpDoc/Paragraph/TblCell.cpp +++ b/HwpFile/HwpDoc/Paragraph/TblCell.cpp @@ -25,41 +25,67 @@ CTblCell::CTblCell(int nSize, CHWPStream& oBuffer, int nOff, int nVersion) oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true)); } -CTblCell::CTblCell(CXMLNode& oNode, int nVersion) +CTblCell::CTblCell(CXMLReader& oReader, int nVersion) { - m_shBorderFill = oNode.GetAttributeInt(L"borderFillIDRef"); + m_shBorderFill = oReader.GetAttributeInt("borderFillIDRef"); - for (CXMLNode& oChild : oNode.GetChilds()) + WHILE_READ_NEXT_NODE_WITH_NAME(oReader) { - if (L"hp:cellAddr" == oChild.GetName()) + if ("hp:cellAddr" == sNodeName) { - m_shColAddr = oChild.GetAttributeInt(L"colAddr"); - m_shRowAddr = oChild.GetAttributeInt(L"rowAddr"); - } - else if (L"hp:cellSpan" == oChild.GetName()) - { - m_shColSpan = oChild.GetAttributeInt(L"colSpan"); - m_shRowSpan = oChild.GetAttributeInt(L"rowSpan"); - } - else if (L"hp:cellSz" == oChild.GetName()) - { - m_nWidth = oChild.GetAttributeInt(L"width"); - m_nHeight = oChild.GetAttributeInt(L"height"); - } - else if (L"hp:cellMargin" == oChild.GetName()) - { - m_arMargin[0] = oChild.GetAttributeInt(L"left"); - m_arMargin[1] = oChild.GetAttributeInt(L"rifht"); - m_arMargin[2] = oChild.GetAttributeInt(L"top"); - m_arMargin[3] = oChild.GetAttributeInt(L"bottom"); - } - else if (L"hp:subList" == oChild.GetName()) - { - m_eVertAlign = ::HWP::GetVertAlign(oChild.GetAttribute(L"vertAlign")); - - for (CXMLNode& oGrandChild : oChild.GetChilds(L"hp:p")) + START_READ_ATTRIBUTES(oReader) { - CCellParagraph *pCellParagraphs = new CCellParagraph(oGrandChild, nVersion); + if ("colAddr" == sAttributeName) + m_shColAddr = oReader.GetInt(); + else if ("rowAddr" == sAttributeName) + m_shRowAddr = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hp:cellSpan" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("colSpan" == sAttributeName) + m_shColSpan = oReader.GetInt(); + else if ("rowSpan" == sAttributeName) + m_shRowSpan = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hp:cellSz" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("width" == sAttributeName) + m_nWidth = oReader.GetInt(); + else if ("height" == sAttributeName) + m_nHeight = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hp:cellSz" == sNodeName) + { + START_READ_ATTRIBUTES(oReader) + { + if ("left" == sAttributeName) + m_arMargin[0] = oReader.GetInt(); + else if ("right" == sAttributeName) + m_arMargin[1] = oReader.GetInt(); + else if ("top" == sAttributeName) + m_arMargin[2] = oReader.GetInt(); + else if ("bottom" == sAttributeName) + m_arMargin[3] = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) + } + else if ("hp:subList" == sNodeName) + { + m_eVertAlign = ::HWP::GetVertAlign(oReader.GetAttribute("vertAlign")); + + WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "hp:p") + { + CCellParagraph *pCellParagraphs = new CCellParagraph(oReader, nVersion); if (nullptr == pCellParagraphs) continue; @@ -69,8 +95,10 @@ CTblCell::CTblCell(CXMLNode& oNode, int nVersion) m_arParas.push_back(pCellParagraphs); } + END_WHILE } } + END_WHILE } void CTblCell::SetVertAlign(EVertAlign eVertAlign) diff --git a/HwpFile/HwpDoc/Paragraph/TblCell.h b/HwpFile/HwpDoc/Paragraph/TblCell.h index dc056d0c9e..f5cf3e9777 100644 --- a/HwpFile/HwpDoc/Paragraph/TblCell.h +++ b/HwpFile/HwpDoc/Paragraph/TblCell.h @@ -24,7 +24,7 @@ class CTblCell HWP_STRING m_sMergedColName; public: CTblCell(int nSize, CHWPStream& oBuffer, int nOff, int nVersion); - CTblCell(CXMLNode& oNode, int nVersion); + CTblCell(CXMLReader& oReader, int nVersion); void SetVertAlign(EVertAlign eVertAlign); diff --git a/HwpFile/HwpDoc/Section/NoteShape.cpp b/HwpFile/HwpDoc/Section/NoteShape.cpp index f4955d2a6a..dd2220b374 100644 --- a/HwpFile/HwpDoc/Section/NoteShape.cpp +++ b/HwpFile/HwpDoc/Section/NoteShape.cpp @@ -17,7 +17,7 @@ ENoteNumbering GetNoteNumbering(int nValue) CNoteShape::CNoteShape() {} -CNoteShape::CNoteShape(CXMLNode& oNode, int nVersion) +CNoteShape::CNoteShape(CXMLReader& oReader, int nVersion) {} CNoteShape* CNoteShape::Parse(int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) diff --git a/HwpFile/HwpDoc/Section/NoteShape.h b/HwpFile/HwpDoc/Section/NoteShape.h index 9d9069793a..d79b4ee14c 100644 --- a/HwpFile/HwpDoc/Section/NoteShape.h +++ b/HwpFile/HwpDoc/Section/NoteShape.h @@ -3,7 +3,7 @@ #include "../HWPElements/HwpRecordTypes.h" #include "../HWPStream.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -47,7 +47,7 @@ class CNoteShape int m_nNoteLineColor; public: CNoteShape(); - CNoteShape(CXMLNode& oNode, int nVersion); + CNoteShape(CXMLReader& oReader, int nVersion); static CNoteShape* Parse(int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); }; diff --git a/HwpFile/HwpDoc/Section/Page.cpp b/HwpFile/HwpDoc/Section/Page.cpp index 43b075f854..e7f875055f 100644 --- a/HwpFile/HwpDoc/Section/Page.cpp +++ b/HwpFile/HwpDoc/Section/Page.cpp @@ -5,31 +5,54 @@ namespace HWP HWP::CPage::CPage() {} -CPage::CPage(CXMLNode& oNode) +CPage::CPage(CXMLReader& oReader) { - m_bLandscape = L"NARROWLY" == oNode.GetAttribute(L"landscape"); - - m_nWidth = oNode.GetAttributeInt(L"width"); - m_nHeight = oNode.GetAttributeInt(L"height"); - - std::wstring wsType = oNode.GetAttribute(L"gutterType"); - - if (L"LEFT_ONELY" == wsType) - m_chGutterType = 0; - else if (L"LEFT_RIGHT" == wsType) - m_chGutterType = 1; - else if (L"TOP_BOTTOM" == wsType) - m_chGutterType = 2; - - for (CXMLNode& oChild : oNode.GetChilds(L"hp:margin")) + START_READ_ATTRIBUTES(oReader) { - m_nMarginLeft = oChild.GetAttributeInt(L"left"); - m_nMarginRight = oChild.GetAttributeInt(L"right"); - m_nMarginTop = oChild.GetAttributeInt(L"top"); - m_nMarginBottom = oChild.GetAttributeInt(L"bottom"); - m_nMarginHeader = oChild.GetAttributeInt(L"header"); - m_nMarginFooter = oChild.GetAttributeInt(L"footer"); - m_nMarginGutter = oChild.GetAttributeInt(L"gutter"); + if ("landscape" == sAttributeName) + m_bLandscape = "NARROWLY" == oReader.GetText2A(); + else if ("width" == sAttributeName) + m_nWidth = oReader.GetInt(); + else if ("height" == sAttributeName) + m_nHeight = oReader.GetInt(); + else if ("gutterType" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; + + if ("LEFT_ONELY" == sType) + m_chGutterType = 0; + else if ("LEFT_RIGHT" == sType) + m_chGutterType = 1; + else if ("TOP_BOTTOM" == sType) + m_chGutterType = 2; + } + } + END_READ_ATTRIBUTES(oReader) + + WHILE_READ_NEXT_NODE(oReader) + { + if ("hp:margin" != oReader.GetNameA()) + continue; + + START_READ_ATTRIBUTES(oReader) + { + if ("left" == sAttributeName) + m_nMarginLeft = oReader.GetInt(); + else if ("right" == sAttributeName) + m_nMarginRight = oReader.GetInt(); + else if ("top" == sAttributeName) + m_nMarginTop = oReader.GetInt(); + else if ("bottom" == sAttributeName) + m_nMarginBottom = oReader.GetInt(); + else if ("header" == sAttributeName) + m_nMarginHeader = oReader.GetInt(); + else if ("footer" == sAttributeName) + m_nMarginFooter = oReader.GetInt(); + else if ("gutter" == sAttributeName) + m_nMarginGutter = oReader.GetInt(); + + } + END_READ_ATTRIBUTES(oReader) } } diff --git a/HwpFile/HwpDoc/Section/Page.h b/HwpFile/HwpDoc/Section/Page.h index a2b5f49243..ba3bdc9a41 100644 --- a/HwpFile/HwpDoc/Section/Page.h +++ b/HwpFile/HwpDoc/Section/Page.h @@ -2,7 +2,7 @@ #define PAGE_H #include "../HWPStream.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -21,7 +21,7 @@ class CPage int m_nMarginGutter; public: CPage(); - CPage(CXMLNode& oNode); + CPage(CXMLReader& oReader); int GetWidth() const; int GetHeight() const; diff --git a/HwpFile/HwpDoc/Section/PageBorderFill.cpp b/HwpFile/HwpDoc/Section/PageBorderFill.cpp index 7ea47183a5..1794962d2f 100644 --- a/HwpFile/HwpDoc/Section/PageBorderFill.cpp +++ b/HwpFile/HwpDoc/Section/PageBorderFill.cpp @@ -5,28 +5,49 @@ namespace HWP CPageBorderFill::CPageBorderFill() {} -CPageBorderFill::CPageBorderFill(CXMLNode& oNode, int nVersion) +CPageBorderFill::CPageBorderFill(CXMLReader& oReader, int nVersion) { - m_shBorderFill = oNode.GetAttributeInt(L"borderFillIDRef"); - m_bTextBorder = L"PAPER" == oNode.GetAttribute(L"textBorder"); - m_bHeaderInside = oNode.GetAttributeBool(L"headerInside"); - m_bFooterInside = oNode.GetAttributeBool(L"footerInside"); - - HWP_STRING sType = oNode.GetAttribute(L"fillArea"); - - if (L"PAPER" == sType) - m_chFillArea = 0; - else if (L"PAGE" == sType) - m_chFillArea = 1; - else if (L"BORDER" == sType) - m_chFillArea = 2; - - for (CXMLNode& oChild : oNode.GetChilds(L"offset")) + START_READ_ATTRIBUTES(oReader) { - m_shOffsetLeft = oChild.GetAttributeInt(L"left"); - m_shOffsetRight = oChild.GetAttributeInt(L"right"); - m_shOffsetTop = oChild.GetAttributeInt(L"top"); - m_shOffsetBottom = oChild.GetAttributeInt(L"bottom"); + if ("borderFillIDRef" == sAttributeName) + m_shBorderFill = oReader.GetInt(); + else if ("textBorder" == sAttributeName) + m_bTextBorder = "PAPER" == oReader.GetText2A(); + else if ("headerInside" == sAttributeName) + m_bHeaderInside = oReader.GetBool(); + else if ("footerInside" == sAttributeName) + m_bFooterInside = oReader.GetBool(); + else if ("fillArea" == sAttributeName) + { + const std::string sType{oReader.GetText2A()}; + + if ("PAPER" == sType) + m_chFillArea = 0; + else if ("PAGE" == sType) + m_chFillArea = 1; + else if ("BORDER" == sType) + m_chFillArea = 2; + } + } + END_READ_ATTRIBUTES(oReader) + + WHILE_READ_NEXT_NODE(oReader) + { + if ("offset" != oReader.GetNameA()) + continue; + + START_READ_ATTRIBUTES(oReader) + { + if ("left" == sAttributeName) + m_shOffsetLeft = oReader.GetInt(); + else if ("right" == sAttributeName) + m_shOffsetRight = oReader.GetInt(); + else if ("top" == sAttributeName) + m_shOffsetTop = oReader.GetInt(); + else if ("bottom" == sAttributeName) + m_shOffsetBottom = oReader.GetInt(); + } + END_READ_ATTRIBUTES(oReader) } } diff --git a/HwpFile/HwpDoc/Section/PageBorderFill.h b/HwpFile/HwpDoc/Section/PageBorderFill.h index 5993f5b542..bd6962611f 100644 --- a/HwpFile/HwpDoc/Section/PageBorderFill.h +++ b/HwpFile/HwpDoc/Section/PageBorderFill.h @@ -2,7 +2,7 @@ #define PAGEBORDERFILL_H #include "../HWPStream.h" -#include "../Common/XMLNode.h" +#include "../Common/XMLReader.h" namespace HWP { @@ -19,7 +19,7 @@ class CPageBorderFill short m_shBorderFill; public: CPageBorderFill(); - CPageBorderFill(CXMLNode& oNode, int nVersion); + CPageBorderFill(CXMLReader& oReader, int nVersion); static CPageBorderFill* Parse(int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); }; diff --git a/OfficeUtils/src/ZipFolder.h b/OfficeUtils/src/ZipFolder.h index 20f2b7fd5b..ba3098f2d0 100644 --- a/OfficeUtils/src/ZipFolder.h +++ b/OfficeUtils/src/ZipFolder.h @@ -37,6 +37,8 @@ #include "../../DesktopEditor/common/Directory.h" #include "../../DesktopEditor/common/Path.h" #include "../../DesktopEditor/xml/include/xmlutils.h" +#include +#include class IFolder {