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

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


                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);

                    final Point2D minLoc = renderer.getMinLocation(fontSize);
                    final int dstX = x + (int) minLoc.getX();
                    final int dstY = y - d.height + (int) minLoc.getY();

                    surface.drawAlphaRaster(alphaRaster, tx, 0, 0, dstX, dstY,
                        d.width, d.height, color);
                }
                x += (scale * (double) hmTable.getAdvanceWidth(index));
            }
        } catch (Exception ex) {
            log.error("Error drawing text", ex);
        }
    }
View Full Code Here


            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);
        } catch (IOException ex) {
            log.error("Error drawing text", ex);
        }
View Full Code Here

     */
    public int charWidth(char ch) {
        try {
            final CMapTable cmapTable = fontData.getCMapTable();
            final CMapTable.EncodingTable encTable = cmapTable.getEncodingTable(0);
            final HorizontalMetricsTable hmTable = fontData.getHorizontalMetricsTable();
            final int index = encTable.getTableFormat().getGlyphIndex(ch);
            return (int) (hmTable.getAdvanceWidth(index) * scale);
        } catch (IOException ex) {
            return 0;
        }
    }
View Full Code Here

    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

TOP

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

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.