diff options
| author | Andrea Azzarone <azzaronea@gmail.com> | 2015-02-27 15:38:00 +0000 |
|---|---|---|
| committer | CI Train Bot <ci-train-bot@canonical.com> | 2015-02-27 15:38:00 +0000 |
| commit | 72e5936a677746312f09567b462c93260d971333 (patch) | |
| tree | 062b3301389f138b15b14a05a778ed46eda4dde7 /unity-shared | |
| parent | 6f3c64d1ac7684c18f292628d490e74f8e4b9a80 (diff) | |
| parent | e691f8865e4a73af5e8e33b62445fd653823ad4f (diff) | |
Remove FontSettings.*.
Add the possibility to specify the font size and the font weight without chaning the default font name. Fix lp 886478. Fixes: #886478 Approved by: Brandon Schaefer, Marco Trevisan (TreviƱo) (bzr r3926)
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/StaticCairoText.cpp | 43 | ||||
| -rw-r--r-- | unity-shared/StaticCairoText.h | 5 |
2 files changed, 47 insertions, 1 deletions
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); |
