1 /*
2  *******************************************************************************
3  * Copyright (C) 1998-2004, International Business Machines Corporation and    *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  *
7  * Created on Dec 3, 2003
8  *
9  *******************************************************************************
10  */
11 package com.ibm.icu.dev.tool.layout;
12 
13 
14 public class FeatureList
15 {
16 
17     private Feature[] features;
18     private int featureCount;
19 
FeatureList()20     public FeatureList()
21     {
22         features = new Feature[10];
23         featureCount = 0;
24     }
25 
addFeature(Feature feature)26     public void addFeature(Feature feature)
27     {
28         if (featureCount >= features.length) {
29             Feature[] newFeatures = new Feature[features.length + 5];
30 
31             System.arraycopy(features, 0, newFeatures, 0, features.length);
32             features = newFeatures;
33         }
34 
35         features[featureCount++] = feature;
36     }
37 
finalizeFeatureList()38     public void finalizeFeatureList()
39     {
40         TaggedRecord.sort(features, featureCount);
41 
42         for (int i = 0; i < featureCount; i += 1) {
43             features[i].setFeatureIndex(i);
44         }
45     }
46 
writeFeaturetList(OpenTypeTableWriter writer)47     public void writeFeaturetList(OpenTypeTableWriter writer)
48     {
49         System.out.print("writing feature list...");
50 
51         int featureListBase = writer.getOutputIndex();
52 
53         writer.writeData(featureCount);
54 
55         int featureRecordOffset = writer.getOutputIndex();
56 
57         for (int i = 0; i < featureCount; i += 1) {
58             String tag = features[i].getTag();
59 
60             System.out.print(" '" + tag + "'");
61             writer.writeTag(tag);
62             writer.writeData(0);
63         }
64 
65         for (int i = 0; i < featureCount; i += 1) {
66             // fix the offset in the featureRecordArray.
67             // The "+2" skips over the tag and the "+3"
68             // skips to the next featureRecord entry
69             writer.fixOffset(featureRecordOffset + 2, featureListBase);
70             featureRecordOffset += 3;
71 
72             features[i].writeFeature(writer);
73         }
74 
75         System.out.println();
76     }
77 }