明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4139|回复: 12

图像控件绘制文本字符的工具

  [复制链接]
发表于 2009-11-28 14:26:00 | 显示全部楼层 |阅读模式

给大家介绍一个在对话框图像控件上绘制矢量文本的工具

用法:首先加载vector_text.VLX(或vector_text.fas);

然后在你的程序中调用函数:vector_text

;-------------------------------------------------------------------------------
; vector_text - 在对话框图像控件中绘制文本
; 参数数量: 6
;   Justify$ = 文本对齐方式:"L" "ML" "TL" "C" "M" "TC" "R" "MR"  "TR"
;   X# =起点的X;   Y# = 起点的 Y;   Rotation# =旋转角度0或90(只有这两种)
;   Color# = 颜色号0到255
;   TextStr$ = 要绘制的文本字符(不支持中文)
; 返回值:对话框图像控件中绘制文本;

; 例如: (vector_text "M" 110 25 0 5 "Hello World")
;-------------------------------------------------------------------------------

 

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
"觉得好,就打赏"
还没有人打赏,支持一下
 楼主| 发表于 2009-11-28 14:34:00 | 显示全部楼层
实例
  1. (defun c:vector_text (/ Dcl_Id% Show_Image:)
  2.   (defun Show_vector_text (str)
  3.     (start_image "Image1")
  4.     (fill_image 30 23 156 178 -2)
  5.     (vector_text "M" 107 154 0 2 str)
  6.     (end_image)
  7.   )
  8.   (setq Dcl_Id% (load_dialog "vector_text.dcl"))
  9.   (new_dialog "vector_text" Dcl_Id%)
  10.   ; Set Dialog Initial Settings
  11.   (set_tile "Title" "文本矢量")
  12.   (set_tile "Edit1" "12.5")
  13.   (set_tile "Text1" "按回车改变显示")
  14.   (start_image "Image1")
  15.   (fill_image 30 23 156 178 -2)
  16.   (vector_text "M" 107 154 0 2 "12.5")
  17.   (end_image)
  18.   
  19.   ; Dialog Actions
  20.   (action_tile "Edit1" "(Show_vector_text $value)")
  21.   (start_dialog)
  22.   ; Unload Dialog
  23.   (unload_dialog Dcl_Id%)
  24.   (princ)
  25. )
dcl代码
  1. //---------------------------------------------------------------------------------------------------------
  2. // vector_text
  3. //---------------------------------------------------------------------------------------------------------
  4. vector_text : dialog {
  5.   key = "Title";
  6.   label = "";//Title$ from lsp file
  7.   spacer;
  8.   : image_button {
  9.     key = "Image1";
  10.     width = 35.92;
  11.     height = 16.59;
  12.     fixed_width = true;
  13.     fixed_height = true;
  14.     aspect_ratio = 1;
  15.     color = -2;
  16.   }
  17. : edit_box {
  18.       label = "输入字符串";
  19.       key = "Edit1";
  20.       edit_width = 20;
  21.       fixed_width = true;
  22.     }
  23.   : text {
  24.     key = "Text1";
  25.     label = "";
  26.     width = 23.42;
  27.     fixed_width = true;
  28.     alignment = centered;
  29.   }
  30.   ok_only;
  31. }//
 楼主| 发表于 2009-11-28 14:42:00 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2009-11-30 10:33:00 | 显示全部楼层
楼主,做一个支持中文的吧
明经网友  发表于 2009-12-16 11:02:00

为什么我运行时出错?

; 错误: no function definition: VECTOR_TEXT
回复 支持 反对

使用道具

发表于 2011-5-23 09:47:52 | 显示全部楼层
; vector_text - Draws text in a dialog image tile
; Arguments: 6
;   Justify$ = Justification option of "L" "ML" "TL" "C" "M" "TC" "R" "MR" or "TR"
;   X# = Starting X location
;   Y# = Starting Y location
;   Rotation# = Rotation angle of 0 or 90
;   Color# = Color number of text ranging from 0 to 255
;   TextStr$ = Text string to draw
; Returns: Draws text string in a dialog image tile
; Note: Use this function between a start_image and an end_image command.
; Example: (vector_text "M" 110 25 0 5 "Hello World")
;-------------------------------------------------------------------------------
(defun vector_text (Justify$ X# Y# Rotation# Color# TextStr$ / ChrList@ FontList@
  Item Num# Width# XY# X1# X2# Y1# Y2#)
  (setq Justify$ (strcase Justify$))
  (if (not (member Justify$ (list "L" "ML" "TL" "C" "M" "TC" "R" "MR" "TR")))
    (progn (princ "\nvector_text syntax error:\nJustification options are L, ML, TL, C, M, TC, R, MR, and TR.")(exit))
  );if
  (if (and (< Color# 0)(> Color# 255))
    (progn (princ "\nvector_text syntax error:\nColor value ranges between 0 and 255.")(exit))
  );if
  (if (or (< X# 0)(< Y# 0))
    (progn (princ "\nvector_text syntax error:\nValues for X and Y must be a positive number.")(exit))
  );if
  (if (not (or (= Rotation# 0)(= Rotation# 90)))
    (progn (princ "\nvector_text syntax error:\nRotation angle can only be 0 or 90 degrees.")(exit))
  );if
  (setq FontList@ (GetFontList TextStr$))
  (setq Width# 0)
  (if (= Rotation# 0)
    (progn
      (if (member Justify$ (list "TL" "TC" "TR"))
        (setq Y# (1- Y#))
      );if
      (if (member Justify$ (list "ML" "M" "MR"))
        (setq Y# (- Y# 5))
      );if
      (if (member Justify$ (list "L" "C" "R"))
        (setq Y# (- Y# 9))
      );if
      (foreach Item FontList@
        (setq Width# (+ Width# (nth 0 Item)))
      );foreach
      (if (member Justify$ (list "C" "M" "TC"))
        (setq X# (- X# (fix (+ (/ Width# 2.0) 0.5))))
      );if
      (if (member Justify$ (list "R" "MR" "TR"))
        (setq X# (- X# Width#))
      );if
      (foreach ChrList@ FontList@
        (setq Num# 1)
        (while (< Num# (length ChrList@))
          (setq XY# (nth Num# ChrList@)
                X1# (+ X# (nth Num# ChrList@))
                Y1# (+ Y# (nth (1+ Num#) ChrList@))
                X2# (+ X# (nth (+ Num# 2) ChrList@))
                Y2# (+ Y# (nth (+ Num# 3) ChrList@))
          );setq
          (if (and (/= XY# -1)(> X1# -1)(> Y1# -1)(> X2# -1)(> Y2# -1))
            (vector_image X1# Y1# X2# Y2# Color#)
          );if
          (setq Num# (+ Num# 4))
        );while
        (setq X# (+ X# (nth 0 ChrList@)))
      );foreach
    );progn
    (progn
      (if (member Justify$ (list "TL" "TC" "TR"))
        (setq X# (1- X#))
      );if
      (if (member Justify$ (list "ML" "M" "MR"))
        (setq X# (- X# 5))
      );if
      (if (member Justify$ (list "L" "C" "R"))
        (setq X# (- X# 9))
      );if
      (foreach Item FontList@
        (setq Width# (+ Width# (nth 0 Item)))
      );foreach
      (if (member Justify$ (list "C" "M" "TC"))
        (setq Y# (+ Y# (fix (+ (/ Width# 2.0) 0.5))))
      );if
      (if (member Justify$ (list "R" "MR" "TR"))
        (setq Y# (+ Y# Width#))
      );if
      (foreach ChrList@ FontList@
        (setq Num# 1)
        (while (< Num# (length ChrList@))
          (setq XY# (nth Num# ChrList@)
                X1# (+ X# (nth (1+ Num#) ChrList@))
                Y1# (- Y# (nth Num# ChrList@))
                X2# (+ X# (nth (+ Num# 3) ChrList@))
                Y2# (- Y# (nth (+ Num# 2) ChrList@))
          );setq
          (if (and (/= XY# -1)(> X1# -1)(> Y1# -1)(> X2# -1)(> Y2# -1))
            (vector_image X1# Y1# X2# Y2# Color#)
          );if
          (setq Num# (+ Num# 4))
        );while
        (setq Y# (- Y# (nth 0 ChrList@)))
      );foreach
    );progn
  );if
);defun vector_text
发表于 2011-5-24 14:39:29 | 显示全部楼层
DEAR SIR,
  1. ; error: no function definition: GETFONTLIST
复制代码
发表于 2011-5-25 19:55:33 | 显示全部楼层
GetFontList
发表于 2011-5-25 20:14:52 | 显示全部楼层
不错,受启发完善了一下函数库!
发表于 2011-5-26 11:21:59 | 显示全部楼层
发给需要的朋友

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-31 00:26 , Processed in 0.214129 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表