Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: ui/gfx/platform_font_fake.cc

Issue 19352002: Fixes vertical alignment of RenderText. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adds platform_font_fake.{cc,h} Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/platform_font_fake.h ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/gfx/platform_font_fake.h"
6
7 #include "base/logging.h"
8 #include "ui/gfx/font.h"
9
10 namespace gfx {
11
12 ////////////////////////////////////////////////////////////////////////////////
13 // PlatformFontPango, public:
14
15 PlatformFontFake::PlatformFontFake() {
16 InitWithNameAndSize("Fake", 10);
17 }
18
19 PlatformFontFake::PlatformFontFake(const std::string& font_name,
20 int font_size) {
21 InitWithNameAndSize(font_name, font_size);
22 }
23
24 ////////////////////////////////////////////////////////////////////////////////
25 // PlatformFontFake, PlatformFont implementation:
26
27 Font PlatformFontFake::DeriveFont(int size_delta, int style) const {
28 PlatformFontFake* platform_font = new PlatformFontFake(
29 font_name_, font_size_ + size_delta);
30 platform_font->style_ = style;
31 return Font(platform_font);
32 }
33
34 int PlatformFontFake::GetHeight() const {
35 return height_;
36 }
37
38 int PlatformFontFake::GetBaseline() const {
39 return baseline_;
40 }
41
42 int PlatformFontFake::GetAverageCharacterWidth() const {
43 return average_character_width_;
44 }
45
46 int PlatformFontFake::GetStringWidth(const base::string16& text) const {
47 return GetAverageCharacterWidth() * text.length();
48 }
49
50 int PlatformFontFake::GetExpectedTextWidth(int length) const {
51 return GetAverageCharacterWidth() * length;
52 }
53
54 int PlatformFontFake::GetStyle() const {
55 return style_;
56 }
57
58 std::string PlatformFontFake::GetFontName() const {
59 return font_name_;
60 }
61
62 int PlatformFontFake::GetFontSize() const {
63 return font_size_;
64 }
65
66 NativeFont PlatformFontFake::GetNativeFont() const {
67 return static_cast<NativeFont>(NULL);
68 }
69
70 ////////////////////////////////////////////////////////////////////////////////
71 // PlatformFontFake, setter for customization:
72
73 void PlatformFontFake::SetHeight(int height) {
74 height_ = height;
75 }
76
77 void PlatformFontFake::SetBaseline(int baseline) {
78 baseline_ = baseline;
79 }
80
81 ////////////////////////////////////////////////////////////////////////////////
82 // PlatformFontPango, private:
83
84 void PlatformFontFake::InitWithNameAndSize(const std::string& font_name,
85 int font_size) {
86 font_name_ = font_name;
87 font_size_ = font_size;
88 style_ = Font::NORMAL;
89 height_ = font_size_;
90 baseline_ = static_cast<int>(height_ * 0.8);
91 average_character_width_ = static_cast<int>(height_ * 0.9);
92 }
93
94 ////////////////////////////////////////////////////////////////////////////////
95 // PlatformFont, public:
96
97 // static
98 PlatformFont* PlatformFont::CreateDefault() {
99 return new PlatformFontFake();
100 }
101
102 // static
103 PlatformFont* PlatformFont::CreateFromNativeFont(NativeFont native_font) {
104 NOTIMPLEMENTED();
105 return NULL;
106 }
107
108 // static
109 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
110 int font_size) {
111 return new PlatformFontFake(font_name, font_size);
112 }
113
114 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/platform_font_fake.h ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698