Skip to content

Commit

Permalink
Reverted changes meant for 2.0.0 and restored Java8 compatibility (#1086
Browse files Browse the repository at this point in the history
)

* Reverted be38865 to maintain compatibility with iText. This kind of changes will be done in 2.0.0 onwards.
* Commit 63a678d  broke java8 compatibility
* Fixed identified by asturio #1086
* wrote about removing it however forgot it (#1086)
  • Loading branch information
Lonzak authored Mar 4, 2024
1 parent b3608b5 commit 3785302
Show file tree
Hide file tree
Showing 44 changed files with 1,451 additions and 357 deletions.
10 changes: 10 additions & 0 deletions openpdf/src/main/java/com/lowagie/text/Annotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,16 @@ public String content() {
return s;
}

/**
* Gets the content of this <CODE>Annotation</CODE>.
* @deprecated use {@link #getAttributes()}
* @return a reference
*/
@Deprecated
public HashMap attributes() {
return (HashMap) annotationAttributes;
}

/**
* Gets the content of this <CODE>Annotation</CODE>.
*
Expand Down
46 changes: 46 additions & 0 deletions openpdf/src/main/java/com/lowagie/text/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,29 @@ public int getHorizontalAlignment() {
return horizontalAlignment;
}

/**
* Sets the horizontal alignment.
* @param value the new value
* @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
* use {@link Cell#setHorizontalAlignment(HorizontalAlignment)} instead
*/
@Deprecated
public void setHorizontalAlignment(int value) {
horizontalAlignment = value;
}

/**
* Sets the alignment of this cell.
* This methods allows you to set the alignment as a String.
* @param alignment the new alignment as a <CODE>String</CODE>
* @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
* use {@link Cell#setHorizontalAlignment(HorizontalAlignment)} instead
*/
@Deprecated
public void setHorizontalAlignment(String alignment) {
setHorizontalAlignment(ElementTags.alignmentValue(alignment));
}

/**
* Gets the vertical alignment.
* @return a value
Expand All @@ -280,6 +303,29 @@ public int getVerticalAlignment() {
return verticalAlignment;
}

/**
* Sets the vertical alignment.
* @param value the new value
* @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
* use {@link Cell#setVerticalAlignment(VerticalAlignment)} instead
*/
@Deprecated
public void setVerticalAlignment(int value) {
verticalAlignment = value;
}

/**
* Sets the alignment of this paragraph.
*
* @param alignment the new alignment as a <CODE>String</CODE>
* @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
* use {@link Cell#setVerticalAlignment(VerticalAlignment)} instead
*/
@Deprecated
public void setVerticalAlignment(String alignment) {
setVerticalAlignment(ElementTags.alignmentValue(alignment));
}

/**
* Sets the width.
*
Expand Down
23 changes: 23 additions & 0 deletions openpdf/src/main/java/com/lowagie/text/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,18 @@ public boolean hasAttributes() {
return attributes != null;
}

/**
* Gets the attributes for this <CODE>Chunk</CODE>.
* <P>
* It may be null.
* @deprecated use {@link #getChunkAttributes()}
* @return the attributes for this <CODE>Chunk</CODE>
*/
@Deprecated
public HashMap getAttributes() {
return (HashMap) attributes;
}

/**
* Gets the attributes for this <CODE>Chunk</CODE>.
* <P>
Expand All @@ -426,6 +438,17 @@ public Map<String, Object> getChunkAttributes() {
return attributes;
}

/**
* Sets the attributes all at once.
* @param attributes the attributes of a Chunk
* @deprecated use {@link #setChunkAttributes(Map)}
*/
@Deprecated
@SuppressWarnings("unchecked")
public void setAttributes(HashMap attributes) {
this.attributes = attributes;
}

/**
* Sets the attributes all at once.
* @param attributes the attributes of a Chunk
Expand Down
6 changes: 6 additions & 0 deletions openpdf/src/main/java/com/lowagie/text/ImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ public static Image getBmpImage(byte[] imageData) {

/**
* Creates an Image from an array of tiff image bytes.
* For JRE < 9, `ImageIO.read()` requires a supporting library in the classpath to read tiffs.
* Options are:
* - https://github.com/jai-imageio/jai-imageio-core
* - https://github.com/haraldk/TwelveMonkeys
*
* see: https://openjdk.java.net/jeps/262
*
* @param imageData bytes of the tiff image
* @return an objet of type <code>Image</code>
Expand Down
26 changes: 26 additions & 0 deletions openpdf/src/main/java/com/lowagie/text/Paragraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,32 @@ public float getExtraParagraphSpace() {
public void setExtraParagraphSpace(float extraParagraphSpace) {
this.extraParagraphSpace = extraParagraphSpace;
}

// scheduled for removal

/**
* Gets the spacing before this paragraph.
*
* @return the spacing
* @deprecated As of iText 2.1.5, replaced by {@link #getSpacingBefore()},
* scheduled for removal at 2.3.0
*/
@Deprecated
public float spacingBefore() {
return getSpacingBefore();
}

/**
* Gets the spacing after this paragraph.
*
* @return the spacing
* @deprecated As of iText 2.1.5, replaced by {@link #getSpacingAfter()},
* scheduled for removal at 2.3.0
*/
@Deprecated
public float spacingAfter() {
return spacingAfter;
}

public int getRunDirection() {
return runDirection;
Expand Down
12 changes: 12 additions & 0 deletions openpdf/src/main/java/com/lowagie/text/Row.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ public int getColumns() {
return columns;
}

/**
* Sets the horizontal alignment.
*
* @param value the new value
* @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
* use {@link Row#setHorizontalAlignment(HorizontalAlignment)} instead
*/
@Deprecated
public void setHorizontalAlignment(int value) {
horizontalAlignment = value;
}

/**
* Gets the horizontal alignment.
*
Expand Down
22 changes: 19 additions & 3 deletions openpdf/src/main/java/com/lowagie/text/StandardFonts.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public enum StandardFonts {
HELVETICA_ITALIC(Font.HELVETICA, Font.ITALIC),
HELVETICA_BOLD(Font.HELVETICA, Font.BOLD),
HELVETICA_BOLDITALIC(Font.HELVETICA, Font.BOLDITALIC),

// Times
TIMES(Font.TIMES_ROMAN, Font.NORMAL),
TIMES_ITALIC(Font.TIMES_ROMAN, Font.ITALIC),
Expand All @@ -26,19 +25,36 @@ public enum StandardFonts {

private int family;
private int style;
/**
* @deprecated Use Liberation
*/
@Deprecated
private String trueTypeFile;

StandardFonts(int family, int style) {
this.family = family;
this.style = style;
}

/**
* @deprecated Use Liberation
*/
@Deprecated
StandardFonts(String trueTypeFile) {
this.trueTypeFile = trueTypeFile;
}

public Font create() throws IOException {
return create(Font.DEFAULTSIZE);
}

public Font create(int size) throws IOException {
final Font font;
if (style == -1) {
if (trueTypeFile != null) {
final String message = String
.format("%s: Please use fonts from openpdf-fonts-extra (Liberation)", this);
throw new IOException(message);
} else if (style == -1) {
font = new Font(family, size);
} else {
font = new Font(family, size, style);
Expand All @@ -47,6 +63,6 @@ public Font create(int size) throws IOException {
}

public boolean isDeprecated() {
return false;
return trueTypeFile != null;
}
}
57 changes: 56 additions & 1 deletion openpdf/src/main/java/com/lowagie/text/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,39 @@ public int endHeaders() {
public int getAlignment() {
return alignment;
}

/**
* Sets the horizontal alignment.
*
* @param value the new value
* @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
* use {@link Table#setHorizontalAlignment(HorizontalAlignment)} instead
*
*/
@Deprecated
public void setAlignment(int value) {
alignment = value;
}

/**
* Sets the alignment of this paragraph.
*
* @param alignment the new alignment as a <CODE>String</CODE>
* @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
* use {@link Table#setHorizontalAlignment(HorizontalAlignment)} instead
*/
@Deprecated
public void setAlignment(String alignment) {
if (ElementTags.ALIGN_LEFT.equalsIgnoreCase(alignment)) {
this.alignment = Element.ALIGN_LEFT;
return;
}
if (ElementTags.RIGHT.equalsIgnoreCase(alignment)) {
this.alignment = Element.ALIGN_RIGHT;
return;
}
this.alignment = Element.ALIGN_CENTER;
}

@Override
public void setHorizontalAlignment(final HorizontalAlignment alignment) {
Expand Down Expand Up @@ -1469,5 +1502,27 @@ public boolean isComplete() {
public void setComplete(boolean complete) {
this.complete = complete;
}


/**
* Gets the default layout of the Table.
* @return a cell with all the defaults
* @deprecated As of iText 2.0.7, replaced by {@link #getDefaultCell()},
* scheduled for removal at 2.2.0
*/
@Deprecated
public Cell getDefaultLayout() {
return getDefaultCell();
}

/**
* Sets the default layout of the Table to
* the provided Cell
* @param value a cell with all the defaults
* @deprecated As of iText 2.0.7, replaced by {@link #setDefaultCell(Cell)},
* scheduled for removal at 2.2.0
*/
@Deprecated
public void setDefaultLayout(Cell value) {
defaultCell = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public class ChainedProperties {
/**
* Will be replaced with types alternative
*/
public ArrayList<Object[]> chain = new ArrayList<>();
@Deprecated
public ArrayList chain = new ArrayList<>();

/**
* Creates a new instance of ChainedProperties
Expand All @@ -84,7 +85,7 @@ public String getProperty(String key) {
*/
public Optional<String> findProperty(String key) {
for (int k = chain.size() - 1; k >= 0; --k) {
Object[] obj = chain.get(k);
Object[] obj = (Object[]) chain.get(k);
HashMap prop = (HashMap) obj[1];
String ret = (String) prop.get(key);
if (ret != null) {
Expand Down Expand Up @@ -115,6 +116,17 @@ public boolean hasProperty(String key) {
return false;
}

/**
* @deprecated use {@link ChainedProperties#addToChain(String, HashMap)}
* @param key the key
* @param prop the properties
*/
@Deprecated
@SuppressWarnings("unchecked")
public void addToChain(String key, HashMap prop) {
addToChain(key, (Map<String, String>) prop);
}

public void addToChain(String key, Map<String, String> prop) {
// adjust the font size
String value = prop.get(ElementTags.SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,23 @@ public static HyphenationEvent getHyphenation(String s) {
return new HyphenationAuto(lang, country, leftMin, rightMin);
}

/**
* This method isn't used by iText, but you can use it to analyze
* the value of a style attribute inside a HashMap.
* The different elements of the style attribute are added to the
* HashMap as key-value pairs.
*
* @param h a HashMap that should have at least a key named
* style. After this method is invoked, more keys could be added.
*
* @deprecated use {@link FactoryProperties#insertStyle(Map)} instead. (since 1.2.22)
*/
@SuppressWarnings("unchecked")
@Deprecated // this method is nor called anywhere. But it is public so theoretically it could be called by consumers of OpenPdf, but why?
public static void insertStyle(HashMap h) {
insertStyle((Map<String, String>) h);
}

public static void insertStyle(Map<String, String> h) {
String style = h.get("style");
if (style == null)
Expand Down Expand Up @@ -339,10 +355,10 @@ public static void insertStyle(Map<String, String> h, ChainedProperties cprops)
case Markup.CSS_KEY_BG: {
for(String attribute: prop.getProperty(key).split(" ")) {
Color c = Markup.decodeColor(attribute.trim());
if (c != null) {
if (c != null) {
h.put(Markup.CSS_KEY_BGCOLOR, attribute.trim());
break;
}
}
}
break;
}
Expand Down
Loading

0 comments on commit 3785302

Please sign in to comment.