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 "sfntly/table/bitmap/composite_bitmap_glyph.h" 18 19namespace sfntly { 20/****************************************************************************** 21 * CompositeBitmapGlyph class 22 ******************************************************************************/ 23CompositeBitmapGlyph::CompositeBitmapGlyph(ReadableFontData* data, 24 int32_t format) 25 : BitmapGlyph(data, format) { 26 Initialize(format); 27} 28 29CompositeBitmapGlyph::~CompositeBitmapGlyph() { 30} 31 32int32_t CompositeBitmapGlyph::NumComponents() { 33 return data_->ReadUShort(num_components_offset_); 34} 35 36CompositeBitmapGlyph::Component CompositeBitmapGlyph::GetComponent( 37 int32_t component_num) const { 38 int32_t component_offset = component_array_offset_ + 39 component_num * Offset::kEbdtComponentLength; 40 return CompositeBitmapGlyph::Component( 41 data_->ReadUShort(component_offset + Offset::kEbdtComponent_glyphCode), 42 data_->ReadChar(component_offset + Offset::kEbdtComponent_xOffset), 43 data_->ReadChar(component_offset + Offset::kEbdtComponent_yOffset)); 44} 45 46void CompositeBitmapGlyph::Initialize(int32_t format) { 47 if (format == 8) { 48 num_components_offset_ = Offset::kGlyphFormat8_numComponents; 49 component_array_offset_ = Offset::kGlyphFormat8_componentArray; 50 } else if (format == 9) { 51 num_components_offset_ = Offset::kGlyphFormat9_numComponents; 52 component_array_offset_ = Offset::kGlyphFormat9_componentArray; 53 } else { 54#if !defined (SFNTLY_NO_EXCEPTION) 55 throw IllegalStateException("Attempt to create a Composite Bitmap Glyph " 56 "with a non-composite format."); 57#endif 58 } 59} 60 61/****************************************************************************** 62 * CompositeBitmapGlyph::Component class 63 ******************************************************************************/ 64CompositeBitmapGlyph::Component::Component(const Component& rhs) 65 : glyph_code_(rhs.glyph_code_), 66 x_offset_(rhs.x_offset_), 67 y_offset_(rhs.y_offset_) { 68} 69 70bool CompositeBitmapGlyph::Component::operator==( 71 const CompositeBitmapGlyph::Component& rhs) { 72 return glyph_code_ == rhs.glyph_code_; 73} 74 75CompositeBitmapGlyph::Component& CompositeBitmapGlyph::Component::operator=( 76 const CompositeBitmapGlyph::Component& rhs) { 77 glyph_code_ = rhs.glyph_code_; 78 x_offset_ = rhs.x_offset_; 79 y_offset_ = rhs.y_offset_; 80 return *this; 81} 82 83CompositeBitmapGlyph::Component::Component(int32_t glyph_code, 84 int32_t x_offset, 85 int32_t y_offset) 86 : glyph_code_(glyph_code), x_offset_(x_offset), y_offset_(y_offset) { 87} 88 89/****************************************************************************** 90 * CompositeBitmapGlyph::Builder class 91 ******************************************************************************/ 92CompositeBitmapGlyph::Builder::Builder(ReadableFontData* data, int32_t format) 93 : BitmapGlyph::Builder(data, format) { 94} 95 96CompositeBitmapGlyph::Builder::Builder(WritableFontData* data, int32_t format) 97 : BitmapGlyph::Builder(data, format) { 98} 99 100CompositeBitmapGlyph::Builder::~Builder() { 101} 102 103CALLER_ATTACH FontDataTable* 104CompositeBitmapGlyph::Builder::SubBuildTable(ReadableFontData* data) { 105 Ptr<CompositeBitmapGlyph> glyph = new CompositeBitmapGlyph(data, format()); 106 return glyph.Detach(); 107} 108 109} // namespace sfntly 110