[Interest] Use Book and Medium weight Gotham font from QML?
Elvis Stansvik
elvstone at gmail.com
Mon Apr 4 17:33:22 CEST 2016
2016-04-04 16:13 GMT+02:00 Elvis Stansvik <elvstone at gmail.com>:
> 2016-04-04 15:51 GMT+02:00 Elvis Stansvik <elvstone at gmail.com>:
>> 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.
>
> Anyone know if it would work if I open both .otf in FontForge, change
> the family names to be e.g. "My Gotham Book" and "My Gotham Medium",
> re-export them to OTF and then use e.g. font.family: "My Gotham
> Medium" and don't set font.weight at all?
So to conclude, this is what I did in the end to work around it. I
edited the fonts in FontForge to give them distinct family names (and
updated other relevant fields):
Gotham-Light.otf: Changed to family "Gotham Light QML"
Gotham-Book.otf: Changed to family "Gotham Book QML"
Gotham-Medium.otf: Changed to family "Gotham Medium QML"
and then just stick with only specifying the family in QML, not the
weight. This way I can at least "reach" all three of the weights.
Hope this maybe helps someone else who is limited by the "range" of
the Font.* weight enum values.
Elvis
>
> As you can understand, I'm a little desperate since we really need to
> use these fonts for the UI, and we want to use the packaged Qt on
> Ubuntu :/
>
> Elvis
>
>>
>> Elvis
>>
>> [1] https://codereview.qt-project.org/#/c/112676/
More information about the Interest
mailing list