From: Simon Steiner Date: Tue, 2 May 2023 09:30:07 +0000 (+0100) Subject: FOP-3132: Link against Java 8 API X-Git-Tag: 2_9~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3d9416baf3723ee8a7d7dd4433a781a643fe9809;p=xmlgraphics-fop.git FOP-3132: Link against Java 8 API --- diff --git a/fop-core/src/main/java/org/apache/fop/complexscripts/fonts/GlyphProcessingState.java b/fop-core/src/main/java/org/apache/fop/complexscripts/fonts/GlyphProcessingState.java index f7b3d5e9c..20abd1616 100644 --- a/fop-core/src/main/java/org/apache/fop/complexscripts/fonts/GlyphProcessingState.java +++ b/fop-core/src/main/java/org/apache/fop/complexscripts/fonts/GlyphProcessingState.java @@ -19,6 +19,7 @@ package org.apache.fop.complexscripts.fonts; +import java.nio.Buffer; import java.nio.IntBuffer; import java.util.ArrayList; import java.util.List; @@ -935,7 +936,8 @@ public class GlyphProcessingState { gb.put(igs.getGlyph(i)); al.add(igs.getAssociation(i)); } - gb.flip(); + Buffer gbBase = gb; + gbBase.flip(); assert igs != null; if (igs.compareGlyphs(gb) != 0) { this.igs = new GlyphSequence(igs.getCharacters(), gb, al); diff --git a/fop-core/src/main/java/org/apache/fop/complexscripts/fonts/GlyphSubstitutionState.java b/fop-core/src/main/java/org/apache/fop/complexscripts/fonts/GlyphSubstitutionState.java index 0be47b8c1..788fe2574 100644 --- a/fop-core/src/main/java/org/apache/fop/complexscripts/fonts/GlyphSubstitutionState.java +++ b/fop-core/src/main/java/org/apache/fop/complexscripts/fonts/GlyphSubstitutionState.java @@ -19,6 +19,7 @@ package org.apache.fop.complexscripts.fonts; +import java.nio.Buffer; import java.nio.IntBuffer; import java.util.ArrayList; import java.util.List; @@ -41,7 +42,7 @@ public class GlyphSubstitutionState extends GlyphProcessingState { /** alternates index */ private int[] alternatesIndex; /** current output glyph sequence */ - private IntBuffer ogb; + private Buffer ogb; /** current output glyph to character associations */ private List oal; /** character association predications */ @@ -131,15 +132,19 @@ public class GlyphSubstitutionState extends GlyphProcessingState { */ public void putGlyph(int glyph, CharAssociation a, Object predication) { if (!ogb.hasRemaining()) { - ogb = growBuffer(ogb); + ogb = growBuffer(getIntBuffer()); } - ogb.put(glyph); + getIntBuffer().put(glyph); if (predications && (predication != null)) { a.setPredication(feature, predication); } oal.add(a); } + private IntBuffer getIntBuffer() { + return (IntBuffer) ogb; + } + /** * Put (write) array of glyphs into glyph output buffer. * @param glyphs to write @@ -165,7 +170,7 @@ public class GlyphSubstitutionState extends GlyphProcessingState { if (position > 0) { ogb.limit(position); ogb.rewind(); - return new GlyphSequence(igs.getCharacters(), ogb, oal); + return new GlyphSequence(igs.getCharacters(), getIntBuffer(), oal); } else { return igs; } @@ -241,12 +246,12 @@ public class GlyphSubstitutionState extends GlyphProcessingState { } } - private static IntBuffer growBuffer(IntBuffer ib) { + private static IntBuffer growBuffer(Buffer ib) { int capacity = ib.capacity(); int capacityNew = capacity * 2; IntBuffer ibNew = IntBuffer.allocate(capacityNew); ib.rewind(); - return ibNew.put(ib); + return ibNew.put((IntBuffer) ib); } } diff --git a/fop-core/src/main/java/org/apache/fop/complexscripts/util/GlyphSequence.java b/fop-core/src/main/java/org/apache/fop/complexscripts/util/GlyphSequence.java index e5cdd07f5..797fd4784 100644 --- a/fop-core/src/main/java/org/apache/fop/complexscripts/util/GlyphSequence.java +++ b/fop-core/src/main/java/org/apache/fop/complexscripts/util/GlyphSequence.java @@ -19,6 +19,7 @@ package org.apache.fop.complexscripts.util; +import java.nio.Buffer; import java.nio.IntBuffer; import java.util.ArrayList; import java.util.Collections; @@ -464,7 +465,8 @@ public class GlyphSequence implements Cloneable { if (lga != null) { gb.put(lga); } - gb.flip(); + Buffer gbBase = gb; + gbBase.flip(); return gb; } diff --git a/fop-core/src/main/java/org/apache/fop/fo/FOText.java b/fop-core/src/main/java/org/apache/fop/fo/FOText.java index 207c3184c..e80063d1a 100644 --- a/fop-core/src/main/java/org/apache/fop/fo/FOText.java +++ b/fop-core/src/main/java/org/apache/fop/fo/FOText.java @@ -20,6 +20,7 @@ package org.apache.fop.fo; import java.awt.Color; +import java.nio.Buffer; import java.nio.CharBuffer; import java.text.CharacterIterator; import java.text.StringCharacterIterator; @@ -49,7 +50,7 @@ import org.apache.fop.util.CharUtilities; public class FOText extends FONode implements CharSequence, TextFragment { /** the CharBuffer containing the text */ - private CharBuffer charBuffer; + private Buffer charBuffer; // cached iterator private CharacterIterator charIterator; @@ -135,18 +136,22 @@ public class FOText extends FONode implements CharSequence, TextFragment { } CharBuffer newBuffer = CharBuffer.allocate(newCapacity); charBuffer.rewind(); - newBuffer.put(charBuffer); + newBuffer.put(getCharBuffer()); charBuffer = newBuffer; } } // extend limit to capacity charBuffer.limit(charBuffer.capacity()); // append characters - charBuffer.put(data, start, length); + getCharBuffer().put(data, start, length); // shrink limit to position charBuffer.limit(charBuffer.position()); } + private CharBuffer getCharBuffer() { + return (CharBuffer) charBuffer; + } + /** * Return the array of characters for this instance. * @@ -157,7 +162,7 @@ public class FOText extends FONode implements CharSequence, TextFragment { return null; } this.charBuffer.rewind(); - return this.charBuffer.asReadOnlyBuffer().subSequence(0, this.charBuffer.limit()); + return getCharBuffer().asReadOnlyBuffer().subSequence(0, this.charBuffer.limit()); } /** {@inheritDoc} */ @@ -170,7 +175,7 @@ public class FOText extends FONode implements CharSequence, TextFragment { if (charBuffer != null) { ft.charBuffer = CharBuffer.allocate(charBuffer.limit()); charBuffer.rewind(); - ft.charBuffer.put(charBuffer); + ft.getCharBuffer().put(getCharBuffer()); ft.charBuffer.rewind(); } } @@ -232,7 +237,7 @@ public class FOText extends FONode implements CharSequence, TextFragment { char ch; charBuffer.rewind(); while (charBuffer.hasRemaining()) { - ch = charBuffer.get(); + ch = getCharBuffer().get(); if (!((ch == CharUtilities.SPACE) || (ch == CharUtilities.LINEFEED_CHAR) || (ch == CharUtilities.CARRIAGE_RETURN) @@ -282,12 +287,12 @@ public class FOText extends FONode implements CharSequence, TextFragment { } charBuffer.rewind(); - CharBuffer tmp = charBuffer.slice(); + CharBuffer tmp = getCharBuffer().slice(); char c; int lim = charBuffer.limit(); int pos = -1; while (++pos < lim) { - c = charBuffer.get(); + c = getCharBuffer().get(); switch (textTransform) { case Constants.EN_UPPERCASE: tmp.put(Character.toUpperCase(c)); @@ -537,7 +542,7 @@ public class FOText extends FONode implements CharSequence, TextFragment { if (this.currentPosition < charBuffer.limit()) { this.canRemove = true; this.canReplace = true; - return charBuffer.get(currentPosition++); + return getCharBuffer().get(currentPosition++); } else { throw new NoSuchElementException(); } @@ -550,13 +555,13 @@ public class FOText extends FONode implements CharSequence, TextFragment { if (this.canRemove) { charBuffer.position(currentPosition); // Slice the buffer at the current position - CharBuffer tmp = charBuffer.slice(); + CharBuffer tmp = getCharBuffer().slice(); // Reset position to before current character charBuffer.position(--currentPosition); if (tmp.hasRemaining()) { // Transfer any remaining characters charBuffer.mark(); - charBuffer.put(tmp); + getCharBuffer().put(tmp); charBuffer.reset(); } // Decrease limit @@ -573,7 +578,7 @@ public class FOText extends FONode implements CharSequence, TextFragment { public void replaceChar(char c) { if (this.canReplace) { - charBuffer.put(currentPosition - 1, c); + getCharBuffer().put(currentPosition - 1, c); } else { throw new IllegalStateException(); } @@ -698,7 +703,7 @@ public class FOText extends FONode implements CharSequence, TextFragment { if (charBuffer == null) { return ""; } else { - CharBuffer cb = charBuffer.duplicate(); + Buffer cb = getCharBuffer().duplicate(); cb.rewind(); return cb.toString(); } @@ -725,12 +730,12 @@ public class FOText extends FONode implements CharSequence, TextFragment { /** {@inheritDoc} */ public char charAt(int position) { - return charBuffer.get(position); + return getCharBuffer().get(position); } /** {@inheritDoc} */ public CharSequence subSequence(int start, int end) { - return charBuffer.subSequence(start, end); + return getCharBuffer().subSequence(start, end); } /** {@inheritDoc} */ diff --git a/fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java b/fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java index 929b4bf6f..cbaace8a2 100644 --- a/fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java +++ b/fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java @@ -21,6 +21,7 @@ package org.apache.fop.fonts; import java.awt.Rectangle; import java.io.InputStream; +import java.nio.Buffer; import java.nio.CharBuffer; import java.nio.IntBuffer; import java.util.ArrayList; @@ -682,8 +683,10 @@ public class MultiByteFont extends CIDFont implements Substitutable, Positionabl cb.put(cc); gb.put(gi); } - cb.flip(); - gb.flip(); + Buffer cbBase = cb; + cbBase.flip(); + Buffer gbBase = gb; + gbBase.flip(); if ((associations != null) && (associations.size() == cs.length())) { associations = new java.util.ArrayList(associations); } else { @@ -732,7 +735,8 @@ public class MultiByteFont extends CIDFont implements Substitutable, Positionabl cb.put(c); } - cb.flip(); + Buffer cbBase = cb; + cbBase.flip(); return cb; } @@ -799,7 +803,8 @@ public class MultiByteFont extends CIDFont implements Substitutable, Positionabl nal.add(a); } } - ngb.flip(); + Buffer ngbBase = ngb; + ngbBase.flip(); return new GlyphSequence(gs.getCharacters(), ngb, nal, gs.getPredications()); } else { return gs;