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

The following examples show how to use java.awt.Font#isBold() . 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
/**
 * Sets the font to be used for drawing text.
 * 
 * @param font  the font ({@code null} is permitted but ignored).
 * 
 * @see #getFont() 
 */
@Override
public void setFont(Font font) {
    if (font == null) {
        return;
    }
    this.font = font;
    FontWeight weight = font.isBold() ? FontWeight.BOLD : FontWeight.NORMAL;
    FontPosture posture = font.isItalic() 
            ? FontPosture.ITALIC : FontPosture.REGULAR;
    this.gc.setFont(javafx.scene.text.Font.font(font.getFamily(), 
            weight, posture, font.getSize()));
}
 
Example 2
Source Project: seaglass   File: SeaGlassBrowser.java    License: Apache License 2.0 6 votes vote down vote up
static void printFont(PrintWriter html, Font font) {
    String style = "";
    if (font.isBold() && font.isItalic()) {
        style = "Bold & Italic";
    } else if (font.isBold()) {
        style = "Bold";
    } else if (font.isItalic()) {
        style = "Italic";
    }
    html.println("<td>Font: " + font.getFamily() + " " + font.getSize() + " " + style + "</td>");
    int w = 300, h = 30;
    BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = img.createGraphics();
    Composite old = g2.getComposite();
    g2.setComposite(AlphaComposite.Clear);
    g2.fillRect(0, 0, w, h);
    g2.setComposite(old);
    g2.setColor(Color.BLACK);
    g2.setFont(font);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.drawString("The quick brown fox jumps over the lazy dog.", 5, 20);
    g2.dispose();
    html.println("<td>" + saveImage(img) + "</td>");
}
 
Example 3
public boolean handle(TextTag textTag, FontTag font, char character) {
    String fontName = font.getFontNameIntag();
    if (!FontTag.getInstalledFontsByFamily().containsKey(fontName)) {
        return false;
    }
    Map<String, Font> faces = FontTag.getInstalledFontsByFamily().get(fontName);

    Font f = null;
    for (String face : faces.keySet()) {
        Font ff = faces.get(face);
        if (ff.isBold() == font.isBold() && ff.isItalic() == font.isItalic()) {
            f = ff;
            break;
        }
    }
    if (f == null) {
        f = faces.get(faces.keySet().iterator().next());
    }
    if (!f.canDisplay(character)) {
        return false;
    }
    font.addCharacter(character, f);
    return true;
}
 
Example 4
/**
 * Sets the font to be used for drawing text.
 * 
 * @param font  the font ({@code null} is permitted but ignored).
 * 
 * @see #getFont() 
 */
@Override
public void setFont(Font font) {
    if (font == null) {
        return;
    }
    this.font = font;
    FontWeight weight = font.isBold() ? FontWeight.BOLD : FontWeight.NORMAL;
    FontPosture posture = font.isItalic() 
            ? FontPosture.ITALIC : FontPosture.REGULAR;
    this.gc.setFont(javafx.scene.text.Font.font(font.getFamily(), 
            weight, posture, font.getSize()));
}
 
Example 5
public JTextPaneTableCellRenderer() {
  textPane.setContentType("text/html");
  textPane.setEditable(false);
  textPane.setOpaque(true);
  textPane.setBorder(null);

  textPane.setForeground(UIManager.getColor("Table.selectionForeground"));
  textPane.setBackground(UIManager.getColor("Table.selectionBackground"));

  Font font = UIManager.getFont("Label.font");
  String bodyRule =
      "body { font-family: " + font.getFamily() + "; " + "font-size: "
          + font.getSize() + "pt; "
          + (font.isBold() ? "font-weight: bold;" : "") + "}";
  ((HTMLDocument)textPane.getDocument()).getStyleSheet().addRule(bodyRule);

  textPane.addHyperlinkListener(new HyperlinkListener() {

    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
          MainFrame.getInstance().showHelpFrame(e.getURL().toString(), "CREOLE Plugin Manager");
    }
  });
}
 
Example 6
/**
 * Sets the font to be used for drawing text.
 * 
 * @param font  the font ({@code null} is permitted but ignored).
 * 
 * @see #getFont() 
 */
@Override
public void setFont(Font font) {
    if (font == null) {
        return;
    }
    this.font = font;
    FontWeight weight = font.isBold() ? FontWeight.BOLD : FontWeight.NORMAL;
    FontPosture posture = font.isItalic() 
            ? FontPosture.ITALIC : FontPosture.REGULAR;
    this.gc.setFont(javafx.scene.text.Font.font(font.getFamily(), 
            weight, posture, font.getSize()));
}
 
Example 7
/**
 * Sets the font to be used for drawing text.
 * 
 * @param font  the font ({@code null} is permitted but ignored).
 * 
 * @see #getFont() 
 */
@Override
public void setFont(Font font) {
    if (font == null) {
        return;
    }
    this.font = font;
    FontWeight weight = font.isBold() ? FontWeight.BOLD : FontWeight.NORMAL;
    FontPosture posture = font.isItalic() 
            ? FontPosture.ITALIC : FontPosture.REGULAR;
    this.gc.setFont(javafx.scene.text.Font.font(font.getFamily(), 
            weight, posture, font.getSize()));
}
 
Example 8
Source Project: SIMVA-SoS   File: FXGraphics2D.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets the font to be used for drawing text.
 * 
 * @param font  the font ({@code null} is permitted but ignored).
 * 
 * @see #getFont() 
 */
@Override
public void setFont(Font font) {
    if (font == null) {
        return;
    }
    this.font = font;
    FontWeight weight = font.isBold() ? FontWeight.BOLD : FontWeight.NORMAL;
    FontPosture posture = font.isItalic() 
            ? FontPosture.ITALIC : FontPosture.REGULAR;
    this.gc.setFont(javafx.scene.text.Font.font(font.getFamily(), 
            weight, posture, font.getSize()));
}
 
Example 9
/**
 * Sets the font to be used for drawing text.
 * 
 * @param font  the font ({@code null} is permitted but ignored).
 * 
 * @see #getFont() 
 */
@Override
public void setFont(Font font) {
    if (font == null) {
        return;
    }
    this.font = font;
    FontWeight weight = font.isBold() ? FontWeight.BOLD : FontWeight.NORMAL;
    FontPosture posture = font.isItalic() 
            ? FontPosture.ITALIC : FontPosture.REGULAR;
    this.gc.setFont(javafx.scene.text.Font.font(font.getFamily(), 
            weight, posture, font.getSize()));
}
 
Example 10
Source Project: FlatLaf   File: UIDefaultsDump.java    License: Apache License 2.0 5 votes vote down vote up
private void dumpFont( PrintWriter out, Font font ) {
	String strStyle = font.isBold()
		? font.isItalic() ? "bolditalic" : "bold"
		: font.isItalic() ? "italic" : "plain";
	out.printf( "%s %s %d    %s",
		font.getName(), strStyle, font.getSize(),
		dumpClass( font ) );
}
 
Example 11
Source Project: RRDiagram   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static String convertFontToCss(Font font) {
  StringBuilder sb = new StringBuilder();
  sb.append("font-family:").append(font.getFamily()).append(",Sans-serif;");
  if(font.isItalic()) {
    sb.append("font-style:italic;");
  }
  if(font.isBold()) {
    sb.append("font-weight:bold;");
  }
  sb.append("font-size:" + font.getSize() + "px;");
  return sb.toString();
}
 
Example 12
private void updateFontButton(@Nonnull final JButton button, @Nonnull final Font font) {
  final String strStyle;
  if (font.isBold()) {
    strStyle = font.isItalic() ? "bolditalic" : "bold"; //NOI18N
  } else {
    strStyle = font.isItalic() ? "italic" : "plain"; //NOI18N
  }

  button.setText(font.getName() + ", " + strStyle + ", " + font.getSize()); //NOI18N
}
 
Example 13
Source Project: netbeans   File: Editor.java    License: Apache License 2.0 5 votes vote down vote up
private String getString(Font font) {
    String style = ""; // NOI18N

    if (font.isBold()) {
        style += "bold"; // NOI18N
    }
    if (font.isItalic()) {
        style += " italic"; // NOI18N
    }
    else {
        style += " plain"; // NOI18N
    }
    return "[" + font.getName() + ", " + style + ", " + font.getSize() + "]"; // NOI18N
}
 
Example 14
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    Component res = orig.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    if (value instanceof ReferedExternalStyleSheetItem) {
        if (res instanceof JLabel) {
            Font font = res.getFont();
            if (!font.isBold()) {
                res.setFont(font.deriveFont(Font.BOLD));
            }
        }
    }
    return res;
}
 
Example 15
/**
 * Converts the value to string using {@link Strings#toString(Object)}
 * method and then stores it.
 * There is get methods for values that are a String, an Integer, a Boolean,
 * a Font, a List of String and a Map of String*String.
 */
@Override
public Object put(Object key, Object value) {
  if(value instanceof Font){
    Font font = (Font)value;
    String family = font.getFamily();
    int size = font.getSize();
    boolean italic = font.isItalic();
    boolean bold = font.isBold();
    value = family + "#" + size + "#" + italic + "#" + bold;
  }
  return super.put(key.toString(), Strings.toString(value));
}
 
Example 16
private String getFontStyle(final Font font) {
    if (font.isBold() && font.isItalic()) {
        return "bold-italic";
    }
    if (font.isBold()) {
        return "bold";
    }
    if (font.isItalic()) {
        return "italic";
    }
    return "plain";
}
 
Example 17
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 18
Source Project: netbeans   File: HtmlPrintContainer.java    License: Apache License 2.0 4 votes vote down vote up
private String createStyle (String element, String selector, Font font, Color fg, Color bg, boolean useDefaults) {
    StringBuffer sb = new StringBuffer();
    if (element != null) {
        sb.append (element);
        sb.append (WS);
    }

    if (selector != null) {
        sb.append (DOT);
        sb.append (selector);
        sb.append (WS);
    }

    sb.append (ST_BEGIN);
    boolean first = true;
    if ((!useDefaults || !fg.equals(getDefaultColor())) && fg != null) {
        sb.append (ST_COLOR);
        sb.append (getHtmlColor(fg));
        first = false;
    }

    if ((!useDefaults || !bg.equals (getDefaultBackgroundColor())) && bg != null) {
        if (!first) {
            sb.append (ST_SEPARATOR);
        }
        sb.append (ST_BGCOLOR);
        sb.append (getHtmlColor(bg));
        first = false;
    }

    if ((!useDefaults || !font.equals (getDefaultFont())) && font != null) {
        if (!first) {
            sb.append (ST_SEPARATOR);
        }
        sb.append (ST_FONT_FAMILY);
        switch(font.getFamily()) {
            case Font.MONOSPACED:
                sb.append (FF_MONOSPACE);
                break;
            case Font.SERIF:
                sb.append (FF_SERIF);
                break;
            case Font.SANS_SERIF:
                sb.append (FF_SANSSERIF);
                break;
            case Font.DIALOG:
                sb.append (FF_SANSSERIF);
                break;
            case Font.DIALOG_INPUT:
                sb.append (FF_MONOSPACE);
                break;
            default:
                sb.append (font.getFamily()); //TODO: Locale should go here
        }
        if (font.isBold()) {
            sb.append (ST_SEPARATOR);
            sb.append (ST_BOLD);
        }
        if (font.isItalic()) {
            sb.append (ST_SEPARATOR);
            sb.append (ST_ITALIC);
        }
        Font df = getDefaultFont();
        if (df != null && df.getSize() != font.getSize()) {
            sb.append (ST_SEPARATOR);
            sb.append (ST_SIZE);
            sb.append (String.valueOf(font.getSize()));
        }

    }
    sb.append (ST_END);
    return sb.toString();
}
 
Example 19
/**
 * 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 20
Source Project: gcs   File: DefaultFontMapper.java    License: Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Returns a BaseFont which can be used to represent the given AWT Font
 *
 * @param font the font to be converted
 * @return a BaseFont which has similar properties to the provided Font
 */

@Override
public BaseFont awtToPdf(Font font) {
	try {
		BaseFontParameters p = getBaseFontParameters(font.getFontName());
		if (p != null) {
			return BaseFont.createFont(p.fontName, p.encoding, p.embedded, p.cached, p.ttfAfm, p.pfb);
		}
		String fontKey = null;
		String logicalName = font.getName();

		if (logicalName.equalsIgnoreCase("DialogInput") || logicalName.equalsIgnoreCase("Monospaced") || logicalName.equalsIgnoreCase("Courier")) {

			if (font.isItalic()) {
				if (font.isBold()) {
					fontKey = BaseFont.COURIER_BOLDOBLIQUE;

				} else {
					fontKey = BaseFont.COURIER_OBLIQUE;
				}

			} else {
				if (font.isBold()) {
					fontKey = BaseFont.COURIER_BOLD;

				} else {
					fontKey = BaseFont.COURIER;
				}
			}

		} else if (logicalName.equalsIgnoreCase("Serif") || logicalName.equalsIgnoreCase("TimesRoman")) {

			if (font.isItalic()) {
				if (font.isBold()) {
					fontKey = BaseFont.TIMES_BOLDITALIC;

				} else {
					fontKey = BaseFont.TIMES_ITALIC;
				}

			} else {
				if (font.isBold()) {
					fontKey = BaseFont.TIMES_BOLD;

				} else {
					fontKey = BaseFont.TIMES_ROMAN;
				}
			}

		} else {  // default, this catches Dialog and SansSerif

			if (font.isItalic()) {
				if (font.isBold()) {
					fontKey = BaseFont.HELVETICA_BOLDOBLIQUE;

				} else {
					fontKey = BaseFont.HELVETICA_OBLIQUE;
				}

			} else {
				if (font.isBold()) {
					fontKey = BaseFont.HELVETICA_BOLD;
				} else {
					fontKey = BaseFont.HELVETICA;
				}
			}
		}
		return BaseFont.createFont(fontKey, BaseFont.CP1252, false);
	} catch (Exception e) {
		throw new ExceptionConverter(e);
	}
}