Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
FONT_ShowXBF.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_ShowXBF.c 00041 Purpose : Shows how to use (E)xternal (B)inary (F)onts 00042 Requirements: WindowManager - (x) 00043 MemoryDevices - ( ) 00044 AntiAliasing - ( ) 00045 VNC-Server - ( ) 00046 PNG-Library - ( ) 00047 TrueTypeFonts - ( ) 00048 00049 Can be used in a MS Windows environment only! 00050 ---------------------------------------------------------------------- 00051 */ 00052 00053 #ifndef SKIP_TEST 00054 00055 #include <windows.h> 00056 00057 #include "GUI.h" 00058 #include "EDIT.h" 00059 00060 // 00061 // Recommended memory to run the sample with adequate performance 00062 // 00063 #define RECOMMENDED_MEMORY (1024L * 5) 00064 00065 /********************************************************************* 00066 * 00067 * Static code 00068 * 00069 ********************************************************************** 00070 */ 00071 /********************************************************************* 00072 * 00073 * _GetFileName 00074 * 00075 * Function description 00076 * Returns the file name of the XBF file to be used 00077 */ 00078 static void _GetFileName(char * pPath, unsigned MaxSize) { 00079 WM_HWIN hWin; 00080 00081 // 00082 // Set default value on first call 00083 // 00084 if (!strlen(pPath)) { 00085 strcpy(pPath, "Sample\\Tutorial\\FONT_ShowXBF\\ExtBinFont.xbf"); 00086 } 00087 // Display small hint 00088 GUI_SetFont(&GUI_Font10_ASCII); 00089 GUI_DispStringHCenterAt("Please enter the file name of the XBF-file:", 160, 80); 00090 // 00091 // Create edit widget 00092 // 00093 hWin = EDIT_Create(10, 120, 300, 20, 0, MaxSize, WM_CF_SHOW); 00094 EDIT_SetText(hWin, pPath); 00095 WM_SetFocus(hWin); 00096 // 00097 // Wait until GUI_KEY_ENTER has been pressed 00098 // 00099 while (GUI_GetKey() != GUI_KEY_ENTER) { 00100 GUI_Delay(100); 00101 } 00102 // 00103 // Get filename from EDIT widget 00104 // 00105 EDIT_GetText(hWin, pPath, MaxSize); 00106 // 00107 // Create edit widget 00108 // 00109 WM_DeleteWindow(hWin); 00110 // 00111 // Clear screen 00112 // 00113 GUI_ClearRect(0, 40, 319, 239); 00114 } 00115 00116 /********************************************************************* 00117 * 00118 * _cbGetData 00119 * 00120 * Function description 00121 * Callback function for getting font data 00122 * 00123 * Parameters: 00124 * Off - Position of XBF file to be read 00125 * NumBytes - Number of requested bytes 00126 * pVoid - Application defined pointer 00127 * pBuffer - Pointer to buffer to be filled by the function 00128 * 00129 * Return value: 00130 * 0 on success, 1 on error 00131 */ 00132 static int _cbGetData(U32 Off, U16 NumBytes, void * pVoid, void * pBuffer) { 00133 HANDLE hFile; 00134 DWORD NumBytesRead; 00135 00136 hFile = *(HANDLE *)pVoid; 00137 // 00138 // Set file pointer to the requested position 00139 // 00140 if (SetFilePointer(hFile, Off, 0, FILE_BEGIN) == 0xFFFFFFFF) { 00141 return 1; // Error 00142 } 00143 // 00144 // Read font data 00145 // 00146 if (!ReadFile(hFile, pBuffer, NumBytes, &NumBytesRead, 0)) { 00147 return 1; // Error 00148 } 00149 if (NumBytesRead != NumBytes) { 00150 return 1; // Error 00151 } 00152 return 0; // Ok 00153 } 00154 00155 /********************************************************************* 00156 * 00157 * _ShowXBF 00158 * 00159 * Function description 00160 * Small sub routine which creates (and selects) a XBF font, 00161 * shows 'Hello world!' and waits for a keypress 00162 */ 00163 static void _ShowXBF(void * pVoid) { 00164 GUI_XBF_DATA XBF_Data; 00165 GUI_FONT Font; 00166 00167 // 00168 // Create XBF font 00169 // 00170 GUI_XBF_CreateFont(&Font, // Pointer to GUI_FONT structure in RAM 00171 &XBF_Data, // Pointer to GUI_XBF_DATA structure in RAM 00172 GUI_XBF_TYPE_PROP, // Font type to be created 00173 _cbGetData, // Pointer to callback function 00174 pVoid); // Pointer to be passed to GetData function 00175 // 00176 // Show 'Hello world!' 00177 // 00178 GUI_DispStringHCenterAt("Hello world!", 160, 80); 00179 // 00180 // Display hint 00181 // 00182 GUI_SetFont(&GUI_Font13_ASCII); 00183 GUI_DispStringHCenterAt("Press any key to continue...", 160, 120); 00184 // 00185 // Wait for pressing a key 00186 // 00187 while (!GUI_GetKey()) { 00188 GUI_Delay(100); 00189 } 00190 // 00191 // Delete XBF font and clear display 00192 // 00193 GUI_XBF_DeleteFont(&Font); 00194 GUI_ClearRect(0, 40, 319, 239); 00195 } 00196 00197 /********************************************************************* 00198 * 00199 * Public code 00200 * 00201 ********************************************************************** 00202 */ 00203 /********************************************************************* 00204 * 00205 * MainTask 00206 */ 00207 void MainTask(void) { 00208 HANDLE hFile; 00209 char acPath[_MAX_PATH] = {0}; 00210 00211 // 00212 // Initialize emWin 00213 // 00214 GUI_Init(); 00215 // 00216 // Check if recommended memory for the sample is available 00217 // 00218 if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) { 00219 GUI_ErrorOut("Not enough memory available."); 00220 return; 00221 } 00222 GUI_SetFont(&GUI_Font24_ASCII); 00223 GUI_DispStringHCenterAt("External binary font sample", 160, 5); 00224 while (1) { 00225 // 00226 // Get font file name... 00227 // 00228 _GetFileName(acPath, sizeof(acPath)); 00229 // 00230 // ...and open the file 00231 // 00232 hFile = CreateFile(acPath, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 00233 if (hFile != INVALID_HANDLE_VALUE) { 00234 // 00235 // On success call demo routine 00236 // 00237 _ShowXBF(&hFile); 00238 CloseHandle(hFile); 00239 } else { 00240 // 00241 // On error show message box 00242 // 00243 GUI_MessageBox("File not found!", "Error", GUI_MESSAGEBOX_CF_MODAL); 00244 GUI_ClearRect(0, 40, 319, 239); 00245 } 00246 } 00247 } 00248 00249 #endif 00250 00251 /*************************** End of file ****************************/ 00252
Generated on Thu Jul 14 2022 12:58:40 by
