package org.xith3d.shapegeom;

import javax.swing.*;

import java.awt.*;

import java.awt.geom.Line2D;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.util.ArrayList;


public class TestString extends JPanel {

  public TestString() {
    JFrame frame = new JFrame("Test");
    this.setPreferredSize(new Dimension(1000,600));

    frame.getContentPane().add(this);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

  }

  public void paintComponent(Graphics g){
    Font f = new Font("serif", Font.PLAIN, 500);
    FontRenderContext rc = new FontRenderContext(null, false, false);
    GlyphVector glv = f.createGlyphVector(rc,"Test");
    Shape s = glv.getOutline(10,550);

    ShapeTriangulator st = new ShapeTriangulator(s, 50.0f);

    ArrayList points = st.getPoints();
    for (int i = 0; i < points.size(); i+=3) {
      double[] pointa = (double[]) points.get(i);
      double[] pointb = (double[]) points.get(i+1);
      double[] pointc = (double[]) points.get(i+2);
      ((Graphics2D)g).draw(new Line2D.Double(pointa[0], pointa[1], pointb[0], pointb[1]));
      ((Graphics2D)g).draw(new Line2D.Double(pointb[0], pointb[1], pointc[0], pointc[1]));
      ((Graphics2D)g).draw(new Line2D.Double(pointc[0], pointc[1], pointa[0], pointa[1]));

    }



  }

  public static void main(String[] args) {
    new TestString();

  }

}
