summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-10-24 17:56:26 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-24 17:56:26 +0000
commit02d42b65b779e29737275a258cb9f30fa8449e5e (patch)
tree12e2b27d3883378315ab32efb1d5b86359783494
parent866d688766dbfc01d69f586bfa197d57df0d9b96 (diff)
downloadpdfium-chromium/3591.tar.xz
Add CFX_Matrix::AsTuple().chromium/3591
Change-Id: I53c1b148cb8cdc77461766fc9996a0a3ce5f4cb7 Reviewed-on: https://pdfium-review.googlesource.com/c/44536 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
-rw-r--r--core/fxcrt/fx_coordinates.cpp5
-rw-r--r--core/fxcrt/fx_coordinates.h5
-rw-r--r--core/fxcrt/fx_coordinates_unittest.cpp35
-rw-r--r--fpdfsdk/fpdf_editimg.cpp10
-rw-r--r--fpdfsdk/fpdf_editpage.cpp8
-rw-r--r--fpdfsdk/fpdf_editpath.cpp8
-rw-r--r--fpdfsdk/fpdf_edittext.cpp9
7 files changed, 38 insertions, 42 deletions
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index 7d0d104122..fabde1e80b 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -300,6 +300,11 @@ std::ostream& operator<<(std::ostream& os, const CFX_RectF& rect) {
}
#endif // NDEBUG
+std::tuple<float, float, float, float, float, float> CFX_Matrix::AsTuple()
+ const {
+ return {a, b, c, d, e, f};
+}
+
CFX_Matrix CFX_Matrix::GetInverse() const {
CFX_Matrix inverse;
float i = a * d - b * c;
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h
index 08dbd08903..67d3736fd8 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -8,12 +8,11 @@
#define CORE_FXCRT_FX_COORDINATES_H_
#include <algorithm>
+#include <tuple>
#include "core/fxcrt/fx_system.h"
#include "third_party/base/numerics/safe_math.h"
-class CFX_Matrix;
-
template <class BaseType>
class CFX_PTemplate {
public:
@@ -541,6 +540,8 @@ class CFX_Matrix {
f = other.f;
}
+ std::tuple<float, float, float, float, float, float> AsTuple() const;
+
void SetIdentity() {
a = 1;
b = 0;
diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp
index 3d11748649..ded4d45c9d 100644
--- a/core/fxcrt/fx_coordinates_unittest.cpp
+++ b/core/fxcrt/fx_coordinates_unittest.cpp
@@ -248,27 +248,38 @@ TEST(CFX_Matrix, ReverseIdentity) {
TEST(CFX_Matrix, SetIdentity) {
CFX_Matrix m;
- EXPECT_FLOAT_EQ(1.0, m.a);
- EXPECT_FLOAT_EQ(0.0, m.b);
- EXPECT_FLOAT_EQ(0.0, m.c);
- EXPECT_FLOAT_EQ(1.0, m.d);
- EXPECT_FLOAT_EQ(0.0, m.e);
- EXPECT_FLOAT_EQ(0.0, m.f);
+ EXPECT_FLOAT_EQ(1.0f, m.a);
+ EXPECT_FLOAT_EQ(0.0f, m.b);
+ EXPECT_FLOAT_EQ(0.0f, m.c);
+ EXPECT_FLOAT_EQ(1.0f, m.d);
+ EXPECT_FLOAT_EQ(0.0f, m.e);
+ EXPECT_FLOAT_EQ(0.0f, m.f);
EXPECT_TRUE(m.IsIdentity());
m.a = -1;
EXPECT_FALSE(m.IsIdentity());
m.SetIdentity();
- EXPECT_FLOAT_EQ(1.0, m.a);
- EXPECT_FLOAT_EQ(0.0, m.b);
- EXPECT_FLOAT_EQ(0.0, m.c);
- EXPECT_FLOAT_EQ(1.0, m.d);
- EXPECT_FLOAT_EQ(0.0, m.e);
- EXPECT_FLOAT_EQ(0.0, m.f);
+ EXPECT_FLOAT_EQ(1.0f, m.a);
+ EXPECT_FLOAT_EQ(0.0f, m.b);
+ EXPECT_FLOAT_EQ(0.0f, m.c);
+ EXPECT_FLOAT_EQ(1.0f, m.d);
+ EXPECT_FLOAT_EQ(0.0f, m.e);
+ EXPECT_FLOAT_EQ(0.0f, m.f);
EXPECT_TRUE(m.IsIdentity());
}
+TEST(CFX_Matrix, AsTuple) {
+ CFX_Matrix m(1, 2, 3, 4, 5, 6);
+ auto tuple = m.AsTuple();
+ EXPECT_FLOAT_EQ(1.0f, std::get<0>(tuple));
+ EXPECT_FLOAT_EQ(2.0f, std::get<1>(tuple));
+ EXPECT_FLOAT_EQ(3.0f, std::get<2>(tuple));
+ EXPECT_FLOAT_EQ(4.0f, std::get<3>(tuple));
+ EXPECT_FLOAT_EQ(5.0f, std::get<4>(tuple));
+ EXPECT_FLOAT_EQ(6.0f, std::get<5>(tuple));
+}
+
TEST(CFX_Matrix, GetInverse) {
static constexpr float data[6] = {3, 0, 2, 3, 1, 4};
CFX_Matrix m(data);
diff --git a/fpdfsdk/fpdf_editimg.cpp b/fpdfsdk/fpdf_editimg.cpp
index 21ed434d7f..8282eebdc1 100644
--- a/fpdfsdk/fpdf_editimg.cpp
+++ b/fpdfsdk/fpdf_editimg.cpp
@@ -6,6 +6,8 @@
#include "public/fpdf_edit.h"
+#include <utility>
+
#include "core/fpdfapi/cpdf_modulemgr.h"
#include "core/fpdfapi/page/cpdf_image.h"
#include "core/fpdfapi/page/cpdf_imageobject.h"
@@ -129,13 +131,7 @@ FPDFImageObj_GetMatrix(FPDF_PAGEOBJECT image_object,
if (!pImgObj || !a || !b || !c || !d || !e || !f)
return false;
- const CFX_Matrix& matrix = pImgObj->matrix();
- *a = matrix.a;
- *b = matrix.b;
- *c = matrix.c;
- *d = matrix.d;
- *e = matrix.e;
- *f = matrix.f;
+ std::tie(*a, *b, *c, *d, *e, *f) = pImgObj->matrix().AsTuple();
return true;
}
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
index 9026c72a4e..981baec70a 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -873,12 +873,6 @@ FPDFFormObj_GetMatrix(FPDF_PAGEOBJECT form_object,
if (!pFormObj || !a || !b || !c || !d || !e || !f)
return false;
- const CFX_Matrix& matrix = pFormObj->form_matrix();
- *a = matrix.a;
- *b = matrix.b;
- *c = matrix.c;
- *d = matrix.d;
- *e = matrix.e;
- *f = matrix.f;
+ std::tie(*a, *b, *c, *d, *e, *f) = pFormObj->form_matrix().AsTuple();
return true;
}
diff --git a/fpdfsdk/fpdf_editpath.cpp b/fpdfsdk/fpdf_editpath.cpp
index 83662aa8b5..8601a60508 100644
--- a/fpdfsdk/fpdf_editpath.cpp
+++ b/fpdfsdk/fpdf_editpath.cpp
@@ -4,6 +4,7 @@
#include "public/fpdf_edit.h"
+#include <utility>
#include <vector>
#include "core/fpdfapi/page/cpdf_path.h"
@@ -251,12 +252,7 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetMatrix(FPDF_PAGEOBJECT path,
if (!pPathObj)
return false;
- *a = pPathObj->m_Matrix.a;
- *b = pPathObj->m_Matrix.b;
- *c = pPathObj->m_Matrix.c;
- *d = pPathObj->m_Matrix.d;
- *e = pPathObj->m_Matrix.e;
- *f = pPathObj->m_Matrix.f;
+ std::tie(*a, *b, *c, *d, *e, *f) = pPathObj->m_Matrix.AsTuple();
return true;
}
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index 1c6709f915..3e1067dff8 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -524,14 +524,7 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_GetMatrix(FPDF_PAGEOBJECT text,
if (!pTextObj)
return false;
- CFX_Matrix text_matrix = pTextObj->GetTextMatrix();
- *a = text_matrix.a;
- *b = text_matrix.b;
- *c = text_matrix.c;
- *d = text_matrix.d;
- *e = text_matrix.e;
- *f = text_matrix.f;
-
+ std::tie(*a, *b, *c, *d, *e, *f) = pTextObj->GetTextMatrix().AsTuple();
return true;
}