1 /**
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <stdint.h>
17 
18 #include <ft2build.h>
19 #include FT_FREETYPE_H
20 
main(int argc,char ** argv)21 int main(int argc, char **argv) {
22   if (argc != 2) {
23     return EXIT_FAILURE;
24   }
25 
26   FILE *fp = fopen(argv[1], "rb");
27   if (!fp) {
28     return EXIT_FAILURE;
29   }
30 
31   fseek(fp, 0, SEEK_END);
32   size_t size = ftell(fp);
33   fseek(fp, 0, SEEK_SET);
34   if (size < 1) {
35     fclose(fp);
36     return EXIT_FAILURE;
37   }
38 
39   uint8_t *data = new uint8_t[size];
40   if (!data) {
41     fclose(fp);
42     return EXIT_FAILURE;
43   }
44   (void)fread(data, sizeof(uint8_t), size, fp);
45   fclose(fp);
46   fp = nullptr;
47 
48   FT_Library ftLib;
49   if (FT_Init_FreeType(&ftLib)) {
50     delete[] data;
51     return EXIT_FAILURE;
52   }
53 
54   FT_Face ftFace;
55   FT_New_Memory_Face(ftLib, data, size, -33, &ftFace);
56 
57   FT_Done_FreeType(ftLib);
58   delete[] data;
59   return EXIT_SUCCESS;
60 }
61