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

Side by Side Diff: chrome/browser/ui/libgtk2ui/gtk2_ui.cc

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use the std::tie in resource_bundle Created 4 years, 8 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
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 "chrome/browser/ui/libgtk2ui/gtk2_ui.h" 5 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <pango/pango.h> 8 #include <pango/pango.h>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 default: 466 default:
467 return views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER; 467 return views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER;
468 } 468 }
469 } 469 }
470 470
471 } // namespace 471 } // namespace
472 472
473 Gtk2UI::Gtk2UI() 473 Gtk2UI::Gtk2UI()
474 : default_font_size_pixels_(0), 474 : default_font_size_pixels_(0),
475 default_font_style_(gfx::Font::NORMAL), 475 default_font_style_(gfx::Font::NORMAL),
476 default_font_weight_(gfx::Font::Weight::NORMAL),
476 middle_click_action_(GetDefaultMiddleClickAction()), 477 middle_click_action_(GetDefaultMiddleClickAction()),
477 device_scale_factor_(1.0) { 478 device_scale_factor_(1.0) {
478 GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess()); 479 GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess());
479 } 480 }
480 481
481 482
482 483
483 void OnThemeChanged(GObject* obj, GParamSpec* param, Gtk2UI* gtkui) { 484 void OnThemeChanged(GObject* obj, GParamSpec* param, Gtk2UI* gtkui) {
484 gtkui->ResetStyle(); 485 gtkui->ResetStyle();
485 } 486 }
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 } 814 }
814 815
815 gfx::FontRenderParams Gtk2UI::GetDefaultFontRenderParams() const { 816 gfx::FontRenderParams Gtk2UI::GetDefaultFontRenderParams() const {
816 static gfx::FontRenderParams params = GetGtkFontRenderParams(); 817 static gfx::FontRenderParams params = GetGtkFontRenderParams();
817 return params; 818 return params;
818 } 819 }
819 820
820 void Gtk2UI::GetDefaultFontDescription( 821 void Gtk2UI::GetDefaultFontDescription(
821 std::string* family_out, 822 std::string* family_out,
822 int* size_pixels_out, 823 int* size_pixels_out,
823 int* style_out, 824 bool* italic_out,
825 gfx::Font::Weight* weight_out,
824 gfx::FontRenderParams* params_out) const { 826 gfx::FontRenderParams* params_out) const {
825 *family_out = default_font_family_; 827 *family_out = default_font_family_;
826 *size_pixels_out = default_font_size_pixels_; 828 *size_pixels_out = default_font_size_pixels_;
827 *style_out = default_font_style_; 829 *italic_out = (default_font_style_ & gfx::Font::ITALIC) != 0;
830 *weight_out = default_font_weight_;
828 *params_out = default_font_render_params_; 831 *params_out = default_font_render_params_;
829 } 832 }
830 833
831 ui::SelectFileDialog* Gtk2UI::CreateSelectFileDialog( 834 ui::SelectFileDialog* Gtk2UI::CreateSelectFileDialog(
832 ui::SelectFileDialog::Listener* listener, 835 ui::SelectFileDialog::Listener* listener,
833 ui::SelectFilePolicy* policy) const { 836 ui::SelectFilePolicy* policy) const {
834 return SelectFileDialogImpl::Create(listener, policy); 837 return SelectFileDialogImpl::Create(listener, policy);
835 } 838 }
836 839
837 bool Gtk2UI::UnityIsRunning() { 840 bool Gtk2UI::UnityIsRunning() {
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). 1341 // Non-absolute sizes are in points (again scaled by PANGO_SIZE).
1339 // Round the value when converting to pixels to match GTK's logic. 1342 // Round the value when converting to pixels to match GTK's logic.
1340 const double size_points = pango_font_description_get_size(desc) / 1343 const double size_points = pango_font_description_get_size(desc) /
1341 static_cast<double>(PANGO_SCALE); 1344 static_cast<double>(PANGO_SCALE);
1342 default_font_size_pixels_ = static_cast<int>( 1345 default_font_size_pixels_ = static_cast<int>(
1343 GetPixelsInPoint(device_scale_factor_) * size_points + 0.5); 1346 GetPixelsInPoint(device_scale_factor_) * size_points + 0.5);
1344 query.point_size = static_cast<int>(size_points); 1347 query.point_size = static_cast<int>(size_points);
1345 } 1348 }
1346 1349
1347 query.style = gfx::Font::NORMAL; 1350 query.style = gfx::Font::NORMAL;
1348 // TODO(davemoore): Support weights other than bold? 1351 query.weight =
1349 if (pango_font_description_get_weight(desc) == PANGO_WEIGHT_BOLD) 1352 static_cast<gfx::Font::Weight>(pango_font_description_get_weight(desc));
1350 query.style |= gfx::Font::BOLD;
1351 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? 1353 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE?
1352 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) 1354 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC)
1353 query.style |= gfx::Font::ITALIC; 1355 query.style |= gfx::Font::ITALIC;
1354 1356
1355 default_font_render_params_ = 1357 default_font_render_params_ =
1356 gfx::GetFontRenderParams(query, &default_font_family_); 1358 gfx::GetFontRenderParams(query, &default_font_family_);
1357 default_font_style_ = query.style; 1359 default_font_style_ = query.style;
1358 } 1360 }
1359 1361
1360 void Gtk2UI::ResetStyle() { 1362 void Gtk2UI::ResetStyle() {
(...skipping 16 matching lines...) Expand all
1377 // Blacklist scaling factors <130% (crbug.com/484400) and round 1379 // Blacklist scaling factors <130% (crbug.com/484400) and round
1378 // to 1 decimal to prevent rendering problems (crbug.com/485183). 1380 // to 1 decimal to prevent rendering problems (crbug.com/485183).
1379 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; 1381 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10;
1380 } 1382 }
1381 1383
1382 } // namespace libgtk2ui 1384 } // namespace libgtk2ui
1383 1385
1384 views::LinuxUI* BuildGtk2UI() { 1386 views::LinuxUI* BuildGtk2UI() {
1385 return new libgtk2ui::Gtk2UI; 1387 return new libgtk2ui::Gtk2UI;
1386 } 1388 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698