From 20d3cc9066c77e3877769c9de9ba3f644d271da9 Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Tue, 23 May 2023 19:22:00 +0100 Subject: [PATCH] tidy up during investigation #600 --- src/UglyToad.PdfPig/Content/Pages.cs | 4 +- .../Operations/TextShowing/ShowText.cs | 220 +++++++++--------- 2 files changed, 112 insertions(+), 112 deletions(-) diff --git a/src/UglyToad.PdfPig/Content/Pages.cs b/src/UglyToad.PdfPig/Content/Pages.cs index 1066a991..1e96aaf8 100644 --- a/src/UglyToad.PdfPig/Content/Pages.cs +++ b/src/UglyToad.PdfPig/Content/Pages.cs @@ -1,6 +1,5 @@ namespace UglyToad.PdfPig.Content { - using Annotations; using Core; using Outline; using System; @@ -69,7 +68,8 @@ { pageTreeMembers.Rotation = rotateToken.Int; } - } + } + var page = pageFactory.Create( pageNumber, pageNode.NodeDictionary, diff --git a/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/ShowText.cs b/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/ShowText.cs index 11e589b1..c54a23bc 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/ShowText.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/ShowText.cs @@ -1,117 +1,117 @@ -namespace UglyToad.PdfPig.Graphics.Operations.TextShowing -{ - using System.IO; - using PdfPig.Core; - using Util.JetBrains.Annotations; - - /// - /// - /// Show a text string - /// - /// - /// The input is a sequence of character codes to be shown as glyphs. - /// - /// Generally each byte represents a single character code, however starting in version 1.2+ - /// a composite font might use multi-byte character codes to map to glyphs. - /// For these composite fonts, the of the font defines the mapping from code to glyph. - /// - /// - /// The grouping of character codes in arguments to this operator does not have any impact on the meaning; for example:
- /// (Abc) Tj is equivalent to (A) Tj (b) Tj (c) Tj
- /// However grouping character codes makes the document easier to search and extract text from. - ///
- ///
- public class ShowText : IGraphicsStateOperation - { - /// - /// The symbol for this operation in a stream. - /// - public const string Symbol = "Tj"; - - /// - public string Operator => Symbol; - - /// - /// The text string to show. - /// - [CanBeNull] - public string Text { get; } - - /// - /// The bytes of the string to show. - /// - [CanBeNull] - public byte[] Bytes { get; } - - /// - /// Create a new . - /// - public ShowText(string text) - { - Text = text; - } - - /// - /// Create a new . - /// - public ShowText(byte[] hexBytes) - { - Bytes = hexBytes; - } - - /// - public void Run(IOperationContext operationContext) - { - var input = new ByteArrayInputBytes(Text != null ? OtherEncodings.StringAsLatin1Bytes(Text) : Bytes); - - operationContext.ShowText(input); - } - - string EscapeText(string text) +namespace UglyToad.PdfPig.Graphics.Operations.TextShowing +{ + using System.IO; + using PdfPig.Core; + using Util.JetBrains.Annotations; + + /// + /// + /// Show a text string + /// + /// + /// The input is a sequence of character codes to be shown as glyphs. + /// + /// Generally each byte represents a single character code, however starting in version 1.2+ + /// a composite font might use multi-byte character codes to map to glyphs. + /// For these composite fonts, the of the font defines the mapping from code to glyph. + /// + /// + /// The grouping of character codes in arguments to this operator does not have any impact on the meaning; for example:
+ /// (Abc) Tj is equivalent to (A) Tj (b) Tj (c) Tj
+ /// However grouping character codes makes the document easier to search and extract text from. + ///
+ ///
+ public class ShowText : IGraphicsStateOperation + { + /// + /// The symbol for this operation in a stream. + /// + public const string Symbol = "Tj"; + + /// + public string Operator => Symbol; + + /// + /// The text string to show. + /// + [CanBeNull] + public string Text { get; } + + /// + /// The bytes of the string to show. + /// + [CanBeNull] + public byte[] Bytes { get; } + + /// + /// Create a new . + /// + public ShowText(string text) { - if (text is null) return null; - // Fix Issue 350 from PDF Spec 1.7 (page 408) on handling 'special characters' of '(', ')' and '\'. - - // The strings must conform to the syntax for string objects. + Text = text; + } + + /// + /// Create a new . + /// + public ShowText(byte[] hexBytes) + { + Bytes = hexBytes; + } + + /// + public void Run(IOperationContext operationContext) + { + var input = new ByteArrayInputBytes(Text != null ? OtherEncodings.StringAsLatin1Bytes(Text) : Bytes); + + operationContext.ShowText(input); + } + + string EscapeText(string text) + { + if (text is null) return null; + // Fix Issue 350 from PDF Spec 1.7 (page 408) on handling 'special characters' of '(', ')' and '\'. + + // The strings must conform to the syntax for string objects. // When a string is written by enclosing the data in parentheses, - // bytes whose values are the same as those - // of the ASCII characters left parenthesis (40), right parenthesis (41), and backslash (92) + // bytes whose values are the same as those + // of the ASCII characters left parenthesis (40), right parenthesis (41), and backslash (92) // must be preceded by a backslash character. // All other byte values between 0 and 255 may be used in a string object. - // These rules apply to each individual byte in a string object, whether the string is interpreted by the text-showing operators - // as single-byte or multiple-byte character codes. - - // Note: order of replacing is important. Replace slash first before brackets. - text = text.Replace(@"\", @"\\)"); // Escape any slash '\' -> '\\' - text = text.Replace("(", @"\("); // Escape any open brackets '(' -> '\(' + // These rules apply to each individual byte in a string object, whether the string is interpreted by the text-showing operators + // as single-byte or multiple-byte character codes. + + // Note: order of replacing is important. Replace slash first before brackets. + text = text.Replace(@"\", @"\\)"); // Escape any slash '\' -> '\\' + text = text.Replace("(", @"\("); // Escape any open brackets '(' -> '\(' text = text.Replace(")", @"\)"); // Escape any close brackets ')' -> '\)' - return text; - } - - /// - public void Write(Stream stream) - { - - if (Bytes != null) - { - stream.WriteHex(Bytes); - } - else - { - var EscapedText = EscapeText(Text); // escape '(', ')' or '\' - stream.WriteText($"({EscapedText})"); - } - - stream.WriteWhiteSpace(); - stream.WriteText(Symbol); - stream.WriteNewLine(); - } - - /// - public override string ToString() - { - return $"{Text} {Symbol}"; - } - } + return text; + } + + /// + public void Write(Stream stream) + { + + if (Bytes != null) + { + stream.WriteHex(Bytes); + } + else + { + var escapedText = EscapeText(Text); // escape '(', ')' or '\' + stream.WriteText($"({escapedText})"); + } + + stream.WriteWhiteSpace(); + stream.WriteText(Symbol); + stream.WriteNewLine(); + } + + /// + public override string ToString() + { + return $"{Text} {Symbol}"; + } + } } \ No newline at end of file