2012-09-19 10 views
5

Tengo el siguiente código que está adaptado de un ejemplo en línea para rotar texto. El código funciona bien, ya que gira el texto en el ángulo correcto, pero quisiera saber si hay alguna manera de mejorar la precisión y la nitidez del texto girado. En mi pantalla, parece que el texto girado es 'escalonado' en lugar de liso.Mejorando la visualización del texto girado

PFont f; 
String message = "abcdefghijklmnopqrstuvwxyz"; 
float theta, x; 

void setup() { 
    size(800, 200); 
    f = createFont("Arial",20,true); 
} 

void draw() { 
// background(255); 
    fill(0); 
    textFont(f); // Set the font 
    translate(x,height/2); // Translate to the center 
    rotate(theta);    // Rotate by theta 
    textAlign(LEFT);    
    text(message,0,0);    
    theta += 0.1;    // Increase rotation 
    x += textWidth(message); 
    if (x>800){noLoop(); } 
} 

He modificado por ejemplo para ayudar a mostrar la diferencia. En el nuevo código, he cambiado el texto a una cadena de guiones bajos y también he dibujado una línea de referencia en rojo. Si funciona igual en su máquina, debería ver un escalonamiento en la línea negra creada por los guiones bajos.

String message = "________"; 
float theta, x; 
PFont f; 

void setup() { 
    size(800, 200); 
    f = loadFont("ArialMT-20.vlw"); 
    smooth(); 
} 

void draw() { 
    fill(0); 
    textFont(f); // Set the font 

    translate(x,height/2); // Translate to the center 
    rotate(theta);    // Rotate by theta 

    text(message,0,0); 

    stroke(255,0,0); 
    strokeWeight(2); 
    line(0,0,textWidth(message),0); 

    theta += 0.1;    // Increase rotation 
    x += textWidth(message); 
    if (x>800){noLoop(); } 
} 

Para mí da la siguiente salida, pero sé que esto será diferente si se ejecuta en un Mac:

enter image description here

+1

Para una mejor ayuda antes, publique un [SSCCE] (http://sscce.org/). –

+1

¿Quizás estás buscando anti-alisasing? http://www.universalwebservices.net/web-programming-resources/java/anti-aliasing-creating-anti-alias-text-in-java – dbalakirev

+0

Debería haber mencionado que este es el código de Processing.org por lo que es posible copiarlo y pegar en el IDE y ejecutar. Tienes razón, estoy buscando que el texto sea antialias y, como yo lo entiendo, debería serlo. Cuando creo la Fuente, la opción 'verdadero' selecciona anti-aliasing. – user1682655

Respuesta

0

Una forma de hacerlo es a trazar el texto (no girado) en un BufferedImage, y luego girar la imagen. Algo como esto:

BufferedImage buff = getGraphicsConfiguration().createCompatibleImage(textWidth, textHeight); //create an image with the dimensions of the text 
Graphics2D g2d = buff.createGraphics(); 
g2d.drawString(yourText); //draw the text without transformations 
g2d.dispose(); 

//apply the rotation transform to g, the Graphics from your component 
g.drawImage(buff, textPosX, textPosY, null); //there you go 
Cuestiones relacionadas