Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8252199: Reimplement support of Type 1 fonts without MappedByteBuffer #258

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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;
@@ -98,7 +97,7 @@ public Object run() {
}
}

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

private String psName = null;

@@ -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)
@@ -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());
@@ -218,7 +218,7 @@ public Object run() {
throw new FontFormatException(e.toString());
}
}
return mapBuf;
return bbuf;
}

protected void close() {
@@ -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;
}