日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

GBK点阵显示字库的制作和使用

發布時間:2023/12/8 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 GBK点阵显示字库的制作和使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

開發環境是

win7系統 、Visual Studio 2019開發工具

1.生成GBK全字符文件

運行下面這段代碼,生成GBK全字符文件gbk.txt,編碼范圍0x8140~0xfefe。

// TestCDemo.cpp : 此文件包含 "main" 函數。程序執行將在此處開始并結束。
//

#include <stdio.h> ?
#include <stdlib.h> ?

int main(void)
{
? ? FILE* fp = 0;
? ? char ch = 0;
? ? unsigned short int start = 0x8140;
? ? unsigned char part1 = 0;
? ? unsigned char part2 = 0;

? ? fopen_s(&fp, "data.txt","wb");
? ? if ( fp == NULL)
? ? {
? ? ? ? perror("Cann't open gbk.txt");
? ? ? ? return -1;
? ? }
? ? else
? ? ? ? printf("Creat file data.txt/n");
? ? while (start < 0xfeff)
? ? {
? ? ? ? part1 = start >> 8;
? ? ? ? part2 = start;
? ? ? ? fputc(part1, fp);
? ? ? ? fputc(part2, fp);
? ? ? ? start++;
? ? }
? ? fclose(fp);
? ? printf("success!");

? ? return 0;
}

運行后,用記事本打開gbk.txt文件,可以看到其中的字符。

2.生成字模二進制文件

用“牧碼字模”軟件打開gbk.txt文件,選擇字體為宋體,字重為1,點陣大小16*16,對齊方式為左下,取模方式為“縱向取模、高位在下”。輸出格式選擇bin。然后點擊輸出,會生成一個temp.bin文件,改名為gbk.bin。

?

3.使用字庫文件

gbk.bin文件中按GBK編碼的大小排列,每32個字節可以顯示一個字符,假設一個字符的GBK編碼為NUM,那么它的點陣數據第一個字節的位置就是:

(NUM-0x8140)*32

從這個字節開始,讀取32個字節,將其按按照取模方式顯示即可。

例如:用Linux的終端模擬點陣屏幕,每個字符位置就是一個點,程序如下:

?

  • #include?<stdio.h>??
  • #include?<unistd.h>??
  • #include?<curses.h>??
  • ??
  • #define?START?0x8140??
  • #define?DATANUM?0x20??
  • ??
  • int?displaychar(FILE?*fp,unsigned?short?int?dispch,char?fillch,char?start_x,char?start_y);??
  • ??
  • int?main(void)??
  • {??
  • ????FILE?*?fp=0;??
  • ????unsigned?short?int?testch?=?0xb0ae;??//漢字'愛‘的gbk碼??
  • ??
  • ????fp?=?fopen("gbk.bin","rb");??
  • ??
  • ????initscr();??
  • ??
  • ????displaychar(fp,testch,'*',0,0);??
  • ??
  • ????refresh();??
  • ??
  • ????while(1);??
  • ????endwin();??
  • ????fclose(fp);??
  • ????return?0;??
  • }??
  • ??
  • /*?
  • ?*?fp指向點陣字庫二進制文件?
  • ?*?以點陣方式顯示一個GBK字符?
  • ?*?dispch是要顯示的字符,fillch是填充點陣的字符?
  • ?*?start_x,start_y是顯示的起始坐標?
  • ?*/??
  • int?displaychar(FILE?*fp,unsigned?short?int?dispch,char?fillch,char?start_x,char?start_y)??
  • {??
  • ????char?x=start_x;??
  • ????char?y=start_y;??
  • ????unsigned?int?location=(dispch-START)*DATANUM;??
  • ??
  • ????int?i=0;??
  • ????int?j=0;??
  • ????char?buf=0;??
  • ??
  • ????fseek(fp,location,SEEK_SET);??
  • ??
  • ????for(i=0;i<DATANUM;i++)??
  • ????{??
  • ????????buf=fgetc(fp);??
  • ??
  • ????????//顯示一個字節??
  • ????????for(j=0;j<8;j++)??
  • ????????{??
  • ????????????move(y+j,x);??
  • ????????????if(?buf?&?(0x01<<j)?)??
  • ????????????{??
  • ????????????????addch(fillch);??
  • ????????????}??
  • ????????}??
  • ??
  • ????????if(x?==?(start_x+15))??
  • ????????{??
  • ????????????x=start_x;??
  • ????????????y=start_y+8;??
  • ????????}??
  • ????????else??
  • ????????????x++;??
  • ????}??
  • ????return?0;??
  • ??
  • }??
  • ?

    具體請查看原作者的文章??https://www.cnblogs.com/alan666/p/8312006.html

    ?

    牧碼字模字膜提取軟件 下載地址??https://download.csdn.net/download/u013519290/14915183

    宋體字模二進制文件下載??https://download.csdn.net/download/u013519290/14915040

    生成GBK全字符文件源碼? ?https://download.csdn.net/download/u013519290/14914896

    總結

    以上是生活随笔為你收集整理的GBK点阵显示字库的制作和使用的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。