Package org.apache.fop.pdf

Examples of org.apache.fop.pdf.PDFColor


      int  irx = (int)(rx * cfact);
      int  iry = (int)(ry * cfact);
      int  isw = (int)(sw * cfact);
      int  longwidth = 0;
      int  pass = 0;
      PDFColor thecolor = null;

      do
      {
        if ( pass == 0 && fc != null )
        {
          thecolor = fc;
        }
        else if ( pass == 1 && sc != null )
        {
          int  iswdiv2 = isw / 2;
          thecolor = sc;
          ix -= iswdiv2;
          iy -= iswdiv2;
          irx += iswdiv2;
          iry += iswdiv2;
          iw += isw;
          ih += isw;
          longwidth = (int)(isw * 1.414);
        }
        else
          thecolor = null;


        if ( thecolor != null )
        {
          int    tx = 0;
          int    ty = iry;
          long  a = irx;
          long  b = iry;
          long  Asquared = (long)Math.pow(a, 2);
          long  TwoAsquared = 2 * Asquared;
          long  Bsquared = (long)Math.pow(b, 2);
          long  TwoBsquared = 2 * Bsquared;
          long  d = Bsquared - Asquared * b + Asquared / 4;
          long  dx = 0;
          long  dy = TwoAsquared * b;
          int    rectlen = iw - 2 * irx;
          Vector  bottomlines = new Vector();

          int x0 = tx;

          // Set Transparency modes and select shading.
          currentStream.add("\033*v0n1O\033*c" + (int)(100 - ((0.3f * thecolor.red() + 0.59f * thecolor.green() + 0.11f * thecolor.blue()) * 100f)) + "G\033*v2T");
          // Move to starting position.
          currentStream.add("\033*p" + ix + "x" + iy + "Y");
          // Start raster graphics
          currentStream.add("\033*t300R\033*r" + iw + "s1A\033*b1M");

 
View Full Code Here


    int x = posx;
    int y = posy;
    SVGStylable style = null;
    if ( area instanceof SVGStylable )
      style = (SVGStylable)area;
    PDFColor fillColour = null;
    PDFColor strokeColour = null;
    float strokeWidth = 1;

    //currentStream.add("q\n");
    //if( area instanceof SVGTransformable )
    //{
    //  SVGTransformable tf = (SVGTransformable)area;
    //  SVGAnimatedTransformList trans = tf.getTransform();
    //  SVGRect bbox = tf.getBBox();
    //  if(trans != null) {
    //    applyTransform(trans, bbox);
    //  }
    //}

    if(style != null)
    {
          CSSValue sp;
          sp = style.getPresentationAttribute("fill");
          if (sp != null)
          {
              if (sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE)
              {
                  if (((CSSPrimitiveValue) sp).getPrimitiveType() == CSSPrimitiveValue.CSS_RGBCOLOR)
                  {
                      RGBColor col = ((CSSPrimitiveValue) sp).getRGBColorValue();
                      CSSPrimitiveValue val;
                      val = col.getRed();
                      float red = val.getFloatValue(CSSPrimitiveValue.CSS_NUMBER);
                      val = col.getGreen();
                      float green = val.getFloatValue(CSSPrimitiveValue.CSS_NUMBER);
                      val = col.getBlue();
                      float blue = val.getFloatValue(CSSPrimitiveValue.CSS_NUMBER);
                      fillColour = new PDFColor(red, green, blue);
                      currentColour = fillColour;
                  }
                  else if ( ((CSSPrimitiveValue) sp).getPrimitiveType() == CSSPrimitiveValue.CSS_STRING)
                  {
                      String str = ((CSSPrimitiveValue) sp).getCssText();
                      if ( str.equals("none") )
                      {
                          fillColour = null;
                      }
                      else if ( str.equals("currentColor") )
                      {
                          fillColour = currentColour;
                      }
                  }
              }
          }
          else
          {
              fillColour = new PDFColor(0, 0, 0);
          }
          sp = style.getPresentationAttribute("stroke");
          if ( sp != null )
          {
              if ( sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE )
              {
                  if ( ((CSSPrimitiveValue) sp).getPrimitiveType() == CSSPrimitiveValue.CSS_RGBCOLOR )
                  {
                      RGBColor col = ((CSSPrimitiveValue) sp).getRGBColorValue();
                      CSSPrimitiveValue val;
                      val = col.getRed();
                      float red = val.getFloatValue(CSSPrimitiveValue.CSS_NUMBER);
                      val = col.getGreen();
                      float green = val.getFloatValue(CSSPrimitiveValue.CSS_NUMBER);
                      val = col.getBlue();
                      float blue = val.getFloatValue(CSSPrimitiveValue.CSS_NUMBER);
                      strokeColour = new PDFColor(red, green, blue);
                  }
                  else if ( ((CSSPrimitiveValue) sp).getPrimitiveType() == CSSPrimitiveValue.CSS_STRING )
                  {
                      String str = ((CSSPrimitiveValue) sp).getCssText();
                      if (str.equals("none"))
                      {
              strokeColour = null;
                      }
                  }
              }
          }
          else
          {
              strokeColour = new PDFColor(0, 0, 0);
          }
          sp = style.getPresentationAttribute("stroke-width");
          if ( sp != null )
          {
              if ( sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE )
View Full Code Here

        ColorType bg = area.getBackgroundColor();

        // I'm not sure I should have to check for bg being null
        // but I do
        if ((bg != null) && (bg.alpha() == 0)) {
            this.addRect(rx, ry, w, -h, new PDFColor(bg), new PDFColor(bg));
        }

    // floats & footnotes stuff
    renderAreaContainer(area.getBeforeFloatReferenceArea());
      renderAreaContainer(area.getFootnoteReferenceArea());
View Full Code Here

        h = h + area.getPaddingTop() + area.getPaddingBottom();

        // I'm not sure I should have to check for bg being null
        // but I do
        if ((bg != null) && (bg.alpha() == 0)) {
            this.addRect(rx, ry, w, -h, new PDFColor(bg), new PDFColor(bg));
        }

        //rx = rx - area.getBorderLeftWidth();
        //ry = ry + area.getBorderTopWidth();
        //w = w + area.getBorderLeftWidth() + area.getBorderRightWidth();
        //h = h + area.getBorderTopWidth() + area.getBorderBottomWidth();

  // Handle line style
  // Offset for haft the line width!
  BorderAndPadding bp = area.getBorderAndPadding();
  int left = rx - area.getBorderLeftWidth() / 2;
  int right = rx + w + area.getBorderRightWidth() / 2;
  int top = ry + area.getBorderTopWidth() / 2;
  int bottom = ry - h - area.getBorderBottomWidth() / 2;
        if (area.getBorderTopWidth() != 0)
            addLine(left, top, right, top, area.getBorderTopWidth(),
                    new PDFColor(bp.getBorderColor(BorderAndPadding.TOP)));
        if (area.getBorderLeftWidth() != 0)
            addLine(left, ry + area.getBorderTopWidth(), left, bottom, area.getBorderLeftWidth(),
                    new PDFColor(bp.getBorderColor(BorderAndPadding.LEFT)));
        if (area.getBorderRightWidth() != 0)
            addLine(right, ry + area.getBorderTopWidth(), right, bottom, area.getBorderRightWidth(),
                    new PDFColor(bp.getBorderColor(BorderAndPadding.RIGHT)));
        if (area.getBorderBottomWidth() != 0)
            addLine(rx - area.getBorderLeftWidth(), bottom, rx + w + area.getBorderRightWidth(), bottom, area.getBorderBottomWidth(),
                    new PDFColor(bp.getBorderColor(BorderAndPadding.BOTTOM)));

    }
View Full Code Here

        //a line with thickness 0 is still displayed
        if (th != 0) {
            switch (st) {
                case org.apache.fop.fo.properties.RuleStyle.DOUBLE:
                    addLine(rx, ry, rx + w, ry, th / 3, st,
                            new PDFColor(area.getRed(),
                                         area.getGreen(), area.getBlue()));
                    addLine(rx, ry + (2 * th / 3), rx + w,
                            ry + (2 * th / 3), th / 3, st,
                            new PDFColor(area.getRed(),
                                         area.getGreen(), area.getBlue()));
                    break;
                case org.apache.fop.fo.properties.RuleStyle.GROOVE:
                    addLine(rx, ry, rx + w, ry, th / 2, st,
                            new PDFColor(area.getRed(),
                                         area.getGreen(), area.getBlue()));
                    addLine(rx, ry + (th / 2), rx + w, ry + (th / 2),
                            th / 2, st, new PDFColor(255, 255, 255));
                    break;
                case org.apache.fop.fo.properties.RuleStyle.RIDGE:
                    addLine(rx, ry, rx + w, ry, th / 2, st,
                            new PDFColor(255, 255, 255));
                    addLine(rx, ry + (th / 2), rx + w, ry + (th / 2),
                            th / 2, st,
                            new PDFColor(area.getRed(),
                                         area.getGreen(), area.getBlue()));
                    break;
                default:
                    addLine(rx, ry, rx + w, ry, th, st,
                            new PDFColor(area.getRed(),
                                         area.getGreen(), area.getBlue()));
            }
            this.currentXPosition += area.getContentWidth();
            this.currentYPosition += th;
        }
View Full Code Here

                Color c1 = cols[count];
                if (c1.getAlpha() != 255) {
                    return false// PDF can't do alpha
                }

                PDFColor color1 = new PDFColor(c1.getRed(), c1.getGreen(),
                                               c1.getBlue());
                someColors.add(color1);
                if (count > 0 && count < cols.length - 1) {
                    theBounds.add(new Double(fractions[count]));
                }
            }

            PDFDeviceColorSpace aColorSpace;
            aColorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
            PDFPattern myPat = pdfDoc.getFactory().makeGradient(
                    resourceContext, false, aColorSpace,
                    someColors, theBounds, theCoords, theMatrix);
            currentStream.write(myPat.getColorSpaceOut(fill));

            return true;
        }
        if (paint instanceof RadialGradientPaint) {
            RadialGradientPaint rgp = (RadialGradientPaint)paint;

            // There is essentially no way to support repeats
            // in PDF for radial gradients (the one option would
            // be to 'grow' the outer circle until it fully covered
            // the bounds and then grow the stops accordingly, the
            // problem is that this may require an extremely large
            // number of stops for cases where the focus is near
            // the edge of the outer circle).  so we rasterize.
            MultipleGradientPaint.CycleMethodEnum cycle = rgp.getCycleMethod();
            if (cycle != MultipleGradientPaint.NO_CYCLE) {
                return false;
            }

            AffineTransform transform;
            transform = new AffineTransform(getBaseTransform());
            transform.concatenate(getTransform());
            transform.concatenate(rgp.getTransform());

            List theMatrix = new java.util.ArrayList();
            double [] mat = new double[6];
            transform.getMatrix(mat);
            for (int idx = 0; idx < mat.length; idx++) {
                theMatrix.add(new Double(mat[idx]));
            }

            double ar = rgp.getRadius();
            Point2D ac = rgp.getCenterPoint();
            Point2D af = rgp.getFocusPoint();

            List theCoords = new java.util.ArrayList();
            double dx = af.getX() - ac.getX();
            double dy = af.getY() - ac.getY();
            double d = Math.sqrt(dx * dx + dy * dy);
            if (d > ar) {
                // the center point af must be within the circle with
                // radius ar centered at ac so limit it to that.
                double scale = (ar * .9999) / d;
                dx = dx * scale;
                dy = dy * scale;
            }

            theCoords.add(new Double(ac.getX() + dx)); // Fx
            theCoords.add(new Double(ac.getY() + dy)); // Fy
            theCoords.add(new Double(0));
            theCoords.add(new Double(ac.getX()));
            theCoords.add(new Double(ac.getY()));
            theCoords.add(new Double(ar));

            Color[] cols = rgp.getColors();
            List someColors = new java.util.ArrayList();
            for (int count = 0; count < cols.length; count++) {
                Color cc = cols[count];
                if (cc.getAlpha() != 255) {
                    return false// PDF can't do alpha
                }

                someColors.add(new PDFColor(cc.getRed(), cc.getGreen(),
                                            cc.getBlue()));
            }

            float[] fractions = rgp.getFractions();
            List theBounds = new java.util.ArrayList();
View Full Code Here

                flushPDFDocument();
            }
            BitmapImage fopimg;
            fopimg = new BitmapImage("TempImage:" + pctx.toString(),
                                     devW, devH, rgb, maskRef);
            fopimg.setTransparent(new PDFColor(255, 255, 255));
            imageInfo = pdfDoc.addImage(resourceContext, fopimg);
            flushPDFDocument();
        }

        currentStream.write("q\n");
View Full Code Here

     * Rather than leaving it as the default white.
     * @param col the background colour to fill
     */
    public void setBackgroundColor(Color col) {
        Color c = col;
        PDFColor currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
        currentStream.write("q\n");
        currentStream.write(currentColour.getColorSpaceOut(true));

        currentStream.write("0 0 " + width + " " + height + " re\n");

        currentStream.write("f\n");
        currentStream.write("Q\n");
View Full Code Here

     * @param fill true to set the fill color, false for the foreground color
     * @param stream the PDFStream to write the PDF code to
     */
    public void setColor(Color col, boolean fill, PDFStream stream) {
        assert stream != null;
        PDFColor color = new PDFColor(this.document, col);
        stream.add(color.getColorSpaceOut(fill));
    }
View Full Code Here

     * @param pdf StringBuffer to write the PDF code to, if null, the code is
     *     written to the current stream.
     */
    protected void setColor(Color col, boolean fill, StringBuffer pdf) {
        if (pdf != null) {
            PDFColor color = new PDFColor(this.document, col);
            pdf.append(color.getColorSpaceOut(fill));
        } else {
            setColor(col, fill, this.currentStream);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.fop.pdf.PDFColor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.