mcfonts.filters

A filter is a class used to control what characters and providers are included or not included when exporting.

Module Contents

Classes

Filter

A filter used in exporting; this controls which glyphs are exported and under which conditions.

Policy

How to handle filtered characters or providers.

class mcfonts.filters.Filter(filtered_characters=None, filtered_providers=None, character_policy=Policy.EXCLUDE, provider_policy=Policy.EXCLUDE)

A filter used in exporting; this controls which glyphs are exported and under which conditions.

Can either act as either an excluding filter, or an inclusive filter.

Construct a filter.

Parameters:
filtered_characters : set[str] | str | None

An optional string or set of strings of the character to add to the filter.

filtered_providers : set[type[mcfonts.providers.base.Provider]] | None

An optional list of the types of providers to add to the filter.

character_policy : Policy

The policy to use with regards to the character filter. Can also be an integer.

provider_policy : Policy

The policy to use with regards to the provider filter. Can also be an integer.

check_character(character)

Determine how character should be handled.

  • If character is in filtered characters and character policy is EXCLUDE, or

  • If character is not in filtered characters and character policy is INCLUDE:
    • Skip character

Parameters:
character : str

A string of a character to determine filtering for.

Returns:

A boolean; True to skip, False to include normally.

Return type:

bool

check_provider(provider)

Determine how provider should be handled.

  • If provider is in filtered providers and provider policy is EXCLUDE, or

  • If provider is not in filtered providers and provider policy is INCLUDE:
    • Skip provider

Parameters:
provider : type[mcfonts.providers.base.Provider]

The type of the provider to determine filtering for; this is not an instance.

Returns:

A boolean; True to skip, False to include normally.

Return type:

bool

filter_character(character)

Add character to the character filter.

Parameters:
character : str

A string of 1 character.

Returns:

Boolean of success; True if character was added, False if it was already present.

Return type:

bool

filter_provider(provider)

Add provider to the provider filter.

Parameters:
provider : type[mcfonts.providers.base.Provider]

A type of Provider.

Returns:

Boolean of success; True if the provider was added, False if it was already present.

Return type:

bool

set_character_policy(new_char_policy)

Set the character policy for how to handle filtering characters.

Parameters:
new_char_policy : Policy

A value from the Policy enum.

Return type:

None

set_provider_policy(new_provider_policy)

Set the provider policy for how to handle filtering providers.

Parameters:
new_provider_policy : Policy

A value from the Policy enum.

Return type:

None

unfilter_character(character)

Remove character from the character filter.

Parameters:
character : str

A string of 1 character.

Returns:

Boolean of success; True if character was removed, False if it wasn't present.

Return type:

bool

unfilter_provider(provider)

Remove provider from the provider filter.

Parameters:
provider : type[mcfonts.providers.base.Provider]

A type of Provider.

Returns:

Boolean of success; True if provider was removed, False if it was never present.

Return type:

bool

class mcfonts.filters.Policy

Bases: enum.IntEnum

How to handle filtered characters or providers.

Initialize self. See help(type(self)) for accurate signature.

EXCLUDE = 1

Include none of the predicate matches.

INCLUDE = 0

Include only the predicate matches.


Last update: 2023 November 30