Lisp lệnh HA U2T trong chủ đề “[Yêu cầu] Lisp chuyển Font12 (font xuyệc (/)) sang UNICODE hay TCVN-3”
Lisp này tôi đang viết để chuyển qua lại giữa 4 font chữ: Unicode, TCVN3, VNI, và "Xuyệc", nhưng chưa hoàn chỉnh. Tuy nhiên chủ topic có thể dùng để chuyển từ font "Xuyệc" qua TCVN3, Unicode, VNI. Riêng với TCVN3 thì bạn cần tạo trước 2 kiểu font mẫu: TCVN3 chữ thường và TCVN3 chữ hoa để chọn font mẫu cho phù hợp.
- Tải lisp
- 210349_ha_u2t.lsp
Cách dùng
- Tải tệp 210349_ha_u2t.lsp về máy.
- Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
- Gõ lệnh HA U2T để chạy lisp.
Mã nguồn 210349_ha_u2t.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/65887-y%C3%AAu-c%E1%BA%A7u-lisp-chuy%E1%BB%83n-font12-font-xuy%E1%BB%87c-sang-unicode-hay-tcvn-3/
; Lisp cha hoµn thiÖn. Míi chØ chuyÓn ®îc 9/12 kiÓu ch÷ thêng. Cßn 3/12 kiÓu ch÷ thêng vµ 12 kiÓu ch÷ hoa.
; "µ Ì ß ï ¸ Ð ã ó ¶ Î á ñ · Ï â ò ¹ Ñ ä ô © ª « Ç Ò å õ Ê Õ è ø È Ó æ ö É Ô ç ÷ Ë Ö é ù ¨ × ¬ ú » Ý ê ý ¾ Ø í û ¼ Ü ë ü ½ Þ ì þ ¨ ® î ¦ ¢ § ¤ ¥ ¡ £"
;----- '(TCVN UNI XUYEC VNI) = '("Ç" "\U+1EA7" "a/m/f" "aà")
(defun C:HA( / entlst sty kieu)
(initget "V2T V2U V2X T2X T2V T2U U2T U2X U2V X2V X2T X2U")
(setq kieu (getkword "\nChon 1 trong 12 kieu chuyen [V2T/V2U/V2X/T2X/T2V/T2U/U2T/U2X/U2V/X2V/X2T/X2U]: "))
(cond
((= kieu "V2T") (setq from "VNI" to "TCVN"))
((= kieu "V2U") (setq from "VNI" to "UNICODE"))
((= kieu "V2X") (setq from "VNI" to "XUYEC"))
((= kieu "T2X") (setq from "TCVN" to "XUYEC"))
((= kieu "T2V") (setq from "TCVN" to "VNI"))
((= kieu "T2U") (setq from "TCVN" to "UNICODE"))
((= kieu "U2T") (setq from "UNICODE" to "TCVN"))
((= kieu "U2X") (setq from "UNICODE" to "XUYEC"))
((= kieu "U2V") (setq from "UNICODE" to "VNI"))
((= kieu "X2V") (setq from "XUYEC" to "VNI"))
((= kieu "X2T") (setq from "XUYEC" to "TCVN"))
((= kieu "X2U") (setq from "XUYEC" to "UNICODE")))
(princ (strcat "\nChon cac Text " from " can chuyen sang " to "..."))
(setq entlst (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "*TEXT")))))))
(setq sty (cdr (assoc 7 (entget (car (entsel (strcat "\nChon 1 Text de lay Font " to " mau: ")))))))
(foreach ent entlst
(if (or (= kieu "T2U") (= kieu "T2V") (= kieu "T2X"))
(entmod (subst (cons 1 (HA2 (cdr (assoc 1 (entget ent))))) (assoc 1 (entget ent)) (entget ent)))
(entmod (subst (cons 1 (HA1 (cdr (assoc 1 (entget ent))))) (assoc 1 (entget ent)) (entget ent))))
(entmod (subst (cons 7 sty) (assoc 7 (entget ent)) (entget ent))))
(princ))
;-----
(defun HA1 (stsua / hoa)
(if (= (strcase stsua) stsua) (setq stsua (strcase stsua T) hoa T))
(foreach n lst
(cond
((= kieu "X2T") (setq stsua (acet-str-replace (caddr n) (car n) stsua))) ;OK100%; Chó ý: nÕu ch÷ Hoa th× chän TCVN Hoa, nÕu ch÷ thêng th× chän TCVN thêng.
((= kieu "X2U") (setq stsua (acet-str-replace (caddr n) (cadr n) stsua))) ;OK100%
((= kieu "X2V") (setq stsua (acet-str-replace (caddr n) (cadddr n) stsua))) ;OK100%
((= kieu "V2T") (setq stsua (acet-str-replace (cadddr n) (car n) stsua))) ;OK
((= kieu "V2X") (setq stsua (acet-str-replace (cadddr n) (caddr n) stsua))) ;OK
((= kieu "V2U") (setq stsua (acet-str-replace (cadddr n) (cadr n) stsua))) ;NO
((= kieu "U2T") (setq stsua (acet-str-replace (cadr n) (car n) stsua))) ;NO
((= kieu "U2X") (setq stsua (acet-str-replace (cadr n) (caddr n) stsua))) ;OK
((= kieu "U2V") (setq stsua (acet-str-replace (cadr n) (cadddr n) stsua))) ;NO
))
(if (and (or (= kieu "X2V") (= kieu "X2U")) (= hoa T)) (setq stsua (xstrcase stsua)))
stsua)
;-----
(defun HA2 (stsua / i stdich chuht chusua)
(setq i 0 stdich "")
(repeat (strlen stsua)
(setq chuht (substr stsua (setq i (1+ i)) 1) chusua chuht)
(foreach n lst
(if (member chuht n)
(setq chusua
(cond
((= kieu "T2X") (caddr n)) ;OK
((= kieu "T2V") (cadddr n)) ;OK
((= kieu "T2U") (cadr n)))))) ;OK
(setq stdich (strcat stdich chusua)))
stdich)
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;Trang web nay co .net cua Gia_bach chuyen nhieu kieu hon: https://www.cadviet.com/forum/index.php?showtopic=22767&st=0
;----- ChuyÓn tõ UNICODE => TCNN3
(defun C:U2T( / entlst sty)
(princ "\nChon cac Text UNICODE can chuyen sang TCVN...")
(setq entlst (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "TEXT")))))))
(setq sty (cdr (assoc 7 (entget (car (entsel "\nChon Text de lay Font TCVN mau: "))))))
(foreach ent entlst
(entmod (subst (cons 1 (Unicode-TCVN (HEXA3 (HEXA2 (HEXA1 (cdr (assoc 1 (entget ent)))))))) (assoc 1 (entget ent)) (entget ent)))
(entmod (subst (cons 7 sty) (assoc 7 (entget ent)) (entget ent))))
(princ))
;----- Hµm bá ký tù ®· thªm "\" tríc khi chuyÓn sang TCVN.
(defun HEXA3(str)
(setq x 1)
(repeat (strlen str)
(cond ((= "\U+005C" (substr str x 7)) (setq str (vl-string-subst "\\" "\U+005C" str))))
(setq x (1+ x)))
str)
;----- Hµm chuyÓn 20 ký tù (µ, ó,...) tõ Unicode sang Hexa.
(defun HEXA2(str)
(setq x 1)
(repeat (strlen str)
(cond ((= (chr 194) (substr str x 1)) (setq str (vl-string-subst "\U+00C2" (substr str x 1) str) x (+ x 6)))
((= (chr 202) (substr str x 1)) (setq str (vl-string-subst "\U+00CA" (substr str x 1) str) x (+ x 6)))
((= (chr 208) (substr str x 1)) (setq str (vl-string-subst "\U+0110" (substr str x 1) str) x (+ x 6)))
((= (chr 212) (substr str x 1)) (setq str (vl-string-subst "\U+00D4" (substr str x 1) str) x (+ x 6)))
((= (chr 224) (substr str x 1)) (setq str (vl-string-subst "\U+00E0" (substr str x 1) str) x (+ x 6)))
((= (chr 225) (substr str x 1)) (setq str (vl-string-subst "\U+00E1" (substr str x 1) str) x (+ x 6)))
((= (chr 226) (substr str x 1)) (setq str (vl-string-subst "\U+00E2" (substr str x 1) str) x (+ x 6)))
((= (chr 227) (substr str x 1)) (setq str (vl-string-subst "\U+00E3" (substr str x 1) str) x (+ x 6)))
((= (chr 232) (substr str x 1)) (setq str (vl-string-subst "\U+00E8" (substr str x 1) str) x (+ x 6)))
((= (chr 233) (substr str x 1)) (setq str (vl-string-subst "\U+00E9" (substr str x 1) str) x (+ x 6)))
((= (chr 234) (substr str x 1)) (setq str (vl-string-subst "\U+00EA" (substr str x 1) str) x (+ x 6)))
((= (chr 236) (substr str x 1)) (setq str (vl-string-subst "\U+00EC" (substr str x 1) str) x (+ x 6)))
((= (chr 237) (substr str x 1)) (setq str (vl-string-subst "\U+00ED" (substr str x 1) str) x (+ x 6)))
((= (chr 242) (substr str x 1)) (setq str (vl-string-subst "\U+00F2" (substr str x 1) str) x (+ x 6)))
((= (chr 243) (substr str x 1)) (setq str (vl-string-subst "\U+00F3" (substr str x 1) str) x (+ x 6)))
((= (chr 244) (substr str x 1)) (setq str (vl-string-subst "\U+00F4" (substr str x 1) str) x (+ x 6)))
((= (chr 245) (substr str x 1)) (setq str (vl-string-subst "\U+00F5" (substr str x 1) str) x (+ x 6)))
((= (chr 249) (substr str x 1)) (setq str (vl-string-subst "\U+00F9" (substr str x 1) str) x (+ x 6)))
((= (chr 250) (substr str x 1)) (setq str (vl-string-subst "\U+00FA" (substr str x 1) str) x (+ x 6)))
((= (chr 253) (substr str x 1)) (setq str (vl-string-subst "\U+00FD" (substr str x 1) str) x (+ x 6))))
(setq x (1+ x)))
str)
;----- Hµm gi÷ nguyªn m· Hexa (kh«ng cho chuyÓn qua Unicode).
(defun HEXA1(str)
(setq x 1 moi "")
(repeat (strlen str)
(setq kytu7 (substr str x 7))
(setq x (+ x 1))
(if (= (substr kytu7 1 3) "\\U+")
(setq moi (strcat moi (strcat "\U+005C" (substr kytu7 2 7))) x (+ x 6))
(setq moi (strcat moi (substr kytu7 1 1))))))
;----- ChuyÓn ngîc tõ Unicode --> TCVN.
(defun Unicode-TCVN (stsua / i stdich chuht)
(TAO_TAPSUA)
(setq i 1)
(repeat (- (strlen stsua) 6)
(setq chuht (substr stsua i 7)
i (1+ i))
(cond ((assoc chuht tapsuan1)
(setq stsua (THAY_CONV stsua (car (assoc chuht tapsuan1)) (cdr (assoc chuht tapsuan1)))))))
(setq stdich stsua))
;----- Hµm con cña chuyÓn ngîc.
(defun THAY_CONV(str old new / n strpp strtt)
(while (setq n (vl-string-search old str))
(setq strpp (substr str (+ 1 n (strlen old))))
(setq strtt (substr str 1 (- (strlen str) (strlen old) (strlen strpp))))
(setq str (strcat strtt new strpp))))
;----- T¹o danh s¸ch c¬ së ®Ó chuyÓn thuËn vµ ngîc gi÷a 4 kiÓu (tæ hîp thµnh 12 kiÓu chuyÓn).
(setq lst ; 74 ký tù (c¸c ký tù IN HOA cã dÊu kh«ng viÕt ®îc b»ng TCVN3 trong Notepad)
(list
'("Ç" "\U+1EA7" "a/m/f" "aà") '("å" "\U+1ED3" "o/m/f" "oà") '("Ò" "\U+1EC1" "e/m/f" "eà") '("õ" "\U+1EEB" "/]/f" "öø")
'("Ê" "\U+1EA5" "a/m/s" "aá") '("è" "\U+1ED1" "o/m/s" "oá") '("Õ" "\U+1EBF" "e/m/s" "eá") '("ø" "\U+1EE9" "/]/s" "öù")
'("Ë" "\U+1EAD" "a/m/j" "aä") '("é" "\U+1ED9" "o/m/j" "oä") '("Ö" "\U+1EC7" "e/m/j" "eä") '("ù" "\U+1EF1" "/]/j" "öï")
'("È" "\U+1EA9" "a/m/r" "aå") '("æ" "\U+1ED5" "o/m/r" "oå") '("Ó" "\U+1EC3" "e/m/r" "eå") '("ö" "\U+1EED" "/]/r" "öû")
'("É" "\U+1EAB" "a/m/x" "aã") '("ç" "\U+1ED7" "o/m/x" "oã") '("Ô" "\U+1EC5" "e/m/x" "eã") '("÷" "\U+1EEF" "/]/x" "öõ")
'("»" "\U+1EB1" "a/w/f" "aè") '("ê" "\U+1EDD" "/[/f" "ôø")
'("¾" "\U+1EAF" "a/w/s" "aé") '("í" "\U+1EDB" "/[/s" "ôù")
'("Æ" "\U+1EB7" "a/w/j" "aë") '("î" "\U+1EE3" "/[/j" "ôï")
'("¼" "\U+1EB3" "a/w/r" "aú") '("ë" "\U+1EDF" "/[/r" "ôû")
'("½" "\U+1EB5" "a/w/x" "aü") '("ì" "\U+1EE1" "/[/x" "ôõ")
'("µ" "\U+00E0" "a/f" "aø") '("ß" "\U+00F2" "o/f" "oø") '("Ì" "\U+00E8" "e/f" "eø") '("ï" "\U+00F9" "u/f" "uø")
'("¸" "\U+00E1" "a/s" "aù") '("ã" "\U+00F3" "o/s" "où") '("Ð" "\U+00E9" "e/s" "eù") '("ó" "\U+00FA" "u/s" "uù")
'("¹" "\U+1EA1" "a/j" "aï") '("ä" "\U+1ECD" "o/j" "oï") '("Ñ" "\U+1EB9" "e/j" "eï") '("ô" "\U+1EE5" "u/j" "uï")
'("¶" "\U+1EA3" "a/r" "aû") '("á" "\U+1ECF" "o/r" "oû") '("Î" "\U+1EBB" "e/r" "eû") '("ñ" "\U+1EE7" "u/r" "uû")
'("·" "\U+00E3" "a/x" "aõ") '("â" "\U+00F5" "o/x" "oõ") '("Ï" "\U+1EBD" "e/x" "eõ") '("ò" "\U+0169" "u/x" "uõ")
'("©" "\U+00E2" "a/m" "aâ") '("«" "\U+00F4" "o/m" "oâ") '("ª" "\U+00EA" "e/m" "eâ") '("" "\U+01B0" "/]" "ö")
'("¨" "\U+0103" "a/w" "aê") '("¬" "\U+01A1" "/[" "ô")
'("¡" "\U+0102" "A/W" "AÊ") '("¥" "\U+01A0" "/{" "Ô") '("£" "\U+00CA" "E/M" "EÂ") '("¦" "\U+01AF" "/}" "Ö")
'("¢" "\U+00C2" "A/M" "AÂ") '("¤" "\U+00D4" "O/M" "OÂ")
'("ý" "\U+00FD" "y/s" "yù") '("û" "\U+1EF7" "y/r" "yû") '("ü" "\U+1EF9" "y/x" "yõ") '("þ" "\U+1EF5" "y/j" "î") '("ú" "\U+1EF3" "y/f" "yø")
'("Ý" "\U+00ED" "i/s" "í") '("Ø" "\U+1EC9" "i/r" "æ") '("Ü" "\U+0129" "i/x" "ó") '("Þ" "\U+1ECB" "i/j" "ò") '("×" "\U+00EC" "i/f" "ì")
'("®" "\U+0111" "/d" "ñ") '("§" "\U+0110" "/D" "Ñ")))
;-----
; (cons "%%174" "ñ") (cons "%%167" "Ñ") (cons "%%181" "aø") (cons "%%184" "aù")
; (cons "%%182" "aû") (cons "%%183" "aõ") (cons "%%185" "aï") (cons "%%169" "aâ")
; (cons "%%162" "AÂ") (cons "%%199" "aà") (cons "%%202" "aá") (cons "%%200" "aå")
; (cons "%%201" "aã") (cons "%%203" "aä") (cons "%%168" "aê") (cons "%%161" "AÊ")
; (cons "%%187" "aè") (cons "%%190" "aé") (cons "%%188" "aú") (cons "%%189" "aü")
; (cons "%%198" "aë") (cons "%%204" "eø") (cons "%%208" "eù") (cons "%%206" "eû")
; (cons "%%207" "eõ") (cons "%%209" "eï") (cons "%%170" "eâ") (cons "%%163" "EÂ")
; (cons "%%210" "eà") (cons "%%213" "eá") (cons "%%211" "eå") (cons "%%212" "eã")
; (cons "%%214" "eä") (cons "%%215" "ì") (cons "%%221" "í") (cons "%%216" "æ")
; (cons "%%220" "ó") (cons "%%222" "ò") (cons "%%223" "oø") (cons "%%227" "où")
; (cons "%%225" "oû") (cons "%%226" "oõ") (cons "%%228" "oï") (cons "%%171" "oâ")
; (cons "%%164" "OÂ") (cons "%%229" "oà") (cons "%%232" "oá") (cons "%%230" "oå")
; (cons "%%231" "oã") (cons "%%233" "oä") (cons "%%172" "ô") (cons "%%165" "Ô")
; (cons "%%234" "ôø") (cons "%%237" "ôù") (cons "%%235" "ôû") (cons "%%236" "ôõ")
; (cons "%%238" "ôï") (cons "%%239" "uø") (cons "%%243" "uù") (cons "%%241" "uû")
; (cons "%%242" "uõ") (cons "%%244" "uï") (cons "%%173" "ö") (cons "%%166" "Ö")
; (cons "%%245" "öø") (cons "%%248" "öù") (cons "%%246" "öû") (cons "%%247" "öõ")
; (cons "%%249" "öï") (cons "%%250" "yø") (cons "%%253" "yù") (cons "%%251" "yû")
; (cons "%%252" "yõ") (cons "%%254" "î")
;-----
Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Yêu cầu] Lisp chuyển Font12 (font xuyệc (/)) sang UNICODE hay TCVN-3. Xem đúng bài viết #210349 để đọc hướng dẫn và trao đổi thêm.