MinikinFontForTest.cpp 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "MinikinFontForTest.h"

#include <minikin/MinikinFont.h>

#include <SkTypeface.h>

#include <cutils/log.h>

S
Seigo Nonaka 已提交
25 26
namespace minikin {

S
Seigo Nonaka 已提交
27 28 29 30 31 32
// static
MinikinFontForTest* MinikinFontForTest::createFromFile(const std::string& font_path) {
    SkTypeface* typeface = SkTypeface::CreateFromFile(font_path.c_str());
    MinikinFontForTest* font = new MinikinFontForTest(font_path, typeface);
    SkSafeUnref(typeface);
    return font;
S
Seigo Nonaka 已提交
33 34 35
}

MinikinFontForTest::MinikinFontForTest(const std::string& font_path, SkTypeface* typeface) :
S
Seigo Nonaka 已提交
36 37 38 39
        MinikinFont(typeface->uniqueID()),
        mTypeface(typeface),
        mFontPath(font_path) {
    SkSafeRef(mTypeface);
40 41 42
}

MinikinFontForTest::~MinikinFontForTest() {
S
Seigo Nonaka 已提交
43
    SkSafeUnref(mTypeface);
44 45
}

46
float MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */,
S
Seigo Nonaka 已提交
47
        const MinikinPaint& /* paint */) const {
48 49 50 51
    LOG_ALWAYS_FATAL("MinikinFontForTest::GetHorizontalAdvance is not yet implemented");
    return 0.0f;
}

S
Seigo Nonaka 已提交
52 53
void MinikinFontForTest::GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_id */,
        const MinikinPaint& /* paint */) const {
54 55 56
    LOG_ALWAYS_FATAL("MinikinFontForTest::GetBounds is not yet implemented");
}

R
Raph Levien 已提交
57
const void* MinikinFontForTest::GetTable(uint32_t tag, size_t* size,
S
Seigo Nonaka 已提交
58
        MinikinDestroyFunc* destroy) {
R
Raph Levien 已提交
59 60 61 62
    const size_t tableSize = mTypeface->getTableSize(tag);
    *size = tableSize;
    if (tableSize == 0) {
        return nullptr;
63
    }
R
Raph Levien 已提交
64 65 66 67 68 69 70
    void* buf = malloc(tableSize);
    if (buf == nullptr) {
        return nullptr;
    }
    mTypeface->getTableData(tag, 0, tableSize, buf);
    *destroy = free;
    return buf;
71
}
S
Seigo Nonaka 已提交
72 73

}  // namespace minikin