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

!A
!A NAME:
!A
!A 	Text Outline Contours  VARIATIONAL
!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
!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]
DIM Point$[256]
DIM Angle_var$[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:!
Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Size_known=0
Firsttime=1
Text_loop:!

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
No_angle_var= LastVariableInput(Angle_var$)

END IF

IF Font_picked THEN
    Fontname$= GetFontNameStr(Ptsize,Weight,Bold,Italic)
ELSE
    Answer$= GetFontNameStr(Ptsize1,Weight,Bold,Italic)
END IF
V1=CreateVariable("font name",WsSystemVars,Fontname$)

Pick_point:Stat=SetInputFormat("n4=","")
Pc=XyzInput("LOCATION POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pc) THEN Pick_point
E1= LastPickEnt
Pick_para= LastPickPara
Pick_return= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(Pc)
        Stat= EntityNameCheck(E1,Point$)
        Pc_created= WsTrue
ELSE
        Stat= EntityNameCheck(E1,Point$)
        Pc_created= WsFalse
END IF
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)

Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CONTOUR: Text outline contours")
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Point$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Point$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Point$,Pick_para,WsGeomCenter)
END SELECT
V1= FreeParameter("Pt size",Ptsize)
V2= FreeParameter("Pt space",Ptspace)
IF No_angle_var THEN
        V3= FreeParameter("Angle",Angle)
ELSE
        V3= FreeParameter("Angle",Angle_var$)
END IF
V4= FreeParameter("Weight",Weight)
V5= FreeParameter("Bold",Bold)
V6= FreeParameter("Italic",Italic)
V7= StringConstant(Text_line$)
V8= StringConstant(Fontname$)
Paths= FontOutline(Pc,V7,V8,V1,V2,V4,V5,V6,V3)
Stat=DeleteEntity(Pc)
Stat= AutoNameGroup(Paths,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Paths)
Stat= PlotEntity(Point$)
IF NOT ValidGeometry(Paths) THEN
        DelLastVarRecord
ELSE
        ActivateUndo
        Stat= AdvanceUndoNumber("text outline contours")
IF Pc_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point$)
        Stat= AddGroupToUndo(WsUBCreateMode,Paths,1,WsTrue)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

Stat=SetPickMask(WsPickAll)
GOTO Text_loop

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