Пример #1
0
        private void AddDataRun(long startLcn, long length)
        {
            long startVcn = 0;
            long prevLcn  = 0;

            if (_runs.Count > 0)
            {
                CookedDataRun tailRun = _runs[_runs.Count - 1];
                startVcn = tailRun.StartVcn + tailRun.Length;
                prevLcn  = tailRun.StartLcn;

                // Continuation of last run...
                if (startLcn == prevLcn + tailRun.Length)
                {
                    tailRun.Length += length;
                    return;
                }
            }

            DataRun       newRun       = new DataRun(startLcn - prevLcn, length);
            CookedDataRun newCookedRun = new CookedDataRun(newRun, startVcn, startLcn);

            _runs.Add(newCookedRun);
            _record.DataRuns.Add(newRun);
        }
Пример #2
0
        /// <summary>
        /// Hàm lấy đoạn văn bản của PowerPoint
        /// </summary>
        /// <param name="_paragraph"></param>
        /// <returns></returns>
        private DataParagraph GetEParagraph(pp.TextRange _paragraph)
        {
            DataParagraph eParagraph = new DataParagraph();

            //Căn vị trí đoạn văn bản - mặc định sẽ căn trái
            eParagraph.LineHeight = _paragraph.ParagraphFormat.SpaceWithin;
            eParagraph.Margin.Top = _paragraph.ParagraphFormat.SpaceBefore;
            eParagraph.TextAlign  = Text.HorizontalAlign.Left;
            switch (_paragraph.ParagraphFormat.Alignment)
            {
            case PpParagraphAlignment.ppAlignmentMixed:
                break;

            case PpParagraphAlignment.ppAlignLeft:
                eParagraph.TextAlign = Text.HorizontalAlign.Left;
                break;

            case PpParagraphAlignment.ppAlignCenter:
                eParagraph.TextAlign = Text.HorizontalAlign.Center;
                break;

            case PpParagraphAlignment.ppAlignRight:
                eParagraph.TextAlign = Text.HorizontalAlign.Right;
                break;

            case PpParagraphAlignment.ppAlignJustify:
                eParagraph.TextAlign = Text.HorizontalAlign.Justify;
                break;

            case PpParagraphAlignment.ppAlignDistribute:
                break;

            case PpParagraphAlignment.ppAlignThaiDistribute:
                break;

            case PpParagraphAlignment.ppAlignJustifyLow:
                break;

            default:
                break;
            }
            foreach (pp.TextRange textRun in _paragraph.Runs())
            {
                DataRun eRun = new DataRun();
                if (textRun.Font.NameAscii == "Cambria Math" && textRun.Font.NameOther == "Cambria Math")
                {
                    //xuất ảnh chứa công thức toán học
                    return(null);
                }
                else
                {
                    //Tạm rào để sử dụng app demo
                    bool result = ((System.Windows.Application.Current as IAppGlobal).SelectedTheme.FontFamilies.Fonts).Any(o => o.Name == textRun.Font.NameAscii);
                    if (result)
                    {
                        eRun.Fontfamily = textRun.Font.NameAscii;
                    }
                    else
                    {
                        eRun.Fontfamily = "Arial";
                    }
                    eRun.FontSize = textRun.Font.Size;
                    if (textRun.Font.Bold == Microsoft.Office.Core.MsoTriState.msoTrue || textRun.Font.Bold == Microsoft.Office.Core.MsoTriState.msoCTrue)
                    {
                        eRun.FontWeight = Text.FontWeight.Bold;
                    }
                    else
                    {
                        eRun.FontWeight = Text.FontWeight.Normal;
                    }
                    if (textRun.Font.Italic == office.MsoTriState.msoTrue || textRun.Font.Italic == office.MsoTriState.msoCTrue)
                    {
                        eRun.FontStyle = Text.FontStyle.Italic;
                    }
                    else
                    {
                        eRun.FontStyle = Text.FontStyle.Normal;
                    }
                    if (textRun.Font.Underline == office.MsoTriState.msoTrue || textRun.Font.Underline == office.MsoTriState.msoCTrue)
                    {
                        DataUnderline underline = new DataUnderline();
                        underline.Color = new SolidColor()
                        {
                            Color = ConvertColor(textRun.Font.Color.RGB)
                        };
                        underline.Style = Text.UnderlineStyle.Single;
                        eRun.Underline  = underline;
                    }
                    eRun.Foreground = new DataColor()
                    {
                        Name = ConvertColor(textRun.Font.Color.RGB)
                    };
                    eRun.Text         = textRun.Text;
                    eRun.ScriptOffset = (int)(textRun.Font.BaselineOffset * 100);
                    eParagraph.Inlines.Add(eRun);
                }
            }
            return(eParagraph);
        }
Пример #3
0
        private void ShapeIsText(PageLayer _page, pp.Shape _shape, EAnimation _animation, string _idShape)
        {
            //Thiếu textindent và strike words
            DataDocument document = new DataDocument();

            document.Name = "TextEditor";
            List <DataParaPositionBullet> ListParaPosition   = new List <DataParaPositionBullet>();
            DataParaPositionBullet        paraPositionBullet = null;

            document.Blocks.Clear();
            document.Container = new DataTextContainer();

            if (_shape.Type == office.MsoShapeType.msoTextBox)
            {
                document.TypeTextContainer = TypeTextContainer.AutoChangeHeight;
            }
            else
            {
                document.TypeTextContainer = TypeTextContainer.ChangeSize;
            }


            //Lấy nội dung
            pp.BulletFormat hasBullet = _shape.TextFrame.TextRange.ParagraphFormat.Bullet;
            if (hasBullet.Visible == office.MsoTriState.msoCTrue || hasBullet.Visible == office.MsoTriState.msoTrue)
            {
                foreach (pp.TextRange paragraph in _shape.TextFrame.TextRange.Paragraphs())
                {
                    DataDocumentList docList = new DataDocumentList();
                    int level = paragraph.IndentLevel;
                    DataDocumentListItem docListItem = new DataDocumentListItem();
                    pp.BulletFormat      prgBullet   = paragraph.ParagraphFormat.Bullet;
                    docListItem.TypeWordBullet = new Text.ViewModels.Text.TypeWordBullet();

                    docListItem.TypeWordBullet.StarIndex = prgBullet.StartValue;
                    if (prgBullet.Visible == office.MsoTriState.msoCTrue || prgBullet.Visible == office.MsoTriState.msoTrue)
                    {
                        docListItem.TypeWordBullet            = new Text.ViewModels.Text.TypeWordBullet();
                        docListItem.TypeWordBullet.SizeOffset = 100;
                        if (prgBullet.Type == PpBulletType.ppBulletNumbered)
                        {
                            docListItem.TypeWordBullet.Fontfamily = "Arial";
                            docListItem.TypeWordBullet.Text       = "1.";
                            docListItem.TypeWordBullet.ListType   = Text.ListType.Decimal;
                            switch (prgBullet.Style)
                            {
                            case PpNumberedBulletStyle.ppBulletStyleMixed:
                                break;

                            case PpNumberedBulletStyle.ppBulletAlphaLCPeriod:
                                docListItem.TypeWordBullet.Fontfamily = "Arial";
                                docListItem.TypeWordBullet.Text       = "a.";
                                docListItem.TypeWordBullet.ListType   = Text.ListType.LowerLatin;
                                break;

                            case PpNumberedBulletStyle.ppBulletAlphaUCPeriod:
                                docListItem.TypeWordBullet.Fontfamily = "Arial";
                                docListItem.TypeWordBullet.Text       = "A.";
                                docListItem.TypeWordBullet.ListType   = Text.ListType.UpperLatin;
                                break;

                            case PpNumberedBulletStyle.ppBulletArabicParenRight:
                                docListItem.TypeWordBullet.Fontfamily = "Arial";
                                docListItem.TypeWordBullet.Text       = "1)";
                                docListItem.TypeWordBullet.ListType   = Text.ListType.Decimal2;
                                break;

                            case PpNumberedBulletStyle.ppBulletArabicPeriod:
                                docListItem.TypeWordBullet.Fontfamily = "Arial";
                                docListItem.TypeWordBullet.Text       = "1.";
                                docListItem.TypeWordBullet.ListType   = Text.ListType.Decimal;
                                break;

                            case PpNumberedBulletStyle.ppBulletRomanLCParenBoth:
                                break;

                            case PpNumberedBulletStyle.ppBulletRomanLCParenRight:
                                break;

                            case PpNumberedBulletStyle.ppBulletRomanLCPeriod:
                                docListItem.TypeWordBullet.Fontfamily = "Arial";
                                docListItem.TypeWordBullet.Text       = "i.";
                                docListItem.TypeWordBullet.ListType   = Text.ListType.LowerRoman;
                                break;

                            case PpNumberedBulletStyle.ppBulletRomanUCPeriod:
                                docListItem.TypeWordBullet.Fontfamily = "Arial";
                                docListItem.TypeWordBullet.Text       = "I.";
                                docListItem.TypeWordBullet.ListType   = Text.ListType.UpperRoman;
                                break;

                            case PpNumberedBulletStyle.ppBulletAlphaLCParenBoth:
                                break;

                            case PpNumberedBulletStyle.ppBulletAlphaLCParenRight:
                                docListItem.TypeWordBullet.Fontfamily = "Arial";
                                docListItem.TypeWordBullet.Text       = "a)";
                                docListItem.TypeWordBullet.ListType   = Text.ListType.LowerLatin2;
                                break;

                            case PpNumberedBulletStyle.ppBulletAlphaUCParenBoth:
                                break;

                            case PpNumberedBulletStyle.ppBulletAlphaUCParenRight:
                                break;

                            case PpNumberedBulletStyle.ppBulletArabicParenBoth:
                                break;

                            case PpNumberedBulletStyle.ppBulletArabicPlain:
                                break;

                            case PpNumberedBulletStyle.ppBulletRomanUCParenBoth:
                                break;

                            case PpNumberedBulletStyle.ppBulletRomanUCParenRight:
                                break;

                            case PpNumberedBulletStyle.ppBulletSimpChinPlain:
                                break;

                            case PpNumberedBulletStyle.ppBulletSimpChinPeriod:
                                break;

                            case PpNumberedBulletStyle.ppBulletCircleNumDBPlain:
                                break;

                            case PpNumberedBulletStyle.ppBulletCircleNumWDWhitePlain:
                                break;

                            case PpNumberedBulletStyle.ppBulletCircleNumWDBlackPlain:
                                break;

                            case PpNumberedBulletStyle.ppBulletTradChinPlain:
                                break;

                            case PpNumberedBulletStyle.ppBulletTradChinPeriod:
                                break;

                            case PpNumberedBulletStyle.ppBulletArabicAlphaDash:
                                break;

                            case PpNumberedBulletStyle.ppBulletArabicAbjadDash:
                                break;

                            case PpNumberedBulletStyle.ppBulletHebrewAlphaDash:
                                break;

                            case PpNumberedBulletStyle.ppBulletKanjiKoreanPlain:
                                break;

                            case PpNumberedBulletStyle.ppBulletKanjiKoreanPeriod:
                                break;

                            case PpNumberedBulletStyle.ppBulletArabicDBPlain:
                                break;

                            case PpNumberedBulletStyle.ppBulletArabicDBPeriod:
                                break;

                            case PpNumberedBulletStyle.ppBulletThaiAlphaPeriod:
                                break;

                            case PpNumberedBulletStyle.ppBulletThaiAlphaParenRight:
                                break;

                            case PpNumberedBulletStyle.ppBulletThaiAlphaParenBoth:
                                break;

                            case PpNumberedBulletStyle.ppBulletThaiNumPeriod:
                                break;

                            case PpNumberedBulletStyle.ppBulletThaiNumParenRight:
                                break;

                            case PpNumberedBulletStyle.ppBulletThaiNumParenBoth:
                                break;

                            case PpNumberedBulletStyle.ppBulletHindiAlphaPeriod:
                                break;

                            case PpNumberedBulletStyle.ppBulletHindiNumPeriod:
                                break;

                            case PpNumberedBulletStyle.ppBulletKanjiSimpChinDBPeriod:
                                break;

                            case PpNumberedBulletStyle.ppBulletHindiNumParenRight:
                                break;

                            case PpNumberedBulletStyle.ppBulletHindiAlpha1Period:
                                break;

                            default:
                                break;
                            }
                        }
                        else if (prgBullet.Type == PpBulletType.ppBulletUnnumbered)
                        {
                            if (prgBullet.Character == 8226)
                            {
                                docListItem.TypeWordBullet.Fontfamily = "Wingdings";
                                docListItem.TypeWordBullet.Text       = "l";
                                docListItem.TypeWordBullet.ListType   = Text.ListType.Bullet;
                            }
                            else if (prgBullet.Character == 111)
                            {
                                docListItem.TypeWordBullet.Fontfamily = "Raleway";
                                docListItem.TypeWordBullet.Text       = "o";
                                docListItem.TypeWordBullet.ListType   = Text.ListType.Bullet;
                            }
                            else if (prgBullet.Character == 167)
                            {
                                docListItem.TypeWordBullet.Fontfamily = "Wingdings";
                                docListItem.TypeWordBullet.Text       = ((char)167).ToString();
                                docListItem.TypeWordBullet.ListType   = Text.ListType.Bullet;
                            }
                            else if (prgBullet.Character == 113)
                            {
                                docListItem.TypeWordBullet.Fontfamily = "Wingdings";
                                docListItem.TypeWordBullet.Text       = "q";
                                docListItem.TypeWordBullet.ListType   = Text.ListType.Bullet;
                            }
                            else if (prgBullet.Character == 118)
                            {
                                docListItem.TypeWordBullet.Fontfamily = "Wingdings";
                                docListItem.TypeWordBullet.Text       = "v";
                                docListItem.TypeWordBullet.ListType   = Text.ListType.Bullet;
                            }
                            else if (prgBullet.Character == 216)
                            {
                                docListItem.TypeWordBullet.Fontfamily = "Wingdings";
                                docListItem.TypeWordBullet.Text       = ((char)216).ToString();
                                docListItem.TypeWordBullet.ListType   = Text.ListType.Bullet;
                            }
                            else if (prgBullet.Character == 252)
                            {
                                docListItem.TypeWordBullet.Fontfamily = "Wingdings";
                                docListItem.TypeWordBullet.Text       = ((char)252).ToString();
                                docListItem.TypeWordBullet.ListType   = Text.ListType.Bullet;
                            }
                            else
                            {
                                docListItem.TypeWordBullet.Fontfamily = "Wingdings";
                                docListItem.TypeWordBullet.Text       = "l";
                                docListItem.TypeWordBullet.ListType   = Text.ListType.Bullet;
                            }
                        }
                    }
                    paraPositionBullet          = new DataParaPositionBullet();
                    paraPositionBullet.Para     = GetEParagraph(paragraph);
                    paraPositionBullet.ListType = docListItem.TypeWordBullet;
                    paraPositionBullet.Position = level;
                    ListParaPosition.Add(paraPositionBullet);
                }
            }
            else
            {
                foreach (pp.TextRange paragraph in _shape.TextFrame.TextRange.Paragraphs())
                {
                    /*
                     * var _para = GetEParagraph(paragraph);
                     * if (_para.Inlines?.Count > 0)
                     * {
                     *  if ((_para.Inlines.Last() as DataRun)?.Text != null)
                     *      (_para.Inlines.Last() as DataRun).Text = (_para.Inlines.Last() as DataRun).Text + "\r";
                     * }
                     * document.Blocks.Add(_para);*/
                    paraPositionBullet      = new DataParaPositionBullet();
                    paraPositionBullet.Para = GetEParagraph(paragraph);
                    if (paraPositionBullet.Para?.Inlines?.Count > 0)
                    {
                        if ((paraPositionBullet.Para.Inlines.Last() as DataRun)?.Text != null)
                        {
                            (paraPositionBullet.Para.Inlines.Last() as DataRun).Text = (paraPositionBullet.Para.Inlines.Last() as DataRun).Text + "\r";
                        }
                    }
                    paraPositionBullet.ListType = null;
                    paraPositionBullet.Position = 0;
                    ListParaPosition.Add(paraPositionBullet);
                }
                //goto addToDoc;
            }
            if (ListParaPosition?.Count == 0)
            {
                paraPositionBullet      = new DataParaPositionBullet();
                paraPositionBullet.Para = new DataParagraph();
                DataRun _run = new DataRun();
                _run.Text       = "\r";
                _run.FontSize   = 14;
                _run.Fontfamily = "Times New Roman";
                _run.Parent     = paraPositionBullet.Para;
                paraPositionBullet.Para.Inlines.Add(_run);
                ListParaPosition.Add(paraPositionBullet);
            }
            ConverterListParaToDataDocument(ListParaPosition, document);

            _page.Children.Add(document);
        }