11c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka/*
21c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka * Copyright (C) 2015 The Android Open Source Project
31c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka *
41c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka * Licensed under the Apache License, Version 2.0 (the "License");
51c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka * you may not use this file except in compliance with the License.
61c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka * You may obtain a copy of the License at
71c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka *
81c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka *      http://www.apache.org/licenses/LICENSE-2.0
91c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka *
101c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka * Unless required by applicable law or agreed to in writing, software
111c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka * distributed under the License is distributed on an "AS IS" BASIS,
121c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka * See the License for the specific language governing permissions and
141c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka * limitations under the License.
151c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka */
161c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka
171c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka#include "MinikinFontForTest.h"
181c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka
191c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka#include <minikin/MinikinFont.h>
201c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka
211c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka#include <SkTypeface.h>
221c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka
231c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka#include <cutils/log.h>
241c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka
256c60831cfce24b0749f50f37231e0a56d8fd4b85Seigo NonakaMinikinFontForTest::MinikinFontForTest(const std::string& font_path) :
266c60831cfce24b0749f50f37231e0a56d8fd4b85Seigo Nonaka    MinikinFontForTest(font_path, SkTypeface::CreateFromFile(font_path.c_str())) {
276c60831cfce24b0749f50f37231e0a56d8fd4b85Seigo Nonaka}
286c60831cfce24b0749f50f37231e0a56d8fd4b85Seigo Nonaka
296c60831cfce24b0749f50f37231e0a56d8fd4b85Seigo NonakaMinikinFontForTest::MinikinFontForTest(const std::string& font_path, SkTypeface* typeface) :
306c60831cfce24b0749f50f37231e0a56d8fd4b85Seigo Nonaka    MinikinFont(typeface->uniqueID()),
316c60831cfce24b0749f50f37231e0a56d8fd4b85Seigo Nonaka    mTypeface(typeface),
326c60831cfce24b0749f50f37231e0a56d8fd4b85Seigo Nonaka    mFontPath(font_path) {
331c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka}
341c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka
351c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo NonakaMinikinFontForTest::~MinikinFontForTest() {
361c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka}
371c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka
38bae347682989d2627081310129a5b60541ed6ad0Seigo Nonakafloat MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */,
39bae347682989d2627081310129a5b60541ed6ad0Seigo Nonaka        const android::MinikinPaint& /* paint */) const {
401c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka    LOG_ALWAYS_FATAL("MinikinFontForTest::GetHorizontalAdvance is not yet implemented");
411c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka    return 0.0f;
421c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka}
431c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka
44bae347682989d2627081310129a5b60541ed6ad0Seigo Nonakavoid MinikinFontForTest::GetBounds(android::MinikinRect* /* bounds */, uint32_t /* glyph_id */,
45bae347682989d2627081310129a5b60541ed6ad0Seigo Nonaka        const android::MinikinPaint& /* paint */) const {
461c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka    LOG_ALWAYS_FATAL("MinikinFontForTest::GetBounds is not yet implemented");
471c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka}
481c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka
49aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levienconst void* MinikinFontForTest::GetTable(uint32_t tag, size_t* size,
50aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien        android::MinikinDestroyFunc* destroy) {
51aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    const size_t tableSize = mTypeface->getTableSize(tag);
52aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    *size = tableSize;
53aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    if (tableSize == 0) {
54aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien        return nullptr;
551c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka    }
56aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    void* buf = malloc(tableSize);
57aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    if (buf == nullptr) {
58aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien        return nullptr;
59aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    }
60aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    mTypeface->getTableData(tag, 0, tableSize, buf);
61aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    *destroy = free;
62aaa4e3470270496e6eb80704eadecb2cb7c56bf0Raph Levien    return buf;
631c2bd209d11e59ea3a31d49ec4e97725fd711beaSeigo Nonaka}
64