SheenFigureLegacy icon indicating copy to clipboard operation
SheenFigureLegacy copied to clipboard

Text height and some other issues

Open almousa1990 opened this issue 11 years ago • 30 comments

Hello,

I would like to thank you again for this great library, i see how much effort you put in.

I am having two issues with the library. I need to get the actual height of rendered text to customized the super view based on the height of the text, seems there is no direct way to do that although it is extremely important.

The other issue was that in some situations the words at the end of the line are clipped.

Untitled

I am not sure why it happens but it seems to be a bug.

almousa1990 avatar Apr 15 '13 22:04 almousa1990

I am using the library with core graphics.

almousa1990 avatar Apr 15 '13 23:04 almousa1990

Height is calculated at the end of -(void)drawRect method as (numLines * singleLineHeight). You can save it there.

Regarding the other issue, I cannot tell what's happening. will have to take a look at your sample project.

mta452 avatar Apr 16 '13 11:04 mta452

Thank you, but i think the problem is that drawRect is the view is first displayed so i cannot save the outcomes before the run time!. So i did something else by copying the drawRect body to another method that returns the numLines * singleLineHeight an then call it before the run time, it works but it doesn't give you the same numLines that drawRect gives (exactly the same implementation).

almousa1990 avatar Apr 16 '13 14:04 almousa1990

Finally i was a able to get the exact height by duplicating the drawRect as stated earlier, my code was ok but the call to init the frame was slightly wrong.

for the other issue, i have overridden your project by changing the font and the text and by setting the flags to use CG.

There is the link for the project: https://www.dropbox.com/c/shmodel?nsid=27338052&sjid=0&state=2&signature=a534cb0&path=/SFGC.zip&id=shmodel

Or you can just use font: https://www.dropbox.com/s/khtyr42rprpwqbn/UthmanicHafs.otf

and the text from here: http://ar.wikipedia.org/wiki/%D8%A2%D9%8A%D8%A9_%D8%A7%D9%84%D8%AF%D9%8A%D9%86

I really appreciate your help

almousa1990 avatar Apr 16 '13 16:04 almousa1990

Yes, its a bug. I'm currently working on new version which is free from this bug. will push it in few days.

You'll have to wait till then.

mta452 avatar Apr 16 '13 16:04 mta452

Thank you.

almousa1990 avatar Apr 16 '13 16:04 almousa1990

OK, just pushed the new version. Let me know if you face any problem.

mta452 avatar Apr 21 '13 07:04 mta452

Great, but seems it doesn't work with ARC enabled although i disabled it for the SSLabel files.

almousa1990 avatar Apr 24 '13 00:04 almousa1990

You don't need to disable ARC for SSLabel files. It's been written to support both ARC and non-ARC. There was a compile error while using CG version which has been fixed now. See the latest commit.

mta452 avatar Apr 24 '13 07:04 mta452

Everything seems to work great.

Thank you!

almousa1990 avatar Apr 24 '13 23:04 almousa1990

I need to get hight before display the view, I have try to take numLines * singleLineHeight from

  • (void)generateCachedPages method but that doesn't work could you please show me how can I make it?

ZainabA avatar May 04 '13 09:05 ZainabA

You could use [_ssText measureHeightForFrameWidth:self.frame.size.width]

I am not sure if it is the best thing to do, it works for me but sometimes it doesn't calculate the height correctly. (Ignores lines)

almousa1990 avatar May 04 '13 15:05 almousa1990

thank you

it works but unfortunately as you said is not accurate

ZainabA avatar May 05 '13 11:05 ZainabA

I hope Mohammad can look at this issue.

almousa1990 avatar May 05 '13 11:05 almousa1990

Probably you are facing this issue because you are not subtracting padding from frame width. Try using this code: [_ssText measureHeightForFrameWidth:self.frame.size.width - (PADDING * 2)]; or simply [_ssText measureHeightForFrameWidth:self.frame.size.width - 6];

mta452 avatar May 05 '13 13:05 mta452

same thing still not accurate height specially in long text

also I faced same problem mentioned above some words at the end of the line are clipped or the last char was missed

ZainabA avatar May 05 '13 16:05 ZainabA

I've tested with the above font and text and it has been working all right. almousa1990! Are you still facing the same problem?

ZainabA! I'll have to take a look at your font, text and modified class. Then I'll be able to say something.

mta452 avatar May 06 '13 11:05 mta452

Thank you Mohammad the problem was with the padding as you mentioned, it works as a charm now.

almousa1990 avatar May 06 '13 11:05 almousa1990

Glad to hear that :)

mta452 avatar May 06 '13 11:05 mta452

my font is (UthmanicHafs1 Ver09.otf ) I define the label like this

SSLabel *label = nil; label = [[SSLabel alloc] initWithFrame:CGRectMake(0,0, CELL_CONTENT_WIDTH, 0)];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; label.font = font; label.textAlignment=NSTextAlignmentCenter; label.text=text;

and I create getHeight method in SSLabel class and I use it to return the height of label to use it to draw the cell

-(int)getHeight{

return  [_ssText measureHeightForFrameWidth:self.frame.size.width - (PADDING * 2)];

}

these are screen shots show how text exceed the cell screen shot 2013-05-07 at 6 11 54 pm screen shot 2013-05-07 at 6 12 30 pm

and here 2 chars are missed in the end of word screen shot 2013-05-07 at 6 12 53 pm

ZainabA avatar May 07 '13 15:05 ZainabA

I use the same font and it works correctly, maybe the CELL_CONTENT_WIDTH is not correct.

For the other problem it is a bug that happens sometimes with words that ends with "ر", but you can solve the problem by adding a space after the word.

almousa1990 avatar May 07 '13 15:05 almousa1990

thats right the space fixed the missed char thanks :)

about CELL_CONTENT_WIDTH how may be incorrect? I try change the value but same thing

I read the return value from( getHight)and from( _measuredHeight inside generateCachedPages method in SSLabel class ) by NSLog
in getHight the value was 6785 whereas in _measuredHeight was 7242

there is big difference !!

ZainabA avatar May 07 '13 16:05 ZainabA

Do you call getHeight after you set the font and the size?

almousa1990 avatar May 07 '13 16:05 almousa1990

yes

ZainabA avatar May 07 '13 16:05 ZainabA

Hi, I have some issue with symbole of arabic text. new

i am using KFGQPCUthmanTahaNaskh-Bold font , please help

Thanks Swatantra

swatantrasingh avatar Jul 12 '13 08:07 swatantrasingh

Please check the text in TextEdit with same font and let me know if it is different.

mta452 avatar Jul 12 '13 09:07 mta452

But when i choose other font it show correct like. 2

swatantrasingh avatar Jul 12 '13 11:07 swatantrasingh

Positioning information is read from font file and every glyph is positioned according to that. Therefore your problem lies in the font and not in the code.

mta452 avatar Jul 12 '13 13:07 mta452

Thanks ....

swatantrasingh avatar Jul 12 '13 15:07 swatantrasingh

Hi Muhammad Tayyab Akram; Can you suggest me any good font which have no issue with this library.

Thanks

swatantrasingh avatar Jul 17 '13 09:07 swatantrasingh