summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-14 01:07:57 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-14 01:07:57 +0000
commit7c1e647e347170863f3ddf513d4f7a2b970e420e (patch)
tree2cfdbbc6e1c764db0a184eccf13147c3d600fc66 /ui
parentdf3329492816f35746b0bff443bab94a98ff1dc2 (diff)
downloadchromium_src-7c1e647e347170863f3ddf513d4f7a2b970e420e.zip
chromium_src-7c1e647e347170863f3ddf513d4f7a2b970e420e.tar.gz
chromium_src-7c1e647e347170863f3ddf513d4f7a2b970e420e.tar.bz2
Reimplement CanvasSkiaMac in terms of pure Skia for demo purposes
The existing Cocoa-based implementation of CanvasSkia is stale and broken. The Mac/Aura shell work needs basic text rendering to properly render views Button controls. The changes here provide a minimal working implementation to this end. A larger effort to render UI text using pure Skia is underway and will eventually replace canvas_skia_(mac|win|linux|...).cc with a single canvas_skia_skia.cc. BUG=None TEST=Manual using Mac/Aura shell, observe text button text appearance. R=asvitkine@chromium.org, ben@chromium.org Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=117461 Review URL: http://codereview.chromium.org/9185022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117746 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/canvas_skia.h2
-rw-r--r--ui/gfx/canvas_skia_mac.mm89
2 files changed, 44 insertions, 47 deletions
diff --git a/ui/gfx/canvas_skia.h b/ui/gfx/canvas_skia.h
index 6115dd3..0f0db78 100644
--- a/ui/gfx/canvas_skia.h
+++ b/ui/gfx/canvas_skia.h
@@ -84,7 +84,6 @@ class UI_EXPORT CanvasSkia : public Canvas {
void DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y);
#endif
-#if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
// Draws text with a 1-pixel halo around it of the given color.
// On Windows, it allows ClearType to be drawn to an otherwise transparenct
// bitmap for drag images. Drag images have only 1-bit of transparency, so
@@ -97,7 +96,6 @@ class UI_EXPORT CanvasSkia : public Canvas {
const SkColor& halo_color,
int x, int y, int w, int h,
int flags);
-#endif
// Extracts a bitmap from the contents of this canvas.
SkBitmap ExtractBitmap() const;
diff --git a/ui/gfx/canvas_skia_mac.mm b/ui/gfx/canvas_skia_mac.mm
index 8018295..8580eb7 100644
--- a/ui/gfx/canvas_skia_mac.mm
+++ b/ui/gfx/canvas_skia_mac.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -6,19 +6,39 @@
#include "ui/gfx/canvas_skia.h"
-#include "base/mac/mac_util.h"
-#include "base/mac/scoped_cftyperef.h"
+#include "base/logging.h"
#include "base/sys_string_conversions.h"
-#include "third_party/skia/include/core/SkShader.h"
+#include "third_party/skia/include/core/SkTypeface.h"
#include "ui/gfx/font.h"
-#include "ui/gfx/rect.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 CanvasSkia::SizeStringInt(const string16& text,
const gfx::Font& font,
- int* width, int* height,
+ int* width,
+ int* height,
int flags) {
NSFont* native_font = font.GetNativeFont();
NSString* ns_string = base::SysUTF16ToNSString(text);
@@ -35,49 +55,28 @@ void CanvasSkia::DrawStringInt(const string16& text,
const SkColor& color,
int x, int y, int w, int h,
int flags) {
- if (!IntersectsClipRectInt(x, y, w, h))
- return;
-
- skia::ScopedPlatformPaint scoped_platform_paint(canvas_);
- CGContextRef context = scoped_platform_paint.GetPlatformSurface();
- CGContextSaveGState(context);
-
- NSColor* ns_color = [NSColor colorWithDeviceRed:SkColorGetR(color) / 255.0
- green:SkColorGetG(color) / 255.0
- blue:SkColorGetB(color) / 255.0
- alpha:SkColorGetA(color) / 255.0];
- NSMutableParagraphStyle *ns_style =
- [[[NSMutableParagraphStyle alloc] init] autorelease];
- if (flags & TEXT_ALIGN_CENTER)
- [ns_style setAlignment:NSCenterTextAlignment];
- // TODO(awalker): Implement the rest of the Canvas text flags
-
- NSDictionary* attributes =
- [NSDictionary dictionaryWithObjectsAndKeys:
- font.GetNativeFont(), NSFontAttributeName,
- ns_color, NSForegroundColorAttributeName,
- ns_style, NSParagraphStyleAttributeName,
- nil];
-
- NSAttributedString* ns_string =
- [[[NSAttributedString alloc] initWithString:base::SysUTF16ToNSString(text)
- attributes:attributes] autorelease];
- base::mac::ScopedCFTypeRef<CTFramesetterRef> framesetter(
- CTFramesetterCreateWithAttributedString(
- base::mac::NSToCFCast(ns_string)));
-
- CGRect text_bounds = CGRectMake(x, y, w, h);
- base::mac::ScopedCFTypeRef<CGMutablePathRef> path(CGPathCreateMutable());
- CGPathAddRect(path, NULL, text_bounds);
+ 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);
+}
- base::mac::ScopedCFTypeRef<CTFrameRef> frame(
- CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL));
- CTFrameDraw(frame, context);
- CGContextRestoreGState(context);
+void CanvasSkia::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) {
}
ui::TextureID CanvasSkia::GetTextureID() {
- // TODO(wjmaclean)
return 0;
}