49

My app uses a UITextView to input Syriac text (Estrangelo font), but UITextView renders some letters incorrectly like this:

enter image description here

I tested it with a UILabel and a UITextView. UILabel displays it correctly, but UITextView incorrectly displays the top dots and moves them to the bottom (see the above result).

This problem only occurs in iOS 7 and does not occur in iOS 6. Please tell me if there's any way to fix the problem.

This is my test code

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
label.center = CGPointMake(self.view.center.x, self.view.center.y-40);
label.font = [UIFont fontWithName:@"East Syriac Adiabene" size:24];
label.text = @"ܩ̈ ܡ̄ ܬ̇ ܒ̃";
[self.view addSubview:label];

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
textView.center = CGPointMake(self.view.center.x, self.view.center.y+40);
textView.font = [UIFont fontWithName:@"East Syriac Adiabene" size:24];
textView.text = @"ܩ̈ ܡ̄ ܬ̇ ܒ̃";
[self.view addSubview:textView];
Abdurrahman Mubeen Ali
  • 1,331
  • 1
  • 13
  • 19
LE SANG
  • 10,955
  • 7
  • 59
  • 78
  • 5
    up voted so you get some of your bounty back and yikes, glad that problem isn't mine! – John Green Feb 10 '14 at 00:49
  • 3
    I can say with certainty, that Apple has had issues with their font system, particularly their pixel measurements and placements. After much research into the topic an personal work on MacOS and iOS, I have seen postings on apple's website to the effect they already know they have these issues. I think they are working on it, but it is an architectural problem that will most likely not be fixed in a single version, but take multiple releases to pan out all of their issues. – trumpetlicks Feb 10 '14 at 01:06
  • 1
    Have you tried the 7.1 beta? No idea if it's actually fixed, just wondering. – Kevin Feb 10 '14 at 01:15
  • it is so interesting.. i played with your code and use text field instead of text view, text field font looks correct before editing. it becomes exactly like text view after press on it... – Xu Yin Feb 10 '14 at 04:22
  • Each symbol in your string consists of two symbols: main character and modifier letter ("tilda", "dot" or "double dot"), and iOS rendering engine mixes them up (may be confused by right-left text direction). I just tried to swap characters in each pair in your example and it started looking similar to UILabel, but far from needed result. https://www.dropbox.com/s/dh4pqp19g3lmivv/Screenshot%202014-02-09%2023.26.11.png – Vadim Kalinsky Feb 10 '14 at 04:26
  • Thanks @VadimKalinsky Could you post question in detail. I use textView because my App is a keyboard, input text dynamically – LE SANG Feb 10 '14 at 04:37
  • 1
    @iMS It may be worth noting that when I pasted those characters into the url/search box in Chrome, I witnessed the same effect. I agree that it seems to be a confusion of RTL text in a LTR field. However, I experimented with setting `UITextView` to a writing direction of right-to-left, and it still renders incorrectly. This made me wonder if the string itself needs to have some RTL specifier, so I prepended the string with the [0x200F](http://www.fileformat.info/info/unicode/char/200f/index.htm) char, and still no luck. – Manny Feb 10 '14 at 16:05
  • I think it's the right moment to use your tech support from Apple if you never do, cause here it's a real big problem, good luck : https://developer.apple.com/membercenter/index.action#requestTechSupport – Tancrede Chazallet Feb 11 '14 at 09:34
  • 1
    I'm trying to create a project to look at this issue, however the Estrangelo V1.1 font that I've found doesn't work at all. Where did you download it? – tarmes Feb 11 '14 at 10:35
  • Thanks @tarmes, yes Estrangelo not work,I make a list of font. I don't check one by one. I change to "East Syriac Adiabene". The file name is SyrCOMAdiabene.otf in my code. The problem also exist. – LE SANG Feb 11 '14 at 12:47
  • if i try to delete hardcode text in from left to right it delete right to left and try right to left it's going left to left. why it is happen. – codercat Feb 11 '14 at 13:07
  • This language order from right to left like Arabic @iDev – LE SANG Feb 11 '14 at 13:09
  • so for it happens for delete the character from right side it going left to right postion. it is correct way – codercat Feb 11 '14 at 13:10
  • Yes, input and delete like Arabic. Problem in typing, from left to right and add above symbol. @iDev – LE SANG Feb 11 '14 at 13:13
  • this issue is only happen in ios 7 do you know this information – codercat Feb 11 '14 at 13:45
  • 2
    I would recommend you file a bug at http://bugreport.apple.com – fzwo Feb 11 '14 at 14:56
  • What do you get using CoreText to draw the string? – Abhi Beckert Feb 12 '14 at 06:34
  • I just input text from custom keyboard to UITextView and this problem happen, I'm not using Coretext @AbhiBeckert – LE SANG Feb 12 '14 at 06:36
  • 1
    @iMS yeah I know... but I suspect you will have to use CoreText to solve your problem. Unfortunately that that might require weeks of programming on your part. CoreText is a complicated API to work with. – Abhi Beckert Feb 12 '14 at 06:49
  • @iMS - your attachment is not working .. :) –  Feb 13 '14 at 08:16
  • I've been reverse engineering this. It seems `UILabel` leaves layout to CoreText, while `UITextView`, using `NSLayoutManager`, does the layout itself incorrectly. This is the reason for the inconsistent behavior. – Léo Natan Feb 14 '14 at 17:40

2 Answers2

6

I debugged this issue a little, and it seems to be a bug in the way NSLayoutManager layouts the text. As other answers pointed out, UITextView is build around TextKit since iOS7, and thus uses NSLayoutManager internally to layout text. UILabel uses Core Text to layout text directly. Both eventually use Core Text to render the glyphs.

You should open a bug report with Apple and post the number so people can duplicate it. The issue has not been fixed so far in iOS7.1 betas.

As a workaround, you can replace UITextView with other Core Text alternative editors, which layout and render directly with Core Text, where the issue does not exist.

I tested SECoreTextView, and it shows the text correctly. It implements a similar API to UITextView but internally uses Core Text.

Here is how it looks after swapping UITextView with SECoreTextView:

SETextView *textView = [[SETextView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
textView.center = CGPointMake(self.view.center.x, self.view.center.y+40);
textView.font = [UIFont fontWithDescriptor:desc size:24];
textView.text = @"ܩ̈ ܡ̄ ܬ̇ ܒ̃";
textView.textColor = [UIColor blackColor];
textView.backgroundColor = [UIColor whiteColor];
textView.editable = YES;

[self.view addSubview:textView];

Using Core Text, the layout issue does not exist.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
2

Some days ago, I had the same problem as yours in iOS 7 (but the font was different). I set the FONT after setting the TEXT and it worked for me. So for your case:

textView.text = @"ܩ̈ ܡ̄ ܬ̇ ܒ̃"; // Setting the text.
textView.font = [UIFont fontWithName:@"East Syriac Adiabene" size:24]; // Setting the font and it's size.

It may seem silly, but it worked for me.

Also see this question/answer. There are many tips for using custom fonts with UITextView, which may be helpful for you.

EDIT :

iOS 7 also introduced a new selectable property on the UITextView for enabling text selection. So make sure you have done the following:

self.textField.editable = YES;
self.textField.selectable = ON;
Community
  • 1
  • 1
iPatel
  • 46,010
  • 16
  • 115
  • 137