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 25 MinikinFontForTest::MinikinFontForTest(const std::string& font_path) : 26 MinikinFontForTest(font_path, SkTypeface::CreateFromFile(font_path.c_str())) { 27 } 28 29 MinikinFontForTest::MinikinFontForTest(const std::string& font_path, SkTypeface* typeface) : 30 MinikinFont(typeface->uniqueID()), 31 mTypeface(typeface), 32 mFontPath(font_path) { 33 } 34 35 MinikinFontForTest::~MinikinFontForTest() { 36 } 37 38 float MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */, 39 const android::MinikinPaint& /* paint */) const { 40 LOG_ALWAYS_FATAL("MinikinFontForTest::GetHorizontalAdvance is not yet implemented"); 41 return 0.0f; 42 } 43 44 void MinikinFontForTest::GetBounds(android::MinikinRect* /* bounds */, uint32_t /* glyph_id */, 45 const android::MinikinPaint& /* paint */) const { 46 LOG_ALWAYS_FATAL("MinikinFontForTest::GetBounds is not yet implemented"); 47 } 48 49 const void* MinikinFontForTest::GetTable(uint32_t tag, size_t* size, 50 android::MinikinDestroyFunc* destroy) { 51 const size_t tableSize = mTypeface->getTableSize(tag); 52 *size = tableSize; 53 if (tableSize == 0) { 54 return nullptr; 55 } 56 void* buf = malloc(tableSize); 57 if (buf == nullptr) { 58 return nullptr; 59 } 60 mTypeface->getTableData(tag, 0, tableSize, buf); 61 *destroy = free; 62 return buf; 63 } 64