aboutsummaryrefslogtreecommitdiff
path: root/cpp/src/sfntly/data
diff options
context:
space:
mode:
authorarthurhsu <arthurhsu@google.com>2011-08-01 17:26:13 +0000
committerarthurhsu <arthurhsu@google.com>2011-08-01 17:26:13 +0000
commitc143ecb4bbc4f3ccca5145dc2b17cc20ca738efe (patch)
treeb7e3b5ad39b34540771daaca53ef56a6a8412564 /cpp/src/sfntly/data
parent2cc640e879459497a8974015a569ec5645ea9bdd (diff)
downloadsfntly-c143ecb4bbc4f3ccca5145dc2b17cc20ca738efe.tar.gz
Readability clean up. The code conforms to Google C++ Coding Style.
Diffstat (limited to 'cpp/src/sfntly/data')
-rw-r--r--cpp/src/sfntly/data/byte_array.cc118
-rw-r--r--cpp/src/sfntly/data/byte_array.h80
-rw-r--r--cpp/src/sfntly/data/font_data.cc60
-rw-r--r--cpp/src/sfntly/data/font_data.h25
-rw-r--r--cpp/src/sfntly/data/font_input_stream.cc80
-rw-r--r--cpp/src/sfntly/data/font_input_stream.h40
-rw-r--r--cpp/src/sfntly/data/font_output_stream.cc80
-rw-r--r--cpp/src/sfntly/data/font_output_stream.h32
-rw-r--r--cpp/src/sfntly/data/growable_memory_byte_array.cc33
-rw-r--r--cpp/src/sfntly/data/growable_memory_byte_array.h16
-rw-r--r--cpp/src/sfntly/data/memory_byte_array.cc47
-rw-r--r--cpp/src/sfntly/data/memory_byte_array.h18
-rw-r--r--cpp/src/sfntly/data/readable_font_data.cc230
-rw-r--r--cpp/src/sfntly/data/readable_font_data.h95
-rw-r--r--cpp/src/sfntly/data/writable_font_data.cc115
-rw-r--r--cpp/src/sfntly/data/writable_font_data.h41
16 files changed, 576 insertions, 534 deletions
diff --git a/cpp/src/sfntly/data/byte_array.cc b/cpp/src/sfntly/data/byte_array.cc
index b8c3717..5502185 100644
--- a/cpp/src/sfntly/data/byte_array.cc
+++ b/cpp/src/sfntly/data/byte_array.cc
@@ -14,52 +14,38 @@
* limitations under the License.
*/
+#include "sfntly/data/byte_array.h"
+
#include <algorithm>
-#include "sfntly/data/byte_array.h"
#include "sfntly/port/exception_type.h"
namespace sfntly {
const int32_t ByteArray::COPY_BUFFER_SIZE = 8192;
-void ByteArray::init(int32_t filled_length, int32_t storage_length,
- bool growable) {
- storage_length_ = storage_length;
- growable_ = growable;
- setFilledLength(filled_length);
-}
-
-ByteArray::ByteArray(int32_t filled_length, int32_t storage_length,
- bool growable) {
- init(filled_length, storage_length, growable);
-}
-
-ByteArray::ByteArray(int32_t filled_length, int32_t storage_length) {
- init(filled_length, storage_length, false);
-}
-
ByteArray::~ByteArray() {}
-int32_t ByteArray::length() { return filled_length_; }
-int32_t ByteArray::size() { return storage_length_; }
-bool ByteArray::growable() { return growable_; }
+int32_t ByteArray::Length() { return filled_length_; }
+int32_t ByteArray::Size() { return storage_length_; }
-int32_t ByteArray::setFilledLength(int32_t filled_length) {
+int32_t ByteArray::SetFilledLength(int32_t filled_length) {
filled_length_ = std::min<int32_t>(filled_length, storage_length_);
return filled_length_;
}
-byte_t ByteArray::get(int32_t index) {
- return internalGet(index);
+byte_t ByteArray::Get(int32_t index) {
+ return InternalGet(index);
}
-int32_t ByteArray::get(int32_t index, ByteVector* b) {
+int32_t ByteArray::Get(int32_t index, ByteVector* b) {
assert(b);
- return get(index, b, 0, b->size());
+ return Get(index, b, 0, b->size());
}
-int32_t ByteArray::get(int32_t index, ByteVector* b, int32_t offset,
+int32_t ByteArray::Get(int32_t index,
+ ByteVector* b,
+ int32_t offset,
int32_t length) {
assert(b);
if (index < 0 || index >= filled_length_) {
@@ -69,47 +55,49 @@ int32_t ByteArray::get(int32_t index, ByteVector* b, int32_t offset,
if (actual_length < 0) {
return -1;
}
- return internalGet(index, b, offset, actual_length);
+ return InternalGet(index, b, offset, actual_length);
}
-bool ByteArray::put(int32_t index, byte_t b) {
- if (index < 0 || index >= size()) {
+bool ByteArray::Put(int32_t index, byte_t b) {
+ if (index < 0 || index >= Size()) {
return false;
}
- bool result = internalPut(index, b);
+ bool result = InternalPut(index, b);
filled_length_ = std::max<int32_t>(filled_length_, index + 1);
return result;
}
-int32_t ByteArray::put(int index, ByteVector* b) {
+int32_t ByteArray::Put(int index, ByteVector* b) {
assert(b);
- return put(index, b, 0, b->size());
+ return Put(index, b, 0, b->size());
}
-int32_t ByteArray::put(int32_t index, ByteVector* b, int32_t offset,
+int32_t ByteArray::Put(int32_t index,
+ ByteVector* b,
+ int32_t offset,
int32_t length) {
assert(b);
- if (index < 0 || index >= size()) {
+ if (index < 0 || index >= Size()) {
return 0;
}
- int32_t actual_length = std::min<int32_t>(length, size() - index);
- int32_t bytes_written = internalPut(index, b, offset, actual_length);
+ int32_t actual_length = std::min<int32_t>(length, Size() - index);
+ int32_t bytes_written = InternalPut(index, b, offset, actual_length);
filled_length_ = std::max<int32_t>(filled_length_, index + bytes_written);
return bytes_written;
}
-int32_t ByteArray::copyTo(ByteArray* array) {
- return copyTo(array, 0, length());
+int32_t ByteArray::CopyTo(ByteArray* array) {
+ return CopyTo(array, 0, Length());
}
-int32_t ByteArray::copyTo(ByteArray* array, int32_t offset, int32_t length) {
- return copyTo(0, array, offset, length);
+int32_t ByteArray::CopyTo(ByteArray* array, int32_t offset, int32_t length) {
+ return CopyTo(0, array, offset, length);
}
-int32_t ByteArray::copyTo(int32_t dst_offset, ByteArray* array,
+int32_t ByteArray::CopyTo(int32_t dst_offset, ByteArray* array,
int32_t src_offset, int32_t length) {
assert(array);
- if (array->size() < dst_offset + length) { // insufficient space
+ if (array->Size() < dst_offset + length) { // insufficient space
return -1;
}
@@ -118,8 +106,8 @@ int32_t ByteArray::copyTo(int32_t dst_offset, ByteArray* array,
int32_t index = 0;
int32_t remaining_length = length;
int32_t buffer_length = std::min<int32_t>(COPY_BUFFER_SIZE, length);
- while ((bytes_read = get(index + src_offset, &b, 0, buffer_length)) > 0) {
- int bytes_written = array->put(index + dst_offset, &b, 0, bytes_read);
+ while ((bytes_read = Get(index + src_offset, &b, 0, buffer_length)) > 0) {
+ int bytes_written = array->Put(index + dst_offset, &b, 0, bytes_read);
if (bytes_written != bytes_read) {
#if defined (SFNTLY_NO_EXCEPTION)
return 0;
@@ -134,31 +122,30 @@ int32_t ByteArray::copyTo(int32_t dst_offset, ByteArray* array,
return index;
}
-int32_t ByteArray::copyTo(OutputStream* os) {
- return copyTo(os, 0, length());
+int32_t ByteArray::CopyTo(OutputStream* os) {
+ return CopyTo(os, 0, Length());
}
-int32_t ByteArray::copyTo(OutputStream* os, int32_t offset, int32_t length) {
+int32_t ByteArray::CopyTo(OutputStream* os, int32_t offset, int32_t length) {
ByteVector b(COPY_BUFFER_SIZE);
int32_t bytes_read = 0;
int32_t index = 0;
int32_t buffer_length = std::min<int32_t>(COPY_BUFFER_SIZE, length);
- while ((bytes_read = get(index + offset, &b, 0, buffer_length)) > 0) {
- os->write(&b, 0, bytes_read);
+ while ((bytes_read = Get(index + offset, &b, 0, buffer_length)) > 0) {
+ os->Write(&b, 0, bytes_read);
index += bytes_read;
buffer_length = std::min<int32_t>(b.size(), length - index);
}
return index;
}
-bool ByteArray::copyFrom(InputStream* is, int32_t length) {
+bool ByteArray::CopyFrom(InputStream* is, int32_t length) {
ByteVector b(COPY_BUFFER_SIZE);
int32_t bytes_read = 0;
int32_t index = 0;
int32_t buffer_length = std::min<int32_t>(COPY_BUFFER_SIZE, length);
- while ((bytes_read =
- is->read(&b, 0, buffer_length)) > 0) {
- if (put(index, &b, 0, bytes_read) != bytes_read) {
+ while ((bytes_read = is->Read(&b, 0, buffer_length)) > 0) {
+ if (Put(index, &b, 0, bytes_read) != bytes_read) {
#if defined (SFNTLY_NO_EXCEPTION)
return 0;
#else
@@ -172,14 +159,13 @@ bool ByteArray::copyFrom(InputStream* is, int32_t length) {
return true;
}
-bool ByteArray::copyFrom(InputStream* is) {
+bool ByteArray::CopyFrom(InputStream* is) {
ByteVector b(COPY_BUFFER_SIZE);
int32_t bytes_read = 0;
int32_t index = 0;
int32_t buffer_length = COPY_BUFFER_SIZE;
- while ((bytes_read =
- is->read(&b, 0, buffer_length)) > 0) {
- if (put(index, &b, 0, bytes_read) != bytes_read) {
+ while ((bytes_read = is->Read(&b, 0, buffer_length)) > 0) {
+ if (Put(index, &b, 0, bytes_read) != bytes_read) {
#if defined (SFNTLY_NO_EXCEPTION)
return 0;
#else
@@ -191,4 +177,22 @@ bool ByteArray::copyFrom(InputStream* is) {
return true;
}
+ByteArray::ByteArray(int32_t filled_length,
+ int32_t storage_length,
+ bool growable) {
+ Init(filled_length, storage_length, growable);
+}
+
+ByteArray::ByteArray(int32_t filled_length, int32_t storage_length) {
+ Init(filled_length, storage_length, false);
+}
+
+void ByteArray::Init(int32_t filled_length,
+ int32_t storage_length,
+ bool growable) {
+ storage_length_ = storage_length;
+ growable_ = growable;
+ SetFilledLength(filled_length);
+}
+
} // namespace sfntly
diff --git a/cpp/src/sfntly/data/byte_array.h b/cpp/src/sfntly/data/byte_array.h
index edb4633..9ac56c0 100644
--- a/cpp/src/sfntly/data/byte_array.h
+++ b/cpp/src/sfntly/data/byte_array.h
@@ -29,38 +29,27 @@ namespace sfntly {
// C++ port of this class assumes that the data are stored in a linear region
// like std::vector.
class ByteArray : virtual public RefCount {
- protected:
- // filledLength the length that is "filled" and readable counting from offset
- // storageLength the maximum storage size of the underlying data
- // growable is the storage growable - storageLength is the max growable size
- ByteArray(int32_t filled_length, int32_t storage_length, bool growable);
- ByteArray(int32_t filled_length, int32_t storage_length);
- void init(int32_t filled_length, int32_t storage_length, bool growable);
-
- static const int32_t COPY_BUFFER_SIZE;
-
public:
virtual ~ByteArray();
// Get the current filled and readable length of the array.
- int32_t length();
+ int32_t Length();
// Get the maximum size of the array. This is the maximum number of bytes that
// the array can hold and all of it may not be filled with data or even fully
// allocated yet.
- int32_t size();
+ int32_t Size();
- bool growable();
- int32_t setFilledLength(int32_t filled_length);
+ bool growable() { return growable_; }
+ int32_t SetFilledLength(int32_t filled_length);
- public:
// Get the byte from the given index.
- virtual byte_t get(int32_t index);
+ virtual byte_t Get(int32_t index);
// Get the bytes from the given index and fill the buffer with them. As many
// bytes as will fit into the buffer are read unless that would go past the
// end of the array.
- virtual int32_t get(int32_t index, ByteVector* b);
+ virtual int32_t Get(int32_t index, ByteVector* b);
// Get the bytes from the given index and fill the buffer with them starting
// at the offset given. As many bytes as the specified length are read unless
@@ -70,17 +59,19 @@ class ByteArray : virtual public RefCount {
// @param offset the location in the buffer to start putting the bytes
// @param length the number of bytes to put into the buffer
// @return the number of bytes put into the buffer
- virtual int32_t get(int32_t index, ByteVector* b, int32_t offset,
+ virtual int32_t Get(int32_t index,
+ ByteVector* b,
+ int32_t offset,
int32_t length);
// Put the specified byte into the array at the given index unless that would
// be beyond the length of the array and it isn't growable.
- virtual bool put(int32_t index, byte_t b);
+ virtual bool Put(int32_t index, byte_t b);
// Put the specified bytes into the array at the given index. The entire
// buffer is put into the array unless that would extend beyond the length and
// the array isn't growable.
- virtual int32_t put(int32_t index, ByteVector* b);
+ virtual int32_t Put(int32_t index, ByteVector* b);
// Put the specified bytes into the array at the given index. All of the bytes
// specified are put into the array unless that would extend beyond the length
@@ -91,19 +82,21 @@ class ByteArray : virtual public RefCount {
// @param offset the offset in the bytes to start copying from
// @param length the number of bytes to copy into the array
// @return the number of bytes actually written
- virtual int32_t put(int32_t index, ByteVector* b, int32_t offset,
+ virtual int32_t Put(int32_t index,
+ ByteVector* b,
+ int32_t offset,
int32_t length);
// Fully copy this ByteArray to another ByteArray to the extent that the
// destination array has storage for the data copied.
- virtual int32_t copyTo(ByteArray* array);
+ virtual int32_t CopyTo(ByteArray* array);
// Copy a segment of this ByteArray to another ByteArray.
// @param array the destination
// @param offset the offset in this ByteArray to start copying from
// @param length the maximum length in bytes to copy
// @return the number of bytes copied
- virtual int32_t copyTo(ByteArray* array, int32_t offset, int32_t length);
+ virtual int32_t CopyTo(ByteArray* array, int32_t offset, int32_t length);
// Copy this ByteArray to another ByteArray.
// @param dstOffset the offset in the destination array to start copying to
@@ -111,25 +104,40 @@ class ByteArray : virtual public RefCount {
// @param srcOffset the offset in this ByteArray to start copying from
// @param length the maximum length in bytes to copy
// @return the number of bytes copied
- virtual int32_t copyTo(int32_t dst_offset, ByteArray* array,
- int32_t src_offset, int32_t length);
+ virtual int32_t CopyTo(int32_t dst_offset,
+ ByteArray* array,
+ int32_t src_offset,
+ int32_t length);
- virtual int32_t copyTo(OutputStream* os);
- virtual int32_t copyTo(OutputStream* os, int32_t offset, int32_t length);
- virtual bool copyFrom(InputStream* is, int32_t length);
- virtual bool copyFrom(InputStream* is);
+ virtual int32_t CopyTo(OutputStream* os);
+ virtual int32_t CopyTo(OutputStream* os, int32_t offset, int32_t length);
+ virtual bool CopyFrom(InputStream* is, int32_t length);
+ virtual bool CopyFrom(InputStream* is);
protected:
- virtual bool internalPut(int32_t index, byte_t b) = 0;
- virtual int32_t internalPut(int32_t index, ByteVector* b, int32_t offset,
+ // filledLength the length that is "filled" and readable counting from offset.
+ // storageLength the maximum storage size of the underlying data.
+ // growable is the storage growable - storageLength is the max growable size.
+ ByteArray(int32_t filled_length, int32_t storage_length, bool growable);
+ ByteArray(int32_t filled_length, int32_t storage_length);
+ void Init(int32_t filled_length, int32_t storage_length, bool growable);
+
+ virtual bool InternalPut(int32_t index, byte_t b) = 0;
+ virtual int32_t InternalPut(int32_t index,
+ ByteVector* b,
+ int32_t offset,
int32_t length) = 0;
- virtual byte_t internalGet(int32_t index) = 0;
- virtual int32_t internalGet(int32_t index, ByteVector* b, int32_t offset,
+ virtual byte_t InternalGet(int32_t index) = 0;
+ virtual int32_t InternalGet(int32_t index,
+ ByteVector* b,
+ int32_t offset,
int32_t length) = 0;
- virtual void close() = 0;
+ virtual void Close() = 0;
+
+ // C++ port only, raw pointer to the first element of storage.
+ virtual byte_t* Begin() = 0;
- // C++ port only, raw pointer to the first element of storage
- virtual byte_t* begin() = 0;
+ static const int32_t COPY_BUFFER_SIZE;
private:
int32_t filled_length_;
diff --git a/cpp/src/sfntly/data/font_data.cc b/cpp/src/sfntly/data/font_data.cc
index fdba5f8..437a810 100644
--- a/cpp/src/sfntly/data/font_data.cc
+++ b/cpp/src/sfntly/data/font_data.cc
@@ -22,30 +22,12 @@
namespace sfntly {
-FontData::~FontData() {}
-
-void FontData::init(ByteArray* ba) {
- array_ = ba;
- bound_offset_ = 0;
- bound_length_ = INT_MAX;
-}
-
-FontData::FontData(ByteArray* ba) {
- init(ba);
-}
-
-FontData::FontData(FontData* data, int32_t offset, int32_t length) {
- init(data->array_);
- bound(data->bound_offset_ + offset, length);
-}
-
-FontData::FontData(FontData* data, int32_t offset) {
- init(data->array_);
- bound(offset);
+int32_t FontData::Size() const {
+ return std::min<int32_t>(array_->Size() - bound_offset_, bound_length_);
}
-bool FontData::bound(int32_t offset, int32_t length) {
- if (offset + length > size() || offset < 0 || length < 0)
+bool FontData::Bound(int32_t offset, int32_t length) {
+ if (offset + length > Size() || offset < 0 || length < 0)
return false;
bound_offset_ += offset;
@@ -53,27 +35,45 @@ bool FontData::bound(int32_t offset, int32_t length) {
return true;
}
-bool FontData::bound(int32_t offset) {
-if (offset > size() || offset < 0)
+bool FontData::Bound(int32_t offset) {
+if (offset > Size() || offset < 0)
return false;
bound_offset_ += offset;
return true;
}
-int32_t FontData::length() const {
- return std::min<int32_t>(array_->length() - bound_offset_, bound_length_);
+int32_t FontData::Length() const {
+ return std::min<int32_t>(array_->Length() - bound_offset_, bound_length_);
}
-int32_t FontData::size() const {
- return std::min<int32_t>(array_->size() - bound_offset_, bound_length_);
+FontData::FontData(ByteArray* ba) {
+ Init(ba);
+}
+
+FontData::FontData(FontData* data, int32_t offset, int32_t length) {
+ Init(data->array_);
+ Bound(data->bound_offset_ + offset, length);
+}
+
+FontData::FontData(FontData* data, int32_t offset) {
+ Init(data->array_);
+ Bound(offset);
+}
+
+FontData::~FontData() {}
+
+void FontData::Init(ByteArray* ba) {
+ array_ = ba;
+ bound_offset_ = 0;
+ bound_length_ = INT_MAX;
}
-int32_t FontData::boundOffset(int32_t offset) {
+int32_t FontData::BoundOffset(int32_t offset) {
return offset + bound_offset_;
}
-int32_t FontData::boundLength(int32_t offset, int32_t length) {
+int32_t FontData::BoundLength(int32_t offset, int32_t length) {
return std::min<int32_t>(length, bound_length_ - offset);
}
diff --git a/cpp/src/sfntly/data/font_data.h b/cpp/src/sfntly/data/font_data.h
index 6bcdb73..ab5cf54 100644
--- a/cpp/src/sfntly/data/font_data.h
+++ b/cpp/src/sfntly/data/font_data.h
@@ -18,6 +18,7 @@
#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_FONT_DATA_H_
#include <vector>
+
#include "sfntly/port/type.h"
#include "sfntly/data/byte_array.h"
#include "sfntly/port/refcount.h"
@@ -51,13 +52,13 @@ class FontData : virtual public RefCount {
// that the font data can hold and all of it may not be filled with data or
// even fully allocated yet.
// @return the size of this array
- virtual int32_t size() const;
+ virtual int32_t Size() const;
// Sets limits on the size of the FontData. The font data is
// @param offset the start of the new bounds
// @param length the number of bytes in the bounded array
// @return true if the bounding range was successful; false otherwise
- virtual bool bound(int32_t offset, int32_t length);
+ virtual bool Bound(int32_t offset, int32_t length);
// Sets limits on the size of the FontData. This is a offset bound only so if
// the FontData is writable and growable then there is no limit to that growth
@@ -65,28 +66,25 @@ class FontData : virtual public RefCount {
// @param offset the start of the new bounds which must be within the current
// size of the FontData
// @return true if the bounding range was successful; false otherwise
- virtual bool bound(int32_t offset);
+ virtual bool Bound(int32_t offset);
// Makes a slice of this FontData. The returned slice will share the data with
// the original FontData.
// @param offset the start of the slice
// @param length the number of bytes in the slice
// @return a slice of the original FontData
- virtual CALLER_ATTACH FontData* slice(int32_t offset, int32_t length) = 0;
+ virtual CALLER_ATTACH FontData* Slice(int32_t offset, int32_t length) = 0;
// Makes a bottom bound only slice of this array. The returned slice will
// share the data with the original FontData.
// @param offset the start of the slice
// @return a slice of the original FontData
- virtual CALLER_ATTACH FontData* slice(int32_t offset) = 0;
+ virtual CALLER_ATTACH FontData* Slice(int32_t offset) = 0;
// Get the length of the data.
- virtual int32_t length() const;
-
+ virtual int32_t Length() const;
protected:
- virtual ~FontData();
-
// Constructor.
// @param ba the byte array to use for the backing data
explicit FontData(ByteArray* ba);
@@ -101,12 +99,13 @@ class FontData : virtual public RefCount {
// @param data the data to wrap
// @param offset the offset to start the wrap from
FontData(FontData* data, int32_t offset);
+ virtual ~FontData();
- void init(ByteArray* ba);
- int32_t boundOffset(int32_t offset);
- int32_t boundLength(int32_t offset, int32_t length);
+ void Init(ByteArray* ba);
+ int32_t BoundOffset(int32_t offset);
+ int32_t BoundLength(int32_t offset, int32_t length);
- protected:
+ // TODO(arthurhsu): style guide violation: refactor this protected member
ByteArrayPtr array_;
private:
diff --git a/cpp/src/sfntly/data/font_input_stream.cc b/cpp/src/sfntly/data/font_input_stream.cc
index b9eccdb..a1fbe44 100644
--- a/cpp/src/sfntly/data/font_input_stream.cc
+++ b/cpp/src/sfntly/data/font_input_stream.cc
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-#include <algorithm>
-
#include "sfntly/data/font_input_stream.h"
+#include <algorithm>
+
namespace sfntly {
FontInputStream::FontInputStream(InputStream* is)
@@ -32,50 +32,50 @@ FontInputStream::~FontInputStream() {
// Do not close here, underlying InputStream will close themselves.
}
-int32_t FontInputStream::available() {
+int32_t FontInputStream::Available() {
if (stream_) {
- return stream_->available();
+ return stream_->Available();
}
return 0;
}
-void FontInputStream::close() {
+void FontInputStream::Close() {
if (stream_) {
- stream_->close();
+ stream_->Close();
}
}
-void FontInputStream::mark(int32_t readlimit) {
+void FontInputStream::Mark(int32_t readlimit) {
if (stream_) {
- stream_->mark(readlimit);
+ stream_->Mark(readlimit);
}
}
-bool FontInputStream::markSupported() {
+bool FontInputStream::MarkSupported() {
if (stream_) {
- return stream_->markSupported();
+ return stream_->MarkSupported();
}
return false;
}
-void FontInputStream::reset() {
+void FontInputStream::Reset() {
if (stream_) {
- stream_->reset();
+ stream_->Reset();
}
}
-int32_t FontInputStream::read() {
+int32_t FontInputStream::Read() {
if (!stream_ || (bounded_ && position_ >= length_)) {
return -1;
}
- int32_t b = stream_->read();
+ int32_t b = stream_->Read();
if (b >= 0) {
position_++;
}
return b;
}
-int32_t FontInputStream::read(ByteVector* b, int32_t offset, int32_t length) {
+int32_t FontInputStream::Read(ByteVector* b, int32_t offset, int32_t length) {
if (!stream_ || offset < 0 || length < 0 ||
(bounded_ && position_ >= length_)) {
return -1;
@@ -83,59 +83,55 @@ int32_t FontInputStream::read(ByteVector* b, int32_t offset, int32_t length) {
int32_t bytes_to_read =
bounded_ ? std::min<int32_t>(length, (int32_t)(length_ - position_)) :
length;
- int32_t bytes_read = stream_->read(b, offset, bytes_to_read);
+ int32_t bytes_read = stream_->Read(b, offset, bytes_to_read);
position_ += bytes_read;
return bytes_read;
}
-int32_t FontInputStream::read(ByteVector* b) {
- return read(b, 0, b->size());
-}
-
-int64_t FontInputStream::position() {
- return position_;
+int32_t FontInputStream::Read(ByteVector* b) {
+ return Read(b, 0, b->size());
}
-int32_t FontInputStream::readChar() {
- return read();
+int32_t FontInputStream::ReadChar() {
+ return Read();
}
-int32_t FontInputStream::readUShort() {
- return 0xffff & (read() << 8 | read());
+int32_t FontInputStream::ReadUShort() {
+ return 0xffff & (Read() << 8 | Read());
}
-int32_t FontInputStream::readShort() {
- return ((read() << 8 | read()) << 16) >> 16;
+int32_t FontInputStream::ReadShort() {
+ return ((Read() << 8 | Read()) << 16) >> 16;
}
-int32_t FontInputStream::readUInt24() {
- return 0xffffff & (read() << 16 | read() << 8 | read());
+int32_t FontInputStream::ReadUInt24() {
+ return 0xffffff & (Read() << 16 | Read() << 8 | Read());
}
-int64_t FontInputStream::readULong() {
- return 0xffffffffL & readLong();
+int64_t FontInputStream::ReadULong() {
+ return 0xffffffffL & ReadLong();
}
-int32_t FontInputStream::readULongAsInt() {
- int64_t ulong = readULong();
+int32_t FontInputStream::ReadULongAsInt() {
+ int64_t ulong = ReadULong();
return ((int32_t)ulong) & ~0x80000000;
}
-int32_t FontInputStream::readLong() {
- return read() << 24 | read() << 16 | read() << 8 | read();
+int32_t FontInputStream::ReadLong() {
+ return Read() << 24 | Read() << 16 | Read() << 8 | Read();
}
-int32_t FontInputStream::readFixed() {
- return readLong();
+int32_t FontInputStream::ReadFixed() {
+ return ReadLong();
}
-int64_t FontInputStream::readDateTimeAsLong() {
- return (int64_t)readULong() << 32 | readULong();
+int64_t FontInputStream::ReadDateTimeAsLong() {
+ return (int64_t)ReadULong() << 32 | ReadULong();
}
-int64_t FontInputStream::skip(int64_t n) {
+int64_t FontInputStream::Skip(int64_t n) {
if (stream_) {
- int64_t skipped = stream_->skip(n);
+ int64_t skipped = stream_->Skip(n);
position_ += skipped;
return skipped;
}
diff --git a/cpp/src/sfntly/data/font_input_stream.h b/cpp/src/sfntly/data/font_input_stream.h
index ed8d364..7404825 100644
--- a/cpp/src/sfntly/data/font_input_stream.h
+++ b/cpp/src/sfntly/data/font_input_stream.h
@@ -33,33 +33,33 @@ class FontInputStream : public InputStream {
FontInputStream(InputStream* is, size_t length);
virtual ~FontInputStream();
- virtual int32_t available();
- virtual void close();
- virtual void mark(int32_t readlimit);
- virtual bool markSupported();
- virtual void reset();
+ virtual int32_t Available();
+ virtual void Close();
+ virtual void Mark(int32_t readlimit);
+ virtual bool MarkSupported();
+ virtual void Reset();
- virtual int32_t read();
- virtual int32_t read(ByteVector* buffer);
- virtual int32_t read(ByteVector* buffer, int32_t offset, int32_t length);
+ virtual int32_t Read();
+ virtual int32_t Read(ByteVector* buffer);
+ virtual int32_t Read(ByteVector* buffer, int32_t offset, int32_t length);
- virtual int64_t position();
+ virtual int64_t position() { return position_; }
- virtual int32_t readChar();
- virtual int32_t readUShort();
- virtual int32_t readShort();
- virtual int32_t readUInt24();
- virtual int64_t readULong();
- virtual int32_t readULongAsInt();
- virtual int32_t readLong();
- virtual int32_t readFixed();
- virtual int64_t readDateTimeAsLong();
- virtual int64_t skip(int64_t n); // n can be negative
+ virtual int32_t ReadChar();
+ virtual int32_t ReadUShort();
+ virtual int32_t ReadShort();
+ virtual int32_t ReadUInt24();
+ virtual int64_t ReadULong();
+ virtual int32_t ReadULongAsInt();
+ virtual int32_t ReadLong();
+ virtual int32_t ReadFixed();
+ virtual int64_t ReadDateTimeAsLong();
+ virtual int64_t Skip(int64_t n); // n can be negative.
private:
InputStream* stream_;
int64_t position_;
- int64_t length_; // bound on length of data to read
+ int64_t length_; // Bound on length of data to read.
bool bounded_;
};
diff --git a/cpp/src/sfntly/data/font_output_stream.cc b/cpp/src/sfntly/data/font_output_stream.cc
index f0f4744..a88a29e 100644
--- a/cpp/src/sfntly/data/font_output_stream.cc
+++ b/cpp/src/sfntly/data/font_output_stream.cc
@@ -14,95 +14,91 @@
* limitations under the License.
*/
-#include <algorithm>
-
#include "sfntly/data/font_output_stream.h"
-#include "sfntly/port/endian.h"
+
+#include <algorithm>
namespace sfntly {
FontOutputStream::FontOutputStream(OutputStream* os)
- : stream_(os), position_(0) {
+ : stream_(os),
+ position_(0) {
}
FontOutputStream::~FontOutputStream() {
// Do not close, underlying stream shall clean up themselves.
}
-size_t FontOutputStream::position() {
- return position_;
-}
-
-void FontOutputStream::write(byte_t b) {
+void FontOutputStream::Write(byte_t b) {
if (stream_) {
- stream_->write(b);
+ stream_->Write(b);
position_++;
}
}
-void FontOutputStream::write(ByteVector* b) {
+void FontOutputStream::Write(ByteVector* b) {
if (b) {
- write(b, 0, b->size());
+ Write(b, 0, b->size());
position_ += b->size();
}
}
-void FontOutputStream::write(ByteVector* b, int32_t offset, int32_t length) {
+void FontOutputStream::Write(ByteVector* b, int32_t offset, int32_t length) {
if (stream_ && b) {
- stream_->write(b, offset, length);
+ stream_->Write(b, offset, length);
position_ += length;
}
}
-void FontOutputStream::writeChar(byte_t c) {
- write(c);
+void FontOutputStream::WriteChar(byte_t c) {
+ Write(c);
}
-void FontOutputStream::writeUShort(int32_t us) {
- write((byte_t)((us >> 8) & 0xff));
- write((byte_t)(us & 0xff));
+void FontOutputStream::WriteUShort(int32_t us) {
+ Write((byte_t)((us >> 8) & 0xff));
+ Write((byte_t)(us & 0xff));
}
-void FontOutputStream::writeShort(int32_t s) {
- writeUShort(s);
+void FontOutputStream::WriteShort(int32_t s) {
+ WriteUShort(s);
}
-void FontOutputStream::writeUInt24(int32_t ui) {
- write((byte_t)(ui >> 16) & 0xff);
- write((byte_t)(ui >> 8) & 0xff);
- write((byte_t)ui & 0xff);
+void FontOutputStream::WriteUInt24(int32_t ui) {
+ Write((byte_t)(ui >> 16) & 0xff);
+ Write((byte_t)(ui >> 8) & 0xff);
+ Write((byte_t)ui & 0xff);
}
-void FontOutputStream::writeULong(int64_t ul) {
- write((byte_t)((ul >> 24) & 0xff));
- write((byte_t)((ul >> 16) & 0xff));
- write((byte_t)((ul >> 8) & 0xff));
- write((byte_t)(ul & 0xff));
+void FontOutputStream::WriteULong(int64_t ul) {
+ Write((byte_t)((ul >> 24) & 0xff));
+ Write((byte_t)((ul >> 16) & 0xff));
+ Write((byte_t)((ul >> 8) & 0xff));
+ Write((byte_t)(ul & 0xff));
}
-void FontOutputStream::writeLong(int64_t l) {
- writeULong(l);
+void FontOutputStream::WriteLong(int64_t l) {
+ WriteULong(l);
}
-void FontOutputStream::writeFixed(int32_t f) {
- writeULong(f);
+void FontOutputStream::WriteFixed(int32_t f) {
+ WriteULong(f);
}
-void FontOutputStream::writeDateTime(int64_t date) {
- writeULong((date >> 32) & 0xffffffff);
- writeULong(date & 0xffffffff);
+void FontOutputStream::WriteDateTime(int64_t date) {
+ WriteULong((date >> 32) & 0xffffffff);
+ WriteULong(date & 0xffffffff);
}
-void FontOutputStream::flush() {
+void FontOutputStream::Flush() {
if (stream_) {
- stream_->flush();
+ stream_->Flush();
}
}
-void FontOutputStream::close() {
+void FontOutputStream::Close() {
if (stream_) {
- stream_->flush();
- stream_->close();
+ stream_->Flush();
+ stream_->Close();
position_ = 0;
}
}
diff --git a/cpp/src/sfntly/data/font_output_stream.h b/cpp/src/sfntly/data/font_output_stream.h
index 4bb923d..6938b66 100644
--- a/cpp/src/sfntly/data/font_output_stream.h
+++ b/cpp/src/sfntly/data/font_output_stream.h
@@ -32,22 +32,22 @@ class FontOutputStream : public OutputStream {
explicit FontOutputStream(OutputStream* os);
virtual ~FontOutputStream();
- virtual size_t position();
-
- virtual void write(byte_t b);
- virtual void write(ByteVector* b);
- virtual void write(ByteVector* b, int32_t offset, int32_t len);
- virtual void writeChar(byte_t c);
- virtual void writeUShort(int32_t us);
- virtual void writeShort(int32_t s);
- virtual void writeUInt24(int32_t ui);
- virtual void writeULong(int64_t ul);
- virtual void writeLong(int64_t l);
- virtual void writeFixed(int32_t l);
- virtual void writeDateTime(int64_t date);
-
- virtual void flush();
- virtual void close();
+ virtual size_t position() { return position_; }
+
+ virtual void Write(byte_t b);
+ virtual void Write(ByteVector* b);
+ virtual void Write(ByteVector* b, int32_t offset, int32_t len);
+ virtual void WriteChar(byte_t c);
+ virtual void WriteUShort(int32_t us);
+ virtual void WriteShort(int32_t s);
+ virtual void WriteUInt24(int32_t ui);
+ virtual void WriteULong(int64_t ul);
+ virtual void WriteLong(int64_t l);
+ virtual void WriteFixed(int32_t l);
+ virtual void WriteDateTime(int64_t date);
+
+ virtual void Flush();
+ virtual void Close();
private:
OutputStream* stream_;
diff --git a/cpp/src/sfntly/data/growable_memory_byte_array.cc b/cpp/src/sfntly/data/growable_memory_byte_array.cc
index 0821321..9e1a043 100644
--- a/cpp/src/sfntly/data/growable_memory_byte_array.cc
+++ b/cpp/src/sfntly/data/growable_memory_byte_array.cc
@@ -14,10 +14,11 @@
* limitations under the License.
*/
+#include "sfntly/data/growable_memory_byte_array.h"
+
#include <limits.h>
-#include <algorithm>
-#include "sfntly/data/growable_memory_byte_array.h"
+#include <algorithm>
namespace sfntly {
@@ -27,40 +28,46 @@ GrowableMemoryByteArray::GrowableMemoryByteArray()
GrowableMemoryByteArray::~GrowableMemoryByteArray() {}
-bool GrowableMemoryByteArray::internalPut(int32_t index, byte_t b) {
+bool GrowableMemoryByteArray::InternalPut(int32_t index, byte_t b) {
if ((size_t)index >= b_.capacity()) {
- b_.resize((size_t)(index + 1) << 2); // grow exponentially
+ b_.resize((size_t)(index + 1) << 2); // Grow exponentially.
}
b_[index] = b;
return true;
}
-int32_t GrowableMemoryByteArray::internalPut(int32_t index, ByteVector* b,
- int32_t offset, int32_t length) {
+int32_t GrowableMemoryByteArray::InternalPut(int32_t index,
+ ByteVector* b,
+ int32_t offset,
+ int32_t length) {
if ((size_t)index + length >= b_.capacity()) {
b_.resize((size_t)(index + length + 1) << 2);
}
- std::copy(b->begin() + offset, b->begin() + (offset + length),
+ std::copy(b->begin() + offset,
+ b->begin() + (offset + length),
b_.begin() + index);
return length;
}
-byte_t GrowableMemoryByteArray::internalGet(int32_t index) {
+byte_t GrowableMemoryByteArray::InternalGet(int32_t index) {
return b_[index];
}
-int32_t GrowableMemoryByteArray::internalGet(int32_t index, ByteVector* b,
- int32_t offset, int32_t length) {
- std::copy(b_.begin() + index, b_.begin() + (index + length),
+int32_t GrowableMemoryByteArray::InternalGet(int32_t index,
+ ByteVector* b,
+ int32_t offset,
+ int32_t length) {
+ std::copy(b_.begin() + index,
+ b_.begin() + (index + length),
b->begin() + offset);
return length;
}
-void GrowableMemoryByteArray::close() {
+void GrowableMemoryByteArray::Close() {
b_.clear();
}
-byte_t* GrowableMemoryByteArray::begin() {
+byte_t* GrowableMemoryByteArray::Begin() {
return &(b_[0]);
}
diff --git a/cpp/src/sfntly/data/growable_memory_byte_array.h b/cpp/src/sfntly/data/growable_memory_byte_array.h
index 3c9d4f0..dc59f62 100644
--- a/cpp/src/sfntly/data/growable_memory_byte_array.h
+++ b/cpp/src/sfntly/data/growable_memory_byte_array.h
@@ -30,14 +30,18 @@ class GrowableMemoryByteArray : public ByteArray,
virtual ~GrowableMemoryByteArray();
protected:
- virtual bool internalPut(int32_t index, byte_t b);
- virtual int32_t internalPut(int32_t index, ByteVector* b, int32_t offset,
+ virtual bool InternalPut(int32_t index, byte_t b);
+ virtual int32_t InternalPut(int32_t index,
+ ByteVector* b,
+ int32_t offset,
int32_t length);
- virtual byte_t internalGet(int32_t index);
- virtual int32_t internalGet(int32_t index, ByteVector* b, int32_t offset,
+ virtual byte_t InternalGet(int32_t index);
+ virtual int32_t InternalGet(int32_t index,
+ ByteVector* b,
+ int32_t offset,
int32_t length);
- virtual void close();
- virtual byte_t* begin();
+ virtual void Close();
+ virtual byte_t* Begin();
private:
ByteVector b_;
diff --git a/cpp/src/sfntly/data/memory_byte_array.cc b/cpp/src/sfntly/data/memory_byte_array.cc
index 528979a..0138b21 100644
--- a/cpp/src/sfntly/data/memory_byte_array.cc
+++ b/cpp/src/sfntly/data/memory_byte_array.cc
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-#include <string.h>
-
#include "sfntly/data/memory_byte_array.h"
+#include <string.h>
+
namespace sfntly {
-// Note: this constructor can fail under low-memory situation
+// Note: this constructor can fail under low-memory situation.
MemoryByteArray::MemoryByteArray(int32_t length)
: ByteArray(0, length), b_(NULL), allocated_(true) {
}
@@ -29,56 +29,61 @@ MemoryByteArray::MemoryByteArray(byte_t* b, int32_t buffer_length)
: ByteArray(buffer_length, buffer_length), b_(b), allocated_(false) {
}
-MemoryByteArray::MemoryByteArray(byte_t* b, int32_t buffer_length,
+MemoryByteArray::MemoryByteArray(byte_t* b,
+ int32_t buffer_length,
int32_t filled_length)
: ByteArray(filled_length, buffer_length), b_(b), allocated_(false) {
}
MemoryByteArray::~MemoryByteArray() {
- close();
+ Close();
}
-void MemoryByteArray::init() {
+void MemoryByteArray::Init() {
if (allocated_ && b_ == NULL) {
- b_ = new byte_t[size()];
- memset(b_, 0, size());
+ b_ = new byte_t[Size()];
+ memset(b_, 0, Size());
}
}
-bool MemoryByteArray::internalPut(int32_t index, byte_t b) {
- init();
+bool MemoryByteArray::InternalPut(int32_t index, byte_t b) {
+ Init();
b_[index] = b;
return true;
}
-int32_t MemoryByteArray::internalPut(int32_t index, ByteVector* b,
- int32_t offset, int32_t length) {
- init();
+int32_t MemoryByteArray::InternalPut(int32_t index,
+ ByteVector* b,
+ int32_t offset,
+ int32_t length) {
+ Init();
memcpy(b_ + index, &((*b)[offset]), length);
return length;
}
-byte_t MemoryByteArray::internalGet(int32_t index) {
- init();
+byte_t MemoryByteArray::InternalGet(int32_t index) {
+ Init();
return b_[index];
}
-int32_t MemoryByteArray::internalGet(int32_t index, ByteVector* b,
- int32_t offset, int32_t length) {
- init();
+int32_t MemoryByteArray::InternalGet(int32_t index,
+ ByteVector* b,
+ int32_t offset,
+ int32_t length) {
+ Init();
memcpy(&((*b)[offset]), b_ + index, length);
return length;
}
-void MemoryByteArray::close() {
+void MemoryByteArray::Close() {
if (allocated_ && b_) {
delete[] b_;
}
b_ = NULL;
}
-byte_t* MemoryByteArray::begin() {
- init();
+byte_t* MemoryByteArray::Begin() {
+ Init();
return b_;
}
diff --git a/cpp/src/sfntly/data/memory_byte_array.h b/cpp/src/sfntly/data/memory_byte_array.h
index 34b26a6..171dcc7 100644
--- a/cpp/src/sfntly/data/memory_byte_array.h
+++ b/cpp/src/sfntly/data/memory_byte_array.h
@@ -29,17 +29,21 @@ class MemoryByteArray : public ByteArray, public RefCounted<MemoryByteArray> {
virtual ~MemoryByteArray();
protected:
- virtual bool internalPut(int32_t index, byte_t b);
- virtual int32_t internalPut(int32_t index, ByteVector* b, int32_t offset,
+ virtual bool InternalPut(int32_t index, byte_t b);
+ virtual int32_t InternalPut(int32_t index,
+ ByteVector* b,
+ int32_t offset,
int32_t length);
- virtual byte_t internalGet(int32_t index);
- virtual int32_t internalGet(int32_t index, ByteVector* b, int32_t offset,
+ virtual byte_t InternalGet(int32_t index);
+ virtual int32_t InternalGet(int32_t index,
+ ByteVector* b,
+ int32_t offset,
int32_t length);
- virtual void close();
- virtual byte_t* begin();
+ virtual void Close();
+ virtual byte_t* Begin();
private:
- void init(); // C++ port only, used to allocate memory outside constructor.
+ void Init(); // C++ port only, used to allocate memory outside constructor.
byte_t* b_;
bool allocated_;
diff --git a/cpp/src/sfntly/data/readable_font_data.cc b/cpp/src/sfntly/data/readable_font_data.cc
index fa7279e..5f8478d 100644
--- a/cpp/src/sfntly/data/readable_font_data.cc
+++ b/cpp/src/sfntly/data/readable_font_data.cc
@@ -20,119 +20,69 @@
namespace sfntly {
-ReadableFontData::~ReadableFontData() {}
-
ReadableFontData::ReadableFontData(ByteArray* array)
- : FontData(array), checksum_set_(false), checksum_(0) {
-}
-
-ReadableFontData::ReadableFontData(ReadableFontData* data, int32_t offset)
- : FontData(data, offset), checksum_set_(false), checksum_(0) {
+ : FontData(array),
+ checksum_set_(false),
+ checksum_(0) {
}
-ReadableFontData::ReadableFontData(ReadableFontData* data, int32_t offset,
- int32_t length)
- : FontData(data, offset, length), checksum_set_(false), checksum_(0) {
-}
+ReadableFontData::~ReadableFontData() {}
-int64_t ReadableFontData::checksum() {
+int64_t ReadableFontData::Checksum() {
// TODO(arthurhsu): IMPLEMENT: atomicity
if (!checksum_set_) {
- computeChecksum();
+ ComputeChecksum();
}
return checksum_;
}
-/* OpenType checksum
-ULONG
-CalcTableChecksum(ULONG *Table, ULONG Length)
-{
-ULONG Sum = 0L;
-ULONG *Endptr = Table+((Length+3) & ~3) / sizeof(ULONG);
-while (Table < EndPtr)
- Sum += *Table++;
-return Sum;
-}
-*/
-void ReadableFontData::computeChecksum() {
- // TODO(arthurhsu): IMPLEMENT: synchronization/atomicity
- int64_t sum = 0;
- if (checksum_range_.empty()) {
- sum = computeCheckSum(0, length());
- } else {
- for (uint32_t low_bound_index = 0; low_bound_index < checksum_range_.size();
- low_bound_index += 2) {
- int32_t low_bound = checksum_range_[low_bound_index];
- int32_t high_bound = (low_bound_index == checksum_range_.size() - 1) ?
- length() :
- checksum_range_[low_bound_index + 1];
- sum += computeCheckSum(low_bound, high_bound);
- }
- }
-
- checksum_ = sum & 0xffffffffL;
- checksum_set_ = true;
-}
-
-int64_t ReadableFontData::computeCheckSum(int32_t low_bound,
- int32_t high_bound) {
- int64_t sum = 0;
- for (int32_t i = low_bound; i < high_bound; i += 4) {
- int32_t b3 = readUByte(i);
- b3 = (b3 == -1) ? 0 : b3;
- int32_t b2 = readUByte(i + 1);
- b2 = (b2 == -1) ? 0 : b2;
- int32_t b1 = readUByte(i + 2);
- b1 = (b1 == -1) ? 0 : b1;
- int32_t b0 = readUByte(i + 3);
- b0 = (b0 == -1) ? 0 : b0;
- sum += (b3 << 24) | (b2 << 16) | (b1 << 8) | b0;
- }
- return sum;
-}
-
-void ReadableFontData::setCheckSumRanges(const IntegerList& ranges) {
+void ReadableFontData::SetCheckSumRanges(const IntegerList& ranges) {
checksum_range_ = ranges;
checksum_set_ = false; // UNIMPLEMENTED: atomicity
}
-int32_t ReadableFontData::readUByte(int32_t index) {
- return 0xff & array_->get(boundOffset(index));
+int32_t ReadableFontData::ReadUByte(int32_t index) {
+ return 0xff & array_->Get(BoundOffset(index));
}
-int32_t ReadableFontData::readByte(int32_t index) {
- return (array_->get(boundOffset(index)) << 24) >> 24;
+int32_t ReadableFontData::ReadByte(int32_t index) {
+ return (array_->Get(BoundOffset(index)) << 24) >> 24;
}
-int32_t ReadableFontData::readBytes(int32_t index, ByteVector* b,
- int32_t offset, int32_t length) {
- return array_->get(boundOffset(index), b, offset, boundLength(index, length));
+int32_t ReadableFontData::ReadBytes(int32_t index,
+ ByteVector* b,
+ int32_t offset,
+ int32_t length) {
+ return array_->Get(BoundOffset(index), b, offset, BoundLength(index, length));
}
-int32_t ReadableFontData::readChar(int32_t index) {
- return readUByte(index);
+int32_t ReadableFontData::ReadChar(int32_t index) {
+ return ReadUByte(index);
}
-int32_t ReadableFontData::readUShort(int32_t index) {
- return 0xffff & (readUByte(index) << 8 | readUByte(index + 1));
+int32_t ReadableFontData::ReadUShort(int32_t index) {
+ return 0xffff & (ReadUByte(index) << 8 | ReadUByte(index + 1));
}
-int32_t ReadableFontData::readShort(int32_t index) {
- return ((readByte(index) << 8 | readUByte(index + 1)) << 16) >> 16;
+int32_t ReadableFontData::ReadShort(int32_t index) {
+ return ((ReadByte(index) << 8 | ReadUByte(index + 1)) << 16) >> 16;
}
-int32_t ReadableFontData::readUInt24(int32_t index) {
- return 0xffffff & (readUByte(index) << 16 |
- readUByte(index + 1) << 8 | readUByte(index + 2));
+int32_t ReadableFontData::ReadUInt24(int32_t index) {
+ return 0xffffff & (ReadUByte(index) << 16 |
+ ReadUByte(index + 1) << 8 |
+ ReadUByte(index + 2));
}
-int64_t ReadableFontData::readULong(int32_t index) {
- return 0xffffffffL & (readUByte(index) << 24 | readUByte(index + 1) << 16 |
- readUByte(index + 2) << 8 | readUByte(index + 3));
+int64_t ReadableFontData::ReadULong(int32_t index) {
+ return 0xffffffffL & (ReadUByte(index) << 24 |
+ ReadUByte(index + 1) << 16 |
+ ReadUByte(index + 2) << 8 |
+ ReadUByte(index + 3));
}
-int32_t ReadableFontData::readULongAsInt(int32_t index) {
- int64_t ulong = readULong(index);
+int32_t ReadableFontData::ReadULongAsInt(int32_t index) {
+ int64_t ulong = ReadULong(index);
#if !defined (SFNTLY_NO_EXCEPTION)
if ((ulong & 0x80000000) == 0x80000000) {
throw ArithmeticException("Long value too large to fit into an integer.");
@@ -141,59 +91,125 @@ int32_t ReadableFontData::readULongAsInt(int32_t index) {
return ((int32_t)ulong) & ~0x80000000;
}
-int32_t ReadableFontData::readLong(int32_t index) {
- return readByte(index) << 24 | readUByte(index + 1) << 16 |
- readUByte(index + 2) << 8 | readUByte(index + 3);
+int32_t ReadableFontData::ReadLong(int32_t index) {
+ return ReadByte(index) << 24 |
+ ReadUByte(index + 1) << 16 |
+ ReadUByte(index + 2) << 8 |
+ ReadUByte(index + 3);
}
-int32_t ReadableFontData::readFixed(int32_t index) {
- return readLong(index);
+int32_t ReadableFontData::ReadFixed(int32_t index) {
+ return ReadLong(index);
}
-int64_t ReadableFontData::readDateTimeAsLong(int32_t index) {
- return (int64_t)readULong(index) << 32 | readULong(index + 4);
+int64_t ReadableFontData::ReadDateTimeAsLong(int32_t index) {
+ return (int64_t)ReadULong(index) << 32 | ReadULong(index + 4);
}
-int32_t ReadableFontData::readFWord(int32_t index) {
- return readShort(index);
+int32_t ReadableFontData::ReadFWord(int32_t index) {
+ return ReadShort(index);
}
-int32_t ReadableFontData::readFUFWord(int32_t index) {
- return readUShort(index);
+int32_t ReadableFontData::ReadFUFWord(int32_t index) {
+ return ReadUShort(index);
}
-int32_t ReadableFontData::copyTo(OutputStream* os) {
- return array_->copyTo(os, boundOffset(0), length());
+int32_t ReadableFontData::CopyTo(OutputStream* os) {
+ return array_->CopyTo(os, BoundOffset(0), Length());
}
-int32_t ReadableFontData::copyTo(WritableFontData* wfd) {
- return array_->copyTo(wfd->boundOffset(0), wfd->array_, boundOffset(0),
- length());
+int32_t ReadableFontData::CopyTo(WritableFontData* wfd) {
+ return array_->CopyTo(wfd->BoundOffset(0),
+ wfd->array_,
+ BoundOffset(0),
+ Length());
}
-int32_t ReadableFontData::copyTo(ByteArray* ba) {
- return array_->copyTo(ba, boundOffset(0), length());
+int32_t ReadableFontData::CopyTo(ByteArray* ba) {
+ return array_->CopyTo(ba, BoundOffset(0), Length());
}
-CALLER_ATTACH FontData* ReadableFontData::slice(int32_t offset,
+CALLER_ATTACH FontData* ReadableFontData::Slice(int32_t offset,
int32_t length) {
- if (offset < 0 || offset + length > size()) {
+ if (offset < 0 || offset + length > Size()) {
return NULL;
}
FontDataPtr slice = new ReadableFontData(this, offset, length);
// Note: exception not ported because the condition is always false in C++.
// if (slice == null) { throw new IndexOutOfBoundsException( ...
- return slice.detach();
+ return slice.Detach();
}
-CALLER_ATTACH FontData* ReadableFontData::slice(int32_t offset) {
- if (offset < 0 || offset > size()) {
+CALLER_ATTACH FontData* ReadableFontData::Slice(int32_t offset) {
+ if (offset < 0 || offset > Size()) {
return NULL;
}
FontDataPtr slice = new ReadableFontData(this, offset);
// Note: exception not ported because the condition is always false in C++.
// if (slice == null) { throw new IndexOutOfBoundsException( ...
- return slice.detach();
+ return slice.Detach();
+}
+
+ReadableFontData::ReadableFontData(ReadableFontData* data, int32_t offset)
+ : FontData(data, offset),
+ checksum_set_(false),
+ checksum_(0) {
+}
+
+ReadableFontData::ReadableFontData(ReadableFontData* data,
+ int32_t offset,
+ int32_t length)
+ : FontData(data, offset, length),
+ checksum_set_(false),
+ checksum_(0) {
+}
+
+/* OpenType checksum
+ULONG
+CalcTableChecksum(ULONG *Table, ULONG Length)
+{
+ULONG Sum = 0L;
+ULONG *Endptr = Table+((Length+3) & ~3) / sizeof(ULONG);
+while (Table < EndPtr)
+ Sum += *Table++;
+return Sum;
+}
+*/
+void ReadableFontData::ComputeChecksum() {
+ // TODO(arthurhsu): IMPLEMENT: synchronization/atomicity
+ int64_t sum = 0;
+ if (checksum_range_.empty()) {
+ sum = ComputeCheckSum(0, Length());
+ } else {
+ for (uint32_t low_bound_index = 0; low_bound_index < checksum_range_.size();
+ low_bound_index += 2) {
+ int32_t low_bound = checksum_range_[low_bound_index];
+ int32_t high_bound = (low_bound_index == checksum_range_.size() - 1) ?
+ Length() :
+ checksum_range_[low_bound_index + 1];
+ sum += ComputeCheckSum(low_bound, high_bound);
+ }
+ }
+
+ checksum_ = sum & 0xffffffffL;
+ checksum_set_ = true;
+}
+
+int64_t ReadableFontData::ComputeCheckSum(int32_t low_bound,
+ int32_t high_bound) {
+ int64_t sum = 0;
+ for (int32_t i = low_bound; i < high_bound; i += 4) {
+ int32_t b3 = ReadUByte(i);
+ b3 = (b3 == -1) ? 0 : b3;
+ int32_t b2 = ReadUByte(i + 1);
+ b2 = (b2 == -1) ? 0 : b2;
+ int32_t b1 = ReadUByte(i + 2);
+ b1 = (b1 == -1) ? 0 : b1;
+ int32_t b0 = ReadUByte(i + 3);
+ b0 = (b0 == -1) ? 0 : b0;
+ sum += (b3 << 24) | (b2 << 16) | (b1 << 8) | b0;
+ }
+ return sum;
}
} // namespace sfntly
diff --git a/cpp/src/sfntly/data/readable_font_data.h b/cpp/src/sfntly/data/readable_font_data.h
index be466de..b1ca846 100644
--- a/cpp/src/sfntly/data/readable_font_data.h
+++ b/cpp/src/sfntly/data/readable_font_data.h
@@ -30,71 +30,52 @@ class ReadableFontData : public FontData,
explicit ReadableFontData(ByteArray* array);
virtual ~ReadableFontData();
- protected:
- // Constructor. Creates a bounded wrapper of another ReadableFontData from the
- // given offset until the end of the original ReadableFontData.
- // @param data data to wrap
- // @param offset the start of this data's view of the original data
- ReadableFontData(ReadableFontData* data, int32_t offset);
-
- // Constructor. Creates a bounded wrapper of another ReadableFontData from the
- // given offset until the end of the original ReadableFontData.
- // @param data data to wrap
- // @param offset the start of this data's view of the original data
- ReadableFontData(ReadableFontData* data, int32_t offset, int32_t length);
-
- private:
- void computeChecksum();
- int64_t computeCheckSum(int32_t low_bound, int32_t high_bound);
-
- public:
// Get a computed checksum for the data. This checksum uses the OpenType spec
// calculation. Every ULong value (32 bit unsigned) in the data is summed and
// the resulting value is truncated to 32 bits. If the data length in bytes is
// not an integral multiple of 4 then any remaining bytes are treated as the
// start of a 4 byte sequence whose remaining bytes are zero.
// @return the checksum
- int64_t checksum();
+ int64_t Checksum();
// Sets the bounds to use for computing the checksum. These bounds are in
// begin and end pairs. If an odd number is given then the final range is
// assumed to extend to the end of the data. The lengths of each range must be
// a multiple of 4.
// @param ranges the range bounds to use for the checksum
- void setCheckSumRanges(const IntegerList& ranges);
+ void SetCheckSumRanges(const IntegerList& ranges);
- public:
- virtual int32_t readUByte(int32_t index);
- virtual int32_t readByte(int32_t index);
- virtual int32_t readBytes(int32_t index, ByteVector* b, int32_t offset,
+ virtual int32_t ReadUByte(int32_t index);
+ virtual int32_t ReadByte(int32_t index);
+ virtual int32_t ReadBytes(int32_t index, ByteVector* b, int32_t offset,
int32_t length);
- virtual int32_t readChar(int32_t index);
- virtual int32_t readUShort(int32_t index);
- virtual int32_t readShort(int32_t index);
- virtual int32_t readUInt24(int32_t index);
- virtual int64_t readULong(int32_t index);
- virtual int32_t readULongAsInt(int32_t index);
- virtual int32_t readLong(int32_t index);
- virtual int32_t readFixed(int32_t index);
- virtual int64_t readDateTimeAsLong(int32_t index);
-
- virtual int32_t readFWord(int32_t index);
- virtual int32_t readFUFWord(int32_t index);
-
- virtual int32_t copyTo(OutputStream* os);
- virtual int32_t copyTo(WritableFontData* wfd);
- virtual int32_t copyTo(ByteArray* ba);
+ virtual int32_t ReadChar(int32_t index);
+ virtual int32_t ReadUShort(int32_t index);
+ virtual int32_t ReadShort(int32_t index);
+ virtual int32_t ReadUInt24(int32_t index);
+ virtual int64_t ReadULong(int32_t index);
+ virtual int32_t ReadULongAsInt(int32_t index);
+ virtual int32_t ReadLong(int32_t index);
+ virtual int32_t ReadFixed(int32_t index);
+ virtual int64_t ReadDateTimeAsLong(int32_t index);
+
+ virtual int32_t ReadFWord(int32_t index);
+ virtual int32_t ReadFUFWord(int32_t index);
+
+ virtual int32_t CopyTo(OutputStream* os);
+ virtual int32_t CopyTo(WritableFontData* wfd);
+ virtual int32_t CopyTo(ByteArray* ba);
// TODO(arthurhsu): IMPLEMENT
/*
- virtual int32_t readFUnit(int32_t index);
- virtual int64_t readF2Dot14(int32_t index);
- virtual int64_t readLongDateTime(int32_t index);
- virtual int32_t searchUShort(int32_t start, int32_t length, int32_t key);
- virtual int32_t searchUShort(int32_t start_index, int32_t start_offset,
+ virtual int32_t ReadFUnit(int32_t index);
+ virtual int64_t ReadF2Dot14(int32_t index);
+ virtual int64_t ReadLongDateTime(int32_t index);
+ virtual int32_t SearchUShort(int32_t start, int32_t length, int32_t key);
+ virtual int32_t SearchUShort(int32_t start_index, int32_t start_offset,
int32_t count_index, int32_t count_offset,
int32_t length, int32_t key);
- virtual int32_t searchULong(int32_t start_index, int32_t start_offset,
+ virtual int32_t SearchULong(int32_t start_index, int32_t start_offset,
int32_t end_index, int32_t end_offset,
int32_t length, int32_t key);
*/
@@ -104,16 +85,32 @@ class ReadableFontData : public FontData,
// @param offset the start of the slice
// @param length the number of bytes in the slice
// @return a slice of the original FontData
- virtual CALLER_ATTACH FontData* slice(int32_t offset, int32_t length);
+ virtual CALLER_ATTACH FontData* Slice(int32_t offset, int32_t length);
// Makes a bottom bound only slice of this array. The returned slice will
// share the data with the original FontData.
// @param offset the start of the slice
// @return a slice of the original FontData
- virtual CALLER_ATTACH FontData* slice(int32_t offset);
+ virtual CALLER_ATTACH FontData* Slice(int32_t offset);
+
+ protected:
+ // Constructor. Creates a bounded wrapper of another ReadableFontData from the
+ // given offset until the end of the original ReadableFontData.
+ // @param data data to wrap
+ // @param offset the start of this data's view of the original data
+ ReadableFontData(ReadableFontData* data, int32_t offset);
+
+ // Constructor. Creates a bounded wrapper of another ReadableFontData from the
+ // given offset until the end of the original ReadableFontData.
+ // @param data data to wrap
+ // @param offset the start of this data's view of the original data
+ ReadableFontData(ReadableFontData* data, int32_t offset, int32_t length);
private:
- bool checksum_set_; // TODO(arthurhsu): IMPLEMENT: must be set atomically
+ void ComputeChecksum();
+ int64_t ComputeCheckSum(int32_t low_bound, int32_t high_bound);
+
+ bool checksum_set_; // TODO(arthurhsu): IMPLEMENT: must be set atomically.
int64_t checksum_;
IntegerList checksum_range_;
};
diff --git a/cpp/src/sfntly/data/writable_font_data.cc b/cpp/src/sfntly/data/writable_font_data.cc
index 8588acb..586acc1 100644
--- a/cpp/src/sfntly/data/writable_font_data.cc
+++ b/cpp/src/sfntly/data/writable_font_data.cc
@@ -18,111 +18,116 @@
namespace sfntly {
-WritableFontData::~WritableFontData() {}
-
WritableFontData::WritableFontData(ByteArray* ba) : ReadableFontData(ba) {
}
-WritableFontData::WritableFontData(WritableFontData* data, int32_t offset)
- : ReadableFontData(data, offset) {
-}
-
-WritableFontData::WritableFontData(WritableFontData* data, int32_t offset,
- int32_t length)
- : ReadableFontData(data, offset, length) {
-}
+WritableFontData::~WritableFontData() {}
-int32_t WritableFontData::writeByte(int32_t index, byte_t b) {
- array_->put(boundOffset(index), b);
+int32_t WritableFontData::WriteByte(int32_t index, byte_t b) {
+ array_->Put(BoundOffset(index), b);
return 1;
}
-int32_t WritableFontData::writeBytes(int32_t offset, ByteVector* b,
- int32_t index, int32_t length) {
- return array_->put(boundOffset(offset), b, index,
- boundLength(offset, length));
+int32_t WritableFontData::WriteBytes(int32_t offset,
+ ByteVector* b,
+ int32_t index,
+ int32_t length) {
+ return array_->Put(BoundOffset(offset),
+ b,
+ index,
+ BoundLength(offset, length));
}
-int32_t WritableFontData::writeBytes(int32_t index, ByteVector* b) {
- return writeBytes(index, b, 0, b->size());
+int32_t WritableFontData::WriteBytes(int32_t index, ByteVector* b) {
+ return WriteBytes(index, b, 0, b->size());
}
-int32_t WritableFontData::writeChar(int32_t index, byte_t c) {
- return writeByte(index, c);
+int32_t WritableFontData::WriteChar(int32_t index, byte_t c) {
+ return WriteByte(index, c);
}
-int32_t WritableFontData::writeUShort(int32_t index, int32_t us) {
- writeByte(index, (byte_t)((us >> 8) & 0xff));
- writeByte(index + 1, (byte_t)(us & 0xff));
+int32_t WritableFontData::WriteUShort(int32_t index, int32_t us) {
+ WriteByte(index, (byte_t)((us >> 8) & 0xff));
+ WriteByte(index + 1, (byte_t)(us & 0xff));
return 2;
}
-int32_t WritableFontData::writeUShortLE(int32_t index, int32_t us) {
- writeByte(index, (byte_t)(us & 0xff));
- writeByte(index + 1, (byte_t)((us >> 8) & 0xff));
+int32_t WritableFontData::WriteUShortLE(int32_t index, int32_t us) {
+ WriteByte(index, (byte_t)(us & 0xff));
+ WriteByte(index + 1, (byte_t)((us >> 8) & 0xff));
return 2;
}
-int32_t WritableFontData::writeShort(int32_t index, int32_t s) {
- return writeUShort(index, s);
+int32_t WritableFontData::WriteShort(int32_t index, int32_t s) {
+ return WriteUShort(index, s);
}
-int32_t WritableFontData::writeUInt24(int32_t index, int32_t ui) {
- writeByte(index, (byte_t)((ui >> 16) & 0xff));
- writeByte(index + 1, (byte_t)((ui >> 8) & 0xff));
- writeByte(index + 2, (byte_t)(ui & 0xff));
+int32_t WritableFontData::WriteUInt24(int32_t index, int32_t ui) {
+ WriteByte(index, (byte_t)((ui >> 16) & 0xff));
+ WriteByte(index + 1, (byte_t)((ui >> 8) & 0xff));
+ WriteByte(index + 2, (byte_t)(ui & 0xff));
return 3;
}
-int32_t WritableFontData::writeULong(int32_t index, int64_t ul) {
- writeByte(index, (byte_t)((ul >> 24) & 0xff));
- writeByte(index + 1, (byte_t)((ul >> 16) & 0xff));
- writeByte(index + 2, (byte_t)((ul >> 8) & 0xff));
- writeByte(index + 3, (byte_t)(ul & 0xff));
+int32_t WritableFontData::WriteULong(int32_t index, int64_t ul) {
+ WriteByte(index, (byte_t)((ul >> 24) & 0xff));
+ WriteByte(index + 1, (byte_t)((ul >> 16) & 0xff));
+ WriteByte(index + 2, (byte_t)((ul >> 8) & 0xff));
+ WriteByte(index + 3, (byte_t)(ul & 0xff));
return 4;
}
-int32_t WritableFontData::writeULongLE(int32_t index, int64_t ul) {
- writeByte(index, (byte_t)(ul & 0xff));
- writeByte(index + 1, (byte_t)((ul >> 8) & 0xff));
- writeByte(index + 2, (byte_t)((ul >> 16) & 0xff));
- writeByte(index + 3, (byte_t)((ul >> 24) & 0xff));
+int32_t WritableFontData::WriteULongLE(int32_t index, int64_t ul) {
+ WriteByte(index, (byte_t)(ul & 0xff));
+ WriteByte(index + 1, (byte_t)((ul >> 8) & 0xff));
+ WriteByte(index + 2, (byte_t)((ul >> 16) & 0xff));
+ WriteByte(index + 3, (byte_t)((ul >> 24) & 0xff));
return 4;
}
-int32_t WritableFontData::writeLong(int32_t index, int64_t l) {
- return writeULong(index, l);
+int32_t WritableFontData::WriteLong(int32_t index, int64_t l) {
+ return WriteULong(index, l);
}
-int32_t WritableFontData::writeFixed(int32_t index, int32_t l) {
- return writeLong(index, l);
+int32_t WritableFontData::WriteFixed(int32_t index, int32_t l) {
+ return WriteLong(index, l);
}
-int32_t WritableFontData::writeDateTime(int32_t index, int64_t date) {
- writeULong(index, (date >> 32) & 0xffffffff);
- writeULong(index + 4, date & 0xffffffff);
+int32_t WritableFontData::WriteDateTime(int32_t index, int64_t date) {
+ WriteULong(index, (date >> 32) & 0xffffffff);
+ WriteULong(index + 4, date & 0xffffffff);
return 8;
}
-CALLER_ATTACH FontData* WritableFontData::slice(int32_t offset,
+CALLER_ATTACH FontData* WritableFontData::Slice(int32_t offset,
int32_t length) {
- if (offset < 0 || offset + length > size()) {
+ if (offset < 0 || offset + length > Size()) {
return NULL;
}
FontDataPtr slice = new WritableFontData(this, offset, length);
// Note: exception not ported because the condition is always false in C++.
// if (slice == null) { throw new IndexOutOfBoundsException( ...
- return slice.detach();
+ return slice.Detach();
}
-CALLER_ATTACH FontData* WritableFontData::slice(int32_t offset) {
- if (offset > size()) {
+CALLER_ATTACH FontData* WritableFontData::Slice(int32_t offset) {
+ if (offset > Size()) {
return NULL;
}
FontDataPtr slice = new WritableFontData(this, offset);
// Note: exception not ported because the condition is always false in C++.
// if (slice == null) { throw new IndexOutOfBoundsException( ...
- return slice.detach();
+ return slice.Detach();
+}
+
+WritableFontData::WritableFontData(WritableFontData* data, int32_t offset)
+ : ReadableFontData(data, offset) {
+}
+
+WritableFontData::WritableFontData(WritableFontData* data,
+ int32_t offset,
+ int32_t length)
+ : ReadableFontData(data, offset, length) {
}
} // namespace sfntly
diff --git a/cpp/src/sfntly/data/writable_font_data.h b/cpp/src/sfntly/data/writable_font_data.h
index 9542cd0..98c9204 100644
--- a/cpp/src/sfntly/data/writable_font_data.h
+++ b/cpp/src/sfntly/data/writable_font_data.h
@@ -26,38 +26,39 @@ class WritableFontData : public ReadableFontData {
explicit WritableFontData(ByteArray* ba);
virtual ~WritableFontData();
- private:
- WritableFontData(WritableFontData* data, int32_t offset);
- WritableFontData(WritableFontData* data, int32_t offset, int32_t length);
-
- public:
- virtual int32_t writeByte(int32_t index, byte_t b);
- virtual int32_t writeBytes(int32_t offset, ByteVector* b, int32_t index,
+ virtual int32_t WriteByte(int32_t index, byte_t b);
+ virtual int32_t WriteBytes(int32_t offset,
+ ByteVector* b,
+ int32_t index,
int32_t length);
- virtual int32_t writeBytes(int32_t index, ByteVector* b);
- virtual int32_t writeChar(int32_t index, byte_t c);
- virtual int32_t writeUShort(int32_t index, int32_t us);
- virtual int32_t writeUShortLE(int32_t index, int32_t us);
- virtual int32_t writeShort(int32_t index, int32_t s);
- virtual int32_t writeUInt24(int32_t index, int32_t ui);
- virtual int32_t writeULong(int32_t index, int64_t ul);
- virtual int32_t writeULongLE(int32_t index, int64_t ul);
- virtual int32_t writeLong(int32_t index, int64_t l);
- virtual int32_t writeFixed(int32_t index, int32_t l);
- virtual int32_t writeDateTime(int32_t index, int64_t date);
+ virtual int32_t WriteBytes(int32_t index, ByteVector* b);
+ virtual int32_t WriteChar(int32_t index, byte_t c);
+ virtual int32_t WriteUShort(int32_t index, int32_t us);
+ virtual int32_t WriteUShortLE(int32_t index, int32_t us);
+ virtual int32_t WriteShort(int32_t index, int32_t s);
+ virtual int32_t WriteUInt24(int32_t index, int32_t ui);
+ virtual int32_t WriteULong(int32_t index, int64_t ul);
+ virtual int32_t WriteULongLE(int32_t index, int64_t ul);
+ virtual int32_t WriteLong(int32_t index, int64_t l);
+ virtual int32_t WriteFixed(int32_t index, int32_t l);
+ virtual int32_t WriteDateTime(int32_t index, int64_t date);
// Makes a slice of this FontData. The returned slice will share the data with
// the original FontData.
// @param offset the start of the slice
// @param length the number of bytes in the slice
// @return a slice of the original FontData
- virtual CALLER_ATTACH FontData* slice(int32_t offset, int32_t length);
+ virtual CALLER_ATTACH FontData* Slice(int32_t offset, int32_t length);
// Makes a bottom bound only slice of this array. The returned slice will
// share the data with the original FontData.
// @param offset the start of the slice
// @return a slice of the original FontData
- virtual CALLER_ATTACH FontData* slice(int32_t offset);
+ virtual CALLER_ATTACH FontData* Slice(int32_t offset);
+
+ private:
+ WritableFontData(WritableFontData* data, int32_t offset);
+ WritableFontData(WritableFontData* data, int32_t offset, int32_t length);
};
typedef Ptr<WritableFontData> WritableFontDataPtr;