简 介: 本文给出了利用 DOP 获得文字坐标的的 DOP方法。
关键词
: 字符位置,DOP,显示
§01 文字坐标
为了实现 DOP 中文字逐步显示,需要获得每个文字的能够逐步显示,需要将所有的字符坐标。 下面给出了获得字符坐标的具体方法。
一、测试文字
下面是创建的测试文字。包括有汉字、英文字符,多行排列等。
▲ 图1.1 测试字符
二、处理程序
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# TEST1.PY -- by Dr. ZhuoQing 2022-08-18
#
# Note:
#============================================================
from headm import *
strid = 4
splitstr =tspgetdopstring(strid).split('\r\n')
#------------------------------------------------------------
def chineselen(s):
return int((len(s.encode('utf-8'))-len(s))/2)+len(s)
linenumber = len(splitstr)
maxlength = max([chineselen(s) for s in splitstr])
rect = tspgetbox(strid)
rectwidth = rect[2] - rect[0]
rectheight = rect[3] - rect[1]
boxdim = []
for i in range(linenumber):
lines = splitstr[i]
strlen = len(lines)
ystart = int(rectheight * i / linenumber + rect[1])
yend = int(rectheight * (i + 1) / linenumber + rect[1])
if strlen > 0:
for j in range(strlen):
xstart = int(chineselen(lines[0:j]) * rectwidth / maxlength + rect[0])
xend = int(chineselen(lines[0:j+1]) * rectwidth / maxlength + rect[0])
boxdim.append((xstart, ystart, xend, yend))
printf(len(boxdim))
printf(boxdim)
#------------------------------------------------------------
tspsetpen(color=0xff, width=1)
for b in boxdim:
tspbox(dc=1, x1=b[0], y1=b[1], x2=b[2], y2=b[3])
#------------------------------------------------------------
# END OF FILE : TEST1.PY
#============================================================
1、处理结果
使用上述办法,可以获得显示字符的每个字符的坐标。
▲ 图1.1.1 处理结果
※ 总 结 ※
本文给出了利用 DOP 获得文字坐标的的 DOP方法。
● 相关图表链接: