From 519d3e69a97434e781d9e983fb9aedfbd399b350 Mon Sep 17 00:00:00 2001 From: Peter Baker Date: Fri, 17 Jan 2025 12:25:41 -0500 Subject: [PATCH] No longer observe distinction of black, white, gray distance. --- src/ygt/makeCVDialog.py | 62 +++++++++++--------- src/ygt/window.py | 2 +- src/ygt/ygHintEditor.py | 127 +++++++++++++++++++++------------------- src/ygt/ygModel.py | 15 +++-- src/ygt/ygSchema.py | 25 +++++--- 5 files changed, 131 insertions(+), 100 deletions(-) diff --git a/src/ygt/makeCVDialog.py b/src/ygt/makeCVDialog.py index 05ef317..fa00250 100644 --- a/src/ygt/makeCVDialog.py +++ b/src/ygt/makeCVDialog.py @@ -560,7 +560,7 @@ def __init__( self.general_tab_layout = QVBoxLayout() self.cv_type_widget = cvTypeWidget(self.cv_source) - self.cv_color_widget = cvColorWidget(self.cv_source) + #self.cv_color_widget = cvColorWidget(self.cv_source) self.cv_axis_widget = cvAxisWidget(self.cv_source) self.cv_val_widget = cvValueWidget(self.cv_source) self.cv_name_widget = cvNameWidget(self.cv_source, owner=self.owner) @@ -593,9 +593,9 @@ def __init__( self.gen_widgets[-1].addWidget(QLabel("suffix")) self.gen_widgets[-1].addWidget(self.cv_suffix_widget) - self.gen_widgets.append(QHBoxLayout()) - self.gen_widgets[-1].addWidget(QLabel("distance type")) - self.gen_widgets[-1].addWidget(self.cv_color_widget) + # self.gen_widgets.append(QHBoxLayout()) + # self.gen_widgets[-1].addWidget(QLabel("distance type")) + # self.gen_widgets[-1].addWidget(self.cv_color_widget) # Set up link tab @@ -699,7 +699,7 @@ def refresh(self, cv_source: cvSource) -> None: self.cv_name_widget.refresh(self.cv_source) self.cv_type_widget.refresh(self.cv_source) self.cv_axis_widget.refresh(self.cv_source) - self.cv_color_widget.refresh(self.cv_source) + #self.cv_color_widget.refresh(self.cv_source) self.cv_val_widget.refresh(self.cv_source) self.cv_cat_widget.refresh(self.cv_source) self.cv_suffix_widget.refresh(self.cv_source) @@ -715,7 +715,7 @@ def fixup(self) -> None: self.cv_name_widget.fixup() self.cv_type_widget.fixup() self.cv_axis_widget.fixup() - self.cv_color_widget.fixup() + #self.cv_color_widget.fixup() self.cv_val_widget.fixup() self.cv_cat_widget.fixup() self.cv_suffix_widget.fixup() @@ -780,20 +780,25 @@ def __init__(self, yg_font: ygFont) -> None: self.anchor_layout.addWidget(self.anchor_checkbox) self.layout_obj.addLayout(self.anchor_layout) - self.blackdist_layout = QHBoxLayout() - self.blackdist_checkbox = QCheckBox("Black distance") - self.blackdist_layout.addWidget(self.blackdist_checkbox) - self.layout_obj.addLayout(self.blackdist_layout) + self.stem_layout = QHBoxLayout() + self.stem_checkbox = QCheckBox("Stem") + self.stem_layout.addWidget(self.stem_checkbox) + self.layout_obj.addLayout(self.stem_layout) + + # self.blackdist_layout = QHBoxLayout() + # self.blackdist_checkbox = QCheckBox("Black distance") + # self.blackdist_layout.addWidget(self.blackdist_checkbox) + # self.layout_obj.addLayout(self.blackdist_layout) - self.whitedist_layout = QHBoxLayout() - self.whitedist_checkbox = QCheckBox("White distance") - self.whitedist_layout.addWidget(self.whitedist_checkbox) - self.layout_obj.addLayout(self.whitedist_layout) + # self.whitedist_layout = QHBoxLayout() + # self.whitedist_checkbox = QCheckBox("White distance") + # self.whitedist_layout.addWidget(self.whitedist_checkbox) + # self.layout_obj.addLayout(self.whitedist_layout) - self.graydist_layout = QHBoxLayout() - self.graydist_checkbox = QCheckBox("Gray distance") - self.graydist_layout.addWidget(self.graydist_checkbox) - self.layout_obj.addLayout(self.graydist_layout) + # self.graydist_layout = QHBoxLayout() + # self.graydist_checkbox = QCheckBox("Gray distance") + # self.graydist_layout.addWidget(self.graydist_checkbox) + # self.layout_obj.addLayout(self.graydist_layout) self.shift_layout = QHBoxLayout() self.shift_checkbox = QCheckBox("Shift") @@ -813,9 +818,10 @@ def __init__(self, yg_font: ygFont) -> None: self.refresh() self.anchor_checkbox.stateChanged.connect(self.button_state_changed) - self.blackdist_checkbox.stateChanged.connect(self.button_state_changed) - self.whitedist_checkbox.stateChanged.connect(self.button_state_changed) - self.graydist_checkbox.stateChanged.connect(self.button_state_changed) + self.stem_checkbox.stateChanged.connect(self.button_state_changed) + # self.blackdist_checkbox.stateChanged.connect(self.button_state_changed) + # self.whitedist_checkbox.stateChanged.connect(self.button_state_changed) + # self.graydist_checkbox.stateChanged.connect(self.button_state_changed) self.shift_checkbox.stateChanged.connect(self.button_state_changed) self.align_checkbox.stateChanged.connect(self.button_state_changed) self.interpolate_checkbox.stateChanged.connect(self.button_state_changed) @@ -828,9 +834,10 @@ def button_state_changed(self) -> None: return r = {} r["anchor"] = self.anchor_checkbox.isChecked() - r["blackdist"] = self.blackdist_checkbox.isChecked() - r["whitedist"] = self.whitedist_checkbox.isChecked() - r["graydist"] = self.graydist_checkbox.isChecked() + r["stem"] = self.stem_checkbox.isChecked() + # r["blackdist"] = self.blackdist_checkbox.isChecked() + # r["whitedist"] = self.whitedist_checkbox.isChecked() + # r["graydist"] = self.graydist_checkbox.isChecked() r["shift"] = self.shift_checkbox.isChecked() r["align"] = self.align_checkbox.isChecked() r["interpolate"] = self.interpolate_checkbox.isChecked() @@ -842,9 +849,10 @@ def fixup(self) -> None: def refresh(self) -> None: self.ignore_signal = True self.anchor_checkbox.setChecked(self.defaults.rounding_state("anchor")) - self.blackdist_checkbox.setChecked(self.defaults.rounding_state("blackdist")) - self.whitedist_checkbox.setChecked(self.defaults.rounding_state("whitedist")) - self.graydist_checkbox.setChecked(self.defaults.rounding_state("graydist")) + self.stem_checkbox.setChecked(self.defaults.rounding_state("stem")) + # self.blackdist_checkbox.setChecked(self.defaults.rounding_state("blackdist")) + # self.whitedist_checkbox.setChecked(self.defaults.rounding_state("whitedist")) + # self.graydist_checkbox.setChecked(self.defaults.rounding_state("graydist")) self.shift_checkbox.setChecked(self.defaults.rounding_state("shift")) self.align_checkbox.setChecked(self.defaults.rounding_state("align")) self.interpolate_checkbox.setChecked( diff --git a/src/ygt/window.py b/src/ygt/window.py index adbc9ae..60b818b 100755 --- a/src/ygt/window.py +++ b/src/ygt/window.py @@ -61,7 +61,7 @@ # FileNameVar = TypeVar("FileNameVar", str, tuple[str, Any]) FileNameVar = Union[str, tuple[str, Any]] # FileNameVar = Any -ygt_version = "0.2.6" +ygt_version = "0.2.7" class ygPreviewFontMaker(QThread): diff --git a/src/ygt/ygHintEditor.py b/src/ygt/ygHintEditor.py index ebaf750..30e8580 100644 --- a/src/ygt/ygHintEditor.py +++ b/src/ygt/ygHintEditor.py @@ -148,9 +148,9 @@ "shift": HINT_SHIFT_COLOR, "interpolate": HINT_INTERPOLATE_COLOR, "stem": HINT_STEM_COLOR, - "whitedist": HINT_STEM_COLOR, - "blackdist": HINT_STEM_COLOR, - "graydist": HINT_STEM_COLOR, + # "whitedist": HINT_STEM_COLOR, + # "blackdist": HINT_STEM_COLOR, + # "graydist": HINT_STEM_COLOR, "move": HINT_STEM_COLOR, "macro": HINT_FUNC_COLOR, "function": HINT_FUNC_COLOR, @@ -162,9 +162,9 @@ "shift": HINT_SHIFT_DARK, "interpolate": HINT_INTERPOLATE_DARK, "stem": HINT_STEM_DARK, - "whitedist": HINT_STEM_DARK, - "blackdist": HINT_STEM_DARK, - "graydist": HINT_STEM_DARK, + # "whitedist": HINT_STEM_DARK, + # "blackdist": HINT_STEM_DARK, + # "graydist": HINT_STEM_DARK, "move": HINT_STEM_DARK, "macro": HINT_FUNC_DARK, "function": HINT_FUNC_DARK, @@ -178,9 +178,9 @@ "shift": HINT_SHIFT_SELECT_COLOR, "interpolate": HINT_INTERPOLATE_SELECT_COLOR, "stem": HINT_STEM_SELECT_COLOR, - "whitedist": HINT_STEM_SELECT_COLOR, - "blackdist": HINT_STEM_SELECT_COLOR, - "graydist": HINT_STEM_SELECT_COLOR, + # "whitedist": HINT_STEM_SELECT_COLOR, + # "blackdist": HINT_STEM_SELECT_COLOR, + # "graydist": HINT_STEM_SELECT_COLOR, "move": HINT_STEM_SELECT_COLOR, "macro": HINT_FUNC_SELECT_COLOR, "function": HINT_FUNC_SELECT_COLOR, @@ -192,9 +192,9 @@ "shift": HINT_SHIFT_SELECT_DARK, "interpolate": HINT_INTERPOLATE_SELECT_DARK, "stem": HINT_STEM_SELECT_DARK, - "whitedist": HINT_STEM_SELECT_DARK, - "blackdist": HINT_STEM_SELECT_DARK, - "graydist": HINT_STEM_SELECT_DARK, + # "whitedist": HINT_STEM_SELECT_DARK, + # "blackdist": HINT_STEM_SELECT_DARK, + # "graydist": HINT_STEM_SELECT_DARK, "move": HINT_STEM_SELECT_DARK, "macro": HINT_FUNC_SELECT_DARK, "function": HINT_FUNC_SELECT_DARK, @@ -839,10 +839,10 @@ def _prepare_graphics(self, **kwargs) -> None: pen.setColor(SELECTED_HINT_COLOR[hint_type]) else: pen.setColor(HINT_COLOR[hint_type]) - if hint_type == "whitedist": - pen.setDashPattern([2, 2]) - if hint_type == "graydist": - pen.setDashPattern([4, 2]) + # if hint_type == "whitedist": + # pen.setDashPattern([2, 2]) + # if hint_type == "graydist": + # pen.setDashPattern([4, 2]) self.setPen(pen) def find_mid_point(self, pt1: QPointF, pt2: QPointF) -> QPointF: @@ -2487,15 +2487,17 @@ def make_hint_from_selection( self.sig_new_hint.emit(new_yg_hint) if hint_type_num in [1, 3]: if pplen >= 2: - try: - if hint_type_num == 3: - hint_type = stemFinder( - self._model_point(pp[0]), - self._model_point(pp[1]), - self.yg_glyph, - ).get_color() - except Exception as e: - print(e) + # try: + # if hint_type_num == 3: + # hint_type = stemFinder( + # self._model_point(pp[0]), + # self._model_point(pp[1]), + # self.yg_glyph, + # ).get_color() + # except Exception as e: + # print(e) + if hint_type_num == 3: + hint_type = "stem" ref_name = "" target_names = [] for ppp in pp: @@ -2551,6 +2553,7 @@ def make_hint_from_selection( h = {"ptid": tgt, "ref": touched_names, "rel": hint_type} # type: ignore new_yg_hint = ygHint(self.yg_glyph, h) else: + # Are we handling a case here that will never happen? newlist = [] for p in pp: newlist.append(self._model_point(p)) @@ -2727,7 +2730,7 @@ def contextMenuEvent(self, event) -> None: cv_anchor_action_list = [] cv_stem_action_list = [] point_param_list = [] - black_space = white_space = gray_space = None + #black_space = white_space = gray_space = None cmenu.addSeparator() @@ -2821,34 +2824,35 @@ def contextMenuEvent(self, event) -> None: hint_color_menu = cmenu.addMenu("Set distance type...") - no_color_menu = hint == None or ntype != 3 - - black_space = QAction("Black", self, checkable=True) # type: ignore - if hint != None: - if hint.yg_hint.hint_type in ["stem", "blackdist"]: - black_space.setChecked(True) - hint_color_menu.addAction(black_space) - if no_color_menu: - black_space.setEnabled(False) - black_space.setVisible(False) - - white_space = QAction("White", self, checkable=True) # type: ignore - if hint != None: - if hint.yg_hint.hint_type == "whitedist": - white_space.setChecked(True) - hint_color_menu.addAction(white_space) - if no_color_menu: - white_space.setEnabled(False) - white_space.setVisible(False) - - gray_space = QAction("Gray", self, checkable=True) # type: ignore - if hint != None: - if hint.yg_hint.hint_type == "graydist": - gray_space.setChecked(True) - hint_color_menu.addAction(gray_space) - if no_color_menu: - gray_space.setEnabled(False) - gray_space.setVisible(False) + #no_color_menu = hint == None or ntype != 3 + no_color_menu = True + + # black_space = QAction("Black", self, checkable=True) # type: ignore + # if hint != None: + # if hint.yg_hint.hint_type in ["stem", "blackdist"]: + # black_space.setChecked(True) + # hint_color_menu.addAction(black_space) + # if no_color_menu: + # black_space.setEnabled(False) + # black_space.setVisible(False) + + # white_space = QAction("White", self, checkable=True) # type: ignore + # if hint != None: + # if hint.yg_hint.hint_type == "whitedist": + # white_space.setChecked(True) + # hint_color_menu.addAction(white_space) + # if no_color_menu: + # white_space.setEnabled(False) + # white_space.setVisible(False) + + # gray_space = QAction("Gray", self, checkable=True) # type: ignore + # if hint != None: + # if hint.yg_hint.hint_type == "graydist": + # gray_space.setChecked(True) + # hint_color_menu.addAction(gray_space) + # if no_color_menu: + # gray_space.setEnabled(False) + # gray_space.setVisible(False) if no_color_menu: a = hint_color_menu.menuAction() @@ -3022,12 +3026,12 @@ def contextMenuEvent(self, event) -> None: self.yg_glyph.send_error_message( {"msg": self.cv_error_msg, "mode": "console"} ) - if hint and ntype == 3 and (action == black_space): - self.sig_change_hint_color.emit({"hint": hint, "color": "blackdist"}) - if hint and ntype == 3 and (action == white_space): - self.sig_change_hint_color.emit({"hint": hint, "color": "whitedist"}) - if hint and ntype == 3 and (action == gray_space): - self.sig_change_hint_color.emit({"hint": hint, "color": "graydist"}) + # if hint and ntype == 3 and (action == black_space): + # self.sig_change_hint_color.emit({"hint": hint, "color": "blackdist"}) + # if hint and ntype == 3 and (action == white_space): + # self.sig_change_hint_color.emit({"hint": hint, "color": "whitedist"}) + # if hint and ntype == 3 and (action == gray_space): + # self.sig_change_hint_color.emit({"hint": hint, "color": "graydist"}) if hint and ntype == 4 and (action == add_params): self.sig_edit_macfunc_params.emit(hint) if action in macro_actions: @@ -3220,7 +3224,8 @@ def make_hint_from_selection(self) -> None: "Align (L)": "align", "Shift (H)": "shift", "Interpolate (I)": "interpolate", - "Stem (T)": "graydist", + #"Stem (T)": "graydist", + "Stem (T)": "stem", } with_ctrl = ( QApplication.keyboardModifiers() & Qt.KeyboardModifier.ControlModifier diff --git a/src/ygt/ygModel.py b/src/ygt/ygModel.py index 6876f36..d135995 100644 --- a/src/ygt/ygModel.py +++ b/src/ygt/ygModel.py @@ -11,7 +11,7 @@ from PyQt6.QtGui import QUndoCommand, QUndoStack, QAction from fontTools import ttLib, ufoLib # type: ignore import yaml -from yaml import Dumper +from yaml import Dumper, parse import os import pathlib import uuid @@ -29,15 +29,19 @@ import defcon # type: ignore from ufo2ft import compileTTF # type: ignore +obsolete_hint_types = [ + "blackdist", "whitedist", "graydist" +] + hint_type_nums = { "anchor": 0, "align": 1, "shift": 1, "interpolate": 2, "stem": 3, - "whitedist": 3, - "blackdist": 3, - "graydist": 3, + # "whitedist": 3, + # "blackdist": 3, + # "graydist": 3, "move": 3, "macro": 4, "function": 4, @@ -2731,6 +2735,9 @@ def _yaml_hint_type(self, n) -> str: if "macro" in n: return "macro" if "rel" in n: + #if n["rel"] == "blackdist" or n["rel"] == "whitedist" or n["rel"] == "graydist": + if n["rel"] in obsolete_hint_types: + n["rel"] = "stem" return n["rel"] return "anchor" diff --git a/src/ygt/ygSchema.py b/src/ygt/ygSchema.py index b2ea3aa..1a7c374 100644 --- a/src/ygt/ygSchema.py +++ b/src/ygt/ygSchema.py @@ -121,9 +121,13 @@ def is_round_valid(r: bool | str) -> bool: Optional("dist"): str, Optional("pos"): str, Optional("round"): is_round_valid, + # Optional("min"): bool, + # "rel": Or( + # "stem", "blackdist", "whitedist", "graydist", "shift", "align", "interpolate" + # ), Optional("min"): bool, "rel": Or( - "stem", "blackdist", "whitedist", "graydist", "shift", "align", "interpolate" + "stem", "shift", "align", "interpolate" ), Optional("points"): validate_points, } @@ -140,11 +144,17 @@ def is_round_valid(r: bool | str) -> bool: Optional("min"): bool, Optional("function"): Or(str, dict), Optional("macro"): Or(str, dict), + # Optional("rel"): Or( + # "stem", + # "blackdist", + # "whitedist", + # "graydist", + # "shift", + # "align", + # "interpolate", + # ), Optional("rel"): Or( "stem", - "blackdist", - "whitedist", - "graydist", "shift", "align", "interpolate", @@ -244,9 +254,10 @@ def is_round_valid(r: bool | str) -> bool: } hint_types = [ - "blackdist", - "whitedist", - "graydist", + "stem", + # "blackdist", + # "whitedist", + # "graydist", "anchor", "shift", "align",