Skip to content

Commit

Permalink
The font now has size
Browse files Browse the repository at this point in the history
  • Loading branch information
djowel committed Oct 14, 2023
1 parent 72bc110 commit 87ce9f8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/icons_list/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class fixed_size_base : public default_label
public:
view_limits limits(const basic_context &ctx) const override
{
point size = measure_text(ctx.canvas, "9" ,get_font(), get_font_size());
point size = measure_text(ctx.canvas, "9", get_font(), get_font_size());
size.x *= Size;
return { { size.x, size.y }, { size.x, size.y } };
}
Expand Down
1 change: 1 addition & 0 deletions lib/include/elements/support/font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ namespace cycfi { namespace elements

friend class canvas;
cairo_font_face_t* _handle = nullptr;
float _size = 12;
};

////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion lib/src/element/gallery/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace cycfi { namespace elements
font = font.size(font._size * get_size());

// Measure text and icon
auto text_size = measure_text(ctx.canvas, get_text().c_str(), font, font._size * get_size());
auto text_size = measure_text(ctx.canvas, get_text().c_str(), font, font._size);
auto icon_space = (get_size() * theme.icon_font._size) + 8;
auto size = text_size;

Expand Down
1 change: 1 addition & 0 deletions lib/src/support/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ namespace cycfi { namespace elements
{
if (font_._handle)
cairo_set_font_face(&_context, font_._handle);
font_size(font_._size);
}

void canvas::font(elements::font const& font_, float size)
Expand Down
6 changes: 6 additions & 0 deletions lib/src/support/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,23 +675,29 @@ namespace cycfi { namespace elements
font::font(font const& rhs)
{
_handle = cairo_font_face_reference(rhs._handle);
_size = rhs._size;
}

font& font::operator=(font const& rhs)
{
if (&rhs != this)
{
_handle = cairo_font_face_reference(rhs._handle);
_size = rhs._size;
}
return *this;
}

font::font(font&& rhs) noexcept
{
std::swap(_handle, rhs._handle);
std::swap(_size, rhs._size);
}

font& font::operator=(font&& rhs) noexcept
{
std::swap(_handle, rhs._handle);
std::swap(_size, rhs._size);
return *this;
}

Expand Down

0 comments on commit 87ce9f8

Please # to comment.