Use TextGlyphPos::GetOrigin() in GetGlyphsBBox().
Use Optional::value() in a few more places as well for consistency.
Change-Id: If502bec2c312a8a80975293b66a27c19d3096894
Reviewed-on: https://pdfium-review.googlesource.com/c/50131
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index 17770b1..dfb7f0d 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -990,8 +990,9 @@
continue;
const RetainPtr<CFX_DIBitmap>& pGlyph = glyph.m_pGlyph->GetBitmap();
- bitmap->TransferBitmap(point->x, point->y, pGlyph->GetWidth(),
- pGlyph->GetHeight(), pGlyph, 0, 0);
+ bitmap->TransferBitmap(point.value().x, point.value().y,
+ pGlyph->GetWidth(), pGlyph->GetHeight(), pGlyph, 0,
+ 0);
}
return SetBitMask(bitmap, bmp_rect.left, bmp_rect.top, fill_color);
}
@@ -1032,9 +1033,9 @@
int ncols = pGlyph->GetWidth();
int nrows = pGlyph->GetHeight();
if (anti_alias == FXFT_RENDER_MODE_NORMAL) {
- if (!bitmap->CompositeMask(point->x, point->y, ncols, nrows, pGlyph,
- fill_color, 0, 0, BlendMode::kNormal, nullptr,
- false, 0)) {
+ if (!bitmap->CompositeMask(point.value().x, point.value().y, ncols, nrows,
+ pGlyph, fill_color, 0, 0, BlendMode::kNormal,
+ nullptr, false, 0)) {
return false;
}
continue;
diff --git a/core/fxge/fx_font.cpp b/core/fxge/fx_font.cpp
index 2654998..1c79f1c 100644
--- a/core/fxge/fx_font.cpp
+++ b/core/fxge/fx_font.cpp
@@ -4,6 +4,8 @@
#include "core/fxge/fx_font.h"
+#include <algorithm>
+
#include "core/fxge/cfx_glyphbitmap.h"
#include "core/fxge/dib/cfx_dibitmap.h"
#include "core/fxge/text_glyph_pos.h"
@@ -23,56 +25,43 @@
} // namespace
FX_RECT GetGlyphsBBox(const std::vector<TextGlyphPos>& glyphs, int anti_alias) {
- FX_RECT rect(0, 0, 0, 0);
+ FX_RECT rect;
bool bStarted = false;
for (const TextGlyphPos& glyph : glyphs) {
- const CFX_GlyphBitmap* pGlyph = glyph.m_pGlyph;
- if (!pGlyph)
+ if (!glyph.m_pGlyph)
continue;
- FX_SAFE_INT32 char_left = glyph.m_Origin.x;
- char_left += pGlyph->left();
- if (!char_left.IsValid())
+ Optional<CFX_Point> point = glyph.GetOrigin({0, 0});
+ if (!point.has_value())
continue;
- FX_SAFE_INT32 char_width = pGlyph->GetBitmap()->GetWidth();
+ int char_width = glyph.m_pGlyph->GetBitmap()->GetWidth();
if (anti_alias == FXFT_RENDER_MODE_LCD)
char_width /= 3;
- if (!char_width.IsValid())
- continue;
- FX_SAFE_INT32 char_right = char_left + char_width;
+ FX_SAFE_INT32 char_right = point.value().x;
+ char_right += char_width;
if (!char_right.IsValid())
continue;
- FX_SAFE_INT32 char_top = glyph.m_Origin.y;
- char_top -= pGlyph->top();
- if (!char_top.IsValid())
- continue;
-
- FX_SAFE_INT32 char_height = pGlyph->GetBitmap()->GetHeight();
- if (!char_height.IsValid())
- continue;
-
- FX_SAFE_INT32 char_bottom = char_top + char_height;
+ FX_SAFE_INT32 char_bottom = point.value().y;
+ char_bottom += glyph.m_pGlyph->GetBitmap()->GetHeight();
if (!char_bottom.IsValid())
continue;
if (bStarted) {
- rect.left = pdfium::base::ValueOrDieForType<int32_t>(
- pdfium::base::CheckMin(rect.left, char_left));
+ rect.left = std::min(rect.left, point.value().x);
+ rect.top = std::min(rect.top, point.value().y);
rect.right = pdfium::base::ValueOrDieForType<int32_t>(
pdfium::base::CheckMax(rect.right, char_right));
- rect.top = pdfium::base::ValueOrDieForType<int32_t>(
- pdfium::base::CheckMin(rect.top, char_top));
rect.bottom = pdfium::base::ValueOrDieForType<int32_t>(
pdfium::base::CheckMax(rect.bottom, char_bottom));
continue;
}
- rect.left = char_left.ValueOrDie();
+ rect.left = point.value().x;
+ rect.top = point.value().y;
rect.right = char_right.ValueOrDie();
- rect.top = char_top.ValueOrDie();
rect.bottom = char_bottom.ValueOrDie();
bStarted = true;
}