From 2c1e6d4871c7c474190c578214a21f83a945bdcf Mon Sep 17 00:00:00 2001 From: Magnus Jacobsson Date: Tue, 6 Jul 2021 22:13:07 +0200 Subject: [PATCH] add render method to GVLayout that returns a GVRenderData object Towards https://gitlab.com/graphviz/graphviz/-/issues/2001. --- lib/gvc++/GVLayout.cpp | 18 ++++++++++++++++-- lib/gvc++/GVLayout.h | 8 ++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/gvc++/GVLayout.cpp b/lib/gvc++/GVLayout.cpp index 879fc9fc8..9c97d1822 100644 --- a/lib/gvc++/GVLayout.cpp +++ b/lib/gvc++/GVLayout.cpp @@ -7,8 +7,7 @@ #include "GVLayout.h" #include "GVRenderData.h" #include -#include -#include +#include namespace GVC { @@ -34,4 +33,19 @@ GVLayout::~GVLayout() { gvFreeLayout(m_gvc->c_struct(), m_g->c_struct()); } +GVRenderData GVLayout::render(const std::string &format) const { + char *result = nullptr; + unsigned int length = 0; + const auto rc = gvRenderData(m_gvc->c_struct(), m_g->c_struct(), + format.c_str(), &result, &length); + if (rc) { + if (result) { + gvFreeRenderData(result); + } + throw std::runtime_error("Rendering failed"); + } + + return GVRenderData(result, length); +} + } // namespace GVC diff --git a/lib/gvc++/GVLayout.h b/lib/gvc++/GVLayout.h index aa66535d0..1c1d43bf6 100644 --- a/lib/gvc++/GVLayout.h +++ b/lib/gvc++/GVLayout.h @@ -2,8 +2,9 @@ #include -#include "cgraph++/AGraph.h" -#include "gvc++/GVContext.h" +#include "GVContext.h" +#include "GVRenderData.h" +#include #ifdef _WIN32 #if gvc___EXPORTS // CMake's substitution of gvc++_EXPORTS @@ -35,6 +36,9 @@ public: GVLayout(GVLayout &&) = default; GVLayout &operator=(GVLayout &&) = default; + // render the layout in the specified format + GVRenderData render(const std::string &format) const; + private: std::shared_ptr m_gvc; std::shared_ptr m_g; -- 2.40.0