예제 #1
0
        public static void AddParagraphProperties(Paragraph paragraph, StringBuilder style)
        {
            AddIndent(paragraph, style);
            AddJustification(paragraph, style);

            AddBorder(paragraph.GetBottomBorder(), "bottom", style);
            AddBorder(paragraph.GetLeftBorder(), "left", style);
            AddBorder(paragraph.GetRightBorder(), "right", style);
            AddBorder(paragraph.GetTopBorder(), "top", style);

            if (paragraph.PageBreakBefore())
            {
                style.Append("break-before:page;");
            }

            style.Append("hyphenate:" + (paragraph.IsAutoHyphenated ? "auto" : "none") + ";");

            if (paragraph.KeepOnPage())
            {
                style.Append("keep-together.within-page:always;");
            }

            if (paragraph.KeepWithNext())
            {
                style.Append("keep-with-next.within-page:always;");
            }
        }
예제 #2
0
 public static void AddIndent(Paragraph paragraph, StringBuilder style)
 {
     AddIndent(style, "text-indent", paragraph.GetFirstLineIndent());
     AddIndent(style, "start-indent", paragraph.GetIndentFromLeft());
     AddIndent(style, "end-indent", paragraph.GetIndentFromRight());
     AddIndent(style, "space-before", paragraph.GetSpacingBefore());
     AddIndent(style, "space-after", paragraph.GetSpacingAfter());
 }
예제 #3
0
 public static void AddJustification(Paragraph paragraph, StringBuilder style)
 {
     String justification = GetJustification(paragraph.GetJustification());
     if (!string.IsNullOrEmpty(justification))
         style.Append("text-align:" + justification + ";");
 }
예제 #4
0
 public static void SetJustification(Paragraph paragraph,
          XmlElement XmlElement)
예제 #5
0
        protected override void ProcessParagraph(HWPFDocumentCore hwpfDocument,
                XmlElement parentFopElement, int currentTableLevel,
                Paragraph paragraph, String bulletText)
        {
            XmlElement block = foDocumentFacade.CreateBlock();
            parentFopElement.AppendChild(block);

            WordToFoUtils.SetParagraphProperties(paragraph, block);

            int charRuns = paragraph.NumCharacterRuns;

            if (charRuns == 0)
            {
                return;
            }

            bool haveAnyText = false;

            if (!string.IsNullOrEmpty(bulletText))
            {
                XmlElement inline = foDocumentFacade.CreateInline();
                block.AppendChild(inline);

                XmlText textNode = foDocumentFacade.CreateText(bulletText);
                inline.AppendChild(textNode);

                haveAnyText |= bulletText.Trim().Length != 0;
            }

            haveAnyText = ProcessCharacters(hwpfDocument, currentTableLevel, paragraph, block);

            if (!haveAnyText)
            {
                XmlElement leader = foDocumentFacade.CreateLeader();
                block.AppendChild(leader);
            }

            WordToFoUtils.CompactInlines(block);
            return;
        }
예제 #6
0
        protected override void ProcessParagraph(HWPFDocumentCore wordDocument, XmlElement parentElement, int currentTableLevel, Paragraph paragraph, string bulletText)
        {
            XmlElement pElement = htmlDocumentFacade.CreateParagraph();
            parentElement.AppendChild(pElement);

            StringBuilder style = new StringBuilder();
            WordToHtmlUtils.AddParagraphProperties(paragraph, style);

            int charRuns = paragraph.NumCharacterRuns;

            if (charRuns == 0)
            {
                return;
            }

            {
                String pFontName;
                int pFontSize;
                CharacterRun characterRun = paragraph.GetCharacterRun(0);
                if (characterRun != null)
                {
                    Triplet triplet = GetCharacterRunTriplet(characterRun);
                    pFontSize = characterRun.GetFontSize() / 2;
                    pFontName = triplet.fontName;
                    WordToHtmlUtils.AddFontFamily(pFontName, style);
                    WordToHtmlUtils.AddFontSize(pFontSize, style);
                }
                else
                {
                    pFontSize = -1;
                    pFontName = string.Empty;
                }
                blocksProperies.Push(new BlockProperies(pFontName, pFontSize));
            }
            try
            {
                if (!string.IsNullOrEmpty(bulletText))
                {
                    XmlText textNode = htmlDocumentFacade.CreateText(bulletText);
                    pElement.AppendChild(textNode);
                }

                ProcessCharacters(wordDocument, currentTableLevel, paragraph, pElement);
            }
            finally
            {
                blocksProperies.Pop();
            }

            if (style.Length > 0)
                htmlDocumentFacade.AddStyleClass(pElement, "p", style.ToString());

            WordToHtmlUtils.CompactSpans(pElement);
        }
예제 #7
0
 public static void SetIndent(Paragraph paragraph, XmlElement block)
 {
     if (paragraph.GetFirstLineIndent() != 0)
     {
         block.SetAttribute(
                 "text-indent",
                 (paragraph.GetFirstLineIndent() / TWIPS_PER_PT).ToString() + "pt");
     }
     if (paragraph.GetIndentFromLeft() != 0)
     {
         block.SetAttribute(
                 "start-indent",
                 (paragraph.GetIndentFromLeft() / TWIPS_PER_PT).ToString() + "pt");
     }
     if (paragraph.GetIndentFromRight() != 0)
     {
         block.SetAttribute(
                 "end-indent",
                 (paragraph.GetIndentFromRight() / TWIPS_PER_PT).ToString() + "pt");
     }
     if (paragraph.GetSpacingBefore() != 0)
     {
         block.SetAttribute(
                 "space-before",
                 (paragraph.GetSpacingBefore() / TWIPS_PER_PT).ToString() + "pt");
     }
     if (paragraph.GetSpacingAfter() != 0)
     {
         block.SetAttribute("space-after",
                 (paragraph.GetSpacingAfter() / TWIPS_PER_PT) + "pt");
     }
 }
예제 #8
0
        public static void SetParagraphProperties(Paragraph paragraph, XmlElement block)
        {
            SetIndent(paragraph, block);
            SetJustification(paragraph, block);

            SetBorder(block, paragraph.GetBottomBorder(), "bottom");
            SetBorder(block, paragraph.GetLeftBorder(), "left");
            SetBorder(block, paragraph.GetRightBorder(), "right");
            SetBorder(block, paragraph.GetTopBorder(), "top");

            if (paragraph.PageBreakBefore())
            {
                block.SetAttribute("break-before", "page");
            }

            block.SetAttribute("hyphenate", paragraph.IsAutoHyphenated.ToString());

            if (paragraph.KeepOnPage())
            {
                block.SetAttribute("keep-together.within-page", "always");
            }

            if (paragraph.KeepWithNext())
            {
                block.SetAttribute("keep-with-next.within-page", "always");
            }

            block.SetAttribute("linefeed-treatment", "preserve");
            block.SetAttribute("white-space-collapse", "false");
        }
예제 #9
0
 public static void SetJustification(Paragraph paragraph,
          XmlElement XmlElement)
 {
     String justification = GetJustification(paragraph.GetJustification());
     if (!string.IsNullOrEmpty(justification))
         XmlElement.SetAttribute("text-align", justification);
 }
예제 #10
0
        public static String GetBulletText(ListTables listTables,
            Paragraph paragraph, int listId)
        {
            ListLevel listLevel = listTables.GetLevel(listId,
                    paragraph.GetIlvl());

            if (listLevel.GetNumberText() == null)
                return string.Empty;

            StringBuilder bulletBuffer = new StringBuilder();
            char[] xst = listLevel.GetNumberText().ToCharArray();
            foreach (char element in xst)
            {
                if (element < 9)//todo:review_antony
                {
                    ListLevel numLevel = listTables.GetLevel(listId, element);

                    int num = numLevel.GetStartAt();
                    bulletBuffer.Append(NumberFormatter.GetNumber(num,
                            listLevel.GetNumberFormat()));

                    if (numLevel == listLevel)
                    {
                        numLevel.SetStartAt(numLevel.GetStartAt() + 1);
                    }

                }
                else
                {
                    bulletBuffer.Append(element);
                }
            }

            byte follow = listLevel.GetTypeOfCharFollowingTheNumber();
            switch (follow)
            {
                case 0:
                    bulletBuffer.Append("\t");
                    break;
                case 1:
                    bulletBuffer.Append(" ");
                    break;
                default:
                    break;
            }

            return bulletBuffer.ToString();
        }
예제 #11
0
 protected override void ProcessParagraph(HWPFDocumentCore wordDocument,
         XmlElement parentElement, int currentTableLevel, Paragraph paragraph,
         String bulletText)
 {
     XmlElement pElement = textDocumentFacade.CreateParagraph();
     pElement.AppendChild(textDocumentFacade.CreateText(bulletText));
     ProcessCharacters(wordDocument, currentTableLevel, paragraph, pElement);
     pElement.AppendChild(textDocumentFacade.CreateText("\n"));
     parentElement.AppendChild(pElement);
 }
예제 #12
0
        private void initCells()
        {
            if (_cellsFound)
            {
                return;
            }

            short expectedCellsCount = _tprops.GetItcMac();

            int lastCellStart      = 0;
            List <TableCell> cells = new List <TableCell>(
                expectedCellsCount + 1);

            for (int p = 0; p < NumParagraphs; p++)
            {
                Paragraph paragraph = GetParagraph(p);
                String    s         = paragraph.Text;

                if (((s.Length > 0 && s[s.Length - 1] == TABLE_CELL_MARK) || paragraph
                     .IsEmbeddedCellMark()) &&
                    paragraph.GetTableLevel() == _levelNum)
                {
                    TableCellDescriptor tableCellDescriptor = _tprops.GetRgtc() != null &&
                                                              _tprops.GetRgtc().Length > cells.Count ? _tprops
                                                              .GetRgtc()[cells.Count] : new TableCellDescriptor();
                    short leftEdge = (_tprops.GetRgdxaCenter() != null &&
                                      _tprops.GetRgdxaCenter().Length > cells.Count) ? (short)_tprops
                                     .GetRgdxaCenter()[cells.Count] : (short)0;
                    short rightEdge = (_tprops.GetRgdxaCenter() != null &&
                                       _tprops.GetRgdxaCenter().Length > cells.Count + 1) ? (short)_tprops
                                      .GetRgdxaCenter()[cells.Count + 1] : (short)0;

                    TableCell tableCell = new TableCell(GetParagraph(
                                                            lastCellStart).StartOffset, GetParagraph(p)
                                                        .EndOffset, this, _levelNum, tableCellDescriptor,
                                                        leftEdge, rightEdge - leftEdge);
                    cells.Add(tableCell);
                    lastCellStart = p + 1;
                }
            }

            if (lastCellStart < (NumParagraphs - 1))
            {
                TableCellDescriptor tableCellDescriptor = _tprops.GetRgtc() != null &&
                                                          _tprops.GetRgtc().Length > cells.Count ? _tprops
                                                          .GetRgtc()[cells.Count] : new TableCellDescriptor();
                short leftEdge = _tprops.GetRgdxaCenter() != null &&
                                 _tprops.GetRgdxaCenter().Length > cells.Count ? (short)_tprops
                                 .GetRgdxaCenter()[cells.Count] : (short)0;
                short rightEdge = _tprops.GetRgdxaCenter() != null &&
                                  _tprops.GetRgdxaCenter().Length > cells.Count + 1 ? (short)_tprops
                                  .GetRgdxaCenter()[cells.Count + 1] : (short)0;

                TableCell tableCell = new TableCell(lastCellStart,
                                                    (NumParagraphs - 1), this, _levelNum,
                                                    tableCellDescriptor, leftEdge, rightEdge - leftEdge);
                cells.Add(tableCell);
            }

            if (cells.Count > 0)
            {
                TableCell lastCell = cells[cells.Count - 1];
                if (lastCell.NumParagraphs == 1 &&
                    (lastCell.GetParagraph(0).IsTableRowEnd()))
                {
                    // remove "fake" cell
                    cells.RemoveAt(cells.Count - 1);
                }
            }

            if (cells.Count != expectedCellsCount)
            {
                _tprops.SetItcMac((short)cells.Count);
            }

            _cells      = cells.ToArray();
            _cellsFound = true;
        }