diff --git a/DesktopEditor/graphics/Graphics.cpp b/DesktopEditor/graphics/Graphics.cpp index 4181772302..8cd6235f75 100644 --- a/DesktopEditor/graphics/Graphics.cpp +++ b/DesktopEditor/graphics/Graphics.cpp @@ -151,6 +151,8 @@ namespace Aggplus RELEASEOBJECT(m_pGraphics); RELEASEOBJECT(m_pBitmap); #endif + + RELEASEINTERFACE(m_pAlphaMask); } INT CGraphics::IsDib() @@ -1201,33 +1203,40 @@ namespace Aggplus return TRUE; } - Status CGraphics::SetAlphaMask(const CAlphaMask &oAlphaMask) + Status CGraphics::SetAlphaMask(CAlphaMask* pAlphaMask) { - m_oAlphaMask = oAlphaMask; - m_oAlphaMask.m_internal->StartApplying(); + RELEASEINTERFACE(m_pAlphaMask); + m_pAlphaMask = pAlphaMask; + if (m_pAlphaMask) + { + m_pAlphaMask->AddRef(); + m_pAlphaMask->m_internal->StartApplying(); + } return Ok; } Status CGraphics::CreateAlphaMask() { - return m_oAlphaMask.CrateImageBuffer(m_frame_buffer.width(), m_frame_buffer.height()); + RELEASEINTERFACE(m_pAlphaMask); + m_pAlphaMask = new CAlphaMask(); + return m_pAlphaMask->CreateImageBuffer(m_frame_buffer.width(), m_frame_buffer.height()); } Status CGraphics::ResetAlphaMask() { - m_oAlphaMask.Clear(); + RELEASEINTERFACE(m_pAlphaMask); return Ok; } Status CGraphics::StartApplyingAlphaMask() { - m_oAlphaMask.m_internal->StartApplying(); + m_pAlphaMask->m_internal->StartApplying(); return Ok; } void CGraphics::CalculateFullTransform() { - m_oFullTransform = m_oCoordTransform; + m_oFullTransform = m_oCoordTransform; m_oFullTransform.Multiply(&m_oBaseTransform, MatrixOrderAppend); m_oFullTransform.Multiply(&m_oTransform, MatrixOrderPrepend); } @@ -1236,18 +1245,18 @@ namespace Aggplus return m_oClip.IsClip(); } - agg::rendering_buffer &CGraphics::GetRenderingBuffer() + agg::rendering_buffer& CGraphics::GetRenderingBuffer() { - if (GenerationAlphaMask == m_oAlphaMask.m_internal->GetStatus()) - return m_oAlphaMask.m_internal->GetRenderingBuffer(); + if (m_pAlphaMask && GenerationAlphaMask == m_pAlphaMask->m_internal->GetStatus()) + return m_pAlphaMask->m_internal->GetRenderingBuffer(); return m_frame_buffer.ren_buf(); } - base_renderer_type &CGraphics::GetRendererBase() + base_renderer_type& CGraphics::GetRendererBase() { - if (GenerationAlphaMask == m_oAlphaMask.m_internal->GetStatus() && ImageBuffer == m_oAlphaMask.m_internal->GetDataType()) - return m_oAlphaMask.m_internal->GetRendererBaseImage(); + if (GenerationAlphaMask == m_pAlphaMask->GetStatus() && ImageBuffer == m_pAlphaMask->GetDataType()) + return m_pAlphaMask->m_internal->GetRendererBaseImage(); return m_frame_buffer.ren_base(); } @@ -1257,12 +1266,12 @@ namespace Aggplus { if (!m_oClip.IsClip()) { - if (ApplyingAlphaMask == m_oAlphaMask.m_internal->GetStatus()) + if (m_pAlphaMask && ApplyingAlphaMask == m_pAlphaMask->GetStatus()) { - if (ImageBuffer == m_oAlphaMask.m_internal->GetDataType()) - return agg::render_scanlines(m_rasterizer.get_rasterizer(), m_oAlphaMask.m_internal->GetScanlineImage(), ren); - else if (AlphaBuffer == m_oAlphaMask.m_internal->GetDataType()) - return agg::render_scanlines(m_rasterizer.get_rasterizer(), m_oAlphaMask.m_internal->GetScanlineABuffer(), ren); + if (ImageBuffer == m_pAlphaMask->GetDataType()) + return agg::render_scanlines(m_rasterizer.get_rasterizer(), m_pAlphaMask->m_internal->GetScanlineImage(), ren); + else if (AlphaBuffer == m_pAlphaMask->GetDataType()) + return agg::render_scanlines(m_rasterizer.get_rasterizer(), m_pAlphaMask->m_internal->GetScanlineABuffer(), ren); } return agg::render_scanlines(m_rasterizer.get_rasterizer(), m_rasterizer.get_scanline(), ren); @@ -1317,12 +1326,12 @@ namespace Aggplus { if (!m_oClip.IsClip()) { - if (ApplyingAlphaMask == m_oAlphaMask.m_internal->GetStatus()) + if (m_pAlphaMask && ApplyingAlphaMask == m_pAlphaMask->GetStatus()) { - if (ImageBuffer == m_oAlphaMask.m_internal->GetDataType()) - return agg::render_scanlines(ras, m_oAlphaMask.m_internal->GetScanlineImage(), ren); - else if (AlphaBuffer == m_oAlphaMask.m_internal->GetDataType()) - return agg::render_scanlines(ras, m_oAlphaMask.m_internal->GetScanlineABuffer(), ren); + if (ImageBuffer == m_pAlphaMask->GetDataType()) + return agg::render_scanlines(ras, m_pAlphaMask->m_internal->GetScanlineImage(), ren); + else if (AlphaBuffer == m_pAlphaMask->GetDataType()) + return agg::render_scanlines(ras, m_pAlphaMask->m_internal->GetScanlineABuffer(), ren); } return agg::render_scanlines(ras, m_rasterizer.get_scanline(), ren); diff --git a/DesktopEditor/graphics/Graphics.h b/DesktopEditor/graphics/Graphics.h index 7a02c923f6..a9b54687e3 100644 --- a/DesktopEditor/graphics/Graphics.h +++ b/DesktopEditor/graphics/Graphics.h @@ -279,7 +279,7 @@ protected: CClipMulti m_oClip; - CAlphaMask m_oAlphaMask; + CAlphaMask* m_pAlphaMask; agg::svg::frame_buffer_rgba m_frame_buffer; agg::svg::rasterizer m_rasterizer; @@ -396,7 +396,7 @@ public: INT DrawStringPathC(const LONG& lText, CFontManager* pFont, CBrush* pBrush, double x, double y); //Работа с альфа-маской - Status SetAlphaMask(const CAlphaMask& oAlphaMask); + Status SetAlphaMask(CAlphaMask* pAlphaMask); Status CreateAlphaMask(); Status ResetAlphaMask(); Status StartApplyingAlphaMask(); diff --git a/DesktopEditor/graphics/GraphicsRenderer.cpp b/DesktopEditor/graphics/GraphicsRenderer.cpp index 58ef21d948..67c2bfaac1 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.cpp +++ b/DesktopEditor/graphics/GraphicsRenderer.cpp @@ -556,9 +556,9 @@ HRESULT CGraphicsRenderer::put_BrushTexturePath(const std::wstring& bsPath) m_oBrush.TexturePath = bsPath; return S_OK; } -HRESULT CGraphicsRenderer::get_BrushTextureImage(Aggplus::CImage *pImage) +HRESULT CGraphicsRenderer::get_BrushTextureImage(Aggplus::CImage** pImage) { - pImage = m_oBrush.Image; + *pImage = m_oBrush.Image; return S_OK; } HRESULT CGraphicsRenderer::put_BrushTextureImage(Aggplus::CImage *pImage) @@ -1406,9 +1406,9 @@ void CGraphicsRenderer::CreateFlip(BYTE* pPixels, const Aggplus::CDoubleRect& oR m_pRenderer->SetPageUnit(Aggplus::UnitMillimeter); } -void CGraphicsRenderer::SetAlphaMask(const Aggplus::CAlphaMask &oAlphaMask) +void CGraphicsRenderer::SetAlphaMask(Aggplus::CAlphaMask* pAlphaMask) { - m_pRenderer->SetAlphaMask(oAlphaMask); + m_pRenderer->SetAlphaMask(pAlphaMask); } void CGraphicsRenderer::put_GlobalAlphaEnabled(const bool& bEnabled, const double& dVal) diff --git a/DesktopEditor/graphics/GraphicsRenderer.h b/DesktopEditor/graphics/GraphicsRenderer.h index 0b358071ff..5f816fc9d0 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.h +++ b/DesktopEditor/graphics/GraphicsRenderer.h @@ -179,7 +179,7 @@ public: virtual HRESULT put_BrushAlpha2(const LONG& lAlpha); virtual HRESULT get_BrushTexturePath(std::wstring* bsPath); virtual HRESULT put_BrushTexturePath(const std::wstring& bsPath); - virtual HRESULT get_BrushTextureImage(Aggplus::CImage* pImage); + virtual HRESULT get_BrushTextureImage(Aggplus::CImage** pImage); virtual HRESULT put_BrushTextureImage(Aggplus::CImage* pImage); virtual HRESULT get_BrushTextureMode(LONG* lMode); virtual HRESULT put_BrushTextureMode(const LONG& lMode); @@ -352,7 +352,7 @@ public: inline double GetPixH() { return m_pRenderer->GetPixH(); } // alpha mask methods - void SetAlphaMask(const Aggplus::CAlphaMask& oAlphaMask); + void SetAlphaMask(Aggplus::CAlphaMask* pAlphaMask); // smart methods void drawHorLine(BYTE align, double y, double x, double r, double penW) diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index 801aa84e6a..2776e48c05 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -199,7 +199,7 @@ public: virtual HRESULT put_BrushAlpha2(const LONG& lAlpha) = 0; virtual HRESULT get_BrushTexturePath(std::wstring* bsPath) = 0; virtual HRESULT put_BrushTexturePath(const std::wstring& bsPath) = 0; - virtual HRESULT get_BrushTextureImage(Aggplus::CImage* pImage) = 0; + virtual HRESULT get_BrushTextureImage(Aggplus::CImage** pImage) = 0; virtual HRESULT put_BrushTextureImage(Aggplus::CImage* pImage) = 0; virtual HRESULT get_BrushTextureMode(LONG* lMode) = 0; virtual HRESULT put_BrushTextureMode(const LONG& lMode) = 0; diff --git a/DesktopEditor/graphics/pro/Graphics.h b/DesktopEditor/graphics/pro/Graphics.h index 93df2e2964..17b5ca1f40 100644 --- a/DesktopEditor/graphics/pro/Graphics.h +++ b/DesktopEditor/graphics/pro/Graphics.h @@ -46,95 +46,95 @@ namespace Aggplus { - class CDIB : public IGrObject - { - public: - BYTE* m_pBits; - LONG m_lWidth; - LONG m_lHeight; + class CDIB : public IGrObject + { + public: + BYTE* m_pBits; + LONG m_lWidth; + LONG m_lHeight; - public: - CDIB() : IGrObject() - { - m_pBits = NULL; - m_lWidth = 0; - m_lHeight = 0; - } - virtual ~CDIB() - { - // delete all in system wrapper - } + public: + CDIB() : IGrObject() + { + m_pBits = NULL; + m_lWidth = 0; + m_lHeight = 0; + } + virtual ~CDIB() + { + // delete all in system wrapper + } - virtual INT Create(LONG lWidth, LONG lHeight, double dDPIX, double dDPIY) = 0; - }; + virtual INT Create(LONG lWidth, LONG lHeight, double dDPIX, double dDPIY) = 0; + }; } namespace NSGraphics { - class GRAPHICS_DECL IGraphicsRenderer : public IRenderer - { - public: - IGraphicsRenderer() {} - virtual ~IGraphicsRenderer() {} + class GRAPHICS_DECL IGraphicsRenderer : public IRenderer + { + public: + IGraphicsRenderer() {} + virtual ~IGraphicsRenderer() {} - public: - virtual void SetImageCache(NSImages::IImageFilesCache* pCache) = 0; - virtual void SetFontManager(NSFonts::IFontManager* pManager = NULL) = 0; - virtual void CheckFontManager() = 0; + public: + virtual void SetImageCache(NSImages::IImageFilesCache* pCache) = 0; + virtual void SetFontManager(NSFonts::IFontManager* pManager = NULL) = 0; + virtual void CheckFontManager() = 0; - virtual NSFonts::IFontManager* GetFontManager() = 0; + virtual NSFonts::IFontManager* GetFontManager() = 0; - virtual void CloseFont() = 0; - virtual void ClearInstallFont() = 0; - - virtual void SetSwapRGB(bool bValue) = 0; - virtual void SetTileImageDpi(const double& dDpi) = 0; + virtual void CloseFont() = 0; + virtual void ClearInstallFont() = 0; - public: - virtual void CreateFromBgraFrame(CBgraFrame* pFrame) = 0; - virtual void SetCoordTransformOffset(double dOffsetX, double dOffsetY) = 0; + virtual void SetSwapRGB(bool bValue) = 0; + virtual void SetTileImageDpi(const double& dDpi) = 0; + + public: + virtual void CreateFromBgraFrame(CBgraFrame* pFrame) = 0; + virtual void SetCoordTransformOffset(double dOffsetX, double dOffsetY) = 0; - virtual void SavePen(NSStructures::CPen& oPen) = 0; - virtual void RestorePen(const NSStructures::CPen& oPen) = 0; + virtual void SavePen(NSStructures::CPen& oPen) = 0; + virtual void RestorePen(const NSStructures::CPen& oPen) = 0; - virtual void SaveBrush(NSStructures::CBrush& oBrush) = 0; - virtual void RestoreBrush(const NSStructures::CBrush& oBrush) = 0; - virtual void put_GlobalAlphaEnabled(const bool& bEnabled, const double& dVal) = 0; - virtual void put_IntegerGrid(const bool& bEnabled) = 0; - virtual bool get_IntegerGrid() = 0; - virtual void AddRect(const double& x, const double& y, const double& w, const double& h) = 0; - virtual void SetFontAttack() = 0; + virtual void SaveBrush(NSStructures::CBrush& oBrush) = 0; + virtual void RestoreBrush(const NSStructures::CBrush& oBrush) = 0; + virtual void put_GlobalAlphaEnabled(const bool& bEnabled, const double& dVal) = 0; + virtual void put_IntegerGrid(const bool& bEnabled) = 0; + virtual bool get_IntegerGrid() = 0; + virtual void AddRect(const double& x, const double& y, const double& w, const double& h) = 0; + virtual void SetFontAttack() = 0; - virtual void Create(BYTE* pPixels, const Aggplus::CDoubleRect& oRect, LONG lWidthControl, LONG lHeightControl, Aggplus::CDIB* pDib = NULL) = 0; - virtual void CreateFlip(BYTE* pPixels, const Aggplus::CDoubleRect& oRect, LONG lWidthControl, LONG lHeightControl, Aggplus::CDIB* pDib = NULL) = 0; + virtual void Create(BYTE* pPixels, const Aggplus::CDoubleRect& oRect, LONG lWidthControl, LONG lHeightControl, Aggplus::CDIB* pDib = NULL) = 0; + virtual void CreateFlip(BYTE* pPixels, const Aggplus::CDoubleRect& oRect, LONG lWidthControl, LONG lHeightControl, Aggplus::CDIB* pDib = NULL) = 0; - virtual Aggplus::CMatrix* GetFullTransform() = 0; - virtual Aggplus::CMatrix* GetTransformMatrix() = 0; - virtual void CalculateFullTransform() = 0; - virtual void PathCommandRect(double x, double y, double w, double h) = 0; - virtual Aggplus::CMatrix* GetCoordTransform() = 0; - virtual void Fill() = 0; - virtual void Stroke() = 0; - virtual double GetPixW() = 0; - virtual double GetPixH() = 0; + virtual Aggplus::CMatrix* GetFullTransform() = 0; + virtual Aggplus::CMatrix* GetTransformMatrix() = 0; + virtual void CalculateFullTransform() = 0; + virtual void PathCommandRect(double x, double y, double w, double h) = 0; + virtual Aggplus::CMatrix* GetCoordTransform() = 0; + virtual void Fill() = 0; + virtual void Stroke() = 0; + virtual double GetPixW() = 0; + virtual double GetPixH() = 0; //alpha mask methods - virtual void SetAlphaMask(const Aggplus::CAlphaMask& oAlphaMask) = 0; + virtual void SetAlphaMask(Aggplus::CAlphaMask* pAlphaMask) = 0; - // smart methods - virtual void drawHorLine(BYTE align, double y, double x, double r, double penW) = 0; - virtual void drawHorLine2(BYTE align, double y, double x, double r, double penW) = 0; + // smart methods + virtual void drawHorLine(BYTE align, double y, double x, double r, double penW) = 0; + virtual void drawHorLine2(BYTE align, double y, double x, double r, double penW) = 0; - virtual void drawVerLine(BYTE align, double x, double y, double b, double penW) = 0; - virtual void drawHorLineExt(BYTE align, double y, double x, double r, double penW, double leftMW, double rightMW) = 0; + virtual void drawVerLine(BYTE align, double x, double y, double b, double penW) = 0; + virtual void drawHorLineExt(BYTE align, double y, double x, double r, double penW, double leftMW, double rightMW) = 0; - // test + // test - virtual void put_BrushGradInfo(const NSStructures::GradientInfo &_ginfo) = 0; - virtual void put_BlendMode(const unsigned int nBlendMode) = 0; - }; + virtual void put_BrushGradInfo(const NSStructures::GradientInfo &_ginfo) = 0; + virtual void put_BlendMode(const unsigned int nBlendMode) = 0; + }; - GRAPHICS_DECL IGraphicsRenderer* Create(); + GRAPHICS_DECL IGraphicsRenderer* Create(); GRAPHICS_DECL std::string GetHatchBase64(const std::wstring& name, unsigned char r1, unsigned char g1, unsigned char b1, unsigned char a1, diff --git a/DesktopEditor/graphics/pro/graphics.pro b/DesktopEditor/graphics/pro/graphics.pro index 86f18cdc1a..475253ae53 100644 --- a/DesktopEditor/graphics/pro/graphics.pro +++ b/DesktopEditor/graphics/pro/graphics.pro @@ -8,12 +8,12 @@ CONFIG += graphics_dynamic_library DEFINES += _QT graphics_dynamic_library { CONFIG += shared - CONFIG += plugin + CONFIG += plugin DEFINES += GRAPHICS_USE_DYNAMIC_LIBRARY_BUILDING } else { DEFINES += GRAPHICS_NO_USE_DYNAMIC_LIBRARY - CONFIG += static + CONFIG += static } CORE_ROOT_DIR = $$PWD/../../.. @@ -36,6 +36,7 @@ INCLUDEPATH += \ # matrix HEADERS += \ + $$GRAPHICS_AGG_PATH/include/test_grads/custom_gradients.h \ ./../Matrix_private.h \ ./../Matrix.h @@ -60,7 +61,7 @@ HEADERS += \ SOURCES += \ ./../AlphaMask_private.cpp \ - ./../AlphaMask.cpp + ./../AlphaMask.cpp SOURCES += \ $$GRAPHICS_AGG_PATH/src/agg_arc.cpp \ @@ -110,11 +111,12 @@ HEADERS += \ ./../MetafileToGraphicsRenderer.h \ ./../FormField.h \ ./../structures.h \ + ./../shading_info.h \ ./../Graphics.h \ ./../GraphicsRenderer.h \ \ ./Graphics.h \ - ./Image.h \ + ./Image.h SOURCES += \ ./../ArrowHead.cpp \ diff --git a/DesktopEditor/graphics/pro/metafile.pri b/DesktopEditor/graphics/pro/metafile.pri index f4a5e13b07..8a9a688c28 100644 --- a/DesktopEditor/graphics/pro/metafile.pri +++ b/DesktopEditor/graphics/pro/metafile.pri @@ -67,57 +67,72 @@ METAFILE_PATH = $$PWD/../../raster/Metafile !metafile_disable_svg { DEFINES += METAFILE_SUPPORT_SVG - HEADERS += \ - $$METAFILE_PATH/svg/SVGFramework.h \ - $$METAFILE_PATH/svg/SVGTransformer.h \ - $$METAFILE_PATH/svg/SvgTypes.h \ - $$METAFILE_PATH/svg/CSvgFile.h \ - $$METAFILE_PATH/svg/CSvgParser.h \ - $$METAFILE_PATH/svg/SvgObjects/CContainer.h \ - $$METAFILE_PATH/svg/SvgObjects/CGradient.h \ - $$METAFILE_PATH/svg/SvgObjects/CClipPath.h \ - $$METAFILE_PATH/svg/SvgObjects/CMask.h \ - $$METAFILE_PATH/svg/SvgObjects/CPattern.h \ - $$METAFILE_PATH/svg/SvgObjects/CSymbol.h \ - $$METAFILE_PATH/svg/SvgObjects/CMarker.h \ - $$METAFILE_PATH/svg/SvgObjects/CImage.h \ - $$METAFILE_PATH/svg/SvgObjects/CLine.h \ - $$METAFILE_PATH/svg/SvgObjects/CRect.h \ - $$METAFILE_PATH/svg/SvgObjects/CCircle.h \ - $$METAFILE_PATH/svg/SvgObjects/CEllipse.h \ - $$METAFILE_PATH/svg/SvgObjects/CPath.h \ - $$METAFILE_PATH/svg/SvgObjects/CText.h \ - $$METAFILE_PATH/svg/SvgObjects/CUse.h \ - $$METAFILE_PATH/svg/SvgObjects/CPolyline.h \ - $$METAFILE_PATH/svg/SvgObjects/CStyle.h \ - $$METAFILE_PATH/svg/SvgObjects/CObjectBase.h \ - $$METAFILE_PATH/svg/SvgUtils.h + # DEPRECATED ENGINE. REMOVE IN 7.6+ VERSIONS + #CONFIG += svg_old_version - SOURCES += \ - $$METAFILE_PATH/svg/SVGFramework.cpp \ - $$METAFILE_PATH/svg/SVGTransformer.cpp \ - $$METAFILE_PATH/svg/CSvgFile.cpp \ - $$METAFILE_PATH/svg/CSvgParser.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CContainer.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CGradient.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CClipPath.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CMask.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CMarker.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CPattern.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CSymbol.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CImage.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CLine.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CRect.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CCircle.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CEllipse.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CPath.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CText.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CUse.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CPolyline.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CObjectBase.cpp \ - $$METAFILE_PATH/svg/SvgObjects/CStyle.cpp + svg_old_version { -include($$METAFILE_PATH/../../../Common/3dParty/html/css/CssCalculator.pri) + DEFINES += SVG_OLD_ENGINE + + HEADERS += \ + $$METAFILE_PATH/svg/SVGFramework.h \ + $$METAFILE_PATH/svg/SVGTransformer.h + + SOURCES += \ + $$METAFILE_PATH/svg/SVGFramework.cpp \ + $$METAFILE_PATH/svg/SVGTransformer.cpp + + } else { + + HEADERS += \ + $$METAFILE_PATH/svg/SvgTypes.h \ + $$METAFILE_PATH/svg/CSvgFile.h \ + $$METAFILE_PATH/svg/CSvgParser.h \ + $$METAFILE_PATH/svg/SvgObjects/CContainer.h \ + $$METAFILE_PATH/svg/SvgObjects/CGradient.h \ + $$METAFILE_PATH/svg/SvgObjects/CClipPath.h \ + $$METAFILE_PATH/svg/SvgObjects/CMask.h \ + $$METAFILE_PATH/svg/SvgObjects/CPattern.h \ + $$METAFILE_PATH/svg/SvgObjects/CSymbol.h \ + $$METAFILE_PATH/svg/SvgObjects/CMarker.h \ + $$METAFILE_PATH/svg/SvgObjects/CImage.h \ + $$METAFILE_PATH/svg/SvgObjects/CLine.h \ + $$METAFILE_PATH/svg/SvgObjects/CRect.h \ + $$METAFILE_PATH/svg/SvgObjects/CCircle.h \ + $$METAFILE_PATH/svg/SvgObjects/CEllipse.h \ + $$METAFILE_PATH/svg/SvgObjects/CPath.h \ + $$METAFILE_PATH/svg/SvgObjects/CText.h \ + $$METAFILE_PATH/svg/SvgObjects/CUse.h \ + $$METAFILE_PATH/svg/SvgObjects/CPolyline.h \ + $$METAFILE_PATH/svg/SvgObjects/CStyle.h \ + $$METAFILE_PATH/svg/SvgObjects/CObjectBase.h \ + $$METAFILE_PATH/svg/SvgUtils.h + + SOURCES += \ + $$METAFILE_PATH/svg/CSvgFile.cpp \ + $$METAFILE_PATH/svg/CSvgParser.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CContainer.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CGradient.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CClipPath.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CMask.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CMarker.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CPattern.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CSymbol.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CImage.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CLine.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CRect.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CCircle.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CEllipse.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CPath.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CText.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CUse.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CPolyline.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CObjectBase.cpp \ + $$METAFILE_PATH/svg/SvgObjects/CStyle.cpp + + include($$METAFILE_PATH/../../../Common/3dParty/html/css/CssCalculator.pri) + + } } !metafile_disable_svm { diff --git a/DesktopEditor/graphics/shading_info.h b/DesktopEditor/graphics/shading_info.h index 06f4186907..10e8552eec 100644 --- a/DesktopEditor/graphics/shading_info.h +++ b/DesktopEditor/graphics/shading_info.h @@ -1,5 +1,9 @@ #include #include +#include + +#include "../agg-2.4/include/agg_color_rgba.h" +#include "../graphics/aggplustypes.h" #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -10,527 +14,527 @@ namespace NSStructures { - /** - * + /** + * * */ - template - class ColorFunction - /** - * Реализацию произвольной функции в рантайме я решил сделать как массив, тк так проще всего - * я еще не совсем понял как точно передается в пдфе функция, но такая реализация, позволяет пользователю - * выбрать любой способ. - * - * Пока все копируется, т.к. в большинсве случаев вектор 2кБ по размеру и проблем нету - * только если использовать двумерную функцию размер возрастает до МБ, но не хочется возится с укузателями - * ради этого, т.к. судя по всему случай исключительный(только 1 шейдинг требует такую функцию). - * Если надо будет, наверно можно будет переписать на юникптр. - * - * Есть возможность выставить обычную линейную интерполяцию, просто для тестирования - * + так реализуется градиент стандартный. - * - * Пока у меня конструкторы по умолчанию, чтото заполняют, для тестирования опятьже - * потом стоит все убрать, чтобы в кисти не таскать это все, когда оно не нужно, - * если не выделять память то там в сумме будет <100B гдето, не думаю, что это будет так много, - * чтобы писать отдельный интерфейс для кисти - * - * Плюс я вообще не знаю как обрабатывать, внештатные ситуации, в целом, можно вообще просто - * эксепшены кидать если что или ничего не делать. - */ - { - public: - ColorFunction() : RESOLUTION(0), x_domain_min(0.0f), x_domain_max(0.0f) - { + template + class ColorFunction + /** + * Реализацию произвольной функции в рантайме я решил сделать как массив, тк так проще всего + * я еще не совсем понял как точно передается в пдфе функция, но такая реализация, позволяет пользователю + * выбрать любой способ. + * + * Пока все копируется, т.к. в большинсве случаев вектор 2кБ по размеру и проблем нету + * только если использовать двумерную функцию размер возрастает до МБ, но не хочется возится с укузателями + * ради этого, т.к. судя по всему случай исключительный(только 1 шейдинг требует такую функцию). + * Если надо будет, наверно можно будет переписать на юникптр. + * + * Есть возможность выставить обычную линейную интерполяцию, просто для тестирования + * + так реализуется градиент стандартный. + * + * Пока у меня конструкторы по умолчанию, чтото заполняют, для тестирования опятьже + * потом стоит все убрать, чтобы в кисти не таскать это все, когда оно не нужно, + * если не выделять память то там в сумме будет <100B гдето, не думаю, что это будет так много, + * чтобы писать отдельный интерфейс для кисти + * + * Плюс я вообще не знаю как обрабатывать, внештатные ситуации, в целом, можно вообще просто + * эксепшены кидать если что или ничего не делать. + */ + { + public: + ColorFunction() : RESOLUTION(0), x_domain_min(0.0f), x_domain_max(0.0f) + { - } + } - ColorFunction(size_t res, float xmin, float xmax) : RESOLUTION(res), x_domain_min(xmin), x_domain_max(xmax) + ColorFunction(size_t res, float xmin, float xmax) : RESOLUTION(res), x_domain_min(xmin), x_domain_max(xmax) - { - values = std::vector>(1, std::vector(RESOLUTION)); - for (size_t i = 0; i < RESOLUTION; i++) - { - unsigned int value = (unsigned int)(255 - (255 * ((float)i / RESOLUTION))); - values[0][i] = ColorT(value, value, value); - } - } + { + values = std::vector>(1, std::vector(RESOLUTION)); + for (size_t i = 0; i < RESOLUTION; i++) + { + unsigned int value = (unsigned int)(255 - (255 * ((float)i / RESOLUTION))); + values[0][i] = ColorT(value, value, value); + } + } - ColorFunction(size_t res, float xmin, float xmax, float ymin, float ymax) : RESOLUTION(res), x_domain_min(xmin), x_domain_max(xmax), y_domain_min(ymin), y_domain_max(ymax) - { - values = std::vector>(RESOLUTION, std::vector(RESOLUTION)); - for (size_t i = 0; i < RESOLUTION; i++) - { - for (size_t j = 0; j < RESOLUTION; j++) - { - unsigned int value = (unsigned int)(255 * sin(i * j * M_PI / RESOLUTION)); - values[j][i] = ColorT(255, 0, 0, 255); - } - } - } + ColorFunction(size_t res, float xmin, float xmax, float ymin, float ymax) : RESOLUTION(res), x_domain_min(xmin), x_domain_max(xmax), y_domain_min(ymin), y_domain_max(ymax) + { + values = std::vector>(RESOLUTION, std::vector(RESOLUTION)); + for (size_t i = 0; i < RESOLUTION; i++) + { + for (size_t j = 0; j < RESOLUTION; j++) + { + unsigned int value = (unsigned int)(255 * sin(i * j * M_PI / RESOLUTION)); + values[j][i] = ColorT(255, 0, 0, 255); + } + } + } - float get_x_min() - { - return x_domain_min; - } - float get_x_max() - { - return x_domain_max; - } - float get_y_min() - { - return y_domain_min; - } - float get_y_max() - { - return y_domain_max; - } - ColorT get_color(float x) - { - int index = get_x_index(x); - return values[0][index]; - } + float get_x_min() + { + return x_domain_min; + } + float get_x_max() + { + return x_domain_max; + } + float get_y_min() + { + return y_domain_min; + } + float get_y_max() + { + return y_domain_max; + } + ColorT get_color(float x) + { + int index = get_x_index(x); + return values[0][index]; + } - //used only in shading type 1 - ColorT get_color(float x, float y) - { - int xi = get_x_index(x); - int yi = get_y_index(y); - //std::cout << x << ' ' << y << std::endl; - return values[yi][xi]; - } + //used only in shading type 1 + ColorT get_color(float x, float y) + { + int xi = get_x_index(x); + int yi = get_y_index(y); + //std::cout << x << ' ' << y << std::endl; + return values[yi][xi]; + } - void set_color(float x, int r, int g, int b, int a) - { - int index = get_x_index(x); // pls dont set color out of bounds, it wont crush, but will work not as you max expected - values[0][index].r = r; - values[0][index].g = g; - values[0][index].b = b; - values[0][index].a = a; - } - void set_color(float x, float y, int r, int g, int b, int a) - { - int xindex = get_x_index(x); - int yindex = get_y_index(y); - values[yindex][xindex].r = r; - values[yindex][xindex].g = g; - values[yindex][xindex].b = b; - values[yindex][xindex].a = a; - } - void set_color(size_t xindex, int r, int g, int b, int a) - { - values[0][xindex].r = r; - values[0][xindex].g = g; - values[0][xindex].b = b; - values[0][xindex].a = a; - } - void set_color(size_t xindex, size_t yindex, int r, int g, int b, int a) - { - values[yindex][xindex].r = r; - values[yindex][xindex].g = g; - values[yindex][xindex].b = b; - values[yindex][xindex].a = a; - } - // position must be sorted by incr ub otherwise - // only for 1 in function - int set_linear_interpolation(const std::vector &colors, const std::vector &positions) - { - if (colors.size() != positions.size()) - { - return -1; // error - } - std::vector indexes; - for (float x : positions) - { - indexes.push_back(get_x_index(x)); - } - for (int i = 0; i < colors.size(); i++) - { - values[0][indexes[i]].r = hex2r(colors[i]); - values[0][indexes[i]].g = hex2g(colors[i]); - values[0][indexes[i]].b = hex2b(colors[i]); - values[0][indexes[i]].a = hex2a(colors[i]); + void set_color(float x, int r, int g, int b, int a) + { + int index = get_x_index(x); // pls dont set color out of bounds, it wont crush, but will work not as you max expected + values[0][index].r = r; + values[0][index].g = g; + values[0][index].b = b; + values[0][index].a = a; + } + void set_color(float x, float y, int r, int g, int b, int a) + { + int xindex = get_x_index(x); + int yindex = get_y_index(y); + values[yindex][xindex].r = r; + values[yindex][xindex].g = g; + values[yindex][xindex].b = b; + values[yindex][xindex].a = a; + } + void set_color(size_t xindex, int r, int g, int b, int a) + { + values[0][xindex].r = r; + values[0][xindex].g = g; + values[0][xindex].b = b; + values[0][xindex].a = a; + } + void set_color(size_t xindex, size_t yindex, int r, int g, int b, int a) + { + values[yindex][xindex].r = r; + values[yindex][xindex].g = g; + values[yindex][xindex].b = b; + values[yindex][xindex].a = a; + } + // position must be sorted by incr ub otherwise + // only for 1 in function + int set_linear_interpolation(const std::vector &colors, const std::vector &positions) + { + if (colors.size() != positions.size()) + { + return -1; // error + } + std::vector indexes; + for (float x : positions) + { + indexes.push_back(get_x_index(x)); + } + for (int i = 0; i < colors.size(); i++) + { + values[0][indexes[i]].r = hex2r(colors[i]); + values[0][indexes[i]].g = hex2g(colors[i]); + values[0][indexes[i]].b = hex2b(colors[i]); + values[0][indexes[i]].a = hex2a(colors[i]); - } - for (int i = 0; i < positions.size() - 1; i++) - { - interpolate_indexes(indexes[i], indexes[i + 1]); - } - return 0; - } - size_t get_resolution() const - { - return RESOLUTION; - } - private: - size_t RESOLUTION; - std::vector> values; - float x_domain_min, x_domain_max; - float y_domain_min, y_domain_max; - int get_x_index(float x) - { - int x_index = (int)(RESOLUTION - 1) * (x - x_domain_min) / (x_domain_max - x_domain_min); - if (x_index < 0) - return 0; - if (x_index > RESOLUTION - 1) - return RESOLUTION - 1; - return x_index; - } - int get_y_index(float y) - { - int y_index = (int)(RESOLUTION - 1) * (y - y_domain_min) / (y_domain_max - y_domain_min); - if (values.size() < RESOLUTION) - { - return 0; - } - if (y_index < 0) - return 0; - if (y_index > RESOLUTION - 1) - return RESOLUTION - 1; - return y_index; - } - /** - * Линейная интерполяция для построения цветовой функции. - */ - int interpolate_indexes(size_t first, size_t second, size_t line = 0) - { - size_t len = second - first; - ColorT f = values[line][first]; - ColorT s = values[line][second]; - for(size_t i = first + 1; i < second; i++) { - values[line][i].r = f.r * (1 - (float)(i - first) / len ) + s.r * ((float)(i - first) / len ); - values[line][i].g = f.g * (1 - (float)(i - first) / len ) + s.g * ((float)(i - first) / len ); ; - values[line][i].b = f.b * (1 - (float)(i - first) / len ) + s.b * ((float)(i - first) / len ); ; - values[line][i].a = f.a * (1 - (float)(i - first) / len ) + s.a * ((float)(i - first) / len ); ; - } - return 0; - } + } + for (int i = 0; i < positions.size() - 1; i++) + { + interpolate_indexes(indexes[i], indexes[i + 1]); + } + return 0; + } + size_t get_resolution() const + { + return RESOLUTION; + } + private: + size_t RESOLUTION; + std::vector> values; + float x_domain_min, x_domain_max; + float y_domain_min, y_domain_max; + int get_x_index(float x) + { + int x_index = (int)(RESOLUTION - 1) * (x - x_domain_min) / (x_domain_max - x_domain_min); + if (x_index < 0) + return 0; + if (x_index > RESOLUTION - 1) + return RESOLUTION - 1; + return x_index; + } + int get_y_index(float y) + { + int y_index = (int)(RESOLUTION - 1) * (y - y_domain_min) / (y_domain_max - y_domain_min); + if (values.size() < RESOLUTION) + { + return 0; + } + if (y_index < 0) + return 0; + if (y_index > RESOLUTION - 1) + return RESOLUTION - 1; + return y_index; + } + /** + * Линейная интерполяция для построения цветовой функции. + */ + int interpolate_indexes(size_t first, size_t second, size_t line = 0) + { + size_t len = second - first; + ColorT f = values[line][first]; + ColorT s = values[line][second]; + for(size_t i = first + 1; i < second; i++) { + values[line][i].r = f.r * (1 - (float)(i - first) / len ) + s.r * ((float)(i - first) / len ); + values[line][i].g = f.g * (1 - (float)(i - first) / len ) + s.g * ((float)(i - first) / len ); ; + values[line][i].b = f.b * (1 - (float)(i - first) / len ) + s.b * ((float)(i - first) / len ); ; + values[line][i].a = f.a * (1 - (float)(i - first) / len ) + s.a * ((float)(i - first) / len ); ; + } + return 0; + } - unsigned int hex2a(uint32_t c) - { - unsigned int a = (c >> 24) & 0xFF; - return a; - } + unsigned int hex2a(uint32_t c) + { + unsigned int a = (c >> 24) & 0xFF; + return a; + } - unsigned int hex2r(uint32_t c) - { - return (c >> 16) & 0xFF; - } - unsigned int hex2g(uint32_t c) - { - return (c >> 8) & 0xFF; - } - unsigned int hex2b(uint32_t c) - { - return c & 0xFF; - } - }; + unsigned int hex2r(uint32_t c) + { + return (c >> 16) & 0xFF; + } + unsigned int hex2g(uint32_t c) + { + return (c >> 8) & 0xFF; + } + unsigned int hex2b(uint32_t c) + { + return c & 0xFF; + } + }; - struct Point - { - Point():x(0),y(0){} - Point(const float& _x, const float& _y):x(_x),y(_y){} - Point(const int& _x, const int& _y):x((float)_x),y((float)_y){} - Point(const double& _x, const double& _y):x((float)_x),y((float)_y){} - float x, y; + struct Point + { + Point():x(0),y(0){} + Point(const float& _x, const float& _y):x(_x),y(_y){} + Point(const int& _x, const int& _y):x((float)_x),y((float)_y){} + Point(const double& _x, const double& _y):x((float)_x),y((float)_y){} + float x, y; - Point& operator+=(const Point &a) - { - x += a.x; - y += a.y; - return *this; - } + Point& operator+=(const Point &a) + { + x += a.x; + y += a.y; + return *this; + } - /** - * Костыль от ошибок линковки. Чтобы время не терять пока что. - */ - friend Point operator*(const Point &a, float t) - { - return Point(a.x * t, a.y * t); - } - friend Point operator*(float t, const Point &a) - { - return Point(a.x * t, a.y * t); - } - friend Point operator+(const Point &a, const Point &b) - { - return Point(a.x + b.x, a.y + b.y); - } - friend Point operator-(const Point &a, const Point &b) - { - return Point(a.x - b.x, a.y - b.y); - } - }; - - - - /** - * Тут хранится информация спецефичная для рендера ПДФ. - * - * Взял новую реализацию преобразований, т.к. готовая была на даблах, - * а в такой точности смысла нету особо. - * - * Для шейдеров требуется поддерживать два способа вычисления (с параметром и без), - * поэтому требуется много дополнительной инфы. - * - * Так же шейдер будет получать, в качетве параметров, границы, тут я пока не решил, вообще - * можно оставить соблюдение границ, на откуп пользователю, т.к. все равно заполенение в конечном итоге будет - * выполняться с помощью рисования замкнутого пути и команды Fill - * */ - struct ShadingInfo - { - public: - ShadingInfo() : shading_type(Parametric), f_type(UseNew), inv_map(6){} - enum ShadingType - { - FunctionOnly, - Parametric, - TriangleInterpolation, - CurveInterpolation, - TensorCurveInterpolation - } shading_type; - - // if UseOld old function is called, look for IGraphicsRender.put_BrushGradientColors; - enum ColorFunctionType - { - UseOld, UseNew - } f_type; - ColorFunction function; - - // Обратное преобразование из картинки в цветовую функцию - std::vector mapping; - std::vector inv_map; - - // Линейный градиент задается в pdf 2 точками - bool set_two_points; - Point point1, point2; - - - // triangle shading - std::vector triangle; - std::vector triangle_colors; - std::vector triangle_parameters; - - /** - * Матрица 4 на 4 заполняется как в документации к пдф 7 тип - * Если выбран тип 6 то значения (1,2) (2,1) (1,1) (2,2) - * В массиве игнормруется и заполняются автоматически, следите за переданным типом градинта - * (Нумерация от нуля) - * - * Наверное напишу адаптор который переводит порядок точек из 6 типа в общий. - */ - std::vector> patch; - std::vector> patch_colors; // 2 на 2 цвета по углам - std::vector> patch_parameters; // 2 на 2 параметра - }; - - // Containing additional info about gradient - struct GradientInfo - { - GradientInfo() : littleRadius(0.0f), largeRadius(1.0f), - centerX(0.0f), centerY(0.0f), - angle(0.0f), - discrete_step(0.0f), - reflected(false), - periods(0.5f), periodic(false), - xsize(1.0f), ysize(1.0f), - linstretch(1.0f), linoffset(0.0f), - continue_shading_f(false), - continue_shading_b(false) - - { - } - void setAngleDegrees(float deg) - { - angle = deg / 180.f * (float)M_PI; - } - float getAngleDegrees() const - { - return angle / (float)M_PI * 180.f; - } - void setStepByNum(int n) // recommended to use - { - discrete_step = 1.0f / n; - } - - Point p0, p1; - float r0, r1; - - float littleRadius, largeRadius; - float centerX, centerY; // used in radial, diamond and conical gradient - offset relative to figure center - float angle; // used in linear and conical gradient (rad) - float discrete_step; // used to make discrete gradient. <= 0 to make continuous - float xsize, ysize; // stretch image; can be negative to reflect relative to other axis; cannot be zero - bool reflected; // 1234567 -> 1357531 works kind of like this - bool periodic; - float periods; // number of periods (best with to colours, works as saw function in color space) - float linstretch; // stretch linear gradient, can be negative (eq angle = 180) can not be zero - float linoffset; // offset relative to image size - float continue_shading_b, continue_shading_f; - ShadingInfo shading; - }; - - - /** - * Создает объект класса GradientInfo по заданным параметрам. - * - * Цветовую функцию надо заполнять вручную - */ - class GInfoConstructor { - public: - static GradientInfo get_functional(float xmin, float xmax, float ymin, float ymax, - std::vector mapping) - { - GradientInfo ginfo; - ginfo.shading.function = ColorFunction(256, xmin, xmax, ymin, ymax); - ginfo.shading.f_type = ShadingInfo::UseNew; - ginfo.shading.shading_type = ShadingInfo::FunctionOnly; - - ginfo.shading.mapping = mapping; - - return ginfo; - } - static GradientInfo get_linear(const Point &p1, const Point &p2, float t0 = 0.0f, float t1 = 1.0f, - bool continue_shading_b = false, bool continue_shading_f = false) - { - GradientInfo ginfo; - ginfo.shading.f_type = ShadingInfo::UseNew; - ginfo.shading.shading_type = ShadingInfo::Parametric; - ginfo.continue_shading_f = continue_shading_f; - ginfo.continue_shading_b = continue_shading_b; - - ginfo.shading.function = ColorFunction(256, t0, t1); - - ginfo.shading.set_two_points = true; - ginfo.shading.point1 = p1; - ginfo.shading.point2 = p2; - - - return ginfo; - } - static GradientInfo get_radial(const Point &c0, const Point &c1, float r0, float r1, - float t0 = 0.0f, float t1 = 1.0f, - bool continue_shading_b = false, bool continue_shading_f = false) - { - GradientInfo ginfo; - ginfo.shading.f_type = ShadingInfo::UseNew; - ginfo.shading.shading_type = ShadingInfo::Parametric; - ginfo.continue_shading_f = continue_shading_f; - ginfo.continue_shading_b = continue_shading_b; - ginfo.shading.function = ColorFunction(256, t0, t1); - ginfo.p0 = c0; - ginfo.p1 = c1; - ginfo.r0 = r0; - ginfo.r1 = r1; - return ginfo; - - - } - static GradientInfo get_triangle(const std::vector &points, - const std::vector &colors, - const std::vector ¶ms, - bool parametric, - float t0 = 0.0f, float t1 = 1.0f) - { - GradientInfo ginfo; - ginfo.shading.triangle = points; - if (parametric) - { - ginfo.shading.triangle_parameters = params; - ginfo.shading.f_type = ShadingInfo::UseNew; - ginfo.shading.function = ColorFunction(256, t0, t1); - ginfo.shading.shading_type = ShadingInfo::Parametric; - ginfo.continue_shading_f = false; - ginfo.continue_shading_b = false; - } - else - { - ginfo.shading.triangle_colors = colors; - ginfo.shading.shading_type = ShadingInfo::TriangleInterpolation; - } - return ginfo; - } - - /** - * Набор из 12 точек для построения границ в порядке указанном в стандарте, - * Порядок цветов или параметров как в стандарте. - */ - static GradientInfo get_curve(const std::vector &curve_points, - const std::vector &curve_parametrs, - const std::vector &curve_colors, - bool parametric, - float t0 = 0.0f, float t1 = 1.0f) - { - GradientInfo ginfo; - ginfo.shading.patch.resize(4, std::vector(4)); - ginfo.shading.patch[0][0] = curve_points[0]; - ginfo.shading.patch[0][1] = curve_points[1]; - ginfo.shading.patch[0][2] = curve_points[2]; - - ginfo.shading.patch[0][3] = curve_points[3]; - ginfo.shading.patch[1][3] = curve_points[4]; - ginfo.shading.patch[2][3] = curve_points[5]; - - ginfo.shading.patch[3][3] = curve_points[6]; - ginfo.shading.patch[3][2] = curve_points[7]; - ginfo.shading.patch[3][1] = curve_points[8]; - - ginfo.shading.patch[3][0] = curve_points[9]; - ginfo.shading.patch[2][0] = curve_points[10]; - ginfo.shading.patch[1][0] = curve_points[11]; + /** + * Костыль от ошибок линковки. Чтобы время не терять пока что. + */ + friend Point operator*(const Point &a, float t) + { + return Point(a.x * t, a.y * t); + } + friend Point operator*(float t, const Point &a) + { + return Point(a.x * t, a.y * t); + } + friend Point operator+(const Point &a, const Point &b) + { + return Point(a.x + b.x, a.y + b.y); + } + friend Point operator-(const Point &a, const Point &b) + { + return Point(a.x - b.x, a.y - b.y); + } + }; - if (parametric) - { - ginfo.shading.patch_parameters.resize(2, std::vector(2)); - ginfo.shading.patch_parameters[0][0] = curve_parametrs[0]; - ginfo.shading.patch_parameters[0][1] = curve_parametrs[1]; - ginfo.shading.patch_parameters[1][0] = curve_parametrs[3]; - ginfo.shading.patch_parameters[1][1] = curve_parametrs[2]; - ginfo.shading.f_type = ShadingInfo::UseNew; - ginfo.shading.function = ColorFunction(256, t0, t1); - ginfo.shading.shading_type = ShadingInfo::Parametric; - ginfo.continue_shading_f = false; - ginfo.continue_shading_b = false; - } - else - { - ginfo.shading.patch_colors.resize(2, std::vector(2)); - ginfo.shading.patch_colors[0][0] = curve_colors[0]; - ginfo.shading.patch_colors[0][1] = curve_colors[1]; - ginfo.shading.patch_colors[1][0] = curve_colors[3]; - ginfo.shading.patch_colors[1][1] = curve_colors[2]; - ginfo.shading.shading_type = ShadingInfo::CurveInterpolation; - } - return ginfo; - } - static GradientInfo get_tensor_curve(const std::vector> &curve_poits, - const std::vector> &curve_parametrs, - const std::vector> &curve_colors, - bool parametric, - float t0 = 0.0f, float t1 = 1.0f) - { - GradientInfo ginfo; - - ginfo.shading.patch = curve_poits; - - if (parametric) - { - ginfo.shading.patch_parameters = curve_parametrs; - ginfo.shading.f_type = ShadingInfo::UseNew; - ginfo.shading.function = ColorFunction(256, t0, t1); - ginfo.shading.shading_type = ShadingInfo::Parametric; - ginfo.continue_shading_f = false; - ginfo.continue_shading_b = false; - } - else - { - ginfo.shading.patch_colors = curve_colors; - ginfo.shading.shading_type = ShadingInfo::TensorCurveInterpolation; - } - return ginfo; - } - }; + /** + * Тут хранится информация спецефичная для рендера ПДФ. + * + * Взял новую реализацию преобразований, т.к. готовая была на даблах, + * а в такой точности смысла нету особо. + * + * Для шейдеров требуется поддерживать два способа вычисления (с параметром и без), + * поэтому требуется много дополнительной инфы. + * + * Так же шейдер будет получать, в качетве параметров, границы, тут я пока не решил, вообще + * можно оставить соблюдение границ, на откуп пользователю, т.к. все равно заполенение в конечном итоге будет + * выполняться с помощью рисования замкнутого пути и команды Fill + * */ + struct ShadingInfo + { + public: + ShadingInfo() : shading_type(Parametric), f_type(UseNew), inv_map(6){} + enum ShadingType + { + FunctionOnly, + Parametric, + TriangleInterpolation, + CurveInterpolation, + TensorCurveInterpolation + } shading_type; + + // if UseOld old function is called, look for IGraphicsRender.put_BrushGradientColors; + enum ColorFunctionType + { + UseOld, UseNew + } f_type; + ColorFunction function; + + // Обратное преобразование из картинки в цветовую функцию + std::vector mapping; + std::vector inv_map; + + // Линейный градиент задается в pdf 2 точками + bool set_two_points; + Point point1, point2; + + + // triangle shading + std::vector triangle; + std::vector triangle_colors; + std::vector triangle_parameters; + + /** + * Матрица 4 на 4 заполняется как в документации к пдф 7 тип + * Если выбран тип 6 то значения (1,2) (2,1) (1,1) (2,2) + * В массиве игнормруется и заполняются автоматически, следите за переданным типом градинта + * (Нумерация от нуля) + * + * Наверное напишу адаптор который переводит порядок точек из 6 типа в общий. + */ + std::vector> patch; + std::vector> patch_colors; // 2 на 2 цвета по углам + std::vector> patch_parameters; // 2 на 2 параметра + }; + + // Containing additional info about gradient + struct GradientInfo + { + GradientInfo() : littleRadius(0.0f), largeRadius(1.0f), + centerX(0.0f), centerY(0.0f), + angle(0.0f), + discrete_step(0.0f), + reflected(false), + periods(0.5f), periodic(false), + xsize(1.0f), ysize(1.0f), + linstretch(1.0f), linoffset(0.0f), + continue_shading_f(false), + continue_shading_b(false) + + { + } + void setAngleDegrees(float deg) + { + angle = deg / 180.f * (float)M_PI; + } + float getAngleDegrees() const + { + return angle / (float)M_PI * 180.f; + } + void setStepByNum(int n) // recommended to use + { + discrete_step = 1.0f / n; + } + + Point p0, p1; + float r0, r1; + + float littleRadius, largeRadius; + float centerX, centerY; // used in radial, diamond and conical gradient - offset relative to figure center + float angle; // used in linear and conical gradient (rad) + float discrete_step; // used to make discrete gradient. <= 0 to make continuous + float xsize, ysize; // stretch image; can be negative to reflect relative to other axis; cannot be zero + bool reflected; // 1234567 -> 1357531 works kind of like this + bool periodic; + float periods; // number of periods (best with to colours, works as saw function in color space) + float linstretch; // stretch linear gradient, can be negative (eq angle = 180) can not be zero + float linoffset; // offset relative to image size + float continue_shading_b, continue_shading_f; + ShadingInfo shading; + }; + + + /** + * Создает объект класса GradientInfo по заданным параметрам. + * + * Цветовую функцию надо заполнять вручную + */ + class GInfoConstructor { + public: + static GradientInfo get_functional(float xmin, float xmax, float ymin, float ymax, + std::vector mapping) + { + GradientInfo ginfo; + ginfo.shading.function = ColorFunction(256, xmin, xmax, ymin, ymax); + ginfo.shading.f_type = ShadingInfo::UseNew; + ginfo.shading.shading_type = ShadingInfo::FunctionOnly; + + ginfo.shading.mapping = mapping; + + return ginfo; + } + static GradientInfo get_linear(const Point &p1, const Point &p2, float t0 = 0.0f, float t1 = 1.0f, + bool continue_shading_b = false, bool continue_shading_f = false) + { + GradientInfo ginfo; + ginfo.shading.f_type = ShadingInfo::UseNew; + ginfo.shading.shading_type = ShadingInfo::Parametric; + ginfo.continue_shading_f = continue_shading_f; + ginfo.continue_shading_b = continue_shading_b; + + ginfo.shading.function = ColorFunction(256, t0, t1); + + ginfo.shading.set_two_points = true; + ginfo.shading.point1 = p1; + ginfo.shading.point2 = p2; + + + return ginfo; + } + static GradientInfo get_radial(const Point &c0, const Point &c1, float r0, float r1, + float t0 = 0.0f, float t1 = 1.0f, + bool continue_shading_b = false, bool continue_shading_f = false) + { + GradientInfo ginfo; + ginfo.shading.f_type = ShadingInfo::UseNew; + ginfo.shading.shading_type = ShadingInfo::Parametric; + ginfo.continue_shading_f = continue_shading_f; + ginfo.continue_shading_b = continue_shading_b; + ginfo.shading.function = ColorFunction(256, t0, t1); + ginfo.p0 = c0; + ginfo.p1 = c1; + ginfo.r0 = r0; + ginfo.r1 = r1; + return ginfo; + + + } + static GradientInfo get_triangle(const std::vector &points, + const std::vector &colors, + const std::vector ¶ms, + bool parametric, + float t0 = 0.0f, float t1 = 1.0f) + { + GradientInfo ginfo; + ginfo.shading.triangle = points; + if (parametric) + { + ginfo.shading.triangle_parameters = params; + ginfo.shading.f_type = ShadingInfo::UseNew; + ginfo.shading.function = ColorFunction(256, t0, t1); + ginfo.shading.shading_type = ShadingInfo::Parametric; + ginfo.continue_shading_f = false; + ginfo.continue_shading_b = false; + } + else + { + ginfo.shading.triangle_colors = colors; + ginfo.shading.shading_type = ShadingInfo::TriangleInterpolation; + } + return ginfo; + } + + /** + * Набор из 12 точек для построения границ в порядке указанном в стандарте, + * Порядок цветов или параметров как в стандарте. + */ + static GradientInfo get_curve(const std::vector &curve_points, + const std::vector &curve_parametrs, + const std::vector &curve_colors, + bool parametric, + float t0 = 0.0f, float t1 = 1.0f) + { + GradientInfo ginfo; + ginfo.shading.patch.resize(4, std::vector(4)); + ginfo.shading.patch[0][0] = curve_points[0]; + ginfo.shading.patch[0][1] = curve_points[1]; + ginfo.shading.patch[0][2] = curve_points[2]; + + ginfo.shading.patch[0][3] = curve_points[3]; + ginfo.shading.patch[1][3] = curve_points[4]; + ginfo.shading.patch[2][3] = curve_points[5]; + + ginfo.shading.patch[3][3] = curve_points[6]; + ginfo.shading.patch[3][2] = curve_points[7]; + ginfo.shading.patch[3][1] = curve_points[8]; + + ginfo.shading.patch[3][0] = curve_points[9]; + ginfo.shading.patch[2][0] = curve_points[10]; + ginfo.shading.patch[1][0] = curve_points[11]; + + + + if (parametric) + { + ginfo.shading.patch_parameters.resize(2, std::vector(2)); + ginfo.shading.patch_parameters[0][0] = curve_parametrs[0]; + ginfo.shading.patch_parameters[0][1] = curve_parametrs[1]; + ginfo.shading.patch_parameters[1][0] = curve_parametrs[3]; + ginfo.shading.patch_parameters[1][1] = curve_parametrs[2]; + ginfo.shading.f_type = ShadingInfo::UseNew; + ginfo.shading.function = ColorFunction(256, t0, t1); + ginfo.shading.shading_type = ShadingInfo::Parametric; + ginfo.continue_shading_f = false; + ginfo.continue_shading_b = false; + } + else + { + ginfo.shading.patch_colors.resize(2, std::vector(2)); + ginfo.shading.patch_colors[0][0] = curve_colors[0]; + ginfo.shading.patch_colors[0][1] = curve_colors[1]; + ginfo.shading.patch_colors[1][0] = curve_colors[3]; + ginfo.shading.patch_colors[1][1] = curve_colors[2]; + ginfo.shading.shading_type = ShadingInfo::CurveInterpolation; + } + return ginfo; + } + static GradientInfo get_tensor_curve(const std::vector> &curve_poits, + const std::vector> &curve_parametrs, + const std::vector> &curve_colors, + bool parametric, + float t0 = 0.0f, float t1 = 1.0f) + { + GradientInfo ginfo; + + ginfo.shading.patch = curve_poits; + + if (parametric) + { + ginfo.shading.patch_parameters = curve_parametrs; + ginfo.shading.f_type = ShadingInfo::UseNew; + ginfo.shading.function = ColorFunction(256, t0, t1); + ginfo.shading.shading_type = ShadingInfo::Parametric; + ginfo.continue_shading_f = false; + ginfo.continue_shading_b = false; + } + else + { + ginfo.shading.patch_colors = curve_colors; + ginfo.shading.shading_type = ShadingInfo::TensorCurveInterpolation; + } + return ginfo; + } + }; } #endif diff --git a/DesktopEditor/graphics/structures.h b/DesktopEditor/graphics/structures.h index 693b4ab0df..f8089a85b3 100644 --- a/DesktopEditor/graphics/structures.h +++ b/DesktopEditor/graphics/structures.h @@ -32,16 +32,12 @@ #ifndef _BUILD_GRAPHICS_STRUCTURES_H_ #define _BUILD_GRAPHICS_STRUCTURES_H_ -#include "../common/Array.h" -#include "../graphics/aggplustypes.h" -#include "../agg-2.4/include/agg_color_rgba.h" -#include "shading_info.h" #include #include #include #include -#include +#include "shading_info.h" #include "Matrix.h" // pen ----------------------------------------------------------- diff --git a/DesktopEditor/graphics/tests/alphaMask/main.cpp b/DesktopEditor/graphics/tests/alphaMask/main.cpp index f6e0b26643..fe424b0896 100644 --- a/DesktopEditor/graphics/tests/alphaMask/main.cpp +++ b/DesktopEditor/graphics/tests/alphaMask/main.cpp @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) } case LoadMaskFromBuffer: { - Aggplus::CAlphaMask oAlphaMask; + Aggplus::CAlphaMask* pAlphaMask = new Aggplus::CAlphaMask(); BYTE* pAlphaBuffer = new BYTE[unWidth * unHeight]; @@ -84,10 +84,11 @@ int main(int argc, char *argv[]) uchAlphaValue += 25; } - oAlphaMask.LoadFromAlphaBuffer(pAlphaBuffer, unWidth, unHeight, false); + pAlphaMask->LoadFromAlphaBuffer(pAlphaBuffer, unWidth, unHeight, false); - pRasterRenderer->SetAlphaMask(oAlphaMask); + pRasterRenderer->SetAlphaMask(pAlphaMask); + pAlphaMask->Release(); break; } case LoadMaskFromFile: diff --git a/DesktopEditor/raster/Metafile/MetaFile.cpp b/DesktopEditor/raster/Metafile/MetaFile.cpp index b114946cd7..8fb14396a9 100644 --- a/DesktopEditor/raster/Metafile/MetaFile.cpp +++ b/DesktopEditor/raster/Metafile/MetaFile.cpp @@ -303,7 +303,6 @@ namespace MetaFile #ifdef METAFILE_SUPPORT_SVG m_oSvgFile.SetFontManager(m_pFontManager); - m_oSvgFile2.SetFontManager(m_pFontManager); #endif //------------------------------------------------------ @@ -351,7 +350,7 @@ namespace MetaFile #endif // Это не svm #ifdef METAFILE_SUPPORT_SVG - if (m_oSvgFile2.OpenFromFile(wsFilePath) == true) + if (m_oSvgFile.OpenFromFile(wsFilePath) == true) { m_lType = c_lMetaSvg; return true; @@ -486,7 +485,7 @@ namespace MetaFile #ifdef METAFILE_SUPPORT_SVG case c_lMetaSvg: { - m_oSvgFile2.Draw(pRenderer, dX, dY, dWidth, dHeight); + m_oSvgFile.Draw(pRenderer, dX, dY, dWidth, dHeight); break; } #endif @@ -565,7 +564,7 @@ namespace MetaFile #ifdef METAFILE_SUPPORT_SVG case c_lMetaSvg: { - m_oSvgFile2.GetBounds(*pdX, *pdY, *pdW, *pdH); + m_oSvgFile.GetBounds(*pdX, *pdY, *pdW, *pdH); break; } #endif diff --git a/DesktopEditor/raster/Metafile/MetaFile.h b/DesktopEditor/raster/Metafile/MetaFile.h index 85eada8ef8..8d804e5e83 100644 --- a/DesktopEditor/raster/Metafile/MetaFile.h +++ b/DesktopEditor/raster/Metafile/MetaFile.h @@ -46,9 +46,13 @@ #endif #ifdef METAFILE_SUPPORT_SVG +#ifdef SVG_OLD_ENGINE #include "svg/SVGTransformer.h" +typedef CSVGTransformer CSvgFile; +#else #include "svg/CSvgFile.h" #endif +#endif namespace MetaFile { @@ -95,8 +99,7 @@ namespace MetaFile #endif #ifdef METAFILE_SUPPORT_SVG - CSVGTransformer m_oSvgFile; - CSvgFile m_oSvgFile2; + CSvgFile m_oSvgFile; #endif int m_lType; diff --git a/DesktopEditor/raster/Metafile/svg/SVGTransformer.cpp b/DesktopEditor/raster/Metafile/svg/SVGTransformer.cpp index 06d460c132..30daa1ba42 100644 --- a/DesktopEditor/raster/Metafile/svg/SVGTransformer.cpp +++ b/DesktopEditor/raster/Metafile/svg/SVGTransformer.cpp @@ -99,3 +99,13 @@ int CSVGTransformer::get_Metrics() { return m_internal->m_oXmlParser.GetMetrics(); } + +bool CSVGTransformer::GetBounds(double &dX, double &dY, double &dWidth, double &dHeight) +{ + dX = 0; + dY = 0; + dWidth = get_Width(); + dHeight = get_Height(); + + return true; +} diff --git a/DesktopEditor/raster/Metafile/svg/SVGTransformer.h b/DesktopEditor/raster/Metafile/svg/SVGTransformer.h index 36b1dccfe1..c145058854 100644 --- a/DesktopEditor/raster/Metafile/svg/SVGTransformer.h +++ b/DesktopEditor/raster/Metafile/svg/SVGTransformer.h @@ -27,6 +27,8 @@ public: int get_Height(); int get_Metrics(); + bool GetBounds(double &dX, double &dY, double &dWidth, double &dHeight); + private: CSVGTransformer_private* m_internal; }; diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CMarker.cpp b/DesktopEditor/raster/Metafile/svg/SvgObjects/CMarker.cpp index 811fce7baa..36e865447c 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CMarker.cpp +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CMarker.cpp @@ -5,7 +5,7 @@ namespace SVG { -CMarker::CMarker(XmlUtils::CXmlNode &oNode) + CMarker::CMarker(XmlUtils::CXmlNode &oNode) : CObject(oNode), m_pImage(NULL) { m_oWindow.m_oX .SetValue(oNode.GetAttribute(L"refX")); diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.cpp b/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.cpp index 5235194e88..32fa98a88a 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.cpp +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.cpp @@ -16,7 +16,7 @@ namespace SVG { -#define DefaultFontFamily L"Times New Roman" + #define DefaultFontFamily L"Times New Roman" CTSpan::CTSpan(XmlUtils::CXmlNode& oNode, CRenderedObject* pParent, NSFonts::IFontManager* pFontManager, bool bCheckText) : CRenderedObject(oNode, pParent), m_pFontManager(pFontManager), pPrevElement(NULL) diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.h b/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.h index a26f175dee..b1e174c1a3 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.h +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.h @@ -73,7 +73,7 @@ namespace SVG bool Draw(IRenderer* pRenderer, const CSvgFile* pFile, CommandeMode oMode = CommandeModeDraw, const TSvgStyles* pOtherStyles = NULL) const override; - static CTextPath* Create(XmlUtils::CXmlNode& oNode, CRenderedObject* pParent = NULL, NSFonts::IFontManager* pFontManager = NULL, const CSvgFile* pFile = NULL); + static CTextPath* Create(XmlUtils::CXmlNode& oNode, CRenderedObject* pParent = NULL, NSFonts::IFontManager* pFontManager = NULL, const CSvgFile* pFile = NULL); private: void DrawGlyph(CTSpan* pTSpan, CMovingPath& oMovingPath, IRenderer* pRenderer, const CSvgFile* pFile, CommandeMode oMode) const; diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CUse.h b/DesktopEditor/raster/Metafile/svg/SvgObjects/CUse.h index a904d44d1e..0fff7c454b 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CUse.h +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CUse.h @@ -6,7 +6,7 @@ namespace SVG { -class CUse : public CRenderedObject + class CUse : public CRenderedObject { public: CUse(XmlUtils::CXmlNode& oNode, CRenderedObject* pParent = NULL, const CSvgFile* pFile = NULL); diff --git a/DesktopEditor/raster/Metafile/svg/SvgTypes.h b/DesktopEditor/raster/Metafile/svg/SvgTypes.h index b3a43dd952..13048c1ee0 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgTypes.h +++ b/DesktopEditor/raster/Metafile/svg/SvgTypes.h @@ -8,16 +8,16 @@ namespace SVG { - #define MapCI std::map::const_iterator + #define MapCI std::map::const_iterator - #define SvgDigit NSCSS::NSProperties::CDigit - #define SvgString NSCSS::NSProperties::CString - #define SvgColor NSCSS::NSProperties::CColor - #define SvgEnum NSCSS::NSProperties::CEnum + #define SvgDigit NSCSS::NSProperties::CDigit + #define SvgString NSCSS::NSProperties::CString + #define SvgColor NSCSS::NSProperties::CColor + #define SvgEnum NSCSS::NSProperties::CEnum - #define SvgTransform NSCSS::NSProperties::CTransform - #define SvgFont NSCSS::NSProperties::CFont - #define SvgText NSCSS::NSProperties::CText + #define SvgTransform NSCSS::NSProperties::CTransform + #define SvgFont NSCSS::NSProperties::CFont + #define SvgText NSCSS::NSProperties::CText struct TStroke { diff --git a/DesktopEditor/raster/Metafile/svg/SvgUtils.h b/DesktopEditor/raster/Metafile/svg/SvgUtils.h index 6718db94d2..792ea4e62f 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgUtils.h +++ b/DesktopEditor/raster/Metafile/svg/SvgUtils.h @@ -9,7 +9,7 @@ namespace SVG { - #define ADD_COLOR( COLOR, R, G, B ) m_Table.insert(std::pair( L##COLOR, ( R << 0 ) | ( G << 8 ) | ( B << 16 ) )) + #define ADD_COLOR( COLOR, R, G, B ) m_Table.insert(std::pair( L##COLOR, ( R << 0 ) | ( G << 8 ) | ( B << 16 ) )) enum Metrics { @@ -219,18 +219,18 @@ namespace SVG { switch (eMetrics) { - case EM: break; - case EX: break; - case PX: dValue *= 96 / 25.4; - case PT: break; - case PC: break; - case CM: break; - case MM: break; - case INCH: break; + case EM: break; + case EX: break; + case PX: dValue *= 96 / 25.4; + case PT: break; + case PC: break; + case CM: break; + case MM: break; + case INCH: break; - case PCT: break; + case PCT: break; - case UNDEFINED: break; + case UNDEFINED: break; } }