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,50 @@
1
+ # this_file: src/fontlab_plugmix/plugins/duplicate_anchors.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Show one red and yellow ring pair for every anchor pair under one unit."""
4
+
5
+ from math import hypot
6
+
7
+ from fontlab_plugmix.reporter import Mark, Reporter
8
+ from fontlab_plugmix.snapshot import GlyphSnapshot
9
+
10
+
11
+ class DuplicateAnchors(Reporter):
12
+ """Three coincident anchors produce three ring pairs at first anchors."""
13
+
14
+ name = "duplicate_anchors"
15
+ title = "Duplicate Anchor Rings"
16
+ handle_size = 8
17
+
18
+ @classmethod
19
+ def set_handle_size(cls, size: int) -> None:
20
+ """Choose the old launcher's 5, 8 or 12 pixel handle size."""
21
+ if size not in (5, 8, 12):
22
+ raise ValueError("Handle size must be 5, 8 or 12")
23
+ cls.handle_size = size
24
+
25
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
26
+ """Find all unordered pairs closer than one font unit."""
27
+ marks = []
28
+ for index, anchor in enumerate(snapshot.anchors):
29
+ for other in snapshot.anchors[index + 1 :]:
30
+ if hypot(anchor.x - other.x, anchor.y - other.y) < 1:
31
+ center = ((anchor.x, anchor.y),)
32
+ marks.extend(
33
+ (
34
+ Mark(
35
+ "ring",
36
+ center,
37
+ (255, 0, 0),
38
+ stroke_px=6,
39
+ diameter_px=2 * self.handle_size,
40
+ ),
41
+ Mark(
42
+ "ring",
43
+ center,
44
+ (255, 255, 0),
45
+ stroke_px=2,
46
+ diameter_px=2 * self.handle_size,
47
+ ),
48
+ )
49
+ )
50
+ return marks
@@ -0,0 +1,28 @@
1
+ # this_file: src/fontlab_plugmix/plugins/glyph_focus.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Dim the viewport outside the glyph advance and vertical metrics box."""
4
+
5
+ from fontlab_plugmix.reporter import Mark, Reporter
6
+ from fontlab_plugmix.snapshot import GlyphSnapshot
7
+
8
+
9
+ class GlyphFocus(Reporter):
10
+ """Leave the current glyph's advance box unobscured."""
11
+
12
+ name = "glyph_focus"
13
+ title = "Glyph Focus"
14
+ extent = 1_000_000.0
15
+ shade = (40, 40, 40, 70)
16
+
17
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
18
+ """Return four translucent rectangles around the advance box."""
19
+ e = self.extent
20
+ top, bottom = snapshot.metrics.ascender, snapshot.metrics.descender
21
+ advance = snapshot.advance
22
+ rectangles = (
23
+ ((-e, top), (e, top), (e, e), (-e, e)),
24
+ ((-e, -e), (e, -e), (e, bottom), (-e, bottom)),
25
+ ((-e, bottom), (0, bottom), (0, top), (-e, top)),
26
+ ((advance, bottom), (e, bottom), (e, top), (advance, top)),
27
+ )
28
+ return [Mark("polygon", points, fill=self.shade) for points in rectangles]
@@ -0,0 +1,44 @@
1
+ # this_file: src/fontlab_plugmix/plugins/imprecise_italic_angle.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Mark straight segments almost, but not exactly, at the master slant."""
4
+
5
+ from math import atan2, degrees
6
+
7
+ from fontlab_plugmix.geometry import segments
8
+ from fontlab_plugmix.reporter import Mark, Reporter
9
+ from fontlab_plugmix.snapshot import GlyphSnapshot
10
+
11
+
12
+ class ImpreciseItalicAngle(Reporter):
13
+ """Check each straight segment against the master's vertical slant."""
14
+
15
+ name = "imprecise_italic_angle"
16
+ title = "Imprecise Italic Angle"
17
+ tolerance_deg = 2.0
18
+ exact_deg = 0.001
19
+
20
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
21
+ """Highlight near-angle lines, ignoring horizontal and exact matches."""
22
+ marks = []
23
+ for contour in snapshot.contours:
24
+ for segment in segments(contour):
25
+ if len(segment) != 2:
26
+ continue
27
+ start, end = segment
28
+ dx, dy = end.x - start.x, end.y - start.y
29
+ if dy == 0:
30
+ continue
31
+ if dy < 0:
32
+ dx, dy = -dx, -dy
33
+ angle = degrees(atan2(dx, dy))
34
+ delta = abs(angle - snapshot.metrics.italic_slant)
35
+ if self.exact_deg < delta <= self.tolerance_deg:
36
+ marks.append(
37
+ Mark(
38
+ "line",
39
+ ((start.x, start.y), (end.x, end.y)),
40
+ (235, 75, 60),
41
+ 2.5,
42
+ )
43
+ )
44
+ return marks
@@ -0,0 +1,26 @@
1
+ # this_file: src/fontlab_plugmix/plugins/node_indexes.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Label every node with its full contour index, including off-curves.
4
+
5
+ Mekkablue's ShowNodeIndexes displays BCP indexes by default. FontLab's own
6
+ contour numbering also counts every node, so labels and numbers follow that
7
+ same full sequence without a separate BCP visibility setting.
8
+ """
9
+
10
+ from fontlab_plugmix.reporter import Mark, Reporter
11
+ from fontlab_plugmix.snapshot import GlyphSnapshot
12
+
13
+
14
+ class NodeIndexes(Reporter):
15
+ """Use original contour indexes at all node positions."""
16
+
17
+ name = "node_indexes"
18
+ title = "Node Indexes"
19
+
20
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
21
+ """Place an index beside each on- and off-curve node."""
22
+ return [
23
+ Mark("text", ((node.x + 5, node.y + 5),), (145, 88, 45), text=str(index))
24
+ for contour in snapshot.contours
25
+ for index, node in enumerate(contour.nodes)
26
+ ]
@@ -0,0 +1,35 @@
1
+ # this_file: src/fontlab_plugmix/plugins/nodes_close_to_zones.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Mark on-curves near, but not exactly on, master zones or metric levels."""
4
+
5
+ from fontlab_plugmix.reporter import Mark, Reporter
6
+ from fontlab_plugmix.snapshot import GlyphSnapshot
7
+
8
+
9
+ class NodesCloseToZones(Reporter):
10
+ """Find near misses against selected-master PostScript zones and metrics."""
11
+
12
+ name = "nodes_close_to_zones"
13
+ title = "Nodes Close to Zones"
14
+ tolerance = 5.0
15
+ needs_zones = True
16
+
17
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
18
+ """Ring each node with a nonzero y-distance at most the tolerance."""
19
+ metrics = snapshot.metrics
20
+ levels = {
21
+ 0.0,
22
+ metrics.ascender,
23
+ metrics.descender,
24
+ metrics.x_height,
25
+ metrics.cap_height,
26
+ }
27
+ for zone in metrics.zones:
28
+ levels.update((zone.position, zone.edge))
29
+ return [
30
+ Mark("ring", ((node.x, node.y),), (230, 120, 30), diameter_px=14)
31
+ for contour in snapshot.contours
32
+ for node in contour.nodes
33
+ if node.on_curve
34
+ and any(0 < abs(node.y - level) <= self.tolerance for level in levels)
35
+ ]
@@ -0,0 +1,31 @@
1
+ # this_file: src/fontlab_plugmix/plugins/offcurve_outside_bounds.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Highlight off-curve handles beyond the on-curve bounding rectangle.
4
+
5
+ Unlike mekkablue's ShowNodesOutsidePaths, this does not test path containment.
6
+ """
7
+
8
+ from fontlab_plugmix.reporter import Mark, Reporter
9
+ from fontlab_plugmix.snapshot import GlyphSnapshot
10
+
11
+
12
+ class OffcurveOutsideBounds(Reporter):
13
+ """Use on-curve extrema as the comparison bounds."""
14
+
15
+ name = "offcurve_outside_bounds"
16
+ title = "Off-curve Handles Outside Bounds"
17
+
18
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
19
+ """Mark only handles outside the on-curve rectangle."""
20
+ nodes = [node for contour in snapshot.contours for node in contour.nodes]
21
+ on = [node for node in nodes if node.on_curve]
22
+ if not on:
23
+ return []
24
+ x_min, x_max = min(n.x for n in on), max(n.x for n in on)
25
+ y_min, y_max = min(n.y for n in on), max(n.y for n in on)
26
+ return [
27
+ Mark("ring", ((n.x, n.y),), (30, 95, 220), stroke_px=2, diameter_px=13)
28
+ for n in nodes
29
+ if not n.on_curve
30
+ and (n.x < x_min or n.x > x_max or n.y < y_min or n.y > y_max)
31
+ ]
@@ -0,0 +1,38 @@
1
+ # this_file: src/fontlab_plugmix/plugins/only_selected_handles.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Emphasise handles of the selection over FontLab's native handle drawing."""
4
+
5
+ from fontlab_plugmix.geometry import neighbours
6
+ from fontlab_plugmix.reporter import Mark, Reporter
7
+ from fontlab_plugmix.snapshot import GlyphSnapshot, Node
8
+
9
+
10
+ def _marks(near: Node, handle: Node) -> list[Mark]:
11
+ """Accent one selected handle relationship."""
12
+ color = (55, 145, 220)
13
+ return [
14
+ Mark("line", ((near.x, near.y), (handle.x, handle.y)), color, 1.5),
15
+ Mark("ring", ((handle.x, handle.y),), color, diameter_px=11),
16
+ ]
17
+
18
+
19
+ class OnlySelectedHandles(Reporter):
20
+ """Connect selected endpoints to their neighbouring off-curves."""
21
+
22
+ name = "only_selected_handles"
23
+ title = "Emphasise Selected Handles"
24
+
25
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
26
+ """Overlay an accent line and ring for each relevant handle."""
27
+ marks = []
28
+ for contour in snapshot.contours:
29
+ nodes = contour.nodes
30
+ for index, handle in enumerate(nodes):
31
+ if handle.on_curve or len(nodes) < 2:
32
+ continue
33
+ for near in neighbours(contour, index):
34
+ if near is not None and near.on_curve:
35
+ if near.selected or handle.selected:
36
+ marks.extend(_marks(near, handle))
37
+ break
38
+ return marks
@@ -0,0 +1,39 @@
1
+ # this_file: src/fontlab_plugmix/plugins/rsb_line.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Show advance boundary and the on-curve left and right sidebearings."""
4
+
5
+ from fontlab_plugmix.reporter import Mark, Reporter
6
+ from fontlab_plugmix.snapshot import GlyphSnapshot
7
+
8
+
9
+ class RSBLine(Reporter):
10
+ """Annotate sidebearings from on-curve x extrema."""
11
+
12
+ name = "rsb_line"
13
+ title = "RSB Line"
14
+ layer = "background"
15
+ needs_bounds = True
16
+
17
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
18
+ """Draw the advance boundary and label both sidebearings."""
19
+ if snapshot.bounds is None:
20
+ on = [
21
+ n for contour in snapshot.contours for n in contour.nodes if n.on_curve
22
+ ]
23
+ if not on:
24
+ return []
25
+ left, right = min(n.x for n in on), max(n.x for n in on)
26
+ else:
27
+ left, _bottom, right, _top = snapshot.bounds
28
+ bottom, top = snapshot.metrics.descender, snapshot.metrics.ascender
29
+ color = (80, 145, 190)
30
+ return [
31
+ Mark("line", ((snapshot.advance, bottom), (snapshot.advance, top)), color),
32
+ Mark(
33
+ "text",
34
+ ((snapshot.advance + 7, 0),),
35
+ color,
36
+ text=f"RSB {snapshot.advance - right:g}",
37
+ ),
38
+ Mark("text", ((0, 0),), color, text=f"LSB {left:g}"),
39
+ ]
@@ -0,0 +1,36 @@
1
+ # this_file: src/fontlab_plugmix/plugins/segment_length.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Label straight and flattened Bézier lengths for selected or all segments."""
4
+
5
+ from fontlab_plugmix.geometry import length, point_at, segments
6
+ from fontlab_plugmix.reporter import Mark, Reporter
7
+ from fontlab_plugmix.snapshot import GlyphSnapshot
8
+
9
+
10
+ class SegmentLength(Reporter):
11
+ """Prefer segments with both on-curve ends selected; otherwise show all."""
12
+
13
+ name = "segment_length"
14
+ title = "Segment Length"
15
+ flatten_steps = 25
16
+
17
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
18
+ """Measure each eligible contour segment in font units."""
19
+ rows = [
20
+ segment for contour in snapshot.contours for segment in segments(contour)
21
+ ]
22
+ selected = any(
23
+ node.selected for contour in snapshot.contours for node in contour.nodes
24
+ )
25
+ chosen = [
26
+ segment for segment in rows if segment[0].selected and segment[-1].selected
27
+ ]
28
+ return [
29
+ Mark(
30
+ "text",
31
+ (point_at(segment, 0.5),),
32
+ (195, 45, 45),
33
+ text=f"{length(segment, self.flatten_steps):.1f}",
34
+ )
35
+ for segment in (chosen if selected else rows)
36
+ ]
@@ -0,0 +1,27 @@
1
+ # this_file: src/fontlab_plugmix/plugins/selected_coordinates.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Show x and y beside selected native nodes."""
4
+
5
+ from fontlab_plugmix.reporter import Mark, Reporter
6
+ from fontlab_plugmix.snapshot import GlyphSnapshot
7
+
8
+
9
+ class SelectedCoordinates(Reporter):
10
+ """Display coordinates for every selected node, including handles."""
11
+
12
+ name = "selected_coordinates"
13
+ title = "Selected Node Coordinates"
14
+
15
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
16
+ """Return compact coordinate labels at selected nodes."""
17
+ return [
18
+ Mark(
19
+ "text",
20
+ ((node.x + 6, node.y - 6),),
21
+ (30, 105, 190),
22
+ text=f"{node.x:g}, {node.y:g}",
23
+ )
24
+ for contour in snapshot.contours
25
+ for node in contour.nodes
26
+ if node.selected
27
+ ]
@@ -0,0 +1,51 @@
1
+ # this_file: src/fontlab_plugmix/plugins/smooth_node_angles.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Label smooth-node handle kinks and incoming/outgoing length proportion."""
4
+
5
+ from math import acos, degrees, hypot
6
+
7
+ from fontlab_plugmix.geometry import neighbours
8
+ from fontlab_plugmix.reporter import Mark, Reporter
9
+ from fontlab_plugmix.snapshot import GlyphSnapshot, Node
10
+
11
+
12
+ def _label(node: Node, before: Node, after: Node) -> str | None:
13
+ """Return the angular mismatch and handle-length ratio for one node."""
14
+ ax, ay = before.x - node.x, before.y - node.y
15
+ bx, by = after.x - node.x, after.y - node.y
16
+ a, b = hypot(ax, ay), hypot(bx, by)
17
+ if not a or not b:
18
+ return None
19
+ cosine = max(-1.0, min(1.0, (ax * bx + ay * by) / (a * b)))
20
+ kink = 180.0 - degrees(acos(cosine))
21
+ return f"{kink:.1f}° · {a / b:.2f}"
22
+
23
+
24
+ class SmoothNodeAngles(Reporter):
25
+ """Show local smoothness and proportion for nodes with two handles."""
26
+
27
+ name = "smooth_node_angles"
28
+ title = "Smooth Node Angles"
29
+
30
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
31
+ """Label each smooth on-curve flanked by off-curve handles."""
32
+ marks = []
33
+ for contour in snapshot.contours:
34
+ nodes = contour.nodes
35
+ for index, node in enumerate(nodes):
36
+ if not node.on_curve or not node.smooth or len(nodes) < 3:
37
+ continue
38
+ before, after = neighbours(contour, index)
39
+ if before is None or after is None or before.on_curve or after.on_curve:
40
+ continue
41
+ label = _label(node, before, after)
42
+ if label is not None:
43
+ marks.append(
44
+ Mark(
45
+ "text",
46
+ ((node.x + 8, node.y + 8),),
47
+ (180, 65, 150),
48
+ text=label,
49
+ )
50
+ )
51
+ return marks
@@ -0,0 +1,34 @@
1
+ # this_file: src/fontlab_plugmix/plugins/tops_and_bottoms.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Label the highest and lowest on-curve positions in the active glyph."""
4
+
5
+ from fontlab_plugmix.reporter import Mark, Reporter
6
+ from fontlab_plugmix.snapshot import GlyphSnapshot
7
+
8
+
9
+ class TopsAndBottoms(Reporter):
10
+ """Show all tied extrema, preserving their exact y values."""
11
+
12
+ name = "tops_and_bottoms"
13
+ title = "Tops and Bottoms"
14
+ layer = "background"
15
+
16
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
17
+ """Place a ring and numeric label at each top or bottom on-curve."""
18
+ on = [n for contour in snapshot.contours for n in contour.nodes if n.on_curve]
19
+ if not on:
20
+ return []
21
+ levels = {min(n.y for n in on), max(n.y for n in on)}
22
+ marks = []
23
+ for node in on:
24
+ if node.y in levels:
25
+ marks.append(Mark("ring", ((node.x, node.y),), (190, 65, 65)))
26
+ marks.append(
27
+ Mark(
28
+ "text",
29
+ ((node.x + 6, node.y + 8),),
30
+ (190, 65, 65),
31
+ text=f"{node.y:g}",
32
+ )
33
+ )
34
+ return marks
@@ -0,0 +1,38 @@
1
+ # this_file: src/fontlab_plugmix/plugins/two_point_distance.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Show a segment, distance and angle when exactly two nodes are selected."""
4
+
5
+ from math import atan2, degrees, hypot
6
+
7
+ from fontlab_plugmix.reporter import Mark, Reporter
8
+ from fontlab_plugmix.snapshot import GlyphSnapshot
9
+
10
+
11
+ class TwoPointDistance(Reporter):
12
+ """Measure both on-curve and off-curve selected points."""
13
+
14
+ name = "two_point_distance"
15
+ title = "Two Point Distance"
16
+
17
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
18
+ """Show a line and its length/angle only for a two-node selection."""
19
+ nodes = [
20
+ node
21
+ for contour in snapshot.contours
22
+ for node in contour.nodes
23
+ if node.selected
24
+ ]
25
+ if len(nodes) != 2:
26
+ return []
27
+ first, last = nodes
28
+ dx, dy = last.x - first.x, last.y - first.y
29
+ midpoint = ((first.x + last.x) / 2, (first.y + last.y) / 2)
30
+ return [
31
+ Mark("line", ((first.x, first.y), (last.x, last.y)), (85, 115, 210)),
32
+ Mark(
33
+ "text",
34
+ (midpoint,),
35
+ (85, 115, 210),
36
+ text=f"{hypot(dx, dy):.1f} · {degrees(atan2(dy, dx)):.1f}°",
37
+ ),
38
+ ]
@@ -0,0 +1,35 @@
1
+ # this_file: src/fontlab_plugmix/plugins/unitizer.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Draw a configurable vertical unit grid across the glyph advance."""
4
+
5
+ from fontlab_plugmix.reporter import Mark, Reporter
6
+ from fontlab_plugmix.snapshot import GlyphSnapshot
7
+
8
+
9
+ class Unitizer(Reporter):
10
+ """Display simple unit increments behind the active glyph."""
11
+
12
+ name = "unitizer"
13
+ title = "Unitizer"
14
+ layer = "background"
15
+ units_per_em = 18
16
+ max_lines = 2_000
17
+
18
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
19
+ """Generate bounded grid lines from one increment to the advance."""
20
+ if self.units_per_em <= 0 or snapshot.metrics.upm <= 0:
21
+ return []
22
+ step = snapshot.metrics.upm / self.units_per_em
23
+ count = min(int(snapshot.advance // step), self.max_lines)
24
+ return [
25
+ Mark(
26
+ "line",
27
+ (
28
+ (index * step, snapshot.metrics.descender),
29
+ (index * step, snapshot.metrics.ascender),
30
+ ),
31
+ (180, 180, 180),
32
+ 0.75,
33
+ )
34
+ for index in range(1, count + 1)
35
+ ]
@@ -0,0 +1,39 @@
1
+ # this_file: src/fontlab_plugmix/plugins/vertical_metrics.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Show the five principal horizontal metric lines with labels."""
4
+
5
+ from fontlab_plugmix.reporter import Mark, Reporter
6
+ from fontlab_plugmix.snapshot import GlyphSnapshot
7
+
8
+
9
+ class VerticalMetrics(Reporter):
10
+ """Annotate ascender, descender, x-height, cap height and baseline."""
11
+
12
+ name = "vertical_metrics"
13
+ title = "Vertical Metrics"
14
+ layer = "background"
15
+
16
+ def compute(self, snapshot: GlyphSnapshot) -> list[Mark]:
17
+ """Return one line and one label per named metric."""
18
+ m = snapshot.metrics
19
+ levels = (
20
+ ("Ascender", m.ascender),
21
+ ("Descender", m.descender),
22
+ ("x-height", m.x_height),
23
+ ("Cap height", m.cap_height),
24
+ ("Baseline", 0.0),
25
+ )
26
+ marks = []
27
+ for label, height in levels:
28
+ marks.append(
29
+ Mark("line", ((0, height), (snapshot.advance, height)), (95, 130, 190))
30
+ )
31
+ marks.append(
32
+ Mark(
33
+ "text",
34
+ ((snapshot.advance + 8, height),),
35
+ (95, 130, 190),
36
+ text=f"{label} {height:g}",
37
+ )
38
+ )
39
+ return marks