All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpedal.fonts.tt.Glyf Maven / Gradle / Ivy

There is a newer version: 7.15.25
Show newest version
/*
 * ===========================================
 * Java Pdf Extraction Decoding Access Library
 * ===========================================
 *
 * Project Info:  http://www.idrsolutions.com
 * Help section for developers at http://www.idrsolutions.com/support/
 *
 * (C) Copyright 1997-2017 IDRsolutions and Contributors.
 *
 * This file is part of JPedal/JPDF2HTML5
 *
 @LICENSE@
 *
 * ---------------
 * Glyf.java
 * ---------------
 */
package org.jpedal.fonts.tt;

import java.util.HashMap;
import java.util.Map;


public class Glyf extends Table {

    /**
     * holds mappings for drawing the glyphs
     */
    private final int[] charStrings;

    private final int glyfCount;

    /**
     * holds list of empty glyphs
     */
    private final boolean[] emptyCharStrings;
    private byte[] glyphTable;

    Glyf(final FontFile2 currentFontFile, final int glyphCount, final int[] glyphIndexStart) {

        //save so we can access
        this.glyfCount = glyphCount;

        charStrings = new int[glyphCount];
        emptyCharStrings = new boolean[glyphCount];

        //move to start and check exists
        final int startPointer = currentFontFile.selectTable(FontFile2.LOCA);

        //read  table
        if (startPointer != 0) {

            //read each gyf
            for (int i = 0; i < glyphCount; i++) {

                //just store in lookup table or flag as zero length
                if ((glyphIndexStart[i] == glyphIndexStart[i + 1])) {
                    charStrings[i] = -1;
                    emptyCharStrings[i] = true;
                } else {
                    charStrings[i] = glyphIndexStart[i];
                }
            }

            //read the actual glyph data
            glyphTable = currentFontFile.getTableBytes(FontFile2.GLYF);

        }
    }

    public int getCharString(final int glyph) {

        final int value;

        if (glyph < 0 || glyph >= glyfCount) {
            value = glyph;
        } else {
            value = charStrings[glyph];
        }

        return value;
    }

    public byte[] getTableData() {
        return glyphTable;
    }

    public int getGlypfCount() {
        return glyfCount;
    }

    /**
     * assume identify and build data needed for our OTF converter
     */
    public Map buildCharStringTable() {

        final Map returnStrings = new HashMap();

        for (int key = 0; key < glyfCount; key++) {
            if (!emptyCharStrings[key]) {
                returnStrings.put(key, key);
            }
        }
        return returnStrings;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy