internal static string ToSerializedValue(this TextSplitMode value) { switch (value) { case TextSplitMode.Pages: return("pages"); case TextSplitMode.Sentences: return("sentences"); } return(null); }
public static string ToSerialString(this TextSplitMode value) => value switch {
//------------------------------------------------------------------------------------------22.08.2006 /// <summary>Gets a line of text with a maximal width from the specified string (metric version).</summary> /// <param name="sText">Text</param> /// <param name="rWidthMaxMM">Maximal width of the text in millimeters</param> /// <param name="iStart">Start position in sText</param> /// <param name="textSplitMode">Text split mode</param> /// <returns>Text with the specified maximal width</returns> /// <remarks> /// The reference parameter <paramref name="iStart"/> must be initialized with the start position. /// After the call, it contains the new start position that can be used for a call of this method for the next line of text. /// </remarks> /// <example>Multiline text sample in <see cref="FontProp.sGetTextLine"/></example> public String sGetTextLineMM(String sText, Double rWidthMaxMM, ref Int32 iStart, TextSplitMode textSplitMode) { return(sGetTextLine(sText, RT.rPointFromMM(rWidthMaxMM), ref iStart, textSplitMode)); }
//------------------------------------------------------------------------------------------22.08.2006 /// <summary>Gets a line of text with a maximal width from the specified string.</summary> /// <param name="sText">Text</param> /// <param name="rWidthMax">Maximal width of the text in points (1/72 inch)</param> /// <param name="iStart">Start position in sText</param> /// <param name="textSplitMode">Text split mode</param> /// <returns>Text with the specified maximal width</returns> /// <remarks> /// The reference parameter <paramref name="iStart"/> must be initialized with the start position. /// After the call, it contains the new start position that can be used for a call of this method for the next line of text. /// </remarks> /// <example>Multiline text sample: /// <code> /// using Root.Reports; /// using System; /// /// public class FontPropSample : Report { /// public static void Main() { /// PdfReport<FontPropSample> pdfReport = new PdfReport<FontPropSample>(); /// pdfReport.View("FontPropSample.pdf"); /// } /// /// protected override void Create() { /// FontDef fontDef = new FontDef(this, FontDef.StandardFont.Helvetica); /// FontProp fontProp = new FontPropMM(fontDef, 15); /// new Page(this); /// String sText = "Once upon a time there was a miller who was poor, but he had a beautiful daughter."; /// Double rY = 20; /// Int32 iStart = 0; /// while (iStart <= sText.Length) { /// String sLine = fontProp.sGetTextLineMM(sText, 170, ref iStart, TextSplitMode.Line); /// page_Cur.AddMM(20, rY, new RepString(fontProp, sLine)); /// rY += fontProp.rLineFeedMM; /// } /// } /// } /// </code> /// </example> public String sGetTextLine(String sText, Double rWidthMax, ref Int32 iStart, TextSplitMode textSplitMode) { return(fontData.sGetTextLine(sText, rWidthMax * 1000.0 / rSizePoint, ref iStart, textSplitMode)); }
private static Skillset CreateTestSkillsetOcrSplitText(OcrSkillLanguage ocrLanguageCode, SplitSkillLanguage splitLanguageCode, TextSplitMode textSplitMode) { var skills = new List <Skill>(); var inputs = new List <InputFieldMappingEntry>() { new InputFieldMappingEntry { Name = "url", Source = "/document/url" }, new InputFieldMappingEntry { Name = "queryString", Source = "/document/queryString" } }; var outputs = new List <OutputFieldMappingEntry>() { new OutputFieldMappingEntry { Name = "text", TargetName = "mytext" } }; skills.Add(new OcrSkill(inputs, outputs, "Tested OCR skill", RootPathString) { TextExtractionAlgorithm = TextExtractionAlgorithm.Printed, DefaultLanguageCode = ocrLanguageCode }); var inputs1 = new List <InputFieldMappingEntry>() { new InputFieldMappingEntry { Name = "text", Source = "/document/mytext" } }; var outputs1 = new List <OutputFieldMappingEntry>() { new OutputFieldMappingEntry { Name = "textItems", TargetName = "myTextItems" } }; skills.Add(new SplitSkill(inputs1, outputs1, "Tested Split skill", RootPathString) { TextSplitMode = textSplitMode, DefaultLanguageCode = splitLanguageCode }); return(new Skillset("testskillset", "Skillset for testing", skills)); }
/// <summary>Gets a text line for the specified width.</summary> /// <param name="sText">Text</param> /// <param name="rWidthMax">Width</param> /// <param name="iStart">Start position in sText</param> /// <param name="textSplitMode">Text split mode</param> /// <returns>Line of text</returns> internal String sGetTextLine(String sText, Double rWidthMax, ref Int32 iStart, TextSplitMode textSplitMode) { if (iStart > sText.Length) { throw new ReportException("start position out of range"); } if (iStart == sText.Length) { iStart++; return(""); } Int32 iStartCopy = iStart; StringBuilder sb = new StringBuilder(120); Double rWidth = 0; Int32 iPos = iStart; Int32 iResultLength = 0; LastChar lastChar = LastChar.Space; while (true) { Char c = sText[iPos]; iPos++; Double rWidthChar = rGetRawWidth(c); UnicodeCategory unicodeCategory = Char.GetUnicodeCategory(c); switch (unicodeCategory) { case UnicodeCategory.Control: { // control character if (c == '\n') { goto case UnicodeCategory.LineSeparator; } if (lastChar != LastChar.Space) { iResultLength = sb.Length; lastChar = LastChar.Space; } iStart = iPos; break; } case UnicodeCategory.LineSeparator: case UnicodeCategory.ParagraphSeparator: { iResultLength = sb.Length; iStart = iPos; goto EndLoop; } case UnicodeCategory.ConnectorPunctuation: // connects two characters case UnicodeCategory.EnclosingMark: // nonspacing combining character that surrounds all previous characters up to and including a base character case UnicodeCategory.Format: // not normally rendered but affects the layout of text or the operation of text processes case UnicodeCategory.ModifierLetter: // free-standing spacing character that indicates modifications of a preceding letter case UnicodeCategory.ModifierSymbol: // indicates modifications of surrounding characters case UnicodeCategory.NonSpacingMark: // indicates modifications of a base character case UnicodeCategory.PrivateUse: // private-use character with unicode value in the range U+E000 through U+F8FF case UnicodeCategory.SpacingCombiningMark: // indicates modifications of a base character and affects the width of the glyph for that base character case UnicodeCategory.Surrogate: { // high-surrogate or a low-surrogate with code values in the range U+D800 through U+DFFF break; } case UnicodeCategory.SpaceSeparator: { // space if (lastChar != LastChar.Space) { iResultLength = sb.Length; lastChar = LastChar.Space; } rWidth += rWidthChar; sb.Append(c); iStart = iPos; break; } case UnicodeCategory.ClosePunctuation: // separator on this line: )]} case UnicodeCategory.DashPunctuation: // - case UnicodeCategory.FinalQuotePunctuation: { rWidth += rWidthChar; if (rWidth > rWidthMax) { iPos--; goto EndLoop; } sb.Append(c); lastChar = LastChar.SeparatorAtEndOfLine; break; } case UnicodeCategory.CurrencySymbol: // separator for next line: € case UnicodeCategory.InitialQuotePunctuation: // opening or initial quotation mark case UnicodeCategory.OpenPunctuation: { // ([{ if (lastChar == LastChar.SeparatorAtEndOfLine || lastChar == LastChar.Word) { iResultLength = sb.Length; iStart = iPos - 1; } rWidth += rWidthChar; if (rWidth > rWidthMax) { iPos--; goto EndLoop; } sb.Append(c); lastChar = LastChar.SeparatorAtStartOfLine; break; } case UnicodeCategory.OtherPunctuation: { // ., rWidth += rWidthChar; if (rWidth > rWidthMax) { iPos--; goto EndLoop; } sb.Append(c); lastChar = LastChar.Word; break; } case UnicodeCategory.DecimalDigitNumber: // character case UnicodeCategory.LetterNumber: case UnicodeCategory.LowercaseLetter: case UnicodeCategory.MathSymbol: // + = case UnicodeCategory.OtherLetter: case UnicodeCategory.OtherNotAssigned: case UnicodeCategory.UppercaseLetter: case UnicodeCategory.TitlecaseLetter: { if (lastChar == LastChar.SeparatorAtEndOfLine) { iResultLength = sb.Length; iStart = iPos; } rWidth += rWidthChar; if (rWidth > rWidthMax) { iPos--; goto EndLoop; } sb.Append(c); lastChar = LastChar.Word; break; } default: { Debug.Fail("unknown unicode category"); break; } } if (iPos >= sText.Length) { iResultLength = sb.Length; iStart = iPos + 1; goto EndLoop; } } EndLoop: if (textSplitMode == TextSplitMode.Truncate) { iStart = sb.Length; return(sb.ToString()); } if (iStart == iStartCopy) { if (sb.Length > 0) { iStart = iPos; return(sb.ToString()); } iStart++; return(sText[iStart - 1].ToString()); } return(sb.ToString(0, iResultLength)); }