Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise annotations.py with new generic container types. #755

Merged
merged 64 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
6c8349c
Update normalizers.rst
knutnergaard Jul 22, 2024
8f6a334
Update normalizers.rst
knutnergaard Jul 22, 2024
fc996a6
Merge branch 'robotools:master' into master
knutnergaard Jul 29, 2024
ea2e5e4
Update point.rst
knutnergaard Jul 29, 2024
720c76b
Update point.rst
knutnergaard Jul 29, 2024
ce6c6ee
Merge branch 'robotools:master' into master
knutnergaard Aug 9, 2024
e144b38
Update conf.py
knutnergaard Aug 9, 2024
7a409a5
Add new module for type annotation definitions.
knutnergaard Aug 9, 2024
f34200e
Add type annotations and edit/add documentation.
knutnergaard Aug 9, 2024
8be7901
Update font.py
knutnergaard Aug 9, 2024
bb3c891
fixed name discrepancy in defaultLayer properties.
knutnergaard Aug 9, 2024
dc8f3b6
Merge branch 'master' of https://github.com/knutnergaard/fontParts
knutnergaard Aug 9, 2024
6437d4a
Fix name discrepancy in defaultLayer properties.
knutnergaard Aug 9, 2024
09ec22d
Add overview and reference items.
knutnergaard Aug 10, 2024
39bd22b
Edit minor details.
knutnergaard Aug 10, 2024
e7152b0
Change to .
knutnergaard Aug 12, 2024
6704728
Revert "Change to ."
knutnergaard Aug 12, 2024
f2fd3ad
Changed type.py to types.py and updtated font.py accordingly.
knutnergaard Aug 12, 2024
4e2e5cb
Recommitting due to error.
knutnergaard Aug 12, 2024
ca4b8b7
- Update _getReverseComponentMapping and _getReverseComponentMapping …
knutnergaard Aug 13, 2024
28a7464
Revise documentation.
knutnergaard Sep 2, 2024
9959124
Add annotations.py.
knutnergaard Sep 2, 2024
d2366f2
Remove types.py.
knutnergaard Sep 2, 2024
2c98baa
Revise documentation.
knutnergaard Sep 2, 2024
ac54672
Fixed type annotation.
knutnergaard Sep 2, 2024
fa52b70
Add documentation tools folder and module for docstring generation.
knutnergaard Sep 9, 2024
0d97f96
vert "Add documentation tools folder and module for docstring generat…
knutnergaard Sep 9, 2024
6253854
Merge branch 'robotools:master' into master
knutnergaard Sep 10, 2024
1f108f7
Add docstring generation module.
knutnergaard Sep 14, 2024
52f0e5a
Merge branch 'master' of https://github.com/knutnergaard/fontParts
knutnergaard Sep 14, 2024
a8ec91e
Refacor extraction of exceptions and normalizers with new CodeAnalyze…
knutnergaard Sep 15, 2024
fc4b321
Add type annotation.
knutnergaard Sep 18, 2024
f72b3c1
Update fonttools from 4.53.1 to 4.54.1 (#746)
pyup-bot Sep 24, 2024
b55089f
Revise and add annotation and documentation.
knutnergaard Oct 2, 2024
45c5b46
correct naming error.
knutnergaard Oct 3, 2024
42c7a9d
Add/improve documentation.
knutnergaard Oct 3, 2024
1dca76c
Add documentation regarding review to `rererence` function.
knutnergaard Oct 3, 2024
d39beb7
Add/improve documentation.
knutnergaard Oct 3, 2024
2bfa558
Update base.py (#750)
benkiel Oct 3, 2024
eb4bd2f
Edit `base.py`
knutnergaard Oct 9, 2024
c848b8a
update docstrings of `base.reference` and `BaseBPoint.type`.
knutnergaard Oct 9, 2024
e7a2abe
Revise `annotations.py` with new generic container types.
knutnergaard Oct 27, 2024
22b8048
Fix conflicts with `v1` branch.
knutnergaard Oct 29, 2024
b14f5c7
Revert "Update documentation (#739)"
knutnergaard Oct 29, 2024
b92b7a0
Resolve merge conflicts.
knutnergaard Oct 30, 2024
c4b1605
Resolve merge conflicts.
knutnergaard Oct 30, 2024
178d615
Add Sublime Text project folders.
knutnergaard Oct 30, 2024
d306ddd
Add Sublime Text project folders.
knutnergaard Oct 30, 2024
cb617ff
Remove unnecessary list comprehensions.
knutnergaard Oct 30, 2024
1ddc0a9
Remove Sublime Text project files.
knutnergaard Oct 30, 2024
1deb5e7
Solve merge conflict.
knutnergaard Oct 30, 2024
0682586
Resolve merge conflicts.
knutnergaard Oct 30, 2024
99de7a4
Resolve merge conflicts.
knutnergaard Oct 30, 2024
2e7530f
Add Sublime Text project folders.
knutnergaard Oct 30, 2024
3b39261
Merge branch 'v1' into annotations
knutnergaard Oct 30, 2024
9df12da
Resolve merge conflicts.
knutnergaard Oct 30, 2024
5d14729
Resolve merge conflicts.
knutnergaard Oct 30, 2024
6ad440e
Resolve merge conflicts.
knutnergaard Oct 30, 2024
afea374
Add type aliases and improve names.
knutnergaard Oct 31, 2024
8e94b7f
Revise type annotation in accordance with changes in `annotations.py`
knutnergaard Oct 31, 2024
5f8e241
Correct naming errors.
knutnergaard Oct 31, 2024
1b7ab1f
Tweak error message language
benkiel Nov 2, 2024
a65431c
Fix type
benkiel Nov 2, 2024
023fdc2
Remove list comprehensions
benkiel Nov 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions Lib/fontParts/base/annotations.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
# pylint: disable=C0103, C0114

from __future__ import annotations
from typing import Dict, List, Protocol, Tuple, TypeVar, Union

from fontTools.pens.basePen import AbstractPen
from fontTools.pens.pointPen import AbstractPointPen

# ------------
# Type Aliases
# ------------

# Builtins

# Generic
T = TypeVar('T')

PairType = Tuple[T, T]
QuadrupleType = Tuple[T, T, T, T]
QuintupleType = Tuple[T, T, T, T, T]
SextupleType = Tuple[T, T, T, T, T, T]
CollectionType = Union[List[T], Tuple[T, ...]]
IntFloatType = Union[int, float]
PairCollectionType = Union[List[T], PairType[T]]
QuadrupleCollectionType = Union[List[T], QuadrupleType[T]]
SextupleCollectionType = Union[List[T], SextupleType[T]]

# FontTools
# Builtins
IntFloatType = Union[int, float]

# Pens
PenType = AbstractPen
PointPenType = AbstractPointPen

# FontParts

BoundsType = Tuple[IntFloatType, IntFloatType, IntFloatType, IntFloatType]
# Mapping
CharacterMappingType = Dict[int, Tuple[str, ...]]
ColorType = Tuple[IntFloatType, IntFloatType, IntFloatType, IntFloatType]
CoordinateType = Tuple[IntFloatType, IntFloatType]
FactorType = Union[IntFloatType, Tuple[IntFloatType, IntFloatType]]
InterpolatableType = TypeVar('InterpolatableType', bound='Interpolatable')
KerningKeyType = Tuple[str, str]
KerningDictType = Dict[KerningKeyType, IntFloatType]
ReverseComponentMappingType = Dict[str, Tuple[str, ...]]
ScaleType = Tuple[IntFloatType, IntFloatType]
TransformationMatrixType = Tuple[
IntFloatType, IntFloatType, IntFloatType,
IntFloatType, IntFloatType, IntFloatType
]

# Kerning
KerningDictType = Dict[PairType[str], PairType[str]]

# Transformation
TransformationType = Union[IntFloatType, List[IntFloatType], PairType[IntFloatType]]

# Interpolation
InterpolatableType = TypeVar('InterpolatableType', bound='Interpolatable')


class Interpolatable(Protocol):
"""Represent a protocol for interpolatable types."""

def __add__(self, other: InterpolatableType) -> InterpolatableType: ...
def __sub__(self, other: InterpolatableType) -> InterpolatableType: ...
def __mul__(self, other: FactorType) -> InterpolatableType: ...
def __add__(self, other: InterpolatableType) -> InterpolatableType:
...

def __sub__(self, other: InterpolatableType) -> InterpolatableType:
...

def __mul__(self, other: TransformationType) -> InterpolatableType:
...
45 changes: 26 additions & 19 deletions Lib/fontParts/base/bPoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
from fontParts.base import normalizers
from fontParts.base.deprecated import DeprecatedBPoint, RemovedBPoint
from fontParts.base.annotations import (
CoordinateType,
TransformationMatrixType
PairType,
PairCollectionType,
SextupleCollectionType
)
if TYPE_CHECKING:
from fontParts.base.contour import BaseContour
Expand Down Expand Up @@ -241,16 +242,16 @@ def _get_font(self) -> Optional[BaseFont]:
"""
)

def _get_base_anchor(self) -> CoordinateType:
def _get_base_anchor(self) -> PairType[IntFloatType]:
value = self._get_anchor()
value = normalizers.normalizeCoordinateTuple(value)
return value

def _set_base_anchor(self, value: CoordinateType) -> None:
def _set_base_anchor(self, value: PairCollectionType[IntFloatType]) -> None:
value = normalizers.normalizeCoordinateTuple(value)
self._set_anchor(value)

def _get_anchor(self) -> CoordinateType:
def _get_anchor(self) -> PairType[IntFloatType]:
"""Get the the bPoint's anchor point.

This is the environment implementation of the :attr:`BaseBPoint.anchor`
Expand All @@ -268,7 +269,7 @@ def _get_anchor(self) -> CoordinateType:
point = self._point
return (point.x, point.y)

def _set_anchor(self, value: CoordinateType) -> None:
def _set_anchor(self, value: PairCollectionType[IntFloatType]) -> None:
"""Set the the bPoint's anchor point.

This is the environment implementation of the :attr:`BaseBPoint.anchor`
Expand Down Expand Up @@ -303,16 +304,16 @@ def _set_anchor(self, value: CoordinateType) -> None:
"""
)

def _get_base_bcpIn(self) -> CoordinateType:
def _get_base_bcpIn(self) -> PairType[IntFloatType]:
value = self._get_bcpIn()
value = normalizers.normalizeCoordinateTuple(value)
return value

def _set_base_bcpIn(self, value: CoordinateType) -> None:
def _set_base_bcpIn(self, value: PairCollectionType[IntFloatType]) -> None:
value = normalizers.normalizeCoordinateTuple(value)
self._set_bcpIn(value)

def _get_bcpIn(self) -> CoordinateType:
def _get_bcpIn(self) -> PairType[IntFloatType]:
"""Get the bPoint's incoming off-curve.

This is the environment implementation of the :attr:`BaseBPoint.bcpIn`
Expand All @@ -336,7 +337,7 @@ def _get_bcpIn(self) -> CoordinateType:
x = y = 0
return (x, y)

def _set_bcpIn(self, value: CoordinateType) -> None:
def _set_bcpIn(self, value: PairCollectionType[IntFloatType]) -> None:
"""Set the bPoint's incoming off-curve.

This is the environment implementation of the :attr:`BaseBPoint.bcpIn`
Expand Down Expand Up @@ -390,16 +391,16 @@ def _set_bcpIn(self, value: CoordinateType) -> None:
"""
)

def _get_base_bcpOut(self) -> CoordinateType:
def _get_base_bcpOut(self) -> PairType[IntFloatType]:
value = self._get_bcpOut()
value = normalizers.normalizeCoordinateTuple(value)
return value

def _set_base_bcpOut(self, value: CoordinateType) -> None:
def _set_base_bcpOut(self, value: PairCollectionType[IntFloatType]) -> None:
value = normalizers.normalizeCoordinateTuple(value)
self._set_bcpOut(value)

def _get_bcpOut(self) -> CoordinateType:
def _get_bcpOut(self) -> PairType[IntFloatType]:
"""Get the bPoint's outgoing off-curve.

This is the environment implementation of the :attr:`BaseBPoint.bcpOut`
Expand All @@ -423,7 +424,7 @@ def _get_bcpOut(self) -> CoordinateType:
x = y = 0
return (x, y)

def _set_bcpOut(self, value: CoordinateType) -> None:
def _set_bcpOut(self, value: PairCollectionType[IntFloatType]) -> None:
"""Set the bPoint's outgoing off-curve.

This is the environment implementation of the :attr:`BaseBPoint.bcpOut`
Expand Down Expand Up @@ -612,7 +613,9 @@ def _get_index(self) -> Optional[int]:
# Transformation
# --------------

def _transformBy(self, matrix: TransformationMatrixType, **kwargs: Any) -> None:
def _transformBy(self,
matrix: SextupleCollectionType[IntFloatType],
**kwargs: Any) -> None:
r"""Transform the native bPoint.

This is the environment implementation of :meth:`BaseBPoint.transformBy`.
Expand Down Expand Up @@ -666,7 +669,8 @@ def round(self) -> None:
normalizers.normalizeVisualRounding(y))


def relativeBCPIn(anchor: CoordinateType, BCPIn: CoordinateType) -> CoordinateType:
def relativeBCPIn(anchor: PairCollectionType[IntFloatType],
BCPIn: PairCollectionType[IntFloatType]) -> PairType[IntFloatType]:
"""convert absolute incoming bcp value to a relative value.

:param anchor: The anchor reference point from which to measure the relative
Expand All @@ -679,7 +683,8 @@ def relativeBCPIn(anchor: CoordinateType, BCPIn: CoordinateType) -> CoordinateTy
return (BCPIn[0] - anchor[0], BCPIn[1] - anchor[1])


def absoluteBCPIn(anchor: CoordinateType, BCPIn: CoordinateType) -> CoordinateType:
def absoluteBCPIn(anchor: PairCollectionType[IntFloatType],
BCPIn: PairCollectionType[IntFloatType]) -> PairType[IntFloatType]:
"""convert relative incoming bcp value to an absolute value.

:param anchor: The anchor reference point from which the relative BCP value
Expand All @@ -692,7 +697,8 @@ def absoluteBCPIn(anchor: CoordinateType, BCPIn: CoordinateType) -> CoordinateTy
return (BCPIn[0] + anchor[0], BCPIn[1] + anchor[1])


def relativeBCPOut(anchor: CoordinateType, BCPOut: CoordinateType) -> CoordinateType:
def relativeBCPOut(anchor: PairCollectionType[IntFloatType],
BCPOut: PairCollectionType[IntFloatType]) -> PairType[IntFloatType]:
"""convert absolute outgoing bcp value to a relative value.

:param anchor: The anchor reference point from which to measure the relative
Expand All @@ -705,7 +711,8 @@ def relativeBCPOut(anchor: CoordinateType, BCPOut: CoordinateType) -> Coordinate
return (BCPOut[0] - anchor[0], BCPOut[1] - anchor[1])


def absoluteBCPOut(anchor: CoordinateType, BCPOut: CoordinateType) -> CoordinateType:
def absoluteBCPOut(anchor: PairCollectionType[IntFloatType],
BCPOut: PairCollectionType[IntFloatType]) -> PairType[IntFloatType]:
"""convert relative outgoing bcp value to an absolute value.

:param anchor: The anchor reference point from which the relative BCP value
Expand Down
Loading