/// <summary>
        /// Initializes a new instance of the <see cref="CellFormat"/> class.
        /// </summary>
        /// <param name="outerBorders">OPTIONAL borders to apply to the cell, in the order that they should be applied.  DEFAULT is no border.</param>
        /// <param name="backgroundColor">OPTIONAL background color of the cell.  DEFAULT is to leave the background color unchanged.</param>
        /// <param name="fontFormat">OPTIONAL font format.  DEFAULT is to leave the font unchanged.</param>
        /// <param name="verticalAlignment">OPTIONAL vertical alignment.  DEFAULT is to leave the vertical alignment unchanged.</param>
        /// <param name="horizontalAlignment">OPTIONAL horizontal alignment.  DEFAULT is to leave the horizontal alignment unchanged.</param>
        /// <param name="fontRotationAngle">OPTIONAL font rotation angle, between +90 and -90.  Positive numbers cause the text to slope upward, negative numbers cause the text to slope downward.  DEFAULT is to leave the font rotation angle unchanged.</param>
        /// <param name="fillPattern">OPTIONAL pattern to fill the cell with.  DEFAULT is no pattern.</param>
        /// <param name="options">OPTIONAL formatting options to apply to the cell.  DEFAULT is to not apply any of the formatting options.</param>
        public CellFormat(
            IReadOnlyList <OuterBorder> outerBorders = null,
            FontFormat fontFormat = null,
            Color?backgroundColor = null,
            VerticalAlignment?verticalAlignment     = null,
            HorizontalAlignment?horizontalAlignment = null,
            int?fontRotationAngle     = null,
            FillPattern fillPattern   = null,
            CellFormatOptions?options = null)
            : base(outerBorders)
        {
            if (verticalAlignment == DataStructure.VerticalAlignment.Unknown)
            {
                throw new ArgumentOutOfRangeException(Invariant($"{nameof(verticalAlignment)} is {nameof(DataStructure.VerticalAlignment.Unknown)}."));
            }

            if (horizontalAlignment == DataStructure.HorizontalAlignment.Unknown)
            {
                throw new ArgumentOutOfRangeException(Invariant($"{nameof(horizontalAlignment)} is {nameof(DataStructure.HorizontalAlignment.Unknown)}."));
            }

            this.FontFormat          = fontFormat;
            this.BackgroundColor     = backgroundColor;
            this.VerticalAlignment   = verticalAlignment;
            this.HorizontalAlignment = horizontalAlignment;
            this.FontRotationAngle   = fontRotationAngle;
            this.FillPattern         = fillPattern;
            this.Options             = options;
        }
예제 #2
0
        protected internal virtual void ApplyVerticalAlignment()
        {
            VerticalAlignment?verticalAlignment = this.GetProperty <VerticalAlignment?>(Property.VERTICAL_ALIGNMENT);

            if (verticalAlignment != null && verticalAlignment != VerticalAlignment.TOP && childRenderers.Count > 0)
            {
                float deltaY = childRenderers[childRenderers.Count - 1].GetOccupiedArea().GetBBox().GetY() - GetInnerAreaBBox
                                   ().GetY();
                switch (verticalAlignment)
                {
                case VerticalAlignment.BOTTOM: {
                    foreach (IRenderer child in childRenderers)
                    {
                        child.Move(0, -deltaY);
                    }
                    break;
                }

                case VerticalAlignment.MIDDLE: {
                    foreach (IRenderer child_1 in childRenderers)
                    {
                        child_1.Move(0, -deltaY / 2);
                    }
                    break;
                }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Compute a vector that would move a bounding box into alignment with another bounding box.
        /// </summary>
        /// <param name="diagramToMove"></param>
        /// <param name="diagramToCompare"></param>
        /// <param name="verticalAlignment"></param>
        /// <param name="horizontalAlignment"></param>
        /// <returns></returns>
        public static Vector ComputeAlignment(
            BoundingBox boundsToMove,
            BoundingBox boundsToCompare,
            VerticalAlignment?verticalAlignment,
            HorizontalAlignment?horizontalAlignment)
        {
            var verticalOffset =
                verticalAlignment switch
            {
                VerticalAlignment.Bottom => boundsToCompare.YMin - boundsToMove.YMin,
                VerticalAlignment.Top => boundsToCompare.YMax - boundsToMove.YMax,
                VerticalAlignment.Center => boundsToCompare.Center().Y - boundsToMove.Center().Y,
                _ => 0M
            };

            var horizontalOffset =
                horizontalAlignment switch
            {
                HorizontalAlignment.Left => boundsToCompare.XMin - boundsToMove.XMin,
                HorizontalAlignment.Right => boundsToCompare.XMax - boundsToMove.XMax,
                HorizontalAlignment.Center => boundsToCompare.Center().X - boundsToMove.Center().X,
                _ => 0M
            };

            return(new Vector(horizontalOffset, verticalOffset));
        }
예제 #4
0
        public virtual void SetVerticalAlignmentBottomTest()
        {
            VerticalAlignment?expectedAlignment = VerticalAlignment.BOTTOM;
            Style             style             = new Style();

            NUnit.Framework.Assert.IsNull(style.GetProperty <VerticalAlignment?>(Property.VERTICAL_ALIGNMENT));
            style.SetVerticalAlignment(expectedAlignment);
            NUnit.Framework.Assert.AreEqual(expectedAlignment, style.GetProperty <VerticalAlignment?>(Property.VERTICAL_ALIGNMENT
                                                                                                      ));
        }
예제 #5
0
 /// <summary>
 /// Compute a vector that would move a diagram into alignment with the other diagram.
 /// </summary>
 /// <param name="diagramToMove"></param>
 /// <param name="diagramToCompare"></param>
 /// <param name="verticalAlignment"></param>
 /// <param name="horizontalAlignment"></param>
 /// <returns></returns>
 public static Vector ComputeAlignment(
     IDiagram diagramToMove,
     IDiagram diagramToCompare,
     VerticalAlignment?verticalAlignment,
     HorizontalAlignment?horizontalAlignment) =>
 ComputeAlignment(
     diagramToMove.Bounds,
     diagramToCompare.Bounds,
     verticalAlignment,
     horizontalAlignment);
예제 #6
0
        private static Cell GetCell(Paragraph p, VerticalAlignment?verticalAlignment)
        {
            Cell cell = new Cell();

            cell.SetVerticalAlignment(verticalAlignment);
            p.SetMargin(2);
            p.SetMultipliedLeading(1);
            cell.Add(p);
            return(cell);
        }
예제 #7
0
        /// <summary>Convenience method to write a text aligned about the specified point</summary>
        /// <param name="p">
        /// paragraph of text to be placed to the page. By default it has no leading and is written in single line.
        /// Set width to write multiline text.
        /// </param>
        /// <param name="x">the point about which the text will be aligned and rotated</param>
        /// <param name="y">the point about which the text will be aligned and rotated</param>
        /// <param name="pageNumber">the page number to write the text</param>
        /// <param name="textAlign">horizontal alignment about the specified point</param>
        /// <param name="vertAlign">vertical alignment about the specified point</param>
        /// <param name="angle">the angle of rotation applied to the text, in radians</param>
        /// <returns>this object</returns>
        public virtual T ShowTextAligned(Paragraph p, float x, float y, int pageNumber, TextAlignment?textAlign,
                                         VerticalAlignment?vertAlign, float angle)
        {
            Div div = new Div();

            div.SetTextAlignment(textAlign).SetVerticalAlignment(vertAlign);
            if (angle != 0)
            {
                div.SetRotationAngle(angle);
            }
            div.SetProperty(Property.ROTATION_POINT_X, x);
            div.SetProperty(Property.ROTATION_POINT_Y, y);
            float divWidth  = AbstractRenderer.INF;
            float divHeight = AbstractRenderer.INF;
            float divX      = x;
            float divY      = y;

            if (textAlign == TextAlignment.CENTER)
            {
                divX = x - divWidth / 2;
                p.SetHorizontalAlignment(HorizontalAlignment.CENTER);
            }
            else
            {
                if (textAlign == TextAlignment.RIGHT)
                {
                    divX = x - divWidth;
                    p.SetHorizontalAlignment(HorizontalAlignment.RIGHT);
                }
            }
            if (vertAlign == VerticalAlignment.MIDDLE)
            {
                divY = y - divHeight / 2;
            }
            else
            {
                if (vertAlign == VerticalAlignment.TOP)
                {
                    divY = y - divHeight;
                }
            }
            if (pageNumber == 0)
            {
                pageNumber = 1;
            }
            div.SetFixedPosition(pageNumber, divX, divY, divWidth).SetHeight(divHeight);
            if (p.GetProperty <Leading>(Property.LEADING) == null)
            {
                p.SetMultipliedLeading(1);
            }
            div.Add(p.SetMargins(0, 0, 0, 0));
            div.SetRole(PdfName.Artifact);
            this.Add(div);
            return((T)(Object)this);
        }
예제 #8
0
        /// <summary>Convenience method to write a text aligned about the specified point</summary>
        /// <param name="p">
        /// paragraph of text to be placed to the page. By default it has no leading and is written in single line.
        /// Set width to write multiline text.
        /// </param>
        /// <param name="x">the point about which the text will be aligned and rotated</param>
        /// <param name="y">the point about which the text will be aligned and rotated</param>
        /// <param name="pageNumber">the page number to write the text</param>
        /// <param name="textAlign">horizontal alignment about the specified point</param>
        /// <param name="vertAlign">vertical alignment about the specified point</param>
        /// <param name="radAngle">the angle of rotation applied to the text, in radians</param>
        /// <returns>this object</returns>
        public virtual T ShowTextAligned(Paragraph p, float x, float y, int pageNumber, TextAlignment?textAlign,
                                         VerticalAlignment?vertAlign, float radAngle)
        {
            Div div = new Div();

            div.SetTextAlignment(textAlign).SetVerticalAlignment(vertAlign);
            if (radAngle != 0)
            {
                div.SetRotationAngle(radAngle);
            }
            div.SetProperty(Property.ROTATION_POINT_X, x);
            div.SetProperty(Property.ROTATION_POINT_Y, y);
            float divSize = 5e3f;
            float divX    = x;
            float divY    = y;

            if (textAlign == TextAlignment.CENTER)
            {
                divX = x - divSize / 2;
                p.SetHorizontalAlignment(HorizontalAlignment.CENTER);
            }
            else
            {
                if (textAlign == TextAlignment.RIGHT)
                {
                    divX = x - divSize;
                    p.SetHorizontalAlignment(HorizontalAlignment.RIGHT);
                }
            }
            if (vertAlign == VerticalAlignment.MIDDLE)
            {
                divY = y - divSize / 2;
            }
            else
            {
                if (vertAlign == VerticalAlignment.TOP)
                {
                    divY = y - divSize;
                }
            }
            if (pageNumber == 0)
            {
                pageNumber = 1;
            }
            div.SetFixedPosition(pageNumber, divX, divY, divSize).SetMinHeight(divSize);
            if (p.GetProperty <Leading>(Property.LEADING) == null)
            {
                p.SetMultipliedLeading(1);
            }
            div.Add(p.SetMargins(0, 0, 0, 0));
            div.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT);
            this.Add(div);
            return((T)(Object)this);
        }
예제 #9
0
        private static IDiagram ThenImplementation(
            IDiagram input,
            IDiagram next,
            HorizontalAlignment?horizontalAlignment,
            VerticalAlignment?verticalAlignment,
            bool evaluateOffset)
        {
            var alignmentVector = LayoutUtilities.ComputeAlignment(next, input, verticalAlignment, horizontalAlignment);
            var offsetDiagram   = evaluateOffset ? next.Offset(alignmentVector) : next.WithOffset(alignmentVector);

            return(input.Then(offsetDiagram));
        }
예제 #10
0
        public virtual void SetVerticalAlignmentViaStyleTest()
        {
            VerticalAlignment?expectedAlignment = VerticalAlignment.MIDDLE;
            Style             style             = new Style();

            style.SetVerticalAlignment(expectedAlignment);
            Paragraph p = new Paragraph();

            p.AddStyle(style);
            NUnit.Framework.Assert.AreEqual(expectedAlignment, p.GetProperty <VerticalAlignment?>(Property.VERTICAL_ALIGNMENT
                                                                                                  ));
        }
예제 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextGraphicsOptions" /> struct.
        /// </summary>
        /// <param name="enableAntialiasing">If set to <c>true</c> [enable antialiasing].</param>
        public TextGraphicsOptions(bool enableAntialiasing)
        {
            this.applyKerning        = true;
            this.tabWidth            = 4;
            this.wrapTextWidth       = 0;
            this.horizontalAlignment = HorizontalAlignment.Left;
            this.verticalAlignment   = VerticalAlignment.Top;

            this.antialiasSubpixelDepth = 16;
            this.blenderMode            = PixelBlenderMode.Normal;
            this.blendPercentage        = 1;
            this.antialias = enableAntialiasing;
        }
        public CellFormat DeepCloneWithVerticalAlignment(VerticalAlignment?verticalAlignment)
        {
            var result = new CellFormat(
                this.OuterBorders?.DeepClone(),
                this.FontFormat?.DeepClone(),
                this.BackgroundColor?.DeepClone(),
                verticalAlignment,
                this.HorizontalAlignment?.DeepClone(),
                this.FontRotationAngle?.DeepClone(),
                this.FillPattern?.DeepClone(),
                this.Options?.DeepClone());

            return(result);
        }
예제 #13
0
 public Aligned(Element child, HorizontalAlignment?horizontal, VerticalAlignment?vertical)
 {
     if (child is Aligned aligned)
     {
         Child      = aligned.Child;
         Horizontal = horizontal ?? aligned.Horizontal;
         Vertical   = vertical ?? aligned.Vertical;
     }
     else
     {
         Child      = child;
         Horizontal = horizontal;
         Vertical   = vertical;
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="TextGraphicsOptions" /> struct.
        /// </summary>
        /// <param name="enableAntiAliasing">If set to <c>true</c> [enable antialiasing].</param>
        public TextGraphicsOptions(bool enableAntiAliasing)
        {
            this.applyKerning        = true;
            this.tabWidth            = 4;
            this.WrapTextWidth       = 0;
            this.horizontalAlignment = HorizontalAlignment.Left;
            this.verticalAlignment   = VerticalAlignment.Top;

            this.antialiasSubpixelDepth = 16;
            this.ColorBlendingMode      = PixelColorBlendingMode.Normal;
            this.AlphaCompositionMode   = PixelAlphaCompositionMode.SrcOver;
            this.blendPercentage        = 1;
            this.antialias = enableAntiAliasing;
            this.dpiX      = DefaultTextDpi;
            this.dpiY      = DefaultTextDpi;
        }
예제 #15
0
        public TextileTableCell(string txt)
        {
            RawText    = txt;
            RowSpan    = 1;
            ColSpan    = 1;
            Horizontal = null;
            Vertical   = null;

            if (txt is null)
            {
                return;
            }

            txt = ParseFormatFrom(txt);

            var sb = new StringBuilder();

            for (var i = 0; i < txt.Length; ++i)
            {
                var c = txt[i];

                if (c == '\\')
                {
                    if (++i < txt.Length)
                    {
                        if (txt[i] == 'n')
                        {
                            sb.Append("  \n"); // \n => linebreak
                        }
                        else
                        {
                            sb.Append('\\').Append(txt[i]);
                        }
                    }
                    else
                    {
                        sb.Append('\\');
                    }
                }
                else
                {
                    sb.Append(c);
                }
            }
            Text = sb.ToString();
        }
예제 #16
0
        /// <summary>
        /// Sets the vertical alignment of a range.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="verticalAlignment">The vertical alignment.</param>
        /// <param name="styleContainer">The style container.</param>
        /// <exception cref="ArgumentNullException"><paramref name="range"/> is null.</exception>
        public static void SetVerticalAlignment(
            this Range range,
            VerticalAlignment?verticalAlignment,
            StyleContainer styleContainer = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (verticalAlignment != null)
            {
                range.SetStyle(styleContainer, _ =>
                {
                    _.Style.VerticalAlignment     = ((VerticalAlignment)verticalAlignment).ToTextAlignmentType();
                    _.StyleFlag.VerticalAlignment = true;
                });
            }
        }
예제 #17
0
        /// <summary>
        /// Add Path
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="row"></param>
        /// <param name="column"></param>
        /// <param name="rowspan"></param>
        /// <param name="columnspan"></param>
        /// <param name="vertical"></param>
        /// <param name="horizontal"></param>
        private void AddPath(Grid grid,
                             string name, string value,
                             int row, int column,
                             int?rowspan, int?columnspan,
                             VerticalAlignment?vertical     = null,
                             HorizontalAlignment?horizontal = null)
        {
            Path path = new Path
            {
                Name   = name,
                Margin = new Thickness(5),
                Data   = GetGeometry(value)
            };

            if (vertical != null)
            {
                path.VerticalAlignment = vertical.Value;
            }
            if (horizontal != null)
            {
                path.HorizontalAlignment = horizontal.Value;
            }
            path.SetBinding(Path.FillProperty, new Binding()
            {
                Source = this,
                Path   = new PropertyPath(nameof(Foreground)),
                Mode   = BindingMode.TwoWay
            });
            path.PointerMoved  += SetCapture;
            path.PointerExited += ReleaseCapture;
            path.SetValue(Grid.RowProperty, row);
            path.SetValue(Grid.ColumnProperty, column);
            if (rowspan != null)
            {
                path.SetValue(Grid.RowSpanProperty, rowspan);
            }
            if (columnspan != null)
            {
                path.SetValue(Grid.ColumnSpanProperty, columnspan);
            }
            grid.Children.Add(path);
        }
예제 #18
0
 public void UpdateUi(
     bool resetContext  = true,
     bool updateNonUi   = true,
     bool updateOpacity = true,
     bool?isDocked      = null,
     HorizontalAlignment?dockHorizontalAlignment = null,
     VerticalAlignment?dockVerticalAlignment     = null)
 {
     if (!IsVisible)
     {
         Refresh(resetContext, updateNonUi, false, updateOpacity);
     }
     else
     {
         this.Animate(AnimationMode.Hide, false, null,
                      () => Refresh(resetContext, updateNonUi, true, updateOpacity),
                      isDocked,
                      dockHorizontalAlignment,
                      dockVerticalAlignment);
     }
 }
예제 #19
0
        private void Add(ref Grid grid,
                         string name, string value,
                         int row, int column,
                         int?rowspan, int?columnspan,
                         VerticalAlignment?vertical     = null,
                         HorizontalAlignment?horizontal = null)
        {
            Path path = StringToPath(value);

            path.Name   = name;
            path.Margin = new Thickness(5);
            if (vertical != null)
            {
                path.VerticalAlignment = vertical.Value;
            }
            if (horizontal != null)
            {
                path.HorizontalAlignment = horizontal.Value;
            }
            path.SetBinding(Path.FillProperty, new Binding()
            {
                Source = this,
                Path   = new PropertyPath("Foreground"),
                Mode   = BindingMode.TwoWay
            });
            path.PointerMoved += Path_PointerMoved;
            path.SetValue(Grid.RowProperty, row);
            path.SetValue(Grid.ColumnProperty, column);
            if (rowspan != null)
            {
                path.SetValue(Grid.RowSpanProperty, rowspan);
            }
            if (columnspan != null)
            {
                path.SetValue(Grid.ColumnSpanProperty, columnspan);
            }
            grid.Children.Add(path);
        }
예제 #20
0
        private void SynchronizeVerticalContentAlignment(VerticalAlignment?alignment = null)
        {
            var childControl = ContentTemplateRoot as FrameworkElement;

            if (childControl != null)
            {
                childControl.SetValue(
                    FrameworkElement.VerticalAlignmentProperty,
                    alignment ?? VerticalContentAlignment,
                    DependencyPropertyValuePrecedences.Inheritance
                    );
            }
            else
            {
                var childControl2 = ContentTemplateRoot as IFrameworkElement;

                if (childControl2 != null)
                {
                    // This case is for controls that implement IFrameworkElement, but do not inherit from FrameworkElement (like TextBlock).

                    var verticalAlignmentProperty = DependencyProperty.GetProperty(ContentTemplateRoot.GetType(), "VerticalAlignment");

                    if (verticalAlignmentProperty != null)
                    {
                        childControl2.SetValue(
                            verticalAlignmentProperty,
                            alignment ?? VerticalContentAlignment,
                            DependencyPropertyValuePrecedences.Inheritance
                            );
                    }
                    else
                    {
                        throw new InvalidOperationException($"The property VerticalAlignment should exist on type {ContentTemplateRoot.GetType()}");
                    }
                }
            }
        }
예제 #21
0
        private string ParseFormatFrom(string txt)
        {
            int idx = txt.IndexOf('.');

            if (idx == -1)
            {
                return(txt.Trim());
            }
            else
            {
                var styleTxt = txt.Substring(0, idx);

                for (var i = 0; i < styleTxt.Length; ++i)
                {
                    var c = styleTxt[i];

                    switch (c)
                    {
                    case '/':     // /2 rowspan
                        ++i;
                        var numTxt = ContinueToNum(styleTxt, ref i);
                        if (numTxt.Length == 0)
                        {
                            goto default;
                        }
                        RowSpan = Int32.Parse(numTxt);

                        break;

                    case '\\':     // \2 colspan
                        ++i;
                        numTxt = ContinueToNum(styleTxt, ref i);
                        if (numTxt.Length == 0)
                        {
                            goto default;
                        }
                        ColSpan = Int32.Parse(numTxt);
                        break;

                    case '<':     // < left align
                        Horizontal = TextAlignment.Left;
                        break;

                    case '>':     // > right align
                        Horizontal = TextAlignment.Right;
                        break;

                    case '=':     // = center align
                        Horizontal = TextAlignment.Center;
                        break;

                    case '^':     // ^ top align
                        Vertical = VerticalAlignment.Top;
                        break;

                    case '~':     // ~ bottom align
                        Vertical = VerticalAlignment.Bottom;
                        break;

                    default:
                        RowSpan    = 1;
                        ColSpan    = 1;
                        Horizontal = null;
                        Vertical   = null;
                        return(txt.Trim());
                    }
                }
                return(txt.Substring(idx + 1).Trim());
            }
        }
예제 #22
0
        internal static GridSplitter CreateGridSplitterThroughCode(int?row, int?column, int?rowSpan, int?columnSpan, double?height, double?width, VerticalAlignment?vAlign, HorizontalAlignment?hAlign, Brush background, bool?showsPreview)
        {
            GridSplitter splitter = new GridSplitter();

            if (row != null)
            {
                splitter.SetValue(Grid.RowProperty, (int)row);
            }
            if (column != null)
            {
                splitter.SetValue(Grid.ColumnProperty, (int)column);
            }
            if (rowSpan != null)
            {
                splitter.SetValue(Grid.RowSpanProperty, (int)rowSpan);
            }
            if (columnSpan != null)
            {
                splitter.SetValue(Grid.ColumnSpanProperty, (int)columnSpan);
            }
            if (height != null)
            {
                splitter.Height = (double)height;
            }
            if (width != null)
            {
                splitter.Width = (double)width;
            }
            if (background != null)
            {
                splitter.Background = background;
            }
            if (showsPreview != null)
            {
                splitter.ShowsPreview = (bool)showsPreview;
            }
            if (hAlign != null)
            {
                splitter.HorizontalAlignment = (HorizontalAlignment)hAlign;
            }
            if (vAlign != null)
            {
                splitter.VerticalAlignment = (VerticalAlignment)vAlign;
            }

            return(splitter);
        }
예제 #23
0
    // the Location has been set to the initial pos, then rework to make sure it shows on screen. Locky means try to keep to Y position unless its too small
    static public void PositionSizeWithinScreen(this Control p, int wantedwidth, int wantedheight, bool lockY,
                                                int margin = 16, HorizontalAlignment?halign = null, VerticalAlignment?vertalign = null, int scrollbarallowwidth = 0)
    {
        Screen    scr  = Screen.FromPoint(p.Location);
        Rectangle scrb = scr.Bounds;

        int left  = p.Left;
        int width = Math.Min(wantedwidth, scrb.Width - margin * 2);         // ensure within screen limits taking off margins

        if (halign == HorizontalAlignment.Right)
        {
            left = scr.Bounds.Left + Math.Max(scrb.Width - margin - width, margin);
        }
        else if (halign == HorizontalAlignment.Center)
        {
            left = scr.Bounds.Left + scrb.Width / 2 - width / 2;
        }
        else if (halign == HorizontalAlignment.Left)
        {
            left = scr.Bounds.Left + margin;
        }

        int top    = p.Top;
        int height = Math.Min(wantedheight, scrb.Height - margin * 2);        // ensure within screen

        if (vertalign == VerticalAlignment.Bottom)
        {
            top = scr.Bounds.Top + Math.Max(scrb.Height - margin - height, margin);
        }
        else if (vertalign == VerticalAlignment.Middle)
        {
            top = scr.Bounds.Top + scrb.Height / 2 - height / 2;
        }
        else if (vertalign == VerticalAlignment.Top)
        {
            top = scr.Bounds.Top + margin;
        }

        int botscreen = scr.Bounds.Bottom;

        int availableh = botscreen - top - margin;                        // available height from top to bottom less margin

        if (height > availableh)                                          // if not enough height available
        {
            if (lockY && availableh >= scrb.Height / 4)                   // if locky and available is reasonable
            {
                height = availableh;                                      // lock height to it, keep y
            }
            else
            {
                top    = scr.Bounds.Top + Math.Max(margin, scrb.Height - margin - height); // at least margin, or at least height-margin-wantedheight
                height = Math.Min(scrb.Height - margin * 2, height);                       // and limit to margin*2
            }

            width += scrollbarallowwidth;                                   // need a scroll bar
        }

        if (left + width >= scr.Bounds.Right - margin)
        {
            left = scr.Bounds.Right - margin - width;
        }


        //  System.Diagnostics.Debug.WriteLine("Pos " + new Point(left, top) + " size " + new Size(width,height));
        p.Location = new Point(left, top);
        p.Size     = new Size(width, height);
    }
예제 #24
0
 /// <summary>Convenience method to write a text aligned about the specified point</summary>
 /// <param name="p">
 /// paragraph of text to be placed to the page. By default it has no leading and is written in single line.
 /// Set width to write multiline text.
 /// </param>
 /// <param name="x">the point about which the text will be aligned and rotated</param>
 /// <param name="y">the point about which the text will be aligned and rotated</param>
 /// <param name="textAlign">horizontal alignment about the specified point</param>
 /// <param name="vertAlign">vertical alignment about the specified point</param>
 /// <returns>this object</returns>
 public virtual T ShowTextAligned(Paragraph p, float x, float y, TextAlignment?textAlign, VerticalAlignment?
                                  vertAlign)
 {
     return(ShowTextAligned(p, x, y, pdfDocument.GetNumberOfPages(), textAlign, vertAlign, 0));
 }
예제 #25
0
        /// <summary>Convenience method to write a kerned text aligned about the specified point</summary>
        /// <param name="text">text to be placed to the page</param>
        /// <param name="x">the point about which the text will be aligned and rotated</param>
        /// <param name="y">the point about which the text will be aligned and rotated</param>
        /// <param name="textAlign">horizontal alignment about the specified point</param>
        /// <param name="vertAlign">vertical alignment about the specified point</param>
        /// <param name="angle">the angle of rotation applied to the text, in radians</param>
        /// <returns>this object</returns>
        public virtual T ShowTextAlignedKerned(String text, float x, float y, TextAlignment?textAlign, VerticalAlignment?
                                               vertAlign, float angle)
        {
            Paragraph p = new Paragraph(text).SetFontKerning(FontKerning.YES);

            return(ShowTextAligned(p, x, y, pdfDocument.GetNumberOfPages(), textAlign, vertAlign, angle));
        }
예제 #26
0
        /// <summary>Convenience method to write a text aligned about the specified point</summary>
        /// <param name="text">text to be placed to the page</param>
        /// <param name="x">the point about which the text will be aligned and rotated</param>
        /// <param name="y">the point about which the text will be aligned and rotated</param>
        /// <param name="textAlign">horizontal alignment about the specified point</param>
        /// <param name="vertAlign">vertical alignment about the specified point</param>
        /// <param name="angle">the angle of rotation applied to the text, in radians</param>
        /// <returns>this object</returns>
        public virtual T ShowTextAligned(String text, float x, float y, TextAlignment?textAlign, VerticalAlignment?
                                         vertAlign, float angle)
        {
            Paragraph p = new Paragraph(text).SetMultipliedLeading(1).SetMargin(0);

            return(ShowTextAligned(p, x, y, pdfDocument.GetNumberOfPages(), textAlign, vertAlign, angle));
        }
예제 #27
0
 /// <summary>Sets the vertical alignment of the element.</summary>
 /// <param name="verticalAlignment">the vertical alignment setting</param>
 /// <returns>this element</returns>
 public virtual T SetVerticalAlignment(VerticalAlignment?verticalAlignment)
 {
     SetProperty(Property.VERTICAL_ALIGNMENT, verticalAlignment);
     return((T)(Object)this);
 }
예제 #28
0
        public static void Animate(this WidgetView view, AnimationMode animationMode, bool focus = false,
                                   Action astartAction = null,
                                   Action aendAction   = null,
                                   bool?isDocked       = null,
                                   HorizontalAlignment?dockHorizontalAlignment = null,
                                   VerticalAlignment?dockVerticalAlignment     = null)
        {
            var settings = view.Id.GetSettings();

            var horizontalAlignment = dockHorizontalAlignment ?? settings.HorizontalAlignment;
            var verticalAlignment   = dockVerticalAlignment ?? settings.VerticalAlignment;
            var docked = isDocked ?? settings.IsDocked;

            view.RenderTransformOrigin = new Point(0.5, 0.5);
            if (docked)
            {
                switch (horizontalAlignment)
                {
                case HorizontalAlignment.Left:
                    view.RenderTransformOrigin = new Point(0, view.RenderTransformOrigin.Y);
                    break;

                case HorizontalAlignment.Right:
                    view.RenderTransformOrigin = new Point(1, view.RenderTransformOrigin.Y);
                    break;
                }
                switch (verticalAlignment)
                {
                case VerticalAlignment.Top:
                    view.RenderTransformOrigin = new Point(view.RenderTransformOrigin.X, 0);
                    break;

                case VerticalAlignment.Bottom:
                    view.RenderTransformOrigin = new Point(view.RenderTransformOrigin.X, 1);
                    break;
                }
            }

            Action startAction = delegate
            {
                if (animationMode == AnimationMode.Show)
                {
                    view.Show();
                }
                astartAction?.Invoke();
                view.AnimationRunning = true;
            };
            Action finishAction = delegate
            {
                if (animationMode == AnimationMode.Hide)
                {
                    view.Hide();
                }
                else
                {
                    if (focus && view.Settings.RefocusMainElementOnShow)
                    {
                        view.FocusMainElement();
                    }
                }
                aendAction?.Invoke();
                view.AnimationRunning = false;
            };

            if (settings.Style.AnimationType == AnimationType.None)
            {
                startAction();
                finishAction();
                return;
            }

            var doubleAnimation = new DoubleAnimation
            {
                Duration       = new Duration(TimeSpan.FromMilliseconds(settings.Style.AnimationTime)),
                From           = animationMode == AnimationMode.Show ? 0 : 1,
                To             = animationMode == AnimationMode.Show ? 1 : 0,
                FillBehavior   = FillBehavior.Stop,
                EasingFunction = settings.Style.AnimationEase
                    ? new SineEase
                {
                    EasingMode = animationMode == AnimationMode.Show ? EasingMode.EaseIn : EasingMode.EaseOut
                }
                    : null
            };

            // Start animation.
            startAction();
            switch (settings.Style.AnimationType)
            {
            case AnimationType.Fade:
                var storyBoard = new Storyboard();
                storyBoard.Completed += (sender, args) => finishAction();
                storyBoard.Children.Add(doubleAnimation);
                Storyboard.SetTarget(doubleAnimation, view);
                Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(UIElement.OpacityProperty));
                storyBoard.Begin();
                break;

            case AnimationType.Slide:
                var counter = 0;
                doubleAnimation.Completed += delegate
                {
                    counter++;
                    if (counter == 2)
                    {
                        finishAction();
                    }
                };
                var trans = new ScaleTransform();
                view.RenderTransform = trans;
                trans.BeginAnimation(ScaleTransform.ScaleXProperty, doubleAnimation);
                trans.BeginAnimation(ScaleTransform.ScaleYProperty, doubleAnimation);
                break;

            default:
                finishAction();
                break;
            }
        }
예제 #29
0
파일: StackLayout.cs 프로젝트: zzlvff/Eto
		/// <summary>
		/// Initializes a new instance of the <see cref="Eto.Forms.StackLayoutItem"/> class when the StackLayout.Orientation is Horizontal.
		/// </summary>
		/// <param name="control">Control for the item.</param>
		/// <param name="alignment">Vertical alignment of the control for horizontal layouts.</param>
		/// <param name="expand">Whether the control expands to fill space along the direction of the layout</param>
		public StackLayoutItem(Control control, VerticalAlignment? alignment, bool expand = false)
		{
			Control = control;
			VerticalAlignment = alignment;
			Expand = expand;
		}
예제 #30
0
 public static void SetVerticalAlignment(UIElement obj, VerticalAlignment?value)
 {
     obj.SetValue(VerticalAlignmentProperty, value);
 }