summaryrefslogtreecommitdiff
path: root/drawinglayer
diff options
context:
space:
mode:
authorKhaled Hosny <khaled@aliftype.com>2022-08-08 22:08:37 +0200
committerCaolán McNamara <caolanm@redhat.com>2022-08-14 21:10:24 +0200
commit3901e029bd39575f700e69a73818565d62226a23 (patch)
tree2851945d9b13ac071d1e21af53288f46125dbc32 /drawinglayer
parentcc54063b915a58db9133c919c151ec7e6209f4cd (diff)
tdf#104921: Cleanup Kashida insertion logic
Communicate Kashida insertion positions in an explicit way. Rest of LibreOffice communicate adjustments to character widths (e.g. for justification or spacing) using so-called DX array. DX array is an array of absolute character positions (e.g. DX[n] is the position after character n from the start of the lines, and its widths is DX[n] - DX[n-1]). This DX array is modified also when Kashidas are inserted after a given character for Arabic justification, by expanding its width. VCL would use this to know where to insert the Kashidas and how many ones. But because DX array is used for both widths adjustments and kashida insertion, this turns out to be a source of bugs since VCL has tosecond guess the DX array to find which is pure width adjustment and which also involves Kashida insertion, and the heuristics it uses are fragile. This change adds a second array of booleans that records where Kashida is inserted and communicates it all the way from where Kashida insertion is decoded in Writer and down to VCL layout. This change passes the Kashida array only when it seems necessary (e.g. during drawing but not when measuring text since the DX array is enough in this case). Hopefully no places where Kashida insertion needs to be passed down were missed. A couple of glyph and layout flags that were used for old heuristics and no longer needed and are removed. This also fixes: tdf#87731 tdf#106309 tdf#108604 tdf#112849 tdf#114257 tdf#127176 tdf#145647 tdf#146199 Change-Id: I4ed0850ef2fdc3e9143341afac649e7e7d463c39 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138068 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'drawinglayer')
-rw-r--r--drawinglayer/source/primitive2d/textbreakuphelper.cxx10
-rw-r--r--drawinglayer/source/primitive2d/textdecoratedprimitive2d.cxx7
-rw-r--r--drawinglayer/source/primitive2d/textlayoutdevice.cxx6
-rw-r--r--drawinglayer/source/primitive2d/textprimitive2d.cxx13
-rw-r--r--drawinglayer/source/primitive2d/textstrikeoutprimitive2d.cxx1
-rw-r--r--drawinglayer/source/processor2d/vclprocessor2d.cxx3
-rw-r--r--drawinglayer/source/tools/emfphelperdata.cxx4
-rw-r--r--drawinglayer/source/tools/wmfemfhelper.cxx7
8 files changed, 40 insertions, 11 deletions
diff --git a/drawinglayer/source/primitive2d/textbreakuphelper.cxx b/drawinglayer/source/primitive2d/textbreakuphelper.cxx
index 5ca10ce633b6..8f92d9817a0e 100644
--- a/drawinglayer/source/primitive2d/textbreakuphelper.cxx
+++ b/drawinglayer/source/primitive2d/textbreakuphelper.cxx
@@ -58,6 +58,7 @@ namespace drawinglayer::primitive2d
// prepare values for new portion
basegfx::B2DHomMatrix aNewTransform;
std::vector< double > aNewDXArray;
+ std::vector< sal_Bool > aNewKashidaArray;
const bool bNewStartIsNotOldStart(nIndex > mrSource.getTextPosition());
if(!mbNoDXArray)
@@ -68,6 +69,13 @@ namespace drawinglayer::primitive2d
mrSource.getDXArray().begin() + ((nIndex + nLength) - mrSource.getTextPosition()));
}
+ if(!mbNoDXArray && !mrSource.getKashidaArray().empty())
+ {
+ aNewKashidaArray = std::vector< sal_Bool >(
+ mrSource.getKashidaArray().begin() + (nIndex - mrSource.getTextPosition()),
+ mrSource.getKashidaArray().begin() + ((nIndex + nLength) - mrSource.getTextPosition()));
+ }
+
if(bNewStartIsNotOldStart)
{
// needs to be moved to a new start position
@@ -137,6 +145,7 @@ namespace drawinglayer::primitive2d
nIndex,
nLength,
std::move(aNewDXArray),
+ std::move(aNewKashidaArray),
mrSource.getFontAttribute(),
mrSource.getLocale(),
mrSource.getFontColor(),
@@ -168,6 +177,7 @@ namespace drawinglayer::primitive2d
nIndex,
nLength,
std::move(aNewDXArray),
+ std::move(aNewKashidaArray),
mrSource.getFontAttribute(),
mrSource.getLocale(),
mrSource.getFontColor()));
diff --git a/drawinglayer/source/primitive2d/textdecoratedprimitive2d.cxx b/drawinglayer/source/primitive2d/textdecoratedprimitive2d.cxx
index 0db26fbeb28d..b14e6994f7c9 100644
--- a/drawinglayer/source/primitive2d/textdecoratedprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/textdecoratedprimitive2d.cxx
@@ -36,6 +36,7 @@ namespace drawinglayer::primitive2d
sal_Int32 nTextPosition,
sal_Int32 nTextLength,
const std::vector< double >& rDXArray,
+ const std::vector< sal_Bool >& rKashidaArray,
const attribute::FontAttribute& rFontAttribute) const
{
// create the SimpleTextPrimitive needed in any case
@@ -46,6 +47,7 @@ namespace drawinglayer::primitive2d
nTextPosition,
nTextLength,
std::vector(rDXArray),
+ std::vector(rKashidaArray),
rFontAttribute,
getLocale(),
getFontColor())));
@@ -189,7 +191,7 @@ namespace drawinglayer::primitive2d
getFontAttribute().getBiDiStrong());
// handle as one word
- impCreateGeometryContent(aRetval, aDecTrans, getText(), getTextPosition(), getTextLength(), getDXArray(), aNewFontAttribute);
+ impCreateGeometryContent(aRetval, aDecTrans, getText(), getTextPosition(), getTextLength(), getDXArray(), getKashidaArray(), aNewFontAttribute);
// Handle Shadow, Outline and TextRelief
if(!aRetval.empty())
@@ -294,6 +296,7 @@ namespace drawinglayer::primitive2d
sal_Int32 nTextPosition,
sal_Int32 nTextLength,
std::vector< double >&& rDXArray,
+ std::vector< sal_Bool >&& rKashidaArray,
const attribute::FontAttribute& rFontAttribute,
const css::lang::Locale& rLocale,
const basegfx::BColor& rFontColor,
@@ -312,7 +315,7 @@ namespace drawinglayer::primitive2d
bool bEmphasisMarkBelow,
TextRelief eTextRelief,
bool bShadow)
- : TextSimplePortionPrimitive2D(rNewTransform, rText, nTextPosition, nTextLength, std::move(rDXArray), rFontAttribute, rLocale, rFontColor, false, 0, rFillColor),
+ : TextSimplePortionPrimitive2D(rNewTransform, rText, nTextPosition, nTextLength, std::move(rDXArray), std::move(rKashidaArray), rFontAttribute, rLocale, rFontColor, false, 0, rFillColor),
maOverlineColor(rOverlineColor),
maTextlineColor(rTextlineColor),
meFontOverline(eFontOverline),
diff --git a/drawinglayer/source/primitive2d/textlayoutdevice.cxx b/drawinglayer/source/primitive2d/textlayoutdevice.cxx
index f70f9f63b81d..78e0c23189ad 100644
--- a/drawinglayer/source/primitive2d/textlayoutdevice.cxx
+++ b/drawinglayer/source/primitive2d/textlayoutdevice.cxx
@@ -215,8 +215,8 @@ double TextLayouterDevice::getTextWidth(const OUString& rText, sal_uInt32 nIndex
void TextLayouterDevice::getTextOutlines(basegfx::B2DPolyPolygonVector& rB2DPolyPolyVector,
const OUString& rText, sal_uInt32 nIndex,
- sal_uInt32 nLength,
- const std::vector<double>& rDXArray) const
+ sal_uInt32 nLength, const std::vector<double>& rDXArray,
+ const std::vector<sal_Bool>& rKashidaArray) const
{
const sal_uInt32 nDXArrayCount(rDXArray.size());
sal_uInt32 nTextLength(nLength);
@@ -239,7 +239,7 @@ void TextLayouterDevice::getTextOutlines(basegfx::B2DPolyPolygonVector& rB2DPoly
}
mrDevice.GetTextOutlines(rB2DPolyPolyVector, rText, nIndex, nIndex, nLength, 0,
- aIntegerDXArray);
+ aIntegerDXArray, rKashidaArray);
}
else
{
diff --git a/drawinglayer/source/primitive2d/textprimitive2d.cxx b/drawinglayer/source/primitive2d/textprimitive2d.cxx
index 6330c89b9184..f60f73b21045 100644
--- a/drawinglayer/source/primitive2d/textprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/textprimitive2d.cxx
@@ -132,13 +132,13 @@ void TextSimplePortionPrimitive2D::getTextOutlinesAndTransformation(
// get the text outlines
aTextLayouter.getTextOutlines(rTarget, getText(), getTextPosition(), getTextLength(),
- aScaledDXArray);
+ aScaledDXArray, getKashidaArray());
}
else
{
// get the text outlines
aTextLayouter.getTextOutlines(rTarget, getText(), getTextPosition(), getTextLength(),
- getDXArray());
+ getDXArray(), getKashidaArray());
}
// create primitives for the outlines
@@ -202,14 +202,16 @@ void TextSimplePortionPrimitive2D::create2DDecomposition(
TextSimplePortionPrimitive2D::TextSimplePortionPrimitive2D(
basegfx::B2DHomMatrix rNewTransform, OUString rText, sal_Int32 nTextPosition,
- sal_Int32 nTextLength, std::vector<double>&& rDXArray, attribute::FontAttribute aFontAttribute,
- css::lang::Locale aLocale, const basegfx::BColor& rFontColor, bool bFilled,
- tools::Long nWidthToFill, const Color& rTextFillColor)
+ sal_Int32 nTextLength, std::vector<double>&& rDXArray, std::vector<sal_Bool>&& rKashidaArray,
+ attribute::FontAttribute aFontAttribute, css::lang::Locale aLocale,
+ const basegfx::BColor& rFontColor, bool bFilled, tools::Long nWidthToFill,
+ const Color& rTextFillColor)
: maTextTransform(std::move(rNewTransform))
, maText(std::move(rText))
, mnTextPosition(nTextPosition)
, mnTextLength(nTextLength)
, maDXArray(std::move(rDXArray))
+ , maKashidaArray(std::move(rKashidaArray))
, maFontAttribute(std::move(aFontAttribute))
, maLocale(std::move(aLocale))
, maFontColor(rFontColor)
@@ -241,6 +243,7 @@ bool TextSimplePortionPrimitive2D::operator==(const BasePrimitive2D& rPrimitive)
&& getTextPosition() == rCompare.getTextPosition()
&& getTextLength() == rCompare.getTextLength()
&& getDXArray() == rCompare.getDXArray()
+ && getKashidaArray() == rCompare.getKashidaArray()
&& getFontAttribute() == rCompare.getFontAttribute()
&& LocalesAreEqual(getLocale(), rCompare.getLocale())
&& getFontColor() == rCompare.getFontColor() && mbFilled == rCompare.mbFilled
diff --git a/drawinglayer/source/primitive2d/textstrikeoutprimitive2d.cxx b/drawinglayer/source/primitive2d/textstrikeoutprimitive2d.cxx
index f7aedb3c9172..269be2d01817 100644
--- a/drawinglayer/source/primitive2d/textstrikeoutprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/textstrikeoutprimitive2d.cxx
@@ -97,6 +97,7 @@ namespace drawinglayer::primitive2d
0,
len,
std::move(aDXArray),
+ {},
getFontAttribute(),
getLocale(),
getFontColor()));
diff --git a/drawinglayer/source/processor2d/vclprocessor2d.cxx b/drawinglayer/source/processor2d/vclprocessor2d.cxx
index 019feba35182..822800882d55 100644
--- a/drawinglayer/source/processor2d/vclprocessor2d.cxx
+++ b/drawinglayer/source/processor2d/vclprocessor2d.cxx
@@ -321,7 +321,8 @@ void VclProcessor2D::RenderTextSimpleOrDecoratedPortionPrimitive2D(
if (!aTransformedDXArray.empty())
{
- mpOutputDevice->DrawTextArray(aStartPoint, aText, aTransformedDXArray, nPos, nLen);
+ mpOutputDevice->DrawTextArray(aStartPoint, aText, aTransformedDXArray,
+ rTextCandidate.getKashidaArray(), nPos, nLen);
}
else
{
diff --git a/drawinglayer/source/tools/emfphelperdata.cxx b/drawinglayer/source/tools/emfphelperdata.cxx
index 542259568cd0..e9b8422557a9 100644
--- a/drawinglayer/source/tools/emfphelperdata.cxx
+++ b/drawinglayer/source/tools/emfphelperdata.cxx
@@ -1683,6 +1683,7 @@ namespace emfplushelper
0, // text always starts at 0
stringLength,
std::move(emptyVector), // EMF-PLUS has no DX-array
+ {},
fontAttribute,
locale,
color.getBColor(), // Font Color
@@ -1702,6 +1703,7 @@ namespace emfplushelper
0, // text always starts at 0
stringLength,
std::move(emptyVector), // EMF-PLUS has no DX-array
+ {},
fontAttribute,
locale,
color.getBColor());
@@ -2195,6 +2197,7 @@ namespace emfplushelper
pos, // take character at current pos
aLength, // use determined length
std::move(aDXArray), // generated DXArray
+ {},
fontAttribute,
Application::GetSettings().GetLanguageTag().getLocale(),
color.getBColor(),
@@ -2214,6 +2217,7 @@ namespace emfplushelper
pos, // take character at current pos
aLength, // use determined length
std::move(aDXArray), // generated DXArray
+ {},
fontAttribute,
Application::GetSettings().GetLanguageTag().getLocale(),
color.getBColor());
diff --git a/drawinglayer/source/tools/wmfemfhelper.cxx b/drawinglayer/source/tools/wmfemfhelper.cxx
index f763cd887ff7..4ec6863eecea 100644
--- a/drawinglayer/source/tools/wmfemfhelper.cxx
+++ b/drawinglayer/source/tools/wmfemfhelper.cxx
@@ -1077,6 +1077,7 @@ namespace wmfemfhelper
sal_uInt16 nTextStart,
sal_uInt16 nTextLength,
std::vector< double >&& rDXArray,
+ std::vector< sal_Bool >&& rKashidaArray,
TargetHolder& rTarget,
PropertyHolder const & rProperty)
{
@@ -1161,6 +1162,7 @@ namespace wmfemfhelper
nTextStart,
nTextLength,
std::move(rDXArray),
+ std::move(rKashidaArray),
aFontAttribute,
aLocale,
aFontColor,
@@ -1189,6 +1191,7 @@ namespace wmfemfhelper
nTextStart,
nTextLength,
std::vector(rDXArray),
+ std::vector(rKashidaArray),
std::move(aFontAttribute),
std::move(aLocale),
aFontColor);
@@ -1770,6 +1773,7 @@ namespace wmfemfhelper
nTextIndex,
nTextLength,
std::move(aDXArray),
+ {},
rTargetHolders.Current(),
rPropertyHolders.Current());
}
@@ -1794,6 +1798,7 @@ namespace wmfemfhelper
// prepare DXArray (if used)
std::vector< double > aDXArray;
const std::vector<sal_Int32> & rDXArray = pA->GetDXArray();
+ std::vector< sal_Bool > aKashidaArray = pA->GetKashidaArray();
if(!rDXArray.empty())
{
@@ -1811,6 +1816,7 @@ namespace wmfemfhelper
nTextIndex,
nTextLength,
std::move(aDXArray),
+ std::move(aKashidaArray),
rTargetHolders.Current(),
rPropertyHolders.Current());
}
@@ -1874,6 +1880,7 @@ namespace wmfemfhelper
nTextIndex,
nTextLength,
std::move(aTextArray),
+ {},
rTargetHolders.Current(),
rPropertyHolders.Current());
}