starmath/source/dialog.cxx | 4 +--- starmath/source/document.cxx | 7 ++----- starmath/source/node.cxx | 3 +-- starmath/source/rect.cxx | 8 ++------ starmath/source/visitors.cxx | 24 +++++++----------------- 5 files changed, 13 insertions(+), 33 deletions(-)
New commits: commit 7528fbd25faa94059a3cfdab5cacce7096ab59cc Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat Aug 16 23:35:05 2025 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sun Aug 17 08:20:22 2025 +0200 Use OutputDevice::ScopedPush in starmath Change-Id: I0aecb6fa26454a24408410f8e29a848963132207 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189801 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/starmath/source/dialog.cxx b/starmath/source/dialog.cxx index 4fa37ec72f37..447367d025b8 100644 --- a/starmath/source/dialog.cxx +++ b/starmath/source/dialog.cxx @@ -1094,7 +1094,7 @@ void SmShowSymbolSet::Paint(vcl::RenderContext& rRenderContext, const tools::Rec rRenderContext.SetBackground(Wallpaper(aBackgroundColor)); rRenderContext.SetTextColor(aTextColor); - rRenderContext.Push(vcl::PushFlags::MAPMODE); + auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::MAPMODE); // set MapUnit for which 'nLen' has been calculated rRenderContext.SetMapMode(MapMode(MapUnit::MapPixel)); @@ -1135,8 +1135,6 @@ void SmShowSymbolSet::Paint(vcl::RenderContext& rRenderContext, const tools::Rec rRenderContext.Invert(tools::Rectangle(OffsetPoint(aPoint), Size(nLen, nLen))); } - - rRenderContext.Pop(); } bool SmShowSymbolSet::MouseButtonDown(const MouseEvent& rMEvt) diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx index a4217d286be6..7abf5f4fc97f 100644 --- a/starmath/source/document.cxx +++ b/starmath/source/document.cxx @@ -262,7 +262,7 @@ void SmDocShell::ArrangeFormula() const SmFormat &rFormat = GetFormat(); mpTree->Prepare(rFormat, *this, 0); - pOutDev->Push(vcl::PushFlags::TEXTLAYOUTMODE | vcl::PushFlags::TEXTLANGUAGE); + auto popIt = pOutDev->ScopedPush(vcl::PushFlags::TEXTLAYOUTMODE | vcl::PushFlags::TEXTLANGUAGE); // We want the device to always be LTR, we handle RTL formulas ourselves. bool bOldRTL = pOutDev->IsRTLEnabled(); @@ -279,7 +279,6 @@ void SmDocShell::ArrangeFormula() mpTree->Arrange(*pOutDev, rFormat); pOutDev->EnableRTL(bOldRTL); - pOutDev->Pop(); SetFormulaArranged(true); @@ -1434,7 +1433,7 @@ void SmDocShell::Impl_Print(OutputDevice& rOutDev, const SmPrintUIOptions& rPrin const sal_uInt16 nZoomFactor = static_cast<sal_uInt16>(rPrintUIOptions.getIntValue(PRTUIOPT_PRINT_SCALE, 100)); - rOutDev.Push(); + auto popIt = rOutDev.ScopedPush(); rOutDev.SetLineColor(COL_BLACK); // output text on top @@ -1564,8 +1563,6 @@ void SmDocShell::Impl_Print(OutputDevice& rOutDev, const SmPrintUIOptions& rPrin rOutDev.SetClipRegion(vcl::Region(aOutRect)); DrawFormula(rOutDev, aPos); rOutDev.SetClipRegion(); - - rOutDev.Pop(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx index 7f8c47d661c3..1df15d9f3cd9 100644 --- a/starmath/source/node.cxx +++ b/starmath/source/node.cxx @@ -2100,10 +2100,9 @@ void SmMathSymbolNode::AdaptToY(OutputDevice &rDev, tools::Long nHeight) // to determine the font width in order to keep it if (aFntSize.Width() == 0) { - rDev.Push(vcl::PushFlags::FONT | vcl::PushFlags::MAPMODE); + auto popIt = rDev.ScopedPush(vcl::PushFlags::FONT | vcl::PushFlags::MAPMODE); rDev.SetFont(GetFont()); aFntSize.setWidth( rDev.GetFontMetric().GetFontSize().Width() ); - rDev.Pop(); } OSL_ENSURE(aFntSize.Width() != 0, "Sm: "); diff --git a/starmath/source/rect.cxx b/starmath/source/rect.cxx index 496501e878df..4902ca63792b 100644 --- a/starmath/source/rect.cxx +++ b/starmath/source/rect.cxx @@ -56,7 +56,7 @@ bool SmGetGlyphBoundRect(const vcl::RenderContext &rDev, const FontMetric aDevFM (rDev.GetFontMetric()); - pGlyphDev->Push(vcl::PushFlags::FONT | vcl::PushFlags::MAPMODE); + auto popIt = pGlyphDev->ScopedPush(vcl::PushFlags::FONT | vcl::PushFlags::MAPMODE); vcl::Font aFnt(rDev.GetFont()); aFnt.SetAlignment(ALIGN_TOP); @@ -102,8 +102,6 @@ bool SmGetGlyphBoundRect(const vcl::RenderContext &rDev, tools::Long nDelta = aDevFM.GetAscent() - pGlyphDev->GetFontMetric().GetAscent() * nScaleFactor; aResult.Move(0, nDelta); - pGlyphDev->Pop(); - rRect = aResult; return bSuccess; } @@ -203,7 +201,7 @@ SmRect::SmRect(const OutputDevice &rDev, const SmFormat *pFormat, { OutputDevice *pWindow = Application::GetDefaultDevice(); - pWindow->Push(vcl::PushFlags::MAPMODE | vcl::PushFlags::FONT); + auto popIt = pWindow->ScopedPush(vcl::PushFlags::MAPMODE | vcl::PushFlags::FONT); pWindow->SetMapMode(rDev.GetMapMode()); pWindow->SetFont(rDev.GetFontMetric()); @@ -215,8 +213,6 @@ SmRect::SmRect(const OutputDevice &rDev, const SmFormat *pFormat, nDelta = nFontHeight * 8 / 43; } SetTop(GetTop() - nDelta); - - pWindow->Pop(); } // get GlyphBoundRect diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx index 6768a83769e5..9f2b5fad3da2 100644 --- a/starmath/source/visitors.cxx +++ b/starmath/source/visitors.cxx @@ -169,12 +169,10 @@ void SmCaretLinesVisitor::DoIt() if (!maPos.IsValid()) return; - //Save device state - mrDev.Push( vcl::PushFlags::FONT | vcl::PushFlags::MAPMODE | vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR | vcl::PushFlags::TEXTCOLOR ); + //Save and eventually restore device state + auto popIt = mrDev.ScopedPush(vcl::PushFlags::FONT | vcl::PushFlags::MAPMODE | vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR | vcl::PushFlags::TEXTCOLOR); maPos.pSelectedNode->Accept( this ); - //Restore device state - mrDev.Pop( ); } void SmCaretLinesVisitor::Visit( SmTextNode* pNode ) @@ -264,8 +262,8 @@ void SmCaretDrawingVisitor::ProcessUnderline(Point from, Point to) void SmCaretPos2LineVisitor::Visit( SmTextNode* pNode ) { - //Save device state - mpDev->Push( vcl::PushFlags::FONT | vcl::PushFlags::TEXTCOLOR ); + //Save and eventually restore device state + auto popIt = mpDev->ScopedPush(vcl::PushFlags::FONT | vcl::PushFlags::TEXTCOLOR); tools::Long i = maPos.nIndex; @@ -277,9 +275,6 @@ void SmCaretPos2LineVisitor::Visit( SmTextNode* pNode ) tools::Long height = pNode->GetHeight( ); maLine = SmCaretLine( left, top, height ); - - //Restore device state - mpDev->Pop( ); } void SmCaretPos2LineVisitor::DefaultVisit( SmNode* pNode ) @@ -1795,17 +1790,14 @@ SmSelectionDrawingVisitor::SmSelectionDrawingVisitor( OutputDevice& rDevice, SmN tools::Rectangle aSelectionArea = GetSelection() + rOffset; - //Save device state - rDevice.Push( vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR ); + //Save and eventually restore device state + auto popIt = rDevice.ScopedPush(vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR); //Change colors rDevice.SetLineColor( ); rDevice.SetFillColor( COL_LIGHTGRAY ); //Draw rectangle rDevice.DrawRect( aSelectionArea ); - - //Restore device state - rDevice.Pop( ); } // SmSelectionRectanglesVisitor @@ -1843,7 +1835,7 @@ void SmSelectionRectanglesVisitor::Visit( SmTextNode* pNode ) if( !pNode->IsSelected()) return; - mrDev.Push( vcl::PushFlags::TEXTCOLOR | vcl::PushFlags::FONT ); + auto popIt = mrDev.ScopedPush(vcl::PushFlags::TEXTCOLOR | vcl::PushFlags::FONT); mrDev.SetFont( pNode->GetFont( ) ); Point Position = pNode->GetTopLeft( ); @@ -1854,8 +1846,6 @@ void SmSelectionRectanglesVisitor::Visit( SmTextNode* pNode ) tools::Rectangle rect( left, top, right, bottom ); ExtendSelectionArea( rect ); - - mrDev.Pop( ); } // SmNodeToTextVisitor