Skip to content

Commit

Permalink
- Update _getReverseComponentMapping and _getReverseComponentMapping …
Browse files Browse the repository at this point in the history
…methods in base/layer.py and fontshell/layer.py to return mappings to tuple.

- Update base/layer.py with doc revisions and type annotations.
- Update layer.rst accordingly.
- Fix link to fontParts.world in various .rst files.
  • Loading branch information
knutnergaard committed Aug 13, 2024
1 parent 4e2e5cb commit ca4b8b7
Show file tree
Hide file tree
Showing 8 changed files with 755 additions and 358 deletions.
1,024 changes: 684 additions & 340 deletions Lib/fontParts/base/layer.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Lib/fontParts/base/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Generic, Iterator, List, Set, Tuple, TypeVar, Union
from typing import Dict, Generic, Iterator, List, Tuple, TypeVar, Union

try:
from fontParts.base.info import BaseInfo
Expand Down Expand Up @@ -28,5 +28,5 @@
GuidelineType = TypeVar('GuidelineType', bound='BaseGuideline')
KerningKey = Tuple[str, str]
KerningDict = Dict[KerningKey, IntFloat]
ReverseComponentMapping = Dict[str, Set[str]]
CharacterMapping = Dict[int, List[str]]
ReverseComponentMapping = Dict[str, Tuple[str]]
CharacterMapping = Dict[int, Tuple[str]]
6 changes: 4 additions & 2 deletions Lib/fontParts/fontshell/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def _removeGlyph(self, name, **kwargs):
# -------

def _getReverseComponentMapping(self):
return self.naked().componentReferences
mapping = self.naked().componentReferences
return {k: tuple(v) for k, v in mapping.items()}

def _getCharacterMapping(self):
return self.naked().unicodeData
mapping = self.naked().unicodeData
return {k: tuple(v) for k, v in mapping.items()}
3 changes: 2 additions & 1 deletion documentation/source/objectref/fontpartsworld/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.. highlight:: python
.. _fontParts.world:

################
fontParts.world
Expand All @@ -23,4 +24,4 @@ fontParts.world
.. autofunction:: CurrentAnchors
.. autofunction:: CurrentGuidelines
.. autofunction:: FontList
.. autoclass:: BaseFontList
.. autoclass:: BaseFontList
3 changes: 1 addition & 2 deletions documentation/source/objectref/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Object Reference
################

FontParts scripts are built on with objects that represent fonts, glyphs, contours and so on. The objects are obtained through :ref:`fontparts-world`.
FontParts scripts are built on with objects that represent fonts, glyphs, contours and so on. The objects are obtained through :ref:`fontParts.world`.


.. toctree::
Expand All @@ -14,4 +14,3 @@ FontParts scripts are built on with objects that represent fonts, glyphs, contou
objects/index
valuetypes/index
fontpartsworld/index

3 changes: 1 addition & 2 deletions documentation/source/objectref/objects/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Objects
################

FontParts scripts are built on with objects that represent fonts, glyphs, contours and so on. The objects are obtained through :ref:`fontparts-world`.
FontParts scripts are built on with objects that represent fonts, glyphs, contours and so on. The objects are obtained through :ref:`fontParts.world`.

.. toctree::
:maxdepth: 1
Expand Down Expand Up @@ -180,4 +180,3 @@ FontParts scripts are built on with objects that represent fonts, glyphs, contou
</g>
</svg>


58 changes: 54 additions & 4 deletions documentation/source/objectref/objects/layer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Layer

.. note::

This section needs to contain the following:
This section needs to contain the following:

* description of what this is
* sub-object with basic usage
* glyph interaction with basic usage
* description of what this is
* sub-object with basic usage
* glyph interaction with basic usage

********
Overview
Expand All @@ -24,6 +24,7 @@ Copy
:nosignatures:

BaseLayer.copy
BaseLayer.copyData

Parents
=======
Expand Down Expand Up @@ -75,6 +76,24 @@ Interpolation
BaseLayer.isCompatible
BaseLayer.interpolate

Mapping
=======

.. autosummary::
:nosignatures:

BaseLayer.getCharacterMapping
BaseLayer.getReverseComponentMapping

Selection
=========

.. autosummary::
:nosignatures:

BaseLayer.selectedGlyphs
BaseLayer.selectedGlyphNames

Normalization
=============

Expand Down Expand Up @@ -104,6 +123,7 @@ Copy
====

.. automethod:: BaseLayer.copy
.. automethod:: BaseLayer.copyData

Parents
=======
Expand All @@ -120,6 +140,7 @@ Sub-Objects
===========

.. autoattribute:: BaseLayer.lib
.. autoattribute:: BaseLayer.tempLib

Glyphs
======
Expand All @@ -139,6 +160,18 @@ Interpolation
.. automethod:: BaseLayer.isCompatible
.. automethod:: BaseLayer.interpolate

Mapping
=======

.. automethod:: BaseLayer.getCharacterMapping
.. automethod:: BaseLayer.getReverseComponentMapping

Selection
=========

.. automethod:: BaseLayer.selectedGlyphs
.. automethod:: BaseLayer.selectedGlyphNames

Normalization
=============

Expand All @@ -150,3 +183,20 @@ Environment

.. automethod:: BaseLayer.naked
.. automethod:: BaseLayer.changed

















10 changes: 6 additions & 4 deletions documentation/source/objectref/valuetypes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Common Value Types
##################

FontParts scripts are built on with objects that represent fonts, glyphs, contours and so on. The objects are obtained through :ref:`fontparts-world`.
FontParts scripts are built on with objects that represent fonts, glyphs, contours and so on. The objects are obtained through :ref:`fontParts.world`.


.. _fontparts-objects:
Expand All @@ -28,7 +28,8 @@ Unicode (unencoded) or string. Internally everything is a unicode string.
Integer/Float
-------------

Integers and floats are interchangeable in FontParts (unless the specification states that only one is allowed).
Integers and floats are interchangeable in FontParts (unless the specification
states that only one is allowed).


.. _type-coordinate:
Expand All @@ -47,7 +48,8 @@ An immutable iterable containing two :ref:`type-int-float` representing:
Angle
-----

XXX define the angle specifications here. Direction, degrees, etc. This will always be a float.
XXX define the angle specifications here. Direction, degrees, etc. This will
always be a float.


.. _type-identifier:
Expand Down Expand Up @@ -86,4 +88,4 @@ An immutable iterable defining a 2x2 transformation plus offset (aka Affine tran
Immutable List
--------------

This must be an immutable, ordered iterable like a ``tuple``.
This must be an immutable, ordered iterable like a ``tuple``.

0 comments on commit ca4b8b7

Please sign in to comment.