1 /* 2 * Copyright 2011 Google Inc. All Rights Reserved. 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 SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_OUTPUT_STREAM_H_ 18 #define SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_OUTPUT_STREAM_H_ 19 20 #include "sfntly/port/type.h" 21 #include "sfntly/port/output_stream.h" 22 23 namespace sfntly { 24 25 // An output stream for writing font data. 26 // The data types used are as listed: 27 // BYTE 8-bit unsigned integer. 28 // CHAR 8-bit signed integer. 29 // USHORT 16-bit unsigned integer. 30 // SHORT 16-bit signed integer. 31 // UINT24 24-bit unsigned integer. 32 // ULONG 32-bit unsigned integer. 33 // LONG 32-bit signed integer. 34 // Fixed 32-bit signed fixed-point number (16.16) 35 // FUNIT Smallest measurable distance in the em space. 36 // FWORD 16-bit signed integer (SHORT) that describes a quantity in FUnits. 37 // UFWORD 16-bit unsigned integer (USHORT) that describes a quantity in 38 // FUnits. 39 // F2DOT14 16-bit signed fixed number with the low 14 bits of fraction (2.14) 40 // LONGDATETIME Date represented in number of seconds since 12:00 midnight, 41 // January 1, 1904. The value is represented as a signed 64-bit 42 // integer. 43 44 // Note: The wrapped output stream is *NOT* reference counted (because it's 45 // meaningless to ref-count an I/O stream). 46 class FontOutputStream : public OutputStream { 47 public: 48 explicit FontOutputStream(OutputStream* os); 49 virtual ~FontOutputStream(); 50 51 virtual void Write(uint8_t b); 52 virtual void Write(std::vector<uint8_t>* b); 53 virtual void Write(std::vector<uint8_t>* b, int32_t off, int32_t len); 54 virtual void Write(uint8_t* b, int32_t off, int32_t len); 55 virtual void WriteChar(uint8_t c); 56 virtual void WriteUShort(int32_t us); 57 virtual void WriteShort(int32_t s); 58 virtual void WriteUInt24(int32_t ui); 59 virtual void WriteULong(int64_t ul); 60 virtual void WriteLong(int64_t l); 61 virtual void WriteFixed(int32_t l); 62 virtual void WriteDateTime(int64_t date); 63 64 // Note: C++ port only. 65 virtual void Flush(); 66 virtual void Close(); 67 68 private: 69 // Note: we do not use the variable name out as in Java because it has 70 // special meaning in VC++ and will be very confusing. 71 OutputStream* stream_; 72 size_t position_; 73 }; 74 75 } // namespace sfntly 76 77 #endif // SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_OUTPUT_STREAM_H_ 78