Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PdfClown-NetStandard/CliSamples/CliSamples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common">
<Version>4.5.0-rc1</Version>
<Version>4.7.0</Version>
</PackageReference>
<PackageReference Include="System.Drawing.Primitives">
<Version>4.3.0</Version>
Expand Down
2 changes: 1 addition & 1 deletion PdfClown-NetStandard/PdfClown/PdfClown.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This is an unofficial port to .NET Standard 2.0.</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="4.5.0-rc1" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down