Можно ли изменить высоту заголовка NSTextView? - PullRequest
1 голос
/ 27 января 2012

Я сохраняю PDF из NSTextview и помещаю логотип в заголовок.Я переопределил pageHeader, и логотип появляется, но он обрезается.

Можно ли изменить высоту заголовка NSTextView?

Спасибо!

Частичный код:

-(IBAction)impLaudo:(id)sender 
{
    NSPrintInfo *printInfo;
    NSPrintInfo *sharedInfo;
    NSPrintOperation *printOp;
    NSMutableDictionary *printInfoDict;
    NSMutableDictionary *sharedDict;

    sharedInfo = [NSPrintInfo sharedPrintInfo];
    sharedDict = [sharedInfo dictionary];
    printInfoDict = [NSMutableDictionary dictionaryWithDictionary:sharedDict];

    [printInfoDict setObject:NSPrintSaveJob forKey:NSPrintJobDisposition];
    [printInfoDict setObject:[[dirLaudos stringByAppendingString:[estudo stringValue]] stringByAppendingString:@".pdf"] forKey:NSPrintSavePath];

    printInfo = [[NSPrintInfo alloc] initWithDictionary: printInfoDict];
    [printInfo setHorizontalPagination: NSClipPagination];
    [printInfo setVerticalPagination: NSAutoPagination];
    [printInfo setVerticallyCentered:NO];
    [[printInfo dictionary] setValue:[NSNumber numberWithBool:YES] forKey:NSPrintHeaderAndFooter];

    printOp = [NSPrintOperation printOperationWithView:textView printInfo:printInfo];
    [printOp setShowsPrintPanel:NO];
    [printOp runOperation];    
}


@implementation MyTextView 

- (NSAttributedString *)pageHeader
{
    // Adicionando cabeçalho
    NSAttributedString *theHeader = nil;

    NSImage * pic = [[NSImage alloc] initWithContentsOfFile:[dirLayout stringByAppendingString:@"cabecalho.jpg"]];
    NSTextAttachmentCell *attachmentCell = [[NSTextAttachmentCell alloc] initImageCell:pic];
    NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
    [attachment setAttachmentCell: attachmentCell ];
    theHeader = [NSAttributedString  attributedStringWithAttachment: attachment];
    return theHeader;
}

@end    

1 Ответ

1 голос
/ 28 января 2012

Вместо переопределения -pageHeader следует переопределить -drawPageBorderWithSize:, что позволяет рисовать дополнительные метки на странице во время печати. ​​

Параметр Size представляет собой структуру NSSize, содержащую размертекущая логическая страница.Все, что вам нужно сделать, это нарисовать ваш логотип в правильном месте:

- (void)drawPageBorderWithSize:(NSSize)pageSize
{
    [super drawPageBorderWithSize:pageSize];
    //draw your logo
    NSPoint offset = NSMakePoint(100.0, 100.0);
    NSImage* logo = [NSImage imageNamed:@"logo"];
    NSSize logoSize = [logo size];
    NSPoint imageOrigin = NSMakePoint(offset.x, pageSize.height - (offset.y + logoSize.height));
    [self lockFocus];
    [logo drawInRect:NSMakeRect(imageOrigin.x, imageOrigin.y, logoSize.width, logoSize.height)
            fromRect:NSZeroRect 
           operation:NSCompositeSourceOver
            fraction:1.0 
      respectFlipped:YES 
               hints:nil];
    [self unlockFocus];
}
...