07-21-2008 11:40 AM
Quote from the previous forum:
07-21-2008 01:19 PM
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 };
07-22-2008 01:41 PM
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
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
.... 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
07-23-2008 10:38 AM
Any suggestion?
Thanks
07-25-2008 12:41 PM
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
07-25-2008 01:14 PM - edited 07-25-2008 01:15 PM