mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
[ASTextNode] Add NSCache based cache for ASTextKitRenderer (#2199)
* Add cache implementation * Remove old ASEqualityHashHelpers * Some more ASEquality and ASEqualityHashHelper cleanup * Add cache for text renderer in ASTextNode * Move from C++ LRU renderer cache to NSCache based renderer cache
This commit is contained in:
committed by
Adlai Holler
parent
6124830b23
commit
2388f67474
@@ -95,7 +95,6 @@
|
||||
254C6B7D1BF94DF4003EC431 /* ASTextKitShadower.h in Headers */ = {isa = PBXBuildFile; fileRef = 2577549F1BEE44CD00737CA5 /* ASTextKitShadower.h */; };
|
||||
254C6B7E1BF94DF4003EC431 /* ASTextKitTailTruncater.h in Headers */ = {isa = PBXBuildFile; fileRef = 257754A11BEE44CD00737CA5 /* ASTextKitTailTruncater.h */; };
|
||||
254C6B7F1BF94DF4003EC431 /* ASTextKitTruncating.h in Headers */ = {isa = PBXBuildFile; fileRef = 257754A31BEE44CD00737CA5 /* ASTextKitTruncating.h */; };
|
||||
254C6B801BF94DF4003EC431 /* ASEqualityHashHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 257754A41BEE44CD00737CA5 /* ASEqualityHashHelpers.h */; };
|
||||
254C6B821BF94F8A003EC431 /* ASTextKitComponents.m in Sources */ = {isa = PBXBuildFile; fileRef = 257754B71BEE458D00737CA5 /* ASTextKitComponents.m */; };
|
||||
254C6B831BF94F8A003EC431 /* ASTextKitCoreTextAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 257754B81BEE458E00737CA5 /* ASTextKitCoreTextAdditions.m */; };
|
||||
254C6B841BF94F8A003EC431 /* ASTextNodeWordKerner.m in Sources */ = {isa = PBXBuildFile; fileRef = 257754BD1BEE458E00737CA5 /* ASTextNodeWordKerner.m */; };
|
||||
@@ -107,8 +106,6 @@
|
||||
254C6B8A1BF94F8A003EC431 /* ASTextKitRenderer+TextChecking.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2577549E1BEE44CD00737CA5 /* ASTextKitRenderer+TextChecking.mm */; };
|
||||
254C6B8B1BF94F8A003EC431 /* ASTextKitShadower.mm in Sources */ = {isa = PBXBuildFile; fileRef = 257754A01BEE44CD00737CA5 /* ASTextKitShadower.mm */; };
|
||||
254C6B8C1BF94F8A003EC431 /* ASTextKitTailTruncater.mm in Sources */ = {isa = PBXBuildFile; fileRef = 257754A21BEE44CD00737CA5 /* ASTextKitTailTruncater.mm */; };
|
||||
254C6B8D1BF94F8A003EC431 /* ASEqualityHashHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2577548F1BED289A00737CA5 /* ASEqualityHashHelpers.mm */; };
|
||||
257754921BED28F300737CA5 /* ASEqualityHashHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2577548F1BED289A00737CA5 /* ASEqualityHashHelpers.mm */; };
|
||||
257754A61BEE44CD00737CA5 /* ASTextKitAttributes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 257754941BEE44CD00737CA5 /* ASTextKitAttributes.mm */; };
|
||||
257754A91BEE44CD00737CA5 /* ASTextKitContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 257754971BEE44CD00737CA5 /* ASTextKitContext.mm */; };
|
||||
257754AB1BEE44CD00737CA5 /* ASTextKitEntityAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 257754991BEE44CD00737CA5 /* ASTextKitEntityAttribute.m */; };
|
||||
@@ -203,6 +200,9 @@
|
||||
68FC85EB1CE29C7D00EDD713 /* ASVisibilityProtocols.m in Sources */ = {isa = PBXBuildFile; fileRef = 68FC85E81CE29C7D00EDD713 /* ASVisibilityProtocols.m */; };
|
||||
68FC85EC1CE29C7D00EDD713 /* ASVisibilityProtocols.m in Sources */ = {isa = PBXBuildFile; fileRef = 68FC85E81CE29C7D00EDD713 /* ASVisibilityProtocols.m */; };
|
||||
696FCB311D6E46050093471E /* ASBackgroundLayoutSpecSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 696FCB301D6E46050093471E /* ASBackgroundLayoutSpecSnapshotTests.mm */; };
|
||||
69708BA61D76386D005C3CF9 /* ASEqualityHashHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 69708BA41D76386D005C3CF9 /* ASEqualityHashHelpers.h */; };
|
||||
69708BA71D76386D005C3CF9 /* ASEqualityHashHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69708BA51D76386D005C3CF9 /* ASEqualityHashHelpers.mm */; };
|
||||
69708BA81D76386D005C3CF9 /* ASEqualityHashHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69708BA51D76386D005C3CF9 /* ASEqualityHashHelpers.mm */; };
|
||||
697B315A1CFE4B410049936F /* ASEditableTextNodeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 697B31591CFE4B410049936F /* ASEditableTextNodeTests.m */; };
|
||||
697C0DE41CF38F28001DE0D4 /* ASLayoutValidation.h in Headers */ = {isa = PBXBuildFile; fileRef = 697C0DE11CF38F28001DE0D4 /* ASLayoutValidation.h */; };
|
||||
697C0DE51CF38F28001DE0D4 /* ASLayoutValidation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 697C0DE21CF38F28001DE0D4 /* ASLayoutValidation.mm */; };
|
||||
@@ -213,6 +213,7 @@
|
||||
69CB62AC1CB8165900024920 /* _ASDisplayViewAccessiblity.h in Headers */ = {isa = PBXBuildFile; fileRef = 69CB62A91CB8165900024920 /* _ASDisplayViewAccessiblity.h */; };
|
||||
69CB62AD1CB8165900024920 /* _ASDisplayViewAccessiblity.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69CB62AA1CB8165900024920 /* _ASDisplayViewAccessiblity.mm */; };
|
||||
69CB62AE1CB8165900024920 /* _ASDisplayViewAccessiblity.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69CB62AA1CB8165900024920 /* _ASDisplayViewAccessiblity.mm */; };
|
||||
69E0E8A71D356C9400627613 /* ASEqualityHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 1950C4481A3BB5C1005C8279 /* ASEqualityHelpers.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
69E1006E1CA89CB600D88C1B /* ASEnvironmentInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 69E100691CA89CB600D88C1B /* ASEnvironmentInternal.h */; };
|
||||
69E1006F1CA89CB600D88C1B /* ASEnvironmentInternal.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69E1006A1CA89CB600D88C1B /* ASEnvironmentInternal.mm */; };
|
||||
69E100701CA89CB600D88C1B /* ASEnvironmentInternal.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69E1006A1CA89CB600D88C1B /* ASEnvironmentInternal.mm */; };
|
||||
@@ -404,7 +405,6 @@
|
||||
B35062571B010F070018CF92 /* ASAssert.h in Headers */ = {isa = PBXBuildFile; fileRef = 058D0A43195D058D00B7D73C /* ASAssert.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
B35062581B010F070018CF92 /* ASAvailability.h in Headers */ = {isa = PBXBuildFile; fileRef = 0516FA3A1A15563400B4EBED /* ASAvailability.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
B35062591B010F070018CF92 /* ASBaseDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = 058D0A44195D058D00B7D73C /* ASBaseDefines.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
B350625B1B010F070018CF92 /* ASEqualityHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 1950C4481A3BB5C1005C8279 /* ASEqualityHelpers.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
B350625C1B010F070018CF92 /* ASLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 0516FA3B1A15563400B4EBED /* ASLog.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
B350625D1B0111740018CF92 /* Photos.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 051943141A1575670030A7D0 /* Photos.framework */; };
|
||||
B350625E1B0111780018CF92 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 051943121A1575630030A7D0 /* AssetsLibrary.framework */; };
|
||||
@@ -570,7 +570,6 @@
|
||||
F7CE6C771D2CDB3F00BE4C15 /* ASTextKitTailTruncater.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 257754A11BEE44CD00737CA5 /* ASTextKitTailTruncater.h */; };
|
||||
F7CE6C781D2CDB3F00BE4C15 /* ASTextKitFontSizeAdjuster.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = A32FEDD31C501B6A004F642A /* ASTextKitFontSizeAdjuster.h */; };
|
||||
F7CE6C791D2CDB3F00BE4C15 /* ASTextKitTruncating.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 257754A31BEE44CD00737CA5 /* ASTextKitTruncating.h */; };
|
||||
F7CE6C7A1D2CDB3F00BE4C15 /* ASEqualityHashHelpers.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 257754A41BEE44CD00737CA5 /* ASEqualityHashHelpers.h */; };
|
||||
F7CE6C7B1D2CDB3F00BE4C15 /* ASAssert.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 058D0A43195D058D00B7D73C /* ASAssert.h */; };
|
||||
F7CE6C7C1D2CDB3F00BE4C15 /* ASAvailability.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0516FA3A1A15563400B4EBED /* ASAvailability.h */; };
|
||||
F7CE6C7D1D2CDB3F00BE4C15 /* ASBaseDefines.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 058D0A44195D058D00B7D73C /* ASBaseDefines.h */; };
|
||||
@@ -741,7 +740,6 @@
|
||||
F7CE6C771D2CDB3F00BE4C15 /* ASTextKitTailTruncater.h in CopyFiles */,
|
||||
F7CE6C781D2CDB3F00BE4C15 /* ASTextKitFontSizeAdjuster.h in CopyFiles */,
|
||||
F7CE6C791D2CDB3F00BE4C15 /* ASTextKitTruncating.h in CopyFiles */,
|
||||
F7CE6C7A1D2CDB3F00BE4C15 /* ASEqualityHashHelpers.h in CopyFiles */,
|
||||
F7CE6C7B1D2CDB3F00BE4C15 /* ASAssert.h in CopyFiles */,
|
||||
F7CE6C7C1D2CDB3F00BE4C15 /* ASAvailability.h in CopyFiles */,
|
||||
F7CE6C7D1D2CDB3F00BE4C15 /* ASBaseDefines.h in CopyFiles */,
|
||||
@@ -908,7 +906,6 @@
|
||||
2538B6F21BC5D2A2003CA0B4 /* ASCollectionViewFlowLayoutInspectorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ASCollectionViewFlowLayoutInspectorTests.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
|
||||
254C6B511BF8FE6D003EC431 /* ASTextKitTruncationTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASTextKitTruncationTests.mm; sourceTree = "<group>"; };
|
||||
254C6B531BF8FF2A003EC431 /* ASTextKitTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASTextKitTests.mm; sourceTree = "<group>"; };
|
||||
2577548F1BED289A00737CA5 /* ASEqualityHashHelpers.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASEqualityHashHelpers.mm; sourceTree = "<group>"; };
|
||||
257754931BEE44CD00737CA5 /* ASTextKitRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASTextKitRenderer.h; path = TextKit/ASTextKitRenderer.h; sourceTree = "<group>"; };
|
||||
257754941BEE44CD00737CA5 /* ASTextKitAttributes.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ASTextKitAttributes.mm; path = TextKit/ASTextKitAttributes.mm; sourceTree = "<group>"; };
|
||||
257754951BEE44CD00737CA5 /* ASTextKitAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASTextKitAttributes.h; path = TextKit/ASTextKitAttributes.h; sourceTree = "<group>"; };
|
||||
@@ -926,7 +923,6 @@
|
||||
257754A11BEE44CD00737CA5 /* ASTextKitTailTruncater.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASTextKitTailTruncater.h; path = TextKit/ASTextKitTailTruncater.h; sourceTree = "<group>"; };
|
||||
257754A21BEE44CD00737CA5 /* ASTextKitTailTruncater.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ASTextKitTailTruncater.mm; path = TextKit/ASTextKitTailTruncater.mm; sourceTree = "<group>"; };
|
||||
257754A31BEE44CD00737CA5 /* ASTextKitTruncating.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASTextKitTruncating.h; path = TextKit/ASTextKitTruncating.h; sourceTree = "<group>"; };
|
||||
257754A41BEE44CD00737CA5 /* ASEqualityHashHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASEqualityHashHelpers.h; path = TextKit/ASEqualityHashHelpers.h; sourceTree = "<group>"; };
|
||||
257754B71BEE458D00737CA5 /* ASTextKitComponents.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ASTextKitComponents.m; path = TextKit/ASTextKitComponents.m; sourceTree = "<group>"; };
|
||||
257754B81BEE458E00737CA5 /* ASTextKitCoreTextAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ASTextKitCoreTextAdditions.m; path = TextKit/ASTextKitCoreTextAdditions.m; sourceTree = "<group>"; };
|
||||
257754B91BEE458E00737CA5 /* ASTextNodeWordKerner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASTextNodeWordKerner.h; path = TextKit/ASTextNodeWordKerner.h; sourceTree = "<group>"; };
|
||||
@@ -971,6 +967,8 @@
|
||||
68FC85E71CE29C7D00EDD713 /* ASVisibilityProtocols.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASVisibilityProtocols.h; sourceTree = "<group>"; };
|
||||
68FC85E81CE29C7D00EDD713 /* ASVisibilityProtocols.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASVisibilityProtocols.m; sourceTree = "<group>"; };
|
||||
696FCB301D6E46050093471E /* ASBackgroundLayoutSpecSnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASBackgroundLayoutSpecSnapshotTests.mm; sourceTree = "<group>"; };
|
||||
69708BA41D76386D005C3CF9 /* ASEqualityHashHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASEqualityHashHelpers.h; path = TextKit/ASEqualityHashHelpers.h; sourceTree = "<group>"; };
|
||||
69708BA51D76386D005C3CF9 /* ASEqualityHashHelpers.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ASEqualityHashHelpers.mm; path = TextKit/ASEqualityHashHelpers.mm; sourceTree = "<group>"; };
|
||||
697B31591CFE4B410049936F /* ASEditableTextNodeTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASEditableTextNodeTests.m; sourceTree = "<group>"; };
|
||||
697C0DE11CF38F28001DE0D4 /* ASLayoutValidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASLayoutValidation.h; path = AsyncDisplayKit/Layout/ASLayoutValidation.h; sourceTree = "<group>"; };
|
||||
697C0DE21CF38F28001DE0D4 /* ASLayoutValidation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ASLayoutValidation.mm; path = AsyncDisplayKit/Layout/ASLayoutValidation.mm; sourceTree = "<group>"; };
|
||||
@@ -1418,9 +1416,6 @@
|
||||
058D09E1195D050800B7D73C /* Details */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
CC4981BA1D1C7F65004E13CC /* NSIndexSet+ASHelpers.h */,
|
||||
CC4981BB1D1C7F65004E13CC /* NSIndexSet+ASHelpers.m */,
|
||||
9CFFC6BD1CCAC52B006A6476 /* ASEnvironment.mm */,
|
||||
058D09E2195D050800B7D73C /* _ASDisplayLayer.h */,
|
||||
058D09E3195D050800B7D73C /* _ASDisplayLayer.mm */,
|
||||
058D09E4195D050800B7D73C /* _ASDisplayView.h */,
|
||||
@@ -1440,17 +1435,16 @@
|
||||
05A6D05819D0EB64002DD95E /* ASDealloc2MainObject.h */,
|
||||
05A6D05919D0EB64002DD95E /* ASDealloc2MainObject.m */,
|
||||
698548611CA9E025008A345F /* ASEnvironment.h */,
|
||||
9CFFC6BD1CCAC52B006A6476 /* ASEnvironment.mm */,
|
||||
4640521B1A3F83C40061C0BA /* ASFlowLayoutController.h */,
|
||||
4640521C1A3F83C40061C0BA /* ASFlowLayoutController.mm */,
|
||||
058D09E6195D050800B7D73C /* ASHighlightOverlayLayer.h */,
|
||||
058D09E7195D050800B7D73C /* ASHighlightOverlayLayer.mm */,
|
||||
430E7C8D1B4C23F100697A4C /* ASIndexPath.h */,
|
||||
430E7C8E1B4C23F100697A4C /* ASIndexPath.m */,
|
||||
05F20AA31A15733C00DCA68A /* ASImageProtocols.h */,
|
||||
68355B371CB57A5A001D4E68 /* ASImageContainerProtocolCategories.h */,
|
||||
68355B381CB57A5A001D4E68 /* ASImageContainerProtocolCategories.m */,
|
||||
68355B391CB57A5A001D4E68 /* ASPINRemoteImageDownloader.h */,
|
||||
68355B361CB57A5A001D4E68 /* ASPINRemoteImageDownloader.m */,
|
||||
05F20AA31A15733C00DCA68A /* ASImageProtocols.h */,
|
||||
430E7C8D1B4C23F100697A4C /* ASIndexPath.h */,
|
||||
430E7C8E1B4C23F100697A4C /* ASIndexPath.m */,
|
||||
4640521D1A3F83C40061C0BA /* ASLayoutController.h */,
|
||||
292C59991A956527007E5DD6 /* ASLayoutRangeType.h */,
|
||||
68EE0DBB1C1B4ED300BA1B99 /* ASMainSerialQueue.h */,
|
||||
@@ -1459,6 +1453,8 @@
|
||||
058D09E9195D050800B7D73C /* ASMutableAttributedStringBuilder.m */,
|
||||
CC7FD9DC1BB5E962005CCB2B /* ASPhotosFrameworkImageRequest.h */,
|
||||
CC7FD9DD1BB5E962005CCB2B /* ASPhotosFrameworkImageRequest.m */,
|
||||
68355B391CB57A5A001D4E68 /* ASPINRemoteImageDownloader.h */,
|
||||
68355B361CB57A5A001D4E68 /* ASPINRemoteImageDownloader.m */,
|
||||
055F1A3619ABD413004DAFF1 /* ASRangeController.h */,
|
||||
055F1A3719ABD413004DAFF1 /* ASRangeController.mm */,
|
||||
69F10C851C84C35D0026140C /* ASRangeControllerUpdateRangeProtocol+Beta.h */,
|
||||
@@ -1467,19 +1463,21 @@
|
||||
296A0A311A951715005ACEAA /* ASScrollDirection.h */,
|
||||
205F0E111B371BD7007741D0 /* ASScrollDirection.m */,
|
||||
058D0A12195D050800B7D73C /* ASThread.h */,
|
||||
9C70F2011CDA4EFA007D6C76 /* ASTraitCollection.h */,
|
||||
9C70F2021CDA4EFA007D6C76 /* ASTraitCollection.m */,
|
||||
68B8A4DF1CBDB958007E4543 /* ASWeakProxy.h */,
|
||||
68B8A4E01CBDB958007E4543 /* ASWeakProxy.m */,
|
||||
205F0E1F1B376416007741D0 /* CGRect+ASConvenience.h */,
|
||||
205F0E201B376416007741D0 /* CGRect+ASConvenience.m */,
|
||||
25B171EA1C12242700508A7A /* Data Controller */,
|
||||
CC4981BA1D1C7F65004E13CC /* NSIndexSet+ASHelpers.h */,
|
||||
CC4981BB1D1C7F65004E13CC /* NSIndexSet+ASHelpers.m */,
|
||||
058D09F5195D050800B7D73C /* NSMutableAttributedString+TextKitAdditions.h */,
|
||||
058D09F6195D050800B7D73C /* NSMutableAttributedString+TextKitAdditions.m */,
|
||||
058D09F7195D050800B7D73C /* Transactions */,
|
||||
205F0E0D1B371875007741D0 /* UICollectionViewLayout+ASConvenience.h */,
|
||||
205F0E0E1B371875007741D0 /* UICollectionViewLayout+ASConvenience.m */,
|
||||
058D09FF195D050800B7D73C /* UIView+ASConvenience.h */,
|
||||
9C70F2011CDA4EFA007D6C76 /* ASTraitCollection.h */,
|
||||
9C70F2021CDA4EFA007D6C76 /* ASTraitCollection.m */,
|
||||
CC3B20871C3F7A5400798563 /* ASWeakSet.h */,
|
||||
CC3B20881C3F7A5400798563 /* ASWeakSet.m */,
|
||||
DBC452D91C5BF64600B16017 /* NSArray+Diffing.h */,
|
||||
@@ -1528,16 +1526,16 @@
|
||||
DE6EA3211C14000600183B10 /* ASDisplayNode+FrameworkPrivate.h */,
|
||||
058D0A0B195D050800B7D73C /* ASDisplayNode+UIViewBridge.mm */,
|
||||
058D0A0C195D050800B7D73C /* ASDisplayNodeInternal.h */,
|
||||
E52405B41C8FEF16004DC8E7 /* ASLayoutTransition.h */,
|
||||
E52405B21C8FEF03004DC8E7 /* ASLayoutTransition.mm */,
|
||||
69E100691CA89CB600D88C1B /* ASEnvironmentInternal.h */,
|
||||
69E1006A1CA89CB600D88C1B /* ASEnvironmentInternal.mm */,
|
||||
68B8A4DB1CBD911D007E4543 /* ASImageNode+AnimatedImagePrivate.h */,
|
||||
058D0A0D195D050800B7D73C /* ASImageNode+CGExtras.h */,
|
||||
058D0A0E195D050800B7D73C /* ASImageNode+CGExtras.m */,
|
||||
68B8A4DB1CBD911D007E4543 /* ASImageNode+AnimatedImagePrivate.h */,
|
||||
ACF6ED431B17847A00DA7C62 /* ASInternalHelpers.h */,
|
||||
ACF6ED441B17847A00DA7C62 /* ASInternalHelpers.m */,
|
||||
ACF6ED451B17847A00DA7C62 /* ASLayoutSpecUtilities.h */,
|
||||
E52405B41C8FEF16004DC8E7 /* ASLayoutTransition.h */,
|
||||
E52405B21C8FEF03004DC8E7 /* ASLayoutTransition.mm */,
|
||||
0442850B1BAA64EC00D16268 /* ASMultidimensionalArrayUtils.h */,
|
||||
0442850C1BAA64EC00D16268 /* ASMultidimensionalArrayUtils.mm */,
|
||||
CC3B20811C3F76D600798563 /* ASPendingStateController.h */,
|
||||
@@ -1574,6 +1572,8 @@
|
||||
257754661BED245B00737CA5 /* TextKit */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
69708BA41D76386D005C3CF9 /* ASEqualityHashHelpers.h */,
|
||||
69708BA51D76386D005C3CF9 /* ASEqualityHashHelpers.mm */,
|
||||
B30BF6501C5964B0004FCD53 /* ASLayoutManager.h */,
|
||||
B30BF6511C5964B0004FCD53 /* ASLayoutManager.m */,
|
||||
257754BA1BEE458E00737CA5 /* ASTextKitComponents.h */,
|
||||
@@ -1602,8 +1602,6 @@
|
||||
A32FEDD31C501B6A004F642A /* ASTextKitFontSizeAdjuster.h */,
|
||||
9C8898BA1C738B9800D6B02E /* ASTextKitFontSizeAdjuster.mm */,
|
||||
257754A31BEE44CD00737CA5 /* ASTextKitTruncating.h */,
|
||||
257754A41BEE44CD00737CA5 /* ASEqualityHashHelpers.h */,
|
||||
2577548F1BED289A00737CA5 /* ASEqualityHashHelpers.mm */,
|
||||
);
|
||||
name = TextKit;
|
||||
sourceTree = "<group>";
|
||||
@@ -1713,6 +1711,7 @@
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
69E0E8A71D356C9400627613 /* ASEqualityHelpers.h in Headers */,
|
||||
698C8B621CAB49FC0052DC3F /* ASLayoutableExtensibility.h in Headers */,
|
||||
698548641CA9E025008A345F /* ASEnvironment.h in Headers */,
|
||||
AC026B6A1BD57D6F00BBC17E /* ASChangeSetDataController.h in Headers */,
|
||||
@@ -1779,14 +1778,12 @@
|
||||
DBABFAFC1C6A8D2F0039EA4A /* _ASTransitionContext.h in Headers */,
|
||||
9C70F2061CDA4F0C007D6C76 /* ASTraitCollection.h in Headers */,
|
||||
8021EC1D1D2B00B100799119 /* UIImage+ASConvenience.h in Headers */,
|
||||
254C6B801BF94DF4003EC431 /* ASEqualityHashHelpers.h in Headers */,
|
||||
B350624F1B010EFD0018CF92 /* ASDisplayNode+DebugTiming.h in Headers */,
|
||||
B35061FD1B010EFD0018CF92 /* ASDisplayNode+Subclasses.h in Headers */,
|
||||
B35061FB1B010EFD0018CF92 /* ASDisplayNode.h in Headers */,
|
||||
B35061FE1B010EFD0018CF92 /* ASDisplayNodeExtras.h in Headers */,
|
||||
B35062521B010EFD0018CF92 /* ASDisplayNodeInternal.h in Headers */,
|
||||
B35062001B010EFD0018CF92 /* ASEditableTextNode.h in Headers */,
|
||||
B350625B1B010F070018CF92 /* ASEqualityHelpers.h in Headers */,
|
||||
680346941CE4052A0009FEB4 /* ASNavigationController.h in Headers */,
|
||||
B350621B1B010EFD0018CF92 /* ASFlowLayoutController.h in Headers */,
|
||||
B350621D1B010EFD0018CF92 /* ASHighlightOverlayLayer.h in Headers */,
|
||||
@@ -1832,6 +1829,7 @@
|
||||
68B0277B1C1A79D60041016B /* ASDisplayNode+Beta.h in Headers */,
|
||||
CCF18FF41D2575E300DF5895 /* NSIndexSet+ASHelpers.h in Headers */,
|
||||
83A7D95C1D44548100BF333E /* ASWeakMap.h in Headers */,
|
||||
69708BA61D76386D005C3CF9 /* ASEqualityHashHelpers.h in Headers */,
|
||||
B350622D1B010EFD0018CF92 /* ASScrollDirection.h in Headers */,
|
||||
254C6B751BF94DF4003EC431 /* ASTextKitComponents.h in Headers */,
|
||||
683489281D70DE3400327501 /* ASDisplayNode+Deprecated.h in Headers */,
|
||||
@@ -2100,6 +2098,7 @@
|
||||
68EE0DBF1C1B4ED300BA1B99 /* ASMainSerialQueue.mm in Sources */,
|
||||
058D0A19195D050800B7D73C /* _ASDisplayView.mm in Sources */,
|
||||
9C55866A1BD549CB00B50E3A /* ASAsciiArtBoxCreator.m in Sources */,
|
||||
69708BA71D76386D005C3CF9 /* ASEqualityHashHelpers.mm in Sources */,
|
||||
058D0A27195D050800B7D73C /* _ASPendingState.mm in Sources */,
|
||||
205F0E1A1B37339C007741D0 /* ASAbstractLayoutController.mm in Sources */,
|
||||
ACF6ED1B1B17843500DA7C62 /* ASBackgroundLayoutSpec.mm in Sources */,
|
||||
@@ -2157,7 +2156,6 @@
|
||||
ACF6ED2C1B17843500DA7C62 /* ASOverlayLayoutSpec.mm in Sources */,
|
||||
0442850F1BAA64EC00D16268 /* ASMultidimensionalArrayUtils.mm in Sources */,
|
||||
7A06A73A1C35F08800FE8DAA /* ASRelativeLayoutSpec.mm in Sources */,
|
||||
257754921BED28F300737CA5 /* ASEqualityHashHelpers.mm in Sources */,
|
||||
E52405B31C8FEF03004DC8E7 /* ASLayoutTransition.mm in Sources */,
|
||||
69CB62AD1CB8165900024920 /* _ASDisplayViewAccessiblity.mm in Sources */,
|
||||
257754AB1BEE44CD00737CA5 /* ASTextKitEntityAttribute.m in Sources */,
|
||||
@@ -2280,6 +2278,7 @@
|
||||
B35062121B010EFD0018CF92 /* _ASDisplayView.mm in Sources */,
|
||||
DEFAD8131CC48914000527C4 /* ASVideoNode.mm in Sources */,
|
||||
B350624C1B010EFD0018CF92 /* _ASPendingState.mm in Sources */,
|
||||
69708BA81D76386D005C3CF9 /* ASEqualityHashHelpers.mm in Sources */,
|
||||
509E68621B3AEDA5009B9150 /* ASAbstractLayoutController.mm in Sources */,
|
||||
254C6B861BF94F8A003EC431 /* ASTextKitContext.mm in Sources */,
|
||||
DBDB83971C6E879900D0098C /* ASPagerFlowLayout.m in Sources */,
|
||||
@@ -2371,7 +2370,6 @@
|
||||
B350620E1B010EFD0018CF92 /* ASTextNode.mm in Sources */,
|
||||
68355B3E1CB57A60001D4E68 /* ASPINRemoteImageDownloader.m in Sources */,
|
||||
509E68661B3AEDD7009B9150 /* CGRect+ASConvenience.m in Sources */,
|
||||
254C6B8D1BF94F8A003EC431 /* ASEqualityHashHelpers.mm in Sources */,
|
||||
254C6B871BF94F8A003EC431 /* ASTextKitEntityAttribute.m in Sources */,
|
||||
34566CB31BC1213700715E6B /* ASPhotosFrameworkImageRequest.m in Sources */,
|
||||
254C6B831BF94F8A003EC431 /* ASTextKitCoreTextAdditions.m in Sources */,
|
||||
|
||||
@@ -44,6 +44,80 @@ static const CGFloat ASTextNodeHighlightLightOpacity = 0.11;
|
||||
static const CGFloat ASTextNodeHighlightDarkOpacity = 0.22;
|
||||
static NSString *ASTextNodeTruncationTokenAttributeName = @"ASTextNodeTruncationAttribute";
|
||||
|
||||
#pragma mark - ASTextKitRenderer
|
||||
|
||||
// Not used at the moment but handy to have
|
||||
/*ASDISPLAYNODE_INLINE NSUInteger ASHashFromCGRect(CGRect rect)
|
||||
{
|
||||
return ((*(NSUInteger *)&rect.origin.x << 10 ^ *(NSUInteger *)&rect.origin.y) + (*(NSUInteger *)&rect.size.width << 10 ^ *(NSUInteger *)&rect.size.height));
|
||||
}*/
|
||||
|
||||
ASDISPLAYNODE_INLINE NSUInteger ASHashFromCGSize(CGSize size)
|
||||
{
|
||||
return ((*(NSUInteger *)&size.width << 10 ^ *(NSUInteger *)&size.height));
|
||||
}
|
||||
|
||||
@interface ASTextNodeRendererKey : NSObject
|
||||
@property (assign, nonatomic) ASTextKitAttributes attributes;
|
||||
@property (assign, nonatomic) CGSize constrainedSize;
|
||||
@end
|
||||
|
||||
@implementation ASTextNodeRendererKey
|
||||
|
||||
- (NSUInteger)hash
|
||||
{
|
||||
return _attributes.hash() ^ ASHashFromCGSize(_constrainedSize);
|
||||
}
|
||||
|
||||
- (BOOL)isEqual:(ASTextNodeRendererKey *)object
|
||||
{
|
||||
if (self == object) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
return _attributes.hash() == object.attributes.hash()
|
||||
&& CGSizeEqualToSize(_constrainedSize, object.constrainedSize);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static NSCache *sharedRendererCache()
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
static NSCache *__rendererCache = nil;
|
||||
dispatch_once(&onceToken, ^{
|
||||
__rendererCache = [[NSCache alloc] init];
|
||||
__rendererCache.totalCostLimit = 500; // 500 renders cache
|
||||
});
|
||||
return __rendererCache;
|
||||
}
|
||||
|
||||
/**
|
||||
The concept here is that neither the node nor layout should ever have a strong reference to the renderer object.
|
||||
This is to reduce memory load when loading thousands and thousands of text nodes into memory at once. Instead
|
||||
we maintain a LRU renderer cache that is queried via stack-allocated keys.
|
||||
*/
|
||||
|
||||
static ASTextKitRenderer *rendererForAttributes(ASTextKitAttributes attributes, CGSize constrainedSize)
|
||||
{
|
||||
NSCache *cache = sharedRendererCache();
|
||||
|
||||
ASTextNodeRendererKey *key = [[ASTextNodeRendererKey alloc] init];
|
||||
key.attributes = attributes;
|
||||
key.constrainedSize = constrainedSize;
|
||||
|
||||
ASTextKitRenderer *renderer = [cache objectForKey:key];
|
||||
if (renderer == nil) {
|
||||
renderer = [[ASTextKitRenderer alloc] initWithTextKitAttributes:attributes constrainedSize:constrainedSize];
|
||||
[cache setObject:renderer forKey:key cost:1];
|
||||
}
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - ASTextNode
|
||||
|
||||
struct ASTextNodeDrawParameter {
|
||||
CGRect bounds;
|
||||
UIColor *backgroundColor;
|
||||
@@ -74,8 +148,6 @@ struct ASTextNodeDrawParameter {
|
||||
|
||||
CGSize _constrainedSize;
|
||||
|
||||
ASTextKitRenderer *_renderer;
|
||||
|
||||
ASTextNodeDrawParameter _drawParameter;
|
||||
|
||||
UILongPressGestureRecognizer *_longPressGestureRecognizer;
|
||||
@@ -143,8 +215,6 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
CGColorRelease(_shadowColor);
|
||||
}
|
||||
|
||||
[self _invalidateRenderer];
|
||||
|
||||
if (_longPressGestureRecognizer) {
|
||||
_longPressGestureRecognizer.delegate = nil;
|
||||
[_longPressGestureRecognizer removeTarget:nil action:NULL];
|
||||
@@ -160,34 +230,11 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
NSString *truncationString = [_composedTruncationText string];
|
||||
if (plainString.length > 50)
|
||||
plainString = [[plainString substringToIndex:50] stringByAppendingString:@"\u2026"];
|
||||
return [NSString stringWithFormat:@"<%@: %p; text = \"%@\"; truncation string = \"%@\"; frame = %@; renderer = %p>", self.class, self, plainString, truncationString, self.nodeLoaded ? NSStringFromCGRect(self.layer.frame) : nil, _renderer];
|
||||
return [NSString stringWithFormat:@"<%@: %p; text = \"%@\"; truncation string = \"%@\"; frame = %@; renderer = %p>", self.class, self, plainString, truncationString, self.nodeLoaded ? NSStringFromCGRect(self.layer.frame) : nil, [self _renderer]];
|
||||
}
|
||||
|
||||
#pragma mark - ASDisplayNode
|
||||
|
||||
// FIXME: Re-evaluate if it is still the right decision to clear the renderer at this stage.
|
||||
// This code was written before TextKit and when 512MB devices were still the overwhelming majority.
|
||||
- (void)displayDidFinish
|
||||
{
|
||||
[super displayDidFinish];
|
||||
|
||||
// We invalidate our renderer here to clear the very high memory cost of
|
||||
// keeping this around. _invalidateRenderer will dealloc this onto a bg
|
||||
// thread resulting in less stutters on the main thread than if it were
|
||||
// to be deallocated in dealloc. This is also helpful in opportunistically
|
||||
// reducing memory consumption and reducing the overall footprint of the app.
|
||||
[self _invalidateRenderer];
|
||||
}
|
||||
|
||||
- (void)clearContents
|
||||
{
|
||||
// We discard the backing store and renderer to prevent the very large
|
||||
// memory overhead of maintaining these for all text nodes. They can be
|
||||
// regenerated when layout is necessary.
|
||||
[super clearContents]; // ASDisplayNode will set layer.contents = nil
|
||||
[self _invalidateRenderer];
|
||||
}
|
||||
|
||||
- (void)didLoad
|
||||
{
|
||||
[super didLoad];
|
||||
@@ -202,18 +249,6 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setFrame:(CGRect)frame
|
||||
{
|
||||
[super setFrame:frame];
|
||||
[self _invalidateRendererIfNeededForBoundsSize:frame.size];
|
||||
}
|
||||
|
||||
- (void)setBounds:(CGRect)bounds
|
||||
{
|
||||
[super setBounds:bounds];
|
||||
[self _invalidateRendererIfNeededForBoundsSize:bounds.size];
|
||||
}
|
||||
|
||||
#pragma mark - Renderer Management
|
||||
|
||||
- (ASTextKitRenderer *)_renderer
|
||||
@@ -225,7 +260,6 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
|
||||
if (_renderer == nil) {
|
||||
CGSize constrainedSize;
|
||||
if (_constrainedSize.width != -INFINITY) {
|
||||
constrainedSize = _constrainedSize;
|
||||
@@ -235,10 +269,7 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
constrainedSize.height -= (_textContainerInset.top + _textContainerInset.bottom);
|
||||
}
|
||||
|
||||
_renderer = [[ASTextKitRenderer alloc] initWithTextKitAttributes:[self _rendererAttributes]
|
||||
constrainedSize:constrainedSize];
|
||||
}
|
||||
return _renderer;
|
||||
return rendererForAttributes([self _rendererAttributes], constrainedSize);
|
||||
}
|
||||
|
||||
- (ASTextKitAttributes)_rendererAttributes
|
||||
@@ -251,51 +282,15 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
.lineBreakMode = _truncationMode,
|
||||
.maximumNumberOfLines = _maximumNumberOfLines,
|
||||
.exclusionPaths = _exclusionPaths,
|
||||
// use the property getter so a subclass can provide these scale factors on demand if desired
|
||||
.pointSizeScaleFactors = self.pointSizeScaleFactors,
|
||||
.shadowOffset = _shadowOffset,
|
||||
.shadowColor = _cachedShadowUIColor,
|
||||
.shadowOpacity = _shadowOpacity,
|
||||
.shadowRadius = _shadowRadius
|
||||
.shadowRadius = _shadowRadius,
|
||||
// use the property getter so a subclass can provide these scale factors on demand if desired
|
||||
.pointSizeScaleFactors = self.pointSizeScaleFactors
|
||||
};
|
||||
}
|
||||
|
||||
- (void)_invalidateRendererIfNeeded
|
||||
{
|
||||
[self _invalidateRendererIfNeededForBoundsSize:self.threadSafeBounds.size];
|
||||
}
|
||||
|
||||
- (void)_invalidateRendererIfNeededForBoundsSize:(CGSize)boundsSize
|
||||
{
|
||||
if ([self _needInvalidateRendererForBoundsSize:boundsSize]) {
|
||||
// Our bounds have changed to a size that is not identical to our constraining size,
|
||||
// so our previous layout information is invalid, and TextKit may draw at the
|
||||
// incorrect origin.
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
_constrainedSize = CGSizeMake(-INFINITY, -INFINITY);
|
||||
}
|
||||
[self _invalidateRenderer];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_invalidateRenderer
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
|
||||
if (_renderer) {
|
||||
// Destruction of the layout managers/containers/text storage is quite
|
||||
// expensive, and can take some time, so we dispatch onto a bg queue to
|
||||
// actually dealloc.
|
||||
__block ASTextKitRenderer *renderer = _renderer;
|
||||
|
||||
ASPerformBlockOnDeallocationQueue(^{
|
||||
renderer = nil;
|
||||
});
|
||||
_renderer = nil;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Layout and Sizing
|
||||
|
||||
- (void)setTextContainerInset:(UIEdgeInsets)textContainerInset
|
||||
@@ -316,44 +311,6 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
return _textContainerInset;
|
||||
}
|
||||
|
||||
- (BOOL)_needInvalidateRendererForBoundsSize:(CGSize)boundsSize
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
|
||||
if (_renderer == nil) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
// If the size is not the same as the constraint we provided to the renderer, start out assuming we need
|
||||
// a new one. However, there are common cases where the constrained size doesn't need to be the same as calculated.
|
||||
CGSize rendererConstrainedSize = _renderer.constrainedSize;
|
||||
|
||||
//inset bounds
|
||||
boundsSize.width -= _textContainerInset.left + _textContainerInset.right;
|
||||
boundsSize.height -= _textContainerInset.top + _textContainerInset.bottom;
|
||||
|
||||
if (CGSizeEqualToSize(boundsSize, rendererConstrainedSize)) {
|
||||
return NO;
|
||||
} else {
|
||||
// It is very common to have a constrainedSize with a concrete, specific width but +Inf height.
|
||||
// In this case, as long as the text node has bounds as large as the full calculatedLayout suggests,
|
||||
// it means that the text has all the room it needs (as it was not vertically bounded). So, we will not
|
||||
// experience truncation and don't need to recreate the renderer with the size it already calculated,
|
||||
// as this would essentially serve to set its constrainedSize to be its calculatedSize (unnecessary).
|
||||
ASLayout *layout = self.calculatedLayout;
|
||||
if (layout != nil && CGSizeEqualToSize(boundsSize, layout.size)) {
|
||||
if (boundsSize.width != rendererConstrainedSize.width) {
|
||||
// Don't bother changing _constrainedSize, as ASDisplayNode's -measure: method would have a cache miss
|
||||
// and ask us to recalculate layout if it were called with the same calculatedSize that got us to this point!
|
||||
_renderer.constrainedSize = boundsSize;
|
||||
}
|
||||
return NO;
|
||||
} else {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)calculatedLayoutDidChange
|
||||
{
|
||||
[super calculatedLayoutDidChange];
|
||||
@@ -364,13 +321,12 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
CGSize layoutSize = layout.size;
|
||||
|
||||
//Apply textContainerInset
|
||||
// Apply textContainerInset
|
||||
layoutSize.width -= (_textContainerInset.left + _textContainerInset.right);
|
||||
layoutSize.height -= (_textContainerInset.top + _textContainerInset.bottom);
|
||||
|
||||
if (CGSizeEqualToSize(_constrainedSize, layoutSize) == NO) {
|
||||
_constrainedSize = layoutSize;
|
||||
_renderer.constrainedSize = layoutSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -391,24 +347,20 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
|
||||
_constrainedSize = constrainedSize;
|
||||
|
||||
// Instead of invalidating the renderer, in case this is a new call with a different constrained size,
|
||||
// just update the size of the NSTextContainer that is owned by the renderer's internal context object.
|
||||
[self _renderer].constrainedSize = _constrainedSize;
|
||||
ASTextKitRenderer *renderer = [self _renderer];
|
||||
|
||||
[self setNeedsDisplay];
|
||||
|
||||
CGSize size = [self _renderer].size;
|
||||
CGSize size = renderer.size;
|
||||
if (_attributedText.length > 0) {
|
||||
self.ascender = [[self class] ascenderWithAttributedString:_attributedText];
|
||||
self.descender = [[_attributedText attribute:NSFontAttributeName atIndex:_attributedText.length - 1 effectiveRange:NULL] descender];
|
||||
if (_renderer.currentScaleFactor > 0 && _renderer.currentScaleFactor < 1.0) {
|
||||
if (renderer.currentScaleFactor > 0 && renderer.currentScaleFactor < 1.0) {
|
||||
// while not perfect, this is a good estimate of what the ascender of the scaled font will be.
|
||||
self.ascender *= _renderer.currentScaleFactor;
|
||||
self.descender *= _renderer.currentScaleFactor;
|
||||
self.ascender *= renderer.currentScaleFactor;
|
||||
self.descender *= renderer.currentScaleFactor;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the constrained size back textContainerInset
|
||||
// Add textContainerInset to size
|
||||
size.width += (_textContainerInset.left + _textContainerInset.right);
|
||||
size.height += (_textContainerInset.top + _textContainerInset.bottom);
|
||||
|
||||
@@ -435,7 +387,6 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
|
||||
- (void)setAttributedText:(NSAttributedString *)attributedText
|
||||
{
|
||||
|
||||
if (attributedText == nil) {
|
||||
attributedText = [[NSAttributedString alloc] initWithString:@"" attributes:nil];
|
||||
}
|
||||
@@ -455,9 +406,6 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
// Without this, the size calculation of the text with truncation applied will
|
||||
// not take into account the attributes of attributedText in the last line
|
||||
[self _updateComposedTruncationText];
|
||||
|
||||
// We need an entirely new renderer
|
||||
[self _invalidateRenderer];
|
||||
}
|
||||
|
||||
NSUInteger length = attributedText.length;
|
||||
@@ -472,7 +420,6 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
// Force display to create renderer with new size and redisplay with new string
|
||||
[self setNeedsDisplay];
|
||||
|
||||
|
||||
// Accessiblity
|
||||
self.accessibilityLabel = attributedText.string;
|
||||
self.isAccessibilityElement = (length != 0); // We're an accessibility element by default if there is a string.
|
||||
@@ -489,7 +436,6 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
}
|
||||
|
||||
_exclusionPaths = [exclusionPaths copy];
|
||||
[self _invalidateRenderer];
|
||||
[self invalidateCalculatedLayout];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
@@ -792,10 +738,11 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
if (highlightTargetLayer != nil) {
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
|
||||
NSArray *highlightRects = [[self _renderer] rectsForTextRange:highlightRange measureOption:ASTextKitRendererMeasureOptionBlock];
|
||||
ASTextKitRenderer *renderer = [self _renderer];
|
||||
NSArray *highlightRects = [renderer rectsForTextRange:highlightRange measureOption:ASTextKitRendererMeasureOptionBlock];
|
||||
NSMutableArray *converted = [NSMutableArray arrayWithCapacity:highlightRects.count];
|
||||
for (NSValue *rectValue in highlightRects) {
|
||||
UIEdgeInsets shadowPadding = _renderer.shadower.shadowPadding;
|
||||
UIEdgeInsets shadowPadding = renderer.shadower.shadowPadding;
|
||||
CGRect rendererRect = ASTextNodeAdjustRenderRectForShadowPadding(rectValue.CGRectValue, shadowPadding);
|
||||
|
||||
// The rects returned from renderer don't have `textContainerInset`,
|
||||
@@ -1125,7 +1072,6 @@ static CGRect ASTextNodeAdjustRenderRectForShadowPadding(CGRect rendererRect, UI
|
||||
}
|
||||
_shadowColor = shadowColor;
|
||||
_cachedShadowUIColor = [UIColor colorWithCGColor:shadowColor];
|
||||
[self _invalidateRenderer];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
}
|
||||
@@ -1143,7 +1089,6 @@ static CGRect ASTextNodeAdjustRenderRectForShadowPadding(CGRect rendererRect, UI
|
||||
|
||||
if (!CGSizeEqualToSize(_shadowOffset, shadowOffset)) {
|
||||
_shadowOffset = shadowOffset;
|
||||
[self _invalidateRenderer];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
}
|
||||
@@ -1161,7 +1106,6 @@ static CGRect ASTextNodeAdjustRenderRectForShadowPadding(CGRect rendererRect, UI
|
||||
|
||||
if (_shadowOpacity != shadowOpacity) {
|
||||
_shadowOpacity = shadowOpacity;
|
||||
[self _invalidateRenderer];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
}
|
||||
@@ -1179,7 +1123,6 @@ static CGRect ASTextNodeAdjustRenderRectForShadowPadding(CGRect rendererRect, UI
|
||||
|
||||
if (_shadowRadius != shadowRadius) {
|
||||
_shadowRadius = shadowRadius;
|
||||
[self _invalidateRenderer];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
}
|
||||
@@ -1238,7 +1181,6 @@ static NSAttributedString *DefaultTruncationAttributedString()
|
||||
|
||||
if (_truncationMode != truncationMode) {
|
||||
_truncationMode = truncationMode;
|
||||
[self _invalidateRenderer];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
}
|
||||
@@ -1257,7 +1199,6 @@ static NSAttributedString *DefaultTruncationAttributedString()
|
||||
|
||||
if ([_pointSizeScaleFactors isEqualToArray:pointSizeScaleFactors] == NO) {
|
||||
_pointSizeScaleFactors = pointSizeScaleFactors;
|
||||
[self _invalidateRenderer];
|
||||
[self setNeedsDisplay];
|
||||
}}
|
||||
|
||||
@@ -1267,7 +1208,6 @@ static NSAttributedString *DefaultTruncationAttributedString()
|
||||
|
||||
if (_maximumNumberOfLines != maximumNumberOfLines) {
|
||||
_maximumNumberOfLines = maximumNumberOfLines;
|
||||
[self _invalidateRenderer];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
}
|
||||
@@ -1291,7 +1231,6 @@ static NSAttributedString *DefaultTruncationAttributedString()
|
||||
- (void)_invalidateTruncationText
|
||||
{
|
||||
[self _updateComposedTruncationText];
|
||||
[self _invalidateRenderer];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,8 @@ struct ASTextKitAttributes {
|
||||
&& maximumNumberOfLines == other.maximumNumberOfLines
|
||||
&& shadowOpacity == other.shadowOpacity
|
||||
&& shadowRadius == other.shadowRadius
|
||||
&& [pointSizeScaleFactors isEqualToArray:other.pointSizeScaleFactors]
|
||||
&& (pointSizeScaleFactors == other.pointSizeScaleFactors
|
||||
|| [pointSizeScaleFactors isEqualToArray:other.pointSizeScaleFactors])
|
||||
&& CGSizeEqualToSize(shadowOffset, other.shadowOffset)
|
||||
&& ASObjectIsEqual(exclusionPaths, other.exclusionPaths)
|
||||
&& ASObjectIsEqual(avoidTailTruncationSet, other.avoidTailTruncationSet)
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
exclusionPaths:(NSArray *)exclusionPaths
|
||||
constrainedSize:(CGSize)constrainedSize;
|
||||
|
||||
@property (nonatomic, assign, readwrite) CGSize constrainedSize;
|
||||
|
||||
/**
|
||||
All operations on TextKit values MUST occur within this locked context. Simultaneous access (even non-mutative) to
|
||||
TextKit components may cause crashes.
|
||||
|
||||
@@ -54,18 +54,6 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CGSize)constrainedSize
|
||||
{
|
||||
ASDN::MutexSharedLocker l(__instanceLock__);
|
||||
return _textContainer.size;
|
||||
}
|
||||
|
||||
- (void)setConstrainedSize:(CGSize)constrainedSize
|
||||
{
|
||||
ASDN::MutexSharedLocker l(__instanceLock__);
|
||||
_textContainer.size = constrainedSize;
|
||||
}
|
||||
|
||||
- (void)performBlockWithLockedTextKitComponents:(void (^)(NSLayoutManager *,
|
||||
NSTextStorage *,
|
||||
NSTextContainer *))block
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
@property (nonatomic, assign, readonly) ASTextKitAttributes attributes;
|
||||
|
||||
@property (nonatomic, assign, readwrite) CGSize constrainedSize;
|
||||
@property (nonatomic, assign, readonly) CGSize constrainedSize;
|
||||
|
||||
@property (nonatomic, assign, readonly) CGFloat currentScaleFactor;
|
||||
|
||||
|
||||
@@ -116,31 +116,6 @@ static NSCharacterSet *_defaultAvoidTruncationCharacterSet()
|
||||
return _calculatedSize;
|
||||
}
|
||||
|
||||
- (void)setConstrainedSize:(CGSize)constrainedSize
|
||||
{
|
||||
if (!CGSizeEqualToSize(constrainedSize, _constrainedSize)) {
|
||||
_sizeIsCalculated = NO;
|
||||
_constrainedSize = constrainedSize;
|
||||
_calculatedSize = CGSizeZero;
|
||||
|
||||
// Throw away the all subcomponents to create them with the new constrained size new as well as let the
|
||||
// truncater do it's job again for the new constrained size. This is necessary as after a truncation did happen
|
||||
// the context would use the truncated string and not the original string to truncate based on the new
|
||||
// constrained size
|
||||
__block ASTextKitContext *ctx = _context;
|
||||
__block ASTextKitTailTruncater *tru = _truncater;
|
||||
__block ASTextKitFontSizeAdjuster *adj = _fontSizeAdjuster;
|
||||
_context = nil;
|
||||
_truncater = nil;
|
||||
_fontSizeAdjuster = nil;
|
||||
ASPerformBlockOnDeallocationQueue(^{
|
||||
ctx = nil;
|
||||
tru = nil;
|
||||
adj = nil;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_calculateSize
|
||||
{
|
||||
// if we have no scale factors or an unconstrained width, there is no reason to try to adjust the font size
|
||||
|
||||
Reference in New Issue
Block a user