Skip navigation.
 
mlRe: Printing in cocoa
FROM : Jae Ho Lee
DATE : Fri Nov 29 20:07:02 2002

On 2002.11.29 8:54 PM, "Andrew Yager" <<email_removed>> wrote:

> Hi,
>
> I¡¯m developing a custom printing class for a NSTableView in Cocoa.
>
> The problem I have is that no matter what co-ordinates I put into
> drawPageBorderWithSize, it always seems to print at the bottom of the
> page... It's like it's being told to draw starting half way down the page.
> Does any one know why/what else I have to implement/what I'm doing wrong?
>

I haven't used '-drawPageBorderWithSize:' but if the 'theTitle' and
'theDate' you are drawing is always drawn at the bottom of the 'theRect',
then you need to flip 'JgScriptPrintView' by adding '-(BOOL)isFlipped'
method returing YES.

Regards,

Jae Ho

> It's quite frustrating as I'm sure you can all imagine :-)
>
> Thanks in advance,
>
> Adrew
>
> Here is the code
>
> --
>
> #import "JgScriptPrintView.h"
>
> @implementation JgScriptPrintView
>
> -(id) initWithFrame:(NSRect) theRect
> {
>
>  [super initWithFrame:theRect];
>  theTitle = [[NSMutableAttributedString alloc] initWithString:@""];
>  theDate = [[NSMutableAttributedString alloc] initWithString:@""];
>  return self;
> }
>
> -(NSTableView*) tableView
> {
>  return self;
> }
>
> -(void) setPrintInfo:(NSPrintInfo*) theInfo
> {
>  thePrintInfo = theInfo;
> }
>
> -(void)setTitle:(NSString*) theString
> {
>  [theTitle setAttributedString:[[NSAttributedString alloc]
> initWithString:theString]];
>  [theTitle addAttribute:NSFontAttributeName value:[NSFont
> fontWithName:@"Arial Bold" size:16.0] range:NSMakeRange(0,[theString
> length])];
> }
>
> -(void)setStartTime:(NSString*) theString
> {
>  [theDate setAttributedString:[[NSAttributedString alloc]
> initWithString:theString]];
>  [theDate addAttribute:NSFontAttributeName value:[NSFont
> fontWithName:@"Arial Italic" size:10.0] range:NSMakeRange(0,[theString
> length])];
> }
>
> -(void) awakeFromNib
> {
>  NSTableColumn* theColumn=[[NSTableColumn alloc]
> initWithIdentifier:@"Start"];
>  [[theColumn dataCell] setFont:[NSFont fontWithName:@"Helvetica"
> size:10]];
>  [theColumn setHeaderCell:[[NSCell alloc] initTextCell:@"Start Time"]];
>  [theColumn setWidth:40];
>  [self addTableColumn:theColumn];
>  theColumn=[[NSTableColumn alloc] initWithIdentifier:@"Duration"];
>  [[theColumn dataCell] setFont:[NSFont fontWithName:@"Helvetica"
> size:10]];
>  [theColumn setHeaderCell:[[NSCell alloc] initTextCell:@"Duration"]];
>  [theColumn setWidth:50];
>  [self addTableColumn:theColumn];
>  theColumn=[[NSTableColumn alloc] initWithIdentifier:@"Name"];
>  [[theColumn dataCell] setFont:[NSFont fontWithName:@"Helvetica"
> size:10]];
>  [theColumn setHeaderCell:[[NSCell alloc] initTextCell:@"Name"]];
>  [theColumn setWidth:100];
>  [self addTableColumn:theColumn];
>  theColumn=[[NSTableColumn alloc] initWithIdentifier:@"Owner"];
>  [[theColumn dataCell] setFont:[NSFont fontWithName:@"Helvetica"
> size:10]];
>  [theColumn setHeaderCell:[[NSCell alloc] initTextCell:@"Owner"]];
>  [theColumn setWidth:60];
>  [self addTableColumn:theColumn];
>  theColumn=[[NSTableColumn alloc] initWithIdentifier:@"Description"];
>  [[theColumn dataCell] setFont:[NSFont fontWithName:@"Helvetica"
> size:10]];
>  [theColumn setHeaderCell:[[NSCell alloc] initTextCell:@"Description"]];
>  [self addTableColumn:theColumn];
> }
>
> -(void) print:(id) sender
> {
>  [super print:sender];
> }
>
> - (void)drawPageBorderWithSize:(NSSize)borderSize
> {
>  //NSTextView* theString = [[NSText alloc]
> initWithFrame:NSMakeRect(0,0,borderSize.width,borderSize.height)];
>  [self lockFocus];
>  NSLog(@"%f, %f", borderSize.width, borderSize.height);
>  NSRect theRect;
>  theRect.size.width=borderSize.width;
>  theRect.size.height=borderSize.height;
>  theRect.origin.x=50;
>  theRect.origin.y=100;
>  //[theTitle
> drawInRect:NSMakeRect(0,-(borderSize.height/2),borderSize.width,24)];
>  //[theDate
> drawInRect:NSMakeRect(0,-(borderSize.height/2)+22,borderSize.width,12)];
>  [theTitle drawInRect:theRect];
>  theRect.origin.y+=28;
>  [theDate drawInRect:theRect];
>  [self unlockFocus];
>  //[theString release];
> }
>
> -(NSRect)rectForPage:(int)pageNum
> {
>  NSRect rect;

>  rect.size.width = [self bounds].size.width;
>  rect.size.height = [thePrintInfo paperSize].height;
>  rect.origin.x = [self bounds].origin.x;
>  rect.origin.y = (pageNum-1) * rect.size.height;
>  NSLog(@"%f - %f %f - %f", rect.size.width, rect.size.height,
> rect.origin.x, rect.origin.y);
>  return rect;
> }
>
> -(BOOL)knowsPageRange:(NSRangePointer)range
> {
>  range->location=1;
>  range->length=1;
>  return YES;
> }
>
> - (void)beginDocument
> {
>  [super beginDocument];
>  NSTableColumn* theCol = [self tableColumnWithIdentifier:@"Description"];
>  int newWidth = [thePrintInfo paperSize].width-[thePrintInfo
> leftMargin]-[thePrintInfo rightMargin];
>  [theCol setWidth:newWidth];
> }
>
>
>
> @end
>
> --
> ___________________
> Andrew Yager
> Real World Technology Solutions
> Real People, Real SolUtions (tm)
> ph: (02) 9945 2567 fax: (02) 9945 2566
> mob: 0405 15 2568
> http://www.rwts.com.au/
> _________________________
>
> _______________________________________________
> MacOSX-dev mailing list
> <email_removed>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev




Related mailsAuthorDate
mlPrinting in cocoa Andrew Yager Nov 29, 03:56
mlRe: Printing in cocoa Jae Ho Lee Nov 29, 20:07