diff options
Diffstat (limited to 'xfa/fxgraphics')
-rw-r--r-- | xfa/fxgraphics/cfx_graphics.cpp | 74 | ||||
-rw-r--r-- | xfa/fxgraphics/cfx_graphics.h | 7 |
2 files changed, 42 insertions, 39 deletions
diff --git a/xfa/fxgraphics/cfx_graphics.cpp b/xfa/fxgraphics/cfx_graphics.cpp index 48d8f6f80f..3cfe2d0192 100644 --- a/xfa/fxgraphics/cfx_graphics.cpp +++ b/xfa/fxgraphics/cfx_graphics.cpp @@ -198,7 +198,7 @@ void CFX_Graphics::FillPath(CFX_Path* path, RenderDeviceFillPath(path, fillMode, matrix); } -void CFX_Graphics::StretchImage(CFX_DIBSource* source, +void CFX_Graphics::StretchImage(const CFX_RetainPtr<CFX_DIBSource>& source, const CFX_RectF& rect, CFX_Matrix* matrix) { if (!source) @@ -318,48 +318,49 @@ void CFX_Graphics::RenderDeviceFillPath(CFX_Path* path, } } -void CFX_Graphics::RenderDeviceStretchImage(CFX_DIBSource* source, - const CFX_RectF& rect, - CFX_Matrix* matrix) { +void CFX_Graphics::RenderDeviceStretchImage( + const CFX_RetainPtr<CFX_DIBSource>& source, + const CFX_RectF& rect, + CFX_Matrix* matrix) { CFX_Matrix m1(m_info.CTM.a, m_info.CTM.b, m_info.CTM.c, m_info.CTM.d, m_info.CTM.e, m_info.CTM.f); if (matrix) { m1.Concat(*matrix); } - std::unique_ptr<CFX_DIBitmap> bmp1 = + CFX_RetainPtr<CFX_DIBitmap> bmp1 = source->StretchTo((int32_t)rect.Width(), (int32_t)rect.Height()); CFX_Matrix m2(rect.Width(), 0.0, 0.0, rect.Height(), rect.left, rect.top); m2.Concat(m1); int32_t left; int32_t top; - std::unique_ptr<CFX_DIBitmap> bmp2 = bmp1->FlipImage(false, true); - std::unique_ptr<CFX_DIBitmap> bmp3 = bmp2->TransformTo(&m2, left, top); + CFX_RetainPtr<CFX_DIBitmap> bmp2 = bmp1->FlipImage(false, true); + CFX_RetainPtr<CFX_DIBitmap> bmp3 = bmp2->TransformTo(&m2, left, top); CFX_RectF r = GetClipRect(); - CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap(); + CFX_RetainPtr<CFX_DIBitmap> bitmap = m_renderDevice->GetBitmap(); bitmap->CompositeBitmap(FXSYS_round(r.left), FXSYS_round(r.top), - FXSYS_round(r.Width()), FXSYS_round(r.Height()), - bmp3.get(), FXSYS_round(r.left - left), - FXSYS_round(r.top - top)); + FXSYS_round(r.Width()), FXSYS_round(r.Height()), bmp3, + FXSYS_round(r.left - left), FXSYS_round(r.top - top)); } void CFX_Graphics::FillPathWithPattern(CFX_Path* path, FX_FillMode fillMode, CFX_Matrix* matrix) { CFX_Pattern* pattern = m_info.fillColor->m_info.pattern; - CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap(); + CFX_RetainPtr<CFX_DIBitmap> bitmap = m_renderDevice->GetBitmap(); int32_t width = bitmap->GetWidth(); int32_t height = bitmap->GetHeight(); - CFX_DIBitmap bmp; - bmp.Create(width, height, FXDIB_Argb); - m_renderDevice->GetDIBits(&bmp, 0, 0); + auto bmp = pdfium::MakeRetain<CFX_DIBitmap>(); + bmp->Create(width, height, FXDIB_Argb); + m_renderDevice->GetDIBits(bmp, 0, 0); FX_HatchStyle hatchStyle = m_info.fillColor->m_info.pattern->m_hatchStyle; const FX_HATCHDATA& data = hatchBitmapData[static_cast<int>(hatchStyle)]; - CFX_DIBitmap mask; - mask.Create(data.width, data.height, FXDIB_1bppMask); - FXSYS_memcpy(mask.GetBuffer(), data.maskBits, mask.GetPitch() * data.height); + auto mask = pdfium::MakeRetain<CFX_DIBitmap>(); + mask->Create(data.width, data.height, FXDIB_1bppMask); + FXSYS_memcpy(mask->GetBuffer(), data.maskBits, + mask->GetPitch() * data.height); CFX_FloatRect rectf = path->GetPathData()->GetBoundingBox(); if (matrix) matrix->TransformRect(rectf); @@ -367,35 +368,35 @@ void CFX_Graphics::FillPathWithPattern(CFX_Path* path, FX_RECT rect(FXSYS_round(rectf.left), FXSYS_round(rectf.top), FXSYS_round(rectf.right), FXSYS_round(rectf.bottom)); CFX_FxgeDevice device; - device.Attach(&bmp, false, nullptr, false); + device.Attach(bmp, false, nullptr, false); device.FillRect(&rect, m_info.fillColor->m_info.pattern->m_backArgb); - for (int32_t j = rect.bottom; j < rect.top; j += mask.GetHeight()) { - for (int32_t i = rect.left; i < rect.right; i += mask.GetWidth()) { - device.SetBitMask(&mask, i, j, + for (int32_t j = rect.bottom; j < rect.top; j += mask->GetHeight()) { + for (int32_t i = rect.left; i < rect.right; i += mask->GetWidth()) { + device.SetBitMask(mask, i, j, m_info.fillColor->m_info.pattern->m_foreArgb); } } m_renderDevice->SaveState(); m_renderDevice->SetClip_PathFill(path->GetPathData(), matrix, fillMode); - SetDIBitsWithMatrix(&bmp, &pattern->m_matrix); + SetDIBitsWithMatrix(bmp, &pattern->m_matrix); m_renderDevice->RestoreState(false); } void CFX_Graphics::FillPathWithShading(CFX_Path* path, FX_FillMode fillMode, CFX_Matrix* matrix) { - CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap(); + CFX_RetainPtr<CFX_DIBitmap> bitmap = m_renderDevice->GetBitmap(); int32_t width = bitmap->GetWidth(); int32_t height = bitmap->GetHeight(); float start_x = m_info.fillColor->m_shading->m_beginPoint.x; float start_y = m_info.fillColor->m_shading->m_beginPoint.y; float end_x = m_info.fillColor->m_shading->m_endPoint.x; float end_y = m_info.fillColor->m_shading->m_endPoint.y; - CFX_DIBitmap bmp; - bmp.Create(width, height, FXDIB_Argb); - m_renderDevice->GetDIBits(&bmp, 0, 0); - int32_t pitch = bmp.GetPitch(); + auto bmp = pdfium::MakeRetain<CFX_DIBitmap>(); + bmp->Create(width, height, FXDIB_Argb); + m_renderDevice->GetDIBits(bmp, 0, 0); + int32_t pitch = bmp->GetPitch(); bool result = false; switch (m_info.fillColor->m_shading->m_type) { case FX_SHADING_Axial: { @@ -403,7 +404,7 @@ void CFX_Graphics::FillPathWithShading(CFX_Path* path, float y_span = end_y - start_y; float axis_len_square = (x_span * x_span) + (y_span * y_span); for (int32_t row = 0; row < height; row++) { - uint32_t* dib_buf = (uint32_t*)(bmp.GetBuffer() + row * pitch); + uint32_t* dib_buf = (uint32_t*)(bmp->GetBuffer() + row * pitch); for (int32_t column = 0; column < width; column++) { float x = (float)(column); float y = (float)(row); @@ -434,7 +435,7 @@ void CFX_Graphics::FillPathWithShading(CFX_Path* path, ((start_y - end_y) * (start_y - end_y)) - ((start_r - end_r) * (start_r - end_r)); for (int32_t row = 0; row < height; row++) { - uint32_t* dib_buf = (uint32_t*)(bmp.GetBuffer() + row * pitch); + uint32_t* dib_buf = (uint32_t*)(bmp->GetBuffer() + row * pitch); for (int32_t column = 0; column < width; column++) { float x = (float)(column); float y = (float)(row); @@ -496,13 +497,14 @@ void CFX_Graphics::FillPathWithShading(CFX_Path* path, if (result) { m_renderDevice->SaveState(); m_renderDevice->SetClip_PathFill(path->GetPathData(), matrix, fillMode); - SetDIBitsWithMatrix(&bmp, matrix); + SetDIBitsWithMatrix(bmp, matrix); m_renderDevice->RestoreState(false); } } -void CFX_Graphics::SetDIBitsWithMatrix(CFX_DIBSource* source, - CFX_Matrix* matrix) { +void CFX_Graphics::SetDIBitsWithMatrix( + const CFX_RetainPtr<CFX_DIBSource>& source, + CFX_Matrix* matrix) { if (matrix->IsIdentity()) { m_renderDevice->SetDIBits(source, 0, 0); } else { @@ -511,9 +513,9 @@ void CFX_Graphics::SetDIBitsWithMatrix(CFX_DIBSource* source, m.Concat(*matrix); int32_t left; int32_t top; - std::unique_ptr<CFX_DIBitmap> bmp1 = source->FlipImage(false, true); - std::unique_ptr<CFX_DIBitmap> bmp2 = bmp1->TransformTo(&m, left, top); - m_renderDevice->SetDIBits(bmp2.get(), left, top); + CFX_RetainPtr<CFX_DIBitmap> bmp1 = source->FlipImage(false, true); + CFX_RetainPtr<CFX_DIBitmap> bmp2 = bmp1->TransformTo(&m, left, top); + m_renderDevice->SetDIBits(bmp2, left, top); } } diff --git a/xfa/fxgraphics/cfx_graphics.h b/xfa/fxgraphics/cfx_graphics.h index c360813401..264ec94d53 100644 --- a/xfa/fxgraphics/cfx_graphics.h +++ b/xfa/fxgraphics/cfx_graphics.h @@ -64,7 +64,7 @@ class CFX_Graphics { void FillPath(CFX_Path* path, FX_FillMode fillMode = FXFILL_WINDING, CFX_Matrix* matrix = nullptr); - void StretchImage(CFX_DIBSource* source, + void StretchImage(const CFX_RetainPtr<CFX_DIBSource>& source, const CFX_RectF& rect, CFX_Matrix* matrix = nullptr); void ConcatMatrix(const CFX_Matrix* matrix); @@ -90,7 +90,7 @@ class CFX_Graphics { void RenderDeviceFillPath(CFX_Path* path, FX_FillMode fillMode, CFX_Matrix* matrix); - void RenderDeviceStretchImage(CFX_DIBSource* source, + void RenderDeviceStretchImage(const CFX_RetainPtr<CFX_DIBSource>& source, const CFX_RectF& rect, CFX_Matrix* matrix); @@ -101,7 +101,8 @@ class CFX_Graphics { FX_FillMode fillMode, CFX_Matrix* matrix); - void SetDIBitsWithMatrix(CFX_DIBSource* source, CFX_Matrix* matrix); + void SetDIBitsWithMatrix(const CFX_RetainPtr<CFX_DIBSource>& source, + CFX_Matrix* matrix); CFX_RenderDevice* m_renderDevice; std::vector<std::unique_ptr<TInfo>> m_infoStack; |