From: Daniel Karbach Date: Sun, 29 Sep 2024 22:02:50 +0000 (+0200) Subject: show channel below quote X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=2d60414ac711e68779829f8949eaed4770f064d6;p=ffmpeg-test.git show channel below quote --- diff --git a/src/app/Renderer.h b/src/app/Renderer.h index bb81c79..b31c73c 100644 --- a/src/app/Renderer.h +++ b/src/app/Renderer.h @@ -2,6 +2,7 @@ #define TEST_APP_RENDERER_H_ #include +#include extern "C" { #include "cairo.h" } @@ -16,16 +17,22 @@ class Renderer { 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() { } @@ -42,6 +49,10 @@ public: 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(); } @@ -51,9 +62,16 @@ public: 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; @@ -62,6 +80,8 @@ private: std::string text; pango::Layout text_layout; + std::string channel; + pango::Layout channel_layout; }; diff --git a/src/main.cpp b/src/main.cpp index 36f0cac..31cfa98 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,10 +37,12 @@ void ws_handler(void *user, const Json::Value &json) { 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(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); } } diff --git a/src/pango/Layout.h b/src/pango/Layout.h index 3e52df9..c465da7 100644 --- a/src/pango/Layout.h +++ b/src/pango/Layout.h @@ -9,6 +9,8 @@ #include #include "Font.h" +#include "pango/pango-layout.h" +#include "pango/pango-types.h" namespace pango { @@ -40,6 +42,18 @@ public: } 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); } @@ -58,11 +72,14 @@ public: 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; };