mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-07 16:14:03 +08:00
Expose letter's font via GetFont(), make Font property as obsolete and use FontDetails instead
Some checks failed
Build, test and publish draft / build (push) Has been cancelled
Build and test [MacOS] / build (push) Has been cancelled
Run Common Crawl Tests / build (0000-0001) (push) Has been cancelled
Run Common Crawl Tests / build (0002-0003) (push) Has been cancelled
Run Common Crawl Tests / build (0004-0005) (push) Has been cancelled
Run Common Crawl Tests / build (0006-0007) (push) Has been cancelled
Run Integration Tests / build (push) Has been cancelled
Nightly Release / Check if this commit has already been published (push) Has been cancelled
Nightly Release / tests (push) Has been cancelled
Nightly Release / build_and_publish_nightly (push) Has been cancelled
Some checks failed
Build, test and publish draft / build (push) Has been cancelled
Build and test [MacOS] / build (push) Has been cancelled
Run Common Crawl Tests / build (0000-0001) (push) Has been cancelled
Run Common Crawl Tests / build (0002-0003) (push) Has been cancelled
Run Common Crawl Tests / build (0004-0005) (push) Has been cancelled
Run Common Crawl Tests / build (0006-0007) (push) Has been cancelled
Run Integration Tests / build (push) Has been cancelled
Nightly Release / Check if this commit has already been published (push) Has been cancelled
Nightly Release / tests (push) Has been cancelled
Nightly Release / build_and_publish_nightly (push) Has been cancelled
This commit is contained in:
@@ -68,25 +68,11 @@
|
||||
// update textSequence?
|
||||
|
||||
// update font details to bold
|
||||
var fontDetails = new FontDetails(letter.Font.Name, true, letter.Font.Weight, letter.Font.IsItalic);
|
||||
|
||||
var newLetter = new Letter(letter.Value,
|
||||
letter.GlyphRectangle,
|
||||
letter.StartBaseLine,
|
||||
letter.EndBaseLine,
|
||||
letter.Width,
|
||||
letter.FontSize,
|
||||
fontDetails,
|
||||
letter.RenderingMode,
|
||||
letter.StrokeColor,
|
||||
letter.FillColor,
|
||||
letter.PointSize,
|
||||
letter.TextSequence);
|
||||
|
||||
// update markedContentStack?
|
||||
|
||||
// update letters
|
||||
cleanLetters[duplicatesOverlappingIndex] = newLetter;
|
||||
cleanLetters[duplicatesOverlappingIndex] = letter.AsBold();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -64,7 +64,7 @@
|
||||
letter.EndBaseLine,
|
||||
letter.Width,
|
||||
letter.FontSize,
|
||||
letter.Font,
|
||||
letter.GetFont()!,
|
||||
letter.RenderingMode,
|
||||
letter.StrokeColor,
|
||||
letter.FillColor,
|
||||
|
@@ -1,14 +1,12 @@
|
||||
namespace UglyToad.PdfPig.Tests.Dla
|
||||
{
|
||||
using System;
|
||||
using PdfFonts;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UglyToad.PdfPig.Content;
|
||||
using UglyToad.PdfPig.Core;
|
||||
using UglyToad.PdfPig.DocumentLayoutAnalysis;
|
||||
using UglyToad.PdfPig.DocumentLayoutAnalysis.ReadingOrderDetector;
|
||||
using UglyToad.PdfPig.Core;
|
||||
|
||||
public class UnsupervisedReadingOrderTests
|
||||
{
|
||||
@@ -65,7 +63,7 @@
|
||||
boundingBox,
|
||||
boundingBox.BottomLeft,
|
||||
boundingBox.BottomRight,
|
||||
10, 1, null, TextRenderingMode.NeitherClip, null, null, 0, 0);// These don't matter
|
||||
10, 1, (FontDetails)null, TextRenderingMode.NeitherClip, null, null, 0, 0);// These don't matter
|
||||
var leftTextBlock = new TextBlock(new[] { new TextLine(new[] { new Word(new[] { letter }) }) });
|
||||
return leftTextBlock;
|
||||
}
|
||||
|
@@ -86,8 +86,8 @@
|
||||
var letter = page.Letters[l];
|
||||
var expected = DataBoldItalic[l];
|
||||
Assert.Equal((string)expected[0], letter.Value);
|
||||
Assert.Equal((bool)expected[1], letter.Font.IsBold);
|
||||
Assert.Equal((bool)expected[2], letter.Font.IsItalic);
|
||||
Assert.Equal((bool)expected[1], letter.FontDetails.IsBold);
|
||||
Assert.Equal((bool)expected[2], letter.FontDetails.IsItalic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1154,7 +1154,7 @@
|
||||
{
|
||||
location += letter.Location.X;
|
||||
location += letter.Location.Y;
|
||||
location += letter.Font.Name.Length;
|
||||
location += letter.FontDetails.Name.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -54,12 +54,20 @@
|
||||
/// <summary>
|
||||
/// The name of the font.
|
||||
/// </summary>
|
||||
public string? FontName => Font?.Name;
|
||||
public string? FontName => FontDetails?.Name;
|
||||
|
||||
/// <summary>
|
||||
/// Details about the font for this letter.
|
||||
/// </summary>
|
||||
public FontDetails Font { get; }
|
||||
public FontDetails FontDetails { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Details about the font for this letter.
|
||||
/// </summary>
|
||||
[Obsolete("Use FontDetails instead.")]
|
||||
public FontDetails Font => FontDetails;
|
||||
|
||||
private readonly IFont? _font;
|
||||
|
||||
/// <summary>
|
||||
/// Text rendering mode that indicates whether we should draw this letter's strokes,
|
||||
@@ -95,17 +103,59 @@
|
||||
/// <summary>
|
||||
/// Sequence number of the ShowText operation that printed this letter.
|
||||
/// </summary>
|
||||
public int TextSequence { get; }
|
||||
public int TextSequence { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new letter to represent some text drawn by the Tj operator.
|
||||
/// </summary>
|
||||
public Letter(string value, PdfRectangle glyphRectangle,
|
||||
public Letter(string value,
|
||||
PdfRectangle glyphRectangle,
|
||||
PdfPoint startBaseLine,
|
||||
PdfPoint endBaseLine,
|
||||
double width,
|
||||
double fontSize,
|
||||
FontDetails font,
|
||||
IFont font,
|
||||
TextRenderingMode renderingMode,
|
||||
IColor strokeColor,
|
||||
IColor fillColor,
|
||||
double pointSize,
|
||||
int textSequence) :
|
||||
this(value, glyphRectangle,
|
||||
startBaseLine, endBaseLine,
|
||||
width, fontSize, font.Details, font,
|
||||
renderingMode, strokeColor, fillColor,
|
||||
pointSize, textSequence)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new letter to represent some text drawn by the Tj operator.
|
||||
/// </summary>
|
||||
public Letter(string value,
|
||||
PdfRectangle glyphRectangle,
|
||||
PdfPoint startBaseLine,
|
||||
PdfPoint endBaseLine,
|
||||
double width,
|
||||
double fontSize,
|
||||
FontDetails fontDetails,
|
||||
TextRenderingMode renderingMode,
|
||||
IColor strokeColor,
|
||||
IColor fillColor,
|
||||
double pointSize,
|
||||
int textSequence):
|
||||
this(value, glyphRectangle,
|
||||
startBaseLine, endBaseLine,
|
||||
width, fontSize, fontDetails, null,
|
||||
renderingMode, strokeColor, fillColor,
|
||||
pointSize, textSequence)
|
||||
{ }
|
||||
|
||||
private Letter(string value, PdfRectangle glyphRectangle,
|
||||
PdfPoint startBaseLine,
|
||||
PdfPoint endBaseLine,
|
||||
double width,
|
||||
double fontSize,
|
||||
FontDetails fontDetails,
|
||||
IFont? font,
|
||||
TextRenderingMode renderingMode,
|
||||
IColor strokeColor,
|
||||
IColor fillColor,
|
||||
@@ -118,7 +168,8 @@
|
||||
EndBaseLine = endBaseLine;
|
||||
Width = width;
|
||||
FontSize = fontSize;
|
||||
Font = font;
|
||||
FontDetails = fontDetails;
|
||||
_font = font;
|
||||
RenderingMode = renderingMode;
|
||||
if (renderingMode == TextRenderingMode.Stroke)
|
||||
{
|
||||
@@ -135,6 +186,42 @@
|
||||
TextOrientation = GetTextOrientation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Letter"/> instance with the same properties as the current instance,
|
||||
/// but with the font details set to bold.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A new <see cref="Letter"/> instance with bold font details.
|
||||
/// </returns>
|
||||
public Letter AsBold()
|
||||
{
|
||||
return new Letter(Value,
|
||||
GlyphRectangle,
|
||||
StartBaseLine,
|
||||
EndBaseLine,
|
||||
Width,
|
||||
FontSize,
|
||||
FontDetails.AsBold(),
|
||||
_font,
|
||||
RenderingMode,
|
||||
StrokeColor,
|
||||
FillColor,
|
||||
PointSize,
|
||||
TextSequence);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the font associated with this letter, if available.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="IFont"/> instance representing the font used for this letter,
|
||||
/// or <c>null</c> if no font is associated.
|
||||
/// </returns>
|
||||
public IFont? GetFont()
|
||||
{
|
||||
return _font;
|
||||
}
|
||||
|
||||
private TextOrientation GetTextOrientation()
|
||||
{
|
||||
if (Math.Abs(StartBaseLine.Y - EndBaseLine.Y) < 10e-5)
|
||||
|
@@ -133,7 +133,7 @@ namespace UglyToad.PdfPig.Graphics
|
||||
attachTo.EndBaseLine,
|
||||
attachTo.Width,
|
||||
attachTo.FontSize,
|
||||
attachTo.Font,
|
||||
attachTo.GetFont()!,
|
||||
attachTo.RenderingMode,
|
||||
attachTo.StrokeColor,
|
||||
attachTo.FillColor,
|
||||
@@ -158,7 +158,7 @@ namespace UglyToad.PdfPig.Graphics
|
||||
transformedPdfBounds.BottomRight,
|
||||
transformedPdfBounds.Width,
|
||||
fontSize,
|
||||
font.Details,
|
||||
font,
|
||||
currentState.FontState.TextRenderingMode,
|
||||
currentState.CurrentStrokingColor!,
|
||||
currentState.CurrentNonStrokingColor!,
|
||||
|
@@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// Summary details of the font used to draw a glyph.
|
||||
/// </summary>
|
||||
public class FontDetails
|
||||
public sealed class FontDetails
|
||||
{
|
||||
/// <summary>
|
||||
/// The normal weight for a font.
|
||||
@@ -35,6 +35,8 @@
|
||||
/// </summary>
|
||||
public bool IsItalic { get; }
|
||||
|
||||
private readonly Lazy<FontDetails> _bold;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="FontDetails"/>.
|
||||
/// </summary>
|
||||
@@ -44,6 +46,17 @@
|
||||
IsBold = isBold;
|
||||
Weight = weight;
|
||||
IsItalic = isItalic;
|
||||
|
||||
_bold = isBold ? new Lazy<FontDetails>(() => this) : new Lazy<FontDetails>(() => new FontDetails(Name, true, Weight, IsItalic));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An instance of <see cref="FontDetails"/> with the same properties as the current instance,
|
||||
/// but with the <see cref="IsBold"/> property set to <c>true</c>.
|
||||
/// </summary>
|
||||
public FontDetails AsBold()
|
||||
{
|
||||
return _bold.Value;
|
||||
}
|
||||
|
||||
internal static FontDetails GetDefault(string? name = null) => new FontDetails(name ?? string.Empty,
|
||||
@@ -51,7 +64,7 @@
|
||||
DefaultWeight,
|
||||
false);
|
||||
|
||||
internal FontDetails WithName(string name) => name != null
|
||||
internal FontDetails WithName(string? name) => name is not null
|
||||
? new FontDetails(name, IsBold, Weight, IsItalic)
|
||||
: this;
|
||||
|
||||
|
Reference in New Issue
Block a user