[FOray-commit] SF.net SVN: foray:[11899] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2021-02-08 12:55:19
|
Revision: 11899
http://sourceforge.net/p/foray/code/11899
Author: victormote
Date: 2021-02-08 12:55:16 +0000 (Mon, 08 Feb 2021)
Log Message:
-----------
Throw exception if subsetting negative glyph indexes is attempted.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/Subset.java
trunk/foray/foray-font/src/test/java/org/foray/font/SubsetTests.java
trunk/foray/master/config/checkstyle/checkstyle-suppressions.xml
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/Subset.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/Subset.java 2021-02-08 12:20:11 UTC (rev 11898)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/Subset.java 2021-02-08 12:55:16 UTC (rev 11899)
@@ -80,9 +80,9 @@
this.originalBySubset = new IntArrayBuilder(this.arraySizeIncrement);
if (this.consumerFont.getFOrayFont() instanceof FsTrueTypeFont) {
// Make sure that the 3 first glyphs are included
- this.encodeSubsetIndex((char) 0);
- this.encodeSubsetIndex((char) 1);
- this.encodeSubsetIndex((char) 2);
+ this.encodeSubsetIndex(0);
+ this.encodeSubsetIndex(1);
+ this.encodeSubsetIndex(2);
}
}
@@ -91,8 +91,12 @@
* necessary.
* @param fontGlyphIndex The index into the full font (not subsetted) glyphs.
* @return The index into the subsetted glyphs.
+ * @throws IllegalArgumentException If {@code fontGlyphIndex} is negative.
*/
public int encodeSubsetIndex(final int fontGlyphIndex) {
+ if (fontGlyphIndex < 0) {
+ throw new IllegalArgumentException("Cannot subset a negative glyph index: " + fontGlyphIndex);
+ }
final int index = this.originalByOriginal.binarySearch(fontGlyphIndex);
if (index < 0) {
return addMapping(fontGlyphIndex);
@@ -101,7 +105,7 @@
}
/**
- * Get the full font glyph index (not subsetted) that corresponds to subsetGlyphIndex.
+ * Get the full font glyph index (not subsetted) that corresponds to {@link subsetGlyphIndex}.
* @param subsetGlyphIndex The index into the subset font glyphs.
* @return The index into the full font (not subsetted) glyphs, or -1 if the input is not valid.
*/
@@ -118,13 +122,13 @@
* @param glyphIndex The glyph index to be added.
* @return The subset index for the new glyph.
*/
- private char addMapping(final int glyphIndex) {
+ private int addMapping(final int glyphIndex) {
final int newIndex = this.originalByOriginal.length();
this.originalByOriginal.append(glyphIndex);
this.subsetByOriginal.append(newIndex);
this.originalBySubset.append(glyphIndex);
sortByOriginal();
- return (char) newIndex;
+ return newIndex;
}
private void sortByOriginal() {
@@ -164,10 +168,9 @@
while (stillSorting) {
stillSorting = false;
for (char i = 1; i < this.numGlyphsUsed(); i++) {
- final char currentOriginalIndex = (char) this.decodeSubsetIndex(i);
+ final int currentOriginalIndex = decodeSubsetIndex(i);
final int currentCodePoint = encoding.decode(currentOriginalIndex);
- final char previousOriginalIndex
- = (char) this.decodeSubsetIndex(i - 1);
+ final int previousOriginalIndex = decodeSubsetIndex(i - 1);
final int previousCodePoint = encoding.decode(previousOriginalIndex);
if (previousCodePoint > currentCodePoint) {
/* They are out of order and should be switched. */
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/SubsetTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/SubsetTests.java 2021-02-08 12:20:11 UTC (rev 11898)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/SubsetTests.java 2021-02-08 12:55:16 UTC (rev 11899)
@@ -93,4 +93,22 @@
Assert.assertEquals(4, out.numGlyphsUsed());
}
+ /**
+ * Tests that an exception is thrown if a negative glyph index is subsetted.
+ */
+ @Test
+ public void subsetting_A_Negative_Glyph_Index_Should_Throw_An_Exception() {
+ final FreeStandingFont mockFsf = Mockito.mock(FreeStandingFont.class);
+ final ConsumerFont4a mockConsumerFont = Mockito.mock(ConsumerFont4a.class);
+ Mockito.when(mockConsumerFont.getFreeStandingFont()).thenReturn(mockFsf);
+
+ final Subset out = new Subset(mockConsumerFont);
+ try {
+ out.encodeSubsetIndex(-1);
+ Assert.fail("Expected IllegalArgumentException to be thrown.");
+ } catch (final IllegalArgumentException e) {
+ /* This is the expected path. */
+ }
+ }
+
}
Modified: trunk/foray/master/config/checkstyle/checkstyle-suppressions.xml
===================================================================
--- trunk/foray/master/config/checkstyle/checkstyle-suppressions.xml 2021-02-08 12:20:11 UTC (rev 11898)
+++ trunk/foray/master/config/checkstyle/checkstyle-suppressions.xml 2021-02-08 12:55:16 UTC (rev 11899)
@@ -19,13 +19,14 @@
original Pascal WEB file, and does not conform to our usual coding standards. -->
<suppress checks="DeclarationOrder"
files="src.main.java.org.foray.hyphen.zzarchive.PatGen.*"/>
-
+
+ <!-- Permanently suppress some tests in the test directories. -->
<!-- Permanently suppress Javadoc package documentation for test directories. -->
- <suppress checks="JavadocPackage"
- files="src.test.java.*"/>
+ <suppress checks="JavadocPackage" files="src.test.java.*"/>
<!-- Permanently suppress Magic Number check for test directories. -->
- <suppress checks="MagicNumber"
- files="src.test.java.*"/>
+ <suppress checks="MagicNumber" files="src.test.java.*"/>
+ <!-- Permanently suppress Method naming checks for test directories. -->
+ <suppress checks="MethodName" files="src.test.java.*"/>
<!-- Permanently suppress checks in resources, data, and archives. -->
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|