Java 类java.awt.font.TextAttribute 实例源码
项目:trashjam2017
文件:UnicodeFont.java
/**
* 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;
}
项目:incubator-netbeans
文件:LinkButton.java
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);
}
项目:incubator-netbeans
文件:AttributedCharacters.java
public Object getAttribute(AttributedCharacterIterator.Attribute att) {
if (att == TextAttribute.FONT) {
return fonts[getIndex()];
} else if (att == TextAttribute.FOREGROUND) {
return colors[getIndex()];
} else {
return null;
}
}
项目:incubator-netbeans
文件:AttributedCharacters.java
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;
}
项目:incubator-netbeans
文件:AttributedCharacters.java
public int getRunLimit(AttributedCharacterIterator.Attribute att) {
if ((att != TextAttribute.FONT) && (att != TextAttribute.FOREGROUND)) {
return getEndIndex(); // undefined attribute
}
return getRunLimit();
}
项目:incubator-netbeans
文件:AttributedCharacters.java
public int getRunLimit(Set<? extends AttributedCharacterIterator.Attribute> attributes) {
if (attributes.contains(TextAttribute.FONT) || attributes.contains(TextAttribute.FOREGROUND)) {
return getRunLimit();
} else {
return getEndIndex();
}
}
项目:incubator-netbeans
文件:AttributedCharacters.java
public int getRunStart(Set<? extends AttributedCharacterIterator.Attribute> attributes) {
if ((attributes.contains(TextAttribute.FONT)) || attributes.contains(TextAttribute.FOREGROUND)) {
return getRunStart();
} else {
return 0;
}
}
项目:incubator-netbeans
文件:ComponentLine.java
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);
}
项目:gate-core
文件:OptionsMap.java
/**
* 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;
}
}
项目:gate-core
文件:JFontChooser.java
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);
}
项目:openjdk-jdk10
文件:AttributeValues.java
@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;
}
项目:lams
文件:FontConverter.java
@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>
}
}
项目:BassNES
文件:NSFPlayer.java
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;
}
项目:BaseClient
文件:UnicodeFont.java
/**
* 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;
}
项目:pdfbox-graphics2d
文件:PdfBoxGraphics2DFontTextDrawer.java
@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();
}
项目:brModelo
文件:DesenhadorDeTexto.java
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;
}
项目:OpenJSharp
文件:ParagraphView.java
/**
* 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));
}
}
项目:OpenJSharp
文件:AbstractDocument.java
/**
* A convenience method for storing up a property value. It is
* equivalent to:
* <pre>
* getDocumentProperties().put(key, value);
* </pre>
* If <code>value</code> is <code>null</code> this method will
* remove the property.
*
* @param key the non-<code>null</code> key
* @param value the property value
* @see #getDocumentProperties
*/
public final void putProperty(Object key, Object value) {
if (value != null) {
getDocumentProperties().put(key, value);
} else {
getDocumentProperties().remove(key);
}
if( key == TextAttribute.RUN_DIRECTION
&& Boolean.TRUE.equals(getProperty(I18NProperty)) )
{
//REMIND - this needs to flip on the i18n property if run dir
//is rtl and the i18n property is not already on.
writeLock();
try {
DefaultDocumentEvent e
= new DefaultDocumentEvent(0, getLength(),
DocumentEvent.EventType.INSERT);
updateBidi( e );
} finally {
writeUnlock();
}
}
}
项目:openjdk-jdk10
文件:AttributeValues.java
@SuppressWarnings("unchecked")
public static AffineTransform getBaselineTransform(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.baselineTransform;
}
}
return null;
}
项目:openjdk-jdk10
文件:X11InputMethod.java
/**
* @see java.awt.Toolkit#mapInputMethodHighlight
*/
public static Map<TextAttribute, ?> mapInputMethodHighlight(InputMethodHighlight highlight) {
int index;
int state = highlight.getState();
if (state == InputMethodHighlight.RAW_TEXT) {
index = 0;
} else if (state == InputMethodHighlight.CONVERTED_TEXT) {
index = 2;
} else {
return null;
}
if (highlight.isSelected()) {
index += 1;
}
return highlightStyles[index];
}
项目:jdk8u-jdk
文件:AbstractDocument.java
/**
* A convenience method for storing up a property value. It is
* equivalent to:
* <pre>
* getDocumentProperties().put(key, value);
* </pre>
* If <code>value</code> is <code>null</code> this method will
* remove the property.
*
* @param key the non-<code>null</code> key
* @param value the property value
* @see #getDocumentProperties
*/
public final void putProperty(Object key, Object value) {
if (value != null) {
getDocumentProperties().put(key, value);
} else {
getDocumentProperties().remove(key);
}
if( key == TextAttribute.RUN_DIRECTION
&& Boolean.TRUE.equals(getProperty(I18NProperty)) )
{
//REMIND - this needs to flip on the i18n property if run dir
//is rtl and the i18n property is not already on.
writeLock();
try {
DefaultDocumentEvent e
= new DefaultDocumentEvent(0, getLength(),
DocumentEvent.EventType.INSERT);
updateBidi( e );
} finally {
writeUnlock();
}
}
}
项目:jdk8u-jdk
文件:Utilities.java
/**
* Draws the given composed text passed from an input method.
*
* @param view View hosting text
* @param attr the attributes containing the composed text
* @param g the graphics context
* @param x the X origin
* @param y the Y origin
* @param p0 starting offset in the composed text to be rendered
* @param p1 ending offset in the composed text to be rendered
* @return the new insertion position
*/
static int drawComposedText(View view, AttributeSet attr, Graphics g,
int x, int y, int p0, int p1)
throws BadLocationException {
Graphics2D g2d = (Graphics2D)g;
AttributedString as = (AttributedString)attr.getAttribute(
StyleConstants.ComposedTextAttribute);
as.addAttribute(TextAttribute.FONT, g.getFont());
if (p0 >= p1)
return x;
AttributedCharacterIterator aci = as.getIterator(null, p0, p1);
return x + (int)SwingUtilities2.drawString(
getJComponent(view), g2d,aci,x,y);
}
项目:jdk8u-jdk
文件:KerningLeak.java
private static void leak() {
Map<TextAttribute, Object> textAttributes = new HashMap<>();
textAttributes.put(TextAttribute.FAMILY, "Sans Serif");
textAttributes.put(TextAttribute.SIZE, 12);
textAttributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
Font font = Font.getFont(textAttributes);
JLabel label = new JLabel();
int dummy = 0;
for (int i = 0; i < 500; i++) {
if (i % 10 == 0) System.out.println("Starting iter " + (i+1));
for (int j = 0; j <1000; j++) {
FontMetrics fm = label.getFontMetrics(font);
dummy += SwingUtilities.computeStringWidth(fm, Integer.toString(j));
}
}
System.out.println("done " + dummy);
}
项目:incubator-netbeans
文件:AttributedCharacters.java
public Set<AttributedCharacterIterator.Attribute> getAllAttributeKeys() {
if (singleton == null) {
Set<AttributedCharacterIterator.Attribute> l = new HashSet<AttributedCharacterIterator.Attribute>(4);
l.add(TextAttribute.FONT);
l.add(TextAttribute.FOREGROUND);
singleton = Collections.unmodifiableSet(l);
}
return singleton;
}
项目:incubator-netbeans
文件:AttributedCharacters.java
public int getRunStart(AttributedCharacterIterator.Attribute att) {
if ((att != TextAttribute.FONT) && (att != TextAttribute.FOREGROUND)) {
return 0; // undefined attribute
}
return getRunStart();
}
项目:incubator-netbeans
文件:XMLCompletionResultItemPaintComponent.java
protected void drawStringToGraphics(Graphics g, String s, Font font, boolean strike) {
if (g != null) {
if (!strike){
g.drawString(s, drawX, drawY);
}else{
Graphics2D g2 = ((Graphics2D)g);
AttributedString strikeText = new AttributedString(s);
strikeText.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
strikeText.addAttribute(TextAttribute.FONT, g.getFont());
g2.drawString(strikeText.getIterator(), drawX, drawY);
}
}
drawX += getWidth(s, font);
}
项目:openjdk-jdk10
文件:AttributeValues.java
public static float getJustification(Map<?, ?> map) {
if (map != null) {
if (map instanceof AttributeMap &&
((AttributeMap) map).getValues() != null) {
return ((AttributeMap)map).getValues().justification;
}
Object obj = map.get(TextAttribute.JUSTIFICATION);
if (obj != null && obj instanceof Number) {
return max(0, min(1, ((Number)obj).floatValue()));
}
}
return DEFAULT.justification;
}
项目:openjdk-jdk10
文件:DefaultStyledDocument.java
/**
* Sets attributes for a paragraph.
* <p>
* This method is thread safe, although most Swing methods
* are not. Please see
* <A HREF="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html">Concurrency
* in Swing</A> for more information.
*
* @param offset the offset into the paragraph >= 0
* @param length the number of characters affected >= 0
* @param s the attributes
* @param replace whether to replace existing attributes, or merge them
*/
public void setParagraphAttributes(int offset, int length, AttributeSet s,
boolean replace) {
try {
writeLock();
DefaultDocumentEvent changes =
new DefaultDocumentEvent(offset, length, DocumentEvent.EventType.CHANGE);
AttributeSet sCopy = s.copyAttributes();
// PENDING(prinz) - this assumes a particular element structure
Element section = getDefaultRootElement();
int index0 = section.getElementIndex(offset);
int index1 = section.getElementIndex(offset + ((length > 0) ? length - 1 : 0));
boolean isI18N = Boolean.TRUE.equals(getProperty(I18NProperty));
boolean hasRuns = false;
for (int i = index0; i <= index1; i++) {
Element paragraph = section.getElement(i);
MutableAttributeSet attr = (MutableAttributeSet) paragraph.getAttributes();
changes.addEdit(new AttributeUndoableEdit(paragraph, sCopy, replace));
if (replace) {
attr.removeAttributes(attr);
}
attr.addAttributes(s);
if (isI18N && !hasRuns) {
hasRuns = (attr.getAttribute(TextAttribute.RUN_DIRECTION) != null);
}
}
if (hasRuns) {
updateBidi( changes );
}
changes.end();
fireChangedUpdate(changes);
fireUndoableEditUpdate(new UndoableEditEvent(this, changes));
} finally {
writeUnlock();
}
}
项目:Equella
文件:TermEditor.java
@Override
@SuppressWarnings("unchecked")
public void setup()
{
data = new JTextArea();
data.setLineWrap(true);
data.setWrapStyleWord(true);
Map<TextAttribute, Object> fas = (Map<TextAttribute, Object>) data.getFont().getAttributes();
fas.put(TextAttribute.FAMILY, Font.MONOSPACED);
data.setFont(new Font(fas));
setLayout(new GridLayout(1, 1));
add(new JScrollPane(data));
}
项目:Equella
文件:JCalendar.java
private JComponent createCentre()
{
dayGrid = new JPanel(new GridLayout(7, 7, 5, 5));
dayGrid.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
dayGrid.setBackground(Color.WHITE);
dayGrid.addMouseListener(this);
Map<TextAttribute, Float> dayAttributes = new HashMap<TextAttribute, Float>();
dayAttributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
Font dayFont = new Font(dayAttributes);
for( int i = 0; i < DAYS.length; i++ )
{
JLabel day = new JLabel(DAYS[i]);
day.setHorizontalAlignment(SwingConstants.CENTER);
day.setVerticalAlignment(SwingConstants.CENTER);
day.setFont(dayFont);
dayGrid.add(day);
}
days = new DayLabel[6][7];
for( int i = 0; i < days.length; i++ )
{
for( int j = 0; j < days[i].length; j++ )
{
days[i][j] = new DayLabel();
days[i][j].setDay(0);
dayGrid.add(days[i][j]);
}
}
return dayGrid;
}
项目:Equella
文件:JCalendar.java
private JComponent createNorth()
{
Map<TextAttribute, Float> fontAttributes = new HashMap<TextAttribute, Float>();
fontAttributes.put(TextAttribute.SIZE, 30f);
fontAttributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
dateDisplay = new JLabel();
dateDisplay.setVerticalAlignment(SwingConstants.BOTTOM);
dateDisplay.setFont(new Font(fontAttributes));
dateDisplay.setForeground(Color.BLUE);
months = new JComboBox(MONTHS);
years = new JComboBox();
for( int i = YEAR_START; i <= YEAR_END; i++ )
{
years.addItem(Integer.valueOf(i));
}
months.addActionListener(this);
years.addActionListener(this);
final int height1 = months.getPreferredSize().height;
final int width1 = months.getPreferredSize().width;
final int[] rows = {height1, height1};
final int[] cols = {TableLayout.FILL, width1};
JPanel all = new JPanel(new TableLayout(rows, cols, 5, 5));
all.add(dateDisplay, new Rectangle(0, 0, 1, 2));
all.add(months, new Rectangle(1, 0, 1, 1));
all.add(years, new Rectangle(1, 1, 1, 1));
return all;
}
项目:pdfbox-graphics2d
文件:PdfBoxGraphics2DFontTextDrawer.java
@Override
public boolean canDrawText(AttributedCharacterIterator iterator, IFontTextDrawerEnv env)
throws IOException, FontFormatException {
/*
* When no font is registered we can not display the text using a font...
*/
if (fontMap.size() == 0 && fontFiles.size() == 0 && !hasDynamicFontMapping())
return false;
boolean run = true;
StringBuilder sb = new StringBuilder();
while (run) {
Font attributeFont = (Font) iterator.getAttribute(TextAttribute.FONT);
if (attributeFont == null)
attributeFont = env.getFont();
if (mapFont(attributeFont, env) == null)
return false;
/*
* We can not do a Background on the text currently.
*/
if (iterator.getAttribute(TextAttribute.BACKGROUND) != null)
return false;
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));
if (isStrikeThrough || isUnderline || isLigatures)
return false;
run = iterateRun(iterator, sb);
String s = sb.toString();
int l = s.length();
for (int i = 0; i < l;) {
int codePoint = s.codePointAt(i);
switch (Character.getDirectionality(codePoint)) {
/*
* We can handle normal LTR.
*/
case Character.DIRECTIONALITY_LEFT_TO_RIGHT:
case Character.DIRECTIONALITY_EUROPEAN_NUMBER:
case Character.DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR:
case Character.DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR:
case Character.DIRECTIONALITY_WHITESPACE:
case Character.DIRECTIONALITY_COMMON_NUMBER_SEPARATOR:
case Character.DIRECTIONALITY_NONSPACING_MARK:
case Character.DIRECTIONALITY_BOUNDARY_NEUTRAL:
case Character.DIRECTIONALITY_PARAGRAPH_SEPARATOR:
case Character.DIRECTIONALITY_SEGMENT_SEPARATOR:
case Character.DIRECTIONALITY_OTHER_NEUTRALS:
case Character.DIRECTIONALITY_ARABIC_NUMBER:
break;
case Character.DIRECTIONALITY_RIGHT_TO_LEFT:
case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC:
case Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING:
case Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE:
case Character.DIRECTIONALITY_POP_DIRECTIONAL_FORMAT:
/*
* We can not handle this
*/
return false;
default:
/*
* Default: We can not handle this
*/
return false;
}
if (!attributeFont.canDisplay(codePoint))
return false;
i += Character.charCount(codePoint);
}
}
return true;
}
项目:OpenJSharp
文件:CodePointInputMethod.java
/**
* Send the composed text to the client.
*/
private void sendComposedText() {
AttributedString as = new AttributedString(buffer.toString());
as.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT,
InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT);
context.dispatchInputMethodEvent(
InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
as.getIterator(), 0,
TextHitInfo.leading(insertionPoint), null);
}
项目:openjdk-jdk10
文件:AttributeValues.java
public Map<TextAttribute, Object> toMap(Map<TextAttribute, Object> fill) {
if (fill == null) {
fill = new HashMap<TextAttribute, Object>();
}
for (int m = defined, i = 0; m != 0; ++i) {
EAttribute ea = EAttribute.atts[i];
if ((m & ea.mask) != 0) {
m &= ~ea.mask;
fill.put(ea.att, get(ea));
}
}
return fill;
}
项目:OpenJSharp
文件:Font.java
/**
* Returns the keys of all the attributes supported by this
* <code>Font</code>. These attributes can be used to derive other
* fonts.
* @return an array containing the keys of all the attributes
* supported by this <code>Font</code>.
* @since 1.2
*/
public Attribute[] getAvailableAttributes() {
// FONT is not supported by Font
Attribute attributes[] = {
TextAttribute.FAMILY,
TextAttribute.WEIGHT,
TextAttribute.WIDTH,
TextAttribute.POSTURE,
TextAttribute.SIZE,
TextAttribute.TRANSFORM,
TextAttribute.SUPERSCRIPT,
TextAttribute.CHAR_REPLACEMENT,
TextAttribute.FOREGROUND,
TextAttribute.BACKGROUND,
TextAttribute.UNDERLINE,
TextAttribute.STRIKETHROUGH,
TextAttribute.RUN_DIRECTION,
TextAttribute.BIDI_EMBEDDING,
TextAttribute.JUSTIFICATION,
TextAttribute.INPUT_METHOD_HIGHLIGHT,
TextAttribute.INPUT_METHOD_UNDERLINE,
TextAttribute.SWAP_COLORS,
TextAttribute.NUMERIC_SHAPING,
TextAttribute.KERNING,
TextAttribute.LIGATURES,
TextAttribute.TRACKING,
};
return attributes;
}
项目:OpenJSharp
文件:AttributeMap.java
private Map<TextAttribute, Object> delegate() {
if (delegateMap == null) {
if (first) {
first = false;
Thread.dumpStack();
}
delegateMap = values.toMap(new HashMap<TextAttribute, Object>(27));
// nuke values, once map is accessible it might be mutated and values would
// no longer reflect its contents
values = null;
}
return delegateMap;
}
项目:OpenJSharp
文件:AttributeValues.java
public Map<TextAttribute, Object> toMap(Map<TextAttribute, Object> fill) {
if (fill == null) {
fill = new HashMap<TextAttribute, Object>();
}
for (int m = defined, i = 0; m != 0; ++i) {
EAttribute ea = EAttribute.atts[i];
if ((m & ea.mask) != 0) {
m &= ~ea.mask;
fill.put(ea.att, get(ea));
}
}
return fill;
}
项目:OpenJSharp
文件:AttributeValues.java
private Object i_get(EAttribute a) {
switch (a) {
case EFAMILY: return family;
case EWEIGHT: return Float.valueOf(weight);
case EWIDTH: return Float.valueOf(width);
case EPOSTURE: return Float.valueOf(posture);
case ESIZE: return Float.valueOf(size);
case ETRANSFORM:
return transform == null
? TransformAttribute.IDENTITY
: new TransformAttribute(transform);
case ESUPERSCRIPT: return Integer.valueOf(superscript);
case EFONT: return font;
case ECHAR_REPLACEMENT: return charReplacement;
case EFOREGROUND: return foreground;
case EBACKGROUND: return background;
case EUNDERLINE: return Integer.valueOf(underline);
case ESTRIKETHROUGH: return Boolean.valueOf(strikethrough);
case ERUN_DIRECTION: {
switch (runDirection) {
// todo: figure out a way to indicate this value
// case -1: return Integer.valueOf(runDirection);
case 0: return TextAttribute.RUN_DIRECTION_LTR;
case 1: return TextAttribute.RUN_DIRECTION_RTL;
default: return null;
}
} // not reachable
case EBIDI_EMBEDDING: return Integer.valueOf(bidiEmbedding);
case EJUSTIFICATION: return Float.valueOf(justification);
case EINPUT_METHOD_HIGHLIGHT: return imHighlight;
case EINPUT_METHOD_UNDERLINE: return Integer.valueOf(imUnderline);
case ESWAP_COLORS: return Boolean.valueOf(swapColors);
case ENUMERIC_SHAPING: return numericShaping;
case EKERNING: return Integer.valueOf(kerning);
case ELIGATURES: return Integer.valueOf(ligatures);
case ETRACKING: return Float.valueOf(tracking);
default: throw new InternalError();
}
}
项目:OpenJSharp
文件:AttributeValues.java
public static NumericShaper getNumericShaping(Map<?, ?> map) {
if (map != null) {
if (map instanceof AttributeMap &&
((AttributeMap) map).getValues() != null) {
return ((AttributeMap)map).getValues().numericShaping;
}
Object obj = map.get(TextAttribute.NUMERIC_SHAPING);
if (obj != null && obj instanceof NumericShaper) {
return (NumericShaper)obj;
}
}
return DEFAULT.numericShaping;
}
项目:OpenJSharp
文件:AttributeValues.java
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;
}