use of com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor in project PdfBox-Android by TomRoush.
the class PDBoxStyle method getGuidelineColor.
/**
* Get the RGB color to be used for the guidelines. This is guaranteed to
* not return null. The default color is [0,0,0].
*
*@return The guideline color.
*/
public PDColor getGuidelineColor() {
COSArray colorValues = (COSArray) dictionary.getDictionaryObject(COSName.C);
if (colorValues == null) {
colorValues = new COSArray();
colorValues.add(COSInteger.ZERO);
colorValues.add(COSInteger.ZERO);
colorValues.add(COSInteger.ZERO);
dictionary.setItem(COSName.C, colorValues);
}
return new PDColor(colorValues.toFloatArray(), PDDeviceRGB.INSTANCE);
}
use of com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor in project PdfBox-Android by TomRoush.
the class PDDefaultAppearanceString method processSetFontColor.
/**
* Process the font color operator.
*
* This is assumed to be an RGB color.
*
* @param operands the color components
* @throws IOException in case of the color components not matching
*/
private void processSetFontColor(List<COSBase> operands) throws IOException {
PDColorSpace colorSpace;
switch(operands.size()) {
case 1:
colorSpace = PDDeviceGray.INSTANCE;
break;
case 3:
colorSpace = PDDeviceRGB.INSTANCE;
break;
case 4:
// colorSpace = PDDeviceCMYK.INSTANCE; TODO: PdfBox-Android
colorSpace = PDDeviceRGB.INSTANCE;
break;
default:
throw new IOException("Missing operands for set non stroking color operator " + Arrays.toString(operands.toArray()));
}
COSArray array = new COSArray();
array.addAll(operands);
setFontColor(new PDColor(array, colorSpace));
}
use of com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor in project PdfBox-Android by TomRoush.
the class PDPageContentStream method setNonStrokingColor.
/**
* Set the non-stroking color using an AWT color. Conversion uses the default sRGB color space.
*
* @param color The color to set.
* @throws IOException If an IO error occurs while writing to the stream.
*/
public void setNonStrokingColor(AWTColor color) throws IOException {
float[] components = new float[] { color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f };
PDColor pdColor = new PDColor(components, PDDeviceRGB.INSTANCE);
setNonStrokingColor(pdColor);
}
use of com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor in project PdfBox-Android by TomRoush.
the class PDOutlineItem method getTextColor.
/**
* Get the RGB text color of this node. Default is black and this method
* will never return null.
*
* @return The structure element of this node.
*/
public PDColor getTextColor() {
COSArray csValues = (COSArray) getCOSObject().getDictionaryObject(COSName.C);
if (csValues == null) {
csValues = new COSArray();
csValues.growToSize(3, new COSFloat(0));
getCOSObject().setItem(COSName.C, csValues);
}
return new PDColor(csValues, PDDeviceRGB.INSTANCE);
}
use of com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor in project PdfBox-Android by TomRoush.
the class AppearanceGeneratorHelper method initializeAppearanceContent.
/**
* Initialize the content of the appearance stream.
*
* Get settings like border style, border width and colors to be used to draw a rectangle and background color
* around the widget
*
* @param widget the field widget
* @param appearanceStream the appearance stream to be used
* @throws IOException in case we can't write to the appearance stream
*/
private void initializeAppearanceContent(PDAnnotationWidget widget, PDAppearanceStream appearanceStream) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
PDPageContentStream contents = new PDPageContentStream(field.getAcroForm().getDocument(), appearanceStream, output);
PDAppearanceCharacteristicsDictionary appearanceCharacteristics = widget.getAppearanceCharacteristics();
// TODO: support more entries like patterns, etc.
if (appearanceCharacteristics != null) {
PDColor backgroundColour = appearanceCharacteristics.getBackground();
if (backgroundColour != null) {
contents.setNonStrokingColor(backgroundColour);
PDRectangle bbox = resolveBoundingBox(widget, appearanceStream);
contents.addRect(bbox.getLowerLeftX(), bbox.getLowerLeftY(), bbox.getWidth(), bbox.getHeight());
contents.fill();
}
float lineWidth = 0f;
PDColor borderColour = appearanceCharacteristics.getBorderColour();
if (borderColour != null) {
contents.setStrokingColor(borderColour);
lineWidth = 1f;
}
PDBorderStyleDictionary borderStyle = widget.getBorderStyle();
if (borderStyle != null && borderStyle.getWidth() > 0) {
lineWidth = borderStyle.getWidth();
}
if (lineWidth > 0 && borderColour != null) {
if (lineWidth != 1) {
contents.setLineWidth(lineWidth);
}
PDRectangle bbox = resolveBoundingBox(widget, appearanceStream);
PDRectangle clipRect = applyPadding(bbox, Math.max(DEFAULT_PADDING, lineWidth / 2));
contents.addRect(clipRect.getLowerLeftX(), clipRect.getLowerLeftY(), clipRect.getWidth(), clipRect.getHeight());
contents.closeAndStroke();
}
}
contents.close();
output.close();
writeToStream(output.toByteArray(), appearanceStream);
}
Aggregations