Size of TTStyledText with floating image is being computed wrong - iphone

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.

Related

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.

Matlab figure size formatting for Word

I'm trying to create MATLAB figures to put into a paper. The paper has very specific sizing instructions for figures that I'm having trouble matching in MATLAB. The figures need to be no greater than 3.5" width, >300 DPI, with 8pt font.
In my code, I use the following to try to set the parameters:
set(gcf,'PaperUnits','inches');
set(gcf,'PaperPosition',[0 0 3.5 3.5]);
xlabel('x-axis label','FontSize',8);ylabel('y-axis label','FontSize',8);
set(gca,'FontSize',8);
print('-djpeg','-r300','filename.jpg')
This should be giving me a 300 DPI, 3.5"x3.5" JPEG image with an 8pt font size. However, when I import the image into Word, it becomes 6.5" x 6.5" and the font size is larger than Word's 8pt font. Even if I resize the image, the font size is still too large, though it should maintain the same DPI. Are the FontSize and PaperPosition parameters not working as I expect they should or is Word doing something strange for importing?
The font size issue was caused due to differing fonts used in MATLAB and Word. Once I learned about set(gca,'FontName'), the font size seemed to be correct when the image was manually resized to 3.5" x 3.5".
The image size issue seemed to be related to saving it as a JPEG. Once I swapped to PNG, the image was the correct size by default. Looking into the JPEG properties, it had the correct number of pixels for a DPI of 300 at 3.5", the sole issue was that it would have to be manually resized. Thanks for the comments that led me to finding a solution.

Scale text size in 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.

The image size is changed when the image is too big

I am using an image with size 4000*3000 pixels. When I show this image through the imshow function, the program shows:
Image is too big to fit on screen : displaying at 67%.
After that, when I want to find size of the image with function size(), the number of column is always multiplied by 3 from the original image. For example, when my image is 563*1000, this function show me 563*3000.
Could anyone tell me how to fix this problem?

CGRectIntegral what is the usage of it?

How does one use the CGRectIntegral function? I understand it's purpose.
The documentation isn't clear on it's exact use.
CGRectIntegral to convert any decimal values to their integer equivalents
see image may be you can understand
How do I fix it?
frame = CGRectIntegral(frame);
-OR-
myTextView.frame = CGRectIntegral(myTextView.frame);
 
see this for more information of CGRectIntegral
CGRectIntegral Method is used to create integer rect . I mean to say suppose if you calculate frame in app you may get frames value in float.
Setting float value as frame to some UIElement like UILabel would make the text looks blur. To avoid that, we use CGRectIntegral.Please look at the example below,
NSLog(#"%#",NSStringFromCGRect( CGRectIntegral(CGRectMake(0, 15.6, 16.1, 20.2))));
This will print, {0,15},{17,21}.
This explanation is found in the header file.
/* Expand `rect' to the smallest rect containing it with integral origin and
size. */
One particular usage is to fix frames that do not align perfectly with on-screen pixels.
See this question: UITextField blurred text
If a label or textfield has a frame that isn't pixel-aligned when rendered to the screen, the text will appear blurred. This can happen if you calculate the frame using division (for example to center it in a parent view).
CGRectIntegral will remove the fractional part of the frame, fixing this problem. Note however that with retina displays a .5 frame value is pixel aligned, but CGRectIntgral will still remove the fractional part.