Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calculation of wrapping advance #440

Merged
merged 3 commits into from
Jan 10, 2025

Conversation

JimBobSquarePants
Copy link
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

An index mismatch was causing the incorrect line-break to be used under certain circumstance.

CC @jez9999

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 17 changed files in this pull request and generated no comments.

Files not reviewed (14)
  • tests/Images/ReferenceOutput/CountLinesWrappingLength_100-3.png: Language not supported
  • tests/Images/ReferenceOutput/CountLinesWrappingLength_100-4.png: Language not supported
  • tests/Images/ReferenceOutput/CountLinesWrappingLength_50-4.png: Language not supported
  • tests/Images/ReferenceOutput/CountLinesWrappingLength_50-5.png: Language not supported
  • tests/Images/ReferenceOutput/MeasureTextWordBreakMatchesMDN_238-layoutMode_HorizontalBottomTop-wordBreaking_BreakAll.png: Language not supported
  • tests/Images/ReferenceOutput/MeasureTextWordBreakMatchesMDN_238-layoutMode_HorizontalTopBottom-wordBreaking_BreakAll.png: Language not supported
  • tests/Images/ReferenceOutput/MeasureTextWordBreak_500-layoutMode_HorizontalBottomTop-wordBreaking_BreakAll.png: Language not supported
  • tests/Images/ReferenceOutput/MeasureTextWordBreak_500-layoutMode_HorizontalTopBottom-wordBreaking_BreakAll.png: Language not supported
  • tests/Images/ReferenceOutput/MeasureTextWordWrappingHorizontalBottomTop_350-height_62.625-width_318.86.png: Language not supported
  • tests/Images/ReferenceOutput/MeasureTextWordWrappingHorizontalTopBottom_350-height_62.625-width_318.86.png: Language not supported
  • tests/Images/ReferenceOutput/MeasureTextWordWrappingVerticalLeftRight_350-height_318.563-width_62.813.png: Language not supported
  • tests/Images/ReferenceOutput/MeasureTextWordWrappingVerticalMixedLeftRight_350-height_318.563-width_62.813.png: Language not supported
  • tests/Images/ReferenceOutput/MeasureTextWordWrappingVerticalRightLeft_350-height_318.563-width_62.813.png: Language not supported
  • tests/Images/ReferenceOutput/ShouldNotInsertExtraLineBreaks_2__WrappingLength_400_.png: Language not supported
Comments suppressed due to low confidence (4)

tests/SixLabors.Fonts.Tests/Issues/Issues_431.cs:35

  • Ensure that the new test case ShouldNotInsertExtraLineBreaks_2 covers the new behavior correctly, especially with the changes in the BreakLines method.
public void ShouldNotInsertExtraLineBreaks_2()

src/SixLabors.Fonts/TextLayout.cs:1077

  • The comment about using inches for comparison is misleading since the actual comparison is done in pixels after conversion. Consider rephrasing to clarify the intent.
// Now scale the advance. We use inches for comparison.

src/SixLabors.Fonts/TextLayout.cs:1156

  • Re-initializing lineAdvance here might be unnecessary and could lead to confusion. Ensure that lineAdvance is correctly managed within the loop.
float lineAdvance = 0;

src/SixLabors.Fonts/TextLayout.cs:1175

  • Resetting i to -1 might cause an off-by-one error. Verify if this is the intended behavior or if i should be reset to 0.
i = -1;
if (codePointIndex == currentLineBreak.PositionWrap && currentLineBreak.Required)
{
// Mandatory line break at index.
TextLine remaining = textLine.SplitAt(i);
textLines.Add(textLine.Finalize(options));
textLine = remaining;
i = 0;
i = -1;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This took me a few hours to figure out! Setting i = 0 was incorrect as the loop was incrementing the value before we read the collection again.

@JimBobSquarePants JimBobSquarePants merged commit 24871a8 into main Jan 10, 2025
8 checks passed
@JimBobSquarePants JimBobSquarePants deleted the js/additional-linebreak-fixes branch January 10, 2025 12:53
@jez9999
Copy link

jez9999 commented Jan 11, 2025

👍 With 2.0.9 all my tests now seem to render as expected.

@jez9999
Copy link

jez9999 commented Jan 13, 2025

Apparently I spoke too soon. 😞 Came across another regression by accident. Filed as #441.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants