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/truetype/loca_table.h"
20 #include "test/serialization_test.h"
21
22 namespace sfntly {
23
24 const int32_t LOCA_NUM_LOCAS = 1503;
25 const int32_t LOCAS[] = {
26 0x00000, // 0
27 0x00058, // 1
28 0x00058, // 2
29 0x00058, // 3
30 0x00058, // 4
31 0x000B8, // 5
32 0x00138, // 6
33 0x001A4, // 7
34 0x0025C, // 8
35 0x00328, // 9
36 0x003B8, // 10
37 };
38 const int32_t NUM_TEST_LOCAS = 11;
39
VerifyLOCA(Table * table)40 static bool VerifyLOCA(Table* table) {
41 LocaTablePtr loca = down_cast<LocaTable*>(table);
42 if (loca == NULL) {
43 return false;
44 }
45
46 EXPECT_EQ(loca->NumLocas(), LOCA_NUM_LOCAS);
47 EXPECT_EQ(loca->num_glyphs(), LOCA_NUM_LOCAS - 1);
48
49 for (int32_t i = 0; i < NUM_TEST_LOCAS - 1; ++i) {
50 EXPECT_EQ(loca->GlyphOffset(i), LOCAS[i]);
51 EXPECT_EQ(loca->GlyphLength(i), LOCAS[i + 1] - LOCAS[i]);
52 }
53 return true;
54 }
55
VerifyLOCA(Table * original,Table * target)56 bool VerifyLOCA(Table* original, Table* target) {
57 EXPECT_TRUE(VerifyLOCA(original));
58 EXPECT_TRUE(VerifyLOCA(target));
59 return true;
60 }
61
62 } // namespace sfntly
63