├── .clang-format ├── .gitignore ├── .kokoro ├── .travis.yml ├── BUILD ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── MDFTextAccessibility.podspec ├── MDFTextAccessibility.xcconfig ├── MDFTextAccessibility.xcodeproj ├── project.pbxproj └── xcshareddata │ └── xcschemes │ └── MDFTextAccessibility.xcscheme ├── Package.swift ├── README.md ├── WORKSPACE ├── examples └── apps │ └── MDFTextAccessibilitySample │ ├── MDFTextAccessibilitySample.xcodeproj │ └── project.pbxproj │ ├── MDFTextAccessibilitySample.xcworkspace │ └── contents.xcworkspacedata │ ├── MDFTextAccessibilitySample │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── ColorCollectionViewCell.swift │ ├── ColorCollectionViewHeader.swift │ ├── ColorsCollectionViewController.swift │ └── Info.plist │ ├── Podfile │ └── Podfile.lock ├── resources └── Info.plist ├── src ├── MDFTextAccessibility-Bridging-Header.h ├── MDFTextAccessibility.h ├── MDFTextAccessibility.m └── private │ ├── MDFColorCalculations.h │ ├── MDFColorCalculations.m │ ├── NSArray+MDFUtils.h │ └── NSArray+MDFUtils.m └── tests ├── resources ├── 100_100_black.png ├── 100_100_gray.png └── 100_100_white.png └── unit ├── Info.plist └── MDFTextAccessibilityUnitTests.swift /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | 3 | AllowShortFunctionsOnASingleLine: Inline 4 | AllowShortIfStatementsOnASingleLine: false 5 | AllowShortLoopsOnASingleLine: false 6 | AlwaysBreakBeforeMultilineStrings: false 7 | BinPackParameters: false 8 | ColumnLimit: 100 9 | ObjCSpaceBeforeProtocolList: true 10 | PointerBindsToType: false 11 | IndentWrappedFunctionNames: true 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bazel-* 2 | .kokoro-ios-runner 3 | 4 | # Xcode 5 | # 6 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 7 | 8 | # OS X System files 9 | .DS_Store 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 | # CocoaPods 37 | # 38 | # We recommend against adding the Pods directory to your .gitignore. However 39 | # you should judge for yourself, the pros and cons are mentioned at: 40 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 41 | # 42 | Pods/ 43 | 44 | # Carthage 45 | # 46 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 47 | # Carthage/Checkouts 48 | 49 | Carthage/Build 50 | 51 | # fastlane 52 | # 53 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 54 | # screenshots whenever they are needed. 55 | # For more information about the recommended setup visit: 56 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 57 | 58 | fastlane/report.xml 59 | fastlane/screenshots 60 | 61 | # Code Injection 62 | # 63 | # After new code Injection tools there's a generated folder /iOSInjectionProject 64 | # https://github.com/johnno1962/injectionforxcode 65 | 66 | iOSInjectionProject/ 67 | -------------------------------------------------------------------------------- /.kokoro: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2017-present The Material Foundation Authors. All Rights Reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Fail on any error. 18 | set -e 19 | 20 | # Display commands to stderr. 21 | set -x 22 | 23 | KOKORO_RUNNER_VERSION="v3.*" 24 | BAZEL_VERSION="0.20.0" 25 | 26 | fix_bazel_imports() { 27 | if [ -z "$KOKORO_BUILD_NUMBER" ]; then 28 | tests_dir_prefix="" 29 | else 30 | tests_dir_prefix="github/repo/" 31 | fi 32 | 33 | rewrite_source() { 34 | find "${stashed_dir}${tests_dir_prefix}tests/unit" -type f -name '*.swift' -exec sed -i '' -E "$1" {} + || true 35 | } 36 | 37 | stashed_dir="" 38 | rewrite_source "s/import MDFTextAccessibility/import _MDFTextAccessibility/" 39 | stashed_dir="$(pwd)/" 40 | reset_imports() { 41 | # Undoes our source changes from above. 42 | rewrite_source "s/import _MDFTextAccessibility/import MDFTextAccessibility/" 43 | } 44 | trap reset_imports EXIT 45 | } 46 | 47 | if [ ! -d .kokoro-ios-runner ]; then 48 | git clone https://github.com/material-foundation/kokoro-ios-runner.git .kokoro-ios-runner 49 | fi 50 | 51 | pushd .kokoro-ios-runner 52 | git fetch > /dev/null 53 | TAG=$(git tag --sort=v:refname -l "$KOKORO_RUNNER_VERSION" | tail -n1) 54 | git checkout "$TAG" > /dev/null 55 | popd 56 | 57 | fix_bazel_imports 58 | 59 | if [ -n "$KOKORO_BUILD_NUMBER" ]; then 60 | bazel version 61 | use_bazel.sh "$BAZEL_VERSION" 62 | bazel version 63 | fi 64 | 65 | ./.kokoro-ios-runner/bazel.sh test //:UnitTests 9.0.0 66 | 67 | echo "Success!" 68 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | osx_image: xcode8.2 3 | sudo: false 4 | # Only fire off builds for specific branches. 5 | branches: 6 | only: 7 | - develop 8 | - stable 9 | env: 10 | global: 11 | - LC_CTYPE=en_US.UTF-8 12 | - LANG=en_US.UTF-8 13 | matrix: 14 | - DESTINATION="platform=iOS Simulator,name=iPhone 7,OS=10.1" SDK="iphonesimulator10.2" 15 | before_install: 16 | - gem install xcpretty --no-rdoc --no-ri --no-document --quiet 17 | script: 18 | - set -o pipefail 19 | - xcodebuild -version 20 | - xcodebuild -showsdks 21 | - xcodebuild -project MDFTextAccessibility.xcodeproj -scheme MDFTextAccessibility -sdk "$SDK" -destination "$DESTINATION" -configuration Debug GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES ONLY_ACTIVE_ARCH=NO build test | xcpretty -c; 22 | after_success: 23 | - bash <(curl -s https://codecov.io/bash) 24 | -------------------------------------------------------------------------------- /BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2017-present The Material Foundation Authors. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test") 16 | load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") 17 | load("@bazel_ios_warnings//:strict_warnings_objc_library.bzl", "strict_warnings_objc_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | exports_files(["LICENSE"]) 22 | 23 | strict_warnings_objc_library( 24 | name = "MDFTextAccessibility", 25 | srcs = glob([ 26 | "src/*.m", 27 | "src/private/*.m", 28 | ]), 29 | hdrs = glob([ 30 | "src/*.h", 31 | "src/private/*.h", 32 | ]), 33 | enable_modules = 1, 34 | includes = ["src"], 35 | visibility = ["//visibility:public"], 36 | ) 37 | 38 | swift_library( 39 | name = "UnitTestsSwiftLib", 40 | srcs = glob([ 41 | "tests/unit/*.swift", 42 | ]), 43 | resources = glob(["tests/resources/*"]), 44 | deps = [":MDFTextAccessibility"], 45 | visibility = ["//visibility:private"], 46 | copts = ["-swift-version", "3"], 47 | ) 48 | 49 | ios_unit_test( 50 | name = "UnitTests", 51 | deps = [ 52 | ":UnitTestsSwiftLib" 53 | ], 54 | minimum_os_version = "8.2", 55 | timeout = "short", 56 | visibility = ["//visibility:private"], 57 | ) 58 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 2.0.1 2 | 3 | This patch release adds Swift Package Manager support. 4 | 5 | * [Adding SPM Support](https://github.com/material-foundation/material-text-accessibility-ios/commit/5b185245864e6b58d6b26dfbe5cd4447e4fda2b4) (DomenicBianchi01) 6 | * [Internal change](https://github.com/material-foundation/material-text-accessibility-ios/commit/191c0f3eb2b38b29d74338c891cf1acecc74bb44) (Andrew Overton) 7 | * [Internal change](https://github.com/material-foundation/material-text-accessibility-ios/commit/3f21de715f00813ddae1a5f7e9aa7dc8a1ff3ae1) (Andrew Overton) 8 | * [Internal change](https://github.com/material-foundation/material-text-accessibility-ios/commit/36ddff44400af3d906ba842d3edb6276d4454d60) (Andrew Overton) 9 | * [Internal change](https://github.com/material-foundation/material-text-accessibility-ios/commit/f5b3d221f3a633c5ddff5309141fee7d9e01a8bb) (Andrew Overton) 10 | 11 | # 2.0.0 12 | 13 | This major release upgrades the bazel dependencies and workspace. This change is breaking for anyone 14 | using bazel to build this library. In order to use this library with bazel, you will also need to 15 | upgrade your workspace versions to match the ones now used in this library's `WORKSPACE` file. 16 | 17 | * [Update bazel workspace to latest versions. (#22)](https://github.com/material-foundation/material-text-accessibility-ios/commit/f21e585f9e5991e0eb00de8c7c01fe995057c902) (featherless) 18 | 19 | # 1.2.1 20 | 21 | This patch release adds various build system-related files. 22 | 23 | ## Non-source changes 24 | 25 | * [Add missing Info.plist (#21)](https://github.com/material-foundation/material-text-accessibility-ios/commit/fc2a7cbbca2ac40fa6f09f34bf71033adc9d5308) (Louis Romero) 26 | * [Remove obsolete comment (#20)](https://github.com/material-foundation/material-text-accessibility-ios/commit/bac12cbbdacd11c0bb315359ec5373d08fc76fb8) (Brenton Simpson) 27 | * [Add support for kokoro and bazel continuous integration. (#19)](https://github.com/material-foundation/material-text-accessibility-ios/commit/fd570d71ae0124c75ad5af00e6b8b4b1668d5e40) (featherless) 28 | 29 | ## 1.2.0 30 | 31 | ### Enhancements 32 | 33 | * Add tvOS as a target plaform. 34 | 35 | ## 1.1.4 36 | 37 | ### Enhancements 38 | 39 | * Removed usage of header_mappings_dir. 40 | * Ran swift 3 update for example. 41 | 42 | ## 1.1.3 43 | 44 | ### Enhancements 45 | 46 | * Fixed unused variable warning when NS_BLOCK_ASSERTIONS is defined ([Adrian Secord](https://github.com/ajsecord)). 47 | 48 | ## 1.1.2 49 | 50 | ### Enhancements 51 | 52 | * Added better warning coverage and fixed a documentation problem ([Adrian Secord](https://github.com/ajsecord)). 53 | 54 | ## 1.1.1 55 | 56 | ### Enhancements 57 | 58 | * Added support for continuous code coverage analysis ([Sean O'Shea](https://github.com/seanoshea)). 59 | * Added unit tests for textColorOnBackgroundImage ([Sean O'Shea](https://github.com/seanoshea)). 60 | * Documentation clean ups ([Sean O'Shea](https://github.com/seanoshea)). 61 | 62 | ## 1.1.0 63 | 64 | ### Enhancements 65 | 66 | * Added a `isLargeForContrastRatios:` advanced method to test a UIFont instance against the W3C's 67 | definition of "large" text. 68 | 69 | ## 1.0.2 70 | 71 | ### Bug Fixes 72 | 73 | * Updated authors in the podspec to properly refer to Google. 74 | 75 | ## 1.0.1 76 | 77 | ### Bug Fixes 78 | 79 | * Fixed podspec issues. 80 | 81 | ## 1.0.0 82 | 83 | Initial release. 84 | 85 | ## x.x.x 86 | 87 | This is a template. When cutting a new release, rename "stable" to the release number and create a 88 | new, empty "Master" section. 89 | 90 | ### Breaking 91 | 92 | ### Enhancements 93 | 94 | ### Bug Fixes 95 | 96 | * This is a template description 97 | [person responsible](https://github.com/...) 98 | [#xxx](github.com/google/material-text-accessibility-ios/issues/xxx) 99 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Want to contribute? Great! First, read this page (including the [small print](#the-small-print)). 2 | 3 | ### Before you contribute 4 | 5 | Before we can use your code, you must sign the 6 | [Google Individual Contributor License Agreement](https://cla.developers.google.com/about/google-individual) 7 | (CLA), which you can do online. The CLA is necessary mainly because you own the copyright to your 8 | changes, even after your contribution becomes part of our codebase, so we need your permission to 9 | use and distribute your code. We also need to be sure of various other things—for instance that 10 | you'll tell us if you know that your code infringes on other people's patents. You don't have to 11 | sign the CLA until after you've submitted your code for review and a member has approved it, but you 12 | must do it before we can put your code into our codebase. Before you start working on a larger 13 | contribution, you should get in touch with us first through the issue tracker with your idea so that 14 | we can help out and possibly guide you. Coordinating up front makes it much easier to avoid 15 | frustration later on. 16 | 17 | ### Code reviews 18 | 19 | All submissions, including submissions by project members, require review. We use Github pull 20 | requests for this purpose. 21 | 22 | ### The small print 23 | 24 | Contributions made by corporations are covered by a different agreement than the one above, the 25 | [Software Grant and Corporate Contributor License Agreement](https://cla.developers.google.com/about/google-corporate). 26 | 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /MDFTextAccessibility.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |spec| 2 | spec.name = "MDFTextAccessibility" 3 | spec.version = "2.0.1" 4 | spec.summary = "MDFTextAccessibility assists in selecting text colors that meet the W3C standards for accessibility." 5 | spec.homepage = "https://github.com/google/material-text-accessibility-ios" 6 | spec.license = "Apache License, Version 2.0" 7 | spec.authors = "Google Inc." 8 | spec.source = { :git => "https://github.com/google/material-text-accessibility-ios.git", :tag => "v#{spec.version}" } 9 | spec.platform = :ios,:tvos 10 | spec.source_files = "src/*.{h,m}", "src/private/*.{h,m}" 11 | spec.public_header_files = "src/MDFTextAccessibility.h" 12 | spec.private_header_files = "src/private/*.h" 13 | spec.header_dir = "MDFTextAccessibility" 14 | spec.ios.deployment_target = '11.0' 15 | spec.tvos.deployment_target = '12.0' 16 | end 17 | -------------------------------------------------------------------------------- /MDFTextAccessibility.xcconfig: -------------------------------------------------------------------------------- 1 | // https://pewpewthespells.com/blog/xcconfig_guide.html 2 | // 3 | // This list is derived from 4 | // http://programmers.stackexchange.com/questions/122608/clang-warning-flags-for-objective-c-development 5 | // 6 | // Overall warning settings: the 'all' and 'extra' classes plus convert warnings into errors. 7 | // -Wall, // Standard known-to-be-bugs warnings. 8 | // -Wextra, // Many useful extra warnings. 9 | // -Werror, // All warnings as errors. 10 | // 11 | // Deprecation support: without these one can't rationally deprecate things. 12 | // -Wno-error=deprecated, // Deprecation warnings are never errors. 13 | // -Wno-error=deprecated-implementations, // Deprecation warnings are never errors. 14 | // 15 | // Useful warnings that are not in the 'all' and 'extra' classes. 16 | // -Wcast-align, // Casting a pointer such that alignment is broken. 17 | // -Wconversion, // Numeric conversion warnings. 18 | // -Wdocumentation, // Warn when documentation is out of date. 19 | // -Wformat=2, // Check printf-style format strings more strictly. 20 | // -Wimplicit-atomic-properties, // Dynamic properties should be non-atomic. 21 | // -Wmissing-declarations, // Warn if a global function is defined without a previous declaration. 22 | // -Wmissing-prototypes, // Global function is defined without a previous prototype. 23 | // -Wno-unused-parameter, // Do not warn on unused parameters. 24 | // -Woverlength-strings, // Strings longer than the C maximum. 25 | // -Wshadow, // Local variable shadows another variable, parameter, etc. 26 | // -Wstrict-selector-match, // Compiler can't figure out the right selector. 27 | // -Wundeclared-selector, // Compiler doesn't see a selector. 28 | // -Wunreachable-code, // Code will never be reached. 29 | WARNING_CFLAGS = $(inherited) -Wall -Wextra -Werror -Wno-error=deprecated -Wno-error=deprecated-implementations -Wcast-align -Wconversion -Wdocumentation -Wformat=2 -Wimplicit-atomic-properties -Wmissing-declarations -Wmissing-prototypes -Wno-unused-parameter -Woverlength-strings -Wshadow -Wstrict-selector-match -Wundeclared-selector -Wunreachable-code 30 | -------------------------------------------------------------------------------- /MDFTextAccessibility.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0B06FEF41CE6342C00244A36 /* MDFColorCalculations.m in Sources */ = {isa = PBXBuildFile; fileRef = 0B06FEF31CE6342C00244A36 /* MDFColorCalculations.m */; }; 11 | 0B2890E91CE2732B009E605A /* MDFTextAccessibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 0B2890D91CE272B6009E605A /* MDFTextAccessibility.m */; }; 12 | 0BDAE3D81CECC649003323B9 /* NSArray+MDFUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BDAE3D71CECC649003323B9 /* NSArray+MDFUtils.m */; }; 13 | 0BDAE3DA1CECD231003323B9 /* MDFImageCalculations.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BDAE3D91CECD231003323B9 /* MDFImageCalculations.m */; }; 14 | 0BDAE3E51CECD3A6003323B9 /* libMDFTextAccessibility.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B2890DF1CE2730C009E605A /* libMDFTextAccessibility.a */; }; 15 | 0BF99E7A1CF4F39200E6F9B9 /* MDFTextAccessibilityUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BF99E781CF4F36300E6F9B9 /* MDFTextAccessibilityUnitTests.swift */; }; 16 | 414705A51D4D54CE00F983B8 /* 100_100_black.png in Resources */ = {isa = PBXBuildFile; fileRef = 414705A21D4D545400F983B8 /* 100_100_black.png */; }; 17 | 414705A61D4D54CE00F983B8 /* 100_100_gray.png in Resources */ = {isa = PBXBuildFile; fileRef = 414705A31D4D545400F983B8 /* 100_100_gray.png */; }; 18 | 414705A71D4D54CE00F983B8 /* 100_100_white.png in Resources */ = {isa = PBXBuildFile; fileRef = 414705A41D4D545400F983B8 /* 100_100_white.png */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 0BDAE3E61CECD3A6003323B9 /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 0B2890D31CE27291009E605A /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 0B2890DE1CE2730C009E605A; 27 | remoteInfo = MDFTextAccessibility; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXCopyFilesBuildPhase section */ 32 | 0B2890DD1CE2730C009E605A /* CopyFiles */ = { 33 | isa = PBXCopyFilesBuildPhase; 34 | buildActionMask = 2147483647; 35 | dstPath = "include/$(PRODUCT_NAME)"; 36 | dstSubfolderSpec = 16; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXCopyFilesBuildPhase section */ 42 | 43 | /* Begin PBXFileReference section */ 44 | 0B06FEE81CE3908C00244A36 /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = ""; }; 45 | 0B06FEE91CE3908C00244A36 /* CONTRIBUTING.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTING.md; sourceTree = ""; }; 46 | 0B06FEEA1CE3908C00244A36 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; 47 | 0B06FEEB1CE3908C00244A36 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 48 | 0B06FEF21CE6342C00244A36 /* MDFColorCalculations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MDFColorCalculations.h; sourceTree = ""; }; 49 | 0B06FEF31CE6342C00244A36 /* MDFColorCalculations.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MDFColorCalculations.m; sourceTree = ""; }; 50 | 0B2890D91CE272B6009E605A /* MDFTextAccessibility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = MDFTextAccessibility.m; path = src/MDFTextAccessibility.m; sourceTree = SOURCE_ROOT; }; 51 | 0B2890DA1CE272B6009E605A /* MDFTextAccessibility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MDFTextAccessibility.h; path = src/MDFTextAccessibility.h; sourceTree = SOURCE_ROOT; }; 52 | 0B2890DF1CE2730C009E605A /* libMDFTextAccessibility.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMDFTextAccessibility.a; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | 0B96D67A1D5CD06100491BDC /* MDFTextAccessibility.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = MDFTextAccessibility.xcconfig; sourceTree = ""; }; 54 | 0BDAE3D61CECC62D003323B9 /* NSArray+MDFUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSArray+MDFUtils.h"; sourceTree = ""; }; 55 | 0BDAE3D71CECC649003323B9 /* NSArray+MDFUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+MDFUtils.m"; sourceTree = ""; }; 56 | 0BDAE3D91CECD231003323B9 /* MDFImageCalculations.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MDFImageCalculations.m; sourceTree = ""; }; 57 | 0BDAE3DB1CECD256003323B9 /* MDFImageCalculations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MDFImageCalculations.h; sourceTree = ""; }; 58 | 0BDAE3E01CECD3A6003323B9 /* MDFTextAccessibilityUnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MDFTextAccessibilityUnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 59 | 0BDAE3E41CECD3A6003323B9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 60 | 0BDAE3EB1CECD4BC003323B9 /* MDFTextAccessibility-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MDFTextAccessibility-Bridging-Header.h"; sourceTree = ""; }; 61 | 0BDAE3EE1CECD7E2003323B9 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = ""; }; 62 | 0BF99E781CF4F36300E6F9B9 /* MDFTextAccessibilityUnitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MDFTextAccessibilityUnitTests.swift; sourceTree = ""; }; 63 | 414705A21D4D545400F983B8 /* 100_100_black.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 100_100_black.png; sourceTree = ""; }; 64 | 414705A31D4D545400F983B8 /* 100_100_gray.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 100_100_gray.png; sourceTree = ""; }; 65 | 414705A41D4D545400F983B8 /* 100_100_white.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 100_100_white.png; sourceTree = ""; }; 66 | /* End PBXFileReference section */ 67 | 68 | /* Begin PBXFrameworksBuildPhase section */ 69 | 0B2890DC1CE2730C009E605A /* Frameworks */ = { 70 | isa = PBXFrameworksBuildPhase; 71 | buildActionMask = 2147483647; 72 | files = ( 73 | ); 74 | runOnlyForDeploymentPostprocessing = 0; 75 | }; 76 | 0BDAE3DD1CECD3A6003323B9 /* Frameworks */ = { 77 | isa = PBXFrameworksBuildPhase; 78 | buildActionMask = 2147483647; 79 | files = ( 80 | 0BDAE3E51CECD3A6003323B9 /* libMDFTextAccessibility.a in Frameworks */, 81 | ); 82 | runOnlyForDeploymentPostprocessing = 0; 83 | }; 84 | /* End PBXFrameworksBuildPhase section */ 85 | 86 | /* Begin PBXGroup section */ 87 | 0B06FEF11CE6341500244A36 /* private */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 0B06FEF21CE6342C00244A36 /* MDFColorCalculations.h */, 91 | 0B06FEF31CE6342C00244A36 /* MDFColorCalculations.m */, 92 | 0BDAE3DB1CECD256003323B9 /* MDFImageCalculations.h */, 93 | 0BDAE3D91CECD231003323B9 /* MDFImageCalculations.m */, 94 | 0BDAE3D61CECC62D003323B9 /* NSArray+MDFUtils.h */, 95 | 0BDAE3D71CECC649003323B9 /* NSArray+MDFUtils.m */, 96 | ); 97 | path = private; 98 | sourceTree = ""; 99 | }; 100 | 0B1450FA1CE373B70087403D /* tests */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | 414705A11D4D541400F983B8 /* resources */, 104 | 0BDAE3E11CECD3A6003323B9 /* unit */, 105 | ); 106 | path = tests; 107 | sourceTree = ""; 108 | }; 109 | 0B2890D21CE27291009E605A = { 110 | isa = PBXGroup; 111 | children = ( 112 | 0B06FEE81CE3908C00244A36 /* CHANGELOG.md */, 113 | 0B06FEE91CE3908C00244A36 /* CONTRIBUTING.md */, 114 | 0B06FEEA1CE3908C00244A36 /* LICENSE */, 115 | 0B06FEEB1CE3908C00244A36 /* README.md */, 116 | 0B96D67A1D5CD06100491BDC /* MDFTextAccessibility.xcconfig */, 117 | 0B2890E11CE2730C009E605A /* src */, 118 | 0B1450FA1CE373B70087403D /* tests */, 119 | FE2B30D3B645564E163F0C71 /* Frameworks */, 120 | 0B2890E01CE2730C009E605A /* Products */, 121 | ); 122 | sourceTree = ""; 123 | }; 124 | 0B2890E01CE2730C009E605A /* Products */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | 0B2890DF1CE2730C009E605A /* libMDFTextAccessibility.a */, 128 | 0BDAE3E01CECD3A6003323B9 /* MDFTextAccessibilityUnitTests.xctest */, 129 | ); 130 | name = Products; 131 | sourceTree = ""; 132 | }; 133 | 0B2890E11CE2730C009E605A /* src */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | 0BDAE3EB1CECD4BC003323B9 /* MDFTextAccessibility-Bridging-Header.h */, 137 | 0B2890DA1CE272B6009E605A /* MDFTextAccessibility.h */, 138 | 0B2890D91CE272B6009E605A /* MDFTextAccessibility.m */, 139 | 0BDAE3EE1CECD7E2003323B9 /* module.modulemap */, 140 | 0B06FEF11CE6341500244A36 /* private */, 141 | ); 142 | path = src; 143 | sourceTree = SOURCE_ROOT; 144 | }; 145 | 0BDAE3E11CECD3A6003323B9 /* unit */ = { 146 | isa = PBXGroup; 147 | children = ( 148 | 0BF99E781CF4F36300E6F9B9 /* MDFTextAccessibilityUnitTests.swift */, 149 | 0BDAE3E41CECD3A6003323B9 /* Info.plist */, 150 | ); 151 | path = unit; 152 | sourceTree = ""; 153 | }; 154 | 414705A11D4D541400F983B8 /* resources */ = { 155 | isa = PBXGroup; 156 | children = ( 157 | 414705A21D4D545400F983B8 /* 100_100_black.png */, 158 | 414705A31D4D545400F983B8 /* 100_100_gray.png */, 159 | 414705A41D4D545400F983B8 /* 100_100_white.png */, 160 | ); 161 | path = resources; 162 | sourceTree = ""; 163 | }; 164 | FE2B30D3B645564E163F0C71 /* Frameworks */ = { 165 | isa = PBXGroup; 166 | children = ( 167 | ); 168 | name = Frameworks; 169 | sourceTree = ""; 170 | }; 171 | /* End PBXGroup section */ 172 | 173 | /* Begin PBXNativeTarget section */ 174 | 0B2890DE1CE2730C009E605A /* MDFTextAccessibility */ = { 175 | isa = PBXNativeTarget; 176 | buildConfigurationList = 0B2890E61CE2730C009E605A /* Build configuration list for PBXNativeTarget "MDFTextAccessibility" */; 177 | buildPhases = ( 178 | 0B2890DB1CE2730C009E605A /* Sources */, 179 | 0B2890DC1CE2730C009E605A /* Frameworks */, 180 | 0B2890DD1CE2730C009E605A /* CopyFiles */, 181 | ); 182 | buildRules = ( 183 | ); 184 | dependencies = ( 185 | ); 186 | name = MDFTextAccessibility; 187 | productName = MDFTextAccessibility; 188 | productReference = 0B2890DF1CE2730C009E605A /* libMDFTextAccessibility.a */; 189 | productType = "com.apple.product-type.library.static"; 190 | }; 191 | 0BDAE3DF1CECD3A6003323B9 /* MDFTextAccessibilityUnitTests */ = { 192 | isa = PBXNativeTarget; 193 | buildConfigurationList = 0BDAE3E81CECD3A6003323B9 /* Build configuration list for PBXNativeTarget "MDFTextAccessibilityUnitTests" */; 194 | buildPhases = ( 195 | 0BDAE3DC1CECD3A6003323B9 /* Sources */, 196 | 0BDAE3DD1CECD3A6003323B9 /* Frameworks */, 197 | 0BDAE3DE1CECD3A6003323B9 /* Resources */, 198 | ); 199 | buildRules = ( 200 | ); 201 | dependencies = ( 202 | 0BDAE3E71CECD3A6003323B9 /* PBXTargetDependency */, 203 | ); 204 | name = MDFTextAccessibilityUnitTests; 205 | productName = MDFTextAccessibilityUnitTests; 206 | productReference = 0BDAE3E01CECD3A6003323B9 /* MDFTextAccessibilityUnitTests.xctest */; 207 | productType = "com.apple.product-type.bundle.unit-test"; 208 | }; 209 | /* End PBXNativeTarget section */ 210 | 211 | /* Begin PBXProject section */ 212 | 0B2890D31CE27291009E605A /* Project object */ = { 213 | isa = PBXProject; 214 | attributes = { 215 | LastSwiftUpdateCheck = 0730; 216 | LastUpgradeCheck = 0730; 217 | TargetAttributes = { 218 | 0B2890DE1CE2730C009E605A = { 219 | CreatedOnToolsVersion = 7.3; 220 | LastSwiftMigration = 0800; 221 | }; 222 | 0BDAE3DF1CECD3A6003323B9 = { 223 | CreatedOnToolsVersion = 7.2; 224 | LastSwiftMigration = 0800; 225 | }; 226 | }; 227 | }; 228 | buildConfigurationList = 0B2890D61CE27291009E605A /* Build configuration list for PBXProject "MDFTextAccessibility" */; 229 | compatibilityVersion = "Xcode 3.2"; 230 | developmentRegion = English; 231 | hasScannedForEncodings = 0; 232 | knownRegions = ( 233 | en, 234 | ); 235 | mainGroup = 0B2890D21CE27291009E605A; 236 | productRefGroup = 0B2890E01CE2730C009E605A /* Products */; 237 | projectDirPath = ""; 238 | projectRoot = ""; 239 | targets = ( 240 | 0B2890DE1CE2730C009E605A /* MDFTextAccessibility */, 241 | 0BDAE3DF1CECD3A6003323B9 /* MDFTextAccessibilityUnitTests */, 242 | ); 243 | }; 244 | /* End PBXProject section */ 245 | 246 | /* Begin PBXResourcesBuildPhase section */ 247 | 0BDAE3DE1CECD3A6003323B9 /* Resources */ = { 248 | isa = PBXResourcesBuildPhase; 249 | buildActionMask = 2147483647; 250 | files = ( 251 | 414705A61D4D54CE00F983B8 /* 100_100_gray.png in Resources */, 252 | 414705A71D4D54CE00F983B8 /* 100_100_white.png in Resources */, 253 | 414705A51D4D54CE00F983B8 /* 100_100_black.png in Resources */, 254 | ); 255 | runOnlyForDeploymentPostprocessing = 0; 256 | }; 257 | /* End PBXResourcesBuildPhase section */ 258 | 259 | /* Begin PBXSourcesBuildPhase section */ 260 | 0B2890DB1CE2730C009E605A /* Sources */ = { 261 | isa = PBXSourcesBuildPhase; 262 | buildActionMask = 2147483647; 263 | files = ( 264 | 0B2890E91CE2732B009E605A /* MDFTextAccessibility.m in Sources */, 265 | 0B06FEF41CE6342C00244A36 /* MDFColorCalculations.m in Sources */, 266 | 0BDAE3D81CECC649003323B9 /* NSArray+MDFUtils.m in Sources */, 267 | 0BDAE3DA1CECD231003323B9 /* MDFImageCalculations.m in Sources */, 268 | ); 269 | runOnlyForDeploymentPostprocessing = 0; 270 | }; 271 | 0BDAE3DC1CECD3A6003323B9 /* Sources */ = { 272 | isa = PBXSourcesBuildPhase; 273 | buildActionMask = 2147483647; 274 | files = ( 275 | 0BF99E7A1CF4F39200E6F9B9 /* MDFTextAccessibilityUnitTests.swift in Sources */, 276 | ); 277 | runOnlyForDeploymentPostprocessing = 0; 278 | }; 279 | /* End PBXSourcesBuildPhase section */ 280 | 281 | /* Begin PBXTargetDependency section */ 282 | 0BDAE3E71CECD3A6003323B9 /* PBXTargetDependency */ = { 283 | isa = PBXTargetDependency; 284 | target = 0B2890DE1CE2730C009E605A /* MDFTextAccessibility */; 285 | targetProxy = 0BDAE3E61CECD3A6003323B9 /* PBXContainerItemProxy */; 286 | }; 287 | /* End PBXTargetDependency section */ 288 | 289 | /* Begin XCBuildConfiguration section */ 290 | 0B2890D71CE27291009E605A /* Debug */ = { 291 | isa = XCBuildConfiguration; 292 | baseConfigurationReference = 0B96D67A1D5CD06100491BDC /* MDFTextAccessibility.xcconfig */; 293 | buildSettings = { 294 | ENABLE_TESTABILITY = YES; 295 | GCC_TREAT_WARNINGS_AS_ERRORS = YES; 296 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 297 | ONLY_ACTIVE_ARCH = YES; 298 | WARNING_CFLAGS = "-Wall"; 299 | }; 300 | name = Debug; 301 | }; 302 | 0B2890D81CE27291009E605A /* Release */ = { 303 | isa = XCBuildConfiguration; 304 | baseConfigurationReference = 0B96D67A1D5CD06100491BDC /* MDFTextAccessibility.xcconfig */; 305 | buildSettings = { 306 | GCC_TREAT_WARNINGS_AS_ERRORS = YES; 307 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 308 | WARNING_CFLAGS = "-Wall"; 309 | }; 310 | name = Release; 311 | }; 312 | 0B2890E71CE2730C009E605A /* Debug */ = { 313 | isa = XCBuildConfiguration; 314 | baseConfigurationReference = 0B96D67A1D5CD06100491BDC /* MDFTextAccessibility.xcconfig */; 315 | buildSettings = { 316 | ALWAYS_SEARCH_USER_PATHS = NO; 317 | CLANG_ANALYZER_NONNULL = YES; 318 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 319 | CLANG_CXX_LIBRARY = "libc++"; 320 | CLANG_ENABLE_MODULES = YES; 321 | CLANG_ENABLE_OBJC_ARC = YES; 322 | CLANG_WARN_BOOL_CONVERSION = YES; 323 | CLANG_WARN_CONSTANT_CONVERSION = YES; 324 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 325 | CLANG_WARN_EMPTY_BODY = YES; 326 | CLANG_WARN_ENUM_CONVERSION = YES; 327 | CLANG_WARN_INT_CONVERSION = YES; 328 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 329 | CLANG_WARN_UNREACHABLE_CODE = YES; 330 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 331 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 332 | COPY_PHASE_STRIP = NO; 333 | DEBUG_INFORMATION_FORMAT = dwarf; 334 | ENABLE_STRICT_OBJC_MSGSEND = YES; 335 | ENABLE_TESTABILITY = YES; 336 | GCC_C_LANGUAGE_STANDARD = gnu99; 337 | GCC_DYNAMIC_NO_PIC = NO; 338 | GCC_GENERATE_TEST_COVERAGE_FILES = YES; 339 | GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES; 340 | GCC_NO_COMMON_BLOCKS = YES; 341 | GCC_OPTIMIZATION_LEVEL = 0; 342 | GCC_PREPROCESSOR_DEFINITIONS = ( 343 | "DEBUG=1", 344 | "$(inherited)", 345 | ); 346 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 347 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 348 | GCC_WARN_UNDECLARED_SELECTOR = YES; 349 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 350 | GCC_WARN_UNUSED_FUNCTION = YES; 351 | GCC_WARN_UNUSED_VARIABLE = YES; 352 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 353 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 354 | MODULEMAP_FILE = src/module.modulemap; 355 | MTL_ENABLE_DEBUG_INFO = YES; 356 | ONLY_ACTIVE_ARCH = YES; 357 | OTHER_LDFLAGS = ( 358 | "$(inherited)", 359 | "-ObjC", 360 | ); 361 | PRODUCT_NAME = "$(TARGET_NAME)"; 362 | SDKROOT = iphoneos; 363 | SKIP_INSTALL = YES; 364 | SWIFT_OBJC_BRIDGING_HEADER = "tests/unit/MDFTextAccessibility-Bridging-Header.h"; 365 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 366 | SWIFT_VERSION = 3.0; 367 | }; 368 | name = Debug; 369 | }; 370 | 0B2890E81CE2730C009E605A /* Release */ = { 371 | isa = XCBuildConfiguration; 372 | baseConfigurationReference = 0B96D67A1D5CD06100491BDC /* MDFTextAccessibility.xcconfig */; 373 | buildSettings = { 374 | ALWAYS_SEARCH_USER_PATHS = NO; 375 | CLANG_ANALYZER_NONNULL = YES; 376 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 377 | CLANG_CXX_LIBRARY = "libc++"; 378 | CLANG_ENABLE_CODE_COVERAGE = NO; 379 | CLANG_ENABLE_MODULES = YES; 380 | CLANG_ENABLE_OBJC_ARC = YES; 381 | CLANG_WARN_BOOL_CONVERSION = YES; 382 | CLANG_WARN_CONSTANT_CONVERSION = YES; 383 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 384 | CLANG_WARN_EMPTY_BODY = YES; 385 | CLANG_WARN_ENUM_CONVERSION = YES; 386 | CLANG_WARN_INT_CONVERSION = YES; 387 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 388 | CLANG_WARN_UNREACHABLE_CODE = YES; 389 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 390 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 391 | COPY_PHASE_STRIP = NO; 392 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 393 | ENABLE_NS_ASSERTIONS = NO; 394 | ENABLE_STRICT_OBJC_MSGSEND = YES; 395 | GCC_C_LANGUAGE_STANDARD = gnu99; 396 | GCC_NO_COMMON_BLOCKS = YES; 397 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 398 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 399 | GCC_WARN_UNDECLARED_SELECTOR = YES; 400 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 401 | GCC_WARN_UNUSED_FUNCTION = YES; 402 | GCC_WARN_UNUSED_VARIABLE = YES; 403 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 404 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 405 | MODULEMAP_FILE = src/module.modulemap; 406 | MTL_ENABLE_DEBUG_INFO = NO; 407 | OTHER_LDFLAGS = ( 408 | "$(inherited)", 409 | "-ObjC", 410 | ); 411 | PRODUCT_NAME = "$(TARGET_NAME)"; 412 | SDKROOT = iphoneos; 413 | SKIP_INSTALL = YES; 414 | SWIFT_OBJC_BRIDGING_HEADER = "tests/unit/MDFTextAccessibility-Bridging-Header.h"; 415 | SWIFT_VERSION = 3.0; 416 | VALIDATE_PRODUCT = YES; 417 | }; 418 | name = Release; 419 | }; 420 | 0BDAE3E91CECD3A6003323B9 /* Debug */ = { 421 | isa = XCBuildConfiguration; 422 | baseConfigurationReference = 0B96D67A1D5CD06100491BDC /* MDFTextAccessibility.xcconfig */; 423 | buildSettings = { 424 | ALWAYS_SEARCH_USER_PATHS = NO; 425 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 426 | CLANG_CXX_LIBRARY = "libc++"; 427 | CLANG_ENABLE_MODULES = YES; 428 | CLANG_ENABLE_OBJC_ARC = YES; 429 | CLANG_WARN_BOOL_CONVERSION = YES; 430 | CLANG_WARN_CONSTANT_CONVERSION = YES; 431 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 432 | CLANG_WARN_EMPTY_BODY = YES; 433 | CLANG_WARN_ENUM_CONVERSION = YES; 434 | CLANG_WARN_INT_CONVERSION = YES; 435 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 436 | CLANG_WARN_UNREACHABLE_CODE = YES; 437 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 438 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 439 | COPY_PHASE_STRIP = NO; 440 | DEBUG_INFORMATION_FORMAT = dwarf; 441 | ENABLE_STRICT_OBJC_MSGSEND = YES; 442 | ENABLE_TESTABILITY = YES; 443 | GCC_C_LANGUAGE_STANDARD = gnu99; 444 | GCC_DYNAMIC_NO_PIC = NO; 445 | GCC_NO_COMMON_BLOCKS = YES; 446 | GCC_OPTIMIZATION_LEVEL = 0; 447 | GCC_PREPROCESSOR_DEFINITIONS = ( 448 | "DEBUG=1", 449 | "$(inherited)", 450 | ); 451 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 452 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 453 | GCC_WARN_UNDECLARED_SELECTOR = YES; 454 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 455 | GCC_WARN_UNUSED_FUNCTION = YES; 456 | GCC_WARN_UNUSED_VARIABLE = YES; 457 | INFOPLIST_FILE = tests/unit/Info.plist; 458 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 459 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 460 | MTL_ENABLE_DEBUG_INFO = YES; 461 | ONLY_ACTIVE_ARCH = YES; 462 | OTHER_LDFLAGS = ( 463 | "$(inherited)", 464 | "-ObjC", 465 | ); 466 | PRODUCT_BUNDLE_IDENTIFIER = com.google.MDFTextAccessibilityUnitTests; 467 | PRODUCT_NAME = "$(TARGET_NAME)"; 468 | SDKROOT = iphoneos; 469 | SWIFT_INCLUDE_PATHS = src; 470 | SWIFT_OBJC_BRIDGING_HEADER = "src/MDFTextAccessibility-Bridging-Header.h"; 471 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 472 | SWIFT_VERSION = 3.0; 473 | }; 474 | name = Debug; 475 | }; 476 | 0BDAE3EA1CECD3A6003323B9 /* Release */ = { 477 | isa = XCBuildConfiguration; 478 | baseConfigurationReference = 0B96D67A1D5CD06100491BDC /* MDFTextAccessibility.xcconfig */; 479 | buildSettings = { 480 | ALWAYS_SEARCH_USER_PATHS = NO; 481 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 482 | CLANG_CXX_LIBRARY = "libc++"; 483 | CLANG_ENABLE_MODULES = YES; 484 | CLANG_ENABLE_OBJC_ARC = YES; 485 | CLANG_WARN_BOOL_CONVERSION = YES; 486 | CLANG_WARN_CONSTANT_CONVERSION = YES; 487 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 488 | CLANG_WARN_EMPTY_BODY = YES; 489 | CLANG_WARN_ENUM_CONVERSION = YES; 490 | CLANG_WARN_INT_CONVERSION = YES; 491 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 492 | CLANG_WARN_UNREACHABLE_CODE = YES; 493 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 494 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 495 | COPY_PHASE_STRIP = NO; 496 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 497 | ENABLE_NS_ASSERTIONS = NO; 498 | ENABLE_STRICT_OBJC_MSGSEND = YES; 499 | GCC_C_LANGUAGE_STANDARD = gnu99; 500 | GCC_NO_COMMON_BLOCKS = YES; 501 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 502 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 503 | GCC_WARN_UNDECLARED_SELECTOR = YES; 504 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 505 | GCC_WARN_UNUSED_FUNCTION = YES; 506 | GCC_WARN_UNUSED_VARIABLE = YES; 507 | INFOPLIST_FILE = tests/unit/Info.plist; 508 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 509 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 510 | MTL_ENABLE_DEBUG_INFO = NO; 511 | OTHER_LDFLAGS = ( 512 | "$(inherited)", 513 | "-ObjC", 514 | ); 515 | PRODUCT_BUNDLE_IDENTIFIER = com.google.MDFTextAccessibilityUnitTests; 516 | PRODUCT_NAME = "$(TARGET_NAME)"; 517 | SDKROOT = iphoneos; 518 | SWIFT_INCLUDE_PATHS = src; 519 | SWIFT_OBJC_BRIDGING_HEADER = "src/MDFTextAccessibility-Bridging-Header.h"; 520 | SWIFT_VERSION = 3.0; 521 | VALIDATE_PRODUCT = YES; 522 | }; 523 | name = Release; 524 | }; 525 | /* End XCBuildConfiguration section */ 526 | 527 | /* Begin XCConfigurationList section */ 528 | 0B2890D61CE27291009E605A /* Build configuration list for PBXProject "MDFTextAccessibility" */ = { 529 | isa = XCConfigurationList; 530 | buildConfigurations = ( 531 | 0B2890D71CE27291009E605A /* Debug */, 532 | 0B2890D81CE27291009E605A /* Release */, 533 | ); 534 | defaultConfigurationIsVisible = 0; 535 | defaultConfigurationName = Release; 536 | }; 537 | 0B2890E61CE2730C009E605A /* Build configuration list for PBXNativeTarget "MDFTextAccessibility" */ = { 538 | isa = XCConfigurationList; 539 | buildConfigurations = ( 540 | 0B2890E71CE2730C009E605A /* Debug */, 541 | 0B2890E81CE2730C009E605A /* Release */, 542 | ); 543 | defaultConfigurationIsVisible = 0; 544 | defaultConfigurationName = Release; 545 | }; 546 | 0BDAE3E81CECD3A6003323B9 /* Build configuration list for PBXNativeTarget "MDFTextAccessibilityUnitTests" */ = { 547 | isa = XCConfigurationList; 548 | buildConfigurations = ( 549 | 0BDAE3E91CECD3A6003323B9 /* Debug */, 550 | 0BDAE3EA1CECD3A6003323B9 /* Release */, 551 | ); 552 | defaultConfigurationIsVisible = 0; 553 | defaultConfigurationName = Release; 554 | }; 555 | /* End XCConfigurationList section */ 556 | }; 557 | rootObject = 0B2890D31CE27291009E605A /* Project object */; 558 | } 559 | -------------------------------------------------------------------------------- /MDFTextAccessibility.xcodeproj/xcshareddata/xcschemes/MDFTextAccessibility.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 34 | 40 | 41 | 42 | 43 | 44 | 50 | 51 | 52 | 53 | 54 | 55 | 65 | 66 | 72 | 73 | 74 | 75 | 76 | 77 | 83 | 84 | 90 | 91 | 92 | 93 | 95 | 96 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.3 2 | 3 | // Copyright 2020-present the Material Text Accessibility for iOS authors. All Rights Reserved. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | 17 | import PackageDescription 18 | 19 | let package = Package( 20 | name: "MDFTextAccessibility", 21 | platforms: [ 22 | .iOS("8.0"), .tvOS("9.0") 23 | ], 24 | products: [ 25 | .library(name: "MDFTextAccessibility", targets: ["MDFTextAccessibility"]) 26 | ], 27 | targets: [ 28 | .target( 29 | name: "MDFTextAccessibility", 30 | path: "src", 31 | publicHeadersPath: ".") 32 | ] 33 | ) 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | MDFTextAccessibility assists in selecting text colors that will meet the 2 | [W3C standards for accessibility](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html). 3 | 4 | [![Build Status](https://travis-ci.org/material-foundation/material-text-accessibility-ios.svg?branch=develop)](https://travis-ci.org/material-foundation/material-text-accessibility-ios) 5 | [![Code Coverage](http://codecov.io/github/material-foundation/material-text-accessibility-ios/coverage.svg?branch=develop)](http://codecov.io/github/material-foundation/material-text-accessibility-ios?branch=develop) 6 | 7 | ## Accessibility of text 8 | 9 | Apps created for the widest range of users should ensure that users can read 10 | text presented over any background. While the legibility of text depends on many 11 | things, a great start is to provide a sufficiently large *contrast ratio* 12 | between foreground text colors and their background colors. The contrast ratio 13 | of two colors is a measurement of how much the brightness of two colors differ. 14 | For example, white on dark grey might have a contrast ratio of 9:1, while white 15 | on medium grey might only have a contrast ratio of 4:1. In general, larger 16 | contrast ratios are better and will ensure the widest range of users can easily 17 | read the text in your app. 18 | 19 | The [W3C](https://www.w3.org)'s 20 | [Web Content Accessibility Guidelines](https://www.w3.org/TR/WCAG/#visual-audio-contrast) 21 | contains two recommendations for text contrast ratios: 22 | 23 | 1. Minimum contrast: text should have a contrast ratio of at least 4.5:1, 24 | except for "large" text, which can have a contrast ratio of 3:1. 25 | 2. Enhanced contrast: text should have a contrast ratio of at least 7:1, except 26 | for large text, which can have a contrast ratio of 4.5:1. 27 | 28 | "Large" text is nominally defined as at least 18pt in a normal font face or at 29 | least 14pt in a bold font face. For more information (including some important 30 | exceptions), see the 31 | [Guidelines](https://www.w3.org/TR/WCAG/#visual-audio-contrast). 32 | 33 | ## Computing contrast ratios 34 | 35 | Computing acceptable contrast ratios involves the foreground color, the 36 | background color, the text size, and the transparency of the foreground color, 37 | if any. MDFTextAccessibility provides convenient access to colors that will 38 | automatically give acceptable contrast ratios. 39 | 40 | For methods that return a UIColor, the color along with its alpha is guaranteed 41 | to provide a contrast ratio meeting the minimum ratios recommended by the W3C. 42 | The returned alpha may be greater than the requested alpha to ensure acceptable 43 | contrast ratios, that is, the returned color may be more opaque than requested 44 | to ensure that the text remains legible. 45 | 46 | ## Legible text on images 47 | 48 | Displaying text legibly on arbitrary images is difficult because the image 49 | content can conflict with the text. Images with smooth gradients or blurred 50 | regions are likely to result in more legible text; images with many details and 51 | high contrast are less likely to result in legible text. 52 | 53 | MDFTextAccessibility provides methods that attempt to select a good color for 54 | displaying text on a particular image, but the quality of the results will 55 | depend on the contents of the image. If the content of the image is not known 56 | (for example, when images provided by the user), then consider using a 57 | semi-transparent shim between the image and the text to increase contrast. 58 | 59 | ## Usage 60 | 61 | ### Basic usage 62 | 63 | The simplest usage is to select between black and white text depending on the 64 | background color, irrespective of the font: 65 | 66 | ```objective-c 67 | label.textColor = [MDFTextAccessibility textColorOnBackgroundColor:label.backgroundColor 68 | textAlpha:1 69 | font:nil]; 70 | ``` 71 | 72 | Many design standards for user interfaces use text colors that are not fully 73 | opaque. However, transparent text can reduce legibility, so you can request a 74 | color that is as close as possible to a particular alpha value while still being 75 | legible: 76 | 77 | ```objective-c 78 | label.textColor = [MDFTextAccessibility textColorOnBackgroundColor:label.backgroundColor 79 | targetTextAlpha:0.85 80 | font:nil]; 81 | ``` 82 | 83 | Since the W3C recommends different contrast ratios for "normal" and "large" 84 | text, including the font can result in a text color closer to your target alpha 85 | when appropriate: 86 | 87 | ```objective-c 88 | label.textColor = [MDFTextAccessibility textColorOnBackgroundColor:label.backgroundColor 89 | textAlpha:0.85 90 | font:label.font]; 91 | ``` 92 | 93 | ### Advanced usage 94 | 95 | For more advanced usage, such as selecting from a set of colors other than white 96 | and black, see MDFTextAccessibility's 97 | `textColorFromChoices:onBackgroundColor:options:`. 98 | 99 | ## License 100 | 101 | MDFTextAccessiblity is licensed under the [Apache License Version 2.0](LICENSE). 102 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | # Copyright 2017-present The Material Foundation Authors. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") 16 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") 17 | 18 | git_repository( 19 | name = "build_bazel_rules_apple", 20 | remote = "https://github.com/bazelbuild/rules_apple.git", 21 | tag = "0.9.0", 22 | ) 23 | 24 | load( 25 | "@build_bazel_rules_apple//apple:repositories.bzl", 26 | "apple_rules_dependencies", 27 | ) 28 | 29 | apple_rules_dependencies() 30 | 31 | git_repository( 32 | name = "build_bazel_rules_swift", 33 | remote = "https://github.com/bazelbuild/rules_swift.git", 34 | tag = "0.4.0", 35 | ) 36 | 37 | load( 38 | "@build_bazel_rules_swift//swift:repositories.bzl", 39 | "swift_rules_dependencies", 40 | ) 41 | 42 | swift_rules_dependencies() 43 | 44 | git_repository( 45 | name = "bazel_ios_warnings", 46 | remote = "https://github.com/material-foundation/bazel_ios_warnings.git", 47 | tag = "v2.0.1", 48 | ) 49 | 50 | http_file( 51 | name = "xctestrunner", 52 | executable = 1, 53 | urls = ["https://github.com/google/xctestrunner/releases/download/0.2.5/ios_test_runner.par"], 54 | ) 55 | -------------------------------------------------------------------------------- /examples/apps/MDFTextAccessibilitySample/MDFTextAccessibilitySample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0B70BDC21CF6541C00C78D36 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B70BDC11CF6541C00C78D36 /* AppDelegate.swift */; }; 11 | 0B70BDC71CF6541C00C78D36 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0B70BDC51CF6541C00C78D36 /* Main.storyboard */; }; 12 | 0B70BDC91CF6541C00C78D36 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0B70BDC81CF6541C00C78D36 /* Assets.xcassets */; }; 13 | 0B70BDCC1CF6541C00C78D36 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0B70BDCA1CF6541C00C78D36 /* LaunchScreen.storyboard */; }; 14 | 0B70BDD61CF65B3400C78D36 /* ColorsCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B70BDD51CF65B3400C78D36 /* ColorsCollectionViewController.swift */; }; 15 | 0B70BDD81CF663B100C78D36 /* ColorCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B70BDD71CF663B100C78D36 /* ColorCollectionViewCell.swift */; }; 16 | 0BFC043A1CF7830C00567F1C /* ColorCollectionViewHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BFC04391CF7830C00567F1C /* ColorCollectionViewHeader.swift */; }; 17 | F849D7387CAE64E85D55003B /* Pods_MDFTextAccessibilitySample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AAEDF7C81A76FAF311AB1A07 /* Pods_MDFTextAccessibilitySample.framework */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 0B70BDBE1CF6541C00C78D36 /* MDFTextAccessibilitySample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MDFTextAccessibilitySample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 0B70BDC11CF6541C00C78D36 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | 0B70BDC61CF6541C00C78D36 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 24 | 0B70BDC81CF6541C00C78D36 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | 0B70BDCB1CF6541C00C78D36 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 26 | 0B70BDCD1CF6541C00C78D36 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | 0B70BDD51CF65B3400C78D36 /* ColorsCollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorsCollectionViewController.swift; sourceTree = ""; }; 28 | 0B70BDD71CF663B100C78D36 /* ColorCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorCollectionViewCell.swift; sourceTree = ""; }; 29 | 0BFC04391CF7830C00567F1C /* ColorCollectionViewHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorCollectionViewHeader.swift; sourceTree = ""; }; 30 | 1AE1DC46C109323BE9E1BC97 /* Pods-MDFTextAccessibilitySample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MDFTextAccessibilitySample.release.xcconfig"; path = "Pods/Target Support Files/Pods-MDFTextAccessibilitySample/Pods-MDFTextAccessibilitySample.release.xcconfig"; sourceTree = ""; }; 31 | 837EE15AAD1298DCA1BF2E20 /* Pods-MDFTextAccessibilitySample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MDFTextAccessibilitySample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-MDFTextAccessibilitySample/Pods-MDFTextAccessibilitySample.debug.xcconfig"; sourceTree = ""; }; 32 | AAEDF7C81A76FAF311AB1A07 /* Pods_MDFTextAccessibilitySample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MDFTextAccessibilitySample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | 0B70BDBB1CF6541C00C78D36 /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | F849D7387CAE64E85D55003B /* Pods_MDFTextAccessibilitySample.framework in Frameworks */, 41 | ); 42 | runOnlyForDeploymentPostprocessing = 0; 43 | }; 44 | /* End PBXFrameworksBuildPhase section */ 45 | 46 | /* Begin PBXGroup section */ 47 | 0B70BDB51CF6541C00C78D36 = { 48 | isa = PBXGroup; 49 | children = ( 50 | 0B70BDC01CF6541C00C78D36 /* MDFTextAccessibilitySample */, 51 | 0B70BDBF1CF6541C00C78D36 /* Products */, 52 | E4FEF74BCDEE18EC2ECE4B38 /* Pods */, 53 | EADA35B2A12AD4F156D27B04 /* Frameworks */, 54 | ); 55 | sourceTree = ""; 56 | }; 57 | 0B70BDBF1CF6541C00C78D36 /* Products */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | 0B70BDBE1CF6541C00C78D36 /* MDFTextAccessibilitySample.app */, 61 | ); 62 | name = Products; 63 | sourceTree = ""; 64 | }; 65 | 0B70BDC01CF6541C00C78D36 /* MDFTextAccessibilitySample */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | 0B70BDC11CF6541C00C78D36 /* AppDelegate.swift */, 69 | 0B70BDC81CF6541C00C78D36 /* Assets.xcassets */, 70 | 0B70BDD71CF663B100C78D36 /* ColorCollectionViewCell.swift */, 71 | 0BFC04391CF7830C00567F1C /* ColorCollectionViewHeader.swift */, 72 | 0B70BDD51CF65B3400C78D36 /* ColorsCollectionViewController.swift */, 73 | 0B70BDCD1CF6541C00C78D36 /* Info.plist */, 74 | 0B70BDCA1CF6541C00C78D36 /* LaunchScreen.storyboard */, 75 | 0B70BDC51CF6541C00C78D36 /* Main.storyboard */, 76 | ); 77 | path = MDFTextAccessibilitySample; 78 | sourceTree = ""; 79 | }; 80 | E4FEF74BCDEE18EC2ECE4B38 /* Pods */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | 837EE15AAD1298DCA1BF2E20 /* Pods-MDFTextAccessibilitySample.debug.xcconfig */, 84 | 1AE1DC46C109323BE9E1BC97 /* Pods-MDFTextAccessibilitySample.release.xcconfig */, 85 | ); 86 | name = Pods; 87 | sourceTree = ""; 88 | }; 89 | EADA35B2A12AD4F156D27B04 /* Frameworks */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | AAEDF7C81A76FAF311AB1A07 /* Pods_MDFTextAccessibilitySample.framework */, 93 | ); 94 | name = Frameworks; 95 | sourceTree = ""; 96 | }; 97 | /* End PBXGroup section */ 98 | 99 | /* Begin PBXNativeTarget section */ 100 | 0B70BDBD1CF6541C00C78D36 /* MDFTextAccessibilitySample */ = { 101 | isa = PBXNativeTarget; 102 | buildConfigurationList = 0B70BDD01CF6541C00C78D36 /* Build configuration list for PBXNativeTarget "MDFTextAccessibilitySample" */; 103 | buildPhases = ( 104 | 77EB4CAE2CC44758B3B78076 /* [CP] Check Pods Manifest.lock */, 105 | 31699BC6ECD347A75696EFB0 /* [CP] Check Pods Manifest.lock */, 106 | C412B6C87BDE4D2B6B1CF19A /* [CP] Check Pods Manifest.lock */, 107 | 0B70BDBA1CF6541C00C78D36 /* Sources */, 108 | 0B70BDBB1CF6541C00C78D36 /* Frameworks */, 109 | 0B70BDBC1CF6541C00C78D36 /* Resources */, 110 | 457B8C81531E0FA57A7339DF /* [CP] Embed Pods Frameworks */, 111 | AC61D42B0C3BEBF8E7C70D21 /* [CP] Copy Pods Resources */, 112 | 74063B709EA7196D10BF7470 /* 📦 Embed Pods Frameworks */, 113 | BD0CDD49D379D3CA0F88B59D /* 📦 Copy Pods Resources */, 114 | ); 115 | buildRules = ( 116 | ); 117 | dependencies = ( 118 | ); 119 | name = MDFTextAccessibilitySample; 120 | productName = MDFTextAccessibilitySample; 121 | productReference = 0B70BDBE1CF6541C00C78D36 /* MDFTextAccessibilitySample.app */; 122 | productType = "com.apple.product-type.application"; 123 | }; 124 | /* End PBXNativeTarget section */ 125 | 126 | /* Begin PBXProject section */ 127 | 0B70BDB61CF6541C00C78D36 /* Project object */ = { 128 | isa = PBXProject; 129 | attributes = { 130 | LastSwiftUpdateCheck = 0730; 131 | LastUpgradeCheck = 0730; 132 | ORGANIZATIONNAME = Google; 133 | TargetAttributes = { 134 | 0B70BDBD1CF6541C00C78D36 = { 135 | CreatedOnToolsVersion = 7.3.1; 136 | LastSwiftMigration = 0800; 137 | }; 138 | }; 139 | }; 140 | buildConfigurationList = 0B70BDB91CF6541C00C78D36 /* Build configuration list for PBXProject "MDFTextAccessibilitySample" */; 141 | compatibilityVersion = "Xcode 3.2"; 142 | developmentRegion = English; 143 | hasScannedForEncodings = 0; 144 | knownRegions = ( 145 | en, 146 | Base, 147 | ); 148 | mainGroup = 0B70BDB51CF6541C00C78D36; 149 | productRefGroup = 0B70BDBF1CF6541C00C78D36 /* Products */; 150 | projectDirPath = ""; 151 | projectRoot = ""; 152 | targets = ( 153 | 0B70BDBD1CF6541C00C78D36 /* MDFTextAccessibilitySample */, 154 | ); 155 | }; 156 | /* End PBXProject section */ 157 | 158 | /* Begin PBXResourcesBuildPhase section */ 159 | 0B70BDBC1CF6541C00C78D36 /* Resources */ = { 160 | isa = PBXResourcesBuildPhase; 161 | buildActionMask = 2147483647; 162 | files = ( 163 | 0B70BDCC1CF6541C00C78D36 /* LaunchScreen.storyboard in Resources */, 164 | 0B70BDC91CF6541C00C78D36 /* Assets.xcassets in Resources */, 165 | 0B70BDC71CF6541C00C78D36 /* Main.storyboard in Resources */, 166 | ); 167 | runOnlyForDeploymentPostprocessing = 0; 168 | }; 169 | /* End PBXResourcesBuildPhase section */ 170 | 171 | /* Begin PBXShellScriptBuildPhase section */ 172 | 31699BC6ECD347A75696EFB0 /* [CP] Check Pods Manifest.lock */ = { 173 | isa = PBXShellScriptBuildPhase; 174 | buildActionMask = 2147483647; 175 | files = ( 176 | ); 177 | inputPaths = ( 178 | ); 179 | name = "[CP] Check Pods Manifest.lock"; 180 | outputPaths = ( 181 | ); 182 | runOnlyForDeploymentPostprocessing = 0; 183 | shellPath = /bin/sh; 184 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; 185 | showEnvVarsInLog = 0; 186 | }; 187 | 457B8C81531E0FA57A7339DF /* [CP] Embed Pods Frameworks */ = { 188 | isa = PBXShellScriptBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | ); 192 | inputPaths = ( 193 | "${SRCROOT}/Pods/Target Support Files/Pods-MDFTextAccessibilitySample/Pods-MDFTextAccessibilitySample-frameworks.sh", 194 | "${BUILT_PRODUCTS_DIR}/MDFTextAccessibility/MDFTextAccessibility.framework", 195 | ); 196 | name = "[CP] Embed Pods Frameworks"; 197 | outputPaths = ( 198 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MDFTextAccessibility.framework", 199 | ); 200 | runOnlyForDeploymentPostprocessing = 0; 201 | shellPath = /bin/sh; 202 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-MDFTextAccessibilitySample/Pods-MDFTextAccessibilitySample-frameworks.sh\"\n"; 203 | showEnvVarsInLog = 0; 204 | }; 205 | 74063B709EA7196D10BF7470 /* 📦 Embed Pods Frameworks */ = { 206 | isa = PBXShellScriptBuildPhase; 207 | buildActionMask = 2147483647; 208 | files = ( 209 | ); 210 | inputPaths = ( 211 | ); 212 | name = "📦 Embed Pods Frameworks"; 213 | outputPaths = ( 214 | ); 215 | runOnlyForDeploymentPostprocessing = 0; 216 | shellPath = /bin/sh; 217 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-MDFTextAccessibilitySample/Pods-MDFTextAccessibilitySample-frameworks.sh\"\n"; 218 | showEnvVarsInLog = 0; 219 | }; 220 | 77EB4CAE2CC44758B3B78076 /* [CP] Check Pods Manifest.lock */ = { 221 | isa = PBXShellScriptBuildPhase; 222 | buildActionMask = 2147483647; 223 | files = ( 224 | ); 225 | inputPaths = ( 226 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 227 | "${PODS_ROOT}/Manifest.lock", 228 | ); 229 | name = "[CP] Check Pods Manifest.lock"; 230 | outputPaths = ( 231 | "$(DERIVED_FILE_DIR)/Pods-MDFTextAccessibilitySample-checkManifestLockResult.txt", 232 | ); 233 | runOnlyForDeploymentPostprocessing = 0; 234 | shellPath = /bin/sh; 235 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 236 | showEnvVarsInLog = 0; 237 | }; 238 | AC61D42B0C3BEBF8E7C70D21 /* [CP] Copy Pods Resources */ = { 239 | isa = PBXShellScriptBuildPhase; 240 | buildActionMask = 2147483647; 241 | files = ( 242 | ); 243 | inputPaths = ( 244 | ); 245 | name = "[CP] Copy Pods Resources"; 246 | outputPaths = ( 247 | ); 248 | runOnlyForDeploymentPostprocessing = 0; 249 | shellPath = /bin/sh; 250 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-MDFTextAccessibilitySample/Pods-MDFTextAccessibilitySample-resources.sh\"\n"; 251 | showEnvVarsInLog = 0; 252 | }; 253 | BD0CDD49D379D3CA0F88B59D /* 📦 Copy Pods Resources */ = { 254 | isa = PBXShellScriptBuildPhase; 255 | buildActionMask = 2147483647; 256 | files = ( 257 | ); 258 | inputPaths = ( 259 | ); 260 | name = "📦 Copy Pods Resources"; 261 | outputPaths = ( 262 | ); 263 | runOnlyForDeploymentPostprocessing = 0; 264 | shellPath = /bin/sh; 265 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-MDFTextAccessibilitySample/Pods-MDFTextAccessibilitySample-resources.sh\"\n"; 266 | showEnvVarsInLog = 0; 267 | }; 268 | C412B6C87BDE4D2B6B1CF19A /* [CP] Check Pods Manifest.lock */ = { 269 | isa = PBXShellScriptBuildPhase; 270 | buildActionMask = 2147483647; 271 | files = ( 272 | ); 273 | inputPaths = ( 274 | ); 275 | name = "[CP] Check Pods Manifest.lock"; 276 | outputPaths = ( 277 | ); 278 | runOnlyForDeploymentPostprocessing = 0; 279 | shellPath = /bin/sh; 280 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; 281 | showEnvVarsInLog = 0; 282 | }; 283 | /* End PBXShellScriptBuildPhase section */ 284 | 285 | /* Begin PBXSourcesBuildPhase section */ 286 | 0B70BDBA1CF6541C00C78D36 /* Sources */ = { 287 | isa = PBXSourcesBuildPhase; 288 | buildActionMask = 2147483647; 289 | files = ( 290 | 0B70BDD81CF663B100C78D36 /* ColorCollectionViewCell.swift in Sources */, 291 | 0B70BDD61CF65B3400C78D36 /* ColorsCollectionViewController.swift in Sources */, 292 | 0B70BDC21CF6541C00C78D36 /* AppDelegate.swift in Sources */, 293 | 0BFC043A1CF7830C00567F1C /* ColorCollectionViewHeader.swift in Sources */, 294 | ); 295 | runOnlyForDeploymentPostprocessing = 0; 296 | }; 297 | /* End PBXSourcesBuildPhase section */ 298 | 299 | /* Begin PBXVariantGroup section */ 300 | 0B70BDC51CF6541C00C78D36 /* Main.storyboard */ = { 301 | isa = PBXVariantGroup; 302 | children = ( 303 | 0B70BDC61CF6541C00C78D36 /* Base */, 304 | ); 305 | name = Main.storyboard; 306 | sourceTree = ""; 307 | }; 308 | 0B70BDCA1CF6541C00C78D36 /* LaunchScreen.storyboard */ = { 309 | isa = PBXVariantGroup; 310 | children = ( 311 | 0B70BDCB1CF6541C00C78D36 /* Base */, 312 | ); 313 | name = LaunchScreen.storyboard; 314 | sourceTree = ""; 315 | }; 316 | /* End PBXVariantGroup section */ 317 | 318 | /* Begin XCBuildConfiguration section */ 319 | 0B70BDCE1CF6541C00C78D36 /* Debug */ = { 320 | isa = XCBuildConfiguration; 321 | buildSettings = { 322 | ALWAYS_SEARCH_USER_PATHS = NO; 323 | CLANG_ANALYZER_NONNULL = YES; 324 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 325 | CLANG_CXX_LIBRARY = "libc++"; 326 | CLANG_ENABLE_MODULES = YES; 327 | CLANG_ENABLE_OBJC_ARC = YES; 328 | CLANG_WARN_BOOL_CONVERSION = YES; 329 | CLANG_WARN_CONSTANT_CONVERSION = YES; 330 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 331 | CLANG_WARN_EMPTY_BODY = YES; 332 | CLANG_WARN_ENUM_CONVERSION = YES; 333 | CLANG_WARN_INT_CONVERSION = YES; 334 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 335 | CLANG_WARN_UNREACHABLE_CODE = YES; 336 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 337 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 338 | COPY_PHASE_STRIP = NO; 339 | DEBUG_INFORMATION_FORMAT = dwarf; 340 | ENABLE_STRICT_OBJC_MSGSEND = YES; 341 | ENABLE_TESTABILITY = YES; 342 | GCC_C_LANGUAGE_STANDARD = gnu99; 343 | GCC_DYNAMIC_NO_PIC = NO; 344 | GCC_NO_COMMON_BLOCKS = YES; 345 | GCC_OPTIMIZATION_LEVEL = 0; 346 | GCC_PREPROCESSOR_DEFINITIONS = ( 347 | "DEBUG=1", 348 | "$(inherited)", 349 | ); 350 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 351 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 352 | GCC_WARN_UNDECLARED_SELECTOR = YES; 353 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 354 | GCC_WARN_UNUSED_FUNCTION = YES; 355 | GCC_WARN_UNUSED_VARIABLE = YES; 356 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 357 | MTL_ENABLE_DEBUG_INFO = YES; 358 | ONLY_ACTIVE_ARCH = YES; 359 | SDKROOT = iphoneos; 360 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 361 | TARGETED_DEVICE_FAMILY = "1,2"; 362 | }; 363 | name = Debug; 364 | }; 365 | 0B70BDCF1CF6541C00C78D36 /* Release */ = { 366 | isa = XCBuildConfiguration; 367 | buildSettings = { 368 | ALWAYS_SEARCH_USER_PATHS = NO; 369 | CLANG_ANALYZER_NONNULL = YES; 370 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 371 | CLANG_CXX_LIBRARY = "libc++"; 372 | CLANG_ENABLE_MODULES = YES; 373 | CLANG_ENABLE_OBJC_ARC = YES; 374 | CLANG_WARN_BOOL_CONVERSION = YES; 375 | CLANG_WARN_CONSTANT_CONVERSION = YES; 376 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 377 | CLANG_WARN_EMPTY_BODY = YES; 378 | CLANG_WARN_ENUM_CONVERSION = YES; 379 | CLANG_WARN_INT_CONVERSION = YES; 380 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 381 | CLANG_WARN_UNREACHABLE_CODE = YES; 382 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 383 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 384 | COPY_PHASE_STRIP = NO; 385 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 386 | ENABLE_NS_ASSERTIONS = NO; 387 | ENABLE_STRICT_OBJC_MSGSEND = YES; 388 | GCC_C_LANGUAGE_STANDARD = gnu99; 389 | GCC_NO_COMMON_BLOCKS = YES; 390 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 391 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 392 | GCC_WARN_UNDECLARED_SELECTOR = YES; 393 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 394 | GCC_WARN_UNUSED_FUNCTION = YES; 395 | GCC_WARN_UNUSED_VARIABLE = YES; 396 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 397 | MTL_ENABLE_DEBUG_INFO = NO; 398 | SDKROOT = iphoneos; 399 | TARGETED_DEVICE_FAMILY = "1,2"; 400 | VALIDATE_PRODUCT = YES; 401 | }; 402 | name = Release; 403 | }; 404 | 0B70BDD11CF6541C00C78D36 /* Debug */ = { 405 | isa = XCBuildConfiguration; 406 | baseConfigurationReference = 837EE15AAD1298DCA1BF2E20 /* Pods-MDFTextAccessibilitySample.debug.xcconfig */; 407 | buildSettings = { 408 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 409 | INFOPLIST_FILE = MDFTextAccessibilitySample/Info.plist; 410 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 411 | PRODUCT_BUNDLE_IDENTIFIER = com.google.MDFTextAccessibilitySample; 412 | PRODUCT_NAME = "$(TARGET_NAME)"; 413 | SWIFT_VERSION = 3.0; 414 | }; 415 | name = Debug; 416 | }; 417 | 0B70BDD21CF6541C00C78D36 /* Release */ = { 418 | isa = XCBuildConfiguration; 419 | baseConfigurationReference = 1AE1DC46C109323BE9E1BC97 /* Pods-MDFTextAccessibilitySample.release.xcconfig */; 420 | buildSettings = { 421 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 422 | INFOPLIST_FILE = MDFTextAccessibilitySample/Info.plist; 423 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 424 | PRODUCT_BUNDLE_IDENTIFIER = com.google.MDFTextAccessibilitySample; 425 | PRODUCT_NAME = "$(TARGET_NAME)"; 426 | SWIFT_VERSION = 3.0; 427 | }; 428 | name = Release; 429 | }; 430 | /* End XCBuildConfiguration section */ 431 | 432 | /* Begin XCConfigurationList section */ 433 | 0B70BDB91CF6541C00C78D36 /* Build configuration list for PBXProject "MDFTextAccessibilitySample" */ = { 434 | isa = XCConfigurationList; 435 | buildConfigurations = ( 436 | 0B70BDCE1CF6541C00C78D36 /* Debug */, 437 | 0B70BDCF1CF6541C00C78D36 /* Release */, 438 | ); 439 | defaultConfigurationIsVisible = 0; 440 | defaultConfigurationName = Release; 441 | }; 442 | 0B70BDD01CF6541C00C78D36 /* Build configuration list for PBXNativeTarget "MDFTextAccessibilitySample" */ = { 443 | isa = XCConfigurationList; 444 | buildConfigurations = ( 445 | 0B70BDD11CF6541C00C78D36 /* Debug */, 446 | 0B70BDD21CF6541C00C78D36 /* Release */, 447 | ); 448 | defaultConfigurationIsVisible = 0; 449 | defaultConfigurationName = Release; 450 | }; 451 | /* End XCConfigurationList section */ 452 | }; 453 | rootObject = 0B70BDB61CF6541C00C78D36 /* Project object */; 454 | } 455 | -------------------------------------------------------------------------------- /examples/apps/MDFTextAccessibilitySample/MDFTextAccessibilitySample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/apps/MDFTextAccessibilitySample/MDFTextAccessibilitySample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016-present Google Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import UIKit 18 | 19 | @UIApplicationMain 20 | class AppDelegate: UIResponder, UIApplicationDelegate { 21 | 22 | var window: UIWindow? 23 | 24 | 25 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 26 | // Override point for customization after application launch. 27 | return true 28 | } 29 | 30 | func applicationWillResignActive(_ application: UIApplication) { 31 | // 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. 32 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 33 | } 34 | 35 | func applicationDidEnterBackground(_ application: UIApplication) { 36 | // 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. 37 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 38 | } 39 | 40 | func applicationWillEnterForeground(_ application: UIApplication) { 41 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 42 | } 43 | 44 | func applicationDidBecomeActive(_ application: UIApplication) { 45 | // 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. 46 | } 47 | 48 | func applicationWillTerminate(_ application: UIApplication) { 49 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 50 | } 51 | 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /examples/apps/MDFTextAccessibilitySample/MDFTextAccessibilitySample/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 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /examples/apps/MDFTextAccessibilitySample/MDFTextAccessibilitySample/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 | -------------------------------------------------------------------------------- /examples/apps/MDFTextAccessibilitySample/MDFTextAccessibilitySample/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 | 28 | 29 | 30 | 31 | 36 | 42 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /examples/apps/MDFTextAccessibilitySample/MDFTextAccessibilitySample/ColorCollectionViewCell.swift: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016-present Google Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import UIKit 18 | 19 | class ColorCollectionViewCell: UICollectionViewCell { 20 | @IBOutlet weak var backgroundColorLabel: UILabel! 21 | @IBOutlet weak var largeTextLabel: UILabel! 22 | @IBOutlet weak var normalTextLabel: UILabel! 23 | 24 | override init(frame: CGRect) { 25 | super.init(frame: frame) 26 | self.layer.cornerRadius = 2 27 | } 28 | 29 | required init?(coder aDecoder: NSCoder) { 30 | super.init(coder: aDecoder) 31 | self.layer.cornerRadius = 2 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /examples/apps/MDFTextAccessibilitySample/MDFTextAccessibilitySample/ColorCollectionViewHeader.swift: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016-present Google Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import UIKit 18 | 19 | class ColorCollectionViewHeader: UICollectionReusableView { 20 | @IBOutlet weak var titleLabel: UILabel! 21 | } 22 | -------------------------------------------------------------------------------- /examples/apps/MDFTextAccessibilitySample/MDFTextAccessibilitySample/ColorsCollectionViewController.swift: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016-present Google Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import MDFTextAccessibility 18 | import UIKit 19 | 20 | private let cellReuseIdentifier = "ColorCell" 21 | private let headerReuseIdentifier = "ColorHeader" 22 | 23 | /** Return a hex string like "#3FA066" from a UIColor object. */ 24 | private func hexStringFromColor(_ color: UIColor) -> String { 25 | var red: CGFloat = 0 26 | var green: CGFloat = 0 27 | var blue: CGFloat = 0 28 | var alpha: CGFloat = 0 29 | color.getRed(&red, green: &green, blue: &blue, alpha: &alpha) 30 | return String(format:"#%.2X%.2X%.2X", Int(red * 255), Int(green * 255), Int(blue * 255)) 31 | } 32 | 33 | /** Return a uniformly random opaque RGB color. */ 34 | private func randomRGBColor() -> UIColor { 35 | return UIColor(red: CGFloat(arc4random_uniform(256)) / CGFloat(255), 36 | green: CGFloat(arc4random_uniform(256)) / CGFloat(255), 37 | blue: CGFloat(arc4random_uniform(256)) / CGFloat(255), 38 | alpha: 1) 39 | } 40 | 41 | /** Set the textColor of a UILabel based on a target text alpha and a background color. */ 42 | private func setLabelAccessibleTextColor(_ label: UILabel, 43 | targetTextAlpha: CGFloat, 44 | preferLightText: Bool, 45 | onBackgroundColor backgroundColor: UIColor?) { 46 | if (backgroundColor != nil) { 47 | let options : MDFTextAccessibilityOptions = [ 48 | MDFTextAccessibility.isLarge(forContrastRatios: label.font) ? .largeFont : MDFTextAccessibilityOptions(), 49 | preferLightText ? .preferLighter : .preferDarker 50 | ] 51 | 52 | label.textColor = 53 | MDFTextAccessibility.textColor(onBackgroundColor: backgroundColor!, 54 | targetTextAlpha: targetTextAlpha, 55 | options: options) 56 | } 57 | } 58 | 59 | /** A title containing a contrast ratio for a color ship. */ 60 | private func contrastRatioTitle(_ prefix: String, 61 | textColor: UIColor, 62 | backgroundColor: UIColor) -> String { 63 | let ratio = MDFTextAccessibility.contrastRatio(forTextColor: textColor, 64 | onBackgroundColor: backgroundColor); 65 | return prefix + String(format: " %.1f:1", ratio) 66 | } 67 | 68 | /** A title reporting the background color for a color chip. */ 69 | private func backgroundColorTitle(_ prefix: String, backgroundColor: UIColor) -> String { 70 | return hexStringFromColor(backgroundColor) 71 | } 72 | 73 | /** A section of color chips with a title text accessibility options. */ 74 | class ColorChipSection { 75 | var title = "" 76 | var colors = [UIColor]() 77 | var targetTextAlpha: CGFloat = 1 78 | var prefersLightText = true 79 | } 80 | 81 | /** A collection view of color chips. */ 82 | class ColorsCollectionViewController: UICollectionViewController { 83 | var colorChipSections = [ColorChipSection]() 84 | 85 | override init(collectionViewLayout layout: UICollectionViewLayout) { 86 | super.init(collectionViewLayout: layout) 87 | self.createColorChipSections() 88 | } 89 | 90 | required init?(coder aDecoder: NSCoder) { 91 | super.init(coder:aDecoder) 92 | self.createColorChipSections() 93 | } 94 | 95 | override func viewDidLoad() { 96 | let flowLayout = self.collectionViewLayout as! UICollectionViewFlowLayout 97 | flowLayout.sectionInset = UIEdgeInsetsMake(0, 8, 8, 8) 98 | } 99 | 100 | fileprivate func createColorChipSections() { 101 | let numColorsPerSection = 10 102 | var colors = [UIColor]() 103 | for _ in 1...numColorsPerSection { 104 | colors.append(randomRGBColor()) 105 | } 106 | 107 | // Fairly typical usage: non-opaque text with a preference to light text. 108 | var colorChipSection = ColorChipSection() 109 | colorChipSection.title = "Target alpha of 0.87, prefer light text" 110 | colorChipSection.targetTextAlpha = 0.87 111 | colorChipSection.colors = colors 112 | self.colorChipSections.append(colorChipSection) 113 | 114 | // Non-opaque text with a preference to dark text. 115 | colorChipSection = ColorChipSection() 116 | colorChipSection.title = "Target alpha of 0.87, prefer dark text" 117 | colorChipSection.targetTextAlpha = 0.87 118 | colorChipSection.prefersLightText = false 119 | colorChipSection.colors = colors 120 | self.colorChipSections.append(colorChipSection) 121 | 122 | // Minimal opacity text. 123 | colorChipSection = ColorChipSection() 124 | colorChipSection.title = "Minimally-opaque accessible text" 125 | colorChipSection.targetTextAlpha = 0 126 | colorChipSection.colors = colors 127 | self.colorChipSections.append(colorChipSection) 128 | } 129 | 130 | fileprivate func backgroundColorForIndexPath(_ indexPath: IndexPath) -> UIColor { 131 | assert((indexPath as NSIndexPath).section < self.colorChipSections.count) 132 | assert((indexPath as NSIndexPath).row < self.colorChipSections[(indexPath as NSIndexPath).section].colors.count) 133 | return self.colorChipSections[(indexPath as NSIndexPath).section].colors[(indexPath as NSIndexPath).row] 134 | } 135 | 136 | fileprivate func configureCell(_ cell: ColorCollectionViewCell, 137 | forItemAtIndexPath indexPath: IndexPath) { 138 | let colorChipSection = self.colorChipSections[(indexPath as NSIndexPath).section] 139 | cell.backgroundColor = colorChipSection.colors[(indexPath as NSIndexPath).row] 140 | 141 | let labels = [ cell.backgroundColorLabel, cell.largeTextLabel, cell.normalTextLabel ] 142 | for label in labels { 143 | setLabelAccessibleTextColor(label!, 144 | targetTextAlpha: colorChipSection.targetTextAlpha, 145 | preferLightText: colorChipSection.prefersLightText, 146 | onBackgroundColor: cell.backgroundColor) 147 | } 148 | 149 | cell.backgroundColorLabel.text = backgroundColorTitle("Background ", 150 | backgroundColor:cell.backgroundColor!) 151 | cell.largeTextLabel.text = contrastRatioTitle("Large text", 152 | textColor:cell.largeTextLabel.textColor, 153 | backgroundColor:cell.backgroundColor!) 154 | cell.normalTextLabel.text = contrastRatioTitle("Normal text", 155 | textColor:cell.normalTextLabel.textColor, 156 | backgroundColor:cell.backgroundColor!) 157 | } 158 | } 159 | 160 | // UICollectionViewDataSource methods 161 | extension ColorsCollectionViewController { 162 | override func numberOfSections(in collectionView: UICollectionView) -> Int { 163 | return self.colorChipSections.count 164 | } 165 | 166 | override func collectionView(_ collectionView: UICollectionView, 167 | numberOfItemsInSection section: Int) -> Int { 168 | return self.colorChipSections[section].colors.count 169 | } 170 | 171 | override func collectionView( 172 | _ collectionView: UICollectionView, 173 | cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 174 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellReuseIdentifier, 175 | for: indexPath) 176 | self.configureCell(cell as! ColorCollectionViewCell, forItemAtIndexPath: indexPath) 177 | return cell 178 | } 179 | 180 | override func collectionView(_ collectionView: UICollectionView, 181 | viewForSupplementaryElementOfKind kind: String, 182 | at indexPath: IndexPath) -> UICollectionReusableView { 183 | assert(kind == UICollectionElementKindSectionHeader) 184 | let headerView = 185 | collectionView.dequeueReusableSupplementaryView(ofKind: kind, 186 | withReuseIdentifier: headerReuseIdentifier, 187 | for: indexPath) 188 | as! ColorCollectionViewHeader 189 | headerView.titleLabel.text = self.colorChipSections[(indexPath as NSIndexPath).section].title 190 | return headerView 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /examples/apps/MDFTextAccessibilitySample/MDFTextAccessibilitySample/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /examples/apps/MDFTextAccessibilitySample/Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '10' 2 | use_frameworks! 3 | 4 | target 'MDFTextAccessibilitySample' do 5 | pod 'MDFTextAccessibility', :path => '../../..' 6 | end 7 | 8 | -------------------------------------------------------------------------------- /examples/apps/MDFTextAccessibilitySample/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - MDFTextAccessibility (1.2.1) 3 | 4 | DEPENDENCIES: 5 | - MDFTextAccessibility (from `../../..`) 6 | 7 | EXTERNAL SOURCES: 8 | MDFTextAccessibility: 9 | :path: ../../.. 10 | 11 | SPEC CHECKSUMS: 12 | MDFTextAccessibility: 8969dcdf8ef664761b47c03204b6a4d24f59e61b 13 | 14 | PODFILE CHECKSUM: ba1d198039c6b887cc904c2b80f4ae8bc213c6fd 15 | 16 | COCOAPODS: 1.3.1 17 | -------------------------------------------------------------------------------- /resources/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 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/MDFTextAccessibility-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016-present Google Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "MDFTextAccessibility.h" 18 | -------------------------------------------------------------------------------- /src/MDFTextAccessibility.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016-present Google Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import 18 | 19 | /** Options for selecting text colors that provide acceptable contrast ratios. */ 20 | typedef NS_OPTIONS(NSUInteger, MDFTextAccessibilityOptions) { 21 | /** No options. */ 22 | MDFTextAccessibilityOptionsNone = 0, 23 | 24 | /** Font size is at least 14pt bold or 18pt normal. */ 25 | MDFTextAccessibilityOptionsLargeFont = 1 << 0, 26 | 27 | /** Do not modify alpha values to find good colors. */ 28 | MDFTextAccessibilityOptionsPreserveAlpha = 1 << 1, 29 | 30 | /** Prefer darker colors to lighter colors. */ 31 | MDFTextAccessibilityOptionsPreferDarker = 1 << 2, 32 | 33 | /** Prefer lighter colors to darker colors. */ 34 | MDFTextAccessibilityOptionsPreferLighter = 1 << 3, 35 | 36 | /** Use enhanced contrast ratios (level AAA) instead of minimum ratios (level AA). */ 37 | MDFTextAccessibilityOptionsEnhancedContrast = 1 << 4, 38 | }; 39 | 40 | /** 41 | MDFTextAccessiblity provides methods to compute accessible text colors. 42 | */ 43 | @interface MDFTextAccessibility : NSObject 44 | 45 | /** 46 | An optionally transparent text color suitable for displaying on a background color with a 47 | particular font. 48 | 49 | The color returned will be white or black with an alpha value of targetTextAlpha, unless the 50 | contrast ratio is insufficient, in which case the alpha is increased (made more opaque). 51 | 52 | If the passed font is nil, then a conservative guess is used. 53 | 54 | @param backgroundColor The opaque background color the text will be displayed on. 55 | @param targetTextAlpha The target alpha of the text. 56 | @param font The font the text will use or nil. 57 | @return A color with acceptable contrast ratio for displaying text on |color|. 58 | */ 59 | + (nonnull UIColor *)textColorOnBackgroundColor:(nonnull UIColor *)backgroundColor 60 | targetTextAlpha:(CGFloat)targetTextAlpha 61 | font:(nullable UIFont *)font; 62 | 63 | #pragma mark Advanced methods 64 | 65 | /** 66 | An optionally transparent text color suitable for displaying text on a given opaque background 67 | color. 68 | 69 | This method calls textColorFromChoices:onColor:options: with the choices [white, black], both 70 | with their alpha set to targetTextAlpha. 71 | 72 | If MDFTextAccessibilityOptionsPreserveAlpha is included in the options, then the algorithm will not 73 | modify the alpha values, which may result in no color being returned at all. 74 | 75 | @param backgroundColor The opaque background color the text will be displayed on. 76 | @param targetTextAlpha The target alpha of the text. 77 | @param options A combination of MDFTextAccessibilityOptions values. 78 | @return A color with acceptable contrast ratio or nil if no such color exists. 79 | */ 80 | + (nullable UIColor *)textColorOnBackgroundColor:(nonnull UIColor *)backgroundColor 81 | targetTextAlpha:(CGFloat)targetTextAlpha 82 | options:(MDFTextAccessibilityOptions)options; 83 | 84 | /** 85 | A color selected from a set which is suitable for displaying text on a given opaque background 86 | color. 87 | 88 | Since the minimum ratio for "large" text is less stringent, set 89 | the MDFTextAccessibilityOptionsLargeFont bit if the font size will be greater than or 90 | equal to 18pt normal or 14pt bold. If in doubt or if the text size can vary, be conservative and do 91 | not specify MDFTextAccessibilityOptionsLargeFont in the options. 92 | 93 | By default, the first acceptable color in |choices| will be returned. If 94 | MDFTextAccessibilityOptionsPreferLighter is set, then the lightest acceptable color will be 95 | returned, and if MDFTextAccessibilityOptionsPreferDarker is set, then the darkest acceptable color 96 | will be returned. This allows for a standard set of text colors to be used in different situations. 97 | 98 | By default, the algorithm will attempt to modify the alpha value of colors in |choices| instead 99 | of switching to an alternate color, under the assumption that text with slightly different 100 | alpha values is less noticible than, for example, black text where white text is usually used. 101 | If MDFTextAccessibilityOptionsPreserveAlpha is included in the options, then the algorithm will not 102 | modify the alpha values, which may result in no color being returned at all. 103 | 104 | @param choices An array of text color UIColor objects with optional alpha values. 105 | @param backgroundColor The opaque background color the text will be displayed on. 106 | @param options A combination of MDFTextAccessibilityOptions values. 107 | @return A color with acceptable contrast ratio or nil if no such color exists. 108 | */ 109 | + (nullable UIColor *)textColorFromChoices:(nonnull NSArray *)choices 110 | onBackgroundColor:(nonnull UIColor *)backgroundColor 111 | options:(MDFTextAccessibilityOptions)options; 112 | 113 | /** 114 | The minimum alpha that text can have and still have an acceptable contrast ratio. Depending on 115 | color combinations, the minimum useable alpha can vary. 116 | 117 | Since the minimum ratio for "large" text is less stringent, set 118 | the MDFTextAccessibilityOptionsLargeFont bit if the font size will be greater than or 119 | equal to 18pt normal or 14pt bold. If in doubt or if the text size can vary, be conservative and do 120 | not specify MDFTextAccessibilityOptionsLargeFont in the options. 121 | 122 | @note There are some color combinations (white on white) for which an acceptable alpha value 123 | doesn't exist. 124 | 125 | @param textColor The text color (alpha is ignored). 126 | @param backgroundColor The opaque background color the text will be displayed on. 127 | @param options A combination of MDFTextAccessibilityOptions values. 128 | @return The minimum alpha value to use in this situation, or -1 if there is no such alpha. 129 | */ 130 | + (CGFloat)minAlphaOfTextColor:(nonnull UIColor *)textColor 131 | onBackgroundColor:(nonnull UIColor *)backgroundColor 132 | options:(MDFTextAccessibilityOptions)options; 133 | 134 | /** 135 | The contrast ratio of a text color when displayed on an opaque background color. 136 | 137 | @param textColor A text color with optional transparency. 138 | @param backgroundColor The opaque background color the text will be displayed on. 139 | @return The contrast ratio of the text color on the background color. 140 | */ 141 | + (CGFloat)contrastRatioForTextColor:(nonnull UIColor *)textColor 142 | onBackgroundColor:(nonnull UIColor *)backgroundColor; 143 | 144 | /** 145 | Whether a text color passes accessibility standards when displayed on an opaque background color. 146 | 147 | MDFTextAccessibilityOptionsLargeFont and MDFTextAccessibilityOptionsEnhancedContrast are relevant 148 | options for this method. 149 | 150 | @param textColor A text color with optional transparency. 151 | @param backgroundColor The opaque background color the text will be displayed on. 152 | @param options A combination of MDFTextAccessibilityOptions values. 153 | @return YES if the text color would meet accessibility standards. 154 | */ 155 | + (BOOL)textColor:(nonnull UIColor *)textColor 156 | passesOnBackgroundColor:(nonnull UIColor *)backgroundColor 157 | options:(MDFTextAccessibilityOptions)options; 158 | 159 | /** 160 | Whether a particular font would be considered "large" for the purposes of calculating 161 | contrast ratios. 162 | 163 | Large fonts are defined as greater than 18pt normal or 14pt bold. If the passed font is nil, then 164 | this method returns NO. 165 | For more see: https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html 166 | 167 | @param font The font to examine, or nil. 168 | @return YES if the font is non-nil and is considered "large". 169 | */ 170 | + (BOOL)isLargeForContrastRatios:(nullable UIFont *)font; 171 | 172 | @end 173 | -------------------------------------------------------------------------------- /src/MDFTextAccessibility.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016-present Google Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "MDFTextAccessibility.h" 18 | 19 | #import "MDFColorCalculations.h" 20 | #import "NSArray+MDFUtils.h" 21 | 22 | static const CGFloat kMinContrastRatioNormalText = 4.5f; 23 | static const CGFloat kMinContrastRatioLargeText = 3.0f; 24 | static const CGFloat kMinContrastRatioNormalTextEnhanced = 7.0f; 25 | static const CGFloat kMinContrastRatioLargeTextEnhanced = 4.5f; 26 | 27 | @implementation MDFTextAccessibility 28 | 29 | + (nonnull UIColor *)textColorOnBackgroundColor:(nonnull UIColor *)backgroundColor 30 | targetTextAlpha:(CGFloat)targetTextAlpha 31 | font:(nullable UIFont *)font { 32 | MDFTextAccessibilityOptions options = 0; 33 | if ([self isLargeForContrastRatios:font]) { 34 | options |= MDFTextAccessibilityOptionsLargeFont; 35 | } 36 | return [self textColorOnBackgroundColor:backgroundColor 37 | targetTextAlpha:targetTextAlpha 38 | options:options]; 39 | } 40 | 41 | + (nullable UIColor *)textColorOnBackgroundColor:(nonnull UIColor *)backgroundColor 42 | targetTextAlpha:(CGFloat)targetTextAlpha 43 | options:(MDFTextAccessibilityOptions)options { 44 | NSArray *colors = @[ 45 | [UIColor colorWithWhite:1 alpha:targetTextAlpha], [UIColor colorWithWhite:0 46 | alpha:targetTextAlpha] 47 | ]; 48 | UIColor *textColor = [self textColorFromChoices:colors 49 | onBackgroundColor:backgroundColor 50 | options:options]; 51 | return textColor; 52 | } 53 | 54 | + (nullable UIColor *)textColorFromChoices:(nonnull NSArray *)choices 55 | onBackgroundColor:(nonnull UIColor *)backgroundColor 56 | options:(MDFTextAccessibilityOptions)options { 57 | [choices enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 58 | NSAssert([obj isKindOfClass:[UIColor class]], @"Choices must be UIColors."); 59 | }]; 60 | 61 | // Sort by luminance if requested. 62 | if ((options & MDFTextAccessibilityOptionsPreferLighter) || 63 | (options & MDFTextAccessibilityOptionsPreferDarker)) { 64 | NSArray *luminances = [choices mdf_arrayByMappingObjects:^id(id object) { 65 | return @([self luminanceOfColor:object]); 66 | }]; 67 | 68 | BOOL inverse = (options & MDFTextAccessibilityOptionsPreferDarker) ? YES : NO; 69 | choices = [luminances mdf_sortArray:choices 70 | usingComparator:^NSComparisonResult(id obj1, id obj2) { 71 | float first = inverse ? [obj1 floatValue] : [obj2 floatValue]; 72 | float second = inverse ? [obj2 floatValue] : [obj1 floatValue]; 73 | 74 | if (first < second) { 75 | return NSOrderedAscending; 76 | } else if (first > second) { 77 | return NSOrderedDescending; 78 | } else { 79 | return NSOrderedSame; 80 | } 81 | }]; 82 | } 83 | 84 | // Search the array for a color that can be used, adjusting alpha values upwards if requested. 85 | // The first acceptable color (adjusted or not) is returned. 86 | BOOL adjustAlphas = (options & MDFTextAccessibilityOptionsPreserveAlpha) ? NO : YES; 87 | for (UIColor *choice in choices) { 88 | if ([self textColor:choice passesOnBackgroundColor:backgroundColor options:options]) { 89 | return choice; 90 | } 91 | 92 | if (!adjustAlphas) { 93 | continue; 94 | } 95 | 96 | CGFloat alpha = CGColorGetAlpha(choice.CGColor); 97 | CGFloat minAlpha = [self minAlphaOfTextColor:choice 98 | onBackgroundColor:backgroundColor 99 | options:options]; 100 | if (minAlpha > 0) { 101 | if (alpha > minAlpha) { 102 | NSAssert(NO, 103 | @"Logic error: computed an acceptable minimum alpha (%f) that is *less* than the " 104 | @"unacceptable current alpha (%f).", 105 | minAlpha, alpha); 106 | continue; 107 | } 108 | return [choice colorWithAlphaComponent:minAlpha]; 109 | } 110 | } 111 | 112 | return nil; 113 | } 114 | 115 | + (CGFloat)minAlphaOfTextColor:(nonnull UIColor *)textColor 116 | onBackgroundColor:(nonnull UIColor *)backgroundColor 117 | options:(MDFTextAccessibilityOptions)options { 118 | CGFloat minContrastRatio = [self minContrastRatioForOptions:options]; 119 | return MDFMinAlphaOfColorOnBackgroundColor(textColor, backgroundColor, minContrastRatio); 120 | } 121 | 122 | + (CGFloat)contrastRatioForTextColor:(UIColor *)textColor 123 | onBackgroundColor:(UIColor *)backgroundColor { 124 | CGFloat colorComponents[4]; 125 | CGFloat backgroundColorComponents[4]; 126 | MDFCopyRGBAComponents(textColor.CGColor, colorComponents); 127 | MDFCopyRGBAComponents(backgroundColor.CGColor, backgroundColorComponents); 128 | 129 | NSAssert(backgroundColorComponents[3] == 1, 130 | @"Background color %@ must be opaque for a valid contrast ratio calculation.", 131 | backgroundColor); 132 | backgroundColorComponents[3] = 1; 133 | 134 | return MDFContrastRatioOfRGBAComponents(colorComponents, backgroundColorComponents); 135 | } 136 | 137 | + (BOOL)textColor:(nonnull UIColor *)textColor 138 | passesOnBackgroundColor:(nonnull UIColor *)backgroundColor 139 | options:(MDFTextAccessibilityOptions)options { 140 | CGFloat minContrastRatio = [self minContrastRatioForOptions:options]; 141 | CGFloat ratio = [self contrastRatioForTextColor:textColor onBackgroundColor:backgroundColor]; 142 | return ratio >= minContrastRatio ? YES : NO; 143 | } 144 | 145 | + (BOOL)isLargeForContrastRatios:(nullable UIFont *)font { 146 | UIFontDescriptor *fontDescriptor = font.fontDescriptor; 147 | BOOL isBold = 148 | (fontDescriptor.symbolicTraits & UIFontDescriptorTraitBold) == UIFontDescriptorTraitBold; 149 | return font.pointSize >= 18 || (isBold && font.pointSize >= 14); 150 | } 151 | 152 | #pragma mark - Private methods 153 | 154 | + (CGFloat)luminanceOfColor:(UIColor *)color { 155 | CGFloat colorComponents[4]; 156 | MDFCopyRGBAComponents(color.CGColor, colorComponents); 157 | return MDFRelativeLuminanceOfRGBComponents(colorComponents); 158 | } 159 | 160 | + (CGFloat)minContrastRatioForOptions:(MDFTextAccessibilityOptions)options { 161 | BOOL isLarge = 162 | (options & MDFTextAccessibilityOptionsLargeFont) == MDFTextAccessibilityOptionsLargeFont; 163 | BOOL isEnhanced = (options & MDFTextAccessibilityOptionsEnhancedContrast) == 164 | MDFTextAccessibilityOptionsEnhancedContrast; 165 | 166 | if (isEnhanced) { 167 | return isLarge ? kMinContrastRatioLargeTextEnhanced : kMinContrastRatioNormalTextEnhanced; 168 | } else { 169 | return isLarge ? kMinContrastRatioLargeText : kMinContrastRatioNormalText; 170 | } 171 | } 172 | 173 | @end 174 | -------------------------------------------------------------------------------- /src/private/MDFColorCalculations.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016-present Google Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import 18 | 19 | #if defined(__cplusplus) 20 | extern "C" { 21 | #endif 22 | 23 | /** 24 | Copies the RGBA components of color, expanding greyscale colors out to RGBA if necessary. 25 | 26 | @param color The color to extract the components from. 27 | @param rgbaComponents A pointer to four CGFloat values. 28 | */ 29 | void MDFCopyRGBAComponents(CGColorRef color, CGFloat *rgbaComponents); 30 | 31 | /** 32 | Returns the contrast ratio of a foreground color blended on top of a background color. 33 | 34 | @param foregroundColorComponents A pointer to four RGBA CGFloats of the foreground color. 35 | @param backgroundColorComponents A pointer to four RGBA CGFloats of the background color. 36 | @return The contrast ratio of the two colors after blending. 37 | */ 38 | CGFloat MDFContrastRatioOfRGBAComponents(const CGFloat *foregroundColorComponents, 39 | const CGFloat *backgroundColorComponents); 40 | 41 | /** 42 | Calculates the relative luminance of a sRGB color from its components (ignores alpha). 43 | @see http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef 44 | 45 | @param components A pointer to three RGB CGFloat values of the color. 46 | @return The relative luminance of the color. 47 | */ 48 | CGFloat MDFRelativeLuminanceOfRGBComponents(const CGFloat *components); 49 | 50 | /** 51 | Calculates the minimum alpha that a foreground color can have such that, when it's blended on top 52 | of an opaque background color, the resulting contrast ratio is higher than a minimum contrast 53 | ratio. 54 | 55 | If there is no such acceptable contrast ratio, then -1 is returned. This is the case when even a 56 | completely opaque foreground color can't produce a high enough contrast ratio. For example, light 57 | grey on white will have a low contrast ratio for any alpha value assigned to the light grey. 58 | 59 | @param color The foreground color (alpha ignored). 60 | @param backgroundColor The background color (assumed to be opaque). 61 | @param minContrastRatio The minimum allowable contrast ratio. 62 | @return The minimum acceptable alpha of the foreground color, or -1 if no such alpha exists. 63 | */ 64 | CGFloat MDFMinAlphaOfColorOnBackgroundColor(UIColor *color, 65 | UIColor *backgroundColor, 66 | CGFloat minContrastRatio); 67 | 68 | #if defined __cplusplus 69 | } // extern "C" 70 | #endif 71 | -------------------------------------------------------------------------------- /src/private/MDFColorCalculations.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016-present Google Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "MDFColorCalculations.h" 18 | 19 | /** 20 | The number of iterations required to find the minimum acceptable alpha is 21 | ceil(log2(1/kMinAlphaSearchPrecision)), or 7 for a precision of 0.01. If you adjust the precision 22 | then also adjust the max iterations, which is used as a safety check. 23 | */ 24 | static const CGFloat kMinAlphaSearchPrecision = 0.01f; 25 | static const NSUInteger kMinAlphaSearchMaxIterations = 10; 26 | 27 | /** Returns value raised to exponent. */ 28 | static inline CGFloat MDFPow(CGFloat value, CGFloat exponent) { 29 | #if CGFLOAT_IS_DOUBLE 30 | return pow(value, exponent); 31 | #else 32 | return powf(value, exponent); 33 | #endif 34 | } 35 | 36 | /** 37 | Calculate a linear RGB component from a sRGB component for calculating luminance. 38 | @see http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef 39 | */ 40 | static inline CGFloat LinearRGBComponent(CGFloat component) { 41 | if (component <= 0.03928f) { 42 | return component / 12.92f; 43 | } else { 44 | return MDFPow(((component + 0.055f) / 1.055f), 2.4f); 45 | } 46 | } 47 | 48 | /** 49 | Blend a foreground color with alpha on a opaque background color. 50 | @note The background color must be opaque for this to be valid. 51 | @see http://en.wikipedia.org/wiki/Alpha_compositing 52 | */ 53 | static inline void BlendColorOnOpaqueBackground(const CGFloat *foregroundColor, 54 | const CGFloat *backgroundColor, 55 | CGFloat *blendedColor) { 56 | for (int i = 0; i < 3; ++i) { 57 | blendedColor[i] = 58 | foregroundColor[i] * foregroundColor[3] + backgroundColor[i] * (1 - foregroundColor[3]); 59 | } 60 | blendedColor[3] = 1.0f; 61 | } 62 | 63 | static inline CGFloat ContrastRatioOfRGBComponents(const CGFloat *firstComponents, 64 | const CGFloat *secondComponents) { 65 | CGFloat firstLuminance = MDFRelativeLuminanceOfRGBComponents(firstComponents); 66 | CGFloat secondLuminance = MDFRelativeLuminanceOfRGBComponents(secondComponents); 67 | 68 | if (secondLuminance > firstLuminance) { 69 | CGFloat temp = firstLuminance; 70 | firstLuminance = secondLuminance; 71 | secondLuminance = temp; 72 | } 73 | 74 | return (firstLuminance + 0.05f) / (secondLuminance + 0.05f); 75 | } 76 | 77 | CGFloat MDFContrastRatioOfRGBAComponents(const CGFloat *foregroundColorComponents, 78 | const CGFloat *backgroundColorComponents) { 79 | CGFloat blendedColor[4]; 80 | BlendColorOnOpaqueBackground(foregroundColorComponents, backgroundColorComponents, blendedColor); 81 | return ContrastRatioOfRGBComponents(blendedColor, backgroundColorComponents); 82 | } 83 | 84 | void MDFCopyRGBAComponents(CGColorRef color, CGFloat *rgbaComponents) { 85 | CGColorSpaceModel colorSpaceModel = CGColorSpaceGetModel(CGColorGetColorSpace(color)); 86 | if (!(colorSpaceModel == kCGColorSpaceModelRGB || 87 | colorSpaceModel == kCGColorSpaceModelMonochrome)) { 88 | NSCAssert(NO, @"Can't compute luminance for non-RGB color space model %i.", colorSpaceModel); 89 | for (int i = 0; i < 4; ++i) { 90 | rgbaComponents[i] = 0; 91 | } 92 | return; 93 | } 94 | 95 | size_t numComponents = CGColorGetNumberOfComponents(color); 96 | const CGFloat *components = CGColorGetComponents(color); 97 | switch (numComponents) { 98 | // Greyscale + alpha 99 | case 2: 100 | for (int i = 0; i < 3; ++i) { 101 | rgbaComponents[i] = components[0]; 102 | } 103 | rgbaComponents[3] = components[1]; 104 | break; 105 | 106 | // RGB + alpha 107 | case 4: 108 | for (int i = 0; i < 4; ++i) { 109 | rgbaComponents[i] = components[i]; 110 | } 111 | break; 112 | 113 | default: 114 | NSCAssert(NO, @"Unexpected number of color components: %zu.", numComponents); 115 | } 116 | } 117 | 118 | CGFloat MDFRelativeLuminanceOfRGBComponents(const CGFloat *components) { 119 | CGFloat linearRGB[3]; 120 | for (int i = 0; i < 3; ++i) { 121 | linearRGB[i] = LinearRGBComponent(components[i]); 122 | } 123 | return 0.2126f * linearRGB[0] + 0.7152f * linearRGB[1] + 0.0722f * linearRGB[2]; 124 | } 125 | 126 | CGFloat MDFMinAlphaOfColorOnBackgroundColor(UIColor *color, UIColor *backgroundColor, 127 | CGFloat minContrastRatio) { 128 | CGFloat colorComponents[4]; 129 | CGFloat backgroundColorComponents[4]; 130 | MDFCopyRGBAComponents(color.CGColor, colorComponents); 131 | MDFCopyRGBAComponents(backgroundColor.CGColor, backgroundColorComponents); 132 | 133 | NSCAssert(backgroundColorComponents[3] == 1, 134 | @"Background color %@ must be opaque for a valid contrast ratio calculation.", 135 | backgroundColor); 136 | backgroundColorComponents[3] = 1; 137 | 138 | NSCAssert(minContrastRatio > 0, @"Invalid min contrast ratio %g.", (double)minContrastRatio); 139 | CGFloat minAlpha = 0; 140 | CGFloat maxAlpha = 1; 141 | 142 | #if DEBUG && !defined(NS_BLOCK_ASSERTIONS) 143 | colorComponents[3] = minAlpha; 144 | CGFloat minAlphaRatio = 145 | MDFContrastRatioOfRGBAComponents(colorComponents, backgroundColorComponents); 146 | NSCAssert(minAlphaRatio < minContrastRatio, @"Transparent color cannot be a valid color."); 147 | #endif // !defined(NS_BLOCK_ASSERTIONS) 148 | 149 | // maxAlphaRatio is the best contrast ratio we can acheive by modifying the alpha of this color. 150 | // If it's not good enough, then return now and inform the caller. 151 | colorComponents[3] = maxAlpha; 152 | CGFloat maxAlphaRatio = 153 | MDFContrastRatioOfRGBAComponents(colorComponents, backgroundColorComponents); 154 | if (maxAlphaRatio < minContrastRatio) { 155 | return -1; 156 | } 157 | 158 | // Classic binary search of a range. 159 | NSUInteger numIterations = 0; 160 | while (numIterations <= kMinAlphaSearchMaxIterations && 161 | (maxAlpha - minAlpha) > kMinAlphaSearchPrecision) { 162 | CGFloat testAlpha = (minAlpha + maxAlpha) / 2; 163 | colorComponents[3] = testAlpha; 164 | CGFloat testRatio = 165 | MDFContrastRatioOfRGBAComponents(colorComponents, backgroundColorComponents); 166 | 167 | if (testRatio < minContrastRatio) { 168 | minAlpha = testAlpha; 169 | } else { 170 | maxAlpha = testAlpha; 171 | } 172 | 173 | ++numIterations; 174 | } 175 | 176 | if (numIterations > kMinAlphaSearchMaxIterations) { 177 | NSCAssert(NO, @"Too many iterations (%i) while finding min alpha of text color %@ on %@.", 178 | (int)numIterations, color, backgroundColor); 179 | return -1; 180 | } 181 | 182 | // Conservatively return the max of the range of possible alphas, which is known to pass. 183 | return maxAlpha; 184 | } 185 | -------------------------------------------------------------------------------- /src/private/NSArray+MDFUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016-present Google Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import 18 | 19 | typedef id (^MDFMappingFunction)(id object); 20 | 21 | /** Functional extensions to NSArray. */ 22 | @interface NSArray (MDFUtils) 23 | 24 | /** 25 | * Returns an array consisting of applying |function| to each element of self in order. 26 | * 27 | * @param function A block mapping an input element to an output element. 28 | * @return An array of the same size as self containing elements mapped through the function. 29 | */ 30 | - (NSArray *)mdf_arrayByMappingObjects:(MDFMappingFunction)function; 31 | 32 | /** 33 | * Returns a sorted version of |array| by using the passed comparator on self. 34 | * 35 | * @note The comparator acts of elements of self, @em not |array|. 36 | * 37 | * Example: 38 | * @code 39 | * NSArray *weights = @[ 100, 200, 50 ]; 40 | * NSArray *dogs = @[ @"Bruno", @"Tiger", @"Spot" ]; 41 | * NSComparator *ascending = ... NSString comparator ... 42 | * NSArray *sortedDogs = [weights mdf_sortArray:dogs 43 | * usingComparator:ascending]; 44 | * // sortedDogs is @[ @"Spot", @"Bruno", @"Tiger" ]. 45 | * @endcode 46 | * 47 | * @param array The array to sort. 48 | * @param comparator A comparator acting on elements of self. 49 | * @return A sorted copy of |array|. 50 | */ 51 | - (NSArray *)mdf_sortArray:(NSArray *)array usingComparator:(NSComparator)comparator; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /src/private/NSArray+MDFUtils.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016-present Google Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "NSArray+MDFUtils.h" 18 | 19 | @implementation NSArray (MDFUtils) 20 | 21 | - (NSArray *)mdf_arrayByMappingObjects:(MDFMappingFunction)function { 22 | NSAssert(function, @"Mapping block must not be NULL."); 23 | NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[self count]]; 24 | [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 25 | [array addObject:function(obj)]; 26 | }]; 27 | return [array copy]; 28 | } 29 | 30 | - (BOOL)mdf_anyObjectPassesTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate { 31 | NSIndexSet *indices = [self indexesOfObjectsPassingTest:predicate]; 32 | return [indices count] > 0; 33 | } 34 | 35 | - (BOOL)mdf_allObjectsPassTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate { 36 | NSIndexSet *indices = [self indexesOfObjectsPassingTest:predicate]; 37 | return [indices count] == [self count]; 38 | } 39 | 40 | - (NSArray *)mdf_sortArray:(NSArray *)array usingComparator:(NSComparator)comparator { 41 | NSAssert(comparator, @"Comparator block must not be NULL."); 42 | 43 | NSUInteger numElements = [self count]; 44 | NSAssert([array count] == numElements, @"Array %@ must have length %lu.", array, 45 | (unsigned long)numElements); 46 | 47 | // Create a permutation array by sorting self with comparator. 48 | NSMutableArray *permutation = [[NSMutableArray alloc] initWithCapacity:numElements]; 49 | for (NSUInteger i = 0; i < numElements; ++i) { 50 | [permutation addObject:@(i)]; 51 | } 52 | 53 | NSArray *sortedPermutation = [permutation sortedArrayUsingComparator:^(id a, id b) { 54 | NSUInteger firstIndex = [a unsignedIntegerValue]; 55 | NSUInteger secondIndex = [b unsignedIntegerValue]; 56 | return comparator(self[firstIndex], self[secondIndex]); 57 | }]; 58 | 59 | // Permute array into order. 60 | NSMutableArray *sorted = [[NSMutableArray alloc] initWithCapacity:numElements]; 61 | for (NSUInteger i = 0; i < numElements; ++i) { 62 | NSUInteger index = [sortedPermutation[i] unsignedIntegerValue]; 63 | [sorted addObject:array[index]]; 64 | } 65 | return [sorted copy]; 66 | } 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /tests/resources/100_100_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/material-foundation/material-text-accessibility-ios/8cd910c1c8bbae261ae0d7e873ed96c69a386448/tests/resources/100_100_black.png -------------------------------------------------------------------------------- /tests/resources/100_100_gray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/material-foundation/material-text-accessibility-ios/8cd910c1c8bbae261ae0d7e873ed96c69a386448/tests/resources/100_100_gray.png -------------------------------------------------------------------------------- /tests/resources/100_100_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/material-foundation/material-text-accessibility-ios/8cd910c1c8bbae261ae0d7e873ed96c69a386448/tests/resources/100_100_white.png -------------------------------------------------------------------------------- /tests/unit/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /tests/unit/MDFTextAccessibilityUnitTests.swift: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016-present Google Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import XCTest 18 | import MDFTextAccessibility 19 | 20 | class MDFTextAccessibilityUnitTests: XCTestCase { 21 | let alphaEpsilon:CGFloat = 0.01 22 | 23 | // MARK: Text color from choices 24 | 25 | // Test large text 26 | // Test that no-modify-alpha properly skips a color with low alpha that would be otherwise ok. 27 | 28 | func testBasicChoices() { 29 | let textColors = [ UIColor.white, UIColor.black ] 30 | let backgroundColor = UIColor.white 31 | let textColor = MDFTextAccessibility.textColor(fromChoices: textColors, 32 | onBackgroundColor: backgroundColor, 33 | options: MDFTextAccessibilityOptions()) 34 | XCTAssertEqual(textColor, UIColor.black) 35 | } 36 | 37 | func testChoiceFromEmptyChoicesReturnsNil() { 38 | let textColors:[UIColor] = [] 39 | let backgroundColor = UIColor.white 40 | let textColor = MDFTextAccessibility.textColor(fromChoices: textColors, 41 | onBackgroundColor: backgroundColor, 42 | options: MDFTextAccessibilityOptions()) 43 | XCTAssertNil(textColor) 44 | } 45 | 46 | func testChoiceObservesLighterPreferences() { 47 | // Both lighterColor and darkerColor are acceptable in terms of contrast ratios. 48 | let lighterColor = UIColor(white: 0.1, alpha: 1) 49 | let darkerColor = UIColor.black 50 | let textColors = [ darkerColor, lighterColor ] 51 | let backgroundColor = UIColor.white 52 | let textColor = MDFTextAccessibility.textColor(fromChoices: textColors, 53 | onBackgroundColor: backgroundColor, 54 | options: MDFTextAccessibilityOptions.preferLighter) 55 | XCTAssertEqual(textColor, lighterColor) 56 | } 57 | 58 | func testChoiceObservesDarkerPreferences() { 59 | // Both lighterColor and darkerColor are acceptable in terms of contrast ratios. 60 | let lighterColor = UIColor(white: 0.1, alpha: 1) 61 | let darkerColor = UIColor.black 62 | let textColors = [ darkerColor, lighterColor ] 63 | let backgroundColor = UIColor.white 64 | let textColor = MDFTextAccessibility.textColor(fromChoices: textColors, 65 | onBackgroundColor: backgroundColor, 66 | options: MDFTextAccessibilityOptions.preferDarker) 67 | XCTAssertEqual(textColor, darkerColor) 68 | } 69 | 70 | // MARK: Minimum alpha values 71 | 72 | func testSameColorsHaveNoMinAlpha() { 73 | let color = UIColor.white 74 | let minAlpha = MDFTextAccessibility.minAlpha(ofTextColor: color, 75 | onBackgroundColor:color, 76 | options:MDFTextAccessibilityOptions()) 77 | XCTAssertEqual(minAlpha, -1) 78 | } 79 | 80 | func testBlackOnWhiteMinAlpha() { 81 | let textColor = UIColor.black 82 | let backgroundColor = UIColor.white 83 | let minAlpha = MDFTextAccessibility.minAlpha(ofTextColor: textColor, 84 | onBackgroundColor:backgroundColor, 85 | options:MDFTextAccessibilityOptions()) 86 | XCTAssertEqualWithAccuracy(minAlpha, 0.54, accuracy: alphaEpsilon) 87 | } 88 | 89 | func testLargeTextBlackOnWhiteMinAlpha() { 90 | let textColor = UIColor.black 91 | let backgroundColor = UIColor.white 92 | let minAlpha = MDFTextAccessibility.minAlpha(ofTextColor: textColor, 93 | onBackgroundColor:backgroundColor, 94 | options:MDFTextAccessibilityOptions.largeFont) 95 | XCTAssertEqualWithAccuracy(minAlpha, 0.42, accuracy: alphaEpsilon) 96 | } 97 | 98 | func testMinAlphaIgnoresColorAlpha() { 99 | let textColor = UIColor.black 100 | let backgroundColor = UIColor.white 101 | let minAlpha = MDFTextAccessibility.minAlpha(ofTextColor: textColor, 102 | onBackgroundColor:backgroundColor, 103 | options:MDFTextAccessibilityOptions()) 104 | 105 | let textColorWithAlpha = UIColor(white: 0, alpha: 0.5) 106 | let minAlphaWithColorWithAlpha = MDFTextAccessibility.minAlpha(ofTextColor: textColorWithAlpha, 107 | onBackgroundColor:backgroundColor, 108 | options:MDFTextAccessibilityOptions()) 109 | 110 | XCTAssertEqualWithAccuracy(minAlpha, minAlphaWithColorWithAlpha, accuracy: alphaEpsilon) 111 | } 112 | 113 | // MARK: Accessibility standard tests 114 | 115 | func testPassesStandards() { 116 | let backgroundColor = UIColor.white 117 | let grey70 = UIColor(white: 0, alpha: 0.7) // Passes everything. 118 | let grey60 = UIColor(white: 0, alpha: 0.6) // Passes everything except normal text at level AAA. 119 | let grey50 = UIColor(white: 0, alpha: 0.5) // Only passes for large text at level AA. 120 | let grey40 = UIColor(white: 0, alpha: 0.4) // Fails everything. 121 | 122 | // Normal text at the AA level, has to be above ~0.54. 123 | XCTAssertTrue(MDFTextAccessibility.textColor(grey70, passesOnBackgroundColor: backgroundColor, options: MDFTextAccessibilityOptions())) 124 | XCTAssertTrue(MDFTextAccessibility.textColor(grey60, passesOnBackgroundColor: backgroundColor, options: MDFTextAccessibilityOptions())) 125 | XCTAssertFalse(MDFTextAccessibility.textColor(grey50, passesOnBackgroundColor: backgroundColor, options: MDFTextAccessibilityOptions())) 126 | XCTAssertFalse(MDFTextAccessibility.textColor(grey40, passesOnBackgroundColor: backgroundColor, options: MDFTextAccessibilityOptions())) 127 | 128 | // Large text at the AA level, has to be above ~0.42. 129 | XCTAssertTrue(MDFTextAccessibility.textColor(grey70, passesOnBackgroundColor: backgroundColor, options: .largeFont)) 130 | XCTAssertTrue(MDFTextAccessibility.textColor(grey60, passesOnBackgroundColor: backgroundColor, options: .largeFont)) 131 | XCTAssertTrue(MDFTextAccessibility.textColor(grey50, passesOnBackgroundColor: backgroundColor, options: .largeFont)) 132 | XCTAssertFalse(MDFTextAccessibility.textColor(grey40, passesOnBackgroundColor: backgroundColor, options: .largeFont)) 133 | 134 | // Normal text at the AAA level, has to be above ~0.67. 135 | XCTAssertTrue(MDFTextAccessibility.textColor(grey70, passesOnBackgroundColor: backgroundColor, options: .enhancedContrast)) 136 | XCTAssertFalse(MDFTextAccessibility.textColor(grey60, passesOnBackgroundColor: backgroundColor, options: .enhancedContrast)) 137 | XCTAssertFalse(MDFTextAccessibility.textColor(grey50, passesOnBackgroundColor: backgroundColor, options: .enhancedContrast)) 138 | XCTAssertFalse(MDFTextAccessibility.textColor(grey40, passesOnBackgroundColor: backgroundColor, options: .enhancedContrast)) 139 | 140 | // Large text at the AAA level, has to be above ~0.54. 141 | XCTAssertTrue(MDFTextAccessibility.textColor(grey70, passesOnBackgroundColor: backgroundColor, options: [.enhancedContrast, .largeFont])) 142 | XCTAssertTrue(MDFTextAccessibility.textColor(grey60, passesOnBackgroundColor: backgroundColor, options: [.enhancedContrast, .largeFont])) 143 | XCTAssertFalse(MDFTextAccessibility.textColor(grey50, passesOnBackgroundColor: backgroundColor, options: [.enhancedContrast, .largeFont])) 144 | XCTAssertFalse(MDFTextAccessibility.textColor(grey40, passesOnBackgroundColor: backgroundColor, options: [.enhancedContrast, .largeFont])) 145 | } 146 | 147 | // MARK: "Large" fonts. 148 | 149 | func testNormalFontIsNotLarge() { 150 | let font = UIFont.systemFont(ofSize: 14) 151 | XCTAssertFalse(MDFTextAccessibility.isLarge(forContrastRatios: font)) 152 | } 153 | 154 | func testLargeFontIsLarge() { 155 | let font = UIFont.systemFont(ofSize: 18) 156 | XCTAssertTrue(MDFTextAccessibility.isLarge(forContrastRatios: font)) 157 | } 158 | 159 | func testSmallBoldFontIsNotLarge() { 160 | let font = UIFont.boldSystemFont(ofSize: 13) 161 | XCTAssertFalse(MDFTextAccessibility.isLarge(forContrastRatios: font)) 162 | } 163 | 164 | func testBoldFontIsLarge() { 165 | let font = UIFont.boldSystemFont(ofSize: 14) 166 | XCTAssertTrue(MDFTextAccessibility.isLarge(forContrastRatios: font)) 167 | } 168 | 169 | func testNilFontIsNotLarge() { 170 | XCTAssertFalse(MDFTextAccessibility.isLarge(forContrastRatios: nil)) 171 | } 172 | 173 | // MARK: textColorOnBackgroundImage 174 | 175 | func testTextColorOnEmptyBackgroundImage() { 176 | let color = MDFTextAccessibility.textColor(onBackgroundImage: UIImage.init(), inRegion:CGRect(x: 0, y: 0, width: 10, height: 10), targetTextAlpha: 1.0, font: UIFont.boldSystemFont(ofSize: 13)) 177 | XCTAssertNil(color) 178 | } 179 | 180 | func testTextColorOnNonEmptyBackgroundImageOffRegion() { 181 | let image = UIImage.init(named: "100_100_gray", in: Bundle.init(for: type(of: self)), compatibleWith: nil)! 182 | let color = MDFTextAccessibility.textColor(onBackgroundImage: image, inRegion:CGRect(x: -10, y: -10, width: 10, height: 10), targetTextAlpha: 1.0, font: UIFont.boldSystemFont(ofSize: 13)) 183 | XCTAssertNil(color) 184 | } 185 | 186 | func testTextColorOnNonEmptyBackgroundImageZeroRect() { 187 | let image = UIImage.init(named: "100_100_gray", in: Bundle.init(for: type(of: self)), compatibleWith: nil)! 188 | let color = MDFTextAccessibility.textColor(onBackgroundImage: image, inRegion:CGRect.zero, targetTextAlpha: 1.0, font: UIFont.boldSystemFont(ofSize: 13)) 189 | XCTAssertNil(color) 190 | } 191 | 192 | func testTextColorOnNonEmptyBackgroundImage() { 193 | let image = UIImage.init(named: "100_100_gray", in: Bundle.init(for: type(of: self)), compatibleWith: nil)! 194 | let color = MDFTextAccessibility.textColor(onBackgroundImage: image, inRegion:CGRect(x: 0, y: 0, width: 10, height: 10), targetTextAlpha: 1.0, font: UIFont.boldSystemFont(ofSize: 13)) 195 | XCTAssertNotNil(color) 196 | } 197 | 198 | func testWhiteBackgroundImage() { 199 | let alpha:CGFloat = 1.0 200 | let image = UIImage.init(named: "100_100_white", in: Bundle.init(for: type(of: self)), compatibleWith: nil)! 201 | let color = MDFTextAccessibility.textColor(onBackgroundImage: image, inRegion:CGRect(x: 0, y: 0, width: 10, height: 10), targetTextAlpha: alpha, font: UIFont.boldSystemFont(ofSize: 13)) 202 | let components = (color?.cgColor)?.components 203 | // 0 here for the first element in the components array represents a black color to give the most contrast against a fully white background image 204 | XCTAssertTrue(components?[0] == 0) 205 | XCTAssertTrue(components?[1] == alpha) 206 | } 207 | 208 | func testBlackBackgroundImage() { 209 | let alpha:CGFloat = 1 210 | let image = UIImage.init(named: "100_100_black", in: Bundle.init(for: type(of: self)), compatibleWith: nil)! 211 | let color = MDFTextAccessibility.textColor(onBackgroundImage: image, inRegion:CGRect(x: 0, y: 0, width: 10, height: 10), targetTextAlpha: alpha, font: UIFont.boldSystemFont(ofSize: 13)) 212 | let components = (color?.cgColor)?.components 213 | // 1 here for the first element in the components array represents a white color to give the most contrast against a fully black background image 214 | XCTAssertTrue(components?[0] == 1) 215 | XCTAssertTrue(components?[1] == alpha) 216 | } 217 | 218 | func testIsLargeFontContrastRatios() { 219 | XCTAssertTrue(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.boldSystemFont(ofSize: 14))) 220 | XCTAssertTrue(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.systemFont(ofSize: 18))) 221 | XCTAssertTrue(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.systemFont(ofSize: 20))) 222 | 223 | XCTAssertFalse(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.boldSystemFont(ofSize: 13))) 224 | XCTAssertFalse(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.systemFont(ofSize: 17))) 225 | XCTAssertFalse(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.systemFont(ofSize: 10))) 226 | 227 | // Bold and thicker fonts are considered large at a lower font size than nonbold fonts. 228 | XCTAssertTrue(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.systemFont(ofSize: 15, weight: UIFontWeightBlack))) 229 | XCTAssertTrue(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.systemFont(ofSize: 15, weight: UIFontWeightHeavy))) 230 | XCTAssertTrue(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.systemFont(ofSize: 15, weight: UIFontWeightBold))) 231 | // Semibold is considered bold by iOS font-weight APIs: fontDescriptor.symbolicTraits & UIFontDescriptorTraitBold. 232 | XCTAssertTrue(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.systemFont(ofSize: 15, weight: UIFontWeightSemibold))) 233 | 234 | // Non-bold fonts are not considered large at the lower font size threshold. 235 | XCTAssertFalse(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.systemFont(ofSize: 15, weight: UIFontWeightMedium))) 236 | XCTAssertFalse(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.systemFont(ofSize: 15, weight: UIFontWeightRegular))) 237 | XCTAssertFalse(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.systemFont(ofSize: 15, weight: UIFontWeightLight))) 238 | XCTAssertFalse(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.systemFont(ofSize: 15, weight: UIFontWeightThin))) 239 | XCTAssertFalse(MDFTextAccessibility.isLarge(forContrastRatios: UIFont.systemFont(ofSize: 15, weight: UIFontWeightUltraLight))) 240 | } 241 | } 242 | --------------------------------------------------------------------------------