#define TEST_APP_RENDERER_H_
#include <cstdint>
+#include <iostream>
extern "C" {
#include "cairo.h"
}
public:
Renderer(uint8_t *plane, int linesize, int width, int height)
- : font("DejaVu Sans 32px")
+ : text_font("DejaVu Sans 32px")
+ , channel_font("DejaVu Sans 24px")
, surface(plane, linesize, CAIRO_FORMAT_ARGB32, width, height)
, ctx(surface.CreateContext())
, width(width)
, height(height)
, text()
- , text_layout(ctx.CreateLayout()) {
- text_layout.SetFont(font);
+ , text_layout(ctx.CreateLayout())
+ , channel()
+ , channel_layout(ctx.CreateLayout()) {
+ text_layout.SetFont(text_font);
text_layout.SetWidth(width / 2);
+ channel_layout.SetFont(channel_font);
+ channel_layout.SetWidth(width / 2);
SetText("Hello, I am a long text that should wrap eventually when it gets long enough to cross the halfway point of the total width available (not including the offset which is added afterwards).");
+ SetChannel("");
}
~Renderer() {
}
ctx.SetSourceRGB(1, 1, 1);
text_layout.Render();
+ ctx.MoveTo(50, 50 + text_layout.GetLogicalRect().height + 10);
+ ctx.SetSourceRGB(0.392, 0.255, 0.647);
+ channel_layout.Render();
+
surface.Flush();
}
text_layout.Update();
}
+ void SetChannel(const std::string &c) {
+ channel = c;
+ channel_layout.SetText(channel);
+ channel_layout.Update();
+ }
+
private:
- pango::Font font;
+ pango::Font text_font;
+ pango::Font channel_font;
cairo::Surface surface;
cairo::Context ctx;
std::string text;
pango::Layout text_layout;
+ std::string channel;
+ pango::Layout channel_layout;
};
Json::Value data;
Json::Reader json_reader;
json_reader.parse(data_string, data);
- const std::string text = data["model"]["text"].asString();
app::Renderer *renderer = static_cast<app::Renderer *>(user);
+ const std::string text = data["model"]["text"].asString();
+ const std::string channel = data["model"]["channel"]["title"].asString();
if (text.length() > 0) {
renderer->SetText(text);
+ renderer->SetChannel(channel);
}
}
#include <utility>
#include "Font.h"
+#include "pango/pango-layout.h"
+#include "pango/pango-types.h"
namespace pango {
}
public:
+ const PangoRectangle &GetInkRect() const {
+ return ink_rect;
+ }
+
+ int GetLineCount() {
+ return pango_layout_get_line_count(l);
+ }
+
+ const PangoRectangle &GetLogicalRect() const {
+ return logical_rect;
+ }
+
void Render() {
pango_cairo_show_layout(c, l);
}
void Update() {
pango_cairo_update_layout(c, l);
+ pango_layout_get_pixel_extents(l, &ink_rect, &logical_rect);
}
private:
cairo_t *c;
PangoLayout *l;
+ PangoRectangle ink_rect;
+ PangoRectangle logical_rect;
};