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