fontlab-python-plugmix 1.1.18__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. fontlab_plugmix/__init__.py +41 -0
  2. fontlab_plugmix/backend.py +285 -0
  3. fontlab_plugmix/boot.py +140 -0
  4. fontlab_plugmix/filter.py +83 -0
  5. fontlab_plugmix/filters/__init__.py +4 -0
  6. fontlab_plugmix/filters/apply.py +158 -0
  7. fontlab_plugmix/filters/delete_small_paths.py +57 -0
  8. fontlab_plugmix/filters/dialog.py +119 -0
  9. fontlab_plugmix/filters/host.py +120 -0
  10. fontlab_plugmix/general.py +144 -0
  11. fontlab_plugmix/general_plugins/__init__.py +4 -0
  12. fontlab_plugmix/general_plugins/host.py +137 -0
  13. fontlab_plugmix/general_plugins/zoom_to_selection.py +27 -0
  14. fontlab_plugmix/geometry.py +64 -0
  15. fontlab_plugmix/kinds.py +33 -0
  16. fontlab_plugmix/menu.py +29 -0
  17. fontlab_plugmix/palette.py +24 -0
  18. fontlab_plugmix/palettes/__init__.py +4 -0
  19. fontlab_plugmix/palettes/apply.py +159 -0
  20. fontlab_plugmix/palettes/host.py +369 -0
  21. fontlab_plugmix/palettes/step_and_repeat.py +53 -0
  22. fontlab_plugmix/palettes/ui.py +86 -0
  23. fontlab_plugmix/plugin.py +14 -0
  24. fontlab_plugmix/plugins/__init__.py +4 -0
  25. fontlab_plugmix/plugins/anchor_cloud.py +30 -0
  26. fontlab_plugmix/plugins/angled_handles.py +40 -0
  27. fontlab_plugmix/plugins/center_lines.py +28 -0
  28. fontlab_plugmix/plugins/crosshair.py +39 -0
  29. fontlab_plugmix/plugins/duplicate_anchors.py +50 -0
  30. fontlab_plugmix/plugins/glyph_focus.py +28 -0
  31. fontlab_plugmix/plugins/imprecise_italic_angle.py +44 -0
  32. fontlab_plugmix/plugins/node_indexes.py +26 -0
  33. fontlab_plugmix/plugins/nodes_close_to_zones.py +35 -0
  34. fontlab_plugmix/plugins/offcurve_outside_bounds.py +31 -0
  35. fontlab_plugmix/plugins/only_selected_handles.py +38 -0
  36. fontlab_plugmix/plugins/rsb_line.py +39 -0
  37. fontlab_plugmix/plugins/segment_length.py +36 -0
  38. fontlab_plugmix/plugins/selected_coordinates.py +27 -0
  39. fontlab_plugmix/plugins/smooth_node_angles.py +51 -0
  40. fontlab_plugmix/plugins/tops_and_bottoms.py +34 -0
  41. fontlab_plugmix/plugins/two_point_distance.py +38 -0
  42. fontlab_plugmix/plugins/unitizer.py +35 -0
  43. fontlab_plugmix/plugins/vertical_metrics.py +39 -0
  44. fontlab_plugmix/registry.py +434 -0
  45. fontlab_plugmix/reporter.py +127 -0
  46. fontlab_plugmix/snapshot.py +285 -0
  47. fontlab_plugmix/tool.py +104 -0
  48. fontlab_plugmix/tools/__init__.py +4 -0
  49. fontlab_plugmix/tools/bridge.py +169 -0
  50. fontlab_plugmix/tools/host.py +143 -0
  51. fontlab_plugmix/tools/smart_select.py +77 -0
  52. fontlab_python_plugmix-1.1.18.dist-info/METADATA +444 -0
  53. fontlab_python_plugmix-1.1.18.dist-info/RECORD +56 -0
  54. fontlab_python_plugmix-1.1.18.dist-info/WHEEL +4 -0
  55. fontlab_python_plugmix-1.1.18.dist-info/licenses/LICENSE +201 -0
  56. fontlab_python_plugmix-1.1.18.dist-info/licenses/NOTICE +228 -0
@@ -0,0 +1,369 @@
1
+ # this_file: src/fontlab_plugmix/palettes/host.py
2
+ """Own docked palette instances, Window toggles and one shared refresh timer."""
3
+
4
+ from dataclasses import dataclass
5
+ from importlib import import_module
6
+ from typing import Any
7
+
8
+ from fontlab_plugmix import snapshot
9
+ from fontlab_plugmix.kinds import Services, guarded
10
+
11
+ from .ui import PaletteUI
12
+
13
+
14
+ @dataclass
15
+ class _Panel:
16
+ """Strong references to one palette and its owned Qt signals."""
17
+
18
+ plugin: Any
19
+ ui: PaletteUI
20
+ owned: Any
21
+ visibility: Any = None
22
+ close_filter: Any = None
23
+ visible: bool = True
24
+
25
+
26
+ def _close_filter(
27
+ base: type, close_type: Any, callback: Any, plugin: Any, sink: Any
28
+ ) -> Any:
29
+ """Create a guarded event filter that only observes explicit dock closes."""
30
+
31
+ class CloseFilter(base):
32
+ def eventFilter(self, watched: Any, event: Any) -> bool:
33
+ guarded(
34
+ plugin, sink, lambda: callback() if event.type() == close_type else None
35
+ )
36
+ return False
37
+
38
+ return CloseFilter()
39
+
40
+
41
+ class PaletteHost:
42
+ """Bind every Palette to an OwnedWidget and refresh visible ones together."""
43
+
44
+ def __init__(self, services: Services, registry: Any) -> None:
45
+ self.services, self.registry = services, registry
46
+ self.actions: dict[str, int] = {}
47
+ self.panels: dict[str, _Panel] = {}
48
+ self.timer: Any = None
49
+ self._tick: Any = None
50
+ self._key: Any = object()
51
+ self._context: Any = None
52
+ self._has_context = False
53
+ self._running = False
54
+ self._close_filter_available = True
55
+ self._close_failures: set[tuple[str, str]] = set()
56
+ self.listeners: dict[str, Any] = {}
57
+
58
+ def _close_filter_base(self) -> type:
59
+ """Use FontLab's PythonQt.private QObject, then older QtCore builds."""
60
+ qt = self.services.qt
61
+ base = getattr(getattr(qt, "private", None), "QObject", None)
62
+ if base is None:
63
+ base = getattr(qt.QtCore, "QObject", None)
64
+ if base is None:
65
+ raise AttributeError("PythonQt has no QObject base for dock close events")
66
+ return base
67
+
68
+ def _degrade_close(self, error: Exception) -> None:
69
+ """Report once; the Window action remains the reliable close control."""
70
+ self._close_filter_available = False
71
+ message = RuntimeError(
72
+ f"Dock close detection unavailable ({error}); use the Window toggle to close"
73
+ )
74
+ try:
75
+ self.services.sink(message, self)
76
+ except Exception: # noqa: BLE001, S110 - diagnostics cannot block Show
77
+ pass
78
+
79
+ def _install_close_filter(self, panel: _Panel, name: str) -> None:
80
+ """Try the optional native event filter without risking panel Show."""
81
+ if not self._close_filter_available:
82
+ return
83
+ widget = panel.owned.widget
84
+ filter_object = None
85
+ try:
86
+ filter_object = _close_filter(
87
+ self._close_filter_base(),
88
+ self.services.qt.QtCore.QEvent.Close,
89
+ lambda: self._schedule_close(name),
90
+ panel.plugin,
91
+ self.services.sink,
92
+ )
93
+ widget.installEventFilter(filter_object)
94
+ except Exception as error: # noqa: BLE001 - optional PythonQt capability
95
+ if filter_object is not None:
96
+ try:
97
+ widget.removeEventFilter(filter_object)
98
+ except Exception: # noqa: BLE001, S110 - may not have installed
99
+ pass
100
+ self._degrade_close(error)
101
+ else:
102
+ panel.close_filter = filter_object
103
+
104
+ def install(self) -> None:
105
+ """Create one checkable Window action and restore chosen panels."""
106
+ for name, cls in self.registry.available("palette").items():
107
+ token = self.services.menus.add_action(
108
+ "Window",
109
+ f"Plugmix: {cls.title} Panel",
110
+ lambda *args, name=name: guarded(
111
+ self, self.services.sink, lambda: self.toggle(name)
112
+ ),
113
+ checkable=True,
114
+ )
115
+ self.actions[name] = token
116
+ self.services.menus.action(token).setChecked(
117
+ name in self.registry.enabled_palettes()
118
+ )
119
+ for name in self.registry.enabled_palettes():
120
+ if name in self.actions:
121
+ guarded(self, self.services.sink, lambda name=name: self._show(name))
122
+ self._checked(name)
123
+
124
+ def _timer(self) -> None:
125
+ """Create the sole timer lazily, then start it for visible panels."""
126
+ if self.timer is None:
127
+ timer = self.services.qt.QtCore.QTimer()
128
+ self._tick = self._tick_once
129
+ try:
130
+ timer.setInterval(250)
131
+ timer.timeout.connect(self._tick)
132
+ except Exception:
133
+ guarded(self, self.services.sink, timer.deleteLater)
134
+ raise
135
+ self.timer = timer
136
+ self._sync_timer()
137
+
138
+ def _sync_timer(self) -> None:
139
+ """Run polling exactly while at least one dock is visible."""
140
+ if self.timer is None:
141
+ return
142
+ visible = bool(self.listeners) or any(
143
+ panel.visible for panel in self.panels.values()
144
+ )
145
+ if visible and not self._running:
146
+ self._key = object()
147
+ self._has_context = False
148
+ self.timer.start()
149
+ self._running = True
150
+ elif not visible and self._running:
151
+ guarded(self, self.services.sink, self.timer.stop)
152
+ self._running = False
153
+ self._has_context = False
154
+
155
+ def _tick_once(self) -> None:
156
+ """Poll palettes and other subscribers on the same guarded QTimer."""
157
+ if any(panel.visible for panel in self.panels.values()):
158
+ guarded(self, self.services.sink, self._poll)
159
+ for callback in tuple(self.listeners.values()):
160
+ guarded(self, self.services.sink, callback)
161
+
162
+ def subscribe(self, name: str, callback: Any) -> None:
163
+ """Share the palette timer with a General plugin's font watcher."""
164
+ self.listeners[name] = callback
165
+ self._timer()
166
+
167
+ def unsubscribe(self, name: str) -> None:
168
+ """Stop polling when no visible palette or other subscriber remains."""
169
+ self.listeners.pop(name, None)
170
+ self._sync_timer()
171
+
172
+ def _show(self, name: str) -> None:
173
+ """Build a docked widget once and attach its guarded close signal."""
174
+ if name in self.panels:
175
+ return
176
+ plugin = self.registry.available("palette")[name]()
177
+ ui_box: list[PaletteUI] = []
178
+
179
+ def build(content: Any) -> None:
180
+ ui = PaletteUI(
181
+ self.services.qt,
182
+ content,
183
+ plugin,
184
+ self.services.sink,
185
+ lambda values: plugin.command(values, self.services),
186
+ )
187
+ ui_box.append(ui)
188
+ plugin.build(ui)
189
+
190
+ create_panel = import_module("fontlabapp.widgets").create_panel
191
+ try:
192
+ owned = create_panel(
193
+ self.services.menus.main_window(), plugin.title, build, plugin.area
194
+ )
195
+ except Exception:
196
+ if ui_box:
197
+ ui_box[0].close()
198
+ guarded(plugin, self.services.sink, plugin.close)
199
+ raise
200
+ panel = _Panel(plugin, ui_box[0], owned, visible=bool(owned.widget.isVisible()))
201
+ self.panels[name] = panel
202
+ try:
203
+ signal = owned.widget.visibilityChanged
204
+ panel.visibility = lambda shown, name=name: guarded(
205
+ plugin, self.services.sink, lambda: self._visibility(name, shown)
206
+ )
207
+ signal.connect(panel.visibility)
208
+ self._install_close_filter(panel, name)
209
+ self._timer()
210
+ if self._has_context and panel.visible:
211
+ guarded(
212
+ plugin, self.services.sink, lambda: plugin.refresh(self._context)
213
+ )
214
+ except Exception:
215
+ self._hide(name)
216
+ raise
217
+
218
+ def _visibility(self, name: str, shown: bool) -> None:
219
+ """Pause hidden docks without changing their saved preference."""
220
+ panel = self.panels.get(name)
221
+ if panel is None:
222
+ return
223
+ was_visible = panel.visible
224
+ panel.visible = bool(shown)
225
+ self._sync_timer()
226
+ if shown and not was_visible and self._has_context:
227
+ guarded(
228
+ panel.plugin,
229
+ self.services.sink,
230
+ lambda: panel.plugin.refresh(self._context),
231
+ )
232
+
233
+ def _schedule_close(self, name: str) -> None:
234
+ """Wait until Qt finishes dispatching Close before deleting the dock."""
235
+ self.services.qt.QtCore.QTimer.singleShot(
236
+ 0,
237
+ lambda: guarded(self, self.services.sink, lambda: self._hide_by_user(name)),
238
+ )
239
+
240
+ def _hide_by_user(self, name: str) -> None:
241
+ """Persist only after the owner accepts an actual dock close."""
242
+ panel = self.panels.get(name)
243
+ if panel is None:
244
+ return
245
+ widget = panel.owned.widget
246
+ if widget is None or not widget.isVisible():
247
+ if self._hide(name):
248
+ self.registry.set_palette_enabled(name, False)
249
+ self._checked(name)
250
+
251
+ def _close_failed(self, name: str, error: Exception) -> None:
252
+ """Report one diagnostic for a repeated close failure."""
253
+ key = (name, str(error))
254
+ if key not in self._close_failures:
255
+ self._close_failures.add(key)
256
+ try:
257
+ self.services.sink(error, self)
258
+ except Exception: # noqa: BLE001, S110 - diagnostic sink is untrusted
259
+ pass
260
+
261
+ def _hide(self, name: str) -> bool:
262
+ """Release a panel only after its owner confirms successful close."""
263
+ panel = self.panels.get(name)
264
+ if panel is None:
265
+ return True
266
+ try:
267
+ accepted = panel.owned.close()
268
+ except Exception as error: # noqa: BLE001 - App may raise ExceptionGroup
269
+ self._close_failed(name, error)
270
+ return False
271
+ if accepted is False:
272
+ self._close_failed(name, RuntimeError(f"Palette {name} close refused"))
273
+ return False
274
+ self.panels.pop(name, None)
275
+ self._close_failures = {item for item in self._close_failures if item[0] != name}
276
+ widget = panel.owned.widget
277
+ if widget is not None and panel.visibility is not None:
278
+ guarded(
279
+ panel.plugin,
280
+ self.services.sink,
281
+ lambda: widget.visibilityChanged.disconnect(panel.visibility),
282
+ )
283
+ if widget is not None and panel.close_filter is not None:
284
+ guarded(
285
+ panel.plugin,
286
+ self.services.sink,
287
+ lambda: widget.removeEventFilter(panel.close_filter),
288
+ )
289
+ guarded(panel.plugin, self.services.sink, panel.ui.close)
290
+ guarded(panel.plugin, self.services.sink, panel.plugin.close)
291
+ self._sync_timer()
292
+ return True
293
+
294
+ def _checked(self, name: str) -> None:
295
+ """Keep the owned QAction aligned with actual dock visibility."""
296
+ self.services.menus.action(self.actions[name]).setChecked(name in self.panels)
297
+
298
+ def toggle(self, name: str) -> bool:
299
+ """Show or hide a panel and persist the resulting user choice."""
300
+ if name not in self.actions:
301
+ raise KeyError(name)
302
+ try:
303
+ if name in self.panels:
304
+ if self._hide(name):
305
+ self.registry.set_palette_enabled(name, False)
306
+ else:
307
+ self._show(name)
308
+ try:
309
+ self.registry.set_palette_enabled(name, True)
310
+ except Exception:
311
+ self._hide(name)
312
+ raise
313
+ finally:
314
+ self._checked(name)
315
+ return name in self.panels
316
+
317
+ def _poll(self) -> None:
318
+ """Capture once and refresh every visible palette only on a key change."""
319
+ active = snapshot.active_glyph(self.services.fontlab)
320
+ key = snapshot.palette_key(active)
321
+ if key == self._key:
322
+ return
323
+ self._key = key
324
+ context = (
325
+ snapshot.capture(
326
+ snapshot.NativeSource(active.package, active.layer),
327
+ fontlab=self.services.fontlab,
328
+ )
329
+ if active
330
+ else None
331
+ )
332
+ self._context = context
333
+ self._has_context = True
334
+ for panel in tuple(self.panels.values()):
335
+ if not panel.visible:
336
+ continue
337
+ guarded(
338
+ panel.plugin,
339
+ self.services.sink,
340
+ lambda panel=panel: panel.plugin.refresh(context),
341
+ )
342
+
343
+ def close(self) -> bool:
344
+ """Stop ownership only after all docks accept close; allow retry."""
345
+ for name in tuple(self.panels):
346
+ self._hide(name)
347
+ if self.panels:
348
+ for name in self.panels:
349
+ self._checked(name)
350
+ return False
351
+ self.listeners.clear()
352
+ if self.timer is not None:
353
+ guarded(self, self.services.sink, self.timer.stop)
354
+ self._running = False
355
+ guarded(
356
+ self,
357
+ self.services.sink,
358
+ lambda: self.timer.timeout.disconnect(self._tick),
359
+ )
360
+ guarded(self, self.services.sink, self.timer.deleteLater)
361
+ self.timer = None
362
+ for token in tuple(self.actions.values()):
363
+ guarded(
364
+ self,
365
+ self.services.sink,
366
+ lambda token=token: self.services.menus.remove(token),
367
+ )
368
+ self.actions.clear()
369
+ return True
@@ -0,0 +1,53 @@
1
+ # this_file: src/fontlab_plugmix/palettes/step_and_repeat.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Repeat selected contours at cumulative x/y offsets in the current glyph."""
4
+
5
+ from typing import Any
6
+
7
+ from fontlab_plugmix.palette import Palette
8
+ from fontlab_plugmix.snapshot import GlyphSnapshot
9
+
10
+ from .apply import repeat_selected, selected_indices
11
+
12
+
13
+ class StepAndRepeat(Palette):
14
+ """A small docked contour duplication control, with one Apply Undo step."""
15
+
16
+ name = "step_and_repeat"
17
+ title = "Step and Repeat"
18
+
19
+ def build(self, ui: Any) -> None:
20
+ """Create number fields and the Apply command once."""
21
+ self.ui = ui
22
+ self.count = ui.number("Copies", 1, integer=True, minimum=0, maximum=100)
23
+ self.dx = ui.number("X offset", 0)
24
+ self.dy = ui.number("Y offset", 50)
25
+ self.status = ui.label("Select a contour, then Apply.")
26
+ ui.button("Apply", self._clicked)
27
+
28
+ def _clicked(self) -> None:
29
+ """Read live control values and show the resulting status message."""
30
+ try:
31
+ values = {
32
+ key: self.ui.value(getattr(self, key)) for key in ("count", "dx", "dy")
33
+ }
34
+ self.ui.set_text(self.status, self.ui.apply(values))
35
+ except Exception as error:
36
+ try:
37
+ self.ui.set_text(self.status, str(error))
38
+ except Exception: # noqa: BLE001, S110 - retain original Apply error
39
+ pass
40
+ raise
41
+
42
+ def command(self, values: dict[str, Any], services: Any) -> str:
43
+ """Apply to the current glyph through the shared outline writer."""
44
+ return repeat_selected(values, services)[2]
45
+
46
+ def refresh(self, context: GlyphSnapshot | None) -> None:
47
+ """Show how many current contours contain a selected node."""
48
+ count = len(selected_indices(context)) if context else 0
49
+ self.ui.set_text(self.status, f"{count} selected contours.")
50
+
51
+ def close(self) -> None:
52
+ """Release the UI reference after the host disconnects its signals."""
53
+ self.ui = None
@@ -0,0 +1,86 @@
1
+ # this_file: src/fontlab_plugmix/palettes/ui.py
2
+ """Small PythonQt facade with owned signal connections for palette controls."""
3
+
4
+ from collections.abc import Callable
5
+ from typing import Any
6
+
7
+ from fontlab_plugmix.kinds import guarded
8
+
9
+
10
+ class PaletteUI:
11
+ """Offer labels, numbers, buttons and checks without exposing Qt imports."""
12
+
13
+ def __init__(
14
+ self, qt: Any, content: Any, plugin: object, sink: Callable, command: Callable
15
+ ) -> None:
16
+ self.qt, self.content = qt, content
17
+ self.plugin, self.sink, self.command = plugin, sink, command
18
+ self.layout = qt.QtGui.QVBoxLayout(content)
19
+ self.connections: list[tuple[Any, Any]] = []
20
+
21
+ def label(self, text: str) -> Any:
22
+ """Append a plain text label and return it for status updates."""
23
+ widget = self.qt.QtGui.QLabel(text, self.content)
24
+ self.layout.addWidget(widget)
25
+ return widget
26
+
27
+ def set_text(self, label: Any, text: str) -> None:
28
+ """Change the text of a label owned by this palette."""
29
+ label.setText(text)
30
+
31
+ def number(
32
+ self,
33
+ label: str,
34
+ value: float,
35
+ *,
36
+ integer: bool = False,
37
+ minimum: float = -1e6,
38
+ maximum: float = 1e6,
39
+ ) -> Any:
40
+ """Append a labelled spin control with a bounded numeric range."""
41
+ gui = self.qt.QtGui
42
+ widget = (gui.QSpinBox if integer else gui.QDoubleSpinBox)(self.content)
43
+ widget.setRange(int(minimum), int(maximum)) if integer else widget.setRange(
44
+ minimum, maximum
45
+ )
46
+ widget.setValue(value)
47
+ row = gui.QFormLayout()
48
+ row.addRow(label, widget)
49
+ self.layout.addLayout(row)
50
+ return widget
51
+
52
+ def checkbox(self, label: str, checked: bool = False) -> Any:
53
+ """Append a checkable option and return its widget handle."""
54
+ widget = self.qt.QtGui.QCheckBox(label, self.content)
55
+ widget.setChecked(checked)
56
+ self.layout.addWidget(widget)
57
+ return widget
58
+
59
+ def button(self, title: str, callback: Callable[[], Any]) -> Any:
60
+ """Connect a guarded button action and remember it for teardown."""
61
+ widget = self.qt.QtGui.QPushButton(title, self.content)
62
+ slot = lambda *args: guarded(self.plugin, self.sink, callback)
63
+ widget.clicked.connect(slot)
64
+ self.connections.append((widget.clicked, slot))
65
+ self.layout.addWidget(widget)
66
+ return widget
67
+
68
+ @staticmethod
69
+ def value(widget: Any) -> Any:
70
+ """Read a PythonQt value property or fake callable consistently."""
71
+ found = widget.value
72
+ return found() if callable(found) else found
73
+
74
+ def apply(self, values: dict[str, Any]) -> Any:
75
+ """Send a palette command through the host-provided edit boundary."""
76
+ return self.command(values)
77
+
78
+ def close(self) -> None:
79
+ """Disconnect callbacks before the dock widget can be deleted."""
80
+ for signal, callback in self.connections:
81
+ guarded(
82
+ self.plugin,
83
+ self.sink,
84
+ lambda signal=signal, callback=callback: signal.disconnect(callback),
85
+ )
86
+ self.connections.clear()
@@ -0,0 +1,14 @@
1
+ # this_file: src/fontlab_plugmix/plugin.py
2
+ """Host-independent identity shared by plugmix plugin kinds."""
3
+
4
+ from typing import ClassVar
5
+
6
+
7
+ class Plugin:
8
+ """A named, discoverable plugin; subclasses define their own host contract."""
9
+
10
+ kind: ClassVar[str] = ""
11
+ name: ClassVar[str] = ""
12
+ title: ClassVar[str] = ""
13
+ since: ClassVar[str] = ""
14
+ requires: ClassVar[str] = ""
@@ -0,0 +1,4 @@
1
+ # this_file: src/fontlab_plugmix/plugins/__init__.py
2
+ """Built-in reporter plugins; registry discovers modules on demand."""
3
+
4
+ __all__: list[str] = [] # submodules are loaded by entry point, not re-exported
@@ -0,0 +1,30 @@
1
+ # this_file: src/fontlab_plugmix/plugins/anchor_cloud.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Show the current glyph's named anchors as a small local cloud."""
4
+
5
+ from fontlab_plugmix.reporter import Mark, Reporter
6
+ from fontlab_plugmix.snapshot import GlyphSnapshot
7
+
8
+
9
+ class AnchorCloud(Reporter):
10
+ """Annotate the current layer's anchor positions without font-wide reads."""
11
+
12
+ name = "anchor_cloud"
13
+ title = "Anchor Cloud"
14
+
15
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
16
+ """Return a dot and name for every current-layer anchor."""
17
+ marks = []
18
+ for anchor in snapshot.anchors:
19
+ marks.append(
20
+ Mark("ring", ((anchor.x, anchor.y),), (105, 145, 185), diameter_px=8)
21
+ )
22
+ marks.append(
23
+ Mark(
24
+ "text",
25
+ ((anchor.x + 6, anchor.y + 8),),
26
+ (105, 145, 185),
27
+ text=anchor.name,
28
+ )
29
+ )
30
+ return marks
@@ -0,0 +1,40 @@
1
+ # this_file: src/fontlab_plugmix/plugins/angled_handles.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Mark off-curve handles departing from horizontal, vertical or italic axes."""
4
+
5
+ from math import atan2, degrees
6
+
7
+ from fontlab_plugmix.geometry import neighbours
8
+ from fontlab_plugmix.reporter import Mark, Reporter
9
+ from fontlab_plugmix.snapshot import GlyphSnapshot
10
+
11
+
12
+ class AngledHandles(Reporter):
13
+ """Flag handles with an axis mismatch greater than a small angle."""
14
+
15
+ name = "angled_handles"
16
+ title = "Angled Handles"
17
+ tolerance_deg = 0.5
18
+
19
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
20
+ """Compare each handle with its adjacent on-curve endpoint."""
21
+ marks = []
22
+ for contour in snapshot.contours:
23
+ nodes = contour.nodes
24
+ for index, node in enumerate(nodes):
25
+ if node.on_curve or len(nodes) < 2:
26
+ continue
27
+ for adjacent in neighbours(contour, index):
28
+ if adjacent is None or not adjacent.on_curve:
29
+ continue
30
+ dx, dy = node.x - adjacent.x, node.y - adjacent.y
31
+ if dx == 0 and dy == 0:
32
+ break
33
+ if dy < 0:
34
+ dx, dy = -dx, -dy
35
+ angle = degrees(atan2(dx, dy))
36
+ axes = (0.0, 90.0, -90.0, snapshot.metrics.italic_slant)
37
+ if min(abs(angle - axis) for axis in axes) > self.tolerance_deg:
38
+ marks.append(Mark("ring", ((node.x, node.y),), (230, 120, 20)))
39
+ break
40
+ return marks
@@ -0,0 +1,28 @@
1
+ # this_file: src/fontlab_plugmix/plugins/center_lines.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Show advance and vertical-metric center guides."""
4
+
5
+ from fontlab_plugmix.reporter import Mark, Reporter
6
+ from fontlab_plugmix.snapshot import GlyphSnapshot
7
+
8
+
9
+ class CenterLines(Reporter):
10
+ """Draw requested font-wide center lines with no font modification."""
11
+
12
+ name = "center_lines"
13
+ title = "Center Lines"
14
+ layer = "background"
15
+
16
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
17
+ """Draw advance/2 and half x-height/cap-height guides."""
18
+ metrics, advance = snapshot.metrics, snapshot.advance
19
+ top, bottom = (
20
+ max(metrics.ascender, metrics.cap_height),
21
+ min(metrics.descender, 0),
22
+ )
23
+ marks = [
24
+ Mark("line", ((advance / 2, bottom), (advance / 2, top)), (95, 130, 190))
25
+ ]
26
+ for height in (metrics.x_height / 2, metrics.cap_height / 2):
27
+ marks.append(Mark("line", ((0, height), (advance, height)), (95, 130, 190)))
28
+ return marks
@@ -0,0 +1,39 @@
1
+ # this_file: src/fontlab_plugmix/plugins/crosshair.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Draw broad, thin crosshairs through selected nodes, without mouse tracking."""
4
+
5
+ from fontlab_plugmix.reporter import Mark, Reporter
6
+ from fontlab_plugmix.snapshot import GlyphSnapshot
7
+
8
+
9
+ class Crosshair(Reporter):
10
+ """Extend selected-node guides far beyond normal Glyph window extents."""
11
+
12
+ name = "crosshair"
13
+ title = "Crosshair"
14
+ layer = "background"
15
+ extent = 1_000_000.0
16
+
17
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
18
+ """Draw two guides per selected node."""
19
+ marks = []
20
+ for contour in snapshot.contours:
21
+ for node in contour.nodes:
22
+ if node.selected:
23
+ marks.extend(
24
+ (
25
+ Mark(
26
+ "line",
27
+ ((-self.extent, node.y), (self.extent, node.y)),
28
+ (140, 140, 140),
29
+ 0.75,
30
+ ),
31
+ Mark(
32
+ "line",
33
+ ((node.x, -self.extent), (node.x, self.extent)),
34
+ (140, 140, 140),
35
+ 0.75,
36
+ ),
37
+ )
38
+ )
39
+ return marks