diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2017-09-22 04:36:33 +0200 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2017-09-22 04:36:33 +0200 |
| commit | 9827be183c04917fc0908733a0c7dfab8d905dd0 (patch) | |
| tree | 2b481e50a79ebd4ffe82510c4f1eaf5b9649bcd9 | |
| parent | 9be8ff33679ff128d43eb76d2f3ca9651e85be4a (diff) | |
EMConverter: remove unneeded font size management
(bzr r4253.4.1)
| -rw-r--r-- | tests/test_em_converter.cpp | 26 | ||||
| -rw-r--r-- | tests/test_raw_pixel.cpp | 3 | ||||
| -rw-r--r-- | unity-shared/EMConverter.cpp | 65 | ||||
| -rw-r--r-- | unity-shared/EMConverter.h | 17 | ||||
| -rw-r--r-- | unity-shared/UnitySettings.cpp | 28 |
5 files changed, 14 insertions, 125 deletions
diff --git a/tests/test_em_converter.cpp b/tests/test_em_converter.cpp index 3936c08bc..44239263e 100644 --- a/tests/test_em_converter.cpp +++ b/tests/test_em_converter.cpp @@ -26,34 +26,19 @@ namespace unity { int const PIXEL_SIZE = 24; -int const FONT_SIZE = 13; double const DPI = 96.0; class TestEMConverter : public Test { public: TestEMConverter() - : em_converter(FONT_SIZE, DPI) + : em_converter(DPI) { } EMConverter em_converter; }; -TEST_F(TestEMConverter, TestCtor) -{ - EXPECT_EQ(FONT_SIZE, em_converter.GetFontSize()); - EXPECT_EQ(DPI, em_converter.GetDPI()); -} - -TEST_F(TestEMConverter, TestSetFontSize) -{ - int const font_size = 15; - - em_converter.SetFontSize(font_size); - EXPECT_EQ(font_size, em_converter.GetFontSize()); -} - TEST_F(TestEMConverter, TestSetDPI) { int const dpi = 120.0; @@ -79,10 +64,13 @@ TEST_F(TestEMConverter, TestDPIScale2) EXPECT_FLOAT_EQ(em_converter.DPIScale(), 2.0); } -TEST_F(TestEMConverter, TestPtToPx) +TEST_F(TestEMConverter, TestConvertPixelScaled) { - int pt = 12; - EXPECT_EQ(em_converter.PtToPx(pt), 16); + for (double scale : std::vector<double>({1.0, 1.25, 1.5, 1.75, 2})) + { + em_converter.SetDPI(DPI * scale); + EXPECT_EQ(std::round(PIXEL_SIZE * scale), em_converter.CP(PIXEL_SIZE)); + } } } // namespace unity diff --git a/tests/test_raw_pixel.cpp b/tests/test_raw_pixel.cpp index 140bf6010..c7cc9eef5 100644 --- a/tests/test_raw_pixel.cpp +++ b/tests/test_raw_pixel.cpp @@ -25,14 +25,13 @@ using namespace testing; namespace unity { -int const FONT_SIZE = 13; double const DPI = 96.0; class TestRawPixel : public Test { public: TestRawPixel() - : cv(std::make_shared<EMConverter>(FONT_SIZE, DPI)) + : cv(std::make_shared<EMConverter>(DPI)) , p_i(10_em) , p_f(10.0_em) { diff --git a/unity-shared/EMConverter.cpp b/unity-shared/EMConverter.cpp index 6a65ab38f..9616a057f 100644 --- a/unity-shared/EMConverter.cpp +++ b/unity-shared/EMConverter.cpp @@ -23,86 +23,31 @@ namespace unity { -double const BASE_DPI = 96.0; -double const DEFAULT_PPE = 10.0; -double const PIXELS_PER_INCH = 72.0; - -EMConverter::EMConverter(int font_size, double dpi) - : pixels_per_em_(DEFAULT_PPE) - , base_pixels_per_em_(DEFAULT_PPE) - , dpi_(dpi) - , font_size_(font_size) -{ - UpdatePixelsPerEM(); - UpdateBasePixelsPerEM(); -} - -double EMConverter::PtToPx(int pt) -{ - return pt * dpi_ / PIXELS_PER_INCH; -} - -void EMConverter::UpdatePixelsPerEM() +namespace { - pixels_per_em_ = font_size_ * dpi_ / PIXELS_PER_INCH; - - if (pixels_per_em_ == 0) - pixels_per_em_ = DEFAULT_PPE; +const double BASE_DPI = 96.0; } -void EMConverter::UpdateBasePixelsPerEM() -{ - base_pixels_per_em_ = font_size_ * BASE_DPI / PIXELS_PER_INCH; - - if (base_pixels_per_em_ == 0) - base_pixels_per_em_ = DEFAULT_PPE; -} - -bool EMConverter::SetFontSize(int font_size) -{ - if (font_size != font_size_) - { - font_size_ = font_size; - UpdatePixelsPerEM(); - UpdateBasePixelsPerEM(); - return true; - } - - return false; -} +EMConverter::EMConverter(double dpi) + : dpi_(dpi) +{} bool EMConverter::SetDPI(double dpi) { if (dpi != dpi_) { dpi_ = dpi; - UpdatePixelsPerEM(); return true; } return false; } -int EMConverter::GetFontSize() const -{ - return font_size_; -} - double EMConverter::GetDPI() const { return dpi_; } -double EMConverter::EMToPixels(double em) const -{ - return (em * pixels_per_em_); -} - -double EMConverter::PixelsToBaseEM(int pixels) const -{ - return (pixels / base_pixels_per_em_); -} - double EMConverter::CP(int pixels) const { return std::round(pixels * DPIScale()); diff --git a/unity-shared/EMConverter.h b/unity-shared/EMConverter.h index 4847d6274..374ed43c2 100644 --- a/unity-shared/EMConverter.h +++ b/unity-shared/EMConverter.h @@ -30,31 +30,16 @@ class EMConverter public: typedef std::shared_ptr<EMConverter> Ptr; - EMConverter(int font_size = 0, double dpi = 96.0); + EMConverter(double dpi = 96.0); - bool SetFontSize(int font_size); bool SetDPI(double dpi); - - int GetFontSize() const; double GetDPI() const; double CP(int pixels) const; double DPIScale() const; - double PtToPx(int pt); - private: - void UpdatePixelsPerEM(); - void UpdateBasePixelsPerEM(); - - double EMToPixels(double em) const; - double PixelsToBaseEM(int pixels) const; - - double pixels_per_em_; - double base_pixels_per_em_; - double dpi_; - int font_size_; }; } // namespace unity diff --git a/unity-shared/UnitySettings.cpp b/unity-shared/UnitySettings.cpp index cf3f557d9..27e91b9be 100644 --- a/unity-shared/UnitySettings.cpp +++ b/unity-shared/UnitySettings.cpp @@ -65,7 +65,6 @@ const std::string UBUNTU_UI_SETTINGS = "com.ubuntu.user-interface"; const std::string SCALE_FACTOR = "scale-factor"; const std::string GNOME_UI_SETTINGS = "org.gnome.desktop.interface"; -const std::string GNOME_FONT_NAME = "font-name"; const std::string GNOME_CURSOR_SIZE = "cursor-size"; const std::string GNOME_SCALE_FACTOR = "scaling-factor"; const std::string GNOME_TEXT_SCALE_FACTOR = "text-scaling-factor"; @@ -174,11 +173,6 @@ public: UpdateDPI(); }); - signals_.Add<void, GSettings*, const gchar*>(gnome_ui_settings_, "changed::" + GNOME_FONT_NAME, [this] (GSettings*, const gchar* t) { - UpdateFontSize(); - UpdateDPI(); - }); - signals_.Add<void, GSettings*, const gchar*>(gnome_ui_settings_, "changed::" + GNOME_TEXT_SCALE_FACTOR, [this] (GSettings*, const gchar* t) { double new_scale_factor = g_settings_get_double(gnome_ui_settings_, GNOME_TEXT_SCALE_FACTOR.c_str()); g_settings_set_double(ui_settings_, TEXT_SCALE_FACTOR.c_str(), new_scale_factor); @@ -203,7 +197,6 @@ public: UpdateGesturesSetting(); UpdateTextScaleFactor(); UpdateCursorScaleFactor(); - UpdateFontSize(); UpdateDPI(); CacheFormFactor(); @@ -365,27 +358,6 @@ public: return g_settings_get_boolean(usettings_, PAM_CHECK_ACCOUNT_TYPE.c_str()); } - int GetFontSize() const - { - gint font_size; - PangoFontDescription* desc; - - glib::String font_name(g_settings_get_string(gnome_ui_settings_, GNOME_FONT_NAME.c_str())); - desc = pango_font_description_from_string(font_name); - font_size = pango_font_description_get_size(desc); - pango_font_description_free(desc); - - return font_size / 1024; - } - - void UpdateFontSize() - { - int font_size = GetFontSize(); - - for (auto const& em : em_converters_) - em->SetFontSize(font_size); - } - void UpdateTextScaleFactor() { parent_->font_scaling = g_settings_get_double(ui_settings_, TEXT_SCALE_FACTOR.c_str()); |
