@@ -61,12 +61,7 @@ public class FontUtil {
61
61
private FontUtil () {}
62
62
63
63
public static String addRandomSubsetPrefixForFontName (final String fontName ) {
64
- final StringBuilder newFontName = new StringBuilder (fontName .length () + 7 );
65
- byte [] randomByte = new byte [1 ];
66
- for (int k = 0 ; k < 6 ; ++k ) {
67
- NUMBER_GENERATOR .nextBytes (randomByte );
68
- newFontName .append ((char ) (Math .abs (randomByte [0 ]%26 ) + 'A' ));
69
- }
64
+ final StringBuilder newFontName = getRandomFontPrefix (6 );
70
65
newFontName .append ('+' ).append (fontName );
71
66
return newFontName .toString ();
72
67
}
@@ -124,11 +119,7 @@ static CMapToUnicode getToUnicodeFromUniMap(String uniMap) {
124
119
}
125
120
126
121
static String createRandomFontName () {
127
- StringBuilder s = new StringBuilder ("" );
128
- for (int k = 0 ; k < 7 ; ++k ) {
129
- s .append ((char ) (Math .random () * 26 + 'A' ));
130
- }
131
- return s .toString ();
122
+ return getRandomFontPrefix (7 ).toString ();
132
123
}
133
124
134
125
static int [] convertSimpleWidthsArray (PdfArray widthsArray , int first , int missingWidth ) {
@@ -172,4 +163,14 @@ static IntHashtable convertCompositeWidthsArray(PdfArray widthsArray) {
172
163
}
173
164
return res ;
174
165
}
166
+
167
+ private static StringBuilder getRandomFontPrefix (int length ) {
168
+ final StringBuilder stringBuilder = new StringBuilder ();
169
+ final byte [] randomByte = new byte [length ];
170
+ NUMBER_GENERATOR .nextBytes (randomByte );
171
+ for (int k = 0 ; k < length ; ++k ) {
172
+ stringBuilder .append ((char ) (Math .abs (randomByte [k ] % 26 ) + 'A' ));
173
+ }
174
+ return stringBuilder ;
175
+ }
175
176
}
0 commit comments