本文整理汇总了Java中java.awt.Font.canDisplay方法的典型用法代码示例。如果您正苦于以下问题:Java Font.canDisplay方法的具体用法?Java Font.canDisplay怎么用?Java Font.canDisplay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Font
的用法示例。
在下文中一共展示了Font.canDisplay方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.awt.Font; //导入方法依赖的package包/类
/** Call with hex codes of interesting characters. */
public static void main(String[] args) {
List<Integer> chars;
if (args.length == 0) {
chars = Collections.singletonList((int) Util.DT);
} else {
chars = new ArrayList<>(args.length);
for (String arg : args) {
chars.add(Integer.parseInt(arg, 16));
}
}
Font[] fonts =
GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
for (Integer c : chars) {
System.out.println("Fonts that can display 0x"
+ Integer.toHexString(c));
for (Font f : fonts) {
if (f.canDisplay(c)) {
System.out.println(f.getFontName());
}
}
}
}
示例2: getSymbolFont
import java.awt.Font; //导入方法依赖的package包/类
/** Returns the font for special (arrow-like) characters. */
public static Font getSymbolFont() {
if (SYMBOL_FONT == null) {
initLookAndFeel();
Font result = getLabelFont();
if (!result.canDisplay(Util.DT)) {
result = UIManager.getDefaults()
.getFont("SansSerif");
}
if (result == null || !result.canDisplay(Util.DT)) {
result = loadFont("stixgeneralregular.ttf").deriveFont(getLabelFont().getSize2D());
}
SYMBOL_FONT = result;
}
return SYMBOL_FONT;
}
示例3: makeDisplayable
import java.awt.Font; //导入方法依赖的package包/类
/**
* 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 makeDisplayable(String str , Font f) {
if( str == null || f == null){
return str;
}
StringBuilder buf = new StringBuilder(str.length());
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
switch (c) {
case '\t': buf.append(c); break;
case '\n': buf.append(c); break;
case '\r': buf.append(c); break;
case '\b': buf.append("\\b"); break; // NOI18N
case '\f': buf.append("\\f"); break; // NOI18N
default:
if( f == null || 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'); //NOI18N
}
buf.append(hex);
}
}
}
return buf.toString();
}
示例4: runTest
import java.awt.Font; //导入方法依赖的package包/类
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);
}
示例5: canDisplayRange
import java.awt.Font; //导入方法依赖的package包/类
protected boolean canDisplayRange(Font font, int rangeStart, int rangeEnd) {
for (int i = rangeStart; i < rangeEnd; i++) {
if (font.canDisplay(i)) {
return true;
}
}
return false;
}
示例6: makeDisplayble
import java.awt.Font; //导入方法依赖的package包/类
/**
* 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();
}
示例7: makeDisplayble
import java.awt.Font; //导入方法依赖的package包/类
/**
* 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();
}