去掉点阵字体中的斜线

前段时间修改MTK平板进去,Recovery模式是字体大小,由于先前是用的是8*16的点整字体,在高分辨率的屏幕显示比较小。故通过找到大的字库更换对应的字体,目前网上自动生成的ASCII字符工具,不注册的情况下会有斜线,因此使用下面脚本去除对应的斜线。

#!/usr/bin/python
# coding=UTF-8
import re
######
FontSrc = "26x48_36.C"
FontSpace = "demo.h"
####设置字体大小
size_w = 24
size_h = 48
### 判断参数是否有传入尺寸参数
def get_font_size(x,y):
if not isinstance(x,(int)):
return
if not isinstance(y,(int)):
return
if (x > y):
size_w = y
size_h = x
else:
size_w = x
size_h = y
return

###########打开对应的文件 需要转换的文件, 对应的参考斜线文件
###########函数返回读取到的文件内容
def openFontFiles(src):
openFile = open ( src,‘r‘ )
try:
all_the_text = openFile.read( )
print(‘=====lixin=====\n‘)
print( all_the_text)
#######退出前关闭文件
openFile.close( )
return all_the_text
finally:
openFile.close( )
return all_the_text
# raise TypeError(‘open file filed! %s‘ % src)
# return ‘open file filed!‘

#########字符穿处理函数,将字符串处理为对应的数组
def getFontNumList(datas):
####匹配最大的"\/\*.*\*\/"---最大的/**/ "\/\*.{,15}\*\/"---/**/中间最多15个字符 "\,$"---文件末尾逗号
C_Rule = "(\/\*.{,15}\*\/)|(\,$)"
#去掉空格跟换行符 依次去掉 空格 制表符 换行 .replace(‘ ‘,‘‘).replace(‘\t‘,‘‘).replace(‘\n‘,‘‘)
temp_text = datas.replace(‘ ‘,‘‘).replace(‘\t‘,‘‘).replace(‘\n‘,‘‘).replace(‘\r‘,‘‘)
#######去掉注释 最后面的一个逗号
temp_text = re.sub(C_Rule, ‘‘, temp_text)
dataList = temp_text.split(‘,‘)
print("*************************\n %s" % dataList )
####将字符串 转换为16进制数
#####直接 将列表中的字符串转换为数字 转换后是十进制 需要其他格式可以定义对应的 eval 函数即可
list_num = map(eval,dataList)
print("*************************" )
print( list_num )
return list_num

##################数据的斜线是或操作 先异或 去掉应的斜线
def removeSlashData(list_temp,list_base):
for index in range(len(list_base)):
list_temp[index] = list_temp[index]^list_base[index]
#print(list_temp)
return list_temp

####补点
def modifyFontData(list_temp,list_base):
for row in range(size_h):
for col in range(size_w/8):
######跟据字符特点采用权值的方式 判定 斜线为做斜线 相邻的 上,下,左,右 左下 右上 如果有两个地方有点则补上
#######需要补点的地方为基准为1的地方
dot_lev = 0
if(list_base[row*(size_w/8) + col]):
##有点的地方需要补点 1,判断 上 第一行没有
if(row-1):
if(list_temp[(row-1)*(size_w/8) + col] & list_base[row*(size_w/8) + col]):
####在同一个位置有点
dot_lev += 1
####2,判断 下 排除 最后一行
if((row+1) < size_h):
if(list_temp[(row+1)*(size_w/8) + col] & list_base[row*(size_w/8) + col]):
####在同一个位置有点
dot_lev += 1
####3,判断 左 排除 第一列
if(col-1):
#####在一个字节的最di位的情况 存储是依次增加的
if(list_base[row*(size_w/8) + col] & 1 ):
if(list_temp[row*(size_w/8) + col] & ( 1 << 7) ):
####在同一个位置有点
dot_lev += 1
else:
if(list_temp[row*(size_w/8) + col] & ( list_base[row*(size_w/8) + col] >> 1 ) ):
####在同一个位置有点
dot_lev += 1
####4,判断 右 排除 最后一列
if((col+1) != size_w/8):
######在一个字节的最gao位的情况
if(list_base[row*(size_w/8) + col] & (1<<7)):
if(list_temp[row*(size_w/8) + col+1] & 1 ):
####在同一个位置有点
dot_lev += 1
else:
if(list_temp[row*(size_w/8) + col] & ( list_base[row*(size_w/8) + col] << 1 ) ):
####在同一个位置有点
dot_lev += 1
####5,判断 左下 排除 最后一行 最后一列
####6,判断 右上 排除 第一行 第一列
###补点
if(dot_lev >= 2):
print(‘----%d-----‘ % dot_lev)
list_temp[row*(size_w/8) + col] = list_temp[row*(size_w/8) + col] | list_base[row*(size_w/8) + col]
#####else 为零的地方不需要补点
#print("removeSlashData")
### print(list_temp)
return list_temp

#########数据处理去除字体中的斜线 传入需要处理的list_src 以及参考的list_base
def dealDats(list_src,list_base):
####最后合成数据
list_result = []
list_src_temp = []
baseLen = len(list_base)
print(len(list_base))
if (len(list_base) != size_w*size_h/8):
raise TypeError(‘base is wrong! dealDats‘)
#### 将数据分割为一段一段以list_base 长度
for split_index in range(len(list_src)/baseLen):
#print("===%d %d" %(len(list_src),baseLen))
#print(len(list_src)/baseLen)
list_src_temp = list_src[(baseLen*split_index):(baseLen*(split_index+1))]

#####数据的斜线是或操作 先异或 去掉应的斜线
list_src_temp = removeSlashData(list_src_temp,list_base)
#print(len(list_src_temp))
#print(list_src_temp)
####补点
list_src_temp = modifyFontData(list_src_temp,list_base)
#print("================")
#print(len(list_src_temp))
#print(list_src_temp)
#####合成数据 L1.extend(L2)
list_result.extend(list_src_temp)
return list_result

######将生成的数字转换为需要的格式
#####将数字转换为对用的0xXX 格式
def intToString(data):
return (‘0x%02x‘ % data)

def numTostring(list_src):
###将数字转换为对用的0xXX 的string格式
list_hex = map(intToString,list_src)
#print(list_hex)
return list_hex

#######保存文件 传入文件名 以及字符串
def writeFontFile(fileName,datas):
file_write= open( fileName, ‘w‘)
file_write.write(datas)
file_write.close()
return

#####将列表数据保存
def saveResult(fileName,list_src,comments):
###将列表直接变成字符串 然后去掉单引号
#datas = str(list_src).replace(‘\‘‘,‘‘)
#print(list_src)
datas = ‘‘
####生成的格式采用一个字体一个块 同时一个字体以每行16字节一行
for block in range(len(list_src)/(size_h*size_w/8)):
#### 为每一个块添加注释 可以将对应文件中的信息取出来
datas += data_comment[block] + ‘\n‘
for index in range(size_h*size_w/8):
#if(index%16 == 0):
###块的最后一个加上换行 并行条件要用英文
if((index%16 == 15) or (index+1) == (size_h*size_w/8)):
datas += list_src[block*(size_h*size_w/8) + index] + ‘,\n‘
else:
datas += list_src[block*(size_h*size_w/8) + index] + ‘,‘
#print(datas)
writeFontFile(fileName,datas)
return

###################################main 流程 #################
#get_font_size($1,$2)
text_space = openFontFiles(FontSpace)
list_space = getFontNumList(text_space)
print(list_space)
print(len(list_space))
text_src = openFontFiles(FontSrc)
list_src = getFontNumList(text_src)
##########将文件中的注释取出来存放到对应的列表中
###注意表达式不要带括号
data_comment = re.findall(r‘\/\*.{,15}\*\/‘,text_src)
print(list_src)
print(len(list_src))
last_data = dealDats(list_src,list_space)
last_text = numTostring(last_data)
#print(last_text)
saveResult(‘result.h‘,last_text,data_comment)
print("#############################")
#print(last_data)
#print(last_text)
print(len(last_data))

时间: 2024-07-29 07:46:06

去掉点阵字体中的斜线的相关文章

Windows7 系统 CMD命令行,点阵字体不能改变大小以及中文乱码的问题

之前装了oracle 11g后,发现开机速度竟然奇葩的达到了3分钟.经过旁边大神指点,说是因为oracle某个(具体不清楚)服务,在断网的时候会不断的ping网络,导致速度变慢.然后就关服务呗,然后一不小心,就将CMD窗口弄出问题了.中文乱码,字体还非常小.于是各种百度啊,还根据网上的方法设置了个新宋体.如图 地址 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Console\TrueTypeFont.后来发现设置不

点阵字体显示系列之二:汉字显示

免责声明: 本文是作者在研究过程中的一篇文章,本着互联网共享.自由(free,应该不是“免费”)之精神发布于此.作者才疏学浅,孤陋寡闻,能力有限,对文中出现的术语及概念的描述多有不当之处,由于本文并非学术报告及论文,不对这些概念性东西进行深入调研,如需权威性解释,请自行查阅相关文献.文中错误的地方,欢迎在文后留言,趁作者还有激情研究之时,大家一直探讨,共同学习,天天向上. 计算机中存在许多种格式的编码,比如ASCII.GB2312.GBK.UTF-8,等等.汉字以“内码”的形式存储于计算机中.对

【STM32H7教程】第52章 STM32H7的LTDC应用之点阵字体和字符编码(重要)

完整教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=86980 第52章       STM32H7的LTDC应用之点阵字体和字符编码(重要) 本章节主要为大家讲解ASCII字符集,ASCII扩展字符集,GB2312字符集,GBK字符集和Unicode字符集.其中,字符编码这块涉及到的知识点非常多,特别是Unicode字符集的编码,涉及到的知识点极其多.大家如果有精力的话,最好可以花点时间把Unicode的发展史捋清楚了.本章节笔

去掉有序数组中重复数字 原地 leetcode java (最简单的方法)

1.利用荷兰国旗的思路,每次记住最后一个位置,遇到一个不重复的数,放在它后面,代码很简单. Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with consta

怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: &#39;NSInteger&#39; (aka &#39;long&#39;) to &#39;int32

在我们的项目中,通常使用了大量的第三方代码,这些代码可能很复杂,我们不敢改动他们,可是作者已经停止更新了,当sdk升级或者是编译器升级后,这些遗留的代码可能会出现许许多多的警告,那么我们有没有办法去掉这些烦人的警告,不然一个工程几百个警告,你看着怎么都不爽吧.我们怎么去掉警告呢 1.最直接,最一劳永逸,最安全的方式,直接找到警告的那段代码,改为不警告.这个方式,最安全. 可是它有一个问题,就是,当我们很多文件都有这种类型的警告的时候,我们就需要改动很多很多的源码了, 对于不是我们写的源码,有可能

IOS 去掉代码html中的标签元素,获得纯文本

content是根据网址获得的网页源码字符串    NSRegularExpression *regularExpretion=[NSRegularExpression regularExpressionWithPattern:@"<[^>]*>|\n"  options:0  error:nil]; //替换所有html和换行匹配元素为"-"        content=[regularExpretion stringByReplacingMa

C#中怎么在EXCEL中的单元格中画斜线啊 ??

Code Snippet 做法: 1,先添加引用COM,找 Excel 2,using Excel = Microsoft.Office.Interop.Excel; 3, 代码 private Excel.Application m_objExcel = null;        private Excel.Workbooks m_objBooks = null;        private Excel._Workbook m_objBook = null;        private E

如何去掉[email&#160;protected]中的@符号Linux文件扩展信息

如何去掉[email protected]中的@符号Linux文件扩展信息ls -lart [email protected] 10 rlanffy staff 340B 3 6 2015 [email protected] 1 rlanffy staff 630B 6 10 17:22 [email protected] 1 rlanffy staff 4.8K 8 12 14:17 [email protected] 3 rlanffy staff 102B 8 14 12:10 [emai

如何去掉Json字符串中反斜杠

在做项目中,前台传来的数据为Json字符串,因为没有合适的实体来这些字段,所有就用了最简单的方式:截取字符串. 前台Json字符串为: <span style="font-size:18px;">string s1 ="[{\"ID\":\"99d2a341-ea2e-4f04-b4f4-623153d64336\",\"Name\":\"王五\",\"TotalScores