Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
batzorent committed Aug 22, 2019
1 parent 95bb101 commit 2155832
Showing 1 changed file with 97 additions and 77 deletions.
174 changes: 97 additions & 77 deletions src/main/java/org/mabb/fontverter/opentype/CmapSubTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ abstract class CmapSubTable {
private int platformId;
private int encodingId;
private long subTableOffset;
private int[] glyphIdToCharacterCode;
private Map<Integer, Integer> characterCodeToGlyphId;

public long getSubTableOffset() {
return subTableOffset;
Expand All @@ -53,11 +51,13 @@ public void setSubTableOffset(long subTableOffset) {
}

public byte[] getRecordData() throws IOException {
FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET);
writer.writeUnsignedShort(platformId);
writer.writeUnsignedShort(encodingId);
writer.writeUnsignedInt((int) subTableOffset);
return writer.toByteArray();
try (FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET)) {
writer.writeUnsignedShort(platformId);
writer.writeUnsignedShort(encodingId);
writer.writeUnsignedInt((int) subTableOffset);

return writer.toByteArray();
}
}

public int getPlatformId() {
Expand Down Expand Up @@ -99,26 +99,27 @@ public Format0SubTable() {

@Override
public byte[] getData() throws IOException {
FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET);
try (FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET)) {

// kludge for read otf fonts
if (rawReadData != null) {
writer.writeUnsignedShort(formatNumber);
writer.writeUnsignedShort(rawReadData.length + 4);
writer.write(rawReadData);
// kludge for read otf fonts
if (rawReadData != null) {
writer.writeUnsignedShort(formatNumber);
writer.writeUnsignedShort(rawReadData.length + 4);
writer.write(rawReadData);

return writer.toByteArray();
}
return writer.toByteArray();
}

writer.writeUnsignedShort((int) formatNumber);
writer.writeUnsignedShort(getLength());
writer.writeUnsignedShort((int) getLanguageId());
writer.writeUnsignedShort((int) formatNumber);
writer.writeUnsignedShort(getLength());
writer.writeUnsignedShort((int) getLanguageId());

for (Map.Entry<Integer, Integer> entry : charCodeToGlyphId.entrySet()) {
writer.writeByte(entry.getValue());
}
for (Map.Entry<Integer, Integer> entry : charCodeToGlyphId.entrySet()) {
writer.writeByte(entry.getValue());
}

return writer.toByteArray();
return writer.toByteArray();
}
}

public int glyphCount() {
Expand All @@ -134,7 +135,8 @@ public void addGlyphMapping(int characterCode, int glyphId) {
charCodeToGlyphId.put(characterCode, glyphId);
}

public void readData(FontDataInput input) throws IOException {
@SuppressWarnings("resource")
public void readData(FontDataInput input) throws IOException {
int length = input.readUnsignedShort();
rawReadData = input.readBytes(length - 4);
input = new FontDataInputStream(rawReadData);
Expand All @@ -148,19 +150,21 @@ public Format2SubTable() {

public byte[] getData() throws IOException {
// kludge for read otf fonts
FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET);
writer.writeUnsignedShort(formatNumber);
writer.writeUnsignedShort(rawReadData.length + 4);
writer.write(rawReadData);
try (FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET)) {
writer.writeUnsignedShort(formatNumber);
writer.writeUnsignedShort(rawReadData.length + 4);
writer.write(rawReadData);

return writer.toByteArray();
return writer.toByteArray();
}
}

public int glyphCount() {
return 0;
}

public void readData(FontDataInput input) throws IOException {
@SuppressWarnings("resource")
public void readData(FontDataInput input) throws IOException {
int length = input.readUnsignedShort();
rawReadData = input.readBytes(length - 4);
input = new FontDataInputStream(rawReadData);
Expand All @@ -175,19 +179,21 @@ public Format6SubTable() {

public byte[] getData() throws IOException {
// kludge for read otf fonts
FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET);
writer.writeUnsignedShort(formatNumber);
writer.writeUnsignedShort(rawReadData.length + 4);
writer.write(rawReadData);
try (FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET)) {
writer.writeUnsignedShort(formatNumber);
writer.writeUnsignedShort(rawReadData.length + 4);
writer.write(rawReadData);

return writer.toByteArray();
return writer.toByteArray();
}
}

public int glyphCount() {
return 0;
}

public void readData(FontDataInput input) throws IOException {
@SuppressWarnings("resource")
public void readData(FontDataInput input) throws IOException {
int length = input.readUnsignedShort();
rawReadData = input.readBytes(length - 4);
input = new FontDataInputStream(rawReadData);
Expand All @@ -202,22 +208,25 @@ public Format8SubTable() {

public byte[] getData() throws IOException {
// kludge for read otf fonts
FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET);
writer.writeUnsignedShort(formatNumber);
// reserved
writer.writeUnsignedShort(0);
writer.writeUnsignedInt(rawReadData.length + 8);
writer.write(rawReadData);
try (FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET)) {
writer.writeUnsignedShort(formatNumber);
// reserved
writer.writeUnsignedShort(0);
writer.writeUnsignedInt(rawReadData.length + 8);
writer.write(rawReadData);

return writer.toByteArray();
return writer.toByteArray();
}
}

public int glyphCount() {
return 0;
}

public void readData(FontDataInput input) throws IOException {
int reserved = input.readUnsignedShort();
@SuppressWarnings("resource")
public void readData(FontDataInput input) throws IOException {
// int reserved =
input.readUnsignedShort();
long length = input.readUnsignedInt();
rawReadData = input.readBytes((int) (length - 8));
input = new FontDataInputStream(rawReadData);
Expand All @@ -232,22 +241,25 @@ public Format10SubTable() {

public byte[] getData() throws IOException {
// kludge for read otf fonts
FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET);
writer.writeUnsignedShort(formatNumber);
// reserved
writer.writeUnsignedShort(0);
writer.writeUnsignedInt(rawReadData.length + 8);
writer.write(rawReadData);
try (FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET)) {
writer.writeUnsignedShort(formatNumber);
// reserved
writer.writeUnsignedShort(0);
writer.writeUnsignedInt(rawReadData.length + 8);
writer.write(rawReadData);

return writer.toByteArray();
return writer.toByteArray();
}
}

public int glyphCount() {
return 0;
}

public void readData(FontDataInput input) throws IOException {
int reserved = input.readUnsignedShort();
@SuppressWarnings("resource")
public void readData(FontDataInput input) throws IOException {
// int reserved =
input.readUnsignedShort();
long length = input.readUnsignedInt();
rawReadData = input.readBytes((int) (length - 8));
input = new FontDataInputStream(rawReadData);
Expand All @@ -262,22 +274,25 @@ public Format12SubTable() {

public byte[] getData() throws IOException {
// kludge for read otf fonts
FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET);
writer.writeUnsignedShort(formatNumber);
// reserved
writer.writeUnsignedShort(0);
writer.writeUnsignedInt(rawReadData.length + 8);
writer.write(rawReadData);
try (FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET)) {
writer.writeUnsignedShort(formatNumber);
// reserved
writer.writeUnsignedShort(0);
writer.writeUnsignedInt(rawReadData.length + 8);
writer.write(rawReadData);

return writer.toByteArray();
return writer.toByteArray();
}
}

public int glyphCount() {
return 0;
}

public void readData(FontDataInput input) throws IOException {
int reserved = input.readUnsignedShort();
@SuppressWarnings("resource")
public void readData(FontDataInput input) throws IOException {
// int reserved =
input.readUnsignedShort();
long length = input.readUnsignedInt();
rawReadData = input.readBytes((int) (length - 8));
input = new FontDataInputStream(rawReadData);
Expand All @@ -293,22 +308,25 @@ public Format13SubTable() {

public byte[] getData() throws IOException {
// kludge for read otf fonts
FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET);
writer.writeUnsignedShort(formatNumber);
// reserved
writer.writeUnsignedShort(0);
writer.writeUnsignedInt(rawReadData.length + 8);
writer.write(rawReadData);
try (FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET)) {
writer.writeUnsignedShort(formatNumber);
// reserved
writer.writeUnsignedShort(0);
writer.writeUnsignedInt(rawReadData.length + 8);
writer.write(rawReadData);

return writer.toByteArray();
return writer.toByteArray();
}
}

public int glyphCount() {
return 0;
}

public void readData(FontDataInput input) throws IOException {
int reserved = input.readUnsignedShort();
@SuppressWarnings("resource")
public void readData(FontDataInput input) throws IOException {
// int reserved =
input.readUnsignedShort();
long length = input.readUnsignedInt();
rawReadData = input.readBytes((int) (length - 8));
input = new FontDataInputStream(rawReadData);
Expand All @@ -324,19 +342,21 @@ public Format14SubTable() {

public byte[] getData() throws IOException {
// kludge for read otf fonts
FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET);
writer.writeUnsignedShort(formatNumber);
writer.writeUnsignedInt(rawReadData.length + 6);
writer.write(rawReadData);
try (FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET)) {
writer.writeUnsignedShort(formatNumber);
writer.writeUnsignedInt(rawReadData.length + 6);
writer.write(rawReadData);

return writer.toByteArray();
return writer.toByteArray();
}
}

public int glyphCount() {
return 0;
}

public void readData(FontDataInput input) throws IOException {
@SuppressWarnings("resource")
public void readData(FontDataInput input) throws IOException {
long length = input.readUnsignedInt();
rawReadData = input.readBytes((int) (length - 6));
input = new FontDataInputStream(rawReadData);
Expand Down

0 comments on commit 2155832

Please sign in to comment.