Display and insert new characters of Chinese character lattice information (based on HZK16 ASC16 font)

Source: Internet
Author: User

Display and insert new characters of Chinese character lattice information (based on HZK16 ASC16 font)

The system operates the HZK16 and ASC16 Chinese character libraries.

Each Chinese Character in the HZK16 font uses 32 bytes of dot matrix information, while the ASC16 font uses 16 bytes of dot matrix information for printing.

This document describes how to print and operate Chinese-character lattice information)

 

 

/*************************************** * *********************************** This C source code is made for HZK16 and ASC16 characters system ********** newplan 2013.9in UESTC ****************** **************************************** * ******************/# include
 
  
# Include
  
   
# Include
   
    
// Typedef unsigned int WORD; // typedef unsigned char BYTE; /*************************************** **************************************** * *************/int Get_Asc_Code (unsigned char * Get_Input_Char, char buff []); int Get_HzK_Code (unsigned char * Get_Input_Char, char buff []); void Print_Asc_Char (char * mat, char * Out_Put_1, char * Out_Put_2 ); void Print_HzK_Char (char * mat, char * Out_Put_1, char * Out_Put_2); un Signed long Judge_type_char (unsigned char * Get_Input_Char, unsigned long * offset, int * length); int Delete_Char_From_Lib (char * character, unsigned long offset, char * Lib_Name ); int Get_Char_Model (unsigned char buff_input [32]); int Not_In_Lib (char buff [32]); int transpose (char chaned [16] [16]); void distranspose (char mat [] [2], char ** array); int asistant_insert (unsigned char * mat); void change (char mat [] [2], cha R ** array ); /*************************************** **************************************** * **************/int output_system (void ); int insert_system (void); int delete_system (void ); //************************************** **************************** // Method: get_Asc_Code // FullName: Get_Asc_Code/Access: public // Returns: int // Qualifier: Get the modulo information of English characters, and save it to the array // Parameter: unsigned char * Get_Input_Cha R: character pointer to obtain the modulo information // Parameter: char buff [] array for storing the obtained model information //**************************** **************************************** int Get_Asc_Code (unsigned char * Get_Input_Char, char buff []) {unsigned long offset; FILE * ASC;/* Open the font FILE asc16 */if (ASC = fopen ("C: \ experience \ ASC16 ", "rb +") = NULL) {printf ("Can't open asc, Please add it? "); System (" pause "); exit (0);} offset = * (Get_Input_Char) * 16 + 1;/* calculate the offset using the ascii code */fseek (ASC, offset, SEEK_SET);/* move the file pointer to the offset position */fread (buff, 16, 1, ASC ); /* read 32 bytes from the offset position */printf ("ASCII: % d, offset: % d \ n \ r", * Get_Input_Char, offset ); fclose (ASC); return 1 ;} //************************************** ***************************************/ /Method: print_Asc_Char // FullName: Print_Asc_Char // Access: public // Retu Rns: void // Qualifier: The English character output based on the modulo information // Parameter: char * mat modulo pointer // Parameter: char * Out_Put_1 the character displayed as 1 in the modulo, that is, the foreground character // Parameter: char * Out_Put_2 is the character displayed as a point of 0, that is, the background character //********************************** **************************** void Print_Asc_Char (char * mat, char * Out_Put_1, char * Out_Put_2) {int I, j; for (I = 0; I <16; I ++)/* 8x16 dot matrix, A total of 16 rows */{for (j = 0; j <8; j ++)/* one horizontal byte of 8 bits, determine in turn whether each is 0 */if (mat [I] & (0x80> j) )/* Test whether the current BIT is 1 */printf ("% s", Out_Put_1);/* if it is 1, the character c1 */else printf ("% s ", out_Put_2);/* 0 is displayed as c2 */printf ("\ n");/* after a row is input, line feed */}}/********************************* **************************************** ** // Method: get_HzK_Code ***** // FullName: Get_HzK_Code ***** // Access: public ***** // Returns: int ***** // Qualifier: obtains the font information of Chinese characters, store the array *** // Parameter: unsigned char * Get_Input_Char character pointer to obtain the model information *** // Par Ameter: char buff [] array for storing mod information ***/*************************** **************************************** * ******/int Get_HzK_Code (unsigned char * Get_Input_Char, char buff []) {int not_find = 0; unsigned char qh, wh; unsigned long offset; FILE * HZK; char file_name [] = "C: \ experience \ HZK16 "; if (HZK = fopen (file_name," rb + ") = NULL) /* open the font file hzk16 */{printf ("Can't open haz16, Please add it? "); System (" pause "); exit (0);}/* area code = internal code (high byte)-160 bits = internal code (low byte) -160 */qh = * (Get_Input_Char)-0xa0;/* 10 hexadecimal 160 equals to hexadecimal A0 */wh = * (Get_Input_Char + 1)-0xa0; /* Get the code and Location Code */offset = (94 * (qh-1) + (wh-1) * 32L; /* calculate the offset of this Chinese Character in the font library */not_find = fseek (HZK, offset, SEEK_SET);/* move the file pointer to the offset position */if (not_find) {printf ("this area is not found! Error !!! \ N "); fclose (HZK); return 0;} fread (buff, 32, 1, HZK ); /* read 32 bytes from the offset position */if (Not_In_Lib (buff) {fclose (HZK); printf ("Unrecognized characters exist! \ N "); system (" pause "); return 0;} printf (" qh: % d, wh: % d, offset: % ld \ n \ r ", qh, wh, offset); fclose (HZK); return 1 ;} //************************************** *********************************** // Method: print_HzK_Char *** // FullName: Print_HzK_Char *** // Access: public *** // Returns: void *** // Qualifier: enter the Chinese character *** // Parameter: char * mat mod pointer *** // Parameter: character displayed at 1 in the char * Out_Put_1 Mod, that is, the foreground character *** // Par Ameter: char * Out_Put_2 is a character displayed at 0 in the modulo, that is, the background character ***//******************************* **************************************** * ** void Print_HzK_Char (char * mat, char * Out_Put_1, char * Out_Put_2) {int I, j, k; for (I = 0; I <16; I ++)/* 16x16 Dot Matrix Chinese characters, A total of 16 rows */{for (j = 0; j <2; j ++)/* have 2 bytes horizontally, cyclically judge the */for (k = 0; k <8; k ++)/* of each byte with 8 digits, cyclically determine whether each user is 1 */if (mat [I * 2 + j] & (0x80> k )) /* test whether the current BIT is 1 */printf ("% s", Out_Put_1);/* if it is 1, the character c1 */els is displayed. E printf ("% s", Out_Put_2);/* 0 is displayed as the character c2 */printf ("\ n");/* after a line is input, newline */}}//******************************** * ******** // Method: not_In_Lib *** // FullName: Not_In_Lib *** // Access: public *** // Returns: int *** // Qualifier: /* determine whether the character is in the font *** // Parameter: char buff [] ***** // ****************************** * ********* int Not_In_Lib (char buff [32]) {for (int I = 0; I <32; I ++) {if (buff [I]) // if one is not 0, the buff [] has been modified. The font already exists. Exit this function return 0;} return 1 ;} //************************************** *************************** // Method: select_type_char *** // FullName: Select_type_char *** // Access: public *** // Returns: int 0 indicates success; *** // Qualifier: determine whether it is a Chinese character or an English single byte character, and calculate the offset *** // Parameter: unsigned char * Get_Input_Char *** // Parameter: int * offset *** // Parameter: length of the int * length Buffer ***//*************************** * *********************************** Unsigned long Judge_type_char (char * Get_Input_Char, unsigned long * offset, int * length) {if (Get_Input_Char [2] = 0 & Get_Input_Char [1] = 0) // asc16 {* offset = * (Get_Input_Char) * 16 + 1; * length = 16;} else // HZK16 {unsigned char qh = (unsigned char) Get_Input_Char [0]-0xa0; /* 10-digit 160 equals to hex A0 */unsigned char wh = (unsigned char) Get_Input_Char [1]-0xa0; /* obtain the area code and Location Code */* offset = (94 * (qh-1) + (wh-1) * 32L;/* calculate the Chinese character offset in the font */* length = 32;} return * offset ;} //************************************** * *********************** // Method: get_Char_Model *** // FullName: Get_Char_Model *** // Access: public *** // Returns: int 0 indicates that the mode reading fails. 1 indicates that the reading is successful. *** // Qualifier: area Chinese character model *** // Parameter: unsigned char * character points to a character to be added to the font // Parameter: char buff_input: pointer to the modulo ***//***************************** **** * *************************** Int Get_Char_Model (unsigned char buff_input [32]) {char st [] = "C:/experience/PCtoLCD/PCtoLCD.exe"; // character variable char file_read_buffer [200] for the given command content; FILE * model_read_stream; int number = 0, current = 0, decade = 0, bits = 0; memset (file_read_buffer, 0, sizeof (file_read_buffer); printf ("to save the template file, be sure: model. save the TXT file name \ n "); printf (" the Chinese character modulo reading application will be opened soon! \ N "); system (" pause "); system (st); // run the pctolcd.exe model_read_stream = fopen (" C:/experience/PCtoLCD/lib/model. TXT "," r "); if (! Model_read_stream) {printf ("failed to open the file! \ N "); return 0;} fread (file_read_buffer, sizeof (file_read_buffer), sizeof (char), model_read_stream); system (" pause "); printf ("\ n % s \ n", file_read_buffer); fclose (model_read_stream); // system ("del C:/experience/PCtoLCD/lib/model. TXT "); // system (" del C:/experience/PCtoLCD/lib/model. TXT_index.TXT "); printf (" wait for a minute! \ N "); system (" pause "); for (current = 0; current
    
     
= 32) return 1;} return 0 ;} //************************************** * ******************** // Method: delete_Char_From_Lib *** // FullName: Delete_Char_From_Lib *** // Access: public *** // Returns: int *** // Qualifier: delete a text *** // Parameter: unsigned char * character to be deleted *** // Parameter: int offset delete character offset *** // Parameter: char * Lib_Name: deletes the Character Library ***//**************************** ********************* * ******** Int Delete_Char_From_Lib (char * character, unsigned long offset, char * Lib_Name) {char buff_clear_chinese [32], buff_clear_english [16]; memset (buff_clear_chinese, 0, sizeof (buff_clear_chinese); memset (buff_clear_english, 0, sizeof (buff_clear_english); FILE * open_file = fopen (Lib_Name, "rb + "); fseek (open_file, offset, SEEK_SET); if (! Open_file) {printf ("can't open file: % s \ n", Lib_Name); exit (0 );} if (character [2] = 0 & character [1] = 0) {fwrite (buff_clear_english, 16,1, open_file);} else {system ("pause "); fwrite (buff_clear_chinese, 32, 1, open_file);} printf ("delete successfully! \ N "); fclose (open_file); system (" pause "); return 0 ;} //************************************** * ************************* // Method: transpose *** // FullName: transpose *** // Access: public *** // Returns: int *** // Qualifier: transpose function *** // because the Chinese characters read by the model software are transposed according to normal operations *** // Parameter: char changed [16] [16] ***** // *************************** * *********************************** int transpose (char changed [16] [16]) {char temp; Int I = 0, j = 0; for (I; I <16; I ++) {for (j = I; j <16; j ++) {temp = changed [I] [j]; changed [I] [j] = changed [j] [I]; changed [j] [I] = temp ;}} return 1 ;} //************************************// method: distranspose // FullName: distranspose // Access: public // Returns: void // Qualifier:/* convert the binary mat array into the character change array * // Parameter: char mat [] [2] // Parameter: char ** array // Parameter: int m // Parameter: int n //*************** * ******************* Void distranspose (char mat [] [2], char ** array) {int I, j, k, l = 0, n = 16; for (I = 0; I <16; I ++) {for (j = 0; j <2; j ++) {for (k = 0; k <8; k ++) {if (* (char *) array + n * I + l) = '#') // calculate the available fonts based on the status of 0 and 1 in each byte {mat [I] [j] | = (0x80> k );} else {mat [I] [j] & = (~ (0x80> k);} l ++;} l = 0;} return ;} //************************************// method: change // FullName: change // Access: public // Returns: void // Qualifier:/* convert the binary mat array into the character change array * // Parameter: char mat [] [2] // Parameter: char ** array // Parameter: int m // Parameter: int n //************************************ void change (char mat [] [2], char ** array) {int I, j, k, l = 0, n = 16; for (I = 0; I <16; I ++) {for (j = 0; j <2; j ++) {for (k = 0; k <8; k ++) {if (mat [I] [j] & (0x80> k) // state 0 and 1 of each byte {* (char *) array + n * I + l) = '#'; l ++;} else {* (char *) array + n * I + l) = '-'; l ++; }}l = 0;} return ;} //************************************// method: asistant_insert // FullName: asistant_insert // Access: public // Returns: int // Qualifier: Auxiliary inserting character function // Parameter: unsigned char * mat //********************************** ** int asistant_insert (unsigned cha R * mat) {int j = 0, I = 0; char array [16] [16], mat_temp [16] [2]; memset (array, 0, sizeof (array); memset (mat_temp, 0, sizeof (mat_temp); for (j = 0, I = 0; j <16; j ++) {mat_temp [j] [0] = mat [I]; mat_temp [j] [1] = mat [I + 1]; I = I + 2;} change (mat_temp, (char **) array); transpose (array); distranspose (mat_temp, (char **) array); for (j = 0, I = 0; j <16; j ++) {mat [I] = mat_temp [j] [0]; mat [I + 1] = mat_temp [j] [1]; I = I + 2 ;} return 0 ;}//****************************** * ***** // Method: out_put_system // FullName: out_put_system // Access: public // Returns: int // Qualifier: display the output system (including Chinese and English characters) // Parameter: void // ************************************ int output_system (void) {int count = 0; char Buffer_English [16], Buffer_Chinese [32]; unsigned char word [3] = {0}; char * Output_String1 = (char *) "● ", * Output_String2 = (char *) "○"; while (1) {memset (Buffer_Chinese, 0, sizeof (Buffer_Chinese); m Emset (Buffer_English, 0, sizeof (Buffer_English); printf ("enter Chinese characters (multiple inputs can be entered) [Q indicates exit]:"); for (;) {word [2] = getchar (); /*************************************** ************************************ encoded according to Chinese Characters rules, the Chinese character is expressed in double bytes, and the first byte is represented as a number *** greater than 128, according to getchar () whether it is greater than 128 can be used to determine whether it is a single-byte character or a dual-byte character ***. In addition, the count variable determines whether the current operation is a double-byte character or a single-byte character .. **************************************** * **********************************/If ((( unsigned char) word [2] <128) & (count % 2 = 0) {if (word [2] = '\ n') {break ;} else if (word [2] = 'q') {getchar (); fflush (stdin); return 1 ;}if (Get_Asc_Code (& word [2], Buffer_English )) {Print_Asc_Char (Buffer_English, Output_String1, Output_String2); memset (Buffer_English, 0, sizeof (Buffer_English);} continue;} if (count % 2) = 0) {word [0] = wor D [2]; count ++; continue;} word [1] = word [2]; word [2] = 0; count ++; if (Get_HzK_Code (word, buffer_Chinese) {Print_HzK_Char (Buffer_Chinese, Output_String1, Output_String2); memset (Buffer_Chinese, 0, sizeof (Buffer_Chinese);} else continue;} return 0 ;} //************************************// method: insert_system // FullName: insert_system // Access: public // Returns: int // Qualifier: insert character // Parameter: void //********** * ************************* Int insert_system (void) {// variable declaration part char get_char [3]; FILE * fp = NULL; int not_find = 0; unsigned char qh, wh; unsigned long offset; char buff [32]; char file_name [] = "C: \ experience \ HZK16"; memset (get_char, 0, sizeof (get_char); printf ("Enter the words you want to add to the font: "); gets (get_char); if (strcmp (get_char," ZZ ") <= 0) {printf (" You entered an invalid character! \ N "); system (" pause "); return 0 ;}if (fp = fopen (file_name," rb + ") = NULL) /* open the font file hzk16 */{printf ("Can't open haz16, Please add it? "); System (" pause "); exit (0);}/* area code = internal code (high byte)-160 bits = internal code (low byte) -160 */qh = (unsigned char) get_char [0]-0xa0;/* 10 hexadecimal 160 equals to hex A0 */wh = (unsigned char) get_char [1]-0xa0;/* Get the code and Location Code */offset = (94 * (qh-1) + (wh-1) * 32L; /* calculate the offset of this Chinese Character in the font library */not_find = fseek (fp, offset, SEEK_SET);/* move the file pointer to the offset */if (not_find) {printf ("this area is not found! Error !!! \ N "); fclose (fp); return 0;} memset (buff, 0, sizeof (buff); fread (buff, 32, 1, fp ); /* read 32 bytes from the offset position */if (! Not_In_Lib (buff) {printf ("this word exists in the HZK16 font !!! \ N "); system (" pause "); fclose (fp); return 0;} fseek (fp, offset, SEEK_SET ); // reset the offset unsigned char buff_time [32]; memset (buff_time, 0, sizeof (buff_time); if (! Get_Char_Model (buff_time) {printf ("Mode read failed \ n"); fclose (fp); return 0;} asistant_insert (buff_time); fwrite (buff_time, fp )? Printf ("character added successfully! \ N "): printf (" failed to add the character! \ N "); printf (" qh: % d, wh: % d, offset: % ld \ n \ r ", qh, wh, offset ); system ("pause"); fclose (fp); return 0 ;} //************************************// method: delete_system // FullName: delete_system // Access: public // Returns: int // Qualifier: delete character section // Parameter: void // ************************************ int delete_system (void) {char character [3], * lib_name; int length = 0; unsigned long offset = 0; memset (character, 0, sizeof (Character); lib_name = (char *) malloc (30 * sizeof (char); memset (lib_name, 0, sizeof (lib_name )); printf ("Enter the character you want to delete:"); gets (character); offset = Judge_type_char (character, & offset, & length); if (length = 16) {strcat (lib_name, "C :\\ experience \ ASC16");} else {strcat (lib_name, "C :\\ experience \ HZK16 ");} delete_Char_From_Lib (character, offset, lib_name); return 0 ;} //************************************// method: main // FullN Ame: main // Access: public // Returns: int // Qualifier: function entry // Parameter: void // ************************************ int main (void) {char choice [2] = {0, 0}; int number =-1; for (;) {printf ("\ n \ tEmbedded Characters Processing Program \ n "); printf ("\ t \ tmade by NEWPLAN \ n"); printf ("\ t \ t2013.9 in UESTC \ n "); printf ("\ t MENU \ n"); printf ("\ t0: Exit program \ n"); printf ("\ t1: character display \ n "); printf ("\ t2: character deletion \ n"); printf ("\ t3: add character \ n "); Printf (" \ t4: clear screen \ n "); printf (" your choice = "); gets (choice); number = atoi (choice ); fflush (stdin); switch (number) {case 0: printf ("exit the program! \ N "); system (" pause "); return 0; case 1: output_system (); break; case 2: delete_system (); break; case 3: insert_system (); break; case 4: system ("cls"); break; default: printf ("incorrect input! \ N "); break;} number =-1;} return 0 ;}
    
   
  
 


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.