下面列出了java.awt.Font#canDisplay ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
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");
}
}
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);
}
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);
}
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
for (int i = rangeStart; i < rangeEnd; i++) {
if (font.canDisplay(i)) {
return true;
}
}
return false;
}
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
for (int i = rangeStart; i < rangeEnd; i++) {
if (font.canDisplay(i)) {
return true;
}
}
return false;
}
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
for (int i = rangeStart; i < rangeEnd; i++) {
if (font.canDisplay(i)) {
return true;
}
}
return false;
}
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
for (int i = rangeStart; i < rangeEnd; i++) {
if (font.canDisplay(i)) {
return true;
}
}
return false;
}
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);
}
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);
}
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);
}
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();
}
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
for (int i = rangeStart; i < rangeEnd; i++) {
if (font.canDisplay(i)) {
return true;
}
}
return false;
}
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);
}
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
for (int i = rangeStart; i < rangeEnd; i++) {
if (font.canDisplay(i)) {
return true;
}
}
return false;
}
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
for (int i = rangeStart; i < rangeEnd; i++) {
if (font.canDisplay(i)) {
return true;
}
}
return false;
}
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);
}
@Override
public boolean 有這个字型無(int 控制碼, int 字體編號)
{
if (字體編號 == 0)
{
for (Font 字體 : 字體集)
{
if (字體.canDisplay(控制碼))
{
return true;
}
}
}
return false;
}
/**
* 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(" " + // NOI18N
" "
); // 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();
}
/**
* 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();
}