diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-02 23:03:07 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-02 23:03:07 +0000 |
commit | 267c03d478d9c83ef8c37999f3abb1cd822881ff (patch) | |
tree | 6286c650d0ec58cdee9c7482fda929252bd985b5 /ui/gfx/canvas_skia_mac.mm | |
parent | 7c085463177741a3844215675577bba3de1be836 (diff) | |
download | chromium_src-267c03d478d9c83ef8c37999f3abb1cd822881ff.zip chromium_src-267c03d478d9c83ef8c37999f3abb1cd822881ff.tar.gz chromium_src-267c03d478d9c83ef8c37999f3abb1cd822881ff.tar.bz2 |
Move src/gfx/ to src/ui/gfx
To reduce the size of this change I've left stub header files in src/gfx/. Once all includes have been updated I'll delete the stub files.
BUG=71063
TEST=Still doing test builds.
Review URL: http://codereview.chromium.org/6246027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73530 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/canvas_skia_mac.mm')
-rw-r--r-- | ui/gfx/canvas_skia_mac.mm | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/ui/gfx/canvas_skia_mac.mm b/ui/gfx/canvas_skia_mac.mm new file mode 100644 index 0000000..fb30055 --- /dev/null +++ b/ui/gfx/canvas_skia_mac.mm @@ -0,0 +1,88 @@ +// Copyright (c) 2010 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 "gfx/canvas_skia.h" + +#include "base/mac/scoped_cftyperef.h" +#include "base/sys_string_conversions.h" +#include "gfx/font.h" +#include "gfx/rect.h" +#include "third_party/skia/include/core/SkShader.h" + +namespace gfx { + +CanvasSkia::CanvasSkia(int width, int height, bool is_opaque) + : skia::PlatformCanvas(width, height, is_opaque) { +} + +CanvasSkia::CanvasSkia() : skia::PlatformCanvas() { +} + +CanvasSkia::~CanvasSkia() { +} + +// static +void CanvasSkia::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 CanvasSkia::DrawStringInt(const string16& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h, + int flags) { + if (!IntersectsClipRectInt(x, y, w, h)) + return; + + CGContextRef context = beginPlatformPaint(); + 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 = + [[[NSParagraphStyle 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( + reinterpret_cast<CFAttributedStringRef>(ns_string))); + + CGRect text_bounds = CGRectMake(x, y, w, h); + CGMutablePathRef path = CGPathCreateMutable(); + CGPathAddRect(path, NULL, text_bounds); + + base::mac::ScopedCFTypeRef<CTFrameRef> frame( + CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL)); + CTFrameDraw(frame, context); + CGContextRestoreGState(context); + endPlatformPaint(); +} + +} // namespace gfx |