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 #ifndef SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_SUBSETTER_H_
18 #define SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_SUBSETTER_H_
19 
20 #include <vector>
21 
22 #include "sfntly/font.h"
23 #include "sfntly/font_factory.h"
24 #include "sfntly/table/core/cmap_table.h"
25 #include "sfntly/tools/subsetter/table_subsetter.h"
26 
27 namespace sfntly {
28 
29 class Subsetter : public RefCounted<Subsetter> {
30  public:
31   Subsetter(Font* font, FontFactory* font_factory);
32   virtual ~Subsetter();
33 
34   virtual void SetGlyphs(IntegerList* glyphs);
35 
36   // Set the cmaps to be used in the subsetted font. The cmaps are listed in
37   // order of priority and the number parameter gives a count of how many of the
38   // list should be put into the subsetted font. If there are no matches in the
39   // font for any of the provided cmap ids which would lead to a font with no
40   // cmap then an error will be thrown during subsetting.
41   // The two most common cases would be: <list>
42   // * a list of one or more cmap ids with a count setting of 1
43   //     This will use the list of cmap ids as an ordered priority and look for
44   //     an available cmap in the font that matches the requests. Only the first
45   //     such match will be placed in the subsetted font.
46   // * a list of one or more cmap ids with a count setting equal to the list
47   //   length
48   //     This will use the list of cmap ids and try to place each one specified
49   //     into the subsetted font.
50   // @param cmapIds the cmap ids to use for the subsetted font
51   // @param number the maximum number of cmaps to place in the subsetted font
52   virtual void SetCMaps(CMapIdList* cmap_ids, int32_t number);
53 
54   virtual void SetRemoveTables(IntegerSet* remove_tables);
55   virtual CALLER_ATTACH Font::Builder* Subset();
56   virtual IntegerList* GlyphPermutationTable();
57   virtual CMapIdList* CMapId();
58 
59  private:
60   FontPtr font_;
61   FontFactoryPtr font_factory_;
62   TableSubsetterList table_subsetters_;
63 
64   // Settings from user
65   IntegerSet remove_tables_;
66   IntegerList new_to_old_glyphs_;
67   CMapIdList cmap_ids_;
68 };
69 
70 }  // namespace sfntly
71 
72 #endif  // SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_SUBSETTER_H_
73