Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
Created October 21, 2021 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krzyzanowskim/8984173d32b5d037290801e01f926dc3 to your computer and use it in GitHub Desktop.
Save krzyzanowskim/8984173d32b5d037290801e01f926dc3 to your computer and use it in GitHub Desktop.
TextKit large numbers
// This file defines two numbers to use to mean "really big".
// The first is called LargeNumberForText, and it was not arbitrarily chosen.
// The actual value was chosen to be around the largest floating point value possible that can preserve at least pixel precision.
// Because of the nature of floating point numbers, the bigger they get, the less precise they get.
// It is not wise to use bigger dimensions for text system objects because, even if you ever fill all that space,
// by the time you get to the far reaches, the letters won't have the precision necessary to look and act correctly.
// This limitation of floating point coordinates goes all the way down into postscript, and holds for any type postscript graphics.
// Because the Cocoa text system respects this limit in various ways, a second constant, NotQuiteAsLargeNumberForText,
// is used for the field-like text views created by the FieldAspect class. This is simply half of LargeNumberForText;
// at sizes as large as LargeNumberForText, the text system stops aligning text, for various reasons.
// Apple mention that recommended text Container size limit should not be more that 1.0e7,
// otherwise text will become blurry.
let largeNumberForText = 1.0e7
// Too large and the Cocoa text system stops aligning text, for various reasons
let notQuiteAsLargeNumberForText = 0.5e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment