Rebased ref, commits from common ancestor:
commit 938503547de1b6229056b0837bccbed43f862cce
Author: Tamás Zolnai <[email protected]>
AuthorDate: Thu Oct 23 10:41:11 2025 +0200
Commit: Tamás Zolnai <[email protected]>
CommitDate: Fri Oct 24 12:59:59 2025 +0200
POC: Better grid in Writer and Calc.
Change-Id: I34905cc2705bb53deb51cfa8cb4b5058c9b21208
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index 3cc7d153a53f..3aeb1cd08e47 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -612,6 +612,8 @@ public:
void DrawGrid( const tools::Rectangle& rRect, const
Size& rDist, DrawGridFlags nFlags );
+ void DrawGridOfCrosses( const tools::Rectangle&
rRect, const Size& rDist, const tools::Rectangle& rCutRect, const Size&
rCrossSize);
+
///@}
/** @name Invert functions
diff --git a/include/vcl/rendercontext/DrawGridFlags.hxx
b/include/vcl/rendercontext/DrawGridFlags.hxx
index 4d783e780976..e90c8f05d348 100644
--- a/include/vcl/rendercontext/DrawGridFlags.hxx
+++ b/include/vcl/rendercontext/DrawGridFlags.hxx
@@ -26,11 +26,12 @@ enum class DrawGridFlags
NONE = 0x0000,
Dots = 0x0001,
HorzLines = 0x0002,
- VertLines = 0x0004
+ VertLines = 0x0004,
+ Crosses = 0x0008
};
namespace o3tl
{
-template <> struct typed_flags<DrawGridFlags> : is_typed_flags<DrawGridFlags,
0x0007>
+template <> struct typed_flags<DrawGridFlags> : is_typed_flags<DrawGridFlags,
0x00f>
{
};
}
diff --git a/svx/source/svdraw/svdpagv.cxx b/svx/source/svdraw/svdpagv.cxx
index 41419bc113f1..7068aee245ea 100644
--- a/svx/source/svdraw/svdpagv.cxx
+++ b/svx/source/svdraw/svdpagv.cxx
@@ -461,6 +461,7 @@ void SdrPageView::DrawPageViewGrid(OutputDevice& rOut,
const tools::Rectangle& r
sal_uInt16 nGridPaintCnt=1;
if (pFrames!=nullptr) nGridPaintCnt=pFrames->GetCount();
for (sal_uInt16 nGridPaintNum=0; nGridPaintNum<nGridPaintCnt;
nGridPaintNum++) {
+ tools::Rectangle aDrawArea;
if (pFrames!=nullptr) {
const SdrPageGridFrame& rGF=(*pFrames)[nGridPaintNum];
nWrX=rGF.GetPaperRect().Left();
@@ -471,6 +472,11 @@ void SdrPageView::DrawPageViewGrid(OutputDevice& rOut,
const tools::Rectangle& r
y2=rGF.GetUserArea().Bottom();
aOrg=rGF.GetUserArea().TopLeft();
aOrg-=rGF.GetPaperRect().TopLeft();
+ aDrawArea=rGF.GetUserArea();
+ }
+ else
+ {
+ aDrawArea=tools::Rectangle{maPageOrigin, GetPage()->GetSize()};
}
if (!rRect.IsEmpty()) {
Size a1PixSiz(rOut.PixelToLogic(Size(1,1)));
@@ -500,18 +506,31 @@ void SdrPageView::DrawPageViewGrid(OutputDevice& rOut,
const tools::Rectangle& r
{
if( bHoriLines )
{
- DrawGridFlags nGridFlags = ( bHoriSolid ?
DrawGridFlags::HorzLines : DrawGridFlags::Dots );
sal_uInt16 nSteps = sal_uInt16(nx1 / nx2);
sal_uInt32 nRestPerStepMul1000 = nSteps ? ( ((nx1 * 1000)/
nSteps) - (nx2 * 1000) ) : 0;
sal_uInt32 nStepOffset = 0;
sal_uInt16 nPointOffset = 0;
+ SAL_WARN("drawGrid", "bHoriSolid: " << (bHoriSolid ? "true" :
"false"));
+ SAL_WARN("drawGrid", "nSteps: " << nSteps);
+ SAL_WARN("drawGrid", "nRestPerStepMul1000: " <<
nRestPerStepMul1000);
+ SAL_WARN("drawGrid", "nStepOffset: " << nStepOffset);
+ SAL_WARN("drawGrid", "nPointOffset: " << nPointOffset);
for(sal_uInt16 a=0;a<nSteps;a++)
{
// draw
- rOut.DrawGrid(
- tools::Rectangle( xFinOrg + (a * nx2) + nPointOffset,
yBigOrg, x2, y2 ),
- Size( nx1, ny1 ), nGridFlags );
+ if (false)
+ {
+ rOut.DrawGrid(
+ tools::Rectangle( xFinOrg + (a * nx2) +
nPointOffset, yBigOrg, x2, y2 ),
+ Size( nx1, ny1 ), DrawGridFlags::HorzLines );
+ }
+ else
+ {
+ rOut.DrawGridOfCrosses(
+ tools::Rectangle( xFinOrg + (a * nx2) +
nPointOffset, yBigOrg, x2, y2 ),
+ Size( nx1, ny1 ), aDrawArea,
Size(GetView().maGridFin.Width() / 4, GetView().maGridFin.Height() / 4) );
+ }
// do a step
nStepOffset += nRestPerStepMul1000;
@@ -525,7 +544,6 @@ void SdrPageView::DrawPageViewGrid(OutputDevice& rOut,
const tools::Rectangle& r
if( bVertLines )
{
- DrawGridFlags nGridFlags = ( bVertSolid ?
DrawGridFlags::VertLines : DrawGridFlags::Dots );
sal_uInt16 nSteps = sal_uInt16(ny1 / ny2);
sal_uInt32 nRestPerStepMul1000 = nSteps ? ( ((ny1 * 1000L)/
nSteps) - (ny2 * 1000L) ) : 0;
sal_uInt32 nStepOffset = 0;
@@ -534,9 +552,18 @@ void SdrPageView::DrawPageViewGrid(OutputDevice& rOut,
const tools::Rectangle& r
for(sal_uInt16 a=0;a<nSteps;a++)
{
// draw
- rOut.DrawGrid(
- tools::Rectangle( xBigOrg, yFinOrg + (a * ny2) +
nPointOffset, x2, y2 ),
- Size( nx1, ny1 ), nGridFlags );
+ if (false)
+ {
+ rOut.DrawGrid(
+ tools::Rectangle( xBigOrg, yFinOrg + (a * ny2) +
nPointOffset, x2, y2 ),
+ Size( nx1, ny1 ), DrawGridFlags::VertLines );
+ }
+ else
+ {
+ rOut.DrawGridOfCrosses(
+ tools::Rectangle( xBigOrg, yFinOrg + (a * ny2) +
nPointOffset, x2, y2 ),
+ Size( nx1, ny1 ), aDrawArea,
Size(GetView().maGridFin.Width() / 4, GetView().maGridFin.Height() / 4) );
+ }
// do a step
nStepOffset += nRestPerStepMul1000;
diff --git a/vcl/source/outdev/rect.cxx b/vcl/source/outdev/rect.cxx
index c2731237d1cf..2c98faea1f27 100644
--- a/vcl/source/outdev/rect.cxx
+++ b/vcl/source/outdev/rect.cxx
@@ -263,7 +263,7 @@ void OutputDevice::DrawGrid( const tools::Rectangle& rRect,
const Size& rDist, D
std::vector< sal_Int32 > aVertBuf;
std::vector< sal_Int32 > aHorzBuf;
- if( ( nFlags & DrawGridFlags::Dots ) || ( nFlags &
DrawGridFlags::HorzLines ) )
+ if( ( nFlags & DrawGridFlags::Dots ) || ( nFlags & DrawGridFlags::Crosses
) ||( nFlags & DrawGridFlags::HorzLines ) )
{
aVertBuf.resize( aDstRect.GetHeight() / nDistY + 2 );
aVertBuf[ nVertCount++ ] = nStartY;
@@ -273,7 +273,7 @@ void OutputDevice::DrawGrid( const tools::Rectangle& rRect,
const Size& rDist, D
}
}
- if( ( nFlags & DrawGridFlags::Dots ) || ( nFlags &
DrawGridFlags::VertLines ) )
+ if( ( nFlags & DrawGridFlags::Dots ) || ( nFlags & DrawGridFlags::Crosses
) || ( nFlags & DrawGridFlags::VertLines ) )
{
aHorzBuf.resize( aDstRect.GetWidth() / nDistX + 2 );
aHorzBuf[ nHorzCount++ ] = nStartX;
@@ -302,6 +302,20 @@ void OutputDevice::DrawGrid( const tools::Rectangle&
rRect, const Size& rDist, D
}
}
}
+ else if( nFlags & DrawGridFlags::Crosses )
+ {
+ for( tools::Long i = 0; i < nVertCount; i++ )
+ {
+ for( tools::Long j = 0, Y = aVertBuf[ i ]; j < nHorzCount; j++ )
+ {
+ tools::Long X = aHorzBuf[ j ];
+ tools::Long crossSizeX = ImplLogicXToDevicePixel( 10 );
+ tools::Long crossSizeY = ImplLogicYToDevicePixel( 10 );
+ mpGraphics->DrawLine( X - crossSizeX, Y, X + crossSizeX, Y,
*this );
+ mpGraphics->DrawLine( X, Y - crossSizeY, X, Y + crossSizeY,
*this );
+ }
+ }
+ }
else
{
if( nFlags & DrawGridFlags::HorzLines )
@@ -326,6 +340,95 @@ void OutputDevice::DrawGrid( const tools::Rectangle&
rRect, const Size& rDist, D
EnableMapMode( bOldMap );
}
+void OutputDevice::DrawGridOfCrosses( const tools::Rectangle& rRect, const
Size& rDist, const tools::Rectangle& rCutRect, const Size& rCrossSize )
+{
+ SAL_WARN("drawGrid", "DrawGridOfCrosses");
+ assert(!is_double_buffered_window());
+
+ tools::Rectangle aDstRect( PixelToLogic( Point() ), GetOutputSize() );
+ aDstRect.Intersection( rRect );
+
+ if( aDstRect.IsEmpty() || ImplIsRecordLayout() )
+ return;
+
+ if( !mpGraphics && !AcquireGraphics() )
+ return;
+ assert(mpGraphics);
+
+ if( mbInitClipRegion )
+ InitClipRegion();
+
+ if( mbOutputClipped )
+ return;
+
+ const tools::Long nDistX = std::max( rDist.Width(), tools::Long(1) );
+ const tools::Long nDistY = std::max( rDist.Height(), tools::Long(1) );
+ tools::Long nX = ( rRect.Left() >= aDstRect.Left() ) ? rRect.Left() : (
rRect.Left() + ( ( aDstRect.Left() - rRect.Left() ) / nDistX ) * nDistX );
+ tools::Long nY = ( rRect.Top() >= aDstRect.Top() ) ? rRect.Top() : (
rRect.Top() + ( ( aDstRect.Top() - rRect.Top() ) / nDistY ) * nDistY );
+ const tools::Long nRight = aDstRect.Right();
+ const tools::Long nBottom = aDstRect.Bottom();
+
+ std::vector< sal_Int32 > aVertBuf;
+ tools::Long nVertCount = 0;
+ aVertBuf.resize( aDstRect.GetHeight() / nDistY + 2 );
+ aVertBuf[ nVertCount++ ] = ImplLogicYToDevicePixel( nY );
+ while( ( nY += nDistY ) <= nBottom )
+ {
+ aVertBuf[ nVertCount++ ] = ImplLogicYToDevicePixel( nY );
+ }
+
+ std::vector< sal_Int32 > aHorzBuf;
+ tools::Long nHorzCount = 0;
+ aHorzBuf.resize( aDstRect.GetWidth() / nDistX + 2 );
+ aHorzBuf[ nHorzCount++ ] = ImplLogicXToDevicePixel( nX );
+ while( ( nX += nDistX ) <= nRight )
+ {
+ aHorzBuf[ nHorzCount++ ] = ImplLogicXToDevicePixel( nX );
+ }
+
+ if( mbInitLineColor )
+ InitLineColor();
+
+ if( mbInitFillColor )
+ InitFillColor();
+
+ for( tools::Long i = 0; i < nVertCount; i++ )
+ {
+ for( tools::Long j = 0; j < nHorzCount; j++ )
+ {
+ const tools::Long nXPixel = aHorzBuf[ j ];
+ const tools::Long nYPixel = aVertBuf[ i ];
+ if (nXPixel < ImplLogicXToDevicePixel(rCutRect.Left()) || nYPixel
< ImplLogicYToDevicePixel(rCutRect.Top()) ||
+ nXPixel > ImplLogicXToDevicePixel(rCutRect.Right()) || nYPixel
> ImplLogicYToDevicePixel(rCutRect.Bottom()))
+ continue;
+
+ const tools::Long crossSizeX =
ImplLogicWidthToDevicePixel(rCrossSize.Width() / 2);
+ const tools::Long crossSizeY =
ImplLogicHeightToDevicePixel(rCrossSize.Height() / 2);
+ const tools::Long nStartX = std::max(nXPixel - crossSizeX,
ImplLogicXToDevicePixel(rCutRect.Left()));
+ const tools::Long nEndX = std::min(nXPixel + crossSizeX + 1,
ImplLogicXToDevicePixel(rCutRect.Right()));
+ const tools::Long nStartY = std::max(nYPixel - crossSizeY,
ImplLogicYToDevicePixel(rCutRect.Top()));
+ const tools::Long nEndY = std::min(nYPixel + crossSizeY + 1,
ImplLogicYToDevicePixel(rCutRect.Bottom()));
+
+ const bool bOldMap = mbMap;
+ EnableMapMode( false );
+
+ mpGraphics->DrawLine( nStartX,
+ nYPixel,
+ nEndX,
+ nYPixel, *this );
+ mpGraphics->DrawLine( nXPixel,
+ nStartY,
+ nXPixel,
+ nEndY, *this );
+
+ mpGraphics->DrawPixel( nXPixel, nYPixel, *this );
+
+ EnableMapMode( bOldMap );
+ }
+ }
+
+}
+
BmpMirrorFlags AdjustTwoRect( SalTwoRect& rTwoRect, const Size& rSizePix )
{
BmpMirrorFlags nMirrFlags = BmpMirrorFlags::NONE;