Exemplo n.º 1
0
 private DqStyle ConvertStyle(Style style, DqNumberingTable dqNumberingsTable, DqFontScheme fontScheme) =>
Exemplo n.º 2
0
        public DqStyle GetParagraphStyle(Paragraph paragraph, DqStyleTable styleTable, DqFontScheme fontScheme, DqNumberingTable dqNumberingTable)
        {
            var value      = paragraph.ParagraphProperties?.ParagraphStyleId?.Val?.Value;
            var basicStyle = styleTable.Paragraph[value] ?? styleTable.Paragraph.Default;

            var pPr = paragraph.ParagraphProperties;

            if (pPr == null)
            {
                return(basicStyle);
            }

            var localStyle = new DqStyle {
                BaseStyle = basicStyle
            };

            if (pPr.SpacingBetweenLines != null)
            {
                localStyle.Current.SpacingBetweenLines = GetSpacingBetweenLines(pPr.SpacingBetweenLines.Line);
            }

            if (pPr.Indentation?.FirstLine != null)
            {
                localStyle.Current.Indent = Convertion.TwipToCm(int.Parse(pPr.Indentation.FirstLine.Value));
            }

            if (pPr.Justification != null)
            {
                localStyle.Current.Aligment = Convert(pPr.Justification.Val);
            }

            if (pPr.GetFirstChild <NumberingProperties>() != null)
            {
                var id        = pPr.GetFirstChild <NumberingProperties>().NumberingId;
                var numbering = dqNumberingTable[id.Val];
                localStyle.Current.Numbering = numbering;

                var level = pPr.GetFirstChild <NumberingProperties>().NumberingLevelReference;
                if (level != null && level.Val < numbering.Levels.Count)
                {
                    localStyle.Current.Indent = numbering.Levels[level.Val].Indent ?? localStyle.Indent;
                }
            }

            var rPr = (OpenXmlElement)pPr.ParagraphMarkRunProperties;

            if (rPr != null)
            {
                if (rPr.GetFirstChild <RunFonts>() != null)
                {
                    localStyle.Current.FontName = GetFontName(rPr.GetFirstChild <RunFonts>(), fontScheme);
                }

                if (rPr.GetFirstChild <FontSize>() != null)
                {
                    localStyle.Current.FontSize = ConvertFontSize(rPr.GetFirstChild <FontSize>());
                }

                if (rPr.GetFirstChild <Bold>() != null)
                {
                    localStyle.Current.IsBold = ConvertBold(rPr.GetFirstChild <Bold>());
                }
            }

            var runs = paragraph.Descendants <Run>().ToList();

            if (runs.Count == 1)
            {
                rPr = runs.Single().RunProperties;
                if (rPr != null)
                {
                    if (rPr.GetFirstChild <RunFonts>() != null)
                    {
                        localStyle.Current.FontName = GetFontName(rPr.GetFirstChild <RunFonts>(), fontScheme);
                    }

                    if (rPr.GetFirstChild <FontSize>() != null)
                    {
                        localStyle.Current.FontSize = ConvertFontSize(rPr.GetFirstChild <FontSize>());
                    }

                    if (rPr.GetFirstChild <Bold>() != null)
                    {
                        localStyle.Current.IsBold = ConvertBold(rPr.GetFirstChild <Bold>());
                    }
                }
            }

            return(localStyle);
        }
Exemplo n.º 3
0
 private IReadOnlyCollection <DqStyle> GetStyles(Styles wStyles, DqNumberingTable dqNumberingsTable, DqFontScheme dqFontScheme) =>
 wStyles.Descendants <Style>().Select(wStyle => ConvertStyle(wStyle, dqNumberingsTable, dqFontScheme)).ToList();