aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Schweinsberg <[email protected]>2017-05-15 18:49:18 -0700
committerDavid Schweinsberg <[email protected]>2017-05-15 18:49:18 -0700
commit8688e5d2cdc743906180914d74d83c5a97c565f7 (patch)
treed6975a301cf316deb88b64cbe55c79646ed67336
parent0d38ac68ce3131b7bfe4b7671ef0cd0c1dce9b13 (diff)
Build out COLR and CPAL tables
-rw-r--r--src/net/java/dev/typecast/ot/table/ColrTable.java75
-rw-r--r--src/net/java/dev/typecast/ot/table/CpalTable.java116
2 files changed, 179 insertions, 12 deletions
diff --git a/src/net/java/dev/typecast/ot/table/ColrTable.java b/src/net/java/dev/typecast/ot/table/ColrTable.java
index 7ae60c0..45051d3 100644
--- a/src/net/java/dev/typecast/ot/table/ColrTable.java
+++ b/src/net/java/dev/typecast/ot/table/ColrTable.java
@@ -1,4 +1,18 @@
-
+/*
+ * Copyright (c) David Schweinsberg
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package net.java.dev.typecast.ot.table;
import java.io.DataInput;
@@ -10,27 +24,49 @@ import java.io.IOException;
public class ColrTable implements Table {
public class BaseGlyphRecord {
+
private final int _gid;
private final int _firstLayerIndex;
private final int _numLayers;
-
+
protected BaseGlyphRecord(DataInput di) throws IOException {
_gid = di.readUnsignedShort();
_firstLayerIndex = di.readUnsignedShort();
_numLayers = di.readUnsignedShort();
}
+
+ public int getGid() {
+ return _gid;
+ }
+
+ public int getFirstLayerIndex() {
+ return _firstLayerIndex;
+ }
+
+ public int getNumLayers() {
+ return _numLayers;
+ }
}
-
+
public class LayerRecord {
+
private final int _gid;
private final int _paletteIndex;
-
+
protected LayerRecord(DataInput di) throws IOException {
_gid = di.readUnsignedShort();
_paletteIndex = di.readUnsignedShort();
}
+
+ public int getGid() {
+ return _gid;
+ }
+
+ public int getPaletteIndex() {
+ return _paletteIndex;
+ }
}
-
+
private final DirectoryEntry _de;
private final int _version;
private final int _numBaseGlyphRecords;
@@ -47,12 +83,22 @@ public class ColrTable implements Table {
_offsetBaseGlyphRecord = di.readInt();
_offsetLayerRecord = di.readInt();
_numLayerRecords = di.readUnsignedShort();
-
+
+ int byteCount = 14;
+ if (_offsetBaseGlyphRecord > byteCount) {
+ di.skipBytes(byteCount - _offsetBaseGlyphRecord);
+ }
+
_baseGlyphRecords = new BaseGlyphRecord[_numBaseGlyphRecords];
for (int i = 0; i < _numBaseGlyphRecords; ++i) {
_baseGlyphRecords[i] = new BaseGlyphRecord(di);
+ byteCount += 6;
+ }
+
+ if (_offsetLayerRecord > byteCount) {
+ di.skipBytes(byteCount - _offsetLayerRecord);
}
-
+
_layerRecords = new LayerRecord[_numLayerRecords];
for (int i = 0; i < _numLayerRecords; ++i) {
_layerRecords[i] = new LayerRecord(di);
@@ -61,9 +107,18 @@ public class ColrTable implements Table {
@Override
public String toString() {
- return new StringBuffer()
- .append("'COLR' Table\n---------------------------------------")
- .toString();
+ StringBuilder sb = new StringBuilder();
+ sb.append("'COLR' Table\n------------\nBase Glyph Records\n");
+ for (BaseGlyphRecord record : _baseGlyphRecords) {
+ sb.append(String.format("%d : %d, %d\n", record.getGid(),
+ record.getFirstLayerIndex(), record.getNumLayers()));
+ }
+ sb.append("\nLayer Records\n");
+ for (LayerRecord record : _layerRecords) {
+ sb.append(String.format("%d : %d\n", record.getGid(),
+ record.getPaletteIndex()));
+ }
+ return sb.toString();
}
@Override
diff --git a/src/net/java/dev/typecast/ot/table/CpalTable.java b/src/net/java/dev/typecast/ot/table/CpalTable.java
index 5326537..9a3d384 100644
--- a/src/net/java/dev/typecast/ot/table/CpalTable.java
+++ b/src/net/java/dev/typecast/ot/table/CpalTable.java
@@ -1,4 +1,18 @@
-
+/*
+ * Copyright (c) David Schweinsberg
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package net.java.dev.typecast.ot.table;
import java.io.DataInput;
@@ -9,10 +23,108 @@ import java.io.IOException;
*/
public class CpalTable implements Table {
- private DirectoryEntry _de;
+ public class ColorRecord {
+
+ private final short _blue;
+ private final short _green;
+ private final short _red;
+ private final short _alpha;
+
+ protected ColorRecord(DataInput di) throws IOException {
+ _blue = (short) di.readUnsignedByte();
+ _green = (short) di.readUnsignedByte();
+ _red = (short) di.readUnsignedByte();
+ _alpha = (short) di.readUnsignedByte();
+ }
+
+ public short getBlue() {
+ return _blue;
+ }
+
+ public short getGreen() {
+ return _green;
+ }
+
+ public short getRed() {
+ return _red;
+ }
+
+ public short getAlpha() {
+ return _alpha;
+ }
+ }
+
+ private final DirectoryEntry _de;
+ private final int _version;
+ private final int _numPalettesEntries;
+ private final int _numPalette;
+ private final int _numColorRecords;
+ private final int _offsetFirstColorRecord;
+ private final int[] _colorRecordIndices;
+ private final int _offsetPaletteTypeArray;
+ private final int _offsetPaletteLabelArray;
+ private final int _offsetPaletteEntryLabelArray;
+ private final ColorRecord[] _colorRecords;
protected CpalTable(DirectoryEntry de, DataInput di) throws IOException {
this._de = (DirectoryEntry) de.clone();
+ _version = di.readUnsignedShort();
+ _numPalettesEntries = di.readUnsignedShort();
+ _numPalette = di.readUnsignedShort();
+ _numColorRecords = di.readUnsignedShort();
+ _offsetFirstColorRecord = di.readInt();
+
+ int byteCount = 12;
+ _colorRecordIndices = new int[_numPalette];
+ for (int i = 0; i < _numPalette; ++i) {
+ _colorRecordIndices[i] = di.readUnsignedShort();
+ byteCount += 2;
+ }
+ if (_version == 1) {
+ _offsetPaletteTypeArray = di.readInt();
+ _offsetPaletteLabelArray = di.readInt();
+ _offsetPaletteEntryLabelArray = di.readInt();
+ byteCount += 12;
+ } else {
+ _offsetPaletteTypeArray = -1;
+ _offsetPaletteLabelArray = -1;
+ _offsetPaletteEntryLabelArray = -1;
+ }
+
+ if (_offsetFirstColorRecord > byteCount) {
+ di.skipBytes(byteCount - _offsetFirstColorRecord);
+ }
+
+ _colorRecords = new ColorRecord[_numColorRecords];
+ for (int i = 0; i < _numColorRecords; ++i) {
+ _colorRecords[i] = new ColorRecord(di);
+ }
+
+ if (_version == 1) {
+ // TODO find some sample version 1 content
+ }
+ }
+
+ public int getNumPalettesEntries() {
+ return _numPalettesEntries;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("'CPAL' Table\n------------\nColor Record Indices\n");
+ int i = 0;
+ for (int index : _colorRecordIndices) {
+ sb.append(String.format("%d: %d\n", i++, index));
+ }
+ sb.append("\nColor Records\n");
+ i = 0;
+ for (ColorRecord record : _colorRecords) {
+ sb.append(String.format("%d: B: %3d, G: %3d, R: %3d, A: %3d\n",
+ i++, record.getBlue(), record.getGreen(), record.getRed(),
+ record.getAlpha()));
+ }
+ return sb.toString();
}
@Override