From 9fa0ee7652fe9741641e57cb72bbad5964d6db43 Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Sun, 11 Feb 2024 16:30:33 +0100 Subject: [PATCH] Support font color customization for toSvg --- include/llama/DumpMapping.hpp | 15 ++++++++++----- tests/dump.cpp | 7 ++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/llama/DumpMapping.hpp b/include/llama/DumpMapping.hpp index 90f5c94753..111b6a519f 100644 --- a/include/llama/DumpMapping.hpp +++ b/include/llama/DumpMapping.hpp @@ -13,6 +13,7 @@ # include # include # include +# include # include namespace llama @@ -250,7 +251,8 @@ namespace llama const Mapping& mapping, std::size_t wrapByteCount = 64, bool breakBoxes = true, - const std::vector& palette = {}) -> std::string + const std::vector& palette = {}, + std::string_view textColor = "black") -> std::string { constexpr auto byteSizeInPixel = 30; constexpr auto blobBlockWidth = 60; @@ -276,13 +278,14 @@ namespace llama const auto height = blobRows * byteSizeInPixel; svg += fmt::format( R"a( -{} +{} )a", blobYOffset[i], blobBlockWidth, height, blobBlockWidth / 2, blobYOffset[i] + height / 2, + textColor, name); }; for(std::size_t i = 0; i < Mapping::blobCount; i++) @@ -377,10 +380,11 @@ namespace llama y + byteSizeInPixel); } svg += fmt::format( - R"({} {} + R"({} {} )", x + width / 2, y + byteSizeInPixel * 3 / 4, + textColor, internal::formatArrayIndex(info.arrayIndex), internal::xmlEscape(std::string{info.recordCoordTags})); if(cropBoxes) @@ -411,9 +415,10 @@ namespace llama LLAMA_EXPORT template - auto toSvg(const Mapping& mapping, const std::vector& palette) -> std::string + auto toSvg(const Mapping& mapping, const std::vector& palette, std::string_view textColor = "#000") + -> std::string { - return toSvg(mapping, 64, true, palette); + return toSvg(mapping, 64, true, palette, textColor); } /// Returns an HTML document visualizing the memory layout created by the given mapping. The visualization is diff --git a/tests/dump.cpp b/tests/dump.cpp index f1ee7402e7..8d36e9d1f6 100644 --- a/tests/dump.cpp +++ b/tests/dump.cpp @@ -15,13 +15,13 @@ namespace using ArrayExtents = decltype(extents); template - void dump(const Mapping& mapping, const std::vector& palette = {}) + void dump(const Mapping& mapping, const std::vector& palette = {}, std::string_view font = "black") { const auto outputDir = std::string{"dump"}; std::filesystem::create_directory(outputDir); // undocumented Catch feature, see: https://github.com/catchorg/Catch2/issues/510 const auto filename = outputDir + "/" + Catch::getResultCapture().getCurrentTestName(); - std::ofstream{filename + ".svg"} << llama::toSvg(mapping, palette); + std::ofstream{filename + ".svg"} << llama::toSvg(mapping, palette, font); std::ofstream{filename + ".html"} << llama::toHtml(mapping); } } // namespace @@ -410,7 +410,8 @@ TEST_CASE("dump.AdePT.track.palette") { dump( llama::mapping::AoS, Track>{{}}, - {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF, 0xFFFFFF}); + {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF, 0xFFFFFF}, + "white"); } TEST_CASE("dump.LHCb.Custom4")