adobe-type-tools / opentype-svg

Tools and sample files for making OpenType-SVG fonts
MIT License
212 stars 17 forks source link

Feature request: Instead of listing font files in command provide a folder with font files #26

Closed filipaldi closed 1 year ago

filipaldi commented 1 year ago

I want to iterate the script through hundreds of styles, and listing them in the terminal command is not a convenient way. What about abstracting the code to observe a folder and then iterating through all the font files?

I've been trying to use for-loop in Terminal but without success.

miguelsousa commented 1 year ago

I want to iterate the script through hundreds of styles

It's not clear to me what you're trying to do. Can you provide a detailed example?

filipaldi commented 1 year ago

I have hundreds of font files (styles of font family) in a folder. I need to get SVG files (but not SVG font) from all of the font files in that folder. Eventually, I don't need to assign colours to SVG paths.

So the prompt will look like this: fonts2svg -c /path/to/directory/with/font/files/ instead of fonts2svg -c [colour-a],[colour-b],[colour-c] font-file-a.otf font-file-b.otf font-file-c.otf

Preferably instead of generating subfolders, let's use naming concatenating "font_style_name","-","glyph_unicode" e.g., my_font_hairline_120-00C1.svg, my_font_hairline_120-00C2.svg. my_font_hairline_120-00C3.svg,...

miguelsousa commented 1 year ago

fonts2svg doesn't provide a way to configure how the SVG files are named. But you can run a shell script that runs the tool for each font in a folder, creating an output folder for the SVGs of each font. Something like this:

#!/bin/bash

# Check if a directory path was provided
if [ -z "$1" ]; then
  echo "Please provide a directory path as an argument."
  exit 1
fi

# Find all .otf and .ttf files in the directory
for file in "$1"/*.{otf,ttf}; do
  # Check if the file exists
  if [ -e "$file" ]; then
    # Get the file path without the extension
    file_no_ext="${file%.*}"

    # Create a folder using the file path without the extension
    mkdir -p "$file_no_ext"

    # Run fonts2svg command
    fonts2svg -g A,Z,a,z "$file" -o "$file_no_ext"
  fi
done

Save the code above in a file named process_folder.sh, and run it like so:

sh ./process_folder.sh path_to_fonts_folder
filipaldi commented 1 year ago

Thanks, @miguelsousa this worked perfectly!