1 /* 2 * Copyright 2010 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 java.io.UnsupportedEncodingException; 20 21 22 /** 23 * Font identification tags used for tables, features, etc. 24 * 25 * Tag names are consistent with the OpenType and sfnt specs. 26 * 27 * @author Stuart Gill 28 */ 29 public final class Tag { 30 public static final int ttcf = Tag.intValue(new byte[]{'t', 't', 'c', 'f'}); 31 32 /*********************************************************************************** 33 * 34 * Table Type Tags 35 * 36 ***********************************************************************************/ 37 38 // required tables 39 public static final int cmap = Tag.intValue(new byte[]{'c', 'm', 'a', 'p'}); 40 public static final int head = Tag.intValue(new byte[]{'h', 'e', 'a', 'd'}); 41 public static final int hhea = Tag.intValue(new byte[]{'h', 'h', 'e', 'a'}); 42 public static final int hmtx = Tag.intValue(new byte[]{'h', 'm', 't', 'x'}); 43 public static final int maxp = Tag.intValue(new byte[]{'m', 'a', 'x', 'p'}); 44 public static final int name = Tag.intValue(new byte[]{'n', 'a', 'm', 'e'}); 45 public static final int OS_2 = Tag.intValue(new byte[]{'O', 'S', '/', '2'}); 46 public static final int post = Tag.intValue(new byte[]{'p', 'o', 's', 't'}); 47 48 // truetype outline tables 49 public static final int cvt = Tag.intValue(new byte[]{'c', 'v', 't', ' '}); 50 public static final int fpgm = Tag.intValue(new byte[]{'f', 'p', 'g', 'm'}); 51 public static final int glyf = Tag.intValue(new byte[]{'g', 'l', 'y', 'f'}); 52 public static final int loca = Tag.intValue(new byte[]{'l', 'o', 'c', 'a'}); 53 public static final int prep = Tag.intValue(new byte[]{'p', 'r', 'e', 'p'}); 54 55 // postscript outline tables 56 public static final int CFF = Tag.intValue(new byte[]{'C', 'F', 'F', ' '}); 57 public static final int VORG = Tag.intValue(new byte[]{'V', 'O', 'R', 'G'}); 58 59 // opentype bitmap glyph outlines 60 public static final int EBDT = Tag.intValue(new byte[]{'E', 'B', 'D', 'T'}); 61 public static final int EBLC = Tag.intValue(new byte[]{'E', 'B', 'L', 'C'}); 62 public static final int EBSC = Tag.intValue(new byte[]{'E', 'B', 'S', 'C'}); 63 64 // advanced typographic features 65 public static final int BASE = Tag.intValue(new byte[]{'B', 'A', 'S', 'E'}); 66 public static final int GDEF = Tag.intValue(new byte[]{'G', 'D', 'E', 'F'}); 67 public static final int GPOS = Tag.intValue(new byte[]{'G', 'P', 'O', 'S'}); 68 public static final int GSUB = Tag.intValue(new byte[]{'G', 'S', 'U', 'B'}); 69 public static final int JSTF = Tag.intValue(new byte[]{'J', 'S', 'T', 'F'}); 70 71 // other 72 public static final int DSIG = Tag.intValue(new byte[]{'D', 'S', 'I', 'G'}); 73 public static final int gasp = Tag.intValue(new byte[]{'g', 'a', 's', 'p'}); 74 public static final int hdmx = Tag.intValue(new byte[]{'h', 'd', 'm', 'x'}); 75 public static final int kern = Tag.intValue(new byte[]{'k', 'e', 'r', 'n'}); 76 public static final int LTSH = Tag.intValue(new byte[]{'L', 'T', 'S', 'H'}); 77 public static final int PCLT = Tag.intValue(new byte[]{'P', 'C', 'L', 'T'}); 78 public static final int VDMX = Tag.intValue(new byte[]{'V', 'D', 'M', 'X'}); 79 public static final int vhea = Tag.intValue(new byte[]{'v', 'h', 'e', 'a'}); 80 public static final int vmtx = Tag.intValue(new byte[]{'v', 'm', 't', 'x'}); 81 82 // AAT Tables 83 // TODO(stuartg): some tables may be missing from this list 84 public static final int bsln = Tag.intValue(new byte[]{'b', 's', 'l', 'n'}); 85 public static final int feat = Tag.intValue(new byte[]{'f', 'e', 'a', 't'}); 86 public static final int lcar = Tag.intValue(new byte[]{'l', 'c', 'a', 'r'}); 87 public static final int morx = Tag.intValue(new byte[]{'m', 'o', 'r', 'x'}); 88 public static final int opbd = Tag.intValue(new byte[]{'o', 'p', 'b', 'd'}); 89 public static final int prop = Tag.intValue(new byte[]{'p', 'r', 'o', 'p'}); 90 91 // Graphite tables 92 public static final int Feat = Tag.intValue(new byte[]{'F', 'e', 'a', 't'}); 93 public static final int Glat = Tag.intValue(new byte[]{'G', 'l', 'a', 't'}); 94 public static final int Gloc = Tag.intValue(new byte[]{'G', 'l', 'o', 'c'}); 95 public static final int Sile = Tag.intValue(new byte[]{'S', 'i', 'l', 'e'}); 96 public static final int Silf = Tag.intValue(new byte[]{'S', 'i', 'l', 'f'}); 97 98 // truetype bitmap font tables 99 public static final int bhed = Tag.intValue(new byte[]{'b', 'h', 'e', 'd'}); 100 public static final int bdat = Tag.intValue(new byte[]{'b', 'd', 'a', 't'}); 101 public static final int bloc = Tag.intValue(new byte[]{'b', 'l', 'o', 'c'}); 102 Tag()103 private Tag() { 104 // Prevent construction. 105 } 106 intValue(byte[] tag)107 public static int intValue(byte[] tag) { 108 return tag[0] << 24 | tag[1] << 16 | tag[2] << 8 | tag[3]; 109 } 110 byteValue(int tag)111 public static byte[] byteValue(int tag) { 112 byte[] b = new byte[4]; 113 b[0] = (byte) (0xff & (tag >> 24)); 114 b[1] = (byte) (0xff & (tag >> 16)); 115 b[2] = (byte) (0xff & (tag >> 8)); 116 b[3] = (byte) (0xff & tag); 117 return b; 118 } 119 stringValue(int tag)120 public static String stringValue(int tag) { 121 String s; 122 try { 123 s = new String(Tag.byteValue(tag), "US-ASCII"); 124 } catch (UnsupportedEncodingException e) { 125 // should never happen since US-ASCII is a guaranteed character set but... 126 return ""; 127 } 128 return s; 129 } 130 intValue(String s)131 public static int intValue(String s) { 132 byte[] b = null; 133 try { 134 b = s.substring(0, 4).getBytes("US-ASCII"); 135 } catch (UnsupportedEncodingException e) { 136 // should never happen since US-ASCII is a guaranteed character set but... 137 return 0; 138 } 139 return intValue(b); 140 } 141 142 /** 143 * Determines whether the tag is that for the header table. 144 * @param tag table tag 145 * @return true if the tag represents the font header table 146 */ isHeaderTable(int tag)147 public static boolean isHeaderTable(int tag) { 148 if (tag == Tag.head || tag == Tag.bhed) { 149 return true; 150 } 151 return false; 152 } 153 } 154