Hi, we are using TLF Text for creating a simple application, to create PDF files from PHP.
We tried with our TLF and Classic text difference for y Position. there we got 20% approx gap, from top, in TLF. Can anybody tell me? How to calculate Y position of TLF Text including line height for the new line text, for PHP?
Getting line height is typically the TextFormat classes property (to set and get). The leading property can adjust line height. Here's that class:
You can get the specific format for a range in a TLFTextField as well as sometimes formatting is applied to regions of the text. You can use the getTextFormat() method of a TLFTextField to get that:
Are you trying to calculate a position of specific text inside the TLFTextField?
I am trying to make a copy from TLF to Classic Text Field in flash CS5.
i applied below logic
//tlft is TLFTextField
for(var i:uint = 0;i<tlft.length-1;i++)
tf = tlft.getTextFormat(i,i+1);
tf.color = '0xff0000';
var txt:TextField = new TextField();
txt.text = str.charAt(i);
txt.y = tlft.y;// How can i set x and y position same as TLF here?
Holy cow... by the loop you just mentioned you're literally trying to make a TextField for every single character?! That's really unadvisable as an approach overall.
I'm not sure how this suits your needs but finding a common medium is the best route here. Here's a couple route change suggestions and then at the end if you really still want to persue this method I'll let you know the method you want to use.
One way is is to make a stylesheet that is re-usable between both TLFTextField and TextField. As long as the same classes are applied to both fields they will look "as close as possible" to identical as long as the same stylesheet is applied to both. Then it's just copying all the text from one field to another once.
The other way which offers a bit less flexibility but still can work is to use HTML directly to style the text. Some attributes like line spacing and such are not supported directly in HTML without stylesheets but you can do a bit of common formtting (like color, font family, font size, bold, italic, etc). Then if you enable the classic TextField's .html property to true you can again just copy the text directly into it and it will format based on the HTML.
If you can't persue either of these, the method you're looking for is this:
getCharBoundaries() returns a Rectangle which contains the x, y, width and height boundaries of the character index you supply. So in your loop you would do something like:
txt.y = tlft.getCharBoundaries(i).y;
The height and width would also be useful for you in certain cases where exotic formatting is used.
Thanks for your reply. But we already used HTML Text of TLF to Classic textfield. But qwe didn't get any positive response from that. just because of y position is different for classic and tlf textfield.
I think there is no use of TLF for printing.And I realized it now that there are many issues in TLF for printing. Adobe still have to work in this.
RED COLOR -- Dynamic text
BLUE COLOR-- TLF Text
txt.y = tlf.y+tlft.getCharBoundaries(i).y;
txt.x = tlf.x+tlft.getCharBoundaries(i).x;
RED COLOR -- Dynamic text
BLUE COLOR-- TLF Text
Now how to manage this y position with different font face?
"Can we use TLF for Printing pdf in server?"
There is a significant difference in the look between TLF and Classic. The entire class foundation is different so you'd have to expect differences. Classic is very simple and TLF has been extended with a lot more options. In my recent projects, which are luckily kiosks, I find myself using device fonts with TLFTextFields. I don't really have any issue with them. But I can assure you I notice a difference in text position if I flip a TLF text field to a Classic text field. I can visibly see the text move just toggling between them. That should tell you the rendering of these different fonts are fundamentally different and can't ever be expected to exactly simulate each other.
I think the general idea is TLF is onwards and upwards and Classic text is only left in for depreciated reasons. I see no reason to use Classic at all.
If you author a font you'll see that the fonts boundaries are described by the author. That's why coders use fixed-width fonts for coding, so text lines up when indented. This is the same reason why different fonts you're switching between render differently. The boundaries are changing.
Also note some fonts come in both TTF and OTF and you may have both variations installed. You'd need to make sure when you flip between Classic and TLF that it's not changing from TTF to OTF. That would change font boundaries and rendering for sure.