From 8abb202934eac50e08c19a6fe011a5ed019f6fb5 Mon Sep 17 00:00:00 2001 From: Nicola Pero Date: Sun, 2 Dec 2001 11:12:52 +0000 Subject: [PATCH] Fixed problem when fixing up paragraph style attributes ... would get into an infinite loop if no style was set at the beginning of paragraph git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11596 72102866-910b-0410-8b05-ffd578937521 --- Source/NSAttributedString.m | 54 ++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index 211f20662..4ff6f456c 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -890,28 +890,56 @@ documentAttributes: (NSDictionary **)dict NSRange found; unsigned end; - // Extend loc to take in entire paragraph if necessary. + /* Extend loc to take in entire paragraph if necessary. */ r = [str lineRangeForRange: NSMakeRange (loc, 1)]; end = NSMaxRange (r); - // get the style in effect at the paragraph start. + /* Get the style in effect at the paragraph start. */ style = [self attribute: NSParagraphStyleAttributeName atIndex: r.location longestEffectiveRange: &found inRange: r]; - - if (style != nil && NSMaxRange (found) < end) - { - // Styles differ - add the old style to the remainder of the range. - found.location = NSMaxRange (found); - found.length = end - found.location; - [self addAttribute: NSParagraphStyleAttributeName - value: style - range: found]; - loc = end; + if (style == nil) + { + /* No style found at the beginning of paragraph. found is + the range without the style set. */ + if ((NSMaxRange (found) + 1) < end) + { + /* This skips the range with style not set, and attempts + again to set the style for the whole paragraph taking + the style at the first location with a style set. */ + loc = NSMaxRange (found) + 1; + } + else + { + /* All the paragraph without a style ... too bad, fixup + the whole paragraph using the default paragraph style. */ + [self addAttribute: NSParagraphStyleAttributeName + value: [NSParagraphStyle defaultParagraphStyle] + range: r]; + + /* Move on to the next paragraph. */ + loc = end; + } } else - loc = NSMaxRange (found); + { + if (NSMaxRange (found) < end) + { + /* Not the whole paragraph has the same style ... add + the style found at the beginning to the remainder of + the paragraph. */ + found.location = NSMaxRange (found); + found.length = end - found.location; + [self addAttribute: NSParagraphStyleAttributeName + value: style + range: found]; + } + + /* Move on to the next paragraph. */ + loc = end; + } + } }