Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created May 15, 2014 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/4c87237697e2080b789d to your computer and use it in GitHub Desktop.
Save zeffii/4c87237697e2080b789d to your computer and use it in GitHub Desktop.
import bpy
from mathutils import Vector
fontdict = {}
for c in bpy.data.curves[1:]:
fontdict[c.name] = []
for idx, spline in enumerate(c.splines):
stroke = [p.co.to_tuple() for p in spline.points]
fontdict[c.name].append(stroke)
fdict = {
'a': 'NurbsPath.001',
'b': 'NurbsPath.002',
'c': 'NurbsPath.003',
'd': 'NurbsPath.004',
'e': 'NurbsPath.005',
'f': 'NurbsPath.006',
'g': 'NurbsPath.007',
'h': 'NurbsPath.008',
'i': 'NurbsPath.009',
'j': 'NurbsPath.010',
'k': 'NurbsPath.011',
'l': 'NurbsPath.012',
'm': 'NurbsPath.013',
'n': 'NurbsPath.014',
'o': 'NurbsPath.015',
'p': 'NurbsPath.016',
'q': 'NurbsPath.017',
'r': 'NurbsPath.018',
's': 'NurbsPath.019',
't': 'NurbsPath.020',
'u': 'NurbsPath.021',
'v': 'NurbsPath.022',
'w': 'NurbsPath.023',
'x': 'NurbsPath.024',
'y': 'NurbsPath.025',
'z': 'NurbsPath.026',
'0': 'NurbsPath.027',
'1': 'NurbsPath.028',
'2': 'NurbsPath.029',
'3': 'NurbsPath.030',
'4': 'NurbsPath.031',
'5': 'NurbsPath.032',
'6': 'NurbsPath.033',
'7': 'NurbsPath.034',
'8': 'NurbsPath.035',
'9': 'NurbsPath.036',
'!': 'NurbsPath.037',
'?': 'NurbsPath.038',
'#': 'NurbsPath.039',
'%': 'NurbsPath.040',
'&': 'NurbsPath.041',
'$': 'NurbsPath.042',
'@': 'NurbsPath.043',
'*': 'NurbsPath.044',
'{': 'NurbsPath.045',
'(': 'NurbsPath.046',
'/': 'NurbsPath.047',
'|': 'NurbsPath.048',
"\\": 'NurbsPath.049',
')': 'NurbsPath.050',
'}': 'NurbsPath.051',
'.': 'NurbsPath.052',
',': 'NurbsPath.053'
}
def font_map(ch, fontdict):
remapable = fdict.get(ch, None)
if remapable:
return fontdict[remapable]
else:
print(repr(ch), 'not fond in charmap')
return
def generate_greasepencil(text, col, pxwide, pos, fontdict):
line_height = 30
char_width = pxwide
spaces = 0
yof = 0
xof = 0
bcx, bcy = pos
nt = bpy.data.node_groups['NodeTree.002']
gp = nt.grease_pencil = bpy.data.grease_pencil.new('temp')
layer = gp.layers.new('damzel')
layer.frames.new(1)
for ch in text:
if spaces > 3:
# drop line after 3 spaces
yof -= line_height
xof = 0
if ch == " ":
spaces += 1
continue
chain = font_map(ch, fontdict)
if not chain:
xof += charwidth
continue
# set drawwidth too?
# set color
s = layer.frames[0].strokes.new()
s.draw_mode = '2DSPACE'
s.points.add(len(chain))
for idx, p in enumerate(chain):
ap = Vector(p)*25
x, y = ap[:2]
xyz = ((x+bcx+xof), (y+bcy+yof), 0)
s.points[idx].co = xyz
xof += charwidth
text = "tis but a name and nothing more!"
col = []
pxwide = 28
pos = 50, 50
generate_greasepencil(text, col, pxwide, pos, fontdict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment