Skip to content

Commit 67e03bc

Browse files
committed
refactor(ui): resolve Qt text wrapper and theme imports in font.py
1 parent 6d94887 commit 67e03bc

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

‎src/tagstudio/previews/renderers/font.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
from tagstudio.core.media_types import MediaTypes
1818
from tagstudio.previews.base_preview import RENDER, BasePreview
1919
from tagstudio.previews.effects import apply_overlay_color
20-
from tagstudio.qt.helpers.text_wrapper import wrap_full_text
21-
from tagstudio.qt.views.styles.color_overlay import auto_theme_overlay
20+
from tagstudio.previews.text_wrapper import wrap_full_text
2221
from tagstudio.qt.views.styles.palette import UiColor
2322

2423
logger = structlog.get_logger(__name__)
@@ -48,7 +47,7 @@ def render(
4847
return (
4948
font_small_thumb(filepath, theme, size)
5049
if is_small
51-
else font_full_preview(filepath, size)
50+
else font_full_preview(filepath, theme, size)
5251
)
5352

5453

@@ -110,6 +109,7 @@ def font_small_thumb(filepath: Path, theme: Theme, size: tuple[int, int]) -> Ima
110109
box=(margin, margin + ((size[1] - new_y) // 2)),
111110
)
112111
im = bg
112+
# TODO: Replace UiColor system, remove Qt-side import here.
113113
im = apply_overlay_color(im, UiColor.BLUE, theme)
114114

115115
except OSError as e:
@@ -118,11 +118,12 @@ def font_small_thumb(filepath: Path, theme: Theme, size: tuple[int, int]) -> Ima
118118
return im
119119

120120

121-
def font_full_preview(filepath: Path, size: tuple[int, int]) -> Image | None:
121+
def font_full_preview(filepath: Path, theme: Theme, size: tuple[int, int]) -> Image | None:
122122
"""Render a large font preview ("Alphabet") thumbnail from a font file.
123123
124124
Args:
125125
filepath (Path): The path of the file.
126+
theme (Theme): The system color theme.
126127
size (tuple[int,int]): The size of the thumbnail.
127128
"""
128129
# Scale the sample font sizes to the preview image
@@ -145,8 +146,8 @@ def font_full_preview(filepath: Path, size: tuple[int, int]) -> Image | None:
145146
y_offset += (len(text_wrapped.split("\n")) + lines_of_padding) * draw.textbbox(
146147
(0, 0), "A", font=font
147148
)[-1]
148-
# TODO: Separate from any Qt stuff
149-
im = auto_theme_overlay(bg, use_alpha=False)
149+
im = new_image("RGBA", size, color="#00000000")
150+
im.paste("#FFFFFF" if theme == Theme.DARK else "#000000", mask=bg)
150151
except OSError as e:
151152
logger.error("Couldn't render thumbnail", filepath=filepath, error=type(e).__name__)
152153
return im

0 commit comments

Comments
 (0)