Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 21a3f61

Browse files
aballwayRaj Seshasankaran
authored andcommitted
Fix infinite loop in __CreateDWriteTextLayout (#1306)
* Fix infinite loop in __CreateDWriteTextLayout * Clang format acting up
1 parent f69ac79 commit 21a3f61

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Frameworks/CoreText/DWriteWrapper_CoreText.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ bool _CloneDWriteGlyphRun(_In_ DWRITE_GLYPH_RUN const* src, _Out_ DWRITE_GLYPH_R
204204
for (size_t i = 0; i < [subString length]; i += attributeRange.length) {
205205
NSDictionary* attribs = [static_cast<NSAttributedString*>(string) attributesAtIndex:i + range.location
206206
longestEffectiveRange:&attributeRange
207-
inRange:{ i, [subString length] }];
207+
inRange:{ i + range.location, [subString length] }];
208208

209209
const DWRITE_TEXT_RANGE dwriteRange = { attributeRange.location, attributeRange.length };
210210

tests/unittests/CoreText/CTFramesetterTests.mm

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
static const float c_errorDelta = 0.0005f;
2424

25-
static NSAttributedString* getAttributedString(NSString* str) {
25+
static NSMutableAttributedString* getAttributedString(NSString* str) {
2626
UIFontDescriptor* fontDescriptor = [UIFontDescriptor fontDescriptorWithName:@"Times New Roman" size:40];
2727
UIFont* font = [UIFont fontWithDescriptor:fontDescriptor size:40];
2828

@@ -103,4 +103,28 @@
103103
EXPECT_EQ(5L, CFArrayGetCount(CTFrameGetLines(frame)));
104104
CFRelease(frame);
105105
CGPathRelease(path);
106+
}
107+
108+
TEST(CTFramesetter, ShouldBeAbleToCreateMultipleFramesFromSameFramesetter) {
109+
NSMutableAttributedString* attrString = getAttributedString(@"ABCDEFGHIJ");
110+
[attrString addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, 7)];
111+
CFAttributedStringRef string = (__bridge CFAttributedStringRef)attrString;
112+
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(string);
113+
CFAutorelease(framesetter);
114+
CGPathRef path = CGPathCreateWithRect(CGRectMake(0, 0, FLT_MAX, FLT_MAX), nullptr);
115+
CTFrameRef firstFrame = CTFramesetterCreateFrame(framesetter, { 0, 5 }, path, nullptr);
116+
EXPECT_NE(nil, firstFrame);
117+
118+
CTFrameRef secondFrame = CTFramesetterCreateFrame(framesetter, { 1, 8 }, path, nullptr);
119+
EXPECT_NE(nil, secondFrame);
120+
121+
CTFrameRef thirdFrame = CTFramesetterCreateFrame(framesetter, { 8, 2 }, path, nullptr);
122+
EXPECT_NE(nil, thirdFrame);
123+
124+
CTFrameRef fullFrame = CTFramesetterCreateFrame(framesetter, {}, path, nullptr);
125+
EXPECT_NE(nil, fullFrame);
126+
CFRelease(firstFrame);
127+
CFRelease(secondFrame);
128+
CFRelease(thirdFrame);
129+
CFRelease(fullFrame);
106130
}

0 commit comments

Comments
 (0)