diff options
author | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-10 09:57:19 +0000 |
---|---|---|
committer | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-10 09:57:19 +0000 |
commit | 8ad3c5a758ba0d46bee600f559a7af88d3038ea6 (patch) | |
tree | fd317d0b10b4740b3c0965c14dedd0f945eaf675 /ui/gfx/canvas.h | |
parent | 51cc0bd3ab9e3e8d905d4fce624cd352e2d97915 (diff) | |
download | chromium_src-8ad3c5a758ba0d46bee600f559a7af88d3038ea6.zip chromium_src-8ad3c5a758ba0d46bee600f559a7af88d3038ea6.tar.gz chromium_src-8ad3c5a758ba0d46bee600f559a7af88d3038ea6.tar.bz2 |
Uses and returns the fractional width in text eliding
On Mac, the width is repsented as CGFloat due to possible sub-pixel
rendering and extra kerning. We need to return the fractional widt,
instead of the integral width.
Some tests have been updated with the hack removed.
BUG=288987
TEST=new tests plus updating existing tests
Review URL: https://codereview.chromium.org/24883002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227905 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/canvas.h')
-rw-r--r-- | ui/gfx/canvas.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/ui/gfx/canvas.h b/ui/gfx/canvas.h index 9aa7a0a..4470023 100644 --- a/ui/gfx/canvas.h +++ b/ui/gfx/canvas.h @@ -139,6 +139,15 @@ class GFX_EXPORT Canvas { int line_height, int flags); + // This is same as SizeStringInt except that fractional size is returned. + // See comment in GetStringWidthF for its usage. + static void SizeStringFloat(const base::string16& text, + const FontList& font_list, + float* width, + float* height, + int line_height, + int flags); + // Returns the number of horizontal pixels needed to display the specified // |text| with |font_list|. static int GetStringWidth(const base::string16& text, @@ -146,6 +155,14 @@ class GFX_EXPORT Canvas { // Obsolete version. Use the above version which takes FontList. static int GetStringWidth(const base::string16& text, const Font& font); + // This is same as GetStringWidth except that fractional width is returned. + // Use this method for the scenario that multiple string widths need to be + // summed up. This is because GetStringWidth returns the ceiled width and + // adding multiple ceiled widths could cause more precision loss for certain + // platform like Mac where the fractioal width is used. + static float GetStringWidthF(const base::string16& text, + const FontList& font_list); + // Returns the default text alignment to be used when drawing text on a // Canvas based on the directionality of the system locale language. // This function is used by Canvas::DrawStringInt when the text alignment |