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

Fixed DirectX RTL text issue where it'd be over other text / offscreen #1873

Merged
merged 8 commits into from
Jul 10, 2019
21 changes: 17 additions & 4 deletions src/renderer/dx/CustomTextLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,20 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory2* const factory,
glyphRunDescription.stringLength = run.textLength;
glyphRunDescription.textPosition = run.textStart;

// Calculate the origin for the next run based on the amount of space
// that would be consumed. We are doing this calculation now, not after,
// because if the text is RTL then we need to advance immediately, before the
// write call since DirectX expects the origin to the RIGHT of the text for RTL.
const auto postOriginX = std::accumulate(_glyphAdvances.begin() + run.glyphStart,
_glyphAdvances.begin() + run.glyphStart + run.glyphCount,
mutableOrigin.x);

// Check for RTL, if it is, apply space adjustment.
if (WI_IsFlagSet(glyphRun.bidiLevel, 1))
miniksa marked this conversation as resolved.
Show resolved Hide resolved
{
mutableOrigin.x = postOriginX;
}

// Try to draw it
RETURN_IF_FAILED(renderer->DrawGlyphRun(clientDrawingContext,
mutableOrigin.x,
Expand All @@ -507,10 +521,9 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory2* const factory,
&glyphRunDescription,
nullptr));

// Shift origin to the right for the next run based on the amount of space consumed.
mutableOrigin.x = std::accumulate(_glyphAdvances.begin() + run.glyphStart,
_glyphAdvances.begin() + run.glyphStart + run.glyphCount,
mutableOrigin.x);
// Either way, we should be at this point by the end of writing this sequence,
// whether it was LTR or RTL.
mutableOrigin.x = postOriginX;
}
}
CATCH_RETURN();
Expand Down