Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
0
        protected Triplet GetCharacterRunTriplet(CharacterRun characterRun)
        {
            Triplet original = new Triplet();

            original.bold     = characterRun.IsBold();
            original.italic   = characterRun.IsItalic();
            original.fontName = characterRun.GetFontName();
            Triplet updated = GetFontReplacer().Update(original);

            return(updated);
        }
Пример #4
0
        protected override void OutputCharacters(XmlElement pElement, CharacterRun characterRun, string text)
        {
            XmlElement span = htmlDocumentFacade.Document.CreateElement("span");

            pElement.AppendChild(span);

            StringBuilder  style          = new StringBuilder();
            BlockProperies blockProperies = this.blocksProperies.Peek();
            Triplet        triplet        = GetCharacterRunTriplet(characterRun);

            if (!string.IsNullOrEmpty(triplet.fontName) &&
                !WordToHtmlUtils.Equals(triplet.fontName,
                                        blockProperies.pFontName))
            {
                style.Append("font-family:" + triplet.fontName + ";");
            }
            if (characterRun.GetFontSize() / 2 != blockProperies.pFontSize)
            {
                style.Append("font-size:" + characterRun.GetFontSize() / 2 + "pt;");
            }
            if (triplet.bold)
            {
                style.Append("font-weight:bold;");
            }
            if (triplet.italic)
            {
                style.Append("font-style:italic;");
            }

            WordToHtmlUtils.AddCharactersProperties(characterRun, style);
            if (style.Length != 0)
            {
                htmlDocumentFacade.AddStyleClass(span, "s", style.ToString());
            }

            XmlText textNode = htmlDocumentFacade.CreateText(text);

            span.AppendChild(textNode);
        }
Пример #5
0
        public Triplet Update(Triplet original)
        {
            if (!string.IsNullOrEmpty(original.fontName))
            {
                String fontName = original.fontName;

                if (fontName.EndsWith(" Regular"))
                {
                    fontName = AbstractWordUtils.SubstringBeforeLast(fontName,
                                                                     " Regular");
                }

                if (fontName
                    .EndsWith(" \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439"))
                {
                    fontName = AbstractWordUtils
                               .SubstringBeforeLast(fontName,
                                                    " \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439")
                               + " Bold";
                }

                if (fontName
                    .EndsWith(" \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439 \u041A\u0443\u0440\u0441\u0438\u0432"))
                {
                    fontName = AbstractWordUtils
                               .SubstringBeforeLast(
                        fontName,
                        " \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439 \u041A\u0443\u0440\u0441\u0438\u0432")
                               + " Bold Italic";
                }

                if (fontName.EndsWith(" \u041A\u0443\u0440\u0441\u0438\u0432"))
                {
                    fontName = AbstractWordUtils.SubstringBeforeLast(fontName,
                                                                     " \u041A\u0443\u0440\u0441\u0438\u0432") + " Italic";
                }

                original.fontName = fontName;
            }

            if (!string.IsNullOrEmpty(original.fontName))
            {
                if ("Times Regular".Equals(original.fontName) ||
                    "Times-Regular".Equals(original.fontName))
                {
                    original.fontName = "Times";
                    original.bold     = false;
                    original.italic   = false;
                }
                if ("Times Bold".Equals(original.fontName) ||
                    "Times-Bold".Equals(original.fontName))
                {
                    original.fontName = "Times";
                    original.bold     = true;
                    original.italic   = false;
                }
                if ("Times Italic".Equals(original.fontName) ||
                    "Times-Italic".Equals(original.fontName))
                {
                    original.fontName = "Times";
                    original.bold     = false;
                    original.italic   = true;
                }
                if ("Times Bold Italic".Equals(original.fontName) ||
                    "Times-BoldItalic".Equals(original.fontName))
                {
                    original.fontName = "Times";
                    original.bold     = true;
                    original.italic   = true;
                }
            }

            return(original);
        }
Пример #6
0
        public Triplet Update(Triplet original)
        {
            if (!string.IsNullOrEmpty(original.fontName))
            {
                String fontName = original.fontName;

                if (fontName.EndsWith(" Regular"))
                    fontName = AbstractWordUtils.SubstringBeforeLast(fontName,
                            " Regular");

                if (fontName
                        .EndsWith(" \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439"))
                    fontName = AbstractWordUtils
                            .SubstringBeforeLast(fontName,
                                    " \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439")
                            + " Bold";

                if (fontName
                        .EndsWith(" \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439 \u041A\u0443\u0440\u0441\u0438\u0432"))
                    fontName = AbstractWordUtils
                            .SubstringBeforeLast(
                                    fontName,
                                    " \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439 \u041A\u0443\u0440\u0441\u0438\u0432")
                            + " Bold Italic";

                if (fontName.EndsWith(" \u041A\u0443\u0440\u0441\u0438\u0432"))
                    fontName = AbstractWordUtils.SubstringBeforeLast(fontName,
                            " \u041A\u0443\u0440\u0441\u0438\u0432") + " Italic";

                original.fontName = fontName;
            }

            if (!string.IsNullOrEmpty(original.fontName))
            {
                if ("Times Regular".Equals(original.fontName)
                        || "Times-Regular".Equals(original.fontName))
                {
                    original.fontName = "Times";
                    original.bold = false;
                    original.italic = false;
                }
                if ("Times Bold".Equals(original.fontName)
                        || "Times-Bold".Equals(original.fontName))
                {
                    original.fontName = "Times";
                    original.bold = true;
                    original.italic = false;
                }
                if ("Times Italic".Equals(original.fontName)
                        || "Times-Italic".Equals(original.fontName))
                {
                    original.fontName = "Times";
                    original.bold = false;
                    original.italic = true;
                }
                if ("Times Bold Italic".Equals(original.fontName)
                        || "Times-BoldItalic".Equals(original.fontName))
                {
                    original.fontName = "Times";
                    original.bold = true;
                    original.italic = true;
                }
            }

            return original;
        }