IntersectClip() public method

public IntersectClip ( Rectangle rect ) : void
rect Rectangle
return void
Esempio n. 1
0
        private void DrawVerticalComponent(int index, Graphics g, LiveSplitState state, float width, float height, Region clipRegion)
        {
            var component = VisibleComponents.ElementAt(index);
            var topPadding = Math.Min(GetPaddingAbove(index), component.PaddingTop) / 2f;
            var bottomPadding = Math.Min(GetPaddingBelow(index), component.PaddingBottom) / 2f;
            g.IntersectClip(new RectangleF(0, topPadding, width, component.VerticalHeight - topPadding - bottomPadding));

            var scale = g.Transform.Elements.First();
            var separatorOffset = component.VerticalHeight * scale < 3 ? 1 : 0;

            if (clipRegion.IsVisible(new RectangleF(
                g.Transform.OffsetX,
                -separatorOffset + g.Transform.OffsetY - topPadding * scale,
                width,
                separatorOffset * 2f + scale * (component.VerticalHeight + bottomPadding))))
                component.DrawVertical(g, state, width, clipRegion);
            g.TranslateTransform(0.0f, component.VerticalHeight - bottomPadding * 2f);
        }
Esempio n. 2
0
        private void DrawHorizontalComponent(int index, Graphics g, LiveSplitState state, float width, float height, Region clipRegion)
        {
            var component = VisibleComponents.ElementAt(index);
            var leftPadding = Math.Min(GetPaddingToLeft(index), component.PaddingLeft) / 2f;
            var rightPadding = Math.Min(GetPaddingToRight(index), component.PaddingRight) / 2f;
            g.IntersectClip(new RectangleF(leftPadding, 0, component.HorizontalWidth - leftPadding - rightPadding, height));

            var scale = g.Transform.Elements.First();
            var separatorOffset = component.VerticalHeight * scale < 3 ? 1 : 0;

            if (clipRegion.IsVisible(new RectangleF(
                -separatorOffset + g.Transform.OffsetX - leftPadding * scale,
                g.Transform.OffsetY,
                separatorOffset * 2f + scale * (component.HorizontalWidth + rightPadding),
                height)))
                component.DrawHorizontal(g, state, height, clipRegion);
            g.TranslateTransform(component.HorizontalWidth - rightPadding * 2f, 0.0f);
        }
Esempio n. 3
0
        private void PaintLink(Graphics g, Link link, SolidBrush foreBrush, SolidBrush linkBrush, bool optimizeBackgroundRendering, RectangleF finalrect) {
            
            // link = null means paint the whole text

            Debug.Assert(g != null, "Must pass valid graphics");
            Debug.Assert(foreBrush != null, "Must pass valid foreBrush");
            Debug.Assert(linkBrush != null, "Must pass valid linkBrush");

            Font font = Font;

            if (link != null) {
                if (link.VisualRegion != null) {
                    Color brushColor = Color.Empty;
                    LinkState linkState = link.State;

                    if ((linkState & LinkState.Hover) == LinkState.Hover) {
                        font = hoverLinkFont;
                    }
                    else {
                        font = linkFont;
                    }

                    if (link.Enabled) { // Not to be confused with Control.Enabled.
                        if ((linkState & LinkState.Active) == LinkState.Active) {
                            brushColor = ActiveLinkColor;
                        }
                        else if ((linkState & LinkState.Visited) == LinkState.Visited) {
                            brushColor = VisitedLinkColor;
                        }
                        // else use linkBrush
                    }
                    else {
                        brushColor = DisabledLinkColor;
                    }

                    if (IsOneLink()) {
                        g.Clip = new Region(finalrect);
                    }
                    else {
                        g.Clip = link.VisualRegion;
                    }
                    
                    if (optimizeBackgroundRendering) {
                        PaintLinkBackground(g);
                    }

                    if( UseCompatibleTextRendering ){
                        SolidBrush useBrush = brushColor == Color.Empty ? linkBrush : new SolidBrush( brushColor );
                        StringFormat stringFormat = CreateStringFormat();
                    
                        g.DrawString(Text, font, useBrush, ClientRectWithPadding, stringFormat);

                        if( useBrush != linkBrush ){
                            useBrush.Dispose();
                        }
                    }
                    else{
                        if(brushColor == Color.Empty ){
                            brushColor = linkBrush.Color;
                        }

                        IntPtr hdc = g.GetHdc();
                        try{
                            using( WindowsGraphics wg = WindowsGraphics.FromHdc( hdc ) ) {
                                brushColor = wg.GetNearestColor(brushColor);
                            }
                        }
                        finally{
                            g.ReleaseHdc();
                        }
                        Rectangle clientRectWithPadding = ClientRectWithPadding;
                        TextRenderer.DrawText(g, Text, font, clientRectWithPadding, brushColor, CreateTextFormatFlags(clientRectWithPadding.Size));
                    }

                    if (Focused && ShowFocusCues && FocusLink == link) {
                        // Get the rectangles making up the visual region, and draw
                        // each one.
                        RectangleF[] rects = link.VisualRegion.GetRegionScans(g.Transform);
                        if( rects != null && rects.Length > 0 ){
                            Rectangle focusRect;

                            if (IsOneLink()) {
                                //draw one merged focus rectangle
                                focusRect = Rectangle.Ceiling(finalrect);
                                Debug.Assert(finalrect != RectangleF.Empty, "finalrect should be initialized");

                                ControlPaint.DrawFocusRectangle(g, focusRect, ForeColor, BackColor);
                            }
                            else {
                                foreach (RectangleF rect in rects) {
                                    ControlPaint.DrawFocusRectangle(g, Rectangle.Ceiling(rect), ForeColor, BackColor);
                                }
                            }
                        }
                    }
                }

                // no else clause... we don't paint anything if we are given a link with no visual region.
                //
            }
            else { // Painting with no link.
                g.IntersectClip(this.textRegion);

                if (optimizeBackgroundRendering) {
                    PaintLinkBackground(g);
                }

                if( UseCompatibleTextRendering ){
                    StringFormat stringFormat = CreateStringFormat();
                    g.DrawString(Text, font, foreBrush, ClientRectWithPadding, stringFormat);
                }
                else{
                    Color color;

                    IntPtr hdc = g.GetHdc();
                    try{
                        using( WindowsGraphics wg = WindowsGraphics.FromHdc( hdc ) ) {
                            color = wg.GetNearestColor(foreBrush.Color);
                        }
                    }
                    finally{
                        g.ReleaseHdc();
                    }
                    Rectangle clientRectWithPadding = ClientRectWithPadding;
                    TextRenderer.DrawText(g, Text, font, clientRectWithPadding, color, CreateTextFormatFlags(clientRectWithPadding.Size));
                }
            }
        }
        private static void DrawInk(GraphicsPath p, InkPressureFeedbackMode m, Size s, Graphics g)
        {
            RectangleF PathBounds = p.GetBounds();  //get the bounds of the path and compute the square scale transform
            float ds = 0.8f * Math.Min(s.Width / PathBounds.Width, s.Height / PathBounds.Height);

            GraphicsState OriginalGraphicsState = g.Save();

            g.TranslateTransform(s.Width >> 1, s.Height >> 1);
            g.ScaleTransform(ds, -ds);

            switch (m)
            {
                case InkPressureFeedbackMode.Size:
                    g.FillEllipse(Brushes.Black, new Rectangle(-800, -800, 1600, 1600));
                    break;

                case InkPressureFeedbackMode.Width:
                    g.DrawLine(new Pen(Color.Black, 500f), new Point(-500, 0), new Point(500, 0));
                    break;

                case InkPressureFeedbackMode.None:
                case InkPressureFeedbackMode.Color:
                default:
                    GraphicsPath InkRegion = new GraphicsPath();    //upper-left triangular clip region to fake "ink"
                    InkRegion.AddPolygon(new Point[] { Point.Empty, new Point(s.Width, 0), new Point(0, s.Height) });
                    Matrix InverseTransform = g.Transform;
                    InverseTransform.Invert();
                    InkRegion.Transform(InverseTransform);

                    g.IntersectClip(new Region(InkRegion));
                    g.DrawPath(new Pen(Color.Blue, 4 / ds), p);
                    break;
            }

            g.Restore(OriginalGraphicsState);
        }
Esempio n. 5
0
 partial void IntersectClipImp(RectangleF r)
 {
     g.IntersectClip(r.ToSystemDrawingObject());
 }
 void RenderControls(Graphics g)
 {
     g.IntersectClip(GetDesignRect());
     g.Clear(this.BackColor);
     int x = _model.PageWidth;
     g.DrawLine(Pens.WhiteSmoke,PointToDesignScreen(new Point(x,0)),PointToDesignScreen(new Point(x,this.Height)));
     foreach (Band band in _model.Bands)
     {
         if (band.Row >= _top)
         {
             foreach (BaseWidget widget in band.Items)
             {
                 Point p = PointToDesignScreen(new Point(widget.Col,widget.Row));
                 Brush brush = new SolidBrush(Color.FromKnownColor(KnownColor.WindowText));
                 Font font;
                 FontStyle fontStyle = FontStyle.Regular;
                 //if (widget.IsSelected)
                 //{
                 //    font = _italicFont;
                 //}
                 //else
                 //{
                 //    font = _normalFont;
                 //}
                 if (widget.IsBold)
                     fontStyle |= FontStyle.Bold;
                 if (widget.IsUnderline)
                     fontStyle |= FontStyle.Underline;
                 if (widget.IsItalic)
                     fontStyle |= FontStyle.Italic;
                 font = new Font("Courier New",10, fontStyle);
                 if (widget.IsSelected)
                 {
                     g.FillRectangle(new SolidBrush(Color.FromKnownColor(KnownColor.Highlight)), RectToScreen(widget.GetRectangle()));
                     brush = new SolidBrush(Color.FromKnownColor(KnownColor.HighlightText));
                 }
                 else if (widget is ValueWidget)
                 {
                     g.FillRectangle(new SolidBrush(Color.FromKnownColor(KnownColor.Control)), RectToScreen(widget.GetRectangle()));
                     brush = new SolidBrush(Color.FromKnownColor(KnownColor.ControlText));
                 }
                 DrawString(g, font, brush, widget.ToString(), p.X, p.Y);
                 brush.Dispose();
                 font.Dispose();
             }
         }
     }
 }
Esempio n. 7
0
		/// <summary>
		/// Render this object to the specified <see cref="Graphics"/> device
		/// This method is normally only called by the Draw method
		/// of the parent <see cref="GraphObjList"/> collection object.
		/// </summary>
		/// <param name="g">
		/// A graphic device object to be drawn into.  This is normally e.Graphics from the
		/// PaintEventArgs argument to the Paint() method.
		/// </param>
		/// <param name="pane">
		/// A reference to the <see cref="PaneBase"/> object that is the parent or
		/// owner of this object.
		/// </param>
		/// <param name="scaleFactor">
		/// The scaling factor to be used for rendering objects.  This is calculated and
		/// passed down by the parent <see cref="GraphPane"/> object using the
		/// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
		/// font sizes, etc. according to the actual size of the graph.
		/// </param>
		override public void Draw( Graphics g, PaneBase pane, float scaleFactor )
		{
			if ( _image != null )
			{
				// Convert the rectangle coordinates from the user coordinate system
				// to the screen coordinate system
				RectangleF tmpRect = _location.TransformRect( pane );

				if ( _isScaled )
					g.DrawImage( _image, tmpRect );
				else
				{
					Region clip = g.Clip.Clone();
					g.IntersectClip( tmpRect );
					g.DrawImageUnscaled( _image, Rectangle.Round( tmpRect ) );
					g.Clip = clip;
					//g.DrawImageUnscaledAndClipped( image, Rectangle.Round( tmpRect ) );
				}
			}

		}
Esempio n. 8
0
		/// <summary>
		/// Draws string into specified rectangle using given ParagraphFormat.
		/// </summary>
		/// <param name="gr"></param>
		/// <param name="rect"></param>
		/// <param name="pf"></param>
		/// <remarks>
		/// This is the 'main' method of the class. This one is called by StringDrawUtils
		/// to draw formatted string.<br/>
		/// As this class (and consequently this method) isn't to be published, there are some limitations:<br/>
		/// Angle of InitialFormat (specified at construction) has to be zero.<br/>
		/// BackgroundBrush
		/// </remarks>
		public void DrawStringInRectangle(Graphics gr, RectangleF rect, ParagraphFormat pf)
		{
			Debug.Assert(InitialFormat.Angle==0);
			Debug.Assert(pf.BackgroundBrush==null);


			if(pf.VerticalAlignment!=ParagraphVerticalAlignment.Top)
			{
				int lines=Math.Min(GetMaxVisibleLineCount(gr, rect.Height, pf), 
					CountOf(Interval.Full(this), '\n')+1);
				float lineHeight=sdu.GetLineHeight(gr,InitialFormat.Font);
				float totalHeight=(lineHeight*lines)+
					sdu.GetMeasureStringVerticalGap(gr, InitialFormat.Font);

				switch(pf.VerticalAlignment)
				{
					case ParagraphVerticalAlignment.Bottom:
						rect.Offset(0, rect.Height-totalHeight);
						break;
					case ParagraphVerticalAlignment.Center:
						rect.Offset(0, (rect.Height-totalHeight)/2);
						break;
				}
			}

			
			Region oldClip=gr.Clip.Clone();

			gr.IntersectClip(rect);

			DrawStringLineByLine(gr, rect, pf);

			gr.Clip=oldClip;

		}
 private void PaintLink(Graphics g, Link link, SolidBrush foreBrush, SolidBrush linkBrush, bool optimizeBackgroundRendering, RectangleF finalrect)
 {
     Font hoverLinkFont = this.Font;
     if (link != null)
     {
         if (link.VisualRegion != null)
         {
             Color empty = Color.Empty;
             LinkState state = link.State;
             if ((state & LinkState.Hover) == LinkState.Hover)
             {
                 hoverLinkFont = this.hoverLinkFont;
             }
             else
             {
                 hoverLinkFont = this.linkFont;
             }
             if (link.Enabled)
             {
                 if ((state & LinkState.Active) == LinkState.Active)
                 {
                     empty = this.ActiveLinkColor;
                 }
                 else if ((state & LinkState.Visited) == LinkState.Visited)
                 {
                     empty = this.VisitedLinkColor;
                 }
             }
             else
             {
                 empty = this.DisabledLinkColor;
             }
             if (this.IsOneLink())
             {
                 g.Clip = new Region(finalrect);
             }
             else
             {
                 g.Clip = link.VisualRegion;
             }
             if (optimizeBackgroundRendering)
             {
                 this.PaintLinkBackground(g);
             }
             if (this.UseCompatibleTextRendering)
             {
                 SolidBrush brush = (empty == Color.Empty) ? linkBrush : new SolidBrush(empty);
                 StringFormat format = this.CreateStringFormat();
                 g.DrawString(this.Text, hoverLinkFont, brush, this.ClientRectWithPadding, format);
                 if (brush != linkBrush)
                 {
                     brush.Dispose();
                 }
             }
             else
             {
                 if (empty == Color.Empty)
                 {
                     empty = linkBrush.Color;
                 }
                 IntPtr hdc = g.GetHdc();
                 try
                 {
                     using (WindowsGraphics graphics = WindowsGraphics.FromHdc(hdc))
                     {
                         empty = graphics.GetNearestColor(empty);
                     }
                 }
                 finally
                 {
                     g.ReleaseHdc();
                 }
                 Rectangle clientRectWithPadding = this.ClientRectWithPadding;
                 TextRenderer.DrawText(g, this.Text, hoverLinkFont, clientRectWithPadding, empty, this.CreateTextFormatFlags(clientRectWithPadding.Size));
             }
             if ((this.Focused && this.ShowFocusCues) && (this.FocusLink == link))
             {
                 RectangleF[] regionScans = link.VisualRegion.GetRegionScans(g.Transform);
                 if ((regionScans != null) && (regionScans.Length > 0))
                 {
                     if (this.IsOneLink())
                     {
                         Rectangle rectangle = Rectangle.Ceiling(finalrect);
                         ControlPaint.DrawFocusRectangle(g, rectangle, this.ForeColor, this.BackColor);
                     }
                     else
                     {
                         foreach (RectangleF ef in regionScans)
                         {
                             ControlPaint.DrawFocusRectangle(g, Rectangle.Ceiling(ef), this.ForeColor, this.BackColor);
                         }
                     }
                 }
             }
         }
     }
     else
     {
         g.IntersectClip(this.textRegion);
         if (optimizeBackgroundRendering)
         {
             this.PaintLinkBackground(g);
         }
         if (this.UseCompatibleTextRendering)
         {
             StringFormat format2 = this.CreateStringFormat();
             g.DrawString(this.Text, hoverLinkFont, foreBrush, this.ClientRectWithPadding, format2);
         }
         else
         {
             Color nearestColor;
             IntPtr hDc = g.GetHdc();
             try
             {
                 using (WindowsGraphics graphics2 = WindowsGraphics.FromHdc(hDc))
                 {
                     nearestColor = graphics2.GetNearestColor(foreBrush.Color);
                 }
             }
             finally
             {
                 g.ReleaseHdc();
             }
             Rectangle bounds = this.ClientRectWithPadding;
             TextRenderer.DrawText(g, this.Text, hoverLinkFont, bounds, nearestColor, this.CreateTextFormatFlags(bounds.Size));
         }
     }
 }
Esempio n. 10
0
		/// <summary>
		/// Draw the this <see cref="CurveItem"/> to the specified <see cref="Graphics"/>
		/// device using the specified smoothing property (<see cref="ZedGraph.Line.SmoothTension"/>).
		/// The routine draws the line segments and the area fill (if any, see <see cref="FillType"/>;
		/// the symbols are drawn by the <see cref="Symbol.Draw"/> method.  This method
		/// is normally only called by the Draw method of the
		/// <see cref="CurveItem"/> object.  Note that the <see cref="StepType"/> property
		/// is ignored for smooth lines (e.g., when <see cref="ZedGraph.Line.IsSmooth"/> is true).
		/// </summary>
		/// <param name="g">
		/// A graphic device object to be drawn into.  This is normally e.Graphics from the
		/// PaintEventArgs argument to the Paint() method.
		/// </param>
		/// <param name="scaleFactor">
		/// The scaling factor to be used for rendering objects.  This is calculated and
		/// passed down by the parent <see cref="GraphPane"/> object using the
		/// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
		/// font sizes, etc. according to the actual size of the graph.
		/// </param>
		/// <param name="pane">
		/// A reference to the <see cref="GraphPane"/> object that is the parent or
		/// owner of this object.
		/// </param>
		/// <param name="curve">A <see cref="LineItem"/> representing this
		/// curve.</param>
		public void DrawSmoothFilledCurve( Graphics g, GraphPane pane,
                                CurveItem curve, float scaleFactor )
		{
			Line source = this;
			if ( curve.IsSelected )
				source = Selection.Line;

			PointF[] arrPoints;
			int count;
			IPointList points = curve.Points;

			if ( this.IsVisible && !this.Color.IsEmpty && points != null &&
				BuildPointsArray( pane, curve, out arrPoints, out count ) &&
				count > 2 )
			{
				float tension = _isSmooth ? _smoothTension : 0f;

				// Fill the curve if needed
				if ( this.Fill.IsVisible )
				{
					Axis yAxis = curve.GetYAxis( pane );

					using ( GraphicsPath path = new GraphicsPath( FillMode.Winding ) )
					{
						path.AddCurve( arrPoints, 0, count - 2, tension );

						double yMin = yAxis._scale._min < 0 ? 0.0 : yAxis._scale._min;
						CloseCurve( pane, curve, arrPoints, count, yMin, path );

						RectangleF rect = path.GetBounds();
						using ( Brush brush = source._fill.MakeBrush( rect ) )
						{
							if ( pane.LineType == LineType.Stack && yAxis.Scale._min < 0 &&
									this.IsFirstLine( pane, curve ) )
							{
								float zeroPix = yAxis.Scale.Transform( 0 );
								RectangleF tRect = pane.Chart._rect;
								tRect.Height = zeroPix - tRect.Top;
								if ( tRect.Height > 0 )
								{
									Region reg = g.Clip.Clone();
									g.IntersectClip( tRect );
									g.FillPath( brush, path );
									g.Clip = reg;
								}
							}
							else
								g.FillPath( brush, path );
							//brush.Dispose();
						}

						// restore the zero line if needed (since the fill tends to cover it up)
						yAxis.FixZeroLine( g, pane, scaleFactor, rect.Left, rect.Right );
					}
				}

				// If it's a smooth curve, go ahead and render the path.  Otherwise, use the
				// standard drawcurve method just in case there are missing values.
				if ( _isSmooth )
				{
					using ( Pen pen = GetPen( pane, scaleFactor ) )
					{
						// Stroke the curve
						g.DrawCurve( pen, arrPoints, 0, count - 2, tension );

						//pen.Dispose();
					}
				}
				else
					DrawCurve( g, pane, curve, scaleFactor );
			}
		}
Esempio n. 11
0
        public void IntersectClipRectangle(Graphics g)
        {
            Pen myPen = new Pen(Color.FromArgb(255, 0, 0x33, 0), (float)0.6);
            SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0x66, 0xEF, 0x7F));

            // Set clipping region.
            Rectangle clipRect = new Rectangle(0, 0, 200, 200);
            Region clipRegion = new Region(clipRect);
            g.SetClip(clipRegion, CombineMode.Replace);

            // Update clipping region to intersection of

            // existing region with specified rectangle.
            Rectangle intersectRect = new Rectangle(100, 100, 200, 200);
            Region intersectRegion = new Region(intersectRect);
            g.IntersectClip(intersectRegion);

            // Fill rectangle to demonstrate effective clipping region.
            g.FillRectangle(myBrush, 0, 0, 500, 500);

            // Reset clipping region to infinite.
            g.ResetClip();

            // Draw clipRect and intersectRect to screen.
            myPen.Color = Color.FromArgb(196, 0xC3, 0xC9, 0xCF);
            myBrush.Color = Color.FromArgb(127, 0xDD, 0xDD, 0xF0);
            g.DrawRectangle(myPen, clipRect);
            g.FillRectangle(myBrush, clipRect);

            myPen.Color = Color.FromArgb(196, 0xF9, 0xBE, 0xA6);
            myBrush.Color = Color.FromArgb(127, 0xFF, 0xE0, 0xE0);

            g.DrawRectangle(myPen, intersectRect);
            g.FillRectangle(myBrush, intersectRect);
        }
Esempio n. 12
0
		/// <summary>
		/// Draws full aligned string into given rectangle.
		/// </summary>
		/// <param name="gr"><see cref="Graphics"/> object to draw into.</param>
		/// <param name="str"><see cref="string"/> to be drawn.</param>
		/// <param name="rect"><see cref="Rectangle"/> that string is drawn into.</param>
		/// <param name="cf"><see cref="CharacterFormat"/> used to draw the <paramref name="str"/>. </param>
		/// <param name="pf"><see cref="ParagraphFormat"/> used to draw the <paramref name="str"/>. </param>
		/// <remarks>As this method isn't to be exposed as public, there are 
		/// several limitations:<br/>
		/// <see cref="Rectangle.Width"/> has to be non-zero.<br/>
		/// <see cref="CharacterFormat.Angle"/> has to be zero.<br/>
		/// <see cref="ParagraphFormat.MultiLine"/> has to be false.<br/>
		/// <see cref="ParagraphFormat.Alignment"/> has to be <see cref="ParagraphAlignment.Full"/>.<br/>
		/// <see cref="ParagraphFormat.BackgroundBrush"/> has to be null.<br/>
		/// If not satisfied, results might be not as expected.</remarks>
		private void DrawFullAlignedStringInRectangle(Graphics gr, string str, RectangleF rect,
		                                              CharacterFormat cf, ParagraphFormat pf)
		{
			Region oldClip = gr.Clip.Clone();
			gr.IntersectClip(rect);

			float yofs = rect.Y;

			StringFormat sfLeft; //StringFormat for drawing left-aligned lines
			{
				ParagraphFormat pf2 = pf.ShallowCopy();
				pf2.Alignment = ParagraphAlignment.Left;
				pf2.VerticalAlignment = ParagraphVerticalAlignment.Top;
				pf2.MultiLine = false;
				pf2.ShowIncompleteLines = true;
				sfLeft = GetStringFormat(cf, pf2);
			}


			//lineHeight & borders retrieving
			float lineHeight = GetLineHeight(gr, cf.Font);

			int lineCount;

			//lineCount retrieving
			{
				StringFormat sf = GetStringFormat(cf, pf);
				int charfit;
				gr.MeasureString(str, cf.Font, new SizeF(rect.Width, rect.Height), sf,
				                 out charfit, out lineCount);
			}


			//VerticalAlignment business
			switch (pf.VerticalAlignment)
			{
				case ParagraphVerticalAlignment.Bottom:
					yofs += rect.Height - lineHeight*lineCount;
					break;
				case ParagraphVerticalAlignment.Center:
					yofs += (rect.Height - lineHeight*lineCount)/2;
					break;
			}


			int flc = 0; //first line character
			int llc = flc; //last line character (actually the one after last)
			int lineIndex = 0;
			while (lineIndex < lineCount - 1 && flc < str.Length)
			{
				lineIndex++;

				llc = flc;

				//add spaces at the beginneing
				while (llc < str.Length && Char.IsWhiteSpace(str, llc))
					llc++;

				//add words until the line is full
				int pllc = llc; //potential last line character
				while (llc == pllc && llc < str.Length)
				{
					pllc++;
					while (pllc < str.Length && !Char.IsWhiteSpace(str, pllc))
						pllc++;
					if (gr.MeasureString(str.Substring(flc, pllc - flc), cf.Font).Width < rect.Width)
						llc = pllc;
				}

				//If nothing was added before, add single characters (rect.Width is too small)
				if (llc == flc)
					do
					{ //always at least one character per line
						llc++;
					} while (llc < str.Length && gr.MeasureString(str.Substring(flc, llc - flc + 1), cf.Font).Width < rect.Width);

				string line = str.Substring(flc, llc - flc);

				//Newline fotmatting
				int nlindex = line.IndexOf('\n');
				if (nlindex >= 0)
				{
					//Newline may be just "\n" or "\r\n"
					if (nlindex > 1 && line[nlindex - 1] == '\r')
						line = line.Substring(0, nlindex - 1);
					else
						line = line.Substring(0, nlindex);

					DrawString(gr, line, new PointF(rect.X, yofs), cf);

					flc += nlindex + 1;
				}
				else
				{
					DrawFullAlignedLine(gr, line, new PointF(rect.X, yofs), rect.Width, cf);

					flc = llc;
					//skip spaces at the end of line (just like Graphics.DrawString does)
					while (flc < str.Length && Char.IsWhiteSpace(str, flc))
						flc++;
				}

				yofs += lineHeight;

			}

			//And here comes the last line - it's always drawn left-aligned
			//(also, we have to get rid of newlines or they will sometimes show
			//in the bottom)

			gr.DrawString(str.Substring(flc), cf.Font, cf.Brush,
			              new RectangleF(rect.X, yofs, rect.Width, lineHeight), sfLeft);

			//Set back the original clipping region
			gr.Clip = oldClip;

		}
Esempio n. 13
0
	    protected Region PushClip(Graphics g, RectangleF clip)
	    {
	        var previousClip = g.Clip.Clone();
            g.IntersectClip(clip);
	        return previousClip;
	    }
Esempio n. 14
0
 partial void IntersectClipImp(RectangleF r)
 {
     g.IntersectClip(r);
 }