diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2023-08-18 17:29:24 +0100 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2023-08-22 15:29:03 +0200 |
commit | ffaed5cae29d6bb14faf870cb935ccd3c35d4a3c (patch) | |
tree | 7c2422e63e31c0e5ddfe8afeb1361567dcf1a859 /editeng | |
parent | 97469c2cac442fc3231694e35a8cd7a0f8d16af4 (diff) |
tdf#98367 implement rendering of draw/impress small capitals
arising out of Þe old tdf#91932
Change-Id: I953aabc280bc31ef1297dc79d483eb3d28a542f3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155846
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/items/svxfont.cxx | 105 |
1 files changed, 54 insertions, 51 deletions
diff --git a/editeng/source/items/svxfont.cxx b/editeng/source/items/svxfont.cxx index 544d80c7d4a9..08bae76685ed 100644 --- a/editeng/source/items/svxfont.cxx +++ b/editeng/source/items/svxfont.cxx @@ -29,6 +29,7 @@ #include <unotools/charclass.hxx> #include <com/sun/star/i18n/KCharacterType.hpp> #include <editeng/escapementitem.hxx> +#include <editeng/smallcaps.hxx> #include <sal/log.hxx> #include <limits> @@ -220,40 +221,6 @@ OUString SvxFont::CalcCaseMap(const OUString &rTxt) const return aTxt; } -/************************************************************************* - * class SvxDoCapitals - * The virtual Method Do si called by SvxFont::DoOnCapitals alternately - * the uppercase and lowercase parts. The derivate of SvxDoCapitals fills - * this method with life. - *************************************************************************/ - -class SvxDoCapitals -{ -protected: - VclPtr<OutputDevice> pOut; - const OUString &rTxt; - const sal_Int32 nIdx; - const sal_Int32 nLen; - -public: - SvxDoCapitals( OutputDevice *_pOut, const OUString &_rTxt, - const sal_Int32 _nIdx, const sal_Int32 _nLen ) - : pOut(_pOut), rTxt(_rTxt), nIdx(_nIdx), nLen(_nLen) - { } - - virtual ~SvxDoCapitals() {} - - virtual void DoSpace( const bool bDraw ); - virtual void SetSpace(); - virtual void Do( const OUString &rTxt, - const sal_Int32 nIdx, const sal_Int32 nLen, - const bool bUpper ) = 0; - - const OUString &GetTxt() const { return rTxt; } - sal_Int32 GetIdx() const { return nIdx; } - sal_Int32 GetLen() const { return nLen; } -}; - void SvxDoCapitals::DoSpace( const bool /*bDraw*/ ) { } void SvxDoCapitals::SetSpace() { } @@ -501,8 +468,13 @@ Size SvxFont::QuickGetTextSize( const OutputDevice *pOut, const OUString &rTxt, if ( !IsCaseMap() ) aTxtSize.setWidth( GetTextArray( pOut, rTxt, pDXArray, nIdx, nLen ) ); else - aTxtSize.setWidth( GetTextArray( pOut, CalcCaseMap( rTxt ), - pDXArray, nIdx, nLen ) ); + { + if (IsCapital() && !rTxt.isEmpty()) + aTxtSize = GetCapitalSize(pOut, rTxt, pDXArray, nIdx, nLen); + else + aTxtSize.setWidth( GetTextArray( pOut, CalcCaseMap( rTxt ), + pDXArray, nIdx, nLen ) ); + } SAL_INFO( "editeng.quicktextsize", "SvxFont::QuickGetTextSize after GetTextArray(): Text length: " << nLen << " Text size: " << aTxtSize.Width() << "x" << aTxtSize.Height()); if( IsFixKerning() && ( nLen > 1 ) ) @@ -544,7 +516,7 @@ Size SvxFont::GetTextSize(const OutputDevice& rOut, const OUString &rTxt, Size aTxtSize; if( IsCapital() && !rTxt.isEmpty() ) { - aTxtSize = GetCapitalSize(&rOut, rTxt, nIdx, nTmp); + aTxtSize = GetCapitalSize(&rOut, rTxt, nullptr, nIdx, nTmp); } else aTxtSize = GetPhysTxtSize(&rOut,rTxt,nIdx,nTmp); const_cast<OutputDevice&>(rOut).SetFont(aOldFont); @@ -703,17 +675,27 @@ namespace { class SvxDoGetCapitalSize : public SvxDoCapitals { protected: + VclPtr<OutputDevice> pOut; SvxFont* pFont; Size aTxtSize; short nKern; + KernArray* pDXAry; public: SvxDoGetCapitalSize( SvxFont *_pFnt, const OutputDevice *_pOut, - const OUString &_rTxt, const sal_Int32 _nIdx, + const OUString &_rTxt, KernArray* _pDXAry, const sal_Int32 _nIdx, const sal_Int32 _nLen, const short _nKrn ) - : SvxDoCapitals( const_cast<OutputDevice*>(_pOut), _rTxt, _nIdx, _nLen ), + : SvxDoCapitals( _rTxt, _nIdx, _nLen ), + pOut( const_cast<OutputDevice*>(_pOut) ), pFont( _pFnt ), - nKern( _nKrn ) - { } + nKern( _nKrn ), + pDXAry( _pDXAry ) + { + if (pDXAry) + { + pDXAry->clear(); + pDXAry->reserve(_nLen); + } + } virtual void Do( const OUString &rTxt, const sal_Int32 nIdx, const sal_Int32 nLen, const bool bUpper ) override; @@ -727,31 +709,50 @@ void SvxDoGetCapitalSize::Do( const OUString &_rTxt, const sal_Int32 _nIdx, const sal_Int32 _nLen, const bool bUpper ) { Size aPartSize; + sal_uInt8 nProp(0); if ( !bUpper ) { - sal_uInt8 nProp = pFont->GetPropr(); + nProp = pFont->GetPropr(); pFont->SetProprRel( SMALL_CAPS_PERCENTAGE ); pFont->SetPhysFont( *pOut ); - aPartSize.setWidth( pOut->GetTextWidth( _rTxt, _nIdx, _nLen ) ); - aPartSize.setHeight( pOut->GetTextHeight() ); - aTxtSize.setHeight( aPartSize.Height() ); - pFont->SetPropr( nProp ); - pFont->SetPhysFont( *pOut ); + } + + if (pDXAry) + { + KernArray aKernArray; + aPartSize.setWidth(pOut->GetTextArray(_rTxt, &aKernArray, _nIdx, _nLen)); + assert(pDXAry->get_factor() == aKernArray.get_factor()); + auto& dest = pDXAry->get_subunit_array(); + sal_Int32 nStart = dest.empty() ? 0 : dest.back(); + size_t nSrcLen = aKernArray.size(); + dest.reserve(dest.size() + nSrcLen); + const auto& src = aKernArray.get_subunit_array(); + for (size_t i = 0; i < nSrcLen; ++i) + dest.push_back(src[i] + nStart); } else { aPartSize.setWidth( pOut->GetTextWidth( _rTxt, _nIdx, _nLen ) ); - aPartSize.setHeight( pOut->GetTextHeight() ); } + + aPartSize.setHeight( pOut->GetTextHeight() ); + + if ( !bUpper ) + { + aTxtSize.setHeight( aPartSize.Height() ); + pFont->SetPropr( nProp ); + pFont->SetPhysFont( *pOut ); + } + aTxtSize.AdjustWidth(aPartSize.Width() ); aTxtSize.AdjustWidth( _nLen * tools::Long( nKern ) ); } -Size SvxFont::GetCapitalSize( const OutputDevice *pOut, const OUString &rTxt, +Size SvxFont::GetCapitalSize( const OutputDevice *pOut, const OUString &rTxt, KernArray* pDXAry, const sal_Int32 nIdx, const sal_Int32 nLen) const { // Start: - SvxDoGetCapitalSize aDo( const_cast<SvxFont *>(this), pOut, rTxt, nIdx, nLen, GetFixKerning() ); + SvxDoGetCapitalSize aDo( const_cast<SvxFont *>(this), pOut, rTxt, pDXAry, nIdx, nLen, GetFixKerning() ); DoOnCapitals( aDo ); Size aTxtSize( aDo.GetSize() ); @@ -769,6 +770,7 @@ namespace { class SvxDoDrawCapital : public SvxDoCapitals { protected: + VclPtr<OutputDevice> pOut; SvxFont *pFont; Point aPos; Point aSpacePos; @@ -777,7 +779,8 @@ public: SvxDoDrawCapital( SvxFont *pFnt, OutputDevice *_pOut, const OUString &_rTxt, const sal_Int32 _nIdx, const sal_Int32 _nLen, const Point &rPos, const short nKrn ) - : SvxDoCapitals( _pOut, _rTxt, _nIdx, _nLen ), + : SvxDoCapitals( _rTxt, _nIdx, _nLen ), + pOut( _pOut ), pFont( pFnt ), aPos( rPos ), aSpacePos( rPos ), |