Fine tuning printing

I need to print text that may be several pages long.


I create an NSTextField that is inserted in the printing view.

Everything works OK, except that the split between pages occur in the middle of a line, which is thus split vertically in 2 parts on 2 pages.


To manage this, following advices from "Printing Programming Guide for Mac", I try to use adjustPageHeightNew.


Tiling Content Across Pages

If the view does not supply its own pagination information and one of the print info object’s pagination settings is NSAutoPagination, NSView tries to fit as much of the view being printed onto a logical page, slicing the view into the largest possible chunks along the given direction (horizontal or vertical). This is sufficient for many views, but if a view’s image must be divided only at certain places—between lines of text or cells in a table, for example—the view can adjust the automatic mechanism to accommodate this by reducing the height or width of each page.

Before printing begins, the view calculates the positions of all the row and column page breaks and gives you an opportunity to adjust them. The adjustPageHeightNew:top:bottom:limit: method provides an out parameter for the new bottom coordinate of the page, followed by the proposed top and bottom. An additional parameter limits the height of the page; the bottom can’t be moved above it. The adjustPageWidthNew:left:right:limit: method works in the same way to allow the view to adjust the width of a page. The limits are calculated as a percentage of the proposed page’s height or width. Your view subclass can also customize this percentage by overriding the methods heightAdjustLimit and widthAdjustLimit to return the fraction of the page that can be adjusted; a value of zero indicates that no adjustments are allowed whereas a value of one indicates that the right or bottom edge of the page bounds can be adjusted all the way to the left or top edge.


So, I set

printInfo.verticalPagination = .AutoPagination


I have 2 problems :


1. adjustPageHeightNew never gets called


    override func adjustPageHeightNew(newBottom: UnsafeMutablePointer<CGFloat>, top: CGFloat, bottom: CGFloat, limit: CGFloat) {
    
        newBottom.memory = bottom + 8          // Just to test something
        Swift.print(top, bottom, limit)          // never gets there
    }


2. I would need to calculate automatically the newBottom.

Is there a way to know that the split presently is in the middle of a line, or do I need to compute it totally manually ?

Fine tuning printing
 
 
Q