Page 1 of 1

Print in columns

Posted: Tue Jul 05, 2022 1:49 pm
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.

Re: Print in columns

Posted: Tue Jul 05, 2022 2:05 pm
by infratec
How do you do this at the moment?

Do you use StartVectorDrawing(PrinterVectorOutput()) and DrawVectorText()?

Re: Print in columns

Posted: Tue Jul 05, 2022 2:45 pm
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

Re: Print in columns

Posted: Tue Jul 05, 2022 2:57 pm
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

Re: Print in columns

Posted: Tue Jul 05, 2022 3:05 pm
by Thorsten1867
I create a PDF (pbPDFModule.pbi) for such things.

Re: Print in columns

Posted: Tue Jul 05, 2022 3:14 pm
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

Re: Print in columns

Posted: Tue Jul 05, 2022 3:29 pm
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:

Re: Print in columns

Posted: Tue Jul 05, 2022 3:32 pm
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.

Re: Print in columns

Posted: Wed Jul 06, 2022 3:39 pm
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.

Re: Print in columns

Posted: Wed Jul 06, 2022 8:52 pm
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