MinikinFontForTest.cpp revision 1c2bd209d11e59ea3a31d49ec4e97725fd711bea
1/*
2 * Copyright (C) 2015 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#include "MinikinFontForTest.h"
18
19#include <minikin/MinikinFont.h>
20
21#include <SkTypeface.h>
22
23#include <cutils/log.h>
24
25MinikinFontForTest::MinikinFontForTest(const std::string& font_path) : mFontPath(font_path) {
26    mTypeface = SkTypeface::CreateFromFile(font_path.c_str());
27}
28
29MinikinFontForTest::~MinikinFontForTest() {
30}
31
32bool MinikinFontForTest::GetGlyph(uint32_t codepoint, uint32_t *glyph) const {
33    LOG_ALWAYS_FATAL("MinikinFontForTest::GetGlyph is not yet implemented");
34    return false;
35}
36
37float MinikinFontForTest::GetHorizontalAdvance(
38        uint32_t glyph_id, const android::MinikinPaint &paint) const {
39    LOG_ALWAYS_FATAL("MinikinFontForTest::GetHorizontalAdvance is not yet implemented");
40    return 0.0f;
41}
42
43void MinikinFontForTest::GetBounds(android::MinikinRect* bounds, uint32_t glyph_id,
44        const android::MinikinPaint& paint) const {
45    LOG_ALWAYS_FATAL("MinikinFontForTest::GetBounds is not yet implemented");
46}
47
48bool MinikinFontForTest::GetTable(uint32_t tag, uint8_t *buf, size_t *size) {
49    if (buf == NULL) {
50        const size_t tableSize = mTypeface->getTableSize(tag);
51        *size = tableSize;
52        return tableSize != 0;
53    } else {
54        const size_t actualSize = mTypeface->getTableData(tag, 0, *size, buf);
55        *size = actualSize;
56        return actualSize != 0;
57    }
58}
59
60int32_t MinikinFontForTest::GetUniqueId() const {
61    return mTypeface->uniqueID();
62}
63