Metadata-Version: 2.4
Name: fontforge_plugin_helper
Version: 0.3.0
Summary: Common routines for Fontforge plugins
Home-page: https://github.com/MihailJP/fontforge-plugin-helper
Author: MihailJP
Author-email: mihailjp@gmail.com
License: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: Text Processing :: Fonts
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

Fontforge plugin helper
=======================

A collection of common routines for Fontforge plugins

This module is intended to be called from Fontforge plugins.
This module itself is not a Fontforge plugin.

Install
-------

```shell
pip3 install fontforge_plugin_helper
```

Usage
-----

### Hook-related features

#### fontforge_plugin_helper.addSystemHook()

```python
def myNewFontHook(font):
    do_something


def myLoadFontHook(font):
    do_something


def fontforge_plugin_init(**kw):
    fontforge_plugin_helper.addSystemHook('newFontHook', myNewFontHook)
    fontforge_plugin_helper.addSystemHook('loadFontHook', myLoadFontHook)
```

#### fontforge_plugin_helper.addFontGenerateHook()

```python
def myPreGenerationHook(font):
    do_something


def myPostGenerationHook(font):
    do_something


def myNewOrLoadFontHook(font):
    fontforge_plugin_helper.addFontGenerateHook(font,
                                                'generateFontPreHook',
                                                myPreGenerationHook)
    fontforge_plugin_helper.addFontGenerateHook(font,
                                                'generateFontPostHook',
                                                myPostGenerationHook)


def fontforge_plugin_init(**kw):
    fontforge_plugin_helper.addSystemHook('newFontHook', myNewOrLoadFontHook)
    fontforge_plugin_helper.addSystemHook('loadFontHook', myNewOrLoadFontHook)
```

#### fontforge_plugin_helper.generationHookSetter()

```python
def myPreGenerationHook(font):
    do_something


def myPostGenerationHook(font):
    do_something


def fontforge_plugin_init(**kw):
    fontforge_plugin_helper.addSystemHook(
        'newFontHook',
        fontforge_plugin_helper.generationHookSetter(
            myPreGenerationHook,
            myPostGenerationHook,
        )
    )
    fontforge_plugin_helper.addSystemHook(
        'loadFontHook',
        fontforge_plugin_helper.generationHookSetter(
            myPreGenerationHook,
            None,  # if not needed
        )
    )
```

### Translation-related features

#### class fontforge_plugin_helper.Translations

```python
tr = fontforge_plugin_helper.Translations()

def spam(u, font):
    pass

def fontforge_plugin_init(**kw):
    tr.set('fr', '_Open', '_Ouvrir')
    tr.setTranslations('fr', {
        '_Open': '_Ouvrir',
        '_Close': '_Fermer',
        '_MyMenu': '_MonMenu',
    })
    tr.setTranslations('de', {
        '_Open': 'Ö_ffnen',
        '_Close': 'S_chließen',
        '_MyMenu': '_MeinMenü',
    })
    fontforge.registerMenuItem(
        callback=spam,
        context="Font",
        name=tr.get('_MyMenu')
    )
```
