• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Google Inc. All Rights Reserved.
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 
17 #include <stdio.h>
18 #include <stdlib.h>
19 
20 #include <map>
21 #include <utility>
22 
23 #include "sfntly/font.h"
24 #include "subtly/merger.h"
25 #include "subtly/stats.h"
26 #include "subtly/utils.h"
27 
28 using namespace subtly;
29 
PrintUsage(const char * program_name)30 void PrintUsage(const char* program_name) {
31   fprintf(stdout, "Usage: %s <input_font_file1> <input_font_file2> ..."
32           "<input_font_filen> <output_font_file>\n",
33           program_name);
34 }
35 
CheckLoading(const char * font_path,Font * font)36 void CheckLoading(const char* font_path, Font* font) {
37   if (!font || font->num_tables() == 0) {
38     fprintf(stderr, "Could not load font %s. Terminating.\n", font_path);
39     exit(1);
40   }
41 }
42 
main(int argc,const char ** argv)43 int main(int argc, const char** argv) {
44   if (argc < 3) {
45     PrintUsage(argv[0]);
46     exit(1);
47   }
48 
49   FontArray fonts;
50   for (int32_t i = 1; i < argc - 1; ++i) {
51     Ptr<Font> font;
52     font.Attach(LoadFont(argv[i]));
53     CheckLoading(argv[i], font);
54     fonts.push_back(font);
55   }
56 
57   Ptr<Merger> merger = new Merger(&fonts);
58   FontPtr new_font;
59   new_font.Attach(merger->Merge());
60 
61   fprintf(stderr, "Serializing font to %s\n", argv[argc - 1]);
62   SerializeFont(argv[argc - 1], new_font);
63   if (!new_font) {
64     fprintf(stdout, "Cannot create merged font.\n");
65     return 1;
66   }
67 
68   return 0;
69 }
70