C Tips:顯示點陣漢字的小範例

來源:互聯網
上載者:User

標籤:blog   http   使用   os   io   2014   for   art   

非常簡陋的一段小程式,示範怎樣顯示點陣字型檔。有時間的時候再詳解。

#include <stdio.h>#include <stdlib.h>struct HzkInfoStruct{int HzkSelect;int HzkSquare;char * fileName;FILE * file;int martixBytesCount;unsigned char *pMatrix;};typedef struct HzkInfoStruct HzkInfo;void SelectHZK(HzkInfo * pHzkInfo);void LoadHzkInfo(HzkInfo * pHzkInfo);void CleanupHzkInfo(HzkInfo hzkInfo);void GetQuWh(unsigned char *chineaseWord, int * qu, int * wh);void FillMartix(HzkInfo * pHzkInfo, const int qu, const int wh);void PrintMartix(HzkInfo hzkInfo);int _tmain(int argc, _TCHAR* argv[]){unsigned char chinease[3] = "京";HzkInfo hzkInfo;int qu;int wh;SelectHZK(&hzkInfo);if(hzkInfo.file == NULL || hzkInfo.pMatrix == NULL){printf("HZK loading failed. Will exit now.\n");goto EXIT;}GetQuWh(chinease, &qu, &wh);FillMartix(&hzkInfo, qu, wh);PrintMartix(hzkInfo);EXIT:CleanupHzkInfo(hzkInfo);return 0;}void GetQuWh(unsigned char *chineaseWord, int * qu, int * wh){*qu = chineaseWord[0] - 0xa0;*wh = chineaseWord[1] - 0xa0;}void FillMartix(HzkInfo * pHzkInfo, const int qu, const int wh){fseek(pHzkInfo->file, (94 * (qu - 1) + (wh - 1)) * pHzkInfo->martixBytesCount, SEEK_SET);fread(pHzkInfo->pMatrix, pHzkInfo->martixBytesCount, 1, pHzkInfo->file);}void PrintMartix(HzkInfo hzkInfo){int i, j, k;int i_steps = hzkInfo.HzkSquare / 8;unsigned char * pMatrix = hzkInfo.pMatrix;printf("\n");for (j = 0; j < hzkInfo.HzkSquare; j++){for (i = 0; i < i_steps; i++){for (k = 0; k < 8; k++){if (pMatrix[i] & (0x80 >> k)){printf("%c ", '*');}else{printf("  ");}}}pMatrix += i_steps;printf("\n");}printf("\n");}void SelectHZK(HzkInfo * pHzkInfo){SELECT:printf("Please select [0: Exit; 1: HZK16; 2: HZK32;] : ");scanf_s("%d", &(pHzkInfo->HzkSelect));if(pHzkInfo->HzkSelect == 0){exit(0);}if(pHzkInfo->HzkSelect < 1 || pHzkInfo->HzkSelect > 2){goto SELECT;}switch(pHzkInfo->HzkSelect){case 1:pHzkInfo->fileName = "Hzk16";pHzkInfo->HzkSquare = 16;break;case 2:pHzkInfo->fileName = "HZK32";pHzkInfo->HzkSquare = 32;break;}LoadHzkInfo(pHzkInfo);}void CleanupHzkInfo(HzkInfo hzkInfo){if(hzkInfo.pMatrix != NULL){fclose(hzkInfo.file);free(hzkInfo.pMatrix);hzkInfo.pMatrix = NULL;}}void LoadHzkInfo(HzkInfo * pHzkInfo){printf("Loading %s ... ", pHzkInfo->fileName);if ((fopen_s(&(pHzkInfo->file), pHzkInfo->fileName, "rb")) != 0){printf("Failed.\n");pHzkInfo->file = NULL;pHzkInfo->martixBytesCount = 0;pHzkInfo->pMatrix = NULL;}else{pHzkInfo->martixBytesCount = pHzkInfo->HzkSquare * pHzkInfo->HzkSquare / 8;pHzkInfo->pMatrix = (unsigned char *)malloc(pHzkInfo->martixBytesCount);if(pHzkInfo->pMatrix == NULL){printf("Malloc failed.\n");fclose(pHzkInfo->file);pHzkInfo->file = NULL;pHzkInfo->martixBytesCount = 0;pHzkInfo->pMatrix = NULL;return;}printf("Done.\n");}}

示範效果:


使用16*16 的字型檔:



使用32*32 的字型檔:


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.