Skip to content

Regarding the use of vertical alignment, there is a discrepancy between the vertical centering effect of the text and the expected outcome. #303

Answered by JimBobSquarePants
inernoro asked this question in Q&A
Discussion options

You must be logged in to vote

Alignment is always measured based upon the line-height and advance (which can collapse over each other for multiline text). This means that the line is centered vertically not the glyph itself since glyphs are aligned within the advance box.

The following code demonstrates this well. Here I am drawing an X using vertical alignment with two red lines as a guide.

// Set variable dimensions
int w = 301;
int h = 301;
float hw = w / 2f;
float hh = h / 2f;

using Image<Rgba32> img = new(w, h, Color.White);

const string t = "X";
Font font = SystemFonts.CreateFont("Arial", h / 4);
RichTextOptions options = new(font)
{
	Origin = new PointF(hw, hh),
	VerticalAlignment = VerticalAlignment.Center,
	H…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@inernoro
Comment options

@JimBobSquarePants
Comment options

Answer selected by inernoro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants