1b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien/*
2b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien * Copyright (C) 2014 The Android Open Source Project
3b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien *
4b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien * Licensed under the Apache License, Version 2.0 (the "License");
5b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien * you may not use this file except in compliance with the License.
6b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien * You may obtain a copy of the License at
7b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien *
8b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien *      http://www.apache.org/licenses/LICENSE-2.0
9b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien *
10b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien * Unless required by applicable law or agreed to in writing, software
11b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien * distributed under the License is distributed on an "AS IS" BASIS,
12b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien * See the License for the specific language governing permissions and
14b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien * limitations under the License.
15b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien */
16b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien
17b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien// Definitions internal to Minikin
18b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien
19b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien#ifndef MINIKIN_INTERNAL_H
20b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien#define MINIKIN_INTERNAL_H
21b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien
22aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien#include <hb.h>
23aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien
24b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien#include <utils/Mutex.h>
25b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien
26aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien#include <minikin/MinikinFont.h>
27aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien
28b80c1f19c58b927820a8a24bf2218e5645724608Raph Leviennamespace android {
29b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien
30b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien// All external Minikin interfaces are designed to be thread-safe.
31b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien// Presently, that's implemented by through a global lock, and having
32b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien// all external interfaces take that lock.
33b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien
34b80c1f19c58b927820a8a24bf2218e5645724608Raph Levienextern Mutex gMinikinLock;
35b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien
36fb0d396929e534a3686469b474d4f670864aa5acSeigo Nonaka// Aborts if gMinikinLock is not acquired. Do nothing on the release build.
37fb0d396929e534a3686469b474d4f670864aa5acSeigo Nonakavoid assertMinikinLocked();
38fb0d396929e534a3686469b474d4f670864aa5acSeigo Nonaka
3977f488345316fba46c271fc04bea470819ae1712Seigo Nonaka// Returns true if c is emoji.
4077f488345316fba46c271fc04bea470819ae1712Seigo Nonakabool isEmoji(uint32_t c);
4177f488345316fba46c271fc04bea470819ae1712Seigo Nonaka
420036da164e3b25f1ac29c840c1fe15b03dc6677fSeigo Nonaka// Returns true if c is emoji modifier base.
430036da164e3b25f1ac29c840c1fe15b03dc6677fSeigo Nonakabool isEmojiBase(uint32_t c);
440036da164e3b25f1ac29c840c1fe15b03dc6677fSeigo Nonaka
450036da164e3b25f1ac29c840c1fe15b03dc6677fSeigo Nonaka// Returns true if c is emoji modifier.
460036da164e3b25f1ac29c840c1fe15b03dc6677fSeigo Nonakabool isEmojiModifier(uint32_t c);
470036da164e3b25f1ac29c840c1fe15b03dc6677fSeigo Nonaka
48aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levienhb_blob_t* getFontTable(MinikinFont* minikinFont, uint32_t tag);
49aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien
50aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien// An RAII wrapper for hb_blob_t
51aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levienclass HbBlob {
52aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levienpublic:
53aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    // Takes ownership of hb_blob_t object, caller is no longer
54aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    // responsible for calling hb_blob_destroy().
55aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    HbBlob(hb_blob_t* blob) : mBlob(blob) {
56aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    }
57aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien
58aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    ~HbBlob() {
59aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien        hb_blob_destroy(mBlob);
60aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    }
61aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien
62aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    const uint8_t* get() const {
63aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien        const char* data = hb_blob_get_data(mBlob, nullptr);
64aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien        return reinterpret_cast<const uint8_t*>(data);
65aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    }
66aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien
67aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    size_t size() const {
68aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien        unsigned int length = 0;
69aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien        hb_blob_get_data(mBlob, &length);
70aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien        return (size_t)length;
71aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    }
72aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien
73aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levienprivate:
74aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    hb_blob_t* mBlob;
75aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien};
76aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien
77b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien}
78b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien
79b80c1f19c58b927820a8a24bf2218e5645724608Raph Levien#endif  // MINIKIN_INTERNAL_H
80