tdf#171624: Add SvxFontVariationsItem and EditEngine plumbing

Change-Id: I2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/203244
Reviewed-by: Khaled Hosny <khaled@libreoffice.org>
Tested-by: Jenkins
This commit is contained in:
Khaled Hosny
2026-04-06 17:13:04 +02:00
committed by Khaled Hosny
parent 38f0fe5d16
commit f02741f3e6
12 changed files with 213 additions and 2 deletions
+11
View File
@@ -404,6 +404,17 @@ public:
};
class EditCharAttribFontVariations final : public EditCharAttrib
{
public:
EditCharAttribFontVariations(SfxItemPool&, const SfxPoolItem&, sal_Int32 nStart, sal_Int32 nEnd);
virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
};
class EditCharAttribGrabBag final : public EditCharAttrib
{
public:
+43
View File
@@ -34,7 +34,9 @@
#include <svl/voiditem.hxx>
#include <tools/stream.hxx>
#include <editeng/fontitem.hxx>
#include <editeng/fontvariationsitem.hxx>
#include <editeng/fhgtitem.hxx>
#include <vcl/font/Feature.hxx>
#include <vcl/salgtype.hxx>
#include <vcl/outdev.hxx>
#include <vcl/virdev.hxx>
@@ -136,6 +138,7 @@ public:
void testTdf151748StaleKashidaArray();
void testTdf162803StaleKashidaArray();
void testTdf157037PasteTextAutoDirection();
void testFontVariationsItem();
DECL_STATIC_LINK(Test, CalcFieldValueHdl, EditFieldInfo*, void);
@@ -171,6 +174,7 @@ public:
CPPUNIT_TEST(testTdf151748StaleKashidaArray);
CPPUNIT_TEST(testTdf162803StaleKashidaArray);
CPPUNIT_TEST(testTdf157037PasteTextAutoDirection);
CPPUNIT_TEST(testFontVariationsItem);
CPPUNIT_TEST_SUITE_END();
private:
@@ -2458,6 +2462,45 @@ void Test::testTdf157037PasteTextAutoDirection()
CPPUNIT_ASSERT(!aEditEngine.IsRightToLeft(4));
}
void Test::testFontVariationsItem()
{
// Test default construction (empty variations)
SvxFontVariationsItem aItem1(EE_CHAR_FONTVARIATIONS);
CPPUNIT_ASSERT(aItem1.GetVariations().empty());
// Test construction with variations
uint32_t nWght = vcl::font::featureCode("wght");
uint32_t nWdth = vcl::font::featureCode("wdth");
std::vector<vcl::FontVariation> aVars = { { nWght, 700.0f }, { nWdth, 75.0f } };
SvxFontVariationsItem aItem2(aVars, EE_CHAR_FONTVARIATIONS);
CPPUNIT_ASSERT_EQUAL(size_t(2), aItem2.GetVariations().size());
// Test equality
SvxFontVariationsItem aItem3(aVars, EE_CHAR_FONTVARIATIONS);
CPPUNIT_ASSERT(aItem2.operator==(aItem3));
CPPUNIT_ASSERT(!aItem1.operator==(aItem2));
// Test hash differs
CPPUNIT_ASSERT(aItem1.hashCode() != aItem2.hashCode());
// Test Clone
std::unique_ptr<SvxFontVariationsItem> pClone(aItem2.Clone());
CPPUNIT_ASSERT(pClone->operator==(aItem2));
CPPUNIT_ASSERT_EQUAL(size_t(2), pClone->GetVariations().size());
// Test QueryValue/PutValue round-trip (UNO string serialization)
css::uno::Any aAny;
CPPUNIT_ASSERT(aItem2.QueryValue(aAny));
OUString aStr;
CPPUNIT_ASSERT(aAny >>= aStr);
CPPUNIT_ASSERT_EQUAL(u"\"wght\" 700, \"wdth\" 75"_ustr, aStr);
SvxFontVariationsItem aItem4(EE_CHAR_FONTVARIATIONS);
CPPUNIT_ASSERT(aItem4.PutValue(aAny, 0));
CPPUNIT_ASSERT(aItem4.operator==(aItem2));
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
+12
View File
@@ -39,6 +39,7 @@
#include <editeng/emphasismarkitem.hxx>
#include <editeng/charreliefitem.hxx>
#include <editeng/cmapitem.hxx>
#include <editeng/fontvariationsitem.hxx>
#include <editeng/opticalsizingitem.hxx>
#include <editattr.hxx>
@@ -479,6 +480,17 @@ void EditCharAttribOpticalSizing::SetFont( SvxFont& rFont, OutputDevice* )
}
EditCharAttribFontVariations::EditCharAttribFontVariations(SfxItemPool& rPool, const SfxPoolItem& rItem, sal_Int32 _nStart, sal_Int32 _nEnd)
: EditCharAttrib(rPool, rItem, _nStart, _nEnd)
{
assert(rItem.Which() == EE_CHAR_FONTVARIATIONS);
}
void EditCharAttribFontVariations::SetFont( SvxFont& rFont, OutputDevice* )
{
rFont.SetVariations( static_cast<const SvxFontVariationsItem*>(GetItem())->GetVariations() );
}
EditCharAttribGrabBag::EditCharAttribGrabBag(SfxItemPool& rPool, const SfxPoolItem& rItem, sal_Int32 _nStart, sal_Int32 _nEnd)
: EditCharAttrib(rPool, rItem, _nStart, _nEnd)
{
+32
View File
@@ -45,6 +45,7 @@
#include <editeng/lrspitem.hxx>
#include <editeng/ulspitem.hxx>
#include <editeng/lspcitem.hxx>
#include <editeng/fontvariationsitem.hxx>
#include <editeng/opticalsizingitem.hxx>
#if ENABLE_YRS
#include <editeng/frmdiritem.hxx>
@@ -327,6 +328,11 @@ EditCharAttrib* MakeCharAttrib( SfxItemPool& rPool, const SfxPoolItem& rAttr, sa
return new EditCharAttribOpticalSizing(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_FONTVARIATIONS:
{
return new EditCharAttribFontVariations(rPool, rAttr, nS, nE );
}
break;
default:
break;
}
@@ -1237,6 +1243,14 @@ void YrsInsertAttribImplImpl(YrsWrite const& yw, SfxPoolItem const& rItm,
attrName = "EE_CHAR_OPTICALSIZING";
break;
}
case EE_CHAR_FONTVARIATIONS:
{
SvxFontVariationsItem const& rItem{static_cast<SvxFontVariationsItem const&>(rItm)};
OUString aStr = vcl::FontVariationsToString(rItem.GetVariations());
attr = yinput_str(OUStringToOString(aStr, RTL_TEXTENCODING_UTF8));
attrName = "EE_CHAR_FONTVARIATIONS";
break;
}
default:
assert(false);
}
@@ -1595,6 +1609,8 @@ char const* YrsWhichToAttrName(sal_Int16 const nWhich)
return "EE_PARA_VER_JUST";
case EE_CHAR_OPTICALSIZING:
return "EE_CHAR_OPTICALSIZING";
case EE_CHAR_FONTVARIATIONS:
return "EE_CHAR_FONTVARIATIONS";
default:
assert(false);
abort();
@@ -1841,6 +1857,10 @@ void YrsImplInsertAttr(SfxItemSet & rSet, ::std::vector<sal_uInt16> *const pRemo
{
nWhich = EE_CHAR_OPTICALSIZING;
}
else if (strcmp(pKey, "EE_CHAR_FONTVARIATIONS") == 0)
{
nWhich = EE_CHAR_FONTVARIATIONS;
}
else if (pKey[0] == 'E' && pKey[1] == 'E' && pKey[2] == '_')
{
abort();
@@ -2479,6 +2499,16 @@ void YrsImplInsertAttr(SfxItemSet & rSet, ::std::vector<sal_uInt16> *const pRemo
rSet.Put(item);
break;
}
case EE_CHAR_FONTVARIATIONS:
{
yvalidate(rValue.tag == Y_JSON_STRING);
OUString aStr = OStringToOUString(
std::string_view(rValue.value.str.buf, rValue.value.str.len),
RTL_TEXTENCODING_UTF8);
SvxFontVariationsItem const item(vcl::FontVariationsFromString(aStr), nWhich);
rSet.Put(item);
break;
}
default:
assert(false);
@@ -3307,6 +3337,8 @@ void CreateFont( SvxFont& rFont, const SfxItemSet& rSet, bool bSearchInParent, S
rFont.SetRelief( rSet.Get( EE_CHAR_RELIEF ).GetValue() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_OPTICALSIZING ) == SfxItemState::SET ) )
rFont.SetOpticalSizing( rSet.Get( EE_CHAR_OPTICALSIZING ).GetValue() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_FONTVARIATIONS ) == SfxItemState::SET ) )
rFont.SetVariations( rSet.Get( EE_CHAR_FONTVARIATIONS ).GetVariations() );
// Operator == compares the individual members of the font if the impl pointer is
// not equal. If all members are the same, this assignment makes
+2
View File
@@ -67,6 +67,7 @@
#include <editeng/xmlcnitm.hxx>
#include <editeng/forbiddencharacterstable.hxx>
#include <editeng/justifyitem.hxx>
#include <editeng/fontvariationsitem.hxx>
#include <editeng/opticalsizingitem.hxx>
#include <tools/mapunit.hxx>
#include <tools/lazydelete.hxx>
@@ -162,6 +163,7 @@ ItemInfoPackage& getItemInfoPackageEditEngine()
{ EE_CHAR_RUBY, new SvxRubyItem( EE_CHAR_RUBY ), SID_ATTR_CHAR_RUBY, SFX_ITEMINFOFLAG_NONE },
{ EE_CHAR_SCRIPT_HINT, new SvxScriptHintItem( EE_CHAR_SCRIPT_HINT ), SID_ATTR_CHAR_SCRIPT_HINT, SFX_ITEMINFOFLAG_NONE },
{ EE_CHAR_OPTICALSIZING, new SvxOpticalSizingItem( false, EE_CHAR_OPTICALSIZING ), SID_ATTR_CHAR_OPTICAL_SIZING, SFX_ITEMINFOFLAG_NONE },
{ EE_CHAR_FONTVARIATIONS, new SvxFontVariationsItem( EE_CHAR_FONTVARIATIONS ), SID_ATTR_CHAR_FONT_VARIATIONS, SFX_ITEMINFOFLAG_NONE },
{ EE_FEATURE_TAB, new SfxVoidItem( EE_FEATURE_TAB ), 0, SFX_ITEMINFOFLAG_NONE },
{ EE_FEATURE_LINEBR, new SfxVoidItem( EE_FEATURE_LINEBR ), 0, SFX_ITEMINFOFLAG_NONE },
{ EE_FEATURE_NOTCONV, new SvxColorItem( COL_RED, EE_FEATURE_NOTCONV ), SID_ATTR_CHAR_CHARSETCOLOR, SFX_ITEMINFOFLAG_NONE },
+63
View File
@@ -82,6 +82,7 @@
#include <editeng/itemtype.hxx>
#include <editeng/scripthintitem.hxx>
#include <editeng/eerdll.hxx>
#include <editeng/fontvariationsitem.hxx>
#include <editeng/opticalsizingitem.hxx>
#include <docmodel/color/ComplexColorJSON.hxx>
#include <docmodel/uno/UnoComplexColor.hxx>
@@ -112,6 +113,7 @@ SfxPoolItem* SvxCharRotateItem::CreateDefault() {return new SvxCharRotateItem(0_
SfxPoolItem* SvxCharScaleWidthItem::CreateDefault() {return new SvxCharScaleWidthItem(100, TypedWhichId<SvxCharScaleWidthItem>(0));}
SfxPoolItem* SvxCharReliefItem::CreateDefault() {return new SvxCharReliefItem(FontRelief::NONE, 0);}
SfxPoolItem* SvxOpticalSizingItem::CreateDefault() {return new SvxOpticalSizingItem(false, 0);}
SfxPoolItem* SvxFontVariationsItem::CreateDefault() {return new SvxFontVariationsItem(0);}
// class SvxFontListItem -------------------------------------------------
@@ -3025,6 +3027,67 @@ void SvxRsidItem::dumpAsXml(xmlTextWriterPtr pWriter) const
(void)xmlTextWriterEndElement(pWriter);
}
// class SvxFontVariationsItem -------------------------------------------
SvxFontVariationsItem::SvxFontVariationsItem(sal_uInt16 nId)
: SfxPoolItem(nId)
{
}
SvxFontVariationsItem::SvxFontVariationsItem(std::vector<vcl::FontVariation> aVariations,
sal_uInt16 nId)
: SfxPoolItem(nId)
, maVariations(std::move(aVariations))
{
}
bool SvxFontVariationsItem::operator==(const SfxPoolItem& rItem) const
{
assert(SfxPoolItem::operator==(rItem));
return maVariations == static_cast<const SvxFontVariationsItem&>(rItem).maVariations;
}
size_t SvxFontVariationsItem::hashCode() const
{
size_t hash = 0;
for (const auto& rVar : maVariations)
{
o3tl::hash_combine(hash, rVar.nTag);
o3tl::hash_combine(hash, rVar.fValue);
}
return hash;
}
SvxFontVariationsItem* SvxFontVariationsItem::Clone(SfxItemPool*) const
{
return new SvxFontVariationsItem(*this);
}
bool SvxFontVariationsItem::GetPresentation(SfxItemPresentation /*ePres*/, MapUnit /*eCoreUnit*/,
MapUnit /*ePresUnit*/, OUString& rText,
const IntlWrapper& /*rIntl*/) const
{
rText = vcl::FontVariationsToString(maVariations);
return true;
}
bool SvxFontVariationsItem::QueryValue(css::uno::Any& rVal, sal_uInt8 /*nMemberId*/) const
{
rVal <<= vcl::FontVariationsToString(maVariations);
return true;
}
bool SvxFontVariationsItem::PutValue(const css::uno::Any& rVal, sal_uInt8 /*nMemberId*/)
{
OUString aStr;
if (rVal >>= aStr)
{
maVariations = vcl::FontVariationsFromString(aStr);
return true;
}
return false;
}
// class SvxOpticalSizingItem --------------------------------------------
SvxOpticalSizingItem::SvxOpticalSizingItem( const bool bOpticalSizing, const sal_uInt16 nId ) :
+1
View File
@@ -190,6 +190,7 @@ class SvxOpticalSizingItem;
#define SID_ATTR_PARA_ADJUST_START ( SID_EDIT_START + 79 )
#define SID_ATTR_PARA_ADJUST_END ( SID_EDIT_START + 80 )
#define SID_ATTR_CHAR_OPTICAL_SIZING TypedWhichId<SvxOpticalSizingItem>( SID_EDIT_START + 81 )
#define SID_ATTR_CHAR_FONT_VARIATIONS TypedWhichId<SvxFontVariationsItem>( SID_EDIT_START + 82 )
#if 95 > (SID_EDIT_END-SID_EDIT_START)
+3 -1
View File
@@ -63,6 +63,7 @@ class SvxJustifyMethodItem;
class SvxVerJustifyItem;
class SvxRubyItem;
class SvxScriptHintItem;
class SvxFontVariationsItem;
class SvxOpticalSizingItem;
/*
@@ -135,8 +136,9 @@ inline constexpr TypedWhichId<SvxColorItem> EE_CHAR_BKGCOLOR (EE
inline constexpr TypedWhichId<SvxRubyItem> EE_CHAR_RUBY (EE_CHAR_START+32);
inline constexpr TypedWhichId<SvxScriptHintItem> EE_CHAR_SCRIPT_HINT (EE_CHAR_START+33);
inline constexpr TypedWhichId<SvxOpticalSizingItem> EE_CHAR_OPTICALSIZING (EE_CHAR_START+34);
inline constexpr TypedWhichId<SvxFontVariationsItem> EE_CHAR_FONTVARIATIONS (EE_CHAR_START+35);
inline constexpr sal_uInt16 EE_CHAR_END (EE_CHAR_START + 34);
inline constexpr sal_uInt16 EE_CHAR_END (EE_CHAR_START + 35);
inline constexpr sal_uInt16 EE_FEATURE_START (EE_CHAR_END + 1);
inline constexpr sal_uInt16 EE_FEATURE_TAB (EE_FEATURE_START + 0);
+42
View File
@@ -0,0 +1,42 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 <svl/poolitem.hxx>
#include <editeng/editengdllapi.h>
#include <vcl/FontVariation.hxx>
class EDITENG_DLLPUBLIC SvxFontVariationsItem final : public SfxPoolItem
{
std::vector<vcl::FontVariation> maVariations;
public:
static SfxPoolItem* CreateDefault();
DECLARE_ITEM_TYPE_FUNCTION(SvxFontVariationsItem)
SvxFontVariationsItem(sal_uInt16 nId);
SvxFontVariationsItem(std::vector<vcl::FontVariation> aVariations, sal_uInt16 nId);
const std::vector<vcl::FontVariation>& GetVariations() const { return maVariations; }
virtual bool operator==(const SfxPoolItem& rItem) const override;
virtual bool supportsHashCode() const override { return true; }
virtual size_t hashCode() const override;
virtual SvxFontVariationsItem* Clone(SfxItemPool* pPool = nullptr) const override;
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric,
MapUnit ePresMetric, OUString& rText,
const IntlWrapper&) const override;
virtual bool QueryValue(css::uno::Any& rVal, sal_uInt8 nMemberId = 0) const override;
virtual bool PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) override;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
+1
View File
@@ -319,6 +319,7 @@ inline constexpr OUString UNO_NAME_EDIT_CHAR_FONTCHARSET = u"CharFontCharSet"_us
inline constexpr OUString UNO_NAME_EDIT_CHAR_FONTPITCH = u"CharFontPitch"_ustr;
inline constexpr OUString UNO_NAME_EDIT_CHAR_POSTURE = u"CharPosture"_ustr;
inline constexpr OUString UNO_NAME_EDIT_CHAR_WEIGHT = u"CharWeight"_ustr;
inline constexpr OUString UNO_NAME_EDIT_CHAR_FONTVARIATIONS = u"CharFontVariations"_ustr;
inline constexpr OUString UNO_NAME_EDIT_CHAR_OPTICALSIZING = u"CharOpticalSizing"_ustr;
inline constexpr OUString UNO_NAME_EDIT_CHAR_LOCALE = u"CharLocale"_ustr;
+2 -1
View File
@@ -138,7 +138,8 @@ struct SfxItemPropertyMapEntry;
{ UNO_NAME_EDIT_CHAR_RUBY_ADJUST, EE_CHAR_RUBY, ::cppu::UnoType<sal_Int16>::get(), 0, MID_RUBY_ADJUST }, \
{ UNO_NAME_EDIT_CHAR_RUBY_POSITION, EE_CHAR_RUBY, ::cppu::UnoType<sal_Int16>::get(), 0, MID_RUBY_POSITION }, \
{ UNO_NAME_EDIT_CHAR_SCRIPT_HINT, EE_CHAR_SCRIPT_HINT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_SCRIPTHINT }, \
{ UNO_NAME_EDIT_CHAR_OPTICALSIZING, EE_CHAR_OPTICALSIZING, ::cppu::UnoType<bool>::get(), 0, 0 }
{ UNO_NAME_EDIT_CHAR_OPTICALSIZING, EE_CHAR_OPTICALSIZING, ::cppu::UnoType<bool>::get(), 0, 0 }, \
{ UNO_NAME_EDIT_CHAR_FONTVARIATIONS, EE_CHAR_FONTVARIATIONS, ::cppu::UnoType<OUString>::get(), 0, 0 }
#define SVX_UNOEDIT_FONT_PROPERTIES \
+1
View File
@@ -345,6 +345,7 @@ enum class SfxItemType : sal_uInt16
SvxFontHeightItemType,
SvxFontItemType,
SvxFontListItemType,
SvxFontVariationsItemType,
SvxForbiddenRuleItemType,
SvxFormatBreakItemType,
SvxFormatKeepItemType,