Skip to content

Commit

Permalink
Font/Pango Text: minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Aug 12, 2017
1 parent ec042a4 commit 5364c50
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/font/text.cpp
Expand Up @@ -645,7 +645,8 @@ void pango_text::render(PangoLayout& layout, const PangoRectangle& rect, const s

cairo_format_t format = CAIRO_FORMAT_ARGB32;

unsigned char* buffer = &surface_buffer_[surface_buffer_offset];
uint8_t* buffer = &surface_buffer_[surface_buffer_offset];

std::unique_ptr<cairo_surface_t, std::function<void(cairo_surface_t*)>> cairo_surface(
cairo_image_surface_create_for_data(buffer, format, width, height, stride), cairo_surface_destroy);
std::unique_ptr<cairo_t, std::function<void(cairo_t*)>> cr(cairo_create(cairo_surface.get()), cairo_destroy);
Expand Down Expand Up @@ -696,7 +697,7 @@ void pango_text::rerender(const bool force)

this->create_surface_buffer(stride * height);

if (!surface_buffer_.size()) {
if (surface_buffer_.empty()) {
surface_.assign(create_neutral_surface(0, 0));
return;
}
Expand All @@ -723,13 +724,11 @@ void pango_text::rerender(const bool force)

void pango_text::create_surface_buffer(const size_t size) const
{
// clear old buffer
// Clear surface.
surface_.assign(nullptr);

surface_buffer_.resize(size);

// Not sure why this is needed, perhaps SDL assumes it?
for (auto & c : surface_buffer_) { c = 0; }
// Resize buffer appropriately and clear all existing data (essentially sets all pixel values to 0).
surface_buffer_.assign(size, 0);
}

bool pango_text::set_markup(utils::string_view text, PangoLayout& layout) {
Expand Down
2 changes: 1 addition & 1 deletion src/font/text.hpp
Expand Up @@ -380,7 +380,7 @@ class pango_text
* data source for the SDL_Surface. This means the buffer needs to be stored
* in the object, since SDL_Surface doesn't own its buffer.
*/
mutable std::vector<unsigned char> surface_buffer_;
mutable std::vector<uint8_t> surface_buffer_;

/**
* Creates a new buffer.
Expand Down

0 comments on commit 5364c50

Please sign in to comment.