You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/06/21 19:45:05 UTC

svn commit: r1834046 - in /pdfbox/branches/2.0/fontbox/src: main/java/org/apache/fontbox/afm/AFMParser.java test/java/org/apache/fontbox/afm/ test/java/org/apache/fontbox/afm/AFMParserTest.java

Author: tilman
Date: Thu Jun 21 19:45:05 2018
New Revision: 1834046

URL: http://svn.apache.org/viewvc?rev=1834046&view=rev
Log:
PDFBOX-4071: clarify code + test

Added:
    pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/afm/
    pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java   (with props)
Modified:
    pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java

Modified: pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java?rev=1834046&r1=1834045&r2=1834046&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java (original)
+++ pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java Thu Jun 21 19:45:05 2018
@@ -951,9 +951,11 @@ public class AFMParser
         buf.append( (char)nextByte );
 
         //now read the data
-        while( !isEOL(nextByte = input.read()) )
+        nextByte = input.read();
+        while (nextByte != -1 && !isEOL(nextByte))
         {
-            buf.append( (char)nextByte );
+            buf.append((char) nextByte);
+            nextByte = input.read();
         }
         return buf.toString();
     }
@@ -978,9 +980,11 @@ public class AFMParser
         buf.append( (char)nextByte );
 
         //now read the data
-        while( !isWhitespace(nextByte = input.read()) )
+        nextByte = input.read();
+        while (nextByte != -1 && !isWhitespace(nextByte))
         {
-            buf.append( (char)nextByte );
+            buf.append((char) nextByte);
+            nextByte = input.read();
         }
         return buf.toString();
     }

Added: pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java?rev=1834046&view=auto
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java (added)
+++ pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java Thu Jun 21 19:45:05 2018
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.fontbox.afm;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import org.apache.fontbox.util.Charsets;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author Tilman Hausherr
+ */
+public class AFMParserTest
+{
+    @Test
+    public void testEof() throws IOException
+    {
+        try
+        {
+            new AFMParser(new ByteArrayInputStream("huhu".getBytes(Charsets.US_ASCII))).parse();
+        }
+        catch (IOException ex)
+        {
+            Assert.assertEquals("Error: The AFM file should start with StartFontMetrics and not 'huhu'", ex.getMessage());
+        }
+    }
+}

Propchange: pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native