diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-07-17 12:05:40 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-07-17 16:22:56 +0000 |
commit | 0b7378afe3dee6db6cff8ee834e758d3a76efa3b (patch) | |
tree | 04ad09e12a5cbd33005194b3bf031c1d690e8ba8 /core/fxge | |
parent | d6aff2f2e8469344becd6f73e443c31bca9baac0 (diff) | |
download | pdfium-0b7378afe3dee6db6cff8ee834e758d3a76efa3b.tar.xz |
Move CPWL_Utils Draw methods to CFX_RenderDevice
This CL removes the drawing code from the AP stream generation code in
CPWL_Utils and places it in CFX_RenderDevice.
Change-Id: I5335fc38368740ba3ddc676ee856201a358979fc
Reviewed-on: https://pdfium-review.googlesource.com/7715
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxge')
-rw-r--r-- | core/fxge/cfx_renderdevice.cpp | 224 | ||||
-rw-r--r-- | core/fxge/cfx_renderdevice.h | 37 |
2 files changed, 261 insertions, 0 deletions
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp index 5d2ae86f2c..407c090c73 100644 --- a/core/fxge/cfx_renderdevice.cpp +++ b/core/fxge/cfx_renderdevice.cpp @@ -1115,6 +1115,230 @@ bool CFX_RenderDevice::DrawTextPath(int nChars, return true; } +void CFX_RenderDevice::DrawFillRect(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const FX_COLORREF& color) { + CFX_PathData path; + CFX_FloatRect rcTemp(rect); + path.AppendRect(rcTemp.left, rcTemp.bottom, rcTemp.right, rcTemp.top); + DrawPath(&path, pUser2Device, nullptr, color, 0, FXFILL_WINDING); +} + +void CFX_RenderDevice::DrawFillArea(CFX_Matrix* pUser2Device, + const CFX_PointF* pPts, + int32_t nCount, + const FX_COLORREF& color) { + CFX_PathData path; + path.AppendPoint(pPts[0], FXPT_TYPE::MoveTo, false); + for (int32_t i = 1; i < nCount; i++) + path.AppendPoint(pPts[i], FXPT_TYPE::LineTo, false); + + DrawPath(&path, pUser2Device, nullptr, color, 0, FXFILL_ALTERNATE); +} + +void CFX_RenderDevice::DrawStrokeRect(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const FX_COLORREF& color, + float fWidth) { + CFX_PathData path; + CFX_FloatRect rcTemp(rect); + path.AppendRect(rcTemp.left, rcTemp.bottom, rcTemp.right, rcTemp.top); + + CFX_GraphStateData gsd; + gsd.m_LineWidth = fWidth; + + DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE); +} + +void CFX_RenderDevice::DrawStrokeLine(CFX_Matrix* pUser2Device, + const CFX_PointF& ptMoveTo, + const CFX_PointF& ptLineTo, + const FX_COLORREF& color, + float fWidth) { + CFX_PathData path; + path.AppendPoint(ptMoveTo, FXPT_TYPE::MoveTo, false); + path.AppendPoint(ptLineTo, FXPT_TYPE::LineTo, false); + + CFX_GraphStateData gsd; + gsd.m_LineWidth = fWidth; + + DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE); +} + +void CFX_RenderDevice::DrawFillRect(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const CFX_Color& color, + int32_t nTransparency) { + DrawFillRect(pUser2Device, rect, color.ToFXColor(nTransparency)); +} + +void CFX_RenderDevice::DrawShadow(CFX_Matrix* pUser2Device, + bool bVertical, + bool bHorizontal, + CFX_FloatRect rect, + int32_t nTransparency, + int32_t nStartGray, + int32_t nEndGray) { + float fStepGray = 1.0f; + + if (bVertical) { + fStepGray = (nEndGray - nStartGray) / rect.Height(); + + for (float fy = rect.bottom + 0.5f; fy <= rect.top - 0.5f; fy += 1.0f) { + int32_t nGray = nStartGray + (int32_t)(fStepGray * (fy - rect.bottom)); + DrawStrokeLine(pUser2Device, CFX_PointF(rect.left, fy), + CFX_PointF(rect.right, fy), + ArgbEncode(nTransparency, nGray, nGray, nGray), 1.5f); + } + } + + if (bHorizontal) { + fStepGray = (nEndGray - nStartGray) / rect.Width(); + + for (float fx = rect.left + 0.5f; fx <= rect.right - 0.5f; fx += 1.0f) { + int32_t nGray = nStartGray + (int32_t)(fStepGray * (fx - rect.left)); + DrawStrokeLine(pUser2Device, CFX_PointF(fx, rect.bottom), + CFX_PointF(fx, rect.top), + ArgbEncode(nTransparency, nGray, nGray, nGray), 1.5f); + } + } +} + +void CFX_RenderDevice::DrawBorder(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + float fWidth, + const CFX_Color& color, + const CFX_Color& crLeftTop, + const CFX_Color& crRightBottom, + BorderStyle nStyle, + int32_t nTransparency) { + float fLeft = rect.left; + float fRight = rect.right; + float fTop = rect.top; + float fBottom = rect.bottom; + + if (fWidth > 0.0f) { + float fHalfWidth = fWidth / 2.0f; + + switch (nStyle) { + default: + case BorderStyle::SOLID: { + CFX_PathData path; + path.AppendRect(fLeft, fBottom, fRight, fTop); + path.AppendRect(fLeft + fWidth, fBottom + fWidth, fRight - fWidth, + fTop - fWidth); + DrawPath(&path, pUser2Device, nullptr, color.ToFXColor(nTransparency), + 0, FXFILL_ALTERNATE); + break; + } + case BorderStyle::DASH: { + CFX_PathData path; + path.AppendPoint( + CFX_PointF(fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f), + FXPT_TYPE::MoveTo, false); + path.AppendPoint( + CFX_PointF(fLeft + fWidth / 2.0f, fTop - fWidth / 2.0f), + FXPT_TYPE::LineTo, false); + path.AppendPoint( + CFX_PointF(fRight - fWidth / 2.0f, fTop - fWidth / 2.0f), + FXPT_TYPE::LineTo, false); + path.AppendPoint( + CFX_PointF(fRight - fWidth / 2.0f, fBottom + fWidth / 2.0f), + FXPT_TYPE::LineTo, false); + path.AppendPoint( + CFX_PointF(fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f), + FXPT_TYPE::LineTo, false); + + CFX_GraphStateData gsd; + gsd.SetDashCount(2); + gsd.m_DashArray[0] = 3.0f; + gsd.m_DashArray[1] = 3.0f; + gsd.m_DashPhase = 0; + + gsd.m_LineWidth = fWidth; + DrawPath(&path, pUser2Device, &gsd, 0, color.ToFXColor(nTransparency), + FXFILL_WINDING); + break; + } + case BorderStyle::BEVELED: + case BorderStyle::INSET: { + CFX_GraphStateData gsd; + gsd.m_LineWidth = fHalfWidth; + + CFX_PathData pathLT; + + pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), + FXPT_TYPE::MoveTo, false); + pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fTop - fHalfWidth), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint( + CFX_PointF(fRight - fHalfWidth * 2, fTop - fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint( + CFX_PointF(fLeft + fHalfWidth * 2, fTop - fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint( + CFX_PointF(fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), + FXPT_TYPE::LineTo, false); + + DrawPath(&pathLT, pUser2Device, &gsd, + crLeftTop.ToFXColor(nTransparency), 0, FXFILL_ALTERNATE); + + CFX_PathData pathRB; + pathRB.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), + FXPT_TYPE::MoveTo, false); + pathRB.AppendPoint( + CFX_PointF(fRight - fHalfWidth, fBottom + fHalfWidth), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint( + CFX_PointF(fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint( + CFX_PointF(fRight - fHalfWidth * 2, fBottom + fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint( + CFX_PointF(fRight - fHalfWidth * 2, fTop - fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), + FXPT_TYPE::LineTo, false); + + DrawPath(&pathRB, pUser2Device, &gsd, + crRightBottom.ToFXColor(nTransparency), 0, FXFILL_ALTERNATE); + + CFX_PathData path; + + path.AppendRect(fLeft, fBottom, fRight, fTop); + path.AppendRect(fLeft + fHalfWidth, fBottom + fHalfWidth, + fRight - fHalfWidth, fTop - fHalfWidth); + + DrawPath(&path, pUser2Device, &gsd, color.ToFXColor(nTransparency), 0, + FXFILL_ALTERNATE); + break; + } + case BorderStyle::UNDERLINE: { + CFX_PathData path; + path.AppendPoint(CFX_PointF(fLeft, fBottom + fWidth / 2), + FXPT_TYPE::MoveTo, false); + path.AppendPoint(CFX_PointF(fRight, fBottom + fWidth / 2), + FXPT_TYPE::LineTo, false); + + CFX_GraphStateData gsd; + gsd.m_LineWidth = fWidth; + + DrawPath(&path, pUser2Device, &gsd, 0, color.ToFXColor(nTransparency), + FXFILL_ALTERNATE); + break; + } + } + } +} + CFX_RenderDevice::StateRestorer::StateRestorer(CFX_RenderDevice* pDevice) : m_pDevice(pDevice) { m_pDevice->SaveState(); diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h index 83c45f9528..ef15718d58 100644 --- a/core/fxge/cfx_renderdevice.h +++ b/core/fxge/cfx_renderdevice.h @@ -10,6 +10,7 @@ #include <memory> #include "core/fxcrt/cfx_unowned_ptr.h" +#include "core/fxge/cfx_color.h" #include "core/fxge/fx_dib.h" #include "core/fxge/fx_font.h" @@ -227,6 +228,42 @@ class CFX_RenderDevice { CFX_PathData* pClippingPath, int nFlag); + void DrawFillRect(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const CFX_Color& color, + int32_t nTransparency); + void DrawFillRect(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const FX_COLORREF& color); + void DrawStrokeRect(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const FX_COLORREF& color, + float fWidth); + void DrawStrokeLine(CFX_Matrix* pUser2Device, + const CFX_PointF& ptMoveTo, + const CFX_PointF& ptLineTo, + const FX_COLORREF& color, + float fWidth); + void DrawBorder(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + float fWidth, + const CFX_Color& color, + const CFX_Color& crLeftTop, + const CFX_Color& crRightBottom, + BorderStyle nStyle, + int32_t nTransparency); + void DrawFillArea(CFX_Matrix* pUser2Device, + const CFX_PointF* pPts, + int32_t nCount, + const FX_COLORREF& color); + void DrawShadow(CFX_Matrix* pUser2Device, + bool bVertical, + bool bHorizontal, + CFX_FloatRect rect, + int32_t nTransparency, + int32_t nStartGray, + int32_t nEndGray); + #ifdef _SKIA_SUPPORT_ virtual void DebugVerifyBitmapIsPreMultiplied() const; virtual bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, |