summaryrefslogtreecommitdiffstats
path: root/ui/gfx/canvas_mac.mm
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-17 18:33:36 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-17 18:33:36 +0000
commit29b8d7edef88b2b9319b8698d3f8aa6280d340e2 (patch)
treeb65d744f69f6eeb354593d91a01326271f9cff22 /ui/gfx/canvas_mac.mm
parenta0bd3fbc565acf25bfb77e6240d89ab4d24c5399 (diff)
downloadchromium_src-29b8d7edef88b2b9319b8698d3f8aa6280d340e2.zip
chromium_src-29b8d7edef88b2b9319b8698d3f8aa6280d340e2.tar.gz
chromium_src-29b8d7edef88b2b9319b8698d3f8aa6280d340e2.tar.bz2
ui/gfx: Fix the file names of "canvas_skia_*" to say just "canvas_platform".
BUG=116572 R=asvitkine@chromium.org TBR=sky@chromium.org Review URL: https://chromiumcodereview.appspot.com/9719018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127369 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/canvas_mac.mm')
-rw-r--r--ui/gfx/canvas_mac.mm79
1 files changed, 79 insertions, 0 deletions
diff --git a/ui/gfx/canvas_mac.mm b/ui/gfx/canvas_mac.mm
new file mode 100644
index 0000000..5230a1d
--- /dev/null
+++ b/ui/gfx/canvas_mac.mm
@@ -0,0 +1,79 @@
+// Copyright (c) 2012 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.
+
+#import <Cocoa/Cocoa.h>
+
+#include "ui/gfx/canvas.h"
+
+#include "base/logging.h"
+#include "base/sys_string_conversions.h"
+#include "third_party/skia/include/core/SkTypeface.h"
+#include "ui/gfx/font.h"
+
+// Note: This is a temporary Skia-based implementation of the ui/gfx text
+// rendering routines for views/aura. It replaces the stale Cocoa-based
+// implementation. A future |canvas_skia_skia.cc| implementation will supersede
+// this and the other platform-specific implmenentations.
+// Most drawing options, such as alignment and multi-line, are not implemented
+// here.
+
+namespace {
+
+SkTypeface::Style FontTypefaceStyle(const gfx::Font& font) {
+ int style = 0;
+ if (font.GetStyle() & gfx::Font::BOLD)
+ style |= SkTypeface::kBold;
+ if (font.GetStyle() & gfx::Font::ITALIC)
+ style |= SkTypeface::kItalic;
+
+ return static_cast<SkTypeface::Style>(style);
+}
+
+} // namespace
+
+namespace gfx {
+
+// static
+void Canvas::SizeStringInt(const string16& text,
+ const gfx::Font& font,
+ int* width,
+ int* height,
+ int flags) {
+ NSFont* native_font = font.GetNativeFont();
+ NSString* ns_string = base::SysUTF16ToNSString(text);
+ NSDictionary* attributes =
+ [NSDictionary dictionaryWithObject:native_font
+ forKey:NSFontAttributeName];
+ NSSize string_size = [ns_string sizeWithAttributes:attributes];
+ *width = string_size.width;
+ *height = font.GetHeight();
+}
+
+void Canvas::DrawStringInt(const string16& text,
+ const gfx::Font& font,
+ const SkColor& color,
+ int x, int y, int w, int h,
+ int flags) {
+ SkTypeface* typeface = SkTypeface::CreateFromName(font.GetFontName().c_str(),
+ FontTypefaceStyle(font));
+ SkPaint paint;
+ paint.setTypeface(typeface);
+ typeface->unref();
+ paint.setColor(color);
+ canvas_->drawText(text.c_str(),
+ text.size() * sizeof(string16::value_type),
+ x,
+ y + h,
+ paint);
+}
+
+void Canvas::DrawStringWithHalo(const string16& text,
+ const gfx::Font& font,
+ const SkColor& text_color,
+ const SkColor& halo_color,
+ int x, int y, int w, int h,
+ int flags) {
+}
+
+} // namespace gfx