Description: Both “LibreOffice Writer” and “LibreOffice Impress” stores wrong font weight values. The saved document containing a font with all acceptable font weights (“Thin” (100); “Ultra Light, Extra Light” (200); “Light” (300); “Regular, Normal” (400); “Medium” (500); “Semi Bold, Demi Bold” (600); “Bold” (700); “Extra Bold, Ultra Bold” (800); “Heavy, Black” (900)) has wrong weight values in the “content.xml” file. The wrong values are for three font weights: - “Ultra Light, Extra Light” (200): fo:font-weight="150"; - “Light” (300): fo:font-weight="250"; - “Medium” (500): fo:font-weight="normal". So there is no surprise that some of the font weight information is lost on reopening the document. I have tried both the ODP or ODT file to unzip and replace these wrong values with the correct ones in the “content.xml” file. Zipped them and renamed. No luck. The fonts weights are not the same as they should be. Steps to Reproduce: 1. For writing text, use font which besides regular weight has at least Medium font weight. 2. Change some characters to Medium weight. 3. Save, close and open document. Actual Results: The Medium font weight is changed to Regular weight. Expected Results: The document should look as it was before closing. Reproducible: Always User Profile Reset: No Additional Info: Creates document with wrong weight values.
Created attachment 200542 [details] Document before saving
Created attachment 200543 [details] The document saved and opened
Please, where is the sample file? Please test in safe mode, Menu/Help/Restart in Safe Mode Please paste here the information on Menu/Help/About LibreOffice (There is an icon to copy)
$ ./soffice --version LibreOffice 25.2.2.2 7370d4be9e3cf6031a51beef54ff3bda878e3fac Version: 25.2.2.2 (X86_64) / LibreOffice Community Build ID: 7370d4be9e3cf6031a51beef54ff3bda878e3fac CPU threads: 4; OS: Linux 6.11; UI render: default; VCL: gtk3 Locale: lv-LV (lv_LV.utf8); UI: en-US Calc: threaded Safe-mode gives the same result.
Created attachment 200549 [details] PDF exported from newly created document.
Created attachment 200550 [details] PDF exported from re-opened document.
Created attachment 200551 [details] Saved example.
Created attachment 200552 [details] Saved example (safe mode)
LibreOffice 7.6.2.1 has already this bug. Not sure which version is earliest.
*** This bug has been marked as a duplicate of bug 35538 ***
Bug 35538 is a too broad issue, the issue here is more specific and can potentially be fixed independent of bug 35538.
This appears to be caused by the weight mapping in https://git.libreoffice.org/core/+/refs/heads/master/xmloff/source/style/weighhdl.cxx#44: FontWeightMapper const aFontWeightMap[] = { { css::awt::FontWeight::DONTKNOW, 0 }, { css::awt::FontWeight::THIN, 100 }, { css::awt::FontWeight::ULTRALIGHT, 150 }, { css::awt::FontWeight::LIGHT, 250 }, { css::awt::FontWeight::SEMILIGHT, 350 }, { css::awt::FontWeight::NORMAL, 400 }, { css::awt::FontWeight::NORMAL, 450 }, { css::awt::FontWeight::SEMIBOLD, 600 }, { css::awt::FontWeight::BOLD, 700 }, { css::awt::FontWeight::ULTRABOLD, 800 }, { css::awt::FontWeight::BLACK, 900 }, { css::awt::FontWeight::DONTKNOW, 1000 } }; The numbers seems to match what is saved in the ODF fo:font-weight. The list also has SEMILIGHT which OpenType does not have (https://learn.microsoft.com/en-us/typography/opentype/spec/os2#usweightclass) and missed medium weight. Elsewhere, medium weight seems to map to css::awt::FontWeight::NORMAL, which matches what is saved in ODF as well https://git.libreoffice.org/core/+/refs/heads/master/vcl/source/app/unohelp.cxx#112: else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) ) return css::awt::FontWeight::NORMAL; I think fixing this requires modifying css::awt::FontWeight to support medium weight and fixing the mapping, but this is a a “Published UNO API” (whatever that is) and must not be changed incompatibility, and changing the mapping to weight numbers might break existing documents, so this might also need a compatibility flag. Hopefully the above can be helpful for someone looking into this.
Here is a preliminary fix https://gerrit.libreoffice.org/c/core/+/186128. With it opening the attached document shows all correct weights except for medium (because it is saved as normal), and fixing medium manually and saving the document the correct weight persists. I have no time to work further on this fix, though.
Checking the OpenDocument spec (https://docs.oasis-open.org/office/v1.2/cd05/OpenDocument-v1.2-cd05-part1.html#a_20_184_fo_font-weight), it has the following text: The values of the fo:font-weight attribute are normal, bold, 100, 200, 300, 400, 500, 600, 700, 800 or 900. So the values LibreOffice currently saves are non-standard. So may be this can be considered a bug fix and backward compatibility concerns can be ignored (it is probably also low impact given that extended families are not supported on Windows, nor on Linux except for variable fonts).
Can this not be reproduced with less-exotic typefaces than Exo 2 and Saira? e.g. with Liberation Sans or Serif? Also, is there something special you see with the second typeface (Saira)? In terms of the wrong font weights?
(In reply to Khaled Hosny from comment #14) > the OpenDocument spec ... has the following text: > The values of the fo:font-weight attribute are normal, bold, 100, 200, 300, > 400, 500, 600, 700, 800 or 900. > > So the values LibreOffice currently saves are non-standard. You mean, 150 and 250? I wonder where we got those from.
(In reply to Eyal Rozenberg from comment #16) > (In reply to Khaled Hosny from comment #14) > > the OpenDocument spec ... has the following text: > > The values of the fo:font-weight attribute are normal, bold, 100, 200, 300, > > 400, 500, 600, 700, 800 or 900. > > > > So the values LibreOffice currently saves are non-standard. > > You mean, 150 and 250? Yes. > I wonder where we got those from. No idea. The mapping has been like this since the first public commit in 2000. This probably was untested, since fonts with such weight range was not common and not supported in Windows (the font family name would be "Exo 2 Light" with style "Regular" under GDI, so the numeric weight would not affect font selection).
I’m now convinced this is the right fix and the backward compatibility considerations are negligible, so I’m going to merge the fix, and if it proved to be problematic we can revert it.
Khaled Hosny committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/b2b31dd8be9d39434aa950a96d116abd4030f4b8 tdf#166357: Fix saving font weight to documents It will be available in 26.2.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.
(In reply to Commit Notification from comment #19) I'm actually kind of worried about the awt::FontWeight values, generally. What are they used for, directly?