Return-Path: Delivered-To: apmail-pdfbox-commits-archive@www.apache.org Received: (qmail 77851 invoked from network); 15 Sep 2010 16:11:28 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Sep 2010 16:11:28 -0000 Received: (qmail 36272 invoked by uid 500); 15 Sep 2010 16:11:28 -0000 Delivered-To: apmail-pdfbox-commits-archive@pdfbox.apache.org Received: (qmail 36245 invoked by uid 500); 15 Sep 2010 16:11:27 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 36238 invoked by uid 99); 15 Sep 2010 16:11:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Sep 2010 16:11:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Sep 2010 16:11:23 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3E7262388A36; Wed, 15 Sep 2010 16:11:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r997381 - in /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap: CMap.java CMapParser.java Date: Wed, 15 Sep 2010 16:11:02 -0000 To: commits@pdfbox.apache.org From: lehmi@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100915161102.3E7262388A36@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 codeSpaceRanges = new ArrayList(); private Map singleByteMappings = new HashMap(); private Map doubleByteMappings = new HashMap(); @@ -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;