Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compile error using forthcoming release of PDFL. #81

Merged
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 @@ -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
Loading