Skip to content

Commit 2e772f9

Browse files
committed
PDFBOX-5660: optimize, as suggested by Valery Bokov, closes #375
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930525 13f79535-47bb-0310-9956-ffa450edef68
1 parent e28209b commit 2e772f9

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ public void generateNormalAppearance()
103103
}
104104
cs.setLineWidth(ab.width);
105105

106+
String startPointEndingStyle = annotation.getStartPointEndingStyle();
107+
String endPointEndingStyle = annotation.getEndPointEndingStyle();
106108
for (int i = 0; i < pathsArray.length / 2; ++i)
107109
{
108110
float x = pathsArray[i * 2];
109111
float y = pathsArray[i * 2 + 1];
110112
if (i == 0)
111113
{
112-
if (SHORT_STYLES.contains(annotation.getStartPointEndingStyle()))
114+
if (SHORT_STYLES.contains(startPointEndingStyle))
113115
{
114116
// modify coordinate to shorten the segment
115117
// https://stackoverflow.com/questions/7740507/extend-a-line-segment-a-specific-distance
@@ -126,8 +128,7 @@ public void generateNormalAppearance()
126128
}
127129
else
128130
{
129-
if (i == pathsArray.length / 2 - 1 &&
130-
SHORT_STYLES.contains(annotation.getEndPointEndingStyle()))
131+
if (i == pathsArray.length / 2 - 1 && SHORT_STYLES.contains(endPointEndingStyle))
131132
{
132133
// modify coordinate to shorten the segment
133134
// https://stackoverflow.com/questions/7740507/extend-a-line-segment-a-specific-distance
@@ -150,15 +151,15 @@ public void generateNormalAppearance()
150151
// which would be more work and produce code difficult to understand
151152

152153
// paint the styles here and after polyline draw, to avoid line crossing a filled shape
153-
if (!LE_NONE.equals(annotation.getStartPointEndingStyle()))
154+
if (!LE_NONE.equals(startPointEndingStyle))
154155
{
155156
// check only needed to avoid q cm Q if LE_NONE
156157
float x2 = pathsArray[2];
157158
float y2 = pathsArray[3];
158159
float x1 = pathsArray[0];
159160
float y1 = pathsArray[1];
160161
cs.saveGraphicsState();
161-
if (ANGLED_STYLES.contains(annotation.getStartPointEndingStyle()))
162+
if (ANGLED_STYLES.contains(startPointEndingStyle))
162163
{
163164
double angle = Math.atan2(y2 - y1, x2 - x1);
164165
cs.transform(Matrix.getRotateInstance(angle, x1, y1));
@@ -167,19 +168,19 @@ public void generateNormalAppearance()
167168
{
168169
cs.transform(Matrix.getTranslateInstance(x1, y1));
169170
}
170-
drawStyle(annotation.getStartPointEndingStyle(), cs, 0, 0, ab.width, hasStroke, hasBackground, false);
171+
drawStyle(startPointEndingStyle, cs, 0, 0, ab.width, hasStroke, hasBackground, false);
171172
cs.restoreGraphicsState();
172173
}
173174

174-
if (!LE_NONE.equals(annotation.getEndPointEndingStyle()))
175+
if (!LE_NONE.equals(endPointEndingStyle))
175176
{
176177
// check only needed to avoid q cm Q if LE_NONE
177178
float x1 = pathsArray[pathsArray.length - 4];
178179
float y1 = pathsArray[pathsArray.length - 3];
179180
float x2 = pathsArray[pathsArray.length - 2];
180181
float y2 = pathsArray[pathsArray.length - 1];
181182
// save / restore not needed because it's the last one
182-
if (ANGLED_STYLES.contains(annotation.getEndPointEndingStyle()))
183+
if (ANGLED_STYLES.contains(endPointEndingStyle))
183184
{
184185
double angle = Math.atan2(y2 - y1, x2 - x1);
185186
cs.transform(Matrix.getRotateInstance(angle, x2, y2));
@@ -188,7 +189,7 @@ public void generateNormalAppearance()
188189
{
189190
cs.transform(Matrix.getTranslateInstance(x2, y2));
190191
}
191-
drawStyle(annotation.getEndPointEndingStyle(), cs, 0, 0, ab.width, hasStroke, hasBackground, true);
192+
drawStyle(endPointEndingStyle, cs, 0, 0, ab.width, hasStroke, hasBackground, true);
192193
}
193194
}
194195
catch (IOException ex)

0 commit comments

Comments
 (0)