### Install Defcon with Multiple Extras (Python) Source: https://github.com/robotools/defcon/blob/master/README.rst Installs defcon with multiple optional extras, such as 'pens' and 'lxml', by separating them with a comma. This allows for a customized installation based on project needs. ```bash pip install --upgrade defcon[pens,lxml] ``` -------------------------------- ### Install Defcon (Python) Source: https://github.com/robotools/defcon/blob/master/README.rst Installs the latest stable release of defcon from the Python Package Index using pip. This is the standard installation method for the library. ```bash pip install --upgrade defcon ``` -------------------------------- ### Font Initialization and Usage Examples Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/font.md Demonstrates how to initialize a Font object, access glyphs, iterate through glyphs, get the glyph count, check for glyph existence, and remove glyphs. This showcases the dict-like behavior of the Font object. ```python from defcon import Font # Initialize a font object, optionally from a UFO path font = Font("path/to/your/font.ufo") # Access a glyph by its name glyph = font["aGlyphName"] # Iterate over all glyphs in the font for glyph in font: print(glyph.name) # Get the total number of glyphs glyphCount = len(font) print(f"Number of glyphs: {glyphCount}") # Check if a glyph exists in the font if "anotherGlyphName" in font: print("Glyph exists.") # Remove a glyph from the font if "glyphToDelete" in font: del font["glyphToDelete"] ``` -------------------------------- ### Install Defcon with lxml Support (Python) Source: https://github.com/robotools/defcon/blob/master/README.rst Installs defcon with optional support for lxml, a faster XML reader and writer library, which can improve performance for XML-based operations. ```bash pip install --upgrade defcon[lxml] ``` -------------------------------- ### Install Defcon with FontPens (Python) Source: https://github.com/robotools/defcon/blob/master/README.rst Installs defcon along with the fontPens package, which is required for specific functionalities like Glyph.correctDirection() and Contour.contourInside(). ```bash pip install --upgrade defcon[pens] ``` -------------------------------- ### Define a Custom Glyph Class in Python Source: https://github.com/robotools/defcon/blob/master/documentation/source/concepts/subclassing.md This snippet demonstrates how to create a custom glyph class by subclassing `defcon.Glyph`. It includes an example of adding a custom method to the glyph. No external dependencies are required beyond the `defcon` library. ```python from defcon import Glyph class MyCustomGlyph(Glyph): def myCustomMethod(self): # do something to the glyph data ``` -------------------------------- ### Get Glyph Guideline Class Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/glyph.md Retrieves the class used for creating and managing guidelines within the glyph. ```python guideline_class = glyph.guidelineClass ``` -------------------------------- ### get Method Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/lib.md Returns the value for a given key if the key exists in the dictionary, otherwise returns a specified default value. ```APIDOC ## GET /robotools/defcon/get ### Description Retrieves the value associated with a specific key. If the key is not found, a default value is returned. ### Method GET ### Endpoint /robotools/defcon/get ### Parameters #### Query Parameters - **key** (any) - Required - The key whose value is to be retrieved. - **default** (any) - Optional - The value to return if the key is not found. Defaults to None. ### Response #### Success Response (200) - **value** (any) - The value associated with the key, or the default value if the key is not found. #### Response Example ```json { "value": "retrieved_value_or_default" } ``` ``` -------------------------------- ### Accessing Lib Data (Python) Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/lib.md Demonstrates how to get and set arbitrary data within the Lib object, which behaves like a Python dictionary. Data is accessed using string keys, typically following a reverse domain naming convention. ```python data = lib["com.typesupply.someApplication.blah"] lib["com.typesupply.someApplication.blah"] = 123 ``` -------------------------------- ### Get Data for Serialization Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/component.md Retrieves data from an object in a format suitable for pickling. Accepts arbitrary keyword arguments. ```python def getDataForSerialization(**kwargs): """ Return a dict of data that can be pickled. """ pass ``` -------------------------------- ### get Method Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/groups.md Retrieves the value for a given key, returning a default if the key is not found. ```APIDOC ## get Method ### Description Return the value for key if key is in the dictionary, else default. ### Method GET ### Endpoint /robotools/defcon/get ### Parameters #### Query Parameters - **key** (any) - Required - The key whose value is to be retrieved. - **default** (any) - Optional - The value to return if the key is not found. Defaults to None. ### Response #### Success Response (200) - **value** (any) - The value associated with the key, or the default value if the key is not found. ### Response Example ```json { "value": "retrieved_value" } ``` ``` -------------------------------- ### Create a New Font From Scratch Source: https://context7.com/robotools/defcon/llms.txt Provides a complete example of creating a new defcon Font object and setting its basic information, including family name, style name, units per em, ascender, descender, cap height, and x-height. ```python from defcon import Font # Create new font font = Font() # Set font info font.info.familyName = "SimpleFont" font.info.styleName = "Regular" font.info.unitsPerEm = 1000 font.info.ascender = 800 font.info.descender = -200 font.info.capHeight = 700 font.info.xHeight = 500 ``` -------------------------------- ### Get Data for Serialization Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/anchor.md Returns a dictionary containing data suitable for pickling. Accepts arbitrary keyword arguments which may influence the data returned. ```python getDataForSerialization(**kwargs) ``` -------------------------------- ### get() Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/unicodedata.md Return the value for a key if it exists, otherwise return a default value. ```APIDOC ## get(key, default=None) ### Description Return the value for key if key is in the dictionary, else default. ### Method [Method not specified, likely GET] ### Endpoint [Endpoint not specified] ### Parameters #### Query Parameters * **key** (any) - Required - The key to look up. * **default** (any) - Optional - Defaults to None. The value to return if the key is not found. ### Request Example None ### Response #### Success Response (200) * **value** (any) - The value associated with the key, or the default value. #### Response Example None ``` -------------------------------- ### Dictionary-like Methods in Python Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/groups.md Provides standard dictionary operations including getting items, keys, and values. Methods like items(), keys(), and values() return views of the dictionary's contents. ```Python def items(): """→ a set-like object providing a view on D's items""" pass def keys(): """→ a set-like object providing a view on D's keys""" pass def values(): """→ a set-like object providing a view on D's values""" pass ``` -------------------------------- ### Get keys view from dictionary Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/kerning.md Returns a set-like object that provides a view of the dictionary's keys. ```Python def keys() -> set: """ → a set-like object providing a view on D's keys """ pass ``` -------------------------------- ### Create a new Font object using defcon Source: https://github.com/robotools/defcon/blob/master/documentation/source/index.md This snippet demonstrates the basic usage of the defcon library by creating a new Font object. It requires the defcon library to be installed. The output is a Font object ready for manipulation. ```python from defcon import Font font = Font() # now do some stuff! ``` -------------------------------- ### Get Glyph Guidelines Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/glyph.md Retrieves an ordered list of 'Guideline' objects associated with the glyph. Modifying this list can trigger 'Glyph.Changed' notifications and other related notifications. ```python guidelines = glyph.guidelines ``` -------------------------------- ### Get Glyph Data for Serialization Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/glyph.md Returns a dictionary containing the glyph's data, suitable for pickling or serialization. Accepts arbitrary keyword arguments. ```python serialization_data = glyph.getDataForSerialization(**kwargs) ``` -------------------------------- ### Load a Font with a Custom Glyph Class in Python Source: https://github.com/robotools/defcon/blob/master/documentation/source/concepts/subclassing.md This snippet shows how to instantiate a `defcon.Font` object using a custom glyph class. By passing the `glyphClass` argument, all subsequently loaded glyphs will be instances of the provided custom class. Requires the `defcon` library. ```python from defcon import Font font = Font(glyphClass=MyCustomGlyph) ``` -------------------------------- ### Retrieving Unicode Information for Glyphs (Python) Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/unicodedata.md Provides examples of methods for retrieving Unicode-related information for a given glyph name. These methods include getting the block, category, and script, with an option to use pseudo-Unicode values. ```python block = unicodeData.blockForGlyphName(glyphName, allowPseudoUnicode=True) category = unicodeData.categoryForGlyphName(glyphName, allowPseudoUnicode=True) script = unicodeData.scriptForGlyphName(glyphName, allowPseudoUnicode=True) ``` -------------------------------- ### Getting Contour Properties in Python Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/contour.md Provides examples for accessing key properties of a Contour object, including its `area`, `bounds`, and `clockwise` direction. The `bounds` property returns a tuple of (xMin, yMin, xMax, yMax), and modifying `clockwise` posts specific notifications. ```python area = contour.area bounds = contour.bounds is_clockwise = contour.clockwise ``` -------------------------------- ### Python: Managing Notifications in defcon.Groups Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/groups.md Illustrates how to control the notification system of the defcon.Groups object. It covers disabling and enabling notifications, either globally or for specific notification types. The provided examples also show the equivalent direct calls to the notification dispatcher. ```Python # Disable all notifications groups.disableNotifications() # Disable a specific notification groups.disableNotifications(notification="Groups.Changed") # Enable all notifications groups.enableNotifications() # Enable a specific notification groups.enableNotifications(notification="Groups.Changed") # Equivalent direct dispatcher calls: dispatcher = anObject.dispatcher dispatcher.disableNotifications( observable=anObject, notification=notification, observer=observer) dispatcher.enableNotifications( observable=anObject, notification=notification, observer=observer) ``` -------------------------------- ### Lib Object Methods Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/lib.md This section details the methods available for interacting with the Lib object, including observer management, undo/redo functionality, and data manipulation. ```APIDOC ## defcon.Lib Class ### Description This object contains arbitrary data and posts various notifications to alert observers of changes. ### Methods #### addObserver(observer, methodName, notification, identifier=None) * **Description:** Adds an observer to this object's notification dispatcher. * **Parameters:** * **observer** (object) - An object that can be referenced with weakref. * **methodName** (string) - The name of the method to call when a notification is posted. * **notification** (string) - The notification to observe. * **identifier** (string, optional) - An identifier for the observation. Recommended to use reverse domain naming convention. * **Returns:** None #### canRedo() * **Description:** Returns a boolean indicating whether the undo manager can perform a redo. * **Returns:** boolean #### canUndo() * **Description:** Returns a boolean indicating whether the undo manager can perform an undo. * **Returns:** boolean #### clear() → None. * **Description:** Removes all items from the Lib object. #### copy() → a shallow copy of D * **Description:** Returns a shallow copy of the Lib object. #### destroyAllRepresentations(notification=None) * **Description:** Destroys all representations associated with the Lib object. #### destroyRepresentation(name, **kwargs) * **Description:** Destroys the stored representation for a given name and optional keyword arguments. * **Parameters:** * **name** (string) - The name of the representation to destroy. * **kwargs** - Additional keyword arguments to match when destroying the representation. #### disableNotifications(notification=None, observer=None) * **Description:** Disables notifications for this object until resumed. Can disable all notifications or specific ones. * **Parameters:** * **notification** (string, optional) - The specific notification to disable. If not provided, all notifications are disabled. * **observer** (object, optional) - The observer to disable notifications for. #### enableNotifications(notification=None, observer=None) * **Description:** Enables notifications for this object. Can enable all notifications or specific ones. * **Parameters:** * **notification** (string, optional) - The specific notification to enable. If not provided, all notifications are enabled. * **observer** (object, optional) - The observer to enable notifications for. ### Properties #### dispatcher * **Description:** The `NotificationCenter` assigned to the parent of this object. * **Type:** `defcon.tools.notifications.NotificationCenter` #### dirty * **Description:** The dirty state of the object. True if the object has been changed, False otherwise. Setting this to True posts the base changed notification. The object automatically maintains this attribute. * **Type:** boolean ``` -------------------------------- ### keys Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/lib.md Returns a set-like view object that provides a view on the dictionary's keys. ```APIDOC ## GET /robotools/defcon/keys ### Description Provides a dynamic view of the dictionary's keys, allowing iteration over keys. ### Method GET ### Endpoint /robotools/defcon/keys ### Response #### Success Response (200) - **keys_view** (set-like object) - A view object containing the dictionary's keys. #### Response Example ```json { "keys_view": ["key1", "key2", "key3"] } ``` ``` -------------------------------- ### Python: Registering Representation Factories with Custom Names Source: https://github.com/robotools/defcon/blob/master/documentation/source/concepts/representations.md Demonstrates the recommended practice for naming representation factories to avoid conflicts. It shows how to register factories for different applications or packages using a 'applicationOrPackageName.representationName' format. ```python from defcon import Glyph, registerRepresentationFactory # Assuming groupEditorGlyphCellImageFactory and previewGlyphFactory are defined elsewhere # registerRepresentationFactory(Glyph, "MetricsMachine.groupEditorGlyphCellImage", groupEditorGlyphCellImageFactory) # registerRepresentationFactory(Glyph, "Prepolator.previewGlyph", previewGlyphFactory) ``` -------------------------------- ### redo Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/lib.md Performs a redo operation if possible. If a redo is performed, it will post BeginRedo and EndRedo notifications. ```APIDOC ## POST /robotools/defcon/redo ### Description Attempts to redo the last undone action. If successful, it triggers notifications for the start and end of the redo operation. ### Method POST ### Endpoint /robotools/defcon/redo ### Response #### Success Response (200) - **status** (str) - Indicates whether redo was performed or not. #### Response Example ```json { "status": "Redo performed successfully." } ``` OR ```json { "status": "No redo available." } ``` ``` -------------------------------- ### Get Representation Data in Defcon Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/layerSet.md Retrieves a representation of the Defcon object, identified by a registered name. Optional keyword arguments are passed to the representation factory. This method is used to get specific views or data formats. ```Python def getRepresentation(name, **kwargs): """Get a representation. **name** must be a registered representation name. **kwargs** will be passed to the appropriate representation factory. """ pass ``` -------------------------------- ### getRepresentation Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/groups.md Gets a representation of the object, identified by a registered name. ```APIDOC ## getRepresentation ### Description Get a representation. **name** must be a registered representation name. **kwargs** will be passed to the appropriate representation factory. ### Method GET ### Endpoint /robotools/defcon/getRepresentation ### Parameters #### Query Parameters - **name** (string) - Required - The name of the representation to retrieve. - **kwargs** (dict) - Optional - Additional arguments to pass to the representation factory. ### Response #### Success Response (200) - **representation** (any) - The requested representation of the object. ### Response Example ```json { "representation": "" } ``` ``` -------------------------------- ### Info Object Methods Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/info.md Documentation for methods related to the Defcon Info object, including observer management, undo/redo capabilities, and representation handling. ```APIDOC ## Info Object Methods ### Description This section details the methods available for interacting with the Defcon Info object, covering observer patterns, undo/redo functionality, and representation management. ### addObserver #### Description Adds an observer to the object's notification dispatcher to receive notifications about changes. #### Method `addObserver(observer, methodName, notification, identifier=None)` #### Parameters - **observer** (object) - Required - An object that can be referenced with weakref. - **methodName** (string) - Required - The name of the method to call when a notification is posted. - **notification** (object) - Required - The notification to observe. - **identifier** (string) - Optional - An identifier for the observation. #### Note The method called will accept a single *notification* argument, which is a [`defcon.tools.notifications.Notification`](notificationcenter.md#defcon.tools.notifications.Notification) object. ### canRedo #### Description Checks if the undo manager can perform a redo operation. #### Method `canRedo()` #### Returns - **boolean** - True if redo is possible, False otherwise. ### canUndo #### Description Checks if the undo manager can perform an undo operation. #### Method `canUndo()` #### Returns - **boolean** - True if undo is possible, False otherwise. ### destroyAllRepresentations #### Description Destroys all stored representations associated with the Info object. #### Method `destroyAllRepresentations(notification=None)` #### Parameters - **notification** (object) - Optional - A notification object. ### destroyRepresentation #### Description Destroys a specific stored representation identified by its name and optional keyword arguments. #### Method `destroyRepresentation(name, **kwargs)` #### Parameters - **name** (string) - Required - The name of the representation to destroy. - **kwargs** - Optional - Additional keyword arguments to filter the representation. ``` -------------------------------- ### Get Glyph Font Object Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/glyph.md Retrieves the 'Font' object to which this glyph belongs. ```python font = glyph.font ``` -------------------------------- ### fromkeys Class Method Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/lib.md Creates a new dictionary with keys from an iterable and values set to a specified value. This is a class method. ```APIDOC ## POST /robotools/defcon/fromkeys ### Description Creates a new dictionary with keys derived from an iterable and all values set to a specified default value. ### Method POST ### Endpoint /robotools/defcon/fromkeys ### Parameters #### Request Body - **iterable** (iterable) - Required - An iterable containing the keys for the new dictionary. - **value** (any) - Optional - The value to assign to each key. Defaults to None. ### Request Example ```json { "iterable": ["key1", "key2", "key3"], "value": "default_value" } ``` ### Response #### Success Response (200) - **dictionary** (dict) - A new dictionary with keys from the iterable and values set to the specified value. #### Response Example ```json { "dictionary": { "key1": "default_value", "key2": "default_value", "key3": "default_value" } } ``` ``` -------------------------------- ### glyphNameForForcedUnicode() Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/unicodedata.md Get the glyph name assigned to a forced-Unicode value. ```APIDOC ## glyphNameForForcedUnicode(value) ### Description Get the glyph name assigned to the forced-Unicode specified by **value**. ### Method [Method not specified, likely GET] ### Endpoint [Endpoint not specified] ### Parameters #### Path Parameters * **value** (string) - Required - The forced-Unicode value. ### Request Example None ### Response #### Success Response (200) * **glyphName** (string or None) - The glyph name associated with the forced-Unicode, or None if not found. #### Response Example None ``` -------------------------------- ### forcedUnicodeForGlyphName() Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/unicodedata.md Get the forced-Unicode value for a given glyph name. ```APIDOC ## forcedUnicodeForGlyphName(glyphName) ### Description Get the forced-Unicode value for **glyphName**. ### Method [Method not specified, likely GET] ### Endpoint [Endpoint not specified] ### Parameters #### Path Parameters * **glyphName** (string) - Required - The name of the glyph. ### Request Example None ### Response #### Success Response (200) * **unicodeValue** (string or None) - The forced-Unicode value for the glyph, or None if not found. #### Response Example None ``` -------------------------------- ### Dictionary-like Methods Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/anchor.md Provides standard dictionary-like methods for accessing and manipulating data. ```APIDOC ## Dictionary-like Methods ### Description These methods provide standard dictionary-like access and manipulation capabilities. ### Methods #### get(key, default=None) - **Method**: GET - **Endpoint**: /robotools/defcon/get - **Parameters**: - **key** (any) - Required - The key to retrieve the value for. - **default** (any) - Optional - The default value to return if the key is not found. - **Response**: Returns the value associated with the key, or the default value. #### items() - **Method**: GET - **Endpoint**: /robotools/defcon/items - **Response**: Returns a set-like object providing a view on the dictionary's items. #### keys() - **Method**: GET - **Endpoint**: /robotools/defcon/keys - **Response**: Returns a set-like object providing a view on the dictionary's keys. #### fromkeys(iterable, value=None) - **Method**: POST - **Endpoint**: /robotools/defcon/fromkeys - **Parameters**: - **iterable** (iterable) - Required - An iterable to create keys from. - **value** (any) - Optional - The value to assign to each key. Defaults to None. - **Response**: Returns a new dictionary with keys from the iterable and values set to the specified value. #### pop(k) - **Method**: DELETE - **Endpoint**: /robotools/defcon/pop - **Parameters**: - **k** (any) - Required - The key to remove and return the value for. - **Response**: Returns the value associated with the key. Raises KeyError if the key is not found and no default is provided. #### popitem() - **Method**: DELETE - **Endpoint**: /robotools/defcon/popitem - **Response**: Removes and returns a (key, value) pair as a 2-tuple in LIFO order. Raises KeyError if the dictionary is empty. ### Example Usage (Conceptual) ```python # Assuming 'obj' is an instance of a class that provides these methods value = obj.get('some_key', 'default_value') all_items = obj.items() all_keys = obj.keys() new_dict = obj.fromkeys(['a', 'b'], 100) removed_value = obj.pop('key_to_remove') first_item = obj.popitem() ``` ``` -------------------------------- ### Get Glyph Pen Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/glyph.md Retrieves the pen object used for drawing operations into the glyph. ```python pen = glyph.getPen() ``` -------------------------------- ### Get Glyph Dispatcher Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/glyph.md Retrieves the NotificationCenter dispatcher associated with the parent object of the glyph. ```python dispatcher = glyph.dispatcher ``` -------------------------------- ### items Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/lib.md Returns a set-like view object that provides a view on the dictionary's items (key-value pairs). ```APIDOC ## GET /robotools/defcon/items ### Description Provides a dynamic view of the dictionary's key-value pairs, allowing iteration over items. ### Method GET ### Endpoint /robotools/defcon/items ### Response #### Success Response (200) - **items_view** (set-like object) - A view object containing the dictionary's items. #### Response Example ```json { "items_view": [ ["key1", "value1"], ["key2", "value2"] ] } ``` ``` -------------------------------- ### glyphNameForUnicode() Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/unicodedata.md Get the first glyph name assigned to a Unicode value. ```APIDOC ## glyphNameForUnicode(value) ### Description Get the first glyph assigned to the Unicode specified as **value**. This will return *None* if no glyph is found. ### Method [Method not specified, likely GET] ### Endpoint [Endpoint not specified] ### Parameters #### Path Parameters * **value** (string) - Required - The Unicode value. ### Request Example None ### Response #### Success Response (200) * **glyphName** (string or None) - The first glyph name assigned to the Unicode, or None if not found. #### Response Example None ``` -------------------------------- ### getRepresentation() Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/unicodedata.md Get a representation associated with a name and optional keyword arguments. ```APIDOC ## getRepresentation(name, **kwargs) ### Description Get a representation. **name** must be a registered representation name. **kwargs** will be passed to the appropriate representation factory. ### Method [Method not specified, likely GET] ### Endpoint [Endpoint not specified] ### Parameters #### Path Parameters * **name** (string) - Required - The registered name of the representation. * **kwargs** (dict) - Optional - Additional keyword arguments to pass to the factory. ### Request Example None ### Response #### Success Response (200) * **representation** (object) - The requested representation object. #### Response Example None ``` -------------------------------- ### Defcon Glyph Object Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/glyph.md Details about the Defcon Glyph object, including its constructor, properties, methods, and notification system. ```APIDOC ## class defcon.Glyph(layer=None, contourClass=None, pointClass=None, componentClass=None, anchorClass=None, guidelineClass=None, libClass=None, imageClass=None) ### Description This object represents a glyph and it contains contour, component, anchor and other assorted bits data about the glyph. **This object posts the following notifications:** - Glyph.Changed - Glyph.BeginUndo - Glyph.EndUndo - Glyph.BeginRedo - Glyph.EndRedo - Glyph.NameWillChange - Glyph.NameChanged - Glyph.UnicodesChanged - Glyph.WidthChanged - Glyph.HeightChanged - Glyph.LeftMarginWillChange - Glyph.LeftMarginDidChange - Glyph.RightMarginWillChange - Glyph.RightMarginDidChange - Glyph.TopMarginWillChange - Glyph.TopMarginDidChange - Glyph.BottomMarginWillChange - Glyph.BottomMarginDidChange - Glyph.NoteChanged - Glyph.LibChanged - Glyph.ImageChanged - Glyph.ImageWillBeCleared - Glyph.ImageCleared - Glyph.ContourWillBeAdded - Glyph.ContourWillBeDeleted - Glyph.ContoursChanged - Glyph.ComponentWillBeAdded - Glyph.ComponentWillBeDeleted - Glyph.ComponentsChanged - Glyph.AnchorWillBeAdded - Glyph.AnchorWillBeDeleted - Glyph.AnchorsChanged - Glyph.GuidelineWillBeAdded - Glyph.GuidelineWillBeDeleted - Glyph.GuidelinesChanged - Glyph.MarkColorChanged - Glyph.VerticalOriginChanged ### Usage The Glyph object has list like behavior. This behavior allows you to interact with contour data directly. #### Accessing Contours - Get a specific contour: `contour = glyph[0]` - Iterate over all contours: `for contour in glyph:` - Get the number of contours: `contourCount = len(glyph)` To interact with components or anchors in a similar way, use the `components` and `anchors` attributes. ### Methods #### Tasks - `name` - `unicodes` - `unicode` #### Metrics - `leftMargin` - `rightMargin` - `width` #### Reference Data - `area` - `bounds` - `controlPointBounds` #### General Editing - `clear()` - `move()` #### Contours - `clearContours()` - `appendContour()` - `insertContour()` - `contourIndex()` - `autoContourDirection()` - `correctContourDirection()` #### Components - `components` - `clearComponents()` - `appendComponent()` - `componentIndex()` - `insertComponent()` #### Anchors - `anchors` - `clearAnchors()` - `appendAnchor()` - `anchorIndex()` - `insertAnchor()` #### Hit Testing - `pointInside()` (See `contour.md#defcon.Contour.pointInside`) #### Pens and Drawing - `getPen()` - `getPointPen()` - `draw()` - `drawPoints()` #### Representations - `getRepresentation()` - `hasCachedRepresentation()` - `representationKeys()` - `destroyRepresentation()` - `destroyAllRepresentations()` #### Changed State - `dirty` #### Notifications - `dispatcher` - `addObserver()` - `removeObserver()` - `hasObserver()` #### Parent - `getParent()` - `setParent()` ``` -------------------------------- ### defcon.Anchor Class Documentation Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/anchor.md Documentation for the defcon.Anchor class, which represents an anchor point in a glyph. It covers initialization, properties, methods for manipulation, and the observer pattern for notifications. ```APIDOC ## Class: defcon.Anchor ### Description This object represents an anchor point. It supports properties like position (x, y), name, and color. It also integrates with a notification system to inform observers of changes. ### Initialization `__init__(glyph=None, anchorDict=None)` Initializes an Anchor object. An optional dictionary can be provided to populate the anchor's data upon creation. ### Properties - **`x`** (number) - The x-coordinate of the anchor. - **`y`** (number) - The y-coordinate of the anchor. - **`name`** (string) - The name of the anchor. - **`color`** (string or tuple or Color object) - The color of the anchor. Setting this posts *Anchor.ColorChanged* and *Anchor.Changed* notifications. - **`dirty`** (boolean) - Indicates if the object has been changed since the last save. True if changed, False otherwise. Setting to True posts the *Anchor.Changed* notification. - **`dispatcher`** (NotificationCenter) - The NotificationCenter assigned to the parent of this object. ### Methods - **`move(xOffset, yOffset)`** Moves the anchor by the specified offsets. - **`addObserver(observer, methodName, notification, identifier=None)`** Adds an observer to the notification dispatcher for a specific notification. - **observer** (object): An object that can be referenced with weakref. - **methodName** (string): The name of the method to call when the notification is posted. - **notification** (string): The notification to observe. - **identifier** (string, optional): An identifier for the observation. - **`removeObserver(observer, methodName, notification, identifier=None)`** Removes an observer from the notification dispatcher. - **`hasObserver(observer, methodName, notification, identifier=None)`** Checks if an observer is registered for a specific notification. - **`getParent()`** Returns the parent object of this anchor. - **`setParent(parent)`** Sets the parent object for this anchor. - **`canRedo()`** Returns a boolean indicating if a redo operation is possible. - **`canUndo()`** Returns a boolean indicating if an undo operation is possible. - **`clear()`** Removes all items from the object. - **`copy()`** Returns a shallow copy of the object. - **`destroyAllRepresentations(**kwargs)`** Destroys all representations of the anchor. - **`destroyRepresentation(name, **kwargs)`** Destroys a specific stored representation. - **`disableNotifications(notification=None, observer=None)`** Disables notifications until `enableNotifications` is called. - **`enableNotifications(notification=None, observer=None)`** Enables notifications that may have been disabled. ### Notifications Posted - **Anchor.Changed** - **Anchor.XChanged** - **Anchor.YChanged** - **Anchor.NameChanged** - **Anchor.ColorChanged** - **Anchor.IdentifierChanged ``` -------------------------------- ### Get Glyph Height Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/glyph.md Retrieves the height of the glyph. Setting this property triggers 'Glyph.HeightChanged' and 'Glyph.Changed' notifications. ```python height = glyph.height ``` -------------------------------- ### getDataForSerialization Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/lib.md Returns a dictionary containing data that can be pickled, allowing for state serialization. ```APIDOC ## GET /robotools/defcon/getDataForSerialization ### Description Retrieves data suitable for serialization (e.g., pickling) from the object. ### Method GET ### Endpoint /robotools/defcon/getDataForSerialization ### Parameters #### Query Parameters - **kwargs** (any) - Optional - Additional keyword arguments to influence serialization. ### Response #### Success Response (200) - **data** (dict) - A dictionary containing the serializable data. #### Response Example ```json { "data": { "": "", "": "" } } ``` ``` -------------------------------- ### Work with Components in Defcon Fonts Source: https://context7.com/robotools/defcon/llms.txt Shows how to add glyph references using components in Defcon for efficient glyph construction. Demonstrates creating a new glyph, appending a base glyph as a component, and adding another glyph (e.g., an accent) as a component with a specific transformation matrix. ```python # Create a component that references another glyphglyph = font.newGlyph("Aacute")glyph.width = 700 # Add base glyph as component component = glyph.appendComponent("A") # Add accent as second component with transformation accent = glyph.appendComponent("acutecomb") # Transformation: (xScale, xyScale, yxScale, yScale, xOffset, yOffset) accent.transformation = (1, 0, 0, 1, 250, 200) ``` -------------------------------- ### keys Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/groups.md Returns a view object that displays a list of all the keys in a dictionary. ```APIDOC ## keys ### Description Returns a set-like object providing a view on the dictionary's keys. ### Method GET ### Endpoint /robotools/defcon/keys ### Response #### Success Response (200) - **keys_view** (set-like object) - A view of the dictionary's keys. ### Response Example ```json { "keys_view": ["key1", "key2"] } ``` ``` -------------------------------- ### Get Glyph Point Pen Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/glyph.md Retrieves the point pen object used for drawing points into the glyph. ```python point_pen = glyph.getPointPen() ``` -------------------------------- ### keys Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/layer.md Returns the names of all glyphs currently in the layer. ```APIDOC ## GET /robotools/defcon/keys ### Description Returns the names of all glyphs in the layer. ### Method GET ### Endpoint /robotools/defcon/keys ### Parameters None ### Response #### Success Response (200) - **glyphNames** (list) - A list of strings, where each string is the name of a glyph in the layer. #### Response Example ```json [ "glyph1", "glyph2", "anotherGlyph" ] ``` ``` -------------------------------- ### decompositionBaseForGlyphName() Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/unicodedata.md Get the decomposition base for a given glyph name. Optionally allows pseudo-Unicode values. ```APIDOC ## decompositionBaseForGlyphName(glyphName, allowPseudoUnicode=True) ### Description Get the decomposition base for **glyphName**. If **allowPseudoUnicode** is True, a pseudo-Unicode value will be used if needed. This will return *glyphName* if nothing can be found. ### Method [Method not specified, likely GET] ### Endpoint [Endpoint not specified] ### Parameters #### Path Parameters * **glyphName** (string) - Required - The name of the glyph. * **allowPseudoUnicode** (boolean) - Optional - Defaults to True. If True, a pseudo-Unicode value will be used if needed. ### Request Example None ### Response #### Success Response (200) * **glyphName** (string) - The decomposition base glyph name. #### Response Example None ``` -------------------------------- ### Guideline Management Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/glyph.md Methods for managing guidelines within a glyph, including adding, retrieving, and clearing them. ```APIDOC ## appendGuideline(guideline) ### Description Append a guideline to the glyph. The guideline must be a defcon `Guideline` object or a subclass. An error will be raised if the guideline’s identifier conflicts with any of the identifiers within the glyph. This will post a *Glyph.Changed* notification. ### Method POST ### Endpoint N/A (Python method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **guideline** (defcon.objects.guideline.Guideline) - Required - The guideline object to append. ### Request Example ```python new_guideline = defcon.objects.guideline.Guideline(x=500, y=0, angle=90) glyph.appendGuideline(new_guideline) ``` ### Response #### Success Response (200) None (method call) #### Response Example None ## clearGuidelines() ### Description Clear all guidelines from the glyph. This posts a *Glyph.Changed* notification. ### Method DELETE ### Endpoint N/A (Python method) ### Parameters None ### Request Example ```python glyph.clearGuidelines() ``` ### Response #### Success Response (200) None (method call) #### Response Example None ``` -------------------------------- ### closeRelativeForGlyphName() Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/unicodedata.md Get the close relative for a given glyph name. Optionally allows pseudo-Unicode values. ```APIDOC ## closeRelativeForGlyphName(glyphName, allowPseudoUnicode=True) ### Description Get the close relative for **glyphName**. For example, if you request the close relative of the glyph name for the character (, you will be given the glyph name for the character ) if it exists in the font. If **allowPseudoUnicode** is True, a pseudo-Unicode value will be used if needed. This will return *None* if nothing can be found. ### Method [Method not specified, likely GET] ### Endpoint [Endpoint not specified] ### Parameters #### Path Parameters * **glyphName** (string) - Required - The name of the glyph. * **allowPseudoUnicode** (boolean) - Optional - Defaults to True. If True, a pseudo-Unicode value will be used if needed. ### Request Example None ### Response #### Success Response (200) * **glyphName** (string or None) - The glyph name of the close relative, or None if not found. #### Response Example None ``` -------------------------------- ### Observer Management Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/glyph.md Methods for adding and managing observers for glyph notifications. ```APIDOC ## addObserver(observer, methodName, notification, identifier=None) ### Description Add an observer to this object’s notification dispatcher. ### Method POST (conceptual, as this is a Python method) ### Endpoint N/A (Python method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **observer** (object) - Required - An object that can be referenced with weakref. * **methodName** (string) - Required - A string representing the method to be called when the notification is posted. * **notification** (string) - Required - The notification that the observer should be notified of. * **identifier** (string or None) - Optional - None or a string identifying the observation. A reverse domain naming scheme is recommended. ### Request Example ```python # Example of adding an observer anObject.addObserver(observer=myObserver, methodName='handleNotification', notification='Glyph.Changed') ``` ### Response #### Success Response (200) None (this is a method call) #### Response Example None ``` -------------------------------- ### Get Cached Representation Keys Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/component.md Retrieves a list of all keys corresponding to representations that are currently stored in the object's cache. ```python def representationKeys(): """ Get a list of all representation keys that are currently cached. """ pass ``` -------------------------------- ### Get Guideline Index in Glyph Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/glyph.md Returns the index of a specific 'guideline' object within the glyph's ordered list of guidelines. ```python index = glyph.guidelineIndex(guideline) ``` -------------------------------- ### View Dictionary Keys Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/anchor.md Returns a set-like object providing a view on the dictionary's keys. Changes to the dictionary are reflected in the view. ```python keys() → a set-like object providing a view on D's keys ``` -------------------------------- ### Get items view from dictionary Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/kerning.md Returns a set-like object that provides a view of the dictionary's items (key-value pairs). ```Python def items() -> set: """ → a set-like object providing a view on D's items """ pass ``` -------------------------------- ### Get Object Representation Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/component.md Retrieves a specific representation of an object by its registered name. Additional keyword arguments are passed to the representation factory. ```python def getRepresentation(name, **kwargs): """ Get a representation. **name** must be a registered representation name. **kwargs** will be passed to the appropriate representation factory. """ pass ``` -------------------------------- ### Drawing and Pen Interfaces Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/glyph.md Methods related to drawing the glyph using a pen interface and retrieving drawing pens. ```APIDOC ## draw(pen) ### Description Draw the glyph using the provided pen object. ### Method POST ### Endpoint /glyph/{glyph_id}/draw #### Parameters ##### Request Body - **pen** (object) - Required - The pen object to draw with. ## drawPoints(pointPen) ### Description Draw the glyph's points using the provided point pen object. ### Method POST ### Endpoint /glyph/{glyph_id}/drawPoints #### Parameters ##### Request Body - **pointPen** (object) - Required - The point pen object to draw with. ## getPen() ### Description Get the pen object used for drawing into this glyph. ### Method GET ### Endpoint /glyph/{glyph_id}/pen ## getPointPen() ### Description Get the point pen object used for drawing points into this glyph. ### Method GET ### Endpoint /glyph/{glyph_id}/pointPen ``` -------------------------------- ### Get Named Representation Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/anchor.md Retrieves a specific representation of the object identified by its name. Additional keyword arguments are passed to the representation factory. ```python getRepresentation(name, **kwargs) ``` -------------------------------- ### Component Properties and Methods (Python) Source: https://github.com/robotools/defcon/blob/master/documentation/source/objects/component.md Provides access to component properties like baseGlyph, bounds, and dirty state, as well as methods for drawing and hit testing. These are fundamental operations for manipulating and inspecting component data. ```Python class Component: # Properties @property def baseGlyph(self): """The glyph that the components references. Setting this will post *Component.BaseGlyphChanged* and *Component.Changed* notifications.""" pass @property def bounds(self): """The bounds of the components’s outline expressed as a tuple of form (xMin, yMin, xMax, yMax).""" pass @property def controlPointBounds(self): """The control bounds of all points in the components. This only measures the point positions, it does not measure curves. So, curves without points at the extrema will not be properly measured.""" pass @property def dirty(self): """The dirty state of the object. True if the object has been changed. False if not. Setting this to True will cause the base changed notification to be posted. The object will automatically maintain this attribute and update it as you change the object.""" pass @property def dispatcher(self): """The [`defcon.tools.notifications.NotificationCenter`](notificationcenter.md#defcon.tools.notifications.NotificationCenter) assigned to the parent of this object.""" pass # Methods def pointInside(self): """Hit Testing method.""" pass def draw(self, pen): """Draw the component with **pen**.""" pass def drawPoints(self, pointPen): """Draw the component with **pointPen**.""" pass def destroyAllRepresentations(self, notification=None): """Destroy all representations.""" pass def destroyRepresentation(self, name, **kwargs): """Destroy the stored representation for **name** and **kwargs**. If no **kwargs** are given, any representation with **name** will be destroyed regardless of the **kwargs** passed when the representation was created.""" pass def canRedo(self): """Returns a boolean indicating whether the undo manager is able to perform a redo.""" pass def canUndo(self): """Returns a boolean indicating whether the undo manager is able to perform an undo.""" pass def getParent(self): """Returns the parent object.""" pass def setParent(self, parent): """Sets the parent object.""" pass ```