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;
71 F = open (name, O_RDONLY);
73 /* Cannot open file */
78 if (read (F, &H, sizeof (H)) != sizeof (H)) {
79 /* Cannot read header bytes */
83 /* Check the header */
84 if (memcmp (&H, Magic, sizeof (Magic)) != 0) {
85 /* Header magic not ok */
89 /* Allocate memory for the data */
90 Font = malloc (H.size);
96 /* Read the whole font file into the buffer */
97 if (read (F, Font, H.size) != H.size) {
98 /* Problem reading font data */
106 /* Fix the offset pointers. When loaded, they contain numeric offsets
107 * into the VectorOps, with the start of the VectorOps at offset zero.
108 * We will add a pointer to the VectorOps to make them actual pointers
109 * that may be used independently from anything else.
111 V = (unsigned) &Font->vec_ops;
112 for (I = 0; I < TGI_VF_CCOUNT; ++I) {
116 /* Return the vector font loaded */
120 /* Some sort of load problem. If the file is still open, be sure to
126 tgi_error = TGI_ERR_CANNOT_LOAD;