summaryrefslogtreecommitdiff
path: root/vcl/source
diff options
context:
space:
mode:
authorNorbert Thiebaud <nthiebaud@gmail.com>2014-09-06 16:13:09 +0200
committerNorbert Thiebaud <nthiebaud@gmail.com>2014-09-12 01:45:27 +0200
commit1b42acdaeae134f94580d6e1eba89da16741d596 (patch)
tree882710be2c142cdef62823c9600925ee22f8dab7 /vcl/source
parent43638d8428abb8358a703247651fbfc72e47ff72 (diff)
vcl: use DeviceCoordinate for GetCaretPositions in sallayout
Change-Id: I5a959e1c3806da713e106c1b0fc8690a6578987b
Diffstat (limited to 'vcl/source')
-rw-r--r--vcl/source/gdi/sallayout.cxx12
-rw-r--r--vcl/source/glyphs/graphite_layout.cxx4
-rw-r--r--vcl/source/outdev/map.cxx25
-rw-r--r--vcl/source/outdev/text.cxx117
4 files changed, 131 insertions, 27 deletions
diff --git a/vcl/source/gdi/sallayout.cxx b/vcl/source/gdi/sallayout.cxx
index c30a99af01fb..a3124c443e37 100644
--- a/vcl/source/gdi/sallayout.cxx
+++ b/vcl/source/gdi/sallayout.cxx
@@ -1247,7 +1247,7 @@ void GenericSalLayout::KashidaJustify( long nKashidaIndex, int nKashidaWidth )
}
}
-void GenericSalLayout::GetCaretPositions( int nMaxIndex, long* pCaretXArray ) const
+void GenericSalLayout::GetCaretPositions( int nMaxIndex, DeviceCoordinate* pCaretXArray ) const
{
// initialize result array
long nXPos = -1;
@@ -1990,26 +1990,28 @@ DeviceCoordinate MultiSalLayout::FillDXArray( DeviceCoordinate* pCharWidths ) co
return nMaxWidth;
}
-void MultiSalLayout::GetCaretPositions( int nMaxIndex, long* pCaretXArray ) const
+void MultiSalLayout::GetCaretPositions( int nMaxIndex, DeviceCoordinate* pCaretXArray ) const
{
SalLayout& rLayout = *mpLayouts[ 0 ];
rLayout.GetCaretPositions( nMaxIndex, pCaretXArray );
if( mnLevel > 1 )
{
- long* pTempPos = (long*)alloca( nMaxIndex * sizeof(long) );
+ DeviceCoordinate* pTempPos = (DeviceCoordinate*)alloca( nMaxIndex * sizeof(DeviceCoordinate) );
for( int n = 1; n < mnLevel; ++n )
{
mpLayouts[ n ]->GetCaretPositions( nMaxIndex, pTempPos );
double fUnitMul = mnUnitsPerPixel;
fUnitMul /= mpLayouts[n]->GetUnitsPerPixel();
for( int i = 0; i < nMaxIndex; ++i )
+ {
if( pTempPos[i] >= 0 )
{
- long w = pTempPos[i];
- w = static_cast<long>(w*fUnitMul + 0.5);
+ DeviceCoordinate w = pTempPos[i];
+ w = (DeviceCoordinate)(w * fUnitMul + 0.5);
pCaretXArray[i] = w;
}
+ }
}
}
}
diff --git a/vcl/source/glyphs/graphite_layout.cxx b/vcl/source/glyphs/graphite_layout.cxx
index 6f7cbb252ab0..508a0db1d733 100644
--- a/vcl/source/glyphs/graphite_layout.cxx
+++ b/vcl/source/glyphs/graphite_layout.cxx
@@ -1090,14 +1090,14 @@ void GraphiteLayout::kashidaJustify(std::vector<int>& rDeltaWidths, sal_GlyphId
}
-void GraphiteLayout::GetCaretPositions( int nArraySize, long* pCaretXArray ) const
+void GraphiteLayout::GetCaretPositions( int nArraySize, DeviceCoordinate* pCaretXArray ) const
{
// For each character except the last discover the caret positions
// immediately before and after that character.
// This is used for underlines in the GUI amongst other things.
// It may be used from MultiSalLayout, in which case it must take into account
// glyphs that have been moved.
- std::fill(pCaretXArray, pCaretXArray + nArraySize, -1);
+ std::fill(pCaretXArray, pCaretXArray + nArraySize, (DeviceCoordinate)-1);
// the layout method doesn't modify the layout even though it isn't
// const in the interface
bool bRtl = (mnLayoutFlags & SAL_LAYOUT_BIDI_RTL);//const_cast<GraphiteLayout*>(this)->maLayout.rightToLeft();
diff --git a/vcl/source/outdev/map.cxx b/vcl/source/outdev/map.cxx
index 396a2c471014..2cea0d3886fa 100644
--- a/vcl/source/outdev/map.cxx
+++ b/vcl/source/outdev/map.cxx
@@ -2142,6 +2142,31 @@ long Window::ImplLogicUnitToPixelY( long nY, MapUnit eUnit )
return nY;
}
+long OutputDevice::DeviceCoordinateToLogicWidth(DeviceCoordinate width) const
+{
+ if ( !mbMap )
+ {
+ return (long)width;
+ }
+#if VCL_FLOAT_DEVICE_PIXEL
+ return (long)(width / (maMapRes.mfScaleX * mnDPIX));
+#else
+ return ImplDevicePixelToLogicWidth(width);
+#endif
+}
+
+long OutputDevice::DeviceCoordinateToLogicHeight(DeviceCoordinate height) const
+{
+ if ( !mbMap )
+ {
+ return (long)height;
+ }
+#if VCL_FLOAT_DEVICE_PIXEL
+ return (long)(height / (maMapRes.mfScaleY * mnDPIY));
+#else
+ return ImplDevicePixelToLogicHeight(height);
+#endif
+}
DeviceCoordinate OutputDevice::LogicWidthToDeviceCoordinate( long nWidth ) const
{
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index 51117fe1c172..1dff2db44141 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -1014,6 +1014,7 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
{
pDXPixelArray = (DeviceCoordinate*)alloca(nLen * sizeof(DeviceCoordinate));
}
+ long nWidthRes;
DeviceCoordinate nWidth = pSalLayout->FillDXArray( pDXPixelArray );
int nWidthFactor = pSalLayout->GetUnitsPerPixel();
pSalLayout->Release();
@@ -1026,36 +1027,41 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
pDXPixelArray[ i ] += pDXPixelArray[ i-1 ];
}
}
- if( mbMap )
+ if( nWidthFactor > 1 )
{
if( pDXPixelArray )
{
for( int i = 0; i < nLen; ++i )
{
- pDXPixelArray[i] = ImplDevicePixelToLogicWidth( pDXPixelArray[i] );
+ pDXPixelArray[i] /= nWidthFactor;
}
}
- nWidth = ImplDevicePixelToLogicWidth( nWidth );
+ nWidth /= nWidthFactor;
}
- if( nWidthFactor > 1 )
+ if( mbMap )
{
if( pDXPixelArray )
{
for( int i = 0; i < nLen; ++i )
{
- pDXPixelArray[i] /= nWidthFactor;
+ pDXAry[i] = DeviceCoordinateToLogicWidth( pDXPixelArray[i] );
}
}
- nWidth /= nWidthFactor;
+ nWidthRes = DeviceCoordinateToLogicWidth( nWidth );
}
- if(pDXAry)
+ else
{
- for( int i = 0; i < nLen; ++i )
+ if( pDXPixelArray )
{
- pDXAry[i] = basegfx::fround(pDXPixelArray[i]);
+ for( int i = 0; i < nLen; ++i )
+ {
+ pDXAry[i] = (long)pDXPixelArray[i];
+ }
}
+ nWidthRes = (long) nWidth;
}
- return basegfx::fround(nWidth);
+
+ return nWidth;
#else /* ! VCL_FLOAT_DEVICE_PIXEL */
@@ -1091,7 +1097,7 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
bool OutputDevice::GetCaretPositions( const OUString& rStr, long* pCaretXArray,
sal_Int32 nIndex, sal_Int32 nLen,
long* pDXAry, long nLayoutWidth,
- bool bCellBreaking ) const
+ bool /* bCellBreaking */ ) const
{
if( nIndex >= rStr.getLength() )
@@ -1105,50 +1111,121 @@ bool OutputDevice::GetCaretPositions( const OUString& rStr, long* pCaretXArray,
if( !pSalLayout )
return false;
+#if VCL_FLOAT_DEVICE_PIXEL
+ int nWidthFactor = pSalLayout->GetUnitsPerPixel();
+ DeviceCoordinate* pDevCaretXArray = (DeviceCoordinate*)alloca(2 * nLen * sizeof(DeviceCoordinate));
+
+ pSalLayout->GetCaretPositions( 2*nLen, pDevCaretXArray );
+ DeviceCoordinate nWidth = pSalLayout->GetTextWidth();
+ pSalLayout->Release();
+
+ // fixup unknown caret positions
+ int i;
+ for( i = 0; i < 2 * nLen; ++i )
+ {
+ if( pDevCaretXArray[ i ] >= 0 )
+ {
+ break;
+ }
+ }
+ DeviceCoordinate nXPos = pCaretXArray[ i ];
+ for( i = 0; i < 2 * nLen; ++i )
+ {
+ if( pCaretXArray[ i ] >= 0 )
+ {
+ nXPos = pCaretXArray[ i ];
+ }
+ else
+ {
+ pCaretXArray[ i ] = nXPos;
+ }
+ }
+ if( nWidthFactor != 1 )
+ {
+ for( i = 0; i < 2*nLen; ++i )
+ {
+ pDevCaretXArray[i] /= nWidthFactor;
+ }
+ }
+
+ // handle window mirroring
+ if( IsRTLEnabled() )
+ {
+ for( i = 0; i < 2 * nLen; ++i )
+ {
+ pDevCaretXArray[i] = nWidth - pDevCaretXArray[i] - 1;
+ }
+ }
+
+ // convert from font units to logical units
+ if( mbMap )
+ {
+ for( i = 0; i < 2*nLen; ++i )
+ {
+ pCaretXArray[i] = DeviceCoordinateToLogicWidth( pDevCaretXArray[i] );
+ }
+ }
+ else
+ {
+ for( i = 0; i < 2*nLen; ++i )
+ {
+ pCaretXArray[i] = (long)pDevCaretXArray[i];
+ }
+ }
+#else
int nWidthFactor = pSalLayout->GetUnitsPerPixel();
+
pSalLayout->GetCaretPositions( 2*nLen, pCaretXArray );
- long nWidth = pSalLayout->GetTextWidth();
+ DeviceCoordinate nWidth = pSalLayout->GetTextWidth();
pSalLayout->Release();
// fixup unknown caret positions
int i;
for( i = 0; i < 2 * nLen; ++i )
+ {
if( pCaretXArray[ i ] >= 0 )
+ {
break;
- long nXPos = pCaretXArray[ i ];
+ }
+ }
+ DeviceCoordinate nXPos = pCaretXArray[ i ];
for( i = 0; i < 2 * nLen; ++i )
{
if( pCaretXArray[ i ] >= 0 )
+ {
nXPos = pCaretXArray[ i ];
+ }
else
+ {
pCaretXArray[ i ] = nXPos;
+ }
}
// handle window mirroring
if( IsRTLEnabled() )
{
for( i = 0; i < 2 * nLen; ++i )
+ {
pCaretXArray[i] = nWidth - pCaretXArray[i] - 1;
+ }
}
// convert from font units to logical units
if( mbMap )
{
for( i = 0; i < 2*nLen; ++i )
+ {
pCaretXArray[i] = ImplDevicePixelToLogicWidth( pCaretXArray[i] );
+ }
}
-
if( nWidthFactor != 1 )
{
for( i = 0; i < 2*nLen; ++i )
+ {
pCaretXArray[i] /= nWidthFactor;
+ }
}
-
- // if requested move caret position to cell limits
- if( bCellBreaking )
- {
- ; // FIXME
- }
+#endif
return true;
}