예제 #1
0
 private static ILineFormatter CreateLineFormatter(string documentLine, int maxWidth)
 {
     if (documentLine.ToLower().StartsWith("<l"))
     {
         return(new LeftAlignFormatter(documentLine, maxWidth));
     }
     if (documentLine.ToLower().StartsWith("<r"))
     {
         return(new RightAlignFormatter(documentLine, maxWidth));
     }
     if (documentLine.ToLower().StartsWith("<c"))
     {
         return(new CenterAlignFormatter(documentLine, maxWidth));
     }
     if (documentLine.ToLower().StartsWith("<f>"))
     {
         return(new HorizontalRuleFormatter(documentLine, maxWidth));
     }
     if (documentLine.ToLower().StartsWith("<t"))
     {
         return(new TitleFormatter(documentLine, maxWidth));
     }
     if (documentLine.ToLower().StartsWith("<bx"))
     {
         return(new BoxFormatter(documentLine, maxWidth));
     }
     if (documentLine.ToLower().StartsWith("<j"))
     {
         var fmtr = new JustifyAlignFormatter(documentLine, maxWidth, true, _lastColumnWidths);
         _lastColumnWidths = fmtr.GetColumnWidths();
         return(fmtr);
     }
     return(new GenericFormatter(documentLine, maxWidth));
 }
예제 #2
0
 private static ILineFormatter GetJustifiedFormatter(string documentLine, int maxWidth, bool shouldBreak)
 {
     documentLine = documentLine.Replace("<p", "<j");
     documentLine = documentLine.Replace("<P", "<J");
     var match = Regex.Match(documentLine, "<[j|J][^:]+(:[^>]+)>");
     var mt = match.Success ? match.Groups[1].Value : "";
     var ratio = 1d;
     if (!string.IsNullOrEmpty(mt))
     {
         documentLine = documentLine.Replace(mt + ">", ">");
         ratio = Convert.ToDouble(mt.Trim(':'));
     }
     var fmtr = new JustifyAlignFormatter(documentLine, maxWidth, shouldBreak, ratio, _lastColumnWidths);
     _lastColumnWidths = fmtr.GetColumnWidths();
     return fmtr;
 }
예제 #3
0
        private static ILineFormatter GetJustifiedFormatter(string documentLine, int maxWidth, bool shouldBreak)
        {
            documentLine = documentLine.Replace("<p", "<j");
            documentLine = documentLine.Replace("<P", "<J");
            var match = Regex.Match(documentLine, "<[j|J][^:]+(:[^>]+)>");
            var mt    = match.Success ? match.Groups[1].Value : "";
            var ratio = 1d;

            if (!string.IsNullOrEmpty(mt))
            {
                documentLine = documentLine.Replace(mt + ">", ">");
                ratio        = Convert.ToDouble(mt.Trim(':'));
            }
            var fmtr = new JustifyAlignFormatter(documentLine, maxWidth, shouldBreak, ratio, _lastColumnWidths);

            _lastColumnWidths = fmtr.GetColumnWidths();
            return(fmtr);
        }
예제 #4
0
 private static ILineFormatter CreateLineFormatter(string documentLine, int maxWidth)
 {
     if (documentLine.ToLower().StartsWith("<l"))
         return new LeftAlignFormatter(documentLine, maxWidth);
     if (documentLine.ToLower().StartsWith("<r"))
         return new RightAlignFormatter(documentLine, maxWidth);
     if (documentLine.ToLower().StartsWith("<c"))
         return new CenterAlignFormatter(documentLine, maxWidth);
     if (documentLine.ToLower().StartsWith("<f>"))
         return new HorizontalRuleFormatter(documentLine, maxWidth);
     if (documentLine.ToLower().StartsWith("<t"))
         return new TitleFormatter(documentLine, maxWidth);
     if (documentLine.ToLower().StartsWith("<bx"))
         return new BoxFormatter(documentLine, maxWidth);
     if (documentLine.ToLower().StartsWith("<j"))
     {
         var fmtr = new JustifyAlignFormatter(documentLine, maxWidth, true, _lastColumnWidths);
         _lastColumnWidths = fmtr.GetColumnWidths();
         return fmtr;
     }
     return new GenericFormatter(documentLine, maxWidth);
 }
예제 #5
0
        public void UnicodeText_CanJustify_TextLengthHandled()
        {
            var str = "<j>ไม่เอาเห็ด|1";
            var formatter = new JustifyAlignFormatter(str, 12, false, 0);
            var r = formatter.GetFormattedLine();

            Assert.AreEqual("ไม่เอาเห็ด   1", r);
        }
예제 #6
0
 public void UnicodeText_CanJustifyMultipleParts_TextLengthHandled7()
 {
     var str = "<j>ไม่เอาเห็ด| Blah| 2";
     var formatter = new JustifyAlignFormatter(str, 12, false, 0);
     var r = formatter.GetFormattedLine();
     Assert.AreEqual("ไม่เอา Blah 2", r);
 }
예제 #7
0
 public void Justification_CanKeepTrailingBlank_TrailingBlanksShouldKeep()
 {
     var str = "<j>   *Test|1";
     var formatter = new JustifyAlignFormatter(str, 15, false, 0);
     var r = formatter.GetFormattedLine();
     Assert.AreEqual("   *Test      1", r);
 }