MinikinFontFreeType.h revision bcc3dc5a2591a95a57e379e27cbad69c18e91e67
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    bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const;
46
47    float GetHorizontalAdvance(uint32_t glyph_id,
48        const MinikinPaint &paint) const;
49
50    // If buf is NULL, just update size
51    bool GetTable(uint32_t tag, uint8_t *buf, size_t *size);
52
53    int32_t GetUniqueId() const;
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    int32_t mUniqueId;
66    static int32_t sIdCounter;
67};
68
69}  // namespace android
70
71#endif  // MINIKIN_FONT_FREETYPE_H
72