Examples of TrueTypeFont


Examples of com.sun.pdfview.font.ttf.TrueTypeFont

                                    if (fontRa != null) {
                                        fontRa.close();
                                    }
                                }

                                TrueTypeFont ttf = TrueTypeFont.parseFont(fontBytes);
                                for (final String fontName : ttf.getNames()) {
                                    if (!namedFontsToLocalTtfFiles.containsKey(fontName)) {
                                        namedFontsToLocalTtfFiles.put(fontName, ttfFile);
                                    }
                                }
                            } catch (Throwable t) {
View Full Code Here

Examples of com.sun.pdfview.font.ttf.TrueTypeFont

            OpenType ot = (OpenType) f;

            byte[] cmapData = ot.getFontTable (OpenType.TAG_CMAP);
            byte[] postData = ot.getFontTable (OpenType.TAG_POST);

            TrueTypeFont ttf = new TrueTypeFont (0x10000);

            cmapTable =
            (CmapTable) TrueTypeTable.createTable (ttf, "cmap",
                    ByteBuffer.wrap (cmapData));
            ttf.addTable ("cmap", cmapTable);

            postTable =
            (PostTable) TrueTypeTable.createTable (ttf, "post",
                    ByteBuffer.wrap (postData));
            ttf.addTable ("post", postTable);
        }
    }
View Full Code Here

Examples of com.sun.pdfview.font.ttf.TrueTypeFont

        // fos.write(fontdata);
        // fos.close();

        try {
            // read the true type information
            TrueTypeFont ttf = TrueTypeFont.parseFont (fontdata);

            // System.out.println(ttf.toString());

            // get the cmap, post, and hmtx tables for later use
            cmapTable = (CmapTable) ttf.getTable ("cmap");
            postTable = (PostTable) ttf.getTable ("post");
            hmtxTable = (HmtxTable) ttf.getTable ("hmtx");

            // read the units per em from the head table
            HeadTable headTable = (HeadTable) ttf.getTable ("head");
            unitsPerEm = headTable.getUnitsPerEm ();

            /* Find out if we have the right info in our name table.
             * This is a hack because Java can only deal with fonts that
             * have a Microsoft encoded name in their name table (PlatformID 3).
             * We'll 'adjust' the font to add it if not, and take our chances
             * with our parsing, since it wasn't going to work anyway.
             */
            NameTable nameTable = null;

            try {
                nameTable = (NameTable) ttf.getTable ("name");
            } catch (Exception ex) {
                System.out.println ("Error reading name table for font " +
                        getBaseFont () + ".  Repairing!");
            }

            boolean nameFixed = fixNameTable (ttf, nameTable);

            /* Figure out if we need to hack the CMap table.  This might
             * be the case if we use characters that Java considers control
             * characters (0x9, 0xa and 0xd), that have to be re-mapped
             */
            boolean cmapFixed = fixCMapTable (ttf, cmapTable);

            // use the parsed font instead of the original
            if (nameFixed || cmapFixed) {
                // System.out.println("Using fixed font!");
                // System.out.println(ttf.toString());
                fontdata = ttf.writeFont ();

                // FileOutputStream fos2 = new FileOutputStream("/tmp/" + getBaseFont() + ".fix");
                // fos2.write(fontdata);
                // fos2.close();
            }
View Full Code Here

Examples of org.apache.fontbox.ttf.TrueTypeFont

                throw new TikaException("Bad TrueType font.");
            }
        }
       
        // Ask FontBox to parse the file for us
        TrueTypeFont font;
        TTFParser parser = new TTFParser();
        if (tis != null && tis.hasFile()) {
            font = parser.parseTTF(tis.getFile());
        } else {
            font = parser.parseTTF(stream);
        }

        // Report the details of the font
        metadata.set(Metadata.CONTENT_TYPE, TYPE.toString());
        metadata.set(TikaCoreProperties.CREATED, font.getHeader().getCreated().getTime());
        metadata.set(
                TikaCoreProperties.MODIFIED,
                font.getHeader().getModified().getTime());

        XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
        xhtml.startDocument();
        xhtml.endDocument();
    }
View Full Code Here

Examples of org.apache.fontbox.ttf.TrueTypeFont

                    "The FontFile can't be read for " + this.font.getName()));
        }
        else
        {
            // there must be exactly one encoding in the "cmap" table if the font is symbolic
            TrueTypeFont ttf = pdTrueTypeFont.getTrueTypeFont();
            try
            {
                if (pdTrueTypeFont.isSymbolic() && ttf.getCmap().getCmaps().length != 1)
                {
                    this.fContainer.push(new ValidationError(ERROR_FONTS_ENCODING,
                            "Symbolic TrueType font has more than one 'cmap' entry for " +
                            this.font.getName()));
                }
View Full Code Here

Examples of org.apache.fontbox.ttf.TrueTypeFont

                "org/apache/pdfbox/ttf/ArialMT.ttf");
        Assert.assertNotNull(arialIs);

        TTFParser parser = new TTFParser();

        TrueTypeFont arial = parser.parse(arialIs);

        CmapTable cmapTable = arial.getCmap();
        Assert.assertNotNull(cmapTable);

        CmapSubtable[] cmaps = cmapTable.getCmaps();
        Assert.assertNotNull(cmaps);

        CmapSubtable cmap = null;

        for (CmapSubtable e : cmaps)
        {
            if (e.getPlatformId() == NameRecord.PLATFORM_WINDOWS
                    && e.getPlatformEncodingId() == NameRecord.ENCODING_WINDOWS_UNICODE_BMP)
            {
                cmap = e;
                break;
            }
        }

        Assert.assertNotNull(cmap);

        PostScriptTable post = arial.getPostScript();
        Assert.assertNotNull(post);

        String[] glyphNames = arial.getPostScript().getGlyphNames();
        Assert.assertNotNull(glyphNames);

        // test a WGL4 (Macintosh standard) name
        int gid = cmap.getGlyphId(0x2122); // TRADE MARK SIGN
        Assert.assertEquals("trademark", glyphNames[gid]);
View Full Code Here

Examples of org.apache.fontbox.ttf.TrueTypeFont

     * we attempt to find a good fallback based on the font descriptor.
     */
    public static TrueTypeFont getTrueTypeFallbackFont(PDFontDescriptor fontDescriptor)
    {
        String fontName = getFallbackFontName(fontDescriptor);
        TrueTypeFont ttf = getTrueTypeFont(fontName);
        if (ttf == null)
        {
            // we have to return something here as TTFs aren't strictly required on the system
            log.error("No TTF fallback font for '" + fontName + "'");
            return ttfFallbackFont;
View Full Code Here

Examples of org.apache.fontbox.ttf.TrueTypeFont

     * @param postScriptName PostScript font name
     */
    public static TrueTypeFont getTrueTypeFont(String postScriptName)
    {
        // first ask the font provider for the font
        TrueTypeFont ttf = getProvider().getTrueTypeFont(postScriptName);
        if (ttf == null)
        {
            // then try substitutes
            for (String substituteName : getSubstitutes(postScriptName))
            {
View Full Code Here

Examples of org.apache.fontbox.ttf.TrueTypeFont

        if (cff != null)
        {
            return cff;
        }

        TrueTypeFont ttf = getTrueTypeFont(postScriptName);
        if (ttf != null)
        {
            return ttf;
        }
View Full Code Here

Examples of org.apache.fontbox.ttf.TrueTypeFont

     * Adds an OTF or TTF font to the file cache. To reduce memory, the parsed font is not cached.
     */
    private void addOpenTypeFont(File otfFile) throws IOException
    {
        TTFParser ttfParser = new TTFParser(false, true);
        TrueTypeFont ttf = null;
        try
        {
            ttf = ttfParser.parse(otfFile);
        }
        catch (NullPointerException e) // TTF parser is buggy
        {
            LOG.error("Could not load font file: " + otfFile, e);
        }
        catch (IOException e)
        {
            LOG.error("Could not load font file: " + otfFile, e);
        }

        try
        {
            // check for 'name' table
            NamingTable nameTable = ttf.getNaming();
            if (nameTable == null)
            {
                LOG.warn("Missing 'name' table in font " + otfFile);
            }
            else
            {
                // read PostScript name, if any
                if (nameTable.getPostScriptName() != null)
                {
                    String psName = nameTable.getPostScriptName();

                    String format;
                    if (ttf.getTableMap().get("CFF ") != null)
                    {
                        format = "OTF";
                        cffFontFiles.put(psName, otfFile);
                    }
                    else
                    {
                        format = "TTF";
                        ttfFontFiles.put(psName, otfFile);
                    }

                    if (LOG.isTraceEnabled())
                    {
                        LOG.trace(format +": '" + psName + "' / '" + nameTable.getFontFamily() +
                                "' / '" + nameTable.getFontSubFamily() + "'");
                    }
                }
                else
                {
                    LOG.warn("Missing 'name' entry for PostScript name in font " + otfFile);
                }
            }
        }
        finally
        {
            if (ttf != null)
            {
                ttf.close();
            }
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.