summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-06-29 12:02:06 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-06-29 20:50:09 +0000
commitb21f174ad87e46c823c2ef8c11682167e2d12864 (patch)
tree79c3661672cbd2f84ee835f9922231bb90a634b3 /core
parent8ce58f522e046ae3b1561d592ca7b3cd7c894731 (diff)
downloadpdfium-b21f174ad87e46c823c2ef8c11682167e2d12864.tar.xz
Change SetReverse to GetInverse in CFX_Matrix
CFX_Matrix::GetInverse is much clearer. Change-Id: Id10ab1723735332e1a78de853f28415ec3a4d834 Reviewed-on: https://pdfium-review.googlesource.com/7090 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Nicolás Peña <npm@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp7
-rw-r--r--core/fpdfapi/render/cpdf_progressiverenderer.cpp4
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp23
-rw-r--r--core/fpdftext/cpdf_textpage.cpp8
-rw-r--r--core/fxcrt/fx_coordinates.cpp24
-rw-r--r--core/fxcrt/fx_coordinates.h2
-rw-r--r--core/fxcrt/fx_coordinates_unittest.cpp14
-rw-r--r--core/fxge/agg/fx_agg_driver.cpp4
-rw-r--r--core/fxge/dib/cfx_imagetransformer.cpp3
9 files changed, 32 insertions, 57 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index 10b3933742..369c2a81ff 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -68,11 +68,8 @@ void CPDF_PageContentGenerator::GenerateContent() {
// Set the default graphic state values
buf << "q\n";
- if (!m_pObjHolder->GetLastCTM().IsIdentity()) {
- CFX_Matrix reverse;
- reverse.SetReverse(m_pObjHolder->GetLastCTM());
- buf << reverse << " cm\n";
- }
+ if (!m_pObjHolder->GetLastCTM().IsIdentity())
+ buf << m_pObjHolder->GetLastCTM().GetInverse() << " cm\n";
ProcessDefaultGraphics(&buf);
// Process the page objects
diff --git a/core/fpdfapi/render/cpdf_progressiverenderer.cpp b/core/fpdfapi/render/cpdf_progressiverenderer.cpp
index 984ad75834..4ddc528342 100644
--- a/core/fpdfapi/render/cpdf_progressiverenderer.cpp
+++ b/core/fpdfapi/render/cpdf_progressiverenderer.cpp
@@ -60,9 +60,7 @@ void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) {
nullptr);
m_pDevice->SaveState();
m_ClipRect = CFX_FloatRect(m_pDevice->GetClipBox());
- CFX_Matrix device2object;
- device2object.SetReverse(m_pCurrentLayer->m_Matrix);
- device2object.TransformRect(m_ClipRect);
+ m_pCurrentLayer->m_Matrix.GetInverse().TransformRect(m_ClipRect);
}
CPDF_PageObjectList::iterator iter;
CPDF_PageObjectList::iterator iterEnd =
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index beeca3febe..a3b1bb8567 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -133,8 +133,6 @@ void DrawAxialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
float x_span = end_x - start_x;
float y_span = end_y - start_y;
float axis_len_square = (x_span * x_span) + (y_span * y_span);
- CFX_Matrix matrix;
- matrix.SetReverse(*pObject2Bitmap);
uint32_t total_results =
std::max(CountOutputs(funcs), pCS->CountComponents());
CFX_FixedBufGrow<float, 16> result_array(total_results);
@@ -160,6 +158,7 @@ void DrawAxialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
FXSYS_round(G * 255), FXSYS_round(B * 255)));
}
int pitch = pBitmap->GetPitch();
+ CFX_Matrix matrix = pObject2Bitmap->GetInverse();
for (int row = 0; row < height; row++) {
uint32_t* dib_buf = (uint32_t*)(pBitmap->GetBuffer() + row * pitch);
for (int column = 0; column < width; column++) {
@@ -202,8 +201,6 @@ void DrawRadialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
float end_x = pCoords->GetNumberAt(3);
float end_y = pCoords->GetNumberAt(4);
float end_r = pCoords->GetNumberAt(5);
- CFX_Matrix matrix;
- matrix.SetReverse(*pObject2Bitmap);
float t_min = 0;
float t_max = 1.0f;
CPDF_Array* pArray = pDict->GetArrayFor("Domain");
@@ -256,6 +253,7 @@ void DrawRadialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
bDecreasing = true;
}
}
+ CFX_Matrix matrix = pObject2Bitmap->GetInverse();
for (int row = 0; row < height; row++) {
uint32_t* dib_buf = (uint32_t*)(pBitmap->GetBuffer() + row * pitch);
for (int column = 0; column < width; column++) {
@@ -334,12 +332,8 @@ void DrawFuncShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
ymax = pDomain->GetNumberAt(3);
}
CFX_Matrix mtDomain2Target = pDict->GetMatrixFor("Matrix");
- CFX_Matrix matrix;
- matrix.SetReverse(*pObject2Bitmap);
-
- CFX_Matrix reverse_matrix;
- reverse_matrix.SetReverse(mtDomain2Target);
- matrix.Concat(reverse_matrix);
+ CFX_Matrix matrix = pObject2Bitmap->GetInverse();
+ matrix.Concat(mtDomain2Target.GetInverse());
int width = pBitmap->GetWidth();
int height = pBitmap->GetHeight();
int pitch = pBitmap->GetPitch();
@@ -1056,9 +1050,7 @@ void CPDF_RenderStatus::RenderObjectList(
DebugVerifyDeviceIsPreMultiplied();
#endif
CFX_FloatRect clip_rect(m_pDevice->GetClipBox());
- CFX_Matrix device2object;
- device2object.SetReverse(*pObj2Device);
- device2object.TransformRect(clip_rect);
+ pObj2Device->GetInverse().TransformRect(clip_rect);
for (const auto& pCurObj : *pObjectHolder->GetPageObjectList()) {
if (pCurObj.get() == m_pStopObj) {
@@ -2243,11 +2235,8 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
if (height == 0)
height = 1;
- CFX_Matrix mtDevice2Pattern;
- mtDevice2Pattern.SetReverse(mtPattern2Device);
-
CFX_FloatRect clip_box_p(clip_box);
- mtDevice2Pattern.TransformRect(clip_box_p);
+ mtPattern2Device.GetInverse().TransformRect(clip_box_p);
int min_col = (int)ceil((clip_box_p.left - pPattern->bbox().right) /
pPattern->x_step());
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index b8860122f1..b6b3a0dbce 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -264,10 +264,7 @@ std::vector<CFX_FloatRect> CPDF_TextPage::GetRectArray(int start,
CFX_Matrix matrix = info_curchar.m_pTextObj->GetTextMatrix();
matrix.Concat(info_curchar.m_Matrix);
- CFX_Matrix matrix_reverse;
- matrix_reverse.SetReverse(matrix);
-
- CFX_PointF origin = matrix_reverse.Transform(info_curchar.m_Origin);
+ CFX_PointF origin = matrix.GetInverse().Transform(info_curchar.m_Origin);
rect.left = info_curchar.m_CharBox.left;
rect.right = info_curchar.m_CharBox.right;
if (pCurObj->GetFont()->GetTypeDescent()) {
@@ -1306,8 +1303,7 @@ CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject(
CFX_Matrix prev_matrix = m_pPreTextObj->GetTextMatrix();
prev_matrix.Concat(m_perMatrix);
- CFX_Matrix prev_reverse;
- prev_reverse.SetReverse(prev_matrix);
+ CFX_Matrix prev_reverse = prev_matrix.GetInverse();
CFX_PointF pos = prev_reverse.Transform(formMatrix.Transform(pObj->GetPos()));
if (last_width < this_width)
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index 27c0a95ee4..0b6aed44cc 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -197,18 +197,20 @@ CFX_FloatRect CFX_FloatRect::GetBBox(const CFX_PointF* pPoints, int nPoints) {
return CFX_FloatRect(min_x, min_y, max_x, max_y);
}
-void CFX_Matrix::SetReverse(const CFX_Matrix& m) {
- float i = m.a * m.d - m.b * m.c;
+CFX_Matrix CFX_Matrix::GetInverse() const {
+ CFX_Matrix inverse;
+ float i = a * d - b * c;
if (fabs(i) == 0)
- return;
+ return inverse;
float j = -i;
- a = m.d / i;
- b = m.b / j;
- c = m.c / j;
- d = m.a / i;
- e = (m.c * m.f - m.d * m.e) / i;
- f = (m.a * m.f - m.b * m.e) / j;
+ inverse.a = d / i;
+ inverse.b = b / j;
+ inverse.c = c / j;
+ inverse.d = a / i;
+ inverse.e = (c * f - d * e) / i;
+ inverse.f = (a * f - b * e) / j;
+ return inverse;
}
void CFX_Matrix::Concat(const CFX_Matrix& m, bool bPrepended) {
@@ -216,9 +218,7 @@ void CFX_Matrix::Concat(const CFX_Matrix& m, bool bPrepended) {
}
void CFX_Matrix::ConcatInverse(const CFX_Matrix& src, bool bPrepended) {
- CFX_Matrix m;
- m.SetReverse(src);
- Concat(m, bPrepended);
+ Concat(src.GetInverse(), bPrepended);
}
bool CFX_Matrix::Is90Rotated() const {
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h
index fc51c458a0..25923f7290 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -608,7 +608,7 @@ class CFX_Matrix {
f = 0;
}
- void SetReverse(const CFX_Matrix& m);
+ CFX_Matrix GetInverse() const;
void Concat(const CFX_Matrix& m, bool bPrepended = false);
void ConcatInverse(const CFX_Matrix& m, bool bPrepended = false);
diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp
index 12ddb97330..e998b440f5 100644
--- a/core/fxcrt/fx_coordinates_unittest.cpp
+++ b/core/fxcrt/fx_coordinates_unittest.cpp
@@ -8,10 +8,9 @@
TEST(CFX_Matrix, ReverseIdentity) {
CFX_Matrix m;
- CFX_Matrix rev;
-
m.SetIdentity();
- rev.SetReverse(m);
+ CFX_Matrix rev = m.GetInverse();
+
EXPECT_FLOAT_EQ(1.0, rev.a);
EXPECT_FLOAT_EQ(0.0, rev.b);
EXPECT_FLOAT_EQ(0.0, rev.c);
@@ -28,9 +27,8 @@ TEST(CFX_Matrix, ReverseIdentity) {
TEST(CFX_Matrix, Reverse) {
float data[6] = {3, 0, 2, 3, 1, 4};
CFX_Matrix m(data);
- CFX_Matrix rev;
+ CFX_Matrix rev = m.GetInverse();
- rev.SetReverse(m);
EXPECT_FLOAT_EQ(0.33333334f, rev.a);
EXPECT_FLOAT_EQ(0.0f, rev.b);
EXPECT_FLOAT_EQ(-0.22222222f, rev.c);
@@ -50,9 +48,8 @@ TEST(CFX_Matrix, ReverseCR702041) {
float data[6] = {0.947368443f, -0.108947366f, -0.923076928f,
0.106153846f, 18.0f, 787.929993f};
CFX_Matrix m(data);
- CFX_Matrix rev;
+ CFX_Matrix rev = m.GetInverse();
- rev.SetReverse(m);
EXPECT_FLOAT_EQ(14247728.0f, rev.a);
EXPECT_FLOAT_EQ(14622668.0f, rev.b);
EXPECT_FLOAT_EQ(1.2389329e+08f, rev.c);
@@ -71,9 +68,8 @@ TEST(CFX_Matrix, ReverseCR714187) {
// The determinate is < std::numeric_limits<float>::epsilon()
float data[6] = {0.000037f, 0.0f, 0.0f, -0.000037f, 182.413101f, 136.977646f};
CFX_Matrix m(data);
- CFX_Matrix rev;
+ CFX_Matrix rev = m.GetInverse();
- rev.SetReverse(m);
EXPECT_FLOAT_EQ(27027.025f, rev.a);
EXPECT_FLOAT_EQ(0.0f, rev.b);
EXPECT_FLOAT_EQ(0.0f, rev.c);
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index 22d80071a9..91272d4427 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -1349,10 +1349,8 @@ bool CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData,
pObject2Device->a / matrix1.a, pObject2Device->b / matrix1.a,
pObject2Device->c / matrix1.d, pObject2Device->d / matrix1.d, 0, 0);
- CFX_Matrix mtRervese;
- mtRervese.SetReverse(matrix2);
matrix1 = *pObject2Device;
- matrix1.Concat(mtRervese);
+ matrix1.Concat(matrix2.GetInverse());
}
CAgg_PathData path_data;
diff --git a/core/fxge/dib/cfx_imagetransformer.cpp b/core/fxge/dib/cfx_imagetransformer.cpp
index 6174a51c29..2fb21e4c33 100644
--- a/core/fxge/dib/cfx_imagetransformer.cpp
+++ b/core/fxge/dib/cfx_imagetransformer.cpp
@@ -235,7 +235,8 @@ bool CFX_ImageTransformer::Start() {
CFX_Matrix(m_pMatrix->a / stretch_width, m_pMatrix->b / stretch_width,
m_pMatrix->c / stretch_height, m_pMatrix->d / stretch_height,
m_pMatrix->e, m_pMatrix->f));
- m_dest2stretch.SetReverse(stretch2dest);
+ ASSERT(m_dest2stretch.IsIdentity());
+ m_dest2stretch = stretch2dest.GetInverse();
CFX_FloatRect clip_rect_f(result_clip);
m_dest2stretch.TransformRect(clip_rect_f);