// Text of project MonacoTest written on 5/9/95 at 5:38 PM // Beginning of text file Project Data /* ** Newton Developer Technical Support Sample Code ** ** Monaco Test v4, A monospaced font for the Newton ** ** by Bob Ebert & J. Christopher Bell, Newton Developer Technical Support ** ** Copyright © 1994-5 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. */ // declare some useful constants constant kMonaco9Plain := '{family: Monaco, size: 9, face: 0}; 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 of text file Project Data // Beginning of file Install Slip // Before Script for "installSlip" x := OpenResFileX(HOME & "Monaco.rsrc"); DefConst('kFontName, GetNamedResource("ustr", "Font Name", 'string)); DefConst('kFontPackage, GetNamedResource("pkg ", "Font Package", 'binary)); DefConst('kFontSymbol, Intern(GetNamedResource("ustr", "Font Symbol", 'string))); CloseResFileX(x); installSlip := {viewBounds: {left: 0, top: 100, right: 200, bottom: 220}, declareSelf: 'base, viewJustify: 16, destination: nil // store , title: "Font Installer", viewSetupDoneScript: func() destination := GetStores()[0];, debug: "installSlip", _proto: @179 }; _view000 := {_proto: @229}; AddStepForm(installSlip, _view000); _view001 := { text: "This application requires the ^1 font, which is not installed. Choose a destination and tap the Install button to install it now." // The afterScript replaces ^1 with the font name from the resource file. , viewBounds: {top: 3, left: 10, right: -10, bottom: 48}, viewJustify: 8240, _proto: @218 }; AddStepForm(installSlip, _view001); // After Script for "_view001" thisView := _view001; StrMunger(thisView.text, StrPos(thisView.text, "^1", 0), 2, kFontName, 0, nil); _view002 := {viewBounds: {left: 0, top: 76, right: 180, bottom: 89}, bounds: {left: 0, top: 0, right: 0, bottom: 0}, labelCommands: nil, viewJustify: 8388624, labelActionScript: func(cmd) begin destination := labelStores[cmd]; end, text: "Destination", textSetup: func() // return first one as default begin :MakeStoresLists(); // to get the default if labelCommands then labelCommands[0] else "" end;, MakeStoresLists: func() begin labelCommands := []; labelStores := []; foreach store in GetStores() do if not store:IsReadOnly() then begin AddArraySlot(labelCommands, store:GetName()); AddArraySlot(labelStores, store); end; end;, labelStores: nil, pickerSetup: func() begin :MakeStoresLists(); // do it every time in case a new store is inserted. true // the popup should happen end, _proto: @190 }; AddStepForm(installSlip, _view002); // After Script for "_view002" thisView := _view002; // this proto uses the bounds instead of the viewbounds slot thisView.bounds := thisView.viewBounds; _view003 := {_proto: @163}; AddStepForm(installSlip, _view003); _view004 := { buttonClickScript: func() begin destination:RestorePackage(kFontPackage); base:Close(); GetRoot().(kAppSymbol):Open(); // re-open the original app end;, text: "Install", viewBounds: {top: -18, left: -56, right: -6, bottom: -5}, viewJustify: 8390790, _proto: @226 }; AddStepForm(installSlip, _view004); constant |layout_Install Slip| := installSlip; // End of file Install Slip // Beginning of file myBorderFormat // Before Script for "_view005" // Copyright 1994 by Apple Computer, Inc. All rights reserved. Created by J. Christopher Bell. _view005 := { printNextPageScript: func() begin nil; // only print one page end, _proto: @200 }; _view006 := {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 }; AddStepForm(_view005, _view006); _view007 := {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 }; AddStepForm(_view005, _view007); _view008 := {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: @218 }; AddStepForm(_view005, _view008); _view009 := {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: @218 }; AddStepForm(_view005, _view009); constant |layout_myBorderFormat| := _view005; // End of file myBorderFormat // Beginning of 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: GetLayout("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, viewSetupFormScript: func() // make sure Monaco is available if not fonts.monaco then begin // open our user-friendly dialog to offer font installation to the user. BuildContext(installSlip):Open(); // prevent the app from opening by setting its viewbounds very small (we are top-left justified) self.viewBounds := RelBounds(0,0,0,0); // close ourselves in a deferred action and remove the viewbounds slot to save some // space and to let our view template's viewBounds be used next time we open... AddDeferredAction(func(v) begin v:Close(); RemoveSlot(v, 'viewBounds) end, [self]); end;, debug: "myBase", _proto: @157 }; theLine := {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, debug: "theLine", _proto: @185 }; AddStepForm(myBase, theLine); StepDeclare(myBase, theLine, 'theLine); _view010 := {viewJustify: 166, viewBounds: {top: -16, left: -42, right: -25, bottom: -3}, _proto: @209 }; AddStepForm(myBase, _view010); installSlip := LinkedSubview(installSlip, {viewBounds: {left: 16, top: 136, right: 88, bottom: 176}, debug: "installSlip" }); AddStepForm(myBase, installSlip); StepDeclare(myBase, installSlip, 'installSlip); constant |layout_main.t| := myBase; // End of file main.t