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

Side by Side Diff: gfx/platform_font_gtk.h

Issue 3083022: Rework gfx::Font by moving platform-specific code into inner classes.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gfx/platform_font.h ('k') | gfx/platform_font_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 #ifndef GFX_PLATFORM_FONT_GTK_
6 #define GFX_PLATFORM_FONT_GTK_
7 #pragma once
8
9 #include "base/scoped_ptr.h"
10 #include "gfx/platform_font.h"
11 #include "third_party/skia/include/core/SkRefCnt.h"
12
13 class SkTypeface;
14 class SkPaint;
15
16 namespace gfx {
17
18 class PlatformFontGtk : public PlatformFont {
19 public:
20 PlatformFontGtk();
21 explicit PlatformFontGtk(const Font& other);
22 explicit PlatformFontGtk(NativeFont native_font);
23 PlatformFontGtk(const std::wstring& font_name,
24 int font_size);
25
26 // Converts |gfx_font| to a new pango font. Free the returned font with
27 // pango_font_description_free().
28 static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font);
29
30 // Position as an offset from the height of the drawn text, used to draw
31 // an underline. This is a negative number, so the underline would be
32 // drawn at y + height + underline_position;
33 double underline_position() const;
34 // The thickness to draw the underline.
35 double underline_thickness() const;
36
37 // Overridden from PlatformFont:
38 virtual Font DeriveFont(int size_delta, int style) const;
39 virtual int GetHeight() const;
40 virtual int GetBaseline() const;
41 virtual int GetAverageCharacterWidth() const;
42 virtual int GetStringWidth(const std::wstring& text) const;
43 virtual int GetExpectedTextWidth(int length) const;
44 virtual int GetStyle() const;
45 virtual const std::wstring& GetFontName() const;
46 virtual int GetFontSize() const;
47 virtual NativeFont GetNativeFont() const;
48
49 private:
50 // Create a new instance of this object with the specified properties. Called
51 // from DeriveFont.
52 PlatformFontGtk(SkTypeface* typeface,
53 const std::wstring& name,
54 int size,
55 int style);
56 virtual ~PlatformFontGtk() {}
57
58 // Initialize this object.
59 void InitWithNameAndSize(const std::wstring& font_name, int font_size);
60 void InitWithTypefaceNameSizeAndStyle(SkTypeface* typeface,
61 const std::wstring& name,
62 int size,
63 int style);
64 void InitFromPlatformFont(const PlatformFontGtk* other);
65
66 // Potentially slow call to get pango metrics (average width, underline info).
67 void InitPangoMetrics();
68
69 // Setup a Skia context to use the current typeface
70 void PaintSetup(SkPaint* paint) const;
71
72 // Make |this| a copy of |other|.
73 void CopyFont(const Font& other);
74
75 // Return the scale factor for fonts that account for DPI.
76 static float GetPangoScaleFactor();
77
78 // The average width of a character, initialized and cached if needed.
79 double GetAverageWidth() const;
80
81 // These two both point to the same SkTypeface. We use the SkAutoUnref to
82 // handle the reference counting, but without @typeface_ we would have to
83 // cast the SkRefCnt from @typeface_helper_ every time.
84 scoped_ptr<SkAutoUnref> typeface_helper_;
85 SkTypeface *typeface_;
86
87 // Additional information about the face
88 // Skia actually expects a family name and not a font name.
89 std::wstring font_family_;
90 int font_size_;
91 int style_;
92
93 // Cached metrics, generated at construction
94 int height_;
95 int ascent_;
96
97 // The pango metrics are much more expensive so we wait until we need them
98 // to compute them.
99 bool pango_metrics_inited_;
100 double average_width_;
101 double underline_position_;
102 double underline_thickness_;
103
104 // The default font, used for the default constructor.
105 static Font* default_font_;
106 };
107
108 } // namespace gfx
109
110 #endif // GFX_PLATFORM_FONT_GTK_
111
OLDNEW
« no previous file with comments | « gfx/platform_font.h ('k') | gfx/platform_font_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698