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

The following examples show how to use java.awt.Font#canDisplay() . 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
Source File: DefineFont3Tag.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
@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
Source File: TextMeasureTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 3
Source File: MergedFont.java    From han3_ji7_tsoo1_kian3 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean 有這个字型無(int 控制碼, int 字體編號)
{
	if (字體編號 == 0)
	{
		for (Font 字體 : 字體集)
		{
			if (字體.canDisplay(控制碼))
			{
				return true;
			}
		}
	}
	return false;
}
 
Example 4
Source File: TextMeasureTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: Font2DTest.java    From jdk8u-jdk with 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 6
Source File: Font2DTest.java    From openjdk-jdk8u-backup with 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 7
Source File: TextMeasureTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: Font2DTest.java    From openjdk-8 with 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
Source File: FontEmbedDialog.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
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 10
Source File: TextMeasureTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: TextMeasureTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: TextMeasureTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 13
Source File: Font2DTest.java    From jdk8u60 with 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 14
Source File: Font2DTest.java    From openjdk-8-source with 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 15
Source File: Font2DTest.java    From jdk8u_jdk with 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 16
Source File: Font2DTest.java    From TencentKona-8 with 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 17
Source File: TextMeasureTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: SpaceAdvance.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 19
Source File: TableSheetCell.java    From netbeans with 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 File: RendererFactory.java    From netbeans with 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();
}