MinikinFont.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_H
18#define MINIKIN_FONT_H
19
20// An abstraction for platform fonts, allowing Minikin to be used with
21// multiple actual implementations of fonts.
22
23namespace android {
24
25class MinikinFont;
26
27// Possibly move into own .h file?
28struct MinikinPaint {
29    MinikinFont *font;
30    float size;
31    // todo: skew, stretch, hinting
32};
33
34class MinikinFontFreeType;
35
36class MinikinFont {
37public:
38    void Ref() { mRefcount_++; }
39    void Unref() { if (--mRefcount_ == 0) { delete this; } }
40
41    //MinikinFont();
42    virtual ~MinikinFont() = 0;
43
44    virtual bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const = 0;
45
46    virtual float GetHorizontalAdvance(uint32_t glyph_id,
47        const MinikinPaint &paint) const = 0;
48
49    // If buf is NULL, just update size
50    virtual bool GetTable(uint32_t tag, uint8_t *buf, size_t *size) = 0;
51
52    virtual int32_t GetUniqueId() const = 0;
53
54    static uint32_t MakeTag(char c1, char c2, char c3, char c4) {
55        return ((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) |
56            ((uint32_t)c3 << 8) | (uint32_t)c4;
57    }
58
59    // This is used to implement a downcast without RTTI
60    virtual MinikinFontFreeType* GetFreeType() {
61        return NULL;
62    }
63
64private:
65    int mRefcount_;
66};
67
68}  // namespace android
69
70#endif  // MINIKIN_FONT_H
71