iOS 10.3 Safari Text-Align:Justify Bug for Persian/Arabic Content

iOS 10.3 safari text-align:justify bug for Persian/Arabic content

it's officially a safari 10.1 bug . things worked fine on older safari .

chrome and other browser worked fine in same device .

you can rate this post on apple communities maybe they fix it sooner. safari 10.1 text-align: justify Bug

You can temporarily fix this problem by adding this code to your css:

@media not all and (min-resolution:.001dpcm) { @media {
.main {
text-align: right!important;
}
}}

Arabic text with custom fonts in iOS

Update:

As of iOS 7, you don't really need to use Core Text to render custom arabic font. You can use UILabel and/or UITextView with NSAttributedString. The results are the same as you get using Core-Text. However, depending on your requirements, using Core Text can still be a better option.

Update:

I've reported this as a bug to Apple, but i'm not sure when they'll add support for Arabic fonts. Currently, there's no easy way to do it. I ended up using the default system font, which is not very good.

Original Message

I did managed to build a Quran application that uses custom arabic font. I used known arabic font(s) with Core Text framework to get the desired results. You can see the results I got in the end by checking the application Quran Presenter for iPad, which is available on the App Store.

Here's some sample code to help you out:

- (CTFontRef)newCustomFontWithName:(NSString *)aFontName
ofType:(NSString *)type
attributes:(NSDictionary *)attributes {
NSString *fontPath = [[NSBundle mainBundle] pathForResource:aFontName ofType:type];

NSData *data = [[NSData alloc] initWithContentsOfFile:fontPath];
CGDataProviderRef fontProvider = CGDataProviderCreateWithCFData((CFDataRef)data);
[data release];

CGFontRef cgFont = CGFontCreateWithDataProvider(fontProvider);
CGDataProviderRelease(fontProvider);

CTFontDescriptorRef fontDescriptor = CTFontDescriptorCreateWithAttributes((CFDictionaryRef)attributes);
CTFontRef font = CTFontCreateWithGraphicsFont(cgFont, 0, NULL, fontDescriptor);
CFRelease(fontDescriptor);
CGFontRelease(cgFont);
return font;
}

- (CATextLayer *)customCATextLayer {
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:24.f], (NSString *)kCTFontSizeAttribute,
[NSNumber numberWithInt:1], (NSString *)kCTLigatureAttributeName,
nil];

CTFontRef font = [self newCustomFontWithName:@"PDMS_Saleem_QuranFont-signed"
ofType:@"ttf"
attributes:attributes];

CATextLayer *normalTextLayer = [[CATextLayer alloc] init];
normalTextLayer.font = font;
normalTextLayer.string = NSLocalizedString(@"Sample", nil);
normalTextLayer.wrapped = YES;
normalTextLayer.foregroundColor = [[UIColor blackColor] CGColor];
normalTextLayer.fontSize = 24.f;
normalTextLayer.alignmentMode = kCAAlignmentCenter;
normalTextLayer.frame = CGRectMake(0.f, 10.f, 320.f, 32.f);

CFRelease(font);
return [normalTextLayer autorelease];
}

- (void)viewDidLoad {
[super viewDidLoad];

CATextLayer *normalTextLayer = [self customCATextLayer];
[self.customView.layer addSublayer:normalTextLayer];
}

Note that I'm using CATextLayer and CTFontRef. There are a few problems with this approach.
1. You'll have to live with the issues in the selected "custom arabic font".
2. You'll have to use the arabic text that uses the extended characters supported by the font.

HTH.



Related Topics



Leave a reply



Submit