1 42 43 package org.jfree.xml.writer.coretypes; 44 45 import java.awt.Font ; 46 import java.io.IOException ; 47 48 import org.jfree.xml.writer.AbstractXmlWriteHandler; 49 import org.jfree.xml.writer.AttributeList; 50 import org.jfree.xml.writer.XMLWriter; 51 import org.jfree.xml.writer.XMLWriterException; 52 53 56 public class FontWriteHandler extends AbstractXmlWriteHandler { 57 58 61 public FontWriteHandler() { 62 super(); 63 } 64 65 77 public void write(final String tagName, final Object object, final XMLWriter writer, 78 final String mPlexAttribute, final String mPlexValue) 79 throws IOException , XMLWriterException { 80 final Font font = (Font ) object; 81 final AttributeList attribs = new AttributeList(); 82 if (mPlexAttribute != null) { 83 attribs.setAttribute(mPlexAttribute, mPlexValue); 84 } 85 attribs.setAttribute("family", font.getFamily()); 86 attribs.setAttribute("size", String.valueOf(font.getSize())); 87 attribs.setAttribute("style", String.valueOf(getFontStyle(font))); 88 writer.writeTag(tagName, attribs, true); 89 } 90 91 private String getFontStyle(final Font font) { 92 if (font.isBold() && font.isItalic()) { 93 return "bold-italic"; 94 } 95 if (font.isBold()) { 96 return "bold"; 97 } 98 if (font.isItalic()) { 99 return "italic"; 100 } 101 return "plain"; 102 } 103 104 } 105 | Popular Tags |