summaryrefslogtreecommitdiffstats
path: root/chrome/common/gfx
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 01:52:03 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 01:52:03 +0000
commit92fee7f85eda4a8cd3482d2ff9da51ade9a58b65 (patch)
tree4cf2b2fd74b71a0c1f6e0d8ff69a09f994d077b8 /chrome/common/gfx
parent6ed4b93f7cf53af95c12e0e54a167b7f99028a82 (diff)
downloadchromium_src-92fee7f85eda4a8cd3482d2ff9da51ade9a58b65.zip
chromium_src-92fee7f85eda4a8cd3482d2ff9da51ade9a58b65.tar.gz
chromium_src-92fee7f85eda4a8cd3482d2ff9da51ade9a58b65.tar.bz2
...
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6869 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/gfx')
-rw-r--r--chrome/common/gfx/chrome_canvas.h1
-rw-r--r--chrome/common/gfx/chrome_font.cc28
-rw-r--r--chrome/common/gfx/chrome_font.h92
3 files changed, 93 insertions, 28 deletions
diff --git a/chrome/common/gfx/chrome_canvas.h b/chrome/common/gfx/chrome_canvas.h
index 313f5db..ea9dbac 100644
--- a/chrome/common/gfx/chrome_canvas.h
+++ b/chrome/common/gfx/chrome_canvas.h
@@ -5,7 +5,6 @@
#ifndef CHROME_COMMON_GFX_CHROME_CANVAS_H_
#define CHROME_COMMON_GFX_CHROME_CANVAS_H_
-#include <windows.h>
#include <string>
#include "base/basictypes.h"
diff --git a/chrome/common/gfx/chrome_font.cc b/chrome/common/gfx/chrome_font.cc
index 446be56..6600abe 100644
--- a/chrome/common/gfx/chrome_font.cc
+++ b/chrome/common/gfx/chrome_font.cc
@@ -27,6 +27,34 @@ static const int kTextMetricWeightBold = 700;
// ChromeFont
//
+ChromeFont::ChromeFont()
+ : font_ref_(GetBaseFontRef()) {
+}
+
+int ChromeFont::height() const {
+ return font_ref_->height();
+}
+
+int ChromeFont::baseline() const {
+ return font_ref_->baseline();
+}
+
+int ChromeFont::ave_char_width() const {
+ return font_ref_->ave_char_width();
+}
+
+int ChromeFont::GetExpectedTextWidth(int length) const {
+ return length * font_ref_->dlu_base_x();
+}
+
+int ChromeFont::style() const {
+ return font_ref_->style();
+}
+
+gfx::NativeFont ChromeFont::nativeFont() const {
+ return hfont();
+}
+
// static
ChromeFont ChromeFont::CreateFont(HFONT font) {
DCHECK(font);
diff --git a/chrome/common/gfx/chrome_font.h b/chrome/common/gfx/chrome_font.h
index ffbbdd3..a26ceaf 100644
--- a/chrome/common/gfx/chrome_font.h
+++ b/chrome/common/gfx/chrome_font.h
@@ -6,14 +6,16 @@
#define CHROME_COMMON_GFX_CHROME_FONT_H_
#include "build/build_config.h"
+#include "base/gfx/native_widget_types.h"
#include <string>
#if defined(OS_WIN)
typedef struct HFONT__* HFONT;
-#else
-// TODO(port): Make it more real.
-typedef void* HFONT;
+#elif defined(OS_LINUX)
+#include "skia/include/SkRefCnt.h"
+class SkPaint;
+class SkTypeface;
#endif
#include "base/basictypes.h"
@@ -24,20 +26,17 @@ typedef void* HFONT;
class ChromeFont {
public:
// The following constants indicate the font style.
- static const int BOLD = 1;
- static const int ITALIC = 2;
- static const int UNDERLINED = 4;
- static const int WEB = 8;
-
- // Creates a ChromeFont from the specified HFONT. The supplied HFONT is
- // effectively copied.
- static ChromeFont CreateFont(HFONT hfont);
+ enum {
+ NORMAL = 0,
+ BOLD = 1,
+ ITALIC = 2,
+ UNDERLINED = 4,
+ WEB = 8, // TODO: what does this mean?
+ };
// Creates a ChromeFont given font name (e.g. arial), font size (e.g. 12).
static ChromeFont CreateFont(const std::wstring& font_name, int font_size);
- // Creates a font with the default name and style.
- ChromeFont() : font_ref_(GetBaseFontRef()) { }
~ChromeFont() { }
// Returns a new Font derived from the existing font.
@@ -56,13 +55,13 @@ class ChromeFont {
// Returns the number of vertical pixels needed to display characters from
// the specified font.
- int height() const { return font_ref_->height(); }
+ int height() const;
// Returns the baseline, or ascent, of the font.
- int baseline() const { return font_ref_->baseline(); }
+ int baseline() const;
// Returns the average character width for the font.
- int ave_char_width() const { return font_ref_->ave_char_width(); }
+ int ave_char_width() const;
// Returns the number of horizontal pixels needed to display the specified
// string.
@@ -70,13 +69,27 @@ class ChromeFont {
// Returns the expected number of horizontal pixels needed to display
// the specified length of characters.
- // Call the GetStringWidth() function to retrieve the actual number.
- int GetExpectedTextWidth(int length) const {
- return length * font_ref_->dlu_base_x();
- }
+ // Call GetStringWidth() to retrieve the actual number.
+ int GetExpectedTextWidth(int length) const;
// Returns the style of the font.
- int style() const { return font_ref_->style(); }
+ int style() const;
+
+ // Font Name.
+ std::wstring FontName();
+
+ // Font Size.
+ int FontSize();
+
+ gfx::NativeFont nativeFont() const;
+
+#if defined(OS_WIN)
+ // Creates a font with the default name and style.
+ ChromeFont();
+
+ // Creates a ChromeFont from the specified HFONT. The supplied HFONT is
+ // effectively copied.
+ static ChromeFont CreateFont(HFONT hfont);
// Returns the handle to the underlying HFONT. This is used by ChromeCanvas to
// draw text.
@@ -90,14 +103,14 @@ class ChromeFont {
int vertical_dlus_to_pixels(int dlus) {
return dlus * font_ref_->height() / 8;
}
-
- // Font Name.
- std::wstring FontName();
-
- // Font Size.
- int FontSize();
+#elif defined(OS_LINUX)
+ // We need a copy constructor to deal with the Skia reference counting
+ ChromeFont(const ChromeFont& other);
+#endif
private:
+
+#if defined(OS_WIN)
// Chrome text drawing bottoms out in the Windows GDI functions that take an
// HFONT (an opaque handle into Windows). To avoid lots of GDI object
// allocation and destruction, ChromeFont indirectly refers to the HFONT
@@ -155,6 +168,31 @@ class ChromeFont {
// Indirect reference to the HFontRef, which references the underlying HFONT.
scoped_refptr<HFontRef> font_ref_;
+#elif defined(OS_LINUX)
+ explicit ChromeFont(SkTypeface* typeface, const std::wstring& name,
+ int size, int style);
+ // Setup a Skia context to use the current typeface
+ void setupPaint(SkPaint* paint) const;
+ // Calculate and cache the font metrics
+ void calculateMetrics();
+
+ // These two both point to the same SkTypeface. We use the SkAutoUnref to
+ // handle the reference counting, but without @typeface_ we would have to
+ // cast the SkRefCnt from @typeface_helper_ every time.
+ SkAutoUnref typeface_helper_;
+ SkTypeface *typeface_;
+
+ // Additional information about the face
+ const std::wstring font_name_;
+ const int font_size_;
+ const int style_;
+
+ // Cached metrics, generated at construction
+ int height_;
+ int ascent_;
+ int avg_width_;
+#endif
+
};
#endif // CHROME_COMMON_GFX_CHROME_FONT_H_