diff options
| author | Andrea Azzarone <azzaronea@gmail.com> | 2015-02-13 18:19:08 +0100 |
|---|---|---|
| committer | Andrea Azzarone <azzaronea@gmail.com> | 2015-02-13 18:19:08 +0100 |
| commit | e691f8865e4a73af5e8e33b62445fd653823ad4f (patch) | |
| tree | 6c654e99d223204ca11a91eecdd37ed7457c8d94 | |
| parent | 41b61acafe6f593806e48142191ad281275f7270 (diff) | |
Add the possibility to specify the font size and the font weight without chaning the default font name.
Fix lp 886478. Fixes LP: #1398287 (bzr r3893.8.1)
| -rw-r--r-- | launcher/SwitcherView.cpp | 3 | ||||
| -rw-r--r-- | unity-shared/StaticCairoText.cpp | 43 | ||||
| -rw-r--r-- | unity-shared/StaticCairoText.h | 5 |
3 files changed, 49 insertions, 2 deletions
diff --git a/launcher/SwitcherView.cpp b/launcher/SwitcherView.cpp index 375d50dd4..0534581f5 100644 --- a/launcher/SwitcherView.cpp +++ b/launcher/SwitcherView.cpp @@ -81,7 +81,8 @@ SwitcherView::SwitcherView(ui::AbstractIconRenderer::Ptr const& renderer) text_view_->SetMaximumWidth(tile_size * TEXT_TILE_MULTIPLIER); text_view_->SetLines(-1); text_view_->SetTextColor(nux::color::White); - text_view_->SetFont("Ubuntu Bold 10"); + text_view_->SetFontSize(10); + text_view_->SetFontWeight(PANGO_WEIGHT_BOLD); text_view_->SetScale(scale); icon_size.changed.connect(sigc::mem_fun(this, &SwitcherView::OnIconSizeChanged)); diff --git a/unity-shared/StaticCairoText.cpp b/unity-shared/StaticCairoText.cpp index ebb634f6e..bc2cbbb49 100644 --- a/unity-shared/StaticCairoText.cpp +++ b/unity-shared/StaticCairoText.cpp @@ -30,7 +30,6 @@ #include <Nux/TextureArea.h> #include <NuxGraphics/CairoGraphics.h> -#include <pango/pango.h> #include <pango/pangocairo.h> #include <UnityCore/GLibWrapper.h> @@ -95,6 +94,8 @@ struct StaticCairoText::Impl : sigc::trackable UnderlineState underline_; std::string font_; + int font_size_ = -1; + PangoWeight font_weight_ = (PangoWeight) -1; std::list<BaseTexturePtr> textures2D_; @@ -418,6 +419,32 @@ void StaticCairoText::SetFont(std::string const& font) } } +void StaticCairoText::SetFontSize(int font_size) +{ + if (pimpl->font_size_ != font_size) + { + pimpl->font_size_ = font_size; + pimpl->need_new_extent_cache_ = true; + Size s = GetTextExtents(); + SetMinimumHeight(s.height); + NeedRedraw(); + sigFontChanged.emit(this); + } +} + +void StaticCairoText::SetFontWeight(PangoWeight font_weight) +{ + if (pimpl->font_weight_ != font_weight) + { + pimpl->font_weight_ = font_weight; + pimpl->need_new_extent_cache_ = true; + Size s = GetTextExtents(); + SetMinimumHeight(s.height); + NeedRedraw(); + sigFontChanged.emit(this); + } +} + std::string StaticCairoText::GetFont() { return pimpl->font_; @@ -559,6 +586,13 @@ Size StaticCairoText::Impl::GetTextExtents() const layout = pango_cairo_create_layout(cr); desc = pango_font_description_from_string(font.c_str()); + + if (font_size_ > 0) + pango_font_description_set_size(desc, font_size_ * PANGO_SCALE); + + if (font_weight_ > 0) + pango_font_description_set_weight(desc, font_weight_); + pango_layout_set_font_description(layout, desc); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_ellipsize(layout, GetPangoEllipsizeMode()); @@ -709,6 +743,13 @@ void StaticCairoText::Impl::DrawText(CacheTexture::Ptr const& texture) desc = pango_font_description_from_string(font.c_str()); + + if (font_size_ > 0) + pango_font_description_set_size(desc, font_size_ * PANGO_SCALE); + + if (font_weight_ > 0) + pango_font_description_set_weight(desc, font_weight_); + pango_layout_set_font_description(layout, desc); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_ellipsize(layout, GetPangoEllipsizeMode()); diff --git a/unity-shared/StaticCairoText.h b/unity-shared/StaticCairoText.h index 77ddc9f5c..7f85db98a 100644 --- a/unity-shared/StaticCairoText.h +++ b/unity-shared/StaticCairoText.h @@ -21,6 +21,7 @@ #ifndef UNITYSHARED_STATICCAIROTEXT_H #define UNITYSHARED_STATICCAIROTEXT_H +#include <pango/pango.h> #include <string> #include <Nux/Nux.h> @@ -82,8 +83,12 @@ public: void SetTextEllipsize(EllipsizeState state); void SetTextAlignment(AlignState state); void SetTextVerticalAlignment(AlignState state); + void SetFont(std::string const& font); + void SetFontSize(int); + void SetFontWeight(PangoWeight); std::string GetFont(); + void SetUnderline(UnderlineState underline); void SetLines(int maximum_lines); void SetLineSpacing(float line_spacing); |
