1 | /** | |
2 | * Copyright 2014 by Tizra Inc. | |
3 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
4 | * (the "License"); you may not use this file except in compliance with the License. | |
5 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
6 | * <p> | |
7 | * Software distributed under the License is distributed on an "AS IS" basis, | |
8 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
9 | * for the specific language governing rights and limitations under the License. | |
10 | * <p> | |
11 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
12 | * <p> | |
13 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
14 | * the Initial Developer are Copyright (C) 1999-2008 by Bruno Lowagie. | |
15 | * All Rights Reserved. | |
16 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
17 | * are Copyright (C) 2000-2008 by Paulo Soares. All Rights Reserved. | |
18 | * <p> | |
19 | * Contributor(s): all the names of the contributors are added in the source code | |
20 | * where applicable. | |
21 | * <p> | |
22 | * Alternatively, the contents of this file may be used under the terms of the | |
23 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
24 | * provisions of LGPL are applicable instead of those above. If you wish to | |
25 | * allow use of your version of this file only under the terms of the LGPL | |
26 | * License and not to allow others to use your version of this file under | |
27 | * the MPL, indicate your decision by deleting the provisions above and | |
28 | * replace them with the notice and other provisions required by the LGPL. | |
29 | * If you do not delete the provisions above, a recipient may use your version | |
30 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
31 | * <p> | |
32 | * This library is free software; you can redistribute it and/or modify it | |
33 | * under the terms of the MPL as stated above or under the terms of the GNU | |
34 | * Library General Public License as published by the Free Software Foundation; | |
35 | * either version 2 of the License, or any later version. | |
36 | * <p> | |
37 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
38 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
39 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
40 | * details. | |
41 | */ | |
42 | package com.lowagie.text.pdf.parser; | |
43 | ||
44 | import javax.annotation.Nullable; | |
45 | ||
46 | /** | |
47 | * @author dgd | |
48 | */ | |
49 | public abstract class ParsedTextImpl implements TextAssemblyBuffer { | |
50 | private final String text; | |
51 | private float ascent; | |
52 | private float descent; | |
53 | private Vector startPoint; | |
54 | private Vector endPoint; | |
55 | private float spaceWidth; | |
56 | /** | |
57 | * We track a vector representing our baseline, left->right, so that calculations of line- | |
58 | * change can be accurate, even with 0-length words (representing lone spaces, when | |
59 | * those are rendered by the PDF). | |
60 | */ | |
61 | private Vector baseline; | |
62 | ||
63 | /** | |
64 | * @param text | |
65 | * characters to be rendered for this string | |
66 | * @param startPoint | |
67 | * Initial rendering spot on baseline | |
68 | * @param endPoint | |
69 | * ending render position on baseline | |
70 | * @param baseline | |
71 | * vector representing baseline (needed for 0-length strings) | |
72 | * @param ascent | |
73 | * font ascent above baseline | |
74 | * @param descent | |
75 | * font descent below the baseling | |
76 | * @param spaceWidth | |
77 | * What is the width of the space in this font.... | |
78 | */ | |
79 | ParsedTextImpl(@Nullable String text, | |
80 | Vector startPoint, | |
81 | Vector endPoint, | |
82 | Vector baseline, | |
83 | float ascent, | |
84 | float descent, | |
85 | float spaceWidth) { | |
86 | this.baseline = baseline; | |
87 | this.text = text; | |
88 | this.startPoint = startPoint; | |
89 | this.endPoint = endPoint; | |
90 | this.ascent = ascent; | |
91 | this.descent = descent; | |
92 | this.spaceWidth = spaceWidth; | |
93 | } | |
94 | ||
95 | /** | |
96 | * {@inheritDoc} | |
97 | * @see com.lowagie.text.pdf.parser.ParsedText#getText() | |
98 | */ | |
99 | @Nullable | |
100 | @Override | |
101 | public String getText() { | |
102 | return text; | |
103 | } | |
104 | ||
105 | /** | |
106 | * @return The width, in user space units, of a single space character in | |
107 | * the current font | |
108 | */ | |
109 | public float getSingleSpaceWidth() { | |
110 | return spaceWidth; | |
111 | } | |
112 | ||
113 | public float getAscent() { | |
114 | return ascent; | |
115 | } | |
116 | ||
117 | public float getDescent() { | |
118 | return descent; | |
119 | } | |
120 | ||
121 | public float getWidth() { | |
122 |
1
1. getWidth : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/parser/ParsedTextImpl::getWidth → NO_COVERAGE |
return getEndPoint().subtract(getStartPoint()).length(); |
123 | } | |
124 | ||
125 | /** | |
126 | * @return a vector in User space representing the start point of the text | |
127 | */ | |
128 | public Vector getStartPoint() { | |
129 | return startPoint; | |
130 | } | |
131 | ||
132 | /** | |
133 | * @return a vector in User space representing the end point of the text | |
134 | * (i.e. the starting point of the text plus the width of the text, | |
135 | * transformed by the applicable transformation matrices) | |
136 | */ | |
137 | public Vector getEndPoint() { | |
138 | return endPoint; | |
139 | } | |
140 | ||
141 | /** | |
142 | * Return the vector representing the baseline of this text chunk, even if the length | |
143 | * of the text is zero. | |
144 | * | |
145 | * @see ParsedTextImpl#baseline | |
146 | * @return baseline | |
147 | */ | |
148 | public Vector getBaseline() { | |
149 | return baseline; | |
150 | } | |
151 | ||
152 | /** | |
153 | * @return true if this was extracted from a string containing spaces, in which case, | |
154 | * we assume further splitting is not needed. | |
155 | */ | |
156 | public abstract boolean shouldNotSplit(); | |
157 | ||
158 | /** | |
159 | * @return true if this was a space or other item that should force a space before it. | |
160 | */ | |
161 | public abstract boolean breakBefore(); | |
162 | } | |
Mutations | ||
122 |
1.1 |