Skip to content

Commit

Permalink
Merge pull request #81 from datalogics-josepha/fix-sample
Browse files Browse the repository at this point in the history
Fix compile error using forthcoming release of PDFL.
  • Loading branch information
datalogics-aarroyo authored Oct 4, 2024
2 parents e9bdf25 + 22d2dd3 commit 1109bad
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void setEndPoint(Point endPoint) {
}

public Form getNormalAppereance() {
return getProperty(AnnotationConsts.NORM_APPEARANCE, new Form(new Content()), Form.class);
return getProperty(AnnotationConsts.NORM_APPEARANCE, new Form(new Content(), null), Form.class);
}

public String getFontFace() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,105 +66,6 @@ private void setAutosize() {
}
}

/**
* Method is used to generate annotation appearance. It uses current font
* face, size, alignment and background and foreground colors of annotation.
*
* @return - new annotation form which constrains from input data
*/
private Form getAnnotationForm() {
Rect dLRect = getProperties().getBoundingRect();
String annotationText = getProperties().getContents();
Content content = (getProperties().getNormalAppereance() != null) ? getProperties().getNormalAppereance().getContent() : new Content();
GraphicState gs = new GraphicState();
Path path = new Path();
EnumSet<PathPaintOpFlags> pathPaintOpFlag;

if (gs.getStrokeColor() != null) {
gs.setStrokeColor(Utils.transform(getProperties().getForeColor()));
pathPaintOpFlag = path.getPaintOp();
pathPaintOpFlag.add(PathPaintOpFlags.STROKE);
path.setPaintOp(pathPaintOpFlag);
}
if (getProperties().hasFill()) {
gs.setFillColor(Utils.transform(getProperties().getInteriorColor()));
pathPaintOpFlag = path.getPaintOp();
pathPaintOpFlag.add(PathPaintOpFlags.FILL);
path.setPaintOp(pathPaintOpFlag);
}

// get the properties for the text
GraphicState gsTextRun = new GraphicState();
gsTextRun.setFillColor(Utils.transform(getProperties().getForeColor()));
TextState textState = new TextState();
textState.setFontSize(getProperties().getFontSize());

com.datalogics.PDFL.Matrix matrix = new com.datalogics.PDFL.Matrix();
matrix.setH(dLRect.getLeft());
matrix.setV(dLRect.getTop() - (textState.getFontSize() * 0.85)); // not the right formula but "close enough"

double textWidth = dLRect.getRight() - dLRect.getLeft();

// get the font
com.datalogics.PDFL.Font dLFont = initFont();
TextRun textRun = null;
Text text = new Text();

int i = 0;

double maxTextHeight = 0;
// grab the text from the Rich Textbox and add it to the text that will
// be used
// to create the FreeText Annotation
if (annotationText != null) {
String[] chars = annotationText.split("\n");
while (i < chars.length) {
if (chars.length > 0) {
if (getProperties().getQuadding() == HorizontalAlignment.LEFT)
matrix.setH(matrix.getH() + 2.0 * (gs.getWidth()));
try {
textRun = new TextRun(chars[i], dLFont, gsTextRun, textState, matrix);
} catch (Exception MissingCMapException) {
if (MissingCMapException.getMessage().contains("537067605")) {
Font tempFont = new com.datalogics.PDFL.Font("Helvetica");
textRun = new TextRun(chars[i], tempFont, gsTextRun, textState, matrix);
}
}

double advance = textRun.getAdvance();
double align = textWidth - advance;

maxTextHeight += textRun.getBoundingBox().getHeight();
if (getProperties().getQuadding() == HorizontalAlignment.RIGHT) {
matrix.setH(matrix.getH() + align);
textRun = new TextRun(chars[i], dLFont, gsTextRun, textState, matrix);
} else if (getProperties().getQuadding() == HorizontalAlignment.CENTER) {
matrix.setH(matrix.getH() + (align / 2.0));
textRun = new TextRun(chars[i], dLFont, gsTextRun, textState, matrix);
}

matrix.setH(dLRect.getLeft());
text.addRun(textRun);
}
matrix.setV(matrix.getV() - 1.2 * textState.getFontSize());
i++;
}
}

// create content to save the new annotation to
content = new Content();
path.setGraphicState(gs);
// adjust the rectangle so it does not clip the text
double width = dLRect.getRight() - dLRect.getLeft();
double height = dLRect.getTop() - dLRect.getBottom();

path.addRect(new Point(dLRect.getLeft(), dLRect.getBottom()), width, height);
content.addElement(path);
content.addElement(text);

return new Form(content); // create a new form and return it
}

/**
* Method is used to update FreeTextAnnotation's appearance. It sets font
* face, font size, font alignment and foreground and background colors of
Expand Down

0 comments on commit 1109bad

Please sign in to comment.