1 29 30 package com.caucho.xtpdoc; 31 import javax.xml.stream.XMLStreamException; 32 import javax.xml.stream.XMLStreamWriter; 33 import java.io.IOException ; 34 import java.io.PrintWriter ; 35 36 public class Figure implements ContentItem { 37 private int _height = -1; 38 private int _width = -1; 39 private String _source; 40 private Document _document; 41 42 public Figure(Document document) 43 { 44 _document = document; 45 } 46 47 public Document getDocument() 48 { 49 return _document; 50 } 51 52 public void setHeight(int height) 53 { 54 _height = height; 55 } 56 57 public void setWidth(int width) 58 { 59 _width = width; 60 } 61 62 public void setSrc(String source) 63 { 64 _source = source; 65 } 66 67 public void writeHtml(XMLStreamWriter out) 68 throws XMLStreamException 69 { 70 out.writeStartElement("center"); 71 72 out.writeEmptyElement("img"); 73 74 if (_height >= 0) 75 out.writeAttribute("height", Integer.toString(_height)); 76 77 if (_width >= 0) 78 out.writeAttribute("width", Integer.toString(_width)); 79 80 out.writeAttribute("src", 81 _document.getContextPath() + "/images/" + _source); 82 83 out.writeEndElement(); } 85 86 public void writeLaTeX(PrintWriter out) 87 throws IOException 88 { 89 91 int dot = _source.lastIndexOf('.'); 92 93 String basename = _source.substring(0, dot); 94 95 int lastSlash = basename.lastIndexOf('/'); 96 97 if (lastSlash >= 0) 98 basename = basename.substring(lastSlash + 1); 99 100 out.println(); 101 out.println(); 102 out.println("\\noindent"); 103 out.println("\\epsfig{file=../images/" + basename + ",width=\\linewidth}"); 104 out.println(); 105 out.println(); 106 107 116 117 } 119 120 public void writeLaTeXEnclosed(PrintWriter out) 121 throws IOException 122 { 123 writeLaTeX(out); 124 } 125 126 public void writeLaTeXTop(PrintWriter out) 127 throws IOException 128 { 129 writeLaTeX(out); 130 } 131 } 132 | Popular Tags |