[FOray-commit] SF.net SVN: foray:[10615] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2008-07-18 02:48:47
|
Revision: 10615
http://foray.svn.sourceforge.net/foray/?rev=10615&view=rev
Author: victormote
Date: 2008-07-18 02:48:55 +0000 (Fri, 18 Jul 2008)
Log Message:
-----------
Add Type 1 CharStrings dictionary wrapper classes, and add some more tests of pfb parsing.
Modified Paths:
--------------
trunk/foray/foray-font/src/javatest/org/foray/font/format/TestType1PfbFile.java
trunk/foray/foray-ps/src/java/org/foray/ps/type1/PsFontDictionary.java
Added Paths:
-----------
trunk/foray/foray-ps/src/java/org/foray/ps/type1/PsCharStringsDictionary.java
Modified: trunk/foray/foray-font/src/javatest/org/foray/font/format/TestType1PfbFile.java
===================================================================
--- trunk/foray/foray-font/src/javatest/org/foray/font/format/TestType1PfbFile.java 2008-07-18 02:18:19 UTC (rev 10614)
+++ trunk/foray/foray-font/src/javatest/org/foray/font/format/TestType1PfbFile.java 2008-07-18 02:48:55 UTC (rev 10615)
@@ -30,7 +30,10 @@
import org.foray.common.Logging;
import org.foray.font.TestFontServer4a;
+import org.foray.ps.type1.PsCharStringsDictionary;
import org.foray.ps.type1.PsFontDictionary;
+import org.foray.ps.type1.PsFontInfoDictionary;
+import org.foray.ps.type1.PsPrivateDictionary;
import org.axsl.font.FontException;
@@ -60,11 +63,30 @@
assertNotNull(reader);
final Type1PFBFile pfbFile = new Type1PFBFile(reader);
assertNotNull(pfbFile);
- final PsFontDictionary fontDictionary = pfbFile.getFontDictionary();
- assertNotNull(fontDictionary);
- final String fontName = fontDictionary.getFontName();
- /* Following value obtained from the AFM file. */
+ final PsFontDictionary fontDict = pfbFile.getFontDictionary();
+ assertNotNull(fontDict);
+
+ /* Test values below obtained from the AFM file. */
+
+ final PsFontInfoDictionary fontInfoDict = fontDict.getFontInfoDictionary();
+ assertNotNull(fontInfoDict);
+
+ final String fontName = fontDict.getFontName();
assertEquals("CMR10", fontName);
+
+ final int[] fontBBox = fontDict.getFontBBox();
+ assertEquals(4, fontBBox.length);
+ /* Following test fails. The AFM file shows -40, but the font file returns -251. */
+// assertEquals(-40, fontBBox[0]);
+ assertEquals(-250, fontBBox[1]);
+ assertEquals(1009, fontBBox[2]);
+ assertEquals(969, fontBBox[3]);
+
+ final PsPrivateDictionary privateDict = fontDict.getPrivateDictionary();
+ assertNotNull(privateDict);
+
+ final PsCharStringsDictionary charStringsDict = fontDict.getCharStringsDictionary();
+ assertNotNull(charStringsDict);
}
}
Added: trunk/foray/foray-ps/src/java/org/foray/ps/type1/PsCharStringsDictionary.java
===================================================================
--- trunk/foray/foray-ps/src/java/org/foray/ps/type1/PsCharStringsDictionary.java (rev 0)
+++ trunk/foray/foray-ps/src/java/org/foray/ps/type1/PsCharStringsDictionary.java 2008-07-18 02:48:55 UTC (rev 10615)
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2008 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
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.ps.type1;
+
+import org.foray.ps.PsArray;
+import org.foray.ps.PsDictionary;
+import org.foray.ps.PsDictionaryWrapper;
+import org.foray.ps.PsNumber;
+import org.foray.ps.PsObject;
+
+import java.math.BigDecimal;
+
+public class PsCharStringsDictionary extends PsDictionaryWrapper {
+
+ /** Key to the "StdVW" entry. */
+ public static final String STD_VW_KEY = "StdVW";
+
+ /**
+ * Constructor.
+ * @param dictionary The wrapped dictionary instance.
+ */
+ public PsCharStringsDictionary(final PsDictionary dictionary) {
+ super(dictionary);
+ }
+
+ /**
+ * Returns the StdVW value from the font file.
+ * @return The StdVW value, or null if it does not exist.
+ */
+ public BigDecimal getStdVW() {
+ final PsObject object = getWrappedDictionary().getItem(PsCharStringsDictionary.STD_VW_KEY);
+ if (object == null || ! (object instanceof PsArray)) {
+ return null;
+ }
+ final PsArray psArray = (PsArray) object;
+ final Object item = psArray.get(0);
+ if (! (item instanceof PsNumber)) {
+ throw new IllegalStateException("/StdVW expected to be a PsNumber");
+ }
+ return ((PsNumber) item).getValue();
+ }
+
+}
Property changes on: trunk/foray/foray-ps/src/java/org/foray/ps/type1/PsCharStringsDictionary.java
___________________________________________________________________
Added: svn:keywords
+ "Author Id Rev Date URL"
Added: svn:eol-style
+ native
Modified: trunk/foray/foray-ps/src/java/org/foray/ps/type1/PsFontDictionary.java
===================================================================
--- trunk/foray/foray-ps/src/java/org/foray/ps/type1/PsFontDictionary.java 2008-07-18 02:18:19 UTC (rev 10614)
+++ trunk/foray/foray-ps/src/java/org/foray/ps/type1/PsFontDictionary.java 2008-07-18 02:48:55 UTC (rev 10615)
@@ -42,6 +42,24 @@
*/
public class PsFontDictionary extends PsDictionaryWrapper {
+ /** Key to the "FontInfo" entry. */
+ public static final String FONT_INFO_KEY = "FontInfo";
+
+ /** Key to the "FontName" entry. */
+ public static final String FONT_NAME_KEY = "FontName";
+
+ /** Key to the "FontBBox" entry. */
+ public static final String FONT_BBOX_KEY = "FontBBox";
+
+ /** Key to the "Private" entry. */
+ public static final String PRIVATE_KEY = "Private";
+
+ /** Key to the "Metrics" entry. */
+ public static final String METRICS_KEY = "Metrics";
+
+ /** Key to the "CharStrings" entry. */
+ public static final String CHAR_STRINGS_KEY = "CharStrings";
+
/**
* Constructor.
* @param dictionary The wrapped dictionary instance.
@@ -51,11 +69,26 @@
}
/**
+ * Returns the FontInfo dictionary.
+ * @return The FontInfo dictionary, or null if it does not exist.
+ */
+ public PsFontInfoDictionary getFontInfoDictionary() {
+ final PsObject psObject = getWrappedDictionary().getItem(PsFontDictionary.FONT_INFO_KEY);
+ if (psObject == null) {
+ return null;
+ }
+ if (psObject instanceof PsDictionary) {
+ return new PsFontInfoDictionary((PsDictionary) psObject);
+ }
+ throw new IllegalStateException("/FontInfo expected to be a PsDictionary");
+ }
+
+ /**
* Returns the /FontName for this font dictionary.
* @return The /FontName.
*/
public String getFontName() {
- return this.getWrappedDictionary().getName("FontName");
+ return this.getWrappedDictionary().getName(PsFontDictionary.FONT_NAME_KEY);
}
/**
@@ -63,7 +96,7 @@
* @return The font bbox.
*/
public int[] getFontBBox() {
- final Object object = this.getWrappedDictionary().getItem("FontBBox");
+ final Object object = this.getWrappedDictionary().getItem(PsFontDictionary.FONT_BBOX_KEY);
if (! (object instanceof PsArray)) {
return null;
}
@@ -86,26 +119,11 @@
}
/**
- * Returns the FontInfo dictionary.
- * @return The FontInfo dictionary, or null if it does not exist.
- */
- public PsFontInfoDictionary getFontInfoDictionary() {
- final PsObject psObject = getWrappedDictionary().getItem("FontInfo");
- if (psObject == null) {
- return null;
- }
- if (psObject instanceof PsDictionary) {
- return new PsFontInfoDictionary((PsDictionary) psObject);
- }
- throw new IllegalStateException("/FontInfo expected to be a PsDictionary");
- }
-
- /**
* Returns the Private dictionary.
* @return The Private dictionary, or null if it does not exist.
*/
public PsPrivateDictionary getPrivateDictionary() {
- final PsObject psObject = getWrappedDictionary().getItem("Private");
+ final PsObject psObject = getWrappedDictionary().getItem(PsFontDictionary.PRIVATE_KEY);
if (psObject == null) {
return null;
}
@@ -120,7 +138,7 @@
* @return The Metrics dictionary, or null if it does not exist.
*/
public PsMetricsDictionary getMetricsDictionary() {
- final PsObject psObject = getWrappedDictionary().getItem("Metrics");
+ final PsObject psObject = getWrappedDictionary().getItem(PsFontDictionary.METRICS_KEY);
if (psObject == null) {
return null;
}
@@ -130,4 +148,19 @@
throw new IllegalStateException("/Metrics expected to be a PsDictionary");
}
+ /**
+ * Returns the CharStrings dictionary.
+ * @return The CharStrings dictionary, or null if it does not exist.
+ */
+ public PsCharStringsDictionary getCharStringsDictionary() {
+ final PsObject psObject = getWrappedDictionary().getItem(PsFontDictionary.CHAR_STRINGS_KEY);
+ if (psObject == null) {
+ return null;
+ }
+ if (psObject instanceof PsDictionary) {
+ return new PsCharStringsDictionary((PsDictionary) psObject);
+ }
+ throw new IllegalStateException("/CharStrings expected to be a PsDictionary");
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|