diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarAndLineChart.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarAndLineChart.java index dea851a9d0..2ad12a3683 100644 --- a/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarAndLineChart.java +++ b/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarAndLineChart.java @@ -62,10 +62,13 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; // additional title formatting from https://stackoverflow.com/questions/50418856 // and legend positioning from https://stackoverflow.com/questions/49615379 // this would probably be an answer for https://stackoverflow.com/questions/36447925 too -public class BarAndLineChart { +public final class BarAndLineChart { + private static final int NUM_OF_ROWS = 7; private static final Random RNG = new Random(); + private BarAndLineChart() {} + public static void main(String[] args) throws Exception { try (XSSFWorkbook wb = new XSSFWorkbook()) { XSSFSheet sheet = wb.createSheet("Sheet1"); diff --git a/src/java/org/apache/poi/sl/extractor/SlideShowExtractor.java b/src/java/org/apache/poi/sl/extractor/SlideShowExtractor.java index b99994bc12..d4a2645ca2 100644 --- a/src/java/org/apache/poi/sl/extractor/SlideShowExtractor.java +++ b/src/java/org/apache/poi/sl/extractor/SlideShowExtractor.java @@ -313,14 +313,14 @@ public class SlideShowExtractor< public List> getOLEShapes() { final List> oleShapes = new ArrayList<>(); - + for (final Slide slide : slideshow.getSlides()) { addOLEShapes(oleShapes, slide); } - + return oleShapes; } - + @SuppressWarnings("unchecked") private void addOLEShapes(final List> oleShapes, ShapeContainer container) { for (Shape shape : container) { @@ -368,8 +368,10 @@ public class SlideShowExtractor< switch (tr.getTextCap()) { case ALL: txt = txt.toUpperCase(LocaleUtil.getUserLocale()); + break; case SMALL: txt = txt.toLowerCase(LocaleUtil.getUserLocale()); + break; } return txt; diff --git a/src/java/org/apache/poi/sl/usermodel/Insets2D.java b/src/java/org/apache/poi/sl/usermodel/Insets2D.java index 51fd5ac105..7fec6354f5 100644 --- a/src/java/org/apache/poi/sl/usermodel/Insets2D.java +++ b/src/java/org/apache/poi/sl/usermodel/Insets2D.java @@ -17,11 +17,13 @@ package org.apache.poi.sl.usermodel; +import org.apache.poi.common.Duplicatable; + /** * This is a replacement for {@link java.awt.Insets} which works on doubles * instead of ints */ -public final class Insets2D implements Cloneable { +public final class Insets2D implements Duplicatable { /** * The inset from the top. @@ -50,10 +52,10 @@ public final class Insets2D implements Cloneable { * to yield a new location for the Right edge. */ public double right; - + /** - * Creates and initializes a new Insets object with the - * specified top, left, bottom, and right insets. + * Creates and initializes a new Insets object with the + * specified top, left, bottom, and right insets. * @param top the inset from the top. * @param left the inset from the left. * @param bottom the inset from the bottom. @@ -83,9 +85,9 @@ public final class Insets2D implements Cloneable { } /** - * Checks whether two insets objects are equal. Two instances + * Checks whether two insets objects are equal. Two instances * of Insets are equal if the four integer values - * of the fields top, left, + * of the fields top, left, * bottom, and right are all equal. * @return true if the two insets are equal; * otherwise false. @@ -115,12 +117,12 @@ public final class Insets2D implements Cloneable { } /** - * Returns a string representation of this Insets object. - * This method is intended to be used only for debugging purposes, and - * the content and format of the returned string may vary between - * implementations. The returned string may be empty but may not be + * Returns a string representation of this Insets object. + * This method is intended to be used only for debugging purposes, and + * the content and format of the returned string may vary between + * implementations. The returned string may be empty but may not be * null. - * + * * @return a string representation of this Insets object. */ public String toString() { @@ -132,9 +134,9 @@ public final class Insets2D implements Cloneable { * @return a copy of this Insets2D object. */ @Override - public Insets2D clone() { + public Insets2D copy() { return new Insets2D(top, left, bottom, right); } - + } diff --git a/src/java/org/apache/poi/ss/util/NormalisedDecimal.java b/src/java/org/apache/poi/ss/util/NormalisedDecimal.java index ca8816b160..6c945f26b5 100644 --- a/src/java/org/apache/poi/ss/util/NormalisedDecimal.java +++ b/src/java/org/apache/poi/ss/util/NormalisedDecimal.java @@ -72,7 +72,7 @@ final class NormalisedDecimal { private static final long MAX_REP_WHOLE_PART = 0x38D7EA4C68000L; - + @SuppressWarnings("java:S128") public static NormalisedDecimal create(BigInteger frac, int binaryExponent) { // estimate pow2&pow10 first, perform optional mulShift, then normalize int pow10; @@ -167,7 +167,7 @@ final class NormalisedDecimal { * Convert to an equivalent {@link ExpandedDouble} representation (binary frac and exponent). * The resulting transformed object is easily converted to a 64 bit IEEE double: *
    - *
  • bits 2-53 of the {@link #getSignificand()} become the 52 bit 'fraction'.
  • + *
  • bits 2-53 of the {@link #composeFrac()} become the 52 bit 'fraction'.
  • *
  • {@link #getBinaryExponent()} is biased by 1023 to give the 'exponent'.
  • *
* The sign bit must be obtained from somewhere else. @@ -184,21 +184,7 @@ final class NormalisedDecimal { * @return the significand as a fixed point number (with 24 fraction bits and 47-50 whole bits) */ BigInteger composeFrac() { - long wp = _wholePart; - int fp = _fractionalPart; - return new BigInteger(new byte[] { - (byte) (wp >> 56), // N.B. assuming sign bit is zero - (byte) (wp >> 48), - (byte) (wp >> 40), - (byte) (wp >> 32), - (byte) (wp >> 24), - (byte) (wp >> 16), - (byte) (wp >> 8), - (byte) (wp >> 0), - (byte) (fp >> 16), - (byte) (fp >> 8), - (byte) (fp >> 0), - }); + return BigInteger.valueOf(_wholePart).shiftLeft(24).or(BigInteger.valueOf(_fractionalPart & 0x00FFFFFF)); } public String getSignificantDecimalDigits() { diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureMarshalDefaultListener.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureMarshalDefaultListener.java index df5c3d88d8..2c7ccdabe9 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureMarshalDefaultListener.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureMarshalDefaultListener.java @@ -42,8 +42,8 @@ import org.w3c.dom.traversal.NodeIterator; * e.g. to register id attributes or set prefixes for registered namespaces */ public class SignatureMarshalDefaultListener implements SignatureMarshalListener { + private static final String OBJECT_TAG = "Object"; private final Set IGNORE_NS = new HashSet<>(Arrays.asList(null, XML_NS, XML_DIGSIG_NS)); - private final String OBJECT_TAG = "Object"; @Override public void handleElement(SignatureInfo signatureInfo, Document doc, EventTarget target, EventListener parentListener) { diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFRunProperties.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFRunProperties.java index 6a18cf6db2..aae476e125 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFRunProperties.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFRunProperties.java @@ -18,6 +18,8 @@ package org.apache.poi.xddf.usermodel.text; import java.util.Locale; +import java.util.function.Consumer; +import java.util.function.Supplier; import org.apache.poi.util.Beta; import org.apache.poi.util.Internal; @@ -36,6 +38,7 @@ import org.apache.poi.xddf.usermodel.XDDFSolidFillProperties; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont; +@SuppressWarnings("unused") @Beta public class XDDFRunProperties { private CTTextCharacterProperties props; @@ -55,95 +58,43 @@ public class XDDFRunProperties { } public void setBaseline(Integer value) { - if (value == null) { - if (props.isSetBaseline()) { - props.unsetBaseline(); - } - } else { - props.setBaseline(value); - } + update(props::isSetBaseline, props::unsetBaseline, props::setBaseline, value); } public void setDirty(Boolean dirty) { - if (dirty == null) { - if (props.isSetDirty()) { - props.unsetDirty(); - } - } else { - props.setDirty(dirty); - } + update(props::isSetDirty, props::unsetDirty, props::setDirty, dirty); } public void setSpellError(Boolean error) { - if (error == null) { - if (props.isSetErr()) { - props.unsetErr(); - } - } else { - props.setErr(error); - } + update(props::isSetErr, props::unsetErr, props::setErr, error); } public void setNoProof(Boolean noproof) { - if (noproof == null) { - if (props.isSetNoProof()) { - props.unsetNoProof(); - } - } else { - props.setNoProof(noproof); - } + update(props::isSetNoProof, props::unsetNoProof, props::setNoProof, noproof); } public void setNormalizeHeights(Boolean normalize) { - if (normalize == null) { - if (props.isSetNormalizeH()) { - props.unsetNormalizeH(); - } - } else { - props.setNormalizeH(normalize); - } + update(props::isSetNormalizeH, props::unsetNormalizeH, props::setNormalizeH, normalize); } public void setKumimoji(Boolean kumimoji) { - if (kumimoji == null) { - if (props.isSetKumimoji()) { - props.unsetKumimoji(); - } - } else { - props.setKumimoji(kumimoji); - } + update(props::isSetKumimoji, props::unsetKumimoji, props::setKumimoji, kumimoji); } public void setBold(Boolean bold) { - if (bold == null) { - if (props.isSetB()) { - props.unsetB(); - } - } else { - props.setB(bold); - } + update(props::isSetB, props::unsetB, props::setB, bold); } public void setItalic(Boolean italic) { - if (italic == null) { - if (props.isSetI()) { - props.unsetI(); - } - } else { - props.setI(italic); - } + update(props::isSetI, props::unsetI, props::setI, italic); } public void setFontSize(Double size) { - if (size == null) { - if (props.isSetSz()) { - props.unsetSz(); - } - } else if (size < 1 || 400 < size) { + if (size != null && (size < 1 || 400 < size)) { throw new IllegalArgumentException("Minimum inclusive = 1. Maximum inclusive = 400."); - } else { - props.setSz((int)(100 * size)); } + + update(props::isSetSz, props::unsetSz, props::setSz, size == null ? null : (int)(100 * size)); } public void setFillProperties(XDDFFillProperties properties) { @@ -184,27 +135,19 @@ public class XDDFRunProperties { } public void setCharacterKerning(Double kerning) { - if (kerning == null) { - if (props.isSetKern()) { - props.unsetKern(); - } - } else if (kerning < 0 || 4000 < kerning) { + if (kerning != null && (kerning < 0 || 4000 < kerning)) { throw new IllegalArgumentException("Minimum inclusive = 0. Maximum inclusive = 4000."); - } else { - props.setKern((int) (100 * kerning)); } + + update(props::isSetKern, props::unsetKern, props::setKern, kerning == null ? null : (int)(100 * kerning)); } public void setCharacterSpacing(Double spacing) { - if (spacing == null) { - if (props.isSetSpc()) { - props.unsetSpc(); - } - } else if (spacing < -4000 || 4000 < spacing) { + if (spacing != null && (spacing < -4000 || 4000 < spacing)) { throw new IllegalArgumentException("Minimum inclusive = -4000. Maximum inclusive = 4000."); - } else { - props.setSpc((int) (100 * spacing)); } + + update(props::isSetSpc, props::unsetSpc, props::setSpc, spacing == null ? null : (int)(100 * spacing)); } public void setFonts(XDDFFont[] fonts) { @@ -212,139 +155,59 @@ public class XDDFRunProperties { CTTextFont xml = font.getXmlObject(); switch (font.getGroup()) { case COMPLEX_SCRIPT: - if (xml == null) { - if (props.isSetCs()) { - props.unsetCs(); - } - } else { - props.setCs(xml); - } + update(props::isSetCs, props::unsetCs, props::setCs, xml); + break; case EAST_ASIAN: - if (xml == null) { - if (props.isSetEa()) { - props.unsetEa(); - } - } else { - props.setEa(xml); - } + update(props::isSetEa, props::unsetEa, props::setEa, xml); + break; case LATIN: - if (xml == null) { - if (props.isSetLatin()) { - props.unsetLatin(); - } - } else { - props.setLatin(xml); - } + update(props::isSetLatin, props::unsetLatin, props::setLatin, xml); + break; case SYMBOL: - if (xml == null) { - if (props.isSetSym()) { - props.unsetSym(); - } - } else { - props.setSym(xml); - } + update(props::isSetSym, props::unsetSym, props::setSym, xml); + break; } } } public void setUnderline(UnderlineType underline) { - if (underline == null) { - if (props.isSetU()) { - props.unsetU(); - } - } else { - props.setU(underline.underlying); - } + update(props::isSetU, props::unsetU, props::setU, underline == null ? null : underline.underlying); } public void setStrikeThrough(StrikeType strike) { - if (strike == null) { - if (props.isSetStrike()) { - props.unsetStrike(); - } - } else { - props.setStrike(strike.underlying); - } + update(props::isSetStrike, props::unsetStrike, props::setStrike, strike == null ? null : strike.underlying); } public void setCapitals(CapsType caps) { - if (caps == null) { - if (props.isSetCap()) { - props.unsetCap(); - } - } else { - props.setCap(caps.underlying); - } + update(props::isSetCap, props::unsetCap, props::setCap, caps == null ? null : caps.underlying); } public void setHyperlink(XDDFHyperlink link) { - if (link == null) { - if (props.isSetHlinkClick()) { - props.unsetHlinkClick(); - } - } else { - props.setHlinkClick(link.getXmlObject()); - } + update(props::isSetHlinkClick, props::unsetHlinkClick, props::setHlinkClick, link == null ? null : link.getXmlObject()); } public void setMouseOver(XDDFHyperlink link) { - if (link == null) { - if (props.isSetHlinkMouseOver()) { - props.unsetHlinkMouseOver(); - } - } else { - props.setHlinkMouseOver(link.getXmlObject()); - } + update(props::isSetHlinkMouseOver, props::unsetHlinkMouseOver, props::setHlinkMouseOver, link == null ? null : link.getXmlObject()); } public void setLanguage(Locale lang) { - if (lang == null) { - if (props.isSetLang()) { - props.unsetLang(); - } - } else { - props.setLang(lang.toLanguageTag()); - } + update(props::isSetLang, props::unsetLang, props::setLang, lang == null ? null : lang.toLanguageTag()); } public void setAlternativeLanguage(Locale lang) { - if (lang == null) { - if (props.isSetAltLang()) { - props.unsetAltLang(); - } - } else { - props.setAltLang(lang.toLanguageTag()); - } + update(props::isSetAltLang, props::unsetAltLang, props::setAltLang, lang == null ? null : lang.toLanguageTag()); } public void setHighlight(XDDFColor color) { - if (color == null) { - if (props.isSetHighlight()) { - props.unsetHighlight(); - } - } else { - props.setHighlight(color.getColorContainer()); - } + update(props::isSetHighlight, props::unsetHighlight, props::setHighlight, color == null ? null : color.getColorContainer()); } public void setLineProperties(XDDFLineProperties properties) { - if (properties == null) { - if (props.isSetLn()) { - props.unsetLn(); - } - } else { - props.setLn(properties.getXmlObject()); - } + update(props::isSetLn, props::unsetLn, props::setLn, properties == null ? null : properties.getXmlObject()); } public void setBookmark(String bookmark) { - if (bookmark == null) { - if (props.isSetBmk()) { - props.unsetBmk(); - } - } else { - props.setBmk(bookmark); - } + update(props::isSetBmk, props::unsetBmk, props::setBmk, bookmark); } public XDDFExtensionList getExtensionList() { @@ -356,13 +219,7 @@ public class XDDFRunProperties { } public void setExtensionList(XDDFExtensionList list) { - if (list == null) { - if (props.isSetExtLst()) { - props.unsetExtLst(); - } - } else { - props.setExtLst(list.getXmlObject()); - } + update(props::isSetExtLst, props::unsetExtLst, props::setExtLst, list == null ? null : list.getXmlObject()); } public XDDFEffectContainer getEffectContainer() { @@ -374,13 +231,7 @@ public class XDDFRunProperties { } public void setEffectContainer(XDDFEffectContainer container) { - if (container == null) { - if (props.isSetEffectDag()) { - props.unsetEffectDag(); - } - } else { - props.setEffectDag(container.getXmlObject()); - } + update(props::isSetEffectDag, props::unsetEffectDag, props::setEffectDag, container == null ? null : container.getXmlObject()); } public XDDFEffectList getEffectList() { @@ -392,12 +243,14 @@ public class XDDFRunProperties { } public void setEffectList(XDDFEffectList list) { - if (list == null) { - if (props.isSetEffectLst()) { - props.unsetEffectLst(); - } - } else { - props.setEffectLst(list.getXmlObject()); + update(props::isSetEffectLst, props::unsetEffectLst, props::setEffectLst, list == null ? null : list.getXmlObject()); + } + + private static void update(Supplier isSet, Runnable unset, Consumer setter, T val) { + if (val != null) { + setter.accept(val); + } else if (isSet.get()) { + unset.run(); } } } diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationWorkbook.java index e9040c9129..7039c1b35f 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationWorkbook.java @@ -22,42 +22,42 @@ import org.apache.poi.ss.formula.EvaluationSheet; import org.apache.poi.ss.formula.FormulaParser; import org.apache.poi.ss.formula.FormulaType; import org.apache.poi.ss.formula.ptg.Ptg; -import org.apache.poi.xssf.usermodel.BaseXSSFEvaluationWorkbook; import org.apache.poi.util.Internal; +import org.apache.poi.xssf.usermodel.BaseXSSFEvaluationWorkbook; /** * SXSSF wrapper around the SXSSF and XSSF workbooks */ @Internal public final class SXSSFEvaluationWorkbook extends BaseXSSFEvaluationWorkbook { - private final SXSSFWorkbook _uBook; - + private final SXSSFWorkbook _sxssfBook; + public static SXSSFEvaluationWorkbook create(SXSSFWorkbook book) { if (book == null) { return null; } return new SXSSFEvaluationWorkbook(book); } - + private SXSSFEvaluationWorkbook(SXSSFWorkbook book) { super(book.getXSSFWorkbook()); - _uBook = book; + _sxssfBook = book; } @Override public int getSheetIndex(EvaluationSheet evalSheet) { SXSSFSheet sheet = ((SXSSFEvaluationSheet)evalSheet).getSXSSFSheet(); - return _uBook.getSheetIndex(sheet); + return _sxssfBook.getSheetIndex(sheet); } @Override public EvaluationSheet getSheet(int sheetIndex) { - return new SXSSFEvaluationSheet(_uBook.getSheetAt(sheetIndex)); + return new SXSSFEvaluationSheet(_sxssfBook.getSheetAt(sheetIndex)); } @Override public Ptg[] getFormulaTokens(EvaluationCell evalCell) { SXSSFCell cell = ((SXSSFEvaluationCell)evalCell).getSXSSFCell(); - return FormulaParser.parse(cell.getCellFormula(), this, FormulaType.CELL, _uBook.getSheetIndex(cell.getSheet())); + return FormulaParser.parse(cell.getCellFormula(), this, FormulaType.CELL, _sxssfBook.getSheetIndex(cell.getSheet())); } } diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/TableWidthType.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/TableWidthType.java index 34a1f2af9b..bb779dfb27 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/TableWidthType.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/TableWidthType.java @@ -29,7 +29,7 @@ public enum TableWidthType { AUTO(STTblWidth.AUTO), /* Width is determined by content. */ DXA(STTblWidth.DXA), /* Width is an integer number of 20ths of a point (twips) */ NIL(STTblWidth.NIL), /* No width value set */ - PCT(STTblWidth.PCT); /* Width is a percentage, e.g. "33.3%" or 50 times percentage value, rounded to an integer, */ + PCT(STTblWidth.PCT); /* Width is a percentage, e.g. "33.3%" or 50 times percentage value, rounded to an integer, */ /* e.g. 2500 for 50% */ private Enum type = STTblWidth.NIL; @@ -37,11 +37,7 @@ public enum TableWidthType { TableWidthType(STTblWidth.Enum type) { this.type = type; } - - protected STTblWidth.Enum getSTWidthType() { - return this.type; - } - + /** * Get the underlying STTblWidth enum value. * diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java index df607fd517..b0af94cec2 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java @@ -1294,7 +1294,7 @@ public class XWPFTable implements IBodyElement, ISDTContents { protected static void setWidthType(TableWidthType widthType, CTTblWidth ctWidth) { TableWidthType currentType = getWidthType(ctWidth); if (!currentType.equals(widthType)) { - STTblWidth.Enum stWidthType = widthType.getSTWidthType(); + STTblWidth.Enum stWidthType = widthType.getStWidthType(); ctWidth.setType(stWidthType); switch (stWidthType.intValue()) { case STTblWidth.INT_PCT: diff --git a/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java b/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java index e297bd45d1..2d92484f0c 100644 --- a/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java +++ b/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java @@ -521,7 +521,7 @@ public class HemfPlusBrush { private EmfPlusWrapMode wrapMode; private Rectangle2D rect = new Rectangle2D.Double(); private Color startColor, endColor; - private AffineTransform transform; + private AffineTransform blendTransform; private float[] positions; private Color[] blendColors; private float[] positionsV; @@ -556,7 +556,7 @@ public class HemfPlusBrush { size += 4*LittleEndianConsts.INT_SIZE; if (TRANSFORM.isSet(dataFlags)) { - size += readXForm(leis, (transform = new AffineTransform())); + size += readXForm(leis, (blendTransform = new AffineTransform())); } if (isPreset() && (isBlendH() || isBlendV())) { @@ -575,7 +575,7 @@ public class HemfPlusBrush { HemfDrawProperties prop = ctx.getProperties(); prop.setBrushStyle(HwmfBrushStyle.BS_LINEAR_GRADIENT); prop.setBrushRect(rect); - prop.setBrushTransform(transform); + prop.setBrushTransform(blendTransform); // Preset colors and BlendH/V are mutual exclusive if (isPreset()) { @@ -613,7 +613,7 @@ public class HemfPlusBrush { m.put("rect", () -> rect); m.put("startColor", () -> startColor); m.put("endColor", () -> endColor); - m.put("transform", () -> transform); + m.put("blendTransform", () -> blendTransform); m.put("positions", () -> positions); m.put("blendColors", () -> blendColors); m.put("positionsV", () -> positionsV); @@ -694,7 +694,7 @@ public class HemfPlusBrush { private Color[] surroundingColor; private EmfPlusPath boundaryPath; private Point2D[] boundaryPoints; - private AffineTransform transform; + private AffineTransform blendTransform; private float[] positions; private Color[] blendColors; private float[] blendFactorsH; @@ -761,7 +761,7 @@ public class HemfPlusBrush { // the path gradient brush. This field MUST be present if the BrushDataTransform flag is set in the // BrushDataFlags field of the EmfPlusPathGradientBrushData object. if (TRANSFORM.isSet(dataFlags)) { - size += readXForm(leis, (transform = new AffineTransform())); + size += readXForm(leis, (blendTransform = new AffineTransform())); } // An optional blend pattern for the path gradient brush. If this field is present, it MUST contain either @@ -825,7 +825,7 @@ public class HemfPlusBrush { m.put("surroundingColor", () -> surroundingColor); m.put("boundaryPath", () -> boundaryPath); m.put("boundaryPoints", () -> boundaryPoints); - m.put("transform", () -> transform); + m.put("blendTransform", () -> blendTransform); m.put("positions", () -> positions); m.put("blendColors", () -> blendColors); m.put("blendFactorsH", () -> blendFactorsH); @@ -839,7 +839,7 @@ public class HemfPlusBrush { public static class EmfPlusTextureBrushData implements EmfPlusBrushData { private int dataFlags; private EmfPlusWrapMode wrapMode; - private AffineTransform transform; + private AffineTransform brushTransform; private EmfPlusImage image; @Override @@ -855,7 +855,7 @@ public class HemfPlusBrush { int size = 2*LittleEndianConsts.INT_SIZE; if (TRANSFORM.isSet(dataFlags)) { - size += readXForm(leis, (transform = new AffineTransform())); + size += readXForm(leis, (brushTransform = new AffineTransform())); } if (dataSize > size) { @@ -871,7 +871,7 @@ public class HemfPlusBrush { image.applyObject(ctx, null); prop.setBrushBitmap(prop.getEmfPlusImage()); prop.setBrushStyle(HwmfBrushStyle.BS_PATTERN); - prop.setBrushTransform(transform); + prop.setBrushTransform(brushTransform); } @Override @@ -894,7 +894,7 @@ public class HemfPlusBrush { return GenericRecordUtil.getGenericProperties( "dataFlags", () -> dataFlags, "wrapMode", () -> wrapMode, - "transform", () -> transform, + "brushTransform", () -> brushTransform, "image", () -> image ); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java index 3b194b7cc0..df11586b95 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java @@ -45,15 +45,15 @@ public final class TextRulerAtom extends RecordAtom { //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 100_000; - + private static final BitField DEFAULT_TAB_SIZE = getInstance(0x0001); private static final BitField C_LEVELS = getInstance(0x0002); private static final BitField TAB_STOPS = getInstance(0x0004); - private static final BitField[] LEFT_MARGIN = { + private static final BitField[] LEFT_MARGIN_LVL_MASK = { getInstance(0x0008), getInstance(0x0010), getInstance(0x0020), getInstance(0x0040), getInstance(0x0080), }; - private static final BitField[] INDENT = { + private static final BitField[] INDENT_LVL_MASK = { getInstance(0x0100), getInstance(0x0200), getInstance(0x0400), getInstance(0x0800), getInstance(0x1000), }; @@ -87,9 +87,9 @@ public final class TextRulerAtom extends RecordAtom { * @param start the start offset into the byte array. * @param len the length of the slice in the byte array. */ - protected TextRulerAtom(final byte[] source, final int start, final int len) { + TextRulerAtom(final byte[] source, final int start, final int len) { final LittleEndianByteArrayInputStream leis = new LittleEndianByteArrayInputStream(source, start, Math.min(len, MAX_RECORD_LENGTH)); - + try { // Get the header. @@ -128,8 +128,8 @@ public final class TextRulerAtom extends RecordAtom { mask |= writeIf(lbos, defaultTabSize, DEFAULT_TAB_SIZE); mask |= writeIf(lbos, tabStops, TAB_STOPS); for (int i=0; i<5; i++) { - mask |= writeIf(lbos, leftMargin[i], LEFT_MARGIN[i]); - mask |= writeIf(lbos, indent[i], INDENT[i]); + mask |= writeIf(lbos, leftMargin[i], LEFT_MARGIN_LVL_MASK[i]); + mask |= writeIf(lbos, indent[i], INDENT_LVL_MASK[i]); } LittleEndian.putInt(_header, 4, bos.size()+4); out.write(_header); @@ -146,7 +146,8 @@ public final class TextRulerAtom extends RecordAtom { } return bit.setBoolean(0, isSet); } - + + @SuppressWarnings("SameParameterValue") private static int writeIf(final LittleEndianOutputStream lbos, List value, BitField bit) { boolean isSet = false; if (value != null && !value.isEmpty()) { @@ -155,7 +156,7 @@ public final class TextRulerAtom extends RecordAtom { } return bit.setBoolean(0, isSet); } - + /** * Read the record bytes and initialize the internal variables */ @@ -167,15 +168,15 @@ public final class TextRulerAtom extends RecordAtom { tabStops.addAll(HSLFTabStopPropCollection.readTabStops(leis)); } for (int i=0; i<5; i++) { - leftMargin[i] = readIf(leis, mask, LEFT_MARGIN[i]); - indent[i] = readIf(leis, mask, INDENT[i]); + leftMargin[i] = readIf(leis, mask, LEFT_MARGIN_LVL_MASK[i]); + indent[i] = readIf(leis, mask, INDENT_LVL_MASK[i]); } } private static Integer readIf(final LittleEndianByteArrayInputStream leis, final int mask, final BitField bit) { return (bit.isSet(mask)) ? (int)leis.readShort() : null; - } - + } + /** * Default distance between tab stops, in master coordinates (576 dpi). */ diff --git a/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfGraphics.java b/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfGraphics.java index d1485c3975..37919c9d69 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfGraphics.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfGraphics.java @@ -297,7 +297,7 @@ public class HwmfGraphics { * Applies the object table entry * * @param index the index of the object table entry (0-based) - * + * * @throws IndexOutOfBoundsException if the index is out of range * @throws NoSuchElementException if the entry was deleted before */ @@ -308,10 +308,10 @@ public class HwmfGraphics { } ote.applyObject(this); } - + /** * Unsets (deletes) the object table entry for further usage - * + * * When a META_DELETEOBJECT record (section 2.3.4.7) is received that specifies this * object's particular index, the object's resources are released, the binding to its * WMF Object Table index is ended, and the index value is returned to the pool of @@ -319,7 +319,7 @@ public class HwmfGraphics { * created by another Object Record Type record. * * @param index the index (0-based) - * + * * @throws IndexOutOfBoundsException if the index is out of range */ public void unsetObjectTableEntry(int index) { @@ -331,7 +331,7 @@ public class HwmfGraphics { objectTable.remove(index); objectIndexes.clear(index); } - + /** * Saves the current properties to the stack */ @@ -343,7 +343,7 @@ public class HwmfGraphics { propStack.add(p); prop = newProperties(p); } - + /** * Restores the properties from the stack * @@ -444,11 +444,11 @@ public class HwmfGraphics { if (font == null || text == null || text.length == 0) { return; } - + double fontH = getFontHeight(font); // TODO: another approx. ... double fontW = fontH/1.8; - + Charset charset; if (isUnicode) { charset = Charsets.UTF_16LE; @@ -552,6 +552,7 @@ public class HwmfGraphics { switch (valign) { case TOP: tx.translate(0, layout.getAscent()); + break; default: case BASELINE: break; @@ -617,7 +618,7 @@ public class HwmfGraphics { } as.addAttribute(TextAttribute.WEIGHT, awtFW); } - + private double getFontHeight(HwmfFont font) { // see HwmfFont#height for details double fontHeight = font.getHeight(); @@ -626,9 +627,9 @@ public class HwmfGraphics { } else if (fontHeight < 0) { return -fontHeight; } else { - // TODO: fix font height calculation + // TODO: fix font height calculation // the height is given as font size + ascent + descent - // as an approximation we reduce the height by a static factor + // as an approximation we reduce the height by a static factor return fontHeight*3/4; } }