[Interest] Use Book and Medium weight Gotham font from QML?

Elvis Stansvik elvstone at gmail.com
Tue Apr 5 17:25:05 CEST 2016


2016-04-05 16:30 GMT+02:00 Jason H <jhihn at gmx.com>:
> Font weights don't work in 5.4, and they don't yet work correctly in 5.6
> https://bugreports.qt.io/browse/QTBUG-51335

Thanks for the pointer Jason. I agree with the solution you and Eskil
agreed upon in the last comments there (that setting styleName _and_
weight, it will stick to the styleName specified, but use synthesized
bold to reach the desired weight).

Just one thing: It must at all times be possible to avoid synthesizing
of weight. If I specify styleName, but _not_ weight (nor the bold)
property, then it should not do some synthesization to reach normal
weight (the default weight according to docs).

I don't think Eskil has this in mind, since it wouldn't really makes
sense, so I'm not worried. Just wanted to be clear :)

Elvis

>
>
>> Sent: Monday, April 04, 2016 at 9:51 AM
>> From: "Elvis Stansvik" <elvstone at gmail.com>
>> To: "interest at qt-project.org Interest" <interest at qt-project.org>
>> Subject: [Interest] Use Book and Medium weight Gotham font from QML?
>>
>> Hi all,
>>
>> I'm targeting Qt 5.4.1 and it seems there's no Font.Medium enumeration
>> value there? I get:
>>
>>     Unable to assign [undefined] to int
>>
>> The font we're using for this app is our company font, which is Gotham
>> from Hoefler & Co. The weights we need in the UI are Book and Medium,
>> each defined in its own .otf (but under the same family name
>> "Gotham"), as shown by the fc-scan output below:
>>
>> estan at newton:~$ fc-scan Gotham-Book.otf
>> Pattern has 22 elts (size 32)
>>         family: "Gotham"(s) "Gotham Book"(s)
>>         familylang: "en"(s) "en"(s)
>>         style: "Book"(s) "Regular"(s)
>>         stylelang: "en"(s) "en"(s)
>>         fullname: "Gotham-Book"(s)
>>         fullnamelang: "en"(s)
>>         slant: 0(i)(s)
>>         weight: 50(i)(s)
>>         width: 100(i)(s)
>>         foundry: "unknown"(s)
>>         file: "Gotham-Book.otf"(s)
>>         index: 0(i)(s)
>>         outline: True(s)
>>         scalable: True(s)
>>         charset:
>>         0000: 00000000 ffffffff ffffffff 7fffffff 00000000 ffdfcfaf
>> ffffffff ffffffff
>>         0001: cffffcff fec3fccf cffff1ff 7ffffc3f 00040000 00000000
>> 00000000 fc000000
>>         0002: 03000000 00000000 02000000 00000000 00000000 00000000
>> 3f0000c0 00000000
>>         0003: 00000000 00000040 00000000 00000000 00000000 00000000
>> 00000000 00000000
>>         000e: 00000000 80000000 00000000 00000000 00000000 00000000
>> 00000000 00000000
>>         001e: 00000000 00000000 00000000 00000000 0000003f 00000000
>> 00000000 000c0000
>>         0020: 771806bc 06010047 00000010 03f10000 000003ff 00021742
>> 00000000 00000000
>>         0021: 00800000 00000005 7ff80000 00000000 00000000 00000000
>> 00000000 00000000
>>         0022: 00040000 00000000 00000000 00000000 00000000 00000000
>> 00000000 00000000
>>         00fb: 0000001f 00000000 00000000 00000000 00000000 00000000
>> 00000000 00000000
>> (s)
>>         lang: aa|ay|bi|br|bs|ca|ch|co|cs|cy|da|de|en|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gv|ho|hr|hu|ia|id|ie|io|is|it|la|lb|lt|lv|mg|mh|mt|nb|nds|nl|nn|no|nr|nso|ny|oc|om|pl|pt|rm|sk|sl|sma|smj|so|sq|ss|st|sv|sw|tk|tl|tn|tr|ts|uz|vo|vot|wa|wen|xh|yap|zu|an|crh|csb|fil|hsb|ht|jv|kj|ku-tr|kwm|li|ms|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|za(s)
>>         fontversion: 144179(i)(s)
>>         capability: "otlayout:     otlayout:latn"(s)
>>         fontformat: "CFF"(s)
>>         decorative: False(s)
>>         hash: "sha256:3083f405cb35b16e06d0108836dd6552630c85c7fc5412a5de724e57e6fd7348"(s)
>>         postscriptname: "Gotham-Book"(s)
>>
>> estan at newton:~$ fc-scan Gotham-Medium.otf
>> Pattern has 22 elts (size 32)
>>         family: "Gotham"(s) "Gotham Medium"(s)
>>         familylang: "en"(s) "en"(s)
>>         style: "Medium"(s) "Regular"(s)
>>         stylelang: "en"(s) "en"(s)
>>         fullname: "Gotham-Medium"(s)
>>         fullnamelang: "en"(s)
>>         slant: 0(i)(s)
>>         weight: 80(i)(s)
>>         width: 100(i)(s)
>>         foundry: "unknown"(s)
>>         file: "Gotham-Medium.otf"(s)
>>         index: 0(i)(s)
>>         outline: True(s)
>>         scalable: True(s)
>>         charset:
>>         0000: 00000000 ffffffff ffffffff 7fffffff 00000000 ffdfcfaf
>> ffffffff ffffffff
>>         0001: cffffcff fec3fccf cffff1ff 7ffffc3f 00040000 00000000
>> 00000000 fc000000
>>         0002: 03000000 00000000 02000000 00000000 00000000 00000000
>> 3f0000c0 00000000
>>         0003: 00000000 00000040 00000000 00000000 00000000 00000000
>> 00000000 00000000
>>         000e: 00000000 80000000 00000000 00000000 00000000 00000000
>> 00000000 00000000
>>         001e: 00000000 00000000 00000000 00000000 0000003f 00000000
>> 00000000 000c0000
>>         0020: 771806bc 06010047 00000010 03f10000 000003ff 00021742
>> 00000000 00000000
>>         0021: 00800000 00000005 7ff80000 00000000 00000000 00000000
>> 00000000 00000000
>>         0022: 00040000 00000000 00000000 00000000 00000000 00000000
>> 00000000 00000000
>>         00fb: 0000001f 00000000 00000000 00000000 00000000 00000000
>> 00000000 00000000
>> (s)
>>         lang: aa|ay|bi|br|bs|ca|ch|co|cs|cy|da|de|en|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gv|ho|hr|hu|ia|id|ie|io|is|it|la|lb|lt|lv|mg|mh|mt|nb|nds|nl|nn|no|nr|nso|ny|oc|om|pl|pt|rm|sk|sl|sma|smj|so|sq|ss|st|sv|sw|tk|tl|tn|tr|ts|uz|vo|vot|wa|wen|xh|yap|zu|an|crh|csb|fil|hsb|ht|jv|kj|ku-tr|kwm|li|ms|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|za(s)
>>         fontversion: 144179(i)(s)
>>         capability: "otlayout:     otlayout:latn"(s)
>>         fontformat: "CFF"(s)
>>         decorative: False(s)
>>         hash: "sha256:bc397773a547218b8c334f9a40ea8e58f55198fab6095b103e598634fe273450"(s)
>>         postscriptname: "Gotham-Medium"(s)
>>
>> estan at newton:~/orexplore/doc/GrafiskProfil/Typsnitt/Gotham$
>>
>> And I'm loading these as follows:
>>
>> Style {
>>     readonly property string mediumFontFamily: __gothamMediumLoader.name
>>     readonly property string regularFontFamily: __gothamBookLoader.name
>>
>>     property FontLoader __gothamBookLoader: FontLoader {
>>         source: "fonts/Gotham-Book.otf"
>>     }
>>
>>     property FontLoader __gothamMediumLoader: FontLoader {
>>         source: "fonts/Gotham-Medium.otf"
>>     }
>>
>>     ...
>> }
>>
>> and trying to use them with:
>>
>> Text {
>>     text: "Foo"
>>     font.family: Style.regularFontFamily
>>     font.weight: Font.Normal
>> }
>>
>> Text {
>>     text: "Foo"
>>     font.family: Style.mediumFontFamily
>>     font.weight: Font.Medium
>> }
>>
>> the Font.Normal seems to work okay, it looks like it's giving me the
>> Book weight from Gotham-Book.otf, which I want. I guess because the
>> weight is close numerically (?)
>>
>> But what do I do with the Medium weight since the enum value is not
>> available? If I try Font.Bold I seem to get synthetic emboldening,
>> which I don't want.
>>
>> It seems there's some fixes in 5.6 which will let me use
>> Font.styleName to match a font by style name, which would be a
>> workaround [1]. But right now I'm stuck with 5.4.1.
>>
>> Thanks in advance for any advice.
>>
>> Elvis
>>
>> [1] https://codereview.qt-project.org/#/c/112676/
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>



More information about the Interest mailing list