com.vectorprint.report.itext.style.parameters.BaseFontWrapper.java Source code

Java tutorial

Introduction

Here is the source code for com.vectorprint.report.itext.style.parameters.BaseFontWrapper.java

Source

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.vectorprint.report.itext.style.parameters;

/*
 * #%L
 * VectorPrintReport
 * %%
 * Copyright (C) 2012 - 2013 VectorPrint
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * #L%
 */

import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.pdf.BaseFont;
import com.vectorprint.VectorPrintRuntimeException;
import java.io.IOException;
import java.io.Serializable;

/**
 *
 * @author Eduard Drenth at VectorPrint.nl
 */
public class BaseFontWrapper implements Serializable {
    private final long serialVersionUID = 1;
    private transient BaseFont baseFont;
    private String fontName;

    public BaseFontWrapper(BaseFont baseFont) {
        this.baseFont = baseFont;
        fontName = baseFont.getPostscriptFontName();
    }

    private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException {
        s.defaultReadObject();
        Font f = FontFactory.getFont(fontName);
        if (f.getBaseFont() == null) {
            throw new VectorPrintRuntimeException("No basefont for: " + fontName);
        }
        baseFont = f.getBaseFont();
    }

    public BaseFont getBaseFont() {
        return baseFont;
    }

    public String getFontName() {
        return fontName;
    }

}