Images
The Word canvas
If an image is greater than available canvas real estate, then the image is resized to fit within the available canvas.
Image sizing logic
Multiple changes have been made with regard to the logic used to obtain and serialize image dimensions.
-
Implemented logic to normalize DPI metrics as soon as an image is inserted into an XML Author document. Since DPI is serialized as an integer value, all DPI will be managed internally as integers thus eliminating the need to round DPI values on demand.
-
Implemented new method to normalize point values to a granularity of 1/20 point. This is used following resize to limit rounding errors thus preventing dimensional drift.
-
Resize logic was modified to use normalized point size of inline shapes following resize. This helps to limit rounding problems and to stabilize dimensional drift.
-
Internal references and definition for DPI variables, properties, etc. were modified to change the data type from floating-point to integer for the purpose of limiting rounding errors which cause image dimensions to drift upon save, close, reopen cycles.
-
The point / pixel conversion logic was refactored to properly round float values during conversion. This is used during operations where images are inserted, refreshed, resized or replaced to limit rounding errors thus preventing dimensional drift.
Rounding Error Issue
Current image size behavior in XML Author is governed by actual image metrics that are extracted from the image binary itself wherever possible. All supported graphics files that contain image metrics use the same data types.
-
Height and width (pixels) are stored as an integer data type.
-
Horizontal and vertical resolution (DPI) are stored as a float data type.
However, meta-files (EMF, EMZ, WMF, WMZ) can store horizontal and vertical resolution as non-integer values. For example, 599.501. All other graphic formats store resolution as whole number values. For example, 600.000.
Facts and conversion factors:
-
DPI = dpi = dots per inch = dots / inch
-
1 inch = 72 points
Microsoft measures the physical size of images in points.
Persistence and certain calculations require pixels and dpi, therefore we must convert back and forth between Microsoft points and pixels-dpi.
Point values may change when images are inserted, resized, refreshed. At the time of these events, point values are rounded to the nearest 1/20 or 0.05 so that point values never deviate from the necessary degree of precision required.
Precision requires that we manage values as integers, this requires that we round resolutions that are not whole numbers to be whole numbers. This only applies to meta-files (EMF, EMZ, WMF, WMZ).
The image metrics must be serialized as integer values using pixels and dpi as the unit of measure for consumption by other downstream processes.
Some precision is lost due to rounding, but rounding is required to maximize the consistency of calculations across all graphic types.
To inspect the image metrics of a given image file use Microsoft Office Picture Manager that is installed in the Office Tools folder. Do not use Microsoft Paint for this purpose. It's unreliable.
