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.
Diff: graphics/EAFont.cpp
- Revision:
- 7:6cf21b018420
- Parent:
- 6:4fe6f365cbeb
--- a/graphics/EAFont.cpp Thu May 06 23:32:14 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-// Copyright 2010 Richard Parker
-
-#include "mbed.h"
-#include "EAFont.h"
-
-#include "../screen/EALCD.h"
-
-EAFont::EAFont()
-: _path(NULL),
- _chars(NULL),
- _noChars(0)
-{
- _img.setCached(true);
- _img.setMask(true);
-}
-
-EAFont::~EAFont()
-{
- // Remember to free up allocated memory.
- if (_chars != NULL)
- {
- delete[] _chars;
- _chars = NULL;
- }
-
- if (_path != NULL)
- {
- delete[] _path;
- _path = NULL;
- }
-}
-
-bool EAFont::load(const char* path)
-{
- if (path == NULL)
- {
- // Invalid path passed in.
- return false;
- }
-
- // Load font descriptor into look up table.
-
- // Try and open the file, check type and load width and height.
- FILE* fp = fopen(path, "r");
- if (fp == NULL)
- {
- return false;
- }
-
- int noChars = 0;
-
- // The first line contains the number of characters,
- if (fscanf(fp, "%d", &noChars) != 1)
- {
- fclose(fp);
- return false;
- }
-
- // Store the path for later
- int pathLen = strlen(path);
-
- // If already loaded an image then clear to load the new one.
- if (_path != NULL)
- {
- delete[] _path;
- _path = NULL;
- }
-
- // Now allocate enough space to hold path. Note +1 for null character.
- _path = new char[pathLen+1];
-
- // Now copy over passed in path to path variable.
- strcpy(_path, path);
-
- // Now change extension to fnb.
- _path[pathLen-1] = 'b';
-
- _noChars = noChars;
-
- // Now that have the correct number of characters want to reserve enough space to hold. First
- // check that there is not already memory allocated.
- if (_chars != NULL)
- {
- delete[] _chars;
- }
-
- // Now create large enough array.
- _chars = new EACharacter[noChars];
-
- // Now loop through loading in the values.
- for (int i = 0; i < noChars; i++)
- {
- int v = 0;
-
- // id.
- fscanf(fp, "%d", &v);
- _chars[i].id = v;
-
- // x.
- fscanf(fp, "%d", &v);
- _chars[i].x = v;
-
- // y.
- fscanf(fp, "%d", &v);
- _chars[i].y = v;
-
- // width.
- fscanf(fp, "%d", &v);
- _chars[i].width = v;
-
- // height.
- fscanf(fp, "%d", &v);
- _chars[i].height = v;
-
- // xoffset.
- fscanf(fp, "%d", &v);
- _chars[i].xOffset = v;
-
- // yoffset.
- fscanf(fp, "%d", &v);
- _chars[i].yOffset = v;
-
- // xAdvance.
- fscanf(fp, "%d", &v);
- _chars[i].xAdvance = v;
- }
-
- fclose(fp);
-
- // Now load the cached image.
- _img.load(_path);
-
- return true;
-}
-
-bool EAFont::_getCharacter(char c, EACharacter& detail)
-{
- for (int i = 0; i < _noChars; i++)
- {
- if (_chars[i].id == c)
- {
- detail = _chars[i];
- return true;
- }
- }
-
- return false;
-}