Esempio n. 1
0
 private static void drawLine(
     final PSGenerator gen,
     final float startx,
     final float starty,
     final float endx,
     final float endy)
     throws IOException {
   gen.writeln(
       gen.formatDouble(startx)
           + " "
           + gen.formatDouble(starty)
           + " M "
           + gen.formatDouble(endx)
           + " "
           + gen.formatDouble(endy)
           + " lineto stroke newpath");
 }
Esempio n. 2
0
 /** {@inheritDoc} */
 public static void drawBorderLine(
     final PSGenerator gen,
     final float x1,
     final float y1,
     final float x2,
     final float y2,
     final boolean horz,
     final boolean startOrBefore,
     final int style,
     final Color col)
     throws IOException {
   final float w = x2 - x1;
   final float h = y2 - y1;
   if (w < 0 || h < 0) {
     log.error("Negative extent received. Border won't be painted.");
     return;
   }
   switch (style) {
     case Constants.EN_DASHED:
       gen.useColor(col);
       if (horz) {
         float unit = Math.abs(2 * h);
         int rep = (int) (w / unit);
         if (rep % 2 == 0) {
           rep++;
         }
         unit = w / rep;
         gen.useDash("[" + unit + "] 0");
         gen.useLineCap(0);
         gen.useLineWidth(h);
         final float ym = y1 + h / 2;
         drawLine(gen, x1, ym, x2, ym);
       } else {
         float unit = Math.abs(2 * w);
         int rep = (int) (h / unit);
         if (rep % 2 == 0) {
           rep++;
         }
         unit = h / rep;
         gen.useDash("[" + unit + "] 0");
         gen.useLineCap(0);
         gen.useLineWidth(w);
         final float xm = x1 + w / 2;
         drawLine(gen, xm, y1, xm, y2);
       }
       break;
     case Constants.EN_DOTTED:
       gen.useColor(col);
       gen.useLineCap(1); // Rounded!
       if (horz) {
         float unit = Math.abs(2 * h);
         int rep = (int) (w / unit);
         if (rep % 2 == 0) {
           rep++;
         }
         unit = w / rep;
         gen.useDash("[0 " + unit + "] 0");
         gen.useLineWidth(h);
         final float ym = y1 + h / 2;
         drawLine(gen, x1, ym, x2, ym);
       } else {
         float unit = Math.abs(2 * w);
         int rep = (int) (h / unit);
         if (rep % 2 == 0) {
           rep++;
         }
         unit = h / rep;
         gen.useDash("[0 " + unit + "] 0");
         gen.useLineWidth(w);
         final float xm = x1 + w / 2;
         drawLine(gen, xm, y1, xm, y2);
       }
       break;
     case Constants.EN_DOUBLE:
       gen.useColor(col);
       gen.useDash(null);
       if (horz) {
         final float h3 = h / 3;
         gen.useLineWidth(h3);
         final float ym1 = y1 + h3 / 2;
         final float ym2 = ym1 + h3 + h3;
         drawLine(gen, x1, ym1, x2, ym1);
         drawLine(gen, x1, ym2, x2, ym2);
       } else {
         final float w3 = w / 3;
         gen.useLineWidth(w3);
         final float xm1 = x1 + w3 / 2;
         final float xm2 = xm1 + w3 + w3;
         drawLine(gen, xm1, y1, xm1, y2);
         drawLine(gen, xm2, y1, xm2, y2);
       }
       break;
     case Constants.EN_GROOVE:
     case Constants.EN_RIDGE:
       float colFactor = style == Constants.EN_GROOVE ? 0.4f : -0.4f;
       gen.useDash(null);
       if (horz) {
         final Color uppercol = ColorUtil.lightenColor(col, -colFactor);
         final Color lowercol = ColorUtil.lightenColor(col, colFactor);
         final float h3 = h / 3;
         gen.useLineWidth(h3);
         final float ym1 = y1 + h3 / 2;
         gen.useColor(uppercol);
         drawLine(gen, x1, ym1, x2, ym1);
         gen.useColor(col);
         drawLine(gen, x1, ym1 + h3, x2, ym1 + h3);
         gen.useColor(lowercol);
         drawLine(gen, x1, ym1 + h3 + h3, x2, ym1 + h3 + h3);
       } else {
         final Color leftcol = ColorUtil.lightenColor(col, -colFactor);
         final Color rightcol = ColorUtil.lightenColor(col, colFactor);
         final float w3 = w / 3;
         gen.useLineWidth(w3);
         final float xm1 = x1 + w3 / 2;
         gen.useColor(leftcol);
         drawLine(gen, xm1, y1, xm1, y2);
         gen.useColor(col);
         drawLine(gen, xm1 + w3, y1, xm1 + w3, y2);
         gen.useColor(rightcol);
         drawLine(gen, xm1 + w3 + w3, y1, xm1 + w3 + w3, y2);
       }
       break;
     case Constants.EN_INSET:
     case Constants.EN_OUTSET:
       colFactor = style == Constants.EN_OUTSET ? 0.4f : -0.4f;
       gen.useDash(null);
       if (horz) {
         final Color c = ColorUtil.lightenColor(col, (startOrBefore ? 1 : -1) * colFactor);
         gen.useLineWidth(h);
         final float ym1 = y1 + h / 2;
         gen.useColor(c);
         drawLine(gen, x1, ym1, x2, ym1);
       } else {
         final Color c = ColorUtil.lightenColor(col, (startOrBefore ? 1 : -1) * colFactor);
         gen.useLineWidth(w);
         final float xm1 = x1 + w / 2;
         gen.useColor(c);
         drawLine(gen, xm1, y1, xm1, y2);
       }
       break;
     case Constants.EN_HIDDEN:
       break;
     default:
       gen.useColor(col);
       gen.useDash(null);
       gen.useLineCap(0);
       if (horz) {
         gen.useLineWidth(h);
         final float ym = y1 + h / 2;
         drawLine(gen, x1, ym, x2, ym);
       } else {
         gen.useLineWidth(w);
         final float xm = x1 + w / 2;
         drawLine(gen, xm, y1, xm, y2);
       }
   }
 }