Fix underline DPI (#35816)

Release Notes:

- Fixed wavy underlines looking inconsistent on different displays
This commit is contained in:
localcc
2025-08-11 13:57:30 +02:00
committed by GitHub
parent 086ea3c619
commit 702a95ffb2
3 changed files with 22 additions and 7 deletions
@@ -914,7 +914,7 @@ float4 path_rasterization_fragment(PathFragmentInput input): SV_Target {
float2 dx = ddx(input.st_position);
float2 dy = ddy(input.st_position);
PathRasterizationSprite sprite = path_rasterization_sprites[input.vertex_id];
Background background = sprite.color;
Bounds bounds = sprite.bounds;
@@ -1021,13 +1021,18 @@ UnderlineVertexOutput underline_vertex(uint vertex_id: SV_VertexID, uint underli
}
float4 underline_fragment(UnderlineFragmentInput input): SV_Target {
const float WAVE_FREQUENCY = 2.0;
const float WAVE_HEIGHT_RATIO = 0.8;
Underline underline = underlines[input.underline_id];
if (underline.wavy) {
float half_thickness = underline.thickness * 0.5;
float2 origin = underline.bounds.origin;
float2 st = ((input.position.xy - origin) / underline.bounds.size.y) - float2(0., 0.5);
float frequency = (M_PI_F * (3. * underline.thickness)) / 8.;
float amplitude = 1. / (2. * underline.thickness);
float frequency = (M_PI_F * WAVE_FREQUENCY * underline.thickness) / underline.bounds.size.y;
float amplitude = (underline.thickness * WAVE_HEIGHT_RATIO) / underline.bounds.size.y;
float sine = sin(st.x * frequency) * amplitude;
float dSine = cos(st.x * frequency) * amplitude * frequency;
float distance = (st.y - sine) / sqrt(1. + dSine * dSine);