/** * Parses a font description in the format of <code>Arial,B,14</code>. * @param value A free text representation of a font in the format of <code>Arial,B,14</code>. * @return according SFont instance. Defaults to plain 12. */ public static SFont parseFont(String value) { StringTokenizer s = new StringTokenizer(value, ","); String fontName = s.nextToken(); String tmpFontType = s.nextToken().toUpperCase().trim(); int fontType = SFont.PLAIN; if (tmpFontType.startsWith("B")) fontType = SFont.BOLD; else if (tmpFontType.startsWith("I")) fontType = SFont.ITALIC; int fontSize = 12; try { fontSize = Integer.parseInt(s.nextToken()); } catch (Exception e) {} return new SFont(fontName, fontType, fontSize); }
/** * Append a inline CSS style definition for the passed component of the aspect font properties. * * @param styleString StringBuilder to append to * @param component Component to use as style source * @return The passed styleString */ public static StringBuilder appendCSSComponentInlineFontStyle(final StringBuilder styleString, final SComponent component) { if (component != null && component.getFont() != null) { final SFont font = component.getFont(); styleString.append("font-size:").append(font.getSize()).append("pt;"); styleString.append("font-style:").append((font.getStyle() & SFont.ITALIC) > 0 ? "italic;" : "normal;"); styleString.append("font-weight:").append((font.getStyle() & SFont.BOLD) > 0 ? "bold;" : "normal;"); styleString.append("font-family:").append(font.getFace()).append(";"); } return styleString; }
public SFont(String face, int style, int size) { setFace(face); this.style = style; this.size = size; }
private SFont createFont(String fontString, SFont defaultFont) { SFont actualDefaultFont; if (defaultFont != null) { actualDefaultFont = defaultFont; } else { actualDefaultFont = DEFAULT_FONT; } org.jspresso.framework.util.gui.Font font = FontHelper .fromString(fontString); int fontStyle; if (font.isBold() && font.isItalic()) { fontStyle = SFont.BOLD | SFont.ITALIC; } else if (font.isBold()) { fontStyle = SFont.BOLD; } else if (font.isItalic()) { fontStyle = SFont.ITALIC; } else { fontStyle = SFont.PLAIN; } if (font.getName() == null || font.getName().length() == 0) { font.setName(actualDefaultFont.getFace()); } if (font.getSize() < 0) { font.setSize(actualDefaultFont.getSize()); } return new SFont(font.getName(), fontStyle, font.getSize()); }
private int computePixelWidth(SComponent component, int characterLength) { int charLength = maxCharacterLength + 2; if (characterLength > 0 && characterLength < maxCharacterLength) { charLength = characterLength + 2; } int fontSize = 12; if (component.getFont() != null) { fontSize = component.getFont().getSize(); } return (int) ((fontSize * charLength) / 4.0); }
/** * {@inheritDoc} */ @Override protected int computePixelWidth(SComponent component, int characterLength) { int charLength = getMaxCharacterLength() + 2; if (characterLength > 0 && characterLength < getMaxCharacterLength()) { charLength = characterLength + 2; } int fontSize = DEFAULT_FONT.getSize(); if (fontSize == SFont.DEFAULT_SIZE) { fontSize = 12; } if (component.getFont() != null) { fontSize = component.getFont().getSize(); } return (int) ((fontSize * charLength) / 4.0); }
if ((styleValue != null) && (styleValue.toLowerCase().contains("italic"))) style |= Font.ITALIC; anyFontAttribute |= (styleValue != null); return anyFontAttribute ? new SFont(family, style, size) : null;
new SFont(viewDescriptor.getFont().getFontName(), viewDescriptor .getFont().getStyle(), viewDescriptor.getFont().getSize()));