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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Highlighted
BlackBerry Development Advisor
Posts: 15,884
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Font scaling/translating

Quote from the previous forum:


Guest
Font scaling/translating
Posted: Jul 21, 2008 11:01 AM
 
I am trying to use the following API for constructing a new font:

public Font derive(int style,
int height,
int units,
int antialiasMode,
int effects,
int[] transform)
I am trying to use the transform to do scaling of 2/3 and translation of 1/2.
Does any body has an example on how to express those values using the 3x2 matrix to define the transform?

Thanks


Please note that this method will attempt to return an existing system font that matches your criteria.  If no match is found, the current font is returned.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Retired
Posts: 86
Registered: ‎07-11-2008
My Device: Not Specified

Re: Font scaling/translating

The javadoc for the Font class indicates the transformation matrix for scaling should take the form:

 

       sx 0 0
       0 sy 0
       0 0 1

Translating that 3x3 matrix to a form useful for this method generates the following matrix:

int[] transform = new int[] { sx, 0, sy, 0, 0, 0 };

 

Brian Zubert
Technical Partnership Manager
Research In Motion
Developer
Developer
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: Font scaling/translating

This is how I am using it, but I do not see any effect:

 

 

 String strText ="Centered Rich TEXT, multiple fonts"; 

  Font fonts[] = new Font[5];
         
        int one = Fixed32.toFP(1);             
        int two = Fixed32.toFP(2);
        int  n = one/2;
        int  m = two/3 ;
                     
        fonts[0] = Font.getDefault();
        fonts[1] = Font.getDefault().derive(Font.BOLD,10,Ui.UNITS_px);
        fonts[2] = Font.getDefault().derive(Font.BOLD | Font.ITALIC,30);
        fonts[3] = Font.getDefault().derive(Font.PLAIN,10,Ui.UNITS_px);
 

        int[] transform = new int[] { one,0,0,one,n,n };

        fonts[4] = Font.getDefault().derive(Font.PLAIN,10,Ui.UNITS_px,1,0,transform);
                        
        int offset[] = new int[5];
        byte attributes[] = new byte[4];
       

        attributes[0] = 1;//bold
        attributes[1] = 3; //Plain, 10
        attributes[2] = 4; //translated
        attributes[3] = 2; //bold italic 30
      
        offset[0] = 0;
        offset[1] = 9;
        offset[2] = 13;
        offset[3] = 18;
        offset[4] = strText.length();
       

 RichTextField   rtf = new RichTextField(strText,offset,attributes,fonts, RichTextField.TEXT_ALIGN_HCENTER|RichTextField.NON_FOCUSABLE);
       

 .... etc..

 

I would expect the word "TEXT" to display at some offset compared to the rest of the text.

The idea here is to use the transform to translate by 1/2 and scale by 2/3. This transformation will display the text as superscript. In the example above I am not scaling as this may not find the font and the derive will return the default one. So I am doing just the translation which ( according to my undestanding ) should work all the time.

 

So where did I go wrong? Can you please help?

 

Thanks

 

Developer
Developer
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: Font scaling/translating

Any suggestion?

 

Thanks

Developer
Developer
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: Font scaling/translating

I kept testing the font scaling and translating, and I got it working when I draw my own text in the paint method, but when I use the same thing within a RichTextField, it does not work.

Here is the code that I am using :

String strText ="Test of gp superscript and subscript"; Font fonts[] = new Font[3]; fonts[0] = Font.getDefault().derive(Font.BOLD,20,Ui.UNITS_px); int style = fonts[0].getStyle(); int size = fonts[0].getHeight(); int one = Fixed32.toFP(1); int two = Fixed32.toFP(2); int ny = Fixed32.toFP(fonts[0].getHeight()/2); int m = two/3 ; int[] transform = new int[] { m,0,0,m,0,-one }; int[] transform1 = new int[] { m,0,0,m,0,ny }; fonts[1] = Font.getDefault().derive(style,size,Ui.UNITS_px,1,0x2,transform); fonts[2] = Font.getDefault().derive(style,size,Ui.UNITS_px,1,0x2,transform1); int offset[] = new int[5]; byte attributes[] = new byte[4]; attributes[0] = 0;//bold attributes[1] = 1; //superscript attributes[2] = 0; //bold attributes[3] = 0; //subscript offset[0] = 0; offset[1] = 10; offset[2] = 21; offset[3] = 26; offset[4] = strText.length(); RichTextField rtf = new RichTextField(strText,offset,attributes,fonts, RichTextField.NON_FOCUSABLE);

 

The same code/fonts work fine if I draw the text in the paint method of a custom field.

 

Does any one know why is this not working?

 

Thanks

 

BlackBerry Development Advisor
Posts: 15,884
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Font scaling/translating

[ Edited ]
This is the expected behaviour.  Font translations, transformations and rotations are not supported in TextFields (and Fields derrived from it).  They are supported when drawing directly to a Graphics object.
Message Edited by MSohm on 07-25-2008 01:15 PM
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.