18c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com/* 28c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com * Copyright 2011 Google Inc. All Rights Reserved. 38c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com * 48c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com * Licensed under the Apache License, Version 2.0 (the "License"); 58c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com * you may not use this file except in compliance with the License. 68c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com * You may obtain a copy of the License at 78c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com * 88c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com * http://www.apache.org/licenses/LICENSE-2.0 98c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com * 108c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com * Unless required by applicable law or agreed to in writing, software 118c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com * distributed under the License is distributed on an "AS IS" BASIS, 128c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com * See the License for the specific language governing permissions and 148c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com * limitations under the License. 158c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com */ 168c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com 178c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com#include <stdio.h> 188c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com#include <stdlib.h> 198c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com 208c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com#include <map> 218c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com#include <utility> 228c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com 238c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com#include "sfntly/font.h" 248c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com#include "subtly/merger.h" 258c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com#include "subtly/stats.h" 268c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com#include "subtly/utils.h" 278c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com 288c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.comusing namespace subtly; 298c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com 308c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.comvoid PrintUsage(const char* program_name) { 318c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com fprintf(stdout, "Usage: %s <input_font_file1> <input_font_file2> ..." 328c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com "<input_font_filen> <output_font_file>\n", 338c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com program_name); 348c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com} 358c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com 368c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.comvoid CheckLoading(const char* font_path, Font* font) { 378c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com if (!font || font->num_tables() == 0) { 388c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com fprintf(stderr, "Could not load font %s. Terminating.\n", font_path); 398c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com exit(1); 408c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com } 418c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com} 428c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com 438c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.comint main(int argc, const char** argv) { 448c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com if (argc < 3) { 458c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com PrintUsage(argv[0]); 468c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com exit(1); 478c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com } 488c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com 498c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com FontArray fonts; 508c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com for (int32_t i = 1; i < argc - 1; ++i) { 518c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com Ptr<Font> font; 528c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com font.Attach(LoadFont(argv[i])); 538c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com CheckLoading(argv[i], font); 548c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com fonts.push_back(font); 558c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com } 568c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com 578c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com Ptr<Merger> merger = new Merger(&fonts); 588c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com FontPtr new_font; 598c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com new_font.Attach(merger->Merge()); 608c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com 618c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com fprintf(stderr, "Serializing font to %s\n", argv[argc - 1]); 628c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com SerializeFont(argv[argc - 1], new_font); 638c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com if (!new_font) { 648c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com fprintf(stdout, "Cannot create merged font.\n"); 658c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com return 1; 668c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com } 678c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com 688c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com return 0; 698c433a9f5819ad995a14c8476c266487c8a82f53dfilimon@google.com} 70