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// File is originally from Chromium third_party/sfntly/src/subsetter.
17// Use as test case in sfntly so that problems can be caught in upstream early.
18
19#ifndef SFNTLY_CPP_SRC_TEST_SUBSETTER_IMPL_H_
20#define SFNTLY_CPP_SRC_TEST_SUBSETTER_IMPL_H_
21
22#include "sfntly/font.h"
23#include "sfntly/font_factory.h"
24#include "sfntly/table/truetype/glyph_table.h"
25#include "sfntly/table/truetype/loca_table.h"
26#include "sfntly/tag.h"
27
28namespace sfntly {
29
30// Smart pointer usage in sfntly:
31//
32// sfntly carries a smart pointer implementation like COM.  Ref-countable object
33// type inherits from RefCounted<>, which have AddRef and Release just like
34// IUnknown (but no QueryInterface).  Use a Ptr<> based smart pointer to hold
35// the object so that the object ref count is handled correctly.
36//
37// class Foo : public RefCounted<Foo> {
38//  public:
39//   static Foo* CreateInstance() {
40//     Ptr<Foo> obj = new Foo();  // ref count = 1
41//     return obj.detach();
42//   }
43// };
44// typedef Ptr<Foo> FooPtr;  // common short-hand notation
45// FooPtr obj;
46// obj.attach(Foo::CreatedInstance());  // ref count = 1
47// {
48//   FooPtr obj2 = obj;  // ref count = 2
49// }  // ref count = 1, obj2 out of scope
50// obj.release();  // ref count = 0, object destroyed
51
52class SubsetterImpl {
53 public:
54  SubsetterImpl();
55  ~SubsetterImpl();
56
57  bool LoadFont(const char* font_name,
58                const unsigned char* original_font,
59                size_t font_size);
60  int SubsetFont(const unsigned int* glyph_ids,
61                 size_t glyph_count,
62                 unsigned char** output_buffer);
63
64 private:
65  CALLER_ATTACH Font* Subset(const IntegerSet& glyph_ids,
66                             GlyphTable* glyf, LocaTable* loca);
67
68  FontFactoryPtr factory_;
69  FontPtr font_;
70};
71
72}  // namespace sfntly
73
74#endif  // SFNTLY_CPP_SRC_TEST_SUBSETTER_IMPL_H_
75