mcfonts.filters#

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

Module Contents#

Classes#

CharPolicy

How to handle filtered characters.

Filter

A filter used in exporting.

FilterResult

The result of a filter query.

OptionPolicy

How to handle special options attached to characters.

ProviderPolicy

How to handle filtered providers.

class mcfonts.filters.CharPolicy(*args, **kwds)#

Bases: enum.Enum

How to handle filtered characters.

EXCLUDE = 1#

Do not include any of the characters in this filter.

INCLUDE = 0#

Include only the characters in this filter.

class mcfonts.filters.Filter(filtered_chars: set[str] | str | None = None, filtered_providers: set[type[mcfonts.providers.utils.AnyProvider]] | None = None, char_policy: CharPolicy = CharPolicy.EXCLUDE, provider_policy: ProviderPolicy = ProviderPolicy.EXCLUDE, option_policy: OptionPolicy = OptionPolicy.INCLUDE)#

A filter used in exporting.

Can filter characters based on their codepoint, and if they have options. Can filter providers based on their type.

filter_char(character: str) bool#

Add character to the character filter.

Parameters:

character -- A string of 1 character.

Returns:

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

filter_provider(provider: type[mcfonts.providers.utils.AnyProvider]) bool#

Add provider to the provider filter.

Parameters:

provider -- A type of AnyProvider.

Returns:

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

set_char_policy(new_char_policy: CharPolicy) None#

Set the character policy for how to handle filtering characters.

Parameters:

new_char_policy -- A value from the CharPolicy enum.

set_option_policy(new_option_policy: OptionPolicy) None#

Set the option policy for how to handle filtering characters with options.

Parameters:

new_option_policy -- A value from the OptionPolicy enum.

set_provider_policy(new_provider_policy: ProviderPolicy) None#

Set the provider policy for how to handle filtering providers.

Parameters:

new_provider_policy -- A value from the ProviderPolicy enum.

should_ignore_char(character: str, options: mcfonts.providers.options.OptionsProvider | None = None) FilterResult#

Determine how character should be handled, working off of the current Filter instance.

  • If filtered characters are declared:
    • 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

  • If options exist:
    • If options DO EXIST for character:
      • If option policy is INCLUDE or INCLUDE_ONLY:
        • Continue

      • If option policy is DISREGARD_OPTIONS:
        • Ignore character options, continue

      • If option policy is EXCLUDE:
        • Skip character

    • If options DO EXIST for character AND option policy is INCLUDE_ONLY:
      • Skip character

  • Else:
    • Continue

Parameters:
  • character -- A string of a character to determine filtering for.

  • options -- An optional instance of OptionsProvider. If this is None, self.char_policy will be ignored.

Returns:

A value from the FilterResult enum.

should_ignore_provider(provider: type[mcfonts.providers.utils.AnyProvider]) FilterResult#

Determine how provider should be handled, working off of the current Filter instance.

  • If filtered providers are declared:
    • 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

  • Else:
    • Continue

Parameters:

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

Returns:

A value from the FilterResult enum.

unfilter_char(character: str) bool#

Remove character from the character filter.

Parameters:

character -- A string of 1 character.

Returns:

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

unfilter_provider(provider: type[mcfonts.providers.utils.AnyProvider]) bool#

Remove provider from the provider filter.

Parameters:

provider -- A type of AnyProvider.

Returns:

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

class mcfonts.filters.FilterResult(*args, **kwds)#

Bases: enum.Enum

The result of a filter query.

CONTINUE = 0#

No special treatment needed; this character is not filtered.

DISCARD_CHAR_OPTIONS = 3#

Character is allowed, but special options must not be considered.

SKIP_CHAR = 1#

Skip this character.

SKIP_PROVIDER = 2#

Skip this provider.

class mcfonts.filters.OptionPolicy(*args, **kwds)#

Bases: enum.Enum

How to handle special options attached to characters.

DISREGARD_OPTIONS = 1#

Disregard the options for a char, even if declared (but still include the char).

EXCLUDE = 3#

Do not include characters that have any options declared..

INCLUDE = 0#

Include characters that have options declared.

INCLUDE_ONLY = 2#

Only include characters that have any options declared.

class mcfonts.filters.ProviderPolicy(*args, **kwds)#

Bases: enum.Enum

How to handle filtered providers.

EXCLUDE = 1#

Do not include these providers.

INCLUDE = 0#

Include only these providers.