当前位置: 首页>>代码示例>>Java>>正文


Java Font.getLineMetrics方法代码示例

本文整理汇总了Java中java.awt.Font.getLineMetrics方法的典型用法代码示例。如果您正苦于以下问题:Java Font.getLineMetrics方法的具体用法?Java Font.getLineMetrics怎么用?Java Font.getLineMetrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Font的用法示例。


在下文中一共展示了Font.getLineMetrics方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fastInit

import java.awt.Font; //导入方法依赖的package包/类
private void fastInit(char[] chars, Font font,
                      Map<? extends Attribute, ?> attrs,
                      FontRenderContext frc) {

    // Object vf = attrs.get(TextAttribute.ORIENTATION);
    // isVerticalLine = TextAttribute.ORIENTATION_VERTICAL.equals(vf);
    isVerticalLine = false;

    LineMetrics lm = font.getLineMetrics(chars, 0, chars.length, frc);
    CoreMetrics cm = CoreMetrics.get(lm);
    byte glyphBaseline = (byte) cm.baselineIndex;

    if (attrs == null) {
        baseline = glyphBaseline;
        baselineOffsets = cm.baselineOffsets;
        justifyRatio = 1.0f;
    } else {
        paragraphInit(glyphBaseline, cm, attrs, chars);
    }

    characterCount = chars.length;

    textLine = TextLine.fastCreateTextLine(frc, chars, font, cm, attrs);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:TextLayout.java

示例2: drawStringInRect

import java.awt.Font; //导入方法依赖的package包/类
/**
 * A utility method that draws a string inside a rectangle.
 *
 * @param g2  the graphics device.
 * @param bounds  the rectangle.
 * @param font  the font.
 * @param text  the text.
 */
private void drawStringInRect(Graphics2D g2, Rectangle2D bounds, Font font,
                              String text) {

    g2.setFont(font);
    FontMetrics fm = g2.getFontMetrics(font);
    Rectangle2D r = TextUtilities.getTextBounds(text, g2, fm);
    double x = bounds.getX();
    if (r.getWidth() < bounds.getWidth()) {
        x = x + (bounds.getWidth() - r.getWidth()) / 2;
    }
    LineMetrics metrics = font.getLineMetrics(
        text, g2.getFontRenderContext()
    );
    g2.drawString(
        text, (float) x, (float) (bounds.getMaxY() 
            - this.bottomInnerGap - metrics.getDescent())
    );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:27,代码来源:MarkerAxisBand.java

示例3: estimateMaximumTickLabelWidth

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Estimates the maximum width of the tick labels, assuming the specified tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we just look at two
 * values: the lower bound and the upper bound for the axis.  These two values will usually
 * be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return the estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelWidth(Graphics2D g2, DateTickUnit unit) {

    Insets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.left + tickLabelInsets.right;

    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of the font)...
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr = null;
        String upperStr = null;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:50,代码来源:DateAxis.java

示例4: estimateMaximumTickLabelHeight

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Estimates the maximum width of the tick labels, assuming the specified tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we just look at two
 * values: the lower bound and the upper bound for the axis.  These two values will usually
 * be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return the estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelHeight(Graphics2D g2, DateTickUnit unit) {

    Insets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.top + tickLabelInsets.bottom;

    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (!isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of the font)...
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr = null;
        String upperStr = null;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:50,代码来源:DateAxis.java

示例5: main

import java.awt.Font; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
    // The bug only happens with Type 1 fonts. The Ghostscript font files
    // should be commonly available. From distro pacakge or
    //  ftp://ftp.gnu.org/gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz
    // Pass pfa/pfb font file as argument
    String path = args[0];

    // Load
    InputStream stream = new FileInputStream(path);
    Font font = Font.createFont(Font.TYPE1_FONT,stream);

    // Ensure native bits have been generated
    BufferedImage img = new BufferedImage(100,100,
                             BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = img.createGraphics();
    FontRenderContext frc = g2d.getFontRenderContext();

    font.getLineMetrics("derp",frc);

    // Force disposal -
    // System.gc() is not sufficient.
    Field font2DHandleField = Font.class.getDeclaredField("font2DHandle");
    font2DHandleField.setAccessible(true);
    sun.font.Font2DHandle font2DHandle =
                  (sun.font.Font2DHandle)font2DHandleField.get(font);

    sun.font.Font2D font2D = font2DHandle.font2D;
    sun.font.Type1Font type1Font = (sun.font.Type1Font)font2D;

    Method getScalerMethod =
    sun.font.Type1Font.class.getDeclaredMethod("getScaler");
    getScalerMethod.setAccessible(true);
    sun.font.FontScaler scaler =
              (sun.font.FontScaler)getScalerMethod.invoke(type1Font);

    // dispose should not crash due to double free
    scaler.dispose();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:FontDisposeTest.java

示例6: findMaximumTickLabelHeight

import java.awt.Font; //导入方法依赖的package包/类
/**
 * A utility method for determining the height of the tallest tick label.
 *
 * @param ticks  the ticks.
 * @param g2  the graphics device.
 * @param drawArea  the area within which the plot and axes should be drawn.
 * @param vertical  a flag that indicates whether or not the tick labels are 'vertical'.
 *
 * @return the height of the tallest tick label.
 */
protected double findMaximumTickLabelHeight(List ticks,
                                            Graphics2D g2, 
                                            Rectangle2D drawArea, 
                                            boolean vertical) {
                                                
    Insets insets = getTickLabelInsets();
    Font font = getTickLabelFont();
    double maxHeight = 0.0;
    if (vertical) {
        FontMetrics fm = g2.getFontMetrics(font);
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            Tick tick = (Tick) iterator.next();
            Rectangle2D labelBounds = TextUtilities.getTextBounds(tick.getText(), g2, fm);
            if (labelBounds.getWidth() + insets.top + insets.bottom > maxHeight) {
                maxHeight = labelBounds.getWidth() + insets.top + insets.bottom;
            }
        }
    }
    else {
        LineMetrics metrics = font.getLineMetrics("ABCxyz", g2.getFontRenderContext());
        maxHeight = metrics.getHeight() + insets.top + insets.bottom;
    }
    return maxHeight;
    
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:37,代码来源:ValueAxis.java

示例7: findMaximumTickLabelWidth

import java.awt.Font; //导入方法依赖的package包/类
/**
 * A utility method for determining the width of the widest tick label.
 *
 * @param ticks  the ticks.
 * @param g2  the graphics device.
 * @param drawArea  the area within which the plot and axes should be drawn.
 * @param vertical  a flag that indicates whether or not the tick labels are 'vertical'.
 *
 * @return the width of the tallest tick label.
 */
protected double findMaximumTickLabelWidth(List ticks, 
                                           Graphics2D g2, 
                                           Rectangle2D drawArea, 
                                           boolean vertical) {
                                               
    Insets insets = getTickLabelInsets();
    Font font = getTickLabelFont();
    double maxWidth = 0.0;
    if (!vertical) {
        FontMetrics fm = g2.getFontMetrics(font);
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            Tick tick = (Tick) iterator.next();
            Rectangle2D labelBounds = TextUtilities.getTextBounds(tick.getText(), g2, fm);
            if (labelBounds.getWidth() + insets.left + insets.right > maxWidth) {
                maxWidth = labelBounds.getWidth() + insets.left + insets.right;
            }
        }
    }
    else {
        LineMetrics metrics = font.getLineMetrics("ABCxyz", g2.getFontRenderContext());
        maxWidth = metrics.getHeight() + insets.top + insets.bottom;
    }
    return maxWidth;
    
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:37,代码来源:ValueAxis.java

示例8: estimateMaximumTickLabelWidth

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Estimates the maximum width of the tick labels, assuming the specified 
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we
 * just look at two values: the lower bound and the upper bound for the 
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelWidth(Graphics2D g2, 
                                             DateTickUnit unit) {

    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();

    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of 
        // the font)...
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr = null;
        String upperStr = null;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:53,代码来源:DateAxis.java

示例9: estimateMaximumTickLabelHeight

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Estimates the maximum width of the tick labels, assuming the specified 
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we 
 * just look at two values: the lower bound and the upper bound for the 
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelHeight(Graphics2D g2, 
                                              DateTickUnit unit) {

    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();

    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (!isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of 
        // the font)...
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr = null;
        String upperStr = null;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:53,代码来源:DateAxis.java

示例10: findMaximumTickLabelHeight

import java.awt.Font; //导入方法依赖的package包/类
/**
 * A utility method for determining the height of the tallest tick label.
 *
 * @param ticks  the ticks.
 * @param g2  the graphics device.
 * @param drawArea  the area within which the plot and axes should be drawn.
 * @param vertical  a flag that indicates whether or not the tick labels 
 *                  are 'vertical'.
 *
 * @return The height of the tallest tick label.
 */
protected double findMaximumTickLabelHeight(List ticks,
                                            Graphics2D g2, 
                                            Rectangle2D drawArea, 
                                            boolean vertical) {
                                                
    RectangleInsets insets = getTickLabelInsets();
    Font font = getTickLabelFont();
    double maxHeight = 0.0;
    if (vertical) {
        FontMetrics fm = g2.getFontMetrics(font);
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            Tick tick = (Tick) iterator.next();
            Rectangle2D labelBounds = TextUtilities.getTextBounds(
                    tick.getText(), g2, fm);
            if (labelBounds.getWidth() + insets.getTop() 
                    + insets.getBottom() > maxHeight) {
                maxHeight = labelBounds.getWidth() 
                            + insets.getTop() + insets.getBottom();
            }
        }
    }
    else {
        LineMetrics metrics = font.getLineMetrics("ABCxyz", 
                g2.getFontRenderContext());
        maxHeight = metrics.getHeight() 
                    + insets.getTop() + insets.getBottom();
    }
    return maxHeight;
    
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:43,代码来源:ValueAxis.java

示例11: findMaximumTickLabelWidth

import java.awt.Font; //导入方法依赖的package包/类
/**
 * A utility method for determining the width of the widest tick label.
 *
 * @param ticks  the ticks.
 * @param g2  the graphics device.
 * @param drawArea  the area within which the plot and axes should be drawn.
 * @param vertical  a flag that indicates whether or not the tick labels 
 *                  are 'vertical'.
 *
 * @return The width of the tallest tick label.
 */
protected double findMaximumTickLabelWidth(List ticks, 
                                           Graphics2D g2, 
                                           Rectangle2D drawArea, 
                                           boolean vertical) {
                                               
    RectangleInsets insets = getTickLabelInsets();
    Font font = getTickLabelFont();
    double maxWidth = 0.0;
    if (!vertical) {
        FontMetrics fm = g2.getFontMetrics(font);
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            Tick tick = (Tick) iterator.next();
            Rectangle2D labelBounds = TextUtilities.getTextBounds(
                    tick.getText(), g2, fm);
            if (labelBounds.getWidth() + insets.getLeft() 
                    + insets.getRight() > maxWidth) {
                maxWidth = labelBounds.getWidth() 
                           + insets.getLeft() + insets.getRight();
            }
        }
    }
    else {
        LineMetrics metrics = font.getLineMetrics("ABCxyz", 
                g2.getFontRenderContext());
        maxWidth = metrics.getHeight() 
                   + insets.getTop() + insets.getBottom();
    }
    return maxWidth;
    
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:43,代码来源:ValueAxis.java

示例12: createComponentsOnRun

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Returns an array in logical order of the TextLineComponents on
 * the text in the given range, with the given attributes.
 */
public static TextLineComponent[] createComponentsOnRun(int runStart,
                                                        int runLimit,
                                                        char[] chars,
                                                        int[] charsLtoV,
                                                        byte[] levels,
                                                        TextLabelFactory factory,
                                                        Font font,
                                                        CoreMetrics cm,
                                                        FontRenderContext frc,
                                                        Decoration decorator,
                                                        TextLineComponent[] components,
                                                        int numComponents) {

    int pos = runStart;
    do {
        int chunkLimit = firstVisualChunk(charsLtoV, levels, pos, runLimit); // <= displayLimit

        do {
            int startPos = pos;
            int lmCount;

            if (cm == null) {
                LineMetrics lineMetrics = font.getLineMetrics(chars, startPos, chunkLimit, frc);
                cm = CoreMetrics.get(lineMetrics);
                lmCount = lineMetrics.getNumChars();
            }
            else {
                lmCount = (chunkLimit-startPos);
            }

            TextLineComponent nextComponent =
                factory.createExtended(font, cm, decorator, startPos, startPos + lmCount);

            ++numComponents;
            if (numComponents >= components.length) {
                components = expandArray(components);
            }

            components[numComponents-1] = nextComponent;

            pos += lmCount;
        } while (pos < chunkLimit);

    } while (pos < runLimit);

    return components;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:52,代码来源:TextLine.java

示例13: StandardTextSource

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Create a simple implementation of a TextSource.
 *
 * Chars is an array containing clen chars in the context, in
 * logical order, contiguously starting at cstart.  Start and len
 * represent that portion of the context representing the true
 * source; start, like cstart, is relative to the start of the
 * character array.
 *
 * Level is the bidi level (0-63 for the entire context. Flags is
 * the layout flags. Font is the font, frc is the render context,
 * and lm is the line metrics for the entire source text, but not
 * necessarily the context.
 */
public StandardTextSource(char[] chars,
                          int start,
                          int len,
                          int cstart,
                          int clen,
                          int level,
                          int flags,
                          Font font,
                          FontRenderContext frc,
                          CoreMetrics cm) {
  if (chars == null) {
    throw new IllegalArgumentException("bad chars: null");
  }
  if (cstart < 0) {
    throw new IllegalArgumentException("bad cstart: " + cstart);
  }
  if (start < cstart) {
    throw new IllegalArgumentException("bad start: " + start + " for cstart: " + cstart);
  }
  if (clen < 0) {
    throw new IllegalArgumentException("bad clen: " + clen);
  }
  if (cstart + clen > chars.length) {
    throw new IllegalArgumentException("bad clen: " + clen + " cstart: " + cstart + " for array len: " + chars.length);
  }
  if (len < 0) {
    throw new IllegalArgumentException("bad len: " + len);
  }
  if ((start + len) > (cstart + clen)) {
    throw new IllegalArgumentException("bad len: " + len + " start: " + start + " for cstart: " + cstart + " clen: " + clen);
  }
  if (font == null) {
    throw new IllegalArgumentException("bad font: null");
  }
  if (frc == null) {
    throw new IllegalArgumentException("bad frc: null");
  }

  this.chars = chars.clone();
  this.start = start;
  this.len = len;
  this.cstart = cstart;
  this.clen = clen;
  this.level = level;
  this.flags = flags;
  this.font = font;
  this.frc = frc;

  if (cm != null) {
      this.cm = cm;
  } else {
      LineMetrics metrics = font.getLineMetrics(chars, cstart, clen, frc);
      this.cm = ((FontLineMetrics)metrics).cm;
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:70,代码来源:StandardTextSource.java

示例14: StandardTextSource

import java.awt.Font; //导入方法依赖的package包/类
/**
   * Create a simple implementation of a TextSource.
   *
   * Chars is an array containing clen chars in the context, in
   * logical order, contiguously starting at cstart.  Start and len
   * represent that portion of the context representing the true
   * source; start, like cstart, is relative to the start of the
   * character array.
   *
   * Level is the bidi level (0-63 for the entire context. Flags is
   * the layout flags. Font is the font, frc is the render context,
   * and lm is the line metrics for the entire source text, but not
   * necessarily the context.
   */
  StandardTextSource(char[] chars,
                     int start,
                     int len,
                     int cstart,
                     int clen,
                     int level,
                     int flags,
                     Font font,
                     FontRenderContext frc,
                     CoreMetrics cm) {
  if (chars == null) {
    throw new IllegalArgumentException("bad chars: null");
  }
  if (cstart < 0) {
    throw new IllegalArgumentException("bad cstart: " + cstart);
  }
  if (start < cstart) {
    throw new IllegalArgumentException("bad start: " + start + " for cstart: " + cstart);
  }
  if (clen < 0) {
    throw new IllegalArgumentException("bad clen: " + clen);
  }
  if (cstart + clen > chars.length) {
    throw new IllegalArgumentException("bad clen: " + clen + " cstart: " + cstart + " for array len: " + chars.length);
  }
  if (len < 0) {
    throw new IllegalArgumentException("bad len: " + len);
  }
  if ((start + len) > (cstart + clen)) {
    throw new IllegalArgumentException("bad len: " + len + " start: " + start + " for cstart: " + cstart + " clen: " + clen);
  }
  if (font == null) {
    throw new IllegalArgumentException("bad font: null");
  }
  if (frc == null) {
    throw new IllegalArgumentException("bad frc: null");
  }

  this.chars = chars;
  this.start = start;
  this.len = len;
  this.cstart = cstart;
  this.clen = clen;
  this.level = level;
  this.flags = flags;
  this.font = font;
  this.frc = frc;

  if (cm != null) {
      this.cm = cm;
  } else {
      LineMetrics metrics = font.getLineMetrics(chars, cstart, clen, frc);
      this.cm = ((FontLineMetrics)metrics).cm;
  }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:70,代码来源:StandardTextSource.java

示例15: main

import java.awt.Font; //导入方法依赖的package包/类
public static void main(String args[]) {
    String fontName = "Lucida Sans";
    if (args.length > 0) {
        fontName = args[0];
    }
    FontRenderContext frc = new FontRenderContext(null, false, false);
    FontRenderContext frc2 = new FontRenderContext(AffineTransform.getScaleInstance(1.5, 1.5), false, false);

    Font font0 = new Font(fontName, 0, 20);
    HashMap map = new HashMap();
    map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    map.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
    Font font = font0.deriveFont(map);

    System.out.println("Using font: " + font);

    double rot = -Math.PI/4;
    AffineTransform scrtx = AffineTransform.getRotateInstance(rot);
    scrtx.scale(1, 2);

    Font[] fonts = {
        font.deriveFont(1f),
        font.deriveFont(20f),
        font.deriveFont(40f),
        font.deriveFont(80f),
        font.deriveFont(AffineTransform.getRotateInstance(rot)),
        font.deriveFont(AffineTransform.getScaleInstance(1, 2)),
        font.deriveFont(AffineTransform.getScaleInstance(2, 4)),
        font.deriveFont(scrtx),
    };

    LineMetrics[] metrics = new LineMetrics[fonts.length * 2];
    for (int i = 0; i < metrics.length; ++i) {
        Font f = fonts[i % fonts.length];
        FontRenderContext frcx = i < fonts.length ? frc : frc2;
        metrics[i] = f.getLineMetrics("X", frcx);
  //       dumpMetrics("Metrics for " + f.getSize2D() + " pt. font,\n  tx: " +
  //       f.getTransform() + ",\n   frctx: " + frcx.getTransform(), metrics[i]);
    }

    // test for linear scale
    // this seems to work, might need to get fancy to deal with last-significant-bit issues?
    double ds1 = metrics[2].getStrikethroughOffset() - metrics[1].getStrikethroughOffset();
    double du1 = metrics[2].getUnderlineThickness() - metrics[1].getUnderlineThickness();
    double ds2 = metrics[3].getStrikethroughOffset() - metrics[2].getStrikethroughOffset();
    double du2 = metrics[3].getUnderlineThickness() - metrics[2].getUnderlineThickness();
    if (ds2 != ds1 * 2 || du2 != du1 * 2) {
        throw new IllegalStateException("non-linear scale: " + ds1 + " / " + ds2 + ", " +
                                        du1 + " / " + du2);
    }

    JFrame jf = new JFrame("Fonts");
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.add(new JScrollPane(new FontsPanel(fonts)));
    jf.pack();
    jf.setVisible(true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:58,代码来源:UnderlineTest.java


注:本文中的java.awt.Font.getLineMetrics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。