1 /* 2 * Copyright 2011 Google Inc. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "gtest/gtest.h" 18 #include "sfntly/font.h" 19 #include "sfntly/table/core/horizontal_device_metrics_table.h" 20 #include "test/test_data.h" 21 #include "test/test_font_utils.h" 22 23 namespace sfntly { 24 25 const int32_t HDMX_VERSION = 0; 26 const int32_t HDMX_NUM_RECORDS = 4; 27 const int32_t HDMX_RECORD_SIZE = 628; 28 const int32_t HDMX_PIXEL_SIZE[] = {10, 11, 12, 13}; 29 const int32_t HDMX_MAX_WIDTH[] = {5, 6, 7, 7}; 30 31 bool TestReadingHdmxTable() { 32 FontFactoryPtr factory; 33 factory.Attach(FontFactory::GetInstance()); 34 FontArray font_array; 35 LoadFont(SAMPLE_BITMAP_FONT, factory, &font_array); 36 FontPtr font = font_array[0]; 37 38 HorizontalDeviceMetricsTablePtr hdmx_table = 39 down_cast<HorizontalDeviceMetricsTable*>(font->GetTable(Tag::hdmx)); 40 41 EXPECT_FALSE(hdmx_table == NULL); 42 43 EXPECT_EQ(hdmx_table->Version(), HDMX_VERSION); 44 EXPECT_EQ(hdmx_table->NumRecords(), HDMX_NUM_RECORDS); 45 EXPECT_EQ(hdmx_table->RecordSize(), HDMX_RECORD_SIZE); 46 47 for (int32_t i = 0; i < HDMX_NUM_RECORDS; ++i) { 48 EXPECT_EQ(hdmx_table->PixelSize(i), HDMX_PIXEL_SIZE[i]); 49 EXPECT_EQ(hdmx_table->MaxWidth(i), HDMX_MAX_WIDTH[i]); 50 } 51 52 EXPECT_EQ(hdmx_table->Width(0, 0), HDMX_MAX_WIDTH[0]); 53 EXPECT_EQ(hdmx_table->Width(0, 19), HDMX_MAX_WIDTH[0]); 54 EXPECT_EQ(hdmx_table->Width(0, 623), HDMX_MAX_WIDTH[0]); 55 EXPECT_EQ(hdmx_table->Width(1, 0), HDMX_MAX_WIDTH[1]); 56 EXPECT_EQ(hdmx_table->Width(1, 19), HDMX_MAX_WIDTH[1]); 57 EXPECT_EQ(hdmx_table->Width(1, 623), HDMX_MAX_WIDTH[1]); 58 EXPECT_EQ(hdmx_table->Width(2, 0), HDMX_MAX_WIDTH[2]); 59 EXPECT_EQ(hdmx_table->Width(2, 19), HDMX_MAX_WIDTH[2]); 60 EXPECT_EQ(hdmx_table->Width(2, 623), HDMX_MAX_WIDTH[2]); 61 EXPECT_EQ(hdmx_table->Width(3, 0), HDMX_MAX_WIDTH[3]); 62 EXPECT_EQ(hdmx_table->Width(3, 19), HDMX_MAX_WIDTH[3]); 63 EXPECT_EQ(hdmx_table->Width(3, 623), HDMX_MAX_WIDTH[3]); 64 65 #if defined(SFNTLY_NO_EXCEPTION) 66 EXPECT_EQ(hdmx_table->PixelSize(4), -1); 67 EXPECT_EQ(hdmx_table->PixelSize(-1), -1); 68 EXPECT_EQ(hdmx_table->MaxWidth(4), -1); 69 EXPECT_EQ(hdmx_table->MaxWidth(-1), -1); 70 EXPECT_EQ(hdmx_table->Width(0, 624), -1); 71 EXPECT_EQ(hdmx_table->Width(1, -1), -1); 72 EXPECT_EQ(hdmx_table->Width(-1, 0), -1); 73 EXPECT_EQ(hdmx_table->Width(-1, -1), -1); 74 #endif 75 return true; 76 } 77 78 } // namespace sfntly 79 80 TEST(HdmxTable, All) { 81 ASSERT_TRUE(sfntly::TestReadingHdmxTable()); 82 } 83