Kaydet (Commit) 736adbb4 authored tarafından Khaled Hosny's avatar Khaled Hosny

Fix left to right full justification

I was overloading ApplyDXArray() with a HarfBuzz specific implementation
because the GenericSalLayout one was screwing right to left kerning, but
it seems to have broken left to right full justifications. Since
mnXOffset was introduced a bit earlier to fix a similar issue, it can
now be used here as well to minimize the possible side effects.

Seems to work fine for both left to right and right to left text now,
but at least one of my Arabic tests is regressing, so might need some
tweaking.

Change-Id: I1239b0ec77a4978f981a480400a6d01cda18af79
üst 62b74b6c
......@@ -90,102 +90,6 @@ void ServerFontLayout::AdjustLayout( ImplLayoutArgs& rArgs )
}
}
// apply adjustments to glyph advances, e.g. as a result of justification.
void ServerFontLayout::ApplyDXArray(ImplLayoutArgs& rArgs)
{
if (bUseHarfBuzz)
{
if (m_GlyphItems.empty())
return;
// determine cluster boundaries and x base offset
const int nCharCount = rArgs.mnEndCharPos - rArgs.mnMinCharPos;
int* pLogCluster = (int*)alloca(nCharCount * sizeof(int));
size_t i;
int n,p;
long nBasePointX = -1;
if (mnLayoutFlags & SAL_LAYOUT_FOR_FALLBACK)
nBasePointX = 0;
for (p = 0; p < nCharCount; ++p)
pLogCluster[p] = -1;
for (i = 0; i < m_GlyphItems.size(); ++i)
{
n = m_GlyphItems[i].mnCharPos - rArgs.mnMinCharPos;
if ((n < 0) || (nCharCount <= n))
continue;
if (pLogCluster[n] < 0)
pLogCluster[n] = i;
if (nBasePointX < 0)
nBasePointX = m_GlyphItems[i].maLinearPos.X();
}
// retarget unresolved pLogCluster[n] to a glyph inside the cluster
// TODO: better do it while the deleted-glyph markers are still there
for (n = 0; n < nCharCount; ++n)
if ((p = pLogCluster[0]) >= 0)
break;
if (n >= nCharCount)
return;
for (n = 0; n < nCharCount; ++n)
{
if (pLogCluster[n] < 0)
pLogCluster[n] = p;
else
p = pLogCluster[n];
}
// calculate adjusted cluster widths
sal_Int32* pNewGlyphWidths = (sal_Int32*)alloca(m_GlyphItems.size() * sizeof(sal_Int32));
for (i = 0; i < m_GlyphItems.size(); ++i)
pNewGlyphWidths[i] = 0;
bool bRTL;
for (int nCharPos = p = -1; rArgs.GetNextPos(&nCharPos, &bRTL); )
{
n = nCharPos - rArgs.mnMinCharPos;
if ((n < 0) || (nCharCount <= n)) continue;
if (pLogCluster[n] >= 0)
p = pLogCluster[n];
if (p >= 0)
{
long nDelta = rArgs.mpDXArray[n];
if(n > 0)
nDelta -= rArgs.mpDXArray[n - 1];
pNewGlyphWidths[p] += nDelta * mnUnitsPerPixel;
}
}
// move cluster positions using the adjusted widths
long nDelta = 0;
for (i = 0; i < m_GlyphItems.size(); ++i)
{
if (m_GlyphItems[i].IsClusterStart())
{
// calculate original and adjusted cluster width
int nOldClusterWidth = m_GlyphItems[i].mnNewWidth;
int nNewClusterWidth = pNewGlyphWidths[i];
size_t j;
for (j = i; ++j < m_GlyphItems.size(); )
{
if (m_GlyphItems[j].IsClusterStart())
break;
if (!m_GlyphItems[j].IsDiacritic()) // #i99367# ignore diacritics
nOldClusterWidth += m_GlyphItems[j].mnNewWidth;
nNewClusterWidth += pNewGlyphWidths[j];
}
nDelta += nNewClusterWidth - nOldClusterWidth;
}
m_GlyphItems[i].mnNewWidth = pNewGlyphWidths[i];
m_GlyphItems[i].maLinearPos.X() += nDelta;
}
}
else
{
GenericSalLayout::ApplyDXArray(rArgs);
}
}
// =======================================================================
static bool lcl_CharIsJoiner(sal_Unicode cChar)
......
......@@ -322,7 +322,6 @@ public:
ServerFontLayout( ServerFont& );
virtual bool LayoutText( ImplLayoutArgs& );
virtual void AdjustLayout( ImplLayoutArgs& );
virtual void ApplyDXArray( ImplLayoutArgs& );
virtual void DrawText( SalGraphics& ) const;
ServerFont& GetServerFont() const { return mrServerFont; }
};
......
......@@ -1090,7 +1090,7 @@ void GenericSalLayout::ApplyDXArray( ImplLayoutArgs& rArgs )
if( m_GlyphItems[i].IsClusterStart() )
{
// calculate original and adjusted cluster width
int nOldClusterWidth = m_GlyphItems[i].mnNewWidth;
int nOldClusterWidth = m_GlyphItems[i].mnNewWidth - m_GlyphItems[i].mnXOffset;
int nNewClusterWidth = pNewGlyphWidths[i];
size_t j;
for( j = i; ++j < m_GlyphItems.size(); )
......@@ -1098,7 +1098,7 @@ void GenericSalLayout::ApplyDXArray( ImplLayoutArgs& rArgs )
if( m_GlyphItems[j].IsClusterStart() )
break;
if( !m_GlyphItems[j].IsDiacritic() ) // #i99367# ignore diacritics
nOldClusterWidth += m_GlyphItems[j].mnNewWidth;
nOldClusterWidth += m_GlyphItems[j].mnNewWidth - m_GlyphItems[j].mnXOffset;
nNewClusterWidth += pNewGlyphWidths[j];
}
const int nDiff = nNewClusterWidth - nOldClusterWidth;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment