Skip to content

Commit

Permalink
Changes to support UNICODE in AutoCAD 2021 and later. The global vari…
Browse files Browse the repository at this point in the history
…able *LISPSYS* holds the value of the system variable LISPSYS and is set to -1 in AutoCAD 2020 and earlier. If *LISPSYS* has a value of 1 or 2, the multibyte character is processed in the AutoLISP standard.
  • Loading branch information
clownPenguin committed May 26, 2020
1 parent d041682 commit 53157be
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 22 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Common LISP uses the coerce function for type conversion. In this library, too,

For example, AutoCAD's selection set and list of ename can be converted to each other with the coerce function. Furthermore, conversion to a safe array or variant type can be performed by specifying SAFEARRAY or VARIANT.

In addition, the source type is an AutoLISP type, but the destination type can specify some special types. The main thing is that if you specify LIST when converting a string to a list, it will be a list of integers representing ASCII character codes by the AutoLISP standard vl-string->list function. However, if you specify the custom type SLIST, it will be converted to a custom structured list representing a string containing multibyte characters. Also, by specifying a special type VECTOR as the conversion destination, it can be converted to a flat one-dimensional safe array used by ActiveX functions from a multi-dimensional list.
In addition, the source type is an AutoLISP type, but the destination type can specify some special types. The main thing is that if you specify LIST when converting a string to a list, it will be a list of integers representing ASCII character codes by the AutoLISP standard vl-string->list function. However, Specifying a custom type SLIST translates to a list with a custom structure that represents a string containing multi-byte characters in AutoCAD 2020 and earlier. Also, by specifying a special type VECTOR as the conversion destination, it can be converted to a flat one-dimensional safe array used by ActiveX functions from a multi-dimensional list.

Basically, the type symbols that can be specified for the source and destination types are as follows, depending on the type of AutoLISP. It is the same as the return value of the type function.

Expand All @@ -126,15 +126,17 @@ In addition to the above, the following special symbols can be specified as conv

Symbol |Description
---|---
SLIST |List that a string converted to with a multibyte character structure
SLIST |List that a string converted to with a multibyte character structure (for use AutoCAD 2020 and earlier)
VECTOR |One-dimensional safe array
BOOL |Symbols used in ActiveX :vlax-true and :vlax-false
CHAR |Integer representing a single character or structure representing a multibyte character
STRC |A single character string

## Multibyte Characters

In this library, the handling of character strings is internally converted into a list and processed. In that case, ASCII character codes and multibyte characters are processed separately. In other words, it supports Japanese kana and kanji. Currently supported are SHIFT_JIS and hexadecimal strings representing UNICODE character codes. And if it is a simple thing like SHIFT_JIS that can be determined only by looking at the character code, it can also support multi-byte characters of other foreign languages.
In this library, strings are handled internally by converting them into lists. And in AutoCAD 2020 and earlier, ASCII character codes and multi-byte characters are treated differently. In other words, it supports Japanese kana and kanji. Currently supported are SHIFT_JIS and hexadecimal strings representing UNICODE character codes. And if it is a simple thing like SHIFT_JIS that can be determined only by looking at the character code, it can also support multi-byte characters of other foreign languages.

In AutoCAD 2021 or later with UNICODE, if the system variable LISPSYS is set to 1 or 2, the list generated by the vl-string->list function is used as is. If the system variable LISPSYS is 0, the operation is the same as AutoCAD 2020 and earlier.

## Comparison of Real Numbers

Expand Down
8 changes: 5 additions & 3 deletions README_JPN.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Common LISP には型の変換に coerce 関数が用いられます。本ライ

独自の拡張について、例えば AutoCAD の【選択セット】と【図形名】のリストは coerce 関数で相互に変換可能です。さらにセーフ配列やバリアント型への変換も SAFEARRAY や VARIANT を指定することで変換できます。

さらに、変換元の型は AutoLISP の型ではありますが、変換先の型に幾つかの独自の型を指定できるようになっています。主要なものとして、文字列をリストに変換する場合に LIST と指定すると AutoLISP 標準の vl-string->list 関数により ASCII 文字コードを表す整数のリストになりますが、独自の型 SLIST と指定すると、マルチバイト文字を含んだ文字列を表す独自の構造を付けられたリストに変換されます。また、多次元のリストから変換先に独自の型 VECTOR を指定すると ActiveX 対応関数で使用するフラットな一次元のセーフ配列に変換することができます。
さらに、変換元の型は AutoLISP の型ではありますが、変換先の型に幾つかの独自の型を指定できるようになっています。主要なものとして、文字列をリストに変換する場合に LIST と指定すると AutoLISP 標準の vl-string->list 関数により ASCII 文字コードを表す整数のリストになりますが、独自の型 SLIST と指定すると、AutoCAD 2020 以前ではマルチバイト文字を含んだ文字列を表す独自の構造を付けられたリストに変換されます。また、多次元のリストから変換先に独自の型 VECTOR を指定すると ActiveX 対応関数で使用するフラットな一次元のセーフ配列に変換することができます。

基本となる変換元の型と変換先に指定できる型のシンボルは、AutoLISP の型の種類により次のとおりです。type 関数の戻り値と同じものです。

Expand All @@ -127,15 +127,17 @@ Common LISP には型の変換に coerce 関数が用いられます。本ライ

シンボル |説明
---|---
SLIST |文字列をリストに変換したもので、マルチバイト文字の構造を付けたもの
SLIST |文字列をリストに変換したもので、マルチバイト文字の構造を付けたもの(AutoCAD 2020以前用)
VECTOR |一次元のセーフ配列
BOOL |ActiveX で使われるシンボル :vlax-true:vlax-false
CHAR |一文字を表す整数、またはマルチバイト文字を表す構造体
STRC |一文字だけの文字列

## マルチバイト文字

本ライブラリにおいて文字列の扱いは内部でリストに変換して処理していますが、その際 ASCII の文字コードとマルチバイト文字は区別して処理されます。つまり、日本語のかなや漢字に対応しています。現在対応しているのは、SHIFT_JIS と UNICODE 文字コードを表す 16 進表記された文字列ですが、文字コードだけを見て判別できる SHIFT_JIS のような単純なものなら、他の外国語のマルチバイト文字への対応も可能です。
本ライブラリにおいて文字列の扱いは内部でリストに変換して処理していますが、AutoCAD 2020 以前か 2021 以降でシステム変数 LISPSYS の値が 0 の場合は、ASCII の文字コードとマルチバイト文字は区別して処理されます。つまり、日本語のかなや漢字に対応しています。現在対応しているのは、SHIFT_JIS と UNICODE 文字コードを表す 16 進表記された文字列ですが、文字コードだけを見て判別できる SHIFT_JIS のような単純なものなら、他の外国語のマルチバイト文字への対応も可能です。

UNICODE で処理されるようになった AutoCAD 2021 以降でシステム変数 LISPSYS の値が 1 ないし 2 の場合は、特別な処置は行わず vl-string->list 関数が生成するリストをそのまま使用しています。システム変数 LISPSYS が 0 の場合は、以前のバージョンと同じ動作をします。

## 実数の比較

Expand Down
7 changes: 5 additions & 2 deletions characters/characterp.LSP
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
;;; https://opensource.org/licenses/mit-license.php
;;; +------------------------------------------------------+

(include '*LISPSYS* "./common/LISPSYS")
(include 'integerp "./numbers/integerp")
(include 'plusp "./numbers/plusp")
(include 'multi-byte-char-p "./types/multibyte/multi-byte-char-p")

(defun characterp (item)
(or (and (integerp item) (<= 0 item) (<= item 255))
(defun characterp (item)
(or (plusp *LISPSYS*)
(and (integerp item) (<= 0 item) (<= item 255))
(multi-byte-char-p item)
)
)
13 changes: 13 additions & 0 deletions common/LISPSYS.LSP
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
;;;(include '*LISPSYS* "./common/LISPSYS")

;;; *LISPSYS* : integer (The value of (getvar "LISPSYS")) or -1

;;; +------------------------------------------------------+
;;; Copyright (c) 2020 manual chair japan
;;; Released under the MIT license
;;; https://opensource.org/licenses/mit-license.php
;;; +------------------------------------------------------+

(include 'default "./common/default")

(setq *LISPSYS* (default (getvar "LISPSYS") '-1))
22 changes: 16 additions & 6 deletions types/multibyte/list-string.LSP
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
;;; https://opensource.org/licenses/mit-license.php
;;; +------------------------------------------------------+

(include '*multi-byte-char:function* "./types/multibyte/multi-byte-char-func")
(include '*LISPSYS* "./common/LISPSYS")
(include 'plusp "./numbers/plusp")
(include '*multi-byte-char:function*
"./types/multibyte/multi-byte-char-func"
)

(defun decode-multibytecharactor:sub (tlist)
(if tlist
Expand All @@ -36,9 +40,15 @@
)
)


(defun list->string (clist)
(vl-list->string
(apply 'append (mapcar 'decode-multibytecharactor clist))
)
(setq list->string
(if (plusp *LISPSYS*)
vl-list->string
(lambda (clist)
(vl-list->string
(apply 'append
(mapcar 'decode-multibytecharactor clist)
)
)
)
)
)
28 changes: 20 additions & 8 deletions types/multibyte/string-list.LSP
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
;;; https://opensource.org/licenses/mit-license.php
;;; +------------------------------------------------------+

(include '*LISPSYS* "./common/LISPSYS")
(include 'plusp "./numbers/plusp")
(include 'nthcdr "./conses/nthcdr")
(include '*multi-byte-char:function* "./types/multibyte/multi-byte-char-func")
(include '*multi-byte-char:function*
"./types/multibyte/multi-byte-char-func"
)

(defun encode-multibytecharactor:sub (clist tlist / func-s)
(if tlist
Expand All @@ -22,14 +26,17 @@
(if (apply (multi-byte-function-predicate func-s) (list clist))
(apply (multi-byte-function-encode func-s) (list clist))
(encode-multibytecharactor:sub clist (cdr tlist))
)
)
)
(cons (car clist) 1)
)
)

(defun encode-multibytecharactor (clist)
(encode-multibytecharactor:sub clist *multi-byte-char:types*)
(encode-multibytecharactor:sub
clist
*multi-byte-char:types*
)
)

(defun string->list:sub (clist)
Expand All @@ -42,8 +49,13 @@
)
)

(defun string->list (string)
(if string
(string->list:sub (vl-string->list string))
)
)
(setq string->list
(if (plusp *LISPSYS*)
vl-string->list
(lambda (astring)
(if astring
(string->list:sub (vl-string->list astring))
)
)
)
)

0 comments on commit 53157be

Please sign in to comment.