MinikinFontFreeType.h revision 6c60831cfce24b0749f50f37231e0a56d8fd4b85
1/*
2 * Copyright (C) 2013 The Android Open Source Project
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 MINIKIN_FONT_FREETYPE_H
18#define MINIKIN_FONT_FREETYPE_H
19
20#include <ft2build.h>
21#include FT_FREETYPE_H
22#include FT_TRUETYPE_TABLES_H
23
24#include <minikin/MinikinFont.h>
25
26// An abstraction for platform fonts, allowing Minikin to be used with
27// multiple actual implementations of fonts.
28
29namespace android {
30
31struct GlyphBitmap {
32    uint8_t *buffer;
33    int width;
34    int height;
35    int left;
36    int top;
37};
38
39class MinikinFontFreeType : public MinikinFont {
40public:
41    explicit MinikinFontFreeType(FT_Face typeface);
42
43    ~MinikinFontFreeType();
44
45    float GetHorizontalAdvance(uint32_t glyph_id,
46        const MinikinPaint &paint) const;
47
48    void GetBounds(MinikinRect* bounds, uint32_t glyph_id,
49        const MinikinPaint& paint) const;
50
51    const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy);
52
53    // TODO: provide access to raw data, as an optimization.
54
55    // Not a virtual method, as the protocol to access rendered
56    // glyph bitmaps is probably different depending on the
57    // backend.
58    bool Render(uint32_t glyph_id,
59        const MinikinPaint &paint, GlyphBitmap *result);
60
61    MinikinFontFreeType* GetFreeType();
62
63private:
64    FT_Face mTypeface;
65    static int32_t sIdCounter;
66};
67
68}  // namespace android
69
70#endif  // MINIKIN_FONT_FREETYPE_H
71