| Index: ui/gfx/platform_font_fake.cc
|
| diff --git a/ui/gfx/platform_font_fake.cc b/ui/gfx/platform_font_fake.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..885c2fc3e8ae5212541098b50dd0aa3be2a9e439
|
| --- /dev/null
|
| +++ b/ui/gfx/platform_font_fake.cc
|
| @@ -0,0 +1,114 @@
|
| +// Copyright (c) 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/platform_font_fake.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "ui/gfx/font.h"
|
| +
|
| +namespace gfx {
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// PlatformFontPango, public:
|
| +
|
| +PlatformFontFake::PlatformFontFake() {
|
| + InitWithNameAndSize("Fake", 10);
|
| +}
|
| +
|
| +PlatformFontFake::PlatformFontFake(const std::string& font_name,
|
| + int font_size) {
|
| + InitWithNameAndSize(font_name, font_size);
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// PlatformFontFake, PlatformFont implementation:
|
| +
|
| +Font PlatformFontFake::DeriveFont(int size_delta, int style) const {
|
| + PlatformFontFake* platform_font = new PlatformFontFake(
|
| + font_name_, font_size_ + size_delta);
|
| + platform_font->style_ = style;
|
| + return Font(platform_font);
|
| +}
|
| +
|
| +int PlatformFontFake::GetHeight() const {
|
| + return height_;
|
| +}
|
| +
|
| +int PlatformFontFake::GetBaseline() const {
|
| + return baseline_;
|
| +}
|
| +
|
| +int PlatformFontFake::GetAverageCharacterWidth() const {
|
| + return average_character_width_;
|
| +}
|
| +
|
| +int PlatformFontFake::GetStringWidth(const base::string16& text) const {
|
| + return GetAverageCharacterWidth() * text.length();
|
| +}
|
| +
|
| +int PlatformFontFake::GetExpectedTextWidth(int length) const {
|
| + return GetAverageCharacterWidth() * length;
|
| +}
|
| +
|
| +int PlatformFontFake::GetStyle() const {
|
| + return style_;
|
| +}
|
| +
|
| +std::string PlatformFontFake::GetFontName() const {
|
| + return font_name_;
|
| +}
|
| +
|
| +int PlatformFontFake::GetFontSize() const {
|
| + return font_size_;
|
| +}
|
| +
|
| +NativeFont PlatformFontFake::GetNativeFont() const {
|
| + return static_cast<NativeFont>(NULL);
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// PlatformFontFake, setter for customization:
|
| +
|
| +void PlatformFontFake::SetHeight(int height) {
|
| + height_ = height;
|
| +}
|
| +
|
| +void PlatformFontFake::SetBaseline(int baseline) {
|
| + baseline_ = baseline;
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// PlatformFontPango, private:
|
| +
|
| +void PlatformFontFake::InitWithNameAndSize(const std::string& font_name,
|
| + int font_size) {
|
| + font_name_ = font_name;
|
| + font_size_ = font_size;
|
| + style_ = Font::NORMAL;
|
| + height_ = font_size_;
|
| + baseline_ = static_cast<int>(height_ * 0.8);
|
| + average_character_width_ = static_cast<int>(height_ * 0.9);
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// PlatformFont, public:
|
| +
|
| +// static
|
| +PlatformFont* PlatformFont::CreateDefault() {
|
| + return new PlatformFontFake();
|
| +}
|
| +
|
| +// static
|
| +PlatformFont* PlatformFont::CreateFromNativeFont(NativeFont native_font) {
|
| + NOTIMPLEMENTED();
|
| + return NULL;
|
| +}
|
| +
|
| +// static
|
| +PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
|
| + int font_size) {
|
| + return new PlatformFontFake(font_name, font_size);
|
| +}
|
| +
|
| +} // namespace gfx
|
|
|