#include "HWPRecordParaShape.h" #include "../Common/NodeNames.h" namespace HWP { EHeadingType GetHeadingType(int nValue) { SWITCH(EHeadingType, nValue) { CASE(EHeadingType::OUTLINE); CASE(EHeadingType::NUMBER); CASE(EHeadingType::BULLET); DEFAULT(EHeadingType::NONE); } } EHeadingType GetHeadingType(const std::string& sValue, EHanType eType) { if (sValue.empty() || GetValueName(EValue::None, eType) == sValue) return EHeadingType::NONE; if (GetValueName(EValue::Outline, eType) == sValue) return EHeadingType::OUTLINE; if (GetValueName(EValue::Number, eType) == sValue) return EHeadingType::NUMBER; if (GetValueName(EValue::Bullet, eType) == sValue) return EHeadingType::BULLET; return EHeadingType::NONE; } EHorizontalAlign GetHorizontalAlign(int nValue) { SWITCH(EHorizontalAlign, nValue) { CASE(EHorizontalAlign::LEFT); CASE(EHorizontalAlign::RIGHT); CASE(EHorizontalAlign::CENTER); CASE(EHorizontalAlign::DISTRIBUTE); CASE(EHorizontalAlign::DISTRIBUTE_SPACE); DEFAULT(EHorizontalAlign::JUSTIFY); } } EHorizontalAlign GetHorizontalAlign(const std::string& sValue, EHanType eType) { if (sValue.empty() || GetValueName(EValue::Left, eType) == sValue) return EHorizontalAlign::LEFT; if (GetValueName(EValue::Center, eType) == sValue) return EHorizontalAlign::CENTER; if (GetValueName(EValue::Right, eType) == sValue) return EHorizontalAlign::RIGHT; if (GetValueName(EValue::Distribute, eType) == sValue) return EHorizontalAlign::DISTRIBUTE; if (GetValueName(EValue::DistributeSpace, eType) == sValue) return EHorizontalAlign::DISTRIBUTE_SPACE; if (GetValueName(EValue::Justify, eType) == sValue) return EHorizontalAlign::JUSTIFY; return EHorizontalAlign::LEFT; } EVerticalAlign GetVerticalAlign(int nValue) { SWITCH(EVerticalAlign, nValue) { CASE(EVerticalAlign::TOP); CASE(EVerticalAlign::CENTER); CASE(EVerticalAlign::BOTTOM); DEFAULT(EVerticalAlign::BASELINE); } } EVerticalAlign GetVerticalAlign(const std::string& sValue, EHanType eType) { if (sValue.empty() || GetValueName(EValue::Top, eType) == sValue) return EVerticalAlign::TOP; if (GetValueName(EValue::Center, eType) == sValue) return EVerticalAlign::CENTER; if (GetValueName(EValue::Bottom, eType) == sValue) return EVerticalAlign::BOTTOM; if (GetValueName(EValue::Baseline, eType) == sValue) return EVerticalAlign::BASELINE; return EVerticalAlign::TOP; } CHWPRecordParaShape::CHWPRecordParaShape(CHWPDocInfo& oDocInfo, int nTagNum, int nLevel, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) : CHWPRecord(nTagNum, nLevel, nSize), m_pParent(&oDocInfo) { int nTypeBits; oBuffer.ReadInt(nTypeBits); m_eAlign = GetHorizontalAlign((nTypeBits >> 2) & 0x07); m_chBreakLatinWord = (HWP_BYTE)((nTypeBits >> 5) & 0x03); m_chBreakNonLatinWord = (HWP_BYTE)((nTypeBits >> 7) & 0x01); m_bSnapToGrid = CHECK_FLAG(nTypeBits, 0x80); m_chCondense = (HWP_BYTE)((nTypeBits >> 9) & 0x7F); m_bWidowOrphan = CHECK_FLAG(nTypeBits, 0x10000); m_bKeepWithNext = CHECK_FLAG(nTypeBits, 0x20000); m_bPageBreakBefore = CHECK_FLAG(nTypeBits, 0x40000); m_eVertAlign = ::HWP::GetVerticalAlign((nTypeBits >> 20) & 0x03); m_bFontLineHeight = CHECK_FLAG(nTypeBits, 0x100000); m_eHeadingType = ::HWP::GetHeadingType((nTypeBits >> 23) & 0x03); m_chHeadingLevel = (HWP_BYTE)((nTypeBits >> 25) & 0x07); m_bConnect = CHECK_FLAG(nTypeBits, 0x800000); m_bIgnoreMargin = CHECK_FLAG(nTypeBits, 0x1000000); m_bParaTailShape = CHECK_FLAG(nTypeBits, 0x2000000); oBuffer.ReadInt(m_nMarginLeft); oBuffer.ReadInt(m_nMarginRight); oBuffer.ReadInt(m_nIndent); oBuffer.ReadInt(m_nMarginPrev); oBuffer.ReadInt(m_nMarginNext); if (nVersion < 5025) { m_nLineSpacingType = (HWP_BYTE)(nTypeBits & 0x03); oBuffer.ReadInt(m_nLineSpacing); } else oBuffer.Skip(4); oBuffer.ReadShort(m_shTabDef); oBuffer.ReadShort(m_shHeadingIdRef); oBuffer.ReadShort(m_shBorderFill); oBuffer.ReadShort(m_shOffsetLeft); oBuffer.ReadShort(m_shOffsetRight); oBuffer.ReadShort(m_shOffsetTop); oBuffer.ReadShort(m_shOffsetBottom); if (nVersion >= 5017) { int nAttrBits; oBuffer.ReadInt(nAttrBits); m_chLineWrap = (HWP_BYTE)(nAttrBits & 0x03); m_bAutoSpaceEAsianEng = CHECK_FLAG(nAttrBits, 0x10); m_bAutoSpaceEAsianNum = CHECK_FLAG(nAttrBits, 0x20); } else oBuffer.Skip(4); if (nVersion >= 5025) { int nAttrBits; oBuffer.ReadInt(nAttrBits); m_nLineSpacingType = (HWP_BYTE)(nAttrBits & 0x0F); oBuffer.ReadInt(m_nLineSpacing); } else oBuffer.Skip(8); } CHWPRecordParaShape::CHWPRecordParaShape(CHWPDocInfo& oDocInfo, CXMLReader& oReader, EHanType eType) : 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_nIndent(0), m_nMarginLeft(0), m_nMarginRight(0), m_nMarginPrev(0), m_nMarginNext(0) { //В HWPX в данной ноде данный пишутся по типу данный в нодах //В HWPML в данной ноде данные пишутся по типу данные в аргументах if (EHanType::HWPX == eType) { START_READ_ATTRIBUTES(oReader) { if (GetAttributeName(EAttribute::TabDef, eType)) m_shTabDef = oReader.GetInt(); else if (GetAttributeName(EAttribute::Condense, eType) == sAttributeName) m_chCondense = (HWP_BYTE)oReader.GetInt(); else if (GetAttributeName(EAttribute::FontLineHeight, eType) == sAttributeName) m_bFontLineHeight = oReader.GetBool(); else if (GetAttributeName(EAttribute::SnapToGrid, eType) == sAttributeName) m_bSnapToGrid = oReader.GetBool(); } END_READ_ATTRIBUTES(oReader) RecursiveParaShape(oReader); return; } else if (EHanType::HWPML != eType) return; START_READ_ATTRIBUTES(oReader) { if ("Align" == sAttributeName) m_eAlign = ::HWP::GetHorizontalAlign(oReader.GetTextA(), eType); else if ("VerAlign" == sAttributeName) m_eVertAlign = ::HWP::GetVerticalAlign(oReader.GetTextA(), eType); else if ("HeadingType" == sAttributeName) m_eHeadingType = ::HWP::GetHeadingType(oReader.GetTextA(), eType); else if ("Heading" == sAttributeName) m_shHeadingIdRef = oReader.GetInt(); else if ("Level" == sAttributeName) m_chHeadingLevel = (HWP_BYTE)oReader.GetInt(); else if ("TabDef" == sAttributeName) m_shTabDef = oReader.GetInt(); else if ("BreakLatinWord" == sAttributeName) { const std::string sType{oReader.GetTextA()}; if ("KeepWord" == sType) m_chBreakLatinWord = 0; else if ("BreakWord" == sType) m_chBreakLatinWord = 1; else if ("Hyphenation" == sType) m_chBreakLatinWord = 2; } else if ("BreakNonLatinWord" == sAttributeName) { //TODO:: проверить соответсвие hwpx и hwpml } else if ("Condense" == sAttributeName) m_chCondense = (HWP_BYTE)oReader.GetInt(); else if ("WidowOrphan" == sAttributeName) m_bWidowOrphan = oReader.GetBool(); else if ("KeepWithNext" == sAttributeName) m_bKeepWithNext = oReader.GetBool(); else if ("KeepLines" == sAttributeName) { /*TODO:: проверить соответсвие hwpx и hwpml*/ } else if ("PageBreakBefore" == sAttributeName) m_bPageBreakBefore = oReader.GetBool(); else if ("FontLineHeight" == sAttributeName) m_bFontLineHeight = oReader.GetBool(); else if ("SnapToGrid" == sAttributeName) m_bSnapToGrid = oReader.GetBool(); else if ("LineWrap" == sAttributeName) { const std::string sType{oReader.GetTextA()}; if ("Break" == sType) m_chLineWrap = 0; else if ("Squeeze" == sType) m_chLineWrap = 1; else if ("Keep" == sType) m_chLineWrap = 2; } else if ("AutoSpaceEAsianEng" == sAttributeName) m_bAutoSpaceEAsianEng = oReader.GetBool(); else if ("AutoSpaceEAsianNum" == sAttributeName) m_bAutoSpaceEAsianNum = oReader.GetBool(); } END_READ_ATTRIBUTES(oReader) WHILE_READ_NEXT_NODE_WITH_NAME(oReader) { if ("PARAMARGIN" == sNodeName) { START_READ_ATTRIBUTES(oReader) { if ("Indent" == sAttributeName) m_nIndent = oReader.GetInt(); else if ("Left" == sAttributeName) m_nMarginLeft = oReader.GetInt(); else if ("Right" == sAttributeName) m_nMarginRight = oReader.GetInt(); else if ("Prev" == sAttributeName) m_nMarginPrev = oReader.GetInt(); else if ("Next" == sAttributeName) m_nMarginNext = oReader.GetInt(); else if ("LineSpacingType" == sAttributeName) { const std::string sType{oReader.GetTextA()}; if ("Percent" == sType) m_nLineSpacingType = 0; else if ("Fixed" == sType) m_nLineSpacingType = 1; else if ("BetweenLines" == sType) m_nLineSpacingType = 2; else if ("AtLeast" == sType) m_nLineSpacingType = 4; } else if ("LineSpacing" == sAttributeName) m_nLineSpacing = oReader.GetInt(); } END_READ_ATTRIBUTES(oReader) } else if ("PARABORDER" == sNodeName) { START_READ_ATTRIBUTES(oReader) { if ("BorderFill" == sAttributeName) m_shBorderFill = oReader.GetInt(); else if ("OffsetLeft" == sAttributeName) m_shOffsetLeft = oReader.GetInt(); else if ("OffsetRigth" == 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) } } END_WHILE } void CHWPRecordParaShape::RecursiveParaShape(CXMLReader& oReader) { WHILE_READ_NEXT_NODE_WITH_NAME(oReader) { if ("hh:align" == sNodeName) { START_READ_ATTRIBUTES(oReader) { if ("horizontal" == sAttributeName) m_eAlign = ::HWP::GetHorizontalAlign(oReader.GetTextA(), EHanType::HWPX); else if ("vertical" == sAttributeName) m_eVertAlign = ::HWP::GetVerticalAlign(oReader.GetTextA(), EHanType::HWPX); } END_READ_ATTRIBUTES(oReader) } else if ("hh:heading" == sNodeName) { START_READ_ATTRIBUTES(oReader) { if ("type" == sAttributeName) m_eHeadingType = ::HWP::GetHeadingType(oReader.GetTextA(), EHanType::HWPX); 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.GetTextA()}; if ("KEEP_WORD" == sType) m_chBreakLatinWord = 0; else if ("BREAK_WORD" == sType) m_chBreakLatinWord = 1; } else if ("breakNonLatinWord" == sAttributeName) { const std::string sType{oReader.GetTextA()}; 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.GetTextA()}; 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.GetTextA()}; 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 || "hp:default" == sNodeName) RecursiveParaShape(oReader); } END_WHILE } EHorizontalAlign CHWPRecordParaShape::GetHorizantalAlign() const { return m_eAlign; } EVerticalAlign CHWPRecordParaShape::GetVerticalAlign() const { return m_eVertAlign; } EHeadingType CHWPRecordParaShape::GetHeadingType() const { return m_eHeadingType; } HWP_BYTE CHWPRecordParaShape::GetHeadingLevel() const { return m_chHeadingLevel; } short CHWPRecordParaShape::GetHeadingIdRef() const { return m_shHeadingIdRef; } bool CHWPRecordParaShape::GetPageBreakBefore() const { return m_bPageBreakBefore; } int CHWPRecordParaShape::GetLineSpacingType() const { return m_nLineSpacingType; } int CHWPRecordParaShape::GetLineSpacing() const { return m_nLineSpacing; } int CHWPRecordParaShape::GetMarginPrev() const { return m_nMarginPrev; } int CHWPRecordParaShape::GetMarginNext() const { return m_nMarginNext; } int CHWPRecordParaShape::GetIndent() const { return m_nIndent; } int CHWPRecordParaShape::GetLeftIndent() const { return m_nMarginLeft; } int CHWPRecordParaShape::GetRightIndent() const { return m_nMarginRight; } short CHWPRecordParaShape::GetTabDef() const { return m_shTabDef; } bool CHWPRecordParaShape::KeepWithNext() const { return m_bKeepWithNext; } }