Table of Contents

Enum ImageFit

Namespace
DocWright.Core.Imaging
Assembly
DocWright.Core.dll

How a rasterized page is fitted into a requested output size.

public enum ImageFit

Fields

Contain = 0

Scale uniformly so the whole page fits inside the requested size. The default.

The output is the scaled page, not the requested box: a portrait page fitted into a square is a portrait image, not a square one with bars down the sides. Nothing is cropped and nothing is distorted, and the constraining axis lands on its requested value exactly.

Cover = 1

Scale uniformly so the page covers the requested size, then centre-crop the overflow.

The output is exactly the requested size. Both a width and a height are required, because "cover" is meaningless against a single unconstrained axis. Cropping happens after rasterization on whole-pixel boundaries, so no pixel is resampled.

Exact = 2

Scale each axis independently so the page fills the requested size exactly.

The output is exactly the requested size and the aspect ratio is not preserved — this is the mode a caller picks when they have already decided distortion is acceptable. Both a width and a height are required. Distances that belong to no axis, such as a stroke width, are scaled by the geometric mean of the two axis scales.

Remarks

The three modes are the ones every layout system converges on, and they differ only in what they are willing to give up when the requested box has a different aspect ratio from the page: Contain gives up filling the box, Cover gives up some of the page, and Exact gives up the aspect ratio.

This lives in DocWright.Core rather than in either renderer because both the document-to-image path and the PDF rasterizer take it, and a resize vocabulary that existed twice would be two things to keep in agreement. The output format enums are deliberately still separate — that separation exists so a PDF reader need not reference the layout renderer, and a shared enum in Core costs neither of them a dependency.