Draw w/max font size in rectangle using DrawVectorText("12")

Just starting out? Need help? Post your questions and find answers here.
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Draw w/max font size in rectangle using DrawVectorText("12")

Post by skywalk »

What is the best approach here?
Should I Loop VectorFont() size until some bounding box is crossed?
Has anyone tried this with the Vector lib?
I need a small single line text within a horizontal rectangle and a rotated -90° rectangle.

Code: Select all

Macro Min(x, y)
  (Bool((x) <= (y)) * (x) + Bool((y) < (x)) * (y))
EndMacro
Define.s r$ = "1234"
Define.d rWd, rHt, rX, rY
Define.d tWd, tHt, tX, tY
If OpenWindow(0, 0, 0, 400, 250, "DrawVectorText() in a box?", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 0, 400, 250)
  LoadFont(0, "Segoe UI", 8, #PB_Font_Bold)
  If StartVectorDrawing(CanvasVectorOutput(0))
    ;/////////////////////////////////////////////////////
    ; Horizontal Rectangle
    ;/////////////////////////////////////////////////////
    rWd = 100
    rHt = 30
    AddPathBox(5, 5, rWd, rHt)     ; Horizontal Rectangle
    VectorSourceColor(RGBA(255, 0, 0, 255))
    StrokePath(1)
    
    VectorFont(FontID(0));, 20) ;<-- Loop VectorFont() size until some bounding box is crossed?
    tHt = VectorTextHeight(r$, #PB_VectorText_Visible)
    tWd = VectorTextWidth(r$, #PB_VectorText_Visible)
    MovePathCursor(5 + 100/2, 5 + 30/2)
    DrawVectorText(r$)
    ;DrawVectorParagraph(r$, 100, 30);, #PB_VectorParagraph_Center)
    
    ;/////////////////////////////////////////////////////
    ; Rectangle Rotated ±90°, Text Wd & Ht swapped.
    ;/////////////////////////////////////////////////////
    rWd = 30
    rHt = 100
    AddPathBox(150, 5, rWd, rHt)     ; Horizontal Rectangle
    VectorSourceColor(RGBA(255, 0, 0, 255))
    StrokePath(1)
    
    VectorFont(FontID(0));, 20)
    tWd = VectorTextHeight(r$, #PB_VectorText_Visible)
    tHt = VectorTextWidth(r$, #PB_VectorText_Visible)
    MovePathCursor(150 + rwd/2, 5 + rht/2)
    RotateCoordinates(PathCursorX(), PathCursorY(), -90)
    ;Debug "Rotated: " + StrD(PathCursorX()) + ", " + StrD(PathCursorY())
    DrawVectorText(r$)
    StrokePath(1, #PB_Path_SquareEnd)
    ResetCoordinates()
    
    StopVectorDrawing()
  EndIf
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
Last edited by skywalk on Tue Jan 09, 2018 9:59 pm, edited 1 time in total.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Fill entire drawn rectangle with DrawVectorText("1234")?

Post by davido »

@skywalk,
Would this rather crude example help?

Code: Select all

If OpenWindow(0, 0, 0, 400, 300, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 400, 300)
    LoadFont(0, "Arial", 20)
    
    If StartVectorDrawing(CanvasVectorOutput(0,#PB_Unit_Point))
      For i = 1 To 2
      VectorFont(FontID(0), 25 * i)

      AddPathBox(100,50 * i,200,20 * i)
      StrokePath(1)
      VectorSourceColor(RGBA(0, 0, 0, 200))
      Text$ = "The quick brown fox jumped over the lazy doc"
      
      MovePathCursor(100,50 * i)
      DrawVectorText(Text$)
Next i

      StopVectorDrawing()
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
DE AA EB
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Fill entire drawn rectangle with DrawVectorText("1234")?

Post by skywalk »

Thanks davido, I got a little further, and now fixed the rotated rectangle text.

Code: Select all

EnableExplicit
Procedure.i fntv_SizeFitRect(txt$, hFnt.i, Rwd.d, Rht.d)
  ; USE:    Loop through VectorFont sizes until exceed Rectangle.
  ;         Must be called from within a StartVectorDrawing() block.
  ; RETURN: Font Size of current VectorFont(), which is left in play.
  ;         i > 0 = no rotation. i < 0 = rotated.
  Protected.i i
  If txt$
    Rwd - 4
    Rht - 4
    If Rwd > Rht
      For i = 1 To 100
        VectorFont(hFnt, i)
        If ((VectorTextWidth(txt$) > rwd) Or (VectorTextHeight(txt$) > rht))
          Break
        EndIf
      Next i
    Else
      For i = 1 To 100
        VectorFont(hFnt, i)
        If ((VectorTextWidth(txt$) > rht) Or (VectorTextHeight(txt$) > rwd))
          i * -1
          Break
        EndIf
      Next i
    EndIf
  EndIf
  ProcedureReturn i
EndProcedure
Procedure Main()
  Protected.s s$ = "1234"
  Protected.d rWd, rHt, rX, rY
  Protected.d tWd, tHt, tX, tY
  Protected.i evWW, hFnt, txSize
  If OpenWindow(0, 0, 0, 400, 250, "DrawVectorText() in a box?", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 400, 250)
    LoadFont(0, "Segoe UI", 8, #PB_Font_Bold)
    hFnt = FontID(0)
    If StartVectorDrawing(CanvasVectorOutput(0))
      ;/////////////////////////////////////////////////////
      ; Horizontal Rectangle
      ;/////////////////////////////////////////////////////
      rWd = 90  ;<-- Change this and the rotated text moves away from center?
      rHt = 30
      AddPathBox(5, 5, rWd, rHt)     ; 0° Rectangle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(1)
      txSize = fntv_SizeFitRect(s$, hFnt, rwd, rht)
      tHt = VectorTextHeight(s$)
      tWd = VectorTextWidth(s$)
      MovePathCursor(5+rwd/2-twd/2, 5+rht/2-tht/2)
      DrawVectorText(s$)
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, Text Wd & Ht swapped.
      ;/////////////////////////////////////////////////////
      rWd = 30  ;<-- Change this and the rotated text moves away from center?
      rHt = 90
      AddPathBox(150, 5, rWd, rHt)   ; Orig Rectangle rotated -90°
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(1)
      txSize = fntv_SizeFitRect(s$, hFnt, rWd, rHt)
      If txSize > 0
        twd = VectorTextWidth(s$)
        tht = VectorTextHeight(s$)
      Else
        tht = VectorTextWidth(s$)
        twd = VectorTextHeight(s$)
      EndIf
      MovePathCursor(150+rwd/2-twd/2, 5+rht/2+tht/2)
      RotateCoordinates(PathCursorX(), PathCursorY(), -90)
      DrawVectorText(s$)
      ResetCoordinates()
      StopVectorDrawing()
    EndIf
    Repeat
      evWW = WaitWindowEvent()
    Until evWW = #PB_Event_CloseWindow
  EndIf
EndProcedure
Main()
EDIT: This works for horizontal and -90° text in a rectangle.
Last edited by skywalk on Tue Jan 09, 2018 10:30 pm, edited 3 times in total.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Draw w/max font size in rectangle using DrawVectorText("

Post by davido »

@skywalk,

Could it be done something like this, perhaps:

Code: Select all

EnableExplicit
Procedure.i fntv_SizeFitRect(txt$, hFnt.i, Rwd.d, Rht.d)
  ; USE:  Loop through VectorFont sizes until exceed Rectangle.
  ;       Must be called from within a StartVectorDrawing() block.
  ; RETURN: Font Size of current VectorFont(), which is left in play.
  Protected.i i
  If txt$
    Rwd - 4
    Rht - 4
    For i = 1 To 100
      VectorFont(hFnt, i)
      If ((VectorTextWidth(txt$) > rwd) Or (VectorTextHeight(txt$) > rht))
        Break
      EndIf
    Next i
  EndIf
  ProcedureReturn i
EndProcedure
Procedure Main()
  Protected.s s$ = "1234"
  Protected.d rWd, rHt, rX, rY
  Protected.d tWd, tHt, tX, tY
  Protected.i evWW, hFnt, txSize
  If OpenWindow(0, 0, 0, 400, 250, "DrawVectorText() in a box?", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 400, 250)
    LoadFont(0, "Segoe UI", 8, #PB_Font_Bold)
    hFnt = FontID(0)
    If StartVectorDrawing(CanvasVectorOutput(0))
      ;/////////////////////////////////////////////////////
      ; Horizontal Rectangle
      ;/////////////////////////////////////////////////////
      rWd = 90  ;<-- Change this and the rotated text moves away from center?
      rHt = 30
      AddPathBox(5, 5, rWd, rHt)     ; 0° Rectangle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(1)
      txSize = fntv_SizeFitRect(s$, hFnt, rwd, rht)
      tHt = VectorTextHeight(s$, #PB_VectorText_Visible)
      tWd = VectorTextWidth(s$, #PB_VectorText_Visible)
      MovePathCursor(5+rwd/2-twd/2, 5+rht/2-tht)
      DrawVectorText(s$)
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, Text Wd & Ht swapped.
      ;/////////////////////////////////////////////////////
       RotateCoordinates(PathCursorX(), PathCursorY(), -90)
      AddPathBox(-5, 35, rWd, rHt)     ; 0° Rectangle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(1)
      txSize = fntv_SizeFitRect(s$, hFnt, rwd, rht)
      tHt = VectorTextHeight(s$, #PB_VectorText_Visible)
      tWd = VectorTextWidth(s$, #PB_VectorText_Visible)
      MovePathCursor(-5+rwd/2-twd/2, 35+rht/2-tht)
      
     

      
      DrawVectorText(s$)
      ResetCoordinates()
      StopVectorDrawing()
    EndIf
    Repeat
      evWW = WaitWindowEvent()
    Until evWW = #PB_Event_CloseWindow
  EndIf
EndProcedure
Main()
Just a thought but

Code: Select all

TranslateCoordinates(x.d, y.d [, System])
might lower the rotated box.
DE AA EB
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Draw w/max font size in rectangle using DrawVectorText("

Post by davido »

@skwalk,
The following works at 45 degrees, etc.

Code: Select all

EnableExplicit
Procedure.i fntv_SizeFitRect(txt$, hFnt.i, Rwd.d, Rht.d)
  ; USE:  Loop through VectorFont sizes until exceed Rectangle.
  ;       Must be called from within a StartVectorDrawing() block.
  ; RETURN: Font Size of current VectorFont(), which is left in play.
  Protected.i i
  If txt$
    Rwd - 4
    Rht - 4
    For i = 1 To 100
      VectorFont(hFnt, i)
      If ((VectorTextWidth(txt$) > rwd) Or (VectorTextHeight(txt$) > rht))
        Break
      EndIf
    Next i
  EndIf
  ProcedureReturn i
EndProcedure
Procedure Main()
  Protected.s s$ = "1234"
  Protected.d rWd, rHt, rX, rY
  Protected.d tWd, tHt, tX, tY
  Protected.i evWW, hFnt, txSize
  If OpenWindow(0, 0, 0, 400, 250, "DrawVectorText() in a box?", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 400, 250)
    LoadFont(0, "Segoe UI", 8, #PB_Font_Bold)
    hFnt = FontID(0)
    If StartVectorDrawing(CanvasVectorOutput(0))
      ;/////////////////////////////////////////////////////
      ; Horizontal Rectangle
      ;/////////////////////////////////////////////////////
      rWd = 90  ;<-- Change this and the rotated text moves away from center?
      rHt = 30
      AddPathBox(5, 5, rWd, rHt)     ; 0° Rectangle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(1)
      txSize = fntv_SizeFitRect(s$, hFnt, rwd, rht)
      tHt = VectorTextHeight(s$, #PB_VectorText_Visible)
      tWd = VectorTextWidth(s$, #PB_VectorText_Visible)
      MovePathCursor(5+rwd/2-twd/2, 5+rht/2-tht)
      DrawVectorText(s$)
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, Text Wd & Ht swapped.
      ;/////////////////////////////////////////////////////
      RotateCoordinates(PathCursorX(), PathCursorY(), -45)
      TranslateCoordinates(30,30)
      AddPathBox(-5, 35, rWd, rHt)     ; 0° Rectangle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(1)
      txSize = fntv_SizeFitRect(s$, hFnt, rwd, rht)
      tHt = VectorTextHeight(s$, #PB_VectorText_Visible)
      tWd = VectorTextWidth(s$, #PB_VectorText_Visible)
      MovePathCursor(-5+rwd/2-twd/2, 35+rht/2-tht)
      
     

      
      DrawVectorText(s$)
      ResetCoordinates()
      StopVectorDrawing()
    EndIf
    Repeat
      evWW = WaitWindowEvent()
    Until evWW = #PB_Event_CloseWindow
  EndIf
EndProcedure
Main()
DE AA EB
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Draw w/max font size in rectangle using DrawVectorText("

Post by skywalk »

Thanks davido, it was the #PB_VectorText_Visible flag that was messing me up.
I modified my last code post with the fixes.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Draw w/max font size in rectangle using DrawVectorText("

Post by skywalk »

How to shrink the paragraph spacing in the blue box?
And, why is the blue box's outline thinner than the red and green box?

Code: Select all

EnableExplicit
Procedure.i fntv_SizeFitRect(txt$, hFnt.i, RectWd.d, RectHt.d)
  ; USE:    Loop through VectorFont sizes until exceed Rectangle.
  ;         Must be called from within a StartVectorDrawing() block.
  ; RETURN: Font Size of current VectorFont(), which is left in play.
  ;         i > 0 = no rotation. i < 0 = rotated.
  Protected.i i
  If txt$
    RectWd - 0
    RectHt - 0
    If RectWd > RectHt
      For i = 1 To 100
        VectorFont(hFnt, i)
        If ((VectorTextWidth(txt$) > RectWd) Or (VectorTextHeight(txt$) > RectHt))
          i - 1
          Break
        EndIf
      Next i
    Else
      For i = 1 To 100
        VectorFont(hFnt, i)
        If ((VectorTextWidth(txt$) > RectHt) Or (VectorTextHeight(txt$) > RectWd))
          i = -1 * (i + 2)
          Break
        EndIf
      Next i
    EndIf
  EndIf
  ProcedureReturn i
EndProcedure
Procedure Main()
  Protected.s s$ = "1234"
  Protected.d rWd, rHt, rX, rY
  Protected.d tWd, tHt, tX, tY
  Protected.i evWW, hFnt, txSize
  If OpenWindow(0, 0, 0, 300, 300, "DrawVectorText() in a box?", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 300, 300)
    LoadFont(0, "Segoe UI", 8, #PB_Font_Bold)
    hFnt = FontID(0)
    If StartVectorDrawing(CanvasVectorOutput(0))
      ;/////////////////////////////////////////////////////
      ; Horizontal Rectangle
      ;/////////////////////////////////////////////////////
      rWd = 140
      rHt = 30
      AddPathBox(5, 5, rWd, rHt)     ; 0° Rectangle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(1)
      ;StrokePath(1)
      txSize = fntv_SizeFitRect(s$, hFnt, rwd, rht)
      tHt = VectorTextHeight(s$)
      tWd = VectorTextWidth(s$)
      MovePathCursor(5+rwd/2-twd/2, 5+rht/2-tht/2)
      DrawVectorText(s$)
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, Text Wd & Ht swapped.
      ;/////////////////////////////////////////////////////
      rWd = 30
      rHt = 140
      AddPathBox(150, 5, rWd, rHt)   ; Orig Rectangle rotated -90°
      VectorSourceColor(RGBA(0, 255, 0, 255))
      StrokePath(1)
      txSize = fntv_SizeFitRect(s$, hFnt, rWd, rHt)
      If txSize > 0
        twd = VectorTextWidth(s$)
        tht = VectorTextHeight(s$)
      Else
        tht = VectorTextWidth(s$)
        twd = VectorTextHeight(s$)
      EndIf
      MovePathCursor(150+rwd/2-twd/2, 5+rht/2+tht/2)
      RotateCoordinates(PathCursorX(), PathCursorY(), -90)
      DrawVectorText(s$)
      ResetCoordinates()
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, But text drawn as topdown paragraph.
      ;/////////////////////////////////////////////////////
      rWd = 30
      rHt = 140
      AddPathBox(5, 40, rWd, rHt)   ; Orig Rectangle rotated -90°
      VectorSourceColor(RGBA(0, 0, 255, 255))
      StrokePath(1)
      txSize = fntv_SizeFitRect(s$, hFnt, rWd, rHt)
      If txSize > 0
        twd = VectorTextWidth(s$)
        tht = VectorTextHeight(s$)
      Else
        ; Try paragraph text
        s$ = "1" + #LF$ + "2" + #LF$ + "3" + #LF$ + "4"
        twd = VectorTextWidth(s$)
        tht = VectorTextHeight(s$)
      EndIf
      MovePathCursor(5+rwd/2-twd/2, 40+rht/2-tht/2)
      DrawVectorParagraph(s$, 30, 140, #PB_VectorParagraph_Center)
      StopVectorDrawing()
    EndIf
    Repeat
      evWW = WaitWindowEvent()
    Until evWW = #PB_Event_CloseWindow
  EndIf
EndProcedure
Main()
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Draw w/max font size in rectangle using DrawVectorText("

Post by srod »

As far as I can tell, up to the point where ResetCoordinates() is used, the stroke width seems to be interpreted in 'point' units as opposed to pixels which must be a bug.

A workaround is to place a ResetCoordinates() call just after the StartDrawing().

I'd report this.
I may look like a mule, but I'm not a complete ass.
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Draw w/max font size in rectangle using DrawVectorText("

Post by skywalk »

Thanks, this action causes visual problems with my rendered graphics in my full app. I'll post as bug.
I don't see a way to have rotate coordinates earlier in the flow?

EDIT: I can limit the damage by isolating RotateCoordinates() to its own StartVectorDrawing()..StopVectorDrawing() session.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Draw w/max font size in rectangle using DrawVectorText("

Post by skywalk »

Code: Select all

EnableExplicit
Procedure Bug()
  Protected.s s$ = "1234"
  Protected.d rWd, rHt, rX, rY
  Protected.d tWd, tHt, tX, tY
  Protected.i evWW, hFnt, txSize
  If OpenWindow(0, 0, 0, 300, 300, "Rotate Coordinates Bug?", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 300, 300)
    LoadFont(0, "Segoe UI", 8, #PB_Font_Bold)
    hFnt = FontID(0)
    If StartVectorDrawing(CanvasVectorOutput(0))
      ;/////////////////////////////////////////////////////
      ; Horizontal Rectangle
      ;/////////////////////////////////////////////////////
      rWd = 140
      rHt = 30
      AddPathBox(5, 5, rWd, rHt)     ; 0° Rectangle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(1)
      txSize = 30
      VectorFont(hFnt, txSize)
      tHt = VectorTextHeight(s$)
      tWd = VectorTextWidth(s$)
      MovePathCursor(5+rwd/2-twd/2, 5+rht/2-tht/2)
      DrawVectorText(s$)
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, Text Wd & Ht swapped.
      ;/////////////////////////////////////////////////////
      rWd = 30
      rHt = 140
      AddPathBox(150, 5, rWd, rHt)   ; Orig Rectangle rotated -90°
      VectorSourceColor(RGBA(0, 255, 0, 255))
      StrokePath(1)
      tht = VectorTextWidth(s$)
      twd = VectorTextHeight(s$)
      MovePathCursor(150+rwd/2-twd/2, 5+rht/2+tht/2)
      RotateCoordinates(PathCursorX(), PathCursorY(), -90)
      DrawVectorText(s$)
      ResetCoordinates()
    ;NOBUG;;  StopVectorDrawing()
    ;NOBUG;;EndIf
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, But text drawn as topdown paragraph.
      ;/////////////////////////////////////////////////////
    ;NOBUG;;If StartVectorDrawing(CanvasVectorOutput(0))
      rWd = 30
      rHt = 140
      AddPathBox(5, 40, rWd, rHt)   ; Orig Rectangle rotated -90°
      VectorSourceColor(RGBA(0, 0, 255, 255))
      StrokePath(1)
      ; Try paragraph text
      VectorFont(hFnt, txSize-6)
      s$ = "1" + #LF$ + "2" + #LF$ + "3" + #LF$ + "4"
      twd = VectorTextWidth(s$)
      tht = VectorTextHeight(s$)
      MovePathCursor(5+rwd/2-twd/2, 40+rht/2-tht/2)
      DrawVectorParagraph(s$, 30, 140, #PB_VectorParagraph_Center)
      StopVectorDrawing()
    EndIf
    Repeat
      evWW = WaitWindowEvent()
    Until evWW = #PB_Event_CloseWindow
  EndIf
EndProcedure
Procedure NoBug()
  Protected.s s$ = "1234"
  Protected.d rWd, rHt, rX, rY
  Protected.d tWd, tHt, tX, tY
  Protected.i evWW, hFnt, txSize
  If OpenWindow(0, 0, 0, 300, 300, "Rotate Coordinates Issue?", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 300, 300)
    LoadFont(0, "Segoe UI", 8, #PB_Font_Bold)
    hFnt = FontID(0)
    If StartVectorDrawing(CanvasVectorOutput(0))
      ;/////////////////////////////////////////////////////
      ; Horizontal Rectangle
      ;/////////////////////////////////////////////////////
      rWd = 140
      rHt = 30
      AddPathBox(5, 5, rWd, rHt)     ; 0° Rectangle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(1)
      txSize = 30
      VectorFont(hFnt, txSize)
      tHt = VectorTextHeight(s$)
      tWd = VectorTextWidth(s$)
      MovePathCursor(5+rwd/2-twd/2, 5+rht/2-tht/2)
      DrawVectorText(s$)
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, Text Wd & Ht swapped.
      ;/////////////////////////////////////////////////////
      rWd = 30
      rHt = 140
      AddPathBox(150, 5, rWd, rHt)   ; Orig Rectangle rotated -90°
      VectorSourceColor(RGBA(0, 255, 0, 255))
      StrokePath(1)
      tht = VectorTextWidth(s$)
      twd = VectorTextHeight(s$)
      MovePathCursor(150+rwd/2-twd/2, 5+rht/2+tht/2)
      RotateCoordinates(PathCursorX(), PathCursorY(), -90)
      DrawVectorText(s$)
      ResetCoordinates()
      StopVectorDrawing()
    EndIf
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, But text drawn as topdown paragraph.
      ;/////////////////////////////////////////////////////
    If StartVectorDrawing(CanvasVectorOutput(0))
      rWd = 30
      rHt = 140
      AddPathBox(5, 40, rWd, rHt)   ; Orig Rectangle rotated -90°
      VectorSourceColor(RGBA(0, 0, 255, 255))
      StrokePath(1)
      ; Try paragraph text
      VectorFont(hFnt, txSize-6)
      s$ = "1" + #LF$ + "2" + #LF$ + "3" + #LF$ + "4"
      twd = VectorTextWidth(s$)
      tht = VectorTextHeight(s$)
      MovePathCursor(5+rwd/2-twd/2, 40+rht/2-tht/2)
      DrawVectorParagraph(s$, 30, 140, #PB_VectorParagraph_Center)
      StopVectorDrawing()
    EndIf
    Repeat
      evWW = WaitWindowEvent()
    Until evWW = #PB_Event_CloseWindow
  EndIf
EndProcedure
CompilerIf 1
  Bug()
CompilerElse
  NoBug()
CompilerEndIf
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply