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

Java Development

Reply
Developer
Posts: 122
Registered: ‎07-26-2008
My Device: 8320, 9500, 9700
My Carrier: Vodafone
Accepted Solution

How to use external fonts in SVG?

Hi All,


I'm having a bit of a struggle understanding how to use external fonts in SVG documents.


I first tried embedding the font in the document (<defs>) per JSR 226 but then it appears this is not supported on the BB, the (fairly old) documentation says you can xlink to an external file and gives an example:

 

 

<font-face-src>
<font-face-uri xlink:href="externalFont1.cbtf" />
</font-face-src>

 

<font-face-src>
<font-face-uri xlink:href="externalFont1.cbtf" />
</font-face-src>

 

Since I don't know how to make a .cbtf file I have attempted to compile the SVG font using the SVGC tool that comes with Theme Studio, I get no errors but I get a tiny PME  file (<100 bytes) that obviously does not contain the <glyph> elements.

 

At this stage I'm pretty confused, its not clear whether the SVG documentation is really relevant since it seems to predate the introduction of JSR-226 support.

 

Has anyone managed to use an external font in SVG on the BlackBerry outside of Plazmic?

 

Thanks!

Bruce


 

 

 


Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: How to use external fonts in SVG?

I'll start off by saying I have absolutely no experience but will see if I can help you and learn something too.

 

I looked at http://www.w3.org/TR/SVGMobile12/fonts.html and at the bottom it tells how to use a SVG file for the font. If you then used "javax.microedition.m2g.ExternalResourceHandler" you could load the SVG and use it to pass the "font" to the ScalableImage and get your SVG rendered (theoretically).

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 122
Registered: ‎07-26-2008
My Device: 8320, 9500, 9700
My Carrier: Vodafone

Re: How to use external fonts in SVG?

[ Edited ]

Thanks for the reply!  
It seems that the BlackBerry implementation of JSR 226 is broken in that it won't load embedded fonts, external fonts are not allowed in SVG Tiny 1.1 so it seems we are stuck there.
Fortunately I have found a solution that works though,  you can use
net.rim.device.api.ui.FontManager to load a True-Type font then that font becomes accessible via SVG.
Cheers,
Bruce

 

Thanks for the reply!  


It seems that the BlackBerry implementation of JSR 226 is broken in that it won't load embedded fonts, external fonts are not allowed in SVG Tiny 1.1 so it seems we are stuck there.


Fortunately I have found a solution that works though,  you can usenet.rim.device.api.ui.FontManager to load a True-Type font and that font then becomes accessible via SVG.

 

Cheers,

Bruce

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: How to use external fonts in SVG?

That works too but only on 5.0 and above.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 122
Registered: ‎07-26-2008
My Device: 8320, 9500, 9700
My Carrier: Vodafone

Re: How to use external fonts in SVG?

hmmm, you're right I missed that.

 

I'm pretty sure the ExternalResourceHandler approach is not going to work since the SVG engine won't load embedded fonts in the main file so I'd guess it would not load them in an external file either, plus this:

 

"Note that SVGT 1.1 does not contain external references to SVG files, therefore an external resource can not contain subsequent external resources."  

 

This is part of JSR 226 anyway, SVG fonts must be embedded in the main document.

 

So it looks like OS 4.6 and OS 4.7 are only able to use the system fonts.. another half-a**ed effort by RIM then.

 

Cheers,

Bruce

 

 

 

Developer
Posts: 122
Registered: ‎07-26-2008
My Device: 8320, 9500, 9700
My Carrier: Vodafone

Re: How to use external fonts in SVG?

Actually despite my little outburst you were perfectly correct.. by implementing an ExternalResourceHandler it is possible to load TrueType fonts in OS 4.6, 4.7 and 5.0.. Thanks!

 

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: How to use external fonts in SVG?

Glad I could help. How did you get a TrueType font loaded on 4.6 and 4.7? I ask because from what I can tell FontManager only supports loading user-made fonts in 5.0 and higher.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 122
Registered: ‎07-26-2008
My Device: 8320, 9500, 9700
My Carrier: Vodafone

Re: How to use external fonts in SVG?

I specify the font in the <defs> section of the SVG file and the SVG renderer requests it via the ExternalResourceHandler.  The documentation doesn't mention the ability to load TrueType fonts in this way but I just tried it on a hunch and it worked on all 3 OSes. Smiley Happy

Highlighted
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: How to use external fonts in SVG?

That's actually good to know, though it would take some work a developer who needs to load a font on a lower-then-5.0 OS can use SVG to do it.

 

Interesting

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
New Contributor
Posts: 6
Registered: ‎05-26-2010
My Device: Bold
My Carrier: Bouygues

Re: How to use external fonts in SVG?

I did actually try this by defining the following :

 

    <defs>
      <font-face font-family="arial_black">
        <font-face-src>
          <font-face-uri xlink:href="img/ariblk.ttf"/>
        </font-face-src>
      </font-face>
    </defs>

 

 

and logged every requestResource call.

 

Result is that ariblk.ttf is not listed when testing on a Bold 9000 simulator/OS 4.6.

 

Did you test on simulator or device?

How did you reference the external font?

 

Thx,

David