@@ -61,12 +61,7 @@ public class FontUtil {
6161 private FontUtil () {}
6262
6363 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 );
7065 newFontName .append ('+' ).append (fontName );
7166 return newFontName .toString ();
7267 }
@@ -124,11 +119,7 @@ static CMapToUnicode getToUnicodeFromUniMap(String uniMap) {
124119 }
125120
126121 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 ();
132123 }
133124
134125 static int [] convertSimpleWidthsArray (PdfArray widthsArray , int first , int missingWidth ) {
@@ -172,4 +163,14 @@ static IntHashtable convertCompositeWidthsArray(PdfArray widthsArray) {
172163 }
173164 return res ;
174165 }
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+ }
175176}
0 commit comments