home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 11.img / BONUS2.LIB / PTEXT.LSP < prev    next >
Encoding:
Text File  |  1993-02-09  |  58.2 KB  |  1,861 lines

  1. ;;;   PText.lsp
  2. ;;;   ¬⌐┼v (C) 1988-1992  Autodesk ñ╜Ñq
  3. ;;;
  4. ;;;   Ñ╗╡{ªíñwÑ╤ Autodesk ñ╜Ñq╡∙ÑU¬⌐┼v, ╢╚⌐≤ñU¡z▒í¬pñUÑi▒┬╗P▒zíu│\ÑiívíC
  5. ;;;   ╗╒ñUñú▒oÑHÑ⌠ª≤º╬ªí╡oªµ⌐╬ÑX¬⌐ª╣╡{ªí¬║íu¡∞⌐l╜Xív; ª²ñ╣│\▒zªb»S⌐w¡lÑ═
  6. ;;;   ¬║ñuº@ñW╡▓ªXª╣╡{ªí¬║íuÑ╪¬║╜Xív¿╧Ñ╬íCª│├÷│o├■¡lÑ═ñuº@¬║▒°Ñ≤ªpñU:
  7. ;;;
  8. ;;;   ( i)  │]¡pñW╗Pñuº@ñW¼╥»┬║Θ░w╣∩ Autodesk ñ╜Ñq¬║▓ú½~íC
  9. ;;;   (ii)  ╕ⁿª│íu¬⌐┼v  (C) 1988-1992  Autodesk ñ╜Ñqív¬║¬⌐┼v│qºiíC
  10. ;;;
  11. ;;;
  12. ;;;
  13. ;;;   AUTODESKñ╜Ñq┤ú¿╤ª╣╡{ªí╢╚¿╤º@íu├■ªⁿív¬║░╤ª╥, ª╙ÑBñú▒╞░úª│Ñ⌠ª≤┐∙╗~¬║
  14. ;;;   Ñi»αíCAUTODESKñ╜Ñq»Sª╣º_╗{Ñ⌠ª≤»S⌐wÑ╬│~ñº╛A║┘⌐╩, ÑHñ╬░╙╖~╛P░Γ⌐╥┴⌠ºt
  15. ;;;   ÑX¿π¬║½O├╥íCAUTODESKñ╜ÑqªP«╔ÑτñúÑX¿πª╣╡{ªí░⌡ªµ«╔ñ@⌐wñú╖|íuññ┬_ív⌐╬
  16. ;;;   íuº╣Ñ■╡L╗~ív¬║½O├╥íC
  17. ;;;
  18. ;;;
  19. ;;;   by Jan S. Yoder
  20. ;;;   with thanks to Kieran McKeogh for suggesting how to handle control
  21. ;;;   characters.
  22. ;;;   15 February 1990
  23. ;;;
  24. ;;;   Version 1.11
  25. ;;;     29 January 1991 -- JSY  : More minor bug fixes.
  26. ;;;     11 January 1991 -- JSY  : Numerous minor bug fixes.
  27. ;;;
  28. ;;;----------------------------------------------------------------------------  ;;;
  29. ;;; DESCRIPTION
  30. ;;;   PTEXT -- Paragraph text processor.
  31. ;;;
  32. ;;;   Text can be entered directly on the AutoCAD text screen, in one of four
  33. ;;;   modes; Left justified, Center or Right justified, or Fit between two
  34. ;;;   line endpoints.  Word wrapping will occur based on some rudimentary
  35. ;;;   assumptions which are necessary until and if a function can be provided
  36. ;;;   for determining the actual size of a text item at any given font and
  37. ;;;   number and size of characters.
  38. ;;;
  39. ;;;   The actual number of characters of "slack", the number of allowable extra
  40. ;;;   characters beyond the predetermined maximum, can be set by the user.
  41. ;;;
  42. ;;;   This processor works by reading keyboard input via (grread) and based
  43. ;;;   on this input, causing the current text entity to be regenerated.  This
  44. ;;;   routine can probably be made to operate unacceptably slowly by doing
  45. ;;;   one or more of the following:
  46. ;;;
  47. ;;;     Operating the routine in multiple viewports where the text entities'
  48. ;;;     layer is ON in all of them.
  49. ;;;
  50. ;;;     Working on fairly long text strings;  say, greater than 30 characters.
  51. ;;;
  52. ;;;     Operating on a slow processor.
  53. ;;;
  54. ;;;   The best method is to work on a layer which is exclusively visible in
  55. ;;;   the current viewport, and on fairly short strings.
  56. ;;;
  57. ;;;   The options are:
  58. ;;;
  59. ;;;    Command: ptext
  60. ;;;    Center/Edit/Fit/Load-file/Right/Slack/<Start point>:
  61. ;;;
  62. ;;;  Left, Center, right, and Fit justified text entry types are supported
  63. ;;;  for text entry.  The editing portion of this routine should work on
  64. ;;;  all of the Release 11 justification options.  This has not been tested!
  65. ;;;
  66. ;;;  The following control characters allow a "cursor" composed of a set of
  67. ;;;  underline control codes to move around within a set of text entities.
  68. ;;;
  69. ;;;       ^A -- Append a space after the current cursor position and
  70. ;;;             move the cursor to that position.
  71. ;;;       ^B -- Go to the beginning of the line.
  72. ;;;       ^D -- Move the cursor down a line; maintains the current letter
  73. ;;;             position.  This position may appear to be different due to
  74. ;;;             character kerning within a font.
  75. ;;;       ^E -- Go to the end of the current line.
  76. ;;;       ^H -- Backspace key.
  77. ;;;       ^I -- Toggle insert/overwrite mode.
  78. ;;;       ^L -- Move the cursor to the left  -- non-destructive cursor.
  79. ;;;   RETURN -- Return; move any characters to the right of the cursor
  80. ;;;             down to the next line and push the remaining lines down
  81. ;;;             one "interline spacing" amount.
  82. ;;;       ^N -- Go to the end of the last text entity in the list.
  83. ;;;       ^R -- Move the cursor to the right -- non-destructive cursor.
  84. ;;;       ^T -- Go to the start of the first text entity in the list.
  85. ;;;       ^U -- Move the cursor up a line; maintains the current letter
  86. ;;;             position.  This position may appear to be different due to
  87. ;;;             character kerning within a font.
  88. ;;;       ^Z -- Exit text entry.
  89. ;;;       -  -- Hyphen character.
  90. ;;;          -- The delete key deletes the current character, and if there is
  91. ;;;             no character and the cursor is at the end of a line and there
  92. ;;;             are more lines, then the next line is pulled up onto the
  93. ;;;             current line and any remaining lines are moved up one
  94. ;;;             "interline spacing" amount.
  95. ;;;
  96. ;;;   ^U and ^X are interchanged between DOS and UNIX machines due to low
  97. ;;;   level character swapping by the operating system, so either of these
  98. ;;;   combinations will cause the cursor to move up a line on either
  99. ;;;   machine type.
  100. ;;;
  101. ;;;   Local variables representing key code values for translation
  102. ;;;   to other keyboard codes, if necessary, are listed at the top
  103. ;;;   of the (ptext) defun.
  104. ;;;
  105. ;;;----------------------------------------------------------------------------
  106.  
  107.  
  108. (defun ptext (/ pt_ver pt_err        pt_oe  pt_oce pt_sty pt_twf
  109.                 char   insert grp_72 pt_spt pt_rpt str
  110.                 line_l pt_cl  pt_str cont   sset   j      TX:LST ent
  111.                 pt_ils cont1  ans    temp   sl     pt_rsp pt_msp pt_tsp
  112.                 return OK2BRK max_j  diff   nchars dir    dstrct pt_obm
  113.                 pt_te EDIT_T  pnding pt_dth
  114.                 P_SLCK P_BEGL P_HLPD P_HLPU P_DWNL P_ENDL P_BACK
  115.                 P_ISRT P_JUST P_LEFT P_RTRN P_ENDT P_RGHT P_BEGT
  116.                 P_UPLD P_UPLU P_QUIT P_SPCE P_HYPH P_DDEL P_UDEL
  117.              )
  118.  
  119.   (setq pt_ver "1.11")                ; Reset this local if you make a change.
  120.  
  121.   ;;
  122.   ;; Internal error handler defined locally
  123.   ;;
  124.  
  125.   (defun pt_err (s)                   ; If an error (such as CTRL-C) occurs
  126.                                       ; while this command is active...
  127.     (if (/= s "Function cancelled")
  128.       (if (= s "quit / exit abort")
  129.         (princ)
  130.         (princ (strcat "\n┐∙╗~: " s))
  131.       )
  132.     )
  133.     (if (null pt_GEX)
  134.       (progn
  135.         (entdel (cdr(assoc -1 pt_te))) ; Delete the test text entity.
  136.         (entmod (subst (cons 1 str) (assoc 1 ent) ent))
  137.       )
  138.     )
  139.     (command "_.UNDO" "_END")
  140.     (if ll_oe                         ; If an old error routine exists
  141.       (setq *error* pt_oe)            ; then, reset it
  142.     )
  143.     (setvar "blipmode" pt_obm)        ; Restore blipmode
  144.     (setvar "cmdecho" pt_oce)         ; Reset command echoing on error
  145.     (princ)
  146.   )
  147.   (if *error*                         ; Set our new error handler
  148.     (setq pt_oe *error* *error* pt_err)
  149.     (setq *error* pt_err)
  150.   )
  151.   (setq pt_oce (getvar "cmdecho"))    ; Save current state of command echoing
  152.   (setq pt_obm (getvar "blipmode"))   ; Save current state of blipmode
  153.   (setvar "cmdecho" 0)                ; Turn off command echoing
  154.   (setvar "blipmode" 0)               ; Turn off blipmode
  155.   (command "_.UNDO" "_GROUP")
  156.  
  157.   (if (null pt_GEX)
  158.     (progn
  159.       (cond
  160.         ((or (= (substr (getvar "PLATFORM") 1 4) "OS/2")
  161.              (= (substr (getvar "PLATFORM") 1 3) "DOS"))
  162.           (or
  163.             (setq temp (findfile "ptext.exe"))
  164.             (setq temp (findfile "ads/ptext.exe"))
  165.           )
  166.         )
  167.         ((= (substr (getvar "PLATFORM") 1 7) "386 DOS")
  168.           (or
  169.             (setq temp (findfile "ptext.exp"))
  170.             (setq temp (findfile "ads/ptext.exp"))
  171.           )
  172.         )
  173.         (T
  174.           (or
  175.             (setq temp (findfile "ptext"))
  176.             (setq temp (findfile "ads/ptext"))
  177.           )
  178.         )
  179.       )
  180.       (if temp
  181.         (if (null (xload temp))
  182.           (progn
  183.             (princ "\n╡L¬k╕ⁿñJíuPtextív░⌡ªµ╡{ªííC ")
  184.             (if (and pt_sup pt_uls get_ch pt_gll pt_cll pt_psl
  185.                      is_num pt_csl pt_gpl pt_gpr pt_sjk pt_mc
  186.                      pt_bul pt_sil pt_ael pt_ail pt_ats pt_pnl
  187.                      pt_pl pt_gmp pt_waw pt_pww pt_pee pt_mne
  188.                      pt_fww pt_dal dr_txt round)
  189.  
  190.               (princ (strcat "\n⌐╥░⌡ªµ¬║ AutoLISP ½Y╢╚¿╤"
  191.                 "íu«iÑ▄ívÑ╬¬║¬⌐Ñ╗íC"))
  192.               (progn
  193.                 (princ "\nª╣¬⌐Ñ╗¬║íuPtext.lspív╗▌¡nѪíC")
  194.                 (exit)
  195.               )
  196.             )
  197.           )
  198.           (princ "\n\n\n░⌡ªµ ADS ¬⌐Ñ╗¬║ PTEXT íC")
  199.         )
  200.         (if (and pt_sup pt_uls get_ch pt_gll pt_cll pt_psl
  201.                  is_num pt_csl pt_gpl pt_gpr pt_sjk pt_mc
  202.                  pt_bul pt_sil pt_ael pt_ail pt_ats pt_pnl
  203.  
  204.                  pt_pl pt_gmp pt_waw pt_pww pt_pee pt_mne
  205.                  pt_fww pt_dal dr_txt round)
  206.  
  207.           (progn
  208.             (princ "\n╡L¬k╕ⁿñJíuPtextív░⌡ªµ╡{ªííC ")
  209.             (princ (strcat "\n⌐╥░⌡ªµ¬║ AutoLISP ½Y╢╚¿╤"
  210.               "íu«iÑ▄ívÑ╬¬║¬⌐Ñ╗íC"))
  211.           )
  212.           (progn
  213.             (princ "\n╡L¬k╕ⁿñJíuPtextív░⌡ªµ╡{ªííC ")
  214.             (princ "\nª╣¬⌐Ñ╗¬║íuPtext.lspív╗▌¡nѪíC")
  215.             (exit)
  216.           )
  217.         )
  218.       )
  219.     )
  220.     (princ "\n\n\n░⌡ªµ ADS ¬⌐Ñ╗¬║ PTEXT íC")
  221.   )
  222.   ;; These are the machine codes for the various cursor motion controls
  223.   ;; for both UNIX and DOS which are reported by calls to (ads_grread).
  224.   ;;
  225.   ;; Note that UNIX machines can redefine the low level codes and the
  226.   ;; actions of the keys marked "DELETE" and the backspace key, as well
  227.   ;; others.  They may not operate as documented.  Check the codes returned
  228.   ;; by (grread) "key press" against the table below to determine which
  229.   ;; codes to change for your system.
  230.   ;;
  231.   ;; They may need translation for other country keyboard codes.
  232.   ;;
  233.   ;; The codes listed here are used only if the PTEXT executable is not
  234.   ;; in use.  Change the source code for the executable if you wish to
  235.   ;; change the response of any of the keys and recompile it as described
  236.   ;; in the ADS User Guide.
  237.  
  238.   (if (null pt_GEX)
  239.     (setq P_APPN   1                  ; ^A Append a space at current pt_rsp.
  240.           P_BEGL   2                  ; ^B Beginning of line.
  241.           P_DWNL   4                  ; ^D Down a line.
  242.           P_ENDL   5                  ; ^E End of line.
  243.           P_BACK   8                  ; ^H Backspace.
  244.           P_ISRT   9                  ; ^I Toggle insert/overwrite mode.
  245.           P_LEFT  12                  ; ^L Left  -- non-destructive cursor.
  246.           P_RTRN  13                  ;    Return.
  247.           P_ENDT  14                  ; ^N End of text.
  248.           P_RGHT  18                  ; ^R Right -- non-destructive cursor.
  249.           P_BEGT  20                  ; ^T Beginning of text.
  250.           P_UPLD  21                  ; ^U Up a line (DOS).
  251.           P_UPLU  24                  ; ^X Up a line (UNIX).
  252.           P_QUIT  26                  ; ^Z Exit text entry.
  253.           P_SPCE  32                  ;    Spacebar.
  254.           P_HYPH  45                  ; -  Hyphen character.
  255.           P_UDEL 127                  ;    Delete character (UNIX).
  256.           P_DDEL 211                  ;    Delete character (DOS).
  257.           P_HLPD 222                  ;^F1 Help screen on DOS
  258.           P_HLPU  31                  ;^?  Help screen on UNIX
  259.     )
  260.   )
  261.   (setq pt_sty (tblsearch "style" (getvar "textstyle"))
  262.         pt_dth (cdr(assoc 40 pt_sty))
  263.         pt_twf (cdr(assoc 41 pt_sty))
  264.         pt_toa (cdr(assoc 50 pt_sty))
  265.         pt_stn (cdr(assoc  2 pt_sty))
  266.         P_SLCK 0                      ; No slack characters
  267.         char   P_SPCE                 ; "space" character
  268.         insert T                      ; Start in insert mode.
  269.   )
  270.  
  271.   ;; Make a frozen layer for determining the length of a text string.
  272.   (if (null (setq temp (tblsearch "layer" "frozen_text")))
  273.     (command "_.LAYER" "_NEW" "FROZEN_TEXT" "_FREEZE" "FROZEN_TEXT" "")
  274.     (if (= (logand (cdr(assoc 70 temp)) 1) 0)
  275.       (command "_.LAYER" "_FREEZE" "FROZEN_TEXT" "")
  276.       (princ)
  277.     )
  278.   )
  279.   (if (= (getvar "handles") 0)        ; Handles are off
  280.     (progn
  281.       (initget "Yes No")
  282.       (if (= (getkword "\n▒╥Ñ╬íu╣╧╜Xív? <Y>: ") "No")
  283.         (progn
  284.           (princ
  285.             "\n▒²¿╧ª╣▒`ªí─~─≥╢iªµÑ▓╢╖┼²íu╣╧╜Xív▒╥Ñ╬íC")
  286.           (exit)
  287.         )
  288.         (command "_.HANDLES" "_ON")
  289.       )
  290.     )
  291.   )
  292.   (if (null pt_GEX)
  293.     (progn
  294.       ;; Create a dummy text entity on this layer.
  295.       (command "_.TEXT" "_R" "0,0" "" "" "Ptext")
  296.       (setq pt_te (entget(entlast))
  297.             pt_te (subst (cons 8 "frozen_text") (assoc 8 pt_te) pt_te)
  298.       )
  299.       (entmod pt_te)
  300.     )
  301.   )
  302.  
  303.   (princ (strcat "\níuThe Paragraph Text Editorív, ¬⌐Ñ╗ "
  304.                  pt_ver
  305.                  ", (c) 1990  Autodesk ñ╜ÑqíC "))
  306.   (pt_opt)                            ; Get options from user
  307.   (if (null EDIT_T)
  308.     (progn
  309.       (pt_sth)                        ; Set text height.
  310.       (if (/= grp_72 5)
  311.         (pt_sra)                      ; Set rotation angle.
  312.         (setq pt_ra (angle pt_spt pt_rpt))
  313.       )
  314.       (setq pt_ils (pt_sis))          ; Set the spacing between lines.
  315.       (if (/= grp_72 5)
  316.         (pt_sml)                      ; Set the length of the lines.
  317.         (setq pt_mll (distance pt_spt pt_rpt))
  318.       )
  319.     )
  320.   )
  321.   (if (null str)
  322.     (setq str T)
  323.   )
  324.   (grtext -2 "Ptext: ┤íñJ╝╥ªí")
  325.   (if (null pt_GEX)
  326.     (progn
  327.       (setq line_l 0
  328.             pt_cl  0
  329.             pt_str ""
  330.       )
  331.       (while (/= str "")
  332.         (pt_sup)                      ; Set up
  333.         (while (get_ch)               ; Get characters
  334.  
  335.           ;; Maximum line length plus "slack" amount not yet reached...
  336.  
  337.           (if (< line_l pt_mll)
  338.             (pt_pl)                   ; Process the line
  339.             (progn
  340.               (setq temp (pt_waw))    ; Set up to wrap at word
  341.               (pt_pww temp)           ; Wrap at word
  342.             )
  343.           )
  344.           (setq char nil)
  345.         )
  346.       )
  347.     )
  348.     (progn
  349.       (setq EDIT_T (if (null EDIT_T) 0 1))
  350.       (if (null pt_rpt) (setq pt_rpt (list 0.0 0.0 0.0)))
  351.       (setq pt_sty (cdr(assoc 2 pt_sty)))
  352.       (setq err
  353.         (pt_GEX pt_spt pt_rpt grp_72 pt_th  pt_ra
  354.                 pt_mll pt_ils (atof pt_ver) pt_sty EDIT_T)
  355.       )
  356.     )
  357.   )
  358.   (if (null pt_GEX)
  359.     (entdel (cdr(assoc -1 pt_te)))    ; Delete the test text entity.
  360.   )
  361.   (command "_.UNDO" "_END")
  362.   (setvar "blipmode" pt_obm)          ; Restore blipmode
  363.   (setvar "cmdecho" pt_oce)           ; Restore command echoing
  364.   (princ)
  365. )
  366. ;;;
  367. ;;; Get options
  368. ;;;
  369. ;;; pt_opt == PText_OPTions
  370. ;;;
  371. (defun pt_opt (/ cont)
  372.   (setvar "cmdecho" 0)
  373.   (while (null cont)
  374.  
  375.     (setq cont T)
  376.  
  377.     (initget "Center Edit Fit Load-file Right Slack ?")
  378.     (setq pt_spt (getpoint
  379.       "\nCññ╢í/E╜s┐Φ/F╢±╗⌠/RÑk/S├Pªó/?/<░_⌐l┬I>: "))
  380.  
  381.     (cond
  382.       ((= pt_spt "Center")
  383.         (setq grp_72 1)
  384.         (initget 1)
  385.         (setq pt_spt (getpoint "\nññ╢ííu░≥╜u┬Iív: "))
  386.         (setq pt_spt (trans pt_spt 1 0))
  387.  
  388.       )
  389.       ((= pt_spt "Edit")
  390.         (princ (strcat
  391.           "\n┐∩╛▄╣w│╞╜s┐Φ¬║ñσªr; Ñ╤¼q╕¿¬║▓─ñ@ªC╢}⌐l┐∩¿·, "
  392.           "\n╡M½ß¿╠º╟┐∩¿·¿Σ╛lªUªC ... "))
  393.         (setq sset (ssget))
  394.         (if sset
  395.           (progn
  396.             (setq j 0)
  397.             (setq temp   (entget (ssname sset j))
  398.                   ename1 (cdr(assoc -1 temp))
  399.                   k      (cdr(assoc 210 temp))
  400.                   fd     (open "ptext.hdl" "w")
  401.             )
  402.             (if (null fd)
  403.               (progn
  404.                 (princ
  405.                   "\n╡L¬k╢}▒╥íu╣╧╜X└╔«╫ ptext.hdlívíC")
  406.                 (exit)
  407.               )
  408.             )
  409.             (if (> (sslength sset) 1)
  410.               (setq temp   (entget (ssname sset (1+ j)))
  411.                     ename2 (cdr(assoc -1 temp))
  412.               )
  413.             )
  414.  
  415.             (repeat (sslength sset)
  416.               (if (null pt_GEX)
  417.                 (progn
  418.                   (if (= (cdr(assoc 0 (entget (ssname sset j)))) "TEXT")
  419.                     (setq TX:LST (if TX:LST
  420.                                    (append TX:LST (list (ssname sset j)))
  421.                                    (list (ssname sset j))
  422.                                  )
  423.                           j      (1+ j)
  424.                           gottxt T
  425.                     )
  426.                   )
  427.                 )
  428.                 (progn
  429.                   (if (and
  430.                         (= (cdr(assoc 0 (entget (ssname sset j)))) "TEXT")
  431.                         (equal (cdr(assoc 210 (entget (ssname sset j)))) k)
  432.                       )
  433.                     (progn
  434.                       (if (> j 0) (princ "\n" fd))
  435.                       (princ (cdr(assoc 5 (entget (ssname sset j)))) fd)
  436.                       (setq gottxt T)
  437.                     )
  438.                   )
  439.                   (setq j      (1+ j))
  440.                 )
  441.               )
  442.             )
  443.             (if gottxt
  444.               (progn
  445.                 (if (null pt_GEX)
  446.                   (setq ent    (entget(nth 0 TX:LST)))
  447.                   (progn
  448.                     (close fd)
  449.                     (setq ent    (entget(ssname sset 0)))
  450.                   )
  451.                 )
  452.                 (setq pt_spt (cdr(assoc 10 ent))
  453.                       str    (cdr(assoc 1  ent))
  454.                       pt_th  (cdr(assoc 40 ent))
  455.                       pt_ra  (cdr(assoc 50 ent))
  456.                       grp_72 (cdr(assoc 72 ent))
  457.                 )
  458.                 (if (= grp_72 5)          ; Fit text
  459.                   (setq pt_rpt (cdr(assoc 11 ent))
  460.                         pt_mll (distance pt_spt pt_rpt)
  461.                   )
  462.                   (setq pt_mll (pt_sml))  ; Set maximum line length
  463.                 )
  464.                 (setq pt_ils (pt_gis)     ; Get interline spacing.
  465.                       EDIT_T T            ; Set a flag that we are editing.
  466.                 )
  467.               )
  468.               (progn
  469.                 (setq cont nil)
  470.                 (princ "\nÑ╝┐∩¿∞íuñσªr╣╧ñ╕ívíC")
  471.               )
  472.             )
  473.           )
  474.           (progn
  475.             (setq cont nil)           ; Repeat the first prompt.
  476.             (princ "\nÑ╝┐∩¿∞íuñσªr╣╧ñ╕ívíC")
  477.           )
  478.         )
  479.       )
  480.       ((= pt_spt "Fit")
  481.         (setq grp_72 5)
  482.         (initget 1)
  483.         (setq pt_spt (getpoint "\nѬíu░≥╜u┬Iív: "))
  484.         (initget 1)
  485.         (setq pt_rpt (getpoint pt_spt "\nÑkíu░≥╜u┬Iív: "))
  486.         (setq char nil)
  487.         (setq pt_spt (trans pt_spt 1 0))
  488.         (setq pt_rpt (trans pt_rpt 1 0))
  489.       )
  490.       ((= pt_spt "Right")
  491.         (setq grp_72 2)
  492.         (initget 1)
  493.         (setq pt_spt (getpoint "\nÑkíu░≥╜u┬Iív: "))
  494.         (setq pt_spt (trans pt_spt 1 0))
  495.  
  496.       )
  497.       ((= pt_spt "Slack")
  498.         (setq cont nil)
  499.         (if (null P_SLCK) (setq P_SLCK 1))
  500.         (initget 4)
  501.         (setq pt_spt (getint (strcat
  502.           "\níu├Pªóív¬║ªrñ╕╝╞Ñ╪ <" (itoa P_SLCK) ">: ")))
  503.         (if pt_spt (setq P_SLCK pt_spt))
  504.       )
  505.       ((= (type pt_spt) 'LIST)        ; A point was entered
  506.         (setq grp_72 0)
  507.         (setq pt_spt (trans pt_spt 1 0))
  508.  
  509.       )
  510.       ((= pt_spt "?")
  511.         (pt_phs T)
  512.         (setq cont nil)
  513.       )
  514.       (T
  515.         (command "_.UNDO" "_END")
  516.         (exit)                        ; Null entry -- get out.
  517.  
  518.       )
  519.     )
  520.   )
  521. )
  522. ;;;
  523. ;;; The help screen.
  524. ;;;
  525. ;;; pt_phs == PText_Print_Help_Screens
  526. ;;;
  527. (defun pt_phs (temp)
  528.   (if textpage (textpage) (textscr))
  529.   (if temp
  530.     (progn
  531.       (princ "\nñσªrÑi▒─ñU¡zÑ|║╪╝╥ªí¿╙┐ΘñJ: íuѬívíBíuññ╢íívíBíuÑkív⌐╬")
  532.       (princ "\níu╢±╗⌠ívíC┐ΘñJñσªr┤┴╢íÑi▒N┤σ╝╨▓╛ª▄ñσªrñºÑ⌠╖Nª∞╕m, ⌐╬╕g")
  533.       (princ "\nÑ╤íu E╜s┐Φív┐∩╢╡½ⁿ⌐wñσªrªC¿╙╢iªµ╜s┐ΦíC ")
  534.       (princ "\n")
  535.       (princ "\n")
  536.       (princ "\nÑ▓╢╖Ñ┐╜Tªa½÷╖╙╣w⌐w¬║╜s┐Φª╕º╟¿╙¼D┐∩│o¿╟ñσªr╣╧ñ╕; ╖φ½ⁿ⌐w")
  537.       (princ "\n¬║ñσªrªCññ┴ΣñJ├BÑ~¬║ñσªr«╔, ▒N╛╔¡P╕╙ªCíu▒▓ºΘ (wrap) ív")
  538.       (princ "\nª▄ñUñ@ªCíC")
  539.       (princ "\n  ")
  540.       (princ "\n  ")
  541.       (princ "\nñU¡z¬║íu▒▒¿εªrñ╕ívÑi┼²ºA╣BÑ╬íu┤σ╝╨ív (Ñ╤ñ@▓╒⌐│╜uíB│╗╜u")
  542.       (princ "\n¬║▒▒¿ε╜X⌐╥▓╒ª¿) ªbñσªr╣╧ñ╕╢íªU│B▓╛¿½íC ")
  543.       (princ "\n")
  544.       (princ "\n")
  545.       (princ "\n<▒╡ñU¡╢>")
  546.       (grread)
  547.       (princ "\r        ")
  548.     )
  549.   )
  550.   (if temp
  551.     (progn
  552.       (princ "\n     ^F1 (DOS) ⌐╬ ")
  553.       (princ "\n     ^?  (UNIX) -- ª╣¿DºU╡e¡▒íC")
  554.     )
  555.   )
  556.   (princ "\n")
  557.   (princ "\n     ^A  -- ªbÑ╪½e┤σ╝╨ª∞╕m¬■╝W (Append) ñ@¡╙¬┼«µ, ¿├▒N┤σ")
  558.   (princ "\n            ╝╨▓╛ª▄╕╙ª∞╕míC")
  559.   (princ "\n     ^B  -- ▒N┤σ╝╨▓╛ª▄Ñ╪½eªrªC¬║íuªC¡║ (Beginning)ívíC")
  560.   (princ "\n     ^D  -- ┤σ╝╨▓╛ª▄ñU (Down) ñ@ªC, ¿├║√½∙ªbÑ╪½eªrñ╕¬║ª∞")
  561.   (princ "\n            ╕mñWíCª╣ª∞╕mÑi»αÑ╤⌐≤íuªr┼ΘívññªUªrñ╕Ñ╗¿¡¬║«t")
  562.   (princ "\n            ▓º, ª╙ñú║╔¼█ªPíC")
  563.   (princ "\n     ^E  -- ▒N┤σ╝╨▓╛ª▄Ñ╪½eªrªC¬║íuªCº└ (End)ívíC")
  564.   (princ "\n     ^H  -- ░hª∞┴ΣíC")
  565.   (princ "\n     ^I  -- ñ┴┤½íu┤íñJí■┬╨╝gív╝╥ªííC")
  566.   (princ "\n     ^L  -- ┤σ╝╨Ѭ (Left) ▓╛íC")
  567.   (if temp
  568.     (progn
  569.       (princ "\n RETURN  -- <Return>; ▒N┤σ╝╨Ñk░╝¬║ªrñ╕íu▒▓ºΘívª▄ñUñ@ªC, ")
  570.       (princ "\n            ¿├▒N¡∞ѲªUªC½÷╖╙íuªC╢Zív¿╠º╟⌐╣ñU▒└íC")
  571.     )
  572.   )
  573.   (princ "\n     ^N  -- ▒N┤σ╝╨▓╛ª▄íuÑ╜ªCívñσªr╣╧ñ╕¬║íuªCº└ (eNd)ívíC")
  574.   (princ "\n     ^R  -- ┤σ╝╨Ñk (Right) ▓╛íC")
  575.   (princ "\n     ^T  -- ▒N┤σ╝╨▓╛ª▄íu│╗ªC (Top)ívñσªr╣╧ñ╕¬║íuªC¡║ívíC")
  576.   (princ "\n     ^U  -- ▒N┤σ╝╨▓╛ª▄ñW (Up) ñ@ªCíC")
  577.   (princ "\n     ^Z  -- ░hÑXñσªr┐ΘñJíC")
  578.   (princ "\n")
  579.   (if (null temp)
  580.     (progn
  581.       (princ "\n½÷Ñ⌠╖N┴ΣÑH¬≡ª^íu╣╧º╬╡e¡▒ívíC")
  582.       (grread)
  583.       (princ "\r                                          ")
  584.       (princ "\n")
  585.       (princ "\n")
  586.       (princ "\nñσªr: ")
  587.       (princ str)
  588.     )
  589.   )
  590.   (if temp
  591.     (progn
  592.       (princ "\n<▒╡ñU¡╢>")
  593.       (grread)
  594.       (princ "\r        ")
  595.       (princ "\n DELETE  -- ½÷ <Del>┴ΣÑiºR░úÑ╪½eªrñ╕; ¡Y┤σ╝╨ª∞⌐≤ªCº└ÑB╕╙")
  596.       (princ "\n            ñσªr¼q⌐|ª│╝╞ªCñσªr, ½hñUñ@ªC▒N│Q▒└ñWª▄Ñ╪½eªC")
  597.       (princ "\n            , ª╙¡∞ѲªUªC▒N½÷╖╙íuªC╢Zív¿╠º╟⌐╣ñW╖h▓╛íC")
  598.       (princ "\n ")
  599.       (princ
  600.         "\nªbªr (word) ññ┤íñJíu-ívªrñ╕, ╕╙ªr▒NÑ╤íu-ív│Bíu▒▓ºΘ (wrap)ívª▄ñUªCíC")
  601.       (princ "\n")
  602.     )
  603.   )
  604.   (princ)
  605. )
  606. ;;;
  607. ;;; Set the height of the text entities.
  608. ;;; Defaults to "0.2" if not preset in the style symbol table.
  609. ;;;
  610. ;;; pt_sth == PText_Set_Text_Height
  611. ;;;
  612. (defun pt_sth ()
  613.   (initget 6)
  614.   (if (= pt_dth 0.0) (setq pt_dth 0.2))
  615.   (setq ans (getdist (trans pt_spt 0 1) (strcat "\nªr░¬ <"
  616.                                     (if pt_th (rtos pt_th) (rtos pt_dth))
  617.                                     ">: ")))
  618.   (if ans
  619.     (setq pt_th ans)
  620.     (if (null pt_th)
  621.       (setq pt_th 0.2)
  622.     )
  623.   )
  624. )
  625. ;;;
  626. ;;; Set the rotation angle for the text.
  627. ;;; Defaults to "0" if not preset in the style symbol table.
  628. ;;;
  629. ;;; pt_sra == PText_Set_Rotation_Angle
  630. ;;;
  631. (defun pt_sra ()
  632.   (if (= (logand (cdr(assoc 70 pt_sty)) 4) 4)
  633.     (setq temp 270)
  634.     (setq temp 0)
  635.   )
  636.   (setq ans (getorient (trans pt_spt 0 1) (strcat
  637.     "\n▒█┬α¿ñ <" (if pt_ra (angtos pt_ra) (itoa temp)) ">: ")))
  638.   (if ans
  639.     (setq pt_ra ans)                  ; in radians
  640.     (setq pt_ra (/ temp (/ 180 pi)))
  641.   )
  642. )
  643. ;;;
  644. ;;; Get the spacing between the "baseline" of lines of text.
  645. ;;; Defaults to 1.5 times the text height.
  646. ;;; "Temp" is the group code to use.
  647. ;;;
  648. ;;; pt_gis == PText_Get_Interline_Spacing
  649. ;;;
  650. (defun pt_gis (/ temp)
  651.   (if (> (sslength sset) 1)
  652.     (progn
  653.       (if (or (= grp_72 0) (= grp_72 5))
  654.         (setq temp 10)
  655.         (setq temp 11)
  656.       )
  657.       (distance (cdr(assoc temp (entget ename1)))
  658.                 (cdr(assoc temp (entget ename2)))
  659.       )
  660.     )
  661.     (progn
  662.       (setq pt_ils (pt_sis))
  663.     )
  664.   )
  665. )
  666. ;;;
  667. ;;; Set the spacing between the "baseline" of lines of text.
  668. ;;; Defaults to 1.5 times the text height.
  669. ;;;
  670. ;;; pt_sis == PText_Set_Interline_Spacing
  671. ;;;
  672. (defun pt_sis ()
  673.   (setq pt_ils (* pt_th 1.5))
  674.   (initget 6)
  675.   (setq ans (getdist (trans pt_spt 0 1) (strcat
  676.     "\nªrªC╢í╢Z <" (if pt_ils (rtos pt_ils) "0.3") ">: ")))
  677.   (if ans
  678.     (if (= (logand (cdr(assoc 70 pt_sty)) 4) 4)
  679.       (- ans)
  680.       ans
  681.     )
  682.     (if (= (logand (cdr(assoc 70 pt_sty)) 4) 4)
  683.       (- (* 1.5 (if pt_th pt_th 0.2)))
  684.       (* 1.5 (if pt_th pt_th 0.2))
  685.     )
  686.   )
  687. )
  688. ;;;
  689. ;;; Set the maximum line length.
  690. ;;; Defaults to 2 units.
  691. ;;; Sets the global pt_mll.
  692. ;;;
  693. ;;; pt_sml == PText_Set_Maximum_line_Length
  694. ;;;
  695. (defun pt_sml ()
  696.   (if (null pt_mll)
  697.     (setq pt_mll (* pt_th 10.0))
  698.   )
  699.   (initget 6)
  700.   (setq ans (getdist (trans pt_spt 0 1) (strcat
  701.     "\nªC¬°ñW¡¡" (if pt_mll
  702.                               (strcat " <"  (rtos pt_mll) ">: ")
  703.                               ": ")))
  704.   )
  705.   (if ans
  706.     (setq pt_mll ans)
  707.   )
  708.   (+ pt_mll (* 0.9 P_SLCK pt_twf pt_th))
  709. )
  710. ;;;
  711. ;;; All functions defined following this line up to the final c: function
  712. ;;; definitions at the end of the file are duplicated in ptext.c and are
  713. ;;; included here to allow you to execute the PTEXT command without using
  714. ;;; an ADS routine.  You may want to try this to see the difference in speed
  715. ;;; between the command running as a pure AutoLisp application versus one
  716. ;;; that has been ported to ADS.
  717. ;;;
  718. ;;; In order to run the AutoLisp version, rename the PTEXT executable, and
  719. ;;; then run PTEXT.  If this routine cannot find an executable with the
  720. ;;; name of PTEXT (the extension varies), then it runs only the AutoLisp
  721. ;;; version.  Otherwise, the ADS version is loaded and run.
  722. ;;;
  723. ;;; If you are never going to run the AutoLisp version, then the code
  724. ;;; following this up to the final c: definitions may be deleted.
  725. ;;;
  726. ;;; ------------------ Cut here ----------------------------------
  727.  
  728. ;;;
  729. ;;; Set up before getting keyboard input.
  730. ;;;
  731. ;;; The counter "pt_cl" is the number of the current line
  732. ;;; starting at "1".  It is always one ahead of the number
  733. ;;; required by the lisp expression (nth <n> <list>) which
  734. ;;; starts its numbering at "0".  This counter is used througout
  735. ;;; for accessing text entities from the list TX:LST.
  736. ;;;
  737. ;;; pt_sup == PText_Set_UP
  738. ;;;
  739. (defun pt_sup ()
  740.   (setq pt_rsp 1
  741.         char   P_SPCE
  742.         pt_cl  (1+ pt_cl)
  743.         pt_vsp 1
  744.   )
  745.   (setq str    (if (= (type str) 'STR) str (chr char))
  746.         strlst (pt_psl str)           ; Parse string to list
  747.         pt_msp (pt_cll (length strlst) T) ; Check line length
  748.         pt_rsp (pt_cll pt_vsp nil)    ; Get character position/size
  749.         pt_str (pt_uls str pt_rsp)    ; Underline character 1
  750.   )
  751.   (if ent
  752.     (progn
  753.       (setq ent (subst (cons 1 pt_str) (assoc 1 ent) ent))
  754.       (entmod ent)
  755.     )
  756.     (progn
  757.       (dr_txt pt_str)                 ; Draw the text string - sets ent
  758.       (setq TX:LST (if TX:LST
  759.                      (pt_ael (cdr(assoc -1 ent)) pt_cl TX:LST)
  760.                      (list (cdr(assoc -1 ent)))
  761.                    )
  762.       )
  763.     )
  764.   )
  765.   (princ "\nñσªr: ")
  766.   (princ str)
  767. )
  768. ;;;
  769. ;;; Turn on underlining for an apparent character location (j)
  770. ;;; in a string (s).  Return the string with underlining.
  771. ;;;
  772. ;;; pt_uls == PText_UnderLine_String
  773. ;;;
  774. (defun pt_uls (s j / temp)
  775.   (setq temp (strlen s))
  776.   (if (> temp 0)
  777.     (if (and (> j 0) (<= j temp))
  778.       (strcat (substr s 1 (pt_csl 1 j))
  779.               (strcat "%%u" (if insert "" "%%o")
  780.                       (nth (1- j) strlst)
  781.                       "%%u" (if insert "" "%%o")
  782.               )
  783.               (substr s (1+ (pt_csl 1 (1+ j))))
  784.       )
  785.       (strcat (substr s 1 (pt_csl 1 j)) "%%u %%u")
  786.     )
  787.     "%%u %%u"
  788.   )
  789. )
  790. ;;;
  791. ;;; Get a character from the keyboard
  792. ;;;
  793. ;;;
  794. (defun get_ch (/ return)
  795.   ;; Disallow all input except the keyboard.
  796.   (while (/= (car (setq char (grread nil))) 2) (princ))
  797.   (setq char (cadr char))
  798.   (cond
  799.     ((= char P_RTRN)
  800.       (pt_pnl)                        ; Process newline
  801.       (setq return nil)
  802.     )
  803.     ((= char P_ISRT)
  804.       (if insert                      ; Toggle insert mode...
  805.         (progn
  806.           (setq insert nil)
  807.           (grtext -2 "Ptext:íu┬╨╝gív╝╥ªí")
  808.         )
  809.         (progn
  810.           (setq insert T)
  811.           (grtext -2 "Ptext:íu┤íñJív╝╥ªí")
  812.         )
  813.       )
  814.       (setq return T)
  815.     )
  816.     ;; Backspace key -- destructive cursor
  817.     ((= char P_BACK)
  818.       (pt_mc "LEFT" T)                ; Move cursor
  819.       (setq return T)
  820.     )
  821.     ((or (= char P_DDEL)
  822.          (= char P_UDEL))             ; Delete key
  823.       (pt_mc "DEL" nil)
  824.       (setq return T)
  825.     )
  826.     ;; ALT - A key  -- Append a space to the current cursor position.
  827.     ((= char P_APPN)
  828.       (setq char P_SPCE)
  829.       (setq pt_rsp (pt_ats char T))   ; Add character to string
  830.       (pt_mc "RIGHT" nil)             ; Move cursor
  831.       (setq return T)
  832.     )
  833.     ((= char P_BEGL)                  ; ALT - B key : Beginning of line
  834.       (pt_mc "HOME" nil)
  835.       (setq return T)
  836.     )
  837.     ((= char P_DWNL)                  ; ALT - D key : Move down a line
  838.       (pt_mc "DOWN" nil)
  839.       (setq return T)
  840.     )
  841.     ((= char P_ENDL)                  ; ALT - E key : End of the line
  842.       (pt_mc "END" nil)
  843.       (setq return T)
  844.     )
  845.     ((= char P_LEFT)                  ; ALT - L key : Move left
  846.       (pt_mc "LEFT" nil)
  847.       (setq return T)
  848.     )
  849.     ((= char P_ENDT)                  ; ALT - N key : Move to bottom of text
  850.       (pt_mc "BOTTOM" nil)
  851.       (setq return T)
  852.     )
  853.     ((= char P_RGHT)                  ; ALT - R key : Move right
  854.       (pt_mc "RIGHT" nil)
  855.       (setq return T)
  856.     )
  857.     ((= char P_BEGT)                  ; ALT - T key : Move to top of text
  858.       (pt_mc "TOP" nil)
  859.       (setq return T)
  860.     )
  861.     ((or (= char P_UPLD)
  862.          (= char P_UPLU))             ; ALT - U key (DOS or UNIX)
  863.       (pt_mc "UP" nil)
  864.       (setq return T)
  865.     )
  866.     ((= char P_QUIT)                  ; ALT - Z key -- exit.
  867.       (initget "Yes No")
  868.       (if (= (getkword "\n░hÑXíuñσªr┐ΘñJív? <Y>: ") "No")
  869.         (progn
  870.           (setq return T)
  871.           (princ "\nñσªr: ")
  872.           (princ str)
  873.         )
  874.         (progn
  875.           (entmod (subst (cons 1 str) (assoc 1 ent) ent))
  876.           (setq str    ""
  877.                 return nil
  878.           )
  879.         )
  880.       )
  881.     )
  882.     ((= char P_DEL)                   ; Delete -- delete character at cursor
  883.       (pt_mc "DEL" nil)
  884.       (setq return T)
  885.     )
  886.     ((or (= char P_HLPD) (= char P_HLPU)) ; ^F1 or ^? -- Help screen.
  887.       (pt_phs nil)
  888.       (setq return T)
  889.     )
  890.     ((= (chr char) "%")
  891.       (cond
  892.         ((= pnding nil) (setq pnding 1))
  893.         ((= pnding 1)   (setq pnding 2))
  894.         ((= pnding 2)   (setq pnding nil))
  895.         (T
  896.           (exit)
  897.         )
  898.       )
  899.       (setq pt_rsp (pt_ats char nil)
  900.             pt_vsp (pt_cll pt_rsp T)
  901.       )
  902.       (setq return T)
  903.     )
  904.     ; Else return T
  905.     (T
  906.       (if (= char P_HYPH)
  907.         (setq OK2BRK T)
  908.         (setq OK2BRK nil)
  909.       )
  910.       (if (> pnding 1)
  911.         (cond
  912.           ((or (= (chr char) "o")     ; overline
  913.               (= (chr char) "u")      ; underline
  914.               (= (chr char) "d")      ; degrees
  915.               (= (chr char) "p")      ; plus/minus
  916.               (= (chr char) " ")      ; space
  917.            )
  918.             (setq pt_rsp (- (pt_ats char nil) 2)
  919.                   strlst (pt_psl str) ; Parse string to list
  920.                   pt_vsp (pt_cll pt_rsp T)
  921.                   pnding nil
  922.             )
  923.           )
  924.           ((is_num (chr char))
  925.             (terpri)
  926.             (if (< pnding 4)
  927.               (setq pt_rsp (pt_ats char nil)
  928.                     pnding (1+ pnding)
  929.                     pt_vsp (pt_cll pt_rsp T)
  930.               )
  931.               (setq pt_rsp (- (pt_ats char nil) (- pnding 2))
  932.                     strlst (pt_psl str) ; Parse string to list
  933.                     pnding nil
  934.                     pt_vsp (pt_cll pt_rsp T)
  935.               )
  936.             )
  937.           )
  938.           (T
  939.             (setq pt_rsp (pt_ats char nil)
  940.                   pt_vsp (pt_cll pt_rsp T)
  941.                   pnding nil
  942.             )
  943.           )
  944.         )
  945.         (setq pt_rsp (pt_ats char nil)
  946.               pt_vsp (pt_cll pt_rsp T)
  947.         )
  948.       )
  949.       (setq return T) ; Return value
  950.     )
  951.   )
  952.   (if (/= char P_RTRN)
  953.     (progn
  954.       ;; set the current string postion (pt_vsp) after allowing for
  955.       ;; various control character codes such as %%d or %%p.
  956.       (setq pt_rsp (pt_cll pt_vsp nil)
  957.             ;; set the string that gets printed on-screen via (entmod).
  958.             pt_str (pt_uls str pt_rsp)
  959.             ;; set the maximum string postion (pt_msp) after allowing for
  960.             ;; various control character codes such as %%d or %%p.
  961.             pt_msp (pt_cll (length strlst) T)
  962.             ;; set the line length up to the current adjusted string position.
  963.             line_l (pt_gll (pt_csl 1 pt_rsp))
  964.       )
  965.     )
  966.   )
  967.   return
  968. )
  969. ;;;
  970. ;;; Get the length of a text line by making a dummy text entity
  971. ;;; on the frozen text layer.  This entity will contain the current
  972. ;;; text string without the underline/overline cursor characters
  973. ;;; up to the current cursor position.
  974. ;;;
  975. ;;; Return the distance between the right and left points of the
  976. ;;; right justified text string.
  977. ;;;
  978. ;;; pt_gll == PText_Get_Line_Length
  979. ;;;
  980. (defun pt_gll (pt_rsp)
  981.   (setq pt_te (subst (cons 1 (pt_sjk 1 pt_rsp)) (assoc 1 pt_te) pt_te))
  982.   (setq pt_te (subst (cons 40 pt_th) (assoc 40 pt_te) pt_te))
  983.   (setq pt_te (subst (cons 41 pt_twf) (assoc 41 pt_te) pt_te))
  984.   (setq pt_te (subst (cons 51 pt_toa) (assoc 51 pt_te) pt_te))
  985.   (setq pt_te (subst (cons 7  pt_stn) (assoc  7 pt_te) pt_te))
  986.   (entmod pt_te)
  987.   (setq pt_te (entget(cdr(assoc -1 pt_te))))
  988.   (distance (cdr(assoc 10 pt_te)) (cdr(assoc 11 pt_te)))
  989. )
  990. ;;;
  991. ;;; Check the string list "strlst" for control characters.  If "diff" is T,
  992. ;;; then return the number of visible characters, else return the number of
  993. ;;; the item in the list which matches the current visual string position.
  994. ;;; N_chars is global to this routine, and specifies how many characters
  995. ;;; to delete if deleting a special symbol.
  996. ;;;
  997. ;;; pt_cll == PText_Check_Line_Length
  998. ;;;
  999. (defun pt_cll (max diff / temp j)
  1000.   (setq temp   0
  1001.         j      0
  1002.         k      0
  1003.         nchars 0  ; global, local to (ptext).
  1004.   )
  1005.   (while (and (< k max) (< j (length strlst)))
  1006.     (cond
  1007.       ((or (= (nth j strlst) "%%o")   ; overline
  1008.            (= (nth j strlst) "%%u"))  ; underline
  1009.         (if diff
  1010.           (setq k (1+ k))
  1011.         )
  1012.         (setq j (1+ j))
  1013.       )
  1014.       (T
  1015.         (setq temp   (1+ temp)        ; diff count
  1016.               nchars (strlen (nth j strlst))
  1017.               j      (1+ j)
  1018.               k      (1+ k)
  1019.         )
  1020.       )
  1021.     )
  1022.   )
  1023.   (if diff (if (> temp 0) temp 1) j)
  1024. )
  1025. ;;;
  1026. ;;; Parse the string "str" into a list of strings, one string for each
  1027. ;;; visual character or control character set.
  1028. ;;; N_chars is global to this routine, and specifies how many characters
  1029. ;;; to delete if deleting a special symbol.
  1030. ;;;
  1031. ;;; pt_psl == PText_Parse_String_to_List
  1032. ;;;
  1033. (defun pt_psl (str / max temp j k tmplst)
  1034.   (setq max  (strlen str)
  1035.         j    1
  1036.         k    0
  1037.         x    1
  1038.         nchars 0  ; global, local to (ptext).
  1039.   )
  1040.   (while (<= j  (strlen str))
  1041.     (if (= (setq temp (substr str j 1)) "%")
  1042.       (progn
  1043.         (if (= (substr str (setq j (1+ j)) 1) "%")
  1044.           (progn
  1045.             (setq j (1+ j))
  1046.             (cond
  1047.               ((= (substr str j 1) " ") ; space
  1048.                 (setq tmplst (if tmplst
  1049.                                (append tmplst (list "%" "%" " "))
  1050.                                (list "%" "%" " ")
  1051.                              )
  1052.                 )
  1053.               )
  1054.               ((or (= (substr str j 1) "%")  ; percent
  1055.                    (= (substr str j 1) "d")  ; degrees
  1056.                    (= (substr str j 1) "p")  ; plus/minus
  1057.                    (= (substr str j 1) "o")  ; overline
  1058.                    (= (substr str j 1) "u")) ; underline
  1059.                 (setq temp   (substr str (- j 2) 3)
  1060.                       j      (1+ j)
  1061.                 )
  1062.               )
  1063.               ((is_num (substr str j 1))
  1064.                 (while (and (< k 3) (is_num (substr str (+ j k) 1)))
  1065.                   (setq k      (1+ k))
  1066.                 )
  1067.                 (setq temp (substr str (- j 2) (+ 2 k))
  1068.                       j    (+ j k)
  1069.                 )
  1070.               )
  1071.               (T
  1072.                 (setq j (1+ j))
  1073.               )
  1074.             )
  1075.             (setq tmplst (if tmplst
  1076.                            (append tmplst (list temp))
  1077.                            (list temp)
  1078.                          )
  1079.             )
  1080.           )
  1081.           (progn
  1082.             (setq tmplst (if tmplst
  1083.                            (append tmplst (list temp))
  1084.                            (list temp)
  1085.                          )
  1086.                   tmplst (append tmplst (list (substr str j 1)))
  1087.                   j      (1+ j)
  1088.             )
  1089.           )
  1090.         )
  1091.       )
  1092.       (progn
  1093.         (setq tmplst (if tmplst
  1094.                        (append tmplst (list temp))
  1095.                        (list temp)
  1096.                      )
  1097.               j      (1+ j)
  1098.         )
  1099.       )
  1100.     )
  1101.   )
  1102.   tmplst
  1103. )
  1104. ;;;
  1105. ;;; Is the character (string) a number...
  1106. ;;;
  1107. ;;;
  1108. (defun is_num (char)
  1109.   (if
  1110.     (or
  1111.       (= char "0") (= char "1") (= char "2") (= char "3") (= char "4")
  1112.       (= char "5") (= char "6") (= char "7") (= char "8") (= char "9")
  1113.     )
  1114.     T
  1115.     nil
  1116.   )
  1117. )
  1118. ;;;
  1119. ;;; Count the number of characters in the list of strings up to the
  1120. ;;; current string position from the starting point.
  1121. ;;;
  1122. ;;; pt_csl == PText_Count_String_Length
  1123. ;;;
  1124. (defun pt_csl (j k / temp)
  1125.   (setq temp 0)
  1126.   (while (and (> j 0) (< j k) (<= j (length strlst)))
  1127.     (setq temp (+ temp (strlen (nth (1- j) strlst)))
  1128.           j    (1+ j)
  1129.     )
  1130.   )
  1131.   temp
  1132. )
  1133. ;;;
  1134. ;;; Get the real string position of the next visual character to the
  1135. ;;; left of the current cursor posistion.
  1136. ;;;
  1137. ;;; pt_gpl == PText_Get_next_start_Position_Left
  1138. ;;;
  1139. (defun pt_gpl (temp)
  1140.   (setq j (pt_cll temp T))
  1141.   (while (and (> temp 0) (= j (setq k (pt_cll temp T))))
  1142.     (setq temp (1- temp))
  1143.   )
  1144.   k
  1145. )
  1146. ;;;
  1147. ;;; Get the real string position of the next visual character to the
  1148. ;;; right of the current cursor posistion.
  1149. ;;;
  1150. ;;; pt_gpr == PText_Get_next_start_Position_Right
  1151. ;;;
  1152. (defun pt_gpr (temp)
  1153.   (pt_cll temp nil)
  1154. )
  1155. ;;;
  1156. ;;; Strcat from the list "strlst" from "j" position to "k" position.
  1157. ;;; Return the string or "".
  1158. ;;;
  1159. ;;; pt_sjk == PText_Strcat_from_J_to_K
  1160. ;;;
  1161. (defun pt_sjk (j k / temp)
  1162.   (setq temp 0
  1163.         l    0
  1164.   )
  1165.   (if (and (<= j (length strlst)) (<= j k))
  1166.     (progn
  1167.       (while (< temp (+ j l))
  1168.         (if (or (= (nth temp strlst) "%%o")  ; overline
  1169.                 (= (nth temp strlst) "%%u")) ; underline
  1170.             (setq l (1+ l))
  1171.         )
  1172.         (setq temp (1+ temp))
  1173.       )
  1174.       (setq temp "")
  1175.       (while (and (<= (+ j l) (length strlst)) (<= j k))
  1176.         (setq temp (strcat temp (nth (1- (+ j l)) strlst)))
  1177.         (if (or (= (nth (1- (+ j l)) strlst) "%%o")  ; overline
  1178.                 (= (nth (1- (+ j l)) strlst) "%%u")) ; underline
  1179.             (setq k (1+ k))
  1180.         )
  1181.         (setq j (1+ j))
  1182.       )
  1183.     )
  1184.     (setq temp "")
  1185.   )
  1186.   temp
  1187. )
  1188.  
  1189. ;;;
  1190. ;;; Move the cursor the direction "dir" and if the second argument is T,
  1191. ;;; then erase the character under the new cursor location.
  1192. ;;;
  1193. ;;; pt_mc == PText_Move_Cursor
  1194. ;;;
  1195. (defun pt_mc (dir dstrct)
  1196.   (cond
  1197.     ((= dir "LEFT")
  1198.       (if dstrct                      ; deleting text
  1199.         (if (> pt_vsp 1)              ; if not at the beginning of a line
  1200.           ;; subtract one visual character from the current position.
  1201.           (progn
  1202.             (setq pt_vsp (1- pt_vsp)
  1203.                   pt_rsp (pt_cll pt_vsp nil)
  1204.                   str    (strcat
  1205.                            (pt_sjk 1 (- pt_vsp 1))
  1206.                            (pt_sjk (1+ pt_vsp) pt_msp)
  1207.                          )
  1208.                   strlst (pt_psl str) ; Parse string to list
  1209.             )
  1210.             (repeat 5
  1211.               (princ (chr P_BACK))
  1212.               (princ (chr P_SPCE))
  1213.               (princ (chr P_BACK))
  1214.             )
  1215.           )
  1216.           (progn                      ; AT the beginning of the text line...
  1217.             (if (> pt_cl 1)           ; if not at the first line...
  1218.               (pt_dal T)              ; back up a line, destructive
  1219.             )
  1220.           )
  1221.         )
  1222.         (if (> pt_vsp 1)              ; NOT deleting text...
  1223.           (setq pt_vsp (1- pt_vsp)
  1224.                 pt_rsp (pt_gpl pt_vsp)
  1225.           )
  1226.           (if (> pt_cl 1)             ; if not at the first line...
  1227.             (pt_dal nil)              ; back up a line, non-destructive
  1228.           )
  1229.         )
  1230.       )
  1231.     )
  1232.     ((= dir "RIGHT")
  1233.       (if dstrct                      ; overwriting text
  1234.         (if (< pt_vsp pt_msp)         ; if not at the end of a line
  1235.           (setq pt_vsp (1+ pt_vsp)
  1236.                 pt_rsp (pt_gpr pt_vsp)
  1237.                 str    (strcat
  1238.                          (pt_sjk 1 (- pt_rsp 2))
  1239.                          " "
  1240.                          (pt_sjk pt_rsp pt_msp)
  1241.                        )
  1242.                 strlst (pt_psl str)   ; Parse string to list
  1243.           )
  1244.         )
  1245.       )
  1246.       (if (< pt_vsp pt_msp)           ; NOT deleting text and ...
  1247.                                       ; NOT at the end of a line...
  1248.         (setq pt_vsp (1+ pt_vsp)
  1249.               pt_rsp (pt_gpr pt_vsp)
  1250.         )
  1251.         ;; else
  1252.         (if (< pt_cl (length TX:LST)) ; AT the end of a line...
  1253.           ;; If not at the last line in the edit list...
  1254.           (progn
  1255.             ;; Modify the current entity to remove the cursor.
  1256.             (entmod (subst (cons 1 str) (assoc 1 ent) ent))
  1257.             (setq pt_cl  (1+ pt_cl)   ; add one to current line counter
  1258.                   ;; get the ename from TX:LST for the new current line.
  1259.                   ent    (entget(nth (1- pt_cl) TX:LST))
  1260.                   ;; get the string in ent
  1261.                   str    (cdr(assoc 1 ent))
  1262.                   strlst (pt_psl str) ; Parse string to list
  1263.                   ;; Actual under-line postion checked in (get_ch)
  1264.                   pt_vsp 1
  1265.             )
  1266.           )
  1267.           ;; Else do nothing.
  1268.         )
  1269.       )
  1270.     )
  1271.     ((= dir "HOME")
  1272.       ;; Actual under-line postion checked in (get_ch)
  1273.       (setq pt_vsp 1)
  1274.     )
  1275.     ((= dir "END")
  1276.       ;; Actual under-line postion checked in (get_ch)
  1277.       (setq pt_vsp pt_msp)
  1278.     )
  1279.     ((= dir "TOP")
  1280.       (entmod (subst (cons 1 str) (assoc 1 ent) ent))
  1281.       (setq pt_cl  1
  1282.             ent    (entget(nth 0 TX:LST))
  1283.             str    (cdr(assoc 1 ent))
  1284.             strlst (pt_psl str)       ; Parse string to list
  1285.             ;; Actual under-line postion checked in (get_ch)
  1286.             pt_vsp 1
  1287.       )
  1288.     )
  1289.     ((= dir "BOTTOM")
  1290.       (entmod (subst (cons 1 str) (assoc 1 ent) ent))
  1291.       (setq pt_cl  (length TX:LST)
  1292.             ent    (entget(last TX:LST))
  1293.             str    (cdr(assoc 1 ent))
  1294.             strlst (pt_psl str)       ; Parse string to list
  1295.             ;; Actual under-line postion checked in (get_ch)
  1296.             pt_vsp pt_msp
  1297.       )
  1298.       (terpri)
  1299.     )
  1300.     ((= dir "DEL")
  1301.       (if (< pt_vsp pt_msp)           ; if not at the end of the line...
  1302.         (progn
  1303.           (setq temp (strlen str)
  1304.                 str    (strcat
  1305.                          (pt_sjk 1 (1- pt_rsp))
  1306.                          (pt_sjk (1+ pt_rsp) pt_msp)
  1307.                        )
  1308.                 strlst (pt_psl str)                ; Parse string to list
  1309.           )
  1310.           (repeat (1+ (- temp (strlen str)))
  1311.             (princ (chr P_BACK))
  1312.             (princ (chr P_SPCE))
  1313.             (princ (chr P_BACK))
  1314.           )
  1315.         )
  1316.         ;; else, at the last character in the line...
  1317.         (if (= (substr str pt_rsp 1) " ") ; if it is a blank...
  1318.           (pt_bul (1+ pt_cl))         ; Bring up lines following this line.
  1319.           ;; else, replace the current character with a space.
  1320.           (setq str    (strcat (pt_sjk 1 (1- pt_rsp)) " ")
  1321.                 strlst (pt_psl str)   ; Parse string to list
  1322.                 pt_spt (polar pt_spt (+ pt_ra (/ pi 2)) pt_ils)
  1323.           )
  1324.         )
  1325.       )
  1326.     )
  1327.     ((= dir "UP")
  1328.       (if (and TX:LST (> pt_cl 1))    ; Never let pt_cl below 1.
  1329.         (progn
  1330.           (entmod (subst (cons 1 str) (assoc 1 ent) ent))
  1331.           (setq pt_cl  (1- pt_cl)
  1332.                 ent    (entget(nth (1- pt_cl) TX:LST))
  1333.                 str    (cdr(assoc 1 ent))
  1334.                 strlst (pt_psl str)   ; Parse string to list
  1335.                 tvsp   (length strlst)
  1336.           )
  1337.           (if (< tvsp pt_vsp) (setq pt_vsp tvsp))
  1338.           (terpri)
  1339.         )
  1340.       )
  1341.     )
  1342.     ((= dir "DOWN")
  1343.       (if (and TX:LST (< pt_cl (length TX:LST)))
  1344.         (progn
  1345.           (entmod (subst (cons 1 str) (assoc 1 ent) ent))
  1346.           (setq pt_cl  (1+ pt_cl)
  1347.                 ent    (entget(nth (1- pt_cl) TX:LST))
  1348.                 str    (cdr(assoc 1 ent))
  1349.                 strlst (pt_psl str)   ; Parse string to list
  1350.                 tvsp   (length strlst)
  1351.           )
  1352.           (if (< tvsp pt_vsp) (setq pt_vsp tvsp))
  1353.           (terpri)
  1354.         )
  1355.       )
  1356.     )
  1357.   )
  1358.   (princ "\rñσªr: ")
  1359.   (princ str)
  1360.   pt_rsp
  1361. )
  1362. ;;;
  1363. ;;; Bring up lines of text when deleting at the end of a line of text.
  1364. ;;;
  1365. ;;; pt_bul == PText_Bring_Up_Lines
  1366. ;;;
  1367. (defun pt_bul (line)
  1368.   (if (< pt_cl (length TX:LST))
  1369.     (progn
  1370.       (setq str  (strcat
  1371.                    (substr str 1 (- pt_rsp 1))
  1372.                    (cdr(assoc 1 (entget (nth pt_cl TX:LST))))
  1373.                  )
  1374.             strlst (pt_psl str)       ; Parse string to list
  1375.             sset (ssadd)
  1376.             j    pt_cl
  1377.       )
  1378.       (entdel (nth pt_cl TX:LST))
  1379.       (setq TX:LST (pt_sil line TX:LST))
  1380.       (while (< j (length TX:LST))
  1381.         (ssadd (nth j TX:LST) sset)
  1382.         (setq j (1+ j))
  1383.       )
  1384.       (if (> (sslength sset) 0)
  1385.         (command "_.MOVE"
  1386.                  sset
  1387.                  ""
  1388.                  pt_spt
  1389.                  (polar pt_spt (+ pt_ra (/ pi 2)) pt_ils)
  1390.         )
  1391.       )
  1392.     )
  1393.   )
  1394.   ;; Else, do nothing.
  1395. )
  1396. ;;;
  1397. ;;; Strip the item from the list of enames in TX:LST.
  1398. ;;;
  1399. ;;; pt_sil == PText_Strip_Item_from_List
  1400. ;;;
  1401. (defun pt_sil (temp lst / j k tmplst)
  1402.   (setq j   0
  1403.         k   (length lst)
  1404.   )
  1405.   (while (< j k)
  1406.     (if (= j (1- temp))
  1407.       (setq j (1+ j))                 ; Skip the entry...
  1408.       ;; else
  1409.       (setq tmplst (if tmplst
  1410.                      (append tmplst (list (nth j lst)))
  1411.                      (list (nth j lst))
  1412.                    )
  1413.             j      (1+ j)
  1414.       )
  1415.     )
  1416.   )
  1417.   tmplst
  1418. )
  1419. ;;;
  1420. ;;; Add the entity name to the list of enames in TX:LST.
  1421. ;;; TX:LST must have at least one member.
  1422. ;;;
  1423. ;;; pt_ael == PText_Add_Ename_to_List
  1424. ;;;
  1425. (defun pt_ael (ename temp lst / j k tmplst)
  1426.   (setq j   0
  1427.         k   (length lst)
  1428.   )
  1429.   (while (< j k)
  1430.     (setq tmplst (if tmplst
  1431.                    (append tmplst (list (nth j lst)))
  1432.                    (list (nth j lst))
  1433.                  )
  1434.           j      (1+ j)
  1435.     )
  1436.     (if (= j (1- temp))
  1437.       (setq tmplst (append tmplst (list ename)))
  1438.     )
  1439.   )
  1440.   tmplst
  1441. )
  1442. ;;;
  1443. ;;; Add the item (ename) to the list (lst).
  1444. ;;;
  1445. ;;; pt_ail == PText_Add_Item_to_List
  1446. ;;;
  1447. (defun pt_ail (ename temp lst / j k tmplst)
  1448.   (setq j   0
  1449.         k   (length lst)
  1450.   )
  1451.   (while (< j k)
  1452.     (if (= j temp)
  1453.       (setq tmplst (if tmplst
  1454.                      (append tmplst (list ename))
  1455.                      (list ename)
  1456.                    )
  1457.             temp   nil
  1458.       )
  1459.     )
  1460.     (setq tmplst (if tmplst
  1461.                    (append tmplst (list (nth j lst)))
  1462.                    (list (nth j lst))
  1463.                  )
  1464.           j      (1+ j)
  1465.     )
  1466.   )
  1467.   (if temp (setq tmplst (if tmplst
  1468.                           (append tmplst (list ename))
  1469.                           (list ename)
  1470.                         )
  1471.            )
  1472.   )
  1473.   tmplst
  1474. )
  1475. ;;;
  1476. ;;; Add a character to a string
  1477. ;;;
  1478. ;;; pt_ats == PText_Add_char_To_String
  1479. ;;;
  1480. (defun pt_ats (char appnd)
  1481.   ;; Add item (chr char) to list "strlst".
  1482.   (setq strlst (pt_ail (chr char) (if appnd pt_rsp (1- pt_rsp)) strlst))
  1483.   (if insert
  1484.     (progn
  1485.       (if (not appnd) (setq pt_vsp (1+ pt_vsp)))
  1486.       (setq pt_msp (1+ pt_msp))
  1487.     )
  1488.   )
  1489.   ;; If overwriting...
  1490.   (if (null insert)
  1491.     ;; Subtract item "pt_rsp" from list "strlst".
  1492.     (if (< pt_rsp pt_msp) (setq strlst (pt_sil pt_rsp strlst)))
  1493.   )
  1494.   (setq str    (pt_sjk 1 (length strlst)))
  1495.   (princ "\rñσªr: ")
  1496.   (princ str)
  1497.   (1+ pt_rsp)
  1498. )
  1499. ;;;
  1500. ;;; Process a newline character
  1501. ;;;
  1502. ;;; pt_pnl == PText_Process_NewLine
  1503. ;;;
  1504. (defun pt_pnl (/ sset j)
  1505.   (if ent ; There should (!) always be an entity at this point...
  1506.     (progn
  1507.       ;; Get the correct "start point" for the current type of text entity...
  1508.       ;; This should correctly handle mixed text justification types.
  1509.       (setq pt_spt (cdr(assoc (if (or (= grp_72 2) ; Right justified
  1510.                                       (= grp_72 1) ; Left justified
  1511.                                   ) 11 10) ent))
  1512.             pt_spt (polar pt_spt (- pt_ra (/ pi 2)) pt_ils)
  1513.       )
  1514.       (if (= grp_72 5)                ; if Fit text
  1515.         (setq pt_rpt (cdr(assoc 11 ent))
  1516.               pt_rpt (polar pt_rpt (- pt_ra (/ pi 2)) pt_ils)
  1517.          )
  1518.       )
  1519.       (setq ent (subst (cons 1 (substr str 1 (1- pt_rsp))) (assoc 1 ent) ent))
  1520.       (if (= (cdr(assoc 1 ent)) "")
  1521.         (setq ent (subst (cons 1 " ") (assoc 1 ent) ent))
  1522.       )
  1523.       (entmod ent)
  1524.       ;; Null line at end of paragraph...
  1525.       (if (and (= pt_cl (length tx:lst)) (= str " "))
  1526.         (setq str "")                 ; Exit from routine.
  1527.         ;; else
  1528.         (progn
  1529.           (setq str (substr str pt_rsp)   ; The balance of the string.
  1530.                 sl     (strlen str)
  1531.                 pt_tsp (pt_cll sl nil)
  1532.                 pt_str (pt_uls str pt_tsp)
  1533.                 sset   (ssadd)
  1534.                 j      pt_cl
  1535.           )
  1536.           (while (< j (length TX:LST))
  1537.             (ssadd (nth j TX:LST) sset)
  1538.             (setq j (1+ j))
  1539.           )
  1540.           (if (> (sslength sset) 0)
  1541.             (command "_.MOVE"
  1542.                      sset
  1543.                      ""
  1544.                      pt_spt
  1545.                      (polar pt_spt (- pt_ra (/ pi 2)) pt_ils)
  1546.             )
  1547.           )
  1548.         )
  1549.       )
  1550.       (setq ent nil)
  1551.       (setq sl 0)
  1552.     )
  1553.     (progn
  1554.       (princ "\n│B▓z╖sªCñσªr┤┴╢í╣Jª│┐∙╗~íC")
  1555.       (exit)
  1556.     )
  1557.   )
  1558. )
  1559. ;;;
  1560. ;;; Process line
  1561. ;;;
  1562. ;;; pt_pl == PText_Process_Line
  1563. ;;;
  1564. (defun pt_pl ()
  1565.   (if ent                             ; Modify the text string
  1566.     (entmod (setq ent (subst (cons 1 pt_str) (assoc 1 ent) ent)))
  1567.     ;; else
  1568.     (progn
  1569.       (dr_txt pt_str)                 ; Draw the text string
  1570.       (setq TX:LST (if TX:LST
  1571.                      (pt_ael (cdr(assoc -1 ent)) pt_cl TX:LST)
  1572.                      (list (cdr(assoc -1 ent)))
  1573.                    )
  1574.       )
  1575.     )
  1576.   )
  1577. )
  1578. ;;;
  1579. ;;; Get the maximum string position allowed on a line given the
  1580. ;;; current contents of the variable "str".  Uses (pt_gll).
  1581. ;;;
  1582. ;;; pt_gmp == PText_Get_Maximum_string_Position
  1583. ;;;
  1584. (defun pt_gmp (/ temp)
  1585.   ;; Get a temporary projected number of characters allowed on a line.
  1586.   ;; Check this against the actual line length of the real characters,
  1587.   ;; adding one character until either the end of the string is reached
  1588.   ;; or the maximum line length is reached.  Then start subtracting
  1589.   ;; characters until either a space or hypen is found, or the start of
  1590.   ;; the string is reached.  If the start of the string is reached, then
  1591.   ;; search forward on the string looking for the end of the word.  If
  1592.   ;; the end of the word is not found then return 1, else return the
  1593.   ;; wrap position on the line.
  1594.  
  1595.   (setq temp (round (/ pt_mll (* 0.8 pt_twf pt_th))))
  1596.   (while (and (< temp pt_rsp) (< (pt_gll temp) pt_mll))
  1597.     (setq temp (1+ temp))
  1598.   )
  1599.   (while (> (pt_gll temp) pt_mll)
  1600.     (setq temp (1- temp))
  1601.   )
  1602.   (while (and (> temp 1)
  1603.               (/= (nth (1- temp) strlst) " ") ; Back up until a space
  1604.               (/= (nth (1- temp) strlst) "-") ; or hyphen is found...
  1605.          )
  1606.     (setq temp (1- temp))
  1607.   )
  1608.   (if (= temp 1)
  1609.     (progn
  1610.       (setq temp (round (/ pt_mll (* 0.8 pt_twf pt_th))))
  1611.       (while (and (< temp pt_rsp)
  1612.                   (/= (nth (1- temp) strlst) " ") ; Back up until a space
  1613.                   (/= (nth (1- temp) strlst) "-") ; or hyphen is found...
  1614.              )
  1615.         (setq temp (1+ temp))
  1616.       )
  1617.     )
  1618.   )
  1619.   (if (= temp pt_rsp)
  1620.     1
  1621.     temp
  1622.   )
  1623. )
  1624. ;;;
  1625. ;;; Wrap the line at the end of the previous word, if there is one.
  1626. ;;; Otherwise, if the line is short and/or the word is long enough
  1627. ;;; to occupy the entire line length, then extend the word.
  1628. ;;;
  1629. ;;; pt_waw == PText_Wrap_At_Word
  1630. ;;;
  1631. (defun pt_waw (/ temp)
  1632.   (setq temp (pt_gmp))                ; Get the maximum string position.
  1633.  
  1634.   (if (= grp_72 5)                    ; Fit text...
  1635.     ;; Set up to test if we are within the last 1/4 of the word,
  1636.     ;; and if so, we will cram the whole word on the line.
  1637.     (progn
  1638.       (setq line_l (* 0.9
  1639.                       pt_twf
  1640.                       pt_th
  1641.                       (- pt_rsp (* (- pt_rsp temp) 0.25)))
  1642.       )
  1643.     )
  1644.     ;; Else, set a dummy value large enough to trip the next test.
  1645.     (setq line_l (* 2 line_l))
  1646.   )
  1647.   (pt_cll temp T) ; Return the visual string position.
  1648. )
  1649. ;;;
  1650. ;;; Process word wrap.
  1651. ;;;
  1652. ;;; pt_pww == PText_Process_Word_Wrap
  1653. ;;;
  1654. (defun pt_pww (loc / sset j)
  1655.   ;; Not at the start of a line and line is longer than  maximum specified...
  1656.   (if (and (> loc 1) (> line_l pt_mll))
  1657.     ;; Wrapping a text line...
  1658.     (progn
  1659.       (pt_pee) ; Process existing entity
  1660.  
  1661.       (pt_mne) ; Make the new text line here...
  1662.     )
  1663.     ;; Extending a text line...
  1664.     (progn
  1665.  
  1666.       ;; set the string that gets printed on-screen via (entmod).
  1667.       (setq pt_str (pt_uls str pt_rsp))
  1668.       (setq ent (subst (cons 1 pt_str) (assoc 1 ent) ent))
  1669.       (entmod ent)
  1670.     )
  1671.   )
  1672. )
  1673. ;;;
  1674. ;;; Process the existing string, entmoding it to its final form.
  1675. ;;;
  1676. ;;; pt_pee == PText_Process_Existing_Entity
  1677. ;;;
  1678. (defun pt_pee ()
  1679.   (repeat (- (pt_cll pt_msp nil) loc) (princ (chr P_BACK))
  1680.                                       (princ (chr P_SPCE))
  1681.                                       (princ (chr P_BACK))
  1682.   )
  1683.   (princ "\rñσªr: ")
  1684.   ;; Strip trailing space.
  1685.   (while (= (nth (1- loc) strlst) " ") (setq loc (1- loc)))
  1686.   (setq ent    (subst
  1687.                  (cons 1 (princ (pt_sjk 1 loc))) ; print the string
  1688.                  (assoc 1 ent)
  1689.                  ent
  1690.                )
  1691.         pt_cl  (1+ pt_cl)
  1692.         pt_spt (cdr(assoc (if (or (= grp_72 2)
  1693.                                   (= grp_72 1)) 11 10) ent))
  1694.         str    (pt_sjk (+ loc 2)  (length strlst))
  1695.         strlst (pt_psl str)           ; Parse string to list
  1696.         pt_msp (pt_cll (length strlst) T) ; Check line length
  1697.         pt_vsp (pt_cll (- pt_rsp loc 1) T)
  1698.         pt_rsp (pt_cll pt_vsp nil)    ; Get character position/size
  1699.   )
  1700.   (if (< pt_vsp 1) (setq pt_vsp 1))
  1701.   (entmod ent)
  1702. )
  1703. ;;;
  1704. ;;; Make a new entity after a word wrap.
  1705. ;;;
  1706. ;;; pt_mne == PText_Make_New_Entity
  1707. ;;;
  1708. (defun pt_mne ()
  1709.   (princ "\nñσªr: ")
  1710.   (princ str)
  1711.   ;; set the string that gets printed on-screen via (entmod).
  1712.   (setq pt_str (pt_uls str pt_rsp))
  1713.  
  1714.   (if (<= pt_cl (length TX:LST))
  1715.     (progn
  1716.       (setq pt_spt (cdr(assoc (if (or (= grp_72 2)
  1717.                                       (= grp_72 1)) 11 10) ent))
  1718.       )
  1719.       (if (= grp_72 5)                ; if Fit text
  1720.         (setq pt_rpt (cdr(assoc 11 ent))
  1721.               pt_rpt (polar pt_rpt (- pt_ra (/ pi 2)) pt_ils)
  1722.         )
  1723.       )
  1724.     )
  1725.     ;; else
  1726.     (princ)
  1727.   )
  1728.  
  1729.   (pt_fww)
  1730.  
  1731.   (setq pt_spt (polar pt_spt (- pt_ra (/ pi 2)) pt_ils))
  1732.   (dr_txt pt_str)                     ; Draw the text string
  1733.   (setq TX:LST (if TX:LST
  1734.                  (pt_ael (cdr(assoc -1 ent)) pt_cl TX:LST)
  1735.                  (list (cdr(assoc -1 ent)))
  1736.                )
  1737.   )
  1738. )
  1739. ;;;
  1740. ;;; Finish up a word wrap; get ready for the next character.
  1741. ;;; Move any entities that may follow down by one space.
  1742. ;;;
  1743. ;;; pt_fww == PText_Finish_Word_wrap
  1744. ;;;
  1745. (defun pt_fww ()
  1746.   (setq sset   (ssadd)
  1747.         j      (1- pt_cl)
  1748.   )
  1749.   (while (< j (length TX:LST))
  1750.     (ssadd (nth j TX:LST) sset)
  1751.     (setq j (1+ j))
  1752.   )
  1753.   (if (> (sslength sset) 0)
  1754.     (command "_.MOVE"
  1755.              sset
  1756.              ""
  1757.              pt_spt
  1758.              (polar pt_spt (- pt_ra (/ pi 2)) pt_ils)
  1759.     )
  1760.   )
  1761. )
  1762. ;;;
  1763. ;;; Delete a line and back up to the previous one
  1764. ;;;
  1765. ;;; pt_dal == PText_Delete_A_Line
  1766. ;;;
  1767. (defun pt_dal (temp / )
  1768.   ;; Remove last ename if at the maximum string position discounting
  1769.   ;; control characters.  Both should be 1.
  1770.   (if (= pt_vsp pt_msp)
  1771.     (if temp
  1772.       (progn
  1773.         (repeat (1+ (strlen str))
  1774.           (princ (chr P_BACK))
  1775.           (princ (chr P_SPCE))
  1776.           (princ (chr P_BACK))
  1777.         )
  1778.         (princ "* ºR░ú *")
  1779.       )
  1780.       (progn
  1781.         (entmod (subst (cons 1 str) (assoc 1 ent) ent))
  1782.         (setq str "")
  1783.       )
  1784.     )
  1785.     (entmod (subst (cons 1 str) (assoc 1 ent) ent))
  1786.   )
  1787.   (terpri)
  1788.   (setq pt_cl (1- pt_cl)
  1789.         ent   (if (and (> pt_cl 0) (> (length TX:LST) 0))
  1790.                 (entget (nth (1- pt_cl) TX:LST))
  1791.                 nil
  1792.               )
  1793.   )
  1794.   (if ent
  1795.     (progn
  1796.       (if temp
  1797.         (progn
  1798.           (pt_bul (1+ pt_cl))        ; Bring up lines following this line.
  1799.           (setq st     (pt_psl (cdr(assoc 1 ent)))
  1800.                 str    (strcat (cdr(assoc 1 ent)) str)
  1801.           )
  1802.         )
  1803.         (setq str    (cdr(assoc 1 ent)))
  1804.       )
  1805.       (setq strlst (pt_psl str)
  1806.             pt_vsp (1+ (pt_cll (length st) nil))
  1807.             pt_msp (pt_cll (length strlst) T)
  1808.             pt_spt (polar pt_spt (+ pt_ra (/ pi 2)) pt_ils)
  1809.       )
  1810.       (princ str)
  1811.       (if (= grp_72 5)
  1812.         (setq pt_rpt (polar pt_rpt (+ pt_ra (/ pi 2)) pt_ils))
  1813.       )
  1814.     )
  1815.     (progn
  1816.       (setq TX:LST nil
  1817.             ent    nil
  1818.       )
  1819.     )
  1820.   )
  1821. )
  1822. ;;;
  1823. ;;; Draw each text item
  1824. ;;;
  1825. ;;;
  1826. (defun dr_txt (str / j)
  1827.   (setq j (* pt_ra (/ 180 pi)))       ; rotation angle in decimal degrees.
  1828.   (cond
  1829.     ((= grp_72 0) (command "_.TEXT" pt_spt pt_th j str))
  1830.     ((= grp_72 1) (command "_.TEXT" "_C" pt_spt pt_th j str))
  1831.     ((= grp_72 2) (command "_.TEXT" "_R" pt_spt pt_th j str))
  1832.     ((= grp_72 5) (command "_.TEXT" "_F" pt_spt pt_rpt pt_th str))
  1833.   )
  1834.   (setq ent (entget(entlast)))
  1835.   (setq pt_spt (cdr(assoc (if (or (= grp_72 2) (= grp_72 1)) 11 10) ent)))
  1836.   (setq pt_spt (polar pt_spt (- pt_ra (/ pi 2)) pt_ils))
  1837.   (if (= grp_72 5)
  1838.     (setq pt_rpt (polar pt_rpt (- pt_ra (/ pi 2)) pt_ils))
  1839.   )
  1840.   ent
  1841. )
  1842.  
  1843. ;;;
  1844. ;;; Round a number off to the nearest integer correctly
  1845. ;;;
  1846. ;;;
  1847. (defun round (num)
  1848.   (if (>= (- num (fix num)) 0.5)
  1849.     (fix (1+ num))
  1850.     (fix num)
  1851.   )
  1852. )
  1853. ;;; ------------------ Cut here ----------------------------------
  1854. ;;;
  1855. ;;; C: function definition.
  1856. ;;;
  1857. (defun c:pt () (ptext))
  1858. (defun c:ptext () (ptext))
  1859. (princ "\n\tíuC:PTextívñw╕ⁿñJ; ╜╨ÑH PT ⌐╬ PTEXT ▒╥░╩½ⁿÑOíC")
  1860. (princ)
  1861.