pixel-font-knife 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ name: Publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ environment:
11
+ name: pypi
12
+ url: https://pypi.org/project/pixel-font-knife/
13
+ permissions:
14
+ id-token: write
15
+ steps:
16
+ - name: Checkout
17
+ uses: actions/checkout@v4
18
+ - name: Setup Python
19
+ uses: actions/setup-python@v5
20
+ with:
21
+ python-version: "3.x"
22
+ - name: Install dependencies
23
+ run: |
24
+ python -m pip install pip --upgrade
25
+ python -m pip install build
26
+ - name: Build
27
+ run: python -m build
28
+ - name: Publish
29
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,24 @@
1
+ name: Test
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ python-version: ["3.10", "3.11", "3.12"]
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v4
15
+ - name: Setup Python
16
+ uses: actions/setup-python@v5
17
+ with:
18
+ python-version: ${{ matrix.python-version }}
19
+ - name: Install dependencies
20
+ run: |
21
+ python -m pip install pip --upgrade
22
+ python -m pip install -r requirements.txt
23
+ - name: Test
24
+ run: python -m pytest
@@ -0,0 +1,141 @@
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
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
98
+ __pypackages__/
99
+
100
+ # Celery stuff
101
+ celerybeat-schedule
102
+ celerybeat.pid
103
+
104
+ # SageMath parsed files
105
+ *.sage.py
106
+
107
+ # Environments
108
+ .env
109
+ .venv
110
+ env/
111
+ venv/
112
+ ENV/
113
+ env.bak/
114
+ venv.bak/
115
+
116
+ # Spyder project settings
117
+ .spyderproject
118
+ .spyproject
119
+
120
+ # Rope project settings
121
+ .ropeproject
122
+
123
+ # mkdocs documentation
124
+ /site
125
+
126
+ # mypy
127
+ .mypy_cache/
128
+ .dmypy.json
129
+ dmypy.json
130
+
131
+ # Pyre type checker
132
+ .pyre/
133
+
134
+ # pytype static type analyzer
135
+ .pytype/
136
+
137
+ # Cython debug symbols
138
+ cython_debug/
139
+
140
+ # PyCharm
141
+ .idea/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 TakWolf
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.3
2
+ Name: pixel-font-knife
3
+ Version: 0.0.1
4
+ Summary: A set of pixel font utilities.
5
+ Project-URL: homepage, https://github.com/TakWolf/pixel-font-knife
6
+ Project-URL: source, https://github.com/TakWolf/pixel-font-knife
7
+ Project-URL: issues, https://github.com/TakWolf/pixel-font-knife/issues
8
+ Author: TakWolf
9
+ Maintainer: TakWolf
10
+ License: MIT License
11
+ License-File: LICENSE
12
+ Keywords: font,pixel
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: pypng>=0.20220715.0
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Pixel Font Knife
21
+
22
+ [![Python](https://img.shields.io/badge/python-3.10-brightgreen)](https://www.python.org)
23
+ [![PyPI](https://img.shields.io/pypi/v/pixel-font-knife)](https://pypi.org/project/pixel-font-knife/)
24
+
25
+ 一组像素字体实用工具。
26
+
27
+ 该库被设计用于和 [Pixel Font Builder](https://github.com/TakWolf/pixel-font-builder) 配合使用,也包含一些符合 [Ark Pixel Font](https://github.com/TakWolf/ark-pixel-font) 构建约定的通用工具。
28
+
29
+ ## 安装
30
+
31
+ ```shell
32
+ pip install pixel-font-knife
33
+ ```
34
+
35
+ ## 程序依赖
36
+
37
+ - [PyPNG](https://gitlab.com/drj11/pypng)
38
+
39
+ ## 许可证
40
+
41
+ 基于 [MIT 许可证](LICENSE)。
@@ -0,0 +1,22 @@
1
+ # Pixel Font Knife
2
+
3
+ [![Python](https://img.shields.io/badge/python-3.10-brightgreen)](https://www.python.org)
4
+ [![PyPI](https://img.shields.io/pypi/v/pixel-font-knife)](https://pypi.org/project/pixel-font-knife/)
5
+
6
+ 一组像素字体实用工具。
7
+
8
+ 该库被设计用于和 [Pixel Font Builder](https://github.com/TakWolf/pixel-font-builder) 配合使用,也包含一些符合 [Ark Pixel Font](https://github.com/TakWolf/ark-pixel-font) 构建约定的通用工具。
9
+
10
+ ## 安装
11
+
12
+ ```shell
13
+ pip install pixel-font-knife
14
+ ```
15
+
16
+ ## 程序依赖
17
+
18
+ - [PyPNG](https://gitlab.com/drj11/pypng)
19
+
20
+ ## 许可证
21
+
22
+ 基于 [MIT 许可证](LICENSE)。
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pixel-font-knife"
7
+ version = "0.0.1"
8
+ description = "A set of pixel font utilities."
9
+ readme = "README.md"
10
+ license = { text = "MIT License" }
11
+ requires-python = ">=3.10"
12
+ authors = [
13
+ { name = "TakWolf" },
14
+ ]
15
+ maintainers = [
16
+ { name = "TakWolf" },
17
+ ]
18
+ keywords = ["font", "pixel"]
19
+ classifiers = [
20
+ "Programming Language :: Python :: 3",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Operating System :: OS Independent",
23
+ ]
24
+
25
+ dependencies = [
26
+ "pypng>=0.20220715.0",
27
+ ]
28
+
29
+ [project.urls]
30
+ homepage = "https://github.com/TakWolf/pixel-font-knife"
31
+ source = "https://github.com/TakWolf/pixel-font-knife"
32
+ issues = "https://github.com/TakWolf/pixel-font-knife/issues"
33
+
34
+ [tool.pytest.ini_options]
35
+ pythonpath = [
36
+ ".",
37
+ "src",
38
+ ]
39
+ addopts = [
40
+ "--import-mode=importlib",
41
+ ]
@@ -0,0 +1,3 @@
1
+ pypng==0.20220715.0
2
+
3
+ pytest==8.2.2
@@ -0,0 +1,35 @@
1
+ from os import PathLike
2
+
3
+ import png
4
+
5
+
6
+ def load_png(
7
+ file_path: str | bytes | PathLike[str] | PathLike[bytes],
8
+ ) -> tuple[list[list[int]], int, int]:
9
+ width, height, pixels, _ = png.Reader(filename=file_path).read()
10
+ bitmap = []
11
+ for pixels_row in pixels:
12
+ bitmap_row = []
13
+ for i in range(0, width * 4, 4):
14
+ alpha = pixels_row[i + 3]
15
+ bitmap_row.append(1 if alpha > 127 else 0)
16
+ bitmap.append(bitmap_row)
17
+ return bitmap, width, height
18
+
19
+
20
+ def save_png(
21
+ bitmap: list[list[int]],
22
+ file_path: str | bytes | PathLike[str] | PathLike[bytes],
23
+ color: tuple[int, int, int] = (0, 0, 0),
24
+ ):
25
+ red, green, blue = color
26
+ pixels = []
27
+ for bitmap_row in bitmap:
28
+ pixels_row = []
29
+ for alpha in bitmap_row:
30
+ pixels_row.append(red)
31
+ pixels_row.append(green)
32
+ pixels_row.append(blue)
33
+ pixels_row.append(255 if alpha != 0 else 0)
34
+ pixels.append(pixels_row)
35
+ png.from_array(pixels, 'RGBA').save(file_path)
@@ -0,0 +1,13 @@
1
+ from pathlib import Path
2
+
3
+ import pytest
4
+
5
+
6
+ @pytest.fixture(scope='session')
7
+ def project_root_dir() -> Path:
8
+ return Path(__file__).parent.joinpath('..').resolve()
9
+
10
+
11
+ @pytest.fixture(scope='session')
12
+ def assets_dir(project_root_dir: Path) -> Path:
13
+ return project_root_dir.joinpath('assets')
@@ -0,0 +1,39 @@
1
+ import hashlib
2
+ from pathlib import Path
3
+
4
+ from pixel_font_knife import mono_bitmap_util
5
+
6
+
7
+ def _file_sha256(file_path: Path) -> str:
8
+ return hashlib.sha256(file_path.read_bytes()).hexdigest()
9
+
10
+
11
+ def test_load_save(assets_dir: Path, tmp_path: Path):
12
+ black_load_path = assets_dir.joinpath('png', '4E2D-black.png')
13
+ black_save_path = tmp_path.joinpath('4E2D-black.png')
14
+ black_bitmap, black_width, black_height = mono_bitmap_util.load_png(black_load_path)
15
+ mono_bitmap_util.save_png(black_bitmap, black_save_path)
16
+
17
+ red_load_path = assets_dir.joinpath('png', '4E2D-red.png')
18
+ red_save_path = tmp_path.joinpath('4E2D-red.png')
19
+ red_bitmap, red_width, red_height = mono_bitmap_util.load_png(red_load_path)
20
+ mono_bitmap_util.save_png(red_bitmap, red_save_path, color=(255, 0, 0))
21
+
22
+ assert black_bitmap == red_bitmap == [
23
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
24
+ [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
25
+ [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
26
+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
27
+ [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0],
28
+ [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0],
29
+ [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0],
30
+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
31
+ [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
32
+ [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
33
+ [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
34
+ [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
35
+ ]
36
+ assert black_width == red_width == 12
37
+ assert black_height == red_height == 12
38
+ assert _file_sha256(black_load_path) == _file_sha256(black_save_path)
39
+ assert _file_sha256(red_load_path) == _file_sha256(red_save_path)