diff --git a/OFDFile/OFDFile.pro b/OFDFile/OFDFile.pro index e0f1ead90a..252fe83a1e 100644 --- a/OFDFile/OFDFile.pro +++ b/OFDFile/OFDFile.pro @@ -20,16 +20,28 @@ ADD_DEPENDENCY(graphics, kernel, UnicodeConverter) HEADERS += \ OFDFile.h \ src/Base.h \ + src/Content/Content.h \ + src/Content/GraphicUnit.h \ + src/Content/IPageBlock.h \ + src/Content/Layer.h \ + src/Content/TextObject.h \ src/Document.h \ src/Page.h \ - src/PublicRes.h + src/PublicRes.h \ + src/Utils/Types.h \ + src/Utils/Utils.h SOURCES += \ OFDFile.cpp \ src/Base.cpp \ + src/Content/Content.cpp \ + src/Content/GraphicUnit.cpp \ + src/Content/Layer.cpp \ + src/Content/TextObject.cpp \ src/Document.cpp \ src/Page.cpp \ - src/PublicRes.cpp + src/PublicRes.cpp \ + src/Utils/Types.cpp HEADERS += $$CORE_ROOT_DIR/OOXML/Base/Unit.h SOURCES += $$CORE_ROOT_DIR/OOXML/Base/Unit.cpp diff --git a/OFDFile/src/Content/Content.cpp b/OFDFile/src/Content/Content.cpp new file mode 100644 index 0000000000..506adcdefc --- /dev/null +++ b/OFDFile/src/Content/Content.cpp @@ -0,0 +1,34 @@ +#include "Content.h" + +namespace OFD +{ +CContent::CContent() +{ + +} + +CContent::~CContent() +{ + for (CLayer* pLayer : m_arLayers) + delete pLayer; +} + +bool CContent::Read(XmlUtils::CXmlLiteReader& oLiteReader) +{ + if (L"ofd:Content" != oLiteReader.GetName()) + return false; + + const int nDepth = oLiteReader.GetDepth(); + std::wstring wsNodeName; + + while (oLiteReader.ReadNextSiblingNode(nDepth)) + { + wsNodeName = oLiteReader.GetName(); + + if (L"ofd:Layer" == wsNodeName) + m_arLayers.push_back(new CLayer(oLiteReader)); + } + + return false; +} +} diff --git a/OFDFile/src/Content/Content.h b/OFDFile/src/Content/Content.h new file mode 100644 index 0000000000..ed51011cf5 --- /dev/null +++ b/OFDFile/src/Content/Content.h @@ -0,0 +1,19 @@ +#ifndef CONTENT_H +#define CONTENT_H + +#include "Layer.h" + +namespace OFD +{ +class CContent +{ + std::vector m_arLayers; +public: + CContent(); + ~CContent(); + + bool Read(XmlUtils::CXmlLiteReader& oLiteReader); +}; +} + +#endif // CONTENT_H diff --git a/OFDFile/src/Content/GraphicUnit.cpp b/OFDFile/src/Content/GraphicUnit.cpp new file mode 100644 index 0000000000..0fd51c87ad --- /dev/null +++ b/OFDFile/src/Content/GraphicUnit.cpp @@ -0,0 +1,65 @@ +#include "GraphicUnit.h" +#include "../../../OOXML/Base/Unit.h" + +namespace OFD +{ +CGraphicUnit::CGraphicUnit(XmlUtils::CXmlLiteReader& oLiteReader) + : m_bVisible(true), m_dLineWidth(0.353), m_eCap(ECap::Butt), + m_eJoin(EJoin::Miter), m_dMiterLimit(4.234), m_dDashOffset(0.), + m_uchAlpha(255) +{ + if (0 == oLiteReader.GetAttributesCount() || !oLiteReader.MoveToFirstAttribute()) + return; + + std::wstring wsAttributeName; + + do + { + wsAttributeName = oLiteReader.GetName(); + + if (L"Boundary" == wsAttributeName) + m_oBoundary.Read(oLiteReader.GetText()); + else if (L"Name" == wsAttributeName) + m_wsName = oLiteReader.GetText(); + else if (L"Visible" == wsAttributeName) + m_bVisible = XmlUtils::GetBoolean(oLiteReader.GetText()); + else if (L"CTM" == wsAttributeName) + m_oCTM.Read(oLiteReader.GetText()); + else if (L"DrawParam" == wsAttributeName) + m_unDrawParam = XmlUtils::GetUInteger(oLiteReader.GetText()); + else if (L"LineWidth" == wsAttributeName) + m_dLineWidth = XmlUtils::GetDouble(oLiteReader.GetText()); + else if (L"Cap" == wsAttributeName) + { + const std::wstring wsValue{oLiteReader.GetText()}; + + if (L"Butt" == wsValue) + m_eCap = ECap::Butt; + else if (L"Round" == wsValue) + m_eCap = ECap::Round; + else if (L"Square" == wsValue) + m_eCap = ECap::Square; + } + else if (L"Join" == wsAttributeName) + { + const std::wstring wsValue{oLiteReader.GetText()}; + + if (L"Miter" == wsValue) + m_eJoin = EJoin::Miter; + else if (L"Round" == wsValue) + m_eJoin = EJoin::Round; + else if (L"Bevel" == wsValue) + m_eJoin = EJoin::Bevel; + } + else if (L"MiterLimit" == wsAttributeName) + m_dMiterLimit = XmlUtils::GetDouble(oLiteReader.GetText()); + else if (L"DashOffset" == wsAttributeName) + m_dDashOffset = XmlUtils::GetDouble(oLiteReader.GetText()); + else if (L"Alpha" == wsAttributeName) + m_uchAlpha = XmlUtils::GetUInteger(oLiteReader.GetText()); + } while (oLiteReader.MoveToNextAttribute()); + + oLiteReader.MoveToElement(); +} + +} diff --git a/OFDFile/src/Content/GraphicUnit.h b/OFDFile/src/Content/GraphicUnit.h new file mode 100644 index 0000000000..764ecdcac0 --- /dev/null +++ b/OFDFile/src/Content/GraphicUnit.h @@ -0,0 +1,42 @@ +#ifndef GRAPHICUNIT_H +#define GRAPHICUNIT_H + +#include "../../../DesktopEditor/xml/include/xmlutils.h" +#include "../Utils/Types.h" +#include + +namespace OFD +{ +class CGraphicUnit +{ + TBox m_oBoundary; + std::wstring m_wsName; + bool m_bVisible; + TBox m_oCTM; + unsigned int m_unDrawParam; + double m_dLineWidth; + + enum class ECap + { + Butt, + Round, + Square + } m_eCap; + + enum class EJoin + { + Miter, + Round, + Bevel + } m_eJoin; + + double m_dMiterLimit; + double m_dDashOffset; + std::vector m_arDashPattern; + unsigned char m_uchAlpha; +public: + CGraphicUnit(XmlUtils::CXmlLiteReader& oLiteReader); +}; +} + +#endif // GRAPHICUNIT_H diff --git a/OFDFile/src/Content/IPageBlock.h b/OFDFile/src/Content/IPageBlock.h new file mode 100644 index 0000000000..4769b2aa45 --- /dev/null +++ b/OFDFile/src/Content/IPageBlock.h @@ -0,0 +1,18 @@ +#ifndef IPAGEBLOCK_H +#define IPAGEBLOCK_H + +#include "../../../DesktopEditor/xml/include/xmlutils.h" + +namespace OFD +{ +class IPageBlock +{ + unsigned int m_unID; +public: + IPageBlock(){}; + virtual ~IPageBlock(){}; + virtual bool Read(XmlUtils::CXmlLiteReader& oLiteReader) = 0; +}; +} + +#endif // IPAGEBLOCK_H diff --git a/OFDFile/src/Content/Layer.cpp b/OFDFile/src/Content/Layer.cpp new file mode 100644 index 0000000000..a8aacad283 --- /dev/null +++ b/OFDFile/src/Content/Layer.cpp @@ -0,0 +1,56 @@ +#include "Layer.h" + +#include "../../../OOXML/Base/Unit.h" + +#include "TextObject.h" + +namespace OFD +{ +CLayer::CLayer(XmlUtils::CXmlLiteReader& oLiteReader) + : m_eType(EType::Body) +{ + Read(oLiteReader); +} + +CLayer::~CLayer() +{ + for (IPageBlock* pPageBlock : m_arPageBlocks) + delete pPageBlock; +} + +bool CLayer::Read(XmlUtils::CXmlLiteReader& oLiteReader) +{ + if (L"ofd:Layer" != oLiteReader.GetName()) + return false; + + if (0 != oLiteReader.GetAttributesCount() && oLiteReader.MoveToFirstAttribute()) + { + do + { + if (L"ID" == oLiteReader.GetName()) + m_unID = XmlUtils::GetUInteger(oLiteReader.GetText()); + } while (oLiteReader.MoveToNextAttribute()); + + oLiteReader.MoveToElement(); + } + + const int nDepth = oLiteReader.GetDepth(); + std::wstring wsNodeName; + + IPageBlock* pPageBlock = nullptr; + + while (oLiteReader.ReadNextSiblingNode(nDepth)) + { + wsNodeName = oLiteReader.GetName(); + pPageBlock = nullptr; + + if (L"ofd:TextObject" == wsNodeName) + pPageBlock = new CTextObject(oLiteReader); + + if (nullptr != pPageBlock) + m_arPageBlocks.push_back(pPageBlock); + } + + return true; +} +} diff --git a/OFDFile/src/Content/Layer.h b/OFDFile/src/Content/Layer.h new file mode 100644 index 0000000000..5e4a66a3c2 --- /dev/null +++ b/OFDFile/src/Content/Layer.h @@ -0,0 +1,27 @@ +#ifndef LAYER_H +#define LAYER_H + +#include "IPageBlock.h" + +namespace OFD +{ +class CLayer +{ + enum class EType + { + Body, + Foreground, + Background + } m_eType; + + unsigned int m_unID; + std::vector m_arPageBlocks; +public: + CLayer(XmlUtils::CXmlLiteReader& oLiteReader); + ~CLayer(); + + bool Read(XmlUtils::CXmlLiteReader& oLiteReader); +}; +} + +#endif // LAYER_H diff --git a/OFDFile/src/Content/TextObject.cpp b/OFDFile/src/Content/TextObject.cpp new file mode 100644 index 0000000000..8cc9dae630 --- /dev/null +++ b/OFDFile/src/Content/TextObject.cpp @@ -0,0 +1,124 @@ +#include "TextObject.h" + +#include "../Utils/Utils.h" + +namespace OFD +{ +CTextCode::CTextCode(XmlUtils::CXmlLiteReader& oLiteReader) +{ + if (NO_VALID_NODE(oLiteReader, L"ofd:TextCode")) + return; + + if (0 != oLiteReader.GetAttributesCount() && oLiteReader.MoveToFirstAttribute()) + { + std::wstring wsAttributeName; + + do + { + wsAttributeName = oLiteReader.GetName(); + + if (L"X" == wsAttributeName) + m_dX = XmlUtils::GetDouble(oLiteReader.GetText()); + else if (L"Y" == wsAttributeName) + m_dY = XmlUtils::GetDouble(oLiteReader.GetText()); + else if (L"DeltaX" == wsAttributeName) + m_arDeltaX = GetDoubleValues(oLiteReader.GetText()); + else if (L"DeltaY" == wsAttributeName) + m_arDeltaY = GetDoubleValues(oLiteReader.GetText()); + } while (oLiteReader.MoveToNextAttribute()); + } + + oLiteReader.MoveToElement(); + + m_wsText = oLiteReader.GetText2(); +} + +CTextObject::CTextObject(XmlUtils::CXmlLiteReader& oLiteReader) + : CGraphicUnit(oLiteReader), + m_bStroke(false), m_bFill(false), m_dHScale(1.), + m_unReadDirection(0), m_unCharDirection(0), m_unWeight(400), + m_bItalic(false), + m_pFillColor(nullptr), m_pStrokeColor(nullptr) +{ + CTextObject::Read(oLiteReader); +} + +CTextObject::~CTextObject() +{ + if (nullptr != m_pFillColor) + delete m_pFillColor; + + if (nullptr != m_pStrokeColor) + delete m_pStrokeColor; + + for (CTextCode* pTextCode : m_arTextCodes) + delete pTextCode; +} + +bool CTextObject::Read(XmlUtils::CXmlLiteReader& oLiteReader) +{ + if (NO_VALID_NODE(oLiteReader, L"ofd:TextObject")) + return false; + + if (0 != oLiteReader.GetAttributesCount() && oLiteReader.MoveToFirstAttribute()) + { + std::wstring wsAttributeName; + + do + { + wsAttributeName = oLiteReader.GetName(); + + if (L"Font" == wsAttributeName) + { + m_unFont = XmlUtils::GetUInteger(oLiteReader.GetText()); + } + else if (L"Size" == wsAttributeName) + m_dSize = XmlUtils::GetDouble(oLiteReader.GetText()); + else if (L"Stroke" == wsAttributeName) + m_bStroke = XmlUtils::GetBoolean(oLiteReader.GetText()); + else if (L"Fill" == wsAttributeName) + m_bFill = XmlUtils::GetBoolean(oLiteReader.GetText()); + else if (L"HScale" == wsAttributeName) + m_dHScale = XmlUtils::GetDouble(oLiteReader.GetText()); + else if (L"ReadDirection" == wsAttributeName) + m_unReadDirection = XmlUtils::GetUInteger(oLiteReader.GetText()); + else if (L"CharDirection" == wsAttributeName) + m_unCharDirection = XmlUtils::GetUInteger(oLiteReader.GetText()); + else if (L"Weight" == wsAttributeName) + m_unWeight = XmlUtils::GetUInteger(oLiteReader.GetText()); + else if (L"Italic" == wsAttributeName) + m_bItalic = XmlUtils::GetBoolean(oLiteReader.GetText()); + } while (oLiteReader.MoveToNextAttribute()); + } + + oLiteReader.MoveToElement(); + + const int nDepth = oLiteReader.GetDepth(); + std::wstring wsNodeName; + + while (oLiteReader.ReadNextSiblingNode(nDepth)) + { + wsNodeName = oLiteReader.GetName(); + + if (L"ofd:FillColor" == wsNodeName && m_bFill) + { + if (nullptr != m_pFillColor) + delete m_pFillColor; + + m_pFillColor = new TColor(oLiteReader); + } + else if (L"ofd:StrokeColor" == wsNodeName && m_bStroke) + { + if (nullptr != m_pStrokeColor) + delete m_pStrokeColor; + + m_pStrokeColor = new TColor(oLiteReader); + } + else if (L"ofd:TextCode" == wsNodeName) + m_arTextCodes.push_back(new CTextCode(oLiteReader)); + } + + return true; +} + +} diff --git a/OFDFile/src/Content/TextObject.h b/OFDFile/src/Content/TextObject.h new file mode 100644 index 0000000000..d748f2c96a --- /dev/null +++ b/OFDFile/src/Content/TextObject.h @@ -0,0 +1,46 @@ +#ifndef TEXTOBJECT_H +#define TEXTOBJECT_H + +#include "IPageBlock.h" +#include "GraphicUnit.h" + +namespace OFD +{ +class CTextCode +{ + double m_dX; + double m_dY; + + std::vector m_arDeltaX; + std::vector m_arDeltaY; + + std::wstring m_wsText; +public: + CTextCode(XmlUtils::CXmlLiteReader& oLiteReader); +}; + +class CTextObject : public IPageBlock, public CGraphicUnit +{ + unsigned int m_unFont; + double m_dSize; + bool m_bStroke; + bool m_bFill; + double m_dHScale; + unsigned int m_unReadDirection; + unsigned int m_unCharDirection; + unsigned int m_unWeight; + bool m_bItalic; + + TColor* m_pFillColor; + TColor* m_pStrokeColor; + + std::vector m_arTextCodes; +public: + CTextObject(XmlUtils::CXmlLiteReader& oLiteReader); + ~CTextObject(); + + virtual bool Read(XmlUtils::CXmlLiteReader& oLiteReader) override; +}; +} + +#endif // TEXTOBJECT_H diff --git a/OFDFile/src/Document.cpp b/OFDFile/src/Document.cpp index 1345d9ad60..7e39cbb447 100644 --- a/OFDFile/src/Document.cpp +++ b/OFDFile/src/Document.cpp @@ -1,13 +1,9 @@ #include "Document.h" -#include "../../DesktopEditor/common/StringExt.h" #include "../../OOXML/Base/Unit.h" -#include namespace OFD { -#define OFD_EPSILON 0.0001 - CPageArea::CPageArea() {} @@ -139,28 +135,4 @@ bool CDocument::Read(const std::wstring& wsFilePath) return false; } - -TBox::TBox() - : m_dX(0.), m_dY(0.), m_dWidth(0.), m_dHeight(0.) -{} - -bool TBox::Empty() const -{ - return m_dWidth < OFD_EPSILON || m_dHeight < OFD_EPSILON; -} - -bool TBox::Read(const std::wstring& wsValue) -{ - const std::vector arValues{NSStringExt::Split(wsValue, L' ')}; - - if (4 > arValues.size()) - return false; - - m_dX = XmlUtils::GetDouble(arValues[0]); - m_dY = XmlUtils::GetDouble(arValues[1]); - m_dWidth = XmlUtils::GetDouble(arValues[2]); - m_dHeight = XmlUtils::GetDouble(arValues[3]); - - return true; -} } diff --git a/OFDFile/src/Document.h b/OFDFile/src/Document.h index 578267417c..3171275666 100644 --- a/OFDFile/src/Document.h +++ b/OFDFile/src/Document.h @@ -4,21 +4,10 @@ #include "Page.h" #include "PublicRes.h" +#include "Utils/Types.h" + namespace OFD { -struct TBox -{ - double m_dX; - double m_dY; - double m_dWidth; - double m_dHeight; - - TBox(); - - bool Empty() const; - bool Read(const std::wstring& wsValue); -}; - class CPageArea { TBox m_oPhysicalBox; diff --git a/OFDFile/src/Page.cpp b/OFDFile/src/Page.cpp index c69bdf3196..6a66d21875 100644 --- a/OFDFile/src/Page.cpp +++ b/OFDFile/src/Page.cpp @@ -1,5 +1,9 @@ #include "Page.h" +#include +#include "../../DesktopEditor/common/File.h" +#include "../../DesktopEditor/common/Path.h" + namespace OFD { CPage::CPage() @@ -12,6 +16,29 @@ CPage* CPage::Read(const std::wstring& wsFilePath) if (wsFilePath.empty()) return nullptr; - return nullptr; + std::wstring wsNormalizedPath = wsFilePath; + + if (L"xml" != NSFile::GetFileExtention(wsNormalizedPath)) + wsNormalizedPath = NSSystemPath::Combine(wsNormalizedPath, L"Content.xml"); + + + XmlUtils::CXmlLiteReader oLiteReader; + if (!oLiteReader.FromFile(wsNormalizedPath) || !oLiteReader.ReadNextNode() || L"ofd:Page" != oLiteReader.GetName()) + return nullptr; + + const int nDepth = oLiteReader.GetDepth(); + std::wstring wsNodeName; + + CPage *pPage = new CPage(); + + while (oLiteReader.ReadNextSiblingNode(nDepth)) + { + wsNodeName = oLiteReader.GetName(); + + if (L"ofd:Content" == wsNodeName) + pPage->m_oContent.Read(oLiteReader); + } + + return pPage; } } diff --git a/OFDFile/src/Page.h b/OFDFile/src/Page.h index 3340ef0cc8..f605eb9d8b 100644 --- a/OFDFile/src/Page.h +++ b/OFDFile/src/Page.h @@ -1,12 +1,13 @@ #ifndef PAGE_H #define PAGE_H -#include "../../OfficeUtils/src/ZipFolder.h" +#include "Content/Content.h" namespace OFD { class CPage { + CContent m_oContent; public: CPage(); diff --git a/OFDFile/src/Utils/Types.cpp b/OFDFile/src/Utils/Types.cpp new file mode 100644 index 0000000000..52ffb6a125 --- /dev/null +++ b/OFDFile/src/Utils/Types.cpp @@ -0,0 +1,49 @@ +#include "Types.h" + +#include +#include "../../../DesktopEditor/common/StringExt.h" +#include "../../../OOXML/Base/Unit.h" + +namespace OFD +{ +TBox::TBox() + : m_dX(0.), m_dY(0.), m_dWidth(0.), m_dHeight(0.) +{} + +bool TBox::Empty() const +{ + return m_dWidth < OFD_EPSILON || m_dHeight < OFD_EPSILON; +} + +bool TBox::Read(const std::wstring& wsValue) +{ + const std::vector arValues{NSStringExt::Split(wsValue, L' ')}; + + if (4 > arValues.size()) + return false; + + m_dX = XmlUtils::GetDouble(arValues[0]); + m_dY = XmlUtils::GetDouble(arValues[1]); + m_dWidth = XmlUtils::GetDouble(arValues[2]); + m_dHeight = XmlUtils::GetDouble(arValues[3]); + + return true; +} + + + +TColor::TColor() +{ +} + +TColor::TColor(XmlUtils::CXmlLiteReader& oLiteReader) +{ + Read(oLiteReader); +} + +bool TColor::Read(XmlUtils::CXmlLiteReader& oLiteReader) +{ + return false; +} + +} diff --git a/OFDFile/src/Utils/Types.h b/OFDFile/src/Utils/Types.h new file mode 100644 index 0000000000..9b38b1b8c7 --- /dev/null +++ b/OFDFile/src/Utils/Types.h @@ -0,0 +1,34 @@ +#ifndef TYPES_H +#define TYPES_H + +#include +#include "../../../DesktopEditor/xml/include/xmlutils.h" + + +namespace OFD +{ +#define OFD_EPSILON 0.0001 + +struct TBox +{ + double m_dX; + double m_dY; + double m_dWidth; + double m_dHeight; + + TBox(); + + bool Empty() const; + bool Read(const std::wstring& wsValue); +}; + +struct TColor +{ + TColor(); + TColor(XmlUtils::CXmlLiteReader& oLiteReader); + + bool Read(XmlUtils::CXmlLiteReader& oLiteReader); +}; +} + +#endif // TYPES_H diff --git a/OFDFile/src/Utils/Utils.h b/OFDFile/src/Utils/Utils.h new file mode 100644 index 0000000000..1b220e8724 --- /dev/null +++ b/OFDFile/src/Utils/Utils.h @@ -0,0 +1,49 @@ +#ifndef UTILS_H +#define UTILS_H + + +#include +#include +#include "../../../OOXML/Base/Unit.h" +#include "../../../DesktopEditor/common/StringExt.h" + +bool GetBoolean(const std::wstring& wsValue) +{ + return false; +} + +int GetInt(const std::wstring& wsValue) +{ + return 0; +} + +unsigned int GetUInt(const std::wstring& wsValue) +{ + return 0; +} + +double GetDouble(const std::wstring& wsValue) +{ + return 0.; +} + + + +std::vector GetDoubleValues(const std::wstring& wsValue) +{ + const std::vector arValues{NSStringExt::Split(wsValue, L' ')}; + + if(arValues.empty()) + return std::vector(); + + std::vector arDoubleValues(arValues.size()); + + for (unsigned int unIndex = 0; unIndex < arValues.size(); ++unIndex) + arDoubleValues[unIndex] = XmlUtils::GetDouble(arValues[unIndex]); + + return arDoubleValues; +} + +#define NO_VALID_NODE(lite_reader, node_name) node_name != oLiteReader.GetName() || oLiteReader.IsEmptyElement() || !oLiteReader.IsValid() + +#endif // UTILS_H