GIMP - Xyzzy using python-fu

Data pubblicazione: 7-giu-2008 22.12.21

Python-fu really better than script-fu so I converted my scripts in python-fu for gimp.

Here python-fu for generating the texture 1 char-face: (much better since we can use utf-8 and we are consistent with lsl script)

#! /usr/bin/env python

from gimpfu import *

def python_log_init():

fileHandle = open( 'python.log', 'w')

fileHandle.close()

def python_log(s):

fileHandle = open ( 'python.log', 'a' )

fileHandle.write(str(s)+"\n")

fileHandle.close()

def python_xytext(font,color,size,limit):

"""Print the arguments on standard output"""

python_log_init()

python_log("font: %s color: <%d,%d,%d> size: %d limit: %d" % ( font, color[0], color[1], color[2], size, limit ))

chars = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ "

decode= ["\xC3\x87", "\xC3\xBC", "\xC3\xA9", "\xC3\xA2", "\xC3\xA4", "\xC3\xA0", "\xC3\xA5", "\xC3\xA7", "\xC3\xAA", "\xC3\xAB" ]

decode+=["\xC3\xA8", "\xC3\xAF", "\xC3\xAE", "\xC3\xAC", "\xC3\x84", "\xC3\x85", "\xC3\x89", "\xC3\xA6", "\xC3\xAE", "\xE2\x96\xB6" ]

decode+=["\xC3\xB6", "\xC3\xB2", "\xC3\xBB", "\xC3\xB9", "\xC3\xBF", "\xC3\x96", "\xC3\x9C", "\xC2\xA2", "\xC2\xA3", "\xC2\xA5"]

decode+=["\xC3\x82", "\xC2\xA9", "\xC3\xA1", "\xC3\xAD", "\xC3\xB3", "\xC3\xBA", "\xC3\xB1", "\xC3\x91", "\xC2\xAA", "\xC2\xBA"]

decode+=["\xC2\xBF", "\xC3\x94", "\xC2\xAC", "\xC2\xBD", "\xC2\xBC", "\xC2\xA1", "\xC2\xAB", "\xC2\xBB", "\xCE\xB1", "\xC3\x9F"]

decode+=["\xCE\x93", "\xCF\x80", "\xCE\xA3", "\xCF\x83", "\xC2\xB5", "\xCF\x84", "\xCE\xA6", "\xCE\x98", "\xCE\xA9", "\xCE\xB4"]

decode+=["\xE2\x88\x9E", "\xCF\x86", "\xCE\xB5", "\xE2\x88\xA9", "\xE2\x89\xA1", "\xC2\xB1", "\xE2\x89\xA5", "\xE2\x89\xA4", "\xE2\x8C\xA0", "\xE2\x8C\xA1"]

decode+=["\xC3\xB7", "\xE2\x89\x88", "\xC2\xB0", "\xC3\x8A", "\xC3\x8E", "\xC3\xB4", "\xC3\x9B", "\xC2\xB2", "\xE2\x82\xAC", "" ];

width=512

height=1024

img = gimp.Image(width, height, RGB)

layer = gimp.Layer(img, "my font", width, height, RGB_IMAGE, 100, NORMAL_MODE)

img.add_layer(layer, 0)

layer.add_alpha()

gimp.set_foreground(color)

pdb.gimp_selection_all(img)

pdb.gimp_edit_clear(layer)

pdb.gimp_selection_none(img)

index=0

extra=-1

#pdb.gimp_text_fontname(img,layer,50,50,"\xC3\x87",0,TRUE,size,PIXELS,font)

try:

for row in range(20):

for col in range(10):

if extra<0:

try:

el=chars[index]

index=index+1

except:

extra=0

if extra>-1:

el=decode[extra]

extra=extra+1

python_log(str(row)+","+str(col)+": "+el)

y=col*51.2+12

x=row*51.2+5

pdb.gimp_text_fontname(img,layer,y,x,el,0,TRUE,size,PIXELS,font)

except:

pass

# Now ready to display this image

img.merge_visible_layers(0)

gimp.Display(img)

register(

"xytext", "", "", "", "", "",

"<Toolbox>/Xtns/_XyText1Char", "",

[

(PF_FONT, "font", "Font to use", "Arial"),

(PF_COLOR,"color","Color to use", (255,255,255) ),

(PF_INT, "size", "Font size", 45 ),

(PF_INT, "limit", "limit font generation ", 180 ),

],

[],

python_xytext

)

main()