diff options
author | Norbert Thiebaud <nthiebaud@gmail.com> | 2014-07-17 18:46:08 +0200 |
---|---|---|
committer | Norbert Thiebaud <nthiebaud@gmail.com> | 2014-07-20 22:10:58 +0200 |
commit | 2b8528a2745bec7909bfe2265d6110a9964eef47 (patch) | |
tree | 335279159b6f01de07ea23e15679e566ac000ed5 /vcl/source | |
parent | 269e960ee190a8f568e99756c90cd98f1a7919ce (diff) |
Use DeviceCorrdinate for DXArray in FillDXArray and ImplLayoutArgs
Change-Id: Ifba7104a13cf737200c81d1a1bd5ece9a29da60e
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/gdi/sallayout.cxx | 46 | ||||
-rw-r--r-- | vcl/source/glyphs/graphite_layout.cxx | 4 | ||||
-rw-r--r-- | vcl/source/outdev/text.cxx | 100 |
3 files changed, 108 insertions, 42 deletions
diff --git a/vcl/source/gdi/sallayout.cxx b/vcl/source/gdi/sallayout.cxx index 20a0ff656e31..100352082631 100644 --- a/vcl/source/gdi/sallayout.cxx +++ b/vcl/source/gdi/sallayout.cxx @@ -836,7 +836,7 @@ void GenericSalLayout::AppendGlyph( const GlyphItem& rGlyphItem ) m_GlyphItems.push_back(rGlyphItem); } -bool GenericSalLayout::GetCharWidths( sal_Int32* pCharWidths ) const +bool GenericSalLayout::GetCharWidths( DeviceCoordinate* pCharWidths ) const { // initialize character extents buffer int nCharCount = mnEndCharPos - mnMinCharPos; @@ -910,7 +910,7 @@ bool GenericSalLayout::GetCharWidths( sal_Int32* pCharWidths ) const return true; } -long GenericSalLayout::FillDXArray( sal_Int32* pCharWidths ) const +DeviceCoordinate GenericSalLayout::FillDXArray( DeviceCoordinate* pCharWidths ) const { if( pCharWidths ) if( !GetCharWidths( pCharWidths ) ) @@ -1281,7 +1281,7 @@ void GenericSalLayout::GetCaretPositions( int nMaxIndex, sal_Int32* pCaretXArray sal_Int32 GenericSalLayout::GetTextBreak( long nMaxWidth, long nCharExtra, int nFactor ) const { int nCharCapacity = mnEndCharPos - mnMinCharPos; - sal_Int32* pCharWidths = (sal_Int32*)alloca( nCharCapacity * sizeof(sal_Int32) ); + DeviceCoordinate* pCharWidths = (DeviceCoordinate*)alloca( nCharCapacity * sizeof(DeviceCoordinate) ); if( !GetCharWidths( pCharWidths ) ) return -1; @@ -1528,7 +1528,7 @@ void MultiSalLayout::AdjustLayout( ImplLayoutArgs& rArgs ) { // for stretched text in a MultiSalLayout the target width needs to be // distributed by individually adjusting its virtual character widths - long nTargetWidth = aMultiArgs.mnLayoutWidth; + DeviceCoordinate nTargetWidth = aMultiArgs.mnLayoutWidth; nTargetWidth *= mnUnitsPerPixel; // convert target width to base font units aMultiArgs.mnLayoutWidth = 0; @@ -1537,12 +1537,12 @@ void MultiSalLayout::AdjustLayout( ImplLayoutArgs& rArgs ) mpLayouts[n]->SalLayout::AdjustLayout( aMultiArgs ); // then we can measure the unmodified metrics int nCharCount = rArgs.mnEndCharPos - rArgs.mnMinCharPos; - sal_Int32* pJustificationArray = (sal_Int32*)alloca( nCharCount * sizeof(sal_Int32) ); + DeviceCoordinate* pJustificationArray = (DeviceCoordinate*)alloca( nCharCount * sizeof(sal_Int32) ); FillDXArray( pJustificationArray ); // #i17359# multilayout is not simplified yet, so calculating the // unjustified width needs handholding; also count the number of // stretchable virtual char widths - long nOrigWidth = 0; + DeviceCoordinate nOrigWidth = 0; int nStretchable = 0; for( int i = 0; i < nCharCount; ++i ) { @@ -1555,14 +1555,14 @@ void MultiSalLayout::AdjustLayout( ImplLayoutArgs& rArgs ) // now we are able to distribute the extra width over the virtual char widths if( nOrigWidth && (nTargetWidth != nOrigWidth) ) { - int nDiffWidth = nTargetWidth - nOrigWidth; - int nWidthSum = 0; + DeviceCoordinate nDiffWidth = nTargetWidth - nOrigWidth; + DeviceCoordinate nWidthSum = 0; for( int i = 0; i < nCharCount; ++i ) { - int nJustWidth = pJustificationArray[i]; + DeviceCoordinate nJustWidth = pJustificationArray[i]; if( (nJustWidth > 0) && (nStretchable > 0) ) { - int nDeltaWidth = nDiffWidth / nStretchable; + DeviceCoordinate nDeltaWidth = nDiffWidth / nStretchable; nJustWidth += nDeltaWidth; nDiffWidth -= nDeltaWidth; --nStretchable; @@ -1579,7 +1579,7 @@ void MultiSalLayout::AdjustLayout( ImplLayoutArgs& rArgs ) { for( int i = 0; i < nCharCount; ++i ) { - sal_Int32 nVal = pJustificationArray[ i ]; + DeviceCoordinate nVal = pJustificationArray[ i ]; nVal += (mnUnitsPerPixel + 1) / 2; pJustificationArray[ i ] = nVal / mnUnitsPerPixel; } @@ -1915,7 +1915,7 @@ sal_Int32 MultiSalLayout::GetTextBreak( long nMaxWidth, long nCharExtra, int nFa return mpLayouts[0]->GetTextBreak( nMaxWidth, nCharExtra, nFactor ); int nCharCount = mnEndCharPos - mnMinCharPos; - sal_Int32* pCharWidths = (sal_Int32*)alloca( 2*nCharCount * sizeof(sal_Int32) ); + DeviceCoordinate* pCharWidths = (DeviceCoordinate*)alloca( 2*nCharCount * sizeof(DeviceCoordinate) ); mpLayouts[0]->FillDXArray( pCharWidths ); for( int n = 1; n < mnLevel; ++n ) @@ -1926,13 +1926,13 @@ sal_Int32 MultiSalLayout::GetTextBreak( long nMaxWidth, long nCharExtra, int nFa fUnitMul /= rLayout.GetUnitsPerPixel(); for( int i = 0; i < nCharCount; ++i ) { - long w = pCharWidths[ i + nCharCount ]; - w = static_cast<long>(w*fUnitMul + 0.5); + DeviceCoordinate w = pCharWidths[ i + nCharCount ]; + w = (DeviceCoordinate)(w * fUnitMul + 0.5); pCharWidths[ i ] += w; } } - long nWidth = 0; + DeviceCoordinate nWidth = 0; for( int i = 0; i < nCharCount; ++i ) { nWidth += pCharWidths[ i ] * nFactor; @@ -1944,30 +1944,30 @@ sal_Int32 MultiSalLayout::GetTextBreak( long nMaxWidth, long nCharExtra, int nFa return -1; } -long MultiSalLayout::FillDXArray( sal_Int32* pCharWidths ) const +DeviceCoordinate MultiSalLayout::FillDXArray( DeviceCoordinate* pCharWidths ) const { - long nMaxWidth = 0; + DeviceCoordinate nMaxWidth = 0; // prepare merging of fallback levels - sal_Int32* pTempWidths = NULL; + DeviceCoordinate* pTempWidths = NULL; const int nCharCount = mnEndCharPos - mnMinCharPos; if( pCharWidths ) { for( int i = 0; i < nCharCount; ++i ) pCharWidths[i] = 0; - pTempWidths = (sal_Int32*)alloca( nCharCount * sizeof(sal_Int32) ); + pTempWidths = (DeviceCoordinate*)alloca( nCharCount * sizeof(DeviceCoordinate) ); } for( int n = mnLevel; --n >= 0; ) { // query every fallback level - long nTextWidth = mpLayouts[n]->FillDXArray( pTempWidths ); + DeviceCoordinate nTextWidth = mpLayouts[n]->FillDXArray( pTempWidths ); if( !nTextWidth ) continue; // merge results from current level double fUnitMul = mnUnitsPerPixel; fUnitMul /= mpLayouts[n]->GetUnitsPerPixel(); - nTextWidth = static_cast<long>(nTextWidth * fUnitMul + 0.5); + nTextWidth = (DeviceCoordinate)(nTextWidth * fUnitMul + 0.5); if( nMaxWidth < nTextWidth ) nMaxWidth = nTextWidth; if( !pCharWidths ) @@ -1979,10 +1979,10 @@ long MultiSalLayout::FillDXArray( sal_Int32* pCharWidths ) const // one char cannot be resolved from different fallbacks if( pCharWidths[i] != 0 ) continue; - long nCharWidth = pTempWidths[i]; + DeviceCoordinate nCharWidth = pTempWidths[i]; if( !nCharWidth ) continue; - nCharWidth = static_cast<long>(nCharWidth * fUnitMul + 0.5); + nCharWidth = (DeviceCoordinate)(nCharWidth * fUnitMul + 0.5); pCharWidths[i] = nCharWidth; } } diff --git a/vcl/source/glyphs/graphite_layout.cxx b/vcl/source/glyphs/graphite_layout.cxx index 57e61ffe60c3..d9801102787f 100644 --- a/vcl/source/glyphs/graphite_layout.cxx +++ b/vcl/source/glyphs/graphite_layout.cxx @@ -732,7 +732,7 @@ sal_Int32 GraphiteLayout::GetTextBreak(long maxmnWidth, long char_extra, int fac return nBreak; } -long GraphiteLayout::FillDXArray( sal_Int32* pDXArray ) const +DeviceCoordinate GraphiteLayout::FillDXArray( DeviceCoordinate* pDXArray ) const { if (mnEndCharPos == mnMinCharPos) // Then we must be zero width! @@ -766,7 +766,7 @@ long GraphiteLayout::FillDXArray( sal_Int32* pDXArray ) const //fprintf(grLog(),"FillDX %ld,%d\n", mnWidth, std::accumulate(pDXArray, pDXArray + mvCharDxs.size(), 0)); } #ifdef GRLAYOUT_DEBUG - fprintf(grLog(),"FillDXArray %d-%d=%ld\n", mnMinCharPos, mnEndCharPos, mnWidth); + fprintf(grLog(),"FillDXArray %d-%d=%g\n", mnMinCharPos, mnEndCharPos, (double)mnWidth); #endif return mnWidth; } diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx index 93a0e919d2a2..f9669e0f402e 100644 --- a/vcl/source/outdev/text.cxx +++ b/vcl/source/outdev/text.cxx @@ -1004,6 +1004,56 @@ long OutputDevice::GetTextArray( const OUString& rStr, sal_Int32* pDXAry, SalLayout* pSalLayout = ImplLayout( rStr, nIndex, nLen ); if( !pSalLayout ) return 0; +#if VCL_FLOAT_DEVICE_PIXEL + DeviceCoordinate* pDXPixelArray = NULL; + if(pDXAry) + { + pDXPixelArray = (DeviceCoordinate*)alloca(nLen * sizeof(DeviceCoordinate)); + } + DeviceCoordinate nWidth = pSalLayout->FillDXArray( pDXPixelArray ); + int nWidthFactor = pSalLayout->GetUnitsPerPixel(); + pSalLayout->Release(); + + // convert virtual char widths to virtual absolute positions + if( pDXPixelArray ) + { + for( int i = 1; i < nLen; ++i ) + { + pDXPixelArray[ i ] += pDXPixelArray[ i-1 ]; + } + } + if( mbMap ) + { + if( pDXPixelArray ) + { + for( int i = 0; i < nLen; ++i ) + { + pDXPixelArray[i] = ImplDevicePixelToLogicWidth( pDXPixelArray[i] ); + } + } + nWidth = ImplDevicePixelToLogicWidth( nWidth ); + } + if( nWidthFactor > 1 ) + { + if( pDXPixelArray ) + { + for( int i = 0; i < nLen; ++i ) + { + pDXPixelArray[i] /= nWidthFactor; + } + } + nWidth /= nWidthFactor; + } + if(pDXAry) + { + for( int i = 0; i < nLen; ++i ) + { + pDXAry[i] = basegfx::fround(pDXPixelArray[i]); + } + } + return basegfx::fround(nWidth); + +#else /* ! VCL_FLOAT_DEVICE_PIXEL */ long nWidth = pSalLayout->FillDXArray( pDXAry ); int nWidthFactor = pSalLayout->GetUnitsPerPixel(); @@ -1030,8 +1080,8 @@ long OutputDevice::GetTextArray( const OUString& rStr, sal_Int32* pDXAry, pDXAry[i] /= nWidthFactor; nWidth /= nWidthFactor; } - return nWidth; +#endif /* VCL_FLOAT_DEVICE_PIXEL */ } bool OutputDevice::GetCaretPositions( const OUString& rStr, sal_Int32* pCaretXArray, @@ -1132,7 +1182,7 @@ void OutputDevice::DrawStretchText( const Point& rStartPt, sal_uLong nWidth, ImplLayoutArgs OutputDevice::ImplPrepareLayoutArgs( OUString& rStr, const sal_Int32 nMinIndex, const sal_Int32 nLen, - long nPixelWidth, const sal_Int32* pDXArray, + DeviceCoordinate nPixelWidth, const DeviceCoordinate* pDXArray, int nLayoutFlags ) const { assert(nMinIndex >= 0); @@ -1276,23 +1326,39 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr, if( mpFontEntry->mpConversion ) { mpFontEntry->mpConversion->RecodeString( aStr, 0, aStr.getLength() ); } - - long nPixelWidth = nLogicalWidth; + DeviceCoordinate nPixelWidth = (DeviceCoordinate)nLogicalWidth; + DeviceCoordinate* pDXPixelArray = NULL; if( nLogicalWidth && mbMap ) - nPixelWidth = ImplLogicWidthToDevicePixel( nLogicalWidth ); - if( pDXArray && mbMap ) { - // convert from logical units to font units using a temporary array - sal_Int32* pTempDXAry = (sal_Int32*)alloca( nLen * sizeof(sal_Int32) ); - // using base position for better rounding a.k.a. "dancing characters" - int nPixelXOfs = ImplLogicWidthToDevicePixel( rLogicalPos.X() ); - for( int i = 0; i < nLen; ++i ) - pTempDXAry[i] = ImplLogicWidthToDevicePixel( rLogicalPos.X() + pDXArray[i] ) - nPixelXOfs; + nPixelWidth = ImplLogicWidthToDevicePixel( nLogicalWidth ); + } - pDXArray = pTempDXAry; + if( pDXArray) + { + if(mbMap) + { + // convert from logical units to font units using a temporary array + pDXPixelArray = (DeviceCoordinate*)alloca( nLen * sizeof(DeviceCoordinate) ); + // using base position for better rounding a.k.a. "dancing characters" + DeviceCoordinate nPixelXOfs = ImplLogicWidthToDevicePixel( rLogicalPos.X() ); + for( int i = 0; i < nLen; ++i ) + pDXPixelArray[i] = ImplLogicWidthToDevicePixel( rLogicalPos.X() + pDXArray[i] ) - nPixelXOfs; + } + else + { +#if VCL_FLOAT_DEVICE_PIXEL + pDXPixelArray = (DeviceCoordinate*)alloca( nLen * sizeof(DeviceCoordinate) ); + for( int i = 0; i < nLen; ++i ) + { + pDXPixelArray[i] = pDXArray[i]; + } +#else /* !VCL_FLOAT_DEVICE_PIXEL */ + pDXPixelArray = (DeviceCoordinate*)pDXArray; +#endif /* !VCL_FLOAT_DEVICE_PIXEL */ + } } - ImplLayoutArgs aLayoutArgs = ImplPrepareLayoutArgs( aStr, nMinIndex, nLen, nPixelWidth, pDXArray, flags); + ImplLayoutArgs aLayoutArgs = ImplPrepareLayoutArgs( aStr, nMinIndex, nLen, nPixelWidth, pDXPixelArray, flags); // get matching layout object for base font SalLayout* pSalLayout = mpGraphics->GetTextLayout( aLayoutArgs, 0 ); @@ -1318,9 +1384,9 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr, // adjust to right alignment if necessary if( aLayoutArgs.mnFlags & SAL_LAYOUT_RIGHT_ALIGN ) { - long nRTLOffset; - if( pDXArray ) - nRTLOffset = pDXArray[ nLen - 1 ]; + DeviceCoordinate nRTLOffset; + if( pDXPixelArray ) + nRTLOffset = pDXPixelArray[ nLen - 1 ]; else if( nPixelWidth ) nRTLOffset = nPixelWidth; else |