Bug 151114 - UI: Wrong font used for rendering in Style Preview
Summary: UI: Wrong font used for rendering in Style Preview
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.5.0.0 alpha0+
Hardware: All All
: medium normal
Assignee: ⁨خالد حسني⁩
URL:
Whiteboard: target:7.5.0
Keywords: bibisected, bisected, regression
Depends on:
Blocks:
 
Reported: 2022-09-22 04:26 UTC by Kevin Suo
Modified: 2022-10-01 11:49 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
test.odt (10.39 KB, application/vnd.oasis.opendocument.text)
2022-09-22 04:26 UTC, Kevin Suo
Details
screenshots.pdf (204.62 KB, application/pdf)
2022-09-22 04:27 UTC, Kevin Suo
Details
screenshot after the fix as of September 30 2022 (167.97 KB, image/png)
2022-09-30 13:37 UTC, Kevin Suo
Details
screenshot with proposed gerrit change 140811 (125.27 KB, image/png)
2022-10-01 03:10 UTC, Kevin Suo
Details
screenshot with proposed gerrit change 140811 (style applied) (196.91 KB, image/png)
2022-10-01 05:34 UTC, Kevin Suo
Details
screenshot with proposed gerrit change 140811 (12pt for western and 32pt for CJK) (176.53 KB, image/png)
2022-10-01 05:47 UTC, Kevin Suo
Details
Screenshot comparing sidebar preview with font tab one (1.26 MB, image/png)
2022-10-01 06:04 UTC, ⁨خالد حسني⁩
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Suo 2022-09-22 04:26:12 UTC
Created attachment 182608 [details]
test.odt

Steps to Reproduce:
1. Switch to English UI.
2. Open the attached test.odt.
3. Observe the font used for Style Preview (in Styles sidebar) for the style named "Title". Compare it with the contents shown in the document.

Current Result:
It seems that the font used for rendering the style preview is not the one used in the style (i.e. Liberation Sans).

Expected Result:
The font used for style preview should be the same as the ones set in the style (for this test document, it is Liberation Sans for western and Noto Sans CJK SC for Asian).

Broken in:
Version: 7.5.0.0.alpha0+ / LibreOffice Community
Build ID: 18f4fc547a8c055afdaec4aad69c9fea387696c3
CPU threads: 8; OS: Linux 5.19; UI render: default; VCL: gtk3
Locale: zh-CN (zh_CN.UTF-8); UI: en-US
Build Platform: Fedora34@X64, Branch:master, bibisect-linux-64-7.4-CN
Calc: threaded

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

Fedora 36 Wayland.
Comment 1 Kevin Suo 2022-09-22 04:27:13 UTC
Created attachment 182609 [details]
screenshots.pdf

This is the screenshots shown the current bad behaviour on master and the good behaviour in 7.4.3+.
Comment 2 Kevin Suo 2022-09-22 09:55:20 UTC
Bug introduced by:

commit 0483fbd1d05d74c394d9274bdee77b3b2aebb495
Author: Khaled Hosny <khaled@aliftype.com>
Date:   Sun Aug 21 01:49:57 2022 +0200

    tdf#87535: Preview styles using CTL/CJK fonts in the sidebar

and

commit 044fc5c8b225732d57970d3bf0720c13a5a9e0a4
Author: Khaled Hosny <khaled@aliftype.com>
Date:   Sun Aug 21 06:08:01 2022 +0200

    tdf#87535: Preview styles using CTL/CJK fonts in the styles menu
    
Adding cc to Khaled Hosny: could you please take a look?

In case a style name is "MyStyle 中文" (i.e., a mixture of western and CJK chars), the preview should use Western for the western part and CJK font for the CJK part.

For the default (localized) styles (e.e. Title, Heading 1, etc) appears as English if the UI is in English and Chinese if I switch to Chinese UI, the font used to render the preview should also change.
Comment 3 Kevin Suo 2022-09-22 09:56:20 UTC Comment hidden (obsolete)
Comment 4 ⁨خالد حسني⁩ 2022-09-22 13:21:32 UTC
The font is correct, but it is incorrectly scaled. Looks like something went wrong with the code that scales the text to fit the height.
Comment 5 Commit Notification 2022-09-24 21:41:41 UTC
Khaled Hosny committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/943177e0f8074753db25d9a56d15f8010a755ffc

tdf#151114: Fix swapped width and height

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 6 Kevin Suo 2022-09-30 13:37:43 UTC
Created attachment 182753 [details]
screenshot after the fix as of September 30 2022

Sorry to set this to reopen, but there seems to be another problem and may be related to the fix to this bug.

When the style names are a mixture of CJK and Western characters, the western characters are rendered at a position upper than then CJK text.

See the attached screenshot. The left side shows how it looks like in 7.4 version, and the right-side shows how it looks like on current master. For instance, for the 4th style (named "标题1"), the Chinese characters "标题" and the western character "1" are aligned to the same vertical position in version 7.4, but on current master the western character "1" is aligned slightly above the character, which causes the "1" seems like a "superscript".
Comment 7 Kevin Suo 2022-10-01 03:10:47 UTC
Created attachment 182761 [details]
screenshot with proposed gerrit change 140811

With the patch in https://gerrit.libreoffice.org/c/core/+/140811, it looks much better now, but still not perfect, see the attached screenshot. The left side is in 7.4 version and the right side is on current master with the patch.

For instance, in 7.4 version, the Character Style named "Internet 链接" (i.e. Internet Links) has the same base line for "Internet" and for "链接", so that the underline is shown as one continuous segment. However, on with this patch, the baseline for "Internet" is slightly above the baseline for "链接", thus the continuous underline becomes broken between the two segments.
Comment 8 ⁨خالد حسني⁩ 2022-10-01 03:59:34 UTC
(In reply to Kevin Suo from comment #7)
> Created attachment 182761 [details]
> screenshot with proposed gerrit change 140811
> 
> With the patch in https://gerrit.libreoffice.org/c/core/+/140811, it looks
> much better now, but still not perfect, see the attached screenshot. The
> left side is in 7.4 version and the right side is on current master with the
> patch.
> 
> For instance, in 7.4 version, the Character Style named "Internet 链接" (i.e.
> Internet Links) has the same base line for "Internet" and for "链接", so that
> the underline is shown as one continuous segment. However, on with this
> patch, the baseline for "Internet" is slightly above the baseline for "链接",
> thus the continuous underline becomes broken between the two segments.

Can you show me the Western and Asian fonts used in these styles?
Comment 9 ⁨خالد حسني⁩ 2022-10-01 04:01:04 UTC
(In reply to خالد حسني from comment #8)
> (In reply to Kevin Suo from comment #7)
> > Created attachment 182761 [details]
> > screenshot with proposed gerrit change 140811
> > 
> > With the patch in https://gerrit.libreoffice.org/c/core/+/140811, it looks
> > much better now, but still not perfect, see the attached screenshot. The
> > left side is in 7.4 version and the right side is on current master with the
> > patch.
> > 
> > For instance, in 7.4 version, the Character Style named "Internet 链接" (i.e.
> > Internet Links) has the same base line for "Internet" and for "链接", so that
> > the underline is shown as one continuous segment. However, on with this
> > patch, the baseline for "Internet" is slightly above the baseline for "链接",
> > thus the continuous underline becomes broken between the two segments.
> 
> Can you show me the Western and Asian fonts used in these styles?

Also how this same text looks like inside the document with the affected style applied to it.
Comment 10 Kevin Suo 2022-10-01 05:34:22 UTC
Created attachment 182763 [details]
screenshot with proposed gerrit change 140811 (style applied)

> Can you show me the Western and Asian fonts used in these styles?

I used Liberation Serif for Western and Noto Serif CJK SC for CJK. In the attached screenshot I have changed the font-size (within the Style) to 32pt for easier observation.

> Also how this same text looks like inside the document with the affected style applied to it.

The rendering within the text body looks good. The rendering in style preview is different.
Comment 11 Kevin Suo 2022-10-01 05:39:47 UTC
> I used ... Noto Serif CJK SC for CJK
The font is freely available at:
https://github.com/googlefonts/noto-cjk/tree/main/Serif#downloading-noto-serif-cjk

P.S. The suffix "SC" stands for "Simplified Chinese".
Comment 12 Kevin Suo 2022-10-01 05:47:22 UTC
Created attachment 182764 [details]
screenshot with proposed gerrit change 140811 (12pt for western and 32pt for CJK)

The flaw is more visible if I set different font size for Western and CJK, respectively. In this attached screenshot, I used font size of 12pt for Western and 32pt for CJK.
Comment 13 Kevin Suo 2022-10-01 05:56:38 UTC
One thing I noticed is that, in 7.4 version, no matter what respective font size I set for Western and CJK, in the style preview it always uses the font size for Western. E.g. when I set font size 12pt for Western and 32pt for CJK, in style preview it uses 12pt also for CJK characters. Maybe that is why the baseline looks the same in version 7.4?
Comment 14 ⁨خالد حسني⁩ 2022-10-01 06:04:21 UTC
Created attachment 182765 [details]
Screenshot comparing sidebar preview with font tab one

(In reply to Kevin Suo from comment #13)
> One thing I noticed is that, in 7.4 version, no matter what respective font
> size I set for Western and CJK, in the style preview it always uses the font
> size for Western. E.g. when I set font size 12pt for Western and 32pt for
> CJK, in style preview it uses 12pt also for CJK characters. Maybe that is
> why the baseline looks the same in version 7.4?

Yes, this is what bug 87535 was about; the Western font was always used for the preview text.

I get the different underline position if I use different font sizes and indeed its looks different from the text in the document, but it looks the same as the preview in the font tab (which is basically what I tried to replicate), so I think it is a general issue with the preview and should be reported separately. It is likely that Writer and the preview use different code paths that handle underline slightly differently.
Comment 15 Commit Notification 2022-10-01 11:30:40 UTC
Khaled Hosny committed a patch related to this issue.
It has been pushed to "master":

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

tdf#151114: Improve styles preview alignment

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.