Revision: 4741
http://skim-app.svn.sourceforge.net/skim-app/?rev=4741&view=rev
Author: hofman
Date: 2008-10-05 16:01:28 +0000 (Sun, 05 Oct 2008)
Log Message:
-----------
Add printing support for notes document.
Modified Paths:
--------------
trunk/SKNotesDocument.m
trunk/Skim.xcodeproj/project.pbxproj
Added Paths:
-----------
trunk/BDSKPrintableView.h
trunk/BDSKPrintableView.m
trunk/MultiplePageView.h
trunk/MultiplePageView.m
Added: trunk/BDSKPrintableView.h
===================================================================
--- trunk/BDSKPrintableView.h (rev 0)
+++ trunk/BDSKPrintableView.h 2008-10-05 16:01:28 UTC (rev 4741)
@@ -0,0 +1,72 @@
+//
+// BDSKPrintableView.h
+// Bibdesk
+//
+// Created by Adam Maxwell on 09/02/05.
+/*
+ This software is Copyright (c) 2005-2008
+ Adam Maxwell. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Adam Maxwell nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import "MultiplePageView.h"
+
+typedef struct _ViewMargins {
+ float left;
+ float right;
+ float top;
+ float bottom;
+} ViewMargins;
+
[EMAIL PROTECTED] BDSKPrintableView : MultiplePageView {
+ NSScrollView *scrollView;
+ BOOL hasMultiplePages;
+ NSTextStorage *textStorage;
+ ViewMargins margins;
+
+ NSFont *currentFont;
+ NSColor *currentColor;
+}
+
+- (id)initForScreenDisplay:(BOOL)onScreen;
+
+- (NSData *)PDFDataWithAttributedString:(NSAttributedString *)attrString;
+- (NSData *)PDFDataWithString:(NSString *)aString;
+- (void)removePage;
+- (void)addPage;
+- (void)setAllMargins:(float)width;
+- (void)setFont:(NSFont *)font;
+- (void)setTextColor:(NSColor *)color;
+- (void)setString:(NSString *)aString;
+- (void)setAttributedString:(NSAttributedString *)attrString;
+
[EMAIL PROTECTED]
+
Added: trunk/BDSKPrintableView.m
===================================================================
--- trunk/BDSKPrintableView.m (rev 0)
+++ trunk/BDSKPrintableView.m 2008-10-05 16:01:28 UTC (rev 4741)
@@ -0,0 +1,263 @@
+//
+// BDSKPrintableView.m
+// Bibdesk
+//
+// Created by Adam Maxwell on 09/02/05.
+/*
+ This software is Copyright (c) 2005-2008
+ Adam Maxwell. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Adam Maxwell nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "BDSKPrintableView.h"
+
+/* Most of this code was borrowed from TextEdit. This is designed mainly to
give a PDF data representation of plain or attributed text, as the AppKit
provides no easy way to do this programmatically. Page layout features have
been overriden in order for better on-screen display, as the default margins
from NSPrintInfo are too large for many cases; pass NO to initForScreenDisplay
to get the default NSPrintInfo values (which are more appropriate for hard-copy
results). */
+
[EMAIL PROTECTED] BDSKPrintableView
+
+- (id)initWithFrame:(NSRect)frameRect{
+ return [self initForScreenDisplay:NO];
+}
+
+// designated initializer for this subclass
+- (id)initForScreenDisplay:(BOOL)onScreen{
+ if(self = ([super initWithFrame:NSZeroRect])){
+ hasMultiplePages = NO;
+
+ if(onScreen){
+ [self setAllMargins:20.0];
+ } else {
+ // set up default margin struct using super's printInfo; we don't
want to use printInfo for on-screen display in many cases, as it has a minimum
margin of 72? pts
+ margins.left = [printInfo leftMargin];
+ margins.right = [printInfo rightMargin];
+ margins.top = [printInfo topMargin];
+ margins.bottom = [printInfo bottomMargin];
+ }
+
+ scrollView = [[NSScrollView alloc] initWithFrame:NSZeroRect];
+ NSClipView *clipView = [[NSClipView alloc] initWithFrame:NSZeroRect];
+
+ [self setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
+
+ // this creates a retain cycle, see the -release override for its fix
+ [clipView setDocumentView:self];
+
+ [scrollView setContentView:clipView];
+ [clipView release]; // retained by the scroll view
+
+ textStorage = [[NSTextStorage alloc] initWithString:@""];
+ NSLayoutManager *lm = [[NSLayoutManager alloc] init];
+ [textStorage addLayoutManager:lm];
+ [lm release]; // owned by the text storage
+ [lm setDelegate:self];
+ [self addPage];
+ [self setTextColor:[NSColor blackColor]];
+ [self setFont:[NSFont userFontOfSize:0.0]];
+ }
+ return self;
+}
+
+- (void)release {
+ // Fix retain cycle through scrollView and clipView
+ if (scrollView && [self retainCount] == 2) {
+ [scrollView autorelease];
+ scrollView = nil;
+ }
+ [super release];
+}
+
+- (void)dealloc{
+ [textStorage release];
+ [super dealloc];
+}
+
+- (NSLayoutManager *)layoutManager{
+ return [[textStorage layoutManagers] objectAtIndex:0];
+}
+
+- (void)printInfoUpdated {
+ unsigned cnt, numberOfPages = [self numberOfPages];
+ NSArray *textContainers = [[self layoutManager] textContainers];
+
+ [self setPrintInfo:printInfo];
+
+ for (cnt = 0; cnt < numberOfPages; cnt++) {
+ NSRect textFrame = [self documentRectForPageNumber:cnt];
+ NSTextContainer *textContainer = [textContainers objectAtIndex:cnt];
+ [textContainer setContainerSize:textFrame.size];
+ [[textContainer textView] setFrame:textFrame];
+ }
+}
+
+- (void)addPage {
+ NSZone *zone = [self zone];
+ unsigned numberOfPages = [self numberOfPages];
+ NSSize textSize = [self documentSizeInPage];
+ NSTextContainer *textContainer = [[NSTextContainer allocWithZone:zone]
initWithContainerSize:textSize];
+ NSTextView *textView;
+ [self setNumberOfPages:numberOfPages + 1];
+ textView = [[NSTextView allocWithZone:zone] initWithFrame:[self
documentRectForPageNumber:numberOfPages] textContainer:textContainer];
+ [textView setHorizontallyResizable:NO];
+ [textView setVerticallyResizable:NO];
+ [self addSubview:textView];
+ [[self layoutManager] addTextContainer:textContainer];
+ [textView release];
+ [textContainer release];
+}
+
+- (void)removePage {
+ unsigned numberOfPages = [self numberOfPages];
+ NSArray *textContainers = [[self layoutManager] textContainers];
+ NSTextContainer *lastContainer = [textContainers
objectAtIndex:[textContainers count] - 1];
+ [self setNumberOfPages:numberOfPages - 1];
+ [[lastContainer textView] removeFromSuperview];
+ [[lastContainer layoutManager] removeTextContainerAtIndex:[textContainers
count] - 1];
+}
+
+- (void)setNumberOfPages:(unsigned int)pages{
+ [super setNumberOfPages:pages];
+ hasMultiplePages = (pages > 1);
+}
+
+- (void)layoutManager:(NSLayoutManager *)layoutManager
didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer
atEnd:(BOOL)layoutFinishedFlag {
+
+ NSArray *containers = [layoutManager textContainers];
+
+ if (!layoutFinishedFlag || (textContainer == nil)) {
+ // Either layout is not finished or it is but there are glyphs laid
nowhere.
+ NSTextContainer *lastContainer = [containers lastObject];
+
+ if ((textContainer == lastContainer) || (textContainer == nil)) {
+ // Add a new page if the newly full container is the last
container or the nowhere container.
+ // Do this only if there are glyphs laid in the last container
(temporary solution for 3729692, until AppKit makes something better available.)
+ if ([layoutManager
glyphRangeForTextContainer:lastContainer].length > 0) [self addPage];
+ }
+ } else {
+ // Layout is done and it all fit. See if we can axe some pages.
+ unsigned lastUsedContainerIndex = [containers
indexOfObjectIdenticalTo:textContainer];
+ unsigned numContainers = [containers count];
+ while (++lastUsedContainerIndex < numContainers) {
+ [self removePage];
+ }
+ }
+}
+
+- (void)setFont:(NSFont *)font{
+ if(currentFont != font){
+ [currentFont release];
+ currentFont = [font retain];
+ [textStorage addAttribute:NSFontAttributeName value:currentFont
range:NSMakeRange(0, [textStorage length])];
+ }
+}
+
+- (void)setTextColor:(NSColor *)color{
+ if(currentColor != color){
+ [currentColor release];
+ currentColor = [color retain];
+ [textStorage addAttribute:NSForegroundColorAttributeName value:color
range:NSMakeRange(0, [textStorage length])];
+ }
+}
+
+- (void)forceLayoutBeforePrinting{
+ // force layout before printing
+ unsigned len;
+ unsigned loc = INT_MAX;
+ if (loc > 0 && (len = [textStorage length]) > 0) {
+ NSRange glyphRange;
+ if (loc >= len) loc = len - 1;
+ /* Find out which glyph index the desired character index corresponds
to */
+ glyphRange = [[self layoutManager]
glyphRangeForCharacterRange:NSMakeRange(loc, 1) actualCharacterRange:NULL];
+ if (glyphRange.location > 0) {
+ /* Now cause layout by asking a question which has to determine
where the glyph is */
+ (void)[[self layoutManager]
textContainerForGlyphAtIndex:glyphRange.location - 1 effectiveRange:NULL];
+ }
+ }
+}
+
+- (void)setString:(NSString *)aString{
+ [textStorage beginEditing];
+ [[textStorage mutableString] setString:aString];
+ [textStorage addAttribute:NSFontAttributeName value:currentFont
range:NSMakeRange(0, [textStorage length])];
+ [textStorage addAttribute:NSForegroundColorAttributeName
value:currentColor range:NSMakeRange(0, [textStorage length])];
+ [textStorage endEditing];
+ [self forceLayoutBeforePrinting];
+}
+
+- (void)setAttributedString:(NSAttributedString *)attrString{
+ [textStorage beginEditing];
+ [textStorage setAttributedString:attrString];
+ [textStorage endEditing];
+ [self forceLayoutBeforePrinting];
+}
+
+- (NSData *)PDFDataWithAttributedString:(NSAttributedString *)attrString{
+ [self setAttributedString:attrString];
+ return [self dataWithPDFInsideRect:[self bounds]];
+}
+
+- (NSData *)PDFDataWithString:(NSString *)aString{
+ [self setString:aString];
+ return [self dataWithPDFInsideRect:[self bounds]];
+}
+
+// sets all margins to a uniform inset
+- (void)setAllMargins:(float)width{
+ margins.left = width;
+ margins.right = width;
+ margins.top = width;
+ margins.bottom = width;
+ [self printInfoUpdated];
+ [self setNeedsDisplay:YES];
+}
+
+- (NSSize)documentSizeInPage {
+ NSSize paperSize = [printInfo paperSize];
+ paperSize.width -= (margins.left + margins.right);
+ paperSize.height -= (margins.top + margins.bottom);
+ return paperSize;
+}
+
+- (NSRect)documentRectForPageNumber:(unsigned)pageNumber { /* First page
is page 0, of course! */
+ NSRect rect = [self pageRectForPageNumber:pageNumber];
+ rect.origin.x += margins.left;
+ rect.origin.y += margins.top;
+ rect.size = [self documentSizeInPage];
+ return rect;
+}
+
+- (NSRect)pageRectForPageNumber:(unsigned)pageNumber {
+ NSRect rect;
+ rect.size = [printInfo paperSize];
+ rect.origin = [self frame].origin;
+ rect.origin.y += ((rect.size.height + [self pageSeparatorHeight]) *
pageNumber);
+ return rect;
+}
+
[EMAIL PROTECTED]
\ No newline at end of file
Added: trunk/MultiplePageView.h
===================================================================
--- trunk/MultiplePageView.h (rev 0)
+++ trunk/MultiplePageView.h 2008-10-05 16:01:28 UTC (rev 4741)
@@ -0,0 +1,63 @@
+/*
+ MultiplePageView.h
+ Copyright (c) 1995-2005 by Apple Computer, Inc., all rights reserved.
+ Author: Ali Ozer
+
+ View which holds all the pages together in the multiple-page case
+*/
+/*
+ IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
("Apple") in
+ consideration of your agreement to the following terms, and your use,
installation,
+ modification or redistribution of this Apple software constitutes acceptance
of these
+ terms. If you do not agree with these terms, please do not use, install,
modify or
+ redistribute this Apple software.
+
+ In consideration of your agreement to abide by the following terms, and
subject to these
+ terms, Apple grants you a personal, non-exclusive license, under Apple's
copyrights in
+ this original Apple software (the "Apple Software"), to use, reproduce,
modify and
+ redistribute the Apple Software, with or without modifications, in source
and/or binary
+ forms; provided that if you redistribute the Apple Software in its entirety
and without
+ modifications, you must retain this notice and the following text and
disclaimers in all
+ such redistributions of the Apple Software. Neither the name, trademarks,
service marks
+ or logos of Apple Computer, Inc. may be used to endorse or promote products
derived from
+ the Apple Software without specific prior written permission from Apple.
Except as expressly
+ stated in this notice, no other rights or licenses, express or implied, are
granted by Apple
+ herein, including but not limited to any patent rights that may be infringed
by your
+ derivative works or by other works in which the Apple Software may be
incorporated.
+
+ The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES,
+ EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
NON-INFRINGEMENT,
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE
SOFTWARE OR ITS
+ USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
+
+ IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF
THE USE,
+ REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER
CAUSED AND
+ WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT
LIABILITY OR
+ OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#import <Cocoa/Cocoa.h>
+
[EMAIL PROTECTED] MultiplePageView : NSView {
+ NSPrintInfo *printInfo;
+ NSColor *lineColor;
+ NSColor *marginColor;
+ unsigned numPages;
+}
+
+- (void)setPrintInfo:(NSPrintInfo *)anObject;
+- (NSPrintInfo *)printInfo;
+- (float)pageSeparatorHeight;
+- (NSSize)documentSizeInPage; /* Returns the area where the document can draw
*/
+- (NSRect)documentRectForPageNumber:(unsigned)pageNumber; /* First page
is page 0 */
+- (NSRect)pageRectForPageNumber:(unsigned)pageNumber; /* First page is page 0
*/
+- (void)setNumberOfPages:(unsigned)num;
+- (unsigned)numberOfPages;
+- (void)setLineColor:(NSColor *)color;
+- (NSColor *)lineColor;
+- (void)setMarginColor:(NSColor *)color;
+- (NSColor *)marginColor;
+
[EMAIL PROTECTED]
Added: trunk/MultiplePageView.m
===================================================================
--- trunk/MultiplePageView.m (rev 0)
+++ trunk/MultiplePageView.m 2008-10-05 16:01:28 UTC (rev 4741)
@@ -0,0 +1,211 @@
+/*
+ MultiplePageView.m
+ Copyright (c) 1995-2005 by Apple Computer, Inc., all rights reserved.
+ Author: Ali Ozer
+
+ View which holds all the pages together in the multiple-page case
+*/
+/*
+ IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
("Apple") in
+ consideration of your agreement to the following terms, and your use,
installation,
+ modification or redistribution of this Apple software constitutes acceptance
of these
+ terms. If you do not agree with these terms, please do not use, install,
modify or
+ redistribute this Apple software.
+
+ In consideration of your agreement to abide by the following terms, and
subject to these
+ terms, Apple grants you a personal, non-exclusive license, under Apple's
copyrights in
+ this original Apple software (the "Apple Software"), to use, reproduce,
modify and
+ redistribute the Apple Software, with or without modifications, in source
and/or binary
+ forms; provided that if you redistribute the Apple Software in its entirety
and without
+ modifications, you must retain this notice and the following text and
disclaimers in all
+ such redistributions of the Apple Software. Neither the name, trademarks,
service marks
+ or logos of Apple Computer, Inc. may be used to endorse or promote products
derived from
+ the Apple Software without specific prior written permission from Apple.
Except as expressly
+ stated in this notice, no other rights or licenses, express or implied, are
granted by Apple
+ herein, including but not limited to any patent rights that may be infringed
by your
+ derivative works or by other works in which the Apple Software may be
incorporated.
+
+ The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES,
+ EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
NON-INFRINGEMENT,
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE
SOFTWARE OR ITS
+ USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
+
+ IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF
THE USE,
+ REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER
CAUSED AND
+ WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT
LIABILITY OR
+ OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#import <Cocoa/Cocoa.h>
+#import "MultiplePageView.h"
+
[EMAIL PROTECTED] MultiplePageView
+
+- (id)initWithFrame:(NSRect)rect {
+ if ((self = [super initWithFrame:rect])) {
+ numPages = 0;
+ [self setLineColor:[NSColor lightGrayColor]];
+ [self setMarginColor:[NSColor whiteColor]];
+ /* This will set the frame to be whatever's appropriate... */
+ [self setPrintInfo:[NSPrintInfo sharedPrintInfo]];
+ }
+ return self;
+}
+
+float defaultTextPadding(void) {
+ static float padding = -1;
+ if (padding < 0.0) {
+ NSTextContainer *container = [[NSTextContainer alloc] init];
+ padding = [container lineFragmentPadding];
+ [container release];
+ }
+ return padding;
+}
+
+- (BOOL)isFlipped {
+ return YES;
+}
+
+- (BOOL)isOpaque {
+ return YES;
+}
+
+- (void)updateFrame {
+ if ([self superview]) {
+ NSRect rect = NSZeroRect;
+ rect.size = [printInfo paperSize];
+ rect.size.height = rect.size.height * numPages;
+ if (numPages > 1) rect.size.height += [self pageSeparatorHeight] *
(numPages - 1);
+ rect.size = [self convertSize:rect.size toView:[self superview]];
+ [self setFrame:rect];
+ }
+}
+
+- (void)setPrintInfo:(NSPrintInfo *)anObject {
+ if (printInfo != anObject) {
+ [printInfo autorelease];
+ printInfo = [anObject copyWithZone:[self zone]];
+ [self updateFrame];
+ [self setNeedsDisplay:YES]; /* Because the page size or margins
might change (could optimize this) */
+ }
+}
+
+- (NSPrintInfo *)printInfo {
+ return printInfo;
+}
+
+- (void)setNumberOfPages:(unsigned)num {
+ if (numPages != num) {
+ NSRect oldFrame = [self frame];
+ NSRect newFrame;
+ numPages = num;
+ [self updateFrame];
+ newFrame = [self frame];
+ if (newFrame.size.height > oldFrame.size.height) {
+ [self setNeedsDisplayInRect:NSMakeRect(oldFrame.origin.x,
NSMaxY(oldFrame), oldFrame.size.width, NSMaxY(newFrame) - NSMaxY(oldFrame))];
+ }
+ }
+}
+
+- (unsigned)numberOfPages {
+ return numPages;
+}
+
+- (float)pageSeparatorHeight {
+ return 5.0;
+}
+
+- (void)dealloc {
+ [printInfo release];
+ [super dealloc];
+}
+
+- (NSSize)documentSizeInPage {
+ NSSize paperSize = [printInfo paperSize];
+ paperSize.width -= ([printInfo leftMargin] + [printInfo rightMargin]) -
defaultTextPadding() * 2.0;
+ paperSize.height -= ([printInfo topMargin] + [printInfo bottomMargin]);
+ return paperSize;
+}
+
+- (NSRect)documentRectForPageNumber:(unsigned)pageNumber { /* First page
is page 0, of course! */
+ NSRect rect = [self pageRectForPageNumber:pageNumber];
+ rect.origin.x += [printInfo leftMargin] - defaultTextPadding();
+ rect.origin.y += [printInfo topMargin];
+ rect.size = [self documentSizeInPage];
+ return rect;
+}
+
+- (NSRect)pageRectForPageNumber:(unsigned)pageNumber {
+ NSRect rect;
+ rect.size = [printInfo paperSize];
+ rect.origin = [self frame].origin;
+ rect.origin.y += ((rect.size.height + [self pageSeparatorHeight]) *
pageNumber);
+ return rect;
+}
+
+- (void)setLineColor:(NSColor *)color {
+ if (color != lineColor) {
+ [lineColor autorelease];
+ lineColor = [color copyWithZone:[self zone]];
+ [self setNeedsDisplay:YES];
+ }
+}
+
+- (NSColor *)lineColor {
+ return lineColor;
+}
+
+- (void)setMarginColor:(NSColor *)color {
+ if (color != marginColor) {
+ [marginColor autorelease];
+ marginColor = [color copyWithZone:[self zone]];
+ [self setNeedsDisplay:YES];
+ }
+}
+
+- (NSColor *)marginColor {
+ return marginColor;
+}
+
+- (void)drawRect:(NSRect)rect {
+ if ([[NSGraphicsContext currentContext] isDrawingToScreen]) {
+ NSSize paperSize = [printInfo paperSize];
+ unsigned firstPage = rect.origin.y / (paperSize.height + [self
pageSeparatorHeight]);
+ unsigned lastPage = NSMaxY(rect) / (paperSize.height + [self
pageSeparatorHeight]);
+ unsigned cnt;
+
+ [marginColor set];
+ NSRectFill(rect);
+
+ [lineColor set];
+ for (cnt = firstPage; cnt <= lastPage; cnt++) {
+ // Draw boundary around the page, making sure it doesn't overlap
the document area in terms of pixels
+ NSRect docRect = NSInsetRect([self centerScanRect:[self
documentRectForPageNumber:cnt]], -1.0, -1.0);
+ NSFrameRectWithWidth(docRect, 1.0);
+ }
+
+ if ([[self superview] isKindOfClass:[NSClipView class]]) {
+ NSColor *backgroundColor = [(NSClipView *)[self superview]
backgroundColor];
+ [backgroundColor set];
+ for (cnt = firstPage; cnt <= lastPage; cnt++) {
+ NSRect pageRect = [self pageRectForPageNumber:cnt];
+ NSRectFill (NSMakeRect(pageRect.origin.x, NSMaxY(pageRect),
pageRect.size.width, [self pageSeparatorHeight]));
+ }
+ }
+ }
+}
+
+/**** Printing support... ****/
+
+- (BOOL)knowsPageRange:(NSRangePointer)aRange {
+ aRange->length = [self numberOfPages];
+ return YES;
+}
+
+- (NSRect)rectForPage:(int)page {
+ return [self documentRectForPageNumber:page-1]; /* Our page numbers start
from 0; the kit's from 1 */
+}
+
[EMAIL PROTECTED]
Modified: trunk/SKNotesDocument.m
===================================================================
--- trunk/SKNotesDocument.m 2008-10-05 15:19:08 UTC (rev 4740)
+++ trunk/SKNotesDocument.m 2008-10-05 16:01:28 UTC (rev 4741)
@@ -55,6 +55,7 @@
#import "NSMenu_SKExtensions.h"
#import "NSView_SKExtensions.h"
#import "Files_SKExtensions.h"
+#import "BDSKPrintableView.h"
static NSString *SKNotesDocumentWindowFrameAutosaveName =
@"SKNotesDocumentWindow";
@@ -284,6 +285,26 @@
return setup;
}
+#pragma mark Printing
+
+- (NSView *)printableView{
+ BDSKPrintableView *printableView = [[[BDSKPrintableView alloc]
initForScreenDisplay:NO] autorelease];
+ NSAttributedString *attrString = [[[NSAttributedString alloc]
initWithRTF:[self notesRTFData] documentAttributes:NULL] autorelease];
+ [printableView setAttributedString:attrString];
+ return printableView;
+}
+
+- (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)printSettings
error:(NSError **)outError {
+ NSPrintInfo *info = [[self printInfo] copy];
+ [[info dictionary] addEntriesFromDictionary:printSettings];
+ NSPrintOperation *printOperation = [NSPrintOperation
printOperationWithView:[self printableView] printInfo:info];
+ [info release];
+ NSPrintPanel *printPanel = [printOperation printPanel];
+ if ([printPanel respondsToSelector:@selector(setOptions:)])
+ [printPanel setOptions:NSPrintPanelShowsCopies |
NSPrintPanelShowsPageRange | NSPrintPanelShowsPaperSize |
NSPrintPanelShowsOrientation | NSPrintPanelShowsScaling |
NSPrintPanelShowsPreview];
+ return printOperation;
+}
+
#pragma mark Actions
- (IBAction)openPDF:(id)sender {
Modified: trunk/Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/Skim.xcodeproj/project.pbxproj 2008-10-05 15:19:08 UTC (rev
4740)
+++ trunk/Skim.xcodeproj/project.pbxproj 2008-10-05 16:01:28 UTC (rev
4741)
@@ -303,6 +303,10 @@
CE898F060C843A8B008A0856 /* PDFDDocument.icns in Resources */ =
{isa = PBXBuildFile; fileRef = CE898F050C843A8B008A0856 /* PDFDDocument.icns
*/; };
CE8B46E90C29CA00005CE7F1 /* SKLineInspector.m in Sources */ =
{isa = PBXBuildFile; fileRef = CE8B46E70C29CA00005CE7F1 /* SKLineInspector.m
*/; };
CE8B46F00C29CA3D005CE7F1 /* LineInspector.nib in Resources */ =
{isa = PBXBuildFile; fileRef = CE8B46EA0C29CA3D005CE7F1 /* LineInspector.nib
*/; };
+ CE9AFFF00E991ACD00FE1497 /* MultiplePageView.m in Sources */ =
{isa = PBXBuildFile; fileRef = CE9AFFEF0E991ACD00FE1497 /* MultiplePageView.m
*/; };
+ CE9AFFF20E991AD500FE1497 /* BDSKPrintableView.m in Sources */ =
{isa = PBXBuildFile; fileRef = CE9AFFF10E991AD500FE1497 /* BDSKPrintableView.m
*/; };
+ CE9AFFF40E991AEC00FE1497 /* BDSKPrintableView.h in Headers */ =
{isa = PBXBuildFile; fileRef = CE9AFFF30E991AEC00FE1497 /* BDSKPrintableView.h
*/; };
+ CE9AFFF60E991B0E00FE1497 /* MultiplePageView.h in Headers */ =
{isa = PBXBuildFile; fileRef = CE9AFFF50E991B0D00FE1497 /* MultiplePageView.h
*/; };
CE9B951E0D04657A00EB1A6C /* SKRemoteStateWindow.m in Sources */
= {isa = PBXBuildFile; fileRef = CE9B951C0D04657A00EB1A6C /*
SKRemoteStateWindow.m */; };
CE9C423C0B8B5633004AD8CF /* PreferenceWindow.nib in Resources
*/ = {isa = PBXBuildFile; fileRef = CE9C42360B8B5633004AD8CF /*
PreferenceWindow.nib */; };
CEA182280C92E3300061A6D4 /* NSData_SKExtensions.m in Sources */
= {isa = PBXBuildFile; fileRef = CEA182260C92E3300061A6D4 /*
NSData_SKExtensions.m */; };
@@ -877,6 +881,10 @@
CE8B46E70C29CA00005CE7F1 /* SKLineInspector.m */ = {isa =
PBXFileReference; lastKnownFileType = sourcecode.c.objc; path =
SKLineInspector.m; sourceTree = "<group>"; };
CE8B46EB0C29CA3D005CE7F1 /* English */ = {isa =
PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path =
English.lproj/LineInspector.nib; sourceTree = "<group>"; };
CE8B46F30C29CA4A005CE7F1 /* Dutch */ = {isa = PBXFileReference;
lastKnownFileType = wrapper.nib; name = Dutch; path =
Dutch.lproj/LineInspector.nib; sourceTree = "<group>"; };
+ CE9AFFEF0E991ACD00FE1497 /* MultiplePageView.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= MultiplePageView.m; sourceTree = "<group>"; };
+ CE9AFFF10E991AD500FE1497 /* BDSKPrintableView.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= BDSKPrintableView.m; sourceTree = "<group>"; };
+ CE9AFFF30E991AEC00FE1497 /* BDSKPrintableView.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
BDSKPrintableView.h; sourceTree = "<group>"; };
+ CE9AFFF50E991B0D00FE1497 /* MultiplePageView.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
MultiplePageView.h; sourceTree = "<group>"; };
CE9B951B0D04657A00EB1A6C /* SKRemoteStateWindow.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
SKRemoteStateWindow.h; sourceTree = "<group>"; };
CE9B951C0D04657A00EB1A6C /* SKRemoteStateWindow.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= SKRemoteStateWindow.m; sourceTree = "<group>"; };
CE9C42370B8B5633004AD8CF /* English */ = {isa =
PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path =
English.lproj/PreferenceWindow.nib; sourceTree = "<group>"; };
@@ -1447,6 +1455,10 @@
F92DB5B20B36FE5E002A26E9 /*
BDSKHeaderPopUpButton.m */,
F92DB5A80B36FE1F002A26E9 /*
BDSKHeaderPopUpButtonCell.h */,
F92DB5A90B36FE1F002A26E9 /*
BDSKHeaderPopUpButtonCell.m */,
+ CE9AFFF50E991B0D00FE1497 /* MultiplePageView.h
*/,
+ CE9AFFEF0E991ACD00FE1497 /* MultiplePageView.m
*/,
+ CE9AFFF30E991AEC00FE1497 /* BDSKPrintableView.h
*/,
+ CE9AFFF10E991AD500FE1497 /* BDSKPrintableView.m
*/,
F92DB5AA0B36FE1F002A26E9 /*
BDSKZoomablePDFView.h */,
F92DB5AB0B36FE1F002A26E9 /*
BDSKZoomablePDFView.m */,
);
@@ -1917,6 +1929,8 @@
CE0461A60E8BA99F00253123 /* Skim_Prefix.pch in
Headers */,
CE05A7370E9024ED0060BB07 /*
SKPresentationOptionsSheetController.h in Headers */,
CE05A86E0E90ED950060BB07 /*
SKTextFieldSheetController.h in Headers */,
+ CE9AFFF40E991AEC00FE1497 /* BDSKPrintableView.h
in Headers */,
+ CE9AFFF60E991B0E00FE1497 /* MultiplePageView.h
in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2420,6 +2434,8 @@
CEEE7C520E7D3F2000B7B208 /*
PDFAnnotationInk_SKExtensions.m in Sources */,
CE05A7380E9024ED0060BB07 /*
SKPresentationOptionsSheetController.m in Sources */,
CE05A86F0E90ED950060BB07 /*
SKTextFieldSheetController.m in Sources */,
+ CE9AFFF00E991ACD00FE1497 /* MultiplePageView.m
in Sources */,
+ CE9AFFF20E991AD500FE1497 /* BDSKPrintableView.m
in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit