private bool HorizontalAlignmentsAreEqual(Cell cell, Cell firstRowCell, bool autoJustify)
        {
            var cellAlignment = GetHorizontalAlignment(cell, autoJustify);
              var firstRowCellAlignment = GetHorizontalAlignment(firstRowCell, autoJustify);

              return cellAlignment == firstRowCellAlignment;
        }
        protected Dictionary<string, BorderInformation.BorderStyleEnum> GetRuleRangesFromTo(Row row, Cell.BorderPositionEnum borderPosition)
        {
            var borderIsSet = GetBorderSet(row, borderPosition);
              var columnCount = row.Columns.Count;

              Dictionary<string, BorderInformation.BorderStyleEnum> ranges = new Dictionary<string, BorderInformation.BorderStyleEnum>();
              if (borderIsSet.Count == 1)
              {
            ranges.Add(borderIsSet.First().Key + "-" + columnCount, borderIsSet.First().Value);
            return ranges;
              }

              for (int i = 0; i < borderIsSet.Count; i++)
              {
            if (borderIsSet.ElementAt(i).Value != BorderInformation.BorderStyleEnum.None)
            {
              if (i + 1 < borderIsSet.Count)
            ranges.Add(borderIsSet.ElementAt(i).Key + "-" + (borderIsSet.ElementAt(i + 1).Key - 1), borderIsSet.ElementAt(i).Value);
              else
            ranges.Add(borderIsSet.ElementAt(i).Key + "-" + columnCount, borderIsSet.ElementAt(i).Value);
            }
              }

              return ranges;
        }
 public void EmphTextStylerFactory_WithItalic_GetsItalicTextStyler()
 {
     var cell = new Cell {Text = "test", TextEmphasis = new List<Cell.EmphasisEnum> {Cell.EmphasisEnum.Italic}};
       var emphTextStylers = _emphTextStylerFactory.GetTextStylers(cell);
       Assert.That(emphTextStylers.Count, Is.EqualTo(1));
       Assert.That(emphTextStylers.First(), Is.TypeOf<ItalicTextStyler>());
 }
        public string Format(Cell cell)
        {
            var formattedCellValue = cell.Text;
              formattedCellValue = EmphasiseCellValue(cell, formattedCellValue);

              return formattedCellValue;
        }
        private static Dictionary<Row, HorizontalRuleStyler> GetHorizontalRuleStyler(Row row, Cell.BorderPositionEnum borderPosition)
        {
            if (row.Columns.Count > 0)
              {
            var ruleStylers = new Dictionary<Row, HorizontalRuleStyler>();

            var dottedStyles = new[] { BorderInformation.BorderStyleEnum.Dotted };
            var dottedPreparedRow = GetPreparedRow(row.Clone(), borderPosition, dottedStyles);
            if (ContainsBorderStyle(dottedPreparedRow.Columns, borderPosition, dottedStyles))
              ruleStylers.Add(dottedPreparedRow, new DottedRuleStyler());

            var dashedStyles = new[] {BorderInformation.BorderStyleEnum.Dashed};
            var dashedPreparedRow = GetPreparedRow(row.Clone(), borderPosition, dashedStyles);
            if (ContainsBorderStyle(dashedPreparedRow.Columns, borderPosition, dashedStyles))
              ruleStylers.Add(dashedPreparedRow, new DashedRuleStyler());

            var solidStyles = new[]{BorderInformation.BorderStyleEnum.Solid, BorderInformation.BorderStyleEnum.DoubleLineSolid};
            var solidPreparedRow = GetPreparedRow(row.Clone(), borderPosition, solidStyles);
            if (ContainsBorderStyle(solidPreparedRow.Columns, borderPosition, solidStyles))
              ruleStylers.Add(solidPreparedRow, new SolidRuleStyler());

            return ruleStylers;
              }

              throw new ArgumentException("specified row has no columns");
        }
 public static Cell DefineHorizontalAlignmentBasedOnDataType(Cell cell)
 {
     if (cell.Text.IsNumericCurrentCulture())
     cell.HorizontalAlignment = Cell.HorizontalAlignmentEnum.Right;
       else
     cell.HorizontalAlignment = Cell.HorizontalAlignmentEnum.Left;
       return cell;
 }
 private Cell.HorizontalAlignmentEnum GetHorizontalAlignment(Cell cell, bool autoJustify)
 {
     if (cell.HorizontalAlignment == Cell.HorizontalAlignmentEnum.General && autoJustify)
       {
     return JustifierFactory.DefineHorizontalAlignmentBasedOnDataType(cell).HorizontalAlignment;
       }
       return cell.HorizontalAlignment;
 }
 private string JustifyCellValue(Cell cell, bool autoJustify, bool useBorders, Cell firstRowCell, string value)
 {
     if (!HorizontalAlignmentsAreEqual(cell, firstRowCell, autoJustify))
       {
     var justifier = JustifierFactory.GetJustifier(cell, autoJustify);
     return justifier.Justify(value, useBorders);
       }
       return value;
 }
 public void BoldAndItalicCombinedTextStyler_WithExtraSpecified_ReturnsFormattedValue()
 {
     var cell = new Cell
       {
     Text = "text",
     TextEmphasis = new List<Cell.EmphasisEnum> {Cell.EmphasisEnum.Bold, Cell.EmphasisEnum.Italic}
       };
       Assert.That(_emphTextStylerFactory.GetCombinedTextStyle(cell, "value"), Is.EqualTo(@"***value***"));
 }
        private static Row GetPreparedRow(Row row, Cell.BorderPositionEnum borderPosition, IEnumerable<BorderInformation.BorderStyleEnum> borderStyles)
        {
            foreach (var column in row.Columns)
              {
            if (!column.Borders.ContainsKey(borderPosition))
              column.Borders.Add(borderPosition, new BorderInformation {BorderStyle = BorderInformation.BorderStyleEnum.None});

            if(!borderStyles.Contains(column.Borders[borderPosition].BorderStyle))
              column.Borders[borderPosition].BorderStyle = BorderInformation.BorderStyleEnum.None;
              }
              return row;
        }
        public static Justifier GetJustifier(Cell cell, bool autoJustify)
        {
            if(cell.HorizontalAlignment == Cell.HorizontalAlignmentEnum.General && autoJustify)
            cell = DefineHorizontalAlignmentBasedOnDataType(cell);

              if(cell.HorizontalAlignment == Cell.HorizontalAlignmentEnum.Right)
              {
            return new RightJustifier();
              }
              if (cell.HorizontalAlignment == Cell.HorizontalAlignmentEnum.Center)
              {
            return new CenterJustifier();
              }
              return new LeftJustifier();
        }
        public string Format(Cell cell, IExtendedLatexFeaturesModel featuresModel, Cell firstRowCell)
        {
            var formattedCellValue = cell.Text;

              if (featuresModel.UseColors)
              {
            formattedCellValue = ColorizeTextInCell(cell, formattedCellValue);
            formattedCellValue = ColorizeCellBackground(cell, formattedCellValue);
              }
              formattedCellValue = EmphasiseCellValue(cell, formattedCellValue);
              formattedCellValue = JustifyCellValue(cell, featuresModel.AutoJustify, featuresModel.UseBorders, firstRowCell, formattedCellValue);

              // TODO: some more formatting - keep reihenfolge in mind (for LaTeX)

              return formattedCellValue;
        }
        public virtual IList<EmphTextStyler> GetTextStylers(Cell cell)
        {
            if (cell.TextEmphasis == null || !cell.TextEmphasis.Any())
              {
            return Enumerable.Empty<EmphTextStyler>().ToList();
              }

              var textStylers = new List<EmphTextStyler>();
              foreach (var emphasisEnum in cell.TextEmphasis)
              {
            if (emphasisEnum == Cell.EmphasisEnum.Bold)
              textStylers.Add(GetBoldTextStyler());
            if (emphasisEnum == Cell.EmphasisEnum.Italic)
              textStylers.Add(GetItalicTextStyler());
              }
              return textStylers;
        }
        private Dictionary<int, BorderInformation.BorderStyleEnum> GetBorderSet(Row row, Cell.BorderPositionEnum borderPosition)
        {
            Dictionary<int, BorderInformation.BorderStyleEnum> borderIsSet = new Dictionary<int, BorderInformation.BorderStyleEnum>();
              int i = 1;
              foreach (var cell in row.Columns)
              {
            if (BorderIsSetAndNoRangeAdded(cell, borderPosition, borderIsSet) ||
              BorderNotSetAndAndNonEmptyLastCellBorder(cell, borderPosition, borderIsSet) ||
              BorderIsSetAndEmptyLastCellBorder(cell, borderPosition, borderIsSet) ||
              LastBorderDiffersFromActualBorder(cell, borderPosition, borderIsSet))
            {
              borderIsSet.Add(i, cell.Borders[borderPosition].BorderStyle);
            }
            i++;
              }

              return borderIsSet;
        }
 private string EmphasiseCellValue(Cell cell, string value)
 {
     return new EmphTextStylerFactory().GetCombinedTextStyle(cell, value);
 }
 public void JustifierFactory_WithoutAutoJustifyAndNumeric_ReturnsLeftJustifier()
 {
     var cell = new Cell { Text = "123" };
       Assert.That(JustifierFactory.GetJustifier(cell, autoJustify: false), Is.TypeOf<LeftJustifier>());
 }
 public string Format(Cell cell, IExtendedLatexFeaturesModel featuresModel, Cell firstRowCell)
 {
     return cell.Text;
 }
 public void JustifierFactory_WithCenterHorizontalAlignmentAndNoAutoJustify_ReturnsCenterJustifier()
 {
     var cell = new Cell { Text = "abc", HorizontalAlignment = Cell.HorizontalAlignmentEnum.Center };
       Assert.That(JustifierFactory.GetJustifier(cell, autoJustify:false), Is.TypeOf<CenterJustifier>());
 }
 public void JustifierFactory_WithNumeric_ReturnsRightHorizontalAlignment()
 {
     var cell = new Cell {Text = "123"};
       Assert.That(JustifierFactory.DefineHorizontalAlignmentBasedOnDataType(cell).HorizontalAlignment, Is.EqualTo(Cell.HorizontalAlignmentEnum.Right));
 }
 private string PrepareCellValue(Cell cell)
 {
     return _cellFormatter.Format(cell);
 }
 public void JustifierFactory_WithAutoJustifyAndNumeric_ReturnsRightJustifier()
 {
     var cell = new Cell { Text = "123" };
       Assert.That(JustifierFactory.GetJustifier(cell, autoJustify:true), Is.TypeOf<RightJustifier>());
 }
 private string GetHorizontalRule(Row row, Cell.BorderPositionEnum borderPosition)
 {
     return GetRuleCommand(GetRuleRangesFromTo(row, borderPosition));
 }
 private string PrepareCellValue(Cell cell, Cell firstRowCell)
 {
     cell.Text = ReplaceConstantsIfSet(cell.Text);
       var cellValue = _cellFormatter.Format(cell, _extendedFeatures, firstRowCell);
       return cellValue;
 }
 public string GetCombinedTextStyle(Cell cell, string value = null)
 {
     return new CombinedTextStyler(GetTextStylers(cell)).Style(value ?? cell.Text);
 }
 private static bool LastBorderDiffersFromActualBorder(Cell cell, Cell.BorderPositionEnum borderPosition,
                                                   Dictionary<int, BorderInformation.BorderStyleEnum> borderIsSet)
 {
     return cell.Borders[borderPosition].BorderStyle != BorderInformation.BorderStyleEnum.None &&
      borderIsSet.Last().Value != cell.Borders[borderPosition].BorderStyle;
 }
 private static bool BorderNotSetAndAndNonEmptyLastCellBorder(Cell cell, Cell.BorderPositionEnum borderPosition, Dictionary<int, BorderInformation.BorderStyleEnum> borderIsSet)
 {
     return cell.Borders[borderPosition].BorderStyle == BorderInformation.BorderStyleEnum.None && borderIsSet.Count > 0 && borderIsSet.Last().Value != BorderInformation.BorderStyleEnum.None;
 }
 public void BoldAndItalicCombinedTextStyler_ReturnsFormattedValue()
 {
     var cell = new Cell { Text = "text", TextEmphasis = new List<Cell.EmphasisEnum> { Cell.EmphasisEnum.Bold, Cell.EmphasisEnum.Italic } };
       Assert.That(_emphTextStylerFactory.GetCombinedTextStyle(cell), Is.EqualTo(@"\textit{\textbf{text}}"));
 }
 public void EmphTextStylerFactory_WithNoEmph_GetsEmptyList()
 {
     var cell = new Cell {Text = "test"};
       var emphTextStylers = _emphTextStylerFactory.GetTextStylers(cell);
       Assert.That(emphTextStylers.Any(), Is.False);
 }
 public void EmphTextStylerFactory_WithNoneEmphasisEnum_GetsEmptyList()
 {
     var cell = new Cell {Text = "test", TextEmphasis = new List<Cell.EmphasisEnum> {Cell.EmphasisEnum.None}};
       var emphTextStylers = _emphTextStylerFactory.GetTextStylers(cell);
       Assert.That(emphTextStylers.Any(), Is.False);
 }
 private static bool BorderIsSetAndNoRangeAdded(Cell cell, Cell.BorderPositionEnum borderPosition, Dictionary<int, BorderInformation.BorderStyleEnum> borderIsSet)
 {
     return cell.Borders[borderPosition].BorderStyle != BorderInformation.BorderStyleEnum.None && borderIsSet.Count == 0;
 }