|
Post by Mark Dunham on May 13, 2019 9:34:27 GMT -5
I have a program that when I save the file it is saved as .rtf for printing. I have been playing with the code to create a nice layout for printing. Right now it seems pretty tedious to get the text printed in a nice format are there any suggestions for formatting files for printing?
|
|
|
Post by tsh73 on May 13, 2019 9:39:11 GMT -5
define "nice" first EDIT Someone might want LaTeX quality. For some things, easy HTML will do (with that, browser will do all word wrapping if you wouldn't bother) Also you 'll get bold/italic/tables.
|
|
|
Post by Mark Dunham on May 13, 2019 9:46:05 GMT -5
define "nice" first EDIT Someone might want LaTeX quality. For some things, easy HTML will do (with that, browser will do all word wrapping if you wouldn't bother) Also you 'll get bold/italic/tables. LOL. Basically I am printing a Character sheet for old school table top RPG as you can see by my sample code. So I guess when I say nice I mean evenly spaced aligned columns. As a note I think I have googled every combination of liberty basic and printing/formatting I could think of.
|
|
|
Post by mknarr on May 13, 2019 12:00:25 GMT -5
Formatting printing is one of the most difficult things in coding. My son is a software engineer that makes a living writing code for mass printing. Here is some code from Alyce Watson that I use for formatted printing in a commercial program. It is used to print several different forms.
'here are the basic instructions. 'Assume you have 10 items to a line, you will need to dim an 'array like this dim Array$(10). This will be used in [PrintOutput] 'When you are ready to send your stuff to the printer, you must open a tempory text file. 'For [PrintOutput] this must be named temp.txt and opened as a sequential file 'like this open "text.tmp" for output as #TextTemp 'Printer text file 'Next you must get each piece of data and print it to the temp.txt file. 'Your code might look something like this 'print #TextTemp, item1$ 'print #TextTemp, item2 'print #TextTemp, item3$ 'print #TextTemp, item4 'print #TextTemp, item5$ 'print #TextTemp, item6 'print #TextTemp, item7$ 'print #TextTemp, item8 'print #TextTemp, item9$ 'print #TextTemp, item10 'It doesn't matter if it's text or numerics 'If you need a blank line you must do this 'for x=1 to 10:print #TextTemp, "":next 'When you are finished, close #TextTemp 'gosub [Printoutput] 'Assume again you have 10 pieces of data to a line, you must print 10 pieces for 'each lin into the temp.txt file even if some are blank. Otherwise the '[PrintOutput] expects to see 10 items per line and will choke if it doesn't get that many. 'In the [PrintOutput] there are a few things which you must set. You 'can find them by looking for the lines marked '************* 'You will need to set Font$, FontSize and reset any font style you want. 'In my programs these are done through a font selection window and 'saved in the progam initilization file. 'The trick part is where you will have to change for the number of items 'and the spacing. Remember, everything depends on the API calls 'to get the dots per inch of your printer for dpi x and y as well as the 'total vertical bits for the page. Total horizontal bits aren't used. 'If you need word wrap, God forbid, you may need the horizontal total bits as well. [PrintOutput] 'Send job to printer 'this section gets the printer name from the system default$ = "" appName$ = "windows" keyName$ = "device" result$ = space$(49)+chr$(0) size = 50 calldll #kernel32, "GetProfileStringA",_ appName$ as ptr,_ keyName$ as ptr,_ default$ as ptr,_ result$ as ptr,_ size as long,_ result as long profile$ = left$(result$, instr(result$, chr$(0)) - 1) j = instr(profile$, ",", 1) PrtName$ = left$(profile$, j-1) 'printer name 'this section creates a device context for the printer j = j + 1 k = instr(profile$, ",", j) Driver$ = mid$(profile$, j, k-j) Driver$=Driver$+chr$(0) PrtName$=PrtName$+chr$(0) Output$= Right$(profile$, Len(profile$)-k) Init=0 calldll #gdi32, "CreateDCA", _ Driver$ as ptr, _ PrtName$ as ptr, _ Output$ as ptr, _ Init as long, _ pDC as long 'returns dots per inch width, printer calldll #gdi32, "GetDeviceCaps",_ pDC as long,_ _LOGPIXELSX as long,_ dpix as long 'returns dots per inch height, printer calldll #gdi32, "GetDeviceCaps",_ pDC as long,_ _LOGPIXELSY as long,_ dpiy as long 'returns dpi height of printed page calldll #gdi32, "GetDeviceCaps", pDC As long, _ _VERTRES As long, vbits As long 'returns dpi width of printed page NOT used in this program calldll #gdi32, "GetDeviceCaps", pDC As long, _ _HORZRES As long, hbits As long 'this struct is needed for StartDoc struct docInfo, _ cbSize as long,_ lpszDocName$ as ptr,_ lpszOutput$ as ptr,_ lpszDatatype$ as ptr,_ fwType as ulong docInfo.cbSize.struct=len(docInfo.struct) docInfo.lpszDocName$.struct="More Than an Address Book"+chr$(0) 'begins the print job calldll #gdi32, "StartDocA", _ pDC as long, _ 'the handle of the printer dc docInfo as struct, _ result as long gosub [startpage] 'set first text location and font height and width '*************** ' Set FontSize to .130 for 8 point '.145 for 9 point '.160 for 10 point '.175 for 11 point '.190 for 12 point '**************** xoffset =0 'set initial x offset in inches based on dpix yoffset =int(dpiy*.25)'set initial y offset in inches based on dpiy fontheight = int(dpiy*FontSize) 'set font height based on dpiy and FontSize fontwidth = int(fontheight/2.5)'setfont width as a ratio of fontheight, 2.5 is normal width to height tvbits=int(int((vbits-yoffset)/fontheight)*fontheight)'tvbits lines printed on one page textx= xoffset 'set initial x location texty= yoffset 'set initial y location 'set font attributes '**************** 'Set the following '**************** weight = _FW_NORMAL 'or _FW_BOLD italic = 0 'or 1 for italic underline = 0 'or 1 for underlined '***************** 'Font$ may be Comic Sans MS or Arial or Times New Roman or what ever you choose 'Font$ ="Times New Roman" or what ever you choose '*************** fontname$= Font$ + chr$(0) 'make sure Font$ = your chosen font gosub [createfont] gosub [selectfont] 'This section reads the text.tmp file one full line at a time 'and prints each item at the proper x coordinate 'prepare text and print text open "text.tmp" for input as #TextTemp '************* 'This is where it gets tricky. This is the part that actually 'reads the text.tmp file one line at a time and spaces each item 'on a line. 'Again assume that you have 10 items on each line and each item is 'spaced 1 inch apart. The example below does that but you can change 'to different spacing and number of items '******************** while eof(#TextTemp)=0 'do until EOF is greater than 0 for x= 1 to 10 'read the 10 items for the first line line input #TextTemp, Array$(x) next 'next read Array$(x) into text$ text$=Array$(1) 'set text$ to first item, first line textx=xoffset 'set x location gosub [printline] 'print the item text$=Array$(2) 'set text$ to second item, first line textx=int(dpix*1.0) 'set new x location gosub [printline] 'print item text$=Array$(3) 'set text$ to third item, first line textx=int(dpix*2.0)'set new x location gosub [printline] 'print item text$=Array$(4) 'set text$ to fourth item, first line textx=int(dpix*3.0)'set new x location gosub [printline] 'print item text$=Array$(5) 'etc textx=int(dpix*4.0) gosub [printline] text$=Array$(6) textx=int(dpix*5.0) gosub [printline] text$=Array$(7) textx=int(dpix*6.0) gosub [printline] text$=Array$(8) textx=int(dpix*7.0) gosub [printline] text$=Array$(9) textx=int(dpix*8.0) gosub [printline] text$=Array$(10) textx=int(dpix*9.0) gosub [printline] texty=texty+fontheight'finaly after the last item is printed on the line, index location to next line wend close #TextTemp kill "text.tmp" 'delete the temp.txt file when finished 'end printing session calldll #gdi32, "EndDoc", _ pDC as long,_ 'the handle of the printer dc result as long 'reset font calldll #gdi32, "SelectObject",_ pDC as long,_ 'handle to DC oldfont as long,_ 'select old font into DC newfont as long 'handle of font no longer in use 'delete new font calldll #gdi32, "DeleteObject",_ newfont as long,_ 'handle of font to delete result as long 'nonzero if successful 'delete printer dc calldll #gdi32, "DeleteDC",_ pDC as long,_ 'the handle of the Printer DC result as long 'a return of 0 indicates an error [printline]'does some checking and send text$ to the printer if texty >= tvbits then 'check to see if new page needed gosub [endpage] gosub [startpage] gosub [selectfont] texty=yoffset 'reset y position to original value for new page. end if 'send text to printer lengthtext=len(text$) 'get the length of the text string calldll #gdi32, "TextOutA", _ pDC as long,_ 'device context textx as long,_ 'x origin of text texty as long,_ 'y origin of text text$ as ptr,_ 'text string to display lengthtext as long,_'length of text string result as long 'nonzero if successful return [startpage] 'begins a new page calldll #gdi32, "StartPage", _ pDC as long, _ 'the handle of the printer dc r as long return [endpage] 'eject page calldll #gdi32, "EndPage", _ pDC as long,_ 'the handle of the printer dc result as long return [createfont] 'create a font calldll #gdi32, "CreateFontA",_ fontheight as long, fontwidth as long,_ escapement as long, orientation as long,_ weight as long, italic as long,_ underline as long, strikeout as long,_ CharSet as long, OutputPrecision as long,_ ClipPrecision as long, Quality as long,_ PitchAndFamily as long,fontname$ as PTR,_ newfont as long return [selectfont] 'select font into printer device context calldll #gdi32, "SelectObject",_ pDC as long,_ 'handle to the DC newfont as long,_ 'handle to the new font oldfont as long 'handle to the previous font return
If you need help using it, maybe I can help.
|
|
|
Post by Mark Dunham on May 13, 2019 12:27:53 GMT -5
Formatting printing is one of the most difficult things in coding. My son is a software engineer that makes a living writing code for mass printing. Here is some code from Alyce Watson that I use for formatted printing in a commercial program. It is used to print several different forms. 'here are the basic instructions. 'Assume you have 10 items to a line, you will need to dim an 'array like this dim Array$(10). This will be used in [PrintOutput] 'When you are ready to send your stuff to the printer, you must open a tempory text file. 'For [PrintOutput] this must be named temp.txt and opened as a sequential file 'like this open "text.tmp" for output as #TextTemp 'Printer text file 'Next you must get each piece of data and print it to the temp.txt file. 'Your code might look something like this 'print #TextTemp, item1$ 'print #TextTemp, item2 'print #TextTemp, item3$ 'print #TextTemp, item4 'print #TextTemp, item5$ 'print #TextTemp, item6 'print #TextTemp, item7$ 'print #TextTemp, item8 'print #TextTemp, item9$ 'print #TextTemp, item10 'It doesn't matter if it's text or numerics 'If you need a blank line you must do this 'for x=1 to 10:print #TextTemp, "":next 'When you are finished, close #TextTemp 'gosub [Printoutput] 'Assume again you have 10 pieces of data to a line, you must print 10 pieces for 'each lin into the temp.txt file even if some are blank. Otherwise the '[PrintOutput] expects to see 10 items per line and will choke if it doesn't get that many. 'In the [PrintOutput] there are a few things which you must set. You 'can find them by looking for the lines marked '************* 'You will need to set Font$, FontSize and reset any font style you want. 'In my programs these are done through a font selection window and 'saved in the progam initilization file. 'The trick part is where you will have to change for the number of items 'and the spacing. Remember, everything depends on the API calls 'to get the dots per inch of your printer for dpi x and y as well as the 'total vertical bits for the page. Total horizontal bits aren't used. 'If you need word wrap, God forbid, you may need the horizontal total bits as well. [PrintOutput] 'Send job to printer 'this section gets the printer name from the system default$ = "" appName$ = "windows" keyName$ = "device" result$ = space$(49)+chr$(0) size = 50 calldll #kernel32, "GetProfileStringA",_ appName$ as ptr,_ keyName$ as ptr,_ default$ as ptr,_ result$ as ptr,_ size as long,_ result as long profile$ = left$(result$, instr(result$, chr$(0)) - 1) j = instr(profile$, ",", 1) PrtName$ = left$(profile$, j-1) 'printer name 'this section creates a device context for the printer j = j + 1 k = instr(profile$, ",", j) Driver$ = mid$(profile$, j, k-j) Driver$=Driver$+chr$(0) PrtName$=PrtName$+chr$(0) Output$= Right$(profile$, Len(profile$)-k) Init=0 calldll #gdi32, "CreateDCA", _ Driver$ as ptr, _ PrtName$ as ptr, _ Output$ as ptr, _ Init as long, _ pDC as long 'returns dots per inch width, printer calldll #gdi32, "GetDeviceCaps",_ pDC as long,_ _LOGPIXELSX as long,_ dpix as long 'returns dots per inch height, printer calldll #gdi32, "GetDeviceCaps",_ pDC as long,_ _LOGPIXELSY as long,_ dpiy as long 'returns dpi height of printed page calldll #gdi32, "GetDeviceCaps", pDC As long, _ _VERTRES As long, vbits As long 'returns dpi width of printed page NOT used in this program calldll #gdi32, "GetDeviceCaps", pDC As long, _ _HORZRES As long, hbits As long 'this struct is needed for StartDoc struct docInfo, _ cbSize as long,_ lpszDocName$ as ptr,_ lpszOutput$ as ptr,_ lpszDatatype$ as ptr,_ fwType as ulong docInfo.cbSize.struct=len(docInfo.struct) docInfo.lpszDocName$.struct="More Than an Address Book"+chr$(0) 'begins the print job calldll #gdi32, "StartDocA", _ pDC as long, _ 'the handle of the printer dc docInfo as struct, _ result as long gosub [startpage] 'set first text location and font height and width '*************** ' Set FontSize to .130 for 8 point '.145 for 9 point '.160 for 10 point '.175 for 11 point '.190 for 12 point '**************** xoffset =0 'set initial x offset in inches based on dpix yoffset =int(dpiy*.25)'set initial y offset in inches based on dpiy fontheight = int(dpiy*FontSize) 'set font height based on dpiy and FontSize fontwidth = int(fontheight/2.5)'setfont width as a ratio of fontheight, 2.5 is normal width to height tvbits=int(int((vbits-yoffset)/fontheight)*fontheight)'tvbits lines printed on one page textx= xoffset 'set initial x location texty= yoffset 'set initial y location 'set font attributes '**************** 'Set the following '**************** weight = _FW_NORMAL 'or _FW_BOLD italic = 0 'or 1 for italic underline = 0 'or 1 for underlined '***************** 'Font$ may be Comic Sans MS or Arial or Times New Roman or what ever you choose 'Font$ ="Times New Roman" or what ever you choose '*************** fontname$= Font$ + chr$(0) 'make sure Font$ = your chosen font gosub [createfont] gosub [selectfont] 'This section reads the text.tmp file one full line at a time 'and prints each item at the proper x coordinate 'prepare text and print text open "text.tmp" for input as #TextTemp '************* 'This is where it gets tricky. This is the part that actually 'reads the text.tmp file one line at a time and spaces each item 'on a line. 'Again assume that you have 10 items on each line and each item is 'spaced 1 inch apart. The example below does that but you can change 'to different spacing and number of items '******************** while eof(#TextTemp)=0 'do until EOF is greater than 0 for x= 1 to 10 'read the 10 items for the first line line input #TextTemp, Array$(x) next 'next read Array$(x) into text$ text$=Array$(1) 'set text$ to first item, first line textx=xoffset 'set x location gosub [printline] 'print the item text$=Array$(2) 'set text$ to second item, first line textx=int(dpix*1.0) 'set new x location gosub [printline] 'print item text$=Array$(3) 'set text$ to third item, first line textx=int(dpix*2.0)'set new x location gosub [printline] 'print item text$=Array$(4) 'set text$ to fourth item, first line textx=int(dpix*3.0)'set new x location gosub [printline] 'print item text$=Array$(5) 'etc textx=int(dpix*4.0) gosub [printline] text$=Array$(6) textx=int(dpix*5.0) gosub [printline] text$=Array$(7) textx=int(dpix*6.0) gosub [printline] text$=Array$(8) textx=int(dpix*7.0) gosub [printline] text$=Array$(9) textx=int(dpix*8.0) gosub [printline] text$=Array$(10) textx=int(dpix*9.0) gosub [printline] texty=texty+fontheight'finaly after the last item is printed on the line, index location to next line wend close #TextTemp kill "text.tmp" 'delete the temp.txt file when finished 'end printing session calldll #gdi32, "EndDoc", _ pDC as long,_ 'the handle of the printer dc result as long 'reset font calldll #gdi32, "SelectObject",_ pDC as long,_ 'handle to DC oldfont as long,_ 'select old font into DC newfont as long 'handle of font no longer in use 'delete new font calldll #gdi32, "DeleteObject",_ newfont as long,_ 'handle of font to delete result as long 'nonzero if successful 'delete printer dc calldll #gdi32, "DeleteDC",_ pDC as long,_ 'the handle of the Printer DC result as long 'a return of 0 indicates an error [printline]'does some checking and send text$ to the printer if texty >= tvbits then 'check to see if new page needed gosub [endpage] gosub [startpage] gosub [selectfont] texty=yoffset 'reset y position to original value for new page. end if 'send text to printer lengthtext=len(text$) 'get the length of the text string calldll #gdi32, "TextOutA", _ pDC as long,_ 'device context textx as long,_ 'x origin of text texty as long,_ 'y origin of text text$ as ptr,_ 'text string to display lengthtext as long,_'length of text string result as long 'nonzero if successful return [startpage] 'begins a new page calldll #gdi32, "StartPage", _ pDC as long, _ 'the handle of the printer dc r as long return [endpage] 'eject page calldll #gdi32, "EndPage", _ pDC as long,_ 'the handle of the printer dc result as long return [createfont] 'create a font calldll #gdi32, "CreateFontA",_ fontheight as long, fontwidth as long,_ escapement as long, orientation as long,_ weight as long, italic as long,_ underline as long, strikeout as long,_ CharSet as long, OutputPrecision as long,_ ClipPrecision as long, Quality as long,_ PitchAndFamily as long,fontname$ as PTR,_ newfont as long return [selectfont] 'select font into printer device context calldll #gdi32, "SelectObject",_ pDC as long,_ 'handle to the DC newfont as long,_ 'handle to the new font oldfont as long 'handle to the previous font return
If you need help using it, maybe I can help. Thank you for the example and the sample code I will dig into it. In C# using WPF there are tools that do a ton of the heavy lifting for you I would like to do it in Liberty Basic as it really is my language of choice. I know quite a few of these high level languages but in the end I find myself just loving LB. I am hoping that asking the question will do exactly what you did give an example that myself and the community can use and build upon. Thank you again for posting if I have any questions I will be sure to post them
|
|
|
Post by pablosl on May 27, 2019 21:05:10 GMT -5
|
|
|
Post by metro on May 27, 2019 21:23:38 GMT -5
For example..........
'This demo will not function without lbbrowse.dll '****************************************************** 'LBBROWSE.DLL is copyright Alyce Watson, 2005. 'LBBROWSE.DLL is freeware. You may use it in any application, 'including commercial products. A credit to the author and a 'link to the website must be included in your program's 'documentation or readme file, and in any source code released 'to the public. 'Alyce Watson 'http://alycesrestaurant.com/ '****************************************************** nomainwin dim info$(10,10) 'make up some data to display in a table dim myData$(20,2) dataField$="One Two Three Four Five Six Seven Eight Nine Ten "+_ "Eleven Twelve Thirteen Fourteen Fifteen * # @ $ Twenty" 'put the data into arrays for n=1 to 20 myData$(n,1)=right$("0"+str$(n),2) myData$(n,2)=word$(dataField$,n) next n sortColumn=2 sort myData$(),1,20,sortColumn fileExists=checkExists("lbbrowse.dll") if fileExists = 0 then notice "Demo requires missing dll";chr$(13);"lbbrowse.DLL can be downloaded from";chr$(13);_ "http://alycesrestaurant.com/";chr$(13);_ "The dll is generously provided as freeware";chr$(13);_ "and is Copyright by Alyce Watson." end end if reportFileName$=DefaultDir$+"\report1.htm" 'make your own logo jpeg image, alternative text is displayed if image 'is not found logoImgFile$="chart.jpg" backGroundFile$="libertyBackground.jpg" columnTitle$(1)="Word #" columnTitle$(2)="Data" tableBorder=1 UpperLeftX=1:UpperLeftY=1 WindowWidth=700:WindowHeight=550 menu #main, "&File","&Internet Options",[internetOptions],"&Print Preview",[printPreview],_ "P&rint",[printHtmlReport],"&Exit",[quit] menu #main, "&Sort","Sort by &Word #",[sortColumn1],"Sort by &Data",[sortColumn2] stylebits #main.rptL, _ES_CENTER or _SS_CENTERIMAGE,0,_WS_EX_CLIENTEDGE,0 statictext #main.rptL, "Report title >", 8, 10, 80, 25 textbox #main.rpt, 90,10,200,25 button #main.rb, "Show report", [showHtmlReport],ul 300,10,90,25 button #main.pnt, "Print report", [printHtmlReport],ul 300,10,90,25 checkbox #main.cbx, "Remove table border", [tableBorder],[tableBorder],400,10,140,25 checkbox #main.cbx2, "Remove background", [tableBgnd],[tableBgnd],550,10,140,25 stylebits #main, 0,_WS_VISIBLE,0,0 open "HTML reports from LibertyBASIC" for window as #main #main, "trapclose quit" #main "resizehandler resizer" hMain=hwnd(#main) #main.pnt, "!hide" #main.cbx, "hide" #main.cbx2, "hide" #main, "font arial 9" 'initial page for browser to display url$=DefaultDir$+"\blank.htm" 'set up embedded browser utilising Alyce's lbbrowse dll open "lbbrowse.dll" for dll as #browse calldll #browse, "CreateBrowser", hMain as ulong, 40 as long, _ 55 as long, 600 as long, 400 as long,_ url$ as ptr, 1 as long, result as ulong
if result<>0 then notice "Unable to load browser control." end end if
'hide browser statusbar calldll #browse, "ShowStatusbar", 0 as long, re as void 'enter default report title in textbox #main.rpt, "'My Report'" #main, "show" wait
sub resizer h$ newW=WindowWidth-80:newH = WindowHeight-75 calldll #browse, "MoveBrowser",40 as long, 55 as long, newW as long,_ newH as long, r as void end sub
[showHtmlReport] gosub [buildHtmlReport] wait
[tableBgnd] tableBg=1-tableBg if tableBg=1 then backGroundFile$="" else backGroundFile$="libertyBackground.jpg" end if gosub [buildHtmlReport] wait
[tableBorder] tableBorder=1-tableBorder gosub [buildHtmlReport] wait
[sortColumn1] sortColumn=1 sort myData$(),1,20,sortColumn gosub [buildHtmlReport] wait
[sortColumn2] sortColumn=2 sort myData$(),1,20,sortColumn gosub [buildHtmlReport] wait
[buildHtmlReport] 'show browser calldll #browse, "ShowBrowser", 1 as long, re as void 'get report title from textbox #main.rpt, "!contents? reportTitle$" 'open file to store report open reportFileName$ for output as #htm 'generate html code for report page formatted as table, two columns per row 'note fixed background graphic over which table scrolls. #htm, "<html><head><title>LibertyBASIC/HTML report generator</title></head>";_ "<body background=";backGroundFile$;" bgproperties=fixed><HR size=6 color=gold>";_ "<font size=5 color=red><I>";reportTitle$;"</I>";_ "<img src=";logoImgFile$;" hspace=200 alt=logo_here>";date$();"</font> (Sorted by: ";_ columnTitle$(sortColumn);")</font><BR><HR color=red><BR>" #htm, "<table border=";tableBorder;" width=100% cellspacing=0 bordercolor=gainsboro>" 'enter column titles #htm, "<tr><td width=20% align=left><font size=4 color=green>";columnTitle$(1);"</font></td>" #htm, "<td width=50% align=left><font size=4 color=green>";columnTitle$(2);"</font></td>" #htm, "<td width=30% align=left><font size=4 color=green> </font></td></tr>" fontColor$="blue" 'font color for first ten items 'enter data from arrays into rows of a table for row=1 to 20 #htm, "<tr><td width=20%><font size=2 color=";fontColor$;">"+myData$(row,1);" </font></td>" #htm, "<td width=50%><font size=2 color=";fontColor$;">"+myData$(row,2);" </font></td>" #htm, "<td width=30%><font size=2 color=";fontColor$;"> </font></td></tr>" if row=10 then fontColor$="purple" 'font color for next ten items next row #htm, "</table><BR><BR>This HTML generated report is produced in an embedded browser "+_ "using lbbrowse.dll, generously gifted to us by Alyce, to whom we are "+_ "eternally indebted! This dll gives us a tool to display and print data "+_ "and documents in tables, frames, full colour, including graphics etc.</body></html>" close #htm 'display the report in the browser
calldll #browse, "Navigate",reportFileName$ as ptr, ret as void #main.rb, "!hide" #main.pnt, "!show" #main.cbx, "show" #main.cbx2, "show" return
[printPreview] calldll #browse, "PrintPreview", re as void wait
[printHtmlReport] calldll #browse, "BrowserPrint", re as void wait
[internetOptions] calldll #browse, "InternetOptions", re as void wait
[quit] call quit "#main"
sub quit hW$ calldll #browse, "DestroyBrowser", re as void close #browse close #hW$ end end sub
function checkExists(f$) files "",f$, info$( checkExists = val(info$(0, 0)) end function
|
|
|
Post by Mark Dunham on May 28, 2019 12:21:10 GMT -5
For example..........
'This demo will not function without lbbrowse.dll '****************************************************** 'LBBROWSE.DLL is copyright Alyce Watson, 2005. 'LBBROWSE.DLL is freeware. You may use it in any application, 'including commercial products. A credit to the author and a 'link to the website must be included in your program's 'documentation or readme file, and in any source code released 'to the public. 'Alyce Watson 'http://alycesrestaurant.com/ '****************************************************** nomainwin dim info$(10,10) 'make up some data to display in a table dim myData$(20,2) dataField$="One Two Three Four Five Six Seven Eight Nine Ten "+_ "Eleven Twelve Thirteen Fourteen Fifteen * # @ $ Twenty" 'put the data into arrays for n=1 to 20 myData$(n,1)=right$("0"+str$(n),2) myData$(n,2)=word$(dataField$,n) next n sortColumn=2 sort myData$(),1,20,sortColumn fileExists=checkExists("lbbrowse.dll") if fileExists = 0 then notice "Demo requires missing dll";chr$(13);"lbbrowse.DLL can be downloaded from";chr$(13);_ "http://alycesrestaurant.com/";chr$(13);_ "The dll is generously provided as freeware";chr$(13);_ "and is Copyright by Alyce Watson." end end if reportFileName$=DefaultDir$+"\report1.htm" 'make your own logo jpeg image, alternative text is displayed if image 'is not found logoImgFile$="chart.jpg" backGroundFile$="libertyBackground.jpg" columnTitle$(1)="Word #" columnTitle$(2)="Data" tableBorder=1 UpperLeftX=1:UpperLeftY=1 WindowWidth=700:WindowHeight=550 menu #main, "&File","&Internet Options",[internetOptions],"&Print Preview",[printPreview],_ "P&rint",[printHtmlReport],"&Exit",[quit] menu #main, "&Sort","Sort by &Word #",[sortColumn1],"Sort by &Data",[sortColumn2] stylebits #main.rptL, _ES_CENTER or _SS_CENTERIMAGE,0,_WS_EX_CLIENTEDGE,0 statictext #main.rptL, "Report title >", 8, 10, 80, 25 textbox #main.rpt, 90,10,200,25 button #main.rb, "Show report", [showHtmlReport],ul 300,10,90,25 button #main.pnt, "Print report", [printHtmlReport],ul 300,10,90,25 checkbox #main.cbx, "Remove table border", [tableBorder],[tableBorder],400,10,140,25 checkbox #main.cbx2, "Remove background", [tableBgnd],[tableBgnd],550,10,140,25 stylebits #main, 0,_WS_VISIBLE,0,0 open "HTML reports from LibertyBASIC" for window as #main #main, "trapclose quit" #main "resizehandler resizer" hMain=hwnd(#main) #main.pnt, "!hide" #main.cbx, "hide" #main.cbx2, "hide" #main, "font arial 9" 'initial page for browser to display url$=DefaultDir$+"\blank.htm" 'set up embedded browser utilising Alyce's lbbrowse dll open "lbbrowse.dll" for dll as #browse calldll #browse, "CreateBrowser", hMain as ulong, 40 as long, _ 55 as long, 600 as long, 400 as long,_ url$ as ptr, 1 as long, result as ulong
if result<>0 then notice "Unable to load browser control." end end if
'hide browser statusbar calldll #browse, "ShowStatusbar", 0 as long, re as void 'enter default report title in textbox #main.rpt, "'My Report'" #main, "show" wait
sub resizer h$ newW=WindowWidth-80:newH = WindowHeight-75 calldll #browse, "MoveBrowser",40 as long, 55 as long, newW as long,_ newH as long, r as void end sub
[showHtmlReport] gosub [buildHtmlReport] wait
[tableBgnd] tableBg=1-tableBg if tableBg=1 then backGroundFile$="" else backGroundFile$="libertyBackground.jpg" end if gosub [buildHtmlReport] wait
[tableBorder] tableBorder=1-tableBorder gosub [buildHtmlReport] wait
[sortColumn1] sortColumn=1 sort myData$(),1,20,sortColumn gosub [buildHtmlReport] wait
[sortColumn2] sortColumn=2 sort myData$(),1,20,sortColumn gosub [buildHtmlReport] wait
[buildHtmlReport] 'show browser calldll #browse, "ShowBrowser", 1 as long, re as void 'get report title from textbox #main.rpt, "!contents? reportTitle$" 'open file to store report open reportFileName$ for output as #htm 'generate html code for report page formatted as table, two columns per row 'note fixed background graphic over which table scrolls. #htm, "<html><head><title>LibertyBASIC/HTML report generator</title></head>";_ "<body background=";backGroundFile$;" bgproperties=fixed><HR size=6 color=gold>";_ "<font size=5 color=red><I>";reportTitle$;"</I>";_ "<img src=";logoImgFile$;" hspace=200 alt=logo_here>";date$();"</font> (Sorted by: ";_ columnTitle$(sortColumn);")</font><BR><HR color=red><BR>" #htm, "<table border=";tableBorder;" width=100% cellspacing=0 bordercolor=gainsboro>" 'enter column titles #htm, "<tr><td width=20% align=left><font size=4 color=green>";columnTitle$(1);"</font></td>" #htm, "<td width=50% align=left><font size=4 color=green>";columnTitle$(2);"</font></td>" #htm, "<td width=30% align=left><font size=4 color=green> </font></td></tr>" fontColor$="blue" 'font color for first ten items 'enter data from arrays into rows of a table for row=1 to 20 #htm, "<tr><td width=20%><font size=2 color=";fontColor$;">"+myData$(row,1);" </font></td>" #htm, "<td width=50%><font size=2 color=";fontColor$;">"+myData$(row,2);" </font></td>" #htm, "<td width=30%><font size=2 color=";fontColor$;"> </font></td></tr>" if row=10 then fontColor$="purple" 'font color for next ten items next row #htm, "</table><BR><BR>This HTML generated report is produced in an embedded browser "+_ "using lbbrowse.dll, generously gifted to us by Alyce, to whom we are "+_ "eternally indebted! This dll gives us a tool to display and print data "+_ "and documents in tables, frames, full colour, including graphics etc.</body></html>" close #htm 'display the report in the browser
calldll #browse, "Navigate",reportFileName$ as ptr, ret as void #main.rb, "!hide" #main.pnt, "!show" #main.cbx, "show" #main.cbx2, "show" return
[printPreview] calldll #browse, "PrintPreview", re as void wait
[printHtmlReport] calldll #browse, "BrowserPrint", re as void wait
[internetOptions] calldll #browse, "InternetOptions", re as void wait
[quit] call quit "#main"
sub quit hW$ calldll #browse, "DestroyBrowser", re as void close #browse close #hW$ end end sub
function checkExists(f$) files "",f$, info$( checkExists = val(info$(0, 0)) end function
Thanks Metro I will check it out.
|
|
ntech
New Member
Posts: 49
|
Post by ntech on Jun 18, 2019 15:59:14 GMT -5
define "nice" first EDIT Someone might want LaTeX quality. For some things, easy HTML will do (with that, browser will do all word wrapping if you wouldn't bother) Also you 'll get bold/italic/tables. LOL. Basically I am printing a Character sheet for old school table top RPG as you can see by my sample code. So I guess when I say nice I mean evenly spaced aligned columns. As a note I think I have googled every combination of liberty basic and printing/formatting I could think of. Awesome. I love tabletop rpgs myself. Anyway, here's a sample bit of code to align columns, etc. global width
width = 80 'Width (in characters)
mainwin 90 24
print "1) Demo of center$(), spacer$(), and leftAndRight$()" print "2) Demo of said functions in action"
input ">"; choice$
if choice$ = "1" then
call demo$
else
call charSheet$
end if
end
sub demo$
cls print "Note: '|' denotes borders of screen."
print "|"+spacer$("-", width)+"|" print "|"+center$("ABC")+"|" print "|"+leftAndRight$("Name: Me", "Age: 24")+"|" print "|"+spacer$("-", width)+"|"
end sub
sub charSheet$
print spacer$("#", width) width = width - 2 'Decrement width to add custom border print "#"+ center$("Pathfinder Character Sheet") +"#" width = width + 2 'Border (the #) added, reverse it. print spacer$("#", width) print print center$("Name: Imzawa" + tab$(2) + "Player: Me") print center$("Homeland: Cartha" + tab$(2) + "Campaign: Mages Blade") print center$("Level: 1 Race: Half-Orc Class: Fighter") print center$("Deity: Desna (CG)" + tab$(2) + "Alignment: Chaotic Good") print center$("Size: Medium Height: 5ft. - 8in. Weight: 195lbs") print center$("Age: 24 Gender: Female Hair: Red Scar: Burns") print center$("Piercing: None" + tab$(2) + "Tattoo: None")
end sub
function tab$(x)
for i = 1 to x tab$ = tab$ + " " next i
end function
function leftAndRight$(leftText$, rightText$)
'Returns a string made up of a piece of 'text, one aligned left, the other aligned 'right.
lltxt = len(leftText$) lrtxt = len(rightText$)
gap = width - (lltxt+lrtxt)
spaceStr$ = spacer$(" ", width)
leftAndRight$ = leftText$ + left$(spaceStr$, gap) + rightText$
end function
function center$(text$)
'Returns centered text
ltxt = len(text$)
diff = int((width - ltxt) / 2)
spaceStr$ = spacer$(" ", width)
checkLen = len(left$(spaceStr$, diff)+text$+left$(spaceStr$, diff))
if checkLen < width then
center$ = left$(spaceStr$, diff+(width-checkLen))+text$+left$(spaceStr$, diff)
else
center$ = left$(spaceStr$, diff)+text$+left$(spaceStr$, diff)
end if
end function
function spacer$(char$, length)
'Returns a string containing as many char$ as length
spacer$ = ""
for i = 1 to length
spacer$ = spacer$ + char$
next i
end function
Demo if it in action: The player information is hard coded, however, it would work well with variables for player name, alignment, etc.
|
|
|
Post by Mark Dunham on Jun 25, 2019 12:17:13 GMT -5
I can definitely work with this thank you. I have spent a ton of time coding generating character abilities and have not gotten back over to the printing yet. I have added the following to what I had - Mute/Unmute music
- Fixed issue where racial modifiers were being added multiple times
- Moved call to gold generation to stop random regen of starting gold
- Added random name generator
- Minor Tweaks and changes
I will be making an official thread for the beta soon but here is what I have so far. Pathfinder Character Generator Beta 1.0.0.2
|
|
|
Post by meerkat on Jun 26, 2019 5:16:56 GMT -5
For really simple "nice" aligned format, the align$ function might work.
siz$ = "14,13,12,11,10,9,8,7,5" algn$ = "l,r,c,l,r,c,l,r,c" hda$ = "+-------------------------------" for i = 1 to 9 siz = val(word$(siz$,i,",")) print "|";align$("Hdr-";i,siz,"c"); hdr1$ = hdr1$ + left$(hda$,siz + 1) next i hdr1$ = hdr1$ + "+" print "|" : print hdr1$
for j = 1 to 10 for i = 1 to 9 print "|";align$("col-";j;i,val(word$(siz$,i,",")),word$(algn$,i,",")); next i print "|" next j print hdr1$ end
' ------------------------------------- ' Align fld$ to left right or center ' for a given width ' ------------------------------------- FUNCTION align$(fld$,width,lrc$) s = width - len(fld$) fld$ = left$(fld$,width) if s < 1 then align$ = fld$ else b$ = " " if lrc$ = "l" then align$ = fld$;left$(b$,s) if lrc$ = "r" then align$ = left$(b$,s);fld$ if lrc$ = "c" then align$ = left$(b$,int(s / 2));fld$;left$(b$,int(s / 2) + (s and 1)) end if END FUNCTION
|
|
|
Post by Mark Dunham on Jun 26, 2019 7:32:54 GMT -5
For really simple "nice" aligned format, the align$ function might work. print "+-------------------------------+" print "| formating text |" print "| Field:Description Amount |" print "+--------:-----------:----------+" print align$("Name:",10,"r");align$("Imzawa",10,"l");align$("1.00",8,"r") print align$("Player:",10,"r");align$("",10,"l");align$("2.00",8,"r") print align$("Homeland:",10,"r");align$("Cartha",10,"l");align$("3.00",8,"r") print align$("Campaign:",10,"r");align$("Maga Blade",10,"l");align$("4.00",8,"r") print align$("Level:",10,"r");align$("1",10,"l");align$("5.00",8,"r") print "--------------------------------" end
' ------------------------------------- ' Align fld$ to left right or center ' for a given width ' ------------------------------------- FUNCTION align$(fld$,width,lrc$) s = width - len(fld$) fld$ = left$(fld$,width) if s < 1 then align$ = fld$ else b$ = " " if lrc$ = "l" then align$ = fld$;left$(b$,s) if lrc$ = "r" then align$ = left$(b$,s);fld$ if lrc$ = "c" then align$ = left$(b$,int(s / 2));fld$;left$(b$,int(s / 2) + (s and 1)) end if END FUNCTION
I will give that a test as well. Thanks for adding to this greatly appreciated.
|
|