コード例 #1
0
ファイル: TestRangeProperties.cs プロジェクト: hiodava/Romero
        public void TestAsciiStyling()
        {
            Range r = a.GetRange();

            Paragraph p1 = r.GetParagraph(0);
            Paragraph p7 = r.GetParagraph(6);

            Assert.AreEqual(1, p1.NumCharacterRuns);
            Assert.AreEqual(1, p7.NumCharacterRuns);

            CharacterRun c1 = p1.GetCharacterRun(0);
            CharacterRun c7 = p7.GetCharacterRun(0);

            Assert.AreEqual("Times New Roman", c1.GetFontName()); // No Calibri
            Assert.AreEqual("Arial Black", c7.GetFontName());
            Assert.AreEqual(20, c1.GetFontSize());
            Assert.AreEqual(32, c7.GetFontSize());

            // This document has 15 styles
            Assert.AreEqual(15, a.GetStyleSheet().NumStyles());

            // Ensure none of the paragraphs refer to one that isn't there,
            //  and none of their character Runs either
            for (int i = 0; i < a.GetRange().NumParagraphs; i++)
            {
                Paragraph p = a.GetRange().GetParagraph(i);
                Assert.IsTrue(p.GetStyleIndex() < 15);
            }
        }
コード例 #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
ファイル: WordToHtmlConverter.cs プロジェクト: zzy092/npoi
        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);
        }
コード例 #4
0
ファイル: WordToHtmlConverter.cs プロジェクト: zzy092/npoi
        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 static void AddCharactersProperties(CharacterRun characterRun, StringBuilder style)
        {
            AddBorder(characterRun.GetBorder(), string.Empty, style);

            if (characterRun.IsCapitalized())
            {
                style.Append("text-transform:uppercase;");
            }
            if (characterRun.GetIco24() != -1)
            {
                style.Append("color:" + GetColor24(characterRun.GetIco24()) + ";");
            }
            if (characterRun.IsHighlighted())
            {
                style.Append("background-color:" + GetColor(characterRun.GetHighlightedColor()) + ";");
            }
            if (characterRun.IsStrikeThrough())
            {
                style.Append("text-decoration:line-through;");
            }
            if (characterRun.IsShadowed())
            {
                style.Append("text-shadow:" + characterRun.GetFontSize() / 24 + "pt;");
            }
            if (characterRun.IsSmallCaps())
            {
                style.Append("font-variant:small-caps;");
            }
            if (characterRun.GetSubSuperScriptIndex() == 1)
            {
                style.Append("vertical-align:super;");
                style.Append("font-size:smaller;");
            }
            if (characterRun.GetSubSuperScriptIndex() == 2)
            {
                style.Append("vertical-align:sub;");
                style.Append("font-size:smaller;");
            }
            if (characterRun.GetUnderlineCode() > 0)
            {
                style.Append("text-decoration:underline;");
            }
            if (characterRun.IsVanished())
            {
                style.Append("visibility:hidden;");
            }
        }
コード例 #6
0
ファイル: TestRangeProperties.cs プロジェクト: hiodava/Romero
        public void TestUnicodeStyling()
        {
            Range r = u.GetRange();

            String[] p1_parts = u_page_1.Split('\r');

            Paragraph p1 = r.GetParagraph(0);
            Paragraph p7 = r.GetParagraph(6);

            // Line ending in its own run each time!
            Assert.AreEqual(2, p1.NumCharacterRuns);
            Assert.AreEqual(2, p7.NumCharacterRuns);

            CharacterRun c1a = p1.GetCharacterRun(0);
            CharacterRun c1b = p1.GetCharacterRun(1);
            CharacterRun c7a = p7.GetCharacterRun(0);
            CharacterRun c7b = p7.GetCharacterRun(1);

            Assert.AreEqual("Times New Roman", c1a.GetFontName()); // No Calibri
            Assert.AreEqual(22, c1a.GetFontSize());

            Assert.AreEqual("Times New Roman", c1b.GetFontName()); // No Calibri
            Assert.AreEqual(22, c1b.GetFontSize());

            Assert.AreEqual("Times New Roman", c7a.GetFontName());
            Assert.AreEqual(48, c7a.GetFontSize());

            Assert.AreEqual("Times New Roman", c7b.GetFontName());
            Assert.AreEqual(48, c7b.GetFontSize());

            // Now check where they crop up
            Assert.AreEqual(
                0,
                c1a.StartOffset
                );
            Assert.AreEqual(
                p1_parts[0].Length,
                c1a.EndOffset
                );

            Assert.AreEqual(
                p1_parts[0].Length,
                c1b.StartOffset
                );
            Assert.AreEqual(
                p1_parts[0].Length + 1,
                c1b.EndOffset
                );

            Assert.AreEqual(
                p1_parts[0].Length + 1 +
                p1_parts[1].Length + 1 +
                p1_parts[2].Length + 1 +
                p1_parts[3].Length + 1 +
                p1_parts[4].Length + 1 +
                p1_parts[5].Length + 1,
                c7a.StartOffset
                );
            Assert.AreEqual(
                p1_parts[0].Length + 1 +
                p1_parts[1].Length + 1 +
                p1_parts[2].Length + 1 +
                p1_parts[3].Length + 1 +
                p1_parts[4].Length + 1 +
                p1_parts[5].Length + 1 +
                1,
                c7a.EndOffset
                );

            Assert.AreEqual(
                p1_parts[0].Length + 1 +
                p1_parts[1].Length + 1 +
                p1_parts[2].Length + 1 +
                p1_parts[3].Length + 1 +
                p1_parts[4].Length + 1 +
                p1_parts[5].Length + 1 +
                1,
                c7b.StartOffset
                );
            Assert.AreEqual(
                p1_parts[0].Length + 1 +
                p1_parts[1].Length + 1 +
                p1_parts[2].Length + 1 +
                p1_parts[3].Length + 1 +
                p1_parts[4].Length + 1 +
                p1_parts[5].Length + 1 +
                p1_parts[6].Length + 1,
                c7b.EndOffset
                );

            // This document has 15 styles
            Assert.AreEqual(15, a.GetStyleSheet().NumStyles());

            // Ensure none of the paragraphs refer to one that isn't there,
            //  and none of their character Runs either
            for (int i = 0; i < a.GetRange().NumParagraphs; i++)
            {
                Paragraph p = a.GetRange().GetParagraph(i);
                Assert.IsTrue(p.GetStyleIndex() < 15);
            }
        }
コード例 #7
0
        public static void SetCharactersProperties(CharacterRun characterRun, XmlElement inline)
        {
            StringBuilder textDecorations = new StringBuilder();

            SetBorder(inline, characterRun.GetBorder(), string.Empty);

            if (characterRun.GetIco24() != -1)
            {
                inline.SetAttribute("color", GetColor24(characterRun.GetIco24()));
            }
            int opacity = (int)(characterRun.GetIco24() & 0xFF000000L) >> 24;

            if (opacity != 0 && opacity != 0xFF)
            {
                inline.SetAttribute("opacity",
                                    GetOpacity(characterRun.GetIco24()));
            }
            if (characterRun.IsCapitalized())
            {
                inline.SetAttribute("text-transform", "uppercase");
            }
            if (characterRun.isHighlighted())
            {
                inline.SetAttribute("background-color",
                                    GetColor(characterRun.GetHighlightedColor()));
            }
            if (characterRun.IsStrikeThrough())
            {
                if (textDecorations.Length > 0)
                {
                    textDecorations.Append(" ");
                }
                textDecorations.Append("line-through");
            }
            if (characterRun.IsShadowed())
            {
                inline.SetAttribute("text-shadow", characterRun.GetFontSize() / 24 + "pt");
            }
            if (characterRun.IsSmallCaps())
            {
                inline.SetAttribute("font-variant", "small-caps");
            }
            if (characterRun.GetSubSuperScriptIndex() == 1)
            {
                inline.SetAttribute("baseline-shift", "super");
                inline.SetAttribute("font-size", "smaller");
            }
            if (characterRun.GetSubSuperScriptIndex() == 2)
            {
                inline.SetAttribute("baseline-shift", "sub");
                inline.SetAttribute("font-size", "smaller");
            }
            if (characterRun.GetUnderlineCode() > 0)
            {
                if (textDecorations.Length > 0)
                {
                    textDecorations.Append(" ");
                }
                textDecorations.Append("underline");
            }
            if (characterRun.IsVanished())
            {
                inline.SetAttribute("visibility", "hidden");
            }
            if (textDecorations.Length > 0)
            {
                inline.SetAttribute("text-decoration", textDecorations.ToString());
            }
        }