| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "gfx/canvas_skia.h" | 7 #include "gfx/canvas_skia.h" |
| 8 | 8 |
| 9 #include "base/mac/scoped_cftyperef.h" | 9 #include "base/mac/scoped_cftyperef.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 NSFont* native_font = font.GetNativeFont(); | 32 NSFont* native_font = font.GetNativeFont(); |
| 33 NSString* ns_string = base::SysUTF16ToNSString(text); | 33 NSString* ns_string = base::SysUTF16ToNSString(text); |
| 34 NSDictionary* attributes = | 34 NSDictionary* attributes = |
| 35 [NSDictionary dictionaryWithObject:native_font | 35 [NSDictionary dictionaryWithObject:native_font |
| 36 forKey:NSFontAttributeName]; | 36 forKey:NSFontAttributeName]; |
| 37 NSSize string_size = [ns_string sizeWithAttributes:attributes]; | 37 NSSize string_size = [ns_string sizeWithAttributes:attributes]; |
| 38 *width = string_size.width; | 38 *width = string_size.width; |
| 39 *height = font.GetHeight(); | 39 *height = font.GetHeight(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void CanvasSkia::DrawStringInt(const string16& text, | 42 void CanvasSkia::DrawStringInt(const std::wstring& text, |
| 43 const gfx::Font& font, | 43 const gfx::Font& font, |
| 44 const SkColor& color, | 44 const SkColor& color, |
| 45 int x, int y, int w, int h, | 45 int x, int y, int w, int h, |
| 46 int flags) { | 46 int flags) { |
| 47 if (!IntersectsClipRectInt(x, y, w, h)) | 47 if (!IntersectsClipRectInt(x, y, w, h)) |
| 48 return; | 48 return; |
| 49 | 49 |
| 50 CGContextRef context = beginPlatformPaint(); | 50 CGContextRef context = beginPlatformPaint(); |
| 51 CGContextSaveGState(context); | 51 CGContextSaveGState(context); |
| 52 | 52 |
| 53 NSColor* ns_color = [NSColor colorWithDeviceRed:SkColorGetR(color) / 255.0 | 53 NSColor* ns_color = [NSColor colorWithDeviceRed:SkColorGetR(color) / 255.0 |
| 54 green:SkColorGetG(color) / 255.0 | 54 green:SkColorGetG(color) / 255.0 |
| 55 blue:SkColorGetB(color) / 255.0 | 55 blue:SkColorGetB(color) / 255.0 |
| 56 alpha:SkColorGetA(color) / 255.0]; | 56 alpha:SkColorGetA(color) / 255.0]; |
| 57 NSMutableParagraphStyle *ns_style = | 57 NSMutableParagraphStyle *ns_style = |
| 58 [[[NSParagraphStyle alloc] init] autorelease]; | 58 [[[NSParagraphStyle alloc] init] autorelease]; |
| 59 if (flags & TEXT_ALIGN_CENTER) | 59 if (flags & TEXT_ALIGN_CENTER) |
| 60 [ns_style setAlignment:NSCenterTextAlignment]; | 60 [ns_style setAlignment:NSCenterTextAlignment]; |
| 61 // TODO(awalker): Implement the rest of the Canvas text flags | 61 // TODO(awalker): Implement the rest of the Canvas text flags |
| 62 | 62 |
| 63 NSDictionary* attributes = | 63 NSDictionary* attributes = |
| 64 [NSDictionary dictionaryWithObjectsAndKeys: | 64 [NSDictionary dictionaryWithObjectsAndKeys: |
| 65 font.GetNativeFont(), NSFontAttributeName, | 65 font.GetNativeFont(), NSFontAttributeName, |
| 66 ns_color, NSForegroundColorAttributeName, | 66 ns_color, NSForegroundColorAttributeName, |
| 67 ns_style, NSParagraphStyleAttributeName, | 67 ns_style, NSParagraphStyleAttributeName, |
| 68 nil]; | 68 nil]; |
| 69 | 69 |
| 70 NSAttributedString* ns_string = | 70 NSAttributedString* ns_string = |
| 71 [[[NSAttributedString alloc] initWithString:base::SysUTF16ToNSString(text) | 71 [[[NSAttributedString alloc] initWithString:base::SysWideToNSString(text) |
| 72 attributes:attributes] autorelease]; | 72 attributes:attributes] autorelease]; |
| 73 base::mac::ScopedCFTypeRef<CTFramesetterRef> framesetter( | 73 base::mac::ScopedCFTypeRef<CTFramesetterRef> framesetter( |
| 74 CTFramesetterCreateWithAttributedString( | 74 CTFramesetterCreateWithAttributedString( |
| 75 reinterpret_cast<CFAttributedStringRef>(ns_string))); | 75 reinterpret_cast<CFAttributedStringRef>(ns_string))); |
| 76 | 76 |
| 77 CGRect text_bounds = CGRectMake(x, y, w, h); | 77 CGRect text_bounds = CGRectMake(x, y, w, h); |
| 78 CGMutablePathRef path = CGPathCreateMutable(); | 78 CGMutablePathRef path = CGPathCreateMutable(); |
| 79 CGPathAddRect(path, NULL, text_bounds); | 79 CGPathAddRect(path, NULL, text_bounds); |
| 80 | 80 |
| 81 base::mac::ScopedCFTypeRef<CTFrameRef> frame( | 81 base::mac::ScopedCFTypeRef<CTFrameRef> frame( |
| 82 CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL)); | 82 CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL)); |
| 83 CTFrameDraw(frame, context); | 83 CTFrameDraw(frame, context); |
| 84 CGContextRestoreGState(context); | 84 CGContextRestoreGState(context); |
| 85 endPlatformPaint(); | 85 endPlatformPaint(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 } // namespace gfx | 88 } // namespace gfx |
| OLD | NEW |