예제 #1
0
        protected override void ProcessEndnoteAutonumbered(HWPFDocument wordDocument,
                                                           int noteIndex, XmlElement block, Range endnoteTextRange)
        {
            String textIndex;// = (internalLinkCounter.incrementAndGet()).ToString();

            lock (objLinkCounter)
            {
                internalLinkCounter++;

                textIndex = internalLinkCounter.ToString();
            }
            String forwardLinkName  = "endnote_" + textIndex;
            String backwardLinkName = "endnote_back_" + textIndex;

            XmlElement forwardLink = foDocumentFacade
                                     .CreateBasicLinkInternal(forwardLinkName);

            forwardLink.AppendChild(CreateNoteInline(textIndex));
            SetId(forwardLink, backwardLinkName);
            block.AppendChild(forwardLink);

            XmlElement endnote      = foDocumentFacade.CreateBlock();
            XmlElement backwardLink = foDocumentFacade
                                      .CreateBasicLinkInternal(backwardLinkName);

            backwardLink.AppendChild(CreateNoteInline(textIndex + " "));
            SetId(backwardLink, forwardLinkName);
            endnote.AppendChild(backwardLink);

            ProcessCharacters(wordDocument, int.MinValue, endnoteTextRange, endnote);

            WordToFoUtils.CompactInlines(endnote);
            this.endnotes.Add(endnote);
        }
예제 #2
0
        protected override void OutputCharacters(XmlElement block, CharacterRun characterRun,
                                                 String text)
        {
            XmlElement inline = foDocumentFacade.CreateInline();

            Triplet triplet = GetCharacterRunTriplet(characterRun);

            if (!string.IsNullOrEmpty(triplet.fontName))
            {
                WordToFoUtils.SetFontFamily(inline, triplet.fontName);
            }
            WordToFoUtils.SetBold(inline, triplet.bold);
            WordToFoUtils.SetItalic(inline, triplet.italic);
            WordToFoUtils.SetFontSize(inline, characterRun.GetFontSize() / 2);
            WordToFoUtils.SetCharactersProperties(characterRun, inline);

            if (IsOutputCharactersLanguage())
            {
                WordToFoUtils.SetLanguage(characterRun, inline);
            }

            block.AppendChild(inline);

            XmlText textNode = foDocumentFacade.CreateText(text);

            inline.AppendChild(textNode);
        }
예제 #3
0
        public static XmlDocument Process(string docFile)
        {
            HWPFDocumentCore  hwpfDocument      = WordToFoUtils.LoadDoc(docFile);
            WordToFoConverter wordToFoConverter = new WordToFoConverter(new XmlDocument());

            wordToFoConverter.ProcessDocument(hwpfDocument);
            return(wordToFoConverter.Document);
        }
예제 #4
0
        protected void ProcessImage(XmlElement currentBlock, bool inlined,
                                    Picture picture, String url)
        {
            XmlElement externalGraphic = foDocumentFacade
                                         .CreateExternalGraphic(url);

            WordToFoUtils.SetPictureProperties(picture, externalGraphic);
            currentBlock.AppendChild(externalGraphic);
        }
예제 #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 ProcessTable(HWPFDocumentCore wordDocument, XmlElement flow,
                                             Table table)
        {
            XmlElement tableHeader = foDocumentFacade.CreateTableHeader();
            XmlElement tableBody   = foDocumentFacade.CreateTableBody();

            int[] tableCellEdges = WordToHtmlUtils.BuildTableCellEdgesArray(table);
            int   tableRows      = table.NumRows;

            int maxColumns = int.MinValue;

            for (int r = 0; r < tableRows; r++)
            {
                maxColumns = Math.Max(maxColumns, table.GetRow(r).NumCells());
            }

            for (int r = 0; r < tableRows; r++)
            {
                TableRow tableRow = table.GetRow(r);

                XmlElement tableRowElement = foDocumentFacade.CreateTableRow();
                WordToFoUtils.SetTableRowProperties(tableRow, tableRowElement);

                // index of current element in tableCellEdges[]
                int currentEdgeIndex = 0;
                int rowCells         = tableRow.NumCells();
                for (int c = 0; c < rowCells; c++)
                {
                    TableCell tableCell = tableRow.GetCell(c);

                    if (tableCell.IsVerticallyMerged() && !tableCell.IsFirstVerticallyMerged())
                    {
                        currentEdgeIndex += getTableCellEdgesIndexSkipCount(table,
                                                                            r, tableCellEdges, currentEdgeIndex, c, tableCell);
                        continue;
                    }

                    XmlElement tableCellElement = foDocumentFacade.CreateTableCell();
                    WordToFoUtils.SetTableCellProperties(tableRow, tableCell,
                                                         tableCellElement, r == 0, r == tableRows - 1, c == 0,
                                                         c == rowCells - 1);

                    int colSpan = GetNumberColumnsSpanned(tableCellEdges,
                                                          currentEdgeIndex, tableCell);
                    currentEdgeIndex += colSpan;

                    if (colSpan == 0)
                    {
                        continue;
                    }

                    if (colSpan != 1)
                    {
                        tableCellElement.SetAttribute("number-columns-spanned", (colSpan).ToString());
                    }

                    int rowSpan = GetNumberRowsSpanned(table, r, c, tableCell);
                    if (rowSpan > 1)
                    {
                        tableCellElement.SetAttribute("number-rows-spanned", (rowSpan).ToString());
                    }

                    ProcessParagraphes(wordDocument, tableCellElement, tableCell,
                                       table.TableLevel);

                    if (!tableCellElement.HasChildNodes)
                    {
                        tableCellElement.AppendChild(foDocumentFacade
                                                     .CreateBlock());
                    }

                    tableRowElement.AppendChild(tableCellElement);
                }

                if (tableRowElement.HasChildNodes)
                {
                    if (tableRow.isTableHeader())
                    {
                        tableHeader.AppendChild(tableRowElement);
                    }
                    else
                    {
                        tableBody.AppendChild(tableRowElement);
                    }
                }
            }

            XmlElement tableElement = foDocumentFacade.CreateTable();

            tableElement.SetAttribute("table-layout", "fixed");
            if (tableHeader.HasChildNodes)
            {
                tableElement.AppendChild(tableHeader);
            }
            if (tableBody.HasChildNodes)
            {
                tableElement.AppendChild(tableBody);
                flow.AppendChild(tableElement);
            }
            else
            {
                logger.Log(POILogger.WARN, "Table without body starting on offset " + table.StartOffset + " -- " + table.EndOffset);
            }
        }