From 5af34fd773f8cfee82321393504f558ddf67c628 Mon Sep 17 00:00:00 2001 From: "arthurhsu@google.com" Date: Tue, 23 Aug 2011 00:48:46 +0000 Subject: Reorg folder structure to aligned with latest Java version. Change header guards. Updated font_data_test.cc so that VC compilation is not broken. Updated CMakeLists.txt so that files are grouped in folders in VC. git-svn-id: http://sfntly.googlecode.com/svn/trunk/cpp/src@58 672e30a5-4c29-85ac-ac6d-611c735e0a51 --- sample/subsetter/subset_util.cc | 8 +- sample/subsetter/subset_util.h | 6 +- sfntly/cmap_table.cc | 511 ---------------- sfntly/cmap_table.h | 447 -------------- sfntly/data/byte_array.h | 6 +- sfntly/data/font_data.h | 6 +- sfntly/data/font_input_stream.h | 6 +- sfntly/data/font_output_stream.h | 6 +- sfntly/data/growable_memory_byte_array.h | 6 +- sfntly/data/memory_byte_array.h | 6 +- sfntly/data/readable_font_data.h | 6 +- sfntly/data/writable_font_data.h | 6 +- sfntly/font.cc | 10 +- sfntly/font.h | 8 +- sfntly/font_data_table.cc | 176 ------ sfntly/font_data_table.h | 117 ---- sfntly/font_data_table_builder_container.h | 6 +- sfntly/font_factory.h | 6 +- sfntly/font_header_table.cc | 259 --------- sfntly/font_header_table.h | 167 ------ sfntly/glyph_table.cc | 667 --------------------- sfntly/glyph_table.h | 330 ----------- sfntly/horizontal_header_table.cc | 215 ------- sfntly/horizontal_header_table.h | 110 ---- sfntly/horizontal_metrics_table.cc | 151 ----- sfntly/horizontal_metrics_table.h | 89 --- sfntly/loca_table.cc | 250 -------- sfntly/loca_table.h | 146 ----- sfntly/math/fixed1616.h | 6 +- sfntly/math/font_math.h | 6 +- sfntly/maximum_profile_table.cc | 224 ------- sfntly/maximum_profile_table.h | 115 ---- sfntly/name_table.cc | 722 ----------------------- sfntly/name_table.h | 737 ------------------------ sfntly/os2_table.cc | 277 --------- sfntly/os2_table.h | 407 ------------- sfntly/port/atomic.h | 6 +- sfntly/port/config.h | 10 +- sfntly/port/endian.h | 6 +- sfntly/port/exception_type.h | 6 +- sfntly/port/file_input_stream.h | 6 +- sfntly/port/input_stream.h | 6 +- sfntly/port/memory_output_stream.h | 6 +- sfntly/port/output_stream.h | 6 +- sfntly/port/refcount.h | 6 +- sfntly/port/type.h | 6 +- sfntly/subtable.cc | 44 -- sfntly/subtable.h | 49 -- sfntly/table.cc | 279 --------- sfntly/table.h | 183 ------ sfntly/table/core/cmap_table.cc | 511 ++++++++++++++++ sfntly/table/core/cmap_table.h | 447 ++++++++++++++ sfntly/table/core/font_header_table.cc | 259 +++++++++ sfntly/table/core/font_header_table.h | 167 ++++++ sfntly/table/core/horizontal_header_table.cc | 211 +++++++ sfntly/table/core/horizontal_header_table.h | 110 ++++ sfntly/table/core/horizontal_metrics_table.cc | 151 +++++ sfntly/table/core/horizontal_metrics_table.h | 89 +++ sfntly/table/core/maximum_profile_table.cc | 224 +++++++ sfntly/table/core/maximum_profile_table.h | 115 ++++ sfntly/table/core/name_table.cc | 722 +++++++++++++++++++++++ sfntly/table/core/name_table.h | 737 ++++++++++++++++++++++++ sfntly/table/core/os2_table.cc | 277 +++++++++ sfntly/table/core/os2_table.h | 407 +++++++++++++ sfntly/table/font_data_table.cc | 176 ++++++ sfntly/table/font_data_table.h | 117 ++++ sfntly/table/subtable.cc | 44 ++ sfntly/table/subtable.h | 49 ++ sfntly/table/table.cc | 279 +++++++++ sfntly/table/table.h | 183 ++++++ sfntly/table/truetype/glyph_table.cc | 667 +++++++++++++++++++++ sfntly/table/truetype/glyph_table.h | 330 +++++++++++ sfntly/table/truetype/loca_table.cc | 250 ++++++++ sfntly/table/truetype/loca_table.h | 146 +++++ sfntly/tag.h | 6 +- sfntly/tools/subsetter.cc | 107 ---- sfntly/tools/subsetter/glyph_table_subsetter.cc | 4 +- sfntly/tools/subsetter/glyph_table_subsetter.h | 6 +- sfntly/tools/subsetter/subsetter.cc | 107 ++++ sfntly/tools/subsetter/subsetter.h | 8 +- sfntly/tools/subsetter/table_subsetter.h | 6 +- sfntly/tools/subsetter/table_subsetter_impl.h | 6 +- test/font_data_test.cc | 32 +- test/font_parsing_test.cc | 8 +- test/font_subsetter.h | 6 +- test/name_editing_test.cc | 4 +- test/otf_basic_editing_test.cc | 2 +- test/serialization_test.h | 8 +- test/subsetter_impl.cc | 6 +- test/subsetter_impl.h | 6 +- test/test_data.h | 6 +- test/test_font_utils.h | 6 +- test/test_utils.h | 6 +- test/verify_glyf.cc | 2 +- test/verify_hhea.cc | 2 +- test/verify_hmtx.cc | 2 +- test/verify_loca.cc | 2 +- test/verify_maxp.cc | 2 +- test/verify_name.cc | 2 +- test/verify_os2.cc | 2 +- 100 files changed, 6930 insertions(+), 6932 deletions(-) delete mode 100644 sfntly/cmap_table.cc delete mode 100644 sfntly/cmap_table.h delete mode 100644 sfntly/font_data_table.cc delete mode 100644 sfntly/font_data_table.h delete mode 100644 sfntly/font_header_table.cc delete mode 100644 sfntly/font_header_table.h delete mode 100644 sfntly/glyph_table.cc delete mode 100644 sfntly/glyph_table.h delete mode 100644 sfntly/horizontal_header_table.cc delete mode 100644 sfntly/horizontal_header_table.h delete mode 100644 sfntly/horizontal_metrics_table.cc delete mode 100644 sfntly/horizontal_metrics_table.h delete mode 100644 sfntly/loca_table.cc delete mode 100644 sfntly/loca_table.h delete mode 100644 sfntly/maximum_profile_table.cc delete mode 100644 sfntly/maximum_profile_table.h delete mode 100644 sfntly/name_table.cc delete mode 100644 sfntly/name_table.h delete mode 100644 sfntly/os2_table.cc delete mode 100644 sfntly/os2_table.h delete mode 100644 sfntly/subtable.cc delete mode 100644 sfntly/subtable.h delete mode 100644 sfntly/table.cc delete mode 100644 sfntly/table.h create mode 100644 sfntly/table/core/cmap_table.cc create mode 100644 sfntly/table/core/cmap_table.h create mode 100644 sfntly/table/core/font_header_table.cc create mode 100644 sfntly/table/core/font_header_table.h create mode 100644 sfntly/table/core/horizontal_header_table.cc create mode 100644 sfntly/table/core/horizontal_header_table.h create mode 100644 sfntly/table/core/horizontal_metrics_table.cc create mode 100644 sfntly/table/core/horizontal_metrics_table.h create mode 100644 sfntly/table/core/maximum_profile_table.cc create mode 100644 sfntly/table/core/maximum_profile_table.h create mode 100644 sfntly/table/core/name_table.cc create mode 100644 sfntly/table/core/name_table.h create mode 100644 sfntly/table/core/os2_table.cc create mode 100644 sfntly/table/core/os2_table.h create mode 100644 sfntly/table/font_data_table.cc create mode 100644 sfntly/table/font_data_table.h create mode 100644 sfntly/table/subtable.cc create mode 100644 sfntly/table/subtable.h create mode 100644 sfntly/table/table.cc create mode 100644 sfntly/table/table.h create mode 100644 sfntly/table/truetype/glyph_table.cc create mode 100644 sfntly/table/truetype/glyph_table.h create mode 100644 sfntly/table/truetype/loca_table.cc create mode 100644 sfntly/table/truetype/loca_table.h delete mode 100644 sfntly/tools/subsetter.cc create mode 100644 sfntly/tools/subsetter/subsetter.cc diff --git a/sample/subsetter/subset_util.cc b/sample/subsetter/subset_util.cc index 9e4e652..26da65f 100644 --- a/sample/subsetter/subset_util.cc +++ b/sample/subsetter/subset_util.cc @@ -17,17 +17,19 @@ // Remove VC++ nag on fopen. #define _CRT_SECURE_NO_WARNINGS +#include "sample/subsetter/subset_util.h" + #include + #include #include -#include "sfntly/port/type.h" #include "sfntly/font.h" -#include "sfntly/tools/subsetter/subsetter.h" -#include "sample/subsetter/subset_util.h" #include "sfntly/data/memory_byte_array.h" #include "sfntly/port/memory_output_stream.h" +#include "sfntly/port/type.h" #include "sfntly/tag.h" +#include "sfntly/tools/subsetter/subsetter.h" namespace sfntly { diff --git a/sample/subsetter/subset_util.h b/sample/subsetter/subset_util.h index 109d63a..5eb4fe4 100644 --- a/sample/subsetter/subset_util.h +++ b/sample/subsetter/subset_util.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SAMPLE_SUBSETTER_SUBSET_UTIL_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SAMPLE_SUBSETTER_SUBSET_UTIL_H_ +#ifndef SFNTLY_CPP_SRC_SAMPLE_SUBSETTER_SUBSET_UTIL_H_ +#define SFNTLY_CPP_SRC_SAMPLE_SUBSETTER_SUBSET_UTIL_H_ namespace sfntly { @@ -29,4 +29,4 @@ class SubsetUtil { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SAMPLE_SUBSETTER_SUBSET_UTIL_H_ +#endif // SFNTLY_CPP_SRC_SAMPLE_SUBSETTER_SUBSET_UTIL_H_ diff --git a/sfntly/cmap_table.cc b/sfntly/cmap_table.cc deleted file mode 100644 index 668dc07..0000000 --- a/sfntly/cmap_table.cc +++ /dev/null @@ -1,511 +0,0 @@ -/* - * 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. - */ - -// TODO(arthurhsu): IMPLEMENT: not really used and tested, need cleanup - -#include - -#include "sfntly/cmap_table.h" -#include "sfntly/name_table.h" -#include "sfntly/font.h" -#include "sfntly/port/endian.h" - -namespace sfntly { - -const int32_t CMapTable::NOTDEF = 0; - -/****************************************************************************** - * CMapTable class - ******************************************************************************/ -CMapTable::~CMapTable() {} - -int32_t CMapTable::Version() { - return data_->ReadUShort(Offset::kVersion); -} - -int32_t CMapTable::NumCMaps() { - return data_->ReadUShort(Offset::kNumTables); -} - -CMapTable::CMapId CMapTable::GetCMapId(int32_t index) { - return CMapId(PlatformId(index), EncodingId(index)); -} - -int32_t CMapTable::PlatformId(int32_t index) { - return data_->ReadUShort(Offset::kEncodingRecordPlatformId + - OffsetForEncodingRecord(index)); -} - -int32_t CMapTable::EncodingId(int32_t index) { - return data_->ReadUShort(Offset::kEncodingRecordEncodingId + - OffsetForEncodingRecord(index)); -} - -int32_t CMapTable::Offset(int32_t index) { - return data_->ReadULongAsInt(Offset::kEncodingRecordOffset + - OffsetForEncodingRecord(index)); -} - -CMapTable::CMapTable(Header* header, ReadableFontData* data) - : Table(header, data) { -} - -int32_t CMapTable::OffsetForEncodingRecord(int32_t index) { - return Offset::kEncodingRecordStart + index * Offset::kEncodingRecordSize; -} - -/****************************************************************************** - * CMapTable::CMapId class - ******************************************************************************/ -CMapTable::CMapId::CMapId(int32_t platform_id, int32_t encoding_id) - : platform_id_(platform_id), encoding_id_(encoding_id) { -} - -CMapTable::CMapId::CMapId(const CMapId& obj) - : platform_id_(obj.platform_id_), encoding_id_(obj.encoding_id_) { -} - -bool CMapTable::CMapId::operator==(const CMapTable::CMapId& obj) { - return obj.platform_id_ == platform_id_ && obj.encoding_id_ == encoding_id_; -} - -const CMapTable::CMapId& CMapTable::CMapId::operator=( - const CMapTable::CMapId& obj) { - platform_id_ = obj.platform_id_; - encoding_id_ = obj.encoding_id_; - return *this; -} - -int CMapTable::CMapId::HashCode() const { - return platform_id_ << 8 | encoding_id_; -} - -CMapTable::CMapId WINDOWS_BMP(PlatformId::kWindows, - WindowsEncodingId::kUnicodeUCS2); -CMapTable::CMapId WINDOWS_UCS4(PlatformId::kWindows, - WindowsEncodingId::kUnicodeUCS4); -CMapTable::CMapId MAC_ROMAN(PlatformId::kWindows, MacintoshEncodingId::kRoman); - -/****************************************************************************** - * CMapTable::CMapIdComparator class - ******************************************************************************/ - -bool CMapTable::CMapIdComparator::operator()(const CMapId& lhs, - const CMapId& rhs) { - return lhs.HashCode() > rhs.HashCode(); -} - -/****************************************************************************** - * CMapTable::CMap class - ******************************************************************************/ -CMapTable::CMap::CMap(ReadableFontData* data, int32_t format, - const CMapId& cmap_id) - : SubTable(data), format_(format), cmap_id_(cmap_id) { -} - -CMapTable::CMap::~CMap() { -} - -/****************************************************************************** - * CMapTable::CMap::Builder class - ******************************************************************************/ -CMapTable::CMap::Builder::~Builder() { -} - -CALLER_ATTACH CMapTable::CMap::Builder* - CMapTable::CMap::Builder::GetBuilder( - FontDataTableBuilderContainer* container, - ReadableFontData* data, - int32_t offset, - const CMapId& cmap_id) { - // NOT IMPLEMENTED: Java enum value validation - int32_t format = data->ReadUShort(offset); - CMapBuilderPtr builder; - switch (format) { - case CMapFormat::kFormat0: - builder = new CMapFormat0::Builder(container, data, offset, cmap_id); - break; - case CMapFormat::kFormat2: - builder = new CMapFormat0::Builder(container, data, offset, cmap_id); - break; - default: - break; - } - return builder.Detach(); -} - -CMapTable::CMap::Builder::Builder(FontDataTableBuilderContainer* container, - ReadableFontData* data, int32_t format, - const CMapId& cmap_id) - : SubTable::Builder(container, data), - format_(format), - cmap_id_(cmap_id) { -} - -CMapTable::CMap::Builder::Builder(FontDataTableBuilderContainer* container, - WritableFontData* data, int32_t format, - const CMapId& cmap_id) - : SubTable::Builder(container, data), - format_(format), - cmap_id_(cmap_id) { -} - -int32_t CMapTable::CMap::Builder::SubSerialize(WritableFontData* new_data) { - return InternalReadData()->CopyTo(new_data); -} - -bool CMapTable::CMap::Builder::SubReadyToSerialize() { - return true; -} - -int32_t CMapTable::CMap::Builder::SubDataSizeToSerialize() { - return InternalReadData()->Length(); -} - -void CMapTable::CMap::Builder::SubDataSet() { - // NOP -} - -/****************************************************************************** - * CMapTable::CMapFormat0 - ******************************************************************************/ -CMapTable::CMapFormat0::~CMapFormat0() { -} - -int32_t CMapTable::CMapFormat0::Language() { - return 0; -} - -int32_t CMapTable::CMapFormat0::GlyphId(int32_t character) { - if (character < 0 || character > 255) { - return CMapTable::NOTDEF; - } - return data_->ReadByte(character + Offset::kFormat0GlyphIdArray); -} - -CMapTable::CMapFormat0::CMapFormat0(ReadableFontData* data, - const CMapId& cmap_id) - : CMap(data, CMapFormat::kFormat0, cmap_id) { -} - -/****************************************************************************** - * CMapTable::CMapFormat0::Builder - ******************************************************************************/ -CMapTable::CMapFormat0::Builder::Builder( - FontDataTableBuilderContainer* container, - WritableFontData* data, - int32_t offset, - const CMapId& cmap_id) - : CMapTable::CMap::Builder(container, - data ? down_cast( - data->Slice(offset, data->ReadUShort( - offset + Offset::kFormat0Length))) - : reinterpret_cast(NULL), - CMapFormat::kFormat0, cmap_id) { - // TODO(arthurhsu): FIXIT: heavy lifting and leak, need fix. -} - -CMapTable::CMapFormat0::Builder::Builder( - FontDataTableBuilderContainer* container, - ReadableFontData* data, - int32_t offset, - const CMapId& cmap_id) - : CMapTable::CMap::Builder(container, - data ? down_cast( - data->Slice(offset, data->ReadUShort( - offset + Offset::kFormat0Length))) - : reinterpret_cast(NULL), - CMapFormat::kFormat0, cmap_id) { - // TODO(arthurhsu): FIXIT: heavy lifting and leak, need fix. -} - -CMapTable::CMapFormat0::Builder::~Builder() { -} - -CALLER_ATTACH FontDataTable* - CMapTable::CMapFormat0::Builder::SubBuildTable(ReadableFontData* data) { - FontDataTablePtr table = new CMapFormat0(data, cmap_id()); - return table.Detach(); -} - -/****************************************************************************** - * CMapTable::CMapFormat2 - ******************************************************************************/ -CMapTable::CMapFormat2::~CMapFormat2() { -} - -int32_t CMapTable::CMapFormat2::Language() { - return 0; -} - -int32_t CMapTable::CMapFormat2::GlyphId(int32_t character) { - if (character > 0xffff) { - return CMapTable::NOTDEF; - } - - uint32_t c = ToBE32(character); - byte_t high_byte = (c >> 8) & 0xff; - byte_t low_byte = c & 0xff; - int32_t offset = SubHeaderOffset(high_byte); - - if (offset == 0) { - low_byte = high_byte; - high_byte = 0; - } - - int32_t first_code = FirstCode(high_byte); - int32_t entry_count = EntryCount(high_byte); - - if (low_byte < first_code || low_byte >= first_code + entry_count) { - return CMapTable::NOTDEF; - } - - int32_t id_range_offset = IdRangeOffset(high_byte); - - // position of idRangeOffset + value of idRangeOffset + index for low byte - // = firstcode - int32_t p_location = (offset + Offset::kFormat2SubHeader_idRangeOffset) + - id_range_offset + - (low_byte - first_code) * DataSize::kUSHORT; - int p = data_->ReadUShort(p_location); - if (p == 0) { - return CMapTable::NOTDEF; - } - - if (offset == 0) { - return p; - } - int id_delta = IdDelta(high_byte); - return (p + id_delta) % 65536; -} - -int32_t CMapTable::CMapFormat2::BytesConsumed(int32_t character) { - uint32_t c = ToBE32(character); - int32_t high_byte = (c >> 8) & 0xff; - int32_t offset = SubHeaderOffset(high_byte); - return (offset == 0) ? 1 : 2; -} - -CMapTable::CMapFormat2::CMapFormat2(ReadableFontData* data, - const CMapId& cmap_id) - : CMap(data, CMapFormat::kFormat2, cmap_id) { -} - -int32_t CMapTable::CMapFormat2::SubHeaderOffset(int32_t sub_header_index) { - return data_->ReadUShort(Offset::kFormat2SubHeaderKeys + - sub_header_index * DataSize::kUSHORT); -} - -int32_t CMapTable::CMapFormat2::FirstCode(int32_t sub_header_index) { - int32_t sub_header_offset = SubHeaderOffset(sub_header_index); - return data_->ReadUShort(sub_header_offset + - Offset::kFormat2SubHeaderKeys + - Offset::kFormat2SubHeader_firstCode); -} - -int32_t CMapTable::CMapFormat2::EntryCount(int32_t sub_header_index) { - int32_t sub_header_offset = SubHeaderOffset(sub_header_index); - return data_->ReadUShort(sub_header_offset + - Offset::kFormat2SubHeaderKeys + - Offset::kFormat2SubHeader_entryCount); -} - -int32_t CMapTable::CMapFormat2::IdRangeOffset(int32_t sub_header_index) { - int32_t sub_header_offset = SubHeaderOffset(sub_header_index); - return data_->ReadUShort(sub_header_offset + - Offset::kFormat2SubHeaderKeys + - Offset::kFormat2SubHeader_idRangeOffset); -} - -int32_t CMapTable::CMapFormat2::IdDelta(int32_t sub_header_index) { - int32_t sub_header_offset = SubHeaderOffset(sub_header_index); - return data_->ReadUShort(sub_header_offset + - Offset::kFormat2SubHeaderKeys + - Offset::kFormat2SubHeader_idDelta); -} - -/****************************************************************************** - * CMapTable::CMapFormat2::Builder - ******************************************************************************/ -CMapTable::CMapFormat2::Builder::Builder( - FontDataTableBuilderContainer* container, - WritableFontData* data, - int32_t offset, - const CMapId& cmap_id) - : CMapTable::CMap::Builder(container, - data ? down_cast( - data->Slice(offset, data->ReadUShort( - offset + Offset::kFormat0Length))) - : reinterpret_cast(NULL), - CMapFormat::kFormat2, cmap_id) { - // TODO(arthurhsu): FIXIT: heavy lifting and leak, need fix. -} - -CMapTable::CMapFormat2::Builder::Builder( - FontDataTableBuilderContainer* container, - ReadableFontData* data, - int32_t offset, - const CMapId& cmap_id) - : CMapTable::CMap::Builder(container, - data ? down_cast( - data->Slice(offset, data->ReadUShort( - offset + Offset::kFormat0Length))) - : reinterpret_cast(NULL), - CMapFormat::kFormat2, cmap_id) { - // TODO(arthurhsu): FIXIT: heavy lifting and leak, need fix. -} - -CMapTable::CMapFormat2::Builder::~Builder() { -} - -CALLER_ATTACH FontDataTable* - CMapTable::CMapFormat2::Builder::SubBuildTable(ReadableFontData* data) { - FontDataTablePtr table = new CMapFormat2(data, cmap_id()); - return table.Detach(); -} - -/****************************************************************************** - * CMapTable::Iterator class - ******************************************************************************/ -CMapTable::CMapIterator::CMapIterator(CMapTable* table, CMapFilter* filter) - : table_index_(0), filter_(filter), table_(table) {} - -bool CMapTable::CMapIterator::HasNext() { - if (!filter_) { - if (table_index_ < table_->NumCMaps()) { - return true; - } - return false; - } - - for (; table_index_ < table_->NumCMaps(); ++table_index_) { - if (filter_->accept(table_->GetCMapId(table_index_))) { - return true; - } - } - return false; -} - -/****************************************************************************** - * CMapTable::Builder class - ******************************************************************************/ -CMapTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data) - : Table::ArrayElementTableBuilder(font_builder, header, data) { -} - -CMapTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data) - : Table::ArrayElementTableBuilder(font_builder, header, data) { -} - -CMapTable::Builder::~Builder() { -} - -int32_t CMapTable::Builder::SubSerialize(WritableFontData* new_data) { - int32_t size = new_data->WriteUShort(CMapTable::Offset::kVersion, - version_); - size += new_data->WriteUShort(CMapTable::Offset::kNumTables, - cmap_builders_.size()); - - int32_t index_offset = size; - size += cmap_builders_.size() * CMapTable::Offset::kEncodingRecordSize; - for (CMapBuilderMap::iterator it = cmap_builders_.begin(), - e = cmap_builders_.end(); it != e; ++it) { - CMapBuilderPtr b = it->second; - // header entry - index_offset += new_data->WriteUShort(index_offset, b->platform_id()); - index_offset += new_data->WriteUShort(index_offset, b->encoding_id()); - index_offset += new_data->WriteULong(index_offset, size); - - // cmap - FontDataPtr slice; - slice.Attach(new_data->Slice(size)); - size += b->SubSerialize(down_cast(slice.p_)); - } - return size; -} - -bool CMapTable::Builder::SubReadyToSerialize() { - if (cmap_builders_.empty()) - return false; - - // check each table - for (CMapBuilderMap::iterator it = cmap_builders_.begin(), - e = cmap_builders_.end(); it != e; ++it) { - if (!it->second->SubReadyToSerialize()) - return false; - } - return true; -} - -int32_t CMapTable::Builder::SubDataSizeToSerialize() { - if (cmap_builders_.empty()) - return 0; - - bool variable = false; - int32_t size = CMapTable::Offset::kEncodingRecordStart + - cmap_builders_.size() * CMapTable::Offset::kEncodingRecordSize; - - // calculate size of each table - for (CMapBuilderMap::iterator it = cmap_builders_.begin(), - e = cmap_builders_.end(); it != e; ++it) { - int32_t cmap_size = it->second->SubDataSizeToSerialize(); - size += abs(cmap_size); - variable |= cmap_size <= 0; - } - return variable ? -size : size; -} - -void CMapTable::Builder::SubDataSet() { - cmap_builders_.clear(); - Table::Builder::set_model_changed(false); -} - -CALLER_ATTACH FontDataTable* - CMapTable::Builder::SubBuildTable(ReadableFontData* data) { - FontDataTablePtr table = new CMapTable(header(), data); - return table.Detach(); -} - -CALLER_ATTACH CMapTable::CMap::Builder* CMapTable::Builder::CMapBuilder( - FontDataTableBuilderContainer* container, ReadableFontData* data, - int32_t index) { - if (index < 0 || index > NumCMaps(data)) - return NULL; - - int32_t record_offset = Offset::kEncodingRecordOffset + index * - Offset::kEncodingRecordSize; - int32_t platform_id = - data->ReadUShort(Offset::kEncodingRecordPlatformId + record_offset); - int32_t encoding_id = - data->ReadUShort(Offset::kEncodingRecordEncodingId + record_offset); - CMapId cmap_id(platform_id, encoding_id); - int32_t offset = - data->ReadULongAsInt(Offset::kEncodingRecordOffset + record_offset); - return CMap::Builder::GetBuilder(container, data, offset, cmap_id); -} - -int32_t CMapTable::Builder::NumCMaps(ReadableFontData* data) { - if (data == NULL) { - return 0; - } - return data->ReadUShort(Offset::kNumTables); -} - -} // namespace sfntly diff --git a/sfntly/cmap_table.h b/sfntly/cmap_table.h deleted file mode 100644 index cdbcad8..0000000 --- a/sfntly/cmap_table.h +++ /dev/null @@ -1,447 +0,0 @@ -/* - * 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. - */ - -// TODO(arthurhsu): IMPLEMENT: not really used and tested, need cleanup -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_CMAP_TABLE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_CMAP_TABLE_H_ - -#include -#include - -#include "sfntly/port/refcount.h" -#include "sfntly/table.h" -#include "sfntly/subtable.h" - -namespace sfntly { - -// CMap subtable formats -struct CMapFormat { - enum { - kFormat0 = 0, - kFormat2 = 2, - kFormat4 = 4, - kFormat6 = 6, - kFormat8 = 8, - kFormat10 = 10, - kFormat12 = 12, - kFormat13 = 13, - kFormat14 = 14 - }; -}; - -// A CMap table -class CMapTable : public Table, public RefCounted { -public: - // CMapTable::CMapId - class CMapId { - public: - CMapId(int32_t platform_id, int32_t encoding_id); - CMapId(const CMapId& obj); - - int32_t platform_id() { return platform_id_; } - int32_t encoding_id() { return encoding_id_; } - - bool operator==(const CMapId& obj); - const CMapId& operator=(const CMapId& obj); - int HashCode() const; - - friend class CMapIdComparator; - - private: - int32_t platform_id_; - int32_t encoding_id_; - }; - static CMapId WINDOWS_BMP; - static CMapId WINDOWS_UCS4; - static CMapId MAC_ROMAN; - - // CMapTable::CMapIdComparator - class CMapIdComparator { - public: - bool operator()(const CMapId& lhs, const CMapId& rhs); - }; - - // A filter on cmap - // CMapTable::CMapFilter - class CMapFilter { - public: - // Test on whether the cmap is acceptable or not - // @param cmap_id the id of the cmap - // @return true if the cmap is acceptable; false otherwise - virtual bool accept(CMapId cmap_id) = 0; - // Make gcc -Wnon-virtual-dtor happy. - virtual ~CMapFilter() {} - }; - - // The abstract base class for all cmaps. - // - // CMap equality is based on the equality of the (@link {@link CMapId} that - // defines the CMap. In the cmap table for a font there can only be one cmap - // with a given cmap id (pair of platform and encoding ids) no matter what the - // type of the cmap is. - // - // The cmap implements {@code Iterable} to allow iteration over - // characters that are mapped by the cmap. This iteration mostly returns the - // characters mapped by the cmap. It will return all characters mapped by the - // cmap to anything but .notdef but it may return some that are not - // mapped or are mapped to .notdef. Various cmap tables provide ranges and - // such to describe characters for lookup but without going the full way to - // mapping to the glyph id it isn't always possible to tell if a character - // will end up with a valid glyph id. So, some of the characters returned from - // the iterator may still end up pointing to the .notdef glyph. However, the - // number of such characters should be small in most cases with well designed - // cmaps. - class Builder; - class CMap : public SubTable { - public: - // CMapTable::CMap::Builder - class Builder : public SubTable::Builder { - public: - virtual ~Builder(); - - CALLER_ATTACH static Builder* - GetBuilder(FontDataTableBuilderContainer* container, - ReadableFontData* data, - int32_t offset, - const CMapId& cmap_id); - - // Note: yes, an object is returned on stack since it's small enough. - virtual CMapId cmap_id() { return cmap_id_; } - virtual int32_t platform_id() { return cmap_id_.platform_id(); } - virtual int32_t encoding_id() { return cmap_id_.encoding_id(); } - - protected: - Builder(FontDataTableBuilderContainer* container, - ReadableFontData* data, - int32_t format, - const CMapId& cmap_id); - Builder(FontDataTableBuilderContainer* container, - WritableFontData* data, - int32_t format, - const CMapId& cmap_id); - - virtual int32_t SubSerialize(WritableFontData* new_data); - virtual bool SubReadyToSerialize(); - virtual int32_t SubDataSizeToSerialize(); - virtual void SubDataSet(); - - private: - int32_t format_; - CMapId cmap_id_; - - friend class CMapTable::Builder; - }; - - CMap(ReadableFontData* data, int32_t format, const CMapId& cmap_id); - virtual ~CMap(); - virtual int32_t format() { return format_; } - virtual CMapId cmap_id() { return cmap_id_; } - virtual int32_t platform_id() { return cmap_id_.platform_id(); } - virtual int32_t encoding_id() { return cmap_id_.encoding_id(); } - - // Get the language of the cmap. - // - // Note on the language field in 'cmap' subtables: The language field must - // be set to zero for all cmap subtables whose platform IDs are other than - // Macintosh (platform ID 1). For cmap subtables whose platform IDs are - // Macintosh, set this field to the Macintosh language ID of the cmap - // subtable plus one, or to zero if the cmap subtable is not - // language-specific. For example, a Mac OS Turkish cmap subtable must set - // this field to 18, since the Macintosh language ID for Turkish is 17. A - // Mac OS Roman cmap subtable must set this field to 0, since Mac OS Roman - // is not a language-specific encoding. - // - // @return the language id - virtual int32_t Language() = 0; - - // Gets the glyph id for the character code provided. - // The character code provided must be in the encoding used by the cmap - // table. - virtual int32_t GlyphId(int32_t character) = 0; - - private: - int32_t format_; - CMapId cmap_id_; - }; - typedef Ptr CMapBuilderPtr; - typedef std::map CMapBuilderMap; - - // A cmap format 0 sub table - class CMapFormat0 : public CMap, public RefCounted { - public: - // CMapTable::CMapFormat0::Builder - class Builder : public CMap::Builder, - public RefCounted { - public: - Builder(FontDataTableBuilderContainer* container, - ReadableFontData* data, - int32_t offset, - const CMapId& cmap_id); - Builder(FontDataTableBuilderContainer* container, - WritableFontData* data, - int32_t offset, - const CMapId& cmap_id); - virtual ~Builder(); - - protected: - virtual CALLER_ATTACH FontDataTable* - SubBuildTable(ReadableFontData* data); - }; - - virtual ~CMapFormat0(); - virtual int32_t Language(); - virtual int32_t GlyphId(int32_t character); - - private: - CMapFormat0(ReadableFontData* data, const CMapId& cmap_id); - }; - - // A cmap format 2 sub table - // The format 2 cmap is used for multi-byte encodings such as SJIS, - // EUC-JP/KR/CN, Big5, etc. - class CMapFormat2 : public CMap, public RefCounted { - public: - // CMapTable::CMapFormat2::Builder - class Builder : public CMap::Builder, - public RefCounted { - public: - Builder(FontDataTableBuilderContainer* container, - ReadableFontData* data, - int32_t offset, - const CMapId& cmap_id); - Builder(FontDataTableBuilderContainer* container, - WritableFontData* data, - int32_t offset, - const CMapId& cmap_id); - virtual ~Builder(); - - protected: - virtual CALLER_ATTACH FontDataTable* - SubBuildTable(ReadableFontData* data); - }; - - virtual ~CMapFormat2(); - virtual int32_t Language(); - virtual int32_t GlyphId(int32_t character); - - // Returns how many bytes would be consumed by a lookup of this character - // with this cmap. This comes about because the cmap format 2 table is - // designed around multi-byte encodings such as SJIS, EUC-JP, Big5, etc. - // return the number of bytes consumed from this "character" - either 1 or 2 - virtual int32_t BytesConsumed(int32_t character); - - private: - CMapFormat2(ReadableFontData* data, const CMapId& cmap_id); - - int32_t SubHeaderOffset(int32_t sub_header_index); - int32_t FirstCode(int32_t sub_header_index); - int32_t EntryCount(int32_t sub_header_index); - int32_t IdRangeOffset(int32_t sub_header_index); - int32_t IdDelta(int32_t sub_header_index); - }; - - // CMapTable::Builder - class Builder : public Table::ArrayElementTableBuilder, - public RefCounted { - public: - // Constructor scope altered to public because C++ does not allow base - // class to instantiate derived class with protected constructors. - Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data); - Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data); - virtual ~Builder(); - - virtual int32_t SubSerialize(WritableFontData* new_data); - virtual bool SubReadyToSerialize(); - virtual int32_t SubDataSizeToSerialize(); - virtual void SubDataSet(); - virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); - - protected: - static CALLER_ATTACH CMap::Builder* - CMapBuilder(FontDataTableBuilderContainer* container, - ReadableFontData* data, - int32_t index); - - private: - static int32_t NumCMaps(ReadableFontData* data); - - int32_t version_; - CMapBuilderMap cmap_builders_; - }; - - virtual ~CMapTable(); - - // Get the table version. - virtual int32_t Version(); - - // Get the number of cmaps within the CMap table. - virtual int32_t NumCMaps(); - - // Get the cmap id for the cmap with the given index. - // Note: yes, an object is returned on stack since it's small enough. - // This function is renamed from cmapId to GetCMapId(). - virtual CMapId GetCMapId(int32_t index); - - virtual int32_t PlatformId(int32_t index); - virtual int32_t EncodingId(int32_t index); - - // Get the offset in the table data for the cmap table with the given index. - // The offset is from the beginning of the table. - virtual int32_t Offset(int32_t index); - - private: - static const int32_t NOTDEF; - - // Offsets to specific elements in the underlying data. These offsets are - // relative to the start of the table or the start of sub-blocks within - // the table. - struct Offset { - enum { - kVersion = 0, - kNumTables = 2, - kEncodingRecordStart = 4, - - // offsets relative to the encoding record - kEncodingRecordPlatformId = 0, - kEncodingRecordEncodingId = 2, - kEncodingRecordOffset = 4, - kEncodingRecordSize = 8, - - kFormat = 0, - - // Format 0: Byte encoding table - kFormat0Format = 0, - kFormat0Length = 2, - kFormat0Language = 4, - kFormat0GlyphIdArray = 6, - - // Format 2: High-byte mapping through table - kFormat2Format = 0, - kFormat2Length = 2, - kFormat2Language = 4, - kFormat2SubHeaderKeys = 6, - kFormat2SubHeaders = 518, - // offset relative to the subHeader structure - kFormat2SubHeader_firstCode = 0, - kFormat2SubHeader_entryCount = 2, - kFormat2SubHeader_idDelta = 4, - kFormat2SubHeader_idRangeOffset = 6, - kFormat2SubHeader_structLength = 8, - - // Format 4: Segment mapping to delta values - kFormat4Format = 0, - kFormat4Length = 2, - kFormat4Language = 4, - kFormat4SegCountX2 = 6, - kFormat4SearchRange = 8, - kFormat4EntrySelector = 10, - kFormat4RangeShift = 12, - kFormat4EndCount = 14, - - // format 6: Trimmed table mapping - kFormat6Format = 0, - kFormat6Length = 2, - kFormat6Language = 4, - kFormat6FirstCode = 6, - kFormat6EntryCount = 8, - kFormat6GlyphIdArray = 10, - - // Format 8: mixed 16-bit and 32-bit coverage - kFormat8Format = 0, - kFormat8Length = 4, - kFormat8Language = 8, - kFormat8Is32 = 12, - kFormat8nGroups204 = 8204, - kFormat8Groups208 = 8208, - // offset relative to the group structure - kFormat8Group_startCharCode = 0, - kFormat8Group_endCharCode = 4, - kFormat8Group_startGlyphId = 8, - kFormat8Group_structLength = 12, - - // Format 10: Trimmed array - kFormat10Format = 0, - kFormat10Length = 4, - kFormat10Language = 8, - kFormat10StartCharCode = 12, - kFormat10NumChars = 16, - kFormat10Glyphs0 = 20, - - // Format 12: Segmented coverage - kFormat12Format = 0, - kFormat12Length = 4, - kFormat12Language = 8, - kFormat12nGroups = 12, - kFormat12Groups = 16, - kFormat12Groups_structLength = 12, - // offsets within the group structure - kFormat12_startCharCode = 0, - kFormat12_endCharCode = 4, - kFormat12_startGlyphId = 8, - - // Format 13: Last Resort Font - kFormat13Format = 0, - kFormat13Length = 4, - kFormat13Language = 8, - kFormat13nGroups = 12, - kFormat13Groups = 16, - kFormat13Groups_structLength = 12, - // offsets within the group structure - kFormat13_startCharCode = 0, - kFormat13_endCharCode = 4, - kFormat13_glyphId = 8, - - // Format 14: Unicode Variation Sequences - kFormat14Format = 0, - kFormat14Length = 2, - - // TODO(stuartg): finish tables - // Default UVS Table - - // Non-default UVS Table - kLast = -1 - }; - }; - - class CMapIterator { - public: - // If filter is NULL, filter through all tables. - CMapIterator(CMapTable* table, CMapFilter* filter); - bool HasNext(); - CMap* Next(); - - private: - int32_t table_index_; - CMapFilter* filter_; - CMapTable* table_; - }; - - CMapTable(Header* header, ReadableFontData* data); - - // Get the offset in the table data for the encoding record for the cmap with - // the given index. The offset is from the beginning of the table. - int32_t OffsetForEncodingRecord(int32_t index); -}; -typedef std::vector CMapIdList; -typedef Ptr CMapTablePtr; - -} // namespace sfntly - -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_CMAP_TABLE_H_ diff --git a/sfntly/data/byte_array.h b/sfntly/data/byte_array.h index 3375244..70dc92f 100644 --- a/sfntly/data/byte_array.h +++ b/sfntly/data/byte_array.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_BYTE_ARRAY_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_BYTE_ARRAY_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_DATA_BYTE_ARRAY_H_ +#define SFNTLY_CPP_SRC_SFNTLY_DATA_BYTE_ARRAY_H_ #include "sfntly/port/refcount.h" #include "sfntly/port/type.h" @@ -198,4 +198,4 @@ typedef Ptr ByteArrayPtr; } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_BYTE_ARRAY_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_DATA_BYTE_ARRAY_H_ diff --git a/sfntly/data/font_data.h b/sfntly/data/font_data.h index 6ac4d5d..ec87c72 100644 --- a/sfntly/data/font_data.h +++ b/sfntly/data/font_data.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_FONT_DATA_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_FONT_DATA_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_DATA_H_ +#define SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_DATA_H_ #include @@ -127,4 +127,4 @@ typedef Ptr FontDataPtr; } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_FONT_DATA_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_DATA_H_ diff --git a/sfntly/data/font_input_stream.h b/sfntly/data/font_input_stream.h index 5d9959d..9992b07 100644 --- a/sfntly/data/font_input_stream.h +++ b/sfntly/data/font_input_stream.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_FONT_INPUT_STREAM_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_FONT_INPUT_STREAM_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_INPUT_STREAM_H_ +#define SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_INPUT_STREAM_H_ #include "sfntly/port/type.h" #include "sfntly/port/input_stream.h" @@ -94,4 +94,4 @@ class FontInputStream : public InputStream { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_FONT_INPUT_STREAM_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_INPUT_STREAM_H_ diff --git a/sfntly/data/font_output_stream.h b/sfntly/data/font_output_stream.h index f420af4..fcd48e8 100644 --- a/sfntly/data/font_output_stream.h +++ b/sfntly/data/font_output_stream.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_FONT_OUTPUT_STREAM_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_FONT_OUTPUT_STREAM_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_OUTPUT_STREAM_H_ +#define SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_OUTPUT_STREAM_H_ #include "sfntly/port/type.h" #include "sfntly/port/output_stream.h" @@ -76,4 +76,4 @@ class FontOutputStream : public OutputStream { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_FONT_OUTPUT_STREAM_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_DATA_FONT_OUTPUT_STREAM_H_ diff --git a/sfntly/data/growable_memory_byte_array.h b/sfntly/data/growable_memory_byte_array.h index 0e35de6..8583a0d 100644 --- a/sfntly/data/growable_memory_byte_array.h +++ b/sfntly/data/growable_memory_byte_array.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_GROWABLE_MEMORY_BYTE_ARRAY_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_GROWABLE_MEMORY_BYTE_ARRAY_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_DATA_GROWABLE_MEMORY_BYTE_ARRAY_H_ +#define SFNTLY_CPP_SRC_SFNTLY_DATA_GROWABLE_MEMORY_BYTE_ARRAY_H_ #include "sfntly/data/byte_array.h" @@ -63,4 +63,4 @@ class GrowableMemoryByteArray : public ByteArray, } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_GROWABLE_MEMORY_BYTE_ARRAY_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_DATA_GROWABLE_MEMORY_BYTE_ARRAY_H_ diff --git a/sfntly/data/memory_byte_array.h b/sfntly/data/memory_byte_array.h index 9de5230..838fd1a 100644 --- a/sfntly/data/memory_byte_array.h +++ b/sfntly/data/memory_byte_array.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_MEMORY_BYTE_ARRAY_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_MEMORY_BYTE_ARRAY_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_DATA_MEMORY_BYTE_ARRAY_H_ +#define SFNTLY_CPP_SRC_SFNTLY_DATA_MEMORY_BYTE_ARRAY_H_ #include "sfntly/data/byte_array.h" @@ -78,4 +78,4 @@ class MemoryByteArray : public ByteArray, public RefCounted { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_MEMORY_BYTE_ARRAY_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_DATA_MEMORY_BYTE_ARRAY_H_ diff --git a/sfntly/data/readable_font_data.h b/sfntly/data/readable_font_data.h index 48b3e77..34d7179 100644 --- a/sfntly/data/readable_font_data.h +++ b/sfntly/data/readable_font_data.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_READABLE_FONT_DATA_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_READABLE_FONT_DATA_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_DATA_READABLE_FONT_DATA_H_ +#define SFNTLY_CPP_SRC_SFNTLY_DATA_READABLE_FONT_DATA_H_ #include "sfntly/port/refcount.h" #include "sfntly/data/font_data.h" @@ -287,4 +287,4 @@ typedef Ptr ReadableFontDataPtr; } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_READABLE_FONT_DATA_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_DATA_READABLE_FONT_DATA_H_ diff --git a/sfntly/data/writable_font_data.h b/sfntly/data/writable_font_data.h index f674ae1..7fac998 100644 --- a/sfntly/data/writable_font_data.h +++ b/sfntly/data/writable_font_data.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_WRITABLE_FONT_DATA_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_WRITABLE_FONT_DATA_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_DATA_WRITABLE_FONT_DATA_H_ +#define SFNTLY_CPP_SRC_SFNTLY_DATA_WRITABLE_FONT_DATA_H_ #include "sfntly/data/readable_font_data.h" @@ -179,4 +179,4 @@ typedef Ptr WritableFontDataPtr; } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_DATA_WRITABLE_FONT_DATA_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_DATA_WRITABLE_FONT_DATA_H_ diff --git a/sfntly/font.cc b/sfntly/font.cc index 8d264b5..14f1505 100644 --- a/sfntly/font.cc +++ b/sfntly/font.cc @@ -25,12 +25,12 @@ #include "sfntly/font_factory.h" #include "sfntly/math/fixed1616.h" #include "sfntly/math/font_math.h" -#include "sfntly/font_header_table.h" -#include "sfntly/horizontal_header_table.h" -#include "sfntly/horizontal_metrics_table.h" -#include "sfntly/loca_table.h" -#include "sfntly/maximum_profile_table.h" #include "sfntly/port/exception_type.h" +#include "sfntly/table/core/font_header_table.h" +#include "sfntly/table/core/horizontal_header_table.h" +#include "sfntly/table/core/horizontal_metrics_table.h" +#include "sfntly/table/core/maximum_profile_table.h" +#include "sfntly/table/truetype/loca_table.h" #include "sfntly/tag.h" namespace sfntly { diff --git a/sfntly/font.h b/sfntly/font.h index 5ce7f17..72b10ac 100644 --- a/sfntly/font.h +++ b/sfntly/font.h @@ -14,19 +14,19 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_FONT_H_ +#define SFNTLY_CPP_SRC_SFNTLY_FONT_H_ #include #include "sfntly/port/refcount.h" #include "sfntly/port/type.h" #include "sfntly/port/endian.h" -#include "sfntly/table.h" #include "sfntly/font_data_table_builder_container.h" #include "sfntly/data/font_input_stream.h" #include "sfntly/data/font_output_stream.h" #include "sfntly/data/writable_font_data.h" +#include "sfntly/table/table.h" namespace sfntly { @@ -293,4 +293,4 @@ typedef std::vector FontBuilderArray; } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_FONT_H_ diff --git a/sfntly/font_data_table.cc b/sfntly/font_data_table.cc deleted file mode 100644 index e6d0984..0000000 --- a/sfntly/font_data_table.cc +++ /dev/null @@ -1,176 +0,0 @@ -/* - * 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 "sfntly/font_data_table.h" - -#include "sfntly/data/font_output_stream.h" - -namespace sfntly { - -/****************************************************************************** - * FontDataTable class - ******************************************************************************/ - -FontDataTable::FontDataTable(ReadableFontData* data) { - data_ = data; -} - -FontDataTable::~FontDataTable() {} - -ReadableFontData* FontDataTable::ReadFontData() { - return data_; -} - -int32_t FontDataTable::Length() { - return data_->Length(); -} - -int32_t FontDataTable::Padding() { - return -1; -} - -int32_t FontDataTable::DataLength() { - int32_t paddings = Padding(); - return (paddings == -1) ? Length() : Length() - paddings; -} - -int32_t FontDataTable::Serialize(OutputStream* os) { - return data_->CopyTo(os); -} - -/****************************************************************************** - * FontDataTable::Builder class - ******************************************************************************/ -CALLER_ATTACH WritableFontData* FontDataTable::Builder::Data() { - WritableFontDataPtr new_data; - if (model_changed_) { - if (!SubReadyToSerialize()) { - return NULL; - } - int32_t size = SubDataSizeToSerialize(); - new_data.Attach(container_->GetNewData(size)); - SubSerialize(new_data); - } else { - ReadableFontDataPtr data = InternalReadData(); - new_data.Attach(container_->GetNewData(data != NULL ? data->Length() : 0)); - data->CopyTo(new_data); - } - return new_data.Detach(); -} - -void FontDataTable::Builder::SetData(ReadableFontData* data) { - InternalSetData(data, true); -} - - -CALLER_ATTACH FontDataTable* FontDataTable::Builder::Build() { - ReadableFontDataPtr data = InternalReadData(); - if (model_changed_) { - // Let subclass serialize from model. - if (!SubReadyToSerialize()) { - return NULL; - } - int32_t size = SubDataSizeToSerialize(); - WritableFontDataPtr new_data; - new_data.Attach(container_->GetNewData(size)); - SubSerialize(new_data); - data = new_data; - } - - if (data == NULL) { - return NULL; // Do not build table with NULL data. - } - - FontDataTablePtr table = SubBuildTable(data); - NotifyPostTableBuild(table); - return table; -} - -bool FontDataTable::Builder::ReadyToBuild() { - return true; -} - -ReadableFontData* FontDataTable::Builder::InternalReadData() { - return (r_data_ != NULL) ? r_data_.p_ : - static_cast(w_data_.p_); -} - -WritableFontData* FontDataTable::Builder::InternalWriteData() { - if (w_data_ == NULL) { - WritableFontDataPtr new_data; - new_data.Attach(container_->GetNewData(r_data_->Length())); - r_data_->CopyTo(new_data); - InternalSetData(new_data, false); - } - return w_data_.p_; -} - -CALLER_ATTACH WritableFontData* - FontDataTable::Builder::InternalNewData(int32_t size) { - return container_->GetNewData(size); -} - -FontDataTable::Builder::Builder(FontDataTableBuilderContainer* container) { - Init(container); -} - -FontDataTable::Builder::Builder(FontDataTableBuilderContainer* container, - WritableFontData* data) { - Init(container); - w_data_ = data; -} - -FontDataTable::Builder::Builder(FontDataTableBuilderContainer* container, - ReadableFontData* data) { - Init(container); - r_data_ = data; -} - -FontDataTable::Builder::~Builder() { -} - -void FontDataTable::Builder::Init(FontDataTableBuilderContainer* container) { - container_ = container; - model_changed_ = false; - data_changed_ = false; -} - -void FontDataTable::Builder::NotifyPostTableBuild(FontDataTable* table) { - // Default: NOP. - UNREFERENCED_PARAMETER(table); -} - -void FontDataTable::Builder::InternalSetData(WritableFontData* data, - bool data_changed) { - w_data_ = data; - r_data_ = NULL; - if (data_changed) { - data_changed_ = true; - SubDataSet(); - } -} - -void FontDataTable::Builder::InternalSetData(ReadableFontData* data, - bool data_changed) { - w_data_ = NULL; - r_data_ = data; - if (data_changed) { - data_changed_ = true; - SubDataSet(); - } -} - -} // namespace sfntly diff --git a/sfntly/font_data_table.h b/sfntly/font_data_table.h deleted file mode 100644 index 207d492..0000000 --- a/sfntly/font_data_table.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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. - */ - -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_DATA_TABLE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_DATA_TABLE_H_ - -#include "sfntly/data/readable_font_data.h" -#include "sfntly/font_data_table_builder_container.h" -#include "sfntly/port/refcount.h" - -namespace sfntly { - -class FontDataTable : virtual public RefCount { - public: - // Note: original version is abstract Builder - // C++ template is not designed that way so plain class is chosen. - class Builder : virtual public RefCount { - public: - // Get a snapshot copy of the internal data of the builder. - // This causes any internal data structures to be serialized to a new data - // object. This data object belongs to the caller and must be properly - // disposed of. No changes are made to the builder and any changes to the - // data directly do not affect the internal state. To do that a subsequent - // call must be made to {@link #SetData(WritableFontData)}. - // @return a copy of the internal data of the builder - CALLER_ATTACH WritableFontData* Data(); - virtual void SetData(ReadableFontData* data); - - // Note: changed from protected to avoid accessibility error in C++ - virtual CALLER_ATTACH FontDataTable* Build(); - virtual bool ReadyToBuild(); - - ReadableFontData* InternalReadData(); - WritableFontData* InternalWriteData(); - CALLER_ATTACH WritableFontData* InternalNewData(int32_t size); - - bool data_changed() { return data_changed_; } - bool model_changed() { return model_changed_; } - bool set_model_changed() { return set_model_changed(true); } - bool set_model_changed(bool changed) { - bool old = model_changed_; - model_changed_ = changed; - return old; - } - - protected: - explicit Builder(FontDataTableBuilderContainer* container); - Builder(FontDataTableBuilderContainer* container, WritableFontData* data); - Builder(FontDataTableBuilderContainer* container, ReadableFontData* data); - virtual ~Builder(); - - void Init(FontDataTableBuilderContainer* container); - - // subclass API - virtual void NotifyPostTableBuild(FontDataTable* table); - virtual int32_t SubSerialize(WritableFontData* new_data) = 0; - virtual bool SubReadyToSerialize() = 0; - virtual int32_t SubDataSizeToSerialize() = 0; - virtual void SubDataSet() = 0; - virtual CALLER_ATTACH FontDataTable* - SubBuildTable(ReadableFontData* data) = 0; - - private: - void InternalSetData(WritableFontData* data, bool data_changed); - void InternalSetData(ReadableFontData* data, bool data_changed); - - FontDataTableBuilderContainer* container_; // avoid circular ref-counting - WritableFontDataPtr w_data_; - ReadableFontDataPtr r_data_; - bool model_changed_; - bool data_changed_; - }; - - explicit FontDataTable(ReadableFontData* data); - virtual ~FontDataTable(); - - // Get the readable font data for this table. - ReadableFontData* ReadFontData(); - - // Get the length of the data for this table in bytes. This is the full - // allocated length of the data and may or may not include any padding. - virtual int32_t Length(); - - // Get the number of bytes of padding used in the table. The padding bytes are - // used to align the table length to a 4 byte boundary. - virtual int32_t Padding(); - - // Return the number of bytes of non-padded data in the table. If the padding - // is unknown or unknowable then the total number of bytes of data in the - // tables is returned. - virtual int32_t DataLength(); - - virtual int32_t Serialize(OutputStream* os); - - protected: - // TODO(arthurhsu): style guide violation: protected member, need refactoring - ReadableFontDataPtr data_; -}; -typedef Ptr FontDataTablePtr; -typedef Ptr FontDataTableBuilderPtr; - -} // namespace sfntly - -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_DATA_TABLE_H_ diff --git a/sfntly/font_data_table_builder_container.h b/sfntly/font_data_table_builder_container.h index f3ccf61..2818464 100644 --- a/sfntly/font_data_table_builder_container.h +++ b/sfntly/font_data_table_builder_container.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_DATA_TABLE_BUILDER_CONTAINER_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_DATA_TABLE_BUILDER_CONTAINER_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_FONT_DATA_TABLE_BUILDER_CONTAINER_H_ +#define SFNTLY_CPP_SRC_SFNTLY_FONT_DATA_TABLE_BUILDER_CONTAINER_H_ #include "sfntly/data/writable_font_data.h" @@ -31,4 +31,4 @@ typedef Ptr FontDataTableBuilderContainerPtr; } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_DATA_TABLE_BUILDER_CONTAINER_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_FONT_DATA_TABLE_BUILDER_CONTAINER_H_ diff --git a/sfntly/font_factory.h b/sfntly/font_factory.h index 7be0841..b706b92 100644 --- a/sfntly/font_factory.h +++ b/sfntly/font_factory.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_FACTORY_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_FACTORY_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_FONT_FACTORY_H_ +#define SFNTLY_CPP_SRC_SFNTLY_FONT_FACTORY_H_ #include @@ -143,4 +143,4 @@ typedef Ptr FontFactoryPtr; } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_FACTORY_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_FONT_FACTORY_H_ diff --git a/sfntly/font_header_table.cc b/sfntly/font_header_table.cc deleted file mode 100644 index f896001..0000000 --- a/sfntly/font_header_table.cc +++ /dev/null @@ -1,259 +0,0 @@ -/* - * 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 "sfntly/font_header_table.h" - -namespace sfntly { -/****************************************************************************** - * FontHeaderTable class - ******************************************************************************/ -FontHeaderTable::~FontHeaderTable() {} - -int32_t FontHeaderTable::TableVersion() { - return data_->ReadFixed(Offset::kTableVersion); -} - -int32_t FontHeaderTable::FontRevision() { - return data_->ReadFixed(Offset::kFontRevision); -} - -int64_t FontHeaderTable::ChecksumAdjustment() { - return data_->ReadULong(Offset::kCheckSumAdjustment); -} - -int64_t FontHeaderTable::MagicNumber() { - return data_->ReadULong(Offset::kMagicNumber); -} - -int32_t FontHeaderTable::FlagsAsInt() { - return data_->ReadUShort(Offset::kFlags); -} - -int32_t FontHeaderTable::UnitsPerEm() { - return data_->ReadUShort(Offset::kUnitsPerEm); -} - -int64_t FontHeaderTable::Created() { - return data_->ReadDateTimeAsLong(Offset::kCreated); -} - -int64_t FontHeaderTable::Modified() { - return data_->ReadDateTimeAsLong(Offset::kModified); -} - -int32_t FontHeaderTable::XMin() { - return data_->ReadUShort(Offset::kXMin); -} - -int32_t FontHeaderTable::YMin() { - return data_->ReadUShort(Offset::kYMin); -} - -int32_t FontHeaderTable::XMax() { - return data_->ReadUShort(Offset::kXMax); -} - -int32_t FontHeaderTable::YMax() { - return data_->ReadUShort(Offset::kYMax); -} - -int32_t FontHeaderTable::MacStyleAsInt() { - return data_->ReadUShort(Offset::kMacStyle); -} - -int32_t FontHeaderTable::LowestRecPPEM() { - return data_->ReadUShort(Offset::kLowestRecPPEM); -} - -int32_t FontHeaderTable::FontDirectionHint() { - return data_->ReadShort(Offset::kFontDirectionHint); -} - -int32_t FontHeaderTable::IndexToLocFormat() { - return data_->ReadShort(Offset::kIndexToLocFormat); -} - -int32_t FontHeaderTable::GlyphDataFormat() { - return data_->ReadShort(Offset::kGlyphDataFormat); -} - -FontHeaderTable::FontHeaderTable(Header* header, ReadableFontData* data) - : Table(header, data) { - IntegerList checksum_ranges; - checksum_ranges.push_back(0); - checksum_ranges.push_back(Offset::kCheckSumAdjustment); - checksum_ranges.push_back(Offset::kMagicNumber); - data_->SetCheckSumRanges(checksum_ranges); -} - -/****************************************************************************** - * FontHeaderTable::Builder class - ******************************************************************************/ -FontHeaderTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, - Header* header, WritableFontData* data) : - Table::TableBasedTableBuilder(font_builder, header, data) { -} - -FontHeaderTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, - Header* header, ReadableFontData* data) : - Table::TableBasedTableBuilder(font_builder, header, data) { -} - -FontHeaderTable::Builder::~Builder() {} - -CALLER_ATTACH FontDataTable* FontHeaderTable::Builder::SubBuildTable( - ReadableFontData* data) { - FontDataTablePtr table = new FontHeaderTable(header(), data); - return table.Detach(); -} - -int32_t FontHeaderTable::Builder::TableVersion() { - return down_cast(GetTable())->TableVersion(); -} - -void FontHeaderTable::Builder::SetTableVersion(int32_t version) { - InternalWriteData()->WriteFixed(Offset::kTableVersion, version); -} - -int32_t FontHeaderTable::Builder::FontRevision() { - return down_cast(GetTable())->FontRevision(); -} - -void FontHeaderTable::Builder::SetFontRevision(int32_t revision) { - InternalWriteData()->WriteFixed(Offset::kFontRevision, revision); -} - -int64_t FontHeaderTable::Builder::ChecksumAdjustment() { - return down_cast(GetTable())->ChecksumAdjustment(); -} - -void FontHeaderTable::Builder::SetChecksumAdjustment(int64_t adjustment) { - InternalWriteData()->WriteULong(Offset::kCheckSumAdjustment, adjustment); -} - -int64_t FontHeaderTable::Builder::MagicNumber() { - return down_cast(GetTable())->MagicNumber(); -} - -void FontHeaderTable::Builder::SetMagicNumber(int64_t magic_number) { - InternalWriteData()->WriteULong(Offset::kMagicNumber, magic_number); -} - -int32_t FontHeaderTable::Builder::FlagsAsInt() { - return down_cast(GetTable())->FlagsAsInt(); -} - -void FontHeaderTable::Builder::SetFlagsAsInt(int32_t flags) { - InternalWriteData()->WriteUShort(Offset::kFlags, flags); -} - -int32_t FontHeaderTable::Builder::UnitsPerEm() { - return down_cast(GetTable())->UnitsPerEm(); -} - -void FontHeaderTable::Builder::SetUnitsPerEm(int32_t units) { - InternalWriteData()->WriteUShort(Offset::kUnitsPerEm, units); -} - -int64_t FontHeaderTable::Builder::Created() { - return down_cast(GetTable())->Created(); -} - -void FontHeaderTable::Builder::SetCreated(int64_t date) { - InternalWriteData()->WriteDateTime(Offset::kCreated, date); -} - -int64_t FontHeaderTable::Builder::Modified() { - return down_cast(GetTable())->Modified(); -} - -void FontHeaderTable::Builder::SetModified(int64_t date) { - InternalWriteData()->WriteDateTime(Offset::kModified, date); -} - -int32_t FontHeaderTable::Builder::XMin() { - return down_cast(GetTable())->XMin(); -} - -void FontHeaderTable::Builder::SetXMin(int32_t xmin) { - InternalWriteData()->WriteShort(Offset::kXMin, xmin); -} - -int32_t FontHeaderTable::Builder::YMin() { - return down_cast(GetTable())->YMin(); -} - -void FontHeaderTable::Builder::SetYMin(int32_t ymin) { - InternalWriteData()->WriteShort(Offset::kYMin, ymin); -} - -int32_t FontHeaderTable::Builder::XMax() { - return down_cast(GetTable())->XMax(); -} - -void FontHeaderTable::Builder::SetXMax(int32_t xmax) { - InternalWriteData()->WriteShort(Offset::kXMax, xmax); -} - -int32_t FontHeaderTable::Builder::YMax() { - return down_cast(GetTable())->YMax(); -} - -void FontHeaderTable::Builder::SetYMax(int32_t ymax) { - InternalWriteData()->WriteShort(Offset::kYMax, ymax); -} - -int32_t FontHeaderTable::Builder::MacStyleAsInt() { - return down_cast(GetTable())->MacStyleAsInt(); -} - -void FontHeaderTable::Builder::SetMacStyleAsInt(int32_t style) { - InternalWriteData()->WriteUShort(Offset::kMacStyle, style); -} - -int32_t FontHeaderTable::Builder::LowestRecPPEM() { - return down_cast(GetTable())->LowestRecPPEM(); -} - -void FontHeaderTable::Builder::SetLowestRecPPEM(int32_t size) { - InternalWriteData()->WriteUShort(Offset::kLowestRecPPEM, size); -} - -int32_t FontHeaderTable::Builder::FontDirectionHint() { - return down_cast(GetTable())->FontDirectionHint(); -} - -void FontHeaderTable::Builder::SetFontDirectionHint(int32_t hint) { - InternalWriteData()->WriteShort(Offset::kFontDirectionHint, hint); -} - -int32_t FontHeaderTable::Builder::IndexToLocFormat() { - return down_cast(GetTable())->IndexToLocFormat(); -} - -void FontHeaderTable::Builder::SetIndexToLocFormat(int32_t format) { - InternalWriteData()->WriteShort(Offset::kIndexToLocFormat, format); -} - -int32_t FontHeaderTable::Builder::GlyphDataFormat() { - return down_cast(GetTable())->GlyphDataFormat(); -} - -void FontHeaderTable::Builder::SetGlyphDataFormat(int32_t format) { - InternalWriteData()->WriteShort(Offset::kGlyphDataFormat, format); -} - -} // namespace sfntly diff --git a/sfntly/font_header_table.h b/sfntly/font_header_table.h deleted file mode 100644 index dd6f593..0000000 --- a/sfntly/font_header_table.h +++ /dev/null @@ -1,167 +0,0 @@ -/* - * 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. - */ - -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_HEADER_TABLE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_HEADER_TABLE_H_ - -#include "sfntly/table.h" - -namespace sfntly { - -struct IndexToLocFormat { - enum { - kShortOffset = 0, - kLongOffset = 1 - }; -}; - -struct FontDirectionHint { - enum { - kFullyMixed = 0, - kOnlyStrongLTR = 1, - kStrongLTRAndNeutral = 2, - kOnlyStrongRTL = -1, - kStrongRTLAndNeutral = -2 - }; -}; - -class FontHeaderTable : public Table, public RefCounted { - public: - class Builder : public Table::TableBasedTableBuilder, - public RefCounted { - public: - // Constructor scope altered to public because C++ does not allow base - // class to instantiate derived class with protected constructors. - Builder(FontDataTableBuilderContainer* font_builder, Header* header, - WritableFontData* data); - Builder(FontDataTableBuilderContainer* font_builder, Header* header, - ReadableFontData* data); - virtual ~Builder(); - virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); - - virtual int32_t TableVersion(); - virtual void SetTableVersion(int32_t version); - virtual int32_t FontRevision(); - virtual void SetFontRevision(int32_t revision); - virtual int64_t ChecksumAdjustment(); - virtual void SetChecksumAdjustment(int64_t adjustment); - virtual int64_t MagicNumber(); - virtual void SetMagicNumber(int64_t magic_number); - virtual int32_t FlagsAsInt(); - virtual void SetFlagsAsInt(int32_t flags); - // TODO(arthurhsu): IMPLEMENT EnumSet Flags() - // TODO(arthurhsu): IMPLEMENT setFlags(EnumSet flags) - virtual int32_t UnitsPerEm(); - virtual void SetUnitsPerEm(int32_t units); - virtual int64_t Created(); - virtual void SetCreated(int64_t date); - virtual int64_t Modified(); - virtual void SetModified(int64_t date); - virtual int32_t XMin(); - virtual void SetXMin(int32_t xmin); - virtual int32_t YMin(); - virtual void SetYMin(int32_t ymin); - virtual int32_t XMax(); - virtual void SetXMax(int32_t xmax); - virtual int32_t YMax(); - virtual void SetYMax(int32_t ymax); - virtual int32_t MacStyleAsInt(); - virtual void SetMacStyleAsInt(int32_t style); - // TODO(arthurhsu): IMPLEMENT EnumSet macStyle() - // TODO(arthurhsu): IMPLEMENT setMacStyle(EnumSet style) - virtual int32_t LowestRecPPEM(); - virtual void SetLowestRecPPEM(int32_t size); - virtual int32_t FontDirectionHint(); - virtual void SetFontDirectionHint(int32_t hint); - virtual int32_t IndexToLocFormat(); - virtual void SetIndexToLocFormat(int32_t format); - virtual int32_t GlyphDataFormat(); - virtual void SetGlyphDataFormat(int32_t format); - }; - - virtual ~FontHeaderTable(); - int32_t TableVersion(); - int32_t FontRevision(); - - // Get the checksum adjustment. To compute: set it to 0, sum the entire font - // as ULONG, then store 0xB1B0AFBA - sum. - int64_t ChecksumAdjustment(); - - // Get the magic number. Set to 0x5F0F3CF5. - int64_t MagicNumber(); - - // TODO(arthurhsu): IMPLEMENT: EnumSet - int32_t FlagsAsInt(); - // TODO(arthurhsu): IMPLEMENT: Flags() returning EnumSet - - int32_t UnitsPerEm(); - - // Get the created date. Number of seconds since 12:00 midnight, January 1, - // 1904. 64-bit integer. - int64_t Created(); - // Get the modified date. Number of seconds since 12:00 midnight, January 1, - // 1904. 64-bit integer. - int64_t Modified(); - - // Get the x min. For all glyph bounding boxes. - int32_t XMin(); - // Get the y min. For all glyph bounding boxes. - int32_t YMin(); - // Get the x max. For all glyph bounding boxes. - int32_t XMax(); - // Get the y max. For all glyph bounding boxes. - int32_t YMax(); - - // TODO(arthurhsu): IMPLEMENT: EnumSet - int32_t MacStyleAsInt(); - // TODO(arthurhsu): IMPLEMENT: macStyle() returning EnumSet - - int32_t LowestRecPPEM(); - int32_t FontDirectionHint(); // Note: no AsInt() form, already int - int32_t IndexToLocFormat(); // Note: no AsInt() form, already int - int32_t GlyphDataFormat(); - - private: - struct Offset { - enum { - kTableVersion = 0, - kFontRevision = 4, - kCheckSumAdjustment = 8, - kMagicNumber = 12, - kFlags = 16, - kUnitsPerEm = 18, - kCreated = 20, - kModified = 28, - kXMin = 36, - kYMin = 38, - kXMax = 40, - kYMax = 42, - kMacStyle = 44, - kLowestRecPPEM = 46, - kFontDirectionHint = 48, - kIndexToLocFormat = 50, - kGlyphDataFormat = 52 - }; - }; - - FontHeaderTable(Header* header, ReadableFontData* data); -}; -typedef Ptr FontHeaderTablePtr; -typedef Ptr FontHeaderTableBuilderPtr; - -} // namespace sfntly - -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_FONT_HEADER_TABLE_H_ diff --git a/sfntly/glyph_table.cc b/sfntly/glyph_table.cc deleted file mode 100644 index ac85ab2..0000000 --- a/sfntly/glyph_table.cc +++ /dev/null @@ -1,667 +0,0 @@ -/* - * 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 "sfntly/glyph_table.h" - -#include - -#include "sfntly/port/exception_type.h" - -namespace sfntly { -/****************************************************************************** - * Constants - ******************************************************************************/ -const int32_t GlyphTable::SimpleGlyph::kFLAG_ONCURVE = 1; -const int32_t GlyphTable::SimpleGlyph::kFLAG_XSHORT = 1 << 1; -const int32_t GlyphTable::SimpleGlyph::kFLAG_YSHORT = 1 << 2; -const int32_t GlyphTable::SimpleGlyph::kFLAG_REPEAT = 1 << 3; -const int32_t GlyphTable::SimpleGlyph::kFLAG_XREPEATSIGN = 1 << 4; -const int32_t GlyphTable::SimpleGlyph::kFLAG_YREPEATSIGN = 1 << 5; - -const int32_t GlyphTable::CompositeGlyph::kFLAG_ARG_1_AND_2_ARE_WORDS = 1 << 0; -const int32_t GlyphTable::CompositeGlyph::kFLAG_ARGS_ARE_XY_VALUES = 1 << 1; -const int32_t GlyphTable::CompositeGlyph::kFLAG_ROUND_XY_TO_GRID = 1 << 2; -const int32_t GlyphTable::CompositeGlyph::kFLAG_WE_HAVE_A_SCALE = 1 << 3; -const int32_t GlyphTable::CompositeGlyph::kFLAG_RESERVED = 1 << 4; -const int32_t GlyphTable::CompositeGlyph::kFLAG_MORE_COMPONENTS = 1 << 5; -const int32_t GlyphTable::CompositeGlyph::kFLAG_WE_HAVE_AN_X_AND_Y_SCALE = 1 << 6; -const int32_t GlyphTable::CompositeGlyph::kFLAG_WE_HAVE_A_TWO_BY_TWO = 1 << 7; -const int32_t GlyphTable::CompositeGlyph::kFLAG_WE_HAVE_INSTRUCTIONS = 1 << 8; -const int32_t GlyphTable::CompositeGlyph::kFLAG_USE_MY_METRICS = 1 << 9; -const int32_t GlyphTable::CompositeGlyph::kFLAG_OVERLAP_COMPOUND = 1 << 10; -const int32_t GlyphTable::CompositeGlyph::kFLAG_SCALED_COMPONENT_OFFSET = 1 << 11; -const int32_t GlyphTable::CompositeGlyph::kFLAG_UNSCALED_COMPONENT_OFFSET = 1 << 12; - -/****************************************************************************** - * GlyphTable class - ******************************************************************************/ -GlyphTable::~GlyphTable() { -} - -GlyphTable::Glyph* GlyphTable::GetGlyph(int32_t offset, int32_t length) { - return GlyphTable::Glyph::GetGlyph(data_, offset, length); -} - -GlyphTable::GlyphTable(Header* header, ReadableFontData* data) - : Table(header, data) { -} - -/****************************************************************************** - * GlyphTable::Builder class - ******************************************************************************/ -GlyphTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data) - : Table::ArrayElementTableBuilder(font_builder, header, data) { -} - -GlyphTable::Builder::~Builder() { -} - -void GlyphTable::Builder::SetLoca(const IntegerList& loca) { - loca_ = loca; - set_model_changed(false); - glyph_builders_.clear(); -} - -void GlyphTable::Builder::GenerateLocaList(IntegerList* locas) { - assert(locas); - GlyphBuilderList* glyph_builders = GetGlyphBuilders(); - locas->resize(glyph_builders->size()); - locas->push_back(0); - if (glyph_builders->size() == 0) { - locas->push_back(0); - } else { - int32_t total = 0; - for (GlyphBuilderList::iterator b = glyph_builders->begin(), - b_end = glyph_builders->end(); - b != b_end; ++b) { - int32_t size = (*b)->SubDataSizeToSerialize(); - locas->push_back(total + size); - total += size; - } - } -} - -GlyphTable::GlyphBuilderList* GlyphTable::Builder::GlyphBuilders() { - return GetGlyphBuilders(); -} - -void GlyphTable::Builder::SetGlyphBuilders(GlyphBuilderList* glyph_builders) { - glyph_builders_ = *glyph_builders; - set_model_changed(); -} - -CALLER_ATTACH GlyphTable::Glyph::Builder* - GlyphTable::Builder::GlyphBuilder(ReadableFontData* data) { - return Glyph::Builder::GetBuilder(this, data); -} - -CALLER_ATTACH FontDataTable* - GlyphTable::Builder::SubBuildTable(ReadableFontData* data) { - FontDataTablePtr table = new GlyphTable(header(), data); - return table.Detach(); -} - -void GlyphTable::Builder::SubDataSet() { - glyph_builders_.clear(); - set_model_changed(false); -} - -int32_t GlyphTable::Builder::SubDataSizeToSerialize() { - if (glyph_builders_.empty()) - return 0; - - bool variable = false; - int32_t size = 0; - - // Calculate size of each table. - for (GlyphBuilderList::iterator b = glyph_builders_.begin(), - end = glyph_builders_.end(); b != end; ++b) { - int32_t glyph_size = (*b)->SubDataSizeToSerialize(); - size += abs(glyph_size); - variable |= glyph_size <= 0; - } - return variable ? -size : size; -} - -bool GlyphTable::Builder::SubReadyToSerialize() { - return !glyph_builders_.empty(); -} - -int32_t GlyphTable::Builder::SubSerialize(WritableFontData* new_data) { - int32_t size = 0; - for (GlyphBuilderList::iterator b = glyph_builders_.begin(), - end = glyph_builders_.end(); b != end; ++b) { - FontDataPtr data; - data.Attach(new_data->Slice(size)); - size += (*b)->SubSerialize(down_cast(data.p_)); - } - return size; -} - -void GlyphTable::Builder::Initialize(ReadableFontData* data, - const IntegerList& loca) { - if (data != NULL) { - if (loca_.empty()) { -#if defined (SFNTLY_NO_EXCEPTION) - return; -#else - throw IllegalStateException( - "Loca values not set - unable to parse glyph data."); -#endif - } - int32_t loca_value; - int32_t last_loca_value = loca[0]; - for (size_t i = 1; i < loca.size(); ++i) { - loca_value = loca[i]; - GlyphBuilderPtr builder; - builder.Attach( - Glyph::Builder::GetBuilder(this, - data, - last_loca_value /*offset*/, - loca_value - last_loca_value /*length*/)); - glyph_builders_.push_back(builder); - last_loca_value = loca_value; - } - } -} - -GlyphTable::GlyphBuilderList* GlyphTable::Builder::GetGlyphBuilders() { - if (glyph_builders_.empty()) { - Initialize(InternalReadData(), loca_); - set_model_changed(); - } - return &glyph_builders_; -} - -void GlyphTable::Builder::Revert() { - glyph_builders_.clear(); - set_model_changed(false); -} - -/****************************************************************************** - * GlyphTable::Glyph class - ******************************************************************************/ -GlyphTable::Glyph::~Glyph() {} - -CALLER_ATTACH GlyphTable::Glyph* - GlyphTable::Glyph::GetGlyph(ReadableFontData* data, - int32_t offset, - int32_t length) { - int32_t type = GlyphType(data, offset, length); - GlyphPtr glyph; - - ReadableFontDataPtr sliced_data; - sliced_data.Attach(down_cast(data->Slice(offset, length))); - if (type == GlyphType::kSimple) { - glyph = new SimpleGlyph(sliced_data); - } else { - glyph = new CompositeGlyph(sliced_data); - } - return glyph.Detach(); -} - -int32_t GlyphTable::Glyph::GlyphType() { - return glyph_type_; -} - -int32_t GlyphTable::Glyph::NumberOfContours() { - return number_of_contours_; -} - -int32_t GlyphTable::Glyph::XMin() { - return data_->ReadShort(Offset::kXMin); -} - -int32_t GlyphTable::Glyph::XMax() { - return data_->ReadShort(Offset::kXMax); -} - -int32_t GlyphTable::Glyph::YMin() { - return data_->ReadShort(Offset::kYMin); -} - -int32_t GlyphTable::Glyph::YMax() { - return data_->ReadShort(Offset::kYMax); -} - -int32_t GlyphTable::Glyph::Padding() { - return padding_; -} - -GlyphTable::Glyph::Glyph(ReadableFontData* data, int32_t glyph_type) - : SubTable(data), - glyph_type_(glyph_type) { - if (data_->Length() == 0) { - number_of_contours_ = 0; - } else { - // -1 if composite - number_of_contours_ = data_->ReadShort(Offset::kNumberOfContours); - } -} - -int32_t GlyphTable::Glyph::GlyphType(ReadableFontData* data, - int32_t offset, - int32_t length) { - if (length == 0) { - return GlyphType::kSimple; - } - int32_t number_of_contours = data->ReadShort(offset); - if (number_of_contours >= 0) { - return GlyphType::kSimple; - } - return GlyphType::kComposite; -} - -/****************************************************************************** - * GlyphTable::Glyph::Builder class - ******************************************************************************/ -GlyphTable::Glyph::Builder::~Builder() { -} - -GlyphTable::Glyph::Builder::Builder(FontDataTableBuilderContainer* font_builder, - WritableFontData* data) - : SubTable::Builder(font_builder, data) { -} - -GlyphTable::Glyph::Builder::Builder(FontDataTableBuilderContainer* font_builder, - ReadableFontData* data) - : SubTable::Builder(font_builder, data) { -} - -CALLER_ATTACH GlyphTable::Glyph::Builder* - GlyphTable::Glyph::Builder::GetBuilder( - FontDataTableBuilderContainer* table_builder, - ReadableFontData* data) { - return GetBuilder(table_builder, data, 0, data->Length()); -} - -CALLER_ATTACH GlyphTable::Glyph::Builder* - GlyphTable::Glyph::Builder::GetBuilder( - FontDataTableBuilderContainer* table_builder, - ReadableFontData* data, - int32_t offset, - int32_t length) { - int32_t type = Glyph::GlyphType(data, offset, length); - GlyphBuilderPtr builder; - ReadableFontDataPtr sliced_data; - sliced_data.Attach(down_cast(data->Slice(offset, length))); - if (type == GlyphType::kSimple) { - builder = new SimpleGlyph::SimpleGlyphBuilder(table_builder, sliced_data); - } else { - builder = new CompositeGlyph::CompositeGlyphBuilder(table_builder, - sliced_data); - } - return builder.Detach(); -} - -void GlyphTable::Glyph::Builder::SubDataSet() { - // NOP -} - -int32_t GlyphTable::Glyph::Builder::SubDataSizeToSerialize() { - return InternalReadData()->Length(); -} - -bool GlyphTable::Glyph::Builder::SubReadyToSerialize() { - return true; -} - -int32_t GlyphTable::Glyph::Builder::SubSerialize(WritableFontData* new_data) { - return InternalReadData()->CopyTo(new_data); -} - -/****************************************************************************** - * GlyphTable::SimpleGlyph - ******************************************************************************/ -GlyphTable::SimpleGlyph::SimpleGlyph(ReadableFontData* data) - : GlyphTable::Glyph(data, GlyphType::kSimple) { -} - -GlyphTable::SimpleGlyph::~SimpleGlyph() { -} - -int32_t GlyphTable::SimpleGlyph::InstructionSize() { - Initialize(); - return instruction_size_; -} - -CALLER_ATTACH ReadableFontData* GlyphTable::SimpleGlyph::Instructions() { - Initialize(); - return down_cast( - data_->Slice(instructions_offset_, InstructionSize())); -} - -int32_t GlyphTable::SimpleGlyph::NumberOfPoints(int32_t contour) { - Initialize(); - if (contour >= NumberOfContours()) { - return 0; - } - return contour_index_[contour + 1] - contour_index_[contour]; -} - -int32_t GlyphTable::SimpleGlyph::XCoordinate(int32_t contour, int32_t point) { - Initialize(); - return x_coordinates_[contour_index_[contour] + point]; -} - -int32_t GlyphTable::SimpleGlyph::YCoordinate(int32_t contour, int32_t point) { - Initialize(); - return y_coordinates_[contour_index_[contour] + point]; -} - -bool GlyphTable::SimpleGlyph::OnCurve(int32_t contour, int32_t point) { - Initialize(); - return on_curve_[contour_index_[contour] + point]; -} - -void GlyphTable::SimpleGlyph::Initialize() { - if (initialized_) { - return; - } - - if (ReadFontData()->Length() == 0) { - instruction_size_ = 0; - number_of_points_ = 0; - instructions_offset_ = 0; - flags_offset_ = 0; - x_coordinates_offset_ = 0; - y_coordinates_offset_ = 0; - return; - } - - instruction_size_ = data_->ReadUShort(Offset::kSimpleEndPtsOfCountours + - NumberOfContours() * DataSize::kUSHORT); - instructions_offset_ = Offset::kSimpleEndPtsOfCountours + - (NumberOfContours() + 1) * DataSize::kUSHORT; - flags_offset_ = instructions_offset_ + instruction_size_ * DataSize::kBYTE; - number_of_points_ = ContourEndPoint(NumberOfContours() - 1) + 1; - x_coordinates_.resize(number_of_points_); - y_coordinates_.resize(number_of_points_); - on_curve_.resize(number_of_points_); - ParseData(false); - x_coordinates_offset_ = flags_offset_ + flag_byte_count_ * DataSize::kBYTE; - y_coordinates_offset_ = x_coordinates_offset_ + x_byte_count_ * - DataSize::kBYTE; - contour_index_.resize(NumberOfContours() + 1); - contour_index_[0] = 0; - for (uint32_t contour = 0; contour < contour_index_.size() - 1; ++contour) { - contour_index_[contour + 1] = ContourEndPoint(contour) + 1; - } - ParseData(true); - int32_t non_padded_data_length = - 5 * DataSize::kSHORT + - (NumberOfContours() * DataSize::kUSHORT) + - DataSize::kUSHORT + - (instruction_size_ * DataSize::kBYTE) + - (flag_byte_count_ * DataSize::kBYTE) + - (x_byte_count_ * DataSize::kBYTE) + - (y_byte_count_ * DataSize::kBYTE); - padding_ = Length() - non_padded_data_length; - initialized_ = true; -} - -void GlyphTable::SimpleGlyph::ParseData(bool fill_arrays) { - int32_t flag = 0; - int32_t flag_repeat = 0; - int32_t flag_index = 0; - int32_t x_byte_index = 0; - int32_t y_byte_index = 0; - - for (int32_t point_index = 0; point_index < number_of_points_; - ++point_index) { - // get the flag for the current point - if (flag_repeat == 0) { - flag = FlagAsInt(flag_index++); - if ((flag & kFLAG_REPEAT) == kFLAG_REPEAT) { - flag_repeat = FlagAsInt(flag_index++); - } - } else { - flag_repeat--; - } - - // on the curve? - if (fill_arrays) { - on_curve_[point_index] = ((flag & kFLAG_ONCURVE) == kFLAG_ONCURVE); - } - // get the x coordinate - if ((flag & kFLAG_XSHORT) == kFLAG_XSHORT) { - // single byte x coord value - if (fill_arrays) { - x_coordinates_[point_index] = - data_->ReadUByte(x_coordinates_offset_ + x_byte_index); - x_coordinates_[point_index] *= - ((flag & kFLAG_XREPEATSIGN) == kFLAG_XREPEATSIGN) ? 1 : -1; - } - x_byte_index++; - } else { - // double byte coord value - if (!((flag & kFLAG_XREPEATSIGN) == kFLAG_XREPEATSIGN)) { - if (fill_arrays) { - x_coordinates_[point_index] = - data_->ReadShort(x_coordinates_offset_ + x_byte_index); - } - x_byte_index += 2; - } - } - if (fill_arrays && point_index > 0) { - x_coordinates_[point_index] += x_coordinates_[point_index - 1]; - } - - // get the y coordinate - if ((flag & kFLAG_YSHORT) == kFLAG_YSHORT) { - if (fill_arrays) { - y_coordinates_[point_index] = - data_->ReadUByte(y_coordinates_offset_ + y_byte_index); - y_coordinates_[point_index] *= - ((flag & kFLAG_YREPEATSIGN) == kFLAG_YREPEATSIGN) ? 1 : -1; - } - y_byte_index++; - } else { - if (!((flag & kFLAG_YREPEATSIGN) == kFLAG_YREPEATSIGN)) { - if (fill_arrays) { - y_coordinates_[point_index] = - data_->ReadShort(y_coordinates_offset_ + y_byte_index); - } - y_byte_index += 2; - } - } - if (fill_arrays && point_index > 0) { - y_coordinates_[point_index] += y_coordinates_[point_index - 1]; - } - } - flag_byte_count_ = flag_index; - x_byte_count_ = x_byte_index; - y_byte_count_ = y_byte_index; -} - -int32_t GlyphTable::SimpleGlyph::FlagAsInt(int32_t index) { - return data_->ReadUByte(flags_offset_ + index * DataSize::kBYTE); -} - -int32_t GlyphTable::SimpleGlyph::ContourEndPoint(int32_t contour) { - return data_->ReadUShort(contour * DataSize::kUSHORT + - Offset::kSimpleEndPtsOfCountours); -} - -/****************************************************************************** - * GlyphTable::SimpleGlyph::Builder - ******************************************************************************/ -GlyphTable::SimpleGlyph::SimpleGlyphBuilder::~SimpleGlyphBuilder() { -} - -GlyphTable::SimpleGlyph::SimpleGlyphBuilder::SimpleGlyphBuilder( - FontDataTableBuilderContainer* table_builder, - WritableFontData* data) - : Glyph::Builder(table_builder, data) { -} - -GlyphTable::SimpleGlyph::SimpleGlyphBuilder::SimpleGlyphBuilder( - FontDataTableBuilderContainer* table_builder, - ReadableFontData* data) - : Glyph::Builder(table_builder, data) { -} - -CALLER_ATTACH FontDataTable* - GlyphTable::SimpleGlyph::SimpleGlyphBuilder::SubBuildTable( - ReadableFontData* data) { - FontDataTablePtr table = new SimpleGlyph(data); - return table.Detach(); -} - -/****************************************************************************** - * GlyphTable::CompositeGlyph - ******************************************************************************/ -GlyphTable::CompositeGlyph::CompositeGlyph(ReadableFontData* data) - : GlyphTable::Glyph(data, GlyphType::kComposite), - instruction_size_(0), - instructions_offset_(0) { - ParseData(); -} - -GlyphTable::CompositeGlyph::~CompositeGlyph() { -} - -int32_t GlyphTable::CompositeGlyph::Flags(int32_t contour) { - return data_->ReadUShort(contour_index_[contour]); -} - -int32_t GlyphTable::CompositeGlyph::NumGlyphs() { - return contour_index_.size(); -} - -int32_t GlyphTable::CompositeGlyph::GlyphIndex(int32_t contour) { - return data_->ReadUShort(DataSize::kUSHORT + contour_index_[contour]); -} - -int32_t GlyphTable::CompositeGlyph::Argument1(int32_t contour) { - int32_t index = 2 * DataSize::kUSHORT + contour_index_[contour]; - int32_t contour_flags = Flags(contour); - if ((contour_flags & kFLAG_ARG_1_AND_2_ARE_WORDS) == - kFLAG_ARG_1_AND_2_ARE_WORDS) { - return data_->ReadUShort(index); - } - return data_->ReadByte(index); -} - -int32_t GlyphTable::CompositeGlyph::Argument2(int32_t contour) { - int32_t index = 2 * DataSize::kUSHORT + contour_index_[contour]; - int32_t contour_flags = Flags(contour); - if ((contour_flags & kFLAG_ARG_1_AND_2_ARE_WORDS) == - kFLAG_ARG_1_AND_2_ARE_WORDS) { - return data_->ReadUShort(index + DataSize::kUSHORT); - } - return data_->ReadByte(index + DataSize::kUSHORT); -} - -int32_t GlyphTable::CompositeGlyph::TransformationSize(int32_t contour) { - int32_t contour_flags = Flags(contour); - if ((contour_flags & kFLAG_WE_HAVE_A_SCALE) == kFLAG_WE_HAVE_A_SCALE) { - return DataSize::kF2DOT14; - } else if ((contour_flags & kFLAG_WE_HAVE_AN_X_AND_Y_SCALE) == - kFLAG_WE_HAVE_AN_X_AND_Y_SCALE) { - return 2 * DataSize::kF2DOT14; - } else if ((contour_flags & kFLAG_WE_HAVE_A_TWO_BY_TWO) == - kFLAG_WE_HAVE_A_TWO_BY_TWO) { - return 4 * DataSize::kF2DOT14; - } - return 0; -} - -void GlyphTable::CompositeGlyph::Transformation(int32_t contour, - ByteVector* transformation) { - int32_t contour_flags = Flags(contour); - int32_t index = contour_index_[contour] + 2 * DataSize::kUSHORT; - if ((contour_flags & kFLAG_ARG_1_AND_2_ARE_WORDS) == - kFLAG_ARG_1_AND_2_ARE_WORDS) { - index += 2 * DataSize::kSHORT; - } else { - index += 2 * DataSize::kBYTE; - } - int32_t tsize = TransformationSize(contour); - transformation->resize(tsize); - data_->ReadBytes(index, &((*transformation)[0]), 0, tsize); -} - -int32_t GlyphTable::CompositeGlyph::InstructionSize() { - return instruction_size_; -} - -CALLER_ATTACH ReadableFontData* GlyphTable::CompositeGlyph::Instructions() { - return down_cast( - data_->Slice(instructions_offset_, InstructionSize())); -} - -void GlyphTable::CompositeGlyph::ParseData() { - int32_t index = 5 * DataSize::kUSHORT; - int32_t flags = kFLAG_MORE_COMPONENTS; - - while ((flags & kFLAG_MORE_COMPONENTS) == kFLAG_MORE_COMPONENTS) { - contour_index_.push_back(index); - flags = data_->ReadUShort(index); - index += 2 * DataSize::kUSHORT; // flags and glyphIndex - if ((flags & kFLAG_ARG_1_AND_2_ARE_WORDS) == kFLAG_ARG_1_AND_2_ARE_WORDS) { - index += 2 * DataSize::kSHORT; - } else { - index += 2 * DataSize::kBYTE; - } - if ((flags & kFLAG_WE_HAVE_A_SCALE) == kFLAG_WE_HAVE_A_SCALE) { - index += DataSize::kF2DOT14; - } else if ((flags & kFLAG_WE_HAVE_AN_X_AND_Y_SCALE) == - kFLAG_WE_HAVE_AN_X_AND_Y_SCALE) { - index += 2 * DataSize::kF2DOT14; - } else if ((flags & kFLAG_WE_HAVE_A_TWO_BY_TWO) == - kFLAG_WE_HAVE_A_TWO_BY_TWO) { - index += 4 * DataSize::kF2DOT14; - } - int32_t non_padded_data_length = index; - if ((flags & kFLAG_WE_HAVE_INSTRUCTIONS) == kFLAG_WE_HAVE_INSTRUCTIONS) { - instruction_size_ = data_->ReadUShort(index); - index += DataSize::kUSHORT; - instructions_offset_ = index; - non_padded_data_length = index + (instruction_size_ * DataSize::kBYTE); - } - padding_ = Length() - non_padded_data_length; - } -} - -/****************************************************************************** - * GlyphTable::CompositeGlyph::Builder - ******************************************************************************/ -GlyphTable::CompositeGlyph::CompositeGlyphBuilder::~CompositeGlyphBuilder() { -} - -GlyphTable::CompositeGlyph::CompositeGlyphBuilder::CompositeGlyphBuilder( - FontDataTableBuilderContainer* table_builder, - WritableFontData* data) - : Glyph::Builder(table_builder, data) { -} - -GlyphTable::CompositeGlyph::CompositeGlyphBuilder::CompositeGlyphBuilder( - FontDataTableBuilderContainer* table_builder, - ReadableFontData* data) - : Glyph::Builder(table_builder, data) { -} - -CALLER_ATTACH FontDataTable* - GlyphTable::CompositeGlyph::CompositeGlyphBuilder::SubBuildTable( - ReadableFontData* data) { - FontDataTablePtr table = new CompositeGlyph(data); - return table.Detach(); -} - -} // namespace sfntly diff --git a/sfntly/glyph_table.h b/sfntly/glyph_table.h deleted file mode 100644 index c066d47..0000000 --- a/sfntly/glyph_table.h +++ /dev/null @@ -1,330 +0,0 @@ -/* - * 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. - */ - -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_GLYPH_TABLE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_GLYPH_TABLE_H_ - -#include - -#include "sfntly/table.h" -#include "sfntly/subtable.h" - -namespace sfntly { - -struct GlyphType { - enum { - kSimple = 0, - kComposite = 1 - }; -}; - -// Note: due to the complexity of this class, the order of declaration is -// different from its Java counter part. GlyphTable::Glyph is defined -// before GlyphTable::Builder to avoid compilation errors. -class GlyphTable : public Table, public RefCounted { - public: - class Builder; - class Glyph : public SubTable { - public: - // Note: Contour is an empty class for the version ported - class Contour { - protected: - Contour() {} - virtual ~Contour() {} - }; - - class Builder : public SubTable::Builder { - public: - virtual ~Builder(); - - protected: - // Incoming table_builder is GlyphTable::Builder*. - // Note: constructor refactored in C++ to avoid heavy lifting. - // caller need to do data->Slice(offset, length) beforehand. - Builder(FontDataTableBuilderContainer* table_builder, - WritableFontData* data); - Builder(FontDataTableBuilderContainer* table_builder, - ReadableFontData* data); - - static CALLER_ATTACH Builder* - GetBuilder(FontDataTableBuilderContainer* table_builder, - ReadableFontData* data); - static CALLER_ATTACH Builder* - GetBuilder(FontDataTableBuilderContainer* table_builder, - ReadableFontData* data, - int32_t offset, - int32_t length); - virtual void SubDataSet(); - virtual int32_t SubDataSizeToSerialize(); - virtual bool SubReadyToSerialize(); - virtual int32_t SubSerialize(WritableFontData* new_data); - - private: - int32_t format_; - friend class GlyphTable::Builder; - }; - - virtual ~Glyph(); - static CALLER_ATTACH Glyph* GetGlyph(ReadableFontData* data, - int32_t offset, - int32_t length); - virtual int32_t GlyphType(); - virtual int32_t NumberOfContours(); - virtual int32_t XMin(); - virtual int32_t XMax(); - virtual int32_t YMin(); - virtual int32_t YMax(); - virtual int32_t Padding(); // override FontDataTable::Padding() - - virtual int32_t InstructionSize() = 0; - virtual ReadableFontData* Instructions() = 0; - - protected: - // Note: constructor refactored in C++ to avoid heavy lifting. - // caller need to do data->Slice(offset, length) beforehand. - Glyph(ReadableFontData* data, int32_t glyph_type); - - // TODO(arthurhsu): violating C++ style guide, need refactoring. - int32_t padding_; - - private: - static int32_t GlyphType(ReadableFontData* data, - int32_t offset, - int32_t length); - - int32_t glyph_type_; - int32_t number_of_contours_; - }; // class GlyphTable::Glyph - typedef Ptr GlyphBuilderPtr; - typedef std::vector GlyphBuilderList; - - class Builder : public Table::ArrayElementTableBuilder, - public RefCounted { - public: - // Note: Constructor scope altered to public for base class to instantiate. - Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data); - virtual ~Builder(); - - virtual void SetLoca(const IntegerList& loca); - virtual void GenerateLocaList(IntegerList* locas); - - // Gets the List of glyph builders for the glyph table builder. These may be - // manipulated in any way by the caller and the changes will be reflected in - // the final glyph table produced. - // If there is no current data for the glyph builder or the glyph builders - // have not been previously set then this will return an empty glyph builder - // List. If there is current data (i.e. data read from an existing font) and - // the loca list has not been set or is null, empty, or - // invalid, then an empty glyph builder List will be returned. - GlyphBuilderList* GlyphBuilders(); - - // Replace the internal glyph builders with the one provided. - void SetGlyphBuilders(GlyphBuilderList* glyph_builders); - - // Glyph builder factories - CALLER_ATTACH Glyph::Builder* GlyphBuilder(ReadableFontData* data); - - protected: // internal API for building - virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); - virtual void SubDataSet(); - virtual int32_t SubDataSizeToSerialize(); - virtual bool SubReadyToSerialize(); - virtual int32_t SubSerialize(WritableFontData* new_data); - - private: - void Initialize(ReadableFontData* data, const IntegerList& loca); - GlyphBuilderList* GetGlyphBuilders(); - void Revert(); - - GlyphBuilderList glyph_builders_; - IntegerList loca_; - }; - - class SimpleGlyph : public Glyph, public RefCounted { - public: - static const int32_t kFLAG_ONCURVE; - static const int32_t kFLAG_XSHORT; - static const int32_t kFLAG_YSHORT; - static const int32_t kFLAG_REPEAT; - static const int32_t kFLAG_XREPEATSIGN; - static const int32_t kFLAG_YREPEATSIGN; - - class SimpleContour : public Glyph::Contour { - protected: - SimpleContour() {} - virtual ~SimpleContour() {} - }; - - class SimpleGlyphBuilder : public Glyph::Builder, - public RefCounted { - public: - virtual ~SimpleGlyphBuilder(); - - protected: - // Note: constructor refactored in C++ to avoid heavy lifting. - // caller need to do data->Slice(offset, length) beforehand. - SimpleGlyphBuilder(FontDataTableBuilderContainer* table_builder, - WritableFontData* data); - SimpleGlyphBuilder(FontDataTableBuilderContainer* table_builder, - ReadableFontData* data); - virtual CALLER_ATTACH FontDataTable* - SubBuildTable(ReadableFontData* data); - - private: - friend class Glyph::Builder; - }; - - // Note: constructor refactored in C++ to avoid heavy lifting. - // caller need to do data->Slice(offset, length) beforehand. - explicit SimpleGlyph(ReadableFontData* data); - virtual ~SimpleGlyph(); - - virtual int32_t InstructionSize(); - virtual CALLER_ATTACH ReadableFontData* Instructions(); - int32_t NumberOfPoints(int32_t contour); - int32_t XCoordinate(int32_t contour, int32_t point); - int32_t YCoordinate(int32_t contour, int32_t point); - bool OnCurve(int32_t contour, int32_t point); - - private: - void Initialize(); - void ParseData(bool fill_arrays); - int32_t FlagAsInt(int32_t index); - int32_t ContourEndPoint(int32_t contour); - - bool initialized_; - int32_t instruction_size_; - int32_t number_of_points_; - - // start offsets of the arrays - int32_t instructions_offset_; - int32_t flags_offset_; - int32_t x_coordinates_offset_; - int32_t y_coordinates_offset_; - - int32_t flag_byte_count_; - int32_t x_byte_count_; - int32_t y_byte_count_; - - IntegerList x_coordinates_; - IntegerList y_coordinates_; - std::vector on_curve_; - IntegerList contour_index_; - }; - - class CompositeGlyph : public Glyph, public RefCounted { - public: - static const int32_t kFLAG_ARG_1_AND_2_ARE_WORDS; - static const int32_t kFLAG_ARGS_ARE_XY_VALUES; - static const int32_t kFLAG_ROUND_XY_TO_GRID; - static const int32_t kFLAG_WE_HAVE_A_SCALE; - static const int32_t kFLAG_RESERVED; - static const int32_t kFLAG_MORE_COMPONENTS; - static const int32_t kFLAG_WE_HAVE_AN_X_AND_Y_SCALE; - static const int32_t kFLAG_WE_HAVE_A_TWO_BY_TWO; - static const int32_t kFLAG_WE_HAVE_INSTRUCTIONS; - static const int32_t kFLAG_USE_MY_METRICS; - static const int32_t kFLAG_OVERLAP_COMPOUND; - static const int32_t kFLAG_SCALED_COMPONENT_OFFSET; - static const int32_t kFLAG_UNSCALED_COMPONENT_OFFSET; - - class CompositeGlyphBuilder : public Glyph::Builder, - public RefCounted { - public: - virtual ~CompositeGlyphBuilder(); - - protected: - // Note: constructor refactored in C++ to avoid heavy lifting. - // caller need to do data->Slice(offset, length) beforehand. - CompositeGlyphBuilder(FontDataTableBuilderContainer* table_builder, - WritableFontData* data); - CompositeGlyphBuilder(FontDataTableBuilderContainer* table_builder, - ReadableFontData* data); - - virtual CALLER_ATTACH FontDataTable* - SubBuildTable(ReadableFontData* data); - - private: - friend class Glyph::Builder; - }; - - // Note: constructor refactored in C++ to avoid heavy lifting. - // caller need to do data->Slice(offset, length) beforehand. - explicit CompositeGlyph(ReadableFontData* data); - virtual ~CompositeGlyph(); - - int32_t Flags(int32_t contour); - int32_t NumGlyphs(); - int32_t GlyphIndex(int32_t contour); - int32_t Argument1(int32_t contour); - int32_t Argument2(int32_t contour); - int32_t TransformationSize(int32_t contour); - void Transformation(int32_t contour, ByteVector* transformation); - virtual int32_t InstructionSize(); - virtual CALLER_ATTACH ReadableFontData* Instructions(); - - private: - void ParseData(); - - IntegerList contour_index_; - int32_t instruction_size_; - int32_t instructions_offset_; - }; - - virtual ~GlyphTable(); - - // C++ port: rename glyph() to GetGlyph(). - Glyph* GetGlyph(int32_t offset, int32_t length); - - private: - struct Offset { - enum { - // header - kNumberOfContours = 0, - kXMin = 2, - kYMin = 4, - kXMax = 6, - kYMax = 8, - - // Simple Glyph Description - kSimpleEndPtsOfCountours = 10, - // offset from the end of the contours array - kSimpleInstructionLength = 0, - kSimpleInstructions = 2, - // flags - // xCoordinates - // yCoordinates - - // Composite Glyph Description - kCompositeFlags = 0, - kCompositeGyphIndexWithoutFlag = 0, - kCompositeGlyphIndexWithFlag = 2, - }; - }; - - GlyphTable(Header* header, ReadableFontData* data); -}; -typedef Ptr GlyphTablePtr; -typedef Ptr GlyphTableBuilderPtr; -typedef std::vector GlyphTableBuilderList; -typedef Ptr GlyphPtr; -typedef Ptr GlyphBuilderPtr; - -} // namespace sfntly - -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_GLYPH_TABLE_H_ diff --git a/sfntly/horizontal_header_table.cc b/sfntly/horizontal_header_table.cc deleted file mode 100644 index a987d70..0000000 --- a/sfntly/horizontal_header_table.cc +++ /dev/null @@ -1,215 +0,0 @@ -/* - * 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. - */ - -// Note: original Java version is inconsistent itself (e.g. readUShort in -// Builder but readShort in Table. Need Fix. -// TODO(arthurhsu): check with Stuart G and fix it. - -#include "sfntly/horizontal_header_table.h" - -namespace sfntly { -/****************************************************************************** - * HorizontalHeaderTable class - ******************************************************************************/ -HorizontalHeaderTable:: ~HorizontalHeaderTable() {} - -int32_t HorizontalHeaderTable::Version() { - return data_->ReadFixed(Offset::kVersion); -} - -int32_t HorizontalHeaderTable::Ascender() { - return data_->ReadShort(Offset::kAscender); -} - -int32_t HorizontalHeaderTable::Descender() { - return data_->ReadShort(Offset::kDescender); -} - -int32_t HorizontalHeaderTable::LineGap() { - return data_->ReadShort(Offset::kLineGap); -} - -int32_t HorizontalHeaderTable::AdvanceWidthMax() { - return data_->ReadUShort(Offset::kAdvanceWidthMax); -} - -int32_t HorizontalHeaderTable::MinLeftSideBearing() { - return data_->ReadShort(Offset::kMinLeftSideBearing); -} - -int32_t HorizontalHeaderTable::MinRightSideBearing() { - return data_->ReadShort(Offset::kMinRightSideBearing); -} - -int32_t HorizontalHeaderTable::XMaxExtent() { - return data_->ReadShort(Offset::kXMaxExtent); -} - -int32_t HorizontalHeaderTable::CaretSlopeRise() { - return data_->ReadShort(Offset::kCaretSlopeRise); -} - -int32_t HorizontalHeaderTable::CaretSlopeRun() { - return data_->ReadShort(Offset::kCaretSlopeRun); -} - -int32_t HorizontalHeaderTable::CaretOffset() { - return data_->ReadShort(Offset::kCaretOffset); -} - -int32_t HorizontalHeaderTable::MetricDataFormat() { - return data_->ReadShort(Offset::kMetricDataFormat); -} - -int32_t HorizontalHeaderTable::NumberOfHMetrics() { - return data_->ReadUShort(Offset::kNumberOfHMetrics); -} - -HorizontalHeaderTable:: HorizontalHeaderTable(Header* header, - ReadableFontData* data) - : Table(header, data) { -} - -/****************************************************************************** - * HorizontalHeaderTable::Builder class - ******************************************************************************/ -HorizontalHeaderTable::Builder::Builder( - FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data) - : Table::TableBasedTableBuilder(font_builder, header, data) { -} - -HorizontalHeaderTable::Builder::Builder( - FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data) - : Table::TableBasedTableBuilder(font_builder, header, data) { -} - -HorizontalHeaderTable::Builder::~Builder() {} - -CALLER_ATTACH FontDataTable* - HorizontalHeaderTable::Builder::SubBuildTable(ReadableFontData* data) { - FontDataTablePtr table = new HorizontalHeaderTable(header(), data); - return table.Detach(); -} - -int32_t HorizontalHeaderTable::Builder::Version() { - return InternalReadData()->ReadFixed(Offset::kVersion); -} - -void HorizontalHeaderTable::Builder::SetVersion(int32_t version) { - InternalWriteData()->WriteFixed(Offset::kVersion, version); -} - -int32_t HorizontalHeaderTable::Builder::Ascender() { - return InternalReadData()->ReadUShort(Offset::kAscender); -} - -void HorizontalHeaderTable::Builder::SetAscender(int32_t ascender) { - InternalWriteData()->WriteUShort(Offset::kVersion, ascender); -} - -int32_t HorizontalHeaderTable::Builder::Descender() { - return InternalReadData()->ReadUShort(Offset::kDescender); -} - -void HorizontalHeaderTable::Builder::SetDescender(int32_t descender) { - InternalWriteData()->WriteUShort(Offset::kDescender, descender); -} - -int32_t HorizontalHeaderTable::Builder::LineGap() { - return InternalReadData()->ReadUShort(Offset::kLineGap); -} - -void HorizontalHeaderTable::Builder::SetLineGap(int32_t line_gap) { - InternalWriteData()->WriteUShort(Offset::kLineGap, line_gap); -} - -int32_t HorizontalHeaderTable::Builder::AdvanceWidthMax() { - return InternalReadData()->ReadUShort(Offset::kAdvanceWidthMax); -} - -void HorizontalHeaderTable::Builder::SetAdvanceWidthMax(int32_t value) { - InternalWriteData()->WriteUShort(Offset::kAdvanceWidthMax, value); -} - -int32_t HorizontalHeaderTable::Builder::MinLeftSideBearing() { - return InternalReadData()->ReadUShort(Offset::kMinLeftSideBearing); -} - -void HorizontalHeaderTable::Builder::SetMinLeftSideBearing(int32_t value) { - InternalWriteData()->WriteUShort(Offset::kMinLeftSideBearing, value); -} - -int32_t HorizontalHeaderTable::Builder::MinRightSideBearing() { - return InternalReadData()->ReadUShort(Offset::kMinRightSideBearing); -} - -void HorizontalHeaderTable::Builder::SetMinRightSideBearing(int32_t value) { - InternalWriteData()->WriteUShort(Offset::kMinRightSideBearing, value); -} - -int32_t HorizontalHeaderTable::Builder::XMaxExtent() { - return InternalReadData()->ReadUShort(Offset::kXMaxExtent); -} - -void HorizontalHeaderTable::Builder::SetXMaxExtent(int32_t value) { - InternalWriteData()->WriteUShort(Offset::kXMaxExtent, value); -} - -int32_t HorizontalHeaderTable::Builder::CaretSlopeRise() { - return InternalReadData()->ReadUShort(Offset::kCaretSlopeRise); -} - -void HorizontalHeaderTable::Builder::SetCaretSlopeRise(int32_t value) { - InternalWriteData()->WriteUShort(Offset::kCaretSlopeRise, value); -} - -int32_t HorizontalHeaderTable::Builder::CaretSlopeRun() { - return InternalReadData()->ReadUShort(Offset::kCaretSlopeRun); -} - -void HorizontalHeaderTable::Builder::SetCaretSlopeRun(int32_t value) { - InternalWriteData()->WriteUShort(Offset::kCaretSlopeRun, value); -} - -int32_t HorizontalHeaderTable::Builder::CaretOffset() { - return InternalReadData()->ReadUShort(Offset::kCaretOffset); -} - -void HorizontalHeaderTable::Builder::SetCaretOffset(int32_t value) { - InternalWriteData()->WriteUShort(Offset::kCaretOffset, value); -} - -int32_t HorizontalHeaderTable::Builder::MetricDataFormat() { - return InternalReadData()->ReadUShort(Offset::kMetricDataFormat); -} - -void HorizontalHeaderTable::Builder::SetMetricDataFormat(int32_t value) { - InternalWriteData()->WriteUShort(Offset::kMetricDataFormat, value); -} - -int32_t HorizontalHeaderTable::Builder::NumberOfHMetrics() { - return InternalReadData()->ReadUShort(Offset::kNumberOfHMetrics); -} - -void HorizontalHeaderTable::Builder::SetNumberOfHMetrics(int32_t value) { - InternalWriteData()->WriteUShort(Offset::kNumberOfHMetrics, value); -} - -} // namespace sfntly diff --git a/sfntly/horizontal_header_table.h b/sfntly/horizontal_header_table.h deleted file mode 100644 index e8a3534..0000000 --- a/sfntly/horizontal_header_table.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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. - */ - -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_HORIZONTAL_HEADER_TABLE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_HORIZONTAL_HEADER_TABLE_H_ - -#include "sfntly/table.h" - -namespace sfntly { - -class HorizontalHeaderTable : public Table, - public RefCounted { - public: - class Builder : public Table::TableBasedTableBuilder, - public RefCounted { - public: - // Constructor scope altered to public because C++ does not allow base - // class to instantiate derived class with protected constructors. - Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data); - Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data); - virtual ~Builder(); - virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); - - int32_t Version(); - void SetVersion(int32_t version); - int32_t Ascender(); - void SetAscender(int32_t ascender); - int32_t Descender(); - void SetDescender(int32_t descender); - int32_t LineGap(); - void SetLineGap(int32_t line_gap); - int32_t AdvanceWidthMax(); - void SetAdvanceWidthMax(int32_t value); - int32_t MinLeftSideBearing(); - void SetMinLeftSideBearing(int32_t value); - int32_t MinRightSideBearing(); - void SetMinRightSideBearing(int32_t value); - int32_t XMaxExtent(); - void SetXMaxExtent(int32_t value); - int32_t CaretSlopeRise(); - void SetCaretSlopeRise(int32_t value); - int32_t CaretSlopeRun(); - void SetCaretSlopeRun(int32_t value); - int32_t CaretOffset(); - void SetCaretOffset(int32_t value); - int32_t MetricDataFormat(); - void SetMetricDataFormat(int32_t value); - int32_t NumberOfHMetrics(); - void SetNumberOfHMetrics(int32_t value); - }; - - virtual ~HorizontalHeaderTable(); - int32_t Version(); - int32_t Ascender(); - int32_t Descender(); - int32_t LineGap(); - int32_t AdvanceWidthMax(); - int32_t MinLeftSideBearing(); - int32_t MinRightSideBearing(); - int32_t XMaxExtent(); - int32_t CaretSlopeRise(); - int32_t CaretSlopeRun(); - int32_t CaretOffset(); - int32_t MetricDataFormat(); - int32_t NumberOfHMetrics(); - - private: - struct Offset { - enum { - kVersion = 0, - kAscender = 4, - kDescender = 6, - kLineGap = 8, - kAdvanceWidthMax = 10, - kMinLeftSideBearing = 12, - kMinRightSideBearing = 14, - kXMaxExtent = 16, - kCaretSlopeRise = 18, - kCaretSlopeRun = 20, - kCaretOffset = 22, - kMetricDataFormat = 32, - kNumberOfHMetrics = 34, - }; - }; - - HorizontalHeaderTable(Header* header, ReadableFontData* data); -}; -typedef Ptr HorizontalHeaderTablePtr; -typedef Ptr HorizontalHeaderTableBuilderPtr; - -} // namespace sfntly - -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_HORIZONTAL_HEADER_TABLE_H_ diff --git a/sfntly/horizontal_metrics_table.cc b/sfntly/horizontal_metrics_table.cc deleted file mode 100644 index 026891d..0000000 --- a/sfntly/horizontal_metrics_table.cc +++ /dev/null @@ -1,151 +0,0 @@ -/* - * 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 "sfntly/horizontal_metrics_table.h" -#include "sfntly/port/exception_type.h" - -namespace sfntly { -/****************************************************************************** - * HorizontalMetricsTable class - ******************************************************************************/ -HorizontalMetricsTable::~HorizontalMetricsTable() {} - -int32_t HorizontalMetricsTable::NumberOfHMetrics() { - return num_hmetrics_; -} - -int32_t HorizontalMetricsTable::NumberOfLSBs() { - return num_glyphs_ - num_hmetrics_; -} - -int32_t HorizontalMetricsTable::HMetricAdvanceWidth(int32_t entry) { - if (entry > num_hmetrics_) { -#if defined (SFNTLY_NO_EXCEPTION) - return 0; -#else - throw IndexOutOfBoundException(); -#endif - } - int32_t offset = Offset::kHMetricsStart + (entry * Offset::kHMetricsSize) + - Offset::kHMetricsAdvanceWidth; - return data_->ReadUShort(offset); -} - -int32_t HorizontalMetricsTable::HMetricLSB(int32_t entry) { - if (entry > num_hmetrics_) { -#if defined (SFNTLY_NO_EXCEPTION) - return 0; -#else - throw IndexOutOfBoundException(); -#endif - } - int32_t offset = Offset::kHMetricsStart + (entry * Offset::kHMetricsSize) + - Offset::kHMetricsLeftSideBearing; - return data_->ReadShort(offset); -} - -int32_t HorizontalMetricsTable::LsbTableEntry(int32_t entry) { - if (entry > num_hmetrics_) { -#if defined (SFNTLY_NO_EXCEPTION) - return 0; -#else - throw IndexOutOfBoundException(); -#endif - } - int32_t offset = Offset::kHMetricsStart + (entry * Offset::kHMetricsSize) + - Offset::kLeftSideBearingSize; - return data_->ReadShort(offset); -} - -int32_t HorizontalMetricsTable::AdvanceWidth(int32_t glyph_id) { - if (glyph_id < num_hmetrics_) { - return HMetricAdvanceWidth(glyph_id); - } - return HMetricAdvanceWidth(glyph_id - num_hmetrics_); -} - -int32_t HorizontalMetricsTable::LeftSideBearing(int32_t glyph_id) { - if (glyph_id < num_hmetrics_) { - return HMetricLSB(glyph_id); - } - return LsbTableEntry(glyph_id - num_hmetrics_); -} - -HorizontalMetricsTable::HorizontalMetricsTable(Header* header, - ReadableFontData* data) - : Table(header, data) { -} - -HorizontalMetricsTable::HorizontalMetricsTable(Header* header, - ReadableFontData* data, - int32_t num_hmetrics, - int32_t num_glyphs) - : Table(header, data), - num_hmetrics_(num_hmetrics), - num_glyphs_(num_glyphs) { -} - -/****************************************************************************** - * HorizontalMetricsTable::Builder class - ******************************************************************************/ -HorizontalMetricsTable::Builder::Builder( - FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data) - : Table::TableBasedTableBuilder(font_builder, header, data) { - Init(); -} - -HorizontalMetricsTable::Builder::Builder( - FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data) - : Table::TableBasedTableBuilder(font_builder, header, data) { - Init(); -} - -HorizontalMetricsTable::Builder::~Builder() {} - -CALLER_ATTACH FontDataTable* - HorizontalMetricsTable::Builder::SubBuildTable(ReadableFontData* data) { - FontDataTablePtr table = - new HorizontalMetricsTable(header(), data, num_hmetrics_, num_glyphs_); - return table.Detach(); -} - -void HorizontalMetricsTable::Builder::SetNumberOfHMetrics( - int32_t num_hmetrics) { - assert(num_hmetrics >= 0); - num_hmetrics_ = num_hmetrics; - HorizontalMetricsTable* table = - down_cast(this->GetTable()); - table->num_hmetrics_ = num_hmetrics; -} - -void HorizontalMetricsTable::Builder::SetNumGlyphs(int32_t num_glyphs) { - assert(num_glyphs >= 0); - num_glyphs_ = num_glyphs; - HorizontalMetricsTable* table = - down_cast(this->GetTable()); - table->num_glyphs_ = num_glyphs; -} - -void HorizontalMetricsTable::Builder::Init() { - num_hmetrics_ = -1; - num_glyphs_ = -1; -} - -} // namespace sfntly diff --git a/sfntly/horizontal_metrics_table.h b/sfntly/horizontal_metrics_table.h deleted file mode 100644 index 55acce6..0000000 --- a/sfntly/horizontal_metrics_table.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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. - */ - -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_HORIZONTAL_METRICS_TABLE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_HORIZONTAL_METRICS_TABLE_H_ - -#include "sfntly/table.h" - -namespace sfntly { - -class HorizontalMetricsTable : public Table, - public RefCounted { - public: - class Builder : public Table::TableBasedTableBuilder, - public RefCounted { - public: - // Constructor scope altered to public because C++ does not allow base - // class to instantiate derived class with protected constructors. - Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data); - Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data); - virtual ~Builder(); - - virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); - void SetNumberOfHMetrics(int32_t num_hmetrics); - void SetNumGlyphs(int32_t num_glyphs); - - private: - void Init(); - - int32_t num_hmetrics_; - int32_t num_glyphs_; - }; - - virtual ~HorizontalMetricsTable(); - int32_t NumberOfHMetrics(); - int32_t NumberOfLSBs(); - int32_t HMetricAdvanceWidth(int32_t entry); - int32_t HMetricLSB(int32_t entry); - int32_t LsbTableEntry(int32_t entry); - int32_t AdvanceWidth(int32_t glyph_id); - int32_t LeftSideBearing(int32_t glyph_id); - - private: - struct Offset { - enum { - // hMetrics - kHMetricsStart = 0, - kHMetricsSize = 4, - - // Offset within an hMetric - kHMetricsAdvanceWidth = 0, - kHMetricsLeftSideBearing = 2, - - kLeftSideBearingSize = 2 - }; - }; - - HorizontalMetricsTable(Header* header, ReadableFontData* data); - HorizontalMetricsTable(Header* header, - ReadableFontData* data, - int32_t num_hmetrics, - int32_t num_glyphs); - - int32_t num_hmetrics_; - int32_t num_glyphs_; -}; -typedef Ptr HorizontalMetricsTablePtr; -typedef Ptr HorizontalMetricsTableBuilderPtr; - -} // namespace sfntly - -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_HORIZONTAL_METRICS_TABLE_H_ diff --git a/sfntly/loca_table.cc b/sfntly/loca_table.cc deleted file mode 100644 index 1869e15..0000000 --- a/sfntly/loca_table.cc +++ /dev/null @@ -1,250 +0,0 @@ -/* - * 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 "sfntly/loca_table.h" -#include "sfntly/port/exception_type.h" - -namespace sfntly { -/****************************************************************************** - * LocaTable class - ******************************************************************************/ -LocaTable::~LocaTable() {} - -int32_t LocaTable::NumGlyphs() { - return num_glyphs_; -} - -int32_t LocaTable::GlyphOffset(int32_t glyph_id) { - if (glyph_id < 0 || glyph_id >= num_glyphs_) { -#if defined (SFNTLY_NO_EXCEPTION) - return 0; -#else - throw IndexOutOfBoundException("Glyph ID is out of bounds."); -#endif - } - return Loca(glyph_id); -} - -int32_t LocaTable::GlyphLength(int32_t glyph_id) { - if (glyph_id < 0 || glyph_id >= num_glyphs_) { -#if defined (SFNTLY_NO_EXCEPTION) - return 0; -#else - throw IndexOutOfBoundException("Glyph ID is out of bounds."); -#endif - } - return Loca(glyph_id + 1) - Loca(glyph_id); -} - -int32_t LocaTable::NumLocas() { - return num_glyphs_ + 1; -} - -int32_t LocaTable::Loca(int32_t index) { - if (index > num_glyphs_) { -#if defined (SFNTLY_NO_EXCEPTION) - return 0; -#else - throw IndexOutOfBoundException(); -#endif - } - if (version_ == IndexToLocFormat::kShortOffset) { - return 2 * data_->ReadUShort(index * DataSize::kUSHORT); - } - return data_->ReadULongAsInt(index * DataSize::kULONG); -} - -LocaTable::LocaTable(Header* header, ReadableFontData* data) - : Table(header, data) { -} - -LocaTable::LocaTable(Header* header, - ReadableFontData* data, - int32_t version, - int32_t num_glyphs) - : Table(header, data), version_(version), num_glyphs_(num_glyphs) { -} - -/****************************************************************************** - * LocaTable::Iterator class - ******************************************************************************/ -LocaTable::LocaIterator::LocaIterator(LocaTable* table) - : index_(-1) { - table_ = table; -} - -bool LocaTable::LocaIterator::HasNext() { - return index_ <= table_->num_glyphs_; -} - -int32_t LocaTable::LocaIterator::Next() { - return table_->Loca(index_++); -} - -/****************************************************************************** - * LocaTable::Builder class - ******************************************************************************/ -LocaTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, - Header* header, WritableFontData* data) : - Table::ArrayElementTableBuilder(font_builder, header, data) { - Init(); -} - -LocaTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, - Header* header, ReadableFontData* data) : - Table::ArrayElementTableBuilder(font_builder, header, data) { - Init(); -} - -LocaTable::Builder::~Builder() {} - -void LocaTable::Builder::SetFormatVersion(int32_t format_version) { - format_version_ = format_version; -} - -IntegerList* LocaTable::Builder::LocaList() { - return GetLocaList(); -} - -void LocaTable::Builder::SetLocaList(IntegerList* list) { - loca_.clear(); - if (list) { - loca_ = *list; - num_glyphs_ = loca_.size(); - set_model_changed(); - } -} - -int32_t LocaTable::Builder::GlyphOffset(int32_t glyph_id) { - if (glyph_id < 0 || glyph_id > (num_glyphs_ + 1)) { -#if defined (SFNTLY_NO_EXCEPTION) - return 0; -#else - throw IndexOutOfBoundException("Glyph ID is out of bounds."); -#endif - } - return Loca(glyph_id); -} - -int32_t LocaTable::Builder::GlyphLength(int32_t glyph_id) { - if (glyph_id < 0 || glyph_id > (num_glyphs_ + 1)) { -#if defined (SFNTLY_NO_EXCEPTION) - return 0; -#else - throw IndexOutOfBoundException("Glyph ID is out of bounds."); -#endif - } - return Loca(glyph_id + 1) - Loca(glyph_id); -} - -void LocaTable::Builder::SetNumGlyphs(int32_t num_glyphs) { - num_glyphs_ = num_glyphs; -} - -int32_t LocaTable::Builder::NumGlyphs() { - if (!loca_.empty()) { - return loca_.size() - 1; - } - return num_glyphs_; -} - -void LocaTable::Builder::Revert() { - loca_.clear(); - set_model_changed(false); -} - -void LocaTable::Builder::Clear() { - GetLocaList()->clear(); -} - -int32_t LocaTable::Builder::NumLocas() { - return GetLocaList()->size(); -} - -int32_t LocaTable::Builder::Loca(int32_t index) { - return GetLocaList()->at(index); -} - -CALLER_ATTACH FontDataTable* LocaTable::Builder::SubBuildTable( - ReadableFontData* data) { - FontDataTablePtr table = - new LocaTable(header(), data, format_version_, num_glyphs_); - return table.Detach(); -} - -void LocaTable::Builder::SubDataSet() { - Initialize(InternalReadData()); -} - -int32_t LocaTable::Builder::SubDataSizeToSerialize() { - if (loca_.empty()) { - return 0; - } - if (format_version_ == IndexToLocFormat::kLongOffset) { - return loca_.size() * DataSize::kULONG; - } - return loca_.size() * DataSize::kUSHORT; -} - -bool LocaTable::Builder::SubReadyToSerialize() { - return !loca_.empty(); -} - -int32_t LocaTable::Builder::SubSerialize(WritableFontData* new_data) { - int32_t size = 0; - for (IntegerList::iterator l = loca_.begin(), end = loca_.end(); - l != end; ++l) { - if (format_version_ == IndexToLocFormat::kLongOffset) { - size += new_data->WriteULong(size, *l); - } else { - size += new_data->WriteUShort(size, *l / 2); - } - } - return 0; -} - -void LocaTable::Builder::Init() { - num_glyphs_ = -1; - format_version_ = IndexToLocFormat::kLongOffset; -} - -void LocaTable::Builder::Initialize(ReadableFontData* data) { - if (data) { - if (NumGlyphs() < 0) { -#if defined (SFNTLY_NO_EXCEPTION) - return; -#else - throw IllegalStateException("numglyphs not set on LocaTable Builder."); -#endif - } - LocaTablePtr table = - new LocaTable(header(), data, format_version_, num_glyphs_); - LocaTable::LocaIterator loca_iter(table); - while (loca_iter.HasNext()) { - loca_.push_back(loca_iter.Next()); - } - } -} - -IntegerList* LocaTable::Builder::GetLocaList() { - if (loca_.empty()) { - Initialize(InternalReadData()); - set_model_changed(); - } - return &loca_; -} - -} // namespace sfntly diff --git a/sfntly/loca_table.h b/sfntly/loca_table.h deleted file mode 100644 index dcf9715..0000000 --- a/sfntly/loca_table.h +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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. - */ - -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_LOCA_TABLE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_LOCA_TABLE_H_ - -#include "sfntly/table.h" -#include "sfntly/font_header_table.h" - -namespace sfntly { - -class LocaTable : public Table, public RefCounted { - public: - // Note: different implementation than Java, caller to instantiate this class - // object directly from stack instead of calling LocaTable::iterator(). - class LocaIterator { - public: - explicit LocaIterator(LocaTable* table); - bool HasNext(); - int32_t Next(); - - private: - int32_t index_; - LocaTable* table_; // use dumb pointer since it's a composition object - }; - - class Builder : public Table::ArrayElementTableBuilder, - public RefCounted { - public: - // Constructor scope altered to public for base class to instantiate. - Builder(FontDataTableBuilderContainer* font_builder, Header* header, - WritableFontData* data); - Builder(FontDataTableBuilderContainer* font_builder, Header* header, - ReadableFontData* data); - virtual ~Builder(); - - void SetFormatVersion(int32_t format_version); - - // Gets the List of locas for loca table builder. These may be manipulated - // in any way by the caller and the changes will be reflected in the final - // loca table produced. - // If there is no current data for the loca table builder or the loca list - // have not been previously set then this will return an empty List. - IntegerList* LocaList(); - void SetLocaList(IntegerList* list); - - // Return the offset for the given glyph id. Valid glyph ids are from 0 to - // one less than the number of glyphs. The zero entry is the special entry - // for the notdef glyph. The final entry beyond the last glyph id is used to - // calculate the size of the last glyph. - // @param glyphId the glyph id to get the offset for; must be less than or - // equal to one more than the number of glyph ids - // @return the offset in the glyph table to the specified glyph id - int32_t GlyphOffset(int32_t glyph_id); - - // Get the length of the data in the glyph table for the specified glyph id. - int32_t GlyphLength(int32_t glyph_id); - - // Set the number of glyphs. - // This method sets the number of glyphs that the builder will attempt to - // parse location data for from the raw binary data. This method only needs - // to be called (and must be) when the raw data for this builder has - // been changed. - void SetNumGlyphs(int32_t num_glyphs); - int NumGlyphs(); - - void Revert(); - void Clear(); - - // Get the number of locations or locas. This will be one more than the - // number of glyphs for this table since the last loca position is used to - // indicate the size of the final glyph. - int32_t NumLocas(); - int32_t Loca(int32_t index); - - virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); - virtual void SubDataSet(); - virtual int32_t SubDataSizeToSerialize(); - virtual bool SubReadyToSerialize(); - virtual int32_t SubSerialize(WritableFontData* new_data); - - private: - void Init(); // short hand for common code in ctors, C++ port only - void Initialize(ReadableFontData* data); // ported from Java - IntegerList* GetLocaList(); - - int32_t format_version_; // Note: IndexToLocFormat - int32_t num_glyphs_; - IntegerList loca_; - }; - - virtual ~LocaTable(); - int32_t NumGlyphs(); - - // Return the offset for the given glyph id. Valid glyph ids are from 0 to the - // one less than the number of glyphs. The zero entry is the special entry for - // the notdef glyph. The final entry beyond the last glyph id is used to - // calculate the size of the last glyph. - // @param glyphId the glyph id to get the offset for; must be less than or - // equal to one more than the number of glyph ids - // @return the offset in the glyph table to the specified glyph id - int32_t GlyphOffset(int32_t glyph_id); - - // Get the length of the data in the glyph table for the specified glyph id. - int32_t GlyphLength(int32_t glyph_id); - - // Get the number of locations or locas. This will be one more than the number - // of glyphs for this table since the last loca position is used to indicate - // the size of the final glyph. - int32_t NumLocas(); - - // Get the value from the loca table for the index specified. Valid index - // values run from 0 to the number of glyphs in the font. - int32_t Loca(int32_t index); - - private: - LocaTable(Header* header, ReadableFontData* data); - LocaTable(Header* header, - ReadableFontData* data, - int32_t version, - int32_t num_glyphs); - - int32_t version_; // Note: IndexToLocFormat - int32_t num_glyphs_; - - friend class LocaIterator; -}; -typedef Ptr LocaTablePtr; -typedef Ptr LocaTableBuilderPtr; - -} // namespace sfntly - -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_LOCA_TABLE_H_ diff --git a/sfntly/math/fixed1616.h b/sfntly/math/fixed1616.h index 843da51..4abbe18 100644 --- a/sfntly/math/fixed1616.h +++ b/sfntly/math/fixed1616.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_MATH_FIXED1616_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_MATH_FIXED1616_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_MATH_FIXED1616_H_ +#define SFNTLY_CPP_SRC_SFNTLY_MATH_FIXED1616_H_ #include "sfntly/port/type.h" @@ -38,4 +38,4 @@ class Fixed1616 { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_MATH_FIXED1616_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_MATH_FIXED1616_H_ diff --git a/sfntly/math/font_math.h b/sfntly/math/font_math.h index f15a786..c469347 100644 --- a/sfntly/math/font_math.h +++ b/sfntly/math/font_math.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_MATH_FONT_MATH_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_MATH_FONT_MATH_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_MATH_FONT_MATH_H_ +#define SFNTLY_CPP_SRC_SFNTLY_MATH_FONT_MATH_H_ #include "sfntly/port/type.h" @@ -35,4 +35,4 @@ class FontMath { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_MATH_FONT_MATH_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_MATH_FONT_MATH_H_ diff --git a/sfntly/maximum_profile_table.cc b/sfntly/maximum_profile_table.cc deleted file mode 100644 index 0ab2aaf..0000000 --- a/sfntly/maximum_profile_table.cc +++ /dev/null @@ -1,224 +0,0 @@ -/* - * 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 "sfntly/maximum_profile_table.h" - -namespace sfntly { -/****************************************************************************** - * MaximumProfileTable class - ******************************************************************************/ -MaximumProfileTable::~MaximumProfileTable() {} - -int32_t MaximumProfileTable::Version() { - return data_->ReadFixed(Offset::kVersion); -} - -int32_t MaximumProfileTable::NumGlyphs() { - return data_->ReadUShort(Offset::kNumGlyphs); -} - -int32_t MaximumProfileTable::MaxPoints() { - return data_->ReadUShort(Offset::kMaxPoints); -} - -int32_t MaximumProfileTable::MaxContours() { - return data_->ReadUShort(Offset::kMaxContours); -} - -int32_t MaximumProfileTable::MaxCompositePoints() { - return data_->ReadUShort(Offset::kMaxCompositePoints); -} - -int32_t MaximumProfileTable::MaxZones() { - return data_->ReadUShort(Offset::kMaxZones); -} - -int32_t MaximumProfileTable::MaxTwilightPoints() { - return data_->ReadUShort(Offset::kMaxTwilightPoints); -} - -int32_t MaximumProfileTable::MaxStorage() { - return data_->ReadUShort(Offset::kMaxStorage); -} - -int32_t MaximumProfileTable::MaxFunctionDefs() { - return data_->ReadUShort(Offset::kMaxFunctionDefs); -} - -int32_t MaximumProfileTable::MaxStackElements() { - return data_->ReadUShort(Offset::kMaxStackElements); -} - -int32_t MaximumProfileTable::MaxSizeOfInstructions() { - return data_->ReadUShort(Offset::kMaxSizeOfInstructions); -} - -int32_t MaximumProfileTable::MaxComponentElements() { - return data_->ReadUShort(Offset::kMaxComponentElements); -} - -int32_t MaximumProfileTable::MaxComponentDepth() { - return data_->ReadUShort(Offset::kMaxComponentDepth); -} - -MaximumProfileTable::MaximumProfileTable(Header* header, - ReadableFontData* data) - : Table(header, data) { -} - -/****************************************************************************** - * MaximumProfileTable::Builder class - ******************************************************************************/ -MaximumProfileTable::Builder::Builder( - FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data) - : Table::TableBasedTableBuilder(font_builder, header, data) { -} - -MaximumProfileTable::Builder::Builder( - FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data) - : Table::TableBasedTableBuilder(font_builder, header, data) { -} - -MaximumProfileTable::Builder::~Builder() {} - -CALLER_ATTACH FontDataTable* - MaximumProfileTable::Builder::SubBuildTable(ReadableFontData* data) { - FontDataTablePtr table = new MaximumProfileTable(header(), data); - return table.Detach(); -} - -int32_t MaximumProfileTable::Builder::Version() { - return InternalReadData()->ReadUShort(Offset::kVersion); -} - -void MaximumProfileTable::Builder::SetVersion(int32_t version) { - InternalWriteData()->WriteUShort(Offset::kVersion, version); -} - -int32_t MaximumProfileTable::Builder::NumGlyphs() { - return InternalReadData()->ReadUShort(Offset::kNumGlyphs); -} - -void MaximumProfileTable::Builder::SetNumGlyphs(int32_t num_glyphs) { - InternalWriteData()->WriteUShort(Offset::kNumGlyphs, num_glyphs); -} - -int32_t MaximumProfileTable::Builder::MaxPoints() { - return InternalReadData()->ReadUShort(Offset::kMaxPoints); -} - -void MaximumProfileTable::Builder::SetMaxPoints(int32_t max_points) { - InternalWriteData()->WriteUShort(Offset::kMaxPoints, max_points); -} - -int32_t MaximumProfileTable::Builder::MaxContours() { - return InternalReadData()->ReadUShort(Offset::kMaxContours); -} - -void MaximumProfileTable::Builder::SetMaxContours(int32_t max_contours) { - InternalWriteData()->WriteUShort(Offset::kMaxContours, max_contours); -} - -int32_t MaximumProfileTable::Builder::MaxCompositePoints() { - return InternalReadData()->ReadUShort(Offset::kMaxCompositePoints); -} - -void MaximumProfileTable::Builder::SetMaxCompositePoints( - int32_t max_composite_points) { - InternalWriteData()->WriteUShort(Offset::kMaxCompositePoints, - max_composite_points); -} - -int32_t MaximumProfileTable::Builder::MaxZones() { - return InternalReadData()->ReadUShort(Offset::kMaxZones); -} - -void MaximumProfileTable::Builder::SetMaxZones(int32_t max_zones) { - InternalWriteData()->WriteUShort(Offset::kMaxZones, max_zones); -} - -int32_t MaximumProfileTable::Builder::MaxTwilightPoints() { - return InternalReadData()->ReadUShort(Offset::kMaxTwilightPoints); -} - -void MaximumProfileTable::Builder::SetMaxTwilightPoints( - int32_t max_twilight_points) { - InternalWriteData()->WriteUShort(Offset::kMaxTwilightPoints, - max_twilight_points); -} - -int32_t MaximumProfileTable::Builder::MaxStorage() { - return InternalReadData()->ReadUShort(Offset::kMaxStorage); -} - -void MaximumProfileTable::Builder::SetMaxStorage(int32_t max_storage) { - InternalWriteData()->WriteUShort(Offset::kMaxStorage, max_storage); -} - -int32_t MaximumProfileTable::Builder::MaxFunctionDefs() { - return InternalReadData()->ReadUShort(Offset::kMaxFunctionDefs); -} - -void MaximumProfileTable::Builder::SetMaxFunctionDefs( - int32_t max_function_defs) { - InternalWriteData()->WriteUShort(Offset::kMaxFunctionDefs, max_function_defs); -} - -int32_t MaximumProfileTable::Builder::MaxStackElements() { - return InternalReadData()->ReadUShort(Offset::kMaxStackElements); -} - -void MaximumProfileTable::Builder::SetMaxStackElements( - int32_t max_stack_elements) { - InternalWriteData()->WriteUShort(Offset::kMaxStackElements, - max_stack_elements); -} - -int32_t MaximumProfileTable::Builder::MaxSizeOfInstructions() { - return InternalReadData()->ReadUShort(Offset::kMaxSizeOfInstructions); -} - -void MaximumProfileTable::Builder::SetMaxSizeOfInstructions( - int32_t max_size_of_instructions) { - InternalWriteData()->WriteUShort(Offset::kMaxSizeOfInstructions, - max_size_of_instructions); -} - -int32_t MaximumProfileTable::Builder::MaxComponentElements() { - return InternalReadData()->ReadUShort(Offset::kMaxComponentElements); -} - -void MaximumProfileTable::Builder::SetMaxComponentElements( - int32_t max_component_elements) { - InternalWriteData()->WriteUShort(Offset::kMaxComponentElements, - max_component_elements); -} - -int32_t MaximumProfileTable::Builder::MaxComponentDepth() { - return InternalReadData()->ReadUShort(Offset::kMaxComponentDepth); -} - -void MaximumProfileTable::Builder::SetMaxComponentDepth( - int32_t max_component_depth) { - InternalWriteData()->WriteUShort(Offset::kMaxComponentDepth, - max_component_depth); -} - -} // namespace sfntly diff --git a/sfntly/maximum_profile_table.h b/sfntly/maximum_profile_table.h deleted file mode 100644 index 9e0d0a6..0000000 --- a/sfntly/maximum_profile_table.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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. - */ - -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_MAXIMUM_PROFILE_TABLE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_MAXIMUM_PROFILE_TABLE_H_ - -#include "sfntly/port/refcount.h" -#include "sfntly/table.h" - -namespace sfntly { - -class MaximumProfileTable : public Table, - public RefCounted { - public: - class Builder : public Table::TableBasedTableBuilder, - public RefCounted { - public: - // Constructor scope altered to public because C++ does not allow base - // class to instantiate derived class with protected constructors. - Builder(FontDataTableBuilderContainer* font_builder, Header* header, - WritableFontData* data); - Builder(FontDataTableBuilderContainer* font_builder, Header* header, - ReadableFontData* data); - virtual ~Builder(); - - virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); - - int32_t Version(); - void SetVersion(int32_t version); - int32_t NumGlyphs(); - void SetNumGlyphs(int32_t num_glyphs); - int32_t MaxPoints(); - void SetMaxPoints(int32_t max_points); - int32_t MaxContours(); - void SetMaxContours(int32_t max_contours); - int32_t MaxCompositePoints(); - void SetMaxCompositePoints(int32_t max_composite_points); - int32_t MaxZones(); - void SetMaxZones(int32_t max_zones); - int32_t MaxTwilightPoints(); - void SetMaxTwilightPoints(int32_t max_twilight_points); - int32_t MaxStorage(); - void SetMaxStorage(int32_t max_storage); - int32_t MaxFunctionDefs(); - void SetMaxFunctionDefs(int32_t max_function_defs); - int32_t MaxStackElements(); - void SetMaxStackElements(int32_t max_stack_elements); - int32_t MaxSizeOfInstructions(); - void SetMaxSizeOfInstructions(int32_t max_size_of_instructions); - int32_t MaxComponentElements(); - void SetMaxComponentElements(int32_t max_component_elements); - int32_t MaxComponentDepth(); - void SetMaxComponentDepth(int32_t max_component_depth); - }; - - virtual ~MaximumProfileTable(); - int32_t Version(); - int32_t NumGlyphs(); - int32_t MaxPoints(); - int32_t MaxContours(); - int32_t MaxCompositePoints(); - int32_t MaxZones(); - int32_t MaxTwilightPoints(); - int32_t MaxStorage(); - int32_t MaxFunctionDefs(); - int32_t MaxStackElements(); - int32_t MaxSizeOfInstructions(); - int32_t MaxComponentElements(); - int32_t MaxComponentDepth(); - - private: - struct Offset { - enum { - // version 0.5 and 1.0 - kVersion = 0, - kNumGlyphs = 4, - - // version 1.0 - kMaxPoints = 6, - kMaxContours = 8, - kMaxCompositePoints = 10, - kMaxCompositeContours = 12, - kMaxZones = 14, - kMaxTwilightPoints = 16, - kMaxStorage = 18, - kMaxFunctionDefs = 20, - kMaxInstructionDefs = 22, - kMaxStackElements = 24, - kMaxSizeOfInstructions = 26, - kMaxComponentElements = 28, - kMaxComponentDepth = 30, - }; - }; - - MaximumProfileTable(Header* header, ReadableFontData* data); -}; -typedef Ptr MaximumProfileTablePtr; -typedef Ptr MaximumProfileTableBuilderPtr; - -} // namespace sfntly - -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_MAXIMUM_PROFILE_TABLE_H_ diff --git a/sfntly/name_table.cc b/sfntly/name_table.cc deleted file mode 100644 index 649baed..0000000 --- a/sfntly/name_table.cc +++ /dev/null @@ -1,722 +0,0 @@ -/* - * 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 "sfntly/name_table.h" - -#include -#include - -#include - -#include "sfntly/font.h" -#include "sfntly/port/exception_type.h" - -namespace sfntly { -/****************************************************************************** - * NameTable::NameEntryId class - ******************************************************************************/ -NameTable::NameEntryId::NameEntryId() - : platform_id_(0), - encoding_id_(0), - language_id_(0), - name_id_(0) { -} - -NameTable::NameEntryId::NameEntryId(int32_t platform_id, - int32_t encoding_id, - int32_t language_id, - int32_t name_id) - : platform_id_(platform_id), - encoding_id_(encoding_id), - language_id_(language_id), - name_id_(name_id) { -} - -NameTable::NameEntryId::NameEntryId(const NameTable::NameEntryId& rhs) { - *this = rhs; -} - -const NameTable::NameEntryId& - NameTable::NameEntryId::operator=(const NameTable::NameEntryId& rhs) const { - platform_id_ = rhs.platform_id_; - encoding_id_ = rhs.encoding_id_; - language_id_ = rhs.language_id_; - name_id_ = rhs.name_id_; - return *this; -} - -bool NameTable::NameEntryId::operator==(const NameEntryId& rhs) const { - return platform_id_ == rhs.platform_id_ && - encoding_id_ == rhs.encoding_id_ && - language_id_ == rhs.language_id_ && - name_id_ == rhs.name_id_; -} - -bool NameTable::NameEntryId::operator<(const NameEntryId& rhs) const { - if (platform_id_ != rhs.platform_id_) return platform_id_ < rhs.platform_id_; - if (encoding_id_ != rhs.encoding_id_) return encoding_id_ < rhs.encoding_id_; - if (language_id_ != rhs.language_id_) return language_id_ < rhs.language_id_; - return name_id_ < rhs.name_id_; -} - -/****************************************************************************** - * NameTable::NameEntry class - ******************************************************************************/ -NameTable::NameEntry::NameEntry() { - Init(0, 0, 0, 0, NULL); -} - -NameTable::NameEntry::NameEntry(const NameEntryId& name_entry_id, - const ByteVector& name_bytes) { - Init(name_entry_id.platform_id(), - name_entry_id.encoding_id(), - name_entry_id.language_id(), - name_entry_id.name_id(), - &name_bytes); -} - -NameTable::NameEntry::NameEntry(int32_t platform_id, - int32_t encoding_id, - int32_t language_id, - int32_t name_id, - const ByteVector& name_bytes) { - Init(platform_id, encoding_id, language_id, name_id, &name_bytes); -} - -NameTable::NameEntry::~NameEntry() {} - -ByteVector* NameTable::NameEntry::NameAsBytes() { - return &name_bytes_; -} - -int32_t NameTable::NameEntry::NameBytesLength() { - return name_bytes_.size(); -} - -UChar* NameTable::NameEntry::Name() { - return NameTable::ConvertFromNameBytes(&name_bytes_, - platform_id(), - encoding_id()); -} - -bool NameTable::NameEntry::operator==(const NameEntry& rhs) const { - return (name_entry_id_ == rhs.name_entry_id_ && - name_bytes_ == rhs.name_bytes_); -} - -void NameTable::NameEntry::Init(int32_t platform_id, - int32_t encoding_id, - int32_t language_id, - int32_t name_id, - const ByteVector* name_bytes) { - name_entry_id_ = NameEntryId(platform_id, encoding_id, language_id, name_id); - if (name_bytes) { - name_bytes_ = *name_bytes; - } else { - name_bytes_.clear(); - } -} - -/****************************************************************************** - * NameTable::NameEntryBuilder class - ******************************************************************************/ -NameTable::NameEntryBuilder::NameEntryBuilder() { - Init(0, 0, 0, 0, NULL); -} - -NameTable::NameEntryBuilder::NameEntryBuilder( - const NameEntryId& name_entry_id, const ByteVector& name_bytes) { - Init(name_entry_id.platform_id(), - name_entry_id.encoding_id(), - name_entry_id.language_id(), - name_entry_id.name_id(), - &name_bytes); -} - -NameTable::NameEntryBuilder::NameEntryBuilder( - const NameEntryId& name_entry_id) { - Init(name_entry_id.platform_id(), - name_entry_id.encoding_id(), - name_entry_id.language_id(), - name_entry_id.name_id(), - NULL); -} - -NameTable::NameEntryBuilder::NameEntryBuilder(NameEntry* b) { - Init(b->platform_id(), - b->encoding_id(), - b->language_id(), - b->name_id(), - b->NameAsBytes()); -} - -NameTable::NameEntryBuilder::~NameEntryBuilder() {} - -void NameTable::NameEntryBuilder::SetName(const UChar* name) { - if (name == NULL) { - name_entry_->name_bytes_.clear(); - return; - } - NameTable::ConvertToNameBytes(name, - name_entry_->platform_id(), - name_entry_->encoding_id(), - &name_entry_->name_bytes_); -} - -void NameTable::NameEntryBuilder::SetName(const ByteVector& name_bytes) { - name_entry_->name_bytes_.clear(); - std::copy(name_bytes.begin(), - name_bytes.end(), - name_entry_->name_bytes_.begin()); -} - -void NameTable::NameEntryBuilder::SetName(const ByteVector& name_bytes, - int32_t offset, - int32_t length) { - name_entry_->name_bytes_.clear(); - std::copy(name_bytes.begin() + offset, - name_bytes.begin() + offset + length, - name_entry_->name_bytes_.begin()); -} - -void NameTable::NameEntryBuilder::Init(int32_t platform_id, - int32_t encoding_id, - int32_t language_id, - int32_t name_id, - const ByteVector* name_bytes) { - name_entry_ = new NameEntry(); - name_entry_->Init(platform_id, encoding_id, language_id, name_id, name_bytes); -} - -/****************************************************************************** - * NameTable::NameEntryFilterInPlace class (C++ port only) - ******************************************************************************/ -NameTable::NameEntryFilterInPlace::NameEntryFilterInPlace(int32_t platform_id, - int32_t encoding_id, - int32_t language_id, - int32_t name_id) - : platform_id_(platform_id), - encoding_id_(encoding_id), - language_id_(language_id), - name_id_(name_id) { -} - -bool NameTable::NameEntryFilterInPlace::Accept(int32_t platform_id, - int32_t encoding_id, - int32_t language_id, - int32_t name_id) { - return (platform_id_ == platform_id && - encoding_id_ == encoding_id && - language_id_ == language_id && - name_id_ == name_id); -} - -/****************************************************************************** - * NameTable::NameEntryIterator class - ******************************************************************************/ -NameTable::NameEntryIterator::NameEntryIterator(NameTable* table) { - Init(table, NULL); -} - -NameTable::NameEntryIterator::NameEntryIterator(NameTable* table, - NameEntryFilter* filter) { - Init(table, filter); -} - -bool NameTable::NameEntryIterator::HasNext() { - if (!filter_) { - if (name_index_ < table_->NameCount()) { - return true; - } - return false; - } - for (; name_index_ < table_->NameCount(); ++name_index_) { - if (filter_->Accept(table_->PlatformId(name_index_), - table_->EncodingId(name_index_), - table_->LanguageId(name_index_), - table_->NameId(name_index_))) { - return true; - } - } - return false; -} - -CALLER_ATTACH NameTable::NameEntry* NameTable::NameEntryIterator::Next() { - if (!HasNext()) - return NULL; - return table_->GetNameEntry(name_index_++); -} - -void NameTable::NameEntryIterator::Remove() { -#if !defined (SFNTLY_NO_EXCEPTION) - throw UnsupportedOperationException( - "Cannot remove a CMap table from an existing font."); -#endif -} - -void NameTable::NameEntryIterator::Init(NameTable* table, - NameEntryFilter* filter) { - table_ = table; - filter_ = filter; - name_index_ = 0; -} - -/****************************************************************************** - * NameTable::Builder class - ******************************************************************************/ -NameTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data) - : Table::ArrayElementTableBuilder(font_builder, header, data) { -} - -NameTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data) - : Table::ArrayElementTableBuilder(font_builder, header, data) { -} - -void NameTable::Builder::RevertNames() { - name_entry_map_.clear(); - set_model_changed(false); -} - -int32_t NameTable::Builder::BuilderCount() { - GetNameBuilders(); // Ensure name_entry_map_ is built. - return (int32_t)name_entry_map_.size(); -} - -bool NameTable::Builder::Has(int32_t platform_id, - int32_t encoding_id, - int32_t language_id, - int32_t name_id) { - NameEntryId probe(platform_id, encoding_id, language_id, name_id); - GetNameBuilders(); // Ensure name_entry_map_ is built. - return (name_entry_map_.find(probe) != name_entry_map_.end()); -} - -CALLER_ATTACH NameTable::NameEntryBuilder* - NameTable::Builder::NameBuilder(int32_t platform_id, - int32_t encoding_id, - int32_t language_id, - int32_t name_id) { - NameEntryId probe(platform_id, encoding_id, language_id, name_id); - NameEntryBuilderMap builders; - GetNameBuilders(); // Ensure name_entry_map_ is built. - if (name_entry_map_.find(probe) != name_entry_map_.end()) { - return name_entry_map_[probe]; - } - NameEntryBuilderPtr builder = new NameEntryBuilder(probe); - name_entry_map_[probe] = builder; - return builder.Detach(); -} - -bool NameTable::Builder::Remove(int32_t platform_id, - int32_t encoding_id, - int32_t language_id, - int32_t name_id) { - NameEntryId probe(platform_id, encoding_id, language_id, name_id); - GetNameBuilders(); // Ensure name_entry_map_ is built. - NameEntryBuilderMap::iterator position = name_entry_map_.find(probe); - if (position != name_entry_map_.end()) { - name_entry_map_.erase(position); - return true; - } - return false; -} - -CALLER_ATTACH FontDataTable* - NameTable::Builder::SubBuildTable(ReadableFontData* data) { - FontDataTablePtr table = new NameTable(header(), data); - return table.Detach(); -} - -void NameTable::Builder::SubDataSet() { - name_entry_map_.clear(); - set_model_changed(false); -} - -int32_t NameTable::Builder::SubDataSizeToSerialize() { - if (name_entry_map_.empty()) { - return 0; - } - - int32_t size = NameTable::Offset::kNameRecordStart + - name_entry_map_.size() * NameTable::Offset::kNameRecordSize; - for (NameEntryBuilderMap::iterator b = name_entry_map_.begin(), - end = name_entry_map_.end(); - b != end; ++b) { - NameEntryBuilderPtr p = b->second; - NameEntry* entry = p->name_entry(); - size += entry->NameBytesLength(); - } - return size; -} - -bool NameTable::Builder::SubReadyToSerialize() { - return !name_entry_map_.empty(); -} - -int32_t NameTable::Builder::SubSerialize(WritableFontData* new_data) { - int32_t string_table_start_offset = - NameTable::Offset::kNameRecordStart + - name_entry_map_.size() * NameTable::Offset::kNameRecordSize; - - // Header - new_data->WriteUShort(NameTable::Offset::kFormat, 0); - new_data->WriteUShort(NameTable::Offset::kCount, name_entry_map_.size()); - new_data->WriteUShort(NameTable::Offset::kStringOffset, - string_table_start_offset); - int32_t name_record_offset = NameTable::Offset::kNameRecordStart; - int32_t string_offset = 0; - // Note: we offered operator< in NameEntryId, which will be used by std::less, - // and therefore our map will act like TreeMap in Java to provide - // sorted key set. - for (NameEntryBuilderMap::iterator b = name_entry_map_.begin(), - end = name_entry_map_.end(); - b != end; ++b) { - new_data->WriteUShort( - name_record_offset + NameTable::Offset::kNameRecordPlatformId, - b->first.platform_id()); - new_data->WriteUShort( - name_record_offset + NameTable::Offset::kNameRecordEncodingId, - b->first.encoding_id()); - new_data->WriteUShort( - name_record_offset + NameTable::Offset::kNameRecordLanguageId, - b->first.language_id()); - new_data->WriteUShort( - name_record_offset + NameTable::Offset::kNameRecordNameId, - b->first.name_id()); - NameEntry* builder_entry = b->second->name_entry(); - new_data->WriteUShort( - name_record_offset + NameTable::Offset::kNameRecordStringLength, - builder_entry->NameBytesLength()); - new_data->WriteUShort( - name_record_offset + NameTable::Offset::kNameRecordStringOffset, - string_offset); - name_record_offset += NameTable::Offset::kNameRecordSize; - string_offset += new_data->WriteBytes( - string_offset + string_table_start_offset, - builder_entry->NameAsBytes()); - } - - return string_offset + string_table_start_offset; -} - -void NameTable::Builder::Initialize(ReadableFontData* data) { - if (data) { - NameTablePtr table = new NameTable(header(), data); - NameEntryIterator name_iter(table, NULL); - while (name_iter.HasNext()) { - NameEntryPtr name_entry; - name_entry.Attach(name_iter.Next()); - NameEntryBuilderPtr name_entry_builder = new NameEntryBuilder(name_entry); - NameEntry* builder_entry = name_entry_builder->name_entry(); - NameEntryId probe = builder_entry->name_entry_id(); - name_entry_map_[probe] = name_entry_builder; - } - } -} - -NameTable::NameEntryBuilderMap* NameTable::Builder::GetNameBuilders() { - if (name_entry_map_.empty()) { - Initialize(InternalReadData()); - } - set_model_changed(); - return &name_entry_map_; -} - -/****************************************************************************** - * NameTable class - ******************************************************************************/ -NameTable::~NameTable() {} - -int32_t NameTable::Format() { - return data_->ReadUShort(Offset::kFormat); -} - -int32_t NameTable::NameCount() { - return data_->ReadUShort(Offset::kCount); -} - -int32_t NameTable::PlatformId(int32_t index) { - return data_->ReadUShort(Offset::kNameRecordPlatformId + - OffsetForNameRecord(index)); -} - -int32_t NameTable::EncodingId(int32_t index) { - return data_->ReadUShort(Offset::kNameRecordEncodingId + - OffsetForNameRecord(index)); -} - -int32_t NameTable::LanguageId(int32_t index) { - return data_->ReadUShort(Offset::kNameRecordLanguageId + - OffsetForNameRecord(index)); -} - -int32_t NameTable::NameId(int32_t index) { - return data_->ReadUShort(Offset::kNameRecordNameId + - OffsetForNameRecord(index)); -} - -void NameTable::NameAsBytes(int32_t index, ByteVector* b) { - assert(b); - int32_t length = NameLength(index); - b->clear(); - b->resize(length); - data_->ReadBytes(NameOffset(index), &((*b)[0]), 0, length); -} - -void NameTable::NameAsBytes(int32_t platform_id, - int32_t encoding_id, - int32_t language_id, - int32_t name_id, - ByteVector* b) { - assert(b); - NameEntryPtr entry; - entry.Attach(GetNameEntry(platform_id, encoding_id, language_id, name_id)); - if (entry) { - ByteVector* name = entry->NameAsBytes(); - std::copy(name->begin(), name->end(), b->begin()); - } -} - -UChar* NameTable::Name(int32_t index) { - ByteVector b; - NameAsBytes(index, &b); - return ConvertFromNameBytes(&b, PlatformId(index), EncodingId(index)); -} - -UChar* NameTable::Name(int32_t platform_id, - int32_t encoding_id, - int32_t language_id, - int32_t name_id) { - NameEntryPtr entry; - entry.Attach(GetNameEntry(platform_id, encoding_id, language_id, name_id)); - if (entry) { - return entry->Name(); - } - return NULL; -} - -CALLER_ATTACH NameTable::NameEntry* NameTable::GetNameEntry(int32_t index) { - ByteVector b; - NameAsBytes(index, &b); - NameEntryPtr instance = new NameEntry(PlatformId(index), - EncodingId(index), - LanguageId(index), - NameId(index), b); - return instance.Detach(); -} - -CALLER_ATTACH NameTable::NameEntry* NameTable::GetNameEntry(int32_t platform_id, - int32_t encoding_id, - int32_t language_id, - int32_t name_id) { - NameTable::NameEntryFilterInPlace - filter(platform_id, encoding_id, language_id, name_id); - NameTable::NameEntryIterator* name_entry_iter = Iterator(&filter); - NameEntryPtr result; - if (name_entry_iter->HasNext()) { - result = name_entry_iter->Next(); - } - delete name_entry_iter; - return result; -} - -NameTable::NameEntryIterator* NameTable::Iterator() { - return new NameTable::NameEntryIterator(this); -} - -NameTable::NameEntryIterator* NameTable::Iterator(NameEntryFilter* filter) { - return new NameTable::NameEntryIterator(this, filter); -} - -NameTable::NameTable(Header* header, ReadableFontData* data) - : Table(header, data) {} - -int32_t NameTable::StringOffset() { - return data_->ReadUShort(Offset::kStringOffset); -} - -int32_t NameTable::OffsetForNameRecord(int32_t index) { - return Offset::kNameRecordStart + index * Offset::kNameRecordSize; -} - -int32_t NameTable::NameLength(int32_t index) { - return data_->ReadUShort(Offset::kNameRecordStringLength + - OffsetForNameRecord(index)); -} - -int32_t NameTable::NameOffset(int32_t index) { - return data_->ReadUShort(Offset::kNameRecordStringOffset + - OffsetForNameRecord(index)) + StringOffset(); -} - -const char* NameTable::GetEncodingName(int32_t platform_id, - int32_t encoding_id) { - switch (platform_id) { - case PlatformId::kUnicode: - return "UTF-16BE"; - case PlatformId::kMacintosh: - switch (encoding_id) { - case MacintoshEncodingId::kRoman: - return "MacRoman"; - case MacintoshEncodingId::kJapanese: - return "Shift-JIS"; - case MacintoshEncodingId::kChineseTraditional: - return "Big5"; - case MacintoshEncodingId::kKorean: - return "EUC-KR"; - case MacintoshEncodingId::kArabic: - return "MacArabic"; - case MacintoshEncodingId::kHebrew: - return "MacHebrew"; - case MacintoshEncodingId::kGreek: - return "MacGreek"; - case MacintoshEncodingId::kRussian: - return "MacCyrillic"; - case MacintoshEncodingId::kRSymbol: - return "MacSymbol"; - case MacintoshEncodingId::kThai: - return "MacThai"; - case MacintoshEncodingId::kChineseSimplified: - return "EUC-CN"; - default: // Note: unknown/unconfirmed cases are not ported. - break; - } - break; - case PlatformId::kISO: - break; - case PlatformId::kWindows: - switch (encoding_id) { - case WindowsEncodingId::kSymbol: - case WindowsEncodingId::kUnicodeUCS2: - return "UTF-16BE"; - case WindowsEncodingId::kShiftJIS: - return "windows-933"; - case WindowsEncodingId::kPRC: - return "windows-936"; - case WindowsEncodingId::kBig5: - return "windows-950"; - case WindowsEncodingId::kWansung: - return "windows-949"; - case WindowsEncodingId::kJohab: - return "ms1361"; - case WindowsEncodingId::kUnicodeUCS4: - return "UCS-4"; - } - break; - case PlatformId::kCustom: - break; - default: - break; - } - return NULL; -} - -UConverter* NameTable::GetCharset(int32_t platform_id, int32_t encoding_id) { - UErrorCode error_code = U_ZERO_ERROR; - UConverter* conv = ucnv_open(GetEncodingName(platform_id, encoding_id), - &error_code); - if (U_SUCCESS(error_code)) { - return conv; - } - - if (conv) { - ucnv_close(conv); - } - return NULL; -} - -void NameTable::ConvertToNameBytes(const UChar* name, - int32_t platform_id, - int32_t encoding_id, - ByteVector* b) { - assert(b); - assert(name); - b->clear(); - UConverter* cs = GetCharset(platform_id, encoding_id); - if (cs == NULL) { - return; - } - - // Preflight to get buffer size. - UErrorCode error_code = U_ZERO_ERROR; - int32_t length = ucnv_fromUChars(cs, NULL, 0, name, -1, &error_code); - b->resize(length + 4); // The longest termination "\0" is 4 bytes. - memset(&((*b)[0]), 0, length + 4); - error_code = U_ZERO_ERROR; - ucnv_fromUChars(cs, - reinterpret_cast(&((*b)[0])), - length + 4, - name, - -1, - &error_code); - if (!U_SUCCESS(error_code)) { - b->clear(); - } - ucnv_close(cs); -} - -UChar* NameTable::ConvertFromNameBytes(ByteVector* name_bytes, - int32_t platform_id, - int32_t encoding_id) { - if (name_bytes == NULL) { - return NULL; - } - UConverter* cs = GetCharset(platform_id, encoding_id); - UErrorCode error_code = U_ZERO_ERROR; - if (cs == NULL) { - char buffer[11] = {0}; -#if defined (WIN32) - _itoa_s(platform_id, buffer, 16); -#else - snprintf(buffer, sizeof(buffer), "%x", platform_id); -#endif - UChar* result = new UChar[12]; - memset(result, 0, sizeof(UChar) * 12); - cs = ucnv_open("utf-8", &error_code); - if (U_SUCCESS(error_code)) { - ucnv_toUChars(cs, result, 12, buffer, 11, &error_code); - ucnv_close(cs); - if (U_SUCCESS(error_code)) { - return result; - } - } - delete[] result; - return NULL; - } - - // No preflight needed here, we will be bigger. - UChar* output_buffer = new UChar[name_bytes->size() + 1]; - memset(output_buffer, 0, sizeof(UChar) * (name_bytes->size() + 1)); - int32_t length = ucnv_toUChars(cs, - output_buffer, - name_bytes->size(), - reinterpret_cast(&((*name_bytes)[0])), - name_bytes->size(), - &error_code); - ucnv_close(cs); - if (length > 0) { - return output_buffer; - } - - delete[] output_buffer; - return NULL; -} - -} // namespace sfntly diff --git a/sfntly/name_table.h b/sfntly/name_table.h deleted file mode 100644 index 64353d6..0000000 --- a/sfntly/name_table.h +++ /dev/null @@ -1,737 +0,0 @@ -/* - * 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. - */ - -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_NAME_TABLE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_NAME_TABLE_H_ - -// Must include this before ICU to avoid stdint redefinition issue. -#include "sfntly/port/type.h" - -#include -#include - -#include -#include - -#include "sfntly/table.h" - -#if defined U_USING_ICU_NAMESPACE - U_NAMESPACE_USE -#endif - -namespace sfntly { - -// The following code implements the name table defined in TTF/OTF spec, which -// can be found at http://www.microsoft.com/typography/otspec/name.htm. - -// Name IDs defined in TTF/OTF spec. -struct NameId { - enum { - kUnknown = -1, - kCopyrightNotice = 0, - kFontFamilyName = 1, - kFontSubfamilyName = 2, - kUniqueFontIdentifier = 3, - kFullFontName = 4, - kVersionString = 5, - kPostscriptName = 6, - kTrademark = 7, - kManufacturerName = 8, - kDesigner = 9, - kDescription = 10, - kVendorURL = 11, - kDesignerURL = 12, - kLicenseDescription = 13, - kLicenseInfoURL = 14, - kReserved15 = 15, - kPreferredFamily = 16, - kPreferredSubfamily = 17, - kCompatibleFullName = 18, - kSampleText = 19, - kPostscriptCID = 20, - kWWSFamilyName = 21, - kWWSSubfamilyName = 22 - }; -}; - -// Unicode language IDs used in Name Records. -struct UnicodeLanguageId { - enum { - kUnknown = -1, - kAll = 0 - }; -}; - -// Macintosh Language IDs (platform ID = 1) -struct MacintoshLanguageId { - enum { - kUnknown = -1, - kEnglish = 0, - kFrench = 1, - kGerman = 2, - kItalian = 3, - kDutch = 4, - kSwedish = 5, - kSpanish = 6, - kDanish = 7, - kPortuguese = 8, - kNorwegian = 9, - kHebrew = 10, - kJapanese = 11, - kArabic = 12, - kFinnish = 13, - kGreek = 14, - kIcelandic = 15, - kMaltese = 16, - kTurkish = 17, - kCroatian = 18, - kChinese_Traditional = 19, - kUrdu = 20, - kHindi = 21, - kThai = 22, - kKorean = 23, - kLithuanian = 24, - kPolish = 25, - kHungarian = 26, - kEstonian = 27, - kLatvian = 28, - kSami = 29, - kFaroese = 30, - kFarsiPersian = 31, - kRussian = 32, - kChinese_Simplified = 33, - kFlemish = 34, - kIrishGaelic = 35, - kAlbanian = 36, - kRomanian = 37, - kCzech = 38, - kSlovak = 39, - kSlovenian = 40, - kYiddish = 41, - kSerbian = 42, - kMacedonian = 43, - kBulgarian = 44, - kUkrainian = 45, - kByelorussian = 46, - kUzbek = 47, - kKazakh = 48, - kAzerbaijani_Cyrillic = 49, - kAzerbaijani_Arabic = 50, - kArmenian = 51, - kGeorgian = 52, - kMoldavian = 53, - kKirghiz = 54, - kTajiki = 55, - kTurkmen = 56, - kMongolian_Mongolian = 57, - kMongolian_Cyrillic = 58, - kPashto = 59, - kKurdish = 60, - kKashmiri = 61, - kSindhi = 62, - kTibetan = 63, - kNepali = 64, - kSanskrit = 65, - kMarathi = 66, - kBengali = 67, - kAssamese = 68, - kGujarati = 69, - kPunjabi = 70, - kOriya = 71, - kMalayalam = 72, - kKannada = 73, - kTamil = 74, - kTelugu = 75, - kSinhalese = 76, - kBurmese = 77, - kKhmer = 78, - kLao = 79, - kVietnamese = 80, - kIndonesian = 81, - kTagalong = 82, - kMalay_Roman = 83, - kMalay_Arabic = 84, - kAmharic = 85, - kTigrinya = 86, - kGalla = 87, - kSomali = 88, - kSwahili = 89, - kKinyarwandaRuanda = 90, - kRundi = 91, - kNyanjaChewa = 92, - kMalagasy = 93, - kEsperanto = 94, - kWelsh = 128, - kBasque = 129, - kCatalan = 130, - kLatin = 131, - kQuenchua = 132, - kGuarani = 133, - kAymara = 134, - kTatar = 135, - kUighur = 136, - kDzongkha = 137, - kJavanese_Roman = 138, - kSundanese_Roman = 139, - kGalician = 140, - kAfrikaans = 141, - kBreton = 142, - kInuktitut = 143, - kScottishGaelic = 144, - kManxGaelic = 145, - kIrishGaelic_WithDotAbove = 146, - kTongan = 147, - kGreek_Polytonic = 148, - kGreenlandic = 149, - kAzerbaijani_Roman = 150 - }; -}; - -// Windows Language IDs (platformID = 3) -struct WindowsLanguageId { - enum { - kUnknown = -1, - kAfrikaans_SouthAfrica = 0x0436, - kAlbanian_Albania = 0x041C, - kAlsatian_France = 0x0484, - kAmharic_Ethiopia = 0x045E, - kArabic_Algeria = 0x1401, - kArabic_Bahrain = 0x3C01, - kArabic_Egypt = 0x0C01, - kArabic_Iraq = 0x0801, - kArabic_Jordan = 0x2C01, - kArabic_Kuwait = 0x3401, - kArabic_Lebanon = 0x3001, - kArabic_Libya = 0x1001, - kArabic_Morocco = 0x1801, - kArabic_Oman = 0x2001, - kArabic_Qatar = 0x4001, - kArabic_SaudiArabia = 0x0401, - kArabic_Syria = 0x2801, - kArabic_Tunisia = 0x1C01, - kArabic_UAE = 0x3801, - kArabic_Yemen = 0x2401, - kArmenian_Armenia = 0x042B, - kAssamese_India = 0x044D, - kAzeri_Cyrillic_Azerbaijan = 0x082C, - kAzeri_Latin_Azerbaijan = 0x042C, - kBashkir_Russia = 0x046D, - kBasque_Basque = 0x042D, - kBelarusian_Belarus = 0x0423, - kBengali_Bangladesh = 0x0845, - kBengali_India = 0x0445, - kBosnian_Cyrillic_BosniaAndHerzegovina = 0x201A, - kBosnian_Latin_BosniaAndHerzegovina = 0x141A, - kBreton_France = 0x047E, - kBulgarian_Bulgaria = 0x0402, - kCatalan_Catalan = 0x0403, - kChinese_HongKongSAR = 0x0C04, - kChinese_MacaoSAR = 0x1404, - kChinese_PeoplesRepublicOfChina = 0x0804, - kChinese_Singapore = 0x1004, - kChinese_Taiwan = 0x0404, - kCorsican_France = 0x0483, - kCroatian_Croatia = 0x041A, - kCroatian_Latin_BosniaAndHerzegovina = 0x101A, - kCzech_CzechRepublic = 0x0405, - kDanish_Denmark = 0x0406, - kDari_Afghanistan = 0x048C, - kDivehi_Maldives = 0x0465, - kDutch_Belgium = 0x0813, - kDutch_Netherlands = 0x0413, - kEnglish_Australia = 0x0C09, - kEnglish_Belize = 0x2809, - kEnglish_Canada = 0x1009, - kEnglish_Caribbean = 0x2409, - kEnglish_India = 0x4009, - kEnglish_Ireland = 0x1809, - kEnglish_Jamaica = 0x2009, - kEnglish_Malaysia = 0x4409, - kEnglish_NewZealand = 0x1409, - kEnglish_RepublicOfThePhilippines = 0x3409, - kEnglish_Singapore = 0x4809, - kEnglish_SouthAfrica = 0x1C09, - kEnglish_TrinidadAndTobago = 0x2C09, - kEnglish_UnitedKingdom = 0x0809, - kEnglish_UnitedStates = 0x0409, - kEnglish_Zimbabwe = 0x3009, - kEstonian_Estonia = 0x0425, - kFaroese_FaroeIslands = 0x0438, - kFilipino_Philippines = 0x0464, - kFinnish_Finland = 0x040B, - kFrench_Belgium = 0x080C, - kFrench_Canada = 0x0C0C, - kFrench_France = 0x040C, - kFrench_Luxembourg = 0x140c, - kFrench_PrincipalityOfMonoco = 0x180C, - kFrench_Switzerland = 0x100C, - kFrisian_Netherlands = 0x0462, - kGalician_Galician = 0x0456, - kGeorgian_Georgia = 0x0437, - kGerman_Austria = 0x0C07, - kGerman_Germany = 0x0407, - kGerman_Liechtenstein = 0x1407, - kGerman_Luxembourg = 0x1007, - kGerman_Switzerland = 0x0807, - kGreek_Greece = 0x0408, - kGreenlandic_Greenland = 0x046F, - kGujarati_India = 0x0447, - kHausa_Latin_Nigeria = 0x0468, - kHebrew_Israel = 0x040D, - kHindi_India = 0x0439, - kHungarian_Hungary = 0x040E, - kIcelandic_Iceland = 0x040F, - kIgbo_Nigeria = 0x0470, - kIndonesian_Indonesia = 0x0421, - kInuktitut_Canada = 0x045D, - kInuktitut_Latin_Canada = 0x085D, - kIrish_Ireland = 0x083C, - kisiXhosa_SouthAfrica = 0x0434, - kisiZulu_SouthAfrica = 0x0435, - kItalian_Italy = 0x0410, - kItalian_Switzerland = 0x0810, - kJapanese_Japan = 0x0411, - kKannada_India = 0x044B, - kKazakh_Kazakhstan = 0x043F, - kKhmer_Cambodia = 0x0453, - kKiche_Guatemala = 0x0486, - kKinyarwanda_Rwanda = 0x0487, - kKiswahili_Kenya = 0x0441, - kKonkani_India = 0x0457, - kKorean_Korea = 0x0412, - kKyrgyz_Kyrgyzstan = 0x0440, - kLao_LaoPDR = 0x0454, - kLatvian_Latvia = 0x0426, - kLithuanian_Lithuania = 0x0427, - kLowerSorbian_Germany = 0x082E, - kLuxembourgish_Luxembourg = 0x046E, - kMacedonian_FYROM_FormerYugoslavRepublicOfMacedonia = 0x042F, - kMalay_BruneiDarussalam = 0x083E, - kMalay_Malaysia = 0x043E, - kMalayalam_India = 0x044C, - kMaltese_Malta = 0x043A, - kMaori_NewZealand = 0x0481, - kMapudungun_Chile = 0x047A, - kMarathi_India = 0x044E, - kMohawk_Mohawk = 0x047C, - kMongolian_Cyrillic_Mongolia = 0x0450, - kMongolian_Traditional_PeoplesRepublicOfChina = 0x0850, - kNepali_Nepal = 0x0461, - kNorwegian_Bokmal_Norway = 0x0414, - kNorwegian_Nynorsk_Norway = 0x0814, - kOccitan_France = 0x0482, - kOriya_India = 0x0448, - kPashto_Afghanistan = 0x0463, - kPolish_Poland = 0x0415, - kPortuguese_Brazil = 0x0416, - kPortuguese_Portugal = 0x0816, - kPunjabi_India = 0x0446, - kQuechua_Bolivia = 0x046B, - kQuechua_Ecuador = 0x086B, - kQuechua_Peru = 0x0C6B, - kRomanian_Romania = 0x0418, - kRomansh_Switzerland = 0x0417, - kRussian_Russia = 0x0419, - kSami_Inari_Finland = 0x243B, - kSami_Lule_Norway = 0x103B, - kSami_Lule_Sweden = 0x143B, - kSami_Northern_Finland = 0x0C3B, - kSami_Northern_Norway = 0x043B, - kSami_Northern_Sweden = 0x083B, - kSami_Skolt_Finland = 0x203B, - kSami_Southern_Norway = 0x183B, - kSami_Southern_Sweden = 0x1C3B, - kSanskrit_India = 0x044F, - kSerbian_Cyrillic_BosniaAndHerzegovina = 0x1C1A, - kSerbian_Cyrillic_Serbia = 0x0C1A, - kSerbian_Latin_BosniaAndHerzegovina = 0x181A, - kSerbian_Latin_Serbia = 0x081A, - kSesothoSaLeboa_SouthAfrica = 0x046C, - kSetswana_SouthAfrica = 0x0432, - kSinhala_SriLanka = 0x045B, - kSlovak_Slovakia = 0x041B, - kSlovenian_Slovenia = 0x0424, - kSpanish_Argentina = 0x2C0A, - kSpanish_Bolivia = 0x400A, - kSpanish_Chile = 0x340A, - kSpanish_Colombia = 0x240A, - kSpanish_CostaRica = 0x140A, - kSpanish_DominicanRepublic = 0x1C0A, - kSpanish_Ecuador = 0x300A, - kSpanish_ElSalvador = 0x440A, - kSpanish_Guatemala = 0x100A, - kSpanish_Honduras = 0x480A, - kSpanish_Mexico = 0x080A, - kSpanish_Nicaragua = 0x4C0A, - kSpanish_Panama = 0x180A, - kSpanish_Paraguay = 0x3C0A, - kSpanish_Peru = 0x280A, - kSpanish_PuertoRico = 0x500A, - kSpanish_ModernSort_Spain = 0x0C0A, - kSpanish_TraditionalSort_Spain = 0x040A, - kSpanish_UnitedStates = 0x540A, - kSpanish_Uruguay = 0x380A, - kSpanish_Venezuela = 0x200A, - kSweden_Finland = 0x081D, - kSwedish_Sweden = 0x041D, - kSyriac_Syria = 0x045A, - kTajik_Cyrillic_Tajikistan = 0x0428, - kTamazight_Latin_Algeria = 0x085F, - kTamil_India = 0x0449, - kTatar_Russia = 0x0444, - kTelugu_India = 0x044A, - kThai_Thailand = 0x041E, - kTibetan_PRC = 0x0451, - kTurkish_Turkey = 0x041F, - kTurkmen_Turkmenistan = 0x0442, - kUighur_PRC = 0x0480, - kUkrainian_Ukraine = 0x0422, - kUpperSorbian_Germany = 0x042E, - kUrdu_IslamicRepublicOfPakistan = 0x0420, - kUzbek_Cyrillic_Uzbekistan = 0x0843, - kUzbek_Latin_Uzbekistan = 0x0443, - kVietnamese_Vietnam = 0x042A, - kWelsh_UnitedKingdom = 0x0452, - kWolof_Senegal = 0x0448, - kYakut_Russia = 0x0485, - kYi_PRC = 0x0478, - kYoruba_Nigeria = 0x046A - }; -}; - -class NameTable : public Table, public RefCounted { - public: - // Unique identifier for a given name record. - class NameEntryId { - public: - NameEntryId(); // C++ port only, must provide default constructor. - NameEntryId(int32_t platform_id, int32_t encoding_id, int32_t language_id, - int32_t name_id); - NameEntryId(const NameEntryId&); - // Make gcc -Wnon-virtual-dtor happy. - virtual ~NameEntryId() {} - - int32_t platform_id() const { return platform_id_; } - int32_t encoding_id() const { return encoding_id_; } - int32_t language_id() const { return language_id_; } - int32_t name_id() const { return name_id_; } - - const NameEntryId& operator=(const NameEntryId& rhs) const; - bool operator==(const NameEntryId& rhs) const; - bool operator<(const NameEntryId& rhs) const; - - private: - mutable int32_t platform_id_; - mutable int32_t encoding_id_; - mutable int32_t language_id_; - mutable int32_t name_id_; - }; - - class NameEntryBuilder; - - // Class to represent a name entry in the name table. - class NameEntry : public RefCounted { - public: - NameEntry(); - NameEntry(const NameEntryId& name_entry_id, const ByteVector& name_bytes); - NameEntry(int32_t platform_id, int32_t encoding_id, int32_t language_id, - int32_t name_id, const ByteVector& name_bytes); - virtual ~NameEntry(); - - NameEntryId& name_entry_id() { return name_entry_id_; } - int32_t platform_id() const { return name_entry_id_.platform_id(); } - int32_t encoding_id() const { return name_entry_id_.encoding_id(); } - int32_t language_id() const { return name_entry_id_.language_id(); } - int32_t name_id() const { return name_entry_id_.name_id(); } - - // Get the bytes for name. Returned pointer is the address of private - // member of this class, do not attempt to delete. - ByteVector* NameAsBytes(); - - // C++ port only: get the length of NameAsBytes. - int32_t NameBytesLength(); - - // Returns the name in Unicode as UChar array. - // Note: ICU UChar* convention requires caller to delete[] it. - UChar* Name(); - bool operator==(const NameEntry& rhs) const; - - private: - void Init(int32_t platform_id, int32_t encoding_id, int32_t language_id, - int32_t name_id, const ByteVector* name_bytes); - - NameEntryId name_entry_id_; - int32_t length_; - ByteVector name_bytes_; - - friend class NameEntryBuilder; - }; - - // Builder of a name entry. - // C++ port: original Java hierarchy inherits from NameEntry. In C++ port, we - // opted not doing so to avoid ref count issues and nasty protected members. - class NameEntryBuilder : public RefCounted { - public: - NameEntryBuilder(); - NameEntryBuilder(const NameEntryId& name_entry_id, - const ByteVector& name_bytes); - explicit NameEntryBuilder(const NameEntryId& name_entry_id); - explicit NameEntryBuilder(NameEntry* entry); - virtual ~NameEntryBuilder(); - - virtual void SetName(const UChar* name); - virtual void SetName(const ByteVector& name_bytes); - virtual void SetName(const ByteVector& name_bytes, int32_t offset, - int32_t length); - - // C++ port only. CALLER_ATTACH is not added because the lifetime shall be - // controlled by this class, therefore the caller shall not increase the ref - // count. - NameEntry* name_entry() { return name_entry_; } - - private: - void Init(int32_t platform_id, int32_t encoding_id, int32_t language_id, - int32_t name_id, const ByteVector* name_bytes); - - Ptr name_entry_; - }; - typedef std::map > NameEntryBuilderMap; - - // An interface for a filter to use with the name entry iterator. This allows - // name entries to be iterated and only those acceptable to the filter will be - // returned. - class NameEntryFilter { - public: - virtual bool Accept(int32_t platform_id, int32_t encoding_id, - int32_t language_id, int32_t name_id) = 0; - // Make gcc -Wnon-virtual-dtor happy. - virtual ~NameEntryFilter() {} - }; - - // C++ port only: an in-place filter to mimic Java Iterator's filtering. - class NameEntryFilterInPlace : public NameEntryFilter { - public: - NameEntryFilterInPlace(int32_t platform_id, int32_t encoding_id, - int32_t language_id, int32_t name_id); - // Make gcc -Wnon-virtual-dtor happy. - virtual ~NameEntryFilterInPlace() {} - - virtual bool Accept(int32_t platform_id, int32_t encoding_id, - int32_t language_id, int32_t name_id); - - private: - int32_t platform_id_; - int32_t encoding_id_; - int32_t language_id_; - int32_t name_id_; - }; - - // Mimic Java's iterator to iterate through the entries within the name table. - class NameEntryIterator { - public: - // If filter is NULL, filter through all tables. - explicit NameEntryIterator(NameTable* table); - NameEntryIterator(NameTable* table, NameEntryFilter* filter); - // Make gcc -Wnon-virtual-dtor happy. - virtual ~NameEntryIterator() {} - - virtual bool HasNext(); - virtual CALLER_ATTACH NameEntry* Next(); - virtual void Remove(); - - private: - void Init(NameTable* table, NameEntryFilter* filter); - - NameTable* table_; // Use dumb pointer since it's a composition object. - int32_t name_index_; - NameEntryFilter* filter_; - }; - - // The builder to construct name table for outputting. - class Builder : public Table::ArrayElementTableBuilder, - public RefCounted { - public: - // Constructor scope altered to public because C++ does not allow base - // class to instantiate derived class with protected constructors. - Builder(FontDataTableBuilderContainer* font_builder, Header* header, - WritableFontData* data); - Builder(FontDataTableBuilderContainer* font_builder, Header* header, - ReadableFontData* data); - - // Revert the name builders for the name table to the last version that came - // from data. - void RevertNames(); - - // Number of name entry builders contained. - int32_t BuilderCount(); - - // Note: For C++ port, clear() is not implemented. The clear() function - // implies completely remove name entry builders, which is easy in - // Java but will take a lot of efforts in C++ to release the builders - // nicely and correctly. - // TODO(arthurhsu): IMPLEMENT - // Clear the name builders for the name table. - // void clear(); - - // Check the existance of a name entry builder by key. - bool Has(int32_t platform_id, int32_t encoding_id, int32_t language_id, - int32_t name_id); - - // Get name entry builder by key. - CALLER_ATTACH NameEntryBuilder* NameBuilder(int32_t platform_id, - int32_t encoding_id, int32_t language_id, int32_t name_id); - - // Remove name entry builder by key. - bool Remove(int32_t platform_id, int32_t encoding_id, int32_t language_id, - int32_t name_id); - - // FontDataTable::Builder API implementation - virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); - virtual void SubDataSet(); - virtual int32_t SubDataSizeToSerialize(); - virtual bool SubReadyToSerialize(); - virtual int32_t SubSerialize(WritableFontData* new_data); - - private: - void Initialize(ReadableFontData* data); - NameEntryBuilderMap* GetNameBuilders(); - - // Note: callers should use the getter funtion provided above to ensure that - // this is lazily initialized instead of accessing directly. - NameEntryBuilderMap name_entry_map_; - }; - - /**************************************************************************** - * public methods of NameTable class - ****************************************************************************/ - virtual ~NameTable(); - - // Get the format used in the name table. - virtual int32_t Format(); - - // Get the number of names in the name table. - virtual int32_t NameCount(); - - // Get the platform id for the given name record. - virtual int32_t PlatformId(int32_t index); - - // Get the encoding id for the given name record. - // see MacintoshEncodingId, WindowsEncodingId, UnicodeEncodingId - virtual int32_t EncodingId(int32_t index); - - // Get the language id for the given name record. - virtual int32_t LanguageId(int32_t index); - - // Get the name id for given name record. - virtual int32_t NameId(int32_t index); - - // Get the name as bytes for the specified name. If there is no entry for the - // requested name, then empty vector is returned. - virtual void NameAsBytes(int32_t index, ByteVector* b); - virtual void NameAsBytes(int32_t platform_id, int32_t encoding_id, - int32_t language_id, int32_t name_id, - ByteVector* b); - - // Get the name as a UChar* for the given name record. If there is no - // encoding conversion available for the name record then a best attempt - // UChar* will be returned. - // Note: ICU UChar* convention requires caller to delete[] it. - virtual UChar* Name(int32_t index); - - // Get the name as a UChar* for the specified name. If there is no entry for - // the requested name then NULL is returned. If there is no encoding - // conversion available for the name then a best attempt UChar* will be - // returned. - // Note: ICU UChar* convention requires caller to delete[] it. - virtual UChar* Name(int32_t platform_id, int32_t encoding_id, - int32_t language_id, int32_t name_id); - - // Note: These functions are renamed in C++ port. Their original Java name is - // nameEntry(). - virtual CALLER_ATTACH NameEntry* GetNameEntry(int32_t index); - virtual CALLER_ATTACH NameEntry* GetNameEntry(int32_t platform_id, - int32_t encoding_id, int32_t language_id, int32_t name_id); - - // Note: Not implemented in C++ port due to complexity and low usage. - // virtual void names(std::set*); - - // Get the iterator to iterate through all name entries. - // Note: Caller delete the returned object. - virtual NameEntryIterator* Iterator(); - virtual NameEntryIterator* Iterator(NameEntryFilter* filter); - - private: - struct Offset { - enum { - kFormat = 0, - kCount = 2, - kStringOffset = 4, - kNameRecordStart = 6, - - // Format 1 - offset from the end of the name records - kLangTagCount = 0, - kLangTagRecord = 2, - - kNameRecordSize = 12, - // Name Records - kNameRecordPlatformId = 0, - kNameRecordEncodingId = 2, - kNameRecordLanguageId = 4, - kNameRecordNameId = 6, - kNameRecordStringLength = 8, - kNameRecordStringOffset = 10 - }; - }; - - // The table shall be constructed using Builder, no direct instantiation. - NameTable(Header* header, ReadableFontData* data); - - // Get the offset to the string data in the name table. - int32_t StringOffset(); - - // Get the offset for the given name record. - int32_t OffsetForNameRecord(int32_t index); - - // Get the length of the string data for the given name record. - int32_t NameLength(int32_t index); - - // Get the offset of the string data for the given name record. - int32_t NameOffset(int32_t index); - - // Note: string literals are returned. Caller shall not attempt to manipulate - // the returned pointer. - static const char* GetEncodingName(int32_t platform_id, int32_t encoding_id); - - // Note: ICU UConverter* convention requires caller to ucnv_close() it. - static UConverter* GetCharset(int32_t platform_id, int32_t encoding_id); - - // Note: Output will be stored in ByteVector* b. Original data in b will be - // erased and replaced with converted name bytes. - static void ConvertToNameBytes(const UChar* name, int32_t platform_id, - int32_t encoding_id, ByteVector* b); - - // Note: ICU UChar* convention requires caller to delete[] it. - static UChar* ConvertFromNameBytes(ByteVector* name_bytes, - int32_t platform_id, int32_t encoding_id); -}; // class NameTable -typedef Ptr NameTablePtr; -typedef Ptr NameEntryPtr; -typedef Ptr NameTableBuilderPtr; -typedef Ptr NameEntryBuilderPtr; - -} // namespace sfntly - -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_NAME_TABLE_H_ diff --git a/sfntly/os2_table.cc b/sfntly/os2_table.cc deleted file mode 100644 index 24ef4e9..0000000 --- a/sfntly/os2_table.cc +++ /dev/null @@ -1,277 +0,0 @@ -/* - * 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 "sfntly/os2_table.h" - -namespace sfntly { -/****************************************************************************** - * Constants - ******************************************************************************/ -const int64_t CodePageRange::kLatin1_1252 = (int64_t)1 << 0; -const int64_t CodePageRange::kLatin2_1250 = (int64_t)1 << (int64_t)1; -const int64_t CodePageRange::kCyrillic_1251 = (int64_t)1 << 2; -const int64_t CodePageRange::kGreek_1253 = (int64_t)1 << 3; -const int64_t CodePageRange::kTurkish_1254 = (int64_t)1 << 4; -const int64_t CodePageRange::kHebrew_1255 = (int64_t)1 << 5; -const int64_t CodePageRange::kArabic_1256 = (int64_t)1 << 6; -const int64_t CodePageRange::kWindowsBaltic_1257 = (int64_t)1 << 7; -const int64_t CodePageRange::kVietnamese_1258 = (int64_t)1 << 8; -const int64_t CodePageRange::kAlternateANSI9 = (int64_t)1 << 9; -const int64_t CodePageRange::kAlternateANSI10 = (int64_t)1 << 10; -const int64_t CodePageRange::kAlternateANSI11 = (int64_t)1 << 11; -const int64_t CodePageRange::kAlternateANSI12 = (int64_t)1 << 12; -const int64_t CodePageRange::kAlternateANSI13 = (int64_t)1 << 13; -const int64_t CodePageRange::kAlternateANSI14 = (int64_t)1 << 14; -const int64_t CodePageRange::kAlternateANSI15 = (int64_t)1 << 15; -const int64_t CodePageRange::kThai_874 = (int64_t)1 << 16; -const int64_t CodePageRange::kJapanJIS_932 = (int64_t)1 << 17; -const int64_t CodePageRange::kChineseSimplified_936 = (int64_t)1 << 18; -const int64_t CodePageRange::kKoreanWansung_949 = (int64_t)1 << 19; -const int64_t CodePageRange::kChineseTraditional_950 = (int64_t)1 << 20; -const int64_t CodePageRange::kKoreanJohab_1361 = (int64_t)1 << 21; -const int64_t CodePageRange::kAlternateANSI22 = (int64_t)1 << 22; -const int64_t CodePageRange::kAlternateANSI23 = (int64_t)1 << 23; -const int64_t CodePageRange::kAlternateANSI24 = (int64_t)1 << 24; -const int64_t CodePageRange::kAlternateANSI25 = (int64_t)1 << 25; -const int64_t CodePageRange::kAlternateANSI26 = (int64_t)1 << 26; -const int64_t CodePageRange::kAlternateANSI27 = (int64_t)1 << 27; -const int64_t CodePageRange::kAlternateANSI28 = (int64_t)1 << 28; -const int64_t CodePageRange::kMacintoshCharacterSet = (int64_t)1 << 29; -const int64_t CodePageRange::kOEMCharacterSet = (int64_t)1 << 30; -const int64_t CodePageRange::kSymbolCharacterSet = (int64_t)1 << 31; -const int64_t CodePageRange::kReservedForOEM32 = (int64_t)1 << 32; -const int64_t CodePageRange::kReservedForOEM33 = (int64_t)1 << 33; -const int64_t CodePageRange::kReservedForOEM34 = (int64_t)1 << 34; -const int64_t CodePageRange::kReservedForOEM35 = (int64_t)1 << 35; -const int64_t CodePageRange::kReservedForOEM36 = (int64_t)1 << 36; -const int64_t CodePageRange::kReservedForOEM37 = (int64_t)1 << 37; -const int64_t CodePageRange::kReservedForOEM38 = (int64_t)1 << 38; -const int64_t CodePageRange::kReservedForOEM39 = (int64_t)1 << 39; -const int64_t CodePageRange::kReservedForOEM40 = (int64_t)1 << 40; -const int64_t CodePageRange::kReservedForOEM41 = (int64_t)1 << 41; -const int64_t CodePageRange::kReservedForOEM42 = (int64_t)1 << 42; -const int64_t CodePageRange::kReservedForOEM43 = (int64_t)1 << 43; -const int64_t CodePageRange::kReservedForOEM44 = (int64_t)1 << 44; -const int64_t CodePageRange::kReservedForOEM45 = (int64_t)1 << 45; -const int64_t CodePageRange::kReservedForOEM46 = (int64_t)1 << 46; -const int64_t CodePageRange::kReservedForOEM47 = (int64_t)1 << 47; -const int64_t CodePageRange::kIBMGreek_869 = (int64_t)1 << 48; -const int64_t CodePageRange::kMSDOSRussion_866 = (int64_t)1 << 49; -const int64_t CodePageRange::kMSDOSNordic_865 = (int64_t)1 << 50; -const int64_t CodePageRange::kArabic_864 = (int64_t)1 << 51; -const int64_t CodePageRange::kMSDOSCanadianFrench_863 = (int64_t)1 << 52; -const int64_t CodePageRange::kHebrew_862 = (int64_t)1 << 53; -const int64_t CodePageRange::kMSDOSIcelandic_861 = (int64_t)1 << 54; -const int64_t CodePageRange::kMSDOSPortugese_860 = (int64_t)1 << 55; -const int64_t CodePageRange::kIBMTurkish_857 = (int64_t)1 << 56; -const int64_t CodePageRange::kIBMCyrillic_855 = (int64_t)1 << 57; -const int64_t CodePageRange::kLatin2_852 = (int64_t)1 << 58; -const int64_t CodePageRange::kMSDOSBaltic_775 = (int64_t)1 << 59; -const int64_t CodePageRange::kGreek_737 = (int64_t)1 << 60; -const int64_t CodePageRange::kArabic_708 = (int64_t)1 << 61; -const int64_t CodePageRange::kLatin1_850 = (int64_t)1 << 62; -const int64_t CodePageRange::kUS_437 = (int64_t)1 << 63; - -/****************************************************************************** - * struct UnicodeRange - ******************************************************************************/ -int32_t UnicodeRange::range(int32_t bit) { - if (bit < 0 || bit > kLast) { - return -1; - } - return bit; -} - -/****************************************************************************** - * class OS2Table - ******************************************************************************/ -OS2Table::~OS2Table() {} - -int32_t OS2Table::Version() { - return data_->ReadUShort(Offset::kVersion); -} - -int32_t OS2Table::XAvgCharWidth() { - return data_->ReadShort(Offset::kXAvgCharWidth); -} - -int32_t OS2Table::UsWeightClass() { - return data_->ReadUShort(Offset::kUsWeightClass); -} - -int32_t OS2Table::UsWidthClass() { - return data_->ReadUShort(Offset::kUsWidthClass); -} - -int32_t OS2Table::FsType() { - return data_->ReadUShort(Offset::kFsType); -} - -int32_t OS2Table::YSubscriptXSize() { - return data_->ReadShort(Offset::kYSubscriptXSize); -} - -int32_t OS2Table::YSubscriptYSize() { - return data_->ReadShort(Offset::kYSubscriptYSize); -} - -int32_t OS2Table::YSubscriptXOffset() { - return data_->ReadShort(Offset::kYSubscriptXOffset); -} - -int32_t OS2Table::YSubscriptYOffset() { - return data_->ReadShort(Offset::kYSubscriptYOffset); -} - -int32_t OS2Table::YSuperscriptXSize() { - return data_->ReadShort(Offset::kYSuperscriptXSize); -} - -int32_t OS2Table::YSuperscriptYSize() { - return data_->ReadShort(Offset::kYSuperscriptYSize); -} - -int32_t OS2Table::YSuperscriptXOffset() { - return data_->ReadShort(Offset::kYSuperscriptXOffset); -} - -int32_t OS2Table::YSuperscriptYOffset() { - return data_->ReadShort(Offset::kYSuperscriptYOffset); -} - -int32_t OS2Table::YStrikeoutSize() { - return data_->ReadShort(Offset::kYStrikeoutSize); -} - -int32_t OS2Table::YStrikeoutPosition() { - return data_->ReadShort(Offset::kYStrikeoutPosition); -} - -int32_t OS2Table::SFamilyClass() { - return data_->ReadShort(Offset::kSFamilyClass); -} - -void OS2Table::Panose(ByteVector* value) { - value->clear(); - value->resize(10); - data_->ReadBytes(Offset::kPanose, &((*value)[0]), 0, 10); -} - -int64_t OS2Table::UlUnicodeRange1() { - return data_->ReadULong(Offset::kUlUnicodeRange1); -} - -int64_t OS2Table::UlUnicodeRange2() { - return data_->ReadULong(Offset::kUlUnicodeRange2); -} - -int64_t OS2Table::UlUnicodeRange3() { - return data_->ReadULong(Offset::kUlUnicodeRange3); -} - -int64_t OS2Table::UlUnicodeRange4() { - return data_->ReadULong(Offset::kUlUnicodeRange4); -} - -void OS2Table::AchVendId(ByteVector* b) { - b->clear(); - b->resize(4); - data_->ReadBytes(Offset::kAchVendId, &((*b)[0]), 0, 4); -} - -int32_t OS2Table::FsSelection() { - return data_->ReadUShort(Offset::kFsSelection); -} - -int32_t OS2Table::UsFirstCharIndex() { - return data_->ReadUShort(Offset::kUsFirstCharIndex); -} - -int32_t OS2Table::UsLastCharIndex() { - return data_->ReadUShort(Offset::kUsLastCharIndex); -} - -int32_t OS2Table::STypoAscender() { - return data_->ReadShort(Offset::kSTypoAscender); -} - -int32_t OS2Table::STypoDescender() { - return data_->ReadShort(Offset::kSTypoDescender); -} - -int32_t OS2Table::STypoLineGap() { - return data_->ReadShort(Offset::kSTypoLineGap); -} - -int32_t OS2Table::UsWinAscent() { - return data_->ReadUShort(Offset::kUsWinAscent); -} - -int32_t OS2Table::UsWinDescent() { - return data_->ReadUShort(Offset::kUsWinDescent); -} - -int64_t OS2Table::UlCodePageRange1() { - return data_->ReadULong(Offset::kUlCodePageRange1); -} - -int64_t OS2Table::UlCodePageRange2() { - return data_->ReadULong(Offset::kUlCodePageRange2); -} - -int64_t OS2Table::UlCodePageRange() { - // TODO(arthurhsu): Possible bug point, check with stuartg. - return ((0xffffffff & UlCodePageRange2()) << 32) | - (0xffffffff & UlCodePageRange1()); -} - -int32_t OS2Table::SxHeight() { - return data_->ReadShort(Offset::kSxHeight); -} - -int32_t OS2Table::UsDefaultChar() { - return data_->ReadUShort(Offset::kUsDefaultChar); -} - -int32_t OS2Table::UsBreakChar() { - return data_->ReadUShort(Offset::kUsBreakChar); -} - -int32_t OS2Table::UsMaxContext() { - return data_->ReadUShort(Offset::kUsMaxContext); -} - -OS2Table::OS2Table(Header* header, ReadableFontData* data) - : Table(header, data) { -} - -/****************************************************************************** - * class OS2Table::Builder - ******************************************************************************/ -OS2Table::Builder::Builder(FontDataTableBuilderContainer* font_builder, - Header* header, WritableFontData* data) : - Table::TableBasedTableBuilder(font_builder, header, data) { -} - -OS2Table::Builder::~Builder() {} - -CALLER_ATTACH FontDataTable* OS2Table::Builder::SubBuildTable( - ReadableFontData* data) { - FontDataTablePtr table = new OS2Table(header(), data); - return table.Detach(); -} - -} // namespace sfntly diff --git a/sfntly/os2_table.h b/sfntly/os2_table.h deleted file mode 100644 index dcad188..0000000 --- a/sfntly/os2_table.h +++ /dev/null @@ -1,407 +0,0 @@ -/* - * 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. - */ - -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_OS2_TABLE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_OS2_TABLE_H_ - -#include "sfntly/port/refcount.h" -#include "sfntly/table.h" - -namespace sfntly { - -struct WeightClass { - enum { - kThin = 100, - kExtraLight = 200, - kUltraLight = 200, - kLight = 300, - kNormal = 400, - kRegular = 400, - kMedium = 500, - kSemiBold = 600, - kDemiBold = 600, - kBold = 700, - kExtraBold = 800, - kUltraBold = 800, - kBlack = 900, - kHeavy = 900 - }; -}; - -struct WidthClass { - enum { - kUltraCondensed = 1, - kExtraCondensed = 2, - kCondensed = 3, - kSemiCondensed = 4, - kMedium = 5, - kNormal = 5, - kSemiExpanded = 6, - kExpanded = 7, - kExtraExpanded = 8, - kUltraExpanded = 9 - }; -}; - -struct EmbeddingFlags { - enum { - kReserved0 = 1 << 0, - kRestrictedLicenseEmbedding = 1 << 1, - kPreviewAndPrintEmbedding = 1 << 2, - kEditableEmbedding = 1 << 3, - kReserved4 = 1 << 4, - kReserved5 = 1 << 5, - kReserved6 = 1 << 6, - kReserved7 = 1 << 7, - kNoSubsetting = 1 << 8, - kBitmapEmbeddingOnly = 1 << 9, - kReserved10 = 1 << 10, - kReserved11 = 1 << 11, - kReserved12 = 1 << 12, - kReserved13 = 1 << 13, - kReserved14 = 1 << 14, - kReserved15 = 1 << 15 - }; -}; - -struct UnicodeRange { - enum { - // This enum relies on the ordering of the data matching the ordinal numbers - // of the properties. - kBasicLatin, - kLatin1Supplement, - kLatinExtendedA, - kLatinExtendedB, - kIPAExtensions, - kSpacingModifierLetters, - kCombiningDiacriticalMarks, - kGreekAndCoptic, - kCoptic, - kCyrillic, - kArmenian, - kHebrew, - kVai, - kArabic, - kNKo, - kDevanagari, - kBengali, - kGurmukhi, - kGujarati, - kOriya, - kTamil, - kTelugu, - kKannada, - kMalayalam, - kThai, - kLao, - kGeorgian, - kBalinese, - kHangulJamo, - kLatinExtendedAdditional, - kGreekExtended, - kGeneralPunctuation, - kSuperscriptsAndSubscripts, - kCurrencySymbols, - kNumberForms, - kArrows, - kMathematicalOperators, - kMiscTechnical, - kControlPictures, - kOCR, - kEnclosedAlphanumerics, - kBoxDrawing, - kBlockElements, - kGeometricShapes, - kMiscSymbols, - kDingbats, - kCJKSymbolsAndPunctuation, - kHiragana, - kKatakana, - kBopomofo, - kHangulCompatibilityJamo, - kPhagspa, - kEnclosedCJKLettersAndMonths, - kCJKCompatibility, - kHangulSyllables, - kNonPlane0, - kPhoenician, - kCJKUnifiedIdeographs, - kPrivateUseAreaPlane0, - kCJKStrokes, - kAlphabeticPresentationForms, - kArabicPresentationFormsA, - kCombiningHalfMarks, - kVerticalForms, - kSmallFormVariants, - kArabicPresentationFormsB, - kHalfwidthAndFullwidthForms, - kSpecials, - kTibetan, - kSyriac, - kThaana, - kSinhala, - kMyanmar, - kEthiopic, - kCherokee, - kUnifiedCanadianAboriginalSyllabics, - kOgham, - kRunic, - kKhmer, - kMongolian, - kBraillePatterns, - kYiSyllables, - kTagalog, - kOldItalic, - kGothic, - kDeseret, - kMusicalSymbols, - kMathematicalAlphanumericSymbols, - kPrivateUsePlane15And16, - kVariationSelectors, - kTags, - kLimbu, - kTaiLe, - kNewTaiLue, - kBuginese, - kGlagolitic, - kTifnagh, - kYijingHexagramSymbols, - kSylotiNagari, - kLinearB, - kAncientGreekNumbers, - kUgaritic, - kOldPersian, - kShavian, - kOsmanya, - kCypriotSyllabary, - kKharoshthi, - kTaiXuanJingSymbols, - kCuneiform, - kCountingRodNumerals, - kSudanese, - kLepcha, - kOlChiki, - kSaurashtra, - kKayahLi, - kRejang, - kCharm, - kAncientSymbols, - kPhaistosDisc, - kCarian, - kDominoTiles, - kReserved123, - kReserved124, - kReserved125, - kReserved126, - kReserved127, - kLast = kReserved127 - }; - - int32_t range(int32_t bit); - // UNIMPLEMENTED: EnumSet asSet(long range1, long range2, - // long range3, long range4) -}; - -struct FsSelection { - enum { - kITALIC = 1 << 0, - kUNDERSCORE = 1 << 1, - kNEGATIVE = 1 << 2, - kOUTLINED = 1 << 3, - kSTRIKEOUT = 1 << 4, - kBOLD = 1 << 5, - kREGULAR = 1 << 6, - kUSE_TYPO_METRICS = 1 << 7, - kWWS = 1 << 8, - kOBLIQUE = 1 << 9 - }; -}; - -// C++ port only: C++ does not support 64-bit enums until C++0x. For better -// portability, we need to use static const int64_t instead. -struct CodePageRange { - static const int64_t kLatin1_1252; - static const int64_t kLatin2_1250; - static const int64_t kCyrillic_1251; - static const int64_t kGreek_1253; - static const int64_t kTurkish_1254; - static const int64_t kHebrew_1255; - static const int64_t kArabic_1256; - static const int64_t kWindowsBaltic_1257; - static const int64_t kVietnamese_1258; - static const int64_t kAlternateANSI9; - static const int64_t kAlternateANSI10; - static const int64_t kAlternateANSI11; - static const int64_t kAlternateANSI12; - static const int64_t kAlternateANSI13; - static const int64_t kAlternateANSI14; - static const int64_t kAlternateANSI15; - static const int64_t kThai_874; - static const int64_t kJapanJIS_932; - static const int64_t kChineseSimplified_936; - static const int64_t kKoreanWansung_949; - static const int64_t kChineseTraditional_950; - static const int64_t kKoreanJohab_1361; - static const int64_t kAlternateANSI22; - static const int64_t kAlternateANSI23; - static const int64_t kAlternateANSI24; - static const int64_t kAlternateANSI25; - static const int64_t kAlternateANSI26; - static const int64_t kAlternateANSI27; - static const int64_t kAlternateANSI28; - static const int64_t kMacintoshCharacterSet; - static const int64_t kOEMCharacterSet; - static const int64_t kSymbolCharacterSet; - static const int64_t kReservedForOEM32; - static const int64_t kReservedForOEM33; - static const int64_t kReservedForOEM34; - static const int64_t kReservedForOEM35; - static const int64_t kReservedForOEM36; - static const int64_t kReservedForOEM37; - static const int64_t kReservedForOEM38; - static const int64_t kReservedForOEM39; - static const int64_t kReservedForOEM40; - static const int64_t kReservedForOEM41; - static const int64_t kReservedForOEM42; - static const int64_t kReservedForOEM43; - static const int64_t kReservedForOEM44; - static const int64_t kReservedForOEM45; - static const int64_t kReservedForOEM46; - static const int64_t kReservedForOEM47; - static const int64_t kIBMGreek_869; - static const int64_t kMSDOSRussion_866; - static const int64_t kMSDOSNordic_865; - static const int64_t kArabic_864; - static const int64_t kMSDOSCanadianFrench_863; - static const int64_t kHebrew_862; - static const int64_t kMSDOSIcelandic_861; - static const int64_t kMSDOSPortugese_860; - static const int64_t kIBMTurkish_857; - static const int64_t kIBMCyrillic_855; - static const int64_t kLatin2_852; - static const int64_t kMSDOSBaltic_775; - static const int64_t kGreek_737; - static const int64_t kArabic_708; - static const int64_t kLatin1_850; - static const int64_t kUS_437; -}; - -class OS2Table : public Table, public RefCounted { - public: - class Builder : public Table::TableBasedTableBuilder, - public RefCounted { - public: - Builder(FontDataTableBuilderContainer* font_builder, Header* header, - WritableFontData* data); - virtual ~Builder(); - virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); - }; - - ~OS2Table(); - - int32_t Version(); - int32_t XAvgCharWidth(); - int32_t UsWeightClass(); - int32_t UsWidthClass(); - // UNIMPLEMENTED: public EnumSet fsType() - int32_t FsType(); - int32_t YSubscriptXSize(); - int32_t YSubscriptYSize(); - int32_t YSubscriptXOffset(); - int32_t YSubscriptYOffset(); - int32_t YSuperscriptXSize(); - int32_t YSuperscriptYSize(); - int32_t YSuperscriptXOffset(); - int32_t YSuperscriptYOffset(); - int32_t YStrikeoutSize(); - int32_t YStrikeoutPosition(); - int32_t SFamilyClass(); - void Panose(ByteVector* value); - int64_t UlUnicodeRange1(); - int64_t UlUnicodeRange2(); - int64_t UlUnicodeRange3(); - int64_t UlUnicodeRange4(); - // UNIMPLEMENTED: public EnumSet UlUnicodeRange() - void AchVendId(ByteVector* b); - // UNIMPLEMENTED: public EnumSet fsSelection() - int32_t FsSelection(); - int32_t UsFirstCharIndex(); - int32_t UsLastCharIndex(); - int32_t STypoAscender(); - int32_t STypoDescender(); - int32_t STypoLineGap(); - int32_t UsWinAscent(); - int32_t UsWinDescent(); - int64_t UlCodePageRange1(); - int64_t UlCodePageRange2(); - // UNIMPLEMENTED: public EnumSet ulCodePageRange() - int64_t UlCodePageRange(); - int32_t SxHeight(); - int32_t SCapHeight(); - int32_t UsDefaultChar(); - int32_t UsBreakChar(); - int32_t UsMaxContext(); - - private: - struct Offset { - enum { - kVersion = 0, - kXAvgCharWidth = 2, - kUsWeightClass = 4, - kUsWidthClass = 6, - kFsType = 8, - kYSubscriptXSize = 10, - kYSubscriptYSize = 12, - kYSubscriptXOffset = 14, - kYSubscriptYOffset = 16, - kYSuperscriptXSize = 18, - kYSuperscriptYSize = 20, - kYSuperscriptXOffset = 22, - kYSuperscriptYOffset = 24, - kYStrikeoutSize = 26, - kYStrikeoutPosition = 28, - kSFamilyClass = 30, - kPanose = 32, - kUlUnicodeRange1 = 42, - kUlUnicodeRange2 = 46, - kUlUnicodeRange3 = 50, - kUlUnicodeRange4 = 54, - kAchVendId = 58, - kFsSelection = 62, - kUsFirstCharIndex = 64, - kUsLastCharIndex = 66, - kSTypoAscender = 68, - kSTypoDescender = 70, - kSTypoLineGap = 72, - kUsWinAscent = 74, - kUsWinDescent = 76, - kUlCodePageRange1 = 78, - kUlCodePageRange2 = 82, - kSxHeight = 86, - kSCapHeight = 88, - kUsDefaultChar = 90, - kUsBreakChar = 92, - kUsMaxContext = 94 - }; - }; - - OS2Table(Header* header, ReadableFontData* data); -}; -typedef Ptr OS2TablePtr; - -} // namespace sfntly - -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_OS2_TABLE_H_ diff --git a/sfntly/port/atomic.h b/sfntly/port/atomic.h index abfc429..b381a52 100644 --- a/sfntly/port/atomic.h +++ b/sfntly/port/atomic.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_ATOMIC_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_ATOMIC_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_PORT_ATOMIC_H_ +#define SFNTLY_CPP_SRC_SFNTLY_PORT_ATOMIC_H_ #if defined (WIN32) @@ -68,4 +68,4 @@ static inline size_t AtomicDecrement(size_t* address) { #endif // WIN32 -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_ATOMIC_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_PORT_ATOMIC_H_ diff --git a/sfntly/port/config.h b/sfntly/port/config.h index 8e610d0..01c4685 100644 --- a/sfntly/port/config.h +++ b/sfntly/port/config.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_CONFIG_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_CONFIG_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_PORT_CONFIG_H_ +#define SFNTLY_CPP_SRC_SFNTLY_PORT_CONFIG_H_ #if !defined(SFNTLY_BIG_ENDIAN) && !defined(SFNTLY_LITTLE_ENDIAN) #if defined (__ppc__) || defined (__ppc64__) - #define TYPOGRAPHY_FONT_SFNTLY_BIG_ENDIAN + #define SFNTLY_CPP_BIG_ENDIAN #else - #define TYPOGRAPHY_FONT_SFNTLY_LITTLE_ENDIAN + #define SFNTLY_CPP_LITTLE_ENDIAN #endif #endif -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_CONFIG_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_PORT_CONFIG_H_ diff --git a/sfntly/port/endian.h b/sfntly/port/endian.h index 1364e42..db58f0a 100644 --- a/sfntly/port/endian.h +++ b/sfntly/port/endian.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_ENDIAN_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_ENDIAN_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_PORT_ENDIAN_H_ +#define SFNTLY_CPP_SRC_SFNTLY_PORT_ENDIAN_H_ #include "sfntly/port/config.h" #include "sfntly/port/type.h" @@ -74,4 +74,4 @@ static inline uint64_t EndianSwap64(uint64_t value) { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_ENDIAN_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_PORT_ENDIAN_H_ diff --git a/sfntly/port/exception_type.h b/sfntly/port/exception_type.h index ddeb95b..b96efcb 100644 --- a/sfntly/port/exception_type.h +++ b/sfntly/port/exception_type.h @@ -16,8 +16,8 @@ // Exceptions used in sfntly -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_EXCEPTION_TYPE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_EXCEPTION_TYPE_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_PORT_EXCEPTION_TYPE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_PORT_EXCEPTION_TYPE_H_ #if !defined (SFNTLY_NO_EXCEPTION) @@ -122,4 +122,4 @@ class IllegalStateException : public Exception { #endif // #if !defined (SFNTLY_NO_EXCEPTION) -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_EXCEPTION_TYPE_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_PORT_EXCEPTION_TYPE_H_ diff --git a/sfntly/port/file_input_stream.h b/sfntly/port/file_input_stream.h index a63726f..cbca25f 100644 --- a/sfntly/port/file_input_stream.h +++ b/sfntly/port/file_input_stream.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_FILE_INPUT_STREAM_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_FILE_INPUT_STREAM_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_PORT_FILE_INPUT_STREAM_H_ +#define SFNTLY_CPP_SRC_SFNTLY_PORT_FILE_INPUT_STREAM_H_ #include @@ -54,4 +54,4 @@ class FileInputStream : public PushbackInputStream { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_FILE_INPUT_STREAM_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_PORT_FILE_INPUT_STREAM_H_ diff --git a/sfntly/port/input_stream.h b/sfntly/port/input_stream.h index a56afb9..5d24036 100644 --- a/sfntly/port/input_stream.h +++ b/sfntly/port/input_stream.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_INPUT_STREAM_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_INPUT_STREAM_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_PORT_INPUT_STREAM_H_ +#define SFNTLY_CPP_SRC_SFNTLY_PORT_INPUT_STREAM_H_ #include "sfntly/port/type.h" @@ -46,4 +46,4 @@ class PushbackInputStream : public InputStream { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_INPUT_STREAM_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_PORT_INPUT_STREAM_H_ diff --git a/sfntly/port/memory_output_stream.h b/sfntly/port/memory_output_stream.h index 8983ab0..d1eda7f 100644 --- a/sfntly/port/memory_output_stream.h +++ b/sfntly/port/memory_output_stream.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_MEMORY_OUTPUT_STREAM_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_MEMORY_OUTPUT_STREAM_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_PORT_MEMORY_OUTPUT_STREAM_H_ +#define SFNTLY_CPP_SRC_SFNTLY_PORT_MEMORY_OUTPUT_STREAM_H_ #include #include @@ -48,4 +48,4 @@ class MemoryOutputStream : public OutputStream { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_MEMORY_OUTPUT_STREAM_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_PORT_MEMORY_OUTPUT_STREAM_H_ diff --git a/sfntly/port/output_stream.h b/sfntly/port/output_stream.h index d813333..64a6024 100644 --- a/sfntly/port/output_stream.h +++ b/sfntly/port/output_stream.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_OUTPUT_STREAM_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_OUTPUT_STREAM_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_PORT_OUTPUT_STREAM_H_ +#define SFNTLY_CPP_SRC_SFNTLY_PORT_OUTPUT_STREAM_H_ #include "sfntly/port/type.h" @@ -43,4 +43,4 @@ class OutputStream { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_OUTPUT_STREAM_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_PORT_OUTPUT_STREAM_H_ diff --git a/sfntly/port/refcount.h b/sfntly/port/refcount.h index 6ac09bb..eed5162 100644 --- a/sfntly/port/refcount.h +++ b/sfntly/port/refcount.h @@ -63,8 +63,8 @@ // end_scope_pointer.Attach(passThrough); // If you are not passing that object back, you are the end of scope. -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_REFCOUNT_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_REFCOUNT_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_PORT_REFCOUNT_H_ +#define SFNTLY_CPP_SRC_SFNTLY_PORT_REFCOUNT_H_ #if !defined (NDEBUG) #define ENABLE_OBJECT_COUNTER @@ -274,4 +274,4 @@ class Ptr { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_REFCOUNT_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_PORT_REFCOUNT_H_ diff --git a/sfntly/port/type.h b/sfntly/port/type.h index 4691a82..458a364 100644 --- a/sfntly/port/type.h +++ b/sfntly/port/type.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_TYPE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_TYPE_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_PORT_TYPE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_PORT_TYPE_H_ #include @@ -93,4 +93,4 @@ inline To down_cast(From* f) { // so we only accept pointers #define UNREFERENCED_PARAMETER(p) do { (void)p; } while (0) #endif -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_TYPE_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_PORT_TYPE_H_ diff --git a/sfntly/subtable.cc b/sfntly/subtable.cc deleted file mode 100644 index 782fd80..0000000 --- a/sfntly/subtable.cc +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 "sfntly/subtable.h" - -namespace sfntly { -/****************************************************************************** - * SubTable class - ******************************************************************************/ -SubTable::~SubTable() {} - -SubTable::SubTable(ReadableFontData* data) - : FontDataTable(data) { -} - -/****************************************************************************** - * SubTable::Builder class - ******************************************************************************/ -SubTable::Builder::~Builder() {} - -SubTable::Builder::Builder(FontDataTableBuilderContainer* container, - WritableFontData* data) - : FontDataTable::Builder(container, data) { -} - -SubTable::Builder::Builder(FontDataTableBuilderContainer* container, - ReadableFontData* data) - : FontDataTable::Builder(container, data) { -} - -} // namespace sfntly diff --git a/sfntly/subtable.h b/sfntly/subtable.h deleted file mode 100644 index 30ecf66..0000000 --- a/sfntly/subtable.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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. - */ - -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_SUBTABLE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_SUBTABLE_H_ - -#include "sfntly/font_data_table.h" - -namespace sfntly { - -// An abstract base class for subtables. Subtables are smaller tables nested -// within other tables and don't have an entry in the main font index. Examples -// of these are the CMap subtables within CMap table (cmap) or a glyph within -// the glyph table (glyf). -class SubTable : public FontDataTable { - public: - class Builder : public FontDataTable::Builder { - public: - virtual ~Builder(); - - protected: - Builder(FontDataTableBuilderContainer* container, WritableFontData* data); - Builder(FontDataTableBuilderContainer* container, ReadableFontData* data); - }; - - virtual ~SubTable(); - - protected: - // Note: constructor refactored in C++ to avoid heavy lifting. - // caller need to do data->Slice(offset, length) beforehand. - explicit SubTable(ReadableFontData* data); -}; - -} // namespace sfntly - -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_SUBTABLE_H_ diff --git a/sfntly/table.cc b/sfntly/table.cc deleted file mode 100644 index fc09d10..0000000 --- a/sfntly/table.cc +++ /dev/null @@ -1,279 +0,0 @@ -/* - * 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 "sfntly/table.h" - -#include "sfntly/font.h" -#include "sfntly/tag.h" -#include "sfntly/cmap_table.h" -#include "sfntly/font_header_table.h" -#include "sfntly/glyph_table.h" -#include "sfntly/horizontal_header_table.h" -#include "sfntly/horizontal_metrics_table.h" -#include "sfntly/loca_table.h" -#include "sfntly/maximum_profile_table.h" -#include "sfntly/name_table.h" -#include "sfntly/os2_table.h" - -namespace sfntly { - -/****************************************************************************** - * Table class - ******************************************************************************/ -Table::~Table() {} - -int64_t Table::CalculatedChecksum() { - return data_->Checksum(); -} - -WritableFontData* Table::GetNewData(int32_t size) { - return font_->GetNewData(size); -} - -void Table::SetFont(Font* font) { - font_ = font; -} - -Table::Table(Header* header, ReadableFontData* data) - : FontDataTable(data) { - header_ = header; -} - -/****************************************************************************** - * Table::Header class - ******************************************************************************/ -Table::Header::Header(int32_t tag) - : tag_(tag), - offset_(0), - length_(0), - offset_valid_(false), - checksum_(0), - checksum_valid_(false) { -} - -Table::Header::Header(int32_t tag, int32_t length) - : tag_(tag), - offset_(0), - length_(length), - offset_valid_(false), - checksum_(0), - checksum_valid_(false) { -} - -Table::Header::Header(int32_t tag, - int64_t checksum, - int32_t offset, - int32_t length) - : tag_(tag), - offset_(offset), - length_(length), - offset_valid_(true), - checksum_(checksum), - checksum_valid_(true) { -} - -Table::Header::~Header() {} - -bool TableHeaderComparator::operator() (const TableHeaderPtr lhs, - const TableHeaderPtr rhs) { - return lhs->offset_ > rhs->offset_; -} - -/****************************************************************************** - * Table::Builder class - ******************************************************************************/ -Table::Builder::~Builder() { - header_.Release(); -} - -void Table::Builder::NotifyPostTableBuild(FontDataTable* table) { - if (model_changed() || data_changed()) { - Table* derived_table = down_cast(table); - header_ = new Header(header()->tag(), - derived_table->ReadFontData()->Length()); - } -} - -WritableFontData* Table::Builder::GetNewData(int32_t size) { - UNREFERENCED_PARAMETER(size); - return InternalWriteData(); -} - -CALLER_ATTACH Table::Builder* - Table::Builder::GetBuilder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* table_data) { - int32_t tag = header->tag(); - TableBuilderPtr builder; - Table::Builder* builder_raw = NULL; - - // Note: Tables are commented out when they are not used/ported. - // TODO(arthurhsu): IMPLEMENT: finish tables that are not ported. - /*if (tag == Tag::cmap) { - builder_raw = static_cast( - new CMapTable::Builder(font_builder, header, table_data)); - } else*/ if (tag == Tag::head) { - builder_raw = static_cast( - new FontHeaderTable::Builder(font_builder, header, table_data)); - } else if (tag == Tag::hhea) { - builder_raw = static_cast( - new HorizontalHeaderTable::Builder(font_builder, header, table_data)); - } else if (tag == Tag::hmtx) { - builder_raw = static_cast( - new HorizontalMetricsTable::Builder(font_builder, header, table_data)); - } else if (tag == Tag::maxp) { - builder_raw = static_cast( - new MaximumProfileTable::Builder(font_builder, header, table_data)); - } else if (tag == Tag::name) { - builder_raw = static_cast( - new NameTable::Builder(font_builder, header, table_data)); - } else if (tag == Tag::OS_2) { - builder_raw = static_cast( - new OS2Table::Builder(font_builder, header, table_data)); - }/* else if (tag == Tag::PostScript) { - builder_raw = static_cast( - new PostScriptTable::Builder(font_builder, header, table_data)); - } else if (tag == Tag::cvt) { - builder_raw = static_cast( - new ControlValueTable::Builder(font_builder, header, table_data)); - }*/ else if (tag == Tag::glyf) { - builder_raw = static_cast( - new GlyphTable::Builder(font_builder, header, table_data)); - } else if (tag == Tag::loca) { - builder_raw = static_cast( - new LocaTable::Builder(font_builder, header, table_data)); - }/* else if (tag == Tag::prep) { - builder_raw = static_cast( - new ControlProgramTable::Builder(font_builder, header, table_data)); - }*/ else if (tag == Tag::bhed) { - builder_raw = static_cast( - new FontHeaderTable::Builder(font_builder, header, table_data)); - } else { - builder_raw = static_cast( - new Table::GenericTableBuilder(font_builder, header, table_data)); - } - - builder = builder_raw; - return builder.Detach(); -} - -Table::Builder::Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data) - : FontDataTable::Builder(font_builder, data) { - header_ = header; -} - -Table::Builder::Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data) - : FontDataTable::Builder(font_builder, data) { - header_ = header; -} - -Table::Builder::Builder(FontDataTableBuilderContainer* font_builder, - Header* header) - : FontDataTable::Builder(font_builder) { - header_ = header; -} - -/****************************************************************************** - * Table::TableBasedTableBuilder class - ******************************************************************************/ -Table::TableBasedTableBuilder::~TableBasedTableBuilder() {} - -int32_t Table::TableBasedTableBuilder::SubSerialize(WritableFontData* data) { - UNREFERENCED_PARAMETER(data); - return 0; -} - -bool Table::TableBasedTableBuilder::SubReadyToSerialize() { - return false; -} - -int32_t Table::TableBasedTableBuilder::SubDataSizeToSerialize() { - return 0; -} - -void Table::TableBasedTableBuilder::SubDataSet() { - table_ = NULL; -} - -Table::TableBasedTableBuilder::TableBasedTableBuilder( - FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data) - : Builder(font_builder, header, data) { -} - -Table::TableBasedTableBuilder::TableBasedTableBuilder( - FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data) - : Builder(font_builder, header, data) { -} - -Table::TableBasedTableBuilder::TableBasedTableBuilder( - FontDataTableBuilderContainer* font_builder, - Header* header) - : Builder(font_builder, header) { -} - -Table* Table::TableBasedTableBuilder::GetTable() { - if (table_ == NULL) { - table_.Attach(down_cast(SubBuildTable(InternalReadData()))); - } - return table_; -} - -/****************************************************************************** - * Table::GenericTableBuilder class - ******************************************************************************/ -Table::GenericTableBuilder::GenericTableBuilder( - FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data) - : TableBasedTableBuilder(font_builder, header, data) { -} - -CALLER_ATTACH FontDataTable* - Table::GenericTableBuilder::SubBuildTable(ReadableFontData* data) { - // Note: In C++ port, we use GenericTable, the ref-counted version of Table - UNREFERENCED_PARAMETER(data); - FontDataTablePtr table = new GenericTable(this->header(), InternalReadData()); - return table.Detach(); -} - -/****************************************************************************** - * Table::ArrayElementTableBuilder class - ******************************************************************************/ -Table::ArrayElementTableBuilder::~ArrayElementTableBuilder() {} - -Table::ArrayElementTableBuilder::ArrayElementTableBuilder( - FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data) - : Builder(font_builder, header, data) { -} - -Table::ArrayElementTableBuilder::ArrayElementTableBuilder( - FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data) - : Builder(font_builder, header, data) { -} - -} // namespace sfntly diff --git a/sfntly/table.h b/sfntly/table.h deleted file mode 100644 index 217abcd..0000000 --- a/sfntly/table.h +++ /dev/null @@ -1,183 +0,0 @@ -/* - * 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. - */ - -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TABLE_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TABLE_H_ - -#include -#include -#include -#include - -#include "sfntly/port/type.h" -#include "sfntly/font_data_table.h" - -namespace sfntly { -class Font; -class Table : public FontDataTable, public FontDataTableBuilderContainer { - public: - class Header : public RefCounted
{ - public: - explicit Header(int32_t tag); - Header(int32_t tag, int32_t length); - Header(int32_t tag, int64_t checksum, int32_t offset, int32_t length); - virtual ~Header(); - - int32_t tag() { return tag_; } - int32_t offset() { return offset_; } - int32_t length() { return length_; } - bool offset_valid() { return offset_valid_; } - int64_t checksum() { return checksum_; } - bool checksum_valid() { return checksum_valid_; } - - private: - int32_t tag_; - int32_t offset_; - int32_t length_; - bool offset_valid_; - int64_t checksum_; - bool checksum_valid_; - - friend class TableHeaderComparator; - }; - - // Note: original version is Builder - // C++ template is not designed that way so plain old inheritance is - // chosen. - class Builder : public FontDataTable::Builder, - public FontDataTableBuilderContainer { - public: - virtual ~Builder(); - virtual Header* header() { return header_; } - virtual void NotifyPostTableBuild(FontDataTable* table); - virtual WritableFontData* GetNewData(int32_t size); - - static CALLER_ATTACH Builder* - GetBuilder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* table_data); - - protected: - // Note: original version is Font.Builder font_builder. This results in - // mutual inclusion happiness that Java solved for C++. Therefore, - // we need to avoid that happiness when we port it to C++. - Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data); - Builder(FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data); - Builder(FontDataTableBuilderContainer* font_builder, - Header* header); - - private: - Ptr
header_; - }; - - class TableBasedTableBuilder : public Builder { - public: - virtual ~TableBasedTableBuilder(); - - virtual int32_t SubSerialize(WritableFontData* new_data); - virtual bool SubReadyToSerialize(); - virtual int32_t SubDataSizeToSerialize(); - virtual void SubDataSet(); - - protected: - TableBasedTableBuilder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data); - TableBasedTableBuilder(FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data); - TableBasedTableBuilder(FontDataTableBuilderContainer* font_builder, - Header* header); - - // C++ port: renamed table() to GetTable() - virtual Table* GetTable(); - - // TODO(arthurhsu): style guide violation: protected member, need refactor - Ptr table_; - }; - - class GenericTableBuilder : public TableBasedTableBuilder, - public RefCounted { - public: - GenericTableBuilder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data); - virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); - }; - - class ArrayElementTableBuilder : public Builder { - public: - virtual ~ArrayElementTableBuilder(); - - protected: - ArrayElementTableBuilder(FontDataTableBuilderContainer* font_builder, - Header* header, - WritableFontData* data); - ArrayElementTableBuilder(FontDataTableBuilderContainer* font_builder, - Header* header, - ReadableFontData* data); - }; - - virtual ~Table(); - virtual int64_t CalculatedChecksum(); - virtual Header* header() { return header_; } - virtual int32_t header_tag() { return header_->tag(); } - virtual int32_t header_offset() { return header_->offset(); } - virtual int32_t header_length() { return header_->length(); } - virtual int64_t header_checksum() { return header_->checksum(); } - virtual WritableFontData* GetNewData(int32_t size); - virtual void SetFont(Font* font); - - protected: - Table(Header* header, ReadableFontData* data); - - private: - Ptr
header_; - Ptr font_; -}; - -// C++ port only -class GenericTable : public Table, public RefCounted { - public: - GenericTable(Header* header, ReadableFontData* data) : Table(header, data) {} - virtual ~GenericTable() {} -}; - -typedef Ptr
TablePtr; -typedef Ptr TableHeaderPtr; -typedef std::vector TableHeaderList; -typedef Ptr TableBuilderPtr; -typedef std::map TableMap; -typedef std::pair TableMapEntry; - -typedef std::map DataBlockMap; -typedef std::pair DataBlockEntry; -typedef std::map TableBuilderMap; -typedef std::pair TableBuilderEntry; - -class TableHeaderComparator { - public: - bool operator()(const TableHeaderPtr h1, const TableHeaderPtr h2); -}; -typedef std::set TableHeaderSortedSet; - -} // namespace sfntly - -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TABLE_H_ diff --git a/sfntly/table/core/cmap_table.cc b/sfntly/table/core/cmap_table.cc new file mode 100644 index 0000000..7217265 --- /dev/null +++ b/sfntly/table/core/cmap_table.cc @@ -0,0 +1,511 @@ +/* + * 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. + */ + +// TODO(arthurhsu): IMPLEMENT: not really used and tested, need cleanup + +#include + +#include "sfntly/table/core/cmap_table.h" +#include "sfntly/table/core/name_table.h" +#include "sfntly/font.h" +#include "sfntly/port/endian.h" + +namespace sfntly { + +const int32_t CMapTable::NOTDEF = 0; + +/****************************************************************************** + * CMapTable class + ******************************************************************************/ +CMapTable::~CMapTable() {} + +int32_t CMapTable::Version() { + return data_->ReadUShort(Offset::kVersion); +} + +int32_t CMapTable::NumCMaps() { + return data_->ReadUShort(Offset::kNumTables); +} + +CMapTable::CMapId CMapTable::GetCMapId(int32_t index) { + return CMapId(PlatformId(index), EncodingId(index)); +} + +int32_t CMapTable::PlatformId(int32_t index) { + return data_->ReadUShort(Offset::kEncodingRecordPlatformId + + OffsetForEncodingRecord(index)); +} + +int32_t CMapTable::EncodingId(int32_t index) { + return data_->ReadUShort(Offset::kEncodingRecordEncodingId + + OffsetForEncodingRecord(index)); +} + +int32_t CMapTable::Offset(int32_t index) { + return data_->ReadULongAsInt(Offset::kEncodingRecordOffset + + OffsetForEncodingRecord(index)); +} + +CMapTable::CMapTable(Header* header, ReadableFontData* data) + : Table(header, data) { +} + +int32_t CMapTable::OffsetForEncodingRecord(int32_t index) { + return Offset::kEncodingRecordStart + index * Offset::kEncodingRecordSize; +} + +/****************************************************************************** + * CMapTable::CMapId class + ******************************************************************************/ +CMapTable::CMapId::CMapId(int32_t platform_id, int32_t encoding_id) + : platform_id_(platform_id), encoding_id_(encoding_id) { +} + +CMapTable::CMapId::CMapId(const CMapId& obj) + : platform_id_(obj.platform_id_), encoding_id_(obj.encoding_id_) { +} + +bool CMapTable::CMapId::operator==(const CMapTable::CMapId& obj) { + return obj.platform_id_ == platform_id_ && obj.encoding_id_ == encoding_id_; +} + +const CMapTable::CMapId& CMapTable::CMapId::operator=( + const CMapTable::CMapId& obj) { + platform_id_ = obj.platform_id_; + encoding_id_ = obj.encoding_id_; + return *this; +} + +int CMapTable::CMapId::HashCode() const { + return platform_id_ << 8 | encoding_id_; +} + +CMapTable::CMapId WINDOWS_BMP(PlatformId::kWindows, + WindowsEncodingId::kUnicodeUCS2); +CMapTable::CMapId WINDOWS_UCS4(PlatformId::kWindows, + WindowsEncodingId::kUnicodeUCS4); +CMapTable::CMapId MAC_ROMAN(PlatformId::kWindows, MacintoshEncodingId::kRoman); + +/****************************************************************************** + * CMapTable::CMapIdComparator class + ******************************************************************************/ + +bool CMapTable::CMapIdComparator::operator()(const CMapId& lhs, + const CMapId& rhs) { + return lhs.HashCode() > rhs.HashCode(); +} + +/****************************************************************************** + * CMapTable::CMap class + ******************************************************************************/ +CMapTable::CMap::CMap(ReadableFontData* data, int32_t format, + const CMapId& cmap_id) + : SubTable(data), format_(format), cmap_id_(cmap_id) { +} + +CMapTable::CMap::~CMap() { +} + +/****************************************************************************** + * CMapTable::CMap::Builder class + ******************************************************************************/ +CMapTable::CMap::Builder::~Builder() { +} + +CALLER_ATTACH CMapTable::CMap::Builder* + CMapTable::CMap::Builder::GetBuilder( + FontDataTableBuilderContainer* container, + ReadableFontData* data, + int32_t offset, + const CMapId& cmap_id) { + // NOT IMPLEMENTED: Java enum value validation + int32_t format = data->ReadUShort(offset); + CMapBuilderPtr builder; + switch (format) { + case CMapFormat::kFormat0: + builder = new CMapFormat0::Builder(container, data, offset, cmap_id); + break; + case CMapFormat::kFormat2: + builder = new CMapFormat0::Builder(container, data, offset, cmap_id); + break; + default: + break; + } + return builder.Detach(); +} + +CMapTable::CMap::Builder::Builder(FontDataTableBuilderContainer* container, + ReadableFontData* data, int32_t format, + const CMapId& cmap_id) + : SubTable::Builder(container, data), + format_(format), + cmap_id_(cmap_id) { +} + +CMapTable::CMap::Builder::Builder(FontDataTableBuilderContainer* container, + WritableFontData* data, int32_t format, + const CMapId& cmap_id) + : SubTable::Builder(container, data), + format_(format), + cmap_id_(cmap_id) { +} + +int32_t CMapTable::CMap::Builder::SubSerialize(WritableFontData* new_data) { + return InternalReadData()->CopyTo(new_data); +} + +bool CMapTable::CMap::Builder::SubReadyToSerialize() { + return true; +} + +int32_t CMapTable::CMap::Builder::SubDataSizeToSerialize() { + return InternalReadData()->Length(); +} + +void CMapTable::CMap::Builder::SubDataSet() { + // NOP +} + +/****************************************************************************** + * CMapTable::CMapFormat0 + ******************************************************************************/ +CMapTable::CMapFormat0::~CMapFormat0() { +} + +int32_t CMapTable::CMapFormat0::Language() { + return 0; +} + +int32_t CMapTable::CMapFormat0::GlyphId(int32_t character) { + if (character < 0 || character > 255) { + return CMapTable::NOTDEF; + } + return data_->ReadByte(character + Offset::kFormat0GlyphIdArray); +} + +CMapTable::CMapFormat0::CMapFormat0(ReadableFontData* data, + const CMapId& cmap_id) + : CMap(data, CMapFormat::kFormat0, cmap_id) { +} + +/****************************************************************************** + * CMapTable::CMapFormat0::Builder + ******************************************************************************/ +CMapTable::CMapFormat0::Builder::Builder( + FontDataTableBuilderContainer* container, + WritableFontData* data, + int32_t offset, + const CMapId& cmap_id) + : CMapTable::CMap::Builder(container, + data ? down_cast( + data->Slice(offset, data->ReadUShort( + offset + Offset::kFormat0Length))) + : reinterpret_cast(NULL), + CMapFormat::kFormat0, cmap_id) { + // TODO(arthurhsu): FIXIT: heavy lifting and leak, need fix. +} + +CMapTable::CMapFormat0::Builder::Builder( + FontDataTableBuilderContainer* container, + ReadableFontData* data, + int32_t offset, + const CMapId& cmap_id) + : CMapTable::CMap::Builder(container, + data ? down_cast( + data->Slice(offset, data->ReadUShort( + offset + Offset::kFormat0Length))) + : reinterpret_cast(NULL), + CMapFormat::kFormat0, cmap_id) { + // TODO(arthurhsu): FIXIT: heavy lifting and leak, need fix. +} + +CMapTable::CMapFormat0::Builder::~Builder() { +} + +CALLER_ATTACH FontDataTable* + CMapTable::CMapFormat0::Builder::SubBuildTable(ReadableFontData* data) { + FontDataTablePtr table = new CMapFormat0(data, cmap_id()); + return table.Detach(); +} + +/****************************************************************************** + * CMapTable::CMapFormat2 + ******************************************************************************/ +CMapTable::CMapFormat2::~CMapFormat2() { +} + +int32_t CMapTable::CMapFormat2::Language() { + return 0; +} + +int32_t CMapTable::CMapFormat2::GlyphId(int32_t character) { + if (character > 0xffff) { + return CMapTable::NOTDEF; + } + + uint32_t c = ToBE32(character); + byte_t high_byte = (c >> 8) & 0xff; + byte_t low_byte = c & 0xff; + int32_t offset = SubHeaderOffset(high_byte); + + if (offset == 0) { + low_byte = high_byte; + high_byte = 0; + } + + int32_t first_code = FirstCode(high_byte); + int32_t entry_count = EntryCount(high_byte); + + if (low_byte < first_code || low_byte >= first_code + entry_count) { + return CMapTable::NOTDEF; + } + + int32_t id_range_offset = IdRangeOffset(high_byte); + + // position of idRangeOffset + value of idRangeOffset + index for low byte + // = firstcode + int32_t p_location = (offset + Offset::kFormat2SubHeader_idRangeOffset) + + id_range_offset + + (low_byte - first_code) * DataSize::kUSHORT; + int p = data_->ReadUShort(p_location); + if (p == 0) { + return CMapTable::NOTDEF; + } + + if (offset == 0) { + return p; + } + int id_delta = IdDelta(high_byte); + return (p + id_delta) % 65536; +} + +int32_t CMapTable::CMapFormat2::BytesConsumed(int32_t character) { + uint32_t c = ToBE32(character); + int32_t high_byte = (c >> 8) & 0xff; + int32_t offset = SubHeaderOffset(high_byte); + return (offset == 0) ? 1 : 2; +} + +CMapTable::CMapFormat2::CMapFormat2(ReadableFontData* data, + const CMapId& cmap_id) + : CMap(data, CMapFormat::kFormat2, cmap_id) { +} + +int32_t CMapTable::CMapFormat2::SubHeaderOffset(int32_t sub_header_index) { + return data_->ReadUShort(Offset::kFormat2SubHeaderKeys + + sub_header_index * DataSize::kUSHORT); +} + +int32_t CMapTable::CMapFormat2::FirstCode(int32_t sub_header_index) { + int32_t sub_header_offset = SubHeaderOffset(sub_header_index); + return data_->ReadUShort(sub_header_offset + + Offset::kFormat2SubHeaderKeys + + Offset::kFormat2SubHeader_firstCode); +} + +int32_t CMapTable::CMapFormat2::EntryCount(int32_t sub_header_index) { + int32_t sub_header_offset = SubHeaderOffset(sub_header_index); + return data_->ReadUShort(sub_header_offset + + Offset::kFormat2SubHeaderKeys + + Offset::kFormat2SubHeader_entryCount); +} + +int32_t CMapTable::CMapFormat2::IdRangeOffset(int32_t sub_header_index) { + int32_t sub_header_offset = SubHeaderOffset(sub_header_index); + return data_->ReadUShort(sub_header_offset + + Offset::kFormat2SubHeaderKeys + + Offset::kFormat2SubHeader_idRangeOffset); +} + +int32_t CMapTable::CMapFormat2::IdDelta(int32_t sub_header_index) { + int32_t sub_header_offset = SubHeaderOffset(sub_header_index); + return data_->ReadUShort(sub_header_offset + + Offset::kFormat2SubHeaderKeys + + Offset::kFormat2SubHeader_idDelta); +} + +/****************************************************************************** + * CMapTable::CMapFormat2::Builder + ******************************************************************************/ +CMapTable::CMapFormat2::Builder::Builder( + FontDataTableBuilderContainer* container, + WritableFontData* data, + int32_t offset, + const CMapId& cmap_id) + : CMapTable::CMap::Builder(container, + data ? down_cast( + data->Slice(offset, data->ReadUShort( + offset + Offset::kFormat0Length))) + : reinterpret_cast(NULL), + CMapFormat::kFormat2, cmap_id) { + // TODO(arthurhsu): FIXIT: heavy lifting and leak, need fix. +} + +CMapTable::CMapFormat2::Builder::Builder( + FontDataTableBuilderContainer* container, + ReadableFontData* data, + int32_t offset, + const CMapId& cmap_id) + : CMapTable::CMap::Builder(container, + data ? down_cast( + data->Slice(offset, data->ReadUShort( + offset + Offset::kFormat0Length))) + : reinterpret_cast(NULL), + CMapFormat::kFormat2, cmap_id) { + // TODO(arthurhsu): FIXIT: heavy lifting and leak, need fix. +} + +CMapTable::CMapFormat2::Builder::~Builder() { +} + +CALLER_ATTACH FontDataTable* + CMapTable::CMapFormat2::Builder::SubBuildTable(ReadableFontData* data) { + FontDataTablePtr table = new CMapFormat2(data, cmap_id()); + return table.Detach(); +} + +/****************************************************************************** + * CMapTable::Iterator class + ******************************************************************************/ +CMapTable::CMapIterator::CMapIterator(CMapTable* table, CMapFilter* filter) + : table_index_(0), filter_(filter), table_(table) {} + +bool CMapTable::CMapIterator::HasNext() { + if (!filter_) { + if (table_index_ < table_->NumCMaps()) { + return true; + } + return false; + } + + for (; table_index_ < table_->NumCMaps(); ++table_index_) { + if (filter_->accept(table_->GetCMapId(table_index_))) { + return true; + } + } + return false; +} + +/****************************************************************************** + * CMapTable::Builder class + ******************************************************************************/ +CMapTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data) + : Table::ArrayElementTableBuilder(font_builder, header, data) { +} + +CMapTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data) + : Table::ArrayElementTableBuilder(font_builder, header, data) { +} + +CMapTable::Builder::~Builder() { +} + +int32_t CMapTable::Builder::SubSerialize(WritableFontData* new_data) { + int32_t size = new_data->WriteUShort(CMapTable::Offset::kVersion, + version_); + size += new_data->WriteUShort(CMapTable::Offset::kNumTables, + cmap_builders_.size()); + + int32_t index_offset = size; + size += cmap_builders_.size() * CMapTable::Offset::kEncodingRecordSize; + for (CMapBuilderMap::iterator it = cmap_builders_.begin(), + e = cmap_builders_.end(); it != e; ++it) { + CMapBuilderPtr b = it->second; + // header entry + index_offset += new_data->WriteUShort(index_offset, b->platform_id()); + index_offset += new_data->WriteUShort(index_offset, b->encoding_id()); + index_offset += new_data->WriteULong(index_offset, size); + + // cmap + FontDataPtr slice; + slice.Attach(new_data->Slice(size)); + size += b->SubSerialize(down_cast(slice.p_)); + } + return size; +} + +bool CMapTable::Builder::SubReadyToSerialize() { + if (cmap_builders_.empty()) + return false; + + // check each table + for (CMapBuilderMap::iterator it = cmap_builders_.begin(), + e = cmap_builders_.end(); it != e; ++it) { + if (!it->second->SubReadyToSerialize()) + return false; + } + return true; +} + +int32_t CMapTable::Builder::SubDataSizeToSerialize() { + if (cmap_builders_.empty()) + return 0; + + bool variable = false; + int32_t size = CMapTable::Offset::kEncodingRecordStart + + cmap_builders_.size() * CMapTable::Offset::kEncodingRecordSize; + + // calculate size of each table + for (CMapBuilderMap::iterator it = cmap_builders_.begin(), + e = cmap_builders_.end(); it != e; ++it) { + int32_t cmap_size = it->second->SubDataSizeToSerialize(); + size += abs(cmap_size); + variable |= cmap_size <= 0; + } + return variable ? -size : size; +} + +void CMapTable::Builder::SubDataSet() { + cmap_builders_.clear(); + Table::Builder::set_model_changed(false); +} + +CALLER_ATTACH FontDataTable* + CMapTable::Builder::SubBuildTable(ReadableFontData* data) { + FontDataTablePtr table = new CMapTable(header(), data); + return table.Detach(); +} + +CALLER_ATTACH CMapTable::CMap::Builder* CMapTable::Builder::CMapBuilder( + FontDataTableBuilderContainer* container, ReadableFontData* data, + int32_t index) { + if (index < 0 || index > NumCMaps(data)) + return NULL; + + int32_t record_offset = Offset::kEncodingRecordOffset + index * + Offset::kEncodingRecordSize; + int32_t platform_id = + data->ReadUShort(Offset::kEncodingRecordPlatformId + record_offset); + int32_t encoding_id = + data->ReadUShort(Offset::kEncodingRecordEncodingId + record_offset); + CMapId cmap_id(platform_id, encoding_id); + int32_t offset = + data->ReadULongAsInt(Offset::kEncodingRecordOffset + record_offset); + return CMap::Builder::GetBuilder(container, data, offset, cmap_id); +} + +int32_t CMapTable::Builder::NumCMaps(ReadableFontData* data) { + if (data == NULL) { + return 0; + } + return data->ReadUShort(Offset::kNumTables); +} + +} // namespace sfntly diff --git a/sfntly/table/core/cmap_table.h b/sfntly/table/core/cmap_table.h new file mode 100644 index 0000000..76b4266 --- /dev/null +++ b/sfntly/table/core/cmap_table.h @@ -0,0 +1,447 @@ +/* + * 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. + */ + +// TODO(arthurhsu): IMPLEMENT: not really used and tested, need cleanup +#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_CMAP_TABLE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_CMAP_TABLE_H_ + +#include +#include + +#include "sfntly/port/refcount.h" +#include "sfntly/table/table.h" +#include "sfntly/table/subtable.h" + +namespace sfntly { + +// CMap subtable formats +struct CMapFormat { + enum { + kFormat0 = 0, + kFormat2 = 2, + kFormat4 = 4, + kFormat6 = 6, + kFormat8 = 8, + kFormat10 = 10, + kFormat12 = 12, + kFormat13 = 13, + kFormat14 = 14 + }; +}; + +// A CMap table +class CMapTable : public Table, public RefCounted { +public: + // CMapTable::CMapId + class CMapId { + public: + CMapId(int32_t platform_id, int32_t encoding_id); + CMapId(const CMapId& obj); + + int32_t platform_id() { return platform_id_; } + int32_t encoding_id() { return encoding_id_; } + + bool operator==(const CMapId& obj); + const CMapId& operator=(const CMapId& obj); + int HashCode() const; + + friend class CMapIdComparator; + + private: + int32_t platform_id_; + int32_t encoding_id_; + }; + static CMapId WINDOWS_BMP; + static CMapId WINDOWS_UCS4; + static CMapId MAC_ROMAN; + + // CMapTable::CMapIdComparator + class CMapIdComparator { + public: + bool operator()(const CMapId& lhs, const CMapId& rhs); + }; + + // A filter on cmap + // CMapTable::CMapFilter + class CMapFilter { + public: + // Test on whether the cmap is acceptable or not + // @param cmap_id the id of the cmap + // @return true if the cmap is acceptable; false otherwise + virtual bool accept(CMapId cmap_id) = 0; + // Make gcc -Wnon-virtual-dtor happy. + virtual ~CMapFilter() {} + }; + + // The abstract base class for all cmaps. + // + // CMap equality is based on the equality of the (@link {@link CMapId} that + // defines the CMap. In the cmap table for a font there can only be one cmap + // with a given cmap id (pair of platform and encoding ids) no matter what the + // type of the cmap is. + // + // The cmap implements {@code Iterable} to allow iteration over + // characters that are mapped by the cmap. This iteration mostly returns the + // characters mapped by the cmap. It will return all characters mapped by the + // cmap to anything but .notdef but it may return some that are not + // mapped or are mapped to .notdef. Various cmap tables provide ranges and + // such to describe characters for lookup but without going the full way to + // mapping to the glyph id it isn't always possible to tell if a character + // will end up with a valid glyph id. So, some of the characters returned from + // the iterator may still end up pointing to the .notdef glyph. However, the + // number of such characters should be small in most cases with well designed + // cmaps. + class Builder; + class CMap : public SubTable { + public: + // CMapTable::CMap::Builder + class Builder : public SubTable::Builder { + public: + virtual ~Builder(); + + CALLER_ATTACH static Builder* + GetBuilder(FontDataTableBuilderContainer* container, + ReadableFontData* data, + int32_t offset, + const CMapId& cmap_id); + + // Note: yes, an object is returned on stack since it's small enough. + virtual CMapId cmap_id() { return cmap_id_; } + virtual int32_t platform_id() { return cmap_id_.platform_id(); } + virtual int32_t encoding_id() { return cmap_id_.encoding_id(); } + + protected: + Builder(FontDataTableBuilderContainer* container, + ReadableFontData* data, + int32_t format, + const CMapId& cmap_id); + Builder(FontDataTableBuilderContainer* container, + WritableFontData* data, + int32_t format, + const CMapId& cmap_id); + + virtual int32_t SubSerialize(WritableFontData* new_data); + virtual bool SubReadyToSerialize(); + virtual int32_t SubDataSizeToSerialize(); + virtual void SubDataSet(); + + private: + int32_t format_; + CMapId cmap_id_; + + friend class CMapTable::Builder; + }; + + CMap(ReadableFontData* data, int32_t format, const CMapId& cmap_id); + virtual ~CMap(); + virtual int32_t format() { return format_; } + virtual CMapId cmap_id() { return cmap_id_; } + virtual int32_t platform_id() { return cmap_id_.platform_id(); } + virtual int32_t encoding_id() { return cmap_id_.encoding_id(); } + + // Get the language of the cmap. + // + // Note on the language field in 'cmap' subtables: The language field must + // be set to zero for all cmap subtables whose platform IDs are other than + // Macintosh (platform ID 1). For cmap subtables whose platform IDs are + // Macintosh, set this field to the Macintosh language ID of the cmap + // subtable plus one, or to zero if the cmap subtable is not + // language-specific. For example, a Mac OS Turkish cmap subtable must set + // this field to 18, since the Macintosh language ID for Turkish is 17. A + // Mac OS Roman cmap subtable must set this field to 0, since Mac OS Roman + // is not a language-specific encoding. + // + // @return the language id + virtual int32_t Language() = 0; + + // Gets the glyph id for the character code provided. + // The character code provided must be in the encoding used by the cmap + // table. + virtual int32_t GlyphId(int32_t character) = 0; + + private: + int32_t format_; + CMapId cmap_id_; + }; + typedef Ptr CMapBuilderPtr; + typedef std::map CMapBuilderMap; + + // A cmap format 0 sub table + class CMapFormat0 : public CMap, public RefCounted { + public: + // CMapTable::CMapFormat0::Builder + class Builder : public CMap::Builder, + public RefCounted { + public: + Builder(FontDataTableBuilderContainer* container, + ReadableFontData* data, + int32_t offset, + const CMapId& cmap_id); + Builder(FontDataTableBuilderContainer* container, + WritableFontData* data, + int32_t offset, + const CMapId& cmap_id); + virtual ~Builder(); + + protected: + virtual CALLER_ATTACH FontDataTable* + SubBuildTable(ReadableFontData* data); + }; + + virtual ~CMapFormat0(); + virtual int32_t Language(); + virtual int32_t GlyphId(int32_t character); + + private: + CMapFormat0(ReadableFontData* data, const CMapId& cmap_id); + }; + + // A cmap format 2 sub table + // The format 2 cmap is used for multi-byte encodings such as SJIS, + // EUC-JP/KR/CN, Big5, etc. + class CMapFormat2 : public CMap, public RefCounted { + public: + // CMapTable::CMapFormat2::Builder + class Builder : public CMap::Builder, + public RefCounted { + public: + Builder(FontDataTableBuilderContainer* container, + ReadableFontData* data, + int32_t offset, + const CMapId& cmap_id); + Builder(FontDataTableBuilderContainer* container, + WritableFontData* data, + int32_t offset, + const CMapId& cmap_id); + virtual ~Builder(); + + protected: + virtual CALLER_ATTACH FontDataTable* + SubBuildTable(ReadableFontData* data); + }; + + virtual ~CMapFormat2(); + virtual int32_t Language(); + virtual int32_t GlyphId(int32_t character); + + // Returns how many bytes would be consumed by a lookup of this character + // with this cmap. This comes about because the cmap format 2 table is + // designed around multi-byte encodings such as SJIS, EUC-JP, Big5, etc. + // return the number of bytes consumed from this "character" - either 1 or 2 + virtual int32_t BytesConsumed(int32_t character); + + private: + CMapFormat2(ReadableFontData* data, const CMapId& cmap_id); + + int32_t SubHeaderOffset(int32_t sub_header_index); + int32_t FirstCode(int32_t sub_header_index); + int32_t EntryCount(int32_t sub_header_index); + int32_t IdRangeOffset(int32_t sub_header_index); + int32_t IdDelta(int32_t sub_header_index); + }; + + // CMapTable::Builder + class Builder : public Table::ArrayElementTableBuilder, + public RefCounted { + public: + // Constructor scope altered to public because C++ does not allow base + // class to instantiate derived class with protected constructors. + Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data); + Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data); + virtual ~Builder(); + + virtual int32_t SubSerialize(WritableFontData* new_data); + virtual bool SubReadyToSerialize(); + virtual int32_t SubDataSizeToSerialize(); + virtual void SubDataSet(); + virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); + + protected: + static CALLER_ATTACH CMap::Builder* + CMapBuilder(FontDataTableBuilderContainer* container, + ReadableFontData* data, + int32_t index); + + private: + static int32_t NumCMaps(ReadableFontData* data); + + int32_t version_; + CMapBuilderMap cmap_builders_; + }; + + virtual ~CMapTable(); + + // Get the table version. + virtual int32_t Version(); + + // Get the number of cmaps within the CMap table. + virtual int32_t NumCMaps(); + + // Get the cmap id for the cmap with the given index. + // Note: yes, an object is returned on stack since it's small enough. + // This function is renamed from cmapId to GetCMapId(). + virtual CMapId GetCMapId(int32_t index); + + virtual int32_t PlatformId(int32_t index); + virtual int32_t EncodingId(int32_t index); + + // Get the offset in the table data for the cmap table with the given index. + // The offset is from the beginning of the table. + virtual int32_t Offset(int32_t index); + + private: + static const int32_t NOTDEF; + + // Offsets to specific elements in the underlying data. These offsets are + // relative to the start of the table or the start of sub-blocks within + // the table. + struct Offset { + enum { + kVersion = 0, + kNumTables = 2, + kEncodingRecordStart = 4, + + // offsets relative to the encoding record + kEncodingRecordPlatformId = 0, + kEncodingRecordEncodingId = 2, + kEncodingRecordOffset = 4, + kEncodingRecordSize = 8, + + kFormat = 0, + + // Format 0: Byte encoding table + kFormat0Format = 0, + kFormat0Length = 2, + kFormat0Language = 4, + kFormat0GlyphIdArray = 6, + + // Format 2: High-byte mapping through table + kFormat2Format = 0, + kFormat2Length = 2, + kFormat2Language = 4, + kFormat2SubHeaderKeys = 6, + kFormat2SubHeaders = 518, + // offset relative to the subHeader structure + kFormat2SubHeader_firstCode = 0, + kFormat2SubHeader_entryCount = 2, + kFormat2SubHeader_idDelta = 4, + kFormat2SubHeader_idRangeOffset = 6, + kFormat2SubHeader_structLength = 8, + + // Format 4: Segment mapping to delta values + kFormat4Format = 0, + kFormat4Length = 2, + kFormat4Language = 4, + kFormat4SegCountX2 = 6, + kFormat4SearchRange = 8, + kFormat4EntrySelector = 10, + kFormat4RangeShift = 12, + kFormat4EndCount = 14, + + // format 6: Trimmed table mapping + kFormat6Format = 0, + kFormat6Length = 2, + kFormat6Language = 4, + kFormat6FirstCode = 6, + kFormat6EntryCount = 8, + kFormat6GlyphIdArray = 10, + + // Format 8: mixed 16-bit and 32-bit coverage + kFormat8Format = 0, + kFormat8Length = 4, + kFormat8Language = 8, + kFormat8Is32 = 12, + kFormat8nGroups204 = 8204, + kFormat8Groups208 = 8208, + // offset relative to the group structure + kFormat8Group_startCharCode = 0, + kFormat8Group_endCharCode = 4, + kFormat8Group_startGlyphId = 8, + kFormat8Group_structLength = 12, + + // Format 10: Trimmed array + kFormat10Format = 0, + kFormat10Length = 4, + kFormat10Language = 8, + kFormat10StartCharCode = 12, + kFormat10NumChars = 16, + kFormat10Glyphs0 = 20, + + // Format 12: Segmented coverage + kFormat12Format = 0, + kFormat12Length = 4, + kFormat12Language = 8, + kFormat12nGroups = 12, + kFormat12Groups = 16, + kFormat12Groups_structLength = 12, + // offsets within the group structure + kFormat12_startCharCode = 0, + kFormat12_endCharCode = 4, + kFormat12_startGlyphId = 8, + + // Format 13: Last Resort Font + kFormat13Format = 0, + kFormat13Length = 4, + kFormat13Language = 8, + kFormat13nGroups = 12, + kFormat13Groups = 16, + kFormat13Groups_structLength = 12, + // offsets within the group structure + kFormat13_startCharCode = 0, + kFormat13_endCharCode = 4, + kFormat13_glyphId = 8, + + // Format 14: Unicode Variation Sequences + kFormat14Format = 0, + kFormat14Length = 2, + + // TODO(stuartg): finish tables + // Default UVS Table + + // Non-default UVS Table + kLast = -1 + }; + }; + + class CMapIterator { + public: + // If filter is NULL, filter through all tables. + CMapIterator(CMapTable* table, CMapFilter* filter); + bool HasNext(); + CMap* Next(); + + private: + int32_t table_index_; + CMapFilter* filter_; + CMapTable* table_; + }; + + CMapTable(Header* header, ReadableFontData* data); + + // Get the offset in the table data for the encoding record for the cmap with + // the given index. The offset is from the beginning of the table. + int32_t OffsetForEncodingRecord(int32_t index); +}; +typedef std::vector CMapIdList; +typedef Ptr CMapTablePtr; + +} // namespace sfntly + +#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_CMAP_TABLE_H_ diff --git a/sfntly/table/core/font_header_table.cc b/sfntly/table/core/font_header_table.cc new file mode 100644 index 0000000..da19258 --- /dev/null +++ b/sfntly/table/core/font_header_table.cc @@ -0,0 +1,259 @@ +/* + * 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 "sfntly/table/core/font_header_table.h" + +namespace sfntly { +/****************************************************************************** + * FontHeaderTable class + ******************************************************************************/ +FontHeaderTable::~FontHeaderTable() {} + +int32_t FontHeaderTable::TableVersion() { + return data_->ReadFixed(Offset::kTableVersion); +} + +int32_t FontHeaderTable::FontRevision() { + return data_->ReadFixed(Offset::kFontRevision); +} + +int64_t FontHeaderTable::ChecksumAdjustment() { + return data_->ReadULong(Offset::kCheckSumAdjustment); +} + +int64_t FontHeaderTable::MagicNumber() { + return data_->ReadULong(Offset::kMagicNumber); +} + +int32_t FontHeaderTable::FlagsAsInt() { + return data_->ReadUShort(Offset::kFlags); +} + +int32_t FontHeaderTable::UnitsPerEm() { + return data_->ReadUShort(Offset::kUnitsPerEm); +} + +int64_t FontHeaderTable::Created() { + return data_->ReadDateTimeAsLong(Offset::kCreated); +} + +int64_t FontHeaderTable::Modified() { + return data_->ReadDateTimeAsLong(Offset::kModified); +} + +int32_t FontHeaderTable::XMin() { + return data_->ReadUShort(Offset::kXMin); +} + +int32_t FontHeaderTable::YMin() { + return data_->ReadUShort(Offset::kYMin); +} + +int32_t FontHeaderTable::XMax() { + return data_->ReadUShort(Offset::kXMax); +} + +int32_t FontHeaderTable::YMax() { + return data_->ReadUShort(Offset::kYMax); +} + +int32_t FontHeaderTable::MacStyleAsInt() { + return data_->ReadUShort(Offset::kMacStyle); +} + +int32_t FontHeaderTable::LowestRecPPEM() { + return data_->ReadUShort(Offset::kLowestRecPPEM); +} + +int32_t FontHeaderTable::FontDirectionHint() { + return data_->ReadShort(Offset::kFontDirectionHint); +} + +int32_t FontHeaderTable::IndexToLocFormat() { + return data_->ReadShort(Offset::kIndexToLocFormat); +} + +int32_t FontHeaderTable::GlyphDataFormat() { + return data_->ReadShort(Offset::kGlyphDataFormat); +} + +FontHeaderTable::FontHeaderTable(Header* header, ReadableFontData* data) + : Table(header, data) { + IntegerList checksum_ranges; + checksum_ranges.push_back(0); + checksum_ranges.push_back(Offset::kCheckSumAdjustment); + checksum_ranges.push_back(Offset::kMagicNumber); + data_->SetCheckSumRanges(checksum_ranges); +} + +/****************************************************************************** + * FontHeaderTable::Builder class + ******************************************************************************/ +FontHeaderTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, + Header* header, WritableFontData* data) : + Table::TableBasedTableBuilder(font_builder, header, data) { +} + +FontHeaderTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, + Header* header, ReadableFontData* data) : + Table::TableBasedTableBuilder(font_builder, header, data) { +} + +FontHeaderTable::Builder::~Builder() {} + +CALLER_ATTACH FontDataTable* FontHeaderTable::Builder::SubBuildTable( + ReadableFontData* data) { + FontDataTablePtr table = new FontHeaderTable(header(), data); + return table.Detach(); +} + +int32_t FontHeaderTable::Builder::TableVersion() { + return down_cast(GetTable())->TableVersion(); +} + +void FontHeaderTable::Builder::SetTableVersion(int32_t version) { + InternalWriteData()->WriteFixed(Offset::kTableVersion, version); +} + +int32_t FontHeaderTable::Builder::FontRevision() { + return down_cast(GetTable())->FontRevision(); +} + +void FontHeaderTable::Builder::SetFontRevision(int32_t revision) { + InternalWriteData()->WriteFixed(Offset::kFontRevision, revision); +} + +int64_t FontHeaderTable::Builder::ChecksumAdjustment() { + return down_cast(GetTable())->ChecksumAdjustment(); +} + +void FontHeaderTable::Builder::SetChecksumAdjustment(int64_t adjustment) { + InternalWriteData()->WriteULong(Offset::kCheckSumAdjustment, adjustment); +} + +int64_t FontHeaderTable::Builder::MagicNumber() { + return down_cast(GetTable())->MagicNumber(); +} + +void FontHeaderTable::Builder::SetMagicNumber(int64_t magic_number) { + InternalWriteData()->WriteULong(Offset::kMagicNumber, magic_number); +} + +int32_t FontHeaderTable::Builder::FlagsAsInt() { + return down_cast(GetTable())->FlagsAsInt(); +} + +void FontHeaderTable::Builder::SetFlagsAsInt(int32_t flags) { + InternalWriteData()->WriteUShort(Offset::kFlags, flags); +} + +int32_t FontHeaderTable::Builder::UnitsPerEm() { + return down_cast(GetTable())->UnitsPerEm(); +} + +void FontHeaderTable::Builder::SetUnitsPerEm(int32_t units) { + InternalWriteData()->WriteUShort(Offset::kUnitsPerEm, units); +} + +int64_t FontHeaderTable::Builder::Created() { + return down_cast(GetTable())->Created(); +} + +void FontHeaderTable::Builder::SetCreated(int64_t date) { + InternalWriteData()->WriteDateTime(Offset::kCreated, date); +} + +int64_t FontHeaderTable::Builder::Modified() { + return down_cast(GetTable())->Modified(); +} + +void FontHeaderTable::Builder::SetModified(int64_t date) { + InternalWriteData()->WriteDateTime(Offset::kModified, date); +} + +int32_t FontHeaderTable::Builder::XMin() { + return down_cast(GetTable())->XMin(); +} + +void FontHeaderTable::Builder::SetXMin(int32_t xmin) { + InternalWriteData()->WriteShort(Offset::kXMin, xmin); +} + +int32_t FontHeaderTable::Builder::YMin() { + return down_cast(GetTable())->YMin(); +} + +void FontHeaderTable::Builder::SetYMin(int32_t ymin) { + InternalWriteData()->WriteShort(Offset::kYMin, ymin); +} + +int32_t FontHeaderTable::Builder::XMax() { + return down_cast(GetTable())->XMax(); +} + +void FontHeaderTable::Builder::SetXMax(int32_t xmax) { + InternalWriteData()->WriteShort(Offset::kXMax, xmax); +} + +int32_t FontHeaderTable::Builder::YMax() { + return down_cast(GetTable())->YMax(); +} + +void FontHeaderTable::Builder::SetYMax(int32_t ymax) { + InternalWriteData()->WriteShort(Offset::kYMax, ymax); +} + +int32_t FontHeaderTable::Builder::MacStyleAsInt() { + return down_cast(GetTable())->MacStyleAsInt(); +} + +void FontHeaderTable::Builder::SetMacStyleAsInt(int32_t style) { + InternalWriteData()->WriteUShort(Offset::kMacStyle, style); +} + +int32_t FontHeaderTable::Builder::LowestRecPPEM() { + return down_cast(GetTable())->LowestRecPPEM(); +} + +void FontHeaderTable::Builder::SetLowestRecPPEM(int32_t size) { + InternalWriteData()->WriteUShort(Offset::kLowestRecPPEM, size); +} + +int32_t FontHeaderTable::Builder::FontDirectionHint() { + return down_cast(GetTable())->FontDirectionHint(); +} + +void FontHeaderTable::Builder::SetFontDirectionHint(int32_t hint) { + InternalWriteData()->WriteShort(Offset::kFontDirectionHint, hint); +} + +int32_t FontHeaderTable::Builder::IndexToLocFormat() { + return down_cast(GetTable())->IndexToLocFormat(); +} + +void FontHeaderTable::Builder::SetIndexToLocFormat(int32_t format) { + InternalWriteData()->WriteShort(Offset::kIndexToLocFormat, format); +} + +int32_t FontHeaderTable::Builder::GlyphDataFormat() { + return down_cast(GetTable())->GlyphDataFormat(); +} + +void FontHeaderTable::Builder::SetGlyphDataFormat(int32_t format) { + InternalWriteData()->WriteShort(Offset::kGlyphDataFormat, format); +} + +} // namespace sfntly diff --git a/sfntly/table/core/font_header_table.h b/sfntly/table/core/font_header_table.h new file mode 100644 index 0000000..343e62c --- /dev/null +++ b/sfntly/table/core/font_header_table.h @@ -0,0 +1,167 @@ +/* + * 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. + */ + +#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_FONT_HEADER_TABLE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_FONT_HEADER_TABLE_H_ + +#include "sfntly/table/table.h" + +namespace sfntly { + +struct IndexToLocFormat { + enum { + kShortOffset = 0, + kLongOffset = 1 + }; +}; + +struct FontDirectionHint { + enum { + kFullyMixed = 0, + kOnlyStrongLTR = 1, + kStrongLTRAndNeutral = 2, + kOnlyStrongRTL = -1, + kStrongRTLAndNeutral = -2 + }; +}; + +class FontHeaderTable : public Table, public RefCounted { + public: + class Builder : public Table::TableBasedTableBuilder, + public RefCounted { + public: + // Constructor scope altered to public because C++ does not allow base + // class to instantiate derived class with protected constructors. + Builder(FontDataTableBuilderContainer* font_builder, Header* header, + WritableFontData* data); + Builder(FontDataTableBuilderContainer* font_builder, Header* header, + ReadableFontData* data); + virtual ~Builder(); + virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); + + virtual int32_t TableVersion(); + virtual void SetTableVersion(int32_t version); + virtual int32_t FontRevision(); + virtual void SetFontRevision(int32_t revision); + virtual int64_t ChecksumAdjustment(); + virtual void SetChecksumAdjustment(int64_t adjustment); + virtual int64_t MagicNumber(); + virtual void SetMagicNumber(int64_t magic_number); + virtual int32_t FlagsAsInt(); + virtual void SetFlagsAsInt(int32_t flags); + // TODO(arthurhsu): IMPLEMENT EnumSet Flags() + // TODO(arthurhsu): IMPLEMENT setFlags(EnumSet flags) + virtual int32_t UnitsPerEm(); + virtual void SetUnitsPerEm(int32_t units); + virtual int64_t Created(); + virtual void SetCreated(int64_t date); + virtual int64_t Modified(); + virtual void SetModified(int64_t date); + virtual int32_t XMin(); + virtual void SetXMin(int32_t xmin); + virtual int32_t YMin(); + virtual void SetYMin(int32_t ymin); + virtual int32_t XMax(); + virtual void SetXMax(int32_t xmax); + virtual int32_t YMax(); + virtual void SetYMax(int32_t ymax); + virtual int32_t MacStyleAsInt(); + virtual void SetMacStyleAsInt(int32_t style); + // TODO(arthurhsu): IMPLEMENT EnumSet macStyle() + // TODO(arthurhsu): IMPLEMENT setMacStyle(EnumSet style) + virtual int32_t LowestRecPPEM(); + virtual void SetLowestRecPPEM(int32_t size); + virtual int32_t FontDirectionHint(); + virtual void SetFontDirectionHint(int32_t hint); + virtual int32_t IndexToLocFormat(); + virtual void SetIndexToLocFormat(int32_t format); + virtual int32_t GlyphDataFormat(); + virtual void SetGlyphDataFormat(int32_t format); + }; + + virtual ~FontHeaderTable(); + int32_t TableVersion(); + int32_t FontRevision(); + + // Get the checksum adjustment. To compute: set it to 0, sum the entire font + // as ULONG, then store 0xB1B0AFBA - sum. + int64_t ChecksumAdjustment(); + + // Get the magic number. Set to 0x5F0F3CF5. + int64_t MagicNumber(); + + // TODO(arthurhsu): IMPLEMENT: EnumSet + int32_t FlagsAsInt(); + // TODO(arthurhsu): IMPLEMENT: Flags() returning EnumSet + + int32_t UnitsPerEm(); + + // Get the created date. Number of seconds since 12:00 midnight, January 1, + // 1904. 64-bit integer. + int64_t Created(); + // Get the modified date. Number of seconds since 12:00 midnight, January 1, + // 1904. 64-bit integer. + int64_t Modified(); + + // Get the x min. For all glyph bounding boxes. + int32_t XMin(); + // Get the y min. For all glyph bounding boxes. + int32_t YMin(); + // Get the x max. For all glyph bounding boxes. + int32_t XMax(); + // Get the y max. For all glyph bounding boxes. + int32_t YMax(); + + // TODO(arthurhsu): IMPLEMENT: EnumSet + int32_t MacStyleAsInt(); + // TODO(arthurhsu): IMPLEMENT: macStyle() returning EnumSet + + int32_t LowestRecPPEM(); + int32_t FontDirectionHint(); // Note: no AsInt() form, already int + int32_t IndexToLocFormat(); // Note: no AsInt() form, already int + int32_t GlyphDataFormat(); + + private: + struct Offset { + enum { + kTableVersion = 0, + kFontRevision = 4, + kCheckSumAdjustment = 8, + kMagicNumber = 12, + kFlags = 16, + kUnitsPerEm = 18, + kCreated = 20, + kModified = 28, + kXMin = 36, + kYMin = 38, + kXMax = 40, + kYMax = 42, + kMacStyle = 44, + kLowestRecPPEM = 46, + kFontDirectionHint = 48, + kIndexToLocFormat = 50, + kGlyphDataFormat = 52 + }; + }; + + FontHeaderTable(Header* header, ReadableFontData* data); +}; +typedef Ptr FontHeaderTablePtr; +typedef Ptr FontHeaderTableBuilderPtr; + +} // namespace sfntly + +#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_FONT_HEADER_TABLE_H_ diff --git a/sfntly/table/core/horizontal_header_table.cc b/sfntly/table/core/horizontal_header_table.cc new file mode 100644 index 0000000..52b0de2 --- /dev/null +++ b/sfntly/table/core/horizontal_header_table.cc @@ -0,0 +1,211 @@ +/* + * 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 "sfntly/table/core/horizontal_header_table.h" + +namespace sfntly { +/****************************************************************************** + * HorizontalHeaderTable class + ******************************************************************************/ +HorizontalHeaderTable:: ~HorizontalHeaderTable() {} + +int32_t HorizontalHeaderTable::Version() { + return data_->ReadFixed(Offset::kVersion); +} + +int32_t HorizontalHeaderTable::Ascender() { + return data_->ReadShort(Offset::kAscender); +} + +int32_t HorizontalHeaderTable::Descender() { + return data_->ReadShort(Offset::kDescender); +} + +int32_t HorizontalHeaderTable::LineGap() { + return data_->ReadShort(Offset::kLineGap); +} + +int32_t HorizontalHeaderTable::AdvanceWidthMax() { + return data_->ReadUShort(Offset::kAdvanceWidthMax); +} + +int32_t HorizontalHeaderTable::MinLeftSideBearing() { + return data_->ReadShort(Offset::kMinLeftSideBearing); +} + +int32_t HorizontalHeaderTable::MinRightSideBearing() { + return data_->ReadShort(Offset::kMinRightSideBearing); +} + +int32_t HorizontalHeaderTable::XMaxExtent() { + return data_->ReadShort(Offset::kXMaxExtent); +} + +int32_t HorizontalHeaderTable::CaretSlopeRise() { + return data_->ReadShort(Offset::kCaretSlopeRise); +} + +int32_t HorizontalHeaderTable::CaretSlopeRun() { + return data_->ReadShort(Offset::kCaretSlopeRun); +} + +int32_t HorizontalHeaderTable::CaretOffset() { + return data_->ReadShort(Offset::kCaretOffset); +} + +int32_t HorizontalHeaderTable::MetricDataFormat() { + return data_->ReadShort(Offset::kMetricDataFormat); +} + +int32_t HorizontalHeaderTable::NumberOfHMetrics() { + return data_->ReadUShort(Offset::kNumberOfHMetrics); +} + +HorizontalHeaderTable:: HorizontalHeaderTable(Header* header, + ReadableFontData* data) + : Table(header, data) { +} + +/****************************************************************************** + * HorizontalHeaderTable::Builder class + ******************************************************************************/ +HorizontalHeaderTable::Builder::Builder( + FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data) + : Table::TableBasedTableBuilder(font_builder, header, data) { +} + +HorizontalHeaderTable::Builder::Builder( + FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data) + : Table::TableBasedTableBuilder(font_builder, header, data) { +} + +HorizontalHeaderTable::Builder::~Builder() {} + +CALLER_ATTACH FontDataTable* + HorizontalHeaderTable::Builder::SubBuildTable(ReadableFontData* data) { + FontDataTablePtr table = new HorizontalHeaderTable(header(), data); + return table.Detach(); +} + +int32_t HorizontalHeaderTable::Builder::Version() { + return InternalReadData()->ReadFixed(Offset::kVersion); +} + +void HorizontalHeaderTable::Builder::SetVersion(int32_t version) { + InternalWriteData()->WriteFixed(Offset::kVersion, version); +} + +int32_t HorizontalHeaderTable::Builder::Ascender() { + return InternalReadData()->ReadShort(Offset::kAscender); +} + +void HorizontalHeaderTable::Builder::SetAscender(int32_t ascender) { + InternalWriteData()->WriteShort(Offset::kVersion, ascender); +} + +int32_t HorizontalHeaderTable::Builder::Descender() { + return InternalReadData()->ReadShort(Offset::kDescender); +} + +void HorizontalHeaderTable::Builder::SetDescender(int32_t descender) { + InternalWriteData()->WriteShort(Offset::kDescender, descender); +} + +int32_t HorizontalHeaderTable::Builder::LineGap() { + return InternalReadData()->ReadShort(Offset::kLineGap); +} + +void HorizontalHeaderTable::Builder::SetLineGap(int32_t line_gap) { + InternalWriteData()->WriteShort(Offset::kLineGap, line_gap); +} + +int32_t HorizontalHeaderTable::Builder::AdvanceWidthMax() { + return InternalReadData()->ReadUShort(Offset::kAdvanceWidthMax); +} + +void HorizontalHeaderTable::Builder::SetAdvanceWidthMax(int32_t value) { + InternalWriteData()->WriteUShort(Offset::kAdvanceWidthMax, value); +} + +int32_t HorizontalHeaderTable::Builder::MinLeftSideBearing() { + return InternalReadData()->ReadShort(Offset::kMinLeftSideBearing); +} + +void HorizontalHeaderTable::Builder::SetMinLeftSideBearing(int32_t value) { + InternalWriteData()->WriteShort(Offset::kMinLeftSideBearing, value); +} + +int32_t HorizontalHeaderTable::Builder::MinRightSideBearing() { + return InternalReadData()->ReadShort(Offset::kMinRightSideBearing); +} + +void HorizontalHeaderTable::Builder::SetMinRightSideBearing(int32_t value) { + InternalWriteData()->WriteShort(Offset::kMinRightSideBearing, value); +} + +int32_t HorizontalHeaderTable::Builder::XMaxExtent() { + return InternalReadData()->ReadShort(Offset::kXMaxExtent); +} + +void HorizontalHeaderTable::Builder::SetXMaxExtent(int32_t value) { + InternalWriteData()->WriteShort(Offset::kXMaxExtent, value); +} + +int32_t HorizontalHeaderTable::Builder::CaretSlopeRise() { + return InternalReadData()->ReadUShort(Offset::kCaretSlopeRise); +} + +void HorizontalHeaderTable::Builder::SetCaretSlopeRise(int32_t value) { + InternalWriteData()->WriteUShort(Offset::kCaretSlopeRise, value); +} + +int32_t HorizontalHeaderTable::Builder::CaretSlopeRun() { + return InternalReadData()->ReadUShort(Offset::kCaretSlopeRun); +} + +void HorizontalHeaderTable::Builder::SetCaretSlopeRun(int32_t value) { + InternalWriteData()->WriteUShort(Offset::kCaretSlopeRun, value); +} + +int32_t HorizontalHeaderTable::Builder::CaretOffset() { + return InternalReadData()->ReadUShort(Offset::kCaretOffset); +} + +void HorizontalHeaderTable::Builder::SetCaretOffset(int32_t value) { + InternalWriteData()->WriteUShort(Offset::kCaretOffset, value); +} + +int32_t HorizontalHeaderTable::Builder::MetricDataFormat() { + return InternalReadData()->ReadUShort(Offset::kMetricDataFormat); +} + +void HorizontalHeaderTable::Builder::SetMetricDataFormat(int32_t value) { + InternalWriteData()->WriteUShort(Offset::kMetricDataFormat, value); +} + +int32_t HorizontalHeaderTable::Builder::NumberOfHMetrics() { + return InternalReadData()->ReadUShort(Offset::kNumberOfHMetrics); +} + +void HorizontalHeaderTable::Builder::SetNumberOfHMetrics(int32_t value) { + InternalWriteData()->WriteUShort(Offset::kNumberOfHMetrics, value); +} + +} // namespace sfntly diff --git a/sfntly/table/core/horizontal_header_table.h b/sfntly/table/core/horizontal_header_table.h new file mode 100644 index 0000000..3a3eb6f --- /dev/null +++ b/sfntly/table/core/horizontal_header_table.h @@ -0,0 +1,110 @@ +/* + * 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. + */ + +#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_HEADER_TABLE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_HEADER_TABLE_H_ + +#include "sfntly/table/table.h" + +namespace sfntly { + +class HorizontalHeaderTable : public Table, + public RefCounted { + public: + class Builder : public Table::TableBasedTableBuilder, + public RefCounted { + public: + // Constructor scope altered to public because C++ does not allow base + // class to instantiate derived class with protected constructors. + Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data); + Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data); + virtual ~Builder(); + virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); + + int32_t Version(); + void SetVersion(int32_t version); + int32_t Ascender(); + void SetAscender(int32_t ascender); + int32_t Descender(); + void SetDescender(int32_t descender); + int32_t LineGap(); + void SetLineGap(int32_t line_gap); + int32_t AdvanceWidthMax(); + void SetAdvanceWidthMax(int32_t value); + int32_t MinLeftSideBearing(); + void SetMinLeftSideBearing(int32_t value); + int32_t MinRightSideBearing(); + void SetMinRightSideBearing(int32_t value); + int32_t XMaxExtent(); + void SetXMaxExtent(int32_t value); + int32_t CaretSlopeRise(); + void SetCaretSlopeRise(int32_t value); + int32_t CaretSlopeRun(); + void SetCaretSlopeRun(int32_t value); + int32_t CaretOffset(); + void SetCaretOffset(int32_t value); + int32_t MetricDataFormat(); + void SetMetricDataFormat(int32_t value); + int32_t NumberOfHMetrics(); + void SetNumberOfHMetrics(int32_t value); + }; + + virtual ~HorizontalHeaderTable(); + int32_t Version(); + int32_t Ascender(); + int32_t Descender(); + int32_t LineGap(); + int32_t AdvanceWidthMax(); + int32_t MinLeftSideBearing(); + int32_t MinRightSideBearing(); + int32_t XMaxExtent(); + int32_t CaretSlopeRise(); + int32_t CaretSlopeRun(); + int32_t CaretOffset(); + int32_t MetricDataFormat(); + int32_t NumberOfHMetrics(); + + private: + struct Offset { + enum { + kVersion = 0, + kAscender = 4, + kDescender = 6, + kLineGap = 8, + kAdvanceWidthMax = 10, + kMinLeftSideBearing = 12, + kMinRightSideBearing = 14, + kXMaxExtent = 16, + kCaretSlopeRise = 18, + kCaretSlopeRun = 20, + kCaretOffset = 22, + kMetricDataFormat = 32, + kNumberOfHMetrics = 34, + }; + }; + + HorizontalHeaderTable(Header* header, ReadableFontData* data); +}; +typedef Ptr HorizontalHeaderTablePtr; +typedef Ptr HorizontalHeaderTableBuilderPtr; + +} // namespace sfntly + +#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_HEADER_TABLE_H_ diff --git a/sfntly/table/core/horizontal_metrics_table.cc b/sfntly/table/core/horizontal_metrics_table.cc new file mode 100644 index 0000000..b2463b9 --- /dev/null +++ b/sfntly/table/core/horizontal_metrics_table.cc @@ -0,0 +1,151 @@ +/* + * 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 "sfntly/table/core/horizontal_metrics_table.h" +#include "sfntly/port/exception_type.h" + +namespace sfntly { +/****************************************************************************** + * HorizontalMetricsTable class + ******************************************************************************/ +HorizontalMetricsTable::~HorizontalMetricsTable() {} + +int32_t HorizontalMetricsTable::NumberOfHMetrics() { + return num_hmetrics_; +} + +int32_t HorizontalMetricsTable::NumberOfLSBs() { + return num_glyphs_ - num_hmetrics_; +} + +int32_t HorizontalMetricsTable::HMetricAdvanceWidth(int32_t entry) { + if (entry > num_hmetrics_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else + throw IndexOutOfBoundException(); +#endif + } + int32_t offset = Offset::kHMetricsStart + (entry * Offset::kHMetricsSize) + + Offset::kHMetricsAdvanceWidth; + return data_->ReadUShort(offset); +} + +int32_t HorizontalMetricsTable::HMetricLSB(int32_t entry) { + if (entry > num_hmetrics_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else + throw IndexOutOfBoundException(); +#endif + } + int32_t offset = Offset::kHMetricsStart + (entry * Offset::kHMetricsSize) + + Offset::kHMetricsLeftSideBearing; + return data_->ReadShort(offset); +} + +int32_t HorizontalMetricsTable::LsbTableEntry(int32_t entry) { + if (entry > num_hmetrics_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else + throw IndexOutOfBoundException(); +#endif + } + int32_t offset = Offset::kHMetricsStart + (entry * Offset::kHMetricsSize) + + Offset::kLeftSideBearingSize; + return data_->ReadShort(offset); +} + +int32_t HorizontalMetricsTable::AdvanceWidth(int32_t glyph_id) { + if (glyph_id < num_hmetrics_) { + return HMetricAdvanceWidth(glyph_id); + } + return HMetricAdvanceWidth(glyph_id - num_hmetrics_); +} + +int32_t HorizontalMetricsTable::LeftSideBearing(int32_t glyph_id) { + if (glyph_id < num_hmetrics_) { + return HMetricLSB(glyph_id); + } + return LsbTableEntry(glyph_id - num_hmetrics_); +} + +HorizontalMetricsTable::HorizontalMetricsTable(Header* header, + ReadableFontData* data) + : Table(header, data) { +} + +HorizontalMetricsTable::HorizontalMetricsTable(Header* header, + ReadableFontData* data, + int32_t num_hmetrics, + int32_t num_glyphs) + : Table(header, data), + num_hmetrics_(num_hmetrics), + num_glyphs_(num_glyphs) { +} + +/****************************************************************************** + * HorizontalMetricsTable::Builder class + ******************************************************************************/ +HorizontalMetricsTable::Builder::Builder( + FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data) + : Table::TableBasedTableBuilder(font_builder, header, data) { + Init(); +} + +HorizontalMetricsTable::Builder::Builder( + FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data) + : Table::TableBasedTableBuilder(font_builder, header, data) { + Init(); +} + +HorizontalMetricsTable::Builder::~Builder() {} + +CALLER_ATTACH FontDataTable* + HorizontalMetricsTable::Builder::SubBuildTable(ReadableFontData* data) { + FontDataTablePtr table = + new HorizontalMetricsTable(header(), data, num_hmetrics_, num_glyphs_); + return table.Detach(); +} + +void HorizontalMetricsTable::Builder::SetNumberOfHMetrics( + int32_t num_hmetrics) { + assert(num_hmetrics >= 0); + num_hmetrics_ = num_hmetrics; + HorizontalMetricsTable* table = + down_cast(this->GetTable()); + table->num_hmetrics_ = num_hmetrics; +} + +void HorizontalMetricsTable::Builder::SetNumGlyphs(int32_t num_glyphs) { + assert(num_glyphs >= 0); + num_glyphs_ = num_glyphs; + HorizontalMetricsTable* table = + down_cast(this->GetTable()); + table->num_glyphs_ = num_glyphs; +} + +void HorizontalMetricsTable::Builder::Init() { + num_hmetrics_ = -1; + num_glyphs_ = -1; +} + +} // namespace sfntly diff --git a/sfntly/table/core/horizontal_metrics_table.h b/sfntly/table/core/horizontal_metrics_table.h new file mode 100644 index 0000000..aa3fa65 --- /dev/null +++ b/sfntly/table/core/horizontal_metrics_table.h @@ -0,0 +1,89 @@ +/* + * 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. + */ + +#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_METRICS_TABLE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_METRICS_TABLE_H_ + +#include "sfntly/table/table.h" + +namespace sfntly { + +class HorizontalMetricsTable : public Table, + public RefCounted { + public: + class Builder : public Table::TableBasedTableBuilder, + public RefCounted { + public: + // Constructor scope altered to public because C++ does not allow base + // class to instantiate derived class with protected constructors. + Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data); + Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data); + virtual ~Builder(); + + virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); + void SetNumberOfHMetrics(int32_t num_hmetrics); + void SetNumGlyphs(int32_t num_glyphs); + + private: + void Init(); + + int32_t num_hmetrics_; + int32_t num_glyphs_; + }; + + virtual ~HorizontalMetricsTable(); + int32_t NumberOfHMetrics(); + int32_t NumberOfLSBs(); + int32_t HMetricAdvanceWidth(int32_t entry); + int32_t HMetricLSB(int32_t entry); + int32_t LsbTableEntry(int32_t entry); + int32_t AdvanceWidth(int32_t glyph_id); + int32_t LeftSideBearing(int32_t glyph_id); + + private: + struct Offset { + enum { + // hMetrics + kHMetricsStart = 0, + kHMetricsSize = 4, + + // Offset within an hMetric + kHMetricsAdvanceWidth = 0, + kHMetricsLeftSideBearing = 2, + + kLeftSideBearingSize = 2 + }; + }; + + HorizontalMetricsTable(Header* header, ReadableFontData* data); + HorizontalMetricsTable(Header* header, + ReadableFontData* data, + int32_t num_hmetrics, + int32_t num_glyphs); + + int32_t num_hmetrics_; + int32_t num_glyphs_; +}; +typedef Ptr HorizontalMetricsTablePtr; +typedef Ptr HorizontalMetricsTableBuilderPtr; + +} // namespace sfntly + +#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_METRICS_TABLE_H_ diff --git a/sfntly/table/core/maximum_profile_table.cc b/sfntly/table/core/maximum_profile_table.cc new file mode 100644 index 0000000..fec508a --- /dev/null +++ b/sfntly/table/core/maximum_profile_table.cc @@ -0,0 +1,224 @@ +/* + * 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 "sfntly/table/core/maximum_profile_table.h" + +namespace sfntly { +/****************************************************************************** + * MaximumProfileTable class + ******************************************************************************/ +MaximumProfileTable::~MaximumProfileTable() {} + +int32_t MaximumProfileTable::Version() { + return data_->ReadFixed(Offset::kVersion); +} + +int32_t MaximumProfileTable::NumGlyphs() { + return data_->ReadUShort(Offset::kNumGlyphs); +} + +int32_t MaximumProfileTable::MaxPoints() { + return data_->ReadUShort(Offset::kMaxPoints); +} + +int32_t MaximumProfileTable::MaxContours() { + return data_->ReadUShort(Offset::kMaxContours); +} + +int32_t MaximumProfileTable::MaxCompositePoints() { + return data_->ReadUShort(Offset::kMaxCompositePoints); +} + +int32_t MaximumProfileTable::MaxZones() { + return data_->ReadUShort(Offset::kMaxZones); +} + +int32_t MaximumProfileTable::MaxTwilightPoints() { + return data_->ReadUShort(Offset::kMaxTwilightPoints); +} + +int32_t MaximumProfileTable::MaxStorage() { + return data_->ReadUShort(Offset::kMaxStorage); +} + +int32_t MaximumProfileTable::MaxFunctionDefs() { + return data_->ReadUShort(Offset::kMaxFunctionDefs); +} + +int32_t MaximumProfileTable::MaxStackElements() { + return data_->ReadUShort(Offset::kMaxStackElements); +} + +int32_t MaximumProfileTable::MaxSizeOfInstructions() { + return data_->ReadUShort(Offset::kMaxSizeOfInstructions); +} + +int32_t MaximumProfileTable::MaxComponentElements() { + return data_->ReadUShort(Offset::kMaxComponentElements); +} + +int32_t MaximumProfileTable::MaxComponentDepth() { + return data_->ReadUShort(Offset::kMaxComponentDepth); +} + +MaximumProfileTable::MaximumProfileTable(Header* header, + ReadableFontData* data) + : Table(header, data) { +} + +/****************************************************************************** + * MaximumProfileTable::Builder class + ******************************************************************************/ +MaximumProfileTable::Builder::Builder( + FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data) + : Table::TableBasedTableBuilder(font_builder, header, data) { +} + +MaximumProfileTable::Builder::Builder( + FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data) + : Table::TableBasedTableBuilder(font_builder, header, data) { +} + +MaximumProfileTable::Builder::~Builder() {} + +CALLER_ATTACH FontDataTable* + MaximumProfileTable::Builder::SubBuildTable(ReadableFontData* data) { + FontDataTablePtr table = new MaximumProfileTable(header(), data); + return table.Detach(); +} + +int32_t MaximumProfileTable::Builder::Version() { + return InternalReadData()->ReadUShort(Offset::kVersion); +} + +void MaximumProfileTable::Builder::SetVersion(int32_t version) { + InternalWriteData()->WriteUShort(Offset::kVersion, version); +} + +int32_t MaximumProfileTable::Builder::NumGlyphs() { + return InternalReadData()->ReadUShort(Offset::kNumGlyphs); +} + +void MaximumProfileTable::Builder::SetNumGlyphs(int32_t num_glyphs) { + InternalWriteData()->WriteUShort(Offset::kNumGlyphs, num_glyphs); +} + +int32_t MaximumProfileTable::Builder::MaxPoints() { + return InternalReadData()->ReadUShort(Offset::kMaxPoints); +} + +void MaximumProfileTable::Builder::SetMaxPoints(int32_t max_points) { + InternalWriteData()->WriteUShort(Offset::kMaxPoints, max_points); +} + +int32_t MaximumProfileTable::Builder::MaxContours() { + return InternalReadData()->ReadUShort(Offset::kMaxContours); +} + +void MaximumProfileTable::Builder::SetMaxContours(int32_t max_contours) { + InternalWriteData()->WriteUShort(Offset::kMaxContours, max_contours); +} + +int32_t MaximumProfileTable::Builder::MaxCompositePoints() { + return InternalReadData()->ReadUShort(Offset::kMaxCompositePoints); +} + +void MaximumProfileTable::Builder::SetMaxCompositePoints( + int32_t max_composite_points) { + InternalWriteData()->WriteUShort(Offset::kMaxCompositePoints, + max_composite_points); +} + +int32_t MaximumProfileTable::Builder::MaxZones() { + return InternalReadData()->ReadUShort(Offset::kMaxZones); +} + +void MaximumProfileTable::Builder::SetMaxZones(int32_t max_zones) { + InternalWriteData()->WriteUShort(Offset::kMaxZones, max_zones); +} + +int32_t MaximumProfileTable::Builder::MaxTwilightPoints() { + return InternalReadData()->ReadUShort(Offset::kMaxTwilightPoints); +} + +void MaximumProfileTable::Builder::SetMaxTwilightPoints( + int32_t max_twilight_points) { + InternalWriteData()->WriteUShort(Offset::kMaxTwilightPoints, + max_twilight_points); +} + +int32_t MaximumProfileTable::Builder::MaxStorage() { + return InternalReadData()->ReadUShort(Offset::kMaxStorage); +} + +void MaximumProfileTable::Builder::SetMaxStorage(int32_t max_storage) { + InternalWriteData()->WriteUShort(Offset::kMaxStorage, max_storage); +} + +int32_t MaximumProfileTable::Builder::MaxFunctionDefs() { + return InternalReadData()->ReadUShort(Offset::kMaxFunctionDefs); +} + +void MaximumProfileTable::Builder::SetMaxFunctionDefs( + int32_t max_function_defs) { + InternalWriteData()->WriteUShort(Offset::kMaxFunctionDefs, max_function_defs); +} + +int32_t MaximumProfileTable::Builder::MaxStackElements() { + return InternalReadData()->ReadUShort(Offset::kMaxStackElements); +} + +void MaximumProfileTable::Builder::SetMaxStackElements( + int32_t max_stack_elements) { + InternalWriteData()->WriteUShort(Offset::kMaxStackElements, + max_stack_elements); +} + +int32_t MaximumProfileTable::Builder::MaxSizeOfInstructions() { + return InternalReadData()->ReadUShort(Offset::kMaxSizeOfInstructions); +} + +void MaximumProfileTable::Builder::SetMaxSizeOfInstructions( + int32_t max_size_of_instructions) { + InternalWriteData()->WriteUShort(Offset::kMaxSizeOfInstructions, + max_size_of_instructions); +} + +int32_t MaximumProfileTable::Builder::MaxComponentElements() { + return InternalReadData()->ReadUShort(Offset::kMaxComponentElements); +} + +void MaximumProfileTable::Builder::SetMaxComponentElements( + int32_t max_component_elements) { + InternalWriteData()->WriteUShort(Offset::kMaxComponentElements, + max_component_elements); +} + +int32_t MaximumProfileTable::Builder::MaxComponentDepth() { + return InternalReadData()->ReadUShort(Offset::kMaxComponentDepth); +} + +void MaximumProfileTable::Builder::SetMaxComponentDepth( + int32_t max_component_depth) { + InternalWriteData()->WriteUShort(Offset::kMaxComponentDepth, + max_component_depth); +} + +} // namespace sfntly diff --git a/sfntly/table/core/maximum_profile_table.h b/sfntly/table/core/maximum_profile_table.h new file mode 100644 index 0000000..10ec872 --- /dev/null +++ b/sfntly/table/core/maximum_profile_table.h @@ -0,0 +1,115 @@ +/* + * 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. + */ + +#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_MAXIMUM_PROFILE_TABLE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_MAXIMUM_PROFILE_TABLE_H_ + +#include "sfntly/port/refcount.h" +#include "sfntly/table/table.h" + +namespace sfntly { + +class MaximumProfileTable : public Table, + public RefCounted { + public: + class Builder : public Table::TableBasedTableBuilder, + public RefCounted { + public: + // Constructor scope altered to public because C++ does not allow base + // class to instantiate derived class with protected constructors. + Builder(FontDataTableBuilderContainer* font_builder, Header* header, + WritableFontData* data); + Builder(FontDataTableBuilderContainer* font_builder, Header* header, + ReadableFontData* data); + virtual ~Builder(); + + virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); + + int32_t Version(); + void SetVersion(int32_t version); + int32_t NumGlyphs(); + void SetNumGlyphs(int32_t num_glyphs); + int32_t MaxPoints(); + void SetMaxPoints(int32_t max_points); + int32_t MaxContours(); + void SetMaxContours(int32_t max_contours); + int32_t MaxCompositePoints(); + void SetMaxCompositePoints(int32_t max_composite_points); + int32_t MaxZones(); + void SetMaxZones(int32_t max_zones); + int32_t MaxTwilightPoints(); + void SetMaxTwilightPoints(int32_t max_twilight_points); + int32_t MaxStorage(); + void SetMaxStorage(int32_t max_storage); + int32_t MaxFunctionDefs(); + void SetMaxFunctionDefs(int32_t max_function_defs); + int32_t MaxStackElements(); + void SetMaxStackElements(int32_t max_stack_elements); + int32_t MaxSizeOfInstructions(); + void SetMaxSizeOfInstructions(int32_t max_size_of_instructions); + int32_t MaxComponentElements(); + void SetMaxComponentElements(int32_t max_component_elements); + int32_t MaxComponentDepth(); + void SetMaxComponentDepth(int32_t max_component_depth); + }; + + virtual ~MaximumProfileTable(); + int32_t Version(); + int32_t NumGlyphs(); + int32_t MaxPoints(); + int32_t MaxContours(); + int32_t MaxCompositePoints(); + int32_t MaxZones(); + int32_t MaxTwilightPoints(); + int32_t MaxStorage(); + int32_t MaxFunctionDefs(); + int32_t MaxStackElements(); + int32_t MaxSizeOfInstructions(); + int32_t MaxComponentElements(); + int32_t MaxComponentDepth(); + + private: + struct Offset { + enum { + // version 0.5 and 1.0 + kVersion = 0, + kNumGlyphs = 4, + + // version 1.0 + kMaxPoints = 6, + kMaxContours = 8, + kMaxCompositePoints = 10, + kMaxCompositeContours = 12, + kMaxZones = 14, + kMaxTwilightPoints = 16, + kMaxStorage = 18, + kMaxFunctionDefs = 20, + kMaxInstructionDefs = 22, + kMaxStackElements = 24, + kMaxSizeOfInstructions = 26, + kMaxComponentElements = 28, + kMaxComponentDepth = 30, + }; + }; + + MaximumProfileTable(Header* header, ReadableFontData* data); +}; +typedef Ptr MaximumProfileTablePtr; +typedef Ptr MaximumProfileTableBuilderPtr; + +} // namespace sfntly + +#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_MAXIMUM_PROFILE_TABLE_H_ diff --git a/sfntly/table/core/name_table.cc b/sfntly/table/core/name_table.cc new file mode 100644 index 0000000..00c4519 --- /dev/null +++ b/sfntly/table/core/name_table.cc @@ -0,0 +1,722 @@ +/* + * 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 "sfntly/table/core/name_table.h" + +#include +#include + +#include + +#include "sfntly/font.h" +#include "sfntly/port/exception_type.h" + +namespace sfntly { +/****************************************************************************** + * NameTable::NameEntryId class + ******************************************************************************/ +NameTable::NameEntryId::NameEntryId() + : platform_id_(0), + encoding_id_(0), + language_id_(0), + name_id_(0) { +} + +NameTable::NameEntryId::NameEntryId(int32_t platform_id, + int32_t encoding_id, + int32_t language_id, + int32_t name_id) + : platform_id_(platform_id), + encoding_id_(encoding_id), + language_id_(language_id), + name_id_(name_id) { +} + +NameTable::NameEntryId::NameEntryId(const NameTable::NameEntryId& rhs) { + *this = rhs; +} + +const NameTable::NameEntryId& + NameTable::NameEntryId::operator=(const NameTable::NameEntryId& rhs) const { + platform_id_ = rhs.platform_id_; + encoding_id_ = rhs.encoding_id_; + language_id_ = rhs.language_id_; + name_id_ = rhs.name_id_; + return *this; +} + +bool NameTable::NameEntryId::operator==(const NameEntryId& rhs) const { + return platform_id_ == rhs.platform_id_ && + encoding_id_ == rhs.encoding_id_ && + language_id_ == rhs.language_id_ && + name_id_ == rhs.name_id_; +} + +bool NameTable::NameEntryId::operator<(const NameEntryId& rhs) const { + if (platform_id_ != rhs.platform_id_) return platform_id_ < rhs.platform_id_; + if (encoding_id_ != rhs.encoding_id_) return encoding_id_ < rhs.encoding_id_; + if (language_id_ != rhs.language_id_) return language_id_ < rhs.language_id_; + return name_id_ < rhs.name_id_; +} + +/****************************************************************************** + * NameTable::NameEntry class + ******************************************************************************/ +NameTable::NameEntry::NameEntry() { + Init(0, 0, 0, 0, NULL); +} + +NameTable::NameEntry::NameEntry(const NameEntryId& name_entry_id, + const ByteVector& name_bytes) { + Init(name_entry_id.platform_id(), + name_entry_id.encoding_id(), + name_entry_id.language_id(), + name_entry_id.name_id(), + &name_bytes); +} + +NameTable::NameEntry::NameEntry(int32_t platform_id, + int32_t encoding_id, + int32_t language_id, + int32_t name_id, + const ByteVector& name_bytes) { + Init(platform_id, encoding_id, language_id, name_id, &name_bytes); +} + +NameTable::NameEntry::~NameEntry() {} + +ByteVector* NameTable::NameEntry::NameAsBytes() { + return &name_bytes_; +} + +int32_t NameTable::NameEntry::NameBytesLength() { + return name_bytes_.size(); +} + +UChar* NameTable::NameEntry::Name() { + return NameTable::ConvertFromNameBytes(&name_bytes_, + platform_id(), + encoding_id()); +} + +bool NameTable::NameEntry::operator==(const NameEntry& rhs) const { + return (name_entry_id_ == rhs.name_entry_id_ && + name_bytes_ == rhs.name_bytes_); +} + +void NameTable::NameEntry::Init(int32_t platform_id, + int32_t encoding_id, + int32_t language_id, + int32_t name_id, + const ByteVector* name_bytes) { + name_entry_id_ = NameEntryId(platform_id, encoding_id, language_id, name_id); + if (name_bytes) { + name_bytes_ = *name_bytes; + } else { + name_bytes_.clear(); + } +} + +/****************************************************************************** + * NameTable::NameEntryBuilder class + ******************************************************************************/ +NameTable::NameEntryBuilder::NameEntryBuilder() { + Init(0, 0, 0, 0, NULL); +} + +NameTable::NameEntryBuilder::NameEntryBuilder( + const NameEntryId& name_entry_id, const ByteVector& name_bytes) { + Init(name_entry_id.platform_id(), + name_entry_id.encoding_id(), + name_entry_id.language_id(), + name_entry_id.name_id(), + &name_bytes); +} + +NameTable::NameEntryBuilder::NameEntryBuilder( + const NameEntryId& name_entry_id) { + Init(name_entry_id.platform_id(), + name_entry_id.encoding_id(), + name_entry_id.language_id(), + name_entry_id.name_id(), + NULL); +} + +NameTable::NameEntryBuilder::NameEntryBuilder(NameEntry* b) { + Init(b->platform_id(), + b->encoding_id(), + b->language_id(), + b->name_id(), + b->NameAsBytes()); +} + +NameTable::NameEntryBuilder::~NameEntryBuilder() {} + +void NameTable::NameEntryBuilder::SetName(const UChar* name) { + if (name == NULL) { + name_entry_->name_bytes_.clear(); + return; + } + NameTable::ConvertToNameBytes(name, + name_entry_->platform_id(), + name_entry_->encoding_id(), + &name_entry_->name_bytes_); +} + +void NameTable::NameEntryBuilder::SetName(const ByteVector& name_bytes) { + name_entry_->name_bytes_.clear(); + std::copy(name_bytes.begin(), + name_bytes.end(), + name_entry_->name_bytes_.begin()); +} + +void NameTable::NameEntryBuilder::SetName(const ByteVector& name_bytes, + int32_t offset, + int32_t length) { + name_entry_->name_bytes_.clear(); + std::copy(name_bytes.begin() + offset, + name_bytes.begin() + offset + length, + name_entry_->name_bytes_.begin()); +} + +void NameTable::NameEntryBuilder::Init(int32_t platform_id, + int32_t encoding_id, + int32_t language_id, + int32_t name_id, + const ByteVector* name_bytes) { + name_entry_ = new NameEntry(); + name_entry_->Init(platform_id, encoding_id, language_id, name_id, name_bytes); +} + +/****************************************************************************** + * NameTable::NameEntryFilterInPlace class (C++ port only) + ******************************************************************************/ +NameTable::NameEntryFilterInPlace::NameEntryFilterInPlace(int32_t platform_id, + int32_t encoding_id, + int32_t language_id, + int32_t name_id) + : platform_id_(platform_id), + encoding_id_(encoding_id), + language_id_(language_id), + name_id_(name_id) { +} + +bool NameTable::NameEntryFilterInPlace::Accept(int32_t platform_id, + int32_t encoding_id, + int32_t language_id, + int32_t name_id) { + return (platform_id_ == platform_id && + encoding_id_ == encoding_id && + language_id_ == language_id && + name_id_ == name_id); +} + +/****************************************************************************** + * NameTable::NameEntryIterator class + ******************************************************************************/ +NameTable::NameEntryIterator::NameEntryIterator(NameTable* table) { + Init(table, NULL); +} + +NameTable::NameEntryIterator::NameEntryIterator(NameTable* table, + NameEntryFilter* filter) { + Init(table, filter); +} + +bool NameTable::NameEntryIterator::HasNext() { + if (!filter_) { + if (name_index_ < table_->NameCount()) { + return true; + } + return false; + } + for (; name_index_ < table_->NameCount(); ++name_index_) { + if (filter_->Accept(table_->PlatformId(name_index_), + table_->EncodingId(name_index_), + table_->LanguageId(name_index_), + table_->NameId(name_index_))) { + return true; + } + } + return false; +} + +CALLER_ATTACH NameTable::NameEntry* NameTable::NameEntryIterator::Next() { + if (!HasNext()) + return NULL; + return table_->GetNameEntry(name_index_++); +} + +void NameTable::NameEntryIterator::Remove() { +#if !defined (SFNTLY_NO_EXCEPTION) + throw UnsupportedOperationException( + "Cannot remove a CMap table from an existing font."); +#endif +} + +void NameTable::NameEntryIterator::Init(NameTable* table, + NameEntryFilter* filter) { + table_ = table; + filter_ = filter; + name_index_ = 0; +} + +/****************************************************************************** + * NameTable::Builder class + ******************************************************************************/ +NameTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data) + : Table::ArrayElementTableBuilder(font_builder, header, data) { +} + +NameTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data) + : Table::ArrayElementTableBuilder(font_builder, header, data) { +} + +void NameTable::Builder::RevertNames() { + name_entry_map_.clear(); + set_model_changed(false); +} + +int32_t NameTable::Builder::BuilderCount() { + GetNameBuilders(); // Ensure name_entry_map_ is built. + return (int32_t)name_entry_map_.size(); +} + +bool NameTable::Builder::Has(int32_t platform_id, + int32_t encoding_id, + int32_t language_id, + int32_t name_id) { + NameEntryId probe(platform_id, encoding_id, language_id, name_id); + GetNameBuilders(); // Ensure name_entry_map_ is built. + return (name_entry_map_.find(probe) != name_entry_map_.end()); +} + +CALLER_ATTACH NameTable::NameEntryBuilder* + NameTable::Builder::NameBuilder(int32_t platform_id, + int32_t encoding_id, + int32_t language_id, + int32_t name_id) { + NameEntryId probe(platform_id, encoding_id, language_id, name_id); + NameEntryBuilderMap builders; + GetNameBuilders(); // Ensure name_entry_map_ is built. + if (name_entry_map_.find(probe) != name_entry_map_.end()) { + return name_entry_map_[probe]; + } + NameEntryBuilderPtr builder = new NameEntryBuilder(probe); + name_entry_map_[probe] = builder; + return builder.Detach(); +} + +bool NameTable::Builder::Remove(int32_t platform_id, + int32_t encoding_id, + int32_t language_id, + int32_t name_id) { + NameEntryId probe(platform_id, encoding_id, language_id, name_id); + GetNameBuilders(); // Ensure name_entry_map_ is built. + NameEntryBuilderMap::iterator position = name_entry_map_.find(probe); + if (position != name_entry_map_.end()) { + name_entry_map_.erase(position); + return true; + } + return false; +} + +CALLER_ATTACH FontDataTable* + NameTable::Builder::SubBuildTable(ReadableFontData* data) { + FontDataTablePtr table = new NameTable(header(), data); + return table.Detach(); +} + +void NameTable::Builder::SubDataSet() { + name_entry_map_.clear(); + set_model_changed(false); +} + +int32_t NameTable::Builder::SubDataSizeToSerialize() { + if (name_entry_map_.empty()) { + return 0; + } + + int32_t size = NameTable::Offset::kNameRecordStart + + name_entry_map_.size() * NameTable::Offset::kNameRecordSize; + for (NameEntryBuilderMap::iterator b = name_entry_map_.begin(), + end = name_entry_map_.end(); + b != end; ++b) { + NameEntryBuilderPtr p = b->second; + NameEntry* entry = p->name_entry(); + size += entry->NameBytesLength(); + } + return size; +} + +bool NameTable::Builder::SubReadyToSerialize() { + return !name_entry_map_.empty(); +} + +int32_t NameTable::Builder::SubSerialize(WritableFontData* new_data) { + int32_t string_table_start_offset = + NameTable::Offset::kNameRecordStart + + name_entry_map_.size() * NameTable::Offset::kNameRecordSize; + + // Header + new_data->WriteUShort(NameTable::Offset::kFormat, 0); + new_data->WriteUShort(NameTable::Offset::kCount, name_entry_map_.size()); + new_data->WriteUShort(NameTable::Offset::kStringOffset, + string_table_start_offset); + int32_t name_record_offset = NameTable::Offset::kNameRecordStart; + int32_t string_offset = 0; + // Note: we offered operator< in NameEntryId, which will be used by std::less, + // and therefore our map will act like TreeMap in Java to provide + // sorted key set. + for (NameEntryBuilderMap::iterator b = name_entry_map_.begin(), + end = name_entry_map_.end(); + b != end; ++b) { + new_data->WriteUShort( + name_record_offset + NameTable::Offset::kNameRecordPlatformId, + b->first.platform_id()); + new_data->WriteUShort( + name_record_offset + NameTable::Offset::kNameRecordEncodingId, + b->first.encoding_id()); + new_data->WriteUShort( + name_record_offset + NameTable::Offset::kNameRecordLanguageId, + b->first.language_id()); + new_data->WriteUShort( + name_record_offset + NameTable::Offset::kNameRecordNameId, + b->first.name_id()); + NameEntry* builder_entry = b->second->name_entry(); + new_data->WriteUShort( + name_record_offset + NameTable::Offset::kNameRecordStringLength, + builder_entry->NameBytesLength()); + new_data->WriteUShort( + name_record_offset + NameTable::Offset::kNameRecordStringOffset, + string_offset); + name_record_offset += NameTable::Offset::kNameRecordSize; + string_offset += new_data->WriteBytes( + string_offset + string_table_start_offset, + builder_entry->NameAsBytes()); + } + + return string_offset + string_table_start_offset; +} + +void NameTable::Builder::Initialize(ReadableFontData* data) { + if (data) { + NameTablePtr table = new NameTable(header(), data); + NameEntryIterator name_iter(table, NULL); + while (name_iter.HasNext()) { + NameEntryPtr name_entry; + name_entry.Attach(name_iter.Next()); + NameEntryBuilderPtr name_entry_builder = new NameEntryBuilder(name_entry); + NameEntry* builder_entry = name_entry_builder->name_entry(); + NameEntryId probe = builder_entry->name_entry_id(); + name_entry_map_[probe] = name_entry_builder; + } + } +} + +NameTable::NameEntryBuilderMap* NameTable::Builder::GetNameBuilders() { + if (name_entry_map_.empty()) { + Initialize(InternalReadData()); + } + set_model_changed(); + return &name_entry_map_; +} + +/****************************************************************************** + * NameTable class + ******************************************************************************/ +NameTable::~NameTable() {} + +int32_t NameTable::Format() { + return data_->ReadUShort(Offset::kFormat); +} + +int32_t NameTable::NameCount() { + return data_->ReadUShort(Offset::kCount); +} + +int32_t NameTable::PlatformId(int32_t index) { + return data_->ReadUShort(Offset::kNameRecordPlatformId + + OffsetForNameRecord(index)); +} + +int32_t NameTable::EncodingId(int32_t index) { + return data_->ReadUShort(Offset::kNameRecordEncodingId + + OffsetForNameRecord(index)); +} + +int32_t NameTable::LanguageId(int32_t index) { + return data_->ReadUShort(Offset::kNameRecordLanguageId + + OffsetForNameRecord(index)); +} + +int32_t NameTable::NameId(int32_t index) { + return data_->ReadUShort(Offset::kNameRecordNameId + + OffsetForNameRecord(index)); +} + +void NameTable::NameAsBytes(int32_t index, ByteVector* b) { + assert(b); + int32_t length = NameLength(index); + b->clear(); + b->resize(length); + data_->ReadBytes(NameOffset(index), &((*b)[0]), 0, length); +} + +void NameTable::NameAsBytes(int32_t platform_id, + int32_t encoding_id, + int32_t language_id, + int32_t name_id, + ByteVector* b) { + assert(b); + NameEntryPtr entry; + entry.Attach(GetNameEntry(platform_id, encoding_id, language_id, name_id)); + if (entry) { + ByteVector* name = entry->NameAsBytes(); + std::copy(name->begin(), name->end(), b->begin()); + } +} + +UChar* NameTable::Name(int32_t index) { + ByteVector b; + NameAsBytes(index, &b); + return ConvertFromNameBytes(&b, PlatformId(index), EncodingId(index)); +} + +UChar* NameTable::Name(int32_t platform_id, + int32_t encoding_id, + int32_t language_id, + int32_t name_id) { + NameEntryPtr entry; + entry.Attach(GetNameEntry(platform_id, encoding_id, language_id, name_id)); + if (entry) { + return entry->Name(); + } + return NULL; +} + +CALLER_ATTACH NameTable::NameEntry* NameTable::GetNameEntry(int32_t index) { + ByteVector b; + NameAsBytes(index, &b); + NameEntryPtr instance = new NameEntry(PlatformId(index), + EncodingId(index), + LanguageId(index), + NameId(index), b); + return instance.Detach(); +} + +CALLER_ATTACH NameTable::NameEntry* NameTable::GetNameEntry(int32_t platform_id, + int32_t encoding_id, + int32_t language_id, + int32_t name_id) { + NameTable::NameEntryFilterInPlace + filter(platform_id, encoding_id, language_id, name_id); + NameTable::NameEntryIterator* name_entry_iter = Iterator(&filter); + NameEntryPtr result; + if (name_entry_iter->HasNext()) { + result = name_entry_iter->Next(); + } + delete name_entry_iter; + return result; +} + +NameTable::NameEntryIterator* NameTable::Iterator() { + return new NameTable::NameEntryIterator(this); +} + +NameTable::NameEntryIterator* NameTable::Iterator(NameEntryFilter* filter) { + return new NameTable::NameEntryIterator(this, filter); +} + +NameTable::NameTable(Header* header, ReadableFontData* data) + : Table(header, data) {} + +int32_t NameTable::StringOffset() { + return data_->ReadUShort(Offset::kStringOffset); +} + +int32_t NameTable::OffsetForNameRecord(int32_t index) { + return Offset::kNameRecordStart + index * Offset::kNameRecordSize; +} + +int32_t NameTable::NameLength(int32_t index) { + return data_->ReadUShort(Offset::kNameRecordStringLength + + OffsetForNameRecord(index)); +} + +int32_t NameTable::NameOffset(int32_t index) { + return data_->ReadUShort(Offset::kNameRecordStringOffset + + OffsetForNameRecord(index)) + StringOffset(); +} + +const char* NameTable::GetEncodingName(int32_t platform_id, + int32_t encoding_id) { + switch (platform_id) { + case PlatformId::kUnicode: + return "UTF-16BE"; + case PlatformId::kMacintosh: + switch (encoding_id) { + case MacintoshEncodingId::kRoman: + return "MacRoman"; + case MacintoshEncodingId::kJapanese: + return "Shift-JIS"; + case MacintoshEncodingId::kChineseTraditional: + return "Big5"; + case MacintoshEncodingId::kKorean: + return "EUC-KR"; + case MacintoshEncodingId::kArabic: + return "MacArabic"; + case MacintoshEncodingId::kHebrew: + return "MacHebrew"; + case MacintoshEncodingId::kGreek: + return "MacGreek"; + case MacintoshEncodingId::kRussian: + return "MacCyrillic"; + case MacintoshEncodingId::kRSymbol: + return "MacSymbol"; + case MacintoshEncodingId::kThai: + return "MacThai"; + case MacintoshEncodingId::kChineseSimplified: + return "EUC-CN"; + default: // Note: unknown/unconfirmed cases are not ported. + break; + } + break; + case PlatformId::kISO: + break; + case PlatformId::kWindows: + switch (encoding_id) { + case WindowsEncodingId::kSymbol: + case WindowsEncodingId::kUnicodeUCS2: + return "UTF-16BE"; + case WindowsEncodingId::kShiftJIS: + return "windows-933"; + case WindowsEncodingId::kPRC: + return "windows-936"; + case WindowsEncodingId::kBig5: + return "windows-950"; + case WindowsEncodingId::kWansung: + return "windows-949"; + case WindowsEncodingId::kJohab: + return "ms1361"; + case WindowsEncodingId::kUnicodeUCS4: + return "UCS-4"; + } + break; + case PlatformId::kCustom: + break; + default: + break; + } + return NULL; +} + +UConverter* NameTable::GetCharset(int32_t platform_id, int32_t encoding_id) { + UErrorCode error_code = U_ZERO_ERROR; + UConverter* conv = ucnv_open(GetEncodingName(platform_id, encoding_id), + &error_code); + if (U_SUCCESS(error_code)) { + return conv; + } + + if (conv) { + ucnv_close(conv); + } + return NULL; +} + +void NameTable::ConvertToNameBytes(const UChar* name, + int32_t platform_id, + int32_t encoding_id, + ByteVector* b) { + assert(b); + assert(name); + b->clear(); + UConverter* cs = GetCharset(platform_id, encoding_id); + if (cs == NULL) { + return; + } + + // Preflight to get buffer size. + UErrorCode error_code = U_ZERO_ERROR; + int32_t length = ucnv_fromUChars(cs, NULL, 0, name, -1, &error_code); + b->resize(length + 4); // The longest termination "\0" is 4 bytes. + memset(&((*b)[0]), 0, length + 4); + error_code = U_ZERO_ERROR; + ucnv_fromUChars(cs, + reinterpret_cast(&((*b)[0])), + length + 4, + name, + -1, + &error_code); + if (!U_SUCCESS(error_code)) { + b->clear(); + } + ucnv_close(cs); +} + +UChar* NameTable::ConvertFromNameBytes(ByteVector* name_bytes, + int32_t platform_id, + int32_t encoding_id) { + if (name_bytes == NULL) { + return NULL; + } + UConverter* cs = GetCharset(platform_id, encoding_id); + UErrorCode error_code = U_ZERO_ERROR; + if (cs == NULL) { + char buffer[11] = {0}; +#if defined (WIN32) + _itoa_s(platform_id, buffer, 16); +#else + snprintf(buffer, sizeof(buffer), "%x", platform_id); +#endif + UChar* result = new UChar[12]; + memset(result, 0, sizeof(UChar) * 12); + cs = ucnv_open("utf-8", &error_code); + if (U_SUCCESS(error_code)) { + ucnv_toUChars(cs, result, 12, buffer, 11, &error_code); + ucnv_close(cs); + if (U_SUCCESS(error_code)) { + return result; + } + } + delete[] result; + return NULL; + } + + // No preflight needed here, we will be bigger. + UChar* output_buffer = new UChar[name_bytes->size() + 1]; + memset(output_buffer, 0, sizeof(UChar) * (name_bytes->size() + 1)); + int32_t length = ucnv_toUChars(cs, + output_buffer, + name_bytes->size(), + reinterpret_cast(&((*name_bytes)[0])), + name_bytes->size(), + &error_code); + ucnv_close(cs); + if (length > 0) { + return output_buffer; + } + + delete[] output_buffer; + return NULL; +} + +} // namespace sfntly diff --git a/sfntly/table/core/name_table.h b/sfntly/table/core/name_table.h new file mode 100644 index 0000000..b5a7f9a --- /dev/null +++ b/sfntly/table/core/name_table.h @@ -0,0 +1,737 @@ +/* + * 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. + */ + +#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_NAME_TABLE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_NAME_TABLE_H_ + +// Must include this before ICU to avoid stdint redefinition issue. +#include "sfntly/port/type.h" + +#include +#include + +#include +#include + +#include "sfntly/table/table.h" + +#if defined U_USING_ICU_NAMESPACE + U_NAMESPACE_USE +#endif + +namespace sfntly { + +// The following code implements the name table defined in TTF/OTF spec, which +// can be found at http://www.microsoft.com/typography/otspec/name.htm. + +// Name IDs defined in TTF/OTF spec. +struct NameId { + enum { + kUnknown = -1, + kCopyrightNotice = 0, + kFontFamilyName = 1, + kFontSubfamilyName = 2, + kUniqueFontIdentifier = 3, + kFullFontName = 4, + kVersionString = 5, + kPostscriptName = 6, + kTrademark = 7, + kManufacturerName = 8, + kDesigner = 9, + kDescription = 10, + kVendorURL = 11, + kDesignerURL = 12, + kLicenseDescription = 13, + kLicenseInfoURL = 14, + kReserved15 = 15, + kPreferredFamily = 16, + kPreferredSubfamily = 17, + kCompatibleFullName = 18, + kSampleText = 19, + kPostscriptCID = 20, + kWWSFamilyName = 21, + kWWSSubfamilyName = 22 + }; +}; + +// Unicode language IDs used in Name Records. +struct UnicodeLanguageId { + enum { + kUnknown = -1, + kAll = 0 + }; +}; + +// Macintosh Language IDs (platform ID = 1) +struct MacintoshLanguageId { + enum { + kUnknown = -1, + kEnglish = 0, + kFrench = 1, + kGerman = 2, + kItalian = 3, + kDutch = 4, + kSwedish = 5, + kSpanish = 6, + kDanish = 7, + kPortuguese = 8, + kNorwegian = 9, + kHebrew = 10, + kJapanese = 11, + kArabic = 12, + kFinnish = 13, + kGreek = 14, + kIcelandic = 15, + kMaltese = 16, + kTurkish = 17, + kCroatian = 18, + kChinese_Traditional = 19, + kUrdu = 20, + kHindi = 21, + kThai = 22, + kKorean = 23, + kLithuanian = 24, + kPolish = 25, + kHungarian = 26, + kEstonian = 27, + kLatvian = 28, + kSami = 29, + kFaroese = 30, + kFarsiPersian = 31, + kRussian = 32, + kChinese_Simplified = 33, + kFlemish = 34, + kIrishGaelic = 35, + kAlbanian = 36, + kRomanian = 37, + kCzech = 38, + kSlovak = 39, + kSlovenian = 40, + kYiddish = 41, + kSerbian = 42, + kMacedonian = 43, + kBulgarian = 44, + kUkrainian = 45, + kByelorussian = 46, + kUzbek = 47, + kKazakh = 48, + kAzerbaijani_Cyrillic = 49, + kAzerbaijani_Arabic = 50, + kArmenian = 51, + kGeorgian = 52, + kMoldavian = 53, + kKirghiz = 54, + kTajiki = 55, + kTurkmen = 56, + kMongolian_Mongolian = 57, + kMongolian_Cyrillic = 58, + kPashto = 59, + kKurdish = 60, + kKashmiri = 61, + kSindhi = 62, + kTibetan = 63, + kNepali = 64, + kSanskrit = 65, + kMarathi = 66, + kBengali = 67, + kAssamese = 68, + kGujarati = 69, + kPunjabi = 70, + kOriya = 71, + kMalayalam = 72, + kKannada = 73, + kTamil = 74, + kTelugu = 75, + kSinhalese = 76, + kBurmese = 77, + kKhmer = 78, + kLao = 79, + kVietnamese = 80, + kIndonesian = 81, + kTagalong = 82, + kMalay_Roman = 83, + kMalay_Arabic = 84, + kAmharic = 85, + kTigrinya = 86, + kGalla = 87, + kSomali = 88, + kSwahili = 89, + kKinyarwandaRuanda = 90, + kRundi = 91, + kNyanjaChewa = 92, + kMalagasy = 93, + kEsperanto = 94, + kWelsh = 128, + kBasque = 129, + kCatalan = 130, + kLatin = 131, + kQuenchua = 132, + kGuarani = 133, + kAymara = 134, + kTatar = 135, + kUighur = 136, + kDzongkha = 137, + kJavanese_Roman = 138, + kSundanese_Roman = 139, + kGalician = 140, + kAfrikaans = 141, + kBreton = 142, + kInuktitut = 143, + kScottishGaelic = 144, + kManxGaelic = 145, + kIrishGaelic_WithDotAbove = 146, + kTongan = 147, + kGreek_Polytonic = 148, + kGreenlandic = 149, + kAzerbaijani_Roman = 150 + }; +}; + +// Windows Language IDs (platformID = 3) +struct WindowsLanguageId { + enum { + kUnknown = -1, + kAfrikaans_SouthAfrica = 0x0436, + kAlbanian_Albania = 0x041C, + kAlsatian_France = 0x0484, + kAmharic_Ethiopia = 0x045E, + kArabic_Algeria = 0x1401, + kArabic_Bahrain = 0x3C01, + kArabic_Egypt = 0x0C01, + kArabic_Iraq = 0x0801, + kArabic_Jordan = 0x2C01, + kArabic_Kuwait = 0x3401, + kArabic_Lebanon = 0x3001, + kArabic_Libya = 0x1001, + kArabic_Morocco = 0x1801, + kArabic_Oman = 0x2001, + kArabic_Qatar = 0x4001, + kArabic_SaudiArabia = 0x0401, + kArabic_Syria = 0x2801, + kArabic_Tunisia = 0x1C01, + kArabic_UAE = 0x3801, + kArabic_Yemen = 0x2401, + kArmenian_Armenia = 0x042B, + kAssamese_India = 0x044D, + kAzeri_Cyrillic_Azerbaijan = 0x082C, + kAzeri_Latin_Azerbaijan = 0x042C, + kBashkir_Russia = 0x046D, + kBasque_Basque = 0x042D, + kBelarusian_Belarus = 0x0423, + kBengali_Bangladesh = 0x0845, + kBengali_India = 0x0445, + kBosnian_Cyrillic_BosniaAndHerzegovina = 0x201A, + kBosnian_Latin_BosniaAndHerzegovina = 0x141A, + kBreton_France = 0x047E, + kBulgarian_Bulgaria = 0x0402, + kCatalan_Catalan = 0x0403, + kChinese_HongKongSAR = 0x0C04, + kChinese_MacaoSAR = 0x1404, + kChinese_PeoplesRepublicOfChina = 0x0804, + kChinese_Singapore = 0x1004, + kChinese_Taiwan = 0x0404, + kCorsican_France = 0x0483, + kCroatian_Croatia = 0x041A, + kCroatian_Latin_BosniaAndHerzegovina = 0x101A, + kCzech_CzechRepublic = 0x0405, + kDanish_Denmark = 0x0406, + kDari_Afghanistan = 0x048C, + kDivehi_Maldives = 0x0465, + kDutch_Belgium = 0x0813, + kDutch_Netherlands = 0x0413, + kEnglish_Australia = 0x0C09, + kEnglish_Belize = 0x2809, + kEnglish_Canada = 0x1009, + kEnglish_Caribbean = 0x2409, + kEnglish_India = 0x4009, + kEnglish_Ireland = 0x1809, + kEnglish_Jamaica = 0x2009, + kEnglish_Malaysia = 0x4409, + kEnglish_NewZealand = 0x1409, + kEnglish_RepublicOfThePhilippines = 0x3409, + kEnglish_Singapore = 0x4809, + kEnglish_SouthAfrica = 0x1C09, + kEnglish_TrinidadAndTobago = 0x2C09, + kEnglish_UnitedKingdom = 0x0809, + kEnglish_UnitedStates = 0x0409, + kEnglish_Zimbabwe = 0x3009, + kEstonian_Estonia = 0x0425, + kFaroese_FaroeIslands = 0x0438, + kFilipino_Philippines = 0x0464, + kFinnish_Finland = 0x040B, + kFrench_Belgium = 0x080C, + kFrench_Canada = 0x0C0C, + kFrench_France = 0x040C, + kFrench_Luxembourg = 0x140c, + kFrench_PrincipalityOfMonoco = 0x180C, + kFrench_Switzerland = 0x100C, + kFrisian_Netherlands = 0x0462, + kGalician_Galician = 0x0456, + kGeorgian_Georgia = 0x0437, + kGerman_Austria = 0x0C07, + kGerman_Germany = 0x0407, + kGerman_Liechtenstein = 0x1407, + kGerman_Luxembourg = 0x1007, + kGerman_Switzerland = 0x0807, + kGreek_Greece = 0x0408, + kGreenlandic_Greenland = 0x046F, + kGujarati_India = 0x0447, + kHausa_Latin_Nigeria = 0x0468, + kHebrew_Israel = 0x040D, + kHindi_India = 0x0439, + kHungarian_Hungary = 0x040E, + kIcelandic_Iceland = 0x040F, + kIgbo_Nigeria = 0x0470, + kIndonesian_Indonesia = 0x0421, + kInuktitut_Canada = 0x045D, + kInuktitut_Latin_Canada = 0x085D, + kIrish_Ireland = 0x083C, + kisiXhosa_SouthAfrica = 0x0434, + kisiZulu_SouthAfrica = 0x0435, + kItalian_Italy = 0x0410, + kItalian_Switzerland = 0x0810, + kJapanese_Japan = 0x0411, + kKannada_India = 0x044B, + kKazakh_Kazakhstan = 0x043F, + kKhmer_Cambodia = 0x0453, + kKiche_Guatemala = 0x0486, + kKinyarwanda_Rwanda = 0x0487, + kKiswahili_Kenya = 0x0441, + kKonkani_India = 0x0457, + kKorean_Korea = 0x0412, + kKyrgyz_Kyrgyzstan = 0x0440, + kLao_LaoPDR = 0x0454, + kLatvian_Latvia = 0x0426, + kLithuanian_Lithuania = 0x0427, + kLowerSorbian_Germany = 0x082E, + kLuxembourgish_Luxembourg = 0x046E, + kMacedonian_FYROM_FormerYugoslavRepublicOfMacedonia = 0x042F, + kMalay_BruneiDarussalam = 0x083E, + kMalay_Malaysia = 0x043E, + kMalayalam_India = 0x044C, + kMaltese_Malta = 0x043A, + kMaori_NewZealand = 0x0481, + kMapudungun_Chile = 0x047A, + kMarathi_India = 0x044E, + kMohawk_Mohawk = 0x047C, + kMongolian_Cyrillic_Mongolia = 0x0450, + kMongolian_Traditional_PeoplesRepublicOfChina = 0x0850, + kNepali_Nepal = 0x0461, + kNorwegian_Bokmal_Norway = 0x0414, + kNorwegian_Nynorsk_Norway = 0x0814, + kOccitan_France = 0x0482, + kOriya_India = 0x0448, + kPashto_Afghanistan = 0x0463, + kPolish_Poland = 0x0415, + kPortuguese_Brazil = 0x0416, + kPortuguese_Portugal = 0x0816, + kPunjabi_India = 0x0446, + kQuechua_Bolivia = 0x046B, + kQuechua_Ecuador = 0x086B, + kQuechua_Peru = 0x0C6B, + kRomanian_Romania = 0x0418, + kRomansh_Switzerland = 0x0417, + kRussian_Russia = 0x0419, + kSami_Inari_Finland = 0x243B, + kSami_Lule_Norway = 0x103B, + kSami_Lule_Sweden = 0x143B, + kSami_Northern_Finland = 0x0C3B, + kSami_Northern_Norway = 0x043B, + kSami_Northern_Sweden = 0x083B, + kSami_Skolt_Finland = 0x203B, + kSami_Southern_Norway = 0x183B, + kSami_Southern_Sweden = 0x1C3B, + kSanskrit_India = 0x044F, + kSerbian_Cyrillic_BosniaAndHerzegovina = 0x1C1A, + kSerbian_Cyrillic_Serbia = 0x0C1A, + kSerbian_Latin_BosniaAndHerzegovina = 0x181A, + kSerbian_Latin_Serbia = 0x081A, + kSesothoSaLeboa_SouthAfrica = 0x046C, + kSetswana_SouthAfrica = 0x0432, + kSinhala_SriLanka = 0x045B, + kSlovak_Slovakia = 0x041B, + kSlovenian_Slovenia = 0x0424, + kSpanish_Argentina = 0x2C0A, + kSpanish_Bolivia = 0x400A, + kSpanish_Chile = 0x340A, + kSpanish_Colombia = 0x240A, + kSpanish_CostaRica = 0x140A, + kSpanish_DominicanRepublic = 0x1C0A, + kSpanish_Ecuador = 0x300A, + kSpanish_ElSalvador = 0x440A, + kSpanish_Guatemala = 0x100A, + kSpanish_Honduras = 0x480A, + kSpanish_Mexico = 0x080A, + kSpanish_Nicaragua = 0x4C0A, + kSpanish_Panama = 0x180A, + kSpanish_Paraguay = 0x3C0A, + kSpanish_Peru = 0x280A, + kSpanish_PuertoRico = 0x500A, + kSpanish_ModernSort_Spain = 0x0C0A, + kSpanish_TraditionalSort_Spain = 0x040A, + kSpanish_UnitedStates = 0x540A, + kSpanish_Uruguay = 0x380A, + kSpanish_Venezuela = 0x200A, + kSweden_Finland = 0x081D, + kSwedish_Sweden = 0x041D, + kSyriac_Syria = 0x045A, + kTajik_Cyrillic_Tajikistan = 0x0428, + kTamazight_Latin_Algeria = 0x085F, + kTamil_India = 0x0449, + kTatar_Russia = 0x0444, + kTelugu_India = 0x044A, + kThai_Thailand = 0x041E, + kTibetan_PRC = 0x0451, + kTurkish_Turkey = 0x041F, + kTurkmen_Turkmenistan = 0x0442, + kUighur_PRC = 0x0480, + kUkrainian_Ukraine = 0x0422, + kUpperSorbian_Germany = 0x042E, + kUrdu_IslamicRepublicOfPakistan = 0x0420, + kUzbek_Cyrillic_Uzbekistan = 0x0843, + kUzbek_Latin_Uzbekistan = 0x0443, + kVietnamese_Vietnam = 0x042A, + kWelsh_UnitedKingdom = 0x0452, + kWolof_Senegal = 0x0448, + kYakut_Russia = 0x0485, + kYi_PRC = 0x0478, + kYoruba_Nigeria = 0x046A + }; +}; + +class NameTable : public Table, public RefCounted { + public: + // Unique identifier for a given name record. + class NameEntryId { + public: + NameEntryId(); // C++ port only, must provide default constructor. + NameEntryId(int32_t platform_id, int32_t encoding_id, int32_t language_id, + int32_t name_id); + NameEntryId(const NameEntryId&); + // Make gcc -Wnon-virtual-dtor happy. + virtual ~NameEntryId() {} + + int32_t platform_id() const { return platform_id_; } + int32_t encoding_id() const { return encoding_id_; } + int32_t language_id() const { return language_id_; } + int32_t name_id() const { return name_id_; } + + const NameEntryId& operator=(const NameEntryId& rhs) const; + bool operator==(const NameEntryId& rhs) const; + bool operator<(const NameEntryId& rhs) const; + + private: + mutable int32_t platform_id_; + mutable int32_t encoding_id_; + mutable int32_t language_id_; + mutable int32_t name_id_; + }; + + class NameEntryBuilder; + + // Class to represent a name entry in the name table. + class NameEntry : public RefCounted { + public: + NameEntry(); + NameEntry(const NameEntryId& name_entry_id, const ByteVector& name_bytes); + NameEntry(int32_t platform_id, int32_t encoding_id, int32_t language_id, + int32_t name_id, const ByteVector& name_bytes); + virtual ~NameEntry(); + + NameEntryId& name_entry_id() { return name_entry_id_; } + int32_t platform_id() const { return name_entry_id_.platform_id(); } + int32_t encoding_id() const { return name_entry_id_.encoding_id(); } + int32_t language_id() const { return name_entry_id_.language_id(); } + int32_t name_id() const { return name_entry_id_.name_id(); } + + // Get the bytes for name. Returned pointer is the address of private + // member of this class, do not attempt to delete. + ByteVector* NameAsBytes(); + + // C++ port only: get the length of NameAsBytes. + int32_t NameBytesLength(); + + // Returns the name in Unicode as UChar array. + // Note: ICU UChar* convention requires caller to delete[] it. + UChar* Name(); + bool operator==(const NameEntry& rhs) const; + + private: + void Init(int32_t platform_id, int32_t encoding_id, int32_t language_id, + int32_t name_id, const ByteVector* name_bytes); + + NameEntryId name_entry_id_; + int32_t length_; + ByteVector name_bytes_; + + friend class NameEntryBuilder; + }; + + // Builder of a name entry. + // C++ port: original Java hierarchy inherits from NameEntry. In C++ port, we + // opted not doing so to avoid ref count issues and nasty protected members. + class NameEntryBuilder : public RefCounted { + public: + NameEntryBuilder(); + NameEntryBuilder(const NameEntryId& name_entry_id, + const ByteVector& name_bytes); + explicit NameEntryBuilder(const NameEntryId& name_entry_id); + explicit NameEntryBuilder(NameEntry* entry); + virtual ~NameEntryBuilder(); + + virtual void SetName(const UChar* name); + virtual void SetName(const ByteVector& name_bytes); + virtual void SetName(const ByteVector& name_bytes, int32_t offset, + int32_t length); + + // C++ port only. CALLER_ATTACH is not added because the lifetime shall be + // controlled by this class, therefore the caller shall not increase the ref + // count. + NameEntry* name_entry() { return name_entry_; } + + private: + void Init(int32_t platform_id, int32_t encoding_id, int32_t language_id, + int32_t name_id, const ByteVector* name_bytes); + + Ptr name_entry_; + }; + typedef std::map > NameEntryBuilderMap; + + // An interface for a filter to use with the name entry iterator. This allows + // name entries to be iterated and only those acceptable to the filter will be + // returned. + class NameEntryFilter { + public: + virtual bool Accept(int32_t platform_id, int32_t encoding_id, + int32_t language_id, int32_t name_id) = 0; + // Make gcc -Wnon-virtual-dtor happy. + virtual ~NameEntryFilter() {} + }; + + // C++ port only: an in-place filter to mimic Java Iterator's filtering. + class NameEntryFilterInPlace : public NameEntryFilter { + public: + NameEntryFilterInPlace(int32_t platform_id, int32_t encoding_id, + int32_t language_id, int32_t name_id); + // Make gcc -Wnon-virtual-dtor happy. + virtual ~NameEntryFilterInPlace() {} + + virtual bool Accept(int32_t platform_id, int32_t encoding_id, + int32_t language_id, int32_t name_id); + + private: + int32_t platform_id_; + int32_t encoding_id_; + int32_t language_id_; + int32_t name_id_; + }; + + // Mimic Java's iterator to iterate through the entries within the name table. + class NameEntryIterator { + public: + // If filter is NULL, filter through all tables. + explicit NameEntryIterator(NameTable* table); + NameEntryIterator(NameTable* table, NameEntryFilter* filter); + // Make gcc -Wnon-virtual-dtor happy. + virtual ~NameEntryIterator() {} + + virtual bool HasNext(); + virtual CALLER_ATTACH NameEntry* Next(); + virtual void Remove(); + + private: + void Init(NameTable* table, NameEntryFilter* filter); + + NameTable* table_; // Use dumb pointer since it's a composition object. + int32_t name_index_; + NameEntryFilter* filter_; + }; + + // The builder to construct name table for outputting. + class Builder : public Table::ArrayElementTableBuilder, + public RefCounted { + public: + // Constructor scope altered to public because C++ does not allow base + // class to instantiate derived class with protected constructors. + Builder(FontDataTableBuilderContainer* font_builder, Header* header, + WritableFontData* data); + Builder(FontDataTableBuilderContainer* font_builder, Header* header, + ReadableFontData* data); + + // Revert the name builders for the name table to the last version that came + // from data. + void RevertNames(); + + // Number of name entry builders contained. + int32_t BuilderCount(); + + // Note: For C++ port, clear() is not implemented. The clear() function + // implies completely remove name entry builders, which is easy in + // Java but will take a lot of efforts in C++ to release the builders + // nicely and correctly. + // TODO(arthurhsu): IMPLEMENT + // Clear the name builders for the name table. + // void clear(); + + // Check the existance of a name entry builder by key. + bool Has(int32_t platform_id, int32_t encoding_id, int32_t language_id, + int32_t name_id); + + // Get name entry builder by key. + CALLER_ATTACH NameEntryBuilder* NameBuilder(int32_t platform_id, + int32_t encoding_id, int32_t language_id, int32_t name_id); + + // Remove name entry builder by key. + bool Remove(int32_t platform_id, int32_t encoding_id, int32_t language_id, + int32_t name_id); + + // FontDataTable::Builder API implementation + virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); + virtual void SubDataSet(); + virtual int32_t SubDataSizeToSerialize(); + virtual bool SubReadyToSerialize(); + virtual int32_t SubSerialize(WritableFontData* new_data); + + private: + void Initialize(ReadableFontData* data); + NameEntryBuilderMap* GetNameBuilders(); + + // Note: callers should use the getter funtion provided above to ensure that + // this is lazily initialized instead of accessing directly. + NameEntryBuilderMap name_entry_map_; + }; + + /**************************************************************************** + * public methods of NameTable class + ****************************************************************************/ + virtual ~NameTable(); + + // Get the format used in the name table. + virtual int32_t Format(); + + // Get the number of names in the name table. + virtual int32_t NameCount(); + + // Get the platform id for the given name record. + virtual int32_t PlatformId(int32_t index); + + // Get the encoding id for the given name record. + // see MacintoshEncodingId, WindowsEncodingId, UnicodeEncodingId + virtual int32_t EncodingId(int32_t index); + + // Get the language id for the given name record. + virtual int32_t LanguageId(int32_t index); + + // Get the name id for given name record. + virtual int32_t NameId(int32_t index); + + // Get the name as bytes for the specified name. If there is no entry for the + // requested name, then empty vector is returned. + virtual void NameAsBytes(int32_t index, ByteVector* b); + virtual void NameAsBytes(int32_t platform_id, int32_t encoding_id, + int32_t language_id, int32_t name_id, + ByteVector* b); + + // Get the name as a UChar* for the given name record. If there is no + // encoding conversion available for the name record then a best attempt + // UChar* will be returned. + // Note: ICU UChar* convention requires caller to delete[] it. + virtual UChar* Name(int32_t index); + + // Get the name as a UChar* for the specified name. If there is no entry for + // the requested name then NULL is returned. If there is no encoding + // conversion available for the name then a best attempt UChar* will be + // returned. + // Note: ICU UChar* convention requires caller to delete[] it. + virtual UChar* Name(int32_t platform_id, int32_t encoding_id, + int32_t language_id, int32_t name_id); + + // Note: These functions are renamed in C++ port. Their original Java name is + // nameEntry(). + virtual CALLER_ATTACH NameEntry* GetNameEntry(int32_t index); + virtual CALLER_ATTACH NameEntry* GetNameEntry(int32_t platform_id, + int32_t encoding_id, int32_t language_id, int32_t name_id); + + // Note: Not implemented in C++ port due to complexity and low usage. + // virtual void names(std::set*); + + // Get the iterator to iterate through all name entries. + // Note: Caller delete the returned object. + virtual NameEntryIterator* Iterator(); + virtual NameEntryIterator* Iterator(NameEntryFilter* filter); + + private: + struct Offset { + enum { + kFormat = 0, + kCount = 2, + kStringOffset = 4, + kNameRecordStart = 6, + + // Format 1 - offset from the end of the name records + kLangTagCount = 0, + kLangTagRecord = 2, + + kNameRecordSize = 12, + // Name Records + kNameRecordPlatformId = 0, + kNameRecordEncodingId = 2, + kNameRecordLanguageId = 4, + kNameRecordNameId = 6, + kNameRecordStringLength = 8, + kNameRecordStringOffset = 10 + }; + }; + + // The table shall be constructed using Builder, no direct instantiation. + NameTable(Header* header, ReadableFontData* data); + + // Get the offset to the string data in the name table. + int32_t StringOffset(); + + // Get the offset for the given name record. + int32_t OffsetForNameRecord(int32_t index); + + // Get the length of the string data for the given name record. + int32_t NameLength(int32_t index); + + // Get the offset of the string data for the given name record. + int32_t NameOffset(int32_t index); + + // Note: string literals are returned. Caller shall not attempt to manipulate + // the returned pointer. + static const char* GetEncodingName(int32_t platform_id, int32_t encoding_id); + + // Note: ICU UConverter* convention requires caller to ucnv_close() it. + static UConverter* GetCharset(int32_t platform_id, int32_t encoding_id); + + // Note: Output will be stored in ByteVector* b. Original data in b will be + // erased and replaced with converted name bytes. + static void ConvertToNameBytes(const UChar* name, int32_t platform_id, + int32_t encoding_id, ByteVector* b); + + // Note: ICU UChar* convention requires caller to delete[] it. + static UChar* ConvertFromNameBytes(ByteVector* name_bytes, + int32_t platform_id, int32_t encoding_id); +}; // class NameTable +typedef Ptr NameTablePtr; +typedef Ptr NameEntryPtr; +typedef Ptr NameTableBuilderPtr; +typedef Ptr NameEntryBuilderPtr; + +} // namespace sfntly + +#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_NAME_TABLE_H_ diff --git a/sfntly/table/core/os2_table.cc b/sfntly/table/core/os2_table.cc new file mode 100644 index 0000000..8ab435b --- /dev/null +++ b/sfntly/table/core/os2_table.cc @@ -0,0 +1,277 @@ +/* + * 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 "sfntly/table/core/os2_table.h" + +namespace sfntly { +/****************************************************************************** + * Constants + ******************************************************************************/ +const int64_t CodePageRange::kLatin1_1252 = (int64_t)1 << 0; +const int64_t CodePageRange::kLatin2_1250 = (int64_t)1 << (int64_t)1; +const int64_t CodePageRange::kCyrillic_1251 = (int64_t)1 << 2; +const int64_t CodePageRange::kGreek_1253 = (int64_t)1 << 3; +const int64_t CodePageRange::kTurkish_1254 = (int64_t)1 << 4; +const int64_t CodePageRange::kHebrew_1255 = (int64_t)1 << 5; +const int64_t CodePageRange::kArabic_1256 = (int64_t)1 << 6; +const int64_t CodePageRange::kWindowsBaltic_1257 = (int64_t)1 << 7; +const int64_t CodePageRange::kVietnamese_1258 = (int64_t)1 << 8; +const int64_t CodePageRange::kAlternateANSI9 = (int64_t)1 << 9; +const int64_t CodePageRange::kAlternateANSI10 = (int64_t)1 << 10; +const int64_t CodePageRange::kAlternateANSI11 = (int64_t)1 << 11; +const int64_t CodePageRange::kAlternateANSI12 = (int64_t)1 << 12; +const int64_t CodePageRange::kAlternateANSI13 = (int64_t)1 << 13; +const int64_t CodePageRange::kAlternateANSI14 = (int64_t)1 << 14; +const int64_t CodePageRange::kAlternateANSI15 = (int64_t)1 << 15; +const int64_t CodePageRange::kThai_874 = (int64_t)1 << 16; +const int64_t CodePageRange::kJapanJIS_932 = (int64_t)1 << 17; +const int64_t CodePageRange::kChineseSimplified_936 = (int64_t)1 << 18; +const int64_t CodePageRange::kKoreanWansung_949 = (int64_t)1 << 19; +const int64_t CodePageRange::kChineseTraditional_950 = (int64_t)1 << 20; +const int64_t CodePageRange::kKoreanJohab_1361 = (int64_t)1 << 21; +const int64_t CodePageRange::kAlternateANSI22 = (int64_t)1 << 22; +const int64_t CodePageRange::kAlternateANSI23 = (int64_t)1 << 23; +const int64_t CodePageRange::kAlternateANSI24 = (int64_t)1 << 24; +const int64_t CodePageRange::kAlternateANSI25 = (int64_t)1 << 25; +const int64_t CodePageRange::kAlternateANSI26 = (int64_t)1 << 26; +const int64_t CodePageRange::kAlternateANSI27 = (int64_t)1 << 27; +const int64_t CodePageRange::kAlternateANSI28 = (int64_t)1 << 28; +const int64_t CodePageRange::kMacintoshCharacterSet = (int64_t)1 << 29; +const int64_t CodePageRange::kOEMCharacterSet = (int64_t)1 << 30; +const int64_t CodePageRange::kSymbolCharacterSet = (int64_t)1 << 31; +const int64_t CodePageRange::kReservedForOEM32 = (int64_t)1 << 32; +const int64_t CodePageRange::kReservedForOEM33 = (int64_t)1 << 33; +const int64_t CodePageRange::kReservedForOEM34 = (int64_t)1 << 34; +const int64_t CodePageRange::kReservedForOEM35 = (int64_t)1 << 35; +const int64_t CodePageRange::kReservedForOEM36 = (int64_t)1 << 36; +const int64_t CodePageRange::kReservedForOEM37 = (int64_t)1 << 37; +const int64_t CodePageRange::kReservedForOEM38 = (int64_t)1 << 38; +const int64_t CodePageRange::kReservedForOEM39 = (int64_t)1 << 39; +const int64_t CodePageRange::kReservedForOEM40 = (int64_t)1 << 40; +const int64_t CodePageRange::kReservedForOEM41 = (int64_t)1 << 41; +const int64_t CodePageRange::kReservedForOEM42 = (int64_t)1 << 42; +const int64_t CodePageRange::kReservedForOEM43 = (int64_t)1 << 43; +const int64_t CodePageRange::kReservedForOEM44 = (int64_t)1 << 44; +const int64_t CodePageRange::kReservedForOEM45 = (int64_t)1 << 45; +const int64_t CodePageRange::kReservedForOEM46 = (int64_t)1 << 46; +const int64_t CodePageRange::kReservedForOEM47 = (int64_t)1 << 47; +const int64_t CodePageRange::kIBMGreek_869 = (int64_t)1 << 48; +const int64_t CodePageRange::kMSDOSRussion_866 = (int64_t)1 << 49; +const int64_t CodePageRange::kMSDOSNordic_865 = (int64_t)1 << 50; +const int64_t CodePageRange::kArabic_864 = (int64_t)1 << 51; +const int64_t CodePageRange::kMSDOSCanadianFrench_863 = (int64_t)1 << 52; +const int64_t CodePageRange::kHebrew_862 = (int64_t)1 << 53; +const int64_t CodePageRange::kMSDOSIcelandic_861 = (int64_t)1 << 54; +const int64_t CodePageRange::kMSDOSPortugese_860 = (int64_t)1 << 55; +const int64_t CodePageRange::kIBMTurkish_857 = (int64_t)1 << 56; +const int64_t CodePageRange::kIBMCyrillic_855 = (int64_t)1 << 57; +const int64_t CodePageRange::kLatin2_852 = (int64_t)1 << 58; +const int64_t CodePageRange::kMSDOSBaltic_775 = (int64_t)1 << 59; +const int64_t CodePageRange::kGreek_737 = (int64_t)1 << 60; +const int64_t CodePageRange::kArabic_708 = (int64_t)1 << 61; +const int64_t CodePageRange::kLatin1_850 = (int64_t)1 << 62; +const int64_t CodePageRange::kUS_437 = (int64_t)1 << 63; + +/****************************************************************************** + * struct UnicodeRange + ******************************************************************************/ +int32_t UnicodeRange::range(int32_t bit) { + if (bit < 0 || bit > kLast) { + return -1; + } + return bit; +} + +/****************************************************************************** + * class OS2Table + ******************************************************************************/ +OS2Table::~OS2Table() {} + +int32_t OS2Table::Version() { + return data_->ReadUShort(Offset::kVersion); +} + +int32_t OS2Table::XAvgCharWidth() { + return data_->ReadShort(Offset::kXAvgCharWidth); +} + +int32_t OS2Table::UsWeightClass() { + return data_->ReadUShort(Offset::kUsWeightClass); +} + +int32_t OS2Table::UsWidthClass() { + return data_->ReadUShort(Offset::kUsWidthClass); +} + +int32_t OS2Table::FsType() { + return data_->ReadUShort(Offset::kFsType); +} + +int32_t OS2Table::YSubscriptXSize() { + return data_->ReadShort(Offset::kYSubscriptXSize); +} + +int32_t OS2Table::YSubscriptYSize() { + return data_->ReadShort(Offset::kYSubscriptYSize); +} + +int32_t OS2Table::YSubscriptXOffset() { + return data_->ReadShort(Offset::kYSubscriptXOffset); +} + +int32_t OS2Table::YSubscriptYOffset() { + return data_->ReadShort(Offset::kYSubscriptYOffset); +} + +int32_t OS2Table::YSuperscriptXSize() { + return data_->ReadShort(Offset::kYSuperscriptXSize); +} + +int32_t OS2Table::YSuperscriptYSize() { + return data_->ReadShort(Offset::kYSuperscriptYSize); +} + +int32_t OS2Table::YSuperscriptXOffset() { + return data_->ReadShort(Offset::kYSuperscriptXOffset); +} + +int32_t OS2Table::YSuperscriptYOffset() { + return data_->ReadShort(Offset::kYSuperscriptYOffset); +} + +int32_t OS2Table::YStrikeoutSize() { + return data_->ReadShort(Offset::kYStrikeoutSize); +} + +int32_t OS2Table::YStrikeoutPosition() { + return data_->ReadShort(Offset::kYStrikeoutPosition); +} + +int32_t OS2Table::SFamilyClass() { + return data_->ReadShort(Offset::kSFamilyClass); +} + +void OS2Table::Panose(ByteVector* value) { + value->clear(); + value->resize(10); + data_->ReadBytes(Offset::kPanose, &((*value)[0]), 0, 10); +} + +int64_t OS2Table::UlUnicodeRange1() { + return data_->ReadULong(Offset::kUlUnicodeRange1); +} + +int64_t OS2Table::UlUnicodeRange2() { + return data_->ReadULong(Offset::kUlUnicodeRange2); +} + +int64_t OS2Table::UlUnicodeRange3() { + return data_->ReadULong(Offset::kUlUnicodeRange3); +} + +int64_t OS2Table::UlUnicodeRange4() { + return data_->ReadULong(Offset::kUlUnicodeRange4); +} + +void OS2Table::AchVendId(ByteVector* b) { + b->clear(); + b->resize(4); + data_->ReadBytes(Offset::kAchVendId, &((*b)[0]), 0, 4); +} + +int32_t OS2Table::FsSelection() { + return data_->ReadUShort(Offset::kFsSelection); +} + +int32_t OS2Table::UsFirstCharIndex() { + return data_->ReadUShort(Offset::kUsFirstCharIndex); +} + +int32_t OS2Table::UsLastCharIndex() { + return data_->ReadUShort(Offset::kUsLastCharIndex); +} + +int32_t OS2Table::STypoAscender() { + return data_->ReadShort(Offset::kSTypoAscender); +} + +int32_t OS2Table::STypoDescender() { + return data_->ReadShort(Offset::kSTypoDescender); +} + +int32_t OS2Table::STypoLineGap() { + return data_->ReadShort(Offset::kSTypoLineGap); +} + +int32_t OS2Table::UsWinAscent() { + return data_->ReadUShort(Offset::kUsWinAscent); +} + +int32_t OS2Table::UsWinDescent() { + return data_->ReadUShort(Offset::kUsWinDescent); +} + +int64_t OS2Table::UlCodePageRange1() { + return data_->ReadULong(Offset::kUlCodePageRange1); +} + +int64_t OS2Table::UlCodePageRange2() { + return data_->ReadULong(Offset::kUlCodePageRange2); +} + +int64_t OS2Table::UlCodePageRange() { + // TODO(arthurhsu): Possible bug point, check with stuartg. + return ((0xffffffff & UlCodePageRange2()) << 32) | + (0xffffffff & UlCodePageRange1()); +} + +int32_t OS2Table::SxHeight() { + return data_->ReadShort(Offset::kSxHeight); +} + +int32_t OS2Table::UsDefaultChar() { + return data_->ReadUShort(Offset::kUsDefaultChar); +} + +int32_t OS2Table::UsBreakChar() { + return data_->ReadUShort(Offset::kUsBreakChar); +} + +int32_t OS2Table::UsMaxContext() { + return data_->ReadUShort(Offset::kUsMaxContext); +} + +OS2Table::OS2Table(Header* header, ReadableFontData* data) + : Table(header, data) { +} + +/****************************************************************************** + * class OS2Table::Builder + ******************************************************************************/ +OS2Table::Builder::Builder(FontDataTableBuilderContainer* font_builder, + Header* header, WritableFontData* data) : + Table::TableBasedTableBuilder(font_builder, header, data) { +} + +OS2Table::Builder::~Builder() {} + +CALLER_ATTACH FontDataTable* OS2Table::Builder::SubBuildTable( + ReadableFontData* data) { + FontDataTablePtr table = new OS2Table(header(), data); + return table.Detach(); +} + +} // namespace sfntly diff --git a/sfntly/table/core/os2_table.h b/sfntly/table/core/os2_table.h new file mode 100644 index 0000000..24b6027 --- /dev/null +++ b/sfntly/table/core/os2_table.h @@ -0,0 +1,407 @@ +/* + * 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. + */ + +#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_OS2_TABLE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_OS2_TABLE_H_ + +#include "sfntly/port/refcount.h" +#include "sfntly/table/table.h" + +namespace sfntly { + +struct WeightClass { + enum { + kThin = 100, + kExtraLight = 200, + kUltraLight = 200, + kLight = 300, + kNormal = 400, + kRegular = 400, + kMedium = 500, + kSemiBold = 600, + kDemiBold = 600, + kBold = 700, + kExtraBold = 800, + kUltraBold = 800, + kBlack = 900, + kHeavy = 900 + }; +}; + +struct WidthClass { + enum { + kUltraCondensed = 1, + kExtraCondensed = 2, + kCondensed = 3, + kSemiCondensed = 4, + kMedium = 5, + kNormal = 5, + kSemiExpanded = 6, + kExpanded = 7, + kExtraExpanded = 8, + kUltraExpanded = 9 + }; +}; + +struct EmbeddingFlags { + enum { + kReserved0 = 1 << 0, + kRestrictedLicenseEmbedding = 1 << 1, + kPreviewAndPrintEmbedding = 1 << 2, + kEditableEmbedding = 1 << 3, + kReserved4 = 1 << 4, + kReserved5 = 1 << 5, + kReserved6 = 1 << 6, + kReserved7 = 1 << 7, + kNoSubsetting = 1 << 8, + kBitmapEmbeddingOnly = 1 << 9, + kReserved10 = 1 << 10, + kReserved11 = 1 << 11, + kReserved12 = 1 << 12, + kReserved13 = 1 << 13, + kReserved14 = 1 << 14, + kReserved15 = 1 << 15 + }; +}; + +struct UnicodeRange { + enum { + // This enum relies on the ordering of the data matching the ordinal numbers + // of the properties. + kBasicLatin, + kLatin1Supplement, + kLatinExtendedA, + kLatinExtendedB, + kIPAExtensions, + kSpacingModifierLetters, + kCombiningDiacriticalMarks, + kGreekAndCoptic, + kCoptic, + kCyrillic, + kArmenian, + kHebrew, + kVai, + kArabic, + kNKo, + kDevanagari, + kBengali, + kGurmukhi, + kGujarati, + kOriya, + kTamil, + kTelugu, + kKannada, + kMalayalam, + kThai, + kLao, + kGeorgian, + kBalinese, + kHangulJamo, + kLatinExtendedAdditional, + kGreekExtended, + kGeneralPunctuation, + kSuperscriptsAndSubscripts, + kCurrencySymbols, + kNumberForms, + kArrows, + kMathematicalOperators, + kMiscTechnical, + kControlPictures, + kOCR, + kEnclosedAlphanumerics, + kBoxDrawing, + kBlockElements, + kGeometricShapes, + kMiscSymbols, + kDingbats, + kCJKSymbolsAndPunctuation, + kHiragana, + kKatakana, + kBopomofo, + kHangulCompatibilityJamo, + kPhagspa, + kEnclosedCJKLettersAndMonths, + kCJKCompatibility, + kHangulSyllables, + kNonPlane0, + kPhoenician, + kCJKUnifiedIdeographs, + kPrivateUseAreaPlane0, + kCJKStrokes, + kAlphabeticPresentationForms, + kArabicPresentationFormsA, + kCombiningHalfMarks, + kVerticalForms, + kSmallFormVariants, + kArabicPresentationFormsB, + kHalfwidthAndFullwidthForms, + kSpecials, + kTibetan, + kSyriac, + kThaana, + kSinhala, + kMyanmar, + kEthiopic, + kCherokee, + kUnifiedCanadianAboriginalSyllabics, + kOgham, + kRunic, + kKhmer, + kMongolian, + kBraillePatterns, + kYiSyllables, + kTagalog, + kOldItalic, + kGothic, + kDeseret, + kMusicalSymbols, + kMathematicalAlphanumericSymbols, + kPrivateUsePlane15And16, + kVariationSelectors, + kTags, + kLimbu, + kTaiLe, + kNewTaiLue, + kBuginese, + kGlagolitic, + kTifnagh, + kYijingHexagramSymbols, + kSylotiNagari, + kLinearB, + kAncientGreekNumbers, + kUgaritic, + kOldPersian, + kShavian, + kOsmanya, + kCypriotSyllabary, + kKharoshthi, + kTaiXuanJingSymbols, + kCuneiform, + kCountingRodNumerals, + kSudanese, + kLepcha, + kOlChiki, + kSaurashtra, + kKayahLi, + kRejang, + kCharm, + kAncientSymbols, + kPhaistosDisc, + kCarian, + kDominoTiles, + kReserved123, + kReserved124, + kReserved125, + kReserved126, + kReserved127, + kLast = kReserved127 + }; + + int32_t range(int32_t bit); + // UNIMPLEMENTED: EnumSet asSet(long range1, long range2, + // long range3, long range4) +}; + +struct FsSelection { + enum { + kITALIC = 1 << 0, + kUNDERSCORE = 1 << 1, + kNEGATIVE = 1 << 2, + kOUTLINED = 1 << 3, + kSTRIKEOUT = 1 << 4, + kBOLD = 1 << 5, + kREGULAR = 1 << 6, + kUSE_TYPO_METRICS = 1 << 7, + kWWS = 1 << 8, + kOBLIQUE = 1 << 9 + }; +}; + +// C++ port only: C++ does not support 64-bit enums until C++0x. For better +// portability, we need to use static const int64_t instead. +struct CodePageRange { + static const int64_t kLatin1_1252; + static const int64_t kLatin2_1250; + static const int64_t kCyrillic_1251; + static const int64_t kGreek_1253; + static const int64_t kTurkish_1254; + static const int64_t kHebrew_1255; + static const int64_t kArabic_1256; + static const int64_t kWindowsBaltic_1257; + static const int64_t kVietnamese_1258; + static const int64_t kAlternateANSI9; + static const int64_t kAlternateANSI10; + static const int64_t kAlternateANSI11; + static const int64_t kAlternateANSI12; + static const int64_t kAlternateANSI13; + static const int64_t kAlternateANSI14; + static const int64_t kAlternateANSI15; + static const int64_t kThai_874; + static const int64_t kJapanJIS_932; + static const int64_t kChineseSimplified_936; + static const int64_t kKoreanWansung_949; + static const int64_t kChineseTraditional_950; + static const int64_t kKoreanJohab_1361; + static const int64_t kAlternateANSI22; + static const int64_t kAlternateANSI23; + static const int64_t kAlternateANSI24; + static const int64_t kAlternateANSI25; + static const int64_t kAlternateANSI26; + static const int64_t kAlternateANSI27; + static const int64_t kAlternateANSI28; + static const int64_t kMacintoshCharacterSet; + static const int64_t kOEMCharacterSet; + static const int64_t kSymbolCharacterSet; + static const int64_t kReservedForOEM32; + static const int64_t kReservedForOEM33; + static const int64_t kReservedForOEM34; + static const int64_t kReservedForOEM35; + static const int64_t kReservedForOEM36; + static const int64_t kReservedForOEM37; + static const int64_t kReservedForOEM38; + static const int64_t kReservedForOEM39; + static const int64_t kReservedForOEM40; + static const int64_t kReservedForOEM41; + static const int64_t kReservedForOEM42; + static const int64_t kReservedForOEM43; + static const int64_t kReservedForOEM44; + static const int64_t kReservedForOEM45; + static const int64_t kReservedForOEM46; + static const int64_t kReservedForOEM47; + static const int64_t kIBMGreek_869; + static const int64_t kMSDOSRussion_866; + static const int64_t kMSDOSNordic_865; + static const int64_t kArabic_864; + static const int64_t kMSDOSCanadianFrench_863; + static const int64_t kHebrew_862; + static const int64_t kMSDOSIcelandic_861; + static const int64_t kMSDOSPortugese_860; + static const int64_t kIBMTurkish_857; + static const int64_t kIBMCyrillic_855; + static const int64_t kLatin2_852; + static const int64_t kMSDOSBaltic_775; + static const int64_t kGreek_737; + static const int64_t kArabic_708; + static const int64_t kLatin1_850; + static const int64_t kUS_437; +}; + +class OS2Table : public Table, public RefCounted { + public: + class Builder : public Table::TableBasedTableBuilder, + public RefCounted { + public: + Builder(FontDataTableBuilderContainer* font_builder, Header* header, + WritableFontData* data); + virtual ~Builder(); + virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); + }; + + ~OS2Table(); + + int32_t Version(); + int32_t XAvgCharWidth(); + int32_t UsWeightClass(); + int32_t UsWidthClass(); + // UNIMPLEMENTED: public EnumSet fsType() + int32_t FsType(); + int32_t YSubscriptXSize(); + int32_t YSubscriptYSize(); + int32_t YSubscriptXOffset(); + int32_t YSubscriptYOffset(); + int32_t YSuperscriptXSize(); + int32_t YSuperscriptYSize(); + int32_t YSuperscriptXOffset(); + int32_t YSuperscriptYOffset(); + int32_t YStrikeoutSize(); + int32_t YStrikeoutPosition(); + int32_t SFamilyClass(); + void Panose(ByteVector* value); + int64_t UlUnicodeRange1(); + int64_t UlUnicodeRange2(); + int64_t UlUnicodeRange3(); + int64_t UlUnicodeRange4(); + // UNIMPLEMENTED: public EnumSet UlUnicodeRange() + void AchVendId(ByteVector* b); + // UNIMPLEMENTED: public EnumSet fsSelection() + int32_t FsSelection(); + int32_t UsFirstCharIndex(); + int32_t UsLastCharIndex(); + int32_t STypoAscender(); + int32_t STypoDescender(); + int32_t STypoLineGap(); + int32_t UsWinAscent(); + int32_t UsWinDescent(); + int64_t UlCodePageRange1(); + int64_t UlCodePageRange2(); + // UNIMPLEMENTED: public EnumSet ulCodePageRange() + int64_t UlCodePageRange(); + int32_t SxHeight(); + int32_t SCapHeight(); + int32_t UsDefaultChar(); + int32_t UsBreakChar(); + int32_t UsMaxContext(); + + private: + struct Offset { + enum { + kVersion = 0, + kXAvgCharWidth = 2, + kUsWeightClass = 4, + kUsWidthClass = 6, + kFsType = 8, + kYSubscriptXSize = 10, + kYSubscriptYSize = 12, + kYSubscriptXOffset = 14, + kYSubscriptYOffset = 16, + kYSuperscriptXSize = 18, + kYSuperscriptYSize = 20, + kYSuperscriptXOffset = 22, + kYSuperscriptYOffset = 24, + kYStrikeoutSize = 26, + kYStrikeoutPosition = 28, + kSFamilyClass = 30, + kPanose = 32, + kUlUnicodeRange1 = 42, + kUlUnicodeRange2 = 46, + kUlUnicodeRange3 = 50, + kUlUnicodeRange4 = 54, + kAchVendId = 58, + kFsSelection = 62, + kUsFirstCharIndex = 64, + kUsLastCharIndex = 66, + kSTypoAscender = 68, + kSTypoDescender = 70, + kSTypoLineGap = 72, + kUsWinAscent = 74, + kUsWinDescent = 76, + kUlCodePageRange1 = 78, + kUlCodePageRange2 = 82, + kSxHeight = 86, + kSCapHeight = 88, + kUsDefaultChar = 90, + kUsBreakChar = 92, + kUsMaxContext = 94 + }; + }; + + OS2Table(Header* header, ReadableFontData* data); +}; +typedef Ptr OS2TablePtr; + +} // namespace sfntly + +#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_OS2_TABLE_H_ diff --git a/sfntly/table/font_data_table.cc b/sfntly/table/font_data_table.cc new file mode 100644 index 0000000..7be3f77 --- /dev/null +++ b/sfntly/table/font_data_table.cc @@ -0,0 +1,176 @@ +/* + * 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 "sfntly/table/font_data_table.h" + +#include "sfntly/data/font_output_stream.h" + +namespace sfntly { + +/****************************************************************************** + * FontDataTable class + ******************************************************************************/ + +FontDataTable::FontDataTable(ReadableFontData* data) { + data_ = data; +} + +FontDataTable::~FontDataTable() {} + +ReadableFontData* FontDataTable::ReadFontData() { + return data_; +} + +int32_t FontDataTable::Length() { + return data_->Length(); +} + +int32_t FontDataTable::Padding() { + return -1; +} + +int32_t FontDataTable::DataLength() { + int32_t paddings = Padding(); + return (paddings == -1) ? Length() : Length() - paddings; +} + +int32_t FontDataTable::Serialize(OutputStream* os) { + return data_->CopyTo(os); +} + +/****************************************************************************** + * FontDataTable::Builder class + ******************************************************************************/ +CALLER_ATTACH WritableFontData* FontDataTable::Builder::Data() { + WritableFontDataPtr new_data; + if (model_changed_) { + if (!SubReadyToSerialize()) { + return NULL; + } + int32_t size = SubDataSizeToSerialize(); + new_data.Attach(container_->GetNewData(size)); + SubSerialize(new_data); + } else { + ReadableFontDataPtr data = InternalReadData(); + new_data.Attach(container_->GetNewData(data != NULL ? data->Length() : 0)); + data->CopyTo(new_data); + } + return new_data.Detach(); +} + +void FontDataTable::Builder::SetData(ReadableFontData* data) { + InternalSetData(data, true); +} + + +CALLER_ATTACH FontDataTable* FontDataTable::Builder::Build() { + ReadableFontDataPtr data = InternalReadData(); + if (model_changed_) { + // Let subclass serialize from model. + if (!SubReadyToSerialize()) { + return NULL; + } + int32_t size = SubDataSizeToSerialize(); + WritableFontDataPtr new_data; + new_data.Attach(container_->GetNewData(size)); + SubSerialize(new_data); + data = new_data; + } + + if (data == NULL) { + return NULL; // Do not build table with NULL data. + } + + FontDataTablePtr table = SubBuildTable(data); + NotifyPostTableBuild(table); + return table; +} + +bool FontDataTable::Builder::ReadyToBuild() { + return true; +} + +ReadableFontData* FontDataTable::Builder::InternalReadData() { + return (r_data_ != NULL) ? r_data_.p_ : + static_cast(w_data_.p_); +} + +WritableFontData* FontDataTable::Builder::InternalWriteData() { + if (w_data_ == NULL) { + WritableFontDataPtr new_data; + new_data.Attach(container_->GetNewData(r_data_->Length())); + r_data_->CopyTo(new_data); + InternalSetData(new_data, false); + } + return w_data_.p_; +} + +CALLER_ATTACH WritableFontData* + FontDataTable::Builder::InternalNewData(int32_t size) { + return container_->GetNewData(size); +} + +FontDataTable::Builder::Builder(FontDataTableBuilderContainer* container) { + Init(container); +} + +FontDataTable::Builder::Builder(FontDataTableBuilderContainer* container, + WritableFontData* data) { + Init(container); + w_data_ = data; +} + +FontDataTable::Builder::Builder(FontDataTableBuilderContainer* container, + ReadableFontData* data) { + Init(container); + r_data_ = data; +} + +FontDataTable::Builder::~Builder() { +} + +void FontDataTable::Builder::Init(FontDataTableBuilderContainer* container) { + container_ = container; + model_changed_ = false; + data_changed_ = false; +} + +void FontDataTable::Builder::NotifyPostTableBuild(FontDataTable* table) { + // Default: NOP. + UNREFERENCED_PARAMETER(table); +} + +void FontDataTable::Builder::InternalSetData(WritableFontData* data, + bool data_changed) { + w_data_ = data; + r_data_ = NULL; + if (data_changed) { + data_changed_ = true; + SubDataSet(); + } +} + +void FontDataTable::Builder::InternalSetData(ReadableFontData* data, + bool data_changed) { + w_data_ = NULL; + r_data_ = data; + if (data_changed) { + data_changed_ = true; + SubDataSet(); + } +} + +} // namespace sfntly diff --git a/sfntly/table/font_data_table.h b/sfntly/table/font_data_table.h new file mode 100644 index 0000000..a2b026f --- /dev/null +++ b/sfntly/table/font_data_table.h @@ -0,0 +1,117 @@ +/* + * 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. + */ + +#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_FONT_DATA_TABLE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TABLE_FONT_DATA_TABLE_H_ + +#include "sfntly/data/readable_font_data.h" +#include "sfntly/font_data_table_builder_container.h" +#include "sfntly/port/refcount.h" + +namespace sfntly { + +class FontDataTable : virtual public RefCount { + public: + // Note: original version is abstract Builder + // C++ template is not designed that way so plain class is chosen. + class Builder : virtual public RefCount { + public: + // Get a snapshot copy of the internal data of the builder. + // This causes any internal data structures to be serialized to a new data + // object. This data object belongs to the caller and must be properly + // disposed of. No changes are made to the builder and any changes to the + // data directly do not affect the internal state. To do that a subsequent + // call must be made to {@link #SetData(WritableFontData)}. + // @return a copy of the internal data of the builder + CALLER_ATTACH WritableFontData* Data(); + virtual void SetData(ReadableFontData* data); + + // Note: changed from protected to avoid accessibility error in C++ + virtual CALLER_ATTACH FontDataTable* Build(); + virtual bool ReadyToBuild(); + + ReadableFontData* InternalReadData(); + WritableFontData* InternalWriteData(); + CALLER_ATTACH WritableFontData* InternalNewData(int32_t size); + + bool data_changed() { return data_changed_; } + bool model_changed() { return model_changed_; } + bool set_model_changed() { return set_model_changed(true); } + bool set_model_changed(bool changed) { + bool old = model_changed_; + model_changed_ = changed; + return old; + } + + protected: + explicit Builder(FontDataTableBuilderContainer* container); + Builder(FontDataTableBuilderContainer* container, WritableFontData* data); + Builder(FontDataTableBuilderContainer* container, ReadableFontData* data); + virtual ~Builder(); + + void Init(FontDataTableBuilderContainer* container); + + // subclass API + virtual void NotifyPostTableBuild(FontDataTable* table); + virtual int32_t SubSerialize(WritableFontData* new_data) = 0; + virtual bool SubReadyToSerialize() = 0; + virtual int32_t SubDataSizeToSerialize() = 0; + virtual void SubDataSet() = 0; + virtual CALLER_ATTACH FontDataTable* + SubBuildTable(ReadableFontData* data) = 0; + + private: + void InternalSetData(WritableFontData* data, bool data_changed); + void InternalSetData(ReadableFontData* data, bool data_changed); + + FontDataTableBuilderContainer* container_; // avoid circular ref-counting + WritableFontDataPtr w_data_; + ReadableFontDataPtr r_data_; + bool model_changed_; + bool data_changed_; + }; + + explicit FontDataTable(ReadableFontData* data); + virtual ~FontDataTable(); + + // Get the readable font data for this table. + ReadableFontData* ReadFontData(); + + // Get the length of the data for this table in bytes. This is the full + // allocated length of the data and may or may not include any padding. + virtual int32_t Length(); + + // Get the number of bytes of padding used in the table. The padding bytes are + // used to align the table length to a 4 byte boundary. + virtual int32_t Padding(); + + // Return the number of bytes of non-padded data in the table. If the padding + // is unknown or unknowable then the total number of bytes of data in the + // tables is returned. + virtual int32_t DataLength(); + + virtual int32_t Serialize(OutputStream* os); + + protected: + // TODO(arthurhsu): style guide violation: protected member, need refactoring + ReadableFontDataPtr data_; +}; +typedef Ptr FontDataTablePtr; +typedef Ptr FontDataTableBuilderPtr; + +} // namespace sfntly + +#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_FONT_DATA_TABLE_H_ diff --git a/sfntly/table/subtable.cc b/sfntly/table/subtable.cc new file mode 100644 index 0000000..4869a97 --- /dev/null +++ b/sfntly/table/subtable.cc @@ -0,0 +1,44 @@ +/* + * 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 "sfntly/table/subtable.h" + +namespace sfntly { +/****************************************************************************** + * SubTable class + ******************************************************************************/ +SubTable::~SubTable() {} + +SubTable::SubTable(ReadableFontData* data) + : FontDataTable(data) { +} + +/****************************************************************************** + * SubTable::Builder class + ******************************************************************************/ +SubTable::Builder::~Builder() {} + +SubTable::Builder::Builder(FontDataTableBuilderContainer* container, + WritableFontData* data) + : FontDataTable::Builder(container, data) { +} + +SubTable::Builder::Builder(FontDataTableBuilderContainer* container, + ReadableFontData* data) + : FontDataTable::Builder(container, data) { +} + +} // namespace sfntly diff --git a/sfntly/table/subtable.h b/sfntly/table/subtable.h new file mode 100644 index 0000000..c542881 --- /dev/null +++ b/sfntly/table/subtable.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_SUBTABLE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TABLE_SUBTABLE_H_ + +#include "sfntly/table/font_data_table.h" + +namespace sfntly { + +// An abstract base class for subtables. Subtables are smaller tables nested +// within other tables and don't have an entry in the main font index. Examples +// of these are the CMap subtables within CMap table (cmap) or a glyph within +// the glyph table (glyf). +class SubTable : public FontDataTable { + public: + class Builder : public FontDataTable::Builder { + public: + virtual ~Builder(); + + protected: + Builder(FontDataTableBuilderContainer* container, WritableFontData* data); + Builder(FontDataTableBuilderContainer* container, ReadableFontData* data); + }; + + virtual ~SubTable(); + + protected: + // Note: constructor refactored in C++ to avoid heavy lifting. + // caller need to do data->Slice(offset, length) beforehand. + explicit SubTable(ReadableFontData* data); +}; + +} // namespace sfntly + +#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_SUBTABLE_H_ diff --git a/sfntly/table/table.cc b/sfntly/table/table.cc new file mode 100644 index 0000000..568f889 --- /dev/null +++ b/sfntly/table/table.cc @@ -0,0 +1,279 @@ +/* + * 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 "sfntly/table/table.h" + +#include "sfntly/font.h" +#include "sfntly/tag.h" +#include "sfntly/table/core/cmap_table.h" +#include "sfntly/table/core/font_header_table.h" +#include "sfntly/table/core/horizontal_header_table.h" +#include "sfntly/table/core/horizontal_metrics_table.h" +#include "sfntly/table/core/maximum_profile_table.h" +#include "sfntly/table/core/name_table.h" +#include "sfntly/table/core/os2_table.h" +#include "sfntly/table/truetype/glyph_table.h" +#include "sfntly/table/truetype/loca_table.h" + +namespace sfntly { + +/****************************************************************************** + * Table class + ******************************************************************************/ +Table::~Table() {} + +int64_t Table::CalculatedChecksum() { + return data_->Checksum(); +} + +WritableFontData* Table::GetNewData(int32_t size) { + return font_->GetNewData(size); +} + +void Table::SetFont(Font* font) { + font_ = font; +} + +Table::Table(Header* header, ReadableFontData* data) + : FontDataTable(data) { + header_ = header; +} + +/****************************************************************************** + * Table::Header class + ******************************************************************************/ +Table::Header::Header(int32_t tag) + : tag_(tag), + offset_(0), + length_(0), + offset_valid_(false), + checksum_(0), + checksum_valid_(false) { +} + +Table::Header::Header(int32_t tag, int32_t length) + : tag_(tag), + offset_(0), + length_(length), + offset_valid_(false), + checksum_(0), + checksum_valid_(false) { +} + +Table::Header::Header(int32_t tag, + int64_t checksum, + int32_t offset, + int32_t length) + : tag_(tag), + offset_(offset), + length_(length), + offset_valid_(true), + checksum_(checksum), + checksum_valid_(true) { +} + +Table::Header::~Header() {} + +bool TableHeaderComparator::operator() (const TableHeaderPtr lhs, + const TableHeaderPtr rhs) { + return lhs->offset_ > rhs->offset_; +} + +/****************************************************************************** + * Table::Builder class + ******************************************************************************/ +Table::Builder::~Builder() { + header_.Release(); +} + +void Table::Builder::NotifyPostTableBuild(FontDataTable* table) { + if (model_changed() || data_changed()) { + Table* derived_table = down_cast(table); + header_ = new Header(header()->tag(), + derived_table->ReadFontData()->Length()); + } +} + +WritableFontData* Table::Builder::GetNewData(int32_t size) { + UNREFERENCED_PARAMETER(size); + return InternalWriteData(); +} + +CALLER_ATTACH Table::Builder* + Table::Builder::GetBuilder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* table_data) { + int32_t tag = header->tag(); + TableBuilderPtr builder; + Table::Builder* builder_raw = NULL; + + // Note: Tables are commented out when they are not used/ported. + // TODO(arthurhsu): IMPLEMENT: finish tables that are not ported. + /*if (tag == Tag::cmap) { + builder_raw = static_cast( + new CMapTable::Builder(font_builder, header, table_data)); + } else*/ if (tag == Tag::head) { + builder_raw = static_cast( + new FontHeaderTable::Builder(font_builder, header, table_data)); + } else if (tag == Tag::hhea) { + builder_raw = static_cast( + new HorizontalHeaderTable::Builder(font_builder, header, table_data)); + } else if (tag == Tag::hmtx) { + builder_raw = static_cast( + new HorizontalMetricsTable::Builder(font_builder, header, table_data)); + } else if (tag == Tag::maxp) { + builder_raw = static_cast( + new MaximumProfileTable::Builder(font_builder, header, table_data)); + } else if (tag == Tag::name) { + builder_raw = static_cast( + new NameTable::Builder(font_builder, header, table_data)); + } else if (tag == Tag::OS_2) { + builder_raw = static_cast( + new OS2Table::Builder(font_builder, header, table_data)); + }/* else if (tag == Tag::PostScript) { + builder_raw = static_cast( + new PostScriptTable::Builder(font_builder, header, table_data)); + } else if (tag == Tag::cvt) { + builder_raw = static_cast( + new ControlValueTable::Builder(font_builder, header, table_data)); + }*/ else if (tag == Tag::glyf) { + builder_raw = static_cast( + new GlyphTable::Builder(font_builder, header, table_data)); + } else if (tag == Tag::loca) { + builder_raw = static_cast( + new LocaTable::Builder(font_builder, header, table_data)); + }/* else if (tag == Tag::prep) { + builder_raw = static_cast( + new ControlProgramTable::Builder(font_builder, header, table_data)); + }*/ else if (tag == Tag::bhed) { + builder_raw = static_cast( + new FontHeaderTable::Builder(font_builder, header, table_data)); + } else { + builder_raw = static_cast( + new Table::GenericTableBuilder(font_builder, header, table_data)); + } + + builder = builder_raw; + return builder.Detach(); +} + +Table::Builder::Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data) + : FontDataTable::Builder(font_builder, data) { + header_ = header; +} + +Table::Builder::Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data) + : FontDataTable::Builder(font_builder, data) { + header_ = header; +} + +Table::Builder::Builder(FontDataTableBuilderContainer* font_builder, + Header* header) + : FontDataTable::Builder(font_builder) { + header_ = header; +} + +/****************************************************************************** + * Table::TableBasedTableBuilder class + ******************************************************************************/ +Table::TableBasedTableBuilder::~TableBasedTableBuilder() {} + +int32_t Table::TableBasedTableBuilder::SubSerialize(WritableFontData* data) { + UNREFERENCED_PARAMETER(data); + return 0; +} + +bool Table::TableBasedTableBuilder::SubReadyToSerialize() { + return false; +} + +int32_t Table::TableBasedTableBuilder::SubDataSizeToSerialize() { + return 0; +} + +void Table::TableBasedTableBuilder::SubDataSet() { + table_ = NULL; +} + +Table::TableBasedTableBuilder::TableBasedTableBuilder( + FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data) + : Builder(font_builder, header, data) { +} + +Table::TableBasedTableBuilder::TableBasedTableBuilder( + FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data) + : Builder(font_builder, header, data) { +} + +Table::TableBasedTableBuilder::TableBasedTableBuilder( + FontDataTableBuilderContainer* font_builder, + Header* header) + : Builder(font_builder, header) { +} + +Table* Table::TableBasedTableBuilder::GetTable() { + if (table_ == NULL) { + table_.Attach(down_cast(SubBuildTable(InternalReadData()))); + } + return table_; +} + +/****************************************************************************** + * Table::GenericTableBuilder class + ******************************************************************************/ +Table::GenericTableBuilder::GenericTableBuilder( + FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data) + : TableBasedTableBuilder(font_builder, header, data) { +} + +CALLER_ATTACH FontDataTable* + Table::GenericTableBuilder::SubBuildTable(ReadableFontData* data) { + // Note: In C++ port, we use GenericTable, the ref-counted version of Table + UNREFERENCED_PARAMETER(data); + FontDataTablePtr table = new GenericTable(this->header(), InternalReadData()); + return table.Detach(); +} + +/****************************************************************************** + * Table::ArrayElementTableBuilder class + ******************************************************************************/ +Table::ArrayElementTableBuilder::~ArrayElementTableBuilder() {} + +Table::ArrayElementTableBuilder::ArrayElementTableBuilder( + FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data) + : Builder(font_builder, header, data) { +} + +Table::ArrayElementTableBuilder::ArrayElementTableBuilder( + FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data) + : Builder(font_builder, header, data) { +} + +} // namespace sfntly diff --git a/sfntly/table/table.h b/sfntly/table/table.h new file mode 100644 index 0000000..8c8fcc8 --- /dev/null +++ b/sfntly/table/table.h @@ -0,0 +1,183 @@ +/* + * 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. + */ + +#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_TABLE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TABLE_TABLE_H_ + +#include +#include +#include +#include + +#include "sfntly/port/type.h" +#include "sfntly/table/font_data_table.h" + +namespace sfntly { +class Font; +class Table : public FontDataTable, public FontDataTableBuilderContainer { + public: + class Header : public RefCounted
{ + public: + explicit Header(int32_t tag); + Header(int32_t tag, int32_t length); + Header(int32_t tag, int64_t checksum, int32_t offset, int32_t length); + virtual ~Header(); + + int32_t tag() { return tag_; } + int32_t offset() { return offset_; } + int32_t length() { return length_; } + bool offset_valid() { return offset_valid_; } + int64_t checksum() { return checksum_; } + bool checksum_valid() { return checksum_valid_; } + + private: + int32_t tag_; + int32_t offset_; + int32_t length_; + bool offset_valid_; + int64_t checksum_; + bool checksum_valid_; + + friend class TableHeaderComparator; + }; + + // Note: original version is Builder + // C++ template is not designed that way so plain old inheritance is + // chosen. + class Builder : public FontDataTable::Builder, + public FontDataTableBuilderContainer { + public: + virtual ~Builder(); + virtual Header* header() { return header_; } + virtual void NotifyPostTableBuild(FontDataTable* table); + virtual WritableFontData* GetNewData(int32_t size); + + static CALLER_ATTACH Builder* + GetBuilder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* table_data); + + protected: + // Note: original version is Font.Builder font_builder. This results in + // mutual inclusion happiness that Java solved for C++. Therefore, + // we need to avoid that happiness when we port it to C++. + Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data); + Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data); + Builder(FontDataTableBuilderContainer* font_builder, + Header* header); + + private: + Ptr
header_; + }; + + class TableBasedTableBuilder : public Builder { + public: + virtual ~TableBasedTableBuilder(); + + virtual int32_t SubSerialize(WritableFontData* new_data); + virtual bool SubReadyToSerialize(); + virtual int32_t SubDataSizeToSerialize(); + virtual void SubDataSet(); + + protected: + TableBasedTableBuilder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data); + TableBasedTableBuilder(FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data); + TableBasedTableBuilder(FontDataTableBuilderContainer* font_builder, + Header* header); + + // C++ port: renamed table() to GetTable() + virtual Table* GetTable(); + + // TODO(arthurhsu): style guide violation: protected member, need refactor + Ptr
table_; + }; + + class GenericTableBuilder : public TableBasedTableBuilder, + public RefCounted { + public: + GenericTableBuilder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data); + virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); + }; + + class ArrayElementTableBuilder : public Builder { + public: + virtual ~ArrayElementTableBuilder(); + + protected: + ArrayElementTableBuilder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data); + ArrayElementTableBuilder(FontDataTableBuilderContainer* font_builder, + Header* header, + ReadableFontData* data); + }; + + virtual ~Table(); + virtual int64_t CalculatedChecksum(); + virtual Header* header() { return header_; } + virtual int32_t header_tag() { return header_->tag(); } + virtual int32_t header_offset() { return header_->offset(); } + virtual int32_t header_length() { return header_->length(); } + virtual int64_t header_checksum() { return header_->checksum(); } + virtual WritableFontData* GetNewData(int32_t size); + virtual void SetFont(Font* font); + + protected: + Table(Header* header, ReadableFontData* data); + + private: + Ptr
header_; + Ptr font_; +}; + +// C++ port only +class GenericTable : public Table, public RefCounted { + public: + GenericTable(Header* header, ReadableFontData* data) : Table(header, data) {} + virtual ~GenericTable() {} +}; + +typedef Ptr
TablePtr; +typedef Ptr TableHeaderPtr; +typedef std::vector TableHeaderList; +typedef Ptr TableBuilderPtr; +typedef std::map TableMap; +typedef std::pair TableMapEntry; + +typedef std::map DataBlockMap; +typedef std::pair DataBlockEntry; +typedef std::map TableBuilderMap; +typedef std::pair TableBuilderEntry; + +class TableHeaderComparator { + public: + bool operator()(const TableHeaderPtr h1, const TableHeaderPtr h2); +}; +typedef std::set TableHeaderSortedSet; + +} // namespace sfntly + +#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_TABLE_H_ diff --git a/sfntly/table/truetype/glyph_table.cc b/sfntly/table/truetype/glyph_table.cc new file mode 100644 index 0000000..ff289f3 --- /dev/null +++ b/sfntly/table/truetype/glyph_table.cc @@ -0,0 +1,667 @@ +/* + * 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 "sfntly/table/truetype/glyph_table.h" + +#include + +#include "sfntly/port/exception_type.h" + +namespace sfntly { +/****************************************************************************** + * Constants + ******************************************************************************/ +const int32_t GlyphTable::SimpleGlyph::kFLAG_ONCURVE = 1; +const int32_t GlyphTable::SimpleGlyph::kFLAG_XSHORT = 1 << 1; +const int32_t GlyphTable::SimpleGlyph::kFLAG_YSHORT = 1 << 2; +const int32_t GlyphTable::SimpleGlyph::kFLAG_REPEAT = 1 << 3; +const int32_t GlyphTable::SimpleGlyph::kFLAG_XREPEATSIGN = 1 << 4; +const int32_t GlyphTable::SimpleGlyph::kFLAG_YREPEATSIGN = 1 << 5; + +const int32_t GlyphTable::CompositeGlyph::kFLAG_ARG_1_AND_2_ARE_WORDS = 1 << 0; +const int32_t GlyphTable::CompositeGlyph::kFLAG_ARGS_ARE_XY_VALUES = 1 << 1; +const int32_t GlyphTable::CompositeGlyph::kFLAG_ROUND_XY_TO_GRID = 1 << 2; +const int32_t GlyphTable::CompositeGlyph::kFLAG_WE_HAVE_A_SCALE = 1 << 3; +const int32_t GlyphTable::CompositeGlyph::kFLAG_RESERVED = 1 << 4; +const int32_t GlyphTable::CompositeGlyph::kFLAG_MORE_COMPONENTS = 1 << 5; +const int32_t GlyphTable::CompositeGlyph::kFLAG_WE_HAVE_AN_X_AND_Y_SCALE = 1 << 6; +const int32_t GlyphTable::CompositeGlyph::kFLAG_WE_HAVE_A_TWO_BY_TWO = 1 << 7; +const int32_t GlyphTable::CompositeGlyph::kFLAG_WE_HAVE_INSTRUCTIONS = 1 << 8; +const int32_t GlyphTable::CompositeGlyph::kFLAG_USE_MY_METRICS = 1 << 9; +const int32_t GlyphTable::CompositeGlyph::kFLAG_OVERLAP_COMPOUND = 1 << 10; +const int32_t GlyphTable::CompositeGlyph::kFLAG_SCALED_COMPONENT_OFFSET = 1 << 11; +const int32_t GlyphTable::CompositeGlyph::kFLAG_UNSCALED_COMPONENT_OFFSET = 1 << 12; + +/****************************************************************************** + * GlyphTable class + ******************************************************************************/ +GlyphTable::~GlyphTable() { +} + +GlyphTable::Glyph* GlyphTable::GetGlyph(int32_t offset, int32_t length) { + return GlyphTable::Glyph::GetGlyph(data_, offset, length); +} + +GlyphTable::GlyphTable(Header* header, ReadableFontData* data) + : Table(header, data) { +} + +/****************************************************************************** + * GlyphTable::Builder class + ******************************************************************************/ +GlyphTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data) + : Table::ArrayElementTableBuilder(font_builder, header, data) { +} + +GlyphTable::Builder::~Builder() { +} + +void GlyphTable::Builder::SetLoca(const IntegerList& loca) { + loca_ = loca; + set_model_changed(false); + glyph_builders_.clear(); +} + +void GlyphTable::Builder::GenerateLocaList(IntegerList* locas) { + assert(locas); + GlyphBuilderList* glyph_builders = GetGlyphBuilders(); + locas->resize(glyph_builders->size()); + locas->push_back(0); + if (glyph_builders->size() == 0) { + locas->push_back(0); + } else { + int32_t total = 0; + for (GlyphBuilderList::iterator b = glyph_builders->begin(), + b_end = glyph_builders->end(); + b != b_end; ++b) { + int32_t size = (*b)->SubDataSizeToSerialize(); + locas->push_back(total + size); + total += size; + } + } +} + +GlyphTable::GlyphBuilderList* GlyphTable::Builder::GlyphBuilders() { + return GetGlyphBuilders(); +} + +void GlyphTable::Builder::SetGlyphBuilders(GlyphBuilderList* glyph_builders) { + glyph_builders_ = *glyph_builders; + set_model_changed(); +} + +CALLER_ATTACH GlyphTable::Glyph::Builder* + GlyphTable::Builder::GlyphBuilder(ReadableFontData* data) { + return Glyph::Builder::GetBuilder(this, data); +} + +CALLER_ATTACH FontDataTable* + GlyphTable::Builder::SubBuildTable(ReadableFontData* data) { + FontDataTablePtr table = new GlyphTable(header(), data); + return table.Detach(); +} + +void GlyphTable::Builder::SubDataSet() { + glyph_builders_.clear(); + set_model_changed(false); +} + +int32_t GlyphTable::Builder::SubDataSizeToSerialize() { + if (glyph_builders_.empty()) + return 0; + + bool variable = false; + int32_t size = 0; + + // Calculate size of each table. + for (GlyphBuilderList::iterator b = glyph_builders_.begin(), + end = glyph_builders_.end(); b != end; ++b) { + int32_t glyph_size = (*b)->SubDataSizeToSerialize(); + size += abs(glyph_size); + variable |= glyph_size <= 0; + } + return variable ? -size : size; +} + +bool GlyphTable::Builder::SubReadyToSerialize() { + return !glyph_builders_.empty(); +} + +int32_t GlyphTable::Builder::SubSerialize(WritableFontData* new_data) { + int32_t size = 0; + for (GlyphBuilderList::iterator b = glyph_builders_.begin(), + end = glyph_builders_.end(); b != end; ++b) { + FontDataPtr data; + data.Attach(new_data->Slice(size)); + size += (*b)->SubSerialize(down_cast(data.p_)); + } + return size; +} + +void GlyphTable::Builder::Initialize(ReadableFontData* data, + const IntegerList& loca) { + if (data != NULL) { + if (loca_.empty()) { +#if defined (SFNTLY_NO_EXCEPTION) + return; +#else + throw IllegalStateException( + "Loca values not set - unable to parse glyph data."); +#endif + } + int32_t loca_value; + int32_t last_loca_value = loca[0]; + for (size_t i = 1; i < loca.size(); ++i) { + loca_value = loca[i]; + GlyphBuilderPtr builder; + builder.Attach( + Glyph::Builder::GetBuilder(this, + data, + last_loca_value /*offset*/, + loca_value - last_loca_value /*length*/)); + glyph_builders_.push_back(builder); + last_loca_value = loca_value; + } + } +} + +GlyphTable::GlyphBuilderList* GlyphTable::Builder::GetGlyphBuilders() { + if (glyph_builders_.empty()) { + Initialize(InternalReadData(), loca_); + set_model_changed(); + } + return &glyph_builders_; +} + +void GlyphTable::Builder::Revert() { + glyph_builders_.clear(); + set_model_changed(false); +} + +/****************************************************************************** + * GlyphTable::Glyph class + ******************************************************************************/ +GlyphTable::Glyph::~Glyph() {} + +CALLER_ATTACH GlyphTable::Glyph* + GlyphTable::Glyph::GetGlyph(ReadableFontData* data, + int32_t offset, + int32_t length) { + int32_t type = GlyphType(data, offset, length); + GlyphPtr glyph; + + ReadableFontDataPtr sliced_data; + sliced_data.Attach(down_cast(data->Slice(offset, length))); + if (type == GlyphType::kSimple) { + glyph = new SimpleGlyph(sliced_data); + } else { + glyph = new CompositeGlyph(sliced_data); + } + return glyph.Detach(); +} + +int32_t GlyphTable::Glyph::GlyphType() { + return glyph_type_; +} + +int32_t GlyphTable::Glyph::NumberOfContours() { + return number_of_contours_; +} + +int32_t GlyphTable::Glyph::XMin() { + return data_->ReadShort(Offset::kXMin); +} + +int32_t GlyphTable::Glyph::XMax() { + return data_->ReadShort(Offset::kXMax); +} + +int32_t GlyphTable::Glyph::YMin() { + return data_->ReadShort(Offset::kYMin); +} + +int32_t GlyphTable::Glyph::YMax() { + return data_->ReadShort(Offset::kYMax); +} + +int32_t GlyphTable::Glyph::Padding() { + return padding_; +} + +GlyphTable::Glyph::Glyph(ReadableFontData* data, int32_t glyph_type) + : SubTable(data), + glyph_type_(glyph_type) { + if (data_->Length() == 0) { + number_of_contours_ = 0; + } else { + // -1 if composite + number_of_contours_ = data_->ReadShort(Offset::kNumberOfContours); + } +} + +int32_t GlyphTable::Glyph::GlyphType(ReadableFontData* data, + int32_t offset, + int32_t length) { + if (length == 0) { + return GlyphType::kSimple; + } + int32_t number_of_contours = data->ReadShort(offset); + if (number_of_contours >= 0) { + return GlyphType::kSimple; + } + return GlyphType::kComposite; +} + +/****************************************************************************** + * GlyphTable::Glyph::Builder class + ******************************************************************************/ +GlyphTable::Glyph::Builder::~Builder() { +} + +GlyphTable::Glyph::Builder::Builder(FontDataTableBuilderContainer* font_builder, + WritableFontData* data) + : SubTable::Builder(font_builder, data) { +} + +GlyphTable::Glyph::Builder::Builder(FontDataTableBuilderContainer* font_builder, + ReadableFontData* data) + : SubTable::Builder(font_builder, data) { +} + +CALLER_ATTACH GlyphTable::Glyph::Builder* + GlyphTable::Glyph::Builder::GetBuilder( + FontDataTableBuilderContainer* table_builder, + ReadableFontData* data) { + return GetBuilder(table_builder, data, 0, data->Length()); +} + +CALLER_ATTACH GlyphTable::Glyph::Builder* + GlyphTable::Glyph::Builder::GetBuilder( + FontDataTableBuilderContainer* table_builder, + ReadableFontData* data, + int32_t offset, + int32_t length) { + int32_t type = Glyph::GlyphType(data, offset, length); + GlyphBuilderPtr builder; + ReadableFontDataPtr sliced_data; + sliced_data.Attach(down_cast(data->Slice(offset, length))); + if (type == GlyphType::kSimple) { + builder = new SimpleGlyph::SimpleGlyphBuilder(table_builder, sliced_data); + } else { + builder = new CompositeGlyph::CompositeGlyphBuilder(table_builder, + sliced_data); + } + return builder.Detach(); +} + +void GlyphTable::Glyph::Builder::SubDataSet() { + // NOP +} + +int32_t GlyphTable::Glyph::Builder::SubDataSizeToSerialize() { + return InternalReadData()->Length(); +} + +bool GlyphTable::Glyph::Builder::SubReadyToSerialize() { + return true; +} + +int32_t GlyphTable::Glyph::Builder::SubSerialize(WritableFontData* new_data) { + return InternalReadData()->CopyTo(new_data); +} + +/****************************************************************************** + * GlyphTable::SimpleGlyph + ******************************************************************************/ +GlyphTable::SimpleGlyph::SimpleGlyph(ReadableFontData* data) + : GlyphTable::Glyph(data, GlyphType::kSimple) { +} + +GlyphTable::SimpleGlyph::~SimpleGlyph() { +} + +int32_t GlyphTable::SimpleGlyph::InstructionSize() { + Initialize(); + return instruction_size_; +} + +CALLER_ATTACH ReadableFontData* GlyphTable::SimpleGlyph::Instructions() { + Initialize(); + return down_cast( + data_->Slice(instructions_offset_, InstructionSize())); +} + +int32_t GlyphTable::SimpleGlyph::NumberOfPoints(int32_t contour) { + Initialize(); + if (contour >= NumberOfContours()) { + return 0; + } + return contour_index_[contour + 1] - contour_index_[contour]; +} + +int32_t GlyphTable::SimpleGlyph::XCoordinate(int32_t contour, int32_t point) { + Initialize(); + return x_coordinates_[contour_index_[contour] + point]; +} + +int32_t GlyphTable::SimpleGlyph::YCoordinate(int32_t contour, int32_t point) { + Initialize(); + return y_coordinates_[contour_index_[contour] + point]; +} + +bool GlyphTable::SimpleGlyph::OnCurve(int32_t contour, int32_t point) { + Initialize(); + return on_curve_[contour_index_[contour] + point]; +} + +void GlyphTable::SimpleGlyph::Initialize() { + if (initialized_) { + return; + } + + if (ReadFontData()->Length() == 0) { + instruction_size_ = 0; + number_of_points_ = 0; + instructions_offset_ = 0; + flags_offset_ = 0; + x_coordinates_offset_ = 0; + y_coordinates_offset_ = 0; + return; + } + + instruction_size_ = data_->ReadUShort(Offset::kSimpleEndPtsOfCountours + + NumberOfContours() * DataSize::kUSHORT); + instructions_offset_ = Offset::kSimpleEndPtsOfCountours + + (NumberOfContours() + 1) * DataSize::kUSHORT; + flags_offset_ = instructions_offset_ + instruction_size_ * DataSize::kBYTE; + number_of_points_ = ContourEndPoint(NumberOfContours() - 1) + 1; + x_coordinates_.resize(number_of_points_); + y_coordinates_.resize(number_of_points_); + on_curve_.resize(number_of_points_); + ParseData(false); + x_coordinates_offset_ = flags_offset_ + flag_byte_count_ * DataSize::kBYTE; + y_coordinates_offset_ = x_coordinates_offset_ + x_byte_count_ * + DataSize::kBYTE; + contour_index_.resize(NumberOfContours() + 1); + contour_index_[0] = 0; + for (uint32_t contour = 0; contour < contour_index_.size() - 1; ++contour) { + contour_index_[contour + 1] = ContourEndPoint(contour) + 1; + } + ParseData(true); + int32_t non_padded_data_length = + 5 * DataSize::kSHORT + + (NumberOfContours() * DataSize::kUSHORT) + + DataSize::kUSHORT + + (instruction_size_ * DataSize::kBYTE) + + (flag_byte_count_ * DataSize::kBYTE) + + (x_byte_count_ * DataSize::kBYTE) + + (y_byte_count_ * DataSize::kBYTE); + padding_ = Length() - non_padded_data_length; + initialized_ = true; +} + +void GlyphTable::SimpleGlyph::ParseData(bool fill_arrays) { + int32_t flag = 0; + int32_t flag_repeat = 0; + int32_t flag_index = 0; + int32_t x_byte_index = 0; + int32_t y_byte_index = 0; + + for (int32_t point_index = 0; point_index < number_of_points_; + ++point_index) { + // get the flag for the current point + if (flag_repeat == 0) { + flag = FlagAsInt(flag_index++); + if ((flag & kFLAG_REPEAT) == kFLAG_REPEAT) { + flag_repeat = FlagAsInt(flag_index++); + } + } else { + flag_repeat--; + } + + // on the curve? + if (fill_arrays) { + on_curve_[point_index] = ((flag & kFLAG_ONCURVE) == kFLAG_ONCURVE); + } + // get the x coordinate + if ((flag & kFLAG_XSHORT) == kFLAG_XSHORT) { + // single byte x coord value + if (fill_arrays) { + x_coordinates_[point_index] = + data_->ReadUByte(x_coordinates_offset_ + x_byte_index); + x_coordinates_[point_index] *= + ((flag & kFLAG_XREPEATSIGN) == kFLAG_XREPEATSIGN) ? 1 : -1; + } + x_byte_index++; + } else { + // double byte coord value + if (!((flag & kFLAG_XREPEATSIGN) == kFLAG_XREPEATSIGN)) { + if (fill_arrays) { + x_coordinates_[point_index] = + data_->ReadShort(x_coordinates_offset_ + x_byte_index); + } + x_byte_index += 2; + } + } + if (fill_arrays && point_index > 0) { + x_coordinates_[point_index] += x_coordinates_[point_index - 1]; + } + + // get the y coordinate + if ((flag & kFLAG_YSHORT) == kFLAG_YSHORT) { + if (fill_arrays) { + y_coordinates_[point_index] = + data_->ReadUByte(y_coordinates_offset_ + y_byte_index); + y_coordinates_[point_index] *= + ((flag & kFLAG_YREPEATSIGN) == kFLAG_YREPEATSIGN) ? 1 : -1; + } + y_byte_index++; + } else { + if (!((flag & kFLAG_YREPEATSIGN) == kFLAG_YREPEATSIGN)) { + if (fill_arrays) { + y_coordinates_[point_index] = + data_->ReadShort(y_coordinates_offset_ + y_byte_index); + } + y_byte_index += 2; + } + } + if (fill_arrays && point_index > 0) { + y_coordinates_[point_index] += y_coordinates_[point_index - 1]; + } + } + flag_byte_count_ = flag_index; + x_byte_count_ = x_byte_index; + y_byte_count_ = y_byte_index; +} + +int32_t GlyphTable::SimpleGlyph::FlagAsInt(int32_t index) { + return data_->ReadUByte(flags_offset_ + index * DataSize::kBYTE); +} + +int32_t GlyphTable::SimpleGlyph::ContourEndPoint(int32_t contour) { + return data_->ReadUShort(contour * DataSize::kUSHORT + + Offset::kSimpleEndPtsOfCountours); +} + +/****************************************************************************** + * GlyphTable::SimpleGlyph::Builder + ******************************************************************************/ +GlyphTable::SimpleGlyph::SimpleGlyphBuilder::~SimpleGlyphBuilder() { +} + +GlyphTable::SimpleGlyph::SimpleGlyphBuilder::SimpleGlyphBuilder( + FontDataTableBuilderContainer* table_builder, + WritableFontData* data) + : Glyph::Builder(table_builder, data) { +} + +GlyphTable::SimpleGlyph::SimpleGlyphBuilder::SimpleGlyphBuilder( + FontDataTableBuilderContainer* table_builder, + ReadableFontData* data) + : Glyph::Builder(table_builder, data) { +} + +CALLER_ATTACH FontDataTable* + GlyphTable::SimpleGlyph::SimpleGlyphBuilder::SubBuildTable( + ReadableFontData* data) { + FontDataTablePtr table = new SimpleGlyph(data); + return table.Detach(); +} + +/****************************************************************************** + * GlyphTable::CompositeGlyph + ******************************************************************************/ +GlyphTable::CompositeGlyph::CompositeGlyph(ReadableFontData* data) + : GlyphTable::Glyph(data, GlyphType::kComposite), + instruction_size_(0), + instructions_offset_(0) { + ParseData(); +} + +GlyphTable::CompositeGlyph::~CompositeGlyph() { +} + +int32_t GlyphTable::CompositeGlyph::Flags(int32_t contour) { + return data_->ReadUShort(contour_index_[contour]); +} + +int32_t GlyphTable::CompositeGlyph::NumGlyphs() { + return contour_index_.size(); +} + +int32_t GlyphTable::CompositeGlyph::GlyphIndex(int32_t contour) { + return data_->ReadUShort(DataSize::kUSHORT + contour_index_[contour]); +} + +int32_t GlyphTable::CompositeGlyph::Argument1(int32_t contour) { + int32_t index = 2 * DataSize::kUSHORT + contour_index_[contour]; + int32_t contour_flags = Flags(contour); + if ((contour_flags & kFLAG_ARG_1_AND_2_ARE_WORDS) == + kFLAG_ARG_1_AND_2_ARE_WORDS) { + return data_->ReadUShort(index); + } + return data_->ReadByte(index); +} + +int32_t GlyphTable::CompositeGlyph::Argument2(int32_t contour) { + int32_t index = 2 * DataSize::kUSHORT + contour_index_[contour]; + int32_t contour_flags = Flags(contour); + if ((contour_flags & kFLAG_ARG_1_AND_2_ARE_WORDS) == + kFLAG_ARG_1_AND_2_ARE_WORDS) { + return data_->ReadUShort(index + DataSize::kUSHORT); + } + return data_->ReadByte(index + DataSize::kUSHORT); +} + +int32_t GlyphTable::CompositeGlyph::TransformationSize(int32_t contour) { + int32_t contour_flags = Flags(contour); + if ((contour_flags & kFLAG_WE_HAVE_A_SCALE) == kFLAG_WE_HAVE_A_SCALE) { + return DataSize::kF2DOT14; + } else if ((contour_flags & kFLAG_WE_HAVE_AN_X_AND_Y_SCALE) == + kFLAG_WE_HAVE_AN_X_AND_Y_SCALE) { + return 2 * DataSize::kF2DOT14; + } else if ((contour_flags & kFLAG_WE_HAVE_A_TWO_BY_TWO) == + kFLAG_WE_HAVE_A_TWO_BY_TWO) { + return 4 * DataSize::kF2DOT14; + } + return 0; +} + +void GlyphTable::CompositeGlyph::Transformation(int32_t contour, + ByteVector* transformation) { + int32_t contour_flags = Flags(contour); + int32_t index = contour_index_[contour] + 2 * DataSize::kUSHORT; + if ((contour_flags & kFLAG_ARG_1_AND_2_ARE_WORDS) == + kFLAG_ARG_1_AND_2_ARE_WORDS) { + index += 2 * DataSize::kSHORT; + } else { + index += 2 * DataSize::kBYTE; + } + int32_t tsize = TransformationSize(contour); + transformation->resize(tsize); + data_->ReadBytes(index, &((*transformation)[0]), 0, tsize); +} + +int32_t GlyphTable::CompositeGlyph::InstructionSize() { + return instruction_size_; +} + +CALLER_ATTACH ReadableFontData* GlyphTable::CompositeGlyph::Instructions() { + return down_cast( + data_->Slice(instructions_offset_, InstructionSize())); +} + +void GlyphTable::CompositeGlyph::ParseData() { + int32_t index = 5 * DataSize::kUSHORT; + int32_t flags = kFLAG_MORE_COMPONENTS; + + while ((flags & kFLAG_MORE_COMPONENTS) == kFLAG_MORE_COMPONENTS) { + contour_index_.push_back(index); + flags = data_->ReadUShort(index); + index += 2 * DataSize::kUSHORT; // flags and glyphIndex + if ((flags & kFLAG_ARG_1_AND_2_ARE_WORDS) == kFLAG_ARG_1_AND_2_ARE_WORDS) { + index += 2 * DataSize::kSHORT; + } else { + index += 2 * DataSize::kBYTE; + } + if ((flags & kFLAG_WE_HAVE_A_SCALE) == kFLAG_WE_HAVE_A_SCALE) { + index += DataSize::kF2DOT14; + } else if ((flags & kFLAG_WE_HAVE_AN_X_AND_Y_SCALE) == + kFLAG_WE_HAVE_AN_X_AND_Y_SCALE) { + index += 2 * DataSize::kF2DOT14; + } else if ((flags & kFLAG_WE_HAVE_A_TWO_BY_TWO) == + kFLAG_WE_HAVE_A_TWO_BY_TWO) { + index += 4 * DataSize::kF2DOT14; + } + int32_t non_padded_data_length = index; + if ((flags & kFLAG_WE_HAVE_INSTRUCTIONS) == kFLAG_WE_HAVE_INSTRUCTIONS) { + instruction_size_ = data_->ReadUShort(index); + index += DataSize::kUSHORT; + instructions_offset_ = index; + non_padded_data_length = index + (instruction_size_ * DataSize::kBYTE); + } + padding_ = Length() - non_padded_data_length; + } +} + +/****************************************************************************** + * GlyphTable::CompositeGlyph::Builder + ******************************************************************************/ +GlyphTable::CompositeGlyph::CompositeGlyphBuilder::~CompositeGlyphBuilder() { +} + +GlyphTable::CompositeGlyph::CompositeGlyphBuilder::CompositeGlyphBuilder( + FontDataTableBuilderContainer* table_builder, + WritableFontData* data) + : Glyph::Builder(table_builder, data) { +} + +GlyphTable::CompositeGlyph::CompositeGlyphBuilder::CompositeGlyphBuilder( + FontDataTableBuilderContainer* table_builder, + ReadableFontData* data) + : Glyph::Builder(table_builder, data) { +} + +CALLER_ATTACH FontDataTable* + GlyphTable::CompositeGlyph::CompositeGlyphBuilder::SubBuildTable( + ReadableFontData* data) { + FontDataTablePtr table = new CompositeGlyph(data); + return table.Detach(); +} + +} // namespace sfntly diff --git a/sfntly/table/truetype/glyph_table.h b/sfntly/table/truetype/glyph_table.h new file mode 100644 index 0000000..320c522 --- /dev/null +++ b/sfntly/table/truetype/glyph_table.h @@ -0,0 +1,330 @@ +/* + * 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. + */ + +#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_TRUETYPE_GLYPH_TABLE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TABLE_TRUETYPE_GLYPH_TABLE_H_ + +#include + +#include "sfntly/table/table.h" +#include "sfntly/table/subtable.h" + +namespace sfntly { + +struct GlyphType { + enum { + kSimple = 0, + kComposite = 1 + }; +}; + +// Note: due to the complexity of this class, the order of declaration is +// different from its Java counter part. GlyphTable::Glyph is defined +// before GlyphTable::Builder to avoid compilation errors. +class GlyphTable : public Table, public RefCounted { + public: + class Builder; + class Glyph : public SubTable { + public: + // Note: Contour is an empty class for the version ported + class Contour { + protected: + Contour() {} + virtual ~Contour() {} + }; + + class Builder : public SubTable::Builder { + public: + virtual ~Builder(); + + protected: + // Incoming table_builder is GlyphTable::Builder*. + // Note: constructor refactored in C++ to avoid heavy lifting. + // caller need to do data->Slice(offset, length) beforehand. + Builder(FontDataTableBuilderContainer* table_builder, + WritableFontData* data); + Builder(FontDataTableBuilderContainer* table_builder, + ReadableFontData* data); + + static CALLER_ATTACH Builder* + GetBuilder(FontDataTableBuilderContainer* table_builder, + ReadableFontData* data); + static CALLER_ATTACH Builder* + GetBuilder(FontDataTableBuilderContainer* table_builder, + ReadableFontData* data, + int32_t offset, + int32_t length); + virtual void SubDataSet(); + virtual int32_t SubDataSizeToSerialize(); + virtual bool SubReadyToSerialize(); + virtual int32_t SubSerialize(WritableFontData* new_data); + + private: + int32_t format_; + friend class GlyphTable::Builder; + }; + + virtual ~Glyph(); + static CALLER_ATTACH Glyph* GetGlyph(ReadableFontData* data, + int32_t offset, + int32_t length); + virtual int32_t GlyphType(); + virtual int32_t NumberOfContours(); + virtual int32_t XMin(); + virtual int32_t XMax(); + virtual int32_t YMin(); + virtual int32_t YMax(); + virtual int32_t Padding(); // override FontDataTable::Padding() + + virtual int32_t InstructionSize() = 0; + virtual ReadableFontData* Instructions() = 0; + + protected: + // Note: constructor refactored in C++ to avoid heavy lifting. + // caller need to do data->Slice(offset, length) beforehand. + Glyph(ReadableFontData* data, int32_t glyph_type); + + // TODO(arthurhsu): violating C++ style guide, need refactoring. + int32_t padding_; + + private: + static int32_t GlyphType(ReadableFontData* data, + int32_t offset, + int32_t length); + + int32_t glyph_type_; + int32_t number_of_contours_; + }; // class GlyphTable::Glyph + typedef Ptr GlyphBuilderPtr; + typedef std::vector GlyphBuilderList; + + class Builder : public Table::ArrayElementTableBuilder, + public RefCounted { + public: + // Note: Constructor scope altered to public for base class to instantiate. + Builder(FontDataTableBuilderContainer* font_builder, + Header* header, + WritableFontData* data); + virtual ~Builder(); + + virtual void SetLoca(const IntegerList& loca); + virtual void GenerateLocaList(IntegerList* locas); + + // Gets the List of glyph builders for the glyph table builder. These may be + // manipulated in any way by the caller and the changes will be reflected in + // the final glyph table produced. + // If there is no current data for the glyph builder or the glyph builders + // have not been previously set then this will return an empty glyph builder + // List. If there is current data (i.e. data read from an existing font) and + // the loca list has not been set or is null, empty, or + // invalid, then an empty glyph builder List will be returned. + GlyphBuilderList* GlyphBuilders(); + + // Replace the internal glyph builders with the one provided. + void SetGlyphBuilders(GlyphBuilderList* glyph_builders); + + // Glyph builder factories + CALLER_ATTACH Glyph::Builder* GlyphBuilder(ReadableFontData* data); + + protected: // internal API for building + virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); + virtual void SubDataSet(); + virtual int32_t SubDataSizeToSerialize(); + virtual bool SubReadyToSerialize(); + virtual int32_t SubSerialize(WritableFontData* new_data); + + private: + void Initialize(ReadableFontData* data, const IntegerList& loca); + GlyphBuilderList* GetGlyphBuilders(); + void Revert(); + + GlyphBuilderList glyph_builders_; + IntegerList loca_; + }; + + class SimpleGlyph : public Glyph, public RefCounted { + public: + static const int32_t kFLAG_ONCURVE; + static const int32_t kFLAG_XSHORT; + static const int32_t kFLAG_YSHORT; + static const int32_t kFLAG_REPEAT; + static const int32_t kFLAG_XREPEATSIGN; + static const int32_t kFLAG_YREPEATSIGN; + + class SimpleContour : public Glyph::Contour { + protected: + SimpleContour() {} + virtual ~SimpleContour() {} + }; + + class SimpleGlyphBuilder : public Glyph::Builder, + public RefCounted { + public: + virtual ~SimpleGlyphBuilder(); + + protected: + // Note: constructor refactored in C++ to avoid heavy lifting. + // caller need to do data->Slice(offset, length) beforehand. + SimpleGlyphBuilder(FontDataTableBuilderContainer* table_builder, + WritableFontData* data); + SimpleGlyphBuilder(FontDataTableBuilderContainer* table_builder, + ReadableFontData* data); + virtual CALLER_ATTACH FontDataTable* + SubBuildTable(ReadableFontData* data); + + private: + friend class Glyph::Builder; + }; + + // Note: constructor refactored in C++ to avoid heavy lifting. + // caller need to do data->Slice(offset, length) beforehand. + explicit SimpleGlyph(ReadableFontData* data); + virtual ~SimpleGlyph(); + + virtual int32_t InstructionSize(); + virtual CALLER_ATTACH ReadableFontData* Instructions(); + int32_t NumberOfPoints(int32_t contour); + int32_t XCoordinate(int32_t contour, int32_t point); + int32_t YCoordinate(int32_t contour, int32_t point); + bool OnCurve(int32_t contour, int32_t point); + + private: + void Initialize(); + void ParseData(bool fill_arrays); + int32_t FlagAsInt(int32_t index); + int32_t ContourEndPoint(int32_t contour); + + bool initialized_; + int32_t instruction_size_; + int32_t number_of_points_; + + // start offsets of the arrays + int32_t instructions_offset_; + int32_t flags_offset_; + int32_t x_coordinates_offset_; + int32_t y_coordinates_offset_; + + int32_t flag_byte_count_; + int32_t x_byte_count_; + int32_t y_byte_count_; + + IntegerList x_coordinates_; + IntegerList y_coordinates_; + std::vector on_curve_; + IntegerList contour_index_; + }; + + class CompositeGlyph : public Glyph, public RefCounted { + public: + static const int32_t kFLAG_ARG_1_AND_2_ARE_WORDS; + static const int32_t kFLAG_ARGS_ARE_XY_VALUES; + static const int32_t kFLAG_ROUND_XY_TO_GRID; + static const int32_t kFLAG_WE_HAVE_A_SCALE; + static const int32_t kFLAG_RESERVED; + static const int32_t kFLAG_MORE_COMPONENTS; + static const int32_t kFLAG_WE_HAVE_AN_X_AND_Y_SCALE; + static const int32_t kFLAG_WE_HAVE_A_TWO_BY_TWO; + static const int32_t kFLAG_WE_HAVE_INSTRUCTIONS; + static const int32_t kFLAG_USE_MY_METRICS; + static const int32_t kFLAG_OVERLAP_COMPOUND; + static const int32_t kFLAG_SCALED_COMPONENT_OFFSET; + static const int32_t kFLAG_UNSCALED_COMPONENT_OFFSET; + + class CompositeGlyphBuilder : public Glyph::Builder, + public RefCounted { + public: + virtual ~CompositeGlyphBuilder(); + + protected: + // Note: constructor refactored in C++ to avoid heavy lifting. + // caller need to do data->Slice(offset, length) beforehand. + CompositeGlyphBuilder(FontDataTableBuilderContainer* table_builder, + WritableFontData* data); + CompositeGlyphBuilder(FontDataTableBuilderContainer* table_builder, + ReadableFontData* data); + + virtual CALLER_ATTACH FontDataTable* + SubBuildTable(ReadableFontData* data); + + private: + friend class Glyph::Builder; + }; + + // Note: constructor refactored in C++ to avoid heavy lifting. + // caller need to do data->Slice(offset, length) beforehand. + explicit CompositeGlyph(ReadableFontData* data); + virtual ~CompositeGlyph(); + + int32_t Flags(int32_t contour); + int32_t NumGlyphs(); + int32_t GlyphIndex(int32_t contour); + int32_t Argument1(int32_t contour); + int32_t Argument2(int32_t contour); + int32_t TransformationSize(int32_t contour); + void Transformation(int32_t contour, ByteVector* transformation); + virtual int32_t InstructionSize(); + virtual CALLER_ATTACH ReadableFontData* Instructions(); + + private: + void ParseData(); + + IntegerList contour_index_; + int32_t instruction_size_; + int32_t instructions_offset_; + }; + + virtual ~GlyphTable(); + + // C++ port: rename glyph() to GetGlyph(). + Glyph* GetGlyph(int32_t offset, int32_t length); + + private: + struct Offset { + enum { + // header + kNumberOfContours = 0, + kXMin = 2, + kYMin = 4, + kXMax = 6, + kYMax = 8, + + // Simple Glyph Description + kSimpleEndPtsOfCountours = 10, + // offset from the end of the contours array + kSimpleInstructionLength = 0, + kSimpleInstructions = 2, + // flags + // xCoordinates + // yCoordinates + + // Composite Glyph Description + kCompositeFlags = 0, + kCompositeGyphIndexWithoutFlag = 0, + kCompositeGlyphIndexWithFlag = 2, + }; + }; + + GlyphTable(Header* header, ReadableFontData* data); +}; +typedef Ptr GlyphTablePtr; +typedef Ptr GlyphTableBuilderPtr; +typedef std::vector GlyphTableBuilderList; +typedef Ptr GlyphPtr; +typedef Ptr GlyphBuilderPtr; + +} // namespace sfntly + +#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_TRUETYPE_GLYPH_TABLE_H_ diff --git a/sfntly/table/truetype/loca_table.cc b/sfntly/table/truetype/loca_table.cc new file mode 100644 index 0000000..537e433 --- /dev/null +++ b/sfntly/table/truetype/loca_table.cc @@ -0,0 +1,250 @@ +/* + * 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 "sfntly/table/truetype/loca_table.h" +#include "sfntly/port/exception_type.h" + +namespace sfntly { +/****************************************************************************** + * LocaTable class + ******************************************************************************/ +LocaTable::~LocaTable() {} + +int32_t LocaTable::NumGlyphs() { + return num_glyphs_; +} + +int32_t LocaTable::GlyphOffset(int32_t glyph_id) { + if (glyph_id < 0 || glyph_id >= num_glyphs_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else + throw IndexOutOfBoundException("Glyph ID is out of bounds."); +#endif + } + return Loca(glyph_id); +} + +int32_t LocaTable::GlyphLength(int32_t glyph_id) { + if (glyph_id < 0 || glyph_id >= num_glyphs_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else + throw IndexOutOfBoundException("Glyph ID is out of bounds."); +#endif + } + return Loca(glyph_id + 1) - Loca(glyph_id); +} + +int32_t LocaTable::NumLocas() { + return num_glyphs_ + 1; +} + +int32_t LocaTable::Loca(int32_t index) { + if (index > num_glyphs_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else + throw IndexOutOfBoundException(); +#endif + } + if (version_ == IndexToLocFormat::kShortOffset) { + return 2 * data_->ReadUShort(index * DataSize::kUSHORT); + } + return data_->ReadULongAsInt(index * DataSize::kULONG); +} + +LocaTable::LocaTable(Header* header, ReadableFontData* data) + : Table(header, data) { +} + +LocaTable::LocaTable(Header* header, + ReadableFontData* data, + int32_t version, + int32_t num_glyphs) + : Table(header, data), version_(version), num_glyphs_(num_glyphs) { +} + +/****************************************************************************** + * LocaTable::Iterator class + ******************************************************************************/ +LocaTable::LocaIterator::LocaIterator(LocaTable* table) + : index_(-1) { + table_ = table; +} + +bool LocaTable::LocaIterator::HasNext() { + return index_ <= table_->num_glyphs_; +} + +int32_t LocaTable::LocaIterator::Next() { + return table_->Loca(index_++); +} + +/****************************************************************************** + * LocaTable::Builder class + ******************************************************************************/ +LocaTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, + Header* header, WritableFontData* data) : + Table::ArrayElementTableBuilder(font_builder, header, data) { + Init(); +} + +LocaTable::Builder::Builder(FontDataTableBuilderContainer* font_builder, + Header* header, ReadableFontData* data) : + Table::ArrayElementTableBuilder(font_builder, header, data) { + Init(); +} + +LocaTable::Builder::~Builder() {} + +void LocaTable::Builder::SetFormatVersion(int32_t format_version) { + format_version_ = format_version; +} + +IntegerList* LocaTable::Builder::LocaList() { + return GetLocaList(); +} + +void LocaTable::Builder::SetLocaList(IntegerList* list) { + loca_.clear(); + if (list) { + loca_ = *list; + num_glyphs_ = loca_.size(); + set_model_changed(); + } +} + +int32_t LocaTable::Builder::GlyphOffset(int32_t glyph_id) { + if (glyph_id < 0 || glyph_id > (num_glyphs_ + 1)) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else + throw IndexOutOfBoundException("Glyph ID is out of bounds."); +#endif + } + return Loca(glyph_id); +} + +int32_t LocaTable::Builder::GlyphLength(int32_t glyph_id) { + if (glyph_id < 0 || glyph_id > (num_glyphs_ + 1)) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else + throw IndexOutOfBoundException("Glyph ID is out of bounds."); +#endif + } + return Loca(glyph_id + 1) - Loca(glyph_id); +} + +void LocaTable::Builder::SetNumGlyphs(int32_t num_glyphs) { + num_glyphs_ = num_glyphs; +} + +int32_t LocaTable::Builder::NumGlyphs() { + if (!loca_.empty()) { + return loca_.size() - 1; + } + return num_glyphs_; +} + +void LocaTable::Builder::Revert() { + loca_.clear(); + set_model_changed(false); +} + +void LocaTable::Builder::Clear() { + GetLocaList()->clear(); +} + +int32_t LocaTable::Builder::NumLocas() { + return GetLocaList()->size(); +} + +int32_t LocaTable::Builder::Loca(int32_t index) { + return GetLocaList()->at(index); +} + +CALLER_ATTACH FontDataTable* LocaTable::Builder::SubBuildTable( + ReadableFontData* data) { + FontDataTablePtr table = + new LocaTable(header(), data, format_version_, num_glyphs_); + return table.Detach(); +} + +void LocaTable::Builder::SubDataSet() { + Initialize(InternalReadData()); +} + +int32_t LocaTable::Builder::SubDataSizeToSerialize() { + if (loca_.empty()) { + return 0; + } + if (format_version_ == IndexToLocFormat::kLongOffset) { + return loca_.size() * DataSize::kULONG; + } + return loca_.size() * DataSize::kUSHORT; +} + +bool LocaTable::Builder::SubReadyToSerialize() { + return !loca_.empty(); +} + +int32_t LocaTable::Builder::SubSerialize(WritableFontData* new_data) { + int32_t size = 0; + for (IntegerList::iterator l = loca_.begin(), end = loca_.end(); + l != end; ++l) { + if (format_version_ == IndexToLocFormat::kLongOffset) { + size += new_data->WriteULong(size, *l); + } else { + size += new_data->WriteUShort(size, *l / 2); + } + } + return 0; +} + +void LocaTable::Builder::Init() { + num_glyphs_ = -1; + format_version_ = IndexToLocFormat::kLongOffset; +} + +void LocaTable::Builder::Initialize(ReadableFontData* data) { + if (data) { + if (NumGlyphs() < 0) { +#if defined (SFNTLY_NO_EXCEPTION) + return; +#else + throw IllegalStateException("numglyphs not set on LocaTable Builder."); +#endif + } + LocaTablePtr table = + new LocaTable(header(), data, format_version_, num_glyphs_); + LocaTable::LocaIterator loca_iter(table); + while (loca_iter.HasNext()) { + loca_.push_back(loca_iter.Next()); + } + } +} + +IntegerList* LocaTable::Builder::GetLocaList() { + if (loca_.empty()) { + Initialize(InternalReadData()); + set_model_changed(); + } + return &loca_; +} + +} // namespace sfntly diff --git a/sfntly/table/truetype/loca_table.h b/sfntly/table/truetype/loca_table.h new file mode 100644 index 0000000..ce7fa44 --- /dev/null +++ b/sfntly/table/truetype/loca_table.h @@ -0,0 +1,146 @@ +/* + * 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. + */ + +#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_TRUETYPE_LOCA_TABLE_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TABLE_TRUETYPE_LOCA_TABLE_H_ + +#include "sfntly/table/table.h" +#include "sfntly/table/core/font_header_table.h" + +namespace sfntly { + +class LocaTable : public Table, public RefCounted { + public: + // Note: different implementation than Java, caller to instantiate this class + // object directly from stack instead of calling LocaTable::iterator(). + class LocaIterator { + public: + explicit LocaIterator(LocaTable* table); + bool HasNext(); + int32_t Next(); + + private: + int32_t index_; + LocaTable* table_; // use dumb pointer since it's a composition object + }; + + class Builder : public Table::ArrayElementTableBuilder, + public RefCounted { + public: + // Constructor scope altered to public for base class to instantiate. + Builder(FontDataTableBuilderContainer* font_builder, Header* header, + WritableFontData* data); + Builder(FontDataTableBuilderContainer* font_builder, Header* header, + ReadableFontData* data); + virtual ~Builder(); + + void SetFormatVersion(int32_t format_version); + + // Gets the List of locas for loca table builder. These may be manipulated + // in any way by the caller and the changes will be reflected in the final + // loca table produced. + // If there is no current data for the loca table builder or the loca list + // have not been previously set then this will return an empty List. + IntegerList* LocaList(); + void SetLocaList(IntegerList* list); + + // Return the offset for the given glyph id. Valid glyph ids are from 0 to + // one less than the number of glyphs. The zero entry is the special entry + // for the notdef glyph. The final entry beyond the last glyph id is used to + // calculate the size of the last glyph. + // @param glyphId the glyph id to get the offset for; must be less than or + // equal to one more than the number of glyph ids + // @return the offset in the glyph table to the specified glyph id + int32_t GlyphOffset(int32_t glyph_id); + + // Get the length of the data in the glyph table for the specified glyph id. + int32_t GlyphLength(int32_t glyph_id); + + // Set the number of glyphs. + // This method sets the number of glyphs that the builder will attempt to + // parse location data for from the raw binary data. This method only needs + // to be called (and must be) when the raw data for this builder has + // been changed. + void SetNumGlyphs(int32_t num_glyphs); + int NumGlyphs(); + + void Revert(); + void Clear(); + + // Get the number of locations or locas. This will be one more than the + // number of glyphs for this table since the last loca position is used to + // indicate the size of the final glyph. + int32_t NumLocas(); + int32_t Loca(int32_t index); + + virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); + virtual void SubDataSet(); + virtual int32_t SubDataSizeToSerialize(); + virtual bool SubReadyToSerialize(); + virtual int32_t SubSerialize(WritableFontData* new_data); + + private: + void Init(); // short hand for common code in ctors, C++ port only + void Initialize(ReadableFontData* data); // ported from Java + IntegerList* GetLocaList(); + + int32_t format_version_; // Note: IndexToLocFormat + int32_t num_glyphs_; + IntegerList loca_; + }; + + virtual ~LocaTable(); + int32_t NumGlyphs(); + + // Return the offset for the given glyph id. Valid glyph ids are from 0 to the + // one less than the number of glyphs. The zero entry is the special entry for + // the notdef glyph. The final entry beyond the last glyph id is used to + // calculate the size of the last glyph. + // @param glyphId the glyph id to get the offset for; must be less than or + // equal to one more than the number of glyph ids + // @return the offset in the glyph table to the specified glyph id + int32_t GlyphOffset(int32_t glyph_id); + + // Get the length of the data in the glyph table for the specified glyph id. + int32_t GlyphLength(int32_t glyph_id); + + // Get the number of locations or locas. This will be one more than the number + // of glyphs for this table since the last loca position is used to indicate + // the size of the final glyph. + int32_t NumLocas(); + + // Get the value from the loca table for the index specified. Valid index + // values run from 0 to the number of glyphs in the font. + int32_t Loca(int32_t index); + + private: + LocaTable(Header* header, ReadableFontData* data); + LocaTable(Header* header, + ReadableFontData* data, + int32_t version, + int32_t num_glyphs); + + int32_t version_; // Note: IndexToLocFormat + int32_t num_glyphs_; + + friend class LocaIterator; +}; +typedef Ptr LocaTablePtr; +typedef Ptr LocaTableBuilderPtr; + +} // namespace sfntly + +#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_TRUETYPE_LOCA_TABLE_H_ diff --git a/sfntly/tag.h b/sfntly/tag.h index 9a548f6..9b50a85 100644 --- a/sfntly/tag.h +++ b/sfntly/tag.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TAG_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TAG_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_TAG_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TAG_H_ #include @@ -108,4 +108,4 @@ extern const size_t TRUE_TYPE_TABLE_ORDERING_SIZE; } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TAG_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_TAG_H_ diff --git a/sfntly/tools/subsetter.cc b/sfntly/tools/subsetter.cc deleted file mode 100644 index c234a1e..0000000 --- a/sfntly/tools/subsetter.cc +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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 "sfntly/tools/subsetter/subsetter.h" - -#include -#include - -#include "sfntly/tools/subsetter/glyph_table_subsetter.h" - -namespace sfntly { - -Subsetter::Subsetter(Font* font, FontFactory* font_factory) { - font_ = font; - font_factory_ = font_factory; - TableSubsetterPtr subsetter = new GlyphTableSubsetter(); - // TODO(arthurhsu): IMPLEMENT: CMap table subsetter - table_subsetters_.push_back(subsetter); -} - -Subsetter::~Subsetter() { - font_factory_.Release(); - font_.Release(); - table_subsetters_.clear(); -} - -void Subsetter::SetGlyphs(IntegerList* glyphs) { - new_to_old_glyphs_ = *glyphs; -} - -void Subsetter::SetCMaps(CMapIdList* cmap_ids, int32_t number) { - UNREFERENCED_PARAMETER(cmap_ids); - UNREFERENCED_PARAMETER(number); - // TODO(arthurhsu): IMPLEMENT -} - -void Subsetter::SetRemoveTables(IntegerSet* remove_tables) { - remove_tables_ = *remove_tables; -} - -CALLER_ATTACH Font::Builder* Subsetter::Subset() { - FontBuilderPtr font_builder; - font_builder.Attach(font_factory_->NewFontBuilder()); - - IntegerSet table_tags; - for (TableMap::iterator i = font_->Tables()->begin(), - e = font_->Tables()->end(); i != e; ++i) { - table_tags.insert(i->first); - } - if (!remove_tables_.empty()) { - IntegerSet result; - std::set_difference(table_tags.begin(), table_tags.end(), - remove_tables_.begin(), remove_tables_.end(), - std::inserter(result, result.end())); - table_tags = result; - } - for (TableSubsetterList::iterator - table_subsetter = table_subsetters_.begin(), - table_subsetter_end = table_subsetters_.end(); - table_subsetter != table_subsetter_end; ++table_subsetter) { - bool handled = (*table_subsetter)->Subset(this, font_, font_builder); - if (handled) { - IntegerSet* handled_tags = (*table_subsetter)->TagsHandled(); - IntegerSet result; - std::set_difference(table_tags.begin(), table_tags.end(), - handled_tags->begin(), handled_tags->end(), - std::inserter(result, result.end())); - table_tags = result; - } - } - for (IntegerSet::iterator tag = table_tags.begin(), - tag_end = table_tags.end(); tag != tag_end; ++tag) { - Table* table = font_->GetTable(*tag); - if (table) { - // The NewTableBuilder() call will alter internal state of font_builder - // AND the reference count of returned object. Therefore we need to - // dereference it. - TableBuilderPtr dereference; - dereference.Attach( - font_builder->NewTableBuilder(*tag, table->ReadFontData())); - } - } - return font_builder.Detach(); -} - -IntegerList* Subsetter::GlyphPermutationTable() { - return &new_to_old_glyphs_; -} - -CMapIdList* Subsetter::CMapId() { - return &cmap_ids_; -} - -} // namespace sfntly diff --git a/sfntly/tools/subsetter/glyph_table_subsetter.cc b/sfntly/tools/subsetter/glyph_table_subsetter.cc index 7609f74..76f8624 100644 --- a/sfntly/tools/subsetter/glyph_table_subsetter.cc +++ b/sfntly/tools/subsetter/glyph_table_subsetter.cc @@ -16,9 +16,9 @@ #include "sfntly/tools/subsetter/glyph_table_subsetter.h" +#include "sfntly/table/truetype/glyph_table.h" +#include "sfntly/table/truetype/loca_table.h" #include "sfntly/tag.h" -#include "sfntly/glyph_table.h" -#include "sfntly/loca_table.h" #include "sfntly/tools/subsetter/subsetter.h" #include "sfntly/port/exception_type.h" diff --git a/sfntly/tools/subsetter/glyph_table_subsetter.h b/sfntly/tools/subsetter/glyph_table_subsetter.h index 3687e27..88c7044 100644 --- a/sfntly/tools/subsetter/glyph_table_subsetter.h +++ b/sfntly/tools/subsetter/glyph_table_subsetter.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TOOLS_SUBSETTER_GLYPH_TABLE_SUBSETTER_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TOOLS_SUBSETTER_GLYPH_TABLE_SUBSETTER_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_GLYPH_TABLE_SUBSETTER_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_GLYPH_TABLE_SUBSETTER_H_ #include "sfntly/tools/subsetter/table_subsetter_impl.h" @@ -34,4 +34,4 @@ class GlyphTableSubsetter : public TableSubsetterImpl, } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TOOLS_SUBSETTER_GLYPH_TABLE_SUBSETTER_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_GLYPH_TABLE_SUBSETTER_H_ diff --git a/sfntly/tools/subsetter/subsetter.cc b/sfntly/tools/subsetter/subsetter.cc new file mode 100644 index 0000000..c234a1e --- /dev/null +++ b/sfntly/tools/subsetter/subsetter.cc @@ -0,0 +1,107 @@ +/* + * 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 "sfntly/tools/subsetter/subsetter.h" + +#include +#include + +#include "sfntly/tools/subsetter/glyph_table_subsetter.h" + +namespace sfntly { + +Subsetter::Subsetter(Font* font, FontFactory* font_factory) { + font_ = font; + font_factory_ = font_factory; + TableSubsetterPtr subsetter = new GlyphTableSubsetter(); + // TODO(arthurhsu): IMPLEMENT: CMap table subsetter + table_subsetters_.push_back(subsetter); +} + +Subsetter::~Subsetter() { + font_factory_.Release(); + font_.Release(); + table_subsetters_.clear(); +} + +void Subsetter::SetGlyphs(IntegerList* glyphs) { + new_to_old_glyphs_ = *glyphs; +} + +void Subsetter::SetCMaps(CMapIdList* cmap_ids, int32_t number) { + UNREFERENCED_PARAMETER(cmap_ids); + UNREFERENCED_PARAMETER(number); + // TODO(arthurhsu): IMPLEMENT +} + +void Subsetter::SetRemoveTables(IntegerSet* remove_tables) { + remove_tables_ = *remove_tables; +} + +CALLER_ATTACH Font::Builder* Subsetter::Subset() { + FontBuilderPtr font_builder; + font_builder.Attach(font_factory_->NewFontBuilder()); + + IntegerSet table_tags; + for (TableMap::iterator i = font_->Tables()->begin(), + e = font_->Tables()->end(); i != e; ++i) { + table_tags.insert(i->first); + } + if (!remove_tables_.empty()) { + IntegerSet result; + std::set_difference(table_tags.begin(), table_tags.end(), + remove_tables_.begin(), remove_tables_.end(), + std::inserter(result, result.end())); + table_tags = result; + } + for (TableSubsetterList::iterator + table_subsetter = table_subsetters_.begin(), + table_subsetter_end = table_subsetters_.end(); + table_subsetter != table_subsetter_end; ++table_subsetter) { + bool handled = (*table_subsetter)->Subset(this, font_, font_builder); + if (handled) { + IntegerSet* handled_tags = (*table_subsetter)->TagsHandled(); + IntegerSet result; + std::set_difference(table_tags.begin(), table_tags.end(), + handled_tags->begin(), handled_tags->end(), + std::inserter(result, result.end())); + table_tags = result; + } + } + for (IntegerSet::iterator tag = table_tags.begin(), + tag_end = table_tags.end(); tag != tag_end; ++tag) { + Table* table = font_->GetTable(*tag); + if (table) { + // The NewTableBuilder() call will alter internal state of font_builder + // AND the reference count of returned object. Therefore we need to + // dereference it. + TableBuilderPtr dereference; + dereference.Attach( + font_builder->NewTableBuilder(*tag, table->ReadFontData())); + } + } + return font_builder.Detach(); +} + +IntegerList* Subsetter::GlyphPermutationTable() { + return &new_to_old_glyphs_; +} + +CMapIdList* Subsetter::CMapId() { + return &cmap_ids_; +} + +} // namespace sfntly diff --git a/sfntly/tools/subsetter/subsetter.h b/sfntly/tools/subsetter/subsetter.h index df417ad..85940a7 100644 --- a/sfntly/tools/subsetter/subsetter.h +++ b/sfntly/tools/subsetter/subsetter.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TOOLS_SUBSETTER_SUBSETTER_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TOOLS_SUBSETTER_SUBSETTER_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_SUBSETTER_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_SUBSETTER_H_ #include #include "sfntly/font.h" #include "sfntly/font_factory.h" -#include "sfntly/cmap_table.h" +#include "sfntly/table/core/cmap_table.h" #include "sfntly/tools/subsetter/table_subsetter.h" namespace sfntly { @@ -69,4 +69,4 @@ class Subsetter : public RefCounted { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TOOLS_SUBSETTER_SUBSETTER_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_SUBSETTER_H_ diff --git a/sfntly/tools/subsetter/table_subsetter.h b/sfntly/tools/subsetter/table_subsetter.h index 437705c..1336615 100644 --- a/sfntly/tools/subsetter/table_subsetter.h +++ b/sfntly/tools/subsetter/table_subsetter.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TOOLS_SUBSETTER_TABLE_SUBSETTER_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TOOLS_SUBSETTER_TABLE_SUBSETTER_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_TABLE_SUBSETTER_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_TABLE_SUBSETTER_H_ #include @@ -36,4 +36,4 @@ typedef std::vector TableSubsetterList; } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TOOLS_SUBSETTER_TABLE_SUBSETTER_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_TABLE_SUBSETTER_H_ diff --git a/sfntly/tools/subsetter/table_subsetter_impl.h b/sfntly/tools/subsetter/table_subsetter_impl.h index 162464a..de0d9a9 100644 --- a/sfntly/tools/subsetter/table_subsetter_impl.h +++ b/sfntly/tools/subsetter/table_subsetter_impl.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TOOLS_SUBSETTER_TABLE_SUBSETTER_IMPL_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TOOLS_SUBSETTER_TABLE_SUBSETTER_IMPL_H_ +#ifndef SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_TABLE_SUBSETTER_IMPL_H_ +#define SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_TABLE_SUBSETTER_IMPL_H_ #include "sfntly/tools/subsetter/table_subsetter.h" @@ -34,4 +34,4 @@ class TableSubsetterImpl : public TableSubsetter { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_TOOLS_SUBSETTER_TABLE_SUBSETTER_IMPL_H_ +#endif // SFNTLY_CPP_SRC_SFNTLY_TOOLS_SUBSETTER_TABLE_SUBSETTER_IMPL_H_ diff --git a/test/font_data_test.cc b/test/font_data_test.cc index ecf9a62..4b0db64 100644 --- a/test/font_data_test.cc +++ b/test/font_data_test.cc @@ -46,35 +46,35 @@ const int32_t kSearchTestPairsLength = 15; const int32_t SEARCH_TEST_OFFSETS[][5] = { // lower[], upper[] { (kLowerByteArrayForSearchingLength + kUpperByteArrayForSearchingLength) - * sizeof(ushort), + * DataSize::kUSHORT, 0, - sizeof(ushort), - kLowerByteArrayForSearchingLength * sizeof(ushort), - sizeof(ushort) }, + DataSize::kUSHORT, + kLowerByteArrayForSearchingLength * DataSize::kUSHORT, + DataSize::kUSHORT }, // {lower, upper} [] { (kLowerByteArrayForSearchingLength + kUpperByteArrayForSearchingLength) - * sizeof(ushort), + * DataSize::kUSHORT, 0, - 2 * sizeof(ushort), - sizeof(ushort), - 2 * sizeof(ushort) }, + 2 * DataSize::kUSHORT, + DataSize::kUSHORT, + 2 * DataSize::kUSHORT }, // upper[], lower[] { (kLowerByteArrayForSearchingLength + kUpperByteArrayForSearchingLength) - * sizeof(ushort), - kLowerByteArrayForSearchingLength * sizeof(ushort), - sizeof(ushort), + * DataSize::kUSHORT, + kLowerByteArrayForSearchingLength * DataSize::kUSHORT, + DataSize::kUSHORT, 0, - sizeof(ushort) }, + DataSize::kUSHORT }, // {upper, lower} [] { (kLowerByteArrayForSearchingLength + kUpperByteArrayForSearchingLength) - * sizeof(ushort), - sizeof(ushort), - 2 * sizeof(ushort), + * DataSize::kUSHORT, + DataSize::kUSHORT, + 2 * DataSize::kUSHORT, 0, - 2 * sizeof(ushort) } + 2 * DataSize::kUSHORT } }; const int32_t kSearchTestOffsetLength = 4; diff --git a/test/font_parsing_test.cc b/test/font_parsing_test.cc index 3dcbda2..2e35c20 100644 --- a/test/font_parsing_test.cc +++ b/test/font_parsing_test.cc @@ -16,13 +16,13 @@ #include "gtest/gtest.h" +#include "sfntly/data/font_input_stream.h" +#include "sfntly/data/memory_byte_array.h" #include "sfntly/font.h" #include "sfntly/font_factory.h" -#include "sfntly/font_header_table.h" +#include "sfntly/table/core/font_header_table.h" +#include "sfntly/table/table.h" #include "sfntly/tag.h" -#include "sfntly/table.h" -#include "sfntly/data/font_input_stream.h" -#include "sfntly/data/memory_byte_array.h" #include "sfntly/port/file_input_stream.h" #include "test/test_data.h" #include "test/test_font_utils.h" diff --git a/test/font_subsetter.h b/test/font_subsetter.h index 6d001eb..07b1b5b 100644 --- a/test/font_subsetter.h +++ b/test/font_subsetter.h @@ -15,8 +15,8 @@ */ // File is originally from Chromium third_party/sfntly/src/subsetter. // Use as test case in sfntly so that problems can be caught in upstream early. -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_FONT_SUBSETTER_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_FONT_SUBSETTER_H_ +#ifndef SFNTLY_CPP_SRC_TEST_FONT_SUBSETTER_H_ +#define SFNTLY_CPP_SRC_TEST_FONT_SUBSETTER_H_ #include @@ -48,4 +48,4 @@ class SfntlyWrapper { unsigned char** output_buffer); }; -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_FONT_SUBSETTER_H_ +#endif // SFNTLY_CPP_SRC_TEST_FONT_SUBSETTER_H_ diff --git a/test/name_editing_test.cc b/test/name_editing_test.cc index 90076cf..ce12cd3 100644 --- a/test/name_editing_test.cc +++ b/test/name_editing_test.cc @@ -21,11 +21,11 @@ #include #include "gtest/gtest.h" +#include "sfntly/data/memory_byte_array.h" #include "sfntly/font.h" #include "sfntly/font_factory.h" -#include "sfntly/name_table.h" +#include "sfntly/table/core/name_table.h" #include "sfntly/tag.h" -#include "sfntly/data/memory_byte_array.h" #include "sfntly/port/memory_output_stream.h" #include "test/test_data.h" #include "test/test_font_utils.h" diff --git a/test/otf_basic_editing_test.cc b/test/otf_basic_editing_test.cc index 1db2d1e..32ba248 100644 --- a/test/otf_basic_editing_test.cc +++ b/test/otf_basic_editing_test.cc @@ -17,7 +17,7 @@ #include "gtest/gtest.h" #include "sfntly/font.h" #include "sfntly/font_factory.h" -#include "sfntly/font_header_table.h" +#include "sfntly/table/core/font_header_table.h" #include "sfntly/tag.h" #include "sfntly/data/memory_byte_array.h" #include "sfntly/port/endian.h" diff --git a/test/serialization_test.h b/test/serialization_test.h index 0718f32..8996793 100644 --- a/test/serialization_test.h +++ b/test/serialization_test.h @@ -14,10 +14,10 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_SERIALIZATION_TEST_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_SERIALIZATION_TEST_H_ +#ifndef SFNTLY_CPP_SRC_TEST_SERIALIZATION_TEST_H_ +#define SFNTLY_CPP_SRC_TEST_SERIALIZATION_TEST_H_ -#include "sfntly/table.h" +#include "sfntly/table/table.h" namespace sfntly { @@ -31,4 +31,4 @@ bool VerifyOS_2(Table* original, Table* target); } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_SERIALIZATION_TEST_H_ +#endif // SFNTLY_CPP_SRC_TEST_SERIALIZATION_TEST_H_ diff --git a/test/subsetter_impl.cc b/test/subsetter_impl.cc index 7999f50..ea886c0 100644 --- a/test/subsetter_impl.cc +++ b/test/subsetter_impl.cc @@ -23,9 +23,9 @@ #include #include -#include "sfntly/glyph_table.h" -#include "sfntly/loca_table.h" -#include "sfntly/name_table.h" +#include "sfntly/table/core/name_table.h" +#include "sfntly/table/truetype/glyph_table.h" +#include "sfntly/table/truetype/loca_table.h" #include "sfntly/tag.h" #include "sfntly/data/memory_byte_array.h" #include "sfntly/port/memory_output_stream.h" diff --git a/test/subsetter_impl.h b/test/subsetter_impl.h index 6ce0aee..f3a8bf3 100644 --- a/test/subsetter_impl.h +++ b/test/subsetter_impl.h @@ -16,8 +16,8 @@ // File is originally from Chromium third_party/sfntly/src/subsetter. // Use as test case in sfntly so that problems can be caught in upstream early. -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_SUBSETTER_IMPL_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_SUBSETTER_IMPL_H_ +#ifndef SFNTLY_CPP_SRC_TEST_SUBSETTER_IMPL_H_ +#define SFNTLY_CPP_SRC_TEST_SUBSETTER_IMPL_H_ #include "sfntly/font.h" #include "sfntly/font_factory.h" @@ -72,4 +72,4 @@ class SubsetterImpl { } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_SUBSETTER_IMPL_H_ +#endif // SFNTLY_CPP_SRC_TEST_SUBSETTER_IMPL_H_ diff --git a/test/test_data.h b/test/test_data.h index b6aa4ea..1b50549 100644 --- a/test/test_data.h +++ b/test/test_data.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_TEST_DATA_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_TEST_DATA_H_ +#ifndef SFNTLY_CPP_SRC_TEST_TEST_DATA_H_ +#define SFNTLY_CPP_SRC_TEST_TEST_DATA_H_ #include "sfntly/tag.h" @@ -42,4 +42,4 @@ extern const size_t SAMPLE_OTF_SIZE; } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_TEST_DATA_H_ +#endif // SFNTLY_CPP_SRC_TEST_TEST_DATA_H_ diff --git a/test/test_font_utils.h b/test/test_font_utils.h index 21296f1..b8a93b9 100644 --- a/test/test_font_utils.h +++ b/test/test_font_utils.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_TEST_FONT_UTILS_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_TEST_FONT_UTILS_H_ +#ifndef SFNTLY_CPP_SRC_TEST_TEST_FONT_UTILS_H_ +#define SFNTLY_CPP_SRC_TEST_TEST_FONT_UTILS_H_ #include "sfntly/font.h" #include "sfntly/font_factory.h" @@ -38,4 +38,4 @@ void HexDump(const unsigned char* byte_data, size_t length); } // namespace sfntly -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_TEST_FONT_UTILS_H_ +#endif // SFNTLY_CPP_SRC_TEST_TEST_FONT_UTILS_H_ diff --git a/test/test_utils.h b/test/test_utils.h index 4d692e1..af3ffd6 100644 --- a/test/test_utils.h +++ b/test/test_utils.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_TEST_UTILS_H_ -#define TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_TEST_UTILS_H_ +#ifndef SFNTLY_CPP_SRC_TEST_TEST_UTILS_H_ +#define SFNTLY_CPP_SRC_TEST_TEST_UTILS_H_ // Must include this before ICU to avoid stdint redefinition issue. #include "sfntly/port/type.h" @@ -107,4 +107,4 @@ class TestUtils { static const char* Extension(const char* file_path); }; } -#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_TEST_TEST_UTILS_H_ +#endif // SFNTLY_CPP_SRC_TEST_TEST_UTILS_H_ diff --git a/test/verify_glyf.cc b/test/verify_glyf.cc index f13f5ce..ff89638 100644 --- a/test/verify_glyf.cc +++ b/test/verify_glyf.cc @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "sfntly/font.h" -#include "sfntly/glyph_table.h" +#include "sfntly/table/truetype/glyph_table.h" #include "test/serialization_test.h" namespace sfntly { diff --git a/test/verify_hhea.cc b/test/verify_hhea.cc index 537b224..491238a 100644 --- a/test/verify_hhea.cc +++ b/test/verify_hhea.cc @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "sfntly/font.h" -#include "sfntly/horizontal_header_table.h" +#include "sfntly/table/core/horizontal_header_table.h" #include "test/serialization_test.h" namespace sfntly { diff --git a/test/verify_hmtx.cc b/test/verify_hmtx.cc index 000597a..67ea6a3 100644 --- a/test/verify_hmtx.cc +++ b/test/verify_hmtx.cc @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "sfntly/font.h" -#include "sfntly/horizontal_metrics_table.h" +#include "sfntly/table/core/horizontal_metrics_table.h" #include "test/serialization_test.h" namespace sfntly { diff --git a/test/verify_loca.cc b/test/verify_loca.cc index a1f14c2..0e36ce8 100644 --- a/test/verify_loca.cc +++ b/test/verify_loca.cc @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "sfntly/font.h" -#include "sfntly/loca_table.h" +#include "sfntly/table/truetype/loca_table.h" #include "test/serialization_test.h" namespace sfntly { diff --git a/test/verify_maxp.cc b/test/verify_maxp.cc index d789fdb..3bd4490 100644 --- a/test/verify_maxp.cc +++ b/test/verify_maxp.cc @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "sfntly/font.h" -#include "sfntly/maximum_profile_table.h" +#include "sfntly/table/core/maximum_profile_table.h" #include "test/serialization_test.h" namespace sfntly { diff --git a/test/verify_name.cc b/test/verify_name.cc index d55d924..fa56de5 100644 --- a/test/verify_name.cc +++ b/test/verify_name.cc @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "sfntly/font.h" -#include "sfntly/name_table.h" +#include "sfntly/table/core/name_table.h" #include "test/serialization_test.h" namespace sfntly { diff --git a/test/verify_os2.cc b/test/verify_os2.cc index e604be9..8f6b9ed 100644 --- a/test/verify_os2.cc +++ b/test/verify_os2.cc @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "sfntly/font.h" -#include "sfntly/os2_table.h" +#include "sfntly/table/core/os2_table.h" #include "test/serialization_test.h" namespace sfntly { -- cgit v1.2.3