Scale text size in FPDF - fpdf

I'm using FPDF and I have a little problem:
I am printing dynamic text in a line that have a maximum width. The text has a maximum height and, when the text have more width that the line, I'm decreasing the font size of the text until it fits to the line.
It works fine, but I want to know if I could decrease only the text width, scaling it and mantaining the height that I declared at the beginning. I've read the documentation and searched for a solution but I didn't find anything related to this.
Thanks.

Finally I found an add-on to scale the text and it works great:
http://fpdf.de/downloads/addons/62/
Instead of using the Cell() function, I use the CellFitScale() function and it scales automatically only the width of the text.

Related

How to calculate fontsize of same height by component height?

There's a RectComponent, and a TextComponent inside. The text will change length sometimes.
So I need "text adaptation".
The fontsize :
The size of glyphs (in logical pixels) to use when painting the text.
I cannot find the conversion method between fontSize(logical pixels) and component size.
Is there some formula between "component size" and "font size"?
There is currently no way to automatically fit the text in the size of the RectangleComponent.
You can however use TextComponent.textRenderer.measureWidth and calculate whether the font size has to be smaller or larger than it currently is.
Remember that if you don't use a mono-spaced font, a string with the same amount of characters as another string might become different widths.
You can use FittedBox, check this answer out:
How to dynamically resize text in Flutter?
So, basically, FittedBox makes sure the content always stays within an area.

What's the proper way to align a strechable Text and an image to two ends in Unity UI?

I have an UI element that has a Text and an Image as its children. It has a HorizontalLayoutGroup component that enables Control Child Size and Child Force Expand.
I want the Image has a fixed size, and Text has strechable size controlled by the HorizontalLayoutGroup. So when the Image is set to inactive, the Text fills the whole space and when the Image is active, the Text shrinks a little bit in order to give space to the Image. Right now this part works good.
My second goal is to align them to both ends: the Text in the left and the Image on the right with space in between. But changing Child Alignment can't achieve this.
I tried the following solution:
Add LayoutElement both to Image and Text. On Text, enable Flexible Width and set a a value, on Image, enable Min Width and set to a value. Manually adjust the two values until it seems right.
This solution seems to work, but I don't know why. Is anyone familiar with this?What's the recommended way to do it? Thanks!
I worked it out. On the LayoutElement, treat Preferred Width or Preferred Height as Max Width or Max Height. Enable them, set the value the same with min value. One the other objects that you want to stretch, enable Flexible values. Then all worked as we want.

UILabel: Get actual font size with adjustFontSizeToFit

I have two labels in my layout.
I want the font size to adjust to fit the label bounds.
I set to true the UILabel adjustFontSizeToFit.
Moreover a need the two labels to have the same font size. So I added an auto-layout constraint to make the labels have the same size.
The issue with it is the labels do not contain the same string. Sometimes the first is longer and vice-versa. The font I use doesn't have the same width for every character which will not allow me to use a space to fill to shorter string. (This solution looks a bit ugly to me).
I tried to get the label.font.size.pointSize after the label has been displayed but the value returned is always the one I set at the beginning (before being reduced to fit).
Does anyone have an idea on how I could achieve it ?

iPhone: UILabel text does not fit the way i want

I have a UILabel with some text on it, what I want is if the text with the given font does not fit to the label, I want it to be first linebreaked to a second line, and if still does not fit then it should automatically adjust those 2 lines to a smaller font.
I experienced with the IB changing the settings of linebreaks and number of rows, but couldn't get what I want.
Any recommendadtions?
To my knowledge UILabel does not support auto adjusting the font when there is more than one line.
The only way I know of it to iteratively calculate a fitting font size and then to set the appropriate font manually.
Maybe the sizeWithFont: method is a solution for you:
– sizeWithFont:forWidth:lineBreakMode:
This calculates the width / height of a NSString with the appropriate font / settings

Size of TTStyledText with floating image is being computed wrong

I have a TTStyledText with a floating image. The problem that I am facing is that the height of the text incase there is a floating image larger than text, is being computed wrong. Instead of incorporating the size of the image + text accompanying the image, The implementation just returns size of text. This causes the image to be clipped.
Any one else has faced this issue?
I finally solved this by defining a TTBoxStyle with minimum size. This way even if the image is clipped the minimum size ensures that some part of the image is displayed properly.