Exemple #1
0
 public static PdfShading simpleRadial(
     PdfWriter writer,
     float x0,
     float y0,
     float r0,
     float x1,
     float y1,
     float r1,
     BaseColor startColor,
     BaseColor endColor,
     boolean extendStart,
     boolean extendEnd) {
   checkCompatibleColors(startColor, endColor);
   PdfFunction function =
       PdfFunction.type2(
           writer,
           new float[] {0, 1},
           null,
           getColorArray(startColor),
           getColorArray(endColor),
           1);
   return type3(
       writer,
       startColor,
       new float[] {x0, y0, r0, x1, y1, r1},
       null,
       function,
       new boolean[] {extendStart, extendEnd});
 }
Exemple #2
0
 public static PdfShading type1(
     PdfWriter writer,
     BaseColor colorSpace,
     float domain[],
     float tMatrix[],
     PdfFunction function) {
   PdfShading sp = new PdfShading(writer);
   sp.shading = new PdfDictionary();
   sp.shadingType = 1;
   sp.shading.put(PdfName.SHADINGTYPE, new PdfNumber(sp.shadingType));
   sp.setColorSpace(colorSpace);
   if (domain != null) sp.shading.put(PdfName.DOMAIN, new PdfArray(domain));
   if (tMatrix != null) sp.shading.put(PdfName.MATRIX, new PdfArray(tMatrix));
   sp.shading.put(PdfName.FUNCTION, function.getReference());
   return sp;
 }
Exemple #3
0
 public static PdfShading type2(
     PdfWriter writer,
     BaseColor colorSpace,
     float coords[],
     float domain[],
     PdfFunction function,
     boolean extend[]) {
   PdfShading sp = new PdfShading(writer);
   sp.shading = new PdfDictionary();
   sp.shadingType = 2;
   sp.shading.put(PdfName.SHADINGTYPE, new PdfNumber(sp.shadingType));
   sp.setColorSpace(colorSpace);
   sp.shading.put(PdfName.COORDS, new PdfArray(coords));
   if (domain != null) sp.shading.put(PdfName.DOMAIN, new PdfArray(domain));
   sp.shading.put(PdfName.FUNCTION, function.getReference());
   if (extend != null && (extend[0] || extend[1])) {
     PdfArray array = new PdfArray(extend[0] ? PdfBoolean.PDFTRUE : PdfBoolean.PDFFALSE);
     array.add(extend[1] ? PdfBoolean.PDFTRUE : PdfBoolean.PDFFALSE);
     sp.shading.put(PdfName.EXTEND, array);
   }
   return sp;
 }
Exemple #4
0
  protected PdfObject getSpotObject(PdfWriter writer) throws IOException {
    PdfArray array = new PdfArray(PdfName.SEPARATION);
    array.add(name);
    PdfFunction func = null;
    if (altcs instanceof ExtendedColor) {
      int type = ((ExtendedColor) altcs).type;

      // ssteward
      // having trouble with unreachable bytecode in switch default (per gcj 4.4)
      // so try a clumsier workaround
      boolean handled_b = false;
      switch (type) {
        case ExtendedColor.TYPE_GRAY:
          array.add(PdfName.DEVICEGRAY);
          func =
              PdfFunction.type2(
                  writer,
                  new float[] {0, 1},
                  null,
                  new float[] {0},
                  new float[] {((GrayColor) altcs).getGray()},
                  1);
          handled_b = true;
          break;
        case ExtendedColor.TYPE_CMYK:
          array.add(PdfName.DEVICECMYK);
          CMYKColor cmyk = (CMYKColor) altcs;
          func =
              PdfFunction.type2(
                  writer,
                  new float[] {0, 1},
                  null,
                  new float[] {0, 0, 0, 0},
                  new float[] {
                    cmyk.getCyan(), cmyk.getMagenta(), cmyk.getYellow(), cmyk.getBlack()
                  },
                  1);
          handled_b = true;
          break;
          //                default:
          //                    throw new RuntimeException("Only RGB, Gray and CMYK are supported as
          // alternative color spaces.");
      }
      if (!handled_b) {
        throw new RuntimeException(
            "Only RGB, Gray and CMYK are supported as alternative color spaces.");
      }
    } else {
      array.add(PdfName.DEVICERGB);
      func =
          PdfFunction.type2(
              writer,
              new float[] {0, 1},
              null,
              new float[] {1, 1, 1},
              new float[] {
                (float) altcs.getRed() / 255,
                (float) altcs.getGreen() / 255,
                (float) altcs.getBlue() / 255
              },
              1);
    }
    array.add(func.getReference());
    return array;
  }