[FOray-commit] SF.net SVN: foray: [6872] trunk/foray/foray-ps/src/java/org/foray/ps/encode
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2006-03-04 12:38:13
|
Revision: 6872 Author: victormote Date: 2006-03-04 04:37:53 -0800 (Sat, 04 Mar 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=6872&view=rev Log Message: ----------- 1. Create new classes to handle TrueType CMap Format 12 tables (32-bit entries). 2. Create abstract superclass for all CMap classes. Modified Paths: -------------- trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap04.java trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap04Entry.java Added Paths: ----------- trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap.java trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap12.java trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap12Entry.java Added: trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap.java =================================================================== --- trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap.java (rev 0) +++ trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap.java 2006-03-04 12:37:53 UTC (rev 6872) @@ -0,0 +1,36 @@ +/* + * Copyright 2006 The FOray Project. + * http://www.foray.org + * + * 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. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +package org.foray.ps.encode; + +/** + * Abstract superclass for all CMap Tables. + */ +public abstract class CMap extends Encoding { + + public CMap(String name) { + super(name); + } + +} Modified: trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap04.java =================================================================== --- trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap04.java 2006-03-04 12:06:03 UTC (rev 6871) +++ trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap04.java 2006-03-04 12:37:53 UTC (rev 6872) @@ -25,11 +25,11 @@ package org.foray.ps.encode; /** - * Class containing a set of Unicode ranges that sequentially map to the + * Class containing a set of 16-bit Unicode ranges that sequentially map to the * same-sized range of glyph indexes. The contents are analogous to a Format 4 * TrueType Font cmap table (from which this class derives its name). */ -public class CMap04 extends Encoding { +public class CMap04 extends CMap { private CMap04Entry[] entries; Modified: trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap04Entry.java =================================================================== --- trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap04Entry.java 2006-03-04 12:06:03 UTC (rev 6871) +++ trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap04Entry.java 2006-03-04 12:37:53 UTC (rev 6872) @@ -25,7 +25,8 @@ package org.foray.ps.encode; /** - * Contains one entry from a CMap table. + * Contains one entry from a TrueType CMap subtable, format 4, which handles + * 16-bit Unicode codepoint ranges. */ public class CMap04Entry { public char unicodeStart; Added: trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap12.java =================================================================== --- trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap12.java (rev 0) +++ trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap12.java 2006-03-04 12:37:53 UTC (rev 6872) @@ -0,0 +1,110 @@ +/* + * Copyright 2006 The FOray Project. + * http://www.foray.org + * + * 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. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +package org.foray.ps.encode; + +/** + * Class containing a set of 32-bit Unicode ranges that sequentially map to the + * same-sized range of glyph indexes. The contents are analogous to a Format 12 + * TrueType Font cmap table (from which this class derives its name). + */ +public class CMap12 extends CMap { + + private CMap12Entry[] entries; + + private int lastEntryAdded = -1; + + public CMap12 (String name, int expectedEntries) { + super(name); + this.entries = new CMap12Entry[expectedEntries]; + } + + public void addEntry(CMap12Entry entry) { + lastEntryAdded++; + if (lastEntryAdded >= entries.length) { + // Fails silently. + return; + } + this.entries[lastEntryAdded] = entry; + } + + public void addEntry(char unicodeStart, char unicodeEnd, + char glyphStartIndex) { + CMap12Entry newEntry = new CMap12Entry(unicodeStart, unicodeEnd, + glyphStartIndex); + addEntry(newEntry); + } + + public int encodeCharacter(int codePoint) { + CMap12Entry entry = entryForChar((char) codePoint); + if (entry == null) { + return 0; + } + return entry.encodeCharacter(codePoint); + } + + private CMap12Entry entryForChar(int codePoint) { + for (int i = 0; i < entries.length; i++) { + if (entries[i].containsChar(codePoint)) { + return entries[i]; + } + } + return null; + } + + /** + * {@inheritDoc} + */ + public int decodeCharacter(int glyphIndexInput) { + for (int i = 0; i < entries.length; i++) { + int codePoint = entries[i].decodeCharacter(glyphIndexInput); + if (codePoint != Character.MAX_VALUE) { + return codePoint; + } + } + return Character.MAX_VALUE; + } + + /** + * {@inheritDoc} + */ + public String asPostScript(org.axsl.ps.Encoding baseEncoding) { + return null; + } + + /** + * {@inheritDoc} + */ + public int getFirstIndex() { + return INVALID_UNICODE_CHAR; + } + + /** + * {@inheritDoc} + */ + public int getLastIndex() { + return INVALID_UNICODE_CHAR; + } + +} Added: trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap12Entry.java =================================================================== --- trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap12Entry.java (rev 0) +++ trunk/foray/foray-ps/src/java/org/foray/ps/encode/CMap12Entry.java 2006-03-04 12:37:53 UTC (rev 6872) @@ -0,0 +1,77 @@ +/* + * Copyright 2006 The FOray Project. + * http://www.foray.org + * + * 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. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id: CMap04Entry.java 6871 2006-03-04 12:06:03Z victormote $ */ + +package org.foray.ps.encode; + +/** + * Contains one entry from a TrueType CMap subtable, Format 12, which handles + * 32-bit Unicode codepoint ranges. + */ +public class CMap12Entry { + public int unicodeStart; + public int unicodeEnd; + public int glyphStartIndex; + + public CMap12Entry(int unicodeStart, int unicodeEnd, int glyphStartIndex) { + this.unicodeStart = unicodeStart; + this.unicodeEnd = unicodeEnd; + this.glyphStartIndex = glyphStartIndex; + } + + /** + * Compute the glyphEndIndex that is implied from the raw data. + * @return The last glyphIndex that is addressed by this entry, i.e. the + * glyph index that corresponds to unicodeEnd. + */ + public int getGlyphEndIndex() { + return glyphStartIndex + unicodeEnd - unicodeStart; + } + + public boolean containsChar(int codePoint) { + if (codePoint < this.unicodeStart) { + return false; + } + if (codePoint > this.unicodeEnd) { + return false; + } + return true; + } + + public int encodeCharacter(int codePoint) { + if (! containsChar(codePoint)) { + return 0; + } + return codePoint - this.unicodeStart + this.glyphStartIndex; + } + + public int decodeCharacter(int glyphIndex) { + int codePoint = glyphIndex - this.glyphStartIndex + this.unicodeStart; + if (glyphIndex >= this.glyphStartIndex + && codePoint <= this.unicodeStart) { + return codePoint; + } + return Character.MAX_VALUE; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |