mta452 / SheenFigureLegacy

A library to render arabic/urdu fonts on smartphones.
Apache License 2.0
30 stars 6 forks source link

Text height and some other issues #8

Open almousa1990 opened 11 years ago

almousa1990 commented 11 years ago

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 commented 11 years ago

I am using the library with core graphics.

mta452 commented 11 years ago

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.

almousa1990 commented 11 years ago

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 commented 11 years ago

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

mta452 commented 11 years ago

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.

almousa1990 commented 11 years ago

Thank you.

mta452 commented 11 years ago

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

almousa1990 commented 11 years ago

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

mta452 commented 11 years ago

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.

almousa1990 commented 11 years ago

Everything seems to work great.

Thank you!

ZainabA commented 11 years ago

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

almousa1990 commented 11 years ago

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)

ZainabA commented 11 years ago

thank you

it works but unfortunately as you said is not accurate

almousa1990 commented 11 years ago

I hope Mohammad can look at this issue.

mta452 commented 11 years ago

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];

ZainabA commented 11 years ago

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

mta452 commented 11 years ago

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.

almousa1990 commented 11 years ago

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

mta452 commented 11 years ago

Glad to hear that :)

ZainabA commented 11 years ago

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

almousa1990 commented 11 years ago

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.

ZainabA commented 11 years ago

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 !!

almousa1990 commented 11 years ago

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

ZainabA commented 11 years ago

yes

swatantrasingh commented 11 years ago

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

i am using KFGQPCUthmanTahaNaskh-Bold font , please help

Thanks Swatantra

mta452 commented 11 years ago

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

swatantrasingh commented 11 years ago

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

mta452 commented 11 years ago

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.

swatantrasingh commented 11 years ago

Thanks ....

swatantrasingh commented 11 years ago

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

Thanks