Pen and brush not aligned in DrawText #329
Answered
by
tocsoft
johantiger
asked this question in
Q&A
Answered by
tocsoft
May 9, 2024
Replies: 1 comment 3 replies
|
Your doing nothing wrong there, that's totally a bug. Looking closely it looks like there is a As a work around you might be able to do something like this. FontCollection fontCollection = new();
FontFamily fontFamily = fontCollection.Add(Path.Combine(functionDirectory, "Assets", "Fonts",
"OpenSans-ExtraBold.ttf"));
Font bibfont = fontFamily.CreateFont(600, FontStyle.Bold);
Font namefont = fontFamily.CreateFont(140, FontStyle.Bold);
RichTextOptions options = new RichTextOptions(bibfont)
{
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
TextDirection = TextDirection.LeftToRight,
Origin = new Point(1156,1024),
};
image.Mutate(x => x.DrawText(options, "9999", Brushes.Solid(Color.White)));
var penWidth = 25f;
options.Origin = options.Origin - new Vector2(penWidth / 2f);
image.Mutate(x => x.DrawText(options, "9999", Pens.Solid(Color.Black, penWidth)));
options.Font = namefont;
options.Origin = new Point(1156, 713);
image.Mutate(x => x.DrawText(options, "JOHAN", Brushes.Solid(Color.White)));
penWidth = 12f;
options.Origin = options.Origin - new Vector2(penWidth / 2f);
image.Mutate(x => x.DrawText(options, "JOHAN", Pens.Solid(Color.Black, 12)));
options.Origin = new Point(1156, 1381);
image.Mutate(x => x.DrawText(options, "TIGERTECH", Brushes.Solid(Color.White)));
options.Origin = options.Origin - new Vector2(penWidth / 2f);
image.Mutate(x => x.DrawText(options, "TIGERTECH", Pens.Solid(Color.Black, 12)));
this will be technically slower but it might be negligible depending on your usage. Just to be completely transparent this is only a work around for a bug that we needs to be fixed and the original code is the expected way to do this. |
3 replies
Answer selected by
johantiger
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Your doing nothing wrong there, that's totally a bug.
Looking closely it looks like there is a
path thickness/2offset being applied to the path during the outlining stage.As a work around you might be able to do something like this.