diff --git a/PdfClown-NetStandard/CliSamples/CliSamples.csproj b/PdfClown-NetStandard/CliSamples/CliSamples.csproj index 94587f4..7f71e30 100644 --- a/PdfClown-NetStandard/CliSamples/CliSamples.csproj +++ b/PdfClown-NetStandard/CliSamples/CliSamples.csproj @@ -105,7 +105,7 @@ - 4.5.0-rc1 + 4.7.0 4.3.0 diff --git a/PdfClown-NetStandard/PdfClown/PdfClown.csproj b/PdfClown-NetStandard/PdfClown/PdfClown.csproj index d1813ef..7a9b9fa 100644 --- a/PdfClown-NetStandard/PdfClown/PdfClown.csproj +++ b/PdfClown-NetStandard/PdfClown/PdfClown.csproj @@ -18,7 +18,7 @@ This is an unofficial port to .NET Standard 2.0. - + diff --git a/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/TextStyle.cs b/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/TextStyle.cs index 9bab659..cb8745c 100644 --- a/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/TextStyle.cs +++ b/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/TextStyle.cs @@ -92,7 +92,8 @@ public double FontSize public double GetWidth( char textChar ) - {return font.GetWidth(textChar, fontSize) * scaleX / scaleY;} + // PK - 2017-09-15 - font can be null, which throws an exception below, so fall back on fontSize for width calculation + {return (font?.GetWidth(textChar, fontSize) ?? fontSize) * scaleX / scaleY;} public TextRenderModeEnum RenderMode {get{return renderMode;}} diff --git a/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/fonts/CompositeFont.cs b/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/fonts/CompositeFont.cs index 2ceea9c..f7009c5 100644 --- a/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/fonts/CompositeFont.cs +++ b/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/fonts/CompositeFont.cs @@ -207,7 +207,8 @@ 2. startCID endCID glyphWidth } // Default glyph width. { - PdfInteger defaultWidthObject = (PdfInteger)BaseDataObject[PdfName.DW]; + // PK 2017-03-08 - Changed type from PdfInteger to IPdfNumber to avoid ClassCastException and allow for more granular font sizes + IPdfNumber defaultWidthObject = (IPdfNumber)BaseDataObject[PdfName.DW]; if(defaultWidthObject != null) {DefaultWidth = defaultWidthObject.IntValue;} } diff --git a/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/fonts/Font.cs b/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/fonts/Font.cs index 49bc42a..248eda3 100644 --- a/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/fonts/Font.cs +++ b/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/fonts/Font.cs @@ -338,10 +338,12 @@ byte[] code {codeBuffers[codeBufferIndex] = new byte[codeBufferIndex];} int index = 0; int codeLength = code.Length; - int codeBufferSize = 1; + // PK 2017-03-08 - tweaks to codeBuffer array to avoid ArrayIndexOutOfBoundsException if character encoding isn't quite as expected + int codeBufferSize = codeBuffers.Length > 0 ? 1 : 0; while(index < codeLength) { - byte[] codeBuffer = codeBuffers[codeBufferSize]; + // PK 2017-03-08 - tweaks to codeBuffer array to avoid ArrayIndexOutOfBoundsException if character encoding isn't quite as expected + byte[] codeBuffer = codeBuffers.Length > codeBufferSize ? codeBuffers[codeBufferSize] : new byte[codeBufferSize]; System.Buffer.BlockCopy(code, index, codeBuffer, 0, codeBufferSize); int textChar = 0; if(!codes.TryGetValue(new ByteArray(codeBuffer), out textChar)) @@ -388,8 +390,9 @@ public int DefaultCode {return defaultCode;} set { - if(!glyphIndexes.ContainsKey(value)) - throw new EncodeException((char)value); + // PK 2017-03-08 - skip EncodeException, which should just result in a "?" or rectangle appearing instead of the correct character + //if(!glyphIndexes.ContainsKey(value)) + // throw new EncodeException((char)value); defaultCode = value; } @@ -810,7 +813,8 @@ protected void Load( else if(codePoints.Contains((int)' ')) {DefaultCode = ' ';} else - {DefaultCode = codePoints.First();} + // PK 2017-03-08 - allow for encoding to fail, which should just result in a "?" or rectangle appearing instead of the correct character + {DefaultCode = codePoints.FirstOrDefault();} } } diff --git a/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/fonts/SimpleFont.cs b/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/fonts/SimpleFont.cs index ae1c25d..6ca22c2 100644 --- a/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/fonts/SimpleFont.cs +++ b/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/fonts/SimpleFont.cs @@ -134,7 +134,8 @@ names replace consecutive code indices until the next code appears in the array. ByteArray charCode = new ByteArray(new byte[]{(byte)((PdfInteger)BaseDataObject[PdfName.FirstChar]).IntValue}); foreach(PdfDirectObject glyphWidthObject in glyphWidthObjects) { - if(((PdfInteger)glyphWidthObject).IntValue == 0) + // PK 2017-03-08 - Changed type from PdfInteger to IPdfNumber to avoid ClassCastException and allow for more granular font sizes + if(((IPdfNumber)glyphWidthObject).IntValue == 0) {codes.Remove(charCode);} charCode.Data[0]++; } diff --git a/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/objects/ShowText.cs b/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/objects/ShowText.cs index 439a0a4..3e4ed2c 100644 --- a/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/objects/ShowText.cs +++ b/PdfClown-NetStandard/PdfClown/org/pdfclown/documents/contents/objects/ShowText.cs @@ -103,7 +103,8 @@ parsing mechanism is implemented... */ double contextHeight = state.Scanner.ContextSize.Height; - Font font = state.Font; + // PK - 2017-09-15 - state.Font can be null, which throws an exception below, so fall back on standard Courier + Font font = state.Font ?? new StandardType1Font(((Page) state.Scanner.RootLevel.ContentContext).Document, StandardType1Font.FamilyEnum.Courier, false, false); double fontSize = state.FontSize; double scaledFactor = Font.GetScalingFactor(fontSize) * state.Scale; bool wordSpaceSupported = !(font is CompositeFont);