summaryrefslogtreecommitdiff
path: root/core/include
diff options
context:
space:
mode:
Diffstat (limited to 'core/include')
-rw-r--r--core/include/fpdfapi/fpdf_resource.h8
-rw-r--r--core/include/fxcrt/fx_coordinates.h378
2 files changed, 191 insertions, 195 deletions
diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h
index 393a9cc0bf..23e1b55efb 100644
--- a/core/include/fpdfapi/fpdf_resource.h
+++ b/core/include/fpdfapi/fpdf_resource.h
@@ -149,7 +149,7 @@ class CPDF_Font {
int GetStringWidth(const FX_CHAR* pString, int size);
virtual int GetCharWidthF(FX_DWORD charcode, int level = 0) = 0;
- virtual void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) = 0;
+ virtual FX_RECT GetCharBBox(FX_DWORD charcode, int level = 0) = 0;
CPDF_Document* m_pDocument;
CFX_Font m_Font;
@@ -226,7 +226,7 @@ class CPDF_SimpleFont : public CPDF_Font {
// CPDF_Font:
int GetCharWidthF(FX_DWORD charcode, int level = 0) override;
- void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override;
+ FX_RECT GetCharBBox(FX_DWORD charcode, int level = 0) override;
int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph = NULL) override;
FX_BOOL IsUnicodeCompatible() const override;
CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const override;
@@ -317,7 +317,7 @@ class CPDF_Type3Font : public CPDF_SimpleFont {
const CPDF_Type3Font* AsType3Font() const override { return this; }
CPDF_Type3Font* AsType3Font() override { return this; }
int GetCharWidthF(FX_DWORD charcode, int level = 0) override;
- void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override;
+ FX_RECT GetCharBBox(FX_DWORD charcode, int level = 0) override;
void SetPageResources(CPDF_Dictionary* pResources) {
m_pPageResources = pResources;
@@ -367,7 +367,7 @@ class CPDF_CIDFont : public CPDF_Font {
CPDF_CIDFont* AsCIDFont() override { return this; }
int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph = NULL) override;
int GetCharWidthF(FX_DWORD charcode, int level = 0) override;
- void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override;
+ FX_RECT GetCharBBox(FX_DWORD charcode, int level = 0) override;
FX_DWORD GetNextChar(const FX_CHAR* pString,
int nStrLen,
int& offset) const override;
diff --git a/core/include/fxcrt/fx_coordinates.h b/core/include/fxcrt/fx_coordinates.h
index c6bf230014..e2800ffdb0 100644
--- a/core/include/fxcrt/fx_coordinates.h
+++ b/core/include/fxcrt/fx_coordinates.h
@@ -120,6 +120,193 @@ class CFX_VTemplate : public CFX_PSTemplate<BaseType> {
typedef CFX_VTemplate<int32_t> CFX_Vector;
typedef CFX_VTemplate<FX_FLOAT> CFX_VectorF;
+// Rectangles.
+// TODO(tsepez): Consolidate all these different rectangle classes.
+
+// LTRB rectangles (y-axis runs downwards).
+struct FX_SMALL_RECT {
+ FX_SMALL_RECT() : FX_SMALL_RECT(kInvalid, kInvalid, kInvalid, kInvalid) {}
+
+ FX_SMALL_RECT(int16_t l, int16_t t, int16_t r, int16_t b)
+ : left(l), top(t), right(r), bottom(b) {}
+
+ static const int16_t kInvalid = -1;
+
+ int16_t left;
+ int16_t top;
+ int16_t right;
+ int16_t bottom;
+};
+
+struct FX_RECT {
+ FX_RECT() : left(0), top(0), right(0), bottom(0) {}
+
+ FX_RECT(int l, int t, int r, int b) : left(l), top(t), right(r), bottom(b) {}
+
+ explicit FX_RECT(const FX_SMALL_RECT& small)
+ : FX_RECT(small.left, small.top, small.right, small.bottom) {}
+
+ int Width() const { return right - left; }
+ int Height() const { return bottom - top; }
+ bool IsEmpty() const { return right <= left || bottom <= top; }
+
+ void Normalize();
+
+ void Intersect(const FX_RECT& src);
+ void Intersect(int l, int t, int r, int b) { Intersect(FX_RECT(l, t, r, b)); }
+
+ void Union(const FX_RECT& other_rect);
+ void Union(int l, int t, int r, int b) { Union(FX_RECT(l, t, r, b)); }
+
+ void Offset(int dx, int dy) {
+ left += dx;
+ right += dx;
+ top += dy;
+ bottom += dy;
+ }
+
+ bool operator==(const FX_RECT& src) const {
+ return left == src.left && right == src.right && top == src.top &&
+ bottom == src.bottom;
+ }
+
+ FX_BOOL Contains(const FX_RECT& other_rect) const {
+ return other_rect.left >= left && other_rect.right <= right &&
+ other_rect.top >= top && other_rect.bottom <= bottom;
+ }
+
+ FX_BOOL Contains(int x, int y) const {
+ return x >= left && x < right && y >= top && y < bottom;
+ }
+
+ FX_SMALL_RECT ToSmallRect() const {
+ return FX_SMALL_RECT(
+ static_cast<uint16_t>(left), static_cast<uint16_t>(top),
+ static_cast<uint16_t>(right), static_cast<uint16_t>(bottom));
+ }
+
+ int left;
+ int top;
+ int right;
+ int bottom;
+};
+
+// LBRT rectangles (y-axis runs upwards).
+class CFX_FloatPoint {
+ public:
+ CFX_FloatPoint(FX_FLOAT xx, FX_FLOAT yy) : x(xx), y(yy) {}
+
+ FX_FLOAT x;
+ FX_FLOAT y;
+};
+
+class CFX_FloatRect {
+ public:
+ CFX_FloatRect() : CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f) {}
+ CFX_FloatRect(FX_FLOAT l, FX_FLOAT b, FX_FLOAT r, FX_FLOAT t)
+ : left(l), bottom(b), right(r), top(t) {}
+
+ explicit CFX_FloatRect(const FX_FLOAT* pArray)
+ : CFX_FloatRect(pArray[0], pArray[1], pArray[2], pArray[3]) {}
+
+ explicit CFX_FloatRect(const FX_RECT& rect);
+
+ void Normalize();
+
+ void Reset() {
+ left = 0.0f;
+ right = 0.0f;
+ bottom = 0.0f;
+ top = 0.0f;
+ }
+
+ FX_BOOL IsEmpty() const { return left >= right || bottom >= top; }
+ FX_BOOL Contains(const CFX_FloatRect& other_rect) const;
+ FX_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);
+
+ FX_RECT GetInnerRect() const;
+ FX_RECT GetOutterRect() const;
+ FX_RECT GetClosestRect() const;
+
+ int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects);
+
+ void InitRect(FX_FLOAT x, FX_FLOAT y) {
+ left = x;
+ right = x;
+ bottom = y;
+ top = y;
+ }
+ void UpdateRect(FX_FLOAT x, FX_FLOAT y);
+
+ FX_FLOAT Width() const { return right - left; }
+ FX_FLOAT Height() const { return top - bottom; }
+
+ void Inflate(FX_FLOAT x, FX_FLOAT y) {
+ Normalize();
+ left -= x;
+ right += x;
+ bottom -= y;
+ top += y;
+ }
+
+ void Inflate(FX_FLOAT other_left,
+ FX_FLOAT other_bottom,
+ FX_FLOAT other_right,
+ FX_FLOAT other_top) {
+ Normalize();
+ left -= other_left;
+ bottom -= other_bottom;
+ right += other_right;
+ top += other_top;
+ }
+
+ void Inflate(const CFX_FloatRect& rt) {
+ Inflate(rt.left, rt.bottom, rt.right, rt.top);
+ }
+
+ void Deflate(FX_FLOAT x, FX_FLOAT y) {
+ Normalize();
+ left += x;
+ right -= x;
+ bottom += y;
+ top -= y;
+ }
+
+ void Deflate(FX_FLOAT other_left,
+ FX_FLOAT other_bottom,
+ FX_FLOAT other_right,
+ FX_FLOAT other_top) {
+ Normalize();
+ left += other_left;
+ bottom += other_bottom;
+ right -= other_right;
+ top -= other_top;
+ }
+
+ void Deflate(const CFX_FloatRect& rt) {
+ Deflate(rt.left, rt.bottom, rt.right, rt.top);
+ }
+
+ void Translate(FX_FLOAT e, FX_FLOAT f) {
+ left += e;
+ right += e;
+ top += f;
+ bottom += f;
+ }
+
+ static CFX_FloatRect GetBBox(const CFX_PointF* pPoints, int nPoints);
+
+ FX_FLOAT left;
+ FX_FLOAT bottom;
+ FX_FLOAT right;
+ FX_FLOAT top;
+};
+
+// LTWH rectangles (y-axis runs downwards).
template <class baseType>
class CFX_RTemplate {
public:
@@ -350,197 +537,6 @@ typedef CFX_RTemplate<FX_FLOAT>* FX_LPRECTF;
typedef CFX_RTemplate<int32_t> const* FX_LPCRECT;
typedef CFX_RTemplate<FX_FLOAT> const* FX_LPCRECTF;
typedef CFX_ArrayTemplate<CFX_RectF> CFX_RectFArray;
-struct FX_RECT {
- int left;
-
- int top;
-
- int right;
-
- int bottom;
-
- FX_RECT() : left(0), top(0), right(0), bottom(0) {}
-
- FX_RECT(int left1, int top1, int right1, int bottom1) {
- left = left1;
- top = top1;
- right = right1;
- bottom = bottom1;
- }
-
- int Width() const { return right - left; }
-
- int Height() const { return bottom - top; }
-
- FX_BOOL IsEmpty() const { return right <= left || bottom <= top; }
-
- void Normalize();
-
- void Intersect(const FX_RECT& src);
-
- void Intersect(int left1, int top1, int right1, int bottom1) {
- Intersect(FX_RECT(left1, top1, right1, bottom1));
- }
-
- void Union(const FX_RECT& other_rect);
-
- bool operator==(const FX_RECT& src) const {
- return left == src.left && right == src.right && top == src.top &&
- bottom == src.bottom;
- }
-
- void Offset(int dx, int dy) {
- left += dx;
- right += dx;
- top += dy;
- bottom += dy;
- }
-
- FX_BOOL Contains(const FX_RECT& other_rect) const {
- return other_rect.left >= left && other_rect.right <= right &&
- other_rect.top >= top && other_rect.bottom <= bottom;
- }
-
- FX_BOOL Contains(int x, int y) const {
- return x >= left && x < right && y >= top && y < bottom;
- }
-};
-struct FX_SMALL_RECT {
- int16_t Left;
-
- int16_t Top;
-
- int16_t Right;
-
- int16_t Bottom;
-};
-
-class CFX_FloatPoint {
- public:
- CFX_FloatPoint(FX_FLOAT xx, FX_FLOAT yy) : x(xx), y(yy) {}
-
- FX_FLOAT x;
- FX_FLOAT y;
-};
-
-class CFX_FloatRect {
- public:
- CFX_FloatRect() { left = right = bottom = top = 0; }
-
- CFX_FloatRect(FX_FLOAT left1,
- FX_FLOAT bottom1,
- FX_FLOAT right1,
- FX_FLOAT top1) {
- left = left1;
- bottom = bottom1;
- right = right1;
- top = top1;
- }
-
- CFX_FloatRect(const FX_FLOAT* pArray) {
- left = pArray[0];
- bottom = pArray[1];
- right = pArray[2];
- top = pArray[3];
- }
-
- CFX_FloatRect(const FX_RECT& rect);
-
- FX_BOOL IsEmpty() const { return left >= right || bottom >= top; }
-
- void Normalize();
-
- void Reset() { left = right = bottom = top = 0; }
-
- FX_BOOL Contains(const CFX_FloatRect& other_rect) const;
-
- FX_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);
-
- FX_RECT GetInnerRect() const;
-
- FX_RECT GetOutterRect() const;
-
- FX_RECT GetClosestRect() const;
-
- int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects);
-
- void InitRect(FX_FLOAT x, FX_FLOAT y) {
- left = right = x;
- bottom = top = y;
- }
-
- void UpdateRect(FX_FLOAT x, FX_FLOAT y);
-
- FX_FLOAT Width() const { return right - left; }
-
- FX_FLOAT Height() const { return top - bottom; }
-
- void Inflate(FX_FLOAT x, FX_FLOAT y) {
- Normalize();
- left -= x;
- right += x;
- bottom -= y;
- top += y;
- }
-
- void Inflate(FX_FLOAT other_left,
- FX_FLOAT other_bottom,
- FX_FLOAT other_right,
- FX_FLOAT other_top) {
- Normalize();
- left -= other_left;
- bottom -= other_bottom;
- right += other_right;
- top += other_top;
- }
-
- void Inflate(const CFX_FloatRect& rt) {
- Inflate(rt.left, rt.bottom, rt.right, rt.top);
- }
-
- void Deflate(FX_FLOAT x, FX_FLOAT y) {
- Normalize();
- left += x;
- right -= x;
- bottom += y;
- top -= y;
- }
-
- void Deflate(FX_FLOAT other_left,
- FX_FLOAT other_bottom,
- FX_FLOAT other_right,
- FX_FLOAT other_top) {
- Normalize();
- left += other_left;
- bottom += other_bottom;
- right -= other_right;
- top -= other_top;
- }
-
- void Deflate(const CFX_FloatRect& rt) {
- Deflate(rt.left, rt.bottom, rt.right, rt.top);
- }
-
- void Translate(FX_FLOAT e, FX_FLOAT f) {
- left += e;
- right += e;
- top += f;
- bottom += f;
- }
-
- static CFX_FloatRect GetBBox(const CFX_PointF* pPoints, int nPoints);
-
- FX_FLOAT left;
- FX_FLOAT right;
- FX_FLOAT bottom;
- FX_FLOAT top;
-};
class CFX_Matrix {
public: