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 b00d8c9 commit 5365df7
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions src/main/java/org/mabb/fontverter/opentype/NameTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.mabb.fontverter.opentype;

import org.mabb.fontverter.io.DataTypeBindingDeserializer;
import org.mabb.fontverter.io.FontDataInput;
import org.mabb.fontverter.io.FontDataInputStream;
import org.mabb.fontverter.io.FontDataOutputStream;
import org.slf4j.Logger;
Expand Down Expand Up @@ -52,60 +51,61 @@ public static NameTable createDefaultTable() {
}

public void readData(byte[] data) throws IOException {
FontDataInput reader = new FontDataInputStream(data);
formatSelector = reader.readUnsignedShort();
if (formatSelector > 0) {
log.warn("nametable format 1 reading not implemented");
return;
}

// read record headers first then thier actual strings
int count = reader.readUnsignedShort();
int stringOffset = reader.readUnsignedShort();
for (int i = 0; i < count; i++) {
DataTypeBindingDeserializer deserializer = new DataTypeBindingDeserializer();
NameRecord record = (NameRecord) deserializer.deserialize(reader, NameRecord.class);
nameRecords.add(record);
}


// discard junk bytes between offset to actual string storage
try (FontDataInputStream reader = new FontDataInputStream(data)) {
formatSelector = reader.readUnsignedShort();
if (formatSelector > 0) {
log.warn("nametable format 1 reading not implemented");
return;
}

// read record headers first then thier actual strings
int count = reader.readUnsignedShort();
int stringOffset = reader.readUnsignedShort();
for (int i = 0; i < count; i++) {
DataTypeBindingDeserializer deserializer = new DataTypeBindingDeserializer();
NameRecord record = (NameRecord) deserializer.deserialize(reader, NameRecord.class);
nameRecords.add(record);
}

// discard junk bytes between offset to actual string storage
// reader.readBytes(stringOffset - reader.getPosition());

for (int i = 0; i < count; i++) {
NameRecord recordOn = nameRecords.get(i);
reader.seek(recordOn.offset + stringOffset);
for (int i = 0; i < count; i++) {
NameRecord recordOn = nameRecords.get(i);
reader.seek(recordOn.offset + stringOffset);

String nameOn = reader.readString(recordOn.length);
recordOn.setStringData(nameOn);
}
String nameOn = reader.readString(recordOn.length);
recordOn.setStringData(nameOn);
}
}
}

protected byte[] generateUnpaddedData() throws IOException {
FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET);
writer.writeUnsignedShort(formatSelector);
writer.writeUnsignedShort(nameRecords.size());
writer.writeUnsignedShort(getOffsetToStringStorage());
try (FontDataOutputStream writer = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET)) {
writer.writeUnsignedShort(formatSelector);
writer.writeUnsignedShort(nameRecords.size());
writer.writeUnsignedShort(getOffsetToStringStorage());

calculateOffsets();
calculateOffsets();

Collections.sort(nameRecords, new Comparator<NameRecord>() {
@Override
public int compare(NameRecord o1, NameRecord o2) {
if (o1.platformID != o2.platformID)
return o1.platformID < o2.platformID ? -1 : 1;
return o1.nameID < o2.nameID ? -1 : o1.nameID == o2.nameID ? 0 : 1;
Collections.sort(nameRecords, new Comparator<NameRecord>() {
@Override
public int compare(NameRecord o1, NameRecord o2) {
if (o1.platformID != o2.platformID)
return o1.platformID < o2.platformID ? -1 : 1;
return o1.nameID < o2.nameID ? -1 : o1.nameID == o2.nameID ? 0 : 1;

}
});
}
});

for (NameRecord record : nameRecords)
writer.write(record.getRecordData());
for (NameRecord record : nameRecords)
writer.write(record.getRecordData());

for (NameRecord record : nameRecords)
writer.write(record.getStringData());
for (NameRecord record : nameRecords)
writer.write(record.getStringData());

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

public String getTableType() {
Expand Down

0 comments on commit 5365df7

Please sign in to comment.