Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
[TextKit] Fix text layout issue for CJK laungages (#3026)
Browse files Browse the repository at this point in the history
* [TextKit] Fix text layout issue for CJK laungages

* [ASTextKitContext] Delay filling _textStorage with attributedString until calling addLayoutManager.
  • Loading branch information
yxztj authored and Adlai Holler committed Feb 15, 2017
1 parent a6e7490 commit 8e18f15
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion AsyncDisplayKit/TextKit/ASTextKitContext.mm
Expand Up @@ -39,10 +39,18 @@ - (instancetype)initWithAttributedString:(NSAttributedString *)attributedString
__instanceLock__ = std::make_shared<ASDN::Mutex>();

// Create the TextKit component stack with our default configuration.
_textStorage = (attributedString ? [[NSTextStorage alloc] initWithAttributedString:attributedString] : [[NSTextStorage alloc] init]);

_textStorage = [[NSTextStorage alloc] init];
_layoutManager = [[ASLayoutManager alloc] init];
_layoutManager.usesFontLeading = NO;
[_textStorage addLayoutManager:_layoutManager];

// Instead of calling [NSTextStorage initWithAttributedString:], setting attributedString just after calling addlayoutManager can fix CJK language layout issues.
// See https://github.com/facebook/AsyncDisplayKit/issues/2894
if (attributedString) {
[_textStorage setAttributedString:attributedString];
}

_textContainer = [[NSTextContainer alloc] initWithSize:constrainedSize];
// We want the text laid out up to the very edges of the container.
_textContainer.lineFragmentPadding = 0;
Expand Down

0 comments on commit 8e18f15

Please sign in to comment.