Java Code Examples for java.awt.Font#canDisplay()

The following examples show how to use java.awt.Font#canDisplay() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void setAdvanceValues(Font font) {
    List<RECT> newFontBoundsTable = new ArrayList<>();
    List<Integer> newFontAdvanceTable = new ArrayList<>();
    for (int i = 0; i < codeTable.size(); i++) {
        Integer character = codeTable.get(i);
        char ch = (char) (int) character;
        if (!font.canDisplay(ch) && fontFlagsHasLayout) { //cannot display, leave old if exist
            newFontAdvanceTable.add(fontAdvanceTable.get(i));
            newFontBoundsTable.add(fontBoundsTable.get(i));
            continue;
        }
        SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(font, (int) Math.round(getDivider() * 1024), ch);
        newFontBoundsTable.add(shp.getBounds());
        int fontStyle = getFontStyle();
        Font advanceFont = font.deriveFont(fontStyle, 1024); // Not multiplied with divider as it causes problems to create font with height around 20k
        newFontAdvanceTable.add((int) getDivider() * Math.round(FontHelper.getFontAdvance(advanceFont, ch)));
    }
    fontAdvanceTable = newFontAdvanceTable;
    fontBoundsTable = newFontBoundsTable;
    fontKerningTable = new ArrayList<>();
    fontFlagsHasLayout = true;
}
 
Example 2
public static void main(String[] args) throws Exception {

        BufferedImage bi = new BufferedImage(1,1,1);
        Graphics2D g2d = bi.createGraphics();
        Font font = new Font(Font.DIALOG, Font.PLAIN, 12);
        if (!font.canDisplay(' ')) {
            return;
        }
        g2d.setFont(font);
        FontMetrics fm = g2d.getFontMetrics();
        if (fm.charWidth(' ') == 0) {
            throw new RuntimeException("Space has char width of 0");
        }
    }
 
Example 3
public void runTest(Object ctx, int numReps) {
    Font font = ((TextContext)ctx).font;
    boolean b = false;
    do {
        for (int i = 0; i < 0x10000; i += 0x64) {
            b ^= font.canDisplay((char)i);
        }
    } while (--numReps >= 0);
}
 
Example 4
public void runTest(Object ctx, int numReps) {
    Font font = ((TextContext)ctx).font;
    boolean b = false;
    do {
        for (int i = 0; i < 0x10000; i += 0x64) {
            b ^= font.canDisplay((char)i);
        }
    } while (--numReps >= 0);
}
 
Example 5
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
    for (int i = rangeStart; i < rangeEnd; i++) {
        if (font.canDisplay(i)) {
            return true;
        }
    }
    return false;
}
 
Example 6
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
    for (int i = rangeStart; i < rangeEnd; i++) {
        if (font.canDisplay(i)) {
            return true;
        }
    }
    return false;
}
 
Example 7
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
    for (int i = rangeStart; i < rangeEnd; i++) {
        if (font.canDisplay(i)) {
            return true;
        }
    }
    return false;
}
 
Example 8
Source Project: jdk8u60   File: Font2DTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
    for (int i = rangeStart; i < rangeEnd; i++) {
        if (font.canDisplay(i)) {
            return true;
        }
    }
    return false;
}
 
Example 9
public void runTest(Object ctx, int numReps) {
    Font font = ((TextContext)ctx).font;
    boolean b = false;
    do {
        for (int i = 0; i < 0x10000; i += 0x64) {
            b ^= font.canDisplay((char)i);
        }
    } while (--numReps >= 0);
}
 
Example 10
public void runTest(Object ctx, int numReps) {
    Font font = ((TextContext)ctx).font;
    boolean b = false;
    do {
        for (int i = 0; i < 0x10000; i += 0x64) {
            b ^= font.canDisplay((char)i);
        }
    } while (--numReps >= 0);
}
 
Example 11
public void runTest(Object ctx, int numReps) {
    Font font = ((TextContext)ctx).font;
    boolean b = false;
    do {
        for (int i = 0; i < 0x10000; i += 0x64) {
            b ^= font.canDisplay((char)i);
        }
    } while (--numReps >= 0);
}
 
Example 12
private void updateCheckboxes() {
    Font f = getSelectedFont().deriveFont(12f);
    int rc = CharacterRanges.rangeCount();

    Set<Integer> allChars = new HashSet<>();
    for (int i = 0; i < rc; i++) {
        rangeNames[i] = CharacterRanges.rangeName(i);
        int[] codes = CharacterRanges.rangeCodes(i);
        int avail = 0;
        StringBuilder sample = new StringBuilder();
        for (int c = 0; c < codes.length; c++) {
            if (f.canDisplay(codes[c])) {
                allChars.add(codes[c]);
                if (avail < SAMPLE_MAX_LENGTH) {
                    sample.append((char) codes[c]);
                }
                avail++;
            }
        }
        rangeSamples[i].setText(sample.toString());
        rangeSamples[i].setFont(f);
        rangeCheckboxes[i].setText(translate("range.description").replace("%available%", Integer.toString(avail)).replace("%name%", rangeNames[i]).replace("%total%", Integer.toString(codes.length)));
    }
    allCheckbox.setText(translate("allcharacters").replace("%available%", Integer.toString(allChars.size())));
    individialSample.setFont(f);
    updateIndividual();
}
 
Example 13
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
    for (int i = rangeStart; i < rangeEnd; i++) {
        if (font.canDisplay(i)) {
            return true;
        }
    }
    return false;
}
 
Example 14
public void runTest(Object ctx, int numReps) {
    Font font = ((TextContext)ctx).font;
    boolean b = false;
    do {
        for (int i = 0; i < 0x10000; i += 0x64) {
            b ^= font.canDisplay((char)i);
        }
    } while (--numReps >= 0);
}
 
Example 15
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
    for (int i = rangeStart; i < rangeEnd; i++) {
        if (font.canDisplay(i)) {
            return true;
        }
    }
    return false;
}
 
Example 16
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
    for (int i = rangeStart; i < rangeEnd; i++) {
        if (font.canDisplay(i)) {
            return true;
        }
    }
    return false;
}
 
Example 17
public void runTest(Object ctx, int numReps) {
    Font font = ((TextContext)ctx).font;
    boolean b = false;
    do {
        for (int i = 0; i < 0x10000; i += 0x64) {
            b ^= font.canDisplay((char)i);
        }
    } while (--numReps >= 0);
}
 
Example 18
@Override
public boolean 有這个字型無(int 控制碼, int 字體編號)
{
	if (字體編號 == 0)
	{
		for (Font 字體 : 字體集)
		{
			if (字體.canDisplay(控制碼))
			{
				return true;
			}
		}
	}
	return false;
}
 
Example 19
Source Project: netbeans   File: TableSheetCell.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Makes the given String displayble. Probably there doesn't exists
 * perfect solution for all situation. (someone prefer display those
 * squares for undisplayable chars, someone unicode placeholders). So lets
 * try do the best compromise.
 */
private static String makeDisplayble(String str, Font f) {
    if (null == str) {
        return str;
    }

    if (null == f) {
        f = new JLabel().getFont();
    }

    StringBuffer buf = new StringBuffer((int) (str.length() * 1.3)); // x -> \u1234
    char[] chars = str.toCharArray();

    for (int i = 0; i < chars.length; i++) {
        char c = chars[i];

        switch (c) {
        case '\t':
            buf.append("&nbsp;&nbsp;&nbsp;&nbsp;" + // NOI18N
                "&nbsp;&nbsp;&nbsp;&nbsp;"
            ); // NOI18N
            break;

        case '\n':
            break;

        case '\r':
            break;

        case '\b':
            buf.append("\\b");

            break; // NOI18N

        case '\f':
            buf.append("\\f");

            break; // NOI18N

        default:

            if (!processHtmlEntity(buf, c)) {
                if ((null == f) || f.canDisplay(c)) {
                    buf.append(c);
                } else {
                    buf.append("\\u"); // NOI18N

                    String hex = Integer.toHexString(c);

                    for (int j = 0; j < (4 - hex.length()); j++)
                        buf.append('0');

                    buf.append(hex);
                }
            }
        }
    }

    return buf.toString();
}
 
Example 20
Source Project: netbeans   File: RendererFactory.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Makes the given String displayble. Probably there doesn't exists
 * perfect solution for all situation. (someone prefer display those
 * squares for undisplayable chars, someone unicode placeholders). So lets
 * try do the best compromise.
 */
private static String makeDisplayble(String str, Font f) {
    if (null == str) {
        return str;
    }

    if (null == f) {
        f = new JLabel().getFont();
    }

    StringBuffer buf = new StringBuffer(str.length() * 6); // x -> \u1234
    char[] chars = str.toCharArray();

    for (int i = 0; i < chars.length; i++) {
        char c = chars[i];

        switch (c) {
        // label doesn't interpret tab correctly
        case '\t':
            buf.append("        "); // NOI18N
            break;

        case '\n':
            break;

        case '\r':
            break;

        case '\b':
            buf.append("\\b");

            break; // NOI18N

        case '\f':
            buf.append("\\f");

            break; // NOI18N

        default:

            if ((null == f) || f.canDisplay(c)) {
                buf.append(c);
            } else {
                buf.append("\\u"); // NOI18N

                String hex = Integer.toHexString(c);

                for (int j = 0; j < (4 - hex.length()); j++)
                    buf.append('0');

                buf.append(hex);
            }
        }
    }

    return buf.toString();
}