It is currently Wed May 22, 2013 2:24 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Possible bug, Rotated text changes sizes (width)
PostPosted: Sun Feb 07, 2010 8:44 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 2399
Location: Utah, USA
In doing some experiments with the DrawRotatedText() function I ran across a bug.

The bug results in the wrong size for rotated text, that is the text size increases for some reason, at least in width.

I wanted to post it in the coding forum first to make sure I wasn't overlooking something that would be causing this effect.


The code below draws non-rotated text and place a box around it using the dimensions returned from TextWidth() and TextHeight(). It's width is 92 pixels.
Rotated text is drawn using an angle of zero, it's width matches the previously drawn text, being 92 pixels.
Rotated text is then drawn using an angle of 0.2 . It's width mysteriously increases by 6 pixels, become 98 pixels. It also shifts down by 2 pixels.

It would seem the shifting doesn't relate to the rotation amount because it should keep the upper-left pixel in the same position or one that is slightly higher. The length change is likewise peculiar.

Code:
Define sizeX = 110, sizeY = 40

If OpenWindow(0, 0, 0, sizeX, sizeY, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateImage(0, sizeX, sizeY) And StartDrawing(ImageOutput(0))
      Box(0, 0, sizeX, sizeY, RGB(255, 255, 255))
     
      Define text.s="X>>>  O  >>>X"
     
      Define tx = TextWidth(text)
      Define ty = TextHeight(text)
     
      ;draw standard text
      DrawText(5,5,text)
      ;outline text with box to highlight dimensions (again)
      DrawingMode(#PB_2DDrawing_Outlined)
      Box(5,5,tx,ty,$FFFF00)
 
      ;draw rotated text with no rotation
      DrawRotatedText(5, 5 + ty, text, 0, #Black)
      ;draw rotated text using a very small angle
      DrawRotatedText(5, 5 + ty, text, 0.2, #Magenta) ; <== text has become wider?
    StopDrawing()
    ImageGadget(0, 0, 0, sizeX, sizeY, ImageID(0))
  EndIf
 
  Define event
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow
EndIf

_________________
Image


Top
 Profile  
 
 Post subject: Re: Possible bug, Rotated text changes sizes (width)
PostPosted: Sun Feb 07, 2010 9:06 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Aug 15, 2009 6:59 pm
Posts: 1024
Isn't that just normal, that if you rotate something it's bounding box becomes bigger?


Top
 Profile  
 
 Post subject: Re: Possible bug, Rotated text changes sizes (width)
PostPosted: Sun Feb 07, 2010 9:39 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5188
Location: Germany
Rotating only works with TrueType fonts on Windows. If your font isn't a TrueType font then the command will try to load one that matches as close as possible. This is where the difference comes from.

_________________
Perl – The only language that looks the same before and after RSA encryption.
-- Keith Bostic


Top
 Profile  
 
 Post subject: Re: Possible bug, Rotated text changes sizes (width)
PostPosted: Mon Feb 08, 2010 2:40 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 2399
Location: Utah, USA
freak wrote:
Rotating only works with TrueType fonts on Windows. If your font isn't a TrueType font then the command will try to load one that matches as close as possible. This is where the difference comes from.


That's helpful to know. So I should make sure I use a TrueType font so everything should work better.

Below is the same code from above with one major change. It loads and uses the "Courier New" TrueType font. Now the rotated text (by 0.2 degrees) is drawn skinnier by 3 pixels and is drawn lower on the screen by 4 pixels. I'm confused, I thought using a Truetype would fix it but it just went off in another direction. Does anyone have a TrueType font that can be used with the code below so that the rotated version does not have it's width shrunk or expanded and won't draw the text below it's anchor point (the top left)?

Any insight would be appreciated.

Code:
Define sizeX = 110, sizeY = 40, px = 2, py = 2

If Not LoadFont(0,"Courier New",10,#PB_Font_Bold): End: EndIf

If OpenWindow(0, 0, 0, sizeX, sizeY, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateImage(0, sizeX, sizeY) And StartDrawing(ImageOutput(0))
      Box(0, 0, sizeX, sizeY, RGB(255, 255, 255))
      DrawingFont(FontID(0))  ;use TrueType font   
      Define text.s="X>>>  O  >>>X"
     
      Define tx = TextWidth(text)
      Define ty = TextHeight(text)

      ;draw standard text
      DrawText(px,py,text)
      ;outline text with box to highlight dimensions (again)
      DrawingMode(#PB_2DDrawing_Outlined)
      Box(px, py, tx, ty, $FFFF00)
 
      ;draw rotated text with no rotation
      DrawRotatedText(px, py + ty, text, 0, #Black)
      ;draw rotated text using a very small angle
      DrawRotatedText(px, py + ty, text, -0.2, #Magenta) ; <== text has become skinnier?
    StopDrawing()
    ImageGadget(0, 0, 0, sizeX, sizeY, ImageID(0))
  EndIf
 
  Define event
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow
EndIf


Thorium wrote:
Isn't that just normal, that if you rotate something it's bounding box becomes bigger?

That is true. That is why I used the smallest rotation that would cause a change in the font rendering, 0.2 degrees. I think the change in the bounding box size should be negligible.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Possible bug, Rotated text changes sizes (width)
PostPosted: Tue Jul 10, 2012 8:20 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 1383
Location: Boston, MA
I think Consolas works on Windows 7, but isn't native to XP.
Code:
;If Not LoadFont(0,"Consolas",10,#PB_Font_Bold): End: EndIf
If Not LoadFont(0,"Consolas",10,#PB_Font_HighQuality): End: EndIf

_________________
To understand recursion, you must first understand recursion. ~ unknown
I never make stupid mistakes. Only very, very clever ones. ~ John Peel


Top
 Profile  
 
 Post subject: Re: Possible bug, Rotated text changes sizes (width)
PostPosted: Wed Jul 11, 2012 6:42 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 1290
Demivec wrote:
Any insight would be appreciated.

Code:
Define sizeX = 110, sizeY = 40, px = 2, py = 2

If Not LoadFont(0,"Courier New",10,#PB_Font_Bold): End: EndIf

If OpenWindow(0, 0, 0, sizeX, sizeY, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateImage(0, sizeX, sizeY) And StartDrawing(ImageOutput(0))
      Box(0, 0, sizeX, sizeY, RGB(255, 255, 255))
      DrawingFont(FontID(0))  ;use TrueType font   
      Define text.s="X>>>  O  >>>X"
     
      Define tx = TextWidth(text)
      Define ty = TextHeight(text)

      ;draw standard text
      DrawText(px,py,text)
      ;outline text with box to highlight dimensions (again)
      DrawingMode(#PB_2DDrawing_Outlined)
      Box(px, py, tx, ty, $FFFF00)
 
      ;draw rotated text with no rotation
      DrawRotatedText(px, py + ty, text, 0, #Black)
      ;draw rotated text using a very small angle
      DrawRotatedText(px, py + ty, text, -0.2, #Magenta) ; <== text has become skinnier?
    StopDrawing()
    ImageGadget(0, 0, 0, sizeX, sizeY, ImageID(0))
  EndIf
 
  Define event
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow
EndIf

You are right, it happens with flag #PB_Font_Bold. Other flags like Italic and Strikeout work correctly.

Works with gDrawing (GDI+):
Code:
XIncludeFile "gDrawing.pbi"

Define sizeX = 510, sizeY = 140, px = 2, py = 2

;If Not LoadFont(0,"Courier New",10,#PB_Font_Bold): End: EndIf

;If Not LoadFont(0,"Consolas",10,#PB_Font_Bold): End: EndIf
;If Not LoadFont(0,"Consolas",10,#PB_Font_HighQuality): End: EndIf
gInit()
If OpenWindow(0, 0, 0, sizeX, sizeY, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateImage(0, sizeX, sizeY) And gStartDrawing(ImageOutput(0))
      gBox(0, 0, sizeX, sizeY, RGBA(255, 255, 255,255))
      gSetFont("Courier New",40,#PB_Font_Bold)  ;use TrueType font
      Define text.s="X>>>  O  >>>X"
     
      Define tx = gTextWidth(text)
      Define ty = gTextHeight(text)

      ;draw standard text
      gDrawText(px,py,text,RGBA(0,0,0,255))
      ;outline text with box to highlight dimensions (again)
      gDrawingMode(#PB_2DDrawing_Outlined)
      gBox(px, py, tx, ty, $FFFFFF00)
      gDrawingMode(#PB_2DDrawing_Default)
 
      ;draw rotated text with no rotation
      gDrawRotatedText(px, py + ty, text, 0, #Black|$FF000000)
      ;draw rotated text using a very small angle
      gDrawRotatedText(px, py + ty, text, 0.5, #Magenta|$FF000000) ; <== text has become skinnier?
    gStopDrawing()
    ImageGadget(0, 0, 0, sizeX, sizeY, ImageID(0))
  EndIf
 
  Define event
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow
EndIf


Top
 Profile  
 
 Post subject: Re: Possible bug, Rotated text changes sizes (width)
PostPosted: Wed Jul 11, 2012 12:29 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 1290
Try with bigger font on Windows:
Code:
Define sizeX = 1810, sizeY = 440, px = 2, py = 2

If Not LoadFont(0,"Courier New",110): End: EndIf
;If Not LoadFont(0,"Consolas",110): End: EndIf

If OpenWindow(0, 0, 0, sizeX, sizeY, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateImage(0, sizeX, sizeY) And StartDrawing(ImageOutput(0))
      Box(0, 0, sizeX, sizeY, RGB(255, 255, 255))
      DrawingFont(FontID(0))  ;use TrueType font   
      Define text.s="X>>>  O  >>>X"
     
      Define tx = TextWidth(text)
      Define ty = TextHeight(text)

      ;draw standard text
      ;DrawingMode(#PB_2DDrawing_Transparent)
      DrawText(px,py,text)
      ;outline text with box to highlight dimensions (again)
      DrawingMode(#PB_2DDrawing_Outlined)
      Box(px, py, tx, ty, $FFFF00)
 
      ;draw rotated text with no rotation
      DrawRotatedText(px, py + ty, text, 0, #Black)
      ;draw rotated text using a very small angle
      DrawRotatedText(px, py + ty, text, -0.2, #Magenta) ; <== text has become skinnier?
    StopDrawing()
    ImageGadget(0, 0, 0, sizeX, sizeY, ImageID(0))
  EndIf
 
  Define event
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow
EndIf

No #PB_Font_Bold flag.
-0.2 degree rotation only and it shows big offset in y-coordinate.
Maybe rotation origin is at -500,0?
Looks wrong, like another bug.


Top
 Profile  
 
 Post subject: Re: Possible bug, Rotated text changes sizes (width)
PostPosted: Wed Jul 11, 2012 1:00 pm 
Offline
User
User

Joined: Thu Jan 05, 2012 12:27 am
Posts: 45
Danilo wrote:
-0.2 degree rotation only and it shows big offset in y-coordinate.
Maybe rotation origin is at -500,0?
Looks wrong, like another bug.


The problem is seen here already when using 0.1 (independent if +0.1° or -0.1°, rotation angles between -0.099999 and +0.099999 will work because they get rounded to 0.0)


Top
 Profile  
 
 Post subject: Re: Possible bug, Rotated text changes sizes (width)
PostPosted: Fri Jul 13, 2012 11:29 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 1290
Danilo wrote:
Try with bigger font on Windows:
Code:
Define sizeX = 1810, sizeY = 440, px = 2, py = 2

If Not LoadFont(0,"Courier New",110): End: EndIf
;If Not LoadFont(0,"Consolas",110): End: EndIf

If OpenWindow(0, 0, 0, sizeX, sizeY, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateImage(0, sizeX, sizeY) And StartDrawing(ImageOutput(0))
      Box(0, 0, sizeX, sizeY, RGB(255, 255, 255))
      DrawingFont(FontID(0))  ;use TrueType font   
      Define text.s="X>>>  O  >>>X"
     
      Define tx = TextWidth(text)
      Define ty = TextHeight(text)

      ;draw standard text
      ;DrawingMode(#PB_2DDrawing_Transparent)
      DrawText(px,py,text)
      ;outline text with box to highlight dimensions (again)
      DrawingMode(#PB_2DDrawing_Outlined)
      Box(px, py, tx, ty, $FFFF00)
 
      ;draw rotated text with no rotation
      DrawRotatedText(px, py + ty, text, 0, #Black)
      ;draw rotated text using a very small angle
      DrawRotatedText(px, py + ty, text, -0.2, #Magenta) ; <== text has become skinnier?
    StopDrawing()
    ImageGadget(0, 0, 0, sizeX, sizeY, ImageID(0))
  EndIf
 
  Define event
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow
EndIf

No #PB_Font_Bold flag.
-0.2 degree rotation only and it shows big offset in y-coordinate.
Maybe rotation origin is at -500,0?
Looks wrong, like another bug.

What do you think, freak?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Exabot [Bot], Joris and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye