Skip to content

Commit 76bbace

Browse files
committed
PDFBOX-5660: optimize, as suggested by Valery Bokov, closes #352
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930271 13f79535-47bb-0310-9956-ffa450edef68
1 parent 57b9978 commit 76bbace

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ public void generateNormalAppearance()
157157
cs.moveTo(lineLength, llo);
158158
cs.lineTo(lineLength, llo + ll + lle);
159159

160+
String startPointEndingStyle = annotation.getStartPointEndingStyle();
161+
String endPointEndingStyle = annotation.getEndPointEndingStyle();
160162
if (annotation.hasCaption() && !contents.isEmpty())
161163
{
162164
// Note that Adobe places the text as a caption even if /CP is not set
@@ -187,7 +189,7 @@ public void generateNormalAppearance()
187189

188190
// draw the line horizontally, using the rotation CTM to get to correct final position
189191
// that's the easiest way to calculate the positions for the line before and after inline caption
190-
if (SHORT_STYLES.contains(annotation.getStartPointEndingStyle()))
192+
if (SHORT_STYLES.contains(startPointEndingStyle))
191193
{
192194
cs.moveTo(lineEndingSize, y);
193195
}
@@ -209,7 +211,7 @@ public void generateNormalAppearance()
209211
cs.lineTo(xOffset - lineEndingSize, y);
210212
cs.moveTo(lineLength - xOffset + lineEndingSize, y);
211213
}
212-
if (SHORT_STYLES.contains(annotation.getEndPointEndingStyle()))
214+
if (SHORT_STYLES.contains(endPointEndingStyle))
213215
{
214216
cs.lineTo(lineLength - lineEndingSize, y);
215217
}
@@ -244,15 +246,15 @@ public void generateNormalAppearance()
244246
}
245247
else
246248
{
247-
if (SHORT_STYLES.contains(annotation.getStartPointEndingStyle()))
249+
if (SHORT_STYLES.contains(startPointEndingStyle))
248250
{
249251
cs.moveTo(lineEndingSize, y);
250252
}
251253
else
252254
{
253255
cs.moveTo(0, y);
254256
}
255-
if (SHORT_STYLES.contains(annotation.getEndPointEndingStyle()))
257+
if (SHORT_STYLES.contains(endPointEndingStyle))
256258
{
257259
cs.lineTo(lineLength - lineEndingSize, y);
258260
}
@@ -277,13 +279,13 @@ public void generateNormalAppearance()
277279
}
278280

279281
// check for LE_NONE only needed to avoid q cm Q for that case
280-
if (!LE_NONE.equals(annotation.getStartPointEndingStyle()))
282+
if (!LE_NONE.equals(startPointEndingStyle))
281283
{
282284
cs.saveGraphicsState();
283-
if (ANGLED_STYLES.contains(annotation.getStartPointEndingStyle()))
285+
if (ANGLED_STYLES.contains(startPointEndingStyle))
284286
{
285287
cs.transform(Matrix.getRotateInstance(angle, x1, y1));
286-
drawStyle(annotation.getStartPointEndingStyle(), cs, 0, y, lineEndingSize, hasStroke, hasBackground, false);
288+
drawStyle(startPointEndingStyle, cs, 0, y, lineEndingSize, hasStroke, hasBackground, false);
287289
}
288290
else
289291
{
@@ -293,19 +295,19 @@ public void generateNormalAppearance()
293295
// We use the angle we already know and the distance y to translate to the new coordinate.
294296
float xx1 = x1 - (float) (y * Math.sin(angle));
295297
float yy1 = y1 + (float) (y * Math.cos(angle));
296-
drawStyle(annotation.getStartPointEndingStyle(), cs, xx1, yy1, lineEndingSize, hasStroke, hasBackground, false);
298+
drawStyle(startPointEndingStyle, cs, xx1, yy1, lineEndingSize, hasStroke, hasBackground, false);
297299
}
298300
cs.restoreGraphicsState();
299301
}
300302

301303
// check for LE_NONE only needed to avoid q cm Q for that case
302-
if (!LE_NONE.equals(annotation.getEndPointEndingStyle()))
304+
if (!LE_NONE.equals(endPointEndingStyle))
303305
{
304306
// save / restore not needed because it's the last one
305-
if (ANGLED_STYLES.contains(annotation.getEndPointEndingStyle()))
307+
if (ANGLED_STYLES.contains(endPointEndingStyle))
306308
{
307309
cs.transform(Matrix.getRotateInstance(angle, x2, y2));
308-
drawStyle(annotation.getEndPointEndingStyle(), cs, 0, y, lineEndingSize, hasStroke, hasBackground, true);
310+
drawStyle(endPointEndingStyle, cs, 0, y, lineEndingSize, hasStroke, hasBackground, true);
309311
}
310312
else
311313
{
@@ -315,7 +317,7 @@ public void generateNormalAppearance()
315317
// We use the angle we already know and the distance y to translate to the new coordinate.
316318
float xx2 = x2 - (float) (y * Math.sin(angle));
317319
float yy2 = y2 + (float) (y * Math.cos(angle));
318-
drawStyle(annotation.getEndPointEndingStyle(), cs, xx2, yy2, lineEndingSize, hasStroke, hasBackground, true);
320+
drawStyle(endPointEndingStyle, cs, xx2, yy2, lineEndingSize, hasStroke, hasBackground, true);
319321
}
320322
}
321323
}

0 commit comments

Comments
 (0)