strokeWidthFor method

  1. @visibleForTesting
double strokeWidthFor(
  1. double width
)

Stroke width to paint, never thinner than one device pixel.

Skia paints a stroke narrower than a pixel as a one-pixel line with its alpha scaled down by the sub-pixel width, rather than as a true sub-pixel band. Faithful to Skia, but not to the page: CAD and schematic producers emit 0.06 pt / 0.12 pt lines meaning "hairline", and those came out at ~6% and ~12% opacity - the pale, washed-out linework this floor fixes. Reference viewers paint them as solid one-pixel lines.

A width of 0 arrives here unchanged from the interpreter and is floored the same way, which is PDF 32000-1 8.4.3.2's "thinnest line that can be rendered at device resolution: 1 device pixel" - and, unlike the old user-space resolution, it stays one pixel at every zoom.

Every stroke goes through this, text included: an outlined glyph (rendering modes 1/2/5/6) is linework, and a 0 w stroked run used to read as blank paper for exactly the reason above (#912).

Implementation

@visibleForTesting
double strokeWidthFor(double width) {
  if (pixelRatio <= 0) return width;
  // 0 is Skia's hairline: exactly one device pixel at *any* canvas
  // transform, at full alpha. That matters because a recorded picture is
  // replayed at several ratios (base raster, deep-zoom detail patch,
  // retained scene), so a page-space floor baked at record time would be
  // right for one of them and too thick for the rest. A hairline is correct
  // for all of them.
  return width * pixelRatio < 1 ? 0 : width;
}