Return-Path: X-Original-To: apmail-pdfbox-commits-archive@www.apache.org Delivered-To: apmail-pdfbox-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1137410B6D for ; Tue, 24 Sep 2013 16:26:10 +0000 (UTC) Received: (qmail 37288 invoked by uid 500); 24 Sep 2013 16:26:09 -0000 Delivered-To: apmail-pdfbox-commits-archive@pdfbox.apache.org Received: (qmail 37232 invoked by uid 500); 24 Sep 2013 16:26:03 -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 37225 invoked by uid 99); 24 Sep 2013 16:26:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Sep 2013 16:26:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Tue, 24 Sep 2013 16:26:00 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id EBA652388831; Tue, 24 Sep 2013 16:25:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1525939 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java Date: Tue, 24 Sep 2013 16:25:39 -0000 To: commits@pdfbox.apache.org From: lehmi@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130924162539.EBA652388831@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: lehmi Date: Tue Sep 24 16:25:39 2013 New Revision: 1525939 URL: http://svn.apache.org/r1525939 Log: PDFBOX-1725: use the DW as default width Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java?rev=1525939&r1=1525938&r2=1525939&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java Tue Sep 24 16:25:39 2013 @@ -17,7 +17,6 @@ package org.apache.pdfbox.pdmodel.font; import java.io.IOException; - import java.util.HashMap; import java.util.Map; @@ -28,7 +27,6 @@ import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSNumber; -import org.apache.pdfbox.encoding.conversion.CMapSubstitution; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.util.ResourceLoader; @@ -36,18 +34,18 @@ import org.apache.pdfbox.util.ResourceLo * This is implementation for the CIDFontType0/CIDFontType2 Fonts. * * @author Ben Litchfield - * @version $Revision: 1.11 $ + * */ public abstract class PDCIDFont extends PDSimpleFont { /** * Log instance. */ - private static final Log log = LogFactory.getLog(PDCIDFont.class); + private static final Log LOG = LogFactory.getLog(PDCIDFont.class); - private Map widthCache = null; + private Map widthCache = null; private long defaultWidth = 0; - + /** * Constructor. */ @@ -61,22 +59,23 @@ public abstract class PDCIDFont extends * * @param fontDictionary The font dictionary according to the PDF specification. */ - public PDCIDFont( COSDictionary fontDictionary ) + public PDCIDFont(COSDictionary fontDictionary) { - super( fontDictionary ); + super(fontDictionary); extractWidths(); } /** - * This will get the fonts bouding box. + * This will get the fonts bounding box. * - * @return The fonts bouding box. + * @return The fonts bounding box. * * @throws IOException If there is an error getting the font bounding box. */ + @Override public PDRectangle getFontBoundingBox() throws IOException { - throw new RuntimeException( "getFontBoundingBox(): Not yet implemented" ); + throw new RuntimeException("getFontBoundingBox(): Not yet implemented"); } /** @@ -86,10 +85,10 @@ public abstract class PDCIDFont extends */ public long getDefaultWidth() { - if (defaultWidth == 0) + if (defaultWidth == 0) { - COSNumber number = (COSNumber)font.getDictionaryObject( COSName.DW); - if( number != null ) + COSNumber number = (COSNumber) font.getDictionaryObject(COSName.DW); + if (number != null) { defaultWidth = number.intValue(); } @@ -106,10 +105,10 @@ public abstract class PDCIDFont extends * * @param dw The default width. */ - public void setDefaultWidth( long dw ) + public void setDefaultWidth(long dw) { defaultWidth = dw; - font.setLong( COSName.DW, dw ); + font.setLong(COSName.DW, dw); } /** @@ -123,60 +122,63 @@ public abstract class PDCIDFont extends * * @throws IOException If an error occurs while parsing. */ - public float getFontWidth( byte[] c, int offset, int length ) throws IOException + @Override + public float getFontWidth(byte[] c, int offset, int length) throws IOException { float retval = getDefaultWidth(); - int code = getCodeFromArray( c, offset, length ); + int code = getCodeFromArray(c, offset, length); - Float widthFloat = widthCache.get( code ); - if( widthFloat != null ) + Float widthFloat = widthCache.get(code); + if (widthFloat != null) { retval = widthFloat.floatValue(); } return retval; } - private void extractWidths() + private void extractWidths() { - if (widthCache == null) + if (widthCache == null) { - widthCache = new HashMap(); - COSArray widths = (COSArray)font.getDictionaryObject( COSName.W ); - if( widths != null ) + widthCache = new HashMap(); + COSArray widths = (COSArray) font.getDictionaryObject(COSName.W); + if (widths != null) { int size = widths.size(); int counter = 0; - while (counter < size) + while (counter < size) { - COSNumber firstCode = (COSNumber)widths.getObject( counter++ ); - COSBase next = widths.getObject( counter++ ); - if( next instanceof COSArray ) + COSNumber firstCode = (COSNumber) widths.getObject(counter++); + COSBase next = widths.getObject(counter++); + if (next instanceof COSArray) { - COSArray array = (COSArray)next; + COSArray array = (COSArray) next; int startRange = firstCode.intValue(); int arraySize = array.size(); - for (int i=0; i 0 ) + COSNumber rangeWidth = (COSNumber) widths.getObject(i); + if (rangeWidth.floatValue() > 0) { totalWidths += rangeWidth.floatValue(); characterCount += 1; @@ -261,20 +264,21 @@ public abstract class PDCIDFont extends } } float average = totalWidths / characterCount; - if( average <= 0 ) + if (average <= 0) { - average = defaultWidth; + average = getDefaultWidth(); } return average; } - + /** * {@inheritDoc} */ - public float getFontWidth( int charCode ) + @Override + public float getFontWidth(int charCode) { - float width = -1; - if (widthCache.containsKey(charCode)) + float width = getDefaultWidth(); + if (widthCache.containsKey(charCode)) { width = widthCache.get(charCode); } @@ -287,23 +291,23 @@ public abstract class PDCIDFont extends */ private String getCIDSystemInfo() { - String cidSystemInfo = null; - COSDictionary cidsysteminfo = (COSDictionary)font.getDictionaryObject(COSName.CIDSYSTEMINFO); - if (cidsysteminfo != null) + String cidSystemInfo = null; + COSDictionary cidsysteminfo = (COSDictionary) font.getDictionaryObject(COSName.CIDSYSTEMINFO); + if (cidsysteminfo != null) { String ordering = cidsysteminfo.getString(COSName.ORDERING); String registry = cidsysteminfo.getString(COSName.REGISTRY); int supplement = cidsysteminfo.getInt(COSName.SUPPLEMENT); - cidSystemInfo = registry + "-" + ordering+ "-" + supplement; + cidSystemInfo = registry + "-" + ordering + "-" + supplement; } return cidSystemInfo; } - + @Override protected void determineEncoding() { String cidSystemInfo = getCIDSystemInfo(); - if (cidSystemInfo != null) + if (cidSystemInfo != null) { if (cidSystemInfo.contains("Identity")) { @@ -315,22 +319,23 @@ public abstract class PDCIDFont extends } else { - cidSystemInfo = cidSystemInfo.substring(0,cidSystemInfo.lastIndexOf("-"))+"-UCS2"; + cidSystemInfo = cidSystemInfo.substring(0, cidSystemInfo.lastIndexOf("-")) + "-UCS2"; } - cmap = cmapObjects.get( cidSystemInfo ); + cmap = cmapObjects.get(cidSystemInfo); if (cmap == null) { String resourceName = resourceRootCMAP + cidSystemInfo; - try { - cmap = parseCmap( resourceRootCMAP, ResourceLoader.loadResource( resourceName )); - if( cmap == null) + try + { + cmap = parseCmap(resourceRootCMAP, ResourceLoader.loadResource(resourceName)); + if (cmap == null) { - log.error("Error: Could not parse predefined CMAP file for '" + cidSystemInfo + "'" ); + LOG.error("Error: Could not parse predefined CMAP file for '" + cidSystemInfo + "'"); } } - catch(IOException exception) + catch (IOException exception) { - log.error("Error: Could not find predefined CMAP file for '" + cidSystemInfo + "'" ); + LOG.error("Error: Could not find predefined CMAP file for '" + cidSystemInfo + "'"); } } } @@ -339,14 +344,14 @@ public abstract class PDCIDFont extends super.determineEncoding(); } } - + @Override public String encode(byte[] c, int offset, int length) throws IOException { String result = null; if (cmap != null) { - result = cmapEncoding(getCodeFromArray( c, offset, length ), length, true, cmap); + result = cmapEncoding(getCodeFromArray(c, offset, length), length, true, cmap); } else {