font_data.h revision 584bf6606b53bda8bf0810e7c0ad57e24cacb4f1
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_DATA_H_ 18#define SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_DATA_H_ 19 20#include <vector> 21 22#include "sfntly/port/type.h" 23#include "sfntly/data/byte_array.h" 24#include "sfntly/port/refcount.h" 25 26namespace sfntly { 27 28struct DataSize { 29 enum { 30 kBYTE = 1, 31 kCHAR = 1, 32 kUSHORT = 2, 33 kSHORT = 2, 34 kUINT24 = 3, 35 kULONG = 4, 36 kLONG = 4, 37 kFixed = 4, 38 kFUNIT = 4, 39 kFWORD = 2, 40 kUFWORD = 2, 41 kF2DOT14 = 2, 42 kLONGDATETIME = 8, 43 kTag = 4, 44 kGlyphID = 2, 45 kOffset = 2 46 }; 47}; 48 49class FontData : virtual public RefCount { 50 public: 51 // Gets the maximum size of the FontData. This is the maximum number of bytes 52 // that the font data can hold and all of it may not be filled with data or 53 // even fully allocated yet. 54 // @return the maximum size of this font data 55 virtual int32_t Size() const; 56 57 // Sets limits on the size of the FontData. The FontData is then only 58 // visible within the bounds set. 59 // @param offset the start of the new bounds 60 // @param length the number of bytes in the bounded array 61 // @return true if the bounding range was successful; false otherwise 62 virtual bool Bound(int32_t offset, int32_t length); 63 64 // Sets limits on the size of the FontData. This is a offset bound only so if 65 // the FontData is writable and growable then there is no limit to that growth 66 // from the bounding operation. 67 // @param offset the start of the new bounds which must be within the current 68 // size of the FontData 69 // @return true if the bounding range was successful; false otherwise 70 virtual bool Bound(int32_t offset); 71 72 // Makes a slice of this FontData. The returned slice will share the data with 73 // the original <code>FontData</code>. 74 // @param offset the start of the slice 75 // @param length the number of bytes in the slice 76 // @return a slice of the original FontData 77 virtual CALLER_ATTACH FontData* Slice(int32_t offset, int32_t length) = 0; 78 79 // Makes a bottom bound only slice of this array. The returned slice will 80 // share the data with the original <code>FontData</code>. 81 // @param offset the start of the slice 82 // @return a slice of the original FontData 83 virtual CALLER_ATTACH FontData* Slice(int32_t offset) = 0; 84 85 // Gets the length of the data. 86 virtual int32_t Length() const; 87 88 protected: 89 // Constructor. 90 // @param ba the byte array to use for the backing data 91 explicit FontData(ByteArray* ba); 92 93 // Constructor. 94 // @param data the data to wrap 95 // @param offset the offset to start the wrap from 96 // @param length the length of the data wrapped 97 FontData(FontData* data, int32_t offset, int32_t length); 98 99 // Constructor. 100 // @param data the data to wrap 101 // @param offset the offset to start the wrap from 102 FontData(FontData* data, int32_t offset); 103 virtual ~FontData(); 104 105 void Init(ByteArray* ba); 106 107 // Gets the offset in the underlying data taking into account any bounds on 108 // the data. 109 // @param offset the offset to get the bound compensated offset for 110 // @return the bound compensated offset 111 int32_t BoundOffset(int32_t offset); 112 113 // Gets the length in the underlying data taking into account any bounds on the data. 114 // @param offset the offset that the length is being used at 115 // @param length the length to get the bound compensated length for 116 // @return the bound compensated length 117 int32_t BoundLength(int32_t offset, int32_t length); 118 119 // TODO(arthurhsu): style guide violation: refactor this protected member 120 ByteArrayPtr array_; 121 122 private: 123 int32_t bound_offset_; 124 int32_t bound_length_; 125}; 126typedef Ptr<FontData> FontDataPtr; 127 128} // namespace sfntly 129 130#endif // SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_DATA_H_ 131