FindBugs fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1823892 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2018-02-11 20:35:11 +00:00
parent 32f3b22d08
commit ae65b5cb4a
4 changed files with 200 additions and 195 deletions

View File

@ -381,17 +381,18 @@ public class DrawTextParagraph implements Drawable {
return getRenderableText(tr); return getRenderableText(tr);
} }
String getRenderableText(TextRun tr) { private String getRenderableText(final TextRun tr) {
String txt = tr.getRawText(); final String txtSpace = tr.getRawText().replace("\t", tab2space(tr)).replace('\u000b', '\n');
txt = txt.replace("\t", tab2space(tr)).replace("\u000b", "\n"); final Locale loc = LocaleUtil.getUserLocale();
switch (tr.getTextCap()) { switch (tr.getTextCap()) {
case ALL: txt = txt.toUpperCase(LocaleUtil.getUserLocale()); break; case ALL:
case SMALL: txt = txt.toLowerCase(LocaleUtil.getUserLocale()); break; return txtSpace.toUpperCase(loc);
case NONE: break; case SMALL:
return txtSpace.toLowerCase(loc);
default:
return txtSpace;
} }
return txt;
} }
/** /**

View File

@ -17,6 +17,7 @@
package org.apache.poi.xslf.usermodel; package org.apache.poi.xslf.usermodel;
import java.awt.Color; import java.awt.Color;
import java.util.Locale;
import org.apache.poi.common.usermodel.fonts.FontCharset; import org.apache.poi.common.usermodel.fonts.FontCharset;
import org.apache.poi.common.usermodel.fonts.FontFamily; import org.apache.poi.common.usermodel.fonts.FontFamily;
@ -97,19 +98,19 @@ public class XSLFTextRun implements TextRun {
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 // TODO: finish support for tabs
txt = txt.replace("\t", " "); final String txtSpace = txt.replace("\t", " ");
final Locale loc = LocaleUtil.getUserLocale();
switch (getTextCap()) { switch (getTextCap()) {
case ALL: case ALL:
txt = txt.toUpperCase(LocaleUtil.getUserLocale()); return txtSpace.toUpperCase(loc);
break;
case SMALL: case SMALL:
txt = txt.toLowerCase(LocaleUtil.getUserLocale()); return txtSpace.toLowerCase(loc);
break; default:
return txtSpace;
} }
return txt;
} }
@Override @Override

View File

@ -32,7 +32,6 @@ import java.awt.geom.Rectangle2D;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;

View File

@ -19,29 +19,28 @@ package org.apache.poi.hslf.blip;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.zip.DeflaterOutputStream; import java.util.zip.DeflaterOutputStream;
import org.apache.poi.hslf.usermodel.HSLFPictureData; 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; import org.apache.poi.util.Units;
/** /**
* Represents a metafile picture which can be one of the following types: EMF, WMF, or PICT. * 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. * A metafile is stored compressed using the ZIP deflate/inflate algorithm.
*
* @author Yegor Kozlov
*/ */
public abstract class Metafile extends HSLFPictureData { public abstract class Metafile extends HSLFPictureData {
/** /**
* A structure which represents a 34-byte header preceding the compressed metafile data * A structure which represents a 34-byte header preceding the compressed metafile data
*
* @author Yegor Kozlov
*/ */
public static class Header{ public static class Header{
private static final int RECORD_LENGTH = 34;
/** /**
* size of the original file * size of the original file
@ -74,43 +73,48 @@ public abstract class Metafile extends HSLFPictureData {
private int filter = 254; private int filter = 254;
public void read(byte[] data, int offset){ public void read(byte[] data, int offset){
int pos = offset; @SuppressWarnings("resource")
wmfsize = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE; LittleEndianInputStream leis = new LittleEndianInputStream(
new ByteArrayInputStream(data, offset, RECORD_LENGTH));
int left = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE; wmfsize = leis.readInt();
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;
int left = leis.readInt();
int top = leis.readInt();
int right = leis.readInt();
int bottom = leis.readInt();
bounds.setBounds(left, top, right-left, bottom-top); 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); size.setSize(width, height);
zipsize = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE; zipsize = leis.readInt();
compression = leis.readUByte();
compression = LittleEndian.getUByte(data, pos); pos++; filter = leis.readUByte();
filter = LittleEndian.getUByte(data, pos); pos++;
} }
public void write(OutputStream out) throws IOException { public void write(OutputStream out) throws IOException {
byte[] header = new byte[34]; @SuppressWarnings("resource")
int pos = 0; LittleEndianOutputStream leos = new LittleEndianOutputStream(out);
LittleEndian.putInt(header, pos, wmfsize); pos += LittleEndian.INT_SIZE; //hmf
LittleEndian.putInt(header, pos, bounds.x); pos += LittleEndian.INT_SIZE; //left //hmf
LittleEndian.putInt(header, pos, bounds.y); pos += LittleEndian.INT_SIZE; //top leos.writeInt(wmfsize);
LittleEndian.putInt(header, pos, bounds.x + bounds.width); pos += LittleEndian.INT_SIZE; //right //left
LittleEndian.putInt(header, pos, bounds.y + bounds.height); pos += LittleEndian.INT_SIZE; //bottom leos.writeInt(bounds.x);
LittleEndian.putInt(header, pos, size.width); pos += LittleEndian.INT_SIZE; //inch //top
LittleEndian.putInt(header, pos, size.height); pos += LittleEndian.INT_SIZE; //inch leos.writeInt(bounds.y);
LittleEndian.putInt(header, pos, zipsize); pos += LittleEndian.INT_SIZE; //inch //right
leos.writeInt(bounds.x + bounds.width);
header[pos] = 0; pos ++; //bottom
header[pos] = (byte)filter; pos ++; leos.writeInt(bounds.y + bounds.height);
//inch
out.write(header); leos.writeInt(size.width);
//inch
leos.writeInt(size.height);
leos.writeInt(zipsize);
leos.writeByte(compression);
leos.writeByte(filter);
} }
public int getSize(){ public int getSize(){