diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/ui/gfx/text_utils.cc | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/ui/gfx/text_utils.cc')
-rw-r--r-- | chromium/ui/gfx/text_utils.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/chromium/ui/gfx/text_utils.cc b/chromium/ui/gfx/text_utils.cc index fa062ea8972..dba839e87eb 100644 --- a/chromium/ui/gfx/text_utils.cc +++ b/chromium/ui/gfx/text_utils.cc @@ -11,6 +11,10 @@ #include "base/numerics/safe_conversions.h" #include "third_party/icu/source/common/unicode/uchar.h" #include "third_party/icu/source/common/unicode/utf16.h" +#include "ui/gfx/font_list.h" +#include "ui/gfx/geometry/insets.h" +#include "ui/gfx/geometry/rect.h" +#include "ui/gfx/geometry/size.h" namespace gfx { @@ -126,4 +130,36 @@ HorizontalAlignment MaybeFlipForRTL(HorizontalAlignment alignment) { return alignment; } +Size GetStringSize(const base::string16& text, const FontList& font_list) { + return Size(GetStringWidth(text, font_list), font_list.GetHeight()); +} + +Insets AdjustVisualBorderForFont(const FontList& font_list, + const Insets& desired_visual_padding) { + Insets result = desired_visual_padding; + const int baseline = font_list.GetBaseline(); + const int leading_space = baseline - font_list.GetCapHeight(); + const int descender = font_list.GetHeight() - baseline; + result.set_top(std::max(0, result.top() - leading_space)); + result.set_bottom(std::max(0, result.bottom() - descender)); + return result; +} + +int GetFontCapHeightCenterOffset(const gfx::FontList& original_font, + const gfx::FontList& to_center) { + const int original_cap_height = original_font.GetCapHeight(); + const int original_cap_leading = + original_font.GetBaseline() - original_cap_height; + const int to_center_cap_height = to_center.GetCapHeight(); + const int to_center_leading = to_center.GetBaseline() - to_center_cap_height; + + const int cap_height_diff = original_cap_height - to_center_cap_height; + const int new_cap_top = + original_cap_leading + std::lround(cap_height_diff / 2.0f); + const int new_top = new_cap_top - to_center_leading; + + // Since we assume the old font starts at zero, the new top is the adjustment. + return new_top; +} + } // namespace gfx |