Offset() public method

public Offset ( double offsetX, double offsetY ) : void
offsetX double
offsetY double
return void
コード例 #1
0
    /// <summary>
    /// When overridden in a derived class, participates in rendering operations that are directed by the layout system. The rendering instructions for this element are not used directly when this method is invoked, and are instead preserved for later asynchronous use by layout and drawing.
    /// </summary>
    /// <param name="drawingContext">The drawing instructions for a specific element. This context is provided to the layout system.</param>
    protected override void OnRender(DrawingContext drawingContext)
    {
      // When no interfaces have been defined, there is nothing to draw.
      if (this.interfaceNames.Count == 0)
      {
        return;
      }

      base.OnRender(drawingContext);

      Pen pen = new Pen(Brushes.Gray, 0.5);
      Point origin = new Point(30, 3);
      double length = Constants.StartHeight + (this.interfaceNames.Count * Constants.LineHeight);

      // draw path at top left
      drawingContext.DrawLine(pen, origin, new Point(origin.X, origin.Y - length));
      drawingContext.DrawEllipse(Brushes.Transparent, pen, new Point(origin.X, origin.Y - length - Constants.Radius), Constants.Radius, Constants.Radius);

      // draw interface names
      origin.Offset(5.0D, -length - Constants.Radius);
      foreach (string name in this.interfaceNames)
      {
        drawingContext.DrawText(new FormattedText(name, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, new Typeface("Segoe UI"), 7, pen.Brush), origin);
        origin.Offset(0, 7.0D);
      }
    }
コード例 #2
0
 private static Point GetOffsetPoint(Point point, ConnectorOrientation orientation, int offset)
 {
     switch (orientation)
     {
         case ConnectorOrientation.Left:
             point.Offset(-offset, 0);
             return point;
         case ConnectorOrientation.Right:
             point.Offset(offset, 0);
             return point;
         default:
             throw new ArgumentOutOfRangeException("orientation");
     }
 }
コード例 #3
0
        public void PlaceString(string text, Point startPoint, string path)
        {
            Point cursor = new Point(startPoint.X, startPoint.Y);

            TtfCharacter i = _TtfCharacterSet['i'];

            for (int idx = 0; idx < text.Length; idx++)
            {
                TtfCharacter c   = _TtfCharacterSet['?'];
                char         chr = text[idx];
                if (_TtfCharacterSet.ContainsKey(chr))
                {
                    c = _TtfCharacterSet[chr];
                }

                if (c != null)
                {
                    Point position = GetCharacterPosition(cursor, c);

                    AtomLabelCharacter alc = new AtomLabelCharacter(position, c, "000000", chr, path, path);
                    _AtomLabelCharacters.Add(alc);

                    if (idx < text.Length - 1)
                    {
                        // Move to next Character position
                        cursor.Offset(OoXmlHelper.ScaleCsTtfToCml(c.Width + i.Width, _meanBondLength), 0);
                    }
                }
            }
        }
コード例 #4
0
        private void Canvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            // If we're not dragging, don't bother
            if (!_isDragging)
            {
                return;
            }

            FrameworkElement element = sender as FrameworkElement;

            if (element == null)
            {
                return;
            }

            // Get the position of the mouse relative to the canvas
            WindowsPoint mousePoint = e.GetPosition(CnvMain);

            // Offset the mouse position by the original offset position
            mousePoint.Offset(-_offset.X, -_offset.Y);

            // Move the element on the canvas
            _draggedImage.SetValue(Canvas.LeftProperty, mousePoint.X);
            _draggedImage.SetValue(Canvas.TopProperty, mousePoint.Y);
        }
コード例 #5
0
        private Rect MeasureString(string text, Point startPoint)
        {
            Rect         boundingBox = Rect.Empty;
            Point        cursor      = new Point(startPoint.X, startPoint.Y);
            TtfCharacter i           = _TtfCharacterSet['i'];

            for (int idx = 0; idx < text.Length; idx++)
            {
                TtfCharacter c   = _TtfCharacterSet['?'];
                char         chr = text[idx];
                if (_TtfCharacterSet.ContainsKey(chr))
                {
                    c = _TtfCharacterSet[chr];
                }

                if (c != null)
                {
                    Point position = GetCharacterPosition(cursor, c);

                    Rect thisRect = new Rect(new Point(position.X, position.Y),
                                             new Size(OoXmlHelper.ScaleCsTtfToCml(c.Width, _meanBondLength),
                                                      OoXmlHelper.ScaleCsTtfToCml(c.Height, _meanBondLength)));

                    boundingBox.Union(thisRect);

                    if (idx < text.Length - 1)
                    {
                        // Move to next Character position
                        cursor.Offset(OoXmlHelper.ScaleCsTtfToCml(c.Width + i.Width, _meanBondLength), 0);
                    }
                }
            }

            return(boundingBox);
        }
コード例 #6
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            Size inflate = new Size();

            if (finalSize.Width < totChildWidth)
                inflate.Width = (totChildWidth - finalSize.Width) / InternalChildren.Count;

            Point offset = new Point();
            if (finalSize.Width > totChildWidth)
                offset.X = -(finalSize.Width - totChildWidth)/2;

            double totalFinalWidth = 0.0;
            foreach (UIElement child in InternalChildren)
            {
                Size childFinalSize = child.DesiredSize;
                childFinalSize.Width -= inflate.Width;
                childFinalSize.Height = finalSize.Height;

                child.Arrange(new Rect(offset, childFinalSize));

                offset.Offset(childFinalSize.Width, 0);
                totalFinalWidth += childFinalSize.Width;
            }

            return new Size(totalFinalWidth, finalSize.Height);
        }
コード例 #7
0
		protected Point GetPosition(UIElement relativeTo, FrameworkElement element, bool centered)
		{
			Point point = new Point(Canvas.GetLeft(element), Canvas.GetTop(element));
			if(centered)
				point.Offset(element.Width / 2, element.Height / 2);
			return relativeTo.TranslatePoint(point, window);
		}
コード例 #8
0
ファイル: Utilities.cs プロジェクト: samuto/designscript
        public static void DrawSlot(DrawingContext drawingContext, Point p1)
        {
            //@TODO(Joy)DONE magic number 10?
            p1.X = (int)p1.X;
            p1.Y = (int)p1.Y;
            Point p2 = p1;
            p2.Y = p1.Y + Configurations.SlotSize;
            p1.Offset(0.5, 0);
            p2.Offset(0.5, 0);
            drawingContext.DrawLine(Configurations.BorderPen, p1, p2);

            p1.Offset(-Configurations.OutputHittestPixels, -Configurations.SlotStripeSize / 2 + Configurations.SlotSize / 2);
            //draw hit test rectangle
            Size hitTestSize = new Size(Configurations.OutputHittestPixels, Configurations.SlotStripeSize);
            Rect hitTestRect = new Rect(p1, hitTestSize);
            drawingContext.DrawRectangle(Configurations.SlotHitTestColor, Configurations.NoBorderPen, hitTestRect);
        }
コード例 #9
0
 public void Start()
 {
     pt = getpos();
     pt.Offset(-win.Left, -win.Top);
     bool b = win.CaptureMouse();
     win.PreviewMouseLeftButtonUp += win_PreviewMouseLeftButtonUp;
     win.PreviewMouseMove += win_PreviewMouseMove;
 }
コード例 #10
0
 void MovableChartLabelPoint_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     isMoving = true;
       e.Handled = true;
       CaptureMouse();
       startPt = e.GetPosition(null);
       if (!double.IsNaN(Offset.X) && !double.IsNaN(Offset.Y))
     startPt.Offset(-Offset.X, -Offset.Y);
 }
コード例 #11
0
		private void DrawingArea_MouseDown(object sender, MouseButtonEventArgs e)
		{
			if (DrawingArea.IsMouseDirectlyOver)
			{
				_backDragStartPt = e.GetPosition(this);
				_backDragStartPt.Offset(-DrawingArea.Margin.Left, -DrawingArea.Margin.Top);
				DrawingArea.CaptureMouse();
			}
		}
コード例 #12
0
ファイル: SelectionBox.cs プロジェクト: samuto/designscript
        internal bool Hittest(Point mousePosition)
        {
            Point pt = new Point(this.x, this.y);
            pt.Offset(this.width, 0);

            if (mousePosition.X > pt.X - Configurations.HittestPixels && mousePosition.X < pt.X)
                if (mousePosition.Y > pt.Y && mousePosition.Y < pt.Y + Configurations.HittestPixels)
                    return true;
            return false;
        }
コード例 #13
0
        public System.Windows.Point TranslateToScreenPoint(System.Drawing.Point charPosition)
        {
            IScriptObject activeScript = Solution.Current.ActiveScript;
            CharPosition  position     = activeScript.CreateCharPosition();

            position.SetCharacterPosition(charPosition.X, charPosition.Y);
            System.Windows.Point result = position.GetScreenPosition();

            // The screen position needs offset based on the current scroll position.
            result.Offset(-scrollViewer.HorizontalOffset, -scrollViewer.VerticalOffset);
            return(result);
        }
コード例 #14
0
        public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var conn = (Connection)value;

            var endpoint1 = new Point(conn.Source.Location.X, (conn.Source.Region.Size.Height - conn.Source.Location.Y));
            var endpoint2 = new Point(conn.Target.Location.X, (conn.Target.Region.Size.Height - conn.Target.Location.Y));

            endpoint1.Offset(-conn.Source.Region.MiniMapOffset.X, -conn.Source.Region.MiniMapOffset.Y);
            endpoint2.Offset(-conn.Target.Region.MiniMapOffset.X, -conn.Target.Region.MiniMapOffset.Y);

            return new LineGeometry(endpoint1, endpoint2);
        }
コード例 #15
0
ファイル: Flow.cs プロジェクト: curiousily/simsrunner
        private void OnMouseDragHandler(object sender, Point dragPoint)
        {
            var rect = (Rectangle) sender;
            dragPoint.Offset(MouseOffset, MouseOffset);
            _sourceLine.X2 = dragPoint.X;
            _sourceLine.Y2 = dragPoint.Y;

            _targetLine.X1 = dragPoint.X;
            _targetLine.Y1 = dragPoint.Y;
            Canvas.SetLeft(rect, dragPoint.X - Width / 2);
            Canvas.SetTop(rect, dragPoint.Y - Height / 2);
        }
コード例 #16
0
        private List <Point> MovePointsBy(List <Point> points, double dx, double dy)
        {
            List <Point> result = new List <Point>();

            foreach (var p in points)
            {
                var pp = new Point(p.X, p.Y);
                pp.Offset(dx, dy);
                result.Add(pp);
            }

            return(result);
        }
コード例 #17
0
        private void DrawHashBondLines(Wpg.WordprocessingGroup wordprocessingGroup1, List <Point> points)
        {
            // Create modifyable Points
            Point p0 = new Point(points[0].X, points[0].Y);
            Point p1 = new Point(points[1].X, points[1].Y);
            Point p2 = new Point(points[2].X, points[2].Y);

            // Draw Tail Line
            BondLine blTail = new BondLine(points[1], points[2], BondLineStyle.Solid, null, null);

            DrawBondLine(wordprocessingGroup1, blTail);

            // Prep for intermediate lines
            Point  midPoint = CoordinateTool.GetMidPoint(points[1], points[2]);
            Vector v        = points[0] - midPoint;
            double ticks    = v.Length / 2;

            v = v / ticks;

            BondLine blNext;

            Point outIntersectP1;
            Point outIntersectP2;

            Point leftTailEnd  = p1;
            Point rightTailEnd = p2;

            bool linesIntersect;
            bool segmentsIntersect;

            // Draw itermediate lines
            for (int i = 1; i <= (int)ticks; i++)
            {
                p1.Offset(v.X, v.Y);
                p2.Offset(v.X, v.Y);
                CoordinateTool.FindIntersection(leftTailEnd, p0, p1, p2,
                                                out linesIntersect, out segmentsIntersect, out outIntersectP1);
                CoordinateTool.FindIntersection(rightTailEnd, p0, p1, p2,
                                                out linesIntersect, out segmentsIntersect, out outIntersectP2);
                blNext = new BondLine(outIntersectP1, outIntersectP2, BondLineStyle.Solid, null, null);
                DrawBondLine(wordprocessingGroup1, blNext);
            }

            // Draw small line for nose
            Point n1 = new Point(points[0].X - 0.025, points[0].Y - 0.025);
            Point n2 = new Point(points[0].X + 0.025, points[0].Y + 0.025);

            BondLine blNose = new BondLine(n1, n2, BondLineStyle.Solid, null, null);

            DrawBondLine(wordprocessingGroup1, blNose);
        }
コード例 #18
0
        public void DrawBondLine(Wpg.WordprocessingGroup wordprocessingGroup, BondLine bl, string colour = "000000")
        {
            Point startPoint = new Point(bl.Start.X, bl.Start.Y);
            Point endPoint   = new Point(bl.End.X, bl.End.Y);
            Rect  cmlExtents = bl.BoundingBox;

            // Move Bond Line Extents and Points to have 0,0 Top Left Reference
            startPoint.Offset(-m_canvasExtents.Left, -m_canvasExtents.Top);
            endPoint.Offset(-m_canvasExtents.Left, -m_canvasExtents.Top);
            cmlExtents.Offset(-m_canvasExtents.Left, -m_canvasExtents.Top);

            // Move points into New Bond Line Extents
            startPoint.Offset(-cmlExtents.Left, -cmlExtents.Top);
            endPoint.Offset(-cmlExtents.Left, -cmlExtents.Top);

            switch (bl.Style)
            {
            case BondLineStyle.Solid:
                DrawSolidLine(wordprocessingGroup, cmlExtents, startPoint, endPoint);
                break;

            case BondLineStyle.Dotted:
                DrawDottedLine(wordprocessingGroup, cmlExtents, startPoint, endPoint, colour);
                break;

            case BondLineStyle.Dashed:
                DrawDashedLine(wordprocessingGroup, cmlExtents, startPoint, endPoint, colour);
                break;

            case BondLineStyle.Wavy:
                DrawWavyLine(wordprocessingGroup, cmlExtents, startPoint, endPoint);
                break;

            default:
                DrawSolidLine(wordprocessingGroup, cmlExtents, startPoint, endPoint);
                break;
            }
        }
コード例 #19
0
ファイル: WpfGraphicsUtil.cs プロジェクト: yesbb12/NetMap
        SquareFromCenterAndHalfWidth
        (
            System.Windows.Point center,
            Double halfWidth
        )
        {
            Debug.Assert(halfWidth >= 0);

            center.Offset(-halfWidth, -halfWidth);
            Double dWidth = 2 * halfWidth;

            return(new System.Windows.Rect(center,
                                           new System.Windows.Size(dWidth, dWidth)));
        }
コード例 #20
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            // Introduce clipping
            drawingContext.PushClip(new RectangleGeometry(new Rect(_adornedElement.RenderSize)));

            foreach (ChartMarkerSet set in MarkerSets)
            {
//                ChartPrimitive parent = set.ParentPrimitive;
                var setBrush = new SolidColorBrush(set.Fill);
                var setPen = new Pen(new SolidColorBrush(set.Stroke), set.StrokeWidth);
                
                foreach (ChartPoint p in set.Points)
                {
                    // Snap the marker's Y-position onto the parent primitive
                    var snappedToParentPos = p.Point;
//                    snappedToParentPos.Y = parent.GetValueY(p.Point.X);

                    // Then render it to the adorner layer (which is on top of the plot canvas)
                    Point pixelPos = _parentChart.ToPixel(snappedToParentPos);
                    drawingContext.DrawEllipse(setBrush, setPen, pixelPos, set.Size/2, set.Size/2);

                    const double labelOffsetY = 10;
                    Point labelPixelOffset = new Point(0, +5);
                    if (snappedToParentPos.Y >= 0)
                        labelPixelOffset.Offset(0, labelOffsetY);
                    else
                        labelPixelOffset.Offset(0, -labelOffsetY);

//                    ChartHelper.RenderTextToChartPosition(drawingContext, _parentChart.TextCanvasInfo, p.Label, set.Color, snappedToParentPos, labelPixelOffset, FlipYAxis, true);
                }
            }

            // End clipping
            drawingContext.Pop();
        }
コード例 #21
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            Point currentPosition = new Point();

            foreach (UIElement child in Children)
            {
                Rect childRect = new Rect(currentPosition, child.DesiredSize);
                //Rect childRect = new Rect(currentPosition, new Size(100,100));
                child.Arrange(childRect);
                currentPosition.Offset(childRect.Width, childRect.Height);

            }

            return new Size(currentPosition.X, currentPosition.Y);
        }
コード例 #22
0
        private System.Windows.Point ScreenToCanvasPosition(System.Windows.Point screenPoint)
        {
            // We won't attempt to offset the cursor position when it falls within the
            // line number column. The relative offset of mouse only matters when the
            // cursor is actually within the source code region.
            //
            double horzOffset = 0;

            if (screenPoint.X > Configurations.LineNumberColumnEnd)
            {
                horzOffset = textCanvas.FirstVisibleColumn * Configurations.FormatFontWidth;
            }

            screenPoint.Offset(horzOffset, textCanvas.FirstVisibleLine * Configurations.FontDisplayHeight);
            return(screenPoint);
        }
コード例 #23
0
        /// <summary>
        /// 1 - Content presenter render size,
        /// 2 - Clipping border padding (main control padding)
        /// </summary>
        /// <param name="values"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Length != 2 || !(values[0] is Size) || !(values[1] is Thickness))
                return Binding.DoNothing;

            var size = (Size)values[0];
            var farPoint = new Point(
                Math.Max(0, size.Width),
                Math.Max(0, size.Height));
            var padding = (Thickness)values[1];
            farPoint.Offset(padding.Left + padding.Right, padding.Top + padding.Bottom);

            return new Rect(
                new Point(), 
                new Point(farPoint.X, farPoint.Y));                                          
        }
コード例 #24
0
ファイル: AreaTest.cs プロジェクト: Benrnz/TypeVisualiser
        public void CanConstructUsing2Points()
        {
            double topX = 12.43, topY = 56.89;
            double bottomX = 45.89, bottomY = 45.87;
            var topPoint = new Point(topX, topY);
            var bottomPoint = new Point(bottomX, bottomY);
            var subject = new Area(topPoint, bottomPoint);

            // Ensure it doesnt change after creation, ie cloned.
            topPoint.Offset(1, 1);
            bottomPoint.Offset(2, 2);

            Assert.AreEqual(topX, subject.TopLeft.X);
            Assert.AreEqual(topY, subject.TopLeft.Y);
            Assert.AreEqual(bottomX, subject.BottomRight.X);
            Assert.AreEqual(bottomY, subject.BottomRight.Y);
        }
コード例 #25
0
        public void MoveTo(Point to)
        {
            position = to;
            position.Offset(-3, -1);
            InvalidateArrange();

            // If we were given a clip visual, hide the triangle, which are totally outside of it
            if (ClippingVisual != null)
            {
                var clipping = new Rect(
                    ClippingVisual.PointToScreen(new Point(-4, -4)),
                    ClippingVisual.PointToScreen(new Point(ClippingVisual.ActualWidth + 4, ClippingVisual.ActualHeight + 4)));
                var testPt = PointToScreen(position);
                topTriangle.Visibility = clipping.Contains(testPt) ? Visibility.Visible : Visibility.Collapsed;
                testPt = PointToScreen(new Point(position.X, position.Y + Height + 2));
                bottomTriangle.Visibility = clipping.Contains(testPt) ? Visibility.Visible : Visibility.Collapsed;
            }

            (Parent as AdornerLayer).Update();
        }
コード例 #26
0
        public void AddMoleculeLabels(List <TextualProperty> labels, Point centrePoint, string moleculePath)
        {
            Point measure = new Point(centrePoint.X, centrePoint.Y);

            foreach (var label in labels)
            {
                // 1. Measure string
                var bb = MeasureString(label.Value, measure);

                // 2. Place string such that they are hanging below the "line"
                if (bb != Rect.Empty)
                {
                    Point place = new Point(measure.X - bb.Width / 2, measure.Y + (measure.Y - bb.Top));
                    PlaceString(label.Value, place, moleculePath);
                }

                // 3. Move to next line
                measure.Offset(0, bb.Height + _meanBondLength * OoXmlHelper.MULTIPLE_BOND_OFFSET_PERCENTAGE / 2);
            }
        }
コード例 #27
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            //base.OnMouseDown(e);
            var window = Window.GetWindow(this);
            if (e.ClickCount == 1)
            {
                if (e.ChangedButton == MouseButton.Left)
                {
                    var positionRelativeToWindow = new Point(VisualOffset.X, VisualOffset.Y);
                    positionRelativeToWindow.Offset(0, ActualHeight);
                    var screenPosition = PointToScreen(positionRelativeToWindow);
                    SystemCommands.ShowSystemMenu(window, screenPosition);
                }

            }
            if (e.ClickCount == 2 && e.ChangedButton == MouseButton.Left)
            {
                Debug.Assert(window != null, "window != null");
                window.Close();
            }
        }
コード例 #28
0
        /// <summary>
        /// Return the point shifted by the row and group location.
        /// </summary>
        private Point GetPoint(Point point)
        {
            point.Offset(
                this.row.Location.X + this.group.Location.X,
                this.row.Location.Y + this.group.Location.Y);

            return point;
        }
コード例 #29
0
        /// <summary>
        /// Generated by right-click mouse release.
        /// </summary>
        /// <param name="sender">System.Windows.Controls.Button</param>
        /// <param name="e">MouseUp</param>
        private void button1_MouseUp(object sender, MouseButtonEventArgs e)
        {                                       // this window is inside the window frame
            releasePoint = e.GetPosition(this); // relative to this window
            releasePoint.Offset(appWin.Left + 4, appWin.Top + 30);
            label1.Content = sender.GetType().ToString() + ": " + e.RoutedEvent.Name
                             + " (" + releasePoint.X + "," + releasePoint.Y + ")";
            button1.ReleaseMouseCapture();

            // Get the UI Element under the releasePoint and
            // navigate up the tree to the main window.
            AutomationElement pathTarget = AutomationElement.FromPoint(releasePoint);

            if (pathTarget == null)
            {
                label1.Content = "No AutomationElement found :-(";
            }
            else
            {             // traverse to the root and record the path.
                //AutomationElement desktop = AutomationElement.RootElement; // the desktop
                //AutomationElement ae = pathTarget.CachedParent;
                //DependencyObject depo = VisualTreeHelper.GetParent(v);
                //LocalizedControlType is a short control desc. like button, spinner, group, title bar, etc..
                // label1.Content = pathTarget.Current.ControlType.LocalizedControlType; // getBestPattern(pathTarget);
                string    pathImage    = pathToDesktop(pathTarget);
                ArrayList wrappedImage = wrapImage(pathImage);
                foreach (string line in wrappedImage)
                {
                    label1.Content += "\nl" + line;
                }

                AutomationPattern[] aps = pathTarget.GetSupportedPatterns();
                foreach (AutomationPattern ap in aps)
                {
                    label1.Content += "\nl" + ap.Id + ap.ProgrammaticName;
                }
                AutomationProperty[] apr = pathTarget.GetSupportedProperties();
                foreach (AutomationProperty ap in apr)
                {
                    label1.Content += "\nl" + ap.Id + ap.ProgrammaticName;
                    //object oValue = pathTarget.GetCurrentPropertyValue(ap);

                    // get the name of the prop and switch to its getter
                    // or cast object to the right type and add to the string

                    // What are the possible property values sorted by type?
                    string str = pathTarget.Current.AcceleratorKey;
                    str = pathTarget.Current.AccessKey;
                    str = pathTarget.Current.AutomationId;
                    Rect rect = pathTarget.Current.BoundingRectangle;
                    str = pathTarget.Current.ClassName;
                    ControlType ct = pathTarget.Current.ControlType;
                    str = pathTarget.Current.FrameworkId;
                    bool boo = pathTarget.Current.HasKeyboardFocus;
                    str = pathTarget.Current.HelpText;
                    boo = pathTarget.Current.IsContentElement;
                    boo = pathTarget.Current.IsControlElement;
                    boo = pathTarget.Current.IsEnabled;
                    boo = pathTarget.Current.IsKeyboardFocusable;
                    boo = pathTarget.Current.IsOffscreen;
                    boo = pathTarget.Current.IsPassword;
                    boo = pathTarget.Current.IsRequiredForForm;
                    str = pathTarget.Current.ItemStatus;
                    str = pathTarget.Current.ItemType;
                    AutomationElement ae = pathTarget.Current.LabeledBy;
                    str = pathTarget.Current.LocalizedControlType;
                    str = pathTarget.Current.Name;
                    int             hwnd   = pathTarget.Current.NativeWindowHandle;
                    OrientationType ot     = pathTarget.Current.Orientation;
                    int             procId = pathTarget.Current.ProcessId;
                }
                // don't need to clear the clipboard
                System.Windows.Clipboard.SetText(pathImage);
            }
        }
コード例 #30
0
        //This snaps the center of the element to grid.
        //Wherever shapeAnchorPoint is valid, it is made co-incident with the drop location.
        static Point SnapVisualToGrid(UIElement element, Point location, Point shapeAnchorPoint, bool isAnchorPointValid)
        {
            Fx.Assert(element != null, "Input UIElement is null");
            element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            Point oldCenter = location;
            if (!isAnchorPointValid)
            {
                //shapeAnchorPoint is invalid in case where it does not make sense (eg. toolbox drop).
                location.X -= InitialNodeWidth / 2;
                location.Y -= InitialNodeHeight / 2;
            }
            else
            {
                location.X -= shapeAnchorPoint.X;
                location.Y -= shapeAnchorPoint.Y;
                oldCenter = new Point(location.X + element.DesiredSize.Width / 2, location.Y + element.DesiredSize.Height / 2);
            }

            Point newCenter = SnapPointToGrid(oldCenter);

            location.Offset(newCenter.X - oldCenter.X, newCenter.Y - oldCenter.Y);

            if (location.X < 0)
            {
                double correction = FreeFormPanel.GridSize - ((location.X * (-1)) % FreeFormPanel.GridSize);
                location.X = (correction == FreeFormPanel.GridSize) ? 0 : correction;
            }
            if (location.Y < 0)
            {
                double correction = FreeFormPanel.GridSize - ((location.Y * (-1)) % FreeFormPanel.GridSize);
                location.Y = (correction == FreeFormPanel.GridSize) ? 0 : correction;
            }
            return location;
        }
コード例 #31
0
        internal override NodePart HitTest(double x, double y, out int index)
        {
            System.Windows.Point pt = this.nodePosition;
            index = -1;

            if (this.IsWithinClickRegion(pt, x, y) && dotsFlag.HasFlag(MenuDots.NorthWest))
            {
                return(NodePart.NorthWest);
            }

            pt   = this.nodePosition;
            pt.X = pt.X + Configurations.NodeWidthIdentifer + Utilities.GetTextWidth(this.Caption);

            if (this.IsWithinClickRegion(pt, x, y) && dotsFlag.HasFlag(MenuDots.NorthEast))
            {
                return(NodePart.NorthEast);
            }

            pt = this.nodePosition;

            if (y > pt.Y && y < pt.Y + Height)
            {
                if (x > pt.X - Configurations.OutputHittestPixels && x < pt.X + Configurations.HittestPixels)
                {
                    if (this.InputSlotIsVisible())
                    {
                        index = 0;
                        return(NodePart.InputSlot);
                    }
                    else
                    {
                        return(NodePart.None);
                    }
                }
                if (x > pt.X + Width - Configurations.HittestPixels && x < pt.X + Width + Configurations.OutputHittestPixels)
                {
                    index = 0;
                    return(NodePart.OutputSlot);
                }
            }

            if (this.previewBubble != null)
            {
                pt = this.previewBubble.RectPosition;
                pt.Offset(this.nodePosition.X, this.nodePosition.Y);
                pt.Offset(this.previewBubble.Width - 2, 2);
                if (this.IsWithinClickRegion(pt, x, y))
                {
                    return(NodePart.PreviewNorthEast);
                }
            }

            pt = this.nodePosition;
            if (y > pt.Y + this.Height + Configurations.InfoBubbleTopMargin)
            {
                return(NodePart.Preview);
            }

            pt = this.nodePosition;
            if (y > pt.Y + this.Height + Configurations.InfoBubbleTopMargin)
            {
                return(NodePart.Preview);
            }

            return(NodePart.Caption);
        }
コード例 #32
0
        private void DrawShape(Wpg.WordprocessingGroup wordprocessingGroup, Rect cmlExtents, A.ShapeTypeValues shape, string colour)
        {
            UInt32Value id           = UInt32Value.FromUInt32((uint)m_ooxmlId++);
            string      bondLineName = "shape" + id;

            Int64Value width  = OoXmlHelper.ScaleCmlToEmu(cmlExtents.Width);
            Int64Value height = OoXmlHelper.ScaleCmlToEmu(cmlExtents.Height);
            Int64Value top    = OoXmlHelper.ScaleCmlToEmu(cmlExtents.Top);
            Int64Value left   = OoXmlHelper.ScaleCmlToEmu(cmlExtents.Left);

            Point location = new Point(left, top);
            Size  size     = new Size(width, height);

            location.Offset(OoXmlHelper.ScaleCmlToEmu(-m_canvasExtents.Left), OoXmlHelper.ScaleCmlToEmu(-m_canvasExtents.Top));
            Rect boundingBox = new Rect(location, size);

            width  = (Int64Value)boundingBox.Width;
            height = (Int64Value)boundingBox.Height;
            top    = (Int64Value)boundingBox.Top;
            left   = (Int64Value)boundingBox.Left;

            A.PresetGeometry presetGeometry = null;
            A.Extents        extents        = new A.Extents {
                Cx = width, Cy = height
            };
            presetGeometry = new A.PresetGeometry()
            {
                Preset = shape
            };

            Wps.WordprocessingShape        wordprocessingShape        = new Wps.WordprocessingShape();
            Wps.NonVisualDrawingProperties nonVisualDrawingProperties = new Wps.NonVisualDrawingProperties()
            {
                Id   = id,
                Name = bondLineName
            };

            Wps.NonVisualDrawingShapeProperties nonVisualDrawingShapeProperties = new Wps.NonVisualDrawingShapeProperties();

            Wps.ShapeProperties shapeProperties = new Wps.ShapeProperties();

            A.Transform2D transform2D = new A.Transform2D();
            A.Offset      offset      = new A.Offset {
                X = left, Y = top
            };

            transform2D.Append(offset);
            transform2D.Append(extents);

            A.AdjustValueList adjustValueList = new A.AdjustValueList();

            presetGeometry.Append(adjustValueList);
            A.SolidFill solidFill = new A.SolidFill();

            A.RgbColorModelHex rgbColorModelHex = new A.RgbColorModelHex {
                Val = colour
            };
            solidFill.Append(rgbColorModelHex);

            shapeProperties.Append(transform2D);
            shapeProperties.Append(presetGeometry);
            shapeProperties.Append(solidFill);

            OoXmlHelper.AppendShapeStyle(wordprocessingShape, nonVisualDrawingProperties, nonVisualDrawingShapeProperties, shapeProperties);
            wordprocessingGroup.Append(wordprocessingShape);
        }
コード例 #33
0
ファイル: RibbonWindow.cs プロジェクト: CarverLab/onCore.root
		private Point ScreenToLocal(Point point)
		{
			NativeMethods.RECT rect;
			NativeMethods.GetWindowRect(new WindowInteropHelper(this).Handle, out rect);
			Matrix matrix = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
			point.Offset((-1*rect.Left), (-1*rect.Top));
			point.X *= matrix.M11;
			point.Y *= matrix.M22;
			return point;
		}
コード例 #34
0
ファイル: PointTest.cs プロジェクト: nobled/mono
		public void Offset ()
		{
			Point p = new Point (4, 5);
			p.Offset (3, 4);
			Assert.AreEqual (new Point (7, 9), p);
		}
コード例 #35
0
        public void DrawCharacter(Wpg.WordprocessingGroup wordprocessingGroup1, AtomLabelCharacter alc)
        {
            Point characterPosition = new Point(alc.Position.X, alc.Position.Y);

            characterPosition.Offset(-_canvasExtents.Left, -_canvasExtents.Top);

            UInt32Value atomLabelId   = UInt32Value.FromUInt32((uint)_ooxmlId++);
            string      atomLabelName = "AtomLabel" + atomLabelId;

            Int64Value width  = OoXmlHelper.ScaleCsTtfToEmu(alc.Character.Width);
            Int64Value height = OoXmlHelper.ScaleCsTtfToEmu(alc.Character.Height);

            if (alc.IsSubScript)
            {
                width  = OoXmlHelper.ScaleCsTtfSubScriptToEmu(alc.Character.Width);
                height = OoXmlHelper.ScaleCsTtfSubScriptToEmu(alc.Character.Height);
            }
            Int64Value top  = OoXmlHelper.ScaleCmlToEmu(characterPosition.Y);
            Int64Value left = OoXmlHelper.ScaleCmlToEmu(characterPosition.X);

            // Set variable true to show bounding box of (every) character
            if (_options.ShowCharacterBoundingBoxes)
            {
                Rect boundingBox = new Rect(new Point(left, top), new Size(width, height));
                DrawCharacterBox(wordprocessingGroup1, boundingBox, "00ff00", 10);
            }

            Wps.WordprocessingShape        wordprocessingShape10        = new Wps.WordprocessingShape();
            Wps.NonVisualDrawingProperties nonVisualDrawingProperties10 = new Wps.NonVisualDrawingProperties()
            {
                Id = atomLabelId, Name = atomLabelName
            };
            Wps.NonVisualDrawingShapeProperties nonVisualDrawingShapeProperties10 = new Wps.NonVisualDrawingShapeProperties();

            Wps.ShapeProperties shapeProperties10 = new Wps.ShapeProperties();

            A.Transform2D transform2D10 = new A.Transform2D();
            A.Offset      offset11      = new A.Offset()
            {
                X = left, Y = top
            };
            A.Extents extents11 = new A.Extents()
            {
                Cx = width, Cy = height
            };

            transform2D10.Append(offset11);
            transform2D10.Append(extents11);

            A.CustomGeometry  customGeometry10  = new A.CustomGeometry();
            A.AdjustValueList adjustValueList10 = new A.AdjustValueList();
            A.Rectangle       rectangle10       = new A.Rectangle()
            {
                Left = "l", Top = "t", Right = "r", Bottom = "b"
            };

            A.PathList pathList10 = new A.PathList();

            A.Path path10 = new A.Path()
            {
                Width = width, Height = height
            };

            foreach (TtfContour contour in alc.Character.Contours)
            {
                int i = 0;
                while (i < contour.Points.Count)
                {
                    TtfPoint thisPoint = contour.Points[i];
                    TtfPoint nextPoint = null;
                    if (i < contour.Points.Count - 1)
                    {
                        nextPoint = contour.Points[i + 1];
                    }

                    switch (thisPoint.Type)
                    {
                    case TtfPoint.PointType.Start:
                        A.MoveTo moveTo1 = new A.MoveTo();
                        if (alc.IsSubScript)
                        {
                            A.Point point1 = new A.Point()
                            {
                                X = OoXmlHelper.ScaleCsTtfSubScriptToEmu(thisPoint.X - alc.Character.OriginX).ToString(),
                                Y = OoXmlHelper.ScaleCsTtfSubScriptToEmu(alc.Character.Height + thisPoint.Y - (alc.Character.Height + alc.Character.OriginY)).ToString()
                            };
                            moveTo1.Append(point1);
                            path10.Append(moveTo1);
                        }
                        else
                        {
                            A.Point point1 = new A.Point()
                            {
                                X = OoXmlHelper.ScaleCsTtfToEmu(thisPoint.X - alc.Character.OriginX).ToString(),
                                Y = OoXmlHelper.ScaleCsTtfToEmu(alc.Character.Height + thisPoint.Y - (alc.Character.Height + alc.Character.OriginY)).ToString()
                            };
                            moveTo1.Append(point1);
                            path10.Append(moveTo1);
                        }
                        i++;
                        break;

                    case TtfPoint.PointType.Line:
                        A.LineTo lineTo1 = new A.LineTo();
                        if (alc.IsSubScript)
                        {
                            A.Point point2 = new A.Point()
                            {
                                X = OoXmlHelper.ScaleCsTtfSubScriptToEmu(thisPoint.X - alc.Character.OriginX).ToString(),
                                Y = OoXmlHelper.ScaleCsTtfSubScriptToEmu(alc.Character.Height + thisPoint.Y - (alc.Character.Height + alc.Character.OriginY)).ToString()
                            };
                            lineTo1.Append(point2);
                            path10.Append(lineTo1);
                        }
                        else
                        {
                            A.Point point2 = new A.Point()
                            {
                                X = OoXmlHelper.ScaleCsTtfToEmu(thisPoint.X - alc.Character.OriginX).ToString(),
                                Y = OoXmlHelper.ScaleCsTtfToEmu(alc.Character.Height + thisPoint.Y - (alc.Character.Height + alc.Character.OriginY)).ToString()
                            };
                            lineTo1.Append(point2);
                            path10.Append(lineTo1);
                        }
                        i++;
                        break;

                    case TtfPoint.PointType.CurveOff:
                        A.QuadraticBezierCurveTo quadraticBezierCurveTo13 = new A.QuadraticBezierCurveTo();
                        if (alc.IsSubScript)
                        {
                            A.Point point3 = new A.Point()
                            {
                                X = OoXmlHelper.ScaleCsTtfSubScriptToEmu(thisPoint.X - alc.Character.OriginX).ToString(),
                                Y = OoXmlHelper.ScaleCsTtfSubScriptToEmu(alc.Character.Height + thisPoint.Y - (alc.Character.Height + alc.Character.OriginY)).ToString()
                            };
                            A.Point point4 = new A.Point()
                            {
                                X = OoXmlHelper.ScaleCsTtfSubScriptToEmu(nextPoint.X - alc.Character.OriginX).ToString(),
                                Y = OoXmlHelper.ScaleCsTtfSubScriptToEmu(alc.Character.Height + nextPoint.Y - (alc.Character.Height + alc.Character.OriginY)).ToString()
                            };
                            quadraticBezierCurveTo13.Append(point3);
                            quadraticBezierCurveTo13.Append(point4);
                            path10.Append(quadraticBezierCurveTo13);
                        }
                        else
                        {
                            A.Point point3 = new A.Point()
                            {
                                X = OoXmlHelper.ScaleCsTtfToEmu(thisPoint.X - alc.Character.OriginX).ToString(),
                                Y = OoXmlHelper.ScaleCsTtfToEmu(alc.Character.Height + thisPoint.Y - (alc.Character.Height + alc.Character.OriginY)).ToString()
                            };
                            A.Point point4 = new A.Point()
                            {
                                X = OoXmlHelper.ScaleCsTtfToEmu(nextPoint.X - alc.Character.OriginX).ToString(),
                                Y = OoXmlHelper.ScaleCsTtfToEmu(alc.Character.Height + nextPoint.Y - (alc.Character.Height + alc.Character.OriginY)).ToString()
                            };
                            quadraticBezierCurveTo13.Append(point3);
                            quadraticBezierCurveTo13.Append(point4);
                            path10.Append(quadraticBezierCurveTo13);
                        }
                        i++;
                        i++;
                        break;

                    case TtfPoint.PointType.CurveOn:
                        // Should never get here !
                        i++;
                        break;
                    }
                }

                A.CloseShapePath closeShapePath1 = new A.CloseShapePath();
                path10.Append(closeShapePath1);
            }

            pathList10.Append(path10);

            customGeometry10.Append(adjustValueList10);
            customGeometry10.Append(rectangle10);
            customGeometry10.Append(pathList10);

            A.SolidFill solidFill10 = new A.SolidFill();

            // Set Colour
            A.RgbColorModelHex rgbColorModelHex10 = new A.RgbColorModelHex()
            {
                Val = alc.Colour
            };
            solidFill10.Append(rgbColorModelHex10);

            shapeProperties10.Append(transform2D10);
            shapeProperties10.Append(customGeometry10);
            shapeProperties10.Append(solidFill10);

            Wps.ShapeStyle  shapeStyle10    = new Wps.ShapeStyle();
            A.LineReference lineReference10 = new A.LineReference()
            {
                Index = (UInt32Value)0U
            };
            A.FillReference fillReference10 = new A.FillReference()
            {
                Index = (UInt32Value)0U
            };
            A.EffectReference effectReference10 = new A.EffectReference()
            {
                Index = (UInt32Value)0U
            };
            A.FontReference fontReference10 = new A.FontReference()
            {
                Index = A.FontCollectionIndexValues.Minor
            };

            shapeStyle10.Append(lineReference10);
            shapeStyle10.Append(fillReference10);
            shapeStyle10.Append(effectReference10);
            shapeStyle10.Append(fontReference10);
            Wps.TextBodyProperties textBodyProperties10 = new Wps.TextBodyProperties();

            wordprocessingShape10.Append(nonVisualDrawingProperties10);
            wordprocessingShape10.Append(nonVisualDrawingShapeProperties10);
            wordprocessingShape10.Append(shapeProperties10);
            wordprocessingShape10.Append(shapeStyle10);
            wordprocessingShape10.Append(textBodyProperties10);

            wordprocessingGroup1.Append(wordprocessingShape10);
        }
コード例 #36
0
ファイル: VIsualHost.cs プロジェクト: tchief/DrawPolygon
 private void DrawVertexName(DrawingContext dc, Point vertexCenter, int index)
 {
     var nextVertexName = new FormattedText(string.Format(VertexNameFormat, index), CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 12, Brushes.Red);
     var textCenter = new Point(vertexCenter.X, vertexCenter.Y);
     textCenter.Offset(_vertexRadius, _vertexRadius);
     dc.DrawText(nextVertexName, textCenter);
 }
コード例 #37
0
        public void CreateElementCharacters(Atom atom, Options options)
        {
            string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()";

            //Point atomCentre = new Point((double)atom.X2, (double)atom.Y2);
            string atomLabel = atom.Element.Symbol;
            Rect   labelBounds;

            // Get Charge and Isotope values for use later on
            int iCharge    = atom.FormalCharge ?? 0;
            int iAbsCharge = Math.Abs(iCharge);
            int isoValue   = atom.IsotopeNumber ?? 0;

            // Get Implicit Hydrogen Count for use later on
            int implicitHCount = atom.ImplicitHydrogenCount;

            Point cursorPosition        = atom.Position;
            Point chargeCursorPosition  = atom.Position;
            Point isotopeCursorPosition = atom.Position;

            double lastOffset = 0;

            int bondCount = atom.Bonds.ToList().Count;

            #region Decide if atom label is to be displayed

            bool showLabel = true;
            if (atomLabel == "C")
            {
                if (atom.ShowSymbol.HasValue)
                {
                    showLabel = atom.ShowSymbol.Value;
                }
                else
                {
                    if (atom.IsInRing || bondCount > 1)
                    {
                        showLabel = false;
                    }

                    if (bondCount == 2)
                    {
                        Point p1 = atom.Bonds.ToList()[0].OtherAtom(atom).Position;
                        Point p2 = atom.Bonds.ToList()[1].OtherAtom(atom).Position;

                        double angle1 = Vector.AngleBetween(-(atom.Position - p1), atom.Position - p2);

                        if (Math.Abs(angle1) < 8)
                        {
                            showLabel = true;
                        }
                    }
                }

                // Force on if atom has charge
                if (iAbsCharge > 0)
                {
                    showLabel = true;
                }
                // Force on if atom has isotope value
                if (isoValue > 0)
                {
                    showLabel = true;
                }
            }

            #endregion Decide if atom label is to be displayed

            if (showLabel)
            {
                #region Set Up Atom Colours

                string atomColour = "000000";
                if (options.ColouredAtoms)
                {
                    if (atom.Element.Colour != null)
                    {
                        atomColour = atom.Element.Colour;
                        // Strip out # as OoXml does not use it
                        atomColour = atomColour.Replace("#", "");
                    }
                }

                #endregion Set Up Atom Colours

                #region Step 1 - Measure Bounding Box for all Characters of label

                double xMin = double.MaxValue;
                double yMin = double.MaxValue;
                double xMax = double.MinValue;
                double yMax = double.MinValue;

                Point thisCharacterPosition;
                for (int idx = 0; idx < atomLabel.Length; idx++)
                {
                    char         chr = atomLabel[idx];
                    TtfCharacter c   = _TtfCharacterSet[chr];
                    if (c != null)
                    {
                        thisCharacterPosition = GetCharacterPosition(cursorPosition, c);

                        xMin = Math.Min(xMin, thisCharacterPosition.X);
                        yMin = Math.Min(yMin, thisCharacterPosition.Y);
                        xMax = Math.Max(xMax, thisCharacterPosition.X + OoXmlHelper.ScaleCsTtfToCml(c.Width, _meanBondLength));
                        yMax = Math.Max(yMax, thisCharacterPosition.Y + OoXmlHelper.ScaleCsTtfToCml(c.Height, _meanBondLength));

                        if (idx < atomLabel.Length - 1)
                        {
                            // Move to next Character position
                            cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(c.IncrementX, _meanBondLength), 0);
                        }
                    }
                }

                #endregion Step 1 - Measure Bounding Box for all Characters of label

                #region Step 2 - Reset Cursor such that the text is centered about the atom's co-ordinates

                double width  = xMax - xMin;
                double height = yMax - yMin;
                cursorPosition        = new Point(atom.Position.X - width / 2, atom.Position.Y + height / 2);
                chargeCursorPosition  = new Point(cursorPosition.X, cursorPosition.Y);
                isotopeCursorPosition = new Point(cursorPosition.X, cursorPosition.Y);
                labelBounds           = new Rect(cursorPosition, new Size(width, height));

                #endregion Step 2 - Reset Cursor such that the text is centered about the atom's co-ordinates

                #region Step 3 - Place the characters

                foreach (char chr in atomLabel)
                {
                    TtfCharacter c = _TtfCharacterSet[chr];
                    if (c != null)
                    {
                        thisCharacterPosition = GetCharacterPosition(cursorPosition, c);
                        AtomLabelCharacter alc = new AtomLabelCharacter(thisCharacterPosition, c, atomColour, chr, atom.Path, atom.Parent.Path);
                        _AtomLabelCharacters.Add(alc);

                        // Move to next Character position
                        lastOffset = OoXmlHelper.ScaleCsTtfToCml(c.IncrementX, _meanBondLength);
                        cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(c.IncrementX, _meanBondLength), 0);
                        chargeCursorPosition = new Point(cursorPosition.X, cursorPosition.Y);
                    }
                }

                #endregion Step 3 - Place the characters

                #region Determine NESW

                double        baFromNorth = Vector.AngleBetween(BasicGeometry.ScreenNorth, atom.BalancingVector(true));
                CompassPoints nesw        = CompassPoints.East;

                if (bondCount == 1)
                {
                    nesw = BasicGeometry.SnapTo2EW(baFromNorth);
                }
                else
                {
                    nesw = BasicGeometry.SnapTo4NESW(baFromNorth);
                }

                #endregion Determine NESW

                #region Step 4 - Add Charge if required

                if (iCharge != 0)
                {
                    TtfCharacter hydrogenCharacter = _TtfCharacterSet['H'];

                    char         sign = '.';
                    TtfCharacter chargeSignCharacter = null;
                    if (iCharge >= 1)
                    {
                        sign = '+';
                        chargeSignCharacter = _TtfCharacterSet['+'];
                    }
                    else if (iCharge <= 1)
                    {
                        sign = '-';
                        chargeSignCharacter = _TtfCharacterSet['-'];
                    }

                    if (iAbsCharge > 1)
                    {
                        string digits = iAbsCharge.ToString();
                        // Insert digits
                        foreach (char chr in digits)
                        {
                            TtfCharacter chargeValueCharacter = _TtfCharacterSet[chr];
                            thisCharacterPosition = GetCharacterPosition(chargeCursorPosition, chargeValueCharacter);

                            // Raise the superscript Character
                            thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(chargeValueCharacter.Height * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR, _meanBondLength));

                            AtomLabelCharacter alcc = new AtomLabelCharacter(thisCharacterPosition, chargeValueCharacter, atomColour, chr, atom.Path, atom.Parent.Path);
                            alcc.IsSmaller   = true;
                            alcc.IsSubScript = true;
                            _AtomLabelCharacters.Add(alcc);

                            // Move to next Character position
                            chargeCursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(chargeValueCharacter.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                            cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(chargeValueCharacter.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                        }
                    }

                    // Insert sign at raised position
                    thisCharacterPosition = GetCharacterPosition(chargeCursorPosition, chargeSignCharacter);
                    thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Height * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR, _meanBondLength));
                    thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(chargeSignCharacter.Height / 2 * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR, _meanBondLength));

                    AtomLabelCharacter alcs = new AtomLabelCharacter(thisCharacterPosition, chargeSignCharacter, atomColour, sign, atom.Path, atom.Parent.Path);
                    alcs.IsSmaller   = true;
                    alcs.IsSubScript = true;
                    _AtomLabelCharacters.Add(alcs);

                    if (iAbsCharge != 0)
                    {
                        cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(chargeSignCharacter.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                    }
                }

                #endregion Step 4 - Add Charge if required

                #region Step 5 - Add Implicit H if required

                if (options.ShowHydrogens && implicitHCount > 0)
                {
                    TtfCharacter hydrogenCharacter      = _TtfCharacterSet['H'];
                    string       numbers                = "012345";
                    TtfCharacter implicitValueCharacter = _TtfCharacterSet[numbers[implicitHCount]];

                    #region Add H

                    if (hydrogenCharacter != null)
                    {
                        switch (nesw)
                        {
                        case CompassPoints.North:
                            if (atom.Bonds.ToList().Count > 1)
                            {
                                cursorPosition.X = labelBounds.X
                                                   + (labelBounds.Width / 2)
                                                   - (OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Width, _meanBondLength) / 2);
                                cursorPosition.Y = cursorPosition.Y
                                                   + OoXmlHelper.ScaleCsTtfToCml(-hydrogenCharacter.Height, _meanBondLength)
                                                   - OoXmlHelper.CHARACTER_VERTICAL_SPACING;
                                if (iCharge > 0)
                                {
                                    if (implicitHCount > 1)
                                    {
                                        cursorPosition.Offset(0,
                                                              OoXmlHelper.ScaleCsTtfToCml(
                                                                  -implicitValueCharacter.Height *
                                                                  OoXmlHelper.SUBSCRIPT_SCALE_FACTOR / 2, _meanBondLength)
                                                              - OoXmlHelper.CHARACTER_VERTICAL_SPACING);
                                    }
                                }
                            }
                            break;

                        case CompassPoints.East:
                            // Leave as is
                            break;

                        case CompassPoints.South:
                            if (atom.Bonds.ToList().Count > 1)
                            {
                                cursorPosition.X = labelBounds.X + (labelBounds.Width / 2)
                                                   - (OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Width, _meanBondLength) / 2);
                                cursorPosition.Y = cursorPosition.Y
                                                   + OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Height, _meanBondLength)
                                                   + OoXmlHelper.CHARACTER_VERTICAL_SPACING;
                            }
                            break;

                        case CompassPoints.West:
                            if (implicitHCount == 1)
                            {
                                if (iAbsCharge == 0)
                                {
                                    cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(-(hydrogenCharacter.IncrementX * 2), _meanBondLength), 0);
                                }
                                else
                                {
                                    cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(-((hydrogenCharacter.IncrementX * 2 + implicitValueCharacter.IncrementX * 1.25)), _meanBondLength), 0);
                                }
                            }
                            else
                            {
                                if (iAbsCharge == 0)
                                {
                                    cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(-(hydrogenCharacter.IncrementX * 2.5), _meanBondLength), 0);
                                }
                                else
                                {
                                    cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(-((hydrogenCharacter.IncrementX * 2 + implicitValueCharacter.IncrementX * 1.25)), _meanBondLength), 0);
                                }
                            }
                            break;
                        }

                        thisCharacterPosition = GetCharacterPosition(cursorPosition, hydrogenCharacter);
                        AtomLabelCharacter alc = new AtomLabelCharacter(thisCharacterPosition, hydrogenCharacter, atomColour, 'H', atom.Path, atom.Parent.Path);
                        _AtomLabelCharacters.Add(alc);

                        // Move to next Character position
                        cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.IncrementX, _meanBondLength), 0);

                        if (nesw == CompassPoints.East)
                        {
                            chargeCursorPosition = new Point(cursorPosition.X, cursorPosition.Y);
                        }
                        if (nesw == CompassPoints.West)
                        {
                            isotopeCursorPosition = new Point(thisCharacterPosition.X, isotopeCursorPosition.Y);
                        }
                    }

                    #endregion Add H

                    #region Add number

                    if (implicitHCount > 1)
                    {
                        if (implicitValueCharacter != null)
                        {
                            thisCharacterPosition = GetCharacterPosition(cursorPosition, implicitValueCharacter);

                            // Drop the subscript Character
                            thisCharacterPosition.Offset(0, OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Width * OoXmlHelper.SUBSCRIPT_DROP_FACTOR, _meanBondLength));

                            AtomLabelCharacter alc = new AtomLabelCharacter(thisCharacterPosition, implicitValueCharacter, atomColour, numbers[implicitHCount], atom.Path, atom.Parent.Path);
                            alc.IsSmaller   = true;
                            alc.IsSubScript = true;
                            _AtomLabelCharacters.Add(alc);

                            // Move to next Character position
                            cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(implicitValueCharacter.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                        }
                    }

                    #endregion Add number
                }

                #endregion Step 5 - Add Implicit H if required

                #region Step 6 - Add IsoTope Number if required

                if (isoValue > 0)
                {
                    string digits = isoValue.ToString();

                    xMin = double.MaxValue;
                    yMin = double.MaxValue;
                    xMax = double.MinValue;
                    yMax = double.MinValue;

                    Point isoOrigin = isotopeCursorPosition;

                    // Calculate width of digits
                    foreach (char chr in digits)
                    {
                        TtfCharacter c = _TtfCharacterSet[chr];
                        thisCharacterPosition = GetCharacterPosition(isotopeCursorPosition, c);

                        // Raise the superscript Character
                        thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(c.Height * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR, _meanBondLength));

                        xMin = Math.Min(xMin, thisCharacterPosition.X);
                        yMin = Math.Min(yMin, thisCharacterPosition.Y);
                        xMax = Math.Max(xMax, thisCharacterPosition.X + OoXmlHelper.ScaleCsTtfToCml(c.Width, _meanBondLength));
                        yMax = Math.Max(yMax, thisCharacterPosition.Y + OoXmlHelper.ScaleCsTtfToCml(c.Height, _meanBondLength));

                        // Move to next Character position
                        isotopeCursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(c.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                    }

                    // Re-position Isotope Cursor
                    width = xMax - xMin;
                    isotopeCursorPosition = new Point(isoOrigin.X - width, isoOrigin.Y);

                    // Insert digits
                    foreach (char chr in digits)
                    {
                        TtfCharacter c = _TtfCharacterSet[chr];
                        thisCharacterPosition = GetCharacterPosition(isotopeCursorPosition, c);

                        // Raise the superscript Character
                        thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(c.Height * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR, _meanBondLength));

                        AtomLabelCharacter alcc = new AtomLabelCharacter(thisCharacterPosition, c, atomColour, chr, atom.Path, atom.Parent.Path);
                        alcc.IsSmaller   = true;
                        alcc.IsSubScript = true;
                        _AtomLabelCharacters.Add(alcc);

                        // Move to next Character position
                        isotopeCursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(c.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                    }
                }

                #endregion Step 6 - Add IsoTope Number if required

                #region Step 7 - Create Convex Hull

                _convexhHulls.Add(atom.Path, ConvexHull(atom.Path));

                #endregion Step 7 - Create Convex Hull
            }
        }
コード例 #38
0
ファイル: GridView.cs プロジェクト: jawbrey/uLife
        private void drawGrid()
        {
            using (DrawingContext dc = this.grid.RenderOpen())
            {
                Rect background = new Rect(0, 0, CELL_SIZE * CELLS_X, CELL_SIZE * CELLS_Y);
                dc.DrawRectangle(Brushes.LightGray, null, background);

                Point start = new Point(0, 0);
                Point end = new Point(0, background.Bottom);
                for (int i = 0; i < CELLS_X; i++)
                {
                    dc.DrawLine(outline, start, end);
                    start.Offset(CELL_SIZE, 0);
                    end.Offset(CELL_SIZE, 0);
                }

                start = new Point(0, 0);
                end = new Point(background.Right, 0);
                for (int i = 0; i < CELLS_X; i++)
                {
                    dc.DrawLine(outline, start, end);
                    start.Offset(0, CELL_SIZE);
                    end.Offset(0, CELL_SIZE);
                }
            }
        }
コード例 #39
0
 private void DrawCord(Canvas canvas, Point centre, float theWidth)
 {
     var geometry = new StreamGeometry() { FillRule = FillRule.EvenOdd };
     using (var context = geometry.Open())
     {
         var arcRadius = theWidth / 3f;
         var curveLength = arcRadius / 5f;
         var curveWidth = arcRadius / 10f;
         var curveStartPoint = new Point(centre.X, centre.Y - arcRadius / 1.5f);
         var curveExtent = new Point(-curveWidth, curveLength);
         curveExtent.Offset(curveStartPoint.X, curveStartPoint.Y);
         var leftCtrlPoint = new Point(-1f * curveWidth, curveLength / 3f);
         leftCtrlPoint.Offset(curveStartPoint.X, curveStartPoint.Y);
         var rightCtrlPoint = new Point(2f * curveWidth, 2f * curveLength / 3f);
         rightCtrlPoint.Offset(curveStartPoint.X, curveStartPoint.Y);
         context.BeginFigure(curveStartPoint, false, false);
         context.BezierTo(leftCtrlPoint, rightCtrlPoint, curveExtent, true, true);
     }
     geometry.Freeze();
     var path = new System.Windows.Shapes.Path() { Data = geometry, Stroke = _blackColour, StrokeThickness = 4f };
     canvas.Children.Add(path);
 }
コード例 #40
0
        private void DrawFilledTriangle(Wpg.WordprocessingGroup wordprocessingGroup1, List <Point> points)
        {
            UInt32Value atomLabelId   = UInt32Value.FromUInt32((uint)m_ooxmlId++);
            string      atomLabelName = "WedgeBond" + atomLabelId;

            double minX = double.MaxValue;
            double maxX = double.MinValue;
            double minY = double.MaxValue;
            double maxY = double.MinValue;

            foreach (Point p in points)
            {
                maxX = Math.Max(p.X, maxX);
                minX = Math.Min(p.X, minX);
                maxY = Math.Max(p.Y, maxY);
                minY = Math.Min(p.Y, minY);
            }

            Rect extents = new Rect(minX, minY, maxX - minX, maxY - minY);

            // Create modifyable Points
            Point p0 = new Point(points[0].X, points[0].Y);
            Point p1 = new Point(points[1].X, points[1].Y);
            Point p2 = new Point(points[2].X, points[2].Y);

            // Move Points to have 0,0 Top Left Reference within the drawing canvas
            p0.Offset(-m_canvasExtents.Left, -m_canvasExtents.Top);
            p1.Offset(-m_canvasExtents.Left, -m_canvasExtents.Top);
            p2.Offset(-m_canvasExtents.Left, -m_canvasExtents.Top);

            // Move shape's extents to correct place in drawing canvas
            extents.Offset(-m_canvasExtents.Left, -m_canvasExtents.Top);

            // Move points again to put them inside the shape's extents
            p0.Offset(-extents.Left, -extents.Top);
            p1.Offset(-extents.Left, -extents.Top);
            p2.Offset(-extents.Left, -extents.Top);

            Int64Value top    = OoXmlHelper.ScaleCmlToEmu(extents.Y);
            Int64Value left   = OoXmlHelper.ScaleCmlToEmu(extents.X);
            Int64Value width  = OoXmlHelper.ScaleCmlToEmu(extents.Width);
            Int64Value height = OoXmlHelper.ScaleCmlToEmu(extents.Height);

            Wps.WordprocessingShape        wordprocessingShape10        = new Wps.WordprocessingShape();
            Wps.NonVisualDrawingProperties nonVisualDrawingProperties10 = new Wps.NonVisualDrawingProperties()
            {
                Id = atomLabelId, Name = atomLabelName
            };
            Wps.NonVisualDrawingShapeProperties nonVisualDrawingShapeProperties10 = new Wps.NonVisualDrawingShapeProperties();

            Wps.ShapeProperties shapeProperties10 = new Wps.ShapeProperties();

            A.Transform2D transform2D10 = new A.Transform2D();
            A.Offset      offset11      = new A.Offset()
            {
                X = left, Y = top
            };
            A.Extents extents11 = new A.Extents()
            {
                Cx = width, Cy = height
            };

            transform2D10.Append(offset11);
            transform2D10.Append(extents11);

            A.CustomGeometry  customGeometry10  = new A.CustomGeometry();
            A.AdjustValueList adjustValueList10 = new A.AdjustValueList();
            A.Rectangle       rectangle10       = new A.Rectangle()
            {
                Left = "l", Top = "t", Right = "r", Bottom = "b"
            };

            A.PathList pathList10 = new A.PathList();

            A.Path path10 = new A.Path()
            {
                Width = width, Height = height
            };

            string xCoOrdinate = OoXmlHelper.ScaleCmlToEmu(p0.X).ToString();
            string yCoOrdinate = OoXmlHelper.ScaleCmlToEmu(p0.Y).ToString();

            A.MoveTo moveTo10 = new A.MoveTo();
            A.Point  point19  = new A.Point()
            {
                X = xCoOrdinate, Y = yCoOrdinate
            };
            moveTo10.Append(point19);
            path10.Append(moveTo10);

            xCoOrdinate = OoXmlHelper.ScaleCmlToEmu(p1.X).ToString();
            yCoOrdinate = OoXmlHelper.ScaleCmlToEmu(p1.Y).ToString();

            A.LineTo lineTo10 = new A.LineTo();
            A.Point  point20  = new A.Point()
            {
                X = xCoOrdinate, Y = yCoOrdinate
            };
            lineTo10.Append(point20);
            path10.Append(lineTo10);

            xCoOrdinate = OoXmlHelper.ScaleCmlToEmu(p2.X).ToString();
            yCoOrdinate = OoXmlHelper.ScaleCmlToEmu(p2.Y).ToString();

            A.LineTo lineTo19 = new A.LineTo();
            A.Point  point29  = new A.Point()
            {
                X = xCoOrdinate, Y = yCoOrdinate
            };
            lineTo19.Append(point29);
            path10.Append(lineTo19);
            A.CloseShapePath closeShapePath1 = new A.CloseShapePath();
            path10.Append(closeShapePath1);

            pathList10.Append(path10);

            customGeometry10.Append(adjustValueList10);
            customGeometry10.Append(rectangle10);
            customGeometry10.Append(pathList10);

            A.SolidFill solidFill10 = new A.SolidFill();

            A.RgbColorModelHex rgbColorModelHex10 = new A.RgbColorModelHex()
            {
                Val = "000000"
            };
            A.Alpha alpha10 = new A.Alpha()
            {
                Val = new Int32Value()
                {
                    InnerText = "100%"
                }
            };

            rgbColorModelHex10.Append(alpha10);

            solidFill10.Append(rgbColorModelHex10);

            shapeProperties10.Append(transform2D10);
            shapeProperties10.Append(customGeometry10);
            shapeProperties10.Append(solidFill10);

            Wps.ShapeStyle  shapeStyle10    = new Wps.ShapeStyle();
            A.LineReference lineReference10 = new A.LineReference()
            {
                Index = (UInt32Value)0U
            };
            A.FillReference fillReference10 = new A.FillReference()
            {
                Index = (UInt32Value)0U
            };
            A.EffectReference effectReference10 = new A.EffectReference()
            {
                Index = (UInt32Value)0U
            };
            A.FontReference fontReference10 = new A.FontReference()
            {
                Index = A.FontCollectionIndexValues.Minor
            };

            shapeStyle10.Append(lineReference10);
            shapeStyle10.Append(fillReference10);
            shapeStyle10.Append(effectReference10);
            shapeStyle10.Append(fontReference10);
            Wps.TextBodyProperties textBodyProperties10 = new Wps.TextBodyProperties();

            wordprocessingShape10.Append(nonVisualDrawingProperties10);
            wordprocessingShape10.Append(nonVisualDrawingShapeProperties10);
            wordprocessingShape10.Append(shapeProperties10);
            wordprocessingShape10.Append(shapeStyle10);
            wordprocessingShape10.Append(textBodyProperties10);

            wordprocessingGroup1.Append(wordprocessingShape10);
        }
コード例 #41
0
        internal override NodePart HitTest(double x, double y, out int index)
        {
            System.Windows.Point pt = this.nodePosition;

            double xMiddle = pt.X + this.centerLine;
            double yMiddle = pt.Y + (this.Height / 2);

            index = -1;

            if (this.IsWithinClickRegion(pt, x, y) && dotsFlag.HasFlag(MenuDots.NorthWest))
            {
                return(NodePart.NorthWest);
            }

            pt.X += this.centerLine + 2;
            pt.Y += 2;

            if (this.IsWithinClickRegion(pt, x, y) && dotsFlag.HasFlag(MenuDots.North))
            {
                return(NodePart.North);
            }

            pt    = this.nodePosition;
            pt.X += this.Width - 2;
            pt.Y += 2;

            if (this.IsWithinClickRegion(pt, x, y) && dotsFlag.HasFlag(MenuDots.NorthEast))
            {
                return(NodePart.NorthEast);
            }

            pt    = this.nodePosition;
            pt.X += this.Width - 2;
            pt.Y += this.Height - Configurations.HittestPixels;

            pt    = this.nodePosition;
            pt.X += this.centerLine + 2;
            pt.Y += this.Height - Configurations.TextVerticalOffset;

            if (this.IsWithinClickRegion(pt, x, y) && dotsFlag.HasFlag(MenuDots.South))
            {
                return(NodePart.South);
            }

            pt = this.nodePosition;
            pt.Offset(0, 1);

            int    replicationCount = this.inputSlots.Count;
            double replicationLine  = pt.X + this.CenterLine - GetMaxReplicationTextWidth();

            if (y > pt.Y && y < pt.Y + this.Height)
            {
                if (x > pt.X - Configurations.OutputHittestPixels && x <= pt.X + Configurations.HittestPixels)
                {
                    double slotCount  = this.inputSlots.Count;
                    double slotHeight = (this.Height) / slotCount;
                    index = (int)((y - pt.Y) / slotHeight);
                    if (this.inputSlots.Count == 0)
                    {
                        index = -1;
                        if (x >= pt.X && x < pt.X + Configurations.HittestPixels)
                        {
                            return(NodePart.InputLabel);
                        }
                    }
                    return(NodePart.InputSlot);
                }
                else if (x > pt.X + Configurations.HittestPixels && x < pt.X + this.CenterLine)
                {
                    double slotCount  = this.inputSlots.Count;
                    double slotHeight = (this.Height) / slotCount;
                    index = (int)((y - pt.Y) / slotHeight);
                    if (index >= 0 && (index < Configurations.ArraySize))
                    {
                        if (slotCount > 1 && x > replicationLine)
                        {
                            return(NodePart.ReplicationGuide);
                        }
                    }

                    return(NodePart.InputLabel);
                }
                else if (x > pt.X + this.CenterLine && x < pt.X + Width - Configurations.HittestPixels)
                {
                    index = 0;
                    if (y > (pt.Y + Height / 2) && y < pt.Y + Height)
                    {
                        return(NodePart.Text);
                    }
                    else
                    {
                        return(NodePart.Caption);
                    }
                }
                else if (x > pt.X + Width - Configurations.HittestPixels && x < pt.X + Width + Configurations.OutputHittestPixels)
                {
                    if (y > pt.Y + Height / 2 && y < pt.Y + Height)
                    {
                        index = 0;
                        return(NodePart.OutputSlot);
                    }
                    else
                    {
                        return(NodePart.Caption);
                    }
                }
            }

            if (this.previewBubble != null)
            {
                pt = this.previewBubble.RectPosition;
                pt.Offset(this.nodePosition.X, this.nodePosition.Y);
                pt.Offset(this.previewBubble.Width - 2, 2);
                if (IsWithinClickRegion(pt, x, y))
                {
                    return(NodePart.PreviewNorthEast);
                }
            }

            pt = this.nodePosition;
            if (y > pt.Y + this.Height + Configurations.InfoBubbleTopMargin)
            {
                return(NodePart.Preview);
            }

            return(NodePart.None);
        }
コード例 #42
0
        internal static Point CalculateDropLocation(Size droppedSize, DependencyObject autoConnectTarget, AutoConnectDirections direction, HashSet<Point> shapeLocations)
        {
            Point dropPoint = new Point(-1, -1);
            if (autoConnectTarget != null)
            {
                Point location = FreeFormPanel.GetLocation(autoConnectTarget);
                Size size = FreeFormPanel.GetChildSize(autoConnectTarget);
                switch (direction)
                {
                    case AutoConnectDirections.Left:
                        dropPoint = new Point(location.X - DropPointOffset - droppedSize.Width, location.Y + ((size.Height - droppedSize.Height) / 2));
                        break;
                    case AutoConnectDirections.Right:
                        dropPoint = new Point(location.X + size.Width + DropPointOffset, location.Y + ((size.Height - droppedSize.Height) / 2));
                        break;
                    case AutoConnectDirections.Top:
                        dropPoint = new Point(location.X + ((size.Width - droppedSize.Width) / 2), location.Y - DropPointOffset - droppedSize.Height);
                        break;
                    case AutoConnectDirections.Bottom:
                        dropPoint = new Point(location.X + ((size.Width - droppedSize.Width) / 2), location.Y + DropPointOffset + size.Height);
                        break;
                    default:
                        Fx.Assert(false, "Should not be here");
                        break;
                }

                dropPoint = new Point(dropPoint.X < 0 ? 0 : dropPoint.X, dropPoint.Y < 0 ? 0 : dropPoint.Y);
                if (shapeLocations != null)
                {
                    while (shapeLocations.Contains(dropPoint))
                    {
                        dropPoint.Offset(FreeFormPanel.GridSize, FreeFormPanel.GridSize);
                    }
                }
            }

            return dropPoint;
        }
コード例 #43
0
            public Point OffsetShapeLocation(Point shapeLocation)
            {
                if (this.isFirstShape)
                {
                    this.lastShape = shapeLocation;
                    this.isFirstShape = false;
                    return shapeLocation;
                }

                // the shapeLocation must be at least at right-down of lastShape
                Double detX = shapeLocation.X - (lastShape.X + FreeFormPanel.GridSize);
                Double detY = shapeLocation.Y - (lastShape.Y + FreeFormPanel.GridSize);
                if (detX < 0 || detY < 0)
                {
                    // overlapped
                    // then offset shapeLocation. 
                    // offsetX and offsetY must be from Integer * FreeFormPanel.GridSize, because
                    // shapeLocation is aligned to grid, and we expect after the offset, it is 
                    // still aligned.
                    Double offsetX = Math.Ceiling(-detX / FreeFormPanel.GridSize) * FreeFormPanel.GridSize;
                    Double offsetY = Math.Ceiling(-detY / FreeFormPanel.GridSize) * FreeFormPanel.GridSize;
                    shapeLocation.Offset(offsetX, offsetY);
                }
                this.lastShape = shapeLocation;
                return this.lastShape;
            }
コード例 #44
0
ファイル: PropertyNode.cs プロジェクト: samuto/designscript
        protected override void ComposeCore(System.Windows.Media.DrawingContext drawingContext, System.Windows.Media.DrawingVisual visual)
        {
            //Text and Caption size
            string tempText = string.Empty;
            double textWidth = Utilities.GetTextWidth(this.Text);
            double captionWidth = Utilities.GetTextWidth(this.Caption);
            if (this.Text.Count() > 25)
            {
                tempText = this.Text.Substring(0, 25);
                tempText += "...";
                textWidth = Utilities.GetTextWidth(tempText);
            }
            else
                tempText = this.Text;

            //Node width
            if (textWidth > captionWidth)
                this.nodeDimension.Width = (int)(Configurations.NodeWidthProperty + textWidth + 1);
            else
                this.nodeDimension.Width = (int)(Configurations.NodeWidthProperty + captionWidth + 1);

            //Node height
            this.nodeDimension.Height = Configurations.NodeHeightProperty;

            base.ComposeCore(drawingContext, visual);

            Rect rect = new Rect(new Point(1, 1), new Size((int)(this.nodeDimension.Width - 1), (int)(this.nodeDimension.Height - 1)));
            drawingContext.DrawRectangle(Configurations.RectGrey, Configurations.NoBorderPen, rect);

            //horizontal Line
            Point p1 = new Point(1, 1);
            p1.Offset(Configurations.TextHorizontalOffset, (int)(this.Height) / 2);
            p1.Offset(0, 0.5);
            Point p2 = p1;
            p2.X = (this.Width - 1) - Configurations.TextHorizontalOffset;
            drawingContext.DrawLine(Configurations.BorderPen, p1, p2);

            //draw caption and text
            p1 = new Point(1, 1);
            p1.Offset(0, Configurations.TextVerticalOffset);
            p1.X = (this.Width / 2) - captionWidth / 2;
            Utilities.DrawText(drawingContext, this.Caption, p1, Configurations.TextNormalColor);
            p1.Y = ((this.Height - 3) / 2) + Configurations.TextVerticalOffset;
            p1.X = (this.Width / 2) - textWidth / 2;
            Utilities.DrawBoldText(drawingContext, tempText, p1);

            //OutputSlot
            p1 = new Point(this.Width, (this.Height / 4));
            p1.Y += (this.Height / 2) - 2;
            DrawingUtilities.DrawDots(drawingContext, DotTypes.TopRight | DotTypes.MiddleRight | DotTypes.BottomRight, p1, AnchorPoint.TopRight, false);
            //OutputSlotHittestPixels
            p1.Y -= (this.Height / 4) - 1;
            drawingContext.DrawRectangle(Configurations.SlotHitTestColor, Configurations.NoBorderPen, new Rect(p1, new Size(Configurations.HittestPixels, this.Height / 2)));

            //NorthEast
            Point p = new Point(0, 0);
            p.Offset(this.Width, Configurations.ContextMenuMargin);
            if (dotsFlag.HasFlag(MenuDots.NorthEast))
                DrawingUtilities.DrawDots(drawingContext, DotTypes.Top | DotTypes.TopRight | DotTypes.MiddleRight, p, AnchorPoint.TopRight, false);

            //NorthWest
            p = new Point(0, 0);
            p.Offset(Configurations.ContextMenuMargin, Configurations.ContextMenuMargin);
            //DrawingUtilities.DrawDots(drawingContext, DotTypes.TopLeft | DotTypes.Top | DotTypes.MiddleLeft, p, AnchorPoint.TopLeft, false);

            //South
            p = new Point(0, 0);
            p.Offset(Configurations.ContextMenuMargin, this.Height);
            //DrawingUtilities.DrawDots(drawingContext, DotTypes.MiddleLeft | DotTypes.BottomLeft | DotTypes.Bottom, p, AnchorPoint.BottomLeft, false);

            //input Slots
            if (this.inputSlots.Count != 0)
            {
                p1 = new Point(-1, 1);
                p1.Y += Configurations.TextVerticalOffset + Configurations.SlotSize / 2;
                Utilities.DrawSlot(drawingContext, p1);
            }

            // Fix: IDE-1616 Geometry property previews are not showing up.
            // Fix: IDE-1623 Preview not coming for the property nodes.
            if (previewBubble != null)
                this.previewBubble.Compose();
        }
コード例 #45
0
ファイル: LayerStack.cs プロジェクト: aragoubi/Nine
        internal void AddNewBullet(Point position)
        {
            var bulletRadius = 15;
            position.Offset(-bulletRadius, -bulletRadius);
            var quiz = ((QuizContent) lessonModel.Exercises.Contents[lessonViewModel.CurrentPageIndex]);
            var bulletPosition = new Layers.Components.Point(position.X, position.Y);
            var bulletIndex = CurrentLayer.GetLastBulletOffset() + 1;
            quiz.AddBullet(bulletIndex, bulletPosition);

            // Forward the adding to each Layer of the View to update it
            foreach (var layer in Layers)
            {
                layer.Value.AddBullet(bulletIndex, position);
            }
        }
コード例 #46
0
ファイル: MainWindow.cs プロジェクト: liuwenye2010/prj_vs2019
        // This method performs the Point operations
        public void PerformOperation(object sender, RoutedEventArgs e)
        {
            var li = sender as RadioButton;

            // Strings used to display the results
            string syntaxString, resultType, operationString;

            // The local variables point1, point2, vector2, etc are defined in each
            // case block for readability reasons. Each variable is contained within
            // the scope of each case statement.
            switch (li?.Name)
            {
            //begin switch

            case "rb1":
            {
                // Translates a Point by a Vector using the overloaded + operator.
                // Returns a Point.
                var point1  = new System.Windows.Point(10, 5);
                var vector1 = new Vector(20, 30);

                var pointResult = point1 + vector1;
                // pointResult is equal to (30, 35)

                // Note: Adding a Point to a Point is not a legal operation

                // Displaying Results
                syntaxString    = "pointResult = point1 + vector1;";
                resultType      = "Point";
                operationString = "Adding a Point and Vector";
                ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb2":
            {
                // Translates a Point by a Vector using the static Add method.
                // Returns a Point.
                var point1  = new System.Windows.Point(10, 5);
                var vector1 = new Vector(20, 30);

                var pointResult = System.Windows.Point.Add(point1, vector1);
                // pointResult is equal to (30, 35)

                // Displaying Results
                syntaxString    = "pointResult = Point.Add(point1, vector1);";
                resultType      = "Point";
                operationString = "Adding a Point and Vector";
                ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb3":
            {
                // Subtracts a Vector from a Point using the overloaded - operator.
                // Returns a Point.
                var point1  = new System.Windows.Point(10, 5);
                var vector1 = new Vector(20, 30);

                var pointResult = point1 - vector1;
                // pointResult is equal to (-10, -25)

                // Displaying Results
                syntaxString    = "pointResult = point1 - vector1;";
                resultType      = "Point";
                operationString = "Subtracting a Vector from a Point";
                ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb4":
            {
                // Subtracts a Vector from a Point using the static Subtract method.
                // Returns a Point.
                var point1  = new System.Windows.Point(10, 5);
                var vector1 = new Vector(20, 30);

                var pointResult = System.Windows.Point.Subtract(point1, vector1);
                // pointResult is equal to (-10, -25)

                // Displaying Results
                syntaxString    = "pointResult = Point.Subtract(point1, vector1);";
                resultType      = "Point";
                operationString = "Subtracting a Vector from a Point";
                ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb5":
            {
                // Subtracts a Point from a Point using the overloaded - operator.
                // Returns a Vector.
                var point1 = new System.Windows.Point(10, 5);
                var point2 = new System.Windows.Point(15, 40);

                var vectorResult = point1 - point2;
                // vectorResult is equal to (-5, -35)

                // Displaying Results
                syntaxString    = "vectorResult = point1 - point2;";
                resultType      = "Vector";
                operationString = "Subtracting a Point from a Point";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb6":
            {
                // Subtracts a Point from a Point using the static Subtract method.
                // Returns a Vector.
                var point1 = new System.Windows.Point(10, 5);
                var point2 = new System.Windows.Point(15, 40);

                var vectorResult = System.Windows.Point.Subtract(point1, point2);
                // vectorResult is equal to (-5, -35)

                // Displaying Results
                syntaxString    = "vectorResult = Point.Subtract(point1, point2);";
                resultType      = "Vector";
                operationString = "Subtracting a Point from a Point";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb7":
            {
                // Offsets the X and Y values of a Point.
                var point1 = new System.Windows.Point(10, 5);

                point1.Offset(20, 30);
                // point1 is equal to (30, 35)

                // Note: This operation is equivalent to adding a point
                // to vector with the corresponding X,Y values.

                // Displaying Results
                syntaxString    = "point1.Offset(20,30);";
                resultType      = "Point";
                operationString = "Offsetting a Point";
                ShowResults(point1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb8":
            {
                // Multiplies a Point by a Matrix.
                // Returns a Point.
                var point1  = new System.Windows.Point(10, 5);
                var matrix1 = new Matrix(40, 50, 60, 70, 80, 90);

                var pointResult = point1 * matrix1;
                // pointResult is equal to (780, 940)

                // Displaying Results
                resultType      = "Point";
                syntaxString    = "pointResult = point1 * matrix1;";
                operationString = "Multiplying a Point by a Matrix";
                ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb9":
            {
                // Multiplies a Point by a Matrix.
                // Returns a Point.
                var point1  = new System.Windows.Point(10, 5);
                var matrix1 = new Matrix(40, 50, 60, 70, 80, 90);

                var pointResult = System.Windows.Point.Multiply(point1, matrix1);
                // pointResult is equal to (780, 940)

                // Displaying Results
                resultType      = "Point";
                syntaxString    = "pointResult = Point.Multiply(point1, matrix1);";
                operationString = "Multiplying a Point by a Matrix";
                ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb10":
            {
                // Checks if two Points are equal using the overloaded equality operator.
                var point1 = new System.Windows.Point(10, 5);
                var point2 = new System.Windows.Point(15, 40);

                var areEqual = (point1 == point2);
                // areEqual is False

                // Displaying Results
                syntaxString    = "areEqual = (point1 == point2);";
                resultType      = "Boolean";
                operationString = "Checking if two points are equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }


            case "rb11":
            {
                // Checks if two Points are equal using the static Equals method.
                var point1 = new System.Windows.Point(10, 5);
                var point2 = new System.Windows.Point(15, 40);

                var areEqual = System.Windows.Point.Equals(point1, point2);
                // areEqual is False

                // Displaying Results
                syntaxString    = "areEqual = Point.Equals(point1, point2);";
                resultType      = "Boolean";
                operationString = "Checking if two points are equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb12":
            {
                // Compares an Object and a Point for equality using the non-static Equals method.
                var point1 = new System.Windows.Point(10, 5);
                var point2 = new System.Windows.Point(15, 40);

                var areEqual = point1.Equals(point2);
                // areEqual is False


                // Displaying Results
                syntaxString    = "areEqual = point1.Equals(point2);";
                resultType      = "Boolean";
                operationString = "Checking if two points are equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb13":
            {
                // Compares an Object and a Vector for equality using the non-static Equals method.
                var vector1 = new Vector(20, 30);
                var vector2 = new Vector(45, 70);

                var areEqual = vector1.Equals(vector2);
                // areEqual is False


                // Displaying Results
                syntaxString    = "areEqual = vector1.Equals(vector2);";
                resultType      = "Boolean";
                operationString = "Checking if two vectors are equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb14":
            {
                // Converts a string representation of a point into a Point structure

                var pointResult = System.Windows.Point.Parse("1,3");
                // pointResult is equal to (1, 3)

                // Displaying Results
                syntaxString    = "pointResult = Point.Parse(\"1,3\");";
                resultType      = "Matrix";
                operationString = "Converts a string into a Point structure.";
                ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb15":
            {
                // Gets a string representation of a Point structure
                var point1 = new System.Windows.Point(10, 5);

                var pointString = point1.ToString();
                // pointString is equal to 10,5

                // Displaying Results
                syntaxString    = "pointString = point1.ToString();";
                resultType      = "String";
                operationString = "Getting the string representation of a Point";
                ShowResults(pointString, syntaxString, resultType, operationString);
                break;
            }

            case "rb16":
            {
                // Gets the hashcode of a Point structure

                var point1 = new System.Windows.Point(10, 5);

                var pointHashCode = point1.GetHashCode();

                // Displaying Results
                syntaxString    = "pointHashCode = point1.GetHashCode();";
                resultType      = "int";
                operationString = "Getting the hashcode of Point";
                ShowResults(pointHashCode.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb17":
            {
                // Explicitly converts a Point structure into a Size structure
                // Returns a Size.

                var point1 = new System.Windows.Point(10, 5);

                var size1 = (Size)point1;
                // size1 has a width of 10 and a height of 5

                // Displaying Results
                syntaxString    = "size1 = (Size)point1;";
                resultType      = "Size";
                operationString = "Expliciting casting a Point into a Size";
                ShowResults(size1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb18":
            {
                // Explicitly converts a Point structure into a Vector structure
                // Returns a Vector.

                var point1 = new System.Windows.Point(10, 5);

                var vector1 = (Vector)point1;
                // vector1 is equal to (10,5)

                // Displaying Results
                syntaxString    = "vector1 = (Vector)point1;";
                resultType      = "Vector";
                operationString = "Expliciting casting a Point into a Vector";
                ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            // task example.  Not accessed through radio buttons
            case "rb20":
            {
                // Checks if two Points are not equal using the overloaded inequality operator.

                // Declaring point1 and initializing x,y values
                var point1 = new System.Windows.Point(10, 5);

                // Declaring point2 without initializing x,y values
                var point2 = new System.Windows.Point
                {
                    X = 15,
                    Y = 40
                };

                // Boolean to hold the result of the comparison

                // assigning values to point2

                // checking for inequality
                var areNotEqual = (point1 != point2);

                // areNotEqual is True

                // Displaying Results
                syntaxString    = "areNotEqual = (point1 != point2);";
                resultType      = "Boolean";
                operationString = "Checking if two points are not equal";
                ShowResults(areNotEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }
            } //end switch
        }
コード例 #47
0
        public void DrawCharacter(Wpg.WordprocessingGroup wordprocessingGroup, AtomLabelCharacter alc)
        {
            Point characterPosition = new Point(alc.Position.X, alc.Position.Y);

            characterPosition.Offset(-_canvasExtents.Left, -_canvasExtents.Top);

            UInt32Value id            = UInt32Value.FromUInt32((uint)_ooxmlId++);
            string      atomLabelName = "Atom " + alc.ParentAtom;

            Int64Value width  = OoXmlHelper.ScaleCsTtfToEmu(alc.Character.Width, _meanBondLength);
            Int64Value height = OoXmlHelper.ScaleCsTtfToEmu(alc.Character.Height, _meanBondLength);

            if (alc.IsSmaller)
            {
                width  = OoXmlHelper.ScaleCsTtfSubScriptToEmu(alc.Character.Width, _meanBondLength);
                height = OoXmlHelper.ScaleCsTtfSubScriptToEmu(alc.Character.Height, _meanBondLength);
            }
            Int64Value top  = OoXmlHelper.ScaleCmlToEmu(characterPosition.Y);
            Int64Value left = OoXmlHelper.ScaleCmlToEmu(characterPosition.X);

            // Set variable true to show bounding box of (every) character
            if (_options.ShowCharacterBoundingBoxes)
            {
                Rect boundingBox = new Rect(new Point(left, top), new Size(width, height));
                DrawCharacterBox(wordprocessingGroup, boundingBox, "00ff00", 0.25);
            }

            Wps.WordprocessingShape        shape = new Wps.WordprocessingShape();
            Wps.NonVisualDrawingProperties nonVisualDrawingProperties = new Wps.NonVisualDrawingProperties()
            {
                Id = id, Name = atomLabelName
            };
            Wps.NonVisualDrawingShapeProperties nonVisualDrawingShapeProperties = new Wps.NonVisualDrawingShapeProperties();

            Wps.ShapeProperties shapeProperties = new Wps.ShapeProperties();

            A.Transform2D transform2D = new A.Transform2D();
            A.Offset      offset      = new A.Offset {
                X = left, Y = top
            };
            A.Extents extents = new A.Extents {
                Cx = width, Cy = height
            };

            transform2D.Append(offset);
            transform2D.Append(extents);

            A.CustomGeometry  geometry        = new A.CustomGeometry();
            A.AdjustValueList adjustValueList = new A.AdjustValueList();
            A.Rectangle       rectangle       = new A.Rectangle {
                Left = "l", Top = "t", Right = "r", Bottom = "b"
            };

            A.PathList pathList = new A.PathList();

            A.Path path = new A.Path {
                Width = width, Height = height
            };

            foreach (TtfContour contour in alc.Character.Contours)
            {
                int i = 0;

                while (i < contour.Points.Count)
                {
                    TtfPoint thisPoint = contour.Points[i];
                    TtfPoint nextPoint = null;
                    if (i < contour.Points.Count - 1)
                    {
                        nextPoint = contour.Points[i + 1];
                    }

                    switch (thisPoint.Type)
                    {
                    case TtfPoint.PointType.Start:
                        A.MoveTo moveTo = new A.MoveTo();
                        if (alc.IsSmaller)
                        {
                            A.Point point = MakeSubscriptPoint(thisPoint);
                            moveTo.Append(point);
                            path.Append(moveTo);
                        }
                        else
                        {
                            A.Point point = MakeNormalPoint(thisPoint);
                            moveTo.Append(point);
                            path.Append(moveTo);
                        }
                        i++;
                        break;

                    case TtfPoint.PointType.Line:
                        A.LineTo lineTo = new A.LineTo();
                        if (alc.IsSmaller)
                        {
                            A.Point point = MakeSubscriptPoint(thisPoint);
                            lineTo.Append(point);
                            path.Append(lineTo);
                        }
                        else
                        {
                            A.Point point = MakeNormalPoint(thisPoint);
                            lineTo.Append(point);
                            path.Append(lineTo);
                        }
                        i++;
                        break;

                    case TtfPoint.PointType.CurveOff:
                        A.QuadraticBezierCurveTo quadraticBezierCurveTo = new A.QuadraticBezierCurveTo();
                        if (alc.IsSmaller)
                        {
                            A.Point pointA = MakeSubscriptPoint(thisPoint);
                            A.Point pointB = MakeSubscriptPoint(nextPoint);
                            quadraticBezierCurveTo.Append(pointA);
                            quadraticBezierCurveTo.Append(pointB);
                            path.Append(quadraticBezierCurveTo);
                        }
                        else
                        {
                            A.Point pointA = MakeNormalPoint(thisPoint);
                            A.Point pointB = MakeNormalPoint(nextPoint);
                            quadraticBezierCurveTo.Append(pointA);
                            quadraticBezierCurveTo.Append(pointB);
                            path.Append(quadraticBezierCurveTo);
                        }
                        i++;
                        i++;
                        break;

                    case TtfPoint.PointType.CurveOn:
                        // Should never get here !
                        i++;
                        break;
                    }
                }

                A.CloseShapePath closeShapePath = new A.CloseShapePath();
                path.Append(closeShapePath);
            }

            pathList.Append(path);

            geometry.Append(adjustValueList);
            geometry.Append(rectangle);
            geometry.Append(pathList);

            A.SolidFill solidFill = new A.SolidFill();

            // Set Colour
            A.RgbColorModelHex rgbColorModelHex = new A.RgbColorModelHex {
                Val = alc.Colour
            };
            solidFill.Append(rgbColorModelHex);

            shapeProperties.Append(transform2D);
            shapeProperties.Append(geometry);
            shapeProperties.Append(solidFill);

            OoXmlHelper.AppendShapeStyle(shape, nonVisualDrawingProperties, nonVisualDrawingShapeProperties, shapeProperties);
            wordprocessingGroup.Append(shape);

            // Local Functions
            A.Point MakeSubscriptPoint(TtfPoint ttfPoint)
            {
                A.Point pp = new A.Point
                {
                    X = $"{OoXmlHelper.ScaleCsTtfSubScriptToEmu(ttfPoint.X - alc.Character.OriginX, _meanBondLength)}",
                    Y = $"{OoXmlHelper.ScaleCsTtfSubScriptToEmu(alc.Character.Height + ttfPoint.Y - (alc.Character.Height + alc.Character.OriginY), _meanBondLength)}"
                };
                return(pp);
            }

            A.Point MakeNormalPoint(TtfPoint ttfPoint)
            {
                A.Point pp = new A.Point
                {
                    X = $"{OoXmlHelper.ScaleCsTtfToEmu(ttfPoint.X - alc.Character.OriginX, _meanBondLength)}",
                    Y = $"{OoXmlHelper.ScaleCsTtfToEmu(alc.Character.Height + ttfPoint.Y - (alc.Character.Height + alc.Character.OriginY), _meanBondLength)}"
                };
                return(pp);
            }
        }
コード例 #48
0
ファイル: FastListView.cs プロジェクト: grarup/SharpE
        protected override void OnRender(DrawingContext drawingContext)
        {
            drawingContext.PushClip(GetLayoutClip(m_clipSize));
              Rect rect = new Rect(new Point(0,0), m_clipSize);
              drawingContext.DrawRectangle(Brushes.Transparent, null, rect);

              int index = ((int) (ScrollValue/m_itemHeight));
              Point position = new Point(5,5);
              while (position.Y < m_clipSize.Height && index < m_list.Count)
              {
            if (SelectedIndex == index)
            {
              SolidColorBrush mySolidColorBrush = new SolidColorBrush { Color = Color.FromArgb(0xFF, 0x00, 0x80, 0xC0) };
              Rect myRect = new Rect(new Point(position.X - 3, position.Y) , new Size(Width - 4, m_itemHeight));
              drawingContext.DrawRectangle(mySolidColorBrush, null, myRect);
            }
            ItemRender.Render(drawingContext, position, m_list[index]);
            position.Offset(0, m_itemHeight);
            index++;
              }
              drawingContext.Pop();
        }
コード例 #49
0
ファイル: OoXmlRenderer.cs プロジェクト: Chem4Word/Version3
        private void DrawLine(Wpg.WordprocessingGroup wordprocessingGroup1, Rect extents, Point startPoint, Point endPoint, string colour, int thick)
        {
            UInt32Value bondLineId   = UInt32Value.FromUInt32((uint)_ooxmlId++);
            string      bondLineName = "diag-line-" + bondLineId;

            // Move Bond Line Extents and Points to have 0,0 Top Left Reference
            startPoint.Offset(-_canvasExtents.Left, -_canvasExtents.Top);
            endPoint.Offset(-_canvasExtents.Left, -_canvasExtents.Top);
            extents.Offset(-_canvasExtents.Left, -_canvasExtents.Top);

            // Move points into New Bond Line Extents
            startPoint.Offset(-extents.Left, -extents.Top);
            endPoint.Offset(-extents.Left, -extents.Top);

            Int64Value width  = OoXmlHelper.ScaleCmlToEmu(extents.Width);
            Int64Value height = OoXmlHelper.ScaleCmlToEmu(extents.Height);
            Int64Value top    = OoXmlHelper.ScaleCmlToEmu(extents.Top);
            Int64Value left   = OoXmlHelper.ScaleCmlToEmu(extents.Left);

            Wps.WordprocessingShape        wordprocessingShape1        = new Wps.WordprocessingShape();
            Wps.NonVisualDrawingProperties nonVisualDrawingProperties1 = new Wps.NonVisualDrawingProperties()
            {
                Id = bondLineId, Name = bondLineName
            };
            Wps.NonVisualDrawingShapeProperties nonVisualDrawingShapeProperties1 = new Wps.NonVisualDrawingShapeProperties();

            Wps.ShapeProperties shapeProperties1 = new Wps.ShapeProperties();

            A.Transform2D transform2D1 = new A.Transform2D();
            A.Offset      offset2      = new A.Offset()
            {
                X = left, Y = top
            };
            A.Extents extents2 = new A.Extents()
            {
                Cx = width, Cy = height
            };

            transform2D1.Append(offset2);
            transform2D1.Append(extents2);

            A.CustomGeometry  customGeometry1  = new A.CustomGeometry();
            A.AdjustValueList adjustValueList1 = new A.AdjustValueList();
            A.Rectangle       rectangle1       = new A.Rectangle()
            {
                Left = "l", Top = "t", Right = "r", Bottom = "b"
            };

            A.PathList pathList1 = new A.PathList();

            A.Path path1 = new A.Path()
            {
                Width = width, Height = height
            };

            A.MoveTo moveTo1 = new A.MoveTo();
            A.Point  point1  = new A.Point()
            {
                X = OoXmlHelper.ScaleCmlToEmu(startPoint.X).ToString(), Y = OoXmlHelper.ScaleCmlToEmu(startPoint.Y).ToString()
            };
            moveTo1.Append(point1);

            A.LineTo lineTo1 = new A.LineTo();
            A.Point  point2  = new A.Point()
            {
                X = OoXmlHelper.ScaleCmlToEmu(endPoint.X).ToString(), Y = OoXmlHelper.ScaleCmlToEmu(endPoint.Y).ToString()
            };
            lineTo1.Append(point2);

            path1.Append(moveTo1);
            path1.Append(lineTo1);

            pathList1.Append(path1);

            customGeometry1.Append(adjustValueList1);
            customGeometry1.Append(rectangle1);
            customGeometry1.Append(pathList1);

            A.Outline outline1 = new A.Outline()
            {
                Width = thick, CapType = A.LineCapValues.Round
            };

            A.SolidFill solidFill1 = new A.SolidFill();

            A.RgbColorModelHex rgbColorModelHex1 = new A.RgbColorModelHex()
            {
                Val = colour
            };
            A.Alpha alpha1 = new A.Alpha()
            {
                Val = new Int32Value()
                {
                    InnerText = "100%"
                }
            };

            rgbColorModelHex1.Append(alpha1);

            solidFill1.Append(rgbColorModelHex1);

            outline1.Append(solidFill1);

            shapeProperties1.Append(transform2D1);
            shapeProperties1.Append(customGeometry1);
            shapeProperties1.Append(outline1);

            Wps.ShapeStyle  shapeStyle1    = new Wps.ShapeStyle();
            A.LineReference lineReference1 = new A.LineReference()
            {
                Index = (UInt32Value)0U
            };
            A.FillReference fillReference1 = new A.FillReference()
            {
                Index = (UInt32Value)0U
            };
            A.EffectReference effectReference1 = new A.EffectReference()
            {
                Index = (UInt32Value)0U
            };
            A.FontReference fontReference1 = new A.FontReference()
            {
                Index = A.FontCollectionIndexValues.Minor
            };

            shapeStyle1.Append(lineReference1);
            shapeStyle1.Append(fillReference1);
            shapeStyle1.Append(effectReference1);
            shapeStyle1.Append(fontReference1);
            Wps.TextBodyProperties textBodyProperties1 = new Wps.TextBodyProperties();

            wordprocessingShape1.Append(nonVisualDrawingProperties1);
            wordprocessingShape1.Append(nonVisualDrawingShapeProperties1);
            wordprocessingShape1.Append(shapeProperties1);
            wordprocessingShape1.Append(shapeStyle1);
            wordprocessingShape1.Append(textBodyProperties1);

            wordprocessingGroup1.Append(wordprocessingShape1);
        }
コード例 #50
0
ファイル: LayerStack.cs プロジェクト: aragoubi/Nine
 internal void AddNewTextBox(Point position)
 {
     var textBoxWidth = 250;
     var textBoxHeight = 150;
     position.Offset(-textBoxWidth/2, -textBoxHeight/2);
     CurrentLayer.AddTextBox(position);
 }
コード例 #51
0
ファイル: OoXmlRenderer.cs プロジェクト: Chem4Word/Version3
        private void DrawShape(Wpg.WordprocessingGroup wordprocessingGroup1, Rect extents, A.ShapeTypeValues shape, string colour)
        {
            UInt32Value bondLineId   = UInt32Value.FromUInt32((uint)_ooxmlId++);
            string      bondLineName = "shape" + bondLineId;

            Int64Value width1  = OoXmlHelper.ScaleCmlToEmu(extents.Width);
            Int64Value height1 = OoXmlHelper.ScaleCmlToEmu(extents.Height);
            Int64Value top1    = OoXmlHelper.ScaleCmlToEmu(extents.Top);
            Int64Value left1   = OoXmlHelper.ScaleCmlToEmu(extents.Left);

            Point pp1 = new Point(left1, top1);
            Size  ss2 = new Size(width1, height1);

            pp1.Offset(OoXmlHelper.ScaleCmlToEmu(-_canvasExtents.Left), OoXmlHelper.ScaleCmlToEmu(-_canvasExtents.Top));
            Rect boundingBox = new Rect(pp1, ss2);

            Int64Value width  = (Int64Value)boundingBox.Width;
            Int64Value height = (Int64Value)boundingBox.Height;
            Int64Value top    = (Int64Value)boundingBox.Top;
            Int64Value left   = (Int64Value)boundingBox.Left;

            A.Extents        extents2        = null;
            A.PresetGeometry presetGeometry1 = null;
            extents2 = new A.Extents()
            {
                Cx = width, Cy = height
            };
            presetGeometry1 = new A.PresetGeometry()
            {
                Preset = shape
            };

            Wps.WordprocessingShape        wordprocessingShape1        = new Wps.WordprocessingShape();
            Wps.NonVisualDrawingProperties nonVisualDrawingProperties1 = new Wps.NonVisualDrawingProperties()
            {
                Id   = bondLineId,
                Name = bondLineName
            };

            Wps.NonVisualDrawingShapeProperties nonVisualDrawingShapeProperties1 = new Wps.NonVisualDrawingShapeProperties();
            Wps.ShapeProperties shapeProperties1 = new Wps.ShapeProperties();

            A.Transform2D transform2D1 = new A.Transform2D();
            A.Offset      offset2      = new A.Offset()
            {
                X = left, Y = top
            };

            transform2D1.Append(offset2);
            transform2D1.Append(extents2);

            A.AdjustValueList adjustValueList1 = new A.AdjustValueList();

            presetGeometry1.Append(adjustValueList1);
            A.SolidFill solidFill1 = new A.SolidFill();

            A.RgbColorModelHex rgbColorModelHex1 = new A.RgbColorModelHex()
            {
                Val = colour
            };
            A.Alpha alpha1 = new A.Alpha()
            {
                Val = new Int32Value()
                {
                    InnerText = "100%"
                }
            };
            solidFill1.Append(rgbColorModelHex1);

            shapeProperties1.Append(transform2D1);
            shapeProperties1.Append(presetGeometry1);
            shapeProperties1.Append(solidFill1);

            Wps.ShapeStyle  shapeStyle1    = new Wps.ShapeStyle();
            A.LineReference lineReference1 = new A.LineReference()
            {
                Index = (UInt32Value)0U
            };
            A.FillReference fillReference1 = new A.FillReference()
            {
                Index = (UInt32Value)0U
            };
            A.EffectReference effectReference1 = new A.EffectReference()
            {
                Index = (UInt32Value)0U
            };
            A.FontReference fontReference1 = new A.FontReference()
            {
                Index = A.FontCollectionIndexValues.Minor
            };

            shapeStyle1.Append(lineReference1);
            shapeStyle1.Append(fillReference1);
            shapeStyle1.Append(effectReference1);
            shapeStyle1.Append(fontReference1);
            Wps.TextBodyProperties textBodyProperties1 = new Wps.TextBodyProperties();

            wordprocessingShape1.Append(nonVisualDrawingProperties1);
            wordprocessingShape1.Append(nonVisualDrawingShapeProperties1);
            wordprocessingShape1.Append(shapeProperties1);
            wordprocessingShape1.Append(shapeStyle1);
            wordprocessingShape1.Append(textBodyProperties1);

            wordprocessingGroup1.Append(wordprocessingShape1);
        }
コード例 #52
0
        public void CreateCharacters(Atom atom, Options options)
        {
            string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()";
            //Debug.WriteLine("Atom: " + atom.Id + " is " + atom.ElementType);

            //Point atomCentre = new Point((double)atom.X2, (double)atom.Y2);
            string atomLabel = atom.Element.Symbol;
            Rect   labelBounds;

            //Debug Code
            //atomLabel = "H" + "abcdefHghijklmnopqrstuvwxyz" + "H";
            //atomLabel = "ABCHDEFGHIJKLMNOHPQRSHTUVWXYZ";
            //atomLabel = "-+H01234567890H+-";

            // Get Charge and Isotope valuesfor use later on
            int iCharge    = atom.FormalCharge ?? 0;
            int iAbsCharge = Math.Abs(iCharge);
            int isoValue   = atom.IsotopeNumber ?? 0;

            // Get Implicit Hydrogen Count for use later on
            int implicitHCount = atom.ImplicitHydrogenCount;

            Point cursorPosition        = atom.Position;
            Point chargeCursorPosition  = atom.Position;
            Point isotopeCursorPosition = atom.Position;

            double lastOffset = 0;

            //Debug.WriteLine("  X: " + atom.X2 + " Y: " + atom.Y2 + " Implicit H Count: " + implicitHCount);

            int ringCount = atom.Rings.Count();
            int bondCount = atom.Bonds.Count;

            //var bv = atom.BalancingVector;
            //_telemetry.Write(module, "Debugging", $"Atom {atomLabel} [{atom.Id}] at {atom.Position} BalancingVector {bv} [{CoordinateTool.BearingOfVector(bv)}°]");

            #region Decide if atom label is to be displayed

            bool showLabel = true;
            if (atomLabel == "C")
            {
                if (!options.ShowCarbons)
                {
                    if (ringCount > 0 || bondCount > 1)
                    {
                        showLabel = false;
                    }

                    if (bondCount == 2)
                    {
                        Point p1 = atom.Bonds[0].OtherAtom(atom).Position;
                        Point p2 = atom.Bonds[1].OtherAtom(atom).Position;

                        double angle1 = Vector.AngleBetween(-(atom.Position - p1), atom.Position - p2);

                        if (Math.Abs(angle1) < 8)
                        {
                            showLabel = true;
                        }
                    }

                    // Force on if atom has charge
                    if (iAbsCharge > 0)
                    {
                        showLabel = true;
                    }
                    // Force on if atom has isotope value
                    if (isoValue > 0)
                    {
                        showLabel = true;
                    }
                }
            }

            #endregion Decide if atom label is to be displayed

            if (showLabel)
            {
                #region Set Up Atom Colours

                string atomColour = "000000";
                if (options.ColouredAtoms)
                {
                    if ((atom.Element as Element).Colour != null)
                    {
                        atomColour = ((Element)atom.Element).Colour;
                        // Strip out # as OoXml does not use it
                        atomColour = atomColour.Replace("#", "");
                    }
                }

                #endregion Set Up Atom Colours

                #region Step 1 - Measure Bounding Box for all Characters of label

                double xMin = double.MaxValue;
                double yMin = double.MaxValue;
                double xMax = double.MinValue;
                double yMax = double.MinValue;

                Point thisCharacterPosition;
                for (int idx = 0; idx < atomLabel.Length; idx++)
                {
                    char         chr = atomLabel[idx];
                    TtfCharacter c   = m_TtfCharacterSet[chr];
                    if (c != null)
                    {
                        thisCharacterPosition = GetCharacterPosition(cursorPosition, c);

                        xMin = Math.Min(xMin, thisCharacterPosition.X);
                        yMin = Math.Min(yMin, thisCharacterPosition.Y);
                        xMax = Math.Max(xMax, thisCharacterPosition.X + OoXmlHelper.ScaleCsTtfToCml(c.Width));
                        yMax = Math.Max(yMax, thisCharacterPosition.Y + OoXmlHelper.ScaleCsTtfToCml(c.Height));

                        // Uncomment the following to disable offsetting for terminal atoms
                        //if (bonds.Count == 1)
                        //{
                        //    break;
                        //}

                        if (idx < atomLabel.Length - 1)
                        {
                            // Move to next Character position
                            cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(c.IncrementX), 0);
                        }
                    }
                }

                #endregion Step 1 - Measure Bounding Box for all Characters of label

                #region Step 2 - Reset Cursor such that the text is centered about the atom's co-ordinates

                double width  = xMax - xMin;
                double height = yMax - yMin;
                cursorPosition        = new Point(atom.Position.X - width / 2, atom.Position.Y + height / 2);
                chargeCursorPosition  = new Point(cursorPosition.X, cursorPosition.Y);
                isotopeCursorPosition = new Point(cursorPosition.X, cursorPosition.Y);
                labelBounds           = new Rect(cursorPosition, new Size(width, height));
                //_telemetry.Write(module, "Debugging", $"Atom {atomLabel} [{atom.Id}] Label Bounds {labelBounds}");

                #endregion Step 2 - Reset Cursor such that the text is centered about the atom's co-ordinates

                #region Step 3 - Place the characters

                foreach (char chr in atomLabel)
                {
                    TtfCharacter c = m_TtfCharacterSet[chr];
                    if (c != null)
                    {
                        thisCharacterPosition = GetCharacterPosition(cursorPosition, c);
                        AtomLabelCharacter alc = new AtomLabelCharacter(thisCharacterPosition, c, atomColour, chr, atom.Id);
                        m_AtomLabelCharacters.Add(alc);

                        // Move to next Character position
                        lastOffset = OoXmlHelper.ScaleCsTtfToCml(c.IncrementX);
                        cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(c.IncrementX), 0);
                        chargeCursorPosition = new Point(cursorPosition.X, cursorPosition.Y);
                    }
                }

                #endregion Step 3 - Place the characters

                #region Determine NESW

                double        baFromNorth = Vector.AngleBetween(BasicGeometry.ScreenNorth(), atom.BalancingVector);
                CompassPoints nesw        = CompassPoints.East;

                if (bondCount == 1)
                {
                    nesw = BasicGeometry.SnapTo2EW(baFromNorth);
                }
                else
                {
                    nesw = BasicGeometry.SnapTo4NESW(baFromNorth);
                }

                #endregion Determine NESW

                #region Step 4 - Add Implicit H if required

                if (options.ShowHydrogens && implicitHCount > 0)
                {
                    TtfCharacter hydrogenCharacter      = m_TtfCharacterSet['H'];
                    string       numbers                = "012345";
                    TtfCharacter implicitValueCharacter = m_TtfCharacterSet[numbers[implicitHCount]];

                    #region Add H

                    if (hydrogenCharacter != null)
                    {
                        switch (nesw)
                        {
                        case CompassPoints.North:
                            if (atom.Bonds.Count > 1)
                            {
                                cursorPosition.X = labelBounds.X + (labelBounds.Width / 2) - (OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Width) / 2);
                                cursorPosition.Y = cursorPosition.Y +
                                                   OoXmlHelper.ScaleCsTtfToCml(-hydrogenCharacter.Height) -
                                                   OoXmlHelper.CHARACTER_CLIPPING_MARGIN;
                                if (iCharge > 0)
                                {
                                    if (implicitHCount > 1)
                                    {
                                        cursorPosition.Offset(0, OoXmlHelper.ScaleCsTtfToCml(-implicitValueCharacter.Height * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR / 2) - OoXmlHelper.CHARACTER_CLIPPING_MARGIN);
                                    }
                                }
                            }
                            break;

                        case CompassPoints.East:
                            // Leave as is
                            break;

                        case CompassPoints.South:
                            if (atom.Bonds.Count > 1)
                            {
                                cursorPosition.X = labelBounds.X + (labelBounds.Width / 2) - (OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Width) / 2);
                                cursorPosition.Y = cursorPosition.Y +
                                                   OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Height) +
                                                   OoXmlHelper.CHARACTER_CLIPPING_MARGIN;
                            }
                            break;

                        case CompassPoints.West:
                            if (implicitHCount == 1)
                            {
                                cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(-(hydrogenCharacter.IncrementX * 2)), 0);
                            }
                            else
                            {
                                cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(-(hydrogenCharacter.IncrementX * 2.5)), 0);
                            }
                            break;
                        }

                        //_telemetry.Write(module, "Debugging", $"Adding H at {cursorPosition}");
                        thisCharacterPosition = GetCharacterPosition(cursorPosition, hydrogenCharacter);
                        AtomLabelCharacter alc = new AtomLabelCharacter(thisCharacterPosition, hydrogenCharacter, atomColour, 'H', atom.Id);
                        m_AtomLabelCharacters.Add(alc);

                        // Move to next Character position
                        cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.IncrementX), 0);

                        if (nesw == CompassPoints.East)
                        {
                            chargeCursorPosition = new Point(cursorPosition.X, cursorPosition.Y);
                        }
                        if (nesw == CompassPoints.West)
                        {
                            isotopeCursorPosition = new Point(thisCharacterPosition.X, isotopeCursorPosition.Y);
                        }
                    }

                    #endregion Add H

                    #region Add number

                    if (implicitHCount > 1)
                    {
                        if (implicitValueCharacter != null)
                        {
                            thisCharacterPosition = GetCharacterPosition(cursorPosition, implicitValueCharacter);

                            // Drop the subscript Character
                            thisCharacterPosition.Offset(0, OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Width * OoXmlHelper.SUBSCRIPT_DROP_FACTOR));

                            AtomLabelCharacter alc = new AtomLabelCharacter(thisCharacterPosition, implicitValueCharacter, atomColour, numbers[implicitHCount], atom.Id);
                            alc.IsSubScript = true;
                            m_AtomLabelCharacters.Add(alc);

                            // Move to next Character position
                            cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(implicitValueCharacter.IncrementX) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                        }
                    }

                    #endregion Add number
                }

                #endregion Step 4 - Add Implicit H if required

                #region Step 5 - Add Charge if required

                if (iCharge != 0)
                {
                    TtfCharacter hydrogenCharacter = m_TtfCharacterSet['H'];

                    char         sign = '.';
                    TtfCharacter chargeSignCharacter = null;
                    if (iCharge >= 1)
                    {
                        sign = '+';
                        chargeSignCharacter = m_TtfCharacterSet['+'];
                    }
                    else if (iCharge <= 1)
                    {
                        sign = '-';
                        chargeSignCharacter = m_TtfCharacterSet['-'];
                    }

                    if (iAbsCharge > 1)
                    {
                        string digits = iAbsCharge.ToString();
                        // Insert digits
                        foreach (char chr in digits)
                        {
                            TtfCharacter chargeValueCharacter = m_TtfCharacterSet[chr];
                            thisCharacterPosition = GetCharacterPosition(chargeCursorPosition, chargeValueCharacter);

                            // Raise the superscript Character
                            thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(chargeValueCharacter.Height * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR));

                            AtomLabelCharacter alcc = new AtomLabelCharacter(thisCharacterPosition, chargeValueCharacter, atomColour, chr, atom.Id);
                            alcc.IsSubScript = true;
                            m_AtomLabelCharacters.Add(alcc);

                            // Move to next Character position
                            chargeCursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(chargeValueCharacter.IncrementX) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                        }
                    }

                    // Insert sign at raised position
                    thisCharacterPosition = GetCharacterPosition(chargeCursorPosition, chargeSignCharacter);
                    thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Height * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR));
                    thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(chargeSignCharacter.Height / 2 * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR));

                    AtomLabelCharacter alcs = new AtomLabelCharacter(thisCharacterPosition, chargeSignCharacter, atomColour, sign, atom.Id);
                    alcs.IsSubScript = true;
                    m_AtomLabelCharacters.Add(alcs);
                }

                #endregion Step 5 - Add Charge if required

                #region Step 6 Add IsoTope Number if required

                if (isoValue > 0)
                {
                    string digits = isoValue.ToString();

                    xMin = double.MaxValue;
                    yMin = double.MaxValue;
                    xMax = double.MinValue;
                    yMax = double.MinValue;

                    Point isoOrigin = isotopeCursorPosition;

                    // Calculate width of digits
                    foreach (char chr in digits)
                    {
                        TtfCharacter c = m_TtfCharacterSet[chr];
                        thisCharacterPosition = GetCharacterPosition(isotopeCursorPosition, c);

                        // Raise the superscript Character
                        thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(c.Height * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR));

                        xMin = Math.Min(xMin, thisCharacterPosition.X);
                        yMin = Math.Min(yMin, thisCharacterPosition.Y);
                        xMax = Math.Max(xMax, thisCharacterPosition.X + OoXmlHelper.ScaleCsTtfToCml(c.Width));
                        yMax = Math.Max(yMax, thisCharacterPosition.Y + OoXmlHelper.ScaleCsTtfToCml(c.Height));

                        // Move to next Character position
                        isotopeCursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(c.IncrementX) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                    }

                    // Re-position Isotope Cursor
                    width = xMax - xMin;
                    isotopeCursorPosition = new Point(isoOrigin.X - width, isoOrigin.Y);

                    // Insert digits
                    foreach (char chr in digits)
                    {
                        TtfCharacter c = m_TtfCharacterSet[chr];
                        thisCharacterPosition = GetCharacterPosition(isotopeCursorPosition, c);

                        // Raise the superscript Character
                        thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(c.Height * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR));

                        AtomLabelCharacter alcc = new AtomLabelCharacter(thisCharacterPosition, c, atomColour, chr, atom.Id);
                        alcc.IsSubScript = true;
                        m_AtomLabelCharacters.Add(alcc);

                        // Move to next Character position
                        isotopeCursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(c.IncrementX) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                    }
                }

                #endregion Step 6 Add IsoTope Number if required
            }
        }
コード例 #53
0
ファイル: OoXmlRenderer.cs プロジェクト: Chem4Word/Version3
        private void DrawBox(Wpg.WordprocessingGroup wordprocessingGroup1, Rect extents, string colour, int thick)
        {
            UInt32Value bondLineId   = UInt32Value.FromUInt32((uint)_ooxmlId++);
            string      bondLineName = "diag-box-" + bondLineId;

            Int64Value width1  = OoXmlHelper.ScaleCmlToEmu(extents.Width);
            Int64Value height1 = OoXmlHelper.ScaleCmlToEmu(extents.Height);
            Int64Value top1    = OoXmlHelper.ScaleCmlToEmu(extents.Top);
            Int64Value left1   = OoXmlHelper.ScaleCmlToEmu(extents.Left);

            Point pp1 = new Point(left1, top1);
            Size  ss2 = new Size(width1, height1);

            pp1.Offset(OoXmlHelper.ScaleCmlToEmu(-_canvasExtents.Left), OoXmlHelper.ScaleCmlToEmu(-_canvasExtents.Top));
            Rect boundingBox = new Rect(pp1, ss2);

            Int64Value width  = (Int64Value)boundingBox.Width;
            Int64Value height = (Int64Value)boundingBox.Height;
            Int64Value top    = (Int64Value)boundingBox.Top;
            Int64Value left   = (Int64Value)boundingBox.Left;

            Wps.WordprocessingShape        wordprocessingShape1        = new Wps.WordprocessingShape();
            Wps.NonVisualDrawingProperties nonVisualDrawingProperties1 = new Wps.NonVisualDrawingProperties()
            {
                Id   = bondLineId,
                Name = bondLineName
            };
            Wps.NonVisualDrawingShapeProperties nonVisualDrawingShapeProperties1 = new Wps.NonVisualDrawingShapeProperties();

            Wps.ShapeProperties shapeProperties1 = new Wps.ShapeProperties();

            A.Transform2D transform2D1 = new A.Transform2D();
            A.Offset      offset2      = new A.Offset()
            {
                X = left, Y = top
            };
            A.Extents extents2 = new A.Extents()
            {
                Cx = width, Cy = height
            };

            transform2D1.Append(offset2);
            transform2D1.Append(extents2);

            A.CustomGeometry  customGeometry1  = new A.CustomGeometry();
            A.AdjustValueList adjustValueList1 = new A.AdjustValueList();
            A.Rectangle       rectangle1       = new A.Rectangle()
            {
                Left = "l", Top = "t", Right = "r", Bottom = "b"
            };

            A.PathList pathList1 = new A.PathList();

            A.Path path1 = new A.Path()
            {
                Width = width, Height = height
            };

            // Starting Point
            A.MoveTo moveTo1 = new A.MoveTo();
            A.Point  point1  = new A.Point()
            {
                X = "0", Y = "0"
            };
            moveTo1.Append(point1);

            // Mid Point
            A.LineTo lineTo1 = new A.LineTo();
            A.Point  point2  = new A.Point()
            {
                X = boundingBox.Width.ToString("0"), Y = "0"
            };
            lineTo1.Append(point2);

            // Mid Point
            A.LineTo lineTo2 = new A.LineTo();
            A.Point  point3  = new A.Point()
            {
                X = boundingBox.Width.ToString("0"), Y = boundingBox.Height.ToString("0")
            };
            lineTo2.Append(point3);

            // Last Point
            A.LineTo lineTo3 = new A.LineTo();
            A.Point  point4  = new A.Point()
            {
                X = "0", Y = boundingBox.Height.ToString("0")
            };
            lineTo3.Append(point4);

            // Back to Start Point
            A.LineTo lineTo4 = new A.LineTo();
            A.Point  point5  = new A.Point()
            {
                X = "0", Y = "0"
            };
            lineTo4.Append(point5);

            path1.Append(moveTo1);
            path1.Append(lineTo1);
            path1.Append(lineTo2);
            path1.Append(lineTo3);
            path1.Append(lineTo4);

            pathList1.Append(path1);

            customGeometry1.Append(adjustValueList1);
            customGeometry1.Append(rectangle1);
            customGeometry1.Append(pathList1);

            A.Outline outline1 = new A.Outline()
            {
                Width = thick, CapType = A.LineCapValues.Round
            };

            A.SolidFill solidFill1 = new A.SolidFill();

            A.RgbColorModelHex rgbColorModelHex1 = new A.RgbColorModelHex()
            {
                Val = colour
            };
            A.Alpha alpha1 = new A.Alpha()
            {
                Val = new Int32Value()
                {
                    InnerText = "100%"
                }
            };

            rgbColorModelHex1.Append(alpha1);

            solidFill1.Append(rgbColorModelHex1);

            outline1.Append(solidFill1);

            shapeProperties1.Append(transform2D1);
            shapeProperties1.Append(customGeometry1);
            shapeProperties1.Append(outline1);

            Wps.ShapeStyle  shapeStyle1    = new Wps.ShapeStyle();
            A.LineReference lineReference1 = new A.LineReference()
            {
                Index = (UInt32Value)0U
            };
            A.FillReference fillReference1 = new A.FillReference()
            {
                Index = (UInt32Value)0U
            };
            A.EffectReference effectReference1 = new A.EffectReference()
            {
                Index = (UInt32Value)0U
            };
            A.FontReference fontReference1 = new A.FontReference()
            {
                Index = A.FontCollectionIndexValues.Minor
            };

            shapeStyle1.Append(lineReference1);
            shapeStyle1.Append(fillReference1);
            shapeStyle1.Append(effectReference1);
            shapeStyle1.Append(fontReference1);
            Wps.TextBodyProperties textBodyProperties1 = new Wps.TextBodyProperties();

            wordprocessingShape1.Append(nonVisualDrawingProperties1);
            wordprocessingShape1.Append(nonVisualDrawingShapeProperties1);
            wordprocessingShape1.Append(shapeProperties1);
            wordprocessingShape1.Append(shapeStyle1);
            wordprocessingShape1.Append(textBodyProperties1);

            wordprocessingGroup1.Append(wordprocessingShape1);
        }