cui/inc/treeopt.hrc | 2 include/svx/optgrid.hxx | 5 + svx/source/dialog/optgrid.cxx | 21 +++++++- svx/uiconfig/ui/optgridpage.ui | 68 ++++++++++++++++++++++++++ sw/source/core/inc/pagefrm.hxx | 6 +- sw/source/core/layout/pagechg.cxx | 91 +++++++++++++++++++++++++++++++++++ sw/source/core/layout/paintfrm.cxx | 94 +++++++++++++++++++++++-------------- sw/source/core/text/porrst.cxx | 80 ++----------------------------- 8 files changed, 253 insertions(+), 114 deletions(-)
New commits: commit 2b4c7e0658cfa5c7e0de84e7c7222da43bcdeb20 Author: Tamás Zolnai <[email protected]> AuthorDate: Mon Dec 1 13:08:09 2025 +0100 Commit: Tamás Zolnai <[email protected]> CommitDate: Mon Dec 1 14:51:26 2025 +0100 Baseline grid options UI. Change-Id: I2e6208f36261f09026aa0d4fa6264ab0436224e1 diff --git a/cui/inc/treeopt.hrc b/cui/inc/treeopt.hrc index 0edd9c3aa06d..48c7b06b89b6 100644 --- a/cui/inc/treeopt.hrc +++ b/cui/inc/treeopt.hrc @@ -71,7 +71,7 @@ const std::pair<TranslateId, sal_uInt16> SID_SW_EDITOPTIONS_RES[] = { NC_("SID_SW_EDITOPTIONS_RES", "General"), RID_SW_TP_OPTLOAD_PAGE }, { NC_("SID_SW_EDITOPTIONS_RES", "View"), RID_SW_TP_CONTENT_OPT }, { NC_("SID_SW_EDITOPTIONS_RES", "Formatting Aids"), RID_SW_TP_OPTSHDWCRSR }, - { NC_("SID_SW_EDITOPTIONS_RES", "Grid"), RID_SVXPAGE_GRID }, + { NC_("SID_SW_EDITOPTIONS_RES", "Grids"), RID_SVXPAGE_GRID }, { NC_("SID_SW_EDITOPTIONS_RES", "Basic Fonts (Western)"),RID_SW_TP_STD_FONT }, { NC_("SID_SW_EDITOPTIONS_RES", "Basic Fonts (Asian)"),RID_SW_TP_STD_FONT_CJK }, { NC_("SID_SW_EDITOPTIONS_RES", "Basic Fonts (CTL)"), RID_SW_TP_STD_FONT_CTL }, diff --git a/include/svx/optgrid.hxx b/include/svx/optgrid.hxx index d6dc7310def2..fb032bc943f8 100644 --- a/include/svx/optgrid.hxx +++ b/include/svx/optgrid.hxx @@ -144,6 +144,11 @@ protected: std::unique_ptr<weld::MetricSpinButton> m_xMtrFldBezAngle; std::unique_ptr<weld::Widget> m_xMtrFldBezAngleImg; + // Baseline grid related items used only for Writer + std::unique_ptr<weld::Widget> m_xBaselineGrid; + std::unique_ptr<weld::CheckButton> m_xCbxBaselineGridVisible; + std::unique_ptr<weld::Widget> m_xCbxBaselineGridVisibleImg; + bool IsDrawMode() const { return m_Emode == DRAW_MODE; } DECL_LINK(ClickRotateHdl_Impl, weld::Toggleable&, void); diff --git a/svx/source/dialog/optgrid.cxx b/svx/source/dialog/optgrid.cxx index 3d3c07453824..fa1e3d38867c 100644 --- a/svx/source/dialog/optgrid.cxx +++ b/svx/source/dialog/optgrid.cxx @@ -136,6 +136,9 @@ SvxGridTabPage::SvxGridTabPage(weld::Container* pPage, weld::DialogController* p , m_xMtrFldAngle(m_xBuilder->weld_metric_spin_button(u"mtrfldangle"_ustr, FieldUnit::DEGREE)) , m_xMtrFldBezAngle(m_xBuilder->weld_metric_spin_button(u"mtrfldbezangle"_ustr, FieldUnit::DEGREE)) , m_xMtrFldBezAngleImg(m_xBuilder->weld_widget(u"lockmtrfldbezangle"_ustr)) + , m_xBaselineGrid(m_xBuilder->weld_widget(u"baselinegridframe"_ustr)) + , m_xCbxBaselineGridVisible(m_xBuilder->weld_check_button(u"baselinegridvisible"_ustr)) + , m_xCbxBaselineGridVisibleImg(m_xBuilder->weld_widget(u"lockbaselinegridvisible"_ustr)) { // This page requires exchange Support SetExchangeSupport(); @@ -175,6 +178,11 @@ SvxGridTabPage::SvxGridTabPage(weld::Container* pPage, weld::DialogController* p } } + if(m_Emode == WRITER_MODE) + { + m_xBaselineGrid->set_visible(true); + } + m_xCbxRotate->connect_toggled(LINK(this, SvxGridTabPage, ClickRotateHdl_Impl)); Link<weld::Toggleable&,void> aLink = LINK(this, SvxGridTabPage, ChangeGridsnapHdl_Impl); m_xCbxUseGridsnap->connect_toggled(aLink); @@ -204,7 +212,7 @@ OUString SvxGridTabPage::GetAllStrings() OUString sAllStrings; OUString labels[] = { u"label1"_ustr, u"label2"_ustr, u"flddrawx"_ustr, u"flddrawy"_ustr, u"label6"_ustr, u"label7"_ustr, u"label3"_ustr, - u"divisionx"_ustr, u"label4"_ustr, u"divisiony"_ustr, u"label5"_ustr, u"label8"_ustr, u"label9"_ustr }; + u"divisionx"_ustr, u"label4"_ustr, u"divisiony"_ustr, u"label5"_ustr, u"label8"_ustr, u"label9"_ustr, u"label10"_ustr }; for (const auto& label : labels) { @@ -214,7 +222,8 @@ OUString SvxGridTabPage::GetAllStrings() OUString checkButton[] = { u"usegridsnap"_ustr, u"gridvisible"_ustr, u"synchronize"_ustr, u"snaphelplines"_ustr, u"snapborder"_ustr, - u"snapframe"_ustr, u"snappoints"_ustr, u"ortho"_ustr, u"bigortho"_ustr, u"rotate"_ustr }; + u"snapframe"_ustr, u"snappoints"_ustr, u"ortho"_ustr, u"bigortho"_ustr, u"rotate"_ustr, + u"baselinegridvisible"_ustr }; for (const auto& check : checkButton) { @@ -399,6 +408,14 @@ void SvxGridTabPage::Reset( const SfxItemSet* rSet ) m_xNumFldDivisionY->set_sensitive(!bReadOnly); m_xNumFldDivisionYImg->set_visible(bReadOnly); + + + // TODO: read config readonly flag + bReadOnly = false; + const bool bActive = false; + m_xCbxBaselineGridVisible->set_active(bActive); + m_xCbxBaselineGridVisible->set_sensitive(!bReadOnly); + m_xCbxBaselineGridVisibleImg->set_visible(bReadOnly); } ChangeGridsnapHdl_Impl(*m_xCbxUseGridsnap); diff --git a/svx/uiconfig/ui/optgridpage.ui b/svx/uiconfig/ui/optgridpage.ui index d8a2ae2f39a0..7b3e0603e23a 100644 --- a/svx/uiconfig/ui/optgridpage.ui +++ b/svx/uiconfig/ui/optgridpage.ui @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.38.2 --> +<!-- Generated with glade 3.40.0 --> <interface domain="svx"> <requires lib="gtk+" version="3.24"/> <object class="GtkAdjustment" id="adjustment1"> @@ -960,6 +960,72 @@ <property name="position">2</property> </packing> </child> + <child> + <object class="GtkFrame" id="baselinegridframe"> + <property name="no-show-all">True</property> + <property name="can-focus">False</property> + <property name="label-xalign">0</property> + <property name="shadow-type">none</property> + <child> + <!-- n-columns=2 n-rows=1 --> + <object class="GtkGrid" id="grid10"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="margin-start">12</property> + <property name="margin-top">6</property> + <property name="hexpand">True</property> + <property name="row-spacing">6</property> + <child> + <object class="GtkCheckButton" id="baselinegridvisible"> + <property name="label" translatable="yes" context="optgridpage|baselinegridvisible">V_isible grid</property> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="receives-default">False</property> + <property name="use-underline">True</property> + <property name="draw-indicator">True</property> + <child internal-child="accessible"> + <object class="AtkObject" id="baselinegridvisible-atkobject"> + <property name="AtkObject::accessible-description" translatable="yes" context="extended_tip|baselinegridvisible">Specifies whether to display the baseline grid.</property> + </object> + </child> + </object> + <packing> + <property name="left-attach">1</property> + <property name="top-attach">0</property> + </packing> + </child> + <child> + <object class="GtkImage" id="lockbaselinegridvisible"> + <property name="can-focus">False</property> + <property name="no-show-all">True</property> + <property name="halign">center</property> + <property name="valign">center</property> + <property name="icon-name">res/lock.png</property> + </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">0</property> + </packing> + </child> + </object> + </child> + <child type="label"> + <object class="GtkLabel" id="label10"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="label" translatable="yes" context="optgridpage|label10">Baseline Grid</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">3</property> + </packing> + </child> <child internal-child="accessible"> <object class="AtkObject" id="OptGridPage-atkobject"> <property name="AtkObject::accessible-description" translatable="yes" context="extended_tip|OptGridPage">Specifies the settings for the configurable grid on your document pages. This grid helps you determine the exact position of your objects. You can also set this grid in line with the "magnetic" snap grid.</property> commit 3d6626a0145631adcc9bb3603ad111f644c7e315 Author: Tamás Zolnai <[email protected]> AuthorDate: Fri Nov 28 12:06:05 2025 +0100 Commit: Tamás Zolnai <[email protected]> CommitDate: Fri Nov 28 12:06:05 2025 +0100 Cleanup drawing code Change-Id: Id9e62d22c9a794916bff71f36d34ff7c4e04dfdc diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx index bc359d9bcf9f..06234ad3a8aa 100644 --- a/sw/source/core/inc/pagefrm.hxx +++ b/sw/source/core/inc/pagefrm.hxx @@ -194,7 +194,7 @@ public: void PaintGrid( OutputDevice const * pOut, SwRect const &rRect ) const; bool HasGrid() const { return m_bHasGrid; } - void PaintBaselineGrid( OutputDevice& rOututDevice, const SwRect &rDrawArea ) const; + void PaintBaselineGrid( OutputDevice& rOututDevice ) const; void PaintDecorators( ) const; virtual void PaintSubsidiaryLines( const SwPageFrame*, const SwRect& ) const override; diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx index 4f8ddd6fb091..c0ab186853c4 100644 --- a/sw/source/core/layout/paintfrm.cxx +++ b/sw/source/core/layout/paintfrm.cxx @@ -3489,7 +3489,7 @@ void SwRootFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect const& pPageView->DrawPageViewGrid(*pSh->GetOut(), aPaintRect.SVRect(), pSh->GetViewOptions()->GetTextGridColor() ); } - pPage->PaintBaselineGrid( *pSh->GetOut(), aPaintRect ); + pPage->PaintBaselineGrid( *pSh->GetOut() ); // #i68597# // moved paint post-process for DrawingLayer overlay here, see above @@ -6189,18 +6189,16 @@ void SwPageFrame::PaintGrid( OutputDevice const * pOut, SwRect const &rRect ) co } } -void SwPageFrame::PaintBaselineGrid( OutputDevice& rOututDevice, const SwRect &/*rDrawArea*/ ) const +void SwPageFrame::PaintBaselineGrid(OutputDevice& rOututDevice) const { - SAL_WARN("PaintBaselineGrid", "PaintBaselineGrid"); - // Not displayed for printing. - if(rOututDevice.GetOutDevType() == OUTDEV_PRINTER) + if (rOututDevice.GetOutDevType() == OUTDEV_PRINTER) { return; } - const SwPageDesc *pPageDesc = GetPageDesc(); - if( !pPageDesc ) + const SwPageDesc* pPageDesc = GetPageDesc(); + if (!pPageDesc) { return; } @@ -6208,59 +6206,60 @@ void SwPageFrame::PaintBaselineGrid( OutputDevice& rOututDevice, const SwRect &/ sal_uInt16 nLineHeight = 0; sal_uInt16 nLineOffset = 0; // If page line spacing is enabled we have the correct height / ascent values computed already. - if( pPageDesc->GetRegisterFormatColl() ) + if (pPageDesc->GetRegisterFormatColl()) { nLineHeight = pPageDesc->GetRegHeight(); nLineOffset = pPageDesc->GetRegAscent(); - SAL_WARN("PaintBaselineGrid", "nLineHeight: " << nLineHeight); - SAL_WARN("PaintBaselineGrid", "nLineOffset: " << nLineOffset); } else { // If page line spacing is disabled, use the standard paragraph style (Body text) to compute // height / ascent values. - const SwViewShell *pViewShell = getRootFrame()->GetCurrShell(); - if(!pViewShell) + const SwRootFrame* pRootFrame = getRootFrame(); + if (!pRootFrame) + { + return; + } + + const SwViewShell* pViewShell = pRootFrame->GetCurrShell(); + if (!pViewShell) { return; } SwDoc* pDoc = pViewShell->GetDoc(); - if(!pDoc) + if (!pDoc) { return; } - SwTextFormatColl* pFormat = pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool( RES_POOLCOLL_TEXT ); - if(!pFormat) + const SwTextFormatColl* pFormat + = pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_TEXT); + if (!pFormat) { return; } - SAL_WARN("PaintBaselineGrid", "found format"); ComputeRegister(pFormat, nLineHeight, nLineOffset); - SAL_WARN("PaintBaselineGrid", "nLineHeight: " << nLineHeight); - SAL_WARN("PaintBaselineGrid", "nLineOffset: " << nLineOffset); } const SwLayoutFrame* pBody = FindBodyCont(); - if( !pBody ) + if (!pBody) { return; } - SwRect aGridArea( pBody->getFramePrintArea() ); + SwRect aGridArea(pBody->getFramePrintArea()); aGridArea += pBody->getFrameArea().Pos(); aGridArea.AddTop(nLineOffset); - const Color aGridColor( COL_BLACK ); - const Color aOriginalLineColor( rOututDevice.GetLineColor() ); - rOututDevice.SetLineColor( aGridColor ); - - // TODO: use drawing area + const Color aGridColor(COL_BLACK); + const Color aOriginalLineColor(rOututDevice.GetLineColor()); + rOututDevice.SetLineColor(aGridColor); const tools::Long nLineWidth = aGridArea.Right() - aGridArea.Left(); - rOututDevice.DrawGrid( aGridArea.SVRect(), Size( nLineWidth, nLineHeight ), DrawGridFlags::HorzLines ); + rOututDevice.DrawGrid(aGridArea.SVRect(), Size(nLineWidth, nLineHeight), + DrawGridFlags::HorzLines); - rOututDevice.SetLineColor( aOriginalLineColor ); + rOututDevice.SetLineColor(aOriginalLineColor); } /** commit 03726918bfee3acf827c9549386f35bb7e4bb693 Author: Tamás Zolnai <[email protected]> AuthorDate: Thu Nov 27 13:59:25 2025 +0100 Commit: Tamás Zolnai <[email protected]> CommitDate: Thu Nov 27 14:27:39 2025 +0100 Reuse ComputeRegister() method. Change-Id: I310ada472359ab5952021b897425c09d66ed817d diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx index 8f34b6c8e991..4f8ddd6fb091 100644 --- a/sw/source/core/layout/paintfrm.cxx +++ b/sw/source/core/layout/paintfrm.cxx @@ -6251,7 +6251,6 @@ void SwPageFrame::PaintBaselineGrid( OutputDevice& rOututDevice, const SwRect &/ aGridArea += pBody->getFrameArea().Pos(); aGridArea.AddTop(nLineOffset); - // TODO: use custom color const Color aGridColor( COL_BLACK ); const Color aOriginalLineColor( rOututDevice.GetLineColor() ); rOututDevice.SetLineColor( aGridColor ); diff --git a/sw/source/core/text/porrst.cxx b/sw/source/core/text/porrst.cxx index 5d5146e2f8c1..a9f7213f6444 100644 --- a/sw/source/core/text/porrst.cxx +++ b/sw/source/core/text/porrst.cxx @@ -563,80 +563,12 @@ bool SwTextFrame::FillRegister( SwTwips& rRegStart, sal_uInt16& rRegDiff ) const SwTextFormatColl *pFormat = pDesc->GetRegisterFormatColl(); if( pFormat ) { - const SvxLineSpacingItem &rSpace = pFormat->GetLineSpacing(); - if( SvxLineSpaceRule::Fix == rSpace.GetLineSpaceRule() ) - { - rRegDiff = rSpace.GetLineHeight(); - pDesc->SetRegHeight( rRegDiff ); - pDesc->SetRegAscent( ( 4 * rRegDiff ) / 5 ); - } - else - { - SwViewShell *pSh = getRootFrame()->GetCurrShell(); - SwFontAccess aFontAccess( pFormat, pSh ); - SwFont aFnt( aFontAccess.Get()->GetFont() ); - - OutputDevice *pOut = nullptr; - if( !pSh || !pSh->GetViewOptions()->getBrowseMode() || - pSh->GetViewOptions()->IsPrtFormat() ) - pOut = GetDoc().getIDocumentDeviceAccess().getReferenceDevice( true ); - - if( pSh && !pOut ) - pOut = pSh->GetWin()->GetOutDev(); - - if( !pOut ) - pOut = Application::GetDefaultDevice(); - - MapMode aOldMap( pOut->GetMapMode() ); - pOut->SetMapMode( MapMode( MapUnit::MapTwip ) ); - - aFnt.ChgFnt( pSh, *pOut ); - rRegDiff = aFnt.GetHeight( pSh, *pOut ); - sal_uInt16 nNetHeight = rRegDiff; - - switch( rSpace.GetLineSpaceRule() ) - { - case SvxLineSpaceRule::Auto: - break; - case SvxLineSpaceRule::Min: - { - if( rRegDiff < rSpace.GetLineHeight() ) - rRegDiff = rSpace.GetLineHeight(); - break; - } - default: - OSL_FAIL( ": unknown LineSpaceRule" ); - } - switch( rSpace.GetInterLineSpaceRule() ) - { - case SvxInterLineSpaceRule::Off: - break; - case SvxInterLineSpaceRule::Prop: - { - tools::Long nTmp = rSpace.GetPropLineSpace(); - if( nTmp < 50 ) - nTmp = nTmp ? 50 : 100; - nTmp *= rRegDiff; - nTmp /= 100; - if( !nTmp ) - ++nTmp; - rRegDiff = o3tl::narrowing<sal_uInt16>(nTmp); - nNetHeight = rRegDiff; - break; - } - case SvxInterLineSpaceRule::Fix: - { - rRegDiff = rRegDiff + rSpace.GetInterLineSpace(); - nNetHeight = rRegDiff; - break; - } - default: OSL_FAIL( ": unknown InterLineSpaceRule" ); - } - pDesc->SetRegHeight( rRegDiff ); - pDesc->SetRegAscent( rRegDiff - nNetHeight + - aFnt.GetAscent( pSh, *pOut ) ); - pOut->SetMapMode( aOldMap ); - } + sal_uInt16 nRegHeight = 0; + sal_uInt16 nRegAscent = 0; + static_cast<const SwPageFrame*>(pFrame)->ComputeRegister(pFormat, nRegHeight, nRegAscent); + pDesc->SetRegHeight( nRegHeight ); + pDesc->SetRegAscent( nRegAscent ); + rRegDiff = pDesc->GetRegHeight(); } } const tools::Long nTmpDiff = pDesc->GetRegAscent() - rRegDiff; commit a864c929db01bd006090fd6d72efe33cd08b4816 Author: Tamás Zolnai <[email protected]> AuthorDate: Thu Nov 27 12:12:12 2025 +0100 Commit: Tamás Zolnai <[email protected]> CommitDate: Thu Nov 27 13:59:14 2025 +0100 Draw default baseline grid. Change-Id: Ib585bc727928f42a21e7254415d0190da7bca40f diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx index 542885c38c1d..bc359d9bcf9f 100644 --- a/sw/source/core/inc/pagefrm.hxx +++ b/sw/source/core/inc/pagefrm.hxx @@ -38,6 +38,7 @@ class SwAnchoredObject; namespace sw { class VirtPageNumHint; } +class SwTextFormatColl; enum class SwPageFrameInvFlags : sal_uInt8 { @@ -173,6 +174,9 @@ public: // Sends a Prepare() to all ContentFrames caused by a changed register template void PrepareRegisterChg(); + void ComputeRegister(const SwTextFormatColl* pFormat, sal_uInt16& rRegHeight, + sal_uInt16& rRegAscent) const; + // Appends a fly frame - the given one or a new one - at the page frame. // Needed for <Modify> and <MakeFrames> // - return value not needed any more diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx index 070b8b8ccf32..aa3303bfd394 100644 --- a/sw/source/core/layout/pagechg.cxx +++ b/sw/source/core/layout/pagechg.cxx @@ -46,6 +46,7 @@ #include <IDocumentDrawModelAccess.hxx> #include <IDocumentSettingAccess.hxx> #include <IDocumentFieldsAccess.hxx> +#include <IDocumentDeviceAccess.hxx> #include <dcontact.hxx> #include <hints.hxx> #include <FrameControlsManager.hxx> @@ -66,6 +67,8 @@ #include <calbck.hxx> #include <txtfly.hxx> #include <frmatr.hxx> +#include <swfntcch.hxx> +#include <vcl/svapp.hxx> using namespace ::com::sun::star; @@ -1072,6 +1075,94 @@ void SwPageFrame::PrepareRegisterChg() } } +void SwPageFrame::ComputeRegister(const SwTextFormatColl* pFormat, sal_uInt16& rRegHeight, + sal_uInt16& rRegAscent) const +{ + rRegHeight = 0; + rRegAscent = 0; + + if (!pFormat) + { + return; + } + + const SvxLineSpacingItem &rSpace = pFormat->GetLineSpacing(); + if( SvxLineSpaceRule::Fix == rSpace.GetLineSpaceRule() ) + { + rRegHeight = rSpace.GetLineHeight(); + rRegAscent = ( 4 * rRegHeight ) / 5; + } + else + { + SwViewShell *pSh = getRootFrame()->GetCurrShell(); + SwFontAccess aFontAccess( pFormat, pSh ); + SwFont aFnt( aFontAccess.Get()->GetFont() ); + + OutputDevice *pOut = nullptr; + if(pSh) + { + if( !pSh->GetViewOptions()->getBrowseMode() || + pSh->GetViewOptions()->IsPrtFormat() ) + pOut = pSh->GetDoc()->getIDocumentDeviceAccess().getReferenceDevice( true ); + + if(!pOut ) + pOut = pSh->GetWin()->GetOutDev(); + } + else + { + pOut = Application::GetDefaultDevice(); + } + + MapMode aOldMap( pOut->GetMapMode() ); + pOut->SetMapMode( MapMode( MapUnit::MapTwip ) ); + + aFnt.ChgFnt( pSh, *pOut ); + rRegHeight = aFnt.GetHeight( pSh, *pOut ); + sal_uInt16 nNetHeight = rRegHeight; + + switch( rSpace.GetLineSpaceRule() ) + { + case SvxLineSpaceRule::Auto: + break; + case SvxLineSpaceRule::Min: + { + if( rRegHeight < rSpace.GetLineHeight() ) + rRegHeight = rSpace.GetLineHeight(); + break; + } + default: + OSL_FAIL( ": unknown LineSpaceRule" ); + } + switch( rSpace.GetInterLineSpaceRule() ) + { + case SvxInterLineSpaceRule::Off: + break; + case SvxInterLineSpaceRule::Prop: + { + tools::Long nTmp = rSpace.GetPropLineSpace(); + if( nTmp < 50 ) + nTmp = nTmp ? 50 : 100; + nTmp *= rRegHeight; + nTmp /= 100; + if( !nTmp ) + ++nTmp; + rRegHeight = o3tl::narrowing<sal_uInt16>(nTmp); + nNetHeight = rRegHeight; + break; + } + case SvxInterLineSpaceRule::Fix: + { + rRegHeight = rRegHeight + rSpace.GetInterLineSpace(); + nNetHeight = rRegHeight; + break; + } + default: OSL_FAIL( ": unknown InterLineSpaceRule" ); + } + rRegAscent = rRegHeight - nNetHeight + aFnt.GetAscent( pSh, *pOut ); + pOut->SetMapMode( aOldMap ); + } +} + namespace sw { /// check if there's content on the page that requires it to exist diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx index 7dd094eb339f..8f34b6c8e991 100644 --- a/sw/source/core/layout/paintfrm.cxx +++ b/sw/source/core/layout/paintfrm.cxx @@ -81,6 +81,7 @@ #include <DocumentSettingManager.hxx> #include <IDocumentDeviceAccess.hxx> #include <IDocumentDrawModelAccess.hxx> +#include <IDocumentStylePoolAccess.hxx> #include <ndole.hxx> #include <PostItMgr.hxx> @@ -129,6 +130,7 @@ #include <ndtxt.hxx> #include <unotools/configmgr.hxx> #include <vcl/hatch.hxx> +#include <poolfmt.hxx> using namespace ::editeng; using namespace ::com::sun::star; @@ -6203,13 +6205,41 @@ void SwPageFrame::PaintBaselineGrid( OutputDevice& rOututDevice, const SwRect &/ return; } - const tools::Long nLineHeight = pPageDesc->GetRegHeight(); - const tools::Long nLineOffset = pPageDesc->GetRegAscent(); - if(nLineHeight == 0 || nLineOffset == 0) + sal_uInt16 nLineHeight = 0; + sal_uInt16 nLineOffset = 0; + // If page line spacing is enabled we have the correct height / ascent values computed already. + if( pPageDesc->GetRegisterFormatColl() ) { - return; + nLineHeight = pPageDesc->GetRegHeight(); + nLineOffset = pPageDesc->GetRegAscent(); + SAL_WARN("PaintBaselineGrid", "nLineHeight: " << nLineHeight); + SAL_WARN("PaintBaselineGrid", "nLineOffset: " << nLineOffset); + } + else + { + // If page line spacing is disabled, use the standard paragraph style (Body text) to compute + // height / ascent values. + const SwViewShell *pViewShell = getRootFrame()->GetCurrShell(); + if(!pViewShell) + { + return; + } + + SwDoc* pDoc = pViewShell->GetDoc(); + if(!pDoc) + { + return; + } + SwTextFormatColl* pFormat = pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool( RES_POOLCOLL_TEXT ); + if(!pFormat) + { + return; + } + SAL_WARN("PaintBaselineGrid", "found format"); + ComputeRegister(pFormat, nLineHeight, nLineOffset); + SAL_WARN("PaintBaselineGrid", "nLineHeight: " << nLineHeight); + SAL_WARN("PaintBaselineGrid", "nLineOffset: " << nLineOffset); } - // TODO: apply some default baseline grid, when page line spacing is not defined. const SwLayoutFrame* pBody = FindBodyCont(); if( !pBody ) @@ -6226,22 +6256,7 @@ void SwPageFrame::PaintBaselineGrid( OutputDevice& rOututDevice, const SwRect &/ const Color aOriginalLineColor( rOututDevice.GetLineColor() ); rOututDevice.SetLineColor( aGridColor ); - /*const tools::Long nStartX = aGridArea.Left(); - const tools::Long nLineWidth = aGridArea.Right() - aGridArea.Left(); - const tools::Long nLineCount = aGridArea.Height() / nLineHeight; - const tools::Long nLineThickness = 1; // TODO: use drawing area - for(int i = 0; i <= nLineCount; i++) - { - const tools::Long nPositionY = aGridArea.Top() + nLineHeight * i; - if(nPositionY >= rDrawArea.Top() - nLineThickness && - nPositionY <= rDrawArea.Bottom()) - { - const SwRect aLineRect( nStartX, nPositionY, nLineWidth, nLineThickness ); - PaintBorderLine(aLineRect, rDrawArea, this, &aGridColor); - } - - }*/ const tools::Long nLineWidth = aGridArea.Right() - aGridArea.Left(); rOututDevice.DrawGrid( aGridArea.SVRect(), Size( nLineWidth, nLineHeight ), DrawGridFlags::HorzLines ); commit 401cc5f1297a05b98a1aa56c66fb0a7c099ee8c2 Author: Tamás Zolnai <[email protected]> AuthorDate: Wed Nov 26 11:28:39 2025 +0100 Commit: Tamás Zolnai <[email protected]> CommitDate: Wed Nov 26 16:19:13 2025 +0100 Draw baseline Change-Id: I7df95d53ad8108b5947cc1f3765ad0ee9db2aa5b diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx index 4f6c61cfc1f9..7dd094eb339f 100644 --- a/sw/source/core/layout/paintfrm.cxx +++ b/sw/source/core/layout/paintfrm.cxx @@ -3487,6 +3487,8 @@ void SwRootFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect const& pPageView->DrawPageViewGrid(*pSh->GetOut(), aPaintRect.SVRect(), pSh->GetViewOptions()->GetTextGridColor() ); } + pPage->PaintBaselineGrid( *pSh->GetOut(), aPaintRect ); + // #i68597# // moved paint post-process for DrawingLayer overlay here, see above { @@ -6190,39 +6192,49 @@ void SwPageFrame::PaintBaselineGrid( OutputDevice& rOututDevice, const SwRect &/ SAL_WARN("PaintBaselineGrid", "PaintBaselineGrid"); // Not displayed for printing. - // TODO: do not render for PDF if(rOututDevice.GetOutDevType() == OUTDEV_PRINTER) { return; } - // TODO: use custom color - const Color aGridColor( COL_BLACK ); - const Color aOriginalLineColor( rOututDevice.GetLineColor() ); - rOututDevice.SetLineColor( aGridColor ); + const SwPageDesc *pPageDesc = GetPageDesc(); + if( !pPageDesc ) + { + return; + } - //GetPageDesc().GetRegHeight() + const tools::Long nLineHeight = pPageDesc->GetRegHeight(); + const tools::Long nLineOffset = pPageDesc->GetRegAscent(); + if(nLineHeight == 0 || nLineOffset == 0) + { + return; + } + // TODO: apply some default baseline grid, when page line spacing is not defined. const SwLayoutFrame* pBody = FindBodyCont(); if( !pBody ) + { return; + } SwRect aGridArea( pBody->getFramePrintArea() ); aGridArea += pBody->getFrameArea().Pos(); - // TODO: find proper line height - const tools::Long nLineHeight = 200; + aGridArea.AddTop(nLineOffset); - // TODO: find proper baseline (offset) + // TODO: use custom color + const Color aGridColor( COL_BLACK ); + const Color aOriginalLineColor( rOututDevice.GetLineColor() ); + rOututDevice.SetLineColor( aGridColor ); - //const tools::Long nStartX = aGridArea.Left(); + /*const tools::Long nStartX = aGridArea.Left(); const tools::Long nLineWidth = aGridArea.Right() - aGridArea.Left(); - //const tools::Long nLineCount = aGridArea.Height() / nLineHeight; - //const tools::Long nLineThickness = 1; + const tools::Long nLineCount = aGridArea.Height() / nLineHeight; + const tools::Long nLineThickness = 1; // TODO: use drawing area - /*for(int i = 1; i <= nLineCount / 2; i++) + for(int i = 0; i <= nLineCount; i++) { const tools::Long nPositionY = aGridArea.Top() + nLineHeight * i; - if(nPositionY >= rDrawArea.Top() + nLineThickness && + if(nPositionY >= rDrawArea.Top() - nLineThickness && nPositionY <= rDrawArea.Bottom()) { const SwRect aLineRect( nStartX, nPositionY, nLineWidth, nLineThickness ); @@ -6231,8 +6243,8 @@ void SwPageFrame::PaintBaselineGrid( OutputDevice& rOututDevice, const SwRect &/ }*/ - rOututDevice.DrawGrid( tools::Rectangle( aGridArea.Left(), aGridArea.Top() + nLineHeight, aGridArea.Right(), aGridArea.Bottom() ), - Size( nLineWidth, nLineHeight ), DrawGridFlags::HorzLines ); + const tools::Long nLineWidth = aGridArea.Right() - aGridArea.Left(); + rOututDevice.DrawGrid( aGridArea.SVRect(), Size( nLineWidth, nLineHeight ), DrawGridFlags::HorzLines ); rOututDevice.SetLineColor( aOriginalLineColor ); } @@ -6781,7 +6793,6 @@ void SwFrame::PaintBaBo( const SwRect& rRect, const SwPageFrame *pPage, if( IsPageFrame() ) { static_cast<const SwPageFrame*>(this)->PaintGrid( pOut, aRect ); - static_cast<const SwPageFrame*>(this)->PaintBaselineGrid( *pOut, aRect ); } PaintSwFrameShadowAndBorder(aRect, pPage, rAttrs);
