Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.verapdf.pd.colors.PDDeviceRGB;
import org.verapdf.pd.font.PDCIDFont;
import org.verapdf.pd.font.PDFontDescriptor;
import org.verapdf.pd.font.type3.PDType3Font;
import org.verapdf.pd.images.PDXForm;
import org.verapdf.pd.images.PDXObject;
import org.verapdf.pd.optionalcontent.PDOCMDDictionary;
Expand Down Expand Up @@ -886,6 +887,19 @@ private void parseString(boolean isVertical, COSString string, TextPieces textPi
LOGGER.log(Level.WARNING, "The glyph can not be mapped to Unicode");
}
}
if (font instanceof PDType3Font) {
Double glyphAscent = ((PDType3Font) font).getAscentFromProgram(code);
if (glyphAscent != null && (textPieces.getAscent() == null ||
glyphAscent > textPieces.getAscent())) {
textPieces.setAscent(glyphAscent);
}
Double glyphDescent = ((PDType3Font) font).getDescentFromProgram(code);
if (glyphDescent != null && (textPieces.getDescent() == null ||
glyphDescent < textPieces.getDescent())) {
textPieces.setDescent(glyphDescent);
}
}
Comment thread
LonelyMidoriya marked this conversation as resolved.

textPieces.add(new TextPieces.TextPiece(value, current, current + width));
textPieces.shiftCurrent(shift);
}
Expand Down Expand Up @@ -934,7 +948,7 @@ private TextChunk createTextChunk(List<COSBase> arguments, String operatorType,
PDFontDescriptor descriptor = font.getFontDescriptor();
String fontNameWithoutSubset = font.getNameWithoutSubset();
TextChunk textChunk = new TextChunk(
TextChunksHelper.calculateTextBoundingBox(isVertical, textRenderingMatrixBefore, textRenderingMatrixAfter, font, pageNumber),
TextChunksHelper.calculateTextBoundingBox(isVertical, textRenderingMatrixBefore, textRenderingMatrixAfter, font, pageNumber, textPieces),
textPieces.getValue(), fontNameWithoutSubset, TextChunksHelper.calculateTextSize(textRenderingMatrixAfter),
TextChunksHelper.calculateFontWeight(graphicsState.getTextState().getRenderingMode(), font),
descriptor.getItalicAngle(), TextChunksHelper.calculateTextBaseLine(textRenderingMatrixAfter),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ protected static COSBase getArgument(List<COSBase> arguments, String operatorTyp
}

protected static BoundingBox calculateTextBoundingBox(boolean isVertical, Matrix textRenderingMatrixBefore,
Matrix textRenderingMatrixAfter, PDFont font, Integer pageNumber) {
Matrix textRenderingMatrixAfter, PDFont font, Integer pageNumber, TextPieces textPieces) {
return isVertical ? TextChunksHelper.calculateTextBoundingBoxV(textRenderingMatrixBefore, textRenderingMatrixAfter, pageNumber)
: TextChunksHelper.calculateTextBoundingBoxH(textRenderingMatrixBefore, textRenderingMatrixAfter, font, pageNumber);
: TextChunksHelper.calculateTextBoundingBoxH(textRenderingMatrixBefore, textRenderingMatrixAfter, font, pageNumber, textPieces);
}

private static BoundingBox calculateTextBoundingBoxH(Matrix textRenderingMatrixBefore, Matrix textRenderingMatrixAfter,
PDFont font, Integer pageNumber) {
PDFont font, Integer pageNumber, TextPieces textPieces) {
double[] fontBoundingBox = font.getBoundingBox();
Double descent = font.getDescent();
if (descent == null) {
descent = fontBoundingBox[1];
descent = textPieces.getDescent() != null ? textPieces.getDescent() : fontBoundingBox[1];
}
Double ascent = font.getAscent();
if (ascent == null) {
ascent = fontBoundingBox[3];
ascent = textPieces.getAscent() != null ? textPieces.getAscent() : fontBoundingBox[3];
}
double x1;
double x2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class TextPieces {
public final boolean isVertical;
private int currentIndex;
private double current;
private Double ascent;
private Double descent;

TextPieces(boolean isVertical) {
this.isVertical = isVertical;
Expand Down Expand Up @@ -132,7 +134,23 @@ public List<StreamInfo> getStreamInfos(int operatorIndex, String xObjectName) {
}
}
return streamInfos;
}
}

public Double getAscent() {
return ascent;
}

public void setAscent(double ascent) {
this.ascent = ascent;
}

public Double getDescent() {
return descent;
}

public void setDescent(double descent) {
this.descent = descent;
}

public static class TextPiece {
private final String value;
Expand Down
Loading