Esempio n. 1
0
		/// <summary>
		/// Measures the given text and returns its size.
		/// </summary>
		/// <param name="graphics">Graphics context used for the measuring</param>
		/// <param name="text">The text to measure</param>
		/// <param name="characterStyle">The text's character style</param>
		/// <param name="proposedSize">The layout area of the text. Size.Empty means no fitting in area.</param>
		/// <param name="paragraphStyle">The paragraph layout of the text</param>
		/// <returns></returns>
		public static Size MeasureText(Graphics graphics, string text, ICharacterStyle characterStyle, Size proposedSize,
		                               IParagraphStyle paragraphStyle)
		{
			if (paragraphStyle == null) throw new ArgumentNullException("paragraphStyle");
			return MeasureText(graphics, text, ToolCache.GetFont(characterStyle), proposedSize,
			                   ToolCache.GetStringFormat(paragraphStyle));
		}
Esempio n. 2
0
		/// <summary>
		/// Calculates the current text's area within the given caption bounds.
		/// </summary>
		public Rectangle CalculateTextBounds(Rectangle captionBounds, ICharacterStyle characterStyle, 
			IParagraphStyle paragraphStyle, IDisplayService displayService) {
			Rectangle textBounds = Rectangle.Empty;
			Debug.Assert(characterStyle != null);
			Debug.Assert(paragraphStyle != null);

			// measure the text size
			//if (float.IsNaN(dpiY)) dpiY = gfx.DpiY;
			if (displayService != null) {
				textBounds.Size = TextMeasurer.MeasureText(displayService.InfoGraphics, string.IsNullOrEmpty(captionText)
						? "Ig" : captionText, ToolCache.GetFont(characterStyle), captionBounds.Size, paragraphStyle);
			} else textBounds.Size = TextMeasurer.MeasureText(string.IsNullOrEmpty(captionText)
				? "Ig" : captionText, ToolCache.GetFont(characterStyle), captionBounds.Size, paragraphStyle);

			// clip text bounds if too large
			if (textBounds.Width > captionBounds.Width)
				textBounds.Width = captionBounds.Width;
			if (textBounds.Height > captionBounds.Height)
				textBounds.Height = captionBounds.Height;

			// set horizontal alignment
			switch (paragraphStyle.Alignment) {
				case ContentAlignment.BottomLeft:
				case ContentAlignment.MiddleLeft:
				case ContentAlignment.TopLeft:
					textBounds.X = captionBounds.X;
					break;
				case ContentAlignment.BottomCenter:
				case ContentAlignment.MiddleCenter:
				case ContentAlignment.TopCenter:
					textBounds.X = captionBounds.X + (int)Math.Round((captionBounds.Width - textBounds.Width) / 2f);
					break;
				case ContentAlignment.BottomRight:
				case ContentAlignment.MiddleRight:
				case ContentAlignment.TopRight:
					textBounds.X = captionBounds.Right - textBounds.Width;
					break;
				default: Debug.Assert(false, "Unhandled switch case"); break;
			}
			// set vertical alignment
			switch (paragraphStyle.Alignment) {
				case ContentAlignment.BottomCenter:
				case ContentAlignment.BottomLeft:
				case ContentAlignment.BottomRight:
					textBounds.Y = captionBounds.Bottom - textBounds.Height;
					break;
				case ContentAlignment.MiddleCenter:
				case ContentAlignment.MiddleLeft:
				case ContentAlignment.MiddleRight:
					textBounds.Y = captionBounds.Top + (int)Math.Round((captionBounds.Height - textBounds.Height) / 2f);
					break;
				case ContentAlignment.TopCenter:
				case ContentAlignment.TopLeft:
				case ContentAlignment.TopRight:
					textBounds.Y = captionBounds.Top;
					break;
				default: Debug.Assert(false, "Unhandled switch case"); break;
			}
			return textBounds;
		}
Esempio n. 3
0
		/// <summary>
		/// Measures the given text and returns its size.
		/// </summary>
		/// <param name="text">The text to measure</param>
		/// <param name="characterStyle">The text's character style.</param>
		/// <param name="proposedSize">The layout area of the text. Size.Empty means no fitting in area.</param>
		/// <param name="paragraphStyle">The paragraph layout of the text</param>
		/// <returns></returns>
		public static Size MeasureText(string text, ICharacterStyle characterStyle, Size proposedSize,
		                               IParagraphStyle paragraphStyle)
		{
			using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
				return MeasureText(graphics, text, ToolCache.GetFont(characterStyle), proposedSize,
				                   ToolCache.GetStringFormat(paragraphStyle));
		}
Esempio n. 4
0
 public static void Compare(IStyleSet designA, IStyleSet designB, int version)
 {
     foreach (ICapStyle styleA in designA.CapStyles)
     {
         ICapStyle styleB = designB.CapStyles[styleA.Name];
         Compare(styleA, styleB, version);
     }
     foreach (ICharacterStyle styleA in designA.CharacterStyles)
     {
         ICharacterStyle styleB = designB.CharacterStyles[styleA.Name];
         Compare(styleA, styleB, version);
     }
     foreach (IColorStyle styleA in designA.ColorStyles)
     {
         IColorStyle styleB = designB.ColorStyles[styleA.Name];
         Compare(styleA, styleB, version);
     }
     foreach (IFillStyle styleA in designA.FillStyles)
     {
         IFillStyle styleB = designB.FillStyles[styleA.Name];
         Compare(styleA, styleB, version);
     }
     foreach (ILineStyle styleA in designA.LineStyles)
     {
         ILineStyle styleB = designB.LineStyles[styleA.Name];
         Compare(styleA, styleB, version);
     }
     foreach (IParagraphStyle styleA in designA.ParagraphStyles)
     {
         IParagraphStyle styleB = designB.ParagraphStyles[styleA.Name];
         Compare(styleA, styleB, version);
     }
 }
Esempio n. 5
0
 public static void Compare(IStyleSet savedDesign, IStyleSet loadedDesign, int version)
 {
     foreach (ICapStyle savedStyle in savedDesign.CapStyles)
     {
         ICapStyle loadedStyle = loadedDesign.CapStyles[savedStyle.Name];
         Compare(savedStyle, loadedStyle, version);
     }
     foreach (ICharacterStyle savedStyle in savedDesign.CharacterStyles)
     {
         ICharacterStyle loadedStyle = loadedDesign.CharacterStyles[savedStyle.Name];
         Compare(savedStyle, loadedStyle, version);
     }
     foreach (IColorStyle savedStyle in savedDesign.ColorStyles)
     {
         IColorStyle loadedStyle = loadedDesign.ColorStyles[savedStyle.Name];
         Compare(savedStyle, loadedStyle, version);
     }
     foreach (IFillStyle savedStyle in savedDesign.FillStyles)
     {
         IFillStyle loadedStyle = loadedDesign.FillStyles[savedStyle.Name];
         Compare(savedStyle, loadedStyle, version);
     }
     foreach (ILineStyle savedStyle in savedDesign.LineStyles)
     {
         ILineStyle loadedStyle = loadedDesign.LineStyles[savedStyle.Name];
         Compare(savedStyle, loadedStyle, version);
     }
     foreach (IParagraphStyle savedStyle in savedDesign.ParagraphStyles)
     {
         IParagraphStyle loadedStyle = loadedDesign.ParagraphStyles[savedStyle.Name];
         Compare(savedStyle, loadedStyle, version);
     }
 }
Esempio n. 6
0
		/// <summary>
		/// Initializes a new instance of <see cref="T:Dataweb.NShape.WinFormsUI.TextUITypeEditorDialog" />.
		/// </summary>
		public TextEditorDialog(string text, ICharacterStyle characterStyle)
			: this(text) {
			if (characterStyle == null) throw new ArgumentNullException("characterStyle");
			Font font = ToolCache.GetFont(characterStyle);
			textBox.Font = (Font)font.Clone();
			font = null;
		}
Esempio n. 7
0
 /// <summary>
 /// Measures the given text and returns its size.
 /// </summary>
 /// <param name="text">The text to measure</param>
 /// <param name="characterStyle">The text's character style.</param>
 /// <param name="proposedSize">The layout area of the text. Size.Empty means no fitting in area.</param>
 /// <param name="paragraphStyle">The paragraph layout of the text</param>
 /// <returns></returns>
 public static Size MeasureText(string text, ICharacterStyle characterStyle, Size proposedSize,
                                IParagraphStyle paragraphStyle)
 {
     using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
         return(MeasureText(graphics, text, ToolCache.GetFont(characterStyle), proposedSize,
                            ToolCache.GetStringFormat(paragraphStyle)));
 }
Esempio n. 8
0
		/// <summary>
		/// Calculates the caption path in the untransformed state.
		/// </summary>
		/// <param name="layoutX">X coordinate of the layout rectangle</param>
		/// <param name="layoutY">Y coordinate of the layout rectangle</param>
		/// <param name="layoutW">Width of the layout rectangle</param>
		/// <param name="layoutH">Height of the layout rectangle</param>
		/// <param name="characterStyle">Character style of the caption</param>
		/// <param name="paragraphStyle">Paragraph style of the caption</param>
		/// <returns></returns>
		public bool CalculatePath(int layoutX, int layoutY, int layoutW, int layoutH, ICharacterStyle characterStyle, IParagraphStyle paragraphStyle) {
			if (characterStyle == null) throw new ArgumentNullException("charStyle");
			if (paragraphStyle == null) throw new ArgumentNullException("paragraphStyle");
			if (string.IsNullOrEmpty(captionText))
				return true;
			else if (textPath != null /*&& layoutW > 0 && layoutH > 0*/) {
				// Collect objects for calculating text layout
				Font font = ToolCache.GetFont(characterStyle);
				StringFormat formatter = ToolCache.GetStringFormat(paragraphStyle);
				Rectangle textBounds = Rectangle.Empty;
				textBounds.X = layoutX + paragraphStyle.Padding.Left;
				textBounds.Y = layoutY + paragraphStyle.Padding.Top;
				textBounds.Width = Math.Max(1, layoutW - paragraphStyle.Padding.Horizontal);
				textBounds.Height = Math.Max(1, layoutH - paragraphStyle.Padding.Vertical);
				// Create text path
				textPath.Reset();
				textPath.StartFigure();
				textPath.AddString(PathText, font.FontFamily, (int)font.Style, characterStyle.Size, textBounds, formatter);
				textPath.CloseFigure();
#if DEBUG_DIAGNOSTICS
				if (textPath.PointCount == 0 && PathText.Trim() != string.Empty) {
					Size textSize = TextMeasurer.MeasureText(PathText, font, textBounds.Size, paragraphStyle);
					Debug.Print("Failed to create TextPath - please check if the caption bounds are too small for the text.");
				}
#endif
				return true;
			}
			return false;
		}
Esempio n. 9
0
		/// <summary>
		/// Calculates the current text's area within the given caption bounds.
		/// </summary>
		public Rectangle CalculateTextBounds(Rectangle captionBounds, ICharacterStyle characterStyle, 
			IParagraphStyle paragraphStyle, IDisplayService displayService) {
			Rectangle textBounds = Rectangle.Empty;
			Debug.Assert(characterStyle != null);
			Debug.Assert(paragraphStyle != null);

			// measure the text size
			//if (float.IsNaN(dpiY)) dpiY = gfx.DpiY;
			if (displayService != null) {
				textBounds.Size = TextMeasurer.MeasureText(displayService.InfoGraphics, string.IsNullOrEmpty(captionText)
						? "Ig" : captionText, ToolCache.GetFont(characterStyle), captionBounds.Size, paragraphStyle);
			} else textBounds.Size = TextMeasurer.MeasureText(string.IsNullOrEmpty(captionText)
				? "Ig" : captionText, ToolCache.GetFont(characterStyle), captionBounds.Size, paragraphStyle);

			// clip text bounds if too large
			if (textBounds.Width > captionBounds.Width)
				textBounds.Width = captionBounds.Width;
			if (textBounds.Height > captionBounds.Height)
				textBounds.Height = captionBounds.Height;

			// set horizontal alignment
			switch (paragraphStyle.Alignment) {
				case ContentAlignment.BottomLeft:
				case ContentAlignment.MiddleLeft:
				case ContentAlignment.TopLeft:
					textBounds.X = captionBounds.X;
					break;
				case ContentAlignment.BottomCenter:
				case ContentAlignment.MiddleCenter:
				case ContentAlignment.TopCenter:
					textBounds.X = captionBounds.X + (int)Math.Round((captionBounds.Width - textBounds.Width) / 2f);
					break;
				case ContentAlignment.BottomRight:
				case ContentAlignment.MiddleRight:
				case ContentAlignment.TopRight:
					textBounds.X = captionBounds.Right - textBounds.Width;
					break;
				default: Debug.Assert(false, "Unhandled switch case"); break;
			}
			// set vertical alignment
			switch (paragraphStyle.Alignment) {
				case ContentAlignment.BottomCenter:
				case ContentAlignment.BottomLeft:
				case ContentAlignment.BottomRight:
					textBounds.Y = captionBounds.Bottom - textBounds.Height;
					break;
				case ContentAlignment.MiddleCenter:
				case ContentAlignment.MiddleLeft:
				case ContentAlignment.MiddleRight:
					textBounds.Y = captionBounds.Top + (int)Math.Round((captionBounds.Height - textBounds.Height) / 2f);
					break;
				case ContentAlignment.TopCenter:
				case ContentAlignment.TopLeft:
				case ContentAlignment.TopRight:
					textBounds.Y = captionBounds.Top;
					break;
				default: Debug.Assert(false, "Unhandled switch case"); break;
			}
			return textBounds;
		}
Esempio n. 10
0
 /// <override></override>
 public override void SetCaptionCharacterStyle(int index, ICharacterStyle characterStyle)
 {
     base.SetCaptionCharacterStyle(index, characterStyle);
     if (autoSize)
     {
         FitShapeToText();
     }
 }
Esempio n. 11
0
 /// <ToBeCompleted></ToBeCompleted>
 public virtual void SetCaptionCharacterStyle(int index, ICharacterStyle characterStyle)
 {
     if (index != 0)
     {
         throw new NShapeException(string.Format("Invalid label index: {0}.", index));
     }
     CharacterStyle = characterStyle;
 }
Esempio n. 12
0
 /// <summary>
 /// Measures the given text and returns its size.
 /// </summary>
 /// <param name="graphics">Graphics context used for the measuring</param>
 /// <param name="text">The text to measure</param>
 /// <param name="characterStyle">The text's character style</param>
 /// <param name="proposedSize">The layout area of the text. Size.Empty means no fitting in area.</param>
 /// <param name="paragraphStyle">The paragraph layout of the text</param>
 /// <returns></returns>
 public static Size MeasureText(Graphics graphics, string text, ICharacterStyle characterStyle, Size proposedSize, IParagraphStyle paragraphStyle)
 {
     if (paragraphStyle == null)
     {
         throw new ArgumentNullException("paragraphStyle");
     }
     return(MeasureText(graphics, text, ToolCache.GetFont(characterStyle), proposedSize, ToolCache.GetStringFormat(paragraphStyle)));
 }
Esempio n. 13
0
		/// <summary>
		/// Draws the caption.
		/// </summary>
		public void Draw(Graphics graphics, ICharacterStyle characterStyle, IParagraphStyle paragraphStyle) {
			if (graphics == null) throw new ArgumentNullException("graphics");
			if (characterStyle == null) throw new ArgumentNullException("charStyle");
			if (paragraphStyle == null) throw new ArgumentNullException("paragraphStyle");
			if (textPath != null && textPath.PointCount > 0) {
				Brush brush = ToolCache.GetBrush(characterStyle.ColorStyle);
				graphics.FillPath(brush, textPath);
			}
		}
Esempio n. 14
0
 public static void Compare(ICharacterStyle savedStyle, ICharacterStyle loadedStyle, int version)
 {
     CompareBaseStyle(savedStyle, loadedStyle, version);
     Compare(savedStyle.ColorStyle, loadedStyle.ColorStyle, version);
     Assert.AreEqual <FontFamily>(savedStyle.FontFamily, loadedStyle.FontFamily);
     Assert.AreEqual <string>(savedStyle.FontName, loadedStyle.FontName);
     Assert.AreEqual <int>(savedStyle.Size, loadedStyle.Size);
     Assert.AreEqual <float>(savedStyle.SizeInPoints, loadedStyle.SizeInPoints);
     Assert.AreEqual <FontStyle>(savedStyle.Style, loadedStyle.Style);
 }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of <see cref="T:Dataweb.NShape.WinFormsUI.TextUITypeEditorDialog" />.
 /// </summary>
 public TextEditorDialog(string text, ICharacterStyle characterStyle)
     : this(text) {
     if (characterStyle == null)
     {
         throw new ArgumentNullException("characterStyle");
     }
     Font font = ToolCache.GetFont(characterStyle);
     textBox.Font = (Font)font.Clone();
     font         = null;
 }
Esempio n. 16
0
 public static void Compare(ICharacterStyle styleA, ICharacterStyle styleB, int version)
 {
     CompareBaseStyle(styleA, styleB, version);
     Compare(styleA.ColorStyle, styleB.ColorStyle, version);
     Assert.AreEqual <FontFamily>(styleA.FontFamily, styleB.FontFamily);
     Assert.AreEqual <string>(styleA.FontName, styleB.FontName);
     Assert.AreEqual <int>(styleA.Size, styleB.Size);
     Assert.AreEqual <float>(styleA.SizeInPoints, styleB.SizeInPoints);
     Assert.AreEqual <FontStyle>(styleA.Style, styleB.Style);
 }
Esempio n. 17
0
 /// <summary>
 /// Deletes all tools based on the given CharacterStyle.
 /// </summary>
 private static void NotifyCharacterStyleChanged(ICharacterStyle characterStyle)
 {
     Debug.Assert(characterStyle != null);
     // Delete affected fonts
     while (_fontCache.ContainsKey(characterStyle))
     {
         Font font = _fontCache[characterStyle];
         _fontCache.Remove(characterStyle);
         font.Dispose();
         font = null;
     }
 }
Esempio n. 18
0
        /// <override></override>
        protected override void OnMeasureItem(MeasureItemEventArgs e)
        {
            if (Items.Count > 0)
            {
                UpdateMaxItemWidth(e.Graphics, e.Index);

                e.ItemWidth = Width;
                if (Items[e.Index] is IStyle)
                {
                    switch (styleCategory)
                    {
                    case StyleCategory.CapStyle:
                        e.ItemHeight = ((ICapStyle)Items[e.Index]).CapSize;
                        break;

                    case StyleCategory.ColorStyle:
                    case StyleCategory.FillStyle:
                        e.ItemHeight = stdItemHeight;
                        break;

                    case StyleCategory.CharacterStyle:
                        ICharacterStyle characterStyle = (ICharacterStyle)Items[e.Index];
                        Font            font           = ToolCache.GetFont(characterStyle);
                        e.ItemHeight = (int)Math.Ceiling(font.GetHeight(e.Graphics));
                        break;

                    case StyleCategory.LineStyle:
                        e.ItemHeight = ((ILineStyle)Items[e.Index]).LineWidth + 4;
                        break;

                    case StyleCategory.ParagraphStyle:
                        e.ItemHeight = dblItemHeight + dblItemHeight;
                        break;

                    default:
                        throw new NShapeException(string.Format("Unexpected enum value '{0}'.", styleCategory));
                    }
                }
                // correct calculated Height by the Height of the label's font
                float fontSizeInPixels = Font.GetHeight(e.Graphics);
                if (fontSizeInPixels > e.ItemHeight)
                {
                    e.ItemHeight = (int)Math.Round(fontSizeInPixels);
                }
                e.ItemHeight += 4;
                if (e.ItemHeight < stdItemHeight)
                {
                    e.ItemHeight = 20;
                }
            }
        }
Esempio n. 19
0
		private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, ICharacterStyle charStyle) {
			Brush fontBrush = ToolCache.GetBrush(charStyle.ColorStyle);
			Font font = ToolCache.GetFont(charStyle);
			int height = Geometry.PointToPixel(charStyle.SizeInPoints, gfx.DpiY);
			float scale = Geometry.CalcScaleFactor(height, height, previewBounds.Width, previewBounds.Height);
			gfx.ScaleTransform(scale, scale);
			RectangleF layoutRect = RectangleF.Empty;
			layoutRect.X = 0;
			layoutRect.Y = 0;
			layoutRect.Width = (float)previewBounds.Width / scale;
			layoutRect.Height = (float)previewBounds.Height / scale;
			gfx.DrawString(string.Format("{0} {1} pt", charStyle.FontName, charStyle.SizeInPoints), 
				font, fontBrush, layoutRect, formatter);
		}
Esempio n. 20
0
        /// <override></override>
        public override void CopyFrom(Shape source)
        {
            base.CopyFrom(source);
            if (source is ICaptionedShape)
            {
                ICaptionedShape src = (ICaptionedShape)source;
                // Copy first caption
                ICharacterStyle charStyle = src.GetCaptionCharacterStyle(0);
                privateCharacterStyle = (Template != null &&
                                         charStyle == ((ICaptionedShape)Template.Shape).GetCaptionCharacterStyle(0))
                                                                ? null
                                                                : charStyle;
                IParagraphStyle paragraphStyle = src.GetCaptionParagraphStyle(0);
                privateParagraphStyle = (Template != null &&
                                         paragraphStyle == ((ICaptionedShape)Template.Shape).GetCaptionParagraphStyle(0))
                                                                ? null
                                                                : paragraphStyle;
                string txt = src.GetCaptionText(0);
                if (!string.IsNullOrEmpty(txt))
                {
                    if (caption == null)
                    {
                        caption = new Caption(txt);
                    }
                    else
                    {
                        caption.Text = txt;
                    }
                }
                else
                {
                    caption = null;
                }

                // Copy remaining captions
                int cnt = Math.Min(CaptionCount, src.CaptionCount);
                for (int i = 1; i < cnt; ++i)
                {
                    SetCaptionCharacterStyle(i, src.GetCaptionCharacterStyle(i));
                    SetCaptionParagraphStyle(i, GetCaptionParagraphStyle(i));
                    SetCaptionText(i, GetCaptionText(i));
                }
            }
        }
Esempio n. 21
0
        /// <override></override>
        protected override void LoadFieldsCore(IRepositoryReader reader, int version)
        {
            base.LoadFieldsCore(reader, 1);

            // ILabel members
            this.privateCharacterStyle = reader.ReadCharacterStyle();
            this.privateParagraphStyle = reader.ReadParagraphStyle();

            string txt = reader.ReadString();
            if (caption == null) caption = new Caption(txt);
            else caption.Text = txt;
        }
Esempio n. 22
0
		/// <ToBeCompleted></ToBeCompleted>
		public static Font GetFont(ICharacterStyle characterStyle) {
			if (characterStyle == null) throw new ArgumentNullException("characterStyle");

			Font font = null;
			fontCache.TryGetValue(characterStyle, out font);
			if (font == null) {
				FontFamily fontFamily = characterStyle.FontFamily;
				FontStyle style = characterStyle.Style;
				// check if the desired FontStyle is available for this particular FontFamily
				// Set an available FontStyle if not.
				if (fontFamily != null && !fontFamily.IsStyleAvailable(style)) {
					if (fontFamily.IsStyleAvailable(FontStyle.Regular)) {
						if (fontFamily.IsStyleAvailable(style | FontStyle.Regular))
							style |= FontStyle.Regular;
						else style = FontStyle.Regular;
					} else if (fontFamily.IsStyleAvailable(FontStyle.Bold)) {
						if (fontFamily.IsStyleAvailable(style | FontStyle.Bold))
							style |= FontStyle.Bold;
						else style = FontStyle.Bold;
					} else if (fontFamily.IsStyleAvailable(FontStyle.Italic)) {
						if (fontFamily.IsStyleAvailable(style | FontStyle.Italic))
							style |= FontStyle.Italic;
						else style = FontStyle.Italic;
					} else if (fontFamily.IsStyleAvailable(FontStyle.Strikeout)) {
						if (fontFamily.IsStyleAvailable(style | FontStyle.Strikeout))
							style |= FontStyle.Strikeout;
						else style = FontStyle.Strikeout;
					} else if (fontFamily.IsStyleAvailable(FontStyle.Underline)) {
						if (fontFamily.IsStyleAvailable(style | FontStyle.Underline))
							style |= FontStyle.Underline;
						else style = FontStyle.Underline;
					}
				}
				//font = new Font(fontFamily, characterStyle.SizeInPoints, style, GraphicsUnit.Point);
				font = new Font(fontFamily, characterStyle.Size, style, GraphicsUnit.Pixel);
				// add font to the FontCache
				fontCache.Add(characterStyle, font);
			}
			return font;
		}
Esempio n. 23
0
		private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, ICharacterStyle charStyle) {
			Brush fontBrush = ToolCache.GetBrush(charStyle.ColorStyle);
			Font font = ToolCache.GetFont(charStyle);
			int height = Geometry.PointToPixel(charStyle.SizeInPoints, gfx.DpiY);
			float scale = Geometry.CalcScaleFactor(height, height, previewBounds.Width, previewBounds.Height);
			gfx.ScaleTransform(scale, scale);
			RectangleF layoutRect = RectangleF.Empty;
			layoutRect.X = 0;
			layoutRect.Y = 0;
			layoutRect.Width = (float)previewBounds.Width / scale;
			layoutRect.Height = (float)previewBounds.Height / scale;
			gfx.DrawString(string.Format("{0} {1} pt", charStyle.FontName, charStyle.SizeInPoints), 
				font, fontBrush, layoutRect, formatter);
		}
Esempio n. 24
0
        public static Shape DrawBox(int Height, int Width, int X, int Y, IFillStyle FillStyle, ILineStyle LineStyle, ICharacterStyle CharacterStyle, IParagraphStyle ParagraphStyle,
                                    String Caption, Object Tag, Char SecurityDomain, Dataweb.NShape.WinFormsUI.Display Display, Dataweb.NShape.Project Project)
        {
            Box shape;

            shape        = (Box)Project.ShapeTypes["Box"].CreateInstance();
            shape.Height = Height;
            shape.Width  = Width;

            shape.X = X;

            shape.Y = Y;

            shape.FillStyle = FillStyle;

            shape.CharacterStyle = CharacterStyle;

            shape.ParagraphStyle = ParagraphStyle;

            shape.SetCaptionText(0, Caption);

            shape.Tag = Tag;

            shape.SecurityDomainName = SecurityDomain;

            Display.Diagram.Shapes.Add(shape);

            Project.Repository.Insert((Shape)shape, Display.Diagram);

            return(shape);
        }
Esempio n. 25
0
		/// <ToBeCompleted></ToBeCompleted>
		public virtual void SetCaptionCharacterStyle(int index, ICharacterStyle characterStyle)
		{
			if (index != 0) throw new NShapeException(string.Format("Invalid label index: {0}.", index));
			CharacterStyle = characterStyle;
		}
Esempio n. 26
0
        private void Construct(IDiagramPresenter owner, ICaptionedShape shape, int captionIndex, string currentText, string newText)
        {
            if (owner == null) throw new ArgumentNullException("owner");
            if (shape == null) throw new ArgumentNullException("shape");
            if (captionIndex < 0 || captionIndex >= shape.CaptionCount) throw new ArgumentOutOfRangeException("captionIndex");
            // Set control styles
            SetStyle(ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
            UpdateStyles();

            // Set caption / style specific properties
            this.owner = owner;
            this.shape = shape;
            this.captionIndex = captionIndex;

            // Set general properties
            this.BackColor = Color.Transparent;	// Does not matter - see CreateParams()
            this.AutoScrollOffset = Point.Empty;
            this.ScrollBars = RichTextBoxScrollBars.None;
            this.BorderStyle = BorderStyle.None;
            // Set Styles here because the ParagraphStyle is needed for resizing
            characterStyle = shape.GetCaptionCharacterStyle(captionIndex);
            paragraphStyle = shape.GetCaptionParagraphStyle(captionIndex);

            // Set base' members
            SuspendLayout();
            try {
                this.WordWrap = paragraphStyle.WordWrap;
                this.Font = ToolCache.GetFont(characterStyle);
                this.ZoomFactor = owner.ZoomLevel / 100f;

                // Get line height
                Size textSize = TextRenderer.MeasureText(((IDisplayService)owner).InfoGraphics, "Iq", Font);
                owner.DiagramToControl(textSize, out textSize);
                lineHeight = textSize.Height;

                DoUpdateBounds();

                SelectAll();
                SelectionAlignment = ConvertToHorizontalAlignment(paragraphStyle.Alignment);
                DeselectAll();
            } finally {
                ResumeLayout();
            }
            OnPaddingChanged(EventArgs.Empty);
        }
Esempio n. 27
0
		/// <ToBeCompleted></ToBeCompleted>
		public void SetCaptionCharacterStyle(int index, ICharacterStyle characterStyle)
		{
			CharacterStyle = characterStyle;
		}
Esempio n. 28
0
 /// <override></override>
 protected internal override void InitializeToDefault(IStyleSet styleSet)
 {
     base.InitializeToDefault(styleSet);
     w = image.Width;
     h = image.Height;
     Fit(0, 0, 100, 100);
     charStyle = styleSet.CharacterStyles.Normal;
     paragraphStyle = styleSet.ParagraphStyles.Title;
     fillStyle = styleSet.FillStyles.Transparent;
 }
Esempio n. 29
0
		/// <summary>
		/// Draws the caption.
		/// </summary>
		public void Draw(Graphics graphics, ICharacterStyle characterStyle, IParagraphStyle paragraphStyle)
		{
			if (graphics == null) throw new ArgumentNullException("graphics");
			if (characterStyle == null) throw new ArgumentNullException("charStyle");
			if (paragraphStyle == null) throw new ArgumentNullException("paragraphStyle");
			if (textPath != null && textPath.PointCount > 0) {
				Brush brush = ToolCache.GetBrush(characterStyle.ColorStyle);
				graphics.FillPath(brush, textPath);
			}
		}
Esempio n. 30
0
 /// <override></override>
 public override void MakePreview(IStyleSet styleSet)
 {
     base.MakePreview(styleSet);
     privateCharacterStyle = styleSet.GetPreviewStyle(CharacterStyle);
     privateParagraphStyle = styleSet.GetPreviewStyle(ParagraphStyle);
 }
 /// <override></override>
 protected override void ProcessExecModelPropertyChange(IModelMapping propertyMapping)
 {
     switch (propertyMapping.ShapePropertyId) {
         case PropertyIdColumnBackgroundColorStyle:
             privateColumnBackgroundColorStyle = (propertyMapping.GetStyle() as IColorStyle);
             Invalidate();
             break;
         case PropertyIdColumnCharacterStyle:
             privateColumnCharacterStyle = (propertyMapping.GetStyle() as ICharacterStyle);
             InvalidateDrawCache();
             Invalidate();
             break;
         case PropertyIdColumnParagraphStyle:
             privateColumnParagraphStyle = (propertyMapping.GetStyle() as IParagraphStyle);
             InvalidateDrawCache();
             Invalidate();
             break;
         default:
             base.ProcessExecModelPropertyChange(propertyMapping);
             break;
     }
 }
 /// <override></override>
 protected override void InitializeToDefault(IStyleSet styleSet)
 {
     base.InitializeToDefault(styleSet);
     privateColumnBackgroundColorStyle = styleSet.ColorStyles.White;
     privateColumnCharacterStyle = styleSet.CharacterStyles.Caption;
     privateColumnParagraphStyle = styleSet.ParagraphStyles.Label;
     Width = 80;
     Height = 120;
     Text = "Table";
 }
 /// <override></override>
 public override void SetCaptionCharacterStyle(int index, ICharacterStyle characterStyle)
 {
     if (index < base.CaptionCount)
         base.SetCaptionCharacterStyle(index, characterStyle);
     else {
         int idx = index - 1;
         // Create if needed
         if (columnCharacterStyles == null)
             columnCharacterStyles = new SortedList<int, ICharacterStyle>(1);
         // Set private style for a single caption
         if (characterStyle != ColumnCharacterStyle) {
             if (!columnCharacterStyles.ContainsKey(idx))
                 columnCharacterStyles.Add(idx, characterStyle);
             else columnCharacterStyles[idx] = characterStyle;
         } else {
             if (columnCharacterStyles != null) {
                 if (columnCharacterStyles.ContainsKey(idx))
                     columnCharacterStyles.Remove(idx);
                 // Delete if not needed any more
                 if (columnCharacterStyles.Count == 0)
                     columnCharacterStyles = null;
             }
         }
     }
 }
Esempio n. 34
0
 /// <override></override>
 public override void MakePreview(IStyleSet styleSet)
 {
     base.MakePreview(styleSet);
     charStyle = styleSet.GetPreviewStyle(CharacterStyle);
     paragraphStyle = styleSet.GetPreviewStyle(ParagraphStyle);
     fillStyle = styleSet.GetPreviewStyle(FillStyle);
 }
Esempio n. 35
0
		/// <override></override>
		public override void SetCaptionCharacterStyle(int index, ICharacterStyle characterStyle) {
			base.SetCaptionCharacterStyle(index, characterStyle);
			if (autoSize) FitShapeToText();
		}
Esempio n. 36
0
        /// <override></override>
        public override void CopyFrom(Shape source)
        {
            base.CopyFrom(source);
            if (source is ICaptionedShape) {
                ICaptionedShape src = (ICaptionedShape)source;
                // Copy first caption
                ICharacterStyle charStyle = src.GetCaptionCharacterStyle(0);
                privateCharacterStyle = (Template != null && charStyle == ((ICaptionedShape)Template.Shape).GetCaptionCharacterStyle(0)) ? null : charStyle;
                IParagraphStyle paragraphStyle = src.GetCaptionParagraphStyle(0);
                privateParagraphStyle = (Template != null && paragraphStyle == ((ICaptionedShape)Template.Shape).GetCaptionParagraphStyle(0)) ? null : paragraphStyle;
                string txt = src.GetCaptionText(0);
                if (!string.IsNullOrEmpty(txt)) {
                    if (caption == null) caption = new Caption(txt);
                    else caption.Text = txt;
                } else caption = null;

                // Copy remaining captions
                int cnt = Math.Min(CaptionCount, src.CaptionCount);
                for (int i = 1; i < cnt; ++i) {
                    SetCaptionCharacterStyle(i, src.GetCaptionCharacterStyle(i));
                    SetCaptionParagraphStyle(i, GetCaptionParagraphStyle(i));
                    SetCaptionText(i, GetCaptionText(i));
                }
            }
        }
Esempio n. 37
0
		/// <summary>
		/// Deletes all tools based on the given CharacterStyle.
		/// </summary>
		private static void NotifyCharacterStyleChanged(ICharacterStyle characterStyle) {
			Debug.Assert(characterStyle != null);
			
			while (fontCache.ContainsKey(characterStyle)) {
				Font font = fontCache[characterStyle];
				fontCache.Remove(characterStyle);
				font.Dispose();
				font = null;
			}
		}
Esempio n. 38
0
        /// <override></override>
        protected override void LoadFieldsCore(IRepositoryReader reader, int version)
        {
            base.LoadFieldsCore(reader, version);
            fillStyle = reader.ReadFillStyle();
            charStyle = reader.ReadCharacterStyle();
            paragraphStyle = reader.ReadParagraphStyle();

            string txt = reader.ReadString();
            if (caption == null) caption = new Caption(txt);
            else caption.Text = txt;
            w = reader.ReadInt32();
            h = reader.ReadInt32();
        }
Esempio n. 39
0
        /// <summary>
        /// Returns the font specified by the given <see cref="T:Dataweb.NShape.ICharacterStyle"/>.
        /// </summary>
        /// <param name="characterStyle"></param>
        /// <returns></returns>
        public static Font GetFont(ICharacterStyle characterStyle)
        {
            if (characterStyle == null)
            {
                throw new ArgumentNullException("characterStyle");
            }

            Font font = null;

            if (!_fontCache.TryGetValue(characterStyle, out font))
            {
                FontFamily fontFamily = characterStyle.FontFamily;
                FontStyle  style      = characterStyle.Style;
                // Check if the desired FontStyle is available for this particular FontFamily
                // Set an available FontStyle if not.
                if (fontFamily != null && !fontFamily.IsStyleAvailable(style))
                {
                    if (fontFamily.IsStyleAvailable(FontStyle.Regular))
                    {
                        if (fontFamily.IsStyleAvailable(style | FontStyle.Regular))
                        {
                            style |= FontStyle.Regular;
                        }
                        else
                        {
                            style = FontStyle.Regular;
                        }
                    }
                    else if (fontFamily.IsStyleAvailable(FontStyle.Bold))
                    {
                        if (fontFamily.IsStyleAvailable(style | FontStyle.Bold))
                        {
                            style |= FontStyle.Bold;
                        }
                        else
                        {
                            style = FontStyle.Bold;
                        }
                    }
                    else if (fontFamily.IsStyleAvailable(FontStyle.Italic))
                    {
                        if (fontFamily.IsStyleAvailable(style | FontStyle.Italic))
                        {
                            style |= FontStyle.Italic;
                        }
                        else
                        {
                            style = FontStyle.Italic;
                        }
                    }
                    else if (fontFamily.IsStyleAvailable(FontStyle.Strikeout))
                    {
                        if (fontFamily.IsStyleAvailable(style | FontStyle.Strikeout))
                        {
                            style |= FontStyle.Strikeout;
                        }
                        else
                        {
                            style = FontStyle.Strikeout;
                        }
                    }
                    else if (fontFamily.IsStyleAvailable(FontStyle.Underline))
                    {
                        if (fontFamily.IsStyleAvailable(style | FontStyle.Underline))
                        {
                            style |= FontStyle.Underline;
                        }
                        else
                        {
                            style = FontStyle.Underline;
                        }
                    }
                }
                //font = new Font(fontFamily, characterStyle.PointSize, style, GraphicsUnit.Point);
                font = new Font(fontFamily, characterStyle.Size, style, GraphicsUnit.Pixel);
                // Add font to the FontCache
                _fontCache.Add(characterStyle, font);
            }
            return(font);
        }
 /// <override></override>
 public override void MakePreview(IStyleSet styleSet)
 {
     base.MakePreview(styleSet);
     privateColumnCharacterStyle = styleSet.GetPreviewStyle(ColumnCharacterStyle);
     privateColumnParagraphStyle = styleSet.GetPreviewStyle(ColumnParagraphStyle);
     privateColumnBackgroundColorStyle = styleSet.GetPreviewStyle(ColumnBackgroundColorStyle);
 }
Esempio n. 41
0
		/// <summary>
		/// Calculates the caption path in the untransformed state.
		/// </summary>
		/// <param name="layoutX">X coordinate of the layout rectangle</param>
		/// <param name="layoutY">Y coordinate of the layout rectangle</param>
		/// <param name="layoutW">Width of the layout rectangle</param>
		/// <param name="layoutH">Height of the layout rectangle</param>
		/// <param name="characterStyle">Character style of the caption</param>
		/// <param name="paragraphStyle">Paragraph style of the caption</param>
		/// <returns></returns>
		public bool CalculatePath(int layoutX, int layoutY, int layoutW, int layoutH, ICharacterStyle characterStyle,
		                          IParagraphStyle paragraphStyle)
		{
			if (characterStyle == null) throw new ArgumentNullException("charStyle");
			if (paragraphStyle == null) throw new ArgumentNullException("paragraphStyle");
			if (string.IsNullOrEmpty(captionText))
				return true;
			else if (textPath != null /*&& layoutW > 0 && layoutH > 0*/) {
				// Collect objects for calculating text layout
				Font font = ToolCache.GetFont(characterStyle);
				StringFormat formatter = ToolCache.GetStringFormat(paragraphStyle);
				Rectangle textBounds = Rectangle.Empty;
				textBounds.X = layoutX + paragraphStyle.Padding.Left;
				textBounds.Y = layoutY + paragraphStyle.Padding.Top;
				textBounds.Width = Math.Max(1, layoutW - paragraphStyle.Padding.Horizontal);
				textBounds.Height = Math.Max(1, layoutH - paragraphStyle.Padding.Vertical);
				// Create text path
				textPath.Reset();
				textPath.StartFigure();
				textPath.AddString(PathText, font.FontFamily, (int) font.Style, characterStyle.Size, textBounds, formatter);
				textPath.CloseFigure();
#if DEBUG_DIAGNOSTICS
				if (textPath.PointCount == 0 && PathText.Trim() != string.Empty) {
					Size textSize = TextMeasurer.MeasureText(PathText, font, textBounds.Size, paragraphStyle);
					Debug.Print("Failed to create TextPath - please check if the caption bounds are too small for the text.");
				}
#endif
				return true;
			}
			return false;
		}