Skip to content
Closed
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
13 changes: 12 additions & 1 deletion openpdf/src/main/java/com/lowagie/text/pdf/BaseField.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ public BaseField(PdfWriter writer, Rectangle box, String fieldName) {
protected static PdfAppearance getBorderAppearance(PdfWriter writer, Rectangle box, int rotation,
Color backgroundColor, int borderStyle, float borderWidth, Color borderColor, int options,
int maxCharacterLength) {
PdfAppearance app = createAppearance(writer, box, rotation);
drawBorderAppearance(box, backgroundColor, borderStyle, borderWidth, borderColor, options, maxCharacterLength,
app);
return app;
}

protected static PdfAppearance createAppearance(PdfWriter writer, Rectangle box, int rotation) {
PdfAppearance app = PdfAppearance.createAppearance(writer, box.getWidth(), box.getHeight());
switch (rotation) {
case 90:
Expand All @@ -238,6 +245,11 @@ protected static PdfAppearance getBorderAppearance(PdfWriter writer, Rectangle b
app.setMatrix(0, -1, 1, 0, 0, box.getWidth());
break;
}
return app;
}

protected static void drawBorderAppearance(Rectangle box, Color backgroundColor, int borderStyle, float borderWidth,
Color borderColor, int options, int maxCharacterLength, PdfAppearance app) {
app.saveState();
// background
if (backgroundColor != null) {
Expand Down Expand Up @@ -309,7 +321,6 @@ protected static PdfAppearance getBorderAppearance(PdfWriter writer, Rectangle b
}
}
app.restoreState();
return app;
}

protected static List<String> getAllHardBreaks(String text) {
Expand Down
68 changes: 15 additions & 53 deletions openpdf/src/main/java/com/lowagie/text/pdf/RadioCheckField.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static PdfAppearance getAppearance(boolean on, PdfWriter writer, int chec
return getAppearanceRadioCircle(on, writer, box, rotation, backgroundColor, borderWidth, borderColor,
textColor);
} else if (checkType == TYPE_CROSS) {
return getAppearanceRadioCross(on, writer, box, rotation, backgroundColor, borderWidth, borderColor,
return getAppearanceRadioCross(on, writer, box, rotation, backgroundColor, borderStyle, borderWidth, borderColor,
textColor);
}

Expand Down Expand Up @@ -218,21 +218,7 @@ public static PdfAppearance getAppearance(boolean on, PdfWriter writer, int chec
*/
public static PdfAppearance getAppearanceRadioCircle(boolean on, PdfWriter writer, Rectangle box, int rotation,
Color backgroundColor, float borderWidth, Color borderColor, Color textColor) {
PdfAppearance app = PdfAppearance.createAppearance(writer, box.getWidth(), box.getHeight());
switch (rotation) {
case 90:
app.setMatrix(0, 1, -1, 0, box.getHeight(), 0);
break;
case 180:
app.setMatrix(-1, 0, 0, -1, box.getWidth(), box.getHeight());
break;
case 270:
app.setMatrix(0, -1, 1, 0, 0, box.getWidth());
break;
case 0:
default:
break;
}
PdfAppearance app = createAppearance(writer, box, rotation);
Rectangle boundingBox = new Rectangle(app.getBoundingBox());
float cx = boundingBox.getWidth() / 2;
float cy = boundingBox.getHeight() / 2;
Expand Down Expand Up @@ -271,45 +257,20 @@ public static PdfAppearance getAppearanceRadioCircle(boolean on, PdfWriter write
* @return the appearance
*/
public static PdfAppearance getAppearanceRadioCross(boolean on, PdfWriter writer, Rectangle box, int rotation,
Color backgroundColor, float borderWidth, Color borderColor, Color textColor) {
Color backgroundColor, int borderStyle, float borderWidth, Color borderColor, Color textColor) {

PdfAppearance app = PdfAppearance.createAppearance(writer, box.getWidth(), box.getHeight());
switch (rotation) {
case 90:
app.setMatrix(0, 1, -1, 0, box.getHeight(), 0);
break;
case 180:
app.setMatrix(-1, 0, 0, -1, box.getWidth(), box.getHeight());
break;
case 270:
app.setMatrix(0, -1, 1, 0, 0, box.getWidth());
break;
}
PdfAppearance app = createAppearance(writer, box, rotation);

//"q"
app.saveState();

if (backgroundColor != null) {
app.setColorFill(backgroundColor);
} else {
//"0 0 0 rg"
app.setRGBColorFillF(0, 0, 0);
}

if (borderWidth > 0 && borderColor != null) {
app.setLineWidth(borderWidth);
app.setColorStroke(borderColor);
//draw surrounding rectangle
//"1 1 "+(width-2)+" "+(height-2)+" re"
app.rectangle(1, 1, box.getWidth() - 2, box.getHeight() - 2);

//"W"
app.clip();
}
drawBorderAppearance(box, backgroundColor, borderStyle, borderWidth, borderColor, 0, 0, app);

if (on) {
//"n"
app.newPath();
//"q"
app.saveState();

if (borderWidth > 0 && borderColor != null) {
app.setLineWidth(borderWidth);
app.setColorStroke(borderColor);
}

//draw lines of the cross:
//upper left corner
Expand All @@ -333,11 +294,12 @@ public static PdfAppearance getAppearanceRadioCross(boolean on, PdfWriter writer

//"s"
app.closePathStroke();

//"Q"
app.restoreState();
} else {
//draw nothing since it is the Off appearance
}
//"Q"
app.restoreState();

return app;
}
Expand Down