summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--base/gfx/native_widget_types.h4
-rw-r--r--chrome/common/common.scons5
-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
-rw-r--r--chrome/test/unit/unit_tests.scons1
6 files changed, 102 insertions, 29 deletions
diff --git a/base/gfx/native_widget_types.h b/base/gfx/native_widget_types.h
index 1f696b0..2bdb4e9 100644
--- a/base/gfx/native_widget_types.h
+++ b/base/gfx/native_widget_types.h
@@ -31,6 +31,7 @@ class NSWindow;
class NSTextField;
#endif // __OBJC__
#elif defined(OS_LINUX)
+class SkTypeface;
typedef struct _GtkWidget GtkWidget;
#endif
@@ -40,14 +41,17 @@ namespace gfx {
typedef HWND NativeView;
typedef HWND NativeWindow;
typedef HWND NativeEditView;
+typedef struct HFONT__* NativeFont;
#elif defined(OS_MACOSX)
typedef NSView* NativeView;
typedef NSWindow* NativeWindow;
typedef NSTextField* NativeEditView;
+typedef void* NativeFont; // TODO(port): set the correct type here
#elif defined(OS_LINUX)
typedef GtkWidget* NativeView;
typedef GtkWidget* NativeWindow;
typedef GtkWidget* NativeEditView;
+typedef SkTypeface* NativeFont;
#else // null port.
#error No known OS defined
#endif
diff --git a/chrome/common/common.scons b/chrome/common/common.scons
index eda51df..6cbca92 100644
--- a/chrome/common/common.scons
+++ b/chrome/common/common.scons
@@ -110,7 +110,10 @@ if env['PLATFORM'] == 'win32':
'win_util.cc',
'worker_thread_ticker.cc',
])
-
+elif env['PLATFORM'] == 'posix':
+ input_files.extend([
+ 'gfx/chrome_font_skia.cc',
+ ])
if env['PLATFORM'] == 'win32':
# Windows specific files
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_
diff --git a/chrome/test/unit/unit_tests.scons b/chrome/test/unit/unit_tests.scons
index b2f7616..70eded7 100644
--- a/chrome/test/unit/unit_tests.scons
+++ b/chrome/test/unit/unit_tests.scons
@@ -135,6 +135,7 @@ if env['PLATFORM'] in ('posix', 'win32'):
'$CHROME_DIR/common/bzip2_unittest.cc',
'$CHROME_DIR/common/jpeg_codec_unittest.cc',
'$CHROME_DIR/common/json_value_serializer_unittest.cc',
+ '$CHROME_DIR/common/gfx/chrome_font_unittest.cc',
])
if env['PLATFORM'] == 'win32':