Home | History | Annotate | Download | only in data
      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 size_t position() { return position_; }
     52 
     53   virtual void Write(byte_t b);
     54   virtual void Write(ByteVector* b);
     55   virtual void Write(ByteVector* b, int32_t off, int32_t len);
     56   virtual void Write(byte_t* b, int32_t off, int32_t len);
     57   virtual void WriteChar(byte_t c);
     58   virtual void WriteUShort(int32_t us);
     59   virtual void WriteShort(int32_t s);
     60   virtual void WriteUInt24(int32_t ui);
     61   virtual void WriteULong(int64_t ul);
     62   virtual void WriteLong(int64_t l);
     63   virtual void WriteFixed(int32_t l);
     64   virtual void WriteDateTime(int64_t date);
     65 
     66   // Note: C++ port only.
     67   virtual void Flush();
     68   virtual void Close();
     69 
     70  private:
     71   // Note: we do not use the variable name out as in Java because it has
     72   //       special meaning in VC++ and will be very confusing.
     73   OutputStream* stream_;
     74   size_t position_;
     75 };
     76 
     77 }  // namespace sfntly
     78 
     79 #endif  // SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_OUTPUT_STREAM_H_
     80