diff --git a/backend/ontario/ontario/__init__.py b/backend/ontario/ontario/__init__.py index b457dd2..03db726 100644 --- a/backend/ontario/ontario/__init__.py +++ b/backend/ontario/ontario/__init__.py @@ -393,6 +393,32 @@ def tileglass(self, width: int, height: int) -> "ImageBuilder": self.__nodes.append(node) return self + def text(self, + string: str, + font: str, + size: float, + color: tuple, + wrap_width: int, + wrap_height: int, + alignment: int, + vert_alignment: int): + """ + Produce text pixel buffer + """ + + node = self.__parent.create_child("gegl:text") + node.set_property("string", string) + node.set_property("font", font) + node.set_property("size", size) + node.set_property("color", Gegl.Color.new(color)) + node.set_property("wrap_width", wrap_width) + node.set_property("wrap_height", wrap_height) + node.set_property("alignment", alignment) + node.set_property("vert_alignment", vert_alignment) + + self.__nodes.append(node) + return node.get_property("width"), node.get_property("height") + def perspective_transform( self, x0: float, diff --git a/gimp/pictonode-gimp-plugin/GIMP 2.99/pictonode/custom_nodes.py b/gimp/pictonode-gimp-plugin/GIMP 2.99/pictonode/custom_nodes.py index 26449fd..af82c99 100644 --- a/gimp/pictonode-gimp-plugin/GIMP 2.99/pictonode/custom_nodes.py +++ b/gimp/pictonode-gimp-plugin/GIMP 2.99/pictonode/custom_nodes.py @@ -40,6 +40,15 @@ gi.require_version("GLib", "2.0") from gi.repository import GLib # noqa + +gi.require_version('Gimp', '3.0') +from gi.repository import Gimp # noqa + +gi.require_version("GObject", "2.0") +from gi.repository import GObject # noqa + +gi.require_version('Gegl', '0.4') +from gi.repository import Gegl # noqa # autopep8 on # node classes based on examples from img.py in the gtknodes project @@ -177,8 +186,8 @@ def process(self): self.image_builder = ontario.ImageBuilder(self.image_context) print("Buffer: ", self.buffer) - self.node_window.buffer_map[self.buffer_id] = [self.buffer, - self.layer] + self.node_window.buffer_map[self.buffer_id] = [self.buffer] + if self.buffer: return True return False @@ -365,7 +374,6 @@ def __init__(self, node_window, *args, **kwds) -> None: self.node_window = node_window self.buffer_id = str(uuid.uuid1()) self.buffer = None - self.layer = None # initialize our image context for the gegl nodes self.image_context = ontario.ImageContext() @@ -412,7 +420,7 @@ def process_ouput(self): ''' print("Buffer: ", self.buffer) - self.node_window.buffer_map[self.buffer_id] = [self.buffer, self.layer] + self.node_window.buffer_map[self.buffer_id] = [self.buffer] if self.buffer: return True @@ -439,7 +447,6 @@ def node_socket_disconnect(self, socket, sink): self.incoming_buffer_id = None self.incoming_buffer = None self.buffer = None - self.layer = None self.process_input() def node_socket_connect(self, sink, source): @@ -458,7 +465,6 @@ def node_socket_incoming(self, socket, payload): self.incoming_buffer_id = None self.incoming_buffer = None self.buffer = None - self.layer = None # set new buffer information if payload: @@ -469,9 +475,6 @@ def node_socket_incoming(self, socket, payload): self.incoming_buffer = self.node_window.buffer_map.get( self.incoming_buffer_id)[0] - self.layer = self.node_window.buffer_map.get( - self.incoming_buffer_id)[1] - print("Invert Incoming: ", self.incoming_buffer) self.process_input() @@ -496,7 +499,6 @@ def __init__(self, node_window, *args, **kwds) -> None: # initialize output buffer and layer self.buffer = None - self.layer = None # default operation arguments self.x: float = 0.0 @@ -676,7 +678,7 @@ def process_ouput(self): ''' print("Buffer: ", self.buffer) - self.node_window.buffer_map[self.buffer_id] = [self.buffer, self.layer] + self.node_window.buffer_map[self.buffer_id] = [self.buffer] if self.buffer: return True @@ -708,7 +710,6 @@ def node_socket_disconnect(self, socket, sink, datasource): self.incoming_buffer2 = None self.buffer = None - self.layer = None self.process_input() def node_socket_connect(self, sink, source): @@ -732,7 +733,6 @@ def node_socket_incoming(self, socket, payload, datasource): self.incoming_buffer2 = None self.buffer = None - self.layer = None # set new buffer information if payload: @@ -748,9 +748,6 @@ def node_socket_incoming(self, socket, payload, datasource): self.incoming_buffer2 = self.node_window.buffer_map.get( self.incoming_buffer2_id)[0] - self.layer = self.node_window.buffer_map.get( - self.incoming_buffer1_id)[1] - print("Comp Incoming 1: ", self.incoming_buffer1) print("Comp Incoming 2: ", self.incoming_buffer2) @@ -768,7 +765,6 @@ def __init__(self, node_window, *args, **kwds) -> None: self.node_window = node_window self.buffer_id = str(uuid.uuid1()) self.buffer = None - self.layer = None # default operation arguments self.std_dev_x: float = 1.5 @@ -855,7 +851,7 @@ def process_ouput(self): ''' print("Buffer: ", self.buffer) - self.node_window.buffer_map[self.buffer_id] = [self.buffer, self.layer] + self.node_window.buffer_map[self.buffer_id] = [self.buffer] if self.buffer: return True @@ -912,7 +908,6 @@ def node_socket_disconnect(self, socket, sink): self.incoming_buffer_id = None self.incoming_buffer = None self.buffer = None - self.layer = None self.process_input() def node_socket_connect(self, sink, source): @@ -931,7 +926,6 @@ def node_socket_incoming(self, socket, payload): self.incoming_buffer_id = None self.incoming_buffer = None self.buffer = None - self.layer = None # set new buffer information if payload: @@ -942,9 +936,6 @@ def node_socket_incoming(self, socket, payload): self.incoming_buffer = self.node_window.buffer_map.get( self.incoming_buffer_id)[0] - self.layer = self.node_window.buffer_map.get( - self.incoming_buffer_id)[1] - print("Invert Incoming: ", self.incoming_buffer) self.process_input() @@ -961,7 +952,6 @@ def __init__(self, node_window, *args, **kwds) -> None: self.node_window = node_window self.buffer_id = str(uuid.uuid1()) self.buffer = None - self.layer = None # default operation arguments self.brightness: float = 0.0 @@ -1048,7 +1038,7 @@ def process_ouput(self): ''' print("Buffer: ", self.buffer) - self.node_window.buffer_map[self.buffer_id] = [self.buffer, self.layer] + self.node_window.buffer_map[self.buffer_id] = [self.buffer] if self.buffer: return True @@ -1118,7 +1108,6 @@ def node_socket_disconnect(self, socket, sink): self.incoming_buffer_id = None self.incoming_buffer = None self.buffer = None - self.layer = None self.process_input() def node_socket_connect(self, sink, source): @@ -1137,7 +1126,6 @@ def node_socket_incoming(self, socket, payload): self.incoming_buffer_id = None self.incoming_buffer = None self.buffer = None - self.layer = None # set new buffer information if payload: @@ -1148,9 +1136,6 @@ def node_socket_incoming(self, socket, payload): self.incoming_buffer = self.node_window.buffer_map.get( self.incoming_buffer_id)[0] - self.layer = self.node_window.buffer_map.get( - self.incoming_buffer_id)[1] - print("Invert Incoming: ", self.incoming_buffer) self.process_input() @@ -1166,7 +1151,6 @@ def __init__(self, node_window, *args, **kwds) -> None: self.node_window = node_window self.buffer_id = str(uuid.uuid1()) self.buffer = None - self.layer = None # default operation arguments self.x_offset: float = 20.0 @@ -1273,7 +1257,7 @@ def process_ouput(self): ''' print("Buffer: ", self.buffer) - self.node_window.buffer_map[self.buffer_id] = [self.buffer, self.layer] + self.node_window.buffer_map[self.buffer_id] = [self.buffer] if self.buffer: return True @@ -1332,7 +1316,6 @@ def node_socket_disconnect(self, socket, sink): self.incoming_buffer_id = None self.incoming_buffer = None self.buffer = None - self.layer = None self.process_input() def node_socket_connect(self, sink, source): @@ -1351,7 +1334,6 @@ def node_socket_incoming(self, socket, payload): self.incoming_buffer_id = None self.incoming_buffer = None self.buffer = None - self.layer = None # set new buffer information if payload: @@ -1362,9 +1344,6 @@ def node_socket_incoming(self, socket, payload): self.incoming_buffer = self.node_window.buffer_map.get( self.incoming_buffer_id)[0] - self.layer = self.node_window.buffer_map.get( - self.incoming_buffer_id)[1] - print("Buffer Incoming: ", self.incoming_buffer) self.process_input() @@ -1381,7 +1360,6 @@ def __init__(self, node_window, *args, **kwds) -> None: self.node_window = node_window self.buffer_id = str(uuid.uuid1()) self.buffer = None - self.layer = None # default operation arguments self.size: int = 32 @@ -1535,7 +1513,7 @@ def process_ouput(self): ''' print("Buffer: ", self.buffer) - self.node_window.buffer_map[self.buffer_id] = [self.buffer, self.layer] + self.node_window.buffer_map[self.buffer_id] = [self.buffer] if self.buffer: return True @@ -1593,7 +1571,6 @@ def node_socket_disconnect(self, socket, sink): self.incoming_buffer_id = None self.incoming_buffer = None self.buffer = None - self.layer = None self.process_handler() def node_socket_connect(self, sink, source): @@ -1612,7 +1589,6 @@ def node_socket_incoming(self, socket, payload): self.incoming_buffer_id = None self.incoming_buffer = None self.buffer = None - self.layer = None # set new buffer information if payload: @@ -1623,9 +1599,6 @@ def node_socket_incoming(self, socket, payload): self.incoming_buffer = self.node_window.buffer_map.get( self.incoming_buffer_id)[0] - self.layer = self.node_window.buffer_map.get( - self.incoming_buffer_id)[1] - print("Buffer Incoming: ", self.incoming_buffer) self.process_handler() @@ -1641,7 +1614,6 @@ def __init__(self, node_window, *args, **kwds) -> None: self.node_window = node_window self.buffer_id = str(uuid.uuid1()) self.buffer = None - self.layer = None # default operation arguments self.width: int = 25 @@ -1772,7 +1744,7 @@ def process_ouput(self): ''' print("Buffer: ", self.buffer) - self.node_window.buffer_map[self.buffer_id] = [self.buffer, self.layer] + self.node_window.buffer_map[self.buffer_id] = [self.buffer] if self.buffer: return True @@ -1793,18 +1765,16 @@ def entry_change(self, entry, entry_id, default, max, min): value = min elif value > max: entry.set_text(str(max)) - value = 1.0 + value = max except ValueError: entry.set_text(str(default)) value = default # set new value for variable associated with entry if entry_id == 1: - self.size = value + self.width = value elif entry_id == 2: - self.smoothness = value - elif entry_id == 3: - self.regularization = value + self.height = value self.process_handler() @@ -1829,7 +1799,6 @@ def node_socket_disconnect(self, socket, sink): self.incoming_buffer_id = None self.incoming_buffer = None self.buffer = None - self.layer = None self.process_handler() def node_socket_connect(self, sink, source): @@ -1848,7 +1817,6 @@ def node_socket_incoming(self, socket, payload): self.incoming_buffer_id = None self.incoming_buffer = None self.buffer = None - self.layer = None # set new buffer information if payload: @@ -1859,15 +1827,13 @@ def node_socket_incoming(self, socket, payload): self.incoming_buffer = self.node_window.buffer_map.get( self.incoming_buffer_id)[0] - self.layer = self.node_window.buffer_map.get( - self.incoming_buffer_id)[1] - print("Buffer Incoming: ", self.incoming_buffer) self.process_handler() else: print("Error!!!") + class TextSrcNode(CustomNode): __gtype_name__ = 'TextSrc' @@ -1922,7 +1888,7 @@ def __init__(self, node_window, *args, **kwds) -> None: label, GtkNodes.NodeSocketIO.SOURCE) self.node_socket_output.connect( "socket_connect", self.node_socket_connect) - + def get_values(self): ''' Returns dictionary of current state of custom values for the node ''' @@ -1957,14 +1923,14 @@ def set_values(self, values: dict): def text_change(self, entry): self.grab_focus() self.text = self.text_entry.get_text() - + self.value_update() def font_change(self, font_button): self.grab_focus() self.font = self.font_chooser.get_font() self.size = float(self.font_chooser.get_font_size() / 1024) - + self.value_update() def color_change(self, font_button): @@ -1972,7 +1938,7 @@ def color_change(self, font_button): self.color = self.color_chooser.get_rgba() self.color = self.convert_color(self.color) print(self.color) - + self.value_update() def convert_color(self, color): @@ -1986,17 +1952,23 @@ def convert_color(self, color): def process(self): # use ontario backend for image processing - width, height = self.image_builder.text(self.text, self.font, self.size, self.color, -1, -1, 0, 0) + self.image_builder.text(self.text, self.font, self.size, self.color, -1, -1, 0, 0) - print(width) - print(height) + extent = Gimp.get_pdb().run_procedure("gimp-text-get-extents-fontname", + [GObject.Value(GObject.TYPE_STRING, self.text), + GObject.Value(GObject.TYPE_DOUBLE, self.size), + GObject.Value(Gimp.SizeType, Gimp.SizeType.PIXELS), + GObject.Value(GObject.TYPE_STRING, self.font)]) + + width = extent.index(1) + height = extent.index(2) # lol what? height is a broken property in gegl, use font size instead self.buffer = Gegl.Buffer.new("RGBA float", 0, 0, (width + (width * 0.2)), (height + (height * 0.2))) self.image_builder.save_to_buffer(self.buffer) self.image_builder.process() - + def value_update(self): ''' Processes image and sends out updated buffer reference @@ -2012,7 +1984,7 @@ def value_update(self): print("Error: could not process text") self.node_socket_output.write(bytes(self.buffer_id, 'utf8')) - + def process_ouput(self): ''' Updates buffer reference in map diff --git a/gimp/pictonode-gimp-plugin/GIMP 2.99/pictonode/json_interpreter.py b/gimp/pictonode-gimp-plugin/GIMP 2.99/pictonode/json_interpreter.py index da4aedf..2047d09 100644 --- a/gimp/pictonode-gimp-plugin/GIMP 2.99/pictonode/json_interpreter.py +++ b/gimp/pictonode-gimp-plugin/GIMP 2.99/pictonode/json_interpreter.py @@ -29,7 +29,8 @@ def json_interpreter(node_view, window, **kwargs): 'CompOver': cn.CompositeNode, 'DropShadow': cn.DropshadowNode, 'Waterpixel': cn.WaterpixelNode, - 'TileGlass': cn.TileGlassNode} + 'TileGlass': cn.TileGlassNode, + 'TextSrc': cn.TextSrcNode} nodes_loaded = {} diff --git a/gimp/pictonode-gimp-plugin/GIMP 2.99/pictonode/window.py b/gimp/pictonode-gimp-plugin/GIMP 2.99/pictonode/window.py index 4a846a9..2cf9e54 100644 --- a/gimp/pictonode-gimp-plugin/GIMP 2.99/pictonode/window.py +++ b/gimp/pictonode-gimp-plugin/GIMP 2.99/pictonode/window.py @@ -309,6 +309,7 @@ def on_button_press(self, widget, event): sub_item7 = Gtk.MenuItem(label="Dropshadow Node") sub_item8 = Gtk.MenuItem(label="Waterpixels Node") sub_item9 = Gtk.MenuItem(label="Tile Glass Node") + sub_item10 = Gtk.MenuItem(label="Text Node") # connect menu items here sub_item1.connect("activate", self.add_image_src_node) @@ -320,6 +321,7 @@ def on_button_press(self, widget, event): sub_item7.connect("activate", self.add_dropshadow_node) sub_item8.connect("activate", self.add_waterpixels_node) sub_item9.connect("activate", self.add_tileglass_node) + sub_item10.connect("activate", self.add_textsrc_node) # disable output node option if one already exists if self.has_output_node: @@ -336,6 +338,7 @@ def on_button_press(self, widget, event): submenu.append(sub_item7) submenu.append(sub_item8) submenu.append(sub_item9) + submenu.append(sub_item10) # add submenu to menu item submenu_item.set_submenu(submenu)