Le 13/01/2020 à 20:23, Steve a écrit :
This is my follow up as promised. After the update I am confirming that printing is seriously screwed. I have traced thru code and information is flowing however the print (as in on paper) using the paint.drawtext is giving unstable results. Printing a receipt from my software produces a blank page with only the graphics and no text at all unless I reprint it then it comes out sort of ok. The font sizes are not stable I am getting fonts smaller than called for. Or larger sometimes. The problem is consistent across multiple projects.

The thing that changed in Gambas 3.14 is Printer.Font.Size. The size of the font has been scaled so that:

- It is consistent between screen and paper.
- It is consistent between Qt and GTK+.

The consistence is approximative, as it relies on screen DPI and printer DPI, which is not very exact, especially with screens.

This is done through the Painter.FontScale property that stores the font size adjustment. That property is initialized when Painter.Begin() is called.

To restore the old behaviour, you can try to set Painter.FontScale to 1.0 just before painting anything.

But it may not work in all cases.

Why? Because there are anyway big problems in your code: it uses absolute values for coordinates ('Y += 9' and so on). This is wrong, and works only by luck or by guess.

Unless you use Paint.Scale() to scale the viewport so that coordinates are now true absolutes values (cm or mm for example), these absolutes values mean nothing stable if the screen or paper changes, or if the library version changes, or if the meaning of font size changes, and so on.

The only thing you can be sure is that Paint.Width and Paint.Height is the size of your paper when printing. But it can use any unit.

You have several things to consider and do:

1) You can use Paint.Scale() so that Paint.Width and Paint.Height are now cm or mm, or any absolute unit you want.

2) Paint.Font.Size should be now really in *points*. One point = 1/72th inch ~= 3.5 mm.

3) You have to use Paint.TextSize() or Paint.TextHeight (the line height actually) to know the size of the text and where to print the next line.

4) You can use the new 'gb.form.print' component. It allows you to print through a preview dialog (the same that is used in the IDE for printing).

I strongly suggest that you do 3) and try 4). Then your code will be reliable and you will have a print preview for free.

As an example, I join to that mail the test module you can find in 'gb.form.print' source code.

Regards,


system Info

fedora 31 latest updates.
Gambas 3.14.2

It seems that the text is not printing at all, but the lines and or graphics do. I do not seem to be able to fix this here as I am pretty sure the problem is in a serious flaw in the interpreter, and it is now a critical issue as it is affecting business operations. Not to mention wasting paper and time to reprint everything.

This is a code snipet of just one printing routine that is not producing correctly.

=======================================================

Function RcptHeader80(SlsID As String, Y As Integer) As Integer
   Dim TVar, I, Fd As String

  Fd = PHPOS.FieldList("StoreName,StoreAddress1,StoreAddress2,StoreCity,StoreState,StoreZip,StorePhone")
   I = MySqlLib.GetAllData(PHPOS.zStoreInfo, Fd)

   Paint.Font.Name = "Arial"
   Paint.Font.Size = 18
   Paint.Font.Bold = True

   TVar = FuncLib.GetField(ByRef I, FuncLib.cFieldDelimiter)
   Paint.DrawRichText(TVar, 1, Y, Paint.Width, Y, Align.Center) 'name
   Y += 14

   TVar = FuncLib.GetField(ByRef I, FuncLib.cFieldDelimiter)
   Paint.Font.Size = 10
   Paint.DrawText(TVar, 1, Y, Paint.Width, Y, Align.Center) 'addr1

   Y += 9
   TVar = FuncLib.GetField(ByRef I, FuncLib.cFieldDelimiter)
   If TVar <> "" Then
     Paint.DrawText(TVar, 1, Y, Paint.Width, Y, Align.Center) 'addr2
     Y += 9
   Endif
   TVar = FuncLib.GetField(ByRef I, FuncLib.cFieldDelimiter)
  Paint.DrawText(TVar & " , " & FuncLib.GetField(ByRef I, FuncLib.cFieldDelimiter) & "  " & FuncLib.GetField(ByRef I, FuncLib.cFieldDelimiter), 1, Y, Paint.Width, Y, Align.Center) 'city state zip
   Y += 9
   TVar = FuncLib.GetField(ByRef I, FuncLib.cFieldDelimiter)
   Paint.DrawText(TVar, 1, Y, Paint.Width, Y, Align.Center) 'phone
   Y += 20
   RcptCustomer80(Y)
   Fd = PHPOS.FieldList("sDate,sTime")
   I = MySqlLib.GetData(PHPOS.zSalesHdr, Fd, "SalesID = " & Trim(SlsID))
   Paint.Font.Size = 8
  Paint.DrawText("Date  " & Format(Date(FuncLib.GetField(ByRef I, FuncLib.cFieldDelimiter)), "mm/dd/yyyy") & "  " & I, 30, Y, Paint.Width, Y, Align.Left)
   Y += 9
   Paint.DrawText("Sale  " & SlsID, 30, Y, Paint.Width, Y, Align.Left)
   Y += 80
   Paint.DrawText("Item", Clmn1, Y, Clmn1W, 14, Align.Left)
   Paint.DrawText("Desc", Clmn2, Y, Clmn2W, 14, Align.Left)
   Paint.DrawText("Price", Clmn3, Y, Clmn3W, 14, Align.Right)
   Paint.DrawText("Qty", Clmn4, Y, Clmn4W, 14, Align.Right)
   Paint.DrawText("Amount", Clmn5, Y, Clmn5W, 14, Align.Right)
   Y += 14
   Paint.FillRect(30, Y, Paint.Width, 2, Color.Black)
   Return Y
End

===================================================






--
Benoît Minisini
' Gambas module file

Private $hPrinter As Printer

Public Sub Main()

  $hPrinter = New Printer As "Printer"

  $hPrinter.MarginTop = 15  
  $hPrinter.Preview()

End

Public Sub Printer_Begin()
  
  Debug
  $hPrinter.Count = 3
  
End

Public Sub Printer_Draw()
  
  Dim H As Float
  
  Debug $hPrinter.Page;; "/";; Paint.W;; Paint.H

  Paint.Font = Font["Liberation Sans,10"]

  Debug "Paint.Width = "; Paint.Width
  Debug "Printer.Resolution = "; $hPrinter.Resolution
  Debug "Paint.ResolutionX = "; Paint.ResolutionX
  Debug "Paint.FontScale = "; Paint.FontScale
  Debug "Paint.Font.Size = "; Paint.Font.Size

  H = Paint.TextSize(" ").H
  Debug H;; Paint.TextHeight;; Paint.Font.H
  Paint.Font = Font["Liberation Sans,10"]
  Paint.DrawText(CStr($hPrinter.Page) & " WÊyg_", 0, 0, Paint.W, H, 
Align.Center)
  Paint.LineWidth = 1
  Paint.Rectangle(0, 0, Paint.W, H)
  Paint.Stroke
  
  Paint.DrawRichText(File.Load("molly-malone.txt"), 0, 100, Paint.W, Paint.H)
  
  'Paint.DrawText("ABCD",10,)
  
End

_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to