Bug 104930 - please handle 'hang' baseline feature of OpenType fonts
Summary: please handle 'hang' baseline feature of OpenType fonts
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
5.2.3.1 rc
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard: target:7.4.0
Keywords:
: 106527 (view as bug list)
Depends on: HarfBuzz
Blocks: Font-Rendering 149336 149361
  Show dependency treegraph
 
Reported: 2016-12-26 13:41 UTC by Elie Roux
Modified: 2022-05-29 09:18 UTC (History)
10 users (show)

See Also:
Crash report or crash signature:


Attachments
image showing good/wrong result (36.44 KB, image/png)
2016-12-26 13:42 UTC, Elie Roux
Details
document with fonts showing the problem (11.95 KB, application/zip)
2016-12-26 13:44 UTC, Elie Roux
Details
screenshot (30.32 KB, image/png)
2016-12-26 23:31 UTC, Julien Nabet
Details
NotoSansTibetan with hang BASE feature added (739.61 KB, application/x-font-ttf)
2017-02-12 11:40 UTC, Elie Roux
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Elie Roux 2016-12-26 13:41:22 UTC
Description:
LibreOffice doesn't handle the "hang" baseline OpenType property, documented on

https://www.microsoft.com/typography/otspec/baselinetags.htm

This feature is necessary to typeset Tibetan correctly: when using different sizes, the letters should be vertically aligned on the upper stroke. See the attachments for an example.

Steps to Reproduce:
1. type Tibetan text
2. change font size of a part of the text
3. experience sadness and disappointment

Actual Results:  
see self-explanatory attached image

Expected Results:
see self-explanatory attached image


Reproducible: Always

User Profile Reset: No

Additional Info:


User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0
Comment 1 Elie Roux 2016-12-26 13:42:13 UTC
Created attachment 129945 [details]
image showing good/wrong result
Comment 2 Elie Roux 2016-12-26 13:44:17 UTC
Created attachment 129946 [details]
document with fonts showing the problem
Comment 3 Elie Roux 2016-12-26 13:46:25 UTC
Note that the attachments show that with a baseline at 0, there is no experience of the problem (hang is ignored, but LibreOffice seems to align things correctly. But not all Tibetan fonts have a baseline at 0, NotoSansTibetan doesn't for instance.

NotoSansTibetan doesn't use the "hang" feature, I've reported the bug on

https://github.com/googlei18n/noto-fonts/issues/814
Comment 4 Julien Nabet 2016-12-26 23:31:21 UTC
Created attachment 129954 [details]
screenshot

On pc Debian x86-64 with master sources updated tody, I could reproduce this.
But the result is slightly different.

Khaled: thought you might be interested in this one.
Comment 5 Xisco Faulí 2017-01-12 12:03:34 UTC
Adding Khaled Hosny for advice
Comment 6 ⁨خالد حسني⁩ 2017-01-15 08:53:57 UTC
It is a valid enhancement request, but I don’t know if it is practical or not.

There does not seem to be many applications that support BASE table (I couldn’t find any actually, though I remember vaguely reading somewhere that some Adobe products support “ideo” tag but not any other tag) and the spec (https://www.microsoft.com/typography/otspec/base.htm) does not seem to be well defined (as usual with OpenType). Taking the 3B example from the spec and trying to apply it to the case here (assuming purely Tibetan text for the sake of simplicity); the hanging baseline is 1500 and assuming a font with 1000 UPEM that would be 15pt for 10pt text. All good so far, but the main use case here is text with different font sizes, so from which font size do we get the baseline value and based on what criteria? Taking it from each font size separately means we will end up with different values and the original issue is still unfixed. Now added different scripts on the same line to the mix and things get wildly. The spec talks about the “dominant run” where everything is relative to it, but nowhere it defines it.

Someone needs to figure this out and come with clear spec or at least some other application that can be checked against in order to be able to implement this.
Comment 7 Elie Roux 2017-01-15 09:24:11 UTC
Thanks for your input Khaled, I agree that the behavior should be defined more consensually for this to be implemented. I have some contacts at the Dzongkha Development Commission (DDC) I can ask about what they think the most natural result would be, but none at Microsoft or Adobe... Do you think you could indicate me some persons to talk to about this issue? (maybe in a private mail? you can find my address on https://github.com/eroux/) Thank you!
Comment 8 ⁨خالد حسني⁩ 2017-01-15 09:51:30 UTC
I don’t have any personal contacts, but you might get some luck asking on the OpenType mailing list (https://www.microsoft.com/typography/otspec/otlist.htm).
Comment 9 Elie Roux 2017-01-15 10:03:10 UTC
Thanks! I'll do that and keep you informed
Comment 10 Elie Roux 2017-01-15 19:48:39 UTC
Khaled, before I send it to the OpenType list (my subscription is pending), would you have a few moments to tell me what you think of

https://github.com/eroux/otf-base-hang-tibt/blob/master/proposed-algorithm.md

?
Comment 11 Elie Roux 2017-02-12 11:40:09 UTC
Created attachment 131129 [details]
NotoSansTibetan with hang BASE feature added

Modified version of NotoSansTibetan including the BASE table. An fea version of the included BASE table is:

table BASE {
  HorizAxis.BaseTagList hang;
  HorizAxis.BaseScriptList
	DFLT hang 1389,
	tibt hang 1389;
} BASE;
Comment 12 Elie Roux 2017-02-15 13:30:55 UTC
I've just received a message from Office Consumer Service stating:

"
Microsoft currently supports 7 baseline tags, including "hang".
"

I'll try to find a way to test.
Comment 13 Elie Roux 2017-02-21 08:11:12 UTC
Commenting the new "Blocks #89870" tag:

I don't really understand why this bug would block anything related to Harfbuzz use, there's no code to support the BASE table in LO, independently of the Layout Engine.

A few updates:

Apple products (Page, etc.) are supposed to handle the BASE table as well as the 'bsln' feature for a long time, but it seems that the implementation is buggy, there is an internal Apple bug report to fix it. (no idea of the delay)

To support the BASE table in LO, the BASE table must first be exposed by Harfbuzz, it's not the case yet, but see

https://github.com/behdad/harfbuzz/issues/418
Comment 14 Buovjaga 2017-03-16 08:16:10 UTC
*** Bug 106527 has been marked as a duplicate of this bug. ***
Comment 15 Volga 2017-04-13 16:04:39 UTC Comment hidden (off-topic)
Comment 16 Volga 2017-08-28 17:47:31 UTC
Here is a simple sample of the behavior of aligning text with Alphabetic baseline and hanging baseline, especially if we get implementation based on 'BASE' table. 
http://tavmjong.free.fr/blog/wp-content/uploads/SYDNEY_2016/AlignIntroB-2FS.gif

This is found at Inkscape Planet.
Comment 17 Volga 2017-10-04 10:50:48 UTC
This baseline can be used for aligning drop initials for several Indic scripts as Devanagari, Bengali, Gujarati and similar. The W3C Working Draft Indic Layout Requirements has instruction for such usage. If we get support for 'BASE' table, we can making implementation based on this.

https://www.w3.org/TR/ilreq/#h_initial_letter_styling
Comment 18 Volga 2017-12-14 19:44:33 UTC
The usage of Tibetan hanging baseline can be found at https://www.unicode.org/wg2/docs/n4851-TangutAdditions.pdf page 11.
Comment 19 Volga 2018-02-27 19:09:52 UTC
HarfBuzz repository received a pull request recently:
https://github.com/harfbuzz/harfbuzz/pull/838
So we can waiting for new release to get support. but we need to know which new APIs added before we can make use of.
Comment 20 Volga 2018-03-08 01:26:41 UTC
It’s coming in HB 1.7.6.
Comment 21 Elie Roux 2018-03-08 08:53:57 UTC
Well, although it's really great news, I wouldn't be so optimistic: the review of the code to read the BASE table is not finished yet, and nothing is exposed to the public yet. The way to access the BASE feature needs to be through an API, and there is no API yet, not even any clue about what it will be. I think there will be at least a few month before a first draft of an API... and not much one can do in the mean time...
Comment 22 Volga 2018-03-09 04:59:10 UTC
OK, so we waiting for new version if HarfBuzz get complete support.
Comment 23 LibreTraining 2018-05-05 22:07:58 UTC
(In reply to Volga from comment #20)
> It’s coming in HB 1.7.6.

Harfbuzz 1.7.6 was released on 2018-03-07.
https://github.com/harfbuzz/harfbuzz/releases

So what is happening with this issue?
Comment 24 Elie Roux 2018-05-06 08:18:31 UTC
I'm not sure what wasn't clear in my previous comment, but here an attempt to clarify what the next steps are for this issue:

1. wait for harfbuzz to expose an API to get the BASE data for a font, in my experience that will probably take a few months, maybe a few years (not because it's complex, because it's super low priority)

2. use this new API to create some code to handle the BASE feature in LO
Comment 25 Elie Roux 2018-05-06 08:20:39 UTC
Sorry, an additional comment to make it crystal clear:

currently (even in the latest release or git version), harbuzz reads the BASE table, but doesn't provide an API to provide the data. These are two different things. Harbuzz 1.7.6 does *not* provide the API that is needed for this issue to be worked on on the LO side.
Comment 26 Volga 2018-11-01 13:28:12 UTC
Now we can focus on the following issue for this, HarfBuzz developers will bring desired APIs for baseline.
https://github.com/harfbuzz/harfbuzz/issues/1345
Comment 27 Volga 2018-11-12 02:45:15 UTC
HarfBuzz is already got support in 2.1.1.
https://github.com/harfbuzz/harfbuzz/commit/b8a78ce201608e9ac6d7f77447b2bbef6f09e9ff
Comment 28 Volga 2019-07-30 15:23:33 UTC
(In reply to Elie Roux from comment #13)
> To support the BASE table in LO, the BASE table must first be exposed by
> Harfbuzz, it's not the case yet, but see
> 
> https://github.com/behdad/harfbuzz/issues/418
This is fixed, so we are able to fix if HarfBuzz released a new version.
Comment 29 Volga 2019-08-20 00:34:42 UTC
It’s coming now in HarfBuzz version 2.6.0, so we can gain basic support for this, i.e. implament basic text alignment with BASE table, additionaly, we can add support for advanced control of this table, at least we can create new API set into LibreOffice BASIC to make use of the table.
Comment 30 Commit Notification 2022-05-10 13:02:50 UTC
Mark Hung committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/5f92e8cf3da6b5f66b6ef23219fcc91d2ad7c754

tdf#104930 Implement TextMetric::GetHangingBaseline.

It will be available in 7.4.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 31 Commit Notification 2022-05-12 23:33:05 UTC
Mark Hung committed a patch related to this issue.
It has been pushed to "master":

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

tdf#104930 aligning CTL text with hanging baseline.

It will be available in 7.4.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.