Пример #1
0
        /// <summary>
        /// Gets/Creates a <see cref="Font"/> given the specified arguments.
        /// </summary>
        public Font CreateFont(CreateFontArgs args)
        {
            var key             = new ItemKey(args.Name, args.Size, args.Style, args.Unit);
            var defaultFontName = !string.IsNullOrWhiteSpace(args.DefaultFontName) ? args.DefaultFontName : GenericSansSerif;

            return(GetFont(key, defaultFontName));
        }
Пример #2
0
            public Font GetFont(string fontName, float fontSize, FontStyle fontStyle = FontStyle.Regular, GraphicsUnit graphicsUnit = GraphicsUnit.Point, string defaultFontName = null)
            {
                var args = new CreateFontArgs(fontName, fontSize, fontStyle, graphicsUnit)
                {
                    DefaultFontName = defaultFontName
                };

                return(_gdiObjectFactory.CreateFont(args));
            }
Пример #3
0
        /// <summary>
        /// Draws a text primitive to the specified destination buffer.
        /// </summary>
        /// <param name="buffer">The destination buffer.</param>
        /// <param name="gdiObjectFactory">A factory for GDI+ objects.</param>
        /// <param name="text">The text primitive to be drawn.</param>
        /// <param name="dpi">The intended output DPI.</param>
        public static void DrawTextPrimitive(IGdiBuffer buffer, IGdiObjectFactory gdiObjectFactory, InvariantTextPrimitive text, float dpi = _nominalScreenDpi)
        {
            text.CoordinateSystem = CoordinateSystem.Destination;
            try
            {
                // We adjust the font size depending on the scale so that it's the same size
                // irrespective of the zoom
                var fontSize       = CalculateScaledFontPoints(text.SizeInPoints, dpi);
                var createFontArgs = new CreateFontArgs(text.Font, fontSize, FontStyle.Regular, GraphicsUnit.Point)
                {
                    DefaultFontName = FontFactory.GenericSansSerif
                };
                var font = gdiObjectFactory.CreateFont(createFontArgs);

                // Calculate how big the text will be so we can set the bounding box
                text.Dimensions = buffer.Graphics.MeasureString(text.Text, font);

                // Draw drop shadow
                var brush = gdiObjectFactory.CreateBrush(new CreateBrushArgs(Color.Black));

                var dropShadowOffset   = new SizeF(1, 1);
                var boundingBoxTopLeft = new PointF(text.BoundingBox.Left, text.BoundingBox.Top);

                buffer.Graphics.DrawString(
                    text.Text,
                    font,
                    brush,
                    boundingBoxTopLeft + dropShadowOffset);

                // Draw text
                brush = gdiObjectFactory.CreateBrush(new CreateBrushArgs(text.Color));

                buffer.Graphics.DrawString(
                    text.Text,
                    font,
                    brush,
                    boundingBoxTopLeft);
            }
            finally
            {
                text.ResetCoordinateSystem();
            }
        }
Пример #4
0
 public Font CreateFont(CreateFontArgs args)
 {
     return(_fontFactory.CreateFont(args));
 }
Пример #5
0
 /// <summary>
 /// Gets/Creates a <see cref="Font"/> given the specified arguments.
 /// </summary>
 public Font CreateFont(CreateFontArgs args)
 {
     var key = new ItemKey(args.Name, args.Size, args.Style, args.Unit);
     var defaultFontName = !string.IsNullOrWhiteSpace(args.DefaultFontName) ? args.DefaultFontName : GenericSansSerif;
     return GetFont(key, defaultFontName);
 }
Пример #6
0
		/// <summary>
		/// Gets a <see cref="Font"/> object for the specified typeface, size, style and unit.
		/// </summary>
		/// <param name="fontName">The name of the typeface.</param>
		/// <param name="fontSize">The size of the font.</param>
		/// <param name="fontStyle">The style of the font.</param>
		/// <param name="graphicsUnit">The units in which <paramref name="fontSize"/> is expressed.</param>
		/// <param name="defaultFontName">The name of a default typeface, in case the font referred to by <paramref name="fontName"/> does not exist.</param>
		/// <returns></returns>
		public Font GetFont(string fontName, float fontSize, FontStyle fontStyle = FontStyle.Regular, GraphicsUnit graphicsUnit = GraphicsUnit.Point, string defaultFontName = null)
		{
		    var args = new CreateFontArgs(fontName, fontSize, fontStyle, graphicsUnit);
            return CreateFont(args);
		}
Пример #7
0
 public Font CreateFont(CreateFontArgs args)
 {
     return _gdiObjectFactory.CreateFont(args);
 }
Пример #8
0
	        public Font CreateFont(CreateFontArgs args)
	        {
	            return _fontFactory.CreateFont(args);
	        }
Пример #9
0
	    /// <summary>
		/// Draws a text primitive to the specified destination buffer.
		/// </summary>
		/// <param name="buffer">The destination buffer.</param>
		/// <param name="gdiObjectFactory">A factory for GDI+ objects.</param>
		/// <param name="text">The text primitive to be drawn.</param>
		/// <param name="dpi">The intended output DPI.</param>
		public static void DrawTextPrimitive(IGdiBuffer buffer, IGdiObjectFactory gdiObjectFactory, InvariantTextPrimitive text, float dpi = _nominalScreenDpi)
		{
			text.CoordinateSystem = CoordinateSystem.Destination;
			try
			{
				// We adjust the font size depending on the scale so that it's the same size
				// irrespective of the zoom
				var fontSize = CalculateScaledFontPoints(text.SizeInPoints, dpi);
                var createFontArgs = new CreateFontArgs(text.Font, fontSize, FontStyle.Regular, GraphicsUnit.Point) { DefaultFontName = FontFactory.GenericSansSerif };
                var font = gdiObjectFactory.CreateFont(createFontArgs);

				// Calculate how big the text will be so we can set the bounding box
				text.Dimensions = buffer.Graphics.MeasureString(text.Text, font);

				// Draw drop shadow
			    var brush = gdiObjectFactory.CreateBrush(new CreateBrushArgs(Color.Black));

				var dropShadowOffset = new SizeF(1, 1);
				var boundingBoxTopLeft = new PointF(text.BoundingBox.Left, text.BoundingBox.Top);

				buffer.Graphics.DrawString(
					text.Text,
					font,
					brush,
					boundingBoxTopLeft + dropShadowOffset);

				// Draw text
                brush = gdiObjectFactory.CreateBrush(new CreateBrushArgs(text.Color));

                buffer.Graphics.DrawString(
					text.Text,
					font,
					brush,
					boundingBoxTopLeft);
			}
			finally
			{
				text.ResetCoordinateSystem();
			}
		}
Пример #10
0
	    /// <summary>
	    /// Draws an annotation box to the specified destination buffer.
	    /// </summary>
	    /// <param name="buffer">The destination buffer.</param>
        /// <param name="gdiObjectFactory">A factory for GDI objects.</param>
        /// <param name="annotationText">The annotation text to be drawn.</param>
	    /// <param name="annotationBox">The annotation box to be drawn.</param>
	    /// <param name="dpi">The intended output DPI.</param>
	    public static void DrawAnnotationBox(IGdiBuffer buffer, IGdiObjectFactory gdiObjectFactory, 
            string annotationText, AnnotationBox annotationBox, float dpi = _nominalScreenDpi)
	    {
	        // if there's nothing to draw, there's nothing to do. go figure.
	        if (string.IsNullOrWhiteSpace(annotationText))
	            return;

	        var clientRectangle = RectangleUtilities.CalculateSubRectangle(buffer.Bounds, annotationBox.NormalizedRectangle);

	        //Deflate the client rectangle by 4 pixels to allow some space 
	        //between neighbouring rectangles whose borders coincide.
	        Rectangle.Inflate(clientRectangle, -4, -4);

	        var fontSize = (clientRectangle.Height/annotationBox.NumberOfLines) - 1;

	        //don't draw it if it's too small to read, anyway.
	        if (fontSize < MinimumFontSizeInPixels)
	            return;

	        var style = FontStyle.Regular;
	        if (annotationBox.Bold)
	            style |= FontStyle.Bold;
	        if (annotationBox.Italics)
	            style |= FontStyle.Italic;

	        //don't draw it if it's too small to read, anyway.
	        if (fontSize < MinimumFontSizeInPixels)
	            return;

	        var fontArgs = new CreateFontArgs(annotationBox.Font, fontSize, style, GraphicsUnit.Pixel) { DefaultFontName = AnnotationBox.DefaultFont };
            var font = gdiObjectFactory.CreateFont(fontArgs);
            var format = gdiObjectFactory.CreateStringFormat(new CreateStringFormatArgs(annotationBox));

	        var layoutArea = new SizeF(clientRectangle.Width, clientRectangle.Height);
	        var size = buffer.Graphics.MeasureString(annotationText, font, layoutArea, format);
	        if (annotationBox.FitWidth && size.Width > clientRectangle.Width)
	        {
	            fontSize = (int) (Math.Round(fontSize*clientRectangle.Width/(double) size.Width - 0.5));
	            //don't draw it if it's too small to read, anyway.
	            if (fontSize < MinimumFontSizeInPixels)
	                return;

                font = gdiObjectFactory.CreateFont(fontArgs);
	        }

	        // Draw drop shadow
			var brush = gdiObjectFactory.CreateBrush(new CreateBrushArgs(Color.Black));
	        clientRectangle.Offset(1, 1);

	        buffer.Graphics.DrawString(
	            annotationText,
	            font,
	            brush,
	            clientRectangle,
	            format);

	        brush = gdiObjectFactory.CreateBrush(new CreateBrushArgs(annotationBox.Color));

	        clientRectangle.Offset(-1, -1);

	        buffer.Graphics.DrawString(
	            annotationText,
	            font,
	            brush,
	            clientRectangle,
	            format);
	    }
Пример #11
0
        /// <summary>
        /// Draws an annotation box to the specified destination buffer.
        /// </summary>
        /// <param name="buffer">The destination buffer.</param>
        /// <param name="gdiObjectFactory">A factory for GDI objects.</param>
        /// <param name="annotationText">The annotation text to be drawn.</param>
        /// <param name="annotationBox">The annotation box to be drawn.</param>
        /// <param name="dpi">The intended output DPI.</param>
        public static void DrawAnnotationBox(IGdiBuffer buffer, IGdiObjectFactory gdiObjectFactory,
                                             string annotationText, AnnotationBox annotationBox, float dpi = _nominalScreenDpi)
        {
            // if there's nothing to draw, there's nothing to do. go figure.
            if (string.IsNullOrWhiteSpace(annotationText))
            {
                return;
            }

            var clientRectangle = RectangleUtilities.CalculateSubRectangle(buffer.Bounds, annotationBox.NormalizedRectangle);

            //Deflate the client rectangle by 4 pixels to allow some space
            //between neighbouring rectangles whose borders coincide.
            Rectangle.Inflate(clientRectangle, -4, -4);

            var fontSize = (clientRectangle.Height / annotationBox.NumberOfLines) - 1;

            //don't draw it if it's too small to read, anyway.
            if (fontSize < MinimumFontSizeInPixels)
            {
                return;
            }

            var style = FontStyle.Regular;

            if (annotationBox.Bold)
            {
                style |= FontStyle.Bold;
            }
            if (annotationBox.Italics)
            {
                style |= FontStyle.Italic;
            }

            //don't draw it if it's too small to read, anyway.
            if (fontSize < MinimumFontSizeInPixels)
            {
                return;
            }

            var fontArgs = new CreateFontArgs(annotationBox.Font, fontSize, style, GraphicsUnit.Pixel)
            {
                DefaultFontName = AnnotationBox.DefaultFont
            };
            var font   = gdiObjectFactory.CreateFont(fontArgs);
            var format = gdiObjectFactory.CreateStringFormat(new CreateStringFormatArgs(annotationBox));

            var layoutArea = new SizeF(clientRectangle.Width, clientRectangle.Height);
            var size       = buffer.Graphics.MeasureString(annotationText, font, layoutArea, format);

            if (annotationBox.FitWidth && size.Width > clientRectangle.Width)
            {
                fontSize = (int)(Math.Round(fontSize * clientRectangle.Width / (double)size.Width - 0.5));
                //don't draw it if it's too small to read, anyway.
                if (fontSize < MinimumFontSizeInPixels)
                {
                    return;
                }

                font = gdiObjectFactory.CreateFont(fontArgs);
            }

            // Draw drop shadow
            var brush = gdiObjectFactory.CreateBrush(new CreateBrushArgs(Color.Black));

            clientRectangle.Offset(1, 1);

            buffer.Graphics.DrawString(
                annotationText,
                font,
                brush,
                clientRectangle,
                format);

            brush = gdiObjectFactory.CreateBrush(new CreateBrushArgs(annotationBox.Color));

            clientRectangle.Offset(-1, -1);

            buffer.Graphics.DrawString(
                annotationText,
                font,
                brush,
                clientRectangle,
                format);
        }
Пример #12
0
 public Font CreateFont(CreateFontArgs args)
 {
     return(_gdiObjectFactory.CreateFont(args));
 }