Drawline rotate output x degrees

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Dec 05, 2012 5:52 am

Here's what I've come up with. Took much longer than I expected... made me have to think!

I took some liberties with your original script removing things for clarity while testing that I did not put back. I don't know if this will be of use to you but I put time and effort in so I'll post it in case there is some tidbit our descendants might find useful.

I have not had time to look at what you created. Looks interesting. I'll have to look up the new API calls to see what they do

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1

Let>scaleD=1
Let>xmax=100
Let>ymax=50
Let>xmin=100
Let>ymin=50
//sample File Data - Lettering:  T  Font:  monotype Corsiva
let>dxdyData=0,0,3%crlf%0,0,3%crlf%0,0,195%crlf%0.7,-5.4,193%crlf%1.4,-10.8,193%crlf%1.9,-16.1,193%crlf%1.9,-16.1,3%crlf%1.8,-16.2,3%crlf%2.9,-16.2,3%crlf%3.7,-15.4,3%crlf%4,-14.3,3%crlf%4,-13.2,3%crlf%3.9,-12.1,3%crlf%4.7,-11.1,3%crlf%4,-11.4,3%crlf%3.9,-12.5,3%crlf%3.9,-14,3%crlf%3.7,-15.4,3%crlf%2.8,-16.2,3%crlf%1.3,-16.5,3%crlf%1.7,-15.5,3%crlf%1.6,-16.7,3%crlf%2.1,-15.6,3%crlf%2,-16.8,3%crlf%2.3,-15.7,3%crlf%2.5,-16.8,3%crlf%2.5,-15.8,3%crlf%3,-16.7,3%crlf%2.7,-15.7,3%crlf%3.5,-16.4,3%crlf%2.9,-15.6,3%crlf%3.8,-16.1,3%crlf%3.1,-15.4,3%crlf%4.1,-15.7,3%crlf%3.3,-15.2,3%crlf%4.4,-15.2,3%crlf%3.4,-14.9,3%crlf%4.5,-14.8,3%crlf%3.4,-14.6,3%crlf%4.5,-14.3,3%crlf%3.4,-14.3,3%crlf%4.6,-13.9,3%crlf%3.4,-14,3%crlf%4,-13.6,3%crlf%3.9,-12.5,3%crlf%4,-11.4,3%crlf%4.8,-11.1,3%crlf%4.8,-10.7,3%crlf%4.9,-11.6,3%crlf%4.7,-10.6,3%crlf%4.8,-11.7,3%crlf%4.2,-10.6,3%crlf%4.5,-11.7,3%crlf%3.6,-11.1,3%crlf%4.4,-11.7,3%crlf%3.4,-11.7,3%crlf%4.4,-11.9,3%crlf%3.4,-12.2,3%crlf%4.4,-12.1,3%crlf%3.4,-12.6,3%crlf%4.4,-12.4,3%crlf%3.4,-13,3%crlf%4.5,-12.7,3%crlf%3.4,-13.4,3%crlf%4.5,-13.1,3%crlf%3.4,-13.7,3%crlf%4.5,-13.5,3%crlf%3.4,-14,3%crlf%3,-13.5,3%crlf%1.4,-13.9,3%crlf%0.2,-14.2,3%crlf%-0.2,-14.1,3%crlf%1.4,-13.7,3%crlf%3.3,-13.6,3%crlf%2.4,-13.8,3%crlf%1.4,-14.1,3%crlf%-0.5,-13.7,3%crlf%-0.4,-15.2,3%crlf%-0.2,-13.6,3%crlf%0.2,-14.2,3%crlf%1.1,-14,3%crlf%2.1,-13.7,3%crlf%3.3,-13.4,3%crlf%3.7,-14,3%crlf%3.6,-12.7,3%crlf%3.3,-14.1,3%crlf%3.2,-12.8,3%crlf%3,-14.2,3%crlf%2.9,-12.8,3%crlf%2.7,-14.3,3%crlf%2.6,-12.9,3%crlf%2.4,-14.3,3%crlf%2.3,-13,3%crlf%2.1,-14.4,3%crlf%2,-13.1,3%crlf%1.8,-14.5,3%crlf%1.7,-13.2,3%crlf%1.5,-14.6,3%crlf%1.3,-13.2,3%crlf%1.2,-14.7,3%crlf%1,-13.3,3%crlf%0.8,-14.7,3%crlf%0.7,-13.4,3%crlf%0.5,-14.8,3%crlf%0.4,-13.5,3%crlf%0.2,-14.9,3%crlf%0.1,-13.6,3%crlf%-0.1,-15,3%crlf%-0.2,-13.6,3%crlf%-0.1,-15,3%crlf%-0.6,-14.9,3%crlf%-0.3,-15.3,3%crlf%-1.2,-15.4,3%crlf%-0.1,-14.9,3%crlf%-1.1,-15,3%crlf%-0.2,-14.5,3%crlf%-1.1,-14.6,3%crlf%-0.2,-14,3%crlf%-1.2,-14.3,3%crlf%-0.3,-13.7,3%crlf%-1.2,-13.8,3%crlf%-0.2,-13.2,3%crlf%-1.2,-13.3,3%crlf%-0.2,-13.1,3%crlf%-1.2,-13.3,3%crlf%-0.2,-13.2,3%crlf%-1.2,-13.3,3%crlf%-0.2,-13.1,3%crlf%-1.2,-13.3,3%crlf%-1.2,-13.3,195%crlf%0.9,-10.7,193
// arrow with right triangle and left square
'let>dxdyData=0,0,3%crlf%0,5,3%crlf%0,25,3%crlf%10,5,3%crlf%10,3,3%crlf%9,3,3%crlf%10,5,3%crlf%-10,5,3%crlf%-10,3,3%crlf%-9,3,3%crlf%-9,5,3%crlf%-10,5,3%crlf%0,25,3


Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 94
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Redraw File'
  ClientHeight = 500
  ClientWidth = 500
  Color = clWhite
  Ctl3D = False
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poDesktopCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,Quit
GDP>Dialog1,,ClientHeight,Wy
GDP>Dialog1,,ClientWidth,Wx
Let>winX=%Wx%/2
Let>winY=%Wy%/2

Let>delay=0.05

Show>Dialog1

Separate>%dxdyData%,%crlf%,dline
let>c=,
let>st=0
Let>b=1


If>scaleD=1
Let>scale={(%Wx%-10)/(%xmax%+%xmin%)}
Else
Let>scale={(%Wy%-10)/(%ymax%+%ymin%)}
Endif
Let>scale={(round(%scale%*10))/10}

'scale for testing
let>scale=4

'Draw bounding box = to extents
'rect
let>ulx={(%winX%)-(%xmax%)}
Let>uly={(%winY%)-(%ymax%)}
let>lrx={(%winX%)+(%xmin%)}
Let>lry={(%winY%)+(%ymin%)}
GoSub>DrawRectangle,Dialog1.handle,1,0,14547193,ulx,uly,lrx,lry

let>xOffset={(%winX%)-(%xmax%-%xmin%)}
let>yOffset={(%winY%)-(%ymax%-%ymin%)}
Separate>dline_%b%,%c%,dl

Separate>dline_%b%,%c%,org

//I wasn't sure what the offset calculation was supposed to accomplish so I
//defined offsets for testing purposes
Let>xOffset=winx
Let>yOffset=winy

let>dl_1={%dl_1%*%scale%}
//Reverse y polarity at the start
let>dl_2={(%dl_2%*%scale%)*-1}

//Rotate coordinates clock Wise
//Is Quad I,  To Quad II
If>{(%dl_1%>0)and(%dl_2%>0)}
 Let>dxs={(%dl_2%*-1)+%xoffset%}
 Let>dys=%dl_1%+%yOffset%
Else
  //Is Quad II,  To Quad III
  If>{(%dl_1%<0)and(%dl_2%>0)}
    Let>dxs={(%dl_2%*-1)+%xOffset%}
    Let>dys=%dl_1%+%yOffset%
  Else
    //Is Quad III,  To Quad IV
    If>{(%dl_1%<0)and(%dl_2%<0)}
      Let>dxs={(%dl_2%*-1)+%xOffset%}
      Let>dys=%dl_1%+%yOffset%
    Else
      //Is Quad IV,  To Quad I
      If>{(%dl_1%>0)and(%dl_2%<0)}
        Let>dxs={(%dl_2%*-1)+%xOffset%}
        Let>dys=%dl_1%+%yOffset%
      EndIf
    EndIf
  EndIf
EndIf

//Deal with zeros should they occur
If>dl_1=0
  Let>dxs=%dl_2%+%xoffset%
  Let>dys={(%dl_1%*-1)+%yOffset%}
EndIf

If>dl_2=0
  Let>dys=%dl_1%+%yoffset%
  Let>dxs={(%dl_2%*-1)+%xOffset%}
EndIf

//Return Y polarity back to original
Let>dys={((%dys%-%yoffset%)*-1)+%yOffset%}


Repeat>b
Let>b=b+1
Separate>dline_%b%,%c%,dl
Separate>dline_%b%,%c%,org

let>dl_1={%dl_1%*%scale%}
let>dl_2={(%dl_2%*%scale%)*-1}

let>Flag=%dl_3%
if>Flag<>3
Random>16777215,color



//Is Quad I,  To Quad II
If>{(%dl_1%>0)and(%dl_2%>0)}
 Let>dxs={(%dl_2%*-1)+%xoffset%}
 Let>dys=%dl_1%+%yOffset%
Else
  //Is Quad II,  To Quad III
  If>{(%dl_1%<0)and(%dl_2%>0)}
    Let>dxs={(%dl_2%*-1)+%xOffset%}
    Let>dys=%dl_1%+%yOffset%
  Else
    //Is Quad III,  To Quad IV
    If>{(%dl_1%<0)and(%dl_2%<0)}
      Let>dxs={(%dl_2%*-1)+%xOffset%}
      Let>dys=%dl_1%+%yOffset%
    Else
      //Is Quad IV,  To Quad I
      If>{(%dl_1%>0)and(%dl_2%<0)}
        Let>dxs={(%dl_2%*-1)+%xOffset%}
        Let>dys=%dl_1%+%yOffset%
      EndIf
    EndIf
  EndIf
EndIf


If>dl_1=0
  Let>dxs=%dl_2%+%xoffset%
  Let>dys={(%dl_1%*-1)+%yOffset%}
EndIf

If>dl_2=0
  Let>dys=%dl_1%+%yoffset%
  Let>dxs={(%dl_2%*-1)+%xOffset%}
EndIf

Let>dys={((%dys%-%yoffset%)*-1)+%yOffset%}

let>dxe=%dxs%
let>dye=%dys%
else


//Is Quad I,  To Quad II
If>{(%dl_1%>0)and(%dl_2%>0)}
 Let>dxe={(%dl_2%*-1)+%xoffset%}
 Let>dye=%dl_1%+%yOffset%
Else
  //Is Quad II,  To Quad III
  If>{(%dl_1%<0)and(%dl_2%>0)}
    Let>dxe={(%dl_2%*-1)+%xOffset%}
    Let>dye=%dl_1%+%yOffset%
  Else
    //Is Quad III,  To Quad IV
    If>{(%dl_1%<0)and(%dl_2%<0)}
      Let>dxe={(%dl_2%*-1)+%xOffset%}
      Let>dye=%dl_1%+%yOffset%
    Else
      //Is Quad IV,  To Quad I
      If>{(%dl_1%>0)and(%dl_2%<0)}
        Let>dxe={(%dl_2%*-1)+%xOffset%}
        Let>dye=%dl_1%+%yOffset%
      EndIf
    EndIf
  EndIf
EndIf

If>dl_1=0
  Let>dxe=%dl_2%+%xoffset%
  Let>dye={(%dl_1%*-1)+%yOffset%}
EndIf

If>dl_2=0
  Let>dye=%dl_1%+%yoffset%
  Let>dxe={(%dl_2%*-1)+%xOffset%}
EndIf

Let>dye={((%dye%-%yoffset%)*-1)+%yOffset%}

wait>0

Let>dys={round(%dys%)}
Let>dxs={round(%dxs%)}
Let>dye={round(%dye%)}
Let>dxe={round(%dxe%)}


GoSub>DrawLine,Dialog1.handle,1,color,dxs,dys,dxe,dye
let>dxs=%dxe%
let>dys=%dye%
endif
Until>b,%dline_count%

let>MSG_HEIGHT=100
Let>MSG_WIDTH=200
Let>MSG_XPOS=600
Let>MSG_YPOS=500
MessageModal>Done

//GoSub>DrawLine,WindowHandle,PenSize,PenColor,XStart,YStart,XEnd,YEnd

SRT>DrawLine
LibFunc>user32,GetDC,HDC,%DrawLine_var_1%
LibFunc>gdi32,CreatePen,Penres,0,%DrawLine_var_2%,%DrawLine_var_3%
LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
Libfunc>gdi32,MoveToEx,mtres,HDC,%DrawLine_var_4%,%DrawLine_var_5%,0
LibFunc>gdi32,LineTo,ltres,hdc,%DrawLine_var_6%,%DrawLine_var_7%
LibFunc>gdi32,DeleteObject,DOres,Penres
LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawLine

//DrawRectangle Usage:
//GoSub>DrawRectangle,WindowHandle,PenSize,PenColor,SolidColor,ULXLocation,ULYLocation,LRXLocation,LRYLocation

SRT>DrawRectangle
LibFunc>user32,GetDC,HDC,%DrawRectangle_var_1%
LibFunc>gdi32,CreatePen,Penres,0,%DrawRectangle_var_2%,%DrawRectangle_var_3%
LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
LibFunc>gdi32,CreateSolidBrush,SBres,%DrawRectangle_var_4%
LibFunc>gdi32,SelectObject,SOres,hdc,sbres
LibFunc>gdi32,Rectangle,recres,hdc,%DrawRectangle_var_5%,%DrawRectangle_var_6%,%DrawRectangle_var_7%,%DrawRectangle_var_8%
LibFunc>gdi32,DeleteObject,DOres,Penres
LibFunc>gdi32,DeleteObject,DOres,sbres
LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawRectangle


SRT>Quit
Exit>0
END>Quit


User avatar
stitch22
Junior Coder
Posts: 31
Joined: Mon Oct 20, 2008 3:18 pm
Location: California
Contact:

Post by stitch22 » Thu Dec 06, 2012 1:47 am

Wow! JRL U da Man! That works fantasticaly. I will Defintely use it.

I'll post a screenshot when I get this implemented into the prototype.
The extra offset were to allow for files that are offset from center.
Iv'e learned alot over the past few days.

Turns out after I got the page in the right coordinate system the data is output at -90 rotation, maybe thats for the machine its sent to. not sure.

The API calls allow you to change the coordinate space of the device (window). Have fun with that.
I am still working on a solution that allows us to use the
SetWorldTransformation Function. That would be a nice function to be able to use. It's requiring me to delve deeper into vbscript than I ever wanted to or needed to.

Thanks again for your help

User avatar
stitch22
Junior Coder
Posts: 31
Joined: Mon Oct 20, 2008 3:18 pm
Location: California
Contact:

Post by stitch22 » Fri Dec 07, 2012 12:58 am

Hi JRL,

Here is the latest. It did not work perfectly, but what ever does. I trimmed down the code and used the new API calls to reduce the code even further.

Here is the test script with the modifications and some notes/comments. I also put your code into a sub called PenDwn. It Works as it is supposed to. the drawings come in and are redrawn in the proper orientation. I still have some clean up and a couple small issues to work out but for the most part its good. thanks again.

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1

Let>scaleD=1
Let>xmax=100
Let>ymax=50
Let>xmin=100
Let>ymin=50
//sample File Data - Lettering:  T  Font:  monotype Corsiva
let>dxdyData=0,0,3%crlf%0,0,3%crlf%0,0,195%crlf%0.7,-5.4,193%crlf%1.4,-10.8,193%crlf%1.9,-16.1,193%crlf%1.9,-16.1,3%crlf%1.8,-16.2,3%crlf%2.9,-16.2,3%crlf%3.7,-15.4,3%crlf%4,-14.3,3%crlf%4,-13.2,3%crlf%3.9,-12.1,3%crlf%4.7,-11.1,3%crlf%4,-11.4,3%crlf%3.9,-12.5,3%crlf%3.9,-14,3%crlf%3.7,-15.4,3%crlf%2.8,-16.2,3%crlf%1.3,-16.5,3%crlf%1.7,-15.5,3%crlf%1.6,-16.7,3%crlf%2.1,-15.6,3%crlf%2,-16.8,3%crlf%2.3,-15.7,3%crlf%2.5,-16.8,3%crlf%2.5,-15.8,3%crlf%3,-16.7,3%crlf%2.7,-15.7,3%crlf%3.5,-16.4,3%crlf%2.9,-15.6,3%crlf%3.8,-16.1,3%crlf%3.1,-15.4,3%crlf%4.1,-15.7,3%crlf%3.3,-15.2,3%crlf%4.4,-15.2,3%crlf%3.4,-14.9,3%crlf%4.5,-14.8,3%crlf%3.4,-14.6,3%crlf%4.5,-14.3,3%crlf%3.4,-14.3,3%crlf%4.6,-13.9,3%crlf%3.4,-14,3%crlf%4,-13.6,3%crlf%3.9,-12.5,3%crlf%4,-11.4,3%crlf%4.8,-11.1,3%crlf%4.8,-10.7,3%crlf%4.9,-11.6,3%crlf%4.7,-10.6,3%crlf%4.8,-11.7,3%crlf%4.2,-10.6,3%crlf%4.5,-11.7,3%crlf%3.6,-11.1,3%crlf%4.4,-11.7,3%crlf%3.4,-11.7,3%crlf%4.4,-11.9,3%crlf%3.4,-12.2,3%crlf%4.4,-12.1,3%crlf%3.4,-12.6,3%crlf%4.4,-12.4,3%crlf%3.4,-13,3%crlf%4.5,-12.7,3%crlf%3.4,-13.4,3%crlf%4.5,-13.1,3%crlf%3.4,-13.7,3%crlf%4.5,-13.5,3%crlf%3.4,-14,3%crlf%3,-13.5,3%crlf%1.4,-13.9,3%crlf%0.2,-14.2,3%crlf%-0.2,-14.1,3%crlf%1.4,-13.7,3%crlf%3.3,-13.6,3%crlf%2.4,-13.8,3%crlf%1.4,-14.1,3%crlf%-0.5,-13.7,3%crlf%-0.4,-15.2,3%crlf%-0.2,-13.6,3%crlf%0.2,-14.2,3%crlf%1.1,-14,3%crlf%2.1,-13.7,3%crlf%3.3,-13.4,3%crlf%3.7,-14,3%crlf%3.6,-12.7,3%crlf%3.3,-14.1,3%crlf%3.2,-12.8,3%crlf%3,-14.2,3%crlf%2.9,-12.8,3%crlf%2.7,-14.3,3%crlf%2.6,-12.9,3%crlf%2.4,-14.3,3%crlf%2.3,-13,3%crlf%2.1,-14.4,3%crlf%2,-13.1,3%crlf%1.8,-14.5,3%crlf%1.7,-13.2,3%crlf%1.5,-14.6,3%crlf%1.3,-13.2,3%crlf%1.2,-14.7,3%crlf%1,-13.3,3%crlf%0.8,-14.7,3%crlf%0.7,-13.4,3%crlf%0.5,-14.8,3%crlf%0.4,-13.5,3%crlf%0.2,-14.9,3%crlf%0.1,-13.6,3%crlf%-0.1,-15,3%crlf%-0.2,-13.6,3%crlf%-0.1,-15,3%crlf%-0.6,-14.9,3%crlf%-0.3,-15.3,3%crlf%-1.2,-15.4,3%crlf%-0.1,-14.9,3%crlf%-1.1,-15,3%crlf%-0.2,-14.5,3%crlf%-1.1,-14.6,3%crlf%-0.2,-14,3%crlf%-1.2,-14.3,3%crlf%-0.3,-13.7,3%crlf%-1.2,-13.8,3%crlf%-0.2,-13.2,3%crlf%-1.2,-13.3,3%crlf%-0.2,-13.1,3%crlf%-1.2,-13.3,3%crlf%-0.2,-13.2,3%crlf%-1.2,-13.3,3%crlf%-0.2,-13.1,3%crlf%-1.2,-13.3,3%crlf%-1.2,-13.3,195%crlf%0.9,-10.7,193
// arrow with right triangle and left square
'let>dxdyData=0,0,3%crlf%0,5,3%crlf%0,25,3%crlf%10,5,3%crlf%10,3,3%crlf%9,3,3%crlf%10,5,3%crlf%-10,5,3%crlf%-10,3,3%crlf%-9,3,3%crlf%-9,5,3%crlf%-10,5,3%crlf%0,25,3


Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 94
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Redraw File'
  ClientHeight = 500
  ClientWidth = 500
  Color = clWhite
  Ctl3D = False
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poDesktopCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,Quit
GDP>Dialog1,,ClientHeight,Wy
GDP>Dialog1,,ClientWidth,Wx
Let>winX=%Wx%/2
Let>winY=%Wy%/2

Let>delay=0.05

Show>Dialog1

Separate>%dxdyData%,%crlf%,dline
let>c=,
let>st=0
Let>b=1


If>scaleD=1
Let>scale={(%Wx%-10)/(%xmax%+%xmin%)}
Else
Let>scale={(%Wy%-10)/(%ymax%+%ymin%)}
Endif
Let>scale={(round(%scale%*10))/10}

'scale for testing
let>scale=8

'Draw bounding box = to extents
'rect
let>ulx={(%winX%)-(%xmax%)}
Let>uly={(%winY%)-(%ymax%)}
let>lrx={(%winX%)+(%xmin%)}
Let>lry={(%winY%)+(%ymin%)}
GoSub>DrawRectangle,Dialog1.handle,1,0,14547193,ulx,uly,lrx,lry

let>xOffset={(%winX%)-(%xmax%-%xmin%)}
let>yOffset={(%winY%)-(%ymax%-%ymin%)}

Separate>dline_%b%,%c%,dl

Separate>dline_%b%,%c%,org

//I wasn't sure what the offset calculation was supposed to accomplish so I
//defined offsets for testing purposes
Let>xOffset=winx
Let>yOffset=winy

// Reverse x y polarity at the start
// both reversed due to new window coordinate
let>dl_1={(%dl_1%*%scale%)*-1}
let>dl_2={(%dl_2%*%scale%)*-1}

// sets start
let>dxs=%dl_1%
let>dys=%dl_2%

Repeat>b
Let>b=b+1
Separate>dline_%b%,%c%,dl
Separate>dline_%b%,%c%,org

let>dl_1={(%dl_1%*%scale%)*-1}
let>dl_2={(%dl_2%*%scale%)*-1}

let>Flag=%dl_3%
if>Flag<>3
Random>16777215,color

let>dxe=%dxs%
let>dye=%dys%

else

GoSub>PenDwn
wait>0


Let>dye={round(%dye%)}
Let>dxe={round(%dxe%)}


GoSub>DrawLine,Dialog1.handle,1,color,dxs,dys,dxe,dye
let>dxs=%dxe%
let>dys=%dye%


endif
Until>b,%dline_count%

let>MSG_HEIGHT=100
Let>MSG_WIDTH=200
Let>MSG_XPOS=600
Let>MSG_YPOS=500
MessageModal>Done

SRT>PenDwn
//Is Quad I,  To Quad II
If>{(%dl_1%>0)and(%dl_2%>0)}
 Let>dxe={(%dl_2%*-1)}
 Let>dye=%dl_1%
Else
  //Is Quad II,  To Quad III
  If>{(%dl_1%<0)and(%dl_2%>0)}
    Let>dxe={(%dl_2%*-1)}
    Let>dye=%dl_1%
  Else
    //Is Quad III,  To Quad IV
    If>{(%dl_1%<0)and(%dl_2%<0)}
      Let>dxe={(%dl_2%*-1)}
      Let>dye=%dl_1%
    Else
      //Is Quad IV,  To Quad I
      If>{(%dl_1%>0)and(%dl_2%<0)}
        Let>dxe={(%dl_2%*-1)}
        Let>dye=%dl_1%
      EndIf
    EndIf
  EndIf
EndIf

//This if Needed for Y not For X ?
If>dl_2=0
  Let>dye=%dl_1%
  Let>dxe={(%dl_2%*-1)}
EndIf

Let>dye={((%dye%)*-1)}
  
END>PenDwn


//GoSub>DrawLine,WindowHandle,PenSize,PenColor,XStart,YStart,XEnd,YEnd
// modified to with new API calls to change window coordinates
// changing window to 0,0  Center instead of  upper left with xy offsets
SRT>DrawLine
LibFunc>user32,GetDC,HDC,%DrawLine_var_1%
// additional calls
LibFunc>gdi32,SetGraphicsMode,gMode,hDC,2
LibFunc>gdi32,SetMapMode,mMode,hDC,4
LibFunc>gdi32,SetWindowExtEx,setWin,hDC,%Wx%,%Wy%,0
LibFunc>gdi32,SetViewportOrgEx,setVPor,hDC,%xOffset%,%yOffset%,0
LibFunc>gdi32,SetViewportExtEx,setVPex,hDC,%Wx%,%Wy%,0
// not all of the above maybe necessary except "SetViewportOrgEx"
LibFunc>gdi32,CreatePen,Penres,0,%DrawLine_var_2%,%DrawLine_var_3%
LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
Libfunc>gdi32,MoveToEx,mtres,HDC,%DrawLine_var_4%,%DrawLine_var_5%,0
LibFunc>gdi32,LineTo,ltres,hdc,%DrawLine_var_6%,%DrawLine_var_7%
LibFunc>gdi32,DeleteObject,DOres,Penres
LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawLine

//DrawRectangle Usage:
//GoSub>DrawRectangle,WindowHandle,PenSize,PenColor,SolidColor,ULXLocation,ULYLocation,LRXLocation,LRYLocation

SRT>DrawRectangle
LibFunc>user32,GetDC,HDC,%DrawRectangle_var_1%
LibFunc>gdi32,CreatePen,Penres,0,%DrawRectangle_var_2%,%DrawRectangle_var_3%
LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
LibFunc>gdi32,CreateSolidBrush,SBres,%DrawRectangle_var_4%
LibFunc>gdi32,SelectObject,SOres,hdc,sbres
LibFunc>gdi32,Rectangle,recres,hdc,%DrawRectangle_var_5%,%DrawRectangle_var_6%,%DrawRectangle_var_7%,%DrawRectangle_var_8%
LibFunc>gdi32,DeleteObject,DOres,Penres
LibFunc>gdi32,DeleteObject,DOres,sbres
LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawRectangle


SRT>Quit
Exit>0
END>Quit

User avatar
stitch22
Junior Coder
Posts: 31
Joined: Mon Oct 20, 2008 3:18 pm
Location: California
Contact:

Post by stitch22 » Sun Dec 09, 2012 12:53 am

Hi JRL,
After many more hours research and testing, a few aspirin and a beer.
I came up with this version. I can now rotate the drawing to any angle.

Code: Select all


//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1

Let>scaleD=1
Let>xmax=100
Let>ymax=50
Let>xmin=100
Let>ymin=50
//sample File Data - Lettering:  T  Font:  monotype Corsiva
let>dxdyData=0,0,3%crlf%0,0,3%crlf%0,0,195%crlf%0.7,-5.4,193%crlf%1.4,-10.8,193%crlf%1.9,-16.1,193%crlf%1.9,-16.1,3%crlf%1.8,-16.2,3%crlf%2.9,-16.2,3%crlf%3.7,-15.4,3%crlf%4,-14.3,3%crlf%4,-13.2,3%crlf%3.9,-12.1,3%crlf%4.7,-11.1,3%crlf%4,-11.4,3%crlf%3.9,-12.5,3%crlf%3.9,-14,3%crlf%3.7,-15.4,3%crlf%2.8,-16.2,3%crlf%1.3,-16.5,3%crlf%1.7,-15.5,3%crlf%1.6,-16.7,3%crlf%2.1,-15.6,3%crlf%2,-16.8,3%crlf%2.3,-15.7,3%crlf%2.5,-16.8,3%crlf%2.5,-15.8,3%crlf%3,-16.7,3%crlf%2.7,-15.7,3%crlf%3.5,-16.4,3%crlf%2.9,-15.6,3%crlf%3.8,-16.1,3%crlf%3.1,-15.4,3%crlf%4.1,-15.7,3%crlf%3.3,-15.2,3%crlf%4.4,-15.2,3%crlf%3.4,-14.9,3%crlf%4.5,-14.8,3%crlf%3.4,-14.6,3%crlf%4.5,-14.3,3%crlf%3.4,-14.3,3%crlf%4.6,-13.9,3%crlf%3.4,-14,3%crlf%4,-13.6,3%crlf%3.9,-12.5,3%crlf%4,-11.4,3%crlf%4.8,-11.1,3%crlf%4.8,-10.7,3%crlf%4.9,-11.6,3%crlf%4.7,-10.6,3%crlf%4.8,-11.7,3%crlf%4.2,-10.6,3%crlf%4.5,-11.7,3%crlf%3.6,-11.1,3%crlf%4.4,-11.7,3%crlf%3.4,-11.7,3%crlf%4.4,-11.9,3%crlf%3.4,-12.2,3%crlf%4.4,-12.1,3%crlf%3.4,-12.6,3%crlf%4.4,-12.4,3%crlf%3.4,-13,3%crlf%4.5,-12.7,3%crlf%3.4,-13.4,3%crlf%4.5,-13.1,3%crlf%3.4,-13.7,3%crlf%4.5,-13.5,3%crlf%3.4,-14,3%crlf%3,-13.5,3%crlf%1.4,-13.9,3%crlf%0.2,-14.2,3%crlf%-0.2,-14.1,3%crlf%1.4,-13.7,3%crlf%3.3,-13.6,3%crlf%2.4,-13.8,3%crlf%1.4,-14.1,3%crlf%-0.5,-13.7,3%crlf%-0.4,-15.2,3%crlf%-0.2,-13.6,3%crlf%0.2,-14.2,3%crlf%1.1,-14,3%crlf%2.1,-13.7,3%crlf%3.3,-13.4,3%crlf%3.7,-14,3%crlf%3.6,-12.7,3%crlf%3.3,-14.1,3%crlf%3.2,-12.8,3%crlf%3,-14.2,3%crlf%2.9,-12.8,3%crlf%2.7,-14.3,3%crlf%2.6,-12.9,3%crlf%2.4,-14.3,3%crlf%2.3,-13,3%crlf%2.1,-14.4,3%crlf%2,-13.1,3%crlf%1.8,-14.5,3%crlf%1.7,-13.2,3%crlf%1.5,-14.6,3%crlf%1.3,-13.2,3%crlf%1.2,-14.7,3%crlf%1,-13.3,3%crlf%0.8,-14.7,3%crlf%0.7,-13.4,3%crlf%0.5,-14.8,3%crlf%0.4,-13.5,3%crlf%0.2,-14.9,3%crlf%0.1,-13.6,3%crlf%-0.1,-15,3%crlf%-0.2,-13.6,3%crlf%-0.1,-15,3%crlf%-0.6,-14.9,3%crlf%-0.3,-15.3,3%crlf%-1.2,-15.4,3%crlf%-0.1,-14.9,3%crlf%-1.1,-15,3%crlf%-0.2,-14.5,3%crlf%-1.1,-14.6,3%crlf%-0.2,-14,3%crlf%-1.2,-14.3,3%crlf%-0.3,-13.7,3%crlf%-1.2,-13.8,3%crlf%-0.2,-13.2,3%crlf%-1.2,-13.3,3%crlf%-0.2,-13.1,3%crlf%-1.2,-13.3,3%crlf%-0.2,-13.2,3%crlf%-1.2,-13.3,3%crlf%-0.2,-13.1,3%crlf%-1.2,-13.3,3%crlf%-1.2,-13.3,195%crlf%0.9,-10.7,193
// arrow with right triangle and left square
'let>dxdyData=0,0,3%crlf%0,5,3%crlf%0,25,3%crlf%10,5,3%crlf%10,3,3%crlf%9,3,3%crlf%10,5,3%crlf%-10,5,3%crlf%-10,3,3%crlf%-9,3,3%crlf%-9,5,3%crlf%-10,5,3%crlf%0,25,3


Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 94
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Redraw File'
  ClientHeight = 500
  ClientWidth = 500
  Color = clWhite
  Ctl3D = False
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poDesktopCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,Quit
GDP>Dialog1,,ClientHeight,Wy
GDP>Dialog1,,ClientWidth,Wx
Let>winX=%Wx%/2
Let>winY=%Wy%/2

Let>delay=0.05

input>angle,Enter Angle [-90 is 0 ]

'let>angle=ang

Show>Dialog1

Separate>%dxdyData%,%crlf%,dline
let>c=,
let>st=0
Let>b=1


If>scaleD=1
Let>scale={(%Wx%-10)/(%xmax%+%xmin%)}
Else
Let>scale={(%Wy%-10)/(%ymax%+%ymin%)}
Endif
Let>scale={(round(%scale%*10))/10}

'scale for testing
let>scale=8

'Draw bounding box = to extents
'rect
let>ulx={(%winX%)-(%xmax%)}
Let>uly={(%winY%)-(%ymax%)}
let>lrx={(%winX%)+(%xmin%)}
Let>lry={(%winY%)+(%ymin%)}
GoSub>DrawRectangle,Dialog1.handle,1,0,14547193,ulx,uly,lrx,lry

let>xOffset={(%winX%)-(%xmax%-%xmin%)}
let>yOffset={(%winY%)-(%ymax%-%ymin%)}

//I wasn't sure what the offset calculation was supposed to accomplish so I
//defined offsets for testing purposes
Let>xOffset=winx
Let>yOffset=winy

Let>rad={%angle%*(pi/180)}
Let>xF_1={Round(Cos(%rad%))}
Let>xF_2={Round(-Sin(%rad%))}
Let>xF_3={Round(Sin(%rad%))}


// sets stary point
Separate>dline_%b%,%c%,dl
Let>dataX={Round(%dl_1%*%scale%)}
Let>dataY={Round(%dl_2%*%scale%)}
Let>dxs={Round(%xF_1%*%dataX%)+(%xF_3%*%dataY%)}
Let>dys={Round(%xF_1%*%dataY%)+(%xF_2%*%dataX%)}
let>dxs=%dxs%*-1


Repeat>b
Let>b=b+1
Separate>dline_%b%,%c%,dl

Let>dataX={Round(%dl_1%*%scale%)}
Let>dataY={Round(%dl_2%*%scale%)}

let>Flag=%dl_3%
if>Flag<>3
Random>16777215,color

let>dxe=%dxs%
let>dye=%dys%

else

Let>dxe={Round(%xF_1%*%dataX%)+(%xF_3%*%dataY%)}
Let>dye={Round(%xF_1%*%dataY%)+(%xF_2%*%dataX%)}
'Flip add *-1
let>dxe=%dxe%*-1


GoSub>DrawLine,Dialog1.handle,1,color,dxs,dys,dxe,dye
let>dxs=%dxe%
let>dys=%dye%


endif
Until>b,%dline_count%

let>MSG_HEIGHT=100
Let>MSG_WIDTH=200
Let>MSG_XPOS=600
Let>MSG_YPOS=500
MessageModal>Done

SRT>PenDwn
//Is Quad I,  To Quad II
If>{(%dl_1%>0)and(%dl_2%>0)}
 Let>dxe={(%dl_2%*-1)}
 Let>dye=%dl_1%
Else
  //Is Quad II,  To Quad III
  If>{(%dl_1%<0)and(%dl_2%>0)}
    Let>dxe={(%dl_2%*-1)}
    Let>dye=%dl_1%
  Else
    //Is Quad III,  To Quad IV
    If>{(%dl_1%<0)and(%dl_2%<0)}
      Let>dxe={(%dl_2%*-1)}
      Let>dye=%dl_1%
    Else
      //Is Quad IV,  To Quad I
      If>{(%dl_1%>0)and(%dl_2%<0)}
        Let>dxe={(%dl_2%*-1)}
        Let>dye=%dl_1%
      EndIf
    EndIf
  EndIf
EndIf

//This if Needed for Y not For X ?
If>dl_2=0
  Let>dye=%dl_1%
  Let>dxe={(%dl_2%*-1)}
EndIf

Let>dye={((%dye%)*-1)}
  
END>PenDwn


//GoSub>DrawLine,WindowHandle,PenSize,PenColor,XStart,YStart,XEnd,YEnd
// modified to with new API calls to change window coordinates
// changing window to 0,0  Center instead of  upper left with xy offsets
SRT>DrawLine
LibFunc>user32,GetDC,HDC,%DrawLine_var_1%
// additional calls
LibFunc>gdi32,SetGraphicsMode,gMode,hDC,2
LibFunc>gdi32,SetMapMode,mMode,hDC,4
LibFunc>gdi32,SetWindowExtEx,setWin,hDC,%Wx%,%Wy%,0
LibFunc>gdi32,SetViewportOrgEx,setVPor,hDC,%xOffset%,%yOffset%,0
LibFunc>gdi32,SetViewportExtEx,setVPex,hDC,%Wx%,%Wy%,0
// not all of the above maybe necessary except "SetViewportOrgEx"
LibFunc>gdi32,CreatePen,Penres,0,%DrawLine_var_2%,%DrawLine_var_3%
LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
Libfunc>gdi32,MoveToEx,mtres,HDC,%DrawLine_var_4%,%DrawLine_var_5%,0
LibFunc>gdi32,LineTo,ltres,hdc,%DrawLine_var_6%,%DrawLine_var_7%
LibFunc>gdi32,DeleteObject,DOres,Penres
LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawLine

//DrawRectangle Usage:
//GoSub>DrawRectangle,WindowHandle,PenSize,PenColor,SolidColor,ULXLocation,ULYLocation,LRXLocation,LRYLocation

SRT>DrawRectangle
LibFunc>user32,GetDC,HDC,%DrawRectangle_var_1%
LibFunc>gdi32,CreatePen,Penres,0,%DrawRectangle_var_2%,%DrawRectangle_var_3%
LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
LibFunc>gdi32,CreateSolidBrush,SBres,%DrawRectangle_var_4%
LibFunc>gdi32,SelectObject,SOres,hdc,sbres
LibFunc>gdi32,Rectangle,recres,hdc,%DrawRectangle_var_5%,%DrawRectangle_var_6%,%DrawRectangle_var_7%,%DrawRectangle_var_8%
LibFunc>gdi32,DeleteObject,DOres,Penres
LibFunc>gdi32,DeleteObject,DOres,sbres
LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawRectangle


SRT>Quit
Exit>0
END>Quit

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts