Home | History | Annotate | Download | only in test
      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/os2_table.h"
     20 #include "test/serialization_test.h"
     21 
     22 namespace sfntly {
     23 
     24 const int32_t OS2_VERSION = 1;
     25 const int32_t OS2_XAVG_CHAR_WIDTH = 863;
     26 const int32_t OS2_US_WEIGHT_CLASS = 500;
     27 const int32_t OS2_US_WIDTH_CLASS = 5;
     28 const int32_t OS2_FS_TYPE = 0;
     29 const int32_t OS2_YSUBS_XSIZE = 0;
     30 const int32_t OS2_YSUBS_YSIZE = 2;
     31 const int32_t OS2_YSUBS_XOFFSET = -16560;
     32 const int32_t OS2_YSUBS_YOFFSET = 0;
     33 const int32_t OS2_YSUPS_XSIZE = -25944;
     34 const int32_t OS2_YSUPS_YSIZE = -27176;
     35 const int32_t OS2_YSUPS_XOFFSET = -16376;
     36 const int32_t OS2_YSUPS_YOFFSET = 1;
     37 const int32_t OS2_YSTRIKEOUT_SIZE = 12312;
     38 const int32_t OS2_YSTRIKEOUT_POS = -16224;
     39 const int32_t OS2_SFAMILY_CLASS = 0;
     40 const byte_t OS2_PANOSE[] = { 2, 11, 6, 3, 6, 1, 0, 0, 0, 0 };
     41 const int64_t OS2_UL_UNICODE_RANGE1 = 0xE00002FFL;
     42 const int64_t OS2_UL_UNICODE_RANGE2 = 0x520020FBL;
     43 const int64_t OS2_UL_UNICODE_RANGE3 = 0L;
     44 const int64_t OS2_UL_UNICODE_RANGE4 = 0L;
     45 const byte_t OS2_ACH_VEND_ID[] = { 'P', 'f', 'E', 'd' };
     46 const int32_t OS2_FS_SELECTION = 0x0040;
     47 const int32_t OS2_US_FIRST_CHAR_IDX = 0x0020;
     48 const int32_t OS2_US_LAST_CHAR_IDX = 0xFFFF;
     49 const int32_t OS2_STYPO_ASCENDER = 1597;
     50 const int32_t OS2_STYPO_DESCENDER = -451;
     51 const int32_t OS2_STYPO_LINE_GAP = 0;
     52 const int32_t OS2_US_WIN_ASCENT = 2023;
     53 const int32_t OS2_US_WIN_DESCENT = 648;
     54 const int64_t OS2_UL_CODE_PAGE_RANGE1 = 0x2000019FL;
     55 const int64_t OS2_UL_CODE_PAGE_RANGE2 = 0x00000000L;
     56 
     57 static bool VerifyOS_2(Table* table) {
     58   OS2TablePtr os2 = down_cast<OS2Table*>(table);
     59   if (os2 == NULL) {
     60     return false;
     61   }
     62 
     63   EXPECT_EQ(os2->TableVersion(), OS2_VERSION);
     64   EXPECT_EQ(os2->XAvgCharWidth(), OS2_XAVG_CHAR_WIDTH);
     65   EXPECT_EQ(os2->UsWeightClass(), OS2_US_WEIGHT_CLASS);
     66   EXPECT_EQ(os2->UsWidthClass(), OS2_US_WIDTH_CLASS);
     67   EXPECT_EQ(os2->FsType(), OS2_FS_TYPE);
     68   EXPECT_EQ(os2->YSubscriptXSize(), OS2_YSUBS_XSIZE);
     69   EXPECT_EQ(os2->YSubscriptYSize(), OS2_YSUBS_YSIZE);
     70   EXPECT_EQ(os2->YSubscriptXOffset(), OS2_YSUBS_XOFFSET);
     71   EXPECT_EQ(os2->YSubscriptYOffset(), OS2_YSUBS_YOFFSET);
     72   EXPECT_EQ(os2->YSuperscriptXSize(), OS2_YSUPS_XSIZE);
     73   EXPECT_EQ(os2->YSuperscriptYSize(), OS2_YSUPS_YSIZE);
     74   EXPECT_EQ(os2->YSuperscriptXOffset(), OS2_YSUPS_XOFFSET);
     75   EXPECT_EQ(os2->YSuperscriptYOffset(), OS2_YSUPS_YOFFSET);
     76   EXPECT_EQ(os2->YStrikeoutSize(), OS2_YSTRIKEOUT_SIZE);
     77   EXPECT_EQ(os2->YStrikeoutPosition(), OS2_YSTRIKEOUT_POS);
     78   EXPECT_EQ(os2->SFamilyClass(), OS2_SFAMILY_CLASS);
     79 
     80   ByteVector panose;
     81   os2->Panose(&panose);
     82   EXPECT_EQ(panose.size(), sizeof(OS2_PANOSE));
     83   for (size_t i = 0; i < panose.size(); ++i) {
     84     EXPECT_EQ(panose[i], OS2_PANOSE[i]);
     85   }
     86 
     87   EXPECT_EQ(os2->UlUnicodeRange1(), OS2_UL_UNICODE_RANGE1);
     88   EXPECT_EQ(os2->UlUnicodeRange2(), OS2_UL_UNICODE_RANGE2);
     89   EXPECT_EQ(os2->UlUnicodeRange3(), OS2_UL_UNICODE_RANGE3);
     90   EXPECT_EQ(os2->UlUnicodeRange4(), OS2_UL_UNICODE_RANGE4);
     91 
     92   ByteVector vend_id;
     93   os2->AchVendId(&vend_id);
     94   EXPECT_EQ(vend_id.size(), sizeof(OS2_ACH_VEND_ID));
     95   for (size_t i = 0; i < vend_id.size(); ++i) {
     96     EXPECT_EQ(vend_id[i], OS2_ACH_VEND_ID[i]);
     97   }
     98 
     99   EXPECT_EQ(os2->FsSelection(), OS2_FS_SELECTION);
    100   EXPECT_EQ(os2->UsFirstCharIndex(), OS2_US_FIRST_CHAR_IDX);
    101   EXPECT_EQ(os2->UsLastCharIndex(), OS2_US_LAST_CHAR_IDX);
    102   EXPECT_EQ(os2->STypoAscender(), OS2_STYPO_ASCENDER);
    103   EXPECT_EQ(os2->STypoDescender(), OS2_STYPO_DESCENDER);
    104   EXPECT_EQ(os2->STypoLineGap(), OS2_STYPO_LINE_GAP);
    105   EXPECT_EQ(os2->UsWinAscent(), OS2_US_WIN_ASCENT);
    106   EXPECT_EQ(os2->UsWinDescent(), OS2_US_WIN_DESCENT);
    107   EXPECT_EQ(os2->UlCodePageRange1(), OS2_UL_CODE_PAGE_RANGE1);
    108   EXPECT_EQ(os2->UlCodePageRange2(), OS2_UL_CODE_PAGE_RANGE2);
    109 
    110   // TODO(arthurhsu): SxHeight() not tested
    111   // TODO(arthurhsu): SCapHeight() not tested
    112   // TODO(arthurhsu): UsDefaultChar() not tested
    113   // TODO(arthurhsu): UsBreakChar() not tested
    114   // TODO(arthurhsu): UsMaxContext() not tested
    115 
    116   return true;
    117 }
    118 
    119 bool VerifyOS_2(Table* original, Table* target) {
    120   EXPECT_TRUE(VerifyOS_2(original));
    121   EXPECT_TRUE(VerifyOS_2(target));
    122   return true;
    123 }
    124 
    125 }  // namespace sfntly
    126