Пример #1
0
        /// <summary>
        /// If there are bullet points, returns a list of paragraphs without bullet points (marked for removal)
        /// If there are no paragraphs with bullet points at all, then return empty list (mark nothing for removal)
        /// </summary>
        private static List <int> GetParagraphsWithoutBullets(Office.TextRange2 textRange)
        {
            var  indexList      = new List <int>();
            int  index          = 0;
            bool hasBulletPoint = false;

            for (int i = 1; i <= textRange.Paragraphs.Count; ++i)
            {
                var paragraph = textRange.Paragraphs[i];
                if (paragraph.Text.Trim().Length == 0)
                {
                    continue;
                }
                if (paragraph.ParagraphFormat.Bullet.Visible == Office.MsoTriState.msoFalse)
                {
                    indexList.Add(index);
                }
                else
                {
                    hasBulletPoint = true;
                }
                index++;
            }

            // Return nothing if there is no bullet point at all.
            if (!hasBulletPoint)
            {
                indexList.Clear();
            }
            return(indexList);
        }
Пример #2
0
 private void GetNodeCharAttribute(Microsoft.Office.Core.TextFrame2 TextFrame)
 {
     Microsoft.Office.Core.TextRange2 Textrange = TextFrame.TextRange;
     spellcheck(Textrange.Text);
     // PPT.TextRange ppttr =(PPT.TextRange) Textrange;
     for (int index = 0; index < Textrange.Text.Count(); index++)
     {
         try
         {
             Microsoft.Office.Core.TextRange2 text = Textrange.Find(Textrange.Text[index].ToString(), index);
             float     sz    = text.Font.Size;
             TextStyle style = new TextStyle();
             style.Size      = sz;
             style.Character = text.Text[0];
             style.Color     = text.Font.Fill.ForeColor.RGB;
             style.FontName  = text.Font.Name;
             TextStlyeList.Add(style);
             TotalTextCount += 1;
         }
         catch (Exception ex)
         {
             Log("\tanalyze slide no " + slide.SlideNumber + " GetCharAttribute exception occur : " + ex.Message);
         }
     }
 }
        /// <summary>
        /// Get a list of unselected paragraphs to mark for removal.
        /// </summary>
        private static List <int> GetUnselectedParagraphs(Office.TextRange2 textRange, Office.TextRange2 selectedText)
        {
            var indexList = new List <int>();
            int index     = 0;

            for (int i = 1; i <= textRange.Paragraphs.Count; ++i)
            {
                var paragraph = textRange.Paragraphs[i];
                if (paragraph.Text.Trim().Length == 0)
                {
                    continue;
                }

                int actualParagraphLength = paragraph.Length;
                if (!paragraph.Text.EndsWith("\r"))
                {
                    actualParagraphLength++;
                }

                if (selectedText.Start + selectedText.Length < paragraph.Start ||
                    selectedText.Start > paragraph.Start + actualParagraphLength - 1)
                {
                    indexList.Add(index);
                }
                index++;
            }
            return(indexList);
        }
Пример #4
0
 private static void trimNewline(Office.TextRange2 paragraph)
 {
     Office.TextRange2 lastChar = paragraph.Characters[paragraph.Characters.Count];
     if (lastChar.Text == "\r")
     {
         paragraph.Characters[paragraph.Characters.Count].Delete();
     }
 }
Пример #5
0
 void HighlightTextRange(Office.TextRange2 textRange, Core.Parser parser)
 {
     textRange.Font.Fill.ForeColor.RGB = System.Drawing.Color.Black.ToMsoColor();
     foreach (var f in parser.Parse(textRange.Text))
     {
         // NOTE: indices of Characters are 1-based
         textRange.get_Characters(1 + f.Start, f.Length).Font.Fill.ForeColor.RGB = f.ForegroundColor.ToMsoColor();
     }
 }
 /// <summary>
 /// The add animations creates a text animation for every paragraph in the text box.
 /// But we may not always want all the paragraphs to have animations.
 /// This method marks paragraphs to remove text animations from and returns a list of the indexes of the marked paragraphs.
 /// Indexes returned is in increasing order.
 /// </summary>
 private static List <int> GetParagraphsToRemove(PowerPoint.Shape sh, Office.TextRange2 selectedText)
 {
     Office.TextRange2 textRange = sh.TextFrame2.TextRange;
     if (userSelection == HighlightTextSelection.kTextSelected)
     {
         return(GetUnselectedParagraphs(textRange, selectedText));
     }
     else
     {
         return(GetParagraphsWithoutBullets(textRange));
     }
 }
Пример #7
0
        public static void AddHighlightedTextFragments()
        {
            try
            {
                var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide;

                PowerPoint.ShapeRange selectedShapes = null;
                Office.TextRange2     selectedText   = null;

                //Get shapes to consider for animation
                switch (userSelection)
                {
                case HighlightTextSelection.kShapeSelected:
                    return;

                case HighlightTextSelection.kTextSelected:
                    selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange;
                    selectedText   = Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange2.TrimText();
                    break;

                case HighlightTextSelection.kNoneSelected:
                    return;

                default:
                    return;
                }
                if (selectedText.Length <= 0)
                {
                    return;
                }

                if (selectedShapes.Count != 1)
                {
                    return;
                }

                List <PowerPoint.Shape> selectionToAnimate = GetShapesFromLinesInText(currentSlide, selectedText, selectedShapes[1]);
                GroupShapesForAnimation(selectionToAnimate);

                List <PowerPoint.Shape> shapesToAnimate = GetShapesToAnimate(currentSlide);
                SelectShapes(shapesToAnimate);

                RunAnimateInSlide();
            }
            catch (Exception e)
            {
                Logger.LogException(e, "AddHighlightedTextFragments");
                throw;
            }
        }
 private static void GenerateHighlightShape(PowerPointSlide currentSlide, Office.TextRange2 paragraph, PowerPoint.Shape sh)
 {
     PowerPoint.Shape highlightShape = currentSlide.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeRoundedRectangle,
                                                                    paragraph.BoundLeft,
                                                                    paragraph.BoundTop,
                                                                    paragraph.BoundWidth,
                                                                    paragraph.BoundHeight);
     highlightShape.Adjustments[1]     = 0.25f;
     highlightShape.Fill.ForeColor.RGB = Utils.GraphicsUtil.ConvertColorToRgb(HighlightLabSettings.bulletsBackgroundColor);
     highlightShape.Fill.Transparency  = 0.50f;
     highlightShape.Line.Visible       = Office.MsoTriState.msoFalse;
     Utils.ShapeUtil.MoveZToJustBehind(highlightShape, sh);
     highlightShape.Name = "PPTLabsHighlightBackgroundShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff");
     highlightShape.Tags.Add("HighlightBackground", sh.Name);
     highlightShape.Select(Office.MsoTriState.msoFalse);
 }
Пример #9
0
 private static void formatBullets(Office.TextRange2 textRange)
 {
     // Loop through the paragraphs if paragraphs exists  (user selected many characters)
     if (textRange.Paragraphs.Count > 0)
     {
         foreach (Office.TextRange2 paragraph in textRange.Paragraphs)
         {
             formatBullets(paragraph.ParagraphFormat);
         }
     }
     // If no selection (only cursor position), only adjust that paragraph
     else
     {
         formatBullets(textRange.ParagraphFormat);
     }
 }
Пример #10
0
        void HighlightTextRange(Office.TextRange2 textRange, Core.Parser parser)
        {
            var text = textRange.Text;

            if (string.IsNullOrEmpty(text))
            {
                return;
            }
            // reset text color.
            textRange.Font.Fill.ForeColor.RGB = System.Drawing.Color.Black.ToMsoColor();

            foreach (var f in parser.Parse(text))
            {
                // NOTE: indices of Characters are 1-based
                textRange.get_Characters(1 + f.Start, f.Length).Font.Fill.ForeColor.RGB = f.ForegroundColor.ToMsoColor();
            }
        }
Пример #11
0
        public static void AddHighlightBulletsText()
        {
            try
            {
                var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide;

                PowerPoint.ShapeRange selectedShapes = null;
                Office.TextRange2     selectedText   = null;

                //Get shapes to consider for animation
                List <PowerPoint.Shape> shapesToUse = null;
                switch (userSelection)
                {
                case HighlightTextSelection.kShapeSelected:
                    selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange;
                    shapesToUse    = GetShapesToUse(currentSlide, selectedShapes);
                    break;

                case HighlightTextSelection.kTextSelected:
                    selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange;
                    selectedText   = Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange2.TrimText();
                    shapesToUse    = GetShapesToUse(currentSlide, selectedShapes);
                    break;

                case HighlightTextSelection.kNoneSelected:
                    currentSlide.DeleteIndicator();
                    currentSlide.DeleteShapesWithPrefix("PPTLabsHighlightBackgroundShape");
                    shapesToUse = GetAllUsableShapesInSlide(currentSlide);
                    break;

                default:
                    break;
                }

                if (currentSlide.Name.Contains("PPTLabsHighlightBulletsSlide"))
                {
                    ProcessExistingHighlightSlide(currentSlide, shapesToUse);
                }

                if (shapesToUse == null || shapesToUse.Count == 0)
                {
                    return;
                }

                currentSlide.Name = "PPTLabsHighlightBulletsSlide" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

                PowerPoint.Sequence sequence = currentSlide.TimeLine.MainSequence;
                bool isFirstShape            = IsFirstShape(currentSlide);

                foreach (PowerPoint.Shape sh in shapesToUse)
                {
                    if (!sh.Name.Contains("HighlightTextShape"))
                    {
                        sh.Name = "HighlightTextShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff");
                    }

                    //Add Font Appear effect for all paragraphs within shape
                    int currentIndex = sequence.Count;
                    sequence.AddEffect(sh, PowerPoint.MsoAnimEffect.msoAnimEffectChangeFontColor, PowerPoint.MsoAnimateByLevel.msoAnimateTextByFifthLevel, PowerPoint.MsoAnimTriggerType.msoAnimTriggerOnPageClick);
                    var appearEffects = AsList(sequence, currentIndex + 1, sequence.Count + 1);

                    //Add Font Disappear effect for all paragraphs within shape
                    currentIndex = sequence.Count;
                    sequence.AddEffect(sh, PowerPoint.MsoAnimEffect.msoAnimEffectChangeFontColor, PowerPoint.MsoAnimateByLevel.msoAnimateTextByFifthLevel, PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious);
                    var disappearEffects = AsList(sequence, currentIndex + 1, sequence.Count + 1);

                    //Remove effects for paragraphs without bullet points
                    var markedForRemoval = GetParagraphsToRemove(sh, selectedText);
                    // assert appearEffects.Count == disappearEffects.Count;
                    // assert markedForRemoval.Count <= appearEffects.Count;
                    for (int i = markedForRemoval.Count - 1; i >= 0; --i)
                    {
                        // delete from back.
                        int index = markedForRemoval[i];
                        appearEffects[index].Delete();
                        appearEffects.RemoveAt(index);
                        disappearEffects[index].Delete();
                        disappearEffects.RemoveAt(index);
                    }

                    if (appearEffects.Count == 0)
                    {
                        continue;
                    }

                    RearrangeEffects(appearEffects, disappearEffects);
                    FormatAppearEffects(appearEffects, isFirstShape);
                    FormatDisappearEffects(disappearEffects);
                    isFirstShape = false;
                }

                Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview");
                PowerPointPresentation.Current.AddAckSlide();
            }
            catch (Exception e)
            {
                Logger.LogException(e, "AddHighlightBulletsText");
                throw;
            }
        }
        private static List <PowerPoint.Shape> GetShapesFromLinesInText(PowerPointSlide currentSlide, Office.TextRange2 text, PowerPoint.Shape shape)
        {
            List <PowerPoint.Shape> shapesToAnimate = new List <PowerPoint.Shape>();
            Boolean isTextBoxTransparent            = (shape.Fill.Transparency).CompareTo(1.0f) == 0;

            foreach (Office.TextRange2 line in text.Lines)
            {
                PowerPoint.Shape highlightShape = currentSlide.Shapes.AddShape(
                    Office.MsoAutoShapeType.msoShapeRoundedRectangle,
                    line.BoundLeft,
                    line.BoundTop,
                    line.BoundWidth,
                    line.BoundHeight);

                highlightShape.Adjustments[1]     = 0.25f;
                highlightShape.Fill.ForeColor.RGB = Utils.Graphics.ConvertColorToRgb(backgroundColor);
                highlightShape.Fill.Transparency  = 0.50f;
                highlightShape.Line.Visible       = Office.MsoTriState.msoFalse;
                if (isTextBoxTransparent)
                {
                    Utils.Graphics.MoveZToJustBehind(highlightShape, shape);
                }
                highlightShape.Name = "PPTLabsHighlightTextFragmentsShape" + Guid.NewGuid().ToString();
                highlightShape.Tags.Add("HighlightTextFragment", highlightShape.Name);
                highlightShape.Select(Office.MsoTriState.msoFalse);
                shapesToAnimate.Add(highlightShape);
            }

            return(shapesToAnimate);
        }
Пример #13
0
        //Add highlight shape for paragraphs within selected shape which have bullets or with text selected by user
        private static bool AddNewShapesToAnimate(PowerPointSlide currentSlide, List <PowerPoint.Shape> shapesToUse, Office.TextRange2 selectedText)
        {
            bool anySelected = false;

            foreach (var sh in shapesToUse)
            {
                sh.Name = "HighlightBackgroundShape" + Guid.NewGuid();
            }

            if (userSelection == HighlightBackgroundSelection.kTextSelected)
            {
                foreach (var sh in shapesToUse)
                {
                    foreach (Office.TextRange2 paragraph in sh.TextFrame2.TextRange.Paragraphs)
                    {
                        if (paragraph.Start <= selectedText.Start + selectedText.Length &&
                            selectedText.Start <= paragraph.Start + paragraph.Length - 1 &&
                            paragraph.TrimText().Length > 0)
                        {
                            GenerateHighlightShape(currentSlide, paragraph, sh);
                            anySelected = true;
                        }
                    }
                }
            }
            else
            {
                foreach (var sh in shapesToUse)
                {
                    bool anySelectedForShape = false;
                    foreach (Office.TextRange2 paragraph in sh.TextFrame2.TextRange.Paragraphs)
                    {
                        if (paragraph.ParagraphFormat.Bullet.Visible == Office.MsoTriState.msoTrue &&
                            paragraph.TrimText().Length > 0)
                        {
                            GenerateHighlightShape(currentSlide, paragraph, sh);
                            anySelected         = true;
                            anySelectedForShape = true;
                        }
                    }
                    if (anySelectedForShape)
                    {
                        continue;
                    }
                    foreach (Office.TextRange2 paragraph in sh.TextFrame2.TextRange.Paragraphs)
                    {
                        if (paragraph.TrimText().Length > 0)
                        {
                            GenerateHighlightShape(currentSlide, paragraph, sh);
                            anySelected = true;
                        }
                    }
                }
            }
            return(anySelected);
        }
Пример #14
0
        public static void AddHighlightBulletsBackground()
        {
            try
            {
                var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide;
                currentSlide.Name = "PPTLabsHighlightBulletsSlide" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

                PowerPoint.ShapeRange selectedShapes = null;
                Office.TextRange2     selectedText   = null;

                //Get shapes to consider for animation
                List <PowerPoint.Shape> shapesToUse = null;
                switch (userSelection)
                {
                case HighlightBackgroundSelection.kShapeSelected:
                    selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange;
                    shapesToUse    = GetShapesToUse(currentSlide, selectedShapes);
                    break;

                case HighlightBackgroundSelection.kTextSelected:
                    selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange;
                    selectedText   = Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange2.TrimText();
                    shapesToUse    = GetShapesToUse(currentSlide, selectedShapes);
                    break;

                case HighlightBackgroundSelection.kNoneSelected:
                    currentSlide.DeleteIndicator();
                    currentSlide.DeleteShapesWithPrefix("PPTLabsHighlightBackgroundShape");
                    shapesToUse = GetAllUsableShapesInSlide(currentSlide);
                    break;

                default:
                    break;
                }

                Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect();
                Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(currentSlide.Index);

                if (shapesToUse == null || shapesToUse.Count == 0)
                {
                    return;
                }

                SelectOldShapesToAnimate(currentSlide, shapesToUse);
                bool newShapesAdded = AddNewShapesToAnimate(currentSlide, shapesToUse, selectedText);

                if (newShapesAdded)
                {
                    bool oldValue = AnimateInSlide.frameAnimationChecked;
                    AnimateInSlide.frameAnimationChecked = false;
                    AnimateInSlide.isHighlightBullets    = true;
                    AnimateInSlide.AddAnimationInSlide();
                    AnimateInSlide.frameAnimationChecked = oldValue;
                    PowerPointPresentation.Current.AddAckSlide();
                }
                Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect();
            }
            catch (Exception e)
            {
                PowerPointLabsGlobals.LogException(e, "AddHighlightBulletsBackground");
                throw;
            }
        }
        public static void AddHighlightBulletsBackground()
        {
            try
            {
                PowerPointSlide currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide;
                currentSlide.Name = "PPTLabsHighlightBulletsSlide" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

                PowerPoint.ShapeRange selectedShapes = null;
                Office.TextRange2     selectedText   = null;

                //Get shapes to consider for animation
                List <PowerPoint.Shape> shapesToUse = null;
                switch (userSelection)
                {
                case HighlightBackgroundSelection.kShapeSelected:
                    selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange;
                    shapesToUse    = GetShapesToUse(currentSlide, selectedShapes);
                    break;

                case HighlightBackgroundSelection.kTextSelected:
                    selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange;
                    selectedText   = Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange2.TrimText();
                    shapesToUse    = GetShapesToUse(currentSlide, selectedShapes);
                    break;

                case HighlightBackgroundSelection.kNoneSelected:
                    currentSlide.DeleteIndicator();
                    shapesToUse = GetAllUsableShapesInSlide(currentSlide);
                    break;

                default:
                    break;
                }

                Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect();
                Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(currentSlide.Index);

                if (shapesToUse == null || shapesToUse.Count == 0)
                {
                    return;
                }

                SelectOldShapesToAnimate(currentSlide, shapesToUse);
                bool newShapesAdded = AddNewShapesToAnimate(currentSlide, shapesToUse, selectedText);

                if (newShapesAdded)
                {
                    bool oldValue = AnimationLabSettings.IsUseFrameAnimation;
                    AnimationLabSettings.IsUseFrameAnimation = false;
                    AnimateInSlide.AddAnimationInSlide(isHighlightBullets: true);
                    AnimationLabSettings.IsUseFrameAnimation = oldValue;
                    PowerPointPresentation.Current.AddAckSlide();
                }

                if (currentSlide.HasAnimationForClick(clickNumber: 1))
                {
                    Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview");
                }

                Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect();
            }
            catch (Exception e)
            {
                Logger.LogException(e, "AddHighlightBulletsBackground");
                throw;
            }
        }