diff options
-rw-r--r-- | core/fxcrt/fx_coordinates.cpp | 6 | ||||
-rw-r--r-- | core/fxcrt/fx_coordinates.h | 138 | ||||
-rw-r--r-- | core/fxcrt/fx_coordinates_unittest.cpp | 12 | ||||
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_page.cpp | 7 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_gefont.cpp | 17 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_gefont.h | 6 | ||||
-rw-r--r-- | xfa/fgas/layout/cfx_txtbreak.cpp | 13 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffpageview.cpp | 28 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffpageview.h | 2 | ||||
-rw-r--r-- | xfa/fxgraphics/cxfa_graphics.cpp | 2 |
10 files changed, 92 insertions, 139 deletions
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp index bd06ce1473..ad64f0b43e 100644 --- a/core/fxcrt/fx_coordinates.cpp +++ b/core/fxcrt/fx_coordinates.cpp @@ -205,6 +205,12 @@ std::ostream& operator<<(std::ostream& os, const CFX_FloatRect& rect) { << rect.left << ", bot " << rect.bottom << ")]"; return os; } + +std::ostream& operator<<(std::ostream& os, const CFX_RectF& rect) { + os << "rect[w " << rect.Width() << " x h " << rect.Height() << " (left " + << rect.left << ", top " << rect.top << ")]"; + return os; +} #endif // NDEBUG CFX_Matrix CFX_Matrix::GetInverse() const { diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h index a458fa8b50..0b98ff2e43 100644 --- a/core/fxcrt/fx_coordinates.h +++ b/core/fxcrt/fx_coordinates.h @@ -363,79 +363,49 @@ std::ostream& operator<<(std::ostream& os, const CFX_FloatRect& rect); #endif // LTWH rectangles (y-axis runs downwards). -template <class BaseType> -class CFX_RTemplate { +class CFX_RectF { public: - 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) + using PointType = CFX_PointF; + using SizeType = CFX_SizeF; + + CFX_RectF() : left(0), top(0), width(0), height(0) {} + CFX_RectF(float dst_left, float dst_top, float dst_width, float 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) + CFX_RectF(float dst_left, float dst_top, const SizeType& dst_size) : left(dst_left), top(dst_top), width(dst_size.width), height(dst_size.height) {} - CFX_RTemplate(const PointType& p, BaseType dst_width, BaseType dst_height) + CFX_RectF(const PointType& p, float dst_width, float dst_height) : left(p.x), top(p.y), width(dst_width), height(dst_height) {} - CFX_RTemplate(const PointType& p1, const SizeType& s2) + CFX_RectF(const PointType& p1, const SizeType& s2) : left(p1.x), top(p1.y), width(s2.width), height(s2.height) {} - CFX_RTemplate(const PointType& p1, const PointType& p2) - : left(p1.x), - top(p1.y), - width(p2.width - p1.width), - height(p2.height - p1.height) { - Normalize(); - } - CFX_RTemplate(const PointType& p, const VectorType& v) - : left(p.x), top(p.y), width(v.x), height(v.y) { - Normalize(); - } - - explicit CFX_RTemplate(const CFX_FloatRect& r) - : left(static_cast<BaseType>(r.left)), - top(static_cast<BaseType>(r.top)), - width(static_cast<BaseType>(r.Width())), - height(static_cast<BaseType>(r.Height())) {} // NOLINTNEXTLINE(runtime/explicit) - CFX_RTemplate(const RectType& other) + CFX_RectF(const CFX_RectF& other) : left(other.left), top(other.top), width(other.width), height(other.height) {} - template <typename OtherType> - CFX_RTemplate<OtherType> As() const { - return CFX_RTemplate<OtherType>( - static_cast<OtherType>(left), static_cast<OtherType>(top), - static_cast<OtherType>(width), static_cast<OtherType>(height)); - } - void Reset() { left = 0; top = 0; width = 0; height = 0; } - RectType& operator+=(const PointType& p) { + CFX_RectF& operator+=(const PointType& p) { left += p.x; top += p.y; return *this; } - RectType& operator-=(const PointType& p) { + CFX_RectF& operator-=(const PointType& p) { left -= p.x; top -= p.y; return *this; } - BaseType right() const { return left + width; } - BaseType bottom() const { return top + height; } + float right() const { return left + width; } + float bottom() const { return top + height; } void Normalize() { if (width < 0) { left += width; @@ -446,46 +416,46 @@ class CFX_RTemplate { height = -height; } } - void Offset(BaseType dx, BaseType dy) { + void Offset(float dx, float dy) { left += dx; top += dy; } - void Inflate(BaseType x, BaseType y) { + void Inflate(float x, float y) { left -= x; width += x * 2; top -= y; height += y * 2; } void Inflate(const PointType& p) { Inflate(p.x, p.y); } - void Inflate(BaseType off_left, - BaseType off_top, - BaseType off_right, - BaseType off_bottom) { + void Inflate(float off_left, + float off_top, + float off_right, + float off_bottom) { left -= off_left; top -= off_top; width += off_left + off_right; height += off_top + off_bottom; } - void Inflate(const RectType& rt) { + void Inflate(const CFX_RectF& rt) { Inflate(rt.left, rt.top, rt.left + rt.width, rt.top + rt.height); } - void Deflate(BaseType x, BaseType y) { + void Deflate(float x, float y) { left += x; width -= x * 2; top += y; height -= y * 2; } void Deflate(const PointType& p) { Deflate(p.x, p.y); } - void Deflate(BaseType off_left, - BaseType off_top, - BaseType off_right, - BaseType off_bottom) { + void Deflate(float off_left, + float off_top, + float off_right, + float off_bottom) { left += off_left; top += off_top; width -= off_left + off_right; height -= off_top + off_bottom; } - void Deflate(const RectType& rt) { + void Deflate(const CFX_RectF& rt) { Deflate(rt.left, rt.top, rt.top + rt.width, rt.top + rt.height); } bool IsEmpty() const { return width <= 0 || height <= 0; } @@ -497,12 +467,12 @@ class CFX_RTemplate { return p.x >= left && p.x < left + width && p.y >= top && p.y < top + height; } - bool Contains(const RectType& rt) const { + bool Contains(const CFX_RectF& 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; } + float Width() const { return width; } + float 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); } @@ -513,9 +483,9 @@ class CFX_RTemplate { PointType Center() const { return PointType(left + width / 2, top + height / 2); } - void Union(BaseType x, BaseType y) { - BaseType r = right(); - BaseType b = bottom(); + void Union(float x, float y) { + float r = right(); + float b = bottom(); left = std::min(left, x); top = std::min(top, y); @@ -526,9 +496,9 @@ class CFX_RTemplate { height = b - top; } void Union(const PointType& p) { Union(p.x, p.y); } - void Union(const RectType& rt) { - BaseType r = right(); - BaseType b = bottom(); + void Union(const CFX_RectF& rt) { + float r = right(); + float b = bottom(); left = std::min(left, rt.left); top = std::min(top, rt.top); @@ -538,9 +508,9 @@ class CFX_RTemplate { width = r - left; height = b - top; } - void Intersect(const RectType& rt) { - BaseType r = right(); - BaseType b = bottom(); + void Intersect(const CFX_RectF& rt) { + float r = right(); + float b = bottom(); left = std::max(left, rt.left); top = std::max(top, rt.top); @@ -550,21 +520,21 @@ class CFX_RTemplate { width = r - left; height = b - top; } - bool IntersectWith(const RectType& rt) const { - RectType rect = rt; + bool IntersectWith(const CFX_RectF& rt) const { + CFX_RectF rect = rt; rect.Intersect(*this); return !rect.IsEmpty(); } - bool IntersectWith(const RectType& rt, float fEpsilon) const { - RectType rect = rt; + bool IntersectWith(const CFX_RectF& rt, float fEpsilon) const { + CFX_RectF rect = rt; rect.Intersect(*this); return !rect.IsEmpty(fEpsilon); } - friend bool operator==(const RectType& rc1, const RectType& rc2) { + friend bool operator==(const CFX_RectF& rc1, const CFX_RectF& rc2) { return rc1.left == rc2.left && rc1.top == rc2.top && rc1.width == rc2.width && rc1.height == rc2.height; } - friend bool operator!=(const RectType& rc1, const RectType& rc2) { + friend bool operator!=(const CFX_RectF& rc1, const CFX_RectF& rc2) { return !(rc1 == rc2); } @@ -574,22 +544,14 @@ class CFX_RTemplate { return CFX_FloatRect(left, top, right(), bottom()); } - BaseType left; - BaseType top; - BaseType width; - BaseType height; + float left; + float top; + float width; + float height; }; -using CFX_Rect = CFX_RTemplate<int32_t>; -using CFX_RectF = CFX_RTemplate<float>; #ifndef NDEBUG -template <class BaseType> -std::ostream& operator<<(std::ostream& os, - const CFX_RTemplate<BaseType>& rect) { - os << "rect[w " << rect.Width() << " x h " << rect.Height() << " (left " - << rect.left << ", top " << rect.top << ")]"; - return os; -} +std::ostream& operator<<(std::ostream& os, const CFX_RectF& rect); #endif // NDEBUG // The matrix is of the form: diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp index 7c25d0da28..d77fe05e91 100644 --- a/core/fxcrt/fx_coordinates_unittest.cpp +++ b/core/fxcrt/fx_coordinates_unittest.cpp @@ -210,18 +210,6 @@ TEST(CFX_FloatRect, Print) { EXPECT_STREQ("rect[w 4.25 x h 3.25 (left 10.5, bot 20.5)]", os.str().c_str()); } -TEST(CFX_Rect, Print) { - std::ostringstream os; - CFX_Rect rect; - os << rect; - EXPECT_STREQ("rect[w 0 x h 0 (left 0, top 0)]", os.str().c_str()); - - os.str(""); - rect = CFX_Rect(10, 20, 4, 3); - os << rect; - EXPECT_STREQ("rect[w 4 x h 3 (left 10, top 20)]", os.str().c_str()); -} - TEST(CFX_RectF, Print) { std::ostringstream os; CFX_RectF rect; diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp index f4f6efdd0e..0b4e8f60ee 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp @@ -185,9 +185,10 @@ CFX_Matrix CPDFXFA_Page::GetDisplayMatrix(int xPos, return m_pPDFPage->GetDisplayMatrix(xPos, yPos, xSize, ySize, iRotate); FX_FALLTHROUGH; case FormType::kXFAFull: - if (m_pXFAPageView) - return m_pXFAPageView->GetDisplayMatrix( - CFX_Rect(xPos, yPos, xSize, ySize), iRotate); + if (m_pXFAPageView) { + FX_RECT rect = FX_RECT(xPos, yPos, xPos + xSize, yPos + ySize); + return m_pXFAPageView->GetDisplayMatrix(rect, iRotate); + } break; } diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp index 83b7ad68d7..6b2cb0f03b 100644 --- a/xfa/fgas/font/cfgas_gefont.cpp +++ b/xfa/fgas/font/cfgas_gefont.cpp @@ -185,7 +185,7 @@ bool CFGAS_GEFont::GetCharWidth(wchar_t wUnicode, int32_t& iWidth) { return iWidth > 0; } -bool CFGAS_GEFont::GetCharBBox(wchar_t wUnicode, CFX_Rect* bbox) { +bool CFGAS_GEFont::GetCharBBox(wchar_t wUnicode, FX_RECT* bbox) { auto it = m_BBoxMap.find(wUnicode); if (it != m_BBoxMap.end()) { *bbox = it->second; @@ -205,21 +205,18 @@ bool CFGAS_GEFont::GetCharBBox(wchar_t wUnicode, CFX_Rect* bbox) { if (!m_pFont->GetGlyphBBox(iGlyph, rtBBox)) return false; - CFX_Rect rt(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height()); - m_BBoxMap[wUnicode] = rt; - *bbox = rt; + m_BBoxMap[wUnicode] = rtBBox; + *bbox = rtBBox; return true; } -bool CFGAS_GEFont::GetBBox(CFX_Rect* bbox) { - FX_RECT rt(0, 0, 0, 0); +bool CFGAS_GEFont::GetBBox(FX_RECT* bbox) { + // TODO(thestig): Pass directly into GetBBox(). + FX_RECT rt; if (!m_pFont->GetBBox(rt)) return false; - bbox->left = rt.left; - bbox->width = rt.Width(); - bbox->top = rt.bottom; - bbox->height = -rt.Height(); + *bbox = rt; return true; } diff --git a/xfa/fgas/font/cfgas_gefont.h b/xfa/fgas/font/cfgas_gefont.h index 646562d9ee..22169d6d3d 100644 --- a/xfa/fgas/font/cfgas_gefont.h +++ b/xfa/fgas/font/cfgas_gefont.h @@ -43,8 +43,8 @@ class CFGAS_GEFont : public Retainable { int32_t GetAscent() const; int32_t GetDescent() const; - bool GetCharBBox(wchar_t wUnicode, CFX_Rect* bbox); - bool GetBBox(CFX_Rect* bbox); + bool GetCharBBox(wchar_t wUnicode, FX_RECT* bbox); + bool GetBBox(FX_RECT* bbox); RetainPtr<CFGAS_GEFont> GetSubstFont(int32_t iGlyphIndex); CFX_Font* GetDevFont() const { return m_pFont; } @@ -89,7 +89,7 @@ class CFGAS_GEFont : public Retainable { RetainPtr<IFX_SeekableReadStream> m_pFileRead; std::unique_ptr<CFX_UnicodeEncoding> m_pFontEncoding; std::map<wchar_t, int32_t> m_CharWidthMap; - std::map<wchar_t, CFX_Rect> m_BBoxMap; + std::map<wchar_t, FX_RECT> m_BBoxMap; std::vector<RetainPtr<CFGAS_GEFont>> m_SubstFonts; std::map<wchar_t, RetainPtr<CFGAS_GEFont>> m_FontMapper; }; diff --git a/xfa/fgas/layout/cfx_txtbreak.cpp b/xfa/fgas/layout/cfx_txtbreak.cpp index 30ed3a6746..c3075b00dc 100644 --- a/xfa/fgas/layout/cfx_txtbreak.cpp +++ b/xfa/fgas/layout/cfx_txtbreak.cpp @@ -851,19 +851,18 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun, } if (chartype == FX_CHARTYPE_Combination) { - CFX_Rect rtBBox; + FX_RECT rtBBox; if (pFont->GetCharBBox(wForm, &rtBBox)) { pCharPos->m_Origin.y = - fYBase + fFontSize - - fFontSize * (float)rtBBox.height / (float)iMaxHeight; + fYBase + fFontSize - fFontSize * rtBBox.Height() / iMaxHeight; } if (wForm == wch && wLast != 0xFEFF) { uint32_t dwLastProps = FX_GetUnicodeProperties(wLast); if ((dwLastProps & FX_CHARTYPEBITSMASK) == FX_CHARTYPE_Combination) { - CFX_Rect rtBox; + FX_RECT rtBox; if (pFont->GetCharBBox(wLast, &rtBox)) - pCharPos->m_Origin.y -= fFontSize * rtBox.height / iMaxHeight; + pCharPos->m_Origin.y -= fFontSize * rtBox.Height() / iMaxHeight; } } } @@ -915,12 +914,12 @@ std::vector<CFX_RectF> CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun, if (!pFont) bCharBBox = false; - CFX_Rect bbox; + FX_RECT bbox; if (bCharBBox) bCharBBox = pFont->GetBBox(&bbox); float fLeft = std::max(0.0f, bbox.left * fScale); - float fHeight = fabs(bbox.height * fScale); + float fHeight = fabs(bbox.Height() * fScale); bool bRTLPiece = !!(pTxtRun->dwCharStyles & FX_TXTCHARSTYLE_OddBidiLevel); bool bSingleLine = !!(pTxtRun->dwStyles & FX_LAYOUTSTYLE_SingleLine); bool bCombText = !!(pTxtRun->dwStyles & FX_LAYOUTSTYLE_CombText); diff --git a/xfa/fxfa/cxfa_ffpageview.cpp b/xfa/fxfa/cxfa_ffpageview.cpp index fa68cb7b81..d85ff07c0f 100644 --- a/xfa/fxfa/cxfa_ffpageview.cpp +++ b/xfa/fxfa/cxfa_ffpageview.cpp @@ -28,7 +28,7 @@ namespace { CFX_Matrix GetPageMatrix(const CFX_RectF& docPageRect, - const CFX_Rect& devicePageRect, + const FX_RECT& devicePageRect, int32_t iRotate, uint32_t dwCoordinatesType) { ASSERT(iRotate >= 0 && iRotate <= 3); @@ -37,29 +37,29 @@ CFX_Matrix GetPageMatrix(const CFX_RectF& docPageRect, bool bFlipY = (dwCoordinatesType & 0x02) != 0; CFX_Matrix m((bFlipX ? -1.0f : 1.0f), 0, 0, (bFlipY ? -1.0f : 1.0f), 0, 0); if (iRotate == 0 || iRotate == 2) { - m.a *= (float)devicePageRect.width / docPageRect.width; - m.d *= (float)devicePageRect.height / docPageRect.height; + m.a *= (float)devicePageRect.Width() / docPageRect.width; + m.d *= (float)devicePageRect.Height() / docPageRect.height; } else { - m.a *= (float)devicePageRect.height / docPageRect.width; - m.d *= (float)devicePageRect.width / docPageRect.height; + m.a *= (float)devicePageRect.Height() / docPageRect.width; + m.d *= (float)devicePageRect.Width() / docPageRect.height; } m.Rotate(iRotate * 1.57079632675f); switch (iRotate) { case 0: - m.e = bFlipX ? (float)devicePageRect.right() : (float)devicePageRect.left; - m.f = bFlipY ? (float)devicePageRect.bottom() : (float)devicePageRect.top; + m.e = bFlipX ? devicePageRect.right : devicePageRect.left; + m.f = bFlipY ? devicePageRect.bottom : devicePageRect.top; break; case 1: - m.e = bFlipY ? (float)devicePageRect.left : (float)devicePageRect.right(); - m.f = bFlipX ? (float)devicePageRect.bottom() : (float)devicePageRect.top; + m.e = bFlipY ? devicePageRect.left : devicePageRect.right; + m.f = bFlipX ? devicePageRect.bottom : devicePageRect.top; break; case 2: - m.e = bFlipX ? (float)devicePageRect.left : (float)devicePageRect.right(); - m.f = bFlipY ? (float)devicePageRect.top : (float)devicePageRect.bottom(); + m.e = bFlipX ? devicePageRect.left : devicePageRect.right; + m.f = bFlipY ? devicePageRect.top : devicePageRect.bottom; break; case 3: - m.e = bFlipY ? (float)devicePageRect.right() : (float)devicePageRect.left; - m.f = bFlipX ? (float)devicePageRect.top : (float)devicePageRect.bottom(); + m.e = bFlipY ? devicePageRect.right : devicePageRect.left; + m.f = bFlipX ? devicePageRect.top : devicePageRect.bottom; break; default: break; @@ -122,7 +122,7 @@ CFX_RectF CXFA_FFPageView::GetPageViewRect() const { return CFX_RectF(0, 0, GetPageSize()); } -CFX_Matrix CXFA_FFPageView::GetDisplayMatrix(const CFX_Rect& rtDisp, +CFX_Matrix CXFA_FFPageView::GetDisplayMatrix(const FX_RECT& rtDisp, int32_t iRotate) const { return GetPageMatrix(CFX_RectF(0, 0, GetPageSize()), rtDisp, iRotate, 0); } diff --git a/xfa/fxfa/cxfa_ffpageview.h b/xfa/fxfa/cxfa_ffpageview.h index b33e25f79d..10dac26b92 100644 --- a/xfa/fxfa/cxfa_ffpageview.h +++ b/xfa/fxfa/cxfa_ffpageview.h @@ -25,7 +25,7 @@ class CXFA_FFPageView : public CXFA_ContainerLayoutItem { CXFA_FFDocView* GetDocView() const; CFX_RectF GetPageViewRect() const; - CFX_Matrix GetDisplayMatrix(const CFX_Rect& rtDisp, int32_t iRotate) const; + CFX_Matrix GetDisplayMatrix(const FX_RECT& rtDisp, int32_t iRotate) const; std::unique_ptr<IXFA_WidgetIterator> CreateWidgetIterator( uint32_t dwTraverseWay, uint32_t dwWidgetFilter); diff --git a/xfa/fxgraphics/cxfa_graphics.cpp b/xfa/fxgraphics/cxfa_graphics.cpp index b13ecc060d..ae1e04acca 100644 --- a/xfa/fxgraphics/cxfa_graphics.cpp +++ b/xfa/fxgraphics/cxfa_graphics.cpp @@ -214,7 +214,7 @@ CFX_RectF CXFA_Graphics::GetClipRect() const { return CFX_RectF(); FX_RECT r = m_renderDevice->GetClipBox(); - return CFX_Rect(r.left, r.top, r.Width(), r.Height()).As<float>(); + return CFX_RectF(r.left, r.top, r.Width(), r.Height()); } void CXFA_Graphics::SetClipRect(const CFX_RectF& rect) { |