public void SetOutlineGradient(OutlineGradient outlineGradient) { this.outlineGradient = outlineGradient; if (style != null) { this.style.SetOutlineGradient(outlineGradient, this); } }
public override Bitmap Apply(Bitmap bmp) { if (string.IsNullOrEmpty(Text)) { return(bmp); } using (Font font = Font) { if (font == null || font.Size < 1) { return(bmp); } NameParser parser = new NameParser(NameParserType.Text); parser.ImageWidth = bmp.Width; parser.ImageHeight = bmp.Height; string parsedText = parser.Parse(Text); using (Graphics g = Graphics.FromImage(bmp)) using (GraphicsPath gp = new GraphicsPath()) { g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.Half; gp.FillMode = FillMode.Winding; float emSize = g.DpiY * font.SizeInPoints / 72; gp.AddString(parsedText, font.FontFamily, (int)font.Style, emSize, Point.Empty, StringFormat.GenericDefault); if (Angle != 0) { using (Matrix matrix = new Matrix()) { matrix.Rotate(Angle); gp.Transform(matrix); } } RectangleF pathRect = gp.GetBounds(); if (pathRect.IsEmpty) { return(bmp); } Size textSize = pathRect.Size.ToSize().Offset(1); Point textPosition = Helpers.GetPosition(Placement, Offset, bmp.Size, textSize); Rectangle textRectangle = new Rectangle(textPosition, textSize); if (AutoHide && !new Rectangle(0, 0, bmp.Width, bmp.Height).Contains(textRectangle)) { return(bmp); } using (Matrix matrix = new Matrix()) { matrix.Translate(textRectangle.X - pathRect.X, textRectangle.Y - pathRect.Y); gp.Transform(matrix); } // Draw text shadow if (Shadow && ((!ShadowUseGradient && ShadowColor.A > 0) || (ShadowUseGradient && ShadowGradient.IsVisible))) { using (Matrix matrix = new Matrix()) { matrix.Translate(ShadowOffset.X, ShadowOffset.Y); gp.Transform(matrix); if (Outline && OutlineSize > 0) { if (ShadowUseGradient) { using (LinearGradientBrush textShadowBrush = ShadowGradient.GetGradientBrush( Rectangle.Round(textRectangle).Offset(OutlineSize + 1).LocationOffset(ShadowOffset))) using (Pen textShadowPen = new Pen(textShadowBrush, OutlineSize) { LineJoin = LineJoin.Round }) { g.DrawPath(textShadowPen, gp); } } else { using (Pen textShadowPen = new Pen(ShadowColor, OutlineSize) { LineJoin = LineJoin.Round }) { g.DrawPath(textShadowPen, gp); } } } else { if (ShadowUseGradient) { using (Brush textShadowBrush = ShadowGradient.GetGradientBrush( Rectangle.Round(textRectangle).Offset(1).LocationOffset(ShadowOffset))) { g.FillPath(textShadowBrush, gp); } } else { using (Brush textShadowBrush = new SolidBrush(ShadowColor)) { g.FillPath(textShadowBrush, gp); } } } matrix.Reset(); matrix.Translate(-ShadowOffset.X, -ShadowOffset.Y); gp.Transform(matrix); } } // Draw text outline if (Outline && OutlineSize > 0) { if (OutlineUseGradient) { if (OutlineGradient.IsVisible) { using (LinearGradientBrush textOutlineBrush = OutlineGradient.GetGradientBrush(Rectangle.Round(textRectangle).Offset(OutlineSize + 1))) using (Pen textOutlinePen = new Pen(textOutlineBrush, OutlineSize) { LineJoin = LineJoin.Round }) { g.DrawPath(textOutlinePen, gp); } } } else if (OutlineColor.A > 0) { using (Pen textOutlinePen = new Pen(OutlineColor, OutlineSize) { LineJoin = LineJoin.Round }) { g.DrawPath(textOutlinePen, gp); } } } // Draw text if (UseGradient) { if (Gradient.IsVisible) { using (Brush textBrush = Gradient.GetGradientBrush(Rectangle.Round(textRectangle).Offset(1))) { g.FillPath(textBrush, gp); } } } else if (Color.A > 0) { using (Brush textBrush = new SolidBrush(Color)) { g.FillPath(textBrush, gp); } } } return(bmp); } }