Search in sources :

Example 11 with PDColor

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);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) PDColor(com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)

Example 12 with PDColor

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));
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) IOException(java.io.IOException) PDColorSpace(com.tom_roush.pdfbox.pdmodel.graphics.color.PDColorSpace) PDColor(com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)

Example 13 with PDColor

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);
}
Also used : PDColor(com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)

Example 14 with 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);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSFloat(com.tom_roush.pdfbox.cos.COSFloat) PDColor(com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)

Example 15 with PDColor

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);
}
Also used : PDAppearanceCharacteristicsDictionary(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAppearanceCharacteristicsDictionary) PDPageContentStream(com.tom_roush.pdfbox.pdmodel.PDPageContentStream) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PDBorderStyleDictionary(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary) PDColor(com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)

Aggregations

PDColor (com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)22 IOException (java.io.IOException)12 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)11 PDAppearanceContentStream (com.tom_roush.pdfbox.pdmodel.PDAppearanceContentStream)10 COSArray (com.tom_roush.pdfbox.cos.COSArray)5 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)4 PDAnnotationTextMarkup (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationTextMarkup)4 PDAnnotationMarkup (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup)3 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)2 PDFormContentStream (com.tom_roush.pdfbox.pdmodel.PDFormContentStream)2 PDColorSpace (com.tom_roush.pdfbox.pdmodel.graphics.color.PDColorSpace)2 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)2 PDAppearanceCharacteristicsDictionary (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAppearanceCharacteristicsDictionary)2 PDBorderStyleDictionary (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)2 Matrix (com.tom_roush.pdfbox.util.Matrix)2 RectF (android.graphics.RectF)1 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)1 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)1 COSBase (com.tom_roush.pdfbox.cos.COSBase)1 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)1