package com.knecon.fforesight.service.viewerdoc.model;

import java.util.Objects;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.font.Standard14Fonts;

import com.pdftron.pdf.Font;
import com.pdftron.pdf.PDFDoc;

import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;

@RequiredArgsConstructor
public class Standard14EmbeddableFont implements EmbeddableFont {

    private final PDType1Font font;

    private final int pdfTronIdentifier;

    public static Standard14EmbeddableFont helvetica() {

        return new Standard14EmbeddableFont(new PDType1Font(Standard14Fonts.FontName.HELVETICA), Font.e_helvetica);
    }


    @SneakyThrows
    public float getStringWidth(String text) {

        return font.getStringWidth(text);
    }


    @Override
    public PDFont embed(PDDocument document) {

        // no need to embed anything
        return font;
    }


    @Override
    @SneakyThrows
    public Font embed(PDFDoc document) {

        return Font.create(document, pdfTronIdentifier);
    }

}
