| OLD | NEW |
| (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 |
| OLD | NEW |