-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Corrected Tests
- Loading branch information
Showing
3 changed files
with
40 additions
and
32 deletions.
There are no files selected for viewing
22 changes: 12 additions & 10 deletions
22
openpdf/src/test/java/com/lowagie/text/pdf/FontSelectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,34 @@ | ||
package com.lowagie.text.pdf; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.lowagie.text.Document; | ||
import com.lowagie.text.Font; | ||
import com.lowagie.text.PageSize; | ||
import com.lowagie.text.pdf.parser.PdfTextExtractor; | ||
|
||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class FontSelectorTest { | ||
|
||
public static final String STRING_TO_CHECK = "Χαίρετε Greek -"; | ||
|
||
public class FontSelectorTest { | ||
@Test | ||
public void testDefaultFont() throws IOException { | ||
void testDefaultFont() throws IOException { | ||
Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10); | ||
ByteArrayOutputStream stream = new ByteArrayOutputStream(); | ||
PdfWriter.getInstance(document, stream); | ||
PdfWriter writer = PdfWriter.getInstance(document, stream); | ||
writer.setRunDirection(PdfWriter.RUN_DIRECTION_LTR); | ||
document.open(); | ||
|
||
FontSelector selector = new FontSelector(); | ||
selector.addFont(new Font(Font.HELVETICA)); | ||
document.add(selector.process("ΧαίρετεGreek -")); | ||
document.add(selector.process(STRING_TO_CHECK)); | ||
document.close(); | ||
|
||
PdfReader rd = new PdfReader(stream.toByteArray()); | ||
PdfTextExtractor pdfTextExtractor = new PdfTextExtractor(rd); | ||
Assertions.assertEquals(pdfTextExtractor.getTextFromPage(1), "ΧαίρετεGreek -"); | ||
assertEquals(pdfTextExtractor.getTextFromPage(1), STRING_TO_CHECK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.lowagie.text.pdf.fonts; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
|
||
import com.lowagie.text.pdf.BaseFont; | ||
|
@@ -8,64 +9,67 @@ | |
import java.io.InputStream; | ||
import java.util.HashMap; | ||
import org.apache.commons.io.IOUtils; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* | ||
* @author Gajendra kumar ([email protected]) | ||
* @author Gajendra kumar ([email protected]) | ||
*/ | ||
public class AdvanceTypographyTest { | ||
class AdvanceTypographyTest { | ||
|
||
/** | ||
* Without ghyph substitution out will be {660,666,676,1143,656,1130}, which is no correct | ||
* FopGlyphProcessor performs ghyph substitution to correct the output | ||
* Without ghyph substitution out will be {660,666,676,1143,656,1130}, which is no correct FopGlyphProcessor | ||
* performs ghyph substitution to correct the output | ||
* | ||
* @throws Exception - DocumentException or IOException thrown by the processedContent() method | ||
*/ | ||
@Test | ||
public void testTypographySubstitution() throws Exception{ | ||
void testTypographySubstitution() throws Exception { | ||
char[] expectedOutput = {660, 666, 911, 656, 1130}; | ||
byte[] processedContent = FopGlyphProcessor.convertToBytesWithGlyphs( | ||
BaseFont.createFont("fonts/jaldi/Jaldi-Regular.ttf", BaseFont.IDENTITY_H, false), | ||
"नमस्ते", "fonts/jaldi/Jaldi-Regular.ttf", new HashMap<>(), "dflt"); | ||
String str = new String(processedContent, "UnicodeBigUnmarked"); | ||
|
||
assertArrayEquals(expectedOutput,str.toCharArray()); | ||
assertArrayEquals(expectedOutput, str.toCharArray()); | ||
} | ||
|
||
/** | ||
* In some fonts combination of two characters can be represented by single glyph | ||
* This method tests above case. | ||
* In some fonts combination of two characters can be represented by single glyph This method tests above case. | ||
* | ||
* @throws Exception - UnsupportedEncodingException by the convertToBytesWithGlyphs method | ||
*/ | ||
@Test | ||
public void testSubstitutionWithMerge() throws Exception{ | ||
void testSubstitutionWithMerge() throws Exception { | ||
char[] expectedOutput = {254, 278, 390, 314, 331, 376, 254, 285, 278}; | ||
byte[] processedContent = FopGlyphProcessor.convertToBytesWithGlyphs( | ||
BaseFont.createFont("fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf", BaseFont.IDENTITY_H, false), | ||
"instruction", "fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf", new HashMap<>(), "dflt"); | ||
String str = new String(processedContent, "UnicodeBigUnmarked"); | ||
assertArrayEquals(expectedOutput,str.toCharArray()); | ||
assertArrayEquals(expectedOutput, str.toCharArray()); | ||
} | ||
|
||
/** | ||
* Test fonts loaded externally and passed as byte array to BaseFont, Fop should be able to | ||
* resolve these fonts | ||
* Test fonts loaded externally and passed as byte array to BaseFont, Fop should be able to resolve these fonts | ||
* | ||
* @throws Exception a DocumentException or an IOException thrown by BaseFont.createFont | ||
*/ | ||
@Test | ||
public void testInMemoryFonts() throws Exception{ | ||
char[] expectedOutput = {254,278,390,314,331,376,254,285,278}; | ||
void testInMemoryFonts() throws Exception { | ||
char[] expectedOutput = {254, 278, 390, 314, 331, 376, 254, 285, 278}; | ||
BaseFont font = BaseFont.createFont("ViaodaLibre-Regular.ttf", BaseFont.IDENTITY_H, | ||
BaseFont.EMBEDDED,true, | ||
getFontByte("fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf"), null, false,false); | ||
BaseFont.EMBEDDED, true, | ||
getFontByte("fonts/Viaoda_Libre/ViaodaLibre-Regular.ttf"), null, false, false); | ||
byte[] processedContent = FopGlyphProcessor.convertToBytesWithGlyphs( | ||
font, "instruction", "Viaoda Libre", new HashMap<>(), "dflt"); | ||
String str = new String(processedContent, "UnicodeBigUnmarked"); | ||
assertArrayEquals(expectedOutput,str.toCharArray()); | ||
assertArrayEquals(expectedOutput, str.toCharArray()); | ||
} | ||
|
||
/*@Disabled | ||
public void testSurrogatePair() throws Exception{ | ||
@Test | ||
@Disabled("Should work, when GH-591 #592 is fixed.") | ||
void testSurrogatePair() throws Exception{ | ||
|
||
BaseFont baseFont = BaseFont.createFont("fonts/jp/GenShinGothic-Normal.ttf", BaseFont.IDENTITY_H, false); | ||
|
||
|
@@ -77,10 +81,11 @@ public void testSurrogatePair() throws Exception{ | |
String str = new String(processedContent, "UnicodeBigUnmarked"); | ||
char[] actual = str.toCharArray(); | ||
assertArrayEquals(expectedOutput, actual); | ||
}*/ | ||
} | ||
|
||
private byte[] getFontByte(String fileName) throws IOException { | ||
InputStream stream = BaseFont.getResourceStream(fileName, null); | ||
InputStream stream = BaseFont.getResourceStream(fileName, this.getClass().getClassLoader()); | ||
assertThat(stream).isNotNull(); | ||
return IOUtils.toByteArray(stream); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters