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

Side by Side Diff: ui/views/examples/text_example.cc

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a lost comment and modify a render text unittest to not test black because of test env font con… Created 4 years, 6 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
« no previous file with comments | « ui/views/examples/multiline_example.cc ('k') | ui/views/examples/textfield_example.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "ui/views/examples/text_example.h" 5 #include "ui/views/examples/text_example.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/font_list.h" 10 #include "ui/gfx/font_list.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 int flags() const { return flags_; } 87 int flags() const { return flags_; }
88 void set_flags(int flags) { flags_ = flags; } 88 void set_flags(int flags) { flags_ = flags; }
89 void set_text(const base::string16& text) { text_ = text; } 89 void set_text(const base::string16& text) { text_ = text; }
90 void set_halo(bool halo) { halo_ = halo; } 90 void set_halo(bool halo) { halo_ = halo; }
91 void set_elide(gfx::ElideBehavior elide) { elide_ = elide; } 91 void set_elide(gfx::ElideBehavior elide) { elide_ = elide; }
92 92
93 int GetStyle() const { return font_list_.GetFontStyle(); } 93 int GetStyle() const { return font_list_.GetFontStyle(); }
94 void SetStyle(int style) { font_list_ = font_list_.DeriveWithStyle(style); } 94 void SetStyle(int style) { font_list_ = font_list_.DeriveWithStyle(style); }
95 95
96 gfx::Font::Weight GetWeight() const { return font_list_.GetFontWeight(); }
97 void SetWeight(gfx::Font::Weight weight) {
98 font_list_ = font_list_.DeriveWithWeight(weight);
99 }
100
96 private: 101 private:
97 // The font used for drawing the text. 102 // The font used for drawing the text.
98 gfx::FontList font_list_; 103 gfx::FontList font_list_;
99 104
100 // The text to draw. 105 // The text to draw.
101 base::string16 text_; 106 base::string16 text_;
102 107
103 // Text flags for passing to |DrawStringRect()|. 108 // Text flags for passing to |DrawStringRect()|.
104 int flags_; 109 int flags_;
105 110
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 layout->StartRow(1, 1); 188 layout->StartRow(1, 1);
184 layout->AddView(text_view_); 189 layout->AddView(text_view_);
185 layout->AddPaddingRow(0, 8); 190 layout->AddPaddingRow(0, 8);
186 } 191 }
187 192
188 void TextExample::ButtonPressed(Button* button, const ui::Event& event) { 193 void TextExample::ButtonPressed(Button* button, const ui::Event& event) {
189 int flags = text_view_->flags(); 194 int flags = text_view_->flags();
190 int style = text_view_->GetStyle(); 195 int style = text_view_->GetStyle();
191 SetFlagFromCheckbox(multiline_checkbox_, &flags, gfx::Canvas::MULTI_LINE); 196 SetFlagFromCheckbox(multiline_checkbox_, &flags, gfx::Canvas::MULTI_LINE);
192 SetFlagFromCheckbox(break_checkbox_, &flags, gfx::Canvas::CHARACTER_BREAK); 197 SetFlagFromCheckbox(break_checkbox_, &flags, gfx::Canvas::CHARACTER_BREAK);
193 SetFlagFromCheckbox(bold_checkbox_, &style, gfx::Font::BOLD);
194 SetFlagFromCheckbox(italic_checkbox_, &style, gfx::Font::ITALIC); 198 SetFlagFromCheckbox(italic_checkbox_, &style, gfx::Font::ITALIC);
195 SetFlagFromCheckbox(underline_checkbox_, &style, gfx::Font::UNDERLINE); 199 SetFlagFromCheckbox(underline_checkbox_, &style, gfx::Font::UNDERLINE);
196 text_view_->set_halo(halo_checkbox_->checked()); 200 text_view_->set_halo(halo_checkbox_->checked());
197 text_view_->set_flags(flags); 201 text_view_->set_flags(flags);
198 text_view_->SetStyle(style); 202 text_view_->SetStyle(style);
203 text_view_->SetWeight(bold_checkbox_->checked() ? gfx::Font::Weight::BOLD
204 : gfx::Font::Weight::NORMAL);
199 text_view_->SchedulePaint(); 205 text_view_->SchedulePaint();
200 } 206 }
201 207
202 void TextExample::OnPerformAction(Combobox* combobox) { 208 void TextExample::OnPerformAction(Combobox* combobox) {
203 int flags = text_view_->flags(); 209 int flags = text_view_->flags();
204 if (combobox == h_align_cb_) { 210 if (combobox == h_align_cb_) {
205 flags &= ~(gfx::Canvas::TEXT_ALIGN_LEFT | 211 flags &= ~(gfx::Canvas::TEXT_ALIGN_LEFT |
206 gfx::Canvas::TEXT_ALIGN_CENTER | 212 gfx::Canvas::TEXT_ALIGN_CENTER |
207 gfx::Canvas::TEXT_ALIGN_RIGHT); 213 gfx::Canvas::TEXT_ALIGN_RIGHT);
208 switch (combobox->selected_index()) { 214 switch (combobox->selected_index()) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 flags |= gfx::Canvas::HIDE_PREFIX; 263 flags |= gfx::Canvas::HIDE_PREFIX;
258 break; 264 break;
259 } 265 }
260 } 266 }
261 text_view_->set_flags(flags); 267 text_view_->set_flags(flags);
262 text_view_->SchedulePaint(); 268 text_view_->SchedulePaint();
263 } 269 }
264 270
265 } // namespace examples 271 } // namespace examples
266 } // namespace views 272 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/examples/multiline_example.cc ('k') | ui/views/examples/textfield_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698