Skip to content

Commit

Permalink
8252199: Reimplement support of Type 1 fonts without MappedByteBuffer
Browse files Browse the repository at this point in the history
Reviewed-by: serb, jdv
  • Loading branch information
prrace committed Sep 20, 2020
1 parent 3d88d38 commit cc7521c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/java.desktop/share/classes/sun/font/Type1Font.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.BufferUnderflowException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel;
Expand Down Expand Up @@ -98,7 +97,7 @@ public Object run() {
}
}

WeakReference<Object> bufferRef = new WeakReference<>(null);
WeakReference<ByteBuffer> bufferRef = new WeakReference<>(null);

private String psName = null;

Expand Down Expand Up @@ -185,8 +184,8 @@ public Type1Font(String platname, Object nativeNames, boolean createdCopy)
}

private synchronized ByteBuffer getBuffer() throws FontFormatException {
MappedByteBuffer mapBuf = (MappedByteBuffer)bufferRef.get();
if (mapBuf == null) {
ByteBuffer bbuf = bufferRef.get();
if (bbuf == null) {
//System.out.println("open T1 " + platName);
try {
RandomAccessFile raf = (RandomAccessFile)
Expand All @@ -202,9 +201,10 @@ public Object run() {
});
FileChannel fc = raf.getChannel();
fileSize = (int)fc.size();
mapBuf = fc.map(FileChannel.MapMode.READ_ONLY, 0, fileSize);
mapBuf.position(0);
bufferRef = new WeakReference<>(mapBuf);
bbuf = ByteBuffer.allocate(fileSize);
fc.read(bbuf);
bbuf.position(0);
bufferRef = new WeakReference<>(bbuf);
fc.close();
} catch (NullPointerException e) {
throw new FontFormatException(e.toString());
Expand All @@ -218,7 +218,7 @@ public Object run() {
throw new FontFormatException(e.toString());
}
}
return mapBuf;
return bbuf;
}

protected void close() {
Expand Down Expand Up @@ -268,14 +268,14 @@ public Object run() {
}

public synchronized ByteBuffer readBlock(int offset, int length) {
ByteBuffer mappedBuf = null;
ByteBuffer bbuf = null;
try {
mappedBuf = getBuffer();
bbuf = getBuffer();
if (offset > fileSize) {
offset = fileSize;
}
mappedBuf.position(offset);
return mappedBuf.slice();
bbuf.position(offset);
return bbuf.slice();
} catch (FontFormatException e) {
return null;
}
Expand Down

1 comment on commit cc7521c

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on cc7521c Sep 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.