#pragma once #include "Structures.h" #include "../../Common/DocxFormat/Source/Base/Nullable.h" namespace NSPresentationEditor { #define DEFAULT_BEFORE(EXIST_PARAM, PARAM) \ if (!EXIST_PARAM && oSrc.##EXIST_PARAM) \ { \ EXIST_PARAM = true; \ PARAM = oSrc.##PARAM; \ } #define APPLY_AFTER(EXIST_PARAM, PARAM) \ if (oSrc.##EXIST_PARAM) \ { \ EXIST_PARAM = true; \ PARAM = oSrc.##PARAM; \ } static CString ToNode(const NSCommon::nullable_base& prop, const CString& strName) { if (!prop.is_init()) return _T(""); int n = (int)prop.get(); CString strVal = XmlUtils::IntToString(n); return _T("<") + strName + _T(">") + strVal + _T(""); } static CString ToNode(const NSCommon::nullable_base& prop, const CString& strName) { if (!prop.is_init()) return _T(""); int n = (int)prop.get(); CString strVal = XmlUtils::IntToString(n); return _T("<") + strName + _T(">") + strVal + _T(""); } static CString ToNode(const NSCommon::nullable_base& prop, const CString& strName) { if (!prop.is_init()) return _T(""); CString strVal = XmlUtils::UIntToString((size_t)prop.get()); return _T("<") + strName + _T(">") + strVal + _T(""); } static CString ToNode(const NSCommon::nullable_base& prop, const CString& strName) { if (!prop.is_init()) return _T(""); CString strVal = XmlUtils::DoubleToString(prop.get()); return _T("<") + strName + _T(">") + strVal + _T(""); } static CString ToNode(const NSCommon::nullable_base& prop, const CString& strName) { if (!prop.is_init()) return _T(""); CString strVal = XmlUtils::UIntToString(prop->GetLONG()); return _T("<") + strName + _T(">") + strVal + _T(""); } class CFontProperties { public: BYTE FontNameProp; CString strFontName; CString strPanose; CString strPitchFamily; LONG lFontFixed; std::vector arFontCharsets; public: CFontProperties() : FontNameProp(0), strFontName(_T("")), strPanose(_T("")), strPitchFamily(_T("")), lFontFixed(0), arFontCharsets() { } ~CFontProperties() { } CFontProperties(const CFontProperties& oSrc) { *this = oSrc; } CFontProperties& operator=(const CFontProperties& oSrc) { FontNameProp = oSrc.FontNameProp; strFontName = oSrc.strFontName; strPanose = oSrc.strPanose; strPitchFamily = oSrc.strPitchFamily; lFontFixed = oSrc.lFontFixed; for (int i =0 ; i< oSrc.arFontCharsets.size(); i++) arFontCharsets.push_back(oSrc.arFontCharsets[i]); return *this; } AVSINLINE void SetFont(CFont& oFont) { strFontName = oFont.Name; strPanose = oFont.Panose; strPitchFamily = oFont.PitchFamily; lFontFixed = (LONG)oFont.Monospace; arFontCharsets.clear(); arFontCharsets.push_back(oFont.Charset); } }; class CTextCFRun { public: NSCommon::nullable_base FontBold; NSCommon::nullable_base FontItalic; NSCommon::nullable_base FontUnderline; NSCommon::nullable_base FontStrikeout; NSCommon::nullable_base FontShadow; NSCommon::nullable_base Typeface; // fontRef NSCommon::nullable_base EAFontRef; // eaFontRef NSCommon::nullable_base AnsiFontRef; // ansiFontRef NSCommon::nullable_base SymbolFontRef; // SymbolFontRef NSCommon::nullable_base BaseLineOffset; // baseline offset NSCommon::nullable_base Color; // text color NSCommon::nullable_base Size; // font size NSCommon::nullable_base Cap; // 0 - none, 1 - TEXT, 2 - text NSCommon::nullable_base FontProperties; public: CTextCFRun() : FontBold(), FontItalic(), FontUnderline(), FontStrikeout(), FontShadow(), Typeface(), EAFontRef(), AnsiFontRef(), SymbolFontRef(), BaseLineOffset(), Color(), Size(), FontProperties(), Cap() { } CTextCFRun(const CTextCFRun& oSrc) { *this = oSrc; } CTextCFRun& operator=(const CTextCFRun& oSrc) { FontBold = oSrc.FontBold; FontItalic = oSrc.FontItalic; FontUnderline = oSrc.FontUnderline; FontStrikeout = oSrc.FontStrikeout; FontShadow = oSrc.FontShadow; Typeface = oSrc.Typeface; EAFontRef = oSrc.EAFontRef; AnsiFontRef = oSrc.AnsiFontRef; SymbolFontRef = oSrc.SymbolFontRef; BaseLineOffset = oSrc.BaseLineOffset; Color = oSrc.Color; Size = oSrc.Size; FontProperties = oSrc.FontProperties; Cap = oSrc.Cap; return *this; } ~CTextCFRun() { } AVSINLINE void ApplyBefore(const CTextCFRun& oSrc) { if (!FontBold.is_init()) FontBold = oSrc.FontBold; if (!FontItalic.is_init()) FontItalic = oSrc.FontItalic; if (!FontUnderline.is_init()) FontUnderline = oSrc.FontUnderline; if (!FontStrikeout.is_init()) FontStrikeout = oSrc.FontStrikeout; if (!FontShadow.is_init()) FontShadow = oSrc.FontShadow; if (!Typeface.is_init()) Typeface = oSrc.Typeface; if (!EAFontRef.is_init()) EAFontRef = oSrc.EAFontRef; if (!AnsiFontRef.is_init()) AnsiFontRef = oSrc.AnsiFontRef; if (!SymbolFontRef.is_init()) SymbolFontRef = oSrc.SymbolFontRef; if (!BaseLineOffset.is_init()) BaseLineOffset = oSrc.BaseLineOffset; if (!Color.is_init()) Color = oSrc.Color; if (!Size.is_init()) Size = oSrc.Size; if (!Cap.is_init()) Cap = oSrc.Cap; if (!FontProperties.is_init()) FontProperties = oSrc.FontProperties; } AVSINLINE void ApplyAfter(const CTextCFRun& oSrc) { if (oSrc.FontBold.is_init()) FontBold = oSrc.FontBold; if (oSrc.FontItalic.is_init()) FontItalic = oSrc.FontItalic; if (oSrc.FontUnderline.is_init()) FontUnderline = oSrc.FontUnderline; if (oSrc.FontStrikeout.is_init()) FontStrikeout = oSrc.FontStrikeout; if (oSrc.FontShadow.is_init()) FontShadow = oSrc.FontShadow; bool bTypefaceSetUp = false; if (oSrc.Typeface.is_init()) { Typeface = oSrc.Typeface; bTypefaceSetUp = true; } if (oSrc.EAFontRef.is_init()) EAFontRef = oSrc.EAFontRef; if (oSrc.AnsiFontRef.is_init()) AnsiFontRef = oSrc.AnsiFontRef; if (oSrc.SymbolFontRef.is_init()) SymbolFontRef = oSrc.SymbolFontRef; if (oSrc.BaseLineOffset.is_init()) BaseLineOffset = oSrc.BaseLineOffset; if (oSrc.Color.is_init()) Color = oSrc.Color; if (oSrc.Size.is_init()) Size = oSrc.Size; if (oSrc.Cap.is_init()) Cap = oSrc.Cap; if (oSrc.FontProperties.is_init()) { FontProperties = oSrc.FontProperties; if (!bTypefaceSetUp) Typeface.reset(); } } CString ToString(LONG lCount) { NSPresentationEditor::CXmlWriter oWriter; oWriter.WriteNodeBegin(_T("Character"), true); oWriter.WriteAttributeLONG(_T("count"), lCount); oWriter.WriteNodeEnd(_T("Character"), true, false); oWriter.WriteNodeBegin(_T("Attributes")); int nBold = 0; int nItalic = 0; CString strXml = _T(""); if (FontBold.is_init()) { if (FontBold.get()) { strXml += _T("1"); nBold = 1; } } if (FontItalic.is_init()) { if (FontItalic.get()) { strXml += _T("1"); nItalic = 1; } } if (FontUnderline.is_init()) { if (FontUnderline.get()) { strXml += _T("1"); } } if (FontStrikeout.is_init()) { if (FontStrikeout.get()) { strXml += _T("1"); } } if (FontShadow.is_init()) { if (FontShadow.get()) { strXml += _T("1"); } } strXml += ToNode(BaseLineOffset, _T("baseline-shift")); strXml += ToNode(Color, _T("brush-color1")); strXml += ToNode(Size, _T("font-size")); if (FontProperties.is_init()) { strXml += (_T("") + FontProperties->strFontName + _T("")); oWriter.WriteString(strXml); oWriter.WriteNodeEnd(_T("Attributes")); // font properties strXml = _T(""); strXml += (_T("")); if (0 < FontProperties->arFontCharsets.size()) strXml += (_T("")); if (_T("unknown") != FontProperties->strPitchFamily) strXml += (_T("")); if (-1 != FontProperties->lFontFixed) strXml += (_T("")); if (_T("") != FontProperties->strPanose) strXml += (_T("")); strXml += (_T("")); return oWriter.GetData(); } }; class CParagraph { public: LONG m_lTextType; LONG m_lTextLevel; CTextPFRun m_oPFRun; std::vector m_arSpans; public: CParagraph() : m_oPFRun(), m_arSpans() { m_lTextType = 0; m_lTextLevel = 0; } CParagraph(const CParagraph& oSrc) { *this = oSrc; } CParagraph& operator=(const CParagraph& oSrc) { m_lTextLevel = oSrc.m_lTextLevel; m_lTextType = oSrc.m_lTextType; m_oPFRun = oSrc.m_oPFRun; m_arSpans = oSrc.m_arSpans; return *this; } ~CParagraph() { m_arSpans.clear(); } AVSINLINE void CheckErrors() { if (IsEmpty()) { m_oPFRun.hasBullet = false; } size_t nCountS = m_arSpans.size(); for (size_t i = 0; i < nCountS; ++i) { m_arSpans[i].m_strText.Replace((TCHAR)(11), (TCHAR)('\n')); } } AVSINLINE bool IsEmpty() { size_t nCountSpans = m_arSpans.size(); for (size_t i = 0; i < nCountSpans; ++i) { int nLen = m_arSpans[i].m_strText.GetLength(); if (nLen > 1) return false; if ((nLen == 1) && ((_T(" ") != m_arSpans[i].m_strText) && (_T("\n") != m_arSpans[i].m_strText))) return false; } return true; } }; }