• 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
Custom printing problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Custom printing problems


  • Subject: Custom printing problems
  • From: Jonathan Jackel <email@hidden>
  • Date: Tue, 9 Dec 2003 21:12:23 -0500

I am using a custom view to set up a special layout for my document
when it prints. I want two columns on each page. Right now I'm
working on the one on the right, and I can't get it, well, right.

Basically I set up a text view to hold the text that appears on each
printed page, with a frame that covers the area for the righthand
column. I create the view and fill it with an attributed string. I
figure out how much of the string is visible, save the invisible part
in an attributed string variable, and then delete the invisible part
from the text view. Then I go to the next page, laying out additional
text views as necessary. The code appears below.

This works pretty well, but I occasionally get very strange results.
For instance, sometimes what should be the last line of the third page
is printed above the first line on the second page. There has to be a
reasonable explanation for this, but I don't know what it could be.
Any ideas? BTW, if anyone has a better approach to multi-column
printing, I'd love to hear it.

Here's my code:

- (void)setUp
{
NSRange realGlyphRange;
NSRange glyphRange;
NSRange charRange;
NSRange destroy;
int countPages = 1;
NSTextView *anotherView;
NSTextContainer *container;
NSTextStorage *storage;
NSLayoutManager *manager;
NSTextStorage *mainStorage = [[self sourceView] textStorage];
//sourceView is the main text view for my doc
NSAttributedString *remaining = [[[mainStorage
attributedSubstringFromRange:NSMakeRange(0, [mainStorage length])]
copy] autorelease];
while ([remaining length])
{
NSRect tempFrame = NSMakeRect(pageWidth/2, pageHeight *
(countPages - 1), pageWidth/2, pageHeight - 36);
NSLog(@"%@", NSStringFromRect(tempFrame));
anotherView = [[[NSTextView alloc] initWithFrame:tempFrame]
autorelease];
[self addSubview:anotherView];
container = [anotherView textContainer];
storage = [anotherView textStorage];
manager = [anotherView layoutManager];
[storage setAttributedString:remaining];
glyphRange = [manager glyphRangeForBoundingRect:[anotherView
bounds]
inTextContainer:container];
charRange = [manager characterRangeForGlyphRange:glyphRange

actualGlyphRange:&realGlyphRange];
if (charRange.length < [storage length])
{
destroy = NSMakeRange(charRange.length, [storage length] -
charRange.length);
remaining = [[[storage
attributedSubstringFromRange:destroy] copy] autorelease];
[storage replaceCharactersInRange:destroy
withString:@""];
countPages++;
} else {
remaining = [[[NSAttributedString alloc]
initWithString:@""] autorelease];
}
}
[self setPages:countPages];
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Custom printing problems
      • From: Buddy Kurz <email@hidden>
  • Prev by Date: Re: Xcode style deployment: debug-symbols?
  • Next by Date: Problem with com.apple.systempreferences.plist
  • Previous by thread: My NSQuicktimeView shows up.. once...
  • Next by thread: Re: Custom printing problems
  • Index(es):
    • Date
    • Thread