001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.svggen.font.table;
020:
021: import java.io.ByteArrayInputStream;
022: import java.io.IOException;
023: import java.io.RandomAccessFile;
024:
025: /**
026: * @version $Id: GlyfTable.java 475477 2006-11-15 22:44:28Z cam $
027: * @author <a href="mailto:david@steadystate.co.uk">David Schweinsberg</a>
028: */
029: public class GlyfTable implements Table {
030:
031: private byte[] buf = null;
032: private GlyfDescript[] descript;
033:
034: protected GlyfTable(DirectoryEntry de, RandomAccessFile raf)
035: throws IOException {
036: raf.seek(de.getOffset());
037: buf = new byte[de.getLength()];
038: raf.read(buf);
039: /*
040: TableMaxp t_maxp = (TableMaxp) td.getEntryByTag(maxp).getTable();
041: TableLoca t_loca = (TableLoca) td.getEntryByTag(loca).getTable();
042: descript = new TableGlyfDescript[t_maxp.getNumGlyphs()];
043: for (int i = 0; i < t_maxp.getNumGlyphs(); i++) {
044: raf.seek(tde.getOffset() + t_loca.getOffset(i));
045: int len = t_loca.getOffset((short)(i + 1)) - t_loca.getOffset(i);
046: if (len > 0) {
047: short numberOfContours = raf.readShort();
048: if (numberOfContours < 0) {
049: // descript[i] = new TableGlyfCompositeDescript(this, raf);
050: } else {
051: descript[i] = new TableGlyfSimpleDescript(this, numberOfContours, raf);
052: }
053: } else {
054: descript[i] = null;
055: }
056: }
057:
058: for (int i = 0; i < t_maxp.getNumGlyphs(); i++) {
059: raf.seek(tde.getOffset() + t_loca.getOffset(i));
060: int len = t_loca.getOffset((short)(i + 1)) - t_loca.getOffset(i);
061: if (len > 0) {
062: short numberOfContours = raf.readShort();
063: if (numberOfContours < 0) {
064: descript[i] = new TableGlyfCompositeDescript(this, raf);
065: }
066: }
067: }
068: */
069: }
070:
071: public void init(int numGlyphs, LocaTable loca) {
072: if (buf == null) {
073: return;
074: }
075: descript = new GlyfDescript[numGlyphs];
076: ByteArrayInputStream bais = new ByteArrayInputStream(buf);
077: for (int i = 0; i < numGlyphs; i++) {
078: int len = loca.getOffset((i + 1)) - loca.getOffset(i);
079: if (len > 0) {
080: bais.reset();
081: bais.skip(loca.getOffset(i));
082: short numberOfContours = (short) (bais.read() << 8 | bais
083: .read());
084: if (numberOfContours >= 0) {
085: descript[i] = new GlyfSimpleDescript(this ,
086: numberOfContours, bais);
087: } else {
088: descript[i] = new GlyfCompositeDescript(this , bais);
089: }
090: }
091: }
092:
093: buf = null;
094:
095: for (int i = 0; i < numGlyphs; i++) {
096: if (descript[i] == null)
097: continue;
098:
099: descript[i].resolve();
100: }
101: }
102:
103: public GlyfDescript getDescription(int i) {
104: return descript[i];
105: }
106:
107: public int getType() {
108: return glyf;
109: }
110: }
|