package org.apache.poi.xslf.usermodel;
import java.awt.Color;
+import java.util.Locale;
import org.apache.poi.common.usermodel.fonts.FontCharset;
import org.apache.poi.common.usermodel.fonts.FontFamily;
private final XmlObject _r;
private final XSLFTextParagraph _p;
- protected XSLFTextRun(XmlObject r, XSLFTextParagraph p) {
+ protected XSLFTextRun(XmlObject r, XSLFTextParagraph p){
_r = r;
_p = p;
if (!(r instanceof CTRegularTextRun || r instanceof CTTextLineBreak || r instanceof CTTextField)) {
- throw new OpenXML4JRuntimeException("unsupported text run of type " + r.getClass());
+ throw new OpenXML4JRuntimeException("unsupported text run of type "+r.getClass());
}
}
- XSLFTextParagraph getParentParagraph() {
+ XSLFTextParagraph getParentParagraph(){
return _p;
}
@Override
- public String getRawText() {
+ public String getRawText(){
if (_r instanceof CTTextField) {
- return ((CTTextField) _r).getT();
+ return ((CTTextField)_r).getT();
} else if (_r instanceof CTTextLineBreak) {
return "\n";
}
- return ((CTRegularTextRun) _r).getT();
+ return ((CTRegularTextRun)_r).getT();
}
- String getRenderableText() {
+ String getRenderableText(){
if (_r instanceof CTTextField) {
- CTTextField tf = (CTTextField) _r;
+ CTTextField tf = (CTTextField)_r;
XSLFSheet sheet = _p.getParentShape().getSheet();
if ("slidenum".equals(tf.getType()) && sheet instanceof XSLFSlide) {
- return Integer.toString(((XSLFSlide) sheet).getSlideNumber());
+ return Integer.toString(((XSLFSlide)sheet).getSlideNumber());
}
return tf.getT();
} else if (_r instanceof CTTextLineBreak) {
return "\n";
}
- return getRenderableText(((CTRegularTextRun) _r).getT());
+ return getRenderableText(((CTRegularTextRun)_r).getT());
}
- String getRenderableText(String txt) {
+ /* package */ String getRenderableText(final String txt){
// TODO: finish support for tabs
- txt = txt.replace("\t", " ");
+ final String txtSpace = txt.replace("\t", " ");
+ final Locale loc = LocaleUtil.getUserLocale();
switch (getTextCap()) {
case ALL:
- txt = txt.toUpperCase(LocaleUtil.getUserLocale());
- break;
+ return txtSpace.toUpperCase(loc);
case SMALL:
- txt = txt.toLowerCase(LocaleUtil.getUserLocale());
- break;
+ return txtSpace.toLowerCase(loc);
+ default:
+ return txtSpace;
}
- return txt;
}
@Override
- public void setText(String text) {
+ public void setText(String text){
if (_r instanceof CTTextField) {
- ((CTTextField) _r).setT(text);
+ ((CTTextField)_r).setT(text);
} else if (!(_r instanceof CTTextLineBreak)) {
- ((CTRegularTextRun) _r).setT(text);
+ ((CTRegularTextRun)_r).setT(text);
}
}
*
* @return the xmlbeans object
*/
- public XmlObject getXmlObject() {
+ public XmlObject getXmlObject(){
return _r;
}
if (!(color instanceof SolidPaint)) {
throw new IllegalArgumentException("Currently only SolidPaint is supported!");
}
- SolidPaint sp = (SolidPaint) color;
+ SolidPaint sp = (SolidPaint)color;
Color c = DrawPaint.applyColorTransform(sp.getSolidColor());
CTTextCharacterProperties rPr = getRPr(true);
}
@Override
- public PaintStyle getFontColor() {
+ public PaintStyle getFontColor(){
final boolean hasPlaceholder = getParentParagraph().getParentShape().getPlaceholder() != null;
- CharacterPropertyFetcher<PaintStyle> fetcher = new CharacterPropertyFetcher<PaintStyle>(_p.getIndentLevel()) {
+ CharacterPropertyFetcher<PaintStyle> fetcher = new CharacterPropertyFetcher<PaintStyle>(_p.getIndentLevel()){
@Override
- public boolean fetch(CTTextCharacterProperties props) {
+ public boolean fetch(CTTextCharacterProperties props){
if (props == null) {
return false;
}
XSLFTheme theme = sheet.getTheme();
PaintStyle ps = XSLFShape.selectPaint(fp, phClr, pp, theme, hasPlaceholder);
- if (ps != null) {
+ if (ps != null) {
setValue(ps);
return true;
}
}
@Override
- public void setFontSize(Double fontSize) {
+ public void setFontSize(Double fontSize){
CTTextCharacterProperties rPr = getRPr(true);
- if (fontSize == null) {
+ if(fontSize == null) {
if (rPr.isSetSz()) {
rPr.unsetSz();
}
throw new IllegalArgumentException("Minimum font size is 1pt but was " + fontSize);
}
- rPr.setSz((int) (100 * fontSize));
+ rPr.setSz((int)(100*fontSize));
}
}
@Override
- public Double getFontSize() {
+ public Double getFontSize(){
double scale = 1;
CTTextNormalAutofit afit = getParentParagraph().getParentShape().getTextBodyPr().getNormAutofit();
- if (afit != null) {
- scale = (double) afit.getFontScale() / 100000;
+ if(afit != null) {
+ scale = (double)afit.getFontScale() / 100000;
}
- CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()) {
+ CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()){
@Override
- public boolean fetch(CTTextCharacterProperties props) {
+ public boolean fetch(CTTextCharacterProperties props){
if (props != null && props.isSetSz()) {
- setValue(props.getSz() * 0.01);
+ setValue(props.getSz()*0.01);
return true;
}
return false;
}
};
fetchCharacterProperty(fetcher);
- return fetcher.getValue() == null ? null : fetcher.getValue() * scale;
+ return fetcher.getValue() == null ? null : fetcher.getValue()*scale;
}
/**
* @return the spacing between characters within a text run,
* If this attribute is omitted than a value of 0 or no adjustment is assumed.
*/
- public double getCharacterSpacing() {
+ public double getCharacterSpacing(){
- CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()) {
+ CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()){
@Override
- public boolean fetch(CTTextCharacterProperties props) {
+ public boolean fetch(CTTextCharacterProperties props){
if (props != null && props.isSetSpc()) {
- setValue(props.getSpc() * 0.01);
+ setValue(props.getSpc()*0.01);
return true;
}
return false;
* negative values to condense.
* </p>
*
- * @param spc character spacing in points.
+ * @param spc character spacing in points.
*/
- public void setCharacterSpacing(double spc) {
+ public void setCharacterSpacing(double spc){
CTTextCharacterProperties rPr = getRPr(true);
- if (spc == 0.0) {
- if (rPr.isSetSpc()) {
+ if(spc == 0.0) {
+ if(rPr.isSetSpc()) {
rPr.unsetSpc();
}
} else {
- rPr.setSpc((int) (100 * spc));
+ rPr.setSpc((int)(100*spc));
}
}
}
@Override
- public byte getPitchAndFamily() {
+ public byte getPitchAndFamily(){
FontGroup fg = FontGroup.getFontGroupFirst(getRawText());
XSLFFontInfo fontInfo = new XSLFFontInfo(fg);
FontPitch pitch = fontInfo.getPitch();
@Override
public boolean isStrikethrough() {
- CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()) {
+ CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
@Override
- public boolean fetch(CTTextCharacterProperties props) {
- if (props != null && props.isSetStrike()) {
+ public boolean fetch(CTTextCharacterProperties props){
+ if(props != null && props.isSetStrike()) {
setValue(props.getStrike() != STTextStrikeType.NO_STRIKE);
return true;
}
@Override
public boolean isSuperscript() {
- CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()) {
+ CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
@Override
- public boolean fetch(CTTextCharacterProperties props) {
+ public boolean fetch(CTTextCharacterProperties props){
if (props != null && props.isSetBaseline()) {
setValue(props.getBaseline() > 0);
return true;
}
/**
- * Set the baseline for both the superscript and subscript fonts.
- * <p>
- * The size is specified using a percentage.
- * Positive values indicate superscript, negative values indicate subscript.
- * </p>
+ * Set the baseline for both the superscript and subscript fonts.
+ * <p>
+ * The size is specified using a percentage.
+ * Positive values indicate superscript, negative values indicate subscript.
+ * </p>
*
* @param baselineOffset
*/
- public void setBaselineOffset(double baselineOffset) {
- getRPr(true).setBaseline((int) baselineOffset * 1000);
+ public void setBaselineOffset(double baselineOffset){
+ getRPr(true).setBaseline((int) baselineOffset * 1000);
}
/**
*
* @see #setBaselineOffset(double)
*/
- public void setSuperscript(boolean flag) {
+ public void setSuperscript(boolean flag){
setBaselineOffset(flag ? 30. : 0.);
}
*
* @see #setBaselineOffset(double)
*/
- public void setSubscript(boolean flag) {
+ public void setSubscript(boolean flag){
setBaselineOffset(flag ? -25.0 : 0.);
}
@Override
public boolean isSubscript() {
- CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()) {
+ CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
@Override
- public boolean fetch(CTTextCharacterProperties props) {
+ public boolean fetch(CTTextCharacterProperties props){
if (props != null && props.isSetBaseline()) {
setValue(props.getBaseline() < 0);
return true;
*/
@Override
public TextCap getTextCap() {
- CharacterPropertyFetcher<TextCap> fetcher = new CharacterPropertyFetcher<TextCap>(_p.getIndentLevel()) {
+ CharacterPropertyFetcher<TextCap> fetcher = new CharacterPropertyFetcher<TextCap>(_p.getIndentLevel()){
@Override
- public boolean fetch(CTTextCharacterProperties props) {
+ public boolean fetch(CTTextCharacterProperties props){
if (props != null && props.isSetCap()) {
int idx = props.getCap().intValue() - 1;
setValue(TextCap.values()[idx]);
}
@Override
- public void setBold(boolean bold) {
+ public void setBold(boolean bold){
getRPr(true).setB(bold);
}
@Override
- public boolean isBold() {
- CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()) {
+ public boolean isBold(){
+ CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
@Override
- public boolean fetch(CTTextCharacterProperties props) {
+ public boolean fetch(CTTextCharacterProperties props){
if (props != null && props.isSetB()) {
setValue(props.getB());
return true;
}
@Override
- public void setItalic(boolean italic) {
+ public void setItalic(boolean italic){
getRPr(true).setI(italic);
}
@Override
- public boolean isItalic() {
- CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()) {
+ public boolean isItalic(){
+ CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
@Override
- public boolean fetch(CTTextCharacterProperties props) {
+ public boolean fetch(CTTextCharacterProperties props){
if (props != null && props.isSetI()) {
setValue(props.getI());
return true;
}
@Override
- public boolean isUnderlined() {
- CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()) {
+ public boolean isUnderlined(){
+ CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
@Override
- public boolean fetch(CTTextCharacterProperties props) {
+ public boolean fetch(CTTextCharacterProperties props){
if (props != null && props.isSetU()) {
setValue(props.getU() != STTextUnderlineType.NONE);
return true;
*/
protected CTTextCharacterProperties getRPr(boolean create) {
if (_r instanceof CTTextField) {
- CTTextField tf = (CTTextField) _r;
+ CTTextField tf = (CTTextField)_r;
if (tf.isSetRPr()) {
return tf.getRPr();
} else if (create) {
return tf.addNewRPr();
}
} else if (_r instanceof CTTextLineBreak) {
- CTTextLineBreak tlb = (CTTextLineBreak) _r;
+ CTTextLineBreak tlb = (CTTextLineBreak)_r;
if (tlb.isSetRPr()) {
return tlb.getRPr();
} else if (create) {
return tlb.addNewRPr();
}
} else {
- CTRegularTextRun tr = (CTRegularTextRun) _r;
+ CTRegularTextRun tr = (CTRegularTextRun)_r;
if (tr.isSetRPr()) {
return tr.getRPr();
} else if (create) {
}
@Override
- public String toString() {
+ public String toString(){
return "[" + getClass() + "]" + getRawText();
}
@Override
- public XSLFHyperlink createHyperlink() {
+ public XSLFHyperlink createHyperlink(){
XSLFHyperlink hl = getHyperlink();
if (hl != null) {
return hl;
}
@Override
- public XSLFHyperlink getHyperlink() {
+ public XSLFHyperlink getHyperlink(){
CTTextCharacterProperties rPr = getRPr(false);
if (rPr == null) {
return null;
return new XSLFHyperlink(hl, _p.getParentShape().getSheet());
}
- private boolean fetchCharacterProperty(CharacterPropertyFetcher<?> fetcher) {
+ private boolean fetchCharacterProperty(CharacterPropertyFetcher<?> fetcher){
XSLFTextShape shape = _p.getParentShape();
XSLFSheet sheet = shape.getSheet();
}
CTPlaceholder ph = shape.getCTPlaceholder();
- if (ph == null) {
+ if (ph == null){
// if it is a plain text box then take defaults from presentation.xml
@SuppressWarnings("resource")
XMLSlideShow ppt = sheet.getSlideShow();
}
// TODO: determine master shape
- CTTextParagraphProperties defaultProps = _p.getDefaultMasterStyle();
- if (defaultProps != null && fetcher.fetch(defaultProps)) {
+ CTTextParagraphProperties defaultProps = _p.getDefaultMasterStyle();
+ if(defaultProps != null && fetcher.fetch(defaultProps)) {
return true;
}
return false;
}
- void copy(XSLFTextRun r) {
+ void copy(XSLFTextRun r){
String srcFontFamily = r.getFontFamily();
- if (srcFontFamily != null && !srcFontFamily.equals(getFontFamily())) {
+ if(srcFontFamily != null && !srcFontFamily.equals(getFontFamily())){
setFontFamily(srcFontFamily);
}
PaintStyle srcFontColor = r.getFontColor();
- if (srcFontColor != null && !srcFontColor.equals(getFontColor())) {
+ if(srcFontColor != null && !srcFontColor.equals(getFontColor())){
setFontColor(srcFontColor);
}
}
boolean bold = r.isBold();
- if (bold != isBold()) {
+ if(bold != isBold()) {
setBold(bold);
}
boolean italic = r.isItalic();
- if (italic != isItalic()) {
+ if(italic != isItalic()) {
setItalic(italic);
}
boolean underline = r.isUnderlined();
- if (underline != isUnderlined()) {
+ if(underline != isUnderlined()) {
setUnderlined(underline);
}
boolean strike = r.isStrikethrough();
- if (strike != isStrikethrough()) {
+ if(strike != isStrikethrough()) {
setStrikethrough(strike);
}
}
@Override
public FieldType getFieldType() {
if (_r instanceof CTTextField) {
- CTTextField tf = (CTTextField) _r;
+ CTTextField tf = (CTTextField)_r;
if ("slidenum".equals(tf.getType())) {
return FieldType.SLIDE_NUMBER;
}
getXmlObject(true).setTypeface(typeface);
return;
}
-
+
CTTextCharacterProperties props = getRPr(false);
if (props == null) {
return;
}
FontGroup fg = FontGroup.getFontGroupFirst(getRawText());
switch (fg) {
- default:
- case LATIN:
- if (props.isSetLatin()) {
- props.unsetLatin();
- }
- break;
- case EAST_ASIAN:
- if (props.isSetEa()) {
- props.unsetEa();
- }
- break;
- case COMPLEX_SCRIPT:
- if (props.isSetCs()) {
- props.unsetCs();
- }
- break;
- case SYMBOL:
- if (props.isSetSym()) {
- props.unsetSym();
- }
- break;
+ default:
+ case LATIN:
+ if (props.isSetLatin()) {
+ props.unsetLatin();
+ }
+ break;
+ case EAST_ASIAN:
+ if (props.isSetEa()) {
+ props.unsetEa();
+ }
+ break;
+ case COMPLEX_SCRIPT:
+ if (props.isSetCs()) {
+ props.unsetCs();
+ }
+ break;
+ case SYMBOL:
+ if (props.isSetSym()) {
+ props.unsetSym();
+ }
+ break;
}
}
@Override
public FontCharset getCharset() {
CTTextFont tf = getXmlObject(false);
- return (tf != null && tf.isSetCharset()) ? FontCharset.valueOf(tf.getCharset() & 0xFF) : null;
+ return (tf != null && tf.isSetCharset()) ? FontCharset.valueOf(tf.getCharset()&0xFF) : null;
}
@Override
public void setCharset(FontCharset charset) {
CTTextFont tf = getXmlObject(true);
if (charset != null) {
- tf.setCharset((byte) charset.getNativeId());
+ tf.setCharset((byte)charset.getNativeId());
} else {
if (tf.isSetCharset()) {
tf.unsetCharset();
return;
}
FontPitch pitch = (tf.isSetPitchFamily())
- ? FontPitch.valueOfPitchFamily(tf.getPitchFamily())
- : FontPitch.VARIABLE;
+ ? FontPitch.valueOfPitchFamily(tf.getPitchFamily())
+ : FontPitch.VARIABLE;
byte pitchFamily = FontPitch.getNativeId(pitch, family != null ? family : FontFamily.FF_SWISS);
tf.setPitchFamily(pitchFamily);
}
return;
}
FontFamily family = (tf.isSetPitchFamily())
- ? FontFamily.valueOfPitchFamily(tf.getPitchFamily())
- : FontFamily.FF_SWISS;
+ ? FontFamily.valueOfPitchFamily(tf.getPitchFamily())
+ : FontFamily.FF_SWISS;
byte pitchFamily = FontPitch.getNativeId(pitch != null ? pitch : FontPitch.VARIABLE, family);
tf.setPitchFamily(pitchFamily);
}
return getCTTextFont(getRPr(true), true);
}
- CharacterPropertyFetcher<CTTextFont> visitor = new CharacterPropertyFetcher<CTTextFont>(_p.getIndentLevel()) {
+ CharacterPropertyFetcher<CTTextFont> visitor = new CharacterPropertyFetcher<CTTextFont>(_p.getIndentLevel()){
@Override
- public boolean fetch(CTTextCharacterProperties props) {
+ public boolean fetch(CTTextCharacterProperties props){
CTTextFont font = getCTTextFont(props, false);
if (font == null) {
return false;
};
fetchCharacterProperty(visitor);
- return visitor.getValue();
+ return visitor.getValue();
}
private CTTextFont getCTTextFont(CTTextCharacterProperties props, boolean create) {
CTTextFont font;
switch (fontGroup) {
- default:
- case LATIN:
- font = props.getLatin();
- if (font == null && create) {
- font = props.addNewLatin();
- }
- break;
- case EAST_ASIAN:
- font = props.getEa();
- if (font == null && create) {
- font = props.addNewEa();
- }
- break;
- case COMPLEX_SCRIPT:
- font = props.getCs();
- if (font == null && create) {
- font = props.addNewCs();
- }
- break;
- case SYMBOL:
- font = props.getSym();
- if (font == null && create) {
- font = props.addNewSym();
- }
- break;
+ default:
+ case LATIN:
+ font = props.getLatin();
+ if (font == null && create) {
+ font = props.addNewLatin();
+ }
+ break;
+ case EAST_ASIAN:
+ font = props.getEa();
+ if (font == null && create) {
+ font = props.addNewEa();
+ }
+ break;
+ case COMPLEX_SCRIPT:
+ font = props.getCs();
+ if (font == null && create) {
+ font = props.addNewCs();
+ }
+ break;
+ case SYMBOL:
+ font = props.getSym();
+ if (font == null && create) {
+ font = props.addNewSym();
+ }
+ break;
}
if (font == null) {
final XSLFTheme theme = _p.getParentShape().getSheet().getTheme();
CTFontScheme fontTheme = theme.getXmlObject().getThemeElements().getFontScheme();
CTFontCollection coll = typeface.startsWith("+mj-")
- ? fontTheme.getMajorFont() : fontTheme.getMinorFont();
+ ? fontTheme.getMajorFont() : fontTheme.getMinorFont();
// TODO: handle LCID codes
// see https://blogs.msdn.microsoft.com/officeinteroperability/2013/04/22/office-open-xml-themes-schemes-and-fonts/
String fgStr = typeface.substring(4);
font = coll.getLatin();
}
// SYMBOL is missing
-
+
if (font == null || !font.isSetTypeface() || "".equals(font.getTypeface())) {
font = coll.getLatin();
}
import java.awt.Dimension;
import java.awt.Rectangle;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.DeflaterOutputStream;
import org.apache.poi.hslf.usermodel.HSLFPictureData;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianInputStream;
+import org.apache.poi.util.LittleEndianOutputStream;
import org.apache.poi.util.Units;
/**
* Represents a metafile picture which can be one of the following types: EMF, WMF, or PICT.
* A metafile is stored compressed using the ZIP deflate/inflate algorithm.
- *
- * @author Yegor Kozlov
*/
public abstract class Metafile extends HSLFPictureData {
/**
* A structure which represents a 34-byte header preceding the compressed metafile data
- *
- * @author Yegor Kozlov
*/
public static class Header{
-
+ private static final int RECORD_LENGTH = 34;
+
/**
* size of the original file
*/
private int filter = 254;
public void read(byte[] data, int offset){
- int pos = offset;
- wmfsize = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE;
-
- int left = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE;
- int top = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE;
- int right = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE;
- int bottom = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE;
-
+ @SuppressWarnings("resource")
+ LittleEndianInputStream leis = new LittleEndianInputStream(
+ new ByteArrayInputStream(data, offset, RECORD_LENGTH));
+
+ wmfsize = leis.readInt();
+
+ int left = leis.readInt();
+ int top = leis.readInt();
+ int right = leis.readInt();
+ int bottom = leis.readInt();
bounds.setBounds(left, top, right-left, bottom-top);
- int width = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE;
- int height = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE;
+ int width = leis.readInt();
+ int height = leis.readInt();
size.setSize(width, height);
- zipsize = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE;
-
- compression = LittleEndian.getUByte(data, pos); pos++;
- filter = LittleEndian.getUByte(data, pos); pos++;
+ zipsize = leis.readInt();
+ compression = leis.readUByte();
+ filter = leis.readUByte();
}
public void write(OutputStream out) throws IOException {
- byte[] header = new byte[34];
- int pos = 0;
- LittleEndian.putInt(header, pos, wmfsize); pos += LittleEndian.INT_SIZE; //hmf
-
- LittleEndian.putInt(header, pos, bounds.x); pos += LittleEndian.INT_SIZE; //left
- LittleEndian.putInt(header, pos, bounds.y); pos += LittleEndian.INT_SIZE; //top
- LittleEndian.putInt(header, pos, bounds.x + bounds.width); pos += LittleEndian.INT_SIZE; //right
- LittleEndian.putInt(header, pos, bounds.y + bounds.height); pos += LittleEndian.INT_SIZE; //bottom
- LittleEndian.putInt(header, pos, size.width); pos += LittleEndian.INT_SIZE; //inch
- LittleEndian.putInt(header, pos, size.height); pos += LittleEndian.INT_SIZE; //inch
- LittleEndian.putInt(header, pos, zipsize); pos += LittleEndian.INT_SIZE; //inch
-
- header[pos] = 0; pos ++;
- header[pos] = (byte)filter; pos ++;
-
- out.write(header);
+ @SuppressWarnings("resource")
+ LittleEndianOutputStream leos = new LittleEndianOutputStream(out);
+
+ //hmf
+ leos.writeInt(wmfsize);
+ //left
+ leos.writeInt(bounds.x);
+ //top
+ leos.writeInt(bounds.y);
+ //right
+ leos.writeInt(bounds.x + bounds.width);
+ //bottom
+ leos.writeInt(bounds.y + bounds.height);
+ //inch
+ leos.writeInt(size.width);
+ //inch
+ leos.writeInt(size.height);
+ leos.writeInt(zipsize);
+ leos.writeByte(compression);
+ leos.writeByte(filter);
}
public int getSize(){