问题
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:
回答1:
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
来源:https://stackoverflow.com/questions/54161101/nslayoutmanager-boundingrectforglyphrangein-returns-wrong-value-for-rtl-lang