4 * Copyright (C) 2011-2017 by Werner Lemberg.
6 * This file is part of the ttfautohint library, and may only be used,
7 * modified, and distributed under the terms given in `COPYING'. By
8 * continuing to use, modify, or distribute this file you indicate that you
9 * have read `COPYING' and understand and accept it fully.
11 * The file `COPYING' mentioned in the previous paragraph is distributed
12 * with the ttfautohint library.
19 #define BUF_SIZE 0x10000
22 TA_font_file_read(FILE* file
,
26 FT_Byte buf
[BUF_SIZE
];
31 *buffer
= (FT_Byte
*)malloc(BUF_SIZE
);
33 return FT_Err_Out_Of_Memory
;
35 while ((read_bytes
= fread(buf
, 1, BUF_SIZE
, file
)) > 0)
40 buf_new
= (FT_Byte
*)realloc(*buffer
, len
+ read_bytes
);
42 return FT_Err_Out_Of_Memory
;
46 memcpy(*buffer
+ len
, buf
, read_bytes
);
52 return FT_Err_Invalid_Stream_Read
;
54 /* a valid TTF can never be that small */
56 return TA_Err_Invalid_Font_Type
;
65 TA_font_file_write(FONT
* font
,
68 if (fwrite(font
->out_buf
, 1, font
->out_len
, out_file
) != font
->out_len
)
69 return TA_Err_Invalid_Stream_Write
;
76 TA_control_file_read(FONT
* font
,
80 size_t control_len
= 0;
84 font
->control_buf
= (char*)malloc(BUF_SIZE
);
85 if (!font
->control_buf
)
86 return FT_Err_Out_Of_Memory
;
88 while ((read_bytes
= fread(buf
, 1, BUF_SIZE
, control_file
)) > 0)
90 char* control_buf_new
;
93 /* we store the data as a C string, allocating one more byte */
94 control_buf_new
= (char*)realloc(font
->control_buf
,
95 control_len
+ read_bytes
+ 1);
97 return FT_Err_Out_Of_Memory
;
99 font
->control_buf
= control_buf_new
;
101 memcpy(font
->control_buf
+ control_len
, buf
, read_bytes
);
103 control_len
+= read_bytes
;
106 if (ferror(control_file
))
107 return FT_Err_Invalid_Stream_Read
;
109 font
->control_len
= control_len
;
110 font
->control_buf
[control_len
] = '\0';
115 /* end of tafile.c */