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 0e3e8c795a
commit 5f71c80131
4 changed files with 200 additions and 195 deletions

View File

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

View File

@ -17,6 +17,7 @@
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;
@ -60,64 +61,64 @@ public class XSLFTextRun implements TextRun {
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);
}
}
@ -128,7 +129,7 @@ public class XSLFTextRun implements TextRun {
*
* @return the xmlbeans object
*/
public XmlObject getXmlObject() {
public XmlObject getXmlObject(){
return _r;
}
@ -142,7 +143,7 @@ public class XSLFTextRun implements TextRun {
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);
@ -153,11 +154,11 @@ public class XSLFTextRun implements TextRun {
}
@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;
}
@ -175,7 +176,7 @@ public class XSLFTextRun implements TextRun {
XSLFTheme theme = sheet.getTheme();
PaintStyle ps = XSLFShape.selectPaint(fp, phClr, pp, theme, hasPlaceholder);
if (ps != null) {
if (ps != null) {
setValue(ps);
return true;
}
@ -188,9 +189,9 @@ public class XSLFTextRun implements TextRun {
}
@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();
}
@ -199,43 +200,43 @@ public class XSLFTextRun implements TextRun {
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;
@ -252,16 +253,16 @@ public class XSLFTextRun implements TextRun {
* 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));
}
}
@ -299,7 +300,7 @@ public class XSLFTextRun implements TextRun {
}
@Override
public byte getPitchAndFamily() {
public byte getPitchAndFamily(){
FontGroup fg = FontGroup.getFontGroupFirst(getRawText());
XSLFFontInfo fontInfo = new XSLFFontInfo(fg);
FontPitch pitch = fontInfo.getPitch();
@ -320,10 +321,10 @@ public class XSLFTextRun implements TextRun {
@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;
}
@ -336,9 +337,9 @@ public class XSLFTextRun implements TextRun {
@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;
@ -351,16 +352,16 @@ public class XSLFTextRun implements TextRun {
}
/**
* 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);
}
/**
@ -369,7 +370,7 @@ public class XSLFTextRun implements TextRun {
*
* @see #setBaselineOffset(double)
*/
public void setSuperscript(boolean flag) {
public void setSuperscript(boolean flag){
setBaselineOffset(flag ? 30. : 0.);
}
@ -379,15 +380,15 @@ public class XSLFTextRun implements TextRun {
*
* @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;
@ -404,9 +405,9 @@ public class XSLFTextRun implements TextRun {
*/
@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]);
@ -420,15 +421,15 @@ public class XSLFTextRun implements TextRun {
}
@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;
@ -441,15 +442,15 @@ public class XSLFTextRun implements TextRun {
}
@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;
@ -467,10 +468,10 @@ public class XSLFTextRun implements TextRun {
}
@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;
@ -490,21 +491,21 @@ public class XSLFTextRun implements TextRun {
*/
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) {
@ -515,12 +516,12 @@ public class XSLFTextRun implements TextRun {
}
@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;
@ -531,7 +532,7 @@ public class XSLFTextRun implements TextRun {
}
@Override
public XSLFHyperlink getHyperlink() {
public XSLFHyperlink getHyperlink(){
CTTextCharacterProperties rPr = getRPr(false);
if (rPr == null) {
return null;
@ -543,7 +544,7 @@ public class XSLFTextRun implements TextRun {
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();
@ -557,7 +558,7 @@ public class XSLFTextRun implements TextRun {
}
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();
@ -569,22 +570,22 @@ public class XSLFTextRun implements TextRun {
}
// 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);
}
@ -596,22 +597,22 @@ public class XSLFTextRun implements TextRun {
}
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);
}
}
@ -620,7 +621,7 @@ public class XSLFTextRun implements TextRun {
@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;
}
@ -674,48 +675,48 @@ public class XSLFTextRun implements TextRun {
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();
@ -736,8 +737,8 @@ public class XSLFTextRun implements TextRun {
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);
}
@ -755,8 +756,8 @@ public class XSLFTextRun implements TextRun {
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);
}
@ -766,9 +767,9 @@ public class XSLFTextRun implements TextRun {
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;
@ -779,7 +780,7 @@ public class XSLFTextRun implements TextRun {
};
fetchCharacterProperty(visitor);
return visitor.getValue();
return visitor.getValue();
}
private CTTextFont getCTTextFont(CTTextCharacterProperties props, boolean create) {
@ -789,31 +790,31 @@ public class XSLFTextRun implements TextRun {
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) {
@ -826,7 +827,7 @@ public class XSLFTextRun implements TextRun {
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);
@ -838,7 +839,7 @@ public class XSLFTextRun implements TextRun {
font = coll.getLatin();
}
// SYMBOL is missing
if (font == null || !font.isSetTypeface() || "".equals(font.getTypeface())) {
font = coll.getLatin();
}

View File

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

View File

@ -19,30 +19,29 @@ package org.apache.poi.hslf.blip;
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
*/
@ -74,43 +73,48 @@ public abstract class Metafile extends HSLFPictureData {
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(){