TweetFollow Us on Twitter

Printing Techniques 2
Volume Number:1
Issue Number:11
Column Tag:Basic School

Printing Techniques for Basic

By Dave Kelly, Hybrids Engineer, MacTutor Editorial Board

Managing BASIC Font Printing

Sometimes when talking about the Macintosh, people have asked "How many columns does the Macintosh have?". My answer to them is that it depends. Many of you like myself started out on other computers such as the Apple //. Many of the early computers had only 40 columns of text display. This severely limited the usefulness of word processing software until the introduction of 80-col display plug in boards. Back in those days it was very important to ask how many columns there were because of the limitations that are imposed by the lack of 80 column display. The Macintosh is an entirely different animal though. Because of the ability of the Macintosh to display proportional spaced fonts on the screen just as it will look when printed, it is not applicable to refer to the Macintosh screen as an 80-col display. It is important in development of applications for the Macintosh that we realize the difference between the Macintosh and other computers when it comes to displaying and printing data. Some may have experienced some frustration in trying to format text when using proportional fonts. I'll try to discuss a few items to keep in mind when using proportional spacing. There are some advantages and disadvantages to be aware of. This month we will explore some of the ins and outs of printing in different size fonts.

First, lets take a look at the difference between proportional and monospaced fonts. The unit of measurement for the spacing is the size of the character "0" in the current font. For monospaced fonts the character "0" happens to be the same width as the rest of the characters in the font. For the proportional spaced font, the "0" is an average width but not necessarily the same width as the other characters. Notice that the spacing of all the uppercase characters for a monospaced font is the same as for the lower case characters. Also note that the proportional spaced "A" is wider than the "a".

The advantage of using the monspaced type of font is that you can always be sure of just where each character will be printed or displayed. In the proportional font each of the letters are a different width depending on how much spacing each character requires. Now that we have a feel for proportional characters, try the following lines of BASIC and compare the results of printing with monospacing and proportional spacing:

' Sample program #1 
' Dave Kelly 
' MACTUTOR ©1985 

l1$="Name #1":r1$="Name #2" 
l2$="123 Main St.":r2$="456 Central Ave." 
l3$="Anyplace, USA":R3$="Anywhere, USA" 

FOR i=1 TO 40     
 zero$=zero$+"0" 
NEXT i 

WIDTH 40,20 
TEXTFONT(4):TEXTSIZE(12) 'Monaco 
GOSUB printit 
TEXTFONT(2):TEXTSIZE(12) 'New York 
GOSUB printit 
END 

printit: 
PRINT  l1$,r1$ 
PRINT  l2$,r2$ 
PRINT  l3$,R3$ 
PRINT  zero$

PRINT  l1$;TAB(21);r1$ 
PRINT  l2$;TAB(21);r2$ 
PRINT  l3$;TAB(21);R3$ 
PRINT  zero$
RETURN 

In the sample program it is clear that the spacing of "0" is different for the 2 fonts, which explains why the second column does not line up. RULE 1: Remember that when mixing fonts you can't expect them to line up. This program demonstrates the use of the BASIC WIDTH command. The syntax of the WIDTH command is defined on page 264 of the MSBASIC manual. In general the syntax is: WIDTH [size ] [,print-zone ] . The size is the number of standard characters that a line may contain. In other words, BASIC will force a carriage return after the line size is full. If the size is 255 then BASIC will not force any carriage returns. The print-zone assigns the width of the print zone. The print zones are similar to tab stops, and they are forced by comma delimiters in the PRINT or LPRINT statements. In the sample program you can see that by using TAB or by using WIDTH the same result can be achieved. Using WIDTH the position of the 2nd column is determined by the print-zone. By using TAB(I), print position moves to the position indicated by I. An understanding of how these commands may be used is helpful when you are trying to format your printed output. An example would be the printing of a multiple column roster or newsletter where different fields might be combined together to create an entire line. The traditional way to do this would be to combine the fields together as one string variable and then to print the variable. The spacing of each field is filled to the size of the print-zone before combining all the fields, so that the total width of all the fields will fit. This works fine with monospaced fonts but it quite difficult to accomplish with proportional spaced fonts. An alternative solution is to use TAB or WIDTH functions to specify where each field will be printed. It is still important to check the length of each field before printing to make sure that each field will fit into the specified print zone. If it won't fit then either the field must be truncated or the print-zone should be adjusted. If not, then the field will print past the assigned print-zone and into the next print-zone. The next field to be printed will be pushed over to the next available print-zone.

This can be demonstated by changing the sample program. In the program the print-zone is set at 20 characters wide. If fewer than 20 characters are printed then the next print field will begin 20 characters after the start of the first print field. Try changing the line: l1$="Name #1":r1$="Name #2" to a field that has more than 20 characters, for example: l1$="Name #1 is too long now":r1$="Name #2" to demonstate the problem. To fix the line change it to:

l1$=LEFT$("Name #1 is too long now",20):r1$="Name #2" or adjust the WIDTH statement to: WIDTH 40,25.

Another consideration when using fonts of different sizes and widths is that each font will use a different number of lines to print the same thing. Because there are so many different fonts and sizes available it is difficult to examine the effect of each one. So, before using any set of fonts you should test each one out to see how many lines will fit on a page and adjust your program to count the lines as they are printed. If you are printing in a 10 pt. font it is probable that you will have more lines than for a 12 pt. font. The Disk Labeler program is a quick sample of what might be done with the WIDTH statement. Keep in mind that this is just a sample and may or may not be a useful application, however it may be modified to meet your needs.

Disk Labeler Program Sample

The program will read filenames one at a time from the disk and place them in an array called filename$(i). I have limited the size to 10 files to simplify the program. Choose Add/Remove from the files menu to add or remove a file. The selected files are printed in window 1. The second menu lets you select the font info. This illustrates a method of changing the fonts and sizes that will be used. This could be expanded to select various attributes such as Bold or Italics. Keep in mind that the different attributes will also change the width of each character. The printlabel routine demonstrates printing different fonts to the printer. If you have had trouble changing fonts when printing to the printer you may want to take a closer look at this routine. The key is the WINDOW OUTPUT #1 statement. This statement is necessary to direct all graphics commands, including those which change the fonts, to the printer. The Set Disk Label item of the files menu will let you set the number of lines and the number of columns that will be printed. The columns are formatted with the WIDTH statement. Disk labels may be printed in any desired font by adding additional fonts to the menu. I recommend printing labels in a small font (9 point) in order to fit more on a label. Have any useful printing tips? Send your best suggestions to me care of MacTutor!

' Disk Labeler 
' By Dave Kelly 
' MACTUTOR ©1985
 
' Watch line breaks. A few Basic lines are longer than 
' this Journals column width, but the breaks are
' obviously placed so that it is clear the Basic line
' continues from the previous line. 

number.of.files=0:DEFINT i-m:maxfiles=10 number.of.lines=5:number.of.col=2 

DIM filename$(maxfiles)
 
'fonts 
chicago=0: Appl=1: Newyork=2: Geneva=3: Monaco=4 
activefont=Geneva: activesize=12
WINDOW 1,"",(200,50)-(400,275),2 
'menu clear 
FOR i=1 TO 5:MENU i,0,0,"":NEXT i 

'set new menus 

MENU 1,0,1,"File" 
MENU 1,1,1,"Add/Remove a file" 
MENU 1,2,1,"Clear all files" 
MENU 1,3,0,"-" 
MENU 1,4,1,"Print Disk Label" 
MENU 1,5,1,"Set Disk Label" 
MENU 1,6,1,"Quit"
 
MENU 2,0,1,"Font Info" 
MENU 2,1,0,"Fonts" 
MENU 2,2,1,"NewYork" 
MENU 2,3,2,"Geneva" 
MENU 2,4,1,"Monaco" 
MENU 2,5,0,"-" 
MENU 2,6,1,"9 point" 
MENU 2,7,1,"10 point" 
MENU 2,8,2,"12 point"
 
ON MENU GOSUB Menucheck:MENU ON 
idle: GOTO idle
 
Menucheck:     
Menunumber=MENU(0): Menuitem=MENU(1)     
ON Menunumber GOSUB Filemenu, Fontmenu     
RETURN      

Filemenu:     
MENU     
ON Menuitem GOSUB Add, Clearfiles,Blank,Printlabel,      Setlabel, Quit 
    
RETURN      

Add:     
x$=FILES$(1)     
IF x$="" THEN GOSUB display:RETURN     'x$=MID$(x$,INSTR(x$,":")+1) 
'optional line:use to strip volume name     

FOR i= 1 TO number.of.files         
IF x$=filename$(i) THEN filename$(i)="zzzzz":      i=number.of.files+2: 
CALL Sort(filename$(),  number.of.files): number.of.files= number.of.files-1 
    
NEXT i     

IF number.of.files>=maxfiles THEN GOSUB display:   RETURN     
IF i=number.of.files+1 THEN filename$(i)=x$:       number.of.files=i 
    
CALL Sort (filename$(),number.of.files )     
GOSUB display     
RETURN      

Clearfiles:     
number.of.files=0     
GOSUB display     
RETURN      

display:     
TEXTFONT(chicago):TEXTSIZE(12)     
CLS:PRINT number.of.files;"files have been selected."     TEXTFONT(activefont):TEXTSIZE(activesize) 
    
FOR i=1 TO number.of.files    
  maxlength=30     
 IF activesize<=10 THEN maxlength=40     
 PRINT LEFT$(filename$(i),maxlength)     
NEXT i 
   
IF number.of.files=maxfiles THEN 
 PRINT"Max.";maxfiles;"files allowed"     
RETURN      

Blank:RETURN
 
Printlabel:    
IF number.of.files=0 THEN RETURN    
OPEN "LPT1:PROMPT"  FOR OUTPUT AS #1     
WINDOW OUTPUT #1     TEXTFONT(activefont):TEXTSIZE(activesize)     
colwid=30:IF number.of.col=2 THEN colwid=20     
WIDTH "LPT1:",(colwid+1)*2,colwid+1     
PRINT: items=number.of.files     
ON ERROR GOTO Error.handle 'check for printing abort     
IF number.of.col=1 THEN onecol    
IF number.of.lines<number.of.files/2 THEN    items=number.of.lines*2 
   
 FOR i= 1 TO items STEP 2         
PRINT #1,LEFT$(filename$(i),colwid), LEFT$(filename$(i+1),colwid)    

NEXT i 
    
CLOSE #1 

Exit.printing:     
WINDOW OUTPUT 1     
GOSUB display     
RETURN 

onecol:     
IF number.of.lines<number.of.files THEN      items=number.of.lines 
    
FOR i= 1 TO items         
 PRINT #1,LEFT$(filename$(i),colwid)     
NEXT i 
    
CLOSE #1     
GOTO Exit.printing     

Error.handle: RESET:RESUME
 
Exit.printing:STOP 

Setlabel:     
CLS:TEXTFONT(0):TEXTSIZE(12)     
LOCATE 1,1:PRINT"Lines per label:"     
LOCATE 3,1:PRINT "# of columns:"     lines$=STR$(number.of.lines)    
 
cwid$=STR$(number.of.col)     
EDIT FIELD 2,cwid$,(125,31)-(155,46),1,2
 EDIT FIELD 1,lines$,(125,1)-(145,16),1,2     
BUTTON 1,1,"OK",(25,70)-(75,88)    

 i=1     

loop:         
d=DIALOG(0)         
IF d=1 THEN Done ' got OK button         
IF d=2 THEN i=DIALOG(2):EDIT FIELD i 'got field 
IF d=6 THEN Done 'got return key         
IF d=7 THEN i=(i MOD 2)+1:EDIT FIELD i 'got TAB key         GOTO loop 
    

Done:         
lines$=EDIT$(1)         
number.of.lines=VAL(lines$)         
IF number.of.lines<1 OR  number.of.lines>9 THEN loop         cwid$=EDIT$(2) 
        
number.of.col=VAL(cwid$)         
IF number.of.col<1 OR number.of.col>2 THEN loop        
EDIT FIELD CLOSE 1:EDIT FIELD CLOSE 2         
BUTTON CLOSE 1         
CLS         
GOSUB display 
RETURN          

Quit:    
 MENU RESET     
WINDOW 1,"Disk Labeler",(2,40)-(510,250),1     
END 

Fontmenu:     
ON Menuitem GOSUB Blank,NY,Geneva,Monaco,          Blank,Pt09,Pt10,Pt12 
    
GOSUB display     
RETURN      

NY:     activefont=Newyork     
MENU 2,2,2: MENU 2,3,1:  MENU 2,4,1     
RETURN      

Geneva:     activefont=Geneva     
MENU 2,2,1: MENU 2,3,2:  MENU 2,4,1     
RETURN      

Monaco:     activefont=Monaco     
MENU 2,2,1: MENU 2,3,1: MENU 2,4,2     
RETURN     

 Pt09:     activesize=9     
MENU 2,6,2: MENU 2,7,1: MENU 2,8,1     
RETURN 

Pt10:     activesize=10     
MENU 2,6,1:  MENU 2,7,2: MENU 2,8,1     
RETURN      

Pt12:     activesize=12     
MENU 2,6,1: MENU 2,7,1: MENU 2,8,2     
RETURN      

SUB  Sort (item$(maxfiles),N) STATIC      
FOR i=1 TO  N-1        
 FOR j=i+1 TO  N             
IF  item$(i)> item$(j) THEN SWAP item$(i),item$(j)         
NEXT  j     
NEXT  i
END SUB 
 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Whitethorn Games combines two completely...
If you have ever gone fishing then you know that it is a lesson in patience, sitting around waiting for a bite that may never come. Well, that's because you have been doing it wrong, since as Whitehorn Games now demonstrates in new release Skate... | Read more »
Call of Duty Warzone is a Waiting Simula...
It's always fun when a splashy multiplayer game comes to mobile because they are few and far between, so I was excited to see the notification about Call of Duty: Warzone Mobile (finally) launching last week and wanted to try it out. As someone who... | Read more »
Albion Online introduces some massive ne...
Sandbox Interactive has announced an upcoming update to its flagship MMORPG Albion Online, containing massive updates to its existing guild Vs guild systems. Someone clearly rewatched the Helms Deep battle in Lord of the Rings and spent the next... | Read more »
Chucklefish announces launch date of the...
Chucklefish, the indie London-based team we probably all know from developing Terraria or their stint publishing Stardew Valley, has revealed the mobile release date for roguelike deck-builder Wildfrost. Developed by Gaziter and Deadpan Games, the... | Read more »
Netmarble opens pre-registration for act...
It has been close to three years since Netmarble announced they would be adapting the smash series Solo Leveling into a video game, and at last, they have announced the opening of pre-orders for Solo Leveling: Arise. [Read more] | Read more »
PUBG Mobile celebrates sixth anniversary...
For the past six years, PUBG Mobile has been one of the most popular shooters you can play in the palm of your hand, and Krafton is celebrating this milestone and many years of ups by teaming up with hit music man JVKE to create a special song for... | Read more »
ASTRA: Knights of Veda refuse to pump th...
In perhaps the most recent example of being incredibly eager, ASTRA: Knights of Veda has dropped its second collaboration with South Korean boyband Seventeen, named so as it consists of exactly thirteen members and a video collaboration with Lee... | Read more »
Collect all your cats and caterpillars a...
If you are growing tired of trying to build a town with your phone by using it as a tiny, ineffectual shover then fear no longer, as Independent Arts Software has announced the upcoming release of Construction Simulator 4, from the critically... | Read more »
Backbone complete its lineup of 2nd Gene...
With all the ports of big AAA games that have been coming to mobile, it is becoming more convenient than ever to own a good controller, and to help with this Backbone has announced the completion of their 2nd generation product lineup with their... | Read more »
Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »

Price Scanner via MacPrices.net

B&H has Apple’s 13-inch M2 MacBook Airs o...
B&H Photo has 13″ MacBook Airs with M2 CPUs and 256GB of storage in stock and on sale for up to $150 off Apple’s new MSRP, starting at only $849. Free 1-2 day delivery is available to most US... Read more
M2 Mac minis on sale for $100-$200 off MSRP,...
B&H Photo has Apple’s M2-powered Mac minis back in stock and on sale today for $100-$200 off MSRP. Free 1-2 day shipping is available for most US addresses: – Mac mini M2/256GB SSD: $499, save $... Read more
Mac Studios with M2 Max and M2 Ultra CPUs on...
B&H Photo has standard-configuration Mac Studios with Apple’s M2 Max & Ultra CPUs in stock today and on Easter sale for $200 off MSRP. Their prices are the lowest available for these models... Read more
Deal Alert! B&H Photo has Apple’s 14-inch...
B&H Photo has new Gray and Black 14″ M3, M3 Pro, and M3 Max MacBook Pros on sale for $200-$300 off MSRP, starting at only $1399. B&H offers free 1-2 day delivery to most US addresses: – 14″ 8... Read more
Department Of Justice Sets Sights On Apple In...
NEWS – The ball has finally dropped on the big Apple. The ball (metaphorically speaking) — an antitrust lawsuit filed in the U.S. on March 21 by the Department of Justice (DOJ) — came down following... Read more
New 13-inch M3 MacBook Air on sale for $999,...
Amazon has Apple’s new 13″ M3 MacBook Air on sale for $100 off MSRP for the first time, now just $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD/Space Gray): $999 $100 off MSRP... Read more
Amazon has Apple’s 9th-generation WiFi iPads...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Discounted 14-inch M3 MacBook Pros with 16GB...
Apple retailer Expercom has 14″ MacBook Pros with M3 CPUs and 16GB of standard memory discounted by up to $120 off Apple’s MSRP: – 14″ M3 MacBook Pro (16GB RAM/256GB SSD): $1691.06 $108 off MSRP – 14... Read more
Clearance 15-inch M2 MacBook Airs on sale for...
B&H Photo has Apple’s 15″ MacBook Airs with M2 CPUs (8GB RAM/256GB SSD) in stock today and on clearance sale for $999 in all four colors. Free 1-2 delivery is available to most US addresses.... Read more
Clearance 13-inch M1 MacBook Airs drop to onl...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray, Silver, & Gold) in stock and on clearance sale today for $300 off MSRP, only $699. Free 1-2 day shipping is available to most addresses in... Read more

Jobs Board

Senior Product Associate - *Apple* Pay (AME...
…is seeking a Senior Associate of Digital Product Management to support our Apple Pay product team. Labs drives innovation at American Express by originating, Read more
Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.