4 * Copyright (C) 2011-2015 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(FONT
* font
,
25 FT_Byte buf
[BUF_SIZE
];
30 font
->in_buf
= (FT_Byte
*)malloc(BUF_SIZE
);
32 return FT_Err_Out_Of_Memory
;
34 while ((read_bytes
= fread(buf
, 1, BUF_SIZE
, in_file
)) > 0)
39 in_buf_new
= (FT_Byte
*)realloc(font
->in_buf
, in_len
+ read_bytes
);
41 return FT_Err_Out_Of_Memory
;
43 font
->in_buf
= in_buf_new
;
45 memcpy(font
->in_buf
+ in_len
, buf
, read_bytes
);
51 return FT_Err_Invalid_Stream_Read
;
53 /* a valid TTF can never be that small */
55 return TA_Err_Invalid_Font_Type
;
57 font
->in_len
= in_len
;
64 TA_font_file_write(FONT
* font
,
67 if (fwrite(font
->out_buf
, 1, font
->out_len
, out_file
) != font
->out_len
)
68 return TA_Err_Invalid_Stream_Write
;
75 TA_control_file_read(FONT
* font
,
79 size_t control_len
= 0;
83 font
->control_buf
= (char*)malloc(BUF_SIZE
);
84 if (!font
->control_buf
)
85 return FT_Err_Out_Of_Memory
;
87 while ((read_bytes
= fread(buf
, 1, BUF_SIZE
, control_file
)) > 0)
89 char* control_buf_new
;
92 /* we store the data as a C string, allocating one more byte */
93 control_buf_new
= (char*)realloc(font
->control_buf
,
94 control_len
+ read_bytes
+ 1);
96 return FT_Err_Out_Of_Memory
;
98 font
->control_buf
= control_buf_new
;
100 memcpy(font
->control_buf
+ control_len
, buf
, read_bytes
);
102 control_len
+= read_bytes
;
105 if (ferror(control_file
))
106 return FT_Err_Invalid_Stream_Read
;
108 font
->control_len
= control_len
;
109 font
->control_buf
[control_len
] = '\0';
114 /* end of tafile.c */