Font font = new Font("helvetica", Font.PLAIN, 12); Map attributes = font.getAttributes(); attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); Font newFont = new Font(attributes);
JLabel label = new JLabel("Underlined Label"); Font font = label.getFont(); Map attributes = font.getAttributes(); attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); label.setFont(font.deriveFont(attributes));
JLabel label = new JLabel("Underlined Label"); Font font = label.getFont(); Map attributes = font.getAttributes(); attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); label.setFont(font.deriveFont(attributes));
private void initializeFont (Font baseFont, int size, boolean bold, boolean italic) { Map attributes = baseFont.getAttributes(); attributes.put(TextAttribute.SIZE, new Float(size)); attributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR); attributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR); try { attributes.put(TextAttribute.class.getDeclaredField("KERNING").get(null), TextAttribute.class.getDeclaredField("KERNING_ON").get(null)); } catch (Throwable ignored) { } font = baseFont.deriveFont(attributes); metrics = GlyphPage.scratchGraphics.getFontMetrics(font); ascent = metrics.getAscent(); descent = metrics.getDescent(); leading = metrics.getLeading(); // Determine width of space glyph (getGlyphPixelBounds gives a width of zero). char[] chars = " ".toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); spaceWidth = vector.getGlyphLogicalBounds(0).getBounds().width; }
private void initializeFont (Font baseFont, int size, boolean bold, boolean italic) { Map attributes = baseFont.getAttributes(); attributes.put(TextAttribute.SIZE, new Float(size)); attributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR); attributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR); try { attributes.put(TextAttribute.class.getDeclaredField("KERNING").get(null), TextAttribute.class.getDeclaredField("KERNING_ON").get(null)); } catch (Throwable ignored) { } font = baseFont.deriveFont(attributes); metrics = GlyphPage.scratchGraphics.getFontMetrics(font); ascent = metrics.getAscent(); descent = metrics.getDescent(); leading = metrics.getLeading(); // Determine width of space glyph (getGlyphPixelBounds gives a width of zero). char[] chars = " ".toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); spaceWidth = vector.getGlyphLogicalBounds(0).getBounds().width; }
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Font font = (Font)source; Map attributes = font.getAttributes(); if (mapper != null) { String classAlias = mapper.aliasForSystemAttribute("class"); for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry)iter.next(); String name = textAttributeConverter.toString(entry.getKey()); Object value = entry.getValue(); Class type = value != null ? value.getClass() : Mapper.Null.class; ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, type); writer.addAttribute(classAlias, mapper.serializedClass(type)); if (value != null) { context.convertAnother(value); } writer.endNode(); } } else { writer.startNode("attributes"); // <attributes> context.convertAnother(attributes); writer.endNode(); // </attributes> } }
public Key(int width, int height, String text, Font font, Color color, int glowSize, float glowIntensity, Color glowColor, boolean wrap) { this.width = width; this.height = height; this.text = text; this.originalFont = new WeakReference<>(font); this.fontAttributes = font.getAttributes(); this.color = color; this.glowSize = glowSize; this.glowIntensity = glowIntensity; this.glowColor = glowColor; this.wrap = wrap; }
private Map<Attribute, Object> textAttributes() { Map<Attribute, Object> attributes = new HashMap<Attribute, Object>(); attributes.putAll(label.getFont().getAttributes()); attributes.put(TextAttribute.FONT, font()); return attributes; }
/** * Radio is selectable/hoverable if it is not already selected (bold). * @return True if radio is not already selected */ protected boolean isActivable() { return !AbstractRadioLink.this.getFont().getAttributes().containsValue(TextAttribute.WEIGHT_BOLD); }
/** * Change font of radio label to underline. */ public final void setUnderlined() { Font font = this.getFont(); Map<TextAttribute, Object> attributes = new HashMap<>(font.getAttributes()); attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DOTTED); attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); this.setFont(font.deriveFont(attributes)); }
/** * Change font of radio label to default. */ public void removeFont() { Font font = this.getFont(); Map<TextAttribute, Object> attributes = new HashMap<>(font.getAttributes()); attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DOTTED); this.setFont(font.deriveFont(attributes)); }
@Override public void mouseEntered(MouseEvent e) { super.mouseEntered(e); AbstractRadioLink radio = (AbstractRadioLink) e.getComponent(); this.original = e.getComponent().getFont(); if (radio.isActivable()) { Font font = radio.getFont(); Map<TextAttribute, Object> attributes = new HashMap<>(font.getAttributes()); attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); radio.setFont(font.deriveFont(attributes)); radio.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } }
AffineTransform[] transforms = new AffineTransform[numGlyphs]; final Font font = component.getGlyphVector().getFont(); Number tracking = (Number) font.getAttributes().get(TextAttribute.TRACKING); for (int i = 0; i < numGlyphs; i++) { outlines[i] = glyphVector.getGlyphOutline(i);
@SuppressWarnings("unchecked") public static Font strikeThrough(final Font font) { @SuppressWarnings("rawtypes") final Map attributes = font.getAttributes(); attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); Font newFont = new Font(attributes); return newFont; }
public void testKerningOffByDefault() throws Exception { TextSymbolizer ts = sf.createTextSymbolizer(); ts.setFill(sf.createFill(null)); Font font = sf.createFont( ff.literal("Serif"), ff.literal("italic"), ff.literal("bold"), ff.literal(20)); ts.setFont(font); ts.getOptions().put(TextSymbolizer.KERNING_KEY, "false"); TextStyle2D tsd = (TextStyle2D) sld.createTextStyle(feature, ts, range); assertEquals(20, tsd.getFont().getSize()); Map<TextAttribute, ?> attributes = tsd.getFont().getAttributes(); Object kerningValue = attributes.get(TextAttribute.KERNING); assertNull(kerningValue); }
public void testKerningOnByDefault() throws Exception { TextSymbolizer ts = sf.createTextSymbolizer(); ts.setFill(sf.createFill(null)); Font font = sf.createFont( ff.literal("Serif"), ff.literal("italic"), ff.literal("bold"), ff.literal(20)); ts.setFont(font); TextStyle2D tsd = (TextStyle2D) sld.createTextStyle(feature, ts, range); assertEquals(20, tsd.getFont().getSize()); Map<TextAttribute, ?> attributes = tsd.getFont().getAttributes(); Object kerningValue = attributes.get(TextAttribute.KERNING); assertEquals(TextAttribute.KERNING_ON, kerningValue); }
/** * @param font * The font to set. */ public synchronized void setFont(Font font) { fontAttributes = new HashMap<>(font.getAttributes()); invalidate(); }
/** * @param font * The font to set. */ public synchronized void setFont(Font font) { fontAttributes = new HashMap<>(font.getAttributes()); invalidate(); }
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Font font = (Font) source; Map attributes = font.getAttributes(); writer.startNode("attributes"); // <attributes> context.convertAnother(attributes); writer.endNode(); // </attributes> }
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Font font = (Font) source; Map attributes = font.getAttributes(); writer.startNode("attributes"); // <attributes> context.convertAnother(attributes); writer.endNode(); // </attributes> }