/*
 * Copyright (C) 2018 AlexMofer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package am.util.opentype.tables;

import java.io.IOException;

import am.util.opentype.OpenTypeReader;
import am.util.opentype.TableRecord;

/**
 * Index to Location Table
 * The indexToLoc table stores the offsets to the locations of the glyphs in the font,
 * relative to the beginning of the glyphData table. In order to compute the length of
 * the last glyph element, there is an extra entry after the last valid index.
 */
@SuppressWarnings("unused")
public class IndexToLocationTable extends BaseTable {

    private final int[] mOffsets;

    public IndexToLocationTable(OpenTypeReader reader, TableRecord record, int indexToLocFormat,
                                int numGlyphs) throws IOException {
        super(record);
        if (reader == null || record == null || record.getTableTag() != TableRecord.TAG_LOCA)
            throw new IOException();
        reader.seek(record.getOffset());
        final int size = numGlyphs + 1;
        final int[] offsets = new int[size];
        if (indexToLocFormat == 0) {
            // Short version
            for (int i = 0; i < size; i++) {
                offsets[i] = reader.readUnsignedShort();
            }
        } else {
            // Long version
            for (int i = 0; i < size; i++) {
                offsets[i] = reader.readUnsignedInt();
            }
        }
        mOffsets = offsets;
    }

    /**
     * The actual local offset
     *
     * @return The actual local offset.
     */
    public int[] getOffsets() {
        return mOffsets;
    }
}

@@ -652,16 +652,41 @@
 ception;
+%0Aimport java.util.Arrays;
 %0A%0Aimport
@@ -2150,11 +2150,736 @@
 s;%0A    %7D
+%0A%0A    @Override%0A    public boolean equals(Object o) %7B%0A        if (this == o) return true;%0A        if (!(o instanceof IndexToLocationTable)) return false;%0A        if (!super.equals(o)) return false;%0A        IndexToLocationTable that = (IndexToLocationTable) o;%0A        return Arrays.equals(mOffsets, that.mOffsets);%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        int result = super.hashCode();%0A        result = 31 * result + Arrays.hashCode(mOffsets);%0A        return result;%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return %22IndexToLocationTable%7B%22 +%0A                %22record=%22 + String.valueOf(getTableRecord()) +%0A                %22, offsets=%22 + Arrays.toString(mOffsets) +%0A                '%7D';%0A    %7D
 %0A%7D%0A

完成LOCA表对象equals、hashCOde及toString方法