From 5d7910f21e881998f142aef473b27ebfd29eb020 Mon Sep 17 00:00:00 2001 From: Darshan-upadhyay1110 Date: Tue, 26 Mar 2024 11:36:47 +0530 Subject: Online: send color preview JSON property to online MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Autofilter has submenus like `filter by font color` and `filter by bg color` - to display it's color preview in online we some data from core to identify that it's a color base dialog - this patch will help to add color preview of following Change-Id: I71c4e276f8c6dd35d6d318ce67cedf9c15a91d29 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165298 Tested-by: Jenkins CollaboraOffice Reviewed-by: Szymon Kłos --- vcl/source/treelist/svtabbx.cxx | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/vcl/source/treelist/svtabbx.cxx b/vcl/source/treelist/svtabbx.cxx index 6f309bb9a85f..feb4f0b2011f 100644 --- a/vcl/source/treelist/svtabbx.cxx +++ b/vcl/source/treelist/svtabbx.cxx @@ -35,6 +35,9 @@ #include #include #include +#include +#include +#include using namespace ::com::sun::star::uno; using namespace ::com::sun::star::accessibility; @@ -42,6 +45,29 @@ using namespace ::com::sun::star::accessibility; constexpr SvLBoxTabFlags MYTABMASK = SvLBoxTabFlags::ADJUST_RIGHT | SvLBoxTabFlags::ADJUST_LEFT | SvLBoxTabFlags::ADJUST_CENTER | SvLBoxTabFlags::FORCE; +namespace { + OString lcl_extractPngString(const BitmapEx& rImage) + { + SvMemoryStream aOStm(65535, 65535); + // Use fastest compression "1" + css::uno::Sequence aFilterData{ + comphelper::makePropertyValue("Compression", sal_Int32(1)), + }; + vcl::PngImageWriter aPNGWriter(aOStm); + aPNGWriter.setParameters(aFilterData); + if (aPNGWriter.write(rImage)) + { + css::uno::Sequence aSeq(static_cast(aOStm.GetData()), + aOStm.Tell()); + OStringBuffer aBuffer("data:image/png;base64,"); + ::comphelper::Base64::encode(aBuffer, aSeq); + return aBuffer.makeStringAndClear(); + } + + return ""_ostr; + } +} + static void lcl_DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter, SvTreeListEntry* pEntry, SvTabListBox* pTabListBox, @@ -51,6 +77,7 @@ static void lcl_DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter, { auto aNode = rJsonWriter.startStruct(); + // DEPRECATED // simple listbox value const SvLBoxItem* pIt = pEntry->GetFirstItem(SvLBoxItemType::String); if (pIt) @@ -79,6 +106,8 @@ static void lcl_DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter, { const OUString& rCollapsed = pBmpItem->GetBitmap1().GetStock(); const OUString& rExpanded = pBmpItem->GetBitmap2().GetStock(); + + // send identifier only, we will use svg icon if (!o3tl::trim(rCollapsed).empty() || !o3tl::trim(rExpanded).empty()) { auto aColumn = rJsonWriter.startStruct(); @@ -87,6 +116,22 @@ static void lcl_DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter, if (!o3tl::trim(rExpanded).empty()) rJsonWriter.put("expanded", rExpanded); } + // custom bitmap - send png + else + { + BitmapEx aCollapsedImage = pBmpItem->GetBitmap1().GetBitmapEx(); + BitmapEx aExpandedImage = pBmpItem->GetBitmap2().GetBitmapEx(); + bool bHasCollapsed = !aCollapsedImage.IsEmpty() && !aCollapsedImage.GetSizePixel().IsEmpty(); + bool bHasExpanded = !aExpandedImage.IsEmpty() && !aExpandedImage.GetSizePixel().IsEmpty(); + if (bHasCollapsed || bHasExpanded) + { + auto aColumn = rJsonWriter.startStruct(); + if (bHasCollapsed) + rJsonWriter.put("collapsedimage", lcl_extractPngString(aCollapsedImage)); + if (bHasExpanded) + rJsonWriter.put("collapsedimage", lcl_extractPngString(aExpandedImage)); + } + } } } } -- cgit v1.2.3