1 /* 2 * Copyright (C) 2022 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_MINIKIN_FONT_FACTORY_H 18 #define MINIKIN_MINIKIN_FONT_FACTORY_H 19 20 #include "minikin/Buffer.h" 21 #include "minikin/MinikinFont.h" 22 23 namespace minikin { 24 25 // A class to serialize / deserialize MinikinFont instance into / from memory buffer. 26 class MinikinFontFactory { 27 public: MinikinFontFactory()28 MinikinFontFactory() {} 29 30 virtual ~MinikinFontFactory() = 0; 31 32 // Create MinikinFont instance from the buffer. 33 virtual std::shared_ptr<MinikinFont> create(BufferReader reader) const = 0; 34 35 // Skip a MinikinFont region in the buffer and advance the reader to the 36 // next position. 37 virtual void skip(BufferReader* reader) const = 0; 38 39 // Serialize MinikinFont into the buffer. 40 virtual void write(BufferWriter* writer, const MinikinFont* minikinFont) const = 0; 41 42 // Return the singleton MinikinFontFactory instance. 43 // setInstance() must be called before any MinikinFont instance is 44 // serialized or deserialized. 45 static const MinikinFontFactory& getInstance(); 46 47 // Set the factory instance. 48 // The factory must be a singleton and cannot be changed during the process lifetime. 49 // It is safe to call this method multiple times with the same instance. 50 // This method itself is not thread safe. The call to this method, as well 51 // as deserialized MinikinFont objects, must be synchronized by the caller. 52 static void setInstance(const MinikinFontFactory* factory); 53 }; 54 55 } // namespace minikin 56 57 #endif // MINIKIN_MINIKIN_FONT_FACTORY_H 58