• 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 "sfntly/table/core/cmap_table.h"
25 #include "sfntly/tag.h"
26 #include "subtly/stats.h"
27 #include "subtly/subsetter.h"
28 #include "subtly/utils.h"
29 
30 using namespace subtly;
31 
PrintUsage(const char * program_name)32 void PrintUsage(const char* program_name) {
33   fprintf(stdout, "Usage: %s <input_font_file>\n", program_name);
34 }
35 
main(int argc,const char ** argv)36 int main(int argc, const char** argv) {
37   const char* program_name = argv[0];
38   if (argc < 2) {
39     PrintUsage(program_name);
40     exit(1);
41   }
42 
43   const char* input_font_path = argv[1];
44   const char* output_font_path = argv[2];
45   FontPtr font;
46   font.Attach(subtly::LoadFont(input_font_path));
47 
48   int32_t original_size = TotalFontSize(font);
49   Ptr<Subsetter> subsetter = new Subsetter(font, NULL);
50   Ptr<Font> new_font;
51   new_font.Attach(subsetter->Subset());
52   if (!new_font) {
53     fprintf(stdout, "Cannot create subset.\n");
54     return 0;
55   }
56 
57   subtly::SerializeFont(output_font_path, new_font);
58   subtly::PrintComparison(stdout, font, new_font);
59   int32_t new_size = TotalFontSize(new_font);
60   fprintf(stdout, "Went from %d to %d: %lf%% of original\n",
61           original_size, new_size,
62           static_cast<double>(new_size) / original_size * 100);
63   return 0;
64 }
65