Search in sources :

Example 81 with COSName

use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.

the class PDFontDescriptor method setFontName.

/**
 * This will set the font name.
 *
 * @param fontName The new name for the font.
 */
public void setFontName(String fontName) {
    COSName name = null;
    if (fontName != null) {
        name = COSName.getPDFName(fontName);
    }
    dic.setItem(COSName.FONT_NAME, name);
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName)

Example 82 with COSName

use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.

the class PDFontFactory method createDescendantFont.

/**
 * Creates a new PDCIDFont instance with the appropriate subclass.
 *
 * @param dictionary descendant font dictionary
 * @return a PDCIDFont instance, based on the SubType entry of the dictionary
 * @throws IOException if something goes wrong
 */
static PDCIDFont createDescendantFont(COSDictionary dictionary, PDType0Font parent) throws IOException {
    COSName type = dictionary.getCOSName(COSName.TYPE, COSName.FONT);
    if (!COSName.FONT.equals(type)) {
        throw new IllegalArgumentException("Expected 'Font' dictionary but found '" + type.getName() + "'");
    }
    COSName subType = dictionary.getCOSName(COSName.SUBTYPE);
    if (COSName.CID_FONT_TYPE0.equals(subType)) {
        return new PDCIDFontType0(dictionary, parent);
    } else if (COSName.CID_FONT_TYPE2.equals(subType)) {
        return new PDCIDFontType2(dictionary, parent);
    } else {
        throw new IOException("Invalid font type: " + type);
    }
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) IOException(java.io.IOException)

Example 83 with COSName

use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.

the class PDFontFactory method createFont.

/**
 * Creates a new PDFont instance with the appropriate subclass.
 *
 * @param dictionary a font dictionary
 * @param resourceCache resource cache, only useful for type 3 fonts, can be null
 * @return a PDFont instance, based on the SubType entry of the dictionary
 * @throws IOException if something goes wrong
 */
public static PDFont createFont(COSDictionary dictionary, ResourceCache resourceCache) throws IOException {
    COSName type = dictionary.getCOSName(COSName.TYPE, COSName.FONT);
    if (!COSName.FONT.equals(type)) {
        Log.e("PdfBox-Android", "Expected 'Font' dictionary but found '" + type.getName() + "'");
    }
    COSName subType = dictionary.getCOSName(COSName.SUBTYPE);
    if (COSName.TYPE1.equals(subType)) {
        COSBase fd = dictionary.getDictionaryObject(COSName.FONT_DESC);
        if (fd instanceof COSDictionary && ((COSDictionary) fd).containsKey(COSName.FONT_FILE3)) {
            return new PDType1CFont(dictionary);
        }
        return new PDType1Font(dictionary);
    } else if (COSName.MM_TYPE1.equals(subType)) {
        COSBase fd = dictionary.getDictionaryObject(COSName.FONT_DESC);
        if (fd instanceof COSDictionary && ((COSDictionary) fd).containsKey(COSName.FONT_FILE3)) {
            return new PDType1CFont(dictionary);
        }
        return new PDMMType1Font(dictionary);
    } else if (COSName.TRUE_TYPE.equals(subType)) {
        return new PDTrueTypeFont(dictionary);
    } else if (COSName.TYPE3.equals(subType)) {
        return new PDType3Font(dictionary, resourceCache);
    } else if (COSName.TYPE0.equals(subType)) {
        return new PDType0Font(dictionary);
    } else if (COSName.CID_FONT_TYPE0.equals(subType)) {
        throw new IllegalArgumentException("Type 0 descendant font not allowed");
    } else if (COSName.CID_FONT_TYPE2.equals(subType)) {
        throw new IllegalArgumentException("Type 2 descendant font not allowed");
    } else {
        // assuming Type 1 font (see PDFBOX-1988) because it seems that Adobe Reader does this
        // however, we may need more sophisticated logic perhaps looking at the FontFile
        Log.w("PdfBox-Android", "Invalid font subtype '" + subType + "'");
        return new PDType1Font(dictionary);
    }
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Aggregations

COSName (com.tom_roush.pdfbox.cos.COSName)83 COSBase (com.tom_roush.pdfbox.cos.COSBase)50 COSArray (com.tom_roush.pdfbox.cos.COSArray)27 IOException (java.io.IOException)24 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)23 COSObject (com.tom_roush.pdfbox.cos.COSObject)11 COSString (com.tom_roush.pdfbox.cos.COSString)11 HashMap (java.util.HashMap)10 Map (java.util.Map)10 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)9 COSStream (com.tom_roush.pdfbox.cos.COSStream)7 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)7 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)5 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)5 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)5 PDXObject (com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)5 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)4 PDTransparencyGroup (com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup)4 OutputStream (java.io.OutputStream)4 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)3