Chromium Code Reviews| Index: ui/gfx/canvas_ios.mm |
| diff --git a/ui/gfx/canvas_ios.mm b/ui/gfx/canvas_ios.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..da431e82a72430687e67a4cb1df9e6695e4ad7c7 |
| --- /dev/null |
| +++ b/ui/gfx/canvas_ios.mm |
| @@ -0,0 +1,44 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/gfx/canvas.h" |
| + |
| +#import <UIKit/UIKit.h> |
| + |
| +#include <algorithm> |
| +#include <cmath> |
| + |
| +#include "base/logging.h" |
| +#include "base/strings/sys_string_conversions.h" |
| +#include "ui/gfx/font_list.h" |
| + |
| +namespace gfx { |
| + |
| +// static |
| +void Canvas::SizeStringInt(const base::string16& text, |
| + const gfx::FontList& font_list, |
| + int* width, |
| + int* height, |
| + int line_height, |
| + int flags) { |
| + DLOG_IF(WARNING, line_height != 0) << "Line height not implemented."; |
| + DLOG_IF(WARNING, flags & Canvas::MULTI_LINE) << "Multi-line not implemented."; |
| + |
| + NSString* ns_text = base::SysUTF16ToNSString(text); |
| + CGSize size = [ns_text |
| + sizeWithFont:font_list.GetPrimaryFont().GetNativeFont()]; |
|
Alexei Svitkine (slow)
2013/08/19 14:17:28
Nit: Extract NativeFont into a local var so that t
msw
2013/08/19 19:05:43
Could this implementation be merged with canvas_ma
stuartmorgan
2013/08/19 22:08:11
This is the public documentation for the iOS equiv
Yuki
2013/08/20 15:05:47
Done.
|
| + *width = std::ceil(size.width); |
| + *height = std::max(static_cast<int>(std::ceil(size.height)), |
| + font_list.GetHeight()); |
| +} |
| + |
| +// static |
| +int Canvas::GetStringWidth(const base::string16& text, |
| + const gfx::FontList& font_list) { |
| + int width = 0, height = 0; |
| + SizeStringInt(text, font_list, &width, &height, 0, NO_ELLIPSIS); |
| + return width; |
| +} |
| + |
| +} // namespace gfx |