• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.google.typography.font.sfntly;
18 
19 import com.google.typography.font.sfntly.table.core.OS2Table;
20 import com.google.typography.font.sfntly.table.core.OS2Table.CodePageRange;
21 import com.google.typography.font.sfntly.table.core.OS2Table.UnicodeRange;
22 import com.google.typography.font.sfntly.testutils.TestFont;
23 import com.google.typography.font.sfntly.testutils.TestFontUtils;
24 import com.google.typography.font.sfntly.testutils.TestUtils;
25 
26 import junit.framework.TestCase;
27 
28 import java.io.File;
29 import java.util.EnumSet;
30 
31 
32 /**
33  * @author Stuart Gill
34  *
35  */
36 public class OS2Tests extends TestCase {
37 
38   private static final File TEST_FONT_FILE = TestFont.TestFontNames.OPENSANS.getFile();
39 
OS2Tests()40   public OS2Tests() {
41   }
42 
OS2Tests(String name)43   public OS2Tests(String name) {
44     super(name);
45   }
46 
47   private static final byte[] achVendId_a = {'a'};
48   private static final byte[] achVendId_a_pad = {'a', ' ', ' ', ' '};
49   private static final byte[] achVendId_abcd = {'a', 'b', 'c', 'd'};
50 
testAchVendId()51   public void testAchVendId() throws Exception {
52     Font.Builder fontBuilder = TestFontUtils.builderForFontFile(TEST_FONT_FILE);
53     OS2Table.Builder os2TableBuilder = (OS2Table.Builder) fontBuilder.getTableBuilder(Tag.OS_2);
54 
55     os2TableBuilder.setAchVendId(achVendId_a);
56     assertTrue(TestUtils.equals(
57         achVendId_a_pad, 0, os2TableBuilder.achVendId(), 0, achVendId_a_pad.length));
58 
59     os2TableBuilder.setAchVendId(achVendId_abcd);
60     assertTrue(
61         TestUtils.equals(achVendId_abcd, 0, os2TableBuilder.achVendId(), 0, achVendId_abcd.length));
62 
63     os2TableBuilder.setAchVendId(achVendId_a);
64     assertTrue(TestUtils.equals(
65         achVendId_a_pad, 0, os2TableBuilder.achVendId(), 0, achVendId_a_pad.length));
66   }
67 
testUnicodeRange()68   public void testUnicodeRange() throws Exception {
69     EnumSet<UnicodeRange> urSet = makeUnicodeRangeSet(false);
70     long[] urArray = UnicodeRange.asArray(urSet);
71     EnumSet<UnicodeRange> urSetCopy =
72         UnicodeRange.asSet(urArray[0], urArray[1], urArray[2], urArray[3]);
73     assertEquals(urSet, urSetCopy);
74   }
75 
testCodePageRange()76   public void testCodePageRange() throws Exception {
77     EnumSet<CodePageRange> urSet = makeCodePageRangeSet(false);
78     long[] cprArray = CodePageRange.asArray(urSet);
79     EnumSet<CodePageRange> urSetCopy = CodePageRange.asSet(cprArray[0], cprArray[1]);
80     assertEquals(urSet, urSetCopy);
81   }
82 
makeUnicodeRangeSet(boolean odd)83   private static EnumSet<UnicodeRange> makeUnicodeRangeSet(boolean odd) {
84     EnumSet<UnicodeRange> rSet = EnumSet.noneOf(UnicodeRange.class);
85 
86     for (UnicodeRange r : UnicodeRange.values()) {
87       if (odd) {
88         rSet.add(r);
89       }
90       odd = odd ? false : true;
91     }
92     return rSet;
93   }
94 
makeCodePageRangeSet(boolean odd)95   private static EnumSet<CodePageRange> makeCodePageRangeSet(boolean odd) {
96     EnumSet<CodePageRange> rSet = EnumSet.noneOf(CodePageRange.class);
97 
98     for (CodePageRange r : CodePageRange.values()) {
99       if (odd) {
100         rSet.add(r);
101       }
102       odd = odd ? false : true;
103     }
104     return rSet;
105   }
106 
107 }
108