### Load SVG Icons from Directory with SVGIconsDirStream Source: https://context7.com/nfroidure/svgicons2svgfont/llms.txt This example shows how to use SVGIconsDirStream to load SVG icons from a directory or an array of files. It automatically extracts metadata from filenames for unicode mapping and glyph names. The stream can then be piped to SVGIcons2SVGFontStream for font generation and subsequently to a file write stream. ```javascript import { SVGIconsDirStream, SVGIcons2SVGFontStream } from 'svgicons2svgfont'; import { createWriteStream } from 'node:fs'; // Load from a directory const iconsDirStream = new SVGIconsDirStream('path/to/icons', { startUnicode: 0xEA01, prependUnicode: false }); // Or load from an array of files const iconsArrayStream = new SVGIconsDirStream([ 'icons/account.svg', 'icons/search.svg', 'icons/menu.svg' ], { startUnicode: 0xE001 }); // Pipe through font generator to file iconsDirStream .pipe(new SVGIcons2SVGFontStream({ fontName: 'my-app-icons', fontHeight: 1000, normalize: true, centerHorizontally: true })) .pipe(createWriteStream('dist/fonts/my-app-icons.svg')) .on('finish', () => console.log('Font generated!')); // Filename conventions for unicode mapping: // uE001-home.svg -> unicode: E001, name: home // uE002,uE003-star.svg -> unicode: E002 and E003, name: star // uE001uE002-combo.svg -> ligature for E001+E002, name: combo // search.svg -> auto-assigned unicode, name: search ``` -------------------------------- ### Generate SVG Fonts in Memory with Streams Source: https://context7.com/nfroidure/svgicons2svgfont/llms.txt This example demonstrates how to use Node.js streams to generate an SVG font directly into a memory buffer. This approach is ideal for build pipelines where intermediate file creation is undesirable. ```javascript import { SVGIcons2SVGFontStream, SVGIconsDirStream } from 'svgicons2svgfont'; import { Writable } from 'node:stream'; async function generateFontToMemory(iconsDir, options) { return new Promise((resolve, reject) => { const chunks = []; const collector = new Writable({ write(chunk, encoding, callback) { chunks.push(chunk); callback(); }, final(callback) { resolve(Buffer.concat(chunks).toString('utf8')); callback(); } }); const fontStream = new SVGIcons2SVGFontStream({ fontName: options.fontName }); fontStream.on('error', reject); new SVGIconsDirStream(iconsDir).pipe(fontStream).pipe(collector); }); } ``` -------------------------------- ### Display CLI Help (Shell) Source: https://github.com/nfroidure/svgicons2svgfont/blob/main/README.md This shell command displays the help information for the svgicons2svgfont CLI tool, listing all available options and their descriptions. This is useful for understanding the full range of customization available for generating SVG fonts from the command line. ```shell npx svgicons2svgfont --help ``` -------------------------------- ### Configuration Options Source: https://github.com/nfroidure/svgicons2svgfont/blob/main/README.md Overview of the configuration object used to customize the SVG font generation process. ```APIDOC ## Configuration Options ### Description These options are passed to the svgicons2svgfont generator to control the output font properties and icon processing. ### Parameters - **fixedWidth** (Boolean) - Optional - Creates a monospace font of the width of the largest input icon. Default: false - **centerHorizontally** (Boolean) - Optional - Calculate the bounds of a glyph and center it horizontally. Default: false - **centerVertically** (Boolean) - Optional - Centers the glyphs vertically in the generated font. Default: false - **normalize** (Boolean) - Optional - Normalize icons by scaling them to the height of the highest icon. Default: false - **preserveAspectRatio** (Boolean) - Optional - Scale down glyph if the SVG width is greater than the height. Default: false - **fontHeight** (Number) - Optional - The outputted font height. Default: MAX(icons.height) - **round** (Number) - Optional - Setup SVG path rounding. Default: 10e12 - **descent** (Number) - Optional - The font descent. Default: 0 - **ascent** (Number) - Optional - The font ascent. Default: fontHeight - descent - **metadata** (String) - Optional - The font metadata (e.g., copyright). - **metadataProvider** (Function) - Optional - A function to determine metadata for an icon. Default: internal provider - **log** (Function) - Optional - Custom logging function. Default: console.log ### Request Example { "fixedWidth": true, "normalize": true, "fontHeight": 512, "descent": 64 } ``` -------------------------------- ### Configure Metadata Provider Source: https://github.com/nfroidure/svgicons2svgfont/blob/main/README.md Provide a custom function to determine metadata for each icon. This function receives the icon file path and should return metadata including path, name, unicode codepoints, and a renamed flag via a callback. This allows for custom SVG to codepoint mapping. ```javascript { metadataProvider: (file, cb) => { // Custom logic to determine metadata const metadata = { file: file, name: 'icon-name', unicode: ['\ue001'], renamed: false }; cb(null, metadata); } } ``` -------------------------------- ### new SVGIcons2SVGFontStream(options) Source: https://github.com/nfroidure/svgicons2svgfont/blob/main/README.md Initializes a new stream to process SVG icons into an SVG font. The options object allows configuration of font metadata such as name, ID, style, and weight. ```APIDOC ## new SVGIcons2SVGFontStream(options) ### Description Creates a new readable/writable stream that accepts SVG icon streams and outputs an SVG font file. ### Parameters #### Request Body - **options** (Object) - Required - Configuration for the font generation. - **fontName** (String) - Optional - The font family name (Default: 'iconfont'). - **fontId** (String) - Optional - The font ID (Default: fontName). - **fontStyle** (String) - Optional - The font style. - **fontWeight** (String) - Optional - The font weight. ### Request Example ```javascript const fontStream = new SVGIcons2SVGFontStream({ fontName: 'my-font', fontId: 'my-font-id' }); ``` ### Response #### Success Response (Stream) - **Stream** (ReadableStream) - The resulting SVG font data stream. ``` -------------------------------- ### Automate Icon Font Generation and Conversion with Gulp Source: https://context7.com/nfroidure/svgicons2svgfont/llms.txt This Gulp task reads SVG icons from a directory, streams them into an SVG font file, and subsequently converts the output into TTF, WOFF, and WOFF2 formats. It requires the svgicons2svgfont, svg2ttf, ttf2woff, and ttf2woff2 packages to function. ```javascript import gulp from 'gulp'; import { SVGIcons2SVGFontStream, SVGIconsDirStream } from 'svgicons2svgfont'; import svg2ttf from 'svg2ttf'; import ttf2woff from 'ttf2woff'; import ttf2woff2 from 'ttf2woff2'; import { createWriteStream, readFileSync, writeFileSync } from 'node:fs'; gulp.task('iconfont', async () => { return new Promise((resolve, reject) => { const fontName = 'app-icons'; new SVGIconsDirStream('src/icons/') .pipe(new SVGIcons2SVGFontStream({ fontName, fontHeight: 1000, normalize: true, centerHorizontally: true })) .pipe(createWriteStream(`dist/fonts/${fontName}.svg`)) .on('finish', () => { const svgFont = readFileSync(`dist/fonts/${fontName}.svg`, 'utf8'); const ttf = svg2ttf(svgFont, {}); writeFileSync(`dist/fonts/${fontName}.ttf`, Buffer.from(ttf.buffer)); const ttfBuffer = readFileSync(`dist/fonts/${fontName}.ttf`); const woff = ttf2woff(new Uint8Array(ttfBuffer)); writeFileSync(`dist/fonts/${fontName}.woff`, Buffer.from(woff.buffer)); const woff2 = ttf2woff2(ttfBuffer); writeFileSync(`dist/fonts/${fontName}.woff2`, woff2); console.log('All font formats generated!'); resolve(); }) .on('error', reject); }); }); ``` -------------------------------- ### CLI Alternatives for Font Conversion Source: https://github.com/nfroidure/svgicons2svgfont/blob/main/README.md Combine the CLI interface of svgicons2svgfont with other command-line tools for comprehensive font format conversion. Tools like `svg2ttf`, `ttf2eot`, `ttf2woff`, and `ttf2woff2` can be used sequentially. ```bash svgicons2svgfont --output-svg=icons.svg *.svg svg2ttf icons.svg -o icons.ttf ttf2woff icons.ttf -o icons.woff ``` -------------------------------- ### Configure Logging Source: https://github.com/nfroidure/svgicons2svgfont/blob/main/README.md Customize the logging function used by the tool. By default, it uses `console.log`. Set to an empty function to disable logging entirely. ```javascript { log: (msg) => { console.log(`[svgicons2svgfont] ${msg}`); } // Custom logger } ``` ```javascript { log: () => {} // Disable logging } ``` -------------------------------- ### Integrate with Grunt Source: https://github.com/nfroidure/svgicons2svgfont/blob/main/README.md Use the `grunt-svgicons2svgfont` plugin to integrate svgicons2svgfont into your Grunt build process. This allows for automated icon font generation as part of your Grunt tasks. ```javascript grunt.loadNpmTasks('grunt-svgicons2svgfont'); ``` -------------------------------- ### Create SVG Font from Icons (JavaScript) Source: https://github.com/nfroidure/svgicons2svgfont/blob/main/README.md This JavaScript code snippet demonstrates how to use the SVGIcons2SVGFontStream class to programmatically create an SVG font from multiple SVG icon files. It shows how to pipe the font stream to a write stream and how to define metadata for each glyph, including unicode values and names. It also illustrates how to handle multiple unicode values and ligatures. ```javascript import { SVGIcons2SVGFontStream } from 'svgicons2svgfont'; import { createReadStream, createWriteStream } from 'node:fs'; const fontStream = new SVGIcons2SVGFontStream({ fontName: 'hello', }); // Setting the font destination fontStream .pipe(createWriteStream('fonts/hello.svg')) .on('finish', function () { console.log('Font successfully created!'); }) .on('error', function (err) { console.log(err); }); // Writing glyphs const glyph1 = createReadStream('icons/icon1.svg'); glyph1.metadata = { unicode: ['\uE001\uE002'], name: 'icon1', }; fontStream.write(glyph1); // Multiple unicode values are possible const glyph2 = createReadStream('icons/icon1.svg'); glyph2.metadata = { unicode: ['\uE002', '\uEA02'], name: 'icon2', }; fontStream.write(glyph2); // Either ligatures are available const glyph3 = createReadStream('icons/icon1.svg'); glyph3.metadata = { unicode: ['\uE001\uE002'], name: 'icon1-icon2', }; fontStream.write(glyph3); // Do not forget to end the stream fontStream.end(); ``` -------------------------------- ### Generate SVG Font via CLI (Shell) Source: https://github.com/nfroidure/svgicons2svgfont/blob/main/README.md This shell command demonstrates how to use the svgicons2svgfont CLI tool to convert a directory of SVG icons into an SVG font. It specifies the font name, output file, and the source directory for the icons. It also mentions a convention for naming icon files to customize unicode and icon names. ```shell svgicons2svgfont --fontName=hello -o font/destination/file.svg icons/directory/*.svg ``` -------------------------------- ### Configure Icon Normalization and Aspect Ratio Source: https://github.com/nfroidure/svgicons2svgfont/blob/main/README.md Control how icons are scaled and their aspect ratio is preserved. `normalize` scales icons to the height of the tallest icon. `preserveAspectRatio` is used with `normalize` to scale down glyphs if their SVG width exceeds their height. ```javascript { normalize: true, preserveAspectRatio: true } ``` -------------------------------- ### Generate SVG Fonts via CLI Source: https://context7.com/nfroidure/svgicons2svgfont/llms.txt The command-line interface allows for rapid SVG font generation using glob patterns. It supports extensive configuration options for font metrics, normalization, and metadata injection. ```bash svgicons2svgfont --output fonts/my-icons.svg --fontName "MyIcons" --normalize --startUnicode 0xEA01 icons/**/*.svg ``` -------------------------------- ### Configure Font Height and Descent Source: https://github.com/nfroidure/svgicons2svgfont/blob/main/README.md Set the font height and descent for the generated font. Font height defaults to the height of the highest input icon, while descent can be manually adjusted for baseline alignment. Ascent is automatically computed based on font height and descent. ```javascript { fontHeight: 100, // Example: Set font height to 100 units descent: 10 // Example: Set descent to 10 units } ``` -------------------------------- ### Sort SVG Files with fileSorter Source: https://context7.com/nfroidure/svgicons2svgfont/llms.txt The fileSorter utility ensures that files with existing Unicode prefixes are processed before unprefixed files. This maintains a predictable and consistent order for codepoint assignment during font generation. ```javascript import { fileSorter } from 'svgicons2svgfont'; const files = ['search.svg', 'uE003-menu.svg', 'account.svg', 'uE001-home.svg', 'uE002-settings.svg']; const sortedFiles = files.sort(fileSorter); console.log(sortedFiles); ``` -------------------------------- ### Extract Glyph Metadata with getMetadataService Source: https://context7.com/nfroidure/svgicons2svgfont/llms.txt The getMetadataService function creates a provider to parse Unicode codepoints from SVG filenames. It supports automatic renaming of files to include assigned codepoints and can be integrated directly into SVGIconsDirStream. ```javascript import { getMetadataService } from 'svgicons2svgfont'; const metadataProvider = getMetadataService({ startUnicode: 0xEA01, prependUnicode: true }); metadataProvider('icons/uE001-home.svg', (error, metadata) => { if (error) { console.error('Failed to parse metadata:', error); return; } console.log(metadata); }); ``` -------------------------------- ### Integrate with Gulp Source: https://github.com/nfroidure/svgicons2svgfont/blob/main/README.md Utilize the `gulp-iconfont` or `gulp-svgicons2svgfont` plugins for Gulp integration. These plugins enable the conversion of SVG icons to icon fonts within your Gulp workflows. ```javascript const gulp = require('gulp'); const iconfont = require('gulp-iconfont'); gulp.task('iconfont', () => { return gulp.src('svg/*.svg') .pipe(iconfont({ fontHeight: 100, normalize: true, formats: ['ttf', 'eot', 'woff', 'woff2', 'svg'] })) .pipe(gulp.dest('fonts')); }); ``` -------------------------------- ### Configure SVG Path Rounding Source: https://github.com/nfroidure/svgicons2svgfont/blob/main/README.md Set the precision for rounding SVG path data. A high value like 10e12 ensures minimal loss of detail during path simplification. ```javascript { round: 10e12 } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.