MinikinFont.h revision f660ef9ee63a500b7fb878e502ea5fd519c39607
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    virtual ~MinikinFont() { };
42
43    virtual bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const = 0;
44
45    virtual float GetHorizontalAdvance(uint32_t glyph_id,
46        const MinikinPaint &paint) const = 0;
47
48    // If buf is NULL, just update size
49    virtual bool GetTable(uint32_t tag, uint8_t *buf, size_t *size) = 0;
50
51    virtual int32_t GetUniqueId() const = 0;
52
53    static uint32_t MakeTag(char c1, char c2, char c3, char c4) {
54        return ((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) |
55            ((uint32_t)c3 << 8) | (uint32_t)c4;
56    }
57
58    // This is used to implement a downcast without RTTI
59    virtual MinikinFontFreeType* GetFreeType() {
60        return NULL;
61    }
62
63private:
64    int mRefcount_;
65};
66
67}  // namespace android
68
69#endif  // MINIKIN_FONT_H
70