Exemple #1
0
        //----------------------------------------
        // HORIZONTAL ALIGNMENT
        //----------------------------------------

        public static StringAlignment ToSystemDrawingStringAlignment(VrsDrawing.HorizontalAlignment vrsHorizontalAlignment)
        {
            switch (vrsHorizontalAlignment)
            {
            case VrsDrawing.HorizontalAlignment.Centre: return(StringAlignment.Center);

            case VrsDrawing.HorizontalAlignment.Left:   return(StringAlignment.Near);

            case VrsDrawing.HorizontalAlignment.Right:  return(StringAlignment.Far);

            default:                                    throw new NotImplementedException();
            }
        }
Exemple #2
0
        /// <summary>
        /// See base docs.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="font"></param>
        /// <param name="fillBrush"></param>
        /// <param name="outlinePen"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="alignment"></param>
        /// <param name="preferSpeedOverQuality"></param>
        public override void DrawText(string text, VrsDrawing.IFont font, VrsDrawing.IBrush fillBrush, VrsDrawing.IPen outlinePen, float x, float y, VrsDrawing.HorizontalAlignment alignment, bool preferSpeedOverQuality = true)
        {
            if (font is FontWrapper fontWrapper)
            {
                GdiPlusLock.EnforceSingleThread(() => {
                    var location = new PointF(x, y);

                    // Mono ignores these flags...
                    var stringFormat = new StringFormat()
                    {
                        Alignment     = Convert.ToSystemDrawingStringAlignment(alignment),
                        LineAlignment = Convert.ToSystemDrawingStringAlignment(alignment),
                        FormatFlags   = StringFormatFlags.NoWrap,
                    };

                    using (var graphicsPath = new GraphicsPath()) {
                        graphicsPath.AddString(
                            text,
                            fontWrapper.NativeFont.FontFamily,
                            (int)fontWrapper.NativeFont.Style,
                            fontWrapper.NativeFont.Size,
                            location,
                            stringFormat
                            );

                        NativeDrawingContext.SmoothingMode     = SmoothingMode.AntiAlias;
                        NativeDrawingContext.InterpolationMode = InterpolationMode.HighQualityBicubic;

                        if (outlinePen is PenWrapper outlinePenWrapper)
                        {
                            NativeDrawingContext.DrawPath(outlinePenWrapper.NativePen, graphicsPath);
                        }
                        if (fillBrush is BrushWrapper fillBrushWrapper)
                        {
                            NativeDrawingContext.FillPath(fillBrushWrapper.NativeBrush, graphicsPath);
                        }
                    }
                });
            }
        }
Exemple #3
0
 /// <summary>
 /// See interface docs.
 /// </summary>
 /// <param name="text"></param>
 /// <param name="font"></param>
 /// <param name="fillBrush"></param>
 /// <param name="outlinePen"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="alignment"></param>
 /// <param name="preferSpeedOverQuality"></param>
 public abstract void DrawText(string text, VrsDrawing.IFont font, VrsDrawing.IBrush fillBrush, VrsDrawing.IPen outlinePen, float x, float y, VrsDrawing.HorizontalAlignment alignment, bool preferSpeedOverQuality = true);