Package org.jnode.awt.font.truetype.tables

Examples of org.jnode.awt.font.truetype.tables.GlyphTable


     */
    protected TTFFontData() {
    }

    public Glyph getGlyph(char c) throws IOException {
        final GlyphTable glyphTable = getGlyphTable();
        final CMapTable cmapTable = getCMapTable();

        if (!(cmapTable.getNrEncodingTables() > 0)) {
            throw new RuntimeException("No Encoding is found!");
        }

        final CMapTable.EncodingTable encTable = cmapTable.getEncodingTable(0);
        if (encTable.getTableFormat() == null) {
            throw new RuntimeException("The table is NUll!!");
        }

        //get the index for the needed glyph
        final int index = encTable.getTableFormat().getGlyphIndex(c);
        return glyphTable.getGlyph(index);
    }
View Full Code Here


    public void render(Surface surface, Shape clip, AffineTransform tx,
                       CharSequence text, int x, int y, Color color) {
        try {
            final TTFFontData fd = (TTFFontData) fontData;
            final int fontSize = fontMetrics.getFont().getSize();
            final GlyphTable glyphTable = fd.getGlyphTable();
            final CMapTable cmapTable = fd.getCMapTable();

            if (!(cmapTable.getNrEncodingTables() > 0)) {
                throw new RuntimeException("No Encoding is found!");
            }
            final CMapTable.EncodingTable encTable = cmapTable
                .getEncodingTable(0);
            if (encTable.getTableFormat() == null) {
                throw new RuntimeException("The table is NUll!!");
            }
            final HorizontalHeaderTable hheadTable = fd
                .getHorizontalHeaderTable();
            final double ascent = hheadTable.getAscent();
            final HorizontalMetricsTable hmTable = fd
                .getHorizontalMetricsTable();
            final double scale = fontSize / ascent;

            final int textLength = text.length();
            final WritableRaster alphaRaster = createAlphaRaster();
            for (int i = 0; i < textLength; i++) {
                // get the index for the needed glyph
                final char ch = text.charAt(i);
                final int index = encTable.getTableFormat().getGlyphIndex(ch);
                if (ch != ' ') {
                    final Glyph g = glyphTable.getGlyph(index);
                    final GlyphRenderer renderer = renderCache.getRenderer(g,
                        ascent);
                    final Dimension d;
                    d = renderer.createGlyphRaster(alphaRaster, fontSize);
View Full Code Here

            int x, int y, Color c) {
        try {
            final GeneralPath gp = new GeneralPath();
            gp.moveTo(x, y);

            final GlyphTable glyphTable = fontData.getGlyphTable();
            final CMapTable cmapTable = fontData.getCMapTable();
            final HorizontalHeaderTable hheadTable = fontData
                .getHorizontalHeaderTable();
            final HorizontalMetricsTable hmTable = fontData
                .getHorizontalMetricsTable();

            if (!(cmapTable.getNrEncodingTables() > 0)) {
                throw new RuntimeException("No Encoding is found!");
            }
            final CMapTable.EncodingTable encTable = cmapTable
                .getEncodingTable(0);
            if (encTable.getTableFormat() == null) {
                throw new RuntimeException("The table is NUll!!");
            }
            final double ascent = hheadTable.getAscent();

            final AffineTransform tx2 = new AffineTransform();           
            final double scale = fontSize / (-hheadTable.getDescent() + ascent);
           
            tx2.translate(x, y + fontSize);
            tx2.scale(scale, -scale);
            tx2.translate(0, ascent);
           
            for (int i = 0; i < text.length(); i++) {
                // get the index for the needed glyph
                final char character = text.charAt(i);
                final int index = encTable.getTableFormat().getGlyphIndex(character);
                if (character != ' ') {
                    Shape shape = ((ShapedGlyph) glyphTable.getGlyph(index)).getShape();
                    gp.append(shape.getPathIterator(tx2), false);
                }
                tx2.translate(hmTable.getAdvanceWidth(index), 0);
            }
            surface.draw(gp, clip, tx, c, Surface.PAINT_MODE);
View Full Code Here

        testGetGlyph(text, 100, 100, 40);
    }

    public static void drawString(Graphics g, String s, int x, int y, double fontSize) throws IOException {

        final GlyphTable glyphTable = ttf.getGlyphTable();
        final CMapTable cmapTable = ttf.getCMapTable();
        final HorizontalHeaderTable hheadTable = ttf.getHorizontalHeaderTable();
        final HorizontalMetricsTable hmTable = ttf.getHorizontalMetricsTable();

        if (!(cmapTable.getNrEncodingTables() > 0)) {
            throw new RuntimeException("No Encoding is found!");
        }
        final CMapTable.EncodingTable encTable = cmapTable.getEncodingTable(0);
        if (encTable.getTableFormat() == null) {
            throw new RuntimeException("The table is NUll!!");
        }
        final int maxAdvance = hheadTable.getMaxAdvance();
        final double ascent = hheadTable.getAscent();
        final int descent = -hheadTable.getDescent();

        final AffineTransform tx = new AffineTransform();
        double scale = fontSize / ascent;

        tx.translate(x, y + fontSize);
        System.out.println("Scale=" + scale);
        tx.scale(scale, -scale);
        tx.translate(0, ascent);

        final Graphics2D g2 = (Graphics2D) g;
        g2.setColor(Color.GREEN);
        g2.fill(new Rectangle2D.Double(x, y - ascent * scale, maxAdvance * scale, ascent * scale));
        g2.setColor(Color.YELLOW);
        g2.fill(new Rectangle2D.Double(x, y, maxAdvance * scale, descent * scale));
        g2.setColor(Color.RED);
        final GeneralPath gp = new GeneralPath();

        for (int i = 0; i < s.length(); i++) {
            // get the index for the needed glyph
            final int index = encTable.getTableFormat().getGlyphIndex(s.charAt(i));
            final TTFGlyph glyph = (TTFGlyph) glyphTable.getGlyph(index);
            final GeneralPath shape = glyph.getShape();
            gp.append(shape.getPathIterator(tx), false);
            tx.translate(hmTable.getAdvanceWidth(index), 0);
        }
        g2.draw(gp);
View Full Code Here

        g2.draw(gp);
    }

    public static void testGetGlyph(String s, int x, int y, int fontSize) throws IOException {

        final GlyphTable glyphTable = ttf.getGlyphTable();
        final CMapTable cmapTable = ttf.getCMapTable();
        final HorizontalHeaderTable hheadTable = ttf.getHorizontalHeaderTable();

        if (!(cmapTable.getNrEncodingTables() > 0)) {
            throw new RuntimeException("No Encoding is found!");
        }
        final CMapTable.EncodingTable encTable = cmapTable.getEncodingTable(0);
        if (encTable.getTableFormat() == null) {
            throw new RuntimeException("The table is NUll!!");
        }

        final double ascent = hheadTable.getAscent();
        final AffineTransform tx = new AffineTransform();
        double scale = fontSize / ascent;
        tx.translate(x, y + fontSize);
        System.out.println("Scale=" + scale + ", ascent=" + ascent);
        tx.scale(scale, -scale);
        tx.translate(0, ascent);

        final String[] types = {"move", "line", "quad", "cubic", "close"};

        for (int i = 0; i < s.length(); i++) {
            // get the index for the needed glyph
            final char ch = s.charAt(i);
            System.out.println("Getting index for char: " + ch);
            final int index = encTable.getTableFormat().getGlyphIndex(ch);
            final TTFGlyph glyph = (TTFGlyph) glyphTable.getGlyph(index);
            final GeneralPath shape = glyph.getShape();
            PathIterator pi = shape.getPathIterator(null);
            final float[] f = new float[6];
            while (!pi.isDone()) {
                final int type = pi.currentSegment(f);
View Full Code Here

TOP

Related Classes of org.jnode.awt.font.truetype.tables.GlyphTable

Copyright © 2018 www.massapicom. 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.