Using Custom Font in "text"

I’ve been able to fix the conversion bug. Now it seems to work OK with several fonts.

Now, maybe the idea would be to see if these fonts can be reasonnably compressed directly into the stdlib and be used directly as parameters in the text command.

2 Likes

Would you want the fonts to be included in the stdlib or do you actually want to give people the option of using any font available to them?

Not sure what’s the best option yet, because at the end, G’MIC user will have to specify a custom font as a font.gmz file, and :

  • Converting a ttf filename into a gmz file cannot be done “easily”, because an external command-line tool must be installed (not even sure this exists for Windows). So it’s not possible to assume that all G’MIC users will be able to do that.

  • For this reason, we cannot rely only on ttf files, so providing a set of “cool” fonts directly as gmz files could be nice (i.e. just as we provide a default set of color LUTs with command clut).

I imagine that having a command font that could provide a default set of fonts would be nice.
For experienced people, they could still convert their .ttf files by themselves.

Yes, that sounds like a plan. We then just have to specify the cool fonts… And perhaps we need a place like the .gmic file where a user can store the converted font files he/she wants to use? Or they could be stored on GitHub and be downloaded from there by the user.
What are you using to convert the ttf?

I’m okay with being provided with just default set of font, and a list of candidates fonts as additional.

Try this for starters: Common fonts for Windows & Mac (Example)

And a few candidates fonts, and I think we’re good.

And a few less boring ones as well, please :wink:

acme

I have a question though. What’s the maximum size of each font? I don’t like the shape_ situation where the shapes are all 512x512, but that’s the easiest solution and fastest one.

Yes. Indeed. Let me find some more, like

  • Montserrat
  • Lato
  • Roboto
  • Halloween
  • Cabin Sketch
  • Cheque
  • Medieval Sharp

What would be great to have is the fonts in italics and bold.

And can we have accents? As a Frenchman, @David_Tschumperle, that should be a given…

Can we have coloured text?

They can’t be all equal size i would assume as the characters are all of different width. I would have the fonts in the stdlib large, we can then resize.

Some progress: I’ve written some scripts to convert the fonts you suggested to the G’MIC format.
I need to generate them at different scales, then write a font command, but I guess this should be doable before the week-end, hopefully!.

What I plan is a syntax like this:

foo : 
  800,800
  text "Hello !",0.5~,0.5~,${"font Arial,48"},1,255

Should be simple and generic enough !

3 Likes

Maybe you could add a few fancier types, a retro-pixel type, and maybe typewriter, for some diversity? :man_shrugging:

And… it would be great if we can compile and use individual fonts oureselves as well. That would have to be reflected in the new command as well.

@David_Tschumperle, can you please check the conversion. Some, like Medieval or Cheque do not look like they should. For example


Also, looking at the image you have, @David_Tschumperle, with the different fonts it looks like the spacing between the words seems to be rather large. Are those spaces created by single spaces of the respective font?

I have the impression that there are a lot of expectations concerning this feature :slight_smile:
(take it easy, please!).

Some news:

  • I’ve polished my scripts to convert the fonts, so it should work OK now (so far, so good).

  • I have set a first collection of G’MIC default fonts, that is stored as a .gmz file that is stored on the G’MIC server (currently 8MB). It contains the default fonts that G’MIC can use to draw text on images. Data file: https://gmic.eu/gmic_fonts.gmz

The new commands that are important to know are (after a $ gmic update):

Command font:

font "Font Name",height generates a font with given name and requested height, and put it in cache (as a global variable). This command returns an identifier that can be used afterwards in commands text and text_outline to draw text on image with specified font. Like in the example below:

foo :
  sp colorful / 2

  # Example 1: Direct integration of 'font' in the call to the 'text_outline' (aka 'to') command:
  to "Acme:\n Hello World!",0.5~,0.2~,${"font Acme,100"},2,1,64,128,255

  # Example 2 : Make it in two steps.
  medieval_sharp=${"font MedievalSharp,100"}  # 'medieval_sharp' can be re-used several times.
  to "Medieval Sharp:\n Hello World!",0.5~,0.6~,$medieval_sharp,2,1,255,255,128

  # Example 3: When an invalid font name is requested, fallback to default G'MIC font.
  donotexist=${"font DoNotExist,32"} # Obviously an invalid font name
  to "When specifying unknown font!",0.5~,0.8~,$donotexist,2,1,255,128,255

which renders this:

This command does not render a font from a .ttf or .otf file. It just gets the font from the G’MIC font collection. So for now, the font name can be only one amongst { Acme | Arial | Arial Black | Cabin Sketch | Cheque | Comic Sans MS | Courier New | Georgia | Halloween | Impact | Lato | Lucida Console | Lucida Sans | MedievalSharp | Montserrat | MS Sans Serif | Oswald | Palatino Linotype | Roboto | Sofia | Tahoma | Times New Roman | Trebuchet | Verdana }.

Command font2gmz:

Now, if you need to draw your own custom font, you’ll have to convert it as a .gmz file before it can be used in the text or text_outline commands. This is what command font2gmz is intended for.
Rendering a font can take time, especially when the font size is large. So once you’ve converted a font, you should always save it as a .gmz file.

Step 1: Convert your font file as a .gmz file. This rasterizes the font, so please keep in mind that the size will be unique.

$ gmic font2gmz JosefinSans-Regular.ttf,80 o JosefinSans.gmz

Step 2: Import that font in a script and use it to draw text on an image:

foo : 
  sp colorful / 2
  l[] { JosefinSans.gmz store __josefin_sans } # Import font
  to "Hello World!",0.5~,0.5~,__josefin_sans,2,1,255,0,255

which renders this:

Note that command font2gmz requires cutycapt to be installed for doing the font snapshot.

I’ll still have a few work to do concerning the normalization of anti-aliasing effects for fonts of different sizes.

I’m not sure I’d go much further than that!

1 Like

Allows cool stuffs already:

foo :
  sp colorful / 2
  euclidean2polar 50%,50%,4 rotate 90
  to "A bit of cool fonts in G'MIC now! \20",0.5~,0.9~,${"font Acme,64"},2,0.5,255,255,255
  rotate -90 polar2euclidean 50%,50%,4
  to "G'MIC",0.5~,0.45~,${"font Sofia,180"},2,1,255,128,0
  to "Forever!",0.55~,0.6~,${"font \"Cabin Sketch\",80"},2,1,255,0,128

5 Likes

Great to see development in this area. I am sure many people will benefit from this, especially for automating tasks.

1 Like

I am only home now and quite puzzled

Ask us anything, if you’re puzzled.