summaryrefslogtreecommitdiff
path: root/chromium/ui/gfx/text_utils.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/ui/gfx/text_utils.h
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-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.h')
-rw-r--r--chromium/ui/gfx/text_utils.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/chromium/ui/gfx/text_utils.h b/chromium/ui/gfx/text_utils.h
index 4b6b5cae13e..ea342ee5a8c 100644
--- a/chromium/ui/gfx/text_utils.h
+++ b/chromium/ui/gfx/text_utils.h
@@ -14,6 +14,8 @@
namespace gfx {
class FontList;
+class Insets;
+class Size;
// Strip the accelerator char (typically '&') from a menu string. A double
// accelerator char ('&&') will be converted to a single char. The out params
@@ -31,6 +33,12 @@ GFX_EXPORT base::string16 RemoveAcceleratorChar(const base::string16& s,
GFX_EXPORT int GetStringWidth(const base::string16& text,
const FontList& font_list);
+// Returns the size required to render |text| in |font_list|. This includes all
+// leading space, descender area, etc. even if the text to render does not
+// contain characters with ascenders or descenders.
+GFX_EXPORT Size GetStringSize(const base::string16& text,
+ const FontList& font_list);
+
// This is same as GetStringWidth except that fractional width is returned.
GFX_EXPORT float GetStringWidthF(const base::string16& text,
const FontList& font_list);
@@ -50,6 +58,72 @@ GFX_EXPORT size_t FindValidBoundaryAfter(const base::string16& text,
// If the UI layout is right-to-left, flip the alignment direction.
GFX_EXPORT HorizontalAlignment MaybeFlipForRTL(HorizontalAlignment alignment);
+// Returns insets that can be used to draw a highlight or border that appears to
+// be distance |desired_visual_padding| from the body of a string of text
+// rendered using |font_list|. The insets are adjusted based on the box used to
+// render capital letters (or the bodies of most letters in non-capital fonts
+// like Hebrew and Devanagari), in order to give the best visual appearance.
+//
+// That is, any portion of |desired_visual_padding| overlapping the font's
+// leading space or descender area are truncated, to a minimum of zero.
+//
+// In this example, the text is rendered in a highlight that stretches above and
+// below the height of the H as well as to the left and right of the text
+// (|desired_visual_padding| = {2, 2, 2, 2}). Note that the descender of the 'y'
+// overlaps with the padding, as it is outside the capital letter box.
+//
+// The resulting padding is {1, 2, 1, 2}.
+//
+// . . . . . . . . . . | actual top
+// . . | | leading space
+// . | | _ . | font | capital
+// . |--| /_\ \ / . | height | height
+// . | | \_ \/ . | |
+// . / . | | descender
+// . . . . . . . . . . | actual bottom
+// ___ ___
+// actual actual
+// left right
+//
+GFX_EXPORT Insets
+AdjustVisualBorderForFont(const FontList& font_list,
+ const Insets& desired_visual_padding);
+
+// Returns the y adjustment necessary to align the center of the "cap size" box
+// - the space between a capital letter's top and bottom - between two fonts.
+// For non-capital scripts (e.g. Hebrew, Devanagari) the box containing the body
+// of most letters is used.
+//
+// A positive return value means the font |to_center| needs to be moved down
+// relative to the font |original_font|, while a negative value means it needs
+// to be moved up.
+//
+// Illustration:
+//
+// original_font to_center
+// ---------- ] - return value (+1)
+// leading ----------
+// ---------- leading
+// ----------
+//
+// cap-height cap-height
+//
+// ----------
+// ---------- descent
+// descent ----------
+// ----------
+//
+// Visual result: Non-Latin example (Devanagari ऐ "ai"):
+// \
+// |\ | ------ \
+// | \ | |\ | | | ----
+// | \ | | \| \ / \|
+// | \| \ /
+// /
+//
+GFX_EXPORT int GetFontCapHeightCenterOffset(const gfx::FontList& original_font,
+ const gfx::FontList& to_center);
+
} // namespace gfx
#endif // UI_GFX_TEXT_UTILS_H_