當前位置: 首頁>>代碼示例>>Java>>正文


Java Font.getFont方法代碼示例

本文整理匯總了Java中java.awt.Font.getFont方法的典型用法代碼示例。如果您正苦於以下問題:Java Font.getFont方法的具體用法?Java Font.getFont怎麽用?Java Font.getFont使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.Font的用法示例。


在下文中一共展示了Font.getFont方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFontAtCurrentPos

import java.awt.Font; //導入方法依賴的package包/類
static Font getFontAtCurrentPos(AttributedCharacterIterator aci) {

        Object value = aci.getAttribute(TextAttribute.FONT);
        if (value != null) {
            return (Font) value;
        }
        if (aci.getAttribute(TextAttribute.FAMILY) != null) {
            return Font.getFont(aci.getAttributes());
        }

        int ch = CodePointIterator.create(aci).next();
        if (ch != CodePointIterator.DONE) {
            FontResolver resolver = FontResolver.getInstance();
            return resolver.getFont(resolver.getFontIndex(ch), aci.getAttributes());
        }
        return null;
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:TextLine.java

示例2: NSFPlayer

import java.awt.Font; //導入方法依賴的package包/類
public NSFPlayer(int i){
	super();
	
	System.out.println("Making an NSF Player!");
	Map<TextAttribute, Object> attributes = new HashMap<>();

	attributes.put(TextAttribute.FAMILY, "Default");
	attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_SEMIBOLD);
	attributes.put(TextAttribute.SIZE, 14);
	largefont = Font.getFont(attributes);
	attributes.put(TextAttribute.FAMILY, "Default");
	attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_SEMIBOLD);
	attributes.put(TextAttribute.SIZE, 10);
	smallfont = Font.getFont(attributes);
	nsfemode = i==1;
}
 
開發者ID:QuantumSoundings,項目名稱:BassNES,代碼行數:17,代碼來源:NSFPlayer.java

示例3: getGraphicOrFont

import java.awt.Font; //導入方法依賴的package包/類
/**
 * Extract a GraphicAttribute or Font from the given attributes.
 * If attributes does not contain a GraphicAttribute, Font, or
 * Font family entry this method returns null.
 */
private static Object getGraphicOrFont(
        Map<? extends Attribute, ?> attributes) {

    Object value = attributes.get(TextAttribute.CHAR_REPLACEMENT);
    if (value != null) {
        return value;
    }
    value = attributes.get(TextAttribute.FONT);
    if (value != null) {
        return value;
    }

    if (attributes.get(TextAttribute.FAMILY) != null) {
        return Font.getFont(attributes);
    }
    else {
        return null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:StyledParagraph.java

示例4: leak

import java.awt.Font; //導入方法依賴的package包/類
private static void leak() {
    Map<TextAttribute, Object> textAttributes = new HashMap<>();
    textAttributes.put(TextAttribute.FAMILY, "Sans Serif");
    textAttributes.put(TextAttribute.SIZE, 12);
    textAttributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
    Font font = Font.getFont(textAttributes);
    JLabel label = new JLabel();
    int dummy = 0;
    for (int i = 0; i < 500; i++) {
        if (i % 10 == 0) System.out.println("Starting iter " + (i+1));
        for (int j = 0; j <1000; j++) {
            FontMetrics fm = label.getFontMetrics(font);
            dummy += SwingUtilities.computeStringWidth(fm, Integer.toString(j));
        }
    }
    System.out.println("done " + dummy);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:KerningLeak.java

示例5: unmarshal

import java.awt.Font; //導入方法依賴的package包/類
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final Map<TextAttribute, Object> attributes;
    if (reader.hasMoreChildren()) {
        reader.moveDown();
        if (!reader.getNodeName().equals("attributes")) {
            final String classAlias = mapper.aliasForSystemAttribute("class");
            attributes = new HashMap<TextAttribute, Object>();
            do {
                if (!attributes.isEmpty()) {
                    reader.moveDown();
                }
                final Class<?> type = mapper.realClass(reader.getAttribute(classAlias));
                final TextAttribute attribute = (TextAttribute)textAttributeConverter.fromString(reader.getNodeName());
                final Object value = type == Mapper.Null.class ? null : context.convertAnother(null, type);
                attributes.put(attribute, value);
                reader.moveUp();
            } while (reader.hasMoreChildren());
        } else {
            // in <attributes>
            @SuppressWarnings("unchecked")
            final Map<TextAttribute, Object> typedAttributes = (Map<TextAttribute, Object>)context.convertAnother(
                null, Map.class);
            attributes = typedAttributes;
            reader.moveUp(); // out of </attributes>
        }
    } else {
        attributes = Collections.emptyMap();
    }
    for (final Iterator<?> iter = attributes.values().iterator(); iter.hasNext();) {
        if (iter.next() == null) {
            iter.remove();
        }
    }
    final Font font = Font.getFont(attributes);
    if (context.getRequiredType() == FontUIResource.class) {
        return new FontUIResource(font);
    } else {
        return font;
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:42,代碼來源:FontConverter.java

示例6: instantiate

import java.awt.Font; //導入方法依賴的package包/類
protected Expression instantiate(Object oldInstance, Encoder out) {
    Font font = (Font) oldInstance;

    int count = 0;
    String family = null;
    int style = Font.PLAIN;
    int size = 12;

    Map<TextAttribute, ?> basic = font.getAttributes();
    Map<TextAttribute, Object> clone = new HashMap<>(basic.size());
    for (TextAttribute key : basic.keySet()) {
        Object value = basic.get(key);
        if (value != null) {
            clone.put(key, value);
        }
        if (key == TextAttribute.FAMILY) {
            if (value instanceof String) {
                count++;
                family = (String) value;
            }
        }
        else if (key == TextAttribute.WEIGHT) {
            if (TextAttribute.WEIGHT_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.WEIGHT_BOLD.equals(value)) {
                count++;
                style |= Font.BOLD;
            }
        }
        else if (key == TextAttribute.POSTURE) {
            if (TextAttribute.POSTURE_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.POSTURE_OBLIQUE.equals(value)) {
                count++;
                style |= Font.ITALIC;
            }
        } else if (key == TextAttribute.SIZE) {
            if (value instanceof Number) {
                Number number = (Number) value;
                size = number.intValue();
                if (size == number.floatValue()) {
                    count++;
                }
            }
        }
    }
    Class<?> type = font.getClass();
    if (count == clone.size()) {
        return new Expression(font, type, "new", new Object[]{family, style, size});
    }
    if (type == Font.class) {
        return new Expression(font, type, "getFont", new Object[]{clone});
    }
    return new Expression(font, type, "new", new Object[]{Font.getFont(clone)});
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:56,代碼來源:MetaData.java


注:本文中的java.awt.Font.getFont方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。