No announcement yet.

string in custom font

  • Filter
  • Time
  • Show
Clear All
new posts

  • string in custom font

    I hope this subsection of the forum is not the wrong place to post this question.
    On the 4Duino I have code that generates a string, which is random letters and numbers.
    I want to take that string, send it to the PICASSO and display it in a custom font.

    How do I achieve this?

    I only need to display one font, but with 30px height (large letters) and in the custom font I selected. As far as I can tell "Strings" and "Static Text" both generate images of the text before upload which are then displayed as images.
    But I need to display dynamic text in a custom font.
    Is there maybe a way to convert the font for use with the Label object?

  • #2

    You may display your String object with a customized font by following the procedure on Serial Displaying Third Party Fonts FAT16.

    Since you’ve mentioned that you’ll be displaying dynamic text, the line containing the PrintDisk should be eliminated for its values are only limited to what you have placed in the object inspector. Replacing it with a simple print function allows you to display varying letters and/or numbers.

    Managing the text height is also possible using the Text Height function that is further explained in Serial Command Reference Manual for Picaso and Picaso-Lite.

    On the other hand, the use of Label and StaticText objects won’t suffice the printing of dynamic text because it will only print the initial caption entered. In addition, the label object does not require the use of a micro SD card because only offers three 4D Fonts whereas the StaticText object demands the use of a micro SD card because its fonts vary to your present library.

    Hope this helps.

    Best Regards,


    • #3
      Thank you for your answer Danica, very much appreciated!

      What do you mean by "Label [..] object won’t suffice the printing of dynamic text because it will only print the initial caption entered".
      I thought it just uses display.putstr and then the string you actually print where the cursor is can be what you want. At least display.putstr works fine for millis, converted to char array with sprintf.
      Did you mean Strings and Static Text are non-dynamic?

      I tried the following code in the loop:

      Display.gfx_RectangleFilled(48, 104, 122, 303, WHITE);
      Display.txt_FontID(hFont1) ; // Font index correct at time of code generation
      Display.txt_FGcolour(BLACK) ;
      Display.txt_BGcolour(WHITE) ;
      Display.gfx_MoveTo(48 , 104) ;
      Display.putstr("AbCd012568") ; // Label1

      But although I select a font in the "strings" object and then replace the PrintDisk line with a putstr, I get "hFont1 was not declared in this scope" at compile time.

      I'm using a uSD card anyways because I use custom LED "glyphs", so I'm operating inside Extended Graphics mode of the workshop4 IDE, on the 4duino. The code I can see and write is only the 32u4's Arduino code, the PICASSO's code I thought was generated automatically.


      • #4
        ahhh, so I figured it out:

        How to print any string in a custom font on the 4D Systems 4Duino / PICASO and probably Diablo16.

        Create a "Strings" widget. There you go to the "Strings" subclass, click the 3three-dotted-button and type something, then select the font you want to use and the size.
        The font files created by the workshop4 IDE on the uSD card are, in my case, called "FONTTE~1.d01" and "FONTTE~1.g01".
        Back to the Arduino code:
        In setup, there is a variable called "hndl". There you need to paste the propper file names, like they are on the uSD. Or create a second word for your font, in the same style as hndl is created (above the setup). Then use that to load the proper files.
        Then in the line Display.txt_FontID you reference the word that loaded the font file from the uSD (select the font you want to use).
        Then with a simple Display.putstr(""); the picasso writes the string you feed it, in the font you selected.
        So I believe once the font files (which is a fancy Bitmap of the letters, so size is important) are created, you can just copy them off the uSD (for later use) and use them without a String object, e.g. with a label object, referring to the correct files in font selection, setup and file-word.
        You can probably even rename the font files (*.d01 and *.g01) as long as you reference them correctly in the code, as they are on the uSD.


        • #5
          well I overlooked something else:
          around line 100 in the template you will find this:

          //hFontn = Display.file_LoadImageControl("NoName4.dnn", "NoName4.gnn", 1); // Open handle to access uSD fonts, uncomment if required and change nn to font number

          you'll still have to create the word "hFontn" where the last n is a number but it's right there, in the template.

          Use this or a different word you created for the font. hndl is used by other funtions, so putting a font in there is folley.

          Also: I discovered another bug in the IDE.
          When you insert a "Label" object and enlarge it with maxheight and maxwidt under "4DGLFont", then insert a "Strings" object, the strings object is pixel-scaled up too, and this looks ugly. This happens because the "Strings" object doesn't have maxheight and maxwidth attributes so the display engine just uses the values from the last object that had them. This can be very confusing, for a minute. Or more if it doesn't come to your head straightaway.


          • #6

            Thank you for your very detailed explanation in applying the customized fonts which applies not only in the 4Duino display module but with the other Diablo-16, Picaso, and Goldelox displays. I’m very sure that this will also benefit other users.

            On the other hand, for the bug that you’ve mentioned, I have observed that the previously declared text height and width of the Label object apply on the preview of the String object on the Workshop4 IDE. However, upon uploading the project, the String object was printed with its default size. Thank you for pointing this out to us and rest assured that we’ll handle and correct this issue.

            If you still encounter any issues, please don’t hesitate to tell us.

            Best Regards,


            • #7
              Thank you Danica for doing your best to support me! You were very helpful!


              • #8
                You're very welcome.
                Glad to help.