/* ** Newton Developer Technical Support Sample Code ** ** Monaco Test v3, A monospaced font for the Newton ** ** by J. Christopher Bell, Newton Developer Technical Support ** ** Copyright © 1994 by Apple Computer, Inc. All rights reserved. ** ** You may incorporate this sample code into your applications without ** restriction. This sample code has been provided "AS IS" and the ** responsibility for its operation is 100% yours. You are not ** permitted to modify and redistribute the source as "DTS Sample Code." ** If you are going to re-distribute the source, we require that you ** make it clear in the source that the code was descended from ** Apple-provided sample code, but that you've made changes. */ constant kMonaco9Plain := '{family: Monaco, size: 9, face: 0}; // declare some useful constants constant kAppSymbol := '|MonacoTest:PIEDTS| ; constant kBorderFormat := '|borderFormat:MonacoTest:PIEDTS| ; // run at application install time // setup stuff the app may need before it is ever opened // or opened for this restart :-) InstallScript := func(partFrame) begin local myApp := partFrame.theForm ; // put my routing frame in the global routing frame routing.(kAppSymbol) := myApp.myRoutingFrame ; // put my format in the root so it can be found GetRoot().(kBorderFormat) := BuildContext(myApp.myPrintFormat); end; // run when application and/or card with app removed // cleanup routing stuff RemoveScript := func(packageFrame) begin // get rid of entry in global routing frame RemoveSlot(routing, kAppSymbol); // remove my print format RemoveSlot(GetRoot(), kBorderFormat); end; // ---- End Project Data ---- // ---- Beginning of Print templates ---- // ---- File myBorderFormat ---- // Before Script for "printFormat_myBorderFormat" // Copyright 1994 by Apple Computer, Inc. All rights reserved. Created by J. Christopher Bell. printFormat_myBorderFormat := { printNextPageScript: func() begin nil; // only print one page end, _proto: protoPrintFormat, debug: "printFormat_myBorderFormat" }; _view000 := /* child of printFormat_myBorderFormat */ {viewFlags: 1, viewFormat: 592, viewBounds: {left: 0, top: 0, right: 0, bottom: 0}, viewSetupFormScript: func() begin self.viewBounds := :Parent():LocalBox() ; self.viewBounds.left := self.viewBounds.left + 2 ; self.viewBounds.right := self.viewBounds.right - 2 ; self.viewBounds.top := self.viewBounds.top + 2 ; self.viewBounds.bottom := self.viewBounds.bottom - 2 ; end, viewDrawScript: func() begin local string := "Demo of text drawn with DrawShape method..."; local theLen := StrWidth(string); local height := FontHeight(viewFont); local descent := FontDescent(viewFont); local otherFont := {family:'monaco, size:9,face:3}; // draw bold and italic! :DrawShape(MakeRect(100,120 - height + descent,100 + theLen, 120 + descent), {penPattern:vfLtGray}); :DrawShape(MakeText(string, 100,70,500,120), {font:viewFont}); // draw bold! theLen := {viewfont: otherFont, msg: func() StrWidth(string)}:msg(); height := FontHeight(otherFont); descent := FontDescent(otherFont); :DrawShape(MakeRect(100,150 - height + descent,100 + theLen, 150 + descent), {penPattern:vfLtGray}); :DrawShape(MakeText(string, 100,80,500,150), {font:otherFont}); end, viewFont: {family: 'Monaco, size: 9, face: 2}, viewclass: 74 }; _view001 := /* child of printFormat_myBorderFormat */ {viewBounds: {top: 161, left: 21, right: 420, bottom: 611}, viewFlags: 1, viewFont: {family: 'Monaco, size: 9, face: 0}, viewFormat: 337 , viewlinespacing: 15, text: "0123456789012345678901234567890123456789012345678901234567890\n0 1 2 3 4 5 6\n\n======= Warning:\nWith any font that comes from a centralized source (e.g. Apple), you should not embed the font within your application using the NTK \"include.pkg\" trick. Although this is technically possible, is a very bad idea for several reasons:\n\n1) compatibility with other apps. Other third-party apps could include the font in their application. Once you both ship your products, one of you will break at \"install\" time or \"deinstall\" time. You cannot safely install the same font more than once!\n\n2) compatibility with the future ROMs. The font family symbol for this font is 'monaco. If a future ROM contains this popular font, you do not want to embed this font in your application because incompatibilities will result because you will double-install the monaco font (also note that future 'monaco versions could contain different metrics or additional font sizes) " , viewJustify: 0, viewclass: 81 }; pageNumber := /* child of printFormat_myBorderFormat */ {text: "Static Text", viewBounds: {top: -20, left: 0, right: 0, bottom: 0}, viewJustify: 8388790, viewSetupFormScript: func() begin text := "Page" && NumberStr(fields.pageNumber) ; end, viewFont: kMonaco9Plain, _proto: protoStaticText, debug: "pageNumber" }; customData := /* child of printFormat_myBorderFormat */ {text: "Static Text", viewBounds: {left: 0, top: 20, right: 0, bottom: 0}, viewSetupFormScript: func() begin text := fields.myData.data ; inherited:?viewSetupFormScript(); end;, viewFont: kMonaco9Plain, viewJustify: 242, _proto: protoStaticText, debug: "customData" }; // ---- End of Print templates ---- // ---- File main.t ---- // Before Script for "myBase" // Copyright 1994 by Apple Computer, Inc. All rights reserved. Created by J. Christopher Bell. myBase := {viewBounds: {left: 0, top: 50, right: 220, bottom: 222}, appSymbol: kAppSymbol, myPrintFormat: { // format for this application. An application can // have more than one format if it wants. // title that shows up in the Format picker // in the print or fax slip title: "Little Prints", // this could be a symbol for an auxilliary // information slip. See the auxForm sample code auxForm: nil, // symbol for a script that is called by // mail for a text only message to send textScript: 'myTextScript, // true if the user can attach a real // frame to the mail attachment: true, // a proto to get a coverPage for free! _proto: ROM_coverPageFormat, // the main format used for each page of // a print or fax output. mainFormat: printFormat_myBorderFormat, }, myRoutingFrame: { // very simple routing frame, just doing printing // and faxing print: { title: "Print Item", routeForm: 'printSlip, formats: [kBorderFormat]}, // and here is the fax stuff fax: { title: "Fax", routeForm: 'faxSlip, formats: [kBorderFormat]} }, SetupRoutingSlip: func(fields) begin // message sent after the user says print or fax // put some information in fields for print, fax // and mail to use. Since fields is available from // print/fax/mail formats, you can add a slot with // relevant info. // NOTE: make the info as small as you can, also // make the info invariant (i.e., do not // just pass a reference to target, since the // the target can change by the time the // print occurs fields.myData := Clone(target) ; // ALSO NOTE: beaming will use the target // slot in your app for the thing beamed. // setup the title that will show in the // outbox item. NOTE: the outbox does not wrap // it will let you overwrite the line below fields.title := title && DateNTime(Time()); end, title: "MonacoTest", viewSetupDoneScript: func() begin // setup the routing information // the target data for the route, this would normally be // a cursor Entry. If you want to do mailing, beaming // deleting, ... this MUST be a cursor entry. self.target := {data: theLine.text}; // view that gets the routing messages self.targetView := self ; end, PutAway: func(item) begin // This is the place where you could get wild and move the information // into soups, other apps, and otherwise extract the information. print(item); end, myTextScript: func(fields, target) begin target.data ; // returns the text that will be put into a mail message end, _proto: protoApp, debug: "myBase" }; theLine := /* child of myBase */ {viewBounds: {left: 8, top: 24, right: 216, bottom: 120}, viewChangedScript: func(slot, view) begin if (slot = 'text) then target.data := text ; end, viewFont: {family: 'Monaco, size: 9, face: 0}, text: "012345678901234567890", viewJustify: 0, viewSetupFormScript: func() begin if not fonts.monaco exists then text := clone("The Monaco font package is not installed"); else if not psfonts.|MonacoCourier:Newton| exists then // you should not normally need to check! text := clone("An old version of the monaco font is installed!"); inherited:?viewSetupFormScript(); // proto has a viewSetupformScript. end, _proto: protoInputLine, debug: "theLine" }; // View theLine is declared to myBase _view002 := /* child of myBase */ {viewJustify: 166, viewBounds: {top: -16, left: -42, right: -25, bottom: -3}, _proto: protoActionButton }; // ---- Beginning of section for non used Layout files ---- // End of output