简体   繁体   中英

NSLayoutManager boundingRect(forGlyphRange:in:) returns wrong value for RTL languages

In my app, I draw custom background under lines of text in UITextView . To do so, I use boundingRect(forGlyphRange:in:) method of NSLayoutManager . It works well for LTR languages (Latin, Cyrillic, Chinese etc): 在此处输入图片说明 But if I use it for RTL texts (Hebrew, Farsi etc), the method returns wrong bounding rect (see padding on the left edge): 在此处输入图片说明

These additional paddings seem to have some logic. The first character determines the size of the padding for a line: 在此处输入图片说明

What the reason for this extra padding and how to get the correct bounding rect?

Here is a demo: https://www.dropbox.com/s/bpsr7bhhd7gqm2z/hebrew.zip?dl=0

UPD: seems this function gives a wrong result for all alphabets that use, I don't know how it's called, mutating characters. Devanagari for example:

在此处输入图片说明

Seems boundingRect(forGlyphRange:in:) counts exactly glyphs with their spaces for attaching neighboring characters but not the final composed piece of text which gives extra paddings.

在此处输入图片说明

I solved my issue but employing boundingRect function of NSString . Check the result: https://www.dropbox.com/s/qq5lmo8fsozjqml/hebrew%202.zip?dl=0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM