Commit 4ae02979 by PLN (Algolia)

midiviz: the wordmark lives inside the D1 cell, at the cell's margin

PLN: 'stuck to left wall, should fit in d1 cell so have same margin as
cell'. The fit is honest: probe core-only ink (the glow inflated the
measurement), shrink the type to the span — never squash, never clip —
crop to true ink, clamp to the cell's outer rect. Glow trimmed another
notch: 'less blurry still neon but somewhat less'.
parent fda0a9aa
...@@ -1743,7 +1743,7 @@ def build_widget(port_label: str, reader: "Reader | None", scale: float = 1.0, ...@@ -1743,7 +1743,7 @@ def build_widget(port_label: str, reader: "Reader | None", scale: float = 1.0,
self._word_font, self._word_font_key = f, key self._word_font, self._word_font_key = f, key
return f return f
def _draw_word_layer(self, qp, base, pad, f, fm, pen): def _draw_word_layer(self, qp, base, pad, fm, pen):
"""One pass of the word: glyphs drawn one by one with the tracked """One pass of the word: glyphs drawn one by one with the tracked
advance, so the letter spacing is OURS and identical under the advance, so the letter spacing is OURS and identical under the
glow rings and the core.""" glow rings and the core."""
...@@ -1777,81 +1777,104 @@ def build_widget(port_label: str, reader: "Reader | None", scale: float = 1.0, ...@@ -1777,81 +1777,104 @@ def build_widget(port_label: str, reader: "Reader | None", scale: float = 1.0,
def _word_pixmap(self, span_w: float, span_h: float): def _word_pixmap(self, span_w: float, span_h: float):
"""The wordmark BAKED — glyphs, tracking and neon glow rendered """The wordmark BAKED — glyphs, tracking and neon glow rendered
once per geometry, not per frame. PLN's verdicts are all in here: once per geometry, not per frame. PLN's verdicts are all in here:
the glow is TIGHT ("a little less blurry? esp made fullscreen"), the glow is TIGHT ("too blurry"), the type is ExtraBold-800
the type is ExtraBold-800 ("too light"), and the bake measures ("too light"), the bake measures its own ink and crops ("i see
its own ink and crops to it ("i see PARVAGU how come missing end PARVAGU"), and it must FIT the D1 cell at the cell's margin —
of letters"). Any width overrun is taken by a vector condense at which means the TYPE shrinks to the width, honestly, rather than
draw time — never raster scaling, so fullscreen rebakes stay a squash that would make the letters strangers to themselves."""
sharp."""
key = (round(span_w), round(span_h)) key = (round(span_w), round(span_h))
if self._word_pm_key == key: if self._word_pm_key == key:
return self._word_pm return self._word_pm
f = self._wave_font(span_w, span_h) f = self._wave_font(span_w, span_h)
if f is None: if f is None:
return None return None
fm = QtGui.QFontMetricsF(f)
pad = max(2, int(f.pixelSize() * 0.25)) def bake(px, canvas_w, glow=True):
# PROBE: draw once, generously, and ask the pixels how wide the fb = QtGui.QFont(f)
# word really is. Metrics-driven sizing cut the tail; ink does not. fb.setPixelSize(max(4, px))
probe_w = span_w * 3 fmb = QtGui.QFontMetricsF(fb)
probe = QtGui.QImage(probe_w, round(span_h) + pad * 2, pad_b = max(2, int(px * 0.25))
QtGui.QImage.Format.Format_ARGB32_Premultiplied) img = QtGui.QImage(round(canvas_w), round(span_h) + pad_b * 2,
probe.fill(0)
qp = QtGui.QPainter(probe)
try:
qp.setRenderHint(QtGui.QPainter.RenderHint.TextAntialiasing,
True)
qp.setFont(f)
base = pad + (span_h + fm.ascent() - fm.descent()) / 2.0
self._draw_word_layer(qp, base, pad, f, fm,
QtGui.QPen(QtGui.QColor("#d900ff")))
finally:
qp.end()
ink = self._word_ink_width(probe)
sx = min(1.0, span_w / max(1.0, ink - pad))
img = QtGui.QImage(round((ink) * sx) + pad * 2,
round(span_h) + pad * 2,
QtGui.QImage.Format.Format_ARGB32_Premultiplied) QtGui.QImage.Format.Format_ARGB32_Premultiplied)
img.fill(0) img.fill(0)
qp = QtGui.QPainter(img) qp = QtGui.QPainter(img)
try: try:
qp.setRenderHint(QtGui.QPainter.RenderHint.TextAntialiasing, qp.setRenderHint(
True) QtGui.QPainter.RenderHint.TextAntialiasing, True)
qp.setFont(f) qp.setFont(fb)
qp.scale(sx, 1.0) base = pad_b + (span_h + fmb.ascent() - fmb.descent()) / 2.0
base = pad + (span_h + fm.ascent() - fm.descent()) / 2.0 if glow:
# the glow: two CLOSE rings, faint — a rim of neon, not a fog # the glow: two CLOSE rings, faint — rim of neon, not fog
r0 = max(1.0, f.pixelSize() * 0.09) r0 = max(1.0, px * 0.07)
for rad, alpha in ((r0, 40), (r0 * 0.45, 60)): for rad, alpha in ((r0, 24), (r0 * 0.5, 38)):
glow = QtGui.QPen(QtGui.QColor(217, 0, 255, alpha)) glow_pen = QtGui.QPen(QtGui.QColor(217, 0, 255, alpha))
glow.setWidthF(max(1.5, f.pixelSize() * 0.07)) glow_pen.setWidthF(max(1.2, px * 0.06))
for i in range(10): for i in range(10):
a = 2 * math.pi * i / 10 a = 2 * math.pi * i / 10
qp.save() qp.save()
qp.translate(math.cos(a) * rad, math.sin(a) * rad) qp.translate(math.cos(a) * rad, math.sin(a) * rad)
self._draw_word_layer(qp, base, pad, f, fm, glow) self._draw_word_layer(qp, base, pad_b, fmb, glow_pen)
qp.restore() qp.restore()
# the core: --neon-high itself, the site's own pink # the core: --neon-high itself, the site's own pink
self._draw_word_layer(qp, base, pad, f, fm, self._draw_word_layer(qp, base, pad_b, fmb,
QtGui.QPen(QtGui.QColor("#d900ff"))) QtGui.QPen(QtGui.QColor("#d900ff")))
finally: finally:
qp.end() qp.end()
pm = QtGui.QPixmap.fromImage(img) return img, pad_b
# PASS 1 — probe CORE-ONLY (the glow's ink would inflate the
# measurement and the fit would undershoot), on a canvas the word
# can never outrun: the D1-span cut came from a probe narrower
# than the word, where the ink scan believed the clip was the edge.
px = max(6.0, span_h * 0.92)
probe, pad1 = bake(px, int(px * 12), glow=False)
ink = self._word_ink_width(probe)
word_w = ink - 2 * pad1
# PASS 2 — if the word outruns the span, shrink the TYPE to fit;
# never squash it, never clip it.
if word_w > span_w:
fit = max(8.0, span_w * 0.94)
px = max(4.0, px * fit / word_w)
img, pad = bake(px, span_w + int(px * 2))
else:
img, pad = bake(px, word_w + pad * 2)
# crop to the true ink so the margins are the cell's, no more
left = 0
w_ = img.width()
while left < w_ and not self._col_has_ink(img, left):
left += 1
right = w_ - 1
while right > left and not self._col_has_ink(img, right):
right -= 1
cropped = img.copy(max(0, left - pad // 2), 0,
min(w_, right - left + 1 + pad),
img.height())
pm = QtGui.QPixmap.fromImage(cropped)
self._word_pm, self._word_pm_key = pm, key self._word_pm, self._word_pm_key = pm, key
return pm return pm
def _col_has_ink(self, img, x):
return any(img.pixelColor(x, y).alpha() > 8
for y in range(img.height()))
def _paint_word(self, p): def _paint_word(self, p):
"""PARVAGUES over D1-D3 — PLN: "bolted to D1-D3 even better as """PARVAGUES inside the D1 cell, with the cell's own margin —
over the djfs :D" — in the site's own display face.""" PLN, 2026-09-24: "appears stuck to left wall, should fit in d1
span_w, span_h = 3 * self.cw, self.ch cell so have same margin as cell". The span is the cell's inner
rectangle, not three columns."""
span_w, span_h = max(20.0, self.cw - self.inset), max(8.0, self.ch - self.inset)
pm = self._word_pixmap(span_w, span_h) pm = self._word_pixmap(span_w, span_h)
if pm is None: if pm is None:
return return
row_y = self.my + 3 * self.ch # PHYSICAL_ORDER index of D row_y = self.my + 3 * self.ch # PHYSICAL_ORDER index of D
p.setOpacity(WORD_ALPHA) p.setOpacity(WORD_ALPHA)
try: try:
p.drawPixmap(round(self.mx + (span_w - pm.width()) / 2.0), # clamped to the cell's outer rect: at the smallest windows
round(row_y + (span_h - pm.height()) / 2.0), pm) # the glow ring can reach 1px past the inner margin, and a
# 1px lean beats 1px of overlap
p.drawPixmap(max(round(self.mx),
round(self.mx + (self.cw - pm.width()) / 2.0)),
round(row_y + (self.ch - pm.height()) / 2.0), pm)
finally: finally:
p.setOpacity(1.0) p.setOpacity(1.0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment