kz.greetgo.msoffice.docx.FontTableContentElement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of greetgo.msoffice Show documentation
Show all versions of greetgo.msoffice Show documentation
greetgo library to generate or parse MS Office files
package kz.greetgo.msoffice.docx;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class FontTableContentElement implements ContentElement {
private final String partName;
private FontTableContentElement(String partName) {
this.partName = partName;
assert partName != null;
}
public static FontTableContentElement createDefault(String partName) {
FontTableContentElement ret = new FontTableContentElement(partName);
ret.initDefault();
return ret;
}
public static class FontElement implements XmlWriter {
private final String name;
private List xmlContent = new ArrayList();
private Font font = null;
public FontElement(String name, Iterator xmlContentIterator) {
this.name = name;
while (xmlContentIterator.hasNext()) {
xmlContent.add(xmlContentIterator.next());
}
}
public Font getFont() {
if (font == null) {
font = new Font();
font.name = name;
}
return font;
}
@Override
public void write(PrintStream out) {
out.print("");
for (String s : xmlContent) {
out.print(s);
}
out.print(" ");
}
public String getName() {
return name;
}
}
private Map elements = new HashMap();
public Font getFont(String name) {
if (!elements.containsKey(name)) {
throw new IllegalArgumentException("No font with name = " + name);
}
return elements.get(name).getFont();
}
private void initDefault() {
List c = new LinkedList();
{
String name = "Calibri";
c.clear();
c.add(" ");
c.add(" ");
c.add(" ");
c.add(" ");
c.add(" ");
elements.put(name, new FontElement(name, c.iterator()));
}
{
String name = "Times New Roman";
c.clear();
c.add(" ");
c.add(" ");
c.add(" ");
c.add(" ");
c.add(" ");
elements.put(name, new FontElement(name, c.iterator()));
}
{
String name = "Tahoma";
c.clear();
c.add(" ");
c.add(" ");
c.add(" ");
c.add(" ");
c.add(" ");
elements.put(name, new FontElement(name, c.iterator()));
}
{
String name = "Cambria";
c.clear();
c.add(" ");
c.add(" ");
c.add(" ");
c.add(" ");
c.add(" ");
elements.put(name, new FontElement(name, c.iterator()));
}
{
String name = "Arial";
c.clear();
c.add(" ");
c.add(" ");
c.add(" ");
c.add(" ");
c.add(" ");
elements.put(name, new FontElement(name, c.iterator()));
}
{
String name = "Courier New";
c.clear();
c.add(" ");
c.add(" ");
c.add(" ");
c.add(" ");
c.add(" ");
elements.put(name, new FontElement(name, c.iterator()));
}
}
@Override
public String getPartName() {
return partName;
}
@Override
public void write(PrintStream out) {
out.print("\n");
out.print("");
for (FontElement e : elements.values()) {
e.write(out);
}
out.print(" ");
}
@Override
public ContentType getContentType() {
return ContentType.FONT_TABLE;
}
}