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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/platform_font_fake.h ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« 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