import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Line2D;
import java.awt.Font;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;

public class GestioneFont extends Applet {
	
	public void paint(Graphics g) {
		Graphics2D g2=(Graphics2D) g;
		Font f=new Font ("Serif",Font.BOLD,120);
		Font defaultFont=g2.getFont();
		g2.setFont(f);
		String message="Applet";
		
		FontRenderContext context = g2.getFontRenderContext();
		TextLayout layout=new TextLayout(message, f, context);
		float advance = layout.getAdvance();
		float ascent = layout.getAscent();
		float descent= layout.getDescent();
		float leading= layout.getLeading();
		
		float xLeft = 0.5F * (getWidth() - advance);
		float yTop = 0.5F * (getHeight() - (ascent+descent+leading));
		float yBase =yTop + ascent;
				
		g2.drawString (message,xLeft,yBase);
		
		//dividi messaggio in ascesa discesa ed interlinea
		Rectangle2D.Float ascentRectangle=new Rectangle2D.Float(xLeft,yTop,advance,ascent);
		Rectangle2D.Float descentRectangle=new Rectangle2D.Float(xLeft,yBase,advance,descent);
		Rectangle2D.Float leadingRectangle=new Rectangle2D.Float(xLeft,yBase+descent,advance,leading);
		g2.draw(ascentRectangle);
		g2.draw(descentRectangle);
		g2.draw(leadingRectangle);
		
		g2.setFont(defaultFont);
		
		//disegna didascalia di ascesa
		message="Ascesa";
		Line2D.Float line = new Line2D.Float(xLeft+advance+10,yTop, xLeft+advance+10,yBase);
		g2.draw(line);
		Line2D.Float dash = new Line2D.Float(xLeft+advance+5,yTop, xLeft+advance+15,yTop);
		g2.draw(dash);
		dash.setLine(xLeft+advance+5,yTop+ascent, xLeft+advance+15,yTop+ascent);
		g2.draw(dash);
		g2.drawString(message,xLeft+advance+20,(yTop+yBase)/2+5);
		
		//disegna didascalia discesa
		line.setLine(xLeft+advance+10,yBase, xLeft+advance+10,yBase+descent);
		g2.draw(line);
		dash.setLine(xLeft+advance+5,yBase, xLeft+advance+15,yBase);
		g2.draw(dash);
		dash.setLine(xLeft+advance+5,yBase+descent, xLeft+advance+15,yBase+descent);
		g2.draw(dash);
		g2.drawString("Discesa",xLeft+advance+20,(yBase+yBase+descent)/2+5);
		
		//disegna didascalia interlinea
		line.setLine(xLeft+advance+10,yBase+descent, xLeft+advance+10,yBase+descent+leading);
		g2.draw(line);
		dash.setLine(xLeft+advance+5,yBase+descent, xLeft+advance+15,yBase+descent);
		g2.draw(dash);
		dash.setLine(xLeft+advance+5,yBase+descent+leading, xLeft+advance+15,yBase+descent+leading);
		g2.draw(dash);
		g2.drawString("Interlinea",xLeft+advance+20,(yBase+yBase+descent+descent+leading)/2+5);
		
		//disegna didascalia giustezza
		line.setLine(xLeft,yBase+descent+leading+10, xLeft+advance,yBase+descent+leading+10);
		g2.draw(line);
		dash.setLine(xLeft,yBase+descent+leading+5, xLeft,yBase+descent+leading+15);
		g2.draw(dash);
		dash.setLine(xLeft+advance,yBase+descent+leading+5, xLeft+advance,yBase+descent+leading+15);
		g2.draw(dash);
		g2.drawString("Giustezza",(xLeft+xLeft+advance)/2-20,yBase+descent+leading+30);
		
		
		
		
		
	}
}
		
		


Questa la bacheca di Informatica Grafica, corso di laurea specialistica in Ing. Edile-architettura
by FdA
ultima modifica: 02/02/2005 11.30