### Install TTFunk Gem Source: https://www.rubydoc.info/gems/ttfunk/file/README.md Install the TTFunk library using the RubyGems package manager. This is the recommended installation method. ```bash gem install ttfunk ``` -------------------------------- ### GET #each Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/Dict Iterates over all dictionary entries. ```APIDOC ## GET #each ### Description Iterate over dict entries. Also known as #each_pair. ### Yield Parameters - **key** (Integer) - The operator key. - **value** (Array) - The associated operands. ``` -------------------------------- ### GET #supported? Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cmap/Format12 Checks if the encoding record format is supported. ```APIDOC ## #supported? ### Description Is this encoding record format supported? ### Response #### Success Response (200) - **supported** (true) - Returns true if supported. ``` -------------------------------- ### Initialize TTFunk::File instance Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/File%3Ainitialize Creates a new File instance by wrapping the provided binary string in a StringIO object and parsing the font directory. ```ruby def initialize(contents, offset = 0) @contents = StringIO.new(contents) @directory = Directory.new(@contents, offset) end ``` -------------------------------- ### GET #rangify Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/BinUtils Turns a sorted sequence of values into a series of two-element arrays representing start and length. ```APIDOC ## rangify(values) ### Description Turns a (sorted) sequence of values into a series of two-element arrays where the first element is the start and the second is the length. ### Parameters #### Request Body - **values** (Array) - Required - A sorted sequence of integers. ### Response #### Success Response (200) - **result** (Array) - An array of [start, length] pairs. ``` -------------------------------- ### Initialize TTFunk::File Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/File%3Ainitialize Initializes a new instance of the TTFunk::File class by providing the binary font data. ```APIDOC ## POST /TTFunk::File#initialize ### Description Returns a new instance of File, which parses the provided binary font data. ### Method POST ### Parameters #### Request Body - **contents** (String) - Required - Binary string containing the font data - **offset** (Integer) - Optional - Offset at which the font data starts (defaults to 0) ### Request Example { "contents": "binary_font_data_string", "offset": 0 } ### Response #### Success Response (200) - **File** (Object) - A new instance of the TTFunk::File class ``` -------------------------------- ### Get Predefined Encoding by ID - TTFunk Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/Encoding.codes_for_encoding_id Retrieves predefined encoding constants based on the provided encoding ID. Use this method to get the correct encoding array for STANDARD or EXPERT encodings. ```ruby def codes_for_encoding_id(encoding_id) case encoding_id when STANDARD_ENCODING_ID Encodings::STANDARD when EXPERT_ENCODING_ID Encodings::EXPERT end end ``` -------------------------------- ### Initialize TTFunk::Table::Simple Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Simple%3Ainitialize Creates a new instance of the Simple table class. Requires a TTFunk::File object and a string tag. ```ruby # File 'lib/ttfunk/table/simple.rb', line 15 def initialize(file, tag) @tag = tag super(file) end ``` -------------------------------- ### Initialize TTFunk Directory Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Directory%3Ainitialize Initializes a new Directory instance by reading the offset table from the provided IO object. ```ruby def initialize(io, offset = 0) io.seek(offset) # https://www.microsoft.com/typography/otspec/otff.htm#offsetTable # We're ignoring searchRange, entrySelector, and rangeShift here, but # skipping past them to get to the table information. @scaler_type, table_count = io.read(12).unpack('Nn') @tables = {} table_count.times do tag, checksum, offset, length = io.read(16).unpack('a4N*') @tables[tag] = { tag: tag, checksum: checksum, offset: offset, length: length, } end end ``` -------------------------------- ### GET #each Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/OneBasedArray Iterate over elements in the array. ```APIDOC ## GET #each ### Description Iterates over each element in the array, yielding to the provided block. ### Parameters #### Yield Parameters - **element** (any) - The current element being iterated. ``` -------------------------------- ### POST /TTFunk/Placeholder/initialize Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Placeholder%3Ainitialize Initializes a new instance of the Placeholder class. Note that this is part of a private API and should be used with caution. ```APIDOC ## POST /TTFunk/Placeholder/initialize ### Description Creates a new instance of a Placeholder object used within the TTFunk library. ### Method POST ### Parameters #### Request Body - **name** (Symbol) - Required - The name of the placeholder. - **length** (Integer) - Optional - The length of the placeholder (defaults to 1). ### Response #### Success Response (200) - **Placeholder** (Object) - A new instance of the Placeholder class. ``` -------------------------------- ### Constructor: initialize Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/SubsetCollection Initializes a new instance of SubsetCollection with the original font file. ```APIDOC ## initialize(original) ### Description Returns a new instance of SubsetCollection. ### Parameters #### Request Body - **original** (TTFunk::File) - Required - The original font file object. ``` -------------------------------- ### GET #[] Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/Dict Retrieves a dictionary value by its operator. ```APIDOC ## GET #[] ### Description Get dict value by operator. ### Parameters #### Path Parameters - **operator** (Integer) - Required - The operator key to retrieve. ### Response - **Returns** (Array) - The value associated with the operator. ``` -------------------------------- ### Constructor: initialize Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/Charstring Creates a new instance of the Charstring class. ```APIDOC ## Constructor: initialize ### Description Creates a new instance of Charstring with the provided glyph ID and dictionary data. ### Parameters #### Path Parameters - **glyph_id** (Integer) - Required - The ID of the glyph. - **top_dict** (TTFunk::Table::Cff::TopDict) - Required - The top dictionary. - **font_dict** (TTFunk::Table::Cff::FontDict) - Required - The font dictionary. - **raw** (String) - Required - The raw charstring data. ``` -------------------------------- ### GET #unicode? Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/Base Checks if the subset is Unicode-based. ```APIDOC ## GET #unicode? ### Description Checks if this is a Unicode-based subset. Note: This method is part of a private API. ### Response #### Success Response (200) - **Boolean** - Returns true if Unicode-based, false otherwise. ``` -------------------------------- ### GET #to_ary Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/OneBasedArray Convert to native array. ```APIDOC ## GET #to_ary ### Description Converts the OneBasedArray into a native Ruby Array. ### Response - **Array** - The underlying array entries. ``` -------------------------------- ### Constructor: initialize Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Glyf/Compound Creates a new instance of a Compound glyph by parsing its binary representation. ```APIDOC ## Constructor: initialize ### Description Initializes a new Compound glyph instance, parsing the provided binary data to extract bounding box information and component glyph IDs. ### Parameters - **id** (Integer) - Required - The glyph ID. - **raw** (String) - Required - The binary serialization of the glyph. ``` -------------------------------- ### TTFunk::Directory#initialize Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Directory%3Ainitialize Initializes a new Directory instance by reading the font file's offset table from the provided IO object. ```APIDOC ## initialize(io, offset = 0) ### Description Creates a new instance of the Directory class. It reads the font file's offset table starting at the specified offset to identify the tables contained within the font. ### Method Constructor (Ruby) ### Parameters #### Path Parameters - **io** (IO) - Required - The IO object representing the font file. - **offset** (Integer) - Optional - The byte offset in the IO object where the directory begins. Defaults to 0. ### Response - **Directory** (Object) - A new instance of the Directory class containing the parsed table information. ``` -------------------------------- ### GET #size Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/OneBasedArray Retrieve the number of elements. ```APIDOC ## GET #size ### Description Returns the total number of elements in the array. ### Response - **Integer** - The count of elements. ``` -------------------------------- ### POST /TTFunk/Min/initialize Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Min%3Ainitialize Initializes a new instance of the TTFunk::Min class, which is used for aggregate calculations. ```APIDOC ## POST /TTFunk/Min/initialize ### Description Creates a new instance of the Min class. This is typically used within the context of aggregate operations on font data. ### Method POST ### Endpoint /TTFunk/Min/initialize ### Parameters #### Request Body - **init_value** (Comparable) - Optional - The initial value to set for the Min instance. ``` -------------------------------- ### GET #[] Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/OneBasedArray Access an element by its one-based index. ```APIDOC ## GET #[] ### Description Accesses an element at the specified one-based index. Raises an IndexError if the index is zero. ### Parameters #### Path Parameters - **idx** (Integer) - Required - The one-based index of the element to retrieve. ``` -------------------------------- ### GET #version Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Sbix Retrieves the version of the sbix table. ```APIDOC ## GET #version ### Description Returns the version number of the sbix table. ### Method GET ### Response - **Returns** (Integer) - The table version. ``` -------------------------------- ### GET #to_unicode_map Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/Base Retrieves the Unicode mapping for the subset. ```APIDOC ## GET #to_unicode_map ### Description Gets a mapping from this subset to Unicode. Note: This method is part of a private API. ### Response #### Success Response (200) - **Hash{Integer => Integer}** - Unicode mapping. ``` -------------------------------- ### POST /TTFunk/ResourceFile.open Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/ResourceFile.open Opens a resource file at the specified path and yields a TTFunk::ResourceFile object to the provided block. ```APIDOC ## POST /TTFunk/ResourceFile.open ### Description Opens a resource file for reading. The method takes a path to the file and yields a TTFunk::ResourceFile instance to a block, ensuring the file is handled correctly. ### Method POST ### Parameters #### Path Parameters - **path** (String, Pathname) - Required - The file system path to the resource file. ### Request Example TTFunk::ResourceFile.open('path/to/font.ttf') do |resource_file| # process resource_file end ### Response #### Success Response (200) - **result** (any) - The result of the executed block. ``` -------------------------------- ### GET #strikes Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Sbix Retrieves the strikes array from the sbix table. ```APIDOC ## GET #strikes ### Description Returns the strikes associated with the sbix table. ### Method GET ### Response - **Returns** (Array) - An array of hashes containing strike information. ``` -------------------------------- ### Initialize FontDict Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/FontDict Creates a new instance of FontDict. ```APIDOC ## initialize(top_dict, file, offset, length = nil) ### Description Returns a new instance of FontDict. ### Parameters #### Path Parameters - **top_dict** (TTFunk::Table::Cff::TopDict) - Required - The top dictionary. - **file** (TTFunk::File) - Required - The font file object. - **offset** (Integer) - Required - The offset in the file. - **length** (Integer) - Optional - The length of the dictionary (defaults to nil). ``` -------------------------------- ### TTFunk::Collection#initialize Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Collection%3Ainitialize Initializes a new TTFunk::Collection instance from an IO object. ```APIDOC ## TTFunk::Collection#initialize ### Description Initializes a new instance of Collection. ### Method POST ### Endpoint /websites/rubydoc_info_gems_ttfunk ### Parameters #### Path Parameters - **io** (IO) - Required - An IO object that responds to `#read` and `#rewind`. ### Request Body ```json { "io": "" } ``` ### Response #### Success Response (200) - **Collection** (Object) - A new instance of the Collection class. #### Response Example ```json { "message": "Collection initialized successfully" } ``` ### Error Handling - **ArgumentError**: Raised if the provided `io` object does not start with the 'ttcf' tag. ``` -------------------------------- ### GET #[] Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cmap/Format12 Retrieves the glyph ID for a given character code. ```APIDOC ## #[](code) ### Description Get glyph ID for character code. ### Parameters #### Path Parameters - **code** (Integer) - Required - Character code. ### Response #### Success Response (200) - **glyph_id** (Integer) - The glyph ID. ``` -------------------------------- ### Initialize Windows1252 Subset Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/Windows1252%3Ainitialize Constructor for creating a new Windows1252 subset instance. Requires an original TTFunk::File object as an argument. ```ruby # File 'lib/ttfunk/subset/windows_1252.rb', line 12 def initialize(original) super(original, 1252, Encoding::CP1252) end ``` -------------------------------- ### Initialize TTFunk::Table::Glyf::Simple Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Glyf/Simple%3Ainitialize Initializes a new instance of the Simple class by parsing raw binary data from a StringIO object. ```ruby def initialize(id, raw) @id = id @raw = raw io = StringIO.new(raw) @number_of_contours, @x_min, @y_min, @x_max, @y_max = io.read(10).unpack('n*').map { |i| BinUtils.twos_comp_to_int(i, bit_width: 16) } @end_points_of_contours = io.read(number_of_contours * 2).unpack('n*') @instruction_length = io.read(2).unpack1('n') @instructions = io.read(instruction_length).unpack('C*') end ``` -------------------------------- ### Get Sum Value Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Sum Retrieves the current accumulated value. ```APIDOC ## Method: value ### Description Returns the current accumulated value. ### Response - **value** (#+) - The current sum. ``` -------------------------------- ### TTFunk::Table::Glyf::PathBased#initialize Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Glyf/PathBased%3Ainitialize Initializes a new instance of TTFunk::Table::Glyf::PathBased. ```APIDOC ## TTFunk::Table::Glyf::PathBased#initialize ### Description Returns a new instance of PathBased. ### Method initialize ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) PathBased #### Response Example None ### Source Code ```ruby def initialize(path, horizontal_metrics) @path = path @horizontal_metrics = horizontal_metrics @x_min = 0 @y_min = 0 @x_max = horizontal_metrics.advance_width @y_max = 0 path.commands.each do |command| cmd, x, y = command next if cmd == :close @x_min = x if x < @x_min @x_max = x if x > @x_max @y_min = y if y < @y_min @y_max = y if y > @y_max end @left_side_bearing = horizontal_metrics.left_side_bearing @right_side_bearing = horizontal_metrics.advance_width - @left_side_bearing - (@x_max - @x_min) end ``` ``` -------------------------------- ### GET #glyphs Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/Base Retrieves the glyphs present in the current subset. ```APIDOC ## GET #glyphs ### Description Retrieves the glyphs in this subset. Note: This method is part of a private API. ### Response #### Success Response (200) - **Hash{Integer => TTFunk::Table::Glyf::Simple, TTFunk::Table::Glyf::Compound}** - Returns glyphs if original is a TrueType font. - **Hash{Integer => TTFunk::Table::Cff::Charstring}** - Returns glyphs if original is a CFF-based OpenType font. ``` -------------------------------- ### Get Glyph Instructions Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Glyf/Simple%3Ainstructions Retrieves the instruction byte code for a simple glyph. This is a read-only property. ```ruby def instructions @instructions end ``` -------------------------------- ### Initialize TTFunk Resource File Parser Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/ResourceFile%3Ainitialize Initializes the parser by reading header information, map offsets, and then iterating through type lists to build an internal map of font data. Requires an IO object for reading. ```ruby def initialize(io) @io = io data_offset, map_offset, map_length = @io.read(16).unpack('NNx4N') @map = {} # skip header copy, next map handle, file reference, and attrs @io.pos = map_offset + 24 type_list_offset, name_list_offset = @io.read(4).unpack('n*') type_list_offset += map_offset name_list_offset += map_offset @io.pos = type_list_offset max_index = @io.read(2).unpack1('n') 0.upto(max_index) do type, max_type_index, ref_list_offset = @io.read(8).unpack('A4nn') @map[type] = { list: [], named: {} } parse_from(type_list_offset + ref_list_offset) do 0.upto(max_type_index) do id, name_ofs, attr = @io.read(5).unpack('nnC') data_ofs = @io.read(3) data_ofs = data_offset + [0, data_ofs].pack('CA*').unpack1('N') handle = @io.read(4).unpack1('N') entry = { id: id, attributes: attr, offset: data_ofs, handle: handle, } if name_list_offset + name_ofs < map_offset + map_length parse_from(name_ofs + name_list_offset) do len = @io.read(1).unpack1('C') entry[:name] = @io.read(len) end end @map[type][:list] << entry @map[type][:named][entry[:name]] = entry if entry[:name] end end end end ``` -------------------------------- ### GET #collect_glyphs Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/Base Retrieves glyphs by their IDs from the original font. ```APIDOC ## GET #collect_glyphs ### Description Get glyphs by their IDs in the original font. ### Parameters #### Request Body - **glyph_ids** (Array) - Required - List of glyph IDs to collect ### Response #### Success Response (200) - **result** (Hash) - Returns a Hash of glyphs (TTFunk::Table::Glyf::Simple/Compound or TTFunk::Table::Cff::Charstring) ``` -------------------------------- ### GET /ttfunk/table/post/italic_angle Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Post%3Aitalic_angle Retrieves the italic angle of a font from the PostScript table. ```APIDOC ## GET /ttfunk/table/post/italic_angle ### Description Returns the italic angle in counter-clockwise degrees from the vertical for the specified font table. ### Method GET ### Endpoint /ttfunk/table/post/italic_angle ### Response #### Success Response (200) - **italic_angle** (Integer) - Italic angle in counter-clockwise degrees from the vertical. ``` -------------------------------- ### Initialize Table Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table Constructor for creating a new Table instance, which attempts to locate the table in the provided file directory. ```ruby # File 'lib/ttfunk/table.rb', line 23 def initialize(file) @file = file @offset = nil @length = nil info = file.directory_info(tag) if info @offset = info[:offset] @length = info[:length] parse_from(@offset) { parse! } end end ``` -------------------------------- ### GET /ttfunk/table/kern/format0/vertical Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Kern/Format0%3Avertical%3F Checks if the current kerning table format is vertical. ```APIDOC ## GET /ttfunk/table/kern/format0/vertical ### Description Determines whether the kerning table format 0 is configured for vertical kerning. ### Method GET ### Endpoint /ttfunk/table/kern/format0/vertical ### Response #### Success Response (200) - **is_vertical** (Boolean) - Returns true if vertical kerning is enabled, false otherwise. ``` -------------------------------- ### Initialize TTFunk::Table::Simple Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Simple Constructor for creating a new Simple table instance, requiring the associated file and a table tag. ```ruby def initialize(file, tag) @tag = tag super(file) end ``` -------------------------------- ### Initialize TTFunk::Directory Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Directory Initializes a new instance of the Directory class by reading the SFNT table directory from the provided IO object. ```APIDOC ## Constructor: initialize ### Description Creates a new instance of Directory by reading the SFNT table directory from an IO stream at a specified offset. ### Method Constructor ### Parameters #### Path Parameters - **io** (IO) - Required - The IO object containing the font data. - **offset** (Integer) - Optional - The byte offset where the directory begins (default: 0). ### Response - **Directory** (Object) - A new instance of the TTFunk::Directory class. ``` -------------------------------- ### GET /ttfunk/table/cmap/subtable/format Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cmap/Subtable%3Aformat Retrieves the encoding format of a specific Cmap subtable. ```APIDOC ## GET /ttfunk/table/cmap/subtable/format ### Description Returns the record encoding format for the Cmap subtable. ### Method GET ### Endpoint /ttfunk/table/cmap/subtable/format ### Response #### Success Response (200) - **format** (Integer) - The encoding format of the subtable. ``` -------------------------------- ### GET #subr_index Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/PrivateDict Retrieves the subroutine index associated with the private dictionary. ```APIDOC ## GET #subr_index ### Description Returns the SubrIndex object if defined, otherwise returns nil. ### Method GET ### Response - **TTFunk::Table::Cff::SubrIndex | nil** - The subroutine index or nil. ``` -------------------------------- ### TTFunk::ResourceFile#initialize Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/ResourceFile%3Ainitialize Initializes a new instance of the ResourceFile class. This class is used for reading resources from font files. ```APIDOC ## TTFunk::ResourceFile#initialize ### Description Returns a new instance of ResourceFile. ### Method initialize ### Endpoint N/A (Class constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ruby # Assuming 'io' is an IO object representing a font file resource_file = TTFunk::ResourceFile.new(io) ``` ### Response #### Success Response (200) N/A (Constructor returns an object) #### Response Example ```ruby # Returns an instance of TTFunk::ResourceFile # Example: # ``` ``` -------------------------------- ### Initialize NameString Instance Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Name/NameString Constructor for creating a new NameString object with associated metadata. ```ruby def initialize(text, platform_id, encoding_id, language_id) super(text) @platform_id = platform_id @encoding_id = encoding_id @language_id = language_id end ``` -------------------------------- ### Get Glyph Representation Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/Charstring Returns a TrueType-compatible glyph representation of the charstring. ```ruby def glyph @glyph ||= begin horizontal_metrics = @top_dict.file.horizontal_metrics.for(glyph_id) Glyf::PathBased.new(path, horizontal_metrics) end end ``` -------------------------------- ### GET /subset_collection/index Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/SubsetCollection%3A%5B%5D Retrieves a specific font subset from the collection by its index. ```APIDOC ## GET /subset_collection/index ### Description Retrieves a font subset object from the collection based on the provided index. ### Method GET ### Endpoint TTFunk::SubsetCollection#[] ### Parameters #### Path Parameters - **subset** (Integer) - Required - The index of the subset to retrieve. ### Response #### Success Response (200) - **result** (TTFunk::Subset::Unicode, TTFunk::Subset::Unicode8Bit, TTFunk::Subset::MacRoman, TTFunk::Subset::Windows1252) - The requested subset object. ``` -------------------------------- ### Constructor: TTFunk::Subset::MacRoman.new Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/MacRoman Initializes a new instance of the MacRoman subset class using an original TTFunk::File object. ```APIDOC ## Constructor: TTFunk::Subset::MacRoman.new ### Description Creates a new instance of the MacRoman subset class, which is used to handle font subsetting for the Mac OS Roman encoding. ### Parameters #### Request Body - **original** (TTFunk::File) - Required - The original font file object to be subsetted. ### Request Example ```ruby subset = TTFunk::Subset::MacRoman.new(original_font_file) ``` ### Response #### Success Response (200) - **instance** (TTFunk::Subset::MacRoman) - A new instance of the MacRoman subset class. ``` -------------------------------- ### TTFunk Glyf Simple Instance Methods Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Glyf/Simple Documentation for the instance methods of the TTFunk Glyf Simple class, including `compound?`, `end_point_of_last_contour`, and `recode`. ```APIDOC ## Instance Methods ### `compound?` - **Description**: Checks if this glyph is a compound glyph. - **Returns**: `false` (Simple glyphs are never compound). ### `end_point_of_last_contour` - **Description**: Calculates and returns the end point index of the last contour. - **Returns**: `Integer` - The index of the last point of the last contour plus one. ### `recode(_mapping)` - **Description**: Recodes the glyph. This method is primarily for API compatibility and does not modify the glyph data for simple glyphs. - **Parameters**: - `_mapping` (any) - Unused parameter, present for API compatibility. - **Returns**: `String` - The original raw binary data of the glyph. ``` -------------------------------- ### GET #unicode_cmap Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/Base Retrieves the first Unicode cmap from the original font. ```APIDOC ## GET #unicode_cmap ### Description Gets the first Unicode cmap from the original font. Note: This method is part of a private API. ### Response #### Success Response (200) - **TTFunk::Table::Cmap::Subtable** - The Unicode cmap subtable. ``` -------------------------------- ### GET #microsoft_symbol? Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/Base Checks if the subset uses Microsoft Symbolic encoding. ```APIDOC ## GET #microsoft_symbol? ### Description Determines if this subset uses Microsoft Symbolic encoding. Note: This method is part of a private API. ### Response #### Success Response (200) - **Boolean** - Returns true if Microsoft Symbolic encoding is used, false otherwise. ``` -------------------------------- ### Initialize Windows1252 Subset Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/Windows1252 Constructs a new instance of the Windows1252 class. It requires the original TTFunk::File object and sets the code page to 1252 and encoding to CP1252. ```ruby def initialize(original) super(original, 1252, Encoding::CP1252) end ``` -------------------------------- ### GET /TTFunk/Subset/Unicode/new_cmap_table Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/Unicode%3Anew_cmap_table Retrieves the cmap table for a specific Unicode subset. ```APIDOC ## GET /TTFunk/Subset/Unicode/new_cmap_table ### Description Generates or retrieves the cmap table for the current Unicode subset. ### Method GET ### Endpoint TTFunk::Subset::Unicode#new_cmap_table ### Response #### Success Response (200) - **cmap_table** (TTFunk::Table::Cmap) - The encoded cmap table for the subset. ``` -------------------------------- ### POST /TTFunk/Subset/MacRoman/initialize Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/MacRoman%3Ainitialize Initializes a new instance of the MacRoman subsetting class for a given TrueType font file. ```APIDOC ## POST /TTFunk/Subset/MacRoman/initialize ### Description Creates a new instance of the MacRoman subsetting class, which is used to handle MacRoman encoding for font subsetting. ### Method POST ### Parameters #### Request Body - **original** (TTFunk::File) - Required - The original font file object to be subsetted. ### Response #### Success Response (200) - **MacRoman** (Object) - A new instance of the MacRoman subsetting class. ``` -------------------------------- ### Initialize FontIndex Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/FontIndex%3Ainitialize Creates a new instance of FontIndex. Requires a top_dict, file, offset, and optional length. ```ruby def initialize(top_dict, file, offset, length = nil) super(file, offset, length) @top_dict = top_dict end ``` -------------------------------- ### Get size of OneBasedArray Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/OneBasedArray Returns the number of elements contained in the array. ```ruby def size entries.size end ``` -------------------------------- ### Initialize TTFunk::Table::Cff::Path Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/Path%3Ainitialize Initializes a new instance of the Path class, setting up internal command and contour count. ```ruby def initialize @commands = [] @number_of_contours = 0 end ``` -------------------------------- ### GET /ttfunk/one_based_array/element Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/OneBasedArray Retrieves an element from the OneBasedArray using a 1-based index. ```APIDOC ## Method: [] ### Description Get an element by its 1-based index. ### Parameters - **idx** (Integer) - Required - The 1-based index of the element to retrieve. ### Response - **element** (any) - The element at the specified index. ### Errors - **IndexError** - Raised if the index provided is 0. ``` -------------------------------- ### TTFunk::Subset::Base#initialize Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/Base%3Ainitialize Initializes a new instance of the Base class. This is a private API method. ```APIDOC ## TTFunk::Subset::Base#initialize ### Description Initializes a new instance of the Base class. ### Method initialize ### Endpoint N/A (Instance method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (Instance) - **Base** (TTFunk::Subset::Base) - A new instance of the Base class. #### Response Example None ### Notes This method is part of a private API and should be avoided if possible. ``` -------------------------------- ### GET #all_bitmap_data_for Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Sbix Retrieves all bitmap data associated with a specific glyph ID. ```APIDOC ## GET #all_bitmap_data_for ### Description Retrieves all bitmap data for a given glyph ID. ### Parameters #### Path Parameters - **glyph_id** (Integer) - Required - The ID of the glyph to retrieve data for. ### Response - **Array** - An array of BitmapData objects. ``` -------------------------------- ### Initialize TTFunk Table Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table%3Ainitialize Initializes a new instance of a TTFunk table by reading directory information from the provided file. ```APIDOC ## [METHOD] TTFunk::Table#initialize ### Description Returns a new instance of a Table, parsing its offset and length from the provided file's directory information. ### Method initialize ### Parameters #### Path Parameters - **file** (TTFunk::File) - Required - The file object containing the font directory information. ### Response - **Table** (Object) - A new instance of the Table class. ``` -------------------------------- ### GET /TTFunk/Table/Post/fixed_pitch? Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Post%3Afixed_pitch%3F Checks if the font is monospaced by inspecting the post table properties. ```APIDOC ## GET /TTFunk/Table/Post/fixed_pitch? ### Description Determines whether the font is monospaced (fixed pitch) based on the post table data. ### Method GET ### Response #### Success Response (200) - **is_fixed_pitch** (Boolean) - Returns true if the font is monospaced, false otherwise. ``` -------------------------------- ### Initialize SignatureRecord Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Dsig/SignatureRecord%3Ainitialize Creates a new instance of SignatureRecord with the specified format, length, offset, and signature data. ```ruby def initialize(format, length, offset, signature) @format = format @length = length @offset = offset @signature = signature end ``` -------------------------------- ### GET glyph_for Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Post/Format40 Retrieves the glyph name associated with a specific character code. ```APIDOC ## GET glyph_for ### Description Get the glyph name for a given character code using the Format 4.0 PostScript table mapping. ### Parameters #### Query Parameters - **code** (Integer) - Required - The character code to look up. ### Response #### Success Response (200) - **glyph_name** (String) - The name of the glyph or 0xFFFF if not found. ``` -------------------------------- ### GET /ttfunk/table/os2/x_height Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/OS2%3Ax_height Retrieves the x-height value from the OS/2 table of a font file. ```APIDOC ## GET /ttfunk/table/os2/x_height ### Description Returns the distance between the baseline and the approximate height of non-ascending lowercase letters as defined in the OS/2 table. ### Method GET ### Endpoint TTFunk::Table::OS2#x_height ### Response #### Success Response (200) - **x_height** (Integer) - The distance between the baseline and the approximate height of non-ascending lowercase letters. ``` -------------------------------- ### Open a resource file with TTFunk::ResourceFile.open Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/ResourceFile.open Opens a file in binary mode and yields the resulting ResourceFile object to the block. The file is automatically closed after the block execution. ```ruby # File 'lib/ttfunk/resource_file.rb', line 16 def self.open(path) ::File.open(path, 'rb') { |io| file = new(io) yield(file) } end ``` -------------------------------- ### TTFunk::Table::Cff::OneBasedIndex#initialize Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/OneBasedIndex%3Ainitialize Initializes a new instance of TTFunk::Table::Cff::OneBasedIndex. All arguments are passed to the base index. ```APIDOC ## TTFunk::Table::Cff::OneBasedIndex#initialize ### Description Returns a new instance of OneBasedIndex. ### Method initialize ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Returns a new instance of OneBasedIndex. #### Response Example None ### Source Code ```ruby # File 'lib/ttfunk/table/cff/one_based_index.rb', line 25 def initialize(*args) @base_index = Index.new(*args) end ``` ``` -------------------------------- ### GET #platform_id Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Name/NameString Retrieves the platform ID associated with the name table entry. ```APIDOC ## GET #platform_id ### Description Returns the platform ID for the current name table entry. ### Method GET ### Response - **platform_id** (Integer) - The unique identifier for the platform. ``` -------------------------------- ### GET #language_id Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Name/NameString Retrieves the language ID associated with the name table entry. ```APIDOC ## GET #language_id ### Description Returns the language ID for the current name table entry. ### Method GET ### Response - **language_id** (Integer) - The unique identifier for the language. ``` -------------------------------- ### Initialize NameString Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Name/NameString%3Ainitialize Creates a new instance of NameString with the specified text and font metadata identifiers. ```ruby # File 'lib/ttfunk/table/name.rb', line 28 def initialize(text, platform_id, encoding_id, language_id) super(text) @platform_id = platform_id @encoding_id = encoding_id @language_id = language_id end ``` -------------------------------- ### Initialize TTFunk::Subset::CodePage Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/CodePage%3Ainitialize Initializes a new instance of CodePage. Requires the original TTFunk::File object, a code page integer, and an encoding. It sets up internal caches and ensures the space character is used. ```ruby def initialize(original, code_page, encoding) super(original) @code_page = code_page @encoding = encoding @subset = Array.new(256) @from_unicode_cache = {} use(space_char_code) end ``` -------------------------------- ### GET #encoding_id Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Name/NameString Retrieves the platform-specific encoding ID associated with the NameString instance. ```APIDOC ## GET #encoding_id ### Description Returns the platform-specific encoding ID for the name record. ### Response - **encoding_id** (Integer) - The encoding ID. ``` -------------------------------- ### GET /ttfunk/table/loca/offsets Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Loca%3Aoffsets Retrieves the glyph offsets from the Loca table of a font file. ```APIDOC ## GET /ttfunk/table/loca/offsets ### Description Retrieves the glyph offsets from the Loca table of a font file. ### Method GET ### Endpoint /ttfunk/table/loca/offsets ### Response #### Success Response (200) - **offsets** (Array) - An array of integers representing the glyph offsets. ``` -------------------------------- ### Initialize SubsetCollection Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/SubsetCollection%3Ainitialize Initializes a new SubsetCollection instance with an original TTFunk::File object. It sets up an initial subset using MacRoman encoding. ```ruby def initialize(original) @original = original @subsets = [Subset.for(@original, :mac_roman)] end ``` -------------------------------- ### Initialize Placeholder Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Placeholder%3Ainitialize Initializes a new Placeholder instance. This method is part of a private API and should be used with caution. ```Ruby def initialize(name, length: 1) @name = name @length = length end ``` -------------------------------- ### Get Left Side Bearing Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Glyf/PathBased Returns the left side bearing of the glyph. ```ruby def left_side_bearing @left_side_bearing end ``` -------------------------------- ### Method: render Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/Charstring Renders the charstring path at a specific size and position. ```APIDOC ## Method: render ### Description Get path representation of this charstring at the specified font size and coordinates. ### Parameters #### Query Parameters - **x** (Integer, Float) - Optional - New horizontal position (defaults to 0). - **y** (Integer, Float) - Optional - New vertical position (defaults to 0). - **font_size** (Integer, Float) - Optional - Font size (defaults to 72). ### Response - **Return Value** (TTFunk::Table::Cff::Path) - The rendered path object. ``` -------------------------------- ### GET /TTFunk/Table/Cmap/Format06/code_map Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cmap/Format06%3Acode_map Retrieves the code map for a Cmap Format 06 table. ```APIDOC ## GET /TTFunk/Table/Cmap/Format06/code_map ### Description Retrieves the code map for a Cmap Format 06 table, which maps character codes to glyph indices. ### Method GET ### Endpoint TTFunk::Table::Cmap::Format06#code_map ### Response #### Success Response (200) - **code_map** (Hash{Integer => Integer}) - A hash mapping character codes to glyph indices. ``` -------------------------------- ### Initialize PathBased Instance Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Glyf/PathBased%3Ainitialize Constructs a new PathBased object by calculating bounding box coordinates from provided path commands and horizontal metrics. ```ruby def initialize(path, horizontal_metrics) @path = path @horizontal_metrics = horizontal_metrics @x_min = 0 @y_min = 0 @x_max = horizontal_metrics.advance_width @y_max = 0 path.commands.each do |command| cmd, x, y = command next if cmd == :close @x_min = x if x < @x_min @x_max = x if x > @x_max @y_min = y if y < @y_min @y_max = y if y > @y_max end @left_side_bearing = horizontal_metrics.left_side_bearing @right_side_bearing = horizontal_metrics.advance_width - @left_side_bearing - (@x_max - @x_min) end ``` -------------------------------- ### GET #nominal_width_x Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/PrivateDict Retrieves the nominal width X value from the private dictionary. ```APIDOC ## GET #nominal_width_x ### Description Returns the nominal width X value. If not explicitly set, returns the default nominal constant. ### Method GET ### Response - **Integer** - The nominal width X value. ``` -------------------------------- ### GET #default_width_x Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/PrivateDict Retrieves the default width X value from the private dictionary. ```APIDOC ## GET #default_width_x ### Description Returns the default width X value. If not explicitly set, returns the default constant. ### Method GET ### Response - **Integer** - The default width X value. ``` -------------------------------- ### Initialize TTFunk::Table::Cmap::Subtable Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cmap/Subtable%3Ainitialize Initializes a new subtable instance by reading the platform, encoding, and offset, then extending the object with the appropriate format module. ```ruby def initialize(file, table_start) @file = file @platform_id, @encoding_id, @offset = read(8, 'nnN') @offset += table_start parse_from(@offset) do @format = read(2, 'n').first case @format when 0 then extend(TTFunk::Table::Cmap::Format00) when 4 then extend(TTFunk::Table::Cmap::Format04) when 6 then extend(TTFunk::Table::Cmap::Format06) when 10 then extend(TTFunk::Table::Cmap::Format10) when 12 then extend(TTFunk::Table::Cmap::Format12) end parse_cmap! end end ``` -------------------------------- ### Initialize TTFunk::Table Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table%3Ainitialize Initializes a new TTFunk::Table instance. It associates the table with a TTFunk::File and attempts to parse the table's data from the file if directory information is available. Requires the TTFunk::File object as an argument. ```ruby def initialize(file) @file = file @offset = nil @length = nil info = file.directory_info(tag) if info @offset = info[:offset] @length = info[:length] parse_from(@offset) { parse! } end end ``` -------------------------------- ### GET /ttfunk/table/cff/top_dict/cff_offset Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/TopDict%3Acff_offset Retrieves the offset of the CFF table within the font file. ```APIDOC ## GET /ttfunk/table/cff/top_dict/cff_offset ### Description Returns the offset of the CFF table in the file. ### Method GET ### Response #### Success Response (200) - **offset** (Integer) - The offset of the CFF table in the file. ``` -------------------------------- ### Get number of items Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Cff/Index Returns the total number of items present in the index. ```ruby def items_count items.length end ``` -------------------------------- ### Initialize TTFunk::Table::Simple Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Simple%3Ainitialize Initializes a new instance of a simple font table within the TTFunk library. ```APIDOC ## Initialize TTFunk::Table::Simple ### Description Creates a new instance of a simple font table, associating it with a specific file and tag. ### Method Constructor ### Parameters #### Path Parameters - **file** (TTFunk::File) - Required - The font file object. - **tag** (String) - Required - The table tag identifier. ``` -------------------------------- ### Get character code Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/Unicode8Bit Retrieves the character code for a given Unicode codepoint. ```ruby def from_unicode(character) @unicodes[character] end ``` -------------------------------- ### Basic TTFunk Usage Source: https://www.rubydoc.info/gems/ttfunk/file/README.md Demonstrates basic usage of the TTFunk library to open a font file and retrieve font metadata such as name, ascent, and descent. Ensure the font file path is correct. ```ruby require 'ttfunk' file = TTFunk::File.open("some/path/myfont.ttf") puts "name : #{file.name.font_name.join(', ')}" puts "ascent : #{file.ascent}" puts "descent : #{file.descent}" ``` -------------------------------- ### GET #encoder_klass Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Subset/Base Determines the appropriate encoder class based on the font type. ```APIDOC ## GET #encoder_klass ### Description Returns the encoder class (TTFEncoder or OTFEncoder) for this subset. ### Response #### Success Response (200) - **encoder** (Class) - Returns TTFunk::TTFEncoder or TTFunk::OTFEncoder ``` -------------------------------- ### TTFunk::Table::Kern::Format0#initialize Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Table/Kern/Format0%3Ainitialize Initializes a new instance of the Format0 class, parsing kern pair data. ```APIDOC ## TTFunk::Table::Kern::Format0#initialize ### Description Returns a new instance of Format0. ### Method initialize ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ### Source Code ```ruby # File 'lib/ttfunk/table/kern/format0.rb', line 21 def initialize(attributes = {}) @attributes = attributes num_pairs, *pairs = attributes.delete(:data).unpack('nx6n*') @pairs = {} num_pairs.times do |i| # sanity check, in case there's a bad length somewhere break if (i * 3) + 2 > pairs.length left = pairs[i * 3] right = pairs[(i * 3) + 1] value = to_signed(pairs[(i * 3) + 2]) @pairs[[left, right]] = value end end ``` ``` -------------------------------- ### Get Current Value Source: https://www.rubydoc.info/gems/ttfunk/TTFunk/Max Retrieves the current maximum value stored in the instance. ```APIDOC ## Method: value ### Description Returns the current stored value. ### Response #### Success Response (200) - **value** (Comparable) - The current maximum value. ```