diff --git a/assets/fonts/AllertaStencil.ttf b/assets/fonts/AllertaStencil.ttf deleted file mode 100644 index 0571a71..0000000 Binary files a/assets/fonts/AllertaStencil.ttf and /dev/null differ diff --git a/assets/fonts/BaseballClub.otf b/assets/fonts/BaseballClub.otf new file mode 100644 index 0000000..cd9425b Binary files /dev/null and b/assets/fonts/BaseballClub.otf differ diff --git a/assets/fonts/BeachDay.otf b/assets/fonts/BeachDay.otf new file mode 100644 index 0000000..fdf08b1 Binary files /dev/null and b/assets/fonts/BeachDay.otf differ diff --git a/assets/fonts/Bolton.ttf b/assets/fonts/Bolton.ttf new file mode 100644 index 0000000..d9b9a82 Binary files /dev/null and b/assets/fonts/Bolton.ttf differ diff --git a/assets/fonts/ButterChicken.ttf b/assets/fonts/ButterChicken.ttf new file mode 100644 index 0000000..49f7cfe Binary files /dev/null and b/assets/fonts/ButterChicken.ttf differ diff --git a/assets/fonts/Chaser.otf b/assets/fonts/Chaser.otf new file mode 100644 index 0000000..23e3153 Binary files /dev/null and b/assets/fonts/Chaser.otf differ diff --git a/assets/fonts/ColorSport.ttf b/assets/fonts/ColorSport.ttf new file mode 100644 index 0000000..71f8290 Binary files /dev/null and b/assets/fonts/ColorSport.ttf differ diff --git a/assets/fonts/FungkyBrow.otf b/assets/fonts/FungkyBrow.otf new file mode 100644 index 0000000..f7d9571 Binary files /dev/null and b/assets/fonts/FungkyBrow.otf differ diff --git a/assets/fonts/Hanky.otf b/assets/fonts/Hanky.otf new file mode 100644 index 0000000..7086a01 Binary files /dev/null and b/assets/fonts/Hanky.otf differ diff --git a/assets/fonts/Kurvaceous.otf b/assets/fonts/Kurvaceous.otf new file mode 100644 index 0000000..ff92631 Binary files /dev/null and b/assets/fonts/Kurvaceous.otf differ diff --git a/assets/fonts/LuckiestGuy.ttf b/assets/fonts/LuckiestGuy.ttf new file mode 100644 index 0000000..01b535a Binary files /dev/null and b/assets/fonts/LuckiestGuy.ttf differ diff --git a/assets/fonts/MilkyWay.ttf b/assets/fonts/MilkyWay.ttf new file mode 100644 index 0000000..39741a2 Binary files /dev/null and b/assets/fonts/MilkyWay.ttf differ diff --git a/assets/fonts/NatureKeystone.otf b/assets/fonts/NatureKeystone.otf new file mode 100644 index 0000000..28be250 Binary files /dev/null and b/assets/fonts/NatureKeystone.otf differ diff --git a/assets/fonts/RacingGames.otf b/assets/fonts/RacingGames.otf new file mode 100644 index 0000000..a1f72f5 Binary files /dev/null and b/assets/fonts/RacingGames.otf differ diff --git a/assets/fonts/Sakana.ttf b/assets/fonts/Sakana.ttf new file mode 100644 index 0000000..286a6d5 Binary files /dev/null and b/assets/fonts/Sakana.ttf differ diff --git a/assets/fonts/SauceTomato.otf b/assets/fonts/SauceTomato.otf new file mode 100644 index 0000000..2421138 Binary files /dev/null and b/assets/fonts/SauceTomato.otf differ diff --git a/assets/fonts/SundayMagic.otf b/assets/fonts/SundayMagic.otf new file mode 100644 index 0000000..15f6381 Binary files /dev/null and b/assets/fonts/SundayMagic.otf differ diff --git a/assets/fonts/Valty.otf b/assets/fonts/Valty.otf new file mode 100644 index 0000000..2c20189 Binary files /dev/null and b/assets/fonts/Valty.otf differ diff --git a/assets/fonts/VintageBrowner.otf b/assets/fonts/VintageBrowner.otf new file mode 100644 index 0000000..de7b8e4 Binary files /dev/null and b/assets/fonts/VintageBrowner.otf differ diff --git a/assets/fonts/VintageRubicon.otf b/assets/fonts/VintageRubicon.otf new file mode 100644 index 0000000..fcc86f4 Binary files /dev/null and b/assets/fonts/VintageRubicon.otf differ diff --git a/assets/fonts/Voegies.ttf b/assets/fonts/Voegies.ttf new file mode 100644 index 0000000..deb5bf0 Binary files /dev/null and b/assets/fonts/Voegies.ttf differ diff --git a/assets/fonts/ss-diamond.otf b/assets/fonts/ss-diamond.otf new file mode 100644 index 0000000..43d61c5 Binary files /dev/null and b/assets/fonts/ss-diamond.otf differ diff --git a/assets/fonts/ss-malibu.otf b/assets/fonts/ss-malibu.otf new file mode 100644 index 0000000..63bfede Binary files /dev/null and b/assets/fonts/ss-malibu.otf differ diff --git a/pretty_gpx/common/data/place_name.py b/pretty_gpx/common/data/place_name.py index b3e6e60..2b1986d 100644 --- a/pretty_gpx/common/data/place_name.py +++ b/pretty_gpx/common/data/place_name.py @@ -50,17 +50,17 @@ def get_start_end_named_points(gpx_track: GpxTrack | MultiGpxTrack) -> list[Scat if get_distance_m(lonlat_1=(start_lon, start_lat), lonlat_2=(end_lon, end_lat)) < 1000: - # Start and end are too close, skip name and position of end point - end = ScatterPoint(name=None, - lon=start_lon, - lat=start_lat, - category=ScatterPointCategory.END) + # Start and end are too close, skip name of end point + end_name = None else: # Start and end are far enough, keep name of end point only if different from start - name = get_place_name(lon=end_lon, lat=end_lat) - end = ScatterPoint(name=name if name != start.name else None, - lon=end_lon, - lat=end_lat, - category=ScatterPointCategory.END) + end_name = get_place_name(lon=end_lon, lat=end_lat) + if end_name == start.name: + end_name = None + + end = ScatterPoint(name=end_name, + lon=end_lon, + lat=end_lat, + category=ScatterPointCategory.END) return [start, end] diff --git a/pretty_gpx/common/drawing/utils/fonts.py b/pretty_gpx/common/drawing/utils/fonts.py index 3b9d3de..e91f1d0 100644 --- a/pretty_gpx/common/drawing/utils/fonts.py +++ b/pretty_gpx/common/drawing/utils/fonts.py @@ -2,6 +2,7 @@ """Fonts.""" import os from enum import Enum +from typing import Final from matplotlib.font_manager import FontProperties @@ -10,14 +11,86 @@ class CustomFont(Enum): """Custom Fonts Enum.""" - DEJA_VU_SANS_BOLD = FontProperties(family="DejaVu Sans", weight="bold") - LOBSTER = FontProperties(family="Lobster", fname=os.path.join(FONTS_DIR, "Lobster.ttf")) - MONOTON = FontProperties(family="Monoton", fname=os.path.join(FONTS_DIR, "Monoton.ttf")) - GOCHI_HAND = FontProperties(family="Gochi Hand", fname=os.path.join(FONTS_DIR, "GochiHand.ttf")) - EMILIO_20 = FontProperties(family="Emilio 20", fname=os.path.join(FONTS_DIR, "Emilio20.ttf")) - ALLERTA_STENCIL = FontProperties(family="Allerta Stencil", fname=os.path.join(FONTS_DIR, "AllertaStencil.ttf")) + DEJA_VU_SANS_BOLD = FontProperties(weight="bold") + LOBSTER = FontProperties(fname=os.path.join(FONTS_DIR, "Lobster.ttf")) + MONOTON = FontProperties(fname=os.path.join(FONTS_DIR, "Monoton.ttf")) + GOCHI_HAND = FontProperties(fname=os.path.join(FONTS_DIR, "GochiHand.ttf")) + EMILIO_20 = FontProperties(fname=os.path.join(FONTS_DIR, "Emilio20.ttf")) + BASEBALL_CLUB = FontProperties(fname=os.path.join(FONTS_DIR, "BaseballClub.otf")) + BEACHDAY = FontProperties(fname=os.path.join(FONTS_DIR, "BeachDay.otf")) + BUTTER_CHICKEN = FontProperties(fname=os.path.join(FONTS_DIR, "ButterChicken.ttf")) + COLOR_SPORT = FontProperties(fname=os.path.join(FONTS_DIR, "ColorSport.ttf")) + HANKY = FontProperties(fname=os.path.join(FONTS_DIR, "Hanky.otf")) + LUCKIEST_GUY = FontProperties(fname=os.path.join(FONTS_DIR, "LuckiestGuy.ttf")) + MILKY_WAY = FontProperties(fname=os.path.join(FONTS_DIR, "MilkyWay.ttf")) + SAKANA = FontProperties(fname=os.path.join(FONTS_DIR, "Sakana.ttf")) + SAUCE_TOMATO = FontProperties(fname=os.path.join(FONTS_DIR, "SauceTomato.otf")) + SUNDAY_MAGIC = FontProperties(fname=os.path.join(FONTS_DIR, "SundayMagic.otf")) + VALTY = FontProperties(fname=os.path.join(FONTS_DIR, "Valty.otf")) + + BOLTON = FontProperties(fname=os.path.join(FONTS_DIR, "Bolton.ttf")) + CHASER = FontProperties(fname=os.path.join(FONTS_DIR, "Chaser.otf")) + FUNGKY_BROW = FontProperties(fname=os.path.join(FONTS_DIR, "FungkyBrow.otf")) + KURVACEOUS = FontProperties(fname=os.path.join(FONTS_DIR, "Kurvaceous.otf")) + NATURE_KEYSTONE = FontProperties(fname=os.path.join(FONTS_DIR, "NatureKeystone.otf")) + RACING_GAMES = FontProperties(fname=os.path.join(FONTS_DIR, "RacingGames.otf")) + SS_DIAMOND = FontProperties(fname=os.path.join(FONTS_DIR, "ss-diamond.otf")) + SS_MALIBU = FontProperties(fname=os.path.join(FONTS_DIR, "ss-malibu.otf")) + VINTAGE_BROWNER = FontProperties(fname=os.path.join(FONTS_DIR, "VintageBrowner.otf")) + VINTAGE_RUBICON = FontProperties(fname=os.path.join(FONTS_DIR, "VintageRubicon.otf")) + VOEGIES = FontProperties(fname=os.path.join(FONTS_DIR, "Voegies.ttf")) @property def font_name(self) -> str: - """Get the font name.""" + """Get the name of the FontProperties object.""" return self.value.get_name() + + +ANNOTATION_FONT: Final = CustomFont.DEJA_VU_SANS_BOLD + +TITLE_FONTS: Final = ( + CustomFont.LOBSTER, + CustomFont.MONOTON, + CustomFont.GOCHI_HAND, + CustomFont.EMILIO_20, + CustomFont.BASEBALL_CLUB, + CustomFont.BEACHDAY, + CustomFont.BUTTER_CHICKEN, + CustomFont.COLOR_SPORT, + CustomFont.HANKY, + CustomFont.LUCKIEST_GUY, + CustomFont.MILKY_WAY, + CustomFont.SAKANA, + CustomFont.SAUCE_TOMATO, + CustomFont.SUNDAY_MAGIC, + CustomFont.VALTY, + CustomFont.BOLTON, + CustomFont.FUNGKY_BROW, + CustomFont.NATURE_KEYSTONE, + CustomFont.RACING_GAMES, + CustomFont.SS_DIAMOND, + CustomFont.SS_MALIBU, + CustomFont.VINTAGE_RUBICON, + CustomFont.VOEGIES, +) + +STATS_FONTS: Final = ( + CustomFont.LOBSTER, + CustomFont.GOCHI_HAND, + CustomFont.BASEBALL_CLUB, + CustomFont.BEACHDAY, + CustomFont.BUTTER_CHICKEN, + CustomFont.LUCKIEST_GUY, + CustomFont.SAKANA, + CustomFont.SAUCE_TOMATO, + CustomFont.SUNDAY_MAGIC, + CustomFont.BOLTON, + CustomFont.CHASER, + CustomFont.KURVACEOUS, + CustomFont.NATURE_KEYSTONE, + CustomFont.RACING_GAMES, + CustomFont.SS_DIAMOND, + CustomFont.SS_MALIBU, + CustomFont.VINTAGE_RUBICON, + CustomFont.VOEGIES, +) diff --git a/pretty_gpx/rendering_modes/city/drawing/city_params.py b/pretty_gpx/rendering_modes/city/drawing/city_params.py index e6ace0a..22dc6f9 100644 --- a/pretty_gpx/rendering_modes/city/drawing/city_params.py +++ b/pretty_gpx/rendering_modes/city/drawing/city_params.py @@ -9,7 +9,9 @@ from pretty_gpx.common.drawing.utils.color_theme import DarkTheme from pretty_gpx.common.drawing.utils.drawing_figure import A4Float from pretty_gpx.common.drawing.utils.drawing_figure import MetersFloat +from pretty_gpx.common.drawing.utils.fonts import ANNOTATION_FONT from pretty_gpx.common.drawing.utils.fonts import CustomFont +from pretty_gpx.common.drawing.utils.fonts import TITLE_FONTS from pretty_gpx.common.drawing.utils.plt_marker import MarkerType from pretty_gpx.common.drawing.utils.scatter_point import ScatterPointCategory from pretty_gpx.rendering_modes.city.data.roads import CityRoadPrecision @@ -85,7 +87,7 @@ def default() -> "CityParams": ScatterPointCategory.END: AnnotatedScatterParams(arrow_linewidth=A4Float(mm=0.5), fontsize=A4Float(mm=3.0)) }, - annot_fontproperties=CustomFont.DEJA_VU_SANS_BOLD.value, + annot_fontproperties=ANNOTATION_FONT.value, annot_ha="center", annot_va="center", city_roads_lw={ @@ -124,5 +126,5 @@ def default() -> "CityParams": centered_title_font_color="cyan", centered_title_font_size=A4Float(mm=20), - centered_title_fontproperties=CustomFont.LOBSTER.value + centered_title_fontproperties=TITLE_FONTS[0].value ) diff --git a/pretty_gpx/rendering_modes/mountain/drawing/mountain_params.py b/pretty_gpx/rendering_modes/mountain/drawing/mountain_params.py index cf64423..0749e88 100644 --- a/pretty_gpx/rendering_modes/mountain/drawing/mountain_params.py +++ b/pretty_gpx/rendering_modes/mountain/drawing/mountain_params.py @@ -8,7 +8,9 @@ from pretty_gpx.common.drawing.components.annotated_scatter import ScatterParams from pretty_gpx.common.drawing.utils.color_theme import DarkTheme from pretty_gpx.common.drawing.utils.drawing_figure import A4Float +from pretty_gpx.common.drawing.utils.fonts import ANNOTATION_FONT from pretty_gpx.common.drawing.utils.fonts import CustomFont +from pretty_gpx.common.drawing.utils.fonts import TITLE_FONTS from pretty_gpx.common.drawing.utils.plt_marker import MarkerType from pretty_gpx.common.drawing.utils.scatter_point import ScatterPointCategory from pretty_gpx.rendering_modes.mountain.drawing.mountain_colors import MOUNTAIN_COLOR_THEMES @@ -69,7 +71,7 @@ def default() -> "MountainParams": ScatterPointCategory.END: AnnotatedScatterParams(arrow_linewidth=A4Float(mm=0.5), fontsize=A4Float(mm=3.0)) }, - annot_fontproperties=CustomFont.DEJA_VU_SANS_BOLD.value, + annot_fontproperties=ANNOTATION_FONT.value, annot_ha="center", annot_va="center", mountain_background_color=MOUNTAIN_COLOR_THEMES[DarkTheme.BLUE_PURPLE_YELLOW].background_color, @@ -93,5 +95,5 @@ def default() -> "MountainParams": centered_title_font_color="cyan", centered_title_font_size=A4Float(mm=20), - centered_title_fontproperties=CustomFont.LOBSTER.value + centered_title_fontproperties=TITLE_FONTS[0].value ) diff --git a/pretty_gpx/rendering_modes/multi_mountain/drawing/multi_mountain_params.py b/pretty_gpx/rendering_modes/multi_mountain/drawing/multi_mountain_params.py index 7bcfb1f..57d5521 100644 --- a/pretty_gpx/rendering_modes/multi_mountain/drawing/multi_mountain_params.py +++ b/pretty_gpx/rendering_modes/multi_mountain/drawing/multi_mountain_params.py @@ -8,7 +8,9 @@ from pretty_gpx.common.drawing.components.annotated_scatter import ScatterParams from pretty_gpx.common.drawing.utils.color_theme import DarkTheme from pretty_gpx.common.drawing.utils.drawing_figure import A4Float +from pretty_gpx.common.drawing.utils.fonts import ANNOTATION_FONT from pretty_gpx.common.drawing.utils.fonts import CustomFont +from pretty_gpx.common.drawing.utils.fonts import TITLE_FONTS from pretty_gpx.common.drawing.utils.plt_marker import MarkerType from pretty_gpx.common.drawing.utils.scatter_point import ScatterPointCategory from pretty_gpx.rendering_modes.mountain.drawing.mountain_colors import MOUNTAIN_COLOR_THEMES @@ -69,7 +71,7 @@ def default() -> "MultiMountainParams": ScatterPointCategory.END: AnnotatedScatterParams(arrow_linewidth=A4Float(mm=0.5), fontsize=A4Float(mm=3.0)) }, - annot_fontproperties=CustomFont.DEJA_VU_SANS_BOLD.value, + annot_fontproperties=ANNOTATION_FONT.value, annot_ha="center", annot_va="center", mountain_background_color=MOUNTAIN_COLOR_THEMES[DarkTheme.BLUE_PURPLE_YELLOW].background_color, @@ -93,5 +95,5 @@ def default() -> "MultiMountainParams": centered_title_font_color="cyan", centered_title_font_size=A4Float(mm=20), - centered_title_fontproperties=CustomFont.LOBSTER.value + centered_title_fontproperties=TITLE_FONTS[0].value ) diff --git a/pretty_gpx/test/test_fonts.py b/pretty_gpx/test/test_fonts.py new file mode 100644 index 0000000..08e3a5c --- /dev/null +++ b/pretty_gpx/test/test_fonts.py @@ -0,0 +1,53 @@ +#!/usr/bin/python3 +"""Test Fonts.""" + +from collections.abc import Iterable +from io import BytesIO +from warnings import catch_warnings + +import matplotlib +import matplotlib.pyplot as plt +import pytest +from matplotlib.font_manager import findfont + +from pretty_gpx.common.drawing.utils.fonts import CustomFont +from pretty_gpx.common.drawing.utils.fonts import STATS_FONTS +from pretty_gpx.common.utils.asserts import assert_isfile + + +def test_fonts_available() -> None: + """Test that all fonts are available.""" + for font in CustomFont: + font_path = findfont(font.value) + assert_isfile(font_path, msg=f"Font {font.value.get_name()} not found at {font_path}") + + +def test_fonts_matplotlib() -> None: + """Test that matplotlib can use the fonts.""" + matplotlib.use('Agg') + plt.figure() + for font in CustomFont: + plt.text(0.5, 0.5, "This is a Test", fontproperties=font.value) + plt.gcf() + plt.close() + + +def __assert_available_glyphs(fonts: Iterable[CustomFont], string_to_test: str) -> None: + """Assert that all glyphs present in the input `string_to_test` are available in the fonts.""" + matplotlib.use('Agg') + plt.figure() + with catch_warnings(record=True) as wlist: + for font in fonts: + plt.text(0.5, 0.5, string_to_test, fontproperties=font.value) + plt.savefig(BytesIO(), format='png') + plt.close() + assert len(wlist) == 0, "\n".join([str(w) for w in wlist]) + + +def test_stats_fonts_matplotlib_numbers() -> None: + """Test that matplotlib can use the stats fonts with numbers.""" + with pytest.raises(AssertionError): + __assert_available_glyphs(fonts=list(CustomFont), string_to_test="1234567890 +-") + + __assert_available_glyphs(fonts=STATS_FONTS, string_to_test="123456789") + __assert_available_glyphs(fonts=STATS_FONTS, string_to_test="+-") diff --git a/pretty_gpx/ui/pages/city/page.py b/pretty_gpx/ui/pages/city/page.py index 2e1daf7..9304e19 100644 --- a/pretty_gpx/ui/pages/city/page.py +++ b/pretty_gpx/ui/pages/city/page.py @@ -2,11 +2,14 @@ """City Page.""" from dataclasses import dataclass +from pretty_gpx.common.drawing.utils.drawing_figure import A4Float +from pretty_gpx.common.drawing.utils.fonts import STATS_FONTS from pretty_gpx.common.drawing.utils.scatter_point import ScatterPointCategory from pretty_gpx.rendering_modes.city.data.roads import CityRoadPrecision from pretty_gpx.rendering_modes.city.drawing.city_colors import CITY_COLOR_THEMES from pretty_gpx.rendering_modes.city.drawing.city_drawer import CityDrawer from pretty_gpx.rendering_modes.city.drawing.city_params import CityParams +from pretty_gpx.ui.pages.template.ui_font_and_size_select import UiFontAndSizeSelect from pretty_gpx.ui.pages.template.ui_input import UiInputInt from pretty_gpx.ui.pages.template.ui_manager import UiManager from pretty_gpx.ui.pages.template.ui_toggle import UiToggle @@ -22,6 +25,7 @@ class CityUiManager(UiManager[CityDrawer]): """City Ui Manager.""" uphill: UiInputInt road_max_precision: UiToggle[CityRoadPrecision] + stats_font: UiFontAndSizeSelect def __init__(self) -> None: drawer = CityDrawer(params=CityParams.default(), top_ratio=0.18, bot_ratio=0.22, margin_ratio=0.1) @@ -37,6 +41,10 @@ def __init__(self) -> None: tooltip="Change the roads level of details", on_change=self.on_click_update, start_key=CityRoadPrecision.MEDIUM.pretty_name) + self.stats_font = UiFontAndSizeSelect(label="Stats' Font", + fonts=STATS_FONTS, + start_fontsize=A4Float(mm=14), + on_change=self.on_click_update) @staticmethod def get_chat_msg() -> list[str]: @@ -60,6 +68,9 @@ def update_drawer_params(self) -> None: self.drawer.params.profile_fill_color = theme.track_color self.drawer.params.profile_font_color = theme.background_color + self.drawer.params.profile_font_size = self.stats_font.fontsize + self.drawer.params.profile_fontproperties = self.stats_font.font.value + self.drawer.params.centered_title_font_color = theme.point_color self.drawer.params.centered_title_fontproperties = self.font.font.value self.drawer.params.centered_title_font_size = self.font._current_fontsize diff --git a/pretty_gpx/ui/pages/mountain/page.py b/pretty_gpx/ui/pages/mountain/page.py index c4878fe..55e7be8 100644 --- a/pretty_gpx/ui/pages/mountain/page.py +++ b/pretty_gpx/ui/pages/mountain/page.py @@ -2,11 +2,14 @@ """Mountain Page.""" from dataclasses import dataclass +from pretty_gpx.common.drawing.utils.drawing_figure import A4Float +from pretty_gpx.common.drawing.utils.fonts import STATS_FONTS from pretty_gpx.common.drawing.utils.scatter_point import ScatterPointCategory from pretty_gpx.rendering_modes.mountain.drawing.hillshading import AZIMUTHS from pretty_gpx.rendering_modes.mountain.drawing.mountain_colors import MOUNTAIN_COLOR_THEMES from pretty_gpx.rendering_modes.mountain.drawing.mountain_drawer import MountainDrawer from pretty_gpx.rendering_modes.mountain.drawing.mountain_params import MountainParams +from pretty_gpx.ui.pages.template.ui_font_and_size_select import UiFontAndSizeSelect from pretty_gpx.ui.pages.template.ui_input import UiInputInt from pretty_gpx.ui.pages.template.ui_manager import UiManager from pretty_gpx.ui.pages.template.ui_toggle import UiToggle @@ -22,6 +25,7 @@ class MountainUiManager(UiManager[MountainDrawer]): """Mountain Ui Manager.""" uphill: UiInputInt azimuth: UiToggle[int] + stats_font: UiFontAndSizeSelect def __init__(self) -> None: drawer = MountainDrawer(params=MountainParams.default(), top_ratio=0.18, bot_ratio=0.22, margin_ratio=0.1) @@ -35,6 +39,10 @@ def __init__(self) -> None: self.azimuth = UiToggle[int].create(mapping=AZIMUTHS, tooltip="Select the azimuth angle for the hillshading", on_change=self.on_click_update) + self.stats_font = UiFontAndSizeSelect(label="Stats' Font", + fonts=STATS_FONTS, + start_fontsize=A4Float(mm=14), + on_change=self.on_click_update) @staticmethod def get_chat_msg() -> list[str]: @@ -53,8 +61,12 @@ def update_drawer_params(self) -> None: self.drawer.params.mountain_background_color = theme.background_color self.drawer.params.mountain_dark_mode = theme.dark_mode self.drawer.params.mountain_azimuth = self.azimuth.value + self.drawer.params.profile_fill_color = theme.track_color self.drawer.params.profile_font_color = theme.background_color + self.drawer.params.profile_font_size = self.stats_font.fontsize + self.drawer.params.profile_fontproperties = self.stats_font.font.value + self.drawer.params.centered_title_font_color = theme.peak_color self.drawer.params.centered_title_fontproperties = self.font.font.value self.drawer.params.centered_title_font_size = self.font._current_fontsize diff --git a/pretty_gpx/ui/pages/multi_mountain/page.py b/pretty_gpx/ui/pages/multi_mountain/page.py index 7a2b656..ceacc5d 100644 --- a/pretty_gpx/ui/pages/multi_mountain/page.py +++ b/pretty_gpx/ui/pages/multi_mountain/page.py @@ -2,12 +2,15 @@ """Multi Mountain Page.""" from dataclasses import dataclass +from pretty_gpx.common.drawing.utils.drawing_figure import A4Float +from pretty_gpx.common.drawing.utils.fonts import STATS_FONTS from pretty_gpx.common.drawing.utils.plt_marker import MarkerType from pretty_gpx.common.drawing.utils.scatter_point import ScatterPointCategory from pretty_gpx.rendering_modes.mountain.drawing.hillshading import AZIMUTHS from pretty_gpx.rendering_modes.mountain.drawing.mountain_colors import MOUNTAIN_COLOR_THEMES from pretty_gpx.rendering_modes.multi_mountain.drawing.multi_mountain_drawer import MultiMountainDrawer from pretty_gpx.rendering_modes.multi_mountain.drawing.multi_mountain_params import MultiMountainParams +from pretty_gpx.ui.pages.template.ui_font_and_size_select import UiFontAndSizeSelect from pretty_gpx.ui.pages.template.ui_icon_toggle import UiIconToggle from pretty_gpx.ui.pages.template.ui_input import UiInputInt from pretty_gpx.ui.pages.template.ui_manager import UiManager @@ -25,6 +28,7 @@ class MultiMountainUiManager(UiManager[MultiMountainDrawer]): uphill: UiInputInt azimuth: UiToggle[int] hut_icon: UiIconToggle + stats_font: UiFontAndSizeSelect def __init__(self) -> None: drawer = MultiMountainDrawer(params=MultiMountainParams.default(), @@ -41,6 +45,10 @@ def __init__(self) -> None: on_change=self.on_click_update) self.hut_icon = UiIconToggle(markers=[MarkerType.HOUSE, MarkerType.CAMPING], on_change=self.on_click_update) + self.stats_font = UiFontAndSizeSelect(label="Stats' Font", + fonts=STATS_FONTS, + start_fontsize=A4Float(mm=14), + on_change=self.on_click_update) @staticmethod def get_chat_msg() -> list[str]: @@ -62,8 +70,12 @@ def update_drawer_params(self) -> None: self.drawer.params.mountain_background_color = theme.background_color self.drawer.params.mountain_dark_mode = theme.dark_mode self.drawer.params.mountain_azimuth = self.azimuth.value + self.drawer.params.profile_fill_color = theme.track_color self.drawer.params.profile_font_color = theme.background_color + self.drawer.params.profile_font_size = self.stats_font.fontsize + self.drawer.params.profile_fontproperties = self.stats_font.font.value + self.drawer.params.centered_title_font_color = theme.peak_color self.drawer.params.centered_title_fontproperties = self.font.font.value self.drawer.params.centered_title_font_size = self.font._current_fontsize diff --git a/pretty_gpx/ui/pages/template/ui_font_select.py b/pretty_gpx/ui/pages/template/ui_font_select.py index 129850c..a3c449b 100644 --- a/pretty_gpx/ui/pages/template/ui_font_select.py +++ b/pretty_gpx/ui/pages/template/ui_font_select.py @@ -44,7 +44,7 @@ async def handler() -> None: if font_css_header is not None: ui.add_css(font_css_header) - items = [ui.item(font.font_name, on_click=on_click_idx(idx)) + items = [ui.item(font.name.title().replace("_", " "), on_click=on_click_idx(idx)) .style(f'font-family:"{font.font_name}";') for idx, font in enumerate(fonts)] diff --git a/pretty_gpx/ui/pages/template/ui_manager.py b/pretty_gpx/ui/pages/template/ui_manager.py index 340fd79..928a8c3 100644 --- a/pretty_gpx/ui/pages/template/ui_manager.py +++ b/pretty_gpx/ui/pages/template/ui_manager.py @@ -19,7 +19,7 @@ from pretty_gpx.common.drawing.utils.drawer import DrawerMultiTrack from pretty_gpx.common.drawing.utils.drawer import DrawerSingleTrack from pretty_gpx.common.drawing.utils.drawing_figure import A4Float -from pretty_gpx.common.drawing.utils.fonts import CustomFont +from pretty_gpx.common.drawing.utils.fonts import TITLE_FONTS from pretty_gpx.common.layout.paper_size import PAPER_SIZES from pretty_gpx.common.layout.paper_size import PaperSize from pretty_gpx.common.utils.logger import logger @@ -208,11 +208,7 @@ def __init__(self, drawer: T) -> None: with self.subclass_column: self.font = UiFontAndSizeSelect(label="Title's Font", - fonts=(CustomFont.LOBSTER, - CustomFont.MONOTON, - CustomFont.GOCHI_HAND, - CustomFont.EMILIO_20, - CustomFont.ALLERTA_STENCIL), + fonts=TITLE_FONTS, start_fontsize=A4Float(mm=20), on_change=self.on_click_update) self.title = UiInputStr.create(label='Title', value="Title", tooltip="Press Enter to update title",