Return to FunctionReference page

Function

  • SWFFont newSWFFont_fromFile(const char *filename);

Purpose

  • Create a font object from an FDB (.fdb) or TrueType (.ttf) file on the local filesystem.

Parameters

  1. const char *filename - Text string giving the name of the file to load. (i.e. "/some/where/font.fdb")

Returns

  • A new font object (SWFFont), or NULL if an error occurred.

Language

  • C

Ming version

  • (unknown). At least 0.4.0 and onwards, possibly earlier versions as well.

Notes

  • Ming version 0.4.0.beta5 and onwards can load TrueType files. Versions of Ming prior to 0.4.0.beta5 are only capable of loading FDB files.

    Further information on using TrueType fonts in Ming can be found here.

Example

   1 #include <stdio.h>
   2 #include <stdlib.h>
   3 #include <ming.h>
   4 
   5 int main(void)
   6 {
   7         // Create local variables
   8         int i;
   9         SWFDisplayItem image_display_item;
  10         SWFFont font_object;
  11         SWFMovie test_movie;
  12         SWFText text_object;
  13 
  14 
  15         // Initialise the movie structure in memory
  16         Ming_init();
  17         test_movie = newSWFMovieWithVersion(7);
  18 
  19         // Set the desired compression level for the output (9 = maximum compression)
  20         Ming_setSWFCompression(9);
  21 
  22         // Set the background color for the movie
  23         SWFMovie_setBackground(test_movie, 0x00, 0x00, 0x00);
  24 
  25         // Adjust the dimensions of the movie
  26         SWFMovie_setDimension(test_movie, 800, 600);
  27 
  28         // Set the frame rate for the movie to 24 frames per second
  29         SWFMovie_setRate(test_movie, 24.0);
  30 
  31         // Load a font from disk
  32         font_object = newSWFFont_fromFile("font.fdb");
  33         if (NULL == font_object)
  34         {
  35                 // Something went wrong, so exit
  36                 printf("Unable to load font from file.\n");
  37                 return EXIT_FAILURE;
  38         }
  39 
  40         // Create a new, empty text object
  41         text_object = newSWFText();
  42 
  43         // Tell the text object to use the font previously loaded
  44         SWFText_setFont(text_object, font_object);
  45 
  46         // Set the height of the text
  47         SWFText_setHeight(text_object, 18.0);
  48 
  49         // Set the color of the text
  50         SWFText_setColor(text_object, 0x00, 0x00, 0xff, 0xff);
  51 
  52         // Add a string to the text object
  53         SWFText_addString(text_object, "This is some example text", NULL);
  54 
  55         // Add the text object to the movie (at 0,0)
  56         image_display_item = SWFMovie_add(test_movie, (SWFBlock) text_object);
  57 
  58         // Move to 100, 100
  59         SWFDisplayItem_moveTo(image_display_item, 100.00, 100.0);
  60 
  61         // Progressively move the text down and to the right
  62         for (i = 0; i <= 250; i++)
  63         {
  64                 SWFMovie_nextFrame(test_movie);
  65                 SWFDisplayItem_move(image_display_item, 2, 2);
  66         }
  67 
  68         // Save the swf movie file to disk
  69         SWFMovie_save(test_movie, "ming-test.swf");
  70 
  71         // Free the swf movie in memory
  72         destroySWFMovie(test_movie);
  73 
  74         // Free the swf text object
  75         destroySWFText(text_object);
  76 
  77         return EXIT_SUCCESS;
  78 }