'How do I get base-space transform from CGContext?

The offset for CGContext.setShadow has to be specified in base-space:

offset - Specifies a translation in base-space.

(from https://developer.apple.com/documentation/coregraphics/cgcontext/1455205-setshadow)

What is this "base-space"?

Semi related docs have this explanation:

  • The drawing (user) coordinate system. This coordinate system is used when you issue drawing commands.
  • The view coordinate system (base space). This coordinate system is a fixed coordinate system relative to the view.
  • The (physical) device coordinate system. This coordinate system represents pixels on the physical screen.

(from: https://developer.apple.com/library/archive/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GraphicsDrawingOverview/GraphicsDrawingOverview.html)

This makes sense. However, how do I get the transform of this base-space? There is CGContext.userSpaceToDeviceSpaceTransform but it seems to be transform from user->physical. How do I get from user->base or base->physical?



Solution 1:[1]

I believe that the base-space is equivalent to when the user-space has an identity transform matrix. In Apple's documentation, figure 1-1, the show the base-space have the origin in the upper-left, and an identity matrix of one (the indicated pixel of (3, 5) is 3 to the right, 5 down, as expected).

Thus, the shadow offset is in untransformed units. This is probably convenient for you, as you probably want the shadow offset to be the same, regardless of what the scale factor is. (If you scale a piece of vector clip art in a PowerPoint presentation, you want the shadow to be offset the same no matter how big you expand the clip art.)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 prewett