Java Code Examples for javax.swing.text.StyleConstants#getFontSize()
The following examples show how to use
javax.swing.text.StyleConstants#getFontSize() .
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
Source File: BrowserDisplayer.java From netbeans with Apache License 2.0 | 6 votes |
/** * Gets the font from an attribute set. This is * implemented to try and fetch a cached font * for the given AttributeSet, and if that fails * the font features are resolved and the * font is fetched from the low-level font cache. * Font's are cached in the StyleSheet of a document * * @param attr the attribute set * @return the font */ private Font getAttributeSetFont(AttributeSet attr) { // PENDING(prinz) add cache behavior int style = Font.PLAIN; if (StyleConstants.isBold(attr)) { style |= Font.BOLD; } if (StyleConstants.isItalic(attr)) { style |= Font.ITALIC; } String family = StyleConstants.getFontFamily(attr); int size = StyleConstants.getFontSize(attr); /** * if either superscript or subscript is * is set, we need to reduce the font size * by 2. */ if (StyleConstants.isSuperscript(attr) || StyleConstants.isSubscript(attr)) { size -= 2; } // fonts are cached in the StyleSheet so use that return doc.getStyleSheet().getFont(family, style, size); }
Example 2
Source File: CSS.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Returns the size in points. This is ultimately * what we need for the purpose of creating/fetching * a Font object. * * @param a the attribute set the value is being * requested from. We may need to walk up the * resolve hierarchy if it's relative. */ int getValue(AttributeSet a, StyleSheet ss) { ss = getStyleSheet(ss); if (index) { // it's an index, translate from size table return Math.round(getPointSize((int) value, ss)); } else if (lu == null) { return Math.round(value); } else { if (lu.type == 0) { boolean isW3CLengthUnits = (ss == null) ? false : ss.isW3CLengthUnits(); return Math.round(lu.getValue(isW3CLengthUnits)); } if (a != null) { AttributeSet resolveParent = a.getResolveParent(); if (resolveParent != null) { int pValue = StyleConstants.getFontSize(resolveParent); float retValue; if (lu.type == 1 || lu.type == 3) { retValue = lu.value * (float)pValue; } else { retValue = lu.value + (float)pValue; } return Math.round(retValue); } } // a is null, or no resolve parent. return 12; } }
Example 3
Source File: XMLTextComponentHighlighter.java From pumpernickel with MIT License | 5 votes |
/** * Create a new JavaTextComponentHighlighter. * * @param jtc * the text component to apply formatting to. */ public XMLTextComponentHighlighter(JTextComponent jtc) { super(jtc); jtc.putClientProperty("caretWidth", new Integer(3)); jtc.getCaret().setBlinkRate(500); initializeAttributes(); Font defaultFont = new Font( StyleConstants.getFontFamily(defaultAttributes), 0, StyleConstants.getFontSize(defaultAttributes)); jtc.setFont(defaultFont); }
Example 4
Source File: JavaTextComponentHighlighter.java From pumpernickel with MIT License | 5 votes |
/** * Create a new JavaTextComponentHighlighter. * * @param jtc * the text component to apply formatting to. */ public JavaTextComponentHighlighter(JTextComponent jtc) { super(jtc); jtc.putClientProperty("caretWidth", new Integer(3)); jtc.getCaret().setBlinkRate(500); initializeAttributes(); Font defaultFont = new Font( StyleConstants.getFontFamily(defaultAttributes), 0, StyleConstants.getFontSize(defaultAttributes)); jtc.setFont(defaultFont); }
Example 5
Source File: FormattedTextHelper.java From PolyGlot with MIT License | 5 votes |
/** * Recursing method implementing functionality of storageFormat() * @param e element to be cycled through * @param pane top parent JTextPane * @return string format value of current node and its children * @throws BadLocationException if unable to create string format */ private static String storeFormatRecurse(Element e, JTextPane pane) throws Exception { String ret = ""; int ec = e.getElementCount(); if (ec == 0) { // if more media addable in the future, this is where to process it... // hard coded values because they're hard coded in Java. Eh. if (e.getAttributes().getAttribute("$ename") != null && e.getAttributes().getAttribute("$ename").equals("icon")) { if (e.getAttributes().getAttribute(PGTUtil.IMAGE_ID_ATTRIBUTE) == null) { throw new Exception("ID For image not stored. Unable to store section."); } ret += "<img src=\"" + e.getAttributes().getAttribute(PGTUtil.IMAGE_ID_ATTRIBUTE) + "\">"; } else { int start = e.getStartOffset(); int len = e.getEndOffset() - start; if (start < pane.getDocument().getLength()) { AttributeSet a = e.getAttributes(); String font = StyleConstants.getFontFamily(a); String fontColor = colorToText(StyleConstants.getForeground(a)); int fontSize = StyleConstants.getFontSize(a); ret += "<font face=\"" + font + "\"" + "size=\"" + fontSize + "\"" + "color=\"" + fontColor + "\"" + ">"; ret += pane.getDocument().getText(start, len); ret += "</font>"; } } } else { for (int i = 0; i < ec; i++) { ret += storeFormatRecurse(e.getElement(i), pane); } } return ret; }
Example 6
Source File: TextStyleChooser.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public boolean checkElement(StyledDocument doc, Element element, int offset) { if (bold != null) { if (StyleConstants.isBold(element.getAttributes()) != bold.booleanValue()) { return false; } } if (italic != null) { if (StyleConstants.isItalic(element.getAttributes()) != italic.booleanValue()) { return false; } } if (strike != null) { if (StyleConstants.isStrikeThrough(element.getAttributes()) != strike.booleanValue()) { return false; } } if (understrike != null) { if (StyleConstants.isUnderline(element.getAttributes()) != understrike.booleanValue()) { return false; } } if (fontSize != null) { if (StyleConstants.getFontSize(element.getAttributes()) != fontSize.intValue()) { return false; } } if (alignment != null) { if (StyleConstants.getAlignment(element.getAttributes()) != alignment.intValue()) { return false; } } if (fontFamily != null) { if (!StyleConstants.getFontFamily(element.getAttributes()).equals(fontFamily)) { return false; } } if (background != null) { if (!StyleConstants.getBackground(element.getAttributes()).equals(background)) { return false; } } if (foreground != null) { if (!StyleConstants.getForeground(element.getAttributes()).equals(foreground)) { return false; } } return true; }
Example 7
Source File: TextPaneAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public int getFontSize() { AttributeSet attrSet = (AttributeSet) attributes.get(Priority.INFO); return StyleConstants.getFontSize(attrSet); }