editeng/source/items/svxfont.cxx |   64 ++++++++++++++++++++++++++++-----------
 include/editeng/svxfont.hxx      |    2 +
 2 files changed, 49 insertions(+), 17 deletions(-)

New commits:
commit 49b321f659fd51c1fd4ff0be54b09a6113cff273
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Tue Aug 22 10:54:03 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Aug 22 16:30:41 2023 +0200

    smallcaps: support dxarray in SvxDoDrawCapital
    
    Change-Id: I1924fce8323fb14f75f49cb67320f21a3ca62cc1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155943
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/editeng/source/items/svxfont.cxx b/editeng/source/items/svxfont.cxx
index 8e660cd4b44e..0d7e1f659b7b 100644
--- a/editeng/source/items/svxfont.cxx
+++ b/editeng/source/items/svxfont.cxx
@@ -562,8 +562,7 @@ void SvxFont::QuickDrawText( OutputDevice *pOut,
 
     if( IsCapital() )
     {
-        DBG_ASSERT( pDXArray.empty(), "DrawCapital not for TextArray!" );
-        DrawCapital( pOut, aPos, rTxt, nIdx, nLen );
+        DrawCapital( pOut, aPos, rTxt, pDXArray, pKashidaArray, nIdx, nLen );
     }
     else
     {
@@ -623,7 +622,7 @@ void SvxFont::DrawPrev( OutputDevice *pOut, Printer* 
pPrinter,
     Font aOldPrnFont( ChgPhysFont(*pPrinter) );
 
     if ( IsCapital() )
-        DrawCapital( pOut, aPos, rTxt, nIdx, nTmp );
+        DrawCapital( pOut, aPos, rTxt, {}, {}, nIdx, nTmp );
     else
     {
         Size aSize = GetPhysTxtSize( pPrinter, rTxt, nIdx, nTmp );
@@ -775,8 +774,12 @@ protected:
     Point aPos;
     Point aSpacePos;
     short nKern;
+    o3tl::span<const sal_Int32> pDXArray;
+    o3tl::span<const sal_Bool> pKashidaArray;
 public:
     SvxDoDrawCapital( SvxFont *pFnt, OutputDevice *_pOut, const OUString 
&_rTxt,
+                      o3tl::span<const sal_Int32> _pDXArray,
+                      o3tl::span<const sal_Bool> _pKashidaArray,
                       const sal_Int32 _nIdx, const sal_Int32 _nLen,
                       const Point &rPos, const short nKrn )
         : SvxDoCapitals( _rTxt, _nIdx, _nLen ),
@@ -784,7 +787,9 @@ public:
           pFont( pFnt ),
           aPos( rPos ),
           aSpacePos( rPos ),
-          nKern( nKrn )
+          nKern( nKrn ),
+          pDXArray(_pDXArray),
+          pKashidaArray(_pKashidaArray)
         { }
     virtual void DoSpace( const bool bDraw ) override;
     virtual void SetSpace() override;
@@ -820,8 +825,8 @@ void SvxDoDrawCapital::SetSpace()
         aSpacePos.setX( aPos.X() );
 }
 
-void SvxDoDrawCapital::Do( const OUString &_rTxt, const sal_Int32 _nIdx,
-                           const sal_Int32 _nLen, const bool bUpper)
+void SvxDoDrawCapital::Do( const OUString &_rTxt, const sal_Int32 nSpanIdx,
+                           const sal_Int32 nSpanLen, const bool bUpper)
 {
     sal_uInt8 nProp = 0;
 
@@ -839,13 +844,39 @@ void SvxDoDrawCapital::Do( const OUString &_rTxt, const 
sal_Int32 _nIdx,
     }
     pFont->SetPhysFont(*pOut);
 
-    tools::Long nWidth = pOut->GetTextWidth( _rTxt, _nIdx, _nLen );
-    if ( nKern )
+    if (pDXArray.empty())
     {
-        aPos.AdjustX(nKern/2);
-        if ( _nLen ) nWidth += (_nLen*tools::Long(nKern));
+        auto nWidth = pOut->GetTextWidth(_rTxt, nSpanIdx, nSpanLen);
+        if (nKern)
+        {
+            aPos.AdjustX(nKern/2);
+            if (nSpanLen)
+                nWidth += (nSpanLen * nKern);
+        }
+        pOut->DrawStretchText(aPos, nWidth-nKern, _rTxt, nSpanIdx, nSpanLen);
+        // in this case we move aPos along to be the start of each subspan
+        aPos.AdjustX(nWidth-(nKern/2) );
+    }
+    else
+    {
+        const sal_Int32 nStartOffset = nSpanIdx - nIdx;
+        sal_Int32 nStartX = nStartOffset ? pDXArray[nStartOffset - 1] : 0;
+
+        Point aStartPos(aPos.X() + nStartX, aPos.Y());
+
+        std::vector<sal_Int32> aDXArray;
+        aDXArray.reserve(nSpanLen);
+        for (sal_Int32 i = 0; i < nSpanLen; ++i)
+            aDXArray.push_back(pDXArray[nStartOffset + i] - nStartX);
+
+        auto aKashidaArray = !pKashidaArray.empty() ?
+            o3tl::span<const sal_Bool>(pKashidaArray.data() + nStartOffset, 
nSpanLen) :
+            o3tl::span<const sal_Bool>();
+
+        DrawTextArray(pOut, aStartPos, _rTxt, aDXArray, aKashidaArray, 
nSpanIdx, nSpanLen);
+        // in this case we leave aPos at the start and use the DXArray to find 
the start
+        // of each subspan
     }
-    pOut->DrawStretchText(aPos,nWidth-nKern,_rTxt,_nIdx,_nLen);
 
     // Restore Font
     pFont->SetUnderline( eUnder );
@@ -854,8 +885,6 @@ void SvxDoDrawCapital::Do( const OUString &_rTxt, const 
sal_Int32 _nIdx,
     if ( !bUpper )
         pFont->SetPropr( nProp );
     pFont->SetPhysFont(*pOut);
-
-    aPos.AdjustX(nWidth-(nKern/2) );
 }
 
 /*************************************************************************
@@ -864,9 +893,13 @@ void SvxDoDrawCapital::Do( const OUString &_rTxt, const 
sal_Int32 _nIdx,
 
 void SvxFont::DrawCapital( OutputDevice *pOut,
                const Point &rPos, const OUString &rTxt,
+               o3tl::span<const sal_Int32> pDXArray,
+               o3tl::span<const sal_Bool> pKashidaArray,
                const sal_Int32 nIdx, const sal_Int32 nLen ) const
 {
-    SvxDoDrawCapital aDo( const_cast<SvxFont 
*>(this),pOut,rTxt,nIdx,nLen,rPos,GetFixKerning() );
+    SvxDoDrawCapital aDo(const_cast<SvxFont *>(this), pOut,
+                         rTxt, pDXArray, pKashidaArray,
+                         nIdx, nLen, rPos, GetFixKerning());
     DoOnCapitals( aDo );
 }
 
diff --git a/include/editeng/svxfont.hxx b/include/editeng/svxfont.hxx
index 9fa7097d04e1..4e290d4cdea6 100644
--- a/include/editeng/svxfont.hxx
+++ b/include/editeng/svxfont.hxx
@@ -79,6 +79,8 @@ public:
     Size GetCapitalSize( const OutputDevice *pOut, const OUString &rTxt, 
KernArray* pDXAry,
                           const sal_Int32 nIdx, const sal_Int32 nLen) const;
     void DrawCapital( OutputDevice *pOut, const Point &rPos, const OUString 
&rTxt,
+                      o3tl::span<const sal_Int32> pDXArray,
+                      o3tl::span<const sal_Bool> pKashidaArray,
                       const sal_Int32 nIdx, const sal_Int32 nLen ) const;
 
     Size GetPhysTxtSize( const OutputDevice *pOut, const OUString &rTxt,
commit 36ab04a0e4fd6d8b8747a8e435a7143f4e3b10dd
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Tue Aug 22 10:01:13 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Aug 22 16:30:33 2023 +0200

    smallcaps: we only use width, so drop the height
    
    Change-Id: I860e5ff246cb21749a73deb83cdd2e26c0ad4b3d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155936
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/editeng/source/items/svxfont.cxx b/editeng/source/items/svxfont.cxx
index 08bae76685ed..8e660cd4b44e 100644
--- a/editeng/source/items/svxfont.cxx
+++ b/editeng/source/items/svxfont.cxx
@@ -824,7 +824,6 @@ void SvxDoDrawCapital::Do( const OUString &_rTxt, const 
sal_Int32 _nIdx,
                            const sal_Int32 _nLen, const bool bUpper)
 {
     sal_uInt8 nProp = 0;
-    Size aPartSize;
 
     // Set the desired font
     FontLineStyle eUnder = pFont->GetUnderline();
@@ -840,9 +839,7 @@ void SvxDoDrawCapital::Do( const OUString &_rTxt, const 
sal_Int32 _nIdx,
     }
     pFont->SetPhysFont(*pOut);
 
-    aPartSize.setWidth( pOut->GetTextWidth( _rTxt, _nIdx, _nLen ) );
-    aPartSize.setHeight( pOut->GetTextHeight() );
-    tools::Long nWidth = aPartSize.Width();
+    tools::Long nWidth = pOut->GetTextWidth( _rTxt, _nIdx, _nLen );
     if ( nKern )
     {
         aPos.AdjustX(nKern/2);

Reply via email to