01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. You may obtain a copy of the License at
09:
10: http://www.apache.org/licenses/LICENSE-2.0
11:
12: Unless required by applicable law or agreed to in writing, software
13: distributed under the License is distributed on an "AS IS" BASIS,
14: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: See the License for the specific language governing permissions and
16: limitations under the License.
17:
18: */
19: package org.apache.batik.gvt.text;
20:
21: import java.awt.geom.GeneralPath;
22: import java.awt.geom.Point2D;
23:
24: import org.apache.batik.ext.awt.geom.PathLength;
25:
26: /**
27: * A text path describes a path along which some text will be rendered.
28: *
29: * @author <a href="mailto:bella.robinson@cmis.csiro.au">Bella Robinson</a>
30: * @version $Id: TextPath.java 475477 2006-11-15 22:44:28Z cam $
31: */
32: public class TextPath {
33:
34: private PathLength pathLength;
35: private float startOffset;
36:
37: /**
38: * Constructs a TextPath based on the specified path.
39: *
40: * @param path The general path along which text is to be laid.
41: */
42: public TextPath(GeneralPath path) {
43: pathLength = new PathLength(path);
44: startOffset = 0;
45: }
46:
47: /**
48: * Sets the offset along the path where the first glyph should be rendered.
49: *
50: * @param startOffset An offset from the start of the path.
51: */
52: public void setStartOffset(float startOffset) {
53: this .startOffset = startOffset;
54: }
55:
56: /**
57: * Returns the start offset of this text path.
58: *
59: * @return The start offset of this text path.
60: */
61: public float getStartOffset() {
62: return startOffset;
63: }
64:
65: /**
66: * Returns the total length of the path.
67: *
68: * @return The lenght of the path.
69: */
70: public float lengthOfPath() {
71: return pathLength.lengthOfPath();
72: }
73:
74: /**
75: * Returns the angle at the specified length
76: * along the path.
77: *
78: * @param length The length along the path.
79: * @return The angle.
80: */
81: public float angleAtLength(float length) {
82: return pathLength.angleAtLength(length);
83: }
84:
85: /**
86: * Returns the point that is at the specified length
87: * along the path.
88: *
89: * @param length The length along the path.
90: * @return The point.
91: */
92: public Point2D pointAtLength(float length) {
93: return pathLength.pointAtLength(length);
94: }
95: }
|