diff --git a/src/UglyToad.PdfPig.Tests/Fonts/TrueType/Parser/TrueTypeFontParserTests.cs b/src/UglyToad.PdfPig.Tests/Fonts/TrueType/Parser/TrueTypeFontParserTests.cs
index 2136ac8ce..302d57bb3 100644
--- a/src/UglyToad.PdfPig.Tests/Fonts/TrueType/Parser/TrueTypeFontParserTests.cs
+++ b/src/UglyToad.PdfPig.Tests/Fonts/TrueType/Parser/TrueTypeFontParserTests.cs
@@ -1,19 +1,14 @@
// ReSharper disable CompareOfFloatsByEqualityOperator
namespace UglyToad.PdfPig.Tests.Fonts.TrueType.Parser
{
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
using PdfPig.Core;
using PdfPig.Fonts.TrueType;
using PdfPig.Fonts.TrueType.Parser;
using PdfPig.Fonts.TrueType.Tables;
- using UglyToad.PdfPig.Fonts.TrueType.Glyphs;
- using UglyToad.PdfPig.Graphics;
+ using System;
+ using System.Globalization;
+ using System.Text;
+ using System.Text.RegularExpressions;
using Xunit;
public class TrueTypeFontParserTests
diff --git a/src/UglyToad.PdfPig.Tests/Integration/VisualVerification/GenerateLetterBoundingBoxImages.cs b/src/UglyToad.PdfPig.Tests/Integration/VisualVerification/GenerateLetterBoundingBoxImages.cs
index 581163204..38704b0c4 100644
--- a/src/UglyToad.PdfPig.Tests/Integration/VisualVerification/GenerateLetterBoundingBoxImages.cs
+++ b/src/UglyToad.PdfPig.Tests/Integration/VisualVerification/GenerateLetterBoundingBoxImages.cs
@@ -1,8 +1,8 @@
namespace UglyToad.PdfPig.Tests.Integration.VisualVerification
{
using PdfPig.Core;
+ using SkiaSharp;
using System;
- using System.Drawing;
using System.IO;
using Xunit;
@@ -24,6 +24,12 @@ public class GenerateLetterBoundingBoxImages
private const string MOZILLA_10372_2File = "MOZILLA-10372-2";
private const string Type3FontZeroHeight = "type3-font-zero-height";
+ private const string OutputPath = "Images";
+
+ private static readonly SKPaint violetPen = new SKPaint() { Color = SKColors.BlueViolet, StrokeWidth = 1 };
+ private static readonly SKPaint redPen = new SKPaint() { Color = SKColors.Crimson, StrokeWidth = 1 };
+ private static readonly SKPaint bluePen = new SKPaint() { Color = SKColors.GreenYellow, StrokeWidth = 1 };
+
private static string GetFilename(string name)
{
var documentFolder = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "Integration", "Documents"));
@@ -155,12 +161,8 @@ private static void Run(string file, int imageHeight = 792, int pageNo = 1)
double scale = imageHeight / page.Height;
- var violetPen = new Pen(Color.BlueViolet, 1);
- var redPen = new Pen(Color.Crimson, 1);
- var bluePen = new Pen(Color.GreenYellow, 1);
-
- using (var bitmap = new Bitmap(image))
- using (var graphics = Graphics.FromImage(bitmap))
+ using (var bitmap = SKBitmap.FromImage(image))
+ using (var graphics = new SKCanvas(bitmap))
{
foreach (var word in page.GetWords())
{
@@ -177,46 +179,51 @@ private static void Run(string file, int imageHeight = 792, int pageNo = 1)
DrawRectangle(annotation.Rectangle, graphics, bluePen, imageHeight, scale);
}
+ graphics.Flush();
+
var imageName = $"{file}.jpg";
- if (!Directory.Exists("Images"))
+ if (!Directory.Exists(OutputPath))
{
- Directory.CreateDirectory("Images");
+ Directory.CreateDirectory(OutputPath);
}
- var savePath = Path.Combine("Images", imageName);
+ var savePath = Path.Combine(OutputPath, imageName);
- bitmap.Save(savePath);
+ using (var fs = new FileStream(savePath, FileMode.Create))
+ using (SKData d = bitmap.Encode(SKEncodedImageFormat.Png, 100))
+ {
+ d.SaveTo(fs);
+ }
}
}
}
- private static void DrawRectangle(PdfRectangle rectangle, Graphics graphics, Pen pen,
- int imageHeight, double scale)
+ private static void DrawRectangle(PdfRectangle rectangle, SKCanvas graphics, SKPaint pen, int imageHeight, double scale)
{
int GetY(PdfPoint p)
{
return imageHeight - (int)(p.Y * scale);
}
- Point GetPoint(PdfPoint p)
+ SKPoint GetPoint(PdfPoint p)
{
- return new Point((int)(p.X * scale), GetY(p));
+ return new SKPoint((int)(p.X * scale), GetY(p));
}
- graphics.DrawLine(pen, GetPoint(rectangle.BottomLeft), GetPoint(rectangle.BottomRight));
- graphics.DrawLine(pen, GetPoint(rectangle.BottomRight), GetPoint(rectangle.TopRight));
- graphics.DrawLine(pen, GetPoint(rectangle.TopRight), GetPoint(rectangle.TopLeft));
- graphics.DrawLine(pen, GetPoint(rectangle.TopLeft), GetPoint(rectangle.BottomLeft));
+ graphics.DrawLine(GetPoint(rectangle.BottomLeft), GetPoint(rectangle.BottomRight), pen);
+ graphics.DrawLine(GetPoint(rectangle.BottomRight), GetPoint(rectangle.TopRight), pen);
+ graphics.DrawLine(GetPoint(rectangle.TopRight), GetPoint(rectangle.TopLeft), pen);
+ graphics.DrawLine(GetPoint(rectangle.TopLeft), GetPoint(rectangle.BottomLeft), pen);
}
- private static Image GetCorrespondingImage(string filename)
+ private static SKImage GetCorrespondingImage(string filename)
{
var pdf = GetFilename(filename);
pdf = pdf.Replace(".pdf", ".jpg");
- return Image.FromFile(pdf);
+ return SKImage.FromEncodedData(pdf);
}
}
}
diff --git a/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj b/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj
index 05fe41af5..0fb78ebf4 100644
--- a/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj
+++ b/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj
@@ -94,7 +94,7 @@
all
-
+