├── .github
├── dependabot.yml
└── workflows
│ ├── codeql-analysis.yml
│ ├── publish-release.yml
│ ├── py-ci.yml
│ ├── py-coverage.yml
│ ├── py-lint.yml
│ └── py-typecheck.yml
├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── MANIFEST.in
├── Makefile
├── README.md
├── codecov.yml
├── lib
├── __init__.py
└── panosifier
│ ├── __init__.py
│ ├── __main__.py
│ └── datastructures.py
├── requirements.in
├── requirements.txt
├── setup.cfg
├── setup.py
├── tests
├── __init__.py
├── profiler.py
├── test_datastructures.py
├── test_main.py
└── testfiles
│ └── fonts
│ ├── LICENSE_OF-NotoL.txt
│ ├── NotoSans-Regular.subset.ttf
│ └── README.md
└── tox.ini
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: pip
4 | directory: "/"
5 | schedule:
6 | interval: daily
7 | open-pull-requests-limit: 10
8 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | name: "CodeQL"
7 |
8 | on:
9 | push:
10 | branches: [main]
11 | pull_request:
12 | # The branches below must be a subset of the branches above
13 | branches: [main]
14 | schedule:
15 | - cron: "0 4 * * 1"
16 |
17 | jobs:
18 | analyze:
19 | name: Analyze
20 | runs-on: ubuntu-latest
21 |
22 | strategy:
23 | fail-fast: false
24 | matrix:
25 | # Override automatic language detection by changing the below list
26 | # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
27 | language: ['python']
28 | # Learn more...
29 | # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
30 |
31 | steps:
32 | - name: Checkout repository
33 | uses: actions/checkout@v2
34 |
35 | # Initializes the CodeQL tools for scanning.
36 | - name: Initialize CodeQL
37 | uses: github/codeql-action/init@v1
38 | with:
39 | languages: ${{ matrix.language }}
40 | # If you wish to specify custom queries, you can do so here or in a config file.
41 | # By default, queries listed here will override any specified in a config file.
42 | # Prefix the list here with "+" to use these queries and those in the config file.
43 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
44 |
45 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
46 | # If this step fails, then you should remove it and run the build manually (see below)
47 | - name: Autobuild
48 | uses: github/codeql-action/autobuild@v1
49 |
50 | # ℹ️ Command-line programs to run using the OS shell.
51 | # 📚 https://git.io/JvXDl
52 |
53 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
54 | # and modify them (or add more) to build your code if your project
55 | # uses a compiled language
56 |
57 | #- run: |
58 | # make bootstrap
59 | # make release
60 |
61 | - name: Perform CodeQL Analysis
62 | uses: github/codeql-action/analyze@v1
63 |
--------------------------------------------------------------------------------
/.github/workflows/publish-release.yml:
--------------------------------------------------------------------------------
1 | on:
2 | push:
3 | # Sequence of patterns matched against refs/tags
4 | tags:
5 | - "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
6 |
7 | name: Create and Publish Release
8 |
9 | jobs:
10 | build:
11 | name: Create and Publish Release
12 | runs-on: ubuntu-latest
13 | strategy:
14 | matrix:
15 | python-version: [3.8]
16 | steps:
17 | - uses: actions/checkout@v2
18 | - name: Set up Python ${{ matrix.python-version }}
19 | uses: actions/setup-python@v2
20 | with:
21 | python-version: ${{ matrix.python-version }}
22 | - name: Install dependencies
23 | run: |
24 | python -m pip install --upgrade pip
25 | pip install --upgrade setuptools wheel twine
26 | - name: Create GitHub release
27 | id: create_release
28 | uses: actions/create-release@v1
29 | env:
30 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31 | with:
32 | tag_name: ${{ github.ref }}
33 | release_name: ${{ github.ref }}
34 | body: |
35 | Please see the root of the repository for the CHANGELOG.md
36 | draft: false
37 | prerelease: false
38 | - name: Build and publish to PyPI
39 | env:
40 | TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
41 | TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
42 | run: |
43 | make dist-build
44 | twine upload dist/*
45 |
--------------------------------------------------------------------------------
/.github/workflows/py-ci.yml:
--------------------------------------------------------------------------------
1 | name: Python CI
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 | runs-on: ${{ matrix.os }}
8 | strategy:
9 | matrix:
10 | os: [ubuntu-latest, macos-latest, windows-latest]
11 | python-version: [3.6, 3.7, 3.8, 3.9]
12 |
13 | steps:
14 | - uses: actions/checkout@v2
15 | - name: Set up Python ${{ matrix.python-version }}
16 | uses: actions/setup-python@v2
17 | with:
18 | python-version: ${{ matrix.python-version }}
19 | - name: Display Python version & architecture
20 | run: |
21 | python -c "import sys; print(sys.version)"
22 | python -c "import struct; print(struct.calcsize('P') * 8)"
23 | - name: Get pip cache dir
24 | id: pip-cache
25 | run: |
26 | pip install --upgrade pip
27 | echo "::set-output name=dir::$(pip cache dir)"
28 | - name: pip cache
29 | uses: actions/cache@v2
30 | with:
31 | path: ${{ steps.pip-cache.outputs.dir }}
32 | key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
33 | restore-keys: |
34 | ${{ runner.os }}-pip-
35 | - name: Install Python testing dependencies
36 | run: pip install --upgrade pytest
37 | - name: Install Python project dependencies
38 | uses: py-actions/py-dependency-install@v2
39 | with:
40 | update-pip: "true"
41 | update-setuptools: "true"
42 | update-wheel: "true"
43 | - name: Install project
44 | run: pip install -r requirements.txt .
45 | - name: Python unit tests
46 | run: pytest
47 |
--------------------------------------------------------------------------------
/.github/workflows/py-coverage.yml:
--------------------------------------------------------------------------------
1 | name: Coverage
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 | runs-on: ${{ matrix.os }}
8 | strategy:
9 | matrix:
10 | os: [ubuntu-latest]
11 | python-version: [3.8]
12 |
13 | steps:
14 | - uses: actions/checkout@v2
15 | - name: Set up Python ${{ matrix.python-version }}
16 | uses: actions/setup-python@v2
17 | with:
18 | python-version: ${{ matrix.python-version }}
19 | - name: Display Python version & architecture
20 | run: |
21 | python -c "import sys; print(sys.version)"
22 | python -c "import struct; print(struct.calcsize('P') * 8)"
23 | - name: Get pip cache dir
24 | id: pip-cache
25 | run: |
26 | pip install --upgrade pip
27 | echo "::set-output name=dir::$(pip cache dir)"
28 | - name: pip cache
29 | uses: actions/cache@v2
30 | with:
31 | path: ${{ steps.pip-cache.outputs.dir }}
32 | key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
33 | restore-keys: |
34 | ${{ runner.os }}-pip-
35 | - name: Install Python testing dependencies
36 | run: pip install --upgrade pytest
37 | - name: Install Python project dependencies
38 | uses: py-actions/py-dependency-install@v2
39 | with:
40 | update-pip: "true"
41 | update-setuptools: "true"
42 | update-wheel: "true"
43 | - name: Install project
44 | run: pip install .
45 | - name: Generate coverage report
46 | run: |
47 | pip install --upgrade coverage
48 | coverage run --source panosifier -m py.test
49 | coverage report -m
50 | coverage xml
51 | - name: Upload coverage to Codecov
52 | uses: codecov/codecov-action@v1
53 | with:
54 | file: ./coverage.xml
55 |
--------------------------------------------------------------------------------
/.github/workflows/py-lint.yml:
--------------------------------------------------------------------------------
1 | name: Python Lints
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 | runs-on: ${{ matrix.os }}
8 | strategy:
9 | matrix:
10 | os: [ubuntu-latest]
11 | python-version: [3.8]
12 |
13 | steps:
14 | - uses: actions/checkout@v2
15 | - name: Set up Python ${{ matrix.python-version }}
16 | uses: actions/setup-python@v2
17 | with:
18 | python-version: ${{ matrix.python-version }}
19 | - name: Install Python testing dependencies
20 | run: pip install --upgrade flake8
21 | - name: flake8 Lint
22 | uses: py-actions/flake8@v1
23 | with:
24 | max-line-length: "90"
25 | path: "lib/panosifier"
26 |
--------------------------------------------------------------------------------
/.github/workflows/py-typecheck.yml:
--------------------------------------------------------------------------------
1 | name: Python Type Checks
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 | runs-on: ${{ matrix.os }}
8 | strategy:
9 | matrix:
10 | os: [ubuntu-latest]
11 | python-version: [3.8]
12 |
13 | steps:
14 | - uses: actions/checkout@v2
15 | - name: Set up Python ${{ matrix.python-version }}
16 | uses: actions/setup-python@v2
17 | with:
18 | python-version: ${{ matrix.python-version }}
19 | - name: Install Python testing dependencies
20 | run: pip install --upgrade mypy
21 | - name: Static type checks
22 | run: mypy lib/panosifier
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | parts/
18 | sdist/
19 | var/
20 | wheels/
21 | *.egg-info/
22 | .installed.cfg
23 | *.egg
24 | MANIFEST
25 |
26 | # PyInstaller
27 | # Usually these files are written by a python script from a template
28 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
29 | *.manifest
30 | *.spec
31 |
32 | # Installer logs
33 | pip-log.txt
34 | pip-delete-this-directory.txt
35 |
36 | # Unit test / coverage reports
37 | htmlcov/
38 | .tox/
39 | .coverage
40 | .coverage.*
41 | .cache
42 | nosetests.xml
43 | coverage.xml
44 | *.cover
45 | .hypothesis/
46 | .pytest_cache/
47 |
48 | # Translations
49 | *.mo
50 | *.pot
51 |
52 | # Django stuff:
53 | *.log
54 | local_settings.py
55 | db.sqlite3
56 |
57 | # Flask stuff:
58 | instance/
59 | .webassets-cache
60 |
61 | # Scrapy stuff:
62 | .scrapy
63 |
64 | # Sphinx documentation
65 | docs/_build/
66 |
67 | # PyBuilder
68 | target/
69 |
70 | # Jupyter Notebook
71 | .ipynb_checkpoints
72 |
73 | # pyenv
74 | .python-version
75 |
76 | # celery beat schedule file
77 | celerybeat-schedule
78 |
79 | # SageMath parsed files
80 | *.sage.py
81 |
82 | # Environments
83 | .env
84 | .venv
85 | env/
86 | venv/
87 | ENV/
88 | env.bak/
89 | venv.bak/
90 |
91 | # Spyder project settings
92 | .spyderproject
93 | .spyproject
94 |
95 | # Rope project settings
96 | .ropeproject
97 |
98 | # mkdocs documentation
99 | /site
100 |
101 | # mypy
102 | .mypy_cache/
103 | .dmypy.json
104 | dmypy.json
105 |
106 | # Pyre type checker
107 | .pyre/
108 |
109 | # Visual Code dir
110 | .vscode
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ## v1.0.1
4 |
5 | - dependency update patch
6 | - update fonttools dependency to v4.17.0
7 |
8 | ## v1.0.0
9 |
10 | - initial production release with support for comma-delimited full panose data definitions and individual panose data field option definitions
11 |
12 | ## v0.0.1
13 |
14 | - PyPI name save release
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include CHANGELOG.md
2 | include LICENSE
3 | include README.md
4 |
5 | include *requirements.txt
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | all: install
2 |
3 | black:
4 | black -l 90 lib/panosifier/*.py
5 |
6 | clean:
7 | - rm dist/*.whl dist/*.tar.gz dist/*.zip
8 |
9 | dist-build: clean
10 | python3 setup.py sdist bdist_wheel
11 |
12 | dist-push:
13 | twine upload dist/*.whl dist/*.tar.gz
14 |
15 | install:
16 | pip3 install --ignore-installed -r requirements.txt .
17 |
18 | install-dev:
19 | pip3 install --ignore-installed -r requirements.txt -e ".[dev]"
20 |
21 | install-user:
22 | pip3 install --ignore-installed --user .
23 |
24 | test: test-lint test-type-check test-unit
25 |
26 | test-coverage:
27 | coverage run --source panosifier -m py.test
28 | coverage report -m
29 | # coverage html
30 |
31 | test-lint:
32 | flake8 --ignore=W50 lib/panosifier
33 |
34 | test-type-check:
35 | mypy lib/panosifier
36 |
37 | test-unit:
38 | tox
39 |
40 | uninstall:
41 | pip3 uninstall --yes panosifier
42 |
43 | .PHONY: all black clean dist-build dist-push install install-dev install-user test test-lint test-type-check test-unit uninstall
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # panosifier
2 |
3 | ### panose data editor for fonts
4 |
5 | [](https://pypi.org/project/panosifier/)
6 | [](https://github.com/source-foundry/panosifier/blob/main/LICENSE)
7 | 
8 | 
9 | 
10 | [](https://codecov.io/gh/source-foundry/panosifier/)
11 |
12 | ## About
13 |
14 | panosifier is a Python 3.6+ command line application that edits [panose data](https://monotype.github.io/panose/pan1.htm) in fonts. The tool edits the [OpenType specification OS/2 table panose fields](https://docs.microsoft.com/en-us/typography/opentype/spec/os2#panose).
15 |
16 | ## Why do I need this tool?
17 |
18 | In many cases, you can define these values in your type design source files and rely on the font compiler to write these values into your font instances. However, there are situations where this behavior is not well-defined and differs across font compilers.
19 |
20 | An example is the approach to panose data writes in variable font format files. In this case, the OpenType specification is vague, environments where these data are essential are not well-defined, and compilers handle the source file defined panose data differently.
21 |
22 | This tool allows you to modify build-time decisions in these situations.
23 |
24 | ## Quick Start
25 |
26 | - Install in a Python 3.6+ virtual environment with `pip install panosifier`
27 | - Define your panose values with a comma-delimited panose value list using the `--panose` command line option or individually with the ten available OpenType panose field options (see `panosifier --help` for a list of available options)
28 |
29 | See the documentation below for additional details.
30 |
31 | ## Installation
32 |
33 | This project requires a Python 3.6+ interpreter.
34 |
35 | We recommend installation in a Python3 virtual environment.
36 |
37 | Use any of the following installation approaches:
38 |
39 | ### pip install from PyPI
40 |
41 | ```
42 | $ pip3 install panosifier
43 | ```
44 |
45 | ### pip install from source
46 |
47 | ```
48 | $ git clone https://github.com/source-foundry/panosifier.git
49 | $ cd panosifier
50 | $ pip3 install -r requirements.txt .
51 | ```
52 |
53 | ### Developer install from source
54 |
55 | The following approach installs the project and associated optional developer dependencies so that source changes are available without the need for re-installation.
56 |
57 | ```
58 | $ git clone https://github.com/source-foundry/panosifier.git
59 | $ cd panosifier
60 | $ pip3 install --ignore-installed -r requirements.txt -e ".[dev]"
61 | ```
62 |
63 | ## Usage
64 |
65 | panosifier supports two command line approaches to edit panose data in one or more command line defined font paths:
66 |
67 | 1. Define all 10 OpenType panose fields with an ordered comma-delimited list of integers with the `--panose` option
68 | 2. Define with individual command line options for one or more of the 10 OpenType panose fields
69 |
70 | ### Comma-delimited list definition
71 |
72 | You can define all panose fields at once with an ordered, comma-delimited list of all 10 OpenType panose values. These must be integer values.
73 |
74 | The field order is:
75 |
76 | 1. FamilyType
77 | 2. SerifStyle
78 | 3. Weight
79 | 4. Proportion
80 | 5. Contrast
81 | 6. StrokeVariation
82 | 7. ArmStyle
83 | 8. LetterForm
84 | 9. Midline
85 | 10. XHeight
86 |
87 | The following image exemplifies this order in the `--panose` option definition idiom. Note that the values in this example are not intended to be valid for a font, but rather to demonstrate how the definition order maps to panose definition fields.
88 |
89 |
90 |
91 | ### Individual panose field options
92 |
93 | There are ten available OpenType panose definitions. Each panose field has a corresponding option in the panosifier tool. These options allow you to define each field individually and make panose definitions explicit in scripted build workflows. Define these options with integer values.
94 |
95 | The example below modifies the panose data write in the comma-delimited list section above with new FamilyType and Proportion values of 2 and 9, respectively:
96 |
97 |
98 |
99 | Use `panosifier --help` to view all available options.
100 |
101 | **Note**: This tool does not perform sanity checks on your definitions and can be used to write invalid definitions in fonts. The tool assumes that you understand how to set these panose values. Please refer to the [panose documentation](https://monotype.github.io/panose/pan1.htm) for detailed background.
102 |
103 | ### Reporting
104 |
105 | panosifier reports panose data definitions in the standard output stream at the end of execution.
106 |
107 | ## Contributing
108 |
109 | Contributions are warmly welcomed. A development dependency environment can be installed in editable mode with the developer installation documentation above.
110 |
111 | Please use the standard Github pull request approach to propose source changes.
112 |
113 | ### Source file linting
114 |
115 | We lint Python source files with `flake8`. See the Makefile `test-lint` target for details.
116 |
117 | ### Testing
118 |
119 | Continuous integration testing is performed on the GitHub Actions service with the `pytest` toolchain. Test modules are located in the `tests` directory of the repository.
120 |
121 | Perform local Python interpreter version testing with the following command executed from the root of the repository:
122 |
123 | ```
124 | $ tox -e [PYTHON INTERPRETER VERSION]
125 | ```
126 |
127 | Please see the `tox` documentation for additional details.
128 |
129 | ### Test coverage
130 |
131 | We perform unit test coverage testing with the `coverage` tool. See the Makefile `test-coverage` target for details.
132 |
133 | ## Acknowledgments
134 |
135 | panosifier is built with the fantastic free [fonttools](https://github.com/fonttools/fonttools) Python library.
136 |
137 | ## License
138 |
139 | [Apache License v2.0](https://github.com/source-foundry/panosifier/blob/main/LICENSE)
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | codecov:
2 | max_report_age: off
3 |
4 | coverage:
5 | status:
6 | project:
7 | default:
8 | # basic
9 | target: auto
10 | threshold: 2%
11 | base: auto
12 |
13 | comment: off
--------------------------------------------------------------------------------
/lib/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/source-foundry/panosifier/9f61da80d1d85505d2e496c9bfdbae1c6927c730/lib/__init__.py
--------------------------------------------------------------------------------
/lib/panosifier/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | version = __version__ = "1.0.2-dev0"
4 |
--------------------------------------------------------------------------------
/lib/panosifier/__main__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | # Copyright 2020 Source Foundry Authors
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 argparse
18 | import os
19 | import sys
20 | from typing import List
21 |
22 | from fontTools.ttLib import TTFont # type: ignore
23 |
24 | from . import __version__
25 | from .datastructures import Panose
26 |
27 |
28 | def main() -> None: # pragma: no cover
29 | run(sys.argv[1:])
30 |
31 |
32 | def validate_args_exclusive(args: argparse.Namespace) -> None:
33 | if args.panose and (
34 | args.familytype
35 | or args.serifstyle
36 | or args.weight
37 | or args.proportion
38 | or args.contrast
39 | or args.strokevar
40 | or args.armstyle
41 | or args.letterform
42 | or args.midline
43 | or args.xheight
44 | ):
45 | sys.stderr.write(
46 | f"[ERROR] the '--panose' option cannot be used with other panose definition "
47 | f"options{os.linesep}"
48 | )
49 | sys.exit(1)
50 |
51 |
52 | def validate_args_at_least_one_definition(args: argparse.Namespace) -> None:
53 | if not args.panose and not (
54 | args.familytype
55 | or args.serifstyle
56 | or args.weight
57 | or args.proportion
58 | or args.contrast
59 | or args.strokevar
60 | or args.armstyle
61 | or args.letterform
62 | or args.midline
63 | or args.xheight
64 | ):
65 | sys.stderr.write(
66 | f"[ERROR] include at least one panose definition in your command "
67 | f"{os.linesep}"
68 | )
69 | sys.exit(1)
70 |
71 |
72 | def validate_args_filepaths_exist(args: argparse.Namespace) -> None:
73 | for fontpath in args.PATH:
74 | if not os.path.isfile(fontpath):
75 | sys.stderr.write(
76 | f"[ERROR] '{fontpath}' does not appear to be a valid file{os.linesep}"
77 | )
78 | sys.exit(1)
79 |
80 |
81 | def run(argv: List[str]) -> None:
82 | # ===========================================================
83 | # argparse command line argument definitions
84 | # ===========================================================
85 | parser = argparse.ArgumentParser(description="Panose data editor for fonts")
86 | parser.add_argument(
87 | "-v", "--version", action="version", version=f"panosifier v{__version__}"
88 | )
89 | parser.add_argument(
90 | "--panose", type=str, required=False, help="comma delimited panose value list"
91 | )
92 | parser.add_argument("--familytype", type=int, required=False, help="FamilyType value")
93 | parser.add_argument("--serifstyle", type=int, required=False, help="SerifStyle value")
94 | parser.add_argument("--weight", type=int, required=False, help="Weight value")
95 | parser.add_argument("--proportion", type=int, required=False, help="Propotion value")
96 | parser.add_argument("--contrast", type=int, required=False, help="Contrast value")
97 | parser.add_argument(
98 | "--strokevar", type=int, required=False, help="StrokeVariation value"
99 | )
100 | parser.add_argument("--armstyle", type=int, required=False, help="ArmStyle value")
101 | parser.add_argument("--letterform", type=int, required=False, help="Letterform value")
102 | parser.add_argument("--midline", type=int, required=False, help="Midline value")
103 | parser.add_argument("--xheight", type=int, required=False, help="XHeight value")
104 | parser.add_argument("PATH", nargs="+", help="Font file path")
105 | args = parser.parse_args(argv)
106 |
107 | # additional CL args validations
108 | validate_args_at_least_one_definition(args)
109 | validate_args_exclusive(args)
110 | validate_args_filepaths_exist(args)
111 |
112 | # panose data edit implementation
113 | for fontpath in args.PATH:
114 | try:
115 | tt = TTFont(fontpath)
116 | except Exception as e:
117 | sys.stderr.write(f"[ERROR] during edit of '{fontpath}': {str(e)}{os.linesep}")
118 | sys.exit(1)
119 |
120 | # define with comma-delimited panose definition string
121 | if args.panose:
122 | panose = Panose()
123 | try:
124 | panose.set_panose_with_comma_delim_string(args.panose)
125 | except ValueError as e:
126 | sys.stderr.write(f"[ERROR] {str(e)}{os.linesep}")
127 | sys.exit(1)
128 | # or define with individual panose definition arguments
129 | else:
130 | try:
131 | panose = Panose(
132 | familytype=args.familytype,
133 | serifstyle=args.serifstyle,
134 | weight=args.weight,
135 | proportion=args.proportion,
136 | contrast=args.contrast,
137 | strokevar=args.strokevar,
138 | armstyle=args.armstyle,
139 | letterform=args.letterform,
140 | midline=args.midline,
141 | xheight=args.xheight,
142 | )
143 | except ValueError as e:
144 | sys.stderr.write(f"[ERROR] {str(e)}{os.linesep}")
145 | sys.exit(1)
146 |
147 | try:
148 | tt = panose.set_font_panose_data(TTFont(fontpath))
149 | tt.save(fontpath)
150 |
151 | # edited font panose data report
152 | tt_edited = TTFont(fontpath)
153 | new_panose = tt_edited["OS/2"].panose.__dict__
154 | print(f"{fontpath} panose:")
155 | space = " " * 3
156 | print(f"{space}FamilyType: {new_panose['bFamilyType']}")
157 | print(f"{space}SerifStyle: {new_panose['bSerifStyle']}")
158 | print(f"{space}Weight: {new_panose['bWeight']}")
159 | print(f"{space}Proportion: {new_panose['bProportion']}")
160 | print(f"{space}Contrast: {new_panose['bContrast']}")
161 | print(f"{space}StrokeVariation: {new_panose['bStrokeVariation']}")
162 | print(f"{space}ArmStyle: {new_panose['bArmStyle']}")
163 | print(f"{space}LetterForm: {new_panose['bLetterForm']}")
164 | print(f"{space}Midline: {new_panose['bMidline']}")
165 | print(f"{space}XHeight: {new_panose['bXHeight']}")
166 | except Exception as e:
167 | sys.stderr.write(f"[ERROR] '{fontpath}' error: {str(e)}{os.linesep}")
168 | sys.exit(1)
169 |
--------------------------------------------------------------------------------
/lib/panosifier/datastructures.py:
--------------------------------------------------------------------------------
1 | from typing import Optional
2 |
3 | from fontTools.ttLib import TTFont # type: ignore
4 |
5 |
6 | class Panose(object):
7 | def __init__(self, **kwargs) -> None:
8 | self.familytype: Optional[int] = None
9 | self.serifstyle: Optional[int] = None
10 | self.weight: Optional[int] = None
11 | self.proportion: Optional[int] = None
12 | self.contrast: Optional[int] = None
13 | self.strokevar: Optional[int] = None
14 | self.armstyle: Optional[int] = None
15 | self.letterform: Optional[int] = None
16 | self.midline: Optional[int] = None
17 | self.xheight: Optional[int] = None
18 | self.__dict__.update(kwargs)
19 | self._validate_attributes()
20 |
21 | def __str__(self) -> str:
22 | return f"< Panose {self.__dict__} >"
23 |
24 | def __repr__(self) -> str:
25 | return f"< Panose {self.__dict__} >"
26 |
27 | def _validate_attributes(self) -> None:
28 | if self.familytype:
29 | int(self.familytype)
30 | if self.serifstyle:
31 | int(self.serifstyle)
32 | if self.weight:
33 | int(self.weight)
34 | if self.proportion:
35 | int(self.proportion)
36 | if self.contrast:
37 | int(self.contrast)
38 | if self.strokevar:
39 | int(self.strokevar)
40 | if self.armstyle:
41 | int(self.armstyle)
42 | if self.letterform:
43 | int(self.letterform)
44 | if self.midline:
45 | int(self.midline)
46 | if self.xheight:
47 | int(self.xheight)
48 |
49 | def set_panose_with_comma_delim_string(self, comma_delim_string: str) -> None:
50 | panose_list = comma_delim_string.split(",")
51 | if len(panose_list) != 10:
52 | raise ValueError(
53 | f"incorrect number of panose values. Received {len(panose_list)} "
54 | f"values and require 10 values"
55 | )
56 | # define panose values with parsed data
57 | self.familytype = int(panose_list[0])
58 | self.serifstyle = int(panose_list[1])
59 | self.weight = int(panose_list[2])
60 | self.proportion = int(panose_list[3])
61 | self.contrast = int(panose_list[4])
62 | self.strokevar = int(panose_list[5])
63 | self.armstyle = int(panose_list[6])
64 | self.letterform = int(panose_list[7])
65 | self.midline = int(panose_list[8])
66 | self.xheight = int(panose_list[9])
67 |
68 | def set_font_panose_data(self, tt: TTFont) -> TTFont:
69 | if self.familytype:
70 | tt["OS/2"].panose.bFamilyType = self.familytype
71 | if self.serifstyle:
72 | tt["OS/2"].panose.bSerifStyle = self.serifstyle
73 | if self.weight:
74 | tt["OS/2"].panose.bWeight = self.weight
75 | if self.proportion:
76 | tt["OS/2"].panose.bProportion = self.proportion
77 | if self.contrast:
78 | tt["OS/2"].panose.bContrast = self.contrast
79 | if self.strokevar:
80 | tt["OS/2"].panose.bStrokeVariation = self.strokevar
81 | if self.armstyle:
82 | tt["OS/2"].panose.bArmStyle = self.armstyle
83 | if self.letterform:
84 | tt["OS/2"].panose.bLetterForm = self.letterform
85 | if self.midline:
86 | tt["OS/2"].panose.bMidline = self.midline
87 | if self.xheight:
88 | tt["OS/2"].panose.bXHeight = self.xheight
89 | return tt
90 |
--------------------------------------------------------------------------------
/requirements.in:
--------------------------------------------------------------------------------
1 | fontTools
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | #
2 | # This file is autogenerated by pip-compile
3 | # To update, run:
4 | #
5 | # pip-compile requirements.in
6 | #
7 | fonttools==4.27.1
8 | # via -r requirements.in
9 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | [bdist_wheel]
2 | universal = 0
3 |
4 | [flake8]
5 | max-line-length = 90
6 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | import io
2 | import os
3 | import sys
4 |
5 | from setuptools import find_packages, setup
6 |
7 | # Package meta-data.
8 | NAME = "panosifier"
9 | DESCRIPTION = "Panose data editor for fonts"
10 | LICENSE = "Apache License v2.0"
11 | URL = "https://github.com/source-foundry/panosifier"
12 | EMAIL = "chris@sourcefoundry.org"
13 | AUTHOR = "Christopher Simpkins"
14 | REQUIRES_PYTHON = ">=3.6.0"
15 |
16 | INSTALL_REQUIRES = ["fontTools"]
17 | # Optional packages
18 | EXTRAS_REQUIRES = {
19 | # for developer installs
20 | "dev": ["coverage", "pytest", "tox", "flake8", "mypy"],
21 | # for maintainer installs
22 | "maintain": ["wheel", "setuptools", "twine"],
23 | }
24 |
25 | this_file_path = os.path.abspath(os.path.dirname(__file__))
26 |
27 | # Version
28 | main_namespace = {}
29 | version_fp = os.path.join(this_file_path, "lib", "panosifier", "__init__.py")
30 | try:
31 | with io.open(version_fp) as v:
32 | exec(v.read(), main_namespace)
33 | except IOError as version_e:
34 | sys.stderr.write(
35 | "[ERROR] setup.py: Failed to read data for the version definition: {}".format(
36 | str(version_e)
37 | )
38 | )
39 | raise version_e
40 |
41 | # Use repository Markdown README.md for PyPI long description
42 | try:
43 | with io.open("README.md", encoding="utf-8") as f:
44 | readme = f.read()
45 | except IOError as readme_e:
46 | sys.stderr.write(
47 | "[ERROR] setup.py: Failed to read README.md for the long description: {}".format(
48 | str(readme_e)
49 | )
50 | )
51 | raise readme_e
52 |
53 | setup(
54 | name=NAME,
55 | version=main_namespace["__version__"],
56 | description=DESCRIPTION,
57 | author=AUTHOR,
58 | author_email=EMAIL,
59 | url=URL,
60 | license=LICENSE,
61 | platforms=["Any"],
62 | long_description=readme,
63 | long_description_content_type="text/markdown",
64 | package_dir={"": "lib"},
65 | packages=find_packages("lib"),
66 | include_package_data=True,
67 | install_requires=INSTALL_REQUIRES,
68 | extras_require=EXTRAS_REQUIRES,
69 | python_requires=REQUIRES_PYTHON,
70 | entry_points={"console_scripts": ["panosifier = panosifier.__main__:main"]},
71 | classifiers=[
72 | "Development Status :: 5 - Production/Stable",
73 | "Environment :: Console",
74 | "Intended Audience :: Developers",
75 | "Intended Audience :: End Users/Desktop",
76 | "License :: OSI Approved :: Apache Software License",
77 | "Natural Language :: English",
78 | "Operating System :: OS Independent",
79 | "Topic :: Text Processing :: Fonts",
80 | "Programming Language :: Python",
81 | "Programming Language :: Python :: 3",
82 | "Programming Language :: Python :: 3.6",
83 | "Programming Language :: Python :: 3.7",
84 | "Programming Language :: Python :: 3.8",
85 | "Programming Language :: Python :: 3.9",
86 | ],
87 | )
88 |
--------------------------------------------------------------------------------
/tests/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/source-foundry/panosifier/9f61da80d1d85505d2e496c9bfdbae1c6927c730/tests/__init__.py
--------------------------------------------------------------------------------
/tests/profiler.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | # -*- coding: utf-8 -*-
3 |
4 | import cProfile
5 | import pstats
6 | from io import StringIO
7 |
8 |
9 | def profile():
10 | # ------------------------------------------------------------------------------
11 | # Setup a profile
12 | # ------------------------------------------------------------------------------
13 | pr = cProfile.Profile()
14 | # ------------------------------------------------------------------------------
15 | # Enter setup code below
16 | # ------------------------------------------------------------------------------
17 | # Optional: include setup code here
18 |
19 | # ------------------------------------------------------------------------------
20 | # Start profiler
21 | # ------------------------------------------------------------------------------
22 | pr.enable()
23 |
24 | # ------------------------------------------------------------------------------
25 | # BEGIN profiled code block
26 | # ------------------------------------------------------------------------------
27 |
28 | # ------------------------------------------------------------------------------
29 | # END profiled code block
30 | # ------------------------------------------------------------------------------
31 | pr.disable()
32 | s = StringIO()
33 | sortby = "cumulative"
34 | ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
35 | ps.strip_dirs().sort_stats("time").print_stats()
36 | print(s.getvalue())
37 |
38 |
39 | if __name__ == "__main__":
40 | profile()
41 |
--------------------------------------------------------------------------------
/tests/test_datastructures.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | import pytest
4 | from fontTools.ttLib import TTFont
5 |
6 | from panosifier import datastructures
7 |
8 |
9 | def get_test_font():
10 | return TTFont(
11 | os.path.join("tests", "testfiles", "fonts", "NotoSans-Regular.subset.ttf")
12 | )
13 |
14 |
15 | def test_panose_obj_instantiation_default():
16 | panose = datastructures.Panose()
17 | assert panose.familytype is None
18 | assert panose.serifstyle is None
19 | assert panose.weight is None
20 | assert panose.proportion is None
21 | assert panose.contrast is None
22 | assert panose.strokevar is None
23 | assert panose.armstyle is None
24 | assert panose.letterform is None
25 | assert panose.midline is None
26 | assert panose.xheight is None
27 |
28 |
29 | def test_panose_obj_instantiation_with_valid_parameters():
30 | panose = datastructures.Panose(
31 | familytype=1,
32 | serifstyle=2,
33 | weight=3,
34 | proportion=4,
35 | contrast=5,
36 | strokevar=6,
37 | armstyle=7,
38 | letterform=8,
39 | midline=9,
40 | xheight=10,
41 | )
42 | assert panose.familytype == 1
43 | assert panose.serifstyle == 2
44 | assert panose.weight == 3
45 | assert panose.proportion == 4
46 | assert panose.contrast == 5
47 | assert panose.strokevar == 6
48 | assert panose.armstyle == 7
49 | assert panose.letterform == 8
50 | assert panose.midline == 9
51 | assert panose.xheight == 10
52 |
53 |
54 | def test_panose_obj_instantiation_with_invalid_parameter_type():
55 | """
56 | Confirm that non-integer type raises ValueError
57 | """
58 | with pytest.raises(ValueError):
59 | datastructures.Panose(familytype="test")
60 |
61 | with pytest.raises(ValueError):
62 | datastructures.Panose(xheight="test")
63 |
64 |
65 | def test_panose_obj_str_repr():
66 | panose = datastructures.Panose()
67 | # test default values
68 | p_str = panose.__str__()
69 | assert (
70 | p_str
71 | == "< Panose {'familytype': None, 'serifstyle': None, 'weight': None, 'proportion': None, 'contrast': None, 'strokevar': None, 'armstyle': None, 'letterform': None, 'midline': None, 'xheight': None} >"
72 | )
73 | p_repr = panose.__repr__()
74 | assert (
75 | p_repr
76 | == "< Panose {'familytype': None, 'serifstyle': None, 'weight': None, 'proportion': None, 'contrast': None, 'strokevar': None, 'armstyle': None, 'letterform': None, 'midline': None, 'xheight': None} >"
77 | )
78 |
79 | # test with defined value
80 | panose.familytype = 1
81 |
82 | p_str = panose.__str__()
83 | assert (
84 | p_str
85 | == "< Panose {'familytype': 1, 'serifstyle': None, 'weight': None, 'proportion': None, 'contrast': None, 'strokevar': None, 'armstyle': None, 'letterform': None, 'midline': None, 'xheight': None} >"
86 | )
87 | p_repr = panose.__repr__()
88 | assert (
89 | p_repr
90 | == "< Panose {'familytype': 1, 'serifstyle': None, 'weight': None, 'proportion': None, 'contrast': None, 'strokevar': None, 'armstyle': None, 'letterform': None, 'midline': None, 'xheight': None} >"
91 | )
92 |
93 |
94 | def test_panose_obj_set_attr_with_comma_delim_string():
95 | panose = datastructures.Panose()
96 | assert panose.familytype is None
97 | assert panose.serifstyle is None
98 | assert panose.weight is None
99 | assert panose.proportion is None
100 | assert panose.contrast is None
101 | assert panose.strokevar is None
102 | assert panose.armstyle is None
103 | assert panose.letterform is None
104 | assert panose.midline is None
105 | assert panose.xheight is None
106 |
107 | value_str = "1,2,3,4,5,6,7,8,9,10"
108 | panose.set_panose_with_comma_delim_string(value_str)
109 |
110 | assert panose.familytype == 1
111 | assert panose.serifstyle == 2
112 | assert panose.weight == 3
113 | assert panose.proportion == 4
114 | assert panose.contrast == 5
115 | assert panose.strokevar == 6
116 | assert panose.armstyle == 7
117 | assert panose.letterform == 8
118 | assert panose.midline == 9
119 | assert panose.xheight == 10
120 |
121 |
122 | def test_panose_obj_set_attr_with_comma_delim_string_invalid_type():
123 | panose = datastructures.Panose()
124 | value_str = "1,1,1,1,1,1,1,1,1,bogus"
125 | with pytest.raises(ValueError):
126 | panose.set_panose_with_comma_delim_string(value_str)
127 |
128 |
129 | def test_panose_obj_set_attr_with_comma_delim_string_invalid_number_of_values():
130 | panose = datastructures.Panose()
131 | # 10 panose values is required
132 | # the following string includes 9 panose values
133 | # should raise exception
134 | value_str = "1,1,1,1,1,1,1,1,1"
135 | with pytest.raises(ValueError):
136 | panose.set_panose_with_comma_delim_string(value_str)
137 |
138 | # the following string includes 11 panose values
139 | # should raise exception
140 | value_str = "1,1,1,1,1,1,1,1,1,1,1"
141 | with pytest.raises(ValueError):
142 | panose.set_panose_with_comma_delim_string(value_str)
143 |
144 |
145 | def test_panose_obj_set_font_panose_data():
146 | tt = get_test_font()
147 | assert tt["OS/2"].panose.bFamilyType == 2
148 | assert tt["OS/2"].panose.bSerifStyle == 11
149 | assert tt["OS/2"].panose.bWeight == 5
150 | assert tt["OS/2"].panose.bProportion == 2
151 | assert tt["OS/2"].panose.bContrast == 4
152 | assert tt["OS/2"].panose.bStrokeVariation == 5
153 | assert tt["OS/2"].panose.bArmStyle == 4
154 | assert tt["OS/2"].panose.bLetterForm == 2
155 | assert tt["OS/2"].panose.bMidline == 2
156 | assert tt["OS/2"].panose.bXHeight == 4
157 |
158 | panose = datastructures.Panose(
159 | familytype=1,
160 | serifstyle=2,
161 | weight=3,
162 | proportion=4,
163 | contrast=5,
164 | strokevar=6,
165 | armstyle=7,
166 | letterform=8,
167 | midline=9,
168 | xheight=10,
169 | )
170 |
171 | panose.set_font_panose_data(tt)
172 | assert tt["OS/2"].panose.bFamilyType == 1
173 | assert tt["OS/2"].panose.bSerifStyle == 2
174 | assert tt["OS/2"].panose.bWeight == 3
175 | assert tt["OS/2"].panose.bProportion == 4
176 | assert tt["OS/2"].panose.bContrast == 5
177 | assert tt["OS/2"].panose.bStrokeVariation == 6
178 | assert tt["OS/2"].panose.bArmStyle == 7
179 | assert tt["OS/2"].panose.bLetterForm == 8
180 | assert tt["OS/2"].panose.bMidline == 9
181 | assert tt["OS/2"].panose.bXHeight == 10
182 |
--------------------------------------------------------------------------------
/tests/test_main.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import argparse
4 | import os
5 | import shutil
6 | import tempfile
7 |
8 | import pytest
9 | from fontTools.ttLib import TTFont
10 |
11 | from panosifier import __main__
12 |
13 |
14 | def test_validate_args_exclusive(capsys):
15 | parser = argparse.ArgumentParser()
16 | parser.add_argument("--panose")
17 | parser.add_argument("--familytype")
18 | parser.add_argument("PATH", nargs="+")
19 | argv = ["--panose", "1", "--familytype", "1", "testfont.ttf"]
20 | args = parser.parse_args(argv)
21 | with pytest.raises(SystemExit) as e:
22 | __main__.validate_args_exclusive(args)
23 |
24 | captured = capsys.readouterr()
25 | assert e.type == SystemExit
26 | assert e.value.code == 1
27 | assert (
28 | "the '--panose' option cannot be used with other panose definition"
29 | in captured.err
30 | )
31 |
32 |
33 | def test_validate_args_at_least_one_def(capsys):
34 | parser = argparse.ArgumentParser()
35 | parser.add_argument("--panose")
36 | parser.add_argument("--familytype")
37 | parser.add_argument("--serifstyle")
38 | parser.add_argument("--weight")
39 | parser.add_argument("--proportion")
40 | parser.add_argument("--contrast")
41 | parser.add_argument("--strokevar")
42 | parser.add_argument("--armstyle")
43 | parser.add_argument("--letterform")
44 | parser.add_argument("--midline")
45 | parser.add_argument("--xheight")
46 | parser.add_argument("PATH", nargs="+")
47 | argv = ["testfont.ttf"]
48 | args = parser.parse_args(argv)
49 | with pytest.raises(SystemExit) as e:
50 | __main__.validate_args_at_least_one_definition(args)
51 |
52 | captured = capsys.readouterr()
53 | assert e.type == SystemExit
54 | assert e.value.code == 1
55 | assert "include at least one panose definition in your command" in captured.err
56 |
57 |
58 | def test_validate_args_filepaths_exist(capsys):
59 | parser = argparse.ArgumentParser()
60 | parser.add_argument("PATH", nargs="+")
61 | argv = ["testfont.ttf"]
62 | args = parser.parse_args(argv)
63 |
64 | # invalid path should raise exception
65 | with pytest.raises(SystemExit) as e:
66 | __main__.validate_args_filepaths_exist(args)
67 |
68 | captured = capsys.readouterr()
69 | assert e.type == SystemExit
70 | assert e.value.code == 1
71 | assert "does not appear to be a valid file" in captured.err
72 |
73 | # valid path should not raise exception
74 | argv_2 = [
75 | f"{os.path.join('tests', 'testfiles', 'fonts', 'NotoSans-Regular.subset.ttf')}"
76 | ]
77 | args2 = parser.parse_args(argv_2)
78 | __main__.validate_args_filepaths_exist(args2)
79 |
80 |
81 | def test_run_define_with_options():
82 | test_font_name = "NotoSans-Regular.subset.ttf"
83 | source_path = os.path.join("tests", "testfiles", "fonts", test_font_name)
84 | with tempfile.TemporaryDirectory() as tmpdirname:
85 | dest_path = os.path.join(tmpdirname, test_font_name)
86 | shutil.copyfile(source_path, dest_path)
87 |
88 | # confirm pre panose data
89 | tt_pre = TTFont(dest_path)
90 | assert tt_pre["OS/2"].panose.bFamilyType == 2
91 | assert tt_pre["OS/2"].panose.bSerifStyle == 11
92 | assert tt_pre["OS/2"].panose.bWeight == 5
93 | assert tt_pre["OS/2"].panose.bProportion == 2
94 | assert tt_pre["OS/2"].panose.bContrast == 4
95 | assert tt_pre["OS/2"].panose.bStrokeVariation == 5
96 | assert tt_pre["OS/2"].panose.bArmStyle == 4
97 | assert tt_pre["OS/2"].panose.bLetterForm == 2
98 | assert tt_pre["OS/2"].panose.bMidline == 2
99 | assert tt_pre["OS/2"].panose.bXHeight == 4
100 |
101 | argv = ["--proportion", "9", "--xheight", "2", f"{dest_path}"]
102 | __main__.run(argv)
103 |
104 | tt_post = TTFont(dest_path)
105 | assert tt_post["OS/2"].panose.bFamilyType == 2
106 | assert tt_post["OS/2"].panose.bSerifStyle == 11
107 | assert tt_post["OS/2"].panose.bWeight == 5
108 | assert tt_post["OS/2"].panose.bProportion == 9
109 | assert tt_post["OS/2"].panose.bContrast == 4
110 | assert tt_post["OS/2"].panose.bStrokeVariation == 5
111 | assert tt_post["OS/2"].panose.bArmStyle == 4
112 | assert tt_post["OS/2"].panose.bLetterForm == 2
113 | assert tt_post["OS/2"].panose.bMidline == 2
114 | assert tt_post["OS/2"].panose.bXHeight == 2
115 |
116 |
117 | def test_run_define_with_panose_comma_delimited_definition():
118 | test_font_name = "NotoSans-Regular.subset.ttf"
119 | source_path = os.path.join("tests", "testfiles", "fonts", test_font_name)
120 | with tempfile.TemporaryDirectory() as tmpdirname:
121 | dest_path = os.path.join(tmpdirname, test_font_name)
122 | shutil.copyfile(source_path, dest_path)
123 |
124 | # confirm pre panose data
125 | tt_pre = TTFont(dest_path)
126 | assert tt_pre["OS/2"].panose.bFamilyType == 2
127 | assert tt_pre["OS/2"].panose.bSerifStyle == 11
128 | assert tt_pre["OS/2"].panose.bWeight == 5
129 | assert tt_pre["OS/2"].panose.bProportion == 2
130 | assert tt_pre["OS/2"].panose.bContrast == 4
131 | assert tt_pre["OS/2"].panose.bStrokeVariation == 5
132 | assert tt_pre["OS/2"].panose.bArmStyle == 4
133 | assert tt_pre["OS/2"].panose.bLetterForm == 2
134 | assert tt_pre["OS/2"].panose.bMidline == 2
135 | assert tt_pre["OS/2"].panose.bXHeight == 4
136 |
137 | argv = ["--panose", "1,2,3,4,5,6,7,8,9,10", f"{dest_path}"]
138 | __main__.run(argv)
139 |
140 | tt_post = TTFont(dest_path)
141 | assert tt_post["OS/2"].panose.bFamilyType == 1
142 | assert tt_post["OS/2"].panose.bSerifStyle == 2
143 | assert tt_post["OS/2"].panose.bWeight == 3
144 | assert tt_post["OS/2"].panose.bProportion == 4
145 | assert tt_post["OS/2"].panose.bContrast == 5
146 | assert tt_post["OS/2"].panose.bStrokeVariation == 6
147 | assert tt_post["OS/2"].panose.bArmStyle == 7
148 | assert tt_post["OS/2"].panose.bLetterForm == 8
149 | assert tt_post["OS/2"].panose.bMidline == 9
150 | assert tt_post["OS/2"].panose.bXHeight == 10
151 |
152 |
153 | def test_run_invalid_font_filepath(capsys):
154 | test_path = os.path.join("tests", "testfiles", "fonts", "README.md")
155 | argv = ["--panose", "1,2,3,4,5,6,7,8,9,10", f"{test_path}"]
156 |
157 | with pytest.raises(SystemExit) as e:
158 | __main__.run(argv)
159 |
160 | captured = capsys.readouterr()
161 | assert e.type == SystemExit
162 | assert e.value.code == 1
163 | assert "[ERROR]" in captured.err
164 |
165 |
166 | def test_run_invalid_panose_definition(capsys):
167 | test_font_name = "NotoSans-Regular.subset.ttf"
168 | source_path = os.path.join("tests", "testfiles", "fonts", test_font_name)
169 | with tempfile.TemporaryDirectory() as tmpdirname:
170 | dest_path = os.path.join(tmpdirname, test_font_name)
171 | shutil.copyfile(source_path, dest_path)
172 |
173 | # test with too many panose values
174 | argv = ["--panose", "1,2,3,4,5,6,7,8,9,10,11", f"{dest_path}"]
175 |
176 | with pytest.raises(SystemExit) as e:
177 | __main__.run(argv)
178 |
179 | captured = capsys.readouterr()
180 | assert e.type == SystemExit
181 | assert e.value.code == 1
182 | assert "[ERROR]" in captured.err
183 |
184 |
185 | def test_run_invalid_option_definition(capsys):
186 | test_font_name = "NotoSans-Regular.subset.ttf"
187 | source_path = os.path.join("tests", "testfiles", "fonts", test_font_name)
188 | with tempfile.TemporaryDirectory() as tmpdirname:
189 | dest_path = os.path.join(tmpdirname, test_font_name)
190 | shutil.copyfile(source_path, dest_path)
191 |
192 | # test with non-integer definition
193 | argv = ["--proportion", "bogus", f"{dest_path}"]
194 |
195 | with pytest.raises(SystemExit) as e:
196 | __main__.run(argv)
197 |
198 | captured = capsys.readouterr()
199 | assert e.type == SystemExit
200 | assert e.value.code == 2
201 | assert "invalid int value" in captured.err
202 |
--------------------------------------------------------------------------------
/tests/testfiles/fonts/LICENSE_OF-NotoL.txt:
--------------------------------------------------------------------------------
1 | This Font Software is licensed under the SIL Open Font License,
2 | Version 1.1.
3 |
4 | This license is copied below, and is also available with a FAQ at:
5 | http://scripts.sil.org/OFL
6 |
7 | -----------------------------------------------------------
8 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
9 | -----------------------------------------------------------
10 |
11 | PREAMBLE
12 | The goals of the Open Font License (OFL) are to stimulate worldwide
13 | development of collaborative font projects, to support the font
14 | creation efforts of academic and linguistic communities, and to
15 | provide a free and open framework in which fonts may be shared and
16 | improved in partnership with others.
17 |
18 | The OFL allows the licensed fonts to be used, studied, modified and
19 | redistributed freely as long as they are not sold by themselves. The
20 | fonts, including any derivative works, can be bundled, embedded,
21 | redistributed and/or sold with any software provided that any reserved
22 | names are not used by derivative works. The fonts and derivatives,
23 | however, cannot be released under any other type of license. The
24 | requirement for fonts to remain under this license does not apply to
25 | any document created using the fonts or their derivatives.
26 |
27 | DEFINITIONS
28 | "Font Software" refers to the set of files released by the Copyright
29 | Holder(s) under this license and clearly marked as such. This may
30 | include source files, build scripts and documentation.
31 |
32 | "Reserved Font Name" refers to any names specified as such after the
33 | copyright statement(s).
34 |
35 | "Original Version" refers to the collection of Font Software
36 | components as distributed by the Copyright Holder(s).
37 |
38 | "Modified Version" refers to any derivative made by adding to,
39 | deleting, or substituting -- in part or in whole -- any of the
40 | components of the Original Version, by changing formats or by porting
41 | the Font Software to a new environment.
42 |
43 | "Author" refers to any designer, engineer, programmer, technical
44 | writer or other person who contributed to the Font Software.
45 |
46 | PERMISSION & CONDITIONS
47 | Permission is hereby granted, free of charge, to any person obtaining
48 | a copy of the Font Software, to use, study, copy, merge, embed,
49 | modify, redistribute, and sell modified and unmodified copies of the
50 | Font Software, subject to the following conditions:
51 |
52 | 1) Neither the Font Software nor any of its individual components, in
53 | Original or Modified Versions, may be sold by itself.
54 |
55 | 2) Original or Modified Versions of the Font Software may be bundled,
56 | redistributed and/or sold with any software, provided that each copy
57 | contains the above copyright notice and this license. These can be
58 | included either as stand-alone text files, human-readable headers or
59 | in the appropriate machine-readable metadata fields within text or
60 | binary files as long as those fields can be easily viewed by the user.
61 |
62 | 3) No Modified Version of the Font Software may use the Reserved Font
63 | Name(s) unless explicit written permission is granted by the
64 | corresponding Copyright Holder. This restriction only applies to the
65 | primary font name as presented to the users.
66 |
67 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
68 | Software shall not be used to promote, endorse or advertise any
69 | Modified Version, except to acknowledge the contribution(s) of the
70 | Copyright Holder(s) and the Author(s) or with their explicit written
71 | permission.
72 |
73 | 5) The Font Software, modified or unmodified, in part or in whole,
74 | must be distributed entirely under this license, and must not be
75 | distributed under any other license. The requirement for fonts to
76 | remain under this license does not apply to any document created using
77 | the Font Software.
78 |
79 | TERMINATION
80 | This license becomes null and void if any of the above conditions are
81 | not met.
82 |
83 | DISCLAIMER
84 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
86 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
87 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
88 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
89 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
90 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
91 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
92 | OTHER DEALINGS IN THE FONT SOFTWARE.
93 |
--------------------------------------------------------------------------------
/tests/testfiles/fonts/NotoSans-Regular.subset.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/source-foundry/panosifier/9f61da80d1d85505d2e496c9bfdbae1c6927c730/tests/testfiles/fonts/NotoSans-Regular.subset.ttf
--------------------------------------------------------------------------------
/tests/testfiles/fonts/README.md:
--------------------------------------------------------------------------------
1 | ## Test files
2 |
3 | This directory contains font files that are used for testing of this project and are re-distributed under the following licenses:
4 |
5 | - NotoSans-Regular.subset.ttf - modified subset derivative for testing purposes [LICENSE](LICENSE_OF-Noto.txt)
--------------------------------------------------------------------------------
/tox.ini:
--------------------------------------------------------------------------------
1 | [tox]
2 | envlist = py39
3 |
4 | [testenv]
5 | commands =
6 | py.test
7 | deps =
8 | pytest
--------------------------------------------------------------------------------