From 941c6e45cc5b4d567c09636fb90fb5cbcd3b832e Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sun, 13 Sep 2026 21:03:14 +0200 Subject: [PATCH] viewer: ring labels in plain type at one screen size, and a cell that holds still The cased white label read as an outline artefact, and its scene-space font - scaled by 1/zoom to hold an apparent size - broke down at high magnification, where a sub-point font rasterises into a white block. The label is now drawn in device coordinates (ItemIgnoresTransformations) at 1.6x the application font, bold, with no outline, so it is the same size at every zoom by construction. The colour is picked from what ends up under it: near-black normally - the label usually sits outside the detector image, on the canvas that is white under every colour map - and white only over the image of a dark map. Not the ring's magenta: where the label meets its own dashes the two blend and the glyphs dissolve. The unit-cell rows pad every number to three integer digits with figure spaces, so 95.0 and 102.3 occupy the same width and the columns do not shift as values change magnitude; no axis reaches 1000 A and no angle 1000 degrees. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_015vRwzF8PLaaa2novAKYorq --- docs/CHANGELOG.md | 2 +- .../image_viewer/JFJochDiffractionImage.cpp | 37 +++++++++++++------ .../widgets/JFJochViewerImageStatistics.cpp | 7 +++- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index f83a6e968..617306829 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,7 +8,7 @@ * The viewer draws its spot markers over a black outline, so they stay visible on a light colour map and are no longer mistaken for a magenta bad pixel or the coral beam stop. * The viewer has a background (black-point) slider beside the foreground one; hold B and scroll the wheel to adjust it. * The viewer's keyboard shortcuts - F, B, A, Home/End/PageUp/PageDown - work whichever panel has the focus, not only with the image focused. -* The viewer's resolution-ring labels follow the font size, are cased like the spot markers so they read on any colour map, and stay whole inside the view instead of clipping at its edge. +* The viewer's resolution-ring labels keep one on-screen size that follows the font setting, print dark on a light colour map and white on a dark one, and stay whole inside the view instead of clipping at its edge. * The viewer's dataset plots put the rotation-angle ticks on round angles - multiples of 90 degrees when the sweep is wide enough. * The viewer's inspector prints the indexed cell as two aligned rows, mosaicity with two decimals, and "No lattice" in grey rather than alarm red. * The viewer's armed "Analyze image" button is marked by a coral outline, instead of turning into a differently-coloured button. diff --git a/viewer/image_viewer/JFJochDiffractionImage.cpp b/viewer/image_viewer/JFJochDiffractionImage.cpp index 4285bcfb3..e1d995dd7 100644 --- a/viewer/image_viewer/JFJochDiffractionImage.cpp +++ b/viewer/image_viewer/JFJochDiffractionImage.cpp @@ -362,23 +362,28 @@ void JFJochDiffractionImage::DrawResolutionRings() { for (const auto &[d, path]: ring_cache_) { addOverlayItem(scene()->addPath(path, pen)); - // The "d Å" label follows the application font (View -> Font size) and is white cased in - // black, like the spot markers, so it reads on any colour map and on the ring's own - // colour. The item lives in scene coordinates, so dividing by the view scale keeps it a - // constant size on screen - 1.2x the application font at every zoom. It is centred on the - // first sampled azimuth (staggered per ring) where the whole text fits in the viewport; - // failing that, on the visible ring point closest to the viewport centre, clamped inside - - // never half a label off the edge. + // The "d Å" label is drawn in device coordinates (ItemIgnoresTransformations), so it + // keeps a constant on-screen size - the application font, a step up and bold - at every + // zoom; shrinking a scene-space font by 1/zoom instead breaks glyph rendering once the + // point size drops below one. No outline; the colour is picked from what ends up under + // the label, white only over the image of a dark colour map. It is centred on the first + // sampled azimuth (staggered per ring) where the whole text fits in the viewport; + // failing that, on the visible ring point closest to the viewport centre, clamped + // inside - never half a label off the edge. QFont font = this->font(); - const qreal f = std::clamp(scale_factor, 0.05, 500.0); - font.setPointSizeF(font.pointSizeF() * 1.2 / f); + font.setPointSizeF(font.pointSizeF() * 1.6); + font.setBold(true); auto *textItem = new QGraphicsSimpleTextItem( QString("%1 Å").arg(QString::number(d, 'f', 2))); textItem->setFont(font); - textItem->setBrush(Qt::white); - textItem->setPen(QPen(Qt::black, font.pointSizeF() / 8.0)); - const QSizeF sz = textItem->boundingRect().size(); + textItem->setFlag(QGraphicsItem::ItemIgnoresTransformations); + textItem->setPen(Qt::NoPen); // brush is chosen below, from what ends up under the label + // Device-size text: convert to scene units for the placement math below. + const qreal sx = std::max(1e-6, transform().m11()); + const qreal sy = std::max(1e-6, transform().m22()); + const QSizeF dev = textItem->boundingRect().size(); + const QSizeF sz(dev.width() / sx, dev.height() / sy); QRectF inner = visibleRect.adjusted(sz.height() * 0.3, sz.height() * 0.3, -sz.height() * 0.3, -sz.height() * 0.3); @@ -420,6 +425,14 @@ void JFJochDiffractionImage::DrawResolutionRings() { if (r.top() < inner.top()) r.moveTop(inner.top()); if (r.bottom() > inner.bottom()) r.moveBottom(inner.bottom()); } + // The label prints dark unless it lands on the image with a dark colour map: off the + // image the canvas is white whatever the map, and on its own magenta dashes either + // colour separates where the ring colour would blend. + const auto map_zero = color_scale.Apply(0.0f); + const double zero_luminance = 0.2126 * map_zero.r + 0.7152 * map_zero.g + 0.0722 * map_zero.b; + const bool dark_under = zero_luminance <= 127.0 + && QRectF(0, 0, static_cast(W), static_cast(H)).contains(r.center()); + textItem->setBrush(dark_under ? QColor(Qt::white) : QColor(0x20, 0x20, 0x20)); textItem->setPos(r.topLeft()); scene()->addItem(textItem); addOverlayItem(textItem); diff --git a/viewer/widgets/JFJochViewerImageStatistics.cpp b/viewer/widgets/JFJochViewerImageStatistics.cpp index 1eab6d29a..c7e32d964 100644 --- a/viewer/widgets/JFJochViewerImageStatistics.cpp +++ b/viewer/widgets/JFJochViewerImageStatistics.cpp @@ -12,8 +12,13 @@ static QString mkUnitCell(const UnitCell &uc, const char *color = nullptr) { const QString style = color ? QString(" style=\"color: %1;\"").arg(color) : QString(); auto num = [&style](double v) { + // Padded to three integer digits with figure spaces (digit-wide), so the columns hold + // still as values change magnitude; no axis reaches 1000 Å and no angle 1000°. + QString s = QString::number(v, 'f', 1); + while (s.size() < 5) + s.prepend(QChar(0x2007)); return QString("%2  ") - .arg(style).arg(QString::number(v, 'f', 1)); + .arg(style).arg(s); }; auto unit = [&style](const char *u) { return QString("%2").arg(style).arg(u);