Print in columns

Just starting out? Need help? Post your questions and find answers here.
k3pto
User
User
Posts: 50
Joined: Sat Jan 17, 2015 5:24 pm

Print in columns

Post by k3pto »

I have just started using PB with a small data base. How do you print data in aligned columns with proportional fonts? The columns line up fine with a fixed font.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Print in columns

Post by infratec »

How do you do this at the moment?

Do you use StartVectorDrawing(PrinterVectorOutput()) and DrawVectorText()?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Print in columns

Post by RASHAD »

As infratec pointed out

Code: Select all

If PrintRequester()

  If StartPrinting("PureBasic Test")
  
    LoadFont(0, "Arial", 10)
  
    If StartVectorDrawing(PrinterVectorOutput())
      
      VectorFont(FontID(0), 12)
      VectorSourceColor(RGBA(0, 0, 0, 255))
      MovePathCursor(10, 25)
      AddPathText("Column #1")
      FillPath()

      VectorSourceColor(RGBA(255, 0, 0, 255))
      MovePathCursor(150, 25)
      AddPathText("Column #2")
      FillPath()
      
      VectorSourceColor(RGBA(0, 255,255, 255))
      MovePathCursor(300, 25)
      AddPathText("Column #3")
      FillPath()     
            
      VectorFont(FontID(0), 6)
      VectorSourceColor(RGBA(0, 0, 0, 255))
      MovePathCursor(10, 50)
      AddPathText("Column #2-1")
      FillPath()

      VectorSourceColor(RGBA(255, 0, 0, 255))
      MovePathCursor(150, 50)
      AddPathText("Column #2-2")
      FillPath()
      
      VectorSourceColor(RGBA(0, 0,255, 255))
      MovePathCursor(300, 50)
      AddPathText("Column #2-3")
      FillPath()
        
      StopVectorDrawing()
    EndIf
    
    StopPrinting()
  EndIf
EndIf
Egypt my love
Jeff8888
User
User
Posts: 38
Joined: Fri Jan 31, 2020 6:48 pm

Re: Print in columns

Post by Jeff8888 »

Use Rset() to right justify column entries with Chr($2007) for spacing. The code would be something like this.

Rset(string$,length,chr($2007))

Look up spacing of unicode character to see why this works.

Unicode character 2007 is known a figure space. It is a space character that is as wide as fixed-width digits. Usually used when typesetting vertically aligned numbers.

Below is a sample of code I used to print out a matrix. Note use of different space character for minus sign. Hope this helps.

Code: Select all

         ns1$=chr($2007)
         For i=1 To ncmps          ;For each row of B-Matrix  (note B is a square matrix)
          p$=RSet(Str(i),6,ns1$)
          For k=1 To ncmps        ;For each col of B-Matrix
            a.f=Bmatrix(i,k)*10000.0
            If a.f<0                                ;use slightly different spacing due to minus sign
              p$=p$+#CRLF$+RSet(StrF(Bmatrix(i,k)*10000.0,3),6,ns1$)
            Else
              p$=p$+#CRLF$+Chr($2004)+RSet(StrF(Bmatrix(i,k)*10000.0,3),5,ns1$)
            EndIf
          Next
          AddGadgetItem(#Table1,-1,p$) 
          If Mod(i,5)=0
            SetGadgetItemColor(#Table1,i-1,#PB_Gadget_BackColor,ColorBack3,#PB_All)
          EndIf
        Next
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: Print in columns

Post by Thorsten1867 »

I create a PDF (pbPDFModule.pbi) for such things.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Print in columns

Post by RASHAD »

Too many alternatives
- Create ListiconGadget()
- Populate the ListIcon()
- Save it as Image
- Print the Image later

But still the Vector lib. is the best
Egypt my love
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Print in columns

Post by Marc56us »

If there is a lot of text, prefer DrawVectorText() rather than AddPathText()
(See why on Remarks on help on AddPathText()). Same code works.
:wink:
k3pto
User
User
Posts: 50
Joined: Sat Jan 17, 2015 5:24 pm

Re: Print in columns

Post by k3pto »

Thank you all for the suggestions. I will try when I get home from work.
I am currently basing my code on the print sample that comes with the PB distribution.
k3pto
User
User
Posts: 50
Joined: Sat Jan 17, 2015 5:24 pm

Re: Print in columns

Post by k3pto »

I implemented the solution suggested by RASHAD and it works quite nicely. It took a little experimenting to get the spacing correct, but it was not too hard. After reading the differences between the two functions, I made the change suggested by Marc56us to use DrawVectorText() instead of AddPathText().

Thank you all for your help and quick replies.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Print in columns

Post by infratec »

With the vector lib you can change the units to mm or inch.
Maybe that's easier.

https://www.purebasic.com/documentation ... runit.html
Post Reply