• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <limits.h>
18 #include <algorithm>
19 #include <functional>
20 
21 #include "sfntly/data/font_data.h"
22 
23 namespace sfntly {
24 
Size() const25 int32_t FontData::Size() const {
26   return std::min<int32_t>(array_->Size() - bound_offset_, bound_length_);
27 }
28 
Bound(int32_t offset,int32_t length)29 bool FontData::Bound(int32_t offset, int32_t length) {
30   if (offset + length > Size() || offset < 0 || length < 0)
31     return false;
32 
33   bound_offset_ += offset;
34   bound_length_ = length;
35   return true;
36 }
37 
Bound(int32_t offset)38 bool FontData::Bound(int32_t offset) {
39 if (offset > Size() || offset < 0)
40     return false;
41 
42   bound_offset_ += offset;
43   return true;
44 }
45 
Length() const46 int32_t FontData::Length() const {
47   return std::min<int32_t>(array_->Length() - bound_offset_, bound_length_);
48 }
49 
FontData(ByteArray * ba)50 FontData::FontData(ByteArray* ba) {
51   Init(ba);
52 }
53 
FontData(FontData * data,int32_t offset,int32_t length)54 FontData::FontData(FontData* data, int32_t offset, int32_t length) {
55   Init(data->array_);
56   Bound(data->bound_offset_ + offset, length);
57 }
58 
FontData(FontData * data,int32_t offset)59 FontData::FontData(FontData* data, int32_t offset) {
60   Init(data->array_);
61   Bound(data->bound_offset_ + offset,
62         (data->bound_length_ == GROWABLE_SIZE)
63             ? GROWABLE_SIZE : data->bound_length_ - offset);
64 }
65 
~FontData()66 FontData::~FontData() {}
67 
Init(ByteArray * ba)68 void FontData::Init(ByteArray* ba) {
69   array_ = ba;
70   bound_offset_ = 0;
71   bound_length_ = GROWABLE_SIZE;
72 }
73 
BoundOffset(int32_t offset)74 int32_t FontData::BoundOffset(int32_t offset) {
75   return offset + bound_offset_;
76 }
77 
BoundLength(int32_t offset,int32_t length)78 int32_t FontData::BoundLength(int32_t offset, int32_t length) {
79   return std::min<int32_t>(length, bound_length_ - offset);
80 }
81 
82 }  // namespace sfntly
83