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 2020/04/10 11:47:55 UTC
svn commit: r1876364 - in /pdfbox/branches/issue45: ./
fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java
fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java
fontbox/src/test/java/org/apache/fontbox/cmap/TestCodespaceRange.java
Author: lehmi
Date: Fri Apr 10 11:47:55 2020
New Revision: 1876364
URL: http://svn.apache.org/viewvc?rev=1876364&view=rev
Log:
PDFBOX-4810: refactor CodespaceRange to be in line with spec
Added:
pdfbox/branches/issue45/fontbox/src/test/java/org/apache/fontbox/cmap/TestCodespaceRange.java
- copied unchanged from r1876363, pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/cmap/TestCodespaceRange.java
Modified:
pdfbox/branches/issue45/ (props changed)
pdfbox/branches/issue45/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java
pdfbox/branches/issue45/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java
Propchange: pdfbox/branches/issue45/
------------------------------------------------------------------------------
Merged /pdfbox/branches/2.0:r1876363
Modified: pdfbox/branches/issue45/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue45/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java?rev=1876364&r1=1876363&r2=1876364&view=diff
==============================================================================
--- pdfbox/branches/issue45/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java (original)
+++ pdfbox/branches/issue45/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java Fri Apr 10 11:47:55 2020
@@ -243,10 +243,7 @@ public class CMapParser
}
byte[] startRange = (byte[]) nextToken;
byte[] endRange = (byte[]) parseNextToken(cmapStream);
- CodespaceRange range = new CodespaceRange();
- range.setStart(startRange);
- range.setEnd(endRange);
- result.addCodespaceRange(range);
+ result.addCodespaceRange(new CodespaceRange(startRange, endRange));
}
}
Modified: pdfbox/branches/issue45/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue45/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java?rev=1876364&r1=1876363&r2=1876364&view=diff
==============================================================================
--- pdfbox/branches/issue45/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java (original)
+++ pdfbox/branches/issue45/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java Fri Apr 10 11:47:55 2020
@@ -16,8 +16,6 @@
*/
package org.apache.fontbox.cmap;
-import static org.apache.fontbox.cmap.CMap.toInt;
-
/**
* This represents a single entry in the codespace range.
*
@@ -25,14 +23,42 @@ import static org.apache.fontbox.cmap.CM
*/
public class CodespaceRange
{
- private byte[] start;
- private byte[] end;
- private int startInt;
- private int endInt;
+ private byte[] startBytes;
+ private byte[] endBytes;
+ private int[] start;
+ private int[] end;
private int codeLength = 0;
/**
+ * Creates a new instance of CodespaceRange. The length of both arrays has to be the same.<br>
+ * For one byte ranges startBytes and endBytes define a linear range of values. Double byte values define a
+ * rectangular range not a linear range. Examples: <br>
+ * <00> <20> defines a linear range from 0x00 up to 0x20.<br>
+ * <8140> to <9FFC> defines a rectangular range. The high byte has to be within 0x81 and 0x9F and the low byte has
+ * to be within 0x40 and 0xFC
+ *
+ */
+ public CodespaceRange(byte[] startBytes, byte[] endBytes)
+ {
+ if (startBytes.length != endBytes.length)
+ {
+ throw new IllegalArgumentException(
+ "The start and the end values must not have different lengths.");
+ }
+ start = new int[startBytes.length];
+ end = new int[endBytes.length];
+ for (int i = 0; i < startBytes.length; i++)
+ {
+ start[i] = startBytes[i] & 0xFF;
+ end[i] = endBytes[i] & 0xFF;
+ }
+ codeLength = endBytes.length;
+ }
+
+ /**
* Creates a new instance of CodespaceRange.
+ *
+ * @Deprecated to be removed in the next major release.
*/
public CodespaceRange()
{
@@ -48,43 +74,63 @@ public class CodespaceRange
return codeLength;
}
- /** Getter for property end.
+ /**
+ * Getter for property end.
+ *
* @return Value of property end.
*
+ * @Deprecated to be removed in the next major release
*/
public byte[] getEnd()
{
- return end;
+ return endBytes;
}
- /** Setter for property end.
+ /**
+ * Setter for property end.
+ *
* @param endBytes New value of property end.
*
+ * @Deprecated to be removed in the next major release
*/
void setEnd(byte[] endBytes)
{
- end = endBytes;
- endInt = toInt(endBytes, endBytes.length);
+ this.endBytes = endBytes;
+ end = new int[endBytes.length];
+ for (int i = 0; i < endBytes.length; i++)
+ {
+ end[i] = endBytes[i] & 0xFF;
+ }
}
- /** Getter for property start.
+ /**
+ * Getter for property start.
+ *
* @return Value of property start.
*
+ * @Deprecated to be removed in the next major release
*/
public byte[] getStart()
{
- return start;
+ return startBytes;
}
- /** Setter for property start.
+ /**
+ * Setter for property start.
+ *
* @param startBytes New value of property start.
*
+ * @Deprecated to be removed in the next major release
*/
void setStart(byte[] startBytes)
{
- start = startBytes;
- codeLength = start.length;
- startInt = toInt(startBytes, startBytes.length);
+ this.startBytes = startBytes;
+ start = new int[startBytes.length];
+ for (int i = 0; i < startBytes.length; i++)
+ {
+ start[i] = startBytes[i] & 0xFF;
+ }
+ codeLength = startBytes.length;
}
/**
@@ -101,15 +147,19 @@ public class CodespaceRange
public boolean isFullMatch(byte[] code, int codeLen)
{
// code must be the same length as the bounding codes
- if (codeLen == codeLength)
+ if (codeLength != codeLen)
+ {
+ return false;
+ }
+ for (int i = 0; i < codeLength; i++)
{
- int value = toInt(code, codeLen);
- if (value >= startInt && value <=endInt)
+ int codeAsInt = code[i] & 0xFF;
+ if (codeAsInt < start[i] || codeAsInt > end[i])
{
- return true;
+ return false;
}
}
- return false;
+ return true;
}
}