Create text with decorations
Create text with decorations
Create a document with text with decorations like gradient color, shadow, emboss and glow
Gradients
With CreatePaths of the TALLcomponents PDF kit you can get the paths of any glyph of any font (these paths are the outline information, it is used to draw a glyph). Using these paths, you can use the pen and brush to add some decoration to what normally be just a plain text. In this example a pen and a gradient brush is used to give text a little more color:
Color colorPen = new RgbColor(0, 100, 0);
Color colorTop = new RgbColor(240, 230, 140);
Color colorBottom = new RgbColor(85, 107, 47);
Brush brush = new AxialGradientBrush(colorBottom , colorTop, 0, 0, 0, size);
Pen pen = new Pen(colorPen, 1);
FreeHandShape charAsShape = new FreeHandShape { Pen = pen, Brush = brush };
charAsShape.Paths.AddRange(usedFont.CreatePaths('b', size));
Dim colorPen As Color = New RgbColor(0, 100, 0)
Dim colorTop As Color = New RgbColor(240, 230, 140)
Dim colorBottom As Color = New RgbColor(85, 107, 47)
Dim brush As Brush = New AxialGradientBrush(colorBottom, colorTop, 0, 0, 0, size)
Dim pen As New Pen(colorPen, 1)
Dim charAsShape As New FreeHandShape() With { _
Key .Pen = pen, _
Key .Brush = brush _
}
charAsShape.Paths.AddRange(usedFont.CreatePaths("b"C, size))
Shadow
Of course, these paths can be added twice to the PDF document, so that there are to glyphs on top of each other. If the bottom one is scaled a bit, moved a little to right down and painted with shadow colors the result will be a text with shadows like:
Apply a transformation on the paths of the glyphs this way:
// scale and position the bottom glyph that is the shadow
charAsShape.Transform = new TransformCollection
{
new ScaleTransform(1.04, 1.04),
new TranslateTransform(2, 3)
};
' scale and position the bottom glyph that is the shadow
charAsShape.Transform = New TransformCollection() From { _
New ScaleTransform(1.04, 1.04), _
New TranslateTransform(2, 3) _
}
Emboss
You can create an emboss effect with three glyphs on top of each other:
- First draw a background rectangle around the text using the text color.
- Then oversize the text by using a dark fat pen, this will be the shadow part.
- Next, overwrite parts of the shadow with highlight color, slightly moved down-right.
- Finally draw the actual text on top with solid color.
What you get is:
Glow
With many glyphs on top of each other you can create a glow effect. Draw several layes of the same text, the lower layers are increasingly fattened (using a thicker pensize), and are increasingly more transparent:
ShapeCollection shapes = new ShapeCollection(0, 0, 100, 50);
double[] Opacities = { 255, 128, 64, 32, 16, 8, 4 };
const double overSizeStep = 1.4;
double offsetY = usedFont.BaselineOffset * fontsize;
double offsetX = 4;
foreach (char c in text)
{
FreeHandPathCollection glyphPaths = usedFont.CreatePaths(c, fontsize);
for (int i = 6; i >= 0; i--)
{
FreeHandShape charStack = new FreeHandShape();
if (i == 0) charStack.Brush = new SolidBrush(colorText);
charStack.Opacity = Opacities[i];
charStack.Pen = new Pen(colorGlow, 1 + (i * overSizeStep));
charStack.Pen.MiterLimit = 4;
charStack.Paths.AddRange(glyphPaths);
charStack.Transform = new TranslateTransform(offsetX, offsetY);
shapes.Add(charStack);
}
offsetX += usedFont.CalculateWidth(c.ToString(), fontsize);
}
Dim shapes As New ShapeCollection(0, 0, 100, 50)
Dim Opacities As Double() = {255, 128, 64, 32, 16, 8, _
4}
Const overSizeStep As Double = 1.4
Dim offsetY As Double = usedFont.BaselineOffset * fontsize
Dim offsetX As Double = 4
For Each c As Char In text
Dim glyphPaths As FreeHandPathCollection = usedFont.CreatePaths(c, fontsize)
For i As Integer = 6 To 0 Step -1
Dim charStack As New FreeHandShape()
If i = 0 Then
charStack.Brush = New SolidBrush(colorText)
End If
charStack.Opacity = Opacities(i)
charStack.Pen = New Pen(colorGlow, 1 + (i * overSizeStep))
charStack.Pen.MiterLimit = 4
charStack.Paths.AddRange(glyphPaths)
charStack.Transform = New TranslateTransform(offsetX, offsetY)
shapes.Add(charStack)
Next
offsetX += usedFont.CalculateWidth(c.ToString(), fontsize)
Next
Inverse
Of course it does not have to end here. You can draw a rectangle around the the glyphs and experiment with the FillRule, this way you get a opaque box with transparent text in it:
ShapeCollection shapes = new ShapeCollection(0, 0, 100, 50);
int size = 48;
Font font = Font.HelveticaBold;
Color colorPen = new RgbColor(0, 100, 0);
Color colorTop = new RgbColor(240, 230, 140);
Color colorBottom = new RgbColor(85, 107, 47);
Pen pen = new Pen(colorPen, 1);
Brush brush = new AxialGradientBrush(colorBottom, colorTop, 0, 0, 0, Size);
double offsetX = 0;
double offsetY = font.BaselineOffset * size;
RectangleShape outline = new RectangleShape(0, 0, width, height);
outline.Pen = new Pen(colorPen);
foreach (char c in "seethrough")
{
double width = font.CalculateWidth(c.ToString(), size);
double height = font.CalculateHeight(c.ToString(), size, width);
FreeHandShape charAsShape = new FreeHandShape { Brush = brush };
FreeHandPath glyphbox = new FreeHandPath(true);
glyphbox.Segments.Add(new FreeHandStartSegment(0, -offsetY));
glyphbox.Segments.Add(new FreeHandLineSegment(width + 0.5, -offsetY));
glyphbox.Segments.Add(new FreeHandLineSegment(width + 0.5, size));
glyphbox.Segments.Add(new FreeHandLineSegment(0, size));
charAsShape.Paths.Add(glyphbox);
charAsShape.Paths.AddRange(font.CreatePaths(c, size));
charAsShape.Transform = new TransformCollection() { new TranslateTransform(offsetX, offsetY)};
charAsShape.FillRule = FillRule.EvenOdd;
shapes.Add(charAsShape);
offsetX += width;
}
shapes.Add(outline);
Dim shapes As New ShapeCollection(0, 0, 100, 50)
Dim size__1 As Integer = 48
Dim font__2 As Font = Font.HelveticaBold
Dim colorPen As Color = New RgbColor(0, 100, 0)
Dim colorTop As Color = New RgbColor(240, 230, 140)
Dim colorBottom As Color = New RgbColor(85, 107, 47)
Dim pen As New Pen(colorPen, 1)
Dim brush As Brush = New AxialGradientBrush(colorBottom, colorTop, 0, 0, 0, Size)
Dim offsetX As Double = 0
Dim offsetY As Double = font__2.BaselineOffset * size__1
Dim outline As New RectangleShape(0, 0, width, height)
outline.Pen = New Pen(colorPen)
For Each c As Char In "seethrough"
Dim width As Double = font__2.CalculateWidth(c.ToString(), size__1)
Dim height As Double = font__2.CalculateHeight(c.ToString(), size__1, width)
Dim charAsShape As New FreeHandShape() With { _
Key .Brush = brush _
}
Dim glyphbox As New FreeHandPath(True)
glyphbox.Segments.Add(New FreeHandStartSegment(0, -offsetY))
glyphbox.Segments.Add(New FreeHandLineSegment(width + 0.5, -offsetY))
glyphbox.Segments.Add(New FreeHandLineSegment(width + 0.5, size__1))
glyphbox.Segments.Add(New FreeHandLineSegment(0, size__1))
charAsShape.Paths.Add(glyphbox)
charAsShape.Paths.AddRange(font__2.CreatePaths(c, size__1))
charAsShape.Transform = New TransformCollection() From { _
New TranslateTransform(offsetX, offsetY) _
}
charAsShape.FillRule = FillRule.EvenOdd
shapes.Add(charAsShape)
offsetX += width
Next
shapes.Add(outline)