package org.verapdf.model.impl.pb.pd.font;

import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.common.PDStream;
import org.apache.pdfbox.pdmodel.font.PDCIDFont;
import org.apache.pdfbox.pdmodel.font.PDFontDescriptor;
import org.apache.pdfbox.pdmodel.font.PDFontLike;
import org.verapdf.model.baselayer.Object;
import org.verapdf.model.factory.font.FontFactory;
import org.verapdf.model.impl.pb.external.PBoxFontProgram;
import org.verapdf.model.impl.pb.pd.PBoxPDResources;
import org.verapdf.model.pdlayer.PDFont;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Timur Kamalov
 */
public abstract class PBoxPDFont extends PBoxPDResources implements PDFont {

    public static final String FONT_FILE = "fontFile";

	protected PBoxPDFont(PDFontLike font, final String type) {
		super(font, type);
	}

    @Override
    public List<? extends Object> getLinkedObjects(String link) {
        if (FONT_FILE.equals(link)) {
            return getFontFile();
        }
        return super.getLinkedObjects(link);
    }

    private List<PBoxFontProgram> getFontFile() {
        List<PBoxFontProgram> list = new ArrayList<>();
        if (!getSubtype().equals(FontFactory.TYPE_3)
                && (pdFontLike.isEmbedded())) {
            PDFontDescriptor fontDescriptor = pdFontLike.getFontDescriptor();
            PDStream fontFile;
            if (getSubtype().equals(FontFactory.TYPE_1)) {
                fontFile = fontDescriptor.getFontFile();
            } else if (getSubtype().equals(FontFactory.TRUE_TYPE)) {
                fontFile = fontDescriptor.getFontFile2();
            } else {
                fontFile = fontDescriptor.getFontFile3();
            }
            if (fontFile != null) {
                list.add(new PBoxFontProgram(fontFile));
            }
        }
        return list;
    }

    @Override
    public String getSubtype() {
        String subtype = null;
        if (pdFontLike instanceof org.apache.pdfbox.pdmodel.font.PDFont) {
            subtype = ((org.apache.pdfbox.pdmodel.font.PDFont) pdFontLike)
                    .getSubType();
        } else if (pdFontLike instanceof PDCIDFont) {
            subtype = ((PDCIDFont) pdFontLike).getCOSObject().getNameAsString(
                    COSName.SUBTYPE);
        }
        return subtype;
    }

    @Override
    public String getBaseFont() {
        return pdFontLike.getName();
    }

}

@@ -832,16 +832,849 @@
 e);%0A%09%7D%0A%0A
+%09public String getType() %7B%0A%09%09String subtype = null;%0A%09%09if (pdFontLike instanceof org.apache.pdfbox.pdmodel.font.PDFont) %7B%0A%09%09%09subtype = ((org.apache.pdfbox.pdmodel.font.PDFont) pdFontLike)%0A%09%09%09%09%09.getType();%0A%09%09%7D else if (pdFontLike instanceof PDCIDFont) %7B%0A%09%09%09subtype = ((PDCIDFont) pdFontLike).getCOSObject().getNameAsString(%0A%09%09%09%09%09COSName.TYPE);%0A%09%09%7D%0A%09%09return subtype;%0A%09%7D%0A%0A%09@Override%0A%09public String getSubtype() %7B%0A%09%09String subtype = null;%0A%09%09if (pdFontLike instanceof org.apache.pdfbox.pdmodel.font.PDFont) %7B%0A%09%09%09subtype = ((org.apache.pdfbox.pdmodel.font.PDFont) pdFontLike)%0A%09%09%09%09%09.getSubType();%0A%09%09%7D else if (pdFontLike instanceof PDCIDFont) %7B%0A%09%09%09subtype = ((PDCIDFont) pdFontLike).getCOSObject().getNameAsString(%0A%09%09%09%09%09COSName.SUBTYPE);%0A%09%09%7D%0A%09%09return subtype;%0A%09%7D%0A%0A%09@Override%0A%09public String getBaseFont() %7B%0A%09%09return pdFontLike.getName();%0A%09%7D%0A%0A
     @Ove
@@ -2680,573 +2680,6 @@
  %7D%0A%0A
-    @Override%0A    public String getSubtype() %7B%0A        String subtype = null;%0A        if (pdFontLike instanceof org.apache.pdfbox.pdmodel.font.PDFont) %7B%0A            subtype = ((org.apache.pdfbox.pdmodel.font.PDFont) pdFontLike)%0A                    .getSubType();%0A        %7D else if (pdFontLike instanceof PDCIDFont) %7B%0A            subtype = ((PDCIDFont) pdFontLike).getCOSObject().getNameAsString(%0A                    COSName.SUBTYPE);%0A        %7D%0A        return subtype;%0A    %7D%0A%0A    @Override%0A    public String getBaseFont() %7B%0A        return pdFontLike.getName();%0A    %7D%0A%0A
 %7D%0A

Add Type property for PBoxPDFont