18
18
19
19
import static uk .org .okapibarcode .graphics .TextAlignment .CENTER ;
20
20
import static uk .org .okapibarcode .graphics .TextAlignment .JUSTIFY ;
21
+ import static uk .org .okapibarcode .util .Integers .normalizeRotation ;
21
22
22
23
import java .io .IOException ;
23
24
import java .io .OutputStream ;
@@ -67,7 +68,7 @@ public class SvgRenderer implements SymbolRenderer {
67
68
68
69
/** Whether or not to include the XML prolog in the output. */
69
70
private final boolean xmlProlog ;
70
-
71
+
71
72
/** The clockwise rotation of the symbol in degrees. */
72
73
private final int rotation ;
73
74
@@ -94,15 +95,15 @@ public SvgRenderer(OutputStream out, double magnification, Color paper, Color in
94
95
* @param ink the ink (foreground) color
95
96
* @param xmlProlog whether or not to include the XML prolog in the output (usually {@code true} for
96
97
* standalone SVG documents, {@code false} for SVG content embedded directly in HTML documents)
97
- * @param rotation the clockwise rotation of the symbol in degrees (0, 90, 180, or 270 )
98
+ * @param rotation the clockwise rotation of the symbol in degrees (must be a multiple of 90 )
98
99
*/
99
100
public SvgRenderer (OutputStream out , double magnification , Color paper , Color ink , boolean xmlProlog , int rotation ) {
100
101
this .out = out ;
101
102
this .magnification = magnification ;
102
103
this .paper = paper ;
103
104
this .ink = ink ;
104
105
this .xmlProlog = xmlProlog ;
105
- this .rotation = SymbolRenderer . normalizeRotation (rotation );
106
+ this .rotation = normalizeRotation (rotation );
106
107
}
107
108
108
109
/** {@inheritDoc} */
@@ -139,37 +140,35 @@ public void render(Symbol symbol) throws IOException {
139
140
writer .append (" \" http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\" >\n " );
140
141
}
141
142
142
- // render rotation clockwise
143
- int rotateHeight = height ;
144
- int rotateWidth = width ;
143
+ // Rotation
144
+ int rotatedHeight = height ;
145
+ int rotatedWidth = width ;
145
146
String transform ;
146
147
switch (rotation ) {
147
148
case 90 :
148
- rotateHeight = width ;
149
- rotateWidth = height ;
150
- transform = " transform=\" rotate(" + rotation + ") translate(0,-" + rotateWidth + ")\" " ;
149
+ rotatedHeight = width ;
150
+ rotatedWidth = height ;
151
+ transform = " transform=\" rotate(" + rotation + ") translate(0,-" + rotatedWidth + ")\" " ;
151
152
break ;
152
153
case 180 :
153
- transform = " transform=\" rotate(" + rotation + "," + (width / 2 ) + "," + (height / 2 ) + ")\" " ;
154
+ transform = " transform=\" rotate(" + rotation + "," + (width / 2 ) + "," + (height / 2 ) + ")\" " ;
154
155
break ;
155
156
case 270 :
156
- rotateHeight = width ;
157
- rotateWidth = height ;
158
- transform = " transform=\" rotate(" + rotation + ") translate(-" + rotateHeight + ",0)\" " ;
157
+ rotatedHeight = width ;
158
+ rotatedWidth = height ;
159
+ transform = " transform=\" rotate(" + rotation + ") translate(-" + rotatedHeight + ",0)\" " ;
159
160
break ;
160
161
default :
161
162
transform = "" ;
162
163
break ;
163
164
}
164
165
165
166
// Header
166
- writer .append ("<svg width=\" " ).appendInt (rotateWidth )
167
- .append ("\" height=\" " ).appendInt (rotateHeight )
167
+ writer .append ("<svg width=\" " ).appendInt (rotatedWidth )
168
+ .append ("\" height=\" " ).appendInt (rotatedHeight )
168
169
.append ("\" version=\" 1.1" )
169
170
.append ("\" xmlns=\" http://www.w3.org/2000/svg\" >\n " );
170
171
writer .append (" <desc>" ).append (clean (title )).append ("</desc>\n " );
171
-
172
-
173
172
writer .append (" <g id=\" barcode\" fill=\" #" ).append (fgColour ).append ("\" " ).append (transform ).append (">\n " );
174
173
writer .append (" <rect x=\" 0\" y=\" 0\" width=\" " ).appendInt (width )
175
174
.append ("\" height=\" " ).appendInt (height )
0 commit comments