├── .gitignore ├── Podfile ├── Podfile.lock ├── Pods ├── Manifest.lock ├── Pods.xcodeproj │ └── project.pbxproj ├── Target Support Files │ ├── Pods-YYTextSample │ │ ├── Info.plist │ │ ├── Pods-YYTextSample-acknowledgements.markdown │ │ ├── Pods-YYTextSample-acknowledgements.plist │ │ ├── Pods-YYTextSample-dummy.m │ │ ├── Pods-YYTextSample-frameworks.sh │ │ ├── Pods-YYTextSample-resources.sh │ │ ├── Pods-YYTextSample-umbrella.h │ │ ├── Pods-YYTextSample.debug.xcconfig │ │ ├── Pods-YYTextSample.modulemap │ │ └── Pods-YYTextSample.release.xcconfig │ └── YYText │ │ ├── Info.plist │ │ ├── YYText-dummy.m │ │ ├── YYText-prefix.pch │ │ ├── YYText-umbrella.h │ │ ├── YYText.modulemap │ │ └── YYText.xcconfig └── YYText │ ├── LICENSE │ ├── README.md │ └── YYText │ ├── Component │ ├── YYTextContainerView.h │ ├── YYTextContainerView.m │ ├── YYTextDebugOption.h │ ├── YYTextDebugOption.m │ ├── YYTextEffectWindow.h │ ├── YYTextEffectWindow.m │ ├── YYTextInput.h │ ├── YYTextInput.m │ ├── YYTextKeyboardManager.h │ ├── YYTextKeyboardManager.m │ ├── YYTextLayout.h │ ├── YYTextLayout.m │ ├── YYTextLine.h │ ├── YYTextLine.m │ ├── YYTextMagnifier.h │ ├── YYTextMagnifier.m │ ├── YYTextSelectionView.h │ └── YYTextSelectionView.m │ ├── String │ ├── YYTextArchiver.h │ ├── YYTextArchiver.m │ ├── YYTextAttribute.h │ ├── YYTextAttribute.m │ ├── YYTextParser.h │ ├── YYTextParser.m │ ├── YYTextRubyAnnotation.h │ ├── YYTextRubyAnnotation.m │ ├── YYTextRunDelegate.h │ └── YYTextRunDelegate.m │ ├── Utility │ ├── NSAttributedString+YYText.h │ ├── NSAttributedString+YYText.m │ ├── NSParagraphStyle+YYText.h │ ├── NSParagraphStyle+YYText.m │ ├── UIPasteboard+YYText.h │ ├── UIPasteboard+YYText.m │ ├── UIView+YYText.h │ ├── UIView+YYText.m │ ├── YYTextAsyncLayer.h │ ├── YYTextAsyncLayer.m │ ├── YYTextTransaction.h │ ├── YYTextTransaction.m │ ├── YYTextUtilities.h │ ├── YYTextUtilities.m │ ├── YYTextWeakProxy.h │ └── YYTextWeakProxy.m │ ├── YYLabel.h │ ├── YYLabel.m │ ├── YYText.h │ ├── YYTextView.h │ └── YYTextView.m ├── README.md ├── YYTextSample.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── YYTextSample.xcworkspace └── contents.xcworkspacedata ├── YYTextSample ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift ├── YYTextSampleTests ├── Info.plist └── YYTextSampleTests.swift ├── iOS10.png └── iOS9.png /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/ios,swift,xcode,osx 3 | 4 | #!! ERROR: ios is undefined. Use list command to see defined gitignore types !!# 5 | 6 | ### Swift ### 7 | # Xcode 8 | # 9 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 10 | 11 | ## Build generated 12 | build/ 13 | DerivedData/ 14 | 15 | ## Various settings 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | xcuserdata/ 25 | 26 | ## Other 27 | *.moved-aside 28 | *.xcuserstate 29 | 30 | ## Obj-C/Swift specific 31 | *.hmap 32 | *.ipa 33 | *.dSYM.zip 34 | *.dSYM 35 | 36 | ## Playgrounds 37 | timeline.xctimeline 38 | playground.xcworkspace 39 | 40 | # Swift Package Manager 41 | # 42 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 43 | # Packages/ 44 | .build/ 45 | 46 | # CocoaPods 47 | # 48 | # We recommend against adding the Pods directory to your .gitignore. However 49 | # you should judge for yourself, the pros and cons are mentioned at: 50 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 51 | # 52 | # Pods/ 53 | 54 | # Carthage 55 | # 56 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 57 | # Carthage/Checkouts 58 | 59 | Carthage/Build 60 | 61 | # fastlane 62 | # 63 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 64 | # screenshots whenever they are needed. 65 | # For more information about the recommended setup visit: 66 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 67 | 68 | fastlane/report.xml 69 | fastlane/Preview.html 70 | fastlane/screenshots 71 | fastlane/test_output 72 | 73 | 74 | ### Xcode ### 75 | # Xcode 76 | # 77 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 78 | 79 | ## Build generated 80 | build/ 81 | DerivedData/ 82 | 83 | ## Various settings 84 | *.pbxuser 85 | !default.pbxuser 86 | *.mode1v3 87 | !default.mode1v3 88 | *.mode2v3 89 | !default.mode2v3 90 | *.perspectivev3 91 | !default.perspectivev3 92 | xcuserdata/ 93 | 94 | ## Other 95 | *.moved-aside 96 | *.xccheckout 97 | *.xcscmblueprint 98 | 99 | 100 | ### OSX ### 101 | *.DS_Store 102 | .AppleDouble 103 | .LSOverride 104 | 105 | # Icon must end with two \r 106 | Icon 107 | 108 | 109 | # Thumbnails 110 | ._* 111 | 112 | # Files that might appear in the root of a volume 113 | .DocumentRevisions-V100 114 | .fseventsd 115 | .Spotlight-V100 116 | .TemporaryItems 117 | .Trashes 118 | .VolumeIcon.icns 119 | .com.apple.timemachine.donotpresent 120 | 121 | # Directories potentially created on remote AFP share 122 | .AppleDB 123 | .AppleDesktop 124 | Network Trash Folder 125 | Temporary Items 126 | .apdisk 127 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | source 'https://github.com/CocoaPods/Specs.git' 2 | use_frameworks! 3 | platform :ios, '8.0' 4 | 5 | target 'YYTextSample' do 6 | pod 'YYText' 7 | end -------------------------------------------------------------------------------- /Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - YYText (1.0.5) 3 | 4 | DEPENDENCIES: 5 | - YYText 6 | 7 | SPEC CHECKSUMS: 8 | YYText: ac09660c9ccd9b817f409a20caa6f5587444d2ae 9 | 10 | PODFILE CHECKSUM: 0f6a6654ba050031cbe5ce0836037f6e97dfa953 11 | 12 | COCOAPODS: 1.0.1 13 | -------------------------------------------------------------------------------- /Pods/Manifest.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - YYText (1.0.5) 3 | 4 | DEPENDENCIES: 5 | - YYText 6 | 7 | SPEC CHECKSUMS: 8 | YYText: ac09660c9ccd9b817f409a20caa6f5587444d2ae 9 | 10 | PODFILE CHECKSUM: 0f6a6654ba050031cbe5ce0836037f6e97dfa953 11 | 12 | COCOAPODS: 1.0.1 13 | -------------------------------------------------------------------------------- /Pods/Target Support Files/Pods-YYTextSample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Pods/Target Support Files/Pods-YYTextSample/Pods-YYTextSample-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | 4 | ## YYText 5 | 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2015 ibireme 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | 28 | 29 | Generated by CocoaPods - https://cocoapods.org 30 | -------------------------------------------------------------------------------- /Pods/Target Support Files/Pods-YYTextSample/Pods-YYTextSample-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | The MIT License (MIT) 18 | 19 | Copyright (c) 2015 ibireme <ibireme@gmail.com> 20 | 21 | Permission is hereby granted, free of charge, to any person obtaining a copy 22 | of this software and associated documentation files (the "Software"), to deal 23 | in the Software without restriction, including without limitation the rights 24 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 25 | copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all 29 | copies or substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 32 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 33 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 34 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 35 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 36 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 37 | SOFTWARE. 38 | 39 | 40 | Title 41 | YYText 42 | Type 43 | PSGroupSpecifier 44 | 45 | 46 | FooterText 47 | Generated by CocoaPods - https://cocoapods.org 48 | Title 49 | 50 | Type 51 | PSGroupSpecifier 52 | 53 | 54 | StringsTable 55 | Acknowledgements 56 | Title 57 | Acknowledgements 58 | 59 | 60 | -------------------------------------------------------------------------------- /Pods/Target Support Files/Pods-YYTextSample/Pods-YYTextSample-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_YYTextSample : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_YYTextSample 5 | @end 6 | -------------------------------------------------------------------------------- /Pods/Target Support Files/Pods-YYTextSample/Pods-YYTextSample-frameworks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 5 | mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 6 | 7 | SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" 8 | 9 | install_framework() 10 | { 11 | if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then 12 | local source="${BUILT_PRODUCTS_DIR}/$1" 13 | elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then 14 | local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" 15 | elif [ -r "$1" ]; then 16 | local source="$1" 17 | fi 18 | 19 | local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 20 | 21 | if [ -L "${source}" ]; then 22 | echo "Symlinked..." 23 | source="$(readlink "${source}")" 24 | fi 25 | 26 | # use filter instead of exclude so missing patterns dont' throw errors 27 | echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" 28 | rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" 29 | 30 | local basename 31 | basename="$(basename -s .framework "$1")" 32 | binary="${destination}/${basename}.framework/${basename}" 33 | if ! [ -r "$binary" ]; then 34 | binary="${destination}/${basename}" 35 | fi 36 | 37 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 38 | if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then 39 | strip_invalid_archs "$binary" 40 | fi 41 | 42 | # Resign the code if required by the build settings to avoid unstable apps 43 | code_sign_if_enabled "${destination}/$(basename "$1")" 44 | 45 | # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. 46 | if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then 47 | local swift_runtime_libs 48 | swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) 49 | for lib in $swift_runtime_libs; do 50 | echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" 51 | rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" 52 | code_sign_if_enabled "${destination}/${lib}" 53 | done 54 | fi 55 | } 56 | 57 | # Signs a framework with the provided identity 58 | code_sign_if_enabled() { 59 | if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then 60 | # Use the current code_sign_identitiy 61 | echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" 62 | echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements \"$1\"" 63 | /usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements "$1" 64 | fi 65 | } 66 | 67 | # Strip invalid architectures 68 | strip_invalid_archs() { 69 | binary="$1" 70 | # Get architectures for current file 71 | archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)" 72 | stripped="" 73 | for arch in $archs; do 74 | if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then 75 | # Strip non-valid architectures in-place 76 | lipo -remove "$arch" -output "$binary" "$binary" || exit 1 77 | stripped="$stripped $arch" 78 | fi 79 | done 80 | if [[ "$stripped" ]]; then 81 | echo "Stripped $binary of architectures:$stripped" 82 | fi 83 | } 84 | 85 | 86 | if [[ "$CONFIGURATION" == "Debug" ]]; then 87 | install_framework "$BUILT_PRODUCTS_DIR/YYText/YYText.framework" 88 | fi 89 | if [[ "$CONFIGURATION" == "Release" ]]; then 90 | install_framework "$BUILT_PRODUCTS_DIR/YYText/YYText.framework" 91 | fi 92 | -------------------------------------------------------------------------------- /Pods/Target Support Files/Pods-YYTextSample/Pods-YYTextSample-resources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 5 | 6 | RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt 7 | > "$RESOURCES_TO_COPY" 8 | 9 | XCASSET_FILES=() 10 | 11 | case "${TARGETED_DEVICE_FAMILY}" in 12 | 1,2) 13 | TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" 14 | ;; 15 | 1) 16 | TARGET_DEVICE_ARGS="--target-device iphone" 17 | ;; 18 | 2) 19 | TARGET_DEVICE_ARGS="--target-device ipad" 20 | ;; 21 | *) 22 | TARGET_DEVICE_ARGS="--target-device mac" 23 | ;; 24 | esac 25 | 26 | realpath() { 27 | DIRECTORY="$(cd "${1%/*}" && pwd)" 28 | FILENAME="${1##*/}" 29 | echo "$DIRECTORY/$FILENAME" 30 | } 31 | 32 | install_resource() 33 | { 34 | if [[ "$1" = /* ]] ; then 35 | RESOURCE_PATH="$1" 36 | else 37 | RESOURCE_PATH="${PODS_ROOT}/$1" 38 | fi 39 | if [[ ! -e "$RESOURCE_PATH" ]] ; then 40 | cat << EOM 41 | error: Resource "$RESOURCE_PATH" not found. Run 'pod install' to update the copy resources script. 42 | EOM 43 | exit 1 44 | fi 45 | case $RESOURCE_PATH in 46 | *.storyboard) 47 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" 48 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 49 | ;; 50 | *.xib) 51 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" 52 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 53 | ;; 54 | *.framework) 55 | echo "mkdir -p ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 56 | mkdir -p "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 57 | echo "rsync -av $RESOURCE_PATH ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 58 | rsync -av "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 59 | ;; 60 | *.xcdatamodel) 61 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH"`.mom\"" 62 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodel`.mom" 63 | ;; 64 | *.xcdatamodeld) 65 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd\"" 66 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd" 67 | ;; 68 | *.xcmappingmodel) 69 | echo "xcrun mapc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm\"" 70 | xcrun mapc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm" 71 | ;; 72 | *.xcassets) 73 | ABSOLUTE_XCASSET_FILE=$(realpath "$RESOURCE_PATH") 74 | XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE") 75 | ;; 76 | *) 77 | echo "$RESOURCE_PATH" 78 | echo "$RESOURCE_PATH" >> "$RESOURCES_TO_COPY" 79 | ;; 80 | esac 81 | } 82 | 83 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 84 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 85 | if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then 86 | mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 87 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 88 | fi 89 | rm -f "$RESOURCES_TO_COPY" 90 | 91 | if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ] 92 | then 93 | # Find all other xcassets (this unfortunately includes those of path pods and other targets). 94 | OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d) 95 | while read line; do 96 | if [[ $line != "`realpath $PODS_ROOT`*" ]]; then 97 | XCASSET_FILES+=("$line") 98 | fi 99 | done <<<"$OTHER_XCASSETS" 100 | 101 | printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 102 | fi 103 | -------------------------------------------------------------------------------- /Pods/Target Support Files/Pods-YYTextSample/Pods-YYTextSample-umbrella.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | 4 | FOUNDATION_EXPORT double Pods_YYTextSampleVersionNumber; 5 | FOUNDATION_EXPORT const unsigned char Pods_YYTextSampleVersionString[]; 6 | 7 | -------------------------------------------------------------------------------- /Pods/Target Support Files/Pods-YYTextSample/Pods-YYTextSample.debug.xcconfig: -------------------------------------------------------------------------------- 1 | FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/YYText" 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 4 | OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/YYText/YYText.framework/Headers" 5 | OTHER_LDFLAGS = $(inherited) -framework "YYText" 6 | PODS_BUILD_DIR = $BUILD_DIR 7 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 8 | PODS_ROOT = ${SRCROOT}/Pods 9 | -------------------------------------------------------------------------------- /Pods/Target Support Files/Pods-YYTextSample/Pods-YYTextSample.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_YYTextSample { 2 | umbrella header "Pods-YYTextSample-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Pods/Target Support Files/Pods-YYTextSample/Pods-YYTextSample.release.xcconfig: -------------------------------------------------------------------------------- 1 | FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/YYText" 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 4 | OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/YYText/YYText.framework/Headers" 5 | OTHER_LDFLAGS = $(inherited) -framework "YYText" 6 | PODS_BUILD_DIR = $BUILD_DIR 7 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 8 | PODS_ROOT = ${SRCROOT}/Pods 9 | -------------------------------------------------------------------------------- /Pods/Target Support Files/YYText/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.5 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Pods/Target Support Files/YYText/YYText-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_YYText : NSObject 3 | @end 4 | @implementation PodsDummy_YYText 5 | @end 6 | -------------------------------------------------------------------------------- /Pods/Target Support Files/YYText/YYText-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | -------------------------------------------------------------------------------- /Pods/Target Support Files/YYText/YYText-umbrella.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "YYTextContainerView.h" 4 | #import "YYTextDebugOption.h" 5 | #import "YYTextEffectWindow.h" 6 | #import "YYTextInput.h" 7 | #import "YYTextKeyboardManager.h" 8 | #import "YYTextLayout.h" 9 | #import "YYTextLine.h" 10 | #import "YYTextMagnifier.h" 11 | #import "YYTextSelectionView.h" 12 | #import "YYTextArchiver.h" 13 | #import "YYTextAttribute.h" 14 | #import "YYTextParser.h" 15 | #import "YYTextRubyAnnotation.h" 16 | #import "YYTextRunDelegate.h" 17 | #import "NSAttributedString+YYText.h" 18 | #import "NSParagraphStyle+YYText.h" 19 | #import "UIPasteboard+YYText.h" 20 | #import "UIView+YYText.h" 21 | #import "YYTextAsyncLayer.h" 22 | #import "YYTextTransaction.h" 23 | #import "YYTextUtilities.h" 24 | #import "YYTextWeakProxy.h" 25 | #import "YYLabel.h" 26 | #import "YYText.h" 27 | #import "YYTextView.h" 28 | 29 | FOUNDATION_EXPORT double YYTextVersionNumber; 30 | FOUNDATION_EXPORT const unsigned char YYTextVersionString[]; 31 | 32 | -------------------------------------------------------------------------------- /Pods/Target Support Files/YYText/YYText.modulemap: -------------------------------------------------------------------------------- 1 | framework module YYText { 2 | umbrella header "YYText-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Pods/Target Support Files/YYText/YYText.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/YYText 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public" 4 | OTHER_LDFLAGS = -framework "Accelerate" -framework "CoreFoundation" -framework "CoreText" -framework "MobileCoreServices" -framework "QuartzCore" -framework "UIKit" 5 | PODS_BUILD_DIR = $BUILD_DIR 6 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 9 | SKIP_INSTALL = YES 10 | -------------------------------------------------------------------------------- /Pods/YYText/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 ibireme 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextContainerView.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextContainerView.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/21. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | #if __has_include() 15 | #import 16 | #else 17 | #import "YYTextLayout.h" 18 | #endif 19 | 20 | NS_ASSUME_NONNULL_BEGIN 21 | 22 | /** 23 | A simple view to diaplay `YYTextLayout`. 24 | 25 | @discussion This view can become first responder. If this view is first responder, 26 | all the action (such as UIMenu's action) would forward to the `hostView` property. 27 | Typically, you should not use this class directly. 28 | 29 | @warning All the methods in this class should be called on main thread. 30 | */ 31 | @interface YYTextContainerView : UIView 32 | 33 | /// First responder's aciton will forward to this view. 34 | @property (nullable, nonatomic, weak) UIView *hostView; 35 | 36 | /// Debug option for layout debug. Set this property will let the view redraw it's contents. 37 | @property (nullable, nonatomic, copy) YYTextDebugOption *debugOption; 38 | 39 | /// Text vertical alignment. 40 | @property (nonatomic) YYTextVerticalAlignment textVerticalAlignment; 41 | 42 | /// Text layout. Set this property will let the view redraw it's contents. 43 | @property (nullable, nonatomic, strong) YYTextLayout *layout; 44 | 45 | /// The contents fade animation duration when the layout's contents changed. Default is 0 (no animation). 46 | @property (nonatomic) NSTimeInterval contentsFadeDuration; 47 | 48 | /// Convenience method to set `layout` and `contentsFadeDuration`. 49 | /// @param layout Same as `layout` property. 50 | /// @param fadeDuration Same as `contentsFadeDuration` property. 51 | - (void)setLayout:(nullable YYTextLayout *)layout withFadeDuration:(NSTimeInterval)fadeDuration; 52 | 53 | @end 54 | 55 | NS_ASSUME_NONNULL_END 56 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextContainerView.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextContainerView.m 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/21. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYTextContainerView.h" 13 | 14 | @implementation YYTextContainerView { 15 | BOOL _attachmentChanged; 16 | NSMutableArray *_attachmentViews; 17 | NSMutableArray *_attachmentLayers; 18 | } 19 | 20 | - (instancetype)initWithFrame:(CGRect)frame { 21 | self = [super initWithFrame:frame]; 22 | if (!self) return nil; 23 | self.backgroundColor = [UIColor clearColor]; 24 | _attachmentViews = [NSMutableArray array]; 25 | _attachmentLayers = [NSMutableArray array]; 26 | return self; 27 | } 28 | 29 | - (void)setDebugOption:(YYTextDebugOption *)debugOption { 30 | BOOL needDraw = _debugOption.needDrawDebug; 31 | _debugOption = debugOption.copy; 32 | if (_debugOption.needDrawDebug != needDraw) { 33 | [self setNeedsDisplay]; 34 | } 35 | } 36 | 37 | - (void)setTextVerticalAlignment:(YYTextVerticalAlignment)textVerticalAlignment { 38 | if (_textVerticalAlignment == textVerticalAlignment) return; 39 | _textVerticalAlignment = textVerticalAlignment; 40 | [self setNeedsDisplay]; 41 | } 42 | 43 | - (void)setContentsFadeDuration:(NSTimeInterval)contentsFadeDuration { 44 | if (_contentsFadeDuration == contentsFadeDuration) return; 45 | _contentsFadeDuration = contentsFadeDuration; 46 | if (contentsFadeDuration <= 0) { 47 | [self.layer removeAnimationForKey:@"contents"]; 48 | } 49 | } 50 | 51 | - (void)setLayout:(YYTextLayout *)layout { 52 | if (_layout == layout) return; 53 | _layout = layout; 54 | _attachmentChanged = YES; 55 | [self setNeedsDisplay]; 56 | } 57 | 58 | - (void)setLayout:(YYTextLayout *)layout withFadeDuration:(NSTimeInterval)fadeDuration { 59 | self.contentsFadeDuration = fadeDuration; 60 | self.layout = layout; 61 | } 62 | 63 | - (void)drawRect:(CGRect)rect { 64 | // fade content 65 | [self.layer removeAnimationForKey:@"contents"]; 66 | if (_contentsFadeDuration > 0) { 67 | CATransition *transition = [CATransition animation]; 68 | transition.duration = _contentsFadeDuration; 69 | transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 70 | transition.type = kCATransitionFade; 71 | [self.layer addAnimation:transition forKey:@"contents"]; 72 | } 73 | 74 | // update attachment 75 | if (_attachmentChanged) { 76 | for (UIView *view in _attachmentViews) { 77 | if (view.superview == self) [view removeFromSuperview]; 78 | } 79 | for (CALayer *layer in _attachmentLayers) { 80 | if (layer.superlayer == self.layer) [layer removeFromSuperlayer]; 81 | } 82 | [_attachmentViews removeAllObjects]; 83 | [_attachmentLayers removeAllObjects]; 84 | } 85 | 86 | // draw layout 87 | CGSize boundingSize = _layout.textBoundingSize; 88 | CGPoint point = CGPointZero; 89 | if (_textVerticalAlignment == YYTextVerticalAlignmentCenter) { 90 | if (_layout.container.isVerticalForm) { 91 | point.x = -(self.bounds.size.width - boundingSize.width) * 0.5; 92 | } else { 93 | point.y = (self.bounds.size.height - boundingSize.height) * 0.5; 94 | } 95 | } else if (_textVerticalAlignment == YYTextVerticalAlignmentBottom) { 96 | if (_layout.container.isVerticalForm) { 97 | point.x = -(self.bounds.size.width - boundingSize.width); 98 | } else { 99 | point.y = (self.bounds.size.height - boundingSize.height); 100 | } 101 | } 102 | [_layout drawInContext:UIGraphicsGetCurrentContext() size:self.bounds.size point:point view:self layer:self.layer debug:_debugOption cancel:nil]; 103 | 104 | // update attachment 105 | if (_attachmentChanged) { 106 | _attachmentChanged = NO; 107 | for (YYTextAttachment *a in _layout.attachments) { 108 | if ([a.content isKindOfClass:[UIView class]]) [_attachmentViews addObject:a.content]; 109 | if ([a.content isKindOfClass:[CALayer class]]) [_attachmentLayers addObject:a.content]; 110 | } 111 | } 112 | } 113 | 114 | - (void)setFrame:(CGRect)frame { 115 | CGSize oldSize = self.bounds.size; 116 | [super setFrame:frame]; 117 | if (!CGSizeEqualToSize(oldSize, self.bounds.size)) { 118 | [self setNeedsLayout]; 119 | } 120 | } 121 | 122 | - (void)setBounds:(CGRect)bounds { 123 | CGSize oldSize = self.bounds.size; 124 | [super setBounds:bounds]; 125 | if (!CGSizeEqualToSize(oldSize, self.bounds.size)) { 126 | [self setNeedsLayout]; 127 | } 128 | } 129 | 130 | #pragma mark - UIResponder forward 131 | 132 | - (BOOL)canBecomeFirstResponder { 133 | return YES; 134 | } 135 | 136 | - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { 137 | return [self.hostView canPerformAction:action withSender:sender]; 138 | } 139 | 140 | - (id)forwardingTargetForSelector:(SEL)aSelector { 141 | return self.hostView; 142 | } 143 | 144 | @end 145 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextDebugOption.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextDebugOption.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/8. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | @class YYTextDebugOption; 15 | 16 | NS_ASSUME_NONNULL_BEGIN 17 | 18 | /** 19 | The YYTextDebugTarget protocol defines the method a debug target should implement. 20 | A debug target can be add to the global container to receive the shared debug 21 | option changed notification. 22 | */ 23 | @protocol YYTextDebugTarget 24 | 25 | @required 26 | /** 27 | When the shared debug option changed, this method would be called on main thread. 28 | It should return as quickly as possible. The option's property should not be changed 29 | in this method. 30 | 31 | @param option The shared debug option. 32 | */ 33 | - (void)setDebugOption:(nullable YYTextDebugOption *)option; 34 | @end 35 | 36 | 37 | 38 | /** 39 | The debug option for YYText. 40 | */ 41 | @interface YYTextDebugOption : NSObject 42 | @property (nullable, nonatomic, strong) UIColor *baselineColor; ///< baseline color 43 | @property (nullable, nonatomic, strong) UIColor *CTFrameBorderColor; ///< CTFrame path border color 44 | @property (nullable, nonatomic, strong) UIColor *CTFrameFillColor; ///< CTFrame path fill color 45 | @property (nullable, nonatomic, strong) UIColor *CTLineBorderColor; ///< CTLine bounds border color 46 | @property (nullable, nonatomic, strong) UIColor *CTLineFillColor; ///< CTLine bounds fill color 47 | @property (nullable, nonatomic, strong) UIColor *CTLineNumberColor; ///< CTLine line number color 48 | @property (nullable, nonatomic, strong) UIColor *CTRunBorderColor; ///< CTRun bounds border color 49 | @property (nullable, nonatomic, strong) UIColor *CTRunFillColor; ///< CTRun bounds fill color 50 | @property (nullable, nonatomic, strong) UIColor *CTRunNumberColor; ///< CTRun number color 51 | @property (nullable, nonatomic, strong) UIColor *CGGlyphBorderColor; ///< CGGlyph bounds border color 52 | @property (nullable, nonatomic, strong) UIColor *CGGlyphFillColor; ///< CGGlyph bounds fill color 53 | 54 | - (BOOL)needDrawDebug; ///< `YES`: at least one debug color is visible. `NO`: all debug color is invisible/nil. 55 | - (void)clear; ///< Set all debug color to nil. 56 | 57 | /** 58 | Add a debug target. 59 | 60 | @discussion When `setSharedDebugOption:` is called, all added debug target will 61 | receive `setDebugOption:` in main thread. It maintains an unsafe_unretained 62 | reference to this target. The target must to removed before dealloc. 63 | 64 | @param target A debug target. 65 | */ 66 | + (void)addDebugTarget:(id)target; 67 | 68 | /** 69 | Remove a debug target which is added by `addDebugTarget:`. 70 | 71 | @param target A debug target. 72 | */ 73 | + (void)removeDebugTarget:(id)target; 74 | 75 | /** 76 | Returns the shared debug option. 77 | 78 | @return The shared debug option, default is nil. 79 | */ 80 | + (nullable YYTextDebugOption *)sharedDebugOption; 81 | 82 | /** 83 | Set a debug option as shared debug option. 84 | This method must be called on main thread. 85 | 86 | @discussion When call this method, the new option will set to all debug target 87 | which is added by `addDebugTarget:`. 88 | 89 | @param option A new debug option (nil is valid). 90 | */ 91 | + (void)setSharedDebugOption:(nullable YYTextDebugOption *)option; 92 | 93 | @end 94 | 95 | NS_ASSUME_NONNULL_END 96 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextDebugOption.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextDebugOption.m 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/8. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYTextDebugOption.h" 13 | #import "YYTextWeakProxy.h" 14 | #import 15 | #import 16 | 17 | static pthread_mutex_t _sharedDebugLock; 18 | static CFMutableSetRef _sharedDebugTargets = nil; 19 | static YYTextDebugOption *_sharedDebugOption = nil; 20 | 21 | static const void* _sharedDebugSetRetain(CFAllocatorRef allocator, const void *value) { 22 | return value; 23 | } 24 | 25 | static void _sharedDebugSetRelease(CFAllocatorRef allocator, const void *value) { 26 | } 27 | 28 | void _sharedDebugSetFunction(const void *value, void *context) { 29 | id target = (__bridge id)(value); 30 | [target setDebugOption:_sharedDebugOption]; 31 | } 32 | 33 | static void _initSharedDebug() { 34 | static dispatch_once_t onceToken; 35 | dispatch_once(&onceToken, ^{ 36 | pthread_mutex_init(&_sharedDebugLock, NULL); 37 | CFSetCallBacks callbacks = kCFTypeSetCallBacks; 38 | callbacks.retain = _sharedDebugSetRetain; 39 | callbacks.release = _sharedDebugSetRelease; 40 | _sharedDebugTargets = CFSetCreateMutable(CFAllocatorGetDefault(), 0, &callbacks); 41 | }); 42 | } 43 | 44 | static void _setSharedDebugOption(YYTextDebugOption *option) { 45 | _initSharedDebug(); 46 | pthread_mutex_lock(&_sharedDebugLock); 47 | _sharedDebugOption = option.copy; 48 | CFSetApplyFunction(_sharedDebugTargets, _sharedDebugSetFunction, NULL); 49 | pthread_mutex_unlock(&_sharedDebugLock); 50 | } 51 | 52 | static YYTextDebugOption *_getSharedDebugOption() { 53 | _initSharedDebug(); 54 | pthread_mutex_lock(&_sharedDebugLock); 55 | YYTextDebugOption *op = _sharedDebugOption; 56 | pthread_mutex_unlock(&_sharedDebugLock); 57 | return op; 58 | } 59 | 60 | static void _addDebugTarget(id target) { 61 | _initSharedDebug(); 62 | pthread_mutex_lock(&_sharedDebugLock); 63 | CFSetAddValue(_sharedDebugTargets, (__bridge const void *)(target)); 64 | pthread_mutex_unlock(&_sharedDebugLock); 65 | } 66 | 67 | static void _removeDebugTarget(id target) { 68 | _initSharedDebug(); 69 | pthread_mutex_lock(&_sharedDebugLock); 70 | CFSetRemoveValue(_sharedDebugTargets, (__bridge const void *)(target)); 71 | pthread_mutex_unlock(&_sharedDebugLock); 72 | } 73 | 74 | 75 | @implementation YYTextDebugOption 76 | 77 | - (id)copyWithZone:(NSZone *)zone { 78 | YYTextDebugOption *op = [self.class new]; 79 | op.baselineColor = self.baselineColor; 80 | op.CTFrameBorderColor = self.CTFrameBorderColor; 81 | op.CTFrameFillColor = self.CTFrameFillColor; 82 | op.CTLineBorderColor = self.CTLineBorderColor; 83 | op.CTLineFillColor = self.CTLineFillColor; 84 | op.CTLineNumberColor = self.CTLineNumberColor; 85 | op.CTRunBorderColor = self.CTRunBorderColor; 86 | op.CTRunFillColor = self.CTRunFillColor; 87 | op.CTRunNumberColor = self.CTRunNumberColor; 88 | op.CGGlyphBorderColor = self.CGGlyphBorderColor; 89 | op.CGGlyphFillColor = self.CGGlyphFillColor; 90 | return op; 91 | } 92 | 93 | - (BOOL)needDrawDebug { 94 | if (self.baselineColor || 95 | self.CTFrameBorderColor || 96 | self.CTFrameFillColor || 97 | self.CTLineBorderColor || 98 | self.CTLineFillColor || 99 | self.CTLineNumberColor || 100 | self.CTRunBorderColor || 101 | self.CTRunFillColor || 102 | self.CTRunNumberColor || 103 | self.CGGlyphBorderColor || 104 | self.CGGlyphFillColor) return YES; 105 | return NO; 106 | } 107 | 108 | - (void)clear { 109 | self.baselineColor = nil; 110 | self.CTFrameBorderColor = nil; 111 | self.CTFrameFillColor = nil; 112 | self.CTLineBorderColor = nil; 113 | self.CTLineFillColor = nil; 114 | self.CTLineNumberColor = nil; 115 | self.CTRunBorderColor = nil; 116 | self.CTRunFillColor = nil; 117 | self.CTRunNumberColor = nil; 118 | self.CGGlyphBorderColor = nil; 119 | self.CGGlyphFillColor = nil; 120 | } 121 | 122 | + (void)addDebugTarget:(id)target { 123 | if (target) _addDebugTarget(target); 124 | } 125 | 126 | + (void)removeDebugTarget:(id)target { 127 | if (target) _removeDebugTarget(target); 128 | } 129 | 130 | + (YYTextDebugOption *)sharedDebugOption { 131 | return _getSharedDebugOption(); 132 | } 133 | 134 | + (void)setSharedDebugOption:(YYTextDebugOption *)option { 135 | NSAssert([NSThread isMainThread], @"This method must be called on the main thread"); 136 | _setSharedDebugOption(option); 137 | } 138 | 139 | @end 140 | 141 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextEffectWindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextEffectWindow.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/2/25. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | #if __has_include() 15 | #import 16 | #import 17 | #else 18 | #import "YYTextMagnifier.h" 19 | #import "YYTextSelectionView.h" 20 | #endif 21 | 22 | NS_ASSUME_NONNULL_BEGIN 23 | 24 | /** 25 | A window to display magnifier and extra contents for text view. 26 | 27 | @discussion Use `sharedWindow` to get the instance, don't create your own instance. 28 | Typically, you should not use this class directly. 29 | */ 30 | @interface YYTextEffectWindow : UIWindow 31 | 32 | /// Returns the shared instance (returns nil in App Extension). 33 | + (nullable instancetype)sharedWindow; 34 | 35 | /// Show the magnifier in this window with a 'popup' animation. @param mag A magnifier. 36 | - (void)showMagnifier:(YYTextMagnifier *)mag; 37 | /// Update the magnifier content and position. @param mag A magnifier. 38 | - (void)moveMagnifier:(YYTextMagnifier *)mag; 39 | /// Remove the magnifier from this window with a 'shrink' animation. @param mag A magnifier. 40 | - (void)hideMagnifier:(YYTextMagnifier *)mag; 41 | 42 | 43 | /// Show the selection dot in this window if the dot is clipped by the selection view. 44 | /// @param selection A selection view. 45 | - (void)showSelectionDot:(YYTextSelectionView *)selection; 46 | /// Remove the selection dot from this window. 47 | /// @param selection A selection view. 48 | - (void)hideSelectionDot:(YYTextSelectionView *)selection; 49 | 50 | @end 51 | 52 | NS_ASSUME_NONNULL_END 53 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextInput.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextInput.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/17. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | /** 17 | Text position affinity. For example, the offset appears after the last 18 | character on a line is backward affinity, before the first character on 19 | the following line is forward affinity. 20 | */ 21 | typedef NS_ENUM(NSInteger, YYTextAffinity) { 22 | YYTextAffinityForward = 0, ///< offset appears before the character 23 | YYTextAffinityBackward = 1, ///< offset appears after the character 24 | }; 25 | 26 | 27 | /** 28 | A YYTextPosition object represents a position in a text container; in other words, 29 | it is an index into the backing string in a text-displaying view. 30 | 31 | YYTextPosition has the same API as Apple's implementation in UITextView/UITextField, 32 | so you can alse use it to interact with UITextView/UITextField. 33 | */ 34 | @interface YYTextPosition : UITextPosition 35 | 36 | @property (nonatomic, readonly) NSInteger offset; 37 | @property (nonatomic, readonly) YYTextAffinity affinity; 38 | 39 | + (instancetype)positionWithOffset:(NSInteger)offset; 40 | + (instancetype)positionWithOffset:(NSInteger)offset affinity:(YYTextAffinity) affinity; 41 | 42 | - (NSComparisonResult)compare:(id)otherPosition; 43 | 44 | @end 45 | 46 | 47 | /** 48 | A YYTextRange object represents a range of characters in a text container; in other words, 49 | it identifies a starting index and an ending index in string backing a text-displaying view. 50 | 51 | YYTextRange has the same API as Apple's implementation in UITextView/UITextField, 52 | so you can alse use it to interact with UITextView/UITextField. 53 | */ 54 | @interface YYTextRange : UITextRange 55 | 56 | @property (nonatomic, readonly) YYTextPosition *start; 57 | @property (nonatomic, readonly) YYTextPosition *end; 58 | @property (nonatomic, readonly, getter=isEmpty) BOOL empty; 59 | 60 | + (instancetype)rangeWithRange:(NSRange)range; 61 | + (instancetype)rangeWithRange:(NSRange)range affinity:(YYTextAffinity) affinity; 62 | + (instancetype)rangeWithStart:(YYTextPosition *)start end:(YYTextPosition *)end; 63 | + (instancetype)defaultRange; ///< <{0,0} Forward> 64 | 65 | - (NSRange)asRange; 66 | 67 | @end 68 | 69 | 70 | /** 71 | A YYTextSelectionRect object encapsulates information about a selected range of 72 | text in a text-displaying view. 73 | 74 | YYTextSelectionRect has the same API as Apple's implementation in UITextView/UITextField, 75 | so you can alse use it to interact with UITextView/UITextField. 76 | */ 77 | @interface YYTextSelectionRect : UITextSelectionRect 78 | 79 | @property (nonatomic, readwrite) CGRect rect; 80 | @property (nonatomic, readwrite) UITextWritingDirection writingDirection; 81 | @property (nonatomic, readwrite) BOOL containsStart; 82 | @property (nonatomic, readwrite) BOOL containsEnd; 83 | @property (nonatomic, readwrite) BOOL isVertical; 84 | 85 | @end 86 | 87 | NS_ASSUME_NONNULL_END 88 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextInput.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextInput.m 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/17. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYTextInput.h" 13 | #import "YYTextUtilities.h" 14 | 15 | 16 | @implementation YYTextPosition 17 | 18 | + (instancetype)positionWithOffset:(NSInteger)offset { 19 | return [self positionWithOffset:offset affinity:YYTextAffinityForward]; 20 | } 21 | 22 | + (instancetype)positionWithOffset:(NSInteger)offset affinity:(YYTextAffinity)affinity { 23 | YYTextPosition *p = [self new]; 24 | p->_offset = offset; 25 | p->_affinity = affinity; 26 | return p; 27 | } 28 | 29 | - (instancetype)copyWithZone:(NSZone *)zone { 30 | return [self.class positionWithOffset:_offset affinity:_affinity]; 31 | } 32 | 33 | - (NSString *)description { 34 | return [NSString stringWithFormat:@"<%@: %p> (%@%@)", self.class, self, @(_offset), _affinity == YYTextAffinityForward ? @"F":@"B"]; 35 | } 36 | 37 | - (NSUInteger)hash { 38 | return _offset * 2 + (_affinity == YYTextAffinityForward ? 1 : 0); 39 | } 40 | 41 | - (BOOL)isEqual:(YYTextPosition *)object { 42 | if (!object) return NO; 43 | return _offset == object.offset && _affinity == object.affinity; 44 | } 45 | 46 | - (NSComparisonResult)compare:(YYTextPosition *)otherPosition { 47 | if (!otherPosition) return NSOrderedAscending; 48 | if (_offset < otherPosition.offset) return NSOrderedAscending; 49 | if (_offset > otherPosition.offset) return NSOrderedDescending; 50 | if (_affinity == YYTextAffinityBackward && otherPosition.affinity == YYTextAffinityForward) return NSOrderedAscending; 51 | if (_affinity == YYTextAffinityForward && otherPosition.affinity == YYTextAffinityBackward) return NSOrderedDescending; 52 | return NSOrderedSame; 53 | } 54 | 55 | @end 56 | 57 | 58 | 59 | @implementation YYTextRange { 60 | YYTextPosition *_start; 61 | YYTextPosition *_end; 62 | } 63 | 64 | - (instancetype)init { 65 | self = [super init]; 66 | if (!self) return nil; 67 | _start = [YYTextPosition positionWithOffset:0]; 68 | _end = [YYTextPosition positionWithOffset:0]; 69 | return self; 70 | } 71 | 72 | - (YYTextPosition *)start { 73 | return _start; 74 | } 75 | 76 | - (YYTextPosition *)end { 77 | return _end; 78 | } 79 | 80 | - (BOOL)isEmpty { 81 | return _start.offset == _end.offset; 82 | } 83 | 84 | - (NSRange)asRange { 85 | return NSMakeRange(_start.offset, _end.offset - _start.offset); 86 | } 87 | 88 | + (instancetype)rangeWithRange:(NSRange)range { 89 | return [self rangeWithRange:range affinity:YYTextAffinityForward]; 90 | } 91 | 92 | + (instancetype)rangeWithRange:(NSRange)range affinity:(YYTextAffinity)affinity { 93 | YYTextPosition *start = [YYTextPosition positionWithOffset:range.location affinity:affinity]; 94 | YYTextPosition *end = [YYTextPosition positionWithOffset:range.location + range.length affinity:affinity]; 95 | return [self rangeWithStart:start end:end]; 96 | } 97 | 98 | + (instancetype)rangeWithStart:(YYTextPosition *)start end:(YYTextPosition *)end { 99 | if (!start || !end) return nil; 100 | if ([start compare:end] == NSOrderedDescending) { 101 | YYTEXT_SWAP(start, end); 102 | } 103 | YYTextRange *range = [YYTextRange new]; 104 | range->_start = start; 105 | range->_end = end; 106 | return range; 107 | } 108 | 109 | + (instancetype)defaultRange { 110 | return [self new]; 111 | } 112 | 113 | - (instancetype)copyWithZone:(NSZone *)zone { 114 | return [self.class rangeWithStart:_start end:_end]; 115 | } 116 | 117 | - (NSString *)description { 118 | return [NSString stringWithFormat:@"<%@: %p> (%@, %@)%@", self.class, self, @(_start.offset), @(_end.offset - _start.offset), _end.affinity == YYTextAffinityForward ? @"F":@"B"]; 119 | } 120 | 121 | - (NSUInteger)hash { 122 | return (sizeof(NSUInteger) == 8 ? OSSwapInt64(_start.hash) : OSSwapInt32(_start.hash)) + _end.hash; 123 | } 124 | 125 | - (BOOL)isEqual:(YYTextRange *)object { 126 | if (!object) return NO; 127 | return [_start isEqual:object.start] && [_end isEqual:object.end]; 128 | } 129 | 130 | @end 131 | 132 | 133 | 134 | @implementation YYTextSelectionRect 135 | 136 | @synthesize rect = _rect; 137 | @synthesize writingDirection = _writingDirection; 138 | @synthesize containsStart = _containsStart; 139 | @synthesize containsEnd = _containsEnd; 140 | @synthesize isVertical = _isVertical; 141 | 142 | - (id)copyWithZone:(NSZone *)zone { 143 | YYTextSelectionRect *one = [self.class new]; 144 | one.rect = _rect; 145 | one.writingDirection = _writingDirection; 146 | one.containsStart = _containsStart; 147 | one.containsEnd = _containsEnd; 148 | one.isVertical = _isVertical; 149 | return one; 150 | } 151 | 152 | @end 153 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextKeyboardManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextKeyboardManager.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/6/3. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | /** 17 | System keyboard transition information. 18 | Use -[YYTextKeyboardManager convertRect:toView:] to convert frame to specified view. 19 | */ 20 | typedef struct { 21 | BOOL fromVisible; ///< Keyboard visible before transition. 22 | BOOL toVisible; ///< Keyboard visible after transition. 23 | CGRect fromFrame; ///< Keyboard frame before transition. 24 | CGRect toFrame; ///< Keyboard frame after transition. 25 | NSTimeInterval animationDuration; ///< Keyboard transition animation duration. 26 | UIViewAnimationCurve animationCurve; ///< Keyboard transition animation curve. 27 | UIViewAnimationOptions animationOption; ///< Keybaord transition animation option. 28 | } YYTextKeyboardTransition; 29 | 30 | 31 | /** 32 | The YYTextKeyboardObserver protocol defines the method you can use 33 | to receive system keyboard change information. 34 | */ 35 | @protocol YYTextKeyboardObserver 36 | @optional 37 | - (void)keyboardChangedWithTransition:(YYTextKeyboardTransition)transition; 38 | @end 39 | 40 | 41 | /** 42 | A YYTextKeyboardManager object lets you get the system keyboard information, 43 | and track the keyboard visible/frame/transition. 44 | 45 | @discussion You should access this class in main thread. 46 | Compatible: iPhone/iPad with iOS6/7/8/9. 47 | */ 48 | @interface YYTextKeyboardManager : NSObject 49 | 50 | - (instancetype)init UNAVAILABLE_ATTRIBUTE; 51 | + (instancetype)new UNAVAILABLE_ATTRIBUTE; 52 | 53 | /// Get the default manager (returns nil in App Extension). 54 | + (nullable instancetype)defaultManager; 55 | 56 | /// Get the keyboard window. nil if there's no keyboard window. 57 | @property (nullable, nonatomic, readonly) UIWindow *keyboardWindow; 58 | 59 | /// Get the keyboard view. nil if there's no keyboard view. 60 | @property (nullable, nonatomic, readonly) UIView *keyboardView; 61 | 62 | /// Whether the keyboard is visible. 63 | @property (nonatomic, readonly, getter=isKeyboardVisible) BOOL keyboardVisible; 64 | 65 | /// Get the keyboard frame. CGRectNull if there's no keyboard view. 66 | /// Use convertRect:toView: to convert frame to specified view. 67 | @property (nonatomic, readonly) CGRect keyboardFrame; 68 | 69 | 70 | /** 71 | Add an observer to manager to get keyboard change information. 72 | This method makes a weak reference to the observer. 73 | 74 | @param observer An observer. 75 | This method will do nothing if the observer is nil, or already added. 76 | */ 77 | - (void)addObserver:(id)observer; 78 | 79 | /** 80 | Remove an observer from manager. 81 | 82 | @param observer An observer. 83 | This method will do nothing if the observer is nil, or not in manager. 84 | */ 85 | - (void)removeObserver:(id)observer; 86 | 87 | /** 88 | Convert rect to specified view or window. 89 | 90 | @param rect The frame rect. 91 | @param view A specified view or window (pass nil to convert for main window). 92 | @return The converted rect in specifeid view. 93 | */ 94 | - (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view; 95 | 96 | @end 97 | 98 | NS_ASSUME_NONNULL_END 99 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextLine.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextLine.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/3/10. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | #import 14 | 15 | #if __has_include() 16 | #import 17 | #else 18 | #import "YYTextAttribute.h" 19 | #endif 20 | 21 | @class YYTextRunGlyphRange; 22 | 23 | NS_ASSUME_NONNULL_BEGIN 24 | 25 | /** 26 | A text line object wrapped `CTLineRef`, see `YYTextLayout` for more. 27 | */ 28 | @interface YYTextLine : NSObject 29 | 30 | + (instancetype)lineWithCTLine:(CTLineRef)CTLine position:(CGPoint)position vertical:(BOOL)isVertical; 31 | 32 | @property (nonatomic) NSUInteger index; ///< line index 33 | @property (nonatomic) NSUInteger row; ///< line row 34 | @property (nullable, nonatomic, strong) NSArray *> *verticalRotateRange; ///< Run rotate range 35 | 36 | @property (nonatomic, readonly) CTLineRef CTLine; ///< CoreText line 37 | @property (nonatomic, readonly) NSRange range; ///< string range 38 | @property (nonatomic, readonly) BOOL vertical; ///< vertical form 39 | 40 | @property (nonatomic, readonly) CGRect bounds; ///< bounds (ascent + descent) 41 | @property (nonatomic, readonly) CGSize size; ///< bounds.size 42 | @property (nonatomic, readonly) CGFloat width; ///< bounds.size.width 43 | @property (nonatomic, readonly) CGFloat height; ///< bounds.size.height 44 | @property (nonatomic, readonly) CGFloat top; ///< bounds.origin.y 45 | @property (nonatomic, readonly) CGFloat bottom; ///< bounds.origin.y + bounds.size.height 46 | @property (nonatomic, readonly) CGFloat left; ///< bounds.origin.x 47 | @property (nonatomic, readonly) CGFloat right; ///< bounds.origin.x + bounds.size.width 48 | 49 | @property (nonatomic) CGPoint position; ///< baseline position 50 | @property (nonatomic, readonly) CGFloat ascent; ///< line ascent 51 | @property (nonatomic, readonly) CGFloat descent; ///< line descent 52 | @property (nonatomic, readonly) CGFloat leading; ///< line leading 53 | @property (nonatomic, readonly) CGFloat lineWidth; ///< line width 54 | @property (nonatomic, readonly) CGFloat trailingWhitespaceWidth; 55 | 56 | @property (nonatomic, readonly) NSArray *attachments; ///< YYTextAttachment 57 | @property (nonatomic, readonly) NSArray *attachmentRanges; ///< NSRange(NSValue) 58 | @property (nonatomic, readonly) NSArray *attachmentRects; ///< CGRect(NSValue) 59 | 60 | @end 61 | 62 | 63 | typedef NS_ENUM(NSUInteger, YYTextRunGlyphDrawMode) { 64 | /// No rotate. 65 | YYTextRunGlyphDrawModeHorizontal = 0, 66 | 67 | /// Rotate vertical for single glyph. 68 | YYTextRunGlyphDrawModeVerticalRotate = 1, 69 | 70 | /// Rotate vertical for single glyph, and move the glyph to a better position, 71 | /// such as fullwidth punctuation. 72 | YYTextRunGlyphDrawModeVerticalRotateMove = 2, 73 | }; 74 | 75 | /** 76 | A range in CTRun, used for vertical form. 77 | */ 78 | @interface YYTextRunGlyphRange : NSObject 79 | @property (nonatomic) NSRange glyphRangeInRun; 80 | @property (nonatomic) YYTextRunGlyphDrawMode drawMode; 81 | + (instancetype)rangeWithRange:(NSRange)range drawMode:(YYTextRunGlyphDrawMode)mode; 82 | @end 83 | 84 | NS_ASSUME_NONNULL_END 85 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextLine.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYYTextLine.m 3 | // YYText 4 | // 5 | // Created by ibireme on 15/3/3. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYTextLine.h" 13 | #import "YYTextUtilities.h" 14 | 15 | 16 | @implementation YYTextLine { 17 | CGFloat _firstGlyphPos; // first glyph position for baseline, typically 0. 18 | } 19 | 20 | + (instancetype)lineWithCTLine:(CTLineRef)CTLine position:(CGPoint)position vertical:(BOOL)isVertical { 21 | if (!CTLine) return nil; 22 | YYTextLine *line = [self new]; 23 | line->_position = position; 24 | line->_vertical = isVertical; 25 | [line setCTLine:CTLine]; 26 | return line; 27 | } 28 | 29 | - (void)dealloc { 30 | if (_CTLine) CFRelease(_CTLine); 31 | } 32 | 33 | - (void)setCTLine:(CTLineRef)CTLine { 34 | if (_CTLine != CTLine) { 35 | if (CTLine) CFRetain(CTLine); 36 | if (_CTLine) CFRelease(_CTLine); 37 | _CTLine = CTLine; 38 | if (_CTLine) { 39 | _lineWidth = CTLineGetTypographicBounds(_CTLine, &_ascent, &_descent, &_leading); 40 | CFRange range = CTLineGetStringRange(_CTLine); 41 | _range = NSMakeRange(range.location, range.length); 42 | if (CTLineGetGlyphCount(_CTLine) > 0) { 43 | CFArrayRef runs = CTLineGetGlyphRuns(_CTLine); 44 | CTRunRef run = CFArrayGetValueAtIndex(runs, 0); 45 | CGPoint pos; 46 | CTRunGetPositions(run, CFRangeMake(0, 1), &pos); 47 | _firstGlyphPos = pos.x; 48 | } else { 49 | _firstGlyphPos = 0; 50 | } 51 | _trailingWhitespaceWidth = CTLineGetTrailingWhitespaceWidth(_CTLine); 52 | } else { 53 | _lineWidth = _ascent = _descent = _leading = _firstGlyphPos = _trailingWhitespaceWidth = 0; 54 | _range = NSMakeRange(0, 0); 55 | } 56 | [self reloadBounds]; 57 | } 58 | } 59 | 60 | - (void)setPosition:(CGPoint)position { 61 | _position = position; 62 | [self reloadBounds]; 63 | } 64 | 65 | - (void)reloadBounds { 66 | if (_vertical) { 67 | _bounds = CGRectMake(_position.x - _descent, _position.y, _ascent + _descent, _lineWidth); 68 | _bounds.origin.y += _firstGlyphPos; 69 | } else { 70 | _bounds = CGRectMake(_position.x, _position.y - _ascent, _lineWidth, _ascent + _descent); 71 | _bounds.origin.x += _firstGlyphPos; 72 | } 73 | 74 | _attachments = nil; 75 | _attachmentRanges = nil; 76 | _attachmentRects = nil; 77 | if (!_CTLine) return; 78 | CFArrayRef runs = CTLineGetGlyphRuns(_CTLine); 79 | NSUInteger runCount = CFArrayGetCount(runs); 80 | if (runCount == 0) return; 81 | 82 | NSMutableArray *attachments = [NSMutableArray new]; 83 | NSMutableArray *attachmentRanges = [NSMutableArray new]; 84 | NSMutableArray *attachmentRects = [NSMutableArray new]; 85 | for (NSUInteger r = 0; r < runCount; r++) { 86 | CTRunRef run = CFArrayGetValueAtIndex(runs, r); 87 | CFIndex glyphCount = CTRunGetGlyphCount(run); 88 | if (glyphCount == 0) continue; 89 | NSDictionary *attrs = (id)CTRunGetAttributes(run); 90 | YYTextAttachment *attachment = attrs[YYTextAttachmentAttributeName]; 91 | if (attachment) { 92 | CGPoint runPosition = CGPointZero; 93 | CTRunGetPositions(run, CFRangeMake(0, 1), &runPosition); 94 | 95 | CGFloat ascent, descent, leading, runWidth; 96 | CGRect runTypoBounds; 97 | runWidth = CTRunGetTypographicBounds(run, CFRangeMake(0, 0), &ascent, &descent, &leading); 98 | 99 | if (_vertical) { 100 | YYTEXT_SWAP(runPosition.x, runPosition.y); 101 | runPosition.y = _position.y + runPosition.y; 102 | runTypoBounds = CGRectMake(_position.x + runPosition.x - descent, runPosition.y , ascent + descent, runWidth); 103 | } else { 104 | runPosition.x += _position.x; 105 | runPosition.y = _position.y - runPosition.y; 106 | runTypoBounds = CGRectMake(runPosition.x, runPosition.y - ascent, runWidth, ascent + descent); 107 | } 108 | 109 | NSRange runRange = YYTextNSRangeFromCFRange(CTRunGetStringRange(run)); 110 | [attachments addObject:attachment]; 111 | [attachmentRanges addObject:[NSValue valueWithRange:runRange]]; 112 | [attachmentRects addObject:[NSValue valueWithCGRect:runTypoBounds]]; 113 | } 114 | } 115 | _attachments = attachments.count ? attachments : nil; 116 | _attachmentRanges = attachmentRanges.count ? attachmentRanges : nil; 117 | _attachmentRects = attachmentRects.count ? attachmentRects : nil; 118 | } 119 | 120 | - (CGSize)size { 121 | return _bounds.size; 122 | } 123 | 124 | - (CGFloat)width { 125 | return CGRectGetWidth(_bounds); 126 | } 127 | 128 | - (CGFloat)height { 129 | return CGRectGetHeight(_bounds); 130 | } 131 | 132 | - (CGFloat)top { 133 | return CGRectGetMinY(_bounds); 134 | } 135 | 136 | - (CGFloat)bottom { 137 | return CGRectGetMaxY(_bounds); 138 | } 139 | 140 | - (CGFloat)left { 141 | return CGRectGetMinX(_bounds); 142 | } 143 | 144 | - (CGFloat)right { 145 | return CGRectGetMaxX(_bounds); 146 | } 147 | 148 | - (NSString *)description { 149 | NSMutableString *desc = @"".mutableCopy; 150 | NSRange range = self.range; 151 | [desc appendFormat:@" row:%zd range:%tu,%tu",self, self.row, range.location, range.length]; 152 | [desc appendFormat:@" position:%@",NSStringFromCGPoint(self.position)]; 153 | [desc appendFormat:@" bounds:%@",NSStringFromCGRect(self.bounds)]; 154 | return desc; 155 | } 156 | 157 | @end 158 | 159 | 160 | @implementation YYTextRunGlyphRange 161 | + (instancetype)rangeWithRange:(NSRange)range drawMode:(YYTextRunGlyphDrawMode)mode { 162 | YYTextRunGlyphRange *one = [self new]; 163 | one.glyphRangeInRun = range; 164 | one.drawMode = mode; 165 | return one; 166 | } 167 | @end 168 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextMagnifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextMagnifier.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/2/25. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | #if __has_include() 15 | #import 16 | #else 17 | #import "YYTextAttribute.h" 18 | #endif 19 | 20 | NS_ASSUME_NONNULL_BEGIN 21 | 22 | /// Magnifier type 23 | typedef NS_ENUM(NSInteger, YYTextMagnifierType) { 24 | YYTextMagnifierTypeCaret, ///< Circular magnifier 25 | YYTextMagnifierTypeRanged, ///< Round rectangle magnifier 26 | }; 27 | 28 | /** 29 | A magnifier view which can be displayed in `YYTextEffectWindow`. 30 | 31 | @discussion Use `magnifierWithType:` to create instance. 32 | Typically, you should not use this class directly. 33 | */ 34 | @interface YYTextMagnifier : UIView 35 | 36 | /// Create a mangifier with the specified type. @param type The magnifier type. 37 | + (id)magnifierWithType:(YYTextMagnifierType)type; 38 | 39 | @property (nonatomic, readonly) YYTextMagnifierType type; ///< Type of magnifier 40 | @property (nonatomic, readonly) CGSize fitSize; ///< The 'best' size for magnifier view. 41 | @property (nonatomic, readonly) CGSize snapshotSize; ///< The 'best' snapshot image size for magnifier. 42 | @property (nullable, nonatomic, strong) UIImage *snapshot; ///< The image in magnifier (readwrite). 43 | 44 | @property (nullable, nonatomic, weak) UIView *hostView; ///< The coordinate based view. 45 | @property (nonatomic) CGPoint hostCaptureCenter; ///< The snapshot capture center in `hostView`. 46 | @property (nonatomic) CGPoint hostPopoverCenter; ///< The popover center in `hostView`. 47 | @property (nonatomic) BOOL hostVerticalForm; ///< The host view is vertical form. 48 | @property (nonatomic) BOOL captureDisabled; ///< A hint for `YYTextEffectWindow` to disable capture. 49 | @property (nonatomic) BOOL captureFadeAnimation; ///< Show fade animation when the snapshot image changed. 50 | @end 51 | 52 | NS_ASSUME_NONNULL_END 53 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextMagnifier.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextMagnifier.m 3 | // YYText 4 | // 5 | // Created by ibireme on 15/2/25. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYTextMagnifier.h" 13 | #import "YYTextUtilities.h" 14 | 15 | #define kCaptureDisableFadeTime 0.1 16 | 17 | 18 | @interface _YYTextMagnifierCaret : YYTextMagnifier { 19 | UIImageView *_contentView; 20 | UIImageView *_coverView; 21 | } 22 | @end 23 | 24 | @implementation _YYTextMagnifierCaret 25 | 26 | #define kMultiple 1.2 27 | #define kDiameter 113.0 28 | #define kPadding 7.0 29 | #define kSize CGSizeMake(kDiameter + kPadding * 2, kDiameter + kPadding * 2) 30 | 31 | - (instancetype)initWithFrame:(CGRect)frame { 32 | self = [super initWithFrame:frame]; 33 | _contentView = [UIImageView new]; 34 | _contentView.frame = CGRectMake(kPadding, kPadding, kDiameter, kDiameter); 35 | _contentView.layer.cornerRadius = kDiameter / 2; 36 | _contentView.clipsToBounds = YES; 37 | [self addSubview:_contentView]; 38 | 39 | _coverView = [UIImageView new]; 40 | _coverView.frame = (CGRect){.origin = CGPointZero, .size = kSize}; 41 | _coverView.image = [self.class coverImage]; 42 | [self addSubview:_coverView]; 43 | return self; 44 | } 45 | 46 | - (instancetype)init { 47 | self = [self initWithFrame:CGRectZero]; 48 | self.frame = (CGRect){.size = [self sizeThatFits:CGSizeZero]}; 49 | return self; 50 | } 51 | 52 | - (YYTextMagnifierType)type { 53 | return YYTextMagnifierTypeCaret; 54 | } 55 | 56 | - (CGSize)sizeThatFits:(CGSize)size { 57 | return kSize; 58 | } 59 | 60 | - (void)setSnapshot:(UIImage *)snapshot { 61 | if (self.captureFadeAnimation) { 62 | [_contentView.layer removeAnimationForKey:@"contents"]; 63 | CABasicAnimation *animation = [CABasicAnimation animation]; 64 | animation.duration = kCaptureDisableFadeTime; 65 | animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 66 | [_contentView.layer addAnimation:animation forKey:@"contents"]; 67 | } 68 | _contentView.image = snapshot; 69 | } 70 | 71 | - (UIImage *)snapshot { 72 | return _contentView.image; 73 | } 74 | 75 | - (CGSize)snapshotSize { 76 | CGFloat length = floor(kDiameter / 1.2); 77 | return CGSizeMake(length, length); 78 | } 79 | 80 | - (CGSize)fitSize { 81 | return [self sizeThatFits:CGSizeZero]; 82 | } 83 | 84 | + (UIImage *)coverImage { 85 | static UIImage *image; 86 | static dispatch_once_t onceToken; 87 | dispatch_once(&onceToken, ^{ 88 | CGSize size = kSize; 89 | CGRect rect = (CGRect) {.size = size, .origin = CGPointZero}; 90 | rect = CGRectInset(rect, kPadding, kPadding); 91 | 92 | UIGraphicsBeginImageContextWithOptions(size, NO, 0); 93 | CGContextRef context = UIGraphicsGetCurrentContext(); 94 | 95 | CGPathRef boxPath = CGPathCreateWithRect(CGRectMake(0, 0, size.width, size.height), NULL); 96 | CGPathRef fillPath = CGPathCreateWithEllipseInRect(rect, NULL); 97 | CGPathRef strokePath = CGPathCreateWithEllipseInRect(YYTextCGRectPixelHalf(rect), NULL); 98 | 99 | // inner shadow 100 | CGContextSaveGState(context); { 101 | CGFloat blurRadius = 25; 102 | CGSize offset = CGSizeMake(0, 15); 103 | CGColorRef shadowColor = [UIColor colorWithWhite:0 alpha:0.16].CGColor; 104 | CGColorRef opaqueShadowColor = CGColorCreateCopyWithAlpha(shadowColor, 1.0); 105 | CGContextAddPath(context, fillPath); 106 | CGContextClip(context); 107 | CGContextSetAlpha(context, CGColorGetAlpha(shadowColor)); 108 | CGContextBeginTransparencyLayer(context, NULL); { 109 | CGContextSetShadowWithColor(context, offset, blurRadius, opaqueShadowColor); 110 | CGContextSetBlendMode(context, kCGBlendModeSourceOut); 111 | CGContextSetFillColorWithColor(context, opaqueShadowColor); 112 | CGContextAddPath(context, fillPath); 113 | CGContextFillPath(context); 114 | } CGContextEndTransparencyLayer(context); 115 | CGColorRelease(opaqueShadowColor); 116 | } CGContextRestoreGState(context); 117 | 118 | // outer shadow 119 | CGContextSaveGState(context); { 120 | CGContextAddPath(context, boxPath); 121 | CGContextAddPath(context, fillPath); 122 | CGContextEOClip(context); 123 | CGColorRef shadowColor = [UIColor colorWithWhite:0 alpha:0.32].CGColor; 124 | CGContextSetShadowWithColor(context, CGSizeMake(0, 1.5), 3, shadowColor); 125 | CGContextBeginTransparencyLayer(context, NULL); { 126 | CGContextAddPath(context, fillPath); 127 | [[UIColor colorWithWhite:0.7 alpha:1.000] setFill]; 128 | CGContextFillPath(context); 129 | } CGContextEndTransparencyLayer(context); 130 | } CGContextRestoreGState(context); 131 | 132 | // stroke 133 | CGContextSaveGState(context); { 134 | CGContextAddPath(context, strokePath); 135 | [[UIColor colorWithWhite:0.6 alpha:1] setStroke]; 136 | CGContextSetLineWidth(context, YYTextCGFloatFromPixel(1)); 137 | CGContextStrokePath(context); 138 | } CGContextRestoreGState(context); 139 | 140 | CFRelease(boxPath); 141 | CFRelease(fillPath); 142 | CFRelease(strokePath); 143 | 144 | image = UIGraphicsGetImageFromCurrentImageContext(); 145 | UIGraphicsEndImageContext(); 146 | 147 | }); 148 | return image; 149 | } 150 | 151 | 152 | #undef kMultiple 153 | #undef kDiameter 154 | #undef kPadding 155 | #undef kSize 156 | 157 | @end 158 | 159 | 160 | 161 | @interface _YYTextMagnifierRanged : YYTextMagnifier { 162 | UIImageView *_contentView; 163 | UIImageView *_coverView; 164 | } 165 | @end 166 | 167 | 168 | @implementation _YYTextMagnifierRanged 169 | #define kMultiple 1.2 170 | #define kSize CGSizeMake(141, 60) 171 | #define kPadding YYTextCGFloatPixelHalf(6.0) 172 | #define kRadius 6.0 173 | #define kHeight 32.0 174 | #define kArrow 14.0 175 | 176 | - (instancetype)initWithFrame:(CGRect)frame { 177 | self = [super initWithFrame:frame]; 178 | _contentView = [UIImageView new]; 179 | _contentView.frame = CGRectMake(kPadding, kPadding, kSize.width - 2 * kPadding, kHeight); 180 | _contentView.layer.cornerRadius = kRadius; 181 | _contentView.clipsToBounds = YES; 182 | [self addSubview:_contentView]; 183 | 184 | _coverView = [UIImageView new]; 185 | _coverView.frame = (CGRect){.origin = CGPointZero, .size = kSize}; 186 | _coverView.image = [self.class coverImage]; 187 | [self addSubview:_coverView]; 188 | 189 | self.layer.anchorPoint = CGPointMake(0.5, 1.2); 190 | return self; 191 | } 192 | 193 | - (instancetype)init { 194 | self = [self initWithFrame:CGRectZero]; 195 | self.frame = (CGRect){.size = [self sizeThatFits:CGSizeZero]}; 196 | return self; 197 | } 198 | 199 | - (YYTextMagnifierType)type { 200 | return YYTextMagnifierTypeRanged; 201 | } 202 | 203 | - (CGSize)sizeThatFits:(CGSize)size { 204 | return kSize; 205 | } 206 | 207 | - (void)setSnapshot:(UIImage *)snapshot { 208 | if (self.captureFadeAnimation) { 209 | [_contentView.layer removeAnimationForKey:@"contents"]; 210 | CABasicAnimation *animation = [CABasicAnimation animation]; 211 | animation.duration = kCaptureDisableFadeTime; 212 | animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 213 | [_contentView.layer addAnimation:animation forKey:@"contents"]; 214 | } 215 | _contentView.image = snapshot; 216 | } 217 | 218 | - (UIImage *)snapshot { 219 | return _contentView.image; 220 | } 221 | 222 | - (CGSize)snapshotSize { 223 | CGSize size; 224 | size.width = floor((kSize.width - 2 * kPadding) / kMultiple); 225 | size.height = floor(kHeight / kMultiple); 226 | return size; 227 | } 228 | 229 | - (CGSize)fitSize { 230 | return [self sizeThatFits:CGSizeZero]; 231 | } 232 | 233 | + (UIImage *)coverImage { 234 | static UIImage *image; 235 | static dispatch_once_t onceToken; 236 | dispatch_once(&onceToken, ^{ 237 | CGSize size = kSize; 238 | CGRect rect = (CGRect) {.size = size, .origin = CGPointZero}; 239 | 240 | UIGraphicsBeginImageContextWithOptions(size, NO, 0); 241 | CGContextRef context = UIGraphicsGetCurrentContext(); 242 | 243 | CGPathRef boxPath = CGPathCreateWithRect(rect, NULL); 244 | 245 | CGMutablePathRef path = CGPathCreateMutable(); 246 | CGPathMoveToPoint(path, NULL, kPadding + kRadius, kPadding); 247 | CGPathAddLineToPoint(path, NULL, size.width - kPadding - kRadius, kPadding); 248 | CGPathAddQuadCurveToPoint(path, NULL, size.width - kPadding, kPadding, size.width - kPadding, kPadding + kRadius); 249 | CGPathAddLineToPoint(path, NULL, size.width - kPadding, kHeight); 250 | CGPathAddCurveToPoint(path, NULL, size.width - kPadding, kPadding + kHeight, size.width - kPadding - kRadius, kPadding + kHeight, size.width - kPadding - kRadius, kPadding + kHeight); 251 | CGPathAddLineToPoint(path, NULL, size.width / 2 + kArrow, kPadding + kHeight); 252 | CGPathAddLineToPoint(path, NULL, size.width / 2, kPadding + kHeight + kArrow); 253 | CGPathAddLineToPoint(path, NULL, size.width / 2 - kArrow, kPadding + kHeight); 254 | CGPathAddLineToPoint(path, NULL, kPadding + kRadius, kPadding + kHeight); 255 | CGPathAddQuadCurveToPoint(path, NULL, kPadding, kPadding + kHeight, kPadding, kHeight); 256 | CGPathAddLineToPoint(path, NULL, kPadding, kPadding + kRadius); 257 | CGPathAddQuadCurveToPoint(path, NULL, kPadding, kPadding, kPadding + kRadius, kPadding); 258 | CGPathCloseSubpath(path); 259 | 260 | CGMutablePathRef arrowPath = CGPathCreateMutable(); 261 | CGPathMoveToPoint(arrowPath, NULL, size.width / 2 - kArrow, YYTextCGFloatPixelFloor(kPadding) + kHeight); 262 | CGPathAddLineToPoint(arrowPath, NULL, size.width / 2 + kArrow, YYTextCGFloatPixelFloor(kPadding) + kHeight); 263 | CGPathAddLineToPoint(arrowPath, NULL, size.width / 2, kPadding + kHeight + kArrow); 264 | CGPathCloseSubpath(arrowPath); 265 | 266 | // inner shadow 267 | CGContextSaveGState(context); { 268 | CGFloat blurRadius = 25; 269 | CGSize offset = CGSizeMake(0, 15); 270 | CGColorRef shadowColor = [UIColor colorWithWhite:0 alpha:0.16].CGColor; 271 | CGColorRef opaqueShadowColor = CGColorCreateCopyWithAlpha(shadowColor, 1.0); 272 | CGContextAddPath(context, path); 273 | CGContextClip(context); 274 | CGContextSetAlpha(context, CGColorGetAlpha(shadowColor)); 275 | CGContextBeginTransparencyLayer(context, NULL); { 276 | CGContextSetShadowWithColor(context, offset, blurRadius, opaqueShadowColor); 277 | CGContextSetBlendMode(context, kCGBlendModeSourceOut); 278 | CGContextSetFillColorWithColor(context, opaqueShadowColor); 279 | CGContextAddPath(context, path); 280 | CGContextFillPath(context); 281 | } CGContextEndTransparencyLayer(context); 282 | CGColorRelease(opaqueShadowColor); 283 | } CGContextRestoreGState(context); 284 | 285 | // outer shadow 286 | CGContextSaveGState(context); { 287 | CGContextAddPath(context, boxPath); 288 | CGContextAddPath(context, path); 289 | CGContextEOClip(context); 290 | CGColorRef shadowColor = [UIColor colorWithWhite:0 alpha:0.32].CGColor; 291 | CGContextSetShadowWithColor(context, CGSizeMake(0, 1.5), 3, shadowColor); 292 | CGContextBeginTransparencyLayer(context, NULL); { 293 | CGContextAddPath(context, path); 294 | [[UIColor colorWithWhite:0.7 alpha:1.000] setFill]; 295 | CGContextFillPath(context); 296 | } CGContextEndTransparencyLayer(context); 297 | } CGContextRestoreGState(context); 298 | 299 | // arrow 300 | CGContextSaveGState(context); { 301 | CGContextAddPath(context, arrowPath); 302 | [[UIColor colorWithWhite:1 alpha:0.95] set]; 303 | CGContextFillPath(context); 304 | } CGContextRestoreGState(context); 305 | 306 | // stroke 307 | CGContextSaveGState(context); { 308 | CGContextAddPath(context, path); 309 | [[UIColor colorWithWhite:0.6 alpha:1] setStroke]; 310 | CGContextSetLineWidth(context, YYTextCGFloatFromPixel(1)); 311 | CGContextStrokePath(context); 312 | } CGContextRestoreGState(context); 313 | 314 | CFRelease(boxPath); 315 | CFRelease(path); 316 | CFRelease(arrowPath); 317 | 318 | image = UIGraphicsGetImageFromCurrentImageContext(); 319 | UIGraphicsEndImageContext(); 320 | 321 | }); 322 | return image; 323 | } 324 | 325 | #undef kMultiple 326 | #undef kSize 327 | #undef kPadding 328 | #undef kRadius 329 | #undef kHeight 330 | #undef kArrow 331 | 332 | @end 333 | 334 | 335 | @implementation YYTextMagnifier 336 | 337 | + (id)magnifierWithType:(YYTextMagnifierType)type { 338 | switch (type) { 339 | case YYTextMagnifierTypeCaret :return [_YYTextMagnifierCaret new]; 340 | case YYTextMagnifierTypeRanged :return [_YYTextMagnifierRanged new]; 341 | } 342 | return nil; 343 | } 344 | 345 | - (id)initWithFrame:(CGRect)frame { 346 | // class cluster 347 | if ([self isMemberOfClass:[YYTextMagnifier class]]) { 348 | @throw [NSException exceptionWithName:NSStringFromClass([self class]) reason:@"Attempting to instantiate an abstract class. Use a concrete subclass instead." userInfo:nil]; 349 | return nil; 350 | } 351 | self = [super initWithFrame:frame]; 352 | return self; 353 | } 354 | 355 | @end 356 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextSelectionView.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextSelectionView.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/2/25. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | #if __has_include() 15 | #import 16 | #import 17 | #else 18 | #import "YYTextAttribute.h" 19 | #import "YYTextInput.h" 20 | #endif 21 | 22 | NS_ASSUME_NONNULL_BEGIN 23 | 24 | /** 25 | A single dot view. The frame should be foursquare. 26 | Change the background color for display. 27 | 28 | @discussion Typically, you should not use this class directly. 29 | */ 30 | @interface YYSelectionGrabberDot : UIView 31 | /// Dont't access this property. It was used by `YYTextEffectWindow`. 32 | @property (nonatomic, strong) UIView *mirror; 33 | @end 34 | 35 | 36 | /** 37 | A grabber (stick with a dot). 38 | 39 | @discussion Typically, you should not use this class directly. 40 | */ 41 | @interface YYSelectionGrabber : UIView 42 | 43 | @property (nonatomic, readonly) YYSelectionGrabberDot *dot; ///< the dot view 44 | @property (nonatomic) YYTextDirection dotDirection; ///< don't support composite direction 45 | @property (nullable, nonatomic, strong) UIColor *color; ///< tint color, default is nil 46 | 47 | @end 48 | 49 | 50 | /** 51 | The selection view for text edit and select. 52 | 53 | @discussion Typically, you should not use this class directly. 54 | */ 55 | @interface YYTextSelectionView : UIView 56 | 57 | @property (nullable, nonatomic, weak) UIView *hostView; ///< the holder view 58 | @property (nullable, nonatomic, strong) UIColor *color; ///< the tint color 59 | @property (nonatomic, getter = isCaretBlinks) BOOL caretBlinks; ///< whether the caret is blinks 60 | @property (nonatomic, getter = isCaretVisible) BOOL caretVisible; ///< whether the caret is visible 61 | @property (nonatomic, getter = isVerticalForm) BOOL verticalForm; ///< weather the text view is vertical form 62 | 63 | @property (nonatomic) CGRect caretRect; ///< caret rect (width==0 or height==0) 64 | @property (nullable, nonatomic, copy) NSArray *selectionRects; ///< default is nil 65 | 66 | @property (nonatomic, readonly) UIView *caretView; 67 | @property (nonatomic, readonly) YYSelectionGrabber *startGrabber; 68 | @property (nonatomic, readonly) YYSelectionGrabber *endGrabber; 69 | 70 | - (BOOL)isGrabberContainsPoint:(CGPoint)point; 71 | - (BOOL)isStartGrabberContainsPoint:(CGPoint)point; 72 | - (BOOL)isEndGrabberContainsPoint:(CGPoint)point; 73 | - (BOOL)isCaretContainsPoint:(CGPoint)point; 74 | - (BOOL)isSelectionRectsContainsPoint:(CGPoint)point; 75 | 76 | @end 77 | 78 | NS_ASSUME_NONNULL_END 79 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Component/YYTextSelectionView.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextSelectionView.m 3 | // YYText 4 | // 5 | // Created by ibireme on 15/2/25. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYTextSelectionView.h" 13 | #import "YYTextUtilities.h" 14 | #import "YYTextWeakProxy.h" 15 | 16 | #define kMarkAlpha 0.2 17 | #define kLineWidth 2.0 18 | #define kBlinkDuration 0.5 19 | #define kBlinkFadeDuration 0.2 20 | #define kBlinkFirstDelay 0.1 21 | #define kTouchTestExtend 14.0 22 | #define kTouchDotExtend 7.0 23 | 24 | 25 | @implementation YYSelectionGrabberDot 26 | 27 | - (instancetype)initWithFrame:(CGRect)frame { 28 | self = [super initWithFrame:frame]; 29 | if (!self) return nil; 30 | self.userInteractionEnabled = NO; 31 | self.mirror = [UIView new]; 32 | return self; 33 | } 34 | 35 | - (void)layoutSubviews { 36 | [super layoutSubviews]; 37 | CGFloat length = MIN(self.bounds.size.width, self.bounds.size.height); 38 | self.layer.cornerRadius = length * 0.5; 39 | self.mirror.bounds = self.bounds; 40 | self.mirror.layer.cornerRadius = self.layer.cornerRadius; 41 | } 42 | 43 | - (void)setBackgroundColor:(UIColor *)backgroundColor { 44 | [super setBackgroundColor:backgroundColor]; 45 | _mirror.backgroundColor = backgroundColor; 46 | } 47 | 48 | @end 49 | 50 | 51 | 52 | @implementation YYSelectionGrabber 53 | 54 | - (instancetype) initWithFrame:(CGRect)frame { 55 | self = [super initWithFrame:frame]; 56 | if (!self) return nil; 57 | _dot = [[YYSelectionGrabberDot alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; 58 | return self; 59 | } 60 | 61 | - (void)setDotDirection:(YYTextDirection)dotDirection { 62 | _dotDirection = dotDirection; 63 | [self addSubview:_dot]; 64 | CGRect frame = _dot.frame; 65 | CGFloat ofs = 0.5; 66 | if (dotDirection == YYTextDirectionTop) { 67 | frame.origin.y = -frame.size.height + ofs; 68 | frame.origin.x = (self.bounds.size.width - frame.size.width) / 2; 69 | } else if (dotDirection == YYTextDirectionRight) { 70 | frame.origin.x = self.bounds.size.width - ofs; 71 | frame.origin.y = (self.bounds.size.height - frame.size.height) / 2; 72 | } else if (dotDirection == YYTextDirectionBottom) { 73 | frame.origin.y = self.bounds.size.height - ofs; 74 | frame.origin.x = (self.bounds.size.width - frame.size.width) / 2; 75 | } else if (dotDirection == YYTextDirectionLeft) { 76 | frame.origin.x = -frame.size.width + ofs; 77 | frame.origin.y = (self.bounds.size.height - frame.size.height) / 2; 78 | } else { 79 | [_dot removeFromSuperview]; 80 | } 81 | _dot.frame = frame; 82 | } 83 | 84 | - (void)setColor:(UIColor *)color { 85 | self.backgroundColor = color; 86 | _dot.backgroundColor = color; 87 | _color = color; 88 | } 89 | 90 | - (void)layoutSubviews { 91 | [super layoutSubviews]; 92 | [self setDotDirection:_dotDirection]; 93 | } 94 | 95 | - (CGRect)touchRect { 96 | CGRect rect = CGRectInset(self.frame, -kTouchTestExtend, -kTouchTestExtend); 97 | UIEdgeInsets insets = {0}; 98 | if (_dotDirection == YYTextDirectionTop) { 99 | insets.top = -kTouchDotExtend; 100 | } else if (_dotDirection == YYTextDirectionRight) { 101 | insets.right = -kTouchDotExtend; 102 | } else if (_dotDirection == YYTextDirectionBottom) { 103 | insets.bottom = -kTouchDotExtend; 104 | } else if (_dotDirection == YYTextDirectionLeft) { 105 | insets.left = -kTouchDotExtend; 106 | } 107 | rect = UIEdgeInsetsInsetRect(rect, insets); 108 | return rect; 109 | } 110 | 111 | @end 112 | 113 | 114 | 115 | @interface YYTextSelectionView () 116 | @property (nonatomic, strong) NSTimer *caretTimer; 117 | @property (nonatomic, strong) UIView *caretView; 118 | @property (nonatomic, strong) YYSelectionGrabber *startGrabber; 119 | @property (nonatomic, strong) YYSelectionGrabber *endGrabber; 120 | @property (nonatomic, strong) NSMutableArray *markViews; 121 | @end 122 | 123 | @implementation YYTextSelectionView 124 | 125 | - (instancetype)initWithFrame:(CGRect)frame { 126 | self = [super initWithFrame:frame]; 127 | if (!self) return nil; 128 | 129 | self.userInteractionEnabled = NO; 130 | self.clipsToBounds = NO; 131 | _markViews = [NSMutableArray array]; 132 | _caretView = [UIView new]; 133 | _caretView.hidden = YES; 134 | _startGrabber = [YYSelectionGrabber new]; 135 | _startGrabber.dotDirection = YYTextDirectionTop; 136 | _startGrabber.hidden = YES; 137 | _endGrabber = [YYSelectionGrabber new]; 138 | _endGrabber.dotDirection = YYTextDirectionBottom; 139 | _endGrabber.hidden = YES; 140 | 141 | [self addSubview:_startGrabber]; 142 | [self addSubview:_endGrabber]; 143 | [self addSubview:_caretView]; 144 | 145 | return self; 146 | } 147 | 148 | - (void)dealloc { 149 | [_caretTimer invalidate]; 150 | } 151 | 152 | - (void)setColor:(UIColor *)color { 153 | _color = color; 154 | self.caretView.backgroundColor = color; 155 | self.startGrabber.color = color; 156 | self.endGrabber.color = color; 157 | [self.markViews enumerateObjectsUsingBlock: ^(UIView *v, NSUInteger idx, BOOL *stop) { 158 | v.backgroundColor = color; 159 | }]; 160 | } 161 | 162 | - (void)setCaretBlinks:(BOOL)caretBlinks { 163 | if (_caretBlinks != caretBlinks) { 164 | _caretView.alpha = 1; 165 | [self.class cancelPreviousPerformRequestsWithTarget:self selector:@selector(_startBlinks) object:nil]; 166 | if (caretBlinks) { 167 | [self performSelector:@selector(_startBlinks) withObject:nil afterDelay:kBlinkFirstDelay]; 168 | } else { 169 | [_caretTimer invalidate]; 170 | _caretTimer = nil; 171 | } 172 | _caretBlinks = caretBlinks; 173 | } 174 | } 175 | 176 | - (void)_startBlinks { 177 | [_caretTimer invalidate]; 178 | if (_caretVisible) { 179 | _caretTimer = [NSTimer timerWithTimeInterval:kBlinkDuration target:[YYTextWeakProxy proxyWithTarget:self] selector:@selector(_doBlink) userInfo:nil repeats:YES]; 180 | [[NSRunLoop currentRunLoop] addTimer:_caretTimer forMode:NSDefaultRunLoopMode]; 181 | } else { 182 | _caretView.alpha = 1; 183 | } 184 | } 185 | 186 | - (void)_doBlink { 187 | [UIView animateWithDuration:kBlinkFadeDuration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations: ^{ 188 | if (_caretView.alpha == 1) _caretView.alpha = 0; 189 | else _caretView.alpha = 1; 190 | } completion:NULL]; 191 | } 192 | 193 | - (void)setCaretVisible:(BOOL)caretVisible { 194 | _caretVisible = caretVisible; 195 | self.caretView.hidden = !caretVisible; 196 | _caretView.alpha = 1; 197 | [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_startBlinks) object:nil]; 198 | if (_caretBlinks) { 199 | [self performSelector:@selector(_startBlinks) withObject:nil afterDelay:kBlinkFirstDelay]; 200 | } 201 | } 202 | 203 | - (void)setVerticalForm:(BOOL)verticalForm { 204 | if (_verticalForm != verticalForm) { 205 | _verticalForm = verticalForm; 206 | [self setCaretRect:_caretRect]; 207 | self.startGrabber.dotDirection = verticalForm ? YYTextDirectionRight : YYTextDirectionTop; 208 | self.endGrabber.dotDirection = verticalForm ? YYTextDirectionLeft : YYTextDirectionBottom; 209 | } 210 | } 211 | 212 | - (CGRect)_standardCaretRect:(CGRect)caretRect { 213 | caretRect = CGRectStandardize(caretRect); 214 | if (_verticalForm) { 215 | if (caretRect.size.height == 0) { 216 | caretRect.size.height = kLineWidth; 217 | caretRect.origin.y -= kLineWidth * 0.5; 218 | } 219 | if (caretRect.origin.y < 0) { 220 | caretRect.origin.y = 0; 221 | } else if (caretRect.origin.y + caretRect.size.height > self.bounds.size.height) { 222 | caretRect.origin.y = self.bounds.size.height - caretRect.size.height; 223 | } 224 | } else { 225 | if (caretRect.size.width == 0) { 226 | caretRect.size.width = kLineWidth; 227 | caretRect.origin.x -= kLineWidth * 0.5; 228 | } 229 | if (caretRect.origin.x < 0) { 230 | caretRect.origin.x = 0; 231 | } else if (caretRect.origin.x + caretRect.size.width > self.bounds.size.width) { 232 | caretRect.origin.x = self.bounds.size.width - caretRect.size.width; 233 | } 234 | } 235 | caretRect = YYTextCGRectPixelRound(caretRect); 236 | if (isnan(caretRect.origin.x) || isinf(caretRect.origin.x)) caretRect.origin.x = 0; 237 | if (isnan(caretRect.origin.y) || isinf(caretRect.origin.y)) caretRect.origin.y = 0; 238 | if (isnan(caretRect.size.width) || isinf(caretRect.size.width)) caretRect.size.width = 0; 239 | if (isnan(caretRect.size.height) || isinf(caretRect.size.height)) caretRect.size.height = 0; 240 | return caretRect; 241 | } 242 | 243 | - (void)setCaretRect:(CGRect)caretRect { 244 | _caretRect = caretRect; 245 | self.caretView.frame = [self _standardCaretRect:caretRect]; 246 | CGFloat minWidth = MIN(self.caretView.bounds.size.width, self.caretView.bounds.size.height); 247 | self.caretView.layer.cornerRadius = minWidth / 2; 248 | } 249 | 250 | - (void)setSelectionRects:(NSArray *)selectionRects { 251 | _selectionRects = selectionRects.copy; 252 | [self.markViews enumerateObjectsUsingBlock: ^(UIView *v, NSUInteger idx, BOOL *stop) { 253 | [v removeFromSuperview]; 254 | }]; 255 | [self.markViews removeAllObjects]; 256 | self.startGrabber.hidden = YES; 257 | self.endGrabber.hidden = YES; 258 | 259 | [selectionRects enumerateObjectsUsingBlock: ^(YYTextSelectionRect *r, NSUInteger idx, BOOL *stop) { 260 | CGRect rect = r.rect; 261 | rect = CGRectStandardize(rect); 262 | rect = YYTextCGRectPixelRound(rect); 263 | if (r.containsStart || r.containsEnd) { 264 | rect = [self _standardCaretRect:rect]; 265 | if (r.containsStart) { 266 | self.startGrabber.hidden = NO; 267 | self.startGrabber.frame = rect; 268 | } 269 | if (r.containsEnd) { 270 | self.endGrabber.hidden = NO; 271 | self.endGrabber.frame = rect; 272 | } 273 | } else { 274 | if (rect.size.width > 0 && rect.size.height > 0) { 275 | UIView *mark = [[UIView alloc] initWithFrame:rect]; 276 | mark.backgroundColor = _color; 277 | mark.alpha = kMarkAlpha; 278 | [self insertSubview:mark atIndex:0]; 279 | [self.markViews addObject:mark]; 280 | } 281 | } 282 | }]; 283 | } 284 | 285 | - (BOOL)isGrabberContainsPoint:(CGPoint)point { 286 | return [self isStartGrabberContainsPoint:point] || [self isEndGrabberContainsPoint:point]; 287 | } 288 | 289 | - (BOOL)isStartGrabberContainsPoint:(CGPoint)point { 290 | if (_startGrabber.hidden) return NO; 291 | CGRect startRect = [_startGrabber touchRect]; 292 | CGRect endRect = [_endGrabber touchRect]; 293 | if (CGRectIntersectsRect(startRect, endRect)) { 294 | CGFloat distStart = YYTextCGPointGetDistanceToPoint(point, YYTextCGRectGetCenter(startRect)); 295 | CGFloat distEnd = YYTextCGPointGetDistanceToPoint(point, YYTextCGRectGetCenter(endRect)); 296 | if (distEnd <= distStart) return NO; 297 | } 298 | return CGRectContainsPoint(startRect, point); 299 | } 300 | 301 | - (BOOL)isEndGrabberContainsPoint:(CGPoint)point { 302 | if (_endGrabber.hidden) return NO; 303 | CGRect startRect = [_startGrabber touchRect]; 304 | CGRect endRect = [_endGrabber touchRect]; 305 | if (CGRectIntersectsRect(startRect, endRect)) { 306 | CGFloat distStart = YYTextCGPointGetDistanceToPoint(point, YYTextCGRectGetCenter(startRect)); 307 | CGFloat distEnd = YYTextCGPointGetDistanceToPoint(point, YYTextCGRectGetCenter(endRect)); 308 | if (distEnd > distStart) return NO; 309 | } 310 | return CGRectContainsPoint(endRect, point); 311 | } 312 | 313 | - (BOOL)isCaretContainsPoint:(CGPoint)point { 314 | if (_caretVisible) { 315 | CGRect rect = CGRectInset(_caretRect, -kTouchTestExtend, -kTouchTestExtend); 316 | return CGRectContainsPoint(rect, point); 317 | } 318 | return NO; 319 | } 320 | 321 | - (BOOL)isSelectionRectsContainsPoint:(CGPoint)point { 322 | if (_selectionRects.count == 0) return NO; 323 | for (YYTextSelectionRect *rect in _selectionRects) { 324 | if (CGRectContainsPoint(rect.rect, point)) return YES; 325 | } 326 | return NO; 327 | } 328 | 329 | @end 330 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/String/YYTextArchiver.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextArchiver.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/3/16. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | /** 17 | A subclass of `NSKeyedArchiver` which implement `NSKeyedArchiverDelegate` protocol. 18 | 19 | The archiver can encode the object which contains 20 | CGColor/CGImage/CTRunDelegateRef/.. (such as NSAttributedString). 21 | */ 22 | @interface YYTextArchiver : NSKeyedArchiver 23 | @end 24 | 25 | /** 26 | A subclass of `NSKeyedUnarchiver` which implement `NSKeyedUnarchiverDelegate` 27 | protocol. The unarchiver can decode the data which is encoded by 28 | `YYTextArchiver` or `NSKeyedArchiver`. 29 | */ 30 | @interface YYTextUnarchiver : NSKeyedUnarchiver 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/String/YYTextArchiver.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextArchiver.m 3 | // YYText 4 | // 5 | // Created by ibireme on 15/3/16. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYTextArchiver.h" 13 | #import "YYTextRunDelegate.h" 14 | #import "YYTextRubyAnnotation.h" 15 | 16 | /** 17 | When call CTRunDelegateGetTypeID() on some devices (runs iOS6), I got the error: 18 | "dyld: lazy symbol binding failed: Symbol not found: _CTRunDelegateGetTypeID" 19 | 20 | Here's a workaround for this issue. 21 | */ 22 | static CFTypeID CTRunDelegateTypeID() { 23 | static CFTypeID typeID; 24 | static dispatch_once_t onceToken; 25 | dispatch_once(&onceToken, ^{ 26 | /* 27 | if ((long)CTRunDelegateGetTypeID + 1 > 1) { //avoid compiler optimization 28 | typeID = CTRunDelegateGetTypeID(); 29 | } 30 | */ 31 | YYTextRunDelegate *delegate = [YYTextRunDelegate new]; 32 | CTRunDelegateRef ref = delegate.CTRunDelegate; 33 | typeID = CFGetTypeID(ref); 34 | CFRelease(ref); 35 | }); 36 | return typeID; 37 | } 38 | 39 | static CFTypeID CTRubyAnnotationTypeID() { 40 | static CFTypeID typeID; 41 | static dispatch_once_t onceToken; 42 | dispatch_once(&onceToken, ^{ 43 | if ((long)CTRubyAnnotationGetTypeID + 1 > 1) { //avoid compiler optimization 44 | typeID = CTRunDelegateGetTypeID(); 45 | } else { 46 | typeID = kCFNotFound; 47 | } 48 | }); 49 | return typeID; 50 | } 51 | 52 | /** 53 | A wrapper for CGColorRef. Used for Archive/Unarchive/Copy. 54 | */ 55 | @interface _YYCGColor : NSObject 56 | @property (nonatomic, assign) CGColorRef CGColor; 57 | + (instancetype)colorWithCGColor:(CGColorRef)CGColor; 58 | @end 59 | 60 | @implementation _YYCGColor 61 | 62 | + (instancetype)colorWithCGColor:(CGColorRef)CGColor { 63 | _YYCGColor *color = [self new]; 64 | color.CGColor = CGColor; 65 | return color; 66 | } 67 | 68 | - (void)setCGColor:(CGColorRef)CGColor { 69 | if (_CGColor != CGColor) { 70 | if (CGColor) CGColor = (CGColorRef)CFRetain(CGColor); 71 | if (_CGColor) CFRelease(_CGColor); 72 | _CGColor = CGColor; 73 | } 74 | } 75 | 76 | - (void)dealloc { 77 | if (_CGColor) CFRelease(_CGColor); 78 | _CGColor = NULL; 79 | } 80 | 81 | - (id)copyWithZone:(NSZone *)zone { 82 | _YYCGColor *color = [self.class new]; 83 | color.CGColor = self.CGColor; 84 | return color; 85 | } 86 | 87 | - (void)encodeWithCoder:(NSCoder *)aCoder { 88 | UIColor *color = [UIColor colorWithCGColor:_CGColor]; 89 | [aCoder encodeObject:color forKey:@"color"]; 90 | } 91 | 92 | - (id)initWithCoder:(NSCoder *)aDecoder { 93 | self = [self init]; 94 | UIColor *color = [aDecoder decodeObjectForKey:@"color"]; 95 | self.CGColor = color.CGColor; 96 | return self; 97 | } 98 | 99 | @end 100 | 101 | /** 102 | A wrapper for CGImageRef. Used for Archive/Unarchive/Copy. 103 | */ 104 | @interface _YYCGImage : NSObject 105 | @property (nonatomic, assign) CGImageRef CGImage; 106 | + (instancetype)imageWithCGImage:(CGImageRef)CGImage; 107 | @end 108 | 109 | @implementation _YYCGImage 110 | 111 | + (instancetype)imageWithCGImage:(CGImageRef)CGImage { 112 | _YYCGImage *image = [self new]; 113 | image.CGImage = CGImage; 114 | return image; 115 | } 116 | 117 | - (void)setCGImage:(CGImageRef)CGImage { 118 | if (_CGImage != CGImage) { 119 | if (CGImage) CGImage = (CGImageRef)CFRetain(CGImage); 120 | if (_CGImage) CFRelease(_CGImage); 121 | _CGImage = CGImage; 122 | } 123 | } 124 | 125 | - (void)dealloc { 126 | if (_CGImage) CFRelease(_CGImage); 127 | } 128 | 129 | - (id)copyWithZone:(NSZone *)zone { 130 | _YYCGImage *image = [self.class new]; 131 | image.CGImage = self.CGImage; 132 | return image; 133 | } 134 | 135 | - (void)encodeWithCoder:(NSCoder *)aCoder { 136 | UIImage *image = [UIImage imageWithCGImage:_CGImage]; 137 | [aCoder encodeObject:image forKey:@"image"]; 138 | } 139 | 140 | - (id)initWithCoder:(NSCoder *)aDecoder { 141 | self = [self init]; 142 | UIImage *image = [aDecoder decodeObjectForKey:@"image"]; 143 | self.CGImage = image.CGImage; 144 | return self; 145 | } 146 | 147 | @end 148 | 149 | 150 | @implementation YYTextArchiver 151 | 152 | + (NSData *)archivedDataWithRootObject:(id)rootObject { 153 | if (!rootObject) return nil; 154 | NSMutableData *data = [NSMutableData data]; 155 | YYTextArchiver *archiver = [[[self class] alloc] initForWritingWithMutableData:data]; 156 | [archiver encodeRootObject:rootObject]; 157 | [archiver finishEncoding]; 158 | return data; 159 | } 160 | 161 | + (BOOL)archiveRootObject:(id)rootObject toFile:(NSString *)path { 162 | NSData *data = [self archivedDataWithRootObject:rootObject]; 163 | if (!data) return NO; 164 | return [data writeToFile:path atomically:YES]; 165 | } 166 | 167 | - (instancetype)init { 168 | self = [super init]; 169 | self.delegate = self; 170 | return self; 171 | } 172 | 173 | - (instancetype)initForWritingWithMutableData:(NSMutableData *)data { 174 | self = [super initForWritingWithMutableData:data]; 175 | self.delegate = self; 176 | return self; 177 | } 178 | 179 | - (id)archiver:(NSKeyedArchiver *)archiver willEncodeObject:(id)object { 180 | CFTypeID typeID = CFGetTypeID((CFTypeRef)object); 181 | if (typeID == CTRunDelegateTypeID()) { 182 | CTRunDelegateRef runDelegate = (__bridge CFTypeRef)(object); 183 | id ref = CTRunDelegateGetRefCon(runDelegate); 184 | if (ref) return ref; 185 | } else if (typeID == CTRubyAnnotationTypeID()) { 186 | CTRubyAnnotationRef ctRuby = (__bridge CFTypeRef)(object); 187 | YYTextRubyAnnotation *ruby = [YYTextRubyAnnotation rubyWithCTRubyRef:ctRuby]; 188 | if (ruby) return ruby; 189 | } else if (typeID == CGColorGetTypeID()) { 190 | return [_YYCGColor colorWithCGColor:(CGColorRef)object]; 191 | } else if (typeID == CGImageGetTypeID()) { 192 | return [_YYCGImage imageWithCGImage:(CGImageRef)object]; 193 | } 194 | return object; 195 | } 196 | 197 | @end 198 | 199 | 200 | @implementation YYTextUnarchiver 201 | 202 | + (id)unarchiveObjectWithData:(NSData *)data { 203 | if (data.length == 0) return nil; 204 | YYTextUnarchiver *unarchiver = [[self alloc] initForReadingWithData:data]; 205 | return [unarchiver decodeObject]; 206 | } 207 | 208 | + (id)unarchiveObjectWithFile:(NSString *)path { 209 | NSData *data = [NSData dataWithContentsOfFile:path]; 210 | return [self unarchiveObjectWithData:data]; 211 | } 212 | 213 | - (instancetype)init { 214 | self = [super init]; 215 | self.delegate = self; 216 | return self; 217 | } 218 | 219 | - (instancetype)initForReadingWithData:(NSData *)data { 220 | self = [super initForReadingWithData:data]; 221 | self.delegate = self; 222 | return self; 223 | } 224 | 225 | - (id)unarchiver:(NSKeyedUnarchiver *)unarchiver didDecodeObject:(id) NS_RELEASES_ARGUMENT object NS_RETURNS_RETAINED { 226 | if ([object class] == [YYTextRunDelegate class]) { 227 | YYTextRunDelegate *runDelegate = object; 228 | CTRunDelegateRef ct = runDelegate.CTRunDelegate; 229 | id ctObj = (__bridge id)ct; 230 | if (ct) CFRelease(ct); 231 | return ctObj; 232 | } else if ([object class] == [YYTextRubyAnnotation class]) { 233 | YYTextRubyAnnotation *ruby = object; 234 | if ([UIDevice currentDevice].systemVersion.floatValue >= 8) { 235 | CTRubyAnnotationRef ct = ruby.CTRubyAnnotation; 236 | id ctObj = (__bridge id)(ct); 237 | if (ct) CFRelease(ct); 238 | return ctObj; 239 | } else { 240 | return object; 241 | } 242 | } else if ([object class] == [_YYCGColor class]) { 243 | _YYCGColor *color = object; 244 | return (id)color.CGColor; 245 | } else if ([object class] == [_YYCGImage class]) { 246 | _YYCGImage *image = object; 247 | return (id)image.CGImage; 248 | } 249 | return object; 250 | } 251 | 252 | @end 253 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/String/YYTextParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextParser.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/3/6. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | /** 17 | The YYTextParser protocol declares the required method for YYTextView and YYLabel 18 | to modify the text during editing. 19 | 20 | You can implement this protocol to add code highlighting or emoticon replacement for 21 | YYTextView and YYLabel. See `YYTextSimpleMarkdownParser` and `YYTextSimpleEmoticonParser` for example. 22 | */ 23 | @protocol YYTextParser 24 | @required 25 | /** 26 | When text is changed in YYTextView or YYLabel, this method will be called. 27 | 28 | @param text The original attributed string. This method may parse the text and 29 | change the text attributes or content. 30 | 31 | @param selectedRange Current selected range in `text`. 32 | This method should correct the range if the text content is changed. If there's 33 | no selected range (such as YYLabel), this value is NULL. 34 | 35 | @return If the 'text' is modified in this method, returns `YES`, otherwise returns `NO`. 36 | */ 37 | - (BOOL)parseText:(nullable NSMutableAttributedString *)text selectedRange:(nullable NSRangePointer)selectedRange; 38 | @end 39 | 40 | 41 | 42 | /** 43 | A simple markdown parser. 44 | 45 | It'a very simple markdown parser, you can use this parser to highlight some 46 | small piece of markdown text. 47 | 48 | This markdown parser use regular expression to parse text, slow and weak. 49 | If you want to write a better parser, try these projests: 50 | https://github.com/NimbusKit/markdown 51 | https://github.com/dreamwieber/AttributedMarkdown 52 | https://github.com/indragiek/CocoaMarkdown 53 | 54 | Or you can use lex/yacc to generate your custom parser. 55 | */ 56 | @interface YYTextSimpleMarkdownParser : NSObject 57 | @property (nonatomic) CGFloat fontSize; ///< default is 14 58 | @property (nonatomic) CGFloat headerFontSize; ///< default is 20 59 | 60 | @property (nullable, nonatomic, strong) UIColor *textColor; 61 | @property (nullable, nonatomic, strong) UIColor *controlTextColor; 62 | @property (nullable, nonatomic, strong) UIColor *headerTextColor; 63 | @property (nullable, nonatomic, strong) UIColor *inlineTextColor; 64 | @property (nullable, nonatomic, strong) UIColor *codeTextColor; 65 | @property (nullable, nonatomic, strong) UIColor *linkTextColor; 66 | 67 | - (void)setColorWithBrightTheme; ///< reset the color properties to pre-defined value. 68 | - (void)setColorWithDarkTheme; ///< reset the color properties to pre-defined value. 69 | @end 70 | 71 | 72 | 73 | /** 74 | A simple emoticon parser. 75 | 76 | Use this parser to map some specified piece of string to image emoticon. 77 | Example: "Hello :smile:" -> "Hello 😀" 78 | 79 | It can also be used to extend the "unicode emoticon". 80 | */ 81 | @interface YYTextSimpleEmoticonParser : NSObject 82 | 83 | /** 84 | The custom emoticon mapper. 85 | The key is a specified plain string, such as @":smile:". 86 | The value is a UIImage which will replace the specified plain string in text. 87 | */ 88 | @property (nullable, copy) NSDictionary *emoticonMapper; 89 | @end 90 | 91 | NS_ASSUME_NONNULL_END 92 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/String/YYTextRubyAnnotation.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextRubyAnnotation.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/24. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | #import 14 | 15 | NS_ASSUME_NONNULL_BEGIN 16 | 17 | /** 18 | Wrapper for CTRubyAnnotationRef. 19 | 20 | Example: 21 | 22 | YYTextRubyAnnotation *ruby = [YYTextRubyAnnotation new]; 23 | ruby.textBefore = @"zhù yīn"; 24 | CTRubyAnnotationRef ctRuby = ruby.CTRubyAnnotation; 25 | if (ctRuby) { 26 | /// add to attributed string 27 | CFRelease(ctRuby); 28 | } 29 | 30 | */ 31 | @interface YYTextRubyAnnotation : NSObject 32 | 33 | /// Specifies how the ruby text and the base text should be aligned relative to each other. 34 | @property (nonatomic) CTRubyAlignment alignment; 35 | 36 | /// Specifies how the ruby text can overhang adjacent characters. 37 | @property (nonatomic) CTRubyOverhang overhang; 38 | 39 | /// Specifies the size of the annotation text as a percent of the size of the base text. 40 | @property (nonatomic) CGFloat sizeFactor; 41 | 42 | 43 | /// The ruby text is positioned before the base text; 44 | /// i.e. above horizontal text and to the right of vertical text. 45 | @property (nullable, nonatomic, copy) NSString *textBefore; 46 | 47 | /// The ruby text is positioned after the base text; 48 | /// i.e. below horizontal text and to the left of vertical text. 49 | @property (nullable, nonatomic, copy) NSString *textAfter; 50 | 51 | /// The ruby text is positioned to the right of the base text whether it is horizontal or vertical. 52 | /// This is the way that Bopomofo annotations are attached to Chinese text in Taiwan. 53 | @property (nullable, nonatomic, copy) NSString *textInterCharacter; 54 | 55 | /// The ruby text follows the base text with no special styling. 56 | @property (nullable, nonatomic, copy) NSString *textInline; 57 | 58 | 59 | /** 60 | Create a ruby object from CTRuby object. 61 | 62 | @param ctRuby A CTRuby object. 63 | 64 | @return A ruby object, or nil when an error occurs. 65 | */ 66 | + (instancetype)rubyWithCTRubyRef:(CTRubyAnnotationRef)ctRuby NS_AVAILABLE_IOS(8_0); 67 | 68 | /** 69 | Create a CTRuby object from the instance. 70 | 71 | @return A new CTRuby object, or NULL when an error occurs. 72 | The returned value should be release after used. 73 | */ 74 | - (nullable CTRubyAnnotationRef)CTRubyAnnotation CF_RETURNS_RETAINED NS_AVAILABLE_IOS(8_0); 75 | 76 | @end 77 | 78 | NS_ASSUME_NONNULL_END 79 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/String/YYTextRubyAnnotation.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextRubyAnnotation.m 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/24. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYTextRubyAnnotation.h" 13 | 14 | @implementation YYTextRubyAnnotation 15 | 16 | - (instancetype)init { 17 | self = super.init; 18 | self.alignment = kCTRubyAlignmentAuto; 19 | self.overhang = kCTRubyOverhangAuto; 20 | self.sizeFactor = 0.5; 21 | return self; 22 | } 23 | 24 | + (instancetype)rubyWithCTRubyRef:(CTRubyAnnotationRef)ctRuby { 25 | if (!ctRuby) return nil; 26 | YYTextRubyAnnotation *one = [self new]; 27 | one.alignment = CTRubyAnnotationGetAlignment(ctRuby); 28 | one.overhang = CTRubyAnnotationGetOverhang(ctRuby); 29 | one.sizeFactor = CTRubyAnnotationGetSizeFactor(ctRuby); 30 | one.textBefore = (__bridge NSString *)(CTRubyAnnotationGetTextForPosition(ctRuby, kCTRubyPositionBefore)); 31 | one.textAfter = (__bridge NSString *)(CTRubyAnnotationGetTextForPosition(ctRuby, kCTRubyPositionAfter)); 32 | one.textInterCharacter = (__bridge NSString *)(CTRubyAnnotationGetTextForPosition(ctRuby, kCTRubyPositionInterCharacter)); 33 | one.textInline = (__bridge NSString *)(CTRubyAnnotationGetTextForPosition(ctRuby, kCTRubyPositionInline)); 34 | return one; 35 | } 36 | 37 | - (CTRubyAnnotationRef)CTRubyAnnotation CF_RETURNS_RETAINED { 38 | if (((long)CTRubyAnnotationCreate + 1) == 1) return NULL; // system not support 39 | 40 | CFStringRef text[kCTRubyPositionCount]; 41 | text[kCTRubyPositionBefore] = (__bridge CFStringRef)(_textBefore); 42 | text[kCTRubyPositionAfter] = (__bridge CFStringRef)(_textAfter); 43 | text[kCTRubyPositionInterCharacter] = (__bridge CFStringRef)(_textInterCharacter); 44 | text[kCTRubyPositionInline] = (__bridge CFStringRef)(_textInline); 45 | CTRubyAnnotationRef ruby = CTRubyAnnotationCreate(_alignment, _overhang, _sizeFactor, text); 46 | return ruby; 47 | } 48 | 49 | - (id)copyWithZone:(NSZone *)zone { 50 | YYTextRubyAnnotation *one = [self.class new]; 51 | one.alignment = _alignment; 52 | one.overhang = _overhang; 53 | one.sizeFactor = _sizeFactor; 54 | one.textBefore = _textBefore; 55 | one.textAfter = _textAfter; 56 | one.textInterCharacter = _textInterCharacter; 57 | one.textInline = _textInline; 58 | return one; 59 | } 60 | 61 | - (void)encodeWithCoder:(NSCoder *)aCoder { 62 | [aCoder encodeObject:@(_alignment) forKey:@"alignment"]; 63 | [aCoder encodeObject:@(_overhang) forKey:@"overhang"]; 64 | [aCoder encodeObject:@(_sizeFactor) forKey:@"sizeFactor"]; 65 | [aCoder encodeObject:_textBefore forKey:@"textBefore"]; 66 | [aCoder encodeObject:_textAfter forKey:@"textAfter"]; 67 | [aCoder encodeObject:_textInterCharacter forKey:@"textInterCharacter"]; 68 | [aCoder encodeObject:_textInline forKey:@"textInline"]; 69 | } 70 | 71 | - (id)initWithCoder:(NSCoder *)aDecoder { 72 | self = [self init]; 73 | _alignment = ((NSNumber *)[aDecoder decodeObjectForKey:@"alignment"]).intValue; 74 | _overhang = ((NSNumber *)[aDecoder decodeObjectForKey:@"overhang"]).intValue; 75 | _sizeFactor = ((NSNumber *)[aDecoder decodeObjectForKey:@"sizeFactor"]).intValue; 76 | _textBefore = [aDecoder decodeObjectForKey:@"textBefore"]; 77 | _textAfter = [aDecoder decodeObjectForKey:@"textAfter"]; 78 | _textInterCharacter = [aDecoder decodeObjectForKey:@"textInterCharacter"]; 79 | _textInline = [aDecoder decodeObjectForKey:@"textInline"]; 80 | return self; 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/String/YYTextRunDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextRunDelegate.h 3 | // YYText 4 | // 5 | // Created by ibireme on 14/10/14. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | #import 14 | 15 | NS_ASSUME_NONNULL_BEGIN 16 | 17 | /** 18 | Wrapper for CTRunDelegateRef. 19 | 20 | Example: 21 | 22 | YYTextRunDelegate *delegate = [YYTextRunDelegate new]; 23 | delegate.ascent = 20; 24 | delegate.descent = 4; 25 | delegate.width = 20; 26 | CTRunDelegateRef ctRunDelegate = delegate.CTRunDelegate; 27 | if (ctRunDelegate) { 28 | /// add to attributed string 29 | CFRelease(ctRunDelegate); 30 | } 31 | 32 | */ 33 | @interface YYTextRunDelegate : NSObject 34 | 35 | /** 36 | Creates and returns the CTRunDelegate. 37 | 38 | @discussion You need call CFRelease() after used. 39 | The CTRunDelegateRef has a strong reference to this YYTextRunDelegate object. 40 | In CoreText, use CTRunDelegateGetRefCon() to get this YYTextRunDelegate object. 41 | 42 | @return The CTRunDelegate object. 43 | */ 44 | - (nullable CTRunDelegateRef)CTRunDelegate CF_RETURNS_RETAINED; 45 | 46 | /** 47 | Additional information about the the run delegate. 48 | */ 49 | @property (nullable, nonatomic, strong) NSDictionary *userInfo; 50 | 51 | /** 52 | The typographic ascent of glyphs in the run. 53 | */ 54 | @property (nonatomic) CGFloat ascent; 55 | 56 | /** 57 | The typographic descent of glyphs in the run. 58 | */ 59 | @property (nonatomic) CGFloat descent; 60 | 61 | /** 62 | The typographic width of glyphs in the run. 63 | */ 64 | @property (nonatomic) CGFloat width; 65 | 66 | @end 67 | 68 | NS_ASSUME_NONNULL_END 69 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/String/YYTextRunDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextRunDelegate.m 3 | // YYText 4 | // 5 | // Created by ibireme on 14/10/14. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYTextRunDelegate.h" 13 | 14 | static void DeallocCallback(void *ref) { 15 | YYTextRunDelegate *self = (__bridge_transfer YYTextRunDelegate *)(ref); 16 | self = nil; // release 17 | } 18 | 19 | static CGFloat GetAscentCallback(void *ref) { 20 | YYTextRunDelegate *self = (__bridge YYTextRunDelegate *)(ref); 21 | return self.ascent; 22 | } 23 | 24 | static CGFloat GetDecentCallback(void *ref) { 25 | YYTextRunDelegate *self = (__bridge YYTextRunDelegate *)(ref); 26 | return self.descent; 27 | } 28 | 29 | static CGFloat GetWidthCallback(void *ref) { 30 | YYTextRunDelegate *self = (__bridge YYTextRunDelegate *)(ref); 31 | return self.width; 32 | } 33 | 34 | @implementation YYTextRunDelegate 35 | 36 | - (CTRunDelegateRef)CTRunDelegate CF_RETURNS_RETAINED { 37 | CTRunDelegateCallbacks callbacks; 38 | callbacks.version = kCTRunDelegateCurrentVersion; 39 | callbacks.dealloc = DeallocCallback; 40 | callbacks.getAscent = GetAscentCallback; 41 | callbacks.getDescent = GetDecentCallback; 42 | callbacks.getWidth = GetWidthCallback; 43 | return CTRunDelegateCreate(&callbacks, (__bridge_retained void *)(self.copy)); 44 | } 45 | 46 | - (void)encodeWithCoder:(NSCoder *)aCoder { 47 | [aCoder encodeObject:@(_ascent) forKey:@"ascent"]; 48 | [aCoder encodeObject:@(_descent) forKey:@"descent"]; 49 | [aCoder encodeObject:@(_width) forKey:@"width"]; 50 | [aCoder encodeObject:_userInfo forKey:@"userInfo"]; 51 | } 52 | 53 | - (id)initWithCoder:(NSCoder *)aDecoder { 54 | self = [super init]; 55 | _ascent = ((NSNumber *)[aDecoder decodeObjectForKey:@"ascent"]).floatValue; 56 | _descent = ((NSNumber *)[aDecoder decodeObjectForKey:@"descent"]).floatValue; 57 | _width = ((NSNumber *)[aDecoder decodeObjectForKey:@"width"]).floatValue; 58 | _userInfo = [aDecoder decodeObjectForKey:@"userInfo"]; 59 | return self; 60 | } 61 | 62 | - (id)copyWithZone:(NSZone *)zone { 63 | typeof(self) one = [self.class new]; 64 | one.ascent = self.ascent; 65 | one.descent = self.descent; 66 | one.width = self.width; 67 | one.userInfo = self.userInfo; 68 | return one; 69 | } 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Utility/NSParagraphStyle+YYText.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSParagraphStyle+YYText.h 3 | // YYText 4 | // 5 | // Created by ibireme on 14/10/7. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | /** 17 | Provides extensions for `NSParagraphStyle` to work with CoreText. 18 | */ 19 | @interface NSParagraphStyle (YYText) 20 | 21 | /** 22 | Creates a new NSParagraphStyle object from the CoreText Style. 23 | 24 | @param CTStyle CoreText Paragraph Style. 25 | 26 | @return a new NSParagraphStyle 27 | */ 28 | + (nullable NSParagraphStyle *)yy_styleWithCTStyle:(CTParagraphStyleRef)CTStyle; 29 | 30 | /** 31 | Creates and returns a CoreText Paragraph Style. (need call CFRelease() after used) 32 | */ 33 | - (nullable CTParagraphStyleRef)yy_CTStyle CF_RETURNS_RETAINED; 34 | 35 | @end 36 | 37 | NS_ASSUME_NONNULL_END 38 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Utility/NSParagraphStyle+YYText.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSParagraphStyle+YYText.m 3 | // YYText 4 | // 5 | // Created by ibireme on 14/10/7. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "NSParagraphStyle+YYText.h" 13 | #import "YYTextAttribute.h" 14 | #import 15 | 16 | // Dummy class for category 17 | @interface NSParagraphStyle_YYText : NSObject @end 18 | @implementation NSParagraphStyle_YYText @end 19 | 20 | 21 | @implementation NSParagraphStyle (YYText) 22 | 23 | + (NSParagraphStyle *)yy_styleWithCTStyle:(CTParagraphStyleRef)CTStyle { 24 | if (CTStyle == NULL) return nil; 25 | 26 | NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; 27 | 28 | CGFloat lineSpacing; 29 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierLineSpacing, sizeof(CGFloat), &lineSpacing)) { 30 | style.lineSpacing = lineSpacing; 31 | } 32 | 33 | CGFloat paragraphSpacing; 34 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierParagraphSpacing, sizeof(CGFloat), ¶graphSpacing)) { 35 | style.paragraphSpacing = paragraphSpacing; 36 | } 37 | 38 | CTTextAlignment alignment; 39 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &alignment)) { 40 | style.alignment = NSTextAlignmentFromCTTextAlignment(alignment); 41 | } 42 | 43 | CGFloat firstLineHeadIndent; 44 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierFirstLineHeadIndent, sizeof(CGFloat), &firstLineHeadIndent)) { 45 | style.firstLineHeadIndent = firstLineHeadIndent; 46 | } 47 | 48 | CGFloat headIndent; 49 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierHeadIndent, sizeof(CGFloat), &headIndent)) { 50 | style.headIndent = headIndent; 51 | } 52 | 53 | CGFloat tailIndent; 54 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierTailIndent, sizeof(CGFloat), &tailIndent)) { 55 | style.tailIndent = tailIndent; 56 | } 57 | 58 | CTLineBreakMode lineBreakMode; 59 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierLineBreakMode, sizeof(CTLineBreakMode), &lineBreakMode)) { 60 | style.lineBreakMode = (NSLineBreakMode)lineBreakMode; 61 | } 62 | 63 | CGFloat minimumLineHeight; 64 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierMinimumLineHeight, sizeof(CGFloat), &minimumLineHeight)) { 65 | style.minimumLineHeight = minimumLineHeight; 66 | } 67 | 68 | CGFloat maximumLineHeight; 69 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierMaximumLineHeight, sizeof(CGFloat), &maximumLineHeight)) { 70 | style.maximumLineHeight = maximumLineHeight; 71 | } 72 | 73 | CTWritingDirection baseWritingDirection; 74 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierBaseWritingDirection, sizeof(CTWritingDirection), &baseWritingDirection)) { 75 | style.baseWritingDirection = (NSWritingDirection)baseWritingDirection; 76 | } 77 | 78 | CGFloat lineHeightMultiple; 79 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierLineHeightMultiple, sizeof(CGFloat), &lineHeightMultiple)) { 80 | style.lineHeightMultiple = lineHeightMultiple; 81 | } 82 | 83 | CGFloat paragraphSpacingBefore; 84 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierParagraphSpacingBefore, sizeof(CGFloat), ¶graphSpacingBefore)) { 85 | style.paragraphSpacingBefore = paragraphSpacingBefore; 86 | } 87 | 88 | if ([style respondsToSelector:@selector(tabStops)]) { 89 | CFArrayRef tabStops; 90 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierTabStops, sizeof(CFArrayRef), &tabStops)) { 91 | if ([style respondsToSelector:@selector(setTabStops:)]) { 92 | NSMutableArray *tabs = [NSMutableArray new]; 93 | [((__bridge NSArray *)(tabStops))enumerateObjectsUsingBlock : ^(id obj, NSUInteger idx, BOOL *stop) { 94 | CTTextTabRef ctTab = (__bridge CFTypeRef)obj; 95 | 96 | NSTextTab *tab = [[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentFromCTTextAlignment(CTTextTabGetAlignment(ctTab)) location:CTTextTabGetLocation(ctTab) options:(__bridge id)CTTextTabGetOptions(ctTab)]; 97 | [tabs addObject:tab]; 98 | }]; 99 | if (tabs.count) { 100 | style.tabStops = tabs; 101 | } 102 | } 103 | } 104 | 105 | CGFloat defaultTabInterval; 106 | if (CTParagraphStyleGetValueForSpecifier(CTStyle, kCTParagraphStyleSpecifierDefaultTabInterval, sizeof(CGFloat), &defaultTabInterval)) { 107 | if ([style respondsToSelector:@selector(setDefaultTabInterval:)]) { 108 | style.defaultTabInterval = defaultTabInterval; 109 | } 110 | } 111 | } 112 | 113 | return style; 114 | } 115 | 116 | - (CTParagraphStyleRef)yy_CTStyle CF_RETURNS_RETAINED { 117 | CTParagraphStyleSetting set[kCTParagraphStyleSpecifierCount] = { 0 }; 118 | int count = 0; 119 | 120 | CGFloat lineSpacing = self.lineSpacing; 121 | set[count].spec = kCTParagraphStyleSpecifierLineSpacing; 122 | set[count].valueSize = sizeof(CGFloat); 123 | set[count].value = &lineSpacing; 124 | count++; 125 | 126 | CGFloat paragraphSpacing = self.paragraphSpacing; 127 | set[count].spec = kCTParagraphStyleSpecifierParagraphSpacing; 128 | set[count].valueSize = sizeof(CGFloat); 129 | set[count].value = ¶graphSpacing; 130 | count++; 131 | 132 | CTTextAlignment alignment = NSTextAlignmentToCTTextAlignment(self.alignment); 133 | set[count].spec = kCTParagraphStyleSpecifierAlignment; 134 | set[count].valueSize = sizeof(CTTextAlignment); 135 | set[count].value = &alignment; 136 | count++; 137 | 138 | CGFloat firstLineHeadIndent = self.firstLineHeadIndent; 139 | set[count].spec = kCTParagraphStyleSpecifierFirstLineHeadIndent; 140 | set[count].valueSize = sizeof(CGFloat); 141 | set[count].value = &firstLineHeadIndent; 142 | count++; 143 | 144 | CGFloat headIndent = self.headIndent; 145 | set[count].spec = kCTParagraphStyleSpecifierHeadIndent; 146 | set[count].valueSize = sizeof(CGFloat); 147 | set[count].value = &headIndent; 148 | count++; 149 | 150 | CGFloat tailIndent = self.tailIndent; 151 | set[count].spec = kCTParagraphStyleSpecifierTailIndent; 152 | set[count].valueSize = sizeof(CGFloat); 153 | set[count].value = &tailIndent; 154 | count++; 155 | 156 | CTLineBreakMode paraLineBreak = (CTLineBreakMode)self.lineBreakMode; 157 | set[count].spec = kCTParagraphStyleSpecifierLineBreakMode; 158 | set[count].valueSize = sizeof(CTLineBreakMode); 159 | set[count].value = ¶LineBreak; 160 | count++; 161 | 162 | CGFloat minimumLineHeight = self.minimumLineHeight; 163 | set[count].spec = kCTParagraphStyleSpecifierMinimumLineHeight; 164 | set[count].valueSize = sizeof(CGFloat); 165 | set[count].value = &minimumLineHeight; 166 | count++; 167 | 168 | CGFloat maximumLineHeight = self.maximumLineHeight; 169 | set[count].spec = kCTParagraphStyleSpecifierMaximumLineHeight; 170 | set[count].valueSize = sizeof(CGFloat); 171 | set[count].value = &maximumLineHeight; 172 | count++; 173 | 174 | CTWritingDirection paraWritingDirection = (CTWritingDirection)self.baseWritingDirection; 175 | set[count].spec = kCTParagraphStyleSpecifierBaseWritingDirection; 176 | set[count].valueSize = sizeof(CTWritingDirection); 177 | set[count].value = ¶WritingDirection; 178 | count++; 179 | 180 | CGFloat lineHeightMultiple = self.lineHeightMultiple; 181 | set[count].spec = kCTParagraphStyleSpecifierLineHeightMultiple; 182 | set[count].valueSize = sizeof(CGFloat); 183 | set[count].value = &lineHeightMultiple; 184 | count++; 185 | 186 | CGFloat paragraphSpacingBefore = self.paragraphSpacingBefore; 187 | set[count].spec = kCTParagraphStyleSpecifierParagraphSpacingBefore; 188 | set[count].valueSize = sizeof(CGFloat); 189 | set[count].value = ¶graphSpacingBefore; 190 | count++; 191 | 192 | if([self respondsToSelector:@selector(tabStops)]) { 193 | NSMutableArray *tabs = [NSMutableArray array]; 194 | if ([self respondsToSelector:@selector(tabStops)]) { 195 | NSInteger numTabs = self.tabStops.count; 196 | if (numTabs) { 197 | [self.tabStops enumerateObjectsUsingBlock: ^(NSTextTab *tab, NSUInteger idx, BOOL *stop) { 198 | CTTextTabRef ctTab = CTTextTabCreate(NSTextAlignmentToCTTextAlignment(tab.alignment), tab.location, (__bridge CFTypeRef)tab.options); 199 | [tabs addObject:(__bridge id)ctTab]; 200 | CFRelease(ctTab); 201 | }]; 202 | 203 | CFArrayRef tabStops = (__bridge CFArrayRef)(tabs); 204 | set[count].spec = kCTParagraphStyleSpecifierTabStops; 205 | set[count].valueSize = sizeof(CFArrayRef); 206 | set[count].value = &tabStops; 207 | count++; 208 | } 209 | } 210 | 211 | if ([self respondsToSelector:@selector(defaultTabInterval)]) { 212 | CGFloat defaultTabInterval = self.defaultTabInterval; 213 | set[count].spec = kCTParagraphStyleSpecifierDefaultTabInterval; 214 | set[count].valueSize = sizeof(CGFloat); 215 | set[count].value = &defaultTabInterval; 216 | count++; 217 | } 218 | } 219 | 220 | CTParagraphStyleRef style = CTParagraphStyleCreate(set, count); 221 | return style; 222 | } 223 | 224 | @end 225 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Utility/UIPasteboard+YYText.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIPasteboard+YYText.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/2. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | /** 17 | Extend UIPasteboard to support image and attributed string. 18 | */ 19 | @interface UIPasteboard (YYText) 20 | 21 | @property (nullable, nonatomic, copy) NSData *yy_PNGData; ///< PNG file data 22 | @property (nullable, nonatomic, copy) NSData *yy_JPEGData; ///< JPEG file data 23 | @property (nullable, nonatomic, copy) NSData *yy_GIFData; ///< GIF file data 24 | @property (nullable, nonatomic, copy) NSData *yy_WEBPData; ///< WebP file data 25 | @property (nullable, nonatomic, copy) NSData *yy_ImageData; ///< image file data 26 | 27 | /// Attributed string, 28 | /// Set this attributed will also set the string property which is copy from the attributed string. 29 | /// If the attributed string contains one or more image, it will also set the `images` property. 30 | @property (nullable, nonatomic, copy) NSAttributedString *yy_AttributedString; 31 | 32 | @end 33 | 34 | 35 | /// The name identifying the attributed string in pasteboard. 36 | UIKIT_EXTERN NSString *const YYTextPasteboardTypeAttributedString; 37 | 38 | /// The UTI Type identifying WebP data in pasteboard. 39 | UIKIT_EXTERN NSString *const YYTextUTTypeWEBP; 40 | 41 | NS_ASSUME_NONNULL_END 42 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Utility/UIPasteboard+YYText.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIPasteboard+YYText.m 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/2. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "UIPasteboard+YYText.h" 13 | #import "NSAttributedString+YYText.h" 14 | #import 15 | 16 | 17 | #if __has_include("YYImage.h") 18 | #import "YYImage.h" 19 | #define YYTextAnimatedImageAvailable 1 20 | #elif __has_include() 21 | #import 22 | #define YYTextAnimatedImageAvailable 1 23 | #elif __has_include() 24 | #import 25 | #define YYTextAnimatedImageAvailable 1 26 | #else 27 | #define YYTextAnimatedImageAvailable 0 28 | #endif 29 | 30 | 31 | // Dummy class for category 32 | @interface UIPasteboard_YYText : NSObject @end 33 | @implementation UIPasteboard_YYText @end 34 | 35 | 36 | NSString *const YYTextPasteboardTypeAttributedString = @"com.ibireme.NSAttributedString"; 37 | NSString *const YYTextUTTypeWEBP = @"com.google.webp"; 38 | 39 | @implementation UIPasteboard (YYText) 40 | 41 | 42 | - (void)setYy_PNGData:(NSData *)PNGData { 43 | [self setData:PNGData forPasteboardType:(id)kUTTypePNG]; 44 | } 45 | 46 | - (NSData *)yy_PNGData { 47 | return [self dataForPasteboardType:(id)kUTTypePNG]; 48 | } 49 | 50 | - (void)setYy_JPEGData:(NSData *)JPEGData { 51 | [self setData:JPEGData forPasteboardType:(id)kUTTypeJPEG]; 52 | } 53 | 54 | - (NSData *)yy_JPEGData { 55 | return [self dataForPasteboardType:(id)kUTTypeJPEG]; 56 | } 57 | 58 | - (void)setYy_GIFData:(NSData *)GIFData { 59 | [self setData:GIFData forPasteboardType:(id)kUTTypeGIF]; 60 | } 61 | 62 | - (NSData *)yy_GIFData { 63 | return [self dataForPasteboardType:(id)kUTTypeGIF]; 64 | } 65 | 66 | - (void)setYy_WEBPData:(NSData *)WEBPData { 67 | [self setData:WEBPData forPasteboardType:YYTextUTTypeWEBP]; 68 | } 69 | 70 | - (NSData *)yy_WEBPData { 71 | return [self dataForPasteboardType:YYTextUTTypeWEBP]; 72 | } 73 | 74 | - (void)setYy_ImageData:(NSData *)imageData { 75 | [self setData:imageData forPasteboardType:(id)kUTTypeImage]; 76 | } 77 | 78 | - (NSData *)yy_ImageData { 79 | return [self dataForPasteboardType:(id)kUTTypeImage]; 80 | } 81 | 82 | - (void)setYy_AttributedString:(NSAttributedString *)attributedString { 83 | self.string = [attributedString yy_plainTextForRange:NSMakeRange(0, attributedString.length)]; 84 | NSData *data = [attributedString yy_archiveToData]; 85 | if (data) { 86 | NSDictionary *item = @{YYTextPasteboardTypeAttributedString : data}; 87 | [self addItems:@[item]]; 88 | } 89 | [attributedString enumerateAttribute:YYTextAttachmentAttributeName inRange:NSMakeRange(0, attributedString.length) options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(YYTextAttachment *attachment, NSRange range, BOOL *stop) { 90 | 91 | // save image 92 | UIImage *simpleImage = nil; 93 | if ([attachment.content isKindOfClass:[UIImage class]]) { 94 | simpleImage = attachment.content; 95 | } else if ([attachment.content isKindOfClass:[UIImageView class]]) { 96 | simpleImage = ((UIImageView *)attachment.content).image; 97 | } 98 | if (simpleImage) { 99 | NSDictionary *item = @{@"com.apple.uikit.image" : simpleImage}; 100 | [self addItems:@[item]]; 101 | } 102 | 103 | #if YYTextAnimatedImageAvailable 104 | // save animated image 105 | if ([attachment.content isKindOfClass:[UIImageView class]]) { 106 | UIImageView *imageView = attachment.content; 107 | Class aniImageClass = NSClassFromString(@"YYImage"); 108 | UIImage *image = imageView.image; 109 | if (aniImageClass && [image isKindOfClass:aniImageClass]) { 110 | NSData *data = [image valueForKey:@"animatedImageData"]; 111 | NSNumber *type = [image valueForKey:@"animatedImageType"]; 112 | if (data) { 113 | switch (type.unsignedIntegerValue) { 114 | case YYImageTypeGIF: { 115 | NSDictionary *item = @{(id)kUTTypeGIF : data}; 116 | [self addItems:@[item]]; 117 | } break; 118 | case YYImageTypePNG: { // APNG 119 | NSDictionary *item = @{(id)kUTTypePNG : data}; 120 | [self addItems:@[item]]; 121 | } break; 122 | case YYImageTypeWebP: { 123 | NSDictionary *item = @{(id)YYTextUTTypeWEBP : data}; 124 | [self addItems:@[item]]; 125 | } break; 126 | default: break; 127 | } 128 | } 129 | } 130 | } 131 | #endif 132 | 133 | }]; 134 | } 135 | 136 | - (NSAttributedString *)yy_AttributedString { 137 | for (NSDictionary *items in self.items) { 138 | NSData *data = items[YYTextPasteboardTypeAttributedString]; 139 | if (data) { 140 | return [NSAttributedString yy_unarchiveFromData:data]; 141 | } 142 | } 143 | return nil; 144 | } 145 | 146 | @end 147 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Utility/UIView+YYText.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+YYText.h 3 | // YYText 4 | // 5 | // Created by ibireme on 13/4/3. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | /** 17 | Provides extensions for `UIView`. 18 | */ 19 | @interface UIView (YYText) 20 | 21 | /** 22 | Returns the view's view controller (may be nil). 23 | */ 24 | @property (nullable, nonatomic, readonly) UIViewController *yy_viewController; 25 | 26 | /** 27 | Returns the visible alpha on screen, taking into account superview and window. 28 | */ 29 | @property (nonatomic, readonly) CGFloat yy_visibleAlpha; 30 | 31 | /** 32 | Converts a point from the receiver's coordinate system to that of the specified view or window. 33 | 34 | @param point A point specified in the local coordinate system (bounds) of the receiver. 35 | @param view The view or window into whose coordinate system point is to be converted. 36 | If view is nil, this method instead converts to window base coordinates. 37 | @return The point converted to the coordinate system of view. 38 | */ 39 | - (CGPoint)yy_convertPoint:(CGPoint)point toViewOrWindow:(UIView *)view; 40 | 41 | /** 42 | Converts a point from the coordinate system of a given view or window to that of the receiver. 43 | 44 | @param point A point specified in the local coordinate system (bounds) of view. 45 | @param view The view or window with point in its coordinate system. 46 | If view is nil, this method instead converts from window base coordinates. 47 | @return The point converted to the local coordinate system (bounds) of the receiver. 48 | */ 49 | - (CGPoint)yy_convertPoint:(CGPoint)point fromViewOrWindow:(UIView *)view; 50 | 51 | /** 52 | Converts a rectangle from the receiver's coordinate system to that of another view or window. 53 | 54 | @param rect A rectangle specified in the local coordinate system (bounds) of the receiver. 55 | @param view The view or window that is the target of the conversion operation. If view is nil, this method instead converts to window base coordinates. 56 | @return The converted rectangle. 57 | */ 58 | - (CGRect)yy_convertRect:(CGRect)rect toViewOrWindow:(UIView *)view; 59 | 60 | /** 61 | Converts a rectangle from the coordinate system of another view or window to that of the receiver. 62 | 63 | @param rect A rectangle specified in the local coordinate system (bounds) of view. 64 | @param view The view or window with rect in its coordinate system. 65 | If view is nil, this method instead converts from window base coordinates. 66 | @return The converted rectangle. 67 | */ 68 | - (CGRect)yy_convertRect:(CGRect)rect fromViewOrWindow:(UIView *)view; 69 | 70 | @end 71 | 72 | NS_ASSUME_NONNULL_END 73 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Utility/UIView+YYText.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+YYText.m 3 | // YYText 4 | // 5 | // Created by ibireme on 13/4/3. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "UIView+YYText.h" 13 | 14 | // Dummy class for category 15 | @interface UIView_YYText : NSObject @end 16 | @implementation UIView_YYText @end 17 | 18 | 19 | @implementation UIView (YYText) 20 | 21 | - (UIViewController *)yy_viewController { 22 | for (UIView *view = self; view; view = view.superview) { 23 | UIResponder *nextResponder = [view nextResponder]; 24 | if ([nextResponder isKindOfClass:[UIViewController class]]) { 25 | return (UIViewController *)nextResponder; 26 | } 27 | } 28 | return nil; 29 | } 30 | 31 | - (CGFloat)yy_visibleAlpha { 32 | if ([self isKindOfClass:[UIWindow class]]) { 33 | if (self.hidden) return 0; 34 | return self.alpha; 35 | } 36 | if (!self.window) return 0; 37 | CGFloat alpha = 1; 38 | UIView *v = self; 39 | while (v) { 40 | if (v.hidden) { 41 | alpha = 0; 42 | break; 43 | } 44 | alpha *= v.alpha; 45 | v = v.superview; 46 | } 47 | return alpha; 48 | } 49 | 50 | - (CGPoint)yy_convertPoint:(CGPoint)point toViewOrWindow:(UIView *)view { 51 | if (!view) { 52 | if ([self isKindOfClass:[UIWindow class]]) { 53 | return [((UIWindow *)self) convertPoint:point toWindow:nil]; 54 | } else { 55 | return [self convertPoint:point toView:nil]; 56 | } 57 | } 58 | 59 | UIWindow *from = [self isKindOfClass:[UIWindow class]] ? (id)self : self.window; 60 | UIWindow *to = [view isKindOfClass:[UIWindow class]] ? (id)view : view.window; 61 | if ((!from || !to) || (from == to)) return [self convertPoint:point toView:view]; 62 | point = [self convertPoint:point toView:from]; 63 | point = [to convertPoint:point fromWindow:from]; 64 | point = [view convertPoint:point fromView:to]; 65 | return point; 66 | } 67 | 68 | - (CGPoint)yy_convertPoint:(CGPoint)point fromViewOrWindow:(UIView *)view { 69 | if (!view) { 70 | if ([self isKindOfClass:[UIWindow class]]) { 71 | return [((UIWindow *)self) convertPoint:point fromWindow:nil]; 72 | } else { 73 | return [self convertPoint:point fromView:nil]; 74 | } 75 | } 76 | 77 | UIWindow *from = [view isKindOfClass:[UIWindow class]] ? (id)view : view.window; 78 | UIWindow *to = [self isKindOfClass:[UIWindow class]] ? (id)self : self.window; 79 | if ((!from || !to) || (from == to)) return [self convertPoint:point fromView:view]; 80 | point = [from convertPoint:point fromView:view]; 81 | point = [to convertPoint:point fromWindow:from]; 82 | point = [self convertPoint:point fromView:to]; 83 | return point; 84 | } 85 | 86 | - (CGRect)yy_convertRect:(CGRect)rect toViewOrWindow:(UIView *)view { 87 | if (!view) { 88 | if ([self isKindOfClass:[UIWindow class]]) { 89 | return [((UIWindow *)self) convertRect:rect toWindow:nil]; 90 | } else { 91 | return [self convertRect:rect toView:nil]; 92 | } 93 | } 94 | 95 | UIWindow *from = [self isKindOfClass:[UIWindow class]] ? (id)self : self.window; 96 | UIWindow *to = [view isKindOfClass:[UIWindow class]] ? (id)view : view.window; 97 | if (!from || !to) return [self convertRect:rect toView:view]; 98 | if (from == to) return [self convertRect:rect toView:view]; 99 | rect = [self convertRect:rect toView:from]; 100 | rect = [to convertRect:rect fromWindow:from]; 101 | rect = [view convertRect:rect fromView:to]; 102 | return rect; 103 | } 104 | 105 | - (CGRect)yy_convertRect:(CGRect)rect fromViewOrWindow:(UIView *)view { 106 | if (!view) { 107 | if ([self isKindOfClass:[UIWindow class]]) { 108 | return [((UIWindow *)self) convertRect:rect fromWindow:nil]; 109 | } else { 110 | return [self convertRect:rect fromView:nil]; 111 | } 112 | } 113 | 114 | UIWindow *from = [view isKindOfClass:[UIWindow class]] ? (id)view : view.window; 115 | UIWindow *to = [self isKindOfClass:[UIWindow class]] ? (id)self : self.window; 116 | if ((!from || !to) || (from == to)) return [self convertRect:rect fromView:view]; 117 | rect = [from convertRect:rect fromView:view]; 118 | rect = [to convertRect:rect fromWindow:from]; 119 | rect = [self convertRect:rect fromView:to]; 120 | return rect; 121 | } 122 | 123 | @end -------------------------------------------------------------------------------- /Pods/YYText/YYText/Utility/YYTextAsyncLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextAsyncLayer.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/11. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | #import 14 | 15 | @class YYTextAsyncLayerDisplayTask; 16 | 17 | NS_ASSUME_NONNULL_BEGIN 18 | 19 | /** 20 | The YYTextAsyncLayer class is a subclass of CALayer used for render contents asynchronously. 21 | 22 | @discussion When the layer need update it's contents, it will ask the delegate 23 | for a async display task to render the contents in a background queue. 24 | */ 25 | @interface YYTextAsyncLayer : CALayer 26 | /// Whether the render code is executed in background. Default is YES. 27 | @property BOOL displaysAsynchronously; 28 | @end 29 | 30 | 31 | /** 32 | The YYTextAsyncLayer's delegate protocol. The delegate of the YYTextAsyncLayer (typically a UIView) 33 | must implements the method in this protocol. 34 | */ 35 | @protocol YYTextAsyncLayerDelegate 36 | @required 37 | /// This method is called to return a new display task when the layer's contents need update. 38 | - (YYTextAsyncLayerDisplayTask *)newAsyncDisplayTask; 39 | @end 40 | 41 | 42 | /** 43 | A display task used by YYTextAsyncLayer to render the contents in background queue. 44 | */ 45 | @interface YYTextAsyncLayerDisplayTask : NSObject 46 | 47 | /** 48 | This block will be called before the asynchronous drawing begins. 49 | It will be called on the main thread. 50 | 51 | @param layer The layer. 52 | */ 53 | @property (nullable, nonatomic, copy) void (^willDisplay)(CALayer *layer); 54 | 55 | /** 56 | This block is called to draw the layer's contents. 57 | 58 | @discussion This block may be called on main thread or background thread, 59 | so is should be thread-safe. 60 | 61 | @param context A new bitmap content created by layer. 62 | @param size The content size (typically same as layer's bound size). 63 | @param isCancelled If this block returns `YES`, the method should cancel the 64 | drawing process and return as quickly as possible. 65 | */ 66 | @property (nullable, nonatomic, copy) void (^display)(CGContextRef context, CGSize size, BOOL(^isCancelled)(void)); 67 | 68 | /** 69 | This block will be called after the asynchronous drawing finished. 70 | It will be called on the main thread. 71 | 72 | @param layer The layer. 73 | @param finished If the draw process is cancelled, it's `NO`, otherwise it's `YES`; 74 | */ 75 | @property (nullable, nonatomic, copy) void (^didDisplay)(CALayer *layer, BOOL finished); 76 | 77 | @end 78 | 79 | NS_ASSUME_NONNULL_END 80 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Utility/YYTextAsyncLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextAsyncLayer.m 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/11. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYTextAsyncLayer.h" 13 | #import 14 | 15 | 16 | /// Global display queue, used for content rendering. 17 | static dispatch_queue_t YYTextAsyncLayerGetDisplayQueue() { 18 | #define MAX_QUEUE_COUNT 16 19 | static int queueCount; 20 | static dispatch_queue_t queues[MAX_QUEUE_COUNT]; 21 | static dispatch_once_t onceToken; 22 | static int32_t counter = 0; 23 | dispatch_once(&onceToken, ^{ 24 | queueCount = (int)[NSProcessInfo processInfo].activeProcessorCount; 25 | queueCount = queueCount < 1 ? 1 : queueCount > MAX_QUEUE_COUNT ? MAX_QUEUE_COUNT : queueCount; 26 | if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) { 27 | for (NSUInteger i = 0; i < queueCount; i++) { 28 | dispatch_queue_attr_t attr = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INITIATED, 0); 29 | queues[i] = dispatch_queue_create("com.ibireme.text.render", attr); 30 | } 31 | } else { 32 | for (NSUInteger i = 0; i < queueCount; i++) { 33 | queues[i] = dispatch_queue_create("com.ibireme.text.render", DISPATCH_QUEUE_SERIAL); 34 | dispatch_set_target_queue(queues[i], dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)); 35 | } 36 | } 37 | }); 38 | int32_t cur = OSAtomicIncrement32(&counter); 39 | if (cur < 0) cur = -cur; 40 | return queues[(cur) % queueCount]; 41 | #undef MAX_QUEUE_COUNT 42 | } 43 | 44 | static dispatch_queue_t YYTextAsyncLayerGetReleaseQueue() { 45 | #ifdef YYDispatchQueuePool_h 46 | return YYDispatchQueueGetForQOS(NSQualityOfServiceDefault); 47 | #else 48 | return dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0); 49 | #endif 50 | } 51 | 52 | 53 | /// a thread safe incrementing counter. 54 | @interface _YYTextSentinel : NSObject 55 | /// Returns the current value of the counter. 56 | @property (atomic, readonly) int32_t value; 57 | /// Increase the value atomically. @return The new value. 58 | - (int32_t)increase; 59 | @end 60 | 61 | @implementation _YYTextSentinel { 62 | int32_t _value; 63 | } 64 | - (int32_t)value { 65 | return _value; 66 | } 67 | - (int32_t)increase { 68 | return OSAtomicIncrement32(&_value); 69 | } 70 | @end 71 | 72 | 73 | @implementation YYTextAsyncLayerDisplayTask 74 | @end 75 | 76 | 77 | @implementation YYTextAsyncLayer { 78 | _YYTextSentinel *_sentinel; 79 | } 80 | 81 | #pragma mark - Override 82 | 83 | + (id)defaultValueForKey:(NSString *)key { 84 | if ([key isEqualToString:@"displaysAsynchronously"]) { 85 | return @(YES); 86 | } else { 87 | return [super defaultValueForKey:key]; 88 | } 89 | } 90 | 91 | - (instancetype)init { 92 | self = [super init]; 93 | static CGFloat scale; //global 94 | static dispatch_once_t onceToken; 95 | dispatch_once(&onceToken, ^{ 96 | scale = [UIScreen mainScreen].scale; 97 | }); 98 | self.contentsScale = scale; 99 | _sentinel = [_YYTextSentinel new]; 100 | _displaysAsynchronously = YES; 101 | return self; 102 | } 103 | 104 | - (void)dealloc { 105 | [_sentinel increase]; 106 | } 107 | 108 | - (void)setNeedsDisplay { 109 | [self _cancelAsyncDisplay]; 110 | [super setNeedsDisplay]; 111 | } 112 | 113 | - (void)display { 114 | super.contents = super.contents; 115 | [self _displayAsync:_displaysAsynchronously]; 116 | } 117 | 118 | #pragma mark - Private 119 | 120 | - (void)_displayAsync:(BOOL)async { 121 | __strong id delegate = self.delegate; 122 | YYTextAsyncLayerDisplayTask *task = [delegate newAsyncDisplayTask]; 123 | if (!task.display) { 124 | if (task.willDisplay) task.willDisplay(self); 125 | self.contents = nil; 126 | if (task.didDisplay) task.didDisplay(self, YES); 127 | return; 128 | } 129 | 130 | if (async) { 131 | if (task.willDisplay) task.willDisplay(self); 132 | _YYTextSentinel *sentinel = _sentinel; 133 | int32_t value = sentinel.value; 134 | BOOL (^isCancelled)() = ^BOOL() { 135 | return value != sentinel.value; 136 | }; 137 | CGSize size = self.bounds.size; 138 | BOOL opaque = self.opaque; 139 | CGFloat scale = self.contentsScale; 140 | CGColorRef backgroundColor = (opaque && self.backgroundColor) ? CGColorRetain(self.backgroundColor) : NULL; 141 | if (size.width < 1 || size.height < 1) { 142 | CGImageRef image = (__bridge_retained CGImageRef)(self.contents); 143 | self.contents = nil; 144 | if (image) { 145 | dispatch_async(YYTextAsyncLayerGetReleaseQueue(), ^{ 146 | CFRelease(image); 147 | }); 148 | } 149 | if (task.didDisplay) task.didDisplay(self, YES); 150 | CGColorRelease(backgroundColor); 151 | return; 152 | } 153 | 154 | dispatch_async(YYTextAsyncLayerGetDisplayQueue(), ^{ 155 | if (isCancelled()) { 156 | CGColorRelease(backgroundColor); 157 | return; 158 | } 159 | UIGraphicsBeginImageContextWithOptions(size, opaque, scale); 160 | CGContextRef context = UIGraphicsGetCurrentContext(); 161 | if (opaque) { 162 | CGContextSaveGState(context); { 163 | if (!backgroundColor || CGColorGetAlpha(backgroundColor) < 1) { 164 | CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); 165 | CGContextAddRect(context, CGRectMake(0, 0, size.width * scale, size.height * scale)); 166 | CGContextFillPath(context); 167 | } 168 | if (backgroundColor) { 169 | CGContextSetFillColorWithColor(context, backgroundColor); 170 | CGContextAddRect(context, CGRectMake(0, 0, size.width * scale, size.height * scale)); 171 | CGContextFillPath(context); 172 | } 173 | } CGContextRestoreGState(context); 174 | CGColorRelease(backgroundColor); 175 | } 176 | task.display(context, size, isCancelled); 177 | if (isCancelled()) { 178 | UIGraphicsEndImageContext(); 179 | dispatch_async(dispatch_get_main_queue(), ^{ 180 | if (task.didDisplay) task.didDisplay(self, NO); 181 | }); 182 | return; 183 | } 184 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 185 | UIGraphicsEndImageContext(); 186 | if (isCancelled()) { 187 | dispatch_async(dispatch_get_main_queue(), ^{ 188 | if (task.didDisplay) task.didDisplay(self, NO); 189 | }); 190 | return; 191 | } 192 | dispatch_async(dispatch_get_main_queue(), ^{ 193 | if (isCancelled()) { 194 | if (task.didDisplay) task.didDisplay(self, NO); 195 | } else { 196 | self.contents = (__bridge id)(image.CGImage); 197 | if (task.didDisplay) task.didDisplay(self, YES); 198 | } 199 | }); 200 | }); 201 | } else { 202 | [_sentinel increase]; 203 | if (task.willDisplay) task.willDisplay(self); 204 | UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, self.contentsScale); 205 | CGContextRef context = UIGraphicsGetCurrentContext(); 206 | if (self.opaque) { 207 | CGSize size = self.bounds.size; 208 | size.width *= self.contentsScale; 209 | size.height *= self.contentsScale; 210 | CGContextSaveGState(context); { 211 | if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) { 212 | CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); 213 | CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height)); 214 | CGContextFillPath(context); 215 | } 216 | if (self.backgroundColor) { 217 | CGContextSetFillColorWithColor(context, self.backgroundColor); 218 | CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height)); 219 | CGContextFillPath(context); 220 | } 221 | } CGContextRestoreGState(context); 222 | } 223 | task.display(context, self.bounds.size, ^{return NO;}); 224 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 225 | UIGraphicsEndImageContext(); 226 | self.contents = (__bridge id)(image.CGImage); 227 | if (task.didDisplay) task.didDisplay(self, YES); 228 | } 229 | } 230 | 231 | - (void)_cancelAsyncDisplay { 232 | [_sentinel increase]; 233 | } 234 | 235 | @end 236 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Utility/YYTextTransaction.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextTransaction.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/18. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | /** 17 | YYTextTransaction let you perform a selector once before current runloop sleep. 18 | */ 19 | @interface YYTextTransaction : NSObject 20 | 21 | /** 22 | Creates and returns a transaction with a specified target and selector. 23 | 24 | @param target A specified target, the target is retained until runloop end. 25 | @param selector A selector for target. 26 | 27 | @return A new transaction, or nil if an error occurs. 28 | */ 29 | + (YYTextTransaction *)transactionWithTarget:(id)target selector:(SEL)selector; 30 | 31 | /** 32 | Commit the trancaction to main runloop. 33 | 34 | @discussion It will perform the selector on the target once before main runloop's 35 | current loop sleep. If the same transaction (same target and same selector) has 36 | already commit to runloop in this loop, this method do nothing. 37 | */ 38 | - (void)commit; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Utility/YYTextTransaction.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextTransaction.m 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/18. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYTextTransaction.h" 13 | 14 | 15 | @interface YYTextTransaction() 16 | @property (nonatomic, strong) id target; 17 | @property (nonatomic, assign) SEL selector; 18 | @end 19 | 20 | static NSMutableSet *transactionSet = nil; 21 | 22 | static void YYRunLoopObserverCallBack(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) { 23 | if (transactionSet.count == 0) return; 24 | NSSet *currentSet = transactionSet; 25 | transactionSet = [NSMutableSet new]; 26 | [currentSet enumerateObjectsUsingBlock:^(YYTextTransaction *transaction, BOOL *stop) { 27 | #pragma clang diagnostic push 28 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 29 | [transaction.target performSelector:transaction.selector]; 30 | #pragma clang diagnostic pop 31 | }]; 32 | } 33 | 34 | static void YYTextTransactionSetup() { 35 | static dispatch_once_t onceToken; 36 | dispatch_once(&onceToken, ^{ 37 | transactionSet = [NSMutableSet new]; 38 | CFRunLoopRef runloop = CFRunLoopGetMain(); 39 | CFRunLoopObserverRef observer; 40 | 41 | observer = CFRunLoopObserverCreate(CFAllocatorGetDefault(), 42 | kCFRunLoopBeforeWaiting | kCFRunLoopExit, 43 | true, // repeat 44 | 0xFFFFFF, // after CATransaction(2000000) 45 | YYRunLoopObserverCallBack, NULL); 46 | CFRunLoopAddObserver(runloop, observer, kCFRunLoopCommonModes); 47 | CFRelease(observer); 48 | }); 49 | } 50 | 51 | 52 | @implementation YYTextTransaction 53 | 54 | + (YYTextTransaction *)transactionWithTarget:(id)target selector:(SEL)selector{ 55 | if (!target || !selector) return nil; 56 | YYTextTransaction *t = [YYTextTransaction new]; 57 | t.target = target; 58 | t.selector = selector; 59 | return t; 60 | } 61 | 62 | - (void)commit { 63 | if (!_target || !_selector) return; 64 | YYTextTransactionSetup(); 65 | [transactionSet addObject:self]; 66 | } 67 | 68 | - (NSUInteger)hash { 69 | long v1 = (long)((void *)_selector); 70 | long v2 = (long)_target; 71 | return v1 ^ v2; 72 | } 73 | 74 | - (BOOL)isEqual:(id)object { 75 | if (self == object) return YES; 76 | if (![object isMemberOfClass:self.class]) return NO; 77 | YYTextTransaction *other = object; 78 | return other.selector == _selector && other.target == _target; 79 | } 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Utility/YYTextUtilities.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextUtilities.m 3 | // YYText 4 | // 5 | // Created by ibireme on 15/4/6. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYTextUtilities.h" 13 | #import 14 | #import "UIView+YYText.h" 15 | 16 | NSCharacterSet *YYTextVerticalFormRotateCharacterSet() { 17 | static NSMutableCharacterSet *set; 18 | static dispatch_once_t onceToken; 19 | dispatch_once(&onceToken, ^{ 20 | set = [NSMutableCharacterSet new]; 21 | [set addCharactersInRange:NSMakeRange(0x1100, 256)]; // Hangul Jamo 22 | [set addCharactersInRange:NSMakeRange(0x2460, 160)]; // Enclosed Alphanumerics 23 | [set addCharactersInRange:NSMakeRange(0x2600, 256)]; // Miscellaneous Symbols 24 | [set addCharactersInRange:NSMakeRange(0x2700, 192)]; // Dingbats 25 | [set addCharactersInRange:NSMakeRange(0x2E80, 128)]; // CJK Radicals Supplement 26 | [set addCharactersInRange:NSMakeRange(0x2F00, 224)]; // Kangxi Radicals 27 | [set addCharactersInRange:NSMakeRange(0x2FF0, 16)]; // Ideographic Description Characters 28 | [set addCharactersInRange:NSMakeRange(0x3000, 64)]; // CJK Symbols and Punctuation 29 | [set removeCharactersInRange:NSMakeRange(0x3008, 10)]; 30 | [set removeCharactersInRange:NSMakeRange(0x3014, 12)]; 31 | [set addCharactersInRange:NSMakeRange(0x3040, 96)]; // Hiragana 32 | [set addCharactersInRange:NSMakeRange(0x30A0, 96)]; // Katakana 33 | [set addCharactersInRange:NSMakeRange(0x3100, 48)]; // Bopomofo 34 | [set addCharactersInRange:NSMakeRange(0x3130, 96)]; // Hangul Compatibility Jamo 35 | [set addCharactersInRange:NSMakeRange(0x3190, 16)]; // Kanbun 36 | [set addCharactersInRange:NSMakeRange(0x31A0, 32)]; // Bopomofo Extended 37 | [set addCharactersInRange:NSMakeRange(0x31C0, 48)]; // CJK Strokes 38 | [set addCharactersInRange:NSMakeRange(0x31F0, 16)]; // Katakana Phonetic Extensions 39 | [set addCharactersInRange:NSMakeRange(0x3200, 256)]; // Enclosed CJK Letters and Months 40 | [set addCharactersInRange:NSMakeRange(0x3300, 256)]; // CJK Compatibility 41 | [set addCharactersInRange:NSMakeRange(0x3400, 2582)]; // CJK Unified Ideographs Extension A 42 | [set addCharactersInRange:NSMakeRange(0x4E00, 20941)]; // CJK Unified Ideographs 43 | [set addCharactersInRange:NSMakeRange(0xAC00, 11172)]; // Hangul Syllables 44 | [set addCharactersInRange:NSMakeRange(0xD7B0, 80)]; // Hangul Jamo Extended-B 45 | [set addCharactersInString:@""]; // U+F8FF (Private Use Area) 46 | [set addCharactersInRange:NSMakeRange(0xF900, 512)]; // CJK Compatibility Ideographs 47 | [set addCharactersInRange:NSMakeRange(0xFE10, 16)]; // Vertical Forms 48 | [set addCharactersInRange:NSMakeRange(0xFF00, 240)]; // Halfwidth and Fullwidth Forms 49 | [set addCharactersInRange:NSMakeRange(0x1F200, 256)]; // Enclosed Ideographic Supplement 50 | [set addCharactersInRange:NSMakeRange(0x1F300, 768)]; // Enclosed Ideographic Supplement 51 | [set addCharactersInRange:NSMakeRange(0x1F600, 80)]; // Emoticons (Emoji) 52 | [set addCharactersInRange:NSMakeRange(0x1F680, 128)]; // Transport and Map Symbols 53 | 54 | // See http://unicode-table.com/ for more information. 55 | }); 56 | return set; 57 | } 58 | 59 | NSCharacterSet *YYTextVerticalFormRotateAndMoveCharacterSet() { 60 | static NSMutableCharacterSet *set; 61 | static dispatch_once_t onceToken; 62 | dispatch_once(&onceToken, ^{ 63 | set = [NSMutableCharacterSet new]; 64 | [set addCharactersInString:@",。、."]; 65 | }); 66 | return set; 67 | } 68 | 69 | // return 0 when succeed 70 | static int matrix_invert(__CLPK_integer N, double *matrix) { 71 | __CLPK_integer error = 0; 72 | __CLPK_integer pivot_tmp[6 * 6]; 73 | __CLPK_integer *pivot = pivot_tmp; 74 | double workspace_tmp[6 * 6]; 75 | double *workspace = workspace_tmp; 76 | bool need_free = false; 77 | 78 | if (N > 6) { 79 | need_free = true; 80 | pivot = malloc(N * N * sizeof(__CLPK_integer)); 81 | if (!pivot) return -1; 82 | workspace = malloc(N * sizeof(double)); 83 | if (!workspace) { 84 | free(pivot); 85 | return -1; 86 | } 87 | } 88 | 89 | dgetrf_(&N, &N, matrix, &N, pivot, &error); 90 | 91 | if (error == 0) { 92 | dgetri_(&N, matrix, &N, pivot, workspace, &N, &error); 93 | } 94 | 95 | if (need_free) { 96 | free(pivot); 97 | free(workspace); 98 | } 99 | return error; 100 | } 101 | 102 | CGAffineTransform YYTextCGAffineTransformGetFromPoints(CGPoint before[3], CGPoint after[3]) { 103 | if (before == NULL || after == NULL) return CGAffineTransformIdentity; 104 | 105 | CGPoint p1, p2, p3, q1, q2, q3; 106 | p1 = before[0]; p2 = before[1]; p3 = before[2]; 107 | q1 = after[0]; q2 = after[1]; q3 = after[2]; 108 | 109 | double A[36]; 110 | A[ 0] = p1.x; A[ 1] = p1.y; A[ 2] = 0; A[ 3] = 0; A[ 4] = 1; A[ 5] = 0; 111 | A[ 6] = 0; A[ 7] = 0; A[ 8] = p1.x; A[ 9] = p1.y; A[10] = 0; A[11] = 1; 112 | A[12] = p2.x; A[13] = p2.y; A[14] = 0; A[15] = 0; A[16] = 1; A[17] = 0; 113 | A[18] = 0; A[19] = 0; A[20] = p2.x; A[21] = p2.y; A[22] = 0; A[23] = 1; 114 | A[24] = p3.x; A[25] = p3.y; A[26] = 0; A[27] = 0; A[28] = 1; A[29] = 0; 115 | A[30] = 0; A[31] = 0; A[32] = p3.x; A[33] = p3.y; A[34] = 0; A[35] = 1; 116 | 117 | int error = matrix_invert(6, A); 118 | if (error) return CGAffineTransformIdentity; 119 | 120 | double B[6]; 121 | B[0] = q1.x; B[1] = q1.y; B[2] = q2.x; B[3] = q2.y; B[4] = q3.x; B[5] = q3.y; 122 | 123 | double M[6]; 124 | M[0] = A[ 0] * B[0] + A[ 1] * B[1] + A[ 2] * B[2] + A[ 3] * B[3] + A[ 4] * B[4] + A[ 5] * B[5]; 125 | M[1] = A[ 6] * B[0] + A[ 7] * B[1] + A[ 8] * B[2] + A[ 9] * B[3] + A[10] * B[4] + A[11] * B[5]; 126 | M[2] = A[12] * B[0] + A[13] * B[1] + A[14] * B[2] + A[15] * B[3] + A[16] * B[4] + A[17] * B[5]; 127 | M[3] = A[18] * B[0] + A[19] * B[1] + A[20] * B[2] + A[21] * B[3] + A[22] * B[4] + A[23] * B[5]; 128 | M[4] = A[24] * B[0] + A[25] * B[1] + A[26] * B[2] + A[27] * B[3] + A[28] * B[4] + A[29] * B[5]; 129 | M[5] = A[30] * B[0] + A[31] * B[1] + A[32] * B[2] + A[33] * B[3] + A[34] * B[4] + A[35] * B[5]; 130 | 131 | CGAffineTransform transform = CGAffineTransformMake(M[0], M[2], M[1], M[3], M[4], M[5]); 132 | return transform; 133 | } 134 | 135 | CGAffineTransform YYTextCGAffineTransformGetFromViews(UIView *from, UIView *to) { 136 | if (!from || !to) return CGAffineTransformIdentity; 137 | 138 | CGPoint before[3], after[3]; 139 | before[0] = CGPointMake(0, 0); 140 | before[1] = CGPointMake(0, 1); 141 | before[2] = CGPointMake(1, 0); 142 | after[0] = [from yy_convertPoint:before[0] toViewOrWindow:to]; 143 | after[1] = [from yy_convertPoint:before[1] toViewOrWindow:to]; 144 | after[2] = [from yy_convertPoint:before[2] toViewOrWindow:to]; 145 | 146 | return YYTextCGAffineTransformGetFromPoints(before, after); 147 | } 148 | 149 | UIViewContentMode YYTextCAGravityToUIViewContentMode(NSString *gravity) { 150 | static NSDictionary *dic; 151 | static dispatch_once_t onceToken; 152 | dispatch_once(&onceToken, ^{ 153 | dic = @{ kCAGravityCenter:@(UIViewContentModeCenter), 154 | kCAGravityTop:@(UIViewContentModeTop), 155 | kCAGravityBottom:@(UIViewContentModeBottom), 156 | kCAGravityLeft:@(UIViewContentModeLeft), 157 | kCAGravityRight:@(UIViewContentModeRight), 158 | kCAGravityTopLeft:@(UIViewContentModeTopLeft), 159 | kCAGravityTopRight:@(UIViewContentModeTopRight), 160 | kCAGravityBottomLeft:@(UIViewContentModeBottomLeft), 161 | kCAGravityBottomRight:@(UIViewContentModeBottomRight), 162 | kCAGravityResize:@(UIViewContentModeScaleToFill), 163 | kCAGravityResizeAspect:@(UIViewContentModeScaleAspectFit), 164 | kCAGravityResizeAspectFill:@(UIViewContentModeScaleAspectFill) }; 165 | }); 166 | if (!gravity) return UIViewContentModeScaleToFill; 167 | return (UIViewContentMode)((NSNumber *)dic[gravity]).integerValue; 168 | } 169 | 170 | NSString *YYTextUIViewContentModeToCAGravity(UIViewContentMode contentMode) { 171 | switch (contentMode) { 172 | case UIViewContentModeScaleToFill: return kCAGravityResize; 173 | case UIViewContentModeScaleAspectFit: return kCAGravityResizeAspect; 174 | case UIViewContentModeScaleAspectFill: return kCAGravityResizeAspectFill; 175 | case UIViewContentModeRedraw: return kCAGravityResize; 176 | case UIViewContentModeCenter: return kCAGravityCenter; 177 | case UIViewContentModeTop: return kCAGravityTop; 178 | case UIViewContentModeBottom: return kCAGravityBottom; 179 | case UIViewContentModeLeft: return kCAGravityLeft; 180 | case UIViewContentModeRight: return kCAGravityRight; 181 | case UIViewContentModeTopLeft: return kCAGravityTopLeft; 182 | case UIViewContentModeTopRight: return kCAGravityTopRight; 183 | case UIViewContentModeBottomLeft: return kCAGravityBottomLeft; 184 | case UIViewContentModeBottomRight: return kCAGravityBottomRight; 185 | default: return kCAGravityResize; 186 | } 187 | } 188 | 189 | CGRect YYTextCGRectFitWithContentMode(CGRect rect, CGSize size, UIViewContentMode mode) { 190 | rect = CGRectStandardize(rect); 191 | size.width = size.width < 0 ? -size.width : size.width; 192 | size.height = size.height < 0 ? -size.height : size.height; 193 | CGPoint center = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); 194 | switch (mode) { 195 | case UIViewContentModeScaleAspectFit: 196 | case UIViewContentModeScaleAspectFill: { 197 | if (rect.size.width < 0.01 || rect.size.height < 0.01 || 198 | size.width < 0.01 || size.height < 0.01) { 199 | rect.origin = center; 200 | rect.size = CGSizeZero; 201 | } else { 202 | CGFloat scale; 203 | if (mode == UIViewContentModeScaleAspectFit) { 204 | if (size.width / size.height < rect.size.width / rect.size.height) { 205 | scale = rect.size.height / size.height; 206 | } else { 207 | scale = rect.size.width / size.width; 208 | } 209 | } else { 210 | if (size.width / size.height < rect.size.width / rect.size.height) { 211 | scale = rect.size.width / size.width; 212 | } else { 213 | scale = rect.size.height / size.height; 214 | } 215 | } 216 | size.width *= scale; 217 | size.height *= scale; 218 | rect.size = size; 219 | rect.origin = CGPointMake(center.x - size.width * 0.5, center.y - size.height * 0.5); 220 | } 221 | } break; 222 | case UIViewContentModeCenter: { 223 | rect.size = size; 224 | rect.origin = CGPointMake(center.x - size.width * 0.5, center.y - size.height * 0.5); 225 | } break; 226 | case UIViewContentModeTop: { 227 | rect.origin.x = center.x - size.width * 0.5; 228 | rect.size = size; 229 | } break; 230 | case UIViewContentModeBottom: { 231 | rect.origin.x = center.x - size.width * 0.5; 232 | rect.origin.y += rect.size.height - size.height; 233 | rect.size = size; 234 | } break; 235 | case UIViewContentModeLeft: { 236 | rect.origin.y = center.y - size.height * 0.5; 237 | rect.size = size; 238 | } break; 239 | case UIViewContentModeRight: { 240 | rect.origin.y = center.y - size.height * 0.5; 241 | rect.origin.x += rect.size.width - size.width; 242 | rect.size = size; 243 | } break; 244 | case UIViewContentModeTopLeft: { 245 | rect.size = size; 246 | } break; 247 | case UIViewContentModeTopRight: { 248 | rect.origin.x += rect.size.width - size.width; 249 | rect.size = size; 250 | } break; 251 | case UIViewContentModeBottomLeft: { 252 | rect.origin.y += rect.size.height - size.height; 253 | rect.size = size; 254 | } break; 255 | case UIViewContentModeBottomRight: { 256 | rect.origin.x += rect.size.width - size.width; 257 | rect.origin.y += rect.size.height - size.height; 258 | rect.size = size; 259 | } break; 260 | case UIViewContentModeScaleToFill: 261 | case UIViewContentModeRedraw: 262 | default: { 263 | rect = rect; 264 | } 265 | } 266 | return rect; 267 | } 268 | 269 | CGFloat YYTextScreenScale() { 270 | static CGFloat scale; 271 | static dispatch_once_t onceToken; 272 | dispatch_once(&onceToken, ^{ 273 | scale = [UIScreen mainScreen].scale; 274 | }); 275 | return scale; 276 | } 277 | 278 | CGSize YYTextScreenSize() { 279 | static CGSize size; 280 | static dispatch_once_t onceToken; 281 | dispatch_once(&onceToken, ^{ 282 | size = [UIScreen mainScreen].bounds.size; 283 | if (size.height < size.width) { 284 | CGFloat tmp = size.height; 285 | size.height = size.width; 286 | size.width = tmp; 287 | } 288 | }); 289 | return size; 290 | } 291 | 292 | 293 | BOOL YYTextIsAppExtension() { 294 | static BOOL isAppExtension = NO; 295 | static dispatch_once_t onceToken; 296 | dispatch_once(&onceToken, ^{ 297 | Class cls = NSClassFromString(@"UIApplication"); 298 | if(!cls || ![cls respondsToSelector:@selector(sharedApplication)]) isAppExtension = YES; 299 | if ([[[NSBundle mainBundle] bundlePath] hasSuffix:@".appex"]) isAppExtension = YES; 300 | }); 301 | return isAppExtension; 302 | } 303 | 304 | UIApplication *YYTextSharedApplication() { 305 | #pragma clang diagnostic push 306 | #pragma clang diagnostic ignored "-Wundeclared-selector" 307 | return YYTextIsAppExtension() ? nil : [UIApplication performSelector:@selector(sharedApplication)]; 308 | #pragma clang diagnostic pop 309 | } 310 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Utility/YYTextWeakProxy.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextWeakProxy.h 3 | // YYText 4 | // 5 | // Created by ibireme on 14/10/18. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | /** 17 | A proxy used to hold a weak object. 18 | It can be used to avoid retain cycles, such as the target in NSTimer or CADisplayLink. 19 | 20 | sample code: 21 | 22 | @implementation MyView { 23 | NSTimer *_timer; 24 | } 25 | 26 | - (void)initTimer { 27 | YYTextWeakProxy *proxy = [YYTextWeakProxy proxyWithTarget:self]; 28 | _timer = [NSTimer timerWithTimeInterval:0.1 target:proxy selector:@selector(tick:) userInfo:nil repeats:YES]; 29 | } 30 | 31 | - (void)tick:(NSTimer *)timer {...} 32 | @end 33 | */ 34 | @interface YYTextWeakProxy : NSProxy 35 | 36 | /** 37 | The proxy target. 38 | */ 39 | @property (nullable, nonatomic, weak, readonly) id target; 40 | 41 | /** 42 | Creates a new weak proxy for target. 43 | 44 | @param target Target object. 45 | 46 | @return A new proxy object. 47 | */ 48 | - (instancetype)initWithTarget:(id)target; 49 | 50 | /** 51 | Creates a new weak proxy for target. 52 | 53 | @param target Target object. 54 | 55 | @return A new proxy object. 56 | */ 57 | + (instancetype)proxyWithTarget:(id)target; 58 | 59 | @end 60 | 61 | NS_ASSUME_NONNULL_END 62 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/Utility/YYTextWeakProxy.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextWeakProxy.m 3 | // YYText 4 | // 5 | // Created by ibireme on 14/10/18. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYTextWeakProxy.h" 13 | 14 | 15 | @implementation YYTextWeakProxy 16 | 17 | - (instancetype)initWithTarget:(id)target { 18 | _target = target; 19 | return self; 20 | } 21 | 22 | + (instancetype)proxyWithTarget:(id)target { 23 | return [[YYTextWeakProxy alloc] initWithTarget:target]; 24 | } 25 | 26 | - (id)forwardingTargetForSelector:(SEL)selector { 27 | return _target; 28 | } 29 | 30 | - (void)forwardInvocation:(NSInvocation *)invocation { 31 | void *null = NULL; 32 | [invocation setReturnValue:&null]; 33 | } 34 | 35 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)selector { 36 | return [NSObject instanceMethodSignatureForSelector:@selector(init)]; 37 | } 38 | 39 | - (BOOL)respondsToSelector:(SEL)aSelector { 40 | return [_target respondsToSelector:aSelector]; 41 | } 42 | 43 | - (BOOL)isEqual:(id)object { 44 | return [_target isEqual:object]; 45 | } 46 | 47 | - (NSUInteger)hash { 48 | return [_target hash]; 49 | } 50 | 51 | - (Class)superclass { 52 | return [_target superclass]; 53 | } 54 | 55 | - (Class)class { 56 | return [_target class]; 57 | } 58 | 59 | - (BOOL)isKindOfClass:(Class)aClass { 60 | return [_target isKindOfClass:aClass]; 61 | } 62 | 63 | - (BOOL)isMemberOfClass:(Class)aClass { 64 | return [_target isMemberOfClass:aClass]; 65 | } 66 | 67 | - (BOOL)conformsToProtocol:(Protocol *)aProtocol { 68 | return [_target conformsToProtocol:aProtocol]; 69 | } 70 | 71 | - (BOOL)isProxy { 72 | return YES; 73 | } 74 | 75 | - (NSString *)description { 76 | return [_target description]; 77 | } 78 | 79 | - (NSString *)debugDescription { 80 | return [_target debugDescription]; 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/YYLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYLabel.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/2/25. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | #if __has_include() 15 | #import 16 | #import 17 | #import 18 | #else 19 | #import "YYTextParser.h" 20 | #import "YYTextLayout.h" 21 | #import "YYTextAttribute.h" 22 | #endif 23 | 24 | NS_ASSUME_NONNULL_BEGIN 25 | 26 | #if !TARGET_INTERFACE_BUILDER 27 | 28 | /** 29 | The YYLabel class implements a read-only text view. 30 | 31 | @discussion The API and behavior is similar to UILabel, but provides more features: 32 | 33 | * It supports asynchronous layout and rendering (to avoid blocking UI thread). 34 | * It extends the CoreText attributes to support more text effects. 35 | * It allows to add UIImage, UIView and CALayer as text attachments. 36 | * It allows to add 'highlight' link to some range of text to allow user interact with. 37 | * It allows to add container path and exclusion paths to control text container's shape. 38 | * It supports vertical form layout to display CJK text. 39 | 40 | See NSAttributedString+YYText.h for more convenience methods to set the attributes. 41 | See YYTextAttribute.h and YYTextLayout.h for more information. 42 | */ 43 | @interface YYLabel : UIView 44 | 45 | #pragma mark - Accessing the Text Attributes 46 | ///============================================================================= 47 | /// @name Accessing the Text Attributes 48 | ///============================================================================= 49 | 50 | /** 51 | The text displayed by the label. Default is nil. 52 | Set a new value to this property also replaces the text in `attributedText`. 53 | Get the value returns the plain text in `attributedText`. 54 | */ 55 | @property (nullable, nonatomic, copy) NSString *text; 56 | 57 | /** 58 | The font of the text. Default is 17-point system font. 59 | Set a new value to this property also causes the new font to be applied to the entire `attributedText`. 60 | Get the value returns the font at the head of `attributedText`. 61 | */ 62 | @property (null_resettable, nonatomic, strong) UIFont *font; 63 | 64 | /** 65 | The color of the text. Default is black. 66 | Set a new value to this property also causes the new color to be applied to the entire `attributedText`. 67 | Get the value returns the color at the head of `attributedText`. 68 | */ 69 | @property (null_resettable, nonatomic, strong) UIColor *textColor; 70 | 71 | /** 72 | The shadow color of the text. Default is nil. 73 | Set a new value to this property also causes the shadow color to be applied to the entire `attributedText`. 74 | Get the value returns the shadow color at the head of `attributedText`. 75 | */ 76 | @property (nullable, nonatomic, strong) UIColor *shadowColor; 77 | 78 | /** 79 | The shadow offset of the text. Default is CGSizeZero. 80 | Set a new value to this property also causes the shadow offset to be applied to the entire `attributedText`. 81 | Get the value returns the shadow offset at the head of `attributedText`. 82 | */ 83 | @property (nonatomic) CGSize shadowOffset; 84 | 85 | /** 86 | The shadow blur of the text. Default is 0. 87 | Set a new value to this property also causes the shadow blur to be applied to the entire `attributedText`. 88 | Get the value returns the shadow blur at the head of `attributedText`. 89 | */ 90 | @property (nonatomic) CGFloat shadowBlurRadius; 91 | 92 | /** 93 | The technique to use for aligning the text. Default is NSTextAlignmentNatural. 94 | Set a new value to this property also causes the new alignment to be applied to the entire `attributedText`. 95 | Get the value returns the alignment at the head of `attributedText`. 96 | */ 97 | @property (nonatomic) NSTextAlignment textAlignment; 98 | 99 | /** 100 | The text vertical aligmnent in container. Default is YYTextVerticalAlignmentCenter. 101 | */ 102 | @property (nonatomic) YYTextVerticalAlignment textVerticalAlignment; 103 | 104 | /** 105 | The styled text displayed by the label. 106 | Set a new value to this property also replaces the value of the `text`, `font`, `textColor`, 107 | `textAlignment` and other properties in label. 108 | 109 | @discussion It only support the attributes declared in CoreText and YYTextAttribute. 110 | See `NSAttributedString+YYText` for more convenience methods to set the attributes. 111 | */ 112 | @property (nullable, nonatomic, copy) NSAttributedString *attributedText; 113 | 114 | /** 115 | The technique to use for wrapping and truncating the label's text. 116 | Default is NSLineBreakByTruncatingTail. 117 | */ 118 | @property (nonatomic) NSLineBreakMode lineBreakMode; 119 | 120 | /** 121 | The truncation token string used when text is truncated. Default is nil. 122 | When the value is nil, the label use "…" as default truncation token. 123 | */ 124 | @property (nullable, nonatomic, copy) NSAttributedString *truncationToken; 125 | 126 | /** 127 | The maximum number of lines to use for rendering text. Default value is 1. 128 | 0 means no limit. 129 | */ 130 | @property (nonatomic) NSUInteger numberOfLines; 131 | 132 | /** 133 | When `text` or `attributedText` is changed, the parser will be called to modify the text. 134 | It can be used to add code highlighting or emoticon replacement to text view. 135 | The default value is nil. 136 | 137 | See `YYTextParser` protocol for more information. 138 | */ 139 | @property (nullable, nonatomic, strong) id textParser; 140 | 141 | /** 142 | The current text layout in text view. It can be used to query the text layout information. 143 | Set a new value to this property also replaces most properties in this label, such as `text`, 144 | `color`, `attributedText`, `lineBreakMode`, `textContainerPath`, `exclusionPaths` and so on. 145 | */ 146 | @property (nullable, nonatomic, strong) YYTextLayout *textLayout; 147 | 148 | 149 | #pragma mark - Configuring the Text Container 150 | ///============================================================================= 151 | /// @name Configuring the Text Container 152 | ///============================================================================= 153 | 154 | /** 155 | A UIBezierPath object that specifies the shape of the text frame. Default value is nil. 156 | */ 157 | @property (nullable, nonatomic, copy) UIBezierPath *textContainerPath; 158 | 159 | /** 160 | An array of UIBezierPath objects representing the exclusion paths inside the 161 | receiver's bounding rectangle. Default value is nil. 162 | */ 163 | @property (nullable, nonatomic, copy) NSArray *exclusionPaths; 164 | 165 | /** 166 | The inset of the text container's layout area within the text view's content area. 167 | Default value is UIEdgeInsetsZero. 168 | */ 169 | @property (nonatomic) UIEdgeInsets textContainerInset; 170 | 171 | /** 172 | Whether the receiver's layout orientation is vertical form. Default is NO. 173 | It may used to display CJK text. 174 | */ 175 | @property (nonatomic, getter=isVerticalForm) BOOL verticalForm; 176 | 177 | /** 178 | The text line position modifier used to modify the lines' position in layout. 179 | Default value is nil. 180 | See `YYTextLinePositionModifier` protocol for more information. 181 | */ 182 | @property (nullable, nonatomic, copy) id linePositionModifier; 183 | 184 | /** 185 | The debug option to display CoreText layout result. 186 | The default value is [YYTextDebugOption sharedDebugOption]. 187 | */ 188 | @property (nullable, nonatomic, copy) YYTextDebugOption *debugOption; 189 | 190 | 191 | #pragma mark - Getting the Layout Constraints 192 | ///============================================================================= 193 | /// @name Getting the Layout Constraints 194 | ///============================================================================= 195 | 196 | /** 197 | The preferred maximum width (in points) for a multiline label. 198 | 199 | @discussion This property affects the size of the label when layout constraints 200 | are applied to it. During layout, if the text extends beyond the width 201 | specified by this property, the additional text is flowed to one or more new 202 | lines, thereby increasing the height of the label. If the text is vertical 203 | form, this value will match to text height. 204 | */ 205 | @property (nonatomic) CGFloat preferredMaxLayoutWidth; 206 | 207 | 208 | #pragma mark - Interacting with Text Data 209 | ///============================================================================= 210 | /// @name Interacting with Text Data 211 | ///============================================================================= 212 | 213 | /** 214 | When user tap the label, this action will be called (similar to tap gesture). 215 | The default value is nil. 216 | */ 217 | @property (nullable, nonatomic, copy) YYTextAction textTapAction; 218 | 219 | /** 220 | When user long press the label, this action will be called (similar to long press gesture). 221 | The default value is nil. 222 | */ 223 | @property (nullable, nonatomic, copy) YYTextAction textLongPressAction; 224 | 225 | /** 226 | When user tap the highlight range of text, this action will be called. 227 | The default value is nil. 228 | */ 229 | @property (nullable, nonatomic, copy) YYTextAction highlightTapAction; 230 | 231 | /** 232 | When user long press the highlight range of text, this action will be called. 233 | The default value is nil. 234 | */ 235 | @property (nullable, nonatomic, copy) YYTextAction highlightLongPressAction; 236 | 237 | 238 | #pragma mark - Configuring the Display Mode 239 | ///============================================================================= 240 | /// @name Configuring the Display Mode 241 | ///============================================================================= 242 | 243 | /** 244 | A Boolean value indicating whether the layout and rendering codes are running 245 | asynchronously on background threads. 246 | 247 | The default value is `NO`. 248 | */ 249 | @property (nonatomic) BOOL displaysAsynchronously; 250 | 251 | /** 252 | If the value is YES, and the layer is rendered asynchronously, then it will 253 | set label.layer.contents to nil before display. 254 | 255 | The default value is `YES`. 256 | 257 | @discussion When the asynchronously display is enabled, the layer's content will 258 | be updated after the background render process finished. If the render process 259 | can not finished in a vsync time (1/60 second), the old content will be still kept 260 | for display. You may manually clear the content by set the layer.contents to nil 261 | after you update the label's properties, or you can just set this property to YES. 262 | */ 263 | @property (nonatomic) BOOL clearContentsBeforeAsynchronouslyDisplay; 264 | 265 | /** 266 | If the value is YES, and the layer is rendered asynchronously, then it will add 267 | a fade animation on layer when the contents of layer changed. 268 | 269 | The default value is `YES`. 270 | */ 271 | @property (nonatomic) BOOL fadeOnAsynchronouslyDisplay; 272 | 273 | /** 274 | If the value is YES, then it will add a fade animation on layer when some range 275 | of text become highlighted. 276 | 277 | The default value is `YES`. 278 | */ 279 | @property (nonatomic) BOOL fadeOnHighlight; 280 | 281 | /** 282 | Ignore common properties (such as text, font, textColor, attributedText...) and 283 | only use "textLayout" to display content. 284 | 285 | The default value is `NO`. 286 | 287 | @discussion If you control the label content only through "textLayout", then 288 | you may set this value to YES for higher performance. 289 | */ 290 | @property (nonatomic) BOOL ignoreCommonProperties; 291 | 292 | /* 293 | Tips: 294 | 295 | 1. If you only need a UILabel alternative to display rich text and receive link touch event, 296 | you do not need to adjust the display mode properties. 297 | 298 | 2. If you have performance issues, you may enable the asynchronous display mode 299 | by setting the `displaysAsynchronously` to YES. 300 | 301 | 3. If you want to get the highest performance, you should do text layout with 302 | `YYTextLayout` class in background thread. Here's an example: 303 | 304 | YYLabel *label = [YYLabel new]; 305 | label.displaysAsynchronously = YES; 306 | label.ignoreCommonProperties = YES; 307 | 308 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 309 | 310 | // Create attributed string. 311 | NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"Some Text"]; 312 | text.yy_font = [UIFont systemFontOfSize:16]; 313 | text.yy_color = [UIColor grayColor]; 314 | [text yy_setColor:[UIColor redColor] range:NSMakeRange(0, 4)]; 315 | 316 | // Create text container 317 | YYTextContainer *container = [YYTextContainer new]; 318 | container.size = CGSizeMake(100, CGFLOAT_MAX); 319 | container.maximumNumberOfRows = 0; 320 | 321 | // Generate a text layout. 322 | YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:text]; 323 | 324 | dispatch_async(dispatch_get_main_queue(), ^{ 325 | label.size = layout.textBoundingSize; 326 | label.textLayout = layout; 327 | }); 328 | }); 329 | 330 | */ 331 | 332 | @end 333 | 334 | 335 | #else // TARGET_INTERFACE_BUILDER 336 | IB_DESIGNABLE 337 | @interface YYLabel : UIView 338 | @property (nullable, nonatomic, copy) IBInspectable NSString *text; 339 | @property (null_resettable, nonatomic, strong) IBInspectable UIColor *textColor; 340 | @property (nullable, nonatomic, strong) IBInspectable NSString *fontName_; 341 | @property (nonatomic) IBInspectable CGFloat fontSize_; 342 | @property (nonatomic) IBInspectable BOOL fontIsBold_; 343 | @property (nonatomic) IBInspectable NSUInteger numberOfLines; 344 | @property (nonatomic) IBInspectable NSInteger lineBreakMode; 345 | @property (nonatomic) IBInspectable CGFloat preferredMaxLayoutWidth; 346 | @property (nonatomic, getter=isVerticalForm) IBInspectable BOOL verticalForm; 347 | @property (nonatomic) IBInspectable NSInteger textAlignment; 348 | @property (nonatomic) IBInspectable NSInteger textVerticalAlignment; 349 | @property (nullable, nonatomic, strong) IBInspectable UIColor *shadowColor; 350 | @property (nonatomic) IBInspectable CGPoint shadowOffset; 351 | @property (nonatomic) IBInspectable CGFloat shadowBlurRadius; 352 | @property (nullable, nonatomic, copy) IBInspectable NSAttributedString *attributedText; 353 | @property (nonatomic) IBInspectable CGFloat insetTop_; 354 | @property (nonatomic) IBInspectable CGFloat insetBottom_; 355 | @property (nonatomic) IBInspectable CGFloat insetLeft_; 356 | @property (nonatomic) IBInspectable CGFloat insetRight_; 357 | @property (nonatomic) IBInspectable BOOL debugEnabled_; 358 | 359 | @property (null_resettable, nonatomic, strong) UIFont *font; 360 | @property (nullable, nonatomic, copy) NSAttributedString *truncationToken; 361 | @property (nullable, nonatomic, strong) id textParser; 362 | @property (nullable, nonatomic, strong) YYTextLayout *textLayout; 363 | @property (nullable, nonatomic, copy) UIBezierPath *textContainerPath; 364 | @property (nullable, nonatomic, copy) NSArray *exclusionPaths; 365 | @property (nonatomic) UIEdgeInsets textContainerInset; 366 | @property (nullable, nonatomic, copy) id linePositionModifier; 367 | @property (nonnull, nonatomic, copy) YYTextDebugOption *debugOption; 368 | @property (nullable, nonatomic, copy) YYTextAction textTapAction; 369 | @property (nullable, nonatomic, copy) YYTextAction textLongPressAction; 370 | @property (nullable, nonatomic, copy) YYTextAction highlightTapAction; 371 | @property (nullable, nonatomic, copy) YYTextAction highlightLongPressAction; 372 | @property (nonatomic) BOOL displaysAsynchronously; 373 | @property (nonatomic) BOOL clearContentsBeforeAsynchronouslyDisplay; 374 | @property (nonatomic) BOOL fadeOnAsynchronouslyDisplay; 375 | @property (nonatomic) BOOL fadeOnHighlight; 376 | @property (nonatomic) BOOL ignoreCommonProperties; 377 | @end 378 | #endif // !TARGET_INTERFACE_BUILDER 379 | 380 | NS_ASSUME_NONNULL_END 381 | -------------------------------------------------------------------------------- /Pods/YYText/YYText/YYText.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYText.h 3 | // YYText 4 | // 5 | // Created by ibireme on 15/2/25. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | #if __has_include() 15 | FOUNDATION_EXPORT double YYTextVersionNumber; 16 | FOUNDATION_EXPORT const unsigned char YYTextVersionString[]; 17 | #import 18 | #import 19 | #import 20 | #import 21 | #import 22 | #import 23 | #import 24 | #import 25 | #import 26 | #import 27 | #import 28 | #import 29 | #import 30 | #import 31 | #import 32 | #import 33 | #else 34 | #import "YYLabel.h" 35 | #import "YYTextView.h" 36 | #import "YYTextAttribute.h" 37 | #import "YYTextArchiver.h" 38 | #import "YYTextParser.h" 39 | #import "YYTextRunDelegate.h" 40 | #import "YYTextRubyAnnotation.h" 41 | #import "YYTextLayout.h" 42 | #import "YYTextLine.h" 43 | #import "YYTextInput.h" 44 | #import "YYTextDebugOption.h" 45 | #import "YYTextKeyboardManager.h" 46 | #import "YYTextUtilities.h" 47 | #import "NSAttributedString+YYText.h" 48 | #import "NSParagraphStyle+YYText.h" 49 | #import "UIPasteboard+YYText.h" 50 | #endif 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Demo of an issue in iOS 10. See screenshot below. 2 | 3 | iOS 9 works well: 4 | 5 | ![](https://raw.githubusercontent.com/onevcat/YYTextSample/master/iOS9.png) 6 | 7 | But fails in iOS 10: 8 | 9 | ![](https://raw.githubusercontent.com/onevcat/YYTextSample/master/iOS10.png) 10 | 11 | See the comment in ViewController.swift for more. -------------------------------------------------------------------------------- /YYTextSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /YYTextSample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /YYTextSample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // YYTextSample 4 | // 5 | // Created by WANG WEI on 2016/09/12. 6 | // Copyright © 2016年 OneV's Den. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /YYTextSample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /YYTextSample/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /YYTextSample/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /YYTextSample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /YYTextSample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // YYTextSample 4 | // 5 | // Created by WANG WEI on 2016/09/12. 6 | // Copyright © 2016年 OneV's Den. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import YYText 11 | 12 | class ViewController: UIViewController { 13 | 14 | override func viewDidLoad() { 15 | super.viewDidLoad() 16 | 17 | // This message will fail in iOS 10. 18 | let message = "あかさたなはまやらあかさたなはまや" 19 | 20 | // But this could work well by appending a space. 21 | // let message = "あかさたなはまやらあかさたなはまや " 22 | 23 | let messageFont = UIFont.systemFont(ofSize: 13.0) 24 | let messageAttr = message.attributedString(font: messageFont, textColor: .black) 25 | 26 | let name = "onevcat_live " 27 | let nameFont = UIFont.boldSystemFont(ofSize: 13.0) 28 | let result = NSMutableAttributedString(attributedString: name.attributedString(font: nameFont, textColor: .blue)) 29 | result.append(messageAttr) 30 | 31 | let width: CGFloat = 295.0 32 | 33 | let size = CGSize(width: width, height: CGFloat.greatestFiniteMagnitude) 34 | let layout = YYTextLayout(containerSize: size, text: result) 35 | 36 | let label = YYLabel(frame: CGRect(x: 0, y: 100, width: width, height: layout!.textBoundingSize.height)) 37 | label.numberOfLines = 0 38 | 39 | // Set the attributedText in iOS 10 will cause the issue. But it works well for iOS 9 40 | label.attributedText = result 41 | 42 | // Setting textLayout instead could solve the issue. 43 | // label.textLayout = layout 44 | 45 | label.backgroundColor = .red 46 | 47 | view.addSubview(label) 48 | } 49 | } 50 | 51 | extension String { 52 | func attributedString(font: UIFont, textColor: UIColor?) -> NSAttributedString { 53 | 54 | var attributes: [String: AnyObject] = [NSFontAttributeName: font] 55 | 56 | // If we do not add a font attribute, it works well. 57 | // var attributes: [String: AnyObject] = [:] 58 | 59 | if let color = textColor { 60 | attributes[NSForegroundColorAttributeName] = color 61 | } 62 | return NSAttributedString(string: self, attributes: attributes) 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /YYTextSampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /YYTextSampleTests/YYTextSampleTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // YYTextSampleTests.swift 3 | // YYTextSampleTests 4 | // 5 | // Created by WANG WEI on 2016/09/12. 6 | // Copyright © 2016年 OneV's Den. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import YYTextSample 11 | 12 | class YYTextSampleTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /iOS10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onevcat/YYTextSample/552cb722eaac5a16cb46ce772d329b62f2f807a4/iOS10.png -------------------------------------------------------------------------------- /iOS9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onevcat/YYTextSample/552cb722eaac5a16cb46ce772d329b62f2f807a4/iOS9.png --------------------------------------------------------------------------------