RED-4824: Created base test for text-position rectangle creation
This commit is contained in:
parent
16ea8364df
commit
cadbc3c7a4
@ -0,0 +1,167 @@
|
||||
package com.iqser.red.service.redaction.v1.server.parsing.model;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.fontbox.util.BoundingBox;
|
||||
import org.apache.pdfbox.cos.COSDictionary;
|
||||
import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||
import org.apache.pdfbox.text.TextPosition;
|
||||
import org.apache.pdfbox.util.Matrix;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
public class TextPositionSequenceTest {
|
||||
|
||||
public static final float UNROTAED_RECTANGLE_X_OFFSET = 0.f;
|
||||
public static final float UNROTATED_RECTANGLE_Y_OFFSET = -2.f;
|
||||
public static final float UNROTATED_RECTANGLE_WIDTH_OFFSET = 1.f;
|
||||
public static final float UNROTATED_RECTANGLE_HEIGHT_OFFSET = 6.f;
|
||||
|
||||
|
||||
@Test
|
||||
@SneakyThrows
|
||||
public void testSinglePosNoRotationRectangle() {
|
||||
|
||||
int page = 2;
|
||||
var testSequence = new TextPositionSequence(page);
|
||||
|
||||
float endX = 4.f;
|
||||
float endY = 5.f;
|
||||
float maxHeight = 20.f;
|
||||
var redTextPosition = createTextPosition(0, endX, endY, maxHeight);
|
||||
|
||||
testSequence.add(redTextPosition);
|
||||
|
||||
var rectangle = testSequence.getRectangle();
|
||||
assertThat(rectangle.getPage()).isEqualTo(page);
|
||||
assertThat(rectangle.getTopLeft().getX()).isEqualTo(UNROTAED_RECTANGLE_X_OFFSET);
|
||||
assertThat(rectangle.getTopLeft().getY()).isEqualTo(UNROTATED_RECTANGLE_Y_OFFSET);
|
||||
assertThat(rectangle.getWidth()).isEqualTo(endX + UNROTATED_RECTANGLE_WIDTH_OFFSET);
|
||||
assertThat(rectangle.getHeight()).isEqualTo(maxHeight + UNROTATED_RECTANGLE_HEIGHT_OFFSET);
|
||||
}
|
||||
|
||||
|
||||
private TextPosition createTextPosition(int pageRotation, float endX, float endY, float maxHeight) throws IOException {
|
||||
|
||||
return new TextPosition(pageRotation, 100, 200, createIdentityMatrix(), endX, endY, maxHeight, 4, 2, "a", null, new DummyFont(), 14, 42);
|
||||
}
|
||||
|
||||
|
||||
private Matrix createIdentityMatrix() {
|
||||
|
||||
return new Matrix();
|
||||
}
|
||||
|
||||
|
||||
private static class DummyFont extends PDFont {
|
||||
|
||||
public DummyFont() throws IOException {
|
||||
|
||||
super(new COSDictionary());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected float getStandard14Width(int i) {
|
||||
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected byte[] encode(int i) {
|
||||
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int readCode(InputStream inputStream) {
|
||||
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isVertical() {
|
||||
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addToSubset(int i) {
|
||||
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void subset() {
|
||||
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean willBeSubset() {
|
||||
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
|
||||
return "DummyFont";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BoundingBox getBoundingBox() {
|
||||
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getHeight(int i) {
|
||||
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasExplicitWidth(int i) {
|
||||
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getWidthFromFont(int i) {
|
||||
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isEmbedded() {
|
||||
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isDamaged() {
|
||||
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user