Files
odfstudio/include/sfx2/msg.hxx
T
László Németh 5da16bdc79 tdf#172674 offapi cui sw xmloff: add hyphenation slider feature
To solve the trade-off between better spacing and less hyphenation,
support hyphenation level and its user interface, the hyphenation
slider, like DTP software do.

Add new paragraph property com::sun::star::text::ParaHyphenationLevel

The hyphenation slider is the basic interface of DTP software to adjust
single (or all) paragraphs using better word spacing (i.e. more
hyphenation) or less hyphenation (i.e. worse word spacing). It allows 1)
to choose the best from the near equally good layouts and 2) to solve an
extreme bad layout (caused by words without hyphenation or other corner
cases).

– 50% hyphenation level means disabled hyphenation, if minimum
  and maximum word spacing settings allow to break the line within
  words (default interoperability value).

– 100% hyphenation level means using extra hyphenation only if that
  results better word spacing in the line, than breaking within words.

– Between 50% and 100% hyphenation level, use extra hyphenation only if
  its weighted word spacing is better, than breaking the line between
  words (weighting grows with the hyphenation level).

– Between 0% and 50% hyphenation level it means disabled hyphenation
  with increased desired and maximum word spacing, depending on the
  hyphenation level. At %0, the desired word spacing is enlarged to the
  original maximum word spacing, while maximum word spacing is enlarged
  by a single space.

For example, the original 4-page unit test document with the default 50%
hyphenation level contains 14 hyphenations. 100% hyphenation level
results in 22 hyphenations, while 0% only results in 8 hyphenations.

– sw/qa/extras/layout/data/tdf167648_minimum.fodt,
  sw/qa/extras/layout/data/tdf169168_minimum.fodt: set maximum
  word-spacing to 100% from 101% to limit the original unit test only
  for minimum letter spacing.

More information: LO/COOL Book & Typography projects:

https://www.numbertext.org/typography/

https://www.numbertext.org/book/

Follow-up to commit cf104be5cb "tdf#119908
tdf#166113 cool#15973 sw smart justify: fix DOCX hyphenation",
commit d572576dd6
"tdf#119908 cool#15973 sw smart justify: fix "smart" hyphenation",
commit 529755f091
"tdf#166113 sw smart justify: adjust algorithm for interoperability" and
commit 7d08767b89 "tdf#130088 tdf#119908
smart justify: fix DOCX line count + compat opt."

Change-Id: I84b3893ea6c5cd4eff74a73514722285e7071392
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207545
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: Jenkins
2026-07-04 17:11:37 +02:00

262 lines
8.1 KiB
C++

/* -*- 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#pragma once
#include <sfx2/shell.hxx>
#include <rtl/ustring.hxx>
#include <svl/poolitem.hxx>
#include <sfx2/dllapi.h>
#include <o3tl/typed_flags_set.hxx>
#include <sfx2/groupid.hxx>
#include <climits>
class SfxItemPool;
enum class SfxSlotMode {
NONE = 0x0000, // default
TOGGLE = 0x0004, // inverted for Execute old value
AUTOUPDATE = 0x0008, // invalidated the status automatically after execute
ASYNCHRON = 0x0020, // via Post-Message
NORECORD = 0x0100, // no recording
RECORDPERITEM = 0x0200, // each item, one statement
RECORDPERSET = 0x0400, // The whole Set is a Statement, default
RECORDABSOLUTE = 0x1000000, // Recording with absolute Target
METHOD = 0x4000,
FASTCALL = 0x8000, // No test if disabled before Execute
MENUCONFIG = 0x20000, // configurable Menu
TOOLBOXCONFIG = 0x40000, // configurable Toolboxen
ACCELCONFIG = 0x80000, // configurable keys
CONTAINER = 0x100000, // Operated by the container at InPlace
READONLYDOC = 0x200000, // also available for read-only Documents
VIEWERAPP = 0x400000, // also available in Viewer app mode
};
namespace o3tl
{
template<> struct typed_flags<SfxSlotMode> : is_typed_flags<SfxSlotMode, 0x17ec72cL> {};
}
#define SFX_EXEC_STUB( aShellClass, aExecMethod) \
void SfxStub##aShellClass##aExecMethod( \
SfxShell *pShell, SfxRequest& rReq) \
{ \
::tools::detail::castTo<aShellClass*>(pShell)->aExecMethod( rReq ); \
}
#define SFX_STATE_STUB( aShellClass, aStateMethod) \
void SfxStub##aShellClass##aStateMethod( \
SfxShell *pShell, SfxItemSet& rSet) \
{ \
static_cast<aShellClass*>(pShell)->aStateMethod( rSet ); \
}
#define SFX_STUB_PTR( aShellClass, aMethod ) \
&SfxStub##aShellClass##aMethod
#define SFX_STUB_PTR_EXEC_NONE &SfxShell::EmptyExecStub
#define SFX_STUB_PTR_STATE_NONE &SfxShell::EmptyStateStub
enum class SfxSlotKind
{
Standard,
Attribute
};
struct SfxTypeAttrib
{
sal_uInt16 nAID;
OUString aName;
};
template<class T> SfxPoolItem* createSfxPoolItem()
{
return T::CreateDefault();
}
struct SfxType
{
SfxPoolItem* (*createSfxPoolItemFunc)();
const std::type_info* pType;
sal_uInt16 nAttribs;
const std::type_info* Type() const{return pType;}
std::unique_ptr<SfxPoolItem> CreateItem() const
{ return std::unique_ptr<SfxPoolItem>(createSfxPoolItemFunc()); }
inline const SfxTypeAttrib& getAttrib(sal_uInt16 idx) const;
};
struct SfxTypeImpl : public SfxType
{
SfxTypeAttrib aAttrib[1]; // variable length
};
// Some casting to work around the lack of zero-sized trailing arrays in c++
inline const SfxTypeAttrib& SfxType::getAttrib(sal_uInt16 idx) const
{ return reinterpret_cast<const SfxTypeImpl*>(this)->aAttrib[idx]; }
struct SfxType0 : public SfxType
{
};
#define SFX_DECL_TYPE(n) struct SfxType##n : public SfxType \
{ \
SfxTypeAttrib aAttrib[n]; \
}
#define SFX_TYPE(Class) &a##Class##_Impl
SFX_DECL_TYPE(1);
SFX_DECL_TYPE(2);
SFX_DECL_TYPE(3);
SFX_DECL_TYPE(4);
SFX_DECL_TYPE(5);
SFX_DECL_TYPE(6);
SFX_DECL_TYPE(7);
SFX_DECL_TYPE(8);
SFX_DECL_TYPE(10); // for SfxDocInfoItem
SFX_DECL_TYPE(11);
SFX_DECL_TYPE(13); // for SwAddPrinterItem, Sd...
SFX_DECL_TYPE(14);
SFX_DECL_TYPE(16); // for SwDocDisplayItem
SFX_DECL_TYPE(17); // for SvxAddressItem
SFX_DECL_TYPE(18); // for SvxHyphenZoneItem
SFX_DECL_TYPE(23); // for SvxSearchItem
// all SfxTypes must be in this header
#undef SFX_DECL_TYPE
#define SFX_SLOT_ARG( aShellClass, id, GroupId, ExecMethodPtr, StateMethodPtr, Flags, ItemClass, nArg0, nArgs, Name, Prop ) \
{ id, GroupId, Flags | Prop, \
USHRT_MAX, 0, \
ExecMethodPtr, \
StateMethodPtr, \
(const SfxType*) &a##ItemClass##_Impl, \
0, \
&a##aShellClass##Args_Impl[nArg0], nArgs, SfxDisableFlags::NONE, Name \
}
#define SFX_NEW_SLOT_ARG( aShellClass, id, GroupId, pNext, ExecMethodPtr, StateMethodPtr, Flags, DisableFlags, ItemClass, nArg0, nArgs, Prop, UnoName ) \
{ id, GroupId, Flags | Prop, \
USHRT_MAX, 0, \
ExecMethodPtr, \
StateMethodPtr, \
(const SfxType*) &a##ItemClass##_Impl, \
pNext, \
&a##aShellClass##Args_Impl[nArg0], nArgs, DisableFlags, UnoName \
}
struct SfxFormalArgument
{
const SfxType* pType; // Type of the parameter (SfxPoolItem subclass)
OUString aName; // Name of the sParameters
sal_uInt16 nSlotId; // Slot-Id for identification of the Parameters
std::unique_ptr<SfxPoolItem> CreateItem() const
{ return pType->CreateItem(); }
};
class SfxSlot
{
public:
sal_uInt16 nSlotId; // Unique slot-ID in Shell
SfxGroupId nGroupId; // for configuration region
SfxSlotMode nFlags; // arithmetic ordered Flags
sal_uInt16 nMasterSlotId; // Enum-Slot for example Which-Id
sal_uInt16 nValue; // Value, in case of Enum-Slot
SfxExecFunc fnExec; // Function to be executed
SfxStateFunc fnState; // Function for Status
const SfxType* pType; // SfxPoolItem-Type (Status)
const SfxSlot* pNextSlot; // with the same Status-Method
const SfxFormalArgument* pFirstArgDef; // first formal Argument-Definition
sal_uInt16 nArgDefCount; // Number of formal Arguments
SfxDisableFlags nDisableFlags; // DisableFlags that need to be
// present, so that the Slot
// can be enabled
OUString aUnoName; // UnoName for the Slots
SfxSlotKind GetKind() const;
sal_uInt16 GetSlotId() const;
SfxSlotMode GetMode() const;
bool IsMode( SfxSlotMode nMode ) const;
SfxGroupId GetGroupId() const;
sal_uInt16 GetWhich( const SfxItemPool &rPool ) const;
const SfxType* GetType() const { return pType; }
const OUString& GetUnoName() const { return aUnoName; }
SFX2_DLLPUBLIC OUString GetCommand() const;
sal_uInt16 GetFormalArgumentCount() const { return nArgDefCount; }
const SfxFormalArgument& GetFormalArgument( sal_uInt16 nNo ) const
{ return pFirstArgDef[nNo]; }
SfxExecFunc GetExecFnc() const { return fnExec; }
SfxStateFunc GetStateFnc() const { return fnState; }
const SfxSlot* GetNextSlot() const { return pNextSlot; }
};
// returns the id of the function
inline sal_uInt16 SfxSlot::GetSlotId() const
{
return nSlotId;
}
// returns a bitfield with flags
inline SfxSlotMode SfxSlot::GetMode() const
{
return nFlags;
}
// determines if the specified mode is assigned
inline bool SfxSlot::IsMode( SfxSlotMode nMode ) const
{
return bool(nFlags & nMode);
}
// returns the id of the associated group
inline SfxGroupId SfxSlot::GetGroupId() const
{
return nGroupId;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */