lokit: unify fill transparency items

Online just listens to .uno:FillFloatTransparence but the set-item
in core it corresponds to, does not represent the fill-transparency
types like 'None' and 'Solid'. This is represented by another item
called XFillTransparencyItem. As a result the mobile wizard does not
show the correct transparency fill type always.
To solve this, this patch encodes the constant transparency percentage
in case of Solid and None(always 0%) as an intensity and stores this
info in the statechange message of .uno:FillFloatTransparence whenever
there is no gradient type and corrects the 'style' attribute of the
message appropriately.

More detailed information is provided as comments at appropriate
places in the patch.

Change-Id: I443ef4ce349badf28f6c2c702b1014868d9c6ed5
(cherry picked from commit 34969e9c04f9305d19826c72a29e38e26794cbe3)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90986
Tested-by: Jenkins
Reviewed-by: Dennis Francis <dennis.francis@collabora.com>
This commit is contained in:
Dennis Francis 2020-03-22 19:43:03 +05:30
parent 2176250581
commit f08bbb5648
2 changed files with 54 additions and 0 deletions

View file

@ -2502,6 +2502,19 @@ boost::property_tree::ptree XFillFloatTransparenceItem::dumpAsJSON() const
boost::property_tree::ptree aTree = XFillGradientItem::dumpAsJSON();
aTree.put("commandName", ".uno:FillFloatTransparence");
if (!bEnabled)
{
boost::property_tree::ptree& rState = aTree.get_child("state");
// When gradient fill is disabled, the intensity fields contain the
// constant encoded percent-transparency. However we use that here to just
// distinguish between 'None' and 'Solid' types and correct the 'style'
// property appropriately.
if (GetGradientValue().GetStartIntens() == 100)
rState.put("style", "NONE");
else
rState.put("style", "SOLID");
}
return aTree;
}

View file

@ -36,6 +36,9 @@
#include <svx/chrtitem.hxx>
#include <svx/xlnwtit.hxx>
#include <svx/xflgrit.hxx>
#include <svx/xflftrit.hxx>
#include <svx/xfltrit.hxx>
#include <comphelper/lok.hxx>
using namespace com::sun::star::drawing;
@ -314,6 +317,40 @@ void SwDrawShell::ExecDrawAttrArgs(SfxRequest const & rReq)
pView->GetModel()->SetChanged();
}
static void lcl_unifyFillTransparencyItems(SfxItemSet& rSet)
{
// Transparent fill options are None, Solid, Linear, Axial, Radial, Elliptical, Quadratic, Square.
// But this is represented across two items namely XFillTransparenceItem (for None and Solid)
// and XFillFloatTransparenceItem (for the rest). To simplify the representation in LOKit case let's
// use XFillFloatTransparenceItem to carry the information of XFillTransparenceItem when gradients
// are disabled. When gradient transparency is disabled, all fields of XFillFloatTransparenceItem are invalid
// and not used. So convert XFillTransparenceItem's constant transparency percentage as an intensity
// and assign this to the XFillFloatTransparenceItem's start-intensity and end-intensity fields.
// Now the LOK clients need only listen to statechange messages of XFillFloatTransparenceItem
// to get fill-transparency settings instead of listening to two separate items.
XFillFloatTransparenceItem* pFillFloatTranspItem =
const_cast<XFillFloatTransparenceItem*>
(rSet.GetItem<XFillFloatTransparenceItem>(XATTR_FILLFLOATTRANSPARENCE));
if (!pFillFloatTranspItem || pFillFloatTranspItem->IsEnabled())
return;
const XFillTransparenceItem* pFillTranspItem =
rSet.GetItem<XFillTransparenceItem>(XATTR_FILLTRANSPARENCE);
if (!pFillTranspItem)
return;
XGradient aTmpGradient = pFillFloatTranspItem->GetGradientValue();
sal_uInt16 nTranspPercent = pFillTranspItem->GetValue();
// Encode transparancy percentage as intensity
sal_uInt16 nIntensity = 100 - std::min<sal_uInt16>
(std::max<sal_uInt16>(nTranspPercent, 0), 100);
aTmpGradient.SetStartIntens(nIntensity);
aTmpGradient.SetEndIntens(nIntensity);
pFillFloatTranspItem->SetGradientValue(aTmpGradient);
}
void SwDrawShell::GetDrawAttrState(SfxItemSet& rSet)
{
SdrView* pSdrView = GetShell().GetDrawView();
@ -323,7 +360,11 @@ void SwDrawShell::GetDrawAttrState(SfxItemSet& rSet)
bool bDisable = Disable( rSet );
if( !bDisable )
{
pSdrView->GetAttributes( rSet );
if (comphelper::LibreOfficeKit::isActive())
lcl_unifyFillTransparencyItems(rSet);
}
}
else
rSet.Put(pSdrView->GetDefaultAttr());