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

The following examples show how to use java.awt.Font#isPlain() . 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
private String getFontStyle() {
    Font font = g.getFont();
    if (font.isPlain()) {
        return "Plain";
    } else if (font.isItalic() && font.isBold()) {
        return "ItalicBold";
    } else if (font.isBold()) {
        return "Bold";
    } else if (font.isItalic()) {
        return "Italic";
    }
    return "";
}
 
Example 2
/**
 * Select the style in the style component
 * 
 * @param font Font where to get the style to search
 */
private void SelectInStyleList(Font font) {
	int index = 0;
	if (font.isPlain())
		index = 0;
	else if (font.isBold() && !font.isItalic())
		index = 1;
	else if (!font.isBold() && font.isItalic())
		index = 2;
	else if (font.isBold() && font.isItalic())
		index = 3;
	jStyleList.setSelectedIndex(index);
	jStyleList.ensureIndexIsVisible(index);
}
 
Example 3
/**
 * Retrieves the fake font details for a given font.
 *
 * @param font
 *            the font to lookup.
 * @return the fake font.
 */
public static synchronized FontDetails getFontDetails(Font font) {
	// If we haven't already identified out font metrics file,
	// figure out which one to use and load it
	if (fontMetricsProps == null) {
	    try {
	        fontMetricsProps = loadMetrics();
	    } catch (IOException e) {
	        throw new RuntimeException("Could not load font metrics", e);
	    }
	}

	// Grab the base name of the font they've asked about
	String fontName = font.getName();

	// Some fonts support plain/bold/italic/bolditalic variants
	// Others have different font instances for bold etc
	// (eg font.dialog.plain.* vs font.Californian FB Bold.*)
	String fontStyle = "";
	if (font.isPlain()) {
		fontStyle += "plain";
	}
	if (font.isBold()) {
		fontStyle += "bold";
	}
	if (font.isItalic()) {
		fontStyle += "italic";
	}

	// Do we have a definition for this font with just the name?
	// If not, check with the font style added
	String fontHeight = FontDetails.buildFontHeightProperty(fontName);
	String styleHeight = FontDetails.buildFontHeightProperty(fontName + "." + fontStyle);
	
	if (fontMetricsProps.get(fontHeight) == null
		&& fontMetricsProps.get(styleHeight) != null) {
		// Need to add on the style to the font name
		fontName += "." + fontStyle;
	}

	// Get the details on this font
	FontDetails fontDetails = fontDetailsMap.get(fontName);
	if (fontDetails == null) {
		fontDetails = FontDetails.create(fontName, fontMetricsProps);
		fontDetailsMap.put(fontName, fontDetails);
	}
       return fontDetails;
}
 
Example 4
public static PDType1Font getPDFont(Font javaFont) {
	switch (javaFont.getFamily()) {
		case Font.SERIF:
			if (javaFont.isPlain()) {
				return PDType1Font.TIMES_ROMAN;
			} else if (javaFont.isBold()) {
				if (javaFont.isItalic()) {
					return PDType1Font.TIMES_BOLD_ITALIC;
				} else {
					return PDType1Font.TIMES_BOLD;
				}
			} else {
				return PDType1Font.TIMES_ITALIC;
			}
		case Font.SANS_SERIF:
			if (javaFont.isPlain()) {
				return PDType1Font.HELVETICA;
			} else if (javaFont.isBold()) {
				if (javaFont.isItalic()) {
					return PDType1Font.HELVETICA_BOLD_OBLIQUE;
				} else {
					return PDType1Font.HELVETICA_BOLD;
				}
			} else {
				return PDType1Font.HELVETICA_OBLIQUE;
			}
		case Font.MONOSPACED:
			if (javaFont.isPlain()) {
				return PDType1Font.COURIER;
			} else if (javaFont.isBold()) {
				if (javaFont.isItalic()) {
					return PDType1Font.COURIER_BOLD_OBLIQUE;
				} else {
					return PDType1Font.COURIER_BOLD;
				}
			} else {
				return PDType1Font.COURIER_OBLIQUE;
			}
		case Font.DIALOG:
		case Font.DIALOG_INPUT:
			return PDType1Font.SYMBOL;
		default:
			throw new DSSException("The font is not supported! Please use DSSFileFont implementation for custom fonts.");
		}
}