1 /*****************************************************************************/
3 /* tgi_load_vectorfont.c */
5 /* Loader module for TGI vector font files */
9 /* (C) 2009, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
42 #include <tgi/tgi-kernel.h>
43 #include <tgi/tgi-vectorfont.h>
47 /*****************************************************************************/
49 /*****************************************************************************/
53 const tgi_vectorfont* __fastcall__ tgi_load_vectorfont (const char* name)
54 /* Load a vector font into memory and return it. In case of errors, NULL is
55 * returned and an error is set, which can be retrieved using tgi_geterror.
56 * To use the font, it has to be installed using tgi_install_vectorfont.
59 static const char Magic[4] = {
60 0x54, 0x43, 0x48, TGI_VF_VERSION
63 tgi_vectorfont_header H;
65 tgi_vectorfont* Font = 0;
70 /* Assume we have an error loading the font */
71 tgi_error = TGI_ERR_CANNOT_LOAD;
74 F = open (name, O_RDONLY);
76 /* Cannot open file */
81 if (read (F, &H, sizeof (H)) != sizeof (H)) {
82 /* Cannot read header bytes */
86 /* Check the header */
87 if (memcmp (&H, Magic, sizeof (Magic)) != 0) {
88 /* Header magic not ok */
92 /* Allocate memory for the data */
93 Font = malloc (H.size);
96 tgi_error = TGI_ERR_NO_RES;
100 /* Read the whole font file into the buffer */
101 if (read (F, Font, H.size) != H.size) {
102 /* Problem reading font data */
110 /* Fix the offset pointers. When loaded, they contain numeric offsets
111 * into the VectorOps, with the start of the VectorOps at offset zero.
112 * We will add a pointer to the VectorOps to make them actual pointers
113 * that may be used independently from anything else.
115 V = (unsigned) &Font->vec_ops;
116 for (I = 0; I < TGI_VF_CCOUNT; ++I) {
120 /* Clear the error */
121 tgi_error = TGI_ERR_OK;
123 /* Return the vector font loaded */
127 /* Some sort of load problem. If the file is still open, be sure to