private void _applyFontStyleForSelection(Font font) { StyledDocument doc = mTextEditor.getStyledDocument(); MutableAttributeSet attrs = mTextEditor.getInputAttributes(); StyleConstants.setFontFamily(attrs, font.getFamily()); StyleConstants.setFontSize(attrs, font.getSize()); StyleConstants.setBold(attrs, ((font.getStyle() & Font.BOLD) != 0)); StyleConstants.setItalic(attrs, ((font.getStyle() & Font.ITALIC) != 0)); StyleConstants.setUnderline(attrs, ((font.getStyle() & Font.CENTER_BASELINE) != 0)); int start = mTextEditor.getSelectionStart(); int end = mTextEditor.getSelectionEnd(); doc.setCharacterAttributes(start, (end - start), attrs, false); }
public void adjustFont(int w, int h) { if (h <= 0) return; int oldH = rHeight; if (font == null) { font = getFont(); fontH = font.getSize(); rHeight = fontH; } nHeight = h; if (fontH >= h) rHeight = h - 2; else rHeight = fontH; if ((rHeight < 10) && (fontH > 10)) rHeight = 10; if (oldH != rHeight) { // Font curFont = font.deriveFont((float) rHeight); Font curFont = DisplayOptions.getFont(font.getName(), font.getStyle(), rHeight); setFont(curFont); } if (rHeight > h) rHeight = h; }