Skip to content

Commit

Permalink
Ported some missing map files from the https://github.com/LibrePDF/Op…
Browse files Browse the repository at this point in the history
…enPDF project
  • Loading branch information
VahidN committed Mar 8, 2019
1 parent 9236401 commit 70b6e38
Show file tree
Hide file tree
Showing 179 changed files with 303,041 additions and 23,674 deletions.
100 changes: 100 additions & 0 deletions src/iTextSharp.LGPLv2.Core.FunctionalTests/Issues/Issue34.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using System.Collections;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace iTextSharp.LGPLv2.Core.FunctionalTests.Issues
{
/// <summary>
/// https://github.com/VahidN/iTextSharp.LGPLv2.Core/issues/34
/// </summary>
[TestClass]
public class Issue34
{
[TestMethod]
public void Verify_Issue34_Create_Font_CanBe_Processed()
{
var pdfDoc = new Document(PageSize.A4);

var pdfFilePath = TestUtils.GetOutputFileName();
var fileStream = new FileStream(pdfFilePath, FileMode.Create);
PdfWriter.GetInstance(pdfDoc, fileStream);

pdfDoc.AddAuthor(TestUtils.Author);
pdfDoc.Open();

// STSong-Light requires this language pack http://ardownload.adobe.com/pub/adobe/reader/win/AcrobatDC/misc/FontPack1900820071_XtdAlf_Lang_DC.msi
var baseFont = BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
var font = new Font(baseFont, 12);

pdfDoc.Add(new Paragraph(font.BaseFont.PostscriptFontName, font));
pdfDoc.Add(new Paragraph("你好", font));

pdfDoc.Close();
fileStream.Dispose();

TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
}

[TestMethod]
public void Verify_Issue34_Fill_Form1_CanBe_Processed()
{
var pdfFilePath = TestUtils.GetOutputFileName();
var stream = new FileStream(pdfFilePath, FileMode.Create);

var path = TestUtils.GetPdfsPath("issue16.pdf");
var reader = new PdfReader(path);
var stamper = new PdfStamper(reader, stream);

var form = stamper.AcroFields;

var baseFont = BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
form.AddSubstitutionFont(baseFont);

foreach (DictionaryEntry field in form.Fields)
{
Console.WriteLine(field.Key);
}

form.SetField("Text Field0", "你好");

stamper.Close();
reader.Close();
stream.Dispose();
}

[TestMethod]
public void Verify_Issue34_Fill_Form2_CanBe_Processed()
{
var pdfFilePath = TestUtils.GetOutputFileName();
var stream = new FileStream(pdfFilePath, FileMode.Create);

var path = TestUtils.GetPdfsPath("SamplePDFForm.pdf");
var reader = new PdfReader(path);
var stamper = new PdfStamper(reader, stream);

var form = stamper.AcroFields;

var baseFont = BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
form.AddSubstitutionFont(baseFont);

foreach (DictionaryEntry field in form.Fields)
{
Console.WriteLine(field.Key);
}

form.SetField("First Name", "你好");
form.SetField("Last Name", "你好");
form.SetField("Awesome Checkbox", true ? "Yes" : "Off");

// set this if you want the result PDF to not be editable.
stamper.FormFlattening = true;

stamper.Close();
reader.Close();
stream.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@
* limitations under the License.
*/

namespace iTextSharp.text.pdf.qrcode {
namespace iTextSharp.text.pdf.qrcode
{

/**
* <p>Thrown when an exception occurs during Reed-Solomon decoding, such as when
* there are too many errors to correct.</p>
*
* @author Sean Owen
*/
[Serializable]
public sealed class ReedSolomonException : Exception {
[Serializable]
public class ReedSolomonException : Exception
{

public ReedSolomonException(String message)
: base(message) {
: base(message)
{
}

protected ReedSolomonException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
protected ReedSolomonException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,29 @@
* limitations under the License.
*/

namespace iTextSharp.text.pdf.qrcode {
namespace iTextSharp.text.pdf.qrcode
{

/**
* A base class which covers the range of exceptions which may occur when encoding a barcode using
* the Writer framework.
*
* @author dswitkin@google.com (Daniel Switkin)
*/
[Serializable]
public sealed class WriterException : Exception {
[Serializable]
public class WriterException : Exception
{

public WriterException()
: base() {
: base()
{
}

public WriterException(String message)
: base(message) {
: base(message)
{
}

protected WriterException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
protected WriterException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
}
Binary file not shown.
4 changes: 2 additions & 2 deletions src/iTextSharp.LGPLv2.Core/iTextSharp.LGPLv2.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description> iTextSharp.LGPLv2.Core is an unofficial port of the last LGPL version of the iTextSharp (V4.1.6) to .NET Core.</Description>
<VersionPrefix>1.4.6</VersionPrefix>
<VersionPrefix>1.5.0</VersionPrefix>
<LangVersion>latest</LangVersion>
<Authors>Vahid Nasiri</Authors>
<TargetFrameworks>net40;netstandard1.3;netstandard2.0</TargetFrameworks>
Expand All @@ -21,7 +21,7 @@
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="iTextSharp\text\pdf\fonts\*.*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<EmbeddedResource Include="iTextSharp\text\pdf\fonts\*.*;iTextSharp\text\pdf\fonts\cmaps\*.*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PlatformTarget>anycpu</PlatformTarget>
Expand Down
67 changes: 26 additions & 41 deletions src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/CJKFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -552,36 +552,28 @@ internal static char[] ReadCMap(string name)

internal static Hashtable ReadFontProperties(string name)
{
try
name += ".properties";
Stream isp = GetResourceStream(RESOURCE_PATH + name);
if (isp == null)
{
name += ".properties";
Stream isp = GetResourceStream(RESOURCE_PATH + name);
if(isp == null)
{
return null;
}

Properties p = new Properties();
p.Load(isp);
isp.Dispose();
IntHashtable w = CreateMetric(p["W"]);
p.Remove("W");
IntHashtable w2 = CreateMetric(p["W2"]);
p.Remove("W2");
Hashtable map = new Hashtable();
foreach (string key in p.Keys)
{
map[key] = p[key];
}
map["W"] = w;
map["W2"] = w2;
return map;
return null;
}
catch

Properties p = new Properties();
p.Load(isp);
isp.Dispose();
IntHashtable w = CreateMetric(p["W"]);
p.Remove("W");
IntHashtable w2 = CreateMetric(p["W2"]);
p.Remove("W2");
Hashtable map = new Hashtable();
foreach (string key in p.Keys)
{
// empty on purpose
map[key] = p[key];
}
return null;
map["W"] = w;
map["W2"] = w2;
return map;
}

internal override int GetRawWidth(int c, string name)
Expand Down Expand Up @@ -624,30 +616,23 @@ private static void loadProperties()
{
if (_propertiesLoaded)
return;
try
Stream isp = GetResourceStream(RESOURCE_PATH + "cjkfonts.properties");
if (isp != null)
{
Stream isp = GetResourceStream(RESOURCE_PATH + "cjkfonts.properties");
CjkFonts.Load(isp);
isp.Dispose();

isp = GetResourceStream(RESOURCE_PATH + "cjkencodings.properties");
if (isp != null)
{
CjkFonts.Load(isp);
CjkEncodings.Load(isp);
isp.Dispose();

isp = GetResourceStream(RESOURCE_PATH + "cjkencodings.properties");
if (isp != null)
{
CjkEncodings.Load(isp);
isp.Dispose();
}
}
}
catch
{
CjkFonts = new Properties();
CjkEncodings = new Properties();
}
_propertiesLoaded = true;
}
}

private float getBBox(int idx)
{
string s = (string)_fontDesc["FontBBox"];
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 70b6e38

Please sign in to comment.