• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[SOLVED] Re: Properly wrapping non-contiguous NSTextViews
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED] Re: Properly wrapping non-contiguous NSTextViews


  • Subject: [SOLVED] Re: Properly wrapping non-contiguous NSTextViews
  • From: Nick Zitzmann <email@hidden>
  • Date: Wed, 17 Aug 2011 14:08:10 -0600

On Aug 17, 2011, at 10:59 AM, Ross Carter wrote:

> OK, I see the problem. It looks like your source text was copied from a web page. (Fonts Arial and Verdana are a clue.) There is something peculiar in your text formatting. I'll bet that the web page embedded that text in a table and the conversion from web to RTF has left some table artifacts in the formatting. The NSParagraphStyle settings in your RTF document look like this:
>
> NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 16/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n), DefaultTabInterval 36, Blocks (\n    \"<NSTextTableBlock: 0x14aa840>\"\n), Lists (null), BaseWritingDirection 0, HyphenationFactor 0, TighteningFactor 0.05, HeaderLevel 0";
>
> Notice the NSTextTableBlock object. It should not be there.
>
> Also, the minimum line height setting of 16 points is a relic of web layout that is not particularly useful in traditional text layout (IMHO), although is not a problem per se.
>
> I ran the RTF doc through TextMate to remove all the formatting, pasted it in TextEdit, added back the formatting by hand, and the problem was gone. You could do this in code; just set NSParagraphStyle textBlocks to nil. Maybe while you're at it, set minimumLineHeight to 0 and, if you want more spacing, set lineHeightMultiple to 1.1 or thereabouts.


Thank you very much for your help. Removing the text blocks did indeed fix the problem; I would've never guessed that would be the problem. Here is a category method that applies the solution when called, in case anyone else ever runs into this problem with their own non-contiguous series of text views:

@implementation NSMutableAttributedString (PageViewExtension)

- (void)fixAttributesForDisplayInPageView
{
	NSMutableSet *weDidTheseAlready = [NSMutableSet set];

	[self beginEditing];
	[self enumerateAttribute:NSParagraphStyleAttributeName inRange:NSMakeRange(0UL, self.length) options:0UL usingBlock:^(id value, NSRange range, BOOL *stop){
		NSMutableParagraphStyle *alteredStyle = [value mutableCopy];
		NSValue *rangeValue = [NSValue valueWithRange:range];

		alteredStyle.textBlocks = nil;	// remove text blocks; they cause text to get cut off during pagination
		alteredStyle.minimumLineHeight = 0.0;
		[self addAttribute:NSParagraphStyleAttributeName value:alteredStyle range:range];
		[alteredStyle release];
		if ([weDidTheseAlready containsObject:rangeValue])
			*stop = YES;
		else
			[weDidTheseAlready addObject:rangeValue];
	}];
	[self endEditing];
}

@end

Nick Zitzmann
<http://www.chronosnet.com/>

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Properly wrapping non-contiguous NSTextViews (From: Nick Zitzmann <email@hidden>)
 >Re: Properly wrapping non-contiguous NSTextViews (From: Ross Carter <email@hidden>)
 >Re: Properly wrapping non-contiguous NSTextViews (From: Nick Zitzmann <email@hidden>)
 >Re: Properly wrapping non-contiguous NSTextViews (From: Martin Wierschin <email@hidden>)
 >Re: Properly wrapping non-contiguous NSTextViews (From: Nick Zitzmann <email@hidden>)
 >Re: Properly wrapping non-contiguous NSTextViews (From: Martin Wierschin <email@hidden>)
 >Re: Properly wrapping non-contiguous NSTextViews (From: Nick Zitzmann <email@hidden>)
 >Re: Properly wrapping non-contiguous NSTextViews (From: Ross Carter <email@hidden>)
 >Re: Properly wrapping non-contiguous NSTextViews (From: Nick Zitzmann <email@hidden>)
 >Re: Properly wrapping non-contiguous NSTextViews (From: Ross Carter <email@hidden>)
 >Re: Properly wrapping non-contiguous NSTextViews (From: Nick Zitzmann <email@hidden>)
 >Re: Properly wrapping non-contiguous NSTextViews (From: Ross Carter <email@hidden>)

  • Prev by Date: Re: August Cocoaheads - Silicon Valley Meeting
  • Next by Date: Re: How can I prevent drag-and-drop initiation in an NSTextField
  • Previous by thread: Re: Properly wrapping non-contiguous NSTextViews
  • Next by thread: Re: Properly wrapping non-contiguous NSTextViews
  • Index(es):
    • Date
    • Thread