Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
gavoh
Posts: 23
Registered: ‎10-08-2012
My Device: 9800

How to Embed a "Custom font" TTF in QML and C++

Hi,

I want to Embed a "Custom font" TTF in QML and C++, I didn't find any references about How to embed and use it

I am using Native SDK for Cascades Beta4

 

Please Advice

 

 

Thanks

Developer
markwilcox
Posts: 51
Registered: ‎11-23-2012
My Device: BB10 Dev Alpha

Re: How to Embed a "Custom font" TTF in QML and C++

It SHOULD be supported by adding it to the Qt Font database in C++ - after that it would be accessible as a standard font selection in both C++ & QML.  However, if you search the forum you'll find the last thread this was asked on and it is apparently not supported by the platform currently.

Contributor
gavoh
Posts: 23
Registered: ‎10-08-2012
My Device: 9800

Re: How to Embed a "Custom font" TTF in QML and C++

[ Edited ]

Thanks for reply, but can you give a samples? and how to add it to the Qt Font database in C++

Developer
markwilcox
Posts: 51
Registered: ‎11-23-2012
My Device: BB10 Dev Alpha

Re: How to Embed a "Custom font" TTF in QML and C++

The documentation is here:

http://doc.qt.digia.com/4.3/qfontdatabase.html#addApplicationFont

 

However, as far as I know it will NOT work at the moment.  The BB10 platform does not support adding custom fonts yet.

Developer
bobdodd
Posts: 116
Registered: ‎10-31-2012
My Device: BB10 Dev Alpha B

Re: How to Embed a "Custom font" TTF in QML and C++

The BB10 platform does not support adding custom fonts yet.


Hi Mark,

 

It's more that Cascades doesn't support custom fonts rather than BB10. It will depend on what libraries you are using to render your app.

 

Look at bbutil.c  from the HelloWorldDisplay example (NDK samples, not Cascades samples). This shows a more low-level form of text support, including loading fonts. (I tried to attach it to the message but ".c" and ".h" are missing fromt he accepted file extensions...)

 

Unfortunately the two approaches are mutually exclusive (Cascades and HelloWorldDisplay), well unless you want to punch holes through Cascades with foreign windows, which is horrible.

 

I'd say that if an app is totally dependent on custom fonts, Cascades is probably  not the way to go. Actually I'm tempted to say that you should go for QtCreator/QtQuick as your development platform for now.  Either that or you go down to the level of bbutil.c

 

Bob

 

 

Developer
markwilcox
Posts: 51
Registered: ‎11-23-2012
My Device: BB10 Dev Alpha

Re: How to Embed a "Custom font" TTF in QML and C++

Sorry, I should have said the BB10 platform doesn't support adding custom fonts to Qt yet. :smileyhappy:

 

I'm not sure even QtCreator/QtQuick will help here?  They need to wrap the custom font rendering the native platform provides with the Qt classes.  If Qt's font database isn't told about the additional font then you're not going to be able to use it in your app.  Or has this already been done but is just not correctly integrated with Cascades?

 

Contributor
gavoh
Posts: 23
Registered: ‎10-08-2012
My Device: 9800

Re: How to Embed a "Custom font" TTF in QML and C++

[ Edited ]

Then, Can I use "Open source font engine" In C++ Cascade app like FreeType http://www.freetype.org/

 

 

Thanks

Developer
markwilcox
Posts: 51
Registered: ‎11-23-2012
My Device: BB10 Dev Alpha

Re: How to Embed a "Custom font" TTF in QML and C++

If you use the font engine to render images and then display those, yes.  Can you plug the font engine into the Qt system and use the fonts in QML, no - as I understand it you need to rebuild Qt itself for the platform to add a new font rendering engine.

Developer
bobdodd
Posts: 116
Registered: ‎10-31-2012
My Device: BB10 Dev Alpha B

Re: How to Embed a "Custom font" TTF in QML and C++

To be honest Mark, I'm not totally sure.

 

As far as I know, you can port pretty much any QT app to BB 10 using the Native SDK with minimal changes. I assume that includes font handling, though QT does depend on its supporting platform libraries for font access.

 

What I've used myself is the bbutil.c.  I wrapped it in a C++ class, and I use it to get string lengths in pixels (another thing missing from Cascades). It allows me to do intelligent word-wrap: I don't want single words, I want phrases to wrap, basically I want "10.30am (tomorrow)" to be on the same line, and the word-wrap you get with multiline labels doesn't handle that use-case. It  does mean having my own screen_context and loading fonts from the file system tho, which is why I'm pretty sure you can load fonts, just not in Cascades.

Developer
markwilcox
Posts: 51
Registered: ‎11-23-2012
My Device: BB10 Dev Alpha

Re: How to Embed a "Custom font" TTF in QML and C++

http://supportforums.blackberry.com/t5/Cascades-Development/How-to-use-custom-OpenType-TrueType-WOFF...

 

I got my info on font sideloading for Qt not being supported on BB10 from the thread above, haven't tried it - Cascades is just using the standard QFontDatabase to provide font support, so if you can do it in standard Qt you'll be able to do it in Cascades too, C++ or QML should work fine.