feat: make FreeDesktop icon thumbnail size as configurable
This commit is contained in:
@@ -7,13 +7,19 @@ from pathlib import Path
|
|||||||
from typing import TypeVar, Generic, Callable
|
from typing import TypeVar, Generic, Callable
|
||||||
from ..lowlevel.environment import Prologue as LowPrologue, Environment as LowEnv
|
from ..lowlevel.environment import Prologue as LowPrologue, Environment as LowEnv
|
||||||
from ..lowlevel.artrdr import SvgRenderKind
|
from ..lowlevel.artrdr import SvgRenderKind
|
||||||
from .utils import FdContext, WinCategory, MacCategory, FD_THUMBNAIL_HWS
|
from .utils import FdContext, WinCategory, MacCategory, VART_HW
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class Prologue(LowPrologue):
|
class Prologue(LowPrologue):
|
||||||
svg_render: SvgRenderKind
|
svg_render: SvgRenderKind
|
||||||
"""The render kind for SVG"""
|
"""The render kind for SVG."""
|
||||||
|
fd_thumbnail_hws: tuple[int, ...]
|
||||||
|
"""
|
||||||
|
The collection of sizes of generated FreeDesktop icons.
|
||||||
|
Each size must be greater than zero and lower or equal to ``VART_HW``.
|
||||||
|
Due to icon is a square rectangle, the height and width are same.
|
||||||
|
"""
|
||||||
temp_dir_initializer: Callable[[Path], None] | None
|
temp_dir_initializer: Callable[[Path], None] | None
|
||||||
"""
|
"""
|
||||||
The extra initializer for user temporary directory.
|
The extra initializer for user temporary directory.
|
||||||
@@ -21,6 +27,15 @@ class Prologue(LowPrologue):
|
|||||||
``None`` for no extra initializer.
|
``None`` for no extra initializer.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
super().__post_init__()
|
||||||
|
for hw in self.fd_thumbnail_hws:
|
||||||
|
if hw <= 0 or hw > VART_HW:
|
||||||
|
raise ValueError(
|
||||||
|
f"Given FreeDesktop icon thumbnail size mismatch the size requirements. "
|
||||||
|
f"Expect >= 0 and <= {VART_HW}, got {hw}."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
_TEMP_USER_DIR: str = "user"
|
_TEMP_USER_DIR: str = "user"
|
||||||
_TEMP_LIB_DIR: str = "assemblicon"
|
_TEMP_LIB_DIR: str = "assemblicon"
|
||||||
@@ -52,7 +67,7 @@ class Environment(Generic[P]):
|
|||||||
parents=True, exist_ok=True
|
parents=True, exist_ok=True
|
||||||
)
|
)
|
||||||
# and output directory
|
# and output directory
|
||||||
for hw in FD_THUMBNAIL_HWS:
|
for hw in self.__prologue.fd_thumbnail_hws:
|
||||||
for kind in FdContext:
|
for kind in FdContext:
|
||||||
self.__output_artifact(f"{hw}x{hw}", str(kind)).mkdir(
|
self.__output_artifact(f"{hw}x{hw}", str(kind)).mkdir(
|
||||||
parents=True, exist_ok=True
|
parents=True, exist_ok=True
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from dataclasses import dataclass
|
|||||||
from .common import Sink
|
from .common import Sink
|
||||||
from ..address import Address, AddressDomain
|
from ..address import Address, AddressDomain
|
||||||
from ..environment import Environment
|
from ..environment import Environment
|
||||||
from ..utils import Artifact, FdContext, FD_THUMBNAIL_HWS, check_vart
|
from ..utils import Artifact, FdContext, check_vart
|
||||||
from ...lowlevel import artio, artrdr
|
from ...lowlevel import artio, artrdr
|
||||||
from ...logger import HIGHLEVEL_LOGGER as LOGGER
|
from ...logger import HIGHLEVEL_LOGGER as LOGGER
|
||||||
|
|
||||||
@@ -33,7 +33,8 @@ class FdArtSink(Sink):
|
|||||||
)
|
)
|
||||||
check_vart(art)
|
check_vart(art)
|
||||||
for hw, thumbnail in zip(
|
for hw, thumbnail in zip(
|
||||||
FD_THUMBNAIL_HWS, artrdr.render_thumbnail(art, FD_THUMBNAIL_HWS)
|
env.prologue.fd_thumbnail_hws,
|
||||||
|
artrdr.render_thumbnail(art, env.prologue.fd_thumbnail_hws),
|
||||||
):
|
):
|
||||||
dst = env.fd_output_artifact(hw, self.__kind, self.__name)
|
dst = env.fd_output_artifact(hw, self.__kind, self.__name)
|
||||||
artio.save_artifact(thumbnail, dst)
|
artio.save_artifact(thumbnail, dst)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from .common import Source
|
|||||||
from ..address import Address, AddressDomain
|
from ..address import Address, AddressDomain
|
||||||
from ..environment import Environment
|
from ..environment import Environment
|
||||||
from ..sink.fdart_sink import FdArtSink
|
from ..sink.fdart_sink import FdArtSink
|
||||||
from ..utils import FdContext, FD_THUMBNAIL_HWS
|
from ..utils import FdContext
|
||||||
from ...lowlevel import artio
|
from ...lowlevel import artio
|
||||||
from ...logger import HIGHLEVEL_LOGGER as LOGGER
|
from ...logger import HIGHLEVEL_LOGGER as LOGGER
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ class FdArtSource(Source):
|
|||||||
sink_hint.kind,
|
sink_hint.kind,
|
||||||
sink_hint.name,
|
sink_hint.name,
|
||||||
)
|
)
|
||||||
for hw in FD_THUMBNAIL_HWS:
|
for hw in env.prologue.fd_thumbnail_hws:
|
||||||
artio.link_artifact(
|
artio.link_artifact(
|
||||||
env.fd_output_artifact(hw, self.__kind, self.__name),
|
env.fd_output_artifact(hw, self.__kind, self.__name),
|
||||||
env.fd_output_artifact(hw, sink_hint.kind, sink_hint.name),
|
env.fd_output_artifact(hw, sink_hint.kind, sink_hint.name),
|
||||||
|
|||||||
@@ -40,7 +40,5 @@ class MacCategory(enum.StrEnum):
|
|||||||
"""Icons for file extensions"""
|
"""Icons for file extensions"""
|
||||||
|
|
||||||
|
|
||||||
# TODO: For easy testing, we only build 32x32 and 48x48.
|
DEFAULT_FD_THUMBNAIL_HWS: tuple[int, ...] = (16, 32, 48, 64, 128, 256)
|
||||||
# Enable full generation after testing.
|
"""The default collection of sizes for generating FreeDesktop icons."""
|
||||||
FD_THUMBNAIL_HWS: tuple[int, ...] = (32, 48)
|
|
||||||
# FD_THUMBNAIL_HWS: tuple[int, ...] = (16, 32, 48, 64, 128, 256)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user