0
;; @discussion PagePacker in Nu.
0
;; @copyright Copyright (c) 2007 Tim Burks, Neon Design Technology, Inc.
0
+;; Substantially derived from original Objective-C source code by Aaron Hillegass.
0
+;; See objc/PagePacker.m for the copyright notice for the original code.
0
-;; these declarations would be unnecessary if Nu is enhanced to read the Apple BridgeSupport files.
0
-(global kPDFDisplaySinglePage 0)
0
-(global NSDragOperationCopy 1)
0
-(global NSPDFPboardType "Apple PDF pasteboard type")
0
-(global NSDragPboard "Apple CFPasteboard drag")
0
-(global NSRectClip (NuBridgedFunction functionWithName:"NSRectClip" signature:"v{_NSRect}"))
0
-(global NSIntersectionRect (NuBridgedFunction functionWithName:"NSIntersectionRect" signature:"{_NSRect}{_NSRect}{_NSRect}"))
0
-(global NSPointInRect (NuBridgedFunction functionWithName:"NSPointInRect" signature:"i{_NSPoint}{_NSRect}"))
0
-(global NSFilenamesPboardType "NSFilenamesPboardType")
0
-(global NSIntersectsRect (NuBridgedFunction functionWithName:"NSIntersectsRect" signature:"i{_NSRect}{_NSRect}"))
0
-(global NSInsetRect (NuBridgedFunction functionWithName:"NSInsetRect" signature:"{_NSRect}{_NSRect}ff"))
0
-(global NSSquareLineCapStyle 2)
0
+(global BLOCK_COUNT 8) ;; We display 8 pages in a PagePacker document. There is no easy way to change this.
0
+;; @class CatalogController
0
+;; @discussion This class controls the display of the PDF source document.
0
+;; Pages can be dragged from this document into the PagePacker document view.
0
(class CatalogController is NSWindowController
0
(int) currentPageIndex)
0
- (set sharedCatalogController nil) ;; Nu closures make this a class variable
0
+ (set sharedCatalogController nil) ;; Since the assignment is made inside the class declaration, Nu closures make this a class variable.
0
+ (+ sharedCatalogController is sharedCatalogController)
0
(super initWithWindowNibName:"CatalogController")
0
(set @currentPageIndex 0)
0
- (+ sharedCatalogController is sharedCatalogController)
0
(set path ((NSBundle mainBundle) pathForResource:"diyp3h_core_1up" ofType:@"pdf"))
0
(set url (NSURL fileURLWithPath:path))
0
(self changeToPage:(- @currentPageIndex 1))
0
(@pageSlider setIntValue:@currentPageIndex)))
0
+;; @discussion This is the main PagePacker document.
0
(if @packerView (self updateUI))
0
-(function PointInRect (point rect)
0
- (and (>= (point first) (rect first))
0
- (>= (point second) (rect second))
0
- (<= (point first) (+ (rect first) (rect third)))
0
- (<= (point second) (+ (rect second) (rect fourth)))))
0
-(function distanceSquaredBetweenPoints (p1 p2)
0
- (set deltax (- (p1 first) (p2 first)))
0
- (set deltay (- (p1 second) (p2 second)))
0
- (+ (* deltax deltax) (* deltay deltay)))
0
+;; @class DragingSourcePDFView
0
+;; @discussion This class controls the view of the source document.
0
(class DraggingSourcePDFView is PDFView
0
(ivar (id) mouseDownEvent)
0
(- (id) hitTest:(NSPoint) aPoint is
0
(if (PointInRect aPoint (self frame))
0
- (else nil)))
;; in the most hard-won conclusion of this project, this should be NULL and not nil.0
(- (BOOL) shouldDelayWindowOrderingForEvent:(id) theEvent is YES)
0
(- (void) mouseUp:(id) e is
0
(set @mouseDownEvent nil)))
0
-(function pdfFromAttributedStringOfSize (attStr sz)
0
- (set v ((TextDisplayView alloc) initWithPageSize:sz attributedString:attStr))
0
- (v dataWithPDFInsideRect:(v bounds)))
0
+;; @discussion This class describes the PagePacker document.
0
(class PackModel is NSObject
0
(ivar (id) pageInfos (id) undoManager)
0
+;; @discussion This class describes an individual page in a PagePacker document.
0
(class PageInfo is NSObject
0
(ivar (id) imageRep (int) pageOfRep)
0
"<PageInfo: #{(@imageRep description)}, #{@pageOfRep}>"))
0
-(function insetRect (rect x y)
0
- (list (+ (rect first) x) (+ (rect second) y) (- (rect third) x x) (- (rect fourth) y y)))
0
-(function isLeftSide (pageNum) (or (eq pageNum 0) (> pageNum 4)))
0
-(function NSMinX (rect)
0
- (set x2 (+ (rect first) (rect third)))
0
- (if (< x1 x2) (then x1) (else x2)))
0
-(function NSMaxX (rect)
0
- (set x2 (+ (rect first) (rect third)))
0
- (if (> x1 x2) (then x1) (else x2)))
0
-(function NSMinY (rect)
0
- (set y1 (rect second))
0
- (set y2 (+ (rect second) (rect fourth)))
0
- (if (< y1 y2) (then y1) (else y2)))
0
-(function NSMaxY (rect)
0
- (set y1 (rect second))
0
- (set y2 (+ (rect second) (rect fourth)))
0
- (if (> y1 y2) (then y1) (else y2)))
0
-(function HalfX (r) (+ (r first) (* 0.5 (r third))))
0
-(function QuarterY (r) (+ (r second) (* 0.25 (r fourth))))
0
-(function HalfY (r) (+ (r second) (* 0.5 (r fourth))))
0
-(function ThreeQuarterY (r) (+ (r second) (* 0.75 (r fourth))))
0
-(global BUTTON_MARGIN 4.0)
0
+;; @class RoundCloseButtonCell
0
+;; @discussion This class provides a custom button cell for use in the PackerView display.
0
+(class RoundCloseButtonCell is NSButtonCell
0
+ (- (void)drawWithFrame:(NSRect)cellFrame inView:(id)controlView is
0
+ (if (NSGraphicsContext currentContextDrawingToScreen)
0
+ (if (self isHighlighted)
0
+ (then ((NSColor orangeColor) set))
0
+ (else ((NSColor blueColor) set)))
0
+ (NSBezierPath fillRect:cellFrame)
0
+ (NSBezierPath setDefaultLineWidth:3)
0
+ ((NSColor whiteColor) set)
0
+ (NSBezierPath strokeRect:cellFrame)
0
+ (set p ((NSBezierPath alloc) init))
0
+ (p setLineCapStyle:NSSquareLineCapStyle)
0
+ (set xRect (NSInsetRect cellFrame 9 7))
0
+ (p moveToPoint:(list (xRect first) (xRect second)))
0
+ (p lineToPoint:(list (+ (xRect first) (xRect third)) (+ (xRect second) (xRect fourth))))
0
+ (p moveToPoint:(list (xRect first) (+ (xRect second) (xRect fourth))))
0
+ (p lineToPoint:(list (+ (xRect first) (xRect third)) (xRect second)))
0
+ ((NSColor whiteColor) set)
0
+;; @discussion This class provides a view of a PagePacker document.
0
- (set numberAttributes nil) ;; pseudo-class variable
0
+ (set numberAttributes nil) ;; a class variable to hold the attribute dictionary for displayed numbers.
0
+ (set buttonMargin 4.0) ;; a class variable that specifies the position of our custom close buttons.
0
+ ;; determine whether a page is on the left or right side of the PageView display.
0
+ ;; Because this function is defined in the class declaration, it is effectively local (private) to this class.
0
+ (function isLeftSide (pageNum) (or (eq pageNum 0) (> pageNum 4)))
0
(+ (void) initialize is
0
(set numberAttributes ((NSMutableDictionary alloc) init))
0
(if (@packModel pageIsFilled:i)
0
(set fullRect (self fullRectForPage:i))
0
- (- (NSMaxX fullRect) (+ 30 BUTTON_MARGIN))
0
- (+ (NSMinY fullRect) BUTTON_MARGIN)
0
+ (set buttonRect (list (- (NSMaxX fullRect) (+ 30 buttonMargin))
0
+ (+ (NSMinY fullRect) buttonMargin)
0
(set button ((NSButton alloc) initWithFrame:buttonRect))
0
(button setCell:((RoundCloseButtonCell alloc) init))
0
(if @showsImageableRect
0
((NSColor blueColor) set)
0
(NSBezierPath setDefaultLineWidth:1.0)
0
- (NSBezierPath strokeRect:@imageablePageRect))
0
+ (NSBezierPath strokeRect:@imageablePageRect))
0
- (set dropColor (NSColor colorWithDeviceRed:0.8
0
+ ((NSColor colorWithDeviceRed:0.8 green:0.5 blue:0.5 alpha:0.3) set)
0
(NSBezierPath fillRect:(self fullRectForPage:@dropPage))))))
0
+;; @class TextDisplayView
0
+;; @discussion This helper class is used to generate PDF representations of strings.
0
(class TextDisplayView is NSView
0
(ivar (id) attString (NSSize) pageSize)
0
(set bounds (NSInsetRect (self bounds) 3 3))
0
(@attString drawInRect:bounds)))
0
+;; use the above class to generate a PDF for an attribute string.
0
+(function pdfFromAttributedStringOfSize (attStr sz)
0
+ (set v ((TextDisplayView alloc) initWithPageSize:sz attributedString:attStr))
0
+ (v dataWithPDFInsideRect:(v bounds)))
0
+;; some internal constants
0
(global PaperSizeChangedNotification "PaperSizeChangedNotification")
0
(global PaperSizeKey "PaperSize")
0
(global FontFamilyKey "FontFamily")
0
(global FontSizeKey "FontSize")
0
-(global LETTER_PAPER_ID 0)
0
+;; @class PreferenceController
0
+;; @discussion This class controls the application's preference window.
0
(class PreferenceController is NSWindowController
0
(ivar (id) paperPopUp (id) textFontField (id) textFont)
0
- (set factoryDefaults ((NSMutableDictionary alloc) init))
0
- (factoryDefaults setObject:(NSNumber numberWithInt:0)
0
- (factoryDefaults setObject:@"Helvetica"
0
- (factoryDefaults setObject:(NSNumber numberWithFloat:8.0)
0
- ((NSUserDefaults standardUserDefaults) registerDefaults:factoryDefaults))
0
+ ((NSUserDefaults standardUserDefaults) registerDefaults:(dict PaperSizeKey 0
0
+ FontFamilyKey "Helvetica"
0
- (+ (id)sharedPreferenceController is
0
- (unless sharedPreferenceController
0
- ((PreferenceController alloc) init))
0
+ (+ (id)sharedPreferenceController is
0
+ (unless sharedPreferenceController ((PreferenceController alloc) init))
0
sharedPreferenceController)
0
(- (void)setPaperSizeID:(int)i is
0
((NSUserDefaults standardUserDefaults) setInteger:i forKey:PaperSizeKey)
0
- (set userInfo (NSMutableDictionary dictionary))
0
- (userInfo setObject:(NSValue valueWithSize:(self paperSize))
0
- ((NSNotificationCenter defaultCenter) postNotificationName:PaperSizeChangedNotification
0
+ ((NSNotificationCenter defaultCenter)
0
+ postNotificationName:PaperSizeChangedNotification
0
+ userInfo:
(dict PaperSizeKey (NSValue valueWithSize:(self paperSize)))))
0
(- (NSSize)paperSize is
0
- (set i (self paperSizeID))
0
- (else ;; assume it's A4
0
+ (case (self paperSizeID)
0
+ (0 '(612 792)) ;; LETTER
0
+ (else '(595 842)))) ;; assume it's A4
0
(- (void)windowDidLoad is
0
- (set i (self paperSizeID))
0
- (@paperPopUp selectItemWithTag:i)
0
+ (@paperPopUp selectItemWithTag:(self paperSizeID))
0
(@textFontField setStringValue:(self fontDescription)))
0
(- (void)paperChosen:(id)sender is
0
- (set i (@paperPopUp selectedTag))
0
- (self setPaperSizeID:i))
0
+ (self setPaperSizeID:(@paperPopUp selectedTag)))
0
(- (id) textFont is @textFont)
0
(- (void) setTextFont:(id) f is
0
- (set ud (NSUserDefaults standardUserDefaults))
0
- (ud setObject:(f familyName) forKey:FontFamilyKey)
0
- (ud setFloat:(f pointSize) forKey:FontSizeKey)
0
+ (set userDefaults (NSUserDefaults standardUserDefaults))
0
+ (userDefaults setObject:(f familyName) forKey:FontFamilyKey)
0
+ (userDefaults setFloat:(f pointSize) forKey:FontSizeKey)
0
(@textFontField setStringValue:(self fontDescription)))
0
(- (id) fontDescription is
0
- (set f (self textFont))
0
- "#{(f displayName)} - #{(f pointSize)}")
0
+ "#{((self textFont) displayName)} - #{((self textFont) pointSize)}")
0
(- (void)changeFont:(id)sender is
0
- (set newFont (sender convertFont:@textFont))
0
- (self setTextFont:newFont))
0
+ (self setTextFont:(sender convertFont:@textFont)))
0
(- (void)chooseFont:(id)sender is
0
- (set fm (NSFontManager sharedFontManager))
0
- (fm setSelectedFont:@textFont isMultiple:NO)
0
- (set fp (NSFontPanel sharedFontPanel))
0
- (fp makeKeyAndOrderFront:nil)))
0
-(class RoundCloseButtonCell is NSButtonCell
0
- (- (void)drawWithFrame:(NSRect)cellFrame inView:(id)controlView is
0
- (if (NSGraphicsContext currentContextDrawingToScreen)
0
- (if (self isHighlighted)
0
- (then ((NSColor orangeColor) set))
0
- (else ((NSColor blueColor) set)))
0
- (NSBezierPath fillRect:cellFrame)
0
- (NSBezierPath setDefaultLineWidth:3)
0
- ((NSColor whiteColor) set)
0
- (NSBezierPath strokeRect:cellFrame)
0
- (set p ((NSBezierPath alloc) init))
0
- (p setLineCapStyle:NSSquareLineCapStyle)
0
- (set xRect (NSInsetRect cellFrame 9 7))
0
- (p moveToPoint:(list (xRect first) (xRect second)))
0
- (p lineToPoint:(list (+ (xRect first) (xRect third)) (+ (xRect second) (xRect fourth))))
0
- (p moveToPoint:(list (xRect first) (+ (xRect second) (xRect fourth))))
0
- (p lineToPoint:(list (+ (xRect first) (xRect third)) (xRect second)))
0
- ((NSColor whiteColor) set)
0
+ ((NSFontManager sharedFontManager) setSelectedFont:@textFont isMultiple:NO)
0
+ ((NSFontPanel sharedFontPanel) makeKeyAndOrderFront:nil)))
0
\ No newline at end of file
Comments
No one has commented yet.