Skip to content

Commit

Permalink
Surefire and Maven updates
Browse files Browse the repository at this point in the history
- Corrected Tests
  • Loading branch information
asturio committed Jan 8, 2024
1 parent 3edebe4 commit d7435c6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 32 deletions.
22 changes: 12 additions & 10 deletions openpdf/src/test/java/com/lowagie/text/pdf/FontSelectorTest.java
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);
}
}
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;
Expand All @@ -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);

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static void main(String[] args) {
cb.setRGBColorStroke(255, 0, 0);
cb.rectangle(250 - size/2, 690, size, 30);
cb.stroke();
writer.setRunDirection(PdfWriter.RUN_DIRECTION_DEFAULT);
}
catch(DocumentException | IOException de) {
System.err.println(de.getMessage());
Expand Down

0 comments on commit d7435c6

Please sign in to comment.