|
| 1 | +|Build Status| |PyPI| |Python Versions| |
| 2 | + |
| 3 | +BooleanOperations |
| 4 | +================= |
| 5 | + |
| 6 | +Boolean operations on paths based on a super fast `polygon clipper |
| 7 | +library by Angus Johnson <http://www.angusj.com/delphi/clipper.php>`__. |
| 8 | + |
| 9 | +You can download the latest version from PyPI: |
| 10 | + |
| 11 | +https://pypi.org/project/booleanOperations. |
| 12 | + |
| 13 | +Install |
| 14 | +------- |
| 15 | + |
| 16 | +`Pip <https://pip.pypa.io/en/stable/>`__ is the recommended tool to |
| 17 | +install booleanOperations. |
| 18 | + |
| 19 | +To install the latest version: |
| 20 | + |
| 21 | +.. code:: sh |
| 22 | +
|
| 23 | + pip install booleanOperations |
| 24 | +
|
| 25 | +BooleanOperations depends on the following packages: |
| 26 | + |
| 27 | +- `pyclipper <https://pypi.org/project/pyclipper/>`__: Cython wrapper for |
| 28 | + the C++ Clipper library |
| 29 | +- `fonttools <github.com/behdad/fonttools>`__ |
| 30 | +- `ufoLib <https://github.com/unified-font-object/ufoLib>`__ |
| 31 | + |
| 32 | +All dependencies are available on PyPI, so they will be resolved |
| 33 | +automatically upon installing booleanOperations. |
| 34 | + |
| 35 | +BooleanOperationManager |
| 36 | +----------------------- |
| 37 | + |
| 38 | +Containing a ``BooleanOperationManager`` handling all boolean operations |
| 39 | +on paths. Paths must be similar to ``defcon``, ``robofab`` contours. A |
| 40 | +manager draws the result in a ``pointPen``. |
| 41 | + |
| 42 | +.. code:: py |
| 43 | +
|
| 44 | + from booleanOperations import BooleanOperationManager |
| 45 | +
|
| 46 | + manager = BooleanOperationManager() |
| 47 | +
|
| 48 | +BooleanOperationManager() |
| 49 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 50 | + |
| 51 | +Create a ``BooleanOperationManager``. |
| 52 | + |
| 53 | +manager.union(contours, pointPen) |
| 54 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 55 | + |
| 56 | +Performs a union on all ``contours`` and draw it in the ``pointPen``. |
| 57 | +(this is a what a remove overlaps does) |
| 58 | + |
| 59 | +manager.difference(contours, clipContours, pointPen) |
| 60 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 61 | + |
| 62 | +Knock out the ``clipContours`` from the ``contours`` and draw it in the |
| 63 | +``pointPen``. |
| 64 | + |
| 65 | +manager.intersection(contours, clipContours, pointPen) |
| 66 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 67 | + |
| 68 | +Draw only the overlaps from the ``contours`` with the |
| 69 | +``clipContours``\ and draw it in the ``pointPen``. |
| 70 | + |
| 71 | +manager.xor(contours, clipContours, pointPen) |
| 72 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 73 | + |
| 74 | +Draw only the parts that not overlaps from the ``contours`` with the |
| 75 | +``clipContours``\ and draw it in the ``pointPen``. |
| 76 | + |
| 77 | +manager.getIntersections(contours) |
| 78 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 79 | + |
| 80 | +Returning all intersection for the given contours |
| 81 | + |
| 82 | +BooleanGlyph |
| 83 | +------------ |
| 84 | + |
| 85 | +A glyph like object with boolean powers. |
| 86 | + |
| 87 | +.. code:: py |
| 88 | +
|
| 89 | + from booleanOperations.booleanGlyph import BooleanGlyph |
| 90 | +
|
| 91 | + booleanGlyph = BooleanGlyph(sourceGlyph) |
| 92 | +
|
| 93 | +BooleanGlyph(sourceGlyph) |
| 94 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 95 | + |
| 96 | +Create a ``BooleanGlyph`` object from ``sourceGlyph``. This is a very |
| 97 | +shallow glyph object with basic support. |
| 98 | + |
| 99 | +booleanGlyph.union(other) |
| 100 | +^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 101 | + |
| 102 | +Perform a **union** with the ``other``. Other must be a glyph or |
| 103 | +``BooleanGlyph`` object. |
| 104 | + |
| 105 | +.. code:: py |
| 106 | +
|
| 107 | + result = BooleanGlyph(glyph).union(BooleanGlyph(glyph2)) |
| 108 | + result = BooleanGlyph(glyph) | BooleanGlyph(glyph2) |
| 109 | +
|
| 110 | +booleanGlyph.difference(other) |
| 111 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 112 | + |
| 113 | +Perform a **difference** with the ``other``. Other must be a glyph or |
| 114 | +``BooleanGlyph`` object. |
| 115 | + |
| 116 | +.. code:: py |
| 117 | +
|
| 118 | + result = BooleanGlyph(glyph).difference(BooleanGlyph(glyph2)) |
| 119 | + result = BooleanGlyph(glyph) % BooleanGlyph(glyph2) |
| 120 | +
|
| 121 | +booleanGlyph.intersection(other) |
| 122 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 123 | + |
| 124 | +Perform a **intersection** with the ``other``. Other must be a glyph or |
| 125 | +``BooleanGlyph`` object. |
| 126 | + |
| 127 | +.. code:: py |
| 128 | +
|
| 129 | + result = BooleanGlyph(glyph).intersection(BooleanGlyph(glyph2)) |
| 130 | + result = BooleanGlyph(glyph) & BooleanGlyph(glyph2) |
| 131 | +
|
| 132 | +booleanGlyph.xor(other) |
| 133 | +^^^^^^^^^^^^^^^^^^^^^^^ |
| 134 | + |
| 135 | +Perform a **xor** with the ``other``. Other must be a glyph or |
| 136 | +``BooleanGlyph`` object. |
| 137 | + |
| 138 | +.. code:: py |
| 139 | +
|
| 140 | + result = BooleanGlyph(glyph).xor(BooleanGlyph(glyph2)) |
| 141 | + result = BooleanGlyph(glyph) ^ BooleanGlyph(glyph2) |
| 142 | +
|
| 143 | +booleanGlyph.removeOverlap() |
| 144 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 145 | + |
| 146 | +Perform a **union** on it self. This will remove all overlapping |
| 147 | +contours and self intersecting contours. |
| 148 | + |
| 149 | +.. code:: py |
| 150 | +
|
| 151 | + result = BooleanGlyph(glyph).removeOverlap() |
| 152 | +
|
| 153 | +-------------- |
| 154 | + |
| 155 | +booleanGlyph.name |
| 156 | +^^^^^^^^^^^^^^^^^ |
| 157 | + |
| 158 | +The **name** of the ``sourceGlyph``. |
| 159 | + |
| 160 | +booleanGlyph.unicodes |
| 161 | +^^^^^^^^^^^^^^^^^^^^^ |
| 162 | + |
| 163 | +The **unicodes** of the ``sourceGlyph``. |
| 164 | + |
| 165 | +booleanGlyph.width |
| 166 | +^^^^^^^^^^^^^^^^^^ |
| 167 | + |
| 168 | +The **width** of the ``sourceGlyph``. |
| 169 | + |
| 170 | +booleanGlyph.lib |
| 171 | +^^^^^^^^^^^^^^^^ |
| 172 | + |
| 173 | +The **lib** of the ``sourceGlyph``. |
| 174 | + |
| 175 | +booleanGlyph.note |
| 176 | +^^^^^^^^^^^^^^^^^ |
| 177 | + |
| 178 | +The **note** of the ``sourceGlyph``. |
| 179 | + |
| 180 | +booleanGlyph.contours |
| 181 | +^^^^^^^^^^^^^^^^^^^^^ |
| 182 | + |
| 183 | +List the **contours** of the glyph. |
| 184 | + |
| 185 | +booleanGlyph.components |
| 186 | +^^^^^^^^^^^^^^^^^^^^^^^ |
| 187 | + |
| 188 | +List the **components** of the glyph. |
| 189 | + |
| 190 | +booleanGlyph.anchors |
| 191 | +^^^^^^^^^^^^^^^^^^^^ |
| 192 | + |
| 193 | +List the **anchors** of the glyph. |
| 194 | + |
| 195 | +.. |Build Status| image:: https://api.travis-ci.org/typemytype/booleanOperations.svg |
| 196 | + :target: https://travis-ci.org/typemytype/booleanOperations |
| 197 | +.. |PyPI| image:: https://img.shields.io/pypi/v/booleanOperations.svg |
| 198 | + :target: https://pypi.org/project/booleanOperations/ |
| 199 | +.. |Python Versions| image:: https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5%2C%203.6-blue.svg |
0 commit comments