コード例 #1
0
        public static void SyncTextRange(TextRange2 refTextRange, TextRange2 candidateTextRange,
                                         bool pickupTextContent = true, bool pickupTextFormat = true)
        {
            bool originallyHadNewLine = candidateTextRange.Text.EndsWith("\r");
            bool lostTheNewLine       = false;

            string candidateText = candidateTextRange.Text.TrimEnd('\r');

            if (pickupTextFormat)
            {
                // pick up format using copy-paste, since we could not deep copy the format
                refTextRange.Copy();
                candidateTextRange.PasteSpecial(MsoClipboardFormat.msoClipboardFormatNative);
                lostTheNewLine = !candidateTextRange.Text.EndsWith("\r");
            }

            if (!pickupTextContent)
            {
                candidateTextRange.Text = candidateText;

                // Handling an uncommon edge case. If we are not copying paragraph content, only format,
                // Sometimes (when the reference paragraph doesn't end with a newline), the newline will be lost after copy.
                if (originallyHadNewLine && lostTheNewLine)
                {
                    candidateTextRange.Text = candidateTextRange.Text + "\r";
                }
            }

            if (refTextRange.Text.Trim().Equals(""))
            {
                candidateTextRange.Text = " ";
            }
        }
コード例 #2
0
        /// <summary>
        /// Applies font highlighting by section to the text in the bullet agenda.
        /// Set currentSection to the first section for everything to be unvisited.
        /// Set currentSection to AgendaSection.None for everything to be visited.
        /// </summary>
        private static void ApplyBulletFormats(TextRange2 textRange, BulletFormats bulletFormats, AgendaSection currentSection)
        {
            // - 1 because first section in agenda is at index 2 (exclude first section)
            int focusIndex = currentSection.IsNone() ? int.MaxValue : currentSection.Index - 1;

            textRange.Font.StrikeThrough = MsoTriState.msoFalse;

            for (var i = 1; i <= textRange.Paragraphs.Count; i++)
            {
                var currentParagraph = textRange.Paragraphs[i];

                if (i == focusIndex)
                {
                    Graphics.SyncTextRange(bulletFormats.Highlighted, currentParagraph, pickupTextContent: false);
                }
                else if (i < focusIndex)
                {
                    Graphics.SyncTextRange(bulletFormats.Visited, currentParagraph, pickupTextContent: false);
                }
                else
                {
                    Graphics.SyncTextRange(bulletFormats.Unvisited, currentParagraph, pickupTextContent: false);
                }
            }
        }
コード例 #3
0
        public void ApplyTextboxEffect(string overlayColor, int transparency, int fontSizeToIncrease)
        {
            Microsoft.Office.Interop.PowerPoint.Shape shape = Util.ShapeUtil.GetTextShapeToProcess(Shapes);
            if (shape == null)
            {
                return;
            }

            int margin = CalculateTextBoxMargin(fontSizeToIncrease);

            // multiple paragraphs..
            foreach (TextRange2 textRange in shape.TextFrame2.TextRange.Paragraphs)
            {
                if (StringUtil.IsNotEmpty(textRange.TrimText().Text))
                {
                    TextRange2 paragraph = textRange.TrimText();
                    float      left      = paragraph.BoundLeft - margin;
                    float      top       = paragraph.BoundTop - margin;
                    float      width     = paragraph.BoundWidth + margin * 2;
                    float      height    = paragraph.BoundHeight + margin * 2;

                    Microsoft.Office.Interop.PowerPoint.Shape overlayShape = ApplyOverlayEffect(overlayColor, transparency,
                                                                                                left, top, width, height);
                    ChangeName(overlayShape, EffectName.TextBox);
                    Utils.ShapeUtil.MoveZToJustBehind(overlayShape, shape);
                }
            }
        }
コード例 #4
0
ファイル: MockTextFrame2.cs プロジェクト: parris/tilda
 public MockTextFrame2(TextRange2 tr = null)
 {
     if (tr == null)
         textRange = new MockTextRange2("",this);
     else
         textRange = tr;
 }
コード例 #5
0
        public string SelectAllTextInShape(string shapeName)
        {
            Shape      shape     = CurrentSlide.Shapes.Cast <Shape>().FirstOrDefault(sh => sh.Name == shapeName);
            TextRange2 textRange = shape.TextFrame2.TextRange;

            textRange.Select();
            return(textRange.Text);
        }
コード例 #6
0
ファイル: TildaTextbox.cs プロジェクト: pengxinglove/tilda
        /**
         * Finds the level of indentation between bullets and text at each paragraph.
         * @param TextRange to look up indentation levels on.
         * @return float[] contains 2 values FirstMargin (where the bullet is) and LeftMargin (where the text starts)
         */
        private float[] findIndentSpacing(TextRange2 t)
        {
            ParagraphFormat2 pg = t.ParagraphFormat;

            return(new float[2] {
                (pg.LeftIndent + pg.FirstLineIndent) * this.scaler, pg.LeftIndent *this.scaler
            });
        }
コード例 #7
0
        public string SelectTextInShape(string shapeName, int startIndex, int endIndex)
        {
            Shape      shape     = CurrentSlide.Shapes.Cast <Shape>().FirstOrDefault(sh => sh.Name == shapeName);
            TextRange2 textRange = shape.TextFrame2.TextRange.Characters[startIndex, endIndex - startIndex];

            textRange.Select();
            return(textRange.Text);
        }
コード例 #8
0
ファイル: TildaTextbox.cs プロジェクト: pengxinglove/tilda
        /**
         * Will render this Text shape to RaphJS code
         * @see currentHeight (private member) will be modified and read by this method.
         * @see PowerPoint.Shape, PowerPoint.TextFrame, PowerPoint.TextRange for more information about
         * what this method expects.
         * @see Settings.Scaler()
         * @return String representing RaphJS code
         */
        public override String toRaphJS()
        {
            this.currentHeight = 0;
            String js = "";

            this.currentHeight = this.findY();
            double shapeX = this.findX();

            for (int i = 0; i < paragraphs.Count; i++)
            {
                js += "idsToAnimate = new Array();";
                TextRange2     paragraph = paragraphs.ElementAt(i);
                TildaAnimation found     = null;
                //find animation
                foreach (TildaAnimation animation in animations)
                {
                    try {
                        if (found == null && this.shape.Id.Equals(animation.shape.shape.Id) && i == animation.effect.Paragraph - 1)
                        {
                            found = animation;
                        }
                    } catch { } // this is obviously not the animation we are looking for; however, just throw it away rather than complaining
                }

                //add spacing above this line
                if (this.isBottomOrBaseLine())
                {
                    this.currentHeight -= (paragraph.ParagraphFormat.SpaceAfter) * this.scaler;
                }
                else
                {
                    this.currentHeight += (paragraph.ParagraphFormat.SpaceBefore) * this.scaler;
                }

                double xAdd = 0;
                if ((PpBulletType)paragraph.ParagraphFormat.Bullet.Type != PpBulletType.ppBulletNone)
                {
                    float[] offsets      = this.findIndentSpacing(paragraph);
                    float   bulletXSpace = offsets[0];
                    float   bulletSize   = paragraph.Font.Size / 4 * this.scaler; // seems correct

                    js   += this.renderBullet(paragraph, (shapeX + bulletXSpace), (this.currentHeight - bulletSize / 2), found);
                    xAdd += offsets[1] + bulletSize;
                }

                foreach (TextRange2 line in this.getLines(paragraph.Lines))
                {
                    js += this.renderLine(line, xAdd, found);
                }

                if (found != null)
                {
                    js += "preso.animations.push({'ids':idsToAnimate,'dur':" + found.effect.Timing.Duration * 1000 + ",'delay':" + found.effect.Timing.TriggerDelayTime * 1000 + ",animate:{'fill-opacity':1,'stroke-opacity':1,'opacity':1}});";
                }
            }
            return(js);
        }
コード例 #9
0
ファイル: Graphics.cs プロジェクト: suheti/powerpointlabs
        public static TextRange ConvertTextRange2ToTextRange(TextRange2 textRange2)
        {
            var textFrame2 = textRange2.Parent as TextFrame2;

            if (textFrame2 == null) return null;

            var shape = textFrame2.Parent as Shape;

            return shape == null ? null : shape.TextFrame.TextRange;
        }
コード例 #10
0
 public MockTextFrame2(TextRange2 tr = null)
 {
     if (tr == null)
     {
         textRange = new MockTextRange2("", this);
     }
     else
     {
         textRange = tr;
     }
 }
コード例 #11
0
        private void ChangeChartTitle(Chart thisChart, Chart tempChart)
        {
            TextRange2 thisTextRange = thisChart.ChartTitle.Format.TextFrame2.TextRange;
            TextRange2 tempTextRange = tempChart.ChartTitle.Format.TextFrame2.TextRange;

            thisTextRange.Font.Fill.ForeColor.RGB = tempTextRange.Font.Fill.ForeColor.RGB;
            thisTextRange.Font.Italic             = tempTextRange.Font.Italic;
            thisTextRange.Font.Size    = tempTextRange.Font.Size;
            thisTextRange.Font.Spacing = tempTextRange.Font.Spacing;
            thisTextRange.Font.Bold    = tempTextRange.Font.Bold;
        }
コード例 #12
0
        public string SelectTextInShape(string shapeName, int startIndex, int endIndex)
        {
            Shape shape = FunctionalTestExtensions.GetCurrentSlide().Shapes
                          .Cast <Shape>()
                          .FirstOrDefault(sh => sh.Name == shapeName);

            shape.Select(); // shape needs to be selected first in 2010
            TextRange2 textRange = shape.TextFrame2.TextRange.Characters[startIndex, endIndex - startIndex];

            textRange.Select();
            return(textRange.Text);
        }
コード例 #13
0
        public static TextRange ConvertTextRange2ToTextRange(TextRange2 textRange2)
        {
            TextFrame2 textFrame2 = textRange2.Parent as TextFrame2;

            if (textFrame2 == null)
            {
                return(null);
            }

            Shape shape = textFrame2.Parent as Shape;

            return(shape == null ? null : shape.TextFrame.TextRange);
        }
コード例 #14
0
        public static void SyncShape(Shape refShape, Shape candidateShape,
                                     bool pickupShapeBasic  = true, bool pickupShapeFormat = true,
                                     bool pickupTextContent = true, bool pickupTextFormat  = true)
        {
            if (pickupShapeBasic)
            {
                SyncShapeRotation(refShape, candidateShape);
                SyncShapeSize(refShape, candidateShape);
                SyncShapeLocation(refShape, candidateShape);
            }


            if (pickupShapeFormat)
            {
                refShape.PickUp();
                candidateShape.Apply();
            }

            if ((pickupTextContent || pickupTextFormat) &&
                refShape.HasTextFrame == MsoTriState.msoTrue &&
                candidateShape.HasTextFrame == MsoTriState.msoTrue)
            {
                TextRange2 refTextRange       = refShape.TextFrame2.TextRange;
                TextRange2 candidateTextRange = candidateShape.TextFrame2.TextRange;

                if (pickupTextContent)
                {
                    candidateTextRange.Text = refTextRange.Text;
                }

                int refParagraphCount       = refShape.TextFrame2.TextRange.Paragraphs.Count;
                int candidateParagraphCount = candidateShape.TextFrame2.TextRange.Paragraphs.Count;

                if (refParagraphCount > 0)
                {
                    string originalText = candidateTextRange.Text;
                    SyncTextRange(refTextRange.Paragraphs[refParagraphCount], candidateTextRange);
                    candidateTextRange.Text = originalText;
                }

                for (int i = 1; i <= candidateParagraphCount; i++)
                {
                    TextRange2 refParagraph       = refTextRange.Paragraphs[i <= refParagraphCount ? i : refParagraphCount];
                    TextRange2 candidateParagraph = candidateTextRange.Paragraphs[i];

                    SyncTextRange(refParagraph, candidateParagraph, pickupTextContent, pickupTextFormat);
                }
            }
        }
コード例 #15
0
ファイル: TildaTextbox.cs プロジェクト: pengxinglove/tilda
        private List <TextRange2> getLines(TextRange2 lines)
        {
            List <TextRange2> trlines = new List <TextRange2>();

            foreach (TextRange2 line in lines)
            {
                trlines.Add(line);
            }

            if (this.isBottomOrBaseLine())
            {
                trlines.Reverse();
            }

            return(trlines);
        }
コード例 #16
0
ファイル: TildaTextbox.cs プロジェクト: pengxinglove/tilda
        /**
         * Renders a Line of Text to RaphJS code
         * @see currentHeight (private member) will be modified and read by this method.
         * @param TextRange that represents the line of text
         * @param double x position offset if needed
         * @param TildaAnimation object containing a powerpoint animation, or just null if no animation
         * @return String containing the RaphJS code representing this bullet
         */
        private String renderLine(TextRange2 line, double xOffset, TildaAnimation anim = null)
        {
            //push current height position up to write the text in the right place if going bottom up
            if (this.isBottomOrBaseLine())
            {
                this.currentHeight -= (line.Font.Size * this.scaler);
            }

            string font      = this.fontStyle(line);
            string transform = this.transformation();
            var    fontpos   = this.fontPosition((float)(xOffset), (float)(this.currentHeight - this.findY()));

            String textbox = "preso.shapes.push(preso.paper.text(" + (this.findX() + xOffset) + "," + this.currentHeight + ",'" + line.Text.Replace("\r", "").Replace("\v", "") + "').attr({" + font + "," + transform + "," + fontpos + "}));";

            if (anim != null)
            {
                textbox += "idsToAnimate.push(preso.shapes.length-1);";
                textbox += "preso.shapes[(preso.shapes.length-1)].attr({'fill-opacity':0,'stroke-opacity':0,'opacity':0});";
            }

            //push the current height position
            if (this.isBottomOrBaseLine())
            {
                this.currentHeight -= (line.ParagraphFormat.SpaceBefore) * this.scaler;
            }
            else
            {
                this.currentHeight += (line.Font.Size + line.ParagraphFormat.SpaceAfter) * this.scaler;
            }


            //add some extra spacing, I tried to be mathematical about it, but I don't know where it is coming from
            //it looks like 1/4 the line height, but spread above and below it, the other half of this is before the bullet
            if ((PpBulletType)line.ParagraphFormat.Bullet.Type != PpBulletType.ppBulletNone)
            {
                if (this.isBottomOrBaseLine())
                {
                    this.currentHeight -= ((line.Font.Size * this.scaler) / 8);
                }
                else
                {
                    this.currentHeight += ((line.Font.Size * this.scaler) / 8);
                }
            }
            return(textbox);
        }
コード例 #17
0
ファイル: TildaTextbox.cs プロジェクト: pengxinglove/tilda
        /**
         * JSON Object attributes for font style of a line of text
         * @param TextRange to look up information on, if none specifed then this this.shape's TextRange is found and used
         * @return String representing JSON attributes of font style as per RaphaelJS specifications
         */
        public String fontStyle(TextRange2 range = null)
        {
            if (range == null)
            {
                range = shape.TextFrame2.TextRange;
            }
            String js = "'font-size':'" + scaler * range.Font.Size + "','fill':'" + this.rgbToHex(range.Font.Fill.ForeColor.RGB) + "'";

            if (range.Font.Bold == MsoTriState.msoCTrue || range.Font.Bold == MsoTriState.msoTrue)
            {
                js += ",'font-weight':'bold'";
            }
            if (range.Font.Italic == MsoTriState.msoCTrue || range.Font.Italic == MsoTriState.msoTrue)
            {
                js += ",'font-family':'" + range.Font.Name + " italic'";
            }
            else
            {
                js += ",'font-family':'" + range.Font.Name + "'";
            }
            return(js);
        }
コード例 #18
0
        public void ApplyFrostedGlassTextBoxEffect(string overlayColor, int transparency, Shape blurImage, int fontSizeToIncrease)
        {
            Shape shape = Util.ShapeUtil.GetTextShapeToProcess(Shapes);

            if (shape == null)
            {
                return;
            }

            int margin = CalculateTextBoxMargin(fontSizeToIncrease);

            // multiple paragraphs..
            foreach (TextRange2 textRange in shape.TextFrame2.TextRange.Paragraphs)
            {
                if (StringUtil.IsNotEmpty(textRange.TrimText().Text))
                {
                    TextRange2 paragraph = textRange.TrimText();
                    float      left      = paragraph.BoundLeft - margin;
                    float      top       = paragraph.BoundTop - margin;
                    float      width     = paragraph.BoundWidth + margin * 2;
                    float      height    = paragraph.BoundHeight + margin * 2;

                    Shape blurTextBox = blurImage.Duplicate()[1];
                    blurTextBox.Left = blurImage.Left;
                    blurTextBox.Top  = blurImage.Top;
                    CropPicture(blurTextBox, left, top, width, height);
                    ChangeName(blurTextBox, EffectName.TextBox);

                    Shape overlayShape = ApplyOverlayEffect(overlayColor, transparency,
                                                            left, top, width, height);
                    ChangeName(overlayShape, EffectName.TextBox);

                    Utils.ShapeUtil.MoveZToJustBehind(blurTextBox, shape);
                    Utils.ShapeUtil.MoveZToJustBehind(overlayShape, shape);
                }
            }
        }
コード例 #19
0
ファイル: TildaTextbox.cs プロジェクト: parris/tilda
 /**
  * Finds the level of indentation between bullets and text at each paragraph.
  * @param TextRange to look up indentation levels on.
  * @return float[] contains 2 values FirstMargin (where the bullet is) and LeftMargin (where the text starts)
  */
 private float[] findIndentSpacing(TextRange2 t)
 {
     ParagraphFormat2 pg = t.ParagraphFormat;
     return new float[2] { (pg.LeftIndent + pg.FirstLineIndent) * this.scaler, pg.LeftIndent * this.scaler };
 }
コード例 #20
0
ファイル: TildaTextbox.cs プロジェクト: parris/tilda
 /**
  * JSON Object attributes for font style of a line of text
  * @param TextRange to look up information on, if none specifed then this this.shape's TextRange is found and used
  * @return String representing JSON attributes of font style as per RaphaelJS specifications
  */
 public String fontStyle(TextRange2 range = null)
 {
     if(range == null)
         range = shape.TextFrame2.TextRange;
     String js = "'font-size':'" + scaler * range.Font.Size + "','fill':'" + this.rgbToHex(range.Font.Fill.ForeColor.RGB) + "'";
     if(range.Font.Bold == MsoTriState.msoCTrue || range.Font.Bold == MsoTriState.msoTrue)
         js += ",'font-weight':'bold'";
     if(range.Font.Italic == MsoTriState.msoCTrue || range.Font.Italic == MsoTriState.msoTrue)
         js += ",'font-family':'" + range.Font.Name + " italic'";
     else
         js += ",'font-family':'" + range.Font.Name + "'";
     return js;
 }
コード例 #21
0
ファイル: TildaTextbox.cs プロジェクト: parris/tilda
        /**
         * Looks up information about a bullet and creates RaphJS code to render it
         * @see currentHeight (private member) will be modified and read by this method.
         * @param TextRange the paragraph that has a bullet
         * @param double x position of the bullet
         * @param double y position of the bullet
         * @param TildaAnimation object containing a powerpoint animation, or just null if no animation
         * @return String containing the RaphJS code representing this bullet
         */
        private String renderBullet(TextRange2 t, double x, double y, TildaAnimation anim = null)
        {
            String js = "";

            //no bullet if no text
            if(t.Text == "" || t.Text == "\r")
                return js;

            //add some extra spacing, I tried to be mathematical about it, but I don't know where it is coming from
            float extraSpacing = ((t.Font.Size*this.scaler) / 8);
            y += extraSpacing;
            if(this.isBottomOrBaseLine())
                this.currentHeight -= extraSpacing;
            else
                this.currentHeight += extraSpacing;

            //relative size is set by user, this look approximately correct
            float bulletSize = (t.ParagraphFormat.Bullet.RelativeSize * (t.Font.Size / 4)) * this.scaler;
            int bullet = t.ParagraphFormat.Bullet.Character;

            // find the right color of the bullet, first try the color of the bullet itself
            // fall back to line color otherwise
            int rgb = t.ParagraphFormat.Bullet.Font.Fill.ForeColor.RGB;
            if(rgb == 0)
                rgb = t.Font.Fill.ForeColor.RGB;
            String color = this.rgbToHex(rgb);

            if(t.ParagraphFormat.Bullet.Type == MsoBulletType.msoBulletNumbered) {
                int bulletNumber = (t.ParagraphFormat.Bullet.StartValue - 1 + t.ParagraphFormat.Bullet.Number);
                String bulletText = this.numberedBullet(bulletNumber, t.ParagraphFormat.Bullet.Style);
                js += "preso.shapes.push(preso.paper.text(" + (x+bulletSize*2) + "," + this.currentHeight + ",'" + bulletText + "'" + ").attr({" + this.fontStyle(t) + "})";
            } else if(bullet == 8226) {
                double radius = bulletSize / 2;
                x += radius;
                y += radius;
                js += "preso.shapes.push(preso.paper.circle(" + x + "," + y + "," + radius + ")";
            } else // if(bullet == 167), the square
                js += "preso.shapes.push(preso.paper.rect(" + x + "," + y + "," + bulletSize + "," + bulletSize + ")";
            js += ".attr({'stroke':'" + color + "','fill':'" + color + "'}));";
            if(anim != null) {
                js += "idsToAnimate.push(preso.shapes.length-1);";
                js += "preso.shapes[(preso.shapes.length-1)].attr({'fill-opacity':0,'stroke-opacity':0});";
            }
            return js;
        }
コード例 #22
0
ファイル: TildaTextbox.cs プロジェクト: pengxinglove/tilda
        /**
         * Looks up information about a bullet and creates RaphJS code to render it
         * @see currentHeight (private member) will be modified and read by this method.
         * @param TextRange the paragraph that has a bullet
         * @param double x position of the bullet
         * @param double y position of the bullet
         * @param TildaAnimation object containing a powerpoint animation, or just null if no animation
         * @return String containing the RaphJS code representing this bullet
         */
        private String renderBullet(TextRange2 t, double x, double y, TildaAnimation anim = null)
        {
            String js = "";

            //no bullet if no text
            if (t.Text == "" || t.Text == "\r")
            {
                return(js);
            }

            //add some extra spacing, I tried to be mathematical about it, but I don't know where it is coming from
            float extraSpacing = ((t.Font.Size * this.scaler) / 8);

            y += extraSpacing;
            if (this.isBottomOrBaseLine())
            {
                this.currentHeight -= extraSpacing;
            }
            else
            {
                this.currentHeight += extraSpacing;
            }

            //relative size is set by user, this look approximately correct
            float bulletSize = (t.ParagraphFormat.Bullet.RelativeSize * (t.Font.Size / 4)) * this.scaler;
            int   bullet     = t.ParagraphFormat.Bullet.Character;

            // find the right color of the bullet, first try the color of the bullet itself
            // fall back to line color otherwise
            int rgb = t.ParagraphFormat.Bullet.Font.Fill.ForeColor.RGB;

            if (rgb == 0)
            {
                rgb = t.Font.Fill.ForeColor.RGB;
            }
            String color = this.rgbToHex(rgb);

            if (t.ParagraphFormat.Bullet.Type == MsoBulletType.msoBulletNumbered)
            {
                int    bulletNumber = (t.ParagraphFormat.Bullet.StartValue - 1 + t.ParagraphFormat.Bullet.Number);
                String bulletText   = this.numberedBullet(bulletNumber, t.ParagraphFormat.Bullet.Style);
                js += "preso.shapes.push(preso.paper.text(" + (x + bulletSize * 2) + "," + this.currentHeight + ",'" + bulletText + "'" + ").attr({" + this.fontStyle(t) + "})";
            }
            else if (bullet == 8226)
            {
                double radius = bulletSize / 2;
                x  += radius;
                y  += radius;
                js += "preso.shapes.push(preso.paper.circle(" + x + "," + y + "," + radius + ")";
            }
            else   // if(bullet == 167), the square
            {
                js += "preso.shapes.push(preso.paper.rect(" + x + "," + y + "," + bulletSize + "," + bulletSize + ")";
            }
            js += ".attr({'stroke':'" + color + "','fill':'" + color + "'}));";
            if (anim != null)
            {
                js += "idsToAnimate.push(preso.shapes.length-1);";
                js += "preso.shapes[(preso.shapes.length-1)].attr({'fill-opacity':0,'stroke-opacity':0});";
            }
            return(js);
        }
コード例 #23
0
 private BeamFormats(TextRange2 highlighted, TextRange2 regular)
 {
     Highlighted = highlighted;
     Regular = regular;
 }
コード例 #24
0
 private BulletFormats(TextRange2 visited, TextRange2 highlighted, TextRange2 unvisited)
 {
     Visited = visited;
     Highlighted = highlighted;
     Unvisited = unvisited;
 }
コード例 #25
0
ファイル: TildaTextbox.cs プロジェクト: parris/tilda
        /**
         * Renders a Line of Text to RaphJS code
         * @see currentHeight (private member) will be modified and read by this method.
         * @param TextRange that represents the line of text
         * @param double x position offset if needed
         * @param TildaAnimation object containing a powerpoint animation, or just null if no animation
         * @return String containing the RaphJS code representing this bullet
         */
        private String renderLine(TextRange2 line, double xOffset, TildaAnimation anim = null)
        {
            //push current height position up to write the text in the right place if going bottom up
            if(this.isBottomOrBaseLine())
                this.currentHeight -= (line.Font.Size * this.scaler);

            string font = this.fontStyle(line);
            string transform = this.transformation();
            var fontpos = this.fontPosition((float)(xOffset), (float)(this.currentHeight - this.findY()));

            String textbox = "preso.shapes.push(preso.paper.text(" + (this.findX() + xOffset) + "," + this.currentHeight + ",'" + line.Text.Replace("\r", "").Replace("\v", "") + "').attr({" + font + "," + transform + "," + fontpos + "}));";

            if(anim != null) {
                textbox += "idsToAnimate.push(preso.shapes.length-1);";
                textbox += "preso.shapes[(preso.shapes.length-1)].attr({'fill-opacity':0,'stroke-opacity':0,'opacity':0});";
            }

            //push the current height position
            if(this.isBottomOrBaseLine())
                this.currentHeight -= (line.ParagraphFormat.SpaceBefore) * this.scaler;
            else
                this.currentHeight += (line.Font.Size + line.ParagraphFormat.SpaceAfter) * this.scaler;

            //add some extra spacing, I tried to be mathematical about it, but I don't know where it is coming from
            //it looks like 1/4 the line height, but spread above and below it, the other half of this is before the bullet
            if((PpBulletType)line.ParagraphFormat.Bullet.Type != PpBulletType.ppBulletNone)
                if (this.isBottomOrBaseLine())
                    this.currentHeight -= ((line.Font.Size * this.scaler) / 8);
                else
                    this.currentHeight += ((line.Font.Size*this.scaler) / 8);
            return textbox;
        }
コード例 #26
0
        /// <summary>
        /// Append text with current internal formatting to the end of text range.
        /// </summary>
        /// <param name="range">Text range</param>
        /// <param name="text">Appended text</param>
        public void AppendText(TextRange2 range, string text)
        {
            int start = range.Text.Length;

            text = text.Replace("\r\n", "\r");
            text = text.Replace("\n", "\r");

            // filter spaces (no space at beginning of line, and no space after space)
            if (text.StartsWith(" ") && (range.Text.EndsWith(" ") || range.Text.EndsWith("\u00A0") || range.Text.Length == 0 || range.Text.EndsWith("\r")))
                text = text.TrimStart(' ');

            if (text.Length > 0)
                range.InsertAfter(text);
            else
                return;

            // apply formatting only if there were changes (experimental!)
            if (_changed)
            {
                TextRange2 format = range.Characters[start + 1, text.Length];

                // check used color, if color is null set default theme color
                if (_currentSettings.Color != null)
                    format.Font.Fill.ForeColor.RGB = (int) _currentSettings.Color;
                else
                    format.Font.Fill.ForeColor.ObjectThemeColor = MsoThemeColorIndex.msoThemeColorText1;

                format.Font.Bold = _currentSettings.Bold;
                format.Font.Italic = _currentSettings.Italic;
                format.Font.Name = _currentSettings.FontFamily;
                format.Font.UnderlineStyle = _currentSettings.Underline;
                format.Font.Smallcaps = _currentSettings.Smallcaps;
                format.Font.Size = _currentSettings.FontSize;
                _changed = false;
            }
        }
コード例 #27
0
 private BulletFormats(TextRange2 visited, TextRange2 highlighted, TextRange2 unvisited)
 {
     Visited     = visited;
     Highlighted = highlighted;
     Unvisited   = unvisited;
 }
コード例 #28
0
ファイル: TildaTextbox.cs プロジェクト: parris/tilda
        private List<TextRange2> getLines(TextRange2 lines)
        {
            List<TextRange2> trlines = new List<TextRange2>();
            foreach(TextRange2 line in lines)
                trlines.Add(line);

            if(this.isBottomOrBaseLine())
                trlines.Reverse();

            return trlines;
        }
コード例 #29
0
        /// <summary>
        /// Applies font highlighting by section to the text in the bullet agenda.
        /// Set currentSection to the first section for everything to be unvisited.
        /// Set currentSection to AgendaSection.None for everything to be visited.
        /// </summary>
        private static void ApplyBulletFormats(TextRange2 textRange, BulletFormats bulletFormats, AgendaSection currentSection)
        {
            // - 1 because first section in agenda is at index 2 (exclude first section)
            int focusIndex = currentSection.IsNone() ? int.MaxValue : currentSection.Index - 1;

            textRange.Font.StrikeThrough = MsoTriState.msoFalse;

            for (var i = 1; i <= textRange.Paragraphs.Count; i++)
            {
                var currentParagraph = textRange.Paragraphs[i];

                if (i == focusIndex)
                {
                    Graphics.SyncTextRange(bulletFormats.Highlighted, currentParagraph, pickupTextContent: false);
                }
                else if (i < focusIndex)
                {
                    Graphics.SyncTextRange(bulletFormats.Visited, currentParagraph, pickupTextContent: false);
                }
                else
                {
                    Graphics.SyncTextRange(bulletFormats.Unvisited, currentParagraph, pickupTextContent: false);
                }
            }
        }
コード例 #30
0
ファイル: Graphics.cs プロジェクト: youthinkk/PowerPointLabs
        public static void SyncTextRange(TextRange2 refTextRange, TextRange2 candidateTextRange,
                                         bool pickupTextContent = true, bool pickupTextFormat = true)
        {
            bool originallyHadNewLine = candidateTextRange.Text.EndsWith("\r");
            bool lostTheNewLine = false;

            var candidateText = candidateTextRange.Text.TrimEnd('\r');

            if (pickupTextFormat)
            {
                // pick up format using copy-paste, since we could not deep copy the format
                refTextRange.Copy();
                candidateTextRange.PasteSpecial(MsoClipboardFormat.msoClipboardFormatNative);
                lostTheNewLine = !candidateTextRange.Text.EndsWith("\r");
            }

            if (!pickupTextContent)
            {
                candidateTextRange.Text = candidateText;

                // Handling an uncommon edge case. If we are not copying paragraph content, only format,
                // Sometimes (when the reference paragraph doesn't end with a newline), the newline will be lost after copy.
                if (originallyHadNewLine && lostTheNewLine)
                {
                    candidateTextRange.Text = candidateTextRange.Text + "\r";
                }
            }
        }
コード例 #31
0
 private BeamFormats(TextRange2 highlighted, TextRange2 regular)
 {
     Highlighted = highlighted;
     Regular     = regular;
 }
コード例 #32
0
ファイル: AdFormatter.cs プロジェクト: ShomreiTorah/Journal
			public void Apply(TextRange2 range) {
				if (FontFamily != null) range.Font.Name = FontFamily;
				if (FontSize != null) range.Font.Size = FontSize.Value;
				if (Bold != null) range.Font.Bold = ToTriState(Bold.Value);
				if (Italic != null) range.Font.Italic = ToTriState(Italic.Value);
				if (AllCaps != null) range.Font.Allcaps = ToTriState(AllCaps.Value);
				if (SmallCaps != null) range.Font.Smallcaps = ToTriState(SmallCaps.Value);
				if (Alignment != null) range.ParagraphFormat.Alignment = Alignment.Value;
			}