Skip to content

Commit

Permalink
CR Select Font
Browse files Browse the repository at this point in the history
  • Loading branch information
Suzie1 committed Jan 11, 2024
1 parent d5f4cca commit 3a9779f
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 45 deletions.
4 changes: 4 additions & 0 deletions Patch_Notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 🧩 Comfyroll Studio - Patch Notes

## v1.66 Jan 11, 2024
- added CR Select Font
- updated CR Get Parameter From Prompt, added handling for quotes

## v1.65 Jan 10, 2024
- added CR Text Length
- added CR Text Operation
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Co-authored by Suzie1 and RockOfFire

Current version: 1.64
Current version: 1.66

# Wiki

Expand Down Expand Up @@ -140,6 +140,7 @@ __🔤 Graphics - Text__
* CR Draw Text
* CR Mask Text
* CR Composite Text
* CR Select Font

__👽 Graphics - Template__
* CR Simple Meme Template
Expand Down
4 changes: 2 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@author: Suzie1
@title: Comfyroll Studio
@nickname: Comfyroll Studio
@description: 164 custom nodes for artists, designers and animators.
@description: 165 custom nodes for artists, designers and animators.
"""

from .live_node_mappings import LIVE_NODE_CLASS_MAPPINGS, LIVE_NODE_DISPLAY_NAME_MAPPINGS
Expand All @@ -36,7 +36,7 @@
NODE_DISPLAY_NAME_MAPPINGS = LIVE_NODE_DISPLAY_NAME_MAPPINGS

print("------------------------------------------")
print("\033[34mComfyroll Studio v1.65 : \033[92m 164 Nodes Loaded\033[0m")
print("\033[34mComfyroll Studio v1.66 : \033[92m 165 Nodes Loaded\033[0m")
print("------------------------------------------")
print("** For changes, please see patch notes at https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/blob/main/Patch_Notes.md")
print("** For help, please see the wiki at https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki")
Expand Down
2 changes: 2 additions & 0 deletions live_node_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"CR Composite Text": CR_CompositeText,
#"CR Arabic Text RTL": CR_ArabicTextRTL,
"CR Simple Text Watermark": CR_SimpleTextWatermark,
"CR Select Font": CR_SelectFont,
### Graphics Filter
"CR Halftone Filter": CR_HalftoneFilter,
"CR Color Tint": CR_ColorTint,
Expand Down Expand Up @@ -373,6 +374,7 @@
"CR Composite Text": "🔤️ CR Composite Text",
#"CR Arabic Text RTL": "🔤️ CR Arabic Text RTL",
"CR Simple Text Watermark": "🔤️ CR Simple Text Watermark",
"CR Select Font": "🔤️ CR Select Font",
### Graphics Filter
"CR Halftone Filter": "🎨 Halftone Filter",
"CR Color Tint": "🎨 CR Color Tint",
Expand Down
38 changes: 38 additions & 0 deletions nodes/nodes_graphics_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ def get_offset_for_true_mm(text, draw, font):
mask_center = (mask_bbox[0] + mask_bbox[2]) // 2, (mask_bbox[1] + mask_bbox[3]) // 2
return anchor_center[0] - mask_center[0], anchor_center[1] - mask_center[1]


class AnyType(str):
"""A special type that can be connected to any other types. Credit to pythongosssss"""

def __ne__(self, __value: object) -> bool:
return False

any_type = AnyType("*")

#---------------------------------------------------------------------------------------------------------------------#

ALIGN_OPTIONS = ["center", "top", "bottom"]
Expand Down Expand Up @@ -436,6 +445,34 @@ def overlay_text(self, image, text, align,

# Convert the PIL image back to a torch tensor
return (images_out, show_help, )

#---------------------------------------------------------------------------------------------------------------------#
class CR_SelectFont:
def __init__(self):
pass

@classmethod
def INPUT_TYPES(cls):

system_root = os.environ.get('SystemRoot')
font_dir = os.path.join(system_root, 'Fonts')
file_list = [f for f in os.listdir(font_dir) if os.path.isfile(os.path.join(font_dir, f)) and f.lower().endswith(".ttf")]

return {"required": {
"font_name": (file_list,),
}
}

RETURN_TYPES = (any_type, "STRING",)
RETURN_NAMES = ("font_name", "show_help",)
FUNCTION = "select_font"
CATEGORY = icons.get("Comfyroll/Graphics/Text")

def select_font(self, font_name):

show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Text-Nodes#cr-select-font"

return (font_name, show_help,)

#---------------------------------------------------------------------------------------------------------------------#
# MAPPINGS
Expand All @@ -450,6 +487,7 @@ def overlay_text(self, image, text, align,
"CR Draw Perspective Text": CR_DrawPerspectiveText,
"CR Arabic Text RTL": CR_ArabicTextRTL,
"CR Simple Text Watermark": CR_SimpleTextWatermark,
"CR Select Font": CR_SelectFont,
}
'''

69 changes: 63 additions & 6 deletions nodes/nodes_utils_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
import math
from ..categories import icons

class AnyType(str):
"""A special type that can be connected to any other types. Credit to pythongosssss"""

def __ne__(self, __value: object) -> bool:
return False

any_type = AnyType("*")

#---------------------------------------------------------------------------------------------------------------------#
# Maths Nodes
#---------------------------------------------------------------------------------------------------------------------#
Expand Down Expand Up @@ -88,6 +96,40 @@ def set_value(self, boolean, value_if_true, value_if_false):
else:
return (int(value_if_false), value_if_false, show_help, )

#---------------------------------------------------------------------------------------------------------------------#
class CR_SetValueOnString:

@ classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text": ("STRING", {"multiline": False, "default": "", "forceInput": True}),
},
"optional": {
"test_string": ("STRING", {"multiline": False, "default": ""}),
"value_if_true": ("STRING", {"multiline": False, "default": ""}),
"value_if_false": ("STRING", {"multiline": False, "default": ""}),
},
}

RETURN_TYPES = (any_type, "STRING", )
RETURN_NAMES = ("STRING", "show_help", )
FUNCTION = "replace_text"
CATEGORY = icons.get("Comfyroll/Utils/Other")

def replace_text(self, text, test_string, value_if_true, value_if_false):

show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/List-Nodes#cr-set-value-on-string"

if test_string in text:
# Test condition is true, replace with value_if_true
text_out = value_if_true
else:
# Test condition is false, replace with value_if_false
text_out = value_if_false

return (text_out, show_help)

#---------------------------------------------------------------------------------------------------------------------#
class CR_IntegerMultipleOf:

Expand Down Expand Up @@ -195,7 +237,7 @@ def INPUT_TYPES(cls):
}
}

RETURN_TYPES =("STRING", "STRING", "FLOAT", "BOOLEAN", "STRING", )
RETURN_TYPES =("STRING", any_type, "FLOAT", "BOOLEAN", "STRING", )
RETURN_NAMES =("prompt", "text", "float", "boolean", "show_help", )
FUNCTION = "get_string"
CATEGORY = icons.get("Comfyroll/Utils/Other")
Expand All @@ -211,16 +253,30 @@ def get_string(self, prompt, search_string):

index = prompt.find(search_string)
if index != -1:
space_index = prompt.find(" ", index)
return_string = prompt[index + len(search_string):space_index] if space_index != -1 else prompt[index + len(search_string):]
# Check if there is a quote after the search_string
if prompt[index + len(search_string)] == '=':
if prompt[index + len(search_string) + 1] == '"':
# Extract text between quotes
start_quote = index + len(search_string) + 2
end_quote = prompt.find('"', start_quote + 1)
if end_quote != -1:
return_string = prompt[start_quote:end_quote]
print(return_string)
else:
# Find the next space after the search_string
space_index = prompt.find(" ", index + len(search_string))
if space_index != -1:
return_string = prompt[index + len(search_string):space_index]
else:
return_string = prompt[index + len(search_string):]
else:
return_string = search_string[1:]

if return_string == "":
return (return_prompt, return_string, return_value, return_boolean, show_help, )

if return_string.startswith("="):
return_string = return_string[1:]
else:
return_string = ""

return_boolean = return_string.lower() == "true"

Expand Down Expand Up @@ -250,7 +306,8 @@ def get_string(self, prompt, search_string):
"CR Value": CR_Value,
"CR Clamp Value": CR_ClampValue,
"CR Set Value On Boolean": CR_SetValueOnBoolean,
"CR Set Value On Binary": CR_SetValueOnBinary,
"CR Set Value On Binary": CR_SetValueOnBinary,
"CR Set Value on String": CR_SetValueOnString,
"CR Integer Multiple": CR_IntegerMultipleOf,
"CR Math Operation": CR_MathOperation,
"CR Get Parameter From Prompt": CR_GetParameterFromPrompt,
Expand Down
37 changes: 1 addition & 36 deletions nodes/nodes_utils_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,40 +248,6 @@ def replace_text(self, text, find1="", replace1="", find2="", replace2="", find3

return (text, show_help)

#---------------------------------------------------------------------------------------------------------------------#
class CR_SetValueOnString:

@ classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text": ("STRING", {"multiline": False, "default": "", "forceInput": True}),
},
"optional": {
"test_string": ("STRING", {"multiline": False, "default": ""}),
"value_if_true": ("STRING", {"multiline": False, "default": ""}),
"value_if_false": ("STRING", {"multiline": False, "default": ""}),
},
}

RETURN_TYPES = (any_type, "STRING", )
RETURN_NAMES = ("STRING", "show_help", )
FUNCTION = "replace_text"
CATEGORY = icons.get("Comfyroll/Utils/Other")

def replace_text(self, text, test_string, value_if_true, value_if_false):

show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/List-Nodes#cr-set-value-on-string"

if test_string in text:
# Test condition is true, replace with value_if_true
text_out = value_if_true
else:
# Test condition is false, replace with value_if_false
text_out = value_if_false

return (text_out, show_help)

#---------------------------------------------------------------------------------------------------------------------#
class CR_TextOperation:

Expand Down Expand Up @@ -363,8 +329,7 @@ def len_text(self, text):
"CR Text Concatenate": CR_TextConcatenate,
"CR Text Replace": CR_TextReplace,
"CR Text Length": CR_TextLength,
"CR Text Operation": CR_TextOperation,
"CR Set Value on String": CR_SetValueOnString,
"CR Text Operation": CR_TextOperation,
"CR Save Text To File": CR_SaveTextToFile,
}
'''
Expand Down

0 comments on commit 3a9779f

Please sign in to comment.