From a82cf375b7aaaa0691fb02ad660bb0ebcbde5dc6 Mon Sep 17 00:00:00 2001 From: Green Date: Mon, 4 Aug 2025 17:54:26 +0300 Subject: [PATCH] Fixed a color bug in OFD --- OFDFile/OFDFile.pro | 2 + OFDFile/src/Annotation.cpp | 14 +++-- OFDFile/src/Annotation.h | 6 +- OFDFile/src/Content/Content.cpp | 4 +- OFDFile/src/Content/Content.h | 2 +- OFDFile/src/Content/GraphicUnit.cpp | 36 +----------- OFDFile/src/Content/GraphicUnit.h | 29 +--------- OFDFile/src/Content/IPageBlock.h | 9 ++- OFDFile/src/Content/ImageObject.cpp | 2 +- OFDFile/src/Content/ImageObject.h | 2 +- OFDFile/src/Content/Layer.cpp | 4 +- OFDFile/src/Content/Layer.h | 2 +- OFDFile/src/Content/PageBlock.cpp | 4 +- OFDFile/src/Content/PageBlock.h | 2 +- OFDFile/src/Content/PathObject.cpp | 26 ++++++--- OFDFile/src/Content/PathObject.h | 2 +- OFDFile/src/Content/TextObject.cpp | 16 ++++-- OFDFile/src/Content/TextObject.h | 2 +- OFDFile/src/Document.cpp | 4 +- OFDFile/src/Page.cpp | 6 +- OFDFile/src/Page.h | 2 +- OFDFile/src/Res.cpp | 10 ++++ OFDFile/src/Res.h | 4 +- OFDFile/src/Types/Color.cpp | 2 + OFDFile/src/Types/Color.h | 2 +- OFDFile/src/Types/DrawParam.cpp | 61 +++++++++++++++++++- OFDFile/src/Types/DrawParam.h | 10 ++++ OFDFile/src/Types/PenSettings.cpp | 87 +++++++++++++++++++++++++++++ OFDFile/src/Types/PenSettings.h | 39 +++++++++++++ OFDFile/src/Types/TemplatePage.h | 2 +- 30 files changed, 286 insertions(+), 107 deletions(-) create mode 100644 OFDFile/src/Types/PenSettings.cpp create mode 100644 OFDFile/src/Types/PenSettings.h diff --git a/OFDFile/OFDFile.pro b/OFDFile/OFDFile.pro index 68f35e0f20..4be46dd245 100644 --- a/OFDFile/OFDFile.pro +++ b/OFDFile/OFDFile.pro @@ -53,6 +53,7 @@ HEADERS += \ src/Types/Font.h \ src/Types/MultiMedia.h \ src/Types/PageArea.h \ + src/Types/PenSettings.h \ src/Types/Signature.h \ src/Types/TemplatePage.h \ src/Utils/Types.h \ @@ -82,6 +83,7 @@ SOURCES += \ src/Types/Font.cpp \ src/Types/MultiMedia.cpp \ src/Types/PageArea.cpp \ + src/Types/PenSettings.cpp \ src/Types/Signature.cpp \ src/Types/TemplatePage.cpp \ src/Utils/Types.cpp \ diff --git a/OFDFile/src/Annotation.cpp b/OFDFile/src/Annotation.cpp index f3fc3c5156..a8b8a23ed6 100644 --- a/OFDFile/src/Annotation.cpp +++ b/OFDFile/src/Annotation.cpp @@ -1,6 +1,8 @@ #include "Annotation.h" #include "Utils/Utils.h" +#include "../../../Common/File.h" + namespace OFD { CParameter::CParameter(CXmlReader& oLiteReader) @@ -106,13 +108,13 @@ CAnnot::~CAnnot() ClearContainer(m_arAppearances); } -void CAnnot::Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const +void CAnnot::Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const { if (!m_bPrint) return; for (const CAppearance* pAppearance : m_arAppearances) - pAppearance->Draw(pRenderer, oCommonData); + pAppearance->Draw(pRenderer, oCommonData, ePageType); } CPageAnnot::CPageAnnot() @@ -144,10 +146,10 @@ CPageAnnot* CPageAnnot::Read(const std::wstring& wsFilePath, const std::wstring& return pPageAnnot; } -void CPageAnnot::Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const +void CPageAnnot::Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const { for (const CAnnot* pAnnot : m_arAnnots) - pAnnot->Draw(pRenderer, oCommonData); + pAnnot->Draw(pRenderer, oCommonData, ePageType); } CAnnotation::CAnnotation() @@ -195,9 +197,9 @@ bool CAnnotation::Read(const std::wstring& wsFilePath, const std::wstring& wsRoo return nullptr != m_pPageAnnot; } -void CAnnotation::Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const +void CAnnotation::Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const { if (nullptr != m_pPageAnnot) - m_pPageAnnot->Draw(pRenderer, oCommonData); + m_pPageAnnot->Draw(pRenderer, oCommonData, ePageType); } } diff --git a/OFDFile/src/Annotation.h b/OFDFile/src/Annotation.h index a6b37f827a..cc51e8ba96 100644 --- a/OFDFile/src/Annotation.h +++ b/OFDFile/src/Annotation.h @@ -34,7 +34,7 @@ public: CAnnot(CXmlReader& oLiteReader); ~CAnnot(); - void Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const; + void Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const; private: EAnnotType m_eType; bool m_bVisible; @@ -54,7 +54,7 @@ public: static CPageAnnot* Read(const std::wstring& wsFilePath, const std::wstring& wsRootPath); - void Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const; + void Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const; private: std::vector m_arAnnots; @@ -68,7 +68,7 @@ public: bool Read(const std::wstring& wsFilePath, const std::wstring& wsRootPath); - void Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const; + void Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const; private: CPageAnnot *m_pPageAnnot; }; diff --git a/OFDFile/src/Content/Content.cpp b/OFDFile/src/Content/Content.cpp index 6bfb81a733..b7aa2b8615 100644 --- a/OFDFile/src/Content/Content.cpp +++ b/OFDFile/src/Content/Content.cpp @@ -30,12 +30,12 @@ bool CContent::Read(CXmlReader& oLiteReader) return false; } -void CContent::Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const +void CContent::Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const { if (nullptr == pRenderer) return; for (const CLayer* pLayer : m_arLayers) - pLayer->Draw(pRenderer, oCommonData); + pLayer->Draw(pRenderer, oCommonData, ePageType); } } diff --git a/OFDFile/src/Content/Content.h b/OFDFile/src/Content/Content.h index 2e90d8b175..9feb723481 100644 --- a/OFDFile/src/Content/Content.h +++ b/OFDFile/src/Content/Content.h @@ -14,7 +14,7 @@ public: ~CContent(); bool Read(CXmlReader& oLiteReader); - void Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const; + void Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const; }; } diff --git a/OFDFile/src/Content/GraphicUnit.cpp b/OFDFile/src/Content/GraphicUnit.cpp index 8a5c6ee85a..3e00b7d6ea 100644 --- a/OFDFile/src/Content/GraphicUnit.cpp +++ b/OFDFile/src/Content/GraphicUnit.cpp @@ -4,9 +4,7 @@ namespace OFD { CGraphicUnit::CGraphicUnit(CXmlReader& oLiteReader) - : m_bVisible(true), m_unDrawParam(0), m_dLineWidth(0.353), - m_eCap(ECap::Butt), m_eJoin(EJoin::Miter), m_dMiterLimit(4.234), - m_dDashOffset(0.), m_uchAlpha(255) + : m_bVisible(true), m_unDrawParam(0), m_oPenSettings(oLiteReader) { if (0 == oLiteReader.GetAttributesCount() || !oLiteReader.MoveToFirstAttribute()) return; @@ -27,36 +25,6 @@ CGraphicUnit::CGraphicUnit(CXmlReader& oLiteReader) m_oCTM.Read(oLiteReader.GetTextA()); else if (L"DrawParam" == wsAttributeName) m_unDrawParam = oLiteReader.GetUInteger(true); - else if (L"LineWidth" == wsAttributeName) - m_dLineWidth = oLiteReader.GetDouble(true); - 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 = oLiteReader.GetDouble(true); - else if (L"DashOffset" == wsAttributeName) - m_dDashOffset = oLiteReader.GetDouble(true); - else if (L"Alpha" == wsAttributeName) - m_uchAlpha = oLiteReader.GetUInteger(true); } while (oLiteReader.MoveToNextAttribute()); oLiteReader.MoveToElement(); @@ -67,6 +35,8 @@ void CGraphicUnit::Apply(IRenderer* pRenderer, TMatrix& oOldTransform) const if (nullptr == pRenderer) return; + m_oPenSettings.Apply(pRenderer); + pRenderer->GetTransform(&oOldTransform.m_dM11, &oOldTransform.m_dM12, &oOldTransform.m_dM21, &oOldTransform.m_dM22, &oOldTransform.m_dDx, &oOldTransform.m_dDy); Aggplus::CMatrix oTransform(oOldTransform.m_dM11, oOldTransform.m_dM12, oOldTransform.m_dM21, oOldTransform.m_dM22, oOldTransform.m_dDx, oOldTransform.m_dDy); diff --git a/OFDFile/src/Content/GraphicUnit.h b/OFDFile/src/Content/GraphicUnit.h index 8cd10c6e5b..4bd336d5a3 100644 --- a/OFDFile/src/Content/GraphicUnit.h +++ b/OFDFile/src/Content/GraphicUnit.h @@ -1,13 +1,9 @@ #ifndef GRAPHICUNIT_H #define GRAPHICUNIT_H -#include "../Utils/XmlReader.h" +#include "../Types/PenSettings.h" #include "../Utils/Types.h" -#include "../../../DesktopEditor/graphics/IRenderer.h" - -#include - namespace OFD { class CGraphicUnit @@ -17,28 +13,7 @@ class CGraphicUnit bool m_bVisible; TMatrix 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; - - friend class CPathObject; + CPenSettings m_oPenSettings; public: CGraphicUnit(CXmlReader& oLiteReader); diff --git a/OFDFile/src/Content/IPageBlock.h b/OFDFile/src/Content/IPageBlock.h index b89e62d139..f1d50a6def 100644 --- a/OFDFile/src/Content/IPageBlock.h +++ b/OFDFile/src/Content/IPageBlock.h @@ -8,13 +8,20 @@ namespace OFD { +enum class EPageType +{ + Page, + TemplatePage, + Anotation +}; + class IPageBlock : public IOFDElement { public: IPageBlock(CXmlReader& oLiteReader) : IOFDElement(oLiteReader){}; virtual ~IPageBlock(){}; - virtual void Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const = 0; + virtual void Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const = 0; }; } diff --git a/OFDFile/src/Content/ImageObject.cpp b/OFDFile/src/Content/ImageObject.cpp index 4f0d7cfec1..67a344ca66 100644 --- a/OFDFile/src/Content/ImageObject.cpp +++ b/OFDFile/src/Content/ImageObject.cpp @@ -24,7 +24,7 @@ CImageObject::CImageObject(CXmlReader& oLiteReader) oLiteReader.MoveToElement(); } -void CImageObject::Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const +void CImageObject::Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const { if (nullptr == pRenderer || nullptr == oCommonData.GetDocumentRes()) return; diff --git a/OFDFile/src/Content/ImageObject.h b/OFDFile/src/Content/ImageObject.h index 5ea978e188..175dd1ce6c 100644 --- a/OFDFile/src/Content/ImageObject.h +++ b/OFDFile/src/Content/ImageObject.h @@ -12,7 +12,7 @@ class CImageObject : public IPageBlock, public CGraphicUnit public: CImageObject(CXmlReader& oLiteReader); - void Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const override; + void Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const override; }; } diff --git a/OFDFile/src/Content/Layer.cpp b/OFDFile/src/Content/Layer.cpp index 754ca81853..935fe5bb43 100644 --- a/OFDFile/src/Content/Layer.cpp +++ b/OFDFile/src/Content/Layer.cpp @@ -21,12 +21,12 @@ CLayer::~CLayer() delete pPageBlock; } -void CLayer::Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const +void CLayer::Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const { if (nullptr == pRenderer) return; for (const IPageBlock* pPageBlock : m_arPageBlocks) - pPageBlock->Draw(pRenderer, oCommonData); + pPageBlock->Draw(pRenderer, oCommonData, ePageType); } } diff --git a/OFDFile/src/Content/Layer.h b/OFDFile/src/Content/Layer.h index 4b913d2d61..47938a4376 100644 --- a/OFDFile/src/Content/Layer.h +++ b/OFDFile/src/Content/Layer.h @@ -20,7 +20,7 @@ public: CLayer(CXmlReader& oLiteReader); ~CLayer(); - void Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const override; + void Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const override; }; } diff --git a/OFDFile/src/Content/PageBlock.cpp b/OFDFile/src/Content/PageBlock.cpp index 087e5a2e6b..e4bfc973c1 100644 --- a/OFDFile/src/Content/PageBlock.cpp +++ b/OFDFile/src/Content/PageBlock.cpp @@ -54,7 +54,7 @@ void CPageBlock::ReadIntoContainer(CXmlReader& oLiteReader, std::vectorSetTransform(dM11, dM12, dM21, dM22, dDx + m_oBoundary.m_dX, dDy + m_oBoundary.m_dY); for (const IPageBlock* pPageBlock : m_arPageBlocks) - pPageBlock->Draw(pRenderer, oCommonData); + pPageBlock->Draw(pRenderer, oCommonData, ePageType); pRenderer->SetTransform(dM11, dM12, dM21, dM22, dDx, dDy); } diff --git a/OFDFile/src/Content/PageBlock.h b/OFDFile/src/Content/PageBlock.h index 1649adcaa3..899df388d1 100644 --- a/OFDFile/src/Content/PageBlock.h +++ b/OFDFile/src/Content/PageBlock.h @@ -15,7 +15,7 @@ public: static void ReadIntoContainer(CXmlReader& oLiteReader, std::vector& arPageBlocks); - void Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const override; + void Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const override; }; } diff --git a/OFDFile/src/Content/PathObject.cpp b/OFDFile/src/Content/PathObject.cpp index 8d850b1c28..a0b09623f6 100644 --- a/OFDFile/src/Content/PathObject.cpp +++ b/OFDFile/src/Content/PathObject.cpp @@ -1,5 +1,7 @@ #include "PathObject.h" + #include "src/Utils/Utils.h" +#include "../Types/DrawParam.h" namespace OFD { @@ -132,7 +134,7 @@ void CPathObject::AddElement(const IPathElement* pElement) m_arElements.push_back(pElement); } -void CPathObject::Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const +void CPathObject::Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const { if (nullptr == pRenderer || m_arElements.empty()) return; @@ -168,38 +170,46 @@ void CPathObject::Draw(IRenderer* pRenderer, const CCommonData& oCommonData) con } } + const CRes* pPublicRes{oCommonData.GetPublicRes()}; + std::vector arDrawParams{pPublicRes->GetDrawParams()}; + if (m_bFill) { pRenderer->put_BrushType(c_BrushTypeSolid); if (nullptr != m_pFillColor) { - pRenderer->put_BrushColor1(m_pFillColor->ToInt(oCommonData.GetPublicRes())); + pRenderer->put_BrushColor1(m_pFillColor->ToInt(pPublicRes)); pRenderer->put_BrushAlpha1(m_pFillColor->GetAlpha()); } else { pRenderer->put_BrushColor1(0); - pRenderer->put_BrushAlpha1(0xff); + + if (EPageType::TemplatePage == ePageType) + for (const CDrawParam* pDrawParam : arDrawParams) + if (pDrawParam->ApplyFillColor(pRenderer, pPublicRes)) + break; } } else pRenderer->put_BrushType(c_BrushTypeNotSet); - if(m_bStroke) { - pRenderer->put_PenSize(m_dLineWidth); - if (nullptr != m_pStrokeColor) { - pRenderer->put_PenColor(m_pStrokeColor->ToInt(oCommonData.GetPublicRes())); + pRenderer->put_PenColor(m_pStrokeColor->ToInt(pPublicRes)); pRenderer->put_PenAlpha(m_pStrokeColor->GetAlpha()); } else { pRenderer->put_PenColor(0); - pRenderer->put_PenAlpha(0xff); + + if (EPageType::TemplatePage == ePageType) + for (const CDrawParam* pDrawParam : arDrawParams) + if (pDrawParam->ApplyStrokeColor(pRenderer, pPublicRes)) + break; } } else diff --git a/OFDFile/src/Content/PathObject.h b/OFDFile/src/Content/PathObject.h index 4a11d9fea7..a1f0d9db72 100644 --- a/OFDFile/src/Content/PathObject.h +++ b/OFDFile/src/Content/PathObject.h @@ -117,7 +117,7 @@ public: CPathObject(CXmlReader& oLiteReader); ~CPathObject(); - void Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const override; + void Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const override; }; } diff --git a/OFDFile/src/Content/TextObject.cpp b/OFDFile/src/Content/TextObject.cpp index 4cdfc4a452..7398582c6b 100644 --- a/OFDFile/src/Content/TextObject.cpp +++ b/OFDFile/src/Content/TextObject.cpp @@ -178,12 +178,14 @@ CTextObject::~CTextObject() delete pTextCode; } -void CTextObject::Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const +void CTextObject::Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const { if (nullptr == pRenderer || m_arTextCodes.empty()) return; - const CFont* pFont = oCommonData.GetPublicRes()->GetFont(m_unFontID); + const CRes* pPublicRes{oCommonData.GetPublicRes()}; + + const CFont* pFont = pPublicRes->GetFont(m_unFontID); if (nullptr == pFont) return; @@ -193,19 +195,25 @@ void CTextObject::Draw(IRenderer* pRenderer, const CCommonData& oCommonData) con TMatrix oOldTransform; CGraphicUnit::Apply(pRenderer, oOldTransform); + std::vector arDrawParams{pPublicRes->GetDrawParams()}; + if (m_bFill) { pRenderer->put_BrushType(c_BrushTypeSolid); if (nullptr != m_pFillColor) { - pRenderer->put_BrushColor1(m_pFillColor->ToInt(oCommonData.GetPublicRes())); + pRenderer->put_BrushColor1(m_pFillColor->ToInt(pPublicRes)); pRenderer->put_BrushAlpha1(m_pFillColor->GetAlpha()); } else { pRenderer->put_BrushColor1(0); - pRenderer->put_BrushAlpha1(0xff); + + if (EPageType::TemplatePage == ePageType) + for (const CDrawParam* pDrawParam : arDrawParams) + if (pDrawParam->ApplyFillColor(pRenderer, pPublicRes)) + break; } } else diff --git a/OFDFile/src/Content/TextObject.h b/OFDFile/src/Content/TextObject.h index 1b01d57d42..4e5103b3f7 100644 --- a/OFDFile/src/Content/TextObject.h +++ b/OFDFile/src/Content/TextObject.h @@ -58,7 +58,7 @@ public: CTextObject(CXmlReader& oLiteReader); ~CTextObject(); - void Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const override; + void Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const override; }; } diff --git a/OFDFile/src/Document.cpp b/OFDFile/src/Document.cpp index 4b2c8d1aa4..5073cfa7bb 100644 --- a/OFDFile/src/Document.cpp +++ b/OFDFile/src/Document.cpp @@ -118,9 +118,9 @@ bool CDocument::DrawPage(IRenderer* pRenderer, int nPageIndex) const if (itFound == m_mPages.cend()) return false; - itFound->second->Draw(pRenderer, m_oCommonData); + itFound->second->Draw(pRenderer, m_oCommonData, EPageType::Page); - m_oAnnotation.Draw(pRenderer, m_oCommonData); + m_oAnnotation.Draw(pRenderer, m_oCommonData, EPageType::Anotation); return true; } diff --git a/OFDFile/src/Page.cpp b/OFDFile/src/Page.cpp index 34a47a28c4..4a793c13cd 100644 --- a/OFDFile/src/Page.cpp +++ b/OFDFile/src/Page.cpp @@ -61,7 +61,7 @@ CPage* CPage::Read(const std::wstring& wsFilePath, const std::wstring& wsRootPat return pPage; } -void CPage::Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const +void CPage::Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const { if (nullptr == pRenderer) return; @@ -73,10 +73,10 @@ void CPage::Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const const CTemplatePage *pTemplatePage = oCommonData.GetTemplatePage(m_parTemplatePage.first, m_parTemplatePage.second); if (nullptr != pTemplatePage && EZOrder::Background == pTemplatePage->GetZOrder() && nullptr != pTemplatePage->GetPage()) - pTemplatePage->GetPage()->Draw(pRenderer, oCommonData); + pTemplatePage->GetPage()->Draw(pRenderer, oCommonData, EPageType::TemplatePage); } - m_oContent.Draw(pRenderer, oCommonData); + m_oContent.Draw(pRenderer, oCommonData, ePageType); pRenderer->EndCommand(c_nImageType); } diff --git a/OFDFile/src/Page.h b/OFDFile/src/Page.h index 09d16e5130..8d3c038d32 100644 --- a/OFDFile/src/Page.h +++ b/OFDFile/src/Page.h @@ -18,7 +18,7 @@ public: ~CPage(); static CPage* Read(const std::wstring& wsFilePath, const std::wstring& wsRootPath); - void Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const; + void Draw(IRenderer* pRenderer, const CCommonData& oCommonData, EPageType ePageType) const; void GetPageSize(double& dWidth, double& dHeight) const; }; diff --git a/OFDFile/src/Res.cpp b/OFDFile/src/Res.cpp index 1297428353..70afaf4e8e 100644 --- a/OFDFile/src/Res.cpp +++ b/OFDFile/src/Res.cpp @@ -135,4 +135,14 @@ const CCompositeGraphicUnit* CRes::GetCompositeGraphicUnit(unsigned int unId) co { RETURN_ELEMENT_FROM_MAP(CCompositeGraphicUnit, m_mCCompositeGraphicUnits); } + +std::vector CRes::GetDrawParams() const +{ + std::vector arValues; + + for (std::map::const_iterator itBegin = m_mDrawParams.cbegin(); itBegin != m_mDrawParams.cend(); ++itBegin) + arValues.push_back(itBegin->second); + + return arValues; +} } diff --git a/OFDFile/src/Res.h b/OFDFile/src/Res.h index c3ef7bdabd..f16eaafef3 100644 --- a/OFDFile/src/Res.h +++ b/OFDFile/src/Res.h @@ -9,8 +9,6 @@ #include "Types/MultiMedia.h" #include "Types/CompositeGraphicUnit.h" -#include "../../OfficeUtils/src/ZipFolder.h" - namespace OFD { class CRes @@ -31,6 +29,8 @@ public: const CFont* GetFont(unsigned int unId) const; const CMultiMedia* GetMultiMedia(unsigned int unId) const; const CCompositeGraphicUnit* GetCompositeGraphicUnit(unsigned int unId) const; + + std::vector GetDrawParams() const; }; } diff --git a/OFDFile/src/Types/Color.cpp b/OFDFile/src/Types/Color.cpp index 4eaf1c7f9a..473da10e62 100644 --- a/OFDFile/src/Types/Color.cpp +++ b/OFDFile/src/Types/Color.cpp @@ -1,5 +1,7 @@ #include "Color.h" +#include "../Res.h" + namespace OFD { CColor::CColor(CXmlReader& oXmlReader) diff --git a/OFDFile/src/Types/Color.h b/OFDFile/src/Types/Color.h index 23688225e7..12f0b28e78 100644 --- a/OFDFile/src/Types/Color.h +++ b/OFDFile/src/Types/Color.h @@ -2,10 +2,10 @@ #define COLOR_H #include "../Utils/XmlReader.h" -#include "../Res.h" namespace OFD { +class CRes; class CColor { BYTE m_oValues[4]; diff --git a/OFDFile/src/Types/DrawParam.cpp b/OFDFile/src/Types/DrawParam.cpp index c1738b429c..fdb387c199 100644 --- a/OFDFile/src/Types/DrawParam.cpp +++ b/OFDFile/src/Types/DrawParam.cpp @@ -3,6 +3,63 @@ namespace OFD { CDrawParam::CDrawParam(CXmlReader& oXmlReader) - : IOFDElement(oXmlReader) -{} + : IOFDElement(oXmlReader), m_oPenSettings(oXmlReader), + m_pStrokeColor(nullptr), m_pFillColor(nullptr) +{ + std::string sName; + const int nDepth = oXmlReader.GetDepth(); + + while (oXmlReader.ReadNextSiblingNode(nDepth)) + { + sName = oXmlReader.GetNameA(); + + if ("ofd:FillColor" == sName) + { + if (nullptr != m_pFillColor) + delete m_pFillColor; + + m_pFillColor = new CColor(oXmlReader); + } + else if ("ofd:StrokeColor" == sName) + { + if (nullptr != m_pStrokeColor) + delete m_pStrokeColor; + + m_pStrokeColor = new CColor(oXmlReader); + } + } +} + +CDrawParam::~CDrawParam() +{ + if (nullptr != m_pStrokeColor) + delete m_pStrokeColor; + + if (nullptr != m_pFillColor) + delete m_pFillColor; +} + +bool CDrawParam::ApplyStrokeColor(IRenderer* pRenderer, const CRes* pPublicRes) const +{ + if (nullptr == pRenderer || nullptr == m_pStrokeColor) + return false; + + m_oPenSettings.Apply(pRenderer); + + pRenderer->put_PenColor(m_pStrokeColor->ToInt(pPublicRes)); + pRenderer->put_PenAlpha(m_pStrokeColor->GetAlpha()); + + return true; +} + +bool CDrawParam::ApplyFillColor(IRenderer* pRenderer, const CRes* pPublicRes) const +{ + if (nullptr == pRenderer || nullptr == m_pFillColor) + return false; + + pRenderer->put_BrushColor1(m_pFillColor->ToInt(pPublicRes)); + pRenderer->put_BrushAlpha1(m_pFillColor->GetAlpha()); + + return true; +} } diff --git a/OFDFile/src/Types/DrawParam.h b/OFDFile/src/Types/DrawParam.h index 90d8080ca1..1ef0ee9d10 100644 --- a/OFDFile/src/Types/DrawParam.h +++ b/OFDFile/src/Types/DrawParam.h @@ -2,13 +2,23 @@ #define DRAWPARAM_H #include "../IOFDElement.h" +#include "PenSettings.h" +#include "Color.h" namespace OFD { class CDrawParam : public IOFDElement { + CPenSettings m_oPenSettings; + + CColor *m_pStrokeColor; + CColor *m_pFillColor; public: CDrawParam(CXmlReader& oXmlReader); + ~CDrawParam(); + + bool ApplyStrokeColor(IRenderer* pRenderer, const CRes* pPublicRes) const; + bool ApplyFillColor(IRenderer* pRenderer, const CRes* pPublicRes) const; }; } #endif // DRAWPARAM_H diff --git a/OFDFile/src/Types/PenSettings.cpp b/OFDFile/src/Types/PenSettings.cpp new file mode 100644 index 0000000000..d869766bff --- /dev/null +++ b/OFDFile/src/Types/PenSettings.cpp @@ -0,0 +1,87 @@ +#include "PenSettings.h" + +namespace OFD +{ +CPenSettings::CPenSettings(CXmlReader& oLiteReader) + : m_dLineWidth(0.353), m_eCap(ECap::Butt), + m_eJoin(EJoin::Miter), m_dMiterLimit(4.234), m_dDashOffset(0.) +{ + if (0 == oLiteReader.GetAttributesCount() || !oLiteReader.MoveToFirstAttribute()) + return; + + std::wstring wsAttributeName; + + do + { + wsAttributeName = oLiteReader.GetName(); + + if (L"LineWidth" == wsAttributeName) + m_dLineWidth = oLiteReader.GetDouble(true); + 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 = oLiteReader.GetDouble(true); + else if (L"DashOffset" == wsAttributeName) + m_dDashOffset = oLiteReader.GetDouble(true); + else if (L"Alpha" == wsAttributeName) + m_uchAlpha = oLiteReader.GetUInteger(true); + } while (oLiteReader.MoveToNextAttribute()); + + oLiteReader.MoveToElement(); +} + +void CPenSettings::Apply(IRenderer* pRenderer) const +{ + pRenderer->put_PenSize(m_dLineWidth); + pRenderer->put_PenAlpha(m_uchAlpha); + pRenderer->put_BrushAlpha1(m_uchAlpha); + + BYTE nCapStyle = 0; + switch (m_eCap) + { + case ECap::Butt: nCapStyle = Aggplus::LineCapFlat; break; + case ECap::Round: nCapStyle = Aggplus::LineCapRound; break; + case ECap::Square: nCapStyle = Aggplus::LineCapSquare; break; + } + + pRenderer->put_PenLineStartCap(nCapStyle); + pRenderer->put_PenLineEndCap(nCapStyle); + + BYTE nJoinStyle = 0; + switch (m_eJoin) + { + case EJoin::Miter: nJoinStyle = Aggplus::LineJoinMiter; break; + case EJoin::Round: nJoinStyle = Aggplus::LineJoinRound; break; + case EJoin::Bevel: nJoinStyle = Aggplus::LineJoinBevel; break; + } + + pRenderer->put_PenLineJoin(nJoinStyle); + + if (!m_arDashPattern.empty()) + { + pRenderer->put_PenDashStyle(Aggplus::DashStyleCustom); + pRenderer->put_PenDashOffset(m_dDashOffset); + pRenderer->PenDashPattern((double*)m_arDashPattern.data(), m_arDashPattern.size()); + } +} +} diff --git a/OFDFile/src/Types/PenSettings.h b/OFDFile/src/Types/PenSettings.h new file mode 100644 index 0000000000..9df7f20d96 --- /dev/null +++ b/OFDFile/src/Types/PenSettings.h @@ -0,0 +1,39 @@ +#ifndef PENSETTINGS_H +#define PENSETTINGS_H + +#include "../Utils/XmlReader.h" + +#include "../../../DesktopEditor/graphics/IRenderer.h" + +namespace OFD +{ +class CPenSettings +{ + 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: + CPenSettings(CXmlReader& oLiteReader); + + void Apply(IRenderer* pRenderer) const; +}; +} + +#endif // PENSETTINGS_H diff --git a/OFDFile/src/Types/TemplatePage.h b/OFDFile/src/Types/TemplatePage.h index 6b3d679614..fdf8042522 100644 --- a/OFDFile/src/Types/TemplatePage.h +++ b/OFDFile/src/Types/TemplatePage.h @@ -9,7 +9,7 @@ enum class EZOrder { Body, Background -} ; +}; EZOrder GetZOrderFromString(const std::string& sValue);