本文整理汇总了Java中java.awt.font.TextAttribute类的典型用法代码示例。如果您正苦于以下问题:Java TextAttribute类的具体用法?Java TextAttribute怎么用?Java TextAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextAttribute类属于java.awt.font包,在下文中一共展示了TextAttribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeFont
import java.awt.font.TextAttribute; //导入依赖的package包/类
/**
* Initialise the font to be used based on configuration
*
* @param baseFont The AWT font to render
* @param size The point size of the font to generated
* @param bold True if the font should be rendered in bold typeface
* @param italic True if the font should be rendered in bold typeface
*/
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 (Exception ignored) {
}
font = baseFont.deriveFont(attributes);
FontMetrics metrics = GlyphPage.getScratchGraphics().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;
}
示例2: init
import java.awt.font.TextAttribute; //导入依赖的package包/类
private void init(Action al) {
setOpaque(false);
setBorder(BorderFactory.createEmptyBorder());
setBorderPainted(false);
setFocusPainted(false);
setFocusable(false);
setContentAreaFilled(false);
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
setModel(new Model());
if (null != al) {
addActionListener(al);
setForeground(ColorManager.getDefault().getLinkColor());
} else {
setEnabled(false);
setForeground(ColorManager.getDefault().getDisabledColor());
}
Font font = UIManager.getFont("Tree.font");//NOI18N
if (underlined) {
Map<TextAttribute, Object> map = new HashMap<TextAttribute, Object>();
map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
font = font.deriveFont(map);
}
setFont(font);
}
示例3: getAttribute
import java.awt.font.TextAttribute; //导入依赖的package包/类
public Object getAttribute(AttributedCharacterIterator.Attribute att) {
if (att == TextAttribute.FONT) {
return fonts[getIndex()];
} else if (att == TextAttribute.FOREGROUND) {
return colors[getIndex()];
} else {
return null;
}
}
示例4: getAttributes
import java.awt.font.TextAttribute; //导入依赖的package包/类
public Map<AttributedCharacterIterator.Attribute,Object> getAttributes() {
Map<AttributedCharacterIterator.Attribute,Object> m = new HashMap<AttributedCharacterIterator.Attribute,Object>(1);
m.put(TextAttribute.FONT, fonts[getIndex()]);
m.put(TextAttribute.FOREGROUND, colors[getIndex()]);
return m;
}
示例5: getRunLimit
import java.awt.font.TextAttribute; //导入依赖的package包/类
public int getRunLimit(AttributedCharacterIterator.Attribute att) {
if ((att != TextAttribute.FONT) && (att != TextAttribute.FOREGROUND)) {
return getEndIndex(); // undefined attribute
}
return getRunLimit();
}
示例6: getRunStart
import java.awt.font.TextAttribute; //导入依赖的package包/类
public int getRunStart(Set<? extends AttributedCharacterIterator.Attribute> attributes) {
if ((attributes.contains(TextAttribute.FONT)) || attributes.contains(TextAttribute.FOREGROUND)) {
return getRunStart();
} else {
return 0;
}
}
示例7: ComponentLine
import java.awt.font.TextAttribute; //导入依赖的package包/类
ComponentLine(AttributedCharacterIterator it, Font defaultFont, Color defaultColor) {
for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) {
Font font = (Font) it.getAttribute(TextAttribute.FONT);
Color color = (Color) it.getAttribute(TextAttribute.FOREGROUND);
mySymbols.add(new Symbol(c, createFont(font, defaultFont), createColor(color, defaultColor)));
}
checkSpaces(defaultFont, defaultColor);
}
示例8: getFont
import java.awt.font.TextAttribute; //导入依赖的package包/类
/**
* If the object stored under key is a Font then returns its value
* otherwise returns null.
* @param key key associated to the value to retrieve
* @return the associated font
*/
public Font getFont(Object key) {
try {
String stringValue = (String) get(key);
if (stringValue == null) { return null; }
StringTokenizer strTok = new StringTokenizer(stringValue, "#", false);
String family = strTok.nextToken();
int size = Integer.parseInt(strTok.nextToken());
boolean italic = Boolean.valueOf(strTok.nextToken());
boolean bold = Boolean.valueOf(strTok.nextToken());
HashMap<TextAttribute, Serializable> fontAttrs =
new HashMap<TextAttribute, Serializable>();
fontAttrs.put(TextAttribute.FAMILY, family);
fontAttrs.put(TextAttribute.SIZE, (float) size);
if(bold) fontAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
else fontAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR);
if(italic) fontAttrs.put(
TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
else fontAttrs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR);
return new Font(fontAttrs);
} catch (Exception e) {
return null;
}
}
示例9: updateFont
import java.awt.font.TextAttribute; //导入依赖的package包/类
protected void updateFont(){
Map<TextAttribute, Object> fontAttrs = new HashMap<TextAttribute, Object>();
fontAttrs.put(TextAttribute.FAMILY, familyCombo.getSelectedItem());
fontAttrs.put(TextAttribute.SIZE, new Float((String)sizeCombo.getSelectedItem()));
if(boldChk.isSelected())
fontAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
else fontAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR);
if(italicChk.isSelected())
fontAttrs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
else fontAttrs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR);
Font newFont = new Font(fontAttrs);
Font oldFont = fontValue;
fontValue = newFont;
sampleTextArea.setFont(newFont);
String text = sampleTextArea.getText();
sampleTextArea.setText("");
sampleTextArea.setText(text);
sampleTextArea.repaint(100);
firePropertyChange("fontValue", oldFont, newFont);
}
示例10: getCharTransform
import java.awt.font.TextAttribute; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static AffineTransform getCharTransform(Map<?, ?> map) {
if (map != null) {
AttributeValues av = null;
if (map instanceof AttributeMap &&
((AttributeMap) map).getValues() != null) {
av = ((AttributeMap)map).getValues();
} else if (map.get(TextAttribute.TRANSFORM) != null) {
av = AttributeValues.fromMap((Map<Attribute, ?>)map); // yuck
}
if (av != null) {
return av.charTransform;
}
}
return null;
}
示例11: marshal
import java.awt.font.TextAttribute; //导入依赖的package包/类
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final Font font = (Font)source;
final Map<TextAttribute, ?> attributes = font.getAttributes();
if (mapper != null) {
final String classAlias = mapper.aliasForSystemAttribute("class");
for (final Map.Entry<TextAttribute, ?> entry : attributes.entrySet()) {
final String name = textAttributeConverter.toString(entry.getKey());
final Object value = entry.getValue();
final 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>
}
}
示例12: NSFPlayer
import java.awt.font.TextAttribute; //导入依赖的package包/类
public NSFPlayer(int i){
super();
System.out.println("Making an NSF Player!");
Map<TextAttribute, Object> attributes = new HashMap<>();
attributes.put(TextAttribute.FAMILY, "Default");
attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_SEMIBOLD);
attributes.put(TextAttribute.SIZE, 14);
largefont = Font.getFont(attributes);
attributes.put(TextAttribute.FAMILY, "Default");
attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_SEMIBOLD);
attributes.put(TextAttribute.SIZE, 10);
smallfont = Font.getFont(attributes);
nsfemode = i==1;
}
示例13: drawText
import java.awt.font.TextAttribute; //导入依赖的package包/类
@Override
public void drawText(AttributedCharacterIterator iterator, IFontTextDrawerEnv env)
throws IOException, FontFormatException {
PDPageContentStream contentStream = env.getContentStream();
contentStream.beginText();
Matrix textMatrix = new Matrix();
textMatrix.scale(1, -1);
contentStream.setTextMatrix(textMatrix);
StringBuilder sb = new StringBuilder();
boolean run = true;
while (run) {
Font attributeFont = (Font) iterator.getAttribute(TextAttribute.FONT);
if (attributeFont == null)
attributeFont = env.getFont();
Number fontSize = ((Number) iterator.getAttribute(TextAttribute.SIZE));
if (fontSize != null)
attributeFont = attributeFont.deriveFont(fontSize.floatValue());
PDFont font = applyFont(attributeFont, env);
Paint paint = (Paint) iterator.getAttribute(TextAttribute.FOREGROUND);
if (paint == null)
paint = env.getPaint();
/*
* Apply the paint
*/
env.applyPaint(paint);
boolean isStrikeThrough = TextAttribute.STRIKETHROUGH_ON
.equals(iterator.getAttribute(TextAttribute.STRIKETHROUGH));
boolean isUnderline = TextAttribute.UNDERLINE_ON.equals(iterator.getAttribute(TextAttribute.UNDERLINE));
boolean isLigatures = TextAttribute.LIGATURES_ON.equals(iterator.getAttribute(TextAttribute.LIGATURES));
run = iterateRun(iterator, sb);
String text = sb.toString();
/*
* If we force the text write we may encounter situations where the font can not
* display the characters. PDFBox will throw an exception in this case. We will
* just silently ignore the text and not display it instead.
*/
try {
showTextOnStream(env, contentStream, attributeFont, font, isStrikeThrough, isUnderline, isLigatures,
text);
} catch (IllegalArgumentException e) {
if (font instanceof PDType1Font && !font.isEmbedded()) {
/*
* We tried to use a builtin default font, but it does not have the needed
* characters. So we use a embedded font as fallback.
*/
try {
if (fallbackFontUnknownEncodings == null)
fallbackFontUnknownEncodings = findFallbackFont(env);
if (fallbackFontUnknownEncodings != null) {
env.getContentStream().setFont(fallbackFontUnknownEncodings, attributeFont.getSize2D());
showTextOnStream(env, contentStream, attributeFont, fallbackFontUnknownEncodings,
isStrikeThrough, isUnderline, isLigatures, text);
e = null;
}
} catch (IllegalArgumentException ignored) {
e = ignored;
}
}
if (e != null)
System.err.println("PDFBoxGraphics: Can not map text " + text + " with font "
+ attributeFont.getFontName() + ": " + e.getMessage());
}
}
contentStream.endText();
}
示例14: getLineBreakMeasurers
import java.awt.font.TextAttribute; //导入依赖的package包/类
private LineBreakMeasurer[] getLineBreakMeasurers(Graphics2D g) {
if (lbmTexto == null && (Texto != null && !Texto.equals(""))) {
lbmTexto = new LineBreakMeasurer[Textos.length];
for (int i = 0; i < lbmTexto.length; i++) {
String tmp = Textos[i].isEmpty()? " " : Textos[i];
AttributedString attribString = new AttributedString(tmp);
attribString.addAttribute(TextAttribute.FONT, getFont());
//attribString.addAttribute(TextAttribute.FONT, getFont());
AttributedCharacterIterator attribCharIterator = attribString.getIterator();
//FontRenderContext frc = new FontRenderContext(null, true, false);
FontRenderContext frc = g.getFontRenderContext();
lbmTexto[i] = new LineBreakMeasurer(attribCharIterator, frc);
}
}
return lbmTexto;
}
示例15: setPropertiesFromAttributes
import java.awt.font.TextAttribute; //导入依赖的package包/类
/**
* Set the cached properties from the attributes.
*/
protected void setPropertiesFromAttributes() {
AttributeSet attr = getAttributes();
if (attr != null) {
setParagraphInsets(attr);
Integer a = (Integer)attr.getAttribute(StyleConstants.Alignment);
int alignment;
if (a == null) {
Document doc = getElement().getDocument();
Object o = doc.getProperty(TextAttribute.RUN_DIRECTION);
if ((o != null) && o.equals(TextAttribute.RUN_DIRECTION_RTL)) {
alignment = StyleConstants.ALIGN_RIGHT;
} else {
alignment = StyleConstants.ALIGN_LEFT;
}
} else {
alignment = a.intValue();
}
setJustification(alignment);
setLineSpacing(StyleConstants.getLineSpacing(attr));
setFirstLineIndent(StyleConstants.getFirstLineIndent(attr));
}
}