@@ -56,14 +56,15 @@ type SimulatorScreenshotFlowDeps = {
5656 * actually taken. `sourcePixelDensity` is that image's own measured scale — the panel the host
5757 * named for a `simctl` capture, or what the runner reported for a runner capture. Undefined means
5858 * nobody measured the source: a single-panel `simctl` capture, or a multi-panel device whose
59- * display inventory never resolved, and the scale probe is the answer either way.
59+ * display inventory never resolved, and the scale probe is the answer either way. Resolves to
60+ * the source's scale when the file keeps its pixels (`native`), so a caller can map them to points.
6061 */
6162 normalizeDensity : (
6263 device : DeviceInfo ,
6364 outPath : string ,
6465 pixelDensity : number | 'native' | undefined ,
6566 sourcePixelDensity : number | undefined ,
66- ) => Promise < void > ;
67+ ) => Promise < number | undefined > ;
6768 captureWithRunner : (
6869 device : DeviceInfo ,
6970 outPath : string ,
@@ -149,10 +150,16 @@ export async function captureSimulatorScreenshotWithFallback(
149150 // A foldable lights one panel at a time, so the capture must name the panel the
150151 // system is currently showing rather than accept simctl's implicit default.
151152 const { display, displayRotation } = await deps . resolveCaptureTarget ( device ) ;
152- const captureFacts : ScreenshotCaptureFacts = displayRotation ? { displayRotation } : { } ;
153+ const captureFacts : { - readonly [ K in keyof ScreenshotCaptureFacts ] : ScreenshotCaptureFacts [ K ] } =
154+ displayRotation ? { displayRotation } : { } ;
155+ const noteDensity = ( sourcePixelDensity : number | undefined ) => {
156+ if ( sourcePixelDensity !== undefined ) captureFacts . sourcePixelDensity = sourcePixelDensity ;
157+ } ;
153158 const captureAndNormalize = async ( ) => {
154159 await deps . captureWithRetry ( device , outPath , display ) ;
155- await deps . normalizeDensity ( device , outPath , options . pixelDensity , display ?. pointScale ) ;
160+ noteDensity (
161+ await deps . normalizeDensity ( device , outPath , options . pixelDensity , display ?. pointScale ) ,
162+ ) ;
156163 } ;
157164 let restoreStatusBar = async ( ) => { } ;
158165 if ( options . normalizeStatusBar === true ) {
@@ -197,7 +204,9 @@ export async function captureSimulatorScreenshotWithFallback(
197204 // that image at, so normalization reads the source instead of applying a panel the host guessed.
198205 // A runner that reports nothing measured nothing: the probe stays the pre-panel answer rather
199206 // than borrowing a scale from a panel nobody captured (#2728).
200- await deps . normalizeDensity ( device , outPath , options . pixelDensity , captured ?. pixelsPerPoint ) ;
207+ noteDensity (
208+ await deps . normalizeDensity ( device , outPath , options . pixelDensity , captured ?. pixelsPerPoint ) ,
209+ ) ;
201210 return captureFacts ;
202211 } finally {
203212 await restoreStatusBar ( ) . catch ( ( error ) =>
@@ -470,20 +479,21 @@ async function normalizeIosSimulatorScreenshotDensity(
470479 outPath : string ,
471480 pixelDensity : number | 'native' | undefined ,
472481 sourcePixelDensity ?: number ,
473- ) : Promise < void > {
474- if ( pixelDensity === 'native' ) return ;
482+ ) : Promise < number | undefined > {
475483 // Both the captured panel's `pointScale` and the runner's reported scale describe the image that
476484 // was actually taken. `SIMULATOR_MAINSCREEN_SCALE` describes one fixed panel, so on a foldable it
477485 // can disagree with the panel that was captured, and it is only ever consulted when nothing
478486 // measured the source — which a multi-panel capture and every runner capture do.
479487 const measuredSourcePixelDensity =
480488 sourcePixelDensity ?? ( await readIosSimulatorMainScreenScale ( device ) ) ;
489+ if ( pixelDensity === 'native' ) return measuredSourcePixelDensity ;
481490 const targetSize = computeDensityScaledScreenshotSize (
482491 await readPngSize ( outPath ) ,
483492 measuredSourcePixelDensity ,
484493 pixelDensity ,
485494 ) ;
486495 if ( targetSize ) await resizePngFile ( outPath , targetSize . width , targetSize . height ) ;
496+ return undefined ;
487497}
488498
489499async function readIosSimulatorMainScreenScale ( device : DeviceInfo ) : Promise < number > {
0 commit comments