mta452 / SheenFigureLegacy

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

TextColor issue #4

Closed roula-misrabi closed 11 years ago

roula-misrabi commented 11 years ago

Hi there,

Thank you for this powerful library, it helped me a lot with loading custom fonts with arabic texts, for my iOS app.

But There seems to be a problem with setting the text color, I noticed that whatever UIColor I use, the text always appears as black or red.

Is there anything that may fix this problem?? I want my text to be white, how would I do that ?

Thanks, Roula.

mta452 commented 11 years ago

Hi,

This problem occur when sheenfigure is used with freetype. You can use sheenfigure with core graphics to avoid this issue.

In order to use SheenFigure-CG, follow these steps: 1) Remove SheenFigureFT project and instead add SheenFigureCG project and also link its library. 2) Open SheenFigure-iOS-Prefix.pch and remove or comment the line containing "#define USE_FREETYPE"

Regards, Tayyab

roula-misrabi commented 11 years ago

Thank you so much! that helped a lot :)

But I would like to ask about something else: I use your library in a non-arc project. I have a viewController that I'm setting the SFLabel to its navigationItem.titleView. I have a button that returns back to root view in navigation controller using popToRootViewControllerAnimated.

After the view is poped out, the library crashes on deallocating the SFLabel either on SFFont.c ---> SFFontRelease ---> sfFont->_retainCount--;

or in SFGSUBData.c ---> SFFreeContextSubst --> inside the loop contained under #ifdef GSUB_CONTEXT_FORMAT2

any idea?

mta452 commented 11 years ago

It seems that your font uses context substitution tables. Note that they are not supported because I could not find a font using them with which I could test. Can you send me your font, so that I can test it?

As of now you can try open SheenFigure\SFConfig.h and comment the lines: 1) #define GSUB_CONTEXT_FORMAT1 2) #define GSUB_CONTEXT_FORMAT2 3) #define GSUB_CONTEXT_FORMAT3 4) #define GSUB_CHAINING_CONTEXT_FORMAT1 5) #define GSUB_CHAINING_CONTEXT_FORMAT2

Let me know if this solves crashing.

roula-misrabi commented 11 years ago

I applied these changes to SheenFigure\SFConfig.h, and first it seemed to be fixed, but as I repeated showing/ hiding the view for multiple times, it crashed again.

I've uploaded the font here: http://www.fileswap.com/dl/WiQsrwx2s/

mta452 commented 11 years ago

Can you send your project? I can't figure what is causing problems on your side.

roula-misrabi commented 11 years ago

Here's a sample application of how I use your library: http://www.fileswap.com/dl/hWPIxs1eQ8/

All of the 4 buttons in main view can show a view controller that contains a label called titleLabel of type SFLabel, and this label is set to navigationItem.titleView in SetTopTitle() method.

Also, I've placed a disabled break point at the line of code that causes the crash.

I really appreciate your help, thank you.

mta452 commented 11 years ago

Whoops. The problem was very minor one. Just add the line "sfFont->_parent = NULL;" in the function "SFFontCreate" of SheenFigure/SFGraphics/SFFont.c at line no 161.

You are setting font again and again. That's not good practice. It will have bad performance because font is loaded in RAM when it is created. Instead create it once when application runs, store it in a global variable for use and release it when application closes.  You can create instance of font like this: SFFontRef font = SFFontCreateWithFileName((CFStringRef)@"bader_al_gordabia2_0", (CFStringRef)@"otf", 36);

Set it like this: [titleLabel setFont:font];

And Release it like this: SFFontRelease(font);

Anyhow your font is not very large so your existing code should also cause no problems.

Also note that your font uses context substitution tables but they are not supported. So you may experience different shapes of letters at some point. I'll be adding support for it in next few days as I have a test specimen now :)

roula-misrabi commented 11 years ago

Great!

Finally, every thing goes fine.

Thank you so much, I also followed your point of setting the font just once in may application using a static font variable.

But my last question is, shall I keep the 5 lines you talked about earlier commented out? 1) #define GSUB_CONTEXT_FORMAT1 2) #define GSUB_CONTEXT_FORMAT2 3) #define GSUB_CONTEXT_FORMAT3 4) #define GSUB_CHAINING_CONTEXT_FORMAT1 5) #define GSUB_CHAINING_CONTEXT_FORMAT2

Thank you for this great effort :)

mta452 commented 11 years ago

Glad that you were able to make everything fine.

Regarding the lines you're talking about; Yes, keep them commented.

roula-misrabi commented 11 years ago

Ok I will. Thanks :)