001: /**
002: * TextLine.java
003: *
004: Copyright (c) 2007, Innovatics Inc.
005:
006: All rights reserved.
007:
008: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
009:
010: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
011: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
012:
013: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
014: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
015: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
016: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
017: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
018: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
019: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
020: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
021: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
022: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
023: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
024: */package com.pdfjet;
025:
026: import java.lang.*;
027: import java.text.*;
028: import java.util.*;
029:
030: //>>>>pdfjet {
031: public class TextLine {
032:
033: protected double x = 0.0;
034: protected double y = 0.0;
035:
036: protected Font font = null;
037: protected String str = "";
038: protected String uri = null;
039: protected boolean underline = false;
040: protected boolean strike = false;
041: protected int degrees = 0;
042:
043: protected double[] color = { 0.0, 0.0, 0.0 };
044:
045: private double box_x = 0.0;
046: private double box_y = 0.0;
047:
048: public TextLine(Font font) {
049: this .font = font;
050: }
051:
052: public TextLine(Font font, String str) {
053: this .font = font;
054: this .str = str;
055: }
056:
057: public void setPosition(double x, double y) {
058: this .x = x;
059: this .y = y;
060: }
061:
062: public void setText(String str) {
063: this .str = str;
064: }
065:
066: public void setFont(Font font) {
067: this .font = font;
068: }
069:
070: public void setColor(double[] color) {
071: this .color = color;
072: }
073:
074: public double[] getColor() {
075: return color;
076: }
077:
078: public void setURIAction(String uri) {
079: this .uri = uri;
080: }
081:
082: public void setUnderline(boolean underline) {
083: this .underline = underline;
084: }
085:
086: public void setStrikeLine(boolean strike) {
087: this .strike = strike;
088: }
089:
090: public void setTextDirection(int degrees) {
091: this .degrees = degrees;
092: }
093:
094: public void placeIn(Box box) {
095: box_x = box.x;
096: box_y = box.y;
097: }
098:
099: public void drawOn(Page page) throws Exception {
100: page.setTextDirection(degrees);
101: x += box_x;
102: y += box_y;
103: if (uri != null) {
104: page.annots.add(new Annotation(uri, x, page.height
105: - (y - font.ascent), x + font.stringWidth(str),
106: page.height - (y - font.descent)));
107: }
108:
109: if (str != null) {
110: page.setBrushColor(color[0], color[1], color[2]);
111: page.drawString(font, str, x, y);
112: }
113:
114: page.setPenWidth(0.25);
115: if (underline) {
116: page.moveTo(x, y + 0.75);
117: page.lineTo(x + font.stringWidth(str), y + 0.75);
118: page.strokePath();
119: }
120:
121: if (strike) {
122: page.moveTo(x, y - 3.5);
123: page.lineTo(x + font.stringWidth(str), y - 3.5);
124: page.strokePath();
125: }
126: page.setTextDirection(0);
127: }
128:
129: } // End of TextLine.java
130: //>>>>}
|