Bug 151544 - “Lines per page" in Grid Mode is not accurately applied (always 1 line less than set in page style dalog)
Summary: “Lines per page" in Grid Mode is not accurately applied (always 1 line less t...
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Kevin Suo
URL:
Whiteboard: target:7.5.0 target:7.4.4
Keywords:
Depends on:
Blocks: Text-Grid
  Show dependency treegraph
 
Reported: 2022-10-15 15:44 UTC by Kevin Suo
Modified: 2022-11-23 14:20 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
text-grid-test.odt (22.67 KB, application/vnd.oasis.opendocument.text)
2022-10-15 15:44 UTC, Kevin Suo
Details
screenshot showing spaces btw lines.pdf (187.59 KB, application/pdf)
2022-11-02 02:07 UTC, Kevin Suo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Suo 2022-10-15 15:44:30 UTC
Created attachment 183063 [details]
text-grid-test.odt

Steps to Reproduce:
1. New Writer, make sure the option named "Use square page mode for text grid" in "Tools - Options - LibreOffice Writer - General" is unchecked.
2. Format > Page Style > Text Grid, check the "Grid (lines and characters)" option and "Snap to Characters" option.
3. In the "Grid Layout" section, input 22 for "lines per page" and 28 for characters per line".
4. Click OK, then fill the full page with Chinese characters (e.g. copy paste the character "某" to fill the whole page).

Current Result:
There are 21 lines per page.

Expected Result:
There should be 22 lines per page, as set in the Page Style settings.

Version: 7.4.3.0.0+ / LibreOffice Community
Build ID: ee37514eb64b2c431c2f51e7f70d933913217cd6
CPU threads: 8; OS: Linux 5.19; UI render: default; VCL: gtk3
Locale: zh-CN (zh_CN.UTF-8); UI: en-US
Calc: threaded

Also in 7.3.8.0+
Comment 1 Dieter 2022-10-31 06:31:25 UTC
I confirm it with
Version: 7.4.2.2 (x64) / LibreOffice Community
Build ID: 1726efbecd001a1fe871cba3e00e71283688f34d
CPU threads: 4; OS: Windows 10.0 Build 19044; UI render: Skia/Raster; VCL: win
Locale: de-DE (de_DE); UI: en-GB
Calc: CL

Steps
1. Make sure, that "Asian" is set in Tools -> options -> Language Settings -> Languages
2. Open attachment 183063 [details]
3. Count lines per page (are 21; should be 22)
4. Change lines per page in grid tap of page style dialog and recount

Actual result
There is always one line missing on a page. If you choose one line per page, LO freezes

Expected result
Number of lines per page, should be the same as set in the Page Style settings.
Comment 2 Kevin Suo 2022-10-31 06:52:45 UTC Comment hidden (obsolete)
Comment 3 Kevin Suo 2022-10-31 15:45:39 UTC
I could not reproduce the crash, although there seems to be a hang.

Adding Mark Hung to cc as he had worked on bug 141957.
Comment 4 Kevin Suo 2022-10-31 16:03:50 UTC
Also reproducible in the "oldest" version of the "releases" bibisect repo, thus this is inherited from OOo.
Comment 5 Kevin Suo 2022-11-02 02:00:31 UTC
I did some debugging.

In function SwTextGridPage::UpdatePageSize(const SfxItemSet& rSet), currently when calculating the page height (net of the header, footer, top space, bottom space etc) (strictly speaking it is the height of the text area, should not be named "page size"), it used the following code:
    sal_Int32 nValue1 = rSize.GetSize().Height() - nDistanceUL -
            rBox.GetDistance(SvxBoxItemLine::TOP) -
                                rBox.GetDistance(SvxBoxItemLine::BOTTOM);

When I change this to:
    sal_Int32 nValue1 = rSize.GetSize().Height() - nDistanceUL -
            rBox.GetDistance(SvxBoxItemLine::TOP) -
                                rBox.GetDistance(SvxBoxItemLine::BOTTOM) - 425;

(i.e. deducting the calculated text area height by 425 twips), then if I set the page grid to 22 lines then there would be 22 lines perfectly shown on the page.

As a result, I guess the problem may be that when calculating the text area height it did not take into account the spaces between the lines, as when you enlarge the page you will see that there are spaces between each lines. The exact additional spaces to be deducted should be the height of each space multiplied by the lines to be displayed on the page.
Comment 7 Kevin Suo 2022-11-02 02:07:39 UTC
Created attachment 183369 [details]
screenshot showing spaces btw lines.pdf
Comment 8 Kevin Suo 2022-11-03 15:41:04 UTC
I think I get it. The tine space above each line is the "ruby" which should only be there when in squared page mode.

The code seems to be trying to set the ruby height to zero in line
https://opengrok.libreoffice.org/xref/core/sw/source/ui/misc/pggrid.cxx?r=384167ab#388

but there seems to be a conversion loss, thus each line finally contains a tiny ruby height, which makes the page not able to hold the number of lines set on the UI.
Comment 9 Commit Notification 2022-11-09 20:25:22 UTC
Kevin Suo committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/875c27dc7975de9b007a215fe1d6f171b4ef090e

tdf#151544: Page grid: ruby height should be zero when not in square page mode

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 10 Kevin Suo 2022-11-10 01:58:54 UTC
This is now fixed on master.
Comment 11 Commit Notification 2022-11-10 19:54:29 UTC
Kevin Suo committed a patch related to this issue.
It has been pushed to "libreoffice-7-4":

https://git.libreoffice.org/core/commit/e6b070d3da4a3be84fa84d0b8c447d58be6d8923

tdf#151544: Page grid: ruby height should be zero when not in square page mode

It will be available in 7.4.4.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 12 Dieter 2022-11-23 11:09:01 UTC
VERIFIED with

Version: 7.5.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 55cd20e6228a06836285c14ca6726adb1bb4ffcb
CPU threads: 4; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: en-US (de_DE); UI: en-GB
Calc: CL threaded

Kevin, thanks for fixing it!

Additional information:
If you open attachment 183063 [details] it still has only 21 lines (expected 22). But if you change number of lines in  page style dialog, you always get the correct result. So I would think, it is fixed.
Comment 13 Kevin Suo 2022-11-23 14:20:33 UTC
> If you open attachment 183063 [details] it still has only 21 lines (expected 22). But if you change number of lines in  page style dialog.
That would be because the old line-space settings were already written to the document. This will also be good as this way it would not break old document.