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

Side by Side Diff: gfx/platform_font_win.h

Issue 6246027: Move src/gfx/ to src/ui/gfx... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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_mac.mm ('k') | gfx/platform_font_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GFX_PLATFORM_FONT_WIN_ 5 #ifndef GFX_PLATFORM_FONT_WIN_
6 #define GFX_PLATFORM_FONT_WIN_ 6 #define GFX_PLATFORM_FONT_WIN_
7 #pragma once 7 #pragma once
8 8
9 #include "base/ref_counted.h" 9 #include "ui/gfx/platform_font_win.h"
10 #include "gfx/platform_font.h" 10 // TODO(sail): remove this file once all includes have been updated.
11
12 namespace gfx {
13
14 class PlatformFontWin : public PlatformFont {
15 public:
16 PlatformFontWin();
17 explicit PlatformFontWin(const Font& other);
18 explicit PlatformFontWin(NativeFont native_font);
19 PlatformFontWin(const string16& font_name,
20 int font_size);
21
22 // Dialog units to pixels conversion.
23 // See http://support.microsoft.com/kb/145994 for details.
24 int horizontal_dlus_to_pixels(int dlus) const {
25 return dlus * font_ref_->dlu_base_x() / 4;
26 }
27 int vertical_dlus_to_pixels(int dlus) const {
28 return dlus * font_ref_->height() / 8;
29 }
30
31 // Callback that returns the minimum height that should be used for
32 // gfx::Fonts. Optional. If not specified, the minimum font size is 0.
33 typedef int (*GetMinimumFontSizeCallback)();
34 static GetMinimumFontSizeCallback get_minimum_font_size_callback;
35
36 // Callback that adjusts a LOGFONT to meet suitability requirements of the
37 // embedding application. Optional. If not specified, no adjustments are
38 // performed other than clamping to a minimum font height if
39 // |get_minimum_font_size_callback| is specified.
40 typedef void (*AdjustFontCallback)(LOGFONT* lf);
41 static AdjustFontCallback adjust_font_callback;
42
43 // Overridden from PlatformFont:
44 virtual Font DeriveFont(int size_delta, int style) const;
45 virtual int GetHeight() const;
46 virtual int GetBaseline() const;
47 virtual int GetAverageCharacterWidth() const;
48 virtual int GetStringWidth(const string16& text) const;
49 virtual int GetExpectedTextWidth(int length) const;
50 virtual int GetStyle() const;
51 virtual string16 GetFontName() const;
52 virtual int GetFontSize() const;
53 virtual NativeFont GetNativeFont() const;
54
55 private:
56 virtual ~PlatformFontWin() {}
57
58 // Chrome text drawing bottoms out in the Windows GDI functions that take an
59 // HFONT (an opaque handle into Windows). To avoid lots of GDI object
60 // allocation and destruction, Font indirectly refers to the HFONT by way of
61 // an HFontRef. That is, every Font has an HFontRef, which has an HFONT.
62 //
63 // HFontRef is reference counted. Upon deletion, it deletes the HFONT.
64 // By making HFontRef maintain the reference to the HFONT, multiple
65 // HFontRefs can share the same HFONT, and Font can provide value semantics.
66 class HFontRef : public base::RefCounted<HFontRef> {
67 public:
68 // This constructor takes control of the HFONT, and will delete it when
69 // the HFontRef is deleted.
70 HFontRef(HFONT hfont,
71 int height,
72 int baseline,
73 int ave_char_width,
74 int style,
75 int dlu_base_x);
76
77 // Accessors
78 HFONT hfont() const { return hfont_; }
79 int height() const { return height_; }
80 int baseline() const { return baseline_; }
81 int ave_char_width() const { return ave_char_width_; }
82 int style() const { return style_; }
83 int dlu_base_x() const { return dlu_base_x_; }
84 const string16& font_name() const { return font_name_; }
85
86 private:
87 friend class base::RefCounted<HFontRef>;
88
89 ~HFontRef();
90
91 const HFONT hfont_;
92 const int height_;
93 const int baseline_;
94 const int ave_char_width_;
95 const int style_;
96 // Constants used in converting dialog units to pixels.
97 const int dlu_base_x_;
98 string16 font_name_;
99
100 DISALLOW_COPY_AND_ASSIGN(HFontRef);
101 };
102
103 // Initializes this object with a copy of the specified HFONT.
104 void InitWithCopyOfHFONT(HFONT hfont);
105
106 // Initializes this object with the specified font name and size.
107 void InitWithFontNameAndSize(const string16& font_name,
108 int font_size);
109
110 // Returns the base font ref. This should ONLY be invoked on the
111 // UI thread.
112 static HFontRef* GetBaseFontRef();
113
114 // Creates and returns a new HFONTRef from the specified HFONT.
115 static HFontRef* CreateHFontRef(HFONT font);
116
117 // Creates a new PlatformFontWin with the specified HFontRef. Used when
118 // constructing a Font from a HFONT we don't want to copy.
119 explicit PlatformFontWin(HFontRef* hfont_ref);
120
121 // Reference to the base font all fonts are derived from.
122 static HFontRef* base_font_ref_;
123
124 // Indirect reference to the HFontRef, which references the underlying HFONT.
125 scoped_refptr<HFontRef> font_ref_;
126 };
127
128 } // namespace gfx
129 11
130 #endif // GFX_PLATFORM_FONT_WIN_ 12 #endif // GFX_PLATFORM_FONT_WIN_
131
OLDNEW
« no previous file with comments | « gfx/platform_font_mac.mm ('k') | gfx/platform_font_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698