AddPathBox Bug PB573

Just starting out? Need help? Post your questions and find answers here.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

AddPathBox Bug PB573

Post by Saki »

It is a coordinates problem.
I assume it primarily affects all functions of the version of VectorLib used here under WindowsOS.
Under Linux and Mac the error does not occur.
There is a shift of the output coordinates, which cannot be calculated with a workaround.
For pixel accurate outputs this is very bad.

I think it is the same bug as in this thread:
https://www.purebasic.fr/english/viewto ... =4&t=77019

But here the problem is now very concise and easy to make visible without having to analyze many postings which are first based on assumptions and only later become more and more concrete.
Therefore I kindly ask for your understanding.
The bug was probably not recognized by users for years, because usually very difficult to establish a connection between cause and effect.

The text lines themselves also shift, so about 1 pixel every three lines.
When DPI aware is used at high scales, it is in fact no longer possible to calculate a reasonably suitable offset with a workaround.

Image

Code: Select all

window_ID=OpenWindow(#PB_Any, 0, 0, 600, 650, "", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
canvas_ID=CanvasGadget(#PB_Any, 0, 0, WindowWidth(window_ID), WindowHeight(window_ID))

font_ID=LoadFont(#PB_Any, "", 15+Bool(#PB_Compiler_OS=#PB_OS_Windows)) ; For better compare with Linux - Mac not adapted here

For i=1 To 25 : text$+LSet ("X", 30 ,"X") +#LF$ : Next i

StartVectorDrawing(CanvasVectorOutput(canvas_ID))
VectorFont(FontID(font_ID))
For i=1 To 25
  VectorSourceColor($FF000000|#Red)
   AddPathBox(0, ii, 500, 1)
   ; AddPathBox(0, ii+i, 500, 1) ; Workaround, but still shifts, with DPI aware and high scaling not usable - The correction must be approx. 1 pixel every three lines.
  ii+VectorTextHeight("X")
  StrokePath(1)
  VectorSourceColor($FF000000|#Black)
  DrawVectorParagraph(text$, WindowWidth(window_ID), WindowHeight(window_ID))  
Next i
StopVectorDrawing() 

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
地球上の平和
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: AddPathBox Bug PB573

Post by netmaestro »

You're using integers where doubles are required. This makes sense to me:

Code: Select all

EnableExplicit
Define.i window_ID, canvas_ID, font_ID, j
Define.s text$
Define.d text_height, text_width, box_height, box_width, box_x, box_y, this_y, box_delta_y, padding
window_ID=OpenWindow(#PB_Any, 0, 0, 600, 650, "", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
canvas_ID=CanvasGadget(#PB_Any, 0, 0, WindowWidth(window_ID), WindowHeight(window_ID))

font_ID=LoadFont(#PB_Any, "", 16)

text$=""
For j=1 To 25
  text$+LSet ("X", 30 ,"X")
Next

box_x = 20
box_y = 20
padding = 0.7

StartVectorDrawing(CanvasVectorOutput(canvas_ID))
  VectorFont(FontID(font_ID))
  text_height = VectorTextHeight("X")
  text_width = VectorTextWidth("X")
  box_height = 1.0
  box_width = text_width*30
  box_delta_y = text_height+padding
  
  For j=0 To 24
    this_y=box_y+j*box_delta_y-box_height
    AddPathBox(box_x, this_y, box_width, box_height)
    VectorSourceColor($FF000000|#Red)
    StrokePath(1)
  Next
  
  MovePathCursor(box_x, box_y)
  VectorSourceColor($FF000000|#Black)
  DrawVectorParagraph(text$, box_width, text_height*25+text_height)
StopVectorDrawing() 

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Last edited by netmaestro on Mon Apr 19, 2021 6:51 pm, edited 1 time in total.
BERESHEIT
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: AddPathBox Bug PB573

Post by Saki »

Thanks netmaestro, but that makes no difference here.
The thing is based on GDI+.
Therefore, you can't compare it directly with Mac and Linux.
But it would be good if it was feasible, because the effects are hard to see through.
So from the feeling I would assume that in the implementation is somewhere an integer where a double should go.
地球上の平和
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: AddPathBox Bug PB573

Post by netmaestro »

It makes no difference there because you've overlooked some other necessary details. See my post above for code.
BERESHEIT
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: AddPathBox Bug PB573

Post by STARGÅTE »

Dear Saki.
There is no bug in AddPathBox()

You can not use VectorTextHeight() you measure the line height of one line in DrawVectorParagraph().
In case of DrawVectorParagraph() you have to use VectorParagraphHeight(), because a different render engine is used in DrawVectorText() and DrawVectorParagraph():
And of cause, you have to use doubles.

Code: Select all

window_ID=OpenWindow(#PB_Any, 0, 0, 600, 650, "", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
canvas_ID=CanvasGadget(#PB_Any, 0, 0, WindowWidth(window_ID), WindowHeight(window_ID))

font_ID=LoadFont(#PB_Any, "", 15+Bool(#PB_Compiler_OS=#PB_OS_Windows)) ; For better compare with Linux - Mac not adapted here

For i=1 To 25 : text$+LSet ("X", 30 ,"X") +#LF$ : Next i

StartVectorDrawing(CanvasVectorOutput(canvas_ID))
VectorFont(FontID(font_ID))
Define ii.d
For i=1 To 25
  VectorSourceColor($FF000000|#Red)
   AddPathBox(0, ii, 500, 1)
   ; AddPathBox(0, ii+i, 500, 1) ; Workaround, but still shifts, with DPI aware and high scaling not usable - The correction must be approx. 1 pixel every three lines.
  ii+VectorParagraphHeight(text$, WindowWidth(window_ID), WindowHeight(window_ID))/CountString(text$, #LF$)
  StrokePath(1)
  VectorSourceColor($FF000000|#Black)
  DrawVectorParagraph(text$, WindowWidth(window_ID), WindowHeight(window_ID))  
Next i
StopVectorDrawing() 

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: AddPathBox Bug PB573

Post by netmaestro »

@STARGATE: I didn't use VectorParagraphHeight, I used the padding instead. Your implementation is better, thanks for the lesson!
BERESHEIT
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: AddPathBox Bug PB573

Post by Saki »

Hi, many thanks both.
I am still pondering.
@netmaestro
Your example works well.
If you multiply the 0.7 with DesktopResolutionY() it works also with high scales and DPI aware.
@STARGATE
Yes, you're certainly right, those are details, once you get your teeth into it it's hard to see a mistake.
I have to think this through in peace.

On Linux and Mac these problems do not exist,
VectorTextHeight()*25 and VectorParagraphHeight()*25 are equal, what you should actually expect.
I am not sure whether to consider it a bug or a peculiarity of WinOS.

Best regards Saki
地球上の平和
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: AddPathBox Bug PB573

Post by STARGÅTE »

Saki wrote: Mon Apr 19, 2021 7:43 pmOn Linux and Mac these problems do not exist,
VectorTextHeight()*25 and VectorParagraphHeight()*25 are equal, what you should actually expect.
I am not sure whether to consider it a bug or a peculiarity of WinOS.
I know what you mean. And I agree.
I have similar problems with DrawVectorText(), AddPathText() and DrawVectorParagraph() in combination with VectorTextWidth() here. It is also for me difficult to say, if it is a bug or a OS specific "feature".
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Post Reply