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 "subtly/subsetter.h" 18 19 #include <stdio.h> 20 21 #include "sfntly/font.h" 22 #include "sfntly/font_factory.h" 23 #include "sfntly/tag.h" 24 #include "subtly/character_predicate.h" 25 #include "subtly/font_assembler.h" 26 #include "subtly/font_info.h" 27 #include "subtly/utils.h" 28 29 namespace subtly { 30 using namespace sfntly; 31 32 /****************************************************************************** 33 * Subsetter class 34 ******************************************************************************/ 35 Subsetter::Subsetter(Font* font, CharacterPredicate* predicate) 36 : font_(font), 37 predicate_(predicate) { 38 } 39 40 Subsetter::Subsetter(const char* font_path, CharacterPredicate* predicate) 41 : predicate_(predicate) { 42 font_.Attach(LoadFont(font_path)); 43 } 44 45 CALLER_ATTACH Font* Subsetter::Subset() { 46 Ptr<FontSourcedInfoBuilder> info_builder = 47 new FontSourcedInfoBuilder(font_, 0, predicate_); 48 49 Ptr<FontInfo> font_info; 50 font_info.Attach(info_builder->GetFontInfo()); 51 if (!font_info) { 52 #if defined (SUBTLY_DEBUG) 53 fprintf(stderr, 54 "Couldn't create font info. No subset will be generated.\n"); 55 #endif 56 return NULL; 57 } 58 IntegerSet* table_blacklist = new IntegerSet; 59 table_blacklist->insert(Tag::DSIG); 60 Ptr<FontAssembler> font_assembler = new FontAssembler(font_info, 61 table_blacklist); 62 Ptr<Font> font_subset; 63 font_subset.Attach(font_assembler->Assemble()); 64 delete table_blacklist; 65 return font_subset.Detach(); 66 } 67 } 68