summaryrefslogtreecommitdiff
path: root/sfntly/data/font_data.cc
diff options
context:
space:
mode:
authorTorne (Richard Coles) <torne@google.com>2013-11-28 11:56:15 +0000
committerTorne (Richard Coles) <torne@google.com>2013-11-28 11:56:15 +0000
commit58f132533b4126b00bc71fd9aed69ecf568cdf39 (patch)
tree3409a319b231317c63b0b3477c161c76822bcb92 /sfntly/data/font_data.cc
parent0232d0f400400568410e1f85e7aba28bcd2ac183 (diff)
parent4a8c3597eb72a7042ead9632e4c3e4fddb5ac695 (diff)
downloadsrc-58f132533b4126b00bc71fd9aed69ecf568cdf39.tar.gz
This commit was generated by merge_to_master.py. Change-Id: If4ff821474cc985d0bc16bc22c8180c8bec48014
Diffstat (limited to 'sfntly/data/font_data.cc')
-rw-r--r--sfntly/data/font_data.cc82
1 files changed, 82 insertions, 0 deletions
diff --git a/sfntly/data/font_data.cc b/sfntly/data/font_data.cc
new file mode 100644
index 0000000..d2b95ea
--- /dev/null
+++ b/sfntly/data/font_data.cc
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2011 Google Inc. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <limits.h>
+#include <algorithm>
+#include <functional>
+
+#include "sfntly/data/font_data.h"
+
+namespace sfntly {
+
+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)
+ return false;
+
+ bound_offset_ += offset;
+ bound_length_ = length;
+ return true;
+}
+
+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_);
+}
+
+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(data->bound_offset_ + offset,
+ (data->bound_length_ == GROWABLE_SIZE)
+ ? GROWABLE_SIZE : data->bound_length_ - offset);
+}
+
+FontData::~FontData() {}
+
+void FontData::Init(ByteArray* ba) {
+ array_ = ba;
+ bound_offset_ = 0;
+ bound_length_ = GROWABLE_SIZE;
+}
+
+int32_t FontData::BoundOffset(int32_t offset) {
+ return offset + bound_offset_;
+}
+
+int32_t FontData::BoundLength(int32_t offset, int32_t length) {
+ return std::min<int32_t>(length, bound_length_ - offset);
+}
+
+} // namespace sfntly