Use correct type when getting document colors
After commit 0460be8848
Send document colors with lok callback
There was issue detected by CI:
/sc/source/core/data/document10.cxx:198:46: runtime error: downcast of address 0x6100000efa40 which does not point to an object of type 'const SvxColorItem'
0x6100000efa40: note: object is of type 'SvxBrushItem'
00 00 00 00 b0 79 19 48 ce 7f 00 00 01 00 00 00 94 00 be be 4c 17 00 00 a0 be be be cc cc ff 00
^~~~~~~~~~~~~~~~~~~~~~~
vptr for 'SvxBrushItem'
#0 0x7fce1fbed369 in ScDocument::GetDocColors() /sc/source/core/data/document10.cxx:198:46
Change-Id: I41f28b6bb54d7720d58c16d75b9d116a53f106cc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162077
Tested-by: Jenkins
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
This commit is contained in:
parent
5276aa03fa
commit
b804dc3c61
3 changed files with 54 additions and 28 deletions
43
include/svx/DocumentColorHelper.hxx
Normal file
43
include/svx/DocumentColorHelper.hxx
Normal file
|
@ -0,0 +1,43 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <editeng/brushitem.hxx>
|
||||
#include <editeng/colritem.hxx>
|
||||
#include <set>
|
||||
#include <svl/itempool.hxx>
|
||||
|
||||
namespace svx
|
||||
{
|
||||
namespace DocumentColorHelper
|
||||
{
|
||||
static inline Color getColorFromItem(const SvxColorItem* pItem) { return pItem->GetValue(); }
|
||||
|
||||
static inline Color getColorFromItem(const SvxBrushItem* pItem) { return pItem->GetColor(); }
|
||||
|
||||
template <class T>
|
||||
void queryColors(const sal_uInt16 nAttrib, const SfxItemPool* pPool, std::set<Color>& rOutput)
|
||||
{
|
||||
ItemSurrogates aSurrogates;
|
||||
pPool->GetItemSurrogates(aSurrogates, nAttrib);
|
||||
for (const SfxPoolItem* pItem : aSurrogates)
|
||||
{
|
||||
auto pColorItem = static_cast<const T*>(pItem);
|
||||
Color aColor(getColorFromItem(pColorItem));
|
||||
if (COL_AUTO != aColor)
|
||||
rOutput.insert(aColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // end of namespace svx
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include <refupdatecontext.hxx>
|
||||
#include <sal/log.hxx>
|
||||
#include <editeng/colritem.hxx>
|
||||
#include <svx/DocumentColorHelper.hxx>
|
||||
#include <scitems.hxx>
|
||||
#include <datamapper.hxx>
|
||||
#include <docsh.hxx>
|
||||
|
@ -188,19 +188,10 @@ std::set<Color> ScDocument::GetDocColors()
|
|||
{
|
||||
std::set<Color> aDocColors;
|
||||
ScDocumentPool *pPool = GetPool();
|
||||
const sal_uInt16 pAttribs[] = {ATTR_BACKGROUND, ATTR_FONT_COLOR};
|
||||
for (sal_uInt16 nAttrib : pAttribs)
|
||||
{
|
||||
ItemSurrogates aSurrogates;
|
||||
pPool->GetItemSurrogates(aSurrogates, nAttrib);
|
||||
for (const SfxPoolItem* pItem : aSurrogates)
|
||||
{
|
||||
const SvxColorItem *pColorItem = static_cast<const SvxColorItem*>(pItem);
|
||||
Color aColor( pColorItem->GetValue() );
|
||||
if (COL_AUTO != aColor)
|
||||
aDocColors.insert(aColor);
|
||||
}
|
||||
}
|
||||
|
||||
svx::DocumentColorHelper::queryColors<SvxBrushItem>(ATTR_BACKGROUND, pPool, aDocColors);
|
||||
svx::DocumentColorHelper::queryColors<SvxColorItem>(ATTR_FONT_COLOR, pPool, aDocColors);
|
||||
|
||||
return aDocColors;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,10 @@
|
|||
#include <editeng/lrspitem.hxx>
|
||||
#include <editeng/formatbreakitem.hxx>
|
||||
#include <editeng/rsiditem.hxx>
|
||||
#include <editeng/colritem.hxx>
|
||||
#include <officecfg/Office/Common.hxx>
|
||||
#include <osl/diagnose.h>
|
||||
#include <svl/zforlist.hxx>
|
||||
#include <svx/DocumentColorHelper.hxx>
|
||||
#include <comphelper/processfactory.hxx>
|
||||
#include <unotools/configmgr.hxx>
|
||||
#include <sal/log.hxx>
|
||||
|
@ -2038,19 +2038,11 @@ std::set<Color> SwDoc::GetDocColors()
|
|||
{
|
||||
std::set<Color> aDocColors;
|
||||
SwAttrPool& rPool = GetAttrPool();
|
||||
const sal_uInt16 pAttribs[] = {RES_CHRATR_COLOR, RES_CHRATR_HIGHLIGHT, RES_BACKGROUND};
|
||||
for (sal_uInt16 nAttrib : pAttribs)
|
||||
{
|
||||
ItemSurrogates aSurrogates;
|
||||
rPool.GetItemSurrogates(aSurrogates, nAttrib);
|
||||
for (const SfxPoolItem* pItem : aSurrogates)
|
||||
{
|
||||
auto pColorItem = static_cast<const SvxColorItem*>(pItem);
|
||||
Color aColor( pColorItem->GetValue() );
|
||||
if (COL_AUTO != aColor)
|
||||
aDocColors.insert(aColor);
|
||||
}
|
||||
}
|
||||
|
||||
svx::DocumentColorHelper::queryColors<SvxColorItem>(RES_CHRATR_COLOR, &rPool, aDocColors);
|
||||
svx::DocumentColorHelper::queryColors<SvxBrushItem>(RES_CHRATR_HIGHLIGHT, &rPool, aDocColors);
|
||||
svx::DocumentColorHelper::queryColors<SvxBrushItem>(RES_CHRATR_BACKGROUND, &rPool, aDocColors);
|
||||
|
||||
return aDocColors;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue