You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2010/09/15 18:11:02 UTC
svn commit: r997381 - in
/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap: CMap.java
CMapParser.java
Author: lehmi
Date: Wed Sep 15 16:11:01 2010
New Revision: 997381
URL: http://svn.apache.org/viewvc?rev=997381&view=rev
Log:
PDFBOX-704: improved CMapParser based on suggestions of Eric Leleu
Modified:
pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java
pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java
Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java?rev=997381&r1=997380&r2=997381&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java Wed Sep 15 16:11:01 2010
@@ -32,6 +32,16 @@ import java.util.Iterator;
*/
public class CMap
{
+
+ private int wmode = 0;
+ private String cmapName = null;
+ private String cmapVersion = null;
+ private int cmapType = -1;
+
+ private String registry = null;
+ private String ordering = null;
+ private int supplement = 0;
+
private List<CodespaceRange> codeSpaceRanges = new ArrayList<CodespaceRange>();
private Map<Integer,String> singleByteMappings = new HashMap<Integer,String>();
private Map<Integer,String> doubleByteMappings = new HashMap<Integer,String>();
@@ -223,5 +233,147 @@ public class CMap
}
}
return false;
- }
+ }
+
+ /**
+ * Returns the WMode of a CMap.
+ *
+ * 0 represents a horizontal and 1 represents a vertical orientation.
+ *
+ * @return
+ */
+ public int getWMode()
+ {
+ return wmode;
+ }
+
+ /**
+ * Sets the WMode of a CMap.
+ *
+ * @param newWMode the new WMode.
+ */
+ public void setWMode(int newWMode)
+ {
+ wmode = newWMode;
+ }
+
+ /**
+ * Returns the name of the CMap.
+ *
+ * @return the CMap name.
+ */
+ public String getName()
+ {
+ return cmapName;
+ }
+
+ /**
+ * Sets the name of the CMap.
+ *
+ * @param name the CMap name.
+ */
+ public void setName(String name)
+ {
+ cmapName = name;
+ }
+
+ /**
+ * Returns the version of the CMap.
+ *
+ * @return the CMap version.
+ */
+ public String getVersion()
+ {
+ return cmapVersion;
+ }
+
+ /**
+ * Sets the version of the CMap.
+ *
+ * @param version the CMap version.
+ */
+ public void setVersion(String version)
+ {
+ cmapVersion = version;
+ }
+
+ /**
+ * Returns the type of the CMap.
+ *
+ * @return the CMap type.
+ */
+ public int getType()
+ {
+ return cmapType;
+ }
+
+ /**
+ * Sets the type of the CMap.
+ *
+ * @param type the CMap type.
+ */
+ public void setType(int type)
+ {
+ cmapType = type;
+ }
+
+ /**
+ * Returns the registry of the CIDSystemInfo.
+ *
+ * @return the registry.
+ */
+ public String getRegistry()
+ {
+ return registry;
+ }
+
+ /**
+ * Sets the registry of the CIDSystemInfo.
+ *
+ * @param newRegistry the registry.
+ */
+ public void setRegistry(String newRegistry)
+ {
+ registry = newRegistry;
+ }
+
+ /**
+ * Returns the ordering of the CIDSystemInfo.
+ *
+ * @return the ordering.
+ */
+ public String getOrdering()
+ {
+ return ordering;
+ }
+
+ /**
+ * Sets the ordering of the CIDSystemInfo.
+ *
+ * @param newOrdering the ordering.
+ */
+ public void setOrdering(String newOrdering)
+ {
+ ordering = newOrdering;
+ }
+
+ /**
+ * Returns the supplement of the CIDSystemInfo.
+ *
+ * @return the supplement.
+ */
+ public int getSupplement()
+ {
+ return supplement;
+ }
+
+ /**
+ * Sets the supplement of the CIDSystemInfo.
+ *
+ * @param newSupplement the supplement.
+ */
+ public void setSupplement(int newSupplement)
+ {
+ supplement = newSupplement;
+ }
}
\ No newline at end of file
Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java?rev=997381&r1=997380&r2=997381&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java Wed Sep 15 16:11:01 2010
@@ -44,6 +44,14 @@ public class CMapParser
private static final String BEGIN_CID_RANGE = "begincidrange";
private static final String USECMAP = "usecmap";
+ private static final String WMODE = "WMode";
+ private static final String CMAP_NAME = "CMapName";
+ private static final String CMAP_VERSION = "CMapVersion";
+ private static final String CMAP_TYPE = "CMapType";
+ private static final String REGISTRY = "Registry";
+ private static final String ORDERING = "Ordering";
+ private static final String SUPPLEMENT = "Supplement";
+
private static final String MARK_END_OF_DICTIONARY = ">>";
private static final String MARK_END_OF_ARRAY = "]";
@@ -234,6 +242,44 @@ public class CMapParser
}
}
}
+ else if (token instanceof LiteralName){
+ LiteralName literal = (LiteralName)token;
+ if (WMODE.equals(literal.name))
+ {
+ int wmode = (Integer)parseNextToken(cmapStream);
+ result.setWMode(wmode);
+ }
+ else if (CMAP_NAME.equals(literal.name))
+ {
+ LiteralName name = (LiteralName)parseNextToken(cmapStream);
+ result.setName(name.name);
+ }
+ else if (CMAP_VERSION.equals(literal.name))
+ {
+ String version = ((Double)parseNextToken(cmapStream)).toString();
+ result.setVersion(version);
+ }
+ else if (CMAP_TYPE.equals(literal.name))
+ {
+ int type = (Integer)parseNextToken(cmapStream);
+ result.setType(type);
+ }
+ else if (REGISTRY.equals(literal.name))
+ {
+ String registry = (String)parseNextToken(cmapStream);
+ result.setRegistry(registry);
+ }
+ else if (ORDERING.equals(literal.name))
+ {
+ String ordering = (String)parseNextToken(cmapStream);
+ result.setOrdering(ordering);
+ }
+ else if (SUPPLEMENT.equals(literal.name))
+ {
+ int supplement = (Integer)parseNextToken(cmapStream);
+ result.setSupplement(supplement);
+ }
+ }
previousToken = token;
}
return result;
@@ -480,8 +526,11 @@ public class CMapParser
private int createIntFromBytes(byte[] bytes)
{
int intValue = (bytes[0]+256)%256;
- intValue <<= 8;
- intValue += (bytes[1]+256)%256;
+ if (bytes.length == 2)
+ {
+ intValue <<= 8;
+ intValue += (bytes[1]+256)%256;
+ }
return intValue;
}
@@ -499,14 +548,6 @@ public class CMapParser
return retval;
}
- private byte[] createBytesFromInt( int value ) throws IOException
- {
- byte[] bytes = new byte[2];
- bytes[1] = (byte)(value % 256);
- bytes[0] = (byte)(value / 256);
- return bytes;
- }
-
private int compare( byte[] first, byte[] second )
{
int retval = 1;