MinikinInternal.h revision aaa4e3470270496e6eb80704eadecb2cb7c56bf0
1/*
2 * Copyright (C) 2014 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// Definitions internal to Minikin
18
19#ifndef MINIKIN_INTERNAL_H
20#define MINIKIN_INTERNAL_H
21
22#include <hb.h>
23
24#include <utils/Mutex.h>
25
26#include <minikin/MinikinFont.h>
27
28namespace android {
29
30// All external Minikin interfaces are designed to be thread-safe.
31// Presently, that's implemented by through a global lock, and having
32// all external interfaces take that lock.
33
34extern Mutex gMinikinLock;
35
36// Aborts if gMinikinLock is not acquired. Do nothing on the release build.
37void assertMinikinLocked();
38
39// Returns true if c is emoji modifier base.
40bool isEmojiBase(uint32_t c);
41
42// Returns true if c is emoji modifier.
43bool isEmojiModifier(uint32_t c);
44
45hb_blob_t* getFontTable(MinikinFont* minikinFont, uint32_t tag);
46
47// An RAII wrapper for hb_blob_t
48class HbBlob {
49public:
50    // Takes ownership of hb_blob_t object, caller is no longer
51    // responsible for calling hb_blob_destroy().
52    HbBlob(hb_blob_t* blob) : mBlob(blob) {
53    }
54
55    ~HbBlob() {
56        hb_blob_destroy(mBlob);
57    }
58
59    const uint8_t* get() const {
60        const char* data = hb_blob_get_data(mBlob, nullptr);
61        return reinterpret_cast<const uint8_t*>(data);
62    }
63
64    size_t size() const {
65        unsigned int length = 0;
66        hb_blob_get_data(mBlob, &length);
67        return (size_t)length;
68    }
69
70private:
71    hb_blob_t* mBlob;
72};
73
74}
75
76#endif  // MINIKIN_INTERNAL_H
77