summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/include/fpdfapi/fpdf_resource.h8
-rw-r--r--core/include/fxcrt/fx_coordinates.h378
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font.cpp74
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp56
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page.cpp3
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render.cpp18
-rw-r--r--core/src/fpdftext/fpdf_text_int.cpp30
8 files changed, 264 insertions, 307 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:
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index fb601e7113..411f77254b 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -306,8 +306,7 @@ void CPDF_Font::CheckFontMetrics() {
} else {
FX_BOOL bFirst = TRUE;
for (int i = 0; i < 256; i++) {
- FX_RECT rect;
- GetCharBBox(i, rect);
+ FX_RECT rect = GetCharBBox(i);
if (rect.left == rect.right) {
continue;
}
@@ -332,19 +331,10 @@ void CPDF_Font::CheckFontMetrics() {
}
}
if (m_Ascent == 0 && m_Descent == 0) {
- FX_RECT rect;
- GetCharBBox('A', rect);
- if (rect.bottom == rect.top) {
- m_Ascent = m_FontBBox.top;
- } else {
- m_Ascent = rect.top;
- }
- GetCharBBox('g', rect);
- if (rect.bottom == rect.top) {
- m_Descent = m_FontBBox.bottom;
- } else {
- m_Descent = rect.bottom;
- }
+ FX_RECT rect = GetCharBBox('A');
+ m_Ascent = rect.bottom == rect.top ? m_FontBBox.top : rect.top;
+ rect = GetCharBBox('g');
+ m_Descent = rect.bottom == rect.top ? m_FontBBox.bottom : rect.bottom;
}
}
@@ -743,13 +733,11 @@ FX_BOOL CPDF_Font::IsStandardFont() const {
return TRUE;
}
-CPDF_SimpleFont::CPDF_SimpleFont() {
- FXSYS_memset(m_CharBBox, 0xff, sizeof m_CharBBox);
+CPDF_SimpleFont::CPDF_SimpleFont()
+ : m_pCharNames(nullptr), m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) {
FXSYS_memset(m_CharWidth, 0xff, sizeof m_CharWidth);
FXSYS_memset(m_GlyphIndex, 0xff, sizeof m_GlyphIndex);
FXSYS_memset(m_ExtGID, 0xff, sizeof m_ExtGID);
- m_pCharNames = NULL;
- m_BaseEncoding = PDFFONT_ENCODING_BUILTIN;
}
CPDF_SimpleFont::~CPDF_SimpleFont() {
@@ -795,21 +783,23 @@ void CPDF_SimpleFont::LoadCharMetrics(int charcode) {
if (err) {
return;
}
- m_CharBBox[charcode].Left = TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face);
- m_CharBBox[charcode].Right = TT2PDF(
- FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face), face);
- m_CharBBox[charcode].Top = TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face);
- m_CharBBox[charcode].Bottom = TT2PDF(
- FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face), face);
+ m_CharBBox[charcode] = FX_SMALL_RECT(
+ TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face),
+ TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face),
+ TT2PDF(FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face),
+ face),
+ TT2PDF(FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face),
+ face));
+
if (m_bUseFontWidth) {
int TT_Width = TT2PDF(FXFT_Get_Glyph_HoriAdvance(face), face);
if (m_CharWidth[charcode] == 0xffff) {
m_CharWidth[charcode] = TT_Width;
} else if (TT_Width && !IsEmbedded()) {
- m_CharBBox[charcode].Right =
- m_CharBBox[charcode].Right * m_CharWidth[charcode] / TT_Width;
- m_CharBBox[charcode].Left =
- m_CharBBox[charcode].Left * m_CharWidth[charcode] / TT_Width;
+ m_CharBBox[charcode].right =
+ m_CharBBox[charcode].right * m_CharWidth[charcode] / TT_Width;
+ m_CharBBox[charcode].left =
+ m_CharBBox[charcode].left * m_CharWidth[charcode] / TT_Width;
}
}
}
@@ -827,17 +817,14 @@ int CPDF_SimpleFont::GetCharWidthF(FX_DWORD charcode, int level) {
return (int16_t)m_CharWidth[charcode];
}
-void CPDF_SimpleFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) {
- if (charcode > 0xff) {
+FX_RECT CPDF_SimpleFont::GetCharBBox(FX_DWORD charcode, int level) {
+ if (charcode > 0xff)
charcode = 0;
- }
- if (m_CharBBox[charcode].Left == (int16_t)0xffff) {
+
+ if (m_CharBBox[charcode].left == FX_SMALL_RECT::kInvalid)
LoadCharMetrics(charcode);
- }
- rect.left = m_CharBBox[charcode].Left;
- rect.right = m_CharBBox[charcode].Right;
- rect.bottom = m_CharBBox[charcode].Bottom;
- rect.top = m_CharBBox[charcode].Top;
+
+ return FX_RECT(m_CharBBox[charcode]);
}
const FX_CHAR* GetAdobeCharName(int iBaseEncoding,
@@ -1704,16 +1691,9 @@ int CPDF_Type3Font::GetCharWidthF(FX_DWORD charcode, int level) {
return pChar ? pChar->m_Width : 0;
}
-void CPDF_Type3Font::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) {
+FX_RECT CPDF_Type3Font::GetCharBBox(FX_DWORD charcode, int level) {
const CPDF_Type3Char* pChar = LoadChar(charcode, level);
- if (!pChar) {
- rect.left = 0;
- rect.right = 0;
- rect.top = 0;
- rect.bottom = 0;
- return;
- }
- rect = pChar->m_BBox;
+ return pChar ? pChar->m_BBox : FX_RECT();
}
CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm)
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
index de6ed1b9b5..1a78b1f93c 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
@@ -1057,7 +1057,6 @@ CPDF_CIDFont::CPDF_CIDFont()
m_pAnsiWidths(nullptr),
m_bAdobeCourierStd(FALSE),
m_pTTGSUBTable(nullptr) {
- FXSYS_memset(m_CharBBox, 0xff, 256 * sizeof(FX_SMALL_RECT));
}
CPDF_CIDFont::~CPDF_CIDFont() {
@@ -1299,19 +1298,15 @@ FX_BOOL CPDF_CIDFont::Load() {
return TRUE;
}
-void CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) {
- if (charcode < 256 && m_CharBBox[charcode].Right != -1) {
- rect.bottom = m_CharBBox[charcode].Bottom;
- rect.left = m_CharBBox[charcode].Left;
- rect.right = m_CharBBox[charcode].Right;
- rect.top = m_CharBBox[charcode].Top;
- return;
- }
+FX_RECT CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, int level) {
+ if (charcode < 256 && m_CharBBox[charcode].right != FX_SMALL_RECT::kInvalid)
+ return FX_RECT(m_CharBBox[charcode]);
+
+ FX_RECT rect;
FX_BOOL bVert = FALSE;
int glyph_index = GlyphFromCharCode(charcode, &bVert);
FXFT_Face face = m_Font.GetFace();
if (face) {
- rect.left = rect.bottom = rect.right = rect.top = 0;
if (FXFT_Is_Face_Tricky(face)) {
int err = FXFT_Load_Glyph(face, glyph_index,
FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
@@ -1324,15 +1319,12 @@ void CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) {
int pixel_size_x = ((FXFT_Face)face)->size->metrics.x_ppem;
int pixel_size_y = ((FXFT_Face)face)->size->metrics.y_ppem;
if (pixel_size_x == 0 || pixel_size_y == 0) {
- rect.left = cbox.xMin;
- rect.right = cbox.xMax;
- rect.top = cbox.yMax;
- rect.bottom = cbox.yMin;
+ rect = FX_RECT(cbox.xMin, cbox.yMax, cbox.xMax, cbox.yMin);
} else {
- rect.left = cbox.xMin * 1000 / pixel_size_x;
- rect.right = cbox.xMax * 1000 / pixel_size_x;
- rect.top = cbox.yMax * 1000 / pixel_size_y;
- rect.bottom = cbox.yMin * 1000 / pixel_size_y;
+ rect = FX_RECT(cbox.xMin * 1000 / pixel_size_x,
+ cbox.yMax * 1000 / pixel_size_y,
+ cbox.xMax * 1000 / pixel_size_x,
+ cbox.yMin * 1000 / pixel_size_y);
}
if (rect.top > FXFT_Get_Face_Ascender(face)) {
rect.top = FXFT_Get_Face_Ascender(face);
@@ -1346,19 +1338,17 @@ void CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) {
} else {
int err = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_NO_SCALE);
if (err == 0) {
- rect.left = TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face);
- rect.right = TT2PDF(
- FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face),
- face);
- rect.top = TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face);
+ rect = FX_RECT(TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face),
+ TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face),
+ TT2PDF(FXFT_Get_Glyph_HoriBearingX(face) +
+ FXFT_Get_Glyph_Width(face),
+ face),
+ TT2PDF(FXFT_Get_Glyph_HoriBearingY(face) -
+ FXFT_Get_Glyph_Height(face),
+ face));
rect.top += rect.top / 64;
- rect.bottom = TT2PDF(
- FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face),
- face);
}
}
- } else {
- rect = FX_RECT(0, 0, 0, 0);
}
if (!m_pFontFile && m_Charset == CIDSET_JAPAN1) {
FX_WORD CID = CIDFromCharCode(charcode);
@@ -1375,12 +1365,10 @@ void CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) {
rect = rect_f.GetOutterRect();
}
}
- if (charcode < 256) {
- m_CharBBox[charcode].Bottom = (short)rect.bottom;
- m_CharBBox[charcode].Left = (short)rect.left;
- m_CharBBox[charcode].Right = (short)rect.right;
- m_CharBBox[charcode].Top = (short)rect.top;
- }
+ if (charcode < 256)
+ m_CharBBox[charcode] = rect.ToSmallRect();
+
+ return rect;
}
int CPDF_CIDFont::GetCharWidthF(FX_DWORD charcode, int level) {
if (m_pAnsiWidths && charcode < 0x80) {
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
index f05c4bea92..301fca8969 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
@@ -251,8 +251,7 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX,
}
m_pCharPos[i - 1] = curpos;
}
- FX_RECT char_rect;
- pFont->GetCharBBox(charcode, char_rect, level);
+ FX_RECT char_rect = pFont->GetCharBBox(charcode, level);
FX_FLOAT charwidth;
if (!bVertWriting) {
if (min_y > char_rect.top) {
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
index 44492b1a54..a294d3bce7 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
@@ -123,10 +123,10 @@ CFX_FloatRect CPDF_ClipPath::GetClipBox() const {
bLayerStarted = FALSE;
} else {
if (!bLayerStarted) {
- layer_rect = pTextObj->GetBBox(NULL);
+ layer_rect = CFX_FloatRect(pTextObj->GetBBox(nullptr));
bLayerStarted = TRUE;
} else {
- layer_rect.Union(pTextObj->GetBBox(NULL));
+ layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox(nullptr)));
}
}
}
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
index a470e94b86..4c7abea30c 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
@@ -240,7 +240,7 @@ FX_BOOL CPDF_RenderStatus::Initialize(CPDF_RenderContext* pContext,
void CPDF_RenderStatus::RenderObjectList(
const CPDF_PageObjectHolder* pObjectHolder,
const CFX_Matrix* pObj2Device) {
- CFX_FloatRect clip_rect = m_pDevice->GetClipBox();
+ CFX_FloatRect clip_rect(m_pDevice->GetClipBox());
CFX_Matrix device2object;
device2object.SetReverse(*pObj2Device);
device2object.TransformRect(clip_rect);
@@ -1059,7 +1059,7 @@ void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) {
m_pContext, m_pDevice, NULL, NULL, NULL, NULL, m_pOptions,
m_pCurrentLayer->m_pObjectHolder->m_Transparency, FALSE, NULL);
m_pDevice->SaveState();
- m_ClipRect = m_pDevice->GetClipBox();
+ m_ClipRect = CFX_FloatRect(m_pDevice->GetClipBox());
CFX_Matrix device2object;
device2object.SetReverse(m_pCurrentLayer->m_Matrix);
device2object.TransformRect(m_ClipRect);
@@ -1295,18 +1295,16 @@ FX_BOOL CPDF_ScaledRenderBuffer::Initialize(CPDF_RenderContext* pContext,
dibFormat = FXDIB_Argb;
bpp = 32;
}
- CFX_FloatRect rect;
- int32_t iWidth, iHeight, iPitch;
while (1) {
- rect = pRect;
+ CFX_FloatRect rect(pRect);
m_Matrix.TransformRect(rect);
FX_RECT bitmap_rect = rect.GetOutterRect();
- iWidth = bitmap_rect.Width();
- iHeight = bitmap_rect.Height();
- iPitch = (iWidth * bpp + 31) / 32 * 4;
- if (iWidth * iHeight < 1) {
+ int32_t iWidth = bitmap_rect.Width();
+ int32_t iHeight = bitmap_rect.Height();
+ int32_t iPitch = (iWidth * bpp + 31) / 32 * 4;
+ if (iWidth * iHeight < 1)
return FALSE;
- }
+
if (iPitch * iHeight <= _FPDFAPI_IMAGESIZE_LIMIT_ &&
m_pBitmapDevice->Create(iWidth, iHeight, dibFormat)) {
break;
diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp
index 77b610a7e8..4a0aae501c 100644
--- a/core/src/fpdftext/fpdf_text_int.cpp
+++ b/core/src/fpdftext/fpdf_text_int.cpp
@@ -884,21 +884,18 @@ void CPDF_TextPage::ProcessFormObject(CPDF_FormObject* pFormObj,
}
int CPDF_TextPage::GetCharWidth(FX_DWORD charCode, CPDF_Font* pFont) const {
- if (charCode == -1) {
+ if (charCode == -1)
return 0;
- }
- int w = pFont->GetCharWidthF(charCode);
- if (w == 0) {
- CFX_ByteString str;
- pFont->AppendChar(str, charCode);
- w = pFont->GetStringWidth(str, 1);
- if (w == 0) {
- FX_RECT BBox;
- pFont->GetCharBBox(charCode, BBox);
- w = BBox.right - BBox.left;
- }
- }
- return w;
+
+ if (int w = pFont->GetCharWidthF(charCode))
+ return w;
+
+ CFX_ByteString str;
+ pFont->AppendChar(str, charCode);
+ if (int w = pFont->GetStringWidth(str, 1))
+ return w;
+
+ return pFont->GetCharBBox(charCode).Width();
}
void CPDF_TextPage::OnPiece(CFX_BidiChar* pBidi, CFX_WideString& str) {
@@ -1464,9 +1461,8 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) {
charinfo.m_OriginX = 0, charinfo.m_OriginY = 0;
matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX,
charinfo.m_OriginY);
- FX_RECT rect(0, 0, 0, 0);
- rect.Intersect(0, 0, 0, 0);
- charinfo.m_pTextObj->GetFont()->GetCharBBox(charinfo.m_CharCode, rect);
+ FX_RECT rect =
+ charinfo.m_pTextObj->GetFont()->GetCharBBox(charinfo.m_CharCode);
charinfo.m_CharBox.top =
rect.top * pTextObj->GetFontSize() / 1000 + item.m_OriginY;
charinfo.m_CharBox.left =