使用了UCDOS的HZK16字库,我已经打包上传,请大家下载附件使用。
13-09-21:WIN7下输出空格出错,更改了默认的前景和背景字符- ::只支持简体汉字,如果输入其它字符,转换结果将会出现错误。
- ::一次最多只能转换四个汉字,如多于四个则取前四个。
- ::09-11-18:同时支持最多四个汉字的转换,并且横向输出。
- ::09-11-18:删去了对汉字区位码、机内码、字模的显示。
- ::09-11-18:添加了前景及背景字符的设定。注意,设置时请统一前景及背景字符的字节数。
- @echo off&setlocal EnableDelayedExpansion&cls
- mode con: cols=129 lines=27
- title code by foxj @ bbs.bathome.cn
- if not exist hzk16 (echo.无法找到HZK16字库文件。请把HZK16与此脚本放至同一目录下。&pause>nul&exit)
- :start
- cls
- set /p HZ=输入所要转换的汉字(最多四个):
- if "%hz%"=="" (echo 请重新输入,按任意键返回。& pause>nul&goto start)
- set /p Qj=设置前景字符(默认为█):
- if "%Qj%"=="" set qj=█
- set /p Bj=设置背景字符(默认为□):
- if "%Bj%"=="" (set bj=□)
- set hz=%hz: =%
- set hz=%hz:~0,4%
- set hznum=0
- for /l %%i in (0,1,3) do (if not "!hz:~%%i,1!"=="" (set /a hznum+=1))
- set /a hznum-=1
- for /l %%d in (0,1,%hznum%) do (
- call :bin !hz:~%%d,1!
- set bin_2=!bin_2:0=%BJ%!
- set bin_2=!bin_2:1=%QJ%!
- set bin%%d=!bin_2!
- )
- ::输出点阵字体
- echo.&for /l %%i in (1,1,64) do (set/p=━<nul)
- echo.&echo.
- for /l %%i in (1,1,16) do (
- for /l %%j in (0,1,%hznum%) do (call set /p=%%bin%%j:~!n!,16%%<nul)
- set /a n=%%i*16
- echo.)
- echo.&for /l %%i in (1,1,64) do (set/p=━<nul)
- ::echo.完成,按任意键重新开始。
- pause>nul&goto start
-
- :bin
- ::计算文字区位码
- (set hzqwm=)
- for /f "delims=" %%i in ('findstr "%1" HZK16') do (
- for %%j in (%%i) do (
- set hzqwm=%%j&set hzqwm=!hzqwm:^(=!&set hzqwm=!hzqwm:^)=!&set hzqwm=!hzqwm:%1=!
- set /a 3/!hzqwm!>nul 2>nul && set qwm=!hzqwm!
- )
- )
- if "%hzqwm%"=="" echo.“%1”不在转换字符集,无法完成转换。& (set hzqwm=nosw) & goto :eof
- call :nxn "%qwm:~0,2%" qwm_1 10 16
- call :nxn "%qwm:~2,4%" qwm_2 10 16
- set qwm_3=0000%qwm_1%
- set qwm_4=0000%qwm_2%
- set qwm_1=%qwm_3:~-2%%qwm_4:~-2%
- call :nxn "%qwm_1%" qwm_2 16 10
- ::计算文字机内码
- set /a jlm_1=qwm_2+8224+32896
- call :nxn "%jlm_1%" jlm_2 10 16
- ::计算文字在字库中的偏移量
- call :nxn "%jlm_2:~0,2%" py_1 16 10
- call :nxn "%jlm_2:~2,4%" py_2 16 10
- set /a py_q=py_1-161,py_w=py_2-161
- set /a py=(py_q*94+py_w)*2-1
- set /a py2=py+1
- ::查找字节编码
- set na=0
- ::echo. "%1"的区位码:%qwm%,内码:%jlm_2%
- for /l %%a in (!py!,1,!py2!) do (
- for /f "delims=" %%i in ('findstr /n .* hzk16 ^| findstr "%%a:"') do (
- set "var1=%%i" & call set var1=%%var1:*:=%%
- set /a na+=1
- set na!na!=!var1!
- )
- )
- if %na% GTR 2 (set var2=!na1! !na3!) else (set var2=!na1! !na2!)
- (set bin_1=) & (set bin_2=)
- for %%j in (!var2!) do (
- call :nxn "%%j" bin 16 2
- set bin_1=00000000!bin!
- set bin_2=!bin_2!!bin_1:~-8!
- )
- goto :eof
-
- ::任意进制数互换,code by 随风
- :nXn 任意进制互转 @随风 @bbs.bathome.cn(封装)
- @echo off&setlocal enabledelayedexpansion
- if "%~4"=="" (set /a q=10,h=2)else (set /a q=%~3,h=%~4)
- set "str=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- for /l %%a in (0 1 35)do set .%%a=!str:~%%a,1!&set ".!str:~%%a,1!=%%a"
- set sun=&set jie=&set "var=%~1"&set /a nnn=1,num=0
- for /l %%a in (0 1 100) do (
- if not "!var:~%%a,1!"=="" (call set sun=%%.!var:~%%a,1!%% !sun!))
- for %%a in (!sun!) do set /a num=%%a*nnn+num,nnn*=q
- :10进制转n进制
- set /a yu=num%%h,num/=h
- set "jie=!.%yu%!!jie!"&if !num! gtr 0 goto 10进制转n进制
- endlocal&set %~2=%jie%&goto :EOF
复制代码 链接: https://pan.baidu.com/s/1Pq1_AFPTgFQxXJ9ZYc2I4Q 提取码: 67rk |