summaryrefslogtreecommitdiff
path: root/sample/chromium/subsetter_impl.h
blob: ffbf408f9c7f6b9c76ead11322be54e14300c206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * Copyright 2011 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// File is originally from Chromium third_party/sfntly/src/subsetter.
// Use as test case in sfntly so that problems can be caught in upstream early.

#ifndef SFNTLY_CPP_SRC_TEST_SUBSETTER_IMPL_H_
#define SFNTLY_CPP_SRC_TEST_SUBSETTER_IMPL_H_

#include "sfntly/font.h"
#include "sfntly/font_factory.h"
#include "sfntly/table/truetype/glyph_table.h"
#include "sfntly/table/truetype/loca_table.h"
#include "sfntly/tag.h"

namespace sfntly {

// Smart pointer usage in sfntly:
//
// sfntly carries a smart pointer implementation like COM.  Ref-countable object
// type inherits from RefCounted<>, which have AddRef and Release just like
// IUnknown (but no QueryInterface).  Use a Ptr<> based smart pointer to hold
// the object so that the object ref count is handled correctly.
//
// class Foo : public RefCounted<Foo> {
//  public:
//   static Foo* CreateInstance() {
//     Ptr<Foo> obj = new Foo();  // ref count = 1
//     return obj.detach();
//   }
// };
// typedef Ptr<Foo> FooPtr;  // common short-hand notation
// FooPtr obj;
// obj.attach(Foo::CreatedInstance());  // ref count = 1
// {
//   FooPtr obj2 = obj;  // ref count = 2
// }  // ref count = 1, obj2 out of scope
// obj.release();  // ref count = 0, object destroyed

class SubsetterImpl {
 public:
  SubsetterImpl();
  ~SubsetterImpl();

  bool LoadFont(const char* font_name,
                const unsigned char* original_font,
                size_t font_size);
  int SubsetFont(const unsigned int* glyph_ids,
                 size_t glyph_count,
                 unsigned char** output_buffer);

 private:
  CALLER_ATTACH Font* Subset(const IntegerSet& glyph_ids,
                             GlyphTable* glyf, LocaTable* loca);

  FontFactoryPtr factory_;
  FontPtr font_;
};

}  // namespace sfntly

#endif  // SFNTLY_CPP_SRC_TEST_SUBSETTER_IMPL_H_