Example usage for java.awt Font TYPE1_FONT

List of usage examples for java.awt Font TYPE1_FONT

Introduction

In this page you can find the example usage for java.awt Font TYPE1_FONT.

Prototype

int TYPE1_FONT

To view the source code for java.awt Font TYPE1_FONT.

Click Source Link

Document

Identify a font resource of type TYPE1.

Usage

From source file:net.padaf.preflight.font.Type1FontValidator.java

/**
 * This methods validates the Font Stream, if the font program is damaged or
 * missing the FontContainer is updated and false is returned.
 * //from w  w w .j  av  a 2  s.  c o m
 * @throws ValidationException
 */
protected boolean checkFontFileElement() throws ValidationException {
    // ---- if the this font is a Subset, the CharSet entry must be present in
    // the FontDescriptor
    if (isSubSet(pFontDesc.getFontName())) {
        String charsetStr = pFontDesc.getCharSet();
        if (charsetStr == null || "".equals(charsetStr)) {
            this.fontContainer
                    .addError(new ValidationResult.ValidationError(ERROR_FONTS_CHARSET_MISSING_FOR_SUBSET,
                            "The Charset entry is missing for the Type1 Subset"));
            return false;
        }
    }

    // ---- FontFile Validation
    PDStream ff1 = pFontDesc.getFontFile();
    PDStream ff2 = pFontDesc.getFontFile2();
    PDStream ff3 = pFontDesc.getFontFile3();
    boolean onlyOne = (ff1 != null && ff2 == null && ff3 == null) || (ff1 == null && ff2 != null && ff3 == null)
            || (ff1 == null && ff2 == null && ff3 != null);

    if ((ff1 == null && (ff3 == null
            || !"Type1C".equals(((COSDictionary) ff3.getCOSObject()).getNameAsString(COSName.SUBTYPE))))
            || !onlyOne) {
        this.fontContainer.addError(new ValidationResult.ValidationError(ERROR_FONTS_FONT_FILEX_INVALID,
                "The FontFile is invalid"));
        return false;
    }

    if (ff1 != null) {
        COSStream stream = ff1.getStream();
        if (stream == null) {
            this.fontContainer.addError(new ValidationResult.ValidationError(ERROR_FONTS_FONT_FILEX_INVALID,
                    "The FontFile is missing"));
            this.fontContainer.setFontProgramEmbedded(false);
            return false;
        }

        boolean hasLength1 = stream.getInt(COSName.getPDFName(FONT_DICTIONARY_KEY_LENGTH1)) > 0;
        boolean hasLength2 = stream.getInt(COSName.getPDFName(FONT_DICTIONARY_KEY_LENGTH2)) > 0;
        boolean hasLength3 = stream.getInt(COSName.getPDFName(FONT_DICTIONARY_KEY_LENGTH3)) > 0;
        if (!(hasLength1 && hasLength2 && hasLength3)) {
            this.fontContainer.addError(new ValidationResult.ValidationError(ERROR_FONTS_FONT_FILEX_INVALID,
                    "The FontFile is invalid"));
            return false;
        }

        // ---- Stream validation should be done by the StreamValidateHelper.
        // ---- Process font specific check
        // ---- try to load the font using the java.awt.font object.
        // ---- if the font is invalid, an exception will be thrown
        ByteArrayInputStream bis = null;
        try {
            bis = new ByteArrayInputStream(ff1.getByteArray());
            Font.createFont(Font.TYPE1_FONT, bis);
            return checkFontMetricsDataAndFeedFontContainer(ff1) && checkFontFileMetaData(pFontDesc, ff1);
        } catch (IOException e) {
            this.fontContainer.addError(new ValidationResult.ValidationError(ERROR_FONTS_TYPE1_DAMAGED,
                    "The FontFile can't be read"));
            return false;
        } catch (FontFormatException e) {
            this.fontContainer.addError(
                    new ValidationResult.ValidationError(ERROR_FONTS_TYPE1_DAMAGED, "The FontFile is damaged"));
            return false;
        } finally {
            if (bis != null) {
                IOUtils.closeQuietly(bis);
            }
        }
    } else {
        return checkCIDFontWidths(ff3) && checkFontFileMetaData(pFontDesc, ff3);
    }
}

From source file:Citas.FrameCita.java

private void disenoBotones(JButton actual) {
    actual.setBackground(colorBotones);/*from w ww  .j  ava 2  s.co m*/
    font = font.deriveFont(Font.TYPE1_FONT, 13);
    actual.setFont(font);
    actual.setBorderPainted(false);
    actual.setFocusPainted(false);
    //actual.setContentAreaFilled(false);

    actual.setOpaque(false);
}

From source file:abfab3d.shapejs.ShapeJSGlobal.java

/**
 * js function to load a font//  w w w . jav  a2s. com
 * returns BufferedImage
 */
public static Object loadFont(Context cx, Scriptable thisObj, Object[] args, Function funObj) {
    if (args.length < 1) {
        throw Context.reportRuntimeError("loadFont() requires one filename.");
    }

    String filename = Context.toString(args[0]);

    if (filename == null || filename.length() == 0) {
        throw Context.reportRuntimeError("No file provided for loadFont() command");
    }

    printf("loading font file: %s\n", filename);

    String reason = null;

    File f = new File(filename);
    Font font = null;
    if (!f.exists()) {
        throw Context.reportRuntimeError(fmt("Cannot find font file: %s\n", f.getAbsoluteFile()));
    }

    if (f.length() > 800000) {
        // Bit of security thought here, font's should not be too large unless they contain some malware payload
        throw Context.reportRuntimeError(fmt("Font file too large"));
    }
    try {
        int type = Font.TRUETYPE_FONT;
        if (filename.indexOf(".ttf") == -1)
            type = Font.TYPE1_FONT;
        font = Font.createFont(type, f);
    } catch (Exception e) {
        reason = e.getMessage();
        e.printStackTrace();
    }
    if (font == null) {
        throw Context.reportRuntimeError(fmt("failed to load font file: %s.  Reason: %s\n", filename, reason));
    }

    return font;
}

From source file:org.apache.pdfbox.pdmodel.font.PDType1CFont.java

private static Font prepareAwtFont(CFFFont font) throws IOException {
    byte[] type1Bytes = Type1FontFormatter.format(font);

    InputStream is = new ByteArrayInputStream(type1Bytes);
    try {//  w w  w.j  a v a  2 s . c o m
        return Font.createFont(Font.TYPE1_FONT, is);
    } catch (FontFormatException ffe) {
        throw new WrappedIOException(ffe);
    } finally {
        is.close();
    }
}

From source file:org.apache.pdfbox.pdmodel.font.PDType1Font.java

/**
 * {@inheritDoc}/*  ww  w  . j a v a2s . c o  m*/
 */
public Font getawtFont() throws IOException {
    if (awtFont == null) {
        if (type1CFont != null) {
            awtFont = type1CFont.getawtFont();
        } else {
            String baseFont = getBaseFont();
            PDFontDescriptor fd = getFontDescriptor();
            if (fd != null && fd instanceof PDFontDescriptorDictionary) {
                PDFontDescriptorDictionary fdDictionary = (PDFontDescriptorDictionary) fd;
                if (fdDictionary.getFontFile() != null) {
                    try {
                        // create a type1 font with the embedded data
                        awtFont = Font.createFont(Font.TYPE1_FONT,
                                fdDictionary.getFontFile().createInputStream());
                    } catch (FontFormatException e) {
                        log.info("Can't read the embedded type1 font " + fd.getFontName());
                    }
                }
                if (awtFont == null) {
                    // check if the font is part of our environment
                    awtFont = FontManager.getAwtFont(fd.getFontName());
                    if (awtFont == null) {
                        log.info("Can't find the specified font " + fd.getFontName());
                    }
                }
            } else {
                // check if the font is part of our environment
                awtFont = FontManager.getAwtFont(baseFont);
                if (awtFont == null) {
                    log.info("Can't find the specified basefont " + baseFont);
                }
            }
        }
        if (awtFont == null) {
            // we can't find anything, so we have to use the standard font
            awtFont = FontManager.getStandardFont();
            log.info("Using font " + awtFont.getName() + " instead");
        }
    }
    return awtFont;
}

From source file:org.apache.pdfbox.preflight.font.descriptor.Type1DescriptorHelper.java

/**
 * Try to load the font using the java.awt.font object. if the font is invalid, an exception will be pushed in the
 * font container// www  .  jav a2  s  .  co m
 * 
 * @param fontDescriptor
 * @param fontFile
 */
protected void processFontFile1(PDFontDescriptorDictionary fontDescriptor, PDStream fontFile) {
    ByteArrayInputStream bis = null;
    try {
        bis = new ByteArrayInputStream(fontFile.getByteArray());
        Font.createFont(Font.TYPE1_FONT, bis);
        IOUtils.closeQuietly(bis);

        // Parse the Type1 Font program in order to extract Glyph Width
        COSStream streamObj = fontFile.getStream();
        int length1 = streamObj.getInt(COSName.LENGTH1);
        int length2 = streamObj.getInt(COSName.LENGTH2);
        bis = new ByteArrayInputStream(fontFile.getByteArray());
        Type1Parser parserForMetrics = Type1Parser.createParserWithEncodingObject(bis, length1, length2,
                font.getFontEncoding());
        Type1 parsedData = parserForMetrics.parse();

        this.fContainer.setType1Font(parsedData);

    } catch (IOException e) {
        this.fContainer.push(new ValidationError(ERROR_FONTS_TYPE1_DAMAGED, "The FontFile can't be read"));
    } catch (FontFormatException e) {
        this.fContainer.push(new ValidationError(ERROR_FONTS_TYPE1_DAMAGED, "The FontFile is damaged"));
    } finally {
        IOUtils.closeQuietly(bis);
    }
}