Skip to content

PERF: Measure the pole figure label width on a 1x1 canvas - #71

Closed
imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:topic/compositor_measure_text_canvas
Closed

imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:topic/compositor_measure_text_canvas

Conversation

@imikejackson

Copy link
Copy Markdown
Collaborator

Summary

PoleFigureCompositor::computeLayoutMetrics measures the width of the letter X to calculate the composite layout. It measured the letter on a canvas as large as one pole figure (imageDim x imageDim). A canvas allocates 16 bytes for each pixel, so at imageDim 8000 this temporary canvas used about 1 GB for each composite. The measured width depends only on the font and the font size, so the function now uses a 1x1 canvas. The layout metrics do not change. DiscretePoleFigureCompositor uses the same function and gets the same change. 2 files changed, +20 / −2 lines.

1. Text measurement

  • Source/EbsdLib/Utilities/PoleFigureCompositor.cpp — 1x1 measurement canvas.

canvas_ity::canvas::measure_text adds the advance widths of the glyphs and multiplies the sum by the font scale. set_font sets that scale to the font size divided by the units per em of the font. Neither function reads the canvas size. All other canvas_ity::canvas objects in Source/ are drawn on, so they keep their sizes.

2. Test

  • Source/Test/PoleFigureCompositorTest.cpp — LayoutMetrics_FontAdvanceOracle.

The test checks subCanvasWidth (145.432), pageWidth (580) and pageHeight (176) at imageDim 128 with the Horizontal layout. The expected values come from the embedded Lato Bold font tables: the X advance is 1358 and the units per em is 2000, so the X width at font size 8 is 5.432. The test fails when the measured width changes. It cannot detect the size of the measurement canvas, because the result is the same for every canvas size.

Companion pull request: BlueQuartzSoftware/simplnx#1965 makes the same change in the Write Pole Figure preflight. The two pull requests do not depend on each other.

Test plan

  • LayoutMetrics_FontAdvanceOracle passes, and fails when 1 px is added to the measured width.
  • macOS Release: the full EbsdLib test suite passes (430/430).
  • CI passes on Windows, Linux and macOS.

Related Issue

  • This PR has no related issue

PoleFigureCompositor::computeLayoutMetrics measured the letter X on a
canvas as large as one pole figure. At imageDim 8000 this canvas used
about 1 GB for each composite. The measured width depends only on the
font and the font size, so the function now uses a 1x1 canvas. The
layout metrics do not change.

Add a test that checks the layout metrics at imageDim 128 against the
X advance width read from the Lato Bold font tables.

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
@imikejackson

Copy link
Copy Markdown
Collaborator Author

Closed in favor of #86, which merges this branch (with its history) together with the other open EbsdLib fixes for the next release, so simplnx can build against one EbsdLib branch. The branch is kept.

🤖 Generated with Claude Code

@imikejackson
imikejackson deleted the topic/compositor_measure_text_canvas branch November 13, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant