Ejemplo n.º 1
0
        /// <summary>
        /// Layouts text inside polygonal area.
        /// </summary>
        public bool LayoutInPolygon(Text text,
                                    PointF[] polygon, LayoutOptions options)
        {
            if (polygon == null)
            {
                return(false);
            }
            if (polygon.Length < 3)
            {
                return(false);
            }
            if (text == null || text.RawText.Length == 0)
            {
                return(true);
            }

            return(DoLayout(text, new Polygon(new PointList(polygon)), options));
        }
Ejemplo n.º 2
0
        private bool DoLayout(Text text, Polygon polygon, LayoutOptions options)
        {
            // Initialize internal variables
            _text    = text;
            _polygon = polygon;
            _options = options;
            _bounds  = _polygon.Bounds;

            _fits = false;

            // Build the h-lines according to the layout settings
            BuildLines();

            // Find out the starting line and the total number
            // of lines needed to layout the text.
            _totalLines = 1;
            _startLine  = FirstLine(_totalLines);
            if (GetHLines(_totalLines).Count == 0)
            {
                return(false);
            }

            do
            {
                // Check if the text fits within the h-lines
                // in the range [_startLine, _startLine + _totalLines)
                int       iword = 0;
                PointList hLine = null;

                for (int i = _startLine; i < _startLine + _totalLines; i++)
                {
                    hLine = GetHLines(_totalLines)[i] as PointList;
                    for (int j = 0; j < hLine.Count; j += 2)
                    {
                        PointF     pt1 = hLine[j];
                        PointF     pt2 = hLine[j + 1];
                        RectangleF rc  = new RectangleF(
                            pt1.X, pt1.Y, pt2.X - pt1.X, pt2.Y - pt1.Y);

                        bool newLine = false;
                        iword = FitTextInRect(iword, rc, ref newLine);

                        if (newLine)
                        {
                            break;
                        }
                        if (iword >= _text.Words.Count)
                        {
                            _fits = true;
                            return(true);
                        }
                    }
                }

                // If the text does not fit, increase the total
                // number of lines and recalculate the starting
                // line depending on v-alignment.
                _totalLines++;
                if (_totalLines > GetHLines(_totalLines).Count)
                {
                    _totalLines--;
                    return(false);
                }
                _startLine = FirstLine(_totalLines);

                ArrayList hLines = GetHLines(_totalLines);
                if (_startLine + _totalLines > hLines.Count)
                {
                    ArrayList hLines2 = GetHLines(_totalLines + 1);
                    if (_totalLines > hLines2.Count)
                    {
                        // The text would not fit in the
                        // polygon, so use all of the available
                        // space to layout as much text as possible
                        _totalLines = Math.Max(hLines.Count, hLines2.Count);
                        _startLine  = 0;
                        return(false);
                    }
                }
            }while ((_startLine = FirstLine(_totalLines)) != -1);

            return(false);
        }
Ejemplo n.º 3
0
 public bool LayoutInRectangle(Text text,
                               RectangleF rectangle, LayoutOptions options)
 {
     return(DoLayout(text, new Polygon(rectangle), options));
 }
Ejemplo n.º 4
0
 public bool LayoutInEllipse(Text text,
                             RectangleF bounds, LayoutOptions options)
 {
     return(DoLayout(text, new Polygon(bounds, 25), options));
 }
Ejemplo n.º 5
0
		/// <summary>
		/// Adds text to speciafied Flowchart.NET node
		/// </summary>
		/// <param name="ActiveNode">Node reference</param>
		/// <param name="Text2Render">String text to be added</param>
		/// <param name="Font2Render">Font to be used for text drawing</param>
		/// <param name="Rect2Render">Rectangle of the text area</param>
		/// <param name="Color2Render">Color for text rendering</param>
		/// <param name="TextFormat2Render">Text format for text renedering</param>
		/// <param name="IsStyled">If TRUE the text is styled</param>
		/// <returns>Returns recently added to SVG XML "text" node</returns>
		public XmlNode AddText( Node ActiveNode, string Text2Render, Font Font2Render, RectangleF Rect2Render, Color Color2Render, StringFormat  TextFormat2Render , bool IsStyled , float angle)
		{
		
		
			Layout tl = null;
			LayoutOptions lo;
			DrawTextHint dhint = null;
			StyledText stext = null;
			PlainText  text = null;
			System.Drawing.SolidBrush br = null;
			GraphicsPath path = null;
			PointF[] pF = null;
			string sPath = "";
			double OffsetY = 0;
			double OffsetX = 0;
			int tlen = 0;
			try
			{
			
				if (( Text2Render == null ) || ( Text2Render==""))
					return null;

				m_InnerNode = m_InnerRoot.InsertAfter(m_InnerDoc.CreateNode(XmlNodeType.Element,"text", sNsDefault), m_InnerRoot.LastChild);
				if ( m_InnerNode ==null )
					return m_InnerNode;
					
				if ( TextFormat2Render.Alignment == StringAlignment.Near )
					Rect2Render.Width+=15;
	
				path = new GraphicsPath(FillMode.Winding);
					
		
				IsTransparent = false;
				IsTable = false;
				if ( ActiveNode == null )
				{
					sPath = Rect2Path(Rect2Render, ref path);
				} 
				else if ( ActiveNode is Box )
				{
					IsTransparent = ((Box) ActiveNode).Transparent;
					if ( ((Box) ActiveNode).Shape == null )
					{
						sPath = Shape2Path((Box) ActiveNode, ref path , null);
					}
					else
						sPath = Complex2Path(Rect2Render, ( ((Box) ActiveNode).Shape.TextArea == null )? ((Box) ActiveNode).Shape.Outline : ((Box) ActiveNode).Shape.TextArea, ref path );
										
				} 
				else if ( ActiveNode is Table )
				{
					sPath = Rect2Path(Rect2Render, ref path);
					IsTable = true;
					OffsetX = -Rect2Render.Width/2;
				}
				else
				{
					return null;
				}
			
				
		
				m_InnerNode.Attributes.Append(m_InnerDoc.CreateAttribute("x"));
				m_InnerNode.Attributes["x"].Value = String.Format("{0}px",Unit2Pix(Rect2Render.X+Rect2Render.Width/2));

				m_InnerNode.Attributes.Append(m_InnerDoc.CreateAttribute("y"));
				m_InnerNode.Attributes["y"].Value = String.Format("{0}px",Unit2Pix(Rect2Render.Y + Rect2Render.Height/2));

				m_InnerNode.Attributes.Append(m_InnerDoc.CreateAttribute("dx"));
				m_InnerNode.Attributes["dx"].Value = String.Format("{0}px",Unit2Pix(OffsetX));

				m_InnerNode.Attributes.Append(m_InnerDoc.CreateAttribute("dy"));
				m_InnerNode.Attributes["dy"].Value = String.Format("{0}px",Unit2Pix(OffsetY));

				m_InnerNode.Attributes.Append(m_InnerDoc.CreateAttribute("font-family"));
				m_InnerNode.Attributes["font-family"].Value = Font2Render.FontFamily.Name.ToString();

				m_InnerNode.Attributes.Append(m_InnerDoc.CreateAttribute("font-size"));
				m_InnerNode.Attributes["font-size"].Value = Unit2Pix(Font2Render.Size, Font2Render.Unit).ToString();

				m_InnerNode.Attributes.Append(m_InnerDoc.CreateAttribute("fill"));
				m_InnerNode.Attributes["fill"].Value = SvgManager.Color2Str(Color2Render);

				m_InnerNode.Attributes.Append(m_InnerDoc.CreateAttribute("style"));
				m_InnerNode.Attributes["style"].Value = SvgManager.Align2Str(TextFormat2Render.Alignment);
				
			
			
				IntPtr hWnd = GetActiveWindow();

				if ( IsStyled )
				{
					stext = new StyledText();
					stext.Setup(Text2Render, System.Drawing.Graphics.FromHwnd(hWnd) ,Font2Render);
					tlen = stext.PlainText.Length;
				}
				else
				{
					text = new PlainText();
					text.Setup(Text2Render, System.Drawing.Graphics.FromHwnd(hWnd) ,Font2Render);
					tlen = text.PlainText.Length;
				}


			
			
				path.Flatten();
				pF = (PointF[])path.PathPoints.Clone();
				path.Dispose();
					

				tl = new Layout();
				br = new System.Drawing.SolidBrush(Color2Render);
				lo = new LayoutOptions();
				dhint = new DrawTextHint(System.Drawing.Graphics.FromHwnd(hWnd),
					Font2Render, br ,TextFormat2Render, false , m_InnerNode, Rect2Render );

				m_lastY = 0;
				m_lastX = 0;
				sTextLine = "";
				
				lo.Alignment = TextFormat2Render.Alignment;
				lo.LineAlignment = TextFormat2Render.LineAlignment;
				tl.LayoutInPolygon((IsStyled ? (Text) stext : (Text) text), docToLocal(pF, Rect2Render),lo);
				tl.Draw(0,0,new RenderTextCallback(___TextCallback),dhint);
				AddRotation(m_InnerNode, Rect2Render , angle );

			
			}
			catch (Exception ex)
			{

				Trace.WriteLine(String.Format("{0} error {1}\n","SvgManager.AddText)",ex.Message));
		
			}
			return m_InnerNode;
		}
Ejemplo n.º 6
0
		private bool DoLayout(Text text, Polygon polygon, LayoutOptions options)
		{
			// Initialize internal variables
			_text = text;
			_polygon = polygon;
			_options = options;
			_bounds = _polygon.Bounds;

			_fits = false;

			// Build the h-lines according to the layout settings
			BuildLines();

			// Find out the starting line and the total number
			// of lines needed to layout the text.
			_totalLines = 1;
			_startLine = FirstLine(_totalLines);
			if (GetHLines(_totalLines).Count == 0)
				return false;

			do
			{
				// Check if the text fits within the h-lines
				// in the range [_startLine, _startLine + _totalLines)
				int iword = 0;
				PointList hLine = null;

				for (int i = _startLine; i < _startLine + _totalLines; i++)
				{
					hLine = GetHLines(_totalLines)[i] as PointList;
					for (int j = 0; j < hLine.Count; j += 2)
					{
						PointF pt1 = hLine[j];
						PointF pt2 = hLine[j + 1];
						RectangleF rc = new RectangleF(
							pt1.X, pt1.Y, pt2.X - pt1.X, pt2.Y - pt1.Y);

						bool newLine = false;
						iword = FitTextInRect(iword, rc, ref newLine);

						if (newLine)
							break;
						if (iword >= _text.Words.Count)
						{
							_fits = true;
							return true;
						}
					}
				}

				// If the text does not fit, increase the total
				// number of lines and recalculate the starting
				// line depending on v-alignment.
				_totalLines++;
				if (_totalLines > GetHLines(_totalLines).Count)
				{
					_totalLines--;
					return false;
				}
				_startLine = FirstLine(_totalLines);

				ArrayList hLines = GetHLines(_totalLines);
				if (_startLine + _totalLines > hLines.Count)
				{
					ArrayList hLines2 = GetHLines(_totalLines + 1);
					if (_totalLines > hLines2.Count)
					{
						// The text would not fit in the
						// polygon, so use all of the available
						// space to layout as much text as possible
						_totalLines = Math.Max(hLines.Count, hLines2.Count);
						_startLine = 0;
						return false;
					}
				}
			}
			while ((_startLine = FirstLine(_totalLines)) != -1);

			return false;
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Layouts text inside polygonal area.
		/// </summary>
		public bool LayoutInPolygon(Text text,
			PointF[] polygon, LayoutOptions options)
		{
			if (polygon == null)
				return false;
			if (polygon.Length < 3)
				return false;
			if (text == null || text.RawText.Length == 0)
				return true;

			return DoLayout(text, new Polygon(new PointList(polygon)), options);
		}
Ejemplo n.º 8
0
		public bool LayoutInEllipse(Text text,
			RectangleF bounds, LayoutOptions options)
		{
			return DoLayout(text, new Polygon(bounds, 25), options);
		}
Ejemplo n.º 9
0
		public bool LayoutInRectangle(Text text,
			RectangleF rectangle, LayoutOptions options)
		{
			return DoLayout(text, new Polygon(rectangle), options);
		}