summaryrefslogtreecommitdiff
path: root/unity-shared
diff options
authorAndrea Azzarone <azzaronea@gmail.com>2015-02-13 18:19:08 +0100
committerAndrea Azzarone <azzaronea@gmail.com>2015-02-13 18:19:08 +0100
commite691f8865e4a73af5e8e33b62445fd653823ad4f (patch)
tree6c654e99d223204ca11a91eecdd37ed7457c8d94 /unity-shared
parent41b61acafe6f593806e48142191ad281275f7270 (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)
Diffstat (limited to 'unity-shared')
-rw-r--r--unity-shared/StaticCairoText.cpp43
-rw-r--r--unity-shared/StaticCairoText.h5
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);