From 118a8e28783f42e089721eac4880f3b3f683e832 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 9 Feb 2017 10:16:07 -0500 Subject: Replace rect.Transform(matrix) with matrix.TransformRect(rect) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This Cl removes the rect based transform method which internally just called the matrix tranform method. The callers have been reversed to make it clearer the matrix is transforming the rect. Change-Id: I8ef57ccc2311e4e853b8180a6ff475f8eda2138e Reviewed-on: https://pdfium-review.googlesource.com/2572 Commit-Queue: dsinclair Reviewed-by: Nicolás Peña --- core/fpdfapi/font/cpdf_cidfont.cpp | 2 +- core/fpdfapi/font/cpdf_type3font.cpp | 2 +- core/fpdfapi/page/cpdf_contentparser.cpp | 6 ++++-- core/fpdfapi/page/cpdf_formobject.cpp | 2 +- core/fpdfapi/page/cpdf_imageobject.cpp | 6 ++++-- core/fpdfapi/page/cpdf_pathobject.cpp | 3 ++- core/fpdfapi/page/cpdf_streamcontentparser.cpp | 2 +- core/fpdfapi/render/cpdf_renderstatus.cpp | 8 +++++--- core/fpdfdoc/cpdf_annotlist.cpp | 6 +++--- core/fxcrt/fx_basic_coords.cpp | 10 ++++++---- core/fxcrt/fx_coordinates.h | 2 -- core/fxge/dib/fx_dib_transform.cpp | 2 +- core/fxge/ge/cfx_renderdevice.cpp | 3 ++- core/fxge/win32/cfx_psrenderer.cpp | 5 +++-- core/fxge/win32/fx_win32_device.cpp | 6 +++--- fpdfsdk/fpdfeditpage.cpp | 2 +- xfa/fxgraphics/cfx_graphics.cpp | 6 +++--- 17 files changed, 41 insertions(+), 32 deletions(-) diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp index e96f824bd5..a9ffbbdf71 100644 --- a/core/fpdfapi/font/cpdf_cidfont.cpp +++ b/core/fpdfapi/font/cpdf_cidfont.cpp @@ -488,7 +488,7 @@ FX_RECT CPDF_CIDFont::GetCharBBox(uint32_t charcode) { CIDTransformToFloat(pTransform[4]) * 1000, CIDTransformToFloat(pTransform[5]) * 1000); CFX_FloatRect rect_f(rect); - rect_f.Transform(&matrix); + matrix.TransformRect(rect_f); rect = rect_f.GetOuterRect(); } } diff --git a/core/fpdfapi/font/cpdf_type3font.cpp b/core/fpdfapi/font/cpdf_type3font.cpp index 9542945845..f6cd6ecf26 100644 --- a/core/fpdfapi/font/cpdf_type3font.cpp +++ b/core/fpdfapi/font/cpdf_type3font.cpp @@ -121,7 +121,7 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(uint32_t charcode) { if (rcBBox.right <= rcBBox.left || rcBBox.bottom >= rcBBox.top) char_rect = pNewChar->m_pForm->CalcBoundingBox(); - char_rect.Transform(&m_FontMatrix); + m_FontMatrix.TransformRect(char_rect); rcBBox.left = FXSYS_round(char_rect.left * 1000); rcBBox.right = FXSYS_round(char_rect.right * 1000); rcBBox.top = FXSYS_round(char_rect.top * 1000); diff --git a/core/fpdfapi/page/cpdf_contentparser.cpp b/core/fpdfapi/page/cpdf_contentparser.cpp index 1e0fe62e09..7f00eabb86 100644 --- a/core/fpdfapi/page/cpdf_contentparser.cpp +++ b/core/fpdfapi/page/cpdf_contentparser.cpp @@ -90,10 +90,12 @@ void CPDF_ContentParser::Start(CPDF_Form* pForm, ClipPath.Transform(&form_matrix); if (pParentMatrix) ClipPath.Transform(pParentMatrix); - form_bbox.Transform(&form_matrix); + + form_matrix.TransformRect(form_bbox); if (pParentMatrix) - form_bbox.Transform(pParentMatrix); + pParentMatrix->TransformRect(form_bbox); } + CPDF_Dictionary* pResources = pForm->m_pFormDict->GetDictFor("Resources"); m_pParser = pdfium::MakeUnique( pForm->m_pDocument, pForm->m_pPageResources, pForm->m_pResources, diff --git a/core/fpdfapi/page/cpdf_formobject.cpp b/core/fpdfapi/page/cpdf_formobject.cpp index dc596e53c6..5642a5dd01 100644 --- a/core/fpdfapi/page/cpdf_formobject.cpp +++ b/core/fpdfapi/page/cpdf_formobject.cpp @@ -35,7 +35,7 @@ CPDF_PageObject::Type CPDF_FormObject::GetType() const { void CPDF_FormObject::CalcBoundingBox() { CFX_FloatRect form_rect = m_pForm->CalcBoundingBox(); - form_rect.Transform(&m_FormMatrix); + m_FormMatrix.TransformRect(form_rect); m_Left = form_rect.left; m_Bottom = form_rect.bottom; m_Right = form_rect.right; diff --git a/core/fpdfapi/page/cpdf_imageobject.cpp b/core/fpdfapi/page/cpdf_imageobject.cpp index bb91820548..01d2df7421 100644 --- a/core/fpdfapi/page/cpdf_imageobject.cpp +++ b/core/fpdfapi/page/cpdf_imageobject.cpp @@ -41,8 +41,10 @@ const CPDF_ImageObject* CPDF_ImageObject::AsImage() const { } void CPDF_ImageObject::CalcBoundingBox() { - m_Left = m_Bottom = 0; - m_Right = m_Top = 1.0f; + m_Left = 0; + m_Bottom = 0; + m_Right = 1.0f; + m_Top = 1.0f; m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); } diff --git a/core/fpdfapi/page/cpdf_pathobject.cpp b/core/fpdfapi/page/cpdf_pathobject.cpp index 27c4535fa5..b5bb89390c 100644 --- a/core/fpdfapi/page/cpdf_pathobject.cpp +++ b/core/fpdfapi/page/cpdf_pathobject.cpp @@ -41,7 +41,8 @@ void CPDF_PathObject::CalcBoundingBox() { } else { rect = m_Path.GetBoundingBox(); } - rect.Transform(&m_Matrix); + m_Matrix.TransformRect(rect); + if (width == 0 && m_bStroke) { rect.left += -0.5f; rect.right += 0.5f; diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 28f3594f47..1fcb27a8c8 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -127,7 +127,7 @@ CFX_FloatRect GetShadingBBox(CPDF_ShadingPattern* pShading, if (bGouraud) stream.BitStream()->ByteAlign(); } - rect.Transform(&matrix); + matrix.TransformRect(rect); return rect; } diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index 1bdf4a0382..07987d616e 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp @@ -1860,7 +1860,8 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj, m_pDevice->RestoreState(false); } else { CFX_FloatRect rect_f = pType3Char->m_pForm->CalcBoundingBox(); - rect_f.Transform(&matrix); + matrix.TransformRect(rect_f); + FX_RECT rect = rect_f.GetOuterRect(); CFX_FxgeDevice bitmap_device; if (!bitmap_device.Create((int)(rect.Width() * sa), @@ -2038,7 +2039,7 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern, } if (pDict->KeyExist("BBox")) { CFX_FloatRect rect = pDict->GetRectFor("BBox"); - rect.Transform(pMatrix); + pMatrix->TransformRect(rect); clip_rect.Intersect(rect.GetOuterRect()); } if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SHADING && @@ -2204,8 +2205,9 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern, int min_col, max_col, min_row, max_row; CFX_Matrix mtDevice2Pattern; mtDevice2Pattern.SetReverse(mtPattern2Device); + CFX_FloatRect clip_box_p(clip_box); - clip_box_p.Transform(&mtDevice2Pattern); + mtDevice2Pattern.TransformRect(clip_box_p); min_col = (int)FXSYS_ceil((clip_box_p.left - pPattern->bbox().right) / pPattern->x_step()); diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp index b1bc4c9ca9..ed1b60c287 100644 --- a/core/fpdfdoc/cpdf_annotlist.cpp +++ b/core/fpdfdoc/cpdf_annotlist.cpp @@ -136,12 +136,12 @@ void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage, CFX_FloatRect annot_rect_f = pAnnot->GetRect(); CFX_Matrix matrix = *pMatrix; if (clip_rect) { - annot_rect_f.Transform(&matrix); + matrix.TransformRect(annot_rect_f); + FX_RECT annot_rect = annot_rect_f.GetOuterRect(); annot_rect.Intersect(*clip_rect); - if (annot_rect.IsEmpty()) { + if (annot_rect.IsEmpty()) continue; - } } if (pContext) { pAnnot->DrawInContext(pPage, pContext, &matrix, CPDF_Annot::Normal); diff --git a/core/fxcrt/fx_basic_coords.cpp b/core/fxcrt/fx_basic_coords.cpp index dc207901f6..2664b52e7e 100644 --- a/core/fxcrt/fx_basic_coords.cpp +++ b/core/fxcrt/fx_basic_coords.cpp @@ -105,9 +105,7 @@ void CFX_FloatRect::Union(const CFX_FloatRect& other_rect) { bottom = bottom < other.bottom ? bottom : other.bottom; top = top > other.top ? top : other.top; } -void CFX_FloatRect::Transform(const CFX_Matrix* pMatrix) { - pMatrix->TransformRect(left, right, top, bottom); -} + int CFX_FloatRect::Substract4(CFX_FloatRect& s, CFX_FloatRect* pRects) { Normalize(); s.Normalize(); @@ -374,7 +372,7 @@ void CFX_Matrix::GetUnitRect(CFX_RectF& rect) const { } CFX_FloatRect CFX_Matrix::GetUnitRect() const { CFX_FloatRect rect(0, 0, 1, 1); - rect.Transform((const CFX_Matrix*)this); + TransformRect(rect); return rect; } FX_FLOAT CFX_Matrix::GetUnitArea() const { @@ -434,23 +432,27 @@ void CFX_Matrix::TransformPoint(int32_t& x, int32_t& y) const { x = FXSYS_round(fx); y = FXSYS_round(fy); } + void CFX_Matrix::TransformRect(CFX_RectF& rect) const { FX_FLOAT right = rect.right(), bottom = rect.bottom(); TransformRect(rect.left, right, bottom, rect.top); rect.width = right - rect.left; rect.height = bottom - rect.top; } + void CFX_Matrix::TransformRect(CFX_Rect& rect) const { FX_FLOAT left = (FX_FLOAT)rect.left; FX_FLOAT top = (FX_FLOAT)rect.bottom(); FX_FLOAT right = (FX_FLOAT)rect.right(); FX_FLOAT bottom = (FX_FLOAT)rect.top; + TransformRect(left, right, top, bottom); rect.left = FXSYS_round(left); rect.top = FXSYS_round(bottom); rect.width = FXSYS_round(right - left); rect.height = FXSYS_round(top - bottom); } + void CFX_Matrix::TransformRect(FX_FLOAT& left, FX_FLOAT& right, FX_FLOAT& top, diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h index 01436c7250..4551a4a5c8 100644 --- a/core/fxcrt/fx_coordinates.h +++ b/core/fxcrt/fx_coordinates.h @@ -498,7 +498,6 @@ class CFX_FloatRect { bool Contains(const CFX_FloatRect& other_rect) const; bool Contains(FX_FLOAT x, FX_FLOAT y) const; - void Transform(const CFX_Matrix* pMatrix); void Intersect(const CFX_FloatRect& other_rect); void Union(const CFX_FloatRect& other_rect); @@ -701,7 +700,6 @@ class CFX_Matrix { FX_FLOAT GetE() const { return e; } FX_FLOAT GetF() const { return f; } - public: FX_FLOAT a; FX_FLOAT b; FX_FLOAT c; diff --git a/core/fxge/dib/fx_dib_transform.cpp b/core/fxge/dib/fx_dib_transform.cpp index 8932a633fa..55e8b8fa20 100644 --- a/core/fxge/dib/fx_dib_transform.cpp +++ b/core/fxge/dib/fx_dib_transform.cpp @@ -402,7 +402,7 @@ bool CFX_ImageTransformer::Start() { m_dest2stretch.SetReverse(stretch2dest); CFX_FloatRect clip_rect_f(result_clip); - clip_rect_f.Transform(&m_dest2stretch); + m_dest2stretch.TransformRect(clip_rect_f); m_StretchClip = clip_rect_f.GetOuterRect(); m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); m_Stretcher = pdfium::MakeUnique( diff --git a/core/fxge/ge/cfx_renderdevice.cpp b/core/fxge/ge/cfx_renderdevice.cpp index 15863e7611..52ed8c37c0 100644 --- a/core/fxge/ge/cfx_renderdevice.cpp +++ b/core/fxge/ge/cfx_renderdevice.cpp @@ -589,7 +589,8 @@ bool CFX_RenderDevice::DrawFillStrokePath(const CFX_PathData* pPathData, bbox = pPathData->GetBoundingBox(); } if (pObject2Device) - bbox.Transform(pObject2Device); + pObject2Device->TransformRect(bbox); + CFX_Matrix ctm = GetCTM(); FX_FLOAT fScaleX = FXSYS_fabs(ctm.a); FX_FLOAT fScaleY = FXSYS_fabs(ctm.d); diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp index 71e62a75f2..2e4519c46f 100644 --- a/core/fxge/win32/cfx_psrenderer.cpp +++ b/core/fxge/win32/cfx_psrenderer.cpp @@ -158,7 +158,8 @@ void CFX_PSRenderer::SetClip_PathFill(const CFX_PathData* pPathData, OutputPath(pPathData, pObject2Device); CFX_FloatRect rect = pPathData->GetBoundingBox(); if (pObject2Device) - rect.Transform(pObject2Device); + pObject2Device->TransformRect(rect); + m_ClipBox.left = static_cast(rect.left); m_ClipBox.right = static_cast(rect.left + rect.right); m_ClipBox.top = static_cast(rect.top + rect.bottom); @@ -185,7 +186,7 @@ void CFX_PSRenderer::SetClip_PathStroke(const CFX_PathData* pPathData, OutputPath(pPathData, nullptr); CFX_FloatRect rect = pPathData->GetBoundingBox(pGraphState->m_LineWidth, pGraphState->m_MiterLimit); - rect.Transform(pObject2Device); + pObject2Device->TransformRect(rect); m_ClipBox.Intersect(rect.GetOuterRect()); if (pObject2Device) { OUTPUT_PS("strokepath W n sm\n"); diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp index 223f64d041..c8ceacfc4c 100644 --- a/core/fxge/win32/fx_win32_device.cpp +++ b/core/fxge/win32/fx_win32_device.cpp @@ -996,9 +996,9 @@ bool CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData, if (!(pGraphState || stroke_color == 0) && !pPlatform->m_GdiplusExt.IsAvailable()) { CFX_FloatRect bbox_f = pPathData->GetBoundingBox(); - if (pMatrix) { - bbox_f.Transform(pMatrix); - } + if (pMatrix) + pMatrix->TransformRect(bbox_f); + FX_RECT bbox = bbox_f.GetInnerRect(); if (bbox.Width() <= 0) { return DrawCosmeticLine( diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index 18a1d61791..63740ba083 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -289,7 +289,7 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, (FX_FLOAT)e, (FX_FLOAT)f); - rect.Transform(&matrix); + matrix.TransformRect(rect); CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect"); if (!pRectArray) diff --git a/xfa/fxgraphics/cfx_graphics.cpp b/xfa/fxgraphics/cfx_graphics.cpp index bed7c36149..4a7041d144 100644 --- a/xfa/fxgraphics/cfx_graphics.cpp +++ b/xfa/fxgraphics/cfx_graphics.cpp @@ -1312,9 +1312,9 @@ FWL_Error CFX_Graphics::FillPathWithPattern(CFX_Path* path, 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) { - rectf.Transform(matrix); - } + if (matrix) + matrix->TransformRect(rectf); + FX_RECT rect(FXSYS_round(rectf.left), FXSYS_round(rectf.top), FXSYS_round(rectf.right), FXSYS_round(rectf.bottom)); CFX_FxgeDevice device; -- cgit v1.2.3