
! script name: draft.d/fontoutline
! topic: gives outline contours for text string

!A
!A NAME:
!A
!A 	Text Outline Contours
!A
!A DESCRIPTION:
!A
!A	Create contours from character outlines for a given text string. 
!A
!A~ image location - images/fontoutline.jpg
!B INSTRUCTIONS:
!B
!B 	TEXT: Enter the line of text to be output at the selected position.
!B
!B	PT SPACE BETWEEN CHARS, Pick font:
!B		Space between characters given in typeface point values
!B		There are 72 points in one inch.
!B		Pick font allows you to change fonts.
!B
!B	ANGLE: Choose the angle of the line of text.
!B
!B 	INPUT ABS X,Y,Z: Enter the X,Y,Z coordinates for the position of the
!B 		line of text.  NOTE: See XYZ INPUT OPTIONS.
!B
!B
!B NOTES:
!B
!B	Placement will be graphical for short text lines. Graphical image quality
!B	will depend on the number of characters. 
!B	For long text lines select the placement point.
!B
!B	To set a default font insert the line:
!B	    V1=CreateVariable("font name",WsSystemVars,"Times New Roman")
!B	into your /usr/weber/contrib/userconstants file. With a font name
!B	which is present on your computer.
!B
!B	Not all fonts are present on each computer. The fonts which are present
!B	depend on the applications installed. 
!B
!B	Not all the fonts which appear in the font dialog box are outline fonts.
!B	If you select a font which cannot be represented as an outline the program
!B	will default to an outline font.
!B
!B	The font outline contours may not necessarily be machinable. Some
!B	character outlines have overlapping entities. These must be repaired
!B	to create cutter offsets.
!B
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: font outline ")

DIM Answer$[256]
DIM Text_line$[256]
DIM Destination$[256]
DIM Fontname$[256]
DEG


Place_min= NamedVarVal("Graph place min",WsSystemVars,50)
Place_max= NamedVarVal("Graph place max",WsSystemVars,2000)
Place_density= NamedVarVal("Graph place density",WsSystemVars,5)
Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)
Place_max= 2000
Place_density= 1


IF (OSystemId=1) THEN
    Fontname$=NamedVariableStr("font name",WsSystemVars,"")
    IF NOT LEN(Fontname$) THEN
        V1=CreateVariable("font name",WsSystemVars,"Nimbus Roman No9 L")
        Fontname$="Nimbus Roman No9 L"
    END IF
ELSE
    Fontname$=NamedVariableStr("font name",WsSystemVars,"")
    IF NOT LEN(Fontname$) THEN
        V1=CreateVariable("font name",WsSystemVars,"Times New Roman")
        Fontname$="Times New Roman"
    END IF
END IF

Ptsize= 72
Ptspace= 0

Start:!
ActivateUndo
Size_known=0
Firsttime=1
Text_loop:!
Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)

Stat=SetInputFormat("a99","")
Stat=GetValue("TEXT ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Text_line$=Answer$
IF LEN(Text_line$)> 20 THEN Graphical_mode=0
Place_density= 1+ INT(LEN(Text_line$)/3)

Font_picked=0
IF Firsttime THEN
Firsttime=0
Stat=SetInputFormat("a1n0=",",P,")
stat=SetEqualsValue(Ptsize)
Ptsize=GetValue("PT SIZE, Pick font",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="P" THEN
PickFont
Font_picked=1
END IF


Stat=SetInputFormat("n0=","")
stat=SetEqualsValue(Ptspace)
Answer$="0"
IF LEN(Text_line$)>1 THEN
Ptspace=GetValue("PT SPACE BETWEEN CHARS",Answer$)
IF (ExitScript(Destination$)) THEN Leave
END IF

Angle=InputAngle("ANGLE")
IF (ExitScript(Destination$)) THEN Leave

END IF

IF Font_picked THEN
    Fontname$= GetFontNameStr(Ptsize,Weight,Bold,Italic)
ELSE
    Answer$= GetFontNameStr(Ptsize1,Weight,Bold,Italic)
END IF
IF Graphical_mode=0 THEN
    Stat=SetInputFormat("n4=","")
    Pc=XyzInput("INPUT",WsXyzInput)
    IF (ExitScript(Destination$)) THEN Leave

    PlotOn
    Paths= FontOutline(Pc,Text_line$,Fontname$,Ptsize,Ptspace,Weight,Bold,Italic,Angle)
    V1=CreateVariable("font name",WsSystemVars,Fontname$)
    Stat=DeleteEntity(Pc)

ELSE
   Active_workplane=0
   Work=CurrentWorkplane
   IF ValidGeometry(Work) THEN Active_workplane=1

   Pref= PointXYZ(0,0,0)
   PlotOff
   Paths= FontOutline(Pref,Text_line$,Fontname$,Ptsize,Ptspace,Weight,Bold,Italic,Angle)
   V1=CreateVariable("font name",WsSystemVars,Fontname$)
   IF NOT ValidGeometry(Paths) THEN
      Stat=DeleteEntity(Pref)
      GOTO Start
   END IF
   Pdest= CopyEntity(Pref)
   P1= PointXYZ(0,0,1)
   Paxis= AddVectors(Pref,P1)
   Stat= DeleteEntity(P1)
   Axis_line= LineTwoPoints(Pref,Paxis)
   Stat= DeleteEntity(Paxis)
   Stat= MakeInvisible(Axis_line)
   Stat= MakeInvisible(Pref)
   PlotOn
   Stat= EraseEntity(Paths)

   Vnum= LastPickView
   stat= SetInputFormat("n4b","")
   Group2= MakeSparseGroup(Paths,Place_min,Place_max,Place_density)
   Stat= MakeInvisible(Paths)
   Rotate_angle= DynamicMoveGroup(Vnum,Group2,Pref,Pdest,0.0,"PICK DESTINATION POINT")
   Stat= DeleteEntity(Group2)
   Stat= MakeVisible(Paths)
   IF ExitScript(Destination$) THEN
        Stat= DeleteGroup(Paths,WsTrue)
        GOTO Leave
   END IF

   Stat= SetSelectedFlag(Paths,WsFalse)
   StdWorkplane
   Trans1= RotMoveAxisTrans(Pdest,Axis_line,Rotate_angle)
   Stat=TransGroupTrans(Paths,Trans1,WsTrue)
   Stat=PlotEntity(Paths)

   Stat= DeleteEntity(Pref)
   Stat= DeleteEntity(Pdest)
   Stat= DeleteEntity(Paxis)
   Stat= DeleteEntity(Axis_line)

   IF Active_workplane THEN
        Stat=SetWorkplane(Work)
   ELSE
        StdWorkplane
   END IF

END IF
ActivateUndo
Stat= AdvanceUndoNumber("font outline")
Stat= AddGroupToUndo(WsUBCreateMode,Paths,WsFalse,WsTrue)
Stat= DeleteEntity(Paths)

Stat=SetPickMask(WsPickAll)
GOTO Text_loop

Leave:!
PlotOn
Stat=DeleteEntity(Pc)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
