basctl/source/basicide/textwindowaccessibility.cxx | 3 ++- offapi/com/sun/star/awt/FontWeight.idl | 7 +++++++ vcl/source/app/unohelp.cxx | 6 +++++- vcl/source/components/fontident.cxx | 2 +- xmloff/source/style/weighhdl.cxx | 12 +++++++++--- 5 files changed, 24 insertions(+), 6 deletions(-)
New commits: commit b2b31dd8be9d39434aa950a96d116abd4030f4b8 Author: Khaled Hosny <kha...@aliftype.com> AuthorDate: Mon Jun 2 12:57:03 2025 +0300 Commit: Khaled Hosny <kha...@libreoffice.org> CommitDate: Tue Jun 10 18:26:22 2025 +0200 tdf#166357: Fix saving font weight to documents Several font weights (Ultra Light, Light, and Medium) were incorrectly saved to file. ULTRALIGHT and LIGHT were saved as fo:font-weight 150 and 250, respectively. But, according to ODF spec, the values of the fo:font-weight attribute are normal, bold, 100, 200, 300, 400, 500, 600, 700, 800 or 900: https://docs.oasis-open.org/office/v1.2/cd05/OpenDocument-v1.2-cd05-part1.html#a_20_184_fo_font-weight This change fixes ULTRALIGHT and LIGHT to map to 200 and 300, respectively. This change also introduces awt::FontWeight::MEDIUM and gives it an arbitrary 105% value (the percentage values in awt::FontWeight make no sense at all, THIN numeric value is 100, so it should be 25% of NORMAL whose numeric value is 400, but it is 50% in awt::FontWeight), and fix the mapping to and from awt::FontWeight to handle medium weight properly, and fixes the numeric weight values saved to file. The backward compatibility for this change are likely negligible since we don’t support extended font families on Windows, or Linux for non-variable fonts. Change-Id: I80ece7bb05462b0f3aceb7f39409f8135f63e94d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186128 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins Reviewed-by: Khaled Hosny <kha...@libreoffice.org> diff --git a/basctl/source/basicide/textwindowaccessibility.cxx b/basctl/source/basicide/textwindowaccessibility.cxx index e9ee3ee30bf5..17e2204a872b 100644 --- a/basctl/source/basicide/textwindowaccessibility.cxx +++ b/basctl/source/basicide/textwindowaccessibility.cxx @@ -2084,7 +2084,7 @@ css::uno::Any Document::mapFontWeight(::FontWeight nWeight) css::awt::FontWeight::LIGHT, // WEIGHT_LIGHT css::awt::FontWeight::SEMILIGHT, // WEIGHT_SEMILIGHT css::awt::FontWeight::NORMAL, // WEIGHT_NORMAL - css::awt::FontWeight::NORMAL, // WEIGHT_MEDIUM + css::awt::FontWeight::MEDIUM, // WEIGHT_MEDIUM css::awt::FontWeight::SEMIBOLD, // WEIGHT_SEMIBOLD css::awt::FontWeight::BOLD, // WEIGHT_BOLD css::awt::FontWeight::ULTRABOLD, // WEIGHT_ULTRABOLD @@ -2103,6 +2103,7 @@ css::uno::Any Document::mapFontWeight(::FontWeight nWeight) : nWeight <= css::awt::FontWeight::LIGHT ? WEIGHT_LIGHT : nWeight <= css::awt::FontWeight::SEMILIGHT ? WEIGHT_SEMILIGHT : nWeight <= css::awt::FontWeight::NORMAL ? WEIGHT_NORMAL + : nWeight <= css::awt::FontWeight::MEDIUM ? WEIGHT_MEDIUM : nWeight <= css::awt::FontWeight::SEMIBOLD ? WEIGHT_SEMIBOLD : nWeight <= css::awt::FontWeight::BOLD ? WEIGHT_BOLD : nWeight <= css::awt::FontWeight::ULTRABOLD ? WEIGHT_ULTRABOLD diff --git a/offapi/com/sun/star/awt/FontWeight.idl b/offapi/com/sun/star/awt/FontWeight.idl index dc5a83d4af5d..75fbd1047136 100644 --- a/offapi/com/sun/star/awt/FontWeight.idl +++ b/offapi/com/sun/star/awt/FontWeight.idl @@ -59,6 +59,13 @@ published constants FontWeight const float NORMAL = 100.000000; + /** specifies a 105% font weight. + + @since LibreOffice 26.2 + */ + const float MEDIUM = 105.000000; + + /** specifies a 110% font weight. */ const float SEMIBOLD = 110.000000; diff --git a/vcl/source/app/unohelp.cxx b/vcl/source/app/unohelp.cxx index 044165a7c189..98b2369093fb 100644 --- a/vcl/source/app/unohelp.cxx +++ b/vcl/source/app/unohelp.cxx @@ -109,8 +109,10 @@ float vcl::unohelper::ConvertFontWeight( FontWeight eWeight ) return css::awt::FontWeight::LIGHT; else if( eWeight == WEIGHT_SEMILIGHT ) return css::awt::FontWeight::SEMILIGHT; - else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) ) + else if( eWeight == WEIGHT_NORMAL ) return css::awt::FontWeight::NORMAL; + else if( eWeight == WEIGHT_MEDIUM ) + return css::awt::FontWeight::MEDIUM; else if( eWeight == WEIGHT_SEMIBOLD ) return css::awt::FontWeight::SEMIBOLD; else if( eWeight == WEIGHT_BOLD ) @@ -138,6 +140,8 @@ FontWeight vcl::unohelper::ConvertFontWeight( float f ) return WEIGHT_SEMILIGHT; else if( f <= css::awt::FontWeight::NORMAL ) return WEIGHT_NORMAL; + else if( f <= css::awt::FontWeight::MEDIUM ) + return WEIGHT_MEDIUM; else if( f <= css::awt::FontWeight::SEMIBOLD ) return WEIGHT_SEMIBOLD; else if( f <= css::awt::FontWeight::BOLD ) diff --git a/vcl/source/components/fontident.cxx b/vcl/source/components/fontident.cxx index 8a602c888115..342866ea02be 100644 --- a/vcl/source/components/fontident.cxx +++ b/vcl/source/components/fontident.cxx @@ -122,7 +122,7 @@ css::uno::Any SAL_CALL FontIdentificator::getMaterial() case WEIGHT_ULTRALIGHT: aFD.Weight = css::awt::FontWeight::ULTRALIGHT;break; case WEIGHT_LIGHT: aFD.Weight = css::awt::FontWeight::LIGHT;break; case WEIGHT_SEMILIGHT: aFD.Weight = css::awt::FontWeight::SEMILIGHT;break; - case WEIGHT_MEDIUM: + case WEIGHT_MEDIUM: aFD.Weight = css::awt::FontWeight::MEDIUM;break; case WEIGHT_NORMAL: aFD.Weight = css::awt::FontWeight::NORMAL;break; case WEIGHT_SEMIBOLD: aFD.Weight = css::awt::FontWeight::SEMIBOLD;break; case WEIGHT_BOLD: aFD.Weight = css::awt::FontWeight::BOLD;break; diff --git a/xmloff/source/style/weighhdl.cxx b/xmloff/source/style/weighhdl.cxx index a069dbd30fd0..7890c6f3e4be 100644 --- a/xmloff/source/style/weighhdl.cxx +++ b/xmloff/source/style/weighhdl.cxx @@ -41,15 +41,21 @@ struct FontWeightMapper } +// ODF specifies the valid fo:font-weight values, but does not provide mapping +// between weight names to numeric values: +// https://docs.oasis-open.org/office/v1.2/cd05/OpenDocument-v1.2-cd05-part1.html#a_20_184_fo_font-weight +// +// The mapping here is the same as OpenType/windows.h: +// https://learn.microsoft.com/en-us/typography/opentype/spec/os2#usweightclass 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::ULTRALIGHT, 200 }, + { css::awt::FontWeight::LIGHT, 300 }, { css::awt::FontWeight::SEMILIGHT, 350 }, { css::awt::FontWeight::NORMAL, 400 }, - { css::awt::FontWeight::NORMAL, 450 }, + { css::awt::FontWeight::MEDIUM, 500 }, { css::awt::FontWeight::SEMIBOLD, 600 }, { css::awt::FontWeight::BOLD, 700 }, { css::awt::FontWeight::ULTRABOLD, 800 },