Skip to content

Commit

Permalink
Reduce delta between master and java7
Browse files Browse the repository at this point in the history
- Reformat code
- rearranged code
- organized imports
  • Loading branch information
asturio committed Oct 16, 2019
1 parent 7327d2f commit f73467c
Show file tree
Hide file tree
Showing 33 changed files with 195 additions and 233 deletions.
7 changes: 2 additions & 5 deletions openpdf/src/main/java/com/lowagie/text/SimpleCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,15 @@
*/
package com.lowagie.text;

import java.util.ArrayList;
import java.util.Optional;

import com.lowagie.text.alignment.HorizontalAlignment;
import com.lowagie.text.alignment.VerticalAlignment;
import com.lowagie.text.error_messages.MessageLocalization;

import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPCellEvent;
import com.lowagie.text.pdf.PdfPTable;
import java.util.ArrayList;
import java.util.Optional;


/**
Expand Down
7 changes: 2 additions & 5 deletions openpdf/src/main/java/com/lowagie/text/SimpleTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,13 @@
*/
package com.lowagie.text;

import java.util.ArrayList;
import java.util.Optional;

import com.lowagie.text.alignment.HorizontalAlignment;
import com.lowagie.text.error_messages.MessageLocalization;

import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPTableEvent;
import java.util.ArrayList;
import java.util.Optional;


/**
Expand Down
20 changes: 11 additions & 9 deletions openpdf/src/main/java/com/lowagie/text/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,15 @@
import com.lowagie.text.alignment.HorizontalAlignment;
import com.lowagie.text.alignment.VerticalAlignment;
import com.lowagie.text.alignment.WithHorizontalAlignment;
import com.lowagie.text.error_messages.MessageLocalization;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import java.awt.Dimension;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Optional;

import com.lowagie.text.error_messages.MessageLocalization;

import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;


/**
* A <CODE>Table</CODE> is a <CODE>Rectangle</CODE> that contains <CODE>Cell</CODE>s,
Expand Down Expand Up @@ -773,9 +771,11 @@ public void addCell(Phrase content, Point location) throws BadElementException {
cell.setBorderWidth(defaultCell.getBorderWidth());
cell.setBorderColor(defaultCell.getBorderColor());
cell.setBackgroundColor(defaultCell.getBackgroundColor());
Optional<HorizontalAlignment> optionalHorizontalAlignment = HorizontalAlignment.of(defaultCell.getHorizontalAlignment());
Optional<HorizontalAlignment> optionalHorizontalAlignment = HorizontalAlignment
.of(defaultCell.getHorizontalAlignment());
cell.setHorizontalAlignment(optionalHorizontalAlignment.orElse(HorizontalAlignment.UNDEFINED));
Optional<VerticalAlignment> optionalVerticalAlignment = VerticalAlignment.of(defaultCell.getVerticalAlignment());
Optional<VerticalAlignment> optionalVerticalAlignment = VerticalAlignment
.of(defaultCell.getVerticalAlignment());
cell.setVerticalAlignment(optionalVerticalAlignment.orElse(VerticalAlignment.UNDEFINED));
cell.setColspan(defaultCell.getColspan());
cell.setRowspan(defaultCell.getRowspan());
Expand Down Expand Up @@ -1265,11 +1265,13 @@ private void assumeTableDefaults(Cell aCell) {
aCell.setBackgroundColor(defaultCell.getBackgroundColor());
}
if (aCell.getHorizontalAlignment() == Element.ALIGN_UNDEFINED) {
final Optional<HorizontalAlignment> of = HorizontalAlignment.of(defaultCell.getHorizontalAlignment());
final Optional<HorizontalAlignment> of = HorizontalAlignment
.of(defaultCell.getHorizontalAlignment());
aCell.setHorizontalAlignment(of.orElse(HorizontalAlignment.UNDEFINED));
}
if (aCell.getVerticalAlignment() == Element.ALIGN_UNDEFINED) {
final Optional<VerticalAlignment> of = VerticalAlignment.of(defaultCell.getVerticalAlignment());
final Optional<VerticalAlignment> of = VerticalAlignment
.of(defaultCell.getVerticalAlignment());
aCell.setVerticalAlignment(of.orElse(VerticalAlignment.UNDEFINED));
}
}
Expand Down
3 changes: 1 addition & 2 deletions openpdf/src/main/java/com/lowagie/text/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
*/
package com.lowagie.text;

import com.lowagie.text.pdf.PRTokeniser;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
Expand All @@ -59,8 +60,6 @@
import java.util.Properties;
import java.util.Set;

import com.lowagie.text.pdf.PRTokeniser;

/**
* A collection of convenience methods that were present in many different iText
* classes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@
package com.lowagie.text.html.simpleparser;

import com.lowagie.text.ElementTags;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class ChainedProperties {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

package com.lowagie.text.html.simpleparser;

import static com.lowagie.text.html.Markup.parseLength;

import com.lowagie.text.Chunk;
import com.lowagie.text.Element;
import com.lowagie.text.ElementTags;
Expand All @@ -64,15 +66,12 @@
import com.lowagie.text.pdf.HyphenationAuto;
import com.lowagie.text.pdf.HyphenationEvent;
import com.lowagie.text.utils.NumberUtilities;

import javax.annotation.Nullable;
import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;

import static com.lowagie.text.html.Markup.parseLength;
import javax.annotation.Nullable;

/**
* @author psoares
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

package com.lowagie.text.html.simpleparser;

import static com.lowagie.text.html.Markup.parseLength;

import com.lowagie.text.Chunk;
import com.lowagie.text.DocListener;
import com.lowagie.text.DocumentException;
Expand All @@ -72,8 +74,6 @@
import com.lowagie.text.utils.NumberUtilities;
import com.lowagie.text.xml.simpleparser.SimpleXMLDocHandler;
import com.lowagie.text.xml.simpleparser.SimpleXMLParser;

import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
Expand All @@ -83,8 +83,7 @@
import java.util.Map;
import java.util.Stack;
import java.util.StringTokenizer;

import static com.lowagie.text.html.Markup.parseLength;
import javax.annotation.Nullable;

public class HTMLWorker implements SimpleXMLDocHandler, DocListener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import com.lowagie.text.html.Markup;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.utils.NumberUtilities;

import java.util.ArrayList;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@
import java.util.Map;

public class StyleSheet {
public HashMap classMap = new HashMap();
public HashMap tagMap = new HashMap();

private Map<String, Map<String, String>> classMap = new HashMap<>();
private Map<String, Map<String, String>> tagMap = new HashMap<>();

@Deprecated
public void applyStyle(String tag, HashMap props) {
applyStyle(tag, (Map<String, String>) props);
}

public void applyStyle(String tag, Map<String, String> props) {
HashMap map = (HashMap) tagMap.get(tag.toLowerCase());
Map<String, String> map = tagMap.get(tag.toLowerCase());
if (map != null) {
Map<String, String> temp = new HashMap<>(map);
temp.putAll(props);
Expand All @@ -73,7 +74,7 @@ public void applyStyle(String tag, Map<String, String> props) {
String cm = props.get(Markup.HTML_ATTR_CSS_CLASS);
if (cm == null)
return;
map = (HashMap) classMap.get(cm.toLowerCase());
map = classMap.get(cm.toLowerCase());
if (map == null)
return;
props.remove(Markup.HTML_ATTR_CSS_CLASS);
Expand All @@ -88,7 +89,7 @@ public void loadStyle(String style, Map<String, String> props) {

public void loadStyle(String style, String key, String value) {
style = style.toLowerCase();
HashMap props = (HashMap) classMap.computeIfAbsent(style, k -> new HashMap<>());
Map<String, String> props = classMap.computeIfAbsent(style, k -> new HashMap<>());
props.put(key, value);
}

Expand All @@ -98,7 +99,7 @@ public void loadTagStyle(String tag, Map<String, String> props) {

public void loadTagStyle(String tag, String key, String value) {
tag = tag.toLowerCase();
Map<String, String> props = (Map<String, String>) tagMap.computeIfAbsent(tag, k -> new HashMap<>());
Map<String, String> props = tagMap.computeIfAbsent(tag, k -> new HashMap<>());
props.put(key, value);
}

Expand Down
15 changes: 7 additions & 8 deletions openpdf/src/main/java/com/lowagie/text/pdf/AcroFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
*/
package com.lowagie.text.pdf;

import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.Rectangle;
import com.lowagie.text.error_messages.MessageLocalization;
import java.awt.Color;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -55,14 +62,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.Rectangle;
import com.lowagie.text.error_messages.MessageLocalization;
import org.w3c.dom.Node;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ private static boolean cleanJava9(final java.nio.ByteBuffer buffer) {
final Field theUnsafeField = unsafeClass.getDeclaredField("theUnsafe");
theUnsafeField.setAccessible(true);
final Object theUnsafe = theUnsafeField.get(null);
final Method invokeCleanerMethod = unsafeClass.getMethod("invokeCleaner", ByteBuffer.class);
final Method invokeCleanerMethod = unsafeClass
.getMethod("invokeCleaner", ByteBuffer.class);
invokeCleanerMethod.invoke(theUnsafe, buffer);
success = Boolean.TRUE;
} catch (Exception ignore) {
Expand All @@ -234,7 +235,8 @@ private static boolean cleanOldsJDK(final java.nio.ByteBuffer buffer) {
Boolean b = AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> {
Boolean success = Boolean.FALSE;
try {
Method getCleanerMethod = buffer.getClass().getMethod("cleaner", (Class[])null);
Method getCleanerMethod = buffer.getClass()
.getMethod("cleaner", (Class[]) null);
if (!getCleanerMethod.isAccessible()) {
getCleanerMethod.setAccessible(true);
}
Expand Down
14 changes: 6 additions & 8 deletions openpdf/src/main/java/com/lowagie/text/pdf/PdfCopy.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,14 @@
*/
package com.lowagie.text.pdf;

import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;

import com.lowagie.text.Rectangle;
import com.lowagie.text.ExceptionConverter;

import com.lowagie.text.Rectangle;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -397,7 +394,8 @@ public void addPage(PdfImportedPage iPage) throws IOException, BadPdfFormatExcep
public void addPage(Rectangle rect, int rotation) {
PdfRectangle mediabox = new PdfRectangle(rect, rotation);
PageResources resources = new PageResources();
PdfPage page = new PdfPage(mediabox, new HashMap<>(), resources.getResources(), 0);
PdfPage page = new PdfPage(mediabox, new HashMap<>(),
resources.getResources(), 0);
page.put(PdfName.TABS, getTabs());
root.addPage(page);
++currentPageNumber;
Expand Down
3 changes: 1 addition & 2 deletions openpdf/src/main/java/com/lowagie/text/pdf/PdfDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
import com.lowagie.text.pdf.draw.DrawInterface;
import com.lowagie.text.pdf.internal.PdfAnnotationsImp;
import com.lowagie.text.pdf.internal.PdfViewerPreferencesImp;

import java.awt.Color;
import java.io.IOException;
import java.text.DecimalFormat;
Expand Down Expand Up @@ -1460,7 +1459,7 @@ else if (isJustified) {
if (chunk.isTab()) {
Object[] tab = (Object[])chunk.getAttribute(Chunk.TAB);
DrawInterface di = (DrawInterface)tab[0];
tabPosition = (Float) tab[1] + (Float) tab[3];
tabPosition = tab[1] + tab[3];
float fontSize = chunk.font().size();
float ascender = chunk.font().getFont().getFontDescriptor(BaseFont.ASCENT, fontSize);
float descender = chunk.font().getFont().getFontDescriptor(BaseFont.DESCENT, fontSize);
Expand Down
16 changes: 9 additions & 7 deletions openpdf/src/main/java/com/lowagie/text/pdf/PdfGraphics2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

package com.lowagie.text.pdf;

import com.lowagie.text.pdf.internal.PolylineShape;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
Expand All @@ -66,11 +67,11 @@
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.RenderingHints.Key;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.TexturePaint;
import java.awt.Transparency;
import java.awt.RenderingHints.Key;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.font.TextAttribute;
Expand Down Expand Up @@ -99,13 +100,11 @@
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;

import com.lowagie.text.pdf.internal.PolylineShape;
import java.util.Locale;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
Expand Down Expand Up @@ -811,7 +810,7 @@ public RenderingHints getRenderingHints() {
* @see Graphics#translate(int, int)
*/
public void translate(int x, int y) {
translate((double)x, (double)y);
translate(x, y);
}

/**
Expand Down Expand Up @@ -1896,7 +1895,8 @@ boolean isCompositeFont(Font font) {
String fontFamily = compositeFont.getFamily();
if (!isSupported() || (fontFamily != null && !fontFamilyComposite.get(fontFamily))) {
assert false;
return defaultDrawingFunction.drawString(s, fontConverter.apply(compositeFont), x, y);
return defaultDrawingFunction
.drawString(s, fontConverter.apply(compositeFont), x, y);
}

try {
Expand All @@ -1906,7 +1906,9 @@ boolean isCompositeFont(Font font) {
String strPart = stringParts.get(i);
Font correspondingFont = correspondingFontsForParts.get(i);
BaseFont correspondingBaseFont = fontConverter.apply(correspondingFont);
BaseFont baseFont = correspondingBaseFont == null ? fontConverter.apply(compositeFont) : correspondingBaseFont;
BaseFont baseFont = correspondingBaseFont == null
? fontConverter.apply(compositeFont)
: correspondingBaseFont;
width += defaultDrawingFunction.drawString(strPart, baseFont, x + width, y);
}
return width;
Expand Down
Loading

0 comments on commit f73467c

Please sign in to comment.