MinikinFontForTest.cpp revision 5e6bc85d69a97d8db6c068e56614aaac02da347a
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 25namespace minikin { 26 27// static 28MinikinFontForTest* MinikinFontForTest::createFromFile(const std::string& font_path) { 29 SkTypeface* typeface = SkTypeface::CreateFromFile(font_path.c_str()); 30 MinikinFontForTest* font = new MinikinFontForTest(font_path, typeface); 31 SkSafeUnref(typeface); 32 return font; 33} 34 35// static 36MinikinFontForTest* MinikinFontForTest::createFromFileWithIndex(const std::string& font_path, 37 int index) { 38 SkTypeface* typeface = SkTypeface::CreateFromFile(font_path.c_str(), index); 39 MinikinFontForTest* font = new MinikinFontForTest(font_path, typeface); 40 SkSafeUnref(typeface); 41 return font; 42} 43 44MinikinFontForTest::MinikinFontForTest(const std::string& font_path, SkTypeface* typeface) : 45 MinikinFont(typeface->uniqueID()), 46 mTypeface(typeface), 47 mFontPath(font_path) { 48 SkSafeRef(mTypeface); 49} 50 51MinikinFontForTest::~MinikinFontForTest() { 52 SkSafeUnref(mTypeface); 53} 54 55float MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */, 56 const MinikinPaint& /* paint */) const { 57 LOG_ALWAYS_FATAL("MinikinFontForTest::GetHorizontalAdvance is not yet implemented"); 58 return 0.0f; 59} 60 61void MinikinFontForTest::GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_id */, 62 const MinikinPaint& /* paint */) const { 63 LOG_ALWAYS_FATAL("MinikinFontForTest::GetBounds is not yet implemented"); 64} 65 66const void* MinikinFontForTest::GetTable(uint32_t tag, size_t* size, 67 MinikinDestroyFunc* destroy) { 68 const size_t tableSize = mTypeface->getTableSize(tag); 69 *size = tableSize; 70 if (tableSize == 0) { 71 return nullptr; 72 } 73 void* buf = malloc(tableSize); 74 if (buf == nullptr) { 75 return nullptr; 76 } 77 mTypeface->getTableData(tag, 0, tableSize, buf); 78 *destroy = free; 79 return buf; 80} 81 82} // namespace minikin 83