Skip to content

Commit

Permalink
Fix translation factor when scaling.
Browse files Browse the repository at this point in the history
  • Loading branch information
miniksa committed May 2, 2020
1 parent fe4e1c7 commit f6e4542
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/renderer/dx/CustomTextLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1551,8 +1551,8 @@ void CustomTextLayout::_OrderRuns()
boxVerticalScaleFactor = cellHeightDesignUnits / boxHeightDesignUnits;
}
{
const auto extraAscent = boxAscentDesignUnits - cellAscentDesignUnits;
const auto extraDescent = boxDescentDesignUnits - cellDescentDesignUnits;
const auto extraAscent = boxAscentDesignUnits * boxVerticalScaleFactor - cellAscentDesignUnits;
const auto extraDescent = boxDescentDesignUnits * boxVerticalScaleFactor - cellDescentDesignUnits;

const auto boxVerticalTranslationDesignUnits = (extraAscent - extraDescent) / 2;

Expand Down Expand Up @@ -1584,8 +1584,8 @@ void CustomTextLayout::_OrderRuns()
boxHorizontalScaleFactor = cellWidthDesignUnits / boxWidthDesignUnits;
}
{
const auto extraLeft = boxLeftDesignUnits - cellLeftDesignUnits;
const auto extraRight = boxRightDesignUnits - cellRightDesignUnits;
const auto extraLeft = boxLeftDesignUnits * boxHorizontalScaleFactor - cellLeftDesignUnits;
const auto extraRight = boxRightDesignUnits * boxHorizontalScaleFactor - cellRightDesignUnits;

const auto boxHorizontalTranslationDesignUnits = (extraLeft - extraRight) / 2;

Expand Down
16 changes: 15 additions & 1 deletion src/renderer/dx/CustomTextRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,20 +543,34 @@ using namespace Microsoft::Console::Render;
glyphRun->bidiLevel % 2,
geometrySink.Get());


geometrySink->Close();

// Can be used to see the dimensions of what is written.
/*D2D1_RECT_F bounds;
pathGeometry->GetBounds(D2D1::IdentityMatrix(), &bounds);*/

// Dig out the box drawing effect parameters.
BoxScale scale;
RETURN_IF_FAILED(clientDrawingEffect->GetScale(&scale));

// Assign to matrix transformation.
const auto matrixTransformation = D2D1::Matrix3x2F::Matrix3x2F(scale.HorizontalScale, 0, 0, scale.VerticalScale, baselineOrigin.x + scale.HorizontalTranslation, baselineOrigin.y + scale.VerticalTranslation);
const auto scaleTransform = D2D1::Matrix3x2F::Scale(scale.HorizontalScale, scale.VerticalScale);
const auto baselineTransform = D2D1::Matrix3x2F::Translation(baselineOrigin.x, baselineOrigin.y);
const auto offsetTransform = D2D1::Matrix3x2F::Translation(scale.HorizontalTranslation, scale.VerticalTranslation);

// The order is important here. Scale it first, then slide it into place.
const auto matrixTransformation = scaleTransform * baselineTransform * offsetTransform;

::Microsoft::WRL::ComPtr<ID2D1TransformedGeometry> transformedGeometry;
d2dFactory->CreateTransformedGeometry(pathGeometry.Get(),
&matrixTransformation,
transformedGeometry.GetAddressOf());

// Can be used to see the dimensions after translation.
/*D2D1_RECT_F boundsAfter;
transformedGeometry->GetBounds(D2D1::IdentityMatrix(), &boundsAfter);*/

// Draw the outline then fill it in.
clientDrawingContext->renderTarget->DrawGeometry(transformedGeometry.Get(), clientDrawingContext->foregroundBrush);
clientDrawingContext->renderTarget->FillGeometry(transformedGeometry.Get(), clientDrawingContext->foregroundBrush);
Expand Down

1 comment on commit f6e4542

@github-actions

This comment was marked as resolved.

Please sign in to comment.