List of usage examples for java.awt Font canDisplayUpTo
public int canDisplayUpTo(String str)
From source file:com.limegroup.gnutella.gui.GUIUtils.java
/** * Determines if a font can display up to a point in the string. * * Returns -1 if it can display the whole string. *///from www . java 2 s . c o m public static boolean canDisplay(Font f, String s) { int upTo = f.canDisplayUpTo(s); if (upTo >= s.length() || upTo == -1) return true; else return false; }
From source file:org.apache.pdfbox.pdmodel.font.PDSimpleFont.java
/** * {@inheritDoc}//from w w w .jav a2 s .c o m */ public void drawString(String string, int[] codePoints, Graphics g, float fontSize, AffineTransform at, float x, float y) throws IOException { Font awtFont = getawtFont(); FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, true); GlyphVector glyphs = null; boolean useCodepoints = codePoints != null && isType0Font(); PDFont descendantFont = useCodepoints ? ((PDType0Font) this).getDescendantFont() : null; // symbolic fonts may trigger the same fontmanager.so/dll error as described below if (useCodepoints && !descendantFont.getFontDescriptor().isSymbolic()) { PDCIDFontType2Font cid2Font = null; if (descendantFont instanceof PDCIDFontType2Font) { cid2Font = (PDCIDFontType2Font) descendantFont; } if ((cid2Font != null && cid2Font.hasCIDToGIDMap()) || isFontSubstituted) { // we still have to use the string if a CIDToGIDMap is used glyphs = awtFont.createGlyphVector(frc, string); } else { glyphs = awtFont.createGlyphVector(frc, codePoints); } } else { // mdavis - fix fontmanager.so/dll on sun.font.FileFont.getGlyphImage // for font with bad cmaps? // Type1 fonts are not affected as they don't have cmaps if (!isType1Font() && awtFont.canDisplayUpTo(string) != -1) { LOG.warn("Changing font on <" + string + "> from <" + awtFont.getName() + "> to the default font"); awtFont = Font.decode(null).deriveFont(1f); } glyphs = awtFont.createGlyphVector(frc, string); } Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); writeFont(g2d, at, x, y, glyphs); }
From source file:org.datacleaner.util.GraphUtils.java
private static <E> Transformer<E, Font> createFontTransformer() { return new Transformer<E, Font>() { @Override//from w ww . j ava2s .c om public Font transform(E input) { final Font defaultFont = WidgetUtils.FONT_SMALL; if (input == null) { return defaultFont; } final String str; if (input instanceof HasName) { str = ((HasName) input).getName(); } else if (input instanceof Object[]) { str = Arrays.toString((Object[]) input); } else { str = input.toString(); } if (defaultFont.canDisplayUpTo(str) == -1) { return defaultFont; } final Font findCompatibleFont = WidgetUtils.findCompatibleFont(str, WidgetUtils.FONT_SMALL); return findCompatibleFont.deriveFont(WidgetUtils.FONT_SIZE_SMALL); } }; }