Skip to content

Commit 611fc2e

Browse files
Generalize reading of bytes for woff format conversion
DEVSIX-1148 Autoported commit. Original commit hash: [66f95dd41b]
1 parent d6dd84a commit 611fc2e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

itext/itext.io/itext/io/font/FontProgramFactory.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ source product.
4343
*/
4444
using System;
4545
using System.Collections.Generic;
46-
using System.IO;
47-
using iText.IO.Util;
46+
using iText.IO.Source;
4847

4948
namespace iText.IO.Font {
5049
/// <summary>Provides methods for creating various types of fonts.</summary>
@@ -217,7 +216,7 @@ public static FontProgram CreateFont(String name, byte[] fontProgram, bool cache
217216
)) {
218217
if (".woff".Equals(fontFileExtension)) {
219218
if (fontProgram == null) {
220-
fontProgram = StreamUtil.InputStreamToArray(new FileStream(name, FileMode.Open, FileAccess.Read));
219+
fontProgram = ReadBytesFromPath(name);
221220
}
222221
try {
223222
fontProgram = WoffConverter.Convert(fontProgram);
@@ -563,5 +562,19 @@ public static void ClearRegisteredFonts() {
563562
public static void ClearRegisteredFontFamilies() {
564563
fontRegisterProvider.ClearRegisteredFontFamilies();
565564
}
565+
566+
/// <exception cref="System.IO.IOException"/>
567+
private static byte[] ReadBytesFromPath(String path) {
568+
RandomAccessFileOrArray raf = new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateBestSource
569+
(path));
570+
int bufLen = (int)raf.Length();
571+
if (bufLen < raf.Length()) {
572+
throw new iText.IO.IOException(String.Format("Source data from \"{0}\" is bigger than byte array can hold."
573+
, path));
574+
}
575+
byte[] buf = new byte[bufLen];
576+
raf.ReadFully(buf);
577+
return buf;
578+
}
566579
}
567580
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
38737174a7ce7345f417aa84d761937e54d10da7
1+
66f95dd41bc82697fdc47f1da676db720bf42ebb

0 commit comments

Comments
 (0)