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
Administrator
MSohm
Posts: 14,082
Registered: ‎07-09-2008
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.
Found a bug? Report it using Issue Tracker
Please use plain text.
BlackBerry Development Advisor (Retired)
bzubert
Posts: 86
Registered: ‎07-11-2008

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
Please use plain text.
Developer
Developer
rab
Posts: 283
Registered: ‎07-22-2008

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

 

Please use plain text.
Developer
Developer
rab
Posts: 283
Registered: ‎07-22-2008

Re: Font scaling/translating

Any suggestion?

 

Thanks

Please use plain text.
Developer
Developer
rab
Posts: 283
Registered: ‎07-22-2008

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

 

Please use plain text.
Administrator
MSohm
Posts: 14,082
Registered: ‎07-09-2008
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.
Found a bug? Report it using Issue Tracker
Please use plain text.