banner



How To Set Margins In Textedit

Fixing Margins Problems in TextEdit

This is based on an commodity past Adam Knight, formerly available at this URL until his site disappeared off the face of the Cyberspace. I have updated information technology to work with the TextEdit 1.6 source code that comes with the MacOS 10.6 version of Developer Tools.


Irresolute TextEdit's Margins

(Updated for Max OS 10.half dozen by Robert Munafo, 2022 June half dozen)

Question

I am big into doing more with less, and threw Part out years ago. Every bit such, I take made TextEdit my writing and annotation taking tool of choice.

I matter that bugs me yet is its inability to alter the margins from the default 1 inch all the fashion effectually.

Is there a mode to change these settings, other than editing a bare .rtf file header then saving that file as stationery. Ideally I would similar to be able to change things at volition.

Answer

I claimed this question, total of a very smug pride, completely fix to put this into the "Screen Door on a Submarine" category with a witty slight by but going to Print Setup and making a new page with smaller margins and printing to that ... only to find that didn't work.

At present, you would think that Apple's own software would respect the margins prepare in Print Setup, wouldn't you?

Alas, this is far from the example. At showtime I thought that it was because someone at Apple is so firm a believer in 72-point margins that it's been hard-coded into TextEdit. When I went to look for evidence of it — I found it. I kid y'all not. If you lot install the Developer Tools and then look in /Developer/Examples/TextEdit, you'll find the complete source to TextEdit to hack effectually with. Open TextEdit.xcodeproj, go to Document.1000, and on or about line 677 you'll encounter the - (NSPrintInfo *)printInfo function:

- (NSPrintInfo *)printInfo { NSPrintInfo *printInfo = [super printInfo]; if (!setUpPrintInfoDefaults) { setUpPrintInfoDefaults = YES; [printInfo setHorizontalPagination:NSFitPagination]; [printInfo setHorizontallyCentered:NO]; [printInfo setVerticallyCentered:NO]; [printInfo setLeftMargin:72.0]; [printInfo setRightMargin:72.0]; [printInfo setTopMargin:72.0]; [printInfo setBottomMargin:72.0]; } return printInfo; }

Son of a drunken monkey. They really did practice that, didn't they? So I commented out that section, thinking MOSX was smart enough to copy the margins from the newspaper size ... it'southward not. In fact, the more I looked into information technology, the Cocoa printing subsystem uses the margins in the Print Setup window (the NSPrintInfo object) to define machine-level margins, non application-level margins. Applications have to do something else to actually handle margins because that's not what this area'due south used for. Well, currently.

What nosotros can practise is set the margin for the print task to the maximum imagable area on the page and that should correspond with the margins specified in the custom paper size in the Impress Setup window. This is technically bad form, but information technology works well enough for what we want to practise. Merely where to practice it? One would recall in the function above, merely if you look at information technology, information technology'south setting that only if information technology'due south not cypher then that's a onetime thing. Looking around, in DocumentWindowController.m TextEdit has some other method that's called when printInfo is updated called, shockingly enough: printInfoUpdated. This looks like a good place. Then, on or about line 227, insert the lines shown below so that - (void)printInfoUpdated begins like so:

- (void)printInfoUpdated { float horizontalMargin, verticalMargin;   /* Changes added per * http://www.mrob.com/pub/comp/textedit-margins.html */ NSSize bounds = [[[self document] printInfo] imageablePageBounds].size; NSSize size = [[[self certificate] printInfo] paperSize];   horizontalMargin = (size.width - bounds.width) / 2.0; verticalMargin = (size.height - bounds.height) / 2.0;   [[[self document] printInfo] setLeftMargin:horizontalMargin]; [[[cocky document] printInfo] setRightMargin:horizontalMargin]; [[[self document] printInfo] setTopMargin:verticalMargin]; [[[self document] printInfo] setBottomMargin:verticalMargin];   if (hasMultiplePages) { NSUInteger cnt, numberOfPages = [self numberOfPages]; /* and and then on... */

And that, as they say, is that. Add the above lines to - (void)printInfoUpdated in DocumentWindowController.m, select Project > Fix Agile Build Configuration > Release, and Build. Replace your TextEdit with the 1 yous just built, and your documents will print with whatever margins the Folio Setup specifies they should employ. This does not give you differing margins on each side, but that's a rarity. Most of the fourth dimension information technology's only well-nigh using more of the paper and this should do that.

(original date: April 17, 2006 - 7:35am)



This page was written in the "embarrassingly readable" markup linguistic communication RHTF, and was terminal updated on 2022 Dec 11. south.27

Source: https://mrob.com/pub/comp/textedit-margins.html

0 Response to "How To Set Margins In Textedit"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel