1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.graphviz.internal.xdot;
14 import java.awt.Graphics2D;
15 import java.awt.RenderingHints;
16 import java.awt.geom.AffineTransform;
17 import java.awt.geom.Rectangle2D;
19 public class Text implements DrawCommand {
27 public Text(double x, double y, int j, double w, String text) {
36 public void draw(Graphics2D g) {
47 //g.draw(new Line2D.Double(lx, y, lx+w, y));
48 g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
49 RenderingHints.VALUE_FRACTIONALMETRICS_ON);
50 Rectangle2D rect = g.getFont().getStringBounds(text, g.getFontRenderContext());
51 AffineTransform oldTransform = g.getTransform();
53 double scale = w / rect.getWidth();
54 g.scale(scale, scale);
55 g.drawString(text, 0.0f, 0.0f);
56 g.setTransform(oldTransform);