Commit c382f649 authored by groby@chromium.org's avatar groby@chromium.org

Turn on canvas_skia for OSX

Re-submit of r221930, with fixed include path.

TBR=asvitkine@chromium.org
BUG=151935

Review URL: https://chromiumcodereview.appspot.com/23454018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222192 0039d316-1c4b-4281-b951-d872f2087c98
parent 754b1c4b
...@@ -655,7 +655,7 @@ ...@@ -655,7 +655,7 @@
# #
# On Aura, this allows per-tile painting to be used in the browser # On Aura, this allows per-tile painting to be used in the browser
# compositor. # compositor.
['OS!="mac" and OS!="android"', { ['OS!="android"', {
'use_canvas_skia%': 1, 'use_canvas_skia%': 1,
}], }],
......
// 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.
#include "ui/gfx/canvas.h"
#import <Cocoa/Cocoa.h>
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "ui/gfx/font_list.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.cc| implementation will supersede
// this and the other platform-specific implmenentations. Most drawing options,
// such as alignment, multi-line, and line heights 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 base::string16& text,
const FontList& font_list,
int* width,
int* height,
int line_height,
int flags) {
DLOG_IF(WARNING, line_height != 0) << "Line heights not implemented.";
DLOG_IF(WARNING, flags & Canvas::MULTI_LINE) << "Multi-line not implemented.";
NSFont* native_font = font_list.GetPrimaryFont().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_list.GetHeight();
}
void Canvas::DrawStringRectWithShadows(const base::string16& text,
const FontList& font_list,
SkColor color,
const Rect& text_bounds,
int line_height,
int flags,
const ShadowValues& shadows) {
DLOG_IF(WARNING, line_height != 0) << "Line heights not implemented.";
DLOG_IF(WARNING, flags & Canvas::MULTI_LINE) << "Multi-line not implemented.";
DLOG_IF(WARNING, !shadows.empty()) << "Text shadows not implemented.";
const Font& font = font_list.GetPrimaryFont();
skia::RefPtr<SkTypeface> typeface = skia::AdoptRef(
SkTypeface::CreateFromName(
font.GetFontName().c_str(), FontTypefaceStyle(font)));
SkPaint paint;
paint.setTypeface(typeface.get());
paint.setColor(color);
canvas_->drawText(text.c_str(),
text.size() * sizeof(base::string16::value_type),
text_bounds.x(),
text_bounds.bottom(),
paint);
}
void Canvas::DrawStringRectWithHalo(const base::string16& text,
const FontList& font_list,
SkColor text_color,
SkColor halo_color,
const Rect& display_rect,
int flags) {
}
} // namespace gfx
// Copyright 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 <Cocoa/Cocoa.h>
#include "base/strings/utf_string_conversions.h"
#include "base/strings/sys_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/font.h"
#include "ui/gfx/font_list.h"
namespace gfx {
namespace {
// Mac-specific code for string size computations. This is a verbatim copy
// of the old implementation that used to be in canvas_mac.mm.
void CanvasMac_SizeStringInt(const base::string16& text,
const FontList& font_list,
int* width,
int* height,
int line_height,
int flags) {
DLOG_IF(WARNING, line_height != 0) << "Line heights not implemented.";
DLOG_IF(WARNING, flags & Canvas::MULTI_LINE) << "Multi-line not implemented.";
NSFont* native_font = font_list.GetPrimaryFont().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_list.GetHeight();
}
} // namespace
class CanvasTestMac : public testing::Test {
protected:
// Compare the size returned by Canvas::SizeStringInt to the size generated
// by the platform-specific version in CanvasMac_SizeStringInt. Will generate
// expectation failure on any mismatch. Only works for single-line text
// without specified line height, since that is all the platform
// implementation supports.
void CompareSizes(const char* text) {
FontList font_list(font_);
base::string16 text16 = base::UTF8ToUTF16(text);
int mac_width = -1;
int mac_height = -1;
CanvasMac_SizeStringInt(text16, font_list, &mac_width, &mac_height, 0, 0);
int canvas_width = -1;
int canvas_height = -1;
Canvas::SizeStringInt(
text16, font_list, &canvas_width, &canvas_height, 0, 0);
EXPECT_EQ(mac_width, canvas_width) << " width for " << text;
EXPECT_EQ(mac_height, canvas_height) << " height for " << text;
}
private:
Font font_;
};
// Tests that Canvas' SizeStringInt yields result consistent with a native
// implementation.
TEST_F(CanvasTestMac, StringSizeIdenticalForSkia) {
CompareSizes("");
CompareSizes("Foo");
CompareSizes("Longword");
CompareSizes("This is a complete sentence.");
}
} // namespace gfx
...@@ -413,7 +413,6 @@ ...@@ -413,7 +413,6 @@
'gfx/canvas.cc', 'gfx/canvas.cc',
'gfx/canvas.h', 'gfx/canvas.h',
'gfx/canvas_android.cc', 'gfx/canvas_android.cc',
'gfx/canvas_mac.mm',
'gfx/canvas_paint_gtk.cc', 'gfx/canvas_paint_gtk.cc',
'gfx/canvas_paint_gtk.h', 'gfx/canvas_paint_gtk.h',
'gfx/canvas_paint_mac.h', 'gfx/canvas_paint_mac.h',
...@@ -647,7 +646,6 @@ ...@@ -647,7 +646,6 @@
['use_canvas_skia==1', { ['use_canvas_skia==1', {
'sources!': [ 'sources!': [
'gfx/canvas_android.cc', 'gfx/canvas_android.cc',
'gfx/canvas_mac.mm',
], ],
}, { # use_canvas_skia!=1 }, { # use_canvas_skia!=1
'sources!': [ 'sources!': [
......
...@@ -170,6 +170,7 @@ ...@@ -170,6 +170,7 @@
'gfx/blit_unittest.cc', 'gfx/blit_unittest.cc',
'gfx/break_list_unittest.cc', 'gfx/break_list_unittest.cc',
'gfx/canvas_unittest.cc', 'gfx/canvas_unittest.cc',
'gfx/canvas_unittest_mac.mm',
'gfx/codec/jpeg_codec_unittest.cc', 'gfx/codec/jpeg_codec_unittest.cc',
'gfx/color_analysis_unittest.cc', 'gfx/color_analysis_unittest.cc',
'gfx/font_list_unittest.cc', 'gfx/font_list_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment