aboutsummaryrefslogtreecommitdiff
path: root/cpp/src/sfntly/data
diff options
context:
space:
mode:
authorarthurhsu <arthurhsu@google.com>2011-10-11 01:01:16 +0000
committerarthurhsu <arthurhsu@google.com>2011-10-11 01:01:16 +0000
commit158cdcb9cf09418ba8b49f4be7be69e37aa8e9fa (patch)
treed45ec0d71e59ea8df58331b5005d6e920daedf3e /cpp/src/sfntly/data
parentb4e699e152543000a5825791e1c26826924a256f (diff)
downloadsfntly-158cdcb9cf09418ba8b49f4be7be69e37aa8e9fa.tar.gz
Update to Sep 30 snapshot, include all current EBXX support.
Refine Iterator ports: all java-style Iterator objects are ref-counted and have automatic memory management now.
Diffstat (limited to 'cpp/src/sfntly/data')
-rw-r--r--cpp/src/sfntly/data/byte_array.cc8
-rw-r--r--cpp/src/sfntly/data/font_data.cc6
-rw-r--r--cpp/src/sfntly/data/font_data.h7
-rw-r--r--cpp/src/sfntly/data/readable_font_data.cc7
-rw-r--r--cpp/src/sfntly/data/readable_font_data.h6
-rw-r--r--cpp/src/sfntly/data/writable_font_data.cc16
-rw-r--r--cpp/src/sfntly/data/writable_font_data.h13
7 files changed, 50 insertions, 13 deletions
diff --git a/cpp/src/sfntly/data/byte_array.cc b/cpp/src/sfntly/data/byte_array.cc
index c820adc..915a40c 100644
--- a/cpp/src/sfntly/data/byte_array.cc
+++ b/cpp/src/sfntly/data/byte_array.cc
@@ -115,13 +115,7 @@ int32_t ByteArray::CopyTo(int32_t dst_offset, ByteArray* array,
while ((bytes_read =
Get(index + src_offset, &(b[0]), 0, buffer_length)) > 0) {
int bytes_written = array->Put(index + dst_offset, &(b[0]), 0, bytes_read);
- if (bytes_written != bytes_read) {
-#if defined (SFNTLY_NO_EXCEPTION)
- return 0;
-#else
- throw IOException("Error writing bytes.");
-#endif
- }
+ UNREFERENCED_PARAMETER(bytes_written);
index += bytes_read;
remaining_length -= bytes_read;
buffer_length = std::min<int32_t>(b.size(), remaining_length);
diff --git a/cpp/src/sfntly/data/font_data.cc b/cpp/src/sfntly/data/font_data.cc
index ccc2a19..d2b95ea 100644
--- a/cpp/src/sfntly/data/font_data.cc
+++ b/cpp/src/sfntly/data/font_data.cc
@@ -58,7 +58,9 @@ FontData::FontData(FontData* data, int32_t offset, int32_t length) {
FontData::FontData(FontData* data, int32_t offset) {
Init(data->array_);
- Bound(data->bound_offset_ + offset);
+ Bound(data->bound_offset_ + offset,
+ (data->bound_length_ == GROWABLE_SIZE)
+ ? GROWABLE_SIZE : data->bound_length_ - offset);
}
FontData::~FontData() {}
@@ -66,7 +68,7 @@ FontData::~FontData() {}
void FontData::Init(ByteArray* ba) {
array_ = ba;
bound_offset_ = 0;
- bound_length_ = INT_MAX;
+ bound_length_ = GROWABLE_SIZE;
}
int32_t FontData::BoundOffset(int32_t offset) {
diff --git a/cpp/src/sfntly/data/font_data.h b/cpp/src/sfntly/data/font_data.h
index ec87c72..d02e8b7 100644
--- a/cpp/src/sfntly/data/font_data.h
+++ b/cpp/src/sfntly/data/font_data.h
@@ -17,6 +17,8 @@
#ifndef SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_DATA_H_
#define SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_DATA_H_
+#include <limits.h>
+
#include <vector>
#include "sfntly/port/type.h"
@@ -110,12 +112,15 @@ class FontData : virtual public RefCount {
// @return the bound compensated offset
int32_t BoundOffset(int32_t offset);
- // Gets the length in the underlying data taking into account any bounds on the data.
+ // Gets the length in the underlying data taking into account any bounds on
+ // the data.
// @param offset the offset that the length is being used at
// @param length the length to get the bound compensated length for
// @return the bound compensated length
int32_t BoundLength(int32_t offset, int32_t length);
+ static const int32_t GROWABLE_SIZE = INT_MAX;
+
// TODO(arthurhsu): style guide violation: refactor this protected member
ByteArrayPtr array_;
diff --git a/cpp/src/sfntly/data/readable_font_data.cc b/cpp/src/sfntly/data/readable_font_data.cc
index fb083cb..bb58c26 100644
--- a/cpp/src/sfntly/data/readable_font_data.cc
+++ b/cpp/src/sfntly/data/readable_font_data.cc
@@ -121,6 +121,13 @@ int32_t ReadableFontData::ReadULongAsInt(int32_t index) {
return static_cast<int32_t>(ulong);
}
+int64_t ReadableFontData::ReadULongLE(int32_t index) {
+ return 0xffffffffL & (ReadUByte(index) |
+ ReadUByte(index + 1) << 8 |
+ ReadUByte(index + 2) << 16 |
+ ReadUByte(index + 3) << 24);
+}
+
int32_t ReadableFontData::ReadLong(int32_t index) {
return ReadByte(index) << 24 |
ReadUByte(index + 1) << 16 |
diff --git a/cpp/src/sfntly/data/readable_font_data.h b/cpp/src/sfntly/data/readable_font_data.h
index c5833e8..b43c626 100644
--- a/cpp/src/sfntly/data/readable_font_data.h
+++ b/cpp/src/sfntly/data/readable_font_data.h
@@ -128,6 +128,12 @@ class ReadableFontData : public FontData,
// @throws IndexOutOfBoundsException if index is outside the FontData's range
virtual int32_t ReadULongAsInt(int32_t index);
+ // Read the ULONG at the given index, little-endian variant
+ // @param index index into the font data
+ // @return the ULONG
+ // @throws IndexOutOfBoundsException if index is outside the FontData's range
+ virtual int64_t ReadULongLE(int32_t index);
+
// Read the LONG at the given index.
// @param index index into the font data
// @return the LONG
diff --git a/cpp/src/sfntly/data/writable_font_data.cc b/cpp/src/sfntly/data/writable_font_data.cc
index 0b271a3..ace387c 100644
--- a/cpp/src/sfntly/data/writable_font_data.cc
+++ b/cpp/src/sfntly/data/writable_font_data.cc
@@ -82,12 +82,22 @@ int32_t WritableFontData::WriteBytesPad(int32_t index,
offset,
BoundLength(index,
std::min<int32_t>(length, b->size() - offset)));
- for (; written < length; written++) {
- array_->Put(written + index, pad);
- }
+ written += WritePadding(written + index, length - written, pad);
return written;
}
+int32_t WritableFontData::WritePadding(int32_t index, int32_t count) {
+ return WritePadding(index, count, (byte_t)0);
+}
+
+int32_t WritableFontData::WritePadding(int32_t index, int32_t count,
+ byte_t pad) {
+ for (int32_t i = 0; i < count; ++i) {
+ array_->Put(index + i, pad);
+ }
+ return count;
+}
+
int32_t WritableFontData::WriteChar(int32_t index, byte_t c) {
return WriteByte(index, c);
}
diff --git a/cpp/src/sfntly/data/writable_font_data.h b/cpp/src/sfntly/data/writable_font_data.h
index 9a9bd7b..f88a986 100644
--- a/cpp/src/sfntly/data/writable_font_data.h
+++ b/cpp/src/sfntly/data/writable_font_data.h
@@ -85,6 +85,19 @@ class WritableFontData : public ReadableFontData {
int32_t length,
byte_t pad);
+ // Writes padding to the FontData. The padding byte written is 0x00.
+ // @param index index into the font data
+ // @param count the number of pad bytes to write
+ // @return the number of pad bytes written
+ virtual int32_t WritePadding(int32_t index, int32_t count);
+
+ // Writes padding to the FontData.
+ // @param index index into the font data
+ // @param count the number of pad bytes to write
+ // @param pad the byte value to use as padding
+ // @return the number of pad bytes written
+ virtual int32_t WritePadding(int32_t index, int32_t count, byte_t pad);
+
// Write the CHAR at the given index.
// @param index index into the font data
// @param c the CHAR