initial commit
This commit is contained in:
commit
f04f3a8ae9
18 changed files with 4577 additions and 0 deletions
46
python/textgrid/_pack_style.py
Normal file
46
python/textgrid/_pack_style.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
from array import array
|
||||
|
||||
_xterm = [
|
||||
(0, 0, 0), (205, 0, 0), (0, 205, 0), (205, 205, 0),
|
||||
(0, 0, 238), (205, 0, 205), (0, 205, 205), (229, 229, 229),
|
||||
(127, 127, 127), (255, 0, 0), (0, 255, 0), (255, 255, 0),
|
||||
(92, 92, 255), (255, 0, 255), (0, 255, 255), (255, 255, 255),
|
||||
]
|
||||
_grad = [0, 95, 135, 175, 215, 255]
|
||||
for _i in range(216):
|
||||
_xterm.append((_grad[_i // 36 % 6], _grad[_i // 6 % 6], _grad[_i % 6]))
|
||||
for _i in range(24):
|
||||
_v = 8 + _i * 10
|
||||
_xterm.append((_v, _v, _v))
|
||||
|
||||
|
||||
def _pack_one(s):
|
||||
fg = s.fg_color
|
||||
if isinstance(fg, tuple):
|
||||
fv = (fg[0] << 24) | (fg[1] << 16) | (fg[2] << 8)
|
||||
else:
|
||||
r, g, b = _xterm[fg]
|
||||
fv = (r << 24) | (g << 16) | (b << 8)
|
||||
bg = s.bg_color
|
||||
if isinstance(bg, tuple):
|
||||
bv = (bg[0] << 24) | (bg[1] << 16) | (bg[2] << 8)
|
||||
else:
|
||||
r, g, b = _xterm[bg]
|
||||
bv = (r << 24) | (g << 16) | (b << 8)
|
||||
attr = (s.is_bold << 0) | (s.is_italic << 1) | (s.is_underlined << 2)
|
||||
return fv, bv, attr
|
||||
|
||||
|
||||
def pack_style_colors(style):
|
||||
n = len(style)
|
||||
first = style[0]
|
||||
if n > 1 and all(s is first for s in style):
|
||||
fv, bv, attr = _pack_one(first)
|
||||
return array('I', [fv, bv, attr] * n)
|
||||
out = array('I')
|
||||
for s in style:
|
||||
fv, bv, attr = _pack_one(s)
|
||||
out.append(fv)
|
||||
out.append(bv)
|
||||
out.append(attr)
|
||||
return out
|
||||
Loading…
Add table
Add a link
Reference in a new issue