Пример #1
0
        public AddRectangleTool(IToolService toolService, IUndoRedoService undoRedo,
                                ICommonNodeFactory commonNodeFactory, IAmDiBasedObjectFactory objectFactory, IImage image, IMovie movie, bool text)
        {
            this.toolService = toolService;
            this.undoRedo    = undoRedo;
            if (text)
            {
                entity = commonNodeFactory.RichTextRectangle(objectFactory.Create <RichText>());
            }
            else if (movie != null)
            {
                entity = commonNodeFactory.MovieRectangleNode(movie);
            }
            else if (image != null)
            {
                entity = commonNodeFactory.ImageRectangleNode(image);
            }
            else
            {
                entity = commonNodeFactory.ColorRectangleNode(GetRandomSaturatedColor());
            }
            rectangleComponent = entity.GetComponent <IRectangleComponent>();

            if (movie != null)
            {
                aspectRatio         = (float)movie.Width / Math.Max(movie.Height, 1);
                preserveAspectRatio = true;
            }
            else if (image != null)
            {
                aspectRatio         = (float)image.Size.Width / Math.Max(image.Size.Height, 1);
                preserveAspectRatio = true;
            }

            state = State.Ready;
        }
Пример #2
0
        private void LoadTextShape(ConversionContext context, Shape shape)
        {
            var richText = AmFactory.Create <RichText>();
            var style    = AmFactory.Create <RtOverallStyle>();

            style.TransparencyMode = RtTransparencyMode.Opaque;
            style.BackgroundColor  = context.CurrentSlide.Background.Fill.ForeColor.ToClarity();
            richText.Style         = style;

            foreach (TextRange ppPara in shape.TextFrame.TextRange.Paragraphs())
            {
                var cPara = AmFactory.Create <RtParagraph>();
                cPara.Style.Alignment = ppPara.ParagraphFormat.Alignment.ToClarity() ?? RtParagraphAlignment.Left;
                cPara.Style.Direction = ppPara.ParagraphFormat.TextDirection.ToClarity() ?? RtParagraphDirection.LeftToRight;
                cPara.Style.ListType  = ppPara.ParagraphFormat.Bullet.Type.ToClarity() ?? RtListType.None;
                // todo: bullet conversion
                // todo: correct margin conversion
                cPara.Style.MarginUp = ppPara.ParagraphFormat.SpaceBefore * 512 / context.PpPresentation.PageSetup.SlideHeight;
                cPara.Style.TabCount = cPara.Style.ListType == RtListType.None
                    ? ppPara.IndentLevel - 1
                    : ppPara.IndentLevel;

                foreach (TextRange ppRun in ppPara.Runs())
                {
                    var cSpan = AmFactory.Create <RtPureSpan>();

                    cSpan.Style.FontDecoration = FontDecoration.None;
                    if (ppRun.Font.Bold == MsoTriState.msoTrue)
                    {
                        cSpan.Style.FontDecoration |= FontDecoration.Bold;
                    }
                    if (ppRun.Font.Italic == MsoTriState.msoTrue)
                    {
                        cSpan.Style.FontDecoration |= FontDecoration.Italic;
                    }
                    // todo: Strikethrough
                    if (ppRun.Font.Underline == MsoTriState.msoTrue)
                    {
                        cSpan.Style.FontDecoration |= FontDecoration.Underline;
                    }

                    cSpan.Style.FontFamily = ppRun.Font.Name;
                    // todo: set actual size and compensate some other way
                    cSpan.Style.Size      = (int)(ppRun.Font.Size * 512f / 360f);
                    cSpan.Style.TextColor = ppRun.Font.Color.ToClarity();

                    cSpan.Text = ppRun.Text; // remove \r ?

                    cPara.Spans.Add(cSpan);
                }

                richText.Paragraphs.Add(cPara);
            }

            var textNode = commonNodeFactory.RichTextRectangle(richText);

            textNode.Id   = context.GetNewId();
            textNode.Name = shape.Name;
            var cRect = textNode.GetComponent <IRectangleComponent>();

            cRect.Rectangle = GetShapeRectangle(context, shape);

            context.CurrentSlideNode.ChildNodes.Add(textNode);
        }