diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-02-06 15:10:48 -0800 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-02-07 14:06:00 +0000 |
commit | 76da8841aef9a60c1c65c646a9f943c25861bc33 (patch) | |
tree | c81d3bfb4bcbe242689812b144c7b320c71cf91b | |
parent | 10def51edb8758632be9b24476459b0ab6f23c51 (diff) | |
download | pdfium-76da8841aef9a60c1c65c646a9f943c25861bc33.tar.xz |
Split CFX_STemplate from CFX_PSTemplate
This will allow the compiler to distinguish between rectangle
initialization from a point and a size vs. two points.
Add corresponding ctors, and fix style noise induced in XFA,
now that rects have become a complex type.
Change-Id: Iaa5887db63dafd41ac95f5c623989ca1d6443fd6
Reviewed-on: https://pdfium-review.googlesource.com/2533
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | core/fxcrt/fx_coordinates.h | 339 | ||||
-rw-r--r-- | xfa/fde/fde_visualset.h | 5 | ||||
-rw-r--r-- | xfa/fde/tto/fde_textout.h | 5 |
3 files changed, 202 insertions, 147 deletions
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h index c266273885..f00675842d 100644 --- a/core/fxcrt/fx_coordinates.h +++ b/core/fxcrt/fx_coordinates.h @@ -12,84 +12,144 @@ class CFX_Matrix; template <class BaseType> -class CFX_PSTemplate { +class CFX_PTemplate { public: - CFX_PSTemplate() : x(0), y(0) {} - CFX_PSTemplate(BaseType new_x, BaseType new_y) : x(new_x), y(new_y) {} - CFX_PSTemplate(const CFX_PSTemplate& other) : x(other.x), y(other.y) {} + CFX_PTemplate() : x(0), y(0) {} + CFX_PTemplate(BaseType new_x, BaseType new_y) : x(new_x), y(new_y) {} + CFX_PTemplate(const CFX_PTemplate& other) : x(other.x), y(other.y) {} void clear() { x = 0; y = 0; } - CFX_PSTemplate operator=(const CFX_PSTemplate& other) { + CFX_PTemplate operator=(const CFX_PTemplate& other) { if (this != &other) { x = other.x; y = other.y; } return *this; } - bool operator==(const CFX_PSTemplate& other) const { + bool operator==(const CFX_PTemplate& other) const { return x == other.x && y == other.y; } - bool operator!=(const CFX_PSTemplate& other) const { + bool operator!=(const CFX_PTemplate& other) const { return !(*this == other); } - CFX_PSTemplate& operator+=(const CFX_PSTemplate<BaseType>& obj) { + CFX_PTemplate& operator+=(const CFX_PTemplate<BaseType>& obj) { x += obj.x; y += obj.y; return *this; } - CFX_PSTemplate& operator-=(const CFX_PSTemplate<BaseType>& obj) { + CFX_PTemplate& operator-=(const CFX_PTemplate<BaseType>& obj) { x -= obj.x; y -= obj.y; return *this; } - CFX_PSTemplate& operator*=(BaseType factor) { + CFX_PTemplate& operator*=(BaseType factor) { x *= factor; y *= factor; return *this; } - CFX_PSTemplate& operator/=(BaseType divisor) { + CFX_PTemplate& operator/=(BaseType divisor) { x /= divisor; y /= divisor; return *this; } - CFX_PSTemplate operator+(const CFX_PSTemplate& other) { - return CFX_PSTemplate(x + other.x, y + other.y); + CFX_PTemplate operator+(const CFX_PTemplate& other) { + return CFX_PTemplate(x + other.x, y + other.y); } - CFX_PSTemplate operator-(const CFX_PSTemplate& other) { - return CFX_PSTemplate(x - other.x, y - other.y); + CFX_PTemplate operator-(const CFX_PTemplate& other) { + return CFX_PTemplate(x - other.x, y - other.y); } - CFX_PSTemplate operator*(BaseType factor) { - return CFX_PSTemplate(x * factor, y * factor); + CFX_PTemplate operator*(BaseType factor) { + return CFX_PTemplate(x * factor, y * factor); } - CFX_PSTemplate operator/(BaseType divisor) { - return CFX_PSTemplate(x / divisor, y / divisor); + CFX_PTemplate operator/(BaseType divisor) { + return CFX_PTemplate(x / divisor, y / divisor); } BaseType x; BaseType y; }; -typedef CFX_PSTemplate<int32_t> CFX_Point; -typedef CFX_PSTemplate<FX_FLOAT> CFX_PointF; -typedef CFX_PSTemplate<int32_t> CFX_Size; -typedef CFX_PSTemplate<FX_FLOAT> CFX_SizeF; +using CFX_Point = CFX_PTemplate<int32_t>; +using CFX_PointF = CFX_PTemplate<FX_FLOAT>; template <class BaseType> -class CFX_VTemplate : public CFX_PSTemplate<BaseType> { +class CFX_STemplate { public: - using CFX_PSTemplate<BaseType>::x; - using CFX_PSTemplate<BaseType>::y; + CFX_STemplate() : x(0), y(0) {} + CFX_STemplate(BaseType new_x, BaseType new_y) : x(new_x), y(new_y) {} + CFX_STemplate(const CFX_STemplate& other) : x(other.x), y(other.y) {} + void clear() { + x = 0; + y = 0; + } + CFX_STemplate operator=(const CFX_STemplate& other) { + if (this != &other) { + x = other.x; + y = other.y; + } + return *this; + } + bool operator==(const CFX_STemplate& other) const { + return x == other.x && y == other.y; + } + bool operator!=(const CFX_STemplate& other) const { + return !(*this == other); + } + CFX_STemplate& operator+=(const CFX_STemplate<BaseType>& obj) { + x += obj.x; + y += obj.y; + return *this; + } + CFX_STemplate& operator-=(const CFX_STemplate<BaseType>& obj) { + x -= obj.x; + y -= obj.y; + return *this; + } + CFX_STemplate& operator*=(BaseType factor) { + x *= factor; + y *= factor; + return *this; + } + CFX_STemplate& operator/=(BaseType divisor) { + x /= divisor; + y /= divisor; + return *this; + } + CFX_STemplate operator+(const CFX_STemplate& other) { + return CFX_STemplate(x + other.x, y + other.y); + } + CFX_STemplate operator-(const CFX_STemplate& other) { + return CFX_STemplate(x - other.x, y - other.y); + } + CFX_STemplate operator*(BaseType factor) { + return CFX_STemplate(x * factor, y * factor); + } + CFX_STemplate operator/(BaseType divisor) { + return CFX_STemplate(x / divisor, y / divisor); + } + + BaseType x; + BaseType y; +}; +using CFX_Size = CFX_STemplate<int32_t>; +using CFX_SizeF = CFX_STemplate<FX_FLOAT>; - CFX_VTemplate() : CFX_PSTemplate<BaseType>() {} +template <class BaseType> +class CFX_VTemplate : public CFX_PTemplate<BaseType> { + public: + using CFX_PTemplate<BaseType>::x; + using CFX_PTemplate<BaseType>::y; + + CFX_VTemplate() : CFX_PTemplate<BaseType>() {} CFX_VTemplate(BaseType new_x, BaseType new_y) - : CFX_PSTemplate<BaseType>(new_x, new_y) {} + : CFX_PTemplate<BaseType>(new_x, new_y) {} - CFX_VTemplate(const CFX_VTemplate& other) : CFX_PSTemplate<BaseType>(other) {} + CFX_VTemplate(const CFX_VTemplate& other) : CFX_PTemplate<BaseType>(other) {} - CFX_VTemplate(const CFX_PSTemplate<BaseType>& point1, - const CFX_PSTemplate<BaseType>& point2) - : CFX_PSTemplate<BaseType>(point2.x - point1.x, point2.y - point1.y) {} + CFX_VTemplate(const CFX_PTemplate<BaseType>& point1, + const CFX_PTemplate<BaseType>& point2) + : CFX_PTemplate<BaseType>(point2.x - point1.x, point2.y - point1.y) {} FX_FLOAT Length() const { return FXSYS_sqrt(x * x + y * y); } void Normalize() { @@ -115,8 +175,8 @@ class CFX_VTemplate : public CFX_PSTemplate<BaseType> { y = x * sinValue + y * cosValue; } }; -typedef CFX_VTemplate<int32_t> CFX_Vector; -typedef CFX_VTemplate<FX_FLOAT> CFX_VectorF; +using CFX_Vector = CFX_VTemplate<int32_t>; +using CFX_VectorF = CFX_VTemplate<FX_FLOAT>; // Rectangles. // TODO(tsepez): Consolidate all these different rectangle classes. @@ -190,40 +250,64 @@ class CFX_FloatPoint { }; // LTWH rectangles (y-axis runs downwards). -template <class baseType> +template <class BaseType> class CFX_RTemplate { public: - typedef CFX_PSTemplate<baseType> FXT_POINT; - typedef CFX_PSTemplate<baseType> FXT_SIZE; - typedef CFX_VTemplate<baseType> FXT_VECTOR; - typedef CFX_RTemplate<baseType> FXT_RECT; - void Set(baseType dst_left, - baseType dst_top, - baseType dst_width, - baseType dst_height) { + using PointType = CFX_PTemplate<BaseType>; + using SizeType = CFX_STemplate<BaseType>; + using VectorType = CFX_VTemplate<BaseType>; + using RectType = CFX_RTemplate<BaseType>; + + CFX_RTemplate() : left(0), top(0), width(0), height(0) {} + CFX_RTemplate(BaseType dst_left, + BaseType dst_top, + BaseType dst_width, + BaseType dst_height) + : left(dst_left), top(dst_top), width(dst_width), height(dst_height) {} + CFX_RTemplate(BaseType dst_left, BaseType dst_top, const SizeType& dst_size) + : left(dst_left), top(dst_top), width(dst_size.x), height(dst_size.y) {} + CFX_RTemplate(const PointType& p, BaseType dst_width, BaseType dst_height) + : left(p.x), top(p.y), width(dst_width), height(dst_height) {} + CFX_RTemplate(const PointType& p1, const SizeType& s2) + : left(p1.x), top(p1.y), width(s2.x), height(s2.y) {} + + void Set(BaseType dst_left, + BaseType dst_top, + BaseType dst_width, + BaseType dst_height) { left = dst_left; top = dst_top; width = dst_width; height = dst_height; } - void Set(baseType dst_left, baseType dst_top, const FXT_SIZE& dst_size) { + void Set(BaseType dst_left, BaseType dst_top, const SizeType& dst_size) { left = dst_left; top = dst_top; - Size(dst_size); + width = dst_size.x; + height = dst_size.y; } - void Set(const FXT_POINT& p, baseType dst_width, baseType dst_height) { - TopLeft(p); + void Set(const PointType& p, BaseType dst_width, BaseType dst_height) { + left = p.x; + top = p.y; width = dst_width; height = dst_height; } - void Set(const FXT_POINT& p1, const FXT_POINT& p2) { - TopLeft(p1); + void Set(const PointType& p, const SizeType& s) { + left = p.x; + top = p.y; + width = s.x; + height = s.y; + } + void Set(const PointType& p1, const PointType& p2) { + left = p1.x; + top = p1.y; width = p2.x - p1.x; height = p2.y - p1.y; Normalize(); } - void Set(const FXT_POINT& p, const FXT_VECTOR& v) { - TopLeft(p); + void Set(const PointType& p, const VectorType& v) { + left = p.x; + top = p.y; width = v.x; height = v.y; Normalize(); @@ -234,18 +318,18 @@ class CFX_RTemplate { width = 0; height = 0; } - FXT_RECT& operator+=(const FXT_POINT& p) { + RectType& operator+=(const PointType& p) { left += p.x; top += p.y; return *this; } - FXT_RECT& operator-=(const FXT_POINT& p) { + RectType& operator-=(const PointType& p) { left -= p.x; top -= p.y; return *this; } - baseType right() const { return left + width; } - baseType bottom() const { return top + height; } + BaseType right() const { return left + width; } + BaseType bottom() const { return top + height; } void Normalize() { if (width < 0) { left += width; @@ -256,46 +340,46 @@ class CFX_RTemplate { height = -height; } } - void Offset(baseType dx, baseType dy) { + void Offset(BaseType dx, BaseType dy) { left += dx; top += dy; } - void Inflate(baseType x, baseType y) { + void Inflate(BaseType x, BaseType y) { left -= x; width += x * 2; top -= y; height += y * 2; } - void Inflate(const FXT_POINT& p) { Inflate(p.x, p.y); } - void Inflate(baseType off_left, - baseType off_top, - baseType off_right, - baseType off_bottom) { + void Inflate(const PointType& p) { Inflate(p.x, p.y); } + void Inflate(BaseType off_left, + BaseType off_top, + BaseType off_right, + BaseType off_bottom) { left -= off_left; top -= off_top; width += off_left + off_right; height += off_top + off_bottom; } - void Inflate(const FXT_RECT& rt) { + void Inflate(const RectType& rt) { Inflate(rt.left, rt.top, rt.left + rt.width, rt.top + rt.height); } - void Deflate(baseType x, baseType y) { + void Deflate(BaseType x, BaseType y) { left += x; width -= x * 2; top += y; height -= y * 2; } - void Deflate(const FXT_POINT& p) { Deflate(p.x, p.y); } - void Deflate(baseType off_left, - baseType off_top, - baseType off_right, - baseType off_bottom) { + void Deflate(const PointType& p) { Deflate(p.x, p.y); } + void Deflate(BaseType off_left, + BaseType off_top, + BaseType off_right, + BaseType off_bottom) { left += off_left; top += off_top; width -= off_left + off_right; height -= off_top + off_bottom; } - void Deflate(const FXT_RECT& rt) { + void Deflate(const RectType& rt) { Deflate(rt.left, rt.top, rt.top + rt.width, rt.top + rt.height); } bool IsEmpty() const { return width <= 0 || height <= 0; } @@ -303,71 +387,29 @@ class CFX_RTemplate { return width <= fEpsilon || height <= fEpsilon; } void Empty() { width = height = 0; } - bool Contains(baseType x, baseType y) const { + bool Contains(BaseType x, BaseType y) const { return x >= left && x < left + width && y >= top && y < top + height; } - bool Contains(const FXT_POINT& p) const { return Contains(p.x, p.y); } - bool Contains(const FXT_RECT& rt) const { + bool Contains(const PointType& p) const { return Contains(p.x, p.y); } + bool Contains(const RectType& rt) const { return rt.left >= left && rt.right() <= right() && rt.top >= top && rt.bottom() <= bottom(); } - baseType Width() const { return width; } - baseType Height() const { return height; } - FXT_SIZE Size() const { - FXT_SIZE size; - size.Set(width, height); - return size; - } - void Size(FXT_SIZE s) { width = s.x, height = s.y; } - FXT_POINT TopLeft() const { - FXT_POINT p; - p.x = left; - p.y = top; - return p; - } - FXT_POINT TopRight() const { - FXT_POINT p; - p.x = left + width; - p.y = top; - return p; - } - FXT_POINT BottomLeft() const { - FXT_POINT p; - p.x = left; - p.y = top + height; - return p; - } - FXT_POINT BottomRight() const { - FXT_POINT p; - p.x = left + width; - p.y = top + height; - return p; - } - void TopLeft(FXT_POINT tl) { - left = tl.x; - top = tl.y; - } - void TopRight(FXT_POINT tr) { - width = tr.x - left; - top = tr.y; - } - void BottomLeft(FXT_POINT bl) { - left = bl.x; - height = bl.y - top; - } - void BottomRight(FXT_POINT br) { - width = br.x - left; - height = br.y - top; - } - FXT_POINT Center() const { - FXT_POINT p; - p.x = left + width / 2; - p.y = top + height / 2; - return p; - } - void Union(baseType x, baseType y) { - baseType r = right(); - baseType b = bottom(); + BaseType Width() const { return width; } + BaseType Height() const { return height; } + SizeType Size() const { return SizeType(width, height); } + PointType TopLeft() const { return PointType(left, top); } + PointType TopRight() const { return PointType(left + width, top); } + PointType BottomLeft() const { return PointType(left, top + height); } + PointType BottomRight() const { + return PointType(left + width, top + height); + } + PointType Center() const { + return PointType(left + width / 2, top + height / 2); + } + void Union(BaseType x, BaseType y) { + BaseType r = right(); + BaseType b = bottom(); if (left > x) left = x; if (r < x) @@ -379,10 +421,10 @@ class CFX_RTemplate { width = r - left; height = b - top; } - void Union(const FXT_POINT& p) { Union(p.x, p.y); } - void Union(const FXT_RECT& rt) { - baseType r = right(); - baseType b = bottom(); + void Union(const PointType& p) { Union(p.x, p.y); } + void Union(const RectType& rt) { + BaseType r = right(); + BaseType b = bottom(); if (left > rt.left) left = rt.left; if (r < rt.right()) @@ -394,9 +436,9 @@ class CFX_RTemplate { width = r - left; height = b - top; } - void Intersect(const FXT_RECT& rt) { - baseType r = right(); - baseType b = bottom(); + void Intersect(const RectType& rt) { + BaseType r = right(); + BaseType b = bottom(); if (left < rt.left) left = rt.left; if (r > rt.right()) @@ -408,28 +450,31 @@ class CFX_RTemplate { width = r - left; height = b - top; } - bool IntersectWith(const FXT_RECT& rt) const { - FXT_RECT rect = rt; + bool IntersectWith(const RectType& rt) const { + RectType rect = rt; rect.Intersect(*this); return !rect.IsEmpty(); } - bool IntersectWith(const FXT_RECT& rt, FX_FLOAT fEpsilon) const { - FXT_RECT rect = rt; + bool IntersectWith(const RectType& rt, FX_FLOAT fEpsilon) const { + RectType rect = rt; rect.Intersect(*this); return !rect.IsEmpty(fEpsilon); } - friend bool operator==(const FXT_RECT& rc1, const FXT_RECT& rc2) { + friend bool operator==(const RectType& rc1, const RectType& rc2) { return rc1.left == rc2.left && rc1.top == rc2.top && rc1.width == rc2.width && rc1.height == rc2.height; } - friend bool operator!=(const FXT_RECT& rc1, const FXT_RECT& rc2) { + friend bool operator!=(const RectType& rc1, const RectType& rc2) { return !(rc1 == rc2); } - baseType left, top; - baseType width, height; + + BaseType left; + BaseType top; + BaseType width; + BaseType height; }; -typedef CFX_RTemplate<int32_t> CFX_Rect; -typedef CFX_RTemplate<FX_FLOAT> CFX_RectF; +using CFX_Rect = CFX_RTemplate<int32_t>; +using CFX_RectF = CFX_RTemplate<FX_FLOAT>; class CFX_FloatRect { public: diff --git a/xfa/fde/fde_visualset.h b/xfa/fde/fde_visualset.h index 30703e795a..0c6341fead 100644 --- a/xfa/fde/fde_visualset.h +++ b/xfa/fde/fde_visualset.h @@ -25,12 +25,17 @@ enum FDE_VISUALOBJTYPE { }; struct FDE_TEXTEDITPIECE { + FDE_TEXTEDITPIECE(); + ~FDE_TEXTEDITPIECE(); + int32_t nStart; int32_t nCount; int32_t nBidiLevel; CFX_RectF rtPiece; uint32_t dwCharStyles; }; +inline FDE_TEXTEDITPIECE::FDE_TEXTEDITPIECE() = default; +inline FDE_TEXTEDITPIECE::~FDE_TEXTEDITPIECE() = default; class IFDE_VisualSet { public: diff --git a/xfa/fde/tto/fde_textout.h b/xfa/fde/tto/fde_textout.h index e1eb71cf3b..97ec1251f4 100644 --- a/xfa/fde/tto/fde_textout.h +++ b/xfa/fde/tto/fde_textout.h @@ -47,11 +47,16 @@ class CFX_TxtBreak; struct FX_TXTRUN; struct FDE_TTOPIECE { + FDE_TTOPIECE(); + ~FDE_TTOPIECE(); + int32_t iStartChar; int32_t iChars; uint32_t dwCharStyles; CFX_RectF rtPiece; }; +inline FDE_TTOPIECE::FDE_TTOPIECE() = default; +inline FDE_TTOPIECE::~FDE_TTOPIECE() = default; typedef CFX_MassArrayTemplate<FDE_TTOPIECE> CFDE_TTOPieceArray; class CFDE_TTOLine { |