BlackBerry Forums Support Community

Closed Thread
LinkBack Thread Tools
Old 07-23-2008, 04:52 PM   #1 (permalink)
Knows Where the Search Button Is
Join Date: Jul 2007
Model: 8300
Carrier: AT&T
Posts: 25
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Font scaling

Please Login to Remove!

I am trying to use the font API:

public Font derive(int style, int height, int units, int antialiasMode,
int effects, int[] transform)

To derive a font that is translated and scaled using the transform as shown in the following code:

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.

But it is not working.
Does any one has a suggestion on what is not done right?


Copyright 2004-2016
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.