public GeneralPath transform(GeneralPath in) {
    GeneralPath out = new GeneralPath();
    PathIterator it = in.getPathIterator(null);
    float[] seg = new float[6];

    Point2D.Double din = new Point2D.Double();
    Point2D.Double dout = new Point2D.Double();

    while (!it.isDone()) {
      int l = it.currentSegment(seg);
      din.x = seg[0];
      din.y = seg[1];
      projection.transform(din, dout);
      float x = (float) dout.x - minx;
      float y = maxy - (float) dout.y;

      try {
        if (!projection.inside(din.x, din.y)) l = PathIterator.SEG_MOVETO;
      } catch (Exception e) {
        l = PathIterator.SEG_MOVETO;
      }

      if (l == PathIterator.SEG_MOVETO) {
        out.moveTo(x, y);
      } else {
        out.lineTo(x, y);
      }
      it.next();
    }
    return out;
  }
 public static GeneralPath readDatFile(String file) throws IOException {
   BufferedReader buf = new BufferedReader(new FileReader(file));
   GeneralPath path = new GeneralPath();
   String line;
   boolean closed = true;
   int lineno = 0;
   while ((line = buf.readLine()) != null) {
     lineno++;
     line = line.trim();
     if (line.equals("")) continue;
     if (line.startsWith(">")) {
       closed = true;
       continue;
     }
     String[] toks = line.split("\\s");
     try {
       float x = Float.parseFloat(toks[0]);
       float y = Float.parseFloat(toks[1]);
       if (closed) path.moveTo(x, y);
       else path.lineTo(x, y);
     } catch (Exception e) {
       throw new RuntimeException("Error parsing line " + lineno + ": " + line, e);
     }
     closed = false;
   }
   buf.close();
   return path;
 }
Ejemplo n.º 3
0
 /**
  * Returns the outline of this glyph. This will be positioned correctly and any glyph transforms
  * will have been applied.
  *
  * @return the outline of this glyph.
  */
 public Shape getOutline() {
   if (outline == null) {
     AffineTransform tr = AffineTransform.getTranslateInstance(position.getX(), position.getY());
     if (transform != null) {
       tr.concatenate(transform);
     }
     Shape glyphChildrenOutline = null;
     if (glyphChildrenNode != null) {
       glyphChildrenOutline = glyphChildrenNode.getOutline();
     }
     GeneralPath glyphOutline = null;
     if (dShape != null && glyphChildrenOutline != null) {
       glyphOutline = new GeneralPath(dShape);
       glyphOutline.append(glyphChildrenOutline, false);
     } else if (dShape != null && glyphChildrenOutline == null) {
       glyphOutline = new GeneralPath(dShape);
     } else if (dShape == null && glyphChildrenOutline != null) {
       glyphOutline = new GeneralPath(glyphChildrenOutline);
     } else {
       // must be a whitespace glyph, return an empty shape
       glyphOutline = new GeneralPath();
     }
     outline = tr.createTransformedShape(glyphOutline);
   }
   return outline;
 }
Ejemplo n.º 4
0
 public GeneralPath getBezieredPoly(Polygon pts) {
   GeneralPath p = new GeneralPath();
   if (pts.npoints > 0) {
     p.moveTo(pts.xpoints[0], pts.ypoints[0]);
     if (pts.npoints >= 4) {
       int counter = 1;
       for (int i = 1; i + 2 < pts.npoints; i += 3) {
         p.curveTo(
             pts.xpoints[i],
             pts.ypoints[i],
             pts.xpoints[i + 1],
             pts.ypoints[i + 1],
             pts.xpoints[i + 2],
             pts.ypoints[i + 2]);
         counter += 3;
       }
       while (counter < pts.npoints) {
         p.lineTo(pts.xpoints[counter], pts.ypoints[counter]);
         counter++;
       }
     } else {
       for (int i = 1; i < pts.npoints; i++) {
         p.lineTo(pts.xpoints[i], pts.ypoints[i]);
       }
     }
   }
   return p;
 }
Ejemplo n.º 5
0
  /**
   * Constructor for objects of class ShipwithFunnels this one asks you to input numoffunnels which
   * is the number of funnels you want the ship to have
   */
  public ShipwithFunnels(double x, double y, double width, double height, int numoffunnels) {
    // construct the basic ship shell
    super(x, y, width, height);

    // get the GeneralPath that we are going to append stuff to
    GeneralPath gp = this.get();

    // Make a funnel;
    // | 	+--+ +--+	|
    // | 	|  | |  |	|
    // |	+--+ +--+ 	|
    // |5w	 w 	w  w 5w |
    //
    // The width of funnel will be 1/11 of ship's width and the
    // height of the funnel is 1*height;

    double w = width / 13;
    double funnelTop = y - height;
    double funnelHt = height;
    int margin = (13 - (numoffunnels * 2 - 1)) / 2;

    GeneralPath wholeShip = this.get();
    for (int i = 0; i < numoffunnels; i++) {
      Rectangle2D.Double funnel1 =
          new Rectangle2D.Double(x + margin * w + i * 2 * w, funnelTop, w, funnelHt);

      wholeShip.append(funnel1, false);
    }
  }
Ejemplo n.º 6
0
  /**
   * Default Constructor for objects of class ShipwithFunnels this one gives one funnel on the ship
   */
  public ShipwithFunnels(double x, double y, double width, double height) {
    // construct the basic ship shell
    super(x, y, width, height);

    // get the GeneralPath that we are going to append stuff to
    GeneralPath gp = this.get();

    // Make a funnel;
    // | 	+--+ 	|
    // | 	|  |	|
    // |	+--+ 	|
    // |6w	 w 	  6w|
    //
    // The width of funnel will be 1/11 of ship's width and the
    // height of the funnel is 1*height;

    double w = width / 13;
    double funnelTop = y - height;
    double funnelHt = height;

    Rectangle2D.Double funnel1 = new Rectangle2D.Double(x + 6 * w, funnelTop, w, funnelHt);

    // add the funnel to the ship

    GeneralPath wholeShip = this.get();
    wholeShip.append(funnel1, false);
  }
Ejemplo n.º 7
0
  @Override
  public void setPosition(Pointt position) {
    super.setPosition(position);
    generatePaint();
    double startAngle = Maths.randomAngle();
    GeneralPath tempRep = new GeneralPath();

    Pointt next = new Pointt(0, 0);
    for (int i = 0; i < vertices.length; i++) {
      vertices[i] =
          next.getArcPointt(
              radius() * Geometry.DISPLAY_REAL_RATIO,
              startAngle + i * 2 * (Math.PI / NUMBER_OF_VERTICES));
    }

    tempRep.moveTo(vertices[0].getX(), vertices[0].getY());

    for (int i = 0; i < vertices.length; i++) {
      next = vertices[(i + 1) % vertices.length];
      tempRep.quadTo(
          vertices[i].midPoint(next).getX()
              + Maths.randomNegative(radius() * Geometry.DISPLAY_REAL_RATIO / 2),
          vertices[i].midPoint(next).getY()
              + Maths.randomNegative(radius() * Geometry.DISPLAY_REAL_RATIO / 2),
          next.getX(),
          next.getY());
    }

    tempRep.closePath();
    rep = new Area(tempRep);

    for (int i = 0; i < vertices.length; i++) {
      vertices[i].translate(position);
    }
  }
  public GeneralPath createLines() {
    GeneralPath lines = new GeneralPath();
    int pad = 0;
    int nLos = 24;
    int nLas = 100;
    for (int lo = 0; lo <= nLos; lo++) {
      boolean first = true;
      for (int la = pad; la <= nLas - pad; la++) {
        float x = (lo - nLos / 2) * (360.0f / nLos);
        float y = (la - nLas / 2) * (180.0f / nLas);
        if (first) lines.moveTo(x, y);
        else lines.lineTo(x, y);
        first = false;
      }
    }

    nLos = 100;
    nLas = 12;
    for (int la = 0; la <= nLas; la++) {
      boolean first = true;
      for (int lo = pad; lo <= nLos - pad; lo++) {
        float x = (lo - nLos / 2) * (360.0f / nLos);
        float y = (la - nLas / 2) * (180.0f / nLas);
        if (first) lines.moveTo(x, y);
        else lines.lineTo(x, y);
        first = false;
      }
    }
    return lines;
  }
Ejemplo n.º 9
0
  /**
   * Build a shape for the entire subtree by joining together the shapes for each of its edges.
   * Vertices included since needed for FullTextPanel.
   */
  public Shape constructInternalShape(DiagramBase diagram, boolean includeVertices) {
    GeneralPath shape = new GeneralPath();
    Enumeration edges = m_edgeList.elements();
    while (edges.hasMoreElements()) {
      TreeEdge edge = (TreeEdge) edges.nextElement();
      Shape edgeShape = edge.getSchemeShape(diagram);
      PathIterator path = edgeShape.getPathIterator(null);
      shape.append(path, false);

      if (includeVertices) {
        Shape vertexShape;
        if (!edge.getSourceVertex().isVirtual()) {
          vertexShape = edge.getSourceVertex().getShape(diagram);
          path = vertexShape.getPathIterator(null);
          shape.append(path, false);
        }
        if (!edge.getDestVertex().isVirtual()) {
          vertexShape = edge.getDestVertex().getShape(diagram);
          path = vertexShape.getPathIterator(null);
          shape.append(path, false);
        }
      }
    }
    BasicStroke stroke =
        new BasicStroke(
            diagram.getSubtreeLineWidth() - DiagramBase.EDGE_OUTLINE_WIDTH + 1,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_MITER);
    internalShapeTable.put(diagram, stroke.createStrokedShape(shape));
    return (Shape) internalShapeTable.get(diagram);
  }
Ejemplo n.º 10
0
 static {
   GeneralPath p = new GeneralPath(new Rectangle2D.Float(-7, -4, 14, 8));
   p.moveTo(-6.5f, -3.5f);
   p.lineTo(0, 1);
   p.lineTo(6.5f, -3.5f);
   SHAPE = p;
 }
Ejemplo n.º 11
0
  /** Render a compound glyf */
  protected GeneralPath renderCompoundGlyph(GlyfTable glyf, GlyfCompound g) {
    GeneralPath gp = new GeneralPath();

    for (int i = 0; i < g.getNumComponents(); i++) {
      // find and render the component glyf
      Glyf gl = glyf.getGlyph(g.getGlyphIndex(i));
      GeneralPath path = null;
      if (gl instanceof GlyfSimple) {
        path = renderSimpleGlyph((GlyfSimple) gl);
      } else if (gl instanceof GlyfCompound) {
        path = renderCompoundGlyph(glyf, (GlyfCompound) gl);
      } else {
        throw new RuntimeException("Unsupported glyph type " + gl.getClass().getCanonicalName());
      }

      // multiply the translations by units per em
      double[] matrix = g.getTransform(i);

      // transform the path
      path.transform(new AffineTransform(matrix));

      // add it to the global path
      gp.append(path, false);
    }

    return gp;
  }
Ejemplo n.º 12
0
  public java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path) {
    double cot = cos(theta);
    double sit = sin(theta);
    double cost, sint;

    if (direct) {
      // Counter-clockwise circle
      for (double t = .1; t < PI * 2; t += .1) {
        cost = cos(t);
        sint = sin(t);
        path.lineTo(
            (float) (xc + r * cost * cot - r * sint * sit),
            (float) (yc + r * cost * sit + r * sint * cot));
      }
    } else {
      // Clockwise circle
      for (double t = .1; t < PI * 2; t += .1) {
        cost = cos(t);
        sint = sin(t);
        path.lineTo(
            (float) (xc + r * cost * cot + r * sint * sit),
            (float) (yc + r * cost * sit - r * sint * cot));
      }
    }

    // line to first point
    path.lineTo((float) (xc + r * cot), (float) (yc + r * sit));

    return path;
  }
Ejemplo n.º 13
0
  protected void curveVertexSegment(
      float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
    curveCoordX[0] = x1;
    curveCoordY[0] = y1;

    curveCoordX[1] = x2;
    curveCoordY[1] = y2;

    curveCoordX[2] = x3;
    curveCoordY[2] = y3;

    curveCoordX[3] = x4;
    curveCoordY[3] = y4;

    curveToBezierMatrix.mult(curveCoordX, curveDrawX);
    curveToBezierMatrix.mult(curveCoordY, curveDrawY);

    // since the paths are continuous,
    // only the first point needs the actual moveto
    if (gpath == null) {
      gpath = new GeneralPath();
      gpath.moveTo(curveDrawX[0], curveDrawY[0]);
    }

    gpath.curveTo(
        curveDrawX[1], curveDrawY[1],
        curveDrawX[2], curveDrawY[2],
        curveDrawX[3], curveDrawY[3]);
  }
  /**
   * Returns the outline of in-ribbon gallery.
   *
   * @param startX Start X of the in-ribbon gallery.
   * @param endX End X of the in-ribbon gallery.
   * @param topY Top Y of the in-ribbon gallery.
   * @param bottomY Bottom Y of the in-ribbon gallery.
   * @param radius Corner radius.
   * @return The outline of in-ribbon gallery.
   */
  public static GeneralPath getRibbonGalleryOutline(
      int startX, int endX, int topY, int bottomY, float radius) {

    int height = bottomY - topY;
    GeneralPath result = new GeneralPath();
    float radius3 = (float) (radius / (1.5 * Math.pow(height, 0.5)));

    // start in the top left corner at the end of the curve
    result.moveTo(startX + radius, topY);

    // move to the top right corner and curve down
    result.lineTo(endX - radius - 1, topY);
    result.quadTo(endX - radius3 - 1, topY + radius3, endX - 1, topY + radius);

    // move to the bottom right corner and curve left
    result.lineTo(endX - 1, bottomY - radius - 1);
    result.quadTo(endX - radius3 - 1, bottomY - 1 - radius3, endX - radius - 1, bottomY - 1);

    // move to the bottom left corner and curve up
    result.lineTo(startX + radius, bottomY - 1);
    result.quadTo(startX + radius3, bottomY - 1 - radius3, startX, bottomY - radius - 1);

    // move to the top left corner and curve right
    result.lineTo(startX, topY + radius);
    result.quadTo(startX + radius3, topY + radius3, startX + radius, topY);

    return result;
  }
Ejemplo n.º 15
0
 public void drawTo(Graphics g, Line line) {
   if (!calc.tileOnMap(t1) || !calc.tileOnMap(t2)) return;
   if (calc.tileOnMap(line.getTile1()) && calc.tileOnMap(line.getTile2())) {
     Point p1 = calc.tileToMinimap(t1);
     Point p2 = calc.tileToMinimap(t2);
     Point p3 = calc.tileToMinimap(line.getTile2());
     Point p4 = calc.tileToMinimap(line.getTile1());
     GeneralPath path = new GeneralPath();
     path.moveTo(p1.x, p1.y);
     path.lineTo(p2.x, p2.y);
     path.lineTo(p3.x, p3.y);
     path.lineTo(p4.x, p4.y);
     path.closePath();
     g.setColor(POLY_FILL);
     ((Graphics2D) g).fill(path);
     ((Graphics2D) g).draw(path);
   }
   Point last = null, p;
   g.setColor(Color.ORANGE);
   for (RSTile t : pathList) {
     if (calc.tileOnMap(t)) {
       p = calc.tileToMinimap(t);
       g.fillOval(p.x - 2, p.y - 2, 5, 5);
       if (last != null) g.drawLine(p.x, p.y, last.x, last.y);
       last = p;
     } else last = null;
   }
 }
Ejemplo n.º 16
0
  public void drawPage(Graphics2D g2) {
    FontRenderContext context = g2.getFontRenderContext();
    Font f = new Font("Serif", Font.PLAIN, 72);
    GeneralPath clipShape = new GeneralPath();

    TextLayout layout = new TextLayout("2426打印指南", f, context);
    AffineTransform transform = AffineTransform.getTranslateInstance(0, 72);
    Shape outline = layout.getOutline(transform);
    clipShape.append(outline, false);

    layout = new TextLayout("thank you", f, context);
    transform = AffineTransform.getTranslateInstance(0, 144);
    outline = layout.getOutline(transform);
    clipShape.append(outline, false);

    g2.draw(clipShape);
    g2.clip(clipShape);

    final int NLINES = 50;
    Point2D p = new Point2D.Double(0, 0);
    for (int i = 0; i < NLINES; i++) {
      double x = (2 * getWidth() * i) / NLINES;
      double y = (2 * getHeight() * (NLINES - 1 - i)) / NLINES;
      Point2D q = new Point2D.Double(x, y);
      g2.draw(new Line2D.Double(p, q));
    }
  }
Ejemplo n.º 17
0
  @Override
  public void draw(Graphics2D g2d) {
    final Dimension2D dimTotal = getDimension(StringBounderUtils.asStringBounder(g2d));

    // Shape ellipse = new Ellipse2D.Double(0, 0, dimTotal.getWidth(),
    // dimTotal.getHeight());
    final GeneralPath ellipse = new GeneralPath();
    final double h = dimTotal.getHeight();
    final double w = dimTotal.getWidth();
    ellipse.append(new QuadCurve2D.Double(0, h / 2, 0, 0, w / 2, 0), true);
    ellipse.append(new QuadCurve2D.Double(w / 2, 0, w, 0, w, h / 2), true);
    ellipse.append(new QuadCurve2D.Double(w, h / 2, w, h, w / 2, h), true);
    ellipse.append(new QuadCurve2D.Double(w / 2, h, 0, h, 0, h / 2), true);
    g2d.setColor(getYellow());
    g2d.fill(ellipse);

    g2d.setColor(getRed());
    g2d.draw(ellipse);

    final Dimension2D nameDim = name.calculateDimension(StringBounderUtils.asStringBounder(g2d));
    final double posx = (w - nameDim.getWidth()) / 2;
    final double posy = (h - nameDim.getHeight()) / 2;
    final Shape rect = new Rectangle2D.Double(posx, posy, nameDim.getWidth(), nameDim.getHeight());
    // g2d.draw(rect);

    g2d.setColor(Color.BLACK);
    name.drawTOBEREMOVED(g2d, posx, posy);
  }
Ejemplo n.º 18
0
  /**
   * Constructor
   *
   * @param x x coord of lower left corner of house
   * @param y y coord of lower left corner of house
   * @param width width of the house
   * @param height of house (including first story and second story)
   */
  public House(double x, double y, double width, double height) {

    // Rather than having to scale at the end, we can just
    // draw things the right way to begin with, using the
    // x, y, width and height.   If you haven't already
    // hard coded a particular drawing, this may be an easier
    // way.

    double firstStoryHeight = .75 * height;
    double roofHeight = height - firstStoryHeight;

    double firstStoryUpperLeftY = y + roofHeight;

    // Make the first story

    Rectangle2D.Double firstStory =
        new Rectangle2D.Double(x, firstStoryUpperLeftY, width, firstStoryHeight);

    // make the roof.   Remember that y goes DOWN the page,
    // so we ADD to y to get a "lower" value on the screen

    Line2D.Double leftRoof = new Line2D.Double(x, y + roofHeight, x + width / 2.0, y);

    Line2D.Double rightRoof = new Line2D.Double(x + width / 2.0, y, x + width, y + roofHeight);

    // put the whole house together

    GeneralPath wholeHouse = this.get();
    wholeHouse.append(firstStory, false);
    wholeHouse.append(leftRoof, false);
    wholeHouse.append(rightRoof, false);
  }
Ejemplo n.º 19
0
  /** Constructor for objects of class CoffeeCup */
  public HouseWithWindows(double x, double y, double width, double height) {
    // construct the basic house shell
    super(x, y, width, height);

    // get the GeneralPath that we are going to append stuff to
    GeneralPath gp = this.get();

    // Make three windows, spaced like this, where w=width/10.0;
    // | +--+ +--+ +--+ |
    // | |  | |  | |  | |
    // | +--+ +--+ +--+ |
    // |w 2w w 2w w w2 w|
    //
    // The top of window will be at y + 0.5*height and the
    // height of the window is 0.25height;

    double w = 0.10 * width;
    double winTop = y + 0.5 * height;
    double winHt = 0.25 * height;

    Rectangle2D.Double win1 = new Rectangle2D.Double(x + w, winTop, 2.0 * w, winHt);
    Rectangle2D.Double win2 = new Rectangle2D.Double(x + 4.0 * w, winTop, 2.0 * w, winHt);
    Rectangle2D.Double win3 = new Rectangle2D.Double(x + 7.0 * w, winTop, 2.0 * w, winHt);

    // add the windows to the house
    // Look up the meaning of the second parameter of append
    // (Hint--is a method of "GeneralPath")

    GeneralPath wholeHouse = this.get();
    wholeHouse.append(win1, false);
    wholeHouse.append(win2, false);
    wholeHouse.append(win3, false);
  }
Ejemplo n.º 20
0
  // TODO: moveInwardsBy() not implemented
  public void moveInwardsBy(float offset) {
    int type = this.getType();
    if (type == TYPE_SLOPED)
      // return;
      throw new RuntimeException("Cannot move a sloped egde inwards: " + this);

    float xOffset = 0;
    float yOffset = 0;

    ShapePoint middle = getMiddle();
    GeneralPath path = owner.makeIntoPath();
    if (type == TYPE_HORIZONTAL) {
      xOffset = 0;
      ShapePoint up = new ShapePoint(middle.x, middle.y - 0.05f);
      ShapePoint down = new ShapePoint(middle.x, middle.y + 0.05f);
      if (path.contains(up)) yOffset = -offset;
      else if (path.contains(down)) yOffset = offset;
    } else if (type == TYPE_VERTICAL) {
      yOffset = 0;
      ShapePoint left = new ShapePoint(middle.x - 0.05f, middle.y);
      ShapePoint right = new ShapePoint(middle.x + 0.05f, middle.y);
      if (path.contains(left)) xOffset = -offset;
      else if (path.contains(right)) xOffset = offset;
    }
    if (DEBUG) System.out.println("Moved edge " + this + " by " + xOffset + ", " + yOffset);
    translate(xOffset, yOffset);
  }
Ejemplo n.º 21
0
 /**
  * Tests two polygons for equality. If both are <code>null</code> this method returns <code>true
  * </code>.
  *
  * @param p1 path 1 (<code>null</code> permitted).
  * @param p2 path 2 (<code>null</code> permitted).
  * @return A boolean.
  */
 public static boolean equal(final GeneralPath p1, final GeneralPath p2) {
   if (p1 == null) {
     return (p2 == null);
   }
   if (p2 == null) {
     return false;
   }
   if (p1.getWindingRule() != p2.getWindingRule()) {
     return false;
   }
   PathIterator iterator1 = p1.getPathIterator(null);
   PathIterator iterator2 = p2.getPathIterator(null);
   double[] d1 = new double[6];
   double[] d2 = new double[6];
   boolean done = iterator1.isDone() && iterator2.isDone();
   while (!done) {
     if (iterator1.isDone() != iterator2.isDone()) {
       return false;
     }
     int seg1 = iterator1.currentSegment(d1);
     int seg2 = iterator2.currentSegment(d2);
     if (seg1 != seg2) {
       return false;
     }
     if (!Arrays.equals(d1, d2)) {
       return false;
     }
     iterator1.next();
     iterator2.next();
     done = iterator1.isDone() && iterator2.isDone();
   }
   return true;
 }
Ejemplo n.º 22
0
  /** Get the outline of a character given the glyph id */
  protected synchronized GeneralPath getOutline(int glyphId, float width) {
    // find the glyph itself
    GlyfTable glyf = (GlyfTable) this.font.getTable("glyf");
    Glyf g = glyf.getGlyph(glyphId);

    GeneralPath gp = null;
    if (g instanceof GlyfSimple) {
      gp = renderSimpleGlyph((GlyfSimple) g);
    } else if (g instanceof GlyfCompound) {
      gp = renderCompoundGlyph(glyf, (GlyfCompound) g);
    } else {
      gp = new GeneralPath();
    }

    // calculate the advance
    HmtxTable hmtx = (HmtxTable) this.font.getTable("hmtx");
    float advance = hmtx.getAdvance(glyphId) / this.unitsPerEm;

    // scale the glyph to match the desired advance
    float widthfactor = width / advance;

    // the base transform scales the glyph to 1x1
    AffineTransform at = AffineTransform.getScaleInstance(1 / this.unitsPerEm, 1 / this.unitsPerEm);
    at.concatenate(AffineTransform.getScaleInstance(widthfactor, 1));

    gp.transform(at);

    return gp;
  }
Ejemplo n.º 23
0
  /**
   * Get a glyph outline by character code
   *
   * <p>Note this method must always return an outline
   *
   * @param src the character code of the desired glyph
   * @return the glyph outline
   */
  @Override
  protected GeneralPath getOutline(char src, float width) {
    // some true type fonts put characters in the undefined
    // region of Unicode instead of as normal characters.
    if (!this.f.canDisplay(src) && this.f.canDisplay((char) (src + 0xf000))) {
      src += 0xf000;
    }

    // filter out control characters
    for (int i = 0; i < controlChars.length; i++) {
      if (controlChars[i] == src) {
        src = (char) (0xf000 | src);
        break;
      }
    }

    char[] glyph = new char[1];
    glyph[0] = src;

    GlyphVector gv = this.f.createGlyphVector(this.basecontext, glyph);
    GeneralPath gp = new GeneralPath(gv.getGlyphOutline(0));

    // this should be gv.getGlyphMetrics(0).getAdvance(), but that is
    // broken on the Mac, so we need to read the advance from the
    // hmtx table in the font
    CMap map = this.cmapTable.getCMap(mapIDs[0], mapIDs[1]);
    int glyphID = map.map(src);
    float advance = (float) this.hmtxTable.getAdvance(glyphID) / (float) this.unitsPerEm;

    float widthfactor = width / advance;
    gp.transform(AffineTransform.getScaleInstance(widthfactor, -1));

    return gp;
  }
Ejemplo n.º 24
0
  /**
   * Draws the needle.
   *
   * @param g2 the graphics device.
   * @param plotArea the plot area.
   * @param rotate the rotation point.
   * @param angle the angle.
   */
  @Override
  protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {

    Area shape;
    GeneralPath pointer = new GeneralPath();

    int minY = (int) (plotArea.getMinY());
    // int maxX = (int) (plotArea.getMaxX());
    int maxY = (int) (plotArea.getMaxY());
    int midX = (int) (plotArea.getMinX() + (plotArea.getWidth() / 2));
    // int midY = (int) (plotArea.getMinY() + (plotArea.getHeight() / 2));
    int lenX = (int) (plotArea.getWidth() / 10);
    if (lenX < 2) {
      lenX = 2;
    }

    pointer.moveTo(midX - lenX, maxY - lenX);
    pointer.lineTo(midX + lenX, maxY - lenX);
    pointer.lineTo(midX, minY + lenX);
    pointer.closePath();

    lenX = 4 * lenX;
    Ellipse2D circle = new Ellipse2D.Double(midX - lenX / 2, plotArea.getMaxY() - lenX, lenX, lenX);

    shape = new Area(circle);
    shape.add(new Area(pointer));
    if ((rotate != null) && (angle != 0)) {
      /// we have rotation
      getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
      shape.transform(getTransform());
    }

    defaultDisplay(g2, shape);
  }
Ejemplo n.º 25
0
  /**
   * Constructor
   *
   * @param x x coord of lower left corner of egg carton
   * @param y y coord of lower left corner of egg carton
   * @param width width of the egg carton
   * @param height of egg carton
   */
  public EggCarton(double x, double y, double width, double height) {

    Rectangle2D.Double carton = new Rectangle2D.Double(x, y, width, 0.45 * width);

    GeneralPath wholeCarton = this.get();
    wholeCarton.append(carton, false);
  }
Ejemplo n.º 26
0
 /**
  * Draws a curve segment relative to the current point of the GeneralPath.
  *
  * <p>Adds a curved segment, defined by three new points, to the path by drawing a Bezier curve
  * that intersects both the current coordinates and the coordinates (x3, y3), using the specified
  * points (x1, y1) and (x2, y2) as Bezier control points.
  */
 public static void curveTo(
     GeneralPath gp, float x1, float y1, float x2, float y2, float x3, float y3) {
   Point2D currentPoint = gp.getCurrentPoint();
   gp.curveTo(
       x1 + (float) currentPoint.getX(), y1 + (float) currentPoint.getY(),
       x2 + (float) currentPoint.getX(), y2 + (float) currentPoint.getY(),
       x3 + (float) currentPoint.getX(), y3 + (float) currentPoint.getY());
 }
Ejemplo n.º 27
0
 /**
  * Creates a triangle shape that points downwards.
  *
  * @param s the size factor (equal to half the height of the triangle).
  * @return A triangle shape.
  */
 public static Shape createDownTriangle(final float s) {
   final GeneralPath p0 = new GeneralPath();
   p0.moveTo(0.0f, s);
   p0.lineTo(s, -s);
   p0.lineTo(-s, -s);
   p0.closePath();
   return p0;
 }
Ejemplo n.º 28
0
 /** Implements {@link PointsHandler#point(float,float)}. */
 public void point(float x, float y) throws ParseException {
   if (newPath) {
     newPath = false;
     path.moveTo(x, y);
   } else {
     path.lineTo(x, y);
   }
 }
 void draw(GeneralPath path, Graphics2D g2d) {
   g2d.translate(47, 30);
   path.moveTo(33, 0);
   path.lineTo(0, 33);
   path.lineTo(0, 34);
   path.lineTo(33, 67);
   path.closePath();
 }
Ejemplo n.º 30
0
 public static Shape createSliderShape() {
   GeneralPath path = new GeneralPath();
   path.moveTo(0.0F, -0.5F * SLIDER_HEIGHT);
   path.lineTo(+0.5F * SLIDER_WIDTH, 0.5F * SLIDER_HEIGHT);
   path.lineTo(-0.5F * SLIDER_WIDTH, 0.5F * SLIDER_HEIGHT);
   path.closePath();
   return path;
 }