Expanded support for the HWPML format

This commit is contained in:
Kirill Polyakov
2025-09-18 12:42:52 +03:00
parent 51de435393
commit 842a44ccf9
42 changed files with 456 additions and 230 deletions

View File

@ -55,7 +55,10 @@ namespace SVG
std::wstring wsImageData = m_wsHref.substr(unType + 8, m_wsHref.length() - unType - 8);
ulSize = NSBase64::Base64DecodeGetRequiredLength(wsImageData.length());
pBuffer = new BYTE[ulSize];
pBuffer = new(std::nothrow) BYTE[ulSize];
if (NULL == pBuffer)
return false;
NSBase64::Base64Decode(wsImageData.c_str(), wsImageData.length(), pBuffer, &(int&)ulSize);
}

View File

@ -131,7 +131,6 @@ HEADERS += \
HwpDoc/HWPElements/HWPRecordParaText.h \
HwpDoc/HWPElements/HWPRecordStyle.h \
HwpDoc/HWPElements/HWPTag.h \
HwpDoc/HWPElements/HWPType.h \
HwpDoc/HWPElements/HwpRecordTabDef.h \
HwpDoc/HWPElements/HwpRecordTypes.h \
HwpDoc/HWPFile.h \

View File

@ -32,6 +32,7 @@ typedef char HWP_BYTE;
#define WSTR(value) MAKE_WSTR(#value)
#define IF_STRING_IN_ENUM(checked_value, value, enum_type)\
TO_UPPER(value);\
if (WSTR(checked_value) == value)\
return enum_type::checked_value
#define ELSE_IF_STRING_IN_ENUM(checked_value, value, enum_type)\

View File

@ -90,7 +90,7 @@ enum class ENode
InSideMargin,
Caption,
TransformMatrix,
ScaleMatrix,
ScaleMatrix, //80
RotationMatrix,
LineShape,
ShadowEffect,
@ -98,9 +98,16 @@ enum class ENode
SoftEdgeEffect,
ReflectionEffect,
EffectsColor,
DrawText,
TextMargin,
Header, //90
Footer,
CellZoneList,
CellZone,
Row,
Cell,
//Only hwpx
Ctrl,
Lineseg,
LinesegArray,
Video,
@ -112,7 +119,7 @@ enum class ENode
};
#define MAX_TYPES 2
#define MAX_NODES 100
#define MAX_NODES 110
static constexpr const char* NODE_NAMES[MAX_TYPES][MAX_NODES] =
{
@ -209,14 +216,23 @@ static constexpr const char* NODE_NAMES[MAX_TYPES][MAX_NODES] =
"hp:softEdge",
"hp:reflection",
"hp:effectsColor",
"hp:drawText",
"hp:textMargin",
"hp:header",
"hp:footer",
"hp:cellzoneList",
"hp:cellzone",
"hp:tr",
"hp:tc",
"hp:ctrl",
"hp:lineseg",
"hp:linesegarray",
"hp:video",
"hp:switch",
"hp:case",
"hp:default"
"hp:default",
"hh:slash",
"hh:backSlash"
},
// HWPML
{
@ -310,6 +326,14 @@ static constexpr const char* NODE_NAMES[MAX_TYPES][MAX_NODES] =
"SOFTEDGE",
"REFLECTION",
"EFFECTSCOLOR",
"DRAWTEXT",
"TEXTMARGIN",
"HEADER",
"FOOTER",
"CELLZONELIST",
"CELLZONE",
"ROW",
"CELL",
"",
"",
@ -317,6 +341,7 @@ static constexpr const char* NODE_NAMES[MAX_TYPES][MAX_NODES] =
"",
"",
"",
"",
""
}
};
@ -331,6 +356,16 @@ inline const char* GetNodeName(ENode eNode, EHanType eType)
}
}
inline bool Equals(ENode eNode, EHanType eType, std::string sNodeName)
{
switch (eType)
{
case EHanType::HWPX: return NODE_NAMES[0][static_cast<int>(eNode)] == sNodeName;
case EHanType::HWPML: return NODE_NAMES[1][static_cast<int>(eNode)] == sNodeName;
default: return false;
}
}
enum class EAttribute
{
ParaShape,
@ -462,7 +497,7 @@ enum class EAttribute
MatrixElement1_2,
MatrixElement2_1,
MatrixElement2_2,
MatrixElementOffsetX,
MatrixElementOffsetX, // 130
MatrixElementOffsetY,
HeadStyle,
HeadSize,
@ -472,13 +507,22 @@ enum class EAttribute
Direction,
Distance,
RotationStyle,
FadeDirection,
FadeDirection, //140
BinData,
RepeatHeader,
RowCount,
ColCount,
CellSpacing,
StartRowAddr,
StartColAddr,
EndRowAddr,
EndColAddr,
PageBreak,
ColumnBreak,
};
#define MAX_ATTRIBUTES 150
#define MAX_ATTRIBUTES 160
//TODO:: добавить все аргументы
static constexpr const char* ATTRUBUTE_NAMES[MAX_TYPES][MAX_ATTRIBUTES] =
@ -569,10 +613,10 @@ static constexpr const char* ATTRUBUTE_NAMES[MAX_TYPES][MAX_ATTRIBUTES] =
"eAsianEng",
"eAsianNum",
"indent",
"top",
"bottom",
"",
"",
"left",
"right",
"prev",
"next",
"",
"", //90
"borderFillIDRef",
@ -585,7 +629,7 @@ static constexpr const char* ATTRUBUTE_NAMES[MAX_TYPES][MAX_ATTRIBUTES] =
"engName",
"nextStyleIDRef",
"langID", //100
"id"
"id",
"lockForm",
"name",
"textFlow",
@ -625,6 +669,15 @@ static constexpr const char* ATTRUBUTE_NAMES[MAX_TYPES][MAX_ATTRIBUTES] =
"distance",
"rotationStyle",
"fadeDirection",
"id",
"repeatHeader",
"rowCnt",
"colCnt",
"cellSpacing",
"startRowAddr",
"startColAddr",
"endRowAddr",
"endColAddr",
"pageBreak",
"columnBreak",
@ -771,6 +824,15 @@ static constexpr const char* ATTRUBUTE_NAMES[MAX_TYPES][MAX_ATTRIBUTES] =
"Distance",
"RotationStyle",
"FadeDirection",
"BinData",
"RepeatHeader",
"RowCount",
"ColCount",
"CellSpacing",
"StartRowAddr",
"StartColAddr",
"EndRowAddr",
"EndColAddr",
"PageBreak",
"ColumnBreak"
@ -787,6 +849,16 @@ inline const char* GetAttributeName(EAttribute eNode, EHanType eType)
}
}
inline bool Equals(EAttribute eAttribute, EHanType eType, std::string sAttributeName)
{
switch (eType)
{
case EHanType::HWPX: return ATTRUBUTE_NAMES[0][static_cast<int>(eAttribute)] == sAttributeName;
case EHanType::HWPML: return ATTRUBUTE_NAMES[1][static_cast<int>(eAttribute)] == sAttributeName;
default: return false;
}
}
#define MAX_VALUES 60
// TODO:: пока всё в одном месте. Возможно стоит лучше разделить по соответствующим классам
@ -896,7 +968,14 @@ static constexpr const char* VALUE_NAMES[MAX_TYPES][MAX_VALUES] =
"MEDIUM_LARGE",
"LARGE_SMALL",
"LARGE_MEDIUM",
"LARGE_LARGE"
"LARGE_LARGE",
"NORMAL",
"ARROW",
"SPEAR",
"CONCAVE_ARROW",
"EMPTY_DIAMOND",
"EMPTY_CIRCLE",
"EMPTY_BOX"
},
//HWPML
{
@ -945,7 +1024,14 @@ static constexpr const char* VALUE_NAMES[MAX_TYPES][MAX_VALUES] =
"MediumLarge",
"LargeSmall",
"LargeMedium",
"LargeLarge"
"LargeLarge",
"Normal",
"Arrow",
"Spear",
"ConcaveArrow",
"EmptyDiamond",
"EmptyCircle",
"EmptyBox"
}
};

View File

@ -336,6 +336,11 @@ bool CWriterContext::GetBinBytes(const HWP_STRING& sId, CHWPStream& oBuffer, HWP
sFileName = NSFile::GetFileName(pBinData->GetPath());
return m_pHWPXFile->GetChildStream(pBinData->GetPath(), oBuffer);
}
case EHanType::HWPML:
{
sFileName = pBinData->GetItemID() + L'.' + pBinData->GetFormat();
return m_pHWPMLFile->GetBinData(pBinData->GetItemID(), oBuffer);
}
default:
break;
}

View File

@ -596,7 +596,8 @@ void CConverter2OOXML::WriteParagraph(const CHWPPargraph* pParagraph, NSStringUt
}
case ECtrlObjectType::HeadFoot:
{
if (EHanType::HWPX == m_pContext->GetType())
if (EHanType::HWPX == m_pContext->GetType() ||
EHanType::HWPML == m_pContext->GetType())
oState.m_arCtrlsHeadFoot.push_back((const CCtrlHeadFoot*)pCtrl);
break;
}
@ -1245,12 +1246,22 @@ void CConverter2OOXML::WriteSectionSettings(TConversionState& oState)
{
std::vector<const CCtrlHeadFoot*> arCtrlsHeadFoot;
if (EHanType::HWP == m_pContext->GetType())
arCtrlsHeadFoot = oState.m_pSectionDef->GetHeaderFooters();
else if (EHanType::HWPX == m_pContext->GetType())
switch (m_pContext->GetType())
{
arCtrlsHeadFoot = oState.m_arCtrlsHeadFoot;
oState.m_arCtrlsHeadFoot.clear();
case EHanType::HWP:
{
arCtrlsHeadFoot = oState.m_pSectionDef->GetHeaderFooters();
break;
}
case EHanType::HWPX:
case EHanType::HWPML:
{
arCtrlsHeadFoot = oState.m_arCtrlsHeadFoot;
oState.m_arCtrlsHeadFoot.clear();
break;
}
default:
return;
}
#define WRITE_ID(id)\
@ -2000,7 +2011,8 @@ void CConverter2OOXML::WriteBorderSettings(const CCtrlShapePic* pCtrlPic, NSStri
if (EHanType::HWP == m_pContext->GetType())
WriteLineSettings(pCtrlPic->GetBorderLineStyle(), pCtrlPic->GetBorderColor(), pCtrlPic->GetBorderThick(), pCtrlPic->GetBorderCompoundLineType(), oBuilder);
else if (EHanType::HWPX == m_pContext->GetType())
else if (EHanType::HWPX == m_pContext->GetType() ||
EHanType::HWPML == m_pContext->GetType())
WriteLineSettings(pCtrlPic->GetLineStyle(), pCtrlPic->GetLineColor(), pCtrlPic->GetLineThick(), 1, oBuilder);
}

View File

@ -24,11 +24,9 @@ namespace Transform
inline std::wstring IntColorToHEX(int nColor)
{
std::wstringstream oSStream;
oSStream << std::uppercase << std::hex << std::setw(6) << std::setfill(L'0') << nColor;
return oSStream.str();
wchar_t buffer[7];
std::swprintf(buffer, L"%02X%02X%02X", nColor & 0xFF, (nColor >> 8) & 0xFF, (nColor >> 16) & 0xFF);
return std::wstring(buffer);
}
inline short LineWidth2Pt(short shHWPThick)

View File

@ -45,9 +45,9 @@ namespace HWP
const int tempLen = 7;
wchar_t arTemp[tempLen];
swprintf(arTemp, tempLen, L"%02X%02X%02X", m_uchRed, m_uchGreen, m_uchBlue);
swprintf(arTemp, tempLen, L"%02X%02X%02X", m_uchBlue, m_uchGreen, m_uchRed);
return std::wstring(arTemp, 6);
return std::wstring(arTemp);
}
};

View File

@ -376,6 +376,7 @@ const CHWPRecord* CHWPDocInfo::GetBinData(const HWP_STRING& sID) const
{
case EHanType::HWP:
case EHanType::HWPX:
case EHanType::HWPML:
{
std::map<HWP_STRING, CHWPRecord*>::const_iterator itFound = m_mBinDatas.find(sID);

View File

@ -81,7 +81,7 @@ CHWPRecordBinData::CHWPRecordBinData(CXMLReader& oReader, int nVersion, EHanType
START_READ_ATTRIBUTES(oReader)
{
if ("id" == sAttributeName)
if (GetAttributeName(EAttribute::BinData, eType) == sAttributeName)
m_sItemID = oReader.GetText();
else if (EHanType::HWPX == eType && "isEmbeded" == sAttributeName)
{

View File

@ -405,7 +405,7 @@ CHWPRecordBorderFill::CHWPRecordBorderFill(CHWPDocInfo& oDocInfo, CXMLReader& oR
m_oDiagonal.Read(oReader, eType);
else if (GetNodeName(ENode::FillBrush, eType) == sNodeName)
m_pFill = new CFill(oReader, eType);
else if (GetNodeName(ENode::Slash, eType) == sNodeName)
else if (Equals(ENode::Slash, eType, sNodeName))
{
START_READ_ATTRIBUTES(oReader)
{

View File

@ -19,7 +19,7 @@ EAccent GetAccent(int nValue)
}
}
EAccent GetAccent(const HWP_STRING& sValue)
EAccent GetAccent(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(DOT, sValue, EAccent);
ELSE_IF_STRING_IN_ENUM(RING, sValue, EAccent);
@ -59,7 +59,7 @@ EUnderline GetUnderline(int nValue)
}
}
EUnderline GetUnderline(const HWP_STRING& sValue)
EUnderline GetUnderline(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(BOTTOM, sValue, EUnderline);
ELSE_IF_STRING_IN_ENUM(CENTER, sValue, EUnderline);
@ -81,7 +81,7 @@ EOutline GetOutline(int nValue)
}
}
EOutline GetOutline(const HWP_STRING& sValue)
EOutline GetOutline(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(SOLID, sValue, EOutline);
ELSE_IF_STRING_IN_ENUM(DOTTED, sValue, EOutline);
@ -102,7 +102,7 @@ EShadow GetShadow(int nValue)
}
}
EShadow GetShadow(const HWP_STRING& sValue)
EShadow GetShadow(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(DISCRETE, sValue, EShadow);
ELSE_IF_STRING_IN_ENUM(CONTINUOUS, sValue, EShadow);

View File

@ -60,7 +60,7 @@ enum class EAccent
};
EAccent GetAccent(int nValue);
EAccent GetAccent(const HWP_STRING& sValue);
EAccent GetAccent(HWP_STRING sValue);
#define MAX_ELEMENTS (int)ELang::MAX

View File

@ -15,7 +15,7 @@ EHeadingType GetHeadingType(int nValue)
}
}
EHeadingType GetHeadingType(const HWP_STRING& sValue)
EHeadingType GetHeadingType(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(OUTLINE, sValue, EHeadingType);
ELSE_IF_STRING_IN_ENUM(NUMBER, sValue, EHeadingType);
@ -36,7 +36,7 @@ EHorizontalAlign GetHorizontalAlign(int nValue)
}
}
EHorizontalAlign GetHorizontalAlign(const HWP_STRING& sValue)
EHorizontalAlign GetHorizontalAlign(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(RIGHT, sValue, EHorizontalAlign);
ELSE_IF_STRING_IN_ENUM(CENTER, sValue, EHorizontalAlign);
@ -57,7 +57,7 @@ EVerticalAlign GetVerticalAlign(int nValue)
}
}
EVerticalAlign GetVerticalAlign(const HWP_STRING& sValue)
EVerticalAlign GetVerticalAlign(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(CENTER, sValue, EVerticalAlign);
ELSE_IF_STRING_IN_ENUM(BOTTOM, sValue, EVerticalAlign);

View File

@ -1,17 +0,0 @@
#ifndef HWPTYPE_H
#define HWPTYPE_H
#include "HWPTag.h"
namespace HWP
{
class CHWPType
{
public:
CHWPType(){};
EHWPTag m_eTag;
};
}
#endif // HWPTYPE_H

View File

@ -50,7 +50,7 @@ inline ELineStyle1 GetLineStyle1(int nValue)
}
}
inline ELineStyle1 GetLineStyle1(const HWP_STRING& sValue)
inline ELineStyle1 GetLineStyle1(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(SOLID, sValue, ELineStyle1);
ELSE_IF_STRING_IN_ENUM(DASH, sValue, ELineStyle1);
@ -107,7 +107,7 @@ inline ELineStyle2 GetLineStyle2(int nValue)
}
}
inline ELineStyle2 GetLineStyle2(const HWP_STRING& sValue)
inline ELineStyle2 GetLineStyle2(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(NONE, sValue, ELineStyle2);
ELSE_IF_STRING_IN_ENUM(SOLID, sValue, ELineStyle2);
@ -165,7 +165,7 @@ inline ENumberShape1 GetNumberShape1(int nValue)
}
}
inline ENumberShape1 GetNumberShape1(const HWP_STRING& sValue)
inline ENumberShape1 GetNumberShape1(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(DIGIT, sValue, ENumberShape1);
ELSE_IF_STRING_IN_ENUM(CIRCLE_DIGIT, sValue, ENumberShape1);
@ -234,7 +234,7 @@ inline ENumberShape2 GetNumberShape2(int nValue)
}
}
inline ENumberShape2 GetNumberShape2(const HWP_STRING& sValue)
inline ENumberShape2 GetNumberShape2(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(DIGIT, sValue, ENumberShape2);
ELSE_IF_STRING_IN_ENUM(CIRCLE_DIGIT, sValue, ENumberShape2);
@ -290,7 +290,7 @@ inline ELineArrowStyle GetLineArrowStyle(int nNum, bool bFill)
}
}
inline ELineArrowStyle GetLineArrowStyle(const HWP_STRING& sValue)
inline ELineArrowStyle GetLineArrowStyle(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(NORMAL, sValue, ELineArrowStyle);
ELSE_IF_STRING_IN_ENUM(ARROW, sValue, ELineArrowStyle);
@ -334,7 +334,7 @@ inline ELineArrowSize GetLineArrowSize(int nValue)
}
}
inline ELineArrowSize GetLineArrowSize(const HWP_STRING& sValue)
inline ELineArrowSize GetLineArrowSize(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(SMALL_SMALL, sValue, ELineArrowSize);
ELSE_IF_STRING_IN_ENUM(SMALL_MEDIUM, sValue, ELineArrowSize);

View File

@ -14,9 +14,9 @@ CHWPMLFile::~CHWPMLFile()
{
CLEAR_ARRAY(CHWPSection, m_arSections);
for (std::pair<unsigned int, BYTE*> oValue : m_mBinDates)
if (nullptr != oValue.second)
delete[] oValue.second;
for (BinMap::iterator itBegin = m_mBinDates.begin(); itBegin != m_mBinDates.end(); ++itBegin)
if (nullptr != itBegin->second)
delete itBegin->second;
}
bool CHWPMLFile::Open()
@ -107,7 +107,7 @@ void CHWPMLFile::ReadBinData(CXMLReader &oReader)
{
size_t unSize = 0;
std::string sEncoding;
unsigned int unID = 0;
HWP_STRING sId;
bool bCompress = true;
START_READ_ATTRIBUTES(oReader)
@ -117,42 +117,39 @@ void CHWPMLFile::ReadBinData(CXMLReader &oReader)
else if ("Encoding" == sAttributeName)
sEncoding = oReader.GetTextA();
else if ("Id" == sAttributeName)
unID = oReader.GetInt();
sId = oReader.GetText();
else if ("Compress" == sAttributeName)
bCompress = oReader.GetBool();
}
END_READ_ATTRIBUTES(oReader)
if (sId.empty())
return;
const std::wstring wsImageData{oReader.GetText()};
if (0 == unSize)
unSize = wsImageData.length();
int nImageSize = NSBase64::Base64DecodeGetRequiredLength(wsImageData.length());
int nImageSize = NSBase64::Base64DecodeGetRequiredLength(unSize);
BYTE* pBuffer = new BYTE[nImageSize];
BYTE* pBuffer = new(std::nothrow) BYTE[nImageSize];
if (nullptr == pBuffer)
return;
if (FALSE == NSBase64::Base64Decode(wsImageData.c_str(), unSize, pBuffer, &nImageSize))
if (FALSE == NSBase64::Base64Decode(wsImageData.c_str(), wsImageData.length(), pBuffer, &nImageSize))
{
delete[] pBuffer;
return;
}
std::map<unsigned int, BYTE*>::iterator itFound = m_mBinDates.find(unID);
BinMap::iterator itFound = m_mBinDates.find(sId);
if (m_mBinDates.end() != itFound)
{
if (nullptr != itFound->second)
delete[] itFound->second;
itFound->second = pBuffer;
return;
((CHWPStream*)itFound->second)->Clear();
((CHWPStream*)itFound->second)->SetStream((HWP_BYTE*)pBuffer, nImageSize, false);
}
m_mBinDates.insert(std::make_pair(unID, pBuffer));
else
m_mBinDates.insert(std::make_pair(sId, new CHWPStream((HWP_BYTE*)pBuffer, nImageSize, false)));
}
VECTOR<const CHWPSection*> CHWPMLFile::GetSections() const
@ -160,13 +157,15 @@ VECTOR<const CHWPSection*> CHWPMLFile::GetSections() const
RETURN_VECTOR_CONST_PTR(CHWPSection, m_arSections);
}
const BYTE *HWP::CHWPMLFile::GetBinData(unsigned int unID) const
bool CHWPMLFile::GetBinData(const HWP_STRING &sId, CHWPStream &oBuffer) const
{
std::map<unsigned int, BYTE*>::const_iterator itFound = m_mBinDates.find(unID);
BinMap::const_iterator itFound = m_mBinDates.find(sId);
if (m_mBinDates.end() == itFound)
return nullptr;
if (m_mBinDates.cend() == itFound || nullptr == itFound->second)
return false;
return itFound->second;
oBuffer.SetStream(((CHWPStream*)(itFound->second))->GetCurPtr(), ((CHWPStream*)(itFound->second))->SizeToEnd());
return true;
}
}

View File

@ -8,10 +8,12 @@ namespace HWP
{
class CHWPMLFile
{
using BinMap = std::map <HWP_STRING, CHWPStream*>;
HWP_STRING m_wsFilePath;
CHWPDocInfo m_oDocInfo;
VECTOR<CHWPSection*> m_arSections;
std::map<unsigned int, BYTE*> m_mBinDates;
BinMap m_mBinDates;
void ReadHead(CXMLReader& oReader);
void ReadBody(CXMLReader& oReader);
@ -29,7 +31,7 @@ public:
const CHWPDocInfo* GetDocInfo() const;
VECTOR<const CHWPSection*> GetSections() const;
const BYTE* GetBinData(unsigned int unID) const;
bool GetBinData(const HWP_STRING& sId, CHWPStream& oBuffer) const;
};
}

View File

@ -55,6 +55,11 @@ HWP_BYTE* CHWPStream::GetCurPtr()
return m_pCur;
}
const HWP_BYTE *CHWPStream::GetCurPtr() const
{
return m_pCur;
}
unsigned long CHWPStream::Tell() const
{
return (!IsValid()) ? 0 : m_pCur - m_pBegin;

View File

@ -33,6 +33,7 @@ public:
void SetStream(HWP_BYTE* pBuffer, unsigned long ulSize, bool bExternalBuffer = true);
HWP_BYTE* GetCurPtr();
const HWP_BYTE* GetCurPtr() const;
unsigned long Tell() const;
unsigned long SizeToEnd() const;

View File

@ -4,11 +4,10 @@ namespace HWP
{
CCellParagraph::CCellParagraph()
: CHWPPargraph()
{
}
{}
CCellParagraph::CCellParagraph(CXMLReader& oReader, int nVersion)
: CHWPPargraph(oReader, nVersion, EHanType::HWPX)
CCellParagraph::CCellParagraph(CXMLReader& oReader, int nVersion, EHanType eType)
: CHWPPargraph(oReader, nVersion, eType)
{}
EParagraphType CCellParagraph::GetType() const

View File

@ -9,7 +9,7 @@ class CCellParagraph : public CHWPPargraph
{
public:
CCellParagraph();
CCellParagraph(CXMLReader& oReader, int nVersion);
CCellParagraph(CXMLReader& oReader, int nVersion, EHanType eType);
EParagraphType GetType() const override;
};

View File

@ -8,6 +8,8 @@
#include "CtrlPageNumPos.h"
#include "CtrlField.h"
#include "../Common/NodeNames.h"
namespace HWP
{
CCtrl::CCtrl()
@ -50,16 +52,16 @@ bool CCtrl::Equals(CCtrl* pFirstCtrl, CCtrl* pSecondCtrl)
pFirstCtrl->m_bFullFilled == pSecondCtrl->m_bFullFilled;
}
CCtrl* CCtrl::GetCtrl(CXMLReader& oReader, int nVersion)
CCtrl* CCtrl::GetCtrl(CXMLReader& oReader, int nVersion, EHanType eType)
{
const std::string sNodeName{oReader.GetName()};
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 (GetNodeName(ENode::Header, eType) == sNodeName)
return new CCtrlHeadFoot(L"daeh", oReader, nVersion, eType);
else if (GetNodeName(ENode::Footer, eType) == sNodeName)
return new CCtrlHeadFoot(L"toof", oReader, nVersion, eType);
else if ("hp:footNote" == sNodeName)
return new CCtrlNote(L" nf", oReader, nVersion);
else if ("hp:endNote" == sNodeName)

View File

@ -1,6 +1,8 @@
#ifndef CTRL_H
#define CTRL_H
#include "../HanType.h"
#include "../Common/Common.h"
#include "../Common/XMLReader.h"
@ -46,7 +48,7 @@ public:
void SetFullFilled();
static bool Equals(CCtrl* pFirstCtrl, CCtrl* pSecondCtrl);
static CCtrl* GetCtrl(CXMLReader& oReader, int nVersion);
static CCtrl* GetCtrl(CXMLReader& oReader, int nVersion, EHanType eType);
};
}

View File

@ -16,7 +16,7 @@ ENumType GetNumType(int nValue)
}
}
ENumType GetNumType(const HWP_STRING& sValue)
ENumType GetNumType(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(FOOTNOTE, sValue, ENumType);
ELSE_IF_STRING_IN_ENUM(ENDNOTE, sValue, ENumType);

View File

@ -21,7 +21,7 @@ enum class ENumType
};
ENumType GetNumType(int nValue);
ENumType GetNumType(const HWP_STRING& sValue);
ENumType GetNumType(HWP_STRING sValue);
class CCtrlAutoNumber : public CCtrl
{

View File

@ -23,8 +23,6 @@ namespace HWP
EVertAlign GetVertAlign(HWP_STRING sValue)
{
TO_UPPER(sValue);
IF_STRING_IN_ENUM(CENTER, sValue, EVertAlign);
ELSE_IF_STRING_IN_ENUM(BOTTOM, sValue, EVertAlign);
ELSE_IF_STRING_IN_ENUM(INSIDE, sValue, EVertAlign);
@ -44,8 +42,6 @@ namespace HWP
EVRelTo GetVRelTo(HWP_STRING sValue)
{
TO_UPPER(sValue);
IF_STRING_IN_ENUM(PARA, sValue, EVRelTo);
ELSE_IF_STRING_IN_ENUM(PAGE, sValue, EVRelTo);
ELSE_IF_STRING_IN_ENUM(PAPER, sValue, EVRelTo);
@ -65,8 +61,6 @@ namespace HWP
EHRelTo GetHRelTo(HWP_STRING sValue)
{
TO_UPPER(sValue);
IF_STRING_IN_ENUM(PAGE, sValue, EHRelTo);
ELSE_IF_STRING_IN_ENUM(PARA, sValue, EHRelTo);
ELSE_IF_STRING_IN_ENUM(COLUMN, sValue, EHRelTo);
@ -87,8 +81,6 @@ namespace HWP
EWidthRelTo GetWidthRelTo(HWP_STRING sValue)
{
TO_UPPER(sValue);
IF_STRING_IN_ENUM(PAGE, sValue, EWidthRelTo);
ELSE_IF_STRING_IN_ENUM(PARA, sValue, EWidthRelTo);
ELSE_IF_STRING_IN_ENUM(COLUMN, sValue, EWidthRelTo);
@ -108,8 +100,6 @@ namespace HWP
EHeightRelTo GetHeightRelTo(HWP_STRING sValue)
{
TO_UPPER(sValue);
IF_STRING_IN_ENUM(PAGE, sValue, EHeightRelTo);
ELSE_IF_STRING_IN_ENUM(ABSOLUTE, sValue, EHeightRelTo);
ELSE_STRING_IN_ENUM(PAPER, EHeightRelTo);
@ -129,8 +119,6 @@ namespace HWP
EHorzAlign GetHorzAlign(HWP_STRING sValue)
{
TO_UPPER(sValue);
IF_STRING_IN_ENUM(CENTER, sValue, EHorzAlign);
ELSE_IF_STRING_IN_ENUM(RIGHT, sValue, EHorzAlign);
ELSE_IF_STRING_IN_ENUM(INSIDE, sValue, EHorzAlign);
@ -151,8 +139,6 @@ namespace HWP
ETextWrap GetTextWrap(HWP_STRING sValue)
{
TO_UPPER(sValue);
IF_STRING_IN_ENUM(TOP_AND_BOTTOM, sValue, ETextWrap);
ELSE_IF_STRING_IN_ENUM(BEHIND_TEXT, sValue, ETextWrap);
ELSE_IF_STRING_IN_ENUM(IN_FRONT_OF_TEXT, sValue, ETextWrap);
@ -268,7 +254,30 @@ namespace HWP
}
CCtrlCommon::CCtrlCommon(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion, EHanType eType)
: 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)
: 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_nZOrder(0)
{
if (EHanType::HWPX == eType)
ReadAttributes(oReader, eType);
}
CCtrlCommon::~CCtrlCommon()
{
for (CHWPPargraph* pParagraph : m_arParas)
{
if (0 == pParagraph->Release())
pParagraph = nullptr;
}
for (CCapParagraph* pCapParagraph : m_arCaption)
{
if (0 == pCapParagraph->Release())
pCapParagraph = nullptr;
}
}
void CCtrlCommon::ReadAttributes(CXMLReader &oReader, EHanType eType)
{
std::string sType;
@ -321,21 +330,6 @@ namespace HWP
END_READ_ATTRIBUTES(oReader)
}
CCtrlCommon::~CCtrlCommon()
{
for (CHWPPargraph* pParagraph : m_arParas)
{
if (0 == pParagraph->Release())
pParagraph = nullptr;
}
for (CCapParagraph* pCapParagraph : m_arCaption)
{
if (0 == pCapParagraph->Release())
pCapParagraph = nullptr;
}
}
ECtrlObjectType CCtrlCommon::GetCtrlType() const
{
return ECtrlObjectType::Common;
@ -350,6 +344,17 @@ namespace HWP
{
const std::string sNodeName{oReader.GetName()};
if (EHanType::HWPML == eType && "SHAPEOBJECT" == sNodeName)
{
ReadAttributes(oReader, eType);
WHILE_READ_NEXT_NODE(oReader)
ParseChildren(oReader, nVersion, EHanType::HWPML);
END_WHILE
return;
}
if (GetNodeName(ENode::Size, eType) == sNodeName)
{
START_READ_ATTRIBUTES(oReader)

View File

@ -109,6 +109,8 @@ class CCtrlCommon : public CCtrl
friend class CCtrlShapeVideo;
friend class CCtrlEqEdit;
friend class CCtrlTable;
void ReadAttributes(CXMLReader& oReader, EHanType eType);
public:
CCtrlCommon();
CCtrlCommon(const HWP_STRING& sCtrlID);

View File

@ -88,6 +88,9 @@ EShapeType CCtrlGeneralShape::GetShapeType() const
ELineArrowSize CheckLineSize(const std::string& sLineSzType, EHanType eType)
{
if (sLineSzType.empty())
return ELineArrowSize::MEDIUM_MEDIUM;
if (GetValueName(EValue::SmallSmall, eType) == sLineSzType)
return ELineArrowSize::SMALL_SMALL;
else if (GetValueName(EValue::SmallMedium, eType) == sLineSzType)
@ -112,6 +115,9 @@ ELineArrowSize CheckLineSize(const std::string& sLineSzType, EHanType eType)
ELineArrowStyle CheckLineArrowStyle(const std::string& sLineArrowStyle, bool bHeadFill, EHanType eType)
{
if (sLineArrowStyle.empty())
return ELineArrowStyle::NORMAL;
if (GetValueName(EValue::Arrow, eType) == sLineArrowStyle)
return ELineArrowStyle::ARROW;
else if (GetValueName(EValue::Spear, eType) == sLineArrowStyle)
@ -179,30 +185,30 @@ void CCtrlGeneralShape::ParseChildren(CXMLReader& oReader, int nVersion, EHanTyp
m_eLineHead = CheckLineArrowStyle(sHeadStyle, bHeadFill, eType);
m_eLineTail = CheckLineArrowStyle(sTailStyle, bTailFill, eType);
}
else if ("hc:fillBrush" == sNodeName)
else if (GetNodeName(ENode::FillBrush, eType) == sNodeName)
m_pFill = new CFill(oReader, eType);
else if ("hp:drawText" == sNodeName)
else if (GetNodeName(ENode::DrawText, eType) == sNodeName)
{
m_nMaxTxtWidth = oReader.GetAttributeInt("lastWidth");
m_nMaxTxtWidth = oReader.GetAttributeInt(GetAttributeName(EAttribute::LastWidth, eType));
WHILE_READ_NEXT_NODE_WITH_DEPTH_AND_NAME(oReader, Child)
{
if ("hp:textMargin" == sNodeChildName)
if (GetNodeName(ENode::TextMargin, eType) == sNodeChildName)
{
START_READ_ATTRIBUTES(oReader)
{
if ("left" == sAttributeName)
if (GetAttributeName(EAttribute::Left, eType) == sAttributeName)
m_shLeftSpace = oReader.GetInt();
else if ("right" == sAttributeName)
else if (GetAttributeName(EAttribute::Right, eType) == sAttributeName)
m_shRightSpace = oReader.GetInt();
else if ("top" == sAttributeName)
else if (GetAttributeName(EAttribute::Top, eType) == sAttributeName)
m_shTopSpace = oReader.GetInt();
else if ("bottom" == sAttributeName)
else if (GetAttributeName(EAttribute::Bottom, eType) == sAttributeName)
m_shBottomSpace = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
}
else if ("hp:subList" == sNodeChildName)
else if (EHanType::HWPX == eType && "hp:subList" == sNodeChildName)
ReadSubList(oReader, nVersion);
}
END_WHILE

View File

@ -24,11 +24,22 @@ CCtrlHeadFoot::CCtrlHeadFoot(const HWP_STRING& sCtrlID, int nSize, CHWPStream& o
oBuffer.ReadInt(m_nSerialInSec);
}
CCtrlHeadFoot::CCtrlHeadFoot(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion)
CCtrlHeadFoot::CCtrlHeadFoot(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion, EHanType eType)
: CCtrl(sCtrlID)
{
m_bIsHeader = L"daeh" == sCtrlID;
switch (eType)
{
case EHanType::HWPX: ReadFromHWPX(oReader, nVersion); break;
case EHanType::HWPML:ReadFromHWPML(oReader); break;
}
m_bFullFilled = true;
}
void CCtrlHeadFoot::ReadFromHWPX(CXMLReader &oReader, int nVersion)
{
m_eWhichPage = GetPageRange(oReader.GetAttributeInt("applyPageType"));
WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "hp:subList")
@ -51,8 +62,36 @@ CCtrlHeadFoot::CCtrlHeadFoot(const HWP_STRING& sCtrlID, CXMLReader& oReader, int
END_WHILE
}
END_WHILE
}
m_bFullFilled = true;
void CCtrlHeadFoot::ReadFromHWPML(CXMLReader &oReader)
{
START_READ_ATTRIBUTES(oReader)
{
if ("ApplyPageType" == sAttributeName)
{
const std::string sValue{oReader.GetTextA()};
if ("Both" == sValue)
m_eWhichPage = EPageRange::BOTH;
else if ("Even" == sValue)
m_eWhichPage = EPageRange::EVEN;
else if ("Odd" == sValue)
m_eWhichPage = EPageRange::ODD;
}
else if ("TextHeight" == sAttributeName)
m_nTextHeight = oReader.GetInt();
else if ("TextWidth" == sAttributeName)
m_nTextWidth = oReader.GetInt();
//TODO:: Реализовать HasTextRef и HasTextRef
}
END_READ_ATTRIBUTES(oReader)
WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "PARALIST")
WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Child, "P")
m_arParas.push_back(new CHWPPargraph(oReader, 0, EHanType::HWPML));
END_WHILE
END_WHILE
}
ECtrlObjectType CCtrlHeadFoot::GetCtrlType() const

View File

@ -28,10 +28,13 @@ class CCtrlHeadFoot : public CCtrl
HWP_BYTE m_chRefLevelNum;
VECTOR<CHWPPargraph*> m_arParas;
void ReadFromHWPX(CXMLReader& oReader, int nVersion);
void ReadFromHWPML(CXMLReader& oReader);
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, CXMLReader& oReader, int nVersion);
CCtrlHeadFoot(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion, EHanType eType);
ECtrlObjectType GetCtrlType() const override;

View File

@ -74,7 +74,7 @@ TMatrix ReadMatrix(CXMLReader& oReader, EHanType eType)
}
CCtrlObjElement::CCtrlObjElement(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVersion, EHanType eType)
: CCtrlCommon(sCtrlID, oReader, nVersion, eType)
: CCtrlCommon(sCtrlID, oReader, nVersion, eType), m_nCurWidth(0), m_nCurHeight(0)
{
if (EHanType::HWPX == eType)
m_shNGrp = oReader.GetAttributeInt("groupLevel");

View File

@ -20,7 +20,7 @@ ENumPos GetNumPos(int nValue)
}
}
ENumPos GetNumPos(const HWP_STRING& sValue)
ENumPos GetNumPos(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(TOP_LEFT, sValue, ENumPos);
ELSE_IF_STRING_IN_ENUM(TOP_CENTER, sValue, ENumPos);

View File

@ -12,7 +12,7 @@ EArcType GetArcType(int nValue)
}
}
EArcType GetArcType(const HWP_STRING& sValue)
EArcType GetArcType(HWP_STRING sValue)
{
IF_STRING_IN_ENUM(PIE, sValue, EArcType);
ELSE_IF_STRING_IN_ENUM(CHORD, sValue, EArcType);

View File

@ -13,7 +13,7 @@ enum class EArcType
};
EArcType GetArcType(int nValue);
EArcType GetArcType(const HWP_STRING& sValue);
EArcType GetArcType(HWP_STRING sValue);
class CCtrlShapeEllipse : public CCtrlGeneralShape
{

View File

@ -354,29 +354,7 @@ void CCtrlShapePic::ReadFromHWPX(CXMLReader &oReader, int nVersion)
else if ("hp:effects" == sNodeName)
ReadEffects(oReader, EHanType::HWPX);
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)
{
const std::string sType{oReader.GetTextA()};
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.GetText();
}
END_READ_ATTRIBUTES(oReader)
}
ReadImage(oReader, EHanType::HWPX);
else if ("hp:imgDim" == sNodeName)
{
START_READ_ATTRIBUTES(oReader)
@ -419,6 +397,10 @@ void CCtrlShapePic::ReadFromHWPML(CXMLReader &oReader)
ReadImageClip(oReader, EHanType::HWPML);
else if ("EFFECTS" == sNodeName)
ReadEffects(oReader, EHanType::HWPML);
else if ("IMAGE" == sNodeName)
ReadImage(oReader, EHanType::HWPML);
else
CCtrlGeneralShape::ParseChildren(oReader, 0, EHanType::HWPML);
}
END_WHILE
}
@ -455,6 +437,31 @@ void CCtrlShapePic::ReadEffects(CXMLReader &oReader, EHanType eType)
END_WHILE
}
void CCtrlShapePic::ReadImage(CXMLReader &oReader, EHanType eType)
{
START_READ_ATTRIBUTES(oReader)
{
if (GetAttributeName(EAttribute::Bright, eType) == sAttributeName)
m_chBright = (HWP_BYTE)oReader.GetInt();
else if (GetAttributeName(EAttribute::Contrast, eType) == sAttributeName)
m_chContrast = (HWP_BYTE)oReader.GetInt();
else if (GetAttributeName(EAttribute::Effect, eType) == sAttributeName)
{
const std::string sType{oReader.GetTextA()};
if (GetValueName(EValue::RealPic, eType) == sType)
m_chEffect = 0;
else if (GetValueName(EValue::GrayScale, eType) == sType)
m_chEffect = 1;
else if (GetValueName(EValue::BlackWhite, eType) == sType)
m_chEffect = 2;
}
else if (GetAttributeName(EAttribute::BinItem, eType) == sAttributeName)
m_sBinDataID = oReader.GetText();
}
END_READ_ATTRIBUTES(oReader)
}
EShapeType CCtrlShapePic::GetShapeType() const
{
return EShapeType::Pic;

View File

@ -135,6 +135,7 @@ class CCtrlShapePic : public CCtrlGeneralShape
void ReadImageClip(CXMLReader& oReader, EHanType eType);
void ReadEffects(CXMLReader& oReader, EHanType eType);
void ReadImage(CXMLReader& oReader, EHanType eType);
public:
CCtrlShapePic();
CCtrlShapePic(const HWP_STRING& sCtrlID);

View File

@ -1,5 +1,7 @@
#include "CtrlTable.h"
#include "../Common/NodeNames.h"
namespace HWP
{
CCtrlTable::CCtrlTable(const HWP_STRING& sCtrlID)
@ -15,51 +17,51 @@ CCtrlTable::CCtrlTable(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVers
{
START_READ_ATTRIBUTES(oReader)
{
if ("rowCnt" == sAttributeName)
if (GetAttributeName(EAttribute::RowCount, eType) == sAttributeName)
m_shNRows = oReader.GetInt();
else if ("colCnt" == sAttributeName)
else if (GetAttributeName(EAttribute::ColCount, eType) == sAttributeName)
m_shNCols = oReader.GetInt();
else if ("cellSpacing" == sAttributeName)
else if (GetAttributeName(EAttribute::CellSpacing, eType) == sAttributeName)
m_shCellSpacing = oReader.GetInt();
else if ("borderFillIDRef" == sAttributeName)
else if (GetAttributeName(EAttribute::BorderFill, eType) == sAttributeName)
m_shBorderFillID = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
WHILE_READ_NEXT_NODE_WITH_NAME(oReader)
{
if ("hp:inMargin" == sNodeName)
if (GetNodeName(ENode::InSideMargin, eType) == sNodeName)
{
START_READ_ATTRIBUTES(oReader)
{
if ("left" == sAttributeName)
if (GetAttributeName(EAttribute::Left, eType) == sAttributeName)
m_shInLSpace = oReader.GetInt();
else if ("right" == sAttributeName)
else if (GetAttributeName(EAttribute::Right, eType) == sAttributeName)
m_shInRSpace = oReader.GetInt();
else if ("top" == sAttributeName)
else if (GetAttributeName(EAttribute::Top, eType) == sAttributeName)
m_shInTSpace = oReader.GetInt();
else if ("bottom" == sAttributeName)
else if (GetAttributeName(EAttribute::Bottom, eType) == sAttributeName)
m_shInBSpace = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
}
else if ("hp:cellzoneList" == sNodeName)
else if (GetNodeName(ENode::CellZoneList, eType) == sNodeName)
{
WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Child, "hp:cellzone")
WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Child, GetNodeName(ENode::CellZone, eType))
{
TCellZone* pCellZone = new TCellZone();
START_READ_ATTRIBUTES(oReader)
{
if ("startRowAddr" == sAttributeName)
if (GetAttributeName(EAttribute::StartRowAddr, eType) == sAttributeName)
pCellZone->m_shStartRowAddr = oReader.GetInt();
else if ("startColAddr" == sAttributeName)
else if (GetAttributeName(EAttribute::StartColAddr, eType) == sAttributeName)
pCellZone->m_shStartColAddr = oReader.GetInt();
else if ("endRowAddr" == sAttributeName)
else if (GetAttributeName(EAttribute::EndRowAddr, eType) == sAttributeName)
pCellZone->m_shEndRowAddr = oReader.GetInt();
else if ("endColAddr" == sAttributeName)
else if (GetAttributeName(EAttribute::EndColAddr, eType) == sAttributeName)
pCellZone->m_shEndColAddr = oReader.GetInt();
else if ("borderFillIDRef" == sAttributeName)
else if (GetAttributeName(EAttribute::BorderFill, eType) == sAttributeName)
pCellZone->m_shBorderFillIDRef = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
@ -68,10 +70,10 @@ CCtrlTable::CCtrlTable(const HWP_STRING& sCtrlID, CXMLReader& oReader, int nVers
}
END_WHILE
}
else if ("hp:tr" == sNodeName)
else if (GetNodeName(ENode::Row, eType) == sNodeName)
{
WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Child, "hp:tc")
m_arCells.push_back(new CTblCell(oReader, nVersion));
WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Child, GetNodeName(ENode::Cell, eType))
m_arCells.push_back(new CTblCell(oReader, nVersion, eType));
END_WHILE
}
else

View File

@ -8,7 +8,7 @@ namespace HWP
struct TCellZone
{
short m_shStartRowAddr;
short m_shStartColAddr;;
short m_shStartColAddr;
short m_shEndRowAddr;
short m_shEndColAddr;
short m_shBorderFillIDRef;

View File

@ -45,7 +45,7 @@ CHWPPargraph::CHWPPargraph(CXMLReader& oReader, int nVersion, EHanType eType)
else
m_chBreakType &= 0b11111011;
}
else if (GetAttributeName(EAttribute::ColumnBreak, eType) == sAttributeName)
else if (Equals(EAttribute::ColumnBreak, eType, sAttributeName))
{
if (oReader.GetBool())
m_chBreakType |= 0b00001000;
@ -97,12 +97,6 @@ bool CHWPPargraph::ParseHWPParagraph(CXMLReader& oReader, int nCharShapeID, int
if (GetNodeName(ENode::SectionDef, eType) == sNodeName)
m_arP.push_back(new CCtrlSectionDef(L"dces", oReader, nVersion));
else if (GetNodeName(ENode::Ctrl, eType) == sNodeName)
{
WHILE_READ_NEXT_NODE(oReader)
AddCtrl(CCtrl::GetCtrl(oReader, nVersion));
END_WHILE
}
else if (GetNodeName(ENode::Char, eType) == sNodeName)
{
if (oReader.IsEmptyNode())
@ -170,6 +164,14 @@ bool CHWPPargraph::ParseHWPParagraph(CXMLReader& oReader, int nCharShapeID, int
m_arP.push_back(new CCtrlShapeTextArt(L"tat$", oReader, nVersion, eType));
else if (GetNodeName(ENode::Video, eType) == sNodeName)
m_arP.push_back(new CCtrlShapeVideo(L"div$", oReader, nVersion, eType));
else if (EHanType::HWPX == eType && "hp:ctrl" == sNodeName)
{
WHILE_READ_NEXT_NODE(oReader)
AddCtrl(CCtrl::GetCtrl(oReader, nVersion, EHanType::HWPX));
END_WHILE
}
else if (EHanType::HWPML == eType)
AddCtrl(CCtrl::GetCtrl(oReader, nVersion, EHanType::HWPML));
if (unCurrentParaCount != m_arP.size())
return true;

View File

@ -1,6 +1,8 @@
#include "TblCell.h"
#include "CtrlCharacter.h"
#include "../Common/NodeNames.h"
namespace HWP
{
CTblCell::CTblCell(int nSize, CHWPStream& oBuffer, int nOff, int nVersion)
@ -25,7 +27,16 @@ CTblCell::CTblCell(int nSize, CHWPStream& oBuffer, int nOff, int nVersion)
oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true));
}
CTblCell::CTblCell(CXMLReader& oReader, int nVersion)
CTblCell::CTblCell(CXMLReader& oReader, int nVersion, EHanType eType)
{
switch (eType)
{
case EHanType::HWPX: ReadFromHWPX(oReader, nVersion); return;
case EHanType::HWPML: ReadFromHWPML(oReader); return;
}
}
void CTblCell::ReadFromHWPX(CXMLReader &oReader, int nVersion)
{
m_shBorderFill = oReader.GetAttributeInt("borderFillIDRef");
@ -65,42 +76,87 @@ CTblCell::CTblCell(CXMLReader& oReader, int nVersion)
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)
}
ReadCellMargin(oReader, EHanType::HWPX);
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;
if (ECtrlObjectType::Character != pCellParagraphs->GetCtrls().back()->GetCtrlType())
pCellParagraphs->AddCtrl(new CCtrlCharacter(L" _", ECtrlCharType::PARAGRAPH_BREAK));
m_arParas.push_back(pCellParagraphs);
}
ReadCell(oReader, nVersion, EHanType::HWPX);
END_WHILE
}
}
END_WHILE
}
void CTblCell::ReadFromHWPML(CXMLReader &oReader)
{
START_READ_ATTRIBUTES(oReader)
{
if ("Name" == sAttributeName)
m_sMergedColName = oReader.GetText();
else if ("ColAddr" == sAttributeName)
m_shColAddr = oReader.GetInt();
else if ("RowAddr" == sAttributeName)
m_shRowAddr = oReader.GetInt();
else if ("ColSpan" == sAttributeName)
m_shColSpan = oReader.GetInt();
else if ("RowSpan" == sAttributeName)
m_shRowSpan = oReader.GetInt();
else if ("Width" == sAttributeName)
m_nWidth = oReader.GetInt();
else if ("Height" == sAttributeName)
m_nHeight = oReader.GetInt();
else if ("BorderFill" == sAttributeName)
m_shBorderFill = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
WHILE_READ_NEXT_NODE_WITH_NAME(oReader)
{
if ("CELLMARGIN" == sNodeName)
ReadCellMargin(oReader, EHanType::HWPML);
else if ("PARALIST" == sNodeName)
{
m_eVertAlign = ::HWP::GetVertAlign(oReader.GetAttribute("VertAlign"));
WHILE_READ_NEXT_NODE_WITH_ONE_NAME(oReader, "P")
ReadCell(oReader, 0, EHanType::HWPML);
END_WHILE
}
}
END_WHILE
}
void CTblCell::ReadCellMargin(CXMLReader &oReader, EHanType eType)
{
START_READ_ATTRIBUTES(oReader)
{
if (GetAttributeName(EAttribute::Left, eType) == sAttributeName)
m_arMargin[0] = oReader.GetInt();
else if (GetAttributeName(EAttribute::Right, eType) == sAttributeName)
m_arMargin[1] = oReader.GetInt();
else if (GetAttributeName(EAttribute::Top, eType) == sAttributeName)
m_arMargin[2] = oReader.GetInt();
else if (GetAttributeName(EAttribute::Bottom, eType) == sAttributeName)
m_arMargin[3] = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
}
void HWP::CTblCell::ReadCell(CXMLReader &oReader, int nVersion, EHanType eType)
{
CCellParagraph *pCellParagraphs = new CCellParagraph(oReader, nVersion, eType);
if (nullptr == pCellParagraphs)
return;
if (ECtrlObjectType::Character != pCellParagraphs->GetCtrls().back()->GetCtrlType())
pCellParagraphs->AddCtrl(new CCtrlCharacter(L" _", ECtrlCharType::PARAGRAPH_BREAK));
m_arParas.push_back(pCellParagraphs);
}
void CTblCell::SetVertAlign(EVertAlign eVertAlign)
{
m_eVertAlign = eVertAlign;

View File

@ -22,9 +22,14 @@ class CTblCell
EVertAlign m_eVertAlign;
HWP_STRING m_sMergedColName;
void ReadFromHWPX(CXMLReader& oReader, int nVersion);
void ReadFromHWPML(CXMLReader& oReader);
void ReadCellMargin(CXMLReader& oReader, EHanType eType);
void ReadCell(CXMLReader& oReader, int nVersion, EHanType eType);
public:
CTblCell(int nSize, CHWPStream& oBuffer, int nOff, int nVersion);
CTblCell(CXMLReader& oReader, int nVersion);
CTblCell(CXMLReader& oReader, int nVersion, EHanType eType);
void SetVertAlign(EVertAlign eVertAlign);