### Install FoundryTools with pip Source: https://github.com/ftcli/foundrytools/blob/main/README.md Install the FoundryTools package from PyPI using pip. Ensure you have Python 3.10 or later. ```bash python -m pip install foundrytools ``` -------------------------------- ### Standard Naming Syntax Examples Source: https://github.com/ftcli/foundrytools/blob/main/foundrytools/data/README-standardnam.md Illustrates the different prefixes used for naming conventions: no prefix for production, friendly, and alternative names; '>' for friendly and alternative; '<' for alternative; and '!' for synonyms. ```plaintext names without prefix are used as production, friendly and alternative names - names with `> ` prefix are used as friendly and alternative names - names with `< ` prefix are used as alternative names - names with `!` prefix are used as synonyms ``` -------------------------------- ### Clone Repository and Install in Editable Mode Source: https://github.com/ftcli/foundrytools/blob/main/README.md Clone the FoundryTools repository from GitHub and install it in editable mode for development. This method is recommended for contributors and requires setting up a virtual environment. ```bash # clone the repository: git clone https://github.com/ftCLI/FoundryTools.git cd foundrytools # create new virtual environment named e.g. ftcli-venv, or whatever you prefer: python -m venv foundrytools-venv # to activate the virtual environment in macOS and Linux, do: . foundrytools-venv/bin/activate # to activate the virtual environment in Windows, do: foundrytools-venv\Scripts\activate.bat # install in 'editable' mode python -m pip install -e . ``` -------------------------------- ### Production Name Compatibility Examples Source: https://github.com/ftcli/foundrytools/blob/main/foundrytools/data/README-standardnam.md Shows examples of production names that are compatible with the Adobe Glyph List for New Fonts (AGLFN) v1.7, including specific Unicode mappings. ```plaintext | Unicode | Friendly | Production | |:--------|:--------------|:--------------| | 0x00B2 | twosuperior | twosuperior | | 0x00B3 | threesuperior | threesuperior | | 0x00B5 | micro | uni00B5 | | 0x00B9 | onesuperior | onesuperior | | 0x0394 | Delta | uni0394 | | 0x03A9 | Omega | uni03A9 | | 0x03BC | mu | uni03BC | | 0x2126 | Ohm | uni2126 | | 0x2206 | increment | uni2206 | | 0xFB00 | f_f | f_f | | 0xFB01 | fi | fi | | 0xFB02 | fl | fl | | 0xFB03 | f_f_i | f_f_i | | 0xFB03 | f_f_i | f_f_i | | 0xFB04 | f_f_l | f_f_l | | 0xFB04 | f_f_l | f_f_l | | 0xFB05 | longs_t | longs_t | | 0xFB06 | s_t | s_t | ``` -------------------------------- ### AGLFN 1.7 Compatibility Examples Source: https://github.com/ftcli/foundrytools/blob/main/foundrytools/data/README-standardnam.md Lists specific character mappings for improved Mac OS X 10.4 compatibility, adhering to AGLFN 1.7 standards. ```plaintext 0x0122 !Gcommaaccent 0x0123 !gcommaaccent 0x0136 !Kcommaaccent 0x0137 !kcommaaccent 0x013B !Lcommaaccent 0x013C !lcommaaccent 0x0145 !Ncommaaccent 0x0146 !ncommaaccent 0x0156 !Rcommaaccent 0x0157 !rcommaaccent 0x0162 !Tcommaaccent 0x0163 !tcommaaccent 0x0218 !Scommaaccent 0x0219 !scommaaccent ``` -------------------------------- ### Basic FontFinder Initialization Source: https://github.com/ftcli/foundrytools/blob/main/README.md Demonstrates basic initialization of FontFinder with a path and default options. Use this for simple font discovery. ```python from foundrytools.lib.font_finder import FontFinder # Path to process path = "path/to/fonts/" # Initialize FontFinder with default options finder = FontFinder(input_path=path) # Find fonts fonts = finder.find_fonts() # Process fonts for font in fonts: print(font) ``` -------------------------------- ### Initialize Font from File, BytesIO, or TTFont Source: https://github.com/ftcli/foundrytools/blob/main/README.md Demonstrates loading a font from a file path, a BytesIO object, or using it as a context manager. Ensure the font file exists at the specified path. ```python from io import BytesIO from foundrytools import Font # Loading a font from a file font = Font("path/to/font.ttf") print(font.file) # Access the file path # Loading a font from BytesIO with open("path/to/font.ttf", "rb") as f: font_data = BytesIO(f.read()) font = Font(font_data) print(font.bytesio) # BytesIO object access # Using the class as a context manager with Font("path/to/font.ttf") as font: print(font.ttfont) # Access the TTFont object ``` -------------------------------- ### Initialize and Find Fonts Source: https://github.com/ftcli/foundrytools/blob/main/README.md Initializes FontFinder with a path and finds all matching fonts. Use this for a straightforward search. ```python from foundrytools.lib.font_finder import FontFinder finder = FontFinder(input_path="path/to/fonts") fonts = finder.find_fonts() for font in fonts: print(font.file) ``` -------------------------------- ### Initialize and Generate Fonts Source: https://github.com/ftcli/foundrytools/blob/main/README.md Initializes FontFinder with custom options and filters, then generates fonts one by one. This is memory-efficient for large directories. ```python from foundrytools.lib.font_finder import FontFinder, FinderOptions, FinderFilter options = FinderOptions(recursive=True, lazy=True) filter_ = FinderFilter(filter_out_tt=True, filter_out_woff=True) finder = FontFinder(input_path="path/to/fonts", options=options, filter_=filter_) for font in finder.generate_fonts(): print(font.file) ``` -------------------------------- ### Access and Modify Name and OS/2 Tables Source: https://github.com/ftcli/foundrytools/blob/main/README.md Illustrates accessing and modifying the 'name' and 'OS/2' tables using their respective wrapper objects. This includes operations like removing unused names, finding/replacing strings, and updating weight class and Unicode ranges. ```python from foundrytools import Font font = Font("path/to/font.otf") font.t_name.remove_unused_names() font.t_name.find_replace("Old Family Name", "New Family Name") font.t_os_2.weight_class = 400 font.t_os_2.recalc_unicode_ranges(percentage=33.0) ``` -------------------------------- ### FontFinder Constructor Source: https://github.com/ftcli/foundrytools/blob/main/README.md Initializes the FontFinder instance with a path and optional search options and filters. ```APIDOC ## FontFinder(`input_path`, `options`=None, `filter_`=None) ### Description Initializes the FontFinder instance. ### Parameters - **input_path** (`Path`): The file or directory path to search for fonts. - **options** (`FinderOptions`): Optional class containing customizable search options. If not provided, defaults to sensible defaults. - **filter_** (`FinderFilter`): Optional class used to filter results based on font properties. ### Key Actions - Resolves the `input_path` to an absolute path. If invalid, a `FinderError` is raised. - Generates filter conditions from the provided `filter_`. - Validates that no conflicting filters are in use. ``` -------------------------------- ### Initialize Font Table Placeholders Source: https://github.com/ftcli/foundrytools/blob/main/README.md This method initializes all font table attributes to None, preparing them for lazy loading when accessed. It ensures a consistent initial state for various font tables. ```python def _init_tables(self) -> None: """ Initialize all font table attributes to None. This method sets up the initial state for each table in the font, ensuring that they are ready to be loaded when accessed. """ self._cff: Optional[CFFTable] = None self._cmap: Optional[CmapTable] = None self._fvar: Optional[FvarTable] = None self._gdef: Optional[GdefTable] = None self._glyf: Optional[GlyfTable] = None self._gsub: Optional[GsubTable] = None self._head: Optional[HeadTable] = None self._hhea: Optional[HheaTable] = None self._hmtx: Optional[HmtxTable] = None self._kern: Optional[KernTable] = None self._name: Optional[NameTable] = None self._os_2: Optional[OS2Table] = None self._post: Optional[PostTable] = None ``` -------------------------------- ### Instantiate Font and Access CFF Table Source: https://github.com/ftcli/foundrytools/blob/main/README.md Shows the basic usage of the Font class to load a font file and access its CFF table. The CFFTable object provides methods for manipulating CFF-specific data. ```python from foundrytools import Font font = Font("path/to/font.otf") cff_table = font.t_cff_ ``` -------------------------------- ### Manage Font Style Flags Source: https://github.com/ftcli/foundrytools/blob/main/README.md Shows how to check and set font style properties like bold, italic, and oblique using the StyleFlags class. The 'is_regular' property is read-only; use set_regular() to modify. ```python from foundrytools.core.font import Font font = Font("path/to/font.ttf") print(font.flags.is_bold) # Check if the font is bold font.flags.is_bold = True # Set the font as bold font.flags.is_italic = False # Set the font as non-italic font.flags.is_oblique = True # Set the font as oblique # The is_regular property is read-only, as it is inferred from the other style flags. To set the # font as regular, use the set_regular method. font.flags.set_regular() # Set the font as regular ``` -------------------------------- ### Direct Access and Modification of Post Table Source: https://github.com/ftcli/foundrytools/blob/main/README.md Demonstrates accessing and modifying a font table directly using fontTools.TTFont and the FoundryTools table wrapper without instantiating the Font class. This is useful for lower-level manipulation. ```python from fontTools.ttLib import TTFont from foundrytools.core.tables.post import PostTable ttfont = TTFont("path/to/font.ttf") post = PostTable(ttfont) post.italic_angle = 0.0 post.underline_position = -100 ttfont.save("path/to/font_2.ttf") ``` -------------------------------- ### Private Font Table Getter Method Source: https://github.com/ftcli/foundrytools/blob/main/README.md The _get_table method implements lazy loading for font tables. It ensures a table is loaded only when first accessed and raises a KeyError if the table is not found in the font. ```python def _get_table(self, table_tag: str): # type: ignore table_attr, table_cls = TABLES_LOOKUP[table_tag] if getattr(self, table_attr) is None: if self.ttfont.get(table_tag) is None: raise KeyError(f"The '{table_tag}' table is not present in the font") setattr(self, table_attr, table_cls(self.ttfont)) table = getattr(self, table_attr) if table is None: raise KeyError(f"An error occurred while loading the '{table_tag}' table") return table ``` -------------------------------- ### Modify CFF Table and Save Font Source: https://github.com/ftcli/foundrytools/blob/main/README.md Demonstrates modifying the CFF table using methods provided by the CFFTable wrapper, such as remove_hinting and round_coordinates, and then saving the modified font. ```python from foundrytools.core.font import Font font = Font("path/to/font.otf") font.t_cff_.remove_hinting() font.t_cff_.round_coordinates() font.save("path/to/font_2.otf") ``` -------------------------------- ### Font Property for CFF Table Access Source: https://github.com/ftcli/foundrytools/blob/main/README.md This property method demonstrates how the _get_table helper is used to provide convenient access to specific font tables. It returns a CFFTable instance, which wraps the underlying fontTools CFF table. ```python @property def t_cff_(self) -> CFFTable: return self._get_table("CFF ") ``` -------------------------------- ### Specific Character Additions Source: https://github.com/ftcli/foundrytools/blob/main/foundrytools/data/README-standardnam.md Details specific character additions and their mappings, such as '!vav' for 0x05D5 and 'Imacron'/'ibreve' for 0x012A/0x012D. ```plaintext 0x05D5 !vav (added in all files) ``` ```plaintext 0x012A Imacron (added in all files) 0x012D ibreve (added in all files) ``` -------------------------------- ### generate_fonts() Source: https://github.com/ftcli/foundrytools/blob/main/README.md A generator function that yields Font objects one by one, useful for memory-efficient processing of large datasets. ```APIDOC ## generate_fonts() ### Description A generator function that yields `Font` objects one by one. Useful when memory efficiency is critical and a large number of files are processed. ### Yields - An object of type `Font` for each font matching the criteria. ### Exceptions - Skips files that raise `TTLibError` or `PermissionError`. ``` -------------------------------- ### Font Table Lookup Dictionary Source: https://github.com/ftcli/foundrytools/blob/main/README.md This dictionary maps table tags to their corresponding attribute names and class types for instantiation. It's used internally by the _get_table method for lazy loading. ```python TABLES_LOOKUP = { "CFF ": ("_cff", CFFTable), "cmap": ("_cmap", CmapTable), "fvar": ("_fvar", FvarTable), "GDEF": ("_gdef", GdefTable), "glyf": ("_glyf", GlyfTable), "GSUB": ("_gsub", GsubTable), "head": ("_head", HeadTable), "hhea": ("_hhea", HheaTable), "kern": ("_kern", KernTable), "hmtx": ("_hmtx", HmtxTable), "name": ("_name", NameTable), "OS/2": ("_os_2", OS2Table), "post": ("_post", PostTable), } ``` -------------------------------- ### Access Wrapped ttLib Table Object Source: https://github.com/ftcli/foundrytools/blob/main/README.md Shows how to access the underlying fontTools ttLib table object from the FoundryTools table wrapper using the '.table' attribute. This allows direct use of fontTools methods. ```python font.t_name.table.getBestFamilyName() # Access the wrapped ttLib.tables._n_a_m_e.table__n_a_m_e object font.ttfont["name"].getBestFamilyName() # This is equivalent to the above line ``` -------------------------------- ### find_fonts() Source: https://github.com/ftcli/foundrytools/blob/main/README.md Returns a list of Font objects that meet the specified search and filter conditions. ```APIDOC ## find_fonts() ### Description This method evaluates font files in the given path and applies the specified filter conditions. ### Returns - A list of `Font` objects matching the criteria. ### Example ```python from foundrytools.lib.font_finder import FontFinder finder = FontFinder(input_path="path/to/fonts") fonts = finder.find_fonts() for font in fonts: print(font.file) ``` ``` -------------------------------- ### Fix Italic Angle with FoundryTools App Source: https://github.com/ftcli/foundrytools/blob/main/README.md Demonstrates how to use the `fix_italic_angle` application to correct the italic angle of fonts found by `FontFinder`. Fonts are processed and saved with a modified filename. ```python from foudrytools.lib.font_finder import FontFinder from foundrytools.apps.fix_italic_angle import run as fix_italic_angle finder = FontFinder(input_path="path/to/fonts") fonts = finder.find_fonts() for font in fonts: fix_italic_angle(font) font.save(font.file.with_name(f"{font.file.stem}_fixed.ttf")) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.