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_INPUT_STREAM_H_ 18#define SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_INPUT_STREAM_H_ 19 20#include "sfntly/port/type.h" 21#include "sfntly/port/input_stream.h" 22 23namespace sfntly { 24 25// An input stream for reading 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: Original class inherits from Java's FilterOutputStream, which wraps 45// an InputStream within. In C++, we directly do the wrapping without 46// defining another layer of abstraction. The wrapped output stream is 47// *NOT* reference counted (because it's meaningless to ref-count an I/O 48// stream). 49class FontInputStream : public InputStream { 50 public: 51 // Constructor. 52 // @param is input stream to wrap 53 explicit FontInputStream(InputStream* is); 54 55 // Constructor for a bounded font input stream. 56 // @param is input stream to wrap 57 // @param length the maximum length of bytes to read 58 FontInputStream(InputStream* is, size_t length); 59 60 virtual ~FontInputStream(); 61 62 63 virtual int32_t Available(); 64 virtual void Close(); 65 virtual void Mark(int32_t readlimit); 66 virtual bool MarkSupported(); 67 virtual void Reset(); 68 69 virtual int32_t Read(); 70 virtual int32_t Read(ByteVector* buffer); 71 virtual int32_t Read(ByteVector* buffer, int32_t offset, int32_t length); 72 73 // Get the current position in the stream in bytes. 74 // @return the current position in bytes 75 virtual int64_t position() { return position_; } 76 77 virtual int32_t ReadChar(); 78 virtual int32_t ReadUShort(); 79 virtual int32_t ReadShort(); 80 virtual int32_t ReadUInt24(); 81 virtual int64_t ReadULong(); 82 virtual int32_t ReadULongAsInt(); 83 virtual int32_t ReadLong(); 84 virtual int32_t ReadFixed(); 85 virtual int64_t ReadDateTimeAsLong(); 86 virtual int64_t Skip(int64_t n); // n can be negative. 87 88 private: 89 InputStream* stream_; 90 int64_t position_; 91 int64_t length_; // Bound on length of data to read. 92 bool bounded_; 93}; 94 95} // namespace sfntly 96 97#endif // SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_INPUT_STREAM_H_ 98