Я пытаюсь написать плагин, который будет создавать растровый шрифт. Тем не менее, это очень расстраивает, чтобы учиться ... пока я не знаком с python, не так сложно подобрать и не иметь проблем с ним за пределами GIMP.Плагины обычно не работают, как мне отлаживать?
скопировали кода из: https://github.com/sole/snippets/blob/master/gimp/generate_bitmap_font/sole_generate_bitmap_font.py и от http://gimpbook.com/scripting/
ли работа:
#!/usr/bin/env python
# Hello World in GIMP Python
from gimpfu import *
def create_font(cwidth, cheight, font, size, color) :
#Set GLOBAL
char_begin = 32
char_end = 127
num_chars = char_end - char_begin
# Figure out total width & height
"""twidth = cwidth * 10
theight = cheight * 10
# Create Image
img = gimp.Image(cwidth * 10, cheight * 10, RGB)
img.disable_undo()
# Save the current foreground color:
pdb.gimp_context_push()
# Set the text color & background color
gimp.set_foreground(color)
gimp.set_background(0, 0, 0)
# Create All Layers & Position Accordingly
for i in range(char_begin, char_end):
string = '%c' % i
offset = i - char_begin
x_pos = offset * cwidth
y_pos = offset * cheight
text_layer = pdb.gimp_text_fontname(img, None, x_pos, y_pos, string, -1, False, size, PIXELS, font)
gimp.progress_update(float(offset)/float(num_chars))
pdb.gimp_image_flatten(img)
img.enable_undo()
# Create a new image window
gimp.Display(img)
# Show the new image window
gimp.displays_flush()
# Restore the old foreground color:
pdb.gimp_context_pop()"""
register(
"python_fu_bitmap_font",
"Bitmap Font",
"Create a new bitmap font",
"*****",
"*****",
"2013",
"Bitmap Font (Py)...",
"", # Create a new image, don't work on an existing one
[
(PF_SPINNER, "cwidth", "Cell Width", 24, (1, 3000, 1)),
(PF_SPINNER, "cheight", "Cell Height", 51, (1, 3000, 1)),
(PF_FONT, "font", "Font face", "Consolas"),
(PF_SPINNER, "size", "Font size", 50, (1, 3000, 1)),
(PF_COLOR, "color", "Text color", (1.0, 0.0, 0.0))
],
[],
create_font, menu="<Image>/File/Create")
main()
Не работает:
#!/usr/bin/env python
# Hello World in GIMP Python
from gimpfu import *
def create_font(cwidth, cheight, font, size, color) :
#Set GLOBAL
char_begin = 32
char_end = 127
num_chars = char_end - char_begin
# Figure out total width & height
twidth = cwidth * 10
theight = cheight * 10
# Create Image
"""img = gimp.Image(cwidth * 10, cheight * 10, RGB)
img.disable_undo()
# Save the current foreground color:
pdb.gimp_context_push()
# Set the text color & background color
gimp.set_foreground(color)
gimp.set_background(0, 0, 0)
# Create All Layers & Position Accordingly
for i in range(char_begin, char_end):
string = '%c' % i
offset = i - char_begin
x_pos = offset * cwidth
y_pos = offset * cheight
text_layer = pdb.gimp_text_fontname(img, None, x_pos, y_pos, string, -1, False, size, PIXELS, font)
gimp.progress_update(float(offset)/float(num_chars))
pdb.gimp_image_flatten(img)
img.enable_undo()
# Create a new image window
gimp.Display(img)
# Show the new image window
gimp.displays_flush()
# Restore the old foreground color:
pdb.gimp_context_pop()"""
register(
"python_fu_bitmap_font",
"Bitmap Font",
"Create a new bitmap font",
"*****",
"*****",
"2013",
"Bitmap Font (Py)...",
"", # Create a new image, don't work on an existing one
[
(PF_SPINNER, "cwidth", "Cell Width", 24, (1, 3000, 1)),
(PF_SPINNER, "cheight", "Cell Height", 51, (1, 3000, 1)),
(PF_FONT, "font", "Font face", "Consolas"),
(PF_SPINNER, "size", "Font size", 50, (1, 3000, 1)),
(PF_COLOR, "color", "Text color", (1.0, 0.0, 0.0))
],
[],
create_font, menu="<Image>/File/Create")
main()
Похоже, что после изменения начало комментария от строка 15 на строку 19, что все идет в ад. И, честно говоря, я даже не уверен, как отладить это. Я попытался использовать консоль в разделе «Фильтры»> «Python-Fu»> «Консоль» - однако это продолжало говорить мне, что строка 1 была проблемой ..., о которой я думаю, мы все можем согласиться, это не так.
Я попытался запустить фрагменты этого кода в скрипте python и отлично работает.
Что мне делать?
Почему вы создаете большую строку без причины? Это ваш способ прокомментировать код? О shebang, вы пытались его удалить? Возможно, GIMP на самом деле пытается что-то сделать. Можете ли вы опубликовать трассировку или другую информацию о том, что именно происходит? – Paco
@Paco Какая большая строка? Я пытаюсь создать изображение со всеми 95 Chars на нем. - Шебанг иногда работает, но стараюсь. (РЕЗУЛЬТАТ: РАБОТАЕТ) - Ну, я думаю, это сработало, и я думаю, что строка 1 была проблемой. Хм ... Позвольте мне поиграть с этим в течение следующих 24 часов, чтобы быть уверенным. – Zeveso
Написал ответ, чтобы отобразить большую строку, а также с моим ответом, который я дал в комментариях – Paco