RED-3067 Bugfix to show redactions on rotated pages correctly
This commit is contained in:
parent
e8dce509f3
commit
f7fbe8f0f6
@ -1,22 +1,24 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.parsing.model;
|
package com.iqser.red.service.redaction.v1.server.parsing.model;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toSet;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
import com.iqser.red.service.redaction.v1.model.Point;
|
|
||||||
import com.iqser.red.service.redaction.v1.model.Rectangle;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.apache.pdfbox.text.TextPosition;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.apache.pdfbox.text.TextPosition;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.iqser.red.service.redaction.v1.model.Point;
|
||||||
|
import com.iqser.red.service.redaction.v1.model.Rectangle;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@JsonIgnoreProperties({ "empty" })
|
@JsonIgnoreProperties({"empty"})
|
||||||
public class TextPositionSequence implements CharSequence {
|
public class TextPositionSequence implements CharSequence {
|
||||||
|
|
||||||
private int page;
|
private int page;
|
||||||
@ -25,12 +27,15 @@ public class TextPositionSequence implements CharSequence {
|
|||||||
private float x1;
|
private float x1;
|
||||||
private float x2;
|
private float x2;
|
||||||
|
|
||||||
|
|
||||||
public TextPositionSequence(int page) {
|
public TextPositionSequence(int page) {
|
||||||
|
|
||||||
this.page = page;
|
this.page = page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static TextPositionSequence fromData(List<RedTextPosition> textPositions, int page) {
|
public static TextPositionSequence fromData(List<RedTextPosition> textPositions, int page) {
|
||||||
|
|
||||||
var textPositionSequence = new TextPositionSequence();
|
var textPositionSequence = new TextPositionSequence();
|
||||||
textPositionSequence.textPositions = textPositions;
|
textPositionSequence.textPositions = textPositions;
|
||||||
textPositionSequence.page = page;
|
textPositionSequence.page = page;
|
||||||
@ -46,9 +51,6 @@ public class TextPositionSequence implements CharSequence {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int length() {
|
public int length() {
|
||||||
|
|
||||||
@ -131,6 +133,7 @@ public class TextPositionSequence implements CharSequence {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public float getRotationAdjustedY() {
|
public float getRotationAdjustedY() {
|
||||||
|
|
||||||
@ -190,10 +193,8 @@ public class TextPositionSequence implements CharSequence {
|
|||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public String getFont() {
|
public String getFont() {
|
||||||
return textPositions.get(0).getFontName()
|
|
||||||
.toLowerCase()
|
return textPositions.get(0).getFontName().toLowerCase().replaceAll(",bold", "").replaceAll(",italic", "");
|
||||||
.replaceAll(",bold", "")
|
|
||||||
.replaceAll(",italic", "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -214,27 +215,33 @@ public class TextPositionSequence implements CharSequence {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public float getFontSize() {
|
public float getFontSize() {
|
||||||
|
|
||||||
return textPositions.get(0).getFontSizeInPt();
|
return textPositions.get(0).getFontSizeInPt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public float getSpaceWidth() {
|
public float getSpaceWidth() {
|
||||||
|
|
||||||
return textPositions.get(0).getWidthOfSpace();
|
return textPositions.get(0).getWidthOfSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public int getRotation() {
|
public int getRotation() {
|
||||||
|
|
||||||
return textPositions.get(0).getRotation();
|
return textPositions.get(0).getRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public Rectangle getRectangle() {
|
public Rectangle getRectangle() {
|
||||||
|
|
||||||
|
log.debug("Page: '{}', Word: '{}', Rotation: '{}'", page, toString(), textPositions.get(0).getRotation());
|
||||||
|
|
||||||
float height = getTextHeight();
|
float height = getTextHeight();
|
||||||
|
|
||||||
float posXInit = getX1();
|
float posXInit = getX1();
|
||||||
@ -246,36 +253,45 @@ public class TextPositionSequence implements CharSequence {
|
|||||||
posXEnd = textPositions.get(0).getYDirAdj() + 2;
|
posXEnd = textPositions.get(0).getYDirAdj() + 2;
|
||||||
posYInit = getY1();
|
posYInit = getY1();
|
||||||
posYEnd = textPositions.get(textPositions.size() - 1).getXDirAdj() - height + 4;
|
posYEnd = textPositions.get(textPositions.size() - 1).getXDirAdj() - height + 4;
|
||||||
} else if (textPositions.get(0).getRotation() == 270) {
|
|
||||||
|
} else if (textPositions.get(0).getRotation() == 270 && textPositions.size() > 1) {
|
||||||
posYInit = textPositions.get(0).getPageHeight() - getX1();
|
posYInit = textPositions.get(0).getPageHeight() - getX1();
|
||||||
posYEnd = textPositions.get(0).getPageHeight() - getX2() - textPositions.get(0)
|
posYEnd = textPositions.get(0).getPageHeight() - getX2() - textPositions.get(0)
|
||||||
.getWidth() - textPositions.get(textPositions.size() - 1).getWidth() - 1;
|
.getWidth() - textPositions.get(textPositions.size() - 1).getWidth() - 1;
|
||||||
posXInit = textPositions.get(0).getPageWidth() - textPositions.get(0).getYDirAdj() - 2;
|
posXInit = textPositions.get(0).getPageWidth() - textPositions.get(0).getYDirAdj() - 2;
|
||||||
posXEnd = textPositions.get(0).getPageWidth() - textPositions.get(textPositions.size() - 1)
|
posXEnd = textPositions.get(0).getPageWidth() - textPositions.get(textPositions.size() - 1)
|
||||||
.getYDirAdj() + height;
|
.getYDirAdj() + height;
|
||||||
} else if(textPositions.get(0).getRotation() == 0 && textPositions.get(0).getDir() == 270f) {
|
|
||||||
|
} else if (textPositions.get(0).getRotation() == 270 && textPositions.size() == 1) {
|
||||||
|
posYInit = textPositions.get(0).getPageHeight() - textPositions.get(0).getYDirAdj() - 2;
|
||||||
|
posYEnd = posYInit + 1;
|
||||||
|
posXInit = textPositions.get(0).getXDirAdj();
|
||||||
|
posXEnd = posXInit + textPositions.get(0).getWidthDirAdj() + 0.1f;
|
||||||
|
|
||||||
|
} else if (textPositions.get(0).getRotation() == 0 && textPositions.get(0).getDir() == 270f) {
|
||||||
posYInit = textPositions.get(0).getPageHeight() - getX1();
|
posYInit = textPositions.get(0).getPageHeight() - getX1();
|
||||||
posYEnd = textPositions.get(0).getPageHeight() - getX2() - textPositions.get(0)
|
posYEnd = textPositions.get(0).getPageHeight() - getX2() - textPositions.get(0)
|
||||||
.getWidthDirAdj() - textPositions.get(textPositions.size() - 1).getWidthDirAdj() - 3;
|
.getWidthDirAdj() - textPositions.get(textPositions.size() - 1).getWidthDirAdj() - 3;
|
||||||
posXInit = textPositions.get(0).getPageWidth() - textPositions.get(0).getYDirAdj() - 2;
|
posXInit = textPositions.get(0).getPageWidth() - textPositions.get(0).getYDirAdj() - 2;
|
||||||
posXEnd = textPositions.get(0).getPageWidth() - textPositions.get(textPositions.size() - 1)
|
posXEnd = textPositions.get(0).getPageWidth() - textPositions.get(textPositions.size() - 1)
|
||||||
.getYDirAdj() + height;
|
.getYDirAdj() + height;
|
||||||
} else if(textPositions.get(0).getRotation() == 90 && textPositions.get(0).getDir() == 0.0f){
|
|
||||||
posXInit = textPositions.get(textPositions.size() - 1)
|
} else if (textPositions.get(0).getRotation() == 90 && textPositions.get(0).getDir() == 0.0f) {
|
||||||
|
posXInit = textPositions.get(textPositions.size() - 1)
|
||||||
.getXDirAdj() + textPositions.get(textPositions.size() - 1).getHeightDir();
|
.getXDirAdj() + textPositions.get(textPositions.size() - 1).getHeightDir();
|
||||||
posXEnd = textPositions.get(0).getXDirAdj();
|
posXEnd = textPositions.get(0).getXDirAdj();
|
||||||
posYInit = textPositions.get(0).getPageHeight() - textPositions.get(0).getYDirAdj() - 2;
|
posYInit = textPositions.get(0).getPageHeight() - textPositions.get(0).getYDirAdj() - 2;
|
||||||
posYEnd = textPositions.get(0).getPageHeight() - textPositions.get(textPositions.size() - 1)
|
posYEnd = textPositions.get(0).getPageHeight() - textPositions.get(textPositions.size() - 1)
|
||||||
.getYDirAdj() + 2;
|
.getYDirAdj() + 2;
|
||||||
} else if(textPositions.get(0).getRotation() == 0 && textPositions.get(0).getDir() == 90f){
|
|
||||||
posYInit = getX1();
|
} else if (textPositions.get(0).getRotation() == 0 && textPositions.get(0).getDir() == 90f) {
|
||||||
posYEnd = getX2() + textPositions.get(0)
|
posYInit = getX1();
|
||||||
.getWidthDirAdj() - textPositions.get(textPositions.size() - 1).getWidthDirAdj() - 3;
|
posYEnd = getX2() + textPositions.get(0).getWidthDirAdj() - textPositions.get(textPositions.size() - 1)
|
||||||
posXInit = textPositions.get(0).getYDirAdj() + 2;
|
.getWidthDirAdj() - 3;
|
||||||
posXEnd = textPositions.get(textPositions.size() - 1)
|
posXInit = textPositions.get(0).getYDirAdj() + 2;
|
||||||
.getYDirAdj() - height;
|
posXEnd = textPositions.get(textPositions.size() - 1).getYDirAdj() - height;
|
||||||
}
|
|
||||||
else {
|
} else {
|
||||||
posXEnd = textPositions.get(textPositions.size() - 1)
|
posXEnd = textPositions.get(textPositions.size() - 1)
|
||||||
.getXDirAdj() + textPositions.get(textPositions.size() - 1).getWidthDirAdj() + 1;
|
.getXDirAdj() + textPositions.get(textPositions.size() - 1).getWidthDirAdj() + 1;
|
||||||
posYInit = textPositions.get(0).getPageHeight() - textPositions.get(0).getYDirAdj() - 2;
|
posYInit = textPositions.get(0).getPageHeight() - textPositions.get(0).getYDirAdj() - 2;
|
||||||
@ -283,7 +299,9 @@ public class TextPositionSequence implements CharSequence {
|
|||||||
.getYDirAdj() + 2;
|
.getYDirAdj() + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Rectangle(new Point(posXInit, posYInit), posXEnd - posXInit, posYEnd - posYInit + height, page);
|
var rectangle = new Rectangle(new Point(posXInit, posYInit), posXEnd - posXInit, posYEnd - posYInit + height, page);
|
||||||
|
log.debug("Rectangle: {}", rectangle);
|
||||||
|
return rectangle;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user