diff --git a/CHANGELOG.md b/CHANGELOG.md index 61cf309..e4e15f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,13 @@ -# v1.1.1 - Unreleased +# v2.0.0 - Unreleased + +### Added +- Custom number of letters to underline + +### Fixed +- Error when entering decimal numbers ### Dependencies -- pillow : `9.5.0` -> `10.1.0` +- pillow : `9.5.0` -> `10.2.0` - click-extra : `4.6.0` -> `4.7.2` # v1.1.0 - 2023-10-02 diff --git a/README.md b/README.md index e288257..1e7a0d1 100644 --- a/README.md +++ b/README.md @@ -42,19 +42,15 @@ python3 src/main.py # Styles -### Style 1 - First letter underlined +### Style 1 - First letters underlined + +> The number of letters to underline is customizable since version 2.0.0

-### Style 2 - All letters underlined - -

- -

- # Color schemes ### Color scheme 1 - adi1090x's color scheme diff --git a/assets/style2.png b/assets/style2.png deleted file mode 100644 index 206c8ba..0000000 Binary files a/assets/style2.png and /dev/null differ diff --git a/src/styles/all_underlined.py b/src/styles/all_underlined.py deleted file mode 100644 index bdb55d7..0000000 --- a/src/styles/all_underlined.py +++ /dev/null @@ -1,9 +0,0 @@ -from . import underline_core - -display_name = "All text underlined" -active = True -questions = underline_core.questions - - -def get_image(answers): - return underline_core.get_image(answers, "all") diff --git a/src/styles/first_letter_underlined.py b/src/styles/first_letter_underlined.py index a9591cc..f6644c5 100644 --- a/src/styles/first_letter_underlined.py +++ b/src/styles/first_letter_underlined.py @@ -1,9 +1,9 @@ from . import underline_core -display_name = "First letter underlined" +display_name = "First letters underlined" active = True questions = underline_core.questions def get_image(answers): - return underline_core.get_image(answers, "first_letter") + return underline_core.get_image(answers) diff --git a/src/styles/underline_core.py b/src/styles/underline_core.py index 43cf4f6..3f3797f 100644 --- a/src/styles/underline_core.py +++ b/src/styles/underline_core.py @@ -10,6 +10,7 @@ questions = [ SelectQuestion("font", "Select a font", [(font, font) for font in font_list], "Iosevka-Nerd-Font-Complete.ttf"), SelectQuestion("color", "Select a color scheme", color_scheme_names, "adi1090x"), + TextQuestion("underline_count", "Lettrs to undrline", [Number(minimum=0)], "1", "1"), TextQuestion("padding_x", "Padding x (px)", [Number()], "200", "200"), TextQuestion("padding_y", "Padding y (px)", [Number()], "20", "20"), TextQuestion("gap", "Gap between text and bar (px)", [Number()], "20", "20"), @@ -20,14 +21,12 @@ active = False -def get_image(answers, type): - if type not in ['all', 'first_letter']: - raise ValueError("Invalid type") - +def get_image(answers): # Load the selected font font_size = 500 font = ImageFont.truetype(os.path.join(FONTS_DIR, answers["font"]), font_size) + # Set the colors background = ImageColor.getrgb(color_schemes[answers['color']]["background"]) text = ImageColor.getrgb(color_schemes[answers['color']]["text"]) accent = ImageColor.getrgb(color_schemes[answers['color']]["accent"]) @@ -44,41 +43,37 @@ def get_image(answers, type): image = Image.new("RGB", (image_width, image_height), background) draw = ImageDraw.Draw(image) - # Get the anchor position and type + # Get the text anchor type and position on the image (where the text will be drawn) + # LM = Left/Middle anchor_type = "lm" anchor_x = int(answers['padding_x']) anchor_y = image_height / 2 - (int(answers['gap']) + int(answers['bar_size'])) / 2 anchor_pos = (anchor_x, anchor_y) - # Get the bbox of the first letter - - first_letter_bbox = draw.textbbox( - anchor_pos, answers['name'][0], font=font, anchor=anchor_type - ) + if int(answers['underline_count']) > 0: + # Get the bbox of the first n letter to underline + first_letters_bbox = draw.textbbox( + anchor_pos, + answers['name'][:int(answers['underline_count'])], + font=font, + anchor=anchor_type) - # Get the underline position - underline_start_x = first_letter_bbox[0] - int(answers['additionnal_bar_width']) - underline_start_y = first_letter_bbox[3] + int(answers['gap']) + # Get the underline position + underline_start_x = first_letters_bbox[0] - int(answers['additionnal_bar_width']) + underline_start_y = first_letters_bbox[3] + int(answers['gap']) - # The end of the underline depends on the type - # If the type is 'all', the underline will go from the start of the first letter to the end of the text - # If the type is 'first_letter', the underline will go - # from the start of the first letter to the end of the first letter - if type == 'first_letter': - underline_end_x = int(answers['additionnal_bar_width']) + (first_letter_bbox[2]) - else: - underline_end_x = int(int(answers['padding_x']) + text_width) + underline_end_x = int(answers['additionnal_bar_width']) + first_letters_bbox[2] - underline_end_y = underline_start_y + int(answers['bar_size']) + underline_end_y = underline_start_y + int(answers['bar_size']) - underline_start = (underline_start_x, underline_start_y) - underline_end = (underline_end_x, underline_end_y) + underline_start = (underline_start_x, underline_start_y) + underline_end = (underline_end_x, underline_end_y) - underline_pos = [underline_start, underline_end] + underline_pos = [underline_start, underline_end] - # Underline the first letter - draw.rectangle(underline_pos, fill=accent, width=answers['bar_size']) + # Underline the first letter + draw.rectangle(underline_pos, fill=accent, width=answers['bar_size']) # Draw the text draw.text(