A solution, but which does not involve only batch is to use a program to extract the source name directly from the file. This can be done with several languages (C, Python and etc). I don’t know if there is any pure batch form that can solve this.
Example:
You can use the library freetype to load the source and get the name. For this you can use the following code (in C):
#include <stdint.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include <freetype.h>
#include <ftglyph.h>
#include <ftsnames.h>
int main(int argc, char** argv)
{
// Verifica se há parâmetros:
if (argc < 2)
{
printf("Nenhum parametro informado.");
return 0;
}
// O arquivo da fonte que se extrairá o nome.
const char* face_target = argv[1];
FT_Library library;
int error = FT_Init_FreeType(&library);
if (error)
{
// Erro ao carregar biblioteca.
return -1;
}
FT_Face face;
error = FT_New_Face(library, face_target, 0, &face);
if (error == FT_Err_Unknown_File_Format)
{
// Erro: Provavelmente o arquivo da fonte não é suportado.
return -1;
}
else if (error)
{
// Erro: Não foi possível abrir o arquivo ou o arquivo está quebrado.
return -1;
}
else
{
// A fonte foi lida com sucesso:
FT_SfntName name;
memset(&name, 0, sizeof(FT_SfntName));
FT_Get_Sfnt_Name(face, 1, &name);
printf("%.*s", name.string_len, name.string);
}
return 0;
}
And generate a program that prints the source name, given her file. Assuming the program is named as "font2name" and is accessible, you can call it Batch like this:
font2name BebasNeue.otf > name.txt
set /p FACE_NAME=< name.txt
echo %FACE_NAME%
With this, FACE_NAME will store the font name the way you want "Bebas Neue".
I’m not sure, but I believe the same can be done with python, using freetype for python. But, I don’t know if, for what you’re doing, it’s possible to replace batch with python.
It seems that to do this you can use Powershell.
– Tony