Thread Content
Abstract: All versions of AutoCAD under various operating systems cannot directly create text with subscripts. Based on practical experience, this paper presents a method to solve this problem. Keywords AutoCAD, text, text subscripts. In AutoCAD, the files used to store the drawings are called graphic files; entities are the basic units that make up such files, and Text is one of the most commonly used entities. I. Terminology: For the sake of clarity, several terms related to text are defined first. In the examples of BASESUPPER DATA (text with superscripts), BASES UB DATA (text with subscripts), and BASESUPPERSUB DATA (text with both superscripts and subscripts), BASE and DATA are referred to as basic text; here, BASE is also called the leading (basic) text, while DATA is called the trailing (basic) text. SUPPER refers to text with superscripts, and SUB refers to text with subscripts. The superscripts and subscripts of text include superscripts, subscripts, and those that appear above and below the text. In AutoCAD, text is a string with attributes such as the same height, aspect ratio (width), rotation angle, skew angle, line type, color, and font, and it consists of one or more characters. Since superscript and subscript text have different heights from regular text, according to this definition, AutoCAD text clearly cannot contain superscripts or subscripts, which causes a lot of trouble for users. In practical use, leading text, superscript text, subscript text, and trailing text must be entered in multiple steps. Although this approach works for practical purposes, it presents many disadvantages: (1) It is cumbersome because the text has to be entered in separate steps; (2) Modifying the text is also complicated since the main text and the superscript/subscript text belong to different entities; (3) It is difficult to achieve perfect consistency in the positions of superscripts and subscripts in the text within a diagram. II. Expanding the TEXT command: In various versions of AutoCAD, the TEXT command is used to enter text (strings) into a drawing; it can only be used to type basic text, not text with subscripts or superscripts. Is it possible to use the TEXT command, without making any modifications to the AutoCAD program, to expand its functionality so that it can also be used to type text with subscripts? The conclusion drawn in this article is yes. To expand the TEXT command, it is first necessary to understand the process by which this command handles text: (1) Determine the various attributes of the text (Western characters, Chinese characters); (2) Set the initial values for the “Text Translator”; (3) Read in a line of text; (4) For each character in that line of text (a single character for Western characters, two characters for Chinese characters), perform the following operations in sequence; (5) Decide on the writing method; (6) Retrieve the corresponding data from the shape file (ordinary shape files for Western characters, multi-shaped files for Chinese characters); (7) The Text Translator interprets the retrieved data according to its definitions and writes it into the diagram. To expand the TEXT command without modifying the AutoCAD program, one can only work with the data used by this command. As indicated by the processing steps outlined above, the main data utilized by the TEXT command are font files (Western character fonts, Chinese character fonts); therefore, the approach involves working with these font files. To do this, it is necessary to understand shape files; not only the file format, but more importantly, the definition of the data contained within them. A shape file consists of shapes and indices, with each shape being made up of shape definition commands and vector data. AutoCAD supports two types of shape files: one is the ordinary shape file (Shape), which uses a single byte as an index for retrieving data; it is used to create Western character libraries and can hold up to 256 shapes. The other type is the big font file, which refers to a shape file capable of holding many characters; it uses a double byte as an index and is used to create Chinese character libraries, with a maximum of 256×256=65536 shapes. Although these two file formats differ slightly, their shape definitions are exactly the same; in this article they are collectively referred to as shape files. As can be seen from the command definition table (Table 1), 1 and 2, 3 and 4, and 5 and 6 are three sets of commands that are inverse operations to each other; they are used respectively for controlling the lowering and raising of the pen, scaling vector data, and saving and restoring the current position. Table 1 shows that in the text interpreter, two important variables are used: one is the “scale factor,” which is a positive real number. Its initial value is related to the specific shapes defined in the shape file (see Table 2). Table 2 specifies the scale for vector data, and its value can be changed by using commands 3 and 4 along with a single-byte integer value ranging from 1 to 255; by combining commands 3 and 4, different values can be assigned to the scale factor. The other variable is the “current position”; its initial value corresponds to the reference point of the text entered by the user. This value changes continuously as the shape definitions are altered during text writing, and it can also be manually adjusted by moving the pen. The starting point of each character is determined by this variable. Commands 5 and 6 are used to push and pop this variable onto and off the stack, thereby allowing its value to be saved and restored. It is worth noting that in a shape, 3 and 4, as well as 5 and 6, do not necessarily have to be used in pairs; this is the key to solving the problem. Taking text with superscripts and subscripts as an example (refer to Table 3), assuming that the height of both superscripts and subscripts is half that of the regular text, the above three set of shape definition commands are used to illustrate how the TEXT command can be used to directly output text with superscripts and subscripts. The following is the working process of the Chinese character interpreter in the TEX T command: (1) Start writing at point A (using command 1 for shape definition), beginning with the leading text; the current position is at point A, and the scale factor is the text height divided by the length of the baseline vector (refer to Table 2). (2) After writing the leading text “BASE”, the current position is at point B. (3) The position at point B is pushed onto the stack (command 5). (4) Adjust the position before writing the superscript text; move the starting point for writing the superscript text (the current position) to point D. Pen down at point B (command 2), move to point C (data OA4), and then move to point D (data 010). (5) Adjust the height of the superscript text by dividing the scale factor by 2 (command 3, data 2), thereby reducing its height by two times. Table 3. (6) After penning down at point D (command 1), start writing the superscript text “SUPPER”; after writing it, the current position is at point E. (7) Pop the position at point B from the stack (command 6), return to point B, and make it the current position. (8) Adjust the position before writing the subscript text; move the starting point for writing the subscript text (the current position) to point G. Pen down at point B (command 2), move to point F (data 04C), and then move to point G (data 020). (9) After penning down at point G (command 1), start writing the subscript text “SUB”; after writing it, the current position is at point H. (10) Restore the height of the subsequent text by multiplying the scale factor by 2 (command 4, data 2), thereby doubling its height and restoring it to the original height of the regular text. (11) Adjust the position before writing the subsequent text; move the starting point of the subsequent text (the current position) to point J. Lift the pen at point H (command 2), move to point I (data 010), and then move to point J (data 024). (12) After penning down at point J (command 1), start writing the subsequent text “DATA”; after writing it, the current position is at point K. (13) The entire text-writing process is completed when reaching point K. For writing text with superscripts or subscripts, see Table 3. It can be seen from the above process that, without modifying the AutoCAD program and by utilizing only its existing functions, it is possible to use the TE XT command to directly generate text with subscripts. III. Delimiters for Text: In text that contains leading text, superscript text, subscript text, and trailing text, it is obvious that only 3 special characters are needed to separate them; these are known as delimiters, and are named “Superscript Start”, “Superscript Separator”, and “Superscript End”. In superscript text that includes leading text, subscript text, and trailing text, two delimiter texts \"Superscript Start\" and \"Superscript End\" should be used. In subscripted text that includes leading text, subscripted text, and trailing text, two delimiter words \"Subscript Start\" and \"Subscript End\" are also required. For text with subscripts and superscripts, there is a separator text \"Subscript Start\" between the preceding text and the superscript text; adjustments to the position and height of the superscript text are required in this area. There is a \"Subscript Separator\" between the superscript text and the subscript text, and adjustments to the position of the subscript text are needed here. Finally, there is a \"Subscript End\" between the subscript text and the subsequent text, with adjustments to the position and height of the subsequent text required in this section. If these 3 delimiters can perform these specified functions, then the TEXT command can directly generate text with subscripts. In text with subscripts, superscripts, and subscripted characters, 7 delimiters for the text are required. If a single character is used to represent this, it can only be inserted into the Western character set; moreover, some characters in that set are difficult to input, some essential ones cannot be replaced, and some conflict with Chinese characters, leaving few available characters – making it inconvenient to use a single character for this purpose. If two characters indicate that something can be inserted into the Chinese character font, and considering the convenience and intuitiveness of input, these 7 delimiters for text are formed using underscores and parentheses; they are: “_{}” (start of superscripts/subscripts), “_|” (separator for superscripts/subscripts) and “_}” (end of superscripts/subscripts), “_+” (start of superscripts) and “_)” (end of superscripts), and “_DATA”. Points to note when using it are: (1) the separator characters between lines can be omitted; (2) in text with subscripts, if there are fewer subscript characters than superscript characters, spaces should be used to fill the gap; (3) since the separator characters are stored in a multigraphic file, text with subscripts and superscripts can only be displayed by using this multigraphic file, that is, by setting it as the current font. In AutoCAD, multi-font files and regular font files must be used together, with data being retrieved in this order. Since the underscore character “_” is already used for separating text and is occupied by multi-font files, it cannot be used in regular font files. To ensure integrity, this character must be redefined in the multi-font files (see Table 2); after redefinition, “----” is used to represent “--”. There are many advantages to using this method to extend the TEXT command: (1) There is no need to modify the AutoCAD program; (2) It has no impact on any of AutoCAD’s commands, including the TEXT command; (3) It works with all versions of AutoCAD on various operating systems; (4) It is easy to use – a single TEXT command can be used to type text with superscripts, subscripts, or both; (5) The basic text as well as the superscripts and subscripts formed are considered entities, making them easy to modify; (6) All types of text (Latin characters, Chinese characters) can be used as basic text, superscript text, subscript text, or text with both superscripts and subscripts; (7) In a line of text, the leading text, trailing text, superscript text, subscript text, or text with both can be omitted or used multiple times; (8) All input methods available for the TEXT command can be used; (9) All attributes of text still apply to text with superscripts and subscripts; (10) It works with all AutoCAD commands that are used to create or modify text, such as the DIM command for dimensioning; (11) Superscripts and subscripts can be nested within each other (see Table 3 for examples), meaning that text with superscripts and subscripts can themselves have further superscripts or subscripts; (12) It saves storage space; (13) Since the position and height of superscripts and subscripts are not manually controlled, it ensures that the superscripts and subscripts of all text in the drawing are identical. Finally, it should be noted that this method can be further extended, for example to enable variable font height (text of different heights) input within a single line of text.