Package java.awt.font

Examples of java.awt.font.LineMetrics


    private void paintAdvancedStyles(final GlyphView v,
                                     final int start, final int end,
                                     final Graphics2D g,
                                     final Font font, final Rectangle bounds) {
        final Segment text = v.getText(start, end);
        final LineMetrics lm = font.getLineMetrics(text.array, text.offset,
                                                   text.offset + text.count,
                                                   g.getFontRenderContext());
        int baseline = bounds.y + Math.round(lm.getAscent());

        if (v.isStrikeThrough()) {
            int offset = Math.round(lm.getStrikethroughOffset()) + baseline;
            BasicStroke stroke =
                new BasicStroke(lm.getStrikethroughThickness());
            Stroke oldStroke = g.getStroke();
            g.setStroke(stroke);
            g.drawLine(bounds.x, offset, bounds.x + bounds.width, offset);
            g.setStroke(oldStroke);
        }

        if (v.isUnderline()) {
            int offset = Math.round(lm.getUnderlineOffset()) + baseline;
            BasicStroke stroke = new BasicStroke(lm.getUnderlineThickness());
            Stroke oldStroke = g.getStroke();
            g.setStroke(stroke);
            g.drawLine(bounds.x, offset, bounds.x + bounds.width, offset);
            g.setStroke(oldStroke);
        }
View Full Code Here


        // handle label drawing...
        FontRenderContext frc = g2.getFontRenderContext();
        Rectangle2D labelBounds =
            this.axisLabelFont.getStringBounds(label, frc);
        LineMetrics lm = this.axisLabelFont.getLineMetrics(label, frc);
        double ascent = lm.getAscent();

        if (labelX == chartArea.getCenterX())
            labelX -= labelBounds.getWidth() / 2;
        else if (labelX < chartArea.getCenterX())
            labelX -= labelBounds.getWidth();
View Full Code Here

        // handle label drawing...
        FontRenderContext frc = g2.getFontRenderContext();
        Rectangle2D labelBounds =
            this.axisLabelFont.getStringBounds(label, frc);
        LineMetrics lm = this.axisLabelFont.getLineMetrics(label, frc);
        double ascent = lm.getAscent();

        if (labelX == chartArea.getCenterX())
            labelX -= labelBounds.getWidth() / 2;
        else if (labelX < chartArea.getCenterX())
            labelX -= labelBounds.getWidth();
View Full Code Here

     *
     * @param str specified String
     * @param frc specified FontRenderContext
     */
    private void setDefaultLineMetrics(String str, FontRenderContext frc){
        LineMetrics lm = fPhysicalFonts[0].getLineMetrics(str, frc, null);
        float maxCharWidth = (float)fPhysicalFonts[0].getMaxCharBounds(frc).getWidth();

        if (numFonts == 1) {
            this.nlm = (LineMetricsImpl)lm;
            return;
        }

        float[] baselineOffsets = lm.getBaselineOffsets();
        int numChars = str.length();

        // XXX: default value - common for all Fonts
        int baseLineIndex = lm.getBaselineIndex();

        float maxUnderlineThickness = lm.getUnderlineThickness();
        float maxUnderlineOffset = lm.getUnderlineOffset();
        float maxStrikethroughThickness = lm.getStrikethroughThickness();
        float minStrikethroughOffset = lm.getStrikethroughOffset();
        float maxLeading = lm.getLeading()// External leading
        float maxHeight = lm.getHeight();   // Height of the font ( == (ascent + descent + leading))
        float maxAscent = lm.getAscent();   // Ascent of the font
        float maxDescent = lm.getDescent(); // Descent of the font

        for (int i = 1; i < numFonts; i++){
            lm = fPhysicalFonts[i].getLineMetrics(str, frc, null);
            if (maxUnderlineThickness < lm.getUnderlineThickness()){
                maxUnderlineThickness = lm.getUnderlineThickness();
            }

            if (maxUnderlineOffset < lm.getUnderlineOffset()){
                maxUnderlineOffset = lm.getUnderlineOffset();
            }

            if (maxStrikethroughThickness < lm.getStrikethroughThickness()){
                maxStrikethroughThickness = lm.getStrikethroughThickness();
            }

            if (minStrikethroughOffset > lm.getStrikethroughOffset()){
                minStrikethroughOffset = lm.getStrikethroughOffset();
            }

            if (maxLeading < lm.getLeading()){
                maxLeading = lm.getLeading();
            }

            if (maxAscent < lm.getAscent()){
                maxAscent = lm.getAscent();
            }

            if (maxDescent < lm.getDescent()){
                maxDescent = lm.getDescent();
            }

            float width = (float)fPhysicalFonts[i].getMaxCharBounds(frc).getWidth();
            if(maxCharWidth < width){
                maxCharWidth = width;
            }
            for (int j =0; j < baselineOffsets.length; j++){
                float[] offsets = lm.getBaselineOffsets();
                if (baselineOffsets[j] > offsets[j]){
                    baselineOffsets[j] = offsets[j];
                }
            }

View Full Code Here

     * @param end the end offset in array of chars
     * @param frc specified FontRenderContext
     */
    public Rectangle2D getStringBounds(char[] chars, int start, int end, FontRenderContext frc){

        LineMetrics lm = getLineMetrics();
        float minY = -lm.getAscent();
        float minX = 0;
        float height = lm.getHeight();
        float width = 0;

        for (int i = start; i < end; i++){
            width += charWidth(chars[i]);
        }
View Full Code Here

        Object val = fonts.get(new Integer(0));

        if (val instanceof Font) {
            Font firstFont = (Font) val;
            LineMetrics lm = firstFont.getLineMetrics(breaker.text, 0, 1, breaker.frc);
            baselineOffsets = lm.getBaselineOffsets();
            baselineIndex = lm.getBaselineIndex();
        } else if (val instanceof GraphicAttribute) {
            // Get first graphic attribute and use it
            GraphicAttribute ga = (GraphicAttribute) val;

            int align = ga.getAlignment();
View Full Code Here

    Graphics g = icon.getGraphics();

    g.setFont(new Font("Helvetica", Font.BOLD, 16));
   
    Rectangle2D bounds = g.getFontMetrics().getStringBounds(text, g);
    LineMetrics lm = g.getFontMetrics().getLineMetrics(text, g);
    System.out.println("Height: "+lm.getHeight());

    BufferedImage drawImage = new BufferedImage(
        (int) Math.max(bounds.getWidth(), icon.getWidth()),
        (int) (bounds.getHeight() + icon.getHeight()),
        BufferedImage.TYPE_4BYTE_ABGR);
View Full Code Here

    }

    @Override
    public int getBaseline(int width, int height) {
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();
        LineMetrics lm = font.getLineMetrics("", fontRenderContext);

        return Math.round(margin.top + lm.getAscent());
    }
View Full Code Here

        float preferredHeight;
        if (text != null) {
            int widthUpdated = width;
            FontRenderContext fontRenderContext = Platform.getFontRenderContext();
            LineMetrics lm = font.getLineMetrics("", fontRenderContext);
            float lineHeight = lm.getHeight();

            preferredHeight = lineHeight;

            int n = text.length();
            if (n > 0
View Full Code Here

            preferredWidth = 0;
        }

        preferredWidth += (padding.left + padding.right);

        LineMetrics lm = font.getLineMetrics("", fontRenderContext);
        int preferredHeight = (int)Math.ceil(lm.getHeight()) + (padding.top + padding.bottom);

        return new Dimensions(preferredWidth, preferredHeight);
    }
View Full Code Here

TOP

Related Classes of java.awt.font.LineMetrics

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.