| Method from com.lowagie.text.pdf.BaseField Detail: |
protected static ArrayList breakLines(ArrayList breaks,
BaseFont font,
float fontSize,
float width) {
ArrayList lines = new ArrayList();
StringBuffer buf = new StringBuffer();
for (int ck = 0; ck < breaks.size(); ++ck) {
buf.setLength(0);
float w = 0;
char cs[] = ((String)breaks.get(ck)).toCharArray();
int len = cs.length;
// 0 inline first, 1 inline, 2 spaces
int state = 0;
int lastspace = -1;
char c = 0;
int refk = 0;
for (int k = 0; k < len; ++k) {
c = cs[k];
switch (state) {
case 0:
w += font.getWidthPoint(c, fontSize);
buf.append(c);
if (w > width) {
w = 0;
if (buf.length() > 1) {
--k;
buf.setLength(buf.length() - 1);
}
lines.add(buf.toString());
buf.setLength(0);
refk = k;
if (c == ' ")
state = 2;
else
state = 1;
}
else {
if (c != ' ")
state = 1;
}
break;
case 1:
w += font.getWidthPoint(c, fontSize);
buf.append(c);
if (c == ' ")
lastspace = k;
if (w > width) {
w = 0;
if (lastspace >= 0) {
k = lastspace;
buf.setLength(lastspace - refk);
trimRight(buf);
lines.add(buf.toString());
buf.setLength(0);
refk = k;
lastspace = -1;
state = 2;
}
else {
if (buf.length() > 1) {
--k;
buf.setLength(buf.length() - 1);
}
lines.add(buf.toString());
buf.setLength(0);
refk = k;
if (c == ' ")
state = 2;
}
}
break;
case 2:
if (c != ' ") {
w = 0;
--k;
state = 1;
}
break;
}
}
trimRight(buf);
lines.add(buf.toString());
}
return lines;
}
|
public int getAlignment() {
return this.alignment;
}
Gets the text horizontal alignment. |
public Color getBackgroundColor() {
return this.backgroundColor;
}
Gets the background color. |
protected PdfAppearance getBorderAppearance() {
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;
}
app.saveState();
// background
if (backgroundColor != null) {
app.setColorFill(backgroundColor);
app.rectangle(0, 0, box.getWidth(), box.getHeight());
app.fill();
}
// border
if (borderStyle == PdfBorderDictionary.STYLE_UNDERLINE) {
if (borderWidth != 0 && borderColor != null) {
app.setColorStroke(borderColor);
app.setLineWidth(borderWidth);
app.moveTo(0, borderWidth / 2);
app.lineTo(box.getWidth(), borderWidth / 2);
app.stroke();
}
}
else if (borderStyle == PdfBorderDictionary.STYLE_BEVELED) {
if (borderWidth != 0 && borderColor != null) {
app.setColorStroke(borderColor);
app.setLineWidth(borderWidth);
app.rectangle(borderWidth / 2, borderWidth / 2, box.getWidth() - borderWidth, box.getHeight() - borderWidth);
app.stroke();
}
// beveled
Color actual = backgroundColor;
if (actual == null)
actual = Color.white;
app.setGrayFill(1);
drawTopFrame(app);
app.setColorFill(actual.darker());
drawBottomFrame(app);
}
else if (borderStyle == PdfBorderDictionary.STYLE_INSET) {
if (borderWidth != 0 && borderColor != null) {
app.setColorStroke(borderColor);
app.setLineWidth(borderWidth);
app.rectangle(borderWidth / 2, borderWidth / 2, box.getWidth() - borderWidth, box.getHeight() - borderWidth);
app.stroke();
}
// inset
app.setGrayFill(0.5f);
drawTopFrame(app);
app.setGrayFill(0.75f);
drawBottomFrame(app);
}
else {
if (borderWidth != 0 && borderColor != null) {
if (borderStyle == PdfBorderDictionary.STYLE_DASHED)
app.setLineDash(3, 0);
app.setColorStroke(borderColor);
app.setLineWidth(borderWidth);
app.rectangle(borderWidth / 2, borderWidth / 2, box.getWidth() - borderWidth, box.getHeight() - borderWidth);
app.stroke();
if ((options & COMB) != 0 && maxCharacterLength > 1) {
float step = box.getWidth() / maxCharacterLength;
float yb = borderWidth / 2;
float yt = box.getHeight() - borderWidth / 2;
for (int k = 1; k < maxCharacterLength; ++k) {
float x = step * k;
app.moveTo(x, yb);
app.lineTo(x, yt);
}
app.stroke();
}
}
}
app.restoreState();
return app;
}
|
public Color getBorderColor() {
return this.borderColor;
}
|
public int getBorderStyle() {
return this.borderStyle;
}
|
public float getBorderWidth() {
return this.borderWidth;
}
Gets the border width in points. |
public Rectangle getBox() {
return this.box;
}
Gets the field dimension and position. |
public String getFieldName() {
return this.fieldName;
}
|
public BaseFont getFont() {
return this.font;
}
|
public float getFontSize() {
return this.fontSize;
}
|
protected static ArrayList getHardBreaks(String text) {
ArrayList arr = new ArrayList();
char cs[] = text.toCharArray();
int len = cs.length;
StringBuffer buf = new StringBuffer();
for (int k = 0; k < len; ++k) {
char c = cs[k];
if (c == '\r") {
if (k + 1 < len && cs[k + 1] == '\n")
++k;
arr.add(buf.toString());
buf = new StringBuffer();
}
else if (c == '\n") {
arr.add(buf.toString());
buf = new StringBuffer();
}
else
buf.append(c);
}
arr.add(buf.toString());
return arr;
}
|
public int getMaxCharacterLength() {
return this.maxCharacterLength;
}
Gets the maximum length of the field's text, in characters. |
public int getOptions() {
return this.options;
}
|
protected BaseFont getRealFont() throws IOException, DocumentException {
if (font == null)
return BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false);
else
return font;
}
|
public int getRotation() {
return this.rotation;
}
|
public String getText() {
return this.text;
}
|
public Color getTextColor() {
return this.textColor;
}
|
public int getVisibility() {
return this.visibility;
}
Gets the field visibility flag. |
public PdfWriter getWriter() {
return writer;
}
Getter for property writer. |
public static void moveFields(PdfDictionary from,
PdfDictionary to) {
for (Iterator i = from.getKeys().iterator(); i.hasNext();) {
PdfName key = (PdfName)i.next();
if (fieldKeys.containsKey(key)) {
if (to != null)
to.put(key, from.get(key));
i.remove();
}
}
}
Moves the field keys from from to to. The moved keys
are removed from from. |
public void setAlignment(int alignment) {
this.alignment = alignment;
}
Sets the text horizontal alignment. It can be Element.ALIGN_LEFT,
Element.ALIGN_CENTER and Element.ALIGN_RIGHT. |
public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
}
Sets the background color. Set to null for
transparent background. |
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
Sets the border color. Set to null to remove
the border. |
public void setBorderStyle(int borderStyle) {
this.borderStyle = borderStyle;
}
Sets the border style. The styles are found in PdfBorderDictionary
and can be STYLE_SOLID, STYLE_DASHED,
STYLE_BEVELED, STYLE_INSET and
STYLE_UNDERLINE. |
public void setBorderWidth(float borderWidth) {
this.borderWidth = borderWidth;
}
Sets the border width in points. To eliminate the border
set the border color to null. |
public void setBox(Rectangle box) {
if (box == null) {
this.box = null;
}
else {
this.box = new Rectangle(box);
this.box.normalize();
}
}
Sets the field dimension and position. |
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
|
public void setFont(BaseFont font) {
this.font = font;
}
Sets the text font. If null then Helvetica
will be used. |
public void setFontSize(float fontSize) {
this.fontSize = fontSize;
}
Sets the font size. If 0 then auto-sizing will be used but
only for text fields. |
public void setMaxCharacterLength(int maxCharacterLength) {
this.maxCharacterLength = maxCharacterLength;
}
Sets the maximum length of the field's text, in characters.
It is only meaningful for text fields. |
public void setOptions(int options) {
this.options = options;
}
Sets the option flags. The option flags can be a combination by oring of
READ_ONLY, REQUIRED,
MULTILINE, DO_NOT_SCROLL,
PASSWORD, FILE_SELECTION,
DO_NOT_SPELL_CHECK and EDIT. |
public void setRotation(int rotation) {
if (rotation % 90 != 0)
throw new IllegalArgumentException("Rotation must be a multiple of 90.");
rotation %= 360;
if (rotation < 0)
rotation += 360;
this.rotation = rotation;
}
Sets the field rotation. This value should be the same as
the page rotation where the field will be shown. |
public void setRotationFromPage(Rectangle page) {
setRotation(page.getRotation());
}
Convenience method to set the field rotation the same as the
page rotation. |
public void setText(String text) {
this.text = text;
}
Sets the text for text fields. |
public void setTextColor(Color textColor) {
this.textColor = textColor;
}
Sets the text color. If null the color used
will be black. |
public void setVisibility(int visibility) {
this.visibility = visibility;
}
Sets the field visibility flag. This flags can be one of
VISIBLE, HIDDEN, VISIBLE_BUT_DOES_NOT_PRINT
and HIDDEN_BUT_PRINTABLE. |
public void setWriter(PdfWriter writer) {
this.writer = writer;
}
Setter for property writer. |
protected static void trimRight(StringBuffer buf) {
int len = buf.length();
while (true) {
if (len == 0)
return;
if (buf.charAt(--len) != ' ")
return;
buf.setLength(len);
}
}
|