1 /* 2 * Copyright (C) 2021 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 #ifndef MINIKIN_FONT_FILE_PARSER_H 18 #define MINIKIN_FONT_FILE_PARSER_H 19 20 #include "minikin/HbUtils.h" 21 22 #include <optional> 23 #include <string> 24 25 namespace minikin { 26 27 // FontFileParser provides various parser logic for OpenType font file. 28 class FontFileParser { 29 public: 30 // This class does not take an ownership of buffer. Caller must free it. 31 FontFileParser(const void* buffer, size_t size, uint32_t index); 32 explicit FontFileParser(const HbFaceUniquePtr& face); 33 explicit FontFileParser(const HbFontUniquePtr& font); 34 35 virtual ~FontFileParser(); 36 37 std::optional<uint32_t> getFontRevision() const; 38 std::optional<std::string> getPostScriptName() const; 39 std::optional<bool> isPostScriptType1Font() const; 40 41 protected: // protected for testing purposes. 42 static bool analyzeFontRevision(const uint8_t* head_data, size_t head_size, uint32_t* out); 43 static bool checkPSName(const std::string& psName); 44 45 private: 46 HbFaceUniquePtr mFace; 47 48 static HbFaceUniquePtr makeHbFace(const void* buffer, size_t size, uint32_t index); 49 }; 50 51 } // namespace minikin 52 53 #endif // MINIKIN_FONT_FILE_PARSER_H 54