mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-14 19:05:01 +08:00
change rectangle drawing logic for tests
support rotated output rectangles in the visual verification tests.
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using PdfPig.Core;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
public class GenerateLetterBoundingBoxImages
|
public class GenerateLetterBoundingBoxImages
|
||||||
@@ -104,21 +105,19 @@
|
|||||||
var page = document.GetPage(1);
|
var page = document.GetPage(1);
|
||||||
|
|
||||||
var violetPen = new Pen(Color.BlueViolet, 1);
|
var violetPen = new Pen(Color.BlueViolet, 1);
|
||||||
var greenPen = new Pen(Color.GreenYellow, 1);
|
var greenPen = new Pen(Color.Crimson, 1);
|
||||||
|
|
||||||
using (var bitmap = new Bitmap(image))
|
using (var bitmap = new Bitmap(image))
|
||||||
using (var graphics = Graphics.FromImage(bitmap))
|
using (var graphics = Graphics.FromImage(bitmap))
|
||||||
{
|
{
|
||||||
foreach (var word in page.GetWords())
|
foreach (var word in page.GetWords())
|
||||||
{
|
{
|
||||||
graphics.DrawRectangle(greenPen, new Rectangle((int)word.BoundingBox.Left,
|
DrawRectangle(word.BoundingBox, graphics, greenPen, imageHeight);
|
||||||
imageHeight - (int)word.BoundingBox.Top, (int)word.BoundingBox.Width, (int)word.BoundingBox.Height));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var letter in page.Letters)
|
foreach (var letter in page.Letters)
|
||||||
{
|
{
|
||||||
graphics.DrawRectangle(violetPen, new Rectangle((int)letter.GlyphRectangle.Left,
|
DrawRectangle(letter.GlyphRectangle, graphics, violetPen, imageHeight);
|
||||||
imageHeight - (int)(letter.GlyphRectangle.Bottom + letter.GlyphRectangle.Height), (int)Math.Max(1, letter.GlyphRectangle.Width), (int)letter.GlyphRectangle.Height));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var imageName = $"{file}.jpg";
|
var imageName = $"{file}.jpg";
|
||||||
@@ -135,6 +134,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void DrawRectangle(PdfRectangle rectangle, Graphics graphics, Pen pen,
|
||||||
|
int imageHeight)
|
||||||
|
{
|
||||||
|
int GetY(PdfPoint p)
|
||||||
|
{
|
||||||
|
return imageHeight - (int) p.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
Point GetPoint(PdfPoint p)
|
||||||
|
{
|
||||||
|
return new Point((int)p.X, 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));
|
||||||
|
}
|
||||||
|
|
||||||
private static Image GetCorrespondingImage(string filename)
|
private static Image GetCorrespondingImage(string filename)
|
||||||
{
|
{
|
||||||
var pdf = GetFilename(filename);
|
var pdf = GetFilename(filename);
|
||||||
|
Reference in New Issue
Block a user