Andrew Reed / Mbed OS CITY1082-i2c_master_wifi_mqtt
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FONT_ShowAllTTFs.c Source File

FONT_ShowAllTTFs.c

00001 /*********************************************************************
00002 *                SEGGER Microcontroller GmbH                         *
00003 *        Solutions for real time microcontroller applications        *
00004 **********************************************************************
00005 *                                                                    *
00006 *        (c) 1996 - 2018  SEGGER Microcontroller GmbH                *
00007 *                                                                    *
00008 *        Internet: www.segger.com    Support:  support@segger.com    *
00009 *                                                                    *
00010 **********************************************************************
00011 
00012 ** emWin V5.48 - Graphical user interface for embedded applications **
00013 All  Intellectual Property rights  in the Software belongs to  SEGGER.
00014 emWin is protected by  international copyright laws.  Knowledge of the
00015 source code may not be used to write a similar product.  This file may
00016 only be used in accordance with the following terms:
00017 
00018 The software  has been licensed to  Cypress Semiconductor Corporation,
00019 whose registered  office is situated  at 198 Champion Ct. San Jose, CA 
00020 95134 USA  solely for the  purposes of creating  libraries for Cypress
00021 PSoC3 and  PSoC5 processor-based devices,  sublicensed and distributed
00022 under  the  terms  and  conditions  of  the  Cypress  End User License
00023 Agreement.
00024 Full source code is available at: www.segger.com
00025 
00026 We appreciate your understanding and fairness.
00027 ----------------------------------------------------------------------
00028 Licensing information
00029 Licensor:                 SEGGER Microcontroller Systems LLC
00030 Licensed to:              Cypress Semiconductor Corp, 198 Champion Ct., San Jose, CA 95134, USA
00031 Licensed SEGGER software: emWin
00032 License number:           GUI-00319
00033 License model:            Services and License Agreement, signed June 10th, 2009
00034 Licensed platform:        Any Cypress platform (Initial targets are: PSoC3, PSoC5)
00035 ----------------------------------------------------------------------
00036 Support and Update Agreement (SUA)
00037 SUA period:               2009-06-12 - 2022-07-27
00038 Contact to extend SUA:    sales@segger.com
00039 ----------------------------------------------------------------------
00040 File        : FONT_ShowAllTTFs.c
00041 Purpose     : Demonstrates the use of TTF font files
00042 Requirements: WindowManager - ( )
00043               MemoryDevices - ( )
00044               AntiAliasing  - ( )
00045               VNC-Server    - ( )
00046               PNG-Library   - ( )
00047               TrueTypeFonts - (x)
00048 
00049               Can be used in a MS Windows environment only!
00050 ----------------------------------------------------------------------
00051 */
00052 
00053 #ifndef SKIP_TEST
00054 
00055 #include <windows.h>
00056 #include <stdio.h>
00057 #include "GUI.h"
00058 
00059 /*********************************************************************
00060 *
00061 *       Defines
00062 *
00063 **********************************************************************
00064 */
00065 //
00066 // Recommended memory to run the sample with adequate performance
00067 //
00068 #define RECOMMENDED_MEMORY (1024L * 5)
00069 
00070 /*********************************************************************
00071 *
00072 *       Static data
00073 *
00074 **********************************************************************
00075 */
00076 static unsigned     _aHeight  [] = {16, 20, 32, 48};   // Array of heights used to show text
00077 static GUI_TTF_CS   _aCS      [GUI_COUNTOF(_aHeight)]; // Each GUI font needs its own GUI_TTF_CS structure
00078 static GUI_FONT     _aFont    [GUI_COUNTOF(_aHeight)]; // Array of GUI fonts
00079 static char         _acFamily [200];
00080 static char         _acStyle  [200];
00081 
00082 /*********************************************************************
00083 *
00084 *       Static code
00085 *
00086 **********************************************************************
00087 */
00088 /*********************************************************************
00089 *
00090 *       _ShowText
00091 */
00092 static void _ShowText(void) {
00093   int i;
00094 
00095   GUI_Clear();
00096   i = 0;
00097   GUI_TTF_GetFamilyName(&_aFont[i], _acFamily, sizeof(_acFamily));
00098   GUI_TTF_GetStyleName(&_aFont[i],  _acStyle,  sizeof(_acStyle));
00099   GUI_SetFont(&GUI_Font20_1);
00100   GUI_DispString(_acFamily);
00101   GUI_DispString(", ");
00102   GUI_DispString(_acStyle);
00103   GUI_DispNextLine();
00104   GUI_DrawHLine(GUI_GetDispPosY(), 0, 0xfff);
00105   GUI_SetFont(&_aFont[i]);
00106   GUI_DispString("abcdefghijklmnopqrstuvwxyz\n");
00107   GUI_DispString("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
00108   GUI_DispString("123456789.:,;(:*!?')\n");
00109   GUI_DrawHLine(GUI_GetDispPosY(), 0, 0xfff);
00110   for (i = 0; i < GUI_COUNTOF(_aHeight); i++) {
00111     GUI_SetFont(&_aFont[i]);
00112     GUI_DispString("The quick brown fox jumps over the lazy dog. 1234567890\n");
00113   }
00114   GUI_Delay(1000);
00115 }
00116 
00117 /*********************************************************************
00118 *
00119 *       _CreateFonts
00120 */
00121 static int _CreateFonts(const U8 * pData, U32 NumBytes) {
00122   int i;
00123   GUI_TTF_DATA TTF_Data;        // Only one GUI_TTF_DATA structure is used per font face
00124 
00125   TTF_Data.pData    = pData;    // Set pointer to file data
00126   TTF_Data.NumBytes = NumBytes; // Set size of file
00127   for (i = 0; i < GUI_COUNTOF(_aHeight); i++) {
00128     //
00129     // Initialize GUI_TTF_CS members
00130     //
00131     _aCS[i].PixelHeight = _aHeight[i];
00132     _aCS[i].pTTF        = &TTF_Data;
00133     //
00134     // Create GUI font
00135     //
00136     if (GUI_TTF_CreateFontAA(&_aFont[i], &_aCS[i])) {
00137       return 1;
00138     }
00139   }
00140   return 0;
00141 }
00142 
00143 /*********************************************************************
00144 *
00145 *       _cbFontDemo
00146 *
00147 * Function description
00148 *   The function uses the given pointer to a true type font for creating
00149 *   a couple of GUI fonts and showing the outline of the TTF font.
00150 *
00151 * Parameters:
00152 *   pData    - Location of font file
00153 *   NumBytes - Size of font file
00154 */
00155 static void _cbFontDemo(const U8 * pData, U32 NumBytes) {
00156   _CreateFonts(pData, NumBytes); // Create fonts
00157   _ShowText();                   // Show some text
00158   GUI_TTF_DestroyCache();        // Clear the TTF cache
00159 }
00160 
00161 /*********************************************************************
00162 *
00163 *       _IterateOverAllFiles
00164 *
00165 * Function description
00166 *   The function iterates over all files of the given folder and the
00167 *   given mask, reads the contents of the file and calls the function
00168 *   pfDoSomething() with location and size of file data.
00169 *   Can be used under Win32 environment only.
00170 */
00171 static void _IterateOverAllFiles(const char * sFolder, const char * sMask, void (* pfDoSomething)(const U8 * pData, U32 NumBytes)) {
00172   GUI_RECT Rect = {0, 10, 1000, 1000};
00173   char              acMask[_MAX_PATH];
00174   char              acFile[_MAX_PATH];
00175   WIN32_FIND_DATA   Context;
00176   HANDLE            hFind;
00177   HANDLE            hFile;
00178   U8              * pData;
00179   DWORD             NumBytes;
00180   DWORD             NumBytesRead;
00181 
00182   sprintf(acMask, "%s\\%s", sFolder, sMask);
00183   hFind = FindFirstFile(acMask, &Context);
00184   if (hFind != INVALID_HANDLE_VALUE) {
00185     do {
00186       sprintf(acFile, "%s\\%s", sFolder, Context.cFileName);
00187       hFile = CreateFile(acFile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
00188       if (hFile != INVALID_HANDLE_VALUE) {
00189         NumBytes = GetFileSize(hFile, NULL);
00190         pData = (U8 *)malloc(NumBytes);
00191         ReadFile(hFile, pData, NumBytes, &NumBytesRead, NULL);
00192         pfDoSomething(pData, NumBytes);
00193         free(pData);
00194       }
00195       CloseHandle(hFile);
00196     } while (FindNextFile(hFind, &Context));
00197   }
00198 }
00199 
00200 /*********************************************************************
00201 *
00202 *       Public code
00203 *
00204 **********************************************************************
00205 */
00206 /*********************************************************************
00207 *
00208 *       MainTask
00209 */
00210 void MainTask(void) {
00211   char acPath[200];
00212 
00213   GUI_Init();
00214   //
00215   // Check if recommended memory for the sample is available
00216   //
00217   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00218     GUI_ErrorOut("Not enough memory available."); 
00219     return;
00220   }
00221   //
00222   // Set colors and text mode
00223   //
00224   GUI_SetBkColor(GUI_WHITE);
00225   GUI_SetColor(GUI_BLACK);
00226   GUI_SetTextMode(GUI_TM_TRANS);
00227   //
00228   // Get windows system directory and extend it with '\Font'
00229   //
00230   GetWindowsDirectory(acPath, sizeof(acPath));
00231   strcat(acPath, "\\Fonts");
00232   //
00233   // Iterate over files and call _cbFontDemo for each file
00234   //
00235   while (1) {
00236     _IterateOverAllFiles(acPath, "*.ttf", _cbFontDemo);
00237   }
00238 }
00239 
00240 #endif
00241 
00242 /*************************** End of file ****************************/