From 4cd4feb25b92e282350bcdebf59686ca439f23f4 Mon Sep 17 00:00:00 2001 From: "Oleg.Korshul" Date: Wed, 12 Feb 2014 15:18:00 +0000 Subject: [PATCH] git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@54353 954022d7-b5bf-4e40-9824-e11837661b57 --- DesktopEditor/graphics/Graphics.cpp | 6 + DesktopEditor/graphics/Graphics.h | 7 +- DesktopEditor/graphics/GraphicsRenderer.cpp | 14 +- DesktopEditor/graphics/GraphicsRenderer.h | 325 +++++++++++++++++++- DesktopEditor/graphics/IRenderer.h | 2 +- 5 files changed, 350 insertions(+), 4 deletions(-) diff --git a/DesktopEditor/graphics/Graphics.cpp b/DesktopEditor/graphics/Graphics.cpp index b02f082b7e..bd32ef0434 100644 --- a/DesktopEditor/graphics/Graphics.cpp +++ b/DesktopEditor/graphics/Graphics.cpp @@ -15,6 +15,8 @@ namespace Aggplus m_ePageUnits = UnitPixel; + m_bIntegerGrid = false; + #ifdef _WINDOWS_GDIPLUS_USE_ m_pBitmap = NULL; m_pGraphics = NULL; @@ -35,6 +37,8 @@ namespace Aggplus m_pPixels = NULL; + m_bIntegerGrid = false; + Create(pBuffer, dwWidth, dwHeight, stride, 0); #ifdef _WINDOW_GDIPLUS_USE_ @@ -59,6 +63,8 @@ namespace Aggplus m_ePageUnits = UnitPixel; m_pPixels = NULL; + + m_bIntegerGrid = false; Create(pImage->m_pImgData, pImage->GetWidth(), pImage->GetHeight(), pImage->m_nStride, 0); diff --git a/DesktopEditor/graphics/Graphics.h b/DesktopEditor/graphics/Graphics.h index c1285c7e08..5e17a63f5e 100644 --- a/DesktopEditor/graphics/Graphics.h +++ b/DesktopEditor/graphics/Graphics.h @@ -281,7 +281,7 @@ protected: agg::svg::frame_buffer_rgba m_frame_buffer; agg::svg::rasterizer m_rasterizer; - + #ifdef _WINDOW_GRAPHIS_USE_ // для отрисовки картинок - используем Gdiplus Gdiplus::Graphics* m_pGraphics; @@ -296,6 +296,8 @@ public: agg::svg::frame_buffer_rgba& get_frame_buffer(); agg::svg::rasterizer& get_rasterizer(); + bool m_bIntegerGrid; + public: CGraphics(); @@ -383,6 +385,9 @@ public: inline Aggplus::CMatrix* GetFullTransform() { return &m_oFullTransform; } inline Aggplus::CMatrix* GetCoordTransform() { return &m_oCoordTransform; } + inline double GetPixW() { return m_dWidthPix; } + inline double GetPixH() { return m_dHeightPix; } + protected: template diff --git a/DesktopEditor/graphics/GraphicsRenderer.cpp b/DesktopEditor/graphics/GraphicsRenderer.cpp index fbf692ffb7..eec7f4a460 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.cpp +++ b/DesktopEditor/graphics/GraphicsRenderer.cpp @@ -896,7 +896,7 @@ HRESULT CGraphicsRenderer::DrawImage(IGrObject* pImage, const double& x, const d m_pRenderer->DrawImage((Aggplus::CImage*)pImage, x, y, w, h); return S_OK; } -HRESULT CGraphicsRenderer::DrawImageFromFile(const std::wstring& bstrVal, const double& x, const double& y, const double& w, const double& h) +HRESULT CGraphicsRenderer::DrawImageFromFile(const std::wstring& bstrVal, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha) { CCacheImage* pCacheImage = NULL; if (NULL != m_pCache) @@ -1140,4 +1140,16 @@ void CGraphicsRenderer::put_GlobalAlphaEnabled(const bool& bEnabled, const doubl m_dGlobalAlpha = dVal; else m_dGlobalAlpha = 1.0; +} + +void CGraphicsRenderer::AddRect(const double& x, const double& y, const double& w, const double& h) +{ + if (!CheckValidate()) + return; + + m_pPath->MoveTo(x, y); + m_pPath->LineTo(x + w, y); + m_pPath->LineTo(x + w, y + h); + m_pPath->LineTo(x, y + h); + m_pPath->CloseFigure(); } \ No newline at end of file diff --git a/DesktopEditor/graphics/GraphicsRenderer.h b/DesktopEditor/graphics/GraphicsRenderer.h index b2d00d725d..b50b87cb34 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.h +++ b/DesktopEditor/graphics/GraphicsRenderer.h @@ -169,7 +169,7 @@ public: //-------- Функции для вывода изображений --------------------------------------------------- virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h); - virtual HRESULT DrawImageFromFile(const std::wstring& sFile, const double& x, const double& y, const double& w, const double& h); + virtual HRESULT DrawImageFromFile(const std::wstring& sFile, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255); // transform -------------------------------------------------------------------------------- virtual HRESULT SetTransform(const double& m1, const double& m2, const double& m3, const double& m4, const double& m5, const double& m6); @@ -186,6 +186,19 @@ public: virtual HRESULT CommandString(const LONG& lType, const std::wstring& sCommand); void put_GlobalAlphaEnabled(const bool& bEnabled, const double& dVal); + inline void put_IntegerGrid(const bool& bEnabled) + { + if (!m_pRenderer) + return; + m_pRenderer->m_bIntegerGrid = bEnabled; + } + inline bool get_IntegerGrid() + { + if (!m_pRenderer) + return false; + return m_pRenderer->m_bIntegerGrid; + } + void AddRect(const double& x, const double& y, const double& w, const double& h); protected: void _SetFont(); @@ -232,6 +245,316 @@ public: { DrawPath(1); } + + inline double GetPixW() { return m_pRenderer->GetPixW(); } + inline double GetPixH() { return m_pRenderer->GetPixH(); } + + // smart methods + void drawHorLine(BYTE align, double y, double x, double r, double penW) + { + int pen_w = (int)((m_pRenderer->GetDpiX() * penW / 25.4) + 0.5); + if (0 == pen_w) + pen_w = 1; + + double __x = x; + double __y1 = y; + double __r = r; + double __y2 = y; + Aggplus::CMatrix* pMatrix = GetFullTransform(); + pMatrix->TransformPoint(__x, __y1); + pMatrix->TransformPoint(__r, __y2); + + double _x = (int)__x; + double _r = (int)__r + 1; + + m_oPen.Size = pen_w; + + switch (align) + { + case 0: + { + double _top = (int)__y1 + 0.5; + _top = _top + pen_w / 2.0 - 0.5; + m_pPath->Reset(); + m_pPath->MoveTo(_x, _top); + m_pPath->LineTo(_r, _top); + Stroke(); + break; + } + case 1: + { + // center + double _center = (int)__y1 + 0.5; + + m_pPath->Reset(); + if (0 == (pen_w % 2)) + { + m_pPath->MoveTo(_x, _center - 0.5); + m_pPath->LineTo(_r, _center - 0.5); + } + else + { + m_pPath->MoveTo(_x, _center); + m_pPath->LineTo(_r, _center); + } + Stroke(); + + break; + } + case 2: + { + double _bottom = (int)__y1 + 0.5; + _bottom = _bottom - pen_w / 2.0 + 0.5; + m_pPath->Reset(); + m_pPath->MoveTo(_x, _bottom); + m_pPath->LineTo(_r, _bottom); + Stroke(); + break; + } + } + } + + void drawHorLine2(BYTE align, double y, double x, double r, double penW) + { + int pen_w = (int)((m_pRenderer->GetDpiX() * penW / 25.4) + 0.5); + if (0 == pen_w) + pen_w = 1; + + double __x = x; + double __y1 = y; + double __r = r; + double __y2 = y; + Aggplus::CMatrix* pMatrix = GetFullTransform(); + pMatrix->TransformPoint(__x, __y1); + pMatrix->TransformPoint(__r, __y2); + + double _x = (int)__x; + double _r = (int)__r + 1; + + switch (align) + { + case 0: + { + // top + double _top = (int)__y1 + 0.5; + + double _pos1 = _top + pen_w / 2.0 - 0.5 - pen_w; + double _pos2 = _pos1 + pen_w * 2.0; + + m_pPath->Reset(); + m_pPath->MoveTo(_x, _pos1); + m_pPath->LineTo(_r, _pos1); + Stroke(); + + m_pPath->Reset(); + m_pPath->MoveTo(_x, _pos2); + m_pPath->LineTo(_r, _pos2); + Stroke(); + break; + } + case 1: + { + // center + // TODO: + + break; + } + case 2: + { + // bottom + // TODO: + + break; + } + } + } + + void drawVerLine(BYTE align, double x, double y, double b, double penW) + { + int pen_w = (int)((m_pRenderer->GetDpiX() * penW / 25.4) + 0.5); + if (0 == pen_w) + pen_w = 1; + + double __x1 = x; + double __y = y; + double __x2 = x; + double __b = b; + + Aggplus::CMatrix* pMatrix = GetFullTransform(); + pMatrix->TransformPoint(__x1, __y); + pMatrix->TransformPoint(__x2, __b); + + double _y = (int)__y; + double _b = (int)__b + 1; + + m_oPen.Size = pen_w; + switch (align) + { + case 0: + { + // left + double _left = __x1 + 0.5; + _left = _left + pen_w / 2.0 - 0.5; + + m_pPath->Reset(); + m_pPath->MoveTo(_left, _y); + m_pPath->LineTo(_left, _b); + Stroke(); + break; + } + case 1: + { + // center + double _center = __x1 + 0.5; + + m_pPath->Reset(); + if (0 == (pen_w % 2)) + { + m_pPath->MoveTo(_center - 0.5, _y); + m_pPath->LineTo(_center - 0.5, _b); + } + else + { + m_pPath->MoveTo(_center, _y); + m_pPath->LineTo(_center, _b); + } + Stroke(); + + break; + } + case 2: + { + // right + double _right = __x1 + 0.5; + _right = _right - pen_w / 2.0 + 0.5; + + m_pPath->Reset(); + m_pPath->MoveTo(_right, _y); + m_pPath->LineTo(_right, _b); + Stroke(); + break; + } + } + } + + void drawHorLineExt(BYTE align, double y, double x, double r, double penW, double leftMW, double rightMW) + { + int pen_w = (int)((m_pRenderer->GetDpiX() * penW / 25.4) + 0.5); + if (0 == pen_w) + pen_w = 1; + + double __x = x; + double __y1 = y; + double __r = r; + double __y2 = y; + Aggplus::CMatrix* pMatrix = GetFullTransform(); + pMatrix->TransformPoint(__x, __y1); + pMatrix->TransformPoint(__r, __y2); + + double _x = (int)__x + 0.5; + double _r = (int)__r + 0.5; + + if (leftMW != 0) + { + double _center = _x; + + int pen_mw = (int)((m_pRenderer->GetDpiX() * abs(leftMW) * 2 / 25.4) + 0.5); + if (0 == pen_mw) + pen_mw = 1; + + if (leftMW < 0) + { + _x = _center - (pen_mw >> 1); + } + else + { + if ((pen_mw % 2) == 0) + { + _x = _center + ((pen_mw >> 1) - 1.0); + } + else + { + _x = _center + (pen_mw >> 1); + } + } + } + if (rightMW != 0) + { + double _center = _r; + + int pen_mw = (int)((m_pRenderer->GetDpiX() * abs(rightMW) * 2 / 25.4) + 0.5); + if (0 == pen_mw) + pen_mw = 1; + + if (rightMW < 0) + { + _r = _center - (pen_mw >> 1); + } + else + { + if ((pen_mw % 2) == 0) + { + _r = _center + (pen_mw >> 1) - 1.0; + } + else + { + _r = _center + (pen_mw >> 1); + } + } + } + + m_oPen.Size = pen_w; + + _x -= 0.5; + _r += 0.5; + + switch (align) + { + case 0: + { + // top + double _top = (int)__y1 + 0.5; + _top = _top + pen_w / 2.0 - 0.5; + + m_pPath->Reset(); + m_pPath->MoveTo(_x, _top); + m_pPath->LineTo(_r, _top); + Stroke(); + break; + } + case 1: + { + // center + double _center = (int)__y1 + 0.5; + + m_pPath->Reset(); + if (0 == (pen_w % 2)) + { + m_pPath->MoveTo(_x, _center - 0.5); + m_pPath->LineTo(_r, _center - 0.5); + } + else + { + m_pPath->MoveTo(_x, _center); + m_pPath->LineTo(_r, _center); + } + Stroke(); + break; + } + case 2: + { + // bottom + double _bottom = (int)__y1 + 0.5; + _bottom = _bottom - pen_w / 2.0 + 0.5; + + m_pPath->Reset(); + m_pPath->MoveTo(_x, _bottom); + m_pPath->LineTo(_r, _bottom); + Stroke(); + break; + } + } + } }; #endif // _BUILD_GRAPHICS_RENDERER_H_ \ No newline at end of file diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index b67c49cc8c..dfe69fa9d1 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -218,7 +218,7 @@ public: //-------- Функции для вывода изображений --------------------------------------------------- virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) = 0; - virtual HRESULT DrawImageFromFile(const std::wstring&, const double& x, const double& y, const double& w, const double& h) = 0; + virtual HRESULT DrawImageFromFile(const std::wstring&, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255) = 0; // transform -------------------------------------------------------------------------------- virtual HRESULT SetTransform(const double& m1, const double& m2, const double& m3, const double& m4, const double& m5, const double& m6) = 0;