Example #1
0
        /**
         * Returns a <code>Shape</code> whose interior defines the
         * stroked outline of a specified <code>Shape</code>.
         * @param s the <code>Shape</code> boundary be stroked
         * @return the <code>Shape</code> of the stroked outline.
         */
        public Shape createStrokedShape(Shape s)
        {
            FillAdapter  filler  = new FillAdapter();
            PathStroker  stroker = new PathStroker(filler);
            PathConsumer consumer;

            stroker.setPenDiameter(width);
            switch (_penFit)
            {
            case PenFit.Thin:
                stroker.setPenFitting(PenUnits, MinPenUnits);
                break;

            case PenFit.ThinAntiAlias:
                stroker.setPenFitting(PenUnits, MinPenUnitsAA);
                break;
            }

            float[] t4 = null;
            if (PenTransform != null && !PenTransform.isIdentity() && (PenTransform.getDeterminant() > 1e-25))
            {
                t4 = new float[] {
                    (float)PenTransform.getScaleX(), (float)PenTransform.getShearY(),
                    (float)PenTransform.getShearX(), (float)PenTransform.getScaleY()
                };
            }

            float[] t6 = null;
            if (OutputTransform != null && !OutputTransform.isIdentity())
            {
                t6 = new float[] {
                    (float)OutputTransform.getScaleX(), (float)OutputTransform.getShearY(),
                    (float)OutputTransform.getShearX(), (float)OutputTransform.getScaleY(),
                    (float)OutputTransform.getTranslateX(), (float)OutputTransform.getTranslateY()
                };
            }

            stroker.setPenT4(t4);
            stroker.setOutputT6(t6);
            stroker.setCaps(RasterizerCaps[cap]);
            stroker.setCorners(RasterizerCorners[join], miterlimit);
            if (dash != null)
            {
                PathDasher dasher = new PathDasher(stroker);
                dasher.setDash(dash, dash_phase);
                dasher.setDashT4(t4);
                consumer = dasher;
            }
            else
            {
                consumer = stroker;
            }

            PathIterator pi = s.getPathIterator(null);

            try {
                consumer.beginPath();
                bool    pathClosed = false;
                float   mx         = 0.0f;
                float   my         = 0.0f;
                float[] point      = new float[6];

                while (!pi.isDone())
                {
                    int type = pi.currentSegment(point);
                    if (pathClosed == true)
                    {
                        pathClosed = false;
                        if (type != PathIterator__Finals.SEG_MOVETO)
                        {
                            // Force current point back to last moveto point
                            consumer.beginSubpath(mx, my);
                        }
                    }
                    switch ((GraphicsPath.JPI)type)
                    {
                    case GraphicsPath.JPI.SEG_MOVETO:
                        mx = point[0];
                        my = point[1];
                        consumer.beginSubpath(point[0], point[1]);
                        break;

                    case GraphicsPath.JPI.SEG_LINETO:
                        consumer.appendLine(point[0], point[1]);
                        break;

                    case GraphicsPath.JPI.SEG_QUADTO:
                        // Quadratic curves take two points
                        consumer.appendQuadratic(point[0], point[1],
                                                 point[2], point[3]);
                        break;

                    case GraphicsPath.JPI.SEG_CUBICTO:
                        // Cubic curves take three points
                        consumer.appendCubic(point[0], point[1],
                                             point[2], point[3],
                                             point[4], point[5]);
                        break;

                    case GraphicsPath.JPI.SEG_CLOSE:
                        consumer.closedSubpath();
                        pathClosed = true;
                        break;
                    }
                    pi.next();
                }

                consumer.endPath();
            } catch (PathException e) {
                throw new InternalError("Unable to Stroke shape (" +
                                        e.Message + ")");
            }

            return(filler.getShape());
        }
Example #2
0
		/**
		 * Returns a <code>Shape</code> whose interior defines the 
		 * stroked outline of a specified <code>Shape</code>.
		 * @param s the <code>Shape</code> boundary be stroked
		 * @return the <code>Shape</code> of the stroked outline.
		 */
		public Shape createStrokedShape(Shape s) {
			FillAdapter filler = new FillAdapter();
			PathStroker stroker = new PathStroker(filler);
			PathConsumer consumer;

			stroker.setPenDiameter(width);
			switch (_penFit) {
				case PenFit.Thin:
					stroker.setPenFitting(PenUnits, MinPenUnits);
					break;
				case PenFit.ThinAntiAlias:
					stroker.setPenFitting(PenUnits, MinPenUnitsAA);
					break;
			}

			float[] t4 = null;
			if (PenTransform != null && !PenTransform.isIdentity() && (PenTransform.getDeterminant() > 1e-25)) {
				t4 = new float[]{
					(float)PenTransform.getScaleX(), (float)PenTransform.getShearY(), 
					(float)PenTransform.getShearX(), (float)PenTransform.getScaleY()
				};
			}

			float[] t6 = null;
			if (OutputTransform != null && !OutputTransform.isIdentity()) {
				t6 = new float[] {
					(float)OutputTransform.getScaleX(), (float)OutputTransform.getShearY(), 
					(float)OutputTransform.getShearX(), (float)OutputTransform.getScaleY(),
					(float)OutputTransform.getTranslateX(), (float)OutputTransform.getTranslateY()
				};
			}

			stroker.setPenT4(t4);
			stroker.setOutputT6(t6);
			stroker.setCaps(RasterizerCaps[cap]);
			stroker.setCorners(RasterizerCorners[join], miterlimit);
			if (dash != null) {
				PathDasher dasher = new PathDasher(stroker);
				dasher.setDash(dash, dash_phase);
				dasher.setDashT4(t4);
				consumer = dasher;
			} else {
				consumer = stroker;
			}

			PathIterator pi = s.getPathIterator(null);

			try {
				consumer.beginPath();
				bool pathClosed = false;
				float mx = 0.0f;
				float my = 0.0f;
				float[] point  = new float[6];

				while (!pi.isDone()) {
					int type = pi.currentSegment(point);
					if (pathClosed == true) {
						pathClosed = false;
						if (type !=  PathIterator__Finals.SEG_MOVETO) {
							// Force current point back to last moveto point
							consumer.beginSubpath(mx, my);
						}
					}
					switch ((GraphicsPath.JPI)type) {
						case GraphicsPath.JPI.SEG_MOVETO:
							mx = point[0];
							my = point[1];
							consumer.beginSubpath(point[0], point[1]);
							break;
						case GraphicsPath.JPI.SEG_LINETO:
							consumer.appendLine(point[0], point[1]);
							break;
						case GraphicsPath.JPI.SEG_QUADTO:
							// Quadratic curves take two points
							consumer.appendQuadratic(point[0], point[1],
								point[2], point[3]);
							break;
						case GraphicsPath.JPI.SEG_CUBICTO:
							// Cubic curves take three points
							consumer.appendCubic(point[0], point[1],
								point[2], point[3],
								point[4], point[5]);
							break;
						case GraphicsPath.JPI.SEG_CLOSE:
							consumer.closedSubpath();
							pathClosed = true;
							break;
					}
					pi.next();
				}

				consumer.endPath();
			} catch (PathException e) {
				throw new InternalError("Unable to Stroke shape ("+
					e.Message+")");
			}

			return filler.getShape();
		}